node-libcamera 0.1.0 → 0.1.6

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.
@@ -1,93 +1,804 @@
1
1
  import { exec } from 'child_process';
2
2
 
3
- var OPTIONS = {
4
- help: {
5
- "short": 'h',
6
- desc: 'Print help information for the application'
7
- },
8
- version: {
9
- desc: 'Print help information for the application'
10
- },
11
- timeout: {
12
- "short": 't',
13
- desc: 'Delay before application stops automatically <milliseconds>',
14
- validator: function validator(val) {
15
- return typeof val === 'number';
16
- },
17
- convert: function convert(val) {
18
- return val.toString();
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
4
+ try {
5
+ var info = gen[key](arg);
6
+ var value = info.value;
7
+ } catch (error) {
8
+ reject(error);
9
+ return;
10
+ }
11
+
12
+ if (info.done) {
13
+ resolve(value);
14
+ } else {
15
+ Promise.resolve(value).then(_next, _throw);
16
+ }
17
+ }
18
+
19
+ function _asyncToGenerator(fn) {
20
+ return function () {
21
+ var self = this,
22
+ args = arguments;
23
+ return new Promise(function (resolve, reject) {
24
+ var gen = fn.apply(self, args);
25
+
26
+ function _next(value) {
27
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
28
+ }
29
+
30
+ function _throw(err) {
31
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
32
+ }
33
+
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+
39
+ function createCommonjsModule(fn, module) {
40
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
41
+ }
42
+
43
+ var runtime_1 = createCommonjsModule(function (module) {
44
+ /**
45
+ * Copyright (c) 2014-present, Facebook, Inc.
46
+ *
47
+ * This source code is licensed under the MIT license found in the
48
+ * LICENSE file in the root directory of this source tree.
49
+ */
50
+
51
+ var runtime = (function (exports) {
52
+
53
+ var Op = Object.prototype;
54
+ var hasOwn = Op.hasOwnProperty;
55
+ var undefined$1; // More compressible than void 0.
56
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
57
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
58
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
59
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
60
+
61
+ function define(obj, key, value) {
62
+ Object.defineProperty(obj, key, {
63
+ value: value,
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true
67
+ });
68
+ return obj[key];
69
+ }
70
+ try {
71
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
72
+ define({}, "");
73
+ } catch (err) {
74
+ define = function(obj, key, value) {
75
+ return obj[key] = value;
76
+ };
77
+ }
78
+
79
+ function wrap(innerFn, outerFn, self, tryLocsList) {
80
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
81
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
82
+ var generator = Object.create(protoGenerator.prototype);
83
+ var context = new Context(tryLocsList || []);
84
+
85
+ // The ._invoke method unifies the implementations of the .next,
86
+ // .throw, and .return methods.
87
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
88
+
89
+ return generator;
90
+ }
91
+ exports.wrap = wrap;
92
+
93
+ // Try/catch helper to minimize deoptimizations. Returns a completion
94
+ // record like context.tryEntries[i].completion. This interface could
95
+ // have been (and was previously) designed to take a closure to be
96
+ // invoked without arguments, but in all the cases we care about we
97
+ // already have an existing method we want to call, so there's no need
98
+ // to create a new function object. We can even get away with assuming
99
+ // the method takes exactly one argument, since that happens to be true
100
+ // in every case, so we don't have to touch the arguments object. The
101
+ // only additional allocation required is the completion record, which
102
+ // has a stable shape and so hopefully should be cheap to allocate.
103
+ function tryCatch(fn, obj, arg) {
104
+ try {
105
+ return { type: "normal", arg: fn.call(obj, arg) };
106
+ } catch (err) {
107
+ return { type: "throw", arg: err };
19
108
  }
20
- },
21
- preview: {
22
- "short": 'p',
23
- desc: 'Preview window settings <x,y,w,h>',
24
- validator: function validator(val) {
25
- return typeof val === 'object' && Boolean((val == null ? void 0 : val.x) && (val == null ? void 0 : val.y) && (val == null ? void 0 : val.width) && (val == null ? void 0 : val.height));
26
- },
27
- convert: function convert(val) {
28
- return val.x + "," + val.y + "," + val.width + "," + val.height;
109
+ }
110
+
111
+ var GenStateSuspendedStart = "suspendedStart";
112
+ var GenStateSuspendedYield = "suspendedYield";
113
+ var GenStateExecuting = "executing";
114
+ var GenStateCompleted = "completed";
115
+
116
+ // Returning this object from the innerFn has the same effect as
117
+ // breaking out of the dispatch switch statement.
118
+ var ContinueSentinel = {};
119
+
120
+ // Dummy constructor functions that we use as the .constructor and
121
+ // .constructor.prototype properties for functions that return Generator
122
+ // objects. For full spec compliance, you may wish to configure your
123
+ // minifier not to mangle the names of these two functions.
124
+ function Generator() {}
125
+ function GeneratorFunction() {}
126
+ function GeneratorFunctionPrototype() {}
127
+
128
+ // This is a polyfill for %IteratorPrototype% for environments that
129
+ // don't natively support it.
130
+ var IteratorPrototype = {};
131
+ define(IteratorPrototype, iteratorSymbol, function () {
132
+ return this;
133
+ });
134
+
135
+ var getProto = Object.getPrototypeOf;
136
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
137
+ if (NativeIteratorPrototype &&
138
+ NativeIteratorPrototype !== Op &&
139
+ hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
140
+ // This environment has a native %IteratorPrototype%; use it instead
141
+ // of the polyfill.
142
+ IteratorPrototype = NativeIteratorPrototype;
143
+ }
144
+
145
+ var Gp = GeneratorFunctionPrototype.prototype =
146
+ Generator.prototype = Object.create(IteratorPrototype);
147
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
148
+ define(Gp, "constructor", GeneratorFunctionPrototype);
149
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
150
+ GeneratorFunction.displayName = define(
151
+ GeneratorFunctionPrototype,
152
+ toStringTagSymbol,
153
+ "GeneratorFunction"
154
+ );
155
+
156
+ // Helper for defining the .next, .throw, and .return methods of the
157
+ // Iterator interface in terms of a single ._invoke method.
158
+ function defineIteratorMethods(prototype) {
159
+ ["next", "throw", "return"].forEach(function(method) {
160
+ define(prototype, method, function(arg) {
161
+ return this._invoke(method, arg);
162
+ });
163
+ });
164
+ }
165
+
166
+ exports.isGeneratorFunction = function(genFun) {
167
+ var ctor = typeof genFun === "function" && genFun.constructor;
168
+ return ctor
169
+ ? ctor === GeneratorFunction ||
170
+ // For the native GeneratorFunction constructor, the best we can
171
+ // do is to check its .name property.
172
+ (ctor.displayName || ctor.name) === "GeneratorFunction"
173
+ : false;
174
+ };
175
+
176
+ exports.mark = function(genFun) {
177
+ if (Object.setPrototypeOf) {
178
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
179
+ } else {
180
+ genFun.__proto__ = GeneratorFunctionPrototype;
181
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
29
182
  }
30
- },
31
- fullscreen: {
32
- "short": 'f',
33
- desc: 'Fullscreen preview mode'
34
- },
35
- 'qt-preview': {
36
- desc: 'Use Qt-based preview window'
37
- },
38
- nopreview: {
39
- "short": 'n',
40
- desc: 'Do not display a preview window'
41
- },
42
- 'info-text': {
43
- desc: 'Set window title bar text <string>',
44
- validator: function validator(val) {
45
- return typeof val === 'string';
183
+ genFun.prototype = Object.create(Gp);
184
+ return genFun;
185
+ };
186
+
187
+ // Within the body of any async function, `await x` is transformed to
188
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
189
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
190
+ // meant to be awaited.
191
+ exports.awrap = function(arg) {
192
+ return { __await: arg };
193
+ };
194
+
195
+ function AsyncIterator(generator, PromiseImpl) {
196
+ function invoke(method, arg, resolve, reject) {
197
+ var record = tryCatch(generator[method], generator, arg);
198
+ if (record.type === "throw") {
199
+ reject(record.arg);
200
+ } else {
201
+ var result = record.arg;
202
+ var value = result.value;
203
+ if (value &&
204
+ typeof value === "object" &&
205
+ hasOwn.call(value, "__await")) {
206
+ return PromiseImpl.resolve(value.__await).then(function(value) {
207
+ invoke("next", value, resolve, reject);
208
+ }, function(err) {
209
+ invoke("throw", err, resolve, reject);
210
+ });
211
+ }
212
+
213
+ return PromiseImpl.resolve(value).then(function(unwrapped) {
214
+ // When a yielded Promise is resolved, its final value becomes
215
+ // the .value of the Promise<{value,done}> result for the
216
+ // current iteration.
217
+ result.value = unwrapped;
218
+ resolve(result);
219
+ }, function(error) {
220
+ // If a rejected Promise was yielded, throw the rejection back
221
+ // into the async generator function so it can be handled there.
222
+ return invoke("throw", error, resolve, reject);
223
+ });
224
+ }
46
225
  }
47
- },
48
- width: {
49
- desc: 'Capture image width <width>',
50
- validator: function validator(val) {
51
- return typeof val === 'number';
52
- },
53
- convert: function convert(val) {
54
- return val.toString();
226
+
227
+ var previousPromise;
228
+
229
+ function enqueue(method, arg) {
230
+ function callInvokeWithMethodAndArg() {
231
+ return new PromiseImpl(function(resolve, reject) {
232
+ invoke(method, arg, resolve, reject);
233
+ });
234
+ }
235
+
236
+ return previousPromise =
237
+ // If enqueue has been called before, then we want to wait until
238
+ // all previous Promises have been resolved before calling invoke,
239
+ // so that results are always delivered in the correct order. If
240
+ // enqueue has not been called before, then it is important to
241
+ // call invoke immediately, without waiting on a callback to fire,
242
+ // so that the async generator function has the opportunity to do
243
+ // any necessary setup in a predictable way. This predictability
244
+ // is why the Promise constructor synchronously invokes its
245
+ // executor callback, and why async functions synchronously
246
+ // execute code before the first await. Since we implement simple
247
+ // async functions in terms of async generators, it is especially
248
+ // important to get this right, even though it requires care.
249
+ previousPromise ? previousPromise.then(
250
+ callInvokeWithMethodAndArg,
251
+ // Avoid propagating failures to Promises returned by later
252
+ // invocations of the iterator.
253
+ callInvokeWithMethodAndArg
254
+ ) : callInvokeWithMethodAndArg();
55
255
  }
56
- },
57
- height: {
58
- desc: 'Capture image height <height>',
59
- validator: function validator(val) {
60
- return typeof val === 'number';
61
- },
62
- convert: function convert(val) {
63
- return val.toString();
256
+
257
+ // Define the unified helper method that is used to implement .next,
258
+ // .throw, and .return (see defineIteratorMethods).
259
+ this._invoke = enqueue;
260
+ }
261
+
262
+ defineIteratorMethods(AsyncIterator.prototype);
263
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
264
+ return this;
265
+ });
266
+ exports.AsyncIterator = AsyncIterator;
267
+
268
+ // Note that simple async functions are implemented on top of
269
+ // AsyncIterator objects; they just return a Promise for the value of
270
+ // the final result produced by the iterator.
271
+ exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
272
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
273
+
274
+ var iter = new AsyncIterator(
275
+ wrap(innerFn, outerFn, self, tryLocsList),
276
+ PromiseImpl
277
+ );
278
+
279
+ return exports.isGeneratorFunction(outerFn)
280
+ ? iter // If outerFn is a generator, return the full iterator.
281
+ : iter.next().then(function(result) {
282
+ return result.done ? result.value : iter.next();
283
+ });
284
+ };
285
+
286
+ function makeInvokeMethod(innerFn, self, context) {
287
+ var state = GenStateSuspendedStart;
288
+
289
+ return function invoke(method, arg) {
290
+ if (state === GenStateExecuting) {
291
+ throw new Error("Generator is already running");
292
+ }
293
+
294
+ if (state === GenStateCompleted) {
295
+ if (method === "throw") {
296
+ throw arg;
297
+ }
298
+
299
+ // Be forgiving, per 25.3.3.3.3 of the spec:
300
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
301
+ return doneResult();
302
+ }
303
+
304
+ context.method = method;
305
+ context.arg = arg;
306
+
307
+ while (true) {
308
+ var delegate = context.delegate;
309
+ if (delegate) {
310
+ var delegateResult = maybeInvokeDelegate(delegate, context);
311
+ if (delegateResult) {
312
+ if (delegateResult === ContinueSentinel) continue;
313
+ return delegateResult;
314
+ }
315
+ }
316
+
317
+ if (context.method === "next") {
318
+ // Setting context._sent for legacy support of Babel's
319
+ // function.sent implementation.
320
+ context.sent = context._sent = context.arg;
321
+
322
+ } else if (context.method === "throw") {
323
+ if (state === GenStateSuspendedStart) {
324
+ state = GenStateCompleted;
325
+ throw context.arg;
326
+ }
327
+
328
+ context.dispatchException(context.arg);
329
+
330
+ } else if (context.method === "return") {
331
+ context.abrupt("return", context.arg);
332
+ }
333
+
334
+ state = GenStateExecuting;
335
+
336
+ var record = tryCatch(innerFn, self, context);
337
+ if (record.type === "normal") {
338
+ // If an exception is thrown from innerFn, we leave state ===
339
+ // GenStateExecuting and loop back for another invocation.
340
+ state = context.done
341
+ ? GenStateCompleted
342
+ : GenStateSuspendedYield;
343
+
344
+ if (record.arg === ContinueSentinel) {
345
+ continue;
346
+ }
347
+
348
+ return {
349
+ value: record.arg,
350
+ done: context.done
351
+ };
352
+
353
+ } else if (record.type === "throw") {
354
+ state = GenStateCompleted;
355
+ // Dispatch the exception by looping back around to the
356
+ // context.dispatchException(context.arg) call above.
357
+ context.method = "throw";
358
+ context.arg = record.arg;
359
+ }
360
+ }
361
+ };
362
+ }
363
+
364
+ // Call delegate.iterator[context.method](context.arg) and handle the
365
+ // result, either by returning a { value, done } result from the
366
+ // delegate iterator, or by modifying context.method and context.arg,
367
+ // setting context.delegate to null, and returning the ContinueSentinel.
368
+ function maybeInvokeDelegate(delegate, context) {
369
+ var method = delegate.iterator[context.method];
370
+ if (method === undefined$1) {
371
+ // A .throw or .return when the delegate iterator has no .throw
372
+ // method always terminates the yield* loop.
373
+ context.delegate = null;
374
+
375
+ if (context.method === "throw") {
376
+ // Note: ["return"] must be used for ES3 parsing compatibility.
377
+ if (delegate.iterator["return"]) {
378
+ // If the delegate iterator has a return method, give it a
379
+ // chance to clean up.
380
+ context.method = "return";
381
+ context.arg = undefined$1;
382
+ maybeInvokeDelegate(delegate, context);
383
+
384
+ if (context.method === "throw") {
385
+ // If maybeInvokeDelegate(context) changed context.method from
386
+ // "return" to "throw", let that override the TypeError below.
387
+ return ContinueSentinel;
388
+ }
389
+ }
390
+
391
+ context.method = "throw";
392
+ context.arg = new TypeError(
393
+ "The iterator does not provide a 'throw' method");
394
+ }
395
+
396
+ return ContinueSentinel;
64
397
  }
65
- },
66
- 'viewfinder-width': {
67
- desc: 'Capture image width <width>',
68
- validator: function validator(val) {
69
- return typeof val === 'number';
70
- },
71
- convert: function convert(val) {
72
- return val.toString();
398
+
399
+ var record = tryCatch(method, delegate.iterator, context.arg);
400
+
401
+ if (record.type === "throw") {
402
+ context.method = "throw";
403
+ context.arg = record.arg;
404
+ context.delegate = null;
405
+ return ContinueSentinel;
73
406
  }
74
- },
75
- 'viewfinder-height': {
76
- desc: 'Capture image height <height>',
77
- validator: function validator(val) {
78
- return typeof val === 'number';
79
- },
80
- convert: function convert(val) {
81
- return val.toString();
407
+
408
+ var info = record.arg;
409
+
410
+ if (! info) {
411
+ context.method = "throw";
412
+ context.arg = new TypeError("iterator result is not an object");
413
+ context.delegate = null;
414
+ return ContinueSentinel;
82
415
  }
83
- },
84
- // ...
85
- output: {
86
- "short": 'o',
87
- desc: 'Output file name <string>',
88
- validator: function validator(val) {
89
- return typeof val === 'string';
416
+
417
+ if (info.done) {
418
+ // Assign the result of the finished delegate to the temporary
419
+ // variable specified by delegate.resultName (see delegateYield).
420
+ context[delegate.resultName] = info.value;
421
+
422
+ // Resume execution at the desired location (see delegateYield).
423
+ context.next = delegate.nextLoc;
424
+
425
+ // If context.method was "throw" but the delegate handled the
426
+ // exception, let the outer generator proceed normally. If
427
+ // context.method was "next", forget context.arg since it has been
428
+ // "consumed" by the delegate iterator. If context.method was
429
+ // "return", allow the original .return call to continue in the
430
+ // outer generator.
431
+ if (context.method !== "return") {
432
+ context.method = "next";
433
+ context.arg = undefined$1;
434
+ }
435
+
436
+ } else {
437
+ // Re-yield the result returned by the delegate method.
438
+ return info;
90
439
  }
440
+
441
+ // The delegate iterator is finished, so forget it and continue with
442
+ // the outer generator.
443
+ context.delegate = null;
444
+ return ContinueSentinel;
445
+ }
446
+
447
+ // Define Generator.prototype.{next,throw,return} in terms of the
448
+ // unified ._invoke helper method.
449
+ defineIteratorMethods(Gp);
450
+
451
+ define(Gp, toStringTagSymbol, "Generator");
452
+
453
+ // A Generator should always return itself as the iterator object when the
454
+ // @@iterator function is called on it. Some browsers' implementations of the
455
+ // iterator prototype chain incorrectly implement this, causing the Generator
456
+ // object to not be returned from this call. This ensures that doesn't happen.
457
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
458
+ define(Gp, iteratorSymbol, function() {
459
+ return this;
460
+ });
461
+
462
+ define(Gp, "toString", function() {
463
+ return "[object Generator]";
464
+ });
465
+
466
+ function pushTryEntry(locs) {
467
+ var entry = { tryLoc: locs[0] };
468
+
469
+ if (1 in locs) {
470
+ entry.catchLoc = locs[1];
471
+ }
472
+
473
+ if (2 in locs) {
474
+ entry.finallyLoc = locs[2];
475
+ entry.afterLoc = locs[3];
476
+ }
477
+
478
+ this.tryEntries.push(entry);
479
+ }
480
+
481
+ function resetTryEntry(entry) {
482
+ var record = entry.completion || {};
483
+ record.type = "normal";
484
+ delete record.arg;
485
+ entry.completion = record;
486
+ }
487
+
488
+ function Context(tryLocsList) {
489
+ // The root entry object (effectively a try statement without a catch
490
+ // or a finally block) gives us a place to store values thrown from
491
+ // locations where there is no enclosing try statement.
492
+ this.tryEntries = [{ tryLoc: "root" }];
493
+ tryLocsList.forEach(pushTryEntry, this);
494
+ this.reset(true);
495
+ }
496
+
497
+ exports.keys = function(object) {
498
+ var keys = [];
499
+ for (var key in object) {
500
+ keys.push(key);
501
+ }
502
+ keys.reverse();
503
+
504
+ // Rather than returning an object with a next method, we keep
505
+ // things simple and return the next function itself.
506
+ return function next() {
507
+ while (keys.length) {
508
+ var key = keys.pop();
509
+ if (key in object) {
510
+ next.value = key;
511
+ next.done = false;
512
+ return next;
513
+ }
514
+ }
515
+
516
+ // To avoid creating an additional object, we just hang the .value
517
+ // and .done properties off the next function object itself. This
518
+ // also ensures that the minifier will not anonymize the function.
519
+ next.done = true;
520
+ return next;
521
+ };
522
+ };
523
+
524
+ function values(iterable) {
525
+ if (iterable) {
526
+ var iteratorMethod = iterable[iteratorSymbol];
527
+ if (iteratorMethod) {
528
+ return iteratorMethod.call(iterable);
529
+ }
530
+
531
+ if (typeof iterable.next === "function") {
532
+ return iterable;
533
+ }
534
+
535
+ if (!isNaN(iterable.length)) {
536
+ var i = -1, next = function next() {
537
+ while (++i < iterable.length) {
538
+ if (hasOwn.call(iterable, i)) {
539
+ next.value = iterable[i];
540
+ next.done = false;
541
+ return next;
542
+ }
543
+ }
544
+
545
+ next.value = undefined$1;
546
+ next.done = true;
547
+
548
+ return next;
549
+ };
550
+
551
+ return next.next = next;
552
+ }
553
+ }
554
+
555
+ // Return an iterator with no values.
556
+ return { next: doneResult };
557
+ }
558
+ exports.values = values;
559
+
560
+ function doneResult() {
561
+ return { value: undefined$1, done: true };
562
+ }
563
+
564
+ Context.prototype = {
565
+ constructor: Context,
566
+
567
+ reset: function(skipTempReset) {
568
+ this.prev = 0;
569
+ this.next = 0;
570
+ // Resetting context._sent for legacy support of Babel's
571
+ // function.sent implementation.
572
+ this.sent = this._sent = undefined$1;
573
+ this.done = false;
574
+ this.delegate = null;
575
+
576
+ this.method = "next";
577
+ this.arg = undefined$1;
578
+
579
+ this.tryEntries.forEach(resetTryEntry);
580
+
581
+ if (!skipTempReset) {
582
+ for (var name in this) {
583
+ // Not sure about the optimal order of these conditions:
584
+ if (name.charAt(0) === "t" &&
585
+ hasOwn.call(this, name) &&
586
+ !isNaN(+name.slice(1))) {
587
+ this[name] = undefined$1;
588
+ }
589
+ }
590
+ }
591
+ },
592
+
593
+ stop: function() {
594
+ this.done = true;
595
+
596
+ var rootEntry = this.tryEntries[0];
597
+ var rootRecord = rootEntry.completion;
598
+ if (rootRecord.type === "throw") {
599
+ throw rootRecord.arg;
600
+ }
601
+
602
+ return this.rval;
603
+ },
604
+
605
+ dispatchException: function(exception) {
606
+ if (this.done) {
607
+ throw exception;
608
+ }
609
+
610
+ var context = this;
611
+ function handle(loc, caught) {
612
+ record.type = "throw";
613
+ record.arg = exception;
614
+ context.next = loc;
615
+
616
+ if (caught) {
617
+ // If the dispatched exception was caught by a catch block,
618
+ // then let that catch block handle the exception normally.
619
+ context.method = "next";
620
+ context.arg = undefined$1;
621
+ }
622
+
623
+ return !! caught;
624
+ }
625
+
626
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
627
+ var entry = this.tryEntries[i];
628
+ var record = entry.completion;
629
+
630
+ if (entry.tryLoc === "root") {
631
+ // Exception thrown outside of any try block that could handle
632
+ // it, so set the completion value of the entire function to
633
+ // throw the exception.
634
+ return handle("end");
635
+ }
636
+
637
+ if (entry.tryLoc <= this.prev) {
638
+ var hasCatch = hasOwn.call(entry, "catchLoc");
639
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
640
+
641
+ if (hasCatch && hasFinally) {
642
+ if (this.prev < entry.catchLoc) {
643
+ return handle(entry.catchLoc, true);
644
+ } else if (this.prev < entry.finallyLoc) {
645
+ return handle(entry.finallyLoc);
646
+ }
647
+
648
+ } else if (hasCatch) {
649
+ if (this.prev < entry.catchLoc) {
650
+ return handle(entry.catchLoc, true);
651
+ }
652
+
653
+ } else if (hasFinally) {
654
+ if (this.prev < entry.finallyLoc) {
655
+ return handle(entry.finallyLoc);
656
+ }
657
+
658
+ } else {
659
+ throw new Error("try statement without catch or finally");
660
+ }
661
+ }
662
+ }
663
+ },
664
+
665
+ abrupt: function(type, arg) {
666
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
667
+ var entry = this.tryEntries[i];
668
+ if (entry.tryLoc <= this.prev &&
669
+ hasOwn.call(entry, "finallyLoc") &&
670
+ this.prev < entry.finallyLoc) {
671
+ var finallyEntry = entry;
672
+ break;
673
+ }
674
+ }
675
+
676
+ if (finallyEntry &&
677
+ (type === "break" ||
678
+ type === "continue") &&
679
+ finallyEntry.tryLoc <= arg &&
680
+ arg <= finallyEntry.finallyLoc) {
681
+ // Ignore the finally entry if control is not jumping to a
682
+ // location outside the try/catch block.
683
+ finallyEntry = null;
684
+ }
685
+
686
+ var record = finallyEntry ? finallyEntry.completion : {};
687
+ record.type = type;
688
+ record.arg = arg;
689
+
690
+ if (finallyEntry) {
691
+ this.method = "next";
692
+ this.next = finallyEntry.finallyLoc;
693
+ return ContinueSentinel;
694
+ }
695
+
696
+ return this.complete(record);
697
+ },
698
+
699
+ complete: function(record, afterLoc) {
700
+ if (record.type === "throw") {
701
+ throw record.arg;
702
+ }
703
+
704
+ if (record.type === "break" ||
705
+ record.type === "continue") {
706
+ this.next = record.arg;
707
+ } else if (record.type === "return") {
708
+ this.rval = this.arg = record.arg;
709
+ this.method = "return";
710
+ this.next = "end";
711
+ } else if (record.type === "normal" && afterLoc) {
712
+ this.next = afterLoc;
713
+ }
714
+
715
+ return ContinueSentinel;
716
+ },
717
+
718
+ finish: function(finallyLoc) {
719
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
720
+ var entry = this.tryEntries[i];
721
+ if (entry.finallyLoc === finallyLoc) {
722
+ this.complete(entry.completion, entry.afterLoc);
723
+ resetTryEntry(entry);
724
+ return ContinueSentinel;
725
+ }
726
+ }
727
+ },
728
+
729
+ "catch": function(tryLoc) {
730
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
731
+ var entry = this.tryEntries[i];
732
+ if (entry.tryLoc === tryLoc) {
733
+ var record = entry.completion;
734
+ if (record.type === "throw") {
735
+ var thrown = record.arg;
736
+ resetTryEntry(entry);
737
+ }
738
+ return thrown;
739
+ }
740
+ }
741
+
742
+ // The context.catch method must only be called with a location
743
+ // argument that corresponds to a known catch block.
744
+ throw new Error("illegal catch attempt");
745
+ },
746
+
747
+ delegateYield: function(iterable, resultName, nextLoc) {
748
+ this.delegate = {
749
+ iterator: values(iterable),
750
+ resultName: resultName,
751
+ nextLoc: nextLoc
752
+ };
753
+
754
+ if (this.method === "next") {
755
+ // Deliberately forget the last sent value so that we don't
756
+ // accidentally pass it on to the delegate.
757
+ this.arg = undefined$1;
758
+ }
759
+
760
+ return ContinueSentinel;
761
+ }
762
+ };
763
+
764
+ // Regardless of whether this script is executing as a CommonJS module
765
+ // or not, return the runtime object so that we can declare the variable
766
+ // regeneratorRuntime in the outer scope, which allows this module to be
767
+ // injected easily by `bin/regenerator --include-runtime script.js`.
768
+ return exports;
769
+
770
+ }(
771
+ // If this script is executing as a CommonJS module, use module.exports
772
+ // as the regeneratorRuntime namespace. Otherwise create a new empty
773
+ // object. Either way, the resulting object will be used to initialize
774
+ // the regeneratorRuntime variable at the top of this file.
775
+ module.exports
776
+ ));
777
+
778
+ try {
779
+ regeneratorRuntime = runtime;
780
+ } catch (accidentalStrictMode) {
781
+ // This module should not be running in strict mode, so the above
782
+ // assignment should always work unless something is misconfigured. Just
783
+ // in case runtime.js accidentally runs in strict mode, in modern engines
784
+ // we can explicitly access globalThis. In older engines we can escape
785
+ // strict mode using a global Function call. This could conceivably fail
786
+ // if a Content Security Policy forbids using Function, but in that case
787
+ // the proper solution is to fix the accidental strict mode problem. If
788
+ // you've misconfigured your bundler to force strict mode and applied a
789
+ // CSP to forbid Function, and you're not willing to fix either of those
790
+ // problems, please detail your unique predicament in a GitHub issue.
791
+ if (typeof globalThis === "object") {
792
+ globalThis.regeneratorRuntime = runtime;
793
+ } else {
794
+ Function("r", "regeneratorRuntime = r")(runtime);
795
+ }
796
+ }
797
+ });
798
+
799
+ var optionConverterMap = {
800
+ preview: function preview(val) {
801
+ return val.x + "," + val.y + "," + val.width + "," + val.height;
91
802
  }
92
803
  };
93
804
 
@@ -108,24 +819,62 @@ function convertOptionsToCmdArgs(options) {
108
819
  Object.entries(options).forEach(function (_ref) {
109
820
  var key = _ref[0],
110
821
  val = _ref[1];
111
- var opt = OPTIONS[key];
112
-
113
- if (typeof opt.validator === 'function' && !opt.validator(val)) {
114
- throw new Error("Invalid value for option \"" + key + "\"");
115
- }
116
-
117
- var value = typeof opt.convert === 'function' ? opt.convert(val) : val;
822
+ var converter = optionConverterMap[key];
823
+ var value = typeof converter === 'function' ? converter(val) : val;
118
824
  if (value) args.push("--" + key);
119
- if (value !== true) args.push(value);
825
+ if (value !== true && value != null && value.toString()) args.push(value == null ? void 0 : value.toString());
120
826
  }, true);
121
827
  return args;
122
828
  }
123
829
 
124
- function snap(options) {
125
- var args = convertOptionsToCmdArgs(options);
126
- var command = cmd('libcamera-still', args);
127
- return run(command);
830
+ function runLibCamera(_x, _x2) {
831
+ return _runLibCamera.apply(this, arguments);
832
+ }
833
+
834
+ function _runLibCamera() {
835
+ _runLibCamera = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(bin, options) {
836
+ var args, command;
837
+ return runtime_1.wrap(function _callee$(_context) {
838
+ while (1) {
839
+ switch (_context.prev = _context.next) {
840
+ case 0:
841
+ if (bin === void 0) {
842
+ bin = 'libcamera-still';
843
+ }
844
+
845
+ args = convertOptionsToCmdArgs(options);
846
+ command = cmd(bin, args);
847
+
848
+ if (!(process.env.NODE_ENV === 'test')) {
849
+ _context.next = 6;
850
+ break;
851
+ }
852
+
853
+ console.log(command);
854
+ return _context.abrupt("return", command);
855
+
856
+ case 6:
857
+ return _context.abrupt("return", run(command));
858
+
859
+ case 7:
860
+ case "end":
861
+ return _context.stop();
862
+ }
863
+ }
864
+ }, _callee);
865
+ }));
866
+ return _runLibCamera.apply(this, arguments);
867
+ }
868
+
869
+ function jpeg(options) {
870
+ return runLibCamera('libcamera-jpeg', options);
871
+ }
872
+ function still(options) {
873
+ return runLibCamera('libcamera-still', options);
874
+ }
875
+ function vid(options) {
876
+ return runLibCamera('libcamera-vid', options);
128
877
  }
129
878
 
130
- export { snap };
879
+ export { jpeg, still, vid };
131
880
  //# sourceMappingURL=node-libcamera.esm.js.map