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