@urban-toolkit/autk-grammar 4.4.0 → 5.0.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,9 +1,9 @@
1
- import { AutkDb as K, DEFAULT_WORKSPACE_COORDINATE_FORMAT as Y } from "@urban-toolkit/autk-db";
2
- import { AutkMap as z, MapEvent as B } from "@urban-toolkit/autk-map";
3
- import { AutkPlot as Z, PlotEvent as I } from "@urban-toolkit/autk-plot";
4
- import { ColorMapInterpolator as tt, ColorMapDomainStrategy as M, ColorMap as v } from "@urban-toolkit/autk-core";
5
- import { AutkComputeEngine as et } from "@urban-toolkit/autk-compute";
6
- function rt(t) {
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) {
7
7
  const { spec: e, adapters: r } = t;
8
8
  let o;
9
9
  async function n() {
@@ -17,15 +17,15 @@ function rt(t) {
17
17
  if (e.map)
18
18
  if (Array.isArray(e.map))
19
19
  for (let l = 0; l < e.map.length; l++) {
20
- let c = e.map[l];
21
- await r.map.resolveMap(i, c, l);
20
+ let u = e.map[l];
21
+ await r.map.resolveMap(i, u, l);
22
22
  }
23
23
  else
24
24
  await r.map.resolveMap(i, e.map);
25
25
  if (e.plot)
26
26
  if (Array.isArray(e.plot))
27
- for (const l of e.plot)
28
- await r.plot.resolvePlot(i, l);
27
+ for (let l = 0; l < e.plot.length; l++)
28
+ await r.plot.resolvePlot(i, e.plot[l], l);
29
29
  else
30
30
  await r.plot.resolvePlot(i, e.plot);
31
31
  o = i;
@@ -42,8 +42,84 @@ function rt(t) {
42
42
  return o;
43
43
  } };
44
44
  }
45
- var ot = /* @__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))(ot || {}), H = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(H || {});
46
- function at(t) {
45
+ function z(t) {
46
+ return t === void 0 ? [] : Array.isArray(t) ? t : [t];
47
+ }
48
+ function Re(t) {
49
+ const e = t.layout ?? {}, r = e.type ?? "vertical";
50
+ if (r !== "vertical" && r !== "horizontal" && r !== "grid")
51
+ throw new Error(`Layout type must be vertical, horizontal or grid, not ${JSON.stringify(r)}.`);
52
+ const o = e.gap ?? 0;
53
+ if (typeof o != "number" || !Number.isFinite(o) || o < 0)
54
+ throw new Error(`Layout gap must be a number of pixels, 0 or more, not ${JSON.stringify(o)}.`);
55
+ const n = e.columns ?? 2;
56
+ if (!Number.isInteger(n) || n < 1)
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) => ({
62
+ kind: l,
63
+ index: u,
64
+ ...c !== void 0 && { id: c },
65
+ key: f,
66
+ row: Math.floor(p / s),
67
+ column: p % s
68
+ }));
69
+ return { type: r, rows: Math.ceil(a.length / s), columns: s, gap: o, panes: i };
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;
74
+ t.getCurrentWorkspace() !== r && await t.setWorkspace(r);
75
+ }
76
+ function A(t, e) {
77
+ return t === void 0 || t === lt ? e : `${t}/${e}`;
78
+ }
79
+ function ft(t) {
80
+ const e = /* @__PURE__ */ new Set();
81
+ for (const o of t)
82
+ o?.id != null && e.add(JSON.stringify(o.id));
83
+ const r = /* @__PURE__ */ new Set();
84
+ return t.map((o, n) => {
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;
89
+ });
90
+ }
91
+ function pt(t) {
92
+ const e = /* @__PURE__ */ new Map();
93
+ return ft(t).map((r) => {
94
+ const o = JSON.stringify(r), n = e.get(o) ?? 0;
95
+ return e.set(o, n + 1), n === 0 ? o : `${o} ${n}`;
96
+ });
97
+ }
98
+ const Z = /* @__PURE__ */ new WeakMap();
99
+ function Tt(t) {
100
+ let e = Z.get(t);
101
+ return e || (e = /* @__PURE__ */ new Map(), t.forEach((r, o) => {
102
+ const n = e.get(r);
103
+ n ? n.push(o) : e.set(r, [o]);
104
+ }), Z.set(t, e), e);
105
+ }
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);
112
+ }
113
+ return [...n];
114
+ }
115
+ const $t = { type: "GeometryCollection", geometries: [] };
116
+ function Ot(t) {
117
+ const e = t.features ?? [], r = ft(e);
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;
121
+ }
122
+ function Ft(t) {
47
123
  const { queryArea: e } = t;
48
124
  if (e.bbox === void 0) return { geocodeArea: e.geocodeArea, areas: e.areas };
49
125
  const r = (l) => new Error(`OSM source "${t.outputTableName}": ${l}`);
@@ -63,11 +139,31 @@ function at(t) {
63
139
  throw r(`queryArea.bbox south (${a}) must be less than north (${i}).`);
64
140
  return { bbox: [n, a, s, i] };
65
141
  }
66
- function nt(t) {
142
+ function Bt(t) {
67
143
  const { autoLoadLayers: e, ...r } = t;
68
- return { ...r, queryArea: at(t), autoLoadLayers: { layers: e?.layers ?? [] } };
144
+ return { ...r, queryArea: Ft(t), autoLoadLayers: { layers: e?.layers ?? [] } };
145
+ }
146
+ function tt(t) {
147
+ 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.`;
69
148
  }
70
- function it(t, e) {
149
+ function dt(t) {
150
+ let e = 1 / 0, r = 1 / 0, o = -1 / 0, n = -1 / 0;
151
+ const a = (i) => {
152
+ if (Array.isArray(i)) {
153
+ if (typeof i[0] == "number") {
154
+ const [l, u] = i;
155
+ l < e && (e = l), l > o && (o = l), u < r && (r = u), u > n && (n = u);
156
+ return;
157
+ }
158
+ for (const l of i) a(l);
159
+ }
160
+ }, s = (i) => {
161
+ i && (i.type === "GeometryCollection" ? i.geometries.forEach(s) : a(i.coordinates));
162
+ };
163
+ for (const i of t.features ?? []) s(i?.geometry);
164
+ return e <= o ? [e, r, o, n] : void 0;
165
+ }
166
+ function xt(t, e) {
71
167
  function r(o, n) {
72
168
  if (!n || !n.db)
73
169
  return;
@@ -83,62 +179,69 @@ function it(t, e) {
83
179
  return {
84
180
  async resolveSource(o, n) {
85
181
  let a = o;
86
- a || (a = new K(), await a.init());
87
- let { type: s, ...i } = n;
88
- switch (s) {
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) {
89
187
  case "osm":
90
- return await a.loadOsm(nt(i)), r(a, t), a;
188
+ return await a.loadOsm(Bt(u)), r(a, t), a;
91
189
  case "csv":
92
- return await a.loadCsv(i), r(a, t), a;
190
+ return await a.loadCsv(u), r(a, t), a;
93
191
  case "json":
94
- return await a.loadJson(i), r(a, t), a;
192
+ return await a.loadJson(u), r(a, t), a;
95
193
  case "geojson": {
96
- const l = i;
97
- let c;
98
- l.geojsonFileUrl ? c = await (await fetch(l.geojsonFileUrl)).json() : c = l.geojsonObject, e && c && e.set(l.outputTableName, c);
99
- const u = c ? (() => {
100
- const f = { ...l, geojsonObject: c };
101
- return delete f.geojsonFileUrl, f;
102
- })() : l;
103
- try {
104
- await a.loadGeojson(u);
105
- } catch (f) {
106
- const p = u.coordinateFormat ? `coordinateFormat is set to "${u.coordinateFormat}"` : "no coordinateFormat was specified — defaulting to EPSG:4326 (WGS84 per RFC 7946)";
194
+ const c = u;
195
+ 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))
107
202
  throw new Error(
108
- `Failed to load GeoJSON layer "${u.outputTableName}": ${f instanceof Error ? f.message : String(f)}. ${p}. Verify that coordinateFormat matches the actual CRS of the input data.`
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)}`
109
204
  );
205
+ 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)}`);
110
209
  }
111
210
  try {
112
- const f = await a.getBoundingBoxFromLayer(u.outputTableName), p = 25e6;
113
- if (!isFinite(f.minLon) || !isFinite(f.minLat) || !isFinite(f.maxLon) || !isFinite(f.maxLat) || Math.abs(f.minLon) > p || Math.abs(f.maxLon) > p || Math.abs(f.minLat) > p || Math.abs(f.maxLat) > p)
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)
114
213
  throw new Error(
115
- `Geometry bounding box after transform is invalid for layer "${u.outputTableName}" (bbox: [${f.minLon}, ${f.minLat}, ${f.maxLon}, ${f.maxLat}]). Verify that coordinateFormat matches the actual CRS of the input data. The workspace uses ${Y}; input is expected in EPSG:4326 by default.`
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.`
116
215
  );
117
- } catch (f) {
118
- if (f instanceof Error && f.message.includes("bounding box after transform")) throw f;
216
+ } catch (m) {
217
+ if (m instanceof Error && m.message.includes("bounding box after transform")) throw m;
119
218
  }
120
219
  return r(a, t), a;
121
220
  }
221
+ case "geotiff":
222
+ return await a.loadGeoTiff(u), r(a, t), a;
122
223
  case "heatmap": {
123
- const l = i;
224
+ const c = u;
225
+ if (c.groupBy?.some((f) => f.aggregateFn === "collect"))
226
+ 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.`);
124
227
  return await a.buildHeatmap({
125
- tableJoinName: l.tableJoinName,
126
- near: { distance: l.near.distance },
127
- outputTableName: l.outputTableName,
128
- grid: l.grid,
129
- ...l.groupBy && { groupBy: l.groupBy }
228
+ tableJoinName: c.joinDataRef,
229
+ near: c.near,
230
+ outputTableName: c.outputTableName,
231
+ grid: c.grid,
232
+ ...c.groupBy && { groupBy: c.groupBy }
130
233
  }), r(a, t), a;
131
234
  }
132
235
  case "join": {
133
- const l = i;
236
+ const c = u;
134
237
  if (await a.spatialQuery({
135
- tableRootName: l.tableRootName,
136
- tableJoinName: l.tableJoinName,
137
- ...l.near && { near: l.near },
138
- ...l.groupBy && { groupBy: l.groupBy }
238
+ tableRootName: c.dataRef,
239
+ tableJoinName: c.joinDataRef,
240
+ ...c.near && { near: c.near },
241
+ ...c.groupBy && { groupBy: c.groupBy }
139
242
  }), e) {
140
- const c = await a.getLayer(l.tableRootName);
141
- e.set(l.tableRootName, c);
243
+ const f = await a.getLayer(c.dataRef);
244
+ e.set(A(s, c.dataRef), f);
142
245
  }
143
246
  return r(a, t), a;
144
247
  }
@@ -148,60 +251,104 @@ function it(t, e) {
148
251
  }
149
252
  };
150
253
  }
151
- function N(t) {
254
+ function mt(t, e, r) {
255
+ if (!t) return r();
256
+ let o = t.get(e);
257
+ return o || (o = r(), t.set(e, o)), o;
258
+ }
259
+ function ht(t, e) {
260
+ return t?.id ?? e;
261
+ }
262
+ function G(t, e) {
263
+ return e === void 0 ? !0 : typeof e == "number" ? t.mapIndex === e : t.mapId === e;
264
+ }
265
+ function yt(t, e, r) {
266
+ const o = t?.get(e) ?? [];
267
+ o.includes(r) || t?.set(e, [...o, r]);
268
+ }
269
+ const gt = 6378137, j = 0.0818191908426215;
270
+ function kt(t, e) {
271
+ if (t === void 0 || typeof t == "number" && Number.isFinite(t) && t > 0) return;
272
+ const r = typeof t == "number" ? String(t) : JSON.stringify(t);
273
+ throw new Error(`Layer "${e}": pointSize must be a number of meters greater than 0, not ${r}.`);
274
+ }
275
+ function Gt(t) {
276
+ const e = Math.exp(-t / gt);
277
+ let r = Math.PI / 2 - 2 * Math.atan(e);
278
+ 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;
282
+ }
283
+ return r;
284
+ }
285
+ function Dt(t, e) {
286
+ if (/^EPSG:3395$/i.test(t)) {
287
+ const r = Gt(e), o = j * Math.sin(r);
288
+ return Math.sqrt(1 - o * o) / Math.cos(r);
289
+ }
290
+ return /^EPSG:3857$/i.test(t) ? Math.cosh(e / gt) : 1;
291
+ }
292
+ function jt(t, e, r, o) {
293
+ if (t === void 0 || e !== "points") return;
294
+ const n = o();
295
+ if (n)
296
+ return t * Dt(r, (n[1] + n[3]) / 2);
297
+ }
298
+ function S(t) {
152
299
  return typeof t.title == "string" && t.title !== "" ? t.title : t.dataRef;
153
300
  }
154
- function st(t, e) {
301
+ function Ut(t, e) {
155
302
  const r = /* @__PURE__ */ new Set();
156
303
  for (const o of t.layerRefs) {
157
- const n = N(o);
304
+ const n = S(o);
158
305
  if (r.has(n))
159
306
  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.`);
160
307
  r.add(n);
161
308
  }
162
309
  }
163
- const lt = /^#[0-9a-fA-F]{6}$/;
164
- function $(t, e, r) {
165
- if (!lt.test(t))
310
+ const Qt = /^#[0-9a-fA-F]{6}$/;
311
+ function et(t, e, r) {
312
+ if (!Qt.test(t))
166
313
  throw new Error(`Layer "${r}": ${e} must be a color written #rrggbb, not "${t}".`);
167
- return v.hexToRgb(t);
314
+ return B.hexToRgb(t);
168
315
  }
169
- function ut(t, e) {
316
+ function Yt(t, e) {
170
317
  const r = {};
171
- return t.color != null && (r.color = $(t.color, "color", e)), t.stroke === !1 ? r.showBorders = !1 : t.stroke != null && (r.strokeColor = $(t.stroke, "stroke", e)), t.width != null && (r.polylinesWidth = t.width), 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;
172
319
  }
173
- function ct(t, e) {
320
+ function Vt(t, e) {
174
321
  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;
175
322
  }
176
- function ft(t, e) {
323
+ function Ht(t, e) {
177
324
  const r = t.features?.[0]?.properties?.[e];
178
325
  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;
179
326
  }
180
- function pt(t, e, r, o, n) {
181
- if (v.isCategorical(e.interpolator)) return;
327
+ function Wt(t, e, r, o, n) {
328
+ if (B.isCategorical(e.interpolator)) return;
182
329
  if (n != null) {
183
- const c = r != null ? [n[0], r, n[1]] : [n[0], n[1]];
184
- return o === !0 ? c.reverse() : c;
330
+ const u = r != null ? [n[0], r, n[1]] : [n[0], n[1]];
331
+ return o === !0 ? u.reverse() : u;
185
332
  }
186
333
  if (!t) return;
187
334
  let a = 0, s = 0;
188
- for (let c = 0; c < t.length; c++) {
189
- const u = t[c];
190
- Number.isFinite(u) && (s++, r != null && (a = Math.max(a, Math.abs(u - r))));
335
+ 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))));
191
338
  }
192
339
  const i = r != null && a > 0;
193
340
  if (s === 0 || !i && o !== !0) return;
194
- const l = i && r != null ? [r - a, r, r + a] : v.resolveDomainFromData(t, e);
341
+ const l = i && r != null ? [r - a, r, r + a] : B.resolveDomainFromData(t, e);
195
342
  return o === !0 ? [...l].reverse() : l;
196
343
  }
197
- function mt(t, e) {
198
- if (!(e == null || v.isCategorical(t.interpolator)))
344
+ function Jt(t, e) {
345
+ if (!(e == null || B.isCategorical(t.interpolator)))
199
346
  return [e[0], e[1]];
200
347
  }
201
- function dt(t) {
348
+ function qt(t) {
202
349
  const e = t.colorMapRange;
203
350
  if (e === void 0) return;
204
- const r = (s) => new Error(`Layer "${N(t)}": ${s}`);
351
+ const r = (s) => new Error(`Layer "${S(t)}": ${s}`);
205
352
  if (!Array.isArray(e) || e.length !== 2 || !e.every((s) => typeof s == "number" && Number.isFinite(s)))
206
353
  throw r("colorMapRange must hold two numbers, [low, high].");
207
354
  const [o, n] = e;
@@ -213,94 +360,127 @@ function dt(t) {
213
360
  if (a != null && (a < o || a > n))
214
361
  throw r(`colorMapCenter (${a}) must lie within colorMapRange [${o}, ${n}].`);
215
362
  }
216
- function ht(t, e) {
217
- return e && e.length > 0 ? { type: M.USER, params: e } : t?.mode === H.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
218
- type: M.PERCENTILE,
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,
219
366
  params: [t.lowerPercentile ?? 0, t.upperPercentile ?? 100]
220
- } : { type: M.PERCENTILE } : { type: M.MIN_MAX };
367
+ } : { type: I.PERCENTILE } : { type: I.MIN_MAX };
221
368
  }
222
- function yt(t, e) {
369
+ function Xt(t, e) {
223
370
  return e.split(".").reduce((r, o) => {
224
371
  if (!(r == null || typeof r != "object"))
225
372
  return r[o];
226
373
  }, t);
227
374
  }
228
- function gt(t, e, r) {
375
+ function zt(t, e, r) {
229
376
  const o = e.split("."), n = { ...t };
230
377
  let a = n;
231
378
  for (let s = 0; s < o.length - 1; s++)
232
379
  a[o[s]] = { ...a[o[s]] ?? {} }, a = a[o[s]];
233
380
  return a[o[o.length - 1]] = r, n;
234
381
  }
235
- function bt(t, e) {
382
+ function Zt(t, e) {
236
383
  const o = t.features?.[0]?.properties?.bands ?? [];
237
384
  return o.find((a) => a.id === e || a.label === e?.replace(/\./g, "_"))?.id ?? o[0]?.id ?? e ?? "";
238
385
  }
239
- function _t(t, e, r, o, n) {
240
- async function a(s, i, l) {
386
+ function te(t, e) {
387
+ 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;
399
+ 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) {
241
404
  let c = {};
242
- for (const u of i.getTablesMetadata())
243
- u.type !== void 0 && (c[u.name] = u.type);
244
- for (const u of l.layerRefs) {
245
- const f = u.dataRef, p = N(u), m = c[f], d = u.getFnv, h = r?.get(f) ?? await i.getLayer(f), y = m === "raster" ? h : {
246
- ...h,
247
- features: (h.features ?? []).filter((g) => g.geometry != null)
248
- }, w = m === "raster" ? bt(y, d) : "";
249
- m === "raster" ? s.loadCollection(p, { collection: y, type: "raster", property: w }) : s.loadCollection(p, { collection: y, type: m }), u.opacity != null && s.updateRenderInfo(p, { opacity: u.opacity });
250
- const A = ut(u, p);
251
- Object.keys(A).length > 0 && s.updateRenderInfo(p, A), ct(u, m) && s.updateRenderInfo(p, { isColorMap: !0 }), u.isPick && s.updateRenderInfo(p, { isPick: !0 }), u.isSkip && s.updateRenderInfo(p, { isSkip: !0 });
252
- const { catchAllCategory: b, colorMapDomain: R } = u;
253
- let F = y, T = R;
254
- if (d && b && R?.length) {
255
- const g = new Set(R);
256
- F = {
257
- ...y,
258
- features: y.features.map((_) => {
259
- const D = _.properties, P = yt(D, d);
260
- return P == null || !g.has(String(P)) ? { ..._, properties: gt(D, d, b) } : _;
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;
261
424
  })
262
- }, T = g.has(b) ? R : [...R, b];
425
+ }, W = w.has(T) ? C : [...C, T];
263
426
  }
264
- const O = m === "raster" && u.transferFunction != null;
265
- O && s.layerManager.searchByLayerId(p)?.setTransferFunction?.(u.transferFunction);
266
- const C = u.colorMapRange, x = m === "raster" && (C != null || u.colorMapCenter != null || u.colorMapReverse === !0);
267
- if (u.colorMapInterpolator || x || C) {
268
- const g = {
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 = {
269
432
  // urban-grammar ColorMapInterpolator values are string-compatible
270
433
  // with autk-core ColorMapInterpolator at runtime
271
- interpolator: u.colorMapInterpolator ?? s.layerManager.searchByLayerId(p)?.layerRenderInfo.colormap.config.interpolator ?? tt.SEQ_REDS,
272
- domainSpec: ht(u.normalization, T)
434
+ interpolator: p.colorMapInterpolator ?? i.layerManager.searchByLayerId(d)?.layerRenderInfo.colormap.config.interpolator ?? Lt.SEQ_REDS,
435
+ domainSpec: Kt(p.normalization, W)
273
436
  };
274
- let _;
275
- x ? _ = pt(ft(y, w), g, u.colorMapCenter, u.colorMapReverse, C) : m !== "raster" && (_ = mt(g, C)), _ && (g.domainSpec = { type: M.USER, params: _ }), s.updateColorMap(p, { colorMap: g });
276
- } else O && s.updateColorMap(p, { colorMap: {} });
277
- if (d && m !== "raster") {
278
- const g = d.startsWith("properties.") ? d : `properties.${d}`;
279
- s.updateThematic(p, { collection: F, property: g });
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 });
280
443
  }
444
+ f.push(h === "raster" ? [] : ee(i, d, pt(b), U));
281
445
  }
446
+ return f;
282
447
  }
283
448
  return {
284
- async resolveMap(s, i, l = 0) {
285
- if (t && t.map && s) {
286
- st(i, l);
287
- for (const f of i.layerRefs)
288
- dt(f);
449
+ async resolveMap(i, l, u = 0) {
450
+ if (t && t.map && i) {
451
+ Ut(l, u);
452
+ for (const d of l.layerRefs)
453
+ qt(d), kt(d.pointSize, S(d));
289
454
  let c;
290
- if (Array.isArray(t.map) ? c = document.getElementById(t.map[l]) : c = document.getElementById(t.map), !c)
455
+ if (Array.isArray(t.map) ? c = document.getElementById(t.map[u]) : c = document.getElementById(t.map), !c)
291
456
  throw new Error("Could not find rendering target for map: " + t.map);
292
457
  if (!(c instanceof HTMLCanvasElement))
293
458
  throw new Error("Target for map is not a canvas: " + t.map);
294
- const u = new z(c);
295
- i.style && u.style.setPredefinedStyle(i.style), await u.init(), await a(u, s, i);
296
- for (const f of i.layerRefs)
297
- e?.set(f.dataRef, u), n?.set(f.dataRef, N(f));
298
- o && (o[l] = u), u.draw();
459
+ const f = new Ct(c);
460
+ let p;
461
+ 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) {
464
+ try {
465
+ f.destroy();
466
+ } catch {
467
+ }
468
+ throw d;
469
+ }
470
+ const y = ht(l, u);
471
+ l.layerRefs.forEach((d, m) => e?.push({
472
+ map: f,
473
+ 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();
299
479
  }
300
480
  }
301
481
  };
302
482
  }
303
- function Et(t) {
483
+ function oe(t) {
304
484
  return {
305
485
  scatter: "scatterplot",
306
486
  bar: "barchart",
@@ -311,229 +491,280 @@ function Et(t) {
311
491
  heatmatrix: "heatmatrix"
312
492
  }[t];
313
493
  }
314
- function wt(t, e, r, o, n, a) {
494
+ function L(t) {
495
+ return t.id ?? t.dataRef;
496
+ }
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));
501
+ });
502
+ for (const s of r)
503
+ t.events.on(s, ({ selection: i }) => {
504
+ n.setHighlightedIds(a, x(i, e, o.rows));
505
+ });
506
+ }
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));
510
+ }
511
+ function ae(t, e, r, o, n, a, s, i) {
315
512
  return {
316
- async resolvePlot(s, i) {
513
+ async resolvePlot(l, u, c = 0) {
317
514
  if (!t || !t.plot) return;
318
- const l = document.getElementById(t.plot);
319
- if (!l) throw new Error(`Could not find plot target: ${t.plot}`);
320
- const c = s;
321
- if (!c) throw new Error("No data context available for plot.");
322
- const u = n?.get(i.dataRef) ?? await c.getLayer(i.dataRef), f = i.events ?? [], p = new Z(l, {
323
- type: Et(i.mark),
324
- collection: u,
325
- attributes: { axis: i.axis, ...i.color && { color: i.color } },
326
- labels: { axis: i.axis, title: i.title },
327
- events: f,
328
- ...i.width && { width: i.width },
329
- ...i.height && { height: i.height },
330
- ...i.margins && { margins: i.margins },
331
- ...i.transform && { transform: i.transform }
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}`);
519
+ const y = l;
520
+ 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,
525
+ attributes: { axis: u.axis, ...u.color && { color: u.color } },
526
+ labels: { axis: u.axis, title: u.title },
527
+ events: h,
528
+ ...u.width && { width: u.width },
529
+ ...u.height && { height: u.height },
530
+ ...u.margins && { margins: u.margins },
531
+ ...u.transform && { transform: u.transform }
332
532
  });
333
- if (r?.set(i.dataRef, p), i.mapRef && o?.set(i.dataRef, i.mapRef), i.mapRef && e) {
334
- const m = e.get(i.mapRef), d = a?.get(i.mapRef) ?? i.mapRef;
335
- if (m) {
336
- m.updateRenderInfo(d, { isPick: !0 }), m.events.on(B.PICKING, ({ selection: h }) => {
337
- p.setSelection(h);
338
- });
339
- for (const h of f)
340
- p.events.on(h, ({ selection: y }) => {
341
- m.setHighlightedIds(d, y);
342
- });
343
- }
344
- }
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));
345
538
  }
346
539
  };
347
540
  }
348
- const k = 134217728, At = 4, Rt = 32;
349
- function Mt(t) {
541
+ const bt = 134217728, ie = 4, se = 32;
542
+ function le(t) {
350
543
  return Array.isArray(t) ? t.join(`
351
544
  `) : t;
352
545
  }
353
- function E(t) {
546
+ function R(t) {
354
547
  return !!t && typeof t == "object" && !Array.isArray(t) && typeof t.fromFeature == "object" && t.fromFeature !== null;
355
548
  }
356
- function S(t, e) {
549
+ function P(t, e) {
357
550
  return t instanceof Map ? t.get(e) : t[e];
358
551
  }
359
- function L(t, e) {
552
+ function F(t, e) {
360
553
  return e.split(".").reduce((r, o) => {
361
554
  if (!(r == null || typeof r != "object"))
362
555
  return r[o];
363
556
  }, t);
364
557
  }
365
- function q(t) {
558
+ function _t(t) {
366
559
  const e = [];
367
560
  for (const r of [t.uniforms, t.uniformMatrices])
368
561
  for (const o of Object.values(r ?? {}))
369
- E(o) && e.push(o);
562
+ R(o) && e.push(o);
370
563
  return e;
371
564
  }
372
- function St(t) {
373
- return [.../* @__PURE__ */ new Set([t.dataRef, ...q(t).map((e) => e.fromFeature.layer)])];
565
+ function ue(t) {
566
+ return [.../* @__PURE__ */ new Set([t.dataRef, ..._t(t).map((e) => e.fromFeature.layer)])];
374
567
  }
375
- function W(t) {
376
- for (const e of q(t)) {
568
+ function Et(t) {
569
+ for (const e of _t(t)) {
377
570
  const { iterate: r, layer: o } = e.fromFeature;
378
571
  if (r === "all" || r === "batched") return { mode: r, layer: o };
379
572
  }
380
573
  return null;
381
574
  }
382
- function X(t, e, r) {
383
- const o = t.fromFeature, n = r !== void 0 && o.iterate === "all" ? r : o.index ?? 0, a = S(e, o.layer)?.features?.[n];
384
- return a ? L(a, o.path) : void 0;
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;
385
578
  }
386
- function G(t, e, r) {
579
+ function rt(t, e, r) {
387
580
  if (!t) return;
388
581
  const o = {};
389
582
  for (const [n, a] of Object.entries(t)) {
390
- if (!E(a)) {
583
+ if (!R(a)) {
391
584
  o[n] = a;
392
585
  continue;
393
586
  }
394
- const s = Number(X(a, e, r) ?? NaN);
587
+ const s = Number(At(a, e, r) ?? NaN);
395
588
  Number.isFinite(s) ? o[n] = s : typeof a.default == "number" && (o[n] = a.default);
396
589
  }
397
590
  return o;
398
591
  }
399
- function j(t, e, r) {
592
+ function ot(t, e, r) {
400
593
  if (!t) return;
401
594
  const o = {};
402
595
  for (const [n, a] of Object.entries(t)) {
403
- if (!E(a)) {
596
+ if (!R(a)) {
404
597
  o[n] = a;
405
598
  continue;
406
599
  }
407
- const s = X(a, e, r), i = Array.isArray(s) ? s : Array.isArray(a.default) ? a.default : void 0;
600
+ const s = At(a, e, r), i = Array.isArray(s) ? s : Array.isArray(a.default) ? a.default : void 0;
408
601
  if (!i) continue;
409
602
  const l = a.cols ?? (Array.isArray(i[0]) ? i[0].length : 0);
410
603
  l > 0 ? o[n] = { data: i, cols: l } : console.warn(`[autk-grammar] uniform matrix "${n}" has no column count; entry dropped`);
411
604
  }
412
605
  return o;
413
606
  }
414
- function Ct(t) {
607
+ function ce(t) {
415
608
  return t != null && !(typeof t == "number" && !Number.isFinite(t));
416
609
  }
417
- function U(t) {
418
- return E(t) && t.fromFeature.iterate === "batched";
610
+ function nt(t) {
611
+ return R(t) && t.fromFeature.iterate === "batched";
419
612
  }
420
- function J(t, e) {
421
- return Object.values(e ?? {}).some(U) ? Rt : Object.values(t ?? {}).some(U) ? At : 0;
613
+ function Mt(t, e) {
614
+ return Object.values(e ?? {}).some(nt) ? se : Object.values(t ?? {}).some(nt) ? ie : 0;
422
615
  }
423
- function It(t, e, r = k) {
424
- const o = J(t, e);
616
+ function fe(t, e, r = bt) {
617
+ const o = Mt(t, e);
425
618
  return o > 0 ? Math.floor(r / o) : Number.POSITIVE_INFINITY;
426
619
  }
427
- function Lt(t, e, r, o = k) {
620
+ function pe(t, e, r, o = bt) {
428
621
  const n = {}, a = {}, s = [];
429
622
  for (const l of [t, e])
430
- for (const c of Object.values(l ?? {}))
431
- E(c) && c.fromFeature.iterate === "batched" && c.fromFeature.required && s.push(c.fromFeature.path);
623
+ for (const u of Object.values(l ?? {}))
624
+ R(u) && u.fromFeature.iterate === "batched" && u.fromFeature.required && s.push(u.fromFeature.path);
432
625
  if (s.length > 0) {
433
626
  const l = r.length;
434
- r = r.filter((c) => s.every((u) => Ct(L(c, u)))), r.length < l && console.info(`[autk-grammar] batched compute dropped ${l - r.length} feature(s) missing ${s.join(", ")}`);
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(", ")}`);
435
628
  }
436
- const i = It(t, e, o);
629
+ const i = fe(t, e, o);
437
630
  r.length > i && (console.warn(
438
- `[autk-grammar] batched compute capped at ${i} features (got ${r.length}): its largest packed array takes ${J(t, e)} B per feature, and a storage buffer binding holds ${o} B`
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`
439
632
  ), r = r.slice(0, i));
440
- for (const [l, c] of Object.entries(t ?? {}))
441
- if (E(c) && c.fromFeature.iterate === "batched") {
442
- const u = typeof c.default == "number" ? c.default : void 0;
633
+ 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;
443
636
  a[l] = r.map((f) => {
444
- const p = Number(L(f, c.fromFeature.path) ?? u);
637
+ const p = Number(F(f, u.fromFeature.path) ?? c);
445
638
  return Number.isFinite(p) ? p : 0;
446
639
  });
447
- } else typeof c == "number" && (n[l] = c);
448
- for (const [l, c] of Object.entries(e ?? {})) {
449
- if (!E(c) || c.fromFeature.iterate !== "batched") continue;
450
- const u = [];
640
+ } else typeof u == "number" && (n[l] = u);
641
+ for (const [l, u] of Object.entries(e ?? {})) {
642
+ if (!R(u) || u.fromFeature.iterate !== "batched") continue;
643
+ const c = [];
451
644
  for (const f of r) {
452
- const p = L(f, c.fromFeature.path);
453
- let m = 1 / 0, d = 1 / 0, h = -1 / 0, y = -1 / 0;
645
+ const p = F(f, u.fromFeature.path);
646
+ let y = 1 / 0, d = 1 / 0, m = -1 / 0, h = -1 / 0;
454
647
  if (Array.isArray(p))
455
- for (const w of p) {
456
- if (!Array.isArray(w) || w.length < 2) continue;
457
- const A = Number(w[0]), b = Number(w[1]);
458
- !Number.isFinite(A) || !Number.isFinite(b) || (m = Math.min(m, A), d = Math.min(d, b), h = Math.max(h, A), y = Math.max(y, b));
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));
459
652
  }
460
- Number.isFinite(m) || (m = 0, d = 0, h = 0, y = 0), u.push(m, d, h, d, h, y, m, y);
653
+ Number.isFinite(y) || (y = 0, d = 0, m = 0, h = 0), c.push(y, d, m, d, m, h, y, h);
461
654
  }
462
- a[l] = u;
655
+ a[l] = c;
463
656
  }
464
657
  return n.num_features = r.length, { uniforms: n, uniformArrays: a };
465
658
  }
466
- function Q(t, e, r) {
467
- const o = S(e, t.dataRef);
659
+ function at(t, e, r) {
660
+ const o = P(e, t.dataRef);
468
661
  if (!o) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
469
662
  const n = {
470
663
  collection: o,
471
664
  variableMapping: t.attributes,
472
- wgslBody: Mt(t.wglsFunction)
665
+ wgslBody: le(t.wgslFunction)
473
666
  };
474
667
  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);
475
- const a = W(t);
668
+ const a = Et(t);
476
669
  if (a?.mode === "batched") {
477
- const c = S(e, a.layer)?.features ?? [], u = Lt(t.uniforms, t.uniformMatrices, c), f = G(V(t.uniforms), e) ?? {}, p = j(V(t.uniformMatrices), e);
478
- return n.uniforms = { ...f, ...u.uniforms }, n.uniformArrays = { ...n.uniformArrays ?? {}, ...u.uniformArrays }, p && Object.keys(p).length > 0 && (n.uniformMatrices = p), n;
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;
479
672
  }
480
- const s = a?.mode === "all" ? r : void 0, i = G(t.uniforms, e, s), l = j(t.uniformMatrices, e, s);
673
+ const s = a?.mode === "all" ? r : void 0, i = rt(t.uniforms, e, s), l = ot(t.uniformMatrices, e, s);
481
674
  return i && (n.uniforms = i), l && (n.uniformMatrices = l), n;
482
675
  }
483
- function V(t) {
676
+ function it(t) {
484
677
  if (t)
485
- return Object.fromEntries(Object.entries(t).filter(([, e]) => !(E(e) && e.fromFeature.iterate === "batched")));
678
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => !(R(e) && e.fromFeature.iterate === "batched")));
486
679
  }
487
- function vt(t) {
680
+ function de(t) {
488
681
  return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
489
682
  }
490
- async function Nt(t, e, r) {
491
- const o = W(t);
492
- if (o?.mode !== "all") return r(Q(t, e));
493
- const n = S(e, t.dataRef);
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);
494
687
  if (!n) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
495
- const a = vt(t), s = structuredClone(n);
688
+ const a = de(t), s = structuredClone(n);
496
689
  for (const l of s.features) {
497
- const c = l.properties ??= {}, u = c.compute ??= {};
498
- for (const f of a) u[f] = 0;
690
+ const u = l.properties ??= {}, c = u.compute ??= {};
691
+ for (const f of a) c[f] = 0;
499
692
  }
500
- const i = S(e, o.layer)?.features?.length ?? 0;
693
+ const i = P(e, o.layer)?.features?.length ?? 0;
501
694
  for (let l = 0; l < i; l++) {
502
- const c = await r({ ...Q(t, e, l), collection: s });
503
- s.features.forEach((u, f) => {
504
- const p = u.properties?.compute, m = c.features[f]?.properties?.compute;
505
- if (!(!p || !m))
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))
506
699
  for (const d of a) {
507
- const h = Number(m[d]);
508
- Number.isFinite(h) && (p[d] += h);
700
+ const m = Number(y[d]);
701
+ Number.isFinite(m) && (p[d] += m);
509
702
  }
510
703
  });
511
704
  }
512
705
  return s;
513
706
  }
514
- function Pt(t) {
515
- return {
516
- async resolveCompute(e, r) {
517
- if (e) {
518
- const o = {};
519
- for (const s of St(r)) {
520
- const i = t?.get(s);
521
- if (i) o[s] = i;
522
- else if (s === r.dataRef) o[s] = await e.getLayer(s);
523
- else
524
- try {
525
- o[s] = await e.getLayer(s);
526
- } catch {
527
- o[s] = void 0;
528
- }
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;
710
+ }
711
+ function ye(t, e) {
712
+ async function r(s, i, l) {
713
+ return t?.get(A(l, i)) ?? await s.getLayer(i);
714
+ }
715
+ function o(s, i, l, u, c) {
716
+ 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);
721
+ }
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({
732
+ layers: l,
733
+ viewpoints: {
734
+ collection: await r(s, i.viewpoints.dataRef, i.workspace),
735
+ strategy: i.viewpoints.strategy,
736
+ sampling: i.viewpoints.sampling
737
+ },
738
+ aggregation: i.aggregation,
739
+ camera: i.camera,
740
+ tileSize: i.tileSize
741
+ });
742
+ o(s, u, i.viewpoints.dataRef, i, i.viewpoints.strategy?.type === "building-windows" ? "points" : void 0);
743
+ }
744
+ async function a(s, i) {
745
+ 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);
750
+ else
751
+ try {
752
+ l[f] = await s.getLayer(f);
753
+ } catch {
754
+ l[f] = void 0;
529
755
  }
530
- const n = new et(), a = await Nt(r, o, (s) => n.gpgpuPipeline(s));
531
- return t && t.set(r.dataRef, a), e;
532
- }
756
+ }
757
+ const u = new X(), c = await me(i, l, (f) => u.gpgpuPipeline(f));
758
+ o(s, c, i.dataRef, i);
759
+ }
760
+ 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;
533
764
  }
534
765
  };
535
766
  }
536
- class Bt {
767
+ class ge {
537
768
  _listeners = /* @__PURE__ */ new Map();
538
769
  on(e, r) {
539
770
  this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
@@ -545,24 +776,46 @@ class Bt {
545
776
  this._listeners.get(e)?.forEach((o) => o(r));
546
777
  }
547
778
  }
548
- class $t {
779
+ function v(t) {
780
+ return t === void 0 ? [] : Array.isArray(t) ? t : [t];
781
+ }
782
+ function we(t) {
783
+ const e = /* @__PURE__ */ new Set();
784
+ for (const o of [...v(t.map), ...v(t.plot)])
785
+ if (o.id !== void 0) {
786
+ if (o.id === "") throw new Error("A map or plot has an empty id.");
787
+ if (e.has(o.id)) throw new Error(`Two maps or plots have the id "${o.id}"; an id names one view.`);
788
+ e.add(o.id);
789
+ }
790
+ 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.`);
795
+ r.set(n, o);
796
+ }
797
+ }
798
+ class Se {
549
799
  dataAdapter;
550
800
  mapAdapter;
551
801
  plotAdapter;
552
802
  computeAdapter;
553
803
  grammarEngine;
554
804
  _computeCache = /* @__PURE__ */ new Map();
805
+ _computeTypes = /* @__PURE__ */ new Map();
555
806
  _data = {};
556
- _mapRegistry = /* @__PURE__ */ new Map();
557
- _mapLayerIds = /* @__PURE__ */ new Map();
807
+ _layers = [];
558
808
  _maps = [];
559
809
  _plotRegistry = /* @__PURE__ */ new Map();
560
810
  _fwdCleanups = [];
561
- _plotMapLinks = /* @__PURE__ */ new Map();
562
- interactions = new Bt();
811
+ _plotLinks = /* @__PURE__ */ new Map();
812
+ _plotRows = /* @__PURE__ */ new Map();
813
+ _exports = /* @__PURE__ */ new Map();
814
+ /** Each GeoJSON table a run loaded and each table a join wrote, which its plots read before the database. */
815
+ _geojsonCache = /* @__PURE__ */ new Map();
816
+ interactions = new ge();
563
817
  constructor(e) {
564
- const r = /* @__PURE__ */ new Map();
565
- this.dataAdapter = it(e, r), this.mapAdapter = _t(e, this._mapRegistry, this._computeCache, this._maps, this._mapLayerIds), this.plotAdapter = wt(e, this._mapRegistry, this._plotRegistry, this._plotMapLinks, r, this._mapLayerIds), this.computeAdapter = Pt(this._computeCache);
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);
566
819
  }
567
820
  /**
568
821
  * The coordinate reference system used internally by the autk workspace.
@@ -573,7 +826,7 @@ class $t {
573
826
  * instead of hard-coding a CRS string.
574
827
  */
575
828
  get workspaceCrs() {
576
- return Y;
829
+ return ut;
577
830
  }
578
831
  get data() {
579
832
  return this._data;
@@ -589,18 +842,51 @@ class $t {
589
842
  get maps() {
590
843
  return this._maps;
591
844
  }
845
+ /**
846
+ * Every layer the maps of the last {@link run} draw for a table, found by the table's name (a layer's `dataRef`):
847
+ * for each, the map that draws it and the layer's id in that map, which is its `title`, else its `dataRef`. The
848
+ * maps come in the spec's order, each map's layers bottom first. Empty when no map draws the table.
849
+ *
850
+ * @param dataRef The table's name.
851
+ * @param mapId The map to look in, by its {@link MapId}: a string names a map by its `id`, a number by its index in
852
+ * the spec's `map` list. Without it, every map.
853
+ */
854
+ mapLayers(e, r) {
855
+ return this._layersOf(e, r).map(({ map: o, layerId: n }) => ({ map: o, layerId: n }));
856
+ }
592
857
  /**
593
858
  * The layer a map of the last {@link run} draws for a table, found by the table's name (a layer's `dataRef`):
594
859
  * the map that draws it, and the layer's id in that map, which is its `title`, else its `dataRef`.
595
- * `undefined` when no map draws the table. When several layers draw it, the last one.
860
+ * `undefined` when no map draws the table. When several layers draw it, the last one, which is the last map's;
861
+ * {@link mapLayers} lists them all.
862
+ *
863
+ * @param dataRef The table's name.
864
+ * @param mapId The map to look in, by its {@link MapId}: a string names a map by its `id`, a number by its index in
865
+ * the spec's `map` list. Without it, every map.
596
866
  *
597
867
  * @example
598
868
  * const layer = grammar.mapLayer('buildings');
599
869
  * layer?.map.updateRenderInfo(layer.layerId, { opacity: 0.5 });
600
870
  */
601
- mapLayer(e) {
602
- const r = this._mapRegistry.get(e);
603
- return r ? { map: r, layerId: this._mapLayerIds.get(e) ?? e } : void 0;
871
+ mapLayer(e, r) {
872
+ return this.mapLayers(e, r).pop();
873
+ }
874
+ /** The drawn layers of a table, on every map or on the one `mapId` names. */
875
+ _layersOf(e, r) {
876
+ return this._layers.filter((o) => o.dataRef === e && G(o, r));
877
+ }
878
+ /**
879
+ * Releases what the last run created: every map (its layers' GPU buffers, its textures, its canvas context, the
880
+ * controls it adds to the page and its event handlers) and the grammar's own registries, caches and event
881
+ * forwarding. autk-map's maps share one GPU device, which stays for the maps of the next run. Call it before the
882
+ * page or the container goes away; `run` calls it before it starts, so running a new spec on the same instance
883
+ * does not leak the maps of the old one.
884
+ */
885
+ destroy() {
886
+ for (const e of this._fwdCleanups) e();
887
+ this._fwdCleanups = [];
888
+ for (const e of this._maps) e.destroy();
889
+ this._maps.length = 0, this._layers.length = 0, this._plotRegistry.clear(), this._plotLinks.clear(), this._plotRows.clear(), this._exports.clear(), this._geojsonCache.clear(), this._computeCache.clear(), this._computeTypes.clear(), this.grammarEngine = void 0, this._data = {};
604
890
  }
605
891
  async run(e) {
606
892
  if (!this.dataAdapter)
@@ -611,7 +897,7 @@ class $t {
611
897
  throw new Error("Plot adapter not initialized. Please call the constructor first.");
612
898
  if (!this.computeAdapter)
613
899
  throw new Error("Compute adapter not initialized. Please call the constructor first.");
614
- this._mapRegistry.clear(), this._mapLayerIds.clear(), this._maps.length = 0, this._plotRegistry.clear(), this._plotMapLinks.clear(), this._computeCache.clear(), this.grammarEngine = rt({
900
+ we(e), this.destroy(), this.grammarEngine = Pt({
615
901
  spec: e,
616
902
  adapters: {
617
903
  db: this.dataAdapter,
@@ -619,9 +905,9 @@ class $t {
619
905
  plot: this.plotAdapter,
620
906
  compute: this.computeAdapter
621
907
  }
622
- }), await this.grammarEngine.run(), this._rewireInteractions();
908
+ }), await this.grammarEngine.run();
623
909
  const r = this.grammarEngine.context;
624
- if (!r) {
910
+ if (r && await N(r), this._wireLinks(e), this._rewireInteractions(e), !r) {
625
911
  console.warn("Grammar engine produced no data context."), this._data = {};
626
912
  return;
627
913
  }
@@ -635,87 +921,148 @@ class $t {
635
921
  enumerable: !0,
636
922
  configurable: !0
637
923
  });
924
+ for (const n of this._computeCache.keys())
925
+ n in o || Object.defineProperty(o, n, {
926
+ get: () => Promise.resolve(this._computeCache.get(n)),
927
+ enumerable: !0,
928
+ configurable: !0
929
+ });
638
930
  this._data = o;
639
931
  }
640
932
  /**
641
- * Highlights features on the map layer that draws the table `dataRef` (see {@link mapLayer}).
642
- * If that layer is linked to a plot via `mapRef`, the plot selection is updated too.
933
+ * Highlights features on every layer that draws the table `dataRef`, in every map (see {@link mapLayers}), or only
934
+ * in the map `mapId` names. If a plot is linked to one of those layers, by a link or its `mapRef`, the plot
935
+ * selection is updated too, to the same rows: the plot finds them by their feature ids, since it can draw the
936
+ * table's rows in another order and draws the rows without a geometry, which a layer leaves out.
937
+ *
938
+ * @param dataRef The table's name.
939
+ * @param featureIds The features to highlight: their positions among those the layer draws.
940
+ * @param mapId The map to highlight on, by its {@link MapId}: a string names a map by its `id`, a number by its
941
+ * index in the spec's `map` list. Without it, every map that draws the table.
643
942
  */
644
- highlightOnMap(e, r) {
645
- const o = this.mapLayer(e);
646
- o?.map.setHighlightedIds(o.layerId, r);
647
- for (const [n, a] of this._plotMapLinks)
648
- a === e && this._plotRegistry.get(n)?.setSelection(r);
943
+ highlightOnMap(e, r, o) {
944
+ const n = this._layersOf(e, o);
945
+ for (const { map: a, layerId: s } of n) a.setHighlightedIds(s, r);
946
+ this._selectInLinkedPlots(n, r);
649
947
  }
650
948
  /**
651
- * Clears highlighted features on the map layer that draws the table `dataRef` (see {@link mapLayer}).
652
- * If that layer is linked to a plot via `mapRef`, the plot selection is cleared too.
949
+ * Clears highlighted features on every layer that draws the table `dataRef`, in every map (see {@link mapLayers}),
950
+ * or only in the map `mapId` names. If a plot is linked to one of those layers, by a link or its `mapRef`, the plot
951
+ * selection is cleared too.
952
+ *
953
+ * @param dataRef The table's name.
954
+ * @param mapId The map to clear, by its {@link MapId}: a string names a map by its `id`, a number by its index in
955
+ * the spec's `map` list. Without it, every map that draws the table.
653
956
  */
654
- clearHighlightOnMap(e) {
655
- const r = this.mapLayer(e);
656
- r?.map.clearHighlightedIds(r.layerId);
657
- for (const [o, n] of this._plotMapLinks)
658
- n === e && this._plotRegistry.get(o)?.setSelection([]);
957
+ clearHighlightOnMap(e, r) {
958
+ const o = this._layersOf(e, r);
959
+ for (const { map: n, layerId: a } of o) n.clearHighlightedIds(a);
960
+ this._selectInLinkedPlots(o, []);
659
961
  }
660
962
  /**
661
- * Clears the selection on the plot identified by `plotId` (its dataRef).
662
- * If that plot is linked to a map via `mapRef`, the map highlight is cleared too.
963
+ * Clears the selection on the plot `plotId` names: its `id`, else its `dataRef`.
964
+ * If that plot is linked to map layers, by links or its `mapRef`, their highlights are cleared too: on every map,
965
+ * or only on the map `mapId` names.
966
+ *
967
+ * @param plotId The plot: its `id`, else its `dataRef`.
968
+ * @param mapId The map whose linked layers to clear, by its {@link MapId}: a string names a map by its `id`, a
969
+ * number by its index in the spec's `map` list. Without it, every linked layer.
663
970
  */
664
- clearHighlightOnPlot(e) {
971
+ clearHighlightOnPlot(e, r) {
665
972
  this._plotRegistry.get(e)?.setSelection([]);
666
- const r = this._plotMapLinks.get(e), o = r ? this.mapLayer(r) : void 0;
667
- o?.map.clearHighlightedIds(o.layerId);
973
+ for (const o of this._plotLinks.get(e) ?? [])
974
+ G(o, r) && o.map.clearHighlightedIds(o.layerId);
668
975
  }
669
976
  /**
670
- * Applies a selection to the plot identified by `plotId` (its dataRef).
671
- * If that plot is linked to a map via `mapRef`, the map highlight is updated too.
977
+ * Applies a selection to the plot `plotId` names: its `id`, else its `dataRef`.
978
+ * If that plot is linked to map layers, by links or its `mapRef`, their highlights are updated too, to the same rows
979
+ * (see {@link highlightOnMap}): on every map, or only on the map `mapId` names.
980
+ *
981
+ * @param plotId The plot: its `id`, else its `dataRef`.
982
+ * @param featureIds The features to select: their positions among those the plot draws.
983
+ * @param mapId The map whose linked layers to highlight, by its {@link MapId}: a string names a map by its `id`, a
984
+ * number by its index in the spec's `map` list. Without it, every linked layer.
672
985
  */
673
- setPlotSelection(e, r) {
986
+ setPlotSelection(e, r, o) {
674
987
  this._plotRegistry.get(e)?.setSelection(r);
675
- const o = this._plotMapLinks.get(e), n = o ? this.mapLayer(o) : void 0;
676
- n?.map.setHighlightedIds(n.layerId, r);
988
+ 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));
677
991
  }
678
- _rewireInteractions() {
679
- for (const r of this._fwdCleanups) r();
992
+ /**
993
+ * Applies a selection made on `layers`, by their positions `featureIds`, to every plot linked to one of them, at the
994
+ * plot's own positions of the selected rows.
995
+ */
996
+ _selectInLinkedPlots(e, r) {
997
+ 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)));
1001
+ this._plotRegistry.get(o)?.setSelection([...i]);
1002
+ }
1003
+ }
1004
+ /** Wires each entry of `links` between a plot and a layer of a map, both now drawn. */
1005
+ _wireLinks(e) {
1006
+ const r = v(e.map), o = v(e.plot);
1007
+ 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)
1010
+ 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];
1012
+ if (i < 0 || !l)
1013
+ 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);
1015
+ 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));
1019
+ }
1020
+ }
1021
+ _rewireInteractions(e) {
1022
+ for (const o of this._fwdCleanups) o();
680
1023
  this._fwdCleanups = [];
681
- const e = /* @__PURE__ */ new Set();
682
- for (const [r, o] of this._mapRegistry) {
683
- if (e.has(o)) continue;
684
- e.add(o);
685
- const n = ({ selection: a }) => {
686
- this.interactions.emit("map:picking", { layerId: r, selection: a });
1024
+ const r = v(e.map);
1025
+ 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 });
687
1028
  };
688
- o.events.on(B.PICKING, n), this._fwdCleanups.push(() => o.events.off(B.PICKING, n));
689
- }
690
- for (const [r, o] of this._plotRegistry)
691
- for (const n of [I.CLICK, I.BRUSH, I.BRUSH_X, I.BRUSH_Y]) {
692
- const a = ({ selection: s }) => {
1029
+ o.events.on(D.PICKING, s), this._fwdCleanups.push(() => o.events.off(D.PICKING, s));
1030
+ });
1031
+ 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 }) => {
693
1034
  this.interactions.emit("plot:selection", {
694
- plotId: r,
695
- event: n,
696
- selection: s
1035
+ plotId: o,
1036
+ event: a,
1037
+ selection: i
697
1038
  });
698
1039
  };
699
- o.events.on(n, a), this._fwdCleanups.push(() => o.events.off(n, a));
1040
+ n.events.on(a, s), this._fwdCleanups.push(() => n.events.off(a, s));
700
1041
  }
701
1042
  }
702
1043
  }
703
1044
  export {
704
- $t as AutkGrammar,
705
- ot as ColorMapInterpolator,
706
- Bt as GrammarEventEmitter,
707
- H as NormalizationMode,
708
- k as STORAGE_BUFFER_BINDING_SIZE,
709
- Lt as buildBatchedUniforms,
710
- St as computeLayerNames,
711
- rt as createEngine,
712
- W as findIterateSource,
713
- E as isFromFeature,
714
- Mt as joinWgsl,
715
- It as maxBatchedFeatures,
716
- Q as resolveComputeParams,
717
- j as resolveUniformMatrices,
718
- G as resolveUniforms,
719
- Nt as runCompute
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
720
1067
  };
721
1068
  //# sourceMappingURL=autk-grammar.js.map