@toclocoinc/lattice-grid 1.74.0 → 1.75.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.
Files changed (225) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/angular/package.json +1 -1
  4. package/docs/API.html +44 -6
  5. package/docs/CHART-CODES.md +8 -0
  6. package/docs/api/adapters.html +1 -1
  7. package/docs/api/ai.html +1 -1
  8. package/docs/api/alarms.html +1 -1
  9. package/docs/api/charts.html +28 -2
  10. package/docs/api/data-router.html +1 -1
  11. package/docs/api/deckgl.html +2 -2
  12. package/docs/api/gantt.html +1 -1
  13. package/docs/api/geometry.html +1 -1
  14. package/docs/api/grid.html +2 -2
  15. package/docs/api/index.html +2 -2
  16. package/docs/api/kanban.html +1 -1
  17. package/docs/api/kpi.html +1 -1
  18. package/docs/api/layout.html +1 -1
  19. package/docs/api/list.html +1 -1
  20. package/docs/api/mock-socket.html +1 -1
  21. package/docs/api/tabs.html +1 -1
  22. package/docs/api/types.html +13 -1
  23. package/docs/api-detail.html +13 -4
  24. package/docs/warnings.json +36 -3
  25. package/lattice-grid.d.ts +37 -2
  26. package/lattice-grid.esm.min.js +3 -3
  27. package/lattice-grid.min.cjs +3 -3
  28. package/lattice-grid.min.js +3 -3
  29. package/modules/ai.d.ts +1 -1
  30. package/modules/ai.esm.min.js +2 -2
  31. package/modules/ai.min.cjs +2 -2
  32. package/modules/ai.min.js +2 -2
  33. package/modules/alarms.d.ts +1 -1
  34. package/modules/alarms.esm.min.js +2 -2
  35. package/modules/alarms.min.cjs +2 -2
  36. package/modules/alarms.min.js +2 -2
  37. package/modules/angular.d.ts +1 -1
  38. package/modules/angular.esm.min.js +2 -2
  39. package/modules/angular.min.cjs +2 -2
  40. package/modules/angular.min.js +2 -2
  41. package/modules/chart-alluvial.d.ts +1 -1
  42. package/modules/chart-alluvial.esm.min.js +1 -1
  43. package/modules/chart-alluvial.min.cjs +1 -1
  44. package/modules/chart-alluvial.min.js +1 -1
  45. package/modules/chart-arc.d.ts +1 -1
  46. package/modules/chart-arc.esm.min.js +1 -1
  47. package/modules/chart-arc.min.cjs +1 -1
  48. package/modules/chart-arc.min.js +1 -1
  49. package/modules/chart-bubblemap.d.ts +1 -1
  50. package/modules/chart-bubblemap.esm.min.js +1 -1
  51. package/modules/chart-bubblemap.min.cjs +1 -1
  52. package/modules/chart-bubblemap.min.js +1 -1
  53. package/modules/chart-bump.d.ts +1 -1
  54. package/modules/chart-bump.esm.min.js +1 -1
  55. package/modules/chart-bump.min.cjs +1 -1
  56. package/modules/chart-bump.min.js +1 -1
  57. package/modules/chart-calendar.d.ts +1 -1
  58. package/modules/chart-calendar.esm.min.js +2 -2
  59. package/modules/chart-calendar.esm.min.js.map +1 -1
  60. package/modules/chart-calendar.min.cjs +2 -2
  61. package/modules/chart-calendar.min.js +2 -2
  62. package/modules/chart-calendar.min.js.map +1 -1
  63. package/modules/chart-choropleth.d.ts +1 -1
  64. package/modules/chart-choropleth.esm.min.js +2 -2
  65. package/modules/chart-choropleth.esm.min.js.map +1 -1
  66. package/modules/chart-choropleth.min.cjs +2 -2
  67. package/modules/chart-choropleth.min.js +2 -2
  68. package/modules/chart-choropleth.min.js.map +1 -1
  69. package/modules/chart-decomposition.d.ts +1 -1
  70. package/modules/chart-decomposition.esm.min.js +1 -1
  71. package/modules/chart-decomposition.min.cjs +1 -1
  72. package/modules/chart-decomposition.min.js +1 -1
  73. package/modules/chart-diverging.d.ts +1 -1
  74. package/modules/chart-diverging.esm.min.js +1 -1
  75. package/modules/chart-diverging.min.cjs +1 -1
  76. package/modules/chart-diverging.min.js +1 -1
  77. package/modules/chart-dumbbell.d.ts +1 -1
  78. package/modules/chart-dumbbell.esm.min.js +1 -1
  79. package/modules/chart-dumbbell.min.cjs +1 -1
  80. package/modules/chart-dumbbell.min.js +1 -1
  81. package/modules/chart-fan.d.ts +1 -1
  82. package/modules/chart-fan.esm.min.js +1 -1
  83. package/modules/chart-fan.min.cjs +1 -1
  84. package/modules/chart-fan.min.js +1 -1
  85. package/modules/chart-hexbin.d.ts +1 -1
  86. package/modules/chart-hexbin.esm.min.js +2 -2
  87. package/modules/chart-hexbin.esm.min.js.map +1 -1
  88. package/modules/chart-hexbin.min.cjs +2 -2
  89. package/modules/chart-hexbin.min.js +2 -2
  90. package/modules/chart-hexbin.min.js.map +1 -1
  91. package/modules/chart-hexmap.d.ts +1 -1
  92. package/modules/chart-hexmap.esm.min.js +2 -2
  93. package/modules/chart-hexmap.esm.min.js.map +1 -1
  94. package/modules/chart-hexmap.min.cjs +2 -2
  95. package/modules/chart-hexmap.min.js +2 -2
  96. package/modules/chart-hexmap.min.js.map +1 -1
  97. package/modules/chart-icicle.d.ts +1 -1
  98. package/modules/chart-icicle.esm.min.js +1 -1
  99. package/modules/chart-icicle.min.cjs +1 -1
  100. package/modules/chart-icicle.min.js +1 -1
  101. package/modules/chart-markermap.d.ts +1 -1
  102. package/modules/chart-markermap.esm.min.js +1 -1
  103. package/modules/chart-markermap.min.cjs +1 -1
  104. package/modules/chart-markermap.min.js +1 -1
  105. package/modules/chart-parallel.d.ts +1 -1
  106. package/modules/chart-parallel.esm.min.js +1 -1
  107. package/modules/chart-parallel.min.cjs +1 -1
  108. package/modules/chart-parallel.min.js +1 -1
  109. package/modules/chart-ridgeline.d.ts +1 -1
  110. package/modules/chart-ridgeline.esm.min.js +1 -1
  111. package/modules/chart-ridgeline.min.cjs +1 -1
  112. package/modules/chart-ridgeline.min.js +1 -1
  113. package/modules/chart-roc.d.ts +1 -1
  114. package/modules/chart-roc.esm.min.js +1 -1
  115. package/modules/chart-roc.min.cjs +1 -1
  116. package/modules/chart-roc.min.js +1 -1
  117. package/modules/chart-slope.d.ts +1 -1
  118. package/modules/chart-slope.esm.min.js +1 -1
  119. package/modules/chart-slope.min.cjs +1 -1
  120. package/modules/chart-slope.min.js +1 -1
  121. package/modules/chart-splom.d.ts +1 -1
  122. package/modules/chart-splom.esm.min.js +1 -1
  123. package/modules/chart-splom.min.cjs +1 -1
  124. package/modules/chart-splom.min.js +1 -1
  125. package/modules/chart-waffle.d.ts +1 -1
  126. package/modules/chart-waffle.esm.min.js +1 -1
  127. package/modules/chart-waffle.min.cjs +1 -1
  128. package/modules/chart-waffle.min.js +1 -1
  129. package/modules/charts.d.ts +1 -1
  130. package/modules/charts.esm.min.js +185 -178
  131. package/modules/charts.esm.min.js.map +2 -2
  132. package/modules/charts.min.cjs +185 -178
  133. package/modules/charts.min.js +185 -178
  134. package/modules/charts.min.js.map +2 -2
  135. package/modules/data-router.d.ts +1 -1
  136. package/modules/data-router.esm.min.js +2 -2
  137. package/modules/data-router.min.cjs +2 -2
  138. package/modules/data-router.min.js +2 -2
  139. package/modules/deckgl.d.ts +9 -3
  140. package/modules/deckgl.esm.min.js +18 -11
  141. package/modules/deckgl.esm.min.js.map +2 -2
  142. package/modules/deckgl.min.cjs +18 -11
  143. package/modules/deckgl.min.js +18 -11
  144. package/modules/deckgl.min.js.map +2 -2
  145. package/modules/devtools.d.ts +1 -1
  146. package/modules/devtools.esm.min.js +1 -1
  147. package/modules/devtools.min.cjs +1 -1
  148. package/modules/devtools.min.js +1 -1
  149. package/modules/dhtmlx-compat.d.ts +1 -1
  150. package/modules/dhtmlx-compat.esm.min.js +2 -2
  151. package/modules/dhtmlx-compat.min.cjs +2 -2
  152. package/modules/dhtmlx-compat.min.js +2 -2
  153. package/modules/gantt.d.ts +1 -1
  154. package/modules/gantt.esm.min.js +2 -2
  155. package/modules/gantt.min.cjs +2 -2
  156. package/modules/gantt.min.js +2 -2
  157. package/modules/geo-europe-nuts.d.ts +1 -1
  158. package/modules/geo-europe-nuts.esm.min.js +1 -1
  159. package/modules/geo-europe-nuts.min.cjs +1 -1
  160. package/modules/geo-europe-nuts.min.js +1 -1
  161. package/modules/geo-uk.d.ts +1 -1
  162. package/modules/geo-uk.esm.min.js +1 -1
  163. package/modules/geo-uk.min.cjs +1 -1
  164. package/modules/geo-uk.min.js +1 -1
  165. package/modules/geo-us-states.d.ts +1 -1
  166. package/modules/geo-us-states.esm.min.js +1 -1
  167. package/modules/geo-us-states.min.cjs +1 -1
  168. package/modules/geo-us-states.min.js +1 -1
  169. package/modules/geo-world-110m.d.ts +1 -1
  170. package/modules/geo-world-110m.esm.min.js +1 -1
  171. package/modules/geo-world-110m.min.cjs +1 -1
  172. package/modules/geo-world-110m.min.js +1 -1
  173. package/modules/geo-world-50m.d.ts +1 -1
  174. package/modules/geo-world-50m.esm.min.js +1 -1
  175. package/modules/geo-world-50m.min.cjs +1 -1
  176. package/modules/geo-world-50m.min.js +1 -1
  177. package/modules/geometry.d.ts +1 -1
  178. package/modules/geometry.esm.min.js +2 -2
  179. package/modules/geometry.min.cjs +2 -2
  180. package/modules/geometry.min.js +2 -2
  181. package/modules/htmx.d.ts +1 -1
  182. package/modules/htmx.esm.min.js +3 -3
  183. package/modules/htmx.min.cjs +3 -3
  184. package/modules/htmx.min.js +3 -3
  185. package/modules/kanban.d.ts +1 -1
  186. package/modules/kanban.esm.min.js +2 -2
  187. package/modules/kanban.min.cjs +2 -2
  188. package/modules/kanban.min.js +2 -2
  189. package/modules/kpi.d.ts +1 -1
  190. package/modules/kpi.esm.min.js +2 -2
  191. package/modules/kpi.min.cjs +2 -2
  192. package/modules/kpi.min.js +2 -2
  193. package/modules/layout.d.ts +1 -1
  194. package/modules/layout.esm.min.js +2 -2
  195. package/modules/layout.min.cjs +2 -2
  196. package/modules/layout.min.js +2 -2
  197. package/modules/list.d.ts +1 -1
  198. package/modules/list.esm.min.js +2 -2
  199. package/modules/list.min.cjs +2 -2
  200. package/modules/list.min.js +2 -2
  201. package/modules/mock-socket.d.ts +1 -1
  202. package/modules/mock-socket.esm.min.js +1 -1
  203. package/modules/mock-socket.min.cjs +1 -1
  204. package/modules/mock-socket.min.js +1 -1
  205. package/modules/react.d.ts +1 -1
  206. package/modules/react.esm.min.js +2 -2
  207. package/modules/react.min.cjs +2 -2
  208. package/modules/react.min.js +2 -2
  209. package/modules/svelte.d.ts +1 -1
  210. package/modules/svelte.esm.min.js +2 -2
  211. package/modules/svelte.min.cjs +2 -2
  212. package/modules/svelte.min.js +2 -2
  213. package/modules/tabs.d.ts +1 -1
  214. package/modules/tabs.esm.min.js +2 -2
  215. package/modules/tabs.min.cjs +2 -2
  216. package/modules/tabs.min.js +2 -2
  217. package/modules/vue.d.ts +1 -1
  218. package/modules/vue.esm.min.js +2 -2
  219. package/modules/vue.min.cjs +2 -2
  220. package/modules/vue.min.js +2 -2
  221. package/modules/webcomponent.d.ts +1 -1
  222. package/modules/webcomponent.esm.min.js +3 -3
  223. package/modules/webcomponent.min.cjs +3 -3
  224. package/modules/webcomponent.min.js +3 -3
  225. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
1
  /*!
2
- * Lattice Grid 1.74.0, data-router module
2
+ * Lattice Grid 1.75.0, data-router module
3
3
  * Copyright (c) 2026 TOCLOCO Inc. All rights reserved.
4
4
  * https://latticegrid.dev
5
5
  */
6
- (function(rn){"use strict";var $t=Object.create(null),Wt=Object.create(null);function xe(h,he){$t[h]=he}function Mt(h){var he=Wt[h];if(he)return he;var te=Object.create(null);Wt[h]=te;var P=$t[h];if(!P)throw new Error("[lattice] missing module: "+h);return P(te,Mt),te}xe("packages/core/src/internal/util.js",function(h,he){"use strict";Object.defineProperty(h,"VERSION",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(h,"reportedWarnings",{enumerable:!0,get:function(){return N}}),Object.defineProperty(h,"warnOnce",{enumerable:!0,get:function(){return C}}),Object.defineProperty(h,"infoOnce",{enumerable:!0,get:function(){return M}}),Object.defineProperty(h,"resetWarnings",{enumerable:!0,get:function(){return D}}),Object.defineProperty(h,"fail",{enumerable:!0,get:function(){return G}}),Object.defineProperty(h,"invariant",{enumerable:!0,get:function(){return v}}),Object.defineProperty(h,"DEV",{enumerable:!0,get:function(){return V}}),Object.defineProperty(h,"isObject",{enumerable:!0,get:function(){return x}}),Object.defineProperty(h,"isFunction",{enumerable:!0,get:function(){return z}}),Object.defineProperty(h,"isNil",{enumerable:!0,get:function(){return U}}),Object.defineProperty(h,"isBlank",{enumerable:!0,get:function(){return J}}),Object.defineProperty(h,"isCtor",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(h,"pathGetter",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(h,"pathSetter",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(h,"getPath",{enumerable:!0,get:function(){return c}}),Object.defineProperty(h,"setPath",{enumerable:!0,get:function(){return L}}),Object.defineProperty(h,"humanise",{enumerable:!0,get:function(){return k}}),Object.defineProperty(h,"escapeHtml",{enumerable:!0,get:function(){return $}}),Object.defineProperty(h,"titleCase",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(h,"expand",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(h,"toArray",{enumerable:!0,get:function(){return qe}}),Object.defineProperty(h,"merge",{enumerable:!0,get:function(){return s}}),Object.defineProperty(h,"mergeRow",{enumerable:!0,get:function(){return f}}),Object.defineProperty(h,"Lru",{enumerable:!0,get:function(){return g}}),Object.defineProperty(h,"collator",{enumerable:!0,get:function(){return m}}),Object.defineProperty(h,"defaultCompare",{enumerable:!0,get:function(){return E}}),Object.defineProperty(h,"now",{enumerable:!0,get:function(){return I}}),Object.defineProperty(h,"nextFrame",{enumerable:!0,get:function(){return W}}),Object.defineProperty(h,"cancelFrame",{enumerable:!0,get:function(){return se}}),Object.defineProperty(h,"frameBatched",{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(h,"settleDebounce",{enumerable:!0,get:function(){return le}}),Object.defineProperty(h,"whenIdle",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(h,"uid",{enumerable:!0,get:function(){return Ae}});const te="1.74.0";async function P(){return te}const Z="1.74.0",X=new Set,re=2e3;function de(l){if(X.add(l),X.size>re){const a=X.values().next().value;a!==void 0&&X.delete(a)}}const F=[],Y=500;function ne(l,a,d){F.push({key:l,level:a,message:d.map(j=>typeof j=="string"?j:T(j)).join(" "),at:Date.now()}),F.length>Y&&F.shift()}function T(l){if(l instanceof Error)return l.message;try{return JSON.stringify(l)}catch{return String(l)}}function N(){return F.map(l=>({...l}))}function C(l,...a){X.has(l)||(de(l),ne(l,"warn",a),console.warn("[lattice]",...a))}function M(l,...a){X.has(l)||(de(l),ne(l,"info",a),console.info("[lattice]",...a))}function D(){X.clear(),F.length=0}function G(l,a){const d=new Error(`[lattice] ${l}`);throw a!==void 0&&(d.cause=a),d}function v(l,a){l||G(a)}const V=(()=>{try{return!(typeof process<"u"&&process.env&&process.env.NODE_ENV==="production")}catch{return!0}})();function x(l){return l!==null&&typeof l=="object"&&!Array.isArray(l)}function z(l){return typeof l=="function"}function U(l){return l==null}function J(l){return l==null||l===""}function oe(l){return typeof l!="function"?!1:/^class[\s{]/.test(Function.prototype.toString.call(l))?!0:!!(l.prototype&&Object.getOwnPropertyNames(l.prototype).length>1)}const ee=new Map;function pe(l){let a=ee.get(l);if(a)return a;if(!l.includes("."))a=d=>d?.[l];else{const d=l.split("."),j=d.length;a=ge=>{let we=ge;for(let ae=0;ae<j;ae++){if(we==null)return;we=we[d[ae]]}return we}}return ee.set(l,a),a}const je=new Map;function Me(l){let a=je.get(l);if(a)return a;if(!l.includes("."))a=(d,j)=>{d!=null&&(d[l]=j)};else{const d=l.split("."),j=d.length-1;a=(ge,we)=>{let ae=ge;for(let me=0;me<j;me++){if(ae==null)return;const Ce=d[me];ae[Ce]==null&&(ae[Ce]={}),ae=ae[Ce]}ae!=null&&(ae[d[j]]=we)}}return je.set(l,a),a}function c(l,a){return pe(a)(l)}function L(l,a,d){Me(a)(l,d)}function k(l){return l?(l.includes(".")?l.slice(l.lastIndexOf(".")+1):l).replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replace(/\s+/g," ").trim().replace(/^./,d=>d.toUpperCase()):""}const R={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function $(l){const a=l==null?"":String(l);return/[&<>"']/.test(a)?a.replace(/[&<>"']/g,d=>R[d]):a}function ie(l){return String(l).replace(/\w\S*/g,a=>a[0].toUpperCase()+a.slice(1).toLowerCase())}function ve(l,a,d){if(l!==void 0)return l===!0?{enabled:!0,...d}:l===!1?{enabled:!1}:x(l)?l:{[a]:l,enabled:!0}}function qe(l){return l==null?[]:Array.isArray(l)?l:[l]}const o=Object.freeze(new Set(["__proto__","constructor","prototype"]));function s(l,a){if(!x(l))return x(a)?{...a}:a;if(!x(a))return a===void 0?l:a;const d={...l};for(const j of Object.keys(a)){if(o.has(j))continue;const ge=a[j];ge!==void 0&&(d[j]=x(ge)&&x(d[j])?s(d[j],ge):ge)}return d}function f(l,a){if(!x(l)||!x(a)||l===a)return a;const d=Object.create(Object.getPrototypeOf(l));return Object.assign(d,l,a),d}class g{#e;#t=new Map;#n;constructor(a=256,d=null){this.#e=a,this.#n=d}get size(){return this.#t.size}get max(){return this.#e}set max(a){this.#e=a,this.#r()}has(a){return this.#t.has(a)}get(a){const d=this.#t;if(!d.has(a))return;const j=d.get(a);return d.delete(a),d.set(a,j),j}peek(a){return this.#t.get(a)}set(a,d){const j=this.#t;return j.has(a)&&j.delete(a),j.set(a,d),this.#r(),d}delete(a){const d=this.#t.get(a);return this.#t.delete(a)&&this.#n&&this.#n(d,a),d}clear(){if(this.#n)for(const[a,d]of this.#t)this.#n(d,a);this.#t.clear()}keys(){return this.#t.keys()}values(){return this.#t.values()}#r(){const a=this.#t;for(;a.size>this.#e;){const d=a.keys().next().value,j=a.get(d);a.delete(d),this.#n&&this.#n(j,d)}}}const y=new Map;function m(l,a){const d=`${l||""}|${a?JSON.stringify(a):""}`;let j=y.get(d);return j||(j=new Intl.Collator(l||void 0,{numeric:!0,sensitivity:"variant",...a}),y.set(d,j)),j}function E(l,a){if(l===a)return 0;if(l==null)return 1;if(a==null)return-1;if(typeof l=="number"&&typeof a=="number")return Number.isNaN(l)?Number.isNaN(a)?0:1:Number.isNaN(a)||l<a?-1:l>a?1:0;const d=String(l),j=String(a);return d<j?-1:d>j?1:0}function I(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const S=typeof requestAnimationFrame=="function";function W(l){return S?requestAnimationFrame(l):setTimeout(()=>l(I()),16)}function se(l){l!=null&&(S?cancelAnimationFrame(l):clearTimeout(l))}function Ne(l){let a=null,d=null;const j=()=>{a=null;const we=d;d=null,l(...we||[])},ge=(...we)=>{d=we,a===null&&(a=W(j))};return ge.cancel=()=>{se(a),a=null,d=null},ge.flush=()=>{a!==null&&(se(a),j())},ge}function le(l,a){let d=null,j=null;const ge=()=>{if(d=null,j===null)return;const me=j;j=null,l(...me),we()},we=()=>{d=setTimeout(ge,a),typeof d?.unref=="function"&&d.unref()},ae=(...me)=>{d===null?(l(...me),we()):(j=me,clearTimeout(d),we())};return ae.flush=()=>{if(d!==null&&clearTimeout(d),d=null,j===null)return;const me=j;j=null,l(...me)},ae.cancel=()=>{d!==null&&clearTimeout(d),d=null,j=null},ae.pending=()=>d!==null||j!==null,ae}function Ee(l,a=50){return typeof requestIdleCallback=="function"?requestIdleCallback(l,{timeout:a}):setTimeout(()=>l({timeRemaining:()=>0,didTimeout:!0}),1)}let ke=0;function Ae(l="l"){return`${l}${(++ke).toString(36)}`}}),xe("packages/core/src/source/filterwire.js",function(h,he){"use strict";Object.defineProperty(h,"HOST_FILTER_WARN_ID",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(h,"WHERE_PAGE_RELATIVE_WARN_ID",{enumerable:!0,get:function(){return X}}),Object.defineProperty(h,"warnWherePageRelative",{enumerable:!0,get:function(){return re}}),Object.defineProperty(h,"warnHostFilterNotApplied",{enumerable:!0,get:function(){return de}}),Object.defineProperty(h,"WHERE_NOT_APPLIED_WARN_ID",{enumerable:!0,get:function(){return F}}),Object.defineProperty(h,"warnWhereNotApplied",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(h,"WHERE_OVER_THRESHOLD_WARN_ID",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(h,"warnWhereOverThreshold",{enumerable:!0,get:function(){return T}}),Object.defineProperty(h,"RELATIVE_TOKENS",{enumerable:!0,get:function(){return x}}),Object.defineProperty(h,"parseRelativeToken",{enumerable:!0,get:function(){return z}}),Object.defineProperty(h,"resolveRelativeRange",{enumerable:!0,get:function(){return U}}),Object.defineProperty(h,"relativeTokenOf",{enumerable:!0,get:function(){return J}}),Object.defineProperty(h,"relativeTokenHelp",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(h,"isResolvableRelative",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(h,"resolveRelativeCondition",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(h,"isGroup",{enumerable:!0,get:function(){return je}}),Object.defineProperty(h,"forEachCondition",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(h,"mapConditions",{enumerable:!0,get:function(){return c}}),Object.defineProperty(h,"normaliseFilterSet",{enumerable:!0,get:function(){return k}}),Object.defineProperty(h,"buildFilterSet",{enumerable:!0,get:function(){return R}}),Object.defineProperty(h,"wireFilters",{enumerable:!0,get:function(){return $}}),Object.defineProperty(h,"querySignature",{enumerable:!0,get:function(){return ie}});const P=he("packages/core/src/internal/util.js").warnOnce,Z="source.remote.hostFilter",X="source.where.pageRelative";function re(o,s){!Array.isArray(o)||!o.length||P(X,`filters.where (${o.join(", ")}) runs over the rows the ${s} source fetched,`,"not the whole dataset: match counts and totals are page-relative.","Give the predicate a { condition } twin so the engine can narrow the fetch itself.")}function de(o){const s=(o||{}).config;!s||!s.hostFilter||P(Z,"config.hostFilter is not sent to a server-delegated source (paged/remote) and is not applied:","filtering only the fetched window would give wrong counts and totals.","Express the filter as a FilterSet condition, or send it through config.context.")}const F="source.where.notApplied";function Y(o,s){P(`${F}:${o}`,`filters.where("${o}") is registered but the ${s} source holds only its fetched window`,"and cannot run the predicate over it: the predicate is not applied there, and rows it would","exclude stay on screen.","Give it a { condition } twin so the engine can narrow the fetch itself — that is the","supported route for a paged or remote source.")}const ne="source.where.overThreshold";function T(o,s,f,g){!Array.isArray(o)||!o.length||P(`${ne}:${s}`,`filters.where (${o.join(", ")}) is not applied to the ${s} pushdown source:`,f===null?"the adapter reports no row total, so the size of the matching set is unknown.":`its matching set is ${f.toLocaleString()} rows, at or past the whereRowLimit of ${g.toLocaleString()}.`,"Running the predicate needs every matching row fetched and held here, which is the whole","download a pushdown source exists to avoid, so it is refused and the rows the predicate","would exclude stay on screen.","Give the predicate a { condition } twin so the engine narrows the fetch itself — that is the","route that works at any size — or raise `whereRowLimit` on the source config if you want the","download.")}const N=new Map;function C(o){let s=N.get(o);return s||(s=new Intl.DateTimeFormat("en-US",{timeZone:o,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),N.set(o,s)),s}function M(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function D(o,s){const f=C(s).formatToParts(new Date(o)),g={y:1970,m:1,d:1,h:0,mi:0,s:0};for(const y of f)y.type==="year"?g.y=+y.value:y.type==="month"?g.m=+y.value:y.type==="day"?g.d=+y.value:y.type==="hour"?g.h=+y.value%24:y.type==="minute"?g.mi=+y.value:y.type==="second"&&(g.s=+y.value);return g}function G(o,s){const f=D(o,s);return Date.UTC(f.y,f.m-1,f.d,f.h,f.mi,f.s)-Math.floor(o/1e3)*1e3}function v(o,s,f,g){const y=Date.UTC(o,s-1,f),m=y-G(y,g);return y-G(m,g)}function V(o,s,f){const g=new Date(Date.UTC(o.y,o.m-1,o.d+s));return v(g.getUTCFullYear(),g.getUTCMonth()+1,g.getUTCDate(),f)}const x=Object.freeze(["today","yesterday","lastNDays","thisWeek","thisMonth","thisQuarter","thisYear","quarterToDate","yearToDate"]);function z(o,s){if(typeof o!="string")return null;const f=o.trim().toLowerCase().replace(/[\s_-]+/g,""),g=/^last(\d*|n)days?$/.exec(f);if(g){const y=g[1]==="n"?"":g[1],m=Number(y||s);return!Number.isFinite(m)||m<=0?null:{kind:"lastNDays",n:Math.floor(m)}}switch(f){case"today":return{kind:"today",n:0};case"yesterday":return{kind:"yesterday",n:0};case"thisweek":return{kind:"thisWeek",n:0};case"thismonth":return{kind:"thisMonth",n:0};case"thisquarter":return{kind:"thisQuarter",n:0};case"thisyear":return{kind:"thisYear",n:0};case"quartertodate":case"qtd":return{kind:"quarterToDate",n:0};case"yeartodate":case"ytd":return{kind:"yearToDate",n:0};default:return null}}function U(o,s={}){const f=z(o,s.n);if(!f)return null;const g=s.tz||M(),y=s.now instanceof Date?s.now.getTime():typeof s.now=="number"?s.now:Date.now(),m=D(y,g),E=v(m.y,m.m,m.d,g),I=V(m,1,g);let S=E,W=I;switch(f.kind){case"today":break;case"yesterday":S=V(m,-1,g),W=E;break;case"lastNDays":W=s.includeToday?I:E,S=V(m,s.includeToday?-(f.n-1):-f.n,g);break;case"thisWeek":{const se=Number.isFinite(s.weekStartsOn)?Number(s.weekStartsOn):1,le=(new Date(Date.UTC(m.y,m.m-1,m.d)).getUTCDay()-se+7)%7;S=V(m,-le,g),W=V(m,-le+7,g);break}case"thisMonth":S=v(m.y,m.m,1,g),W=v(m.m===12?m.y+1:m.y,m.m===12?1:m.m+1,1,g);break;case"thisQuarter":case"quarterToDate":{const se=Math.floor((m.m-1)/3)*3+1;S=v(m.y,se,1,g),W=f.kind==="quarterToDate"?I:se===10?v(m.y+1,1,1,g):v(m.y,se+3,1,g);break}case"thisYear":case"yearToDate":S=v(m.y,1,1,g),W=f.kind==="yearToDate"?I:v(m.y+1,1,1,g);break;default:return null}return{from:new Date(S).toISOString(),to:new Date(W).toISOString(),bounds:"[)",tz:g,relative:f.kind==="lastNDays"?`last${f.n}Days`:f.kind,n:f.n}}function J(o){if(!o||typeof o!="object")return null;const s=o.value;if(s&&typeof s=="object"&&!Array.isArray(s)&&"relative"in s)return{token:String(s.relative),n:typeof s.n=="number"?s.n:void 0};if(o.op==="relative"&&typeof o.value=="string")return{token:o.value,n:void 0};const f=o.meta;return f&&typeof f.relative=="string"&&o.value===void 0?{token:f.relative,n:typeof f.n=="number"?f.n:void 0}:null}function oe(){return`Known tokens: ${x.filter(s=>s!=="lastNDays").join(", ")}. "lastNDays" needs a count: pass "last7Days", or the value object { relative: 'lastNDays', n: 7 }.`}function ee(o){const s=J(o);return s?z(s.token,s.n)!==null:!1}function pe(o,s={}){const f=J(o);if(!f)return o;const g=U(f.token,{...s,n:f.n});return g?{...o,type:o.type||"date",op:"between",value:[g.from,g.to],bounds:o.bounds||g.bounds,meta:{...o.meta||{},relative:g.relative,tz:g.tz}}:(P(`source.relative.${f.token}`,`unknown relative date token "${f.token}"; sending the condition unresolved.`,oe()),o)}function je(o){return!!o&&typeof o=="object"&&Array.isArray(o.conditions)}function Me(o,s){if(o){if(je(o)){for(const f of o.conditions)Me(f,s);return}s(o)}}function c(o,s){if(!o)return null;if(!je(o))return s(o);const f=o;let g=!1;const y=[];for(const m of f.conditions){const E=c(m,s);E!==m&&(g=!0),E&&y.push(E)}return!g&&y.length===f.conditions.length?o:y.length?{...f,conditions:y}:null}function L(o){if(!o)return null;if(!je(o))return o;const s=o,f=[];for(const g of s.conditions){const y=L(g);y&&f.push(y)}return f.length?{op:s.op,conditions:f}:null}function k(o){const s=L(o);return s?je(s)&&s.op==="and"?s:{op:"and",conditions:[s]}:null}function R(o){const s=(o||[]).filter(Boolean);return s.length?{op:"and",conditions:s}:null}function $(o,s={}){const f=c(o,g=>pe(g,s));return k(f)}function ie(o){const s=ve(o.filters??null);return JSON.stringify([s,o.sort??null,o.quick??"",o.groupBy??null,o.pivotBy??null,qe(o.context)])}function ve(o){if(!o)return null;if(je(o)){const g=o;return{op:g.op,conditions:g.conditions.map(ve)}}const s=o,f=s.meta&&typeof s.meta.relative=="string"?s.meta.relative:J(s)?.token;return{col:s.col,op:s.op,bounds:s.bounds??null,caseSensitive:s.caseSensitive??!1,value:f?`rel:${f}`:s.value??null}}function qe(o){if(o==null)return null;try{return JSON.parse(JSON.stringify(o))}catch{return P("source.context.unserialisable","config.context is not JSON-serialisable; cache keys ignore it."),"[unserialisable]"}}}),xe("packages/core/src/source/aggregates.js",function(h,he){"use strict";Object.defineProperty(h,"STAT_PUSHDOWN",{enumerable:!0,get:function(){return te}}),Object.defineProperty(h,"pushableAggregates",{enumerable:!0,get:function(){return P}}),Object.defineProperty(h,"fillAggregateSql",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(h,"resolveAggregatesConfig",{enumerable:!0,get:function(){return X}}),Object.defineProperty(h,"routeAggregate",{enumerable:!0,get:function(){return re}}),Object.defineProperty(h,"resolveAggregatePlan",{enumerable:!0,get:function(){return de}}),Object.defineProperty(h,"groupKeysPushable",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(h,"pushdownDocRows",{enumerable:!0,get:function(){return ne}});const te=Object.freeze({sum:{pushable:!0,class:"identical",sql:"sum(%c)"},avg:{pushable:!0,class:"identical",sql:"avg(%c)"},min:{pushable:!0,class:"identical",sql:"min(%c)"},max:{pushable:!0,class:"identical",sql:"max(%c)"},count:{pushable:!0,class:"identical",sql:"count(*)"},countValues:{pushable:!0,class:"identical",sql:"count(%c)",blankAware:!0},range:{pushable:!0,class:"identical",sql:"(max(%c) - min(%c))"},variance:{pushable:!0,class:"identical",sql:"var_samp(%c)"},varianceP:{pushable:!0,class:"identical",sql:"var_pop(%c)"},stddev:{pushable:!0,class:"identical",sql:"stddev_samp(%c)"},stddevP:{pushable:!0,class:"identical",sql:"stddev_pop(%c)"},sumSquares:{pushable:!0,class:"identical",sql:"sum(%c * %c)"},median:{pushable:!0,class:"identical",sql:"median(%c)"},p25:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.25)"},p75:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.75)"},p90:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.9)"},p95:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.95)"},p99:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.99)"},iqr:{pushable:!0,class:"identical",sql:"(quantile_cont(%c, 0.75) - quantile_cont(%c, 0.25))"},mad:{pushable:!0,class:"identical",sql:"mad(%c)"},distinct:{pushable:!0,class:"identical",sql:"count(DISTINCT %c)",blankAware:!0},skewness:{pushable:!0,class:"identical",sql:"skewness(%c)"},kurtosis:{pushable:!0,class:"identical",sql:"kurtosis(%c)"},geomean:{pushable:!0,class:"identical",sql:"exp(avg(ln(%c)))"},harmean:{pushable:!0,class:"identical",sql:"(count(%c) / sum(1.0 / %c))"},entropy:{pushable:!0,class:"identical",sql:"entropy(%c)",blankAware:!0},correlation:{pushable:!0,class:"identical",sql:"corr(%w, %c)",twoColumn:!0},hhi:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_transform(map_values(histogram(%c)), lambda v: (v::DOUBLE/count(%c))*(v::DOUBLE/count(%c)))) END"},evenness:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL WHEN count(DISTINCT %c)<2 THEN 1.0 ELSE entropy(%c)/log2(count(DISTINCT %c)) END"},top3Share:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_slice(list_sort(map_values(histogram(%c)),'DESC'),1,3))::DOUBLE/count(%c) END"},top10Share:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_slice(list_sort(map_values(histogram(%c)),'DESC'),1,10))::DOUBLE/count(%c) END"},gini:{pushable:!0,class:"identical",sql:"CASE WHEN list_min(list(%c) FILTER (WHERE isfinite(%c)))<0 THEN NULL WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL WHEN list_sum(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN 0 ELSE 2.0*list_sum(list_transform(list_sort(list(%c) FILTER (WHERE isfinite(%c))), lambda v, i: i*v))/(len(list(%c) FILTER (WHERE isfinite(%c)))*list_sum(list(%c) FILTER (WHERE isfinite(%c))))-(len(list(%c) FILTER (WHERE isfinite(%c)))+1.0)/len(list(%c) FILTER (WHERE isfinite(%c))) END"},trimmedMean:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL ELSE list_avg(list_slice(list_sort(list(%c) FILTER (WHERE isfinite(%c))), floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT+1, len(list(%c) FILTER (WHERE isfinite(%c)))-floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT)) END"},winsorizedMean:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL ELSE list_avg(list_transform(list_sort(list(%c) FILTER (WHERE isfinite(%c))), lambda v: least(list_sort(list(%c) FILTER (WHERE isfinite(%c)))[len(list(%c) FILTER (WHERE isfinite(%c)))-floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT], greatest(list_sort(list(%c) FILTER (WHERE isfinite(%c)))[floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT+1], v)))) END"},robustOutliers:{pushable:!0,class:"identical",sql:"(SELECT CASE WHEN len(d.a)=0 THEN NULL WHEN d.mad=0 THEN NULL ELSE len(list_filter(d.a, lambda v: abs(0.6745*(v-d.med)/d.mad)>3.5)) END FROM (SELECT xs AS a, list_median(xs) AS med, list_median(list_transform(xs, lambda w: abs(w-list_median(xs)))) AS mad FROM (SELECT list(%c) FILTER (WHERE isfinite(%c)) AS xs)) d)"},jarqueBera:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))<8 THEN NULL WHEN list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2)))=0 THEN NULL ELSE (len(list(%c) FILTER (WHERE isfinite(%c)))/6.0)*(power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),3)))/power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2))),1.5),2)+power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),4)))/power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2))),2)-3,2)/4.0) END"},weightedAvg:{pushable:!0,class:"identical",twoColumn:!0,sql:"sum(%c*%w) FILTER (WHERE isfinite(%c) AND isfinite(%w))/nullif(sum(%w) FILTER (WHERE isfinite(%c) AND isfinite(%w)),0)"},mode:{pushable:!0,class:"may-differ",sql:"mode(%c)",note:"DuckDB returns a modal value even for an all-distinct column; the grid returns null. Tie-breaking can also differ, and on a text column an empty string counts as a value. Under pushdown you will see a value."},weightedQuantile:{pushable:!1,class:"fallback",note:"No SQL equivalent for the grid's weighted-quantile midpoint convention; always computed client-side (needs a full-dataset pull for a correct figure over a remote source)."}});function P(){const T=new Set;for(const[N,C]of Object.entries(te))C.pushable&&T.add(N);return T}function Z(T,N,C){let M=T.split("%c").join(N);return C!==void 0&&(M=M.split("%w").join(C)),M}function X(T){const N=T||{},C=N.default==="engine"||N.default==="engine-if-identical"?N.default:"client",M={};if(N.overrides&&typeof N.overrides=="object")for(const[D,G]of Object.entries(N.overrides))(G==="engine"||G==="client")&&(M[D]=G);return{default:C,overrides:M}}function re(T,N){const C=te[T];if(!C||!C.pushable)return"client";const M=N.overrides[T];return M==="engine"||M==="client"?M:N.default==="client"?"client":N.default==="engine-if-identical"?C.class==="identical"?"engine":"client":"engine"}function de(T,N){const C=X(N),M=[],D=[];for(const G of T||[]){const v=te[G.fn],V=re(G.fn,C),x={id:G.id,col:G.col,fn:G.fn,class:v?v.class:"fallback"};G.weight!==void 0&&(x.weight=G.weight),G.params!==void 0&&(x.params=G.params),V==="engine"?M.push(x):(x.reason=v&&!v.pushable?v.note||"the engine cannot express this stat":"client by config",D.push(x))}return{engine:M,client:D,config:C}}const F=/^[A-Za-z_][A-Za-z0-9_$]*$/;function Y(T,N=[]){return(T||[]).every(M=>{if(typeof M=="string")return F.test(M);if(!M||typeof M!="object")return!1;const D=M;return Array.isArray(N)&&N.includes(D.bucket)&&typeof D.col=="string"&&F.test(D.col)&&typeof D.size=="number"&&Number.isFinite(D.size)&&D.size>0})}function ne(){return Object.entries(te).map(([T,N])=>({stat:T,class:N.class,sql:N.sql?Z(N.sql,"col",N.twoColumn?"weight":void 0):"",note:N.note||(N.class==="identical"?"Pushes to DuckDB with the same result.":"")}))}}),xe("packages/core/src/source/abort.js",function(h,he){"use strict";Object.defineProperty(h,"SupersededError",{enumerable:!0,get:function(){return te}}),Object.defineProperty(h,"RequestToken",{enumerable:!0,get:function(){return P}}),Object.defineProperty(h,"AbortScope",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(h,"createAbortScope",{enumerable:!0,get:function(){return X}}),Object.defineProperty(h,"isAbortError",{enumerable:!0,get:function(){return re}});class te extends Error{constructor(F,Y="superseded"){super(`[lattice] request ${F?`"${F}" `:""}${Y}`),this.name="SupersededError",this.superseded=!0,this.key=F}}class P{#e;constructor(F,Y,ne,T){this.#e=F,this.key=Y,this.controller=ne,this.signal=ne.signal,this.seq=T}get current(){return!this.signal.aborted&&this.#e.tokenFor(this.key)===this}settle(){this.#e.settle(this)}abort(F){this.signal.aborted||this.controller.abort(new te(this.key,F)),this.#e.settle(this)}}class Z{#e=new Map;#t=0;begin(F="",Y="superseded"){const ne=this.#e.get(F);ne&&!ne.signal.aborted&&ne.controller.abort(new te(F,Y));const T=new P(this,F,new AbortController,++this.#t);return this.#e.set(F,T),T}tokenFor(F){return this.#e.get(F)}pending(F=""){const Y=this.#e.get(F);return!!Y&&!Y.signal.aborted}get size(){return this.#e.size}settle(F){this.#e.get(F.key)===F&&this.#e.delete(F.key)}abort(F="",Y="superseded"){const ne=this.#e.get(F);ne&&ne.abort(Y)}abortAll(F="superseded"){for(const Y of[...this.#e.values()])Y.abort(F);this.#e.clear()}}function X(){return new Z}function re(de){if(!de||typeof de!="object")return!1;const F=de;return F.superseded===!0||F.name==="AbortError"||F.name==="SupersededError"}}),xe("packages/core/src/source/pushdown.js",function(h,he){"use strict";Object.defineProperty(h,"NO_CAPABILITIES",{enumerable:!0,get:function(){return G}}),Object.defineProperty(h,"resolveMutate",{enumerable:!0,get:function(){return v}}),Object.defineProperty(h,"capabilitiesOf",{enumerable:!0,get:function(){return z}}),Object.defineProperty(h,"splitFilters",{enumerable:!0,get:function(){return J}}),Object.defineProperty(h,"planQuery",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(h,"applyResidual",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(h,"DEFAULT_WHERE_ROW_LIMIT",{enumerable:!0,get:function(){return R}}),Object.defineProperty(h,"createPushdownSource",{enumerable:!0,get:function(){return qe}});const te=he("packages/core/src/internal/util.js"),P=te.isFunction,Z=te.warnOnce,X=he("packages/core/src/source/filterwire.js"),re=X.isGroup,de=X.warnWherePageRelative,F=X.warnWhereOverThreshold,Y=he("packages/core/src/source/aggregates.js"),ne=Y.resolveAggregatePlan,T=Y.groupKeysPushable,N=Y.STAT_PUSHDOWN,M=he("packages/core/src/source/abort.js").SupersededError;function D(o){const s=o&&o.signal;if(!s||!s.aborted)return;const f=s.reason;throw f instanceof Error?f:new M("","superseded before it was sent")}const G=Object.freeze({filter:!1,operators:Object.freeze([]),sort:!1,quick:!1,range:!1,total:!1,group:!1,mutate:!1});function v(o){if(!o||typeof o!="object")return!1;const s=o.returning==="row"||o.returning==="key"?o.returning:"none";return{append:o.append===!0,update:o.update===!0,delete:o.delete===!0,returning:s}}function V(o,s){if(!o||typeof s!="string")return;if(!s.includes("."))return o[s];let f=o;for(const g of s.split(".")){if(f===null||typeof f!="object")return;f=f[g]}return f}function x(o){if(o===!0)return!0;if(!o||typeof o!="object")return!1;const s=o;return s.enabled===!1?!1:s.enabled===!0||P(s.commit)}function z(o){const s={...G,...o||{}};return s.operators=new Set(s.operators||[]),s.mutate=v(s.mutate),s}function U(o,s){return!o||!o.op||!s.operators.size?!1:s.operators.has(o.op)}function J(o,s){if(!o)return{pushed:null,residual:null};if(!s.filter)return{pushed:null,residual:o};if(s.filter==="term"){if(re(o)){const m=o.conditions||[];if(String(o.op)!=="and")return{pushed:null,residual:o};const E=m.findIndex(S=>!re(S)&&U(S,s));if(E<0)return{pushed:null,residual:o};const I=m.filter((S,W)=>W!==E);return{pushed:m[E],residual:I.length?{op:"and",conditions:I}:null}}return U(o,s)?{pushed:o,residual:null}:{pushed:null,residual:o}}if(!re(o))return U(o,s)?{pushed:o,residual:null}:{pushed:null,residual:o};if(String(o.op)!=="and")return(o.conditions||[]).every(E=>re(E)?J(E,s).residual===null:U(E,s))?{pushed:o,residual:null}:{pushed:null,residual:o};const f=[],g=[];for(const m of o.conditions||[]){if(re(m)){if(s.filter==="flat"){g.push(m);continue}const E=J(m,s);E.pushed&&f.push(E.pushed),E.residual&&g.push(E.residual);continue}(U(m,s)?f:g).push(m)}const y=m=>m.length===0?null:m.length===1?m[0]:{op:"and",conditions:m};return{pushed:y(f),residual:y(g)}}function oe(o,s,f,g,y,m,E){const I=Array.isArray(o.groupBy)?o.groupBy:[],S=Array.isArray(o.groupPath)?o.groupPath:[],W=Array.isArray(o.groupValues)?o.groupValues:null;return s.group?T(I)?f.residual?"the filter did not fully push, so the engine would group a superset of the matching rows":g?y?m?"a host `where` predicate can only run in the browser, over rows the engine grouped":E?"fullDataset holds the whole matching set, so the grid groups it itself":!W||W.length!==S.length?"the request carries no typed `groupValues` for its group path, and the string `groupPath` cannot be compared against a typed column":"":"a quick search did not push, so the engine would group unsearched rows":"the sort did not push, so the engine would order the groups differently":"a grouping key is not a plain column the engine can name in a GROUP BY":"the adapter does not declare the `group` capability"}function ee(o,s,f=!1){const g=J(o.filters||null,s),y=[];g.residual&&y.push("filter");const m=o.sort||[],E=m.length===0||s.sort==="multi"&&m.length>=1||s.sort==="single"&&m.length===1;!E&&m.length&&y.push("sort");const I=o.quick?String(o.quick):"",S=!I||!!s.quick;S||y.push("quick");const W=o.where&&o.where.active?o.where:null;W&&y.push("where");const se={filters:g.residual,sort:E?null:m,quick:S?"":I,where:W},Ne=!!f,le=Array.isArray(o.groupBy)&&o.groupBy.length>0,Ee=le?oe(o,s,g,E,S,W,Ne):"",ke=le&&Ee==="";le&&!ke&&y.push("group");const Ae=ke&&Array.isArray(o.groupValues)?o.groupValues.length:0,l=ke?!1:Ne||!!(se.filters||se.sort||se.quick||se.where)||!s.range;return{pushed:{...o,filters:g.pushed,sort:E?m:[],quick:S?I:"",range:l?null:o.range},residual:se,needsAll:l,unpushed:y,full:Ne,grouped:ke,groupLevel:Ae,groupReason:Ee}}function pe(o){const s=Array.isArray(o.totals)?o.totals:[],f=o.totalFns&&typeof o.totalFns=="object"?o.totalFns:{},g=[],y=[];for(const m of s){const E=String(m),I=typeof f[E]=="string"?f[E]:null,S=I?N[I]:null;I?!S||!S.pushable||!S.sql?y.push({id:E,fn:I,class:S?S.class:"fallback",reason:S&&S.note?S.note:`the pushdown map cannot express "${I}"`}):S.twoColumn?y.push({id:E,fn:I,class:S.class,reason:`"${I}" reduces two columns, and a grouped request carries no weight column`}):g.push({id:E,col:E,fn:I,class:S.class}):y.push({id:E,fn:null,class:"fallback",reason:"the column totals with a host function, so there is no named statistic to push"})}return{engine:g,client:y}}const je=Object.freeze({items:o=>o==null?[]:Array.isArray(o)?o:[o]});function Me(o,s,f){if(!s)return o;let g=o;if(s.filters&&P(f.evaluateFilters)){const y=g,m={count:g.length,handle:S=>({id:S,get:W=>V(y[W],S)}),itemwise:S=>y.some(W=>Array.isArray(V(W,S)))?je:null},E=f.evaluateFilters(s.filters,m),I=[];for(let S=0;S<g.length;S++)E[S]&&I.push(g[S]);g=I}if(s.where&&s.where.active&&(s.whole||de(s.where.names,"pushdown"),g=g.filter(y=>s.where.passes(y))),s.quick){const y=s.quick.toLowerCase();g=g.filter(m=>{if(!m||typeof m!="object")return!1;for(const E of Object.values(m))if(E!=null&&String(E).toLowerCase().includes(y))return!0;return!1})}if(s.sort&&s.sort.length&&P(f.sortMulti)){const y=[...new Set(s.sort.map(S=>S.col))],m=g,E=y.map(S=>({id:S,get:W=>V(m[W],S)})),I=f.sortMulti(E,s.sort.map(S=>({col:S.col,dir:S.dir})),Uint32Array.from({length:g.length},(S,W)=>W),{});g=Array.from(I,S=>m[S])}return g}function c(o){return JSON.stringify({filters:o.filters||null,sort:o.sort||[],quick:o.quick||"",groupBy:o.groupBy||[],groupPath:o.groupPath||[],context:o.context??null})}function L(o){if(!o||typeof o!="object")return 16;let s="";try{s=JSON.stringify(o)}catch{return 200}return s.length*2+64}function k(o){const s=o||{};return{enabled:!!s.enabled,maxRows:Number.isFinite(s.maxRows)?s.maxRows:1e6,maxBytesEstimate:Number.isFinite(s.maxBytesEstimate)?s.maxBytesEstimate:512*1024*1024}}const R=5e4;function $(o){return Number.isFinite(o)&&o>=0?o:R}function ie(o){return!!o&&P(o.then)}async function ve(o){if(!o||o.total!==void 0||!ie(o.pendingTotal))return o;const s=await o.pendingTotal,{pendingTotal:f,...g}=o;return typeof s=="number"?{...g,total:s}:g}function qe(o={}){const s=o.adapter;if(!s||!P(s.execute))return Z("source.pushdown.adapter","createPushdownSource needs an `adapter` with an `execute(query)` function."),{...o,mode:"remote",fetch:async()=>({rows:[],total:0})};const f=z(s.capabilities),g=s.capabilities&&Object.getOwnPropertyDescriptor(s.capabilities,"operators");g&&P(g.get)&&Object.defineProperty(f,"operators",{enumerable:!0,configurable:!0,get:()=>new Set(s.capabilities.operators||[]),set:()=>{}});const y=s.name||"adapter";let m=null;const E=()=>P(s.ready)?(m||(m=Promise.resolve(s.ready()).then(()=>{Object.assign(f,z(s.capabilities))},q=>{throw m=null,q})),m):null,I=k(o.fullDataset),S=!!o.allowPartialResults,W=$(o.whereRowLimit);let se=null;const Ne=o.aggregates;let le=null,Ee=null,ke=null,Ae=null,l=null,a,d=null,j=0,ge=null;const we=()=>!I.enabled||!le?null:(ge!==le.key&&(j++,ge=le.key),{rows:le.rows,version:j}),ae=async q=>{const ce=q.where&&q.where.active?q.where:null;if(!ce)return{request:q,probe:null};const{where:Q,...O}=q,ue=ee(O,f,I.enabled);if(ue.needsAll)return{request:q,probe:null};const B=c(ue.pushed);let ye=null;return(!se||se.key!==B)&&(f.total?(D(q),ye=await ve(await s.execute(ue.pushed,q)),se={key:B,size:ye&&typeof ye.total=="number"?ye.total:null}):se={key:B,size:null}),se.size!==null&&se.size<W?{request:q,probe:null}:(F(ce.names,y,se.size,W),{request:O,probe:ye})},me=async(q,ce)=>{d=null;const Q=pe(q.pushed);ke={engine:Q.engine,client:Q.client,groupBy:q.pushed.groupBy},Q.client.length&&Z(`source.pushdown.group.totals.${y}.${Q.client.map(B=>B.id).join(".")}`,`the ${y} adapter cannot compute the group subtotal for ${Q.client.map(B=>`"${B.id}" (${B.reason})`).join(", ")}, so those group rows carry no value for that column. A figure computed over anything other than the group would be wrong, so none is shown; \`lastPlan().aggregates.client\` names them.`);const O=await s.executeGroupLevel(q.pushed,Q.engine,ce)||{};let ue=O.rows||[];return!f.range&&ce.range&&(ue=ue.slice(ce.range.start,ce.range.end)),typeof O.matchCount=="number"&&(Ae=O.matchCount,l=O.grand?{totals:O.grand,leafCount:O.matchCount}:null,a===void 0&&P(s.unfilteredCount)&&(a=null,Promise.resolve(s.unfilteredCount()).then(B=>{a=typeof B=="number"?B:null}).catch(B=>{Z(`source.pushdown.group.unfiltered.${y}`,`the ${y} adapter could not count the unfiltered set (${B&&B.message?B.message:B}), so "N of M" falls back to the display count for its denominator.`)}))),O.total===void 0?{rows:ue}:{rows:ue,total:O.total}},Ce=(q,ce)=>{const Q={key:ce,state:"pending",value:null};return d=Q,q.then(O=>(d===Q&&(d={key:ce,state:"settled",value:typeof O=="number"?O:null}),O),O=>{throw d===Q&&(d={key:ce,state:"failed",value:null}),O})},Je=async q=>{const ce=E();ce&&await ce;const Q=await ae(q);D(q);let O=ee(Q.request,f,I.enabled);if(O.grouped&&!P(s.executeGroupLevel)&&(Z(`source.pushdown.group.method.${y}`,`the ${y} adapter declares the \`group\` capability but has no \`executeGroupLevel(query, aggregates, request)\`, so grouping is not pushed and the grid is left to group whatever rows it holds. Implement the method or drop the capability.`),O=ee(Q.request,{...f,group:!1},I.enabled)),Ee=O,O.grouped)return me(O,q);if(O.groupReason&&Z(`source.pushdown.group.${y}.${O.groupReason}`,`the ${y} adapter was not asked to group this query because ${O.groupReason}. The engine returns rows and the grouping is the grid's to do, which needs every matching row in the browser — correct where the grid holds them, and wrong-looking where it holds a window. \`lastPlan().unpushed\` names it.`),!O.needsAll){const _=Q.probe||await s.execute(O.pushed,q),fe=_.rows||[];return ie(_.pendingTotal)&&_.total===void 0?{rows:fe,pendingTotal:Ce(_.pendingTotal,c(O.pushed))}:(d=null,!f.total&&_.total===void 0?{rows:fe}:{rows:fe,total:_.total??fe.length})}O.unpushed.length&&Z(`source.pushdown.residual.${y}.${O.unpushed.join(".")}`,`the ${y} adapter cannot push ${O.unpushed.join(" or ")}, so every matching row is fetched and the rest is applied in the browser. Correct, and slower than it needs to be: widening the adapter is the fix.`);const ue=c(O.pushed);if(!le||le.key!==ue){const _=await ve(await s.execute(O.pushed,q));d=null;const fe=_.rows||[];if(O.full){const Re=typeof _.total=="number"?Math.max(_.total,fe.length):fe.length;if(Re>I.maxRows)throw new Error(`[lattice] fullDataset refused: the ${y} adapter's matching set is ${Re.toLocaleString()} rows, past the configured maxRows of ${I.maxRows.toLocaleString()}. The whole set cannot be held client-side, so it is refused rather than truncated — a fraction shown as the whole would make every total and statistic silently wrong. Narrow the filter or raise maxRows.`);const Te=fe.length*L(fe[0]);if(Te>I.maxBytesEstimate)throw new Error(`[lattice] fullDataset refused: the ${y} adapter's matching set is an estimated ${Math.round(Te/(1024*1024)).toLocaleString()} MB across ${fe.length.toLocaleString()} rows, past the configured maxBytesEstimate of ${Math.round(I.maxBytesEstimate/(1024*1024)).toLocaleString()} MB. The whole set cannot be held client-side, so it is refused rather than truncated. Narrow the filter or raise maxBytesEstimate.`)}if(typeof _.total=="number"&&fe.length<_.total){const Re=!!(O.residual.filters||O.residual.quick||O.residual.sort&&O.residual.sort.length);if(Re&&!S)throw new Error(`[lattice] the ${y} adapter returned ${fe.length} of ${_.total} matching rows when asked for the whole result, and the query has residual ${O.unpushed.join(" and ")||"work"} to finish in the browser. Filtering or sorting a fraction of the result would return wrong rows, so the result is refused. Fix the adapter to follow the engine's own paging before returning, hold the data in memory, or set \`allowPartialResults: true\` on the source config to accept this knowingly.`);Re?Z(`source.pushdown.partial.residual.${y}`,`the ${y} adapter returned ${fe.length} of ${_.total} matching rows when asked for the whole result, and residual work will run over that fraction. allowPartialResults is set, so the result is used as-is — it may be wrong. The adapter must follow the engine's own paging to be correct.`):Z(`source.pushdown.partial.${y}`,`the ${y} adapter returned ${fe.length} of ${_.total} matching rows when asked for the whole result. The adapter must follow the engine's own paging before returning.`)}le={key:ue,rows:fe,total:typeof _.total=="number"?_.total:null}}let B=O;if(O.residual.where){const _=le.total??le.rows.length;if(_>=W){F(O.residual.where.names,y,_,W);const{where:fe,...Re}=Q.request;B=ee(Re,f,I.enabled),Ee=B}}const ye=le.total!==null&&le.rows.length>=le.total,We=Me(le.rows,{...B.residual,whole:ye},o.compute||{}),Le=q.range?q.range.start:0,Se=q.range?q.range.end:We.length;return{rows:We.slice(Le,Se),total:We.length}},ot=async(q,ce)=>{const Q=E();Q&&await Q;const O=ee(q,f,I.enabled);Ee=O;const ue=ne(ce,Ne),B=Array.isArray(q.groupBy)?q.groupBy:[],ye=B.length>0,We=!O.residual.filters&&!O.residual.quick,Le=!ye||T(B,f.buckets);let Se=ue.engine,_=ue.client;const fe=Ze=>{_=[...Se.map(st=>({...st,reason:Ze})),..._],Se=[]};Se.length&&!We?fe(O.residual.quick&&!O.residual.filters?"a quick search the adapter cannot push forces all-client (no mixed provenance)":"residual filter forces all-client (no mixed provenance)"):Se.length&&!Le&&fe("a grouping key the engine cannot form forces all-client (no mixed provenance)");let Re={},Te;return Se.length&&(P(ye?s.executeGroupedAggregates:s.executeAggregates)?ye?Te=await s.executeGroupedAggregates(O.pushed,B,Se)||[]:Re=await s.executeAggregates(O.pushed,Se)||{}:(Z(`source.pushdown.aggregates.${y}${ye?".grouped":""}`,`the ${y} adapter cannot compute ${ye?"grouped ":""}aggregates, so every requested statistic is computed client-side. Correct, and slower than it needs to be.`),fe(`adapter cannot compute ${ye?"grouped ":""}aggregates`))),ke={engine:Se,client:_,...ye?{groupBy:B}:{}},{values:Re,engine:Se,client:_,...Te!==void 0?{groups:Te}:{}}},it=x(o.edit),ze=o.edit&&typeof o.edit=="object"&&P(o.edit.commit);let $e=o.edit;if(it&&!ze)if(f.mutate&&f.mutate.update){const q=ce=>{if(!f.mutate||!f.mutate.update)throw new Error(`[lattice] the ${y} adapter cannot update rows (mutate.update is not declared), so this edit cannot be persisted. The cell is reverted rather than left looking saved.`);const Q={kind:"update",key:String(ce.key),patch:{[ce.colId]:ce.value}};return s.mutate(Q,ce.request||{})};$e={...o.edit===!0?{}:o.edit,commit:q}}else Z(`source.pushdown.readonly.${y}`,`edit is enabled but the ${y} adapter declares mutate: ${f.mutate?"without update":"false"} (read-only by declaration), so no commit is synthesised and the grid stays read-only. Declare \`mutate: { update: true }\` on the adapter to allow cell edits.`);const He=it&&f.mutate&&(f.mutate.append||f.mutate.delete)?{append:f.mutate.append===!0,remove:f.mutate.delete===!0,returning:f.mutate.returning,mutate:(q,ce)=>s.mutate(q,ce||{})}:null;return{...o,edit:$e,rowMutate:He,mode:"remote",fetch:Je,aggregate:ot,lastPlan:()=>Ee?{...Ee,...ke?{aggregates:ke}:{},...d?{total:{deferred:!0,state:d.state,value:d.value}}:{}}:null,fullFrame:we,counts:()=>({match:Ae,total:a??null,pending:!!d&&d.state==="pending"}),grandTotals:()=>l}}}),xe("packages/core/src/model/rowkey.js",function(h,he){"use strict";Object.defineProperty(h,"KEY_DEPENDENT_FEATURES",{enumerable:!0,get:function(){return de}}),Object.defineProperty(h,"compositeKey",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(h,"createRowKey",{enumerable:!0,get:function(){return T}}),Object.defineProperty(h,"warnMissingKeys",{enumerable:!0,get:function(){return M}}),Object.defineProperty(h,"groupPathKey",{enumerable:!0,get:function(){return D}}),Object.defineProperty(h,"splitPathKey",{enumerable:!0,get:function(){return G}});const te=he("packages/core/src/internal/util.js"),P=te.warnOnce,Z=te.pathGetter,X=te.isFunction,re=te.isBlank,de=["changes (rows.apply / rows.queue)","streaming dedupe","selection persistence","remote reload","cell comments"],F="";function Y(v){if(v===null)return"\0n";if(v===void 0)return"\0u";const V=typeof v;if(V==="string")return v;if(V==="number"||V==="bigint"||V==="boolean")return String(v);if(v instanceof Date)return`\0d${v.getTime()}`;try{return`\0o${JSON.stringify(v)}`}catch{return"\0o?"}}function ne(v){if(v.length===1)return Y(v[0]);let V="";for(let x=0;x<v.length;x++)x&&(V+=F),V+=Y(v[x]);return V}function T(v,V={}){const x=V.warn!==!1;if(X(v)){const z=v;return{stable:!0,fields:[],disabled:[],key(U,J){try{const oe=z(U);return Array.isArray(oe)?ne(oe):Y(oe)}catch(oe){return P("rowKey.throw","rowKey function threw; falling back to index identity for the affected rows.",oe),`#${J??-1}`}},keyEmpty(U){try{const J=z(U);return Array.isArray(J)?J.length===0||J.some(re):re(J)}catch{return!1}},missingFields(){return[]}}}if(Array.isArray(v)&&v.length>0){const z=v.filter(oe=>typeof oe=="string"),U=z.map(oe=>Z(oe)),J=U.length;return{stable:!0,fields:z,disabled:[],key(oe){const ee=new Array(J);for(let pe=0;pe<J;pe++)ee[pe]=U[pe](oe);return ne(ee)},keyEmpty(oe){for(let ee=0;ee<J;ee++)if(re(U[ee](oe)))return!0;return!1},missingFields(oe){const ee=[];for(let pe=0;pe<J;pe++)re(U[pe](oe))&&ee.push(z[pe]);return ee}}}if(typeof v=="string"&&v.length>0){const z=Z(v);return{stable:!0,fields:[v],disabled:[],key(U){return Y(z(U))},keyEmpty(U){return re(z(U))},missingFields(U){return re(z(U))?[v]:[]}}}return x&&P("rowKey.missing",`no rowKey configured, so rows are identified by object identity. This disables: ${de.join(", ")}. Set rowKey to a field name, an array of field names, or a function.`),{stable:!1,fields:[],disabled:de.slice(),key(z,U){if(z===null||typeof z!="object")return`#${U??0}:${String(z)}`;let J=N.get(z);return J===void 0&&(J=`#${C++}`,N.set(z,J)),J}}}const N=new WeakMap;let C=0;function M(v,V){if(!v||v.stable===!1||!X(v.keyEmpty)||!Array.isArray(V)||V.length===0)return;let x=0,z=null,U;for(let pe=0;pe<V.length;pe++){const je=V[pe];v.keyEmpty(je)&&(x++,z===null&&(z=X(v.missingFields)?v.missingFields(je):[],U=je))}if(x===0)return;const J=v.fields.length?v.fields.join(","):"(function)",oe=z&&z.length?z.join(", "):v.fields.length?v.fields.join(", "):"the rowKey function",ee=U!==null&&typeof U=="object"?Object.keys(U).join(", ")||"(no fields)":String(U);P(`rowKey.emptyValue:${J}`,`rowKey ${oe} is missing on ${x} of ${V.length} rows; the first such row has: ${ee}. Rows without a key value collapse onto one key, so selection, edits and rows.apply updates land on whichever row now shares it. Set rowKey to a field present on every row, or fix the source data.`)}function D(v){return ne(v)}function G(v){return v.split(F)}}),xe("packages/modules/data-router/devtools.js",function(h,he){"use strict";Object.defineProperty(h,"mountRouterDevtools",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(h,"default",{enumerable:!0,get:function(){return ne}});const P=he("packages/core/src/internal/util.js").warnOnce,Z="lat-router-devtools";function X(T,N,C){const M=T.createElement(N);return M.textContent=C==null?"—":String(C),M}function re(T){return Number.isFinite(T)?`${Math.round(T*10)/10}/s`:"—"}function de(T,N,C,M){const D=T.createElement("section");D.className=`${Z}-section`;const G=T.createElement("h4");G.textContent=N,D.appendChild(G);const v=T.createElement("table"),V=T.createElement("tr");for(const x of C)V.appendChild(X(T,"th",x));v.appendChild(V);for(const x of M){const z=T.createElement("tr");for(const U of x)z.appendChild(X(T,"td",U));v.appendChild(z)}return D.appendChild(v),D}function F(T,N,C){N.textContent="";const M=de(T,"Router",["metric","value"],[["throughput",re(C.throughput)],["unrouted",C.unrouted],["dropped (duplicate)",C.dropped],["buffer depth",C.buffered],["lag (deltas behind)",C.lag]]);N.appendChild(M),N.appendChild(de(T,"Routes",["#","label","kind","rows","shown","rows/sec"],C.routes.map(D=>[D.index,D.label,D.kind,D.rows,D.shown,re(D.throughput)]))),C.sources.length&&N.appendChild(de(T,"Sources",["id","rows","ingested","rows/sec"],C.sources.map(D=>[D.id,D.rows,D.ingested,re(D.throughput)])))}function Y(T,N,C={}){const M=N&&N.ownerDocument||(typeof document<"u"?document:null);if(!T||typeof T.metrics!="function"||typeof T.on!="function"||!N||!M)return P("data-router:devtools-target","router.mountDevtools(el) needs a router with metrics()/on() and a DOM element to render into; the panel was not mounted."),{destroy(){},refresh(){}};const D=M.createElement("div");D.className=Z,N.appendChild(D);const G=()=>F(M,D,T.metrics());G();const v=T.on("metrics",()=>G());return{refresh:G,destroy(){v(),D.parentNode&&D.parentNode.removeChild(D)}}}const ne=Y}),xe("packages/modules/data-router/index.js",function(h,he){"use strict";Object.defineProperty(h,"createDataRouter",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(h,"default",{enumerable:!0,get:function(){return Me}});const P=he("packages/core/src/internal/util.js").warnOnce,Z=he("packages/core/src/source/pushdown.js"),X=Z.planQuery,re=Z.capabilitiesOf,F=he("packages/core/src/model/rowkey.js").compositeKey,ne=he("packages/modules/data-router/devtools.js").mountRouterDevtools;function T(c,L){return typeof c=="function"?c:typeof c=="string"?k=>k[c]:L}function N(c){return Array.isArray(c)?"array":c===null?"null":typeof c}function C(c,L){if(c===void 0||typeof c=="string"&&c.length>0)return c;if(typeof c=="function")return k=>{const R=c(k);if(typeof R=="string"||typeof R=="number"&&Number.isFinite(R))return R;throw new Error(`lattice-data-router: rowKey function must return a string or number; got ${N(R)}.`)};throw new Error(`lattice-data-router: rowKey must be a property name or a function; composite keys are not supported on ${L}.`)}function M(c){if(typeof c=="function")return c;if(c&&typeof c=="object"&&typeof c.key=="string"){const L=c.dir==="desc"?-1:1,{key:k}=c;return(R,$)=>{const ie=R?R[k]:void 0,ve=$?$[k]:void 0;return ie<ve?-1*L:ie>ve?1*L:0}}return null}function D(c){if(!c||typeof c!="object")return null;let L=0;Number.isFinite(c.minInterval)&&c.minInterval>0?L=Number(c.minInterval):Number.isFinite(c.maxHz)&&c.maxHz>0&&(L=1e3/Number(c.maxHz));const k=Number.isFinite(c.sample)&&c.sample>1?Math.floor(Number(c.sample)):1,R=Number.isFinite(c.maxLag)&&c.maxLag>=0?Math.floor(Number(c.maxLag)):null;return L===0&&k===1&&R===null?null:{minInterval:L,sample:k,maxLag:R}}let G=0;function v(){return G+=1,`r${G}`}function V(c){const k=(Array.isArray(c)?c:[c]).map(R=>({name:typeof R=="string"?R:null,get:T(R,()=>{})}));return R=>{const $={},ie=[];for(const ve of k){const qe=ve.get(R);ie.push(qe),ve.name&&($[ve.name]=qe)}return{key:F(ie),fields:$}}}function x(c,L){if(typeof c=="function")return c(L);if(c&&typeof c=="object"){const{op:k,field:R}=c;if(k==="count")return L.length;const $=R!=null?L.map(ie=>Number(ie[R])).filter(ie=>Number.isFinite(ie)):[];if(k==="sum")return $.reduce((ie,ve)=>ie+ve,0);if(k==="avg")return $.length?$.reduce((ie,ve)=>ie+ve,0)/$.length:0;if(k==="min")return $.length?Math.min(...$):void 0;if(k==="max")return $.length?Math.max(...$):void 0}}function z(c){return c&&typeof c=="object"&&typeof c.from=="string"&&typeof c.to=="string"?{from:c.to,to:c.from}:(P("data-router:mutual-fn","relate({ mutual: true }) with a function relation cannot be inverted; the same predicate is applied in both directions. Use a { from, to } key map for a mutual edge."),c)}function U(c,L){return c?L?{op:"and",conditions:[c,L]}:c:L||null}const J=Object.freeze(["eq","ne","lt","lte","gt","gte","between","notBetween","in","notIn","contains","notContains","startsWith","endsWith","blank","notBlank"]);function oe(c,L){const k=L?L[c.col]:void 0,R=c.value,$=ie=>c.caseSensitive?String(ie):String(ie).toLowerCase();switch(c.op){case"eq":return k===R;case"ne":return k!==R;case"lt":return k<R;case"lte":return k<=R;case"gt":return k>R;case"gte":return k>=R;case"between":return Array.isArray(R)&&k>=R[0]&&k<=R[1];case"notBetween":return!(Array.isArray(R)&&k>=R[0]&&k<=R[1]);case"in":return Array.isArray(R)&&R.includes(k);case"notIn":return!(Array.isArray(R)&&R.includes(k));case"contains":return k!=null&&$(k).includes($(R));case"notContains":return k==null||!$(k).includes($(R));case"startsWith":return k!=null&&$(k).startsWith($(R));case"endsWith":return k!=null&&$(k).endsWith($(R));case"blank":return k==null||k==="";case"notBlank":return!(k==null||k==="");default:throw new Error(`[lattice] query() cannot evaluate the residual filter operator "${String(c.op)}" on column "${String(c.col)}" client-side, so the query is refused rather than returning rows the filter excludes. Push it down to an adapter that implements it, or use an operator this router evaluates: ${J.join(", ")}.`)}}function ee(c,L){return c?Array.isArray(c.conditions)?c.op==="or"?c.conditions.some(k=>ee(k,L)):c.op==="not"?!c.conditions.every(k=>ee(k,L)):c.conditions.every(k=>ee(k,L)):oe(c,L):!0}function pe(c={}){const L=T(c.key,()=>{}),k=T(C(c.rowKey,"routes"),e=>e.rowKey),R=!!c.overlap,$=typeof c.onUnrouted=="function"?c.onUnrouted:null,ie=Number.isFinite(c.selectionDebounce)?Number(c.selectionDebounce):16,ve=typeof c.onWrite=="function"?c.onWrite:null,qe=typeof c.onConflict=="function"?c.onConflict:null,o=c.seq!=null?T(c.seq,()=>{}):null,s=o?c.dedupe!==!1:!1,f=k;let g=null;typeof c.batch=="number"?g=c.batch:c.batch&&Number.isFinite(c.batch.intervalMs)&&(g=Number(c.batch.intervalMs));const y=g!==null||!!c.coalesce,m=new Map;let E,I=0;const S=[];let W=null;const se=c.time!=null?T(c.time,()=>{}):null,Ne=typeof c.now=="function"?c.now:Date.now,le=1e4;let Ee=!1,ke=null,Ae=null,l="time",a=new Map;const d=[];let j=0,ge,we,ae=!1,me=null,Ce=[],Je=0,ot=0,it="time",ze=!1,$e=null,He=null;const q=e=>{if(e&&Number.isFinite(e.seq))return e.seq;if(o&&e&&e.row){const t=o(e.row);return Number.isFinite(t)?t:void 0}},ce=e=>{if(e&&Number.isFinite(e.t))return e.t;if(se&&e&&e.row){const t=se(e.row);if(Number.isFinite(t))return t}return Ne()},Q=[];let O=null;const ue=[],B=[],ye=new Map,We=new Set;let Le=null,Se=0;const _=new Map,fe=new Set,Re=typeof c.rowKey=="string"?c.rowKey:"rowKey",Te=new Map;let Ze=0;const st=new Map,Be=(e,t)=>{st.set(e,(st.get(e)||0)+t)};let bt=0;const wt=new Map,ut=new Map;let Ue=null;const qt=Number.isFinite(c.metricsInterval)?Number(c.metricsInterval):1e3;let Ve=0,Fe=null,vt="lattice-router",Et=250,Ie=null,Xe=null,lt=!1,kt=!1,De=null,et=!1,St=null;const Ge=[],be=()=>O?[...Q,O]:Q,Qe=e=>be().find(t=>t.grid===e)||null,at=e=>{const t=[];for(const n of Q)if(n.match(e)&&(t.push(n),!R))break;return t.length?t:O?[O]:[]},on=(e,t)=>{if(t.add.length||t.update.length||t.remove.length){const n=e.sink(t);sn(e,n)}return{added:t.add.length,updated:t.update.length,removed:t.remove.length}},sn=(e,t)=>{const n=t?.rejected;if(!Array.isArray(n)||!n.length)return;const r=n.filter(u=>u&&u.operation==="remove");if(!r.length)return;const i=e.label||`route ${e.routeId}`;P(`data-router:remove-rejected:${e.routeId}`,`route "${i}" asked its target to remove ${r.length} row(s) the target does not have (for example ${JSON.stringify(String(r[0].id))}). The rows are still on screen. This is a key mismatch: the key the route derives for a row is not the key the grid derives for it. Check that the route's \`rowKey\` names the same value as the grid's.`)},un=(e,t)=>{for(const n of ue)if(n.to===e.grid&&n.predicate&&!n.predicate(t))return!1;if(e.graphPreds){for(const n of e.graphPreds)if(!n(t))return!1}return!0},Ke=e=>{const t=[];for(const p of e.partition.values())e.filter&&!e.filter(p)||un(e,p)&&t.push(p);let n;if(e.rollup){const p=new Map;for(const b of t){const{key:A,fields:K}=e.rollup.group(b);let H=p.get(A);H||(H={key:A,fields:K,rows:[]},p.set(A,H)),H.rows.push(b)}let w=[];for(const b of p.values()){const A={...b.fields};for(const[K,H]of e.rollup.specs)A[K]=x(H,b.rows);w.push({gkey:b.key,row:A})}e.sort&&w.sort((b,A)=>e.sort(b.row,A.row)),e.transform&&(w=w.map(b=>({gkey:b.gkey,row:e.transform(b.row)}))),n=new Map(w.map(b=>[b.gkey,b.row]))}else{let p=t;e.sort&&(p=p.slice().sort(e.sort)),n=new Map;for(const w of p)n.set(F([e.keyOf(w)]),e.transform?e.transform(w):w)}const r=[],i=[],u=[];for(const[p,w]of n)e.keys.has(p)?je(e.keys.get(p),w)||i.push(w):r.push(w);for(const p of e.keys.keys())n.has(p)||u.push(p);return e.keys=n,on(e,{add:r,update:i,remove:u})},ct=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),Ke(e),e.bpPending=0,e.bpLastFlush=Ne()},ln=(e,t)=>{if(e.bpTimer)return;const n=e.bp.minInterval>0?Math.max(e.bp.minInterval-(t-e.bpLastFlush),0):0;e.bpTimer=setTimeout(()=>{e.bpTimer=null,ct(e)},n),e.bpTimer&&typeof e.bpTimer.unref=="function"&&e.bpTimer.unref()},an=(e,t)=>{if(!e.bp){Ke(e);return}e.bpPending+=t,e.bpCoalesced+=t;const n=e.bp;if(n.maxLag!=null&&e.bpPending<=n.maxLag&&!e.bpTimer){ct(e);return}const r=Ne(),i=r-e.bpLastFlush>=n.minInterval,u=e.bpPending>=n.sample;if(i&&u){ct(e);return}ln(e,r)},cn=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),e.bpPending=0,e.bpLastFlush=Ne()},Ot=(e,t)=>{if(typeof e=="function"){const n=e(t);return typeof n=="function"?n:null}if(e&&typeof e=="object"){const n=e.from,r=e.to,i=new Set(t.map(u=>u&&u[n]));return u=>i.has(u&&u[r])}return null},Ht=e=>{const t=Qe(e),n=e&&e.selection,r=n&&typeof n.keys=="function"?n.keys():[];return!r.length||!t?[]:r.map(i=>t.partition.get(String(i))).filter(i=>i!==void 0)},Ye=e=>{const t=Ht(e.from);e.predicate=t.length?Ot(e.relation,t):null},tt=()=>{const e=new Set;for(const t of B)e.add(t.from),e.add(t.to);return e},_e=()=>{for(const u of be())u.graphPreds=null;if(!B.length)return;const e=tt(),t=new Map;for(const u of e){const p=Ht(u);p.length&&t.set(u,p)}const n=new Map(t);let r=!0,i=(e.size+1)*2;for(;r&&i-- >0;){r=!1;for(const u of e){if(t.has(u))continue;const p=B.filter(H=>H.to===u&&n.has(H.from));if(!p.length)continue;const w=Qe(u);if(!w)continue;const b=p.map(H=>Ot(H.rel,n.get(H.from))).filter(Boolean),A=[];for(const H of w.partition.values())b.every(Oe=>Oe(H))&&A.push(H);const K=n.get(u);if(!K||K.length!==A.length)n.set(u,A),r=!0;else{const H=new Set(K);A.some(Oe=>!H.has(Oe))&&(n.set(u,A),r=!0)}}}for(const u of B){if(!n.has(u.from))continue;const p=Ot(u.rel,n.get(u.from));if(!p)continue;const w=Qe(u.to);w&&(w.graphPreds||(w.graphPreds=[])).push(p)}},Bt=e=>{const t=ye.get(e);if(t){t.count+=1;return}const n=e&&typeof e.on=="function"?e.on("selection:changed",()=>fn(e)):()=>{};ye.set(e,{off:n,count:1})},Tt=()=>{Le&&(clearTimeout(Le),Le=null);const e=We;if(!e.size)return;const t=new Set;for(const n of ue)e.has(n.from)&&(Ye(n),t.add(n.to));if(We.clear(),B.length){_e();for(const n of tt())t.add(n)}for(const n of t){const r=Qe(n);r&&Ke(r)}},fn=e=>{if(We.add(e),ie<=0){Tt();return}Le||(Le=setTimeout(Tt,ie))},Kt=e=>{const t=ye.get(e);t&&(t.count-=1,t.count<=0&&(t.off(),ye.delete(e)))},dn=e=>typeof e=="function"?t=>e(t):e&&e.rows&&typeof e.rows.apply=="function"?t=>e.rows.apply(t):(P("data-router:bad-target","attach/subscribe target has no rows.apply and is not a function; its slice goes nowhere. Pass a grid or a handler(change) function."),()=>{}),jt=(e,t,n)=>({grid:e,routeId:v(),sink:dn(e),match:t,keyOf:T(C(n.rowKey,"routes"),k),partition:new Map,keys:new Map,transform:typeof n.transform=="function"?n.transform:null,filter:typeof n.filter=="function"?n.filter:null,sort:M(n.sort),rollup:n.rollup&&n.rollup.groupBy!=null?{group:V(n.rollup.groupBy),specs:Object.entries(n.rollup.aggregate||{})}:null,where:n.where&&typeof n.where=="object"?n.where:null,graphPreds:null,onWrite:typeof n.onWrite=="function"?n.onWrite:null,onConflict:typeof n.onConflict=="function"?n.onConflict:null,writable:n.writable===!0,readonly:!!(n.rollup&&n.rollup.groupBy!=null||typeof n.transform=="function"),label:typeof n.label=="string"?n.label:null,metricRows:0,bp:D(n.backpressure),bpPending:0,bpTimer:null,bpLastFlush:-1/0,bpCoalesced:0}),xt=e=>{if(!R){for(const t of Q)if(t.hasPartValue&&t.partValue===e){P(`data-router:overlap:${String(e)}`,`Data Router: value ${JSON.stringify(e)} already routes to another viewer; with overlap:false only the first receives rows. Pass createDataRouter({ overlap: true }) to fan one value to several viewers.`);return}}},zt=(e,t)=>`${String(e)}${String(t)}`,pn=e=>{const t=e&&e.row;if(!t)return null;const n=t.data&&typeof t.data=="object"?t.data:t;return n?{...n}:null},ft=(e,t)=>{const n=e.grid;if(!n||!n.edit||typeof n.edit.setCells!="function")return;const r=zt(t.key,t.colId);fe.add(r);try{n.edit.setCells([{key:t.key,colId:t.colId,value:t.before}],"cell")}finally{fe.delete(r)}Be("writeReverted",1)},Ut=e=>{e&&Pe.apply([{op:"upsert",row:e}])},Vt=(e,t,n)=>{const r=n&&typeof n=="object"?n:null,i=r&&r.conflict!==void 0?r.conflict:null;if(i){const u=e.onConflict||qe;if(u)try{u(t,{serverRow:i})}catch{}Be("writeConflicted",1),Ut(r&&r.row?r.row:t.row);return}if(n===!1||r&&r.ok===!1){Be("writeRejected",1),ft(e,t);return}Be("writeAccepted",1),Ut(r&&r.row?r.row:t.row)},hn=e=>{const t=String(e);for(const n of Te.values())if(n.live.has(t))return n.handle;return null},gn=(e,t)=>{if(!t||t.key===void 0||t.colId===void 0||fe.has(zt(t.key,t.colId)))return;const n=pn(t),r={key:String(t.key),colId:String(t.colId),value:t.value,before:t.oldValue,row:n};if(Be("writeRouted",1),e.readonly){P("data-router:readonly-write","an edit on a derived (rollup/transform) route is read-only and was reverted; a derived row cannot be inverted to a source row. Make the source route writable instead."),ft(e,r);return}const i=e.onWrite||ve;if(!i){P("data-router:no-onwrite","a route attached with { writable: true } has no onWrite handler (per-route or router-global); the edit was left in place but not persisted. Pass onWrite to route the write.");return}let u;try{u=i(r,{route:e.grid,source:hn(r.key)})}catch{ft(e,r),Be("writeRejected",1);return}u&&typeof u.then=="function"?u.then(p=>Vt(e,r,p),()=>{ft(e,r),Be("writeRejected",1)}):Vt(e,r,u)},mn=e=>{const t=e.grid;if(!t||typeof t.on!="function"||!t.edit||typeof t.edit.setCells!="function"){P("data-router:writable-target","attach({ writable: true }) needs a grid exposing grid.on and grid.edit.setCells; write-back is off for this route.");return}if(_.has(t))return;const n=t.on("cell:changed",r=>gn(e,r));_.set(t,typeof n=="function"?n:()=>{})},yn=e=>{const t=[];for(const n of e.partition.values())e.filter&&!e.filter(n)||t.push(n);return t},dt=e=>{const t=yn(e);if(e.kind==="monitor"){let r;try{r=e.evaluate(t)}catch{r=void 0}e.handler(r,t);return}let n;try{n=e.condition(t)}catch{n=!1}if(n){if(!e.armed)return;e.debounceMs>0?(e.pending={signal:n,rows:t},e.timer||(e.timer=setTimeout(()=>{e.timer=null;const r=e.pending;e.pending=null,r&&(e.armed=!1,e.handler(r.signal,r.rows))},e.debounceMs))):(e.armed=!1,e.handler(n,t))}else e.armed=!0,e.timer&&(clearTimeout(e.timer),e.timer=null),e.pending=null},Rt=(e,t)=>{e.partition=new Map;for(const n of t)e.match(n)&&e.partition.set(String(e.keyOf(n)),n)},bn=(e,t)=>{for(const n of t){const r=n&&n.row;if(!r)continue;const i=String(e.keyOf(r));if(n.op==="delete"){e.partition.delete(i);continue}e.match(r)?e.partition.set(i,r):e.partition.delete(i)}},nt=()=>{const e=new Map;for(const t of be())for(const n of t.partition.values())e.set(String(f(n)),n);return[...e.values()]},Gt=()=>{a=new Map;for(const e of be())for(const t of e.partition.values())a.set(String(f(t)),t);d.length=0,j=0,ge=E,we=void 0},Jt=()=>{const e=d.shift();e&&(e.op==="del"?a.delete(e.key):a.set(e.key,e.row),ge=e.seq,we=e.t)},wn=()=>{if(ke!=null)for(;d.length>ke;)Jt();if(Ae!=null&&d.length){const e=d[d.length-1].t;for(;d.length>1&&e-d[0].t>Ae;)Jt()}},vn=e=>{!e||!e.row||d.push({pos:j++,seq:q(e),t:ce(e),op:e.op==="delete"?"del":"set",key:String(f(e.row)),row:e.row})},Pt=(e,t)=>t==="seq"?e.seq:e.t,pt=(e,t)=>{const n=new Map(a);for(const r of d){const i=Pt(r,t);if(e!==void 0&&i!==void 0&&i>e)break;r.op==="del"?n.delete(r.key):n.set(r.key,r.row)}return n},ht=e=>{const t=new Map(be().map(n=>[n,[]]));for(const n of e)for(const r of at(n))t.get(r).push(n);for(const n of be())n.partition=new Map(t.get(n).map(r=>[String(n.keyOf(r)),r]));for(const n of ue)Ye(n);_e();for(const n of be())Ke(n)},Nt=e=>Ee?!0:(P("data-router:no-buffer",`${e}() needs a buffered window; call router.buffer({ window, max }) first to record one.`),!1),gt=()=>{if($e&&(clearTimeout($e),$e=null),ze=!1,Ce=[],Je=0,He){const e=He;He=null,e()}},En=()=>{if(Ce=[],Je=0,He){const e=He;He=null,e()}},kn=()=>{$e=null;const e=Ce[Je++];e.op==="del"?me.delete(e.key):me.set(e.key,e.row),ht([...me.values()]),Ve=e.pos+1,At()};function At(){if(!ze){if(Je>=Ce.length){En();return}$e=setTimeout(kn,ot)}}function mt(e){if(De)try{De.postMessage(e)}catch{}}function Qt(){return{t:"snapshot",rows:nt(),seq:E,checkpoint:Object.fromEntries(m)}}function Sn(e){const t=e&&e.data;if(!(!t||typeof t!="object")){if(t.t==="hello"){nt().length&&mt(Qt());return}et=!0;try{t.t==="delta"?Pe.apply(t.deltas||[]):t.t==="snapshot"&&(Pe.load(t.rows||[]),t.checkpoint&&Pe.seenThrough(t.checkpoint))}finally{et=!1}}}function On(e,t){e.partition=new Map(t.map(n=>[String(e.keyOf(n)),n]))}function Tn(e,t){const n=t.filter(i=>!i.isDefault),r=t.find(i=>i.isDefault)||null;for(const i of t)i.partition=new Map;for(const i of e){const u=[];for(const w of n)if(w.match(i)&&(u.push(w),!R))break;const p=u.length?u:r?[r]:[];if(!p.length){Se+=1,$&&$(i);continue}for(const w of p)w.partition.set(String(w.keyOf(i)),i)}}const jn=(e,t)=>{if(typeof t=="function")return r=>t(r);let n=null;return t===!0?n=String(e):typeof t=="string"&&(n=t),n==null?null:r=>`${n}:${r[Re]}`},_t=(e,t)=>{const n={...e.map?e.map(t):t};return e.ns&&(n[Re]=e.ns(n)),n},Yt=(e,t)=>{const n=[];for(const r of t||[]){if(!r||!r.row)continue;const i=_t(e,r.row),u=String(i[Re]);r.op==="delete"?e.live.delete(u):e.live.set(u,i),n.push({...r,row:i})}return e.ingested+=n.length,Be(`source:${e.id}`,n.length),n},Rn=e=>({get id(){return e.id},get size(){return e.live.size},load(t){const n=(t||[]).map(u=>_t(e,u)),r=new Map(n.map(u=>[String(u[Re]),u])),i=[];for(const[u,p]of e.live)r.has(u)||i.push({op:"delete",row:p});for(const u of n)i.push({op:"upsert",row:u});return e.live=r,e.ingested+=n.length,Be(`source:${e.id}`,n.length),Dt(e,i,u=>Pe.apply(u)),this},apply(t){return Dt(e,Yt(e,t),n=>Pe.apply(n)),this},push(t){return Dt(e,Yt(e,Array.isArray(t)?t:[t]),n=>Pe.push(n)),this},remove(){const t=[];for(const n of e.live.values())t.push({op:"delete",row:n});return e.live.clear(),Te.delete(e.id),t.length&&Pe.apply(t),Pe}}),Ft=e=>e==null?null:String(e),Pn=(e,t)=>{if(!e||typeof e!="object")return null;const n=e.from!=null?String(e.from):null;if(!n)return P("data-router:join-no-from","join needs a `from` (the lookup source id); ignoring the join."),null;const r=e.localKey!=null?e.localKey:e.on;let i;if(typeof r=="function")i=r;else if(typeof r=="string")i=Oe=>Oe[r];else return P("data-router:join-no-localkey","join needs a `localKey` (a field name or fn); ignoring the join."),null;const u=e.foreignKey!=null?e.foreignKey:e.fromKey;let p,w;if(typeof u=="function")p=u,w=u;else if(typeof u=="string")p=Oe=>Oe[u],w=u;else if(typeof r=="string")p=Oe=>Oe[r],w=r;else return P("data-router:join-no-foreignkey","join with a fn `localKey` needs an explicit string/fn `foreignKey`; ignoring the join."),null;let b=null;const A=[],K=e.fields!=null?e.fields:e.select;if(typeof K=="function")b=K;else if(Array.isArray(K))for(const Oe of K)A.push([String(Oe),String(Oe)]);else if(K&&typeof K=="object")for(const[Oe,rt]of Object.entries(K))A.push([Oe,String(rt)]);else P("data-router:join-no-fields","join has no `fields`/`select`; rows pass through unenriched.");let H=e.missing;return H!=="hold"&&H!=="passthrough"&&H!=="null"&&(H!=null&&P("data-router:join-bad-missing",`join.missing "${H}" is not hold|passthrough|null; using "passthrough".`),H="passthrough"),{from:n,localKey:i,foreignKeyFn:p,ffKey:w,pairs:A,selectFn:b,missing:H,keyIndex:new Map,lastFk:new Map,owner:t,probe:null}},Zt=(e,t,n)=>{const r={...t};if(e.selectFn){const i=e.selectFn(n,t);return i&&typeof i=="object"&&Object.assign(r,i),r}for(const[i,u]of e.pairs)r[u]=n?n[i]:null;return r},Nn=(e,t)=>{if(t==null||!e.probe)return null;const n=e.probe.index.get(t);if(!n||!n.size)return null;const r=Te.get(e.from);if(!r)return null;let i;for(i of n);return r.live.get(i)||null},Xt=(e,t,n)=>{const r=Nn(e,n);return r?{emit:!0,row:Zt(e,t,r)}:e.missing==="hold"?{emit:!1,row:t}:e.missing==="null"?{emit:!0,row:Zt(e,t,null)}:{emit:!0,row:{...t}}},en=(e,t,n)=>{const r=e.lastFk.get(t);if(r!==void 0&&r!==n){const u=e.keyIndex.get(r);u&&(u.delete(t),u.size||e.keyIndex.delete(r))}if(n==null){e.lastFk.set(t,null);return}let i=e.keyIndex.get(n);i||(i=new Set,e.keyIndex.set(n,i)),i.add(t),e.lastFk.set(t,n)},An=(e,t)=>{const n=e.join,r=[];for(const i of t){const u=String(i.row[Re]);if(i.op==="delete"){en(n,u,null),n.lastFk.delete(u),r.push(i);continue}const p=Ft(n.localKey(i.row));en(n,u,p);const w=Xt(n,i.row,p);w.emit&&r.push({...i,row:w.row})}return r},tn=(e,t)=>{e.probes||(e.probes=new Map);let n=e.probes.get(t.ffKey);if(!n){n={fn:t.foreignKeyFn,index:new Map,prev:new Map,specs:new Set},e.probes.set(t.ffKey,n);for(const[r,i]of e.live){const u=Ft(n.fn(i));if(u==null)continue;let p=n.index.get(u);p||(p=new Set,n.index.set(u,p)),p.add(r),n.prev.set(r,u)}}n.specs.add(t),t.probe=n},Fn=(e,t)=>{if(!e.probes||!e.probes.size)return;const n=[];for(const r of e.probes.values()){const i=new Set;for(const u of t){const p=String(u.row[Re]);if(u.op==="delete"){const A=r.prev.get(p);if(A!=null){const K=r.index.get(A);K&&(K.delete(p),K.size||r.index.delete(A)),i.add(A)}r.prev.delete(p);continue}const w=Ft(r.fn(u.row)),b=r.prev.get(p);if(b!=null&&b!==w){const A=r.index.get(b);A&&(A.delete(p),A.size||r.index.delete(b)),i.add(b)}if(w!=null){let A=r.index.get(w);A||(A=new Set,r.index.set(w,A)),A.add(p),i.add(w)}r.prev.set(p,w)}if(i.size)for(const u of r.specs)for(const p of i){const w=u.keyIndex.get(p);if(w)for(const b of w){const A=u.owner.live.get(b);if(!A)continue;const K=Xt(u,A,p);n.push(K.emit?{op:"upsert",row:K.row}:{op:"delete",row:A})}}}n.length&&Pe.apply(n)},Dt=(e,t,n)=>{n(e.join?An(e,t):t),e.probes&&e.probes.size&&Fn(e,t)},Lt=(e,t,n)=>{const r=wt.get(e);if(wt.set(e,{cur:t,t:n}),!r)return 0;const i=(n-r.t)/1e3;return i<=0?0:(t-r.cur)/i},Dn=()=>{if(!Ee)return 0;let e=0;for(const t of d)t.pos>=Ve&&(e+=1);return e},Ln=(e,t)=>{const n=ut.get(e);if(n)for(const r of n)try{r(t)}catch{}},In=()=>{Ue||qt<=0||(Ue=setInterval(()=>Ln("metrics",Pe.metrics()),qt),Ue&&typeof Ue.unref=="function"&&Ue.unref())},nn=()=>{Ue&&(clearInterval(Ue),Ue=null)},Cn=e=>{const t=e.indexedDB||(typeof indexedDB<"u"?indexedDB:null);if(!t)return null;const n=typeof e.dbName=="string"?e.dbName:"lattice-router",r=typeof e.storeName=="string"?e.storeName:"snapshots";let i=null;const u=()=>i||(i=new Promise((p,w)=>{let b;try{b=t.open(n,1)}catch(A){w(A);return}b.onupgradeneeded=()=>{const A=b.result;A.objectStoreNames.contains(r)||A.createObjectStore(r)},b.onsuccess=()=>p(b.result),b.onerror=()=>w(b.error)}),i);return{set(p,w){return u().then(b=>new Promise((A,K)=>{const H=b.transaction(r,"readwrite");H.objectStore(r).put(w,p),H.oncomplete=()=>A(),H.onerror=()=>K(H.error),H.onabort=()=>K(H.error)}))},get(p){return u().then(w=>new Promise((b,A)=>{const H=w.transaction(r,"readonly").objectStore(r).get(p);H.onsuccess=()=>b(H.result),H.onerror=()=>A(H.error)}))},close(){i&&i.then(p=>{try{p.close()}catch{}},()=>{})}}},$n=()=>Ee?[...pt(void 0,l).values()]:nt(),Wn=()=>({v:1,world:$n(),maxSeq:E,checkpoint:Object.fromEntries(m),buffer:Ee?{on:!0,max:ke,window:Ae,domain:l,pos:j,baseSeq:ge,baseT:we,base:[...a.entries()],log:d.map(e=>({pos:e.pos,seq:e.seq,t:e.t,op:e.op,key:e.key,row:e.row}))}:{on:!1}}),Mn=e=>{if(!e||typeof e!="object")return!1;kt=!0;try{Pe.load(Array.isArray(e.world)?e.world:[])}finally{kt=!1}e.checkpoint&&Pe.seenThrough(e.checkpoint),Number.isFinite(e.maxSeq)&&(E===void 0||e.maxSeq>E)&&(E=e.maxSeq);const t=e.buffer;if(t&&t.on){Ee=!0,ke=Number.isFinite(t.max)?t.max:null,Ae=Number.isFinite(t.window)?t.window:null,l=t.domain==="seq"||t.domain==="time"?t.domain:o?"seq":"time",a=new Map(Array.isArray(t.base)?t.base:[]),d.length=0;for(const n of Array.isArray(t.log)?t.log:[])d.push({...n});j=Number.isFinite(t.pos)?t.pos:d.length,ge=t.baseSeq,we=t.baseT,Ve=j}return!0},It=()=>{if(!Fe)return Promise.resolve();const e=Wn(),t=Promise.resolve().then(()=>Fe.set(vt,e)).catch(()=>{});return Xe=t,t.then(()=>{Xe===t&&(Xe=null)})},Ct=()=>{if(!(!lt||!Fe||kt)){if(Et<=0){It();return}Ie||(Ie=setTimeout(()=>{Ie=null,It()},Et),Ie&&typeof Ie.unref=="function"&&Ie.unref())}},Pe={attach(e,t,n={}){const r=typeof t!="function",i=r?p=>L(p)===t:t;r&&xt(t);const u=jt(e,i,n);return r&&(u.hasPartValue=!0,u.partValue=t),Q.push(u),u.writable&&mn(u),this},attachDefault(e,t={}){return O=jt(e,()=>!1,t),O.isDefault=!0,this},subscribe(e,t,n={}){const r=typeof e!="function",i=r?p=>L(p)===e:e;r&&xt(e);const u=jt(t,i,n);return r&&(u.hasPartValue=!0,u.partValue=e),Q.push(u),this},alert(e,t,n,r={}){const u={match:typeof e=="function"?e:p=>L(p)===e,keyOf:T(C(r.rowKey,"alerts"),k),filter:typeof r.filter=="function"?r.filter:null,condition:typeof t=="function"?t:()=>!1,handler:typeof n=="function"?n:()=>{},debounceMs:Number.isFinite(r.debounce)?Number(r.debounce):0,armed:!0,timer:null,pending:null,partition:new Map};return Ge.push(u),Rt(u,nt()),dt(u),this},monitor(e,t,n,r={}){const u={kind:"monitor",match:typeof e=="function"?e:p=>L(p)===e,keyOf:T(C(r.rowKey,"alerts"),k),filter:typeof r.filter=="function"?r.filter:null,evaluate:typeof t=="function"?t:()=>{},handler:typeof n=="function"?n:()=>{},armed:!0,timer:null,pending:null,partition:new Map};return Ge.push(u),Rt(u,nt()),dt(u),()=>{const p=Ge.indexOf(u);p>=0&&Ge.splice(p,1),u.timer&&(clearTimeout(u.timer),u.timer=null),u.partition.clear()}},configure(e={}){const t=n=>({rowKey:n.rowKey,transform:n.transform,filter:n.filter,sort:n.sort,rollup:n.rollup,debounce:n.debounce,where:n.where,writable:n.writable,onWrite:n.onWrite,onConflict:n.onConflict,backpressure:n.backpressure,label:n.label});for(const n of e.routes||[])if(n){if(n.default!==void 0){this.attachDefault(n.default,t(n));continue}if(n.alert!==void 0){this.alert(n.when,n.condition,n.alert,t(n));continue}if(n.subscribe!==void 0){this.subscribe(n.when,n.subscribe,t(n));continue}this.attach(n.grid,n.when,t(n))}for(const n of e.links||[])n&&n.from&&n.to&&this.link(n.from,n.to,n.on!==void 0?n.on:n.relation);return e.relate&&this.relate(e.relate),e.buffer&&this.buffer(e.buffer),this},link(e,t,n){const r={from:e,to:t,relation:n,predicate:null};ue.push(r),Bt(e),Ye(r);const i=Qe(t);return i&&Ke(i),this},relate(e){for(const t of e||[]){if(!t||!t.from||!t.to)continue;const n=t.on!==void 0?t.on:t.relation!==void 0?t.relation:t.rel;B.push({from:t.from,to:t.to,rel:n}),t.mutual&&B.push({from:t.to,to:t.from,rel:z(n)})}for(const t of tt())Bt(t);_e();for(const t of tt()){const n=Qe(t);n&&Ke(n)}return this},flush(){return Tt(),this},detach(e){const t=new Set;for(let i=ue.length-1;i>=0;i--){const u=ue[i];(u.from===e||u.to===e)&&(u.to!==e&&t.add(u.to),Kt(u.from),ue.splice(i,1))}let n=!1;for(let i=B.length-1;i>=0;i--)(B[i].from===e||B[i].to===e)&&(Kt(B[i].from),B.splice(i,1),n=!0);for(let i=Q.length-1;i>=0;i--)Q[i].grid===e&&Q.splice(i,1);O&&O.grid===e&&(O=null),We.delete(e);const r=_.get(e);if(r&&(r(),_.delete(e)),n){_e();for(const i of tt())t.add(i)}for(const i of t){const u=Qe(i);u&&Ke(u)}return this},load(e){Se=0;const t=new Map(be().map(r=>[r,[]]));for(const r of e||[]){const i=at(r);if(!i.length){Se+=1,$&&$(r);continue}for(const u of i)t.get(u).push(r)}for(const r of be()){const i=t.get(r);r.partition=new Map(i.map(u=>[String(r.keyOf(u)),u])),r.metricRows+=i.length,bt+=i.length}if(o)for(const r of e||[]){const i=o(r);if(!Number.isFinite(i))continue;const u=String(f(r)),p=m.get(u);(p===void 0||i>p)&&m.set(u,i),(E===void 0||i>E)&&(E=i)}for(const r of ue)Ye(r);_e();for(const r of Ge)Rt(r,e||[]),dt(r);for(const r of be())r.bp&&cn(r);const n=be().map(r=>Ke(r));return Ee&&Gt(),Ve=j,De&&!et&&mt(Qt()),Ct(),n},apply(e){let t=(e||[]).filter(i=>i&&i.row);if(s){t=t.map((u,p)=>[u,p]).sort((u,p)=>{const w=q(u[0]),b=q(p[0]);return w===void 0||b===void 0?u[1]-p[1]:w-b||u[1]-p[1]}).map(u=>u[0]);const i=[];for(const u of t){const p=q(u);if(p!==void 0){const w=String(f(u.row)),b=m.get(w);if(b!==void 0&&p<=b){I+=1;continue}m.set(w,p),(E===void 0||p>E)&&(E=p)}i.push(u)}t=i}if(De&&!et&&t.length&&mt({t:"delta",deltas:t.map(i=>({op:i.op,row:i.row,seq:i.seq}))}),Ee){for(const i of t)vn(i);wn()}for(const i of Ge)bn(i,t),dt(i);if(ae){Ct();return}const n=new Map(be().map(i=>[i,new Map]));for(const i of t){const u=i&&i.row;if(!u)continue;if(i.op==="delete"){let w=!1;for(const b of be()){const A=String(b.keyOf(u));(b.partition.has(A)||n.get(b).has(A))&&(n.get(b).set(A,{op:"del"}),w=!0)}!w&&!at(u).length&&(Se+=1,$&&$(i));continue}const p=at(u);if(!p.length){Se+=1,$&&$(i);continue}for(const w of be()){if(p.includes(w))continue;const b=String(w.keyOf(u));(w.partition.has(b)||n.get(w).get(b)?.op==="set")&&n.get(w).set(b,{op:"del"})}for(const w of p)n.get(w).set(String(w.keyOf(u)),{op:"set",row:u})}const r=new Map;for(const i of be()){let u=0;const p=n.get(i).size;for(const[w,b]of n.get(i)){if(b.op==="del"){i.partition.delete(w);continue}i.partition.set(w,b.row),u+=1}i.metricRows+=u,bt+=u,r.set(i,p)}for(const i of ue)Ye(i);_e();for(const i of be())an(i,r.get(i)||0);Ve=j,Ct()},push(e){const t=Array.isArray(e)?e:[e];if(!y)return this.apply(t),this;for(const n of t)S.push(n);return g!==null&&(g<=0?this.flushStream():W||(W=setTimeout(()=>this.flushStream(),g))),this},flushStream(){if(W&&(clearTimeout(W),W=null),!S.length)return this;const e=S.splice(0,S.length);return this.apply(e),this},flushBackpressure(){for(const e of be())e.bp&&(e.bpTimer||e.bpPending>0)&&ct(e);return this},addSource(e,t){let n,r;e&&typeof e=="object"?(r=e,n=r.id!=null?String(r.id):`source${++Ze}`):(n=e!=null?String(e):`source${++Ze}`,r=t||{});const i=Te.get(n);if(i)return P("data-router:duplicate-source",`addSource("${n}") was already registered; returning the existing source handle. Use a distinct id per feed.`),i.handle;const u={id:n,map:typeof r.map=="function"?r.map:null,ns:jn(n,r.key),live:new Map,ingested:0};u.handle=Rn(u),u.join=Pn(r.join,u),Te.set(n,u),u.join&&Te.has(u.join.from)&&tn(Te.get(u.join.from),u.join);for(const p of Te.values())p!==u&&p.join&&p.join.from===n&&p.join.probe==null&&tn(u,p.join);return u.handle},removeSource(e){const t=e&&typeof e=="object"&&e.id!==void 0?String(e.id):String(e),n=Te.get(t);return n&&n.handle.remove(),this},sources(){return[...Te.keys()]},metrics(){const e=Ne(),t=be().map((r,i)=>({index:i,label:r.label||(r.isDefault?"default":null),kind:typeof r.grid=="function"?"view":"grid",rows:r.partition.size,shown:r.keys.size,routed:r.metricRows,throughput:Lt(`route:${i}`,r.metricRows,e),backpressure:r.bp?{pending:r.bpPending,coalesced:r.bpCoalesced}:null})),n=[...Te.values()].map(r=>({id:r.id,rows:r.live.size,ingested:r.ingested,throughput:Lt(`source:${r.id}`,r.ingested,e)}));return{routes:t,sources:n,unrouted:Se,dropped:I,buffered:d.length,lag:Dn(),throughput:Lt("total",bt,e)}},on(e,t){if(typeof t!="function")return()=>{};let n=ut.get(e);return n||(n=new Set,ut.set(e,n)),n.add(t),e==="metrics"&&In(),()=>{n.delete(t),e==="metrics"&&n.size===0&&nn()}},mountDevtools(e,t={}){return ne(this,e,t)},get unrouted(){return Se},get dropped(){return I},lastSeq(){return E},checkpoint(){return new Map(m)},seenThrough(e){const t=e instanceof Map?e.entries():Object.entries(e||{});for(const[n,r]of t){const i=Number(r);if(!Number.isFinite(i))continue;const u=m.get(String(n));(u===void 0||i>u)&&m.set(String(n),i),(E===void 0||i>E)&&(E=i)}return this},persist(e={}){if(lt=!0,typeof e.key=="string"&&(vt=e.key),Number.isFinite(e.debounce)&&(Et=Number(e.debounce)),e.storage&&typeof e.storage.get=="function"&&typeof e.storage.set=="function")Fe=e.storage;else{let t=null;try{t=Cn(e)}catch{t=null}t?Fe=t:(Fe=null,P("data-router:no-indexeddb","router.persist() found no usable IndexedDB (a non-browser runtime, private mode, or blocked storage); the router runs in-memory with no durable resume. Pass { storage } to use another backend."))}return this},async restore(){if(!Fe)return!1;let e;try{e=await Fe.get(vt)}catch{return!1}return e==null?!1:Mn(e)},async flushPersist(){return Ie&&(clearTimeout(Ie),Ie=null),await It(),Xe&&await Xe,this},get persisting(){return lt&&!!Fe},buffer(e={}){return Ee=!0,Number.isFinite(e.max)?ke=Number(e.max):"max"in e&&e.max==null&&(ke=null),Number.isFinite(e.window)?Ae=Number(e.window):"window"in e&&e.window==null&&(Ae=null),ke==null&&Ae==null&&(ke=le,P("data-router:buffer-default-cap",`buffer() called with no window or max; applying a default cap of ${le} deltas so the buffer stays bounded. Pass { window } or { max } to size it.`)),l=o?"seq":"time",Gt(),this},scrubTo(e,t={}){if(!Nt("scrubTo"))return this;gt(),ae=!0;const n=t.by||l;me=pt(e,n),ht([...me.values()]),Ve=0;for(const r of d){const i=Pt(r,n);if(e!==void 0&&i!==void 0&&i>e)break;Ve=r.pos+1}return this},replay(e,t,n={}){if(!Nt("replay"))return Promise.resolve();gt(),ae=!0;const r=n.by||l;return it=r,ot=Number.isFinite(n.speed)?Number(n.speed):0,me=pt(e,r),ht([...me.values()]),Ce=d.filter(i=>{const u=Pt(i,r);return u!==void 0&&u>e&&u<=t}).slice().sort((i,u)=>i.pos-u.pos),Je=0,ze=!1,new Promise(i=>{He=i,At()})},pause(){return ze=!0,$e&&(clearTimeout($e),$e=null),this},resume(){return ze?(ze=!1,At(),this):this},live(){return Nt("live")?(gt(),ae=!1,me=null,ht([...pt(void 0,l).values()]),Ve=j,this):this},get traveling(){return ae},get buffered(){return d.length},broadcast(e={}){if(typeof BroadcastChannel!="function")return P("data-router:no-broadcastchannel","router.broadcast() needs the BroadcastChannel API, which this runtime does not provide; cross-tab mirroring is off."),this;const t=e&&typeof e.channel=="string"?e.channel:"";return t?(De&&(De.close(),De=null),De=new BroadcastChannel(t),De.onmessage=Sn,mt({t:"hello"}),this):(P("data-router:broadcast-channel","router.broadcast({ channel }) needs a string channel name; nothing was mirrored."),this)},get broadcasting(){return!!De},async query(e,t={}){if(!e||typeof e.execute!="function")return P("data-router:bad-query-source","router.query(adapter) needs an adapter with an execute(query) function (a DFQL/DuckDB adapter or a pushdown source); nothing was fetched."),this;const n=re(e.capabilities),r=t||{},i=r.filters||null,u=[];Se=0;const p=be().filter(b=>b.where),w=be().filter(b=>!b.where);for(const b of p){const A=U(i,b.where),K=X({...r,filters:A},n);let Oe=((await e.execute(K.pushed,r)).rows||[]).slice();K.residual&&K.residual.filters&&(Oe=Oe.filter(rt=>ee(K.residual.filters,rt))),Oe=Oe.filter(rt=>b.match(rt)),On(b,Oe),u.push({route:b.grid,pushedFilter:!!(K.pushed&&K.pushed.filters),residual:K.unpushed.slice()})}if(w.length){const b=X(r,n);let K=((await e.execute(b.pushed,r)).rows||[]).slice();b.residual&&b.residual.filters&&(K=K.filter(H=>ee(b.residual.filters,H))),Tn(K,w),u.push({base:!0,pushedFilter:!!(b.pushed&&b.pushed.filters),residual:b.unpushed.slice()})}St=u;for(const b of ue)Ye(b);_e();for(const b of be())Ke(b);return this},lastQueryPlan(){return St?St.map(e=>({...e})):null},destroy(){if(Le&&(clearTimeout(Le),Le=null),W&&(clearTimeout(W),W=null),Ie&&(clearTimeout(Ie),Ie=null),Fe&&typeof Fe.close=="function")try{Fe.close()}catch{}lt=!1,Fe=null,De&&(De.close(),De=null),et=!1,gt(),Ee=!1,ae=!1,me=null,d.length=0,a.clear();for(const e of ye.values())e.off();ye.clear();for(const e of _.values())e();_.clear(),fe.clear(),Te.clear(),nn(),ut.clear(),wt.clear();for(const e of Ge)e.timer&&(clearTimeout(e.timer),e.timer=null);Ge.length=0;for(const e of be())e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null);ue.length=0,B.length=0,We.clear(),S.length=0,m.clear(),Q.length=0,O=null}};return c.config&&Pe.configure(c.config),Pe}function je(c,L){if(c===L)return!0;if(!c||!L)return!1;const k=Object.keys(c),R=Object.keys(L);if(k.length!==R.length)return!1;for(const $ of k)if(c[$]!==L[$])return!1;return!0}const Me=pe});var yt=Mt("packages/modules/data-router/index.js");typeof module=="object"&&module.exports?module.exports=yt:typeof define=="function"&&define.amd?define(function(){return yt}):rn.LatticeGridDataRouter=yt})(typeof globalThis<"u"?globalThis:this);
6
+ (function(rn){"use strict";var $t=Object.create(null),Wt=Object.create(null);function xe(h,he){$t[h]=he}function Mt(h){var he=Wt[h];if(he)return he;var te=Object.create(null);Wt[h]=te;var P=$t[h];if(!P)throw new Error("[lattice] missing module: "+h);return P(te,Mt),te}xe("packages/core/src/internal/util.js",function(h,he){"use strict";Object.defineProperty(h,"VERSION",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(h,"reportedWarnings",{enumerable:!0,get:function(){return N}}),Object.defineProperty(h,"warnOnce",{enumerable:!0,get:function(){return C}}),Object.defineProperty(h,"infoOnce",{enumerable:!0,get:function(){return M}}),Object.defineProperty(h,"resetWarnings",{enumerable:!0,get:function(){return D}}),Object.defineProperty(h,"fail",{enumerable:!0,get:function(){return G}}),Object.defineProperty(h,"invariant",{enumerable:!0,get:function(){return v}}),Object.defineProperty(h,"DEV",{enumerable:!0,get:function(){return V}}),Object.defineProperty(h,"isObject",{enumerable:!0,get:function(){return x}}),Object.defineProperty(h,"isFunction",{enumerable:!0,get:function(){return z}}),Object.defineProperty(h,"isNil",{enumerable:!0,get:function(){return U}}),Object.defineProperty(h,"isBlank",{enumerable:!0,get:function(){return J}}),Object.defineProperty(h,"isCtor",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(h,"pathGetter",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(h,"pathSetter",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(h,"getPath",{enumerable:!0,get:function(){return c}}),Object.defineProperty(h,"setPath",{enumerable:!0,get:function(){return L}}),Object.defineProperty(h,"humanise",{enumerable:!0,get:function(){return k}}),Object.defineProperty(h,"escapeHtml",{enumerable:!0,get:function(){return $}}),Object.defineProperty(h,"titleCase",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(h,"expand",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(h,"toArray",{enumerable:!0,get:function(){return qe}}),Object.defineProperty(h,"merge",{enumerable:!0,get:function(){return s}}),Object.defineProperty(h,"mergeRow",{enumerable:!0,get:function(){return f}}),Object.defineProperty(h,"Lru",{enumerable:!0,get:function(){return g}}),Object.defineProperty(h,"collator",{enumerable:!0,get:function(){return m}}),Object.defineProperty(h,"defaultCompare",{enumerable:!0,get:function(){return E}}),Object.defineProperty(h,"now",{enumerable:!0,get:function(){return I}}),Object.defineProperty(h,"nextFrame",{enumerable:!0,get:function(){return W}}),Object.defineProperty(h,"cancelFrame",{enumerable:!0,get:function(){return se}}),Object.defineProperty(h,"frameBatched",{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(h,"settleDebounce",{enumerable:!0,get:function(){return le}}),Object.defineProperty(h,"whenIdle",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(h,"uid",{enumerable:!0,get:function(){return Ae}});const te="1.75.0";async function P(){return te}const Z="1.75.0",X=new Set,re=2e3;function de(l){if(X.add(l),X.size>re){const a=X.values().next().value;a!==void 0&&X.delete(a)}}const F=[],Y=500;function ne(l,a,d){F.push({key:l,level:a,message:d.map(j=>typeof j=="string"?j:T(j)).join(" "),at:Date.now()}),F.length>Y&&F.shift()}function T(l){if(l instanceof Error)return l.message;try{return JSON.stringify(l)}catch{return String(l)}}function N(){return F.map(l=>({...l}))}function C(l,...a){X.has(l)||(de(l),ne(l,"warn",a),console.warn("[lattice]",...a))}function M(l,...a){X.has(l)||(de(l),ne(l,"info",a),console.info("[lattice]",...a))}function D(){X.clear(),F.length=0}function G(l,a){const d=new Error(`[lattice] ${l}`);throw a!==void 0&&(d.cause=a),d}function v(l,a){l||G(a)}const V=(()=>{try{return!(typeof process<"u"&&process.env&&process.env.NODE_ENV==="production")}catch{return!0}})();function x(l){return l!==null&&typeof l=="object"&&!Array.isArray(l)}function z(l){return typeof l=="function"}function U(l){return l==null}function J(l){return l==null||l===""}function oe(l){return typeof l!="function"?!1:/^class[\s{]/.test(Function.prototype.toString.call(l))?!0:!!(l.prototype&&Object.getOwnPropertyNames(l.prototype).length>1)}const ee=new Map;function pe(l){let a=ee.get(l);if(a)return a;if(!l.includes("."))a=d=>d?.[l];else{const d=l.split("."),j=d.length;a=ge=>{let we=ge;for(let ae=0;ae<j;ae++){if(we==null)return;we=we[d[ae]]}return we}}return ee.set(l,a),a}const je=new Map;function Me(l){let a=je.get(l);if(a)return a;if(!l.includes("."))a=(d,j)=>{d!=null&&(d[l]=j)};else{const d=l.split("."),j=d.length-1;a=(ge,we)=>{let ae=ge;for(let me=0;me<j;me++){if(ae==null)return;const Ce=d[me];ae[Ce]==null&&(ae[Ce]={}),ae=ae[Ce]}ae!=null&&(ae[d[j]]=we)}}return je.set(l,a),a}function c(l,a){return pe(a)(l)}function L(l,a,d){Me(a)(l,d)}function k(l){return l?(l.includes(".")?l.slice(l.lastIndexOf(".")+1):l).replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replace(/\s+/g," ").trim().replace(/^./,d=>d.toUpperCase()):""}const R={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function $(l){const a=l==null?"":String(l);return/[&<>"']/.test(a)?a.replace(/[&<>"']/g,d=>R[d]):a}function ie(l){return String(l).replace(/\w\S*/g,a=>a[0].toUpperCase()+a.slice(1).toLowerCase())}function ve(l,a,d){if(l!==void 0)return l===!0?{enabled:!0,...d}:l===!1?{enabled:!1}:x(l)?l:{[a]:l,enabled:!0}}function qe(l){return l==null?[]:Array.isArray(l)?l:[l]}const o=Object.freeze(new Set(["__proto__","constructor","prototype"]));function s(l,a){if(!x(l))return x(a)?{...a}:a;if(!x(a))return a===void 0?l:a;const d={...l};for(const j of Object.keys(a)){if(o.has(j))continue;const ge=a[j];ge!==void 0&&(d[j]=x(ge)&&x(d[j])?s(d[j],ge):ge)}return d}function f(l,a){if(!x(l)||!x(a)||l===a)return a;const d=Object.create(Object.getPrototypeOf(l));return Object.assign(d,l,a),d}class g{#e;#t=new Map;#n;constructor(a=256,d=null){this.#e=a,this.#n=d}get size(){return this.#t.size}get max(){return this.#e}set max(a){this.#e=a,this.#r()}has(a){return this.#t.has(a)}get(a){const d=this.#t;if(!d.has(a))return;const j=d.get(a);return d.delete(a),d.set(a,j),j}peek(a){return this.#t.get(a)}set(a,d){const j=this.#t;return j.has(a)&&j.delete(a),j.set(a,d),this.#r(),d}delete(a){const d=this.#t.get(a);return this.#t.delete(a)&&this.#n&&this.#n(d,a),d}clear(){if(this.#n)for(const[a,d]of this.#t)this.#n(d,a);this.#t.clear()}keys(){return this.#t.keys()}values(){return this.#t.values()}#r(){const a=this.#t;for(;a.size>this.#e;){const d=a.keys().next().value,j=a.get(d);a.delete(d),this.#n&&this.#n(j,d)}}}const y=new Map;function m(l,a){const d=`${l||""}|${a?JSON.stringify(a):""}`;let j=y.get(d);return j||(j=new Intl.Collator(l||void 0,{numeric:!0,sensitivity:"variant",...a}),y.set(d,j)),j}function E(l,a){if(l===a)return 0;if(l==null)return 1;if(a==null)return-1;if(typeof l=="number"&&typeof a=="number")return Number.isNaN(l)?Number.isNaN(a)?0:1:Number.isNaN(a)||l<a?-1:l>a?1:0;const d=String(l),j=String(a);return d<j?-1:d>j?1:0}function I(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const S=typeof requestAnimationFrame=="function";function W(l){return S?requestAnimationFrame(l):setTimeout(()=>l(I()),16)}function se(l){l!=null&&(S?cancelAnimationFrame(l):clearTimeout(l))}function Ne(l){let a=null,d=null;const j=()=>{a=null;const we=d;d=null,l(...we||[])},ge=(...we)=>{d=we,a===null&&(a=W(j))};return ge.cancel=()=>{se(a),a=null,d=null},ge.flush=()=>{a!==null&&(se(a),j())},ge}function le(l,a){let d=null,j=null;const ge=()=>{if(d=null,j===null)return;const me=j;j=null,l(...me),we()},we=()=>{d=setTimeout(ge,a),typeof d?.unref=="function"&&d.unref()},ae=(...me)=>{d===null?(l(...me),we()):(j=me,clearTimeout(d),we())};return ae.flush=()=>{if(d!==null&&clearTimeout(d),d=null,j===null)return;const me=j;j=null,l(...me)},ae.cancel=()=>{d!==null&&clearTimeout(d),d=null,j=null},ae.pending=()=>d!==null||j!==null,ae}function Ee(l,a=50){return typeof requestIdleCallback=="function"?requestIdleCallback(l,{timeout:a}):setTimeout(()=>l({timeRemaining:()=>0,didTimeout:!0}),1)}let ke=0;function Ae(l="l"){return`${l}${(++ke).toString(36)}`}}),xe("packages/core/src/source/filterwire.js",function(h,he){"use strict";Object.defineProperty(h,"HOST_FILTER_WARN_ID",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(h,"WHERE_PAGE_RELATIVE_WARN_ID",{enumerable:!0,get:function(){return X}}),Object.defineProperty(h,"warnWherePageRelative",{enumerable:!0,get:function(){return re}}),Object.defineProperty(h,"warnHostFilterNotApplied",{enumerable:!0,get:function(){return de}}),Object.defineProperty(h,"WHERE_NOT_APPLIED_WARN_ID",{enumerable:!0,get:function(){return F}}),Object.defineProperty(h,"warnWhereNotApplied",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(h,"WHERE_OVER_THRESHOLD_WARN_ID",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(h,"warnWhereOverThreshold",{enumerable:!0,get:function(){return T}}),Object.defineProperty(h,"RELATIVE_TOKENS",{enumerable:!0,get:function(){return x}}),Object.defineProperty(h,"parseRelativeToken",{enumerable:!0,get:function(){return z}}),Object.defineProperty(h,"resolveRelativeRange",{enumerable:!0,get:function(){return U}}),Object.defineProperty(h,"relativeTokenOf",{enumerable:!0,get:function(){return J}}),Object.defineProperty(h,"relativeTokenHelp",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(h,"isResolvableRelative",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(h,"resolveRelativeCondition",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(h,"isGroup",{enumerable:!0,get:function(){return je}}),Object.defineProperty(h,"forEachCondition",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(h,"mapConditions",{enumerable:!0,get:function(){return c}}),Object.defineProperty(h,"normaliseFilterSet",{enumerable:!0,get:function(){return k}}),Object.defineProperty(h,"buildFilterSet",{enumerable:!0,get:function(){return R}}),Object.defineProperty(h,"wireFilters",{enumerable:!0,get:function(){return $}}),Object.defineProperty(h,"querySignature",{enumerable:!0,get:function(){return ie}});const P=he("packages/core/src/internal/util.js").warnOnce,Z="source.remote.hostFilter",X="source.where.pageRelative";function re(o,s){!Array.isArray(o)||!o.length||P(X,`filters.where (${o.join(", ")}) runs over the rows the ${s} source fetched,`,"not the whole dataset: match counts and totals are page-relative.","Give the predicate a { condition } twin so the engine can narrow the fetch itself.")}function de(o){const s=(o||{}).config;!s||!s.hostFilter||P(Z,"config.hostFilter is not sent to a server-delegated source (paged/remote) and is not applied:","filtering only the fetched window would give wrong counts and totals.","Express the filter as a FilterSet condition, or send it through config.context.")}const F="source.where.notApplied";function Y(o,s){P(`${F}:${o}`,`filters.where("${o}") is registered but the ${s} source holds only its fetched window`,"and cannot run the predicate over it: the predicate is not applied there, and rows it would","exclude stay on screen.","Give it a { condition } twin so the engine can narrow the fetch itself — that is the","supported route for a paged or remote source.")}const ne="source.where.overThreshold";function T(o,s,f,g){!Array.isArray(o)||!o.length||P(`${ne}:${s}`,`filters.where (${o.join(", ")}) is not applied to the ${s} pushdown source:`,f===null?"the adapter reports no row total, so the size of the matching set is unknown.":`its matching set is ${f.toLocaleString()} rows, at or past the whereRowLimit of ${g.toLocaleString()}.`,"Running the predicate needs every matching row fetched and held here, which is the whole","download a pushdown source exists to avoid, so it is refused and the rows the predicate","would exclude stay on screen.","Give the predicate a { condition } twin so the engine narrows the fetch itself — that is the","route that works at any size — or raise `whereRowLimit` on the source config if you want the","download.")}const N=new Map;function C(o){let s=N.get(o);return s||(s=new Intl.DateTimeFormat("en-US",{timeZone:o,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),N.set(o,s)),s}function M(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function D(o,s){const f=C(s).formatToParts(new Date(o)),g={y:1970,m:1,d:1,h:0,mi:0,s:0};for(const y of f)y.type==="year"?g.y=+y.value:y.type==="month"?g.m=+y.value:y.type==="day"?g.d=+y.value:y.type==="hour"?g.h=+y.value%24:y.type==="minute"?g.mi=+y.value:y.type==="second"&&(g.s=+y.value);return g}function G(o,s){const f=D(o,s);return Date.UTC(f.y,f.m-1,f.d,f.h,f.mi,f.s)-Math.floor(o/1e3)*1e3}function v(o,s,f,g){const y=Date.UTC(o,s-1,f),m=y-G(y,g);return y-G(m,g)}function V(o,s,f){const g=new Date(Date.UTC(o.y,o.m-1,o.d+s));return v(g.getUTCFullYear(),g.getUTCMonth()+1,g.getUTCDate(),f)}const x=Object.freeze(["today","yesterday","lastNDays","thisWeek","thisMonth","thisQuarter","thisYear","quarterToDate","yearToDate"]);function z(o,s){if(typeof o!="string")return null;const f=o.trim().toLowerCase().replace(/[\s_-]+/g,""),g=/^last(\d*|n)days?$/.exec(f);if(g){const y=g[1]==="n"?"":g[1],m=Number(y||s);return!Number.isFinite(m)||m<=0?null:{kind:"lastNDays",n:Math.floor(m)}}switch(f){case"today":return{kind:"today",n:0};case"yesterday":return{kind:"yesterday",n:0};case"thisweek":return{kind:"thisWeek",n:0};case"thismonth":return{kind:"thisMonth",n:0};case"thisquarter":return{kind:"thisQuarter",n:0};case"thisyear":return{kind:"thisYear",n:0};case"quartertodate":case"qtd":return{kind:"quarterToDate",n:0};case"yeartodate":case"ytd":return{kind:"yearToDate",n:0};default:return null}}function U(o,s={}){const f=z(o,s.n);if(!f)return null;const g=s.tz||M(),y=s.now instanceof Date?s.now.getTime():typeof s.now=="number"?s.now:Date.now(),m=D(y,g),E=v(m.y,m.m,m.d,g),I=V(m,1,g);let S=E,W=I;switch(f.kind){case"today":break;case"yesterday":S=V(m,-1,g),W=E;break;case"lastNDays":W=s.includeToday?I:E,S=V(m,s.includeToday?-(f.n-1):-f.n,g);break;case"thisWeek":{const se=Number.isFinite(s.weekStartsOn)?Number(s.weekStartsOn):1,le=(new Date(Date.UTC(m.y,m.m-1,m.d)).getUTCDay()-se+7)%7;S=V(m,-le,g),W=V(m,-le+7,g);break}case"thisMonth":S=v(m.y,m.m,1,g),W=v(m.m===12?m.y+1:m.y,m.m===12?1:m.m+1,1,g);break;case"thisQuarter":case"quarterToDate":{const se=Math.floor((m.m-1)/3)*3+1;S=v(m.y,se,1,g),W=f.kind==="quarterToDate"?I:se===10?v(m.y+1,1,1,g):v(m.y,se+3,1,g);break}case"thisYear":case"yearToDate":S=v(m.y,1,1,g),W=f.kind==="yearToDate"?I:v(m.y+1,1,1,g);break;default:return null}return{from:new Date(S).toISOString(),to:new Date(W).toISOString(),bounds:"[)",tz:g,relative:f.kind==="lastNDays"?`last${f.n}Days`:f.kind,n:f.n}}function J(o){if(!o||typeof o!="object")return null;const s=o.value;if(s&&typeof s=="object"&&!Array.isArray(s)&&"relative"in s)return{token:String(s.relative),n:typeof s.n=="number"?s.n:void 0};if(o.op==="relative"&&typeof o.value=="string")return{token:o.value,n:void 0};const f=o.meta;return f&&typeof f.relative=="string"&&o.value===void 0?{token:f.relative,n:typeof f.n=="number"?f.n:void 0}:null}function oe(){return`Known tokens: ${x.filter(s=>s!=="lastNDays").join(", ")}. "lastNDays" needs a count: pass "last7Days", or the value object { relative: 'lastNDays', n: 7 }.`}function ee(o){const s=J(o);return s?z(s.token,s.n)!==null:!1}function pe(o,s={}){const f=J(o);if(!f)return o;const g=U(f.token,{...s,n:f.n});return g?{...o,type:o.type||"date",op:"between",value:[g.from,g.to],bounds:o.bounds||g.bounds,meta:{...o.meta||{},relative:g.relative,tz:g.tz}}:(P(`source.relative.${f.token}`,`unknown relative date token "${f.token}"; sending the condition unresolved.`,oe()),o)}function je(o){return!!o&&typeof o=="object"&&Array.isArray(o.conditions)}function Me(o,s){if(o){if(je(o)){for(const f of o.conditions)Me(f,s);return}s(o)}}function c(o,s){if(!o)return null;if(!je(o))return s(o);const f=o;let g=!1;const y=[];for(const m of f.conditions){const E=c(m,s);E!==m&&(g=!0),E&&y.push(E)}return!g&&y.length===f.conditions.length?o:y.length?{...f,conditions:y}:null}function L(o){if(!o)return null;if(!je(o))return o;const s=o,f=[];for(const g of s.conditions){const y=L(g);y&&f.push(y)}return f.length?{op:s.op,conditions:f}:null}function k(o){const s=L(o);return s?je(s)&&s.op==="and"?s:{op:"and",conditions:[s]}:null}function R(o){const s=(o||[]).filter(Boolean);return s.length?{op:"and",conditions:s}:null}function $(o,s={}){const f=c(o,g=>pe(g,s));return k(f)}function ie(o){const s=ve(o.filters??null);return JSON.stringify([s,o.sort??null,o.quick??"",o.groupBy??null,o.pivotBy??null,qe(o.context)])}function ve(o){if(!o)return null;if(je(o)){const g=o;return{op:g.op,conditions:g.conditions.map(ve)}}const s=o,f=s.meta&&typeof s.meta.relative=="string"?s.meta.relative:J(s)?.token;return{col:s.col,op:s.op,bounds:s.bounds??null,caseSensitive:s.caseSensitive??!1,value:f?`rel:${f}`:s.value??null}}function qe(o){if(o==null)return null;try{return JSON.parse(JSON.stringify(o))}catch{return P("source.context.unserialisable","config.context is not JSON-serialisable; cache keys ignore it."),"[unserialisable]"}}}),xe("packages/core/src/source/aggregates.js",function(h,he){"use strict";Object.defineProperty(h,"STAT_PUSHDOWN",{enumerable:!0,get:function(){return te}}),Object.defineProperty(h,"pushableAggregates",{enumerable:!0,get:function(){return P}}),Object.defineProperty(h,"fillAggregateSql",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(h,"resolveAggregatesConfig",{enumerable:!0,get:function(){return X}}),Object.defineProperty(h,"routeAggregate",{enumerable:!0,get:function(){return re}}),Object.defineProperty(h,"resolveAggregatePlan",{enumerable:!0,get:function(){return de}}),Object.defineProperty(h,"groupKeysPushable",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(h,"pushdownDocRows",{enumerable:!0,get:function(){return ne}});const te=Object.freeze({sum:{pushable:!0,class:"identical",sql:"sum(%c)"},avg:{pushable:!0,class:"identical",sql:"avg(%c)"},min:{pushable:!0,class:"identical",sql:"min(%c)"},max:{pushable:!0,class:"identical",sql:"max(%c)"},count:{pushable:!0,class:"identical",sql:"count(*)"},countValues:{pushable:!0,class:"identical",sql:"count(%c)",blankAware:!0},range:{pushable:!0,class:"identical",sql:"(max(%c) - min(%c))"},variance:{pushable:!0,class:"identical",sql:"var_samp(%c)"},varianceP:{pushable:!0,class:"identical",sql:"var_pop(%c)"},stddev:{pushable:!0,class:"identical",sql:"stddev_samp(%c)"},stddevP:{pushable:!0,class:"identical",sql:"stddev_pop(%c)"},sumSquares:{pushable:!0,class:"identical",sql:"sum(%c * %c)"},median:{pushable:!0,class:"identical",sql:"median(%c)"},p25:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.25)"},p75:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.75)"},p90:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.9)"},p95:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.95)"},p99:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.99)"},iqr:{pushable:!0,class:"identical",sql:"(quantile_cont(%c, 0.75) - quantile_cont(%c, 0.25))"},mad:{pushable:!0,class:"identical",sql:"mad(%c)"},distinct:{pushable:!0,class:"identical",sql:"count(DISTINCT %c)",blankAware:!0},skewness:{pushable:!0,class:"identical",sql:"skewness(%c)"},kurtosis:{pushable:!0,class:"identical",sql:"kurtosis(%c)"},geomean:{pushable:!0,class:"identical",sql:"exp(avg(ln(%c)))"},harmean:{pushable:!0,class:"identical",sql:"(count(%c) / sum(1.0 / %c))"},entropy:{pushable:!0,class:"identical",sql:"entropy(%c)",blankAware:!0},correlation:{pushable:!0,class:"identical",sql:"corr(%w, %c)",twoColumn:!0},hhi:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_transform(map_values(histogram(%c)), lambda v: (v::DOUBLE/count(%c))*(v::DOUBLE/count(%c)))) END"},evenness:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL WHEN count(DISTINCT %c)<2 THEN 1.0 ELSE entropy(%c)/log2(count(DISTINCT %c)) END"},top3Share:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_slice(list_sort(map_values(histogram(%c)),'DESC'),1,3))::DOUBLE/count(%c) END"},top10Share:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_slice(list_sort(map_values(histogram(%c)),'DESC'),1,10))::DOUBLE/count(%c) END"},gini:{pushable:!0,class:"identical",sql:"CASE WHEN list_min(list(%c) FILTER (WHERE isfinite(%c)))<0 THEN NULL WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL WHEN list_sum(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN 0 ELSE 2.0*list_sum(list_transform(list_sort(list(%c) FILTER (WHERE isfinite(%c))), lambda v, i: i*v))/(len(list(%c) FILTER (WHERE isfinite(%c)))*list_sum(list(%c) FILTER (WHERE isfinite(%c))))-(len(list(%c) FILTER (WHERE isfinite(%c)))+1.0)/len(list(%c) FILTER (WHERE isfinite(%c))) END"},trimmedMean:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL ELSE list_avg(list_slice(list_sort(list(%c) FILTER (WHERE isfinite(%c))), floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT+1, len(list(%c) FILTER (WHERE isfinite(%c)))-floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT)) END"},winsorizedMean:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL ELSE list_avg(list_transform(list_sort(list(%c) FILTER (WHERE isfinite(%c))), lambda v: least(list_sort(list(%c) FILTER (WHERE isfinite(%c)))[len(list(%c) FILTER (WHERE isfinite(%c)))-floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT], greatest(list_sort(list(%c) FILTER (WHERE isfinite(%c)))[floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT+1], v)))) END"},robustOutliers:{pushable:!0,class:"identical",sql:"(SELECT CASE WHEN len(d.a)=0 THEN NULL WHEN d.mad=0 THEN NULL ELSE len(list_filter(d.a, lambda v: abs(0.6745*(v-d.med)/d.mad)>3.5)) END FROM (SELECT xs AS a, list_median(xs) AS med, list_median(list_transform(xs, lambda w: abs(w-list_median(xs)))) AS mad FROM (SELECT list(%c) FILTER (WHERE isfinite(%c)) AS xs)) d)"},jarqueBera:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))<8 THEN NULL WHEN list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2)))=0 THEN NULL ELSE (len(list(%c) FILTER (WHERE isfinite(%c)))/6.0)*(power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),3)))/power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2))),1.5),2)+power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),4)))/power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2))),2)-3,2)/4.0) END"},weightedAvg:{pushable:!0,class:"identical",twoColumn:!0,sql:"sum(%c*%w) FILTER (WHERE isfinite(%c) AND isfinite(%w))/nullif(sum(%w) FILTER (WHERE isfinite(%c) AND isfinite(%w)),0)"},mode:{pushable:!0,class:"may-differ",sql:"mode(%c)",note:"DuckDB returns a modal value even for an all-distinct column; the grid returns null. Tie-breaking can also differ, and on a text column an empty string counts as a value. Under pushdown you will see a value."},weightedQuantile:{pushable:!1,class:"fallback",note:"No SQL equivalent for the grid's weighted-quantile midpoint convention; always computed client-side (needs a full-dataset pull for a correct figure over a remote source)."}});function P(){const T=new Set;for(const[N,C]of Object.entries(te))C.pushable&&T.add(N);return T}function Z(T,N,C){let M=T.split("%c").join(N);return C!==void 0&&(M=M.split("%w").join(C)),M}function X(T){const N=T||{},C=N.default==="engine"||N.default==="engine-if-identical"?N.default:"client",M={};if(N.overrides&&typeof N.overrides=="object")for(const[D,G]of Object.entries(N.overrides))(G==="engine"||G==="client")&&(M[D]=G);return{default:C,overrides:M}}function re(T,N){const C=te[T];if(!C||!C.pushable)return"client";const M=N.overrides[T];return M==="engine"||M==="client"?M:N.default==="client"?"client":N.default==="engine-if-identical"?C.class==="identical"?"engine":"client":"engine"}function de(T,N){const C=X(N),M=[],D=[];for(const G of T||[]){const v=te[G.fn],V=re(G.fn,C),x={id:G.id,col:G.col,fn:G.fn,class:v?v.class:"fallback"};G.weight!==void 0&&(x.weight=G.weight),G.params!==void 0&&(x.params=G.params),V==="engine"?M.push(x):(x.reason=v&&!v.pushable?v.note||"the engine cannot express this stat":"client by config",D.push(x))}return{engine:M,client:D,config:C}}const F=/^[A-Za-z_][A-Za-z0-9_$]*$/;function Y(T,N=[]){return(T||[]).every(M=>{if(typeof M=="string")return F.test(M);if(!M||typeof M!="object")return!1;const D=M;return Array.isArray(N)&&N.includes(D.bucket)&&typeof D.col=="string"&&F.test(D.col)&&typeof D.size=="number"&&Number.isFinite(D.size)&&D.size>0})}function ne(){return Object.entries(te).map(([T,N])=>({stat:T,class:N.class,sql:N.sql?Z(N.sql,"col",N.twoColumn?"weight":void 0):"",note:N.note||(N.class==="identical"?"Pushes to DuckDB with the same result.":"")}))}}),xe("packages/core/src/source/abort.js",function(h,he){"use strict";Object.defineProperty(h,"SupersededError",{enumerable:!0,get:function(){return te}}),Object.defineProperty(h,"RequestToken",{enumerable:!0,get:function(){return P}}),Object.defineProperty(h,"AbortScope",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(h,"createAbortScope",{enumerable:!0,get:function(){return X}}),Object.defineProperty(h,"isAbortError",{enumerable:!0,get:function(){return re}});class te extends Error{constructor(F,Y="superseded"){super(`[lattice] request ${F?`"${F}" `:""}${Y}`),this.name="SupersededError",this.superseded=!0,this.key=F}}class P{#e;constructor(F,Y,ne,T){this.#e=F,this.key=Y,this.controller=ne,this.signal=ne.signal,this.seq=T}get current(){return!this.signal.aborted&&this.#e.tokenFor(this.key)===this}settle(){this.#e.settle(this)}abort(F){this.signal.aborted||this.controller.abort(new te(this.key,F)),this.#e.settle(this)}}class Z{#e=new Map;#t=0;begin(F="",Y="superseded"){const ne=this.#e.get(F);ne&&!ne.signal.aborted&&ne.controller.abort(new te(F,Y));const T=new P(this,F,new AbortController,++this.#t);return this.#e.set(F,T),T}tokenFor(F){return this.#e.get(F)}pending(F=""){const Y=this.#e.get(F);return!!Y&&!Y.signal.aborted}get size(){return this.#e.size}settle(F){this.#e.get(F.key)===F&&this.#e.delete(F.key)}abort(F="",Y="superseded"){const ne=this.#e.get(F);ne&&ne.abort(Y)}abortAll(F="superseded"){for(const Y of[...this.#e.values()])Y.abort(F);this.#e.clear()}}function X(){return new Z}function re(de){if(!de||typeof de!="object")return!1;const F=de;return F.superseded===!0||F.name==="AbortError"||F.name==="SupersededError"}}),xe("packages/core/src/source/pushdown.js",function(h,he){"use strict";Object.defineProperty(h,"NO_CAPABILITIES",{enumerable:!0,get:function(){return G}}),Object.defineProperty(h,"resolveMutate",{enumerable:!0,get:function(){return v}}),Object.defineProperty(h,"capabilitiesOf",{enumerable:!0,get:function(){return z}}),Object.defineProperty(h,"splitFilters",{enumerable:!0,get:function(){return J}}),Object.defineProperty(h,"planQuery",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(h,"applyResidual",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(h,"DEFAULT_WHERE_ROW_LIMIT",{enumerable:!0,get:function(){return R}}),Object.defineProperty(h,"createPushdownSource",{enumerable:!0,get:function(){return qe}});const te=he("packages/core/src/internal/util.js"),P=te.isFunction,Z=te.warnOnce,X=he("packages/core/src/source/filterwire.js"),re=X.isGroup,de=X.warnWherePageRelative,F=X.warnWhereOverThreshold,Y=he("packages/core/src/source/aggregates.js"),ne=Y.resolveAggregatePlan,T=Y.groupKeysPushable,N=Y.STAT_PUSHDOWN,M=he("packages/core/src/source/abort.js").SupersededError;function D(o){const s=o&&o.signal;if(!s||!s.aborted)return;const f=s.reason;throw f instanceof Error?f:new M("","superseded before it was sent")}const G=Object.freeze({filter:!1,operators:Object.freeze([]),sort:!1,quick:!1,range:!1,total:!1,group:!1,mutate:!1});function v(o){if(!o||typeof o!="object")return!1;const s=o.returning==="row"||o.returning==="key"?o.returning:"none";return{append:o.append===!0,update:o.update===!0,delete:o.delete===!0,returning:s}}function V(o,s){if(!o||typeof s!="string")return;if(!s.includes("."))return o[s];let f=o;for(const g of s.split(".")){if(f===null||typeof f!="object")return;f=f[g]}return f}function x(o){if(o===!0)return!0;if(!o||typeof o!="object")return!1;const s=o;return s.enabled===!1?!1:s.enabled===!0||P(s.commit)}function z(o){const s={...G,...o||{}};return s.operators=new Set(s.operators||[]),s.mutate=v(s.mutate),s}function U(o,s){return!o||!o.op||!s.operators.size?!1:s.operators.has(o.op)}function J(o,s){if(!o)return{pushed:null,residual:null};if(!s.filter)return{pushed:null,residual:o};if(s.filter==="term"){if(re(o)){const m=o.conditions||[];if(String(o.op)!=="and")return{pushed:null,residual:o};const E=m.findIndex(S=>!re(S)&&U(S,s));if(E<0)return{pushed:null,residual:o};const I=m.filter((S,W)=>W!==E);return{pushed:m[E],residual:I.length?{op:"and",conditions:I}:null}}return U(o,s)?{pushed:o,residual:null}:{pushed:null,residual:o}}if(!re(o))return U(o,s)?{pushed:o,residual:null}:{pushed:null,residual:o};if(String(o.op)!=="and")return(o.conditions||[]).every(E=>re(E)?J(E,s).residual===null:U(E,s))?{pushed:o,residual:null}:{pushed:null,residual:o};const f=[],g=[];for(const m of o.conditions||[]){if(re(m)){if(s.filter==="flat"){g.push(m);continue}const E=J(m,s);E.pushed&&f.push(E.pushed),E.residual&&g.push(E.residual);continue}(U(m,s)?f:g).push(m)}const y=m=>m.length===0?null:m.length===1?m[0]:{op:"and",conditions:m};return{pushed:y(f),residual:y(g)}}function oe(o,s,f,g,y,m,E){const I=Array.isArray(o.groupBy)?o.groupBy:[],S=Array.isArray(o.groupPath)?o.groupPath:[],W=Array.isArray(o.groupValues)?o.groupValues:null;return s.group?T(I)?f.residual?"the filter did not fully push, so the engine would group a superset of the matching rows":g?y?m?"a host `where` predicate can only run in the browser, over rows the engine grouped":E?"fullDataset holds the whole matching set, so the grid groups it itself":!W||W.length!==S.length?"the request carries no typed `groupValues` for its group path, and the string `groupPath` cannot be compared against a typed column":"":"a quick search did not push, so the engine would group unsearched rows":"the sort did not push, so the engine would order the groups differently":"a grouping key is not a plain column the engine can name in a GROUP BY":"the adapter does not declare the `group` capability"}function ee(o,s,f=!1){const g=J(o.filters||null,s),y=[];g.residual&&y.push("filter");const m=o.sort||[],E=m.length===0||s.sort==="multi"&&m.length>=1||s.sort==="single"&&m.length===1;!E&&m.length&&y.push("sort");const I=o.quick?String(o.quick):"",S=!I||!!s.quick;S||y.push("quick");const W=o.where&&o.where.active?o.where:null;W&&y.push("where");const se={filters:g.residual,sort:E?null:m,quick:S?"":I,where:W},Ne=!!f,le=Array.isArray(o.groupBy)&&o.groupBy.length>0,Ee=le?oe(o,s,g,E,S,W,Ne):"",ke=le&&Ee==="";le&&!ke&&y.push("group");const Ae=ke&&Array.isArray(o.groupValues)?o.groupValues.length:0,l=ke?!1:Ne||!!(se.filters||se.sort||se.quick||se.where)||!s.range;return{pushed:{...o,filters:g.pushed,sort:E?m:[],quick:S?I:"",range:l?null:o.range},residual:se,needsAll:l,unpushed:y,full:Ne,grouped:ke,groupLevel:Ae,groupReason:Ee}}function pe(o){const s=Array.isArray(o.totals)?o.totals:[],f=o.totalFns&&typeof o.totalFns=="object"?o.totalFns:{},g=[],y=[];for(const m of s){const E=String(m),I=typeof f[E]=="string"?f[E]:null,S=I?N[I]:null;I?!S||!S.pushable||!S.sql?y.push({id:E,fn:I,class:S?S.class:"fallback",reason:S&&S.note?S.note:`the pushdown map cannot express "${I}"`}):S.twoColumn?y.push({id:E,fn:I,class:S.class,reason:`"${I}" reduces two columns, and a grouped request carries no weight column`}):g.push({id:E,col:E,fn:I,class:S.class}):y.push({id:E,fn:null,class:"fallback",reason:"the column totals with a host function, so there is no named statistic to push"})}return{engine:g,client:y}}const je=Object.freeze({items:o=>o==null?[]:Array.isArray(o)?o:[o]});function Me(o,s,f){if(!s)return o;let g=o;if(s.filters&&P(f.evaluateFilters)){const y=g,m={count:g.length,handle:S=>({id:S,get:W=>V(y[W],S)}),itemwise:S=>y.some(W=>Array.isArray(V(W,S)))?je:null},E=f.evaluateFilters(s.filters,m),I=[];for(let S=0;S<g.length;S++)E[S]&&I.push(g[S]);g=I}if(s.where&&s.where.active&&(s.whole||de(s.where.names,"pushdown"),g=g.filter(y=>s.where.passes(y))),s.quick){const y=s.quick.toLowerCase();g=g.filter(m=>{if(!m||typeof m!="object")return!1;for(const E of Object.values(m))if(E!=null&&String(E).toLowerCase().includes(y))return!0;return!1})}if(s.sort&&s.sort.length&&P(f.sortMulti)){const y=[...new Set(s.sort.map(S=>S.col))],m=g,E=y.map(S=>({id:S,get:W=>V(m[W],S)})),I=f.sortMulti(E,s.sort.map(S=>({col:S.col,dir:S.dir})),Uint32Array.from({length:g.length},(S,W)=>W),{});g=Array.from(I,S=>m[S])}return g}function c(o){return JSON.stringify({filters:o.filters||null,sort:o.sort||[],quick:o.quick||"",groupBy:o.groupBy||[],groupPath:o.groupPath||[],context:o.context??null})}function L(o){if(!o||typeof o!="object")return 16;let s="";try{s=JSON.stringify(o)}catch{return 200}return s.length*2+64}function k(o){const s=o||{};return{enabled:!!s.enabled,maxRows:Number.isFinite(s.maxRows)?s.maxRows:1e6,maxBytesEstimate:Number.isFinite(s.maxBytesEstimate)?s.maxBytesEstimate:512*1024*1024}}const R=5e4;function $(o){return Number.isFinite(o)&&o>=0?o:R}function ie(o){return!!o&&P(o.then)}async function ve(o){if(!o||o.total!==void 0||!ie(o.pendingTotal))return o;const s=await o.pendingTotal,{pendingTotal:f,...g}=o;return typeof s=="number"?{...g,total:s}:g}function qe(o={}){const s=o.adapter;if(!s||!P(s.execute))return Z("source.pushdown.adapter","createPushdownSource needs an `adapter` with an `execute(query)` function."),{...o,mode:"remote",fetch:async()=>({rows:[],total:0})};const f=z(s.capabilities),g=s.capabilities&&Object.getOwnPropertyDescriptor(s.capabilities,"operators");g&&P(g.get)&&Object.defineProperty(f,"operators",{enumerable:!0,configurable:!0,get:()=>new Set(s.capabilities.operators||[]),set:()=>{}});const y=s.name||"adapter";let m=null;const E=()=>P(s.ready)?(m||(m=Promise.resolve(s.ready()).then(()=>{Object.assign(f,z(s.capabilities))},q=>{throw m=null,q})),m):null,I=k(o.fullDataset),S=!!o.allowPartialResults,W=$(o.whereRowLimit);let se=null;const Ne=o.aggregates;let le=null,Ee=null,ke=null,Ae=null,l=null,a,d=null,j=0,ge=null;const we=()=>!I.enabled||!le?null:(ge!==le.key&&(j++,ge=le.key),{rows:le.rows,version:j}),ae=async q=>{const ce=q.where&&q.where.active?q.where:null;if(!ce)return{request:q,probe:null};const{where:Q,...O}=q,ue=ee(O,f,I.enabled);if(ue.needsAll)return{request:q,probe:null};const B=c(ue.pushed);let ye=null;return(!se||se.key!==B)&&(f.total?(D(q),ye=await ve(await s.execute(ue.pushed,q)),se={key:B,size:ye&&typeof ye.total=="number"?ye.total:null}):se={key:B,size:null}),se.size!==null&&se.size<W?{request:q,probe:null}:(F(ce.names,y,se.size,W),{request:O,probe:ye})},me=async(q,ce)=>{d=null;const Q=pe(q.pushed);ke={engine:Q.engine,client:Q.client,groupBy:q.pushed.groupBy},Q.client.length&&Z(`source.pushdown.group.totals.${y}.${Q.client.map(B=>B.id).join(".")}`,`the ${y} adapter cannot compute the group subtotal for ${Q.client.map(B=>`"${B.id}" (${B.reason})`).join(", ")}, so those group rows carry no value for that column. A figure computed over anything other than the group would be wrong, so none is shown; \`lastPlan().aggregates.client\` names them.`);const O=await s.executeGroupLevel(q.pushed,Q.engine,ce)||{};let ue=O.rows||[];return!f.range&&ce.range&&(ue=ue.slice(ce.range.start,ce.range.end)),typeof O.matchCount=="number"&&(Ae=O.matchCount,l=O.grand?{totals:O.grand,leafCount:O.matchCount}:null,a===void 0&&P(s.unfilteredCount)&&(a=null,Promise.resolve(s.unfilteredCount()).then(B=>{a=typeof B=="number"?B:null}).catch(B=>{Z(`source.pushdown.group.unfiltered.${y}`,`the ${y} adapter could not count the unfiltered set (${B&&B.message?B.message:B}), so "N of M" falls back to the display count for its denominator.`)}))),O.total===void 0?{rows:ue}:{rows:ue,total:O.total}},Ce=(q,ce)=>{const Q={key:ce,state:"pending",value:null};return d=Q,q.then(O=>(d===Q&&(d={key:ce,state:"settled",value:typeof O=="number"?O:null}),O),O=>{throw d===Q&&(d={key:ce,state:"failed",value:null}),O})},Je=async q=>{const ce=E();ce&&await ce;const Q=await ae(q);D(q);let O=ee(Q.request,f,I.enabled);if(O.grouped&&!P(s.executeGroupLevel)&&(Z(`source.pushdown.group.method.${y}`,`the ${y} adapter declares the \`group\` capability but has no \`executeGroupLevel(query, aggregates, request)\`, so grouping is not pushed and the grid is left to group whatever rows it holds. Implement the method or drop the capability.`),O=ee(Q.request,{...f,group:!1},I.enabled)),Ee=O,O.grouped)return me(O,q);if(O.groupReason&&Z(`source.pushdown.group.${y}.${O.groupReason}`,`the ${y} adapter was not asked to group this query because ${O.groupReason}. The engine returns rows and the grouping is the grid's to do, which needs every matching row in the browser — correct where the grid holds them, and wrong-looking where it holds a window. \`lastPlan().unpushed\` names it.`),!O.needsAll){const _=Q.probe||await s.execute(O.pushed,q),fe=_.rows||[];return ie(_.pendingTotal)&&_.total===void 0?{rows:fe,pendingTotal:Ce(_.pendingTotal,c(O.pushed))}:(d=null,!f.total&&_.total===void 0?{rows:fe}:{rows:fe,total:_.total??fe.length})}O.unpushed.length&&Z(`source.pushdown.residual.${y}.${O.unpushed.join(".")}`,`the ${y} adapter cannot push ${O.unpushed.join(" or ")}, so every matching row is fetched and the rest is applied in the browser. Correct, and slower than it needs to be: widening the adapter is the fix.`);const ue=c(O.pushed);if(!le||le.key!==ue){const _=await ve(await s.execute(O.pushed,q));d=null;const fe=_.rows||[];if(O.full){const Re=typeof _.total=="number"?Math.max(_.total,fe.length):fe.length;if(Re>I.maxRows)throw new Error(`[lattice] fullDataset refused: the ${y} adapter's matching set is ${Re.toLocaleString()} rows, past the configured maxRows of ${I.maxRows.toLocaleString()}. The whole set cannot be held client-side, so it is refused rather than truncated — a fraction shown as the whole would make every total and statistic silently wrong. Narrow the filter or raise maxRows.`);const Te=fe.length*L(fe[0]);if(Te>I.maxBytesEstimate)throw new Error(`[lattice] fullDataset refused: the ${y} adapter's matching set is an estimated ${Math.round(Te/(1024*1024)).toLocaleString()} MB across ${fe.length.toLocaleString()} rows, past the configured maxBytesEstimate of ${Math.round(I.maxBytesEstimate/(1024*1024)).toLocaleString()} MB. The whole set cannot be held client-side, so it is refused rather than truncated. Narrow the filter or raise maxBytesEstimate.`)}if(typeof _.total=="number"&&fe.length<_.total){const Re=!!(O.residual.filters||O.residual.quick||O.residual.sort&&O.residual.sort.length);if(Re&&!S)throw new Error(`[lattice] the ${y} adapter returned ${fe.length} of ${_.total} matching rows when asked for the whole result, and the query has residual ${O.unpushed.join(" and ")||"work"} to finish in the browser. Filtering or sorting a fraction of the result would return wrong rows, so the result is refused. Fix the adapter to follow the engine's own paging before returning, hold the data in memory, or set \`allowPartialResults: true\` on the source config to accept this knowingly.`);Re?Z(`source.pushdown.partial.residual.${y}`,`the ${y} adapter returned ${fe.length} of ${_.total} matching rows when asked for the whole result, and residual work will run over that fraction. allowPartialResults is set, so the result is used as-is — it may be wrong. The adapter must follow the engine's own paging to be correct.`):Z(`source.pushdown.partial.${y}`,`the ${y} adapter returned ${fe.length} of ${_.total} matching rows when asked for the whole result. The adapter must follow the engine's own paging before returning.`)}le={key:ue,rows:fe,total:typeof _.total=="number"?_.total:null}}let B=O;if(O.residual.where){const _=le.total??le.rows.length;if(_>=W){F(O.residual.where.names,y,_,W);const{where:fe,...Re}=Q.request;B=ee(Re,f,I.enabled),Ee=B}}const ye=le.total!==null&&le.rows.length>=le.total,We=Me(le.rows,{...B.residual,whole:ye},o.compute||{}),Le=q.range?q.range.start:0,Se=q.range?q.range.end:We.length;return{rows:We.slice(Le,Se),total:We.length}},ot=async(q,ce)=>{const Q=E();Q&&await Q;const O=ee(q,f,I.enabled);Ee=O;const ue=ne(ce,Ne),B=Array.isArray(q.groupBy)?q.groupBy:[],ye=B.length>0,We=!O.residual.filters&&!O.residual.quick,Le=!ye||T(B,f.buckets);let Se=ue.engine,_=ue.client;const fe=Ze=>{_=[...Se.map(st=>({...st,reason:Ze})),..._],Se=[]};Se.length&&!We?fe(O.residual.quick&&!O.residual.filters?"a quick search the adapter cannot push forces all-client (no mixed provenance)":"residual filter forces all-client (no mixed provenance)"):Se.length&&!Le&&fe("a grouping key the engine cannot form forces all-client (no mixed provenance)");let Re={},Te;return Se.length&&(P(ye?s.executeGroupedAggregates:s.executeAggregates)?ye?Te=await s.executeGroupedAggregates(O.pushed,B,Se)||[]:Re=await s.executeAggregates(O.pushed,Se)||{}:(Z(`source.pushdown.aggregates.${y}${ye?".grouped":""}`,`the ${y} adapter cannot compute ${ye?"grouped ":""}aggregates, so every requested statistic is computed client-side. Correct, and slower than it needs to be.`),fe(`adapter cannot compute ${ye?"grouped ":""}aggregates`))),ke={engine:Se,client:_,...ye?{groupBy:B}:{}},{values:Re,engine:Se,client:_,...Te!==void 0?{groups:Te}:{}}},it=x(o.edit),ze=o.edit&&typeof o.edit=="object"&&P(o.edit.commit);let $e=o.edit;if(it&&!ze)if(f.mutate&&f.mutate.update){const q=ce=>{if(!f.mutate||!f.mutate.update)throw new Error(`[lattice] the ${y} adapter cannot update rows (mutate.update is not declared), so this edit cannot be persisted. The cell is reverted rather than left looking saved.`);const Q={kind:"update",key:String(ce.key),patch:{[ce.colId]:ce.value}};return s.mutate(Q,ce.request||{})};$e={...o.edit===!0?{}:o.edit,commit:q}}else Z(`source.pushdown.readonly.${y}`,`edit is enabled but the ${y} adapter declares mutate: ${f.mutate?"without update":"false"} (read-only by declaration), so no commit is synthesised and the grid stays read-only. Declare \`mutate: { update: true }\` on the adapter to allow cell edits.`);const He=it&&f.mutate&&(f.mutate.append||f.mutate.delete)?{append:f.mutate.append===!0,remove:f.mutate.delete===!0,returning:f.mutate.returning,mutate:(q,ce)=>s.mutate(q,ce||{})}:null;return{...o,edit:$e,rowMutate:He,mode:"remote",fetch:Je,aggregate:ot,lastPlan:()=>Ee?{...Ee,...ke?{aggregates:ke}:{},...d?{total:{deferred:!0,state:d.state,value:d.value}}:{}}:null,fullFrame:we,counts:()=>({match:Ae,total:a??null,pending:!!d&&d.state==="pending"}),grandTotals:()=>l}}}),xe("packages/core/src/model/rowkey.js",function(h,he){"use strict";Object.defineProperty(h,"KEY_DEPENDENT_FEATURES",{enumerable:!0,get:function(){return de}}),Object.defineProperty(h,"compositeKey",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(h,"createRowKey",{enumerable:!0,get:function(){return T}}),Object.defineProperty(h,"warnMissingKeys",{enumerable:!0,get:function(){return M}}),Object.defineProperty(h,"groupPathKey",{enumerable:!0,get:function(){return D}}),Object.defineProperty(h,"splitPathKey",{enumerable:!0,get:function(){return G}});const te=he("packages/core/src/internal/util.js"),P=te.warnOnce,Z=te.pathGetter,X=te.isFunction,re=te.isBlank,de=["changes (rows.apply / rows.queue)","streaming dedupe","selection persistence","remote reload","cell comments"],F="";function Y(v){if(v===null)return"\0n";if(v===void 0)return"\0u";const V=typeof v;if(V==="string")return v;if(V==="number"||V==="bigint"||V==="boolean")return String(v);if(v instanceof Date)return`\0d${v.getTime()}`;try{return`\0o${JSON.stringify(v)}`}catch{return"\0o?"}}function ne(v){if(v.length===1)return Y(v[0]);let V="";for(let x=0;x<v.length;x++)x&&(V+=F),V+=Y(v[x]);return V}function T(v,V={}){const x=V.warn!==!1;if(X(v)){const z=v;return{stable:!0,fields:[],disabled:[],key(U,J){try{const oe=z(U);return Array.isArray(oe)?ne(oe):Y(oe)}catch(oe){return P("rowKey.throw","rowKey function threw; falling back to index identity for the affected rows.",oe),`#${J??-1}`}},keyEmpty(U){try{const J=z(U);return Array.isArray(J)?J.length===0||J.some(re):re(J)}catch{return!1}},missingFields(){return[]}}}if(Array.isArray(v)&&v.length>0){const z=v.filter(oe=>typeof oe=="string"),U=z.map(oe=>Z(oe)),J=U.length;return{stable:!0,fields:z,disabled:[],key(oe){const ee=new Array(J);for(let pe=0;pe<J;pe++)ee[pe]=U[pe](oe);return ne(ee)},keyEmpty(oe){for(let ee=0;ee<J;ee++)if(re(U[ee](oe)))return!0;return!1},missingFields(oe){const ee=[];for(let pe=0;pe<J;pe++)re(U[pe](oe))&&ee.push(z[pe]);return ee}}}if(typeof v=="string"&&v.length>0){const z=Z(v);return{stable:!0,fields:[v],disabled:[],key(U){return Y(z(U))},keyEmpty(U){return re(z(U))},missingFields(U){return re(z(U))?[v]:[]}}}return x&&P("rowKey.missing",`no rowKey configured, so rows are identified by object identity. This disables: ${de.join(", ")}. Set rowKey to a field name, an array of field names, or a function.`),{stable:!1,fields:[],disabled:de.slice(),key(z,U){if(z===null||typeof z!="object")return`#${U??0}:${String(z)}`;let J=N.get(z);return J===void 0&&(J=`#${C++}`,N.set(z,J)),J}}}const N=new WeakMap;let C=0;function M(v,V){if(!v||v.stable===!1||!X(v.keyEmpty)||!Array.isArray(V)||V.length===0)return;let x=0,z=null,U;for(let pe=0;pe<V.length;pe++){const je=V[pe];v.keyEmpty(je)&&(x++,z===null&&(z=X(v.missingFields)?v.missingFields(je):[],U=je))}if(x===0)return;const J=v.fields.length?v.fields.join(","):"(function)",oe=z&&z.length?z.join(", "):v.fields.length?v.fields.join(", "):"the rowKey function",ee=U!==null&&typeof U=="object"?Object.keys(U).join(", ")||"(no fields)":String(U);P(`rowKey.emptyValue:${J}`,`rowKey ${oe} is missing on ${x} of ${V.length} rows; the first such row has: ${ee}. Rows without a key value collapse onto one key, so selection, edits and rows.apply updates land on whichever row now shares it. Set rowKey to a field present on every row, or fix the source data.`)}function D(v){return ne(v)}function G(v){return v.split(F)}}),xe("packages/modules/data-router/devtools.js",function(h,he){"use strict";Object.defineProperty(h,"mountRouterDevtools",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(h,"default",{enumerable:!0,get:function(){return ne}});const P=he("packages/core/src/internal/util.js").warnOnce,Z="lat-router-devtools";function X(T,N,C){const M=T.createElement(N);return M.textContent=C==null?"—":String(C),M}function re(T){return Number.isFinite(T)?`${Math.round(T*10)/10}/s`:"—"}function de(T,N,C,M){const D=T.createElement("section");D.className=`${Z}-section`;const G=T.createElement("h4");G.textContent=N,D.appendChild(G);const v=T.createElement("table"),V=T.createElement("tr");for(const x of C)V.appendChild(X(T,"th",x));v.appendChild(V);for(const x of M){const z=T.createElement("tr");for(const U of x)z.appendChild(X(T,"td",U));v.appendChild(z)}return D.appendChild(v),D}function F(T,N,C){N.textContent="";const M=de(T,"Router",["metric","value"],[["throughput",re(C.throughput)],["unrouted",C.unrouted],["dropped (duplicate)",C.dropped],["buffer depth",C.buffered],["lag (deltas behind)",C.lag]]);N.appendChild(M),N.appendChild(de(T,"Routes",["#","label","kind","rows","shown","rows/sec"],C.routes.map(D=>[D.index,D.label,D.kind,D.rows,D.shown,re(D.throughput)]))),C.sources.length&&N.appendChild(de(T,"Sources",["id","rows","ingested","rows/sec"],C.sources.map(D=>[D.id,D.rows,D.ingested,re(D.throughput)])))}function Y(T,N,C={}){const M=N&&N.ownerDocument||(typeof document<"u"?document:null);if(!T||typeof T.metrics!="function"||typeof T.on!="function"||!N||!M)return P("data-router:devtools-target","router.mountDevtools(el) needs a router with metrics()/on() and a DOM element to render into; the panel was not mounted."),{destroy(){},refresh(){}};const D=M.createElement("div");D.className=Z,N.appendChild(D);const G=()=>F(M,D,T.metrics());G();const v=T.on("metrics",()=>G());return{refresh:G,destroy(){v(),D.parentNode&&D.parentNode.removeChild(D)}}}const ne=Y}),xe("packages/modules/data-router/index.js",function(h,he){"use strict";Object.defineProperty(h,"createDataRouter",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(h,"default",{enumerable:!0,get:function(){return Me}});const P=he("packages/core/src/internal/util.js").warnOnce,Z=he("packages/core/src/source/pushdown.js"),X=Z.planQuery,re=Z.capabilitiesOf,F=he("packages/core/src/model/rowkey.js").compositeKey,ne=he("packages/modules/data-router/devtools.js").mountRouterDevtools;function T(c,L){return typeof c=="function"?c:typeof c=="string"?k=>k[c]:L}function N(c){return Array.isArray(c)?"array":c===null?"null":typeof c}function C(c,L){if(c===void 0||typeof c=="string"&&c.length>0)return c;if(typeof c=="function")return k=>{const R=c(k);if(typeof R=="string"||typeof R=="number"&&Number.isFinite(R))return R;throw new Error(`lattice-data-router: rowKey function must return a string or number; got ${N(R)}.`)};throw new Error(`lattice-data-router: rowKey must be a property name or a function; composite keys are not supported on ${L}.`)}function M(c){if(typeof c=="function")return c;if(c&&typeof c=="object"&&typeof c.key=="string"){const L=c.dir==="desc"?-1:1,{key:k}=c;return(R,$)=>{const ie=R?R[k]:void 0,ve=$?$[k]:void 0;return ie<ve?-1*L:ie>ve?1*L:0}}return null}function D(c){if(!c||typeof c!="object")return null;let L=0;Number.isFinite(c.minInterval)&&c.minInterval>0?L=Number(c.minInterval):Number.isFinite(c.maxHz)&&c.maxHz>0&&(L=1e3/Number(c.maxHz));const k=Number.isFinite(c.sample)&&c.sample>1?Math.floor(Number(c.sample)):1,R=Number.isFinite(c.maxLag)&&c.maxLag>=0?Math.floor(Number(c.maxLag)):null;return L===0&&k===1&&R===null?null:{minInterval:L,sample:k,maxLag:R}}let G=0;function v(){return G+=1,`r${G}`}function V(c){const k=(Array.isArray(c)?c:[c]).map(R=>({name:typeof R=="string"?R:null,get:T(R,()=>{})}));return R=>{const $={},ie=[];for(const ve of k){const qe=ve.get(R);ie.push(qe),ve.name&&($[ve.name]=qe)}return{key:F(ie),fields:$}}}function x(c,L){if(typeof c=="function")return c(L);if(c&&typeof c=="object"){const{op:k,field:R}=c;if(k==="count")return L.length;const $=R!=null?L.map(ie=>Number(ie[R])).filter(ie=>Number.isFinite(ie)):[];if(k==="sum")return $.reduce((ie,ve)=>ie+ve,0);if(k==="avg")return $.length?$.reduce((ie,ve)=>ie+ve,0)/$.length:0;if(k==="min")return $.length?Math.min(...$):void 0;if(k==="max")return $.length?Math.max(...$):void 0}}function z(c){return c&&typeof c=="object"&&typeof c.from=="string"&&typeof c.to=="string"?{from:c.to,to:c.from}:(P("data-router:mutual-fn","relate({ mutual: true }) with a function relation cannot be inverted; the same predicate is applied in both directions. Use a { from, to } key map for a mutual edge."),c)}function U(c,L){return c?L?{op:"and",conditions:[c,L]}:c:L||null}const J=Object.freeze(["eq","ne","lt","lte","gt","gte","between","notBetween","in","notIn","contains","notContains","startsWith","endsWith","blank","notBlank"]);function oe(c,L){const k=L?L[c.col]:void 0,R=c.value,$=ie=>c.caseSensitive?String(ie):String(ie).toLowerCase();switch(c.op){case"eq":return k===R;case"ne":return k!==R;case"lt":return k<R;case"lte":return k<=R;case"gt":return k>R;case"gte":return k>=R;case"between":return Array.isArray(R)&&k>=R[0]&&k<=R[1];case"notBetween":return!(Array.isArray(R)&&k>=R[0]&&k<=R[1]);case"in":return Array.isArray(R)&&R.includes(k);case"notIn":return!(Array.isArray(R)&&R.includes(k));case"contains":return k!=null&&$(k).includes($(R));case"notContains":return k==null||!$(k).includes($(R));case"startsWith":return k!=null&&$(k).startsWith($(R));case"endsWith":return k!=null&&$(k).endsWith($(R));case"blank":return k==null||k==="";case"notBlank":return!(k==null||k==="");default:throw new Error(`[lattice] query() cannot evaluate the residual filter operator "${String(c.op)}" on column "${String(c.col)}" client-side, so the query is refused rather than returning rows the filter excludes. Push it down to an adapter that implements it, or use an operator this router evaluates: ${J.join(", ")}.`)}}function ee(c,L){return c?Array.isArray(c.conditions)?c.op==="or"?c.conditions.some(k=>ee(k,L)):c.op==="not"?!c.conditions.every(k=>ee(k,L)):c.conditions.every(k=>ee(k,L)):oe(c,L):!0}function pe(c={}){const L=T(c.key,()=>{}),k=T(C(c.rowKey,"routes"),e=>e.rowKey),R=!!c.overlap,$=typeof c.onUnrouted=="function"?c.onUnrouted:null,ie=Number.isFinite(c.selectionDebounce)?Number(c.selectionDebounce):16,ve=typeof c.onWrite=="function"?c.onWrite:null,qe=typeof c.onConflict=="function"?c.onConflict:null,o=c.seq!=null?T(c.seq,()=>{}):null,s=o?c.dedupe!==!1:!1,f=k;let g=null;typeof c.batch=="number"?g=c.batch:c.batch&&Number.isFinite(c.batch.intervalMs)&&(g=Number(c.batch.intervalMs));const y=g!==null||!!c.coalesce,m=new Map;let E,I=0;const S=[];let W=null;const se=c.time!=null?T(c.time,()=>{}):null,Ne=typeof c.now=="function"?c.now:Date.now,le=1e4;let Ee=!1,ke=null,Ae=null,l="time",a=new Map;const d=[];let j=0,ge,we,ae=!1,me=null,Ce=[],Je=0,ot=0,it="time",ze=!1,$e=null,He=null;const q=e=>{if(e&&Number.isFinite(e.seq))return e.seq;if(o&&e&&e.row){const t=o(e.row);return Number.isFinite(t)?t:void 0}},ce=e=>{if(e&&Number.isFinite(e.t))return e.t;if(se&&e&&e.row){const t=se(e.row);if(Number.isFinite(t))return t}return Ne()},Q=[];let O=null;const ue=[],B=[],ye=new Map,We=new Set;let Le=null,Se=0;const _=new Map,fe=new Set,Re=typeof c.rowKey=="string"?c.rowKey:"rowKey",Te=new Map;let Ze=0;const st=new Map,Be=(e,t)=>{st.set(e,(st.get(e)||0)+t)};let bt=0;const wt=new Map,ut=new Map;let Ue=null;const qt=Number.isFinite(c.metricsInterval)?Number(c.metricsInterval):1e3;let Ve=0,Fe=null,vt="lattice-router",Et=250,Ie=null,Xe=null,lt=!1,kt=!1,De=null,et=!1,St=null;const Ge=[],be=()=>O?[...Q,O]:Q,Qe=e=>be().find(t=>t.grid===e)||null,at=e=>{const t=[];for(const n of Q)if(n.match(e)&&(t.push(n),!R))break;return t.length?t:O?[O]:[]},on=(e,t)=>{if(t.add.length||t.update.length||t.remove.length){const n=e.sink(t);sn(e,n)}return{added:t.add.length,updated:t.update.length,removed:t.remove.length}},sn=(e,t)=>{const n=t?.rejected;if(!Array.isArray(n)||!n.length)return;const r=n.filter(u=>u&&u.operation==="remove");if(!r.length)return;const i=e.label||`route ${e.routeId}`;P(`data-router:remove-rejected:${e.routeId}`,`route "${i}" asked its target to remove ${r.length} row(s) the target does not have (for example ${JSON.stringify(String(r[0].id))}). The rows are still on screen. This is a key mismatch: the key the route derives for a row is not the key the grid derives for it. Check that the route's \`rowKey\` names the same value as the grid's.`)},un=(e,t)=>{for(const n of ue)if(n.to===e.grid&&n.predicate&&!n.predicate(t))return!1;if(e.graphPreds){for(const n of e.graphPreds)if(!n(t))return!1}return!0},Ke=e=>{const t=[];for(const p of e.partition.values())e.filter&&!e.filter(p)||un(e,p)&&t.push(p);let n;if(e.rollup){const p=new Map;for(const b of t){const{key:A,fields:K}=e.rollup.group(b);let H=p.get(A);H||(H={key:A,fields:K,rows:[]},p.set(A,H)),H.rows.push(b)}let w=[];for(const b of p.values()){const A={...b.fields};for(const[K,H]of e.rollup.specs)A[K]=x(H,b.rows);w.push({gkey:b.key,row:A})}e.sort&&w.sort((b,A)=>e.sort(b.row,A.row)),e.transform&&(w=w.map(b=>({gkey:b.gkey,row:e.transform(b.row)}))),n=new Map(w.map(b=>[b.gkey,b.row]))}else{let p=t;e.sort&&(p=p.slice().sort(e.sort)),n=new Map;for(const w of p)n.set(F([e.keyOf(w)]),e.transform?e.transform(w):w)}const r=[],i=[],u=[];for(const[p,w]of n)e.keys.has(p)?je(e.keys.get(p),w)||i.push(w):r.push(w);for(const p of e.keys.keys())n.has(p)||u.push(p);return e.keys=n,on(e,{add:r,update:i,remove:u})},ct=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),Ke(e),e.bpPending=0,e.bpLastFlush=Ne()},ln=(e,t)=>{if(e.bpTimer)return;const n=e.bp.minInterval>0?Math.max(e.bp.minInterval-(t-e.bpLastFlush),0):0;e.bpTimer=setTimeout(()=>{e.bpTimer=null,ct(e)},n),e.bpTimer&&typeof e.bpTimer.unref=="function"&&e.bpTimer.unref()},an=(e,t)=>{if(!e.bp){Ke(e);return}e.bpPending+=t,e.bpCoalesced+=t;const n=e.bp;if(n.maxLag!=null&&e.bpPending<=n.maxLag&&!e.bpTimer){ct(e);return}const r=Ne(),i=r-e.bpLastFlush>=n.minInterval,u=e.bpPending>=n.sample;if(i&&u){ct(e);return}ln(e,r)},cn=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),e.bpPending=0,e.bpLastFlush=Ne()},Ot=(e,t)=>{if(typeof e=="function"){const n=e(t);return typeof n=="function"?n:null}if(e&&typeof e=="object"){const n=e.from,r=e.to,i=new Set(t.map(u=>u&&u[n]));return u=>i.has(u&&u[r])}return null},Ht=e=>{const t=Qe(e),n=e&&e.selection,r=n&&typeof n.keys=="function"?n.keys():[];return!r.length||!t?[]:r.map(i=>t.partition.get(String(i))).filter(i=>i!==void 0)},Ye=e=>{const t=Ht(e.from);e.predicate=t.length?Ot(e.relation,t):null},tt=()=>{const e=new Set;for(const t of B)e.add(t.from),e.add(t.to);return e},_e=()=>{for(const u of be())u.graphPreds=null;if(!B.length)return;const e=tt(),t=new Map;for(const u of e){const p=Ht(u);p.length&&t.set(u,p)}const n=new Map(t);let r=!0,i=(e.size+1)*2;for(;r&&i-- >0;){r=!1;for(const u of e){if(t.has(u))continue;const p=B.filter(H=>H.to===u&&n.has(H.from));if(!p.length)continue;const w=Qe(u);if(!w)continue;const b=p.map(H=>Ot(H.rel,n.get(H.from))).filter(Boolean),A=[];for(const H of w.partition.values())b.every(Oe=>Oe(H))&&A.push(H);const K=n.get(u);if(!K||K.length!==A.length)n.set(u,A),r=!0;else{const H=new Set(K);A.some(Oe=>!H.has(Oe))&&(n.set(u,A),r=!0)}}}for(const u of B){if(!n.has(u.from))continue;const p=Ot(u.rel,n.get(u.from));if(!p)continue;const w=Qe(u.to);w&&(w.graphPreds||(w.graphPreds=[])).push(p)}},Bt=e=>{const t=ye.get(e);if(t){t.count+=1;return}const n=e&&typeof e.on=="function"?e.on("selection:changed",()=>fn(e)):()=>{};ye.set(e,{off:n,count:1})},Tt=()=>{Le&&(clearTimeout(Le),Le=null);const e=We;if(!e.size)return;const t=new Set;for(const n of ue)e.has(n.from)&&(Ye(n),t.add(n.to));if(We.clear(),B.length){_e();for(const n of tt())t.add(n)}for(const n of t){const r=Qe(n);r&&Ke(r)}},fn=e=>{if(We.add(e),ie<=0){Tt();return}Le||(Le=setTimeout(Tt,ie))},Kt=e=>{const t=ye.get(e);t&&(t.count-=1,t.count<=0&&(t.off(),ye.delete(e)))},dn=e=>typeof e=="function"?t=>e(t):e&&e.rows&&typeof e.rows.apply=="function"?t=>e.rows.apply(t):(P("data-router:bad-target","attach/subscribe target has no rows.apply and is not a function; its slice goes nowhere. Pass a grid or a handler(change) function."),()=>{}),jt=(e,t,n)=>({grid:e,routeId:v(),sink:dn(e),match:t,keyOf:T(C(n.rowKey,"routes"),k),partition:new Map,keys:new Map,transform:typeof n.transform=="function"?n.transform:null,filter:typeof n.filter=="function"?n.filter:null,sort:M(n.sort),rollup:n.rollup&&n.rollup.groupBy!=null?{group:V(n.rollup.groupBy),specs:Object.entries(n.rollup.aggregate||{})}:null,where:n.where&&typeof n.where=="object"?n.where:null,graphPreds:null,onWrite:typeof n.onWrite=="function"?n.onWrite:null,onConflict:typeof n.onConflict=="function"?n.onConflict:null,writable:n.writable===!0,readonly:!!(n.rollup&&n.rollup.groupBy!=null||typeof n.transform=="function"),label:typeof n.label=="string"?n.label:null,metricRows:0,bp:D(n.backpressure),bpPending:0,bpTimer:null,bpLastFlush:-1/0,bpCoalesced:0}),xt=e=>{if(!R){for(const t of Q)if(t.hasPartValue&&t.partValue===e){P(`data-router:overlap:${String(e)}`,`Data Router: value ${JSON.stringify(e)} already routes to another viewer; with overlap:false only the first receives rows. Pass createDataRouter({ overlap: true }) to fan one value to several viewers.`);return}}},zt=(e,t)=>`${String(e)}${String(t)}`,pn=e=>{const t=e&&e.row;if(!t)return null;const n=t.data&&typeof t.data=="object"?t.data:t;return n?{...n}:null},ft=(e,t)=>{const n=e.grid;if(!n||!n.edit||typeof n.edit.setCells!="function")return;const r=zt(t.key,t.colId);fe.add(r);try{n.edit.setCells([{key:t.key,colId:t.colId,value:t.before}],"cell")}finally{fe.delete(r)}Be("writeReverted",1)},Ut=e=>{e&&Pe.apply([{op:"upsert",row:e}])},Vt=(e,t,n)=>{const r=n&&typeof n=="object"?n:null,i=r&&r.conflict!==void 0?r.conflict:null;if(i){const u=e.onConflict||qe;if(u)try{u(t,{serverRow:i})}catch{}Be("writeConflicted",1),Ut(r&&r.row?r.row:t.row);return}if(n===!1||r&&r.ok===!1){Be("writeRejected",1),ft(e,t);return}Be("writeAccepted",1),Ut(r&&r.row?r.row:t.row)},hn=e=>{const t=String(e);for(const n of Te.values())if(n.live.has(t))return n.handle;return null},gn=(e,t)=>{if(!t||t.key===void 0||t.colId===void 0||fe.has(zt(t.key,t.colId)))return;const n=pn(t),r={key:String(t.key),colId:String(t.colId),value:t.value,before:t.oldValue,row:n};if(Be("writeRouted",1),e.readonly){P("data-router:readonly-write","an edit on a derived (rollup/transform) route is read-only and was reverted; a derived row cannot be inverted to a source row. Make the source route writable instead."),ft(e,r);return}const i=e.onWrite||ve;if(!i){P("data-router:no-onwrite","a route attached with { writable: true } has no onWrite handler (per-route or router-global); the edit was left in place but not persisted. Pass onWrite to route the write.");return}let u;try{u=i(r,{route:e.grid,source:hn(r.key)})}catch{ft(e,r),Be("writeRejected",1);return}u&&typeof u.then=="function"?u.then(p=>Vt(e,r,p),()=>{ft(e,r),Be("writeRejected",1)}):Vt(e,r,u)},mn=e=>{const t=e.grid;if(!t||typeof t.on!="function"||!t.edit||typeof t.edit.setCells!="function"){P("data-router:writable-target","attach({ writable: true }) needs a grid exposing grid.on and grid.edit.setCells; write-back is off for this route.");return}if(_.has(t))return;const n=t.on("cell:changed",r=>gn(e,r));_.set(t,typeof n=="function"?n:()=>{})},yn=e=>{const t=[];for(const n of e.partition.values())e.filter&&!e.filter(n)||t.push(n);return t},dt=e=>{const t=yn(e);if(e.kind==="monitor"){let r;try{r=e.evaluate(t)}catch{r=void 0}e.handler(r,t);return}let n;try{n=e.condition(t)}catch{n=!1}if(n){if(!e.armed)return;e.debounceMs>0?(e.pending={signal:n,rows:t},e.timer||(e.timer=setTimeout(()=>{e.timer=null;const r=e.pending;e.pending=null,r&&(e.armed=!1,e.handler(r.signal,r.rows))},e.debounceMs))):(e.armed=!1,e.handler(n,t))}else e.armed=!0,e.timer&&(clearTimeout(e.timer),e.timer=null),e.pending=null},Rt=(e,t)=>{e.partition=new Map;for(const n of t)e.match(n)&&e.partition.set(String(e.keyOf(n)),n)},bn=(e,t)=>{for(const n of t){const r=n&&n.row;if(!r)continue;const i=String(e.keyOf(r));if(n.op==="delete"){e.partition.delete(i);continue}e.match(r)?e.partition.set(i,r):e.partition.delete(i)}},nt=()=>{const e=new Map;for(const t of be())for(const n of t.partition.values())e.set(String(f(n)),n);return[...e.values()]},Gt=()=>{a=new Map;for(const e of be())for(const t of e.partition.values())a.set(String(f(t)),t);d.length=0,j=0,ge=E,we=void 0},Jt=()=>{const e=d.shift();e&&(e.op==="del"?a.delete(e.key):a.set(e.key,e.row),ge=e.seq,we=e.t)},wn=()=>{if(ke!=null)for(;d.length>ke;)Jt();if(Ae!=null&&d.length){const e=d[d.length-1].t;for(;d.length>1&&e-d[0].t>Ae;)Jt()}},vn=e=>{!e||!e.row||d.push({pos:j++,seq:q(e),t:ce(e),op:e.op==="delete"?"del":"set",key:String(f(e.row)),row:e.row})},Pt=(e,t)=>t==="seq"?e.seq:e.t,pt=(e,t)=>{const n=new Map(a);for(const r of d){const i=Pt(r,t);if(e!==void 0&&i!==void 0&&i>e)break;r.op==="del"?n.delete(r.key):n.set(r.key,r.row)}return n},ht=e=>{const t=new Map(be().map(n=>[n,[]]));for(const n of e)for(const r of at(n))t.get(r).push(n);for(const n of be())n.partition=new Map(t.get(n).map(r=>[String(n.keyOf(r)),r]));for(const n of ue)Ye(n);_e();for(const n of be())Ke(n)},Nt=e=>Ee?!0:(P("data-router:no-buffer",`${e}() needs a buffered window; call router.buffer({ window, max }) first to record one.`),!1),gt=()=>{if($e&&(clearTimeout($e),$e=null),ze=!1,Ce=[],Je=0,He){const e=He;He=null,e()}},En=()=>{if(Ce=[],Je=0,He){const e=He;He=null,e()}},kn=()=>{$e=null;const e=Ce[Je++];e.op==="del"?me.delete(e.key):me.set(e.key,e.row),ht([...me.values()]),Ve=e.pos+1,At()};function At(){if(!ze){if(Je>=Ce.length){En();return}$e=setTimeout(kn,ot)}}function mt(e){if(De)try{De.postMessage(e)}catch{}}function Qt(){return{t:"snapshot",rows:nt(),seq:E,checkpoint:Object.fromEntries(m)}}function Sn(e){const t=e&&e.data;if(!(!t||typeof t!="object")){if(t.t==="hello"){nt().length&&mt(Qt());return}et=!0;try{t.t==="delta"?Pe.apply(t.deltas||[]):t.t==="snapshot"&&(Pe.load(t.rows||[]),t.checkpoint&&Pe.seenThrough(t.checkpoint))}finally{et=!1}}}function On(e,t){e.partition=new Map(t.map(n=>[String(e.keyOf(n)),n]))}function Tn(e,t){const n=t.filter(i=>!i.isDefault),r=t.find(i=>i.isDefault)||null;for(const i of t)i.partition=new Map;for(const i of e){const u=[];for(const w of n)if(w.match(i)&&(u.push(w),!R))break;const p=u.length?u:r?[r]:[];if(!p.length){Se+=1,$&&$(i);continue}for(const w of p)w.partition.set(String(w.keyOf(i)),i)}}const jn=(e,t)=>{if(typeof t=="function")return r=>t(r);let n=null;return t===!0?n=String(e):typeof t=="string"&&(n=t),n==null?null:r=>`${n}:${r[Re]}`},_t=(e,t)=>{const n={...e.map?e.map(t):t};return e.ns&&(n[Re]=e.ns(n)),n},Yt=(e,t)=>{const n=[];for(const r of t||[]){if(!r||!r.row)continue;const i=_t(e,r.row),u=String(i[Re]);r.op==="delete"?e.live.delete(u):e.live.set(u,i),n.push({...r,row:i})}return e.ingested+=n.length,Be(`source:${e.id}`,n.length),n},Rn=e=>({get id(){return e.id},get size(){return e.live.size},load(t){const n=(t||[]).map(u=>_t(e,u)),r=new Map(n.map(u=>[String(u[Re]),u])),i=[];for(const[u,p]of e.live)r.has(u)||i.push({op:"delete",row:p});for(const u of n)i.push({op:"upsert",row:u});return e.live=r,e.ingested+=n.length,Be(`source:${e.id}`,n.length),Dt(e,i,u=>Pe.apply(u)),this},apply(t){return Dt(e,Yt(e,t),n=>Pe.apply(n)),this},push(t){return Dt(e,Yt(e,Array.isArray(t)?t:[t]),n=>Pe.push(n)),this},remove(){const t=[];for(const n of e.live.values())t.push({op:"delete",row:n});return e.live.clear(),Te.delete(e.id),t.length&&Pe.apply(t),Pe}}),Ft=e=>e==null?null:String(e),Pn=(e,t)=>{if(!e||typeof e!="object")return null;const n=e.from!=null?String(e.from):null;if(!n)return P("data-router:join-no-from","join needs a `from` (the lookup source id); ignoring the join."),null;const r=e.localKey!=null?e.localKey:e.on;let i;if(typeof r=="function")i=r;else if(typeof r=="string")i=Oe=>Oe[r];else return P("data-router:join-no-localkey","join needs a `localKey` (a field name or fn); ignoring the join."),null;const u=e.foreignKey!=null?e.foreignKey:e.fromKey;let p,w;if(typeof u=="function")p=u,w=u;else if(typeof u=="string")p=Oe=>Oe[u],w=u;else if(typeof r=="string")p=Oe=>Oe[r],w=r;else return P("data-router:join-no-foreignkey","join with a fn `localKey` needs an explicit string/fn `foreignKey`; ignoring the join."),null;let b=null;const A=[],K=e.fields!=null?e.fields:e.select;if(typeof K=="function")b=K;else if(Array.isArray(K))for(const Oe of K)A.push([String(Oe),String(Oe)]);else if(K&&typeof K=="object")for(const[Oe,rt]of Object.entries(K))A.push([Oe,String(rt)]);else P("data-router:join-no-fields","join has no `fields`/`select`; rows pass through unenriched.");let H=e.missing;return H!=="hold"&&H!=="passthrough"&&H!=="null"&&(H!=null&&P("data-router:join-bad-missing",`join.missing "${H}" is not hold|passthrough|null; using "passthrough".`),H="passthrough"),{from:n,localKey:i,foreignKeyFn:p,ffKey:w,pairs:A,selectFn:b,missing:H,keyIndex:new Map,lastFk:new Map,owner:t,probe:null}},Zt=(e,t,n)=>{const r={...t};if(e.selectFn){const i=e.selectFn(n,t);return i&&typeof i=="object"&&Object.assign(r,i),r}for(const[i,u]of e.pairs)r[u]=n?n[i]:null;return r},Nn=(e,t)=>{if(t==null||!e.probe)return null;const n=e.probe.index.get(t);if(!n||!n.size)return null;const r=Te.get(e.from);if(!r)return null;let i;for(i of n);return r.live.get(i)||null},Xt=(e,t,n)=>{const r=Nn(e,n);return r?{emit:!0,row:Zt(e,t,r)}:e.missing==="hold"?{emit:!1,row:t}:e.missing==="null"?{emit:!0,row:Zt(e,t,null)}:{emit:!0,row:{...t}}},en=(e,t,n)=>{const r=e.lastFk.get(t);if(r!==void 0&&r!==n){const u=e.keyIndex.get(r);u&&(u.delete(t),u.size||e.keyIndex.delete(r))}if(n==null){e.lastFk.set(t,null);return}let i=e.keyIndex.get(n);i||(i=new Set,e.keyIndex.set(n,i)),i.add(t),e.lastFk.set(t,n)},An=(e,t)=>{const n=e.join,r=[];for(const i of t){const u=String(i.row[Re]);if(i.op==="delete"){en(n,u,null),n.lastFk.delete(u),r.push(i);continue}const p=Ft(n.localKey(i.row));en(n,u,p);const w=Xt(n,i.row,p);w.emit&&r.push({...i,row:w.row})}return r},tn=(e,t)=>{e.probes||(e.probes=new Map);let n=e.probes.get(t.ffKey);if(!n){n={fn:t.foreignKeyFn,index:new Map,prev:new Map,specs:new Set},e.probes.set(t.ffKey,n);for(const[r,i]of e.live){const u=Ft(n.fn(i));if(u==null)continue;let p=n.index.get(u);p||(p=new Set,n.index.set(u,p)),p.add(r),n.prev.set(r,u)}}n.specs.add(t),t.probe=n},Fn=(e,t)=>{if(!e.probes||!e.probes.size)return;const n=[];for(const r of e.probes.values()){const i=new Set;for(const u of t){const p=String(u.row[Re]);if(u.op==="delete"){const A=r.prev.get(p);if(A!=null){const K=r.index.get(A);K&&(K.delete(p),K.size||r.index.delete(A)),i.add(A)}r.prev.delete(p);continue}const w=Ft(r.fn(u.row)),b=r.prev.get(p);if(b!=null&&b!==w){const A=r.index.get(b);A&&(A.delete(p),A.size||r.index.delete(b)),i.add(b)}if(w!=null){let A=r.index.get(w);A||(A=new Set,r.index.set(w,A)),A.add(p),i.add(w)}r.prev.set(p,w)}if(i.size)for(const u of r.specs)for(const p of i){const w=u.keyIndex.get(p);if(w)for(const b of w){const A=u.owner.live.get(b);if(!A)continue;const K=Xt(u,A,p);n.push(K.emit?{op:"upsert",row:K.row}:{op:"delete",row:A})}}}n.length&&Pe.apply(n)},Dt=(e,t,n)=>{n(e.join?An(e,t):t),e.probes&&e.probes.size&&Fn(e,t)},Lt=(e,t,n)=>{const r=wt.get(e);if(wt.set(e,{cur:t,t:n}),!r)return 0;const i=(n-r.t)/1e3;return i<=0?0:(t-r.cur)/i},Dn=()=>{if(!Ee)return 0;let e=0;for(const t of d)t.pos>=Ve&&(e+=1);return e},Ln=(e,t)=>{const n=ut.get(e);if(n)for(const r of n)try{r(t)}catch{}},In=()=>{Ue||qt<=0||(Ue=setInterval(()=>Ln("metrics",Pe.metrics()),qt),Ue&&typeof Ue.unref=="function"&&Ue.unref())},nn=()=>{Ue&&(clearInterval(Ue),Ue=null)},Cn=e=>{const t=e.indexedDB||(typeof indexedDB<"u"?indexedDB:null);if(!t)return null;const n=typeof e.dbName=="string"?e.dbName:"lattice-router",r=typeof e.storeName=="string"?e.storeName:"snapshots";let i=null;const u=()=>i||(i=new Promise((p,w)=>{let b;try{b=t.open(n,1)}catch(A){w(A);return}b.onupgradeneeded=()=>{const A=b.result;A.objectStoreNames.contains(r)||A.createObjectStore(r)},b.onsuccess=()=>p(b.result),b.onerror=()=>w(b.error)}),i);return{set(p,w){return u().then(b=>new Promise((A,K)=>{const H=b.transaction(r,"readwrite");H.objectStore(r).put(w,p),H.oncomplete=()=>A(),H.onerror=()=>K(H.error),H.onabort=()=>K(H.error)}))},get(p){return u().then(w=>new Promise((b,A)=>{const H=w.transaction(r,"readonly").objectStore(r).get(p);H.onsuccess=()=>b(H.result),H.onerror=()=>A(H.error)}))},close(){i&&i.then(p=>{try{p.close()}catch{}},()=>{})}}},$n=()=>Ee?[...pt(void 0,l).values()]:nt(),Wn=()=>({v:1,world:$n(),maxSeq:E,checkpoint:Object.fromEntries(m),buffer:Ee?{on:!0,max:ke,window:Ae,domain:l,pos:j,baseSeq:ge,baseT:we,base:[...a.entries()],log:d.map(e=>({pos:e.pos,seq:e.seq,t:e.t,op:e.op,key:e.key,row:e.row}))}:{on:!1}}),Mn=e=>{if(!e||typeof e!="object")return!1;kt=!0;try{Pe.load(Array.isArray(e.world)?e.world:[])}finally{kt=!1}e.checkpoint&&Pe.seenThrough(e.checkpoint),Number.isFinite(e.maxSeq)&&(E===void 0||e.maxSeq>E)&&(E=e.maxSeq);const t=e.buffer;if(t&&t.on){Ee=!0,ke=Number.isFinite(t.max)?t.max:null,Ae=Number.isFinite(t.window)?t.window:null,l=t.domain==="seq"||t.domain==="time"?t.domain:o?"seq":"time",a=new Map(Array.isArray(t.base)?t.base:[]),d.length=0;for(const n of Array.isArray(t.log)?t.log:[])d.push({...n});j=Number.isFinite(t.pos)?t.pos:d.length,ge=t.baseSeq,we=t.baseT,Ve=j}return!0},It=()=>{if(!Fe)return Promise.resolve();const e=Wn(),t=Promise.resolve().then(()=>Fe.set(vt,e)).catch(()=>{});return Xe=t,t.then(()=>{Xe===t&&(Xe=null)})},Ct=()=>{if(!(!lt||!Fe||kt)){if(Et<=0){It();return}Ie||(Ie=setTimeout(()=>{Ie=null,It()},Et),Ie&&typeof Ie.unref=="function"&&Ie.unref())}},Pe={attach(e,t,n={}){const r=typeof t!="function",i=r?p=>L(p)===t:t;r&&xt(t);const u=jt(e,i,n);return r&&(u.hasPartValue=!0,u.partValue=t),Q.push(u),u.writable&&mn(u),this},attachDefault(e,t={}){return O=jt(e,()=>!1,t),O.isDefault=!0,this},subscribe(e,t,n={}){const r=typeof e!="function",i=r?p=>L(p)===e:e;r&&xt(e);const u=jt(t,i,n);return r&&(u.hasPartValue=!0,u.partValue=e),Q.push(u),this},alert(e,t,n,r={}){const u={match:typeof e=="function"?e:p=>L(p)===e,keyOf:T(C(r.rowKey,"alerts"),k),filter:typeof r.filter=="function"?r.filter:null,condition:typeof t=="function"?t:()=>!1,handler:typeof n=="function"?n:()=>{},debounceMs:Number.isFinite(r.debounce)?Number(r.debounce):0,armed:!0,timer:null,pending:null,partition:new Map};return Ge.push(u),Rt(u,nt()),dt(u),this},monitor(e,t,n,r={}){const u={kind:"monitor",match:typeof e=="function"?e:p=>L(p)===e,keyOf:T(C(r.rowKey,"alerts"),k),filter:typeof r.filter=="function"?r.filter:null,evaluate:typeof t=="function"?t:()=>{},handler:typeof n=="function"?n:()=>{},armed:!0,timer:null,pending:null,partition:new Map};return Ge.push(u),Rt(u,nt()),dt(u),()=>{const p=Ge.indexOf(u);p>=0&&Ge.splice(p,1),u.timer&&(clearTimeout(u.timer),u.timer=null),u.partition.clear()}},configure(e={}){const t=n=>({rowKey:n.rowKey,transform:n.transform,filter:n.filter,sort:n.sort,rollup:n.rollup,debounce:n.debounce,where:n.where,writable:n.writable,onWrite:n.onWrite,onConflict:n.onConflict,backpressure:n.backpressure,label:n.label});for(const n of e.routes||[])if(n){if(n.default!==void 0){this.attachDefault(n.default,t(n));continue}if(n.alert!==void 0){this.alert(n.when,n.condition,n.alert,t(n));continue}if(n.subscribe!==void 0){this.subscribe(n.when,n.subscribe,t(n));continue}this.attach(n.grid,n.when,t(n))}for(const n of e.links||[])n&&n.from&&n.to&&this.link(n.from,n.to,n.on!==void 0?n.on:n.relation);return e.relate&&this.relate(e.relate),e.buffer&&this.buffer(e.buffer),this},link(e,t,n){const r={from:e,to:t,relation:n,predicate:null};ue.push(r),Bt(e),Ye(r);const i=Qe(t);return i&&Ke(i),this},relate(e){for(const t of e||[]){if(!t||!t.from||!t.to)continue;const n=t.on!==void 0?t.on:t.relation!==void 0?t.relation:t.rel;B.push({from:t.from,to:t.to,rel:n}),t.mutual&&B.push({from:t.to,to:t.from,rel:z(n)})}for(const t of tt())Bt(t);_e();for(const t of tt()){const n=Qe(t);n&&Ke(n)}return this},flush(){return Tt(),this},detach(e){const t=new Set;for(let i=ue.length-1;i>=0;i--){const u=ue[i];(u.from===e||u.to===e)&&(u.to!==e&&t.add(u.to),Kt(u.from),ue.splice(i,1))}let n=!1;for(let i=B.length-1;i>=0;i--)(B[i].from===e||B[i].to===e)&&(Kt(B[i].from),B.splice(i,1),n=!0);for(let i=Q.length-1;i>=0;i--)Q[i].grid===e&&Q.splice(i,1);O&&O.grid===e&&(O=null),We.delete(e);const r=_.get(e);if(r&&(r(),_.delete(e)),n){_e();for(const i of tt())t.add(i)}for(const i of t){const u=Qe(i);u&&Ke(u)}return this},load(e){Se=0;const t=new Map(be().map(r=>[r,[]]));for(const r of e||[]){const i=at(r);if(!i.length){Se+=1,$&&$(r);continue}for(const u of i)t.get(u).push(r)}for(const r of be()){const i=t.get(r);r.partition=new Map(i.map(u=>[String(r.keyOf(u)),u])),r.metricRows+=i.length,bt+=i.length}if(o)for(const r of e||[]){const i=o(r);if(!Number.isFinite(i))continue;const u=String(f(r)),p=m.get(u);(p===void 0||i>p)&&m.set(u,i),(E===void 0||i>E)&&(E=i)}for(const r of ue)Ye(r);_e();for(const r of Ge)Rt(r,e||[]),dt(r);for(const r of be())r.bp&&cn(r);const n=be().map(r=>Ke(r));return Ee&&Gt(),Ve=j,De&&!et&&mt(Qt()),Ct(),n},apply(e){let t=(e||[]).filter(i=>i&&i.row);if(s){t=t.map((u,p)=>[u,p]).sort((u,p)=>{const w=q(u[0]),b=q(p[0]);return w===void 0||b===void 0?u[1]-p[1]:w-b||u[1]-p[1]}).map(u=>u[0]);const i=[];for(const u of t){const p=q(u);if(p!==void 0){const w=String(f(u.row)),b=m.get(w);if(b!==void 0&&p<=b){I+=1;continue}m.set(w,p),(E===void 0||p>E)&&(E=p)}i.push(u)}t=i}if(De&&!et&&t.length&&mt({t:"delta",deltas:t.map(i=>({op:i.op,row:i.row,seq:i.seq}))}),Ee){for(const i of t)vn(i);wn()}for(const i of Ge)bn(i,t),dt(i);if(ae){Ct();return}const n=new Map(be().map(i=>[i,new Map]));for(const i of t){const u=i&&i.row;if(!u)continue;if(i.op==="delete"){let w=!1;for(const b of be()){const A=String(b.keyOf(u));(b.partition.has(A)||n.get(b).has(A))&&(n.get(b).set(A,{op:"del"}),w=!0)}!w&&!at(u).length&&(Se+=1,$&&$(i));continue}const p=at(u);if(!p.length){Se+=1,$&&$(i);continue}for(const w of be()){if(p.includes(w))continue;const b=String(w.keyOf(u));(w.partition.has(b)||n.get(w).get(b)?.op==="set")&&n.get(w).set(b,{op:"del"})}for(const w of p)n.get(w).set(String(w.keyOf(u)),{op:"set",row:u})}const r=new Map;for(const i of be()){let u=0;const p=n.get(i).size;for(const[w,b]of n.get(i)){if(b.op==="del"){i.partition.delete(w);continue}i.partition.set(w,b.row),u+=1}i.metricRows+=u,bt+=u,r.set(i,p)}for(const i of ue)Ye(i);_e();for(const i of be())an(i,r.get(i)||0);Ve=j,Ct()},push(e){const t=Array.isArray(e)?e:[e];if(!y)return this.apply(t),this;for(const n of t)S.push(n);return g!==null&&(g<=0?this.flushStream():W||(W=setTimeout(()=>this.flushStream(),g))),this},flushStream(){if(W&&(clearTimeout(W),W=null),!S.length)return this;const e=S.splice(0,S.length);return this.apply(e),this},flushBackpressure(){for(const e of be())e.bp&&(e.bpTimer||e.bpPending>0)&&ct(e);return this},addSource(e,t){let n,r;e&&typeof e=="object"?(r=e,n=r.id!=null?String(r.id):`source${++Ze}`):(n=e!=null?String(e):`source${++Ze}`,r=t||{});const i=Te.get(n);if(i)return P("data-router:duplicate-source",`addSource("${n}") was already registered; returning the existing source handle. Use a distinct id per feed.`),i.handle;const u={id:n,map:typeof r.map=="function"?r.map:null,ns:jn(n,r.key),live:new Map,ingested:0};u.handle=Rn(u),u.join=Pn(r.join,u),Te.set(n,u),u.join&&Te.has(u.join.from)&&tn(Te.get(u.join.from),u.join);for(const p of Te.values())p!==u&&p.join&&p.join.from===n&&p.join.probe==null&&tn(u,p.join);return u.handle},removeSource(e){const t=e&&typeof e=="object"&&e.id!==void 0?String(e.id):String(e),n=Te.get(t);return n&&n.handle.remove(),this},sources(){return[...Te.keys()]},metrics(){const e=Ne(),t=be().map((r,i)=>({index:i,label:r.label||(r.isDefault?"default":null),kind:typeof r.grid=="function"?"view":"grid",rows:r.partition.size,shown:r.keys.size,routed:r.metricRows,throughput:Lt(`route:${i}`,r.metricRows,e),backpressure:r.bp?{pending:r.bpPending,coalesced:r.bpCoalesced}:null})),n=[...Te.values()].map(r=>({id:r.id,rows:r.live.size,ingested:r.ingested,throughput:Lt(`source:${r.id}`,r.ingested,e)}));return{routes:t,sources:n,unrouted:Se,dropped:I,buffered:d.length,lag:Dn(),throughput:Lt("total",bt,e)}},on(e,t){if(typeof t!="function")return()=>{};let n=ut.get(e);return n||(n=new Set,ut.set(e,n)),n.add(t),e==="metrics"&&In(),()=>{n.delete(t),e==="metrics"&&n.size===0&&nn()}},mountDevtools(e,t={}){return ne(this,e,t)},get unrouted(){return Se},get dropped(){return I},lastSeq(){return E},checkpoint(){return new Map(m)},seenThrough(e){const t=e instanceof Map?e.entries():Object.entries(e||{});for(const[n,r]of t){const i=Number(r);if(!Number.isFinite(i))continue;const u=m.get(String(n));(u===void 0||i>u)&&m.set(String(n),i),(E===void 0||i>E)&&(E=i)}return this},persist(e={}){if(lt=!0,typeof e.key=="string"&&(vt=e.key),Number.isFinite(e.debounce)&&(Et=Number(e.debounce)),e.storage&&typeof e.storage.get=="function"&&typeof e.storage.set=="function")Fe=e.storage;else{let t=null;try{t=Cn(e)}catch{t=null}t?Fe=t:(Fe=null,P("data-router:no-indexeddb","router.persist() found no usable IndexedDB (a non-browser runtime, private mode, or blocked storage); the router runs in-memory with no durable resume. Pass { storage } to use another backend."))}return this},async restore(){if(!Fe)return!1;let e;try{e=await Fe.get(vt)}catch{return!1}return e==null?!1:Mn(e)},async flushPersist(){return Ie&&(clearTimeout(Ie),Ie=null),await It(),Xe&&await Xe,this},get persisting(){return lt&&!!Fe},buffer(e={}){return Ee=!0,Number.isFinite(e.max)?ke=Number(e.max):"max"in e&&e.max==null&&(ke=null),Number.isFinite(e.window)?Ae=Number(e.window):"window"in e&&e.window==null&&(Ae=null),ke==null&&Ae==null&&(ke=le,P("data-router:buffer-default-cap",`buffer() called with no window or max; applying a default cap of ${le} deltas so the buffer stays bounded. Pass { window } or { max } to size it.`)),l=o?"seq":"time",Gt(),this},scrubTo(e,t={}){if(!Nt("scrubTo"))return this;gt(),ae=!0;const n=t.by||l;me=pt(e,n),ht([...me.values()]),Ve=0;for(const r of d){const i=Pt(r,n);if(e!==void 0&&i!==void 0&&i>e)break;Ve=r.pos+1}return this},replay(e,t,n={}){if(!Nt("replay"))return Promise.resolve();gt(),ae=!0;const r=n.by||l;return it=r,ot=Number.isFinite(n.speed)?Number(n.speed):0,me=pt(e,r),ht([...me.values()]),Ce=d.filter(i=>{const u=Pt(i,r);return u!==void 0&&u>e&&u<=t}).slice().sort((i,u)=>i.pos-u.pos),Je=0,ze=!1,new Promise(i=>{He=i,At()})},pause(){return ze=!0,$e&&(clearTimeout($e),$e=null),this},resume(){return ze?(ze=!1,At(),this):this},live(){return Nt("live")?(gt(),ae=!1,me=null,ht([...pt(void 0,l).values()]),Ve=j,this):this},get traveling(){return ae},get buffered(){return d.length},broadcast(e={}){if(typeof BroadcastChannel!="function")return P("data-router:no-broadcastchannel","router.broadcast() needs the BroadcastChannel API, which this runtime does not provide; cross-tab mirroring is off."),this;const t=e&&typeof e.channel=="string"?e.channel:"";return t?(De&&(De.close(),De=null),De=new BroadcastChannel(t),De.onmessage=Sn,mt({t:"hello"}),this):(P("data-router:broadcast-channel","router.broadcast({ channel }) needs a string channel name; nothing was mirrored."),this)},get broadcasting(){return!!De},async query(e,t={}){if(!e||typeof e.execute!="function")return P("data-router:bad-query-source","router.query(adapter) needs an adapter with an execute(query) function (a DFQL/DuckDB adapter or a pushdown source); nothing was fetched."),this;const n=re(e.capabilities),r=t||{},i=r.filters||null,u=[];Se=0;const p=be().filter(b=>b.where),w=be().filter(b=>!b.where);for(const b of p){const A=U(i,b.where),K=X({...r,filters:A},n);let Oe=((await e.execute(K.pushed,r)).rows||[]).slice();K.residual&&K.residual.filters&&(Oe=Oe.filter(rt=>ee(K.residual.filters,rt))),Oe=Oe.filter(rt=>b.match(rt)),On(b,Oe),u.push({route:b.grid,pushedFilter:!!(K.pushed&&K.pushed.filters),residual:K.unpushed.slice()})}if(w.length){const b=X(r,n);let K=((await e.execute(b.pushed,r)).rows||[]).slice();b.residual&&b.residual.filters&&(K=K.filter(H=>ee(b.residual.filters,H))),Tn(K,w),u.push({base:!0,pushedFilter:!!(b.pushed&&b.pushed.filters),residual:b.unpushed.slice()})}St=u;for(const b of ue)Ye(b);_e();for(const b of be())Ke(b);return this},lastQueryPlan(){return St?St.map(e=>({...e})):null},destroy(){if(Le&&(clearTimeout(Le),Le=null),W&&(clearTimeout(W),W=null),Ie&&(clearTimeout(Ie),Ie=null),Fe&&typeof Fe.close=="function")try{Fe.close()}catch{}lt=!1,Fe=null,De&&(De.close(),De=null),et=!1,gt(),Ee=!1,ae=!1,me=null,d.length=0,a.clear();for(const e of ye.values())e.off();ye.clear();for(const e of _.values())e();_.clear(),fe.clear(),Te.clear(),nn(),ut.clear(),wt.clear();for(const e of Ge)e.timer&&(clearTimeout(e.timer),e.timer=null);Ge.length=0;for(const e of be())e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null);ue.length=0,B.length=0,We.clear(),S.length=0,m.clear(),Q.length=0,O=null}};return c.config&&Pe.configure(c.config),Pe}function je(c,L){if(c===L)return!0;if(!c||!L)return!1;const k=Object.keys(c),R=Object.keys(L);if(k.length!==R.length)return!1;for(const $ of k)if(c[$]!==L[$])return!1;return!0}const Me=pe});var yt=Mt("packages/modules/data-router/index.js");typeof module=="object"&&module.exports?module.exports=yt:typeof define=="function"&&define.amd?define(function(){return yt}):rn.LatticeGridDataRouter=yt})(typeof globalThis<"u"?globalThis:this);
7
7
 
8
8
  //# sourceMappingURL=data-router.min.js.map