1
+ // Figma Plugin API version 1, update 5
2
+
1
3
// Global variable with Figma's plugin API.
2
4
declare const figma : PluginAPI
3
5
declare const __html__ : string
4
6
5
7
interface PluginAPI {
6
8
readonly apiVersion : "1.0.0"
7
9
readonly command : string
8
- readonly root : DocumentNode
9
10
readonly viewport : ViewportAPI
10
11
closePlugin ( message ?: string ) : void
11
12
13
+ notify ( message : string , options ?: NotificationOptions ) : NotificationHandler
14
+
12
15
showUI ( html : string , options ?: ShowUIOptions ) : void
13
16
readonly ui : UIAPI
14
17
@@ -17,8 +20,13 @@ interface PluginAPI {
17
20
getNodeById ( id : string ) : BaseNode | null
18
21
getStyleById ( id : string ) : BaseStyle | null
19
22
23
+ readonly root : DocumentNode
20
24
currentPage : PageNode
21
25
26
+ on ( type : "selectionchange" | "currentpagechange" | "close" , callback : ( ) => void )
27
+ once ( type : "selectionchange" | "currentpagechange" | "close" , callback : ( ) => void )
28
+ off ( type : "selectionchange" | "currentpagechange" | "close" , callback : ( ) => void )
29
+
22
30
readonly mixed : symbol
23
31
24
32
createRectangle ( ) : RectangleNode
@@ -28,17 +36,27 @@ interface PluginAPI {
28
36
createStar ( ) : StarNode
29
37
createVector ( ) : VectorNode
30
38
createText ( ) : TextNode
31
- createBooleanOperation ( ) : BooleanOperationNode
32
39
createFrame ( ) : FrameNode
33
40
createComponent ( ) : ComponentNode
34
41
createPage ( ) : PageNode
35
42
createSlice ( ) : SliceNode
43
+ /**
44
+ * [DEPRECATED]: This API often fails to create a valid boolean operation. Use figma.union, figma.subtract, figma.intersect and figma.exclude instead.
45
+ */
46
+ createBooleanOperation ( ) : BooleanOperationNode
36
47
37
48
createPaintStyle ( ) : PaintStyle
38
49
createTextStyle ( ) : TextStyle
39
50
createEffectStyle ( ) : EffectStyle
40
51
createGridStyle ( ) : GridStyle
41
52
53
+ // The styles are returned in the same order as displayed in the UI. Only
54
+ // local styles are returned. Never styles from team library.
55
+ getLocalPaintStyles ( ) : PaintStyle [ ]
56
+ getLocalTextStyles ( ) : TextStyle [ ]
57
+ getLocalEffectStyles ( ) : EffectStyle [ ]
58
+ getLocalGridStyles ( ) : GridStyle [ ]
59
+
42
60
importComponentByKeyAsync ( key : string ) : Promise < ComponentNode >
43
61
importStyleByKeyAsync ( key : string ) : Promise < BaseStyle >
44
62
@@ -53,35 +71,54 @@ interface PluginAPI {
53
71
54
72
group ( nodes : ReadonlyArray < BaseNode > , parent : BaseNode & ChildrenMixin , index ?: number ) : FrameNode
55
73
flatten ( nodes : ReadonlyArray < BaseNode > , parent ?: BaseNode & ChildrenMixin , index ?: number ) : VectorNode
74
+
75
+ union ( nodes : ReadonlyArray < BaseNode > , parent : BaseNode & ChildrenMixin , index ?: number ) : BooleanOperationNode
76
+ subtract ( nodes : ReadonlyArray < BaseNode > , parent : BaseNode & ChildrenMixin , index ?: number ) : BooleanOperationNode
77
+ intersect ( nodes : ReadonlyArray < BaseNode > , parent : BaseNode & ChildrenMixin , index ?: number ) : BooleanOperationNode
78
+ exclude ( nodes : ReadonlyArray < BaseNode > , parent : BaseNode & ChildrenMixin , index ?: number ) : BooleanOperationNode
56
79
}
57
80
58
81
interface ClientStorageAPI {
59
82
getAsync ( key : string ) : Promise < any | undefined >
60
83
setAsync ( key : string , value : any ) : Promise < void >
61
84
}
62
85
63
- type ShowUIOptions = {
86
+ interface NotificationOptions {
87
+ timeout ?: number ,
88
+ }
89
+
90
+ interface NotificationHandler {
91
+ cancel : ( ) => void ,
92
+ }
93
+
94
+ interface ShowUIOptions {
64
95
visible ?: boolean ,
65
96
width ?: number ,
66
97
height ?: number ,
98
+ position ?: 'default' | 'last' | 'auto' // PROPOSED API ONLY
67
99
}
68
100
69
- type UIPostMessageOptions = {
70
- targetOrigin ?: string ,
101
+ interface UIPostMessageOptions {
102
+ origin ?: string ,
71
103
}
72
104
73
- type OnMessageProperties = {
74
- sourceOrigin : string ,
105
+ interface OnMessageProperties {
106
+ origin : string ,
75
107
}
76
108
109
+ type MessageEventHandler = ( pluginMessage : any , props : OnMessageProperties ) => void
110
+
77
111
interface UIAPI {
78
112
show ( ) : void
79
113
hide ( ) : void
80
114
resize ( width : number , height : number ) : void
81
115
close ( ) : void
82
116
83
117
postMessage ( pluginMessage : any , options ?: UIPostMessageOptions ) : void
84
- onmessage : ( ( pluginMessage : any , props : OnMessageProperties ) => void ) | undefined
118
+ onmessage : MessageEventHandler | undefined
119
+ on ( type : "message" , callback : MessageEventHandler )
120
+ once ( type : "message" , callback : MessageEventHandler )
121
+ off ( type : "message" , callback : MessageEventHandler )
85
122
}
86
123
87
124
interface ViewportAPI {
@@ -161,13 +198,13 @@ interface ColorStop {
161
198
}
162
199
163
200
interface ImageFilters {
164
- exposure ?: number
165
- contrast ?: number
166
- saturation ?: number
167
- temperature ?: number
168
- tint ?: number
169
- highlights ?: number
170
- shadows ?: number
201
+ readonly exposure ?: number
202
+ readonly contrast ?: number
203
+ readonly saturation ?: number
204
+ readonly temperature ?: number
205
+ readonly tint ?: number
206
+ readonly highlights ?: number
207
+ readonly shadows ?: number
171
208
}
172
209
173
210
interface SolidPaint {
@@ -297,7 +334,7 @@ interface VectorPath {
297
334
298
335
type VectorPaths = ReadonlyArray < VectorPath >
299
336
300
- type LetterSpacing = {
337
+ interface LetterSpacing {
301
338
readonly value : number
302
339
readonly unit : "PIXELS" | "PERCENT"
303
340
}
@@ -340,7 +377,7 @@ interface Font {
340
377
interface BaseNodeMixin {
341
378
readonly id : string
342
379
readonly parent : ( BaseNode & ChildrenMixin ) | null
343
- name : string // Note: setting this also sets `autoRename` to false on TextNodes
380
+ name : string // Note: setting this also sets \ `autoRename\ ` to false on TextNodes
344
381
readonly removed : boolean
345
382
toString ( ) : string
346
383
remove ( ) : void
@@ -360,13 +397,13 @@ interface SceneNodeMixin {
360
397
}
361
398
362
399
interface ChildrenMixin {
363
- readonly children : ReadonlyArray < BaseNode >
400
+ readonly children : ReadonlyArray < SceneNode >
364
401
365
- appendChild ( child : BaseNode ) : void
366
- insertChild ( index : number , child : BaseNode ) : void
402
+ appendChild ( child : SceneNode ) : void
403
+ insertChild ( index : number , child : SceneNode ) : void
367
404
368
- findAll ( callback ?: ( node : BaseNode ) => boolean ) : ReadonlyArray < BaseNode >
369
- findOne ( callback : ( node : BaseNode ) => boolean ) : BaseNode | null
405
+ findAll ( callback ?: ( node : SceneNode ) => boolean ) : SceneNode [ ]
406
+ findOne ( callback : ( node : SceneNode ) => boolean ) : SceneNode | null
370
407
}
371
408
372
409
interface ConstraintMixin {
@@ -426,7 +463,7 @@ interface CornerMixin {
426
463
}
427
464
428
465
interface ExportMixin {
429
- exportSettings : ExportSettings [ ]
466
+ exportSettings : ReadonlyArray < ExportSettings >
430
467
exportAsync ( settings ?: ExportSettings ) : Promise < Uint8Array > // Defaults to PNG format
431
468
}
432
469
@@ -444,8 +481,16 @@ interface DefaultContainerMixin extends
444
481
////////////////////////////////////////////////////////////////////////////////
445
482
// Nodes
446
483
447
- interface DocumentNode extends BaseNodeMixin , ChildrenMixin {
484
+ interface DocumentNode extends BaseNodeMixin {
448
485
readonly type : "DOCUMENT"
486
+
487
+ readonly children : ReadonlyArray < PageNode >
488
+
489
+ appendChild ( child : PageNode ) : void
490
+ insertChild ( index : number , child : PageNode ) : void
491
+
492
+ findAll ( callback ?: ( node : ( PageNode | SceneNode ) ) => boolean ) : Array < PageNode | SceneNode >
493
+ findOne ( callback : ( node : ( PageNode | SceneNode ) ) => boolean ) : PageNode | SceneNode | null
449
494
}
450
495
451
496
interface PageNode extends BaseNodeMixin , ChildrenMixin , ExportMixin {
@@ -454,6 +499,8 @@ interface PageNode extends BaseNodeMixin, ChildrenMixin, ExportMixin {
454
499
455
500
guides : ReadonlyArray < Guide >
456
501
selection : ReadonlyArray < SceneNode >
502
+
503
+ backgrounds : ReadonlyArray < Paint >
457
504
}
458
505
459
506
interface FrameNode extends DefaultContainerMixin {
@@ -652,4 +699,4 @@ interface GridStyle extends BaseStyle {
652
699
interface Image {
653
700
readonly hash : string
654
701
getBytesAsync ( ) : Promise < Uint8Array >
655
- }
702
+ }
0 commit comments