class Inkcite::Animation::Keyframe

Attributes

duration[RW]

Ending percentage the animation stays at this keyframe. For example, a keyframe that starts at 20% and has a duration of 19.9% would render as 25%, 39.9% { … }

end_percent[RW]

Alternative to duration, the ending percentage

percent[R]
style[R]

Public Class Methods

new(percent, ctx, styles={}) click to toggle source
# File lib/inkcite/facade/keyframe.rb, line 15
def initialize percent, ctx, styles={}

  # Animation percents are always rounded to the nearest whole number.
  @percent = percent
  @end_percent = nil
  @duration = nil

  # Instantiate a new Style for this percentage.
  @style = Inkcite::Renderer::Style.new(nil, ctx, styles)

end

Public Instance Methods

[](key) click to toggle source
# File lib/inkcite/facade/keyframe.rb, line 27
def [] key
  @style[key]
end
[]=(key, val) click to toggle source
# File lib/inkcite/facade/keyframe.rb, line 31
def []= key, val
  @style[key] = val
end
add(key, val) click to toggle source

For style chaining - e.g. keyframe.add(:key1, 'val').add(:key)

# File lib/inkcite/facade/keyframe.rb, line 36
def add key, val
  @style[key] = val
  self
end
add_with_prefixes(key, val, ctx) click to toggle source
# File lib/inkcite/facade/keyframe.rb, line 50
def add_with_prefixes key, val, ctx

  ctx.prefixes.each do |prefix|
    _key = "#{prefix}#{key}".to_sym
    self[_key] = val
  end

  self
end
append(key, val) click to toggle source

Appends a value to an existing key

# File lib/inkcite/facade/keyframe.rb, line 42
def append key, val

  @style[key] ||= ''
  @style[key] << ' ' unless @style[key].blank?
  @style[key] << val

end
to_css(prefix) click to toggle source
# File lib/inkcite/facade/keyframe.rb, line 60
def to_css prefix
  css = "#{@percent}%"

  ends_at = calc_ends_at
  css << ", #{ends_at}%" if ends_at

  css << ' { '
  css << @style.to_inline_css(prefix)
  css << ' }'
  css
end

Private Instance Methods

calc_ends_at() click to toggle source

Returns the percent at which the animation keyframe ends based on either end_percent (preferred) or duration (deprecated) being set. Will return nil if neither is present.

# File lib/inkcite/facade/keyframe.rb, line 77
def calc_ends_at
  ends_at = if @end_percent
    @end_percent
  elsif @duration
    (@percent + @duration).round(1)
  end

  # Ensure that the ending percentage never exceeds 100%
  ends_at = 100 if ends_at && ends_at >= 100.0

  ends_at
end
get_prefixed_styles(prefix) click to toggle source

Creates a copy of the array of styles with the appropriate properties (e.g. transform) prefixed.

# File lib/inkcite/facade/keyframe.rb, line 92
def get_prefixed_styles prefix

  _styles = {}

  @styles.each_pair do |key, val|
    key = "#{prefix}#{key}".to_sym if Inkcite::Renderer::Style.needs_prefixing?(key)
    _styles[key] = val
  end

  _styles
end