@urban-toolkit/autk-grammar 5.0.0 → 5.2.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,227 +1,290 @@
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
- const { spec: e, adapters: r } = t;
8
- let o;
1
+ import { DEFAULT_WORKSPACE_NAME as G, isVectorTable as Dt, AutkDb as Gt, isRenderableTable as yt, DEFAULT_WORKSPACE_COORDINATE_FORMAT as Ut } from "@urban-toolkit/autk-db";
2
+ import { AutkMap as Qt, MapEvent as Y } from "@urban-toolkit/autk-map";
3
+ import { AutkPlot as Wt, PlotStyle as F, PlotEvent as x } from "@urban-toolkit/autk-plot";
4
+ import { ColorMapDomainStrategy as $, ColorMapInterpolator as gt, ColorMap as N, valueAtPath as Yt } from "@urban-toolkit/autk-core";
5
+ import { AutkComputeEngine as et } from "@urban-toolkit/autk-compute";
6
+ function Vt(t) {
7
+ const { spec: e, adapters: o } = t;
8
+ let r;
9
9
  async function n() {
10
- let i;
11
- if (e.data)
12
- for (const l of e.data)
13
- i = await r.db.resolveSource(i, l);
10
+ let s;
11
+ if (e.workspaces?.length && o.db.resolveWorkspaces && (s = await o.db.resolveWorkspaces(s, e.workspaces)), e.data)
12
+ for (const i of e.data)
13
+ s = await o.db.resolveSource(s, i);
14
14
  if (e.compute)
15
- for (const l of e.compute)
16
- i = await r.compute.resolveCompute(i, l);
15
+ for (const i of e.compute)
16
+ s = await o.compute.resolveCompute(s, i);
17
17
  if (e.map)
18
18
  if (Array.isArray(e.map))
19
- for (let l = 0; l < e.map.length; l++) {
20
- let u = e.map[l];
21
- await r.map.resolveMap(i, u, l);
19
+ for (let i = 0; i < e.map.length; i++) {
20
+ let u = e.map[i];
21
+ await o.map.resolveMap(s, u, i);
22
22
  }
23
23
  else
24
- await r.map.resolveMap(i, e.map);
24
+ await o.map.resolveMap(s, e.map);
25
25
  if (e.plot)
26
26
  if (Array.isArray(e.plot))
27
- for (let l = 0; l < e.plot.length; l++)
28
- await r.plot.resolvePlot(i, e.plot[l], l);
27
+ for (let i = 0; i < e.plot.length; i++)
28
+ await o.plot.resolvePlot(s, e.plot[i], i);
29
29
  else
30
- await r.plot.resolvePlot(i, e.plot);
31
- o = i;
30
+ await o.plot.resolvePlot(s, e.plot);
31
+ r = s;
32
32
  }
33
- function a(i) {
34
- return console.log("Spec to update", i), new Promise((l) => {
35
- l();
33
+ function l(s) {
34
+ return console.log("Spec to update", s), new Promise((i) => {
35
+ i();
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() {
42
- return o;
41
+ return { run: n, updatedSpec: l, destroy: a, get context() {
42
+ return r;
43
43
  } };
44
44
  }
45
- function z(t) {
45
+ function ot(t) {
46
46
  return t === void 0 ? [] : Array.isArray(t) ? t : [t];
47
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)}.`);
48
+ function to(t) {
49
+ const e = t.layout ?? {}, o = e.type ?? "vertical";
50
+ if (o !== "vertical" && o !== "horizontal" && o !== "grid")
51
+ throw new Error(`Layout type must be vertical, horizontal or grid, not ${JSON.stringify(o)}.`);
52
+ const r = e.gap ?? 0;
53
+ if (typeof r != "number" || !Number.isFinite(r) || r < 0)
54
+ throw new Error(`Layout gap must be a number of pixels, 0 or more, not ${JSON.stringify(r)}.`);
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) => ({
62
- kind: l,
58
+ const l = [
59
+ ...ot(t.map).map((i, u) => ({ kind: "map", index: u, id: i.id, key: i.id ?? u })),
60
+ ...ot(t.plot).map((i, u) => ({ kind: "plot", index: u, id: i.id, key: i.id ?? i.dataRef }))
61
+ ], a = o === "vertical" ? 1 : o === "horizontal" ? Math.max(l.length, 1) : n, s = l.map(({ kind: i, index: u, id: d, key: c }, f) => ({
62
+ kind: i,
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: o, rows: Math.ceil(l.length / a), columns: a, gap: r, panes: s };
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;
74
- t.getCurrentWorkspace() !== r && await t.setWorkspace(r);
71
+ var Ht = /* @__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))(Ht || {}), wt = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(wt || {});
72
+ async function P(t, e) {
73
+ const o = e ?? G;
74
+ t.getCurrentWorkspace() !== o && await t.setWorkspace(o);
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 === G ? e : `${t}/${e}`;
78
78
  }
79
- function ft(t) {
79
+ const bt = /* @__PURE__ */ new WeakMap();
80
+ function Jt(t, e) {
81
+ bt.set(t, e);
82
+ }
83
+ function qt(t, e) {
84
+ const o = t && bt.get(t);
85
+ return o !== void 0 && o.toUpperCase() === e.toUpperCase() ? t : void 0;
86
+ }
87
+ function Et(t) {
80
88
  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
+ for (const r of t)
90
+ r?.id != null && e.add(JSON.stringify(r.id));
91
+ const o = /* @__PURE__ */ new Set();
92
+ return t.map((r, n) => {
93
+ if (r?.id != null) return r.id;
94
+ let l = `autk-feature-${n}`;
95
+ for (; e.has(JSON.stringify(l)) || o.has(JSON.stringify(l)); ) l = `${l}-generated`;
96
+ return o.add(JSON.stringify(l)), l;
89
97
  });
90
98
  }
91
- function pt(t) {
99
+ function _t(t) {
92
100
  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}`;
101
+ return Et(t).map((o) => {
102
+ const r = JSON.stringify(o), n = e.get(r) ?? 0;
103
+ return e.set(r, n + 1), n === 0 ? r : `${r} ${n}`;
96
104
  });
97
105
  }
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);
106
+ const rt = /* @__PURE__ */ new WeakMap();
107
+ function Kt(t) {
108
+ let e = rt.get(t);
109
+ return e || (e = /* @__PURE__ */ new Map(), t.forEach((o, r) => {
110
+ const n = e.get(o);
111
+ n ? n.push(r) : e.set(o, [r]);
112
+ }), rt.set(t, e), e);
113
+ }
114
+ function D(t, e, o) {
115
+ const r = Kt(o), n = /* @__PURE__ */ new Set();
116
+ for (const l of t) {
117
+ const a = e[l];
118
+ if (a !== void 0)
119
+ for (const s of r.get(a) ?? []) n.add(s);
112
120
  }
113
121
  return [...n];
114
122
  }
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;
123
+ const zt = { type: "GeometryCollection", geometries: [] };
124
+ function Xt(t) {
125
+ const e = t.features ?? [], o = Et(e);
126
+ let r = !1;
127
+ const n = e.map((a, s) => a == null || a.id != null && a.geometry != null ? a : (r = !0, { ...a, id: o[s], geometry: a.geometry ?? zt })), l = e.findIndex((a) => a?.geometry != null);
128
+ return l > 0 && e[0] != null && e[0].geometry == null && ([n[0], n[l]] = [n[l], n[0]], r = !0), r ? { ...t, features: n } : t;
121
129
  }
122
- function Ft(t) {
130
+ function Zt(t) {
123
131
  const { queryArea: e } = t;
124
132
  if (e.bbox === void 0) return { geocodeArea: e.geocodeArea, areas: e.areas };
125
- const r = (l) => new Error(`OSM source "${t.outputTableName}": ${l}`);
133
+ const o = (i) => new Error(`OSM source "${t.outputTableName}": ${i}`);
126
134
  if (e.geocodeArea !== void 0 || e.areas !== void 0)
127
- throw r("queryArea takes either bbox or geocodeArea with areas, not both.");
128
- const o = e.bbox;
129
- if (!Array.isArray(o) || o.length !== 4 || !o.every((l) => typeof l == "number" && Number.isFinite(l)))
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)
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)
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] };
141
- }
142
- function Bt(t) {
143
- const { autoLoadLayers: e, ...r } = t;
144
- return { ...r, queryArea: Ft(t), autoLoadLayers: { layers: e?.layers ?? [] } };
145
- }
146
- function tt(t) {
135
+ throw o("queryArea takes either bbox or geocodeArea with areas, not both.");
136
+ const r = e.bbox;
137
+ if (!Array.isArray(r) || r.length !== 4 || !r.every((i) => typeof i == "number" && Number.isFinite(i)))
138
+ throw o("queryArea.bbox must hold four numbers, [west, south, east, north] in degrees.");
139
+ const [n, l, a, s] = e.bbox;
140
+ if (Math.abs(n) > 180 || Math.abs(a) > 180)
141
+ throw o("queryArea.bbox west and east must be longitudes from -180 to 180.");
142
+ if (Math.abs(l) > 90 || Math.abs(s) > 90)
143
+ throw o("queryArea.bbox south and north must be latitudes from -90 to 90.");
144
+ if (n >= a)
145
+ throw o(`queryArea.bbox west (${n}) must be less than east (${a}); a box across the antimeridian is not supported.`);
146
+ if (l >= s)
147
+ throw o(`queryArea.bbox south (${l}) must be less than north (${s}).`);
148
+ return { bbox: [n, l, a, s] };
149
+ }
150
+ function te(t) {
151
+ const { autoLoadLayers: e, ...o } = t;
152
+ if (t.pbfFileUrl !== void 0 && (t.tagSets?.length ?? 0) > 0)
153
+ throw new Error(`OSM source "${t.outputTableName}": tagSets are read from the Overpass API only, so a source with pbfFileUrl cannot take them.`);
154
+ return {
155
+ ...o,
156
+ queryArea: Zt(t),
157
+ autoLoadLayers: {
158
+ layers: e?.layers ?? [],
159
+ ...e?.coordinateFormat !== void 0 && { coordinateFormat: e.coordinateFormat }
160
+ }
161
+ };
162
+ }
163
+ function nt(t) {
147
164
  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
165
  }
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);
166
+ function Q(t) {
167
+ return t === void 0 || t === G ? "the default workspace" : `the workspace "${t}"`;
168
+ }
169
+ function at(t) {
170
+ if (t != null)
171
+ return typeof t == "string" ? t : JSON.stringify(t);
172
+ }
173
+ async function ee(t, e, o, r) {
174
+ const n = /* @__PURE__ */ new Map();
175
+ for (const s of (await t.getLayer(e.name)).features) {
176
+ const i = at(s.properties?.[r]);
177
+ if (i !== void 0) {
178
+ if (s.id === void 0 || s.id === null)
179
+ throw new Error("its rows have no feature id to update them by.");
180
+ n.set(i, [...n.get(i) ?? [], s.id]);
181
+ }
182
+ }
183
+ const l = o.features.flatMap((s) => {
184
+ const i = at(s.properties?.[r]);
185
+ return i === void 0 ? [] : (n.get(i) ?? []).map((u) => ({ ...s, id: u }));
186
+ }), a = e.columns.some((s) => s.name === "geojson_id") ? "geojson_id" : "id";
187
+ return { data: { ...o, features: l }, idColumn: a };
188
+ }
189
+ async function it(t) {
190
+ if (t) return t;
191
+ const e = new Gt();
192
+ return await e.init(), e;
193
+ }
194
+ function vt(t) {
195
+ let e = 1 / 0, o = 1 / 0, r = -1 / 0, n = -1 / 0;
196
+ const l = (s) => {
197
+ if (Array.isArray(s)) {
198
+ if (typeof s[0] == "number") {
199
+ const [i, u] = s;
200
+ i < e && (e = i), i > r && (r = i), u < o && (o = u), u > n && (n = u);
156
201
  return;
157
202
  }
158
- for (const l of i) a(l);
203
+ for (const i of s) l(i);
159
204
  }
160
- }, s = (i) => {
161
- i && (i.type === "GeometryCollection" ? i.geometries.forEach(s) : a(i.coordinates));
205
+ }, a = (s) => {
206
+ s && (s.type === "GeometryCollection" ? s.geometries.forEach(a) : l(s.coordinates));
162
207
  };
163
- for (const i of t.features ?? []) s(i?.geometry);
164
- return e <= o ? [e, r, o, n] : void 0;
208
+ for (const s of t.features ?? []) a(s?.geometry);
209
+ return e <= r ? [e, o, r, n] : void 0;
165
210
  }
166
- function xt(t, e) {
167
- function r(o, n) {
168
- if (!n || !n.db)
211
+ function oe(t, e) {
212
+ function o(n, l) {
213
+ if (!l || !l.db)
169
214
  return;
170
- const a = document.getElementById(n.db);
215
+ const a = document.getElementById(l.db);
171
216
  if (a) {
172
- const s = o.getTablesMetadata();
217
+ const s = n.getTablesMetadata();
173
218
  a.innerHTML += "<ul>";
174
219
  for (const i of s)
175
220
  a.innerHTML += `<li>${i.name}: (${i.source}, ${i.type}) </li>`;
176
221
  a.innerHTML += "</ul>", a.innerHTML += `<p>Number of tables: ${s.length}</p>`;
177
222
  }
178
223
  }
224
+ async function r(n, l, a) {
225
+ if (!e) return;
226
+ const s = b(l, a), i = n.getTablesMetadata().find((u) => u.name === a);
227
+ i && yt(i) ? e.set(s, await n.getLayer(a)) : e.delete(s);
228
+ }
179
229
  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;
230
+ async resolveWorkspaces(n, l) {
231
+ const a = await it(n), s = /* @__PURE__ */ new Set();
232
+ for (const { name: i, coordinateFormat: u, precisionGrid: d } of l) {
233
+ const c = i ?? G;
234
+ if (s.has(c))
235
+ throw new Error(`workspaces sets ${Q(i)} twice; give each workspace one entry.`);
236
+ s.add(c);
237
+ try {
238
+ await a.setWorkspace(c, { coordinateFormat: u, precisionGrid: d });
239
+ } catch (f) {
240
+ throw new Error(`workspaces, ${Q(i)}: ${f instanceof Error ? f.message : String(f)}`);
241
+ }
242
+ }
243
+ return await P(a), a;
244
+ },
245
+ async resolveSource(n, l) {
246
+ const a = await it(n), { workspace: s } = l;
247
+ await P(a, s);
248
+ let { type: i, workspace: u, ...d } = l;
186
249
  switch (i) {
187
250
  case "osm":
188
- return await a.loadOsm(Bt(u)), r(a, t), a;
251
+ return await a.loadOsm(te(d)), o(a, t), a;
189
252
  case "csv":
190
- return await a.loadCsv(u), r(a, t), a;
253
+ return await a.loadCsv(d), o(a, t), a;
191
254
  case "json":
192
- return await a.loadJson(u), r(a, t), a;
255
+ return await a.loadJson(d), o(a, t), a;
193
256
  case "geojson": {
194
- const c = u;
257
+ const c = d;
195
258
  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))
259
+ c.geojsonFileUrl ? f = await (await fetch(c.geojsonFileUrl)).json() : f = c.geojsonObject, e && f && (e.set(b(s, c.outputTableName), f), Jt(f, c.coordinateFormat ?? "EPSG:4326"));
260
+ const m = f ? (() => {
261
+ const p = { ...c, geojsonObject: Xt(f) };
262
+ return delete p.geojsonFileUrl, p;
263
+ })() : c, h = /^EPSG:4326$/i.test(m.coordinateFormat ?? "EPSG:4326"), y = f && h ? vt(f) : void 0;
264
+ if (y && (y[1] < -90 || y[3] > 90))
202
265
  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)}`
266
+ `GeoJSON layer "${m.outputTableName}" has y coordinates outside -90 to 90 (bbox: [${y.join(", ")}]), so they cannot be EPSG:4326 degrees. ${nt(m.coordinateFormat)}`
204
267
  );
205
268
  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)}`);
269
+ await a.loadGeojson(m);
270
+ } catch (p) {
271
+ throw new Error(`Failed to load GeoJSON layer "${m.outputTableName}": ${p instanceof Error ? p.message : String(p)}`);
209
272
  }
210
273
  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)
274
+ const p = await a.getBoundingBoxFromLayer(m.outputTableName), g = 25e6;
275
+ if (!isFinite(p.minLon) || !isFinite(p.minLat) || !isFinite(p.maxLon) || !isFinite(p.maxLat) || Math.abs(p.minLon) > g || Math.abs(p.maxLon) > g || Math.abs(p.minLat) > g || Math.abs(p.maxLat) > g)
213
276
  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.`
277
+ `Geometry bounding box after transform is invalid for layer "${m.outputTableName}" (bbox: [${p.minLon}, ${p.minLat}, ${p.maxLon}, ${p.maxLat}]). ${nt(m.coordinateFormat)} The workspace uses ${a.getWorkspaceConfiguration().coordinateFormat}; input is expected in EPSG:4326 by default.`
215
278
  );
216
- } catch (m) {
217
- if (m instanceof Error && m.message.includes("bounding box after transform")) throw m;
279
+ } catch (p) {
280
+ if (p instanceof Error && p.message.includes("bounding box after transform")) throw p;
218
281
  }
219
- return r(a, t), a;
282
+ return o(a, t), a;
220
283
  }
221
284
  case "geotiff":
222
- return await a.loadGeoTiff(u), r(a, t), a;
285
+ return await a.loadGeoTiff(d), o(a, t), a;
223
286
  case "heatmap": {
224
- const c = u;
287
+ const c = d;
225
288
  if (c.groupBy?.some((f) => f.aggregateFn === "collect"))
226
289
  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
290
  return await a.buildHeatmap({
@@ -230,10 +293,10 @@ function xt(t, e) {
230
293
  outputTableName: c.outputTableName,
231
294
  grid: c.grid,
232
295
  ...c.groupBy && { groupBy: c.groupBy }
233
- }), r(a, t), a;
296
+ }), o(a, t), a;
234
297
  }
235
298
  case "join": {
236
- const c = u;
299
+ const c = d;
237
300
  if (await a.spatialQuery({
238
301
  tableRootName: c.dataRef,
239
302
  tableJoinName: c.joinDataRef,
@@ -241,246 +304,403 @@ function xt(t, e) {
241
304
  ...c.groupBy && { groupBy: c.groupBy }
242
305
  }), e) {
243
306
  const f = await a.getLayer(c.dataRef);
244
- e.set(A(s, c.dataRef), f);
307
+ e.set(b(s, c.dataRef), f);
308
+ }
309
+ return o(a, t), a;
310
+ }
311
+ case "sql": {
312
+ const c = d;
313
+ try {
314
+ await a.rawQuery({
315
+ query: c.query,
316
+ output: {
317
+ type: "CREATE_TABLE",
318
+ tableName: c.outputTableName,
319
+ source: "user",
320
+ ...c.layerType !== void 0 && { tableType: c.layerType }
321
+ }
322
+ });
323
+ } catch (f) {
324
+ throw new Error(`SQL source "${c.outputTableName}": ${f instanceof Error ? f.message : String(f)}`);
325
+ }
326
+ return e?.delete(b(s, c.outputTableName)), o(a, t), a;
327
+ }
328
+ case "update": {
329
+ const c = d, f = (y) => new Error(`Update of "${c.dataRef}": ${y}`);
330
+ if (c.geojsonObject === void 0 == (c.jsonObject === void 0))
331
+ throw f("give its rows in geojsonObject or in jsonObject, one of the two.");
332
+ if (c.strategy === "update" && !c.idColumn)
333
+ throw f("the update strategy needs an idColumn, the column that matches a given row to the table's rows.");
334
+ let m = c.geojsonObject ?? c.jsonObject, h = c.idColumn;
335
+ try {
336
+ const y = a.getTablesMetadata().find((p) => p.name === c.dataRef);
337
+ if (c.strategy === "update" && c.geojsonObject && h?.startsWith("properties.") && y && Dt(y) && ({ data: m, idColumn: h } = await ee(a, y, c.geojsonObject, h.slice(11)), m.features.length === 0))
338
+ return o(a, t), a;
339
+ await a.updateTable({
340
+ tableName: c.dataRef,
341
+ data: m,
342
+ strategy: c.strategy,
343
+ ...h !== void 0 && { idColumn: h }
344
+ });
345
+ } catch (y) {
346
+ throw f(y instanceof Error ? y.message : String(y));
245
347
  }
246
- return r(a, t), a;
348
+ return await r(a, s, c.dataRef), o(a, t), a;
349
+ }
350
+ case "drop": {
351
+ const c = d;
352
+ if (!a.getTablesMetadata().some((f) => f.name === c.dataRef))
353
+ throw new Error(`Drop of "${c.dataRef}": ${Q(s)} holds no table of that name.`);
354
+ return await a.removeLayer(c.dataRef), e?.delete(b(s, c.dataRef)), o(a, t), a;
247
355
  }
248
356
  default:
249
- return;
357
+ throw new Error(`Unknown data source type "${String(i)}".`);
250
358
  }
251
359
  }
252
360
  };
253
361
  }
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;
362
+ function Mt(t, e) {
363
+ return e === !0 ? `${t} osm-elements` : t;
258
364
  }
259
- function ht(t, e) {
365
+ function At(t) {
366
+ return t === !0 ? { osmElements: !0 } : void 0;
367
+ }
368
+ function Ct(t, e, o) {
369
+ if (!t) return o();
370
+ let r = t.get(e);
371
+ return r || (r = o(), t.set(e, r)), r;
372
+ }
373
+ function St(t, e) {
260
374
  return t?.id ?? e;
261
375
  }
262
- function G(t, e) {
376
+ function W(t, e) {
263
377
  return e === void 0 ? !0 : typeof e == "number" ? t.mapIndex === e : t.mapId === e;
264
378
  }
265
- function yt(t, e, r) {
266
- const o = t?.get(e) ?? [];
267
- o.includes(r) || t?.set(e, [...o, r]);
379
+ function Rt(t, e, o) {
380
+ const r = t?.get(e) ?? [];
381
+ r.includes(o) || t?.set(e, [...r, o]);
268
382
  }
269
- const gt = 6378137, j = 0.0818191908426215;
270
- function kt(t, e) {
383
+ const It = 6378137, V = 0.0818191908426215;
384
+ function re(t, e) {
271
385
  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;
386
+ const o = typeof t == "number" ? String(t) : JSON.stringify(t);
387
+ throw new Error(`Layer "${e}": pointSize must be a number of meters greater than 0, not ${o}.`);
388
+ }
389
+ function ne(t) {
390
+ const e = Math.exp(-t / It);
391
+ let o = Math.PI / 2 - 2 * Math.atan(e);
392
+ for (let r = 0; r < 10; r++) {
393
+ const n = V * Math.sin(o), l = Math.PI / 2 - 2 * Math.atan(e * ((1 - n) / (1 + n)) ** (V / 2));
394
+ if (Math.abs(l - o) < 1e-12) return l;
395
+ o = l;
282
396
  }
283
- return r;
397
+ return o;
284
398
  }
285
- function Dt(t, e) {
399
+ function ae(t, e) {
286
400
  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);
401
+ const o = ne(e), r = V * Math.sin(o);
402
+ return Math.sqrt(1 - r * r) / Math.cos(o);
289
403
  }
290
- return /^EPSG:3857$/i.test(t) ? Math.cosh(e / gt) : 1;
404
+ return /^EPSG:3857$/i.test(t) ? Math.cosh(e / It) : 1;
291
405
  }
292
- function jt(t, e, r, o) {
406
+ function ie(t, e, o, r) {
293
407
  if (t === void 0 || e !== "points") return;
294
- const n = o();
408
+ const n = r();
295
409
  if (n)
296
- return t * Dt(r, (n[1] + n[3]) / 2);
410
+ return t * ae(o, (n[1] + n[3]) / 2);
411
+ }
412
+ const $t = /^#[0-9a-fA-F]{6}$/;
413
+ function Pt(t, e) {
414
+ if (t === void 0) return;
415
+ if (!Array.isArray(t) || t.length !== 2 || !t.every((n) => typeof n == "number" && Number.isFinite(n)))
416
+ return "colorMapRange must hold two numbers, [low, high].";
417
+ const [o, r] = t;
418
+ if (o >= r)
419
+ return `colorMapRange low (${o}) must be less than high (${r}).`;
420
+ if (e !== void 0)
421
+ return "set colorMapRange or colorMapDomain, not both.";
422
+ }
423
+ function Lt(t, e) {
424
+ return e && e.length > 0 ? { type: $.USER, params: e } : t?.mode === wt.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
425
+ type: $.PERCENTILE,
426
+ params: [t.lowerPercentile ?? 0, t.upperPercentile ?? 100]
427
+ } : { type: $.PERCENTILE } : { type: $.MIN_MAX };
297
428
  }
298
- function S(t) {
429
+ function R(t) {
299
430
  return typeof t.title == "string" && t.title !== "" ? t.title : t.dataRef;
300
431
  }
301
- function Ut(t, e) {
302
- const r = /* @__PURE__ */ new Set();
303
- for (const o of t.layerRefs) {
304
- const n = S(o);
305
- if (r.has(n))
432
+ function se(t, e) {
433
+ const o = /* @__PURE__ */ new Set();
434
+ for (const r of t.layerRefs) {
435
+ const n = R(r);
436
+ if (o.has(n))
306
437
  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
- r.add(n);
438
+ o.add(n);
308
439
  }
309
440
  }
310
- const Qt = /^#[0-9a-fA-F]{6}$/;
311
- function et(t, e, r) {
312
- if (!Qt.test(t))
313
- throw new Error(`Layer "${r}": ${e} must be a color written #rrggbb, not "${t}".`);
314
- return B.hexToRgb(t);
441
+ function st(t, e, o) {
442
+ if (!$t.test(t))
443
+ throw new Error(`Layer "${o}": ${e} must be a color written #rrggbb, not "${t}".`);
444
+ return N.hexToRgb(t);
315
445
  }
316
- function Yt(t, e) {
317
- 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;
446
+ function le(t, e) {
447
+ const o = {};
448
+ return t.color != null && (o.color = st(t.color, "color", e)), t.stroke === !1 ? o.showBorders = !1 : t.stroke != null && (o.strokeColor = st(t.stroke, "stroke", e)), t.width != null && (o.polylinesWidth = t.width), o;
319
449
  }
320
- function Vt(t, e) {
450
+ function ue(t, e) {
321
451
  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
452
  }
323
- function Ht(t, e) {
324
- const r = t.features?.[0]?.properties?.[e];
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;
453
+ function ce(t, e) {
454
+ const o = t.features?.[0]?.properties?.[e];
455
+ return o instanceof Float32Array ? o : ArrayBuffer.isView(o) && !(o instanceof DataView) || Array.isArray(o) ? Float32Array.from(o, (r) => Number.isFinite(Number(r)) ? Number(r) : NaN) : null;
326
456
  }
327
- function Wt(t, e, r, o, n) {
328
- if (B.isCategorical(e.interpolator)) return;
457
+ function fe(t, e, o, r, n) {
458
+ if (N.isCategorical(e.interpolator)) return;
329
459
  if (n != null) {
330
- const u = r != null ? [n[0], r, n[1]] : [n[0], n[1]];
331
- return o === !0 ? u.reverse() : u;
460
+ const u = o != null ? [n[0], o, n[1]] : [n[0], n[1]];
461
+ return r === !0 ? u.reverse() : u;
332
462
  }
333
463
  if (!t) return;
334
- let a = 0, s = 0;
464
+ let l = 0, a = 0;
335
465
  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))));
466
+ const d = t[u];
467
+ Number.isFinite(d) && (a++, o != null && (l = Math.max(l, Math.abs(d - o))));
338
468
  }
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);
342
- return o === !0 ? [...l].reverse() : l;
469
+ const s = o != null && l > 0;
470
+ if (a === 0 || !s && r !== !0) return;
471
+ const i = s && o != null ? [o - l, o, o + l] : N.resolveDomainFromData(t, e);
472
+ return r === !0 ? [...i].reverse() : i;
343
473
  }
344
- function Jt(t, e) {
345
- if (!(e == null || B.isCategorical(t.interpolator)))
474
+ function de(t, e) {
475
+ if (!(e == null || N.isCategorical(t.interpolator)))
346
476
  return [e[0], e[1]];
347
477
  }
348
- function qt(t) {
478
+ function pe(t) {
349
479
  const e = t.colorMapRange;
350
480
  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)))
353
- throw r("colorMapRange must hold two numbers, [low, high].");
354
- const [o, n] = e;
355
- if (o >= n)
356
- throw r(`colorMapRange low (${o}) must be less than high (${n}).`);
357
- if (t.colorMapDomain !== void 0)
358
- 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}].`);
362
- }
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,
366
- params: [t.lowerPercentile ?? 0, t.upperPercentile ?? 100]
367
- } : { type: I.PERCENTILE } : { type: I.MIN_MAX };
368
- }
369
- function Xt(t, e) {
370
- return e.split(".").reduce((r, o) => {
371
- if (!(r == null || typeof r != "object"))
372
- return r[o];
481
+ const o = (s) => new Error(`Layer "${R(t)}": ${s}`), r = Pt(e, t.colorMapDomain);
482
+ if (r)
483
+ throw o(r);
484
+ const [n, l] = e, a = t.colorMapCenter;
485
+ if (a != null && (a < n || a > l))
486
+ throw o(`colorMapCenter (${a}) must lie within colorMapRange [${n}, ${l}].`);
487
+ }
488
+ function me(t, e) {
489
+ return e.split(".").reduce((o, r) => {
490
+ if (!(o == null || typeof o != "object"))
491
+ return o[r];
373
492
  }, t);
374
493
  }
375
- function zt(t, e, r) {
376
- 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;
494
+ function he(t, e, o) {
495
+ const r = e.split("."), n = { ...t };
496
+ let l = n;
497
+ for (let a = 0; a < r.length - 1; a++)
498
+ l[r[a]] = { ...l[r[a]] ?? {} }, l = l[r[a]];
499
+ return l[r[r.length - 1]] = o, n;
381
500
  }
382
- function Zt(t, e) {
383
- 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 ?? "";
501
+ function ye(t, e) {
502
+ const r = t.features?.[0]?.properties?.bands ?? [];
503
+ return r.find((l) => l.id === e || l.label === e?.replace(/\./g, "_"))?.id ?? r[0]?.id ?? e ?? "";
385
504
  }
386
- function te(t, e) {
505
+ function Nt(t) {
506
+ const { pitch: e } = t;
507
+ 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.`;
508
+ }
509
+ function ge(t, e) {
510
+ const o = Nt(e);
511
+ if (o) throw new Error(o);
387
512
  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),
513
+ const r = t.camera, [n, l] = 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, u = [
514
+ n - a * Math.sin(s) * Math.sin(i),
515
+ l - a * Math.sin(s) * Math.cos(i),
391
516
  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) {
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;
517
+ ], d = [Math.cos(s) * Math.sin(i), Math.cos(s) * Math.cos(i), Math.sin(s)];
518
+ r.resetCamera(d, [n, l, 0], u);
519
+ }
520
+ function we(t, e, o, r) {
521
+ const l = t.layerManager.searchByLayerId(e)?.components;
522
+ return Array.isArray(l) ? l.map((a, s) => {
523
+ const i = Number.isInteger(a?.featureIndex) ? a.featureIndex : s;
524
+ return o[r[i]] ?? "";
525
+ }) : r.map((a) => o[a] ?? "");
526
+ }
527
+ function be(t, e, o, r, n, l) {
528
+ async function a(s, i, u) {
529
+ let d = {};
530
+ for (const f of i.getTablesMetadata())
531
+ f.type !== void 0 && (d[f.name] = f.type);
532
+ const c = [];
533
+ for (const f of u.layerRefs) {
534
+ const m = f.dataRef, h = R(f), y = b(u.workspace, m), p = n?.get(y) ?? d[m], g = f.getFnv, E = o?.get(y) ?? (p === "raster" ? await i.getRaster(m) : await Ct(l, Mt(y, f.osmElements), () => i.getLayer(m, At(f.osmElements)))), _ = E.features ?? [], I = p === "raster" ? [] : _.flatMap((w, v) => w?.geometry != null ? [v] : []), C = p === "raster" ? E : { ...E, features: I.map((w) => _[w]) }, H = p === "raster" ? ye(C, g) : "";
535
+ p === "raster" ? s.loadCollection(h, { collection: C, type: "raster", property: H }) : s.loadCollection(h, { collection: C, type: p }), f.opacity != null && s.updateRenderInfo(h, { opacity: f.opacity });
536
+ const J = le(f, h);
537
+ Object.keys(J).length > 0 && s.updateRenderInfo(h, J);
538
+ const jt = i.getWorkspaceConfiguration().coordinateFormat, q = ie(f.pointSize, p, jt, () => vt(C));
539
+ q !== void 0 && s.updateRenderInfo(h, { pointSize: q }), ue(f, p) && s.updateRenderInfo(h, { isColorMap: !0 }), f.isPick && s.updateRenderInfo(h, { isPick: !0 }), f.isSkip && s.updateRenderInfo(h, { isSkip: !0 });
540
+ const { catchAllCategory: T, colorMapDomain: L } = f;
541
+ let K = C, z = L;
542
+ if (g && T && L?.length) {
543
+ const w = new Set(L);
544
+ K = {
545
+ ...C,
546
+ features: C.features.map((v) => {
547
+ const tt = v.properties, U = me(tt, g);
548
+ return U == null || !w.has(String(U)) ? { ...v, properties: he(tt, g, T) } : v;
424
549
  })
425
- }, W = w.has(T) ? C : [...C, T];
550
+ }, z = w.has(T) ? L : [...L, T];
426
551
  }
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 || $) {
552
+ const X = p === "raster" && f.transferFunction != null;
553
+ X && s.layerManager.searchByLayerId(h)?.setTransferFunction?.(f.transferFunction);
554
+ const O = f.colorMapRange, Z = p === "raster" && (O != null || f.colorMapCenter != null || f.colorMapReverse === !0);
555
+ if (f.colorMapInterpolator || Z || O) {
431
556
  const w = {
432
557
  // urban-grammar ColorMapInterpolator values are string-compatible
433
558
  // 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)
559
+ interpolator: f.colorMapInterpolator ?? s.layerManager.searchByLayerId(h)?.layerRenderInfo.colormap.config.interpolator ?? gt.SEQ_REDS,
560
+ domainSpec: Lt(f.normalization, z)
436
561
  };
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") {
562
+ let v;
563
+ Z ? v = fe(ce(C, H), w, f.colorMapCenter, f.colorMapReverse, O) : p !== "raster" && (v = de(w, O)), v && (w.domainSpec = { type: $.USER, params: v }), s.updateColorMap(h, { colorMap: w });
564
+ } else X && s.updateColorMap(h, { colorMap: {} });
565
+ if (g && p !== "raster") {
441
566
  const w = g.startsWith("properties.") ? g : `properties.${g}`;
442
- i.updateThematic(d, { collection: H, property: w });
567
+ s.updateThematic(h, { collection: K, property: w });
443
568
  }
444
- f.push(h === "raster" ? [] : ee(i, d, pt(b), U));
569
+ c.push(p === "raster" ? [] : we(s, h, _t(_), I));
445
570
  }
446
- return f;
571
+ return c;
447
572
  }
448
573
  return {
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));
574
+ async resolveMap(s, i, u = 0) {
575
+ if (t && t.map && s) {
576
+ se(i, u);
577
+ for (const y of i.layerRefs)
578
+ pe(y), re(y.pointSize, R(y));
579
+ const d = i.camera && Nt(i.camera);
580
+ if (d)
581
+ throw new Error(`Map ${u}: ${d}`);
454
582
  let c;
455
583
  if (Array.isArray(t.map) ? c = document.getElementById(t.map[u]) : c = document.getElementById(t.map), !c)
456
584
  throw new Error("Could not find rendering target for map: " + t.map);
457
585
  if (!(c instanceof HTMLCanvasElement))
458
586
  throw new Error("Target for map is not a canvas: " + t.map);
459
- const f = new Ct(c);
460
- let p;
587
+ const f = new Qt(c);
588
+ let m;
461
589
  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) {
590
+ i.style && f.style.setPredefinedStyle(i.style), await f.init(), await P(s, i.workspace), m = await a(f, s, i);
591
+ } catch (y) {
464
592
  try {
465
593
  f.destroy();
466
594
  } catch {
467
595
  }
468
- throw d;
596
+ throw y;
469
597
  }
470
- const y = ht(l, u);
471
- l.layerRefs.forEach((d, m) => e?.push({
598
+ const h = St(i, u);
599
+ i.layerRefs.forEach((y, p) => e?.push({
472
600
  map: f,
473
601
  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();
602
+ mapId: h,
603
+ layerId: R(y),
604
+ dataRef: y.dataRef,
605
+ rows: m[p]
606
+ })), r && (r[u] = f), i.camera && ge(f, i.camera), f.draw();
479
607
  }
480
608
  }
481
609
  };
482
610
  }
483
- function oe(t) {
611
+ function A(t) {
612
+ return t.id ?? t.dataRef;
613
+ }
614
+ const Ee = new Set(Object.values(gt));
615
+ function lt(t, e, o) {
616
+ if (e !== void 0) {
617
+ if (typeof e != "string" || !Ee.has(e)) return `${t} ${JSON.stringify(e)} is not a color scheme.`;
618
+ if (N.isCategorical(e) !== o)
619
+ return o ? `${t} "${e}" is not a categorical scheme: categories take a scheme* scheme, such as schemeTableau10.` : `${t} "${e}" is a categorical scheme: numbers take an interpolate* scheme, and categories take categoricalColorMapInterpolator.`;
620
+ }
621
+ }
622
+ const _e = /^(?:.?[<>=^])?[-+( ]?[$#]?0?\d*,?(?:\.\d+)?~?[a-zA-Z%]?$/;
623
+ function ve(t) {
624
+ if (t === void 0) return;
625
+ if (!Array.isArray(t) || t.length !== 2)
626
+ return "tickFormats must hold two d3-format specifiers, [x, y].";
627
+ const e = t.findIndex((o) => typeof o != "string" || !_e.test(o));
628
+ if (e >= 0)
629
+ return `tickFormats[${e}] ${JSON.stringify(t[e])} is not a d3-format specifier, such as "~s", ",d" or ".0%".`;
630
+ }
631
+ function Me(t, e) {
632
+ if (t === void 0) return;
633
+ if (!Array.isArray(t) || !t.every((r) => typeof r == "string"))
634
+ return "axisLabels must be a list of titles, one for each column of axis.";
635
+ if (t.length > e.length)
636
+ return `axisLabels has ${t.length} titles for the ${e.length} columns of axis.`;
637
+ const o = t.find((r, n) => t.indexOf(r) !== n);
638
+ if (o !== void 0)
639
+ return `axisLabels gives two axes the title ${JSON.stringify(o)}.`;
640
+ }
641
+ function ut(t, e) {
642
+ if (!(e === void 0 || typeof e == "string" && $t.test(e)))
643
+ return `${t} must be a color written #rrggbb, not ${JSON.stringify(e)}.`;
644
+ }
645
+ function Ae(t) {
646
+ if (t !== void 0 && (!Array.isArray(t) || !t.every((e) => Number.isInteger(e) && e >= 0)))
647
+ return "selection must list the positions of rows, whole numbers from 0.";
648
+ }
649
+ function Ce(t) {
650
+ const e = lt("colorMapInterpolator", t.colorMapInterpolator, !1) ?? lt("categoricalColorMapInterpolator", t.categoricalColorMapInterpolator, !0) ?? Pt(t.colorMapRange, t.colorMapDomain) ?? ve(t.tickFormats) ?? Me(t.axisLabels, t.axis) ?? Ae(t.selection) ?? ut("markColor", t.markColor) ?? ut("highlightColor", t.highlightColor);
651
+ if (e) throw new Error(`Plot "${A(t)}": ${e}`);
652
+ }
653
+ function Se(t) {
654
+ const e = {};
655
+ for (const [o, r] of [["markColor", "mark"], ["highlightColor", "highlight"]]) {
656
+ let n;
657
+ for (const l of t) {
658
+ const a = l[o];
659
+ if (a !== void 0) {
660
+ if (n && n[o].toLowerCase() !== a.toLowerCase())
661
+ throw new Error(`Plots "${A(n)}" and "${A(l)}" set different ${o} values, "${n[o]}" and "${a}": autk-plot draws every plot of a page in one ${r} color.`);
662
+ n ??= l;
663
+ }
664
+ }
665
+ n && (e[o] = n[o]);
666
+ }
667
+ return e;
668
+ }
669
+ function Re(t, e) {
670
+ const o = t.selection?.find((r) => r >= e);
671
+ if (o !== void 0)
672
+ throw new Error(`Plot "${A(t)}": selection names row ${o}, but the plot draws ${e === 1 ? "1 row" : `${e} rows`}.`);
673
+ }
674
+ function Ie(t, e) {
675
+ return t === void 0 || t === "@transform" ? !1 : e.some((o) => {
676
+ const r = Yt(o?.properties ?? {}, t);
677
+ return typeof r == "string" && isNaN(Number(r));
678
+ });
679
+ }
680
+ function $e(t, e) {
681
+ const o = t.colorMapRange;
682
+ if (o !== void 0 && !Ie(t.color, e))
683
+ return { type: $.USER, params: [o[0], o[1]] };
684
+ if (!(t.normalization === void 0 && t.colorMapDomain === void 0))
685
+ return Lt(t.normalization, t.colorMapDomain);
686
+ }
687
+ function Pe(t) {
688
+ return t.axis.map((e, o) => t.axisLabels?.[o] ?? (e === "@transform" ? "value" : e));
689
+ }
690
+ function Le(t, e) {
691
+ const o = $e(t, e);
692
+ return {
693
+ labels: { axis: Pe(t), title: t.title },
694
+ // The grammar's scheme names are autk-core's, as strings.
695
+ ...t.colorMapInterpolator !== void 0 && { colorMapInterpolator: t.colorMapInterpolator },
696
+ ...t.categoricalColorMapInterpolator !== void 0 && {
697
+ categoricalColorMapInterpolator: t.categoricalColorMapInterpolator
698
+ },
699
+ ...o && { domainSpec: o },
700
+ ...t.tickFormats !== void 0 && { tickFormats: [...t.tickFormats] }
701
+ };
702
+ }
703
+ function Ne(t) {
484
704
  return {
485
705
  scatter: "scatterplot",
486
706
  bar: "barchart",
@@ -491,245 +711,248 @@ function oe(t) {
491
711
  heatmatrix: "heatmatrix"
492
712
  }[t];
493
713
  }
494
- function L(t) {
495
- return t.id ?? t.dataRef;
714
+ let B;
715
+ function ke(t) {
716
+ t.markColor === void 0 && t.highlightColor === void 0 && !B || (B ??= { markColor: F.default, highlightColor: F.highlight }, F.setDefaultColor(t.markColor ?? B.markColor), F.setHighlightColor(t.highlightColor ?? B.highlightColor));
496
717
  }
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));
718
+ function kt(t, e, o, r) {
719
+ const { map: n, layerId: l } = r;
720
+ n.updateRenderInfo(l, { isPick: !0 }), n.events.on(Y.PICKING, ({ layerId: a, selection: s }) => {
721
+ a === l && t.setSelection(D(s, r.rows, e));
501
722
  });
502
- for (const s of r)
503
- t.events.on(s, ({ selection: i }) => {
504
- n.setHighlightedIds(a, x(i, e, o.rows));
723
+ for (const a of o)
724
+ t.events.on(a, ({ selection: s }) => {
725
+ n.setHighlightedIds(l, D(s, e, r.rows));
505
726
  });
506
727
  }
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));
728
+ async function Te(t, e, o, r, n) {
729
+ const l = t.getTablesMetadata().find((a) => a.name === e);
730
+ return l && !yt(l) ? { type: "FeatureCollection", features: (await t.getTable(e)).map((s) => ({ type: "Feature", geometry: null, properties: s })) } : Ct(r, Mt(o, n), () => t.getLayer(e, At(n)));
510
731
  }
511
- function ae(t, e, r, o, n, a, s, i) {
732
+ function Oe(t, e, o, r, n, l, a, s) {
512
733
  return {
513
- async resolvePlot(l, u, c = 0) {
734
+ async resolvePlot(i, u, d = 0) {
514
735
  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}`);
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,
736
+ const c = Array.isArray(t.plot) ? t.plot[d] : t.plot;
737
+ if (c === void 0) throw new Error(`Plot ${d} has no target: the plot targets name ${t.plot.length} elements.`);
738
+ const f = document.getElementById(c);
739
+ if (!f) throw new Error(`Could not find plot target: ${c}`);
740
+ const m = i;
741
+ if (!m) throw new Error("No data context available for plot.");
742
+ await P(m, u.workspace);
743
+ const h = b(u.workspace, u.dataRef), y = u.osmElements === !0 ? void 0 : n?.get(h), p = l?.get(h) ?? y ?? await Te(m, u.dataRef, h, s, u.osmElements);
744
+ Re(u, p.features?.length ?? 0);
745
+ const g = u.events ?? [], E = new Wt(f, {
746
+ type: Ne(u.mark),
747
+ collection: p,
525
748
  attributes: { axis: u.axis, ...u.color && { color: u.color } },
526
- labels: { axis: u.axis, title: u.title },
527
- events: h,
749
+ events: g,
750
+ ...Le(u, p.features ?? []),
528
751
  ...u.width && { width: u.width },
529
752
  ...u.height && { height: u.height },
530
753
  ...u.margins && { margins: u.margins },
531
754
  ...u.transform && { transform: u.transform }
532
755
  });
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));
756
+ u.mark === "scatter" && u.color !== void 0 && E.setSelection([]), o?.set(A(u), E);
757
+ const _ = _t(p.features ?? []);
758
+ a?.set(A(u), _);
759
+ for (const I of e ?? [])
760
+ !u.mapRef || I.dataRef !== u.mapRef || (kt(E, _, g, I), Rt(r, A(u), I));
538
761
  }
539
762
  };
540
763
  }
541
- const bt = 134217728, ie = 4, se = 32;
542
- function le(t) {
764
+ const Tt = 134217728, Fe = 4, xe = 32;
765
+ function Be(t) {
543
766
  return Array.isArray(t) ? t.join(`
544
767
  `) : t;
545
768
  }
546
- function R(t) {
769
+ function S(t) {
547
770
  return !!t && typeof t == "object" && !Array.isArray(t) && typeof t.fromFeature == "object" && t.fromFeature !== null;
548
771
  }
549
- function P(t, e) {
772
+ function k(t, e) {
550
773
  return t instanceof Map ? t.get(e) : t[e];
551
774
  }
552
- function F(t, e) {
553
- return e.split(".").reduce((r, o) => {
554
- if (!(r == null || typeof r != "object"))
555
- return r[o];
775
+ function j(t, e) {
776
+ return e.split(".").reduce((o, r) => {
777
+ if (!(o == null || typeof o != "object"))
778
+ return o[r];
556
779
  }, t);
557
780
  }
558
- function _t(t) {
781
+ function Ot(t) {
559
782
  const e = [];
560
- for (const r of [t.uniforms, t.uniformMatrices])
561
- for (const o of Object.values(r ?? {}))
562
- R(o) && e.push(o);
783
+ for (const o of [t.uniforms, t.uniformMatrices])
784
+ for (const r of Object.values(o ?? {}))
785
+ S(r) && e.push(r);
563
786
  return e;
564
787
  }
565
- function ue(t) {
566
- return [.../* @__PURE__ */ new Set([t.dataRef, ..._t(t).map((e) => e.fromFeature.layer)])];
788
+ function je(t) {
789
+ return [.../* @__PURE__ */ new Set([t.dataRef, ...Ot(t).map((e) => e.fromFeature.layer)])];
567
790
  }
568
- function Et(t) {
569
- for (const e of _t(t)) {
570
- const { iterate: r, layer: o } = e.fromFeature;
571
- if (r === "all" || r === "batched") return { mode: r, layer: o };
791
+ function Ft(t) {
792
+ for (const e of Ot(t)) {
793
+ const { iterate: o, layer: r } = e.fromFeature;
794
+ if (o === "all" || o === "batched") return { mode: o, layer: r };
572
795
  }
573
796
  return null;
574
797
  }
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;
798
+ function xt(t, e, o) {
799
+ const r = t.fromFeature, n = o !== void 0 && r.iterate === "all" ? o : r.index ?? 0, l = k(e, r.layer)?.features?.[n];
800
+ return l ? j(l, r.path) : void 0;
578
801
  }
579
- function rt(t, e, r) {
802
+ function ct(t, e, o) {
580
803
  if (!t) return;
581
- const o = {};
582
- for (const [n, a] of Object.entries(t)) {
583
- if (!R(a)) {
584
- o[n] = a;
804
+ const r = {};
805
+ for (const [n, l] of Object.entries(t)) {
806
+ if (!S(l)) {
807
+ r[n] = l;
585
808
  continue;
586
809
  }
587
- const s = Number(At(a, e, r) ?? NaN);
588
- Number.isFinite(s) ? o[n] = s : typeof a.default == "number" && (o[n] = a.default);
810
+ const a = Number(xt(l, e, o) ?? NaN);
811
+ Number.isFinite(a) ? r[n] = a : typeof l.default == "number" && (r[n] = l.default);
589
812
  }
590
- return o;
813
+ return r;
591
814
  }
592
- function ot(t, e, r) {
815
+ function ft(t, e, o) {
593
816
  if (!t) return;
594
- const o = {};
595
- for (const [n, a] of Object.entries(t)) {
596
- if (!R(a)) {
597
- o[n] = a;
817
+ const r = {};
818
+ for (const [n, l] of Object.entries(t)) {
819
+ if (!S(l)) {
820
+ r[n] = l;
598
821
  continue;
599
822
  }
600
- const s = At(a, e, r), i = Array.isArray(s) ? s : Array.isArray(a.default) ? a.default : void 0;
601
- if (!i) continue;
602
- const l = a.cols ?? (Array.isArray(i[0]) ? i[0].length : 0);
603
- l > 0 ? o[n] = { data: i, cols: l } : console.warn(`[autk-grammar] uniform matrix "${n}" has no column count; entry dropped`);
823
+ const a = xt(l, e, o), s = Array.isArray(a) ? a : Array.isArray(l.default) ? l.default : void 0;
824
+ if (!s) continue;
825
+ const i = l.cols ?? (Array.isArray(s[0]) ? s[0].length : 0);
826
+ i > 0 ? r[n] = { data: s, cols: i } : console.warn(`[autk-grammar] uniform matrix "${n}" has no column count; entry dropped`);
604
827
  }
605
- return o;
828
+ return r;
606
829
  }
607
- function ce(t) {
830
+ function De(t) {
608
831
  return t != null && !(typeof t == "number" && !Number.isFinite(t));
609
832
  }
610
- function nt(t) {
611
- return R(t) && t.fromFeature.iterate === "batched";
612
- }
613
- function Mt(t, e) {
614
- return Object.values(e ?? {}).some(nt) ? se : Object.values(t ?? {}).some(nt) ? ie : 0;
615
- }
616
- function fe(t, e, r = bt) {
617
- const o = Mt(t, e);
618
- return o > 0 ? Math.floor(r / o) : Number.POSITIVE_INFINITY;
619
- }
620
- function pe(t, e, r, o = bt) {
621
- const n = {}, a = {}, s = [];
622
- for (const l of [t, e])
623
- 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) {
626
- 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(", ")}`);
833
+ function dt(t) {
834
+ return S(t) && t.fromFeature.iterate === "batched";
835
+ }
836
+ function Bt(t, e) {
837
+ return Object.values(e ?? {}).some(dt) ? xe : Object.values(t ?? {}).some(dt) ? Fe : 0;
838
+ }
839
+ function Ge(t, e, o = Tt) {
840
+ const r = Bt(t, e);
841
+ return r > 0 ? Math.floor(o / r) : Number.POSITIVE_INFINITY;
842
+ }
843
+ function Ue(t, e, o, r = Tt) {
844
+ const n = {}, l = {}, a = [];
845
+ for (const i of [t, e])
846
+ for (const u of Object.values(i ?? {}))
847
+ S(u) && u.fromFeature.iterate === "batched" && u.fromFeature.required && a.push(u.fromFeature.path);
848
+ if (a.length > 0) {
849
+ const i = o.length;
850
+ o = o.filter((u) => a.every((d) => De(j(u, d)))), o.length < i && console.info(`[autk-grammar] batched compute dropped ${i - o.length} feature(s) missing ${a.join(", ")}`);
628
851
  }
629
- const i = fe(t, e, o);
630
- 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`
632
- ), r = r.slice(0, i));
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;
636
- a[l] = r.map((f) => {
637
- const p = Number(F(f, u.fromFeature.path) ?? c);
638
- return Number.isFinite(p) ? p : 0;
852
+ const s = Ge(t, e, r);
853
+ o.length > s && (console.warn(
854
+ `[autk-grammar] batched compute capped at ${s} features (got ${o.length}): its largest packed array takes ${Bt(t, e)} B per feature, and a storage buffer binding holds ${r} B`
855
+ ), o = o.slice(0, s));
856
+ for (const [i, u] of Object.entries(t ?? {}))
857
+ if (S(u) && u.fromFeature.iterate === "batched") {
858
+ const d = typeof u.default == "number" ? u.default : void 0;
859
+ l[i] = o.map((c) => {
860
+ const f = Number(j(c, u.fromFeature.path) ?? d);
861
+ return Number.isFinite(f) ? f : 0;
639
862
  });
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 = [];
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) {
863
+ } else typeof u == "number" && (n[i] = u);
864
+ for (const [i, u] of Object.entries(e ?? {})) {
865
+ if (!S(u) || u.fromFeature.iterate !== "batched") continue;
866
+ const d = [];
867
+ for (const c of o) {
868
+ const f = j(c, u.fromFeature.path);
869
+ let m = 1 / 0, h = 1 / 0, y = -1 / 0, p = -1 / 0;
870
+ if (Array.isArray(f))
871
+ for (const g of f) {
649
872
  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));
873
+ const E = Number(g[0]), _ = Number(g[1]);
874
+ !Number.isFinite(E) || !Number.isFinite(_) || (m = Math.min(m, E), h = Math.min(h, _), y = Math.max(y, E), p = Math.max(p, _));
652
875
  }
653
- Number.isFinite(y) || (y = 0, d = 0, m = 0, h = 0), c.push(y, d, m, d, m, h, y, h);
876
+ Number.isFinite(m) || (m = 0, h = 0, y = 0, p = 0), d.push(m, h, y, h, y, p, m, p);
654
877
  }
655
- a[l] = c;
878
+ l[i] = d;
656
879
  }
657
- return n.num_features = r.length, { uniforms: n, uniformArrays: a };
880
+ return n.num_features = o.length, { uniforms: n, uniformArrays: l };
658
881
  }
659
- function at(t, e, r) {
660
- const o = P(e, t.dataRef);
661
- if (!o) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
882
+ function pt(t, e, o) {
883
+ const r = k(e, t.dataRef);
884
+ if (!r) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
662
885
  const n = {
663
- collection: o,
886
+ collection: r,
664
887
  variableMapping: t.attributes,
665
- wgslBody: le(t.wgslFunction)
888
+ wgslBody: Be(t.wgslFunction)
666
889
  };
667
890
  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;
891
+ const l = Ft(t);
892
+ if (l?.mode === "batched") {
893
+ const u = k(e, l.layer)?.features ?? [], d = Ue(t.uniforms, t.uniformMatrices, u), c = ct(mt(t.uniforms), e) ?? {}, f = ft(mt(t.uniformMatrices), e);
894
+ return n.uniforms = { ...c, ...d.uniforms }, n.uniformArrays = { ...n.uniformArrays ?? {}, ...d.uniformArrays }, f && Object.keys(f).length > 0 && (n.uniformMatrices = f), n;
672
895
  }
673
- const s = a?.mode === "all" ? r : void 0, i = rt(t.uniforms, e, s), l = ot(t.uniformMatrices, e, s);
674
- return i && (n.uniforms = i), l && (n.uniformMatrices = l), n;
896
+ const a = l?.mode === "all" ? o : void 0, s = ct(t.uniforms, e, a), i = ft(t.uniformMatrices, e, a);
897
+ return s && (n.uniforms = s), i && (n.uniformMatrices = i), n;
675
898
  }
676
- function it(t) {
899
+ function mt(t) {
677
900
  if (t)
678
- return Object.fromEntries(Object.entries(t).filter(([, e]) => !(R(e) && e.fromFeature.iterate === "batched")));
901
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => !(S(e) && e.fromFeature.iterate === "batched")));
679
902
  }
680
- function de(t) {
903
+ function Qe(t) {
681
904
  return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
682
905
  }
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);
906
+ async function We(t, e, o) {
907
+ const r = Ft(t);
908
+ if (r?.mode !== "all") return o(pt(t, e));
909
+ const n = k(e, t.dataRef);
687
910
  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;
911
+ const l = Qe(t), a = structuredClone(n);
912
+ for (const i of a.features) {
913
+ const u = i.properties ??= {}, d = u.compute ??= {};
914
+ for (const c of l) d[c] = 0;
692
915
  }
693
- const i = P(e, o.layer)?.features?.length ?? 0;
694
- 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);
916
+ const s = k(e, r.layer)?.features?.length ?? 0;
917
+ for (let i = 0; i < s; i++) {
918
+ const u = await o({ ...pt(t, e, i), collection: a });
919
+ a.features.forEach((d, c) => {
920
+ const f = d.properties?.compute, m = u.features[c]?.properties?.compute;
921
+ if (!(!f || !m))
922
+ for (const h of l) {
923
+ const y = Number(m[h]);
924
+ Number.isFinite(y) && (f[h] += y);
702
925
  }
703
926
  });
704
927
  }
705
- return s;
928
+ return a;
706
929
  }
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;
930
+ const ht = ["surface", "parks", "water", "roads", "buildings", "polygons", "polylines"];
931
+ function Ye(t, e, o, r) {
932
+ return r?.get(b(o, e)) ?? t.getTablesMetadata().find((n) => n.name === e)?.type;
710
933
  }
711
- function ye(t, e) {
712
- async function r(s, i, l) {
713
- return t?.get(A(l, i)) ?? await s.getLayer(i);
934
+ function Ve(t, e, o) {
935
+ async function r(s, i, u) {
936
+ return t?.get(b(u, i)) ?? await s.getLayer(i);
714
937
  }
715
- function o(s, i, l, u, c) {
938
+ function n(s, i, u, d, c) {
716
939
  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);
940
+ const f = d.outputTableName ?? u;
941
+ t.set(b(d.workspace, f), i);
942
+ const m = d.layerType ?? c ?? Ye(s, u, d.workspace, e);
943
+ d.outputTableName && m && e?.set(b(d.workspace, f), m);
721
944
  }
722
- async function n(s, i) {
945
+ async function l(s, i) {
723
946
  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) => ({
947
+ if (!ht.includes(c.type))
948
+ 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 ${ht.join(", ")}.`);
949
+ const u = await Promise.all(i.layers.map(async (c) => ({
727
950
  id: c.id,
728
951
  collection: await r(s, c.dataRef, i.workspace),
729
952
  type: c.type,
730
953
  objectIdProperty: c.objectIdProperty
731
- }))), u = await new X().renderPipeline({
732
- layers: l,
954
+ }))), d = await new et().renderPipeline({
955
+ layers: u,
733
956
  viewpoints: {
734
957
  collection: await r(s, i.viewpoints.dataRef, i.workspace),
735
958
  strategy: i.viewpoints.strategy,
@@ -739,63 +962,63 @@ function ye(t, e) {
739
962
  camera: i.camera,
740
963
  tileSize: i.tileSize
741
964
  });
742
- o(s, u, i.viewpoints.dataRef, i, i.viewpoints.strategy?.type === "building-windows" ? "points" : void 0);
965
+ n(s, d, i.viewpoints.dataRef, i, i.viewpoints.strategy?.type === "building-windows" ? "points" : void 0);
743
966
  }
744
967
  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);
968
+ const u = {}, d = s.getWorkspaceConfiguration().coordinateFormat;
969
+ for (const m of je(i)) {
970
+ const h = b(i.workspace, m), y = t?.get(h) ?? (m === i.dataRef ? void 0 : qt(o?.get(h), d));
971
+ if (y) u[m] = y;
972
+ else if (m === i.dataRef) u[m] = await s.getLayer(m);
750
973
  else
751
974
  try {
752
- l[f] = await s.getLayer(f);
975
+ u[m] = await s.getLayer(m);
753
976
  } catch {
754
- l[f] = void 0;
977
+ u[m] = void 0;
755
978
  }
756
979
  }
757
- const u = new X(), c = await me(i, l, (f) => u.gpgpuPipeline(f));
758
- o(s, c, i.dataRef, i);
980
+ const c = new et(), f = await We(i, u, (m) => c.gpgpuPipeline(m));
981
+ n(s, f, i.dataRef, i);
759
982
  }
760
983
  return {
761
984
  async resolveCompute(s, i) {
762
985
  if (s)
763
- return await N(s, i.workspace), i.type === "render" ? await n(s, i) : await a(s, i), s;
986
+ return await P(s, i.workspace), i.type === "render" ? await l(s, i) : await a(s, i), s;
764
987
  }
765
988
  };
766
989
  }
767
- class ge {
990
+ class He {
768
991
  _listeners = /* @__PURE__ */ new Map();
769
- on(e, r) {
992
+ on(e, o) {
770
993
  this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
771
- const o = this._listeners.get(e);
772
- return o.add(r), () => o.delete(r);
994
+ const r = this._listeners.get(e);
995
+ return r.add(o), () => r.delete(o);
773
996
  }
774
997
  /** @internal */
775
- emit(e, r) {
776
- this._listeners.get(e)?.forEach((o) => o(r));
998
+ emit(e, o) {
999
+ this._listeners.get(e)?.forEach((r) => r(o));
777
1000
  }
778
1001
  }
779
- function v(t) {
1002
+ function M(t) {
780
1003
  return t === void 0 ? [] : Array.isArray(t) ? t : [t];
781
1004
  }
782
- function we(t) {
1005
+ function Je(t) {
783
1006
  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);
1007
+ for (const r of [...M(t.map), ...M(t.plot)])
1008
+ if (r.id !== void 0) {
1009
+ if (r.id === "") throw new Error("A map or plot has an empty id.");
1010
+ if (e.has(r.id)) throw new Error(`Two maps or plots have the id "${r.id}"; an id names one view.`);
1011
+ e.add(r.id);
789
1012
  }
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);
1013
+ const o = /* @__PURE__ */ new Map();
1014
+ for (const r of M(t.plot)) {
1015
+ const n = A(r), l = o.get(n);
1016
+ if (l)
1017
+ throw new Error(l.id === void 0 && r.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.`);
1018
+ o.set(n, r);
796
1019
  }
797
1020
  }
798
- class Se {
1021
+ class eo {
799
1022
  dataAdapter;
800
1023
  mapAdapter;
801
1024
  plotAdapter;
@@ -813,12 +1036,13 @@ class Se {
813
1036
  _exports = /* @__PURE__ */ new Map();
814
1037
  /** Each GeoJSON table a run loaded and each table a join wrote, which its plots read before the database. */
815
1038
  _geojsonCache = /* @__PURE__ */ new Map();
816
- interactions = new ge();
1039
+ interactions = new He();
817
1040
  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);
1041
+ this.dataAdapter = oe(e, this._geojsonCache), this.mapAdapter = be(e, this._layers, this._computeCache, this._maps, this._computeTypes, this._exports), this.plotAdapter = Oe(e, this._layers, this._plotRegistry, this._plotLinks, this._geojsonCache, this._computeCache, this._plotRows, this._exports), this.computeAdapter = Ve(this._computeCache, this._computeTypes, this._geojsonCache);
819
1042
  }
820
1043
  /**
821
- * The coordinate reference system used internally by the autk workspace.
1044
+ * The coordinate reference system autk-db stores a workspace's tables in, unless the spec's `workspaces` sets
1045
+ * another for it.
822
1046
  *
823
1047
  * Input data is expected in EPSG:4326 (WGS84) by default and is transformed
824
1048
  * to this CRS on load. Consumers that prepare data for injection (e.g. by
@@ -826,7 +1050,7 @@ class Se {
826
1050
  * instead of hard-coding a CRS string.
827
1051
  */
828
1052
  get workspaceCrs() {
829
- return ut;
1053
+ return Ut;
830
1054
  }
831
1055
  get data() {
832
1056
  return this._data;
@@ -851,8 +1075,8 @@ class Se {
851
1075
  * @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
1076
  * the spec's `map` list. Without it, every map.
853
1077
  */
854
- mapLayers(e, r) {
855
- return this._layersOf(e, r).map(({ map: o, layerId: n }) => ({ map: o, layerId: n }));
1078
+ mapLayers(e, o) {
1079
+ return this._layersOf(e, o).map(({ map: r, layerId: n }) => ({ map: r, layerId: n }));
856
1080
  }
857
1081
  /**
858
1082
  * The layer a map of the last {@link run} draws for a table, found by the table's name (a layer's `dataRef`):
@@ -868,12 +1092,12 @@ class Se {
868
1092
  * const layer = grammar.mapLayer('buildings');
869
1093
  * layer?.map.updateRenderInfo(layer.layerId, { opacity: 0.5 });
870
1094
  */
871
- mapLayer(e, r) {
872
- return this.mapLayers(e, r).pop();
1095
+ mapLayer(e, o) {
1096
+ return this.mapLayers(e, o).pop();
873
1097
  }
874
1098
  /** 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));
1099
+ _layersOf(e, o) {
1100
+ return this._layers.filter((r) => r.dataRef === e && W(r, o));
877
1101
  }
878
1102
  /**
879
1103
  * Releases what the last run created: every map (its layers' GPU buffers, its textures, its canvas context, the
@@ -897,7 +1121,10 @@ class Se {
897
1121
  throw new Error("Plot adapter not initialized. Please call the constructor first.");
898
1122
  if (!this.computeAdapter)
899
1123
  throw new Error("Compute adapter not initialized. Please call the constructor first.");
900
- we(e), this.destroy(), this.grammarEngine = Pt({
1124
+ Je(e);
1125
+ for (const l of M(e.plot)) Ce(l);
1126
+ const o = Se(M(e.plot));
1127
+ this.destroy(), M(e.plot).length > 0 && ke(o), this.grammarEngine = Vt({
901
1128
  spec: e,
902
1129
  adapters: {
903
1130
  db: this.dataAdapter,
@@ -907,27 +1134,27 @@ class Se {
907
1134
  }
908
1135
  }), await this.grammarEngine.run();
909
1136
  const r = this.grammarEngine.context;
910
- if (r && await N(r), this._wireLinks(e), this._rewireInteractions(e), !r) {
1137
+ if (r && await P(r), this._wireLinks(e), this._selectFromTheStart(e), this._rewireInteractions(e), !r) {
911
1138
  console.warn("Grammar engine produced no data context."), this._data = {};
912
1139
  return;
913
1140
  }
914
- const o = {};
915
- for (const n of r.getLayersMetadata())
916
- Object.defineProperty(o, n.name, {
1141
+ const n = {};
1142
+ for (const l of r.getLayersMetadata())
1143
+ Object.defineProperty(n, l.name, {
917
1144
  get: () => {
918
- const a = this._computeCache.get(n.name);
919
- return a ? Promise.resolve(a) : r.getLayer(n.name);
1145
+ const a = this._computeCache.get(l.name);
1146
+ return a ? Promise.resolve(a) : r.getLayer(l.name);
920
1147
  },
921
1148
  enumerable: !0,
922
1149
  configurable: !0
923
1150
  });
924
- for (const n of this._computeCache.keys())
925
- n in o || Object.defineProperty(o, n, {
926
- get: () => Promise.resolve(this._computeCache.get(n)),
1151
+ for (const l of this._computeCache.keys())
1152
+ l in n || Object.defineProperty(n, l, {
1153
+ get: () => Promise.resolve(this._computeCache.get(l)),
927
1154
  enumerable: !0,
928
1155
  configurable: !0
929
1156
  });
930
- this._data = o;
1157
+ this._data = n;
931
1158
  }
932
1159
  /**
933
1160
  * Highlights features on every layer that draws the table `dataRef`, in every map (see {@link mapLayers}), or only
@@ -940,10 +1167,10 @@ class Se {
940
1167
  * @param mapId The map to highlight on, by its {@link MapId}: a string names a map by its `id`, a number by its
941
1168
  * index in the spec's `map` list. Without it, every map that draws the table.
942
1169
  */
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);
1170
+ highlightOnMap(e, o, r) {
1171
+ const n = this._layersOf(e, r);
1172
+ for (const { map: l, layerId: a } of n) l.setHighlightedIds(a, o);
1173
+ this._selectInLinkedPlots(n, o);
947
1174
  }
948
1175
  /**
949
1176
  * Clears highlighted features on every layer that draws the table `dataRef`, in every map (see {@link mapLayers}),
@@ -954,10 +1181,10 @@ class Se {
954
1181
  * @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
1182
  * the spec's `map` list. Without it, every map that draws the table.
956
1183
  */
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, []);
1184
+ clearHighlightOnMap(e, o) {
1185
+ const r = this._layersOf(e, o);
1186
+ for (const { map: n, layerId: l } of r) n.clearHighlightedIds(l);
1187
+ this._selectInLinkedPlots(r, []);
961
1188
  }
962
1189
  /**
963
1190
  * Clears the selection on the plot `plotId` names: its `id`, else its `dataRef`.
@@ -968,10 +1195,10 @@ class Se {
968
1195
  * @param mapId The map whose linked layers to clear, by its {@link MapId}: a string names a map by its `id`, a
969
1196
  * number by its index in the spec's `map` list. Without it, every linked layer.
970
1197
  */
971
- clearHighlightOnPlot(e, r) {
1198
+ clearHighlightOnPlot(e, o) {
972
1199
  this._plotRegistry.get(e)?.setSelection([]);
973
- for (const o of this._plotLinks.get(e) ?? [])
974
- G(o, r) && o.map.clearHighlightedIds(o.layerId);
1200
+ for (const r of this._plotLinks.get(e) ?? [])
1201
+ W(r, o) && r.map.clearHighlightedIds(r.layerId);
975
1202
  }
976
1203
  /**
977
1204
  * Applies a selection to the plot `plotId` names: its `id`, else its `dataRef`.
@@ -983,86 +1210,95 @@ class Se {
983
1210
  * @param mapId The map whose linked layers to highlight, by its {@link MapId}: a string names a map by its `id`, a
984
1211
  * number by its index in the spec's `map` list. Without it, every linked layer.
985
1212
  */
986
- setPlotSelection(e, r, o) {
987
- this._plotRegistry.get(e)?.setSelection(r);
1213
+ setPlotSelection(e, o, r) {
1214
+ this._plotRegistry.get(e)?.setSelection(o);
988
1215
  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));
1216
+ for (const l of this._plotLinks.get(e) ?? [])
1217
+ W(l, r) && l.map.setHighlightedIds(l.layerId, D(o, n, l.rows));
991
1218
  }
992
1219
  /**
993
1220
  * Applies a selection made on `layers`, by their positions `featureIds`, to every plot linked to one of them, at the
994
1221
  * plot's own positions of the selected rows.
995
1222
  */
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]);
1223
+ _selectInLinkedPlots(e, o) {
1224
+ for (const [r, n] of this._plotLinks) {
1225
+ const l = n.filter((i) => e.includes(i));
1226
+ if (l.length === 0) continue;
1227
+ const a = this._plotRows.get(r) ?? [], s = new Set(l.flatMap((i) => D(o, i.rows, a)));
1228
+ this._plotRegistry.get(r)?.setSelection([...s]);
1002
1229
  }
1003
1230
  }
1004
1231
  /** Wires each entry of `links` between a plot and a layer of a map, both now drawn. */
1005
1232
  _wireLinks(e) {
1006
- const r = v(e.map), o = v(e.plot);
1233
+ const o = M(e.map), r = M(e.plot);
1007
1234
  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)
1235
+ const l = r.find((c) => A(c) === n.source), a = this._plotRegistry.get(n.source);
1236
+ if (!l || !a)
1010
1237
  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)
1238
+ const s = o.findIndex((c) => c.id === n.target), i = this._maps[s];
1239
+ if (s < 0 || !i)
1013
1240
  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);
1241
+ const u = o[s].layerRefs.find((c) => n.layer !== void 0 ? R(c) === n.layer : c.dataRef === l.dataRef);
1015
1242
  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));
1243
+ 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 "${l.dataRef}"; name the layer.`);
1244
+ const d = this._layers.find((c) => c.mapIndex === s && c.layerId === R(u));
1245
+ d && (kt(a, this._plotRows.get(n.source) ?? [], l.events ?? [], d), Rt(this._plotLinks, n.source, d));
1019
1246
  }
1020
1247
  }
1248
+ /**
1249
+ * Applies each plot's `selection` once the plots and their links exist, as `setPlotSelection` does: the plot selects
1250
+ * the rows, and the layers it is linked to, by `mapRef` or `links`, highlight them. autk-plot's `setSelection` emits
1251
+ * no event, so no `plot:selection` reports it.
1252
+ */
1253
+ _selectFromTheStart(e) {
1254
+ for (const o of M(e.plot))
1255
+ o.selection && o.selection.length > 0 && this.setPlotSelection(A(o), o.selection);
1256
+ }
1021
1257
  _rewireInteractions(e) {
1022
- for (const o of this._fwdCleanups) o();
1258
+ for (const r of this._fwdCleanups) r();
1023
1259
  this._fwdCleanups = [];
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 });
1260
+ const o = M(e.map);
1261
+ this._maps.forEach((r, n) => {
1262
+ const l = St(o[n], n), a = ({ layerId: s, selection: i }) => {
1263
+ this.interactions.emit("map:picking", { mapId: l, layerId: s, selection: i });
1028
1264
  };
1029
- o.events.on(D.PICKING, s), this._fwdCleanups.push(() => o.events.off(D.PICKING, s));
1265
+ r.events.on(Y.PICKING, a), this._fwdCleanups.push(() => r.events.off(Y.PICKING, a));
1030
1266
  });
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 }) => {
1267
+ for (const [r, n] of this._plotRegistry)
1268
+ for (const l of [x.CLICK, x.BRUSH, x.BRUSH_X, x.BRUSH_Y]) {
1269
+ const a = ({ selection: s }) => {
1034
1270
  this.interactions.emit("plot:selection", {
1035
- plotId: o,
1036
- event: a,
1037
- selection: i
1271
+ plotId: r,
1272
+ event: l,
1273
+ selection: s
1038
1274
  });
1039
1275
  };
1040
- n.events.on(a, s), this._fwdCleanups.push(() => n.events.off(a, s));
1276
+ n.events.on(l, a), this._fwdCleanups.push(() => n.events.off(l, a));
1041
1277
  }
1042
1278
  }
1043
1279
  }
1044
1280
  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
1281
+ eo as AutkGrammar,
1282
+ Ht as ColorMapInterpolator,
1283
+ He as GrammarEventEmitter,
1284
+ wt as NormalizationMode,
1285
+ Tt as STORAGE_BUFFER_BINDING_SIZE,
1286
+ ge as applyCamera,
1287
+ to as arrangeViews,
1288
+ Ue as buildBatchedUniforms,
1289
+ je as computeLayerNames,
1290
+ Ve as createComputeAdapter,
1291
+ oe as createDataAdapter,
1292
+ Vt as createEngine,
1293
+ P as enterWorkspace,
1294
+ Ft as findIterateSource,
1295
+ S as isFromFeature,
1296
+ Be as joinWgsl,
1297
+ Ge as maxBatchedFeatures,
1298
+ pt as resolveComputeParams,
1299
+ ft as resolveUniformMatrices,
1300
+ ct as resolveUniforms,
1301
+ We as runCompute,
1302
+ b as tableKey
1067
1303
  };
1068
1304
  //# sourceMappingURL=autk-grammar.js.map