workerScript = {
const blob = new Blob(
[
`
importScripts("${await require.resolve("jszip@3/dist/jszip.min.js")}");
importScripts("${await require.resolve("@tmcw/togeojson@3")}");
importScripts("${await require.resolve("https://bundle.run/xmldom@0.3.0")}");
onmessage = async (event) => {
// prepare to peek into archive
const archive = await JSZip.loadAsync(event.data);
// find all the files that end with .kml (in case there is other noise like PNGs)
const files = archive.file(/\.kml$/);
const results = {};
for (const file of files) {
// the generated ID of this file
const name = file.name.replace('.kml', '');
// get the raw XML string...
const str = await file.async('string');
// ...and pass it through DOMParser
const kml = new xmldom.DOMParser().parseFromString(str, 'text/xml');
results[name] = toGeoJSON.kml(kml);
}
postMessage(results);
close();
};
`
],
{ type: "text/javascript" }
);
const script = URL.createObjectURL(blob);
invalidation.then(() => URL.revokeObjectURL(script));
return script;
}