@kubohiroya/turbowarp-camera-source 0.15.0 → 0.17.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 +14 -2
- package/README.md +40 -2
- package/dist/calibration/camera-info.d.ts +2 -0
- package/dist/calibration/camera-info.d.ts.map +1 -1
- package/dist/calibration/camera-info.js +4 -0
- package/dist/calibration/camera-info.js.map +1 -1
- package/dist/camera-source.js +10264 -1728
- package/dist/extension-manifest.json +25 -0
- package/dist/profile.d.ts +1 -1
- package/dist/profile.d.ts.map +1 -1
- package/dist/profile.js +1 -1
- package/dist/profile.js.map +1 -1
- package/lib-editor/schemas/camera-intrinsics-v1.json +346 -0
- package/lib-editor/schemas/editor-legacy-calibration.json +57 -0
- package/lib-editor/schemas/editor-ros-camera-info.json +29 -0
- package/lib-editor/src/calibration/camera-info.d.ts +33 -0
- package/lib-editor/src/calibration/camera-info.js +340 -0
- package/lib-editor/src/calibration/profile.d.ts +46 -0
- package/lib-editor/src/calibration/profile.js +479 -0
- package/lib-editor/src/calibration/types.d.ts +134 -0
- package/lib-editor/src/calibration/types.js +12 -0
- package/lib-editor/src/calibration/yaml.d.ts +20 -0
- package/lib-editor/src/calibration/yaml.js +444 -0
- package/lib-editor/src/editor-schema.d.ts +51 -0
- package/lib-editor/src/editor-schema.js +119 -0
- package/package.json +18 -7
- package/schemas/editor-legacy-calibration.json +57 -0
- package/schemas/editor-ros-camera-info.json +29 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of YAML that camera calibration files are written in.
|
|
3
|
+
*
|
|
4
|
+
* ROS `camera_info` files come out of yaml-cpp's emitter, PyYAML's `dump`, and people's editors, so
|
|
5
|
+
* the reader accepts what those produce: block mappings, block and flow sequences, flow mappings,
|
|
6
|
+
* plain and quoted scalars, comments, and a `%YAML` directive or `---` marker. It refuses what a
|
|
7
|
+
* calibration never needs and a careless reader gets wrong -- anchors and aliases, tags, block
|
|
8
|
+
* scalars, several documents in one file -- by name, rather than guessing.
|
|
9
|
+
*
|
|
10
|
+
* Hand-written for the same reason the profile validator is: a YAML library is larger than this whole
|
|
11
|
+
* extension, and every extension that needs a camera loads this bundle.
|
|
12
|
+
*/
|
|
13
|
+
export class YamlError extends Error {
|
|
14
|
+
line;
|
|
15
|
+
constructor(message, line) {
|
|
16
|
+
super(line > 0 ? `Line ${line}: ${message}` : message);
|
|
17
|
+
this.name = 'YamlError';
|
|
18
|
+
this.line = line;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const MAXIMUM_DEPTH = 16;
|
|
22
|
+
const MAXIMUM_LENGTH = 64 * 1024;
|
|
23
|
+
export function parseYaml(source) {
|
|
24
|
+
if (source.length > MAXIMUM_LENGTH) {
|
|
25
|
+
throw new YamlError('The document is longer than a calibration file ever is.', 0);
|
|
26
|
+
}
|
|
27
|
+
const lines = splitLines(source);
|
|
28
|
+
if (lines.length === 0)
|
|
29
|
+
throw new YamlError('The document is empty.', 0);
|
|
30
|
+
const reader = new BlockReader(lines);
|
|
31
|
+
const value = reader.readBlock(lines[0].indent, 0);
|
|
32
|
+
if (!reader.done()) {
|
|
33
|
+
const line = reader.peek();
|
|
34
|
+
throw new YamlError('Unexpected indentation.', line.number);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function splitLines(source) {
|
|
39
|
+
const lines = [];
|
|
40
|
+
let started = false;
|
|
41
|
+
source
|
|
42
|
+
.replace(/^\uFEFF/, '')
|
|
43
|
+
.split(/\r\n|\r|\n/)
|
|
44
|
+
.forEach((raw, index) => {
|
|
45
|
+
const number = index + 1;
|
|
46
|
+
if (/\t/.test(raw.match(/^\s*/)[0])) {
|
|
47
|
+
throw new YamlError('Tabs cannot indent YAML.', number);
|
|
48
|
+
}
|
|
49
|
+
const text = stripComment(raw).trimEnd();
|
|
50
|
+
const content = text.trimStart();
|
|
51
|
+
if (content.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
if (!started && content.startsWith('%'))
|
|
54
|
+
return;
|
|
55
|
+
if (content === '---' || content.startsWith('--- ')) {
|
|
56
|
+
if (started)
|
|
57
|
+
throw new YamlError('Only one document is read from a calibration file.', number);
|
|
58
|
+
started = true;
|
|
59
|
+
const rest = content.slice(3).trim();
|
|
60
|
+
if (rest.length > 0)
|
|
61
|
+
lines.push({ number, indent: 0, text: rest });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (content === '...') {
|
|
65
|
+
started = true;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
started = true;
|
|
69
|
+
lines.push({ number, indent: text.length - content.length, text: content });
|
|
70
|
+
});
|
|
71
|
+
return lines;
|
|
72
|
+
}
|
|
73
|
+
/** Removes a `#` comment that is not inside quotes. A `#` only starts one after whitespace. */
|
|
74
|
+
function stripComment(raw) {
|
|
75
|
+
let quote;
|
|
76
|
+
for (let index = 0; index < raw.length; index += 1) {
|
|
77
|
+
const character = raw[index];
|
|
78
|
+
if (quote) {
|
|
79
|
+
if (character === '\\' && quote === '"')
|
|
80
|
+
index += 1;
|
|
81
|
+
else if (character === quote)
|
|
82
|
+
quote = undefined;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (character === '"' || character === "'")
|
|
86
|
+
quote = character;
|
|
87
|
+
else if (character === '#' && (index === 0 || /\s/.test(raw[index - 1])))
|
|
88
|
+
return raw.slice(0, index);
|
|
89
|
+
}
|
|
90
|
+
return raw;
|
|
91
|
+
}
|
|
92
|
+
class BlockReader {
|
|
93
|
+
lines;
|
|
94
|
+
index = 0;
|
|
95
|
+
constructor(lines) {
|
|
96
|
+
this.lines = lines;
|
|
97
|
+
}
|
|
98
|
+
done() {
|
|
99
|
+
return this.index >= this.lines.length;
|
|
100
|
+
}
|
|
101
|
+
peek() {
|
|
102
|
+
return this.lines[this.index];
|
|
103
|
+
}
|
|
104
|
+
readBlock(indent, depth) {
|
|
105
|
+
if (depth > MAXIMUM_DEPTH)
|
|
106
|
+
throw new YamlError('The document is nested too deeply.', this.peek()?.number ?? 0);
|
|
107
|
+
const first = this.peek();
|
|
108
|
+
if (!first)
|
|
109
|
+
throw new YamlError('Expected a value.', 0);
|
|
110
|
+
if (first.text === '-' || first.text.startsWith('- '))
|
|
111
|
+
return this.readSequence(indent, depth);
|
|
112
|
+
if (findMappingColon(first.text) >= 0)
|
|
113
|
+
return this.readMapping(indent, depth);
|
|
114
|
+
this.index += 1;
|
|
115
|
+
return this.readInline(first.text, first.number, first.indent);
|
|
116
|
+
}
|
|
117
|
+
readMapping(indent, depth) {
|
|
118
|
+
const mapping = {};
|
|
119
|
+
while (!this.done()) {
|
|
120
|
+
const line = this.peek();
|
|
121
|
+
if (line.indent < indent)
|
|
122
|
+
break;
|
|
123
|
+
if (line.indent > indent)
|
|
124
|
+
throw new YamlError('Unexpected indentation.', line.number);
|
|
125
|
+
const colon = findMappingColon(line.text);
|
|
126
|
+
if (colon < 0)
|
|
127
|
+
throw new YamlError('Expected a "key: value" pair.', line.number);
|
|
128
|
+
const key = readKey(line.text.slice(0, colon).trim(), line.number);
|
|
129
|
+
if (Object.prototype.hasOwnProperty.call(mapping, key)) {
|
|
130
|
+
throw new YamlError(`The key "${key}" appears twice.`, line.number);
|
|
131
|
+
}
|
|
132
|
+
const rest = line.text.slice(colon + 1).trim();
|
|
133
|
+
this.index += 1;
|
|
134
|
+
if (rest.length > 0) {
|
|
135
|
+
mapping[key] = this.readInline(rest, line.number, line.indent);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const next = this.peek();
|
|
139
|
+
const nestedSequence = next !== undefined && next.indent === indent && (next.text === '-' || next.text.startsWith('- '));
|
|
140
|
+
if (next === undefined || (next.indent <= indent && !nestedSequence)) {
|
|
141
|
+
mapping[key] = null;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
mapping[key] = this.readBlock(next.indent, depth + 1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return mapping;
|
|
148
|
+
}
|
|
149
|
+
readSequence(indent, depth) {
|
|
150
|
+
const sequence = [];
|
|
151
|
+
while (!this.done()) {
|
|
152
|
+
const line = this.peek();
|
|
153
|
+
if (line.indent < indent || !(line.text === '-' || line.text.startsWith('- ')))
|
|
154
|
+
break;
|
|
155
|
+
if (line.indent > indent)
|
|
156
|
+
throw new YamlError('Unexpected indentation.', line.number);
|
|
157
|
+
const rest = line.text.slice(1).trim();
|
|
158
|
+
this.index += 1;
|
|
159
|
+
if (rest.length === 0) {
|
|
160
|
+
const next = this.peek();
|
|
161
|
+
sequence.push(next !== undefined && next.indent > indent ? this.readBlock(next.indent, depth + 1) : null);
|
|
162
|
+
}
|
|
163
|
+
else if (findMappingColon(rest) >= 0 && !/^[[{"']/.test(rest)) {
|
|
164
|
+
throw new YamlError('A mapping inside a block sequence is not part of a calibration file.', line.number);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
sequence.push(this.readInline(rest, line.number, line.indent));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return sequence;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Reads a value that starts on one line. A flow collection may continue on the lines after it, as
|
|
174
|
+
* PyYAML writes long matrices, so those lines are drawn in until the brackets balance.
|
|
175
|
+
*/
|
|
176
|
+
readInline(text, number, indent) {
|
|
177
|
+
if (text.startsWith('[') || text.startsWith('{')) {
|
|
178
|
+
let joined = text;
|
|
179
|
+
while (!flowClosed(joined)) {
|
|
180
|
+
const next = this.peek();
|
|
181
|
+
if (!next || next.indent <= indent)
|
|
182
|
+
throw new YamlError('A bracket is never closed.', number);
|
|
183
|
+
joined += ` ${next.text}`;
|
|
184
|
+
this.index += 1;
|
|
185
|
+
}
|
|
186
|
+
const flow = new FlowReader(joined, number);
|
|
187
|
+
const value = flow.readValue(0);
|
|
188
|
+
flow.expectEnd();
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
return readScalar(text, number);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** Where the `: ` separating a key from its value is, or -1. Colons inside quotes do not count. */
|
|
195
|
+
function findMappingColon(text) {
|
|
196
|
+
let quote;
|
|
197
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
198
|
+
const character = text[index];
|
|
199
|
+
if (quote) {
|
|
200
|
+
if (character === '\\' && quote === '"')
|
|
201
|
+
index += 1;
|
|
202
|
+
else if (character === quote)
|
|
203
|
+
quote = undefined;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (index === 0 && (character === '[' || character === '{'))
|
|
207
|
+
return -1;
|
|
208
|
+
if (character === '"' || character === "'")
|
|
209
|
+
quote = character;
|
|
210
|
+
else if (character === ':' && (index === text.length - 1 || text[index + 1] === ' '))
|
|
211
|
+
return index;
|
|
212
|
+
}
|
|
213
|
+
return -1;
|
|
214
|
+
}
|
|
215
|
+
function flowClosed(text) {
|
|
216
|
+
let depth = 0;
|
|
217
|
+
let quote;
|
|
218
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
219
|
+
const character = text[index];
|
|
220
|
+
if (quote) {
|
|
221
|
+
if (character === '\\' && quote === '"')
|
|
222
|
+
index += 1;
|
|
223
|
+
else if (character === quote)
|
|
224
|
+
quote = undefined;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (character === '"' || character === "'")
|
|
228
|
+
quote = character;
|
|
229
|
+
else if (character === '[' || character === '{')
|
|
230
|
+
depth += 1;
|
|
231
|
+
else if (character === ']' || character === '}')
|
|
232
|
+
depth -= 1;
|
|
233
|
+
}
|
|
234
|
+
return depth <= 0;
|
|
235
|
+
}
|
|
236
|
+
function readKey(text, number) {
|
|
237
|
+
const value = readScalar(text, number);
|
|
238
|
+
if (typeof value !== 'string')
|
|
239
|
+
return String(value);
|
|
240
|
+
return value;
|
|
241
|
+
}
|
|
242
|
+
class FlowReader {
|
|
243
|
+
text;
|
|
244
|
+
number;
|
|
245
|
+
index = 0;
|
|
246
|
+
constructor(text, number) {
|
|
247
|
+
this.text = text;
|
|
248
|
+
this.number = number;
|
|
249
|
+
}
|
|
250
|
+
readValue(depth) {
|
|
251
|
+
if (depth > MAXIMUM_DEPTH)
|
|
252
|
+
throw new YamlError('The document is nested too deeply.', this.number);
|
|
253
|
+
this.skipSpace();
|
|
254
|
+
const character = this.text[this.index];
|
|
255
|
+
if (character === '[')
|
|
256
|
+
return this.readSequence(depth);
|
|
257
|
+
if (character === '{')
|
|
258
|
+
return this.readMapping(depth);
|
|
259
|
+
return readScalar(this.readToken(), this.number);
|
|
260
|
+
}
|
|
261
|
+
expectEnd() {
|
|
262
|
+
this.skipSpace();
|
|
263
|
+
if (this.index < this.text.length) {
|
|
264
|
+
throw new YamlError('Unexpected text after a closing bracket.', this.number);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
readSequence(depth) {
|
|
268
|
+
this.index += 1;
|
|
269
|
+
const sequence = [];
|
|
270
|
+
this.skipSpace();
|
|
271
|
+
if (this.text[this.index] === ']') {
|
|
272
|
+
this.index += 1;
|
|
273
|
+
return sequence;
|
|
274
|
+
}
|
|
275
|
+
for (;;) {
|
|
276
|
+
sequence.push(this.readValue(depth + 1));
|
|
277
|
+
this.skipSpace();
|
|
278
|
+
const separator = this.text[this.index];
|
|
279
|
+
this.index += 1;
|
|
280
|
+
if (separator === ']')
|
|
281
|
+
return sequence;
|
|
282
|
+
if (separator !== ',')
|
|
283
|
+
throw new YamlError('Expected "," or "]" in a sequence.', this.number);
|
|
284
|
+
this.skipSpace();
|
|
285
|
+
// A trailing comma before the bracket is allowed.
|
|
286
|
+
if (this.text[this.index] === ']') {
|
|
287
|
+
this.index += 1;
|
|
288
|
+
return sequence;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
readMapping(depth) {
|
|
293
|
+
this.index += 1;
|
|
294
|
+
const mapping = {};
|
|
295
|
+
this.skipSpace();
|
|
296
|
+
if (this.text[this.index] === '}') {
|
|
297
|
+
this.index += 1;
|
|
298
|
+
return mapping;
|
|
299
|
+
}
|
|
300
|
+
for (;;) {
|
|
301
|
+
this.skipSpace();
|
|
302
|
+
const key = readKey(this.readToken(':'), this.number);
|
|
303
|
+
this.skipSpace();
|
|
304
|
+
if (this.text[this.index] !== ':')
|
|
305
|
+
throw new YamlError('Expected ":" after a key.', this.number);
|
|
306
|
+
this.index += 1;
|
|
307
|
+
if (Object.prototype.hasOwnProperty.call(mapping, key)) {
|
|
308
|
+
throw new YamlError(`The key "${key}" appears twice.`, this.number);
|
|
309
|
+
}
|
|
310
|
+
mapping[key] = this.readValue(depth + 1);
|
|
311
|
+
this.skipSpace();
|
|
312
|
+
const separator = this.text[this.index];
|
|
313
|
+
this.index += 1;
|
|
314
|
+
if (separator === '}')
|
|
315
|
+
return mapping;
|
|
316
|
+
if (separator !== ',')
|
|
317
|
+
throw new YamlError('Expected "," or "}" in a mapping.', this.number);
|
|
318
|
+
this.skipSpace();
|
|
319
|
+
if (this.text[this.index] === '}') {
|
|
320
|
+
this.index += 1;
|
|
321
|
+
return mapping;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/** A quoted string, or plain text up to the next flow delimiter. */
|
|
326
|
+
readToken(stopAlso = '') {
|
|
327
|
+
this.skipSpace();
|
|
328
|
+
const start = this.index;
|
|
329
|
+
const character = this.text[this.index];
|
|
330
|
+
if (character === '"' || character === "'") {
|
|
331
|
+
this.index += 1;
|
|
332
|
+
while (this.index < this.text.length) {
|
|
333
|
+
const current = this.text[this.index];
|
|
334
|
+
if (current === '\\' && character === '"') {
|
|
335
|
+
this.index += 2;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (current === character) {
|
|
339
|
+
if (character === "'" && this.text[this.index + 1] === "'") {
|
|
340
|
+
this.index += 2;
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
this.index += 1;
|
|
344
|
+
return this.text.slice(start, this.index);
|
|
345
|
+
}
|
|
346
|
+
this.index += 1;
|
|
347
|
+
}
|
|
348
|
+
throw new YamlError('A quoted string is never closed.', this.number);
|
|
349
|
+
}
|
|
350
|
+
while (this.index < this.text.length && !`,]}${stopAlso}`.includes(this.text[this.index])) {
|
|
351
|
+
this.index += 1;
|
|
352
|
+
}
|
|
353
|
+
return this.text.slice(start, this.index).trim();
|
|
354
|
+
}
|
|
355
|
+
skipSpace() {
|
|
356
|
+
while (this.index < this.text.length && /\s/.test(this.text[this.index]))
|
|
357
|
+
this.index += 1;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const INTEGER = /^[-+]?(?:0|[1-9][0-9_]*)$/;
|
|
361
|
+
const FLOAT = /^[-+]?(?:[0-9][0-9_]*)?\.?[0-9]*(?:[eE][-+]?[0-9]+)?$/;
|
|
362
|
+
function readScalar(text, number) {
|
|
363
|
+
const value = text.trim();
|
|
364
|
+
if (value.length === 0)
|
|
365
|
+
return null;
|
|
366
|
+
const first = value[0];
|
|
367
|
+
if (first === '"')
|
|
368
|
+
return readDoubleQuoted(value, number);
|
|
369
|
+
if (first === "'") {
|
|
370
|
+
if (value.length < 2 || !value.endsWith("'"))
|
|
371
|
+
throw new YamlError('A quoted string is never closed.', number);
|
|
372
|
+
return value.slice(1, -1).replace(/''/g, "'");
|
|
373
|
+
}
|
|
374
|
+
if (first === '&' || first === '*')
|
|
375
|
+
throw new YamlError('Anchors and aliases are not read.', number);
|
|
376
|
+
if (first === '!')
|
|
377
|
+
throw new YamlError('Tags are not read.', number);
|
|
378
|
+
if (first === '|' || first === '>')
|
|
379
|
+
throw new YamlError('Block scalars are not read.', number);
|
|
380
|
+
if (first === '@' || first === '`')
|
|
381
|
+
throw new YamlError(`A plain value cannot start with "${first}".`, number);
|
|
382
|
+
if (value === '~' || value === 'null' || value === 'Null' || value === 'NULL')
|
|
383
|
+
return null;
|
|
384
|
+
if (value === 'true' || value === 'True' || value === 'TRUE')
|
|
385
|
+
return true;
|
|
386
|
+
if (value === 'false' || value === 'False' || value === 'FALSE')
|
|
387
|
+
return false;
|
|
388
|
+
if (/^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/.test(value)) {
|
|
389
|
+
throw new YamlError('Infinity and NaN are not calibration values.', number);
|
|
390
|
+
}
|
|
391
|
+
if (INTEGER.test(value))
|
|
392
|
+
return Number(value.replace(/_/g, ''));
|
|
393
|
+
if (/[0-9]/.test(value) && FLOAT.test(value)) {
|
|
394
|
+
const parsed = Number(value.replace(/_/g, ''));
|
|
395
|
+
if (Number.isFinite(parsed))
|
|
396
|
+
return parsed;
|
|
397
|
+
}
|
|
398
|
+
return value;
|
|
399
|
+
}
|
|
400
|
+
function readDoubleQuoted(value, number) {
|
|
401
|
+
if (value.length < 2 || !value.endsWith('"'))
|
|
402
|
+
throw new YamlError('A quoted string is never closed.', number);
|
|
403
|
+
const body = value.slice(1, -1);
|
|
404
|
+
let result = '';
|
|
405
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
406
|
+
const character = body[index];
|
|
407
|
+
if (character !== '\\') {
|
|
408
|
+
result += character;
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
const escape = body[index + 1];
|
|
412
|
+
index += 1;
|
|
413
|
+
switch (escape) {
|
|
414
|
+
case '"':
|
|
415
|
+
case '\\':
|
|
416
|
+
case '/':
|
|
417
|
+
result += escape;
|
|
418
|
+
break;
|
|
419
|
+
case 'n':
|
|
420
|
+
result += '\n';
|
|
421
|
+
break;
|
|
422
|
+
case 't':
|
|
423
|
+
result += '\t';
|
|
424
|
+
break;
|
|
425
|
+
case 'r':
|
|
426
|
+
result += '\r';
|
|
427
|
+
break;
|
|
428
|
+
case '0':
|
|
429
|
+
result += '\0';
|
|
430
|
+
break;
|
|
431
|
+
case 'u': {
|
|
432
|
+
const hex = body.slice(index + 1, index + 5);
|
|
433
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex))
|
|
434
|
+
throw new YamlError('Invalid \\u escape.', number);
|
|
435
|
+
result += String.fromCharCode(parseInt(hex, 16));
|
|
436
|
+
index += 4;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
default:
|
|
440
|
+
throw new YamlError(`Unsupported escape "\\${escape ?? ''}".`, number);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return result;
|
|
444
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { SchemaValidationContext } from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
2
|
+
import type { SchemaBundle, SyncOwnerValidator } from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
3
|
+
export { readCameraInfoDocument } from './calibration/camera-info.js';
|
|
4
|
+
export { readCameraProfileDocument } from './calibration/profile.js';
|
|
5
|
+
export type CameraProfileVariant = 'twcs' | 'legacy' | 'ros';
|
|
6
|
+
export declare const cameraProfileSchemaBundles: {
|
|
7
|
+
readonly twcs: SchemaBundle;
|
|
8
|
+
readonly legacy: SchemaBundle;
|
|
9
|
+
readonly ros: SchemaBundle;
|
|
10
|
+
};
|
|
11
|
+
/** Raw edit values stay separate from any normalized profile returned by the owner. */
|
|
12
|
+
export declare function readCameraProfileInput(data: unknown): import("./calibration/types.js").ProfileResult;
|
|
13
|
+
export declare const validateCameraProfileInput: SyncOwnerValidator;
|
|
14
|
+
export declare function decodeCameraProfileSource(source: string): {
|
|
15
|
+
source: string;
|
|
16
|
+
format: "json" | "yaml";
|
|
17
|
+
variantId: CameraProfileVariant;
|
|
18
|
+
data: unknown;
|
|
19
|
+
};
|
|
20
|
+
/** Safe source boundary: preserve raw input separately from diagnostics and normalized values. */
|
|
21
|
+
export declare function validateCameraProfileSource(source: string, context: SchemaValidationContext): {
|
|
22
|
+
source: string;
|
|
23
|
+
result: {
|
|
24
|
+
kind: "invalid";
|
|
25
|
+
diagnostics: readonly [import("@kubohiroya/turbowarp-extension-data-editor/schema").SchemaDiagnosticBase & {
|
|
26
|
+
readonly phase: "decode";
|
|
27
|
+
readonly code: "input-format-invalid" | "variant-unrecognized";
|
|
28
|
+
readonly dataPath: import("@kubohiroya/turbowarp-extension-data-editor/schema").JsonPointer;
|
|
29
|
+
} & {
|
|
30
|
+
phase: "decode";
|
|
31
|
+
}];
|
|
32
|
+
};
|
|
33
|
+
} | {
|
|
34
|
+
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>;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: "execution-error";
|
|
39
|
+
readonly diagnostics: import("@kubohiroya/turbowarp-extension-data-editor/schema").NonEmpty<import("@kubohiroya/turbowarp-extension-data-editor/schema").CompileExecutionDiagnostic>;
|
|
40
|
+
};
|
|
41
|
+
source: string;
|
|
42
|
+
format: "json" | "yaml";
|
|
43
|
+
variantId: CameraProfileVariant;
|
|
44
|
+
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
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { compileSchemaBundle, validateSchemaInput, } from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
2
|
+
import twcs from '../schemas/camera-intrinsics-v1.json' with { type: 'json' };
|
|
3
|
+
import legacy from '../schemas/editor-legacy-calibration.json' with { type: 'json' };
|
|
4
|
+
import ros from '../schemas/editor-ros-camera-info.json' with { type: 'json' };
|
|
5
|
+
import { readCameraProfileDocument } from './calibration/profile.js';
|
|
6
|
+
import { readCameraInfoDocument } from './calibration/camera-info.js';
|
|
7
|
+
import { parseYaml } from './calibration/yaml.js';
|
|
8
|
+
export { readCameraInfoDocument } from './calibration/camera-info.js';
|
|
9
|
+
export { readCameraProfileDocument } from './calibration/profile.js';
|
|
10
|
+
function bundle(document, filename, variantId) {
|
|
11
|
+
const source = { repository: 'turbowarp-camera-source', path: 'schemas/' + filename };
|
|
12
|
+
return {
|
|
13
|
+
identity: {
|
|
14
|
+
ownerId: 'turbowarp-camera-source',
|
|
15
|
+
contractId: 'camera-profile',
|
|
16
|
+
revision: 'profile-v0.16.0',
|
|
17
|
+
variantId,
|
|
18
|
+
},
|
|
19
|
+
dialect: '2020-12',
|
|
20
|
+
root: {
|
|
21
|
+
retrievalUri: document.$id,
|
|
22
|
+
document: document,
|
|
23
|
+
artifact: { role: 'canonical-schema', source },
|
|
24
|
+
},
|
|
25
|
+
resources: [],
|
|
26
|
+
provenance: {
|
|
27
|
+
canonicalSources: [source],
|
|
28
|
+
generatedFiles: [],
|
|
29
|
+
referenceSchemas: [],
|
|
30
|
+
generationSources: [],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export const cameraProfileSchemaBundles = {
|
|
35
|
+
twcs: bundle(twcs, 'camera-intrinsics-v1.json', 'twcs'),
|
|
36
|
+
legacy: bundle(legacy, 'editor-legacy-calibration.json', 'legacy'),
|
|
37
|
+
ros: bundle(ros, 'editor-ros-camera-info.json', 'ros'),
|
|
38
|
+
};
|
|
39
|
+
/** Raw edit values stay separate from any normalized profile returned by the owner. */
|
|
40
|
+
export function readCameraProfileInput(data) {
|
|
41
|
+
if (data && typeof data === 'object' && Object.hasOwn(data, 'image_width')) {
|
|
42
|
+
const read = readCameraInfoDocument(data);
|
|
43
|
+
return read.ok ? readCameraProfileDocument(read.document) : read;
|
|
44
|
+
}
|
|
45
|
+
return readCameraProfileDocument(data);
|
|
46
|
+
}
|
|
47
|
+
export const validateCameraProfileInput = (data) => {
|
|
48
|
+
const result = readCameraProfileInput(data);
|
|
49
|
+
return result.ok
|
|
50
|
+
? { kind: 'valid', issues: [] }
|
|
51
|
+
: { kind: 'invalid', issues: [{ dataPath: '', ruleId: result.error.code }] };
|
|
52
|
+
};
|
|
53
|
+
export function decodeCameraProfileSource(source) {
|
|
54
|
+
const json = source.trim().startsWith('{');
|
|
55
|
+
const data = json ? JSON.parse(source.trim()) : parseYaml(source.trim());
|
|
56
|
+
let variantId;
|
|
57
|
+
if (!json)
|
|
58
|
+
variantId = 'ros';
|
|
59
|
+
else if (data &&
|
|
60
|
+
typeof data === 'object' &&
|
|
61
|
+
'schema' in data &&
|
|
62
|
+
data.schema === 'twcs/camera-intrinsics')
|
|
63
|
+
variantId = 'twcs';
|
|
64
|
+
else if (data &&
|
|
65
|
+
typeof data === 'object' &&
|
|
66
|
+
'schema' in data &&
|
|
67
|
+
data.schema === 'twrmc/camera-calibration')
|
|
68
|
+
variantId = 'legacy';
|
|
69
|
+
else
|
|
70
|
+
throw new TypeError('Unrecognized camera profile variant.');
|
|
71
|
+
return { source, format: json ? 'json' : 'yaml', variantId, data };
|
|
72
|
+
}
|
|
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. */
|
|
78
|
+
export function validateCameraProfileSource(source, context) {
|
|
79
|
+
let consumerId;
|
|
80
|
+
try {
|
|
81
|
+
const descriptor = Object.getOwnPropertyDescriptor(context, 'consumerId');
|
|
82
|
+
if (descriptor && 'value' in descriptor && typeof descriptor.value === 'string')
|
|
83
|
+
consumerId = descriptor.value;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
/* Leave the consumer unspecified when context cannot be inspected safely. */
|
|
87
|
+
}
|
|
88
|
+
let decoded;
|
|
89
|
+
try {
|
|
90
|
+
decoded = decodeCameraProfileSource(source);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
const code = error instanceof TypeError && error.message === 'Unrecognized camera profile variant.'
|
|
94
|
+
? 'variant-unrecognized'
|
|
95
|
+
: 'input-format-invalid';
|
|
96
|
+
const diagnostics = [
|
|
97
|
+
{
|
|
98
|
+
scope: {
|
|
99
|
+
identity: { ...cameraProfileSchemaBundles.twcs.identity, variantId: 'unrecognized' },
|
|
100
|
+
...(consumerId === undefined ? {} : { consumerId }),
|
|
101
|
+
},
|
|
102
|
+
phase: 'decode',
|
|
103
|
+
code,
|
|
104
|
+
dataPath: '',
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
return { source, result: { kind: 'invalid', diagnostics } };
|
|
108
|
+
}
|
|
109
|
+
const compilation = sourceCompilations[decoded.variantId];
|
|
110
|
+
if (compilation.kind !== 'compiled')
|
|
111
|
+
return { ...decoded, result: compilation };
|
|
112
|
+
return {
|
|
113
|
+
...decoded,
|
|
114
|
+
result: validateSchemaInput(compilation.validator, decoded.data, {
|
|
115
|
+
context,
|
|
116
|
+
ownerValidate: validateCameraProfileInput,
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-camera-source",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.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",
|
|
@@ -23,14 +23,19 @@
|
|
|
23
23
|
"types": "./dist/profile.d.ts",
|
|
24
24
|
"import": "./dist/profile.js"
|
|
25
25
|
},
|
|
26
|
-
"./package.json": "./package.json"
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
"./editor-schema": {
|
|
28
|
+
"types": "./lib-editor/src/editor-schema.d.ts",
|
|
29
|
+
"import": "./lib-editor/src/editor-schema.js"
|
|
30
|
+
}
|
|
27
31
|
},
|
|
28
32
|
"files": [
|
|
29
33
|
"dist/",
|
|
30
34
|
"schemas/",
|
|
31
35
|
"README.md",
|
|
32
36
|
"README.ja.md",
|
|
33
|
-
"LICENSE"
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"lib-editor/"
|
|
34
39
|
],
|
|
35
40
|
"unpkg": "./dist/camera-source.js",
|
|
36
41
|
"jsdelivr": "./dist/camera-source.js",
|
|
@@ -45,7 +50,7 @@
|
|
|
45
50
|
"scripts": {
|
|
46
51
|
"dev": "vite build --watch",
|
|
47
52
|
"typecheck": "tsc --noEmit",
|
|
48
|
-
"build": "vite build && tsc -p tsconfig.lib.json",
|
|
53
|
+
"build": "vite build && tsc -p tsconfig.lib.json && npm run build:editor",
|
|
49
54
|
"lint": "eslint src tests vite.config.ts",
|
|
50
55
|
"format": "eslint src tests vite.config.ts --fix",
|
|
51
56
|
"test": "vitest run",
|
|
@@ -57,7 +62,9 @@
|
|
|
57
62
|
"release:check": "pnpm publish --dry-run --access public --no-git-checks",
|
|
58
63
|
"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",
|
|
59
64
|
"check:dist": "pnpm run build && node scripts/check-dist.ts",
|
|
60
|
-
"prepack": "
|
|
65
|
+
"prepack": "node scripts/prepack.mjs",
|
|
66
|
+
"build:editor": "tsc -p tsconfig.editor.json",
|
|
67
|
+
"prepare": "npm run build"
|
|
61
68
|
},
|
|
62
69
|
"devDependencies": {
|
|
63
70
|
"@eslint/js": "^9.39.5",
|
|
@@ -69,7 +76,8 @@
|
|
|
69
76
|
"typescript": "^5.9.3",
|
|
70
77
|
"typescript-eslint": "^8.66.0",
|
|
71
78
|
"vite": "^8.2.2",
|
|
72
|
-
"vitest": "^4.1.10"
|
|
79
|
+
"vitest": "^4.1.10",
|
|
80
|
+
"react-dom": "18.3.1"
|
|
73
81
|
},
|
|
74
82
|
"keywords": [
|
|
75
83
|
"turbowarp",
|
|
@@ -78,5 +86,8 @@
|
|
|
78
86
|
"camera",
|
|
79
87
|
"media-devices",
|
|
80
88
|
"getusermedia"
|
|
81
|
-
]
|
|
89
|
+
],
|
|
90
|
+
"dependencies": {
|
|
91
|
+
"@kubohiroya/turbowarp-extension-data-editor": "git+https://github.com/kubohiroya/turbowarp-extension-data-editor.git#76fa1d50a3c188082ceef723ea018a9d8769ea6e"
|
|
92
|
+
}
|
|
82
93
|
}
|