@urban-toolkit/autk-grammar 0.3.0 → 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,124 +1,124 @@
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) {
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
7
  const { spec: e, adapters: r } = t;
8
8
  let a;
9
9
  async function s() {
10
10
  let l;
11
11
  if (e.data)
12
- for (const i of e.data)
13
- l = await r.db.resolveSource(l, i);
12
+ for (const n of e.data)
13
+ l = await r.db.resolveSource(l, n);
14
14
  if (e.compute)
15
- for (const i of e.compute)
16
- l = await r.compute.resolveCompute(l, i);
15
+ for (const n of e.compute)
16
+ l = await r.compute.resolveCompute(l, n);
17
17
  if (e.map)
18
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);
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
24
  await r.map.resolveMap(l, e.map);
25
25
  if (e.plot)
26
26
  if (Array.isArray(e.plot))
27
- for (const i of e.plot)
28
- await r.plot.resolvePlot(l, i);
27
+ for (const n of e.plot)
28
+ await r.plot.resolvePlot(l, n);
29
29
  else
30
30
  await r.plot.resolvePlot(l, e.plot);
31
31
  a = l;
32
32
  }
33
33
  function o(l) {
34
- return console.log("Spec to update", l), new Promise((i) => {
35
- i();
34
+ return console.log("Spec to update", l), new Promise((n) => {
35
+ n();
36
36
  });
37
37
  }
38
- function n() {
38
+ function i() {
39
39
  console.log("Function not implemented yet");
40
40
  }
41
- return { run: s, updatedSpec: o, destroy: n, get context() {
41
+ return { run: s, updatedSpec: o, destroy: i, get context() {
42
42
  return a;
43
43
  } };
44
44
  }
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) {
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
47
  const { autoLoadLayers: e, ...r } = t;
48
48
  return { ...r, autoLoadLayers: { layers: e?.layers ?? [] } };
49
49
  }
50
- function W(t, e) {
50
+ function J(t, e) {
51
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 n = a.getTablesMetadata();
56
+ const i = a.getTablesMetadata();
57
57
  o.innerHTML += "<ul>";
58
- for (const l of n)
58
+ for (const l of i)
59
59
  o.innerHTML += `<li>${l.name}: (${l.source}, ${l.type}) </li>`;
60
- o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${n.length}</p>`;
60
+ o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${i.length}</p>`;
61
61
  }
62
62
  }
63
63
  return {
64
64
  async resolveSource(a, s) {
65
65
  let o = a;
66
- o || (o = new x(), await o.init());
67
- let { type: n, ...l } = s;
68
- switch (n) {
66
+ o || (o = new Q(), await o.init());
67
+ let { type: i, ...l } = s;
68
+ switch (i) {
69
69
  case "osm":
70
- return await o.loadOsm(V(l)), r(o, t), o;
70
+ return await o.loadOsm(W(l)), r(o, t), o;
71
71
  case "csv":
72
72
  return await o.loadCsv(l), r(o, t), o;
73
73
  case "json":
74
74
  return await o.loadJson(l), r(o, t), o;
75
75
  case "geojson": {
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;
76
+ const n = l;
77
+ let u;
78
+ n.geojsonFileUrl ? u = await (await fetch(n.geojsonFileUrl)).json() : u = n.geojsonObject, e && u && e.set(n.outputTableName, u);
79
+ const c = u ? (() => {
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 (u) {
85
+ } catch (f) {
86
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}": ${u instanceof Error ? u.message : String(u)}. ${p}. 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 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)
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: [${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.`
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 (u) {
98
- if (u instanceof Error && u.message.includes("bounding box after transform")) throw u;
97
+ } catch (f) {
98
+ if (f instanceof Error && f.message.includes("bounding box after transform")) throw f;
99
99
  }
100
100
  return r(o, t), o;
101
101
  }
102
102
  case "heatmap": {
103
- const i = l;
103
+ const n = l;
104
104
  return await o.buildHeatmap({
105
- tableJoinName: i.tableJoinName,
106
- near: { distance: i.near.distance },
107
- outputTableName: i.outputTableName,
108
- grid: i.grid,
109
- ...i.groupBy && { groupBy: i.groupBy }
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
110
  }), r(o, t), o;
111
111
  }
112
112
  case "join": {
113
- const i = l;
113
+ const n = l;
114
114
  if (await o.spatialQuery({
115
- tableRootName: i.tableRootName,
116
- tableJoinName: i.tableJoinName,
117
- ...i.near && { near: i.near },
118
- ...i.groupBy && { groupBy: i.groupBy }
115
+ tableRootName: n.tableRootName,
116
+ tableJoinName: n.tableJoinName,
117
+ ...n.near && { near: n.near },
118
+ ...n.groupBy && { groupBy: n.groupBy }
119
119
  }), e) {
120
- const f = await o.getLayer(i.tableRootName);
121
- e.set(i.tableRootName, f);
120
+ const u = await o.getLayer(n.tableRootName);
121
+ e.set(n.tableRootName, u);
122
122
  }
123
123
  return r(o, t), o;
124
124
  }
@@ -128,85 +128,85 @@ function W(t, e) {
128
128
  }
129
129
  };
130
130
  }
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,
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: b.PERCENTILE } : { type: b.MIN_MAX };
135
+ } : { type: w.PERCENTILE } : { type: w.MIN_MAX };
136
136
  }
137
- function J(t, e) {
137
+ function X(t, e) {
138
138
  return e.split(".").reduce((r, a) => {
139
139
  if (!(r == null || typeof r != "object"))
140
140
  return r[a];
141
141
  }, t);
142
142
  }
143
- function K(t, e, r) {
143
+ function q(t, e, r) {
144
144
  const a = e.split("."), s = { ...t };
145
145
  let o = s;
146
- for (let n = 0; n < a.length - 1; n++)
147
- o[a[n]] = { ...o[a[n]] ?? {} }, o = o[a[n]];
146
+ for (let i = 0; i < a.length - 1; i++)
147
+ o[a[i]] = { ...o[a[i]] ?? {} }, o = o[a[i]];
148
148
  return o[a[a.length - 1]] = r, s;
149
149
  }
150
- function X(t, e) {
150
+ function z(t, e) {
151
151
  const a = t.features?.[0]?.properties?.bands ?? [];
152
152
  return a.find((o) => o.id === e || o.label === e?.replace(/\./g, "_"))?.id ?? a[0]?.id ?? e ?? "";
153
153
  }
154
- function q(t, e, r) {
155
- async function a(s, o, n) {
154
+ function Z(t, e, r) {
155
+ async function a(s, o, i) {
156
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 : {
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
161
  ...p,
162
- features: (p.features ?? []).filter((y) => y.geometry != null)
162
+ features: (p.features ?? []).filter((h) => h.geometry != null)
163
163
  };
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);
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
169
  E = {
170
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;
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
- }, L = y.has(d) ? g : [...g, d];
175
+ }, R = h.has(d) ? y : [...y, d];
176
176
  }
177
- if (i.colorMapInterpolator) {
178
- const y = {
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: i.colorMapInterpolator,
182
- domainSpec: k(i.normalization, L)
181
+ interpolator: n.colorMapInterpolator,
182
+ domainSpec: K(n.normalization, R)
183
183
  };
184
- s.updateRenderInfo(f, { colormap: { config: y }, isColorMap: !0 });
184
+ s.updateRenderInfo(u, { colormap: { config: h }, isColorMap: !0 });
185
185
  }
186
- if (u && c !== "raster") {
187
- const y = u.startsWith("properties.") ? u : `properties.${u}`;
188
- s.updateThematic(f, { collection: E, property: y });
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
- async resolveMap(s, o, n = 0) {
193
+ async resolveMap(s, o, i = 0) {
194
194
  if (t && t.map && s) {
195
195
  let l;
196
- if (Array.isArray(t.map) ? l = document.getElementById(t.map[n]) : l = document.getElementById(t.map), !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
198
  if (!(l instanceof HTMLCanvasElement))
199
199
  throw new Error("Target for map is not a canvas: " + t.map);
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();
200
+ const n = new $(l);
201
+ if (o.style && n.style.setPredefinedStyle(o.style), await n.init(), await a(n, s, o), e)
202
+ for (const u of o.layerRefs)
203
+ e.set(u.dataRef, n);
204
+ n.draw();
205
205
  }
206
206
  }
207
207
  };
208
208
  }
209
- function z(t) {
209
+ function tt(t) {
210
210
  return {
211
211
  scatter: "scatterplot",
212
212
  bar: "barchart",
@@ -217,79 +217,79 @@ function z(t) {
217
217
  heatmatrix: "heatmatrix"
218
218
  }[t];
219
219
  }
220
- function Z(t, e, r, a, s) {
220
+ function et(t, e, r, a, s) {
221
221
  return {
222
- async resolvePlot(o, n) {
222
+ async resolvePlot(o, i) {
223
223
  if (!t || !t.plot) return;
224
224
  const l = document.getElementById(t.plot);
225
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 },
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
+ collection: u,
231
+ attributes: { axis: i.axis, ...i.color && { color: i.color } },
232
+ labels: { axis: i.axis, title: i.title },
233
233
  events: c,
234
- ...n.width && { width: n.width },
235
- ...n.height && { height: n.height },
236
- ...n.margins && { margins: n.margins },
237
- ...n.transform && { transform: n.transform }
234
+ ...i.width && { width: i.width },
235
+ ...i.height && { height: i.height },
236
+ ...i.margins && { margins: i.margins },
237
+ ...i.transform && { transform: i.transform }
238
238
  });
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);
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
241
  if (p) {
242
- p.updateRenderInfo(n.mapRef, { isPick: !0 }), p.events.on(P.PICKING, ({ selection: m }) => {
243
- u.setSelection(m);
242
+ p.updateRenderInfo(i.mapRef, { isPick: !0 }), p.events.on(P.PICKING, ({ selection: m }) => {
243
+ f.setSelection(m);
244
244
  });
245
245
  for (const m of c)
246
- u.events.on(m, ({ selection: h }) => {
247
- p.setHighlightedIds(n.mapRef, h);
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
- const M = 2e3;
255
- function tt(t) {
254
+ const G = 134217728, rt = 4, ot = 32;
255
+ function at(t) {
256
256
  return Array.isArray(t) ? t.join(`
257
257
  `) : t;
258
258
  }
259
259
  function _(t) {
260
260
  return !!t && typeof t == "object" && !Array.isArray(t) && typeof t.fromFeature == "object" && t.fromFeature !== null;
261
261
  }
262
- function R(t, e) {
262
+ function b(t, e) {
263
263
  return t instanceof Map ? t.get(e) : t[e];
264
264
  }
265
- function w(t, e) {
265
+ function S(t, e) {
266
266
  return e.split(".").reduce((r, a) => {
267
267
  if (!(r == null || typeof r != "object"))
268
268
  return r[a];
269
269
  }, t);
270
270
  }
271
- function G(t) {
271
+ function D(t) {
272
272
  const e = [];
273
273
  for (const r of [t.uniforms, t.uniformMatrices])
274
274
  for (const a of Object.values(r ?? {}))
275
275
  _(a) && e.push(a);
276
276
  return e;
277
277
  }
278
- function et(t) {
279
- return [.../* @__PURE__ */ new Set([t.dataRef, ...G(t).map((e) => e.fromFeature.layer)])];
278
+ function nt(t) {
279
+ return [.../* @__PURE__ */ new Set([t.dataRef, ...D(t).map((e) => e.fromFeature.layer)])];
280
280
  }
281
- function D(t) {
282
- for (const e of G(t)) {
281
+ function j(t) {
282
+ for (const e of D(t)) {
283
283
  const { iterate: r, layer: a } = e.fromFeature;
284
284
  if (r === "all" || r === "batched") return { mode: r, layer: a };
285
285
  }
286
286
  return null;
287
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;
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
291
  }
292
- function N(t, e, r) {
292
+ function v(t, e, r) {
293
293
  if (!t) return;
294
294
  const a = {};
295
295
  for (const [s, o] of Object.entries(t)) {
@@ -297,12 +297,12 @@ function N(t, e, r) {
297
297
  a[s] = o;
298
298
  continue;
299
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);
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
302
  }
303
303
  return a;
304
304
  }
305
- function T(t, e, r) {
305
+ function N(t, e, r) {
306
306
  if (!t) return;
307
307
  const a = {};
308
308
  for (const [s, o] of Object.entries(t)) {
@@ -310,123 +310,136 @@ function T(t, e, r) {
310
310
  a[s] = o;
311
311
  continue;
312
312
  }
313
- const n = j(o, e, r), l = Array.isArray(n) ? n : Array.isArray(o.default) ? o.default : void 0;
313
+ const i = x(o, e, r), l = Array.isArray(i) ? i : Array.isArray(o.default) ? o.default : void 0;
314
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`);
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
317
  }
318
318
  return a;
319
319
  }
320
- function rt(t) {
320
+ function it(t) {
321
321
  return t != null && !(typeof t == "number" && !Number.isFinite(t));
322
322
  }
323
- function ot(t, e, r) {
324
- const a = {}, s = {}, o = [];
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 = [];
325
335
  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) {
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) {
329
339
  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(", ")}`);
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(", ")}`);
331
341
  }
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;
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;
339
352
  });
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 = [];
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 = [];
344
357
  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));
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));
352
365
  }
353
- Number.isFinite(u) || (u = 0, p = 0, m = 0, h = 0), i.push(u, p, m, p, m, h, u, h);
366
+ Number.isFinite(m) || (m = 0, g = 0, d = 0, y = 0), c.push(m, g, d, g, d, y, m, y);
354
367
  }
355
- s[n] = i;
368
+ o[n] = c;
356
369
  }
357
- return a.num_features = r.length, { uniforms: a, uniformArrays: s };
370
+ return s.num_features = r.length, { uniforms: s, uniformArrays: o };
358
371
  }
359
- function I(t, e, r) {
360
- const a = R(e, t.dataRef);
372
+ function B(t, e, r) {
373
+ const a = b(e, t.dataRef);
361
374
  if (!a) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
362
375
  const s = {
363
376
  collection: a,
364
377
  variableMapping: t.attributes,
365
- wgslBody: tt(t.wglsFunction)
378
+ wgslBody: at(t.wglsFunction)
366
379
  };
367
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);
368
- const o = D(t);
381
+ const o = j(t);
369
382
  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;
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;
372
385
  }
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;
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;
375
388
  }
376
- function B(t) {
389
+ function T(t) {
377
390
  if (t)
378
391
  return Object.fromEntries(Object.entries(t).filter(([, e]) => !(_(e) && e.fromFeature.iterate === "batched")));
379
392
  }
380
- function at(t) {
393
+ function ut(t) {
381
394
  return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
382
395
  }
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);
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);
387
400
  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;
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;
392
405
  }
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;
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;
398
411
  if (!(!p || !m))
399
- for (const h of o) {
400
- const d = Number(m[h]);
401
- Number.isFinite(d) && (p[h] += d);
412
+ for (const g of o) {
413
+ const d = Number(m[g]);
414
+ Number.isFinite(d) && (p[g] += d);
402
415
  }
403
416
  });
404
417
  }
405
- return n;
418
+ return i;
406
419
  }
407
- function it(t) {
420
+ function ct(t) {
408
421
  return {
409
422
  async resolveCompute(e, r) {
410
423
  if (e) {
411
424
  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);
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);
416
429
  else
417
430
  try {
418
- a[n] = await e.getLayer(n);
431
+ a[i] = await e.getLayer(i);
419
432
  } catch {
420
- a[n] = void 0;
433
+ a[i] = void 0;
421
434
  }
422
435
  }
423
- const s = new $(), o = await nt(r, a, (n) => s.gpgpuPipeline(n));
436
+ const s = new H(), o = await ft(r, a, (i) => s.gpgpuPipeline(i));
424
437
  return t && t.set(r.dataRef, o), e;
425
438
  }
426
439
  }
427
440
  };
428
441
  }
429
- class st {
442
+ class pt {
430
443
  _listeners = /* @__PURE__ */ new Map();
431
444
  on(e, r) {
432
445
  this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
@@ -438,7 +451,7 @@ class st {
438
451
  this._listeners.get(e)?.forEach((a) => a(r));
439
452
  }
440
453
  }
441
- class mt {
454
+ class _t {
442
455
  dataAdapter;
443
456
  mapAdapter;
444
457
  plotAdapter;
@@ -450,10 +463,10 @@ class mt {
450
463
  _plotRegistry = /* @__PURE__ */ new Map();
451
464
  _fwdCleanups = [];
452
465
  _plotMapLinks = /* @__PURE__ */ new Map();
453
- interactions = new st();
466
+ interactions = new pt();
454
467
  constructor(e) {
455
468
  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);
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);
457
470
  }
458
471
  /**
459
472
  * The coordinate reference system used internally by the autk workspace.
@@ -478,7 +491,7 @@ class mt {
478
491
  throw new Error("Plot adapter not initialized. Please call the constructor first.");
479
492
  if (!this.computeAdapter)
480
493
  throw new Error("Compute adapter not initialized. Please call the constructor first.");
481
- this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this._computeCache.clear(), this.grammarEngine = H({
494
+ this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this._computeCache.clear(), this.grammarEngine = V({
482
495
  spec: e,
483
496
  adapters: {
484
497
  db: this.dataAdapter,
@@ -554,11 +567,11 @@ class mt {
554
567
  }
555
568
  for (const [r, a] of this._plotRegistry)
556
569
  for (const s of [A.CLICK, A.BRUSH, A.BRUSH_X, A.BRUSH_Y]) {
557
- const o = ({ selection: n }) => {
570
+ const o = ({ selection: i }) => {
558
571
  this.interactions.emit("plot:selection", {
559
572
  plotId: r,
560
573
  event: s,
561
- selection: n
574
+ selection: i
562
575
  });
563
576
  };
564
577
  a.events.on(s, o), this._fwdCleanups.push(() => a.events.off(s, o));
@@ -566,20 +579,21 @@ class mt {
566
579
  }
567
580
  }
568
581
  export {
569
- mt as AutkGrammar,
570
- Y as ColorMapInterpolator,
571
- st as GrammarEventEmitter,
572
- M as MAX_BATCHED_FEATURES,
582
+ _t as AutkGrammar,
583
+ k as ColorMapInterpolator,
584
+ pt as GrammarEventEmitter,
573
585
  O as NormalizationMode,
574
- ot as buildBatchedUniforms,
575
- et as computeLayerNames,
576
- H as createEngine,
577
- D as findIterateSource,
586
+ G as STORAGE_BUFFER_BINDING_SIZE,
587
+ lt as buildBatchedUniforms,
588
+ nt as computeLayerNames,
589
+ V as createEngine,
590
+ j as findIterateSource,
578
591
  _ as isFromFeature,
579
- tt as joinWgsl,
580
- I as resolveComputeParams,
581
- T as resolveUniformMatrices,
582
- N as resolveUniforms,
583
- nt as runCompute
592
+ at as joinWgsl,
593
+ st as maxBatchedFeatures,
594
+ B as resolveComputeParams,
595
+ N as resolveUniformMatrices,
596
+ v as resolveUniforms,
597
+ ft as runCompute
584
598
  };
585
599
  //# sourceMappingURL=autk-grammar.js.map