| 1 |
import type { Readable } from "svelte/store"; |
| 2 |
import { writable } from "svelte/store"; |
| 3 |
|
| 4 |
const ledger_mtime_writable = writable(BigInt("0")); |
| 5 |
|
| 6 |
/** |
| 7 |
* Last file change to one of the source files of the current ledger. |
| 8 |
*/ |
| 9 |
export const ledger_mtime: Readable<bigint> = ledger_mtime_writable; |
| 10 |
|
| 11 |
/** |
| 12 |
* Set the mtime from the given string value. |
| 13 |
*/ |
| 14 |
export function set_mtime(text: string): void { |
| 15 |
const new_value = text.startsWith("X") |
| 16 |
? // the timestamp is replaced by a sequence of `X` in incognito mode. |
| 17 |
BigInt(text.replaceAll("X", "1")) |
| 18 |
: BigInt(text); |
| 19 |
ledger_mtime_writable.update((v) => (new_value > v ? new_value : v)); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Read the mtime from the HTML source. |
| 24 |
*/ |
| 25 |
export function read_mtime(): void { |
| 26 |
const el = document.getElementById("ledger-mtime"); |
| 27 |
const text = el?.textContent; |
| 28 |
if (text != null) { |
| 29 |
el?.remove(); |
| 30 |
set_mtime(text); |
| 31 |
} |
| 32 |
} |