@kubohiroya/turbowarp-camera-source 0.6.0 → 0.7.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.
- package/README.ja.md +51 -3
- package/README.md +174 -11
- package/dist/camera-source.js +1165 -44
- package/dist/extension-manifest.json +119 -3
- package/dist/runtime.d.ts +76 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +34 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +27 -19
- package/schemas/camera-intrinsics-v1.json +346 -0
- package/schemas/extension-manifest.schema.json +49 -0
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
"formatVersion": 1,
|
|
3
3
|
"id": "kubohiroyacamerasource",
|
|
4
4
|
"blocks": [
|
|
5
|
+
{
|
|
6
|
+
"opcode": "cameraConditionsGeneration",
|
|
7
|
+
"blockType": "REPORTER",
|
|
8
|
+
"arguments": [
|
|
9
|
+
{
|
|
10
|
+
"id": "CAMERA_ID",
|
|
11
|
+
"type": "STRING"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"opcode": "cameraConditionsJson",
|
|
17
|
+
"blockType": "REPORTER",
|
|
18
|
+
"arguments": [
|
|
19
|
+
{
|
|
20
|
+
"id": "CAMERA_ID",
|
|
21
|
+
"type": "STRING"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
},
|
|
5
25
|
{
|
|
6
26
|
"opcode": "cameraDeviceCount",
|
|
7
27
|
"blockType": "REPORTER",
|
|
@@ -87,6 +107,86 @@
|
|
|
87
107
|
}
|
|
88
108
|
]
|
|
89
109
|
},
|
|
110
|
+
{
|
|
111
|
+
"opcode": "cameraProfileAdaptation",
|
|
112
|
+
"blockType": "REPORTER",
|
|
113
|
+
"arguments": [
|
|
114
|
+
{
|
|
115
|
+
"id": "CAMERA_ID",
|
|
116
|
+
"type": "STRING"
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"opcode": "cameraProfileCompatibility",
|
|
122
|
+
"blockType": "REPORTER",
|
|
123
|
+
"arguments": [
|
|
124
|
+
{
|
|
125
|
+
"id": "CAMERA_ID",
|
|
126
|
+
"type": "STRING"
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"opcode": "cameraProfileCompatibilityDetail",
|
|
132
|
+
"blockType": "REPORTER",
|
|
133
|
+
"arguments": [
|
|
134
|
+
{
|
|
135
|
+
"id": "CAMERA_ID",
|
|
136
|
+
"type": "STRING"
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"opcode": "cameraProfileError",
|
|
142
|
+
"blockType": "REPORTER",
|
|
143
|
+
"arguments": []
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"opcode": "cameraProfileErrorDetail",
|
|
147
|
+
"blockType": "REPORTER",
|
|
148
|
+
"arguments": []
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"opcode": "cameraProfileIntrinsicsJson",
|
|
152
|
+
"blockType": "REPORTER",
|
|
153
|
+
"arguments": [
|
|
154
|
+
{
|
|
155
|
+
"id": "CAMERA_ID",
|
|
156
|
+
"type": "STRING"
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"opcode": "cameraProfileJson",
|
|
162
|
+
"blockType": "REPORTER",
|
|
163
|
+
"arguments": [
|
|
164
|
+
{
|
|
165
|
+
"id": "CAMERA_ID",
|
|
166
|
+
"type": "STRING"
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"opcode": "cameraProfileRegistered",
|
|
172
|
+
"blockType": "BOOLEAN",
|
|
173
|
+
"arguments": [
|
|
174
|
+
{
|
|
175
|
+
"id": "CAMERA_ID",
|
|
176
|
+
"type": "STRING"
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"opcode": "forgetCameraProfile",
|
|
182
|
+
"blockType": "COMMAND",
|
|
183
|
+
"arguments": [
|
|
184
|
+
{
|
|
185
|
+
"id": "CAMERA_ID",
|
|
186
|
+
"type": "STRING"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
},
|
|
90
190
|
{
|
|
91
191
|
"opcode": "hideCameraPreview",
|
|
92
192
|
"blockType": "COMMAND",
|
|
@@ -112,6 +212,16 @@
|
|
|
112
212
|
"blockType": "COMMAND",
|
|
113
213
|
"arguments": []
|
|
114
214
|
},
|
|
215
|
+
{
|
|
216
|
+
"opcode": "registerCameraProfile",
|
|
217
|
+
"blockType": "COMMAND",
|
|
218
|
+
"arguments": [
|
|
219
|
+
{
|
|
220
|
+
"id": "PROFILE_JSON",
|
|
221
|
+
"type": "STRING"
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
},
|
|
115
225
|
{
|
|
116
226
|
"opcode": "showCameraPreview",
|
|
117
227
|
"blockType": "COMMAND",
|
|
@@ -121,8 +231,9 @@
|
|
|
121
231
|
"type": "STRING"
|
|
122
232
|
},
|
|
123
233
|
{
|
|
124
|
-
"id": "
|
|
125
|
-
"type": "STRING"
|
|
234
|
+
"id": "PREVIEW_FLIP",
|
|
235
|
+
"type": "STRING",
|
|
236
|
+
"menu": "flips"
|
|
126
237
|
}
|
|
127
238
|
]
|
|
128
239
|
},
|
|
@@ -151,5 +262,10 @@
|
|
|
151
262
|
]
|
|
152
263
|
}
|
|
153
264
|
],
|
|
154
|
-
"menus": [
|
|
265
|
+
"menus": [
|
|
266
|
+
{
|
|
267
|
+
"id": "flips",
|
|
268
|
+
"acceptReporters": true
|
|
269
|
+
}
|
|
270
|
+
]
|
|
155
271
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract other extensions use to share a camera with this one.
|
|
3
|
+
*
|
|
4
|
+
* Published as its own entry point so a consumer states what it expects instead of re-declaring it.
|
|
5
|
+
* A hand-written copy of an interface compiles perfectly against nothing: when the shape here
|
|
6
|
+
* changes, the copy keeps type-checking in its own repository and fails at runtime in a browser,
|
|
7
|
+
* which is the worst order to find out. Importing these declarations moves that failure to the
|
|
8
|
+
* consumer's build.
|
|
9
|
+
*
|
|
10
|
+
* This module holds no logic and pulls in none of the extension, so importing it costs a consumer
|
|
11
|
+
* nothing at runtime beyond the three constants below.
|
|
12
|
+
*/
|
|
13
|
+
/** The extension ID, as it appears in block opcodes and in a project's extension list. */
|
|
14
|
+
export declare const cameraSourceExtensionId = "kubohiroyacamerasource";
|
|
15
|
+
/**
|
|
16
|
+
* Where the extension instance puts itself on the VM runtime.
|
|
17
|
+
*
|
|
18
|
+
* Present as soon as the extension is registered. Absent means Camera Source is not loaded, which a
|
|
19
|
+
* consumer has to handle whatever else it does.
|
|
20
|
+
*/
|
|
21
|
+
export declare const cameraSourceRuntimeKey = "ext_kubohiroyacamerasource";
|
|
22
|
+
/** Where the versioned capability sits, when the build publishing it has that path enabled. */
|
|
23
|
+
export declare const cameraSourceCapabilityKey = "kubohiroyaCameraSourceCapability";
|
|
24
|
+
/**
|
|
25
|
+
* Which way an image has been turned over.
|
|
26
|
+
*
|
|
27
|
+
* `horizontal` is the left-right mirror, matching `cv::flip` with a flip code of 1, ffmpeg's
|
|
28
|
+
* `hflip` and CSS `scaleX(-1)`. Rotation is deliberately not folded in: a portrait capture is a
|
|
29
|
+
* rotation and not a flip, and once both exist their order matters.
|
|
30
|
+
*/
|
|
31
|
+
export type Flip = 'none' | 'horizontal' | 'vertical' | 'both';
|
|
32
|
+
export interface CameraAcquireOptions {
|
|
33
|
+
/** Free text naming the caller. Appears in diagnostics; never used to decide anything. */
|
|
34
|
+
owner?: string;
|
|
35
|
+
/** The role name of the stream, such as `pose` or `qr`. Callers naming the same one share it. */
|
|
36
|
+
cameraId?: string;
|
|
37
|
+
deviceId?: string;
|
|
38
|
+
video?: MediaTrackConstraints | boolean;
|
|
39
|
+
/** How this consumer wants the stage preview drawn. Only meaningful together with `preview`. */
|
|
40
|
+
previewFlip?: Flip;
|
|
41
|
+
preview?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface CameraFrameSource {
|
|
44
|
+
readonly kind: 'video';
|
|
45
|
+
readonly element: HTMLVideoElement;
|
|
46
|
+
readonly width: number;
|
|
47
|
+
readonly height: number;
|
|
48
|
+
/**
|
|
49
|
+
* How the stage preview is being drawn, which says nothing about the pixels.
|
|
50
|
+
*
|
|
51
|
+
* The frames behind it are always the ones the camera captured: drawing a preview turned over is
|
|
52
|
+
* a rendering transform and never reaches them. A consumer that reads this as a statement about
|
|
53
|
+
* the image and flips its coordinates to compensate feeds a solve reflected input, and the pose
|
|
54
|
+
* that comes back is a left-right reflection whose reprojection error stays small.
|
|
55
|
+
*
|
|
56
|
+
* Read it when drawing something that sits next to the preview and should match it.
|
|
57
|
+
*/
|
|
58
|
+
readonly previewFlip: Flip;
|
|
59
|
+
readonly deviceId: string;
|
|
60
|
+
}
|
|
61
|
+
export interface CameraLease {
|
|
62
|
+
getFrameSource(): CameraFrameSource;
|
|
63
|
+
release(): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* What `Scratch.vm.runtime[cameraSourceRuntimeKey]` offers.
|
|
67
|
+
*
|
|
68
|
+
* Only the members a sharing consumer needs are named here. The extension instance carries its
|
|
69
|
+
* block methods as well, but those are the block surface and not a contract between extensions.
|
|
70
|
+
*/
|
|
71
|
+
export interface CameraSourceRuntime {
|
|
72
|
+
acquireCamera(options?: CameraAcquireOptions): Promise<CameraLease>;
|
|
73
|
+
}
|
|
74
|
+
/** Narrows a runtime value to the Camera Source surface, so a missing extension reads as absent. */
|
|
75
|
+
export declare function readCameraSourceRuntime(runtime: unknown): CameraSourceRuntime | undefined;
|
|
76
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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ACpG,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,GAAG,SAAS,CAMzF"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract other extensions use to share a camera with this one.
|
|
3
|
+
*
|
|
4
|
+
* Published as its own entry point so a consumer states what it expects instead of re-declaring it.
|
|
5
|
+
* A hand-written copy of an interface compiles perfectly against nothing: when the shape here
|
|
6
|
+
* changes, the copy keeps type-checking in its own repository and fails at runtime in a browser,
|
|
7
|
+
* which is the worst order to find out. Importing these declarations moves that failure to the
|
|
8
|
+
* consumer's build.
|
|
9
|
+
*
|
|
10
|
+
* This module holds no logic and pulls in none of the extension, so importing it costs a consumer
|
|
11
|
+
* nothing at runtime beyond the three constants below.
|
|
12
|
+
*/
|
|
13
|
+
/** The extension ID, as it appears in block opcodes and in a project's extension list. */
|
|
14
|
+
export const cameraSourceExtensionId = 'kubohiroyacamerasource';
|
|
15
|
+
/**
|
|
16
|
+
* Where the extension instance puts itself on the VM runtime.
|
|
17
|
+
*
|
|
18
|
+
* Present as soon as the extension is registered. Absent means Camera Source is not loaded, which a
|
|
19
|
+
* consumer has to handle whatever else it does.
|
|
20
|
+
*/
|
|
21
|
+
export const cameraSourceRuntimeKey = 'ext_kubohiroyacamerasource';
|
|
22
|
+
/** Where the versioned capability sits, when the build publishing it has that path enabled. */
|
|
23
|
+
export const cameraSourceCapabilityKey = 'kubohiroyaCameraSourceCapability';
|
|
24
|
+
/** Narrows a runtime value to the Camera Source surface, so a missing extension reads as absent. */
|
|
25
|
+
export function readCameraSourceRuntime(runtime) {
|
|
26
|
+
if (typeof runtime !== 'object' || runtime === null)
|
|
27
|
+
return undefined;
|
|
28
|
+
const candidate = runtime[cameraSourceRuntimeKey];
|
|
29
|
+
if (typeof candidate !== 'object' || candidate === null)
|
|
30
|
+
return undefined;
|
|
31
|
+
const { acquireCamera } = candidate;
|
|
32
|
+
return typeof acquireCamera === 'function' ? candidate : undefined;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,4BAA4B,CAAC;AAEnE,+FAA+F;AAC/F,MAAM,CAAC,MAAM,yBAAyB,GAAG,kCAAkC,CAAC;AAyD5E,oGAAoG;AACpG,MAAM,UAAU,uBAAuB,CAAC,OAAgB;IACtD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACtE,MAAM,SAAS,GAAI,OAAmC,CAAC,sBAAsB,CAAC,CAAC;IAC/E,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAC1E,MAAM,EAAC,aAAa,EAAC,GAAG,SAAsC,CAAC;IAC/D,OAAO,OAAO,aAAa,KAAK,UAAU,CAAC,CAAC,CAAE,SAAiC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-camera-source",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|
|
@@ -15,10 +15,15 @@
|
|
|
15
15
|
},
|
|
16
16
|
"exports": {
|
|
17
17
|
"./camera-source.js": "./dist/camera-source.js",
|
|
18
|
+
"./runtime": {
|
|
19
|
+
"types": "./dist/runtime.d.ts",
|
|
20
|
+
"import": "./dist/runtime.js"
|
|
21
|
+
},
|
|
18
22
|
"./package.json": "./package.json"
|
|
19
23
|
},
|
|
20
24
|
"files": [
|
|
21
25
|
"dist/",
|
|
26
|
+
"schemas/",
|
|
22
27
|
"README.md",
|
|
23
28
|
"README.ja.md",
|
|
24
29
|
"LICENSE"
|
|
@@ -29,13 +34,32 @@
|
|
|
29
34
|
"access": "public",
|
|
30
35
|
"registry": "https://registry.npmjs.org/"
|
|
31
36
|
},
|
|
37
|
+
"packageManager": "pnpm@11.18.0",
|
|
32
38
|
"engines": {
|
|
33
39
|
"node": ">=22.18.0"
|
|
34
40
|
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"dev": "vite build --watch",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"build": "vite build && tsc -p tsconfig.lib.json",
|
|
45
|
+
"lint": "eslint src tests vite.config.ts",
|
|
46
|
+
"format": "eslint src tests vite.config.ts --fix",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"docs": "node scripts/generate-readme.ts",
|
|
49
|
+
"docs:check": "pnpm run docs && git diff --exit-code -- README.md README.ja.md",
|
|
50
|
+
"docs:pages:check": "node scripts/check-pages.ts",
|
|
51
|
+
"repo:check": "node scripts/check-repo.ts",
|
|
52
|
+
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
53
|
+
"release:check": "pnpm publish --dry-run --access public --no-git-checks",
|
|
54
|
+
"check": "pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run docs:check && pnpm run docs:pages:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check",
|
|
55
|
+
"check:dist": "pnpm run build && node scripts/check-dist.ts",
|
|
56
|
+
"prepack": "pnpm run check"
|
|
57
|
+
},
|
|
35
58
|
"devDependencies": {
|
|
36
59
|
"@eslint/js": "^9.39.5",
|
|
37
60
|
"@kubohiroya/vite-plugin-turbowarp-extension": "0.4.0",
|
|
38
61
|
"@types/node": "^24.13.3",
|
|
62
|
+
"ajv": "^8.20.0",
|
|
39
63
|
"eslint": "^9.39.5",
|
|
40
64
|
"typescript": "^5.9.3",
|
|
41
65
|
"typescript-eslint": "^8.66.0",
|
|
@@ -49,21 +73,5 @@
|
|
|
49
73
|
"camera",
|
|
50
74
|
"media-devices",
|
|
51
75
|
"getusermedia"
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
"dev": "vite build --watch",
|
|
55
|
-
"typecheck": "tsc --noEmit",
|
|
56
|
-
"build": "vite build",
|
|
57
|
-
"lint": "eslint src tests vite.config.ts",
|
|
58
|
-
"format": "eslint src tests vite.config.ts --fix",
|
|
59
|
-
"test": "vitest run",
|
|
60
|
-
"docs": "node scripts/generate-readme.ts",
|
|
61
|
-
"docs:check": "pnpm run docs && git diff --exit-code -- README.md",
|
|
62
|
-
"docs:pages:check": "node scripts/check-pages.ts",
|
|
63
|
-
"repo:check": "node scripts/check-repo.ts",
|
|
64
|
-
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
65
|
-
"release:check": "pnpm publish --dry-run --access public --no-git-checks",
|
|
66
|
-
"check": "pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run docs:check && pnpm run docs:pages:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check",
|
|
67
|
-
"check:dist": "pnpm run build && node scripts/check-dist.ts"
|
|
68
|
-
}
|
|
69
|
-
}
|
|
76
|
+
]
|
|
77
|
+
}
|