-
Notifications
You must be signed in to change notification settings - Fork 0
/
brookers__hyop.ts
318 lines (318 loc) · 12.1 KB
/
brookers__hyop.ts
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/// <reference lib="dom" />
import { type brookers_timeline_op_T } from '@btakita/domain--any--brookebrodack/brookers'
import { md_px_num } from '@btakita/ui--server--brookebrodack/css'
import { browser_ctx__ensure } from '@rappstack/domain--browser/ctx'
import {
calling,
type circular_memo_T,
memo_,
type memo_T,
nullish__none_,
rmemo__wait,
run,
sig_,
sleep
} from 'ctx-core/rmemo'
import { wanimato__new, type wanimato_T } from 'ctx-core/web_animation'
import { spinner__attach, spinner__remove } from '../../spinner/index.js'
import { YT_player_, YT_PlayerState__CUED_ } from '../../youtube/index.js'
export async function brookers__hyop(brookers__div:HTMLDivElement) {
await brookers__div__animate(brookers__div)
await brookers_timeline__li__init(brookers__div)
}
async function brookers__div__animate(brookers__div:HTMLDivElement) {
const h1 = brookers__div.querySelector('h1')!
const h2 = brookers__div.querySelector('h2')!
const brookers_hero__div = brookers__div.querySelector<HTMLElement>(
'.brookers_hero__div')!
const brookers_master__div = brookers__div.querySelector<HTMLElement>(
'.brookers_master__div')!
const brookers_img__div = brookers__div.querySelector<HTMLElement>(
'.brookers_img__div')!
await ready__waitfor()
animation__run().catch(err=>console.error(err))
brookers__div.classList.remove('hidden')
async function ready__waitfor() {
while ((innerWidth__is_pending_() || brookers_hero__div__is_pending_())) {
await sleep(10)
}
/**
* Chrome seems to have a short period where the outerWidth is 0.
* TODO: 2023-11-8: check if this is necessary in the future
*/
function innerWidth__is_pending_() {
return !window.outerWidth
}
function brookers_hero__div__is_pending_() {
return !brookers_hero__div.getBoundingClientRect().width
}
}
async function animation__run() {
brookers_hero__div.style.transform = 'translateX(calc(50vw - 50%))'
const brookers_hero__div__width = brookers_hero__div.getBoundingClientRect().width
const h1__center__factor = brookers_hero__div__width / 2 + 'px - 35%'
brookers_hero__div.classList.remove('opacity-0')
const h1__flyin_wanimato$ = h1__flyin_wanimato$_()
const h1__bounce_wanimato$ = h1__bounce_wanimato$_()
const h2__flyin_wanimato$ = h2__flyin_wanimato$_()
const h2__bounce_wanimato$ = h2__bounce_wanimato$_()
const brookers_img__div__slidein_wanimato$ = brookers_img__div__slidein_wanimato$_()
const brookers_img__div__slideout_wanimato$ = brookers_img__div__slideout_wanimato$_()
const brookers_master__div__slide_wanimato$ = brookers_master__div__slide_wanimato$_()
const brookers_hero__div__slide_wanimato$ = brookers_hero__div__slide_wanimato$_()
const h1__center_to_left_wanimato$ = h1__center_to_left_wanimato$_()
if (document.scrollingElement) document.scrollingElement.scrollTop = 0
document.body.style.overflowY = 'hidden'
await rmemo__wait(memo_(()=>
h1__flyin_wanimato$()?.is_finish
&& h1__bounce_wanimato$()?.is_finish
&& h1__center_to_left_wanimato$()?.is_finish
&& h2__flyin_wanimato$()?.is_finish
&& h2__bounce_wanimato$()?.is_finish
&& brookers_img__div__slidein_wanimato$()?.is_finish
&& brookers_img__div__slideout_wanimato$()?.is_finish
&& brookers_master__div__slide_wanimato$()?.is_finish
&& brookers_hero__div__slide_wanimato$()?.is_finish),
finish=>finish,
20_000)
document.body.style.overflowY = 'auto'
function h1__flyin_wanimato$_() {
return calling(memo_<wanimato_T>(
$=>{
h1.classList.remove('opacity-0')
return wanimato__new($, h1, ()=>h1.animate([
{ transform: `translate(calc(-25vw + ${h1__center__factor}), -25vh) rotate(-45deg)`, opacity: 0 },
{ transform: `translate(calc(4px + ${h1__center__factor}), 1px) rotate(10deg)`, opacity: 1 },
{ transform: `translate(calc(40px + ${h1__center__factor}), 10px) rotate(10deg)`, opacity: 1 },
], { duration: 400, fill: 'both', easing: 'ease-in' }))
}))
}
function h1__bounce_wanimato$_() {
return calling(memo_<wanimato_T|undefined>(
$=>{
if (!h1__flyin_wanimato$().is_finish) return
const keyframe_a1 = s180_d12_spring__keyframe_a1_({
X: 40, Y: 10, O: 10, X_factor: h1__center__factor
})
return wanimato__new($, h1, ()=>h1.animate(keyframe_a1, {
duration: 800,
easing: 'ease-in',
fill: 'both'
}))
}))
}
function h1__center_to_left_wanimato$_() {
return calling(memo_<wanimato_T|undefined>($=>{
if (!brookers_img__div__slideout_wanimato$()?.is_finish) return
return wanimato__new($, h1, ()=>h1.animate([
{ transform: 'translateX(calc(50vw - 90%))' },
{ transform: 'translateX(0)' }
], { duration: 200, fill: 'forwards' }))
}))
}
function h2__flyin_wanimato$_() {
return calling(memo_<wanimato_T|undefined>(
$=>{
if (!h1__flyin_wanimato$().is_finish) return
h2.classList.remove('opacity-0')
return wanimato__new($, h2, ()=>h2.animate([
{ transform: `translate(25vw, -25vh) rotate(45deg)`, opacity: 0 },
{ transform: `translate(-4px, 1px) rotate(-10deg)`, opacity: 1 },
{ transform: `translate(-40px, 10px) rotate(-10deg)`, opacity: 1 },
], { duration: 400, easing: 'ease-in', fill: 'both' }))
}))
}
function h2__bounce_wanimato$_() {
return calling(memo_<wanimato_T|undefined>(
$=>{
if (!h2__flyin_wanimato$()?.is_finish) return
const keyframe_a1 = s180_d12_spring__keyframe_a1_({
X: -40, Y: 10, O: -10
})
return wanimato__new($, h2, ()=>h2.animate(keyframe_a1, {
duration: 800,
easing: 'ease-in',
fill: 'both'
}))
}))
}
function brookers_img__div__slidein_wanimato$_() {
return calling(memo_<wanimato_T&{ forwards__transform:string }|undefined>($=>{
if (!h2__bounce_wanimato$()?.is_finish) return
brookers_img__div.classList.remove('opacity-0')
const forwards__transform = `translateX(${innerWidth > md_px_num ? '25vw' : '0'})`
return {
...wanimato__new($, brookers_img__div, ()=>brookers_img__div.animate([
{
transform: 'translateX(-100vw)',
opacity: 0
},
{
transform: forwards__transform,
opacity: 1
}
], { duration: 200, fill: 'forwards' })),
forwards__transform
}
}))
}
function brookers_img__div__slideout_wanimato$_() {
return calling(memo_<wanimato_T|undefined>($=>{
if (!brookers_img__div__slidein_wanimato$()?.is_finish) return
const val = wanimato__new($, brookers_img__div, ()=>brookers_img__div.animate([
{ transform: brookers_img__div__slidein_wanimato$()!.forwards__transform },
{ transform: 'translateX(-100vw)' }
], {
delay: 2000,
duration: 400,
fill: 'forwards'
}))
val.animation.addEventListener('finish', ()=>{
brookers_img__div.remove()
})
return val
}))
}
function brookers_master__div__slide_wanimato$_() {
return calling(memo_<wanimato_T|undefined>($=>{
if (!brookers_img__div__slideout_wanimato$()?.is_finish) return
brookers_master__div.classList.remove('opacity-0')
return wanimato__new($, brookers_master__div, ()=>brookers_master__div.animate([
{
transform: `translateX(100vw)`
},
{
transform: 'translateX(0)'
}
], {
duration: 200,
fill: 'both'
}))
}))
}
function brookers_hero__div__slide_wanimato$_() {
return calling(memo_<wanimato_T|undefined>($=>{
if (!brookers_img__div__slideout_wanimato$()?.is_finish) return
return wanimato__new($, brookers_hero__div, ()=>brookers_hero__div.animate([
{ transform: 'translateX(calc(50vw - 50%))' },
{ transform: 'translateX(32px)' }
], { duration: 200, fill: 'forwards' }))
}))
}
}
}
async function brookers_timeline__li__init(brookers__div:HTMLDivElement) {
const browser_ctx = browser_ctx__ensure()
const brookers_detail__div =
brookers__div.querySelector<HTMLDivElement&{ op__go$:circular_memo_T }>(
'.brookers_detail__div')!
const brookers_timeline__li_a =
Array.from(brookers__div.querySelectorAll<brookers_timeline__li_T>(
'.brookers_timeline__li'))
const html_op__div = brookers_detail__div.querySelector('#html_op__div')!
const brookers__timeline_op$ = sig_<brookers_timeline_op_T|undefined>(undefined)
const op_title__div = brookers_detail__div.querySelector<HTMLDivElement>('#op_title__div')!
const op_close__div = brookers_detail__div.querySelector('#op_close__div')!
op_close__div.addEventListener('click', ()=>{
brookers__timeline_op$.set(undefined)
})
op__init()
function op__init() {
brookers_detail__div.op__go$ = run(
memo_<circular_memo_T, {
brookers__timeline_op:brookers_timeline_op_T|undefined
}>(op__go$=>{
nullish__none_([YT_player_(browser_ctx)], YT_player=>{
const brookers__timeline_op = brookers__timeline_op$()
switch (brookers__timeline_op?.type) {
case 'html':
op_title__div.innerText = brookers__timeline_op.title
brookers_detail__div.classList.remove('hidden')
if (brookers__timeline_op !== op__go$.brookers__timeline_op) {
YT_player.stopVideo()
YT_player.getIframe().classList.add('hidden')
html_op__div.innerHTML = brookers__timeline_op.html
html_op__div.classList.remove('hidden')
const iframe =
html_op__div.querySelector<HTMLIFrameElement>('iframe')
if (iframe) {
spinner__attach(brookers_detail__div)
iframe.addEventListener('load', ()=>spinner__remove(brookers_detail__div))
}
}
break
case 'youtube':
op_title__div.innerText = brookers__timeline_op.title
brookers_detail__div.classList.remove('hidden')
html_op__div.classList.add('hidden')
if (brookers__timeline_op !== op__go$.brookers__timeline_op) {
html_op__div.innerHTML = ''
YT_player.stopVideo()
YT_player.getIframe().classList.remove('hidden')
YT_player.loadVideoById({
videoId: brookers__timeline_op.videoId
})
YT_player.playVideo()
}
if (YT_PlayerState__CUED_(browser_ctx)) {
spinner__attach(brookers_detail__div)
} else {
spinner__remove(brookers_detail__div)
}
break
default:
html_op__div.innerHTML = ''
YT_player.stopVideo()
html_op__div.classList.remove('hidden')
YT_player.getIframe().classList.remove('hidden')
brookers_detail__div.classList.add('hidden')
}
op__go$.brookers__timeline_op = brookers__timeline_op
})
return op__go$
}))
for (const brookers_timeline__li of brookers_timeline__li_a) {
brookers_timeline__li.op = JSON.parse(
decodeURIComponent(brookers_timeline__li.dataset.op ?? '{}')
) as brookers_timeline_op_T
brookers_timeline__li.selected__watch$ = calling(memo_(()=>{
brookers_timeline__li.classList.toggle(
'selected',
brookers__timeline_op$() === brookers_timeline__li.op)
}))
brookers_timeline__li.addEventListener('click', async ()=>{
brookers__timeline_op$.set(brookers_timeline__li.op)
})
for (const a of Array.from(brookers_timeline__li.querySelectorAll<HTMLAnchorElement>('a'))) {
a.addEventListener('click', evt=>evt.stopPropagation())
}
}
}
}
// f(0) = 0; f'(0) = 0; f''(t) = -180(f(t) - 1) - 12f'(t)
// https://www.wolframalpha.com/input?i=f%280%29+%3D+0%3B+f%27%280%29+%3D+0%3B+f%27%27%28t%29+%3D+-180%28f%28t%29+-+1%29+-+12f%27%28t%29
// f(t) = -1/2 e^(-6 t) (-2 e^(6 t) + sin(12 t) + 2 cos(12 t))
function s180_d12_spring__keyframe_a1_(config:{
X:number, Y:number, O:number, X_factor?:string
}) {
const { X, Y, O, X_factor } = config
const keyframe_a1:Keyframe[] = []
keyframe_a1.push({
transform: `translate(calc(${X}px${X_factor ? ` + ${X_factor}` : ''}), ${Y}px) rotate(${O}deg)`
})
for (let T = 1; T < 100; T++) {
const t = T / 100
const c = -.5 * Math.exp(-6 * t) * (-2 * Math.exp(6 * t) + Math.sin(12 * t) + 2 * Math.cos(12 * t))
keyframe_a1.push({
transform: `translate(calc(${X - c * X}px${X_factor ? ` + ${X_factor}` : ''}), ${Y - c * Y}px) rotate(${O - c * O}deg)`
})
}
keyframe_a1.push({
transform: `translate(calc(${X_factor ?? '0px'}), 0) rotate(0deg)`
})
return keyframe_a1
}
type brookers_timeline__li_T = HTMLOListElement&{
op:brookers_timeline_op_T
selected__watch$:memo_T<void>
}