New module packages/core/src/random.ts with randomHex, randomInt, randomIndex — centralizes all crypto-based randomness. Replaces: - Date.now() IDs in VariablesDialog (not unique, not random) - Hand-rolled hex token in automation/server.ts - Inline crypto.getRandomValues in clipboard.ts, use-collab.ts Also adds --color-component Tailwind theme color (#9747ff) and replaces all 6 hardcoded occurrences across DesignPanel, LayerTree, NodeContextMenuContent, and menu.ts.
15 lines
415 B
TypeScript
15 lines
415 B
TypeScript
export function randomHex(bytes = 16): string {
|
|
const buf = crypto.getRandomValues(new Uint8Array(bytes))
|
|
let hex = ''
|
|
for (const b of buf) hex += b.toString(16).padStart(2, '0')
|
|
return hex
|
|
}
|
|
|
|
export function randomInt(): number {
|
|
return crypto.getRandomValues(new Int32Array(1))[0]
|
|
}
|
|
|
|
export function randomIndex(length: number): number {
|
|
return crypto.getRandomValues(new Uint8Array(1))[0] % length
|
|
}
|