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