@mastergo/plugin-typings 1.3.0 → 1.4.0

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +2135 -0
  2. package/package.json +1 -2
@@ -0,0 +1,2135 @@
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' | 'drop'
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
+ 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
+ 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
+ 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
+
937
+ interface CreateStyleConfig {
938
+ name: string;
939
+ /**
940
+ * layerId
941
+ */
942
+ id: string;
943
+ description?: string;
944
+ }
945
+
946
+ interface FlowStartingPoint {
947
+ name: string
948
+ id: string
949
+ flowId: string
950
+ description: string
951
+ }
952
+ interface Reaction {
953
+ readonly trigger: Trigger;
954
+ readonly action?: Action;
955
+ }
956
+ interface Action {
957
+ readonly type: ActionType;
958
+ readonly destinationId: string;
959
+ readonly navigation: Navigation;
960
+ readonly transition: Transition;
961
+ readonly url: string;
962
+ readonly scrollToXOffset?: number;
963
+ readonly scrollToYOffset?: number;
964
+ }
965
+
966
+ type ActionType = 'BACK' | 'NODE'| 'URL'| 'CLOSE'| 'NONE';
967
+
968
+ type Navigation = 'NAVIGATE' | 'OVERLAY' | 'SWAP_OVERLAY' | 'SCROLL_TO';
969
+
970
+ interface Transition {
971
+ readonly type: TransitionType;
972
+ readonly duration: number;
973
+ readonly direction: TransitionDirection;
974
+ readonly easing: Easing;
975
+ }
976
+
977
+ type TransitionType = 'TANS_NONE' | 'INSTANT' | 'DISSOLVE' | 'SMART_ANIMATE' | 'MOVE_IN' | 'MOVE_OUT' | 'PUSH' | 'SLIDE_IN' | 'SLIDE_OUT' | 'DISPLACE'
978
+
979
+ type TransitionDirection = 'LEFT' | 'RIGHT' | 'TOP' | 'BOTTOM'
980
+ interface Easing{
981
+ readonly type: EasingType;
982
+ readonly easingFunctionCubicBezier: {
983
+ x1: number;
984
+ x2: number;
985
+ y1: number;
986
+ y2: number;
987
+ };
988
+ }
989
+
990
+ 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'
991
+ interface Trigger{
992
+ readonly type: TriggerType;
993
+ readonly delay: number;
994
+ }
995
+ type TriggerType = 'ON_CLICK' | 'ON_DRAG' | 'ON_HOVER' | 'ON_PRESS' | 'MOUSE_ENTER' | 'MOUSE_LEAVE' | 'MOUSE_DOWN' | 'MOUSE_UP' | 'AFTER_DELAY'
996
+
997
+ interface ArcData {
998
+ /**
999
+ * 起点弧度
1000
+ */
1001
+ startingAngle: number
1002
+ /**
1003
+ * 终点弧度
1004
+ */
1005
+ endingAngle?: number
1006
+ /**
1007
+ * 内径
1008
+ */
1009
+ innerRadius: number
1010
+ }
1011
+
1012
+ interface PluginDrop {
1013
+ clientX: number
1014
+ clientY: number
1015
+ dropMetadata?: any
1016
+ }
1017
+
1018
+ interface DropEvent {
1019
+ x: number
1020
+ y: number
1021
+ absoluteX: number
1022
+ absoluteY: number
1023
+ dropMetadata?: any
1024
+ }
1025
+
1026
+ type BaseNode = DocumentNode | PageNode | SceneNode
1027
+
1028
+ /**
1029
+ * 画布节点
1030
+ */
1031
+ type SceneNode =
1032
+ | GroupNode
1033
+ | FrameNode
1034
+ | PenNode
1035
+ | StarNode
1036
+ | LineNode
1037
+ | EllipseNode
1038
+ | PolygonNode
1039
+ | RectangleNode
1040
+ | TextNode
1041
+ | ComponentNode
1042
+ | ComponentSetNode
1043
+ | InstanceNode
1044
+ | BooleanOperationNode
1045
+ | SliceNode
1046
+ | ConnectorNode
1047
+
1048
+ type NodeType =
1049
+ | 'DOCUMENT'
1050
+ | 'PAGE'
1051
+ | 'GROUP'
1052
+ | 'FRAME'
1053
+ | 'RECTANGLE'
1054
+ | 'TEXT'
1055
+ | 'LINE'
1056
+ | 'ELLIPSE'
1057
+ | 'POLYGON'
1058
+ | 'STAR'
1059
+ | 'PEN'
1060
+ | 'COMPONENT'
1061
+ | 'COMPONENT_SET'
1062
+ | 'INSTANCE'
1063
+ | 'BOOLEAN_OPERATION'
1064
+ | 'SLICE'
1065
+ | 'CONNECTOR'
1066
+ }
1067
+
1068
+ declare global {
1069
+ const mastergo: PluginAPI
1070
+ const mg: PluginAPI
1071
+ const console: Console
1072
+ const __html__: string
1073
+
1074
+ function setTimeout(callback: Function, timeout: number): number
1075
+ function clearTimeout(timeoutID: number): void
1076
+ function setInterval(callback: Function, timeout: number): number
1077
+ function clearInterval(timeoutID: number): void
1078
+ function requestAnimationFrame(cb: (ts: number) => void): number
1079
+ function cancelAnimationFrame(requestID: number): void
1080
+
1081
+ interface Console {
1082
+ log(message?: any, ...optionalParams: any[]): void
1083
+ error(message?: any, ...optionalParams: any[]): void
1084
+ assert(condition?: boolean, message?: string, ...data: any[]): void
1085
+ info(message?: any, ...optionalParams: any[]): void
1086
+ warn(message?: any, ...optionalParams: any[]): void
1087
+ clear(): void
1088
+ }
1089
+
1090
+ interface Image {
1091
+ readonly href: string
1092
+ getBytesAsync(): Promise<Uint8Array>
1093
+ }
1094
+
1095
+ enum LinkFlagEnum {
1096
+ CURRPAGE = 'currPage',
1097
+ OTHERPAGE = 'otherPage',
1098
+ PROTOTYPE = 'prototype',
1099
+ OUTFILE = 'outFile',
1100
+ OWNWEBSITE = 'ownWebsite',
1101
+ OTHERLINK = 'otherLink',
1102
+ }
1103
+
1104
+ interface Superlink {
1105
+ start: number
1106
+ end: number
1107
+ superlink: {
1108
+ layerId?: string
1109
+ link: string
1110
+ linkFlag: LinkFlagEnum
1111
+ pageId: string
1112
+ }
1113
+ }
1114
+
1115
+ interface Hyperlink {
1116
+ type: 'PAGE' | 'NODE' | 'URL',
1117
+ value: string
1118
+ }
1119
+ interface HyperlinkWithRange {
1120
+ start: number
1121
+ end: number
1122
+ hyperlink: Hyperlink
1123
+ }
1124
+
1125
+ type PluginEventType = 'selectionchange' | 'currentpagechange' | 'close' | 'themechange' | 'drop'
1126
+ type ThemeColor = 'dark' | 'light'
1127
+
1128
+ interface PluginAPI {
1129
+ readonly document: DocumentNode
1130
+
1131
+ readonly ui: UIAPI
1132
+
1133
+ readonly themeColor: ThemeColor
1134
+
1135
+ readonly apiVersion: string
1136
+
1137
+ readonly documentId: number
1138
+
1139
+ readonly clientStorage: ClientStorageAPI
1140
+
1141
+ readonly viewport: ViewportAPI
1142
+
1143
+ closePlugin(): void
1144
+
1145
+ on(type: PluginEventType, callback: CallableFunction): void
1146
+ once(type: PluginEventType, callback: CallableFunction): void
1147
+ off(type?: PluginEventType, callback?: CallableFunction): void
1148
+
1149
+ commitUndo(): void
1150
+ triggerUndo(): void
1151
+
1152
+ showUI(html: string, options?: ShowUIOptions): void
1153
+
1154
+ getNodeById(id: string): SceneNode | null
1155
+ createRectangle(): RectangleNode
1156
+ createLine(): LineNode
1157
+ createEllipse(): EllipseNode
1158
+ createPolygon(): PolygonNode
1159
+ createStar(): StarNode
1160
+ createPen(): PenNode
1161
+ createText(): TextNode
1162
+ createFrame(): FrameNode
1163
+ createComponent(): ComponentNode
1164
+ createPage(): PageNode
1165
+ createSlice(): SliceNode
1166
+ createConnector(): ConnectorNode
1167
+ createNodeFromSvgAsync(svg: string): Promise<FrameNode>
1168
+
1169
+ getHoverLayer(): PageNode | SceneNode
1170
+
1171
+ showGrid(show: boolean): void
1172
+
1173
+ group(children: ReadonlyArray<SceneNode>): GroupNode
1174
+ union(children: ReadonlyArray<SceneNode>): BooleanOperationNode
1175
+ subtract(children: ReadonlyArray<SceneNode>): BooleanOperationNode
1176
+ intersect(children: ReadonlyArray<SceneNode>): BooleanOperationNode
1177
+ exclude(children: ReadonlyArray<SceneNode>): BooleanOperationNode
1178
+
1179
+ saveVersionHistoryAsync(desc: string): Promise<void>
1180
+
1181
+ notify(message: string, options?: NotifyOptions): void
1182
+
1183
+ getStyleById(id: string): Style | null
1184
+ getTitleByFontFamilyAndStyle(fontFamily: string, fontStyle: string) : FontAlias | null
1185
+ createFillStyle(config: CreateStyleConfig): PaintStyle
1186
+ createStrokeStyle(config: CreateStyleConfig): PaintStyle
1187
+ createEffectStyle(config: CreateStyleConfig): EffectStyle
1188
+ createTextStyle(config: CreateStyleConfig): TextStyle
1189
+ createGridStyle(config: CreateStyleConfig): GridStyle
1190
+
1191
+ getLocalPaintStyles(): PaintStyle[]
1192
+ getLocalEffectStyles(): EffectStyle[]
1193
+ getLocalTextStyles(): TextStyle[]
1194
+ getLocalGridStyles(): GridStyle[]
1195
+
1196
+ listAvailableFontsAsync(): Promise<Font[]>
1197
+ loadFontAsync(fontName: FontName): Promise<boolean>
1198
+ createImage(imageData: Uint8Array): Promise<Image>
1199
+ getImageByHref(href: string): Image
1200
+
1201
+ hexToRGBA(hex: string): RGBA
1202
+ RGBAToHex(rgba: RGBA): string
1203
+ }
1204
+
1205
+ interface Rect {
1206
+ readonly x: number
1207
+ readonly y: number
1208
+ readonly width: number
1209
+ readonly height: number
1210
+ }
1211
+
1212
+ interface ViewportAPI {
1213
+ center: Vector
1214
+ zoom: number
1215
+ readonly bound: Rect
1216
+ scrollAndZoomIntoView(nodes: ReadonlyArray<BaseNode>): void
1217
+ }
1218
+
1219
+ interface ClientStorageAPI {
1220
+ getAsync(key: string): Promise<any | undefined>
1221
+ setAsync(key: string, value: any): Promise<void>
1222
+ }
1223
+
1224
+ type ShowUIOptions = {
1225
+ width?: number
1226
+ height?: number
1227
+ visible?: boolean
1228
+ }
1229
+
1230
+ interface ExportSettingsConstraints {
1231
+ type: 'SCALE' | 'WIDTH' | 'HEIGHT'
1232
+ value: number
1233
+ }
1234
+ type ExportFileFormat = 'PNG' | 'JPG' | 'SVG' | 'PDF' | 'WEBP'
1235
+ type ExportSettings = {
1236
+ format: ExportFileFormat
1237
+ constraint?: ExportSettingsConstraints
1238
+ isSuffix?: boolean
1239
+ fileName?: string
1240
+ readonly useAbsoluteBounds?: boolean
1241
+ }
1242
+
1243
+ interface ExportMixin {
1244
+ exportSettings: ReadonlyArray<ExportSettings>
1245
+ export(settings?: ExportSettings): Promise<Uint8Array | string> // Defaults to PNG format
1246
+ }
1247
+
1248
+ interface NotifyOptions {
1249
+ position?: 'top' | 'bottom'
1250
+ type?: 'normal' | 'highlight' | 'error' | 'warning' | 'success'
1251
+ }
1252
+
1253
+ interface UIAPI {
1254
+ show(): void
1255
+ hide(): void
1256
+ close(): void
1257
+ resize(width: number, height: number): void
1258
+
1259
+ postMessage(pluginMessage: any, origin?: string): void
1260
+ onmessage: ((pluginMessage: any, origin: string) => void) | undefined
1261
+ }
1262
+
1263
+ /// /////////////////////////////////////////////////////////////////////////////
1264
+ // Styles
1265
+ interface PublishableMixin {
1266
+ description: string
1267
+ /**
1268
+ * 是否为团队库样式
1269
+ */
1270
+ readonly isExternal: boolean
1271
+ readonly ukey: string
1272
+ }
1273
+
1274
+ type StyleType = 'PAINT' | 'TEXT' | 'EFFECT' | 'GRID'
1275
+
1276
+ interface BaseStyle extends PublishableMixin {
1277
+ readonly id: string
1278
+ readonly type: StyleType
1279
+ name: string
1280
+ remove(): void
1281
+ }
1282
+
1283
+ interface PaintStyle extends BaseStyle {
1284
+ type: 'PAINT'
1285
+ paints: ReadonlyArray<Paint>
1286
+ }
1287
+
1288
+ interface NumValue {
1289
+ value: number
1290
+ unit: 'PIXELS' | 'PERCENT'
1291
+ }
1292
+
1293
+ interface TextSegStyle {
1294
+ start: number
1295
+ end: number
1296
+ textStyleId: string
1297
+ textStyle: {
1298
+ fontName: FontName
1299
+ fontSize: number
1300
+ letterSpacing: LetterSpacing
1301
+ lineHeight: LineHeight
1302
+ textDecoration: TextDecoration
1303
+ textCase: TextCase
1304
+ }
1305
+ fills: Paint[]
1306
+ }
1307
+
1308
+ interface EffectStyle extends BaseStyle {
1309
+ type: 'EFFECT'
1310
+ effects: ReadonlyArray<Effect>
1311
+ }
1312
+
1313
+ interface TextStyle extends BaseStyle {
1314
+ type: 'TEXT'
1315
+ decoration: TextDecoration
1316
+ description: string
1317
+ fontSize: number
1318
+ isExternal: boolean
1319
+ letterSpacing: number
1320
+ letterSpacingUnit: NumValue['unit']
1321
+ textCase: TextCase
1322
+ }
1323
+
1324
+ interface FontAlias {
1325
+ title: string
1326
+ subtitle: string
1327
+ }
1328
+
1329
+ interface GridStyle extends BaseStyle {
1330
+ type: 'GRID'
1331
+ layoutGrids: ReadonlyArray<LayoutGrid>
1332
+ }
1333
+
1334
+ type Style = PaintStyle | EffectStyle | TextStyle | GridStyle
1335
+
1336
+ /// /////////////////////////////////////////////////////////////////////////////
1337
+ // Datatypes
1338
+
1339
+ type Transform = [[number, number, number], [number, number, number]]
1340
+
1341
+ interface Vector {
1342
+ readonly x: number
1343
+ readonly y: number
1344
+ }
1345
+
1346
+ interface RGB {
1347
+ readonly r: number
1348
+ readonly g: number
1349
+ readonly b: number
1350
+ }
1351
+
1352
+ interface RGBA {
1353
+ readonly r: number
1354
+ readonly g: number
1355
+ readonly b: number
1356
+ readonly a: number
1357
+ }
1358
+
1359
+ interface FontName {
1360
+ readonly family: string
1361
+ readonly style: string
1362
+ }
1363
+
1364
+ type TextCase = 'ORIGINAL' | 'UPPER' | 'LOWER' | 'TITLE';
1365
+
1366
+ type TextDecoration = 'NONE' | 'UNDERLINE' | 'STRIKETHROUGH'
1367
+
1368
+ interface ShadowEffect {
1369
+ readonly type: 'DROP_SHADOW' | 'INNER_SHADOW'
1370
+ readonly color: RGBA
1371
+ // Effect的 x, y;
1372
+ readonly offset: Vector
1373
+ // spread和radius待确定
1374
+ readonly spread: number
1375
+ readonly radius: number
1376
+ readonly isVisible: boolean
1377
+ readonly blendMode: BlendMode
1378
+ }
1379
+
1380
+ interface BlurEffect {
1381
+ readonly type: 'LAYER_BLUR' | 'BACKGROUND_BLUR'
1382
+ readonly radius: number
1383
+ readonly isVisible: boolean
1384
+ readonly blendMode: BlendMode
1385
+ }
1386
+
1387
+ type Effect = ShadowEffect | BlurEffect
1388
+
1389
+ // 待确认
1390
+ type ConstraintType = 'START' | 'END' | 'STARTANDEND' | 'CENTER' | 'SCALE'
1391
+
1392
+ interface Constraints {
1393
+ readonly horizontal: ConstraintType
1394
+ readonly vertical: ConstraintType
1395
+ }
1396
+
1397
+ interface ColorStop {
1398
+ readonly position: number
1399
+ readonly color: RGBA
1400
+ }
1401
+
1402
+ interface SolidPaint {
1403
+ readonly type: 'SOLID'
1404
+ readonly color: RGBA
1405
+
1406
+ readonly isVisible?: boolean
1407
+ /**
1408
+ * It always be 1 when type is 'SOLID', please modify the alpha field in color instead.
1409
+ * 纯色模式下alpha始终为1, 请设置color中的alpha.
1410
+ */
1411
+ readonly alpha?: number
1412
+ readonly blendMode?: BlendMode
1413
+ }
1414
+
1415
+ interface GradientPaint {
1416
+ readonly type:
1417
+ | 'GRADIENT_LINEAR'
1418
+ | 'GRADIENT_RADIAL'
1419
+ | 'GRADIENT_ANGULAR'
1420
+ | 'GRADIENT_DIAMOND'
1421
+ readonly transform: Transform
1422
+ readonly gradientStops: ReadonlyArray<ColorStop>
1423
+ readonly gradientHandlePositions?: [{ x: number, y: number}, { x: number, y: number}];
1424
+ readonly isVisible?: boolean
1425
+ readonly alpha?: number
1426
+ readonly blendMode?: BlendMode
1427
+ }
1428
+
1429
+ interface ImagePaint {
1430
+ readonly type: 'IMAGE'
1431
+ readonly imageRef: string
1432
+ readonly scaleMode?: 'FILL' | 'TILE' | 'STRETCH' | 'FIT' | 'CROP'
1433
+
1434
+ readonly isVisible?: boolean
1435
+ readonly alpha?: number
1436
+ readonly blendMode?: BlendMode
1437
+ }
1438
+
1439
+ type Paint = SolidPaint | GradientPaint | ImagePaint
1440
+
1441
+ type WindingRule = 'Nonzero' | 'Evenodd'
1442
+
1443
+ // 待确定
1444
+ interface VectorVertex {
1445
+ readonly id: number
1446
+ readonly x: number
1447
+ readonly y: number
1448
+ readonly type: 'PATH_NODE' | 'CONTROL_NODE' // 0 路径端点 1 控制节点
1449
+ readonly strokeCap?: StrokeCap
1450
+ readonly strokeJoin?: StrokeJoin
1451
+ readonly cornerRadius?: number
1452
+ }
1453
+
1454
+ // 待确定
1455
+ interface VectorRegion {
1456
+ readonly id: number
1457
+ readonly windingRule: WindingRule
1458
+ readonly pathIds?: ReadonlyArray<number>
1459
+ }
1460
+
1461
+ interface VectorCtrl {
1462
+ x: number
1463
+ y: number
1464
+ }
1465
+
1466
+ type LetterSpacing = {
1467
+ readonly value: number
1468
+ readonly unit: 'PIXELS' | 'PERCENT'
1469
+ }
1470
+
1471
+ type LineHeight = {
1472
+ readonly value: number
1473
+ readonly unit: 'PIXELS'
1474
+ }
1475
+
1476
+ type BlendMode =
1477
+ | 'NORMAL'
1478
+ | 'DARKEN'
1479
+ | 'MULTIPLY'
1480
+ | 'COLOR_BURN'
1481
+ | 'LIGHTEN'
1482
+ | 'SCREEN'
1483
+ | 'COLOR_DODGE'
1484
+ | 'OVERLAY'
1485
+ | 'SOFT_LIGHT'
1486
+ | 'HARD_LIGHT'
1487
+ | 'DIFFERENCE'
1488
+ | 'EXCLUSION'
1489
+ | 'HUE'
1490
+ | 'SATURATION'
1491
+ | 'COLOR'
1492
+ | 'LUMINOSITY'
1493
+ | 'PLUS_DARKER'
1494
+ | 'PLUS_LIGHTER'
1495
+ | 'PASS_THROUGH'
1496
+
1497
+ interface Font {
1498
+ fontName: FontName
1499
+ }
1500
+
1501
+ /// /////////////////////////////////////////////////////////////////////////////
1502
+ // Mixins
1503
+
1504
+ interface BaseNodeMixin {
1505
+ readonly id: string
1506
+ readonly parent: (BaseNode & ChildrenMixin) | void
1507
+ name: string // Note: setting this also sets \`autoRename\` to false on TextNodes
1508
+ removed: boolean
1509
+ remove(): void
1510
+ getPluginData(key: string): string
1511
+ setPluginData(key: string, value: string): void
1512
+ getPluginDataKeys(): string[]
1513
+ removePluginData(key: string): void
1514
+ clearPluginData(): void
1515
+ getSharedPluginData(namespace: string, key: string): string
1516
+ setSharedPluginData(namespace: string, key: string, value: string): void
1517
+ getSharedPluginDataKeys(namespace: string): void
1518
+ removeSharedPluginData(namespace: string, key: string): void
1519
+ clearSharedPluginData(namespace: string): void
1520
+ }
1521
+
1522
+ interface SceneNodeMixin {
1523
+ isVisible: boolean
1524
+ isLocked: boolean
1525
+ }
1526
+
1527
+ interface ChildrenMixin<ChildrenNode = SceneNode> {
1528
+ readonly children: ReadonlyArray<ChildrenNode>
1529
+ appendChild(child: SceneNode): void
1530
+ insertChild(index: number, child: SceneNode): void
1531
+
1532
+ findChildren(
1533
+ callback?: (node: SceneNode) => boolean
1534
+ ): ReadonlyArray<SceneNode>
1535
+ findChild(callback: (node: SceneNode) => boolean): SceneNode | null
1536
+
1537
+ findAll(callback?: (node: SceneNode) => boolean): ReadonlyArray<SceneNode>
1538
+ findOne(callback: (node: SceneNode) => boolean): SceneNode | null
1539
+ }
1540
+
1541
+ interface ConstraintMixin {
1542
+ constraints: Constraints
1543
+ }
1544
+
1545
+ interface Bound {
1546
+ x: number
1547
+ y: number
1548
+ width: number
1549
+ height: number
1550
+ }
1551
+
1552
+ interface LayoutMixin {
1553
+ absoluteTransform: Transform
1554
+ relativeTransform: Transform
1555
+ bound: Bound
1556
+ x: number
1557
+ y: number
1558
+ width: number
1559
+ height: number
1560
+ rotation: number // In degrees
1561
+ constrainProportions: boolean
1562
+ layoutPositioning: 'AUTO' | 'ABSOLUTE' // applicable only inside auto-layout frames
1563
+ alignSelf: 'STRETCH' | 'INHERIT' // applicable only inside auto-layout frames
1564
+ flexGrow: 0 | 1 // applicable only inside auto-layout frames
1565
+ }
1566
+
1567
+ interface BlendMixin {
1568
+ opacity: number
1569
+ blendMode: BlendMode
1570
+ isMask: boolean
1571
+ effects: ReadonlyArray<Effect>
1572
+ effectStyleId: string
1573
+ }
1574
+
1575
+ type StrokeCap = 'NONE' | 'ROUND' | 'SQUARE' | 'LINE_ARROW' | 'TRIANGLE_ARROW' | 'ROUND_ARROW' | 'RING' | 'DIAMOND' | 'LINE'
1576
+ type StrokeJoin = 'MITER' | 'BEVEL' | 'ROUND'
1577
+ type StrokeAlign = 'CENTER' | 'INSIDE' | 'OUTSIDE'
1578
+ type DashCap = 'NONE' | 'ROUND' | 'SQUARE'
1579
+ type StrokeStyle = 'SOLID' | 'DASH' | 'CUSTOM'
1580
+ type ConnectorStrokeCap = StrokeCap
1581
+
1582
+ interface ConnectorEndpointPosition {
1583
+ readonly position: { x: number; y: number }
1584
+ }
1585
+
1586
+ interface ConnectorEndpointConnected {
1587
+ readonly position: { x: number; y: number }
1588
+ readonly endpointNodeId: string
1589
+ readonly magnet: 'TOP' | 'LEFT' | 'BOTTOM' | 'RIGHT'
1590
+ }
1591
+
1592
+
1593
+ type ConnectorEndpoint =
1594
+ | ConnectorEndpointPosition
1595
+ | ConnectorEndpointConnected
1596
+
1597
+ interface GeometryMixin {
1598
+ fills: ReadonlyArray<Paint>
1599
+ strokes: ReadonlyArray<Paint>
1600
+ strokeWeight: number
1601
+ strokeAlign: StrokeAlign
1602
+ strokeCap: StrokeCap
1603
+ strokeJoin: StrokeJoin
1604
+ strokeStyle: StrokeStyle
1605
+ dashCap: DashCap
1606
+ strokeDashes: ReadonlyArray<number>
1607
+ fillStyleId: string
1608
+ strokeStyleId: string
1609
+ /**
1610
+ * You have to ensure the layer has stroke before invoking this method.
1611
+ * 在调用接口之前需要确保layer有描边.
1612
+ */
1613
+ outlineStroke(): SceneNode | null
1614
+ }
1615
+
1616
+ interface RectangleStrokeWeightMixin {
1617
+ strokeTopWeight: number
1618
+ strokeLeftWeight: number
1619
+ strokeBottomWeight: number
1620
+ strokeRightWeight: number
1621
+ }
1622
+
1623
+ interface CornerMixin {
1624
+ // 待确认
1625
+ cornerSmooth: number
1626
+ cornerRadius: number | symbol
1627
+ }
1628
+
1629
+ interface DefaultShapeMixin
1630
+ extends BaseNodeMixin,
1631
+ SceneNodeMixin,
1632
+ BlendMixin,
1633
+ GeometryMixin,
1634
+ LayoutMixin,
1635
+ ReactionMixin,
1636
+ ExportMixin { }
1637
+
1638
+ interface DefaultContainerMixin
1639
+ extends BaseNodeMixin,
1640
+ ReactionMixin,
1641
+ SceneNodeMixin,
1642
+ ChildrenMixin,
1643
+ RectangleCornerMixin,
1644
+ BlendMixin,
1645
+ CornerMixin,
1646
+ ConstraintMixin,
1647
+ LayoutMixin,
1648
+ ExportMixin { }
1649
+
1650
+ interface AutoLayout {
1651
+ flexMode: 'NONE' | 'HORIZONTAL' | 'VERTICAL'
1652
+ itemSpacing: number
1653
+ mainAxisAlignItems: 'FLEX_START' | 'FLEX_END' | 'CENTER' | 'SPACING_BETWEEN'
1654
+ crossAxisAlignItems: 'FLEX_START' | 'FLEX_END' | 'CENTER'
1655
+ mainAxisSizingMode: 'FIXED' | 'AUTO'
1656
+ crossAxisSizingMode: 'FIXED' | 'AUTO'
1657
+ strokesIncludedInLayout: boolean
1658
+ itemReverseZIndex: boolean
1659
+ paddingTop: number
1660
+ paddingRight: number
1661
+ paddingBottom: number
1662
+ paddingLeft: number
1663
+ }
1664
+
1665
+ interface RowsColsLayoutGrid {
1666
+ readonly gridType: "ROWS" | "COLUMNS"
1667
+
1668
+ readonly alignment: "LEFT" | "RIGHT" | "STRETCH" | "CENTER"
1669
+ readonly gutterSize: number
1670
+ readonly count: number
1671
+ readonly sectionSize?: number | null
1672
+ readonly offset?: number
1673
+
1674
+ readonly isVisible?: boolean
1675
+ readonly color?: RGBA
1676
+ readonly id?: string
1677
+ readonly name?: string
1678
+ }
1679
+
1680
+ interface GridLayoutGrid {
1681
+ readonly gridType: "GRID"
1682
+
1683
+ readonly sectionSize: number
1684
+
1685
+ readonly isVisible?: boolean
1686
+ readonly color?: RGBA
1687
+ readonly id?: string
1688
+ readonly name?: string
1689
+ }
1690
+
1691
+
1692
+ type LayoutGrid = RowsColsLayoutGrid | GridLayoutGrid
1693
+
1694
+ interface FrameContainerMixin extends AutoLayout {
1695
+ clipsContent: boolean
1696
+ layoutGrids: ReadonlyArray<LayoutGrid>
1697
+ gridStyleId: string
1698
+ overflowDirection: OverflowDirection
1699
+ }
1700
+
1701
+ type OverflowDirection = "NONE" | "HORIZONTAL" | "VERTICAL" | "BOTH"
1702
+
1703
+ interface RectangleCornerMixin {
1704
+ topLeftRadius: number
1705
+ topRightRadius: number
1706
+ bottomLeftRadius: number
1707
+ bottomRightRadius: number
1708
+ }
1709
+
1710
+ interface ReactionMixin {
1711
+ reactions: ReadonlyArray<Reaction>
1712
+ }
1713
+
1714
+ interface OpaqueNodeMixin extends BaseNodeMixin, SceneNodeMixin, ExportMixin {
1715
+ readonly absoluteTransform: Transform
1716
+ relativeTransform: Transform
1717
+ x: number
1718
+ y: number
1719
+ readonly width: number
1720
+ readonly height: number
1721
+ readonly bound: Bound
1722
+ }
1723
+
1724
+ interface MinimalBlendMixin {
1725
+ opacity: number
1726
+ blendMode: BlendMode
1727
+ }
1728
+
1729
+ interface MinimalStrokesMixin {
1730
+ strokes: ReadonlyArray<Paint>
1731
+ strokeStyleId: string
1732
+ strokeWeight: number
1733
+ strokeJoin: StrokeJoin
1734
+ strokeAlign: StrokeAlign
1735
+ strokeStyle: StrokeStyle
1736
+ strokeCap: StrokeCap
1737
+ strokeDashes: ReadonlyArray<number>
1738
+ dashCap: DashCap
1739
+ }
1740
+
1741
+ interface MinimalFillsMixin {
1742
+ fills: ReadonlyArray<Paint>
1743
+ fillStyleId: string
1744
+ }
1745
+
1746
+ /// /////////////////////////////////////////////////////////////////////////////
1747
+ // Nodes
1748
+
1749
+ interface DocumentNode extends ChildrenMixin<PageNode> {
1750
+ readonly type: 'DOCUMENT'
1751
+ currentPage: PageNode
1752
+ name: string
1753
+ }
1754
+
1755
+ interface PageNode
1756
+ extends BaseNodeMixin,
1757
+ ChildrenMixin<SceneNode> {
1758
+ readonly type: 'PAGE'
1759
+
1760
+ selection: ReadonlyArray<SceneNode>
1761
+ clone(): PageNode
1762
+ /**
1763
+ * 选中所有图层
1764
+ */
1765
+ selectAll() : void
1766
+ /**
1767
+ * 背景颜色
1768
+ */
1769
+ bgColor: RGBA
1770
+ /**
1771
+ * 原型所有的flow
1772
+ */
1773
+ readonly flowStartingPoints: FlowStartingPoint[]
1774
+ /**
1775
+ * 标签,默认'NONE'
1776
+ */
1777
+ label:'NONE' | 'BLUE' | 'GREEN' | 'RED' | 'YELLOW' | 'PURPLE' | 'GRAY'
1778
+ }
1779
+
1780
+ interface FrameNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
1781
+ readonly type: 'FRAME'
1782
+ clone(): FrameNode
1783
+ }
1784
+
1785
+ interface GroupNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin {
1786
+ readonly type: 'GROUP'
1787
+ clone(): GroupNode
1788
+ }
1789
+
1790
+ interface RectangleNode
1791
+ extends DefaultShapeMixin,
1792
+ ConstraintMixin,
1793
+ CornerMixin,
1794
+ RectangleStrokeWeightMixin,
1795
+ RectangleCornerMixin {
1796
+ readonly type: 'RECTANGLE'
1797
+ clone(): RectangleNode
1798
+ }
1799
+
1800
+ interface LineNode extends DefaultShapeMixin, ConstraintMixin {
1801
+ readonly type: 'LINE'
1802
+ clone(): LineNode
1803
+ readonly height: number
1804
+ leftStrokeCap: StrokeCap
1805
+ rightStrokeCap: StrokeCap
1806
+ }
1807
+
1808
+ interface EllipseNode extends DefaultShapeMixin, ConstraintMixin {
1809
+ readonly type: 'ELLIPSE'
1810
+ clone(): EllipseNode
1811
+ arcData: ArcData
1812
+ }
1813
+
1814
+ interface PolygonNode extends DefaultShapeMixin, ConstraintMixin, CornerMixin {
1815
+ readonly type: 'POLYGON'
1816
+ pointCount: number
1817
+ clone(): PolygonNode
1818
+ }
1819
+
1820
+ interface StarNode extends DefaultShapeMixin, ConstraintMixin, CornerMixin {
1821
+ readonly type: 'STAR'
1822
+ pointCount: number
1823
+ innerRadius: number
1824
+ clone(): StarNode
1825
+ }
1826
+
1827
+ // interface VectorPath {
1828
+ // readonly id: number
1829
+ // readonly nodeIds: ReadonlyArray<number>
1830
+ // }
1831
+ type VectorPath = number[]
1832
+
1833
+ type VectorPaths = ReadonlyArray<VectorPath>
1834
+
1835
+ interface PenNetwork {
1836
+ paths: ReadonlyArray<VectorPaths>
1837
+ nodes: ReadonlyArray<VectorVertex>
1838
+ regions: ReadonlyArray<VectorRegion> | []
1839
+ ctrlNodes: ReadonlyArray<VectorCtrl>
1840
+ }
1841
+
1842
+ interface PenPaths {
1843
+ windingRule: WindingRule
1844
+ data: string
1845
+ }
1846
+
1847
+ interface PenNode extends DefaultShapeMixin, ConstraintMixin, CornerMixin {
1848
+ readonly type: 'PEN'
1849
+ penNetwork: PenNetwork
1850
+ set penPaths(paths: Array<PenPaths>)
1851
+ //@ts-ignore
1852
+ get penPaths(): PenPaths
1853
+ clone(): PenNode
1854
+ }
1855
+
1856
+ interface BooleanOperationNode
1857
+ extends DefaultShapeMixin,
1858
+ FrameContainerMixin,
1859
+ ChildrenMixin,
1860
+ CornerMixin {
1861
+ readonly type: 'BOOLEAN_OPERATION'
1862
+ booleanOperation: 'UNION' | 'INTERSECT' | 'SUBTRACT' | 'EXCLUDE'
1863
+ clone(): BooleanOperationNode
1864
+ }
1865
+
1866
+ interface TextRangeStyle {
1867
+ fontName: FontName
1868
+ fontSize: number
1869
+ lineHeight: LineHeight
1870
+ textDecoration: TextDecoration
1871
+ letterSpacing: LetterSpacing
1872
+ }
1873
+
1874
+ interface TextNode extends DefaultShapeMixin, ConstraintMixin {
1875
+ readonly type: 'TEXT'
1876
+ characters: string
1877
+ readonly hasMissingFont: boolean
1878
+ /**
1879
+ * @deprecated
1880
+ * This attribute is deprecared, please use hyperlinks instead.
1881
+ */
1882
+ readonly superlinks: Array<Superlink>
1883
+ readonly hyperlinks: Array<HyperlinkWithRange>
1884
+ textAlignHorizontal: 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFIED'
1885
+ textAlignVertical: 'TOP' | 'CENTER' | 'BOTTOM'
1886
+ textAutoResize: 'NONE' | 'WIDTH_AND_HEIGHT' | 'HEIGHT'
1887
+ paragraphSpacing: number
1888
+ readonly textStyles: ReadonlyArray<TextSegStyle>
1889
+ clone(): TextNode
1890
+
1891
+ insertCharacters(start: number, characters: string): void
1892
+ deleteCharacters(start: number, end: number): void
1893
+
1894
+ setRangeFontSize(start: number, end: number, fontSize: number): void
1895
+ setRangeTextDecoration(
1896
+ start: number,
1897
+ end: number,
1898
+ decoration: TextDecoration
1899
+ ): void
1900
+ setRangeFontName(start: number, end: number, fontName: FontName): void
1901
+ setRangeLetterSpacing(
1902
+ start: number,
1903
+ end: number,
1904
+ value: LetterSpacing
1905
+ ): void
1906
+ setRangeLineHeight(start: number, end: number, value: LineHeight): void
1907
+ setRangeFills(start: number, end: number, paints: Paint[]): void
1908
+ /**
1909
+ * @deprecated
1910
+ * This function is deprecared, please use setRangeHyperLink instead.
1911
+ */
1912
+ setRangeSuperLink(start: number, end: number, link: string | null): void
1913
+ setRangeHyperLink(start: number, end: number, hyperlink: Hyperlink | null): void
1914
+ setRangeTextCase(start: number, end: number, textCase: TextCase): void
1915
+ }
1916
+
1917
+ interface ComponentNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
1918
+ readonly type: 'COMPONENT'
1919
+ readonly variantProperties: Array<Record<string, string>>
1920
+ description: string
1921
+ setVariantPropertyValues(property: Record<string, string>): void
1922
+ clone(): ComponentNode
1923
+ createInstance(): InstanceNode
1924
+ }
1925
+
1926
+ interface ComponentSetNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
1927
+ readonly type: 'COMPONENT_SET'
1928
+ readonly componentPropertyDefinitions: Array<Record<string, Array<string> | string>>
1929
+ clone(): ComponentSetNode
1930
+ createVariantComponent(): void
1931
+ createVariantProperties(properties: Array<string>): void
1932
+ editVariantProperties(properties: Record<string, string>): void
1933
+ editVariantPropertyValues(properties: Record<string, { oldValue: string, newValue: string }>): void
1934
+ deleteVariantProperty(property: string): void
1935
+ }
1936
+
1937
+ interface InstanceNode extends DefaultContainerMixin, GeometryMixin, FrameContainerMixin, RectangleStrokeWeightMixin {
1938
+ readonly type: 'INSTANCE'
1939
+ readonly variantProperties: Array<Record<string, string>>
1940
+ setVariantPropertyValues(property: Record<string, string>): void
1941
+ clone(): InstanceNode
1942
+ /**
1943
+ * this is an async func
1944
+ */
1945
+ swapComponent(): void
1946
+ detachInstance(): InstanceNode
1947
+ mainComponent: ComponentNode | null
1948
+ }
1949
+
1950
+ interface SliceNode extends BaseNodeMixin, LayoutMixin, ConstraintMixin, SceneNodeMixin, ExportMixin {
1951
+ readonly type: 'SLICE'
1952
+ clone(): SliceNode
1953
+ isPreserveRatio: boolean
1954
+ }
1955
+
1956
+ interface ConnectorNode extends OpaqueNodeMixin, Pick<MinimalBlendMixin, 'opacity'>, Omit<MinimalStrokesMixin, 'strokeAlign'> {
1957
+ readonly type: 'CONNECTOR'
1958
+ createText(): TextSublayerNode
1959
+ readonly text: TextSublayerNode | null
1960
+ cornerRadius?: number
1961
+ connectorStart: ConnectorEndpoint
1962
+ connectorEnd: ConnectorEndpoint
1963
+ connectorStartStrokeCap: ConnectorStrokeCap
1964
+ connectorEndStrokeCap: ConnectorStrokeCap
1965
+ readonly strokeAlign: 'CENTER'
1966
+ clone(): ConnectorNode
1967
+ }
1968
+
1969
+ interface TextSublayerNode extends MinimalFillsMixin {
1970
+ readonly id: string
1971
+ readonly hasMissingFont: boolean
1972
+ readonly textAlignHorizontal: 'CENTER'
1973
+ readonly textAlignVertical: 'CENTER'
1974
+ readonly textAutoResize: 'WIDTH_AND_HEIGHT'
1975
+ readonly hyperlinks: Array<HyperlinkWithRange>
1976
+
1977
+ readonly textStyles: ReadonlyArray<TextSegStyle>
1978
+
1979
+ paragraphSpacing: number
1980
+
1981
+ characters: string
1982
+ insertCharacters(start: number, characters: string): void
1983
+ deleteCharacters(start: number, end: number): void
1984
+
1985
+ setRangeFontSize(start: number, end: number, fontSize: number): void
1986
+ setRangeTextDecoration(
1987
+ start: number,
1988
+ end: number,
1989
+ decoration: TextDecoration
1990
+ ): void
1991
+ setRangeFontName(start: number, end: number, fontName: FontName): void
1992
+ setRangeLetterSpacing(
1993
+ start: number,
1994
+ end: number,
1995
+ value: LetterSpacing
1996
+ ): void
1997
+ setRangeLineHeight(start: number, end: number, value: LineHeight): void
1998
+ setRangeFills(start: number, end: number, paints: Paint[]): void
1999
+ setRangeHyperLink(start: number, end: number, hyperlink: Hyperlink | null): void
2000
+ setRangeTextCase(start: number, end: number, textCase: TextCase): void
2001
+ }
2002
+
2003
+
2004
+ interface CreateStyleConfig {
2005
+ name: string;
2006
+ /**
2007
+ * layerId
2008
+ */
2009
+ id: string;
2010
+ description?: string;
2011
+ }
2012
+
2013
+ interface FlowStartingPoint {
2014
+ name: string
2015
+ id: string
2016
+ flowId: string
2017
+ description: string
2018
+ }
2019
+ interface Reaction {
2020
+ readonly trigger: Trigger;
2021
+ readonly action?: Action;
2022
+ }
2023
+ interface Action {
2024
+ readonly type: ActionType;
2025
+ readonly destinationId: string;
2026
+ readonly navigation: Navigation;
2027
+ readonly transition: Transition;
2028
+ readonly url: string;
2029
+ readonly scrollToXOffset?: number;
2030
+ readonly scrollToYOffset?: number;
2031
+ }
2032
+
2033
+ type ActionType = 'BACK' | 'NODE'| 'URL'| 'CLOSE'| 'NONE';
2034
+
2035
+ type Navigation = 'NAVIGATE' | 'OVERLAY' | 'SWAP_OVERLAY' | 'SCROLL_TO';
2036
+
2037
+ interface Transition {
2038
+ readonly type: TransitionType;
2039
+ readonly duration: number;
2040
+ readonly direction: TransitionDirection;
2041
+ readonly easing: Easing;
2042
+ }
2043
+
2044
+ type TransitionType = 'TANS_NONE' | 'INSTANT' | 'DISSOLVE' | 'SMART_ANIMATE' | 'MOVE_IN' | 'MOVE_OUT' | 'PUSH' | 'SLIDE_IN' | 'SLIDE_OUT' | 'DISPLACE'
2045
+
2046
+ type TransitionDirection = 'LEFT' | 'RIGHT' | 'TOP' | 'BOTTOM'
2047
+ interface Easing{
2048
+ readonly type: EasingType;
2049
+ readonly easingFunctionCubicBezier: {
2050
+ x1: number;
2051
+ x2: number;
2052
+ y1: number;
2053
+ y2: number;
2054
+ };
2055
+ }
2056
+
2057
+ 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'
2058
+ interface Trigger{
2059
+ readonly type: TriggerType;
2060
+ readonly delay: number;
2061
+ }
2062
+ type TriggerType = 'ON_CLICK' | 'ON_DRAG' | 'ON_HOVER' | 'ON_PRESS' | 'MOUSE_ENTER' | 'MOUSE_LEAVE' | 'MOUSE_DOWN' | 'MOUSE_UP' | 'AFTER_DELAY'
2063
+
2064
+ interface ArcData {
2065
+ /**
2066
+ * 起点弧度
2067
+ */
2068
+ startingAngle: number
2069
+ /**
2070
+ * 终点弧度
2071
+ */
2072
+ endingAngle?: number
2073
+ /**
2074
+ * 内径
2075
+ */
2076
+ innerRadius: number
2077
+ }
2078
+
2079
+ interface PluginDrop {
2080
+ clientX: number
2081
+ clientY: number
2082
+ dropMetadata?: any
2083
+ }
2084
+
2085
+ interface DropEvent {
2086
+ x: number
2087
+ y: number
2088
+ absoluteX: number
2089
+ absoluteY: number
2090
+ dropMetadata?: any
2091
+ }
2092
+
2093
+ type BaseNode = DocumentNode | PageNode | SceneNode
2094
+
2095
+ /**
2096
+ * 画布节点
2097
+ */
2098
+ type SceneNode =
2099
+ | GroupNode
2100
+ | FrameNode
2101
+ | PenNode
2102
+ | StarNode
2103
+ | LineNode
2104
+ | EllipseNode
2105
+ | PolygonNode
2106
+ | RectangleNode
2107
+ | TextNode
2108
+ | ComponentNode
2109
+ | ComponentSetNode
2110
+ | InstanceNode
2111
+ | BooleanOperationNode
2112
+ | SliceNode
2113
+ | ConnectorNode
2114
+
2115
+ type NodeType =
2116
+ | 'DOCUMENT'
2117
+ | 'PAGE'
2118
+ | 'GROUP'
2119
+ | 'FRAME'
2120
+ | 'RECTANGLE'
2121
+ | 'TEXT'
2122
+ | 'LINE'
2123
+ | 'ELLIPSE'
2124
+ | 'POLYGON'
2125
+ | 'STAR'
2126
+ | 'PEN'
2127
+ | 'COMPONENT'
2128
+ | 'COMPONENT_SET'
2129
+ | 'INSTANCE'
2130
+ | 'BOOLEAN_OPERATION'
2131
+ | 'SLICE'
2132
+ | 'CONNECTOR'
2133
+ }
2134
+
2135
+ export { }