@urban-toolkit/autk-grammar 0.2.1 → 0.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,126 +1,126 @@
1
- import { AutkDb as L, DEFAULT_WORKSPACE_COORDINATE_FORMAT as P } from "@urban-toolkit/autk-db";
2
- import { AutkMap as T, MapEvent as b } from "@urban-toolkit/autk-map";
3
- import { AutkPlot as I, PlotEvent as _ } from "@urban-toolkit/autk-plot";
4
- import { ColorMapDomainStrategy as E } from "@urban-toolkit/autk-core";
5
- import { AutkComputeEngine as v } from "@urban-toolkit/autk-compute";
6
- function B(t) {
7
- const { spec: a, adapters: e } = t;
8
- let n;
1
+ import { AutkDb as x, DEFAULT_WORKSPACE_COORDINATE_FORMAT as F } from "@urban-toolkit/autk-db";
2
+ import { AutkMap as U, MapEvent as P } from "@urban-toolkit/autk-map";
3
+ import { AutkPlot as Q, PlotEvent as A } from "@urban-toolkit/autk-plot";
4
+ import { ColorMapDomainStrategy as b } from "@urban-toolkit/autk-core";
5
+ import { AutkComputeEngine as $ } from "@urban-toolkit/autk-compute";
6
+ function H(t) {
7
+ const { spec: e, adapters: r } = t;
8
+ let a;
9
9
  async function s() {
10
- let p;
11
- if (a.data)
12
- for (const r of a.data)
13
- p = await e.db.resolveSource(p, r);
14
- if (a.compute)
15
- for (const r of a.compute)
16
- p = await e.compute.resolveCompute(p, r);
17
- if (a.map)
18
- if (Array.isArray(a.map))
19
- for (let r = 0; r < a.map.length; r++) {
20
- let u = a.map[r];
21
- await e.map.resolveMap(p, u, r);
10
+ let l;
11
+ if (e.data)
12
+ for (const i of e.data)
13
+ l = await r.db.resolveSource(l, i);
14
+ if (e.compute)
15
+ for (const i of e.compute)
16
+ l = await r.compute.resolveCompute(l, i);
17
+ if (e.map)
18
+ if (Array.isArray(e.map))
19
+ for (let i = 0; i < e.map.length; i++) {
20
+ let f = e.map[i];
21
+ await r.map.resolveMap(l, f, i);
22
22
  }
23
23
  else
24
- await e.map.resolveMap(p, a.map);
25
- if (a.plot)
26
- if (Array.isArray(a.plot))
27
- for (const r of a.plot)
28
- await e.plot.resolvePlot(p, r);
24
+ await r.map.resolveMap(l, e.map);
25
+ if (e.plot)
26
+ if (Array.isArray(e.plot))
27
+ for (const i of e.plot)
28
+ await r.plot.resolvePlot(l, i);
29
29
  else
30
- await e.plot.resolvePlot(p, a.plot);
31
- n = p;
30
+ await r.plot.resolvePlot(l, e.plot);
31
+ a = l;
32
32
  }
33
- function o(p) {
34
- return console.log("Spec to update", p), new Promise((r) => {
35
- r();
33
+ function o(l) {
34
+ return console.log("Spec to update", l), new Promise((i) => {
35
+ i();
36
36
  });
37
37
  }
38
- function i() {
38
+ function n() {
39
39
  console.log("Function not implemented yet");
40
40
  }
41
- return { run: s, updatedSpec: o, destroy: i, get context() {
42
- return n;
41
+ return { run: s, updatedSpec: o, destroy: n, get context() {
42
+ return a;
43
43
  } };
44
44
  }
45
- var N = /* @__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_BU_GN = "interpolateBuGn", t.SEQ_BU_PU = "interpolateBuPu", t.SEQ_GN_BU = "interpolateGnBu", t.SEQ_OR_RD = "interpolateOrRd", t.SEQ_PU_BU = "interpolatePuBu", t.SEQ_PU_RD = "interpolatePuRd", t.SEQ_RD_PU = "interpolateRdPu", 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))(N || {}), M = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(M || {});
46
- function G(t) {
47
- const { autoLoadLayers: a, ...e } = t;
48
- return { ...e, autoLoadLayers: { layers: a?.layers ?? [] } };
45
+ var Y = /* @__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))(Y || {}), O = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(O || {});
46
+ function V(t) {
47
+ const { autoLoadLayers: e, ...r } = t;
48
+ return { ...r, autoLoadLayers: { layers: e?.layers ?? [] } };
49
49
  }
50
- function D(t, a) {
51
- function e(n, s) {
50
+ function W(t, e) {
51
+ function r(a, s) {
52
52
  if (!s || !s.db)
53
53
  return;
54
54
  const o = document.getElementById(s.db);
55
55
  if (o) {
56
- const i = n.getTablesMetadata();
56
+ const n = a.getTablesMetadata();
57
57
  o.innerHTML += "<ul>";
58
- for (const p of i)
59
- o.innerHTML += `<li>${p.name}: (${p.source}, ${p.type}) </li>`;
60
- o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${i.length}</p>`;
58
+ for (const l of n)
59
+ o.innerHTML += `<li>${l.name}: (${l.source}, ${l.type}) </li>`;
60
+ o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${n.length}</p>`;
61
61
  }
62
62
  }
63
63
  return {
64
- async resolveSource(n, s) {
65
- let o = n;
66
- o || (o = new L(), await o.init());
67
- let { type: i, ...p } = s;
68
- switch (i) {
64
+ async resolveSource(a, s) {
65
+ let o = a;
66
+ o || (o = new x(), await o.init());
67
+ let { type: n, ...l } = s;
68
+ switch (n) {
69
69
  case "osm":
70
- return await o.loadOsm(G(p)), e(o, t), o;
70
+ return await o.loadOsm(V(l)), r(o, t), o;
71
71
  case "csv":
72
- return await o.loadCsv(p), e(o, t), o;
72
+ return await o.loadCsv(l), r(o, t), o;
73
73
  case "json":
74
- return await o.loadJson(p), e(o, t), o;
74
+ return await o.loadJson(l), r(o, t), o;
75
75
  case "geojson": {
76
- const r = p;
77
- let u;
78
- r.geojsonFileUrl ? u = await (await fetch(r.geojsonFileUrl)).json() : u = r.geojsonObject, a && u && a.set(r.outputTableName, u);
79
- const c = u ? (() => {
80
- const l = { ...r, geojsonObject: u };
81
- return delete l.geojsonFileUrl, l;
82
- })() : r;
76
+ const i = l;
77
+ let f;
78
+ i.geojsonFileUrl ? f = await (await fetch(i.geojsonFileUrl)).json() : f = i.geojsonObject, e && f && e.set(i.outputTableName, f);
79
+ const c = f ? (() => {
80
+ const u = { ...i, geojsonObject: f };
81
+ return delete u.geojsonFileUrl, u;
82
+ })() : i;
83
83
  try {
84
84
  await o.loadGeojson(c);
85
- } catch (l) {
86
- const m = c.coordinateFormat ? `coordinateFormat is set to "${c.coordinateFormat}"` : "no coordinateFormat was specified — defaulting to EPSG:4326 (WGS84 per RFC 7946)";
85
+ } catch (u) {
86
+ const p = c.coordinateFormat ? `coordinateFormat is set to "${c.coordinateFormat}"` : "no coordinateFormat was specified — defaulting to EPSG:4326 (WGS84 per RFC 7946)";
87
87
  throw new Error(
88
- `Failed to load GeoJSON layer "${c.outputTableName}": ${l instanceof Error ? l.message : String(l)}. ${m}. Verify that coordinateFormat matches the actual CRS of the input data.`
88
+ `Failed to load GeoJSON layer "${c.outputTableName}": ${u instanceof Error ? u.message : String(u)}. ${p}. Verify that coordinateFormat matches the actual CRS of the input data.`
89
89
  );
90
90
  }
91
91
  try {
92
- const l = await o.getBoundingBoxFromLayer(c.outputTableName), m = 25e6;
93
- if (!isFinite(l.minLon) || !isFinite(l.minLat) || !isFinite(l.maxLon) || !isFinite(l.maxLat) || Math.abs(l.minLon) > m || Math.abs(l.maxLon) > m || Math.abs(l.minLat) > m || Math.abs(l.maxLat) > m)
92
+ const u = await o.getBoundingBoxFromLayer(c.outputTableName), p = 25e6;
93
+ if (!isFinite(u.minLon) || !isFinite(u.minLat) || !isFinite(u.maxLon) || !isFinite(u.maxLat) || Math.abs(u.minLon) > p || Math.abs(u.maxLon) > p || Math.abs(u.minLat) > p || Math.abs(u.maxLat) > p)
94
94
  throw new Error(
95
- `Geometry bounding box after transform is invalid for layer "${c.outputTableName}" (bbox: [${l.minLon}, ${l.minLat}, ${l.maxLon}, ${l.maxLat}]). Verify that coordinateFormat matches the actual CRS of the input data. The workspace uses ${P}; input is expected in EPSG:4326 by default.`
95
+ `Geometry bounding box after transform is invalid for layer "${c.outputTableName}" (bbox: [${u.minLon}, ${u.minLat}, ${u.maxLon}, ${u.maxLat}]). Verify that coordinateFormat matches the actual CRS of the input data. The workspace uses ${F}; input is expected in EPSG:4326 by default.`
96
96
  );
97
- } catch (l) {
98
- if (l instanceof Error && l.message.includes("bounding box after transform")) throw l;
97
+ } catch (u) {
98
+ if (u instanceof Error && u.message.includes("bounding box after transform")) throw u;
99
99
  }
100
- return e(o, t), o;
100
+ return r(o, t), o;
101
101
  }
102
102
  case "heatmap": {
103
- const r = p;
103
+ const i = l;
104
104
  return await o.buildHeatmap({
105
- tableJoinName: r.tableJoinName,
106
- near: { distance: r.near.distance },
107
- outputTableName: r.outputTableName,
108
- grid: r.grid,
109
- ...r.groupBy && { groupBy: r.groupBy }
110
- }), e(o, t), o;
105
+ tableJoinName: i.tableJoinName,
106
+ near: { distance: i.near.distance },
107
+ outputTableName: i.outputTableName,
108
+ grid: i.grid,
109
+ ...i.groupBy && { groupBy: i.groupBy }
110
+ }), r(o, t), o;
111
111
  }
112
112
  case "join": {
113
- const r = p;
113
+ const i = l;
114
114
  if (await o.spatialQuery({
115
- tableRootName: r.tableRootName,
116
- tableJoinName: r.tableJoinName,
117
- ...r.near && { near: r.near },
118
- ...r.groupBy && { groupBy: r.groupBy }
119
- }), a) {
120
- const u = await o.getLayer(r.tableRootName);
121
- a.set(r.tableRootName, u);
115
+ tableRootName: i.tableRootName,
116
+ tableJoinName: i.tableJoinName,
117
+ ...i.near && { near: i.near },
118
+ ...i.groupBy && { groupBy: i.groupBy }
119
+ }), e) {
120
+ const f = await o.getLayer(i.tableRootName);
121
+ e.set(i.tableRootName, f);
122
122
  }
123
- return e(o, t), o;
123
+ return r(o, t), o;
124
124
  }
125
125
  default:
126
126
  return;
@@ -128,85 +128,85 @@ function D(t, a) {
128
128
  }
129
129
  };
130
130
  }
131
- function O(t, a) {
132
- return a && a.length > 0 ? { type: E.USER, params: a } : t?.mode === M.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
133
- type: E.PERCENTILE,
131
+ function k(t, e) {
132
+ return e && e.length > 0 ? { type: b.USER, params: e } : t?.mode === O.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
133
+ type: b.PERCENTILE,
134
134
  params: [t.lowerPercentile ?? 0, t.upperPercentile ?? 100]
135
- } : { type: E.PERCENTILE } : { type: E.MIN_MAX };
135
+ } : { type: b.PERCENTILE } : { type: b.MIN_MAX };
136
136
  }
137
- function k(t, a) {
138
- return a.split(".").reduce((e, n) => {
139
- if (!(e == null || typeof e != "object"))
140
- return e[n];
137
+ function J(t, e) {
138
+ return e.split(".").reduce((r, a) => {
139
+ if (!(r == null || typeof r != "object"))
140
+ return r[a];
141
141
  }, t);
142
142
  }
143
- function Q(t, a, e) {
144
- const n = a.split("."), s = { ...t };
143
+ function K(t, e, r) {
144
+ const a = e.split("."), s = { ...t };
145
145
  let o = s;
146
- for (let i = 0; i < n.length - 1; i++)
147
- o[n[i]] = { ...o[n[i]] ?? {} }, o = o[n[i]];
148
- return o[n[n.length - 1]] = e, s;
146
+ for (let n = 0; n < a.length - 1; n++)
147
+ o[a[n]] = { ...o[a[n]] ?? {} }, o = o[a[n]];
148
+ return o[a[a.length - 1]] = r, s;
149
149
  }
150
- function x(t, a) {
151
- const n = t.features?.[0]?.properties?.bands ?? [];
152
- return n.find((o) => o.id === a || o.label === a?.replace(/\./g, "_"))?.id ?? n[0]?.id ?? a ?? "";
150
+ function X(t, e) {
151
+ const a = t.features?.[0]?.properties?.bands ?? [];
152
+ return a.find((o) => o.id === e || o.label === e?.replace(/\./g, "_"))?.id ?? a[0]?.id ?? e ?? "";
153
153
  }
154
- function U(t, a, e) {
155
- async function n(s, o, i) {
156
- let p = {};
157
- for (const r of o.getTablesMetadata())
158
- r.type !== void 0 && (p[r.name] = r.type);
159
- for (const r of i.layerRefs) {
160
- const u = r.dataRef, c = p[u], l = r.getFnv, m = e?.get(u) ?? await o.getLayer(u), d = c === "raster" ? m : {
161
- ...m,
162
- features: (m.features ?? []).filter((f) => f.geometry != null)
154
+ function q(t, e, r) {
155
+ async function a(s, o, n) {
156
+ let l = {};
157
+ for (const i of o.getTablesMetadata())
158
+ i.type !== void 0 && (l[i.name] = i.type);
159
+ for (const i of n.layerRefs) {
160
+ const f = i.dataRef, c = l[f], u = i.getFnv, p = r?.get(f) ?? await o.getLayer(f), m = c === "raster" ? p : {
161
+ ...p,
162
+ features: (p.features ?? []).filter((y) => y.geometry != null)
163
163
  };
164
- c === "raster" ? s.loadCollection(u, { collection: d, type: "raster", property: x(d, l) }) : s.loadCollection(u, { collection: d, type: c }), r.opacity != null && s.updateRenderInfo(u, { opacity: r.opacity }), (r.isColorMap ?? (l != null && c !== "raster")) && s.updateRenderInfo(u, { isColorMap: !0 }), r.isPick && s.updateRenderInfo(u, { isPick: !0 }), r.isSkip && s.updateRenderInfo(u, { isSkip: !0 });
165
- const { catchAllCategory: g, colorMapDomain: h } = r;
166
- let S = d, A = h;
167
- if (l && g && h?.length) {
168
- const f = new Set(h);
169
- S = {
170
- ...d,
171
- features: d.features.map((R) => {
172
- const C = R.properties, y = k(C, l);
173
- return y == null || !f.has(String(y)) ? { ...R, properties: Q(C, l, g) } : R;
164
+ c === "raster" ? s.loadCollection(f, { collection: m, type: "raster", property: X(m, u) }) : s.loadCollection(f, { collection: m, type: c }), i.opacity != null && s.updateRenderInfo(f, { opacity: i.opacity }), (i.isColorMap ?? (u != null && c !== "raster")) && s.updateRenderInfo(f, { isColorMap: !0 }), i.isPick && s.updateRenderInfo(f, { isPick: !0 }), i.isSkip && s.updateRenderInfo(f, { isSkip: !0 });
165
+ const { catchAllCategory: d, colorMapDomain: g } = i;
166
+ let E = m, L = g;
167
+ if (u && d && g?.length) {
168
+ const y = new Set(g);
169
+ E = {
170
+ ...m,
171
+ features: m.features.map((S) => {
172
+ const v = S.properties, C = J(v, u);
173
+ return C == null || !y.has(String(C)) ? { ...S, properties: K(v, u, d) } : S;
174
174
  })
175
- }, A = f.has(g) ? h : [...h, g];
175
+ }, L = y.has(d) ? g : [...g, d];
176
176
  }
177
- if (r.colorMapInterpolator) {
178
- const f = {
177
+ if (i.colorMapInterpolator) {
178
+ const y = {
179
179
  // urban-grammar ColorMapInterpolator values are string-compatible
180
180
  // with autk-core ColorMapInterpolator at runtime
181
- interpolator: r.colorMapInterpolator,
182
- domainSpec: O(r.normalization, A)
181
+ interpolator: i.colorMapInterpolator,
182
+ domainSpec: k(i.normalization, L)
183
183
  };
184
- s.updateRenderInfo(u, { colormap: { config: f }, isColorMap: !0 });
184
+ s.updateRenderInfo(f, { colormap: { config: y }, isColorMap: !0 });
185
185
  }
186
- if (l && c !== "raster") {
187
- const f = l.startsWith("properties.") ? l : `properties.${l}`;
188
- s.updateThematic(u, { collection: S, property: f });
186
+ if (u && c !== "raster") {
187
+ const y = u.startsWith("properties.") ? u : `properties.${u}`;
188
+ s.updateThematic(f, { collection: E, property: y });
189
189
  }
190
190
  }
191
191
  }
192
192
  return {
193
- async resolveMap(s, o, i = 0) {
193
+ async resolveMap(s, o, n = 0) {
194
194
  if (t && t.map && s) {
195
- let p;
196
- if (Array.isArray(t.map) ? p = document.getElementById(t.map[i]) : p = document.getElementById(t.map), !p)
195
+ let l;
196
+ if (Array.isArray(t.map) ? l = document.getElementById(t.map[n]) : l = document.getElementById(t.map), !l)
197
197
  throw new Error("Could not find rendering target for map: " + t.map);
198
- if (!(p instanceof HTMLCanvasElement))
198
+ if (!(l instanceof HTMLCanvasElement))
199
199
  throw new Error("Target for map is not a canvas: " + t.map);
200
- const r = new T(p);
201
- if (o.style && r.style.setPredefinedStyle(o.style), await r.init(), await n(r, s, o), a)
202
- for (const u of o.layerRefs)
203
- a.set(u.dataRef, r);
204
- r.draw();
200
+ const i = new U(l);
201
+ if (o.style && i.style.setPredefinedStyle(o.style), await i.init(), await a(i, s, o), e)
202
+ for (const f of o.layerRefs)
203
+ e.set(f.dataRef, i);
204
+ i.draw();
205
205
  }
206
206
  }
207
207
  };
208
208
  }
209
- function F(t) {
209
+ function z(t) {
210
210
  return {
211
211
  scatter: "scatterplot",
212
212
  bar: "barchart",
@@ -217,74 +217,228 @@ function F(t) {
217
217
  heatmatrix: "heatmatrix"
218
218
  }[t];
219
219
  }
220
- function j(t, a, e, n, s) {
220
+ function Z(t, e, r, a, s) {
221
221
  return {
222
- async resolvePlot(o, i) {
222
+ async resolvePlot(o, n) {
223
223
  if (!t || !t.plot) return;
224
- const p = document.getElementById(t.plot);
225
- if (!p) throw new Error(`Could not find plot target: ${t.plot}`);
226
- const r = o;
227
- if (!r) throw new Error("No data context available for plot.");
228
- const u = s?.get(i.dataRef) ?? await r.getLayer(i.dataRef), c = i.events ?? [], l = new I(p, {
229
- type: F(i.mark),
230
- collection: u,
231
- attributes: { axis: i.axis, ...i.color && { color: i.color } },
232
- labels: { axis: i.axis, title: i.title },
224
+ const l = document.getElementById(t.plot);
225
+ if (!l) throw new Error(`Could not find plot target: ${t.plot}`);
226
+ const i = o;
227
+ if (!i) throw new Error("No data context available for plot.");
228
+ const f = s?.get(n.dataRef) ?? await i.getLayer(n.dataRef), c = n.events ?? [], u = new Q(l, {
229
+ type: z(n.mark),
230
+ collection: f,
231
+ attributes: { axis: n.axis, ...n.color && { color: n.color } },
232
+ labels: { axis: n.axis, title: n.title },
233
233
  events: c,
234
- ...i.width && { width: i.width },
235
- ...i.height && { height: i.height },
236
- ...i.margins && { margins: i.margins },
237
- ...i.transform && { transform: i.transform }
234
+ ...n.width && { width: n.width },
235
+ ...n.height && { height: n.height },
236
+ ...n.margins && { margins: n.margins },
237
+ ...n.transform && { transform: n.transform }
238
238
  });
239
- if (e?.set(i.dataRef, l), i.mapRef && n?.set(i.dataRef, i.mapRef), i.mapRef && a) {
240
- const m = a.get(i.mapRef);
241
- if (m) {
242
- m.updateRenderInfo(i.mapRef, { isPick: !0 }), m.events.on(b.PICKING, ({ selection: d }) => {
243
- l.setSelection(d);
239
+ if (r?.set(n.dataRef, u), n.mapRef && a?.set(n.dataRef, n.mapRef), n.mapRef && e) {
240
+ const p = e.get(n.mapRef);
241
+ if (p) {
242
+ p.updateRenderInfo(n.mapRef, { isPick: !0 }), p.events.on(P.PICKING, ({ selection: m }) => {
243
+ u.setSelection(m);
244
244
  });
245
- for (const d of c)
246
- l.events.on(d, ({ selection: w }) => {
247
- m.setHighlightedIds(i.mapRef, w);
245
+ for (const m of c)
246
+ u.events.on(m, ({ selection: h }) => {
247
+ p.setHighlightedIds(n.mapRef, h);
248
248
  });
249
249
  }
250
250
  }
251
251
  }
252
252
  };
253
253
  }
254
- function H(t) {
254
+ const M = 2e3;
255
+ function tt(t) {
256
+ return Array.isArray(t) ? t.join(`
257
+ `) : t;
258
+ }
259
+ function _(t) {
260
+ return !!t && typeof t == "object" && !Array.isArray(t) && typeof t.fromFeature == "object" && t.fromFeature !== null;
261
+ }
262
+ function R(t, e) {
263
+ return t instanceof Map ? t.get(e) : t[e];
264
+ }
265
+ function w(t, e) {
266
+ return e.split(".").reduce((r, a) => {
267
+ if (!(r == null || typeof r != "object"))
268
+ return r[a];
269
+ }, t);
270
+ }
271
+ function G(t) {
272
+ const e = [];
273
+ for (const r of [t.uniforms, t.uniformMatrices])
274
+ for (const a of Object.values(r ?? {}))
275
+ _(a) && e.push(a);
276
+ return e;
277
+ }
278
+ function et(t) {
279
+ return [.../* @__PURE__ */ new Set([t.dataRef, ...G(t).map((e) => e.fromFeature.layer)])];
280
+ }
281
+ function D(t) {
282
+ for (const e of G(t)) {
283
+ const { iterate: r, layer: a } = e.fromFeature;
284
+ if (r === "all" || r === "batched") return { mode: r, layer: a };
285
+ }
286
+ return null;
287
+ }
288
+ function j(t, e, r) {
289
+ const a = t.fromFeature, s = r !== void 0 && a.iterate === "all" ? r : a.index ?? 0, o = R(e, a.layer)?.features?.[s];
290
+ return o ? w(o, a.path) : void 0;
291
+ }
292
+ function N(t, e, r) {
293
+ if (!t) return;
294
+ const a = {};
295
+ for (const [s, o] of Object.entries(t)) {
296
+ if (!_(o)) {
297
+ a[s] = o;
298
+ continue;
299
+ }
300
+ const n = Number(j(o, e, r) ?? NaN);
301
+ Number.isFinite(n) ? a[s] = n : typeof o.default == "number" && (a[s] = o.default);
302
+ }
303
+ return a;
304
+ }
305
+ function T(t, e, r) {
306
+ if (!t) return;
307
+ const a = {};
308
+ for (const [s, o] of Object.entries(t)) {
309
+ if (!_(o)) {
310
+ a[s] = o;
311
+ continue;
312
+ }
313
+ const n = j(o, e, r), l = Array.isArray(n) ? n : Array.isArray(o.default) ? o.default : void 0;
314
+ if (!l) continue;
315
+ const i = o.cols ?? (Array.isArray(l[0]) ? l[0].length : 0);
316
+ i > 0 ? a[s] = { data: l, cols: i } : console.warn(`[autk-grammar] uniform matrix "${s}" has no column count; entry dropped`);
317
+ }
318
+ return a;
319
+ }
320
+ function rt(t) {
321
+ return t != null && !(typeof t == "number" && !Number.isFinite(t));
322
+ }
323
+ function ot(t, e, r) {
324
+ const a = {}, s = {}, o = [];
325
+ for (const n of [t, e])
326
+ for (const l of Object.values(n ?? {}))
327
+ _(l) && l.fromFeature.iterate === "batched" && l.fromFeature.required && o.push(l.fromFeature.path);
328
+ if (o.length > 0) {
329
+ const n = r.length;
330
+ r = r.filter((l) => o.every((i) => rt(w(l, i)))), r.length < n && console.info(`[autk-grammar] batched compute dropped ${n - r.length} feature(s) missing ${o.join(", ")}`);
331
+ }
332
+ r.length > M && (console.warn(`[autk-grammar] batched compute capped at ${M} features (got ${r.length})`), r = r.slice(0, M));
333
+ for (const [n, l] of Object.entries(t ?? {}))
334
+ if (_(l) && l.fromFeature.iterate === "batched") {
335
+ const i = typeof l.default == "number" ? l.default : void 0;
336
+ s[n] = r.map((f) => {
337
+ const c = Number(w(f, l.fromFeature.path) ?? i);
338
+ return Number.isFinite(c) ? c : 0;
339
+ });
340
+ } else typeof l == "number" && (a[n] = l);
341
+ for (const [n, l] of Object.entries(e ?? {})) {
342
+ if (!_(l) || l.fromFeature.iterate !== "batched") continue;
343
+ const i = [];
344
+ for (const f of r) {
345
+ const c = w(f, l.fromFeature.path);
346
+ let u = 1 / 0, p = 1 / 0, m = -1 / 0, h = -1 / 0;
347
+ if (Array.isArray(c))
348
+ for (const d of c) {
349
+ if (!Array.isArray(d) || d.length < 2) continue;
350
+ const g = Number(d[0]), E = Number(d[1]);
351
+ !Number.isFinite(g) || !Number.isFinite(E) || (u = Math.min(u, g), p = Math.min(p, E), m = Math.max(m, g), h = Math.max(h, E));
352
+ }
353
+ Number.isFinite(u) || (u = 0, p = 0, m = 0, h = 0), i.push(u, p, m, p, m, h, u, h);
354
+ }
355
+ s[n] = i;
356
+ }
357
+ return a.num_features = r.length, { uniforms: a, uniformArrays: s };
358
+ }
359
+ function I(t, e, r) {
360
+ const a = R(e, t.dataRef);
361
+ if (!a) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
362
+ const s = {
363
+ collection: a,
364
+ variableMapping: t.attributes,
365
+ wgslBody: tt(t.wglsFunction)
366
+ };
367
+ t.attributeArrays && (s.attributeArrays = t.attributeArrays), t.attributeMatrices && (s.attributeMatrices = t.attributeMatrices), t.uniformArrays && (s.uniformArrays = t.uniformArrays), t.outputColumnName && (s.resultField = t.outputColumnName), t.outputColumns && (s.outputColumns = t.outputColumns);
368
+ const o = D(t);
369
+ if (o?.mode === "batched") {
370
+ const f = R(e, o.layer)?.features ?? [], c = ot(t.uniforms, t.uniformMatrices, f), u = N(B(t.uniforms), e) ?? {}, p = T(B(t.uniformMatrices), e);
371
+ return s.uniforms = { ...u, ...c.uniforms }, s.uniformArrays = { ...s.uniformArrays ?? {}, ...c.uniformArrays }, p && Object.keys(p).length > 0 && (s.uniformMatrices = p), s;
372
+ }
373
+ const n = o?.mode === "all" ? r : void 0, l = N(t.uniforms, e, n), i = T(t.uniformMatrices, e, n);
374
+ return l && (s.uniforms = l), i && (s.uniformMatrices = i), s;
375
+ }
376
+ function B(t) {
377
+ if (t)
378
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => !(_(e) && e.fromFeature.iterate === "batched")));
379
+ }
380
+ function at(t) {
381
+ return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
382
+ }
383
+ async function nt(t, e, r) {
384
+ const a = D(t);
385
+ if (a?.mode !== "all") return r(I(t, e));
386
+ const s = R(e, t.dataRef);
387
+ if (!s) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
388
+ const o = at(t), n = structuredClone(s);
389
+ for (const i of n.features) {
390
+ const f = i.properties ??= {}, c = f.compute ??= {};
391
+ for (const u of o) c[u] = 0;
392
+ }
393
+ const l = R(e, a.layer)?.features?.length ?? 0;
394
+ for (let i = 0; i < l; i++) {
395
+ const f = await r({ ...I(t, e, i), collection: n });
396
+ n.features.forEach((c, u) => {
397
+ const p = c.properties?.compute, m = f.features[u]?.properties?.compute;
398
+ if (!(!p || !m))
399
+ for (const h of o) {
400
+ const d = Number(m[h]);
401
+ Number.isFinite(d) && (p[h] += d);
402
+ }
403
+ });
404
+ }
405
+ return n;
406
+ }
407
+ function it(t) {
255
408
  return {
256
- async resolveCompute(a, e) {
257
- if (a) {
258
- const n = await a.getLayer(e.dataRef), o = await new v().gpgpuPipeline({
259
- collection: n,
260
- variableMapping: e.attributes,
261
- wgslBody: e.wglsFunction,
262
- ...e.outputColumnName && { resultField: e.outputColumnName },
263
- ...e.outputColumns && { outputColumns: e.outputColumns },
264
- ...e.attributeArrays && { attributeArrays: e.attributeArrays },
265
- ...e.attributeMatrices && { attributeMatrices: e.attributeMatrices },
266
- ...e.uniforms && { uniforms: e.uniforms },
267
- ...e.uniformArrays && { uniformArrays: e.uniformArrays },
268
- ...e.uniformMatrices && { uniformMatrices: e.uniformMatrices }
269
- });
270
- return t && t.set(e.dataRef, o), a;
409
+ async resolveCompute(e, r) {
410
+ if (e) {
411
+ const a = {};
412
+ for (const n of et(r)) {
413
+ const l = t?.get(n);
414
+ if (l) a[n] = l;
415
+ else if (n === r.dataRef) a[n] = await e.getLayer(n);
416
+ else
417
+ try {
418
+ a[n] = await e.getLayer(n);
419
+ } catch {
420
+ a[n] = void 0;
421
+ }
422
+ }
423
+ const s = new $(), o = await nt(r, a, (n) => s.gpgpuPipeline(n));
424
+ return t && t.set(r.dataRef, o), e;
271
425
  }
272
426
  }
273
427
  };
274
428
  }
275
- class V {
429
+ class st {
276
430
  _listeners = /* @__PURE__ */ new Map();
277
- on(a, e) {
278
- this._listeners.has(a) || this._listeners.set(a, /* @__PURE__ */ new Set());
279
- const n = this._listeners.get(a);
280
- return n.add(e), () => n.delete(e);
431
+ on(e, r) {
432
+ this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
433
+ const a = this._listeners.get(e);
434
+ return a.add(r), () => a.delete(r);
281
435
  }
282
436
  /** @internal */
283
- emit(a, e) {
284
- this._listeners.get(a)?.forEach((n) => n(e));
437
+ emit(e, r) {
438
+ this._listeners.get(e)?.forEach((a) => a(r));
285
439
  }
286
440
  }
287
- class X {
441
+ class mt {
288
442
  dataAdapter;
289
443
  mapAdapter;
290
444
  plotAdapter;
@@ -296,10 +450,10 @@ class X {
296
450
  _plotRegistry = /* @__PURE__ */ new Map();
297
451
  _fwdCleanups = [];
298
452
  _plotMapLinks = /* @__PURE__ */ new Map();
299
- interactions = new V();
300
- constructor(a) {
301
- const e = /* @__PURE__ */ new Map();
302
- this.dataAdapter = D(a, e), this.mapAdapter = U(a, this._mapRegistry, this._computeCache), this.plotAdapter = j(a, this._mapRegistry, this._plotRegistry, this._plotMapLinks, e), this.computeAdapter = H(this._computeCache);
453
+ interactions = new st();
454
+ constructor(e) {
455
+ const r = /* @__PURE__ */ new Map();
456
+ this.dataAdapter = W(e, r), this.mapAdapter = q(e, this._mapRegistry, this._computeCache), this.plotAdapter = Z(e, this._mapRegistry, this._plotRegistry, this._plotMapLinks, r), this.computeAdapter = it(this._computeCache);
303
457
  }
304
458
  /**
305
459
  * The coordinate reference system used internally by the autk workspace.
@@ -310,12 +464,12 @@ class X {
310
464
  * instead of hard-coding a CRS string.
311
465
  */
312
466
  get workspaceCrs() {
313
- return P;
467
+ return F;
314
468
  }
315
469
  get data() {
316
470
  return this._data;
317
471
  }
318
- async run(a) {
472
+ async run(e) {
319
473
  if (!this.dataAdapter)
320
474
  throw new Error("Database adapter not initialized. Please call the constructor first.");
321
475
  if (!this.mapAdapter)
@@ -324,8 +478,8 @@ class X {
324
478
  throw new Error("Plot adapter not initialized. Please call the constructor first.");
325
479
  if (!this.computeAdapter)
326
480
  throw new Error("Compute adapter not initialized. Please call the constructor first.");
327
- this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this.grammarEngine = B({
328
- spec: a,
481
+ this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this._computeCache.clear(), this.grammarEngine = H({
482
+ spec: e,
329
483
  adapters: {
330
484
  db: this.dataAdapter,
331
485
  map: this.mapAdapter,
@@ -333,89 +487,99 @@ class X {
333
487
  compute: this.computeAdapter
334
488
  }
335
489
  }), await this.grammarEngine.run(), this._rewireInteractions();
336
- const e = this.grammarEngine.context;
337
- if (!e) {
490
+ const r = this.grammarEngine.context;
491
+ if (!r) {
338
492
  console.warn("Grammar engine produced no data context."), this._data = {};
339
493
  return;
340
494
  }
341
- const n = {};
342
- for (const s of e.getLayersMetadata())
343
- Object.defineProperty(n, s.name, {
495
+ const a = {};
496
+ for (const s of r.getLayersMetadata())
497
+ Object.defineProperty(a, s.name, {
344
498
  get: () => {
345
499
  const o = this._computeCache.get(s.name);
346
- return o ? Promise.resolve(o) : e.getLayer(s.name);
500
+ return o ? Promise.resolve(o) : r.getLayer(s.name);
347
501
  },
348
502
  enumerable: !0,
349
503
  configurable: !0
350
504
  });
351
- this._data = n;
505
+ this._data = a;
352
506
  }
353
507
  /**
354
508
  * Highlights features on the map layer identified by `layerId`.
355
509
  * If that layer is linked to a plot via `mapRef`, the plot selection is updated too.
356
510
  */
357
- highlightOnMap(a, e) {
358
- this._mapRegistry.get(a)?.setHighlightedIds(a, e);
359
- for (const [n, s] of this._plotMapLinks)
360
- s === a && this._plotRegistry.get(n)?.setSelection(e);
511
+ highlightOnMap(e, r) {
512
+ this._mapRegistry.get(e)?.setHighlightedIds(e, r);
513
+ for (const [a, s] of this._plotMapLinks)
514
+ s === e && this._plotRegistry.get(a)?.setSelection(r);
361
515
  }
362
516
  /**
363
517
  * Clears highlighted features on the map layer identified by `layerId`.
364
518
  * If that layer is linked to a plot via `mapRef`, the plot selection is cleared too.
365
519
  */
366
- clearHighlightOnMap(a) {
367
- this._mapRegistry.get(a)?.clearHighlightedIds(a);
368
- for (const [e, n] of this._plotMapLinks)
369
- n === a && this._plotRegistry.get(e)?.setSelection([]);
520
+ clearHighlightOnMap(e) {
521
+ this._mapRegistry.get(e)?.clearHighlightedIds(e);
522
+ for (const [r, a] of this._plotMapLinks)
523
+ a === e && this._plotRegistry.get(r)?.setSelection([]);
370
524
  }
371
525
  /**
372
526
  * Clears the selection on the plot identified by `plotId` (its dataRef).
373
527
  * If that plot is linked to a map via `mapRef`, the map highlight is cleared too.
374
528
  */
375
- clearHighlightOnPlot(a) {
376
- this._plotRegistry.get(a)?.setSelection([]);
377
- const e = this._plotMapLinks.get(a);
378
- e && this._mapRegistry.get(e)?.clearHighlightedIds(e);
529
+ clearHighlightOnPlot(e) {
530
+ this._plotRegistry.get(e)?.setSelection([]);
531
+ const r = this._plotMapLinks.get(e);
532
+ r && this._mapRegistry.get(r)?.clearHighlightedIds(r);
379
533
  }
380
534
  /**
381
535
  * Applies a selection to the plot identified by `plotId` (its dataRef).
382
536
  * If that plot is linked to a map via `mapRef`, the map highlight is updated too.
383
537
  */
384
- setPlotSelection(a, e) {
385
- this._plotRegistry.get(a)?.setSelection(e);
386
- const n = this._plotMapLinks.get(a);
387
- n && this._mapRegistry.get(n)?.setHighlightedIds(n, e);
538
+ setPlotSelection(e, r) {
539
+ this._plotRegistry.get(e)?.setSelection(r);
540
+ const a = this._plotMapLinks.get(e);
541
+ a && this._mapRegistry.get(a)?.setHighlightedIds(a, r);
388
542
  }
389
543
  _rewireInteractions() {
390
- for (const e of this._fwdCleanups) e();
544
+ for (const r of this._fwdCleanups) r();
391
545
  this._fwdCleanups = [];
392
- const a = /* @__PURE__ */ new Set();
393
- for (const [e, n] of this._mapRegistry) {
394
- if (a.has(n)) continue;
395
- a.add(n);
546
+ const e = /* @__PURE__ */ new Set();
547
+ for (const [r, a] of this._mapRegistry) {
548
+ if (e.has(a)) continue;
549
+ e.add(a);
396
550
  const s = ({ selection: o }) => {
397
- this.interactions.emit("map:picking", { layerId: e, selection: o });
551
+ this.interactions.emit("map:picking", { layerId: r, selection: o });
398
552
  };
399
- n.events.on(b.PICKING, s), this._fwdCleanups.push(() => n.events.off(b.PICKING, s));
553
+ a.events.on(P.PICKING, s), this._fwdCleanups.push(() => a.events.off(P.PICKING, s));
400
554
  }
401
- for (const [e, n] of this._plotRegistry)
402
- for (const s of [_.CLICK, _.BRUSH, _.BRUSH_X, _.BRUSH_Y]) {
403
- const o = ({ selection: i }) => {
555
+ for (const [r, a] of this._plotRegistry)
556
+ for (const s of [A.CLICK, A.BRUSH, A.BRUSH_X, A.BRUSH_Y]) {
557
+ const o = ({ selection: n }) => {
404
558
  this.interactions.emit("plot:selection", {
405
- plotId: e,
559
+ plotId: r,
406
560
  event: s,
407
- selection: i
561
+ selection: n
408
562
  });
409
563
  };
410
- n.events.on(s, o), this._fwdCleanups.push(() => n.events.off(s, o));
564
+ a.events.on(s, o), this._fwdCleanups.push(() => a.events.off(s, o));
411
565
  }
412
566
  }
413
567
  }
414
568
  export {
415
- X as AutkGrammar,
416
- N as ColorMapInterpolator,
417
- V as GrammarEventEmitter,
418
- M as NormalizationMode,
419
- B as createEngine
569
+ mt as AutkGrammar,
570
+ Y as ColorMapInterpolator,
571
+ st as GrammarEventEmitter,
572
+ M as MAX_BATCHED_FEATURES,
573
+ O as NormalizationMode,
574
+ ot as buildBatchedUniforms,
575
+ et as computeLayerNames,
576
+ H as createEngine,
577
+ D as findIterateSource,
578
+ _ as isFromFeature,
579
+ tt as joinWgsl,
580
+ I as resolveComputeParams,
581
+ T as resolveUniformMatrices,
582
+ N as resolveUniforms,
583
+ nt as runCompute
420
584
  };
421
585
  //# sourceMappingURL=autk-grammar.js.map