mirror of
https://codeberg.org/demostf/frontend.git
synced 2026-06-03 18:24:12 +02:00
edit wip
This commit is contained in:
parent
0ab24ead47
commit
189788a1b6
14 changed files with 599 additions and 6 deletions
45
script/edit/EditWorker.ts
Normal file
45
script/edit/EditWorker.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import init from "@demostf/edit";
|
||||
import {count_ticks, edit_js} from "@demostf/edit";
|
||||
|
||||
declare function postMessage(message: any, transfer?: any[]): void;
|
||||
|
||||
function getCacheBuster(): string {
|
||||
const url = self.location.href;
|
||||
return url.substring(url.indexOf('?'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @global postMessage
|
||||
* @param event
|
||||
*/
|
||||
onmessage = async (event: MessageEvent) => {
|
||||
await init(`/tf-demo-editor.wasm${getCacheBuster()}`);
|
||||
if (event.data.count) {
|
||||
const buffer: ArrayBuffer = event.data.buffer;
|
||||
const bytes = new Uint8Array(buffer);
|
||||
try {
|
||||
const ticks = count_ticks(bytes);
|
||||
postMessage({
|
||||
ticks: ticks
|
||||
});
|
||||
} catch(e) {
|
||||
postMessage({
|
||||
error: e
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const buffer: ArrayBuffer = event.data.buffer;
|
||||
const options = event.data.options;
|
||||
const bytes = new Uint8Array(buffer);
|
||||
try {
|
||||
const edited = edit_js(bytes, options);
|
||||
postMessage({
|
||||
buffer: edited.buffer
|
||||
}, [edited.buffer]);
|
||||
} catch (e) {
|
||||
postMessage({
|
||||
error: e
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue