@kubohiroya/turbowarp-aframe 0.7.0 → 0.8.1
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.ja.md +6 -1
- package/README.md +6 -1
- package/dist/turbowarp-aframe.js +16548 -7926
- package/docs/editor-schema-ci-fix-20261018.ja.md +25 -0
- package/docs/editor-schema-ci-fix-20261018.json +88 -0
- package/docs/editor-schema-publication.ja.md +13 -0
- package/docs/editor-schema-publication.json +100 -0
- package/docs/editor-schema-verification.json +50 -0
- package/docs/editor-schema.ja.md +23 -0
- package/docs/fixed-input-editors.ja.md +52 -0
- package/docs/index.html +56 -1
- package/docs/source-editor.ja.md +13 -0
- package/docs/stage-2-publication.ja.md +34 -0
- package/docs/stage-2-publication.json +67 -0
- package/lib-editor/schemas/block-editor-template-compat.schema.json +48 -0
- package/lib-editor/src/editor-schema.d.ts +44 -0
- package/lib-editor/src/editor-schema.js +100 -0
- package/lib-editor/src/template-validation.d.ts +10 -0
- package/lib-editor/src/template-validation.js +69 -0
- package/package.json +29 -6
- package/schemas/block-editor-fixed-inputs.schema.json +229 -0
- package/schemas/block-editor-template-compat.schema.json +48 -0
- package/src/editor-schema.ts +111 -0
- package/src/extension.ts +22 -78
- package/src/fixed-input-editors.ts +142 -0
- package/src/fixed-input-schema.ts +14 -0
- package/src/source-editors.ts +30 -0
- package/src/template-validation.ts +79 -0
- package/schemas/extension-manifest.schema.json +0 -49
- package/src/extension-manifest.ts +0 -149
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://kubohiroya.github.io/turbowarp-aframe/schemas/block-editor-fixed-inputs.schema.json",
|
|
4
|
+
"title": "turbowarp-aframe fixed input registration schema",
|
|
5
|
+
"$defs": {
|
|
6
|
+
"createScene": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"LAYER": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"enum": [
|
|
12
|
+
"above-stage",
|
|
13
|
+
"below-stage"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"setPosition": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"properties": {
|
|
21
|
+
"X": {
|
|
22
|
+
"type": "number",
|
|
23
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
24
|
+
},
|
|
25
|
+
"Y": {
|
|
26
|
+
"type": "number",
|
|
27
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
28
|
+
},
|
|
29
|
+
"Z": {
|
|
30
|
+
"type": "number",
|
|
31
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"moveBy": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"properties": {
|
|
38
|
+
"X": {
|
|
39
|
+
"type": "number",
|
|
40
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
41
|
+
},
|
|
42
|
+
"Y": {
|
|
43
|
+
"type": "number",
|
|
44
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
45
|
+
},
|
|
46
|
+
"Z": {
|
|
47
|
+
"type": "number",
|
|
48
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"setRotation": {
|
|
53
|
+
"type": "object",
|
|
54
|
+
"properties": {
|
|
55
|
+
"X": {
|
|
56
|
+
"type": "number",
|
|
57
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
58
|
+
},
|
|
59
|
+
"Y": {
|
|
60
|
+
"type": "number",
|
|
61
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
62
|
+
},
|
|
63
|
+
"Z": {
|
|
64
|
+
"type": "number",
|
|
65
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"createAnimationClip": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {
|
|
72
|
+
"DURATION": {
|
|
73
|
+
"type": "number",
|
|
74
|
+
"minimum": -1,
|
|
75
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"addVectorKeyframeTrack": {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"properties": {
|
|
82
|
+
"PATH": {
|
|
83
|
+
"type": "string",
|
|
84
|
+
"enum": [
|
|
85
|
+
".position",
|
|
86
|
+
".scale"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"addQuaternionKeyframeTrack": {
|
|
92
|
+
"type": "object",
|
|
93
|
+
"properties": {
|
|
94
|
+
"PATH": {
|
|
95
|
+
"type": "string",
|
|
96
|
+
"enum": [
|
|
97
|
+
".quaternion"
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"addEulerRotationKeyframeTrack": {
|
|
103
|
+
"type": "object",
|
|
104
|
+
"properties": {
|
|
105
|
+
"PATH": {
|
|
106
|
+
"type": "string",
|
|
107
|
+
"enum": [
|
|
108
|
+
".quaternion"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
"UNIT": {
|
|
112
|
+
"type": "string",
|
|
113
|
+
"enum": [
|
|
114
|
+
"degrees",
|
|
115
|
+
"radians"
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"addPositionKeyframe": {
|
|
121
|
+
"type": "object",
|
|
122
|
+
"properties": {
|
|
123
|
+
"TIME": {
|
|
124
|
+
"type": "number",
|
|
125
|
+
"minimum": 0,
|
|
126
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
127
|
+
},
|
|
128
|
+
"X": {
|
|
129
|
+
"type": "number",
|
|
130
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
131
|
+
},
|
|
132
|
+
"Y": {
|
|
133
|
+
"type": "number",
|
|
134
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
135
|
+
},
|
|
136
|
+
"Z": {
|
|
137
|
+
"type": "number",
|
|
138
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
"addScaleKeyframe": {
|
|
143
|
+
"type": "object",
|
|
144
|
+
"properties": {
|
|
145
|
+
"TIME": {
|
|
146
|
+
"type": "number",
|
|
147
|
+
"minimum": 0,
|
|
148
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
149
|
+
},
|
|
150
|
+
"X": {
|
|
151
|
+
"type": "number",
|
|
152
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
153
|
+
},
|
|
154
|
+
"Y": {
|
|
155
|
+
"type": "number",
|
|
156
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
157
|
+
},
|
|
158
|
+
"Z": {
|
|
159
|
+
"type": "number",
|
|
160
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"addEulerRotationKeyframe": {
|
|
165
|
+
"type": "object",
|
|
166
|
+
"properties": {
|
|
167
|
+
"TIME": {
|
|
168
|
+
"type": "number",
|
|
169
|
+
"minimum": 0,
|
|
170
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
171
|
+
},
|
|
172
|
+
"X": {
|
|
173
|
+
"type": "number",
|
|
174
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
175
|
+
},
|
|
176
|
+
"Y": {
|
|
177
|
+
"type": "number",
|
|
178
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
179
|
+
},
|
|
180
|
+
"Z": {
|
|
181
|
+
"type": "number",
|
|
182
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
183
|
+
},
|
|
184
|
+
"UNIT": {
|
|
185
|
+
"type": "string",
|
|
186
|
+
"enum": [
|
|
187
|
+
"degrees",
|
|
188
|
+
"radians"
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
"setAnimationTimeScale": {
|
|
194
|
+
"type": "object",
|
|
195
|
+
"properties": {
|
|
196
|
+
"SCALE": {
|
|
197
|
+
"type": "number",
|
|
198
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
"setVrmBoneRotation": {
|
|
203
|
+
"type": "object",
|
|
204
|
+
"properties": {
|
|
205
|
+
"X": {
|
|
206
|
+
"type": "number",
|
|
207
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
208
|
+
},
|
|
209
|
+
"Y": {
|
|
210
|
+
"type": "number",
|
|
211
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
212
|
+
},
|
|
213
|
+
"Z": {
|
|
214
|
+
"type": "number",
|
|
215
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
"setVrmExpression": {
|
|
220
|
+
"type": "object",
|
|
221
|
+
"properties": {
|
|
222
|
+
"WEIGHT": {
|
|
223
|
+
"type": "number",
|
|
224
|
+
"$comment": "New finite numeric input uses NP-finite-new-input-v1. Existing raw is preserved on no-op; runtime clamp/floor is not applied to stored raw."
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://kubohiroya.github.io/turbowarp-aframe/schemas/block-editor-template-compat.schema.json",
|
|
4
|
+
"title": "A-Frame existing parser compatible template",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"properties": {
|
|
8
|
+
"type": {
|
|
9
|
+
"type": "string"
|
|
10
|
+
},
|
|
11
|
+
"id": {
|
|
12
|
+
"type": "string"
|
|
13
|
+
},
|
|
14
|
+
"class": {
|
|
15
|
+
"oneOf": [
|
|
16
|
+
{
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"type": "array",
|
|
21
|
+
"items": {
|
|
22
|
+
"type": "string"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"classes": {
|
|
28
|
+
"type": "array",
|
|
29
|
+
"items": {
|
|
30
|
+
"type": "string"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"data": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"additionalProperties": true
|
|
36
|
+
},
|
|
37
|
+
"attributes": {
|
|
38
|
+
"type": "object",
|
|
39
|
+
"additionalProperties": true
|
|
40
|
+
},
|
|
41
|
+
"children": {
|
|
42
|
+
"type": "array",
|
|
43
|
+
"items": {
|
|
44
|
+
"$ref": "#"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compileSchemaBundle,
|
|
3
|
+
validateSchemaInput,
|
|
4
|
+
} from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
5
|
+
import type {
|
|
6
|
+
SchemaValidationContext,
|
|
7
|
+
SchemaJsonValue,
|
|
8
|
+
InputDiagnostic,
|
|
9
|
+
} from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
10
|
+
import document from '../schemas/block-editor-template-compat.schema.json' with { type: 'json' };
|
|
11
|
+
import type {
|
|
12
|
+
SchemaBundle,
|
|
13
|
+
SchemaDocument,
|
|
14
|
+
SyncOwnerValidator,
|
|
15
|
+
} from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
16
|
+
import { validateTemplateNode } from './template-validation.js';
|
|
17
|
+
export { validateTemplateNode } from './template-validation.js';
|
|
18
|
+
const source = {
|
|
19
|
+
repository: 'turbowarp-aframe',
|
|
20
|
+
path: 'schemas/block-editor-template-compat.schema.json',
|
|
21
|
+
};
|
|
22
|
+
/** Parser-compatible gate; the older strict public schema is reference material only. */
|
|
23
|
+
export const templateSchemaBundle: SchemaBundle = {
|
|
24
|
+
identity: {
|
|
25
|
+
ownerId: 'turbowarp-aframe',
|
|
26
|
+
contractId: 'aframe-template',
|
|
27
|
+
revision: 'parser-v0.7.0',
|
|
28
|
+
variantId: 'template-json',
|
|
29
|
+
},
|
|
30
|
+
dialect: '2020-12',
|
|
31
|
+
root: {
|
|
32
|
+
retrievalUri: document.$id,
|
|
33
|
+
document: document as SchemaDocument,
|
|
34
|
+
artifact: { role: 'canonical-schema', source },
|
|
35
|
+
},
|
|
36
|
+
resources: [],
|
|
37
|
+
provenance: {
|
|
38
|
+
canonicalSources: [
|
|
39
|
+
source,
|
|
40
|
+
{
|
|
41
|
+
repository: 'turbowarp-aframe',
|
|
42
|
+
path: 'src/template-validation.ts',
|
|
43
|
+
symbol: 'validateTemplateNode',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
generatedFiles: [],
|
|
47
|
+
referenceSchemas: [
|
|
48
|
+
{ repository: 'turbowarp-aframe', path: 'schemas/aframe-template.schema.json' },
|
|
49
|
+
],
|
|
50
|
+
generationSources: [],
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
export const validateTemplateInput: SyncOwnerValidator = (data) => {
|
|
54
|
+
try {
|
|
55
|
+
validateTemplateNode(data, 'template');
|
|
56
|
+
return { kind: 'valid', issues: [] };
|
|
57
|
+
} catch {
|
|
58
|
+
return { kind: 'invalid', issues: [{ dataPath: '', ruleId: 'existing-template-parser' }] };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export function decodeTemplateSource(source: string) {
|
|
62
|
+
return {
|
|
63
|
+
source,
|
|
64
|
+
format: 'json' as const,
|
|
65
|
+
variantId: 'template-json' as const,
|
|
66
|
+
data: JSON.parse(source) as unknown,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const sourceCompilation = compileSchemaBundle(templateSchemaBundle);
|
|
71
|
+
/** Safe source boundary: preserve raw input separately from diagnostics and normalized values. */
|
|
72
|
+
export function validateTemplateSource(source: string, context: SchemaValidationContext) {
|
|
73
|
+
let consumerId: string | undefined;
|
|
74
|
+
try {
|
|
75
|
+
const descriptor = Object.getOwnPropertyDescriptor(context, 'consumerId');
|
|
76
|
+
if (descriptor && 'value' in descriptor && typeof descriptor.value === 'string')
|
|
77
|
+
consumerId = descriptor.value;
|
|
78
|
+
} catch {
|
|
79
|
+
/* Leave the consumer unspecified when context cannot be inspected safely. */
|
|
80
|
+
}
|
|
81
|
+
let decoded: ReturnType<typeof decodeTemplateSource>;
|
|
82
|
+
try {
|
|
83
|
+
decoded = decodeTemplateSource(source);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
const code =
|
|
86
|
+
error instanceof TypeError && error.message === 'Unrecognized camera profile variant.'
|
|
87
|
+
? ('variant-unrecognized' as const)
|
|
88
|
+
: ('input-format-invalid' as const);
|
|
89
|
+
const diagnostics: readonly [InputDiagnostic & { phase: 'decode' }] = [
|
|
90
|
+
{
|
|
91
|
+
scope: {
|
|
92
|
+
identity: templateSchemaBundle.identity,
|
|
93
|
+
...(consumerId === undefined ? {} : { consumerId }),
|
|
94
|
+
},
|
|
95
|
+
phase: 'decode',
|
|
96
|
+
code,
|
|
97
|
+
dataPath: '',
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
return { source, result: { kind: 'invalid' as const, diagnostics } };
|
|
101
|
+
}
|
|
102
|
+
const compilation = sourceCompilation;
|
|
103
|
+
if (compilation.kind !== 'compiled') return { ...decoded, result: compilation };
|
|
104
|
+
return {
|
|
105
|
+
...decoded,
|
|
106
|
+
result: validateSchemaInput(compilation.validator, decoded.data as SchemaJsonValue, {
|
|
107
|
+
context,
|
|
108
|
+
ownerValidate: validateTemplateInput,
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
111
|
+
}
|
package/src/extension.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {fixedInputRegistration} from './fixed-input-editors.js';
|
|
2
|
+
import {registerSourceEditors} from './source-editors.js';
|
|
3
|
+
import {validateTemplateNode, type TemplateNode} from './template-validation.js';
|
|
1
4
|
import {extensionConfig} from './config';
|
|
2
5
|
import definitions from './block-definitions.json';
|
|
3
6
|
import {
|
|
@@ -26,15 +29,6 @@ interface BlockDefinition {
|
|
|
26
29
|
arguments: Record<string, DefinitionArgument>;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
interface TemplateNode {
|
|
30
|
-
type?: string;
|
|
31
|
-
id?: string;
|
|
32
|
-
class?: string | string[];
|
|
33
|
-
classes?: string[];
|
|
34
|
-
data?: Record<string, unknown>;
|
|
35
|
-
attributes?: Record<string, unknown>;
|
|
36
|
-
children?: TemplateNode[];
|
|
37
|
-
}
|
|
38
32
|
|
|
39
33
|
interface SceneNode {
|
|
40
34
|
id: string;
|
|
@@ -141,15 +135,7 @@ interface VrmHostElement {
|
|
|
141
135
|
const blockDefinitions = definitions.blocks as readonly BlockDefinition[];
|
|
142
136
|
const ROOT_ID = 'scene';
|
|
143
137
|
const DOM_EVENT_TYPES = ['click', 'tap', 'pointerenter', 'pointerleave'] as const;
|
|
144
|
-
|
|
145
|
-
'attributes',
|
|
146
|
-
'children',
|
|
147
|
-
'class',
|
|
148
|
-
'classes',
|
|
149
|
-
'data',
|
|
150
|
-
'id',
|
|
151
|
-
'type'
|
|
152
|
-
]);
|
|
138
|
+
|
|
153
139
|
|
|
154
140
|
export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
155
141
|
private readonly nodes = new Map<string, SceneNode>();
|
|
@@ -167,7 +153,17 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
167
153
|
private disposed = false;
|
|
168
154
|
private readonly vrms = new VrmAvatars(() => this.getThree() as unknown as VrmThreeApi | null);
|
|
169
155
|
|
|
156
|
+
private readonly removeSourceEditors: () => void;
|
|
157
|
+
private readonly handleSourceEditorDispose = (): void => {
|
|
158
|
+
this.removeSourceEditors();
|
|
159
|
+
const runtime = Scratch.vm?.runtime as {off?: (event: string, listener: () => void) => void} | undefined;
|
|
160
|
+
runtime?.off?.('RUNTIME_DISPOSED', this.handleSourceEditorDispose);
|
|
161
|
+
};
|
|
162
|
+
|
|
170
163
|
public constructor() {
|
|
164
|
+
this.removeSourceEditors = registerSourceEditors(Scratch);
|
|
165
|
+
const editorRuntime = Scratch.vm?.runtime as {on?: (event: string, listener: () => void) => void} | undefined;
|
|
166
|
+
editorRuntime?.on?.('RUNTIME_DISPOSED', this.handleSourceEditorDispose);
|
|
171
167
|
this.resetGraph();
|
|
172
168
|
this.runtimeCapability = createRuntimeCapability(
|
|
173
169
|
{
|
|
@@ -204,13 +200,17 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
204
200
|
if (runtime) runtime[runtimeCapabilityKey] = this.runtimeCapability;
|
|
205
201
|
}
|
|
206
202
|
|
|
203
|
+
private readonly fixedEditors = fixedInputRegistration(Scratch);
|
|
204
|
+
|
|
207
205
|
public getInfo(): Record<string, unknown> {
|
|
206
|
+
const blocks = blockDefinitions.map((block) => this.toScratchBlock(block));
|
|
207
|
+
this.fixedEditors.ensure(blocks.map(block => `${extensionConfig.id}_${block.opcode}`));
|
|
208
208
|
return {
|
|
209
209
|
id: extensionConfig.id,
|
|
210
210
|
name: Scratch.translate(definitions.extensionName),
|
|
211
211
|
docsURI: extensionConfig.docsURI,
|
|
212
212
|
blockIconURI: extensionConfig.blockIconURI,
|
|
213
|
-
blocks
|
|
213
|
+
blocks
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
|
|
@@ -638,8 +638,10 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
638
638
|
}
|
|
639
639
|
|
|
640
640
|
public dispose(): void {
|
|
641
|
+
this.fixedEditors.dispose();
|
|
641
642
|
if (this.disposed) return;
|
|
642
643
|
this.disposed = true;
|
|
644
|
+
this.handleSourceEditorDispose();
|
|
643
645
|
for (const key of [...this.animationPlaybacks.keys()]) {
|
|
644
646
|
this.stopPlayback(key, true);
|
|
645
647
|
}
|
|
@@ -1235,68 +1237,10 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
1235
1237
|
|
|
1236
1238
|
private parseTemplate(source: string): TemplateNode {
|
|
1237
1239
|
const value: unknown = JSON.parse(source);
|
|
1238
|
-
|
|
1240
|
+
validateTemplateNode(value, 'template');
|
|
1239
1241
|
return value as TemplateNode;
|
|
1240
1242
|
}
|
|
1241
1243
|
|
|
1242
|
-
private validateTemplateNode(value: unknown, path: string): asserts value is TemplateNode {
|
|
1243
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
1244
|
-
throw new TypeError(`A-Frame ${path} must be an object.`);
|
|
1245
|
-
}
|
|
1246
|
-
const node = value as Record<string, unknown>;
|
|
1247
|
-
for (const key of Object.keys(node)) {
|
|
1248
|
-
if (!TEMPLATE_NODE_KEYS.has(key)) {
|
|
1249
|
-
throw new TypeError(`A-Frame ${path}.${key} is not supported.`);
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
this.validateOptionalString(node['type'], `${path}.type`);
|
|
1253
|
-
this.validateOptionalString(node['id'], `${path}.id`);
|
|
1254
|
-
this.validateTemplateClass(node['class'], `${path}.class`);
|
|
1255
|
-
this.validateOptionalStringArray(node['classes'], `${path}.classes`);
|
|
1256
|
-
this.validateStringRecord(node['data'], `${path}.data`);
|
|
1257
|
-
this.validateStringRecord(node['attributes'], `${path}.attributes`);
|
|
1258
|
-
const children = node['children'];
|
|
1259
|
-
if (children === undefined) return;
|
|
1260
|
-
if (!Array.isArray(children)) {
|
|
1261
|
-
throw new TypeError(`A-Frame ${path}.children must be an array.`);
|
|
1262
|
-
}
|
|
1263
|
-
children.forEach((child, index) => {
|
|
1264
|
-
this.validateTemplateNode(child, `${path}.children[${index}]`);
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
private validateTemplateClass(value: unknown, path: string): void {
|
|
1269
|
-
if (value === undefined || typeof value === 'string') return;
|
|
1270
|
-
if (Array.isArray(value) && value.every((item) => typeof item === 'string')) return;
|
|
1271
|
-
throw new TypeError(`A-Frame ${path} must be a string or string array.`);
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
private validateOptionalStringArray(value: unknown, path: string): void {
|
|
1275
|
-
if (value === undefined) return;
|
|
1276
|
-
if (Array.isArray(value) && value.every((item) => typeof item === 'string')) return;
|
|
1277
|
-
throw new TypeError(`A-Frame ${path} must be a string array.`);
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
private validateOptionalString(value: unknown, path: string): void {
|
|
1281
|
-
if (value === undefined || typeof value === 'string') return;
|
|
1282
|
-
throw new TypeError(`A-Frame ${path} must be a string.`);
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
private validateStringRecord(value: unknown, path: string): void {
|
|
1286
|
-
if (value === undefined) return;
|
|
1287
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
1288
|
-
throw new TypeError(`A-Frame ${path} must be an object.`);
|
|
1289
|
-
}
|
|
1290
|
-
for (const [key, recordValue] of Object.entries(value)) {
|
|
1291
|
-
if (key.trim().length === 0) {
|
|
1292
|
-
throw new TypeError(`A-Frame ${path} keys must be non-empty strings.`);
|
|
1293
|
-
}
|
|
1294
|
-
if (recordValue === undefined) {
|
|
1295
|
-
throw new TypeError(`A-Frame ${path}.${key} must not be undefined.`);
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
1244
|
private normalizeClasses(template: TemplateNode): string[] {
|
|
1301
1245
|
const classes = [
|
|
1302
1246
|
...(Array.isArray(template.class) ? template.class : String(template.class ?? '').split(/\s+/)),
|