@kubohiroya/turbowarp-aframe 0.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.
@@ -0,0 +1,329 @@
1
+ {
2
+ "extensionName": "TurboWarp-A-Frame",
3
+ "blocks": [
4
+ {
5
+ "opcode": "createScene",
6
+ "blockType": "COMMAND",
7
+ "text": "create 3D scene with layer [LAYER] mode [MODE]",
8
+ "description": "Initializes the A-Frame scene host and emits the scene ready event.",
9
+ "arguments": {
10
+ "LAYER": {"type": "STRING", "defaultValue": "above-stage"},
11
+ "MODE": {"type": "STRING", "defaultValue": "3d"}
12
+ }
13
+ },
14
+ {
15
+ "opcode": "loadTemplate",
16
+ "blockType": "COMMAND",
17
+ "text": "load template [ID] from JSON [SOURCE]",
18
+ "description": "Stores a declarative scene graph template for later instantiation.",
19
+ "arguments": {
20
+ "ID": {"type": "STRING", "defaultValue": "monster"},
21
+ "SOURCE": {
22
+ "type": "STRING",
23
+ "defaultValue": "{\"type\":\"box\",\"id\":\"body\",\"attributes\":{\"color\":\"#4cffb0\"}}"
24
+ }
25
+ }
26
+ },
27
+ {
28
+ "opcode": "createNode",
29
+ "blockType": "COMMAND",
30
+ "text": "create [TYPE] node id [ID] under [PARENT]",
31
+ "description": "Creates a primitive, model, text, light, camera, or group node.",
32
+ "arguments": {
33
+ "TYPE": {"type": "STRING", "defaultValue": "box"},
34
+ "ID": {"type": "STRING", "defaultValue": "card"},
35
+ "PARENT": {"type": "STRING", "defaultValue": "#scene"}
36
+ }
37
+ },
38
+ {
39
+ "opcode": "createFromTemplate",
40
+ "blockType": "COMMAND",
41
+ "text": "create template [TEMPLATE] as [INSTANCE] under [PARENT]",
42
+ "description": "Instantiates a stored template under the first node matching the parent selector.",
43
+ "arguments": {
44
+ "TEMPLATE": {"type": "STRING", "defaultValue": "monster"},
45
+ "INSTANCE": {"type": "STRING", "defaultValue": "monster-1"},
46
+ "PARENT": {"type": "STRING", "defaultValue": "#scene"}
47
+ }
48
+ },
49
+ {
50
+ "opcode": "setPosition",
51
+ "blockType": "COMMAND",
52
+ "text": "set selector [SELECTOR] position x [X] y [Y] z [Z]",
53
+ "description": "Sets local position on every node matching the selector.",
54
+ "arguments": {
55
+ "SELECTOR": {"type": "STRING", "defaultValue": "#card"},
56
+ "X": {"type": "NUMBER", "defaultValue": 0},
57
+ "Y": {"type": "NUMBER", "defaultValue": 1},
58
+ "Z": {"type": "NUMBER", "defaultValue": -3}
59
+ }
60
+ },
61
+ {
62
+ "opcode": "moveBy",
63
+ "blockType": "COMMAND",
64
+ "text": "move selector [SELECTOR] by x [X] y [Y] z [Z]",
65
+ "description": "Offsets local position on every node matching the selector.",
66
+ "arguments": {
67
+ "SELECTOR": {"type": "STRING", "defaultValue": "#card"},
68
+ "X": {"type": "NUMBER", "defaultValue": 0},
69
+ "Y": {"type": "NUMBER", "defaultValue": 0},
70
+ "Z": {"type": "NUMBER", "defaultValue": 1}
71
+ }
72
+ },
73
+ {
74
+ "opcode": "setRotation",
75
+ "blockType": "COMMAND",
76
+ "text": "set selector [SELECTOR] rotation x [X] y [Y] z [Z]",
77
+ "description": "Sets local Euler rotation in degrees on every node matching the selector.",
78
+ "arguments": {
79
+ "SELECTOR": {"type": "STRING", "defaultValue": "#card"},
80
+ "X": {"type": "NUMBER", "defaultValue": 0},
81
+ "Y": {"type": "NUMBER", "defaultValue": 45},
82
+ "Z": {"type": "NUMBER", "defaultValue": 0}
83
+ }
84
+ },
85
+ {
86
+ "opcode": "addClass",
87
+ "blockType": "COMMAND",
88
+ "text": "add class [CLASS] to selector [SELECTOR]",
89
+ "description": "Adds a CSS-style class to every node matching the selector.",
90
+ "arguments": {
91
+ "CLASS": {"type": "STRING", "defaultValue": "monster"},
92
+ "SELECTOR": {"type": "STRING", "defaultValue": "#card"}
93
+ }
94
+ },
95
+ {
96
+ "opcode": "setData",
97
+ "blockType": "COMMAND",
98
+ "text": "set selector [SELECTOR] data [KEY] to [VALUE]",
99
+ "description": "Sets a data-* value on every node matching the selector.",
100
+ "arguments": {
101
+ "SELECTOR": {"type": "STRING", "defaultValue": "#card"},
102
+ "KEY": {"type": "STRING", "defaultValue": "zone"},
103
+ "VALUE": {"type": "STRING", "defaultValue": "field"}
104
+ }
105
+ },
106
+ {
107
+ "opcode": "setAttribute",
108
+ "blockType": "COMMAND",
109
+ "text": "set selector [SELECTOR] attribute [NAME] to [VALUE]",
110
+ "description": "Sets an A-Frame component or HTML attribute on every node matching the selector.",
111
+ "arguments": {
112
+ "SELECTOR": {"type": "STRING", "defaultValue": "#card"},
113
+ "NAME": {"type": "STRING", "defaultValue": "visible"},
114
+ "VALUE": {"type": "STRING", "defaultValue": "true"}
115
+ }
116
+ },
117
+ {
118
+ "opcode": "deleteSelector",
119
+ "blockType": "COMMAND",
120
+ "text": "delete selector [SELECTOR]",
121
+ "description": "Deletes every non-root node matching the selector and its descendants.",
122
+ "arguments": {
123
+ "SELECTOR": {"type": "STRING", "defaultValue": "#card"}
124
+ }
125
+ },
126
+ {
127
+ "opcode": "countSelector",
128
+ "blockType": "REPORTER",
129
+ "text": "count selector [SELECTOR]",
130
+ "description": "Returns the number of nodes matching a limited selector.",
131
+ "arguments": {
132
+ "SELECTOR": {"type": "STRING", "defaultValue": ".monster"}
133
+ }
134
+ },
135
+ {
136
+ "opcode": "eventTargetId",
137
+ "blockType": "REPORTER",
138
+ "text": "event target id",
139
+ "description": "Returns the id of the most recently handled 3D event target.",
140
+ "arguments": {}
141
+ },
142
+ {
143
+ "opcode": "emitEvent",
144
+ "blockType": "COMMAND",
145
+ "text": "emit 3D event [TYPE] from selector [SELECTOR] with data [DATA]",
146
+ "description": "Queues and dispatches a 3D event from the first node matching the selector.",
147
+ "arguments": {
148
+ "TYPE": {"type": "STRING", "defaultValue": "attack"},
149
+ "SELECTOR": {"type": "STRING", "defaultValue": "#card"},
150
+ "DATA": {"type": "STRING", "defaultValue": "{}"}
151
+ }
152
+ },
153
+ {
154
+ "opcode": "whenSceneReady",
155
+ "blockType": "HAT",
156
+ "text": "when 3D scene ready",
157
+ "description": "Fires once after create 3D scene initializes the scene host.",
158
+ "arguments": {}
159
+ },
160
+ {
161
+ "opcode": "whenEventOnSelector",
162
+ "blockType": "HAT",
163
+ "text": "when event [TYPE] on selector [SELECTOR]",
164
+ "description": "Fires when a queued 3D event of the given type targets a node matching the selector.",
165
+ "arguments": {
166
+ "TYPE": {"type": "STRING", "defaultValue": "attack"},
167
+ "SELECTOR": {"type": "STRING", "defaultValue": ".monster"}
168
+ }
169
+ },
170
+ {
171
+ "opcode": "createAnimationClip",
172
+ "blockType": "COMMAND",
173
+ "text": "create 3D animation clip [NAME] duration [DURATION]",
174
+ "description": "Creates or replaces a Three.js AnimationClip definition.",
175
+ "arguments": {
176
+ "NAME": {"type": "STRING", "defaultValue": "wave"},
177
+ "DURATION": {"type": "NUMBER", "defaultValue": -1}
178
+ }
179
+ },
180
+ {
181
+ "opcode": "deleteAnimationClip",
182
+ "blockType": "COMMAND",
183
+ "text": "delete 3D animation clip [NAME]",
184
+ "description": "Deletes a stored 3D animation clip definition and stops its active actions.",
185
+ "arguments": {
186
+ "NAME": {"type": "STRING", "defaultValue": "wave"}
187
+ }
188
+ },
189
+ {
190
+ "opcode": "addVectorKeyframeTrack",
191
+ "blockType": "COMMAND",
192
+ "text": "add vector keyframe track to clip [CLIP] path [PATH] times [TIMES] values [VALUES]",
193
+ "description": "Adds a Three.js VectorKeyframeTrack definition with x y z values.",
194
+ "arguments": {
195
+ "CLIP": {"type": "STRING", "defaultValue": "move-up"},
196
+ "PATH": {"type": "STRING", "defaultValue": ".position"},
197
+ "TIMES": {"type": "STRING", "defaultValue": "0,0.5,1"},
198
+ "VALUES": {"type": "STRING", "defaultValue": "0,1,-3, 0,1.5,-3, 0,1,-3"}
199
+ }
200
+ },
201
+ {
202
+ "opcode": "addQuaternionKeyframeTrack",
203
+ "blockType": "COMMAND",
204
+ "text": "add quaternion keyframe track to clip [CLIP] path [PATH] times [TIMES] values [VALUES]",
205
+ "description": "Adds a Three.js QuaternionKeyframeTrack definition with x y z w values.",
206
+ "arguments": {
207
+ "CLIP": {"type": "STRING", "defaultValue": "wave"},
208
+ "PATH": {"type": "STRING", "defaultValue": ".quaternion"},
209
+ "TIMES": {"type": "STRING", "defaultValue": "0,0.5,1"},
210
+ "VALUES": {"type": "STRING", "defaultValue": "0,0,0,1, 0,0,0.389,0.921, 0,0,0,1"}
211
+ }
212
+ },
213
+ {
214
+ "opcode": "addEulerRotationKeyframeTrack",
215
+ "blockType": "COMMAND",
216
+ "text": "add euler rotation keyframe track to clip [CLIP] path [PATH] times [TIMES] values [VALUES] unit [UNIT]",
217
+ "description": "Adds a quaternion track converted from Euler x y z rotation values.",
218
+ "arguments": {
219
+ "CLIP": {"type": "STRING", "defaultValue": "wave"},
220
+ "PATH": {"type": "STRING", "defaultValue": ".quaternion"},
221
+ "TIMES": {"type": "STRING", "defaultValue": "0,0.25,0.5,0.75,1"},
222
+ "VALUES": {"type": "STRING", "defaultValue": "0,0,0, 0,0,0.8, 0,0,0, 0,0,-0.8, 0,0,0"},
223
+ "UNIT": {"type": "STRING", "defaultValue": "radians"}
224
+ }
225
+ },
226
+ {
227
+ "opcode": "addPositionKeyframe",
228
+ "blockType": "COMMAND",
229
+ "text": "add position keyframe to clip [CLIP] at [TIME] x [X] y [Y] z [Z]",
230
+ "description": "Adds or replaces one position keyframe on the clip.",
231
+ "arguments": {
232
+ "CLIP": {"type": "STRING", "defaultValue": "move-up"},
233
+ "TIME": {"type": "NUMBER", "defaultValue": 0},
234
+ "X": {"type": "NUMBER", "defaultValue": 0},
235
+ "Y": {"type": "NUMBER", "defaultValue": 1},
236
+ "Z": {"type": "NUMBER", "defaultValue": -3}
237
+ }
238
+ },
239
+ {
240
+ "opcode": "addScaleKeyframe",
241
+ "blockType": "COMMAND",
242
+ "text": "add scale keyframe to clip [CLIP] at [TIME] x [X] y [Y] z [Z]",
243
+ "description": "Adds or replaces one scale keyframe on the clip.",
244
+ "arguments": {
245
+ "CLIP": {"type": "STRING", "defaultValue": "pulse"},
246
+ "TIME": {"type": "NUMBER", "defaultValue": 0},
247
+ "X": {"type": "NUMBER", "defaultValue": 1},
248
+ "Y": {"type": "NUMBER", "defaultValue": 1},
249
+ "Z": {"type": "NUMBER", "defaultValue": 1}
250
+ }
251
+ },
252
+ {
253
+ "opcode": "addEulerRotationKeyframe",
254
+ "blockType": "COMMAND",
255
+ "text": "add euler rotation keyframe to clip [CLIP] at [TIME] x [X] y [Y] z [Z] unit [UNIT]",
256
+ "description": "Adds or replaces one Euler rotation keyframe converted to quaternion values.",
257
+ "arguments": {
258
+ "CLIP": {"type": "STRING", "defaultValue": "wave"},
259
+ "TIME": {"type": "NUMBER", "defaultValue": 0},
260
+ "X": {"type": "NUMBER", "defaultValue": 0},
261
+ "Y": {"type": "NUMBER", "defaultValue": 0},
262
+ "Z": {"type": "NUMBER", "defaultValue": 0.8},
263
+ "UNIT": {"type": "STRING", "defaultValue": "radians"}
264
+ }
265
+ },
266
+ {
267
+ "opcode": "playAnimationClip",
268
+ "blockType": "COMMAND",
269
+ "text": "play 3D animation clip [CLIP] on selector [SELECTOR] loop [LOOP]",
270
+ "description": "Plays a stored 3D animation clip on every matching node.",
271
+ "arguments": {
272
+ "CLIP": {"type": "STRING", "defaultValue": "wave"},
273
+ "SELECTOR": {"type": "STRING", "defaultValue": "#leftArm"},
274
+ "LOOP": {"type": "BOOLEAN", "defaultValue": true}
275
+ }
276
+ },
277
+ {
278
+ "opcode": "stopAnimationClip",
279
+ "blockType": "COMMAND",
280
+ "text": "stop 3D animation clip [CLIP] on selector [SELECTOR]",
281
+ "description": "Stops a stored 3D animation clip on every matching node.",
282
+ "arguments": {
283
+ "CLIP": {"type": "STRING", "defaultValue": "wave"},
284
+ "SELECTOR": {"type": "STRING", "defaultValue": "#leftArm"}
285
+ }
286
+ },
287
+ {
288
+ "opcode": "pauseAnimationClip",
289
+ "blockType": "COMMAND",
290
+ "text": "pause 3D animation clip [CLIP] on selector [SELECTOR]",
291
+ "description": "Pauses a stored 3D animation clip on every matching node.",
292
+ "arguments": {
293
+ "CLIP": {"type": "STRING", "defaultValue": "wave"},
294
+ "SELECTOR": {"type": "STRING", "defaultValue": "#leftArm"}
295
+ }
296
+ },
297
+ {
298
+ "opcode": "resumeAnimationClip",
299
+ "blockType": "COMMAND",
300
+ "text": "resume 3D animation clip [CLIP] on selector [SELECTOR]",
301
+ "description": "Resumes a paused 3D animation clip on every matching node.",
302
+ "arguments": {
303
+ "CLIP": {"type": "STRING", "defaultValue": "wave"},
304
+ "SELECTOR": {"type": "STRING", "defaultValue": "#leftArm"}
305
+ }
306
+ },
307
+ {
308
+ "opcode": "setAnimationTimeScale",
309
+ "blockType": "COMMAND",
310
+ "text": "set 3D animation clip [CLIP] on selector [SELECTOR] time scale [SCALE]",
311
+ "description": "Sets the playback speed for a stored 3D animation clip on every matching node.",
312
+ "arguments": {
313
+ "CLIP": {"type": "STRING", "defaultValue": "wave"},
314
+ "SELECTOR": {"type": "STRING", "defaultValue": "#leftArm"},
315
+ "SCALE": {"type": "NUMBER", "defaultValue": 1}
316
+ }
317
+ },
318
+ {
319
+ "opcode": "isAnimationClipPlaying",
320
+ "blockType": "BOOLEAN",
321
+ "text": "is 3D animation clip [CLIP] playing on selector [SELECTOR]?",
322
+ "description": "Reports whether any matching node has the stored 3D animation clip playing.",
323
+ "arguments": {
324
+ "CLIP": {"type": "STRING", "defaultValue": "wave"},
325
+ "SELECTOR": {"type": "STRING", "defaultValue": "#leftArm"}
326
+ }
327
+ }
328
+ ]
329
+ }
package/src/config.ts ADDED
@@ -0,0 +1,12 @@
1
+ export const extensionConfig = {
2
+ id: 'turbowarpaframe',
3
+ slug: 'turbowarp-aframe',
4
+ name: 'TurboWarp-A-Frame',
5
+ description: 'A TurboWarp extension for declarative A-Frame scene graphs.',
6
+ author: 'Hiroya Kubo',
7
+ license: 'MPL-2.0',
8
+ unsandboxed: true,
9
+ docsURI: 'https://kubohiroya.github.io/turbowarp-aframe/',
10
+ blockIconURI:
11
+ 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCI+PHJlY3QgeD0iNiIgeT0iOCIgd2lkdGg9IjM2IiBoZWlnaHQ9IjMyIiByeD0iNCIgZmlsbD0iIzEyMTgyNiIvPjxwYXRoIGQ9Ik0xNCAzMmw5LTE4IDkgMThoLTRsLTItNWgtNmwtMiA1aC00Wm03LjQtOGgzLjJsLTEuNi00LjEtMS42IDQuMVoiIGZpbGw9IiM0Q0ZGQjAiLz48Y2lyY2xlIGN4PSIzNiIgY3k9IjE0IiByPSI0IiBmaWxsPSIjRkZBQjE5Ii8+PC9zdmc+'
12
+ } as const;
@@ -0,0 +1,149 @@
1
+ import type {Plugin} from 'vite';
2
+
3
+ export const EXTENSION_MANIFEST_FORMAT_VERSION = 1 as const;
4
+
5
+ export interface ExtensionManifestArgument {
6
+ id: string;
7
+ type: string;
8
+ menu?: string;
9
+ }
10
+
11
+ export interface ExtensionManifestBlock {
12
+ opcode: string;
13
+ blockType: string;
14
+ arguments: ExtensionManifestArgument[];
15
+ }
16
+
17
+ export interface ExtensionManifestMenu {
18
+ id: string;
19
+ acceptReporters: boolean;
20
+ }
21
+
22
+ export interface ExtensionManifest {
23
+ formatVersion: typeof EXTENSION_MANIFEST_FORMAT_VERSION;
24
+ id: string;
25
+ blocks: ExtensionManifestBlock[];
26
+ menus: ExtensionManifestMenu[];
27
+ }
28
+
29
+ export interface ExtensionManifestPluginOptions {
30
+ id: string;
31
+ definitions: unknown;
32
+ fileName?: string;
33
+ }
34
+
35
+ export function createExtensionManifest(id: string, definitions: unknown): ExtensionManifest {
36
+ if (!/^[a-z0-9]+$/.test(id)) {
37
+ throw new TypeError('Extension manifest ID must contain only lowercase letters and numbers.');
38
+ }
39
+
40
+ const source = requireRecord(definitions, 'Block definitions');
41
+ const sourceBlocks = source.blocks;
42
+ if (!Array.isArray(sourceBlocks)) {
43
+ throw new TypeError('Block definitions must contain a blocks array.');
44
+ }
45
+
46
+ const menus = normalizeMenus(source.menus);
47
+ const menuIds = new Set(menus.map((menu) => menu.id));
48
+ const seenOpcodes = new Set<string>();
49
+ const blocks = sourceBlocks.map((block, index) => {
50
+ const normalized = normalizeBlock(block, index, menuIds);
51
+ if (seenOpcodes.has(normalized.opcode)) {
52
+ throw new TypeError(`Duplicate block opcode: ${normalized.opcode}`);
53
+ }
54
+ seenOpcodes.add(normalized.opcode);
55
+ return normalized;
56
+ });
57
+
58
+ return {
59
+ formatVersion: EXTENSION_MANIFEST_FORMAT_VERSION,
60
+ id,
61
+ blocks: blocks.sort((left, right) => compareIds(left.opcode, right.opcode)),
62
+ menus
63
+ };
64
+ }
65
+
66
+ export function serializeExtensionManifest(id: string, definitions: unknown): string {
67
+ return `${JSON.stringify(createExtensionManifest(id, definitions), null, 2)}\n`;
68
+ }
69
+
70
+ export function extensionManifestPlugin(options: ExtensionManifestPluginOptions): Plugin {
71
+ return {
72
+ name: 'extension-api-manifest',
73
+ apply: 'build',
74
+ enforce: 'post',
75
+ generateBundle() {
76
+ this.emitFile({
77
+ type: 'asset',
78
+ fileName: options.fileName ?? 'extension-manifest.json',
79
+ source: serializeExtensionManifest(options.id, options.definitions)
80
+ });
81
+ }
82
+ };
83
+ }
84
+
85
+ function normalizeBlock(
86
+ value: unknown,
87
+ index: number,
88
+ menuIds: ReadonlySet<string>
89
+ ): ExtensionManifestBlock {
90
+ const block = requireRecord(value, `Block at index ${index}`);
91
+ const opcode = requireNonEmptyString(block.opcode, `Block at index ${index} opcode`);
92
+ const blockType = requireNonEmptyString(block.blockType, `Block ${opcode} blockType`);
93
+ const sourceArguments = block.arguments ?? {};
94
+ const argumentRecord = requireRecord(sourceArguments, `Block ${opcode} arguments`);
95
+ const argumentsList = Object.entries(argumentRecord).map(([argumentId, argument]) => {
96
+ requireNonEmptyString(argumentId, `Block ${opcode} argument ID`);
97
+ const definition = requireRecord(argument, `Block ${opcode} argument ${argumentId}`);
98
+ const type = requireNonEmptyString(
99
+ definition.type,
100
+ `Block ${opcode} argument ${argumentId} type`
101
+ );
102
+ const menu = definition.menu;
103
+ if (menu !== undefined && (typeof menu !== 'string' || !menuIds.has(menu))) {
104
+ throw new TypeError(`Block ${opcode} argument ${argumentId} references unknown menu: ${menu}`);
105
+ }
106
+ return menu === undefined ? {id: argumentId, type} : {id: argumentId, type, menu};
107
+ });
108
+
109
+ return {
110
+ opcode,
111
+ blockType,
112
+ arguments: argumentsList.sort((left, right) => compareIds(left.id, right.id))
113
+ };
114
+ }
115
+
116
+ function normalizeMenus(value: unknown): ExtensionManifestMenu[] {
117
+ const menuRecord = requireRecord(value ?? {}, 'Block definition menus');
118
+ return Object.entries(menuRecord)
119
+ .map(([id, menu]) => {
120
+ requireNonEmptyString(id, 'Menu ID');
121
+ const definition = requireRecord(menu, `Menu ${id}`);
122
+ const acceptReporters = definition.acceptReporters ?? false;
123
+ if (typeof acceptReporters !== 'boolean') {
124
+ throw new TypeError(`Menu ${id} acceptReporters must be a boolean.`);
125
+ }
126
+ return {id, acceptReporters};
127
+ })
128
+ .sort((left, right) => compareIds(left.id, right.id));
129
+ }
130
+
131
+ function requireRecord(value: unknown, label: string): Record<string, unknown> {
132
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
133
+ throw new TypeError(`${label} must be an object.`);
134
+ }
135
+ return value as Record<string, unknown>;
136
+ }
137
+
138
+ function requireNonEmptyString(value: unknown, label: string): string {
139
+ if (typeof value !== 'string' || value.length === 0) {
140
+ throw new TypeError(`${label} must be a non-empty string.`);
141
+ }
142
+ return value;
143
+ }
144
+
145
+ function compareIds(left: string, right: string): number {
146
+ if (left < right) return -1;
147
+ if (left > right) return 1;
148
+ return 0;
149
+ }