From 332c0f8d5625c34893eba64f9080800221392ee5 Mon Sep 17 00:00:00 2001 From: Uros Smolnik Date: Tue, 4 Nov 2014 21:22:07 +0100 Subject: [PATCH 001/371] express 4.x middleware - response-time - serve-favicon - serve-static --- response-time/response-time.d.ts | 38 +++++++++++++++ serve-favicon/serve-favicon.d.ts | 29 ++++++++++++ serve-static/serve-static.d.ts | 79 ++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 response-time/response-time.d.ts create mode 100644 serve-favicon/serve-favicon.d.ts create mode 100644 serve-static/serve-static.d.ts diff --git a/response-time/response-time.d.ts b/response-time/response-time.d.ts new file mode 100644 index 000000000..0a7c25465 --- /dev/null +++ b/response-time/response-time.d.ts @@ -0,0 +1,38 @@ +// Type definitions for response-time 2.2.0 +// Project: https://github.com/expressjs/response-time +// Definitions by: Uros Smolnik +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + +/* =================== USAGE =================== + + import responseTime = require('response-time'); + app.use(responseTime()); + + =============================================== */ + +/// + +declare module "response-time" { + import express = require('express'); + + /** + * Response time header for node.js + * Returns middleware that adds a X-Response-Time header to responses. + */ + function responseTime(options?: { + /** + * The fixed number of digits to include in the output, which is always in milliseconds, defaults to 3 (ex: 2.300ms). + */ + digits?: number; + /** + * The name of the header to set, defaults to X-Response-Time. + */ + header?: string; + /** + * Boolean to indicate if units of measurement suffix should be added to the output, defaults to true (ex: 2.300ms vs 2.300). + */ + suffix?: boolean; + }): express.RequestHandler; + + export = responseTime; +} \ No newline at end of file diff --git a/serve-favicon/serve-favicon.d.ts b/serve-favicon/serve-favicon.d.ts new file mode 100644 index 000000000..80faf5921 --- /dev/null +++ b/serve-favicon/serve-favicon.d.ts @@ -0,0 +1,29 @@ +// Type definitions for serve-favicon 2.1.6 +// Project: https://github.com/expressjs/serve-favicon +// Definitions by: Uros Smolnik +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + +/* =================== USAGE =================== + + import serveFavicon = require('serve-favicon'); + app.use(serveFavicon(__dirname + '/public/favicon.ico')); + + =============================================== */ + +/// + +declare module "serve-favicon" { + import express = require('express'); + + /** + * Node.js middleware for serving a favicon. + */ + function serveFavicon(path: string, options?: { + /** + * The cache-control max-age directive in ms, defaulting to 1 day. This can also be a string accepted by the ms module. + */ + maxAge?: number; + }): express.RequestHandler; + + export = serveFavicon; +} \ No newline at end of file diff --git a/serve-static/serve-static.d.ts b/serve-static/serve-static.d.ts new file mode 100644 index 000000000..9bb57e6d3 --- /dev/null +++ b/serve-static/serve-static.d.ts @@ -0,0 +1,79 @@ +// Type definitions for serve-static 1.7.1 +// Project: https://github.com/expressjs/serve-static +// Definitions by: Uros Smolnik +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + +/* =================== USAGE =================== + + import serveStatic = require('serve-static'); + app.use(serveStatic('public/ftp', {'index': ['default.html', 'default.htm']})) + + =============================================== */ + +/// + +declare module "serve-static" { + import express = require('express'); + + /** + * Create a new middleware function to serve files from within a given root directory. + * The file to serve will be determined by combining req.url with the provided root directory. + * When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs. + */ + function serveStatic(root: string, options?: { + /** + * Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot ("."). + * Note this check is done on the path itself without checking if the path actually exists on the disk. + * If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny"). + * The default value is 'ignore'. + * 'allow' No special treatment for dotfiles + * 'deny' Send a 403 for any request for a dotfile + * 'ignore' Pretend like the dotfile does not exist and call next() + */ + dotfiles?: string; + + /** + * Enable or disable etag generation, defaults to true. + */ + etag?: boolean; + + /** + * Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for. + * The first that exists will be served. Example: ['html', 'htm']. + * The default value is false. + */ + extensions?: boolean; + + /** + * By default this module will send "index.html" files in response to a request on a directory. + * To disable this set false or to supply a new index pass a string or an array in preferred order. + */ + index?: boolean; + + /** + * Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value. + */ + lastModified?: boolean; + + /** + * Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module. + */ + maxAge?: number; + + /** + * Redirect to trailing "/" when the pathname is a dir. Defaults to true. + */ + redirect?: number; + + /** + * Function to set custom headers on response. Alterations to the headers need to occur synchronously. + * The function is called as fn(res, path, stat), where the arguments are: + * res the response object + * path the file path that is being sent + * stat the stat object of the file that is being sent + */ + setHeaders?: (res, path, stat) => any; + }): express.Handler; + + export = serveStatic; +} \ No newline at end of file From c3a688719edf7545818a18d3514c6ae5e4b257b6 Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Wed, 28 Jan 2015 11:15:55 -0800 Subject: [PATCH 002/371] fixed typing for async.parallel and co --- async/async-explicit-tests.ts | 44 +++++++++++++++++ async/async-explicit-tests.ts.tscparams | 1 + async/async.d.ts | 63 +++++++++++++------------ 3 files changed, 79 insertions(+), 29 deletions(-) create mode 100644 async/async-explicit-tests.ts create mode 100644 async/async-explicit-tests.ts.tscparams diff --git a/async/async-explicit-tests.ts b/async/async-explicit-tests.ts new file mode 100644 index 000000000..10d8f0bd2 --- /dev/null +++ b/async/async-explicit-tests.ts @@ -0,0 +1,44 @@ +/// + +interface StringCallback { (err: Error, result: string): void; } +interface AsyncStringGetter { (callback: StringCallback): void; } + +var taskArray: AsyncStringGetter[] = [ + function (callback) { + setTimeout(function () { + callback(null, 'one'); + }, 200); + }, + function (callback) { + setTimeout(function () { + callback(null, 'two'); + }, 100); + }, +]; + +async.series(taskArray, function (err, results) { console.log(results[0].match(/o/)) }); +async.parallel(taskArray, function (err, results) { console.log(results[0].match(/o/)) }); +async.parallelLimit(taskArray, 3, function (err, results) { console.log(results[0].match(/o/)) }); + + +interface Lookup { [key: string]: T; } +interface NumberCallback { (err: Error, result: number): void; } +interface AsyncNumberGetter { (callback: NumberCallback): void; } + +var taskDict: Lookup = { + one: function(callback){ + setTimeout(function(){ + callback(null, 1); + }, 200); + }, + two: function(callback){ + setTimeout(function(){ + callback(null, 2); + }, 100); + } +} + +async.series(taskDict, function(err, results) { console.log(results['one'].toFixed(1)) }); +async.parallel(taskDict, function(err, results) { console.log(results['one'].toFixed(1)) }); +async.parallelLimit(taskDict, 3, function(err, results) { console.log(results['one'].toFixed(1)) }); + diff --git a/async/async-explicit-tests.ts.tscparams b/async/async-explicit-tests.ts.tscparams new file mode 100644 index 000000000..3195c46cd --- /dev/null +++ b/async/async-explicit-tests.ts.tscparams @@ -0,0 +1 @@ +--noImplicitAny diff --git a/async/async.d.ts b/async/async.d.ts index 5f558c384..aae7eb1ae 100644 --- a/async/async.d.ts +++ b/async/async.d.ts @@ -3,10 +3,13 @@ // Definitions by: Boris Yankov // Definitions: https://github.com/borisyankov/DefinitelyTyped +interface Dict { [key: string]: T; } + interface ErrorCallback { (err?: Error): void; } -interface AsyncResultsCallback { (err: Error, results: T[]): void; } interface AsyncResultCallback { (err: Error, result: T): void; } -interface AsyncTimesCallback { (n: number, callback: AsyncResultsCallback): void; } +interface AsyncResultArrayCallback { (err: Error, results: T[]): void; } +interface AsyncResultDictCallback { (err: Error, results: Dict): void; } +interface AsyncTimesCallback { (n: number, callback: AsyncResultArrayCallback): void; } interface AsyncIterator { (item: T, callback: ErrorCallback): void; } interface AsyncResultIterator { (item: T, callback: AsyncResultCallback): void; } @@ -14,15 +17,17 @@ interface AsyncMemoIterator { (memo: R, item: T, callback: AsyncResultCall interface AsyncWorker { (task: T, callback: Function): void; } +interface AsyncTaskFn { (callback: AsyncResultCallback): void; } + interface AsyncQueue { length(): number; concurrency: number; started: boolean; paused: boolean; - push(task: T, callback?: AsyncResultsCallback): void; - push(task: T[], callback?: AsyncResultsCallback): void; - unshift(task: T, callback?: AsyncResultsCallback): void; - unshift(task: T[], callback?: AsyncResultsCallback): void; + push(task: T, callback?: AsyncResultArrayCallback): void; + push(task: T[], callback?: AsyncResultArrayCallback): void; + unshift(task: T, callback?: AsyncResultArrayCallback): void; + unshift(task: T[], callback?: AsyncResultArrayCallback): void; saturated: () => any; empty: () => any; drain: () => any; @@ -38,8 +43,8 @@ interface AsyncPriorityQueue { concurrency: number; started: boolean; paused: boolean; - push(task: T, priority: number, callback?: AsyncResultsCallback): void; - push(task: T[], priority: number, callback?: AsyncResultsCallback): void; + push(task: T, priority: number, callback?: AsyncResultArrayCallback): void; + push(task: T[], priority: number, callback?: AsyncResultArrayCallback): void; saturated: () => any; empty: () => any; drain: () => any; @@ -56,9 +61,9 @@ interface Async { each(arr: T[], iterator: AsyncIterator, callback: ErrorCallback): void; eachSeries(arr: T[], iterator: AsyncIterator, callback: ErrorCallback): void; eachLimit(arr: T[], limit: number, iterator: AsyncIterator, callback: ErrorCallback): void; - map(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; - mapSeries(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; - mapLimit(arr: T[], limit: number, iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; + map(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; + mapSeries(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; + mapLimit(arr: T[], limit: number, iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; filter(arr: T[], iterator: AsyncResultIterator, callback: (results: T[]) => any): any; select(arr: T[], iterator: AsyncResultIterator, callback: (results: T[]) => any): any; filterSeries(arr: T[], iterator: AsyncResultIterator, callback: (results: T[]) => any): any; @@ -70,33 +75,33 @@ interface Async { foldl(arr: T[], memo: R, iterator: AsyncMemoIterator, callback: AsyncResultCallback): any; reduceRight(arr: T[], memo: R, iterator: AsyncMemoIterator, callback: AsyncResultCallback): any; foldr(arr: T[], memo: R, iterator: AsyncMemoIterator, callback: AsyncResultCallback): any; - detect(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; - detectSeries(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; - sortBy(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; - some(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; - any(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; + detect(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; + detectSeries(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; + sortBy(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; + some(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; + any(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; every(arr: T[], iterator: AsyncResultIterator, callback: (result: boolean) => any): any; all(arr: T[], iterator: AsyncResultIterator, callback: (result: boolean) => any): any; - concat(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; - concatSeries(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultsCallback): any; + concat(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; + concatSeries(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; // Control Flow - series(tasks: T[], callback?: AsyncResultsCallback): void; - series(tasks: T, callback?: AsyncResultsCallback): void; - parallel(tasks: T[], callback?: AsyncResultsCallback): void; - parallel(tasks: T, callback?: AsyncResultsCallback): void; - parallelLimit(tasks: T[], limit: number, callback?: AsyncResultsCallback): void; - parallelLimit(tasks: T, limit: number, callback?: AsyncResultsCallback): void; + series(tasks: Array>, callback?: AsyncResultArrayCallback): void; + series(tasks: Dict>, callback?: AsyncResultDictCallback): void; + parallel(tasks: Array>, callback?: AsyncResultArrayCallback): void; + parallel(tasks: Dict>, callback?: AsyncResultDictCallback): void; + parallelLimit(tasks: Array>, limit: number, callback?: AsyncResultArrayCallback): void; + parallelLimit(tasks: Dict>, limit: number, callback?: AsyncResultDictCallback): void; whilst(test: Function, fn: Function, callback: Function): void; until(test: Function, fn: Function, callback: Function): void; - waterfall(tasks: T[], callback?: AsyncResultsCallback): void; - waterfall(tasks: T, callback?: AsyncResultsCallback): void; + waterfall(tasks: Function[], callback?: AsyncResultArrayCallback): void; + waterfall(tasks: Function, callback?: AsyncResultArrayCallback): void; queue(worker: AsyncWorker, concurrency: number): AsyncQueue; priorityQueue(worker: AsyncWorker, concurrency: number): AsyncPriorityQueue; - // auto(tasks: any[], callback?: AsyncResultsCallback): void; - auto(tasks: any, callback?: AsyncResultsCallback): void; + // auto(tasks: any[], callback?: AsyncResultArrayCallback): void; + auto(tasks: any, callback?: AsyncResultArrayCallback): void; iterator(tasks: Function[]): Function; - apply(fn: Function, ...arguments: any[]): void; + apply(fn: Function, ...arguments: any[]): AsyncTaskFn; nextTick(callback: Function): void; times (n: number, callback: AsyncTimesCallback): void; From a583963da3e3b91df3be96922329629fd300b7ed Mon Sep 17 00:00:00 2001 From: reppners Date: Mon, 2 Feb 2015 12:12:34 +0100 Subject: [PATCH 003/371] + enhanced existing typedefinitions by looking at source code of angular-hotkeys to identify missing pieces --- angular-hotkeys/angular-hotkeys.d.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/angular-hotkeys/angular-hotkeys.d.ts b/angular-hotkeys/angular-hotkeys.d.ts index f209fbe08..63085fc03 100644 --- a/angular-hotkeys/angular-hotkeys.d.ts +++ b/angular-hotkeys/angular-hotkeys.d.ts @@ -9,13 +9,16 @@ declare module ng.hotkeys { interface HotkeysProvider { template: string; + templateTitle:string; includeCheatSheet: boolean; cheatSheetHotkey: string; cheatSheetDescription: string; - add(combo: string, description: string, callback: (event: Event, hotkeys: ng.hotkeys.Hotkey) => void): void; + add(combo: string, callback: (event: Event, hotkey?: Hotkey) => void, action?: string, allowIn?: Array, persistent?: boolean): ng.hotkeys.Hotkey; - add(hotkeyObj: ng.hotkeys.Hotkey): void; + add(combo: string, description: string, callback: (event: Event, hotkey?: Hotkey) => void, action?: string, allowIn?: Array, persistent?: boolean): ng.hotkeys.Hotkey; + + add(hotkeyObj: ng.hotkeys.Hotkey): ng.hotkeys.Hotkey; bindTo(scope : ng.IScope): ng.hotkeys.HotkeysProviderChained; @@ -24,6 +27,8 @@ declare module ng.hotkeys { get(combo: string): ng.hotkeys.Hotkey; toggleCheatSheet(): void; + + purgeHotkeys(): void; } interface HotkeysProviderChained { @@ -36,5 +41,8 @@ declare module ng.hotkeys { combo: string; description?: string; callback: (event: Event, hotkey: ng.hotkeys.Hotkey) => void; + action?: string; + allowIn?: Array; + persistent?: boolean; } } From 57708d0b2416820cb7946a3ffb467d32fa1616fb Mon Sep 17 00:00:00 2001 From: reppners Date: Mon, 2 Feb 2015 14:56:52 +0100 Subject: [PATCH 004/371] + added additional overload for del() --- angular-hotkeys/angular-hotkeys.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/angular-hotkeys/angular-hotkeys.d.ts b/angular-hotkeys/angular-hotkeys.d.ts index 63085fc03..60ffc2bfb 100644 --- a/angular-hotkeys/angular-hotkeys.d.ts +++ b/angular-hotkeys/angular-hotkeys.d.ts @@ -24,6 +24,8 @@ declare module ng.hotkeys { del(combo: string): void; + del(hotkeyObj: ng.hotkeys.Hotkey): void; + get(combo: string): ng.hotkeys.Hotkey; toggleCheatSheet(): void; From 3552529f78b81f6eeaf215e8813a03037836288e Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Tue, 3 Feb 2015 21:16:00 -0800 Subject: [PATCH 005/371] updated PR following review from @lukehoban and @chbrown --- async/async-tests.ts | 74 ++++++++++++++++++++++++++++++++++++++------ async/async.d.ts | 43 ++++++++++++------------- 2 files changed, 86 insertions(+), 31 deletions(-) diff --git a/async/async-tests.ts b/async/async-tests.ts index 9a563276a..a6b041b4d 100644 --- a/async/async-tests.ts +++ b/async/async-tests.ts @@ -67,6 +67,17 @@ async.series([ ], function (err, results) { }); +async.series([ + function (callback) { + callback(null, 'one'); + }, + function (callback) { + callback(null, 'two'); + }, +], +function (err, results) { }); + + async.series({ one: function (callback) { setTimeout(function () { @@ -81,6 +92,21 @@ async.series({ }, function (err, results) { }); +async.series({ + one: function (callback) { + setTimeout(function () { + callback(null, 1); + }, 200); + }, + two: function (callback) { + setTimeout(function () { + callback(null, 2); + }, 100); + }, +}, +function (err, results) { }); + + async.parallel([ function (callback) { setTimeout(function () { @@ -95,6 +121,20 @@ async.parallel([ ], function (err, results) { }); +async.parallel([ + function (callback) { + setTimeout(function () { + callback(null, 'one'); + }, 200); + }, + function (callback) { + setTimeout(function () { + callback(null, 'two'); + }, 100); + }, +], +function (err, results) { }); + async.parallel({ one: function (callback) { @@ -110,6 +150,20 @@ async.parallel({ }, function (err, results) { }); +async.parallel({ + one: function (callback) { + setTimeout(function () { + callback(null, 1); + }, 200); + }, + two: function (callback) { + setTimeout(function () { + callback(null, 2); + }, 100); + }, +}, +function (err, results) { }); + var count = 0; @@ -136,7 +190,7 @@ async.waterfall([ ], function (err, result) { }); -var q = async.queue(function (task: any, callback) { +var q = async.queue(function (task: any, callback) { console.log('hello ' + task.name); callback(); }, 2); @@ -189,29 +243,29 @@ q.resume(); q.kill(); // tests for strongly typed tasks -var q2 = async.queue(function (task: string, callback) { +var q2 = async.queue(function (task: string, callback) { console.log('Task: ' + task); callback(); }, 1); q2.push('task1'); -q2.push('task2', function (error, results: string[]) { - console.log('Finished tasks: ' + results.join(', ')); +q2.push('task2', function (error) { + console.log('Finished tasks'); }); -q2.push(['task3', 'task4', 'task5'], function (error, results: string[]) { - console.log('Finished tasks: ' + results.join(', ')); +q2.push(['task3', 'task4', 'task5'], function (error) { + console.log('Finished tasks'); }); q2.unshift('task1'); -q2.unshift('task2', function (error, results: string[]) { - console.log('Finished tasks: ' + results.join(', ')); +q2.unshift('task2', function (error) { + console.log('Finished tasks'); }); -q2.unshift(['task3', 'task4', 'task5'], function (error, results: string[]) { - console.log('Finished tasks: ' + results.join(', ')); +q2.unshift(['task3', 'task4', 'task5'], function (error) { + console.log('Finished tasks'); }); var filename = ''; diff --git a/async/async.d.ts b/async/async.d.ts index aae7eb1ae..bb8890ef7 100644 --- a/async/async.d.ts +++ b/async/async.d.ts @@ -3,31 +3,32 @@ // Definitions by: Boris Yankov // Definitions: https://github.com/borisyankov/DefinitelyTyped -interface Dict { [key: string]: T; } +interface Dictionary { [key: string]: T; } interface ErrorCallback { (err?: Error): void; } interface AsyncResultCallback { (err: Error, result: T): void; } interface AsyncResultArrayCallback { (err: Error, results: T[]): void; } -interface AsyncResultDictCallback { (err: Error, results: Dict): void; } +interface AsyncResultObjectCallback { (err: Error, results: Dictionary): void; } interface AsyncTimesCallback { (n: number, callback: AsyncResultArrayCallback): void; } interface AsyncIterator { (item: T, callback: ErrorCallback): void; } interface AsyncResultIterator { (item: T, callback: AsyncResultCallback): void; } interface AsyncMemoIterator { (memo: R, item: T, callback: AsyncResultCallback): void; } -interface AsyncWorker { (task: T, callback: Function): void; } +interface AsyncWorker { (task: T, callback: ErrorCallback): void; } -interface AsyncTaskFn { (callback: AsyncResultCallback): void; } +interface AsyncFunction { (callback: AsyncResultCallback): void; } +interface AsyncVoidFunction { (callback: ErrorCallback): void; } interface AsyncQueue { length(): number; concurrency: number; started: boolean; paused: boolean; - push(task: T, callback?: AsyncResultArrayCallback): void; - push(task: T[], callback?: AsyncResultArrayCallback): void; - unshift(task: T, callback?: AsyncResultArrayCallback): void; - unshift(task: T[], callback?: AsyncResultArrayCallback): void; + push(task: T, callback?: ErrorCallback): void; + push(task: T[], callback?: ErrorCallback): void; + unshift(task: T, callback?: ErrorCallback): void; + unshift(task: T[], callback?: ErrorCallback): void; saturated: () => any; empty: () => any; drain: () => any; @@ -86,23 +87,23 @@ interface Async { concatSeries(arr: T[], iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): any; // Control Flow - series(tasks: Array>, callback?: AsyncResultArrayCallback): void; - series(tasks: Dict>, callback?: AsyncResultDictCallback): void; - parallel(tasks: Array>, callback?: AsyncResultArrayCallback): void; - parallel(tasks: Dict>, callback?: AsyncResultDictCallback): void; - parallelLimit(tasks: Array>, limit: number, callback?: AsyncResultArrayCallback): void; - parallelLimit(tasks: Dict>, limit: number, callback?: AsyncResultDictCallback): void; - whilst(test: Function, fn: Function, callback: Function): void; - until(test: Function, fn: Function, callback: Function): void; - waterfall(tasks: Function[], callback?: AsyncResultArrayCallback): void; - waterfall(tasks: Function, callback?: AsyncResultArrayCallback): void; + series(tasks: Array>, callback?: AsyncResultArrayCallback): void; + series(tasks: Dictionary>, callback?: AsyncResultObjectCallback): void; + parallel(tasks: Array>, callback?: AsyncResultArrayCallback): void; + parallel(tasks: Dictionary>, callback?: AsyncResultObjectCallback): void; + parallelLimit(tasks: Array>, limit: number, callback?: AsyncResultArrayCallback): void; + parallelLimit(tasks: Dictionary>, limit: number, callback?: AsyncResultObjectCallback): void; + whilst(test: () => boolean, fn: AsyncVoidFunction, callback: (err: any) => void): void; + doWhilst(fn: AsyncVoidFunction, test: () => boolean, callback: (err: any) => void): void; + until(test: () => boolean, fn: AsyncVoidFunction, callback: (err: any) => void): void; + doUntil(fn: AsyncVoidFunction, test: () => boolean, callback: (err: any) => void): void; + waterfall(tasks: Function[], callback?: AsyncResultArrayCallback): void; queue(worker: AsyncWorker, concurrency: number): AsyncQueue; priorityQueue(worker: AsyncWorker, concurrency: number): AsyncPriorityQueue; - // auto(tasks: any[], callback?: AsyncResultArrayCallback): void; auto(tasks: any, callback?: AsyncResultArrayCallback): void; iterator(tasks: Function[]): Function; - apply(fn: Function, ...arguments: any[]): AsyncTaskFn; - nextTick(callback: Function): void; + apply(fn: Function, ...arguments: any[]): AsyncFunction; + nextTick(callback: Function): void; times (n: number, callback: AsyncTimesCallback): void; timesSeries (n: number, callback: AsyncTimesCallback): void; From 6aefcc0fd9935befd11d76001753354d50d68729 Mon Sep 17 00:00:00 2001 From: reppners Date: Wed, 4 Feb 2015 21:23:37 +0100 Subject: [PATCH 006/371] + added author --- angular-hotkeys/angular-hotkeys.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angular-hotkeys/angular-hotkeys.d.ts b/angular-hotkeys/angular-hotkeys.d.ts index 60ffc2bfb..63da273ce 100644 --- a/angular-hotkeys/angular-hotkeys.d.ts +++ b/angular-hotkeys/angular-hotkeys.d.ts @@ -1,6 +1,6 @@ // Type definitions for angular-hotkeys // Project: https://github.com/chieffancypants/angular-hotkeys -// Definitions by: Jason Zhao +// Definitions by: Jason Zhao , Stefan Steinhart // Definitions: https://github.com/borisyankov/DefinitelyTyped /// From a7981f2146914d3522101bf8c454fa2de80da016 Mon Sep 17 00:00:00 2001 From: "EWOUT-QMINO\\Ewout" Date: Thu, 5 Feb 2015 10:07:20 +0100 Subject: [PATCH 007/371] Added event callbacks to CellView --- jointjs/jointjs.d.ts | 110 ++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 49 deletions(-) diff --git a/jointjs/jointjs.d.ts b/jointjs/jointjs.d.ts index 9e6a2f0cc..e52c13f3c 100644 --- a/jointjs/jointjs.d.ts +++ b/jointjs/jointjs.d.ts @@ -17,33 +17,33 @@ declare module joint { class Graph extends Backbone.Model { initialize(); - fromJSON(json: any); + fromJSON(json:any); clear(); - addCell(cell: Cell); - addCells(cells: Cell[]); - getConnectedLinks(cell: Cell, opt?: any): Link[]; - disconnectLinks(cell: Cell); - removeLinks(cell: Cell); + addCell(cell:Cell); + addCells(cells:Cell[]); + getConnectedLinks(cell:Cell, opt?:any):Link[]; + disconnectLinks(cell:Cell); + removeLinks(cell:Cell); findModelsFromPoint(point:{x : number; y: number}):Element[]; } class Cell extends Backbone.Model { toJSON(); - remove(options?: any); + remove(options?:any); toFront(); toBack(); - embed(cell: Cell); - unembed(cell: Cell); - getEmbeddedCells(): Cell[]; - clone(opt?: any): Backbone.Model; // @todo: return can either be Cell or Cell[]. - attr(attrs: any): Cell; + embed(cell:Cell); + unembed(cell:Cell); + getEmbeddedCells():Cell[]; + clone(opt?:any):Backbone.Model; // @todo: return can either be Cell or Cell[]. + attr(attrs:any):Cell; } class Element extends Cell { - position(x: number, y: number): Element; - translate(tx: number, ty?: number): Element; - resize(width: number, height: number): Element; - rotate(angle: number, absolute): Element; + position(x:number, y:number):Element; + translate(tx:number, ty?:number):Element; + resize(width:number, height:number):Element; + rotate(angle:number, absolute):Element; } interface IDefaults { @@ -51,9 +51,9 @@ declare module joint { } class Link extends Cell { - defaults(): IDefaults; - disconnect(): Link; - label(idx?: number, value?: any): any; // @todo: returns either a label under idx or Link if both idx and value were passed + defaults():IDefaults; + disconnect():Link; + label(idx?:number, value?:any):any; // @todo: returns either a label under idx or Link if both idx and value were passed } interface IOptions { @@ -66,34 +66,41 @@ declare module joint { } class Paper extends Backbone.View { - options: IOptions; - setDimensions(width: number, height: number); - scale(sx: number, sy?: number, ox?: number, oy?: number): Paper; - rotate(deg: number, ox?: number, oy?: number): Paper; // @todo not released yet though it's in the source code already - findView(el: any): CellView; - findViewByModel(modelOrId: any): CellView; - findViewsFromPoint(p: { x: number; y: number; }): CellView[]; - findViewsInArea(r: { x: number; y: number; width: number; height: number; }): CellView[]; - snapToGrid(p): { x: number; y: number; }; + options:IOptions; + + setDimensions(width:number, height:number); + scale(sx:number, sy?:number, ox?:number, oy?:number):Paper; + rotate(deg:number, ox?:number, oy?:number):Paper; // @todo not released yet though it's in the source code already + findView(el:any):CellView; + findViewByModel(modelOrId:any):CellView; + findViewsFromPoint(p:{ x: number; y: number; }):CellView[]; + findViewsInArea(r:{ x: number; y: number; width: number; height: number; }):CellView[]; + snapToGrid(p):{ x: number; y: number; }; } - class ElementView extends CellView { - scale(sx: number, sy: number); + class ElementView extends CellView { + scale(sx:number, sy:number); } class CellView extends Backbone.View { - getBBox(): { x: number; y: number; width: number; height: number; }; - highlight(el?: any); - unhighlight(el?: any); - findMagnet(el: any); - getSelector(el: any); + getBBox():{ x: number; y: number; width: number; height: number; }; + highlight(el?:any); + unhighlight(el?:any); + findMagnet(el:any); + getSelector(el:any); + + pointerdblclick(evt:any, x:number, y:number):void; + pointerclick(evt:any, x:number, y:number):void; + pointerdown(evt:any, x:number, y:number):void; + pointermove(evt:any, x:number, y:number):void; + pointerup(evt:any, x:number, y:number):void; } class LinkView extends CellView { - getConnectionLength(): number; - getPointAtLength(length: number): { x: number; y: number; }; + getConnectionLength():number; + getPointAtLength(length:number):{ x: number; y: number; }; } - + } module ui { @@ -127,21 +134,26 @@ declare module joint { module shapes { module basic { - class Generic extends joint.dia.Element { } - class Rect extends Generic { } - class Text extends Generic { } - class Circle extends Generic { } - class Image extends Generic { } + class Generic extends joint.dia.Element { + } + class Rect extends Generic { + } + class Text extends Generic { + } + class Circle extends Generic { + } + class Image extends Generic { + } } } module util { - function uuid(): string; - function guid(obj: any): string; - function mixin(objects: any[]): any; - function supplement(objects: any[]): any; - function deepMixin(objects: any[]): any; - function deepSupplement(objects: any[], defaultIndicator?: any): any; + function uuid():string; + function guid(obj:any):string; + function mixin(objects:any[]):any; + function supplement(objects:any[]):any; + function deepMixin(objects:any[]):any; + function deepSupplement(objects:any[], defaultIndicator?:any):any; } } From a0f9e136c004ef9894833bb09a98bdb60a25bb1f Mon Sep 17 00:00:00 2001 From: "EWOUT-QMINO\\Ewout" Date: Fri, 6 Feb 2015 09:48:57 +0100 Subject: [PATCH 008/371] Separated jointjs and rappid definitions. --- jointjs/jointjs.d.ts | 34 ++++------------------------------ rappid/README.md | 1 + rappid/rappid.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 rappid/README.md create mode 100644 rappid/rappid.d.ts diff --git a/jointjs/jointjs.d.ts b/jointjs/jointjs.d.ts index e52c13f3c..483523d67 100644 --- a/jointjs/jointjs.d.ts +++ b/jointjs/jointjs.d.ts @@ -1,6 +1,7 @@ -// Type definitions for Joint JS 0.6 +// Type definitions for Joint JS 0.9.3 // Project: http://www.jointjs.com/ -// Definitions by: Aidan Reel , David Durman +// Definitions by: Aidan Reel , +// David Durman , Ewout Van Gossum // Definitions: https://github.com/borisyankov/DefinitelyTyped /// @@ -103,34 +104,7 @@ declare module joint { } - module ui { - interface Handle { - name : string; - position : string; - icon: string; - } - - class SelectionView extends Backbone.Model { - paper:joint.dia.Paper; - graph:joint.dia.Graph; - model:Backbone.Collection; - - constructor(opt:{ - paper : joint.dia.Paper; - graph : joint.dia.Graph; - model : Backbone.Collection - }); - - createSelectionBox(cellView:joint.dia.CellView); - destroySelectionBox(cellView:joint.dia.CellView); - startSelecting(evt:any); - cancelSelection(); - - addHandle(handle:Handle); - removeHandle(name:string); - changeHandle(name:string, handle:Handle); - } - } + module ui {} module shapes { module basic { diff --git a/rappid/README.md b/rappid/README.md new file mode 100644 index 000000000..1119a7e6b --- /dev/null +++ b/rappid/README.md @@ -0,0 +1 @@ +These definitions are far from complete. \ No newline at end of file diff --git a/rappid/rappid.d.ts b/rappid/rappid.d.ts new file mode 100644 index 000000000..2b3aaf4e2 --- /dev/null +++ b/rappid/rappid.d.ts @@ -0,0 +1,38 @@ +// Type definitions for Rappid 1.5 +// Project: http://jointjs.com/about-rappid +// Definitions by: Ewout Van Gossum +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +declare module joint{ + module ui{ + interface Handle { + name : string; + position : string; + icon: string; + } + + class SelectionView extends Backbone.Model { + paper:joint.dia.Paper; + graph:joint.dia.Graph; + model:Backbone.Collection; + + constructor(opt:{ + paper : joint.dia.Paper; + graph : joint.dia.Graph; + model : Backbone.Collection + }); + + createSelectionBox(cellView:joint.dia.CellView); + destroySelectionBox(cellView:joint.dia.CellView); + startSelecting(evt:any); + cancelSelection(); + + addHandle(handle:Handle); + removeHandle(name:string); + changeHandle(name:string, handle:Handle); + } + } +} \ No newline at end of file From 42c7718ad5ad711eae79c2f8d2c10e8fd7c491a7 Mon Sep 17 00:00:00 2001 From: "EWOUT-QMINO\\Ewout" Date: Tue, 10 Feb 2015 08:55:17 +0100 Subject: [PATCH 009/371] Added return types where necessary. --- jointjs/jointjs.d.ts | 39 ++++++++++++++++++++------------------- rappid/rappid.d.ts | 14 +++++++------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/jointjs/jointjs.d.ts b/jointjs/jointjs.d.ts index 483523d67..5d2257ffd 100644 --- a/jointjs/jointjs.d.ts +++ b/jointjs/jointjs.d.ts @@ -17,24 +17,25 @@ declare module joint { } class Graph extends Backbone.Model { - initialize(); - fromJSON(json:any); - clear(); - addCell(cell:Cell); - addCells(cells:Cell[]); + addCell(cell:Cell) : void; + addCells(cells:Cell[]) : void; + initialize() : void; + fromJSON(json:any) : void; + toJSON() : Object; + clear() : void; getConnectedLinks(cell:Cell, opt?:any):Link[]; - disconnectLinks(cell:Cell); - removeLinks(cell:Cell); + disconnectLinks(cell:Cell) : void; + removeLinks(cell:Cell) : void; findModelsFromPoint(point:{x : number; y: number}):Element[]; } class Cell extends Backbone.Model { - toJSON(); - remove(options?:any); - toFront(); - toBack(); - embed(cell:Cell); - unembed(cell:Cell); + toJSON() : Object; + remove(options?:any) : void; + toFront() : void; + toBack() : void; + embed(cell:Cell) : void; + unembed(cell:Cell) : void; getEmbeddedCells():Cell[]; clone(opt?:any):Backbone.Model; // @todo: return can either be Cell or Cell[]. attr(attrs:any):Cell; @@ -69,7 +70,7 @@ declare module joint { class Paper extends Backbone.View { options:IOptions; - setDimensions(width:number, height:number); + setDimensions(width:number, height:number) : void; scale(sx:number, sy?:number, ox?:number, oy?:number):Paper; rotate(deg:number, ox?:number, oy?:number):Paper; // @todo not released yet though it's in the source code already findView(el:any):CellView; @@ -80,15 +81,15 @@ declare module joint { } class ElementView extends CellView { - scale(sx:number, sy:number); + scale(sx:number, sy:number) : void; } class CellView extends Backbone.View { getBBox():{ x: number; y: number; width: number; height: number; }; - highlight(el?:any); - unhighlight(el?:any); - findMagnet(el:any); - getSelector(el:any); + highlight(el?:any): void; + unhighlight(el?:any): void; + findMagnet(el:any): void; + getSelector(el:any): void; pointerdblclick(evt:any, x:number, y:number):void; pointerclick(evt:any, x:number, y:number):void; diff --git a/rappid/rappid.d.ts b/rappid/rappid.d.ts index 2b3aaf4e2..9cc438884 100644 --- a/rappid/rappid.d.ts +++ b/rappid/rappid.d.ts @@ -25,14 +25,14 @@ declare module joint{ model : Backbone.Collection }); - createSelectionBox(cellView:joint.dia.CellView); - destroySelectionBox(cellView:joint.dia.CellView); - startSelecting(evt:any); - cancelSelection(); + createSelectionBox(cellView:joint.dia.CellView) : void; + destroySelectionBox(cellView:joint.dia.CellView) : void; + startSelecting(evt:any) : void; + cancelSelection() : void; - addHandle(handle:Handle); - removeHandle(name:string); - changeHandle(name:string, handle:Handle); + addHandle(handle:Handle) : void; + removeHandle(name:string) : void; + changeHandle(name:string, handle:Handle) : void; } } } \ No newline at end of file From 24ef5a1d8aaa61548a42e54891f86023d06c3f5a Mon Sep 17 00:00:00 2001 From: "EWOUT-QMINO\\Ewout" Date: Tue, 10 Feb 2015 09:04:47 +0100 Subject: [PATCH 010/371] Fixed Element rotate (and also updated to current jointjs api) --- jointjs/jointjs.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jointjs/jointjs.d.ts b/jointjs/jointjs.d.ts index 5d2257ffd..5917f1811 100644 --- a/jointjs/jointjs.d.ts +++ b/jointjs/jointjs.d.ts @@ -45,7 +45,7 @@ declare module joint { position(x:number, y:number):Element; translate(tx:number, ty?:number):Element; resize(width:number, height:number):Element; - rotate(angle:number, absolute):Element; + rotate(angle:number, options : {absolute : boolean; origin: {x:number;y:number}}):Element; } interface IDefaults { From 7aa6024ba2db7b2e5b8ccee44168c6d362ddb37b Mon Sep 17 00:00:00 2001 From: "EWOUT-QMINO\\Ewout" Date: Tue, 10 Feb 2015 09:08:35 +0100 Subject: [PATCH 011/371] Removed snapToGrid as it doesn't seem to be part of the public JointJS API. --- jointjs/jointjs.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/jointjs/jointjs.d.ts b/jointjs/jointjs.d.ts index 5917f1811..cf5efdc5b 100644 --- a/jointjs/jointjs.d.ts +++ b/jointjs/jointjs.d.ts @@ -1,7 +1,6 @@ // Type definitions for Joint JS 0.9.3 // Project: http://www.jointjs.com/ -// Definitions by: Aidan Reel , -// David Durman , Ewout Van Gossum +// Definitions by: Aidan Reel , David Durman , Ewout Van Gossum // Definitions: https://github.com/borisyankov/DefinitelyTyped /// @@ -77,7 +76,6 @@ declare module joint { findViewByModel(modelOrId:any):CellView; findViewsFromPoint(p:{ x: number; y: number; }):CellView[]; findViewsInArea(r:{ x: number; y: number; width: number; height: number; }):CellView[]; - snapToGrid(p):{ x: number; y: number; }; } class ElementView extends CellView { From 427d97003e0cb8754a63fb9c6577606322c70634 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Thu, 12 Feb 2015 16:22:00 +1300 Subject: [PATCH 012/371] Change leaflet to use interfaces to allow for plugins --- leaflet/leaflet.d.ts | 669 +++++++++++++++++++++++-------------------- 1 file changed, 356 insertions(+), 313 deletions(-) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index ff90fb479..61ba2b3b9 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -36,19 +36,21 @@ declare module L { */ export function bounds(points: Point[]): Bounds; - export class Bounds { + export var Bounds: { /** * Creates a Bounds object from two coordinates (usually top-left and bottom-right * corners). */ - constructor(topLeft: Point, bottomRight: Point); - + new(topLeft: Point, bottomRight: Point): Bounds; + /** * Creates a Bounds object defined by the points it contains. */ - constructor(points: Point[]); + new(points: Point[]): Bounds; + }; + export interface Bounds { /** * Extends the bounds to contain the given point. */ @@ -98,74 +100,74 @@ declare module L { declare module L { - export class Browser { + module Browser { /** * true for all Internet Explorer versions. */ - static ie: boolean; + export var ie: boolean; /** * true for Internet Explorer 6. */ - static ie6: boolean; + export var ie6: boolean; /** * true for Internet Explorer 6. */ - static ie7: boolean; + export var ie7: boolean; /** * true for webkit-based browsers like Chrome and Safari (including mobile * versions). */ - static webkit: boolean; + export var webkit: boolean; /** * true for webkit-based browsers that support CSS 3D transformations. */ - static webkit3d: boolean; + export var webkit3d: boolean; /** * true for Android mobile browser. */ - static android: boolean; + export var android: boolean; /** * true for old Android stock browsers (2 and 3). */ - static android23: boolean; + export var android23: boolean; /** * true for modern mobile browsers (including iOS Safari and different Android * browsers). */ - static mobile: boolean; + export var mobile: boolean; /** * true for mobile webkit-based browsers. */ - static mobileWebkit: boolean; + export var mobileWebkit: boolean; /** * true for mobile Opera. */ - static mobileOpera: boolean; + export var mobileOpera: boolean; /** * true for all browsers on touch devices. */ - static touch: boolean; + export var touch: boolean; /** * true for browsers with Microsoft touch model (e.g. IE10). */ - static msTouch: boolean; + export var msTouch: boolean; /** * true for devices with Retina screens. */ - static retina: boolean; + export var retina: boolean; } } @@ -179,14 +181,15 @@ declare module L { */ function circle(latlng: LatLng, radius: number, options?: PathOptions): Circle; - export class Circle extends Path { - + export var Circle: { /** * Instantiates a circle object given a geographical point, a radius in meters * and optionally an options object. */ - constructor(latlng: LatLng, radius: number, options?: PathOptions); - + new(latlng: LatLng, radius: number, options?: PathOptions): Circle; + }; + + export interface Circle extends Path { /** * Returns the current geographical position of the circle. */ @@ -224,15 +227,17 @@ declare module L { */ function circleMarker(latlng: LatLng, options?: PathOptions): CircleMarker; - export class CircleMarker extends Circle { + export var CircleMarker: { /** * Instantiates a circle marker given a geographical point and optionally * an options object. The default radius is 10 and can be altered by passing a * "radius" member in the path options object. */ - constructor(latlng: LatLng, options?: PathOptions); + new(latlng: LatLng, options?: PathOptions): CircleMarker; + }; + export interface CircleMarker extends Circle { /** * Sets the position of a circle marker to a new location. */ @@ -281,34 +286,62 @@ declare module L { * L.Class powers the OOP facilities of Leaflet and is used to create * almost all of the Leaflet classes documented. */ - export class Class { + module Class { /** * You use L.Class.extend to define new classes, but you can use the * same method on any class to inherit from it. */ - static extend(options: ClassExtendOptions): any; + function extend(options: ClassExtendOptions): any; /** * You can also use the following shortcut when you just need to make * one additional method call. */ - static addInitHook(methodName: string, ...args: any[]): void; + function addInitHook(methodName: string, ...args: any[]): void; } -} - - - +} + declare module L { - - export class Control extends Class implements IControl { - + export var Control: { /** * Creates a control with the given options. */ - constructor(options?: ControlOptions); + new(options?: ControlOptions): Control; + Zoom: { + /** + * Creates a zoom control. + */ + new(options?: ZoomOptions): Control.Zoom; + }; + + Attribution: { + /** + * Creates an attribution control. + */ + new(options?: AttributionOptions): Control.Attribution; + }; + + Layers: { + /** + * Creates an attribution control with the given layers. Base layers will be + * switched with radio buttons, while overlays will be switched with checkboxes. + */ + new(baseLayers?: any, overlays?: any, options?: LayersOptions): Control.Layers; + }; + + Scale: { + /** + * Creates an scale control with the given options. + */ + new(options?: ScaleOptions): Control.Scale; + }; + + }; + + export interface Control extends IControl { /** * Sets the position of the control. See control positions. */ @@ -352,22 +385,10 @@ declare module L { } module Control { - - export class Zoom extends L.Control { - - /** - * Creates a zoom control. - */ - constructor(options?: ZoomOptions); + export interface Zoom extends L.Control { } - export class Attribution extends L.Control { - - /** - * Creates an attribution control. - */ - constructor(options?: AttributionOptions); - + export interface Attribution extends L.Control { /** * Sets the text before the attributions. */ @@ -385,14 +406,7 @@ declare module L { } - export class Layers extends L.Control implements IEventPowered { - - /** - * Creates an attribution control with the given layers. Base layers will be - * switched with radio buttons, while overlays will be switched with checkboxes. - */ - constructor(baseLayers?: any, overlays?: any, options?: LayersOptions); - + export interface Layers extends L.Control, IEventPowered { /** * Adds a base layer (radio button entry) with the given name to the control. */ @@ -426,43 +440,39 @@ declare module L { off(eventMap?: any, context?: any): Layers; } - export class Scale extends L.Control { - - /** - * Creates an scale control with the given options. - */ - constructor(options?: ScaleOptions); - + export interface Scale extends L.Control { } } - export class control { - + export interface control { /** * Creates a control with the given options. */ function (options?: ControlOptions): Control; + } + + module control { /** * Creates a zoom control. */ - static zoom(options?: ZoomOptions): L.Control.Zoom; + export function zoom(options?: ZoomOptions): L.Control.Zoom; /** * Creates an attribution control. */ - static attribution(options?: AttributionOptions): L.Control.Attribution; + export function attribution(options?: AttributionOptions): L.Control.Attribution; /** * Creates an attribution control with the given layers. Base layers will be * switched with radio buttons, while overlays will be switched with checkboxes. */ - static layers(baseLayers?: any, overlays?: any, options?: LayersOptions): L.Control.Layers; + export function layers(baseLayers?: any, overlays?: any, options?: LayersOptions): L.Control.Layers; /** * Creates an scale control with the given options. */ - static scale(options?: ScaleOptions): L.Control.Scale; + export function scale(options?: ScaleOptions): L.Control.Scale; } } @@ -482,32 +492,32 @@ declare module L { declare module L { - export class CRS { + module CRS { /** * The most common CRS for online maps, used by almost all free and commercial * tile providers. Uses Spherical Mercator projection. Set in by default in * Map's crs option. */ - static EPSG3857: ICRS; + export var EPSG3857: ICRS; /** * A common CRS among GIS enthusiasts. Uses simple Equirectangular projection. */ - static EPSG4326: ICRS; + export var EPSG4326: ICRS; /** * Rarely used by some commercial tile providers. Uses Elliptical Mercator * projection. */ - static EPSG3395: ICRS; + export var EPSG3395: ICRS; /** * A simple CRS that maps longitude and latitude into x and y directly. May be * used for maps of flat surfaces (e.g. game maps). Note that the y axis should * still be inverted (going from bottom to top). */ - static Simple: ICRS; + export var Simple: ICRS; } } @@ -519,12 +529,14 @@ declare module L { */ function divIcon(options: DivIconOptions): DivIcon; - export class DivIcon extends Icon { - + export var DivIcon: { /** * Creates a div icon instance with the given options. */ - constructor(options: DivIconOptions); + new(options: DivIconOptions): DivIcon; + }; + + export interface DivIcon extends Icon { } } @@ -564,20 +576,20 @@ declare module L { declare module L { - export class DomEvent { + export interface DomEvent { /** * Adds a listener fn to the element's DOM event of the specified type. this keyword * inside the listener will point to context, or to the element if not specified. */ - static addListener(el: HTMLElement, type: string, fn: (e: Event) => void, context?: any): DomEvent; - static on(el: HTMLElement, type: string, fn: (e: Event) => void, context?: any): DomEvent; + addListener(el: HTMLElement, type: string, fn: (e: Event) => void, context?: any): DomEvent; + on(el: HTMLElement, type: string, fn: (e: Event) => void, context?: any): DomEvent; /** * Removes an event listener from the element. */ - static removeListener(el: HTMLElement, type: string, fn: (e: Event) => void, context?: any): DomEvent; - static off(el: HTMLElement, type: string, fn: (e: Event) => void, context?: any): DomEvent; + removeListener(el: HTMLElement, type: string, fn: (e: Event) => void, context?: any): DomEvent; + off(el: HTMLElement, type: string, fn: (e: Event) => void, context?: any): DomEvent; /** * Stop the given event from propagation to parent elements. Used inside the @@ -587,116 +599,118 @@ declare module L { * L.DomEvent.stopPropagation(e); * }); */ - static stopPropagation(e: Event): DomEvent; + stopPropagation(e: Event): DomEvent; /** * Prevents the default action of the event from happening (such as following * a link in the href of the a element, or doing a POST request with page reload * when form is submitted). Use it inside listener functions. */ - static preventDefault(e: Event): DomEvent; + preventDefault(e: Event): DomEvent; /** * Does stopPropagation and preventDefault at the same time. */ - static stop(e: Event): DomEvent; + stop(e: Event): DomEvent; /** * Adds stopPropagation to the element's 'click', 'doubleclick', 'mousedown' * and 'touchstart' events. */ - static disableClickPropagation(el: HTMLElement): DomEvent; + disableClickPropagation(el: HTMLElement): DomEvent; /** * Gets normalized mouse position from a DOM event relative to the container * or to the whole page if not specified. */ - static getMousePosition(e: Event, container?: HTMLElement): Point; + getMousePosition(e: Event, container?: HTMLElement): Point; /** * Gets normalized wheel delta from a mousewheel DOM event. */ - static getWheelDelta(e: Event): number; + getWheelDelta(e: Event): number; } + + export var DomEvent: DomEvent; } declare module L { - export class DomUtil { + module DomUtil { /** * Returns an element with the given id if a string was passed, or just returns * the element if it was passed directly. */ - static get(id: string): HTMLElement; + export function get(id: string): HTMLElement; /** * Returns the value for a certain style attribute on an element, including * computed values or values set through CSS. */ - static getStyle(el: HTMLElement, style: string): string; + export function getStyle(el: HTMLElement, style: string): string; /** * Returns the offset to the viewport for the requested element. */ - static getViewportOffset(el: HTMLElement): Point; + export function getViewportOffset(el: HTMLElement): Point; /** * Creates an element with tagName, sets the className, and optionally appends * it to container element. */ - static create(tagName: string, className: string, container?: HTMLElement): HTMLElement; + export function create(tagName: string, className: string, container?: HTMLElement): HTMLElement; /** * Makes sure text cannot be selected, for example during dragging. */ - static disableTextSelection(): void; + export function disableTextSelection(): void; /** * Makes text selection possible again. */ - static enableTextSelection(): void; + export function enableTextSelection(): void; /** * Returns true if the element class attribute contains name. */ - static hasClass(el: HTMLElement, name: string): boolean; + export function hasClass(el: HTMLElement, name: string): boolean; /** * Adds name to the element's class attribute. */ - static addClass(el: HTMLElement, name: string): void; + export function addClass(el: HTMLElement, name: string): void; /** * Removes name from the element's class attribute. */ - static removeClass(el: HTMLElement, name: string): void; + export function removeClass(el: HTMLElement, name: string): void; /** * Set the opacity of an element (including old IE support). Value must be from * 0 to 1. */ - static setOpacity(el: HTMLElement, value: number): void; + export function setOpacity(el: HTMLElement, value: number): void; /** * Goes through the array of style names and returns the first name that is a valid * style name for an element. If no such name is found, it returns false. Useful * for vendor-prefixed styles like transform. */ - static testProp(props: string[]): any; + export function testProp(props: string[]): any; /** * Returns a CSS transform string to move an element by the offset provided in * the given point. Uses 3D translate on WebKit for hardware-accelerated transforms * and 2D on other browsers. */ - static getTranslateString(point: Point): string; + export function getTranslateString(point: Point): string; /** * Returns a CSS transform string to scale an element (with the given scale origin). */ - static getScaleString(scale: number, origin: Point): string; + export function getScaleString(scale: number, origin: Point): string; /** * Sets the position of an element to coordinates specified by point, using @@ -704,22 +718,22 @@ declare module L { * Leaflet internally to position its layers). Forces top/left positioning * if disable3D is true. */ - static setPosition(el: HTMLElement, point: Point, disable3D?: boolean): void; + export function setPosition(el: HTMLElement, point: Point, disable3D?: boolean): void; /** * Returns the coordinates of an element previously positioned with setPosition. */ - static getPosition(el: HTMLElement): Point; + export function getPosition(el: HTMLElement): Point; /** * Vendor-prefixed transition style name (e.g. 'webkitTransition' for WebKit). */ - static TRANSITION: string; + export var TRANSITION: string; /** * Vendor-prefixed transform style name. */ - static TRANSFORM: string; + export var TRANSFORM: string; } } @@ -732,14 +746,16 @@ declare module L { */ function draggable(element: HTMLElement, dragHandle?: HTMLElement): Draggable; - export class Draggable extends Class implements IEventPowered { - + export var Draggable: { /** * Creates a Draggable object for moving the given element when you start dragging * the dragHandle element (equals the element itself by default). */ - constructor(element: HTMLElement, dragHandle?: HTMLElement); - + new(element: HTMLElement, dragHandle?: HTMLElement): Draggable; + }; + + + export interface Draggable extends IEventPowered { /** * Enables the dragging ability. */ @@ -778,13 +794,15 @@ declare module L { */ function featureGroup(layers?: T[]): FeatureGroup; - export class FeatureGroup extends LayerGroup implements ILayer, IEventPowered> { + export var FeatureGroup: { /** * Create a layer group, optionally given an initial set of layers. */ - constructor(layers?: T[]); - + new(layers?: T[]): FeatureGroup; + }; + + export interface FeatureGroup extends LayerGroup, ILayer, IEventPowered> { /** * Binds a popup with a particular HTML content to a click on any layer from the * group that has a bindPopup method. @@ -892,15 +910,36 @@ declare module L { */ function geoJson(geojson?: any, options?: GeoJSONOptions): GeoJSON; - export class GeoJSON extends FeatureGroup { - + export var GeoJSON: { /** * Creates a GeoJSON layer. Optionally accepts an object in GeoJSON format * to display on the map (you can alternatively add it later with addData method) * and an options object. */ - constructor(geojson?: any, options?: GeoJSONOptions); - + new(geojson?: any, options?: GeoJSONOptions): GeoJSON; + + /** + * Creates a layer from a given GeoJSON feature. + */ + geometryToLayer(featureData: GeoJSON, pointToLayer?: (featureData: any, latlng: LatLng) => ILayer): ILayer; + + /** + * Creates a LatLng object from an array of 2 numbers (latitude, longitude) + * used in GeoJSON for points. If reverse is set to true, the numbers will be interpreted + * as (longitude, latitude). + */ + coordsToLatlng(coords: number[], reverse?: boolean): LatLng; + + /** + * Creates a multidimensional array of LatLng objects from a GeoJSON coordinates + * array. levelsDeep specifies the nesting level (0 is for an array of points, + * 1 for an array of arrays of points, etc., 0 by default). If reverse is set to + * true, the numbers will be interpreted as (longitude, latitude). + */ + coordsToLatlngs(coords: number[], levelsDeep?: number, reverse?: boolean): LatLng[]; + }; + + export interface GeoJSON extends FeatureGroup { /** * Adds a GeoJSON object to the layer. */ @@ -921,30 +960,9 @@ declare module L { * useful for resetting style after hover events. */ resetStyle(layer: Path): GeoJSON; - - /** - * Creates a layer from a given GeoJSON feature. - */ - static geometryToLayer(featureData: GeoJSON, pointToLayer?: (featureData: any, latlng: LatLng) => ILayer): ILayer; - - /** - * Creates a LatLng object from an array of 2 numbers (latitude, longitude) - * used in GeoJSON for points. If reverse is set to true, the numbers will be interpreted - * as (longitude, latitude). - */ - static coordsToLatlng(coords: number[], reverse?: boolean): LatLng; - - /** - * Creates a multidimensional array of LatLng objects from a GeoJSON coordinates - * array. levelsDeep specifies the nesting level (0 is for an array of points, - * 1 for an array of arrays of points, etc., 0 by default). If reverse is set to - * true, the numbers will be interpreted as (longitude, latitude). - */ - static coordsToLatlngs(coords: number[], levelsDeep?: number, reverse?: boolean): LatLng[]; - } } - + declare module L { export interface GeoJSONOptions { /** @@ -989,28 +1007,31 @@ declare module L { */ function icon(options: IconOptions): Icon; - export class Icon extends Class { - + export var Icon: { /** * Creates an icon instance with the given options. */ - constructor(options: IconOptions); + new(options: IconOptions): Icon; + + Default: { + /** + * Creates a default icon instance with the given options. + */ + new(options?: IconOptions): Icon.Default; + + imagePath: string; + }; + }; + + export interface Icon { } module Icon { - /** * L.Icon.Default extends L.Icon and is the blue icon Leaflet uses * for markers by default. */ - export class Default extends Icon { - - /** - * Creates a default icon instance with the given options. - */ - constructor(options?: IconOptions); - - static imagePath: string; + export interface Default extends Icon { } } } @@ -1252,7 +1273,7 @@ declare module L { enabled(): boolean; } - export class Handler extends Class { + export interface Handler { initialize(map: Map): void; } } @@ -1277,7 +1298,7 @@ declare module L { } declare module L { - export module Mixin { + module Mixin { export interface LeafletMixinEvents extends IEventPowered { } @@ -1293,14 +1314,15 @@ declare module L { */ function imageOverlay(imageUrl: string, bounds: LatLngBounds, options?: ImageOverlayOptions): ImageOverlay; - export class ImageOverlay extends Class implements ILayer { - + export var ImageOverlay: { /** * Instantiates an image overlay object given the URL of the image and the geographical * bounds it is tied to. */ - constructor(imageUrl: string, bounds: LatLngBounds, options?: ImageOverlayOptions); + new(imageUrl: string, bounds: LatLngBounds, options?: ImageOverlayOptions): ImageOverlay; + }; + export interface ImageOverlay extends ILayer { /** * Adds the overlay to the map. */ @@ -1385,7 +1407,6 @@ declare module L { } declare module L { - /** * Creates an object representing a geographical point with the given latitude * and longitude. @@ -1398,20 +1419,42 @@ declare module L { */ function latLng(coords: number[]): LatLng; - export class LatLng { + export var LatLng: { + /** + * Creates an object representing a geographical point with the given latitude + * and longitude. + */ + new(latitude: number, longitude: number): LatLng; /** * Creates an object representing a geographical point with the given latitude * and longitude. */ - constructor(latitude: number, longitude: number); - - /** - * Creates an object representing a geographical point with the given latitude - * and longitude. - */ - constructor(coords: number[]); + new(coords: number[]): LatLng; + /** + * A multiplier for converting degrees into radians. + * + * Value: Math.PI / 180. + */ + DEG_TO_RAD: number; + + /** + * A multiplier for converting radians into degrees. + * + * Value: 180 / Math.PI. + */ + RAD_TO_DEG: number; + + /** + * Max margin of error for the equality check. + * + * Value: 1.0E-9. + */ + MAX_MARGIN: number; + }; + + export interface LatLng { /** * Returns the distance (in meters) to the given LatLng calculated using the * Haversine formula. See description on wikipedia @@ -1444,30 +1487,9 @@ declare module L { * Longitude in degrees. */ lng: number; - - /** - * A multiplier for converting degrees into radians. - * - * Value: Math.PI / 180. - */ - static DEG_TO_RAD: number; - - /** - * A multiplier for converting radians into degrees. - * - * Value: 180 / Math.PI. - */ - static RAD_TO_DEG: number; - - /** - * Max margin of error for the equality check. - * - * Value: 1.0E-9. - */ - static MAX_MARGIN: number; } } - + declare module L { /** @@ -1482,20 +1504,21 @@ declare module L { */ function latLngBounds(latlngs: LatLng[]): LatLngBounds; - export class LatLngBounds { - + export var LatLngBounds: { /** * Creates a LatLngBounds object by defining south-west and north-east corners * of the rectangle. */ - constructor(southWest: LatLng, northEast: LatLng); - + new(southWest: LatLng, northEast: LatLng): LatLngBounds; + /** * Creates a LatLngBounds object defined by the geographical points it contains. * Very useful for zooming the map to fit a particular set of locations with fitBounds. */ - constructor(latlngs: LatLng[]); + new(latlngs: LatLng[]): LatLngBounds; + }; + export interface LatLngBounds { /** * Extends the bounds to contain the given point. */ @@ -1579,13 +1602,15 @@ declare module L { */ function layerGroup(layers?: T[]): LayerGroup; - export class LayerGroup extends Class implements ILayer { + export var LayerGroup: { /** * Create a layer group, optionally given an initial set of layers. */ - constructor(layers?: T[]); - + new(layers?: T[]): LayerGroup; + }; + + export interface LayerGroup extends ILayer { /** * Adds the group of layers to the map. */ @@ -1886,7 +1911,7 @@ declare module L { declare module L { - export class LineUtil { + module LineUtil { /** * Dramatically reduces the number of points in a polyline while retaining @@ -1896,24 +1921,24 @@ declare module L { * (lesser value means higher quality but slower and with more points). Also * released as a separated micro-library Simplify.js. */ - static simplify(points: Point[], tolerance: number): Point[]; + export function simplify(points: Point[], tolerance: number): Point[]; /** * Returns the distance between point p and segment p1 to p2. */ - static pointToSegmentDistance(p: Point, p1: Point, p2: Point): number; + export function pointToSegmentDistance(p: Point, p1: Point, p2: Point): number; /** * Returns the closest point from a point p on a segment p1 to p2. */ - static closestPointOnSegment(p: Point, p1: Point, p2: Point): number; + export function closestPointOnSegment(p: Point, p1: Point, p2: Point): number; /** * Clips the segment a to b by rectangular bounds (modifying the segment points * directly!). Used by Leaflet to only show polyline points that are on the screen * or near, increasing performance. */ - static clipSegment(a: Point, b: Point, bounds: Bounds): void; + export function clipSegment(a: Point, b: Point, bounds: Bounds): void; } } @@ -1985,15 +2010,15 @@ declare module L { */ function map(id: string, options?: MapOptions): Map; - export class Map extends Class implements IEventPowered { + export var Map: { /** * Instantiates a map object given a div element and optionally an * object literal with map options described below. * * @constructor */ - constructor(id: HTMLElement, options?: MapOptions); + new(id: HTMLElement, options?: MapOptions): Map; /** * Instantiates a map object given a div element id and optionally an @@ -2001,8 +2026,10 @@ declare module L { * * @constructor */ - constructor(id: string, options?: MapOptions); + new(id: string, options?: MapOptions): Map; + }; + export interface Map extends IEventPowered { // Methods for Modifying Map State /** @@ -2357,7 +2384,7 @@ declare module L { off(eventMap?: any, context?: any): Map; } } - + declare module L { export interface MapOptions { @@ -2647,14 +2674,15 @@ declare module L { */ function marker(latlng: LatLng, options?: MarkerOptions): Marker; - export class Marker extends Class implements ILayer, IEventPowered { - + var Marker: { /** * Instantiates a Marker object given a geographical point and optionally * an options object. */ - constructor(latlng: LatLng, options?: MarkerOptions); - + new(latlng: LatLng, options?: MarkerOptions): Marker; + }; + + export interface Marker extends ILayer, IEventPowered { /** * Adds the marker to the map. */ @@ -2877,15 +2905,16 @@ declare module L { */ function multiPolygon(latlngs: LatLng[][], options?: PolylineOptions): MultiPolygon; - export class MultiPolygon extends FeatureGroup { - + export var MultiPolylgon: { /** * Instantiates a multi-polyline object given an array of latlngs arrays (one * for each individual polygon) and optionally an options object (the same * as for MultiPolyline). */ - constructor(latlngs: LatLng[][], options?: PolylineOptions); - + new(latlngs: LatLng[][], options?: PolylineOptions): MultiPolygon; + }; + + export interface MultiPolygon extends FeatureGroup { /** * Replace all polygons and their paths with the given array of arrays * of geographical points. @@ -2917,14 +2946,15 @@ declare module L { */ function multiPolyline(latlngs: LatLng[][], options?: PolylineOptions): MultiPolyline; - export class MultiPolyline extends FeatureGroup { - + export var MultiPolyline: { /** * Instantiates a multi-polyline object given an array of arrays of geographical * points (one for each individual polyline) and optionally an options object. */ - constructor(latlngs: LatLng[][], options?: PolylineOptions); + new(latlngs: LatLng[][], options?: PolylineOptions): MultiPolyline; + }; + export interface MultiPolyline extends FeatureGroup { /** * Replace all polygons and their paths with the given array of arrays * of geographical points. @@ -2986,7 +3016,7 @@ declare module L { declare module L { - export class Path extends Class implements ILayer, IEventPowered { + export interface Path extends ILayer, IEventPowered { /** * Adds the layer to the map. @@ -3049,34 +3079,6 @@ declare module L { * the path uses. */ redraw(): Path; - - /** - * True if SVG is used for vector rendering (true for most modern browsers). - */ - static SVG: boolean; - - /** - * True if VML is used for vector rendering (IE 6-8). - */ - static VML: boolean; - - /** - * True if Canvas is used for vector rendering (Android 2). You can also force - * this by setting global variable L_PREFER_CANVAS to true before the Leaflet - * include on your page — sometimes it can increase performance dramatically - * when rendering thousands of circle markers, but currently suffers from - * a bug that causes removing such layers to be extremely slow. - */ - static CANVAS: boolean; - - /** - * How much to extend the clip area around the map view (relative to its size, - * e.g. 0.5 is half the screen in each direction). Smaller values mean that you - * will see clipped ends of paths while you're dragging the map, and bigger values - * decrease drawing performance. - */ - static CLIP_PADDING: number; - //////////// //////////// /** @@ -3109,8 +3111,37 @@ declare module L { on(eventMap: any, context?: any): Path; off(eventMap?: any, context?: any): Path; } + + module Path { + /** + * True if SVG is used for vector rendering (true for most modern browsers). + */ + export var SVG: boolean; + + /** + * True if VML is used for vector rendering (IE 6-8). + */ + export var VML: boolean; + + /** + * True if Canvas is used for vector rendering (Android 2). You can also force + * this by setting global variable L_PREFER_CANVAS to true before the Leaflet + * include on your page — sometimes it can increase performance dramatically + * when rendering thousands of circle markers, but currently suffers from + * a bug that causes removing such layers to be extremely slow. + */ + export var CANVAS: boolean; + + /** + * How much to extend the clip area around the map view (relative to its size, + * e.g. 0.5 is half the screen in each direction). Smaller values mean that you + * will see clipped ends of paths while you're dragging the map, and bigger values + * decrease drawing performance. + */ + export var CLIP_PADDING: number; + } } - + declare module L { export interface PathOptions { @@ -3215,14 +3246,15 @@ declare module L { */ function point(x: number, y: number, round?: boolean): Point; - export class Point { - + export var Point: { /** * Creates a Point object with the given x and y coordinates. If optional round * is set to true, rounds the x and y values. */ - constructor(x: number, y: number, round?: boolean); + new(x: number, y: number, round?: boolean): Point; + }; + export interface Point { /** * Returns the result of addition of the current and the given points. */ @@ -3292,8 +3324,8 @@ declare module L { */ function polygon(latlngs: LatLng[], options?: PolylineOptions): Polygon; - export class Polygon extends Polyline { + export var Polygon: { /** * Instantiates a polygon object given an array of geographical points and * optionally an options object (the same as for Polyline). You can also create @@ -3301,7 +3333,10 @@ declare module L { * latlngs array representing the exterior ring while the remaining represent * the holes inside. */ - constructor(latlngs: LatLng[], options?: PolylineOptions); + new(latlngs: LatLng[], options?: PolylineOptions): Polygon; + }; + + export interface Polygon extends Polyline { } } @@ -3313,14 +3348,15 @@ declare module L { */ function polyline(latlngs: LatLng[], options?: PolylineOptions): Polyline; - export class Polyline extends Path { - + export var Polyline: { /** * Instantiates a polyline object given an array of geographical points and * optionally an options object. */ - constructor(latlngs: LatLng[], options?: PolylineOptions); - + new(latlngs: LatLng[], options?: PolylineOptions): Polyline; + }; + + export interface Polyline extends Path { /** * Adds a given point to the polyline. */ @@ -3378,7 +3414,7 @@ declare module L { declare module L { - export class PolyUtil { + module PolyUtil { /** * Clips the polygon geometry defined by the given points by rectangular bounds. @@ -3386,7 +3422,7 @@ declare module L { * increasing performance. Note that polygon points needs different algorithm * for clipping than polyline, so there's a seperate method for it. */ - static clipPolygon(points: Point[], bounds: Bounds): Point[]; + export function clipPolygon(points: Point[], bounds: Bounds): Point[]; } } @@ -3399,15 +3435,16 @@ declare module L { */ function popup(options?: PopupOptions, source?: any): Popup; - export class Popup extends Class implements ILayer { - + export var Popup: { /** * Instantiates a Popup object given an optional options object that describes * its appearance and location and an optional object that is used to tag the * popup with a reference to the source object to which it refers. */ - constructor(options?: PopupOptions, source?: any); - + new(options?: PopupOptions, source?: any): Popup; + }; + + export interface Popup extends ILayer { /** * Adds the popup to the map. */ @@ -3557,13 +3594,14 @@ declare module L { declare module L { - export class PosAnimation extends Class implements IEventPowered { - + export var PosAnimation: { /** * Creates a PosAnimation object. */ - constructor(); - + new(): PosAnimation; + }; + + export interface PosAnimation extends IEventPowered { /** * Run an animation of a given element to a new position, optionally setting * duration in seconds (0.25 by default) and easing linearity factor (3rd argument @@ -3592,21 +3630,21 @@ declare module L { declare module L { - export class Projection { + module Projection { /** * Spherical Mercator projection — the most common projection for online maps, * used by almost all free and commercial tile providers. Assumes that Earth * is a sphere. Used by the EPSG:3857 CRS. */ - static SphericalMercator: IProjection; + export var SphericalMercator: IProjection; /** * Elliptical Mercator projection — more complex than Spherical Mercator. * Takes into account that Earth is a geoid, not a perfect sphere. Used by the * EPSG:3395 CRS. */ - static Mercator: IProjection; + export var Mercator: IProjection; /** * Equirectangular, or Plate Carree projection — the most simple projection, @@ -3614,7 +3652,7 @@ declare module L { * Also suitable for flat worlds, e.g. game maps. Used by the EPSG:3395 and Simple * CRS. */ - static LonLat: IProjection; + export var LonLat: IProjection; } } @@ -3626,14 +3664,15 @@ declare module L { */ function rectangle(bounds: LatLngBounds, options?: PathOptions): Rectangle; - export class Rectangle extends Polygon { - + export var Rectangle: { /** * Instantiates a rectangle object with the given geographical bounds and * optionally an options object. */ - constructor(bounds: LatLngBounds, options?: PathOptions); - + new(bounds: LatLngBounds, options?: PathOptions): Rectangle; + }; + + export interface Rectangle extends Polygon { /** * Redraws the rectangle with the passed bounds. */ @@ -3682,14 +3721,30 @@ declare module L { declare module L { - export class TileLayer implements ILayer, IEventPowered { - + export var TileLayer: { /** * Instantiates a tile layer object given a URL template and optionally an options * object. */ - constructor(urlTemplate: string, options?: TileLayerOptions); - + new(urlTemplate: string, options?: TileLayerOptions): TileLayer; + + WMS: { + /** + * Instantiates a WMS tile layer object given a base URL of the WMS service and + * a WMS parameters/options object. + */ + new(baseUrl: string, options: WMSOptions): TileLayer.WMS; + }; + + Canvas: { + /** + * Instantiates a Canvas tile layer object given an options object (optionally). + */ + new(options?: TileLayerOptions): TileLayer.Canvas; + }; + }; + + export interface TileLayer extends ILayer, IEventPowered { /** * Adds the layer to the map. */ @@ -3764,15 +3819,7 @@ declare module L { } module TileLayer { - - export class WMS extends TileLayer { - - /** - * Instantiates a WMS tile layer object given a base URL of the WMS service and - * a WMS parameters/options object. - */ - constructor(baseUrl: string, options: WMSOptions); - + export interface WMS extends TileLayer { /** * Merges an object with the new parameters and re-requests tiles on the current * screen (unless noRedraw was set to true). @@ -3780,13 +3827,7 @@ declare module L { setParams(params: WMS, noRedraw?: boolean): WMS; } - export class Canvas { - - /** - * Instantiates a Canvas tile layer object given an options object (optionally). - */ - constructor(options?: TileLayerOptions); - + export interface Canvas { /** * You need to define this method after creating the instance to draw tiles; * canvas is the actual canvas tile on which you can draw, tilePoint represents @@ -3966,16 +4007,16 @@ declare module L { reuseTiles?: boolean; } } - + declare module L { - - export class Transformation { - + export var Transformation: { /** * Creates a transformation object with the given coefficients. */ - constructor(a: number, b: number, c: number, d: number); - + new(a: number, b: number, c: number, d: number): Transformation; + }; + + export interface Transformation { /** * Returns a transformed point, optionally multiplied by the given scale. * Only accepts real L.Point instances, not arrays. @@ -3992,24 +4033,24 @@ declare module L { declare module L { - export class Util { + module Util { /** * Merges the properties of the src object (or multiple objects) into dest object * and returns the latter. Has an L.extend shortcut. */ - static extend(dest: any, ...sources: any[]): any; + export function extend(dest: any, ...sources: any[]): any; /** * Returns a function which executes function fn with the given scope obj (so * that this keyword refers to obj inside the function code). Has an L.bind shortcut. */ - static bind(fn: T, obj: any): T; + export function bind(fn: T, obj: any): T; /** * Applies a unique key to the object and returns that key. Has an L.stamp shortcut. */ - static stamp(obj: any): string; + export function stamp(obj: any): string; /** * Returns a wrapper around the function fn that makes sure it's called not more @@ -4018,58 +4059,58 @@ declare module L { * the map), optionally passing the scope (context) in which the function will * be called. */ - static limitExecByInterval(fn: T, time: number, context?: any): T; + export function limitExecByInterval(fn: T, time: number, context?: any): T; /** * Returns a function which always returns false. */ - static falseFn(): () => boolean; + export function falseFn(): () => boolean; /** * Returns the number num rounded to digits decimals. */ - static formatNum(num: number, digits: number): number; + export function formatNum(num: number, digits: number): number; /** * Trims and splits the string on whitespace and returns the array of parts. */ - static splitWords(str: string): string[]; + export function splitWords(str: string): string[]; /** * Merges the given properties to the options of the obj object, returning the * resulting options. See Class options. Has an L.setOptions shortcut. */ - static setOptions(obj: any, options: any): any; + export function setOptions(obj: any, options: any): any; /** * Converts an object into a parameter URL string, e.g. {a: "foo", b: "bar"} * translates to '?a=foo&b=bar'. */ - static getParamString(obj: any): string; + export function getParamString(obj: any): string; /** * Simple templating facility, creates a string by applying the values of the * data object of a form {a: 'foo', b: 'bar', …} to a template string of the form * 'Hello {a}, {b}' — in this example you will get 'Hello foo, bar'. */ - static template(str: string, data: any): string; + export function template(str: string, data: any): string; /** * Returns true if the given object is an array. */ - static isArray(obj: any): boolean; + export function isArray(obj: any): boolean; /** * Trims the whitespace from both ends of the string and returns the result. */ - static trim(str: string): string; + export function trim(str: string): string; /** * Data URI string containing a base64-encoded empty GIF image. Used as a hack * to free memory from unused images on WebKit-powered mobile devices (by setting * image src to this string). */ - static emptyImageUrl: string; + export var emptyImageUrl: string; } } @@ -4182,3 +4223,5 @@ declare var L_DISABLE_3D: boolean; declare module "leaflet" { export = L; } + +// vim: et ts=4 sw=4 From 66597850ba9b562d3d1f24a34d1c6be643bbdabc Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Thu, 12 Feb 2015 16:46:14 +1300 Subject: [PATCH 013/371] Add definitions for Leaflet.label --- leaflet-label/leaflet-label-tests.ts | 140 +++++++++++++++++++++++++++ leaflet-label/leaflet-label.d.ts | 70 ++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 leaflet-label/leaflet-label-tests.ts create mode 100644 leaflet-label/leaflet-label.d.ts diff --git a/leaflet-label/leaflet-label-tests.ts b/leaflet-label/leaflet-label-tests.ts new file mode 100644 index 000000000..884f5f67e --- /dev/null +++ b/leaflet-label/leaflet-label-tests.ts @@ -0,0 +1,140 @@ +/// + +var map: L.Map; +var label: L.Label; + +// Icon +var icon: L.Icon = new L.Icon({ labelAnchor: L.point(1, 1) }); + +// CircleMarker +var circleMarker: L.CircleMarker = new L.CircleMarker(new L.LatLng(0, 0), { labelAnchor: L.point(1, 1) }); + +circleMarker = circleMarker.bindLabel('test', { + className: 'thingy', + clickable: true, + direction: 'right', + noHide: false, + offset: new L.Point(0, 0), + opacity: 0.5, + zoomAnimation: true, +}); + +circleMarker.showLabel(); +circleMarker.hideLabel(); +circleMarker.setLabelNoHide(true); +circleMarker.updateLabelContent('test2'); +label = circleMarker.getLabel() +circleMarker = circleMarker.unbindLabel(); + +// Marker +var marker = new L.Marker(new L.LatLng(0, 0)); + +marker = marker.bindLabel('test', { + className: 'thingy', + clickable: true, + direction: 'right', + noHide: false, + offset: new L.Point(0, 0), + opacity: 0.5, + zoomAnimation: true, +}); + +marker.showLabel(); +marker.hideLabel(); +marker.setLabelNoHide(true); +marker.updateLabelContent('test2'); +label = marker.getLabel() +marker = marker.unbindLabel(); +marker.setOpacity(0.5); +marker.setOpacity(0.5, true); + +// Path +var path: L.Path = new L.Polyline([L.latLng(0, 0)]); + +path = path.bindLabel('test', { + className: 'thingy', + clickable: true, + direction: 'right', + noHide: false, + offset: new L.Point(0, 0), + opacity: 0.5, + zoomAnimation: true, +}); + +path.updateLabelContent('test2'); + +path = path.unbindLabel(); + +// Label + +label.setOpacity(0.7); +label.updateZIndex(5); +label.setLatLng(new L.LatLng(3, 3)); +label.setContent('thing'); +label.close(); + +// Examples from the README +var example: () => void; + +example = () => { + L.marker(L.latLng(-37.7772, 175.2606)).bindLabel('Look revealing label!').addTo(map); +}; + +example = () => { + L.polyline([ + L.latLng(-37.7612, 175.2756), + L.latLng(-37.7702, 175.2796), + L.latLng(-37.7802, 175.2750), + ]).bindLabel('Even polylines can have labels.').addTo(map); +}; + +example = () => { + L.marker(L.latLng(-37.785, 175.263)) + .bindLabel('A sweet static label!', { noHide: true }) + .addTo(map); +}; + +example = () => { + var myIcon = L.icon({ + iconUrl: 'my-icon.png', + iconSize: L.point(20, 20), + iconAnchor: L.point(10, 10), + labelAnchor: L.point(6, 0) // as I want the label to appear 2px past the icon (10 + 2 - 6) + }); + L.marker(L.latLng(-37.7772, 175.2606), { + icon: myIcon + }).bindLabel('My label', { + noHide: true, + direction: 'auto' + }); +}; + +example = () => { + var myIcon = L.icon({ + iconUrl: 'my-icon.png', + iconSize: L.point(20, 20), + iconAnchor: L.point(10, 10), + labelAnchor: L.point(6, 0) // as I want the label to appear 2px past the icon (10 + 2 - 6) + }); + L.marker(L.latLng(-37.7772, 175.2606), { + icon: myIcon + }).bindLabel('Look revealing label!').addTo(map); +}; + +example = () => { + var markerLabel = L.marker(L.latLng(-37.7772, 175.2606)).bindLabel('Look revealing label!').addTo(map); + + // Sets opacity of marker to 0.3 and opacity of label to 1 + markerLabel.setOpacity(0.3); + + // Sets opacity of marker to 0.3 and opacity of label to 0.3 + markerLabel.setOpacity(0.3, true); + + // Sets opacity of marker to 0 and opacity of label to 0 + markerLabel.setOpacity(0); + markerLabel.setOpacity(0, true); + + // Sets opacity of marker to 1 and opacity of label to 1 + markerLabel.setOpacity(1); + markerLabel.setOpacity(1, true); +}; diff --git a/leaflet-label/leaflet-label.d.ts b/leaflet-label/leaflet-label.d.ts new file mode 100644 index 000000000..b08996025 --- /dev/null +++ b/leaflet-label/leaflet-label.d.ts @@ -0,0 +1,70 @@ +// Type definitions for Leaflet.label v0.2.1 +// Project: https://github.com/Leaflet/Leaflet.label +// Definitions by: Wim Looman +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module L { + export interface IconOptions { + labelAnchor?: Point; + } + + export interface CircleMarkerOptions { + labelAnchor?: Point; + } + + export interface Marker { + showLabel(): Marker; + hideLabel(): Marker; + setLabelNoHide(noHide: boolean): void; + bindLabel(content: string, options?: LabelOptions): Marker; + unbindLabel(): Marker; + updateLabelContent(content: string): void; + getLabel(): Label; + setOpacity(opacity: number, labelHasSemiTransparency: boolean): void; + } + + export interface CircleMarker { + showLabel(): CircleMarker; + hideLabel(): CircleMarker; + setLabelNoHide(noHide: boolean): void; + bindLabel(content: string, options?: LabelOptions): CircleMarker; + unbindLabel(): CircleMarker; + updateLabelContent(content: string): void; + getLabel(): Label; + } + + export interface FeatureGroup { + clearLayers(): FeatureGroup; + bindLabel(content: string, options?: LabelOptions): FeatureGroup; + unbindLabel(): FeatureGroup; + updateLabelContent(content: string): FeatureGroup; + } + + export interface Path { + bindLabel(content: string, options?: LabelOptions): Path; + unbindLabel(): Path; + updateLabelContent(content: string): void; + } + + export interface LabelOptions { + className?: string; + clickable?: boolean; + direction?: string; // 'left' | 'right' | 'auto'; + noHide?: boolean; + offset?: Point; + opacity?: number; + zoomAnimation?: boolean; + } + + export interface Label extends IEventPowered