More work

This commit is contained in:
Thomas Forgione 2023-02-17 17:55:41 +01:00
parent accb2d4f3a
commit e5cca75737
1 changed files with 30 additions and 7 deletions

View File

@ -4,6 +4,9 @@ const fs = require('fs').promises;
const process = require('process'); const process = require('process');
const puppeteer = require('puppeteer'); const puppeteer = require('puppeteer');
// Size of the rendering of the web page
const size = { width: 1280, height: 720 };
async function main() { async function main() {
if (process.argv[2] === undefined) { if (process.argv[2] === undefined) {
@ -24,19 +27,30 @@ async function main() {
process.exit(1); process.exit(1);
} }
// Size of the rendering of the web page
const size = { width: 1280, height: 720 };
// Initialize browser // Initialize browser
const browser = await puppeteer.launch(); const browser = await puppeteer.launch();
const page = await browser.newPage(); const page = await browser.newPage();
await page.setViewport(size); await page.setViewport(size);
await page.goto("file://" + path); await page.goto("file://" + path);
let root = await page.$("#\\31"); let currentSlide = 1;
let hierarchy = {}; let hierarchy = [];
await analyseElement(root); while (true) {
let root = await page.$("#\\3" + currentSlide);
if (root === null) {
break;
}
let currentInfo = {};
hierarchy.push(currentInfo);
await analyseElement(root, currentInfo);
currentSlide++;
}
console.log(JSON.stringify(hierarchy, undefined, 4));
await browser.close(); await browser.close();
@ -51,13 +65,22 @@ async function analyseElement(element, hierarchy, tabs = '', stop = false) {
let className = await classAttr.jsonValue(); let className = await classAttr.jsonValue();
let box = await element.boundingBox(); let box = await element.boundingBox();
hierarchy.tag = tagName;
hierarchy.class = className;
hierarchy.x = box.x / size.width;
hierarchy.width = box.width / size.width;
hierarchy.y = box.y / size.height;
hierarchy.height = box.height / size.height;
hierarchy.children = [];
console.log(tabs + tagName + ' "' + className + '" ' + JSON.stringify(box)); console.log(tabs + tagName + ' "' + className + '" ' + JSON.stringify(box));
let children = await element.$$('> *'); let children = await element.$$('> *');
for (let child of children) { for (let child of children) {
await analyseElement(child, hierarchy, tabs + ' ', true); let currentInfo = {};
hierarchy.children.push(currentInfo);
await analyseElement(child, currentInfo, tabs + ' ', true);
} }
} }