/**
 * Returns a SHA-256 hex digest of the normalised source text.
 * NFC normalisation and trim are applied before hashing, so purely whitespace-only
 * source edits (leading/trailing spaces, equivalent Unicode sequences) produce
 * the same hash and are intentionally treated as unchanged.
 */
const encoder = new TextEncoder()

export async function hashSource(text: string): Promise<string> {
  const normalized = text.normalize('NFC').trim()
  const data = encoder.encode(normalized)
  const digest = await crypto.subtle.digest('SHA-256', data)
  return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, '0')).join('')
}
