Merge pull request #4411 from Asana/master

Adding type definitions for styles
This commit is contained in:
Masahiro Wakame
2015-05-25 00:26:15 +09:00
4 changed files with 180 additions and 0 deletions
@@ -0,0 +1,9 @@
/// <reference path="autoprefixer-core.d.ts" />
import autoprefixer = require("autoprefixer-core");
var css: string;
var prefixed = autoprefixer.process(css).css;
var processor = autoprefixer({ browsers: ['> 1%', 'IE 7'], cascade: false });
console.log(processor.info());
+44
View File
@@ -0,0 +1,44 @@
// Type definitions for Autoprefixer Core 5.1.11
// Project: https://github.com/postcss/autoprefixer-core
// Definitions by: Asana <https://asana.com>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "autoprefixer-core" {
interface Config {
browsers?: string[];
cascade?: boolean;
remove?: boolean;
}
interface Options {
from?: string;
to?: string;
safe?: boolean;
map?: {
inline?: boolean;
prev?: string | Object;
}
}
interface Result {
css: string;
map: string;
opts: Options;
}
interface Processor {
postcss: any;
info(): string;
process(css: string, opts?: Options): Result;
}
interface Exports {
(config: Config): Processor;
postcss: any;
info(): string;
process(css: string, opts?: Options): Result;
}
var exports: Exports;
export = exports;
}
+71
View File
@@ -0,0 +1,71 @@
/// <reference path="node-sass.d.ts" />
import sass = require('node-sass');
sass.render({
file: '/path/to/myFile.scss',
data: 'body{background:blue; a{color:black;}}',
importer: function(url, prev, done) {
// url is the path in import as is, which libsass encountered.
// prev is the previously resolved path.
// done is an optional callback, either consume it or return value synchronously.
// this.options contains this options hash, this.callback contains the node-style callback
someAsyncFunction(url, prev, function(result) {
done({
file: result.path, // only one of them is required, see section Sepcial Behaviours.
contents: result.data
});
});
// OR
var result = someSyncFunction(url, prev);
return { file: result.path, contents: result.data };
},
includePaths: ['lib/', 'mod/'],
outputStyle: 'compressed'
}, function(error, result) { // node-style callback from v3.0.0 onwards
if (error) {
console.log(error.status); // used to be "code" in v2x and below
console.log(error.column);
console.log(error.message);
console.log(error.line);
}
else {
console.log(result.css.toString());
console.log(result.stats);
console.log(result.map.toString());
// or better
console.log(JSON.stringify(result.map)); // note, JSON.stringify accepts Buffer too
}
});
// OR
var result = sass.renderSync({
file: '/path/to/file.scss',
data: 'body{background:blue; a{color:black;}}',
outputStyle: 'compressed',
outFile: '/to/my/output.css',
sourceMap: true, // or an absolute or relative (to outFile) path
importer: function(url, prev, done) {
// url is the path in import as is, which libsass encountered.
// prev is the previously resolved path.
// done is an optional callback, either consume it or return value synchronously.
// this.options contains this options hash
someAsyncFunction(url, prev, function(result) {
done({
file: result.path, // only one of them is required, see section Sepcial Behaviours.
contents: result.data
});
});
// OR
var result = someSyncFunction(url, prev);
return { file: result.path, contents: result.data };
},
});
console.log(result.css);
console.log(result.map);
console.log(result.stats);
function someAsyncFunction(url: string, prev: string, callback: (result: { path: string; data: string }) => void): void {}
function someSyncFunction(url: string, prev: string): { path: string; data: string} {
return null;
}
+56
View File
@@ -0,0 +1,56 @@
// Type definitions for Node Sass
// Project: https://github.com/sass/node-sass
// Definitions by: Asana <https://asana.com>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "node-sass" {
interface Importer {
(url: string, prev: string, done: (data: { file: string; contents: string; }) => void): void;
}
interface Options {
file?: string;
data?: string;
importer?: Importer | Importer[];
functions?: { [key: string]: Function };
includePaths?: string[];
indentedSyntax?: boolean;
indentType?: string;
indentWidth?: number;
linefeed?: string;
omitSourceMapUrl?: boolean;
outFile?: string;
outputStyle?: string;
precision?: number;
sourceComments?: boolean;
sourceMap?: boolean | string;
sourceMapContents?: boolean;
sourceMapEmbed?: boolean;
sourceMapRoot?: boolean;
}
interface SassError extends Error {
message: string;
line: number;
column: number;
status: number;
file: string;
}
interface Result {
css: Buffer;
map: Buffer;
stats: {
entry: string;
start: number;
end: number;
duration: number;
includedFiles: string[];
}
}
export function render(options: Options, callback: (err: SassError, result: Result) => any): void;
export function renderSync(options: Options): Result;
}