import { TempstreamJSX } from "tempstream"; import type { ComponentToHTMLArgs, ExtractStructuredComponentArgumentsParsed, JDDContext, } from "@sealcode/jdd"; import { Component, ComponentArguments } from "@sealcode/jdd"; import arrow from "./autoscrolling-images-arrow.svg"; import type { FilePointer } from "@sealcode/file-manager"; import type { makeJDDContext } from "../../jdd-context.js"; const images = new ComponentArguments.List( new ComponentArguments.Structured({ image: new ComponentArguments.Image(), alt: new ComponentArguments.ShortText(), }) ); images.getExampleCount = () => { return Math.round(4 + Math.random() * 9); }; const component_arguments = { title: new ComponentArguments.ShortText(), imagesPerPage: new ComponentArguments.ShortText().setExampleValues(["6"]), background_mode: new ComponentArguments.Enum([ "transparent", "white", "white-square", ]), speed: new ComponentArguments.ShortText().setExampleValues(["5"]), desktop_interval: new ComponentArguments.ShortText().setExampleValues(["5"]), endless: new ComponentArguments.Enum(["true", "false"]), images, } as const; function renderimagePageArrows({ radioButtonIdPrefix, pageIndex, imagePages, }: { radioButtonIdPrefix: string; pageIndex: number; imagePages: Array>>; }) { return (
); } export function renderImagePage({ page, render_image, mode = "regular", background_mode, }: { page: Array<{ image: FilePointer | null; alt: string }>; render_image: ReturnType["render_image"]; mode?: "regular" | "looping-tail" | "looping-head"; background_mode: "white" | "white-square" | "transparent"; }): JSX.Element { return (
{page.map((image) => (
{render_image(image.image, { container: { ...(background_mode == "white-square" ? { width: 128, height: 128 } : { width: 212, height: 150 }), objectFit: "contain", }, alt: image.alt, lossless: true, thumbnailSize: 0, })}
))}
); } export class AutoscrollingImages extends Component { getArguments() { return component_arguments; } getTitle( _: JDDContext, args: ExtractStructuredComponentArgumentsParsed ) { return args.title || null; } toHTML({ args: { title, imagesPerPage, images, speed, desktop_interval, background_mode, endless, }, jdd_context: { render_image }, classes, index, }: ComponentToHTMLArgs) { const imageNumberPerPage = parseInt(imagesPerPage); const imagePages: (typeof images)[] = []; for (let i = 0; i < images.length; i += imageNumberPerPage) { imagePages.push(images.slice(i, i + imageNumberPerPage)); } const radioButtonIdPrefix = "r" + Math.floor(100 + Math.random() * 900); const radioButton_name = `autoscrolling-images__radio--${radioButtonIdPrefix}`; return (

{title}

{imagePages.length > 1 ? ( ) : ( "" )}
); } }