@mastergo/plugin-typings 2.7.0 → 2.8.0-beta.2
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/README-en.md +2 -0
- package/README.md +2 -0
- package/dist/index.d.ts +176 -12
- package/package.json +1 -1
package/README-en.md
CHANGED
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -999,7 +999,11 @@ declare global {
|
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
1001
|
declare global {
|
|
1002
|
+
/**
|
|
1003
|
+
* @deprecated please use mg instead
|
|
1004
|
+
*/
|
|
1002
1005
|
const mastergo: PluginAPI
|
|
1006
|
+
|
|
1003
1007
|
const mg: PluginAPI
|
|
1004
1008
|
const console: Console
|
|
1005
1009
|
const __html__: string
|
|
@@ -1020,14 +1024,47 @@ declare global {
|
|
|
1020
1024
|
clear(): void
|
|
1021
1025
|
}
|
|
1022
1026
|
|
|
1027
|
+
interface ConfirmAction {
|
|
1028
|
+
label: string
|
|
1029
|
+
type: 'primary' | 'text'
|
|
1030
|
+
action: () => void
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
interface PromptAction {
|
|
1034
|
+
label: string
|
|
1035
|
+
type: 'primary' | 'text'
|
|
1036
|
+
action: (value: string) => void
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1023
1039
|
interface Image {
|
|
1024
1040
|
readonly href: string
|
|
1025
1041
|
getBytesAsync(): Promise<Uint8Array>
|
|
1026
1042
|
}
|
|
1027
1043
|
|
|
1028
|
-
type PluginEventType = 'selectionchange' | 'layoutchange' | 'currentpagechange' | 'close' | 'themechange' | 'drop' | 'run'
|
|
1029
1044
|
type ThemeColor = 'dark' | 'light'
|
|
1030
1045
|
|
|
1046
|
+
type LayoutInfo = {
|
|
1047
|
+
leftbar: number;
|
|
1048
|
+
rightbar: number;
|
|
1049
|
+
canvas: number;
|
|
1050
|
+
window: number;
|
|
1051
|
+
height: number;
|
|
1052
|
+
topbar: number;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
type MGEventCallbackMap = {
|
|
1056
|
+
'selectionchange': (selectionLayerIds: string[]) => void;
|
|
1057
|
+
'layoutchange': (layoutInfo: LayoutInfo) => void;
|
|
1058
|
+
'currentpagechange': (pageId: string) => void;
|
|
1059
|
+
'themechange': (theme: ThemeColor) => void;
|
|
1060
|
+
'drop': (event: DropEvent) => void;
|
|
1061
|
+
'run': (command: { command: string }) => void;
|
|
1062
|
+
'close': () => void;
|
|
1063
|
+
'beforeReadyForDev': (sectionLayerId: string, callback: (setReady: boolean) => void) => void;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
type PluginEventType = keyof MGEventCallbackMap
|
|
1067
|
+
|
|
1031
1068
|
interface PluginAPI {
|
|
1032
1069
|
readonly document: DocumentNode
|
|
1033
1070
|
|
|
@@ -1051,14 +1088,16 @@ declare global {
|
|
|
1051
1088
|
|
|
1052
1089
|
readonly viewport: ViewportAPI
|
|
1053
1090
|
|
|
1054
|
-
|
|
1091
|
+
/**
|
|
1092
|
+
* @note only available in devMode
|
|
1093
|
+
*/
|
|
1055
1094
|
readonly codegen?: CodegenAPI
|
|
1056
1095
|
|
|
1057
1096
|
closePlugin(): void
|
|
1058
1097
|
|
|
1059
|
-
on(type:
|
|
1060
|
-
once(type:
|
|
1061
|
-
off(type?:
|
|
1098
|
+
on<T extends PluginEventType>(type: T, callback: MGEventCallbackMap[T]): void
|
|
1099
|
+
once<T extends PluginEventType>(type: T, callback: MGEventCallbackMap[T]): void
|
|
1100
|
+
off<T extends PluginEventType>(type?: T, callback?: MGEventCallbackMap[T]): void
|
|
1062
1101
|
|
|
1063
1102
|
commitUndo(): void
|
|
1064
1103
|
triggerUndo(): void
|
|
@@ -1105,16 +1144,64 @@ declare global {
|
|
|
1105
1144
|
|
|
1106
1145
|
getStyleById(id: string): Style | null
|
|
1107
1146
|
getTitleByFontFamilyAndStyle(fontFamily: string, fontStyle: string): FontAlias | null
|
|
1147
|
+
|
|
1108
1148
|
createFillStyle(config: CreateStyleConfig): PaintStyle
|
|
1109
|
-
createStrokeStyle(config: CreateStyleConfig): PaintStyle
|
|
1110
1149
|
createEffectStyle(config: CreateStyleConfig): EffectStyle
|
|
1111
1150
|
createTextStyle(config: CreateStyleConfig): TextStyle
|
|
1112
1151
|
createGridStyle(config: CreateStyleConfig): GridStyle
|
|
1152
|
+
createCornerRadiusStyle(config: CreateStyleConfig): CornerRadiusStyle
|
|
1153
|
+
createPaddingStyle(config: CreateStyleConfig): PaddingStyle
|
|
1154
|
+
createSpacingStyle(config: CreateStyleConfig): SpacingStyle
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* @deprecated please use createStrokeFillStyle instead
|
|
1158
|
+
*/
|
|
1159
|
+
createStrokeStyle(config: CreateStyleConfig): PaintStyle
|
|
1160
|
+
createStrokeFillStyle(config: CreateStyleConfig): PaintStyle
|
|
1161
|
+
createStrokeWidthStyle(config: CreateStyleConfig): StrokeWidthStyle
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* createFillStyle/createStrokeFillStyle 这些函数的聚合函数,传入不同的 type,返回对应的 style
|
|
1165
|
+
* @param layerId
|
|
1166
|
+
* @param type NodeStyleType
|
|
1167
|
+
* @param styleName
|
|
1168
|
+
* @param description optional
|
|
1169
|
+
*/
|
|
1170
|
+
createStyleByLayer<T extends NodeStyleType>(layerId: string, type: T, styleName: string, description?: string): NodeStyleReturnType<T>
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* 创建一个新的默认样式,不依赖某一个图层中的样式,
|
|
1174
|
+
* eg: createStyle('PAINT', 'New Style', 'This is a new style')
|
|
1175
|
+
* @param type styleType
|
|
1176
|
+
* @param styleName
|
|
1177
|
+
* @param description optional
|
|
1178
|
+
*/
|
|
1179
|
+
createStyle<T extends StyleType>(type: T, styleName: string, description?: string): StyleReturnType<T>
|
|
1180
|
+
/**
|
|
1181
|
+
* 创建某一个样式的副本
|
|
1182
|
+
* @param sourceStyleId 副本的源样式id
|
|
1183
|
+
* @param type
|
|
1184
|
+
* @param styleName
|
|
1185
|
+
* @param description
|
|
1186
|
+
*/
|
|
1187
|
+
createStyleCopy<T extends StyleType = StyleType>(sourceStyleId: string, type: T, styleName?: string, description?: string): StyleReturnType<T>
|
|
1188
|
+
/**
|
|
1189
|
+
* 创建某一个样式引用
|
|
1190
|
+
* @param sourceStyleId 引用源样式id
|
|
1191
|
+
* @param type
|
|
1192
|
+
* @param styleName
|
|
1193
|
+
* @param description
|
|
1194
|
+
*/
|
|
1195
|
+
createStyleRef<T extends StyleType = StyleType>(sourceStyleId: string, type: T, styleName?: string, description?: string): StyleReturnType<T>
|
|
1113
1196
|
|
|
1114
1197
|
getLocalPaintStyles(): PaintStyle[]
|
|
1115
1198
|
getLocalEffectStyles(): EffectStyle[]
|
|
1116
1199
|
getLocalTextStyles(): TextStyle[]
|
|
1117
1200
|
getLocalGridStyles(): GridStyle[]
|
|
1201
|
+
getLocalStrokeWidthStyles(): StrokeWidthStyle[]
|
|
1202
|
+
getLocalCornerRadiusStyles(): CornerRadiusStyle[]
|
|
1203
|
+
getLocalPaddingStyles(): PaddingStyle[]
|
|
1204
|
+
getLocalSpacingStyles(): SpacingStyle[]
|
|
1118
1205
|
|
|
1119
1206
|
listAvailableFontsAsync(): Promise<Font[]>
|
|
1120
1207
|
loadFontAsync(fontName: FontName): Promise<boolean>
|
|
@@ -1135,6 +1222,9 @@ declare global {
|
|
|
1135
1222
|
|
|
1136
1223
|
hexToRGBA(hex: string): RGBA
|
|
1137
1224
|
RGBAToHex(rgba: RGBA): string
|
|
1225
|
+
|
|
1226
|
+
confirm: (message: string, options: [ConfirmAction, ...ConfirmAction[]]) => void
|
|
1227
|
+
prompt: (message: string, defaultValue: string, options: [PromptAction, ...PromptAction[]]) => void
|
|
1138
1228
|
}
|
|
1139
1229
|
|
|
1140
1230
|
interface User {
|
|
@@ -1256,19 +1346,23 @@ declare global {
|
|
|
1256
1346
|
description: string
|
|
1257
1347
|
documentationLinks: ReadonlyArray<DocumentationLink>
|
|
1258
1348
|
/**
|
|
1259
|
-
*
|
|
1260
|
-
|
|
1349
|
+
* @description 组件或者组件集的别名
|
|
1350
|
+
*/
|
|
1351
|
+
alias: string
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* @description 是否为团队库组件/样式
|
|
1355
|
+
*/
|
|
1261
1356
|
readonly isExternal: boolean
|
|
1262
1357
|
readonly ukey: string
|
|
1263
1358
|
readonly publishStatus: PublishStatus
|
|
1264
1359
|
}
|
|
1265
1360
|
|
|
1266
|
-
/// /////////////////////////////////////////////////////////////////////////////
|
|
1267
1361
|
// Styles
|
|
1362
|
+
type StyleType = 'PAINT' | 'TEXT' | 'EFFECT' | 'GRID' | 'STROKE_WIDTH' | 'CORNER_RADIUS' | 'PADDING' | 'SPACING'
|
|
1363
|
+
type NodeStyleType = 'fill' | 'strokeFill' | 'strokeWidth' | 'cornerRadius' | 'padding' | 'spacing'
|
|
1268
1364
|
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
interface BaseStyle extends Omit<PublishableMixin, 'documentationLinks'> {
|
|
1365
|
+
interface BaseStyle extends Omit<PublishableMixin, 'documentationLinks' | 'alias'> {
|
|
1272
1366
|
readonly id: string
|
|
1273
1367
|
readonly type: StyleType
|
|
1274
1368
|
name: string
|
|
@@ -1280,6 +1374,26 @@ declare global {
|
|
|
1280
1374
|
paints: ReadonlyArray<Paint>
|
|
1281
1375
|
}
|
|
1282
1376
|
|
|
1377
|
+
interface StrokeWidthStyle extends BaseStyle {
|
|
1378
|
+
type: 'STROKE_WIDTH'
|
|
1379
|
+
value: StrokeWidth
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
interface CornerRadiusStyle extends BaseStyle {
|
|
1383
|
+
type: 'CORNER_RADIUS'
|
|
1384
|
+
value: CornerRadius
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
interface PaddingStyle extends BaseStyle {
|
|
1388
|
+
type: 'PADDING'
|
|
1389
|
+
value: Padding
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
interface SpacingStyle extends BaseStyle {
|
|
1393
|
+
type: 'SPACING'
|
|
1394
|
+
value: Spacing
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1283
1397
|
interface NumValue {
|
|
1284
1398
|
value: number
|
|
1285
1399
|
unit: 'PIXELS' | 'PERCENT'
|
|
@@ -1463,6 +1577,24 @@ declare global {
|
|
|
1463
1577
|
|
|
1464
1578
|
type Paint = SolidPaint | GradientPaint | ImagePaint
|
|
1465
1579
|
|
|
1580
|
+
type CSSWidthSetter = number | [number, number] | [number, number, number] | [number, number, number, number]
|
|
1581
|
+
|
|
1582
|
+
interface StrokeWidth {
|
|
1583
|
+
width: CSSWidthSetter,
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
interface Padding {
|
|
1587
|
+
padding: CSSWidthSetter,
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
interface Spacing {
|
|
1591
|
+
spacing: CSSWidthSetter,
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
interface CornerRadius {
|
|
1595
|
+
cornerRadius: CSSWidthSetter,
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1466
1598
|
type WindingRule = 'Nonzero' | 'Evenodd'
|
|
1467
1599
|
|
|
1468
1600
|
// 待确定
|
|
@@ -1658,7 +1790,17 @@ declare global {
|
|
|
1658
1790
|
dashCap: DashCap
|
|
1659
1791
|
strokeDashes: ReadonlyArray<number>
|
|
1660
1792
|
fillStyleId: string
|
|
1793
|
+
/**
|
|
1794
|
+
* @deprecated please use strokePaintStyleId instead
|
|
1795
|
+
*/
|
|
1661
1796
|
strokeStyleId: string
|
|
1797
|
+
strokeFillStyleId: string
|
|
1798
|
+
strokeWidthStyleId: string
|
|
1799
|
+
borderStyleId: string
|
|
1800
|
+
paddingStyleId: string
|
|
1801
|
+
spacingStyleId: string
|
|
1802
|
+
cornerRadiusStyleId: string
|
|
1803
|
+
|
|
1662
1804
|
/**
|
|
1663
1805
|
* You have to ensure the layer has stroke before invoking this method.
|
|
1664
1806
|
* 在调用接口之前需要确保layer有描边.
|
|
@@ -2310,6 +2452,10 @@ declare global {
|
|
|
2310
2452
|
effects: ReadonlyArray<TeamLibraryStyle>
|
|
2311
2453
|
texts: ReadonlyArray<TeamLibraryStyle>
|
|
2312
2454
|
grids: ReadonlyArray<TeamLibraryStyle>
|
|
2455
|
+
strokeWidths: ReadonlyArray<TeamLibraryStyle>
|
|
2456
|
+
cornerRadiuses: ReadonlyArray<TeamLibraryStyle>
|
|
2457
|
+
paddings: ReadonlyArray<TeamLibraryStyle>
|
|
2458
|
+
spacings: ReadonlyArray<TeamLibraryStyle>
|
|
2313
2459
|
}
|
|
2314
2460
|
}>
|
|
2315
2461
|
|
|
@@ -2423,4 +2569,22 @@ declare global {
|
|
|
2423
2569
|
*/
|
|
2424
2570
|
getCodeByDSL(data: MGDSL.MGDSLData, type: MGDSL.Framework): Promise<CodeFile | null>;
|
|
2425
2571
|
}
|
|
2572
|
+
|
|
2573
|
+
type StyleReturnType<T extends StyleType> =
|
|
2574
|
+
T extends 'PAINT' ? PaintStyle :
|
|
2575
|
+
T extends 'TEXT' ? TextStyle :
|
|
2576
|
+
T extends 'EFFECT' ? EffectStyle :
|
|
2577
|
+
T extends 'GRID' ? GridStyle :
|
|
2578
|
+
T extends 'STROKE_WIDTH' ? StrokeWidthStyle :
|
|
2579
|
+
T extends 'CORNER_RADIUS' ? CornerRadiusStyle :
|
|
2580
|
+
T extends 'PADDING' ? PaddingStyle :
|
|
2581
|
+
T extends 'SPACING' ? SpacingStyle : never
|
|
2582
|
+
|
|
2583
|
+
type NodeStyleReturnType<T extends NodeStyleType> =
|
|
2584
|
+
T extends 'fill' ? PaintStyle :
|
|
2585
|
+
T extends 'strokeFill' ? PaintStyle :
|
|
2586
|
+
T extends 'strokeWidth' ? StrokeWidthStyle :
|
|
2587
|
+
T extends 'cornerRadius' ? CornerRadiusStyle :
|
|
2588
|
+
T extends 'padding' ? PaddingStyle :
|
|
2589
|
+
T extends 'spacing' ? SpacingStyle : never
|
|
2426
2590
|
}
|