@fugood/bricks-project 2.21.0-beta.14.test0
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/api/application.ts +65 -0
- package/api/index.ts +1 -0
- package/compile/index.ts +485 -0
- package/compile/util.ts +347 -0
- package/index.ts +10 -0
- package/package.json +15 -0
- package/types/animation.ts +95 -0
- package/types/bricks.ts +3052 -0
- package/types/canvas.ts +78 -0
- package/types/common.ts +116 -0
- package/types/data-calc.ts +6950 -0
- package/types/data.ts +33 -0
- package/types/generators.ts +6633 -0
- package/types/index.ts +10 -0
- package/types/subspace.ts +33 -0
- package/types/switch.ts +45 -0
- package/types/system.ts +397 -0
- package/uuid.ts +58 -0
package/compile/util.ts
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { makeId } from '../uuid'
|
|
2
|
+
|
|
3
|
+
type ScriptConfig = {
|
|
4
|
+
inputs: Record<string, string>
|
|
5
|
+
enable_async: boolean
|
|
6
|
+
disabled_triggers: Record<string, boolean>
|
|
7
|
+
output: string | null
|
|
8
|
+
outputs: Record<string, string[]>
|
|
9
|
+
error: string | null
|
|
10
|
+
code: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const errorMsg = 'Not allow duplicate set property id between inputs / outputs / output / error.'
|
|
14
|
+
|
|
15
|
+
export const validateConfig = (config: ScriptConfig) => {
|
|
16
|
+
if (config.error && config.inputs[config.error]) {
|
|
17
|
+
throw new Error(`${errorMsg}. key: error`)
|
|
18
|
+
}
|
|
19
|
+
if (config.output && config.inputs[config.output]) {
|
|
20
|
+
throw new Error(`${errorMsg}. key: output`)
|
|
21
|
+
}
|
|
22
|
+
if (Object.values(config.outputs).some((value) => value.some((id) => config.inputs[id]))) {
|
|
23
|
+
throw new Error(`${errorMsg}. key: outputs`)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const padding = 15
|
|
28
|
+
const layerXInterval = 300
|
|
29
|
+
const layerYInterval = 150
|
|
30
|
+
|
|
31
|
+
export const generateCalulationMap = (config: ScriptConfig, opts?: { snapshotMode?: boolean }) => {
|
|
32
|
+
validateConfig(config)
|
|
33
|
+
const sandboxId = makeId('property_bank_command', opts)
|
|
34
|
+
const sandboxErrorId = makeId('property_bank_command', opts)
|
|
35
|
+
const sandboxResultId = makeId('property_bank_command', opts)
|
|
36
|
+
|
|
37
|
+
const inputs = Object.entries(config.inputs).reduce(
|
|
38
|
+
(acc, [key, value], index) => {
|
|
39
|
+
const commandId = makeId('property_bank_command', opts)
|
|
40
|
+
acc.map[key] = {
|
|
41
|
+
type: 'data-node',
|
|
42
|
+
properties: {},
|
|
43
|
+
in: {
|
|
44
|
+
change: null,
|
|
45
|
+
},
|
|
46
|
+
out: {
|
|
47
|
+
value: [
|
|
48
|
+
{
|
|
49
|
+
id: commandId,
|
|
50
|
+
port: 'value',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
acc.editorInfo[key] = {
|
|
56
|
+
position: { x: padding, y: index * layerYInterval + padding },
|
|
57
|
+
points: {},
|
|
58
|
+
}
|
|
59
|
+
if (acc.prevCommandId) {
|
|
60
|
+
acc.map[acc.prevCommandId].out.result = [
|
|
61
|
+
{
|
|
62
|
+
id: commandId,
|
|
63
|
+
port: 'obj',
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
acc.map[commandId] = {
|
|
68
|
+
type: 'command-node-object',
|
|
69
|
+
title: 'Command: OBJECT_SET',
|
|
70
|
+
properties: {
|
|
71
|
+
command: 'OBJECT_SET',
|
|
72
|
+
args: {
|
|
73
|
+
path: value,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
in: {
|
|
77
|
+
obj: acc.prevCommandId
|
|
78
|
+
? [
|
|
79
|
+
{
|
|
80
|
+
id: acc.prevCommandId,
|
|
81
|
+
port: 'result',
|
|
82
|
+
},
|
|
83
|
+
]
|
|
84
|
+
: null,
|
|
85
|
+
path: null,
|
|
86
|
+
value: [
|
|
87
|
+
{
|
|
88
|
+
id: key,
|
|
89
|
+
port: 'value',
|
|
90
|
+
disable_trigger_command_in: config.disabled_triggers?.[key] ? sandboxId : undefined,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
out: {
|
|
95
|
+
result: [
|
|
96
|
+
{
|
|
97
|
+
id: sandboxId,
|
|
98
|
+
port: 'inputs',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
acc.editorInfo[commandId] = {
|
|
104
|
+
position: { x: layerXInterval, y: index * layerYInterval + padding },
|
|
105
|
+
points: {},
|
|
106
|
+
}
|
|
107
|
+
acc.prevCommandId = commandId
|
|
108
|
+
return acc
|
|
109
|
+
},
|
|
110
|
+
{ map: {}, editorInfo: {}, prevCommandId: null } as {
|
|
111
|
+
map: Record<string, any>
|
|
112
|
+
editorInfo: Record<string, any>
|
|
113
|
+
prevCommandId: string | null
|
|
114
|
+
},
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
let y = 0
|
|
118
|
+
const outputs = Object.entries(config.outputs).reduce(
|
|
119
|
+
(acc, [key, pbList], index) => {
|
|
120
|
+
const commandId = makeId('property_bank_command', opts)
|
|
121
|
+
acc.commandIdList.push(commandId)
|
|
122
|
+
acc.map[commandId] = {
|
|
123
|
+
type: 'command-node-object',
|
|
124
|
+
title: 'Command: OBJECT_GET',
|
|
125
|
+
properties: {
|
|
126
|
+
command: 'OBJECT_GET',
|
|
127
|
+
args: {
|
|
128
|
+
path: key,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
in: {
|
|
132
|
+
obj: [
|
|
133
|
+
{
|
|
134
|
+
id: sandboxResultId,
|
|
135
|
+
port: 'result',
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
path: null,
|
|
139
|
+
},
|
|
140
|
+
out: {
|
|
141
|
+
result: pbList.map((pb) => ({
|
|
142
|
+
id: pb,
|
|
143
|
+
port: 'change',
|
|
144
|
+
})),
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
acc.editorInfo[commandId] = {
|
|
148
|
+
position: {
|
|
149
|
+
x: layerXInterval * 3,
|
|
150
|
+
y: index * layerYInterval + padding,
|
|
151
|
+
},
|
|
152
|
+
points: {},
|
|
153
|
+
}
|
|
154
|
+
pbList.forEach((pb, pbIndex) => {
|
|
155
|
+
acc.map[pb] = {
|
|
156
|
+
type: 'data-node',
|
|
157
|
+
properties: {},
|
|
158
|
+
in: {
|
|
159
|
+
change: [
|
|
160
|
+
{
|
|
161
|
+
id: commandId,
|
|
162
|
+
port: 'result',
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
out: {
|
|
167
|
+
value: null,
|
|
168
|
+
},
|
|
169
|
+
}
|
|
170
|
+
acc.editorInfo[pb] = {
|
|
171
|
+
position: {
|
|
172
|
+
x: layerXInterval * 4,
|
|
173
|
+
y: padding + y + index * layerYInterval + pbIndex * layerYInterval,
|
|
174
|
+
},
|
|
175
|
+
points: {},
|
|
176
|
+
}
|
|
177
|
+
if (pbIndex > 0) y += layerYInterval
|
|
178
|
+
})
|
|
179
|
+
return acc
|
|
180
|
+
},
|
|
181
|
+
{ map: {}, editorInfo: {}, commandIdList: [] } as {
|
|
182
|
+
map: Record<string, any>
|
|
183
|
+
editorInfo: Record<string, any>
|
|
184
|
+
commandIdList: string[]
|
|
185
|
+
},
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
map: {
|
|
190
|
+
...inputs.map,
|
|
191
|
+
[sandboxId]: {
|
|
192
|
+
type: 'command-node-sandbox',
|
|
193
|
+
title: 'Command: SANDBOX_RUN_JAVASCRIPT',
|
|
194
|
+
properties: {
|
|
195
|
+
command: 'SANDBOX_RUN_JAVASCRIPT',
|
|
196
|
+
args: {
|
|
197
|
+
code: config.code,
|
|
198
|
+
enable_async: config.enable_async,
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
in: {
|
|
202
|
+
code: null,
|
|
203
|
+
inputs: inputs.prevCommandId
|
|
204
|
+
? [
|
|
205
|
+
{
|
|
206
|
+
id: inputs.prevCommandId,
|
|
207
|
+
port: 'result',
|
|
208
|
+
},
|
|
209
|
+
]
|
|
210
|
+
: [],
|
|
211
|
+
},
|
|
212
|
+
out: {
|
|
213
|
+
result: [
|
|
214
|
+
{
|
|
215
|
+
id: sandboxErrorId,
|
|
216
|
+
port: 'result',
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: sandboxResultId,
|
|
220
|
+
port: 'result',
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
[sandboxErrorId]: {
|
|
226
|
+
type: 'command-node-sandbox',
|
|
227
|
+
title: 'Command: SANDBOX_GET_ERROR',
|
|
228
|
+
properties: {
|
|
229
|
+
command: 'SANDBOX_GET_ERROR',
|
|
230
|
+
},
|
|
231
|
+
in: {
|
|
232
|
+
result: [
|
|
233
|
+
{
|
|
234
|
+
id: sandboxId,
|
|
235
|
+
port: 'result',
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
out: {
|
|
240
|
+
result: config.error
|
|
241
|
+
? [
|
|
242
|
+
{
|
|
243
|
+
id: config.error,
|
|
244
|
+
port: 'change',
|
|
245
|
+
},
|
|
246
|
+
]
|
|
247
|
+
: [],
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
[sandboxResultId]: {
|
|
251
|
+
type: 'command-node-sandbox',
|
|
252
|
+
title: 'Command: SANDBOX_GET_RETURN_VALUE',
|
|
253
|
+
properties: {
|
|
254
|
+
command: 'SANDBOX_GET_RETURN_VALUE',
|
|
255
|
+
},
|
|
256
|
+
in: {
|
|
257
|
+
result: [
|
|
258
|
+
{
|
|
259
|
+
id: sandboxId,
|
|
260
|
+
port: 'result',
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
out: {
|
|
265
|
+
result: (config.output
|
|
266
|
+
? [
|
|
267
|
+
{
|
|
268
|
+
id: config.output,
|
|
269
|
+
port: 'change',
|
|
270
|
+
},
|
|
271
|
+
]
|
|
272
|
+
: []
|
|
273
|
+
).concat(
|
|
274
|
+
outputs.commandIdList.map((commandId) => ({
|
|
275
|
+
id: commandId,
|
|
276
|
+
port: 'obj',
|
|
277
|
+
})),
|
|
278
|
+
),
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
...(config.error && {
|
|
283
|
+
[config.error]: {
|
|
284
|
+
type: 'data-node',
|
|
285
|
+
properties: {},
|
|
286
|
+
in: {
|
|
287
|
+
change: [
|
|
288
|
+
{
|
|
289
|
+
id: sandboxErrorId,
|
|
290
|
+
port: 'result',
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
},
|
|
294
|
+
out: {
|
|
295
|
+
value: null,
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
...(config.output && {
|
|
300
|
+
[config.output]: {
|
|
301
|
+
type: 'data-node',
|
|
302
|
+
properties: {},
|
|
303
|
+
in: {
|
|
304
|
+
change: [
|
|
305
|
+
{
|
|
306
|
+
id: sandboxResultId,
|
|
307
|
+
port: 'result',
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
},
|
|
311
|
+
out: {
|
|
312
|
+
value: null,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
}),
|
|
316
|
+
...outputs.map,
|
|
317
|
+
},
|
|
318
|
+
editor_info: {
|
|
319
|
+
...inputs.editorInfo,
|
|
320
|
+
[sandboxId]: {
|
|
321
|
+
position: { x: layerXInterval * 2, y: padding },
|
|
322
|
+
points: {},
|
|
323
|
+
},
|
|
324
|
+
[sandboxErrorId]: {
|
|
325
|
+
position: { x: layerXInterval * 2, y: layerYInterval },
|
|
326
|
+
points: {},
|
|
327
|
+
},
|
|
328
|
+
[sandboxResultId]: {
|
|
329
|
+
position: { x: layerXInterval * 2, y: layerYInterval * 2 },
|
|
330
|
+
points: {},
|
|
331
|
+
},
|
|
332
|
+
...(config.error && {
|
|
333
|
+
[config.error]: {
|
|
334
|
+
position: { x: layerXInterval * 2, y: layerYInterval * 3 },
|
|
335
|
+
points: {},
|
|
336
|
+
},
|
|
337
|
+
}),
|
|
338
|
+
...(config.output && {
|
|
339
|
+
[config.output]: {
|
|
340
|
+
position: { x: layerXInterval * 2, y: layerYInterval * 4 },
|
|
341
|
+
points: {},
|
|
342
|
+
},
|
|
343
|
+
}),
|
|
344
|
+
...outputs.editorInfo,
|
|
345
|
+
},
|
|
346
|
+
}
|
|
347
|
+
}
|
package/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fugood/bricks-project",
|
|
3
|
+
"version": "2.21.0-beta.14.test0",
|
|
4
|
+
"main": "index.ts",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "node scripts/build.js"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"acorn": "^8.13.0",
|
|
10
|
+
"escodegen": "^2.1.0",
|
|
11
|
+
"lodash": "^4.17.4",
|
|
12
|
+
"uuid": "^8.3.1"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {}
|
|
15
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export type Easing =
|
|
2
|
+
| ''
|
|
3
|
+
| 'easeInSine'
|
|
4
|
+
| 'easeOutSine'
|
|
5
|
+
| 'easeInOutSine'
|
|
6
|
+
| 'easeInQuad'
|
|
7
|
+
| 'easeOutQuad'
|
|
8
|
+
| 'easeInOutQuad'
|
|
9
|
+
| 'easeInCubic'
|
|
10
|
+
| 'easeOutCubic'
|
|
11
|
+
| 'easeInOutCubic'
|
|
12
|
+
| 'easeInQuart'
|
|
13
|
+
| 'easeOutQuart'
|
|
14
|
+
| 'easeInOutQuart'
|
|
15
|
+
| 'easeInQuint'
|
|
16
|
+
| 'easeOutQuint'
|
|
17
|
+
| 'easeInOutQuint'
|
|
18
|
+
| 'easeInExpo'
|
|
19
|
+
| 'easeOutExpo'
|
|
20
|
+
| 'easeInOutExpo'
|
|
21
|
+
| 'easeInCirc'
|
|
22
|
+
| 'easeOutCirc'
|
|
23
|
+
| 'easeInOutCirc'
|
|
24
|
+
| 'easeInBack'
|
|
25
|
+
| 'easeOutBack'
|
|
26
|
+
| 'easeInOutBack'
|
|
27
|
+
| 'easeInElastic'
|
|
28
|
+
| 'easeOutElastic'
|
|
29
|
+
| 'easeInOutElastic'
|
|
30
|
+
| 'easeInBounce'
|
|
31
|
+
| 'easeOutBounce'
|
|
32
|
+
| 'easeInOutBounce'
|
|
33
|
+
|
|
34
|
+
export interface AnimationTimingConfig {
|
|
35
|
+
__type: 'AnimationTimingConfig'
|
|
36
|
+
toValue: number // BRICKS Grid unit
|
|
37
|
+
duration: number // ms
|
|
38
|
+
easing: Easing
|
|
39
|
+
delay: number // ms
|
|
40
|
+
isInteraction: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AnimationSpringConfig {
|
|
44
|
+
__type: 'AnimationSpringConfig'
|
|
45
|
+
toValue: number // BRICKS Grid unit
|
|
46
|
+
friction: number
|
|
47
|
+
tension: number
|
|
48
|
+
speed: number
|
|
49
|
+
bounciness: number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface AnimationDecayConfig {
|
|
53
|
+
__type: 'AnimationDecayConfig'
|
|
54
|
+
toValue: number // BRICKS Grid unit
|
|
55
|
+
velocity: number
|
|
56
|
+
deceleration: number
|
|
57
|
+
isInteraction: boolean
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface AnimationDef {
|
|
61
|
+
__typename: 'Animation'
|
|
62
|
+
id: string
|
|
63
|
+
title: string
|
|
64
|
+
description?: string
|
|
65
|
+
runType?: 'once' | 'loop'
|
|
66
|
+
property:
|
|
67
|
+
| 'transform.translateX'
|
|
68
|
+
| 'transform.translateY'
|
|
69
|
+
| 'transform.scale'
|
|
70
|
+
| 'transform.scaleX'
|
|
71
|
+
| 'transform.scaleY'
|
|
72
|
+
| 'transform.rotate'
|
|
73
|
+
| 'transform.rotateX'
|
|
74
|
+
| 'transform.rotateY'
|
|
75
|
+
| 'opacity'
|
|
76
|
+
config: AnimationTimingConfig | AnimationSpringConfig | AnimationDecayConfig
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface AnimationComposeDef {
|
|
80
|
+
__typename: 'AnimationCompose'
|
|
81
|
+
id: string
|
|
82
|
+
title: string
|
|
83
|
+
description?: string
|
|
84
|
+
runType?: 'once' | 'loop'
|
|
85
|
+
composeType: 'parallel' | 'sequence'
|
|
86
|
+
items: Array<() => AnimationDef>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type Animation = AnimationDef | AnimationComposeDef
|
|
90
|
+
|
|
91
|
+
export interface AnimationBasicEvents {
|
|
92
|
+
show?: Animation
|
|
93
|
+
standby?: Animation
|
|
94
|
+
breatheStart?: Animation
|
|
95
|
+
}
|