camstreamerlib 3.5.2 → 4.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 (72) hide show
  1. package/CamOverlayAPI.d.ts +11 -28
  2. package/CamOverlayAPI.js +116 -138
  3. package/CamOverlayDrawingAPI.js +26 -18
  4. package/CamOverlayPainter/Frame.js +167 -182
  5. package/CamOverlayPainter/Painter.js +80 -101
  6. package/CamOverlayPainter/ResourceManager.js +31 -46
  7. package/CamScripterAPI.d.ts +19 -0
  8. package/CamScripterAPI.js +66 -0
  9. package/CamScripterAPICameraEventsGenerator.js +22 -16
  10. package/CamStreamerAPI.d.ts +5 -27
  11. package/CamStreamerAPI.js +45 -71
  12. package/CamSwitcherAPI.d.ts +38 -71
  13. package/CamSwitcherAPI.js +329 -91
  14. package/CamSwitcherEvents.d.ts +15 -33
  15. package/CamSwitcherEvents.js +53 -97
  16. package/CreatePackage.js +5 -7
  17. package/README.md +3 -1
  18. package/VapixAPI.d.ts +66 -0
  19. package/VapixAPI.js +454 -0
  20. package/VapixEvents.js +18 -16
  21. package/errors/errors.d.ts +34 -0
  22. package/errors/errors.js +66 -0
  23. package/events/AxisCameraStationEvents.js +29 -42
  24. package/events/GenetecAgent.d.ts +14 -15
  25. package/events/GenetecAgent.js +81 -100
  26. package/internal/Digest.js +5 -11
  27. package/internal/ProxyClient.d.ts +11 -0
  28. package/internal/ProxyClient.js +40 -0
  29. package/internal/common.d.ts +19 -4
  30. package/internal/common.js +11 -26
  31. package/internal/constants.d.ts +1 -0
  32. package/internal/constants.js +1 -0
  33. package/internal/transformers.d.ts +5 -0
  34. package/internal/transformers.js +25 -0
  35. package/internal/utils.d.ts +11 -0
  36. package/internal/utils.js +34 -0
  37. package/internal/versionCompare.d.ts +6 -0
  38. package/internal/versionCompare.js +44 -0
  39. package/node/DefaultClient.d.ts +15 -0
  40. package/node/DefaultClient.js +50 -0
  41. package/{internal → node}/HttpRequestSender.d.ts +2 -2
  42. package/node/HttpRequestSender.js +85 -0
  43. package/{HttpServer.d.ts → node/HttpServer.d.ts} +1 -1
  44. package/{HttpServer.js → node/HttpServer.js} +22 -24
  45. package/{internal → node}/WsClient.d.ts +1 -1
  46. package/{internal → node}/WsClient.js +32 -39
  47. package/node/WsEventClient.d.ts +13 -0
  48. package/node/WsEventClient.js +18 -0
  49. package/package.json +7 -3
  50. package/types/CamOverlayAPI.d.ts +188 -0
  51. package/types/CamOverlayAPI.js +44 -0
  52. package/types/CamScripterAPI.d.ts +67 -0
  53. package/types/CamScripterAPI.js +17 -0
  54. package/types/CamStreamerAPI.d.ts +139 -0
  55. package/types/CamStreamerAPI.js +25 -0
  56. package/types/CamSwitcherAPI.d.ts +814 -0
  57. package/types/CamSwitcherAPI.js +134 -0
  58. package/types/CamswitcherEvents.d.ts +491 -0
  59. package/types/CamswitcherEvents.js +59 -0
  60. package/types/VapixAPI.d.ts +1704 -0
  61. package/types/VapixAPI.js +129 -0
  62. package/types/common.d.ts +37 -0
  63. package/types/common.js +11 -0
  64. package/web/DefaultClient.d.ts +6 -0
  65. package/web/DefaultClient.js +16 -0
  66. package/web/WsClient.d.ts +13 -0
  67. package/web/WsClient.js +58 -0
  68. package/CameraVapix.d.ts +0 -98
  69. package/CameraVapix.js +0 -441
  70. package/DefaultAgent.d.ts +0 -15
  71. package/DefaultAgent.js +0 -68
  72. package/internal/HttpRequestSender.js +0 -117
@@ -1,40 +1,44 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Frame = void 0;
13
- const events_1 = require("events");
14
- class Frame extends events_1.EventEmitter {
1
+ import { EventEmitter } from 'events';
2
+ export class Frame extends EventEmitter {
3
+ enabled;
4
+ posX;
5
+ posY;
6
+ width;
7
+ height;
8
+ text = '';
9
+ fontColor;
10
+ fontName;
11
+ font;
12
+ align = 'A_LEFT';
13
+ textType = 'TFM_OVERFLOW';
14
+ bgColor;
15
+ bgImageName;
16
+ bgImage;
17
+ bgType;
18
+ borderRadius;
19
+ borderWidth;
20
+ borderColor;
21
+ customDraw;
22
+ layer;
23
+ children = new Array();
15
24
  constructor(opt) {
16
- var _a, _b, _c, _d, _e, _f, _g;
17
25
  super();
18
- this.text = '';
19
- this.align = 'A_LEFT';
20
- this.textType = 'TFM_OVERFLOW';
21
- this.children = new Array();
22
- this.enabled = (_a = opt.enabled) !== null && _a !== void 0 ? _a : true;
26
+ this.enabled = opt.enabled ?? true;
23
27
  this.posX = opt.x;
24
28
  this.posY = opt.y;
25
29
  this.width = opt.width;
26
30
  this.height = opt.height;
27
- this.setText((_b = opt.text) !== null && _b !== void 0 ? _b : '', 'A_LEFT');
28
- this.fontColor = (_c = opt.fontColor) !== null && _c !== void 0 ? _c : [1.0, 1.0, 1.0];
31
+ this.setText(opt.text ?? '', 'A_LEFT');
32
+ this.fontColor = opt.fontColor ?? [1.0, 1.0, 1.0];
29
33
  this.fontName = opt.font;
30
34
  this.bgColor = opt.bgColor;
31
35
  this.bgImageName = opt.bgImage;
32
36
  this.bgType = opt.bgType;
33
- this.borderRadius = (_d = opt.borderRadius) !== null && _d !== void 0 ? _d : 0;
34
- this.borderWidth = (_e = opt.borderWidth) !== null && _e !== void 0 ? _e : 0;
35
- this.borderColor = (_f = opt.borderColor) !== null && _f !== void 0 ? _f : [1, 1, 1, 1];
37
+ this.borderRadius = opt.borderRadius ?? 0;
38
+ this.borderWidth = opt.borderWidth ?? 0;
39
+ this.borderColor = opt.borderColor ?? [1, 1, 1, 1];
36
40
  this.customDraw = opt.customDraw;
37
- this.layer = (_g = opt.layer) !== null && _g !== void 0 ? _g : 0;
41
+ this.layer = opt.layer ?? 0;
38
42
  }
39
43
  enable() {
40
44
  this.enabled = true;
@@ -141,172 +145,153 @@ class Frame extends events_1.EventEmitter {
141
145
  layoutChanged() {
142
146
  this.emit('layoutChanged');
143
147
  }
144
- displayImage(cod, resourceManager, cairo, ppX, ppY, scale, layer) {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- if (this.enabled) {
147
- ppX += this.posX;
148
- ppY += this.posY;
149
- yield this.prepareResources(resourceManager);
150
- yield cod.cairo('cairo_save', cairo);
151
- yield this.clipDrawing(cod, cairo, scale, ppX, ppY);
152
- if (this.layer === layer) {
153
- yield this.displayOwnImage(cod, cairo, ppX, ppY, scale);
154
- }
155
- for (const child of this.children) {
156
- yield child.displayImage(cod, resourceManager, cairo, ppX, ppY, scale, layer);
157
- }
158
- yield cod.cairo('cairo_restore', cairo);
159
- }
160
- });
161
- }
162
- prepareResources(resourceManager) {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- if (this.bgImageName !== undefined) {
165
- this.bgImage = yield resourceManager.image(this.bgImageName);
166
- }
167
- if (this.fontName !== undefined) {
168
- this.font = yield resourceManager.font(this.fontName);
169
- }
170
- });
171
- }
172
- displayOwnImage(cod, cairo, ppX, ppY, scale) {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- if (!this.enabled) {
175
- return;
176
- }
177
- const promises = new Array();
178
- if (this.font !== undefined) {
179
- promises.push(cod.cairo('cairo_set_font_face', cairo, this.font.var));
180
- }
181
- else {
182
- promises.push(cod.cairo('cairo_set_font_face', cairo, 'NULL'));
183
- }
184
- if (this.bgColor !== undefined) {
185
- promises.push(this.drawFrame(cod, cairo, scale, ppX, ppY));
186
- }
187
- if (this.bgImage !== undefined) {
188
- promises.push(this.drawImage(cod, cairo, scale, ppX, ppY));
189
- }
190
- if (this.borderWidth > 0) {
191
- promises.push(this.drawBorder(cod, cairo, scale, ppX, ppY));
148
+ async displayImage(cod, resourceManager, cairo, ppX, ppY, scale, layer) {
149
+ if (this.enabled) {
150
+ const posX = ppX + this.posX;
151
+ const posY = ppY + this.posY;
152
+ await this.prepareResources(resourceManager);
153
+ await cod.cairo('cairo_save', cairo);
154
+ await this.clipDrawing(cod, cairo, scale, posX, posY);
155
+ if (this.layer === layer) {
156
+ await this.displayOwnImage(cod, cairo, posX, posY, scale);
192
157
  }
193
- if (this.text) {
194
- promises.push(this.drawText(cod, cairo, scale, ppX, ppY));
158
+ for (const child of this.children) {
159
+ await child.displayImage(cod, resourceManager, cairo, posX, posY, scale, layer);
195
160
  }
196
- if (this.customDraw) {
197
- promises.push(cod.cairo('cairo_identity_matrix', cairo));
198
- promises.push(cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY));
199
- promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
200
- promises.push(this.customDraw(cod, cairo, { width: this.width, height: this.height }));
201
- }
202
- yield Promise.all(promises);
203
- });
161
+ await cod.cairo('cairo_restore', cairo);
162
+ }
204
163
  }
205
- clipDrawing(cod, cairo, scale, ppX, ppY) {
206
- return __awaiter(this, void 0, void 0, function* () {
207
- if (this.borderRadius === 0) {
208
- return;
209
- }
210
- yield Promise.all([
211
- this.drawRectPath(cod, cairo, scale, ppX, ppY, this.borderRadius),
212
- cod.cairo('cairo_clip', cairo),
213
- ]);
214
- });
215
- }
216
- drawFrame(cod, cairo, scale, ppX, ppY) {
217
- return __awaiter(this, void 0, void 0, function* () {
218
- if (this.bgColor) {
219
- const promises = [
220
- cod.cairo('cairo_identity_matrix', cairo),
221
- cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
222
- cod.cairo('cairo_scale', cairo, scale, scale),
223
- cod.cairo('cairo_set_source_rgba', cairo, this.bgColor[0], this.bgColor[1], this.bgColor[2], this.bgColor[3]),
224
- cod.cairo('cairo_rectangle', cairo, 0, 0, this.width, this.height),
225
- cod.cairo('cairo_fill', cairo),
226
- cod.cairo('cairo_stroke', cairo),
227
- ];
228
- yield Promise.all(promises);
229
- }
230
- else {
231
- throw new Error('Color of the frame is undefined.');
232
- }
233
- });
164
+ async prepareResources(resourceManager) {
165
+ if (this.bgImageName !== undefined) {
166
+ this.bgImage = await resourceManager.image(this.bgImageName);
167
+ }
168
+ if (this.fontName !== undefined) {
169
+ this.font = await resourceManager.font(this.fontName);
170
+ }
234
171
  }
235
- drawImage(cod, cairo, scale, ppX, ppY) {
236
- return __awaiter(this, void 0, void 0, function* () {
237
- if (this.bgImage === undefined) {
238
- return;
239
- }
240
- const bgImage = this.bgImage.var;
241
- const bgWidth = this.bgImage.width;
242
- const bgHeight = this.bgImage.height;
243
- const promises = new Array();
172
+ async displayOwnImage(cod, cairo, ppX, ppY, scale) {
173
+ if (!this.enabled) {
174
+ return;
175
+ }
176
+ const promises = new Array();
177
+ if (this.font !== undefined) {
178
+ promises.push(cod.cairo('cairo_set_font_face', cairo, this.font.var));
179
+ }
180
+ else {
181
+ promises.push(cod.cairo('cairo_set_font_face', cairo, 'NULL'));
182
+ }
183
+ if (this.bgColor !== undefined) {
184
+ promises.push(this.drawFrame(cod, cairo, scale, ppX, ppY));
185
+ }
186
+ if (this.bgImage !== undefined) {
187
+ promises.push(this.drawImage(cod, cairo, scale, ppX, ppY));
188
+ }
189
+ if (this.borderWidth > 0) {
190
+ promises.push(this.drawBorder(cod, cairo, scale, ppX, ppY));
191
+ }
192
+ if (this.text) {
193
+ promises.push(this.drawText(cod, cairo, scale, ppX, ppY));
194
+ }
195
+ if (this.customDraw) {
244
196
  promises.push(cod.cairo('cairo_identity_matrix', cairo));
245
197
  promises.push(cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY));
246
- if (this.bgType === 'fill') {
247
- const sx = (scale * this.width) / bgWidth;
248
- const sy = (scale * this.height) / bgHeight;
249
- promises.push(cod.cairo('cairo_scale', cairo, sx, sy));
250
- }
251
- else if (this.bgType === 'fit') {
252
- const sx = this.width / bgWidth;
253
- const sy = this.height / bgHeight;
254
- const scaleRatio = scale * Math.min(sx, sy);
255
- promises.push(cod.cairo('cairo_scale', cairo, scaleRatio, scaleRatio));
256
- }
257
- else {
258
- promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
259
- }
260
- promises.push(cod.cairo('cairo_set_source_surface', cairo, bgImage, 0, 0));
261
- promises.push(cod.cairo('cairo_paint', cairo));
262
- yield Promise.all(promises);
263
- });
198
+ promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
199
+ promises.push(this.customDraw(cod, cairo, { width: this.width, height: this.height }));
200
+ }
201
+ await Promise.all(promises);
264
202
  }
265
- drawText(cod, cairo, scale, ppX, ppY) {
266
- return __awaiter(this, void 0, void 0, function* () {
203
+ async clipDrawing(cod, cairo, scale, ppX, ppY) {
204
+ if (this.borderRadius === 0) {
205
+ return;
206
+ }
207
+ await Promise.all([
208
+ this.drawRectPath(cod, cairo, scale, ppX, ppY, this.borderRadius),
209
+ cod.cairo('cairo_clip', cairo),
210
+ ]);
211
+ }
212
+ async drawFrame(cod, cairo, scale, ppX, ppY) {
213
+ if (this.bgColor) {
267
214
  const promises = [
268
215
  cod.cairo('cairo_identity_matrix', cairo),
269
- cod.cairo('cairo_set_source_rgb', cairo, this.fontColor[0], this.fontColor[1], this.fontColor[2]),
270
- cod.writeText(cairo, '' + this.text, Math.floor(scale * ppX), Math.floor(scale * ppY), Math.floor(scale * this.width), Math.floor(scale * this.height), this.align, this.textType),
271
- ];
272
- yield Promise.all(promises);
273
- });
274
- }
275
- drawBorder(cod, cairo, scale, ppX, ppY) {
276
- return __awaiter(this, void 0, void 0, function* () {
277
- yield Promise.all([
278
- this.drawRectPath(cod, cairo, scale, ppX, ppY, this.borderRadius),
279
- cod.cairo('cairo_set_source_rgba', cairo, this.borderColor[0], this.borderColor[1], this.borderColor[2], this.borderColor[3]),
280
- cod.cairo('cairo_set_line_width', cairo, this.borderWidth),
216
+ cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
217
+ cod.cairo('cairo_scale', cairo, scale, scale),
218
+ cod.cairo('cairo_set_source_rgba', cairo, this.bgColor[0], this.bgColor[1], this.bgColor[2], this.bgColor[3]),
219
+ cod.cairo('cairo_rectangle', cairo, 0, 0, this.width, this.height),
220
+ cod.cairo('cairo_fill', cairo),
281
221
  cod.cairo('cairo_stroke', cairo),
222
+ ];
223
+ await Promise.all(promises);
224
+ }
225
+ else {
226
+ throw new Error('Color of the frame is undefined.');
227
+ }
228
+ }
229
+ async drawImage(cod, cairo, scale, ppX, ppY) {
230
+ if (this.bgImage === undefined) {
231
+ return;
232
+ }
233
+ const bgImage = this.bgImage.var;
234
+ const bgWidth = this.bgImage.width;
235
+ const bgHeight = this.bgImage.height;
236
+ const promises = new Array();
237
+ promises.push(cod.cairo('cairo_identity_matrix', cairo));
238
+ promises.push(cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY));
239
+ if (this.bgType === 'fill') {
240
+ const sx = (scale * this.width) / bgWidth;
241
+ const sy = (scale * this.height) / bgHeight;
242
+ promises.push(cod.cairo('cairo_scale', cairo, sx, sy));
243
+ }
244
+ else if (this.bgType === 'fit') {
245
+ const sx = this.width / bgWidth;
246
+ const sy = this.height / bgHeight;
247
+ const scaleRatio = scale * Math.min(sx, sy);
248
+ promises.push(cod.cairo('cairo_scale', cairo, scaleRatio, scaleRatio));
249
+ }
250
+ else {
251
+ promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
252
+ }
253
+ promises.push(cod.cairo('cairo_set_source_surface', cairo, bgImage, 0, 0));
254
+ promises.push(cod.cairo('cairo_paint', cairo));
255
+ await Promise.all(promises);
256
+ }
257
+ async drawText(cod, cairo, scale, ppX, ppY) {
258
+ const promises = [
259
+ cod.cairo('cairo_identity_matrix', cairo),
260
+ cod.cairo('cairo_set_source_rgb', cairo, this.fontColor[0], this.fontColor[1], this.fontColor[2]),
261
+ cod.writeText(cairo, '' + this.text, Math.floor(scale * ppX), Math.floor(scale * ppY), Math.floor(scale * this.width), Math.floor(scale * this.height), this.align, this.textType),
262
+ ];
263
+ await Promise.all(promises);
264
+ }
265
+ async drawBorder(cod, cairo, scale, ppX, ppY) {
266
+ await Promise.all([
267
+ this.drawRectPath(cod, cairo, scale, ppX, ppY, this.borderRadius),
268
+ cod.cairo('cairo_set_source_rgba', cairo, this.borderColor[0], this.borderColor[1], this.borderColor[2], this.borderColor[3]),
269
+ cod.cairo('cairo_set_line_width', cairo, this.borderWidth),
270
+ cod.cairo('cairo_stroke', cairo),
271
+ ]);
272
+ }
273
+ async drawRectPath(cod, cairo, scale, ppX, ppY, radius) {
274
+ if (radius === 0) {
275
+ return await Promise.all([
276
+ cod.cairo('cairo_identity_matrix', cairo),
277
+ cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
278
+ cod.cairo('cairo_scale', cairo, scale, scale),
279
+ cod.cairo('cairo_rectangle', cairo, 0, 0, this.width, this.height),
282
280
  ]);
283
- });
284
- }
285
- drawRectPath(cod, cairo, scale, ppX, ppY, radius) {
286
- return __awaiter(this, void 0, void 0, function* () {
287
- if (radius === 0) {
288
- return yield Promise.all([
289
- cod.cairo('cairo_identity_matrix', cairo),
290
- cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
291
- cod.cairo('cairo_scale', cairo, scale, scale),
292
- cod.cairo('cairo_rectangle', cairo, 0, 0, this.width, this.height),
293
- ]);
294
- }
295
- else {
296
- const degrees = Math.PI / 180;
297
- return yield Promise.all([
298
- cod.cairo('cairo_identity_matrix', cairo),
299
- cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
300
- cod.cairo('cairo_scale', cairo, scale, scale),
301
- cod.cairo('cairo_new_sub_path', cairo),
302
- cod.cairo('cairo_arc', cairo, this.width - radius, radius, radius, -90 * degrees, 0 * degrees),
303
- cod.cairo('cairo_arc', cairo, this.width - radius, this.height - radius, radius, 0 * degrees, 90 * degrees),
304
- cod.cairo('cairo_arc', cairo, radius, this.height - radius, radius, 90 * degrees, 180 * degrees),
305
- cod.cairo('cairo_arc', cairo, radius, radius, radius, 180 * degrees, 270 * degrees),
306
- cod.cairo('cairo_close_path', cairo),
307
- ]);
308
- }
309
- });
281
+ }
282
+ else {
283
+ const degrees = Math.PI / 180;
284
+ return await Promise.all([
285
+ cod.cairo('cairo_identity_matrix', cairo),
286
+ cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
287
+ cod.cairo('cairo_scale', cairo, scale, scale),
288
+ cod.cairo('cairo_new_sub_path', cairo),
289
+ cod.cairo('cairo_arc', cairo, this.width - radius, radius, radius, -90 * degrees, 0 * degrees),
290
+ cod.cairo('cairo_arc', cairo, this.width - radius, this.height - radius, radius, 0 * degrees, 90 * degrees),
291
+ cod.cairo('cairo_arc', cairo, radius, this.height - radius, radius, 90 * degrees, 180 * degrees),
292
+ cod.cairo('cairo_arc', cairo, radius, radius, radius, 180 * degrees, 270 * degrees),
293
+ cod.cairo('cairo_close_path', cairo),
294
+ ]);
295
+ }
310
296
  }
311
297
  }
312
- exports.Frame = Frame;
@@ -1,21 +1,7 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ResourceManager = exports.Frame = exports.Painter = exports.COORD = void 0;
13
- const CamOverlayDrawingAPI_1 = require("../CamOverlayDrawingAPI");
14
- const ResourceManager_1 = require("./ResourceManager");
15
- exports.ResourceManager = ResourceManager_1.default;
16
- const Frame_1 = require("./Frame");
17
- Object.defineProperty(exports, "Frame", { enumerable: true, get: function () { return Frame_1.Frame; } });
18
- exports.COORD = {
1
+ import { CamOverlayDrawingAPI } from '../CamOverlayDrawingAPI';
2
+ import ResourceManager from './ResourceManager';
3
+ import { Frame } from './Frame';
4
+ export const COORD = {
19
5
  top_left: [-1, -1],
20
6
  center_left: [-1, 0],
21
7
  bottom_left: [-1, 1],
@@ -26,16 +12,21 @@ exports.COORD = {
26
12
  center_right: [1, 0],
27
13
  bottom_right: [1, 1],
28
14
  };
29
- class Painter extends Frame_1.Frame {
15
+ export class Painter extends Frame {
16
+ screenWidth;
17
+ screenHeight;
18
+ coAlignment;
19
+ cod;
20
+ rm;
21
+ refreshLayers = true;
22
+ layers = [];
30
23
  constructor(opt, coopt) {
31
24
  super(opt);
32
- this.refreshLayers = true;
33
- this.layers = [];
34
- this.coAlignment = exports.COORD[opt.coAlignment];
25
+ this.coAlignment = COORD[opt.coAlignment];
35
26
  this.screenWidth = opt.screenWidth;
36
27
  this.screenHeight = opt.screenHeight;
37
- this.cod = new CamOverlayDrawingAPI_1.CamOverlayDrawingAPI(coopt);
38
- this.rm = new ResourceManager_1.default(this.cod);
28
+ this.cod = new CamOverlayDrawingAPI(coopt);
29
+ this.rm = new ResourceManager(this.cod);
39
30
  }
40
31
  get camOverlayDrawingAPI() {
41
32
  return this.cod;
@@ -75,98 +66,86 @@ class Painter extends Frame_1.Frame {
75
66
  this.screenHeight = sh;
76
67
  }
77
68
  setCoAlignment(coAlignment) {
78
- this.coAlignment = exports.COORD[coAlignment];
69
+ this.coAlignment = COORD[coAlignment];
79
70
  }
80
71
  layoutChanged() {
81
72
  this.refreshLayers = true;
82
73
  }
83
- display(scale = 1.0) {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- if (this.enabled) {
86
- if (this.refreshLayers) {
87
- this.refreshLayers = false;
88
- yield this.prepareLayers();
74
+ async display(scale = 1.0) {
75
+ if (this.enabled) {
76
+ if (this.refreshLayers) {
77
+ this.refreshLayers = false;
78
+ await this.prepareLayers();
79
+ }
80
+ let cairo;
81
+ let surface;
82
+ let lastCachedLayer;
83
+ for (let i = 0; i < this.layers.length; i++) {
84
+ const layer = this.layers[i];
85
+ if (layer.cairoCache !== undefined &&
86
+ layer.surfaceCache !== undefined &&
87
+ surface === undefined &&
88
+ cairo === undefined) {
89
+ lastCachedLayer = layer;
90
+ continue;
89
91
  }
90
- let cairo;
91
- let surface;
92
- let lastCachedLayer;
93
- for (let i = 0; i < this.layers.length; i++) {
94
- const layer = this.layers[i];
95
- if (layer.cairoCache !== undefined &&
96
- layer.surfaceCache !== undefined &&
97
- surface === undefined &&
98
- cairo === undefined) {
99
- lastCachedLayer = layer;
100
- continue;
101
- }
102
- if (surface === undefined || cairo === undefined) {
103
- [surface, cairo] = yield this.prepareSurface(scale, lastCachedLayer === null || lastCachedLayer === void 0 ? void 0 : lastCachedLayer.surfaceCache, lastCachedLayer === null || lastCachedLayer === void 0 ? void 0 : lastCachedLayer.cairoCache);
104
- }
105
- yield this.displayImage(this.cod, this.rm, cairo, -this.posX, -this.posY, scale, layer.layer);
106
- if (i < this.layers.length - 1) {
107
- const [surfaceToCache, cairoToCache] = yield this.prepareSurface(scale, surface, cairo);
108
- layer.surfaceCache = surfaceToCache;
109
- layer.cairoCache = cairoToCache;
110
- }
92
+ if (surface === undefined || cairo === undefined) {
93
+ [surface, cairo] = await this.prepareSurface(scale, lastCachedLayer?.surfaceCache, lastCachedLayer?.cairoCache);
111
94
  }
112
- if (surface !== undefined && cairo !== undefined) {
113
- yield this.cod.showCairoImage(surface, this.positionConvertor(this.coAlignment[0], this.screenWidth, this.posX, scale * this.width), this.positionConvertor(this.coAlignment[1], this.screenHeight, this.posY, scale * this.height));
114
- yield this.cleanupSurface(surface, cairo);
95
+ await this.displayImage(this.cod, this.rm, cairo, -this.posX, -this.posY, scale, layer.layer);
96
+ if (i < this.layers.length - 1) {
97
+ const [surfaceToCache, cairoToCache] = await this.prepareSurface(scale, surface, cairo);
98
+ layer.surfaceCache = surfaceToCache;
99
+ layer.cairoCache = cairoToCache;
115
100
  }
116
101
  }
117
- });
102
+ if (surface !== undefined && cairo !== undefined) {
103
+ await this.cod.showCairoImage(surface, this.positionConvertor(this.coAlignment[0], this.screenWidth, this.posX, scale * this.width), this.positionConvertor(this.coAlignment[1], this.screenHeight, this.posY, scale * this.height));
104
+ await this.cleanupSurface(surface, cairo);
105
+ }
106
+ }
118
107
  }
119
- hide() {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- yield this.cod.removeImage();
122
- });
108
+ async hide() {
109
+ await this.cod.removeImage();
123
110
  }
124
- invalidateLayer(layer) {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- const layerIdx = this.layers.findIndex((l) => l.layer === layer);
127
- if (layerIdx === -1) {
128
- return;
129
- }
130
- for (let i = layerIdx; i < this.layers.length; i++) {
131
- const layer = this.layers[i];
132
- if (layer.surfaceCache !== undefined && layer.cairoCache !== undefined) {
133
- yield this.cleanupSurface(layer.surfaceCache, layer.cairoCache);
134
- layer.surfaceCache = undefined;
135
- layer.cairoCache = undefined;
136
- }
111
+ async invalidateLayer(layer) {
112
+ const layerIdx = this.layers.findIndex((l) => l.layer === layer);
113
+ if (layerIdx === -1) {
114
+ return;
115
+ }
116
+ for (let i = layerIdx; i < this.layers.length; i++) {
117
+ const currentLayer = this.layers[i];
118
+ if (currentLayer.surfaceCache !== undefined && currentLayer.cairoCache !== undefined) {
119
+ await this.cleanupSurface(currentLayer.surfaceCache, currentLayer.cairoCache);
120
+ currentLayer.surfaceCache = undefined;
121
+ currentLayer.cairoCache = undefined;
137
122
  }
138
- });
123
+ }
139
124
  }
140
- prepareLayers() {
141
- return __awaiter(this, void 0, void 0, function* () {
142
- for (const layer of this.layers) {
143
- if (layer.surfaceCache !== undefined && layer.cairoCache !== undefined) {
144
- yield this.cleanupSurface(layer.surfaceCache, layer.cairoCache);
145
- }
125
+ async prepareLayers() {
126
+ for (const layer of this.layers) {
127
+ if (layer.surfaceCache !== undefined && layer.cairoCache !== undefined) {
128
+ await this.cleanupSurface(layer.surfaceCache, layer.cairoCache);
146
129
  }
147
- const uniqueLayers = this.getLayers();
148
- const sortedLayers = Array.from(uniqueLayers).sort((a, b) => a - b);
149
- this.layers = sortedLayers.map((layer) => {
150
- return { layer };
151
- });
130
+ }
131
+ const uniqueLayers = this.getLayers();
132
+ const sortedLayers = Array.from(uniqueLayers).sort((a, b) => a - b);
133
+ this.layers = sortedLayers.map((layer) => {
134
+ return { layer };
152
135
  });
153
136
  }
154
- prepareSurface(scale, cachedSurface, cachedCairo) {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- const surface = (yield this.cod.cairo('cairo_image_surface_create', 'CAIRO_FORMAT_ARGB32', Math.floor(this.width * scale), Math.floor(this.height * scale)));
157
- const cairo = (yield this.cod.cairo('cairo_create', surface.var));
158
- if (cachedSurface !== undefined && cachedCairo !== undefined) {
159
- yield this.cod.cairo('cairo_set_source_surface', cairo.var, cachedSurface, 0, 0);
160
- yield this.cod.cairo('cairo_paint', cairo.var);
161
- }
162
- return [surface.var, cairo.var];
163
- });
137
+ async prepareSurface(scale, cachedSurface, cachedCairo) {
138
+ const surface = (await this.cod.cairo('cairo_image_surface_create', 'CAIRO_FORMAT_ARGB32', Math.floor(this.width * scale), Math.floor(this.height * scale)));
139
+ const cairo = (await this.cod.cairo('cairo_create', surface.var));
140
+ if (cachedSurface !== undefined && cachedCairo !== undefined) {
141
+ await this.cod.cairo('cairo_set_source_surface', cairo.var, cachedSurface, 0, 0);
142
+ await this.cod.cairo('cairo_paint', cairo.var);
143
+ }
144
+ return [surface.var, cairo.var];
164
145
  }
165
- cleanupSurface(surface, cairo) {
166
- return __awaiter(this, void 0, void 0, function* () {
167
- yield this.cod.cairo('cairo_surface_destroy', surface);
168
- yield this.cod.cairo('cairo_destroy', cairo);
169
- });
146
+ async cleanupSurface(surface, cairo) {
147
+ await this.cod.cairo('cairo_surface_destroy', surface);
148
+ await this.cod.cairo('cairo_destroy', cairo);
170
149
  }
171
150
  positionConvertor(alignment, screenSize, position, graphicsSize) {
172
151
  switch (alignment) {
@@ -181,4 +160,4 @@ class Painter extends Frame_1.Frame {
181
160
  }
182
161
  }
183
162
  }
184
- exports.Painter = Painter;
163
+ export { Frame, ResourceManager };