Open History to see the last commit
1export const DIFF_THEME_NAMES = {
2 light: "pierre-light",
3 dark: "pierre-dark",
4} as const;
5
6export type DiffThemeName = (typeof DIFF_THEME_NAMES)[keyof typeof DIFF_THEME_NAMES];
7
8export function resolveDiffThemeName(theme: "light" | "dark"): DiffThemeName {
9 return theme === "dark" ? DIFF_THEME_NAMES.dark : DIFF_THEME_NAMES.light;
10}
11
12const FNV_OFFSET_BASIS_32 = 0x811c9dc5;
13const FNV_PRIME_32 = 0x01000193;
14const SECONDARY_HASH_SEED = 0x9e3779b9;
15const SECONDARY_HASH_MULTIPLIER = 0x85ebca6b;
16
17export function fnv1a32(
18 input: string,
19 seed = FNV_OFFSET_BASIS_32,
20 multiplier = FNV_PRIME_32,
21): number {
22 let hash = seed >>> 0;
23 for (let index = 0; index < input.length; index += 1) {
24 hash ^= input.charCodeAt(index);
25 hash = Math.imul(hash, multiplier) >>> 0;
26 }
27 return hash >>> 0;
28}
29
30export function buildPatchCacheKey(patch: string, scope = "diff-panel"): string {
31 const normalizedPatch = patch.trim();
32 const primary = fnv1a32(normalizedPatch, FNV_OFFSET_BASIS_32, FNV_PRIME_32).toString(36);
33 const secondary = fnv1a32(
34 normalizedPatch,
35 SECONDARY_HASH_SEED,
36 SECONDARY_HASH_MULTIPLIER,
37 ).toString(36);
38 return `${scope}:${normalizedPatch.length}:${primary}:${secondary}`;
39}