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