diff --git a/geopattern/geopattern-tests.ts b/geopattern/geopattern-tests.ts new file mode 100644 index 0000000000..79def7a91e --- /dev/null +++ b/geopattern/geopattern-tests.ts @@ -0,0 +1,4 @@ +/// + +var pattern = GeoPattern.generate('GitHub'); +pattern.toDataUrl(); diff --git a/geopattern/index.d.ts b/geopattern/index.d.ts new file mode 100644 index 0000000000..77584571c9 --- /dev/null +++ b/geopattern/index.d.ts @@ -0,0 +1,70 @@ +// Type definitions for GeoPattern v1.2.3 +// Project: https://github.com/btmills/geopattern +// Definitions by: Gaelan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace GeoPattern; + +/** + * Returns a newly-generated, tiling SVG Pattern. + * + * @param string Will be hashed using the SHA1 algorithm, and the resulting hash + * will be used as the seed for generation. + */ +export function generate(string: string, options?: PatternOptions): Pattern; + +export interface PatternOptions { + /** + * Specify an exact background color. This is a CSS hexadecimal color + * value. + */ + color: string; + + /** + * Controls the relative background color of the generated image. The color + * is not identical to that used in the pattern because the hue is rotated + * by the generator. This is a CSS hexadecimal color value, which defaults + * to #933c3c. + */ + baseColor: string; + + /** + * Determines the pattern. All of the original patterns from the Ruby + * version at jasonlong/geo_pattern are available in this port, and their + * names are camelCased. + */ + generator: GeneratorType; +} + +export type GeneratorType = 'chevrons' | 'octagons' | 'overlappingCircles' | + 'plusSigns' | 'xes' | 'sineWaves' | 'hexagons' | 'overlappingRings' | + 'plaid' |'triangles' | 'squares' | 'nestedSquares' | 'mosaicSquares' | + 'concentricCircles' | 'diamonds' | 'tessellation'; + +export interface Pattern { + /** Gets the pattern's background color as a hexadecimal string. */ + color: string; + + /** Gets the SVG string representing the pattern. */ + toString(): string; + + /** Gets the SVG string representing the pattern. */ + toSvg(): string; + + /** Gets the SVG as a Base64-encoded string. */ + toBase64(): string; + + /** + * Gets the pattern as a data URI, + * i.e. data:image/svg+xml;base64,PHN2ZyB... + */ + toDataUri(): string; + + /** + * Gets the pattern as a data URL suitable for use as a CSS + * background-image, i.e. url("data:image/svg+xml;base64,PHN2ZyB..."). + */ + toDataUrl(): string; +} + +// TODO: implement the jQuery plugin. diff --git a/geopattern/tsconfig.json b/geopattern/tsconfig.json new file mode 100644 index 0000000000..4dd9479920 --- /dev/null +++ b/geopattern/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "geopattern-tests.ts" + ] +} diff --git a/geopattern/tslint.json b/geopattern/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/geopattern/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }