# Path: css2video/components/stylesheet.py
# class StyleSheetComponent(BaseComponent):
#     """A wrapper from stylesheet dictionary object"""
# 
#     def __init__(self, *args, **kwargs):
#         super(StyleSheetComponent, self).__init__(*args, **kwargs)
# 
#     @property
#     def style_rules(self):
#         """Returns the style components"""
#         style_rules = filter(
#             lambda x: x['type'] == 'style', self.Dict.get('rules', []))
#         return [
#             StyleRuleComponent.from_dict(Dict=rule) for rule in style_rules
#         ]
# 
#     @property
#     def keyframes_rules(self):
#         keyframes_rules = filter(
#             lambda x: x['type'] == 'keyframes', self.Dict.get('rules', []))
#         return [
#             KeyframesRuleComponent.from_dict(Dict=rule)
#             for rule in keyframes_rules
#         ]
# 
#     def animation_names(self):
#         """Returns a list of animation names"""
#         return [rule.name for rule in self.keyframes_rules]
# 
#     def get_keyframes_rule(self, name):
#         """Returns the keyframes rule with this name
#         Args:
#             - name: name of the animation
#         """
#         for keyframes_rule in self.keyframes_rules:
#             if name == keyframes_rule.name:
#                 return keyframes_rule
# 
# Path: css2video/interpolators/value.py
# def interpolate_value(from_value, to_value, fraction, type='linear'):
#     '''Interpolate a value between the given two values
#     from_value - initial value
#     to_value   - final value
#     fraction   - fraction position from the initial value
#     type       - type of interpolation function'''
# 
#     if from_value.get('type') != to_value.get('type'):
#         raise ValueTypeMismatch()
# 
#     value_type = from_value.get('type')
#     interpolator_fn = Interpolators.get_timing_function(name=type)
# 
#     required_value = copy.deepcopy(from_value)
# 
#     if value_type in ['number', 'length', 'percentage', 'time']:
#         # Interpolate the value
#         required_value['value'] = interpolator_fn(
#             from_value['value'], to_value['value'], fraction)
# 
#     if value_type == 'color':
#         # Interpolate RGBA values
#         required_value['red'] = interpolator_fn(
#             from_value['red'], to_value['red'], fraction)
#         required_value['green'] = interpolator_fn(
#             from_value['green'], to_value['green'], fraction)
#         required_value['blue'] = interpolator_fn(
#             from_value['blue'], to_value['blue'], fraction)
#         required_value['alpha'] = interpolator_fn(
#             from_value['alpha'], to_value['alpha'], fraction)
# 
#     if value_type in ['text', 'url']:
#         # Text values cannot be interpolated.
#         # When the fraction is 1, return the final value
#         if fraction == 1:
#             required_value['value'] = to_value['value']
# 
#     if value_type == 'function':
#         # Check the argument count of both the values and interpolate each of
#         # the value
#         from_args = from_value.get('args', [])
#         to_args = to_value.get('args', [])
#         if len(from_args) != len(to_args):
#             raise FunctionValueArgCountMismatch()
#         args = []
#         for arg1, arg2 in zip(from_args, to_args):
#             args.append(interpolate_value(arg1, arg2, fraction, type))
#         required_value['args'] = args
# 
#     if value_type == 'array':
#         # Check the length of the array and interpolate each of the array items
#         from_values = from_value.get('values', [])
#         to_values = to_value.get('values', [])
#         if len(from_values) != len(to_values):
#             raise ArrayLengthMismatch()
#         values = []
#         for value1, value2 in zip(from_values, to_values):
#             values.append(interpolate_value(value1, value2, fraction, type))
#         required_value['values'] = values
# 
#     return required_value


from ..components import StyleSheetComponent
from .value import interpolate_value
    def generate(self, time):
        '''Returns a stylesheet dictionary object for the given time'''
        stylesheet = self.stylesheet.duplicate()

        for rule in stylesheet.style_rules:
            animation_properties = rule.animation_properties()
            animation_name = animation_properties.get('animation-name')
            if not animation_name:
                continue

            time_offset = self.get_time_offset(animation_properties, time)
            if time_offset is None:
                continue

            keyframes_rule = stylesheet.get_keyframes_rule(animation_name)
            kfp1, kfp2 = keyframes_rule.get_property_sets(
                time_offset=time_offset)

            if kfp2.time_offset == kfp1.time_offset:
                fraction = 0
            else:
                fraction = (
                    (time_offset - kfp1.time_offset) /
                    (kfp2.time_offset - kfp1.time_offset)
                )

            for pname1, value1 in kfp1.properties.items():
                if pname1 not in kfp2.properties:
                    raise MissingProperty('Missing property %s' % pname1)
                value2 = kfp2.properties[pname1]

# Path: css2video/components/stylesheet.py
# class StyleSheetComponent(BaseComponent):
#     """A wrapper from stylesheet dictionary object"""
# 
#     def __init__(self, *args, **kwargs):
#         super(StyleSheetComponent, self).__init__(*args, **kwargs)
# 
#     @property
#     def style_rules(self):
#         """Returns the style components"""
#         style_rules = filter(
#             lambda x: x['type'] == 'style', self.Dict.get('rules', []))
#         return [
#             StyleRuleComponent.from_dict(Dict=rule) for rule in style_rules
#         ]
# 
#     @property
#     def keyframes_rules(self):
#         keyframes_rules = filter(
#             lambda x: x['type'] == 'keyframes', self.Dict.get('rules', []))
#         return [
#             KeyframesRuleComponent.from_dict(Dict=rule)
#             for rule in keyframes_rules
#         ]
# 
#     def animation_names(self):
#         """Returns a list of animation names"""
#         return [rule.name for rule in self.keyframes_rules]
# 
#     def get_keyframes_rule(self, name):
#         """Returns the keyframes rule with this name
#         Args:
#             - name: name of the animation
#         """
#         for keyframes_rule in self.keyframes_rules:
#             if name == keyframes_rule.name:
#                 return keyframes_rule
# 
# Path: css2video/interpolators/value.py
# def interpolate_value(from_value, to_value, fraction, type='linear'):
#     '''Interpolate a value between the given two values
#     from_value - initial value
#     to_value   - final value
#     fraction   - fraction position from the initial value
#     type       - type of interpolation function'''
# 
#     if from_value.get('type') != to_value.get('type'):
#         raise ValueTypeMismatch()
# 
#     value_type = from_value.get('type')
#     interpolator_fn = Interpolators.get_timing_function(name=type)
# 
#     required_value = copy.deepcopy(from_value)
# 
#     if value_type in ['number', 'length', 'percentage', 'time']:
#         # Interpolate the value
#         required_value['value'] = interpolator_fn(
#             from_value['value'], to_value['value'], fraction)
# 
#     if value_type == 'color':
#         # Interpolate RGBA values
#         required_value['red'] = interpolator_fn(
#             from_value['red'], to_value['red'], fraction)
#         required_value['green'] = interpolator_fn(
#             from_value['green'], to_value['green'], fraction)
#         required_value['blue'] = interpolator_fn(
#             from_value['blue'], to_value['blue'], fraction)
#         required_value['alpha'] = interpolator_fn(
#             from_value['alpha'], to_value['alpha'], fraction)
# 
#     if value_type in ['text', 'url']:
#         # Text values cannot be interpolated.
#         # When the fraction is 1, return the final value
#         if fraction == 1:
#             required_value['value'] = to_value['value']
# 
#     if value_type == 'function':
#         # Check the argument count of both the values and interpolate each of
#         # the value
#         from_args = from_value.get('args', [])
#         to_args = to_value.get('args', [])
#         if len(from_args) != len(to_args):
#             raise FunctionValueArgCountMismatch()
#         args = []
#         for arg1, arg2 in zip(from_args, to_args):
#             args.append(interpolate_value(arg1, arg2, fraction, type))
#         required_value['args'] = args
# 
#     if value_type == 'array':
#         # Check the length of the array and interpolate each of the array items
#         from_values = from_value.get('values', [])
#         to_values = to_value.get('values', [])
#         if len(from_values) != len(to_values):
#             raise ArrayLengthMismatch()
#         values = []
#         for value1, value2 in zip(from_values, to_values):
#             values.append(interpolate_value(value1, value2, fraction, type))
#         required_value['values'] = values
# 
#     return required_value


# Path: css2video/interpolators/stylesheet.py
from ..components import StyleSheetComponent
from .value import interpolate_value

    def generate(self, time):
        '''Returns a stylesheet dictionary object for the given time'''
        stylesheet = self.stylesheet.duplicate()

        for rule in stylesheet.style_rules:
            animation_properties = rule.animation_properties()
            animation_name = animation_properties.get('animation-name')
            if not animation_name:
                continue

            time_offset = self.get_time_offset(animation_properties, time)
            if time_offset is None:
                continue

            keyframes_rule = stylesheet.get_keyframes_rule(animation_name)
            kfp1, kfp2 = keyframes_rule.get_property_sets(
                time_offset=time_offset)

            if kfp2.time_offset == kfp1.time_offset:
                fraction = 0
            else:
                fraction = (
                    (time_offset - kfp1.time_offset) /
                    (kfp2.time_offset - kfp1.time_offset)
                )

            for pname1, value1 in kfp1.properties.items():
                if pname1 not in kfp2.properties:
                    raise MissingProperty('Missing property %s' % pname1)
                value2 = kfp2.properties[pname1]

                value = interpolate_value(