diff --git a/types/styletron-engine-atomic/index.d.ts b/types/styletron-engine-atomic/index.d.ts new file mode 100644 index 0000000000..ea1de298e1 --- /dev/null +++ b/types/styletron-engine-atomic/index.d.ts @@ -0,0 +1,85 @@ +// Type definitions for styletron-engine-atomic 1.1 +// Project: https://github.com/styletron/styletron +// Definitions by: Jhey Tompkins +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.9 + +import { KeyframesObject, FontFace as FontFaceObject, StandardEngine, StyleObject } from 'styletron-standard'; + +export class SequentialIDGenerator { + prefix: string; + count: number; + offset: number; + msb: number; + power: number; + constructor(prefix: string); + next(): string; + increment(): number; + } + +export class Cache { + cache: {[key: string]: string}; + idGenerator: SequentialIDGenerator; + key: string; + onNewValue: (cache: Cache, id: string, value: any) => any; + constructor( + idGenerator: SequentialIDGenerator, + onNewValue: (cache: Cache, id: string, value: any) => any, + ); + addValue(key: string, value: T): number; +} +export class MultiCache { + caches: {[key: string]: Cache}; + idGenerator: SequentialIDGenerator; + onNewCache: (key: string, cache: Cache, insertAtIndex: number) => any; + onNewValue: (cache: Cache, id: string, value: T) => any; + sortedCacheKeys: string[]; + constructor( + idGenerator: SequentialIDGenerator, + onNewCache: () => any, + onNewValue: () => any, + ); + getCache(key: string): Cache; + getSortedCacheKeys(): string[]; +} + +export type hydrateType = HTMLCollectionOf | HTMLStyleElement[] | NodeListOf; +export interface Sheet { + css: string; + attrs: { [key: string]: string }; +} + +export interface ClientOptions { + hydrate?: hydrateType; + container?: Element; + prefix?: string; +} + +export interface ServerOptions { + prefix?: string; +} + +export class Client implements StandardEngine { + constructor(opts?: ClientOptions); + styleElements: { [key: string]: HTMLStyleElement }; + fontFaceSheet: HTMLStyleElement; + keyframesSheet: HTMLStyleElement; + styleCache: MultiCache<{pseudo: string, block: string}>; + keyframesCache: Cache; + fontFaceCache: Cache; + renderStyle(style: StyleObject): string; + renderKeyframes(keyframes: KeyframesObject): string; + renderFontFace(fontFace: FontFaceObject): string; +} +export class Server implements StandardEngine { + constructor(opts?: ServerOptions) + styleRules: { [key: string]: string }; + keyframesRules: string; + fontFaceRules: string; + getStylesheets(): Sheet[]; + getStylesheetsHtml(className?: string): string; + getCss(): string; + renderStyle(style: StyleObject): string; + renderKeyframes(keyframes: KeyframesObject): string; + renderFontFace(fontFace: FontFaceObject): string; +} diff --git a/types/styletron-engine-atomic/styletron-engine-atomic-tests.ts b/types/styletron-engine-atomic/styletron-engine-atomic-tests.ts new file mode 100644 index 0000000000..e5c4d78070 --- /dev/null +++ b/types/styletron-engine-atomic/styletron-engine-atomic-tests.ts @@ -0,0 +1,20 @@ +import { + Client, + Server +} from 'styletron-engine-atomic'; + +const validOptions = { + prefix: 'test-prefix__' +}; + +const invalidOptions = { + hydrate: 'erroneous hydration' +}; + +new Client(validOptions); +new Client(invalidOptions); // $ExpectError + +new Server({prefix: 1234}); // $ExpectError +const myServer = new Server(validOptions); +myServer.getCss(); // $ExpectType string +myServer.getStylesheetsHtml(); // $ExpectType string diff --git a/types/styletron-engine-atomic/tsconfig.json b/types/styletron-engine-atomic/tsconfig.json new file mode 100644 index 0000000000..9c2736fba2 --- /dev/null +++ b/types/styletron-engine-atomic/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "styletron-engine-atomic-tests.ts" + ] +} diff --git a/types/styletron-engine-atomic/tslint.json b/types/styletron-engine-atomic/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/styletron-engine-atomic/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }