import { Attributes, ComponentChild, ComponentChildren, JSX, VNode, toChildArray, } from "preact"; import { render } from "preact-render-to-string"; import { writeText } from "copy-paste"; export function Main({ children, ...attributes }: { children?: ComponentChildren; style?: JSX.CSSProperties; attributes?: JSX.HTMLAttributes; }) { return (
{...toChildArray(children)}
); } export const HCenter = ({ children, ...attrs }: { children: ComponentChildren; attrs?: Attributes; }) => (
{...toChildArray(children)}
); export const eggbug_emotions = { smiling: ( eggbug, smiling ), frowning: ( eggbug, frowning ), revengeance: ( ULTRA EGGBUG REVENGEANCE, MEGA. THERE IS FIRE. THERE IS TRISCAR. EGGBUG REVENGEANCE. YOU ARE. DIE! ), jpeg_annihilation: ( eggbug dissolving as the image gets more and more jpeg ), } as const; export type EggbugEmotion = keyof typeof eggbug_emotions; export const EggbugImg = ({ type }: { type: EggbugEmotion }) => eggbug_emotions[type]; export const render_and_copy = (elem: VNode, pretty = false) => { const rendered = render(elem, null, { pretty }); writeText(rendered); console.log(rendered); }; export const mk_class_wrapper = (klass: string) => ({ children }: { children?: ComponentChildren }) =>
{...toChildArray(children)}
; 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] ? ( ) : ( <> ); // 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; }) => (
{children}
); export function shuffle(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 = R["length"] extends N // ? R // : NOf; // export function n_of( // n: N, // x: T // ): NOf { // return []; // } export function n_of(n: number, x: T): T[] { return new Array(n).fill(x); } export const static_url = (res: string) => `https://static.pyrope.net/${res}`; export const randirect = (...urls: string[]) => `https://pyrope.net/randirect#${urls.join("::")}`;