@urban-toolkit/autk-grammar 0.2.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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 Q, DEFAULT_WORKSPACE_COORDINATE_FORMAT as F } from "@urban-toolkit/autk-db";
2
+ import { AutkMap as $, MapEvent as P } from "@urban-toolkit/autk-map";
3
+ import { AutkPlot as Y, PlotEvent as A } from "@urban-toolkit/autk-plot";
4
+ import { ColorMapDomainStrategy as w } from "@urban-toolkit/autk-core";
5
+ import { AutkComputeEngine as H } from "@urban-toolkit/autk-compute";
6
+ function V(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 n of e.data)
13
+ l = await r.db.resolveSource(l, n);
14
+ if (e.compute)
15
+ for (const n of e.compute)
16
+ l = await r.compute.resolveCompute(l, n);
17
+ if (e.map)
18
+ if (Array.isArray(e.map))
19
+ for (let n = 0; n < e.map.length; n++) {
20
+ let u = e.map[n];
21
+ await r.map.resolveMap(l, u, n);
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 n of e.plot)
28
+ await r.plot.resolvePlot(l, n);
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((n) => {
35
+ n();
36
36
  });
37
37
  }
38
38
  function i() {
39
39
  console.log("Function not implemented yet");
40
40
  }
41
41
  return { run: s, updatedSpec: o, destroy: i, get context() {
42
- return n;
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 k = /* @__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))(k || {}), O = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(O || {});
46
+ function W(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 J(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 i = a.getTablesMetadata();
57
57
  o.innerHTML += "<ul>";
58
- for (const p of i)
59
- o.innerHTML += `<li>${p.name}: (${p.source}, ${p.type}) </li>`;
58
+ for (const l of i)
59
+ o.innerHTML += `<li>${l.name}: (${l.source}, ${l.type}) </li>`;
60
60
  o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${i.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;
64
+ async resolveSource(a, s) {
65
+ let o = a;
66
+ o || (o = new Q(), await o.init());
67
+ let { type: i, ...l } = s;
68
68
  switch (i) {
69
69
  case "osm":
70
- return await o.loadOsm(G(p)), e(o, t), o;
70
+ return await o.loadOsm(W(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;
76
+ const n = l;
77
77
  let u;
78
- r.geojsonFileUrl ? u = await (await fetch(r.geojsonFileUrl)).json() : u = r.geojsonObject, a && u && a.set(r.outputTableName, u);
78
+ n.geojsonFileUrl ? u = await (await fetch(n.geojsonFileUrl)).json() : u = n.geojsonObject, e && u && e.set(n.outputTableName, u);
79
79
  const c = u ? (() => {
80
- const l = { ...r, geojsonObject: u };
81
- return delete l.geojsonFileUrl, l;
82
- })() : r;
80
+ const f = { ...n, geojsonObject: u };
81
+ return delete f.geojsonFileUrl, f;
82
+ })() : n;
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 (f) {
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}": ${f instanceof Error ? f.message : String(f)}. ${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 f = await o.getBoundingBoxFromLayer(c.outputTableName), p = 25e6;
93
+ if (!isFinite(f.minLon) || !isFinite(f.minLat) || !isFinite(f.maxLon) || !isFinite(f.maxLat) || Math.abs(f.minLon) > p || Math.abs(f.maxLon) > p || Math.abs(f.minLat) > p || Math.abs(f.maxLat) > p)
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: [${f.minLon}, ${f.minLat}, ${f.maxLon}, ${f.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 (f) {
98
+ if (f instanceof Error && f.message.includes("bounding box after transform")) throw f;
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 n = 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: n.tableJoinName,
106
+ near: { distance: n.near.distance },
107
+ outputTableName: n.outputTableName,
108
+ grid: n.grid,
109
+ ...n.groupBy && { groupBy: n.groupBy }
110
+ }), r(o, t), o;
111
111
  }
112
112
  case "join": {
113
- const r = p;
113
+ const n = 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: n.tableRootName,
116
+ tableJoinName: n.tableJoinName,
117
+ ...n.near && { near: n.near },
118
+ ...n.groupBy && { groupBy: n.groupBy }
119
+ }), e) {
120
+ const u = await o.getLayer(n.tableRootName);
121
+ e.set(n.tableRootName, u);
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: w.USER, params: e } : t?.mode === O.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
133
+ type: w.PERCENTILE,
134
134
  params: [t.lowerPercentile ?? 0, t.upperPercentile ?? 100]
135
- } : { type: E.PERCENTILE } : { type: E.MIN_MAX };
135
+ } : { type: w.PERCENTILE } : { type: w.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 X(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 q(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;
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 ?? "";
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)
146
+ for (let i = 0; i < a.length - 1; i++)
147
+ o[a[i]] = { ...o[a[i]] ?? {} }, o = o[a[i]];
148
+ return o[a[a.length - 1]] = r, s;
149
+ }
150
+ function z(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
+ }
154
+ function Z(t, e, r) {
155
+ async function a(s, o, i) {
156
+ let l = {};
157
+ for (const n of o.getTablesMetadata())
158
+ n.type !== void 0 && (l[n.name] = n.type);
159
+ for (const n of i.layerRefs) {
160
+ const u = n.dataRef, c = l[u], f = n.getFnv, p = r?.get(u) ?? await o.getLayer(u), m = c === "raster" ? p : {
161
+ ...p,
162
+ features: (p.features ?? []).filter((h) => h.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(u, { collection: m, type: "raster", property: z(m, f) }) : s.loadCollection(u, { collection: m, type: c }), n.opacity != null && s.updateRenderInfo(u, { opacity: n.opacity }), (n.isColorMap ?? (f != null && c !== "raster")) && s.updateRenderInfo(u, { isColorMap: !0 }), n.isPick && s.updateRenderInfo(u, { isPick: !0 }), n.isSkip && s.updateRenderInfo(u, { isSkip: !0 });
165
+ const { catchAllCategory: d, colorMapDomain: y } = n;
166
+ let E = m, R = y;
167
+ if (f && d && y?.length) {
168
+ const h = new Set(y);
169
+ E = {
170
+ ...m,
171
+ features: m.features.map((C) => {
172
+ const L = C.properties, M = X(L, f);
173
+ return M == null || !h.has(String(M)) ? { ...C, properties: q(L, f, d) } : C;
174
174
  })
175
- }, A = f.has(g) ? h : [...h, g];
175
+ }, R = h.has(d) ? y : [...y, d];
176
176
  }
177
- if (r.colorMapInterpolator) {
178
- const f = {
177
+ if (n.colorMapInterpolator) {
178
+ const h = {
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: n.colorMapInterpolator,
182
+ domainSpec: K(n.normalization, R)
183
183
  };
184
- s.updateRenderInfo(u, { colormap: { config: f }, isColorMap: !0 });
184
+ s.updateRenderInfo(u, { colormap: { config: h }, 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 (f && c !== "raster") {
187
+ const h = f.startsWith("properties.") ? f : `properties.${f}`;
188
+ s.updateThematic(u, { collection: E, property: h });
189
189
  }
190
190
  }
191
191
  }
192
192
  return {
193
193
  async resolveMap(s, o, i = 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[i]) : 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)
200
+ const n = new $(l);
201
+ if (o.style && n.style.setPredefinedStyle(o.style), await n.init(), await a(n, s, o), e)
202
202
  for (const u of o.layerRefs)
203
- a.set(u.dataRef, r);
204
- r.draw();
203
+ e.set(u.dataRef, n);
204
+ n.draw();
205
205
  }
206
206
  }
207
207
  };
208
208
  }
209
- function F(t) {
209
+ function tt(t) {
210
210
  return {
211
211
  scatter: "scatterplot",
212
212
  bar: "barchart",
@@ -217,16 +217,16 @@ function F(t) {
217
217
  heatmatrix: "heatmatrix"
218
218
  }[t];
219
219
  }
220
- function j(t, a, e, n, s) {
220
+ function et(t, e, r, a, s) {
221
221
  return {
222
222
  async resolvePlot(o, i) {
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),
224
+ const l = document.getElementById(t.plot);
225
+ if (!l) throw new Error(`Could not find plot target: ${t.plot}`);
226
+ const n = o;
227
+ if (!n) throw new Error("No data context available for plot.");
228
+ const u = s?.get(i.dataRef) ?? await n.getLayer(i.dataRef), c = i.events ?? [], f = new Y(l, {
229
+ type: tt(i.mark),
230
230
  collection: u,
231
231
  attributes: { axis: i.axis, ...i.color && { color: i.color } },
232
232
  labels: { axis: i.axis, title: i.title },
@@ -236,55 +236,222 @@ function j(t, a, e, n, s) {
236
236
  ...i.margins && { margins: i.margins },
237
237
  ...i.transform && { transform: i.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(i.dataRef, f), i.mapRef && a?.set(i.dataRef, i.mapRef), i.mapRef && e) {
240
+ const p = e.get(i.mapRef);
241
+ if (p) {
242
+ p.updateRenderInfo(i.mapRef, { isPick: !0 }), p.events.on(P.PICKING, ({ selection: m }) => {
243
+ f.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
+ f.events.on(m, ({ selection: g }) => {
247
+ p.setHighlightedIds(i.mapRef, g);
248
248
  });
249
249
  }
250
250
  }
251
251
  }
252
252
  };
253
253
  }
254
- function H(t) {
254
+ const G = 134217728, rt = 4, ot = 32;
255
+ function at(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 b(t, e) {
263
+ return t instanceof Map ? t.get(e) : t[e];
264
+ }
265
+ function S(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 D(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 nt(t) {
279
+ return [.../* @__PURE__ */ new Set([t.dataRef, ...D(t).map((e) => e.fromFeature.layer)])];
280
+ }
281
+ function j(t) {
282
+ for (const e of D(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 x(t, e, r) {
289
+ const a = t.fromFeature, s = r !== void 0 && a.iterate === "all" ? r : a.index ?? 0, o = b(e, a.layer)?.features?.[s];
290
+ return o ? S(o, a.path) : void 0;
291
+ }
292
+ function v(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 i = Number(x(o, e, r) ?? NaN);
301
+ Number.isFinite(i) ? a[s] = i : typeof o.default == "number" && (a[s] = o.default);
302
+ }
303
+ return a;
304
+ }
305
+ function N(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 i = x(o, e, r), l = Array.isArray(i) ? i : Array.isArray(o.default) ? o.default : void 0;
314
+ if (!l) continue;
315
+ const n = o.cols ?? (Array.isArray(l[0]) ? l[0].length : 0);
316
+ n > 0 ? a[s] = { data: l, cols: n } : console.warn(`[autk-grammar] uniform matrix "${s}" has no column count; entry dropped`);
317
+ }
318
+ return a;
319
+ }
320
+ function it(t) {
321
+ return t != null && !(typeof t == "number" && !Number.isFinite(t));
322
+ }
323
+ function I(t) {
324
+ return _(t) && t.fromFeature.iterate === "batched";
325
+ }
326
+ function U(t, e) {
327
+ return Object.values(e ?? {}).some(I) ? ot : Object.values(t ?? {}).some(I) ? rt : 0;
328
+ }
329
+ function st(t, e, r = G) {
330
+ const a = U(t, e);
331
+ return a > 0 ? Math.floor(r / a) : Number.POSITIVE_INFINITY;
332
+ }
333
+ function lt(t, e, r, a = G) {
334
+ const s = {}, o = {}, i = [];
335
+ for (const n of [t, e])
336
+ for (const u of Object.values(n ?? {}))
337
+ _(u) && u.fromFeature.iterate === "batched" && u.fromFeature.required && i.push(u.fromFeature.path);
338
+ if (i.length > 0) {
339
+ const n = r.length;
340
+ r = r.filter((u) => i.every((c) => it(S(u, c)))), r.length < n && console.info(`[autk-grammar] batched compute dropped ${n - r.length} feature(s) missing ${i.join(", ")}`);
341
+ }
342
+ const l = st(t, e, a);
343
+ r.length > l && (console.warn(
344
+ `[autk-grammar] batched compute capped at ${l} features (got ${r.length}): its largest packed array takes ${U(t, e)} B per feature, and a storage buffer binding holds ${a} B`
345
+ ), r = r.slice(0, l));
346
+ for (const [n, u] of Object.entries(t ?? {}))
347
+ if (_(u) && u.fromFeature.iterate === "batched") {
348
+ const c = typeof u.default == "number" ? u.default : void 0;
349
+ o[n] = r.map((f) => {
350
+ const p = Number(S(f, u.fromFeature.path) ?? c);
351
+ return Number.isFinite(p) ? p : 0;
352
+ });
353
+ } else typeof u == "number" && (s[n] = u);
354
+ for (const [n, u] of Object.entries(e ?? {})) {
355
+ if (!_(u) || u.fromFeature.iterate !== "batched") continue;
356
+ const c = [];
357
+ for (const f of r) {
358
+ const p = S(f, u.fromFeature.path);
359
+ let m = 1 / 0, g = 1 / 0, d = -1 / 0, y = -1 / 0;
360
+ if (Array.isArray(p))
361
+ for (const E of p) {
362
+ if (!Array.isArray(E) || E.length < 2) continue;
363
+ const R = Number(E[0]), h = Number(E[1]);
364
+ !Number.isFinite(R) || !Number.isFinite(h) || (m = Math.min(m, R), g = Math.min(g, h), d = Math.max(d, R), y = Math.max(y, h));
365
+ }
366
+ Number.isFinite(m) || (m = 0, g = 0, d = 0, y = 0), c.push(m, g, d, g, d, y, m, y);
367
+ }
368
+ o[n] = c;
369
+ }
370
+ return s.num_features = r.length, { uniforms: s, uniformArrays: o };
371
+ }
372
+ function B(t, e, r) {
373
+ const a = b(e, t.dataRef);
374
+ if (!a) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
375
+ const s = {
376
+ collection: a,
377
+ variableMapping: t.attributes,
378
+ wgslBody: at(t.wglsFunction)
379
+ };
380
+ 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);
381
+ const o = j(t);
382
+ if (o?.mode === "batched") {
383
+ const u = b(e, o.layer)?.features ?? [], c = lt(t.uniforms, t.uniformMatrices, u), f = v(T(t.uniforms), e) ?? {}, p = N(T(t.uniformMatrices), e);
384
+ return s.uniforms = { ...f, ...c.uniforms }, s.uniformArrays = { ...s.uniformArrays ?? {}, ...c.uniformArrays }, p && Object.keys(p).length > 0 && (s.uniformMatrices = p), s;
385
+ }
386
+ const i = o?.mode === "all" ? r : void 0, l = v(t.uniforms, e, i), n = N(t.uniformMatrices, e, i);
387
+ return l && (s.uniforms = l), n && (s.uniformMatrices = n), s;
388
+ }
389
+ function T(t) {
390
+ if (t)
391
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => !(_(e) && e.fromFeature.iterate === "batched")));
392
+ }
393
+ function ut(t) {
394
+ return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
395
+ }
396
+ async function ft(t, e, r) {
397
+ const a = j(t);
398
+ if (a?.mode !== "all") return r(B(t, e));
399
+ const s = b(e, t.dataRef);
400
+ if (!s) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
401
+ const o = ut(t), i = structuredClone(s);
402
+ for (const n of i.features) {
403
+ const u = n.properties ??= {}, c = u.compute ??= {};
404
+ for (const f of o) c[f] = 0;
405
+ }
406
+ const l = b(e, a.layer)?.features?.length ?? 0;
407
+ for (let n = 0; n < l; n++) {
408
+ const u = await r({ ...B(t, e, n), collection: i });
409
+ i.features.forEach((c, f) => {
410
+ const p = c.properties?.compute, m = u.features[f]?.properties?.compute;
411
+ if (!(!p || !m))
412
+ for (const g of o) {
413
+ const d = Number(m[g]);
414
+ Number.isFinite(d) && (p[g] += d);
415
+ }
416
+ });
417
+ }
418
+ return i;
419
+ }
420
+ function ct(t) {
255
421
  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;
422
+ async resolveCompute(e, r) {
423
+ if (e) {
424
+ const a = {};
425
+ for (const i of nt(r)) {
426
+ const l = t?.get(i);
427
+ if (l) a[i] = l;
428
+ else if (i === r.dataRef) a[i] = await e.getLayer(i);
429
+ else
430
+ try {
431
+ a[i] = await e.getLayer(i);
432
+ } catch {
433
+ a[i] = void 0;
434
+ }
435
+ }
436
+ const s = new H(), o = await ft(r, a, (i) => s.gpgpuPipeline(i));
437
+ return t && t.set(r.dataRef, o), e;
271
438
  }
272
439
  }
273
440
  };
274
441
  }
275
- class V {
442
+ class pt {
276
443
  _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);
444
+ on(e, r) {
445
+ this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
446
+ const a = this._listeners.get(e);
447
+ return a.add(r), () => a.delete(r);
281
448
  }
282
449
  /** @internal */
283
- emit(a, e) {
284
- this._listeners.get(a)?.forEach((n) => n(e));
450
+ emit(e, r) {
451
+ this._listeners.get(e)?.forEach((a) => a(r));
285
452
  }
286
453
  }
287
- class X {
454
+ class _t {
288
455
  dataAdapter;
289
456
  mapAdapter;
290
457
  plotAdapter;
@@ -296,10 +463,10 @@ class X {
296
463
  _plotRegistry = /* @__PURE__ */ new Map();
297
464
  _fwdCleanups = [];
298
465
  _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);
466
+ interactions = new pt();
467
+ constructor(e) {
468
+ const r = /* @__PURE__ */ new Map();
469
+ this.dataAdapter = J(e, r), this.mapAdapter = Z(e, this._mapRegistry, this._computeCache), this.plotAdapter = et(e, this._mapRegistry, this._plotRegistry, this._plotMapLinks, r), this.computeAdapter = ct(this._computeCache);
303
470
  }
304
471
  /**
305
472
  * The coordinate reference system used internally by the autk workspace.
@@ -310,12 +477,12 @@ class X {
310
477
  * instead of hard-coding a CRS string.
311
478
  */
312
479
  get workspaceCrs() {
313
- return P;
480
+ return F;
314
481
  }
315
482
  get data() {
316
483
  return this._data;
317
484
  }
318
- async run(a) {
485
+ async run(e) {
319
486
  if (!this.dataAdapter)
320
487
  throw new Error("Database adapter not initialized. Please call the constructor first.");
321
488
  if (!this.mapAdapter)
@@ -324,8 +491,8 @@ class X {
324
491
  throw new Error("Plot adapter not initialized. Please call the constructor first.");
325
492
  if (!this.computeAdapter)
326
493
  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,
494
+ this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this._computeCache.clear(), this.grammarEngine = V({
495
+ spec: e,
329
496
  adapters: {
330
497
  db: this.dataAdapter,
331
498
  map: this.mapAdapter,
@@ -333,89 +500,100 @@ class X {
333
500
  compute: this.computeAdapter
334
501
  }
335
502
  }), await this.grammarEngine.run(), this._rewireInteractions();
336
- const e = this.grammarEngine.context;
337
- if (!e) {
503
+ const r = this.grammarEngine.context;
504
+ if (!r) {
338
505
  console.warn("Grammar engine produced no data context."), this._data = {};
339
506
  return;
340
507
  }
341
- const n = {};
342
- for (const s of e.getLayersMetadata())
343
- Object.defineProperty(n, s.name, {
508
+ const a = {};
509
+ for (const s of r.getLayersMetadata())
510
+ Object.defineProperty(a, s.name, {
344
511
  get: () => {
345
512
  const o = this._computeCache.get(s.name);
346
- return o ? Promise.resolve(o) : e.getLayer(s.name);
513
+ return o ? Promise.resolve(o) : r.getLayer(s.name);
347
514
  },
348
515
  enumerable: !0,
349
516
  configurable: !0
350
517
  });
351
- this._data = n;
518
+ this._data = a;
352
519
  }
353
520
  /**
354
521
  * Highlights features on the map layer identified by `layerId`.
355
522
  * If that layer is linked to a plot via `mapRef`, the plot selection is updated too.
356
523
  */
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);
524
+ highlightOnMap(e, r) {
525
+ this._mapRegistry.get(e)?.setHighlightedIds(e, r);
526
+ for (const [a, s] of this._plotMapLinks)
527
+ s === e && this._plotRegistry.get(a)?.setSelection(r);
361
528
  }
362
529
  /**
363
530
  * Clears highlighted features on the map layer identified by `layerId`.
364
531
  * If that layer is linked to a plot via `mapRef`, the plot selection is cleared too.
365
532
  */
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([]);
533
+ clearHighlightOnMap(e) {
534
+ this._mapRegistry.get(e)?.clearHighlightedIds(e);
535
+ for (const [r, a] of this._plotMapLinks)
536
+ a === e && this._plotRegistry.get(r)?.setSelection([]);
370
537
  }
371
538
  /**
372
539
  * Clears the selection on the plot identified by `plotId` (its dataRef).
373
540
  * If that plot is linked to a map via `mapRef`, the map highlight is cleared too.
374
541
  */
375
- clearHighlightOnPlot(a) {
376
- this._plotRegistry.get(a)?.setSelection([]);
377
- const e = this._plotMapLinks.get(a);
378
- e && this._mapRegistry.get(e)?.clearHighlightedIds(e);
542
+ clearHighlightOnPlot(e) {
543
+ this._plotRegistry.get(e)?.setSelection([]);
544
+ const r = this._plotMapLinks.get(e);
545
+ r && this._mapRegistry.get(r)?.clearHighlightedIds(r);
379
546
  }
380
547
  /**
381
548
  * Applies a selection to the plot identified by `plotId` (its dataRef).
382
549
  * If that plot is linked to a map via `mapRef`, the map highlight is updated too.
383
550
  */
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);
551
+ setPlotSelection(e, r) {
552
+ this._plotRegistry.get(e)?.setSelection(r);
553
+ const a = this._plotMapLinks.get(e);
554
+ a && this._mapRegistry.get(a)?.setHighlightedIds(a, r);
388
555
  }
389
556
  _rewireInteractions() {
390
- for (const e of this._fwdCleanups) e();
557
+ for (const r of this._fwdCleanups) r();
391
558
  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);
559
+ const e = /* @__PURE__ */ new Set();
560
+ for (const [r, a] of this._mapRegistry) {
561
+ if (e.has(a)) continue;
562
+ e.add(a);
396
563
  const s = ({ selection: o }) => {
397
- this.interactions.emit("map:picking", { layerId: e, selection: o });
564
+ this.interactions.emit("map:picking", { layerId: r, selection: o });
398
565
  };
399
- n.events.on(b.PICKING, s), this._fwdCleanups.push(() => n.events.off(b.PICKING, s));
566
+ a.events.on(P.PICKING, s), this._fwdCleanups.push(() => a.events.off(P.PICKING, s));
400
567
  }
401
- for (const [e, n] of this._plotRegistry)
402
- for (const s of [_.CLICK, _.BRUSH, _.BRUSH_X, _.BRUSH_Y]) {
568
+ for (const [r, a] of this._plotRegistry)
569
+ for (const s of [A.CLICK, A.BRUSH, A.BRUSH_X, A.BRUSH_Y]) {
403
570
  const o = ({ selection: i }) => {
404
571
  this.interactions.emit("plot:selection", {
405
- plotId: e,
572
+ plotId: r,
406
573
  event: s,
407
574
  selection: i
408
575
  });
409
576
  };
410
- n.events.on(s, o), this._fwdCleanups.push(() => n.events.off(s, o));
577
+ a.events.on(s, o), this._fwdCleanups.push(() => a.events.off(s, o));
411
578
  }
412
579
  }
413
580
  }
414
581
  export {
415
- X as AutkGrammar,
416
- N as ColorMapInterpolator,
417
- V as GrammarEventEmitter,
418
- M as NormalizationMode,
419
- B as createEngine
582
+ _t as AutkGrammar,
583
+ k as ColorMapInterpolator,
584
+ pt as GrammarEventEmitter,
585
+ O as NormalizationMode,
586
+ G as STORAGE_BUFFER_BINDING_SIZE,
587
+ lt as buildBatchedUniforms,
588
+ nt as computeLayerNames,
589
+ V as createEngine,
590
+ j as findIterateSource,
591
+ _ as isFromFeature,
592
+ at as joinWgsl,
593
+ st as maxBatchedFeatures,
594
+ B as resolveComputeParams,
595
+ N as resolveUniformMatrices,
596
+ v as resolveUniforms,
597
+ ft as runCompute
420
598
  };
421
599
  //# sourceMappingURL=autk-grammar.js.map