Files
wehub-resource-sync dde272c4b8
CD - Docker - GHCR Images / Build and Push Images (push) Waiting to run
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

41 lines
1.0 KiB
TypeScript

import { version } from '@freecodecamp/browser-scripts/package.json';
// work around for SASS error in Edge
// https://github.com/medialize/sass.js/issues/96#issuecomment-424386171
interface WorkerWithSass extends Worker {
Sass: {
compile(data: unknown, callback: unknown): void;
};
}
const ctx: WorkerWithSass & typeof globalThis =
self as unknown as WorkerWithSass & typeof globalThis;
if (!ctx.crypto) {
(ctx.crypto as unknown) = {
getRandomValues: function (array: number[]) {
for (let i = 0, l = array.length; i < l; i++) {
array[i] = Math.floor(Math.random() * 256);
}
return array;
}
};
}
ctx.importScripts(`/js/workers/${version}/sass.sync.js`);
ctx.onmessage = e => {
const data: unknown = e.data;
ctx.Sass.compile(data, (result: Record<string, unknown>) => {
if (result.status === 0) {
ctx.postMessage(result.text);
} else {
ctx.postMessage({
type: 'error',
data: { message: result.formatted }
});
}
});
};
ctx.postMessage({ type: 'contentLoaded' });