@urban-toolkit/autk-grammar 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,14 @@
1
- import { DEFAULT_WORKSPACE_NAME as lt, AutkDb as St, DEFAULT_WORKSPACE_COORDINATE_FORMAT as ut, isRenderableTable as vt } from "@urban-toolkit/autk-db";
2
- import { AutkMap as Ct, MapEvent as D } from "@urban-toolkit/autk-map";
3
- import { AutkPlot as It, PlotEvent as O } from "@urban-toolkit/autk-plot";
4
- import { ColorMapInterpolator as Lt, ColorMapDomainStrategy as I, ColorMap as B } from "@urban-toolkit/autk-core";
5
- import { AutkComputeEngine as X } from "@urban-toolkit/autk-compute";
6
- function Pt(t) {
1
+ import { DEFAULT_WORKSPACE_NAME as j, isVectorTable as Nt, AutkDb as Tt, isRenderableTable as dt, DEFAULT_WORKSPACE_COORDINATE_FORMAT as $t } from "@urban-toolkit/autk-db";
2
+ import { AutkMap as Ot, MapEvent as Q } from "@urban-toolkit/autk-map";
3
+ import { AutkPlot as kt, PlotEvent as k } from "@urban-toolkit/autk-plot";
4
+ import { ColorMapInterpolator as Ft, ColorMapDomainStrategy as P, ColorMap as B } from "@urban-toolkit/autk-core";
5
+ import { AutkComputeEngine as Z } from "@urban-toolkit/autk-compute";
6
+ function Bt(t) {
7
7
  const { spec: e, adapters: r } = t;
8
8
  let o;
9
9
  async function n() {
10
10
  let i;
11
- if (e.data)
11
+ if (e.workspaces?.length && r.db.resolveWorkspaces && (i = await r.db.resolveWorkspaces(i, e.workspaces)), e.data)
12
12
  for (const l of e.data)
13
13
  i = await r.db.resolveSource(i, l);
14
14
  if (e.compute)
@@ -30,22 +30,22 @@ function Pt(t) {
30
30
  await r.plot.resolvePlot(i, e.plot);
31
31
  o = i;
32
32
  }
33
- function a(i) {
33
+ function s(i) {
34
34
  return console.log("Spec to update", i), new Promise((l) => {
35
35
  l();
36
36
  });
37
37
  }
38
- function s() {
38
+ function a() {
39
39
  console.log("Function not implemented yet");
40
40
  }
41
- return { run: n, updatedSpec: a, destroy: s, get context() {
41
+ return { run: n, updatedSpec: s, destroy: a, get context() {
42
42
  return o;
43
43
  } };
44
44
  }
45
- function z(t) {
45
+ function tt(t) {
46
46
  return t === void 0 ? [] : Array.isArray(t) ? t : [t];
47
47
  }
48
- function Re(t) {
48
+ function Te(t) {
49
49
  const e = t.layout ?? {}, r = e.type ?? "vertical";
50
50
  if (r !== "vertical" && r !== "horizontal" && r !== "grid")
51
51
  throw new Error(`Layout type must be vertical, horizontal or grid, not ${JSON.stringify(r)}.`);
@@ -55,71 +55,71 @@ function Re(t) {
55
55
  const n = e.columns ?? 2;
56
56
  if (!Number.isInteger(n) || n < 1)
57
57
  throw new Error(`Layout columns must be a whole number, 1 or more, not ${JSON.stringify(n)}.`);
58
- const a = [
59
- ...z(t.map).map((l, u) => ({ kind: "map", index: u, id: l.id, key: l.id ?? u })),
60
- ...z(t.plot).map((l, u) => ({ kind: "plot", index: u, id: l.id, key: l.id ?? l.dataRef }))
61
- ], s = r === "vertical" ? 1 : r === "horizontal" ? Math.max(a.length, 1) : n, i = a.map(({ kind: l, index: u, id: c, key: f }, p) => ({
58
+ const s = [
59
+ ...tt(t.map).map((l, u) => ({ kind: "map", index: u, id: l.id, key: l.id ?? u })),
60
+ ...tt(t.plot).map((l, u) => ({ kind: "plot", index: u, id: l.id, key: l.id ?? l.dataRef }))
61
+ ], a = r === "vertical" ? 1 : r === "horizontal" ? Math.max(s.length, 1) : n, i = s.map(({ kind: l, index: u, id: d, key: c }, f) => ({
62
62
  kind: l,
63
63
  index: u,
64
- ...c !== void 0 && { id: c },
65
- key: f,
66
- row: Math.floor(p / s),
67
- column: p % s
64
+ ...d !== void 0 && { id: d },
65
+ key: c,
66
+ row: Math.floor(f / a),
67
+ column: f % a
68
68
  }));
69
- return { type: r, rows: Math.ceil(a.length / s), columns: s, gap: o, panes: i };
69
+ return { type: r, rows: Math.ceil(s.length / a), columns: a, gap: o, panes: i };
70
70
  }
71
- var Nt = /* @__PURE__ */ ((t) => (t.CAT_ACCENT = "schemeAccent", t.CAT_DARK2 = "schemeDark2", t.CAT_CATEGORY10 = "schemeCategory10", t.CAT_OBSERVABLE10 = "schemeObservable10", t.CAT_PAIRED = "schemePaired", t.CAT_PASTEL1 = "schemePastel1", t.CAT_PASTEL2 = "schemePastel2", t.CAT_SET1 = "schemeSet1", t.CAT_SET2 = "schemeSet2", t.CAT_SET3 = "schemeSet3", t.CAT_TABLEAU10 = "schemeTableau10", t.SEQ_REDS = "interpolateReds", t.SEQ_BLUES = "interpolateBlues", t.SEQ_GREENS = "interpolateGreens", t.SEQ_GREYS = "interpolateGreys", t.SEQ_ORANGES = "interpolateOranges", t.SEQ_PURPLES = "interpolatePurples", t.SEQ_TURBO = "interpolateTurbo", t.SEQ_VIRIDIS = "interpolateViridis", t.SEQ_INFERNO = "interpolateInferno", t.SEQ_MAGMA = "interpolateMagma", t.SEQ_PLASMA = "interpolatePlasma", t.SEQ_CIVIDIS = "interpolateCividis", t.SEQ_WARM = "interpolateWarm", t.SEQ_COOL = "interpolateCool", t.SEQ_CUBEHELIX_DEFAULT = "interpolateCubehelixDefault", t.SEQ_BU_GN = "interpolateBuGn", t.SEQ_BU_PU = "interpolateBuPu", t.SEQ_GN_BU = "interpolateGnBu", t.SEQ_OR_RD = "interpolateOrRd", t.SEQ_PU_BU_GN = "interpolatePuBuGn", t.SEQ_PU_BU = "interpolatePuBu", t.SEQ_PU_RD = "interpolatePuRd", t.SEQ_RD_PU = "interpolateRdPu", t.SEQ_YL_GN_BU = "interpolateYlGnBu", t.SEQ_YL_GN = "interpolateYlGn", t.SEQ_YL_OR_BR = "interpolateYlOrBr", t.SEQ_YL_OR_RD = "interpolateYlOrRd", t.DIV_BR_BG = "interpolateBrBG", t.DIV_PR_GN = "interpolatePRGn", t.DIV_PI_YG = "interpolatePiYG", t.DIV_PU_OR = "interpolatePuOr", t.DIV_RED_BLUE = "interpolateRdBu", t.DIV_RED_GREY = "interpolateRdGy", t.DIV_RED_YELLOW_BLUE = "interpolateRdYlBu", t.DIV_RED_YELLOW_GREEN = "interpolateRdYlGn", t.DIV_SPECTRAL = "interpolateSpectral", t))(Nt || {}), ct = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(ct || {});
72
- async function N(t, e) {
73
- const r = e ?? lt;
71
+ var xt = /* @__PURE__ */ ((t) => (t.CAT_ACCENT = "schemeAccent", t.CAT_DARK2 = "schemeDark2", t.CAT_CATEGORY10 = "schemeCategory10", t.CAT_OBSERVABLE10 = "schemeObservable10", t.CAT_PAIRED = "schemePaired", t.CAT_PASTEL1 = "schemePastel1", t.CAT_PASTEL2 = "schemePastel2", t.CAT_SET1 = "schemeSet1", t.CAT_SET2 = "schemeSet2", t.CAT_SET3 = "schemeSet3", t.CAT_TABLEAU10 = "schemeTableau10", t.SEQ_REDS = "interpolateReds", t.SEQ_BLUES = "interpolateBlues", t.SEQ_GREENS = "interpolateGreens", t.SEQ_GREYS = "interpolateGreys", t.SEQ_ORANGES = "interpolateOranges", t.SEQ_PURPLES = "interpolatePurples", t.SEQ_TURBO = "interpolateTurbo", t.SEQ_VIRIDIS = "interpolateViridis", t.SEQ_INFERNO = "interpolateInferno", t.SEQ_MAGMA = "interpolateMagma", t.SEQ_PLASMA = "interpolatePlasma", t.SEQ_CIVIDIS = "interpolateCividis", t.SEQ_WARM = "interpolateWarm", t.SEQ_COOL = "interpolateCool", t.SEQ_CUBEHELIX_DEFAULT = "interpolateCubehelixDefault", t.SEQ_BU_GN = "interpolateBuGn", t.SEQ_BU_PU = "interpolateBuPu", t.SEQ_GN_BU = "interpolateGnBu", t.SEQ_OR_RD = "interpolateOrRd", t.SEQ_PU_BU_GN = "interpolatePuBuGn", t.SEQ_PU_BU = "interpolatePuBu", t.SEQ_PU_RD = "interpolatePuRd", t.SEQ_RD_PU = "interpolateRdPu", t.SEQ_YL_GN_BU = "interpolateYlGnBu", t.SEQ_YL_GN = "interpolateYlGn", t.SEQ_YL_OR_BR = "interpolateYlOrBr", t.SEQ_YL_OR_RD = "interpolateYlOrRd", t.DIV_BR_BG = "interpolateBrBG", t.DIV_PR_GN = "interpolatePRGn", t.DIV_PI_YG = "interpolatePiYG", t.DIV_PU_OR = "interpolatePuOr", t.DIV_RED_BLUE = "interpolateRdBu", t.DIV_RED_GREY = "interpolateRdGy", t.DIV_RED_YELLOW_BLUE = "interpolateRdYlBu", t.DIV_RED_YELLOW_GREEN = "interpolateRdYlGn", t.DIV_SPECTRAL = "interpolateSpectral", t))(xt || {}), pt = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(pt || {});
72
+ async function I(t, e) {
73
+ const r = e ?? j;
74
74
  t.getCurrentWorkspace() !== r && await t.setWorkspace(r);
75
75
  }
76
- function A(t, e) {
77
- return t === void 0 || t === lt ? e : `${t}/${e}`;
76
+ function b(t, e) {
77
+ return t === void 0 || t === j ? e : `${t}/${e}`;
78
78
  }
79
- function ft(t) {
79
+ function mt(t) {
80
80
  const e = /* @__PURE__ */ new Set();
81
81
  for (const o of t)
82
82
  o?.id != null && e.add(JSON.stringify(o.id));
83
83
  const r = /* @__PURE__ */ new Set();
84
84
  return t.map((o, n) => {
85
85
  if (o?.id != null) return o.id;
86
- let a = `autk-feature-${n}`;
87
- for (; e.has(JSON.stringify(a)) || r.has(JSON.stringify(a)); ) a = `${a}-generated`;
88
- return r.add(JSON.stringify(a)), a;
86
+ let s = `autk-feature-${n}`;
87
+ for (; e.has(JSON.stringify(s)) || r.has(JSON.stringify(s)); ) s = `${s}-generated`;
88
+ return r.add(JSON.stringify(s)), s;
89
89
  });
90
90
  }
91
- function pt(t) {
91
+ function ht(t) {
92
92
  const e = /* @__PURE__ */ new Map();
93
- return ft(t).map((r) => {
93
+ return mt(t).map((r) => {
94
94
  const o = JSON.stringify(r), n = e.get(o) ?? 0;
95
95
  return e.set(o, n + 1), n === 0 ? o : `${o} ${n}`;
96
96
  });
97
97
  }
98
- const Z = /* @__PURE__ */ new WeakMap();
99
- function Tt(t) {
100
- let e = Z.get(t);
98
+ const et = /* @__PURE__ */ new WeakMap();
99
+ function jt(t) {
100
+ let e = et.get(t);
101
101
  return e || (e = /* @__PURE__ */ new Map(), t.forEach((r, o) => {
102
102
  const n = e.get(r);
103
103
  n ? n.push(o) : e.set(r, [o]);
104
- }), Z.set(t, e), e);
104
+ }), et.set(t, e), e);
105
105
  }
106
106
  function x(t, e, r) {
107
- const o = Tt(r), n = /* @__PURE__ */ new Set();
108
- for (const a of t) {
109
- const s = e[a];
110
- if (s !== void 0)
111
- for (const i of o.get(s) ?? []) n.add(i);
107
+ const o = jt(r), n = /* @__PURE__ */ new Set();
108
+ for (const s of t) {
109
+ const a = e[s];
110
+ if (a !== void 0)
111
+ for (const i of o.get(a) ?? []) n.add(i);
112
112
  }
113
113
  return [...n];
114
114
  }
115
- const $t = { type: "GeometryCollection", geometries: [] };
116
- function Ot(t) {
117
- const e = t.features ?? [], r = ft(e);
115
+ const Gt = { type: "GeometryCollection", geometries: [] };
116
+ function Dt(t) {
117
+ const e = t.features ?? [], r = mt(e);
118
118
  let o = !1;
119
- const n = e.map((s, i) => s == null || s.id != null && s.geometry != null ? s : (o = !0, { ...s, id: r[i], geometry: s.geometry ?? $t })), a = e.findIndex((s) => s?.geometry != null);
120
- return a > 0 && e[0] != null && e[0].geometry == null && ([n[0], n[a]] = [n[a], n[0]], o = !0), o ? { ...t, features: n } : t;
119
+ const n = e.map((a, i) => a == null || a.id != null && a.geometry != null ? a : (o = !0, { ...a, id: r[i], geometry: a.geometry ?? Gt })), s = e.findIndex((a) => a?.geometry != null);
120
+ return s > 0 && e[0] != null && e[0].geometry == null && ([n[0], n[s]] = [n[s], n[0]], o = !0), o ? { ...t, features: n } : t;
121
121
  }
122
- function Ft(t) {
122
+ function Ut(t) {
123
123
  const { queryArea: e } = t;
124
124
  if (e.bbox === void 0) return { geocodeArea: e.geocodeArea, areas: e.areas };
125
125
  const r = (l) => new Error(`OSM source "${t.outputTableName}": ${l}`);
@@ -128,100 +128,155 @@ function Ft(t) {
128
128
  const o = e.bbox;
129
129
  if (!Array.isArray(o) || o.length !== 4 || !o.every((l) => typeof l == "number" && Number.isFinite(l)))
130
130
  throw r("queryArea.bbox must hold four numbers, [west, south, east, north] in degrees.");
131
- const [n, a, s, i] = e.bbox;
132
- if (Math.abs(n) > 180 || Math.abs(s) > 180)
131
+ const [n, s, a, i] = e.bbox;
132
+ if (Math.abs(n) > 180 || Math.abs(a) > 180)
133
133
  throw r("queryArea.bbox west and east must be longitudes from -180 to 180.");
134
- if (Math.abs(a) > 90 || Math.abs(i) > 90)
134
+ if (Math.abs(s) > 90 || Math.abs(i) > 90)
135
135
  throw r("queryArea.bbox south and north must be latitudes from -90 to 90.");
136
- if (n >= s)
137
- throw r(`queryArea.bbox west (${n}) must be less than east (${s}); a box across the antimeridian is not supported.`);
138
- if (a >= i)
139
- throw r(`queryArea.bbox south (${a}) must be less than north (${i}).`);
140
- return { bbox: [n, a, s, i] };
136
+ if (n >= a)
137
+ throw r(`queryArea.bbox west (${n}) must be less than east (${a}); a box across the antimeridian is not supported.`);
138
+ if (s >= i)
139
+ throw r(`queryArea.bbox south (${s}) must be less than north (${i}).`);
140
+ return { bbox: [n, s, a, i] };
141
141
  }
142
- function Bt(t) {
142
+ function Qt(t) {
143
143
  const { autoLoadLayers: e, ...r } = t;
144
- return { ...r, queryArea: Ft(t), autoLoadLayers: { layers: e?.layers ?? [] } };
144
+ if (t.pbfFileUrl !== void 0 && (t.tagSets?.length ?? 0) > 0)
145
+ throw new Error(`OSM source "${t.outputTableName}": tagSets are read from the Overpass API only, so a source with pbfFileUrl cannot take them.`);
146
+ return {
147
+ ...r,
148
+ queryArea: Ut(t),
149
+ autoLoadLayers: {
150
+ layers: e?.layers ?? [],
151
+ ...e?.coordinateFormat !== void 0 && { coordinateFormat: e.coordinateFormat }
152
+ }
153
+ };
145
154
  }
146
- function tt(t) {
155
+ function rt(t) {
147
156
  return `${t ? `coordinateFormat is set to "${t}"` : "no coordinateFormat was specified, so it defaults to EPSG:4326 (WGS84 per RFC 7946)"}. Verify that coordinateFormat matches the actual CRS of the input data.`;
148
157
  }
149
- function dt(t) {
158
+ function D(t) {
159
+ return t === void 0 || t === j ? "the default workspace" : `the workspace "${t}"`;
160
+ }
161
+ function ot(t) {
162
+ if (t != null)
163
+ return typeof t == "string" ? t : JSON.stringify(t);
164
+ }
165
+ async function Yt(t, e, r, o) {
166
+ const n = /* @__PURE__ */ new Map();
167
+ for (const i of (await t.getLayer(e.name)).features) {
168
+ const l = ot(i.properties?.[o]);
169
+ if (l !== void 0) {
170
+ if (i.id === void 0 || i.id === null)
171
+ throw new Error("its rows have no feature id to update them by.");
172
+ n.set(l, [...n.get(l) ?? [], i.id]);
173
+ }
174
+ }
175
+ const s = r.features.flatMap((i) => {
176
+ const l = ot(i.properties?.[o]);
177
+ return l === void 0 ? [] : (n.get(l) ?? []).map((u) => ({ ...i, id: u }));
178
+ }), a = e.columns.some((i) => i.name === "geojson_id") ? "geojson_id" : "id";
179
+ return { data: { ...r, features: s }, idColumn: a };
180
+ }
181
+ async function nt(t) {
182
+ if (t) return t;
183
+ const e = new Tt();
184
+ return await e.init(), e;
185
+ }
186
+ function yt(t) {
150
187
  let e = 1 / 0, r = 1 / 0, o = -1 / 0, n = -1 / 0;
151
- const a = (i) => {
188
+ const s = (i) => {
152
189
  if (Array.isArray(i)) {
153
190
  if (typeof i[0] == "number") {
154
191
  const [l, u] = i;
155
192
  l < e && (e = l), l > o && (o = l), u < r && (r = u), u > n && (n = u);
156
193
  return;
157
194
  }
158
- for (const l of i) a(l);
195
+ for (const l of i) s(l);
159
196
  }
160
- }, s = (i) => {
161
- i && (i.type === "GeometryCollection" ? i.geometries.forEach(s) : a(i.coordinates));
197
+ }, a = (i) => {
198
+ i && (i.type === "GeometryCollection" ? i.geometries.forEach(a) : s(i.coordinates));
162
199
  };
163
- for (const i of t.features ?? []) s(i?.geometry);
200
+ for (const i of t.features ?? []) a(i?.geometry);
164
201
  return e <= o ? [e, r, o, n] : void 0;
165
202
  }
166
- function xt(t, e) {
167
- function r(o, n) {
168
- if (!n || !n.db)
203
+ function Vt(t, e) {
204
+ function r(n, s) {
205
+ if (!s || !s.db)
169
206
  return;
170
- const a = document.getElementById(n.db);
207
+ const a = document.getElementById(s.db);
171
208
  if (a) {
172
- const s = o.getTablesMetadata();
209
+ const i = n.getTablesMetadata();
173
210
  a.innerHTML += "<ul>";
174
- for (const i of s)
175
- a.innerHTML += `<li>${i.name}: (${i.source}, ${i.type}) </li>`;
176
- a.innerHTML += "</ul>", a.innerHTML += `<p>Number of tables: ${s.length}</p>`;
211
+ for (const l of i)
212
+ a.innerHTML += `<li>${l.name}: (${l.source}, ${l.type}) </li>`;
213
+ a.innerHTML += "</ul>", a.innerHTML += `<p>Number of tables: ${i.length}</p>`;
177
214
  }
178
215
  }
216
+ async function o(n, s, a) {
217
+ if (!e) return;
218
+ const i = b(s, a), l = n.getTablesMetadata().find((u) => u.name === a);
219
+ l && dt(l) ? e.set(i, await n.getLayer(a)) : e.delete(i);
220
+ }
179
221
  return {
180
- async resolveSource(o, n) {
181
- let a = o;
182
- a || (a = new St(), await a.init());
183
- const { workspace: s } = n;
184
- await N(a, s);
185
- let { type: i, workspace: l, ...u } = n;
186
- switch (i) {
222
+ async resolveWorkspaces(n, s) {
223
+ const a = await nt(n), i = /* @__PURE__ */ new Set();
224
+ for (const { name: l, coordinateFormat: u, precisionGrid: d } of s) {
225
+ const c = l ?? j;
226
+ if (i.has(c))
227
+ throw new Error(`workspaces sets ${D(l)} twice; give each workspace one entry.`);
228
+ i.add(c);
229
+ try {
230
+ await a.setWorkspace(c, { coordinateFormat: u, precisionGrid: d });
231
+ } catch (f) {
232
+ throw new Error(`workspaces, ${D(l)}: ${f instanceof Error ? f.message : String(f)}`);
233
+ }
234
+ }
235
+ return await I(a), a;
236
+ },
237
+ async resolveSource(n, s) {
238
+ const a = await nt(n), { workspace: i } = s;
239
+ await I(a, i);
240
+ let { type: l, workspace: u, ...d } = s;
241
+ switch (l) {
187
242
  case "osm":
188
- return await a.loadOsm(Bt(u)), r(a, t), a;
243
+ return await a.loadOsm(Qt(d)), r(a, t), a;
189
244
  case "csv":
190
- return await a.loadCsv(u), r(a, t), a;
245
+ return await a.loadCsv(d), r(a, t), a;
191
246
  case "json":
192
- return await a.loadJson(u), r(a, t), a;
247
+ return await a.loadJson(d), r(a, t), a;
193
248
  case "geojson": {
194
- const c = u;
249
+ const c = d;
195
250
  let f;
196
- c.geojsonFileUrl ? f = await (await fetch(c.geojsonFileUrl)).json() : f = c.geojsonObject, e && f && e.set(A(s, c.outputTableName), f);
197
- const p = f ? (() => {
198
- const m = { ...c, geojsonObject: Ot(f) };
199
- return delete m.geojsonFileUrl, m;
200
- })() : c, y = /^EPSG:4326$/i.test(p.coordinateFormat ?? "EPSG:4326"), d = f && y ? dt(f) : void 0;
201
- if (d && (d[1] < -90 || d[3] > 90))
251
+ c.geojsonFileUrl ? f = await (await fetch(c.geojsonFileUrl)).json() : f = c.geojsonObject, e && f && e.set(b(i, c.outputTableName), f);
252
+ const y = f ? (() => {
253
+ const p = { ...c, geojsonObject: Dt(f) };
254
+ return delete p.geojsonFileUrl, p;
255
+ })() : c, m = /^EPSG:4326$/i.test(y.coordinateFormat ?? "EPSG:4326"), h = f && m ? yt(f) : void 0;
256
+ if (h && (h[1] < -90 || h[3] > 90))
202
257
  throw new Error(
203
- `GeoJSON layer "${p.outputTableName}" has y coordinates outside -90 to 90 (bbox: [${d.join(", ")}]), so they cannot be EPSG:4326 degrees. ${tt(p.coordinateFormat)}`
258
+ `GeoJSON layer "${y.outputTableName}" has y coordinates outside -90 to 90 (bbox: [${h.join(", ")}]), so they cannot be EPSG:4326 degrees. ${rt(y.coordinateFormat)}`
204
259
  );
205
260
  try {
206
- await a.loadGeojson(p);
207
- } catch (m) {
208
- throw new Error(`Failed to load GeoJSON layer "${p.outputTableName}": ${m instanceof Error ? m.message : String(m)}`);
261
+ await a.loadGeojson(y);
262
+ } catch (p) {
263
+ throw new Error(`Failed to load GeoJSON layer "${y.outputTableName}": ${p instanceof Error ? p.message : String(p)}`);
209
264
  }
210
265
  try {
211
- const m = await a.getBoundingBoxFromLayer(p.outputTableName), h = 25e6;
212
- if (!isFinite(m.minLon) || !isFinite(m.minLat) || !isFinite(m.maxLon) || !isFinite(m.maxLat) || Math.abs(m.minLon) > h || Math.abs(m.maxLon) > h || Math.abs(m.minLat) > h || Math.abs(m.maxLat) > h)
266
+ const p = await a.getBoundingBoxFromLayer(y.outputTableName), w = 25e6;
267
+ if (!isFinite(p.minLon) || !isFinite(p.minLat) || !isFinite(p.maxLon) || !isFinite(p.maxLat) || Math.abs(p.minLon) > w || Math.abs(p.maxLon) > w || Math.abs(p.minLat) > w || Math.abs(p.maxLat) > w)
213
268
  throw new Error(
214
- `Geometry bounding box after transform is invalid for layer "${p.outputTableName}" (bbox: [${m.minLon}, ${m.minLat}, ${m.maxLon}, ${m.maxLat}]). ${tt(p.coordinateFormat)} The workspace uses ${ut}; input is expected in EPSG:4326 by default.`
269
+ `Geometry bounding box after transform is invalid for layer "${y.outputTableName}" (bbox: [${p.minLon}, ${p.minLat}, ${p.maxLon}, ${p.maxLat}]). ${rt(y.coordinateFormat)} The workspace uses ${a.getWorkspaceConfiguration().coordinateFormat}; input is expected in EPSG:4326 by default.`
215
270
  );
216
- } catch (m) {
217
- if (m instanceof Error && m.message.includes("bounding box after transform")) throw m;
271
+ } catch (p) {
272
+ if (p instanceof Error && p.message.includes("bounding box after transform")) throw p;
218
273
  }
219
274
  return r(a, t), a;
220
275
  }
221
276
  case "geotiff":
222
- return await a.loadGeoTiff(u), r(a, t), a;
277
+ return await a.loadGeoTiff(d), r(a, t), a;
223
278
  case "heatmap": {
224
- const c = u;
279
+ const c = d;
225
280
  if (c.groupBy?.some((f) => f.aggregateFn === "collect"))
226
281
  throw new Error(`Heatmap "${c.outputTableName}": aggregateFn "collect" lists the rows near a cell, and a cell holds one value; use sum, avg, count, min, max or weighted.`);
227
282
  return await a.buildHeatmap({
@@ -233,7 +288,7 @@ function xt(t, e) {
233
288
  }), r(a, t), a;
234
289
  }
235
290
  case "join": {
236
- const c = u;
291
+ const c = d;
237
292
  if (await a.spatialQuery({
238
293
  tableRootName: c.dataRef,
239
294
  tableJoinName: c.joinDataRef,
@@ -241,246 +296,306 @@ function xt(t, e) {
241
296
  ...c.groupBy && { groupBy: c.groupBy }
242
297
  }), e) {
243
298
  const f = await a.getLayer(c.dataRef);
244
- e.set(A(s, c.dataRef), f);
299
+ e.set(b(i, c.dataRef), f);
245
300
  }
246
301
  return r(a, t), a;
247
302
  }
303
+ case "sql": {
304
+ const c = d;
305
+ try {
306
+ await a.rawQuery({
307
+ query: c.query,
308
+ output: {
309
+ type: "CREATE_TABLE",
310
+ tableName: c.outputTableName,
311
+ source: "user",
312
+ ...c.layerType !== void 0 && { tableType: c.layerType }
313
+ }
314
+ });
315
+ } catch (f) {
316
+ throw new Error(`SQL source "${c.outputTableName}": ${f instanceof Error ? f.message : String(f)}`);
317
+ }
318
+ return e?.delete(b(i, c.outputTableName)), r(a, t), a;
319
+ }
320
+ case "update": {
321
+ const c = d, f = (h) => new Error(`Update of "${c.dataRef}": ${h}`);
322
+ if (c.geojsonObject === void 0 == (c.jsonObject === void 0))
323
+ throw f("give its rows in geojsonObject or in jsonObject, one of the two.");
324
+ if (c.strategy === "update" && !c.idColumn)
325
+ throw f("the update strategy needs an idColumn, the column that matches a given row to the table's rows.");
326
+ let y = c.geojsonObject ?? c.jsonObject, m = c.idColumn;
327
+ try {
328
+ const h = a.getTablesMetadata().find((p) => p.name === c.dataRef);
329
+ if (c.strategy === "update" && c.geojsonObject && m?.startsWith("properties.") && h && Nt(h) && ({ data: y, idColumn: m } = await Yt(a, h, c.geojsonObject, m.slice(11)), y.features.length === 0))
330
+ return r(a, t), a;
331
+ await a.updateTable({
332
+ tableName: c.dataRef,
333
+ data: y,
334
+ strategy: c.strategy,
335
+ ...m !== void 0 && { idColumn: m }
336
+ });
337
+ } catch (h) {
338
+ throw f(h instanceof Error ? h.message : String(h));
339
+ }
340
+ return await o(a, i, c.dataRef), r(a, t), a;
341
+ }
342
+ case "drop": {
343
+ const c = d;
344
+ if (!a.getTablesMetadata().some((f) => f.name === c.dataRef))
345
+ throw new Error(`Drop of "${c.dataRef}": ${D(i)} holds no table of that name.`);
346
+ return await a.removeLayer(c.dataRef), e?.delete(b(i, c.dataRef)), r(a, t), a;
347
+ }
248
348
  default:
249
- return;
349
+ throw new Error(`Unknown data source type "${String(l)}".`);
250
350
  }
251
351
  }
252
352
  };
253
353
  }
254
- function mt(t, e, r) {
354
+ function wt(t, e) {
355
+ return e === !0 ? `${t} osm-elements` : t;
356
+ }
357
+ function gt(t) {
358
+ return t === !0 ? { osmElements: !0 } : void 0;
359
+ }
360
+ function bt(t, e, r) {
255
361
  if (!t) return r();
256
362
  let o = t.get(e);
257
363
  return o || (o = r(), t.set(e, o)), o;
258
364
  }
259
- function ht(t, e) {
365
+ function _t(t, e) {
260
366
  return t?.id ?? e;
261
367
  }
262
- function G(t, e) {
368
+ function U(t, e) {
263
369
  return e === void 0 ? !0 : typeof e == "number" ? t.mapIndex === e : t.mapId === e;
264
370
  }
265
- function yt(t, e, r) {
371
+ function Et(t, e, r) {
266
372
  const o = t?.get(e) ?? [];
267
373
  o.includes(r) || t?.set(e, [...o, r]);
268
374
  }
269
- const gt = 6378137, j = 0.0818191908426215;
270
- function kt(t, e) {
375
+ const Mt = 6378137, Y = 0.0818191908426215;
376
+ function Wt(t, e) {
271
377
  if (t === void 0 || typeof t == "number" && Number.isFinite(t) && t > 0) return;
272
378
  const r = typeof t == "number" ? String(t) : JSON.stringify(t);
273
379
  throw new Error(`Layer "${e}": pointSize must be a number of meters greater than 0, not ${r}.`);
274
380
  }
275
- function Gt(t) {
276
- const e = Math.exp(-t / gt);
381
+ function Ht(t) {
382
+ const e = Math.exp(-t / Mt);
277
383
  let r = Math.PI / 2 - 2 * Math.atan(e);
278
384
  for (let o = 0; o < 10; o++) {
279
- const n = j * Math.sin(r), a = Math.PI / 2 - 2 * Math.atan(e * ((1 - n) / (1 + n)) ** (j / 2));
280
- if (Math.abs(a - r) < 1e-12) return a;
281
- r = a;
385
+ const n = Y * Math.sin(r), s = Math.PI / 2 - 2 * Math.atan(e * ((1 - n) / (1 + n)) ** (Y / 2));
386
+ if (Math.abs(s - r) < 1e-12) return s;
387
+ r = s;
282
388
  }
283
389
  return r;
284
390
  }
285
- function Dt(t, e) {
391
+ function qt(t, e) {
286
392
  if (/^EPSG:3395$/i.test(t)) {
287
- const r = Gt(e), o = j * Math.sin(r);
393
+ const r = Ht(e), o = Y * Math.sin(r);
288
394
  return Math.sqrt(1 - o * o) / Math.cos(r);
289
395
  }
290
- return /^EPSG:3857$/i.test(t) ? Math.cosh(e / gt) : 1;
396
+ return /^EPSG:3857$/i.test(t) ? Math.cosh(e / Mt) : 1;
291
397
  }
292
- function jt(t, e, r, o) {
398
+ function Jt(t, e, r, o) {
293
399
  if (t === void 0 || e !== "points") return;
294
400
  const n = o();
295
401
  if (n)
296
- return t * Dt(r, (n[1] + n[3]) / 2);
402
+ return t * qt(r, (n[1] + n[3]) / 2);
297
403
  }
298
- function S(t) {
404
+ function R(t) {
299
405
  return typeof t.title == "string" && t.title !== "" ? t.title : t.dataRef;
300
406
  }
301
- function Ut(t, e) {
407
+ function Kt(t, e) {
302
408
  const r = /* @__PURE__ */ new Set();
303
409
  for (const o of t.layerRefs) {
304
- const n = S(o);
410
+ const n = R(o);
305
411
  if (r.has(n))
306
412
  throw new Error(`Map ${e} draws two layers with the id "${n}". A layer's id is its title, else its dataRef: give each layer of a map its own title.`);
307
413
  r.add(n);
308
414
  }
309
415
  }
310
- const Qt = /^#[0-9a-fA-F]{6}$/;
311
- function et(t, e, r) {
312
- if (!Qt.test(t))
416
+ const Xt = /^#[0-9a-fA-F]{6}$/;
417
+ function at(t, e, r) {
418
+ if (!Xt.test(t))
313
419
  throw new Error(`Layer "${r}": ${e} must be a color written #rrggbb, not "${t}".`);
314
420
  return B.hexToRgb(t);
315
421
  }
316
- function Yt(t, e) {
422
+ function zt(t, e) {
317
423
  const r = {};
318
- return t.color != null && (r.color = et(t.color, "color", e)), t.stroke === !1 ? r.showBorders = !1 : t.stroke != null && (r.strokeColor = et(t.stroke, "stroke", e)), t.width != null && (r.polylinesWidth = t.width), r;
424
+ return t.color != null && (r.color = at(t.color, "color", e)), t.stroke === !1 ? r.showBorders = !1 : t.stroke != null && (r.strokeColor = at(t.stroke, "stroke", e)), t.width != null && (r.polylinesWidth = t.width), r;
319
425
  }
320
- function Vt(t, e) {
426
+ function Zt(t, e) {
321
427
  return t.isColorMap != null ? t.isColorMap : e === "raster" ? t.colorMapInterpolator != null || t.colorMapRange != null || t.colorMapCenter != null || t.colorMapReverse === !0 : t.color != null ? !1 : t.colorMapInterpolator != null || t.getFnv != null;
322
428
  }
323
- function Ht(t, e) {
429
+ function te(t, e) {
324
430
  const r = t.features?.[0]?.properties?.[e];
325
431
  return r instanceof Float32Array ? r : ArrayBuffer.isView(r) && !(r instanceof DataView) || Array.isArray(r) ? Float32Array.from(r, (o) => Number.isFinite(Number(o)) ? Number(o) : NaN) : null;
326
432
  }
327
- function Wt(t, e, r, o, n) {
433
+ function ee(t, e, r, o, n) {
328
434
  if (B.isCategorical(e.interpolator)) return;
329
435
  if (n != null) {
330
436
  const u = r != null ? [n[0], r, n[1]] : [n[0], n[1]];
331
437
  return o === !0 ? u.reverse() : u;
332
438
  }
333
439
  if (!t) return;
334
- let a = 0, s = 0;
440
+ let s = 0, a = 0;
335
441
  for (let u = 0; u < t.length; u++) {
336
- const c = t[u];
337
- Number.isFinite(c) && (s++, r != null && (a = Math.max(a, Math.abs(c - r))));
442
+ const d = t[u];
443
+ Number.isFinite(d) && (a++, r != null && (s = Math.max(s, Math.abs(d - r))));
338
444
  }
339
- const i = r != null && a > 0;
340
- if (s === 0 || !i && o !== !0) return;
341
- const l = i && r != null ? [r - a, r, r + a] : B.resolveDomainFromData(t, e);
445
+ const i = r != null && s > 0;
446
+ if (a === 0 || !i && o !== !0) return;
447
+ const l = i && r != null ? [r - s, r, r + s] : B.resolveDomainFromData(t, e);
342
448
  return o === !0 ? [...l].reverse() : l;
343
449
  }
344
- function Jt(t, e) {
450
+ function re(t, e) {
345
451
  if (!(e == null || B.isCategorical(t.interpolator)))
346
452
  return [e[0], e[1]];
347
453
  }
348
- function qt(t) {
454
+ function oe(t) {
349
455
  const e = t.colorMapRange;
350
456
  if (e === void 0) return;
351
- const r = (s) => new Error(`Layer "${S(t)}": ${s}`);
352
- if (!Array.isArray(e) || e.length !== 2 || !e.every((s) => typeof s == "number" && Number.isFinite(s)))
457
+ const r = (a) => new Error(`Layer "${R(t)}": ${a}`);
458
+ if (!Array.isArray(e) || e.length !== 2 || !e.every((a) => typeof a == "number" && Number.isFinite(a)))
353
459
  throw r("colorMapRange must hold two numbers, [low, high].");
354
460
  const [o, n] = e;
355
461
  if (o >= n)
356
462
  throw r(`colorMapRange low (${o}) must be less than high (${n}).`);
357
463
  if (t.colorMapDomain !== void 0)
358
464
  throw r("set colorMapRange or colorMapDomain, not both.");
359
- const a = t.colorMapCenter;
360
- if (a != null && (a < o || a > n))
361
- throw r(`colorMapCenter (${a}) must lie within colorMapRange [${o}, ${n}].`);
465
+ const s = t.colorMapCenter;
466
+ if (s != null && (s < o || s > n))
467
+ throw r(`colorMapCenter (${s}) must lie within colorMapRange [${o}, ${n}].`);
362
468
  }
363
- function Kt(t, e) {
364
- return e && e.length > 0 ? { type: I.USER, params: e } : t?.mode === ct.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
365
- type: I.PERCENTILE,
469
+ function ne(t, e) {
470
+ return e && e.length > 0 ? { type: P.USER, params: e } : t?.mode === pt.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
471
+ type: P.PERCENTILE,
366
472
  params: [t.lowerPercentile ?? 0, t.upperPercentile ?? 100]
367
- } : { type: I.PERCENTILE } : { type: I.MIN_MAX };
473
+ } : { type: P.PERCENTILE } : { type: P.MIN_MAX };
368
474
  }
369
- function Xt(t, e) {
475
+ function ae(t, e) {
370
476
  return e.split(".").reduce((r, o) => {
371
477
  if (!(r == null || typeof r != "object"))
372
478
  return r[o];
373
479
  }, t);
374
480
  }
375
- function zt(t, e, r) {
481
+ function ie(t, e, r) {
376
482
  const o = e.split("."), n = { ...t };
377
- let a = n;
378
- for (let s = 0; s < o.length - 1; s++)
379
- a[o[s]] = { ...a[o[s]] ?? {} }, a = a[o[s]];
380
- return a[o[o.length - 1]] = r, n;
483
+ let s = n;
484
+ for (let a = 0; a < o.length - 1; a++)
485
+ s[o[a]] = { ...s[o[a]] ?? {} }, s = s[o[a]];
486
+ return s[o[o.length - 1]] = r, n;
381
487
  }
382
- function Zt(t, e) {
488
+ function se(t, e) {
383
489
  const o = t.features?.[0]?.properties?.bands ?? [];
384
- return o.find((a) => a.id === e || a.label === e?.replace(/\./g, "_"))?.id ?? o[0]?.id ?? e ?? "";
490
+ return o.find((s) => s.id === e || s.label === e?.replace(/\./g, "_"))?.id ?? o[0]?.id ?? e ?? "";
385
491
  }
386
- function te(t, e) {
492
+ function At(t) {
493
+ const { pitch: e } = t;
494
+ return e === void 0 || typeof e == "number" && e >= 0 && e < 90 ? void 0 : `camera.pitch must be at least 0 and less than 90 degrees, not ${typeof e == "number" ? String(e) : JSON.stringify(e)}: at 90 the eye would sit on the ground, edge-on to the map's flat layers, and the map could not pan.`;
495
+ }
496
+ function le(t, e) {
497
+ const r = At(e);
498
+ if (r) throw new Error(r);
387
499
  if (e.zoom === void 0 && !e.pitch && !e.bearing) return;
388
- const r = t.camera, [o, n] = r.getLookAt(), a = e.zoom !== void 0 ? 1e4 / Math.pow(2, e.zoom - 10) : Math.abs(r.getEye()[2]), s = (e.pitch ?? 0) * Math.PI / 180, i = (e.bearing ?? 0) * Math.PI / 180, l = [
389
- o - a * Math.sin(s) * Math.sin(i),
390
- n - a * Math.sin(s) * Math.cos(i),
391
- a * Math.cos(s)
392
- ];
393
- r.resetCamera([Math.sin(i), Math.cos(i), 0], [o, n, 0], l);
394
- }
395
- function ee(t, e, r, o) {
396
- const a = t.layerManager.searchByLayerId(e)?.components;
397
- return Array.isArray(a) ? a.map((s, i) => {
398
- const l = Number.isInteger(s?.featureIndex) ? s.featureIndex : i;
500
+ const o = t.camera, [n, s] = o.getLookAt(), a = e.zoom !== void 0 ? 1e4 / Math.pow(2, e.zoom - 10) : Math.abs(o.getEye()[2]), i = (e.pitch ?? 0) * Math.PI / 180, l = (e.bearing ?? 0) * Math.PI / 180, u = [
501
+ n - a * Math.sin(i) * Math.sin(l),
502
+ s - a * Math.sin(i) * Math.cos(l),
503
+ a * Math.cos(i)
504
+ ], d = [Math.cos(i) * Math.sin(l), Math.cos(i) * Math.cos(l), Math.sin(i)];
505
+ o.resetCamera(d, [n, s, 0], u);
506
+ }
507
+ function ue(t, e, r, o) {
508
+ const s = t.layerManager.searchByLayerId(e)?.components;
509
+ return Array.isArray(s) ? s.map((a, i) => {
510
+ const l = Number.isInteger(a?.featureIndex) ? a.featureIndex : i;
399
511
  return r[o[l]] ?? "";
400
- }) : o.map((s) => r[s] ?? "");
401
- }
402
- function re(t, e, r, o, n, a) {
403
- async function s(i, l, u) {
404
- let c = {};
405
- for (const p of l.getTablesMetadata())
406
- p.type !== void 0 && (c[p.name] = p.type);
407
- const f = [];
408
- for (const p of u.layerRefs) {
409
- const y = p.dataRef, d = S(p), m = A(u.workspace, y), h = n?.get(m) ?? c[y], g = p.getFnv, _ = r?.get(m) ?? (h === "raster" ? await l.getRaster(y) : await mt(a, m, () => l.getLayer(y))), b = _.features ?? [], U = h === "raster" ? [] : b.flatMap((w, E) => w?.geometry != null ? [E] : []), M = h === "raster" ? _ : { ..._, features: U.map((w) => b[w]) }, Q = h === "raster" ? Zt(M, g) : "";
410
- h === "raster" ? i.loadCollection(d, { collection: M, type: "raster", property: Q }) : i.loadCollection(d, { collection: M, type: h }), p.opacity != null && i.updateRenderInfo(d, { opacity: p.opacity });
411
- const Y = Yt(p, d);
412
- Object.keys(Y).length > 0 && i.updateRenderInfo(d, Y);
413
- const Rt = l.getWorkspaceConfiguration().coordinateFormat, V = jt(p.pointSize, h, Rt, () => dt(M));
414
- V !== void 0 && i.updateRenderInfo(d, { pointSize: V }), Vt(p, h) && i.updateRenderInfo(d, { isColorMap: !0 }), p.isPick && i.updateRenderInfo(d, { isPick: !0 }), p.isSkip && i.updateRenderInfo(d, { isSkip: !0 });
415
- const { catchAllCategory: T, colorMapDomain: C } = p;
416
- let H = M, W = C;
417
- if (g && T && C?.length) {
418
- const w = new Set(C);
419
- H = {
420
- ...M,
421
- features: M.features.map((E) => {
422
- const K = E.properties, k = Xt(K, g);
423
- return k == null || !w.has(String(k)) ? { ...E, properties: zt(K, g, T) } : E;
512
+ }) : o.map((a) => r[a] ?? "");
513
+ }
514
+ function ce(t, e, r, o, n, s) {
515
+ async function a(i, l, u) {
516
+ let d = {};
517
+ for (const f of l.getTablesMetadata())
518
+ f.type !== void 0 && (d[f.name] = f.type);
519
+ const c = [];
520
+ for (const f of u.layerRefs) {
521
+ const y = f.dataRef, m = R(f), h = b(u.workspace, y), p = n?.get(h) ?? d[y], w = f.getFnv, _ = r?.get(h) ?? (p === "raster" ? await l.getRaster(y) : await bt(s, wt(h, f.osmElements), () => l.getLayer(y, gt(f.osmElements)))), E = _.features ?? [], S = p === "raster" ? [] : E.flatMap((g, M) => g?.geometry != null ? [M] : []), A = p === "raster" ? _ : { ..._, features: S.map((g) => E[g]) }, V = p === "raster" ? se(A, w) : "";
522
+ p === "raster" ? i.loadCollection(m, { collection: A, type: "raster", property: V }) : i.loadCollection(m, { collection: A, type: p }), f.opacity != null && i.updateRenderInfo(m, { opacity: f.opacity });
523
+ const W = zt(f, m);
524
+ Object.keys(W).length > 0 && i.updateRenderInfo(m, W);
525
+ const Pt = l.getWorkspaceConfiguration().coordinateFormat, H = Jt(f.pointSize, p, Pt, () => yt(A));
526
+ H !== void 0 && i.updateRenderInfo(m, { pointSize: H }), Zt(f, p) && i.updateRenderInfo(m, { isColorMap: !0 }), f.isPick && i.updateRenderInfo(m, { isPick: !0 }), f.isSkip && i.updateRenderInfo(m, { isSkip: !0 });
527
+ const { catchAllCategory: $, colorMapDomain: L } = f;
528
+ let q = A, J = L;
529
+ if (w && $ && L?.length) {
530
+ const g = new Set(L);
531
+ q = {
532
+ ...A,
533
+ features: A.features.map((M) => {
534
+ const z = M.properties, G = ae(z, w);
535
+ return G == null || !g.has(String(G)) ? { ...M, properties: ie(z, w, $) } : M;
424
536
  })
425
- }, W = w.has(T) ? C : [...C, T];
537
+ }, J = g.has($) ? L : [...L, $];
426
538
  }
427
- const J = h === "raster" && p.transferFunction != null;
428
- J && i.layerManager.searchByLayerId(d)?.setTransferFunction?.(p.transferFunction);
429
- const $ = p.colorMapRange, q = h === "raster" && ($ != null || p.colorMapCenter != null || p.colorMapReverse === !0);
430
- if (p.colorMapInterpolator || q || $) {
431
- const w = {
539
+ const K = p === "raster" && f.transferFunction != null;
540
+ K && i.layerManager.searchByLayerId(m)?.setTransferFunction?.(f.transferFunction);
541
+ const O = f.colorMapRange, X = p === "raster" && (O != null || f.colorMapCenter != null || f.colorMapReverse === !0);
542
+ if (f.colorMapInterpolator || X || O) {
543
+ const g = {
432
544
  // urban-grammar ColorMapInterpolator values are string-compatible
433
545
  // with autk-core ColorMapInterpolator at runtime
434
- interpolator: p.colorMapInterpolator ?? i.layerManager.searchByLayerId(d)?.layerRenderInfo.colormap.config.interpolator ?? Lt.SEQ_REDS,
435
- domainSpec: Kt(p.normalization, W)
546
+ interpolator: f.colorMapInterpolator ?? i.layerManager.searchByLayerId(m)?.layerRenderInfo.colormap.config.interpolator ?? Ft.SEQ_REDS,
547
+ domainSpec: ne(f.normalization, J)
436
548
  };
437
- let E;
438
- q ? E = Wt(Ht(M, Q), w, p.colorMapCenter, p.colorMapReverse, $) : h !== "raster" && (E = Jt(w, $)), E && (w.domainSpec = { type: I.USER, params: E }), i.updateColorMap(d, { colorMap: w });
439
- } else J && i.updateColorMap(d, { colorMap: {} });
440
- if (g && h !== "raster") {
441
- const w = g.startsWith("properties.") ? g : `properties.${g}`;
442
- i.updateThematic(d, { collection: H, property: w });
549
+ let M;
550
+ X ? M = ee(te(A, V), g, f.colorMapCenter, f.colorMapReverse, O) : p !== "raster" && (M = re(g, O)), M && (g.domainSpec = { type: P.USER, params: M }), i.updateColorMap(m, { colorMap: g });
551
+ } else K && i.updateColorMap(m, { colorMap: {} });
552
+ if (w && p !== "raster") {
553
+ const g = w.startsWith("properties.") ? w : `properties.${w}`;
554
+ i.updateThematic(m, { collection: q, property: g });
443
555
  }
444
- f.push(h === "raster" ? [] : ee(i, d, pt(b), U));
556
+ c.push(p === "raster" ? [] : ue(i, m, ht(E), S));
445
557
  }
446
- return f;
558
+ return c;
447
559
  }
448
560
  return {
449
561
  async resolveMap(i, l, u = 0) {
450
562
  if (t && t.map && i) {
451
- Ut(l, u);
452
- for (const d of l.layerRefs)
453
- qt(d), kt(d.pointSize, S(d));
563
+ Kt(l, u);
564
+ for (const h of l.layerRefs)
565
+ oe(h), Wt(h.pointSize, R(h));
566
+ const d = l.camera && At(l.camera);
567
+ if (d)
568
+ throw new Error(`Map ${u}: ${d}`);
454
569
  let c;
455
570
  if (Array.isArray(t.map) ? c = document.getElementById(t.map[u]) : c = document.getElementById(t.map), !c)
456
571
  throw new Error("Could not find rendering target for map: " + t.map);
457
572
  if (!(c instanceof HTMLCanvasElement))
458
573
  throw new Error("Target for map is not a canvas: " + t.map);
459
- const f = new Ct(c);
460
- let p;
574
+ const f = new Ot(c);
575
+ let y;
461
576
  try {
462
- l.style && f.style.setPredefinedStyle(l.style), await f.init(), await N(i, l.workspace), p = await s(f, i, l);
463
- } catch (d) {
577
+ l.style && f.style.setPredefinedStyle(l.style), await f.init(), await I(i, l.workspace), y = await a(f, i, l);
578
+ } catch (h) {
464
579
  try {
465
580
  f.destroy();
466
581
  } catch {
467
582
  }
468
- throw d;
583
+ throw h;
469
584
  }
470
- const y = ht(l, u);
471
- l.layerRefs.forEach((d, m) => e?.push({
585
+ const m = _t(l, u);
586
+ l.layerRefs.forEach((h, p) => e?.push({
472
587
  map: f,
473
588
  mapIndex: u,
474
- mapId: y,
475
- layerId: S(d),
476
- dataRef: d.dataRef,
477
- rows: p[m]
478
- })), o && (o[u] = f), l.camera && te(f, l.camera), f.draw();
589
+ mapId: m,
590
+ layerId: R(h),
591
+ dataRef: h.dataRef,
592
+ rows: y[p]
593
+ })), o && (o[u] = f), l.camera && le(f, l.camera), f.draw();
479
594
  }
480
595
  }
481
596
  };
482
597
  }
483
- function oe(t) {
598
+ function fe(t) {
484
599
  return {
485
600
  scatter: "scatterplot",
486
601
  bar: "barchart",
@@ -491,62 +606,62 @@ function oe(t) {
491
606
  heatmatrix: "heatmatrix"
492
607
  }[t];
493
608
  }
494
- function L(t) {
609
+ function N(t) {
495
610
  return t.id ?? t.dataRef;
496
611
  }
497
- function wt(t, e, r, o) {
498
- const { map: n, layerId: a } = o;
499
- n.updateRenderInfo(a, { isPick: !0 }), n.events.on(D.PICKING, ({ layerId: s, selection: i }) => {
500
- s === a && t.setSelection(x(i, o.rows, e));
612
+ function vt(t, e, r, o) {
613
+ const { map: n, layerId: s } = o;
614
+ n.updateRenderInfo(s, { isPick: !0 }), n.events.on(Q.PICKING, ({ layerId: a, selection: i }) => {
615
+ a === s && t.setSelection(x(i, o.rows, e));
501
616
  });
502
- for (const s of r)
503
- t.events.on(s, ({ selection: i }) => {
504
- n.setHighlightedIds(a, x(i, e, o.rows));
617
+ for (const a of r)
618
+ t.events.on(a, ({ selection: i }) => {
619
+ n.setHighlightedIds(s, x(i, e, o.rows));
505
620
  });
506
621
  }
507
- async function ne(t, e, r, o) {
508
- const n = t.getTablesMetadata().find((a) => a.name === e);
509
- return n && !vt(n) ? { type: "FeatureCollection", features: (await t.getTable(e)).map((s) => ({ type: "Feature", geometry: null, properties: s })) } : mt(o, r, () => t.getLayer(e));
622
+ async function de(t, e, r, o, n) {
623
+ const s = t.getTablesMetadata().find((a) => a.name === e);
624
+ return s && !dt(s) ? { type: "FeatureCollection", features: (await t.getTable(e)).map((i) => ({ type: "Feature", geometry: null, properties: i })) } : bt(o, wt(r, n), () => t.getLayer(e, gt(n)));
510
625
  }
511
- function ae(t, e, r, o, n, a, s, i) {
626
+ function pe(t, e, r, o, n, s, a, i) {
512
627
  return {
513
- async resolvePlot(l, u, c = 0) {
628
+ async resolvePlot(l, u, d = 0) {
514
629
  if (!t || !t.plot) return;
515
- const f = Array.isArray(t.plot) ? t.plot[c] : t.plot;
516
- if (f === void 0) throw new Error(`Plot ${c} has no target: the plot targets name ${t.plot.length} elements.`);
517
- const p = document.getElementById(f);
518
- if (!p) throw new Error(`Could not find plot target: ${f}`);
630
+ const c = Array.isArray(t.plot) ? t.plot[d] : t.plot;
631
+ if (c === void 0) throw new Error(`Plot ${d} has no target: the plot targets name ${t.plot.length} elements.`);
632
+ const f = document.getElementById(c);
633
+ if (!f) throw new Error(`Could not find plot target: ${c}`);
519
634
  const y = l;
520
635
  if (!y) throw new Error("No data context available for plot.");
521
- await N(y, u.workspace);
522
- const d = A(u.workspace, u.dataRef), m = a?.get(d) ?? n?.get(d) ?? await ne(y, u.dataRef, d, i), h = u.events ?? [], g = new It(p, {
523
- type: oe(u.mark),
524
- collection: m,
636
+ await I(y, u.workspace);
637
+ const m = b(u.workspace, u.dataRef), h = u.osmElements === !0 ? void 0 : n?.get(m), p = s?.get(m) ?? h ?? await de(y, u.dataRef, m, i, u.osmElements), w = u.events ?? [], _ = new kt(f, {
638
+ type: fe(u.mark),
639
+ collection: p,
525
640
  attributes: { axis: u.axis, ...u.color && { color: u.color } },
526
641
  labels: { axis: u.axis, title: u.title },
527
- events: h,
642
+ events: w,
528
643
  ...u.width && { width: u.width },
529
644
  ...u.height && { height: u.height },
530
645
  ...u.margins && { margins: u.margins },
531
646
  ...u.transform && { transform: u.transform }
532
647
  });
533
- r?.set(L(u), g);
534
- const _ = pt(m.features ?? []);
535
- s?.set(L(u), _);
536
- for (const b of e ?? [])
537
- !u.mapRef || b.dataRef !== u.mapRef || (wt(g, _, h, b), yt(o, L(u), b));
648
+ r?.set(N(u), _);
649
+ const E = ht(p.features ?? []);
650
+ a?.set(N(u), E);
651
+ for (const S of e ?? [])
652
+ !u.mapRef || S.dataRef !== u.mapRef || (vt(_, E, w, S), Et(o, N(u), S));
538
653
  }
539
654
  };
540
655
  }
541
- const bt = 134217728, ie = 4, se = 32;
542
- function le(t) {
656
+ const Rt = 134217728, me = 4, he = 32;
657
+ function ye(t) {
543
658
  return Array.isArray(t) ? t.join(`
544
659
  `) : t;
545
660
  }
546
- function R(t) {
661
+ function v(t) {
547
662
  return !!t && typeof t == "object" && !Array.isArray(t) && typeof t.fromFeature == "object" && t.fromFeature !== null;
548
663
  }
549
- function P(t, e) {
664
+ function T(t, e) {
550
665
  return t instanceof Map ? t.get(e) : t[e];
551
666
  }
552
667
  function F(t, e) {
@@ -555,183 +670,183 @@ function F(t, e) {
555
670
  return r[o];
556
671
  }, t);
557
672
  }
558
- function _t(t) {
673
+ function St(t) {
559
674
  const e = [];
560
675
  for (const r of [t.uniforms, t.uniformMatrices])
561
676
  for (const o of Object.values(r ?? {}))
562
- R(o) && e.push(o);
677
+ v(o) && e.push(o);
563
678
  return e;
564
679
  }
565
- function ue(t) {
566
- return [.../* @__PURE__ */ new Set([t.dataRef, ..._t(t).map((e) => e.fromFeature.layer)])];
680
+ function we(t) {
681
+ return [.../* @__PURE__ */ new Set([t.dataRef, ...St(t).map((e) => e.fromFeature.layer)])];
567
682
  }
568
- function Et(t) {
569
- for (const e of _t(t)) {
683
+ function Ct(t) {
684
+ for (const e of St(t)) {
570
685
  const { iterate: r, layer: o } = e.fromFeature;
571
686
  if (r === "all" || r === "batched") return { mode: r, layer: o };
572
687
  }
573
688
  return null;
574
689
  }
575
- function At(t, e, r) {
576
- const o = t.fromFeature, n = r !== void 0 && o.iterate === "all" ? r : o.index ?? 0, a = P(e, o.layer)?.features?.[n];
577
- return a ? F(a, o.path) : void 0;
690
+ function It(t, e, r) {
691
+ const o = t.fromFeature, n = r !== void 0 && o.iterate === "all" ? r : o.index ?? 0, s = T(e, o.layer)?.features?.[n];
692
+ return s ? F(s, o.path) : void 0;
578
693
  }
579
- function rt(t, e, r) {
694
+ function it(t, e, r) {
580
695
  if (!t) return;
581
696
  const o = {};
582
- for (const [n, a] of Object.entries(t)) {
583
- if (!R(a)) {
584
- o[n] = a;
697
+ for (const [n, s] of Object.entries(t)) {
698
+ if (!v(s)) {
699
+ o[n] = s;
585
700
  continue;
586
701
  }
587
- const s = Number(At(a, e, r) ?? NaN);
588
- Number.isFinite(s) ? o[n] = s : typeof a.default == "number" && (o[n] = a.default);
702
+ const a = Number(It(s, e, r) ?? NaN);
703
+ Number.isFinite(a) ? o[n] = a : typeof s.default == "number" && (o[n] = s.default);
589
704
  }
590
705
  return o;
591
706
  }
592
- function ot(t, e, r) {
707
+ function st(t, e, r) {
593
708
  if (!t) return;
594
709
  const o = {};
595
- for (const [n, a] of Object.entries(t)) {
596
- if (!R(a)) {
597
- o[n] = a;
710
+ for (const [n, s] of Object.entries(t)) {
711
+ if (!v(s)) {
712
+ o[n] = s;
598
713
  continue;
599
714
  }
600
- const s = At(a, e, r), i = Array.isArray(s) ? s : Array.isArray(a.default) ? a.default : void 0;
715
+ const a = It(s, e, r), i = Array.isArray(a) ? a : Array.isArray(s.default) ? s.default : void 0;
601
716
  if (!i) continue;
602
- const l = a.cols ?? (Array.isArray(i[0]) ? i[0].length : 0);
717
+ const l = s.cols ?? (Array.isArray(i[0]) ? i[0].length : 0);
603
718
  l > 0 ? o[n] = { data: i, cols: l } : console.warn(`[autk-grammar] uniform matrix "${n}" has no column count; entry dropped`);
604
719
  }
605
720
  return o;
606
721
  }
607
- function ce(t) {
722
+ function ge(t) {
608
723
  return t != null && !(typeof t == "number" && !Number.isFinite(t));
609
724
  }
610
- function nt(t) {
611
- return R(t) && t.fromFeature.iterate === "batched";
725
+ function lt(t) {
726
+ return v(t) && t.fromFeature.iterate === "batched";
612
727
  }
613
- function Mt(t, e) {
614
- return Object.values(e ?? {}).some(nt) ? se : Object.values(t ?? {}).some(nt) ? ie : 0;
728
+ function Lt(t, e) {
729
+ return Object.values(e ?? {}).some(lt) ? he : Object.values(t ?? {}).some(lt) ? me : 0;
615
730
  }
616
- function fe(t, e, r = bt) {
617
- const o = Mt(t, e);
731
+ function be(t, e, r = Rt) {
732
+ const o = Lt(t, e);
618
733
  return o > 0 ? Math.floor(r / o) : Number.POSITIVE_INFINITY;
619
734
  }
620
- function pe(t, e, r, o = bt) {
621
- const n = {}, a = {}, s = [];
735
+ function _e(t, e, r, o = Rt) {
736
+ const n = {}, s = {}, a = [];
622
737
  for (const l of [t, e])
623
738
  for (const u of Object.values(l ?? {}))
624
- R(u) && u.fromFeature.iterate === "batched" && u.fromFeature.required && s.push(u.fromFeature.path);
625
- if (s.length > 0) {
739
+ v(u) && u.fromFeature.iterate === "batched" && u.fromFeature.required && a.push(u.fromFeature.path);
740
+ if (a.length > 0) {
626
741
  const l = r.length;
627
- r = r.filter((u) => s.every((c) => ce(F(u, c)))), r.length < l && console.info(`[autk-grammar] batched compute dropped ${l - r.length} feature(s) missing ${s.join(", ")}`);
742
+ r = r.filter((u) => a.every((d) => ge(F(u, d)))), r.length < l && console.info(`[autk-grammar] batched compute dropped ${l - r.length} feature(s) missing ${a.join(", ")}`);
628
743
  }
629
- const i = fe(t, e, o);
744
+ const i = be(t, e, o);
630
745
  r.length > i && (console.warn(
631
- `[autk-grammar] batched compute capped at ${i} features (got ${r.length}): its largest packed array takes ${Mt(t, e)} B per feature, and a storage buffer binding holds ${o} B`
746
+ `[autk-grammar] batched compute capped at ${i} features (got ${r.length}): its largest packed array takes ${Lt(t, e)} B per feature, and a storage buffer binding holds ${o} B`
632
747
  ), r = r.slice(0, i));
633
748
  for (const [l, u] of Object.entries(t ?? {}))
634
- if (R(u) && u.fromFeature.iterate === "batched") {
635
- const c = typeof u.default == "number" ? u.default : void 0;
636
- a[l] = r.map((f) => {
637
- const p = Number(F(f, u.fromFeature.path) ?? c);
638
- return Number.isFinite(p) ? p : 0;
749
+ if (v(u) && u.fromFeature.iterate === "batched") {
750
+ const d = typeof u.default == "number" ? u.default : void 0;
751
+ s[l] = r.map((c) => {
752
+ const f = Number(F(c, u.fromFeature.path) ?? d);
753
+ return Number.isFinite(f) ? f : 0;
639
754
  });
640
755
  } else typeof u == "number" && (n[l] = u);
641
756
  for (const [l, u] of Object.entries(e ?? {})) {
642
- if (!R(u) || u.fromFeature.iterate !== "batched") continue;
643
- const c = [];
644
- for (const f of r) {
645
- const p = F(f, u.fromFeature.path);
646
- let y = 1 / 0, d = 1 / 0, m = -1 / 0, h = -1 / 0;
647
- if (Array.isArray(p))
648
- for (const g of p) {
649
- if (!Array.isArray(g) || g.length < 2) continue;
650
- const _ = Number(g[0]), b = Number(g[1]);
651
- !Number.isFinite(_) || !Number.isFinite(b) || (y = Math.min(y, _), d = Math.min(d, b), m = Math.max(m, _), h = Math.max(h, b));
757
+ if (!v(u) || u.fromFeature.iterate !== "batched") continue;
758
+ const d = [];
759
+ for (const c of r) {
760
+ const f = F(c, u.fromFeature.path);
761
+ let y = 1 / 0, m = 1 / 0, h = -1 / 0, p = -1 / 0;
762
+ if (Array.isArray(f))
763
+ for (const w of f) {
764
+ if (!Array.isArray(w) || w.length < 2) continue;
765
+ const _ = Number(w[0]), E = Number(w[1]);
766
+ !Number.isFinite(_) || !Number.isFinite(E) || (y = Math.min(y, _), m = Math.min(m, E), h = Math.max(h, _), p = Math.max(p, E));
652
767
  }
653
- Number.isFinite(y) || (y = 0, d = 0, m = 0, h = 0), c.push(y, d, m, d, m, h, y, h);
768
+ Number.isFinite(y) || (y = 0, m = 0, h = 0, p = 0), d.push(y, m, h, m, h, p, y, p);
654
769
  }
655
- a[l] = c;
770
+ s[l] = d;
656
771
  }
657
- return n.num_features = r.length, { uniforms: n, uniformArrays: a };
772
+ return n.num_features = r.length, { uniforms: n, uniformArrays: s };
658
773
  }
659
- function at(t, e, r) {
660
- const o = P(e, t.dataRef);
774
+ function ut(t, e, r) {
775
+ const o = T(e, t.dataRef);
661
776
  if (!o) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
662
777
  const n = {
663
778
  collection: o,
664
779
  variableMapping: t.attributes,
665
- wgslBody: le(t.wgslFunction)
780
+ wgslBody: ye(t.wgslFunction)
666
781
  };
667
782
  t.attributeArrays && (n.attributeArrays = t.attributeArrays), t.attributeMatrices && (n.attributeMatrices = t.attributeMatrices), t.uniformArrays && (n.uniformArrays = t.uniformArrays), t.outputColumnName && (n.resultField = t.outputColumnName), t.outputColumns && (n.outputColumns = t.outputColumns);
668
- const a = Et(t);
669
- if (a?.mode === "batched") {
670
- const u = P(e, a.layer)?.features ?? [], c = pe(t.uniforms, t.uniformMatrices, u), f = rt(it(t.uniforms), e) ?? {}, p = ot(it(t.uniformMatrices), e);
671
- return n.uniforms = { ...f, ...c.uniforms }, n.uniformArrays = { ...n.uniformArrays ?? {}, ...c.uniformArrays }, p && Object.keys(p).length > 0 && (n.uniformMatrices = p), n;
783
+ const s = Ct(t);
784
+ if (s?.mode === "batched") {
785
+ const u = T(e, s.layer)?.features ?? [], d = _e(t.uniforms, t.uniformMatrices, u), c = it(ct(t.uniforms), e) ?? {}, f = st(ct(t.uniformMatrices), e);
786
+ return n.uniforms = { ...c, ...d.uniforms }, n.uniformArrays = { ...n.uniformArrays ?? {}, ...d.uniformArrays }, f && Object.keys(f).length > 0 && (n.uniformMatrices = f), n;
672
787
  }
673
- const s = a?.mode === "all" ? r : void 0, i = rt(t.uniforms, e, s), l = ot(t.uniformMatrices, e, s);
788
+ const a = s?.mode === "all" ? r : void 0, i = it(t.uniforms, e, a), l = st(t.uniformMatrices, e, a);
674
789
  return i && (n.uniforms = i), l && (n.uniformMatrices = l), n;
675
790
  }
676
- function it(t) {
791
+ function ct(t) {
677
792
  if (t)
678
- return Object.fromEntries(Object.entries(t).filter(([, e]) => !(R(e) && e.fromFeature.iterate === "batched")));
793
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => !(v(e) && e.fromFeature.iterate === "batched")));
679
794
  }
680
- function de(t) {
795
+ function Ee(t) {
681
796
  return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
682
797
  }
683
- async function me(t, e, r) {
684
- const o = Et(t);
685
- if (o?.mode !== "all") return r(at(t, e));
686
- const n = P(e, t.dataRef);
798
+ async function Me(t, e, r) {
799
+ const o = Ct(t);
800
+ if (o?.mode !== "all") return r(ut(t, e));
801
+ const n = T(e, t.dataRef);
687
802
  if (!n) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
688
- const a = de(t), s = structuredClone(n);
689
- for (const l of s.features) {
690
- const u = l.properties ??= {}, c = u.compute ??= {};
691
- for (const f of a) c[f] = 0;
803
+ const s = Ee(t), a = structuredClone(n);
804
+ for (const l of a.features) {
805
+ const u = l.properties ??= {}, d = u.compute ??= {};
806
+ for (const c of s) d[c] = 0;
692
807
  }
693
- const i = P(e, o.layer)?.features?.length ?? 0;
808
+ const i = T(e, o.layer)?.features?.length ?? 0;
694
809
  for (let l = 0; l < i; l++) {
695
- const u = await r({ ...at(t, e, l), collection: s });
696
- s.features.forEach((c, f) => {
697
- const p = c.properties?.compute, y = u.features[f]?.properties?.compute;
698
- if (!(!p || !y))
699
- for (const d of a) {
700
- const m = Number(y[d]);
701
- Number.isFinite(m) && (p[d] += m);
810
+ const u = await r({ ...ut(t, e, l), collection: a });
811
+ a.features.forEach((d, c) => {
812
+ const f = d.properties?.compute, y = u.features[c]?.properties?.compute;
813
+ if (!(!f || !y))
814
+ for (const m of s) {
815
+ const h = Number(y[m]);
816
+ Number.isFinite(h) && (f[m] += h);
702
817
  }
703
818
  });
704
819
  }
705
- return s;
820
+ return a;
706
821
  }
707
- const st = ["surface", "parks", "water", "roads", "buildings", "polygons", "polylines"];
708
- function he(t, e, r, o) {
709
- return o?.get(A(r, e)) ?? t.getTablesMetadata().find((n) => n.name === e)?.type;
822
+ const ft = ["surface", "parks", "water", "roads", "buildings", "polygons", "polylines"];
823
+ function Ae(t, e, r, o) {
824
+ return o?.get(b(r, e)) ?? t.getTablesMetadata().find((n) => n.name === e)?.type;
710
825
  }
711
- function ye(t, e) {
712
- async function r(s, i, l) {
713
- return t?.get(A(l, i)) ?? await s.getLayer(i);
826
+ function ve(t, e) {
827
+ async function r(a, i, l) {
828
+ return t?.get(b(l, i)) ?? await a.getLayer(i);
714
829
  }
715
- function o(s, i, l, u, c) {
830
+ function o(a, i, l, u, d) {
716
831
  if (!t) return;
717
- const f = u.outputTableName ?? l;
718
- t.set(A(u.workspace, f), i);
719
- const p = u.layerType ?? c ?? he(s, l, u.workspace, e);
720
- u.outputTableName && p && e?.set(A(u.workspace, f), p);
832
+ const c = u.outputTableName ?? l;
833
+ t.set(b(u.workspace, c), i);
834
+ const f = u.layerType ?? d ?? Ae(a, l, u.workspace, e);
835
+ u.outputTableName && f && e?.set(b(u.workspace, c), f);
721
836
  }
722
- async function n(s, i) {
723
- for (const c of i.layers)
724
- if (!st.includes(c.type))
725
- throw new Error(`Render pass "${i.outputTableName}": layer "${c.id}" has the type "${c.type}", which a render pass cannot draw. A layer's type is one of ${st.join(", ")}.`);
726
- const l = await Promise.all(i.layers.map(async (c) => ({
727
- id: c.id,
728
- collection: await r(s, c.dataRef, i.workspace),
729
- type: c.type,
730
- objectIdProperty: c.objectIdProperty
731
- }))), u = await new X().renderPipeline({
837
+ async function n(a, i) {
838
+ for (const d of i.layers)
839
+ if (!ft.includes(d.type))
840
+ throw new Error(`Render pass "${i.outputTableName}": layer "${d.id}" has the type "${d.type}", which a render pass cannot draw. A layer's type is one of ${ft.join(", ")}.`);
841
+ const l = await Promise.all(i.layers.map(async (d) => ({
842
+ id: d.id,
843
+ collection: await r(a, d.dataRef, i.workspace),
844
+ type: d.type,
845
+ objectIdProperty: d.objectIdProperty
846
+ }))), u = await new Z().renderPipeline({
732
847
  layers: l,
733
848
  viewpoints: {
734
- collection: await r(s, i.viewpoints.dataRef, i.workspace),
849
+ collection: await r(a, i.viewpoints.dataRef, i.workspace),
735
850
  strategy: i.viewpoints.strategy,
736
851
  sampling: i.viewpoints.sampling
737
852
  },
@@ -739,32 +854,32 @@ function ye(t, e) {
739
854
  camera: i.camera,
740
855
  tileSize: i.tileSize
741
856
  });
742
- o(s, u, i.viewpoints.dataRef, i, i.viewpoints.strategy?.type === "building-windows" ? "points" : void 0);
857
+ o(a, u, i.viewpoints.dataRef, i, i.viewpoints.strategy?.type === "building-windows" ? "points" : void 0);
743
858
  }
744
- async function a(s, i) {
859
+ async function s(a, i) {
745
860
  const l = {};
746
- for (const f of ue(i)) {
747
- const p = t?.get(A(i.workspace, f));
748
- if (p) l[f] = p;
749
- else if (f === i.dataRef) l[f] = await s.getLayer(f);
861
+ for (const c of we(i)) {
862
+ const f = t?.get(b(i.workspace, c));
863
+ if (f) l[c] = f;
864
+ else if (c === i.dataRef) l[c] = await a.getLayer(c);
750
865
  else
751
866
  try {
752
- l[f] = await s.getLayer(f);
867
+ l[c] = await a.getLayer(c);
753
868
  } catch {
754
- l[f] = void 0;
869
+ l[c] = void 0;
755
870
  }
756
871
  }
757
- const u = new X(), c = await me(i, l, (f) => u.gpgpuPipeline(f));
758
- o(s, c, i.dataRef, i);
872
+ const u = new Z(), d = await Me(i, l, (c) => u.gpgpuPipeline(c));
873
+ o(a, d, i.dataRef, i);
759
874
  }
760
875
  return {
761
- async resolveCompute(s, i) {
762
- if (s)
763
- return await N(s, i.workspace), i.type === "render" ? await n(s, i) : await a(s, i), s;
876
+ async resolveCompute(a, i) {
877
+ if (a)
878
+ return await I(a, i.workspace), i.type === "render" ? await n(a, i) : await s(a, i), a;
764
879
  }
765
880
  };
766
881
  }
767
- class ge {
882
+ class Re {
768
883
  _listeners = /* @__PURE__ */ new Map();
769
884
  on(e, r) {
770
885
  this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
@@ -776,26 +891,26 @@ class ge {
776
891
  this._listeners.get(e)?.forEach((o) => o(r));
777
892
  }
778
893
  }
779
- function v(t) {
894
+ function C(t) {
780
895
  return t === void 0 ? [] : Array.isArray(t) ? t : [t];
781
896
  }
782
- function we(t) {
897
+ function Se(t) {
783
898
  const e = /* @__PURE__ */ new Set();
784
- for (const o of [...v(t.map), ...v(t.plot)])
899
+ for (const o of [...C(t.map), ...C(t.plot)])
785
900
  if (o.id !== void 0) {
786
901
  if (o.id === "") throw new Error("A map or plot has an empty id.");
787
902
  if (e.has(o.id)) throw new Error(`Two maps or plots have the id "${o.id}"; an id names one view.`);
788
903
  e.add(o.id);
789
904
  }
790
905
  const r = /* @__PURE__ */ new Map();
791
- for (const o of v(t.plot)) {
792
- const n = L(o), a = r.get(n);
793
- if (a)
794
- throw new Error(a.id === void 0 && o.id === void 0 ? `Two plots of the table "${n}" have no id; give each plot an id.` : `A plot's id "${n}" is the dataRef of a plot without an id; give each plot an id.`);
906
+ for (const o of C(t.plot)) {
907
+ const n = N(o), s = r.get(n);
908
+ if (s)
909
+ throw new Error(s.id === void 0 && o.id === void 0 ? `Two plots of the table "${n}" have no id; give each plot an id.` : `A plot's id "${n}" is the dataRef of a plot without an id; give each plot an id.`);
795
910
  r.set(n, o);
796
911
  }
797
912
  }
798
- class Se {
913
+ class $e {
799
914
  dataAdapter;
800
915
  mapAdapter;
801
916
  plotAdapter;
@@ -813,12 +928,13 @@ class Se {
813
928
  _exports = /* @__PURE__ */ new Map();
814
929
  /** Each GeoJSON table a run loaded and each table a join wrote, which its plots read before the database. */
815
930
  _geojsonCache = /* @__PURE__ */ new Map();
816
- interactions = new ge();
931
+ interactions = new Re();
817
932
  constructor(e) {
818
- this.dataAdapter = xt(e, this._geojsonCache), this.mapAdapter = re(e, this._layers, this._computeCache, this._maps, this._computeTypes, this._exports), this.plotAdapter = ae(e, this._layers, this._plotRegistry, this._plotLinks, this._geojsonCache, this._computeCache, this._plotRows, this._exports), this.computeAdapter = ye(this._computeCache, this._computeTypes);
933
+ this.dataAdapter = Vt(e, this._geojsonCache), this.mapAdapter = ce(e, this._layers, this._computeCache, this._maps, this._computeTypes, this._exports), this.plotAdapter = pe(e, this._layers, this._plotRegistry, this._plotLinks, this._geojsonCache, this._computeCache, this._plotRows, this._exports), this.computeAdapter = ve(this._computeCache, this._computeTypes);
819
934
  }
820
935
  /**
821
- * The coordinate reference system used internally by the autk workspace.
936
+ * The coordinate reference system autk-db stores a workspace's tables in, unless the spec's `workspaces` sets
937
+ * another for it.
822
938
  *
823
939
  * Input data is expected in EPSG:4326 (WGS84) by default and is transformed
824
940
  * to this CRS on load. Consumers that prepare data for injection (e.g. by
@@ -826,7 +942,7 @@ class Se {
826
942
  * instead of hard-coding a CRS string.
827
943
  */
828
944
  get workspaceCrs() {
829
- return ut;
945
+ return $t;
830
946
  }
831
947
  get data() {
832
948
  return this._data;
@@ -873,7 +989,7 @@ class Se {
873
989
  }
874
990
  /** The drawn layers of a table, on every map or on the one `mapId` names. */
875
991
  _layersOf(e, r) {
876
- return this._layers.filter((o) => o.dataRef === e && G(o, r));
992
+ return this._layers.filter((o) => o.dataRef === e && U(o, r));
877
993
  }
878
994
  /**
879
995
  * Releases what the last run created: every map (its layers' GPU buffers, its textures, its canvas context, the
@@ -897,7 +1013,7 @@ class Se {
897
1013
  throw new Error("Plot adapter not initialized. Please call the constructor first.");
898
1014
  if (!this.computeAdapter)
899
1015
  throw new Error("Compute adapter not initialized. Please call the constructor first.");
900
- we(e), this.destroy(), this.grammarEngine = Pt({
1016
+ Se(e), this.destroy(), this.grammarEngine = Bt({
901
1017
  spec: e,
902
1018
  adapters: {
903
1019
  db: this.dataAdapter,
@@ -907,7 +1023,7 @@ class Se {
907
1023
  }
908
1024
  }), await this.grammarEngine.run();
909
1025
  const r = this.grammarEngine.context;
910
- if (r && await N(r), this._wireLinks(e), this._rewireInteractions(e), !r) {
1026
+ if (r && await I(r), this._wireLinks(e), this._rewireInteractions(e), !r) {
911
1027
  console.warn("Grammar engine produced no data context."), this._data = {};
912
1028
  return;
913
1029
  }
@@ -915,8 +1031,8 @@ class Se {
915
1031
  for (const n of r.getLayersMetadata())
916
1032
  Object.defineProperty(o, n.name, {
917
1033
  get: () => {
918
- const a = this._computeCache.get(n.name);
919
- return a ? Promise.resolve(a) : r.getLayer(n.name);
1034
+ const s = this._computeCache.get(n.name);
1035
+ return s ? Promise.resolve(s) : r.getLayer(n.name);
920
1036
  },
921
1037
  enumerable: !0,
922
1038
  configurable: !0
@@ -942,7 +1058,7 @@ class Se {
942
1058
  */
943
1059
  highlightOnMap(e, r, o) {
944
1060
  const n = this._layersOf(e, o);
945
- for (const { map: a, layerId: s } of n) a.setHighlightedIds(s, r);
1061
+ for (const { map: s, layerId: a } of n) s.setHighlightedIds(a, r);
946
1062
  this._selectInLinkedPlots(n, r);
947
1063
  }
948
1064
  /**
@@ -956,7 +1072,7 @@ class Se {
956
1072
  */
957
1073
  clearHighlightOnMap(e, r) {
958
1074
  const o = this._layersOf(e, r);
959
- for (const { map: n, layerId: a } of o) n.clearHighlightedIds(a);
1075
+ for (const { map: n, layerId: s } of o) n.clearHighlightedIds(s);
960
1076
  this._selectInLinkedPlots(o, []);
961
1077
  }
962
1078
  /**
@@ -971,7 +1087,7 @@ class Se {
971
1087
  clearHighlightOnPlot(e, r) {
972
1088
  this._plotRegistry.get(e)?.setSelection([]);
973
1089
  for (const o of this._plotLinks.get(e) ?? [])
974
- G(o, r) && o.map.clearHighlightedIds(o.layerId);
1090
+ U(o, r) && o.map.clearHighlightedIds(o.layerId);
975
1091
  }
976
1092
  /**
977
1093
  * Applies a selection to the plot `plotId` names: its `id`, else its `dataRef`.
@@ -986,8 +1102,8 @@ class Se {
986
1102
  setPlotSelection(e, r, o) {
987
1103
  this._plotRegistry.get(e)?.setSelection(r);
988
1104
  const n = this._plotRows.get(e) ?? [];
989
- for (const a of this._plotLinks.get(e) ?? [])
990
- G(a, o) && a.map.setHighlightedIds(a.layerId, x(r, n, a.rows));
1105
+ for (const s of this._plotLinks.get(e) ?? [])
1106
+ U(s, o) && s.map.setHighlightedIds(s.layerId, x(r, n, s.rows));
991
1107
  }
992
1108
  /**
993
1109
  * Applies a selection made on `layers`, by their positions `featureIds`, to every plot linked to one of them, at the
@@ -995,74 +1111,74 @@ class Se {
995
1111
  */
996
1112
  _selectInLinkedPlots(e, r) {
997
1113
  for (const [o, n] of this._plotLinks) {
998
- const a = n.filter((l) => e.includes(l));
999
- if (a.length === 0) continue;
1000
- const s = this._plotRows.get(o) ?? [], i = new Set(a.flatMap((l) => x(r, l.rows, s)));
1114
+ const s = n.filter((l) => e.includes(l));
1115
+ if (s.length === 0) continue;
1116
+ const a = this._plotRows.get(o) ?? [], i = new Set(s.flatMap((l) => x(r, l.rows, a)));
1001
1117
  this._plotRegistry.get(o)?.setSelection([...i]);
1002
1118
  }
1003
1119
  }
1004
1120
  /** Wires each entry of `links` between a plot and a layer of a map, both now drawn. */
1005
1121
  _wireLinks(e) {
1006
- const r = v(e.map), o = v(e.plot);
1122
+ const r = C(e.map), o = C(e.plot);
1007
1123
  for (const n of e.links ?? []) {
1008
- const a = o.find((f) => L(f) === n.source), s = this._plotRegistry.get(n.source);
1009
- if (!a || !s)
1124
+ const s = o.find((c) => N(c) === n.source), a = this._plotRegistry.get(n.source);
1125
+ if (!s || !a)
1010
1126
  throw new Error(`Link source "${n.source}" is not the id (or the dataRef) of a plot of this specification.`);
1011
- const i = r.findIndex((f) => f.id === n.target), l = this._maps[i];
1127
+ const i = r.findIndex((c) => c.id === n.target), l = this._maps[i];
1012
1128
  if (i < 0 || !l)
1013
1129
  throw new Error(`Link target "${n.target}" is not the id of a map of this specification.`);
1014
- const u = r[i].layerRefs.find((f) => n.layer !== void 0 ? S(f) === n.layer : f.dataRef === a.dataRef);
1130
+ const u = r[i].layerRefs.find((c) => n.layer !== void 0 ? R(c) === n.layer : c.dataRef === s.dataRef);
1015
1131
  if (!u)
1016
- throw new Error(n.layer !== void 0 ? `Link from "${n.source}": map "${n.target}" has no layer "${n.layer}".` : `Link from "${n.source}": map "${n.target}" draws no layer of the table "${a.dataRef}"; name the layer.`);
1017
- const c = this._layers.find((f) => f.mapIndex === i && f.layerId === S(u));
1018
- c && (wt(s, this._plotRows.get(n.source) ?? [], a.events ?? [], c), yt(this._plotLinks, n.source, c));
1132
+ throw new Error(n.layer !== void 0 ? `Link from "${n.source}": map "${n.target}" has no layer "${n.layer}".` : `Link from "${n.source}": map "${n.target}" draws no layer of the table "${s.dataRef}"; name the layer.`);
1133
+ const d = this._layers.find((c) => c.mapIndex === i && c.layerId === R(u));
1134
+ d && (vt(a, this._plotRows.get(n.source) ?? [], s.events ?? [], d), Et(this._plotLinks, n.source, d));
1019
1135
  }
1020
1136
  }
1021
1137
  _rewireInteractions(e) {
1022
1138
  for (const o of this._fwdCleanups) o();
1023
1139
  this._fwdCleanups = [];
1024
- const r = v(e.map);
1140
+ const r = C(e.map);
1025
1141
  this._maps.forEach((o, n) => {
1026
- const a = ht(r[n], n), s = ({ layerId: i, selection: l }) => {
1027
- this.interactions.emit("map:picking", { mapId: a, layerId: i, selection: l });
1142
+ const s = _t(r[n], n), a = ({ layerId: i, selection: l }) => {
1143
+ this.interactions.emit("map:picking", { mapId: s, layerId: i, selection: l });
1028
1144
  };
1029
- o.events.on(D.PICKING, s), this._fwdCleanups.push(() => o.events.off(D.PICKING, s));
1145
+ o.events.on(Q.PICKING, a), this._fwdCleanups.push(() => o.events.off(Q.PICKING, a));
1030
1146
  });
1031
1147
  for (const [o, n] of this._plotRegistry)
1032
- for (const a of [O.CLICK, O.BRUSH, O.BRUSH_X, O.BRUSH_Y]) {
1033
- const s = ({ selection: i }) => {
1148
+ for (const s of [k.CLICK, k.BRUSH, k.BRUSH_X, k.BRUSH_Y]) {
1149
+ const a = ({ selection: i }) => {
1034
1150
  this.interactions.emit("plot:selection", {
1035
1151
  plotId: o,
1036
- event: a,
1152
+ event: s,
1037
1153
  selection: i
1038
1154
  });
1039
1155
  };
1040
- n.events.on(a, s), this._fwdCleanups.push(() => n.events.off(a, s));
1156
+ n.events.on(s, a), this._fwdCleanups.push(() => n.events.off(s, a));
1041
1157
  }
1042
1158
  }
1043
1159
  }
1044
1160
  export {
1045
- Se as AutkGrammar,
1046
- Nt as ColorMapInterpolator,
1047
- ge as GrammarEventEmitter,
1048
- ct as NormalizationMode,
1049
- bt as STORAGE_BUFFER_BINDING_SIZE,
1050
- te as applyCamera,
1051
- Re as arrangeViews,
1052
- pe as buildBatchedUniforms,
1053
- ue as computeLayerNames,
1054
- ye as createComputeAdapter,
1055
- xt as createDataAdapter,
1056
- Pt as createEngine,
1057
- N as enterWorkspace,
1058
- Et as findIterateSource,
1059
- R as isFromFeature,
1060
- le as joinWgsl,
1061
- fe as maxBatchedFeatures,
1062
- at as resolveComputeParams,
1063
- ot as resolveUniformMatrices,
1064
- rt as resolveUniforms,
1065
- me as runCompute,
1066
- A as tableKey
1161
+ $e as AutkGrammar,
1162
+ xt as ColorMapInterpolator,
1163
+ Re as GrammarEventEmitter,
1164
+ pt as NormalizationMode,
1165
+ Rt as STORAGE_BUFFER_BINDING_SIZE,
1166
+ le as applyCamera,
1167
+ Te as arrangeViews,
1168
+ _e as buildBatchedUniforms,
1169
+ we as computeLayerNames,
1170
+ ve as createComputeAdapter,
1171
+ Vt as createDataAdapter,
1172
+ Bt as createEngine,
1173
+ I as enterWorkspace,
1174
+ Ct as findIterateSource,
1175
+ v as isFromFeature,
1176
+ ye as joinWgsl,
1177
+ be as maxBatchedFeatures,
1178
+ ut as resolveComputeParams,
1179
+ st as resolveUniformMatrices,
1180
+ it as resolveUniforms,
1181
+ Me as runCompute,
1182
+ b as tableKey
1067
1183
  };
1068
1184
  //# sourceMappingURL=autk-grammar.js.map