Given a change on an HTML element based on an HTML attribute:

  • if the HTML attribute change has an equivalence in CSS style rules:
    • determine the selector(s) and the corresponding declarations for that change
    • in all editable stylesheets (embedded or remote from an "editable" domain) applied to the current medium, find all rules based on these selectors and nix the corresponding declarations if present ; remove rules if empty after that change
    • if there's no editable stylesheet, create one
    • for each selector, try to find a remaining rule for that selector ; if there's no rule, create a new one
    • attach the corresponding declarations to that new rule
    • get the computed style for the element and check if it corresponds to the desired style
      • if it does, then leave as is
      • if it does not, then a rule of higher precedence in the cascade masks the ones we just created
        • if the rules we just created can be contained in inline styles on the element, then nix the rules and turn the corresponding styles into a style attribute on the element
        • if they can't be contained in  inline styles, then we're doomed; we have only two choices : let as is but the visual result is different fom user's expectations and that is A Bad Thing ; nix the rules and fallback to the HTML attribute...
  • if there's no CSS equivalence, apply the HTML attribute

Hum, to say the least. Coments anyone ?