Synthetic DOM demo refresh

This commit is contained in:
SheetJS 2024-06-25 03:16:41 -04:00
parent 066741f185
commit c4d9ba0948
19 changed files with 264 additions and 40 deletions

@ -131,14 +131,14 @@ const puppeteer = require('puppeteer');
:::note Tested Deployments
This demo was last tested on 2024 January 27 against Puppeteer 21.9.0.
This demo was last tested on 2024 June 24 against Puppeteer 22.12.0.
:::
1) Install SheetJS and Puppeteer:
<CodeBlock language="bash">{`\
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz puppeteer@21.9.0`}
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz puppeteer@22.12.0`}
</CodeBlock>
2) Save the `SheetJSPuppeteer.js` code snippet to `SheetJSPuppeteer.js`.
@ -206,7 +206,7 @@ await browser.close();`}
:::note Tested Deployments
This demo was last tested on 2024 January 27 against deno-puppeteer 16.2.0.
This demo was last tested on 2024 June 24 against deno-puppeteer 16.2.0.
:::
@ -294,14 +294,14 @@ const { webkit } = require('playwright'); // import desired browser
:::note Tested Deployments
This demo was last tested on 2024 January 27 against Playwright 1.41.1.
This demo was last tested on 2024 June 24 against Playwright 1.45.0.
:::
1) Install SheetJS and Playwright:
<CodeBlock language="bash">{`\
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz playwright@1.41.1`}
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz playwright@1.45.0`}
</CodeBlock>
2) Save the `SheetJSPlaywright.js` code snippet to `SheetJSPlaywright.js`.

@ -107,15 +107,33 @@ const workbook = XLSX.utils.table_to_book(doc);
XLSX.writeFile(workbook, "SheetJSDOM.xlsx");
```
<details>
<summary><b>Complete Demo</b> (click to show)</summary>
:::note Tested Deployments
This demo was last tested on 2024 January 27 against JSDOM `24.0.0`
This demo was tested in the following deployments:
| JSDOM | Date |
|:--------|:-----------|
| 24.1.0 | 2024-06-24 |
| 23.2.0 | 2024-06-24 |
| 22.1.0 | 2024-06-24 |
| 21.1.2 | 2024-06-24 |
| 20.0.3 | 2024-06-24 |
| 19.0.0 | 2024-06-24 |
| 18.1.1 | 2024-06-24 |
| 17.0.0 | 2024-06-24 |
| 16.7.0 | 2024-06-24 |
| 15.2.1 | 2024-06-24 |
| 14.1.0 | 2024-06-24 |
| 13.2.0 | 2024-06-24 |
| 12.2.0 | 2024-06-24 |
| 11.12.0 | 2024-06-24 |
| 10.1.0 | 2024-06-24 |
:::
<details>
<summary><b>Complete Demo</b> (click to show)</summary>
1) Install SheetJS and JSDOM libraries:
<CodeBlock language="bash">{`\
@ -148,15 +166,31 @@ the following patches were needed:
- TABLE `rows` property (explained above)
- TR `cells` property (explained above)
<details>
<summary><b>Complete Demo</b> (click to show)</summary>
:::note Tested Deployments
This demo was last tested on 2024 January 27 against HappyDOM `13.3.1`
This demo was tested in the following deployments:
| HappyDOM | Date |
|:---------|:-----------|
| 14.12.3 | 2024-06-24 |
| 13.10.1 | 2024-06-24 |
| 12.10.3 | 2024-06-24 |
| 11.2.0 | 2024-06-24 |
| 10.11.2 | 2024-06-24 |
| 9.20.3 | 2024-06-24 |
| 8.9.0 | 2024-06-24 |
| 7.8.1 | 2024-06-24 |
| 6.0.4 | 2024-06-24 |
| 5.4.0 | 2024-06-24 |
| 4.1.0 | 2024-06-24 |
| 3.2.2 | 2024-06-24 |
| 2.55.0 | 2024-06-24 |
:::
<details>
<summary><b>Complete Demo</b> (click to show)</summary>
1) Install SheetJS and HappyDOM libraries:
<CodeBlock language="bash">{`\

@ -324,7 +324,7 @@ Swift on MacOS supports JavaScriptCore without additional dependencies.
**Compiled**
The ["Swift C"](#swift-c) section starts from the static libraries built in the
["C++"](#c) section and build Swift bindings.
["C++"](#c) section and builds Swift bindings.
| Architecture | Version | Date |
|:-------------|:-----------------|:-----------|

@ -105,21 +105,21 @@ This demo was tested in the following deployments:
| OpenJDK | Nashorn | Date |
|:--------|:----------------|:-----------|
| 22 | 15.4 standalone | 2024-03-23 |
| 21.0.3 | 15.4 standalone | 2024-05-24 |
| 20.0.2 | 15.4 standalone | 2024-03-23 |
| 19.0.2 | 15.4 standalone | 2024-03-23 |
| 18.0.2 | 15.4 standalone | 2024-03-23 |
| 17.0.10 | 15.4 standalone | 2024-03-25 |
| 16.0.1 | 15.4 standalone | 2024-03-23 |
| 15.0.10 | 15.4 standalone | 2024-03-23 |
| 14.0.2 | Built-in | 2024-03-23 |
| 13.0.14 | Built-in | 2024-03-23 |
| 12.0.2 | Built-in | 2024-03-23 |
| 11.0.20 | Built-in | 2024-03-23 |
| 10.0.2 | Built-in | 2024-03-23 |
| 9 | Built-in | 2024-03-23 |
| 1.8.0 | Built-in | 2024-03-23 |
| 22.0.1 | 15.4 standalone | 2024-06-24 |
| 21.0.3 | 15.4 standalone | 2024-06-24 |
| 20.0.2 | 15.4 standalone | 2024-06-24 |
| 19.0.2 | 15.4 standalone | 2024-06-24 |
| 18.0.2 | 15.4 standalone | 2024-06-24 |
| 17.0.11 | 15.4 standalone | 2024-06-24 |
| 16.0.1 | 15.4 standalone | 2024-06-24 |
| 15.0.10 | 15.4 standalone | 2024-06-24 |
| 14.0.2 | Built-in | 2024-06-24 |
| 13.0.14 | Built-in | 2024-06-24 |
| 12.0.2 | Built-in | 2024-06-24 |
| 11.0.23 | Built-in | 2024-06-24 |
| 10.0.2 | Built-in | 2024-06-24 |
| 9 | Built-in | 2024-06-24 |
| 1.8.0 | Built-in | 2024-06-24 |
:::

@ -32,4 +32,3 @@ bun run sheet2csv.ts pres.numbers
bun build ./sheet2csv.ts --compile --outfile sheet2csv
./sheet2csv pres.numbers

@ -13,4 +13,3 @@ deno run -r --allow-read https://docs.sheetjs.com/cli/sheet2csv.ts pres.numbers
deno compile -r --allow-read https://docs.sheetjs.com/cli/sheet2csv.ts
./sheet2csv pres.numbers

@ -61,5 +61,3 @@ codesign -s - ./sheet2csv
./sheet2csv pres.numbers
codesign -dv ./sheet2csv

@ -17,4 +17,4 @@ npx pkg xlsx-cli.js
## NOTE: these steps are for darwin-x64
./xlsx-cli-macos pres.numbers
./xlsx-cli-macos pres.numbers

20
tests/dom-happydom.sh Executable file

@ -0,0 +1,20 @@
#!/bin/bash
# https://docs.sheetjs.com/docs/demos/net/dom#happydom
cd /tmp
rm -rf sheetjs-happydom
mkdir sheetjs-happydom
cd sheetjs-happydom
npm i --save https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz
curl -LO https://docs.sheetjs.com/dom/SheetJSHappyDOM.js
curl -LO https://docs.sheetjs.com/dom/SheetJSTable.html
for n in {2..14}; do
rm -f SheetJSHappyDOM.xlsx
npm i --save happy-dom@$n
npm ls | grep happy-dom
node SheetJSHappyDOM.js
npx -y xlsx-cli SheetJSHappyDOM.xlsx | head -n 3
done

36
tests/dom-jsdom.sh Executable file

@ -0,0 +1,36 @@
#!/bin/bash
# https://docs.sheetjs.com/docs/demos/net/dom#jsdom
cd /tmp
rm -rf sheetjs-jsdom
mkdir sheetjs-jsdom
cd sheetjs-jsdom
npm i --save https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz
cat >SheetJSDOM.js <<EOF
const XLSX = require("xlsx");
const { readFileSync } = require("fs");
const { JSDOM } = require("jsdom");
/* obtain HTML string. This example reads from SheetJSTable.html */
const html_str = readFileSync("SheetJSTable.html", "utf8");
/* get first TABLE element */
const doc = new JSDOM(html_str).window.document.querySelector("table");
/* generate workbook */
const workbook = XLSX.utils.table_to_book(doc);
XLSX.writeFile(workbook, "SheetJSDOM.xlsx");
EOF
curl -LO https://docs.sheetjs.com/dom/SheetJSTable.html
for n in {10..24}; do
rm -f SheetJSDom.xlsx
npm i --save jsdom@$n
npm ls | grep jsdom
node SheetJSDom.js
npx -y xlsx-cli SheetJSDom.xlsx | head -n 3
done

@ -14,4 +14,4 @@ curl -LO https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js
curl -LO https://sheetjs.com/pres.xlsx
curl -L -o src/main.rs https://docs.sheetjs.com/boa/main.rs
cargo run --release; echo $?
cargo run --release; echo $?

@ -10,4 +10,4 @@ curl -LO https://sheetjs.com/pres.numbers
curl -LO https://docs.sheetjs.com/execjs/ExecSheetJS.rb
ruby ExecSheetJS.rb pres.numbers; echo $?
ruby ExecSheetJS.rb pres.numbers; echo $?

@ -35,4 +35,4 @@ for n in {17..22}; do
cd sheethorn
java -cp ".:js-scriptengine-24.0.1.jar:js-language-24.0.1.jar:polyglot-24.0.1.jar:collections-24.0.1.jar:truffle-api-24.0.1.jar:nativeimage-24.0.1.jar:icu4j-24.0.1.jar:regex-24.0.1.jar:SheetJSNashorn.jar" -Dpolyglot.js.nashorn-compat=true SheetJSNashorn pres.xlsx
cd -
done
done

@ -34,4 +34,4 @@ console.log(XLSX.utils.sheet_to_csv(wb.Sheets[wb.SheetNames[0]]));
EOF
cat global.js xlsx.full.min.js payload.js jerry.js > xlsx.jerry.js
jerryscript/build/bin/jerry xlsx.jerry.js; echo $?
jerryscript/build/bin/jerry xlsx.jerry.js; echo $?

@ -19,7 +19,9 @@ curl -L -o asm-util-9.5.jar "https://search.maven.org/remotecontent?filepath=org
# Standalone Nashorn
for n in {15..22}; do
echo $n
export JAVA_HOME=`/usr/libexec/java_home -v $n`
echo $JAVA_HOME
java -version
rm -fr SheetJSNashorn.class SheetJSNashorn.jar sheethorn
javac SheetJSNashorn.java
@ -46,4 +48,3 @@ for n in 1.8 {9..14}; do
java -cp .:SheetJSNashorn.jar SheetJSNashorn pres.xlsx
cd -
done

@ -51,4 +51,4 @@ for n in 1.8 {9..22}; do
jar -cf SheetJS.jar SheetJSRhino.class com/sheetjs/*.class xlsx.full.min.js
java -cp ".:SheetJS.jar:rhino.jar" SheetJSRhino pres.xlsx
done
done

46
tests/headless-playwright.sh Executable file

@ -0,0 +1,46 @@
#!/bin/bash
# https://docs.sheetjs.com/docs/demos/net/headless#playwright
cd /tmp
rm -rf sheetjs-playwright
mkdir sheetjs-playwright
cd sheetjs-playwright
npm i --save https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz playwright@1.45.0
cat >SheetJSPlaywright.js <<EOF
const fs = require("fs");
const { webkit } = require('playwright'); // import desired browser
(async () => {
/* (1) Load the target page */
const browser = await webkit.launch(); // launch desired browser
const page = await browser.newPage();
page.on("console", msg => console.log("PAGE LOG:", msg.text()));
await page.setViewportSize({width: 1920, height: 1080}); // different name :(
await page.goto('https://sheetjs.com/demos/table');
/* (2) Load the standalone SheetJS build from the CDN */
await page.addScriptTag({ url: 'https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/xlsx.full.min.js' });
/* (3) Run the snippet in browser and return data */
const bin = await page.evaluate(() => {
/* find first table */
var table = document.body.getElementsByTagName('table')[0];
/* call table_to_book on first table */
var wb = XLSX.utils.table_to_book(table);
/* generate XLSB and return binary string */
return XLSX.write(wb, {type: "binary", bookType: "xlsb"});
});
/* (4) write data to file */
fs.writeFileSync("SheetJSPlaywright.xlsb", bin, { encoding: "binary" });
await browser.close();
})();
EOF
node SheetJSPlaywright.js
npx -y playwright@1.45.0 install
npx -y xlsx-cli SheetJSPlaywright.xlsb

@ -0,0 +1,44 @@
#!/bin/bash
# https://docs.sheetjs.com/docs/demos/net/headless#puppeteer
cd /tmp
rm -rf sheetjs-puppeteer-deno
mkdir sheetjs-puppeteer-deno
cd sheetjs-puppeteer-deno
env PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts
cat >SheetJSPuppeteer.ts <<EOF
import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts";
import { decode } from "https://deno.land/std/encoding/base64.ts"
/* (1) Load the target page */
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.on("console", msg => console.log("PAGE LOG:", msg.text()));
await page.setViewport({width: 1920, height: 1080});
await page.goto('https://sheetjs.com/demos/table');
/* (2) Load the standalone SheetJS build from the CDN */
await page.addScriptTag({ url: 'https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/xlsx.full.min.js' });
/* (3) Run the snippet in browser and return data */
const b64 = await page.evaluate(() => {
/* find first table */
var table = document.body.getElementsByTagName('table')[0];
/* call table_to_book on first table */
var wb = XLSX.utils.table_to_book(table);
/* generate XLSB and return binary string */
return XLSX.write(wb, {type: "base64", bookType: "xlsb"});
});
/* (4) write data to file */
Deno.writeFileSync("SheetJSPuppeteer.xlsb", decode(b64));
await browser.close();
EOF
deno run -A --unstable SheetJSPuppeteer.ts
npx -y xlsx-cli SheetJSPuppeteer.xlsb

47
tests/headless-puppeteer.sh Executable file

@ -0,0 +1,47 @@
#!/bin/bash
# https://docs.sheetjs.com/docs/demos/net/headless#puppeteer
cd /tmp
rm -rf sheetjs-puppeteer
mkdir sheetjs-puppeteer
cd sheetjs-puppeteer
npm i --save https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz puppeteer@22.12.0
cat >SheetJSPuppeteer.js <<EOF
const fs = require("fs");
const puppeteer = require('puppeteer');
(async () => {
/* (1) Load the target page */
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.on("console", msg => console.log("PAGE LOG:", msg.text()));
await page.setViewport({width: 1920, height: 1080});
await page.goto('https://sheetjs.com/demos/table');
/* (2) Load the standalone SheetJS build from the CDN */
await page.addScriptTag({ url: 'https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/xlsx.full.min.js' });
/* (3) Run the snippet in browser and return data */
const bin = await page.evaluate(() => {
/* find first table */
var table = document.body.getElementsByTagName('table')[0];
/* call table_to_book on first table */
var wb = XLSX.utils.table_to_book(table);
/* generate XLSB and return binary string */
return XLSX.write(wb, {type: "binary", bookType: "xlsb"});
});
/* (4) write data to file */
fs.writeFileSync("SheetJSPuppeteer.xlsb", bin, { encoding: "binary" });
await browser.close();
})();
EOF
node SheetJSPuppeteer.js
npx -y xlsx-cli SheetJSPuppeteer.xlsb