Skip to content

Commit

Permalink
feat: 🎸 add CSSOM and VCSSOM TypeScript typings
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 22, 2019
1 parent aea14e5 commit 607253a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions addon/cssom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface CSSOMRule extends CSSRule {
index: number;
style: CSSStyleDeclaration;
styleMap: any;
}

export interface AddonCSSOM {
/**
* @param selector CSS rule selector string.
* @param prelude Media query at-rule prelude string.
*/
createRule(selector: string, prelude: string): CSSOMRule;
}

export function addon<Nano extends {sh: HTMLStyleElement}>(nano: Nano): Nano & AddonCSSOM;
12 changes: 12 additions & 0 deletions addon/vcssom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {AddonCSSOM} from './cssom';
import {Css} from './vcssom/cssToTree';

export interface VSheet {
diff(css: Css);
}

export interface AddonVCSSOM {
VSheet: new () => VSheet;
}

export function addon<Nano extends AddonCSSOM>(nano: Nano): Nano & AddonVCSSOM;
15 changes: 15 additions & 0 deletions addon/vcssom/cssToTree.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {CssLikeObject} from '../../types/common';

export interface Css {
[key: string]: CssLikeObject[keyof CssLikeObject] | Css;
}

export interface Tree {
[atRulePrelude: string]: {
[selector: string]: {
[property: string]: CssLikeObject;
};
};
}

export function cssToTree(css: Css): Tree;
3 changes: 3 additions & 0 deletions addon/vcssom/removeRule.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {CSSOMRule} from '../cssom';

export function removeRule(sh: CSSStyleSheet, rule: CSSOMRule);
2 changes: 2 additions & 0 deletions addon/vcssom/removeRule.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: `rule` should have a reference to stylesheet it is contained in,
// maybe we don't need to pass `sh` in here.
function removeRule (sh, rule) {
var maxIndex = rule.index;
var rules = sh.cssRules || sh.rules;
Expand Down

0 comments on commit 607253a

Please sign in to comment.