2023-09-07 21:24:57 -04:00
|
|
|
import { ComponentChildren } from "preact";
|
|
|
|
import { css, render_and_copy } from "./common.tsx";
|
|
|
|
// combine a shake with a fall
|
|
|
|
// fall should be more delayed than shake
|
|
|
|
// we want outliers (a few letters falling before than others)
|
|
|
|
// exponentials should do
|
|
|
|
|
2023-09-07 21:42:33 -04:00
|
|
|
const default_shaky_delay = (x: number) => 5 + 20 * x;
|
2023-09-07 21:24:57 -04:00
|
|
|
export type DelayFn = (_: number) => number;
|
|
|
|
|
|
|
|
// exporting these in case they turn out to be useful
|
|
|
|
export const Shaky = ({
|
|
|
|
children,
|
2023-09-07 21:27:45 -04:00
|
|
|
delay = 0,
|
2023-09-07 21:24:57 -04:00
|
|
|
}: {
|
|
|
|
children: ComponentChildren;
|
2023-09-07 21:27:45 -04:00
|
|
|
delay?: number;
|
2023-09-07 21:24:57 -04:00
|
|
|
}) => (
|
2023-09-07 21:36:15 -04:00
|
|
|
<span
|
2023-09-07 21:24:57 -04:00
|
|
|
style={{
|
2023-09-07 21:27:45 -04:00
|
|
|
transform: css.transform(css.translate(css.px(-1), css.px(-1))),
|
|
|
|
animation: `0.2s spin alternate-reverse linear ${delay}s infinite`,
|
2023-09-07 21:24:57 -04:00
|
|
|
display: css.inline_block,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
2023-09-07 21:36:15 -04:00
|
|
|
</span>
|
2023-09-07 21:24:57 -04:00
|
|
|
);
|
|
|
|
|
2023-09-07 21:42:33 -04:00
|
|
|
const default_fall_delay = (x: number) => 10 + 25 * x;
|
2023-09-07 21:36:15 -04:00
|
|
|
// direction should be random but that doesn't need to be as custo
|
|
|
|
// well should it
|
|
|
|
// i think i'll try without that first
|
|
|
|
// a slow fall is fun
|
2023-09-07 21:58:39 -04:00
|
|
|
// i could have some weird hack where there's another copy that's hidden but that seems like the wrong way to do it
|
|
|
|
// i think the best way to do it is jump-hackery (jump 0s in to the start
|
|
|
|
// (which is 0 displacement when reversed)), then wait, then jump to the real animation
|
2023-09-07 21:24:57 -04:00
|
|
|
export const Fall = ({
|
|
|
|
children,
|
2023-09-07 21:27:45 -04:00
|
|
|
delay = 0,
|
2023-09-07 21:24:57 -04:00
|
|
|
}: {
|
|
|
|
children: ComponentChildren;
|
2023-09-07 21:27:45 -04:00
|
|
|
delay?: number;
|
2023-09-07 21:24:57 -04:00
|
|
|
}) => (
|
2023-09-07 21:36:15 -04:00
|
|
|
<span
|
2023-09-07 21:24:57 -04:00
|
|
|
style={{
|
2023-09-07 21:58:39 -04:00
|
|
|
transform: css.transform(css.translateY(css.rem(413))),
|
|
|
|
animation: `15s ${delay}s linear once spin`,
|
2023-09-07 21:24:57 -04:00
|
|
|
display: css.inline_block,
|
|
|
|
}}
|
2023-09-07 21:42:33 -04:00
|
|
|
class="bla"
|
2023-09-07 21:24:57 -04:00
|
|
|
>
|
|
|
|
{children}
|
2023-09-07 21:36:15 -04:00
|
|
|
</span>
|
2023-09-07 21:24:57 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
const msg = `
|
|
|
|
i haven't seen this on other blogs, but some of the posts on mine seem to be kinda unstable?
|
|
|
|
if that makes sense?
|
|
|
|
like, sometimes i see them shake, and i swear i saw some letters fall
|
|
|
|
|
|
|
|
i know i'm a (convicted?) css criminal, so i'm thinking that this might just be the w3 gods punishing me.
|
|
|
|
|
|
|
|
so. yeah. if you see anything like that on any of my posts let me know
|
|
|
|
`.trim();
|
|
|
|
|
|
|
|
// should probably do it word wise so they don't break
|
2023-09-07 21:58:39 -04:00
|
|
|
// where did the cool bug go???
|
2023-09-07 21:24:57 -04:00
|
|
|
export const Crumble = ({
|
|
|
|
msg,
|
2023-09-07 21:27:45 -04:00
|
|
|
shaky_delay_fn = default_shaky_delay,
|
|
|
|
fall_delay_fn = default_fall_delay,
|
2023-09-07 21:24:57 -04:00
|
|
|
}: {
|
|
|
|
msg: string;
|
|
|
|
shaky_delay_fn?: DelayFn;
|
|
|
|
fall_delay_fn?: DelayFn;
|
|
|
|
}) => (
|
|
|
|
<div>
|
2023-09-07 21:27:45 -04:00
|
|
|
{msg.split("").map(c => {
|
|
|
|
if (/[^\s]/.test(c)) {
|
|
|
|
const seed = Math.random();
|
2023-09-07 21:58:39 -04:00
|
|
|
const fall_delay = fall_delay_fn(seed);
|
2023-09-07 21:27:45 -04:00
|
|
|
return (
|
2023-09-07 21:58:39 -04:00
|
|
|
<Fall delay={fall_delay}>
|
2023-09-07 21:27:45 -04:00
|
|
|
<Shaky delay={shaky_delay_fn(seed)}>{c}</Shaky>
|
|
|
|
</Fall>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (c == "\n") return <br />;
|
|
|
|
return c;
|
|
|
|
})}
|
2023-09-07 21:24:57 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
render_and_copy(<Crumble msg={msg} />);
|