Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/solid-motion-experiments.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125/* @refresh skip */import type { Component } from "solid-js";import { Dynamic, generateHydrationScript, renderToString } from "solid-js/web";
import { motion } from "../index.ts";
export const SSR_HYDRATION_CONTROL_CASES = [ "plain-div", "plain-svg", "dynamic-div",] as const;
export const SSR_HYDRATION_MOTION_CASES = [ "explicit-initial", "initial-false", "omitted-initial", "svg-style", "css-vars-transform",] as const;
export const SSR_HYDRATION_CASES = [ ...SSR_HYDRATION_CONTROL_CASES, ...SSR_HYDRATION_MOTION_CASES,] as const;
export type SsrHydrationControlCaseName = typeof SSR_HYDRATION_CONTROL_CASES[number];export type SsrHydrationMotionCaseName = typeof SSR_HYDRATION_MOTION_CASES[number];export type SsrHydrationCaseName = typeof SSR_HYDRATION_CASES[number];
export function renderIdForHydrationCase(name: SsrHydrationCaseName): string { return `solid-motion-${name}`;}
const cases: Record<SsrHydrationCaseName, Component> = { "plain-div": () => ( <div data-testid="plain-div" style={{ opacity: 1, color: "red" }} /> ), "plain-svg": () => ( <svg data-testid="plain-svg" viewBox="0 0 10 10" style={{ opacity: 0.5 }} > <path d="M0 0 L10 10" /> </svg> ), "dynamic-div": () => ( <Dynamic component="div" data-testid="dynamic-div" style={{ opacity: 1, color: "blue" }} /> ), "explicit-initial": () => ( <motion.div data-testid="explicit-initial" initial={{ opacity: 0, x: 4 }} animate={{ opacity: 1, x: 0 }} transition={{ duration: 0 }} /> ), "initial-false": () => ( <motion.div data-testid="initial-false" initial={false} animate={{ opacity: 1, x: 12 }} transition={{ duration: 0 }} /> ), "omitted-initial": () => ( <motion.div data-testid="omitted-initial" animate={{ opacity: 1, x: 12 }} transition={{ duration: 0 }} /> ), "svg-style": () => ( <motion.svg data-testid="svg-style" viewBox="0 0 10 10" initial={{ opacity: 0.5 }} animate={{ opacity: 1 }} style={{ "--svg-alpha": "0.4" }} transition={{ duration: 0 }} > <path d="M0 0 L10 10" /> </motion.svg> ), "css-vars-transform": () => ( <motion.div data-testid="css-vars-transform" style={{ "--brand-alpha": "0.75", x: 4 }} initial={false} animate={{ opacity: 1, x: 12 }} transition={{ duration: 0 }} /> ),};
export const SsrHydrationFixture: Component<{ name: SsrHydrationCaseName }> = (props) => { const Case = cases[props.name]; return <Case />;};
export interface SsrHydrationFixtureMarkup { html: string; hydrationScript: string;}
export function renderSsrHydrationFixture(name: SsrHydrationCaseName): string { return renderToString(() => <SsrHydrationFixture name={name} />, { renderId: renderIdForHydrationCase(name), });}
export function renderSsrHydrationFixtureMarkup(name: SsrHydrationCaseName): SsrHydrationFixtureMarkup { return { html: renderSsrHydrationFixture(name), hydrationScript: generateHydrationScript(), };}