@kubohiroya/turbowarp-camera-source 0.17.0 → 0.18.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,21 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://kubohiroya.github.io/turbowarp-camera-source/schemas/block-editor-fixed-inputs.schema.json",
4
+ "$defs": {
5
+ "showCameraPreview": {
6
+ "type": "object",
7
+ "properties": {
8
+ "PREVIEW_FLIP": {
9
+ "type": "string",
10
+ "enum": [
11
+ "none",
12
+ "horizontal",
13
+ "vertical",
14
+ "both"
15
+ ]
16
+ }
17
+ },
18
+ "additionalProperties": false
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,9 @@
1
+ export declare const extensionConfig: {
2
+ readonly id: "kubohiroyacamerasource";
3
+ readonly slug: "camera-source";
4
+ readonly name: "Camera Source";
5
+ readonly description: "Share one MediaDevices camera stream between TurboWarp extensions.";
6
+ readonly author: "Hiroya Kubo";
7
+ readonly license: "MPL-2.0";
8
+ readonly unsandboxed: true;
9
+ };
@@ -0,0 +1,9 @@
1
+ export const extensionConfig = {
2
+ id: 'kubohiroyacamerasource',
3
+ slug: 'camera-source',
4
+ name: 'Camera Source',
5
+ description: 'Share one MediaDevices camera stream between TurboWarp extensions.',
6
+ author: 'Hiroya Kubo',
7
+ license: 'MPL-2.0',
8
+ unsandboxed: true
9
+ };
@@ -0,0 +1,4 @@
1
+ /** Lightweight declarations and pure callbacks; the optional GUI owns all editor machinery. */
2
+ export * from './editor-schema.js';
3
+ export { cameraProfileUiSchemas, createSourceEditorOptions, registerSourceEditors } from './source-editors.js';
4
+ export { fixedInputEditors, registerFixedInputEditors } from './fixed-input-editors.js';
@@ -0,0 +1,4 @@
1
+ /** Lightweight declarations and pure callbacks; the optional GUI owns all editor machinery. */
2
+ export * from './editor-schema.js';
3
+ export { cameraProfileUiSchemas, createSourceEditorOptions, registerSourceEditors } from './source-editors.js';
4
+ export { fixedInputEditors, registerFixedInputEditors } from './fixed-input-editors.js';
@@ -17,7 +17,10 @@ export declare function decodeCameraProfileSource(source: string): {
17
17
  variantId: CameraProfileVariant;
18
18
  data: unknown;
19
19
  };
20
- /** Safe source boundary: preserve raw input separately from diagnostics and normalized values. */
20
+ /** Decode and apply the runtime owner's pure rules to the exact commit candidate.
21
+ * The common GUI compiles the supplied SchemaBundle and checks schema constraints separately.
22
+ * This boundary deliberately performs no schema compilation or GUI initialization.
23
+ */
21
24
  export declare function validateCameraProfileSource(source: string, context: SchemaValidationContext): {
22
25
  source: string;
23
26
  result: {
@@ -32,20 +35,22 @@ export declare function validateCameraProfileSource(source: string, context: Sch
32
35
  };
33
36
  } | {
34
37
  result: {
35
- readonly kind: "schema-error";
36
- readonly diagnostics: import("@kubohiroya/turbowarp-extension-data-editor/schema").NonEmpty<import("@kubohiroya/turbowarp-extension-data-editor/schema").CompileDiagnostic>;
38
+ kind: "valid";
39
+ diagnostics: never[];
37
40
  } | {
38
- readonly kind: "execution-error";
39
- readonly diagnostics: import("@kubohiroya/turbowarp-extension-data-editor/schema").NonEmpty<import("@kubohiroya/turbowarp-extension-data-editor/schema").CompileExecutionDiagnostic>;
41
+ kind: "invalid";
42
+ diagnostics: {
43
+ scope: {
44
+ consumerId?: string;
45
+ identity: import("@kubohiroya/turbowarp-extension-data-editor/schema").SchemaIdentity;
46
+ };
47
+ phase: "owner";
48
+ code: string;
49
+ dataPath: import("@kubohiroya/turbowarp-extension-data-editor/schema").JsonPointer;
50
+ }[];
40
51
  };
41
52
  source: string;
42
53
  format: "json" | "yaml";
43
54
  variantId: CameraProfileVariant;
44
55
  data: unknown;
45
- } | {
46
- result: import("@kubohiroya/turbowarp-extension-data-editor/schema").SchemaInputValidationResult;
47
- source: string;
48
- format: "json" | "yaml";
49
- variantId: CameraProfileVariant;
50
- data: unknown;
51
56
  };
@@ -1,4 +1,3 @@
1
- import { compileSchemaBundle, validateSchemaInput, } from '@kubohiroya/turbowarp-extension-data-editor/schema';
2
1
  import twcs from '../schemas/camera-intrinsics-v1.json' with { type: 'json' };
3
2
  import legacy from '../schemas/editor-legacy-calibration.json' with { type: 'json' };
4
3
  import ros from '../schemas/editor-ros-camera-info.json' with { type: 'json' };
@@ -70,11 +69,10 @@ export function decodeCameraProfileSource(source) {
70
69
  throw new TypeError('Unrecognized camera profile variant.');
71
70
  return { source, format: json ? 'json' : 'yaml', variantId, data };
72
71
  }
73
- const sourceCompilations = Object.fromEntries(Object.entries(cameraProfileSchemaBundles).map(([key, bundle]) => [
74
- key,
75
- compileSchemaBundle(bundle),
76
- ]));
77
- /** Safe source boundary: preserve raw input separately from diagnostics and normalized values. */
72
+ /** Decode and apply the runtime owner's pure rules to the exact commit candidate.
73
+ * The common GUI compiles the supplied SchemaBundle and checks schema constraints separately.
74
+ * This boundary deliberately performs no schema compilation or GUI initialization.
75
+ */
78
76
  export function validateCameraProfileSource(source, context) {
79
77
  let consumerId;
80
78
  try {
@@ -106,14 +104,19 @@ export function validateCameraProfileSource(source, context) {
106
104
  ];
107
105
  return { source, result: { kind: 'invalid', diagnostics } };
108
106
  }
109
- const compilation = sourceCompilations[decoded.variantId];
110
- if (compilation.kind !== 'compiled')
111
- return { ...decoded, result: compilation };
107
+ const result = validateCameraProfileInput(decoded.data, context);
112
108
  return {
113
109
  ...decoded,
114
- result: validateSchemaInput(compilation.validator, decoded.data, {
115
- context,
116
- ownerValidate: validateCameraProfileInput,
117
- }),
110
+ result: result.kind === 'valid'
111
+ ? { kind: 'valid', diagnostics: [] }
112
+ : { kind: 'invalid', diagnostics: result.issues.map(issue => ({
113
+ scope: {
114
+ identity: cameraProfileSchemaBundles[decoded.variantId].identity,
115
+ ...(consumerId === undefined ? {} : { consumerId }),
116
+ },
117
+ phase: 'owner',
118
+ code: issue.ruleId,
119
+ dataPath: issue.dataPath,
120
+ })) },
118
121
  };
119
122
  }
@@ -0,0 +1,9 @@
1
+ import type { FixedInputEditorOptions } from '@kubohiroya/turbowarp-extension-data-editor';
2
+ export declare const fixedInputEditors: readonly FixedInputEditorOptions[];
3
+ interface RuntimeLifetime {
4
+ on?: (event: string, listener: () => void) => void;
5
+ off?: (event: string, listener: () => void) => void;
6
+ }
7
+ /** Register metadata only; the GUI startup capability owns editor activation. */
8
+ export declare function registerFixedInputEditors(scratch: unknown, definitions: readonly FixedInputEditorOptions[], runtimeOverride?: RuntimeLifetime): () => void;
9
+ export {};
@@ -0,0 +1,68 @@
1
+ import { fixedInputBundle } from './fixed-input-schema.js';
2
+ const invalid = () => [{ message: 'Invalid fixed input.' }];
3
+ function enumBinding(opcode, argument, choices, normalization) {
4
+ const project = (value) => {
5
+ if (typeof value !== 'string')
6
+ return value;
7
+ const normalized = normalization === 'none' ? value : normalization === 'trim' ? value.trim() : value.trim().toLowerCase();
8
+ return choices.includes(normalized) ? normalized : value;
9
+ };
10
+ return { argument, schemaBundle: fixedInputBundle(opcode, argument), control: { label: argument, kind: 'enum', choices: choices.map(value => ({ value })) },
11
+ read: project,
12
+ encode(value) { if (typeof value !== 'string' || !choices.includes(value))
13
+ throw new TypeError('Choose a known value.'); return value; },
14
+ validateCandidate(candidate, _context, finalSnapshot) {
15
+ try {
16
+ return typeof candidate === 'string' && choices.includes(candidate) && ownerCheck(opcode, argument, candidate, finalSnapshot) ? [] : invalid();
17
+ }
18
+ catch {
19
+ return invalid();
20
+ }
21
+ } };
22
+ }
23
+ // Per-field schema constraints are checked by the common prepared engine against the exact candidate.
24
+ // Clamp/fallback and device/session prerequisites remain runtime behavior, never editor providers.
25
+ function ownerCheck(_opcode, _argument, _candidate, _snapshot) { void [_opcode, _argument, _candidate, _snapshot]; return true; }
26
+ const extensionId = 'kubohiroyacamerasource';
27
+ const validationContext = () => ({ consumerId: 'turbowarp-camera-source', nowMs: 0, settings: null });
28
+ export const fixedInputEditors = [
29
+ { apiVersion: 1, extensionId, editorId: 'showCameraPreview-fixed', opcodes: [`${extensionId}_showCameraPreview`],
30
+ contractId: 'turbowarp-camera-source/showCameraPreview', contractRevision: '1', validationContext,
31
+ readOnlyArguments: [],
32
+ bindings: [
33
+ enumBinding('showCameraPreview', 'PREVIEW_FLIP', ["none", "horizontal", "vertical", "both"], 'none')
34
+ ]
35
+ }
36
+ ];
37
+ /** Register metadata only; the GUI startup capability owns editor activation. */
38
+ export function registerFixedInputEditors(scratch, definitions, runtimeOverride) {
39
+ const host = scratch;
40
+ const api = host.gui?.blockEditors;
41
+ if (!definitions.length || api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== 'function')
42
+ return () => { };
43
+ const runtime = runtimeOverride ?? host.vm?.runtime;
44
+ const removers = [];
45
+ let active = true;
46
+ const dispose = () => {
47
+ if (!active)
48
+ return;
49
+ active = false;
50
+ runtime?.off?.('RUNTIME_DISPOSED', dispose);
51
+ for (const remove of removers.splice(0).reverse())
52
+ remove();
53
+ };
54
+ try {
55
+ for (const definition of definitions) {
56
+ const remove = api.registerFixedInputEditor.call(api, definition);
57
+ if (typeof remove !== 'function')
58
+ throw new TypeError('Invalid fixed input registration disposer.');
59
+ removers.push(remove);
60
+ }
61
+ runtime?.on?.('RUNTIME_DISPOSED', dispose);
62
+ }
63
+ catch (error) {
64
+ dispose();
65
+ throw error;
66
+ }
67
+ return dispose;
68
+ }
@@ -0,0 +1,3 @@
1
+ import type { SchemaBundle } from '@kubohiroya/turbowarp-extension-data-editor/schema';
2
+ /** Canonical fixed field fragments; URI is identity only, never fetched. */
3
+ export declare function fixedInputBundle(opcode: string, argument: string): SchemaBundle;
@@ -0,0 +1,11 @@
1
+ import document from '../schemas/block-editor-fixed-inputs.schema.json' with { type: 'json' };
2
+ /** Canonical fixed field fragments; URI is identity only, never fetched. */
3
+ export function fixedInputBundle(opcode, argument) {
4
+ const source = { repository: 'turbowarp-camera-source', path: 'schemas/block-editor-fixed-inputs.schema.json', symbol: `#/$defs/${opcode}/properties/${argument}` };
5
+ const definitions = document.$defs;
6
+ return { identity: { ownerId: 'turbowarp-camera-source', contractId: 'fixed-inputs', revision: '1', variantId: opcode + '.' + argument }, dialect: '2020-12',
7
+ root: { retrievalUri: document.$id, document: definitions[opcode].properties[argument], artifact: { role: 'canonical-schema', source } }, resources: [],
8
+ provenance: { canonicalSources: [source, ...[{ "repository": "turbowarp-camera-source", "path": "src/flip.ts", "symbol": "FLIPS / isFlip / toFlip" }]],
9
+ generatedFiles: [{ repository: 'turbowarp-camera-source', path: 'docs/schemas/block-editor-fixed-inputs.schema.json' }],
10
+ generationSources: [{ repository: 'turbowarp-camera-source', path: 'scripts/generate-fixed-input-docs.mjs' }], referenceSchemas: [] } };
11
+ }
@@ -0,0 +1,7 @@
1
+ import type { SourceEditorOptions, SchemaJsonObject } from '@kubohiroya/turbowarp-extension-data-editor/schema';
2
+ import { cameraProfileSchemaBundles } from './editor-schema.js';
3
+ /** Presentation is opt-in at the common GUI; schema and stored profile shape stay authoritative. */
4
+ export declare const cameraProfileUiSchemas: Readonly<Record<keyof typeof cameraProfileSchemaBundles, SchemaJsonObject>>;
5
+ export declare function createSourceEditorOptions(nowMs?: () => number): readonly SourceEditorOptions[];
6
+ /** Optional capability: old GUIs continue executing blocks without editor registration. */
7
+ export declare function registerSourceEditors(scratch: unknown, nowMs?: () => number): () => void;
@@ -0,0 +1,64 @@
1
+ import { extensionConfig } from './config.js';
2
+ function checkedSource(value) {
3
+ return value.result.kind === 'valid'
4
+ ? { source: value.source, result: { kind: 'valid', diagnostics: [] } }
5
+ : { source: value.source, result: { kind: value.result.kind, diagnostics: value.result.diagnostics } };
6
+ }
7
+ import { cameraProfileSchemaBundles, decodeCameraProfileSource, validateCameraProfileSource } from './editor-schema.js';
8
+ /** Presentation is opt-in at the common GUI; schema and stored profile shape stay authoritative. */
9
+ export const cameraProfileUiSchemas = {
10
+ twcs: {
11
+ 'ui:options': { extensionDataLayout: { version: 1, items: [{ tabs: [
12
+ { label: 'Profile', items: [
13
+ { group: 'Identity', items: [{ field: 'profileId' }, { field: 'cameraId' }, { field: 'calibratedAt' }, { field: 'producer' }] },
14
+ { group: 'Contract', items: [{ field: 'schema' }, { field: 'version' }, { field: 'cameraModel' }] },
15
+ ] },
16
+ { label: 'Camera', items: [{ field: 'image' }, { field: 'intrinsics' }, { field: 'distortion' }] },
17
+ { label: 'Capture', items: [{ field: 'capture' }, { field: 'quality' }, { field: 'device' }] },
18
+ ] }] } },
19
+ image: { 'ui:options': { extensionDataLayout: { version: 1, items: [
20
+ { grid: 2, items: [{ field: 'width' }, { field: 'height' }] }, { field: 'undistorted' },
21
+ ] } } },
22
+ intrinsics: { 'ui:options': { extensionDataLayout: { version: 1, items: [
23
+ { grid: 2, items: [{ field: 'fx' }, { field: 'fy' }, { field: 'cx' }, { field: 'cy' }] }, { field: 'skew' },
24
+ ] } } },
25
+ },
26
+ legacy: { 'ui:options': { extensionDataLayout: { version: 1, items: [{ tabs: [
27
+ { label: 'Profile', items: [{ group: 'Identity', items: [{ field: 'calibrationId' }, { field: 'cameraId' }, { field: 'calibratedAt' }] }, { field: 'schema' }, { field: 'version' }] },
28
+ { label: 'Camera', items: [{ grid: 2, items: [{ field: 'imageWidth' }, { field: 'imageHeight' }] }, { field: 'intrinsicMatrix' }, { field: 'distortionCoefficients' }] },
29
+ { label: 'World', items: [{ field: 'worldFromCameraMatrix' }, { field: 'worldUnit' }] },
30
+ ] }] } } },
31
+ ros: { 'ui:options': { extensionDataLayout: { version: 1, items: [{ tabs: [
32
+ { label: 'Image', items: [{ field: 'camera_name' }, { grid: 2, items: [{ field: 'image_width' }, { field: 'image_height' }] }, { field: 'turbowarp_camera_source' }] },
33
+ { label: 'Matrices', items: [{ field: 'camera_matrix' }, { field: 'distortion_model' }, { field: 'distortion_coefficients' }, { field: 'rectification_matrix' }, { field: 'projection_matrix' }] },
34
+ { label: 'Region', items: [{ grid: 2, items: [{ field: 'binning_x' }, { field: 'binning_y' }] }, { field: 'roi' }] },
35
+ ] }] } } },
36
+ };
37
+ export function createSourceEditorOptions(nowMs = Date.now) {
38
+ const context = () => ({ consumerId: extensionConfig.id, nowMs: nowMs(), settings: null });
39
+ return [
40
+ { apiVersion: 1, extensionId: extensionConfig.id, editorId: 'camera-profile-source', opcodes: ["registerCameraProfile", "registerCameraProfileAs"].map(opcode => `${extensionConfig.id}_${opcode}`), bindings: [{ argument: 'PROFILE_JSON', variants: Object.entries(cameraProfileSchemaBundles).map(([variantId, schemaBundle]) => ({ variantId, format: variantId === 'ros' ? 'yaml' : 'json', schemaBundle, uiSchema: cameraProfileUiSchemas[variantId] })), decode: source => { const decoded = decodeCameraProfileSource(source); return { ...decoded, data: decoded.data }; }, validateSource: (source, context) => checkedSource(validateCameraProfileSource(source, context)) }], validationContext: context }
41
+ ];
42
+ }
43
+ /** Optional capability: old GUIs continue executing blocks without editor registration. */
44
+ export function registerSourceEditors(scratch, nowMs = Date.now) {
45
+ const api = scratch?.gui?.blockEditors;
46
+ if (api?.apiVersion !== 1 || typeof api.registerSourceEditor !== 'function')
47
+ return () => { };
48
+ const removers = [];
49
+ try {
50
+ for (const options of createSourceEditorOptions(nowMs))
51
+ removers.push(api.registerSourceEditor(options));
52
+ }
53
+ catch {
54
+ for (const remove of removers.reverse())
55
+ remove();
56
+ return () => { };
57
+ }
58
+ let active = true;
59
+ return () => { if (active) {
60
+ active = false;
61
+ for (const remove of removers.reverse())
62
+ remove();
63
+ } };
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-camera-source",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
5
5
  "description": "A TurboWarp capability extension for sharing one MediaDevices camera stream across extensions.",
6
6
  "type": "module",
@@ -27,6 +27,10 @@
27
27
  "./editor-schema": {
28
28
  "types": "./lib-editor/src/editor-schema.d.ts",
29
29
  "import": "./lib-editor/src/editor-schema.js"
30
+ },
31
+ "./editor-metadata": {
32
+ "types": "./lib-editor/src/editor-metadata.d.ts",
33
+ "import": "./lib-editor/src/editor-metadata.js"
30
34
  }
31
35
  },
32
36
  "files": [
@@ -54,7 +58,7 @@
54
58
  "lint": "eslint src tests vite.config.ts",
55
59
  "format": "eslint src tests vite.config.ts --fix",
56
60
  "test": "vitest run",
57
- "docs": "node scripts/generate-readme.ts",
61
+ "docs": "node scripts/generate-readme.ts && node scripts/generate-fixed-input-docs.mjs",
58
62
  "docs:check": "pnpm run docs && git diff --exit-code -- README.md README.ja.md",
59
63
  "docs:pages:check": "node scripts/check-pages.ts",
60
64
  "repo:check": "node scripts/check-repo.ts",
@@ -68,8 +72,8 @@
68
72
  },
69
73
  "devDependencies": {
70
74
  "@eslint/js": "^9.39.5",
71
- "@kubohiroya/turbowarp-extension-manifest": "0.2.0",
72
- "@kubohiroya/vite-plugin-turbowarp-extension": "0.4.0",
75
+ "@kubohiroya/turbowarp-extension-manifest": "0.3.2",
76
+ "@kubohiroya/vite-plugin-turbowarp-extension": "0.6.1",
73
77
  "@types/node": "^24.13.3",
74
78
  "ajv": "^8.20.0",
75
79
  "eslint": "^9.39.5",
@@ -77,7 +81,8 @@
77
81
  "typescript-eslint": "^8.66.0",
78
82
  "vite": "^8.2.2",
79
83
  "vitest": "^4.1.10",
80
- "react-dom": "18.3.1"
84
+ "react-dom": "18.3.1",
85
+ "@kubohiroya/turbowarp-extension-data-editor": "0.3.0"
81
86
  },
82
87
  "keywords": [
83
88
  "turbowarp",
@@ -86,8 +91,5 @@
86
91
  "camera",
87
92
  "media-devices",
88
93
  "getusermedia"
89
- ],
90
- "dependencies": {
91
- "@kubohiroya/turbowarp-extension-data-editor": "git+https://github.com/kubohiroya/turbowarp-extension-data-editor.git#76fa1d50a3c188082ceef723ea018a9d8769ea6e"
92
- }
94
+ ]
93
95
  }
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://kubohiroya.github.io/turbowarp-camera-source/schemas/block-editor-fixed-inputs.schema.json",
4
+ "$defs": {
5
+ "showCameraPreview": {
6
+ "type": "object",
7
+ "properties": {
8
+ "PREVIEW_FLIP": {
9
+ "type": "string",
10
+ "enum": [
11
+ "none",
12
+ "horizontal",
13
+ "vertical",
14
+ "both"
15
+ ]
16
+ }
17
+ },
18
+ "additionalProperties": false
19
+ }
20
+ }
21
+ }