@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,142 @@
|
|
|
1
|
+
import {parseFixedNumberInput} from '@kubohiroya/turbowarp-extension-data-editor';
|
|
2
|
+
import type {FixedInputBinding, FixedInputEditorOptions, JsonValue, LiteralValue} from '@kubohiroya/turbowarp-extension-data-editor';
|
|
3
|
+
import {fixedInputBundle} from './fixed-input-schema.js';
|
|
4
|
+
|
|
5
|
+
const existingNumber = (value: LiteralValue): number => {
|
|
6
|
+
if ((typeof value !== 'number' && typeof value !== 'string') ||
|
|
7
|
+
(typeof value === 'string' && value.trim() === '')) throw new TypeError('Expected a numeric literal.');
|
|
8
|
+
const number = Number(value);
|
|
9
|
+
if (!Number.isFinite(number)) throw new TypeError('Expected a finite number.');
|
|
10
|
+
return number;
|
|
11
|
+
};
|
|
12
|
+
const newNumber = (value: JsonValue): string => {
|
|
13
|
+
const parsed = parseFixedNumberInput(value);
|
|
14
|
+
if (parsed.kind !== 'valid') throw new TypeError('Invalid new numeric input.');
|
|
15
|
+
return parsed.token;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function binding(opcode: string, argument: string, values?: readonly string[]): FixedInputBinding {
|
|
19
|
+
return {argument, schemaBundle: fixedInputBundle(opcode, argument),
|
|
20
|
+
control: values ? {kind: 'enum', choices: values.map(value => ({value}))} : {kind: 'number'},
|
|
21
|
+
read(value) {
|
|
22
|
+
if (!values) return existingNumber(value);
|
|
23
|
+
if (typeof value !== 'string') throw new TypeError('Expected a string.');
|
|
24
|
+
return projectEnum(opcode, argument, value);
|
|
25
|
+
},
|
|
26
|
+
encode(value) {
|
|
27
|
+
if (!values) return newNumber(value);
|
|
28
|
+
if (typeof value !== 'string' || !values.includes(value)) throw new TypeError('Invalid selection.');
|
|
29
|
+
return value;
|
|
30
|
+
},
|
|
31
|
+
validateCandidate(value) {
|
|
32
|
+
try {
|
|
33
|
+
if (!values) existingNumber(value);
|
|
34
|
+
else if (typeof value !== 'string' || !values.includes(value)) throw new TypeError('Invalid selection.');
|
|
35
|
+
return [];
|
|
36
|
+
} catch {return [{message: 'Invalid fixed input.'}];}
|
|
37
|
+
}};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function projectEnum(_opcode: string, argument: string, value: string): string {
|
|
41
|
+
return argument === 'UNIT' ? value.trim().toLowerCase() : value.trim();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const fixedInputEditors: readonly FixedInputEditorOptions[] = [
|
|
45
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-createScene', opcodes: ['turbowarpaframe_createScene'],
|
|
46
|
+
contractId: 'turbowarp-aframe/createScene', contractRevision: '1',
|
|
47
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
48
|
+
bindings: [binding('createScene', 'LAYER', ["above-stage", "below-stage"])]},
|
|
49
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-setPosition', opcodes: ['turbowarpaframe_setPosition'],
|
|
50
|
+
contractId: 'turbowarp-aframe/setPosition', contractRevision: '1',
|
|
51
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
52
|
+
bindings: [binding('setPosition', 'X'), binding('setPosition', 'Y'), binding('setPosition', 'Z')]},
|
|
53
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-moveBy', opcodes: ['turbowarpaframe_moveBy'],
|
|
54
|
+
contractId: 'turbowarp-aframe/moveBy', contractRevision: '1',
|
|
55
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
56
|
+
bindings: [binding('moveBy', 'X'), binding('moveBy', 'Y'), binding('moveBy', 'Z')]},
|
|
57
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-setRotation', opcodes: ['turbowarpaframe_setRotation'],
|
|
58
|
+
contractId: 'turbowarp-aframe/setRotation', contractRevision: '1',
|
|
59
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
60
|
+
bindings: [binding('setRotation', 'X'), binding('setRotation', 'Y'), binding('setRotation', 'Z')]},
|
|
61
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-createAnimationClip', opcodes: ['turbowarpaframe_createAnimationClip'],
|
|
62
|
+
contractId: 'turbowarp-aframe/createAnimationClip', contractRevision: '1',
|
|
63
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
64
|
+
bindings: [binding('createAnimationClip', 'DURATION')]},
|
|
65
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-addVectorKeyframeTrack', opcodes: ['turbowarpaframe_addVectorKeyframeTrack'],
|
|
66
|
+
contractId: 'turbowarp-aframe/addVectorKeyframeTrack', contractRevision: '1',
|
|
67
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
68
|
+
bindings: [binding('addVectorKeyframeTrack', 'PATH', [".position", ".scale"])]},
|
|
69
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-addQuaternionKeyframeTrack', opcodes: ['turbowarpaframe_addQuaternionKeyframeTrack'],
|
|
70
|
+
contractId: 'turbowarp-aframe/addQuaternionKeyframeTrack', contractRevision: '1',
|
|
71
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
72
|
+
bindings: [binding('addQuaternionKeyframeTrack', 'PATH', [".quaternion"])]},
|
|
73
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-addEulerRotationKeyframeTrack', opcodes: ['turbowarpaframe_addEulerRotationKeyframeTrack'],
|
|
74
|
+
contractId: 'turbowarp-aframe/addEulerRotationKeyframeTrack', contractRevision: '1',
|
|
75
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
76
|
+
bindings: [binding('addEulerRotationKeyframeTrack', 'PATH', [".quaternion"]), binding('addEulerRotationKeyframeTrack', 'UNIT', ["degrees", "radians"])]},
|
|
77
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-addPositionKeyframe', opcodes: ['turbowarpaframe_addPositionKeyframe'],
|
|
78
|
+
contractId: 'turbowarp-aframe/addPositionKeyframe', contractRevision: '1',
|
|
79
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
80
|
+
bindings: [binding('addPositionKeyframe', 'TIME'), binding('addPositionKeyframe', 'X'), binding('addPositionKeyframe', 'Y'), binding('addPositionKeyframe', 'Z')]},
|
|
81
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-addScaleKeyframe', opcodes: ['turbowarpaframe_addScaleKeyframe'],
|
|
82
|
+
contractId: 'turbowarp-aframe/addScaleKeyframe', contractRevision: '1',
|
|
83
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
84
|
+
bindings: [binding('addScaleKeyframe', 'TIME'), binding('addScaleKeyframe', 'X'), binding('addScaleKeyframe', 'Y'), binding('addScaleKeyframe', 'Z')]},
|
|
85
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-addEulerRotationKeyframe', opcodes: ['turbowarpaframe_addEulerRotationKeyframe'],
|
|
86
|
+
contractId: 'turbowarp-aframe/addEulerRotationKeyframe', contractRevision: '1',
|
|
87
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
88
|
+
bindings: [binding('addEulerRotationKeyframe', 'TIME'), binding('addEulerRotationKeyframe', 'X'), binding('addEulerRotationKeyframe', 'Y'), binding('addEulerRotationKeyframe', 'Z'), binding('addEulerRotationKeyframe', 'UNIT', ["degrees", "radians"])]},
|
|
89
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-setAnimationTimeScale', opcodes: ['turbowarpaframe_setAnimationTimeScale'],
|
|
90
|
+
contractId: 'turbowarp-aframe/setAnimationTimeScale', contractRevision: '1',
|
|
91
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
92
|
+
bindings: [binding('setAnimationTimeScale', 'SCALE')]},
|
|
93
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-setVrmBoneRotation', opcodes: ['turbowarpaframe_setVrmBoneRotation'],
|
|
94
|
+
contractId: 'turbowarp-aframe/setVrmBoneRotation', contractRevision: '1',
|
|
95
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
96
|
+
bindings: [binding('setVrmBoneRotation', 'X'), binding('setVrmBoneRotation', 'Y'), binding('setVrmBoneRotation', 'Z')]},
|
|
97
|
+
{apiVersion: 1, extensionId: 'turbowarpaframe', editorId: 'fixed-setVrmExpression', opcodes: ['turbowarpaframe_setVrmExpression'],
|
|
98
|
+
contractId: 'turbowarp-aframe/setVrmExpression', contractRevision: '1',
|
|
99
|
+
validationContext: () => ({consumerId: 'turbowarp-aframe', nowMs: 0, settings: null}),
|
|
100
|
+
bindings: [binding('setVrmExpression', 'WEIGHT')]},
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
interface OptionalHost {
|
|
104
|
+
gui?: {blockEditors?: {apiVersion?: number; registerFixedInputEditor?: (options: FixedInputEditorOptions) => () => void}};
|
|
105
|
+
vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Register only currently declared opcodes; release obsolete feature-flag scopes. */
|
|
109
|
+
export function fixedInputRegistration(scratch: unknown) {
|
|
110
|
+
const host = (typeof scratch === 'object' && scratch !== null ? scratch : {}) as OptionalHost;
|
|
111
|
+
let active: unknown;
|
|
112
|
+
let activeOpcodes = '';
|
|
113
|
+
const removers: (() => void)[] = [];
|
|
114
|
+
let disposed = false;
|
|
115
|
+
const dispose = () => {
|
|
116
|
+
host.vm?.runtime?.off?.('RUNTIME_DISPOSED', shutdown);
|
|
117
|
+
for (const remove of removers.splice(0).reverse()) remove();
|
|
118
|
+
active = undefined; activeOpcodes = '';
|
|
119
|
+
};
|
|
120
|
+
const shutdown = () => {disposed = true; dispose();};
|
|
121
|
+
return {
|
|
122
|
+
ensure(opcodes: readonly string[]) {
|
|
123
|
+
const api = host.gui?.blockEditors;
|
|
124
|
+
const signature = [...new Set(opcodes)].sort().join('\0');
|
|
125
|
+
if (disposed || (api === active && signature === activeOpcodes)) return;
|
|
126
|
+
dispose();
|
|
127
|
+
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== 'function') return;
|
|
128
|
+
try {
|
|
129
|
+
for (const definition of fixedInputEditors) {
|
|
130
|
+
if (definition.opcodes.every(opcode => opcodes.includes(opcode))) {
|
|
131
|
+
const remove = api.registerFixedInputEditor.call(api, definition);
|
|
132
|
+
if (typeof remove !== 'function') throw new TypeError('Invalid fixed registration cleanup.');
|
|
133
|
+
removers.push(remove);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
active = api; activeOpcodes = signature;
|
|
137
|
+
host.vm?.runtime?.on?.('RUNTIME_DISPOSED', shutdown);
|
|
138
|
+
} catch (error) {dispose(); throw error;}
|
|
139
|
+
},
|
|
140
|
+
dispose: shutdown
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import document from '../schemas/block-editor-fixed-inputs.schema.json' with {type: 'json'};
|
|
2
|
+
import type {SchemaBundle, SchemaDocument} from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
3
|
+
|
|
4
|
+
/** Owner canonical fragments, distinct from older SOURCE/editor schemas. */
|
|
5
|
+
export function fixedInputBundle(opcode: string, argument: string): SchemaBundle {
|
|
6
|
+
const source = {repository: 'turbowarp-aframe', path: 'schemas/block-editor-fixed-inputs.schema.json',
|
|
7
|
+
symbol: `#/$defs/${opcode}/properties/${argument}`};
|
|
8
|
+
const fragment = (document.$defs as Record<string, {properties: Record<string, SchemaDocument>}>)[opcode]!.properties[argument]!;
|
|
9
|
+
return {identity: {ownerId: 'turbowarp-aframe', contractId: 'fixed-inputs', revision: '1', variantId: `${opcode}.${argument}`},
|
|
10
|
+
dialect: '2020-12', root: {retrievalUri: document.$id, document: fragment, artifact: {role: 'canonical-schema', source}}, resources: [],
|
|
11
|
+
provenance: {canonicalSources: [source, {repository: 'turbowarp-aframe', path: 'src/extension.ts', symbol: opcode}],
|
|
12
|
+
generatedFiles: [], referenceSchemas: [], generationSources: []}};
|
|
13
|
+
}
|
|
14
|
+
export const fixedSchemas = document.$defs;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {SourceBinding, SourceEditorOptions, SourceValidation} from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
2
|
+
import {extensionConfig} from './config.js';
|
|
3
|
+
|
|
4
|
+
function checkedSource(value: {source: string; result: {kind: 'valid' | 'invalid' | 'execution-error' | 'schema-error'; diagnostics: readonly {code: string; dataPath?: string}[]}}): SourceValidation {
|
|
5
|
+
return value.result.kind === 'valid'
|
|
6
|
+
? {source: value.source, result: {kind: 'valid', diagnostics: []}}
|
|
7
|
+
: {source: value.source, result: {kind: value.result.kind, diagnostics: value.result.diagnostics}};
|
|
8
|
+
}
|
|
9
|
+
import {templateSchemaBundle, decodeTemplateSource, validateTemplateSource} from './editor-schema.js';
|
|
10
|
+
export function createSourceEditorOptions(nowMs: () => number = Date.now): readonly SourceEditorOptions[] {
|
|
11
|
+
const context = () => ({consumerId: extensionConfig.id, nowMs: nowMs(), settings: null});
|
|
12
|
+
return [
|
|
13
|
+
{apiVersion: 1, extensionId: extensionConfig.id, editorId: 'template-source', opcodes: ["loadTemplate"].map(opcode => `${extensionConfig.id}_${opcode}`), bindings: [{argument: 'SOURCE', variants: [{variantId: 'template-json', format: 'json', schemaBundle: templateSchemaBundle}], decode: source => {const decoded = decodeTemplateSource(source); return {...decoded, data: decoded.data as ReturnType<SourceBinding['decode']>['data']};}, validateSource: (source, context) => checkedSource(validateTemplateSource(source, context))}], validationContext: context}
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Optional capability: old GUIs continue executing blocks without editor registration. */
|
|
18
|
+
export function registerSourceEditors(scratch: unknown, nowMs: () => number = Date.now): () => void {
|
|
19
|
+
const api = (scratch as {gui?: {blockEditors?: {apiVersion?: number; registerSourceEditor?: (options: SourceEditorOptions) => () => void}}})?.gui?.blockEditors;
|
|
20
|
+
if (api?.apiVersion !== 1 || typeof api.registerSourceEditor !== 'function') return () => {};
|
|
21
|
+
const removers: (() => void)[] = [];
|
|
22
|
+
try {
|
|
23
|
+
for (const options of createSourceEditorOptions(nowMs)) removers.push(api.registerSourceEditor(options));
|
|
24
|
+
} catch {
|
|
25
|
+
for (const remove of removers.reverse()) remove();
|
|
26
|
+
return () => {};
|
|
27
|
+
}
|
|
28
|
+
let active = true;
|
|
29
|
+
return () => {if (active) {active = false; for (const remove of removers.reverse()) remove();}};
|
|
30
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export interface TemplateNode {
|
|
2
|
+
type?: string;
|
|
3
|
+
id?: string;
|
|
4
|
+
class?: string | string[];
|
|
5
|
+
classes?: string[];
|
|
6
|
+
data?: Record<string, unknown>;
|
|
7
|
+
attributes?: Record<string, unknown>;
|
|
8
|
+
children?: TemplateNode[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const TEMPLATE_NODE_KEYS = new Set([
|
|
13
|
+
'attributes',
|
|
14
|
+
'children',
|
|
15
|
+
'class',
|
|
16
|
+
'classes',
|
|
17
|
+
'data',
|
|
18
|
+
'id',
|
|
19
|
+
'type'
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
export function validateTemplateNode(value: unknown, path: string): asserts value is TemplateNode {
|
|
23
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
24
|
+
throw new TypeError(`A-Frame ${path} must be an object.`);
|
|
25
|
+
}
|
|
26
|
+
const node = value as Record<string, unknown>;
|
|
27
|
+
for (const key of Object.keys(node)) {
|
|
28
|
+
if (!TEMPLATE_NODE_KEYS.has(key)) {
|
|
29
|
+
throw new TypeError(`A-Frame ${path}.${key} is not supported.`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
validateOptionalString(node['type'], `${path}.type`);
|
|
33
|
+
validateOptionalString(node['id'], `${path}.id`);
|
|
34
|
+
validateTemplateClass(node['class'], `${path}.class`);
|
|
35
|
+
validateOptionalStringArray(node['classes'], `${path}.classes`);
|
|
36
|
+
validateStringRecord(node['data'], `${path}.data`);
|
|
37
|
+
validateStringRecord(node['attributes'], `${path}.attributes`);
|
|
38
|
+
const children = node['children'];
|
|
39
|
+
if (children === undefined) return;
|
|
40
|
+
if (!Array.isArray(children)) {
|
|
41
|
+
throw new TypeError(`A-Frame ${path}.children must be an array.`);
|
|
42
|
+
}
|
|
43
|
+
children.forEach((child, index) => {
|
|
44
|
+
validateTemplateNode(child, `${path}.children[${index}]`);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function validateTemplateClass(value: unknown, path: string): void {
|
|
49
|
+
if (value === undefined || typeof value === 'string') return;
|
|
50
|
+
if (Array.isArray(value) && value.every((item) => typeof item === 'string')) return;
|
|
51
|
+
throw new TypeError(`A-Frame ${path} must be a string or string array.`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function validateOptionalStringArray(value: unknown, path: string): void {
|
|
55
|
+
if (value === undefined) return;
|
|
56
|
+
if (Array.isArray(value) && value.every((item) => typeof item === 'string')) return;
|
|
57
|
+
throw new TypeError(`A-Frame ${path} must be a string array.`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function validateOptionalString(value: unknown, path: string): void {
|
|
61
|
+
if (value === undefined || typeof value === 'string') return;
|
|
62
|
+
throw new TypeError(`A-Frame ${path} must be a string.`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function validateStringRecord(value: unknown, path: string): void {
|
|
66
|
+
if (value === undefined) return;
|
|
67
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
68
|
+
throw new TypeError(`A-Frame ${path} must be an object.`);
|
|
69
|
+
}
|
|
70
|
+
for (const [key, recordValue] of Object.entries(value)) {
|
|
71
|
+
if (key.trim().length === 0) {
|
|
72
|
+
throw new TypeError(`A-Frame ${path} keys must be non-empty strings.`);
|
|
73
|
+
}
|
|
74
|
+
if (recordValue === undefined) {
|
|
75
|
+
throw new TypeError(`A-Frame ${path}.${key} must not be undefined.`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://raw.githubusercontent.com/kubohiroya/turbowarp-aframe/main/schemas/extension-manifest.schema.json",
|
|
4
|
-
"title": "TurboWarp Extension API Manifest",
|
|
5
|
-
"type": "object",
|
|
6
|
-
"additionalProperties": false,
|
|
7
|
-
"required": ["formatVersion", "id", "blocks", "menus"],
|
|
8
|
-
"properties": {
|
|
9
|
-
"formatVersion": {"const": 1},
|
|
10
|
-
"id": {"type": "string", "pattern": "^[a-z0-9]+$"},
|
|
11
|
-
"blocks": {
|
|
12
|
-
"type": "array",
|
|
13
|
-
"items": {
|
|
14
|
-
"type": "object",
|
|
15
|
-
"additionalProperties": false,
|
|
16
|
-
"required": ["opcode", "blockType", "arguments"],
|
|
17
|
-
"properties": {
|
|
18
|
-
"opcode": {"type": "string", "minLength": 1},
|
|
19
|
-
"blockType": {"type": "string", "minLength": 1},
|
|
20
|
-
"arguments": {
|
|
21
|
-
"type": "array",
|
|
22
|
-
"items": {
|
|
23
|
-
"type": "object",
|
|
24
|
-
"additionalProperties": false,
|
|
25
|
-
"required": ["id", "type"],
|
|
26
|
-
"properties": {
|
|
27
|
-
"id": {"type": "string", "minLength": 1},
|
|
28
|
-
"type": {"type": "string", "minLength": 1},
|
|
29
|
-
"menu": {"type": "string", "minLength": 1}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"menus": {
|
|
37
|
-
"type": "array",
|
|
38
|
-
"items": {
|
|
39
|
-
"type": "object",
|
|
40
|
-
"additionalProperties": false,
|
|
41
|
-
"required": ["id", "acceptReporters"],
|
|
42
|
-
"properties": {
|
|
43
|
-
"id": {"type": "string", "minLength": 1},
|
|
44
|
-
"acceptReporters": {"type": "boolean"}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
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
|
-
}
|