|
|
import "./style.css";
|
|
|
|
|
|
async function loadProvincesLocal() {
|
|
|
const res = await fetch("./provinces.json", { cache: "no-store" });
|
|
|
if (!res.ok) throw new Error("Không tải được provinces.json");
|
|
|
return res.json();
|
|
|
}
|
|
|
|
|
|
function makeWorker(url) {
|
|
|
return new Worker(new URL(url, import.meta.url), { type: "module" });
|
|
|
}
|
|
|
|
|
|
async function boot() {
|
|
|
const el = document.querySelector("#app");
|
|
|
el.innerHTML = `
|
|
|
<div style="padding:16px;font-family:system-ui">
|
|
|
<h2>CAD2MAP (Local-only)</h2>
|
|
|
<div id="prov">Đang tải provinces...</div>
|
|
|
<input id="file" type="file" />
|
|
|
<div id="log" style="margin-top:12px;white-space:pre-wrap"></div>
|
|
|
</div>
|
|
|
`;
|
|
|
|
|
|
const log = (s) => (document.querySelector("#log").textContent += s + "\n");
|
|
|
|
|
|
|
|
|
try {
|
|
|
const p = await loadProvincesLocal();
|
|
|
document.querySelector("#prov").textContent = `Provinces: ${p.length} (từ provinces.json, không cloud)`;
|
|
|
} catch (e) {
|
|
|
document.querySelector("#prov").textContent = "Lỗi tải provinces (local)";
|
|
|
log(String(e));
|
|
|
}
|
|
|
|
|
|
|
|
|
const dxfWorker = makeWorker("./workers/dxf-parser-worker.js");
|
|
|
|
|
|
document.querySelector("#file").addEventListener("change", async (ev) => {
|
|
|
const f = ev.target.files?.[0];
|
|
|
if (!f) return;
|
|
|
|
|
|
const buf = await f.arrayBuffer();
|
|
|
const id = crypto.randomUUID();
|
|
|
dxfWorker.postMessage({ id, input: { fileName: f.name, buffer: buf } }, [buf]);
|
|
|
|
|
|
dxfWorker.onmessage = (msgEv) => {
|
|
|
const { success, error } = msgEv.data || {};
|
|
|
if (!success) log("DXF worker: " + (error || "fail"));
|
|
|
else log("DXF worker: OK");
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
boot();
|
|
|
|