@mastergo/plugin-typings 2.5.0 → 2.7.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/dist/index.d.ts +1080 -3
  2. package/package.json +17 -9
  3. package/CHANGELOG.md +0 -849
package/dist/index.d.ts CHANGED
@@ -1,3 +1,1003 @@
1
+ import { Properties, PropertiesHyphen } from 'csstype';
2
+
3
+ declare global {
4
+ namespace MGDSL {
5
+ interface MGDSLData {
6
+ /**
7
+ * 版本信息,遵循SemVer规则
8
+ */
9
+ readonly version: string;
10
+ /**
11
+ * 框架类型
12
+ */
13
+ framework: Framework;
14
+ readonly nodeMap: Record<NodeId, MGNode>;
15
+ readonly localStyleMap: StyleMap;
16
+ readonly fileMap: Record<FileId, MGDSLFile>;
17
+ root: MGLayerNode;
18
+ settings: DSLSettings;
19
+ entry: FileId;
20
+ /**
21
+ * 预览代码时所引入模块,需要将配置模型上的依赖模块引入
22
+ */
23
+ importPath: ImportPath;
24
+ importType: 'GLOBAL' | 'IMPORT';
25
+ }
26
+
27
+ type ImportPath = {
28
+ name: string;
29
+ path: string;
30
+ type: 'script' | 'style';
31
+ importRule?: 'ALL' | 'DEFAULT' | 'NAMED';
32
+ }[];
33
+
34
+ // js dsl模板
35
+ interface JSDSLData extends MGDSLData {
36
+ /**
37
+ * 全局样式表
38
+ */
39
+ globalStyleMap: {
40
+ [classId: string]: ClassStyle;
41
+ };
42
+ }
43
+ interface ReactDSLData extends JSDSLData {
44
+ readonly framework: 'REACT';
45
+ }
46
+ interface Vue3DSLData extends JSDSLData {
47
+ readonly framework: 'VUE3';
48
+ }
49
+ interface Vue2DSLData extends JSDSLData {
50
+ readonly framework: 'VUE2';
51
+ }
52
+ interface AndroidDSLData extends MGDSLData {
53
+ readonly framework: 'ANDROID';
54
+ /**
55
+ * 全局样式表
56
+ */
57
+ globalStyleMap: {
58
+ [classId: string]: ClassStyle;
59
+ };
60
+ }
61
+ interface IOSDSLData extends MGDSLData {
62
+ readonly framework: 'IOS';
63
+ }
64
+
65
+ type Framework = 'REACT' | 'VUE2' | 'VUE3' | 'ANDROID' | 'IOS';
66
+
67
+ type TokenName = string;
68
+ type TokenVariable = string;
69
+ type TokenValue = MGDSL.StyleSet[keyof MGDSL.StyleSet];
70
+ /**
71
+ * 自定义样式
72
+ */
73
+ type TokenItem = TokenCommonItem | TokenTextItem;
74
+ type TokenCommonItem = {
75
+ id: string;
76
+ type: 'color' | 'padding' | 'border-radius' | 'border-width' | 'gap';
77
+ name: TokenName;
78
+ originName: string;
79
+ originAlias: string;
80
+ value: TokenValue;
81
+ variable: TokenVariable;
82
+
83
+ /**
84
+ * 是否是多段
85
+ */
86
+ isMultiple?: boolean;
87
+ };
88
+ type TokenTextSubItemType = 'fontfamily' | 'fontstyle' | 'fontsize' | 'lineheight' | 'decoration' | 'letterspacing';
89
+
90
+ type TokenTextItem = {
91
+ id: string;
92
+ type: 'text';
93
+ name: TokenName;
94
+ originName: string;
95
+ originAlias: string;
96
+ textItems: Record<TokenTextSubItemType, TokenTextSubItem>;
97
+ };
98
+
99
+ type TokenTextSubItem = {
100
+ type: TokenTextSubItemType;
101
+ name: TokenName;
102
+ value: TokenValue;
103
+ };
104
+
105
+ /**
106
+ * TODO: 安卓自定义样式
107
+ */
108
+ type AndroidStyleItem = any;
109
+ /**
110
+ * 自定义样式map
111
+ */
112
+ type StyleMap = {
113
+ [styleId: string]: TokenItem | AndroidStyleItem;
114
+ };
115
+
116
+ /**
117
+ * 配置
118
+ */
119
+ interface DSLSettings {
120
+ /**
121
+ * 是否使用自定义样式,默认为true
122
+ */
123
+ useToken: boolean;
124
+ }
125
+
126
+ interface ClassStyle {
127
+ id: ClassId;
128
+ name: string;
129
+ scoped: boolean;
130
+ value: StyleSet;
131
+ // 伪类
132
+ pseudo?: 'HOVER' | 'ACTIVE' | 'FOCUS' | 'DISABLED';
133
+ /**
134
+ * css类型
135
+ * */
136
+ type: 'group' | 'class' | 'pseudo' | 'id' | 'attribute' | 'combinators';
137
+ }
138
+
139
+ type NodeId = LayerId | OperationId;
140
+ type LayerId = string;
141
+ type OperationId = string;
142
+
143
+ type MGNode = MGLayerNode | MGOperationNode;
144
+
145
+ interface MGLayerNode {
146
+ type: 'LAYER';
147
+ id: LayerId;
148
+ children: NodeId[];
149
+ name: string;
150
+ /**
151
+ * 图层在代码中的组件名
152
+ */
153
+ componentName: string;
154
+ /**
155
+ * 图层实际类型名称 RECTANGLE TEXT FRAME...
156
+ */
157
+ layerType: NodeType;
158
+ // 是否是蒙版
159
+ isMask: boolean;
160
+ // 是否隐藏
161
+ isVisible: boolean;
162
+ layout: NodeLayout;
163
+ style: CssNodeStyle | IOSNodeStyle | AndroidNodeStyle;
164
+ /**
165
+ * 是否是根元素
166
+ */
167
+ isRoot: boolean;
168
+ parent?: NodeId;
169
+ /**
170
+ * 关联的文件
171
+ */
172
+ relatedFile: FileId;
173
+ /**
174
+ * 是否拆分成新文件,默认false
175
+ */
176
+ isNewFile?: boolean;
177
+ characters: string;
178
+ }
179
+
180
+ type DocumentationLink = {
181
+ url: string;
182
+ };
183
+
184
+ interface MGComponentNode extends MGLayerNode {
185
+ layerType: 'COMPONENT';
186
+ alias: string;
187
+ description: string;
188
+ documentationLinks: DocumentationLink[];
189
+ /**
190
+ * 是组件集子组件的话则存在
191
+ */
192
+ componentSetId?: string;
193
+ componentSetDescription?: string;
194
+ componentSetDocumentationLinks?: DocumentationLink[];
195
+ }
196
+
197
+ interface MGInstanceNode extends MGLayerNode {
198
+ layerType: 'INSTANCE';
199
+ /**
200
+ * 实例的主组件Layer, 这里不开通用模型就不解析
201
+ */
202
+ mainComponent?: LayerId;
203
+ description: string;
204
+ documentationLinks: DocumentationLink[];
205
+ componentSetDescription?: string;
206
+ componentSetDocumentationLinks?: DocumentationLink[];
207
+ }
208
+
209
+ interface MGCustomNode extends MGLayerNode {
210
+ layerType: 'CUSTOM';
211
+ tagName?: string;
212
+ props?: ComponentProp[];
213
+ imports: ImportItem[];
214
+ }
215
+
216
+ interface MGTextNode extends MGLayerNode {
217
+ characters: string;
218
+ }
219
+
220
+ type NodeType =
221
+ | 'GROUP'
222
+ | 'FRAME'
223
+ | 'RECTANGLE'
224
+ | 'TEXT'
225
+ | 'LINE'
226
+ | 'ELLIPSE'
227
+ | 'POLYGON'
228
+ | 'STAR'
229
+ | 'PEN'
230
+ | 'COMPONENT'
231
+ | 'COMPONENTSET'
232
+ | 'INSTANCE'
233
+ | 'BOOLEANOPERATION'
234
+ | 'SLICE'
235
+ | 'CONNECTOR'
236
+ | 'SECTION'
237
+ | 'CUSTOM';
238
+
239
+ /**
240
+ * 图层的布局信息
241
+ */
242
+ interface NodeLayout {
243
+ /**
244
+ * 相对矩阵
245
+ */
246
+ matrix?: Matrix;
247
+ width?: Dimension;
248
+ height?: Dimension;
249
+ /**
250
+ * 实际在画布渲染的宽 包括阴影外描边
251
+ */
252
+ renderWidth?: Dimension;
253
+ /**
254
+ * 实际在画布渲染的高 包括阴影外描边
255
+ */
256
+ renderHeight?: Dimension;
257
+ /**
258
+ * 自动布局
259
+ */
260
+ autoLayout?: AutoLayout;
261
+ overflow?: 'HIDDEN' | 'VISIBLE';
262
+ /**
263
+ * 相对于父元素的布局
264
+ */
265
+ relatedLayout?: AbsoluteLayout | RelatedAutoLayout;
266
+ }
267
+
268
+ /**
269
+ * 自动布局
270
+ */
271
+ type AutoLayout = {
272
+ direction: 'COLUMN' | 'ROW';
273
+ layoutWrap: 'NO_WRAP' | 'WRAP';
274
+ // 轴距
275
+ itemSpacing: Dimension | 'AUTO';
276
+ // 交叉轴距, 只有在 layoutWrap = 'WRAP'时生效
277
+ crossAxisSpacing: Dimension | 'AUTO' | null;
278
+ paddingTop: Dimension;
279
+ paddingRight: Dimension;
280
+ paddingBottom: Dimension;
281
+ paddingLeft: Dimension;
282
+ /**
283
+ * 主轴对齐方式
284
+ */
285
+ mainAxisAlignItems: AlignTypes;
286
+ /**
287
+ * 交叉轴对齐方式
288
+ */
289
+ crossAxisAlignItems: Exclude<AlignTypes, 'SPACE_BETWEEN'>;
290
+ /**
291
+ * 仅当换行的时候,交叉轴的多行对齐方式
292
+ */
293
+ crossAxisAlignContent: 'AUTO' | 'SPACE_BETWEEN';
294
+ /**
295
+ * 描边是否包含在布局内
296
+ */
297
+ strokesIncludedInLayout: boolean;
298
+ itemReverseZIndex: boolean;
299
+ };
300
+
301
+ /**
302
+ * 绝对定位
303
+ */
304
+ type AbsoluteLayout = {
305
+ type: 'ABSOLUTE';
306
+ bound: {
307
+ left?: Dimension;
308
+ right?: Dimension;
309
+ top?: Dimension;
310
+ bottom?: Dimension;
311
+ };
312
+ /**
313
+ * 包含外描边和阴影,实际渲染的bound
314
+ */
315
+ renderBound: {
316
+ left?: Dimension;
317
+ right?: Dimension;
318
+ top?: Dimension;
319
+ bottom?: Dimension;
320
+ };
321
+ };
322
+
323
+ /**
324
+ * 相对于父元素的自动布局
325
+ */
326
+ type RelatedAutoLayout = {
327
+ type: 'AUTO';
328
+ alignSelf: 'STRETCH' | 'INHERIT' | 'AUTO';
329
+ flexGrow: number;
330
+ };
331
+
332
+ type Matrix = [[number, number, number], [number, number, number]];
333
+ /**
334
+ * flex布局主轴
335
+ */
336
+ type AlignTypes = 'START' | 'END' | 'CENTER' | 'SPACE_BETWEEN';
337
+ /**
338
+ * 尺寸单位
339
+ */
340
+ type Dimension = {
341
+ type: 'PIXEL' | 'PERCENT' | 'CALC';
342
+ value: number | string;
343
+ };
344
+
345
+ interface NodeStyle {
346
+ /**
347
+ * 和localClassMap的key保持一致
348
+ */
349
+ id: `style-${NodeId}`;
350
+ type: NodeStyleType;
351
+ disable?: boolean;
352
+ }
353
+
354
+ /**
355
+ * 分段样式
356
+ */
357
+ type TextSegStyle = {
358
+ start: number;
359
+ end: number;
360
+ textStyleId: string;
361
+ textStyle: StyleSet;
362
+ };
363
+
364
+ interface CssNodeStyle extends NodeStyle {
365
+ /**
366
+ * css类名
367
+ */
368
+ name: string;
369
+ /**
370
+ * UI样式
371
+ */
372
+ value: StyleSet;
373
+ /**
374
+ * 布局样式
375
+ */
376
+ layoutStyles: StyleSet;
377
+ /**
378
+ * key为属性名称
379
+ */
380
+ attributes: Record<string, AttributeItem>;
381
+ /**
382
+ * 行内样式
383
+ */
384
+ inlineStyles?: StyleSet;
385
+ /**
386
+ * 动态行内样式
387
+ */
388
+ dynamicInlineStyles?: {
389
+ [key in keyof StyleSet]: string;
390
+ };
391
+ /**
392
+ * 文字分段样式
393
+ */
394
+ textStyles?: TextSegStyle[];
395
+ /**
396
+ * 样式名数组
397
+ */
398
+ classList?: ClassId[];
399
+ /**
400
+ * 标签名称
401
+ */
402
+ tag?: 'IMG' | 'DIV' | 'TEXT' | 'BUTTON' | 'INPUT' | 'SLOT' | 'SVG' | 'OPTION';
403
+ /**
404
+ * 子选择器
405
+ */
406
+ subSelectors?: Array<ClassStyle>;
407
+ /**
408
+ * 样式token关联
409
+ */
410
+ styleTokenAlias?: {
411
+ backgroundTokenId?: string;
412
+ strokeColorTokenId?: string;
413
+ paddingTokenId?: string;
414
+ gapTokenId?: string;
415
+ crossGapTokenId?: string;
416
+ radiusTokenId?: string;
417
+ };
418
+ }
419
+
420
+ /**
421
+ * STATIC 静态属性
422
+ * DYNAMIC 动态属性
423
+ * METHOD 方法
424
+ * UNBIND 只定义,但没有使用的属性
425
+ */
426
+ type Attribute = 'STATIC' | 'DYNAMIC' | 'METHOD' | 'UNBIND';
427
+
428
+ interface AttributeItem {
429
+ type: Attribute;
430
+ /**
431
+ * 属性名
432
+ */
433
+ name: string;
434
+ /**
435
+ * 属性值或者是对应的函数名称
436
+ */
437
+ value: string;
438
+ /**
439
+ * 参数类型
440
+ */
441
+ valueType: keyof ComponentPropType;
442
+ /**
443
+ * 属性值的来源
444
+ */
445
+ valueSource?: 'PROPS' | 'METHODS' | 'DATA';
446
+ /**
447
+ * 函数的表达式
448
+ */
449
+ expression?: string;
450
+ /**
451
+ * 默认值
452
+ */
453
+ defaultValue?: string | number | boolean;
454
+ /**
455
+ * 方法的传参
456
+ */
457
+ arguments?: string[];
458
+ }
459
+
460
+ type IOSNodeStyle = NodeStyle;
461
+
462
+ interface AndroidNodeStyle extends NodeStyle {
463
+ /**
464
+ * android样式
465
+ */
466
+ attributes: Record<string, string>;
467
+ /**
468
+ * 控件标签
469
+ */
470
+ // eslint-disable-next-line
471
+ tag: 'View'
472
+ | 'Canvas'
473
+ | 'ImageView'
474
+ | 'TextView'
475
+ | 'EditText'
476
+ | 'Button'
477
+ | 'Spinner'
478
+ | 'RadioButton'
479
+ | 'CheckBox'
480
+ | 'androidx.recyclerview.widget.RecyclerView'
481
+ | 'ScrollView'
482
+ | 'HorizontalScrollView'
483
+ | 'androidx.constraintlayout.widget.ConstraintLayout'
484
+ | 'com.example.mapplication.utils.MSvg';
485
+ /**
486
+ * 关联的文件
487
+ */
488
+ subFiles: AndroidFileType[];
489
+ /**
490
+ * 是否是slot
491
+ */
492
+ slot: boolean;
493
+ /**
494
+ * 包路径
495
+ */
496
+ package: string;
497
+ /**
498
+ * 溢出方向
499
+ */
500
+ overflowDirection: number;
501
+
502
+ effect: any;
503
+ }
504
+
505
+ type AndroidFileType = AndroidXMLFile | AndroidJavaFile;
506
+
507
+ interface AndroidFile {
508
+ name: string;
509
+ type: string;
510
+ path: string;
511
+ }
512
+
513
+ interface AndroidXMLFile extends AndroidFile {
514
+ type: 'xml';
515
+ header: string;
516
+ footer: string;
517
+ content: AndroidXMLFileTag[];
518
+ }
519
+
520
+ interface AndroidXMLFileTag {
521
+ tag: string;
522
+ attributes: Record<string, string>;
523
+ children?: AndroidXMLFileTag[];
524
+ }
525
+
526
+ interface AndroidJavaFile extends AndroidFile {
527
+ type: 'java';
528
+ package: string;
529
+ imports: string[];
530
+ className: string;
531
+ variables: Record<string, string>;
532
+ }
533
+ interface AndroidKotlinFile extends AndroidFile {
534
+ type: 'kotlin';
535
+ package: string;
536
+ imports: string[];
537
+ className: string;
538
+ variables: Record<string, string>;
539
+ }
540
+
541
+ interface AndroidBitmapFile extends AndroidFile {
542
+ type: 'png' | 'jpeg';
543
+ imageRef: string;
544
+ }
545
+
546
+ interface StyleSet extends Properties<string | number>, PropertiesHyphen<string | number> {}
547
+
548
+ // style-class-xx
549
+ type ClassId = string;
550
+
551
+ type NodeStyleType = 'VIEW' | 'SVG' | 'IMAGE' | 'TEXT' | 'INPUT' | 'BUTTON' | 'SCROLLVIEW';
552
+
553
+ type AndroidTag = {
554
+ SVG: 'com.example.mapplication.utils.MSvg';
555
+ IMAGE: 'ImageView';
556
+ TEXT: 'TextView';
557
+ INPUT: 'EditText';
558
+ BUTTON: 'Button';
559
+ SELECT: 'Spinner';
560
+ RADIO: 'RadioButton';
561
+ CHECKBOX: 'CheckBox';
562
+ SCROLLVIEW: 'ScrollView';
563
+ LIST: 'androidx.recyclerview.widget.RecyclerView';
564
+ VIEW: 'androidx.constraintlayout.widget.ConstraintLayout';
565
+ };
566
+
567
+ /**
568
+ * 运算符
569
+ */
570
+ type MGOperationNode = IfStatement | Iteration | Raw | TernaryExpression;
571
+
572
+ /**
573
+ * 条件判断
574
+ */
575
+ interface IfStatement {
576
+ id: OperationId;
577
+ type: 'OPERATION';
578
+ operationType: 'If_STATEMENT';
579
+ // 表达式
580
+ condition: string;
581
+ consequent: {
582
+ type: 'MGNode' | 'EXPRESSION';
583
+ body: MGNode | string;
584
+ };
585
+ alternate: {
586
+ type: 'MGNode' | 'EXPRESSION';
587
+ body: MGNode | string;
588
+ };
589
+ }
590
+
591
+ /**
592
+ * 迭代器
593
+ */
594
+ interface Iteration {
595
+ id: OperationId;
596
+ type: 'OPERATION';
597
+ operationType: 'ITERATOR';
598
+ // 迭代器的变量名
599
+ variable: string;
600
+ body: MGNode;
601
+ // 作为key的变量名,属于迭代变量中元素上的字段
602
+ key?: string;
603
+ }
604
+
605
+ /**
606
+ * 原始字符串
607
+ */
608
+ interface Raw {
609
+ id: OperationId;
610
+ type: 'OPERATION';
611
+ operationType: 'RAW';
612
+ body: string;
613
+ }
614
+ /**
615
+ * 三目运算
616
+ */
617
+ interface TernaryExpression {
618
+ id: OperationId;
619
+ type: 'OPERATION';
620
+ operationType: 'TERNARY_EXPRESSION';
621
+ condition: string;
622
+ trueExpression: {
623
+ type: 'MGNode' | 'EXPRESSION';
624
+ body: MGNode | string;
625
+ };
626
+ falseExpression: {
627
+ type: 'MGNode' | 'EXPRESSION';
628
+ body: MGNode | string;
629
+ };
630
+ }
631
+
632
+ type ImportItem = {
633
+ name: string;
634
+ path: string;
635
+ /**
636
+ * DEFAULT: import name from 'path'
637
+ * ALL: import * as name from 'path'
638
+ * NAMED: import { name } from 'path'
639
+ */
640
+ type: 'DEFAULT' | 'ALL'; // | 'NAMED'
641
+ };
642
+
643
+ interface MGDSLFile {
644
+ id: FileId;
645
+ name: string;
646
+ entryLayerId: LayerId;
647
+ chunks: FileId[];
648
+ data: Record<string, Data>;
649
+ props: Record<string, Prop>;
650
+ methods: Record<string, Method>;
651
+ computed: Record<string, Computed>;
652
+ // 导入
653
+ imports: ImportItem[];
654
+ }
655
+
656
+ type FileId = string;
657
+
658
+ type ComponentPropType = {
659
+ STRING: string;
660
+ NUMBER: number;
661
+ BOOLEAN: boolean;
662
+ FUNCTION: string | MGLayerNode[];
663
+ OBJECT: Record<string, ComponentPropValue<keyof ComponentPropType>>;
664
+ ARRAY: ComponentPropValue<keyof ComponentPropType>[];
665
+ SLOT: string | MGLayerNode[];
666
+ };
667
+
668
+ type ComponentPropValue<T extends keyof ComponentPropType> = {
669
+ type: T;
670
+ value: ComponentPropType[T];
671
+ };
672
+
673
+ type ComponentPropItem<T extends keyof ComponentPropType> = {
674
+ /**
675
+ * 类型
676
+ */
677
+ type: T;
678
+ /**
679
+ * 默认值,也可作为初始值使用
680
+ */
681
+ defaultValue?: ComponentPropType[T];
682
+ /**
683
+ * 属性名,根据aliasName和originalName经过处理后的名称,用于最终的展示
684
+ */
685
+ name: string;
686
+ };
687
+
688
+ type ComponentPropString = ComponentPropItem<'STRING'>;
689
+ type ComponentPropNumber = ComponentPropItem<'NUMBER'>;
690
+ type ComponentPropBoolean = ComponentPropItem<'BOOLEAN'>;
691
+ type ComponentPropFunction = ComponentPropItem<'FUNCTION'>;
692
+ type ComponentPropObject = ComponentPropItem<'OBJECT'>;
693
+ type ComponentPropArray = ComponentPropItem<'ARRAY'>;
694
+ type ComponentPropSlot = ComponentPropItem<'SLOT'>;
695
+
696
+ type ComponentProp =
697
+ | ComponentPropString
698
+ | ComponentPropNumber
699
+ | ComponentPropBoolean
700
+ | ComponentPropFunction
701
+ | ComponentPropObject
702
+ | ComponentPropArray
703
+ | ComponentPropSlot;
704
+
705
+ interface Method {
706
+ name: string;
707
+ args: Array<string>;
708
+ content: string;
709
+ returnValue?: string;
710
+ }
711
+
712
+ type DSLNumber = {
713
+ type: 'NUMBER';
714
+ /**
715
+ * 默认值,也可作为初始值使用
716
+ */
717
+ defaultValue?: number | undefined;
718
+ name: string;
719
+ };
720
+
721
+ type DSLBoolean = {
722
+ type: 'BOOLEAN';
723
+ defaultValue?: boolean | undefined;
724
+ name: string;
725
+ };
726
+
727
+ type DSLString = {
728
+ type: 'STRING';
729
+ /**
730
+ * 默认值,也可作为初始值使用
731
+ */
732
+ defaultValue?: string | undefined;
733
+ name: string;
734
+ };
735
+
736
+ type DSLFunction = {
737
+ type: 'FUNCTION';
738
+ defaultValue?: string | undefined;
739
+ name: string;
740
+ };
741
+
742
+ type DSLArray = {
743
+ type: 'ARRAY';
744
+ defaultValue?: Array<any> | undefined;
745
+ name: string;
746
+ };
747
+
748
+ type DSLObject = {
749
+ type: 'OBJECT';
750
+ /**
751
+ * 默认值,也可作为初始值使用
752
+ */
753
+ defaultValue?: { [key: string]: any };
754
+ name: string;
755
+ };
756
+
757
+ type Data = DSLString | DSLNumber | DSLBoolean | DSLFunction | DSLArray | DSLObject;
758
+ type Prop = DSLString | DSLNumber | DSLBoolean | DSLFunction | DSLArray | DSLObject;
759
+
760
+ interface Computed {
761
+ name: string;
762
+ args: Array<string>;
763
+ content: string;
764
+ returnValue?: string;
765
+ dependencies?: Array<string>;
766
+ }
767
+
768
+ interface CustomCode {
769
+ type: 'custom';
770
+ data: {
771
+ title: string;
772
+ code: string;
773
+ // 暂时不设置类型
774
+ type: string;
775
+ }[];
776
+ }
777
+ }
778
+ }
779
+
780
+ declare global {
781
+ namespace MGTMP {
782
+ type RegExpString = string;
783
+ type PseudoType = 'HOVER' | 'ACTIVE' | 'FOCUS' | 'DISABLED';
784
+ /**
785
+ * 工具类样式,如:.flex-1 { flex: 1 }
786
+ * 通常为写死的样式,不会根据数据动态生成。当value与DSLToCode.StyleNode.value相同时,可以直接使用StyleRule.className作为DSLToCode.StyleNode.className
787
+ */
788
+ type UtilityStyle = {
789
+ type: 'UTILITY';
790
+ className: string;
791
+ pseudo?: PseudoType;
792
+ value: Properties & PropertiesHyphen;
793
+ };
794
+ /**
795
+ * 配置类样式,如:.bg-color { background-color: var(--bg-color) },.bg-color:hover { background-color: var(--bg-color-hover) },
796
+ * 根据token的值按配置规则动态生成的样式。
797
+ */
798
+ type ConfigStyle = {
799
+ type: 'CONFIG';
800
+ prefix: string;
801
+ output: (token: string, tokenNameWithoutPrefix: string) => UtilityStyle[];
802
+ };
803
+ type StyleRule = UtilityStyle | ConfigStyle;
804
+ type StyleTemplate = StyleRule[];
805
+ /**
806
+ * 组件属性类型
807
+ */
808
+ type ComponentPropType = {
809
+ STRING: string;
810
+ NUMBER: number;
811
+ BOOLEAN: boolean;
812
+ FUNCTION: string | MGDSL.MGLayerNode[];
813
+ OBJECT: Record<string, MGDSL.ComponentPropValue<keyof ComponentPropType>>;
814
+ ARRAY: MGDSL.ComponentPropValue<keyof ComponentPropType>[];
815
+ SLOT: string | MGDSL.MGLayerNode[];
816
+ };
817
+
818
+ type GetValueType<T extends keyof ComponentPropType> = (
819
+ nodeId: MGDSL.LayerId,
820
+ nodeMap: Record<MGDSL.NodeId, MGDSL.MGNode>,
821
+ componentId?: string,
822
+ ) => {
823
+ value: ComponentPropType[T] | undefined;
824
+ nodeMap: Record<string, MGDSL.MGLayerNode>;
825
+ };
826
+
827
+ type ComponentPropItem<T extends keyof ComponentPropType> = {
828
+ /**
829
+ * 类型
830
+ */
831
+ type: T;
832
+ /**
833
+ * 默认值,也可作为初始值使用
834
+ */
835
+ defaultValue?: ComponentPropType[T];
836
+ /**
837
+ * 该方法内部需要bridge函数支持,不适合在配置模板中使用,请尽量少的使用该函数作判断
838
+ */
839
+ getValue?: GetValueType<T>;
840
+ /**
841
+ * 属性名,根据aliasName和originalName经过处理后的名称,用于最终的展示
842
+ */
843
+ name: string;
844
+ /**
845
+ * 属性别名
846
+ */
847
+ aliasName?: string;
848
+ /**
849
+ * 原始名称,区别于经过处理的name
850
+ */
851
+ originalName?: string;
852
+ /**
853
+ * 属性枚举值对应关系。一般和aliasName配合使用,根据画布图层的属性值,映射到代码中的属性值
854
+ */
855
+ aliasMap?: Record<string, ComponentPropType[T] | undefined>;
856
+ /**
857
+ * DSM属性枚举值对应关系
858
+ */
859
+ dsmAlias?: Record<string, string>;
860
+ /**
861
+ * 组件库解析时,是否将大写属性值转换为小写
862
+ */
863
+ lowerCase?: boolean;
864
+ /**
865
+ * 是否应用该属性
866
+ * @param aliasName 对应画布图层属性名,当前当前仅支持属性名的判断
867
+ * @param aliasMap 对应画布图层属性值
868
+ */
869
+ visible?: {
870
+ aliasName: string;
871
+ aliasMap?: Record<string, boolean>;
872
+ };
873
+ };
874
+ /**
875
+ * 组件属性类型
876
+ * 泛型没有显式指定类型时,会被推断所有生命类型,起不到约束作用
877
+ */
878
+ type ComponentPropString = ComponentPropItem<'STRING'> & {
879
+ /**
880
+ * 如果是string,允许已某个图层的content作为值
881
+ */
882
+ nodePath?: SlotMatchType[];
883
+ };
884
+ type ComponentPropNumber = ComponentPropItem<'NUMBER'>;
885
+ type ComponentPropBoolean = ComponentPropItem<'BOOLEAN'>;
886
+ type ComponentPropFunction = ComponentPropItem<'FUNCTION'>;
887
+ type ComponentPropObject = ComponentPropItem<'OBJECT'>;
888
+ type ComponentPropArray = ComponentPropItem<'ARRAY'>;
889
+ type ComponentPropInstance = ComponentPropItem<'SLOT'> & {
890
+ /**
891
+ * react的INSTANCE视为Vue的SLOT效果,故这里提供nodePath属性,继续遍历图层并以此图层为属性内容
892
+ * 这里只能指向唯一图层才能向下遍历
893
+ */
894
+ nodePath?: SlotMatchType[];
895
+ ignoreClass?: boolean;
896
+ };
897
+ /**
898
+ * 组件的虚拟路径,如:'@/components/xxx.vue'
899
+ * export default {} 为 DEFAULT
900
+ * export const xxx = {} 为 xxx
901
+ */
902
+ type ComponentSource = {
903
+ path: string;
904
+ export: 'DEFAULT' | string;
905
+ };
906
+ /**
907
+ * 组件属性
908
+ * @param type 属性类型
909
+ * @param name 属性名称
910
+ * @param defaultValue 属性默认值
911
+ * @param aliasName 对应设计系统的组件别名,如能匹配则根据别名生成代码
912
+ */
913
+ type ComponentProp =
914
+ | ComponentPropString
915
+ | ComponentPropNumber
916
+ | ComponentPropBoolean
917
+ | ComponentPropFunction
918
+ | ComponentPropObject
919
+ | ComponentPropArray
920
+ | ComponentPropInstance;
921
+ type ComponentData = {
922
+ name: string;
923
+ defaultValue: string | number | boolean;
924
+ type: keyof ComponentPropType;
925
+ };
926
+ type ComponentProps = {
927
+ name: string;
928
+ originalName?: string;
929
+ defaultValue?: string | number | boolean;
930
+ type: keyof ComponentPropType;
931
+ };
932
+ type SlotMatchType = RegExpString | number;
933
+ /**
934
+ * 组件插槽
935
+ * @param name 插槽名称
936
+ * @param relateNodeNames 关联的节点名称
937
+ */
938
+ type ComponentSlot = {
939
+ name: string;
940
+ relateNodeNames: (SlotMatchType | SlotMatchType[])[];
941
+ ignoreClass?: boolean;
942
+ } & (
943
+ | { type?: '' }
944
+ | {
945
+ type: 'TEXT';
946
+ }
947
+ | {
948
+ type: 'CUSTOM';
949
+ // 返回MGDSL数据,id可为空
950
+ getValue: GetValueType<'SLOT'>;
951
+ }
952
+ );
953
+
954
+ /**
955
+ * 组件模板
956
+ * @param name 组件名称
957
+ * @param props 组件属性
958
+ * @param source 组件的虚拟路径
959
+ */
960
+ type ComponentOrigin = {
961
+ name: string;
962
+ props: ComponentProp[];
963
+ slots?: ComponentSlot[];
964
+ source: ComponentSource;
965
+ ignoreRect?: boolean;
966
+ };
967
+ type ComponentItem = ComponentOrigin & { id: string; matchName?: string };
968
+ // 图标库
969
+ type Icons = {
970
+ /**
971
+ * 组件名适配正则
972
+ */
973
+ reg: RegExpString;
974
+ getValue: (node: MGDSL.MGLayerNode) => MGDSL.MGCustomNode;
975
+ };
976
+
977
+ type ComponentTemplate = {
978
+ // 防止组件库解析,存储对应文件id
979
+ documentId: string;
980
+ // 暂时作为唯一标识
981
+ name: string;
982
+ /**
983
+ * 组件导入类型
984
+ * GLOBAL 全局引入
985
+ * IMPORT esm引入
986
+ */
987
+ importType: 'GLOBAL' | 'IMPORT';
988
+ importPath: {
989
+ name: string;
990
+ importName: string;
991
+ path: string;
992
+ type: 'script' | 'style';
993
+ }[];
994
+ framework: 'VUE2' | 'VUE3' | 'REACT';
995
+ components: ComponentItem[];
996
+ icons?: Icons;
997
+ };
998
+ }
999
+ }
1000
+
1
1001
  declare global {
2
1002
  const mastergo: PluginAPI
3
1003
  const mg: PluginAPI
@@ -51,6 +1051,9 @@ declare global {
51
1051
 
52
1052
  readonly viewport: ViewportAPI
53
1053
 
1054
+ // only available in devMode
1055
+ readonly codegen?: CodegenAPI
1056
+
54
1057
  closePlugin(): void
55
1058
 
56
1059
  on(type: PluginEventType, callback: CallableFunction): void
@@ -115,7 +1118,7 @@ declare global {
115
1118
 
116
1119
  listAvailableFontsAsync(): Promise<Font[]>
117
1120
  loadFontAsync(fontName: FontName): Promise<boolean>
118
- createImage(imageData: Uint8Array): Promise<Image>
1121
+ createImage(imageData: Uint8Array, isSync?: boolean): Promise<Image>
119
1122
  getImageByHref(href: string): Image
120
1123
 
121
1124
 
@@ -288,6 +1291,8 @@ declare global {
288
1291
  textStyleId: string
289
1292
  textStyle: {
290
1293
  fontName: FontName
1294
+ localizedFontName: FontName
1295
+ referrer: FontReferrer
291
1296
  fontSize: number
292
1297
  letterSpacing: LetterSpacing
293
1298
  lineHeight: LineHeight
@@ -376,6 +1381,8 @@ declare global {
376
1381
  readonly radius: number
377
1382
  readonly isVisible: boolean
378
1383
  readonly blendMode: BlendMode
1384
+ readonly showShadowBehindNode: boolean
1385
+ readonly isEffectShow: boolean
379
1386
  }
380
1387
 
381
1388
  interface BlurEffect {
@@ -512,8 +1519,12 @@ declare global {
512
1519
  | 'PLUS_LIGHTER'
513
1520
  | 'PASS_THROUGH'
514
1521
 
1522
+ type FontReferrer = 'team' | 'org' | 'local' | 'official'
1523
+
515
1524
  interface Font {
516
1525
  fontName: FontName
1526
+ localizedFontName: FontName
1527
+ referrer: FontReferrer
517
1528
  }
518
1529
 
519
1530
  /// /////////////////////////////////////////////////////////////////////////////
@@ -1344,6 +2355,72 @@ declare global {
1344
2355
  | 'SLICE'
1345
2356
  | 'CONNECTOR'
1346
2357
  | 'SECTION'
2358
+
2359
+
2360
+
2361
+ // d2c
2362
+ type CodeFile = {
2363
+ /**
2364
+ * import third-party paths
2365
+ */
2366
+ importPath?: {
2367
+ name: string;
2368
+ path: string;
2369
+ type: 'script' | 'style';
2370
+ }[];
2371
+ importType?: 'GLOBAL' | 'IMPORT';
2372
+ // absolute path
2373
+ path: string;
2374
+ // relative to the relative path of the imported file
2375
+ relativePath: string;
2376
+ fileName: string;
2377
+ type: 'css' | 'js' | 'typescript' | 'ts-definition' | 'static' | 'vue' | 'react' | 'java' | 'kt' | 'xml';
2378
+ // code
2379
+ code: string;
2380
+ // parsed code
2381
+ parsedCode?: string;
2382
+ // import
2383
+ chunks?: CodeFile[];
2384
+ };
2385
+ interface CodegenAPI {
2386
+ /**
2387
+ * @param event a callback function that is triggered when the plugin generates the DSL, and the parameter of the callback function is the modified DSL data
2388
+ */
2389
+ on(type: 'generateDSL', event: (generateData: {data: MGDSL.MGDSLData, callback: (modifiedData: MGDSL.MGDSLData) => void}) => void) : void
2390
+ /**
2391
+ * @param event a callback function that is triggered when the plugin generates the DSL, and the parameter of the callback function is the custom code, and when the callback returns the custom code, the custom code will be used as the standard, and the code will not be generated according to the DSL
2392
+ */
2393
+ on(type: 'generate', event: (generateData: {data: MGDSL.MGDSLData, callback: (modifiedData: MGDSL.CustomCode) => void}) => void) : void
2394
+ /**
2395
+ * @param event a callback function that is triggered when the plugin generates the code, and the parameter of the callback function is the generated code
2396
+ */
2397
+ on(type: 'codeChange', event: (data: MGDSL.CustomCode['data']) => void) : void
2398
+ /**
2399
+ * Set the component template
2400
+ * @description used to set the component mapping relationship
2401
+ * @param template component template
2402
+ */
2403
+ setComponentTemplate(template: MGTMP.ComponentTemplate): void
2404
+ /**
2405
+ * Get code by id and framework
2406
+ * @param layerId layer id
2407
+ * @param type framework type
2408
+ * @returns code file
2409
+ */
2410
+ getCode(layerId: string, type: MGDSL.Framework): Promise<CodeFile | null>;
2411
+ /**
2412
+ * Get DSL by id and framework
2413
+ * @param layerId layer id
2414
+ * @param type framework type
2415
+ * @returns DSL data
2416
+ */
2417
+ getDSL(layerId: string, type: MGDSL.Framework): Promise<MGDSL.MGDSLData | null>;
2418
+ /**
2419
+ * Get code by DSL
2420
+ * @param data DSL data
2421
+ * @param type framework type
2422
+ * @returns code file
2423
+ */
2424
+ getCodeByDSL(data: MGDSL.MGDSLData, type: MGDSL.Framework): Promise<CodeFile | null>;
2425
+ }
1347
2426
  }
1348
-
1349
- export { }