forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayground.js
More file actions
31 lines (25 loc) · 702 Bytes
/
playground.js
File metadata and controls
31 lines (25 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import init, {transform} from '../node/pkg';
let enc = new TextEncoder();
let dec = new TextDecoder();
let inputs = document.querySelectorAll('input[type=number]');
async function update() {
await init();
let targets = {};
for (let input of inputs) {
if (input.value !== '') {
targets[input.id] = input.valueAsNumber << 16;
}
}
let res = transform({
filename: 'test.css',
code: enc.encode(source.value),
minify: minify.checked,
targets: Object.keys(targets).length === 0 ? null : targets
});
compiled.value = dec.decode(res.code);
}
update();
source.oninput = update;
for (let input of document.querySelectorAll('input')) {
input.oninput = update;
}