mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-04 19:42:46 +08:00
Merge pull request #26686 from screendriver/csso
[csso] Add type definition
This commit is contained in:
40
types/csso/csso-tests.ts
Normal file
40
types/csso/csso-tests.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import csso = require('csso');
|
||||
|
||||
csso.minify('.test { color: #ff0000; }').css;
|
||||
csso.minify('.test { color: #ff0000; }').map;
|
||||
csso.minify('.test { color: #ff0000; }', {
|
||||
sourceMap: true,
|
||||
filename: '',
|
||||
debug: true,
|
||||
beforeCompress: () => {},
|
||||
afterCompress: () => {},
|
||||
restructure: false,
|
||||
forceMediaMerge: true,
|
||||
clone: false,
|
||||
comments: '',
|
||||
logger: () => {}
|
||||
});
|
||||
|
||||
csso.minifyBlock('color: rgba(255, 0, 0, 1); color: #ff0000').css;
|
||||
csso.minifyBlock('color: rgba(255, 0, 0, 1); color: #ff0000').map;
|
||||
csso.minifyBlock('color: rgba(255, 0, 0, 1); color: #ff0000', {
|
||||
sourceMap: true,
|
||||
filename: '',
|
||||
debug: true,
|
||||
beforeCompress: () => {},
|
||||
afterCompress: () => {},
|
||||
restructure: false,
|
||||
forceMediaMerge: true,
|
||||
clone: false,
|
||||
comments: '',
|
||||
logger: () => {}
|
||||
});
|
||||
|
||||
csso.compress({}).ast;
|
||||
csso.compress({}, {
|
||||
restructure: false,
|
||||
forceMediaMerge: true,
|
||||
clone: false,
|
||||
comments: '',
|
||||
logger: () => {}
|
||||
}).ast;
|
||||
107
types/csso/index.d.ts
vendored
Normal file
107
types/csso/index.d.ts
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
// Type definitions for csso 3.5
|
||||
// Project: https://github.com/css/csso
|
||||
// Definitions by: Christian Rackerseder <https://github.com/screendriver>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
declare namespace csso {
|
||||
interface Result {
|
||||
/**
|
||||
* Resulting CSS.
|
||||
*/
|
||||
css: string;
|
||||
/**
|
||||
* Instance of SourceMapGenerator or null.
|
||||
*/
|
||||
map: object | null;
|
||||
}
|
||||
|
||||
interface CompressOptions {
|
||||
/**
|
||||
* Disable or enable a structure optimisations.
|
||||
* @default true
|
||||
*/
|
||||
restructure?: boolean;
|
||||
/**
|
||||
* Enables merging of @media rules with the same media query by splitted by other rules.
|
||||
* The optimisation is unsafe in general, but should work fine in most cases. Use it on your own risk.
|
||||
* @default false
|
||||
*/
|
||||
forceMediaMerge?: boolean;
|
||||
/**
|
||||
* Transform a copy of input AST if true. Useful in case of AST reuse.
|
||||
* @default false
|
||||
*/
|
||||
clone?: boolean;
|
||||
/**
|
||||
* Specify what comments to leave:
|
||||
* - 'exclamation' or true – leave all exclamation comments
|
||||
* - 'first-exclamation' – remove every comment except first one
|
||||
* - false – remove all comments
|
||||
* @default true
|
||||
*/
|
||||
comments?: string | boolean;
|
||||
/**
|
||||
* Usage data for advanced optimisations.
|
||||
*/
|
||||
usage?: object;
|
||||
/**
|
||||
* Function to track every step of transformation.
|
||||
*/
|
||||
logger?: () => void;
|
||||
}
|
||||
|
||||
interface MinifyOptions {
|
||||
/**
|
||||
* Generate a source map when true.
|
||||
* @default false
|
||||
*/
|
||||
sourceMap?: boolean;
|
||||
/**
|
||||
* Filename of input CSS, uses for source map generation.
|
||||
* @default '<unknown>'
|
||||
*/
|
||||
filename?: string;
|
||||
/**
|
||||
* Output debug information to stderr.
|
||||
* @default false
|
||||
*/
|
||||
debug?: boolean;
|
||||
/**
|
||||
* Called right after parse is run.
|
||||
*/
|
||||
beforeCompress?: BeforeCompressFn | BeforeCompressFn[];
|
||||
/**
|
||||
* Called right after compress() is run.
|
||||
*/
|
||||
afterCompress?: AfterCompressFn | AfterCompressFn[];
|
||||
restructure?: boolean;
|
||||
}
|
||||
|
||||
type BeforeCompressFn = (ast: object, options: CompressOptions) => void;
|
||||
type AfterCompressFn = (compressResult: string, options: CompressOptions) => void;
|
||||
}
|
||||
|
||||
interface Csso {
|
||||
/**
|
||||
* Minify source CSS passed as String
|
||||
* @param source
|
||||
* @param options
|
||||
*/
|
||||
minify(source: string, options?: csso.MinifyOptions & csso.CompressOptions): csso.Result;
|
||||
|
||||
/**
|
||||
* The same as minify() but for list of declarations. Usually it's a style attribute value.
|
||||
* @param source
|
||||
* @param options
|
||||
*/
|
||||
minifyBlock(source: string, options?: csso.MinifyOptions & csso.CompressOptions): csso.Result;
|
||||
|
||||
/**
|
||||
* Does the main task – compress an AST.
|
||||
*/
|
||||
compress(ast: object, options?: csso.CompressOptions): { ast: object };
|
||||
}
|
||||
|
||||
declare const csso: Csso;
|
||||
export = csso;
|
||||
23
types/csso/tsconfig.json
Normal file
23
types/csso/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"csso-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/csso/tslint.json
Normal file
1
types/csso/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user