@maaxyz/maa-node 4.4.0-beta.2 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,17 @@
1
1
  import type { FlatRect } from './maa';
2
2
  type NodeName = string;
3
- type OutputRemove<T, Output> = Output extends true ? never : T;
4
- type MaybeArray<T, Output> = T[] | OutputRemove<T, Output>;
3
+ export type ModeFragment = 0;
4
+ export type ModeStrict = 1;
5
+ export type ModeDump = 2;
6
+ type RemoveIfDump<T, Mode> = Mode extends ModeDump ? never : T;
7
+ type MaybeArray<T, Mode> = T[] | RemoveIfDump<T, Mode>;
5
8
  type FixedArray<T, K extends number, A extends T[] = []> = A['length'] extends K ? A : FixedArray<T, K, [...A, T]>;
9
+ type RequiredIfStrict<T, Keys, Mode> = Mode extends ModeStrict ? RequiredKeys<T, Keys> : T;
10
+ type RequiredKeys<T, Keys> = {
11
+ [key in keyof T & Keys]: NonNullable<T[key]>;
12
+ } & {
13
+ [key in Exclude<keyof T, Keys>]: T[key];
14
+ };
6
15
  type OrderByMap = {
7
16
  TemplateMatch: 'Horizontal' | 'Vertical' | 'Score' | 'Random';
8
17
  FeatureMatch: 'Horizontal' | 'Vertical' | 'Score' | 'Area' | 'Random';
@@ -12,96 +21,94 @@ type OrderByMap = {
12
21
  NeuralNetworkDetect: 'Horizontal' | 'Vertical' | 'Score' | 'Area' | 'Random';
13
22
  };
14
23
  export type RecognitionDirectHit = {};
15
- export type RecognitionTemplateMatch<Output> = {
24
+ export type RecognitionTemplateMatch<Mode> = RequiredIfStrict<{
16
25
  roi?: FlatRect | NodeName;
17
26
  roi_offset?: FlatRect;
18
- template?: MaybeArray<string, Output>;
19
- template_?: MaybeArray<string, Output>;
20
- threshold?: MaybeArray<number, Output>;
27
+ template?: MaybeArray<string, Mode>;
28
+ threshold?: MaybeArray<number, Mode>;
21
29
  order_by?: OrderByMap['TemplateMatch'];
22
30
  index?: number;
23
31
  method?: 1 | 3 | 5;
24
32
  green_mask?: boolean;
25
- };
26
- export type RecognitionFeatureMatch<Output> = {
33
+ }, 'template', Mode>;
34
+ export type RecognitionFeatureMatch<Mode> = RequiredIfStrict<{
27
35
  roi?: FlatRect | NodeName;
28
36
  roi_offset?: FlatRect;
29
- template?: MaybeArray<string, Output>;
30
- template_?: MaybeArray<string, Output>;
37
+ template?: MaybeArray<string, Mode>;
31
38
  count?: number;
32
39
  order_by?: OrderByMap['FeatureMatch'];
33
40
  index?: number;
34
41
  green_mask?: boolean;
35
42
  detector?: 'SIFT' | 'KAZE' | 'AKAZE' | 'BRISK' | 'ORB';
36
43
  ratio?: number;
37
- };
38
- export type RecognitionColorMatch<Output> = {
44
+ }, 'template', Mode>;
45
+ export type RecognitionColorMatch<Mode> = {
39
46
  roi?: FlatRect | NodeName;
40
47
  roi_offset?: FlatRect;
41
- } & ({
48
+ } & RequiredIfStrict<{
42
49
  method?: 4 | 40;
43
- lower?: MaybeArray<FixedArray<number, 3>, Output>;
44
- upper?: MaybeArray<FixedArray<number, 3>, Output>;
50
+ lower?: MaybeArray<FixedArray<number, 3>, Mode>;
51
+ upper?: MaybeArray<FixedArray<number, 3>, Mode>;
45
52
  } | {
46
53
  method: 6;
47
- lower?: MaybeArray<FixedArray<number, 1>, Output>;
48
- upper?: MaybeArray<FixedArray<number, 1>, Output>;
49
- }) & {
54
+ lower?: MaybeArray<FixedArray<number, 1>, Mode>;
55
+ upper?: MaybeArray<FixedArray<number, 1>, Mode>;
56
+ }, 'lower' | 'upper', Mode> & {
50
57
  count?: number;
51
58
  order_by?: OrderByMap['ColorMatch'];
52
59
  index?: number;
53
60
  connected?: boolean;
54
61
  };
55
- export type RecognitionOCR<Output> = {
62
+ export type RecognitionOCR<Mode> = RequiredIfStrict<{
56
63
  roi?: FlatRect | NodeName;
57
64
  roi_offset?: FlatRect;
58
- expected?: MaybeArray<string, Output>;
59
- threshold?: MaybeArray<number, Output>;
60
- replace?: MaybeArray<FixedArray<string, 2>, Output>;
65
+ expected?: MaybeArray<string, Mode>;
66
+ threshold?: MaybeArray<number, Mode>;
67
+ replace?: MaybeArray<FixedArray<string, 2>, Mode>;
61
68
  order_by?: OrderByMap['OCR'];
62
69
  index?: number;
63
70
  only_rec?: boolean;
64
71
  model?: string;
65
- };
66
- export type RecognitionNeuralNetworkClassify<Output> = {
72
+ }, 'expected', Mode>;
73
+ export type RecognitionNeuralNetworkClassify<Mode> = RequiredIfStrict<{
67
74
  roi?: FlatRect | NodeName;
68
75
  roi_offset?: FlatRect;
69
76
  labels?: string[];
70
77
  model?: string;
71
- expected?: MaybeArray<number, Output>;
78
+ expected?: MaybeArray<number, Mode>;
72
79
  order_by?: OrderByMap['NeuralNetworkClassify'];
73
80
  index?: number;
74
- };
75
- export type RecognitionNeuralNetworkDetect<Output> = {
81
+ }, 'model', Mode>;
82
+ export type RecognitionNeuralNetworkDetect<Mode> = RequiredIfStrict<{
76
83
  roi?: FlatRect | NodeName;
77
84
  roi_offset?: FlatRect;
78
85
  labels?: string[];
79
86
  model?: string;
80
- expected?: MaybeArray<number, Output>;
87
+ expected?: MaybeArray<number, Mode>;
81
88
  threshold?: number;
82
89
  order_by?: OrderByMap['NeuralNetworkDetect'];
83
90
  index?: number;
84
- };
85
- export type RecognitionCustom = {
91
+ }, 'model', Mode>;
92
+ export type RecognitionCustom<Mode> = RequiredIfStrict<{
86
93
  roi?: FlatRect | NodeName;
87
94
  roi_offset?: FlatRect;
88
95
  custom_recognition?: string;
89
96
  custom_recognition_param?: unknown;
90
- };
91
- type MixReco<Type extends string, Param, Output> = {
97
+ }, 'custom_recognition', Mode>;
98
+ type MixReco<Type extends string, Param, Mode> = {
92
99
  recognition: {
93
100
  type: Type;
94
101
  param?: Param;
95
102
  };
96
- } | OutputRemove<{
103
+ } | RemoveIfDump<{
97
104
  recognition: Type;
98
- } & Param, Output>;
99
- export type Recognition<Output> = OutputRemove<{
105
+ } & Param, Mode>;
106
+ export type Recognition<Mode> = RemoveIfDump<{
100
107
  recognition?: {
101
108
  type?: never;
102
109
  param?: never;
103
110
  };
104
- }, Output> | MixReco<'DirectHit', RecognitionDirectHit, Output> | MixReco<'TemplateMatch', RecognitionTemplateMatch<Output>, Output> | MixReco<'FeatureMatch', RecognitionFeatureMatch<Output>, Output> | MixReco<'ColorMatch', RecognitionColorMatch<Output>, Output> | MixReco<'OCR', RecognitionOCR<Output>, Output> | MixReco<'NeuralNetworkClassify', RecognitionNeuralNetworkClassify<Output>, Output> | MixReco<'NeuralNetworkDetect', RecognitionNeuralNetworkDetect<Output>, Output> | MixReco<'Custom', RecognitionCustom, Output>;
111
+ }, Mode> | MixReco<'DirectHit', RecognitionDirectHit, Mode> | MixReco<'TemplateMatch', RecognitionTemplateMatch<Mode>, Mode> | MixReco<'FeatureMatch', RecognitionFeatureMatch<Mode>, Mode> | MixReco<'ColorMatch', RecognitionColorMatch<Mode>, Mode> | MixReco<'OCR', RecognitionOCR<Mode>, Mode> | MixReco<'NeuralNetworkClassify', RecognitionNeuralNetworkClassify<Mode>, Mode> | MixReco<'NeuralNetworkDetect', RecognitionNeuralNetworkDetect<Mode>, Mode> | MixReco<'Custom', RecognitionCustom<Mode>, Mode>;
105
112
  export type ActionDoNothing = {};
106
113
  export type ActionClick = {
107
114
  target?: true | NodeName | FlatRect;
@@ -119,7 +126,7 @@ export type ActionSwipe = {
119
126
  end_offset?: FlatRect;
120
127
  duration?: number;
121
128
  };
122
- export type ActionMultiSwipe = {
129
+ export type ActionMultiSwipe<Mode> = RequiredIfStrict<{
123
130
  swipes?: {
124
131
  starting?: number;
125
132
  begin?: true | NodeName | FlatRect;
@@ -128,45 +135,45 @@ export type ActionMultiSwipe = {
128
135
  end_offset?: FlatRect;
129
136
  duration?: number;
130
137
  }[];
131
- };
132
- export type ActionKey<Output> = {
133
- key?: MaybeArray<number, Output>;
134
- };
135
- export type ActionInputText = {
138
+ }, 'swipes', Mode>;
139
+ export type ActionKey<Mode> = RequiredIfStrict<{
140
+ key?: MaybeArray<number, Mode>;
141
+ }, 'key', Mode>;
142
+ export type ActionInputText<Mode> = RequiredIfStrict<{
136
143
  input_text?: string;
137
- };
138
- export type ActionStartApp = {
144
+ }, 'input_text', Mode>;
145
+ export type ActionStartApp<Mode> = RequiredIfStrict<{
139
146
  package?: string;
140
- };
141
- export type ActionStopApp = {
147
+ }, 'package', Mode>;
148
+ export type ActionStopApp<Mode> = RequiredIfStrict<{
142
149
  package?: string;
143
- };
150
+ }, 'package', Mode>;
144
151
  export type ActionStopTask = {};
145
- export type ActionCommand = {
152
+ export type ActionCommand<Mode> = RequiredIfStrict<{
146
153
  exec?: string;
147
154
  args?: string[];
148
155
  detach?: boolean;
149
- };
150
- export type ActionCustom = {
156
+ }, 'exec', Mode>;
157
+ export type ActionCustom<Mode> = RequiredIfStrict<{
151
158
  target?: true | NodeName | FlatRect;
152
159
  target_offset?: FlatRect;
153
160
  custom_action?: string;
154
161
  custom_action_param?: unknown;
155
- };
156
- type MixAct<Type extends string, Param, Output> = OutputRemove<{
162
+ }, 'custom_action', Mode>;
163
+ type MixAct<Type extends string, Param, Mode> = RemoveIfDump<{
157
164
  action: Type;
158
- } & Param, Output> | {
165
+ } & Param, Mode> | {
159
166
  action: {
160
167
  type: Type;
161
168
  param?: Param;
162
169
  };
163
170
  };
164
- export type Action<Output> = OutputRemove<{
171
+ export type Action<Mode> = RemoveIfDump<{
165
172
  action?: {
166
173
  type?: never;
167
174
  param?: never;
168
175
  };
169
- }, Output> | MixAct<'DoNothing', ActionDoNothing, Output> | MixAct<'Click', ActionClick, Output> | MixAct<'LongPress', ActionLongPress, Output> | MixAct<'Swipe', ActionSwipe, Output> | MixAct<'MultiSwipe', ActionMultiSwipe, Output> | MixAct<'Key', ActionKey<Output>, Output> | MixAct<'InputText', ActionInputText, Output> | MixAct<'StartApp', ActionStartApp, Output> | MixAct<'StopApp', ActionStopApp, Output> | MixAct<'StopTask', ActionStopTask, Output> | MixAct<'Command', ActionCommand, Output> | MixAct<'Custom', ActionCustom, Output>;
176
+ }, Mode> | MixAct<'DoNothing', ActionDoNothing, Mode> | MixAct<'Click', ActionClick, Mode> | MixAct<'LongPress', ActionLongPress, Mode> | MixAct<'Swipe', ActionSwipe, Mode> | MixAct<'MultiSwipe', ActionMultiSwipe<Mode>, Mode> | MixAct<'Key', ActionKey<Mode>, Mode> | MixAct<'InputText', ActionInputText<Mode>, Mode> | MixAct<'StartApp', ActionStartApp<Mode>, Mode> | MixAct<'StopApp', ActionStopApp<Mode>, Mode> | MixAct<'StopTask', ActionStopTask, Mode> | MixAct<'Command', ActionCommand<Mode>, Mode> | MixAct<'Custom', ActionCustom<Mode>, Mode>;
170
177
  export type WaitFreeze = {
171
178
  time?: number;
172
179
  target?: true | NodeName | FlatRect;
@@ -176,24 +183,25 @@ export type WaitFreeze = {
176
183
  rate_limit?: number;
177
184
  timeout?: number;
178
185
  };
179
- export type General<Output> = {
180
- next?: MaybeArray<NodeName, Output>;
181
- interrupt?: MaybeArray<NodeName, Output>;
186
+ export type General<Mode> = {
187
+ next?: MaybeArray<NodeName, Mode>;
188
+ interrupt?: MaybeArray<NodeName, Mode>;
182
189
  is_sub?: boolean;
183
190
  rate_limit?: number;
184
191
  timeout?: number;
185
- on_error?: MaybeArray<string, Output>;
192
+ on_error?: MaybeArray<string, Mode>;
186
193
  inverse?: boolean;
187
194
  enabled?: boolean;
188
195
  pre_delay?: boolean;
189
196
  post_delay?: boolean;
190
- pre_wait_freezes?: OutputRemove<number, Output> | WaitFreeze;
191
- post_wait_freezes?: OutputRemove<number, Output> | WaitFreeze;
197
+ pre_wait_freezes?: RemoveIfDump<number, Mode> | WaitFreeze;
198
+ post_wait_freezes?: RemoveIfDump<number, Mode> | WaitFreeze;
192
199
  focus?: unknown;
193
200
  };
194
- export type Task = Recognition<false> & Action<false> & General<false>;
201
+ export type Task = Recognition<ModeFragment> & Action<ModeFragment> & General<ModeFragment>;
202
+ export type StrictTask = Recognition<ModeStrict> & Action<ModeStrict> & General<ModeStrict>;
195
203
  type RecursiveRequired<T> = T extends Record<string, unknown> ? {
196
- [key in keyof T]-?: RecursiveRequired<T[key]>;
204
+ [key in keyof T]: NonNullable<RecursiveRequired<T[key]>>;
197
205
  } : T;
198
- export type DumpTask = RecursiveRequired<Recognition<true> & Action<true> & General<true>>;
206
+ export type DumpTask = RecursiveRequired<Recognition<ModeDump> & Action<ModeDump> & General<ModeDump>>;
199
207
  export {};
package/package.json CHANGED
@@ -25,13 +25,13 @@
25
25
  "prettier": "^3.5.2",
26
26
  "typescript": "^5.8.2"
27
27
  },
28
- "version": "4.4.0-beta.2",
28
+ "version": "4.4.0",
29
29
  "optionalDependencies": {
30
- "@maaxyz/maa-node-darwin-arm64": "4.4.0-beta.2",
31
- "@maaxyz/maa-node-darwin-x64": "4.4.0-beta.2",
32
- "@maaxyz/maa-node-linux-arm64": "4.4.0-beta.2",
33
- "@maaxyz/maa-node-linux-x64": "4.4.0-beta.2",
34
- "@maaxyz/maa-node-win32-arm64": "4.4.0-beta.2",
35
- "@maaxyz/maa-node-win32-x64": "4.4.0-beta.2"
30
+ "@maaxyz/maa-node-darwin-arm64": "4.4.0",
31
+ "@maaxyz/maa-node-darwin-x64": "4.4.0",
32
+ "@maaxyz/maa-node-linux-arm64": "4.4.0",
33
+ "@maaxyz/maa-node-linux-x64": "4.4.0",
34
+ "@maaxyz/maa-node-win32-arm64": "4.4.0",
35
+ "@maaxyz/maa-node-win32-x64": "4.4.0"
36
36
  }
37
37
  }
package/src/pipeline.ts CHANGED
@@ -2,11 +2,21 @@ import type { FlatRect } from './maa'
2
2
 
3
3
  type NodeName = string
4
4
 
5
- type OutputRemove<T, Output> = Output extends true ? never : T
6
- type MaybeArray<T, Output> = T[] | OutputRemove<T, Output>
5
+ export type ModeFragment = 0
6
+ export type ModeStrict = 1
7
+ export type ModeDump = 2
8
+
9
+ type RemoveIfDump<T, Mode> = Mode extends ModeDump ? never : T
10
+ type MaybeArray<T, Mode> = T[] | RemoveIfDump<T, Mode>
7
11
  type FixedArray<T, K extends number, A extends T[] = []> = A['length'] extends K
8
12
  ? A
9
13
  : FixedArray<T, K, [...A, T]>
14
+ type RequiredIfStrict<T, Keys, Mode> = Mode extends ModeStrict ? RequiredKeys<T, Keys> : T
15
+ type RequiredKeys<T, Keys> = {
16
+ [key in keyof T & Keys]: NonNullable<T[key]>
17
+ } & {
18
+ [key in Exclude<keyof T, Keys>]: T[key]
19
+ }
10
20
 
11
21
  type OrderByMap = {
12
22
  TemplateMatch: 'Horizontal' | 'Vertical' | 'Score' | 'Random'
@@ -19,124 +29,148 @@ type OrderByMap = {
19
29
 
20
30
  export type RecognitionDirectHit = {}
21
31
 
22
- export type RecognitionTemplateMatch<Output> = {
23
- roi?: FlatRect | NodeName
24
- roi_offset?: FlatRect
25
- template?: MaybeArray<string, Output>
26
- template_?: MaybeArray<string, Output> // 玛丽玛不想写, 所以多了个键
27
- threshold?: MaybeArray<number, Output>
28
- order_by?: OrderByMap['TemplateMatch']
29
- index?: number
30
- method?: 1 | 3 | 5
31
- green_mask?: boolean
32
- }
33
-
34
- export type RecognitionFeatureMatch<Output> = {
35
- roi?: FlatRect | NodeName
36
- roi_offset?: FlatRect
37
- template?: MaybeArray<string, Output>
38
- template_?: MaybeArray<string, Output>
39
- count?: number
40
- order_by?: OrderByMap['FeatureMatch']
41
- index?: number
42
- green_mask?: boolean
43
- detector?: 'SIFT' | 'KAZE' | 'AKAZE' | 'BRISK' | 'ORB'
44
- ratio?: number
45
- }
46
-
47
- export type RecognitionColorMatch<Output> = {
32
+ export type RecognitionTemplateMatch<Mode> = RequiredIfStrict<
33
+ {
34
+ roi?: FlatRect | NodeName
35
+ roi_offset?: FlatRect
36
+ template?: MaybeArray<string, Mode>
37
+ threshold?: MaybeArray<number, Mode>
38
+ order_by?: OrderByMap['TemplateMatch']
39
+ index?: number
40
+ method?: 1 | 3 | 5
41
+ green_mask?: boolean
42
+ },
43
+ 'template',
44
+ Mode
45
+ >
46
+
47
+ export type RecognitionFeatureMatch<Mode> = RequiredIfStrict<
48
+ {
49
+ roi?: FlatRect | NodeName
50
+ roi_offset?: FlatRect
51
+ template?: MaybeArray<string, Mode>
52
+ count?: number
53
+ order_by?: OrderByMap['FeatureMatch']
54
+ index?: number
55
+ green_mask?: boolean
56
+ detector?: 'SIFT' | 'KAZE' | 'AKAZE' | 'BRISK' | 'ORB'
57
+ ratio?: number
58
+ },
59
+ 'template',
60
+ Mode
61
+ >
62
+
63
+ export type RecognitionColorMatch<Mode> = {
48
64
  roi?: FlatRect | NodeName
49
65
  roi_offset?: FlatRect
50
- } & (
66
+ } & RequiredIfStrict<
51
67
  | {
52
68
  method?: 4 | 40
53
- lower?: MaybeArray<FixedArray<number, 3>, Output>
54
- upper?: MaybeArray<FixedArray<number, 3>, Output>
69
+ lower?: MaybeArray<FixedArray<number, 3>, Mode>
70
+ upper?: MaybeArray<FixedArray<number, 3>, Mode>
55
71
  }
56
72
  | {
57
73
  method: 6
58
- lower?: MaybeArray<FixedArray<number, 1>, Output>
59
- upper?: MaybeArray<FixedArray<number, 1>, Output>
60
- }
61
- ) & {
74
+ lower?: MaybeArray<FixedArray<number, 1>, Mode>
75
+ upper?: MaybeArray<FixedArray<number, 1>, Mode>
76
+ },
77
+ 'lower' | 'upper',
78
+ Mode
79
+ > & {
62
80
  count?: number
63
81
  order_by?: OrderByMap['ColorMatch']
64
82
  index?: number
65
83
  connected?: boolean
66
84
  }
67
85
 
68
- export type RecognitionOCR<Output> = {
69
- roi?: FlatRect | NodeName
70
- roi_offset?: FlatRect
71
- expected?: MaybeArray<string, Output>
72
- threshold?: MaybeArray<number, Output>
73
- replace?: MaybeArray<FixedArray<string, 2>, Output>
74
- order_by?: OrderByMap['OCR']
75
- index?: number
76
- only_rec?: boolean
77
- model?: string
78
- }
79
-
80
- export type RecognitionNeuralNetworkClassify<Output> = {
81
- roi?: FlatRect | NodeName
82
- roi_offset?: FlatRect
83
- labels?: string[]
84
- model?: string
85
- expected?: MaybeArray<number, Output>
86
- order_by?: OrderByMap['NeuralNetworkClassify']
87
- index?: number
88
- }
89
-
90
- export type RecognitionNeuralNetworkDetect<Output> = {
91
- roi?: FlatRect | NodeName
92
- roi_offset?: FlatRect
93
- labels?: string[]
94
- model?: string
95
- expected?: MaybeArray<number, Output>
96
- threshold?: number
97
- order_by?: OrderByMap['NeuralNetworkDetect']
98
- index?: number
99
- }
100
-
101
- export type RecognitionCustom = {
102
- roi?: FlatRect | NodeName
103
- roi_offset?: FlatRect
104
- custom_recognition?: string
105
- custom_recognition_param?: unknown
106
- }
107
-
108
- type MixReco<Type extends string, Param, Output> =
86
+ export type RecognitionOCR<Mode> = RequiredIfStrict<
87
+ {
88
+ roi?: FlatRect | NodeName
89
+ roi_offset?: FlatRect
90
+ expected?: MaybeArray<string, Mode>
91
+ threshold?: MaybeArray<number, Mode>
92
+ replace?: MaybeArray<FixedArray<string, 2>, Mode>
93
+ order_by?: OrderByMap['OCR']
94
+ index?: number
95
+ only_rec?: boolean
96
+ model?: string
97
+ },
98
+ 'expected',
99
+ Mode
100
+ >
101
+
102
+ export type RecognitionNeuralNetworkClassify<Mode> = RequiredIfStrict<
103
+ {
104
+ roi?: FlatRect | NodeName
105
+ roi_offset?: FlatRect
106
+ labels?: string[]
107
+ model?: string
108
+ expected?: MaybeArray<number, Mode>
109
+ order_by?: OrderByMap['NeuralNetworkClassify']
110
+ index?: number
111
+ },
112
+ 'model',
113
+ Mode
114
+ >
115
+
116
+ export type RecognitionNeuralNetworkDetect<Mode> = RequiredIfStrict<
117
+ {
118
+ roi?: FlatRect | NodeName
119
+ roi_offset?: FlatRect
120
+ labels?: string[]
121
+ model?: string
122
+ expected?: MaybeArray<number, Mode>
123
+ threshold?: number
124
+ order_by?: OrderByMap['NeuralNetworkDetect']
125
+ index?: number
126
+ },
127
+ 'model',
128
+ Mode
129
+ >
130
+
131
+ export type RecognitionCustom<Mode> = RequiredIfStrict<
132
+ {
133
+ roi?: FlatRect | NodeName
134
+ roi_offset?: FlatRect
135
+ custom_recognition?: string
136
+ custom_recognition_param?: unknown
137
+ },
138
+ 'custom_recognition',
139
+ Mode
140
+ >
141
+
142
+ type MixReco<Type extends string, Param, Mode> =
109
143
  | {
110
144
  recognition: {
111
145
  type: Type
112
146
  param?: Param
113
147
  }
114
148
  }
115
- | OutputRemove<
149
+ | RemoveIfDump<
116
150
  {
117
151
  recognition: Type
118
152
  } & Param,
119
- Output
153
+ Mode
120
154
  >
121
155
 
122
- export type Recognition<Output> =
123
- | OutputRemove<
156
+ export type Recognition<Mode> =
157
+ | RemoveIfDump<
124
158
  {
125
159
  recognition?: {
126
160
  type?: never
127
161
  param?: never
128
162
  }
129
163
  },
130
- Output
164
+ Mode
131
165
  >
132
- | MixReco<'DirectHit', RecognitionDirectHit, Output>
133
- | MixReco<'TemplateMatch', RecognitionTemplateMatch<Output>, Output>
134
- | MixReco<'FeatureMatch', RecognitionFeatureMatch<Output>, Output>
135
- | MixReco<'ColorMatch', RecognitionColorMatch<Output>, Output>
136
- | MixReco<'OCR', RecognitionOCR<Output>, Output>
137
- | MixReco<'NeuralNetworkClassify', RecognitionNeuralNetworkClassify<Output>, Output>
138
- | MixReco<'NeuralNetworkDetect', RecognitionNeuralNetworkDetect<Output>, Output>
139
- | MixReco<'Custom', RecognitionCustom, Output>
166
+ | MixReco<'DirectHit', RecognitionDirectHit, Mode>
167
+ | MixReco<'TemplateMatch', RecognitionTemplateMatch<Mode>, Mode>
168
+ | MixReco<'FeatureMatch', RecognitionFeatureMatch<Mode>, Mode>
169
+ | MixReco<'ColorMatch', RecognitionColorMatch<Mode>, Mode>
170
+ | MixReco<'OCR', RecognitionOCR<Mode>, Mode>
171
+ | MixReco<'NeuralNetworkClassify', RecognitionNeuralNetworkClassify<Mode>, Mode>
172
+ | MixReco<'NeuralNetworkDetect', RecognitionNeuralNetworkDetect<Mode>, Mode>
173
+ | MixReco<'Custom', RecognitionCustom<Mode>, Mode>
140
174
 
141
175
  export type ActionDoNothing = {}
142
176
 
@@ -159,54 +193,82 @@ export type ActionSwipe = {
159
193
  duration?: number
160
194
  }
161
195
 
162
- export type ActionMultiSwipe = {
163
- swipes?: {
164
- starting?: number
165
- begin?: true | NodeName | FlatRect
166
- begin_offset?: FlatRect
167
- end?: true | NodeName | FlatRect
168
- end_offset?: FlatRect
169
- duration?: number
170
- }[]
171
- }
172
-
173
- export type ActionKey<Output> = {
174
- key?: MaybeArray<number, Output>
175
- }
176
-
177
- export type ActionInputText = {
178
- input_text?: string
179
- }
180
-
181
- export type ActionStartApp = {
182
- package?: string
183
- }
184
-
185
- export type ActionStopApp = {
186
- package?: string
187
- }
196
+ export type ActionMultiSwipe<Mode> = RequiredIfStrict<
197
+ {
198
+ swipes?: {
199
+ starting?: number
200
+ begin?: true | NodeName | FlatRect
201
+ begin_offset?: FlatRect
202
+ end?: true | NodeName | FlatRect
203
+ end_offset?: FlatRect
204
+ duration?: number
205
+ }[]
206
+ },
207
+ 'swipes',
208
+ Mode
209
+ >
210
+
211
+ export type ActionKey<Mode> = RequiredIfStrict<
212
+ {
213
+ key?: MaybeArray<number, Mode>
214
+ },
215
+ 'key',
216
+ Mode
217
+ >
218
+
219
+ export type ActionInputText<Mode> = RequiredIfStrict<
220
+ {
221
+ input_text?: string
222
+ },
223
+ 'input_text',
224
+ Mode
225
+ >
226
+
227
+ export type ActionStartApp<Mode> = RequiredIfStrict<
228
+ {
229
+ package?: string
230
+ },
231
+ 'package',
232
+ Mode
233
+ >
234
+
235
+ export type ActionStopApp<Mode> = RequiredIfStrict<
236
+ {
237
+ package?: string
238
+ },
239
+ 'package',
240
+ Mode
241
+ >
188
242
 
189
243
  export type ActionStopTask = {}
190
244
 
191
- export type ActionCommand = {
192
- exec?: string
193
- args?: string[]
194
- detach?: boolean
195
- }
196
-
197
- export type ActionCustom = {
198
- target?: true | NodeName | FlatRect
199
- target_offset?: FlatRect
200
- custom_action?: string
201
- custom_action_param?: unknown
202
- }
203
-
204
- type MixAct<Type extends string, Param, Output> =
205
- | OutputRemove<
245
+ export type ActionCommand<Mode> = RequiredIfStrict<
246
+ {
247
+ exec?: string
248
+ args?: string[]
249
+ detach?: boolean
250
+ },
251
+ 'exec',
252
+ Mode
253
+ >
254
+
255
+ export type ActionCustom<Mode> = RequiredIfStrict<
256
+ {
257
+ target?: true | NodeName | FlatRect
258
+ target_offset?: FlatRect
259
+ custom_action?: string
260
+ custom_action_param?: unknown
261
+ },
262
+ 'custom_action',
263
+ Mode
264
+ >
265
+
266
+ type MixAct<Type extends string, Param, Mode> =
267
+ | RemoveIfDump<
206
268
  {
207
269
  action: Type
208
270
  } & Param,
209
- Output
271
+ Mode
210
272
  >
211
273
  | {
212
274
  action: {
@@ -215,28 +277,28 @@ type MixAct<Type extends string, Param, Output> =
215
277
  }
216
278
  }
217
279
 
218
- export type Action<Output> =
219
- | OutputRemove<
280
+ export type Action<Mode> =
281
+ | RemoveIfDump<
220
282
  {
221
283
  action?: {
222
284
  type?: never
223
285
  param?: never
224
286
  }
225
287
  },
226
- Output
288
+ Mode
227
289
  >
228
- | MixAct<'DoNothing', ActionDoNothing, Output>
229
- | MixAct<'Click', ActionClick, Output>
230
- | MixAct<'LongPress', ActionLongPress, Output>
231
- | MixAct<'Swipe', ActionSwipe, Output>
232
- | MixAct<'MultiSwipe', ActionMultiSwipe, Output>
233
- | MixAct<'Key', ActionKey<Output>, Output>
234
- | MixAct<'InputText', ActionInputText, Output>
235
- | MixAct<'StartApp', ActionStartApp, Output>
236
- | MixAct<'StopApp', ActionStopApp, Output>
237
- | MixAct<'StopTask', ActionStopTask, Output>
238
- | MixAct<'Command', ActionCommand, Output>
239
- | MixAct<'Custom', ActionCustom, Output>
290
+ | MixAct<'DoNothing', ActionDoNothing, Mode>
291
+ | MixAct<'Click', ActionClick, Mode>
292
+ | MixAct<'LongPress', ActionLongPress, Mode>
293
+ | MixAct<'Swipe', ActionSwipe, Mode>
294
+ | MixAct<'MultiSwipe', ActionMultiSwipe<Mode>, Mode>
295
+ | MixAct<'Key', ActionKey<Mode>, Mode>
296
+ | MixAct<'InputText', ActionInputText<Mode>, Mode>
297
+ | MixAct<'StartApp', ActionStartApp<Mode>, Mode>
298
+ | MixAct<'StopApp', ActionStopApp<Mode>, Mode>
299
+ | MixAct<'StopTask', ActionStopTask, Mode>
300
+ | MixAct<'Command', ActionCommand<Mode>, Mode>
301
+ | MixAct<'Custom', ActionCustom<Mode>, Mode>
240
302
 
241
303
  export type WaitFreeze = {
242
304
  time?: number
@@ -248,29 +310,32 @@ export type WaitFreeze = {
248
310
  timeout?: number
249
311
  }
250
312
 
251
- export type General<Output> = {
252
- next?: MaybeArray<NodeName, Output>
253
- interrupt?: MaybeArray<NodeName, Output>
313
+ export type General<Mode> = {
314
+ next?: MaybeArray<NodeName, Mode>
315
+ interrupt?: MaybeArray<NodeName, Mode>
254
316
  is_sub?: boolean
255
317
  rate_limit?: number
256
318
  timeout?: number
257
- on_error?: MaybeArray<string, Output>
319
+ on_error?: MaybeArray<string, Mode>
258
320
  inverse?: boolean
259
321
  enabled?: boolean
260
322
  pre_delay?: boolean
261
323
  post_delay?: boolean
262
- pre_wait_freezes?: OutputRemove<number, Output> | WaitFreeze
263
- post_wait_freezes?: OutputRemove<number, Output> | WaitFreeze
324
+ pre_wait_freezes?: RemoveIfDump<number, Mode> | WaitFreeze
325
+ post_wait_freezes?: RemoveIfDump<number, Mode> | WaitFreeze
264
326
  focus?: unknown
265
327
  }
266
328
 
267
- export type Task = Recognition<false> & Action<false> & General<false>
329
+ export type Task = Recognition<ModeFragment> & Action<ModeFragment> & General<ModeFragment>
330
+ export type StrictTask = Recognition<ModeStrict> & Action<ModeStrict> & General<ModeStrict>
268
331
 
269
332
  type RecursiveRequired<T> =
270
333
  T extends Record<string, unknown>
271
334
  ? {
272
- [key in keyof T]-?: RecursiveRequired<T[key]>
335
+ [key in keyof T]: NonNullable<RecursiveRequired<T[key]>>
273
336
  }
274
337
  : T
275
338
 
276
- export type DumpTask = RecursiveRequired<Recognition<true> & Action<true> & General<true>>
339
+ export type DumpTask = RecursiveRequired<
340
+ Recognition<ModeDump> & Action<ModeDump> & General<ModeDump>
341
+ >