UNPKG

askui

Version:

Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on

38 lines (37 loc) 1.64 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Annotation = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const jsdom_1 = require("jsdom"); const detected_element_1 = require("../model/annotation-result/detected-element"); class Annotation { constructor(image, detected_elements = []) { this.image = image; this.detected_elements = detected_elements; } toHtml() { const template = Annotation.getHtmlTemplate(); const script = template.window.document.createElement('script'); script.innerHTML = ` var el = document.getElementsByTagName("bounding-box-renderer"); el[0].setAttribute("shouldrenderimage", true); el[0].setAttribute("imagestr", "${this.image.trim()}"); el[0].setAttribute("detectedobjects", JSON.stringify(${JSON.stringify(this.detected_elements)})); `; template.window.document.body.appendChild(script); return template; } static fromJson(json, resizeRatio = 1) { const annotation = json; return new Annotation(annotation.image, annotation.detected_elements.map((data) => detected_element_1.DetectedElement.fromJson(data, resizeRatio))); } static getHtmlTemplate() { const templatePath = path_1.default.join(__dirname, 'template.html'); return new jsdom_1.JSDOM(fs_1.default.readFileSync(templatePath, 'utf8')); } } exports.Annotation = Annotation;