rcompiler 0.0.0-stage → 2.2.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/CHANGELOG.md +31 -0
- package/CONTRIBUTING.md +38 -0
- package/LICENSE +15 -0
- package/README.md +170 -2
- package/SECURITY.md +27 -0
- package/assets/placeholder.png +0 -0
- package/docs/ARCHITECTURE.md +74 -0
- package/docs/CLI.md +67 -0
- package/docs/COMPATIBILITY.md +29 -0
- package/docs/CONFIG.md +73 -0
- package/docs/DEBUGGING.md +46 -0
- package/docs/NATIVE.md +110 -0
- package/docs/ROADMAP.md +12 -0
- package/docs/TESTING.md +55 -0
- package/exts/args.js +142 -0
- package/exts/freya.js +430 -0
- package/exts/fs.js +317 -0
- package/exts/io.js +396 -0
- package/exts/path.js +208 -0
- package/exts/process.js +416 -0
- package/exts/rcompilerExt.js +1396 -0
- package/exts/vartypeany.js +131 -0
- package/package.json +50 -4
- package/src/analysis.js +571 -0
- package/src/assets.js +335 -0
- package/src/cli.js +359 -0
- package/src/emit.js +353 -0
- package/src/mods.js +146 -0
- package/src/preludes.js +4174 -0
- package/src/rcompiler.js +2785 -0
- package/src/standard.js +1452 -0
- package/src/targets.js +129 -0
- package/src/web.js +1593 -0
package/exts/freya.js
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
(function (util) {
|
|
2
|
+
const ArgumentType = util.ArgumentType ? util.ArgumentType : { STRING: 'r', NUMBER: 'r' };
|
|
3
|
+
const gf = (args, name) => {
|
|
4
|
+
return args.scope.block.fields[name][0];
|
|
5
|
+
}
|
|
6
|
+
const Safe = util.Cast ? util.Cast.Safe : () => { };
|
|
7
|
+
const ko = util.Cast ? util.Cast.keywordOnly : () => { };
|
|
8
|
+
if (typeof vm != 'undefined') {
|
|
9
|
+
const runtime = vm.runtime;
|
|
10
|
+
const cbfsb = runtime._convertBlockForScratchBlocks.bind(runtime);
|
|
11
|
+
runtime._convertBlockForScratchBlocks = function (blockInfo, categoryInfo) {
|
|
12
|
+
const res = cbfsb(blockInfo, categoryInfo);
|
|
13
|
+
if (blockInfo.全局) {
|
|
14
|
+
res.json.previousStatement = void 0;
|
|
15
|
+
res.json.nextStatement = void 0;
|
|
16
|
+
}
|
|
17
|
+
if (blockInfo.usefield) {
|
|
18
|
+
blockInfo.usefield.forEach(element => {
|
|
19
|
+
res.json.args0[element] = {
|
|
20
|
+
"type": "field_input",
|
|
21
|
+
"name": res.json.args0[element].name,
|
|
22
|
+
"text": res.json.args0[element].text,
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
let inlabel = false;
|
|
30
|
+
class freya {
|
|
31
|
+
id = 'freya';
|
|
32
|
+
blocks = [
|
|
33
|
+
{
|
|
34
|
+
func: "help",
|
|
35
|
+
blockType: util.BlockType.BUTTON,
|
|
36
|
+
text: '使用方法'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
func: "help",
|
|
40
|
+
blockType: util.BlockType.BUTTON,
|
|
41
|
+
text: '项目示例'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
blockType: util.BlockType.LABEL,
|
|
45
|
+
text: '请在 “编译器” 扩展中禁用异步运行时'
|
|
46
|
+
},
|
|
47
|
+
'---',
|
|
48
|
+
{
|
|
49
|
+
blockType: util.BlockType.LABEL,
|
|
50
|
+
text: 'GUI'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
opcode: 'launch',
|
|
54
|
+
blockType: util.BlockType.COMMAND,
|
|
55
|
+
text: '启动 GUI [app] 标题: [title] x: [x] y: [y]',
|
|
56
|
+
usefield: ['0'],
|
|
57
|
+
arguments: {
|
|
58
|
+
app: {
|
|
59
|
+
type: ArgumentType.STRING,
|
|
60
|
+
defalutValue: 'app'
|
|
61
|
+
},
|
|
62
|
+
title: {
|
|
63
|
+
type: ArgumentType.STRING,
|
|
64
|
+
defalutValue: 'Freya'
|
|
65
|
+
},
|
|
66
|
+
x: {
|
|
67
|
+
type: ArgumentType.NUMBER,
|
|
68
|
+
defalutValue: '400.0'
|
|
69
|
+
},
|
|
70
|
+
y: {
|
|
71
|
+
type: ArgumentType.NUMBER,
|
|
72
|
+
defalutValue: '350.0'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
opcode: 'app',
|
|
78
|
+
blockType: util.BlockType.COMMAND,
|
|
79
|
+
text: '空间 [name]',
|
|
80
|
+
usefield: ['0'],
|
|
81
|
+
branchCount: 2,
|
|
82
|
+
全局: 1,
|
|
83
|
+
blockStart: 1,
|
|
84
|
+
arguments: {
|
|
85
|
+
name: {
|
|
86
|
+
type: ArgumentType.STRING,
|
|
87
|
+
defalutValue: 'app'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
opcode: 'rsx',
|
|
93
|
+
blockType: util.BlockType.COMMAND,
|
|
94
|
+
text: '内容',
|
|
95
|
+
branchCount: 1
|
|
96
|
+
},
|
|
97
|
+
'---',
|
|
98
|
+
{
|
|
99
|
+
blockType: util.BlockType.LABEL,
|
|
100
|
+
text: '组件/设置'
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
opcode: 'rect',
|
|
104
|
+
blockType: util.BlockType.COMMAND,
|
|
105
|
+
text: '[item]',
|
|
106
|
+
branchCount: 1,
|
|
107
|
+
autoInput: 1,
|
|
108
|
+
arguments: {
|
|
109
|
+
item: {
|
|
110
|
+
type: ArgumentType.STRING,
|
|
111
|
+
menu: 'rects'
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
opcode: 'settings',
|
|
117
|
+
blockType: util.BlockType.COMMAND,
|
|
118
|
+
text: '设置 [setting] 为 [value]',
|
|
119
|
+
arguments: {
|
|
120
|
+
setting: {
|
|
121
|
+
type: ArgumentType.STRING,
|
|
122
|
+
menu: 'settings'
|
|
123
|
+
},
|
|
124
|
+
value: {
|
|
125
|
+
type: ArgumentType.STRING,
|
|
126
|
+
defalutValue: ''
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
opcode: 'text',
|
|
132
|
+
blockType: util.BlockType.COMMAND,
|
|
133
|
+
text: '文字 [text]',
|
|
134
|
+
arguments: {
|
|
135
|
+
text: {
|
|
136
|
+
type: ArgumentType.STRING,
|
|
137
|
+
defalutValue: ''
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
opcode: 'variset',
|
|
143
|
+
blockType: util.BlockType.COMMAND,
|
|
144
|
+
text: '变量 [text]',
|
|
145
|
+
usefield: ['0'],
|
|
146
|
+
arguments: {
|
|
147
|
+
text: {
|
|
148
|
+
type: ArgumentType.STRING,
|
|
149
|
+
defalutValue: ''
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
opcode: 'settingsBranch',
|
|
155
|
+
blockType: util.BlockType.COMMAND,
|
|
156
|
+
text: '设置 [setting] 为',
|
|
157
|
+
branchCount: 1,
|
|
158
|
+
arguments: {
|
|
159
|
+
setting: {
|
|
160
|
+
type: ArgumentType.STRING,
|
|
161
|
+
menu: 'settingsBranch'
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
opcode: 'call',
|
|
167
|
+
blockType: util.BlockType.COMMAND,
|
|
168
|
+
text: '空间 [name]',
|
|
169
|
+
branchCount: 1,
|
|
170
|
+
usefield: ['0'],
|
|
171
|
+
arguments: {
|
|
172
|
+
name: {
|
|
173
|
+
type: ArgumentType.STRING,
|
|
174
|
+
defalutValue: 'app'
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
'---',
|
|
179
|
+
{
|
|
180
|
+
blockType: util.BlockType.LABEL,
|
|
181
|
+
text: '空间参数'
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
opcode: 'setarg',
|
|
185
|
+
blockType: util.BlockType.COMMAND,
|
|
186
|
+
text: '参数设置 [name]: [value]',
|
|
187
|
+
usefield: ['0', '1'],
|
|
188
|
+
arguments: {
|
|
189
|
+
name: {
|
|
190
|
+
type: ArgumentType.STRING,
|
|
191
|
+
defalutValue: 'children'
|
|
192
|
+
},
|
|
193
|
+
value: {
|
|
194
|
+
type: ArgumentType.STRING,
|
|
195
|
+
defalutValue: 'Element'
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
opcode: 'arg',
|
|
201
|
+
blockType: util.BlockType.COMMAND,
|
|
202
|
+
text: '参数 [name]',
|
|
203
|
+
usefield: ['0'],
|
|
204
|
+
arguments: {
|
|
205
|
+
name: {
|
|
206
|
+
type: ArgumentType.STRING,
|
|
207
|
+
defalutValue: ''
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
'---',
|
|
212
|
+
{
|
|
213
|
+
blockType: util.BlockType.LABEL,
|
|
214
|
+
text: '空间变量'
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
opcode: 'vari',
|
|
218
|
+
blockType: util.BlockType.REPORTER,
|
|
219
|
+
text: '信号化 [value]',
|
|
220
|
+
arguments: {
|
|
221
|
+
value: {
|
|
222
|
+
type: ArgumentType.STRING,
|
|
223
|
+
defalutValue: ''
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
];
|
|
228
|
+
getInfo() {
|
|
229
|
+
return {
|
|
230
|
+
id: this.id,
|
|
231
|
+
name: 'Freya GUI',
|
|
232
|
+
blocks: this.blocks,
|
|
233
|
+
color1: '#775aea',
|
|
234
|
+
color2: '#a08fe1',
|
|
235
|
+
menus: {
|
|
236
|
+
settings: [
|
|
237
|
+
{
|
|
238
|
+
text: '高度',
|
|
239
|
+
value: 'height'
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
text: '宽度',
|
|
243
|
+
value: 'width'
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
text: '上对齐',
|
|
247
|
+
value: 'main_align'
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
text: '左对齐',
|
|
251
|
+
value: 'cross_align'
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
text: '背景颜色',
|
|
255
|
+
value: 'background'
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
text: '颜色',
|
|
259
|
+
value: 'color'
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
text: '阴影',
|
|
263
|
+
value: 'shadow'
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
text: '对齐',
|
|
267
|
+
value: 'direction'
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
text: '填充',
|
|
271
|
+
value: 'padding'
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
text: '文字大小',
|
|
275
|
+
value: 'font_size'
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
text: '文字宽度',
|
|
279
|
+
value: 'font_weight'
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
text: '圆角半径',
|
|
283
|
+
value: 'corner_radius'
|
|
284
|
+
}
|
|
285
|
+
],
|
|
286
|
+
settingsBranch: [
|
|
287
|
+
{
|
|
288
|
+
text: '点击时',
|
|
289
|
+
value: 'onclick'
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
text: '主题',
|
|
293
|
+
value: 'theme'
|
|
294
|
+
}
|
|
295
|
+
],
|
|
296
|
+
rects: [
|
|
297
|
+
{
|
|
298
|
+
text: '渲染',
|
|
299
|
+
value: 'rect'
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
text: '标签',
|
|
303
|
+
value: 'label'
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
text: '按钮',
|
|
307
|
+
value: 'Button'
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
text: '滚动浏览',
|
|
311
|
+
value: 'ScrollView'
|
|
312
|
+
}
|
|
313
|
+
]
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
launch(args) {
|
|
318
|
+
if (!util.isCompiler) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
util.Tools.setdepend(['freya = "0.2"', 'dioxus = { version = "0.5", features = ["macro", "hooks"], default-features = false }']);
|
|
322
|
+
util.Tools.setlibrary(['use freya::prelude::*;']);
|
|
323
|
+
|
|
324
|
+
const name = ko(gf(args, 'app'));
|
|
325
|
+
args.compiler += `launch_with_props(Default::${name},${args.title.Str()},(${args.x.Num()},${args.y.Num()}));\n`;
|
|
326
|
+
return args.compiler;
|
|
327
|
+
}
|
|
328
|
+
app(args) {
|
|
329
|
+
if (!util.isCompiler) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const name = ko(gf(args, 'name'));
|
|
334
|
+
args.compiler += Safe(args.SUBSTACK) ? `#[derive(Props, Clone, PartialEq)]\nstruct ${name}_props{\n${Safe(args.SUBSTACK)}}\n` : '';
|
|
335
|
+
args.compiler += `fn ${name}(${Safe(args.SUBSTACK) ? `props: ${name}_props` : ''}) -> Element {\n${Safe(args.SUBSTACK2)}}\n`;
|
|
336
|
+
util.Tools.setfunc([args.compiler]);
|
|
337
|
+
return args.compiler;
|
|
338
|
+
}
|
|
339
|
+
rsx(args) {
|
|
340
|
+
if (!util.isCompiler) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
args.compiler += `rsx!(\n${Safe(args.SUBSTACK)})\n`;
|
|
345
|
+
return args.compiler;
|
|
346
|
+
}
|
|
347
|
+
async rect(args) {
|
|
348
|
+
if (!util.isCompiler) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const name = gf(args, 'item');
|
|
353
|
+
if (name == 'label') inlabel = true;
|
|
354
|
+
else inlabel = false;
|
|
355
|
+
args.compiler += `${name} {\n${(await util.compile_this(args.scope.target.blocks[args.scope.block.inputs.SUBSTACK[1]], args.scope.target)).block()}}\n`;
|
|
356
|
+
return args.compiler;
|
|
357
|
+
}
|
|
358
|
+
settings(args) {
|
|
359
|
+
if (!util.isCompiler) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const name = gf(args, 'setting');
|
|
364
|
+
args.compiler += `${name}: ${args.value.Str()},\n`;
|
|
365
|
+
return args.compiler;
|
|
366
|
+
}
|
|
367
|
+
text(args) {
|
|
368
|
+
if (!util.isCompiler) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
args.compiler += `${args.text.Str()},\n`;
|
|
373
|
+
return args.compiler;
|
|
374
|
+
}
|
|
375
|
+
variset(args) {
|
|
376
|
+
if (!util.isCompiler) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const text = gf(args, 'text');
|
|
381
|
+
args.compiler += inlabel ? `"{${text}}",\n` : `{${text}},\n`;
|
|
382
|
+
return args.compiler;
|
|
383
|
+
}
|
|
384
|
+
settingsBranch(args) {
|
|
385
|
+
if (!util.isCompiler) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const name = gf(args, 'setting');
|
|
390
|
+
switch (name) {
|
|
391
|
+
case 'onclick': {
|
|
392
|
+
args.compiler += `onclick: move |_| {\n${Safe(args.SUBSTACK)}\n},\n`;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
case 'theme': {
|
|
396
|
+
args.compiler += `theme: theme_with!(ScrollViewTheme {\n${Safe(args.SUBSTACK)}\n}),\n`;
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return args.compiler;
|
|
401
|
+
}
|
|
402
|
+
setarg(args) {
|
|
403
|
+
if (!util.isCompiler) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const name = ko(gf(args, 'name'));
|
|
408
|
+
const value = ko(gf(args, 'value'));
|
|
409
|
+
args.compiler += `${name}: ${value}`;
|
|
410
|
+
return args.compiler;
|
|
411
|
+
}
|
|
412
|
+
arg(args) {
|
|
413
|
+
if (!util.isCompiler) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const name = ko(gf(args, 'name'));
|
|
418
|
+
args.compiler += inlabel ? `"{props.${name}}"` : `{props.${name}}`;
|
|
419
|
+
return args.compiler;
|
|
420
|
+
}
|
|
421
|
+
vari(args) {
|
|
422
|
+
if (!util.isCompiler) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return new util.TypeInput[args.value.type](`use_signal(|| ${args.value[args.value.type]()})`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
util.extensions.register(new freya());
|
|
430
|
+
})(this.isCompiler ? this : Scratch);
|