-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.d.ts
More file actions
1935 lines (1697 loc) · 47.6 KB
/
plugin.d.ts
File metadata and controls
1935 lines (1697 loc) · 47.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import './mg-dsl.d'
import './mg-comp-temp.d'
declare global {
/**
* @deprecated please use mg instead
*/
const mastergo: PluginAPI
const mg: PluginAPI
const console: Console
const __html__: string
function setTimeout(callback: Function, timeout: number): number
function clearTimeout(timeoutID: number): void
function setInterval(callback: Function, timeout: number): number
function clearInterval(timeoutID: number): void
function requestAnimationFrame(cb: (ts: number) => void): number
function cancelAnimationFrame(requestID: number): void
interface Console {
log(message?: any, ...optionalParams: any[]): void
error(message?: any, ...optionalParams: any[]): void
assert(condition?: boolean, message?: string, ...data: any[]): void
info(message?: any, ...optionalParams: any[]): void
warn(message?: any, ...optionalParams: any[]): void
clear(): void
}
interface ConfirmAction {
label: string
type: 'primary' | 'text'
action: () => void
}
interface PromptAction {
label: string
type: 'primary' | 'text'
action: (value: string) => void
}
interface Image {
readonly href: string
getBytesAsync(): Promise<Uint8Array>
}
type ThemeColor = 'dark' | 'light'
type LayoutInfo = {
leftbar: number
rightbar: number
canvas: number
window: number
height: number
topbar: number
}
type MGEventCallbackMap = {
selectionchange: (selectionLayerIds: string[]) => void
layoutchange: (layoutInfo: LayoutInfo) => void
currentpagechange: (pageId: string) => void
themechange: (theme: ThemeColor) => void
drop: (event: DropEvent) => void
run: (command: { command: string }) => void
close: () => void
beforeReadyForDev: (
sectionLayerId: string,
callback: (setReady: boolean) => void
) => void
}
type PluginEventType = keyof MGEventCallbackMap
interface PluginAPI {
readonly document: DocumentNode
readonly ui: UIAPI
readonly themeColor: ThemeColor
readonly apiVersion: string
readonly documentId: number
readonly pluginId: number
readonly command: string
readonly mixed: string | symbol
readonly clientStorage: ClientStorageAPI
readonly currentUser: User | null
readonly viewport: ViewportAPI
/**
* @note only available in devMode
*/
readonly codegen?: CodegenAPI
readonly snippetgen?: SnippetgenAPI
readonly mode?: 'inspect' | 'design' | 'codegen' | 'snippetgen'
closePlugin(): void
on<T extends PluginEventType>(
type: T,
callback: MGEventCallbackMap[T]
): void
once<T extends PluginEventType>(
type: T,
callback: MGEventCallbackMap[T]
): void
off<T extends PluginEventType>(
type?: T,
callback?: MGEventCallbackMap[T]
): void
commitUndo(): void
triggerUndo(): void
showUI(html: string, options?: ShowUIOptions): void
getNodeById<T extends SceneNode>(id: string): T | null
getNodeByPosition(position: { x: number; y: number }): SceneNode | null
createRectangle(): RectangleNode
createLine(): LineNode
createEllipse(): EllipseNode
createPolygon(): PolygonNode
createStar(): StarNode
createPen(): PenNode
createText(): TextNode
createFrame(children?: SceneNode[]): FrameNode
createComponent(children?: SceneNode[]): ComponentNode
createSection(): SectionNode
createPage(): PageNode
createSlice(): SliceNode
createConnector(): ConnectorNode
createNodeFromSvgAsync(svg: string): Promise<FrameNode>
combineAsVariants(nodes: ComponentNode[]): ComponentSetNode
getHoverLayer(): PageNode | SceneNode
/**
* @deprecated
* This function is deprecated, please use viewport.layoutGridVisible instead.
*/
showGrid(show: boolean): void
group(children: SceneNode[]): GroupNode
union(children: SceneNode[]): BooleanOperationNode
subtract(children: SceneNode[]): BooleanOperationNode
intersect(children: SceneNode[]): BooleanOperationNode
exclude(children: SceneNode[]): BooleanOperationNode
flatten(nodes: SceneNode[]): PenNode | null
saveVersionHistoryAsync(desc: string, title?: string): Promise<void>
notify(message: string, options?: NotifyOptions): NotificationHandler
getStyleById(id: string): Style | null
getStyleCodeById(id: string, options?: StyleCodeOptions): CodeString | null
getWebStyleCodeById(
id: string,
options?: WebStyleCodeOptions
): CodeString | null
getAndroidStyleCodeById(
id: string,
options?: AndroidStyleCodeOptions
): CodeString | null
getIOSStyleCodeById(
id: string,
options?: IOSStyleCodeOptions
): CodeString | null
getTitleByFontFamilyAndStyle(
fontFamily: string,
fontStyle: string
): FontAlias | null
createFillStyle(config: CreateStyleConfig): PaintStyle
createEffectStyle(config: CreateStyleConfig): EffectStyle
createTextStyle(config: CreateStyleConfig): TextStyle
createGridStyle(config: CreateStyleConfig): GridStyle
createCornerRadiusStyle(config: CreateStyleConfig): CornerRadiusStyle
createPaddingStyle(config: CreateStyleConfig): PaddingStyle
createSpacingStyle(config: CreateStyleConfig): SpacingStyle
/**
* @deprecated please use createStrokeFillStyle instead
*/
createStrokeStyle(config: CreateStyleConfig): PaintStyle
createStrokeFillStyle(config: CreateStyleConfig): PaintStyle
createStrokeWidthStyle(config: CreateStyleConfig): StrokeWidthStyle
/**
* createFillStyle/createStrokeFillStyle 这些函数的聚合函数,传入不同的 type,返回对应的 style
* @param layerId
* @param type NodeStyleType
* @param styleName
* @param description optional
*/
createStyleByLayer<T extends NodeStyleType>(
layerId: string,
type: T,
styleName: string,
description?: string
): NodeStyleReturnType<T>
/**
* 创建一个新的默认样式,不依赖某一个图层中的样式,
* eg: createStyle('PAINT', 'New Style', 'This is a new style')
* @param type styleType
* @param styleName
* @param description optional
*/
createStyle<T extends StyleType>(
type: T,
styleName: string,
description?: string
): StyleReturnType<T>
/**
* 创建某一个样式的副本
* @param sourceStyleId 副本的源样式id
* @param type
* @param styleName
* @param description
*/
createStyleCopy<T extends StyleType = 'PAINT'>(
sourceStyleId: string,
styleName?: string,
description?: string
): StyleReturnType<T>
getLocalPaintStyles(): PaintStyle[]
getLocalEffectStyles(): EffectStyle[]
getLocalTextStyles(): TextStyle[]
getLocalGridStyles(): GridStyle[]
getLocalStrokeWidthStyles(): StrokeWidthStyle[]
getLocalCornerRadiusStyles(): CornerRadiusStyle[]
getLocalPaddingStyles(): PaddingStyle[]
getLocalSpacingStyles(): SpacingStyle[]
listAvailableFontsAsync(): Promise<Font[]>
loadFontAsync(fontName: FontName): Promise<boolean>
createImage(imageData: Uint8Array, isSync?: boolean): Promise<Image>
getImageByHref(href: string): Image
getTeamLibraryAsync(): Promise<TeamLibrary>
importComponentByKeyAsync(ukey: string): Promise<ComponentNode>
importComponentSetByKeyAsync(ukey: string): Promise<ComponentSetNode>
importStyleByKeyAsync(ukey: string): Promise<Style>
/**
* @deprecated
*
* This attribute is deprecated, please use getTeamLibraryAsync instead.
*/
teamLibrary: TeamLibrary
hexToRGBA(hex: string): RGBA
RGBAToHex(rgba: RGBA): string
confirm: (
message: string,
options: [ConfirmAction, ...ConfirmAction[]]
) => void
prompt: (
message: string,
defaultValue: string,
options: [PromptAction, ...PromptAction[]]
) => void
}
interface User {
id: string | null
name: string | 'Anonymous'
photoUrl: string | null
}
interface Rect extends Readonly<Bound> {}
interface NotificationHandler {
cancel: () => void
}
interface Layout {
canvas: number
leftbar: number
rightbar: number
window: number
}
interface PositionOnDom {
width: number
height: number
x: number
y: number
}
interface ViewportAPI {
center: Vector
zoom: number
readonly bound: Rect
/**
* @deprecated
*/
readonly layout: Layout
readonly positionOnDom: PositionOnDom
rulerVisible: boolean
layoutGridVisible: boolean
scrollAndZoomIntoView(nodes: SceneNode[]): void
}
interface ClientStorageAPI {
getAsync(key: string): Promise<any | undefined>
setAsync(key: string, value: any): Promise<void>
deleteAsync(key: string): Promise<void>
keysAsync(): Promise<string[]>
}
type ShowUIOptions = {
width?: number
height?: number
visible?: boolean
x?: number | string
y?: number | string
}
interface ExportSettingsConstraints {
type: 'SCALE' | 'WIDTH' | 'HEIGHT'
value: number
}
interface ExportSettingsImage {
readonly format: 'JPG' | 'PNG' | 'WEBP'
readonly isSuffix?: boolean
readonly fileName?: string
readonly constraint?: ExportSettingsConstraints
readonly useAbsoluteBounds?: boolean // defaults to true
readonly useRenderBounds?: boolean // default to true
}
interface ExportSettingsSVG {
readonly format: 'SVG'
readonly isSuffix?: boolean
readonly fileName?: string
}
interface ExportSettingsPDF {
readonly format: 'PDF'
readonly isSuffix?: string
readonly fileName?: string
readonly useAbsoluteBounds?: boolean // defaults to true
readonly useRenderBounds?: boolean // default to true
}
type ExportSettings =
| ExportSettingsImage
| ExportSettingsSVG
| ExportSettingsPDF
interface ExportMixin {
exportSettings: ReadonlyArray<ExportSettings>
export(settings?: ExportSettings): Uint8Array | string // Defaults to PNG format
exportAsync(settings?: ExportSettings): Promise<Uint8Array | string>
}
interface NotifyOptions {
position?: 'top' | 'bottom'
type?: 'normal' | 'highlight' | 'error' | 'warning' | 'success'
timeout?: number
isLoading?: boolean
}
type CodeType = 'Web' | 'iOS' | 'Android'
type WebCodeLang = 'css' | 'less' | 'sass'
type AndroidCodeLang = 'xml'
type IOSCodeLang = 'swift'
type CodeLang = WebCodeLang | AndroidCodeLang | IOSCodeLang
type WebCodeUnit = 'px' | 'rem' | 'rpx'
type AndroidCodeUnit = 'dp' | 'dp/sp'
type IOSCodeUnit = 'pt'
type CodeUnit = WebCodeUnit | AndroidCodeUnit | IOSCodeUnit
interface StyleCodeOptions {
codeType?: CodeType
codeLang?: CodeLang
unit?: CodeUnit
pixelRatio?: number
}
interface WebStyleCodeOptions {
codeLang?: WebCodeLang
unit?: WebCodeUnit
pixelRatio?: number
}
interface AndroidStyleCodeOptions {
pixelRatio?: number
}
interface IOSStyleCodeOptions {
pixelRatio?: number
}
type CodeData = {
layout?: string
style?: string
typography?: string
other?: string
}
interface CodeString {
type: 'CSS' | 'iOS' | 'Android'
data: CodeData | ''
}
interface UIViewport extends Bound {
readonly headerHeight: number
readonly visible: boolean
}
interface UIAPI {
show(): void
hide(): void
close(): void
resize(width: number, height: number): void
moveTo(x: number, y: number): void
viewport: UIViewport
postMessage(pluginMessage: any, origin?: string): void
onmessage: ((pluginMessage: any, origin: string) => void) | undefined
}
type PublishStatus = 'UNPUBLISHED' | 'CURRENT' | 'CHANGED'
interface DocumentationLink {
readonly uri: string
}
interface PublishableMixin {
description: string
documentationLinks: ReadonlyArray<DocumentationLink>
/**
* @description 组件或者组件集的别名
*/
alias: string
/**
* @description 是否为团队库组件/样式
*/
readonly isExternal: boolean
readonly ukey: string
readonly publishStatus: PublishStatus
}
// Styles
type StyleType =
| 'PAINT'
| 'TEXT'
| 'EFFECT'
| 'GRID'
| 'STROKE_WIDTH'
| 'CORNER_RADIUS'
| 'PADDING'
| 'SPACING'
type NodeStyleType =
| 'fill'
| 'strokeFill'
| 'strokeWidth'
| 'cornerRadius'
| 'padding'
| 'spacing'
interface BaseStyle extends Omit<PublishableMixin, 'documentationLinks'> {
readonly id: string
readonly type: StyleType
name: string
remove(): void
}
interface PaintStyle extends BaseStyle {
type: 'PAINT'
paints: ReadonlyArray<Paint>
}
interface StrokeWidthStyle extends BaseStyle {
type: 'STROKE_WIDTH'
value: StrokeWidth
}
interface CornerRadiusStyle extends BaseStyle {
type: 'CORNER_RADIUS'
value: CornerRadius
}
interface PaddingStyle extends BaseStyle {
type: 'PADDING'
value: Padding
}
interface SpacingStyle extends BaseStyle {
type: 'SPACING'
value: Spacing
}
interface NumValue {
value: number
unit: 'PIXELS' | 'PERCENT'
}
interface TextSegStyle {
start: number
end: number
textStyleId: string
textStyle: {
fontName: FontName
localizedFontName: FontName
referrer: FontReferrer
fontSize: number
letterSpacing: LetterSpacing
lineHeight: LineHeight
lineHeightByPx: number
textDecoration: TextDecoration
textCase: TextCase
fontWeight: number
}
fills: Paint[]
fillStyleId: string
}
interface ListStyle {
start: number
end: number
level: number
type: 'ORDERED' | 'BULLETED' | 'NONE'
}
interface EffectStyle extends BaseStyle {
type: 'EFFECT'
effects: ReadonlyArray<Effect>
}
interface TextStyle extends BaseStyle {
type: 'TEXT'
decoration: TextDecoration
fontSize: number
letterSpacing: number
letterSpacingUnit: NumValue['unit']
textCase: TextCase
lineHeight: LineHeight
fontName: FontName
}
interface FontAlias {
title: string
subtitle: string
}
interface GridStyle extends BaseStyle {
type: 'GRID'
layoutGrids: ReadonlyArray<LayoutGrid>
}
type Style =
| PaintStyle
| EffectStyle
| TextStyle
| GridStyle
| StrokeWidthStyle
| CornerRadiusStyle
| PaddingStyle
| SpacingStyle
/// /////////////////////////////////////////////////////////////////////////////
// Datatypes
type Transform = [[number, number, number], [number, number, number]]
interface Vector {
readonly x: number
readonly y: number
}
interface RGB {
readonly r: number
readonly g: number
readonly b: number
}
interface RGBA {
readonly r: number
readonly g: number
readonly b: number
readonly a: number
}
interface FontName {
readonly family: string
readonly style: string
}
type TextCase = 'ORIGINAL' | 'UPPER' | 'LOWER' | 'TITLE'
type TextDecoration = 'NONE' | 'UNDERLINE' | 'STRIKETHROUGH'
interface ShadowEffect {
readonly type: 'DROP_SHADOW' | 'INNER_SHADOW'
readonly color: RGBA
// Effect的 x, y;
readonly offset: Vector
readonly spread: number
readonly radius: number
readonly isVisible: boolean
readonly blendMode: BlendMode
readonly showShadowBehindNode: boolean
readonly isEffectShow: boolean
}
interface BlurEffect {
readonly type: 'LAYER_BLUR' | 'BACKGROUND_BLUR'
readonly radius: number
readonly isVisible: boolean
readonly blendMode: BlendMode
readonly gradient: PluginGradientEffect
}
interface PluginGradientEffect {
readonly mode: 'EVEN' | 'PROGRESSIVE'
readonly gradientStops?: ReadonlyArray<PluginGradientStopItem>
readonly gradientHandlePositions?: [Point, Point]
readonly transform?: Transform
}
interface PluginGradientStopItem {
readonly position: number
readonly value: number
}
interface Point {
readonly x: number
readonly y: number
}
interface LiquidGlassEffect {
readonly type: 'LIQUID_GLASS'
readonly depth: number
readonly dispersion: number
readonly refraction: number
readonly lightIntensity: number
readonly lightAngle: number
readonly isVisible: boolean
readonly radius: number
readonly blendMode: BlendMode
}
interface MotionBlurEffect {
readonly isVisible: boolean
readonly radius: number
readonly angle: number
readonly blendMode: BlendMode
}
type Effect = ShadowEffect | BlurEffect | LiquidGlassEffect | MotionBlurEffect
// 待确认
type ConstraintType = 'START' | 'END' | 'STARTANDEND' | 'CENTER' | 'SCALE'
interface Constraints {
readonly horizontal: ConstraintType
readonly vertical: ConstraintType
}
interface ColorStop {
readonly position: number
readonly color: RGBA
}
interface SolidPaint {
readonly type: 'SOLID'
readonly color: RGBA
readonly isVisible?: boolean
/**
* It always be 1 when type is 'SOLID', please modify the alpha field in color instead.
* 纯色模式下alpha始终为1, 请设置color中的alpha.
*/
readonly alpha?: number
readonly blendMode?: BlendMode
readonly name?: string
}
interface GradientPaint {
readonly type:
| 'GRADIENT_LINEAR'
| 'GRADIENT_RADIAL'
| 'GRADIENT_ANGULAR'
| 'GRADIENT_DIAMOND'
readonly transform: Transform
readonly gradientStops: ReadonlyArray<ColorStop>
readonly gradientHandlePositions?: [
{ x: number; y: number },
{ x: number; y: number }
]
readonly isVisible?: boolean
readonly alpha?: number
readonly blendMode?: BlendMode
readonly name?: string
}
interface ImageFilters {
exposure?: number
contrast?: number
saturation?: number
temperature?: number
tint?: number
highlights?: number
shadows?: number
hue?: number
}
interface ImagePaint {
readonly type: 'IMAGE'
readonly imageRef: string
readonly scaleMode?: 'FILL' | 'TILE' | 'STRETCH' | 'FIT' | 'CROP'
readonly filters?: ImageFilters
readonly isVisible?: boolean
readonly alpha?: number
readonly blendMode?: BlendMode
readonly name?: string
readonly ratio?: number
readonly rotation?: number
}
type Paint = SolidPaint | GradientPaint | ImagePaint
type CSSWidthSetter =
| number
| [number, number]
| [number, number, number]
| [number, number, number, number]
interface StrokeWidth {
width: CSSWidthSetter
}
interface Padding {
padding: CSSWidthSetter
}
interface Spacing {
spacing: CSSWidthSetter
}
interface CornerRadius {
cornerRadius: CSSWidthSetter
}
type WindingRule = 'Nonzero' | 'Evenodd'
// 待确定
interface VectorVertex {
readonly x: number
readonly y: number
readonly strokeCap?: StrokeCap
readonly cornerRadius?: number
}
// 待确定
interface VectorRegion {
readonly windingRule: WindingRule
readonly loops: ReadonlyArray<VectorPaths>
}
interface VectorCtrl {
x: number
y: number
}
type LetterSpacing = {
readonly value: number
readonly unit: 'PIXELS' | 'PERCENT'
}
type LineHeight =
| {
readonly value: number
readonly unit: 'PIXELS' | 'PERCENT'
}
| {
readonly unit: 'AUTO'
}
type BlendMode =
| 'NORMAL'
| 'DARKEN'
| 'MULTIPLY'
| 'COLOR_BURN'
| 'LIGHTEN'
| 'SCREEN'
| 'COLOR_DODGE'
| 'OVERLAY'
| 'SOFT_LIGHT'
| 'HARD_LIGHT'
| 'DIFFERENCE'
| 'EXCLUSION'
| 'HUE'
| 'SATURATION'
| 'COLOR'
| 'LUMINOSITY'
| 'PLUS_DARKER'
| 'PLUS_LIGHTER'
| 'PASS_THROUGH'
type FontReferrer = 'team' | 'org' | 'local' | 'official'
interface Font {
fontName: FontName
localizedFontName: FontName
referrer: FontReferrer
}
/// /////////////////////////////////////////////////////////////////////////////
// Mixins
interface BaseNodeMixin {
readonly id: string
readonly parent: (BaseNode & ChildrenMixin) | null
name: string
removed: boolean
remove(): void
getPluginData(key: string): string
setPluginData(key: string, value: string): void
getPluginDataKeys(): string[]
removePluginData(key: string): void
clearPluginData(): void
getSharedPluginData(namespace: string, key: string): string
setSharedPluginData(namespace: string, key: string, value: string): void
getSharedPluginDataKeys(namespace: string): string[]
removeSharedPluginData(namespace: string, key: string): void
clearSharedPluginData(namespace: string): void
}
interface SceneNodeMixin {
isVisible: boolean
isLocked: boolean
readonly attachedConnectors: ConnectorNode[]
componentPropertyReferences: {
isVisible?: string
characters?: string
mainComponent?: string
} | null
slotInfo: { slotName: string; slotAlias: string } | null
}
interface ChildrenMixin<ChildrenNode = SceneNode> {
readonly children: ReadonlyArray<ChildrenNode>
appendChild(child: SceneNode): void
insertChild(index: number, child: SceneNode): void
findChildren(
callback?: (node: SceneNode) => boolean
): ReadonlyArray<SceneNode>
findChild(callback: (node: SceneNode) => boolean): SceneNode | null
findAll(callback?: (node: SceneNode) => boolean): ReadonlyArray<SceneNode>
findOne(callback: (node: SceneNode) => boolean): SceneNode | null
findAllWithCriteria<T extends NodeType[]>(criteria: {
types: T
}): Array<{ type: T[number] } & SceneNode>
}
interface ConstraintMixin {
constraints: Constraints
}
interface Bound {
x: number
y: number
width: number
height: number
}
type ScaleCenter =
| 'TOPLEFT'
| 'TOP'
| 'TOPRIGHT'
| 'LEFT'
| 'CENTER'
| 'RIGHT'
| 'BOTTOMLEFT'
| 'BOTTOM'
| 'BOTTOMRIGHT'
interface ScaleOption {
scaleCenter?: ScaleCenter
}
interface LayoutMixin {
absoluteTransform: Transform
relativeTransform: Transform
readonly absoluteRenderBounds: Bound | null
readonly absoluteBoundingBox: Bound
bound: Bound
x: number
y: number
width: number
height: number
minWidth: number | null
maxWidth: number | null
minHeight: number | null
maxHeight: number | null
rotation: number // In degrees
constrainProportions: boolean
layoutPositioning: 'AUTO' | 'ABSOLUTE' // applicable only inside auto-layout frames
alignSelf: 'STRETCH' | 'INHERIT' // applicable only inside auto-layout frames
flexGrow: 0 | 1 // applicable only inside auto-layout frames
rescale(scale: number, scaleOption?: ScaleOption): void
scaleFactor: number // The default value is 1
flip(direction: 'VERTICAL' | 'HORIZONTAL'): void
}
interface BlendMixin {
opacity: number
blendMode: BlendMode
isMask: boolean
isMaskOutline: boolean
isMaskVisible: boolean
effects: ReadonlyArray<Effect>
effectStyleId: string
}
type StrokeCap =
| 'NONE'
| 'ROUND'
| 'SQUARE'
| 'LINE_ARROW'
| 'TRIANGLE_ARROW'
| 'ROUND_ARROW'
| 'RING'
| 'DIAMOND'
| 'LINE'
type StrokeJoin = 'MITER' | 'BEVEL' | 'ROUND'
type StrokeAlign = 'CENTER' | 'INSIDE' | 'OUTSIDE'
type DashCap = 'NONE' | 'ROUND' | 'SQUARE'
type StrokeStyle = 'SOLID' | 'DASH' | 'CUSTOM'
type ConnectorStrokeCap = StrokeCap
interface ConnectorEndpointPosition {
readonly position: { x: number; y: number }
}
interface ConnectorEndpointConnected {
readonly position: { x: number; y: number }
readonly endpointNodeId: string
readonly magnet: 'TOP' | 'LEFT' | 'BOTTOM' | 'RIGHT'
}
type ConnectorEndpoint =
| ConnectorEndpointPosition
| ConnectorEndpointConnected
interface GeometryMixin {
fills: ReadonlyArray<Paint>
strokes: ReadonlyArray<Paint>
strokeWeight: number
strokeAlign: StrokeAlign
strokeCap: StrokeCap
strokeJoin: StrokeJoin
strokeStyle: StrokeStyle
dashCap: DashCap
strokeDashes: ReadonlyArray<number>
fillStyleId: string
/**
* @deprecated please use strokePaintStyleId instead
*/
strokeStyleId: string
strokeFillStyleId: string
strokeWidthStyleId: string
paddingStyleId: string
spacingStyleId: string
cornerRadiusStyleId: string
/**
* You have to ensure the layer has stroke before invoking this method.
* 在调用接口之前需要确保layer有描边.
*/
outlineStroke(): SceneNode | null
}
interface RectangleStrokeWeightMixin {
strokeTopWeight: number
strokeLeftWeight: number
strokeBottomWeight: number
strokeRightWeight: number
}
interface CornerMixin {
cornerSmooth: number
cornerRadius: number | PluginAPI['mixed']
topLeftRadius: number
topRightRadius: number