1 // Set up worker and send it a message with the canvas to draw to.
2 const offscreenCanvas = document.getElementById('offscreen-canvas').transferControlToOffscreen();
3 const worker = new Worker('worker.js');
4 worker.postMessage({ offscreenCanvas }, [offscreenCanvas]);
6 const canvasKitInitPromise =
7 CanvasKitInit({locateFile: (file) => 'https://unpkg.com/canvaskit-wasm@0.25.0/bin/full/'+file});
8 const skottieJsonPromise =
9 fetch('https://storage.googleapis.com/skia-cdn/misc/lego_loader.json')
10 .then((response) => response.text());
19 const onscreenCanvas = document.getElementById('onscreen-canvas');
20 const surface = CanvasKit.MakeWebGLCanvasSurface(onscreenCanvas, null);
22 throw 'Could not make canvas surface';
25 SkottieExample(CanvasKit, surface, jsonStr);
28 document.getElementById('busy-button').addEventListener('click', () => {
29 const startTime = performance.now();
30 // This loop runs for 1300ms, emulating computation.
31 // 1300ms was chosen because it causes a visually obvious lag in the lego loader animation.
32 while (performance.now() - startTime < 1300) {