Skip to content

Commit c3bcd97

Browse files
committed
Add types
1 parent 3dff7d7 commit c3bcd97

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"license": "MIT",
2424
"main": "./dist",
25+
"types": "./types/index.d.ts",
2526
"scripts": {
2627
"build": "cross-env NODE_ENV=production webpack --mode production --config webpack/library.cfg.js --display-modules",
2728
"build:light": "babel ./src --out-dir ./dist",

types/index.d.ts

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
declare module 'react-sketch' {
2+
import * as React from 'react'
3+
4+
export class SketchField extends React.PureComponent<{
5+
// the color of the line
6+
lineColor?: string
7+
// The width of the line
8+
lineWidth?: number
9+
// the fill color of the shape when applicable
10+
fillColor?: string
11+
// the background color of the sketch
12+
backgroundColor?: string,
13+
// the opacity of the object
14+
opacity?: number
15+
// number of undo/redo steps to maintain
16+
undoSteps?: number
17+
// The tool to use, can be pencil, rectangle, circle, brush;
18+
tool?: string
19+
// image format when calling toDataURL
20+
imageFormat?: string
21+
// Sketch data for controlling sketch from
22+
// outside the component
23+
value?: object
24+
// Set to true if you wish to force load the given value, even if it is the same
25+
forceValue?: boolean
26+
// Specify some width correction which will be applied on auto resize
27+
widthCorrection?: number
28+
// Specify some height correction which will be applied on auto resize
29+
heightCorrection?: number
30+
// Specify action on change
31+
onChange?: (evt: any) => void,
32+
// Default initial value
33+
defaultValue?: {},
34+
// Sketch width
35+
width?: number
36+
// Sketch height
37+
height?: number
38+
// Class name to pass to container div of canvas
39+
className?: string
40+
// Style options to pass to container div of canvas
41+
style?: {}
42+
}> {
43+
44+
/**
45+
* Enable touch Scrolling on Canvas
46+
*/
47+
enableTouchScroll(): void
48+
49+
/**
50+
* Disable touch Scrolling on Canvas
51+
*/
52+
disableTouchScroll(): void
53+
54+
/**
55+
* Add an image as object to the canvas
56+
*
57+
* @param dataUrl the image url or Data Url
58+
* @param options object to pass and change some options when loading image, the format of the object is:
59+
*
60+
* {
61+
* left: <Number: distance from left of canvas>,
62+
* top: <Number: distance from top of canvas>,
63+
* scale: <Number: initial scale of image>
64+
* }
65+
*/
66+
addImg(dataUrl: string, options?: { left?: number, top?: number, scale?: number }): void
67+
68+
/**
69+
* Zoom the drawing by the factor specified
70+
*
71+
* The zoom factor is a percentage with regards the original, for example if factor is set to 2
72+
* it will double the size whereas if it is set to 0.5 it will half the size
73+
*
74+
* @param factor the zoom factor
75+
*/
76+
zoom(factor: number): void
77+
78+
/**
79+
* Perform an undo operation on canvas, if it cannot undo it will leave the canvas intact
80+
*/
81+
undo(): void
82+
83+
/**
84+
* Perform a redo operation on canvas, if it cannot redo it will leave the canvas intact
85+
*/
86+
redo(): void
87+
88+
/**
89+
* Delegation method to check if we can perform an undo Operation, useful to disable/enable possible buttons
90+
*
91+
* @returns {*} true if we can undo otherwise false
92+
*/
93+
canUndo(): boolean
94+
95+
/**
96+
* Delegation method to check if we can perform a redo Operation, useful to disable/enable possible buttons
97+
*
98+
* @returns {*} true if we can redo otherwise false
99+
*/
100+
canRedo(): boolean
101+
102+
/**
103+
* Exports canvas element to a dataurl image. Note that when multiplier is used, cropping is scaled appropriately
104+
*
105+
* Available Options are
106+
* <table style="width:100%">
107+
*
108+
* <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Argument</b></td><td><b>Default</b></td><td><b>Description</b></td></tr>
109+
* <tr><td>format</td> <td>String</td> <td><optional></td><td>png</td><td>The format of the output image. Either "jpeg" or "png"</td></tr>
110+
* <tr><td>quality</td><td>Number</td><td><optional></td><td>1</td><td>Quality level (0..1). Only used for jpeg.</td></tr>
111+
* <tr><td>multiplier</td><td>Number</td><td><optional></td><td>1</td><td>Multiplier to scale by</td></tr>
112+
* <tr><td>left</td><td>Number</td><td><optional></td><td></td><td>Cropping left offset. Introduced in v1.2.14</td></tr>
113+
* <tr><td>top</td><td>Number</td><td><optional></td><td></td><td>Cropping top offset. Introduced in v1.2.14</td></tr>
114+
* <tr><td>width</td><td>Number</td><td><optional></td><td></td><td>Cropping width. Introduced in v1.2.14</td></tr>
115+
* <tr><td>height</td><td>Number</td><td><optional></td><td></td><td>Cropping height. Introduced in v1.2.14</td></tr>
116+
*
117+
* </table>
118+
*
119+
* @returns {String} URL containing a representation of the object in the format specified by options.format
120+
*/
121+
toDataURL(options?: {
122+
format?: string
123+
quality?: number
124+
multiplier?: number
125+
left?: number
126+
top?: number
127+
width?: number
128+
height?: number
129+
}): string
130+
131+
/**
132+
* Returns JSON representation of canvas
133+
*
134+
* @param propertiesToInclude Array <optional> Any properties that you might want to additionally include in the output
135+
* @returns {string} JSON string
136+
*/
137+
toJSON(propertiesToInclude?: ArrayLike<string>): string
138+
139+
/**
140+
* Populates canvas with data from the specified JSON.
141+
*
142+
* JSON format must conform to the one of fabric.Canvas#toDatalessJSON
143+
*
144+
* @param json JSON string or object
145+
*/
146+
fromJSON(json: string): void
147+
148+
/**
149+
* Clear the content of the canvas, this will also clear history but will return the canvas content as JSON to be
150+
* used as needed in order to undo the clear if possible
151+
*
152+
* @param propertiesToInclude Array <optional> Any properties that you might want to additionally include in the output
153+
* @returns {string} JSON string of the canvas just cleared
154+
*/
155+
clear(propertiesToInclude?: ArrayLike<string>): string
156+
157+
/**
158+
* Remove selected object from the canvas
159+
*/
160+
removeSelected(): void
161+
162+
copy(): void
163+
164+
paste(): void
165+
166+
/**
167+
* Sets the background from the dataUrl given
168+
*
169+
* @param dataUrl the dataUrl to be used as a background
170+
* @param options
171+
*/
172+
setBackgroundFromDataUrl(dataUrl: string, options?: {
173+
stretched?: boolean
174+
stretchedX?: boolean
175+
stretchedY?: boolean
176+
[name: string]: any
177+
}): void
178+
179+
addText(text: string, options?: {}): void
180+
181+
}
182+
}

0 commit comments

Comments
 (0)