node-libcamera 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Hussain Abbas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # TSDX User Guide
2
+
3
+ Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
4
+
5
+ > This TSDX setup is meant for developing libraries (not apps!) that can be published to NPM. If you’re looking to build a Node app, you could use `ts-node-dev`, plain `ts-node`, or simple `tsc`.
6
+
7
+ > If you’re new to TypeScript, checkout [this handy cheatsheet](https://devhints.io/typescript)
8
+
9
+ ## Commands
10
+
11
+ TSDX scaffolds your new library inside `/src`.
12
+
13
+ To run TSDX, use:
14
+
15
+ ```bash
16
+ npm start # or yarn start
17
+ ```
18
+
19
+ This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
20
+
21
+ To do a one-off build, use `npm run build` or `yarn build`.
22
+
23
+ To run tests, use `npm test` or `yarn test`.
24
+
25
+ ## Configuration
26
+
27
+ Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
28
+
29
+ ### Jest
30
+
31
+ Jest tests are set up to run with `npm test` or `yarn test`.
32
+
33
+ ### Bundle Analysis
34
+
35
+ [`size-limit`](https://github.com/ai/size-limit) is set up to calculate the real cost of your library with `npm run size` and visualize the bundle with `npm run analyze`.
36
+
37
+ #### Setup Files
38
+
39
+ This is the folder structure we set up for you:
40
+
41
+ ```txt
42
+ /src
43
+ index.tsx # EDIT THIS
44
+ /test
45
+ blah.test.tsx # EDIT THIS
46
+ .gitignore
47
+ package.json
48
+ README.md # EDIT THIS
49
+ tsconfig.json
50
+ ```
51
+
52
+ ### Rollup
53
+
54
+ TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
55
+
56
+ ### TypeScript
57
+
58
+ `tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
59
+
60
+ ## Continuous Integration
61
+
62
+ ### GitHub Actions
63
+
64
+ Two actions are added by default:
65
+
66
+ - `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
67
+ - `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)
68
+
69
+ ## Optimizations
70
+
71
+ Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
72
+
73
+ ```js
74
+ // ./types/index.d.ts
75
+ declare var __DEV__: boolean;
76
+
77
+ // inside your code...
78
+ if (__DEV__) {
79
+ console.log('foo');
80
+ }
81
+ ```
82
+
83
+ You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
84
+
85
+ ## Module Formats
86
+
87
+ CJS, ESModules, and UMD module formats are supported.
88
+
89
+ The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
90
+
91
+ ## Named Exports
92
+
93
+ Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
94
+
95
+ ## Including Styles
96
+
97
+ There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
98
+
99
+ For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
100
+
101
+ ## Publishing to NPM
102
+
103
+ We recommend using [np](https://github.com/sindresorhus/np).
@@ -0,0 +1,2 @@
1
+ import { LibCamera } from './options';
2
+ export declare function snap(options: LibCamera.OptionsObject): Promise<unknown>;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./node-libcamera.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./node-libcamera.cjs.development.js')
8
+ }
@@ -0,0 +1,135 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var child_process = require('child_process');
6
+
7
+ var OPTIONS = {
8
+ help: {
9
+ "short": 'h',
10
+ desc: 'Print help information for the application'
11
+ },
12
+ version: {
13
+ desc: 'Print help information for the application'
14
+ },
15
+ timeout: {
16
+ "short": 't',
17
+ desc: 'Delay before application stops automatically <milliseconds>',
18
+ validator: function validator(val) {
19
+ return typeof val === 'number';
20
+ },
21
+ convert: function convert(val) {
22
+ return val.toString();
23
+ }
24
+ },
25
+ preview: {
26
+ "short": 'p',
27
+ desc: 'Preview window settings <x,y,w,h>',
28
+ validator: function validator(val) {
29
+ 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));
30
+ },
31
+ convert: function convert(val) {
32
+ return val.x + "," + val.y + "," + val.width + "," + val.height;
33
+ }
34
+ },
35
+ fullscreen: {
36
+ "short": 'f',
37
+ desc: 'Fullscreen preview mode'
38
+ },
39
+ 'qt-preview': {
40
+ desc: 'Use Qt-based preview window'
41
+ },
42
+ nopreview: {
43
+ "short": 'n',
44
+ desc: 'Do not display a preview window'
45
+ },
46
+ 'info-text': {
47
+ desc: 'Set window title bar text <string>',
48
+ validator: function validator(val) {
49
+ return typeof val === 'string';
50
+ }
51
+ },
52
+ width: {
53
+ desc: 'Capture image width <width>',
54
+ validator: function validator(val) {
55
+ return typeof val === 'number';
56
+ },
57
+ convert: function convert(val) {
58
+ return val.toString();
59
+ }
60
+ },
61
+ height: {
62
+ desc: 'Capture image height <height>',
63
+ validator: function validator(val) {
64
+ return typeof val === 'number';
65
+ },
66
+ convert: function convert(val) {
67
+ return val.toString();
68
+ }
69
+ },
70
+ 'viewfinder-width': {
71
+ desc: 'Capture image width <width>',
72
+ validator: function validator(val) {
73
+ return typeof val === 'number';
74
+ },
75
+ convert: function convert(val) {
76
+ return val.toString();
77
+ }
78
+ },
79
+ 'viewfinder-height': {
80
+ desc: 'Capture image height <height>',
81
+ validator: function validator(val) {
82
+ return typeof val === 'number';
83
+ },
84
+ convert: function convert(val) {
85
+ return val.toString();
86
+ }
87
+ },
88
+ // ...
89
+ output: {
90
+ "short": 'o',
91
+ desc: 'Output file name <string>',
92
+ validator: function validator(val) {
93
+ return typeof val === 'string';
94
+ }
95
+ }
96
+ };
97
+
98
+ function cmd(base, args) {
99
+ if (base && !args) return base;
100
+ return base + " " + (args == null ? void 0 : args.join(' '));
101
+ }
102
+ function run(command, options) {
103
+ return new Promise(function (resolve, reject) {
104
+ child_process.exec(command, options, function (error, stdout, stderr) {
105
+ if (stderr || error) reject(stderr || error);
106
+ resolve(stdout);
107
+ });
108
+ });
109
+ }
110
+ function convertOptionsToCmdArgs(options) {
111
+ var args = [];
112
+ Object.entries(options).forEach(function (_ref) {
113
+ var key = _ref[0],
114
+ val = _ref[1];
115
+ var opt = OPTIONS[key];
116
+
117
+ if (typeof opt.validator === 'function' && !opt.validator(val)) {
118
+ throw new Error("Invalid value for option \"" + key + "\"");
119
+ }
120
+
121
+ var value = typeof opt.convert === 'function' ? opt.convert(val) : val;
122
+ if (value) args.push("--" + key);
123
+ if (value !== true) args.push(value);
124
+ }, true);
125
+ return args;
126
+ }
127
+
128
+ function snap(options) {
129
+ var args = convertOptionsToCmdArgs(options);
130
+ var command = cmd('libcamera-still', args);
131
+ return run(command);
132
+ }
133
+
134
+ exports.snap = snap;
135
+ //# sourceMappingURL=node-libcamera.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-libcamera.cjs.development.js","sources":["../src/options.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["export namespace LibCamera {\n export type OptionKeys = typeof OPTION_KEYS[number]\n\n export interface OptionDefinition {\n short?: string\n desc?: string\n validator?: (val: any) => boolean\n convert?: (val: any) => string\n }\n\n export type OptionsObject = {\n [key in OptionKeys]?: any\n }\n\n export interface PreviewOption {\n x: number\n y: number\n width: number\n height: number\n }\n}\n\nexport const OPTION_KEYS = [\n 'help',\n 'version',\n 'timeout',\n 'preview',\n 'fullscreen',\n 'qt-preview',\n 'nopreview',\n 'info-text',\n 'width',\n 'height',\n 'viewfinder-width',\n 'viewfinder-height',\n // ...\n 'output',\n] as const\n\nexport const OPTIONS: Record<\n LibCamera.OptionKeys,\n LibCamera.OptionDefinition\n> = {\n help: {\n short: 'h',\n desc: 'Print help information for the application',\n },\n version: {\n desc: 'Print help information for the application',\n },\n timeout: {\n short: 't',\n desc: 'Delay before application stops automatically <milliseconds>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n preview: {\n short: 'p',\n desc: 'Preview window settings <x,y,w,h>',\n validator(val: LibCamera.PreviewOption) {\n return (\n typeof val === 'object' &&\n Boolean(val?.x && val?.y && val?.width && val?.height)\n )\n },\n convert(val: LibCamera.PreviewOption) {\n return `${val.x},${val.y},${val.width},${val.height}`\n },\n },\n fullscreen: {\n short: 'f',\n desc: 'Fullscreen preview mode',\n },\n 'qt-preview': {\n desc: 'Use Qt-based preview window',\n },\n nopreview: {\n short: 'n',\n desc: 'Do not display a preview window',\n },\n 'info-text': {\n desc: 'Set window title bar text <string>',\n validator: (val: string) => typeof val === 'string',\n },\n width: {\n desc: 'Capture image width <width>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n height: {\n desc: 'Capture image height <height>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n 'viewfinder-width': {\n desc: 'Capture image width <width>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n 'viewfinder-height': {\n desc: 'Capture image height <height>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n\n // ...\n\n output: {\n short: 'o',\n desc: 'Output file name <string>',\n validator: (val: string) => typeof val === 'string',\n },\n} as const\n","import { exec, ExecOptionsWithBufferEncoding } from 'child_process'\nimport { OPTIONS, LibCamera } from './options'\n\nexport function cmd(base: string, args?: string[]): string {\n if (base && !args) return base\n return `${base} ${args?.join(' ')}`\n}\n\nexport function run(command: string, options?: ExecOptionsWithBufferEncoding) {\n return new Promise((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (stderr || error) reject(stderr || error)\n resolve(stdout)\n })\n })\n}\n\nexport function convertOptionsToCmdArgs(\n options: LibCamera.OptionsObject\n): string[] {\n const args: string[] = []\n Object.entries(options).forEach(([key, val]) => {\n const opt = OPTIONS[key as LibCamera.OptionKeys]\n if (typeof opt.validator === 'function' && !opt.validator(val)) {\n throw new Error(`Invalid value for option \"${key}\"`)\n }\n const value = typeof opt.convert === 'function' ? opt.convert(val) : val\n if (value) args.push(`--${key}`)\n if (value !== true) args.push(value)\n }, true)\n return args\n}\n","import { LibCamera } from './options'\nimport { run, cmd, convertOptionsToCmdArgs } from './utils'\n\nexport function snap(options: LibCamera.OptionsObject) {\n const args = convertOptionsToCmdArgs(options)\n const command = cmd('libcamera-still', args)\n return run(command)\n}\n"],"names":["OPTIONS","help","desc","version","timeout","validator","val","convert","toString","preview","Boolean","x","y","width","height","fullscreen","nopreview","output","cmd","base","args","join","run","command","options","Promise","resolve","reject","exec","error","stdout","stderr","convertOptionsToCmdArgs","Object","entries","forEach","key","opt","Error","value","push","snap"],"mappings":";;;;;;AAuCO,IAAMA,OAAO,GAGhB;AACFC,EAAAA,IAAI,EAAE;AACJ,aAAO,GADH;AAEJC,IAAAA,IAAI,EAAE;AAFF,GADJ;AAKFC,EAAAA,OAAO,EAAE;AACPD,IAAAA,IAAI,EAAE;AADC,GALP;AAQFE,EAAAA,OAAO,EAAE;AACP,aAAO,GADA;AAEPF,IAAAA,IAAI,EAAE,6DAFC;AAGPG,IAAAA,SAAS,EAAE,mBAACC,GAAD;AAAA,aAAiB,OAAOA,GAAP,KAAe,QAAhC;AAAA,KAHJ;AAIPC,IAAAA,OAAO,EAAE,iBAACD,GAAD;AAAA,aAAiBA,GAAG,CAACE,QAAJ,EAAjB;AAAA;AAJF,GARP;AAcFC,EAAAA,OAAO,EAAE;AACP,aAAO,GADA;AAEPP,IAAAA,IAAI,EAAE,mCAFC;AAGPG,IAAAA,SAHO,qBAGGC,GAHH;AAIL,aACE,OAAOA,GAAP,KAAe,QAAf,IACAI,OAAO,CAAC,CAAAJ,GAAG,QAAH,YAAAA,GAAG,CAAEK,CAAL,MAAUL,GAAV,oBAAUA,GAAG,CAAEM,CAAf,MAAoBN,GAApB,oBAAoBA,GAAG,CAAEO,KAAzB,MAAkCP,GAAlC,oBAAkCA,GAAG,CAAEQ,MAAvC,CAAD,CAFT;AAID,KARM;AASPP,IAAAA,OATO,mBASCD,GATD;AAUL,aAAUA,GAAG,CAACK,CAAd,SAAmBL,GAAG,CAACM,CAAvB,SAA4BN,GAAG,CAACO,KAAhC,SAAyCP,GAAG,CAACQ,MAA7C;AACD;AAXM,GAdP;A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AAvB,GAAoC8B,GAAG,CAAC9B,OAAJ,CAAYD,GAAZ,CAApC,GAAuDA,GAArE;AACA,QAAIiC,KAAJ,EAAWnB,IAAI,CAACoB,IAAL,QAAeJ,GAAf;AACX,QAAIG,KAAK,KAAK,IAAd,EAAoBnB,IAAI,CAACoB,IAAL,CAAUD,KAAV;AACrB,GARD,EAQG,IARH;AASA,SAAOnB,IAAP;AACD;;SC5BeqB,KAAKjB;AACnB,MAAMJ,IAAI,GAAGY,uBAAuB,CAACR,OAAD,CAApC;AACA,MAAMD,OAAO,GAAGL,GAAG,CAAC,iBAAD,EAAoBE,IAApB,CAAnB;AACA,SAAOE,GAAG,CAACC,OAAD,CAAV;AACD;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("child_process"),e={help:{short:"h",desc:"Print help information for the application"},version:{desc:"Print help information for the application"},timeout:{short:"t",desc:"Delay before application stops automatically <milliseconds>",validator:function(t){return"number"==typeof t},convert:function(t){return t.toString()}},preview:{short:"p",desc:"Preview window settings <x,y,w,h>",validator:function(t){return"object"==typeof t&&Boolean((null==t?void 0:t.x)&&(null==t?void 0:t.y)&&(null==t?void 0:t.width)&&(null==t?void 0:t.height))},convert:function(t){return t.x+","+t.y+","+t.width+","+t.height}},fullscreen:{short:"f",desc:"Fullscreen preview mode"},"qt-preview":{desc:"Use Qt-based preview window"},nopreview:{short:"n",desc:"Do not display a preview window"},"info-text":{desc:"Set window title bar text <string>",validator:function(t){return"string"==typeof t}},width:{desc:"Capture image width <width>",validator:function(t){return"number"==typeof t},convert:function(t){return t.toString()}},height:{desc:"Capture image height <height>",validator:function(t){return"number"==typeof t},convert:function(t){return t.toString()}},"viewfinder-width":{desc:"Capture image width <width>",validator:function(t){return"number"==typeof t},convert:function(t){return t.toString()}},"viewfinder-height":{desc:"Capture image height <height>",validator:function(t){return"number"==typeof t},convert:function(t){return t.toString()}},output:{short:"o",desc:"Output file name <string>",validator:function(t){return"string"==typeof t}}};exports.snap=function(n){return r=function(t,e){return e?t+" "+(null==e?void 0:e.join(" ")):t}("libcamera-still",function(t){var n=[];return Object.entries(t).forEach((function(t){var r=t[0],i=t[1],o=e[r];if("function"==typeof o.validator&&!o.validator(i))throw new Error('Invalid value for option "'+r+'"');var u="function"==typeof o.convert?o.convert(i):i;u&&n.push("--"+r),!0!==u&&n.push(u)}),!0),n}(n)),new Promise((function(e,n){t.exec(r,void 0,(function(t,r,i){(i||t)&&n(i||t),e(r)}))}));var r};
2
+ //# sourceMappingURL=node-libcamera.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-libcamera.cjs.production.min.js","sources":["../src/options.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["export namespace LibCamera {\n export type OptionKeys = typeof OPTION_KEYS[number]\n\n export interface OptionDefinition {\n short?: string\n desc?: string\n validator?: (val: any) => boolean\n convert?: (val: any) => string\n }\n\n export type OptionsObject = {\n [key in OptionKeys]?: any\n }\n\n export interface PreviewOption {\n x: number\n y: number\n width: number\n height: number\n }\n}\n\nexport const OPTION_KEYS = [\n 'help',\n 'version',\n 'timeout',\n 'preview',\n 'fullscreen',\n 'qt-preview',\n 'nopreview',\n 'info-text',\n 'width',\n 'height',\n 'viewfinder-width',\n 'viewfinder-height',\n // ...\n 'output',\n] as const\n\nexport const OPTIONS: Record<\n LibCamera.OptionKeys,\n LibCamera.OptionDefinition\n> = {\n help: {\n short: 'h',\n desc: 'Print help information for the application',\n },\n version: {\n desc: 'Print help information for the application',\n },\n timeout: {\n short: 't',\n desc: 'Delay before application stops automatically <milliseconds>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n preview: {\n short: 'p',\n desc: 'Preview window settings <x,y,w,h>',\n validator(val: LibCamera.PreviewOption) {\n return (\n typeof val === 'object' &&\n Boolean(val?.x && val?.y && val?.width && val?.height)\n )\n },\n convert(val: LibCamera.PreviewOption) {\n return `${val.x},${val.y},${val.width},${val.height}`\n },\n },\n fullscreen: {\n short: 'f',\n desc: 'Fullscreen preview mode',\n },\n 'qt-preview': {\n desc: 'Use Qt-based preview window',\n },\n nopreview: {\n short: 'n',\n desc: 'Do not display a preview window',\n },\n 'info-text': {\n desc: 'Set window title bar text <string>',\n validator: (val: string) => typeof val === 'string',\n },\n width: {\n desc: 'Capture image width <width>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n height: {\n desc: 'Capture image height <height>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n 'viewfinder-width': {\n desc: 'Capture image width <width>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n 'viewfinder-height': {\n desc: 'Capture image height <height>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n\n // ...\n\n output: {\n short: 'o',\n desc: 'Output file name <string>',\n validator: (val: string) => typeof val === 'string',\n },\n} as const\n","import { LibCamera } from './options'\nimport { run, cmd, convertOptionsToCmdArgs } from './utils'\n\nexport function snap(options: LibCamera.OptionsObject) {\n const args = convertOptionsToCmdArgs(options)\n const command = cmd('libcamera-still', args)\n return run(command)\n}\n","import { exec, ExecOptionsWithBufferEncoding } from 'child_process'\nimport { OPTIONS, LibCamera } from './options'\n\nexport function cmd(base: string, args?: string[]): string {\n if (base && !args) return base\n return `${base} ${args?.join(' ')}`\n}\n\nexport function run(command: string, options?: ExecOptionsWithBufferEncoding) {\n return new Promise((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (stderr || error) reject(stderr || error)\n resolve(stdout)\n })\n })\n}\n\nexport function convertOptionsToCmdArgs(\n options: LibCamera.OptionsObject\n): string[] {\n const args: string[] = []\n Object.entries(options).forEach(([key, val]) => {\n const opt = OPTIONS[key as LibCamera.OptionKeys]\n if (typeof opt.validator === 'function' && !opt.validator(val)) {\n throw new Error(`Invalid value for option \"${key}\"`)\n }\n const value = typeof opt.convert === 'function' ? opt.convert(val) : val\n if (value) args.push(`--${key}`)\n if (value !== true) args.push(value)\n }, true)\n return args\n}\n"],"names":["OPTIONS","help","desc","version","timeout","validator","val","convert","toString","preview","Boolean","x","y","width","height","fullscreen","nopreview","output","options","command","base","args","join","cmd","Object","entries","forEach","key","opt","Error","value","push","convertOptionsToCmdArgs","Promise","resolve","reject","exec","run","error","stdout","stderr"],"mappings":"mGAuCaA,EAGT,CACFC,KAAM,OACG,IACPC,KAAM,8CAERC,QAAS,CACPD,KAAM,8CAERE,QAAS,OACA,IACPF,KAAM,8DACNG,UAAW,SAACC,SAA+B,iBAARA,GACnCC,QAAS,SAACD,UAAgBA,EAAIE,aAEhCC,QAAS,OACA,IACPP,KAAM,oCACNG,mBAAUC,SAES,iBAARA,GACPI,eAAQJ,SAAAA,EAAKK,WAAKL,SAAAA,EAAKM,WAAKN,SAAAA,EAAKO,eAASP,SAAAA,EAAKQ,UAGnDP,iBAAQD,UACIA,EAAIK,MAAKL,EAAIM,MAAKN,EAAIO,UAASP,EAAIQ,SAGjDC,WAAY,OACH,IACPb,KAAM,wCAEM,CACZA,KAAM,+BAERc,UAAW,OACF,IACPd,KAAM,+CAEK,CACXA,KAAM,qCACNG,UAAW,SAACC,SAA+B,iBAARA,IAErCO,MAAO,CACLX,KAAM,8BACNG,UAAW,SAACC,SAA+B,iBAARA,GACnCC,QAAS,SAACD,UAAgBA,EAAIE,aAEhCM,OAAQ,CACNZ,KAAM,gCACNG,UAAW,SAACC,SAA+B,iBAARA,GACnCC,QAAS,SAACD,UAAgBA,EAAIE,gCAEZ,CAClBN,KAAM,8BACNG,UAAW,SAACC,SAA+B,iBAARA,GACnCC,QAAS,SAACD,UAAgBA,EAAIE,iCAEX,CACnBN,KAAM,gCACNG,UAAW,SAACC,SAA+B,iBAARA,GACnCC,QAAS,SAACD,UAAgBA,EAAIE,aAKhCS,OAAQ,OACC,IACPf,KAAM,4BACNG,UAAW,SAACC,SAA+B,iBAARA,2BC3GlBY,UCKDC,WALAC,EAAcC,UACnBA,EACHD,aAAQC,SAAAA,EAAMC,KAAK,MADHF,EDCVG,CAAI,2BCapBL,OAEMG,EAAiB,UACvBG,OAAOC,QAAQP,GAASQ,SAAQ,gBAAEC,OAAKrB,OAC/BsB,EAAM5B,EAAQ2B,MACS,mBAAlBC,EAAIvB,YAA6BuB,EAAIvB,UAAUC,SAClD,IAAIuB,mCAAmCF,WAEzCG,EAA+B,mBAAhBF,EAAIrB,QAAyBqB,EAAIrB,QAAQD,GAAOA,EACjEwB,GAAOT,EAAKU,UAAUJ,IACZ,IAAVG,GAAgBT,EAAKU,KAAKD,MAC7B,GACIT,ED1BMW,CAAwBd,ICK9B,IAAIe,SAAQ,SAACC,EAASC,GAC3BC,OAAKjB,ODJAkB,GCIkB,SAACC,EAAOC,EAAQC,IACjCA,GAAUF,IAAOH,EAAOK,GAAUF,GACtCJ,EAAQK,aAJMpB"}
@@ -0,0 +1,131 @@
1
+ import { exec } from 'child_process';
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();
19
+ }
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;
29
+ }
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';
46
+ }
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();
55
+ }
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();
64
+ }
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();
73
+ }
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();
82
+ }
83
+ },
84
+ // ...
85
+ output: {
86
+ "short": 'o',
87
+ desc: 'Output file name <string>',
88
+ validator: function validator(val) {
89
+ return typeof val === 'string';
90
+ }
91
+ }
92
+ };
93
+
94
+ function cmd(base, args) {
95
+ if (base && !args) return base;
96
+ return base + " " + (args == null ? void 0 : args.join(' '));
97
+ }
98
+ function run(command, options) {
99
+ return new Promise(function (resolve, reject) {
100
+ exec(command, options, function (error, stdout, stderr) {
101
+ if (stderr || error) reject(stderr || error);
102
+ resolve(stdout);
103
+ });
104
+ });
105
+ }
106
+ function convertOptionsToCmdArgs(options) {
107
+ var args = [];
108
+ Object.entries(options).forEach(function (_ref) {
109
+ var key = _ref[0],
110
+ 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;
118
+ if (value) args.push("--" + key);
119
+ if (value !== true) args.push(value);
120
+ }, true);
121
+ return args;
122
+ }
123
+
124
+ function snap(options) {
125
+ var args = convertOptionsToCmdArgs(options);
126
+ var command = cmd('libcamera-still', args);
127
+ return run(command);
128
+ }
129
+
130
+ export { snap };
131
+ //# sourceMappingURL=node-libcamera.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-libcamera.esm.js","sources":["../src/options.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["export namespace LibCamera {\n export type OptionKeys = typeof OPTION_KEYS[number]\n\n export interface OptionDefinition {\n short?: string\n desc?: string\n validator?: (val: any) => boolean\n convert?: (val: any) => string\n }\n\n export type OptionsObject = {\n [key in OptionKeys]?: any\n }\n\n export interface PreviewOption {\n x: number\n y: number\n width: number\n height: number\n }\n}\n\nexport const OPTION_KEYS = [\n 'help',\n 'version',\n 'timeout',\n 'preview',\n 'fullscreen',\n 'qt-preview',\n 'nopreview',\n 'info-text',\n 'width',\n 'height',\n 'viewfinder-width',\n 'viewfinder-height',\n // ...\n 'output',\n] as const\n\nexport const OPTIONS: Record<\n LibCamera.OptionKeys,\n LibCamera.OptionDefinition\n> = {\n help: {\n short: 'h',\n desc: 'Print help information for the application',\n },\n version: {\n desc: 'Print help information for the application',\n },\n timeout: {\n short: 't',\n desc: 'Delay before application stops automatically <milliseconds>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n preview: {\n short: 'p',\n desc: 'Preview window settings <x,y,w,h>',\n validator(val: LibCamera.PreviewOption) {\n return (\n typeof val === 'object' &&\n Boolean(val?.x && val?.y && val?.width && val?.height)\n )\n },\n convert(val: LibCamera.PreviewOption) {\n return `${val.x},${val.y},${val.width},${val.height}`\n },\n },\n fullscreen: {\n short: 'f',\n desc: 'Fullscreen preview mode',\n },\n 'qt-preview': {\n desc: 'Use Qt-based preview window',\n },\n nopreview: {\n short: 'n',\n desc: 'Do not display a preview window',\n },\n 'info-text': {\n desc: 'Set window title bar text <string>',\n validator: (val: string) => typeof val === 'string',\n },\n width: {\n desc: 'Capture image width <width>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n height: {\n desc: 'Capture image height <height>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n 'viewfinder-width': {\n desc: 'Capture image width <width>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n 'viewfinder-height': {\n desc: 'Capture image height <height>',\n validator: (val: number) => typeof val === 'number',\n convert: (val: number) => val.toString(),\n },\n\n // ...\n\n output: {\n short: 'o',\n desc: 'Output file name <string>',\n validator: (val: string) => typeof val === 'string',\n },\n} as const\n","import { exec, ExecOptionsWithBufferEncoding } from 'child_process'\nimport { OPTIONS, LibCamera } from './options'\n\nexport function cmd(base: string, args?: string[]): string {\n if (base && !args) return base\n return `${base} ${args?.join(' ')}`\n}\n\nexport function run(command: string, options?: ExecOptionsWithBufferEncoding) {\n return new Promise((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (stderr || error) reject(stderr || error)\n resolve(stdout)\n })\n })\n}\n\nexport function convertOptionsToCmdArgs(\n options: LibCamera.OptionsObject\n): string[] {\n const args: string[] = []\n Object.entries(options).forEach(([key, val]) => {\n const opt = OPTIONS[key as LibCamera.OptionKeys]\n if (typeof opt.validator === 'function' && !opt.validator(val)) {\n throw new Error(`Invalid value for option \"${key}\"`)\n }\n const value = typeof opt.convert === 'function' ? opt.convert(val) : val\n if (value) args.push(`--${key}`)\n if (value !== true) args.push(value)\n }, true)\n return args\n}\n","import { LibCamera } from './options'\nimport { run, cmd, convertOptionsToCmdArgs } from './utils'\n\nexport function snap(options: LibCamera.OptionsObject) {\n const args = convertOptionsToCmdArgs(options)\n const command = cmd('libcamera-still', args)\n return run(command)\n}\n"],"names":["OPTIONS","help","desc","version","timeout","validator","val","convert","toString","preview","Boolean","x","y","width","height","fullscreen","nopreview","output","cmd","base","args","join","run","command","options","Promise","resolve","reject","exec","error","stdout","stderr","convertO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D,EAQG,IARH;AASA,SAAOnB,IAAP;AACD;;SC5BeqB,KAAKjB;AACnB,MAAMJ,IAAI,GAAGY,uBAAuB,CAACR,OAAD,CAApC;AACA,MAAMD,OAAO,GAAGL,GAAG,CAAC,iBAAD,EAAoBE,IAApB,CAAnB;AACA,SAAOE,GAAG,CAACC,OAAD,CAAV;AACD;;;;"}
@@ -0,0 +1,20 @@
1
+ export declare namespace LibCamera {
2
+ type OptionKeys = typeof OPTION_KEYS[number];
3
+ interface OptionDefinition {
4
+ short?: string;
5
+ desc?: string;
6
+ validator?: (val: any) => boolean;
7
+ convert?: (val: any) => string;
8
+ }
9
+ type OptionsObject = {
10
+ [key in OptionKeys]?: any;
11
+ };
12
+ interface PreviewOption {
13
+ x: number;
14
+ y: number;
15
+ width: number;
16
+ height: number;
17
+ }
18
+ }
19
+ export declare const OPTION_KEYS: readonly ["help", "version", "timeout", "preview", "fullscreen", "qt-preview", "nopreview", "info-text", "width", "height", "viewfinder-width", "viewfinder-height", "output"];
20
+ export declare const OPTIONS: Record<LibCamera.OptionKeys, LibCamera.OptionDefinition>;
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import { ExecOptionsWithBufferEncoding } from 'child_process';
3
+ import { LibCamera } from './options';
4
+ export declare function cmd(base: string, args?: string[]): string;
5
+ export declare function run(command: string, options?: ExecOptionsWithBufferEncoding): Promise<unknown>;
6
+ export declare function convertOptionsToCmdArgs(options: LibCamera.OptionsObject): string[];
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "node-libcamera",
3
+ "author": "Hussain Abbas",
4
+ "version": "0.1.0",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "typings": "dist/index.d.ts",
8
+ "module": "dist/node-libcamera.esm.js",
9
+ "files": [
10
+ "dist",
11
+ "src"
12
+ ],
13
+ "engines": {
14
+ "node": ">=10"
15
+ },
16
+ "scripts": {
17
+ "start": "tsdx watch",
18
+ "build": "tsdx build",
19
+ "test": "tsdx test",
20
+ "lint": "tsdx lint",
21
+ "prepare": "tsdx build",
22
+ "size": "size-limit",
23
+ "analyze": "size-limit --why"
24
+ },
25
+ "peerDependencies": {},
26
+ "devDependencies": {
27
+ "@size-limit/preset-small-lib": "^7.0.5",
28
+ "husky": "^7.0.4",
29
+ "size-limit": "^7.0.5",
30
+ "tsdx": "^0.14.1",
31
+ "tslib": "^2.3.1",
32
+ "typescript": "^3.9.10"
33
+ },
34
+ "husky": {
35
+ "hooks": {
36
+ "pre-commit": "tsdx lint"
37
+ }
38
+ },
39
+ "prettier": {
40
+ "printWidth": 80,
41
+ "semi": false,
42
+ "singleQuote": true,
43
+ "trailingComma": "es5"
44
+ },
45
+ "size-limit": [
46
+ {
47
+ "path": "dist/node-libcamera.cjs.production.min.js",
48
+ "limit": "10 KB"
49
+ },
50
+ {
51
+ "path": "dist/node-libcamera.esm.js",
52
+ "limit": "10 KB"
53
+ }
54
+ ]
55
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { LibCamera } from './options'
2
+ import { run, cmd, convertOptionsToCmdArgs } from './utils'
3
+
4
+ export function snap(options: LibCamera.OptionsObject) {
5
+ const args = convertOptionsToCmdArgs(options)
6
+ const command = cmd('libcamera-still', args)
7
+ return run(command)
8
+ }
package/src/options.ts ADDED
@@ -0,0 +1,113 @@
1
+ export namespace LibCamera {
2
+ export type OptionKeys = typeof OPTION_KEYS[number]
3
+
4
+ export interface OptionDefinition {
5
+ short?: string
6
+ desc?: string
7
+ validator?: (val: any) => boolean
8
+ convert?: (val: any) => string
9
+ }
10
+
11
+ export type OptionsObject = {
12
+ [key in OptionKeys]?: any
13
+ }
14
+
15
+ export interface PreviewOption {
16
+ x: number
17
+ y: number
18
+ width: number
19
+ height: number
20
+ }
21
+ }
22
+
23
+ export const OPTION_KEYS = [
24
+ 'help',
25
+ 'version',
26
+ 'timeout',
27
+ 'preview',
28
+ 'fullscreen',
29
+ 'qt-preview',
30
+ 'nopreview',
31
+ 'info-text',
32
+ 'width',
33
+ 'height',
34
+ 'viewfinder-width',
35
+ 'viewfinder-height',
36
+ // ...
37
+ 'output',
38
+ ] as const
39
+
40
+ export const OPTIONS: Record<
41
+ LibCamera.OptionKeys,
42
+ LibCamera.OptionDefinition
43
+ > = {
44
+ help: {
45
+ short: 'h',
46
+ desc: 'Print help information for the application',
47
+ },
48
+ version: {
49
+ desc: 'Print help information for the application',
50
+ },
51
+ timeout: {
52
+ short: 't',
53
+ desc: 'Delay before application stops automatically <milliseconds>',
54
+ validator: (val: number) => typeof val === 'number',
55
+ convert: (val: number) => val.toString(),
56
+ },
57
+ preview: {
58
+ short: 'p',
59
+ desc: 'Preview window settings <x,y,w,h>',
60
+ validator(val: LibCamera.PreviewOption) {
61
+ return (
62
+ typeof val === 'object' &&
63
+ Boolean(val?.x && val?.y && val?.width && val?.height)
64
+ )
65
+ },
66
+ convert(val: LibCamera.PreviewOption) {
67
+ return `${val.x},${val.y},${val.width},${val.height}`
68
+ },
69
+ },
70
+ fullscreen: {
71
+ short: 'f',
72
+ desc: 'Fullscreen preview mode',
73
+ },
74
+ 'qt-preview': {
75
+ desc: 'Use Qt-based preview window',
76
+ },
77
+ nopreview: {
78
+ short: 'n',
79
+ desc: 'Do not display a preview window',
80
+ },
81
+ 'info-text': {
82
+ desc: 'Set window title bar text <string>',
83
+ validator: (val: string) => typeof val === 'string',
84
+ },
85
+ width: {
86
+ desc: 'Capture image width <width>',
87
+ validator: (val: number) => typeof val === 'number',
88
+ convert: (val: number) => val.toString(),
89
+ },
90
+ height: {
91
+ desc: 'Capture image height <height>',
92
+ validator: (val: number) => typeof val === 'number',
93
+ convert: (val: number) => val.toString(),
94
+ },
95
+ 'viewfinder-width': {
96
+ desc: 'Capture image width <width>',
97
+ validator: (val: number) => typeof val === 'number',
98
+ convert: (val: number) => val.toString(),
99
+ },
100
+ 'viewfinder-height': {
101
+ desc: 'Capture image height <height>',
102
+ validator: (val: number) => typeof val === 'number',
103
+ convert: (val: number) => val.toString(),
104
+ },
105
+
106
+ // ...
107
+
108
+ output: {
109
+ short: 'o',
110
+ desc: 'Output file name <string>',
111
+ validator: (val: string) => typeof val === 'string',
112
+ },
113
+ } as const
package/src/utils.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { exec, ExecOptionsWithBufferEncoding } from 'child_process'
2
+ import { OPTIONS, LibCamera } from './options'
3
+
4
+ export function cmd(base: string, args?: string[]): string {
5
+ if (base && !args) return base
6
+ return `${base} ${args?.join(' ')}`
7
+ }
8
+
9
+ export function run(command: string, options?: ExecOptionsWithBufferEncoding) {
10
+ return new Promise((resolve, reject) => {
11
+ exec(command, options, (error, stdout, stderr) => {
12
+ if (stderr || error) reject(stderr || error)
13
+ resolve(stdout)
14
+ })
15
+ })
16
+ }
17
+
18
+ export function convertOptionsToCmdArgs(
19
+ options: LibCamera.OptionsObject
20
+ ): string[] {
21
+ const args: string[] = []
22
+ Object.entries(options).forEach(([key, val]) => {
23
+ const opt = OPTIONS[key as LibCamera.OptionKeys]
24
+ if (typeof opt.validator === 'function' && !opt.validator(val)) {
25
+ throw new Error(`Invalid value for option "${key}"`)
26
+ }
27
+ const value = typeof opt.convert === 'function' ? opt.convert(val) : val
28
+ if (value) args.push(`--${key}`)
29
+ if (value !== true) args.push(value)
30
+ }, true)
31
+ return args
32
+ }