import { type FileContents, File, FileOptions, LineAnnotation } from "@pierre/diffs" import { ComponentProps, createEffect, createMemo, splitProps } from "solid-js" import { createDefaultOptions, styleVariables } from "../pierre" import { workerPool } from "../pierre/worker" export type CodeProps = FileOptions & { file: FileContents annotations?: LineAnnotation[] class?: string classList?: ComponentProps<"div">["classList"] } export function Code(props: CodeProps) { let container!: HTMLDivElement const [local, others] = splitProps(props, ["file", "class", "classList", "annotations"]) const file = createMemo( () => new File( { ...createDefaultOptions("unified"), ...others, }, workerPool, ), ) createEffect(() => { container.innerHTML = "" file().render({ file: local.file, lineAnnotations: local.annotations, containerWrapper: container, }) }) return (
) }