Merge pull request #34460 from she11sh0cked/master

[hummus-recipe] added a namespace for types and interfaces, fixed a typo and a wrong type
This commit is contained in:
Daniel Rosenwasser
2019-04-10 14:10:25 -07:00
committed by GitHub
2 changed files with 184 additions and 162 deletions

View File

@@ -1,4 +1,4 @@
import { Recipe } from 'hummus-recipe';
import Recipe = require("hummus-recipe");
// $ExpectType Recipe
const pdf = new Recipe("new", "test.pdf", {

View File

@@ -4,20 +4,8 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export interface RecipeOptions {
version?: number;
author?: string;
title?: string;
subject?: string;
keywords?: string[];
}
export interface CommentOptions {
title?: string;
date?: string;
open?: boolean;
richText?: boolean;
flag?:
declare namespace Recipe {
type CommentOptionsFlag =
| "invisible"
| "hidden"
| "print"
@@ -27,13 +15,26 @@ export interface CommentOptions {
| "readonly"
| "locked"
| "togglenoview";
}
export interface AnotOptions {
title?: string;
open?: boolean;
richText?: boolean;
flag?:
type AnnotSubtype =
| "Text"
| "FreeText"
| "Line"
| "Square"
| "Circle"
| "Polygon"
| "PolyLine"
| "Highlight"
| "Underline"
| "Squiggly"
| "StrikeOut"
| "Stamp"
| "Caret"
| "Ink"
| "FileAttachment"
| "Sound";
type AnnotOptionsFlag =
| "invisible"
| "hidden"
| "print"
@@ -43,7 +44,8 @@ export interface AnotOptions {
| "readonly"
| "locked"
| "togglenoview";
icon?:
type AnnotOptionsIcon =
| "Comment"
| "Key"
| "Note"
@@ -51,159 +53,172 @@ export interface AnotOptions {
| "NewParagraph"
| "Paragraph"
| "Insert";
width?: number;
height?: number;
interface RecipeOptions {
version?: number;
author?: string;
title?: string;
subject?: string;
keywords?: string[];
}
interface CommentOptions {
title?: string;
date?: string;
open?: boolean;
richText?: boolean;
flag?: CommentOptionsFlag;
}
interface AnnotOptions {
title?: string;
open?: boolean;
richText?: boolean;
flag?: AnnotOptionsFlag;
icon?: AnnotOptionsIcon;
width?: number;
height?: number;
}
interface EncryptOptions {
password?: string;
ownerPassword?: string;
userProtectionFlag?: number;
}
interface ImageOptions {
width?: number;
height?: number;
scale?: number;
keepAspectRatio?: boolean;
opacity?: number;
align?: string;
}
interface InfoOptions {
version?: string;
author?: string;
title?: string;
subject?: string;
keywords?: string[];
}
interface OverlayOptions {
scale?: number;
keepAspectRatio?: boolean;
fitWidth?: boolean;
fitHeight?: boolean;
}
interface TextBoxStyle {
lineWidth?: number;
stroke?: string | number[];
dash?: number[];
fill?: string | number[];
opacity?: number;
}
interface TextBox {
width?: number;
height?: number;
minHeight?: number;
padding?: number | number[];
lineHeight?: number;
textAlign?: string;
style?: TextBoxStyle;
}
interface TextOptions {
color?: string | number[];
opacity?: number;
rotation?: number;
rotationOrigin?: number[];
font?: string;
size?: number;
align?: string;
highlight?: boolean;
underline?: boolean;
strikeOut?: boolean;
textBox?: TextBox;
}
interface LineToOptions {
color?: string | number[];
stroke?: string | number[];
fill?: string | number[];
lineWidth?: number;
opacity?: number;
dash?: number[];
}
interface LineOptions {
color?: string | number[];
stroke?: string | number[];
lineWidth?: number;
dash?: number[];
}
interface PolygonOptions {
color?: string | number[];
stroke?: string | number[];
fill?: string | number[];
lineWidth?: number;
opacity?: number;
dash?: number[];
}
interface CircleOptions {
color?: string | number[];
stroke?: string | number[];
fill?: string | number[];
lineWidth?: number;
opacity?: number;
dash?: number[];
}
interface RectangleOptions {
color?: string | number[];
stroke?: string | number[];
fill?: string | number[];
lineWidth?: number;
opacity?: number;
dash?: number[];
rotation?: number;
rotationOrigin?: number[];
}
}
export interface EncryptOptions {
password?: string;
ownerPassword?: string;
userProtectionFlag?: number;
}
export interface ImageOptions {
width?: number;
height?: number;
scale?: number;
keepAspectRatio?: boolean;
opacity?: number;
align?: string;
}
export interface InfoOptions {
version?: string;
author?: string;
title?: string;
subject?: string;
keywords?: string[];
}
export interface OverlayOptions {
scale?: number;
keepAspectRatio?: boolean;
fitWidth?: boolean;
fitHeight?: boolean;
}
export interface TextBoxStyle {
lineWidth?: number;
stroke?: string | number[];
dash?: number[];
fill?: string | number[];
opacity?: number;
}
export interface TextBox {
width?: number;
height?: number;
minHeight?: number;
padding?: number | number[];
lineHeight?: number;
textAlign?: string;
style?: TextBoxStyle;
}
export interface TextOptions {
color?: string | number[];
opacity?: number;
rotation?: number;
rotationOrigin?: number[];
font?: string;
size?: number;
align?: string;
highlight?: boolean;
underline?: boolean;
strikeOut?: boolean;
textBox?: TextBox;
}
export interface LineToOptions {
color?: string | number[];
stroke?: string | number[];
fill?: string | number[];
lineWidth?: number;
opacity?: number;
dash?: number[];
}
export interface LineOptions {
color?: string | number[];
stroke?: string | number[];
lineWidth?: number;
dash?: number[];
}
export interface PolygonOptions {
color?: string | number[];
stroke?: string | number[];
fill?: string | number[];
lineWidth?: number;
opacity?: number;
dash?: number[];
}
export interface CircleOptions {
color?: string | number[];
stroke?: string | number[];
fill?: string | number[];
lineWidth?: number;
opacity?: number;
dash?: number[];
}
export interface RectangleOptions {
color?: string | number[];
stroke?: string | number[];
fill?: string | number[];
lineWidth?: number;
opacity?: number;
dash?: number[];
rotation?: number;
rotationOrigin?: number[];
}
export class Recipe {
constructor(src: string, output: string, options?: RecipeOptions);
declare class Recipe {
constructor(src: string, output: string, options?: Recipe.RecipeOptions);
comment(
text: string,
x: number,
y: number,
options?: CommentOptions
options?: Recipe.CommentOptions
): Recipe;
annot(
x: number,
y: number,
subtype:
| "Text"
| "FreeText"
| "Line"
| "Square"
| "Circle"
| "Polygon"
| "PolyLine"
| "Highlight"
| "Underline"
| "Squiggly"
| "StrikeOut"
| "Stamp"
| "Caret"
| "Ink"
| "FileAttachment"
| "Sound",
options?: AnotOptions
subtype: Recipe.AnnotSubtype,
options?: Recipe.AnnotOptions
): Recipe;
appendPage(pdfSrc: string, pages: number | number[]): Recipe;
encrypt(options: EncryptOptions): Recipe;
encrypt(options: Recipe.EncryptOptions): Recipe;
registerFont(fontName: string, fontSrcPath: string): Recipe;
image(imgSrc: string, x: number, y: number, options?: ImageOptions): Recipe;
image(
imgSrc: string,
x: number,
y: number,
options?: Recipe.ImageOptions
): Recipe;
info(options?: InfoOptions): Recipe;
info(options?: Recipe.InfoOptions): Recipe;
custom(key?: string, value?: string): Recipe;
@@ -217,7 +232,7 @@ export class Recipe {
pdfSrc: string,
x: number,
y: number,
options?: OverlayOptions
options?: Recipe.OverlayOptions
): Recipe;
createPage(pageWidth: number, pageHeight: number): Recipe;
@@ -230,21 +245,26 @@ export class Recipe {
split(outputDir: string, prefix: string): Recipe;
text(text: string, x: number, y: number, options?: TextOptions): Recipe;
text(
text: string,
x: number,
y: number,
options?: Recipe.TextOptions
): Recipe;
moveTo(x: number, y: number): Recipe;
lineTo(x: number, y: number, options?: LineToOptions): Recipe;
lineTo(x: number, y: number, options?: Recipe.LineToOptions): Recipe;
line(coordinates: number[], options?: LineOptions): Recipe;
line(coordinates: number[][], options?: Recipe.LineOptions): Recipe;
polygon(coordinates: number[][], options?: PolygonOptions): Recipe;
polygon(coordinates: number[][], options?: Recipe.PolygonOptions): Recipe;
circle(
x: number,
y: number,
radius: number,
options?: CircleOptions
options?: Recipe.CircleOptions
): Recipe;
rectangle(
@@ -252,8 +272,10 @@ export class Recipe {
y: number,
width: number,
height: number,
options?: RectangleOptions
options?: Recipe.RectangleOptions
): Recipe;
endPDF(callback?: () => any): Recipe;
}
export = Recipe;