From c0a35141e6b70eed1a9ba576fe43b7f7d690b968 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Tue, 2 Dec 2025 06:50:16 -0600 Subject: feat: better code and diff rendering performance --- packages/ui/src/pierre/index.ts | 77 ++++++++++++++++++++++++++++++++++++++++ packages/ui/src/pierre/worker.ts | 5 +++ 2 files changed, 82 insertions(+) create mode 100644 packages/ui/src/pierre/index.ts create mode 100644 packages/ui/src/pierre/worker.ts (limited to 'packages/ui/src/pierre') diff --git a/packages/ui/src/pierre/index.ts b/packages/ui/src/pierre/index.ts new file mode 100644 index 000000000..26e902d05 --- /dev/null +++ b/packages/ui/src/pierre/index.ts @@ -0,0 +1,77 @@ +import { DiffLineAnnotation, FileContents, FileDiffOptions } from "@pierre/precision-diffs" +import { ComponentProps } from "solid-js" + +export type DiffProps = FileDiffOptions & { + before: FileContents + after: FileContents + annotations?: DiffLineAnnotation[] + class?: string + classList?: ComponentProps<"div">["classList"] +} + +export function createDefaultOptions(style: FileDiffOptions["diffStyle"]) { + return { + theme: "OpenCode", + themeType: "system", + disableLineNumbers: false, + overflow: "wrap", + diffStyle: style ?? "unified", + diffIndicators: "bars", + disableBackground: false, + expansionLineCount: 20, + lineDiffType: style === "split" ? "word-alt" : "none", + maxLineDiffLength: 1000, + maxLineLengthForHighlighting: 1000, + disableFileHeader: true, + unsafeCSS: ` +[data-pjs-header], +[data-pjs] { + [data-separator-wrapper] { + margin: 0 !important; + border-radius: 0 !important; + } + [data-expand-button] { + width: 6.5ch !important; + height: 24px !important; + justify-content: end !important; + padding-left: 3ch !important; + padding-inline: 1ch !important; + } + [data-separator-multi-button] { + grid-template-rows: 10px 10px !important; + [data-expand-button] { + height: 12px !important; + } + } + [data-separator-content] { + height: 24px !important; + } +}`, + // hunkSeparators(hunkData: HunkData) { + // const fragment = document.createDocumentFragment() + // const numCol = document.createElement("div") + // numCol.innerHTML = ` ` + // numCol.dataset["slot"] = "diff-hunk-separator-line-number" + // fragment.appendChild(numCol) + // const contentCol = document.createElement("div") + // contentCol.dataset["slot"] = "diff-hunk-separator-content" + // const span = document.createElement("span") + // span.dataset["slot"] = "diff-hunk-separator-content-span" + // span.textContent = `${hunkData.lines} unmodified lines` + // contentCol.appendChild(span) + // fragment.appendChild(contentCol) + // return fragment + // }, + } as const +} + +export const styleVariables = { + "--pjs-font-family": "var(--font-family-mono)", + "--pjs-font-size": "var(--font-size-small)", + "--pjs-line-height": "24px", + "--pjs-tab-size": 2, + "--pjs-font-features": "var(--font-family-mono--font-feature-settings)", + "--pjs-header-font-family": "var(--font-family-sans)", + "--pjs-gap-block": 0, + "--pjs-min-number-column-width": "4ch", +} diff --git a/packages/ui/src/pierre/worker.ts b/packages/ui/src/pierre/worker.ts new file mode 100644 index 000000000..de5fd625a --- /dev/null +++ b/packages/ui/src/pierre/worker.ts @@ -0,0 +1,5 @@ +import ShikiWorkerUrl from "@pierre/precision-diffs/worker/shiki-worker.js?worker&url" + +export function workerFactory(): Worker { + return new Worker(ShikiWorkerUrl, { type: "module" }) +} -- cgit v1.2.3