(css: string)
| 294 | } |
| 295 | |
| 296 | function collectKeyframeBlocks(css: string): { |
| 297 | keyframes: Array<{ name: string; stops: CssKeyframeStop[] }>; |
| 298 | ranges: Array<{ start: number; end: number }>; |
| 299 | } { |
| 300 | const keyframes: Array<{ name: string; stops: CssKeyframeStop[] }> = []; |
| 301 | const ranges: Array<{ start: number; end: number }> = []; |
| 302 | const re = /@keyframes\s+([a-zA-Z0-9_-]+)/g; |
| 303 | let match: RegExpExecArray | null; |
| 304 | while ((match = re.exec(css))) { |
| 305 | const open = css.indexOf("{", re.lastIndex); |
| 306 | const block = open >= 0 ? readBalancedBlock(css, open) : null; |
| 307 | if (!block) continue; |
| 308 | ranges.push({ start: match.index, end: block.end }); |
| 309 | const stops: CssKeyframeStop[] = []; |
| 310 | const stopRe = /([^{}]+)\{([^{}]*)\}/g; |
| 311 | let stop: RegExpExecArray | null; |
| 312 | while ((stop = stopRe.exec(block.body))) { |
| 313 | stops.push({ |
| 314 | selector: stop[1]!.trim().replace(/\s+/g, " "), |
| 315 | declarations: parseDeclarations(stop[2]!), |
| 316 | }); |
| 317 | } |
| 318 | keyframes.push({ name: match[1]!, stops }); |
| 319 | } |
| 320 | return { keyframes, ranges }; |
| 321 | } |
| 322 | |
| 323 | function stripQuotes(raw: string): string { |
| 324 | return raw.trim().replace(/^["']|["']$/g, ""); |
no test coverage detected