/** * UUIDを生成するためのユーティリティ関数です。 * crypto.randomUUID() のラッパーであり、非セキュアなコンテキスト(HTTPや古いブラウザなど)向けのフォールバック提供します。 */ export const generateUUID = (): string => { // crypto.randomUUID が利用可能かチェック (セキュアなコンテキスト HTTPS/localhost でのみ利用可能) if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') { return crypto.randomUUID(); } // 非セキュアなコンテキストや古いブラウザ向けのフォールバック (RFC4122 v4 互換) 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); }); };