Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle TimelineRangeOffsets (rangeStart / rangeEnd) #121

Merged
merged 8 commits into from
Aug 17, 2023
Prev Previous commit
Next Next commit
Remove animation-delay/animation-end-delay from CSS parser
  • Loading branch information
bramus committed Aug 17, 2023
commit 2517b08cff4b8c790be53439fb12416e3e0db93c
29 changes: 6 additions & 23 deletions src/scroll-timeline-css-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export const RegexMatcher = {
VIEW_TIMELINE_AXIS: /view-timeline-axis\s*:([^;}]+)/,
VIEW_TIMELINE_INSET: /view-timeline-inset\s*:([^;}]+)/,
ANIMATION_TIMELINE: /animation-timeline\s*:([^;}]+)/,
ANIMATION_DELAY: /animation-delay\s*:([^;}]+)/,
ANIMATION_END_DELAY: /animation-end-delay\s*:([^;}]+)/,
ANIMATION_TIME_RANGE: /animation-range\s*:([^;}]+)/,
ANIMATION_NAME: /animation-name\s*:([^;}]+)/,
ANIMATION: /animation\s*:([^;}]+)/,
Expand Down Expand Up @@ -101,8 +99,6 @@ export class StyleParser {
if (!current['animation-name'] || current['animation-name'] == animationName) {
return {
'animation-timeline': current['animation-timeline'],
'animation-delay': current['animation-delay'],
'animation-end-delay': current['animation-end-delay'],
'animation-range': current['animation-range']
}
}
Expand Down Expand Up @@ -420,34 +416,21 @@ export class StyleParser {
}

saveRelationInList(rule, timelineNames, animationNames) {
const hasAnimationDelay = rule.block.contents.includes("animation-delay:");
const hasAnimationEndDelay = rule.block.contents.includes("animation-end-delay:");
const hasAnimationTimeRange = rule.block.contents.includes("animation-range:");
const hasAnimationRange = rule.block.contents.includes("animation-range:");
let animationRanges = [];

let animationDelays = [];
let animationEndDelays = [];
let animationTimeRanges = [];

if (hasAnimationDelay)
animationDelays = this.extractMatches(rule.block.contents, RegexMatcher.ANIMATION_DELAY);

if (hasAnimationEndDelay)
animationEndDelays = this.extractMatches(rule.block.contents, RegexMatcher.ANIMATION_END_DELAY);

if (hasAnimationTimeRange)
animationTimeRanges = this.extractMatches(rule.block.contents, RegexMatcher.ANIMATION_TIME_RANGE);
if (hasAnimationRange)
animationRanges = this.extractMatches(rule.block.contents, RegexMatcher.ANIMATION_TIME_RANGE);

const maxLength = Math.max(timelineNames.length, animationNames.length,
animationDelays.length, animationEndDelays.length, animationTimeRanges.length);
animationRanges.length);

for (let i = 0; i < maxLength; i++) {
this.cssRulesWithTimelineName.push({
selector: rule.selector,
'animation-timeline': timelineNames[i % timelineNames.length],
...(animationNames.length ? {'animation-name': animationNames[i % animationNames.length]}: {}),
...(animationDelays.length ? {'animation-delay': animationDelays[i % animationDelays.length]}: {}),
...(animationEndDelays.length ? {'animation-end-delay': animationEndDelays[i % animationEndDelays.length]}: {}),
...(animationTimeRanges.length ? {'animation-range': animationTimeRanges[i % animationTimeRanges.length]}: {}),
...(animationRanges.length ? {'animation-range': animationRanges[i % animationRanges.length]}: {}),
});
}
}
Expand Down