MCPcopy Create free account
hub / github.com/angular/angular / _scopeAnimationRule

Method _scopeAnimationRule

packages/compiler/src/shadow_css.ts:359–406  ·  view source on GitHub ↗

* Scope an animation rule so that the keyframes mentioned in such rule * are scoped if defined in the component's css and left untouched otherwise. * * It can scope values of both the 'animation' and 'animation-name' properties. * * @param rule css rule to scope. * @param scopeSele

(
    rule: CssRule,
    scopeSelector: string,
    unscopedKeyframesSet: ReadonlySet<string>,
  )

Source from the content-addressed store, hash-verified

357 * @returns the updated css rule.
358 **/
359 private _scopeAnimationRule(
360 rule: CssRule,
361 scopeSelector: string,
362 unscopedKeyframesSet: ReadonlySet<string>,
363 ): CssRule {
364 let content = rule.content.replace(
365 /((?:^|\s+|;)(?:-webkit-)?animation\s*:\s*)([^;]+)/g,
366 (_, start, animationDeclarations) =>
367 start +
368 animationDeclarations.replace(
369 this._animationDeclarationKeyframesRe,
370 (
371 original: string,
372 leadingSpaces: string,
373 quote = '',
374 quotedName: string,
375 nonQuotedName: string,
376 ) => {
377 if (quotedName) {
378 return `${leadingSpaces}${this._scopeAnimationKeyframe(
379 `${quote}${quotedName}${quote}`,
380 scopeSelector,
381 unscopedKeyframesSet,
382 )}`;
383 } else {
384 return animationKeywords.has(nonQuotedName)
385 ? original
386 : `${leadingSpaces}${this._scopeAnimationKeyframe(
387 nonQuotedName,
388 scopeSelector,
389 unscopedKeyframesSet,
390 )}`;
391 }
392 },
393 ),
394 );
395 content = content.replace(
396 /((?:^|\s+|;)(?:-webkit-)?animation-name(?:\s*):(?:\s*))([^;]+)/g,
397 (_match, start, commaSeparatedKeyframes) =>
398 `${start}${commaSeparatedKeyframes
399 .split(',')
400 .map((keyframe: string) =>
401 this._scopeAnimationKeyframe(keyframe, scopeSelector, unscopedKeyframesSet),
402 )
403 .join(',')}`,
404 );
405 return {...rule, content};
406 }
407
408 /* Ensure styles are scoped. Pseudo-scoping takes a rule like:
409 *

Callers 1

Calls 5

mapMethod · 0.80
hasMethod · 0.65
joinMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected