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