(prefix = "figma")
| 55 | |
| 56 | // Generate a class name - prefer direct uniqueId, but fall back to counter-based if needed |
| 57 | export function generateUniqueClassName(prefix = "figma"): string { |
| 58 | // Sanitize the prefix to ensure valid CSS class |
| 59 | const sanitizedPrefix = |
| 60 | prefix.replace(/[^a-zA-Z0-9_-]/g, "").replace(/^[0-9_-]/, "f") || // Ensure it doesn't start with a number or special char |
| 61 | "figma"; |
| 62 | |
| 63 | // Most of the time, we'll just use the prefix directly as it's pre-generated to be unique |
| 64 | // But keep the counter logic as a fallback |
| 65 | const count = classNameCounters.get(sanitizedPrefix) || 0; |
| 66 | classNameCounters.set(sanitizedPrefix, count + 1); |
| 67 | |
| 68 | // Only add suffix if this isn't the first instance |
| 69 | return count === 0 |
| 70 | ? sanitizedPrefix |
| 71 | : `${sanitizedPrefix}_${count.toString().padStart(2, "0")}`; |
| 72 | } |
| 73 | |
| 74 | // Reset all class name counters - call this at the start of processing |
| 75 | export function resetClassNameCounters(): void { |
no test coverage detected