import { type FileContents, File, FileOptions, LineAnnotation } from "@pierre/precision-diffs" import { ComponentProps, createEffect, splitProps } from "solid-js" import { createDefaultOptions, styleVariables } from "../pierre" import { getOrCreateWorkerPoolSingleton } from "@pierre/precision-diffs/worker" import { workerFactory } from "../pierre/worker" const workerPool = getOrCreateWorkerPoolSingleton({ poolOptions: { workerFactory, // poolSize defaults to 8. More workers = more parallelism but // also more memory. Too many can actually slow things down. // poolSize: 8, }, highlighterOptions: { theme: "OpenCode", // Optionally preload languages to avoid lazy-loading delays // langs: ["typescript", "javascript", "css", "html"], }, }) 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"]) createEffect(() => { const instance = new File( { ...createDefaultOptions("unified"), ...others, }, workerPool, ) container.innerHTML = "" instance.render({ file: local.file, lineAnnotations: local.annotations, containerWrapper: container, }) }) return (
) }