2023-07-20 13:33:55 -04:00
|
|
|
import {
|
|
|
|
Attributes,
|
|
|
|
ComponentChild,
|
|
|
|
ComponentChildren,
|
|
|
|
JSX,
|
|
|
|
VNode,
|
|
|
|
toChildArray,
|
|
|
|
} from "preact";
|
2023-07-12 14:15:53 -04:00
|
|
|
import { render } from "preact-render-to-string";
|
|
|
|
import { writeText } from "copy-paste";
|
2023-09-23 11:40:56 -04:00
|
|
|
// i know it's out of date; i just want something simple
|
|
|
|
import { randomInt } from "https://deno.land/std@0.146.0/node/internal/crypto/random.ts";
|
2023-07-10 14:52:20 -04:00
|
|
|
|
2023-07-12 14:15:53 -04:00
|
|
|
export function Main({
|
|
|
|
children,
|
|
|
|
...attributes
|
|
|
|
}: {
|
2023-07-20 14:31:12 -04:00
|
|
|
children?: ComponentChildren;
|
2023-08-19 20:30:42 -04:00
|
|
|
style?: JSX.CSSProperties;
|
2023-07-25 02:08:15 -04:00
|
|
|
attributes?: JSX.HTMLAttributes;
|
2023-07-12 14:15:53 -04:00
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<div {...attributes} id="main">
|
|
|
|
{...toChildArray(children)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2023-07-12 07:05:48 -04:00
|
|
|
|
2023-07-12 14:15:53 -04:00
|
|
|
export const HCenter = ({
|
|
|
|
children,
|
|
|
|
...attrs
|
|
|
|
}: {
|
|
|
|
children: ComponentChildren;
|
|
|
|
attrs?: Attributes;
|
|
|
|
}) => (
|
2023-07-12 07:05:48 -04:00
|
|
|
<div
|
2023-07-12 14:15:53 -04:00
|
|
|
{...attrs}
|
2023-07-12 07:05:48 -04:00
|
|
|
class="hcenter"
|
|
|
|
style="display: flex; justify-content: center;"
|
|
|
|
>
|
2023-07-12 14:15:53 -04:00
|
|
|
{...toChildArray(children)}
|
2023-07-12 07:05:48 -04:00
|
|
|
</div>
|
|
|
|
);
|
2023-07-12 07:52:26 -04:00
|
|
|
|
2023-08-23 20:31:10 -04:00
|
|
|
export const eggbug_emotions = (attrs: JSX.HTMLAttributes<HTMLImageElement>) =>
|
|
|
|
({
|
|
|
|
smiling: (
|
|
|
|
<img
|
|
|
|
class="eggbug"
|
|
|
|
src="https://staging.cohostcdn.org/attachment/f33b4285-0455-4128-96b8-117054af40c3/eggbugSquare.png"
|
|
|
|
alt="eggbug, smiling"
|
|
|
|
{...attrs}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
frowning: (
|
|
|
|
<img
|
|
|
|
class="eggbug"
|
|
|
|
src="https://static.pyrope.net/eggbug-sad.png"
|
|
|
|
alt="eggbug, frowning"
|
|
|
|
{...attrs}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
revengeance: (
|
|
|
|
<img
|
|
|
|
class="eggbug"
|
|
|
|
src="https://static.pyrope.net/eggbug-revengeance.png"
|
|
|
|
alt="ULTRA EGGBUG REVENGEANCE, MEGA. THERE IS FIRE. THERE IS TRISCAR. EGGBUG REVENGEANCE. YOU ARE. DIE!"
|
|
|
|
{...attrs}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
jpeg_annihilation: (
|
|
|
|
<img
|
|
|
|
class="eggbug"
|
|
|
|
src="https://static.pyrope.net/eggbug-jpeg-annihilation.gif"
|
|
|
|
alt="eggbug dissolving as the image gets more and more jpeg"
|
|
|
|
{...attrs}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
golfball: (
|
|
|
|
<img
|
|
|
|
class="eggbug"
|
|
|
|
src="https://static.pyrope.net/eggbug-golfball.png"
|
|
|
|
alt="eggbug as a golfball. no legs"
|
|
|
|
{...attrs}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
} as const);
|
2023-07-12 14:15:53 -04:00
|
|
|
|
2023-08-23 20:31:10 -04:00
|
|
|
export type EggbugEmotion = keyof ReturnType<typeof eggbug_emotions>;
|
|
|
|
type bla = ({
|
|
|
|
type: EggbugEmotion;
|
|
|
|
} & JSX.HTMLAttributes<HTMLImageElement>)["type"];
|
2023-07-31 17:07:27 -04:00
|
|
|
|
2023-08-23 20:31:10 -04:00
|
|
|
export const EggbugImg = ({
|
|
|
|
type,
|
|
|
|
...attrs
|
|
|
|
}: { type: EggbugEmotion } & Omit<
|
|
|
|
JSX.HTMLAttributes<HTMLImageElement>,
|
|
|
|
"type"
|
|
|
|
>) => eggbug_emotions(attrs)[type];
|
2023-07-12 12:55:08 -04:00
|
|
|
|
2023-07-20 14:31:12 -04:00
|
|
|
export const render_and_copy = (elem: VNode, pretty = false) => {
|
|
|
|
const rendered = render(elem, null, { pretty });
|
2023-07-12 14:15:53 -04:00
|
|
|
writeText(rendered);
|
|
|
|
console.log(rendered);
|
|
|
|
};
|
2023-07-15 22:53:32 -04:00
|
|
|
|
|
|
|
export const mk_class_wrapper =
|
|
|
|
(klass: string) =>
|
2023-07-20 14:31:12 -04:00
|
|
|
({ children }: { children?: ComponentChildren }) =>
|
2023-07-16 00:36:39 -04:00
|
|
|
<div class={klass}>{...toChildArray(children)}</div>;
|
2023-07-20 13:33:55 -04:00
|
|
|
|
|
|
|
export const slidify = (
|
|
|
|
Slide: (_: {
|
|
|
|
slide: JSX.Element;
|
|
|
|
next?: JSX.Element;
|
|
|
|
n: number;
|
|
|
|
max: number;
|
|
|
|
}) => JSX.Element,
|
|
|
|
slides: JSX.Element[],
|
|
|
|
n = 1,
|
|
|
|
max = slides.length
|
|
|
|
): JSX.Element =>
|
|
|
|
slides[0] ? (
|
|
|
|
<Slide
|
|
|
|
slide={slides[0]}
|
|
|
|
next={slidify(Slide, slides.slice(1), n + 1, max)}
|
|
|
|
n={n}
|
|
|
|
max={max}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
);
|
|
|
|
|
|
|
|
// https://cohost.org/lexyeevee/post/2107474-css-for-css-baby-3 (wayyy down at the bottom)
|
|
|
|
export const DisappearOnClick = ({
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
}: {
|
|
|
|
className?: string;
|
|
|
|
children: ComponentChildren;
|
|
|
|
}) => (
|
|
|
|
<details
|
|
|
|
open
|
|
|
|
class={`disappearing ${className}`}
|
|
|
|
style="position: relative; cursor: pointer;"
|
|
|
|
>
|
|
|
|
<summary style="list-style: none; position: absolute; inset: 0;"></summary>
|
|
|
|
{children}
|
|
|
|
</details>
|
|
|
|
);
|
2023-07-22 16:19:42 -04:00
|
|
|
|
2023-09-06 21:48:30 -04:00
|
|
|
/// make sure the margins are all legit
|
|
|
|
export const ToggleOnClick = ({
|
|
|
|
children: [a, b],
|
|
|
|
}: {
|
|
|
|
children: [ComponentChild, ComponentChild];
|
|
|
|
}) => (
|
|
|
|
<details style="position: relative; margin: 0 auto; cursor: pointer;">
|
|
|
|
<summary style="list-style: none;">{a}</summary>
|
|
|
|
<div style="display: block; position: absolute; top: 0; pointer-events: none;">
|
|
|
|
{b}
|
|
|
|
</div>
|
|
|
|
</details>
|
|
|
|
);
|
|
|
|
|
2023-09-21 23:42:42 -04:00
|
|
|
// TODO: probably doesn't work
|
|
|
|
export const ReduceOnClick = ({ children }: { children: VNode<{}>[] }) => {
|
|
|
|
if (children.length == 0) return <></>;
|
|
|
|
if (children.length == 1) return children[1];
|
|
|
|
return (
|
|
|
|
<details style="position: relative; margin: 0 auto; cursor: pointer;">
|
|
|
|
<summary style="list-style: none;">{children[0]}</summary>
|
|
|
|
<ReduceOnClick>{...children.slice(1)}</ReduceOnClick>
|
|
|
|
</details>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-07-22 16:19:42 -04:00
|
|
|
export function shuffle<T>(array: T[]): T[] {
|
|
|
|
let currentIndex = array.length,
|
|
|
|
randomIndex;
|
|
|
|
|
|
|
|
// While there remain elements to shuffle.
|
|
|
|
while (currentIndex != 0) {
|
|
|
|
// Pick a remaining element.
|
|
|
|
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
|
|
currentIndex--;
|
|
|
|
|
|
|
|
// And swap it with the current element.
|
|
|
|
[array[currentIndex], array[randomIndex]] = [
|
|
|
|
array[randomIndex],
|
|
|
|
array[currentIndex],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
// type NOf<N extends number, T, R extends any[] = []> = R["length"] extends N
|
|
|
|
// ? R
|
|
|
|
// : NOf<N, T, [T, ...R]>;
|
|
|
|
|
|
|
|
// export function n_of<N extends number, T, R extends any[]>(
|
|
|
|
// n: N,
|
|
|
|
// x: T
|
|
|
|
// ): NOf<N, T, R> {
|
|
|
|
// return [];
|
|
|
|
// }
|
|
|
|
|
|
|
|
export function n_of<T>(n: number, x: T): T[] {
|
|
|
|
return new Array(n).fill(x);
|
|
|
|
}
|
2023-07-25 01:41:07 -04:00
|
|
|
|
|
|
|
export const static_url = (res: string) => `https://static.pyrope.net/${res}`;
|
2023-08-20 13:33:54 -04:00
|
|
|
|
|
|
|
export const randirect = (...urls: string[]) =>
|
|
|
|
`https://pyrope.net/randirect#${urls.join("::")}`;
|
2023-09-02 21:08:44 -04:00
|
|
|
|
2023-09-24 07:31:25 -04:00
|
|
|
export const serverside_randirect = (...urls: string[]) =>
|
|
|
|
`https://pyrope.net/serverside-randirect?${urls.join("::")}`;
|
|
|
|
|
2023-09-02 21:08:44 -04:00
|
|
|
// could do some [T, ...T[]] shenanigans for totality but meh
|
|
|
|
// kinda bad name
|
2023-09-23 11:40:56 -04:00
|
|
|
// unhappy with the randomness so i'm going way overkill lol
|
|
|
|
export const pick_random = <T,>(xs: readonly T[]): T =>
|
2023-09-24 07:02:33 -04:00
|
|
|
xs[randomInt(xs.length)];
|
2023-09-04 23:22:46 -04:00
|
|
|
|
|
|
|
export const jitter = (n: number) => n * (Math.random() - 0.5);
|
2023-09-06 20:29:10 -04:00
|
|
|
|
|
|
|
export const svg_url = (svg: string) => `data:image/svg+xml,${encodeURI(svg)}`;
|
|
|
|
|
2023-09-06 21:01:47 -04:00
|
|
|
// something higher-level might be worthwhile...
|
|
|
|
// could namespace; e.g. css.font.sans_serif
|
2023-11-15 03:00:23 -05:00
|
|
|
// could put various beziers
|
2023-09-06 20:29:10 -04:00
|
|
|
export const css = {
|
|
|
|
url(href: string) {
|
|
|
|
return `url('${href}')`;
|
|
|
|
},
|
2023-09-06 21:01:47 -04:00
|
|
|
|
2023-09-06 20:29:10 -04:00
|
|
|
px(n: number) {
|
|
|
|
return `${n}px`;
|
|
|
|
},
|
|
|
|
em(n: number) {
|
|
|
|
return `${n}em`;
|
|
|
|
},
|
|
|
|
rem(n: number) {
|
|
|
|
return `${n}rem`;
|
|
|
|
},
|
2023-09-06 21:01:47 -04:00
|
|
|
|
|
|
|
deg(n: number) {
|
|
|
|
return `${n}deg`;
|
|
|
|
},
|
|
|
|
rad(n: number) {
|
|
|
|
return `${n}rad`;
|
|
|
|
},
|
|
|
|
turn(n: number) {
|
|
|
|
return `${n}turn`;
|
|
|
|
},
|
|
|
|
// now i feel like this could be generalizable
|
|
|
|
// but js metaprogramming SUCKS
|
|
|
|
transform(...ts: string[]) {
|
|
|
|
return ts.join(" ");
|
|
|
|
},
|
|
|
|
rotate(by: string) {
|
|
|
|
return `rotate(${by})`;
|
|
|
|
},
|
|
|
|
translateX(by: string) {
|
|
|
|
return `translateX(${by})`;
|
|
|
|
},
|
|
|
|
translateY(by: string) {
|
|
|
|
return `translateY(${by})`;
|
|
|
|
},
|
|
|
|
translate(x: string, y: string) {
|
|
|
|
return `translate(${x}, ${y})`;
|
|
|
|
},
|
|
|
|
|
|
|
|
fontstack(...fonts: string[]) {
|
|
|
|
return fonts.join(", ");
|
|
|
|
},
|
|
|
|
// # ruby i wont you ..
|
2023-09-06 20:29:10 -04:00
|
|
|
inline_block: "inline-block",
|
|
|
|
block: "block",
|
|
|
|
grid: "grid",
|
|
|
|
flex: "flex",
|
2023-09-06 21:01:47 -04:00
|
|
|
fit_content: "fit-content",
|
|
|
|
min_content: "min-content",
|
|
|
|
max_content: "max-content",
|
2023-09-06 20:29:10 -04:00
|
|
|
} as const;
|
2023-09-09 13:02:51 -04:00
|
|
|
|
|
|
|
export const Filler = ({ height }: { height: string }) => (
|
|
|
|
<div style={`height:${height}`}></div>
|
|
|
|
);
|
2023-09-21 23:42:42 -04:00
|
|
|
|
2023-09-23 11:40:56 -04:00
|
|
|
/// nonfunctional, deno's toplevel await (:D) is generally the best workaround
|
2023-09-21 23:42:42 -04:00
|
|
|
export function make_sync_no_matter_the_cost<T>(promise: Promise<T>): T {
|
|
|
|
let done = false;
|
|
|
|
let out;
|
|
|
|
|
|
|
|
promise.then(t => {
|
|
|
|
out = t;
|
|
|
|
done = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return out as T;
|
|
|
|
}
|
2023-11-28 00:32:25 -05:00
|
|
|
|
|
|
|
// INFINITE CREDIT TO @BLACKLE https://cohost.org/blackle/post/72096-h3-style-text-alig
|
|
|
|
export const Cycle = ({
|
|
|
|
width_px,
|
|
|
|
height_px,
|
|
|
|
children,
|
|
|
|
style,
|
2024-01-04 21:31:57 -05:00
|
|
|
credit = true,
|
2023-11-28 00:32:25 -05:00
|
|
|
}: {
|
|
|
|
width_px: number;
|
|
|
|
height_px: number;
|
|
|
|
children: [ComponentChild, ...ComponentChild[]];
|
|
|
|
style?: Record<string, string>;
|
2024-01-04 21:31:57 -05:00
|
|
|
credit?: boolean;
|
2023-11-28 00:32:25 -05:00
|
|
|
}) => (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
width: `${width_px}px`,
|
|
|
|
height: `${height_px}px`,
|
|
|
|
overflow: "hidden",
|
2024-01-04 21:31:57 -05:00
|
|
|
...(credit
|
|
|
|
? {
|
|
|
|
filter: "url(https://mehbark.github.io/#INFINITE%20CREDIT%20TO%20@BLACKLE)",
|
|
|
|
}
|
|
|
|
: {}),
|
2023-11-28 00:32:25 -05:00
|
|
|
...style,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: "inline-flex",
|
|
|
|
height: `${height_px}px`,
|
|
|
|
paddingRight: `${width_px}px`,
|
|
|
|
position: "relative",
|
|
|
|
cursor: "pointer",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{...children.map((c, i) => (
|
|
|
|
<details>
|
|
|
|
<summary
|
|
|
|
style={{
|
|
|
|
position: "absolute",
|
|
|
|
top: "0px",
|
|
|
|
left: `calc(-${width_px * 100}% + ${
|
|
|
|
width_px * width_px + width_px * i
|
|
|
|
}px)`,
|
|
|
|
// width: `${width_px}px`,
|
|
|
|
width: `calc(${
|
|
|
|
width_px * (children.length - 1) * 2 +
|
|
|
|
width_px -
|
|
|
|
width_px * i * 2
|
|
|
|
}px)`,
|
|
|
|
height: `${height_px}px`,
|
|
|
|
listStyle: "none",
|
|
|
|
overflow: "hidden",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{c}
|
|
|
|
</summary>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
width: `${
|
|
|
|
i == children.length - 1
|
|
|
|
? children.length - 1
|
|
|
|
: 1
|
|
|
|
}px`,
|
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
</details>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|