diff --git a/types/cssom/index.d.ts b/types/cssom/index.d.ts new file mode 100644 index 0000000000..50b2357c32 --- /dev/null +++ b/types/cssom/index.d.ts @@ -0,0 +1,174 @@ +// Type definitions for cssom 0.4 +// Project: https://github.com/NV/CSSOM#readme +// Definitions by: ExE Boss +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace CSSOM; + +/** + * Produces a deep copy of stylesheet — the instance variables of stylesheet are copied recursively. + */ +export function clone(stylesheet: CSSStyleSheet): CSSStyleSheet; + +export function parse(token: string): CSSStyleSheet; + +export abstract class StyleSheet { + parentStyleSheet: StyleSheet | null; +} + +export class CSSStyleSheet extends StyleSheet { + cssRules: CSSRule[]; + + deleteRule(index: number): void; + insertRule(rule: string, index?: number): number; +} + +export abstract class CSSRule { + readonly cssText: string; + + parentRule: CSSRule | null; + parentStyleSheet: StyleSheet | null; + + readonly type: number; +} + +export namespace CSSRule { + /** @deprecated Obsolete */ + const UNKNOWN_RULE = 0; + const STYLE_RULE = 1; + /** @deprecated Obsolete */ + const CHARSET_RULE = 2; + const IMPORT_RULE = 3; + const MEDIA_RULE = 4; + const FONT_FACE_RULE = 5; + const PAGE_RULE = 6; + const KEYFRAMES_RULE = 7; + const KEYFRAME_RULE = 8; + const MARGIN_RULE = 9; + const NAMESPACE_RULE = 10; + const COUNTER_STYLE_RULE = 11; + const SUPPORTS_RULE = 12; + const DOCUMENT_RULE = 13; + const FONT_FEATURE_VALUES_RULE = 14; + const VIEWPORT_RULE = 15; + const REGION_STYLE_RULE = 16; +} + +export class CSSStyleRule extends CSSRule { + cssText: string; + + selectorText: string; + style: CSSStyleDeclaration; + + static parse(ruleText: any): any; + readonly type: 1; +} + +export class CSSImportRule extends CSSRule { + cssText: string; + + href: string; + media: MediaList; + styleSheet: CSSStyleSheet; + + readonly type: 3; +} + +export class CSSMediaRule extends CSSRule { + media: MediaList; + cssRules: CSSRule[]; + + readonly type: 4; +} + +export class CSSFontFaceRule extends CSSRule { + style: CSSStyleDeclaration; + + readonly type: 5; +} + +export class CSSKeyframesRule extends CSSRule { + name: string; + cssRules: CSSRule[]; + + readonly type: 7; +} + +export class CSSKeyframeRule extends CSSRule { + keyText: string; + style: CSSStyleDeclaration; + + readonly type: 8; +} + +export class CSSSupportsRule extends CSSRule { + conditionText: string; + cssRules: CSSRule[]; + + readonly type: 12; +} + +/** @deprecated Removed from spec */ +export class CSSDocumentRule extends CSSRule { + matcher: MatcherList; + cssRules: CSSRule[]; + + readonly type: 13; +} + +/** + * @deprecated Legacy Shadow DOM v0 + * @see https://www.w3.org/TR/2013/WD-shadow-dom-20130514/#host-at-rule + */ +export class CSSHostRule extends CSSRule { + cssRules: CSSRule[]; + + readonly type: 1001; +} + +export class CSSStyleDeclaration { + cssText: string; + length: number; + parentRule: CSSRule | null; + + getPropertyPriority(name: string): string; + getPropertyValue(name: string): string; + removeProperty(name: string): string; + setProperty(name: string, value: string | null, priority?: string | null): void; + + [index: number]: string; +} + +/** @deprecated */ +export class CSSValue { + /** @unsupported The getter and setter are currently unimplemented and throw unconditionally. */ + cssText: string; +} + +/** @deprecated */ +export class CSSValueExpression extends CSSValue { + constructor(token: string, idx: number); + + parse(): { error: any } | { idx: number; expression: string }; +} + +/** @deprecated Removed from spec */ +export class MatcherList { + length: number; + matcherText: string; + + appendMatcher(matcher: string): void; + deleteMatcher(matcher: string): void; + + [index: number]: string; +} + +export class MediaList { + length: number; + mediaText: string; + + appendMedium(medium: string): void; + deleteMedium(medium: string): void; + + [index: number]: string; +} diff --git a/types/cssom/test/cssom.cjs.test.ts b/types/cssom/test/cssom.cjs.test.ts new file mode 100644 index 0000000000..2c97a060fd --- /dev/null +++ b/types/cssom/test/cssom.cjs.test.ts @@ -0,0 +1,17 @@ +import * as CSSOM from 'cssom'; + +let styleSheet: CSSOM.CSSStyleSheet; + +styleSheet = CSSOM.parse(` +@import url("./foo.css"); + +*, +::before, +::after, +::marker { + box-sizing: border-box; +} +`); + +styleSheet.parentStyleSheet; // $ExpectType StyleSheet | null +styleSheet.cssRules; // $ExpectType CSSRule[] diff --git a/types/cssom/test/cssom.umd.test.ts b/types/cssom/test/cssom.umd.test.ts new file mode 100644 index 0000000000..c61289a724 --- /dev/null +++ b/types/cssom/test/cssom.umd.test.ts @@ -0,0 +1,17 @@ +/// + +let styleSheet: CSSOM.CSSStyleSheet; + +styleSheet = CSSOM.parse(` +@import url("./foo.css"); + +*, +::before, +::after, +::marker { + box-sizing: border-box; +} +`); + +styleSheet.parentStyleSheet; // $ExpectType StyleSheet | null +styleSheet.cssRules; // $ExpectType CSSRule[] diff --git a/types/cssom/tsconfig.json b/types/cssom/tsconfig.json new file mode 100644 index 0000000000..d466217096 --- /dev/null +++ b/types/cssom/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["ES2015"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "test/cssom.cjs.test.ts", + "test/cssom.umd.test.ts", + "index.d.ts" + ] +} diff --git a/types/cssom/tslint.json b/types/cssom/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cssom/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }