askui 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -12
- package/dist/cjs/core/annotation/annotation-writer.js +2 -4
- package/dist/cjs/core/annotation/annotation.d.ts +3 -4
- package/dist/cjs/core/annotation/annotation.js +5 -4
- package/dist/cjs/core/inference-response/inference-response.d.ts +15 -0
- package/dist/cjs/core/inference-response/inference-response.js +25 -0
- package/dist/cjs/core/model/annotation-result/boundary-box.d.ts +23 -0
- package/dist/cjs/core/model/annotation-result/boundary-box.js +27 -0
- package/dist/cjs/core/model/annotation-result/detected-element.d.ts +9 -3
- package/dist/cjs/core/model/annotation-result/detected-element.js +10 -4
- package/dist/cjs/core/ui-control-commands/control-command.d.ts +1 -1
- package/dist/cjs/core/ui-control-commands/control-command.js +2 -1
- package/dist/cjs/core/ui-control-commands/index.d.ts +1 -0
- package/dist/cjs/core/ui-control-commands/index.js +3 -1
- package/dist/cjs/execution/dsl.d.ts +1076 -2
- package/dist/cjs/execution/dsl.js +1371 -7
- package/dist/cjs/execution/dsl.spec.js +4 -4
- package/dist/cjs/execution/execution-runtime.d.ts +2 -0
- package/dist/cjs/execution/execution-runtime.js +11 -1
- package/dist/cjs/execution/inference-client.d.ts +3 -0
- package/dist/cjs/execution/inference-client.js +28 -12
- package/dist/cjs/execution/inference-response-error.d.ts +2 -0
- package/dist/cjs/execution/inference-response-error.js +6 -0
- package/dist/cjs/execution/ui-control-client.d.ts +5 -3
- package/dist/cjs/execution/ui-control-client.js +10 -2
- package/dist/cjs/lib/copy-example-project.js +40 -4
- package/dist/cjs/utils/http/http-client-got.js +5 -1
- package/dist/esm/core/annotation/annotation-writer.js +2 -4
- package/dist/esm/core/annotation/annotation.d.ts +3 -4
- package/dist/esm/core/annotation/annotation.js +5 -4
- package/dist/esm/core/inference-response/inference-response.d.ts +15 -0
- package/dist/esm/core/inference-response/inference-response.js +21 -0
- package/dist/esm/core/model/annotation-result/boundary-box.d.ts +23 -0
- package/dist/esm/core/model/annotation-result/boundary-box.js +27 -0
- package/dist/esm/core/model/annotation-result/detected-element.d.ts +9 -3
- package/dist/esm/core/model/annotation-result/detected-element.js +10 -4
- package/dist/esm/core/ui-control-commands/control-command.d.ts +1 -1
- package/dist/esm/core/ui-control-commands/control-command.js +2 -1
- package/dist/esm/core/ui-control-commands/index.d.ts +1 -0
- package/dist/esm/core/ui-control-commands/index.js +1 -0
- package/dist/esm/execution/dsl.d.ts +1076 -2
- package/dist/esm/execution/dsl.js +1365 -6
- package/dist/esm/execution/dsl.spec.js +4 -4
- package/dist/esm/execution/execution-runtime.d.ts +2 -0
- package/dist/esm/execution/execution-runtime.js +11 -1
- package/dist/esm/execution/inference-client.d.ts +3 -0
- package/dist/esm/execution/inference-client.js +29 -13
- package/dist/esm/execution/inference-response-error.d.ts +2 -0
- package/dist/esm/execution/inference-response-error.js +2 -0
- package/dist/esm/execution/ui-control-client.d.ts +5 -3
- package/dist/esm/execution/ui-control-client.js +11 -3
- package/dist/esm/lib/copy-example-project.js +40 -4
- package/dist/esm/utils/http/http-client-got.js +5 -1
- package/dist/example_projects_templates/typescript_jest/test/helper/jest.setup.ts +6 -1
- package/dist/example_projects_templates/typescript_jest/test/my-first-askui-test-suite.test.ts +5 -0
- package/package.json +1 -1
- package/dist/cjs/core/annotation/annotation-json.d.ts +0 -5
- package/dist/cjs/core/annotation/annotation-json.js +0 -2
- package/dist/esm/core/annotation/annotation-json.d.ts +0 -5
- package/dist/esm/core/annotation/annotation-json.js +0 -1
package/README.md
CHANGED
|
@@ -14,28 +14,22 @@ To use **askui** follow these steps:
|
|
|
14
14
|
npm init
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
### 1. Install askui
|
|
17
|
+
### 1. Install askui with Needed Dependencies
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
-
npm i -D askui
|
|
20
|
+
npm i -D askui typescript ts-node @types/jest ts-jest jest
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
### 2.
|
|
23
|
+
### 2. Create your First Test
|
|
24
24
|
|
|
25
25
|
```
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### 3. Install Typescript
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
npm i -D @types/jest ts-jest ts-node typescript
|
|
26
|
+
npx askui init
|
|
33
27
|
```
|
|
34
28
|
|
|
35
|
-
###
|
|
29
|
+
### 3. Execute the Test
|
|
36
30
|
|
|
37
31
|
```
|
|
38
|
-
npx askui
|
|
32
|
+
npx jest test/my-first-askui-test-suite.test.ts --config ./test/jest.config.ts
|
|
39
33
|
```
|
|
40
34
|
|
|
41
35
|
## Documentation
|
|
@@ -10,10 +10,8 @@ const logger_1 = require("../../lib/logger");
|
|
|
10
10
|
class AnnotationWriter {
|
|
11
11
|
static write(html, outputFolder = 'report', fileNamePrefix = 'annotation') {
|
|
12
12
|
const currentDateTime = new Date();
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
+ `-${currentDateTime.getMinutes()}-${currentDateTime.getSeconds()}`;
|
|
16
|
-
const fileName = `${fileNamePrefix}_${formattedTime}.html`;
|
|
13
|
+
const currentTimeStringOnlyNumbers = currentDateTime.toISOString().replace(/\D/g, '');
|
|
14
|
+
const fileName = `${currentTimeStringOnlyNumbers}_${fileNamePrefix}.html`;
|
|
17
15
|
const outputFilePath = path_1.default.join(outputFolder, fileName);
|
|
18
16
|
if (!(fs_1.default.existsSync(outputFolder))) {
|
|
19
17
|
fs_1.default.mkdirSync(outputFolder, { recursive: true });
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { JSDOM } from 'jsdom';
|
|
2
2
|
import { DetectedElement } from '../model/annotation-result/detected-element';
|
|
3
|
-
import { AnnotationJson } from './annotation-json';
|
|
4
3
|
export declare class Annotation {
|
|
5
4
|
image: string;
|
|
6
|
-
|
|
7
|
-
constructor(image: string,
|
|
5
|
+
detected_elements: DetectedElement[];
|
|
6
|
+
constructor(image: string, detected_elements?: DetectedElement[]);
|
|
8
7
|
toHtml(): JSDOM;
|
|
9
|
-
static fromJson(json:
|
|
8
|
+
static fromJson(json: unknown, resizeRatio?: number): Annotation;
|
|
10
9
|
private static getHtmlTemplate;
|
|
11
10
|
}
|
|
@@ -9,9 +9,9 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const jsdom_1 = require("jsdom");
|
|
10
10
|
const detected_element_1 = require("../model/annotation-result/detected-element");
|
|
11
11
|
class Annotation {
|
|
12
|
-
constructor(image,
|
|
12
|
+
constructor(image, detected_elements = []) {
|
|
13
13
|
this.image = image;
|
|
14
|
-
this.
|
|
14
|
+
this.detected_elements = detected_elements;
|
|
15
15
|
}
|
|
16
16
|
toHtml() {
|
|
17
17
|
const template = Annotation.getHtmlTemplate();
|
|
@@ -20,13 +20,14 @@ class Annotation {
|
|
|
20
20
|
var el = document.getElementsByTagName("bounding-box-renderer");
|
|
21
21
|
el[0].setAttribute("shouldrenderimage", true);
|
|
22
22
|
el[0].setAttribute("imagestr", "${this.image.trim()}");
|
|
23
|
-
el[0].setAttribute("detectedobjects", JSON.stringify(${JSON.stringify(this.
|
|
23
|
+
el[0].setAttribute("detectedobjects", JSON.stringify(${JSON.stringify(this.detected_elements)}));
|
|
24
24
|
`;
|
|
25
25
|
template.window.document.body.appendChild(script);
|
|
26
26
|
return template;
|
|
27
27
|
}
|
|
28
28
|
static fromJson(json, resizeRatio = 1) {
|
|
29
|
-
|
|
29
|
+
const annotation = json;
|
|
30
|
+
return new Annotation(annotation.image, annotation.detected_elements.map((data) => detected_element_1.DetectedElement.fromJson(data, resizeRatio)));
|
|
30
31
|
}
|
|
31
32
|
static getHtmlTemplate() {
|
|
32
33
|
const templatePath = path_1.default.join(__dirname, 'template.html');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ControlCommand } from '../ui-control-commands/control-command';
|
|
2
|
+
import { Annotation } from '../annotation/annotation';
|
|
3
|
+
export declare class InferenceResponse {
|
|
4
|
+
type: string;
|
|
5
|
+
data: ControlCommand | Annotation;
|
|
6
|
+
constructor(type: string, data: ControlCommand | Annotation);
|
|
7
|
+
static fromJson(json: unknown, resizeRatio?: number, image?: string): ControlCommand | Annotation;
|
|
8
|
+
static createModels(type: string, data: ControlCommand | Annotation, resizeRatio: number, image?: string): ControlCommand | Annotation;
|
|
9
|
+
static models: Models;
|
|
10
|
+
}
|
|
11
|
+
interface Models {
|
|
12
|
+
DETECTED_ELEMENTS: CallableFunction;
|
|
13
|
+
COMMANDS: CallableFunction;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InferenceResponse = void 0;
|
|
4
|
+
const control_command_1 = require("../ui-control-commands/control-command");
|
|
5
|
+
const annotation_1 = require("../annotation/annotation");
|
|
6
|
+
class InferenceResponse {
|
|
7
|
+
constructor(type, data) {
|
|
8
|
+
this.type = type;
|
|
9
|
+
this.data = data;
|
|
10
|
+
}
|
|
11
|
+
static fromJson(json, resizeRatio = 1, image) {
|
|
12
|
+
const inferenceResponse = json;
|
|
13
|
+
return this.createModels(inferenceResponse.type, inferenceResponse.data, resizeRatio, image);
|
|
14
|
+
}
|
|
15
|
+
static createModels(type, data, resizeRatio, image) {
|
|
16
|
+
return this.models[type](data, resizeRatio, image);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.InferenceResponse = InferenceResponse;
|
|
20
|
+
InferenceResponse.models = {
|
|
21
|
+
DETECTED_ELEMENTS: (data, resizeRatio, image) => annotation_1.Annotation
|
|
22
|
+
.fromJson({ image, detected_elements: data.detected_elements }, resizeRatio),
|
|
23
|
+
COMMANDS: (data, resizeRatio) => control_command_1.ControlCommand
|
|
24
|
+
.fromJson(data, resizeRatio),
|
|
25
|
+
};
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @remarks
|
|
4
|
+
* The screen top left corner is the origin
|
|
5
|
+
*
|
|
6
|
+
* @param {number} xmin - The bounding box xmin coordinate in pixels
|
|
7
|
+
* @param {number} ymin - The bounding box ymin coordinate in pixels
|
|
8
|
+
* @param {number} xmax - The bounding box xmax coordinate in pixels
|
|
9
|
+
* @param {number} ymax - The bounding box ymax coordinate in pixels
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
1
12
|
export declare class BoundingBox {
|
|
2
13
|
xmin: number;
|
|
3
14
|
ymin: number;
|
|
@@ -5,4 +16,16 @@ export declare class BoundingBox {
|
|
|
5
16
|
ymax: number;
|
|
6
17
|
constructor(xmin: number, ymin: number, xmax: number, ymax: number);
|
|
7
18
|
static fromJson(boundinBox: BoundingBox, resizeRatio?: number): BoundingBox;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @returns {number} The bounding box height in pixels
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
get_height(): number;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @returns {number} The bounding box width in pixels
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
get_width(): number;
|
|
8
31
|
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BoundingBox = void 0;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The screen top left corner is the origin
|
|
8
|
+
*
|
|
9
|
+
* @param {number} xmin - The bounding box xmin coordinate in pixels
|
|
10
|
+
* @param {number} ymin - The bounding box ymin coordinate in pixels
|
|
11
|
+
* @param {number} xmax - The bounding box xmax coordinate in pixels
|
|
12
|
+
* @param {number} ymax - The bounding box ymax coordinate in pixels
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
4
15
|
class BoundingBox {
|
|
5
16
|
constructor(xmin, ymin, xmax, ymax) {
|
|
6
17
|
this.xmin = xmin;
|
|
@@ -11,5 +22,21 @@ class BoundingBox {
|
|
|
11
22
|
static fromJson(boundinBox, resizeRatio = 1) {
|
|
12
23
|
return new BoundingBox(boundinBox.xmin * resizeRatio, boundinBox.ymin * resizeRatio, boundinBox.xmax * resizeRatio, boundinBox.ymax * resizeRatio);
|
|
13
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @returns {number} The bounding box height in pixels
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
get_height() {
|
|
31
|
+
return this.ymax - this.ymin;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @returns {number} The bounding box width in pixels
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
get_width() {
|
|
39
|
+
return this.xmax - this.xmin;
|
|
40
|
+
}
|
|
14
41
|
}
|
|
15
42
|
exports.BoundingBox = BoundingBox;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { BoundingBox } from './boundary-box';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {string} name - The element type e.g text, button
|
|
5
|
+
* @param {string} text - The detected text inside the element
|
|
6
|
+
* @param {string[]} colors - The element top 3 dominate colors
|
|
7
|
+
* @param {BoundingBox} bndbox - The element bounding box
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
2
10
|
export declare class DetectedElement {
|
|
3
11
|
name: string;
|
|
4
|
-
truncated: number;
|
|
5
|
-
difficult: number;
|
|
6
12
|
text: string;
|
|
7
13
|
colors: string[];
|
|
8
14
|
bndbox: BoundingBox;
|
|
9
|
-
constructor(name: string,
|
|
15
|
+
constructor(name: string, text: string, colors: string[], bndbox: BoundingBox);
|
|
10
16
|
static fromJson(detectedElement: DetectedElement, resizeRatio?: number): DetectedElement;
|
|
11
17
|
}
|
|
@@ -2,17 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DetectedElement = void 0;
|
|
4
4
|
const boundary_box_1 = require("./boundary-box");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {string} name - The element type e.g text, button
|
|
8
|
+
* @param {string} text - The detected text inside the element
|
|
9
|
+
* @param {string[]} colors - The element top 3 dominate colors
|
|
10
|
+
* @param {BoundingBox} bndbox - The element bounding box
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
5
13
|
class DetectedElement {
|
|
6
|
-
constructor(name,
|
|
14
|
+
constructor(name, text, colors, bndbox) {
|
|
7
15
|
this.name = name;
|
|
8
|
-
this.truncated = truncated;
|
|
9
|
-
this.difficult = difficult;
|
|
10
16
|
this.text = text;
|
|
11
17
|
this.colors = colors;
|
|
12
18
|
this.bndbox = bndbox;
|
|
13
19
|
}
|
|
14
20
|
static fromJson(detectedElement, resizeRatio = 1) {
|
|
15
|
-
return new DetectedElement(detectedElement.name, detectedElement.
|
|
21
|
+
return new DetectedElement(detectedElement.name, detectedElement.text, detectedElement.colors, boundary_box_1.BoundingBox.fromJson(detectedElement.bndbox, resizeRatio));
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
24
|
exports.DetectedElement = DetectedElement;
|
|
@@ -5,6 +5,6 @@ export declare class ControlCommand {
|
|
|
5
5
|
actions: Action[];
|
|
6
6
|
tryToRepeat: boolean;
|
|
7
7
|
constructor(code: ControlCommandCode, actions: Action[], tryToRepeat?: boolean);
|
|
8
|
-
static fromJson(json:
|
|
8
|
+
static fromJson(json: unknown, resizeRatio?: number): ControlCommand;
|
|
9
9
|
setTextToBeTyped(text: string): void;
|
|
10
10
|
}
|
|
@@ -11,7 +11,8 @@ class ControlCommand {
|
|
|
11
11
|
this.tryToRepeat = tryToRepeat;
|
|
12
12
|
}
|
|
13
13
|
static fromJson(json, resizeRatio = 1) {
|
|
14
|
-
|
|
14
|
+
const controlCommand = json;
|
|
15
|
+
return new ControlCommand(control_command_code_1.ControlCommandCode[controlCommand.code], controlCommand.actions.map((action) => action_1.Action.fromJson(action, resizeRatio)), controlCommand.tryToRepeat);
|
|
15
16
|
}
|
|
16
17
|
setTextToBeTyped(text) {
|
|
17
18
|
this.actions = this.actions.map((action) => ([input_event_1.InputEvent.TYPE, input_event_1.InputEvent.TYPE_TEXT].includes(action.inputEvent)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ControlCommandCode = exports.ControlCommand = void 0;
|
|
3
|
+
exports.InferenceResponse = exports.ControlCommandCode = exports.ControlCommand = void 0;
|
|
4
4
|
var control_command_1 = require("./control-command");
|
|
5
5
|
Object.defineProperty(exports, "ControlCommand", { enumerable: true, get: function () { return control_command_1.ControlCommand; } });
|
|
6
6
|
var control_command_code_1 = require("./control-command-code");
|
|
7
7
|
Object.defineProperty(exports, "ControlCommandCode", { enumerable: true, get: function () { return control_command_code_1.ControlCommandCode; } });
|
|
8
|
+
var inference_response_1 = require("../inference-response/inference-response");
|
|
9
|
+
Object.defineProperty(exports, "InferenceResponse", { enumerable: true, get: function () { return inference_response_1.InferenceResponse; } });
|