@zappar/zappar-cv 0.4.0-beta.8 → 2.0.0-beta.2

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -2
  3. package/lib/additional.d.ts +3 -1
  4. package/lib/additional.js +1 -2
  5. package/lib/camera-source-map.js +16 -24
  6. package/lib/camera-source.js +17 -21
  7. package/lib/cameramodel.js +18 -23
  8. package/lib/compatibility.js +1 -3
  9. package/lib/deserializer.js +1 -5
  10. package/lib/direct.js +12 -16
  11. package/lib/drawcamera.js +26 -31
  12. package/lib/drawface.js +5 -9
  13. package/lib/drawfaceproject.js +5 -9
  14. package/lib/drawplane.js +6 -11
  15. package/lib/event.js +5 -13
  16. package/lib/facelandmark.d.ts +1 -2
  17. package/lib/facelandmark.js +11 -18
  18. package/lib/facelandmarkdata.js +1 -4
  19. package/lib/facelandmarkinterface.js +1 -2
  20. package/lib/facemesh.js +10 -17
  21. package/lib/gen/zappar-client.js +5 -24
  22. package/lib/gen/zappar-cwrap.js +1 -12
  23. package/lib/gen/zappar-native.d.ts +0 -1
  24. package/lib/gen/zappar-native.js +10 -13
  25. package/lib/gen/zappar-server.js +5 -13
  26. package/lib/gen/zappar.d.ts +7 -2
  27. package/lib/gen/zappar.js +5 -13
  28. package/lib/gfx.js +1 -4
  29. package/lib/gl-state-manager.d.ts +9 -0
  30. package/lib/gl-state-manager.js +31 -0
  31. package/lib/html-element-source.js +23 -27
  32. package/lib/image-process-gl.js +73 -32
  33. package/lib/imagebitmap-camera-source.js +30 -34
  34. package/lib/imagetracker.d.ts +28 -0
  35. package/lib/imagetracker.js +115 -0
  36. package/lib/index-standalone.d.ts +3 -0
  37. package/lib/index-standalone.js +5 -0
  38. package/lib/index.d.ts +2 -1
  39. package/lib/index.js +6 -27
  40. package/lib/landmarkdatagenerate.js +25 -30
  41. package/lib/loglevel.js +9 -16
  42. package/lib/messages.js +4 -8
  43. package/lib/mstp-camera-source.js +22 -26
  44. package/lib/native.d.ts +2 -1
  45. package/lib/native.js +194 -132
  46. package/lib/options.d.ts +3 -0
  47. package/lib/options.js +1 -0
  48. package/lib/permission.js +13 -27
  49. package/lib/pipeline.d.ts +1 -2
  50. package/lib/pipeline.js +34 -39
  51. package/lib/profile.js +40 -45
  52. package/lib/riff-reader.d.ts +18 -0
  53. package/lib/riff-reader.js +52 -0
  54. package/lib/sequencerecorder.js +7 -12
  55. package/lib/sequencesource.d.ts +2 -0
  56. package/lib/sequencesource.js +28 -25
  57. package/lib/serializer.js +1 -5
  58. package/lib/shader.js +2 -7
  59. package/lib/source.js +1 -5
  60. package/lib/version.d.ts +1 -1
  61. package/lib/version.js +1 -4
  62. package/lib/worker-client.d.ts +1 -1
  63. package/lib/worker-client.js +9 -21
  64. package/lib/worker-imagebitmap.js +9 -13
  65. package/lib/worker-server.js +33 -37
  66. package/lib/worker.js +6 -10
  67. package/lib/workerinterface.js +1 -2
  68. package/lib/zcv.js +125 -115
  69. package/lib/zcv.wasm +0 -0
  70. package/package.json +14 -16
  71. package/umd/169.zappar-cv.js +1 -0
  72. package/umd/{482727c0e7dd40d73f5aae47f238ad61.zbin → 482727c0e7dd40d73f5a.zbin} +0 -0
  73. package/umd/557cf735d27efb96e262.wasm +0 -0
  74. package/umd/752.zappar-cv.js +1 -0
  75. package/umd/{b4f46e148a3b3b5aef90717d8d60e3fc.zbin → b4f46e148a3b3b5aef90.zbin} +0 -0
  76. package/umd/{f7b62a3a53b5c9b3222ba8dc53cb8b11.zbin → f7b62a3a53b5c9b3222b.zbin} +0 -0
  77. package/umd/zappar-cv.js +1 -1
  78. package/umd/zappar-cv.worker.js +1 -1
  79. package/umd/fbf9061bc2d2826ecf97c8ba2b51e7a5.wasm +0 -0
@@ -0,0 +1,28 @@
1
+ import { zappar_image_tracker_t, zappar_pipeline_t } from "./gen/zappar";
2
+ import { zappar_cwrap } from "./gen/zappar-native";
3
+ interface PreviewInfo {
4
+ compressed: Uint8Array;
5
+ mimeType: string;
6
+ }
7
+ interface ParsedTargetInfo {
8
+ preview?: PreviewInfo;
9
+ physicalScaleFactor: number;
10
+ topRadius: number;
11
+ bottomRadius: number;
12
+ sideLength: number;
13
+ }
14
+ export declare class ImageTracker {
15
+ private _client;
16
+ private _impl;
17
+ private _targets;
18
+ static create(pipeline: zappar_pipeline_t, client: zappar_cwrap): zappar_image_tracker_t;
19
+ static get(p: zappar_image_tracker_t): ImageTracker | undefined;
20
+ private constructor();
21
+ destroy(): void;
22
+ loadFromMemory(data: ArrayBuffer): void;
23
+ targetCount(): number;
24
+ getTargetInfo(i: number): ParsedTargetInfo;
25
+ private _parseOdle;
26
+ getDecodedPreview(i: number): HTMLImageElement | undefined;
27
+ }
28
+ export {};
@@ -0,0 +1,115 @@
1
+ import { RiffReader } from "./riff-reader";
2
+ let byId = new Map();
3
+ const decoder = new TextDecoder();
4
+ export class ImageTracker {
5
+ constructor(_client, _impl) {
6
+ this._client = _client;
7
+ this._impl = _impl;
8
+ this._targets = [];
9
+ }
10
+ static create(pipeline, client) {
11
+ let ret = client.image_tracker_create(pipeline);
12
+ byId.set(ret, new ImageTracker(client, ret));
13
+ return ret;
14
+ }
15
+ static get(p) {
16
+ return byId.get(p);
17
+ }
18
+ destroy() {
19
+ this._client.image_tracker_destroy(this._impl);
20
+ byId.delete(this._impl);
21
+ }
22
+ loadFromMemory(data) {
23
+ this._targets.push({ data });
24
+ this._client.image_tracker_target_load_from_memory(this._impl, data);
25
+ }
26
+ targetCount() {
27
+ return this._targets.length;
28
+ }
29
+ getTargetInfo(i) {
30
+ let current = this._targets[i];
31
+ if (current && current.info)
32
+ return current.info;
33
+ current.info = {
34
+ topRadius: -1,
35
+ bottomRadius: -1,
36
+ sideLength: -1,
37
+ physicalScaleFactor: -1
38
+ };
39
+ try {
40
+ const reader = new RiffReader(current.data, false);
41
+ const imgChunk = reader.find("IMG ");
42
+ if (imgChunk) {
43
+ let mimeType = "image/png";
44
+ const mimeTypeChunk = reader.find("IMGM");
45
+ if (mimeTypeChunk)
46
+ mimeType = decoder.decode(mimeTypeChunk.data);
47
+ current.info.preview = { mimeType, compressed: imgChunk.data };
48
+ }
49
+ const odleChunk = reader.find("ODLE");
50
+ if (odleChunk) {
51
+ const odle = decoder.decode(odleChunk.data);
52
+ this._parseOdle(odle, current.info);
53
+ }
54
+ }
55
+ catch (err) { }
56
+ return current.info;
57
+ }
58
+ _parseOdle(data, info) {
59
+ let currentOffset = 0;
60
+ let version = "0";
61
+ [version, currentOffset] = readLine(currentOffset, data);
62
+ if (version === "3") {
63
+ let treeOrFlat = "0";
64
+ [treeOrFlat, currentOffset] = readLine(currentOffset, data);
65
+ if (treeOrFlat !== "0" && treeOrFlat !== "1")
66
+ return;
67
+ let numberTargets = "0";
68
+ [numberTargets, currentOffset] = readLine(currentOffset, data);
69
+ const parsedTargets = parseInt(numberTargets);
70
+ if (isNaN(parsedTargets) || parsedTargets < 1)
71
+ return;
72
+ let emptyLine = "";
73
+ [emptyLine, currentOffset] = readLine(currentOffset, data);
74
+ if (emptyLine.length !== 0)
75
+ return;
76
+ let infoLine = "";
77
+ [infoLine, currentOffset] = readLine(currentOffset, data);
78
+ const infoLineParts = infoLine.split(" ");
79
+ if (infoLineParts.length < 7)
80
+ return;
81
+ info.physicalScaleFactor = parseFloat(infoLineParts[6]);
82
+ if (isNaN(info.physicalScaleFactor))
83
+ info.physicalScaleFactor = -1;
84
+ if (infoLineParts.length >= 8) {
85
+ info.topRadius = parseFloat(infoLineParts[7]);
86
+ if (isNaN(info.topRadius))
87
+ info.topRadius = -1;
88
+ info.bottomRadius = info.topRadius;
89
+ }
90
+ if (infoLineParts.length >= 9) {
91
+ info.bottomRadius = parseFloat(infoLineParts[8]);
92
+ if (isNaN(info.bottomRadius))
93
+ info.bottomRadius = -1;
94
+ }
95
+ if (infoLineParts.length >= 10) {
96
+ info.sideLength = parseFloat(infoLineParts[9]);
97
+ if (isNaN(info.sideLength))
98
+ info.sideLength = -1;
99
+ }
100
+ }
101
+ }
102
+ getDecodedPreview(i) {
103
+ const info = this.getTargetInfo(i);
104
+ if (!info.preview)
105
+ return undefined;
106
+ const blob = new Blob([info.preview.compressed], { type: info.preview.mimeType });
107
+ const image = new Image();
108
+ image.src = URL.createObjectURL(blob);
109
+ return image;
110
+ }
111
+ }
112
+ function readLine(offset, str) {
113
+ let indx = str.indexOf("\n", offset);
114
+ return [str.substring(offset, indx >= 0 ? indx : undefined).replace("\r", ""), indx + 1];
115
+ }
@@ -0,0 +1,3 @@
1
+ import { Options } from "./options";
2
+ export * from "./index";
3
+ export declare function initialize(opts?: Options): import(".").Zappar;
@@ -0,0 +1,5 @@
1
+ import { initialize as init } from "./index";
2
+ export * from "./index";
3
+ export function initialize(opts) {
4
+ return init(Object.assign(Object.assign({}, opts), { worker: (opts === null || opts === void 0 ? void 0 : opts.worker) || new (require("worker-loader?inline=fallback!./worker").default)() }));
5
+ }
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { zappar } from "./gen/zappar";
2
2
  import { Additional } from "./additional";
3
+ import { Options } from "./options";
3
4
  export declare type Zappar = zappar & Additional;
4
- export declare function initialize(): Zappar;
5
+ export declare function initialize(opts?: Options): Zappar;
5
6
  export { zappar_image_tracker_t, zappar_instant_world_tracker_t, zappar_barcode_finder_t, zappar_face_tracker_t, zappar_face_landmark_t, barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, zappar_face_mesh_t, zappar_pipeline_t, zappar_camera_source_t, zappar_sequence_source_t } from "./gen/zappar";
package/lib/index.js CHANGED
@@ -1,28 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.log_level_t = exports.instant_world_tracker_transform_orientation_t = exports.face_landmark_name_t = exports.barcode_format_t = exports.initialize = void 0;
4
- if (typeof Z_STANDALONE !== 'undefined' && Z_STANDALONE) {
5
- if (document.currentScript) {
6
- const url = new URL(document.currentScript.src);
7
- let href = url.toString();
8
- if (url.pathname) {
9
- let pathParts = href.split("/");
10
- pathParts.pop();
11
- href = pathParts.join("/") + "/";
12
- }
13
- __webpack_public_path__ = href;
14
- }
1
+ import { initialize as nativeInitialize } from "./native";
2
+ import { VERSION } from "./version";
3
+ export function initialize(opts) {
4
+ console.log(`Zappar CV v${VERSION}`);
5
+ return nativeInitialize(opts);
15
6
  }
16
- ////
17
- const native_1 = require("./native");
18
- const version_1 = require("./version");
19
- function initialize() {
20
- console.log(`Zappar CV v${version_1.VERSION}`);
21
- return native_1.initialize();
22
- }
23
- exports.initialize = initialize;
24
- var zappar_1 = require("./gen/zappar");
25
- Object.defineProperty(exports, "barcode_format_t", { enumerable: true, get: function () { return zappar_1.barcode_format_t; } });
26
- Object.defineProperty(exports, "face_landmark_name_t", { enumerable: true, get: function () { return zappar_1.face_landmark_name_t; } });
27
- Object.defineProperty(exports, "instant_world_tracker_transform_orientation_t", { enumerable: true, get: function () { return zappar_1.instant_world_tracker_transform_orientation_t; } });
28
- Object.defineProperty(exports, "log_level_t", { enumerable: true, get: function () { return zappar_1.log_level_t; } });
7
+ export { barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t } from "./gen/zappar";
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,32 +7,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.generateDataCPP = exports.generateDataJSON = void 0;
13
- const facemesh_1 = require("./facemesh");
14
- const zappar_1 = require("./gen/zappar");
10
+ import { FaceMesh } from "./facemesh";
11
+ import { face_landmark_name_t } from "./gen/zappar";
15
12
  let vertexIndexByName = new Map([
16
- [zappar_1.face_landmark_name_t.EAR_LEFT, 888],
17
- [zappar_1.face_landmark_name_t.EAR_RIGHT, 467],
18
- [zappar_1.face_landmark_name_t.EYE_LEFT, [1076, 1062]],
19
- [zappar_1.face_landmark_name_t.EYE_RIGHT, [1094, 1108]],
20
- [zappar_1.face_landmark_name_t.NOSE_BRIDGE, 36],
21
- [zappar_1.face_landmark_name_t.NOSE_BASE, 3],
22
- [zappar_1.face_landmark_name_t.NOSE_TIP, 8],
23
- [zappar_1.face_landmark_name_t.LIP_TOP, 24],
24
- [zappar_1.face_landmark_name_t.LIP_BOTTOM, 25],
25
- [zappar_1.face_landmark_name_t.MOUTH_CENTER, [24, 25]],
26
- [zappar_1.face_landmark_name_t.CHIN, 1049],
27
- [zappar_1.face_landmark_name_t.EYEBROW_LEFT, 657],
28
- [zappar_1.face_landmark_name_t.EYEBROW_RIGHT, 210],
13
+ [face_landmark_name_t.EAR_LEFT, 888],
14
+ [face_landmark_name_t.EAR_RIGHT, 467],
15
+ [face_landmark_name_t.EYE_LEFT, [1076, 1062]],
16
+ [face_landmark_name_t.EYE_RIGHT, [1094, 1108]],
17
+ [face_landmark_name_t.NOSE_BRIDGE, 36],
18
+ [face_landmark_name_t.NOSE_BASE, 3],
19
+ [face_landmark_name_t.NOSE_TIP, 8],
20
+ [face_landmark_name_t.LIP_TOP, 24],
21
+ [face_landmark_name_t.LIP_BOTTOM, 25],
22
+ [face_landmark_name_t.MOUTH_CENTER, [24, 25]],
23
+ [face_landmark_name_t.CHIN, 1049],
24
+ [face_landmark_name_t.EYEBROW_LEFT, 657],
25
+ [face_landmark_name_t.EYEBROW_RIGHT, 210],
29
26
  ]);
30
- function generateDataJSON() {
27
+ export function generateDataJSON() {
31
28
  return __awaiter(this, void 0, void 0, function* () {
32
- let mesh = new facemesh_1.FaceMesh();
33
- let url = require("file-loader!./face_mesh_face_model.zbin").default;
34
- let req = yield fetch(url);
29
+ let mesh = new FaceMesh();
30
+ let url = new URL("./face_mesh_face_model.zbin", import.meta.url);
31
+ let req = yield fetch(url.toString());
35
32
  mesh.loadFromMemory(yield req.arrayBuffer(), false, false, false, false);
36
- let names = new Set([zappar_1.face_landmark_name_t.EYE_LEFT, zappar_1.face_landmark_name_t.EYE_RIGHT, zappar_1.face_landmark_name_t.EAR_LEFT, zappar_1.face_landmark_name_t.EAR_RIGHT, zappar_1.face_landmark_name_t.NOSE_BRIDGE, zappar_1.face_landmark_name_t.NOSE_TIP, zappar_1.face_landmark_name_t.NOSE_BASE, zappar_1.face_landmark_name_t.LIP_TOP, zappar_1.face_landmark_name_t.LIP_BOTTOM, zappar_1.face_landmark_name_t.MOUTH_CENTER, zappar_1.face_landmark_name_t.CHIN, zappar_1.face_landmark_name_t.EYEBROW_LEFT, zappar_1.face_landmark_name_t.EYEBROW_RIGHT]);
33
+ let names = new Set([face_landmark_name_t.EYE_LEFT, face_landmark_name_t.EYE_RIGHT, face_landmark_name_t.EAR_LEFT, face_landmark_name_t.EAR_RIGHT, face_landmark_name_t.NOSE_BRIDGE, face_landmark_name_t.NOSE_TIP, face_landmark_name_t.NOSE_BASE, face_landmark_name_t.LIP_TOP, face_landmark_name_t.LIP_BOTTOM, face_landmark_name_t.MOUTH_CENTER, face_landmark_name_t.CHIN, face_landmark_name_t.EYEBROW_LEFT, face_landmark_name_t.EYEBROW_RIGHT]);
37
34
  let data = {};
38
35
  for (let n of names) {
39
36
  let indices = vertexIndexByName.get(n);
@@ -55,17 +52,16 @@ function generateDataJSON() {
55
52
  });
56
53
  });
57
54
  }
58
- exports.generateDataJSON = generateDataJSON;
59
55
  function arrayAsCPPLiteral(a) {
60
56
  return `{ ${a.join(", ")} }`;
61
57
  }
62
- function generateDataCPP() {
58
+ export function generateDataCPP() {
63
59
  return __awaiter(this, void 0, void 0, function* () {
64
- let mesh = new facemesh_1.FaceMesh();
65
- let url = require("file-loader!./face_mesh_face_model.zbin").default;
66
- let req = yield fetch(url);
60
+ let mesh = new FaceMesh();
61
+ let url = new URL("./face_mesh_face_model.zbin", import.meta.url);
62
+ let req = yield fetch(url.toString());
67
63
  mesh.loadFromMemory(yield req.arrayBuffer(), false, false, false, false);
68
- let names = [zappar_1.face_landmark_name_t.EYE_LEFT, zappar_1.face_landmark_name_t.EYE_RIGHT, zappar_1.face_landmark_name_t.EAR_LEFT, zappar_1.face_landmark_name_t.EAR_RIGHT, zappar_1.face_landmark_name_t.NOSE_BRIDGE, zappar_1.face_landmark_name_t.NOSE_TIP, zappar_1.face_landmark_name_t.NOSE_BASE, zappar_1.face_landmark_name_t.LIP_TOP, zappar_1.face_landmark_name_t.LIP_BOTTOM, zappar_1.face_landmark_name_t.MOUTH_CENTER, zappar_1.face_landmark_name_t.CHIN, zappar_1.face_landmark_name_t.EYEBROW_LEFT, zappar_1.face_landmark_name_t.EYEBROW_RIGHT];
64
+ let names = [face_landmark_name_t.EYE_LEFT, face_landmark_name_t.EYE_RIGHT, face_landmark_name_t.EAR_LEFT, face_landmark_name_t.EAR_RIGHT, face_landmark_name_t.NOSE_BRIDGE, face_landmark_name_t.NOSE_TIP, face_landmark_name_t.NOSE_BASE, face_landmark_name_t.LIP_TOP, face_landmark_name_t.LIP_BOTTOM, face_landmark_name_t.MOUTH_CENTER, face_landmark_name_t.CHIN, face_landmark_name_t.EYEBROW_LEFT, face_landmark_name_t.EYEBROW_RIGHT];
69
65
  let output = "std::vector<std::vector<std::vector<float> > > _zappar_landmark_means = {\n";
70
66
  output += names.map(val => {
71
67
  let indices = vertexIndexByName.get(val);
@@ -99,4 +95,3 @@ function generateDataCPP() {
99
95
  return output;
100
96
  });
101
97
  }
102
- exports.generateDataCPP = generateDataCPP;
package/lib/loglevel.js CHANGED
@@ -1,24 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zcwarn = exports.zcerr = exports.zcout = exports.setLogLevel = void 0;
4
- const zappar_1 = require("./gen/zappar");
5
- let logLevel = zappar_1.log_level_t.LOG_LEVEL_ERROR;
6
- function setLogLevel(l) {
1
+ import { log_level_t } from "./gen/zappar";
2
+ let logLevel = log_level_t.LOG_LEVEL_ERROR;
3
+ export function setLogLevel(l) {
7
4
  logLevel = l;
8
5
  }
9
- exports.setLogLevel = setLogLevel;
10
- function zcout(...args) {
11
- if (logLevel >= zappar_1.log_level_t.LOG_LEVEL_VERBOSE)
6
+ export function zcout(...args) {
7
+ if (logLevel >= log_level_t.LOG_LEVEL_VERBOSE)
12
8
  console.log("[Zappar] INFO", ...args);
13
9
  }
14
- exports.zcout = zcout;
15
- function zcerr(...args) {
16
- if (logLevel >= zappar_1.log_level_t.LOG_LEVEL_ERROR)
10
+ export function zcerr(...args) {
11
+ if (logLevel >= log_level_t.LOG_LEVEL_ERROR)
17
12
  console.error("[Zappar] ERROR", ...args);
18
13
  }
19
- exports.zcerr = zcerr;
20
- function zcwarn(...args) {
21
- if (logLevel >= zappar_1.log_level_t.LOG_LEVEL_VERBOSE)
14
+ export function zcwarn(...args) {
15
+ if (logLevel >= log_level_t.LOG_LEVEL_VERBOSE)
22
16
  console.log("[Zappar] WARN", ...args);
23
17
  }
24
- exports.zcwarn = zcwarn;
package/lib/messages.js CHANGED
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MsgManager = void 0;
4
- const event_1 = require("./event");
5
- class MsgManager {
1
+ import { Event, Event1 } from "./event";
2
+ export class MsgManager {
6
3
  constructor() {
7
- this.onOutgoingMessage = new event_1.Event();
8
- this.onIncomingMessage = new event_1.Event1();
4
+ this.onOutgoingMessage = new Event();
5
+ this.onIncomingMessage = new Event1();
9
6
  this._outgoingMessages = [];
10
7
  }
11
8
  postIncomingMessage(msg) {
@@ -24,4 +21,3 @@ class MsgManager {
24
21
  return ret;
25
22
  }
26
23
  }
27
- exports.MsgManager = MsgManager;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,15 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MSTPCameraSource = void 0;
13
- const profile_1 = require("./profile");
14
- const pipeline_1 = require("./pipeline");
15
- const source_1 = require("./source");
16
- const cameramodel_1 = require("./cameramodel");
17
- const loglevel_1 = require("./loglevel");
18
- const camera_source_map_1 = require("./camera-source-map");
19
- class MSTPCameraSource extends source_1.Source {
10
+ import { profile } from "./profile";
11
+ import { Pipeline } from "./pipeline";
12
+ import { Source } from "./source";
13
+ import { cameraRotationForScreenOrientation } from "./cameramodel";
14
+ import { zcout } from "./loglevel";
15
+ import { deleteCameraSource } from "./camera-source-map";
16
+ export class MSTPCameraSource extends Source {
20
17
  constructor(_impl, _pipeline, _deviceId) {
21
18
  super();
22
19
  this._impl = _impl;
@@ -29,7 +26,7 @@ class MSTPCameraSource extends source_1.Source {
29
26
  this._cameraToScreenRotation = 0;
30
27
  this._hasStartedOrientation = false;
31
28
  this._deviceMotionListener = (ev) => {
32
- let pipeline = pipeline_1.Pipeline.get(this._pipeline);
29
+ let pipeline = Pipeline.get(this._pipeline);
33
30
  if (!pipeline)
34
31
  return;
35
32
  let timeStamp = (ev.timeStamp !== undefined && ev.timeStamp !== null) ? ev.timeStamp : performance.now();
@@ -37,7 +34,7 @@ class MSTPCameraSource extends source_1.Source {
37
34
  ev.accelerationIncludingGravity.x !== null &&
38
35
  ev.accelerationIncludingGravity.y !== null &&
39
36
  ev.accelerationIncludingGravity.z !== null) {
40
- pipeline.motionAccelerometerSubmit(timeStamp, ev.accelerationIncludingGravity.x * profile_1.profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.y * profile_1.profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.z * profile_1.profile.deviceMotionMutliplier);
37
+ pipeline.motionAccelerometerSubmit(timeStamp, ev.accelerationIncludingGravity.x * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.y * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.z * profile.deviceMotionMutliplier);
41
38
  }
42
39
  if (ev.rotationRate !== null &&
43
40
  ev.rotationRate.alpha !== null &&
@@ -50,11 +47,11 @@ class MSTPCameraSource extends source_1.Source {
50
47
  this._startDeviceOrientation();
51
48
  }
52
49
  };
53
- loglevel_1.zcout("Using MSTP camera source");
50
+ zcout("Using MSTP camera source");
54
51
  }
55
52
  destroy() {
56
53
  this.pause();
57
- camera_source_map_1.deleteCameraSource(this._impl);
54
+ deleteCameraSource(this._impl);
58
55
  }
59
56
  _stop() {
60
57
  if (!this._currentStream)
@@ -65,7 +62,7 @@ class MSTPCameraSource extends source_1.Source {
65
62
  }
66
63
  pause() {
67
64
  this._isPaused = true;
68
- let p = pipeline_1.Pipeline.get(this._pipeline);
65
+ let p = Pipeline.get(this._pipeline);
69
66
  if (p && p.currentCameraSource === this)
70
67
  p.currentCameraSource = undefined;
71
68
  this._stopDeviceMotion();
@@ -73,7 +70,7 @@ class MSTPCameraSource extends source_1.Source {
73
70
  }
74
71
  start() {
75
72
  var _a;
76
- let p = pipeline_1.Pipeline.get(this._pipeline);
73
+ let p = Pipeline.get(this._pipeline);
77
74
  if (p && p.currentCameraSource !== this) {
78
75
  (_a = p.currentCameraSource) === null || _a === void 0 ? void 0 : _a.pause();
79
76
  p.currentCameraSource = this;
@@ -98,9 +95,9 @@ class MSTPCameraSource extends source_1.Source {
98
95
  audio: false,
99
96
  video: {
100
97
  facingMode: facingMode,
101
- width: profile_1.profile.videoWidth,
102
- height: profile_1.profile.videoHeight,
103
- frameRate: profile_1.profile.requestHighFrameRate ? 60 : 30,
98
+ width: profile.videoWidth,
99
+ height: profile.videoHeight,
100
+ frameRate: profile.requestHighFrameRate ? 60 : 30,
104
101
  deviceId: deviceId
105
102
  }
106
103
  };
@@ -128,7 +125,7 @@ class MSTPCameraSource extends source_1.Source {
128
125
  return constraints;
129
126
  }
130
127
  if (typeof constraints.video === "object") {
131
- loglevel_1.zcout("choosing device ID", devices[devices.length - 1].deviceId);
128
+ zcout("choosing device ID", devices[devices.length - 1].deviceId);
132
129
  constraints.video.deviceId = devices[devices.length - 1].deviceId;
133
130
  }
134
131
  return constraints;
@@ -136,9 +133,9 @@ class MSTPCameraSource extends source_1.Source {
136
133
  }
137
134
  getFrame(allowRead) {
138
135
  var _a, _b;
139
- let rotation = cameramodel_1.cameraRotationForScreenOrientation(false);
136
+ let rotation = cameraRotationForScreenOrientation(false);
140
137
  if (rotation != this._cameraToScreenRotation) {
141
- (_b = (_a = pipeline_1.Pipeline.get(this._pipeline)) === null || _a === void 0 ? void 0 : _a.sendCameraToScreenRotationToWorker) === null || _b === void 0 ? void 0 : _b.call(_a, rotation);
138
+ (_b = (_a = Pipeline.get(this._pipeline)) === null || _a === void 0 ? void 0 : _a.sendCameraToScreenRotationToWorker) === null || _b === void 0 ? void 0 : _b.call(_a, rotation);
142
139
  this._cameraToScreenRotation = rotation;
143
140
  }
144
141
  return;
@@ -176,7 +173,7 @@ class MSTPCameraSource extends source_1.Source {
176
173
  let processor = new MediaStreamTrackProcessor({
177
174
  track: videoTracks[0]
178
175
  });
179
- let p = pipeline_1.Pipeline.get(this._pipeline);
176
+ let p = Pipeline.get(this._pipeline);
180
177
  if (p)
181
178
  p.sendCameraStreamToWorker(this._impl, processor.readable, this._isUserFacing);
182
179
  }
@@ -189,7 +186,7 @@ class MSTPCameraSource extends source_1.Source {
189
186
  return;
190
187
  this._hasStartedOrientation = true;
191
188
  window.addEventListener("deviceorientation", (ev) => {
192
- let pipeline = pipeline_1.Pipeline.get(this._pipeline);
189
+ let pipeline = Pipeline.get(this._pipeline);
193
190
  if (!pipeline)
194
191
  return;
195
192
  let timeStamp = (ev.timeStamp !== undefined && ev.timeStamp !== null) ? ev.timeStamp : performance.now();
@@ -205,7 +202,7 @@ class MSTPCameraSource extends source_1.Source {
205
202
  window.removeEventListener("devicemotion", this._deviceMotionListener);
206
203
  }
207
204
  uploadGL(info) {
208
- const pipeline = pipeline_1.Pipeline.get(this._pipeline);
205
+ const pipeline = Pipeline.get(this._pipeline);
209
206
  const gl = pipeline === null || pipeline === void 0 ? void 0 : pipeline.glContext;
210
207
  if (!info ||
211
208
  info.texture ||
@@ -225,6 +222,5 @@ class MSTPCameraSource extends source_1.Source {
225
222
  delete info.frame;
226
223
  }
227
224
  }
228
- exports.MSTPCameraSource = MSTPCameraSource;
229
225
  MSTPCameraSource.USER_DEFAULT_DEVICE_ID = "Simulated User Default Device ID: a908df7f-5661-4d20-b227-a1c15d2fdb4b";
230
226
  MSTPCameraSource.DEFAULT_DEVICE_ID = "Simulated Default Device ID: a908df7f-5661-4d20-b227-a1c15d2fdb4b";
package/lib/native.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { Zappar } from ".";
2
- export declare function initialize(): Zappar;
2
+ import { Options } from "./options";
3
+ export declare function initialize(opts?: Options): Zappar;