cohost/html/hot_people_who_eat_croissants_are_dangerous.tsx

103 lines
2.7 KiB
TypeScript
Raw Normal View History

2023-07-10 14:52:20 -04:00
import { Html, debug_render } from "./html.ts";
import { Component } from "./jsx/jsx-runtime.ts";
2023-07-10 14:57:18 -04:00
const peopleify = (...people: string[]): string[] =>
people.map(p => `${p} people`);
const animation_length = (num_items: number): number => num_items / 5;
const wheel_style = (num_items: number, delay_seconds = 0): string =>
`transform: translateY(calc(2rem * -${num_items})); animation: ${animation_length(
num_items
)}s 0s ease-in-out reverse none running spin; animation-delay: ${delay_seconds}s;`;
const get_delays = (...lengths: number[]): number[] => {
let out = [0];
for (const l of lengths) {
out.push((out.at(-1) ?? 0) + animation_length(l));
}
return out;
};
const Wheel: Component = ({ delay_seconds }, children) => (
2023-07-10 14:52:20 -04:00
<div class="wheel">
<div
class="wheel-inner"
style={wheel_style(children.length, delay_seconds)}
>
<div class="wheel-item empty"></div>
{...children.map(i => <div class="wheel-item">{i}</div>)}
</div>
2023-07-10 14:52:20 -04:00
</div>
);
// i'll probably just hardcode the delays... lame but w/e
const Take: Component = ({ subjects, objects, adjectives }, _) => {
const [d1, d2, d3] = get_delays(
subjects.length,
objects.length,
adjectives.length
);
console.log(get_delays(subjects.length, objects.length, adjectives.length));
return (
<div class="take">
<Wheel delay_seconds={d1}>{...subjects}</Wheel> who eat{" "}
<Wheel delay_seconds={d2}>{...objects}</Wheel> are{" "}
<Wheel delay_seconds={d3}>{...adjectives}</Wheel>
</div>
);
};
2023-07-10 14:52:20 -04:00
// might want to have the final item be seperate
// turned out to be unnecessary
2023-07-10 14:52:20 -04:00
debug_render(
<Take
2023-07-10 14:57:18 -04:00
subjects={peopleify(
2023-07-10 14:52:20 -04:00
"poor",
"fat",
"dumb",
"tall",
"short",
"poor",
"fat",
"dumb",
"tall",
2023-07-10 14:57:18 -04:00
"hot"
)}
2023-07-10 14:52:20 -04:00
objects={[
"apples",
"bread",
"pasta",
"candy",
"rice",
"beans",
"apples",
"bread",
"candy",
"rice",
"beans",
"apples",
"bread",
"pasta",
"candy",
"rice",
"croissants",
]}
adjectives={[
"vibes",
"mean",
"dumb",
"cool",
"hot",
"stupid",
"funny",
"vibes",
"mean",
"dumb",
"cool",
"hot",
"stupid",
"dangerous",
]}
/>
);