@mastergo/plugin-typings 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2107 @@
1
+ declare global {
2
+ const mastergo: PluginAPI
3
+ const mg: PluginAPI
4
+ const console: Console
5
+ const __html__: string
6
+
7
+ function setTimeout(callback: Function, timeout: number): number
8
+ function clearTimeout(timeoutID: number): void
9
+ function setInterval(callback: Function, timeout: number): number
10
+ function clearInterval(timeoutID: number): void
11
+ function requestAnimationFrame(cb: (ts: number) => void): number
12
+ function cancelAnimationFrame(requestID: number): void
13
+
14
+ interface Console {
15
+ log(message?: any, ...optionalParams: any[]): void
16
+ error(message?: any, ...optionalParams: any[]): void
17
+ assert(condition?: boolean, message?: string, ...data: any[]): void
18
+ info(message?: any, ...optionalParams: any[]): void
19
+ warn(message?: any, ...optionalParams: any[]): void
20
+ clear(): void
21
+ }
22
+
23
+ interface Image {
24
+ readonly href: string
25
+ getBytesAsync(): Promise<Uint8Array>
26
+ }
27
+
28
+ enum LinkFlagEnum {
29
+ CURRPAGE = 'currPage',
30
+ OTHERPAGE = 'otherPage',
31
+ PROTOTYPE = 'prototype',
32
+ OUTFILE = 'outFile',
33
+ OWNWEBSITE = 'ownWebsite',
34
+ OTHERLINK = 'otherLink',
35
+ }
36
+
37
+ interface Superlink {
38
+ start: number
39
+ end: number
40
+ superlink: {
41
+ layerId?: string
42
+ link: string
43
+ linkFlag: LinkFlagEnum
44
+ pageId: string
45
+ }
46
+ }
47
+
48
+ interface Hyperlink {
49
+ type: 'PAGE' | 'NODE' | 'URL',
50
+ value: string
51
+ }
52
+ interface HyperlinkWithRange {
53
+ start: number
54
+ end: number
55
+ hyperlink: Hyperlink
56
+ }
57
+
58
+ type PluginEventType = 'selectionchange' | 'currentpagechange' | 'close' | 'themechange'
59
+ type ThemeColor = 'dark' | 'light'
60
+
61
+ interface PluginAPI {
62
+ readonly document: DocumentNode
63
+
64
+ readonly ui: UIAPI
65
+
66
+ readonly themeColor: ThemeColor
67
+
68
+ readonly apiVersion: string
69
+
70
+ readonly documentId: number
71
+
72
+ readonly clientStorage: ClientStorageAPI
73
+
74
+ readonly viewport: ViewportAPI
75
+
76
+ closePlugin(): void
77
+
78
+ on(type: PluginEventType, callback: CallableFunction): void
79
+ once(type: PluginEventType, callback: CallableFunction): void
80
+ off(type?: PluginEventType, callback?: CallableFunction): void
81
+
82
+ commitUndo(): void
83
+ triggerUndo(): void
84
+
85
+ showUI(html: string, options?: ShowUIOptions): void
86
+
87
+ getNodeById(id: string): SceneNode | null
88
+ createRectangle(): RectangleNode
89
+ createLine(): LineNode
90
+ createEllipse(): EllipseNode
91
+ createPolygon(): PolygonNode
92
+ createStar(): StarNode
93
+ createPen(): PenNode
94
+ createText(): TextNode
95
+ createFrame(): FrameNode
96
+ createComponent(): ComponentNode
97
+ createPage(): PageNode
98
+ createSlice(): SliceNode
99
+ createConnector(): ConnectorNode
100
+ createNodeFromSvgAsync(svg: string): Promise<FrameNode>
101
+
102
+ getHoverLayer(): PageNode | SceneNode
103
+
104
+ showGrid(show: boolean): void
105
+
106
+ group(children: ReadonlyArray<SceneNode>): GroupNode
107
+ union(children: ReadonlyArray<SceneNode>): BooleanOperationNode
108
+ subtract(children: ReadonlyArray<SceneNode>): BooleanOperationNode
109
+ intersect(children: ReadonlyArray<SceneNode>): BooleanOperationNode
110
+ exclude(children: ReadonlyArray<SceneNode>): BooleanOperationNode
111
+
112
+ saveVersionHistoryAsync(desc: string): Promise<void>
113
+
114
+ notify(message: string, options?: NotifyOptions): void
115
+
116
+ getStyleById(id: string): Style | null
117
+ getTitleByFontFamilyAndStyle(fontFamily: string, fontStyle: string) : FontAlias | null
118
+ createFillStyle(config: CreateStyleConfig): PaintStyle
119
+ createStrokeStyle(config: CreateStyleConfig): PaintStyle
120
+ createEffectStyle(config: CreateStyleConfig): EffectStyle
121
+ createTextStyle(config: CreateStyleConfig): TextStyle
122
+ createGridStyle(config: CreateStyleConfig): GridStyle
123
+
124
+ getLocalPaintStyles(): PaintStyle[]
125
+ getLocalEffectStyles(): EffectStyle[]
126
+ getLocalTextStyles(): TextStyle[]
127
+ getLocalGridStyles(): GridStyle[]
128
+
129
+ listAvailableFontsAsync(): Promise<Font[]>
130
+ loadFontAsync(fontName: FontName): Promise<boolean>
131
+ createImage(imageData: Uint8Array): Promise<Image>
132
+ getImageByHref(href: string): Image
133
+
134
+ hexToRGBA(hex: string): RGBA
135
+ RGBAToHex(rgba: RGBA): string
136
+ }
137
+
138
+ interface Rect {
139
+ readonly x: number
140
+ readonly y: number
141
+ readonly width: number
142
+ readonly height: number
143
+ }
144
+
145
+ interface ViewportAPI {
146
+ center: Vector
147
+ zoom: number
148
+ readonly bound: Rect
149
+ scrollAndZoomIntoView(nodes: ReadonlyArray<BaseNode>): void
150
+ }
151
+
152
+ interface ClientStorageAPI {
153
+ getAsync(key: string): Promise<any | undefined>
154
+ setAsync(key: string, value: any): Promise<void>
155
+ }
156
+
157
+ type ShowUIOptions = {
158
+ width?: number
159
+ height?: number
160
+ visible?: boolean
161
+ }
162
+
163
+ interface ExportSettingsConstraints {
164
+ type: 'SCALE' | 'WIDTH' | 'HEIGHT'
165
+ value: number
166
+ }
167
+ type ExportFileFormat = 'PNG' | 'JPG' | 'SVG' | 'PDF' | 'WEBP'
168
+ type ExportSettings = {
169
+ format: ExportFileFormat
170
+ constraint?: ExportSettingsConstraints
171
+ isSuffix?: boolean
172
+ fileName?: string
173
+ readonly useAbsoluteBounds?: boolean
174
+ }
175
+
176
+ interface ExportMixin {
177
+ exportSettings: ReadonlyArray<ExportSettings>
178
+ export(settings?: ExportSettings): Promise<Uint8Array | string> // Defaults to PNG format
179
+ }
180
+
181
+ interface NotifyOptions {
182
+ position?: 'top' | 'bottom'
183
+ type?: 'normal' | 'highlight' | 'error' | 'warning' | 'success'
184
+ }
185
+
186
+ interface UIAPI {
187
+ show(): void
188
+ hide(): void
189
+ close(): void
190
+ resize(width: number, height: number): void
191
+
192
+ postMessage(pluginMessage: any, origin?: string): void
193
+ onmessage: ((pluginMessage: any, origin: string) => void) | undefined
194
+ }
195
+
196
+ /// /////////////////////////////////////////////////////////////////////////////
197
+ // Styles
198
+ interface PublishableMixin {
199
+ description: string
200
+ /**
201
+ * 是否为团队库样式
202
+ */
203
+ readonly isExternal: boolean
204
+ readonly ukey: string
205
+ }
206
+
207
+ type StyleType = 'PAINT' | 'TEXT' | 'EFFECT' | 'GRID'
208
+
209
+ interface BaseStyle extends PublishableMixin {
210
+ readonly id: string
211
+ readonly type: StyleType
212
+ name: string
213
+ remove(): void
214
+ }
215
+
216
+ interface PaintStyle extends BaseStyle {
217
+ type: 'PAINT'
218
+ paints: ReadonlyArray<Paint>
219
+ }
220
+
221
+ interface NumValue {
222
+ value: number
223
+ unit: 'PIXELS' | 'PERCENT'
224
+ }
225
+
226
+ interface TextSegStyle {
227
+ start: number
228
+ end: number
229
+ textStyleId: string
230
+ textStyle: {
231
+ fontName: FontName
232
+ fontSize: number
233
+ letterSpacing: LetterSpacing
234
+ lineHeight: LineHeight
235
+ textDecoration: TextDecoration
236
+ textCase: TextCase
237
+ }
238
+ fills: Paint[]
239
+ }
240
+
241
+ interface EffectStyle extends BaseStyle {
242
+ type: 'EFFECT'
243
+ effects: ReadonlyArray<Effect>
244
+ }
245
+
246
+ interface TextStyle extends BaseStyle {
247
+ type: 'TEXT'
248
+ decoration: TextDecoration
249
+ description: string
250
+ fontSize: number
251
+ isExternal: boolean
252
+ letterSpacing: number
253
+ letterSpacingUnit: NumValue['unit']
254
+ textCase: TextCase
255
+ }
256
+
257
+ interface FontAlias {
258
+ title: string
259
+ subtitle: string
260
+ }
261
+
262
+ interface GridStyle extends BaseStyle {
263
+ type: 'GRID'
264
+ layoutGrids: ReadonlyArray<LayoutGrid>
265
+ }
266
+
267
+ type Style = PaintStyle | EffectStyle | TextStyle | GridStyle
268
+
269
+ /// /////////////////////////////////////////////////////////////////////////////
270
+ // Datatypes
271
+
272
+ type Transform = [[number, number, number], [number, number, number]]
273
+
274
+ interface Vector {
275
+ readonly x: number
276
+ readonly y: number
277
+ }
278
+
279
+ interface RGB {
280
+ readonly r: number
281
+ readonly g: number
282
+ readonly b: number
283
+ }
284
+
285
+ interface RGBA {
286
+ readonly r: number
287
+ readonly g: number
288
+ readonly b: number
289
+ readonly a: number
290
+ }
291
+
292
+ interface FontName {
293
+ readonly family: string
294
+ readonly style: string
295
+ }
296
+
297
+ type TextCase = 'ORIGINAL' | 'UPPER' | 'LOWER' | 'TITLE';
298
+
299
+ type TextDecoration = 'NONE' | 'UNDERLINE' | 'STRIKETHROUGH'
300
+
301
+ interface ShadowEffect {
302
+ readonly type: 'DROP_SHADOW' | 'INNER_SHADOW'
303
+ readonly color: RGBA
304
+ // Effect的 x, y;
305
+ readonly offset: Vector
306
+ // spread和radius待确定
307
+ readonly spread: number
308
+ readonly radius: number
309
+ readonly isVisible: boolean
310
+ readonly blendMode: BlendMode
311
+ }
312
+
313
+ interface BlurEffect {
314
+ readonly type: 'LAYER_BLUR' | 'BACKGROUND_BLUR'
315
+ readonly radius: number
316
+ readonly isVisible: boolean
317
+ readonly blendMode: BlendMode
318
+ }
319
+
320
+ type Effect = ShadowEffect | BlurEffect
321
+
322
+ // 待确认
323
+ type ConstraintType = 'START' | 'END' | 'STARTANDEND' | 'CENTER' | 'SCALE'
324
+
325
+ interface Constraints {
326
+ readonly horizontal: ConstraintType
327
+ readonly vertical: ConstraintType
328
+ }
329
+
330
+ interface ColorStop {
331
+ readonly position: number
332
+ readonly color: RGBA
333
+ }
334
+
335
+ interface SolidPaint {
336
+ readonly type: 'SOLID'
337
+ readonly color: RGBA
338
+
339
+ readonly isVisible?: boolean
340
+ /**
341
+ * It always be 1 when type is 'SOLID', please modify the alpha field in color instead.
342
+ * 纯色模式下alpha始终为1, 请设置color中的alpha.
343
+ */
344
+ readonly alpha?: number
345
+ readonly blendMode?: BlendMode
346
+ }
347
+
348
+ interface GradientPaint {
349
+ readonly type:
350
+ | 'GRADIENT_LINEAR'
351
+ | 'GRADIENT_RADIAL'
352
+ | 'GRADIENT_ANGULAR'
353
+ | 'GRADIENT_DIAMOND'
354
+ readonly transform: Transform
355
+ readonly gradientStops: ReadonlyArray<ColorStop>
356
+ readonly gradientHandlePositions?: [{ x: number, y: number}, { x: number, y: number}];
357
+ readonly isVisible?: boolean
358
+ readonly alpha?: number
359
+ readonly blendMode?: BlendMode
360
+ }
361
+
362
+ interface ImagePaint {
363
+ readonly type: 'IMAGE'
364
+ readonly imageRef: string
365
+ readonly scaleMode?: 'FILL' | 'TILE' | 'STRETCH' | 'FIT' | 'CROP'
366
+
367
+ readonly isVisible?: boolean
368
+ readonly alpha?: number
369
+ readonly blendMode?: BlendMode
370
+ }
371
+
372
+ type Paint = SolidPaint | GradientPaint | ImagePaint
373
+
374
+ type WindingRule = 'Nonzero' | 'Evenodd'
375
+
376
+ // 待确定
377
+ interface VectorVertex {
378
+ readonly id: number
379
+ readonly x: number
380
+ readonly y: number
381
+ readonly type: 'PATH_NODE' | 'CONTROL_NODE' // 0 路径端点 1 控制节点
382
+ readonly strokeCap?: StrokeCap
383
+ readonly strokeJoin?: StrokeJoin
384
+ readonly cornerRadius?: number
385
+ }
386
+
387
+ // 待确定
388
+ interface VectorRegion {
389
+ readonly id: number
390
+ readonly windingRule: WindingRule
391
+ readonly pathIds?: ReadonlyArray<number>
392
+ }
393
+
394
+ interface VectorCtrl {
395
+ x: number
396
+ y: number
397
+ }
398
+
399
+ type LetterSpacing = {
400
+ readonly value: number
401
+ readonly unit: 'PIXELS' | 'PERCENT'
402
+ }
403
+
404
+ type LineHeight = {
405
+ readonly value: number
406
+ readonly unit: 'PIXELS'
407
+ }
408
+
409
+ type BlendMode =
410
+ | 'NORMAL'
411
+ | 'DARKEN'
412
+ | 'MULTIPLY'
413
+ | 'COLOR_BURN'
414
+ | 'LIGHTEN'
415
+ | 'SCREEN'
416
+ | 'COLOR_DODGE'
417
+ | 'OVERLAY'
418
+ | 'SOFT_LIGHT'
419
+ | 'HARD_LIGHT'
420
+ | 'DIFFERENCE'
421
+ | 'EXCLUSION'
422
+ | 'HUE'
423
+ | 'SATURATION'
424
+ | 'COLOR'
425
+ | 'LUMINOSITY'
426
+ | 'PLUS_DARKER'
427
+ | 'PLUS_LIGHTER'
428
+ | 'PASS_THROUGH'
429
+
430
+ interface Font {
431
+ fontName: FontName
432
+ }
433
+
434
+ /// /////////////////////////////////////////////////////////////////////////////
435
+ // Mixins
436
+
437
+ interface BaseNodeMixin {
438
+ readonly id: string
439
+ readonly parent: (BaseNode & ChildrenMixin) | void
440
+ name: string // Note: setting this also sets \`autoRename\` to false on TextNodes
441
+ removed: boolean
442
+ remove(): void
443
+ getPluginData(key: string): string
444
+ setPluginData(key: string, value: string): void
445
+ getPluginDataKeys(): string[]
446
+ removePluginData(key: string): void
447
+ clearPluginData(): void
448
+ getSharedPluginData(namespace: string, key: string): string
449
+ setSharedPluginData(namespace: string, key: string, value: string): void
450
+ getSharedPluginDataKeys(namespace: string): void
451
+ removeSharedPluginData(namespace: string, key: string): void
452
+ clearSharedPluginData(namespace: string): void
453
+ }
454
+
455
+ interface SceneNodeMixin {
456
+ isVisible: boolean
457
+ isLocked: boolean
458
+ }
459
+
460
+ interface ChildrenMixin<ChildrenNode = SceneNode> {
461
+ readonly children: ReadonlyArray<ChildrenNode>
462
+ appendChild(child: SceneNode): void
463
+ insertChild(index: number, child: SceneNode): void
464
+
465
+ findChildren(
466
+ callback?: (node: SceneNode) => boolean
467
+ ): ReadonlyArray<SceneNode>
468
+ findChild(callback: (node: SceneNode) => boolean): SceneNode | null
469
+
470
+ findAll(callback?: (node: SceneNode) => boolean): ReadonlyArray<SceneNode>
471
+ findOne(callback: (node: SceneNode) => boolean): SceneNode | null
472
+ }
473
+
474
+ interface ConstraintMixin {
475
+ constraints: Constraints
476
+ }
477
+
478
+ interface Bound {
479
+ x: number
480
+ y: number
481
+ width: number
482
+ height: number
483
+ }
484
+
485
+ interface LayoutMixin {
486
+ absoluteTransform: Transform
487
+ relativeTransform: Transform
488
+ bound: Bound
489
+ x: number
490
+ y: number
491
+ width: number
492
+ height: number
493
+ rotation: number // In degrees
494
+ constrainProportions: boolean
495
+ layoutPositioning: 'AUTO' | 'ABSOLUTE' // applicable only inside auto-layout frames
496
+ alignSelf: 'STRETCH' | 'INHERIT' // applicable only inside auto-layout frames
497
+ flexGrow: 0 | 1 // applicable only inside auto-layout frames
498
+ }
499
+
500
+ interface BlendMixin {
501
+ opacity: number
502
+ blendMode: BlendMode
503
+ isMask: boolean
504
+ effects: ReadonlyArray<Effect>
505
+ effectStyleId: string
506
+ }
507
+
508
+ type StrokeCap = 'NONE' | 'ROUND' | 'SQUARE' | 'LINE_ARROW' | 'TRIANGLE_ARROW' | 'ROUND_ARROW' | 'RING' | 'DIAMOND' | 'LINE'
509
+ type StrokeJoin = 'MITER' | 'BEVEL' | 'ROUND'
510
+ type StrokeAlign = 'CENTER' | 'INSIDE' | 'OUTSIDE'
511
+ type DashCap = 'NONE' | 'ROUND' | 'SQUARE'
512
+ type StrokeStyle = 'SOLID' | 'DASH' | 'CUSTOM'
513
+ type ConnectorStrokeCap = StrokeCap
514
+
515
+ interface ConnectorEndpointPosition {
516
+ readonly position: { x: number; y: number }
517
+ }
518
+
519
+ interface ConnectorEndpointConnected {
520
+ readonly position: { x: number; y: number }
521
+ readonly endpointNodeId: string
522
+ readonly magnet: 'TOP' | 'LEFT' | 'BOTTOM' | 'RIGHT'
523
+ }
524
+
525
+
526
+ type ConnectorEndpoint =
527
+ | ConnectorEndpointPosition
528
+ | ConnectorEndpointConnected
529
+
530
+ interface GeometryMixin {
531
+ fills: ReadonlyArray<Paint>
532
+ strokes: ReadonlyArray<Paint>
533
+ strokeWeight: number
534
+ strokeAlign: StrokeAlign
535
+ strokeCap: StrokeCap
536
+ strokeJoin: StrokeJoin
537
+ strokeStyle: StrokeStyle
538
+ dashCap: DashCap
539
+ strokeDashes: ReadonlyArray<number>
540
+ fillStyleId: string
541
+ strokeStyleId: string
542
+ /**
543
+ * You have to ensure the layer has stroke before invoking this method.
544
+ * 在调用接口之前需要确保layer有描边.
545
+ */
546
+ outlineStroke(): SceneNode | null
547
+ }
548
+
549
+ interface RectangleStrokeWeightMixin {
550
+ strokeTopWeight: number
551
+ strokeLeftWeight: number
552
+ strokeBottomWeight: number
553
+ strokeRightWeight: number
554
+ }
555
+
556
+ interface CornerMixin {
557
+ // 待确认
558
+ cornerSmooth: number
559
+ cornerRadius: number | symbol
560
+ }
561
+
562
+ interface DefaultShapeMixin
563
+ extends BaseNodeMixin,
564
+ SceneNodeMixin,
565
+ BlendMixin,
566
+ GeometryMixin,
567
+ LayoutMixin,
568
+ ReactionMixin,
569
+ ExportMixin { }
570
+
571
+ interface DefaultContainerMixin
572
+ extends BaseNodeMixin,
573
+ ReactionMixin,
574
+ SceneNodeMixin,
575
+ ChildrenMixin,
576
+ RectangleCornerMixin,
577
+ BlendMixin,
578
+ CornerMixin,
579
+ ConstraintMixin,
580
+ LayoutMixin,
581
+ ExportMixin { }
582
+
583
+ interface AutoLayout {
584
+ flexMode: 'NONE' | 'HORIZONTAL' | 'VERTICAL'
585
+ itemSpacing: number
586
+ mainAxisAlignItems: 'FLEX_START' | 'FLEX_END' | 'CENTER' | 'SPACING_BETWEEN'
587
+ crossAxisAlignItems: 'FLEX_START' | 'FLEX_END' | 'CENTER'
588
+ mainAxisSizingMode: 'FIXED' | 'AUTO'
589
+ crossAxisSizingMode: 'FIXED' | 'AUTO'
590
+ strokesIncludedInLayout: boolean
591
+ itemReverseZIndex: boolean
592
+ paddingTop: number
593
+ paddingRight: number
594
+ paddingBottom: number
595
+ paddingLeft: number
596
+ }
597
+
598
+ export interface RowsColsLayoutGrid {
599
+ readonly gridType: "ROWS" | "COLUMNS"
600
+
601
+ readonly alignment: "LEFT" | "RIGHT" | "STRETCH" | "CENTER"
602
+ readonly gutterSize: number
603
+ readonly count: number
604
+ readonly sectionSize?: number | null
605
+ readonly offset?: number
606
+
607
+ readonly isVisible?: boolean
608
+ readonly color?: RGBA
609
+ readonly id?: string
610
+ readonly name?: string
611
+ }
612
+
613
+ export interface GridLayoutGrid {
614
+ readonly gridType: "GRID"
615
+
616
+ readonly sectionSize: number
617
+
618
+ readonly isVisible?: boolean
619
+ readonly color?: RGBA
620
+ readonly id?: string
621
+ readonly name?: string
622
+ }
623
+
624
+
625
+ export type LayoutGrid = RowsColsLayoutGrid | GridLayoutGrid
626
+
627
+ interface FrameContainerMixin extends AutoLayout {
628
+ clipsContent: boolean
629
+ layoutGrids: ReadonlyArray<LayoutGrid>
630
+ gridStyleId: string
631
+ overflowDirection: OverflowDirection
632
+ }
633
+
634
+ type OverflowDirection = "NONE" | "HORIZONTAL" | "VERTICAL" | "BOTH"
635
+
636
+ interface RectangleCornerMixin {
637
+ topLeftRadius: number
638
+ topRightRadius: number
639
+ bottomLeftRadius: number
640
+ bottomRightRadius: number
641
+ }
642
+
643
+ interface ReactionMixin {
644
+ reactions: ReadonlyArray<Reaction>
645
+ }
646
+
647
+ interface OpaqueNodeMixin extends BaseNodeMixin, SceneNodeMixin, ExportMixin {
648
+ readonly absoluteTransform: Transform
649
+ relativeTransform: Transform
650
+ x: number
651
+ y: number
652
+ readonly width: number
653
+ readonly height: number
654
+ readonly bound: Bound
655
+ }
656
+
657
+ interface MinimalBlendMixin {
658
+ opacity: number
659
+ blendMode: BlendMode
660
+ }
661
+
662
+ interface MinimalStrokesMixin {
663
+ strokes: ReadonlyArray<Paint>
664
+ strokeStyleId: string
665
+ strokeWeight: number
666
+ strokeJoin: StrokeJoin
667
+ strokeAlign: StrokeAlign
668
+ strokeStyle: StrokeStyle
669
+ strokeCap: StrokeCap
670
+ strokeDashes: ReadonlyArray<number>
671
+ dashCap: DashCap
672
+ }
673
+
674
+ interface MinimalFillsMixin {
675
+ fills: ReadonlyArray<Paint>
676
+ fillStyleId: string
677
+ }
678
+
679
+ /// /////////////////////////////////////////////////////////////////////////////
680
+ // Nodes
681
+
682
+ interface DocumentNode extends ChildrenMixin<PageNode> {
683
+ readonly type: 'DOCUMENT'
684
+ currentPage: PageNode
685
+ name: string
686
+ }
687
+
688
+ interface PageNode
689
+ extends BaseNodeMixin,
690
+ ChildrenMixin<SceneNode> {
691
+ readonly type: 'PAGE'
692
+
693
+ selection: ReadonlyArray<SceneNode>
694
+ clone(): PageNode
695
+ /**
696
+ * 选中所有图层
697
+ */
698
+ selectAll() : void
699
+ /**
700
+ * 背景颜色
701
+ */
702
+ bgColor: RGBA
703
+ /**
704
+ * 原型所有的flow
705
+ */
706
+ readonly flowStartingPoints: FlowStartingPoint[]
707
+ /**
708
+ * 标签,默认'NONE'
709
+ */
710
+ label:'NONE' | 'BLUE' | 'GREEN' | 'RED' | 'YELLOW' | 'PURPLE' | 'GRAY'
711
+ }
712
+
713
+ interface FrameNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
714
+ readonly type: 'FRAME'
715
+ clone(): FrameNode
716
+ }
717
+
718
+ interface GroupNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin {
719
+ readonly type: 'GROUP'
720
+ clone(): GroupNode
721
+ }
722
+
723
+ interface RectangleNode
724
+ extends DefaultShapeMixin,
725
+ ConstraintMixin,
726
+ CornerMixin,
727
+ RectangleStrokeWeightMixin,
728
+ RectangleCornerMixin {
729
+ readonly type: 'RECTANGLE'
730
+ clone(): RectangleNode
731
+ }
732
+
733
+ interface LineNode extends DefaultShapeMixin, ConstraintMixin {
734
+ readonly type: 'LINE'
735
+ clone(): LineNode
736
+ readonly height: number
737
+ leftStrokeCap: StrokeCap
738
+ rightStrokeCap: StrokeCap
739
+ }
740
+
741
+ interface EllipseNode extends DefaultShapeMixin, ConstraintMixin {
742
+ readonly type: 'ELLIPSE'
743
+ clone(): EllipseNode
744
+ arcData: ArcData
745
+ }
746
+
747
+ interface PolygonNode extends DefaultShapeMixin, ConstraintMixin, CornerMixin {
748
+ readonly type: 'POLYGON'
749
+ pointCount: number
750
+ clone(): PolygonNode
751
+ }
752
+
753
+ interface StarNode extends DefaultShapeMixin, ConstraintMixin, CornerMixin {
754
+ readonly type: 'STAR'
755
+ pointCount: number
756
+ innerRadius: number
757
+ clone(): StarNode
758
+ }
759
+
760
+ // interface VectorPath {
761
+ // readonly id: number
762
+ // readonly nodeIds: ReadonlyArray<number>
763
+ // }
764
+ type VectorPath = number[]
765
+
766
+ type VectorPaths = ReadonlyArray<VectorPath>
767
+
768
+ interface PenNetwork {
769
+ paths: ReadonlyArray<VectorPaths>
770
+ nodes: ReadonlyArray<VectorVertex>
771
+ regions: ReadonlyArray<VectorRegion> | []
772
+ ctrlNodes: ReadonlyArray<VectorCtrl>
773
+ }
774
+
775
+ interface PenPaths {
776
+ windingRule: WindingRule
777
+ data: string
778
+ }
779
+
780
+ interface PenNode extends DefaultShapeMixin, ConstraintMixin, CornerMixin {
781
+ readonly type: 'PEN'
782
+ penNetwork: PenNetwork
783
+ set penPaths(paths: Array<PenPaths>)
784
+ //@ts-ignore
785
+ get penPaths(): PenPaths
786
+ clone(): PenNode
787
+ }
788
+
789
+ interface BooleanOperationNode
790
+ extends DefaultShapeMixin,
791
+ FrameContainerMixin,
792
+ ChildrenMixin,
793
+ CornerMixin {
794
+ readonly type: 'BOOLEAN_OPERATION'
795
+ booleanOperation: 'UNION' | 'INTERSECT' | 'SUBTRACT' | 'EXCLUDE'
796
+ clone(): BooleanOperationNode
797
+ }
798
+
799
+ interface TextRangeStyle {
800
+ fontName: FontName
801
+ fontSize: number
802
+ lineHeight: LineHeight
803
+ textDecoration: TextDecoration
804
+ letterSpacing: LetterSpacing
805
+ }
806
+
807
+ interface TextNode extends DefaultShapeMixin, ConstraintMixin {
808
+ readonly type: 'TEXT'
809
+ characters: string
810
+ readonly hasMissingFont: boolean
811
+ /**
812
+ * @deprecated
813
+ * This attribute is deprecared, please use hyperlinks instead.
814
+ */
815
+ readonly superlinks: Array<Superlink>
816
+ readonly hyperlinks: Array<HyperlinkWithRange>
817
+ textAlignHorizontal: 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFIED'
818
+ textAlignVertical: 'TOP' | 'CENTER' | 'BOTTOM'
819
+ textAutoResize: 'NONE' | 'WIDTH_AND_HEIGHT' | 'HEIGHT'
820
+ paragraphSpacing: number
821
+ readonly textStyles: ReadonlyArray<TextSegStyle>
822
+ clone(): TextNode
823
+
824
+ insertCharacters(start: number, characters: string): void
825
+ deleteCharacters(start: number, end: number): void
826
+
827
+ setRangeFontSize(start: number, end: number, fontSize: number): void
828
+ setRangeTextDecoration(
829
+ start: number,
830
+ end: number,
831
+ decoration: TextDecoration
832
+ ): void
833
+ setRangeFontName(start: number, end: number, fontName: FontName): void
834
+ setRangeLetterSpacing(
835
+ start: number,
836
+ end: number,
837
+ value: LetterSpacing
838
+ ): void
839
+ setRangeLineHeight(start: number, end: number, value: LineHeight): void
840
+ setRangeFills(start: number, end: number, paints: Paint[]): void
841
+ /**
842
+ * @deprecated
843
+ * This function is deprecared, please use setRangeHyperLink instead.
844
+ */
845
+ setRangeSuperLink(start: number, end: number, link: string | null): void
846
+ setRangeHyperLink(start: number, end: number, hyperlink: Hyperlink | null): void
847
+ setRangeTextCase(start: number, end: number, textCase: TextCase): void
848
+ }
849
+
850
+ interface ComponentNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
851
+ readonly type: 'COMPONENT'
852
+ readonly variantProperties: Array<Record<string, string>>
853
+ description: string
854
+ setVariantPropertyValues(property: Record<string, string>): void
855
+ clone(): ComponentNode
856
+ createInstance(): InstanceNode
857
+ }
858
+
859
+ interface ComponentSetNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
860
+ readonly type: 'COMPONENT_SET'
861
+ readonly componentPropertyDefinitions: Array<Record<string, Array<string> | string>>
862
+ clone(): ComponentSetNode
863
+ createVariantComponent(): void
864
+ createVariantProperties(properties: Array<string>): void
865
+ editVariantProperties(properties: Record<string, string>): void
866
+ editVariantPropertyValues(properties: Record<string, { oldValue: string, newValue: string }>): void
867
+ deleteVariantProperty(property: string): void
868
+ }
869
+
870
+ interface InstanceNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
871
+ readonly type: 'INSTANCE'
872
+ readonly variantProperties: Array<Record<string, string>>
873
+ setVariantPropertyValues(property: Record<string, string>): void
874
+ clone(): InstanceNode
875
+ /**
876
+ * this is an async func
877
+ */
878
+ swapComponent(): void
879
+ detachInstance(): InstanceNode
880
+ mainComponent: ComponentNode | null
881
+ }
882
+
883
+ interface SliceNode extends BaseNodeMixin, LayoutMixin, ConstraintMixin, SceneNodeMixin, ExportMixin {
884
+ readonly type: 'SLICE'
885
+ clone(): SliceNode
886
+ isPreserveRatio: boolean
887
+ }
888
+
889
+ interface ConnectorNode extends OpaqueNodeMixin, Pick<MinimalBlendMixin, 'opacity'>, Omit<MinimalStrokesMixin, 'strokeAlign'> {
890
+ readonly type: 'CONNECTOR'
891
+ createText(): TextSublayerNode
892
+ readonly text: TextSublayerNode | null
893
+ cornerRadius?: number
894
+ connectorStart: ConnectorEndpoint
895
+ connectorEnd: ConnectorEndpoint
896
+ connectorStartStrokeCap: ConnectorStrokeCap
897
+ connectorEndStrokeCap: ConnectorStrokeCap
898
+ readonly strokeAlign: 'CENTER'
899
+ clone(): ConnectorNode
900
+ }
901
+
902
+ interface TextSublayerNode extends MinimalFillsMixin {
903
+ readonly id: string
904
+ readonly hasMissingFont: boolean
905
+ readonly textAlignHorizontal: 'CENTER'
906
+ readonly textAlignVertical: 'CENTER'
907
+ readonly textAutoResize: 'WIDTH_AND_HEIGHT'
908
+ readonly hyperlinks: Array<HyperlinkWithRange>
909
+
910
+ readonly textStyles: ReadonlyArray<TextSegStyle>
911
+
912
+ paragraphSpacing: number
913
+
914
+ characters: string
915
+ insertCharacters(start: number, characters: string): void
916
+ deleteCharacters(start: number, end: number): void
917
+
918
+ setRangeFontSize(start: number, end: number, fontSize: number): void
919
+ setRangeTextDecoration(
920
+ start: number,
921
+ end: number,
922
+ decoration: TextDecoration
923
+ ): void
924
+ setRangeFontName(start: number, end: number, fontName: FontName): void
925
+ setRangeLetterSpacing(
926
+ start: number,
927
+ end: number,
928
+ value: LetterSpacing
929
+ ): void
930
+ setRangeLineHeight(start: number, end: number, value: LineHeight): void
931
+ setRangeFills(start: number, end: number, paints: Paint[]): void
932
+ setRangeHyperLink(start: number, end: number, hyperlink: Hyperlink | null): void
933
+ setRangeTextCase(start: number, end: number, textCase: TextCase): void
934
+ }
935
+
936
+ type BaseNode = DocumentNode | PageNode | SceneNode
937
+
938
+ /**
939
+ * 画布节点
940
+ */
941
+ type SceneNode =
942
+ | GroupNode
943
+ | FrameNode
944
+ | PenNode
945
+ | StarNode
946
+ | LineNode
947
+ | EllipseNode
948
+ | PolygonNode
949
+ | RectangleNode
950
+ | TextNode
951
+ | ComponentNode
952
+ | ComponentSetNode
953
+ | InstanceNode
954
+ | BooleanOperationNode
955
+ | SliceNode
956
+ | ConnectorNode
957
+
958
+ type NodeType =
959
+ | 'DOCUMENT'
960
+ | 'PAGE'
961
+ | 'GROUP'
962
+ | 'FRAME'
963
+ | 'RECTANGLE'
964
+ | 'TEXT'
965
+ | 'LINE'
966
+ | 'ELLIPSE'
967
+ | 'POLYGON'
968
+ | 'STAR'
969
+ | 'PEN'
970
+ | 'COMPONENT'
971
+ | 'COMPONENT_SET'
972
+ | 'INSTANCE'
973
+ | 'BOOLEAN_OPERATION'
974
+ | 'SLICE'
975
+ | 'CONNECTOR'
976
+ }
977
+
978
+ interface CreateStyleConfig {
979
+ name: string;
980
+ /**
981
+ * layerId
982
+ */
983
+ id: string;
984
+ description?: string;
985
+ }
986
+
987
+ interface FlowStartingPoint {
988
+ name: string
989
+ id: string
990
+ flowId: string
991
+ description: string
992
+ }
993
+ interface Reaction {
994
+ readonly trigger: Trigger;
995
+ readonly action?: Action;
996
+ }
997
+ interface Action {
998
+ readonly type: ActionType;
999
+ readonly destinationId: string;
1000
+ readonly navigation: Navigation;
1001
+ readonly transition: Transition;
1002
+ readonly url: string;
1003
+ readonly scrollToXOffset?: number;
1004
+ readonly scrollToYOffset?: number;
1005
+ }
1006
+
1007
+ type ActionType = 'BACK' | 'NODE'| 'URL'| 'CLOSE'| 'NONE';
1008
+
1009
+ type Navigation = 'NAVIGATE' | 'OVERLAY' | 'SWAP_OVERLAY' | 'SCROLL_TO';
1010
+
1011
+ interface Transition {
1012
+ readonly type: TransitionType;
1013
+ readonly duration: number;
1014
+ readonly direction: TransitionDirection;
1015
+ readonly easing: Easing;
1016
+ }
1017
+
1018
+ type TransitionType = 'TANS_NONE' | 'INSTANT' | 'DISSOLVE' | 'SMART_ANIMATE' | 'MOVE_IN' | 'MOVE_OUT' | 'PUSH' | 'SLIDE_IN' | 'SLIDE_OUT' | 'DISPLACE'
1019
+
1020
+ type TransitionDirection = 'LEFT' | 'RIGHT' | 'TOP' | 'BOTTOM'
1021
+ interface Easing{
1022
+ readonly type: EasingType;
1023
+ readonly easingFunctionCubicBezier: {
1024
+ x1: number;
1025
+ x2: number;
1026
+ y1: number;
1027
+ y2: number;
1028
+ };
1029
+ }
1030
+
1031
+ type EasingType = 'LINEAR' | 'EASE_IN' | 'EASE_OUT' | 'EASE_IN_AND_OUT' | 'EASE_IN_BACK' | 'EASE_OUT_BACK' | 'EASE_IN_AND_OUT_BACK' | 'CUSTOM_CUBIC_BEZIER'
1032
+ interface Trigger{
1033
+ readonly type: TriggerType;
1034
+ readonly delay: number;
1035
+ }
1036
+ type TriggerType = 'ON_CLICK' | 'ON_DRAG' | 'ON_HOVER' | 'ON_PRESS' | 'MOUSE_ENTER' | 'MOUSE_LEAVE' | 'MOUSE_DOWN' | 'MOUSE_UP' | 'AFTER_DELAY'
1037
+
1038
+ interface ArcData {
1039
+ /**
1040
+ * 起点弧度
1041
+ */
1042
+ startingAngle: number
1043
+ /**
1044
+ * 终点弧度
1045
+ */
1046
+ endingAngle?: number
1047
+ /**
1048
+ * 内径
1049
+ */
1050
+ innerRadius: number
1051
+ }
1052
+
1053
+ export { CreateStyleConfig };
1054
+
1055
+ declare global {
1056
+ const mastergo: PluginAPI
1057
+ const mg: PluginAPI
1058
+ const console: Console
1059
+ const __html__: string
1060
+
1061
+ function setTimeout(callback: Function, timeout: number): number
1062
+ function clearTimeout(timeoutID: number): void
1063
+ function setInterval(callback: Function, timeout: number): number
1064
+ function clearInterval(timeoutID: number): void
1065
+ function requestAnimationFrame(cb: (ts: number) => void): number
1066
+ function cancelAnimationFrame(requestID: number): void
1067
+
1068
+ interface Console {
1069
+ log(message?: any, ...optionalParams: any[]): void
1070
+ error(message?: any, ...optionalParams: any[]): void
1071
+ assert(condition?: boolean, message?: string, ...data: any[]): void
1072
+ info(message?: any, ...optionalParams: any[]): void
1073
+ warn(message?: any, ...optionalParams: any[]): void
1074
+ clear(): void
1075
+ }
1076
+
1077
+ interface Image {
1078
+ readonly href: string
1079
+ getBytesAsync(): Promise<Uint8Array>
1080
+ }
1081
+
1082
+ enum LinkFlagEnum {
1083
+ CURRPAGE = 'currPage',
1084
+ OTHERPAGE = 'otherPage',
1085
+ PROTOTYPE = 'prototype',
1086
+ OUTFILE = 'outFile',
1087
+ OWNWEBSITE = 'ownWebsite',
1088
+ OTHERLINK = 'otherLink',
1089
+ }
1090
+
1091
+ interface Superlink {
1092
+ start: number
1093
+ end: number
1094
+ superlink: {
1095
+ layerId?: string
1096
+ link: string
1097
+ linkFlag: LinkFlagEnum
1098
+ pageId: string
1099
+ }
1100
+ }
1101
+
1102
+ interface Hyperlink {
1103
+ type: 'PAGE' | 'NODE' | 'URL',
1104
+ value: string
1105
+ }
1106
+ interface HyperlinkWithRange {
1107
+ start: number
1108
+ end: number
1109
+ hyperlink: Hyperlink
1110
+ }
1111
+
1112
+ type PluginEventType = 'selectionchange' | 'currentpagechange' | 'close' | 'themechange'
1113
+ type ThemeColor = 'dark' | 'light'
1114
+
1115
+ interface PluginAPI {
1116
+ readonly document: DocumentNode
1117
+
1118
+ readonly ui: UIAPI
1119
+
1120
+ readonly themeColor: ThemeColor
1121
+
1122
+ readonly apiVersion: string
1123
+
1124
+ readonly documentId: number
1125
+
1126
+ readonly clientStorage: ClientStorageAPI
1127
+
1128
+ readonly viewport: ViewportAPI
1129
+
1130
+ closePlugin(): void
1131
+
1132
+ on(type: PluginEventType, callback: CallableFunction): void
1133
+ once(type: PluginEventType, callback: CallableFunction): void
1134
+ off(type?: PluginEventType, callback?: CallableFunction): void
1135
+
1136
+ commitUndo(): void
1137
+ triggerUndo(): void
1138
+
1139
+ showUI(html: string, options?: ShowUIOptions): void
1140
+
1141
+ getNodeById(id: string): SceneNode | null
1142
+ createRectangle(): RectangleNode
1143
+ createLine(): LineNode
1144
+ createEllipse(): EllipseNode
1145
+ createPolygon(): PolygonNode
1146
+ createStar(): StarNode
1147
+ createPen(): PenNode
1148
+ createText(): TextNode
1149
+ createFrame(): FrameNode
1150
+ createComponent(): ComponentNode
1151
+ createPage(): PageNode
1152
+ createSlice(): SliceNode
1153
+ createConnector(): ConnectorNode
1154
+ createNodeFromSvgAsync(svg: string): Promise<FrameNode>
1155
+
1156
+ getHoverLayer(): PageNode | SceneNode
1157
+
1158
+ showGrid(show: boolean): void
1159
+
1160
+ group(children: ReadonlyArray<SceneNode>): GroupNode
1161
+ union(children: ReadonlyArray<SceneNode>): BooleanOperationNode
1162
+ subtract(children: ReadonlyArray<SceneNode>): BooleanOperationNode
1163
+ intersect(children: ReadonlyArray<SceneNode>): BooleanOperationNode
1164
+ exclude(children: ReadonlyArray<SceneNode>): BooleanOperationNode
1165
+
1166
+ saveVersionHistoryAsync(desc: string): Promise<void>
1167
+
1168
+ notify(message: string, options?: NotifyOptions): void
1169
+
1170
+ getStyleById(id: string): Style | null
1171
+ getTitleByFontFamilyAndStyle(fontFamily: string, fontStyle: string) : FontAlias | null
1172
+ createFillStyle(config: CreateStyleConfig): PaintStyle
1173
+ createStrokeStyle(config: CreateStyleConfig): PaintStyle
1174
+ createEffectStyle(config: CreateStyleConfig): EffectStyle
1175
+ createTextStyle(config: CreateStyleConfig): TextStyle
1176
+ createGridStyle(config: CreateStyleConfig): GridStyle
1177
+
1178
+ getLocalPaintStyles(): PaintStyle[]
1179
+ getLocalEffectStyles(): EffectStyle[]
1180
+ getLocalTextStyles(): TextStyle[]
1181
+ getLocalGridStyles(): GridStyle[]
1182
+
1183
+ listAvailableFontsAsync(): Promise<Font[]>
1184
+ loadFontAsync(fontName: FontName): Promise<boolean>
1185
+ createImage(imageData: Uint8Array): Promise<Image>
1186
+ getImageByHref(href: string): Image
1187
+
1188
+ hexToRGBA(hex: string): RGBA
1189
+ RGBAToHex(rgba: RGBA): string
1190
+ }
1191
+
1192
+ interface Rect {
1193
+ readonly x: number
1194
+ readonly y: number
1195
+ readonly width: number
1196
+ readonly height: number
1197
+ }
1198
+
1199
+ interface ViewportAPI {
1200
+ center: Vector
1201
+ zoom: number
1202
+ readonly bound: Rect
1203
+ scrollAndZoomIntoView(nodes: ReadonlyArray<BaseNode>): void
1204
+ }
1205
+
1206
+ interface ClientStorageAPI {
1207
+ getAsync(key: string): Promise<any | undefined>
1208
+ setAsync(key: string, value: any): Promise<void>
1209
+ }
1210
+
1211
+ type ShowUIOptions = {
1212
+ width?: number
1213
+ height?: number
1214
+ visible?: boolean
1215
+ }
1216
+
1217
+ interface ExportSettingsConstraints {
1218
+ type: 'SCALE' | 'WIDTH' | 'HEIGHT'
1219
+ value: number
1220
+ }
1221
+ type ExportFileFormat = 'PNG' | 'JPG' | 'SVG' | 'PDF' | 'WEBP'
1222
+ type ExportSettings = {
1223
+ format: ExportFileFormat
1224
+ constraint?: ExportSettingsConstraints
1225
+ isSuffix?: boolean
1226
+ fileName?: string
1227
+ readonly useAbsoluteBounds?: boolean
1228
+ }
1229
+
1230
+ interface ExportMixin {
1231
+ exportSettings: ReadonlyArray<ExportSettings>
1232
+ export(settings?: ExportSettings): Promise<Uint8Array | string> // Defaults to PNG format
1233
+ }
1234
+
1235
+ interface NotifyOptions {
1236
+ position?: 'top' | 'bottom'
1237
+ type?: 'normal' | 'highlight' | 'error' | 'warning' | 'success'
1238
+ }
1239
+
1240
+ interface UIAPI {
1241
+ show(): void
1242
+ hide(): void
1243
+ close(): void
1244
+ resize(width: number, height: number): void
1245
+
1246
+ postMessage(pluginMessage: any, origin?: string): void
1247
+ onmessage: ((pluginMessage: any, origin: string) => void) | undefined
1248
+ }
1249
+
1250
+ /// /////////////////////////////////////////////////////////////////////////////
1251
+ // Styles
1252
+ interface PublishableMixin {
1253
+ description: string
1254
+ /**
1255
+ * 是否为团队库样式
1256
+ */
1257
+ readonly isExternal: boolean
1258
+ readonly ukey: string
1259
+ }
1260
+
1261
+ type StyleType = 'PAINT' | 'TEXT' | 'EFFECT' | 'GRID'
1262
+
1263
+ interface BaseStyle extends PublishableMixin {
1264
+ readonly id: string
1265
+ readonly type: StyleType
1266
+ name: string
1267
+ remove(): void
1268
+ }
1269
+
1270
+ interface PaintStyle extends BaseStyle {
1271
+ type: 'PAINT'
1272
+ paints: ReadonlyArray<Paint>
1273
+ }
1274
+
1275
+ interface NumValue {
1276
+ value: number
1277
+ unit: 'PIXELS' | 'PERCENT'
1278
+ }
1279
+
1280
+ interface TextSegStyle {
1281
+ start: number
1282
+ end: number
1283
+ textStyleId: string
1284
+ textStyle: {
1285
+ fontName: FontName
1286
+ fontSize: number
1287
+ letterSpacing: LetterSpacing
1288
+ lineHeight: LineHeight
1289
+ textDecoration: TextDecoration
1290
+ textCase: TextCase
1291
+ }
1292
+ fills: Paint[]
1293
+ }
1294
+
1295
+ interface EffectStyle extends BaseStyle {
1296
+ type: 'EFFECT'
1297
+ effects: ReadonlyArray<Effect>
1298
+ }
1299
+
1300
+ interface TextStyle extends BaseStyle {
1301
+ type: 'TEXT'
1302
+ decoration: TextDecoration
1303
+ description: string
1304
+ fontSize: number
1305
+ isExternal: boolean
1306
+ letterSpacing: number
1307
+ letterSpacingUnit: NumValue['unit']
1308
+ textCase: TextCase
1309
+ }
1310
+
1311
+ interface FontAlias {
1312
+ title: string
1313
+ subtitle: string
1314
+ }
1315
+
1316
+ interface GridStyle extends BaseStyle {
1317
+ type: 'GRID'
1318
+ layoutGrids: ReadonlyArray<LayoutGrid>
1319
+ }
1320
+
1321
+ type Style = PaintStyle | EffectStyle | TextStyle | GridStyle
1322
+
1323
+ /// /////////////////////////////////////////////////////////////////////////////
1324
+ // Datatypes
1325
+
1326
+ type Transform = [[number, number, number], [number, number, number]]
1327
+
1328
+ interface Vector {
1329
+ readonly x: number
1330
+ readonly y: number
1331
+ }
1332
+
1333
+ interface RGB {
1334
+ readonly r: number
1335
+ readonly g: number
1336
+ readonly b: number
1337
+ }
1338
+
1339
+ interface RGBA {
1340
+ readonly r: number
1341
+ readonly g: number
1342
+ readonly b: number
1343
+ readonly a: number
1344
+ }
1345
+
1346
+ interface FontName {
1347
+ readonly family: string
1348
+ readonly style: string
1349
+ }
1350
+
1351
+ type TextCase = 'ORIGINAL' | 'UPPER' | 'LOWER' | 'TITLE';
1352
+
1353
+ type TextDecoration = 'NONE' | 'UNDERLINE' | 'STRIKETHROUGH'
1354
+
1355
+ interface ShadowEffect {
1356
+ readonly type: 'DROP_SHADOW' | 'INNER_SHADOW'
1357
+ readonly color: RGBA
1358
+ // Effect的 x, y;
1359
+ readonly offset: Vector
1360
+ // spread和radius待确定
1361
+ readonly spread: number
1362
+ readonly radius: number
1363
+ readonly isVisible: boolean
1364
+ readonly blendMode: BlendMode
1365
+ }
1366
+
1367
+ interface BlurEffect {
1368
+ readonly type: 'LAYER_BLUR' | 'BACKGROUND_BLUR'
1369
+ readonly radius: number
1370
+ readonly isVisible: boolean
1371
+ readonly blendMode: BlendMode
1372
+ }
1373
+
1374
+ type Effect = ShadowEffect | BlurEffect
1375
+
1376
+ // 待确认
1377
+ type ConstraintType = 'START' | 'END' | 'STARTANDEND' | 'CENTER' | 'SCALE'
1378
+
1379
+ interface Constraints {
1380
+ readonly horizontal: ConstraintType
1381
+ readonly vertical: ConstraintType
1382
+ }
1383
+
1384
+ interface ColorStop {
1385
+ readonly position: number
1386
+ readonly color: RGBA
1387
+ }
1388
+
1389
+ interface SolidPaint {
1390
+ readonly type: 'SOLID'
1391
+ readonly color: RGBA
1392
+
1393
+ readonly isVisible?: boolean
1394
+ /**
1395
+ * It always be 1 when type is 'SOLID', please modify the alpha field in color instead.
1396
+ * 纯色模式下alpha始终为1, 请设置color中的alpha.
1397
+ */
1398
+ readonly alpha?: number
1399
+ readonly blendMode?: BlendMode
1400
+ }
1401
+
1402
+ interface GradientPaint {
1403
+ readonly type:
1404
+ | 'GRADIENT_LINEAR'
1405
+ | 'GRADIENT_RADIAL'
1406
+ | 'GRADIENT_ANGULAR'
1407
+ | 'GRADIENT_DIAMOND'
1408
+ readonly transform: Transform
1409
+ readonly gradientStops: ReadonlyArray<ColorStop>
1410
+ readonly gradientHandlePositions?: [{ x: number, y: number}, { x: number, y: number}];
1411
+ readonly isVisible?: boolean
1412
+ readonly alpha?: number
1413
+ readonly blendMode?: BlendMode
1414
+ }
1415
+
1416
+ interface ImagePaint {
1417
+ readonly type: 'IMAGE'
1418
+ readonly imageRef: string
1419
+ readonly scaleMode?: 'FILL' | 'TILE' | 'STRETCH' | 'FIT' | 'CROP'
1420
+
1421
+ readonly isVisible?: boolean
1422
+ readonly alpha?: number
1423
+ readonly blendMode?: BlendMode
1424
+ }
1425
+
1426
+ type Paint = SolidPaint | GradientPaint | ImagePaint
1427
+
1428
+ type WindingRule = 'Nonzero' | 'Evenodd'
1429
+
1430
+ // 待确定
1431
+ interface VectorVertex {
1432
+ readonly id: number
1433
+ readonly x: number
1434
+ readonly y: number
1435
+ readonly type: 'PATH_NODE' | 'CONTROL_NODE' // 0 路径端点 1 控制节点
1436
+ readonly strokeCap?: StrokeCap
1437
+ readonly strokeJoin?: StrokeJoin
1438
+ readonly cornerRadius?: number
1439
+ }
1440
+
1441
+ // 待确定
1442
+ interface VectorRegion {
1443
+ readonly id: number
1444
+ readonly windingRule: WindingRule
1445
+ readonly pathIds?: ReadonlyArray<number>
1446
+ }
1447
+
1448
+ interface VectorCtrl {
1449
+ x: number
1450
+ y: number
1451
+ }
1452
+
1453
+ type LetterSpacing = {
1454
+ readonly value: number
1455
+ readonly unit: 'PIXELS' | 'PERCENT'
1456
+ }
1457
+
1458
+ type LineHeight = {
1459
+ readonly value: number
1460
+ readonly unit: 'PIXELS'
1461
+ }
1462
+
1463
+ type BlendMode =
1464
+ | 'NORMAL'
1465
+ | 'DARKEN'
1466
+ | 'MULTIPLY'
1467
+ | 'COLOR_BURN'
1468
+ | 'LIGHTEN'
1469
+ | 'SCREEN'
1470
+ | 'COLOR_DODGE'
1471
+ | 'OVERLAY'
1472
+ | 'SOFT_LIGHT'
1473
+ | 'HARD_LIGHT'
1474
+ | 'DIFFERENCE'
1475
+ | 'EXCLUSION'
1476
+ | 'HUE'
1477
+ | 'SATURATION'
1478
+ | 'COLOR'
1479
+ | 'LUMINOSITY'
1480
+ | 'PLUS_DARKER'
1481
+ | 'PLUS_LIGHTER'
1482
+ | 'PASS_THROUGH'
1483
+
1484
+ interface Font {
1485
+ fontName: FontName
1486
+ }
1487
+
1488
+ /// /////////////////////////////////////////////////////////////////////////////
1489
+ // Mixins
1490
+
1491
+ interface BaseNodeMixin {
1492
+ readonly id: string
1493
+ readonly parent: (BaseNode & ChildrenMixin) | void
1494
+ name: string // Note: setting this also sets \`autoRename\` to false on TextNodes
1495
+ removed: boolean
1496
+ remove(): void
1497
+ getPluginData(key: string): string
1498
+ setPluginData(key: string, value: string): void
1499
+ getPluginDataKeys(): string[]
1500
+ removePluginData(key: string): void
1501
+ clearPluginData(): void
1502
+ getSharedPluginData(namespace: string, key: string): string
1503
+ setSharedPluginData(namespace: string, key: string, value: string): void
1504
+ getSharedPluginDataKeys(namespace: string): void
1505
+ removeSharedPluginData(namespace: string, key: string): void
1506
+ clearSharedPluginData(namespace: string): void
1507
+ }
1508
+
1509
+ interface SceneNodeMixin {
1510
+ isVisible: boolean
1511
+ isLocked: boolean
1512
+ }
1513
+
1514
+ interface ChildrenMixin<ChildrenNode = SceneNode> {
1515
+ readonly children: ReadonlyArray<ChildrenNode>
1516
+ appendChild(child: SceneNode): void
1517
+ insertChild(index: number, child: SceneNode): void
1518
+
1519
+ findChildren(
1520
+ callback?: (node: SceneNode) => boolean
1521
+ ): ReadonlyArray<SceneNode>
1522
+ findChild(callback: (node: SceneNode) => boolean): SceneNode | null
1523
+
1524
+ findAll(callback?: (node: SceneNode) => boolean): ReadonlyArray<SceneNode>
1525
+ findOne(callback: (node: SceneNode) => boolean): SceneNode | null
1526
+ }
1527
+
1528
+ interface ConstraintMixin {
1529
+ constraints: Constraints
1530
+ }
1531
+
1532
+ interface Bound {
1533
+ x: number
1534
+ y: number
1535
+ width: number
1536
+ height: number
1537
+ }
1538
+
1539
+ interface LayoutMixin {
1540
+ absoluteTransform: Transform
1541
+ relativeTransform: Transform
1542
+ bound: Bound
1543
+ x: number
1544
+ y: number
1545
+ width: number
1546
+ height: number
1547
+ rotation: number // In degrees
1548
+ constrainProportions: boolean
1549
+ layoutPositioning: 'AUTO' | 'ABSOLUTE' // applicable only inside auto-layout frames
1550
+ alignSelf: 'STRETCH' | 'INHERIT' // applicable only inside auto-layout frames
1551
+ flexGrow: 0 | 1 // applicable only inside auto-layout frames
1552
+ }
1553
+
1554
+ interface BlendMixin {
1555
+ opacity: number
1556
+ blendMode: BlendMode
1557
+ isMask: boolean
1558
+ effects: ReadonlyArray<Effect>
1559
+ effectStyleId: string
1560
+ }
1561
+
1562
+ type StrokeCap = 'NONE' | 'ROUND' | 'SQUARE' | 'LINE_ARROW' | 'TRIANGLE_ARROW' | 'ROUND_ARROW' | 'RING' | 'DIAMOND' | 'LINE'
1563
+ type StrokeJoin = 'MITER' | 'BEVEL' | 'ROUND'
1564
+ type StrokeAlign = 'CENTER' | 'INSIDE' | 'OUTSIDE'
1565
+ type DashCap = 'NONE' | 'ROUND' | 'SQUARE'
1566
+ type StrokeStyle = 'SOLID' | 'DASH' | 'CUSTOM'
1567
+ type ConnectorStrokeCap = StrokeCap
1568
+
1569
+ interface ConnectorEndpointPosition {
1570
+ readonly position: { x: number; y: number }
1571
+ }
1572
+
1573
+ interface ConnectorEndpointConnected {
1574
+ readonly position: { x: number; y: number }
1575
+ readonly endpointNodeId: string
1576
+ readonly magnet: 'TOP' | 'LEFT' | 'BOTTOM' | 'RIGHT'
1577
+ }
1578
+
1579
+
1580
+ type ConnectorEndpoint =
1581
+ | ConnectorEndpointPosition
1582
+ | ConnectorEndpointConnected
1583
+
1584
+ interface GeometryMixin {
1585
+ fills: ReadonlyArray<Paint>
1586
+ strokes: ReadonlyArray<Paint>
1587
+ strokeWeight: number
1588
+ strokeAlign: StrokeAlign
1589
+ strokeCap: StrokeCap
1590
+ strokeJoin: StrokeJoin
1591
+ strokeStyle: StrokeStyle
1592
+ dashCap: DashCap
1593
+ strokeDashes: ReadonlyArray<number>
1594
+ fillStyleId: string
1595
+ strokeStyleId: string
1596
+ /**
1597
+ * You have to ensure the layer has stroke before invoking this method.
1598
+ * 在调用接口之前需要确保layer有描边.
1599
+ */
1600
+ outlineStroke(): SceneNode | null
1601
+ }
1602
+
1603
+ interface RectangleStrokeWeightMixin {
1604
+ strokeTopWeight: number
1605
+ strokeLeftWeight: number
1606
+ strokeBottomWeight: number
1607
+ strokeRightWeight: number
1608
+ }
1609
+
1610
+ interface CornerMixin {
1611
+ // 待确认
1612
+ cornerSmooth: number
1613
+ cornerRadius: number | symbol
1614
+ }
1615
+
1616
+ interface DefaultShapeMixin
1617
+ extends BaseNodeMixin,
1618
+ SceneNodeMixin,
1619
+ BlendMixin,
1620
+ GeometryMixin,
1621
+ LayoutMixin,
1622
+ ReactionMixin,
1623
+ ExportMixin { }
1624
+
1625
+ interface DefaultContainerMixin
1626
+ extends BaseNodeMixin,
1627
+ ReactionMixin,
1628
+ SceneNodeMixin,
1629
+ ChildrenMixin,
1630
+ RectangleCornerMixin,
1631
+ BlendMixin,
1632
+ CornerMixin,
1633
+ ConstraintMixin,
1634
+ LayoutMixin,
1635
+ ExportMixin { }
1636
+
1637
+ interface AutoLayout {
1638
+ flexMode: 'NONE' | 'HORIZONTAL' | 'VERTICAL'
1639
+ itemSpacing: number
1640
+ mainAxisAlignItems: 'FLEX_START' | 'FLEX_END' | 'CENTER' | 'SPACING_BETWEEN'
1641
+ crossAxisAlignItems: 'FLEX_START' | 'FLEX_END' | 'CENTER'
1642
+ mainAxisSizingMode: 'FIXED' | 'AUTO'
1643
+ crossAxisSizingMode: 'FIXED' | 'AUTO'
1644
+ strokesIncludedInLayout: boolean
1645
+ itemReverseZIndex: boolean
1646
+ paddingTop: number
1647
+ paddingRight: number
1648
+ paddingBottom: number
1649
+ paddingLeft: number
1650
+ }
1651
+
1652
+ export interface RowsColsLayoutGrid {
1653
+ readonly gridType: "ROWS" | "COLUMNS"
1654
+
1655
+ readonly alignment: "LEFT" | "RIGHT" | "STRETCH" | "CENTER"
1656
+ readonly gutterSize: number
1657
+ readonly count: number
1658
+ readonly sectionSize?: number | null
1659
+ readonly offset?: number
1660
+
1661
+ readonly isVisible?: boolean
1662
+ readonly color?: RGBA
1663
+ readonly id?: string
1664
+ readonly name?: string
1665
+ }
1666
+
1667
+ export interface GridLayoutGrid {
1668
+ readonly gridType: "GRID"
1669
+
1670
+ readonly sectionSize: number
1671
+
1672
+ readonly isVisible?: boolean
1673
+ readonly color?: RGBA
1674
+ readonly id?: string
1675
+ readonly name?: string
1676
+ }
1677
+
1678
+
1679
+ export type LayoutGrid = RowsColsLayoutGrid | GridLayoutGrid
1680
+
1681
+ interface FrameContainerMixin extends AutoLayout {
1682
+ clipsContent: boolean
1683
+ layoutGrids: ReadonlyArray<LayoutGrid>
1684
+ gridStyleId: string
1685
+ overflowDirection: OverflowDirection
1686
+ }
1687
+
1688
+ type OverflowDirection = "NONE" | "HORIZONTAL" | "VERTICAL" | "BOTH"
1689
+
1690
+ interface RectangleCornerMixin {
1691
+ topLeftRadius: number
1692
+ topRightRadius: number
1693
+ bottomLeftRadius: number
1694
+ bottomRightRadius: number
1695
+ }
1696
+
1697
+ interface ReactionMixin {
1698
+ reactions: ReadonlyArray<Reaction>
1699
+ }
1700
+
1701
+ interface OpaqueNodeMixin extends BaseNodeMixin, SceneNodeMixin, ExportMixin {
1702
+ readonly absoluteTransform: Transform
1703
+ relativeTransform: Transform
1704
+ x: number
1705
+ y: number
1706
+ readonly width: number
1707
+ readonly height: number
1708
+ readonly bound: Bound
1709
+ }
1710
+
1711
+ interface MinimalBlendMixin {
1712
+ opacity: number
1713
+ blendMode: BlendMode
1714
+ }
1715
+
1716
+ interface MinimalStrokesMixin {
1717
+ strokes: ReadonlyArray<Paint>
1718
+ strokeStyleId: string
1719
+ strokeWeight: number
1720
+ strokeJoin: StrokeJoin
1721
+ strokeAlign: StrokeAlign
1722
+ strokeStyle: StrokeStyle
1723
+ strokeCap: StrokeCap
1724
+ strokeDashes: ReadonlyArray<number>
1725
+ dashCap: DashCap
1726
+ }
1727
+
1728
+ interface MinimalFillsMixin {
1729
+ fills: ReadonlyArray<Paint>
1730
+ fillStyleId: string
1731
+ }
1732
+
1733
+ /// /////////////////////////////////////////////////////////////////////////////
1734
+ // Nodes
1735
+
1736
+ interface DocumentNode extends ChildrenMixin<PageNode> {
1737
+ readonly type: 'DOCUMENT'
1738
+ currentPage: PageNode
1739
+ name: string
1740
+ }
1741
+
1742
+ interface PageNode
1743
+ extends BaseNodeMixin,
1744
+ ChildrenMixin<SceneNode> {
1745
+ readonly type: 'PAGE'
1746
+
1747
+ selection: ReadonlyArray<SceneNode>
1748
+ clone(): PageNode
1749
+ /**
1750
+ * 选中所有图层
1751
+ */
1752
+ selectAll() : void
1753
+ /**
1754
+ * 背景颜色
1755
+ */
1756
+ bgColor: RGBA
1757
+ /**
1758
+ * 原型所有的flow
1759
+ */
1760
+ readonly flowStartingPoints: FlowStartingPoint[]
1761
+ /**
1762
+ * 标签,默认'NONE'
1763
+ */
1764
+ label:'NONE' | 'BLUE' | 'GREEN' | 'RED' | 'YELLOW' | 'PURPLE' | 'GRAY'
1765
+ }
1766
+
1767
+ interface FrameNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
1768
+ readonly type: 'FRAME'
1769
+ clone(): FrameNode
1770
+ }
1771
+
1772
+ interface GroupNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin {
1773
+ readonly type: 'GROUP'
1774
+ clone(): GroupNode
1775
+ }
1776
+
1777
+ interface RectangleNode
1778
+ extends DefaultShapeMixin,
1779
+ ConstraintMixin,
1780
+ CornerMixin,
1781
+ RectangleStrokeWeightMixin,
1782
+ RectangleCornerMixin {
1783
+ readonly type: 'RECTANGLE'
1784
+ clone(): RectangleNode
1785
+ }
1786
+
1787
+ interface LineNode extends DefaultShapeMixin, ConstraintMixin {
1788
+ readonly type: 'LINE'
1789
+ clone(): LineNode
1790
+ readonly height: number
1791
+ leftStrokeCap: StrokeCap
1792
+ rightStrokeCap: StrokeCap
1793
+ }
1794
+
1795
+ interface EllipseNode extends DefaultShapeMixin, ConstraintMixin {
1796
+ readonly type: 'ELLIPSE'
1797
+ clone(): EllipseNode
1798
+ arcData: ArcData
1799
+ }
1800
+
1801
+ interface PolygonNode extends DefaultShapeMixin, ConstraintMixin, CornerMixin {
1802
+ readonly type: 'POLYGON'
1803
+ pointCount: number
1804
+ clone(): PolygonNode
1805
+ }
1806
+
1807
+ interface StarNode extends DefaultShapeMixin, ConstraintMixin, CornerMixin {
1808
+ readonly type: 'STAR'
1809
+ pointCount: number
1810
+ innerRadius: number
1811
+ clone(): StarNode
1812
+ }
1813
+
1814
+ // interface VectorPath {
1815
+ // readonly id: number
1816
+ // readonly nodeIds: ReadonlyArray<number>
1817
+ // }
1818
+ type VectorPath = number[]
1819
+
1820
+ type VectorPaths = ReadonlyArray<VectorPath>
1821
+
1822
+ interface PenNetwork {
1823
+ paths: ReadonlyArray<VectorPaths>
1824
+ nodes: ReadonlyArray<VectorVertex>
1825
+ regions: ReadonlyArray<VectorRegion> | []
1826
+ ctrlNodes: ReadonlyArray<VectorCtrl>
1827
+ }
1828
+
1829
+ interface PenPaths {
1830
+ windingRule: WindingRule
1831
+ data: string
1832
+ }
1833
+
1834
+ interface PenNode extends DefaultShapeMixin, ConstraintMixin, CornerMixin {
1835
+ readonly type: 'PEN'
1836
+ penNetwork: PenNetwork
1837
+ set penPaths(paths: Array<PenPaths>)
1838
+ //@ts-ignore
1839
+ get penPaths(): PenPaths
1840
+ clone(): PenNode
1841
+ }
1842
+
1843
+ interface BooleanOperationNode
1844
+ extends DefaultShapeMixin,
1845
+ FrameContainerMixin,
1846
+ ChildrenMixin,
1847
+ CornerMixin {
1848
+ readonly type: 'BOOLEAN_OPERATION'
1849
+ booleanOperation: 'UNION' | 'INTERSECT' | 'SUBTRACT' | 'EXCLUDE'
1850
+ clone(): BooleanOperationNode
1851
+ }
1852
+
1853
+ interface TextRangeStyle {
1854
+ fontName: FontName
1855
+ fontSize: number
1856
+ lineHeight: LineHeight
1857
+ textDecoration: TextDecoration
1858
+ letterSpacing: LetterSpacing
1859
+ }
1860
+
1861
+ interface TextNode extends DefaultShapeMixin, ConstraintMixin {
1862
+ readonly type: 'TEXT'
1863
+ characters: string
1864
+ readonly hasMissingFont: boolean
1865
+ /**
1866
+ * @deprecated
1867
+ * This attribute is deprecared, please use hyperlinks instead.
1868
+ */
1869
+ readonly superlinks: Array<Superlink>
1870
+ readonly hyperlinks: Array<HyperlinkWithRange>
1871
+ textAlignHorizontal: 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFIED'
1872
+ textAlignVertical: 'TOP' | 'CENTER' | 'BOTTOM'
1873
+ textAutoResize: 'NONE' | 'WIDTH_AND_HEIGHT' | 'HEIGHT'
1874
+ paragraphSpacing: number
1875
+ readonly textStyles: ReadonlyArray<TextSegStyle>
1876
+ clone(): TextNode
1877
+
1878
+ insertCharacters(start: number, characters: string): void
1879
+ deleteCharacters(start: number, end: number): void
1880
+
1881
+ setRangeFontSize(start: number, end: number, fontSize: number): void
1882
+ setRangeTextDecoration(
1883
+ start: number,
1884
+ end: number,
1885
+ decoration: TextDecoration
1886
+ ): void
1887
+ setRangeFontName(start: number, end: number, fontName: FontName): void
1888
+ setRangeLetterSpacing(
1889
+ start: number,
1890
+ end: number,
1891
+ value: LetterSpacing
1892
+ ): void
1893
+ setRangeLineHeight(start: number, end: number, value: LineHeight): void
1894
+ setRangeFills(start: number, end: number, paints: Paint[]): void
1895
+ /**
1896
+ * @deprecated
1897
+ * This function is deprecared, please use setRangeHyperLink instead.
1898
+ */
1899
+ setRangeSuperLink(start: number, end: number, link: string | null): void
1900
+ setRangeHyperLink(start: number, end: number, hyperlink: Hyperlink | null): void
1901
+ setRangeTextCase(start: number, end: number, textCase: TextCase): void
1902
+ }
1903
+
1904
+ interface ComponentNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
1905
+ readonly type: 'COMPONENT'
1906
+ readonly variantProperties: Array<Record<string, string>>
1907
+ description: string
1908
+ setVariantPropertyValues(property: Record<string, string>): void
1909
+ clone(): ComponentNode
1910
+ createInstance(): InstanceNode
1911
+ }
1912
+
1913
+ interface ComponentSetNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
1914
+ readonly type: 'COMPONENT_SET'
1915
+ readonly componentPropertyDefinitions: Array<Record<string, Array<string> | string>>
1916
+ clone(): ComponentSetNode
1917
+ createVariantComponent(): void
1918
+ createVariantProperties(properties: Array<string>): void
1919
+ editVariantProperties(properties: Record<string, string>): void
1920
+ editVariantPropertyValues(properties: Record<string, { oldValue: string, newValue: string }>): void
1921
+ deleteVariantProperty(property: string): void
1922
+ }
1923
+
1924
+ interface InstanceNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
1925
+ readonly type: 'INSTANCE'
1926
+ readonly variantProperties: Array<Record<string, string>>
1927
+ setVariantPropertyValues(property: Record<string, string>): void
1928
+ clone(): InstanceNode
1929
+ /**
1930
+ * this is an async func
1931
+ */
1932
+ swapComponent(): void
1933
+ detachInstance(): InstanceNode
1934
+ mainComponent: ComponentNode | null
1935
+ }
1936
+
1937
+ interface SliceNode extends BaseNodeMixin, LayoutMixin, ConstraintMixin, SceneNodeMixin, ExportMixin {
1938
+ readonly type: 'SLICE'
1939
+ clone(): SliceNode
1940
+ isPreserveRatio: boolean
1941
+ }
1942
+
1943
+ interface ConnectorNode extends OpaqueNodeMixin, Pick<MinimalBlendMixin, 'opacity'>, Omit<MinimalStrokesMixin, 'strokeAlign'> {
1944
+ readonly type: 'CONNECTOR'
1945
+ createText(): TextSublayerNode
1946
+ readonly text: TextSublayerNode | null
1947
+ cornerRadius?: number
1948
+ connectorStart: ConnectorEndpoint
1949
+ connectorEnd: ConnectorEndpoint
1950
+ connectorStartStrokeCap: ConnectorStrokeCap
1951
+ connectorEndStrokeCap: ConnectorStrokeCap
1952
+ readonly strokeAlign: 'CENTER'
1953
+ clone(): ConnectorNode
1954
+ }
1955
+
1956
+ interface TextSublayerNode extends MinimalFillsMixin {
1957
+ readonly id: string
1958
+ readonly hasMissingFont: boolean
1959
+ readonly textAlignHorizontal: 'CENTER'
1960
+ readonly textAlignVertical: 'CENTER'
1961
+ readonly textAutoResize: 'WIDTH_AND_HEIGHT'
1962
+ readonly hyperlinks: Array<HyperlinkWithRange>
1963
+
1964
+ readonly textStyles: ReadonlyArray<TextSegStyle>
1965
+
1966
+ paragraphSpacing: number
1967
+
1968
+ characters: string
1969
+ insertCharacters(start: number, characters: string): void
1970
+ deleteCharacters(start: number, end: number): void
1971
+
1972
+ setRangeFontSize(start: number, end: number, fontSize: number): void
1973
+ setRangeTextDecoration(
1974
+ start: number,
1975
+ end: number,
1976
+ decoration: TextDecoration
1977
+ ): void
1978
+ setRangeFontName(start: number, end: number, fontName: FontName): void
1979
+ setRangeLetterSpacing(
1980
+ start: number,
1981
+ end: number,
1982
+ value: LetterSpacing
1983
+ ): void
1984
+ setRangeLineHeight(start: number, end: number, value: LineHeight): void
1985
+ setRangeFills(start: number, end: number, paints: Paint[]): void
1986
+ setRangeHyperLink(start: number, end: number, hyperlink: Hyperlink | null): void
1987
+ setRangeTextCase(start: number, end: number, textCase: TextCase): void
1988
+ }
1989
+
1990
+ type BaseNode = DocumentNode | PageNode | SceneNode
1991
+
1992
+ /**
1993
+ * 画布节点
1994
+ */
1995
+ type SceneNode =
1996
+ | GroupNode
1997
+ | FrameNode
1998
+ | PenNode
1999
+ | StarNode
2000
+ | LineNode
2001
+ | EllipseNode
2002
+ | PolygonNode
2003
+ | RectangleNode
2004
+ | TextNode
2005
+ | ComponentNode
2006
+ | ComponentSetNode
2007
+ | InstanceNode
2008
+ | BooleanOperationNode
2009
+ | SliceNode
2010
+ | ConnectorNode
2011
+
2012
+ type NodeType =
2013
+ | 'DOCUMENT'
2014
+ | 'PAGE'
2015
+ | 'GROUP'
2016
+ | 'FRAME'
2017
+ | 'RECTANGLE'
2018
+ | 'TEXT'
2019
+ | 'LINE'
2020
+ | 'ELLIPSE'
2021
+ | 'POLYGON'
2022
+ | 'STAR'
2023
+ | 'PEN'
2024
+ | 'COMPONENT'
2025
+ | 'COMPONENT_SET'
2026
+ | 'INSTANCE'
2027
+ | 'BOOLEAN_OPERATION'
2028
+ | 'SLICE'
2029
+ | 'CONNECTOR'
2030
+ }
2031
+
2032
+ export interface CreateStyleConfig {
2033
+ name: string;
2034
+ /**
2035
+ * layerId
2036
+ */
2037
+ id: string;
2038
+ description?: string;
2039
+ }
2040
+
2041
+ interface FlowStartingPoint {
2042
+ name: string
2043
+ id: string
2044
+ flowId: string
2045
+ description: string
2046
+ }
2047
+ interface Reaction {
2048
+ readonly trigger: Trigger;
2049
+ readonly action?: Action;
2050
+ }
2051
+ interface Action {
2052
+ readonly type: ActionType;
2053
+ readonly destinationId: string;
2054
+ readonly navigation: Navigation;
2055
+ readonly transition: Transition;
2056
+ readonly url: string;
2057
+ readonly scrollToXOffset?: number;
2058
+ readonly scrollToYOffset?: number;
2059
+ }
2060
+
2061
+ type ActionType = 'BACK' | 'NODE'| 'URL'| 'CLOSE'| 'NONE';
2062
+
2063
+ type Navigation = 'NAVIGATE' | 'OVERLAY' | 'SWAP_OVERLAY' | 'SCROLL_TO';
2064
+
2065
+ interface Transition {
2066
+ readonly type: TransitionType;
2067
+ readonly duration: number;
2068
+ readonly direction: TransitionDirection;
2069
+ readonly easing: Easing;
2070
+ }
2071
+
2072
+ type TransitionType = 'TANS_NONE' | 'INSTANT' | 'DISSOLVE' | 'SMART_ANIMATE' | 'MOVE_IN' | 'MOVE_OUT' | 'PUSH' | 'SLIDE_IN' | 'SLIDE_OUT' | 'DISPLACE'
2073
+
2074
+ type TransitionDirection = 'LEFT' | 'RIGHT' | 'TOP' | 'BOTTOM'
2075
+ interface Easing{
2076
+ readonly type: EasingType;
2077
+ readonly easingFunctionCubicBezier: {
2078
+ x1: number;
2079
+ x2: number;
2080
+ y1: number;
2081
+ y2: number;
2082
+ };
2083
+ }
2084
+
2085
+ type EasingType = 'LINEAR' | 'EASE_IN' | 'EASE_OUT' | 'EASE_IN_AND_OUT' | 'EASE_IN_BACK' | 'EASE_OUT_BACK' | 'EASE_IN_AND_OUT_BACK' | 'CUSTOM_CUBIC_BEZIER'
2086
+ interface Trigger{
2087
+ readonly type: TriggerType;
2088
+ readonly delay: number;
2089
+ }
2090
+ type TriggerType = 'ON_CLICK' | 'ON_DRAG' | 'ON_HOVER' | 'ON_PRESS' | 'MOUSE_ENTER' | 'MOUSE_LEAVE' | 'MOUSE_DOWN' | 'MOUSE_UP' | 'AFTER_DELAY'
2091
+
2092
+ interface ArcData {
2093
+ /**
2094
+ * 起点弧度
2095
+ */
2096
+ startingAngle: number
2097
+ /**
2098
+ * 终点弧度
2099
+ */
2100
+ endingAngle?: number
2101
+ /**
2102
+ * 内径
2103
+ */
2104
+ innerRadius: number
2105
+ }
2106
+
2107
+ export { }