(function (dl) {
"use strict";
class Handle {
constructor(marked) { this.$ = marked; Object.freeze(this); }
}
const enc = (v) => {
if (v instanceof Handle) return v.$;
if (typeof v === "function") return { $function: true };
if (Array.isArray(v)) return v.map(enc);
if (v !== null && typeof v === "object" && !(v instanceof Part)) {
const out = {};
for (const k of Object.keys(v)) if (v[k] !== undefined) out[k] = enc(v[k]);
return out;
}
if (v instanceof Part) return v.$;
return v;
};
class Part {
constructor(marked) {
this.$ = marked;
for (const name of marked.parts) {
let made;
Object.defineProperty(this, name, { enumerable: true, get: () => made || (made = dec(dl.get(marked, name))) });
}
Object.freeze(this);
}
}
const dec = (v) => {
if (Array.isArray(v)) return v.map(dec);
if (v === null || typeof v !== "object") return v;
if ("$features" in v || "$area" in v || "$lines" in v) return new Handle(v);
if ("$lazy" in v) return new Part(v);
const out = {};
for (const k of Object.keys(v)) out[k] = dec(v[k]);
return Object.freeze(out);
};
const call = (name) => (...args) => dec(dl.call(name, enc(args)));
const prop = (name) => () => dec(dl.prop(name));
const lib = {};
for (const name of dl.functions()) {
const [space, fn] = name.split(".");
if (fn === undefined) lib[space] = call(name);
else (lib[space] || (lib[space] = {}))[fn] = call(name);
}
for (const name of dl.properties()) {
const [space, key] = name.split(".");
Object.defineProperty(lib[space] || (lib[space] = {}), key, { enumerable: true, get: prop(name) });
}
lib.output = (spec) => {
if (!dl.outputBegin(enc(spec))) return;
const warps = spec.warp == null ? [] : Array.isArray(spec.warp) ? spec.warp : [spec.warp];
const done = [];
warps.forEach((w, n) => {
if (w != null && typeof w === "object" && "remap" in w) {
dl.outputWarps(enc(done));
const { columns, rows, points } = dl.remapGrid(enc(w), n);
const went = points.map((p) => w.remap(p));
done.push(dec(dl.remapMesh(n, columns, rows, points, enc(went))));
} else {
done.push(w);
}
});
dl.outputWarps(enc(done));
};
lib.view = (spec, style) => {
if (typeof style === "string") return dl.viewStyle(enc(spec), style);
if (typeof style !== "function") {
dl.fail(`view: the style is a name the host knows ("city-grain") or a function that draws, got ${dl.describe(enc(style))}`);
}
dl.viewBegin(enc(spec));
let ok = false;
try {
style();
ok = true;
} finally {
dl.viewEnd(ok);
}
return spec.id;
};
const burinTerrain = (build, options) => {
if (typeof build !== "function" && (build === null || typeof build !== "object")) {
dl.fail(`burin.terrain expects a function: burin.terrain((b) => { … }), got ${dl.describe(enc(build))}`);
}
const atlas = typeof build === "function" ? dl.burin(build) : build;
return dec(dl.call("burin.terrain", enc([atlas, options])));
};
lib.burin.terrain = burinTerrain;
lib.burin.script = burinTerrain;
for (const value of Object.values(lib)) if (typeof value === "object") Object.freeze(value);
return Object.freeze(lib);
})