Open History to see the last commit
1/**
2 * Id source for picker annotations and their targets, one per page load.
3 *
4 * The composer keeps annotations keyed by id across preview reloads, and this
5 * preload restarts on every page load, so a bare counter reissues ids that a
6 * draft already holds. `getRandomValues` rather than `randomUUID`, because
7 * plain-http previews (LAN, tailnet) are not secure contexts.
8 */
9export function createAnnotationIdSource(): (prefix: string) => string {
10 const pageLoad = Array.from(crypto.getRandomValues(new Uint32Array(2)), (part) =>
11 part.toString(36),
12 ).join("");
13 let sequence = 0;
14 return (prefix) => {
15 sequence += 1;
16 return `${prefix}_${pageLoad}_${sequence.toString(36)}`;
17 };
18}