export function uuidV4() { // ref: https://stackoverflow.com/a/2117523 try { const globalCrypto = crypto as any; if (globalCrypto?.randomUUID) { return globalCrypto.randomUUID(); } if (globalCrypto?.getRandomValues && Uint8Array) { return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) => (Number(c) ^ (globalCrypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (Number(c) / 4)))).toString(16), ); } } catch (_e) {} return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { const r = (Math.random() * 16) | 0; const v = c === 'x' ? r : (r & 0x3) | 0x8; return v.toString(16); }); }