File size: 3,014 Bytes
fc93158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import type { FileContents, FileDiffMetadata, SupportedLanguages } from "@pierre/diffs";

export const DIFF_LAYOUTS = ["unified", "split"] as const;
export const DIFF_MODES = ["view", "image", "file", "both"] as const;
export const DIFF_THEMES = ["light", "dark"] as const;
export const DIFF_INDICATORS = ["bars", "classic", "none"] as const;
export const DIFF_IMAGE_QUALITY_PRESETS = ["standard", "hq", "print"] as const;
export const DIFF_OUTPUT_FORMATS = ["png", "pdf"] as const;

export type DiffLayout = (typeof DIFF_LAYOUTS)[number];
export type DiffMode = (typeof DIFF_MODES)[number];
export type DiffTheme = (typeof DIFF_THEMES)[number];
export type DiffIndicators = (typeof DIFF_INDICATORS)[number];
export type DiffImageQualityPreset = (typeof DIFF_IMAGE_QUALITY_PRESETS)[number];
export type DiffOutputFormat = (typeof DIFF_OUTPUT_FORMATS)[number];

export type DiffPresentationDefaults = {
  fontFamily: string;
  fontSize: number;
  lineSpacing: number;
  layout: DiffLayout;
  showLineNumbers: boolean;
  diffIndicators: DiffIndicators;
  wordWrap: boolean;
  background: boolean;
  theme: DiffTheme;
};

export type DiffFileDefaults = {
  fileFormat: DiffOutputFormat;
  fileQuality: DiffImageQualityPreset;
  fileScale: number;
  fileMaxWidth: number;
};

export type DiffToolDefaults = DiffPresentationDefaults &
  DiffFileDefaults & {
    mode: DiffMode;
  };

export type BeforeAfterDiffInput = {
  kind: "before_after";
  before: string;
  after: string;
  path?: string;
  lang?: string;
  title?: string;
};

export type PatchDiffInput = {
  kind: "patch";
  patch: string;
  title?: string;
};

export type DiffInput = BeforeAfterDiffInput | PatchDiffInput;

export type DiffRenderOptions = {
  presentation: DiffPresentationDefaults;
  image: {
    format: DiffOutputFormat;
    qualityPreset: DiffImageQualityPreset;
    scale: number;
    maxWidth: number;
    maxPixels: number;
  };
  expandUnchanged: boolean;
};

export type DiffViewerOptions = {
  theme: {
    light: "pierre-light";
    dark: "pierre-dark";
  };
  diffStyle: DiffLayout;
  diffIndicators: DiffIndicators;
  disableLineNumbers: boolean;
  expandUnchanged: boolean;
  themeType: DiffTheme;
  backgroundEnabled: boolean;
  overflow: "scroll" | "wrap";
  unsafeCSS: string;
};

export type DiffViewerPayload = {
  prerenderedHTML: string;
  options: DiffViewerOptions;
  langs: SupportedLanguages[];
  oldFile?: FileContents;
  newFile?: FileContents;
  fileDiff?: FileDiffMetadata;
};

export type RenderedDiffDocument = {
  html: string;
  imageHtml: string;
  title: string;
  fileCount: number;
  inputKind: DiffInput["kind"];
};

export type DiffArtifactMeta = {
  id: string;
  token: string;
  createdAt: string;
  expiresAt: string;
  title: string;
  inputKind: DiffInput["kind"];
  fileCount: number;
  viewerPath: string;
  htmlPath: string;
  filePath?: string;
  imagePath?: string;
};

export const DIFF_ARTIFACT_ID_PATTERN = /^[0-9a-f]{20}$/;
export const DIFF_ARTIFACT_TOKEN_PATTERN = /^[0-9a-f]{48}$/;