@toclocoinc/lattice-grid 1.71.1 → 1.71.3

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 (195) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/angular/package.json +1 -1
  4. package/docs/API.html +42 -8
  5. package/docs/api/adapters.html +1 -1
  6. package/docs/api/ai.html +1 -1
  7. package/docs/api/alarms.html +1 -1
  8. package/docs/api/charts.html +39 -5
  9. package/docs/api/data-router.html +1 -1
  10. package/docs/api/gantt.html +1 -1
  11. package/docs/api/grid.html +2 -2
  12. package/docs/api/index.html +2 -2
  13. package/docs/api/kanban.html +1 -1
  14. package/docs/api/kpi.html +1 -1
  15. package/docs/api/layout.html +1 -1
  16. package/docs/api/mock-socket.html +1 -1
  17. package/docs/api/tabs.html +1 -1
  18. package/docs/api/types.html +1 -1
  19. package/docs/api-detail.html +4 -4
  20. package/docs/warnings.json +13 -2
  21. package/lattice-grid.d.ts +31 -7
  22. package/lattice-grid.esm.min.js +3 -3
  23. package/lattice-grid.min.cjs +3 -3
  24. package/lattice-grid.min.js +3 -3
  25. package/modules/ai.d.ts +1 -1
  26. package/modules/ai.esm.min.js +2 -2
  27. package/modules/ai.min.cjs +2 -2
  28. package/modules/ai.min.js +2 -2
  29. package/modules/alarms.d.ts +1 -1
  30. package/modules/alarms.esm.min.js +2 -2
  31. package/modules/alarms.min.cjs +2 -2
  32. package/modules/alarms.min.js +2 -2
  33. package/modules/angular.d.ts +1 -1
  34. package/modules/angular.esm.min.js +2 -2
  35. package/modules/angular.min.cjs +2 -2
  36. package/modules/angular.min.js +2 -2
  37. package/modules/chart-alluvial.d.ts +1 -1
  38. package/modules/chart-alluvial.esm.min.js +1 -1
  39. package/modules/chart-alluvial.min.cjs +1 -1
  40. package/modules/chart-alluvial.min.js +1 -1
  41. package/modules/chart-arc.d.ts +1 -1
  42. package/modules/chart-arc.esm.min.js +1 -1
  43. package/modules/chart-arc.min.cjs +1 -1
  44. package/modules/chart-arc.min.js +1 -1
  45. package/modules/chart-bubblemap.d.ts +1 -1
  46. package/modules/chart-bubblemap.esm.min.js +1 -1
  47. package/modules/chart-bubblemap.min.cjs +1 -1
  48. package/modules/chart-bubblemap.min.js +1 -1
  49. package/modules/chart-bump.d.ts +1 -1
  50. package/modules/chart-bump.esm.min.js +1 -1
  51. package/modules/chart-bump.min.cjs +1 -1
  52. package/modules/chart-bump.min.js +1 -1
  53. package/modules/chart-calendar.d.ts +1 -1
  54. package/modules/chart-calendar.esm.min.js +1 -1
  55. package/modules/chart-calendar.min.cjs +1 -1
  56. package/modules/chart-calendar.min.js +1 -1
  57. package/modules/chart-decomposition.d.ts +1 -1
  58. package/modules/chart-decomposition.esm.min.js +1 -1
  59. package/modules/chart-decomposition.min.cjs +1 -1
  60. package/modules/chart-decomposition.min.js +1 -1
  61. package/modules/chart-diverging.d.ts +1 -1
  62. package/modules/chart-diverging.esm.min.js +1 -1
  63. package/modules/chart-diverging.min.cjs +1 -1
  64. package/modules/chart-diverging.min.js +1 -1
  65. package/modules/chart-dumbbell.d.ts +1 -1
  66. package/modules/chart-dumbbell.esm.min.js +1 -1
  67. package/modules/chart-dumbbell.min.cjs +1 -1
  68. package/modules/chart-dumbbell.min.js +1 -1
  69. package/modules/chart-fan.d.ts +1 -1
  70. package/modules/chart-fan.esm.min.js +1 -1
  71. package/modules/chart-fan.min.cjs +1 -1
  72. package/modules/chart-fan.min.js +1 -1
  73. package/modules/chart-hexbin.d.ts +1 -1
  74. package/modules/chart-hexbin.esm.min.js +1 -1
  75. package/modules/chart-hexbin.min.cjs +1 -1
  76. package/modules/chart-hexbin.min.js +1 -1
  77. package/modules/chart-hexmap.d.ts +1 -1
  78. package/modules/chart-hexmap.esm.min.js +1 -1
  79. package/modules/chart-hexmap.min.cjs +1 -1
  80. package/modules/chart-hexmap.min.js +1 -1
  81. package/modules/chart-icicle.d.ts +1 -1
  82. package/modules/chart-icicle.esm.min.js +1 -1
  83. package/modules/chart-icicle.min.cjs +1 -1
  84. package/modules/chart-icicle.min.js +1 -1
  85. package/modules/chart-markermap.d.ts +1 -1
  86. package/modules/chart-markermap.esm.min.js +1 -1
  87. package/modules/chart-markermap.min.cjs +1 -1
  88. package/modules/chart-markermap.min.js +1 -1
  89. package/modules/chart-parallel.d.ts +1 -1
  90. package/modules/chart-parallel.esm.min.js +1 -1
  91. package/modules/chart-parallel.min.cjs +1 -1
  92. package/modules/chart-parallel.min.js +1 -1
  93. package/modules/chart-ridgeline.d.ts +1 -1
  94. package/modules/chart-ridgeline.esm.min.js +1 -1
  95. package/modules/chart-ridgeline.min.cjs +1 -1
  96. package/modules/chart-ridgeline.min.js +1 -1
  97. package/modules/chart-roc.d.ts +1 -1
  98. package/modules/chart-roc.esm.min.js +1 -1
  99. package/modules/chart-roc.min.cjs +1 -1
  100. package/modules/chart-roc.min.js +1 -1
  101. package/modules/chart-slope.d.ts +1 -1
  102. package/modules/chart-slope.esm.min.js +1 -1
  103. package/modules/chart-slope.min.cjs +1 -1
  104. package/modules/chart-slope.min.js +1 -1
  105. package/modules/chart-splom.d.ts +1 -1
  106. package/modules/chart-splom.esm.min.js +1 -1
  107. package/modules/chart-splom.min.cjs +1 -1
  108. package/modules/chart-splom.min.js +1 -1
  109. package/modules/chart-waffle.d.ts +1 -1
  110. package/modules/chart-waffle.esm.min.js +1 -1
  111. package/modules/chart-waffle.min.cjs +1 -1
  112. package/modules/chart-waffle.min.js +1 -1
  113. package/modules/charts.d.ts +1 -1
  114. package/modules/charts.esm.min.js +13 -9
  115. package/modules/charts.esm.min.js.map +2 -2
  116. package/modules/charts.min.cjs +141 -137
  117. package/modules/charts.min.js +141 -137
  118. package/modules/charts.min.js.map +2 -2
  119. package/modules/data-router.d.ts +1 -1
  120. package/modules/data-router.esm.min.js +2 -2
  121. package/modules/data-router.min.cjs +2 -2
  122. package/modules/data-router.min.js +2 -2
  123. package/modules/devtools.d.ts +1 -1
  124. package/modules/devtools.esm.min.js +1 -1
  125. package/modules/devtools.min.cjs +1 -1
  126. package/modules/devtools.min.js +1 -1
  127. package/modules/dhtmlx-compat.d.ts +1 -1
  128. package/modules/dhtmlx-compat.esm.min.js +2 -2
  129. package/modules/dhtmlx-compat.min.cjs +2 -2
  130. package/modules/dhtmlx-compat.min.js +2 -2
  131. package/modules/gantt.d.ts +1 -1
  132. package/modules/gantt.esm.min.js +2 -2
  133. package/modules/gantt.min.cjs +2 -2
  134. package/modules/gantt.min.js +2 -2
  135. package/modules/geo-europe-nuts.d.ts +1 -1
  136. package/modules/geo-europe-nuts.esm.min.js +1 -1
  137. package/modules/geo-europe-nuts.min.cjs +1 -1
  138. package/modules/geo-europe-nuts.min.js +1 -1
  139. package/modules/geo-uk.d.ts +1 -1
  140. package/modules/geo-uk.esm.min.js +1 -1
  141. package/modules/geo-uk.min.cjs +1 -1
  142. package/modules/geo-uk.min.js +1 -1
  143. package/modules/geo-us-states.d.ts +1 -1
  144. package/modules/geo-us-states.esm.min.js +1 -1
  145. package/modules/geo-us-states.min.cjs +1 -1
  146. package/modules/geo-us-states.min.js +1 -1
  147. package/modules/geo-world-110m.d.ts +1 -1
  148. package/modules/geo-world-110m.esm.min.js +1 -1
  149. package/modules/geo-world-110m.min.cjs +1 -1
  150. package/modules/geo-world-110m.min.js +1 -1
  151. package/modules/geo-world-50m.d.ts +1 -1
  152. package/modules/geo-world-50m.esm.min.js +1 -1
  153. package/modules/geo-world-50m.min.cjs +1 -1
  154. package/modules/geo-world-50m.min.js +1 -1
  155. package/modules/htmx.d.ts +1 -1
  156. package/modules/htmx.esm.min.js +3 -3
  157. package/modules/htmx.min.cjs +3 -3
  158. package/modules/htmx.min.js +3 -3
  159. package/modules/kanban.d.ts +1 -1
  160. package/modules/kanban.esm.min.js +2 -2
  161. package/modules/kanban.min.cjs +2 -2
  162. package/modules/kanban.min.js +2 -2
  163. package/modules/kpi.d.ts +1 -1
  164. package/modules/kpi.esm.min.js +2 -2
  165. package/modules/kpi.min.cjs +2 -2
  166. package/modules/kpi.min.js +2 -2
  167. package/modules/layout.d.ts +1 -1
  168. package/modules/layout.esm.min.js +2 -2
  169. package/modules/layout.min.cjs +2 -2
  170. package/modules/layout.min.js +2 -2
  171. package/modules/mock-socket.d.ts +1 -1
  172. package/modules/mock-socket.esm.min.js +1 -1
  173. package/modules/mock-socket.min.cjs +1 -1
  174. package/modules/mock-socket.min.js +1 -1
  175. package/modules/react.d.ts +1 -1
  176. package/modules/react.esm.min.js +2 -2
  177. package/modules/react.min.cjs +2 -2
  178. package/modules/react.min.js +2 -2
  179. package/modules/svelte.d.ts +1 -1
  180. package/modules/svelte.esm.min.js +2 -2
  181. package/modules/svelte.min.cjs +2 -2
  182. package/modules/svelte.min.js +2 -2
  183. package/modules/tabs.d.ts +1 -1
  184. package/modules/tabs.esm.min.js +2 -2
  185. package/modules/tabs.min.cjs +2 -2
  186. package/modules/tabs.min.js +2 -2
  187. package/modules/vue.d.ts +1 -1
  188. package/modules/vue.esm.min.js +2 -2
  189. package/modules/vue.min.cjs +2 -2
  190. package/modules/vue.min.js +2 -2
  191. package/modules/webcomponent.d.ts +1 -1
  192. package/modules/webcomponent.esm.min.js +3 -3
  193. package/modules/webcomponent.min.cjs +3 -3
  194. package/modules/webcomponent.min.js +3 -3
  195. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
1
  /*!
2
- * Lattice Grid 1.71.1, data-router module
2
+ * Lattice Grid 1.71.3, 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 It=Object.create(null),Ct=Object.create(null);function Ve(y,ge){It[y]=ge}function Wt(y){var ge=Ct[y];if(ge)return ge;var ie=Object.create(null);Ct[y]=ie;var F=It[y];if(!F)throw new Error("[lattice] missing module: "+y);return F(ie,Wt),ie}Ve("packages/core/src/internal/util.js",function(y,ge){"use strict";Object.defineProperty(y,"VERSION",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(y,"reportedWarnings",{enumerable:!0,get:function(){return A}}),Object.defineProperty(y,"warnOnce",{enumerable:!0,get:function(){return D}}),Object.defineProperty(y,"infoOnce",{enumerable:!0,get:function(){return z}}),Object.defineProperty(y,"resetWarnings",{enumerable:!0,get:function(){return W}}),Object.defineProperty(y,"fail",{enumerable:!0,get:function(){return G}}),Object.defineProperty(y,"invariant",{enumerable:!0,get:function(){return k}}),Object.defineProperty(y,"DEV",{enumerable:!0,get:function(){return x}}),Object.defineProperty(y,"isObject",{enumerable:!0,get:function(){return $}}),Object.defineProperty(y,"isFunction",{enumerable:!0,get:function(){return U}}),Object.defineProperty(y,"isNil",{enumerable:!0,get:function(){return H}}),Object.defineProperty(y,"isBlank",{enumerable:!0,get:function(){return _}}),Object.defineProperty(y,"isCtor",{enumerable:!0,get:function(){return X}}),Object.defineProperty(y,"pathGetter",{enumerable:!0,get:function(){return se}}),Object.defineProperty(y,"pathSetter",{enumerable:!0,get:function(){return We}}),Object.defineProperty(y,"getPath",{enumerable:!0,get:function(){return f}}),Object.defineProperty(y,"setPath",{enumerable:!0,get:function(){return I}}),Object.defineProperty(y,"humanise",{enumerable:!0,get:function(){return T}}),Object.defineProperty(y,"escapeHtml",{enumerable:!0,get:function(){return s}}),Object.defineProperty(y,"titleCase",{enumerable:!0,get:function(){return d}}),Object.defineProperty(y,"expand",{enumerable:!0,get:function(){return O}}),Object.defineProperty(y,"toArray",{enumerable:!0,get:function(){return S}}),Object.defineProperty(y,"merge",{enumerable:!0,get:function(){return a}}),Object.defineProperty(y,"mergeRow",{enumerable:!0,get:function(){return p}}),Object.defineProperty(y,"Lru",{enumerable:!0,get:function(){return m}}),Object.defineProperty(y,"collator",{enumerable:!0,get:function(){return v}}),Object.defineProperty(y,"defaultCompare",{enumerable:!0,get:function(){return q}}),Object.defineProperty(y,"now",{enumerable:!0,get:function(){return be}}),Object.defineProperty(y,"nextFrame",{enumerable:!0,get:function(){return re}}),Object.defineProperty(y,"cancelFrame",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(y,"frameBatched",{enumerable:!0,get:function(){return le}}),Object.defineProperty(y,"settleDebounce",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(y,"whenIdle",{enumerable:!0,get:function(){return Re}}),Object.defineProperty(y,"uid",{enumerable:!0,get:function(){return Ce}});const ie="1.71.1";async function F(){return ie}const Y="1.71.1",Z=new Set,ne=2e3;function Te(u){if(Z.add(u),Z.size>ne){const c=Z.values().next().value;c!==void 0&&Z.delete(c)}}const me=[],ke=500;function Se(u,c,g){me.push({key:u,level:c,message:g.map(R=>typeof R=="string"?R:j(R)).join(" "),at:Date.now()}),me.length>ke&&me.shift()}function j(u){if(u instanceof Error)return u.message;try{return JSON.stringify(u)}catch{return String(u)}}function A(){return me.map(u=>({...u}))}function D(u,...c){Z.has(u)||(Te(u),Se(u,"warn",c),console.warn("[lattice]",...c))}function z(u,...c){Z.has(u)||(Te(u),Se(u,"info",c),console.info("[lattice]",...c))}function W(){Z.clear(),me.length=0}function G(u,c){const g=new Error(`[lattice] ${u}`);throw c!==void 0&&(g.cause=c),g}function k(u,c){u||G(c)}const x=(()=>{try{return!(typeof process<"u"&&process.env&&process.env.NODE_ENV==="production")}catch{return!0}})();function $(u){return u!==null&&typeof u=="object"&&!Array.isArray(u)}function U(u){return typeof u=="function"}function H(u){return u==null}function _(u){return u==null||u===""}function X(u){return typeof u!="function"?!1:/^class[\s{]/.test(Function.prototype.toString.call(u))?!0:!!(u.prototype&&Object.getOwnPropertyNames(u.prototype).length>1)}const ee=new Map;function se(u){let c=ee.get(u);if(c)return c;if(!u.includes("."))c=g=>g?.[u];else{const g=u.split("."),R=g.length;c=fe=>{let ye=fe;for(let te=0;te<R;te++){if(ye==null)return;ye=ye[g[te]]}return ye}}return ee.set(u,c),c}const Oe=new Map;function We(u){let c=Oe.get(u);if(c)return c;if(!u.includes("."))c=(g,R)=>{g!=null&&(g[u]=R)};else{const g=u.split("."),R=g.length-1;c=(fe,ye)=>{let te=fe;for(let de=0;de<R;de++){if(te==null)return;const C=g[de];te[C]==null&&(te[C]={}),te=te[C]}te!=null&&(te[g[R]]=ye)}}return Oe.set(u,c),c}function f(u,c){return se(c)(u)}function I(u,c,g){We(c)(u,g)}function T(u){return u?(u.includes(".")?u.slice(u.lastIndexOf(".")+1):u).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(/^./,g=>g.toUpperCase()):""}const P={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function s(u){const c=u==null?"":String(u);return/[&<>"']/.test(c)?c.replace(/[&<>"']/g,g=>P[g]):c}function d(u){return String(u).replace(/\w\S*/g,c=>c[0].toUpperCase()+c.slice(1).toLowerCase())}function O(u,c,g){if(u!==void 0)return u===!0?{enabled:!0,...g}:u===!1?{enabled:!1}:$(u)?u:{[c]:u,enabled:!0}}function S(u){return u==null?[]:Array.isArray(u)?u:[u]}const l=Object.freeze(new Set(["__proto__","constructor","prototype"]));function a(u,c){if(!$(u))return $(c)?{...c}:c;if(!$(c))return c===void 0?u:c;const g={...u};for(const R of Object.keys(c)){if(l.has(R))continue;const fe=c[R];fe!==void 0&&(g[R]=$(fe)&&$(g[R])?a(g[R],fe):fe)}return g}function p(u,c){if(!$(u)||!$(c)||u===c)return c;const g=Object.create(Object.getPrototypeOf(u));return Object.assign(g,u,c),g}class m{#n;#e=new Map;#t;constructor(c=256,g=null){this.#n=c,this.#t=g}get size(){return this.#e.size}get max(){return this.#n}set max(c){this.#n=c,this.#r()}has(c){return this.#e.has(c)}get(c){const g=this.#e;if(!g.has(c))return;const R=g.get(c);return g.delete(c),g.set(c,R),R}peek(c){return this.#e.get(c)}set(c,g){const R=this.#e;return R.has(c)&&R.delete(c),R.set(c,g),this.#r(),g}delete(c){const g=this.#e.get(c);return this.#e.delete(c)&&this.#t&&this.#t(g,c),g}clear(){if(this.#t)for(const[c,g]of this.#e)this.#t(g,c);this.#e.clear()}keys(){return this.#e.keys()}values(){return this.#e.values()}#r(){const c=this.#e;for(;c.size>this.#n;){const g=c.keys().next().value,R=c.get(g);c.delete(g),this.#t&&this.#t(R,g)}}}const E=new Map;function v(u,c){const g=`${u||""}|${c?JSON.stringify(c):""}`;let R=E.get(g);return R||(R=new Intl.Collator(u||void 0,{numeric:!0,sensitivity:"variant",...c}),E.set(g,R)),R}function q(u,c){if(u===c)return 0;if(u==null)return 1;if(c==null)return-1;if(typeof u=="number"&&typeof c=="number")return Number.isNaN(u)?Number.isNaN(c)?0:1:Number.isNaN(c)||u<c?-1:u>c?1:0;const g=String(u),R=String(c);return g<R?-1:g>R?1:0}function be(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const ae=typeof requestAnimationFrame=="function";function re(u){return ae?requestAnimationFrame(u):setTimeout(()=>u(be()),16)}function ce(u){u!=null&&(ae?cancelAnimationFrame(u):clearTimeout(u))}function le(u){let c=null,g=null;const R=()=>{c=null;const ye=g;g=null,u(...ye||[])},fe=(...ye)=>{g=ye,c===null&&(c=re(R))};return fe.cancel=()=>{ce(c),c=null,g=null},fe.flush=()=>{c!==null&&(ce(c),R())},fe}function Pe(u,c){let g=null,R=null;const fe=()=>{if(g=null,R===null)return;const de=R;R=null,u(...de),ye()},ye=()=>{g=setTimeout(fe,c),typeof g?.unref=="function"&&g.unref()},te=(...de)=>{g===null?(u(...de),ye()):(R=de,clearTimeout(g),ye())};return te.flush=()=>{if(g!==null&&clearTimeout(g),g=null,R===null)return;const de=R;R=null,u(...de)},te.cancel=()=>{g!==null&&clearTimeout(g),g=null,R=null},te.pending=()=>g!==null||R!==null,te}function Re(u,c=50){return typeof requestIdleCallback=="function"?requestIdleCallback(u,{timeout:c}):setTimeout(()=>u({timeRemaining:()=>0,didTimeout:!0}),1)}let De=0;function Ce(u="l"){return`${u}${(++De).toString(36)}`}}),Ve("packages/core/src/source/filterwire.js",function(y,ge){"use strict";Object.defineProperty(y,"HOST_FILTER_WARN_ID",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(y,"WHERE_PAGE_RELATIVE_WARN_ID",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(y,"warnWherePageRelative",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(y,"warnHostFilterNotApplied",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(y,"WHERE_NOT_APPLIED_WARN_ID",{enumerable:!0,get:function(){return me}}),Object.defineProperty(y,"warnWhereNotApplied",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(y,"WHERE_OVER_THRESHOLD_WARN_ID",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(y,"warnWhereOverThreshold",{enumerable:!0,get:function(){return j}}),Object.defineProperty(y,"RELATIVE_TOKENS",{enumerable:!0,get:function(){return $}}),Object.defineProperty(y,"parseRelativeToken",{enumerable:!0,get:function(){return U}}),Object.defineProperty(y,"resolveRelativeRange",{enumerable:!0,get:function(){return H}}),Object.defineProperty(y,"relativeTokenOf",{enumerable:!0,get:function(){return _}}),Object.defineProperty(y,"relativeTokenHelp",{enumerable:!0,get:function(){return X}}),Object.defineProperty(y,"isResolvableRelative",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(y,"resolveRelativeCondition",{enumerable:!0,get:function(){return se}}),Object.defineProperty(y,"isGroup",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(y,"forEachCondition",{enumerable:!0,get:function(){return We}}),Object.defineProperty(y,"mapConditions",{enumerable:!0,get:function(){return f}}),Object.defineProperty(y,"normaliseFilterSet",{enumerable:!0,get:function(){return T}}),Object.defineProperty(y,"buildFilterSet",{enumerable:!0,get:function(){return P}}),Object.defineProperty(y,"wireFilters",{enumerable:!0,get:function(){return s}}),Object.defineProperty(y,"querySignature",{enumerable:!0,get:function(){return d}});const F=ge("packages/core/src/internal/util.js").warnOnce,Y="source.remote.hostFilter",Z="source.where.pageRelative";function ne(l,a){!Array.isArray(l)||!l.length||F(Z,`filters.where (${l.join(", ")}) runs over the rows the ${a} 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 Te(l){const a=(l||{}).config;!a||!a.hostFilter||F(Y,"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 me="source.where.notApplied";function ke(l,a){F(`${me}:${l}`,`filters.where("${l}") is registered but the ${a} 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 Se="source.where.overThreshold";function j(l,a,p,m){!Array.isArray(l)||!l.length||F(`${Se}:${a}`,`filters.where (${l.join(", ")}) is not applied to the ${a} pushdown source:`,p===null?"the adapter reports no row total, so the size of the matching set is unknown.":`its matching set is ${p.toLocaleString()} rows, at or past the whereRowLimit of ${m.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 A=new Map;function D(l){let a=A.get(l);return a||(a=new Intl.DateTimeFormat("en-US",{timeZone:l,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),A.set(l,a)),a}function z(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function W(l,a){const p=D(a).formatToParts(new Date(l)),m={y:1970,m:1,d:1,h:0,mi:0,s:0};for(const E of p)E.type==="year"?m.y=+E.value:E.type==="month"?m.m=+E.value:E.type==="day"?m.d=+E.value:E.type==="hour"?m.h=+E.value%24:E.type==="minute"?m.mi=+E.value:E.type==="second"&&(m.s=+E.value);return m}function G(l,a){const p=W(l,a);return Date.UTC(p.y,p.m-1,p.d,p.h,p.mi,p.s)-Math.floor(l/1e3)*1e3}function k(l,a,p,m){const E=Date.UTC(l,a-1,p),v=E-G(E,m);return E-G(v,m)}function x(l,a,p){const m=new Date(Date.UTC(l.y,l.m-1,l.d+a));return k(m.getUTCFullYear(),m.getUTCMonth()+1,m.getUTCDate(),p)}const $=Object.freeze(["today","yesterday","lastNDays","thisWeek","thisMonth","thisQuarter","thisYear","quarterToDate","yearToDate"]);function U(l,a){if(typeof l!="string")return null;const p=l.trim().toLowerCase().replace(/[\s_-]+/g,""),m=/^last(\d*|n)days?$/.exec(p);if(m){const E=m[1]==="n"?"":m[1],v=Number(E||a);return!Number.isFinite(v)||v<=0?null:{kind:"lastNDays",n:Math.floor(v)}}switch(p){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 H(l,a={}){const p=U(l,a.n);if(!p)return null;const m=a.tz||z(),E=a.now instanceof Date?a.now.getTime():typeof a.now=="number"?a.now:Date.now(),v=W(E,m),q=k(v.y,v.m,v.d,m),be=x(v,1,m);let ae=q,re=be;switch(p.kind){case"today":break;case"yesterday":ae=x(v,-1,m),re=q;break;case"lastNDays":re=a.includeToday?be:q,ae=x(v,a.includeToday?-(p.n-1):-p.n,m);break;case"thisWeek":{const ce=Number.isFinite(a.weekStartsOn)?Number(a.weekStartsOn):1,Pe=(new Date(Date.UTC(v.y,v.m-1,v.d)).getUTCDay()-ce+7)%7;ae=x(v,-Pe,m),re=x(v,-Pe+7,m);break}case"thisMonth":ae=k(v.y,v.m,1,m),re=k(v.m===12?v.y+1:v.y,v.m===12?1:v.m+1,1,m);break;case"thisQuarter":case"quarterToDate":{const ce=Math.floor((v.m-1)/3)*3+1;ae=k(v.y,ce,1,m),re=p.kind==="quarterToDate"?be:ce===10?k(v.y+1,1,1,m):k(v.y,ce+3,1,m);break}case"thisYear":case"yearToDate":ae=k(v.y,1,1,m),re=p.kind==="yearToDate"?be:k(v.y+1,1,1,m);break;default:return null}return{from:new Date(ae).toISOString(),to:new Date(re).toISOString(),bounds:"[)",tz:m,relative:p.kind==="lastNDays"?`last${p.n}Days`:p.kind,n:p.n}}function _(l){if(!l||typeof l!="object")return null;const a=l.value;if(a&&typeof a=="object"&&!Array.isArray(a)&&"relative"in a)return{token:String(a.relative),n:typeof a.n=="number"?a.n:void 0};if(l.op==="relative"&&typeof l.value=="string")return{token:l.value,n:void 0};const p=l.meta;return p&&typeof p.relative=="string"&&l.value===void 0?{token:p.relative,n:typeof p.n=="number"?p.n:void 0}:null}function X(){return`Known tokens: ${$.filter(a=>a!=="lastNDays").join(", ")}. "lastNDays" needs a count: pass "last7Days", or the value object { relative: 'lastNDays', n: 7 }.`}function ee(l){const a=_(l);return a?U(a.token,a.n)!==null:!1}function se(l,a={}){const p=_(l);if(!p)return l;const m=H(p.token,{...a,n:p.n});return m?{...l,type:l.type||"date",op:"between",value:[m.from,m.to],bounds:l.bounds||m.bounds,meta:{...l.meta||{},relative:m.relative,tz:m.tz}}:(F(`source.relative.${p.token}`,`unknown relative date token "${p.token}"; sending the condition unresolved.`,X()),l)}function Oe(l){return!!l&&typeof l=="object"&&Array.isArray(l.conditions)}function We(l,a){if(l){if(Oe(l)){for(const p of l.conditions)We(p,a);return}a(l)}}function f(l,a){if(!l)return null;if(!Oe(l))return a(l);const p=l;let m=!1;const E=[];for(const v of p.conditions){const q=f(v,a);q!==v&&(m=!0),q&&E.push(q)}return!m&&E.length===p.conditions.length?l:E.length?{...p,conditions:E}:null}function I(l){if(!l)return null;if(!Oe(l))return l;const a=l,p=[];for(const m of a.conditions){const E=I(m);E&&p.push(E)}return p.length?{op:a.op,conditions:p}:null}function T(l){const a=I(l);return a?Oe(a)&&a.op==="and"?a:{op:"and",conditions:[a]}:null}function P(l){const a=(l||[]).filter(Boolean);return a.length?{op:"and",conditions:a}:null}function s(l,a={}){const p=f(l,m=>se(m,a));return T(p)}function d(l){const a=O(l.filters??null);return JSON.stringify([a,l.sort??null,l.quick??"",l.groupBy??null,l.pivotBy??null,S(l.context)])}function O(l){if(!l)return null;if(Oe(l)){const m=l;return{op:m.op,conditions:m.conditions.map(O)}}const a=l,p=a.meta&&typeof a.meta.relative=="string"?a.meta.relative:_(a)?.token;return{col:a.col,op:a.op,bounds:a.bounds??null,caseSensitive:a.caseSensitive??!1,value:p?`rel:${p}`:a.value??null}}function S(l){if(l==null)return null;try{return JSON.parse(JSON.stringify(l))}catch{return F("source.context.unserialisable","config.context is not JSON-serialisable; cache keys ignore it."),"[unserialisable]"}}}),Ve("packages/core/src/source/aggregates.js",function(y,ge){"use strict";Object.defineProperty(y,"STAT_PUSHDOWN",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(y,"pushableAggregates",{enumerable:!0,get:function(){return F}}),Object.defineProperty(y,"fillAggregateSql",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(y,"resolveAggregatesConfig",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(y,"routeAggregate",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(y,"resolveAggregatePlan",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(y,"groupKeysPushable",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(y,"pushdownDocRows",{enumerable:!0,get:function(){return Se}});const ie=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 F(){const j=new Set;for(const[A,D]of Object.entries(ie))D.pushable&&j.add(A);return j}function Y(j,A,D){let z=j.split("%c").join(A);return D!==void 0&&(z=z.split("%w").join(D)),z}function Z(j){const A=j||{},D=A.default==="engine"||A.default==="engine-if-identical"?A.default:"client",z={};if(A.overrides&&typeof A.overrides=="object")for(const[W,G]of Object.entries(A.overrides))(G==="engine"||G==="client")&&(z[W]=G);return{default:D,overrides:z}}function ne(j,A){const D=ie[j];if(!D||!D.pushable)return"client";const z=A.overrides[j];return z==="engine"||z==="client"?z:A.default==="client"?"client":A.default==="engine-if-identical"?D.class==="identical"?"engine":"client":"engine"}function Te(j,A){const D=Z(A),z=[],W=[];for(const G of j||[]){const k=ie[G.fn],x=ne(G.fn,D),$={id:G.id,col:G.col,fn:G.fn,class:k?k.class:"fallback"};G.weight!==void 0&&($.weight=G.weight),G.params!==void 0&&($.params=G.params),x==="engine"?z.push($):($.reason=k&&!k.pushable?k.note||"the engine cannot express this stat":"client by config",W.push($))}return{engine:z,client:W,config:D}}const me=/^[A-Za-z_][A-Za-z0-9_$]*$/;function ke(j){return(j||[]).every(D=>typeof D=="string"&&me.test(D))}function Se(){return Object.entries(ie).map(([j,A])=>({stat:j,class:A.class,sql:A.sql?Y(A.sql,"col",A.twoColumn?"weight":void 0):"",note:A.note||(A.class==="identical"?"Pushes to DuckDB with the same result.":"")}))}}),Ve("packages/core/src/source/pushdown.js",function(y,ge){"use strict";Object.defineProperty(y,"NO_CAPABILITIES",{enumerable:!0,get:function(){return D}}),Object.defineProperty(y,"resolveMutate",{enumerable:!0,get:function(){return z}}),Object.defineProperty(y,"capabilitiesOf",{enumerable:!0,get:function(){return k}}),Object.defineProperty(y,"splitFilters",{enumerable:!0,get:function(){return $}}),Object.defineProperty(y,"planQuery",{enumerable:!0,get:function(){return H}}),Object.defineProperty(y,"applyResidual",{enumerable:!0,get:function(){return X}}),Object.defineProperty(y,"DEFAULT_WHERE_ROW_LIMIT",{enumerable:!0,get:function(){return We}}),Object.defineProperty(y,"createPushdownSource",{enumerable:!0,get:function(){return P}});const ie=ge("packages/core/src/internal/util.js"),F=ie.isFunction,Y=ie.warnOnce,Z=ge("packages/core/src/source/filterwire.js"),ne=Z.isGroup,Te=Z.warnWherePageRelative,me=Z.warnWhereOverThreshold,ke=ge("packages/core/src/source/aggregates.js"),Se=ke.resolveAggregatePlan,j=ke.groupKeysPushable,A=ke.STAT_PUSHDOWN,D=Object.freeze({filter:!1,operators:Object.freeze([]),sort:!1,quick:!1,range:!1,total:!1,group:!1,mutate:!1});function z(s){if(!s||typeof s!="object")return!1;const d=s.returning==="row"||s.returning==="key"?s.returning:"none";return{append:s.append===!0,update:s.update===!0,delete:s.delete===!0,returning:d}}function W(s,d){if(!s||typeof d!="string")return;if(!d.includes("."))return s[d];let O=s;for(const S of d.split(".")){if(O===null||typeof O!="object")return;O=O[S]}return O}function G(s){if(s===!0)return!0;if(!s||typeof s!="object")return!1;const d=s;return d.enabled===!1?!1:d.enabled===!0||F(d.commit)}function k(s){const d={...D,...s||{}};return d.operators=new Set(d.operators||[]),d.mutate=z(d.mutate),d}function x(s,d){return!s||!s.op||!d.operators.size?!1:d.operators.has(s.op)}function $(s,d){if(!s)return{pushed:null,residual:null};if(!d.filter)return{pushed:null,residual:s};if(d.filter==="term"){if(ne(s)){const a=s.conditions||[];if(String(s.op)!=="and")return{pushed:null,residual:s};const p=a.findIndex(E=>!ne(E)&&x(E,d));if(p<0)return{pushed:null,residual:s};const m=a.filter((E,v)=>v!==p);return{pushed:a[p],residual:m.length?{op:"and",conditions:m}:null}}return x(s,d)?{pushed:s,residual:null}:{pushed:null,residual:s}}if(!ne(s))return x(s,d)?{pushed:s,residual:null}:{pushed:null,residual:s};if(String(s.op)!=="and")return(s.conditions||[]).every(p=>ne(p)?$(p,d).residual===null:x(p,d))?{pushed:s,residual:null}:{pushed:null,residual:s};const O=[],S=[];for(const a of s.conditions||[]){if(ne(a)){if(d.filter==="flat"){S.push(a);continue}const p=$(a,d);p.pushed&&O.push(p.pushed),p.residual&&S.push(p.residual);continue}(x(a,d)?O:S).push(a)}const l=a=>a.length===0?null:a.length===1?a[0]:{op:"and",conditions:a};return{pushed:l(O),residual:l(S)}}function U(s,d,O,S,l,a,p){const m=Array.isArray(s.groupBy)?s.groupBy:[],E=Array.isArray(s.groupPath)?s.groupPath:[],v=Array.isArray(s.groupValues)?s.groupValues:null;return d.group?j(m)?O.residual?"the filter did not fully push, so the engine would group a superset of the matching rows":S?l?a?"a host `where` predicate can only run in the browser, over rows the engine grouped":p?"fullDataset holds the whole matching set, so the grid groups it itself":!v||v.length!==E.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 H(s,d,O=!1){const S=$(s.filters||null,d),l=[];S.residual&&l.push("filter");const a=s.sort||[],p=a.length===0||d.sort==="multi"&&a.length>=1||d.sort==="single"&&a.length===1;!p&&a.length&&l.push("sort");const m=s.quick?String(s.quick):"",E=!m||!!d.quick;E||l.push("quick");const v=s.where&&s.where.active?s.where:null;v&&l.push("where");const q={filters:S.residual,sort:p?null:a,quick:E?"":m,where:v},be=!!O,ae=Array.isArray(s.groupBy)&&s.groupBy.length>0,re=ae?U(s,d,S,p,E,v,be):"",ce=ae&&re==="";ae&&!ce&&l.push("group");const le=ce&&Array.isArray(s.groupValues)?s.groupValues.length:0,Pe=ce?!1:be||!!(q.filters||q.sort||q.quick||q.where)||!d.range;return{pushed:{...s,filters:S.pushed,sort:p?a:[],quick:E?m:"",range:Pe?null:s.range},residual:q,needsAll:Pe,unpushed:l,full:be,grouped:ce,groupLevel:le,groupReason:re}}function _(s){const d=Array.isArray(s.totals)?s.totals:[],O=s.totalFns&&typeof s.totalFns=="object"?s.totalFns:{},S=[],l=[];for(const a of d){const p=String(a),m=typeof O[p]=="string"?O[p]:null,E=m?A[m]:null;m?!E||!E.pushable||!E.sql?l.push({id:p,fn:m,class:E?E.class:"fallback",reason:E&&E.note?E.note:`the pushdown map cannot express "${m}"`}):E.twoColumn?l.push({id:p,fn:m,class:E.class,reason:`"${m}" reduces two columns, and a grouped request carries no weight column`}):S.push({id:p,col:p,fn:m,class:E.class}):l.push({id:p,fn:null,class:"fallback",reason:"the column totals with a host function, so there is no named statistic to push"})}return{engine:S,client:l}}function X(s,d,O){if(!d)return s;let S=s;if(d.filters&&F(O.evaluateFilters)){const l={count:S.length,handle:m=>({id:m,get:E=>W(S[E],m)})},a=O.evaluateFilters(d.filters,l),p=[];for(let m=0;m<S.length;m++)a[m]&&p.push(S[m]);S=p}if(d.where&&d.where.active&&(d.whole||Te(d.where.names,"pushdown"),S=S.filter(l=>d.where.passes(l))),d.quick){const l=d.quick.toLowerCase();S=S.filter(a=>{if(!a||typeof a!="object")return!1;for(const p of Object.values(a))if(p!=null&&String(p).toLowerCase().includes(l))return!0;return!1})}if(d.sort&&d.sort.length&&F(O.sortMulti)){const l=[...new Set(d.sort.map(E=>E.col))],a=S,p=l.map(E=>({id:E,get:v=>W(a[v],E)})),m=O.sortMulti(p,d.sort.map(E=>({col:E.col,dir:E.dir})),Uint32Array.from({length:S.length},(E,v)=>v),{});S=Array.from(m,E=>a[E])}return S}function ee(s){return JSON.stringify({filters:s.filters||null,sort:s.sort||[],quick:s.quick||"",groupBy:s.groupBy||[],groupPath:s.groupPath||[],context:s.context??null})}function se(s){if(!s||typeof s!="object")return 16;let d="";try{d=JSON.stringify(s)}catch{return 200}return d.length*2+64}function Oe(s){const d=s||{};return{enabled:!!d.enabled,maxRows:Number.isFinite(d.maxRows)?d.maxRows:1e6,maxBytesEstimate:Number.isFinite(d.maxBytesEstimate)?d.maxBytesEstimate:512*1024*1024}}const We=5e4;function f(s){return Number.isFinite(s)&&s>=0?s:We}function I(s){return!!s&&F(s.then)}async function T(s){if(!s||s.total!==void 0||!I(s.pendingTotal))return s;const d=await s.pendingTotal,{pendingTotal:O,...S}=s;return typeof d=="number"?{...S,total:d}:S}function P(s={}){const d=s.adapter;if(!d||!F(d.execute))return Y("source.pushdown.adapter","createPushdownSource needs an `adapter` with an `execute(query)` function."),{...s,mode:"remote",fetch:async()=>({rows:[],total:0})};const O=k(d.capabilities),S=d.name||"adapter",l=Oe(s.fullDataset),a=!!s.allowPartialResults,p=f(s.whereRowLimit);let m=null;const E=s.aggregates;let v=null,q=null,be=null,ae=null,re=null,ce,le=null,Pe=0,Re=null;const De=()=>!l.enabled||!v?null:(Re!==v.key&&(Pe++,Re=v.key),{rows:v.rows,version:Pe}),Ce=async C=>{const J=C.where&&C.where.active?C.where:null;if(!J)return{request:C,probe:null};const{where:L,...oe}=C,ue=H(oe,O,l.enabled);if(ue.needsAll)return{request:C,probe:null};const V=ee(ue.pushed);let Ee=null;return(!m||m.key!==V)&&(O.total?(Ee=await T(await d.execute(ue.pushed,C)),m={key:V,size:Ee&&typeof Ee.total=="number"?Ee.total:null}):m={key:V,size:null}),m.size!==null&&m.size<p?{request:C,probe:null}:(me(J.names,S,m.size,p),{request:oe,probe:Ee})},u=async(C,J)=>{le=null;const L=_(C.pushed);be={engine:L.engine,client:L.client,groupBy:C.pushed.groupBy},L.client.length&&Y(`source.pushdown.group.totals.${S}.${L.client.map(V=>V.id).join(".")}`,`the ${S} adapter cannot compute the group subtotal for ${L.client.map(V=>`"${V.id}" (${V.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 oe=await d.executeGroupLevel(C.pushed,L.engine,J)||{};let ue=oe.rows||[];return!O.range&&J.range&&(ue=ue.slice(J.range.start,J.range.end)),typeof oe.matchCount=="number"&&(ae=oe.matchCount,re=oe.grand?{totals:oe.grand,leafCount:oe.matchCount}:null,ce===void 0&&F(d.unfilteredCount)&&(ce=null,Promise.resolve(d.unfilteredCount()).then(V=>{ce=typeof V=="number"?V:null}).catch(V=>{Y(`source.pushdown.group.unfiltered.${S}`,`the ${S} adapter could not count the unfiltered set (${V&&V.message?V.message:V}), so "N of M" falls back to the display count for its denominator.`)}))),oe.total===void 0?{rows:ue}:{rows:ue,total:oe.total}},c=(C,J)=>{const L={key:J,state:"pending",value:null};return le=L,C.then(oe=>(le===L&&(le={key:J,state:"settled",value:typeof oe=="number"?oe:null}),oe),oe=>{throw le===L&&(le={key:J,state:"failed",value:null}),oe})},g=async C=>{const J=await Ce(C);let L=H(J.request,O,l.enabled);if(L.grouped&&!F(d.executeGroupLevel)&&(Y(`source.pushdown.group.method.${S}`,`the ${S} 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.`),L=H(J.request,{...O,group:!1},l.enabled)),q=L,L.grouped)return u(L,C);if(L.groupReason&&Y(`source.pushdown.group.${S}.${L.groupReason}`,`the ${S} adapter was not asked to group this query because ${L.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.`),!L.needsAll){const K=J.probe||await d.execute(L.pushed,C),Q=K.rows||[];return I(K.pendingTotal)&&K.total===void 0?{rows:Q,pendingTotal:c(K.pendingTotal,ee(L.pushed))}:(le=null,!O.total&&K.total===void 0?{rows:Q}:{rows:Q,total:K.total??Q.length})}L.unpushed.length&&Y(`source.pushdown.residual.${S}.${L.unpushed.join(".")}`,`the ${S} adapter cannot push ${L.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 oe=ee(L.pushed);if(!v||v.key!==oe){const K=await T(await d.execute(L.pushed,C));le=null;const Q=K.rows||[];if(L.full){const pe=typeof K.total=="number"?Math.max(K.total,Q.length):Q.length;if(pe>l.maxRows)throw new Error(`[lattice] fullDataset refused: the ${S} adapter's matching set is ${pe.toLocaleString()} rows, past the configured maxRows of ${l.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 we=Q.length*se(Q[0]);if(we>l.maxBytesEstimate)throw new Error(`[lattice] fullDataset refused: the ${S} adapter's matching set is an estimated ${Math.round(we/(1024*1024)).toLocaleString()} MB across ${Q.length.toLocaleString()} rows, past the configured maxBytesEstimate of ${Math.round(l.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 K.total=="number"&&Q.length<K.total){const pe=!!(L.residual.filters||L.residual.quick||L.residual.sort&&L.residual.sort.length);if(pe&&!a)throw new Error(`[lattice] the ${S} adapter returned ${Q.length} of ${K.total} matching rows when asked for the whole result, and the query has residual ${L.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.`);pe?Y(`source.pushdown.partial.residual.${S}`,`the ${S} adapter returned ${Q.length} of ${K.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.`):Y(`source.pushdown.partial.${S}`,`the ${S} adapter returned ${Q.length} of ${K.total} matching rows when asked for the whole result. The adapter must follow the engine's own paging before returning.`)}v={key:oe,rows:Q,total:typeof K.total=="number"?K.total:null}}let ue=L;if(L.residual.where){const K=v.total??v.rows.length;if(K>=p){me(L.residual.where.names,S,K,p);const{where:Q,...pe}=J.request;ue=H(pe,O,l.enabled),q=ue}}const V=v.total!==null&&v.rows.length>=v.total,Ee=X(v.rows,{...ue.residual,whole:V},s.compute||{}),He=C.range?C.range.start:0,Ne=C.range?C.range.end:Ee.length;return{rows:Ee.slice(He,Ne),total:Ee.length}},R=async(C,J)=>{const L=H(C,O,l.enabled);q=L;const oe=Se(J,E),ue=Array.isArray(C.groupBy)?C.groupBy:[],V=ue.length>0,Ee=!L.residual.filters,He=!V||j(ue);let Ne=oe.engine,K=oe.client;const Q=$e=>{K=[...Ne.map(Ge=>({...Ge,reason:$e})),...K],Ne=[]};Ne.length&&!Ee?Q("residual filter forces all-client (no mixed provenance)"):Ne.length&&!He&&Q("a grouping key the engine cannot form forces all-client (no mixed provenance)");let pe={},we;return Ne.length&&(F(V?d.executeGroupedAggregates:d.executeAggregates)?V?we=await d.executeGroupedAggregates(L.pushed,ue,Ne)||[]:pe=await d.executeAggregates(L.pushed,Ne)||{}:(Y(`source.pushdown.aggregates.${S}${V?".grouped":""}`,`the ${S} adapter cannot compute ${V?"grouped ":""}aggregates, so every requested statistic is computed client-side. Correct, and slower than it needs to be.`),Q(`adapter cannot compute ${V?"grouped ":""}aggregates`))),be={engine:Ne,client:K,...V?{groupBy:ue}:{}},{values:pe,engine:Ne,client:K,...we!==void 0?{groups:we}:{}}},fe=G(s.edit),ye=s.edit&&typeof s.edit=="object"&&F(s.edit.commit);let te=s.edit;if(fe&&!ye)if(O.mutate&&O.mutate.update){const C=J=>{if(!O.mutate||!O.mutate.update)throw new Error(`[lattice] the ${S} 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 L={kind:"update",key:String(J.key),patch:{[J.colId]:J.value}};return d.mutate(L,J.request||{})};te={...s.edit===!0?{}:s.edit,commit:C}}else Y(`source.pushdown.readonly.${S}`,`edit is enabled but the ${S} adapter declares mutate: ${O.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 de=fe&&O.mutate&&(O.mutate.append||O.mutate.delete)?{append:O.mutate.append===!0,remove:O.mutate.delete===!0,returning:O.mutate.returning,mutate:(C,J)=>d.mutate(C,J||{})}:null;return{...s,edit:te,rowMutate:de,mode:"remote",fetch:g,aggregate:R,lastPlan:()=>q?{...q,...be?{aggregates:be}:{},...le?{total:{deferred:!0,state:le.state,value:le.value}}:{}}:null,fullFrame:De,counts:()=>({match:ae,total:ce??null,pending:!!le&&le.state==="pending"}),grandTotals:()=>re}}}),Ve("packages/core/src/model/rowkey.js",function(y,ge){"use strict";Object.defineProperty(y,"KEY_DEPENDENT_FEATURES",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(y,"compositeKey",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(y,"createRowKey",{enumerable:!0,get:function(){return j}}),Object.defineProperty(y,"warnMissingKeys",{enumerable:!0,get:function(){return z}}),Object.defineProperty(y,"groupPathKey",{enumerable:!0,get:function(){return W}}),Object.defineProperty(y,"splitPathKey",{enumerable:!0,get:function(){return G}});const ie=ge("packages/core/src/internal/util.js"),F=ie.warnOnce,Y=ie.pathGetter,Z=ie.isFunction,ne=ie.isBlank,Te=["changes (rows.apply / rows.queue)","streaming dedupe","selection persistence","remote reload","cell comments"],me="";function ke(k){if(k===null)return"\0n";if(k===void 0)return"\0u";const x=typeof k;if(x==="string")return k;if(x==="number"||x==="bigint"||x==="boolean")return String(k);if(k instanceof Date)return`\0d${k.getTime()}`;try{return`\0o${JSON.stringify(k)}`}catch{return"\0o?"}}function Se(k){if(k.length===1)return ke(k[0]);let x="";for(let $=0;$<k.length;$++)$&&(x+=me),x+=ke(k[$]);return x}function j(k,x={}){const $=x.warn!==!1;if(Z(k)){const U=k;return{stable:!0,fields:[],disabled:[],key(H,_){try{const X=U(H);return Array.isArray(X)?Se(X):ke(X)}catch(X){return F("rowKey.throw","rowKey function threw; falling back to index identity for the affected rows.",X),`#${_??-1}`}},keyEmpty(H){try{const _=U(H);return Array.isArray(_)?_.length===0||_.some(ne):ne(_)}catch{return!1}},missingFields(){return[]}}}if(Array.isArray(k)&&k.length>0){const U=k.filter(X=>typeof X=="string"),H=U.map(X=>Y(X)),_=H.length;return{stable:!0,fields:U,disabled:[],key(X){const ee=new Array(_);for(let se=0;se<_;se++)ee[se]=H[se](X);return Se(ee)},keyEmpty(X){for(let ee=0;ee<_;ee++)if(ne(H[ee](X)))return!0;return!1},missingFields(X){const ee=[];for(let se=0;se<_;se++)ne(H[se](X))&&ee.push(U[se]);return ee}}}if(typeof k=="string"&&k.length>0){const U=Y(k);return{stable:!0,fields:[k],disabled:[],key(H){return ke(U(H))},keyEmpty(H){return ne(U(H))},missingFields(H){return ne(U(H))?[k]:[]}}}return $&&F("rowKey.missing",`no rowKey configured, so rows are identified by object identity. This disables: ${Te.join(", ")}. Set rowKey to a field name, an array of field names, or a function.`),{stable:!1,fields:[],disabled:Te.slice(),key(U,H){if(U===null||typeof U!="object")return`#${H??0}:${String(U)}`;let _=A.get(U);return _===void 0&&(_=`#${D++}`,A.set(U,_)),_}}}const A=new WeakMap;let D=0;function z(k,x){if(!k||k.stable===!1||!Z(k.keyEmpty)||!Array.isArray(x)||x.length===0)return;let $=0,U=null,H;for(let se=0;se<x.length;se++){const Oe=x[se];k.keyEmpty(Oe)&&($++,U===null&&(U=Z(k.missingFields)?k.missingFields(Oe):[],H=Oe))}if($===0)return;const _=k.fields.length?k.fields.join(","):"(function)",X=U&&U.length?U.join(", "):k.fields.length?k.fields.join(", "):"the rowKey function",ee=H!==null&&typeof H=="object"?Object.keys(H).join(", ")||"(no fields)":String(H);F(`rowKey.emptyValue:${_}`,`rowKey ${X} is missing on ${$} of ${x.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 W(k){return Se(k)}function G(k){return k.split(me)}}),Ve("packages/modules/data-router/devtools.js",function(y,ge){"use strict";Object.defineProperty(y,"mountRouterDevtools",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(y,"default",{enumerable:!0,get:function(){return Se}});const F=ge("packages/core/src/internal/util.js").warnOnce,Y="lat-router-devtools";function Z(j,A,D){const z=j.createElement(A);return z.textContent=D==null?"—":String(D),z}function ne(j){return Number.isFinite(j)?`${Math.round(j*10)/10}/s`:"—"}function Te(j,A,D,z){const W=j.createElement("section");W.className=`${Y}-section`;const G=j.createElement("h4");G.textContent=A,W.appendChild(G);const k=j.createElement("table"),x=j.createElement("tr");for(const $ of D)x.appendChild(Z(j,"th",$));k.appendChild(x);for(const $ of z){const U=j.createElement("tr");for(const H of $)U.appendChild(Z(j,"td",H));k.appendChild(U)}return W.appendChild(k),W}function me(j,A,D){A.textContent="";const z=Te(j,"Router",["metric","value"],[["throughput",ne(D.throughput)],["unrouted",D.unrouted],["dropped (duplicate)",D.dropped],["buffer depth",D.buffered],["lag (deltas behind)",D.lag]]);A.appendChild(z),A.appendChild(Te(j,"Routes",["#","label","kind","rows","shown","rows/sec"],D.routes.map(W=>[W.index,W.label,W.kind,W.rows,W.shown,ne(W.throughput)]))),D.sources.length&&A.appendChild(Te(j,"Sources",["id","rows","ingested","rows/sec"],D.sources.map(W=>[W.id,W.rows,W.ingested,ne(W.throughput)])))}function ke(j,A,D={}){const z=A&&A.ownerDocument||(typeof document<"u"?document:null);if(!j||typeof j.metrics!="function"||typeof j.on!="function"||!A||!z)return F("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 W=z.createElement("div");W.className=Y,A.appendChild(W);const G=()=>me(z,W,j.metrics());G();const k=j.on("metrics",()=>G());return{refresh:G,destroy(){k(),W.parentNode&&W.parentNode.removeChild(W)}}}const Se=ke}),Ve("packages/modules/data-router/index.js",function(y,ge){"use strict";Object.defineProperty(y,"createDataRouter",{enumerable:!0,get:function(){return se}}),Object.defineProperty(y,"default",{enumerable:!0,get:function(){return We}});const F=ge("packages/core/src/internal/util.js").warnOnce,Y=ge("packages/core/src/source/pushdown.js"),Z=Y.planQuery,ne=Y.capabilitiesOf,me=ge("packages/core/src/model/rowkey.js").compositeKey,Se=ge("packages/modules/data-router/devtools.js").mountRouterDevtools;function j(f,I){return typeof f=="function"?f:typeof f=="string"?T=>T[f]:I}function A(f){return Array.isArray(f)?"array":f===null?"null":typeof f}function D(f,I){if(f===void 0||typeof f=="string"&&f.length>0)return f;if(typeof f=="function")return T=>{const P=f(T);if(typeof P=="string"||typeof P=="number"&&Number.isFinite(P))return P;throw new Error(`lattice-data-router: rowKey function must return a string or number; got ${A(P)}.`)};throw new Error(`lattice-data-router: rowKey must be a property name or a function; composite keys are not supported on ${I}.`)}function z(f){if(typeof f=="function")return f;if(f&&typeof f=="object"&&typeof f.key=="string"){const I=f.dir==="desc"?-1:1,{key:T}=f;return(P,s)=>{const d=P?P[T]:void 0,O=s?s[T]:void 0;return d<O?-1*I:d>O?1*I:0}}return null}function W(f){if(!f||typeof f!="object")return null;let I=0;Number.isFinite(f.minInterval)&&f.minInterval>0?I=Number(f.minInterval):Number.isFinite(f.maxHz)&&f.maxHz>0&&(I=1e3/Number(f.maxHz));const T=Number.isFinite(f.sample)&&f.sample>1?Math.floor(Number(f.sample)):1,P=Number.isFinite(f.maxLag)&&f.maxLag>=0?Math.floor(Number(f.maxLag)):null;return I===0&&T===1&&P===null?null:{minInterval:I,sample:T,maxLag:P}}let G=0;function k(){return G+=1,`r${G}`}function x(f){const T=(Array.isArray(f)?f:[f]).map(P=>({name:typeof P=="string"?P:null,get:j(P,()=>{})}));return P=>{const s={},d=[];for(const O of T){const S=O.get(P);d.push(S),O.name&&(s[O.name]=S)}return{key:me(d),fields:s}}}function $(f,I){if(typeof f=="function")return f(I);if(f&&typeof f=="object"){const{op:T,field:P}=f;if(T==="count")return I.length;const s=P!=null?I.map(d=>Number(d[P])).filter(d=>Number.isFinite(d)):[];if(T==="sum")return s.reduce((d,O)=>d+O,0);if(T==="avg")return s.length?s.reduce((d,O)=>d+O,0)/s.length:0;if(T==="min")return s.length?Math.min(...s):void 0;if(T==="max")return s.length?Math.max(...s):void 0}}function U(f){return f&&typeof f=="object"&&typeof f.from=="string"&&typeof f.to=="string"?{from:f.to,to:f.from}:(F("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."),f)}function H(f,I){return f?I?{op:"and",conditions:[f,I]}:f:I||null}const _=Object.freeze(["eq","ne","lt","lte","gt","gte","between","notBetween","in","notIn","contains","notContains","startsWith","endsWith","blank","notBlank"]);function X(f,I){const T=I?I[f.col]:void 0,P=f.value,s=d=>f.caseSensitive?String(d):String(d).toLowerCase();switch(f.op){case"eq":return T===P;case"ne":return T!==P;case"lt":return T<P;case"lte":return T<=P;case"gt":return T>P;case"gte":return T>=P;case"between":return Array.isArray(P)&&T>=P[0]&&T<=P[1];case"notBetween":return!(Array.isArray(P)&&T>=P[0]&&T<=P[1]);case"in":return Array.isArray(P)&&P.includes(T);case"notIn":return!(Array.isArray(P)&&P.includes(T));case"contains":return T!=null&&s(T).includes(s(P));case"notContains":return T==null||!s(T).includes(s(P));case"startsWith":return T!=null&&s(T).startsWith(s(P));case"endsWith":return T!=null&&s(T).endsWith(s(P));case"blank":return T==null||T==="";case"notBlank":return!(T==null||T==="");default:throw new Error(`[lattice] query() cannot evaluate the residual filter operator "${String(f.op)}" on column "${String(f.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: ${_.join(", ")}.`)}}function ee(f,I){return f?Array.isArray(f.conditions)?f.op==="or"?f.conditions.some(T=>ee(T,I)):f.op==="not"?!f.conditions.every(T=>ee(T,I)):f.conditions.every(T=>ee(T,I)):X(f,I):!0}function se(f={}){const I=j(f.key,()=>{}),T=j(D(f.rowKey,"routes"),e=>e.rowKey),P=!!f.overlap,s=typeof f.onUnrouted=="function"?f.onUnrouted:null,d=Number.isFinite(f.selectionDebounce)?Number(f.selectionDebounce):16,O=typeof f.onWrite=="function"?f.onWrite:null,S=typeof f.onConflict=="function"?f.onConflict:null,l=f.seq!=null?j(f.seq,()=>{}):null,a=l?f.dedupe!==!1:!1,p=T;let m=null;typeof f.batch=="number"?m=f.batch:f.batch&&Number.isFinite(f.batch.intervalMs)&&(m=Number(f.batch.intervalMs));const E=m!==null||!!f.coalesce,v=new Map;let q,be=0;const ae=[];let re=null;const ce=f.time!=null?j(f.time,()=>{}):null,le=typeof f.now=="function"?f.now:Date.now,Pe=1e4;let Re=!1,De=null,Ce=null,u="time",c=new Map;const g=[];let R=0,fe,ye,te=!1,de=null,C=[],J=0,L=0,oe="time",ue=!1,V=null,Ee=null;const He=e=>{if(e&&Number.isFinite(e.seq))return e.seq;if(l&&e&&e.row){const t=l(e.row);return Number.isFinite(t)?t:void 0}},Ne=e=>{if(e&&Number.isFinite(e.t))return e.t;if(ce&&e&&e.row){const t=ce(e.row);if(Number.isFinite(t))return t}return le()},K=[];let Q=null;const pe=[],we=[],$e=new Map,Ge=new Set;let Be=null,xe=0;const _e=new Map,ot=new Set,Ye=typeof f.rowKey=="string"?f.rowKey:"rowKey",Le=new Map;let $t=0;const Mt=new Map,Me=(e,t)=>{Mt.set(e,(Mt.get(e)||0)+t)};let mt=0;const yt=new Map,it=new Map;let Ke=null;const qt=Number.isFinite(f.metricsInterval)?Number(f.metricsInterval):1e3;let ze=0,Ae=null,bt="lattice-router",wt=250,Ie=null,Xe=null,st=!1,vt=!1,Fe=null,et=!1,Et=null;const Ue=[],he=()=>Q?[...K,Q]:K,Je=e=>he().find(t=>t.grid===e)||null,lt=e=>{const t=[];for(const n of K)if(n.match(e)&&(t.push(n),!P))break;return t.length?t:Q?[Q]:[]},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(i=>i&&i.operation==="remove");if(!r.length)return;const o=e.label||`route ${e.routeId}`;F(`data-router:remove-rejected:${e.routeId}`,`route "${o}" 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.`)},ln=(e,t)=>{for(const n of pe)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},qe=e=>{const t=[];for(const h of e.partition.values())e.filter&&!e.filter(h)||ln(e,h)&&t.push(h);let n;if(e.rollup){const h=new Map;for(const b of t){const{key:N,fields:B}=e.rollup.group(b);let M=h.get(N);M||(M={key:N,fields:B,rows:[]},h.set(N,M)),M.rows.push(b)}let w=[];for(const b of h.values()){const N={...b.fields};for(const[B,M]of e.rollup.specs)N[B]=$(M,b.rows);w.push({gkey:b.key,row:N})}e.sort&&w.sort((b,N)=>e.sort(b.row,N.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 h=t;e.sort&&(h=h.slice().sort(e.sort)),n=new Map;for(const w of h)n.set(me([e.keyOf(w)]),e.transform?e.transform(w):w)}const r=[],o=[],i=[];for(const[h,w]of n)e.keys.has(h)?Oe(e.keys.get(h),w)||o.push(w):r.push(w);for(const h of e.keys.keys())n.has(h)||i.push(h);return e.keys=n,on(e,{add:r,update:o,remove:i})},ut=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),qe(e),e.bpPending=0,e.bpLastFlush=le()},un=(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,ut(e)},n),e.bpTimer&&typeof e.bpTimer.unref=="function"&&e.bpTimer.unref()},an=(e,t)=>{if(!e.bp){qe(e);return}e.bpPending+=t,e.bpCoalesced+=t;const n=e.bp;if(n.maxLag!=null&&e.bpPending<=n.maxLag&&!e.bpTimer){ut(e);return}const r=le(),o=r-e.bpLastFlush>=n.minInterval,i=e.bpPending>=n.sample;if(o&&i){ut(e);return}un(e,r)},cn=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),e.bpPending=0,e.bpLastFlush=le()},kt=(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,o=new Set(t.map(i=>i&&i[n]));return i=>o.has(i&&i[r])}return null},Ht=e=>{const t=Je(e),n=e&&e.selection,r=n&&typeof n.keys=="function"?n.keys():[];return!r.length||!t?[]:r.map(o=>t.partition.get(String(o))).filter(o=>o!==void 0)},Ze=e=>{const t=Ht(e.from);e.predicate=t.length?kt(e.relation,t):null},tt=()=>{const e=new Set;for(const t of we)e.add(t.from),e.add(t.to);return e},Qe=()=>{for(const i of he())i.graphPreds=null;if(!we.length)return;const e=tt(),t=new Map;for(const i of e){const h=Ht(i);h.length&&t.set(i,h)}const n=new Map(t);let r=!0,o=(e.size+1)*2;for(;r&&o-- >0;){r=!1;for(const i of e){if(t.has(i))continue;const h=we.filter(M=>M.to===i&&n.has(M.from));if(!h.length)continue;const w=Je(i);if(!w)continue;const b=h.map(M=>kt(M.rel,n.get(M.from))).filter(Boolean),N=[];for(const M of w.partition.values())b.every(ve=>ve(M))&&N.push(M);const B=n.get(i);if(!B||B.length!==N.length)n.set(i,N),r=!0;else{const M=new Set(B);N.some(ve=>!M.has(ve))&&(n.set(i,N),r=!0)}}}for(const i of we){if(!n.has(i.from))continue;const h=kt(i.rel,n.get(i.from));if(!h)continue;const w=Je(i.to);w&&(w.graphPreds||(w.graphPreds=[])).push(h)}},Bt=e=>{const t=$e.get(e);if(t){t.count+=1;return}const n=e&&typeof e.on=="function"?e.on("selection:changed",()=>fn(e)):()=>{};$e.set(e,{off:n,count:1})},St=()=>{Be&&(clearTimeout(Be),Be=null);const e=Ge;if(!e.size)return;const t=new Set;for(const n of pe)e.has(n.from)&&(Ze(n),t.add(n.to));if(Ge.clear(),we.length){Qe();for(const n of tt())t.add(n)}for(const n of t){const r=Je(n);r&&qe(r)}},fn=e=>{if(Ge.add(e),d<=0){St();return}Be||(Be=setTimeout(St,d))},xt=e=>{const t=$e.get(e);t&&(t.count-=1,t.count<=0&&(t.off(),$e.delete(e)))},dn=e=>typeof e=="function"?t=>e(t):e&&e.rows&&typeof e.rows.apply=="function"?t=>e.rows.apply(t):(F("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."),()=>{}),Tt=(e,t,n)=>({grid:e,routeId:k(),sink:dn(e),match:t,keyOf:j(D(n.rowKey,"routes"),T),partition:new Map,keys:new Map,transform:typeof n.transform=="function"?n.transform:null,filter:typeof n.filter=="function"?n.filter:null,sort:z(n.sort),rollup:n.rollup&&n.rollup.groupBy!=null?{group:x(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:W(n.backpressure),bpPending:0,bpTimer:null,bpLastFlush:-1/0,bpCoalesced:0}),Kt=e=>{if(!P){for(const t of K)if(t.hasPartValue&&t.partValue===e){F(`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},at=(e,t)=>{const n=e.grid;if(!n||!n.edit||typeof n.edit.setCells!="function")return;const r=zt(t.key,t.colId);ot.add(r);try{n.edit.setCells([{key:t.key,colId:t.colId,value:t.before}],"cell")}finally{ot.delete(r)}Me("writeReverted",1)},Ut=e=>{e&&je.apply([{op:"upsert",row:e}])},Vt=(e,t,n)=>{const r=n&&typeof n=="object"?n:null,o=r&&r.conflict!==void 0?r.conflict:null;if(o){const i=e.onConflict||S;if(i)try{i(t,{serverRow:o})}catch{}Me("writeConflicted",1),Ut(r&&r.row?r.row:t.row);return}if(n===!1||r&&r.ok===!1){Me("writeRejected",1),at(e,t);return}Me("writeAccepted",1),Ut(r&&r.row?r.row:t.row)},hn=e=>{const t=String(e);for(const n of Le.values())if(n.live.has(t))return n.handle;return null},gn=(e,t)=>{if(!t||t.key===void 0||t.colId===void 0||ot.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(Me("writeRouted",1),e.readonly){F("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."),at(e,r);return}const o=e.onWrite||O;if(!o){F("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 i;try{i=o(r,{route:e.grid,source:hn(r.key)})}catch{at(e,r),Me("writeRejected",1);return}i&&typeof i.then=="function"?i.then(h=>Vt(e,r,h),()=>{at(e,r),Me("writeRejected",1)}):Vt(e,r,i)},mn=e=>{const t=e.grid;if(!t||typeof t.on!="function"||!t.edit||typeof t.edit.setCells!="function"){F("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(_e.has(t))return;const n=t.on("cell:changed",r=>gn(e,r));_e.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},ct=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},Ot=(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 o=String(e.keyOf(r));if(n.op==="delete"){e.partition.delete(o);continue}e.match(r)?e.partition.set(o,r):e.partition.delete(o)}},nt=()=>{const e=new Map;for(const t of he())for(const n of t.partition.values())e.set(String(p(n)),n);return[...e.values()]},Gt=()=>{c=new Map;for(const e of he())for(const t of e.partition.values())c.set(String(p(t)),t);g.length=0,R=0,fe=q,ye=void 0},Jt=()=>{const e=g.shift();e&&(e.op==="del"?c.delete(e.key):c.set(e.key,e.row),fe=e.seq,ye=e.t)},wn=()=>{if(De!=null)for(;g.length>De;)Jt();if(Ce!=null&&g.length){const e=g[g.length-1].t;for(;g.length>1&&e-g[0].t>Ce;)Jt()}},vn=e=>{!e||!e.row||g.push({pos:R++,seq:He(e),t:Ne(e),op:e.op==="delete"?"del":"set",key:String(p(e.row)),row:e.row})},Rt=(e,t)=>t==="seq"?e.seq:e.t,ft=(e,t)=>{const n=new Map(c);for(const r of g){const o=Rt(r,t);if(e!==void 0&&o!==void 0&&o>e)break;r.op==="del"?n.delete(r.key):n.set(r.key,r.row)}return n},dt=e=>{const t=new Map(he().map(n=>[n,[]]));for(const n of e)for(const r of lt(n))t.get(r).push(n);for(const n of he())n.partition=new Map(t.get(n).map(r=>[String(n.keyOf(r)),r]));for(const n of pe)Ze(n);Qe();for(const n of he())qe(n)},jt=e=>Re?!0:(F("data-router:no-buffer",`${e}() needs a buffered window; call router.buffer({ window, max }) first to record one.`),!1),pt=()=>{if(V&&(clearTimeout(V),V=null),ue=!1,C=[],J=0,Ee){const e=Ee;Ee=null,e()}},En=()=>{if(C=[],J=0,Ee){const e=Ee;Ee=null,e()}},kn=()=>{V=null;const e=C[J++];e.op==="del"?de.delete(e.key):de.set(e.key,e.row),dt([...de.values()]),ze=e.pos+1,Pt()};function Pt(){if(!ue){if(J>=C.length){En();return}V=setTimeout(kn,L)}}function ht(e){if(Fe)try{Fe.postMessage(e)}catch{}}function Qt(){return{t:"snapshot",rows:nt(),seq:q,checkpoint:Object.fromEntries(v)}}function Sn(e){const t=e&&e.data;if(!(!t||typeof t!="object")){if(t.t==="hello"){nt().length&&ht(Qt());return}et=!0;try{t.t==="delta"?je.apply(t.deltas||[]):t.t==="snapshot"&&(je.load(t.rows||[]),t.checkpoint&&je.seenThrough(t.checkpoint))}finally{et=!1}}}function Tn(e,t){e.partition=new Map(t.map(n=>[String(e.keyOf(n)),n]))}function On(e,t){const n=t.filter(o=>!o.isDefault),r=t.find(o=>o.isDefault)||null;for(const o of t)o.partition=new Map;for(const o of e){const i=[];for(const w of n)if(w.match(o)&&(i.push(w),!P))break;const h=i.length?i:r?[r]:[];if(!h.length){xe+=1,s&&s(o);continue}for(const w of h)w.partition.set(String(w.keyOf(o)),o)}}const Rn=(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[Ye]}`},_t=(e,t)=>{const n={...e.map?e.map(t):t};return e.ns&&(n[Ye]=e.ns(n)),n},Yt=(e,t)=>{const n=[];for(const r of t||[]){if(!r||!r.row)continue;const o=_t(e,r.row),i=String(o[Ye]);r.op==="delete"?e.live.delete(i):e.live.set(i,o),n.push({...r,row:o})}return e.ingested+=n.length,Me(`source:${e.id}`,n.length),n},jn=e=>({get id(){return e.id},get size(){return e.live.size},load(t){const n=(t||[]).map(i=>_t(e,i)),r=new Map(n.map(i=>[String(i[Ye]),i])),o=[];for(const[i,h]of e.live)r.has(i)||o.push({op:"delete",row:h});for(const i of n)o.push({op:"upsert",row:i});return e.live=r,e.ingested+=n.length,Me(`source:${e.id}`,n.length),At(e,o,i=>je.apply(i)),this},apply(t){return At(e,Yt(e,t),n=>je.apply(n)),this},push(t){return At(e,Yt(e,Array.isArray(t)?t:[t]),n=>je.push(n)),this},remove(){const t=[];for(const n of e.live.values())t.push({op:"delete",row:n});return e.live.clear(),Le.delete(e.id),t.length&&je.apply(t),je}}),Nt=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 F("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 o;if(typeof r=="function")o=r;else if(typeof r=="string")o=ve=>ve[r];else return F("data-router:join-no-localkey","join needs a `localKey` (a field name or fn); ignoring the join."),null;const i=e.foreignKey!=null?e.foreignKey:e.fromKey;let h,w;if(typeof i=="function")h=i,w=i;else if(typeof i=="string")h=ve=>ve[i],w=i;else if(typeof r=="string")h=ve=>ve[r],w=r;else return F("data-router:join-no-foreignkey","join with a fn `localKey` needs an explicit string/fn `foreignKey`; ignoring the join."),null;let b=null;const N=[],B=e.fields!=null?e.fields:e.select;if(typeof B=="function")b=B;else if(Array.isArray(B))for(const ve of B)N.push([String(ve),String(ve)]);else if(B&&typeof B=="object")for(const[ve,rt]of Object.entries(B))N.push([ve,String(rt)]);else F("data-router:join-no-fields","join has no `fields`/`select`; rows pass through unenriched.");let M=e.missing;return M!=="hold"&&M!=="passthrough"&&M!=="null"&&(M!=null&&F("data-router:join-bad-missing",`join.missing "${M}" is not hold|passthrough|null; using "passthrough".`),M="passthrough"),{from:n,localKey:o,foreignKeyFn:h,ffKey:w,pairs:N,selectFn:b,missing:M,keyIndex:new Map,lastFk:new Map,owner:t,probe:null}},Zt=(e,t,n)=>{const r={...t};if(e.selectFn){const o=e.selectFn(n,t);return o&&typeof o=="object"&&Object.assign(r,o),r}for(const[o,i]of e.pairs)r[i]=n?n[o]: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=Le.get(e.from);if(!r)return null;let o;for(o of n);return r.live.get(o)||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 i=e.keyIndex.get(r);i&&(i.delete(t),i.size||e.keyIndex.delete(r))}if(n==null){e.lastFk.set(t,null);return}let o=e.keyIndex.get(n);o||(o=new Set,e.keyIndex.set(n,o)),o.add(t),e.lastFk.set(t,n)},An=(e,t)=>{const n=e.join,r=[];for(const o of t){const i=String(o.row[Ye]);if(o.op==="delete"){en(n,i,null),n.lastFk.delete(i),r.push(o);continue}const h=Nt(n.localKey(o.row));en(n,i,h);const w=Xt(n,o.row,h);w.emit&&r.push({...o,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,o]of e.live){const i=Nt(n.fn(o));if(i==null)continue;let h=n.index.get(i);h||(h=new Set,n.index.set(i,h)),h.add(r),n.prev.set(r,i)}}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 o=new Set;for(const i of t){const h=String(i.row[Ye]);if(i.op==="delete"){const N=r.prev.get(h);if(N!=null){const B=r.index.get(N);B&&(B.delete(h),B.size||r.index.delete(N)),o.add(N)}r.prev.delete(h);continue}const w=Nt(r.fn(i.row)),b=r.prev.get(h);if(b!=null&&b!==w){const N=r.index.get(b);N&&(N.delete(h),N.size||r.index.delete(b)),o.add(b)}if(w!=null){let N=r.index.get(w);N||(N=new Set,r.index.set(w,N)),N.add(h),o.add(w)}r.prev.set(h,w)}if(o.size)for(const i of r.specs)for(const h of o){const w=i.keyIndex.get(h);if(w)for(const b of w){const N=i.owner.live.get(b);if(!N)continue;const B=Xt(i,N,h);n.push(B.emit?{op:"upsert",row:B.row}:{op:"delete",row:N})}}}n.length&&je.apply(n)},At=(e,t,n)=>{n(e.join?An(e,t):t),e.probes&&e.probes.size&&Fn(e,t)},Ft=(e,t,n)=>{const r=yt.get(e);if(yt.set(e,{cur:t,t:n}),!r)return 0;const o=(n-r.t)/1e3;return o<=0?0:(t-r.cur)/o},Dn=()=>{if(!Re)return 0;let e=0;for(const t of g)t.pos>=ze&&(e+=1);return e},Ln=(e,t)=>{const n=it.get(e);if(n)for(const r of n)try{r(t)}catch{}},In=()=>{Ke||qt<=0||(Ke=setInterval(()=>Ln("metrics",je.metrics()),qt),Ke&&typeof Ke.unref=="function"&&Ke.unref())},nn=()=>{Ke&&(clearInterval(Ke),Ke=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 o=null;const i=()=>o||(o=new Promise((h,w)=>{let b;try{b=t.open(n,1)}catch(N){w(N);return}b.onupgradeneeded=()=>{const N=b.result;N.objectStoreNames.contains(r)||N.createObjectStore(r)},b.onsuccess=()=>h(b.result),b.onerror=()=>w(b.error)}),o);return{set(h,w){return i().then(b=>new Promise((N,B)=>{const M=b.transaction(r,"readwrite");M.objectStore(r).put(w,h),M.oncomplete=()=>N(),M.onerror=()=>B(M.error),M.onabort=()=>B(M.error)}))},get(h){return i().then(w=>new Promise((b,N)=>{const M=w.transaction(r,"readonly").objectStore(r).get(h);M.onsuccess=()=>b(M.result),M.onerror=()=>N(M.error)}))},close(){o&&o.then(h=>{try{h.close()}catch{}},()=>{})}}},Wn=()=>Re?[...ft(void 0,u).values()]:nt(),$n=()=>({v:1,world:Wn(),maxSeq:q,checkpoint:Object.fromEntries(v),buffer:Re?{on:!0,max:De,window:Ce,domain:u,pos:R,baseSeq:fe,baseT:ye,base:[...c.entries()],log:g.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;vt=!0;try{je.load(Array.isArray(e.world)?e.world:[])}finally{vt=!1}e.checkpoint&&je.seenThrough(e.checkpoint),Number.isFinite(e.maxSeq)&&(q===void 0||e.maxSeq>q)&&(q=e.maxSeq);const t=e.buffer;if(t&&t.on){Re=!0,De=Number.isFinite(t.max)?t.max:null,Ce=Number.isFinite(t.window)?t.window:null,u=t.domain==="seq"||t.domain==="time"?t.domain:l?"seq":"time",c=new Map(Array.isArray(t.base)?t.base:[]),g.length=0;for(const n of Array.isArray(t.log)?t.log:[])g.push({...n});R=Number.isFinite(t.pos)?t.pos:g.length,fe=t.baseSeq,ye=t.baseT,ze=R}return!0},Dt=()=>{if(!Ae)return Promise.resolve();const e=$n(),t=Promise.resolve().then(()=>Ae.set(bt,e)).catch(()=>{});return Xe=t,t.then(()=>{Xe===t&&(Xe=null)})},Lt=()=>{if(!(!st||!Ae||vt)){if(wt<=0){Dt();return}Ie||(Ie=setTimeout(()=>{Ie=null,Dt()},wt),Ie&&typeof Ie.unref=="function"&&Ie.unref())}},je={attach(e,t,n={}){const r=typeof t!="function",o=r?h=>I(h)===t:t;r&&Kt(t);const i=Tt(e,o,n);return r&&(i.hasPartValue=!0,i.partValue=t),K.push(i),i.writable&&mn(i),this},attachDefault(e,t={}){return Q=Tt(e,()=>!1,t),Q.isDefault=!0,this},subscribe(e,t,n={}){const r=typeof e!="function",o=r?h=>I(h)===e:e;r&&Kt(e);const i=Tt(t,o,n);return r&&(i.hasPartValue=!0,i.partValue=e),K.push(i),this},alert(e,t,n,r={}){const i={match:typeof e=="function"?e:h=>I(h)===e,keyOf:j(D(r.rowKey,"alerts"),T),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 Ue.push(i),Ot(i,nt()),ct(i),this},monitor(e,t,n,r={}){const i={kind:"monitor",match:typeof e=="function"?e:h=>I(h)===e,keyOf:j(D(r.rowKey,"alerts"),T),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 Ue.push(i),Ot(i,nt()),ct(i),()=>{const h=Ue.indexOf(i);h>=0&&Ue.splice(h,1),i.timer&&(clearTimeout(i.timer),i.timer=null),i.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};pe.push(r),Bt(e),Ze(r);const o=Je(t);return o&&qe(o),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;we.push({from:t.from,to:t.to,rel:n}),t.mutual&&we.push({from:t.to,to:t.from,rel:U(n)})}for(const t of tt())Bt(t);Qe();for(const t of tt()){const n=Je(t);n&&qe(n)}return this},flush(){return St(),this},detach(e){const t=new Set;for(let o=pe.length-1;o>=0;o--){const i=pe[o];(i.from===e||i.to===e)&&(i.to!==e&&t.add(i.to),xt(i.from),pe.splice(o,1))}let n=!1;for(let o=we.length-1;o>=0;o--)(we[o].from===e||we[o].to===e)&&(xt(we[o].from),we.splice(o,1),n=!0);for(let o=K.length-1;o>=0;o--)K[o].grid===e&&K.splice(o,1);Q&&Q.grid===e&&(Q=null),Ge.delete(e);const r=_e.get(e);if(r&&(r(),_e.delete(e)),n){Qe();for(const o of tt())t.add(o)}for(const o of t){const i=Je(o);i&&qe(i)}return this},load(e){xe=0;const t=new Map(he().map(r=>[r,[]]));for(const r of e||[]){const o=lt(r);if(!o.length){xe+=1,s&&s(r);continue}for(const i of o)t.get(i).push(r)}for(const r of he()){const o=t.get(r);r.partition=new Map(o.map(i=>[String(r.keyOf(i)),i])),r.metricRows+=o.length,mt+=o.length}if(l)for(const r of e||[]){const o=l(r);if(!Number.isFinite(o))continue;const i=String(p(r)),h=v.get(i);(h===void 0||o>h)&&v.set(i,o),(q===void 0||o>q)&&(q=o)}for(const r of pe)Ze(r);Qe();for(const r of Ue)Ot(r,e||[]),ct(r);for(const r of he())r.bp&&cn(r);const n=he().map(r=>qe(r));return Re&&Gt(),ze=R,Fe&&!et&&ht(Qt()),Lt(),n},apply(e){let t=(e||[]).filter(o=>o&&o.row);if(a){t=t.map((i,h)=>[i,h]).sort((i,h)=>{const w=He(i[0]),b=He(h[0]);return w===void 0||b===void 0?i[1]-h[1]:w-b||i[1]-h[1]}).map(i=>i[0]);const o=[];for(const i of t){const h=He(i);if(h!==void 0){const w=String(p(i.row)),b=v.get(w);if(b!==void 0&&h<=b){be+=1;continue}v.set(w,h),(q===void 0||h>q)&&(q=h)}o.push(i)}t=o}if(Fe&&!et&&t.length&&ht({t:"delta",deltas:t.map(o=>({op:o.op,row:o.row,seq:o.seq}))}),Re){for(const o of t)vn(o);wn()}for(const o of Ue)bn(o,t),ct(o);if(te){Lt();return}const n=new Map(he().map(o=>[o,new Map]));for(const o of t){const i=o&&o.row;if(!i)continue;if(o.op==="delete"){let w=!1;for(const b of he()){const N=String(b.keyOf(i));(b.partition.has(N)||n.get(b).has(N))&&(n.get(b).set(N,{op:"del"}),w=!0)}!w&&!lt(i).length&&(xe+=1,s&&s(o));continue}const h=lt(i);if(!h.length){xe+=1,s&&s(o);continue}for(const w of he()){if(h.includes(w))continue;const b=String(w.keyOf(i));(w.partition.has(b)||n.get(w).get(b)?.op==="set")&&n.get(w).set(b,{op:"del"})}for(const w of h)n.get(w).set(String(w.keyOf(i)),{op:"set",row:i})}const r=new Map;for(const o of he()){let i=0;const h=n.get(o).size;for(const[w,b]of n.get(o)){if(b.op==="del"){o.partition.delete(w);continue}o.partition.set(w,b.row),i+=1}o.metricRows+=i,mt+=i,r.set(o,h)}for(const o of pe)Ze(o);Qe();for(const o of he())an(o,r.get(o)||0);ze=R,Lt()},push(e){const t=Array.isArray(e)?e:[e];if(!E)return this.apply(t),this;for(const n of t)ae.push(n);return m!==null&&(m<=0?this.flushStream():re||(re=setTimeout(()=>this.flushStream(),m))),this},flushStream(){if(re&&(clearTimeout(re),re=null),!ae.length)return this;const e=ae.splice(0,ae.length);return this.apply(e),this},flushBackpressure(){for(const e of he())e.bp&&(e.bpTimer||e.bpPending>0)&&ut(e);return this},addSource(e,t){let n,r;e&&typeof e=="object"?(r=e,n=r.id!=null?String(r.id):`source${++$t}`):(n=e!=null?String(e):`source${++$t}`,r=t||{});const o=Le.get(n);if(o)return F("data-router:duplicate-source",`addSource("${n}") was already registered; returning the existing source handle. Use a distinct id per feed.`),o.handle;const i={id:n,map:typeof r.map=="function"?r.map:null,ns:Rn(n,r.key),live:new Map,ingested:0};i.handle=jn(i),i.join=Pn(r.join,i),Le.set(n,i),i.join&&Le.has(i.join.from)&&tn(Le.get(i.join.from),i.join);for(const h of Le.values())h!==i&&h.join&&h.join.from===n&&h.join.probe==null&&tn(i,h.join);return i.handle},removeSource(e){const t=e&&typeof e=="object"&&e.id!==void 0?String(e.id):String(e),n=Le.get(t);return n&&n.handle.remove(),this},sources(){return[...Le.keys()]},metrics(){const e=le(),t=he().map((r,o)=>({index:o,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:Ft(`route:${o}`,r.metricRows,e),backpressure:r.bp?{pending:r.bpPending,coalesced:r.bpCoalesced}:null})),n=[...Le.values()].map(r=>({id:r.id,rows:r.live.size,ingested:r.ingested,throughput:Ft(`source:${r.id}`,r.ingested,e)}));return{routes:t,sources:n,unrouted:xe,dropped:be,buffered:g.length,lag:Dn(),throughput:Ft("total",mt,e)}},on(e,t){if(typeof t!="function")return()=>{};let n=it.get(e);return n||(n=new Set,it.set(e,n)),n.add(t),e==="metrics"&&In(),()=>{n.delete(t),e==="metrics"&&n.size===0&&nn()}},mountDevtools(e,t={}){return Se(this,e,t)},get unrouted(){return xe},get dropped(){return be},lastSeq(){return q},checkpoint(){return new Map(v)},seenThrough(e){const t=e instanceof Map?e.entries():Object.entries(e||{});for(const[n,r]of t){const o=Number(r);if(!Number.isFinite(o))continue;const i=v.get(String(n));(i===void 0||o>i)&&v.set(String(n),o),(q===void 0||o>q)&&(q=o)}return this},persist(e={}){if(st=!0,typeof e.key=="string"&&(bt=e.key),Number.isFinite(e.debounce)&&(wt=Number(e.debounce)),e.storage&&typeof e.storage.get=="function"&&typeof e.storage.set=="function")Ae=e.storage;else{let t=null;try{t=Cn(e)}catch{t=null}t?Ae=t:(Ae=null,F("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(!Ae)return!1;let e;try{e=await Ae.get(bt)}catch{return!1}return e==null?!1:Mn(e)},async flushPersist(){return Ie&&(clearTimeout(Ie),Ie=null),await Dt(),Xe&&await Xe,this},get persisting(){return st&&!!Ae},buffer(e={}){return Re=!0,Number.isFinite(e.max)?De=Number(e.max):"max"in e&&e.max==null&&(De=null),Number.isFinite(e.window)?Ce=Number(e.window):"window"in e&&e.window==null&&(Ce=null),De==null&&Ce==null&&(De=Pe,F("data-router:buffer-default-cap",`buffer() called with no window or max; applying a default cap of ${Pe} deltas so the buffer stays bounded. Pass { window } or { max } to size it.`)),u=l?"seq":"time",Gt(),this},scrubTo(e,t={}){if(!jt("scrubTo"))return this;pt(),te=!0;const n=t.by||u;de=ft(e,n),dt([...de.values()]),ze=0;for(const r of g){const o=Rt(r,n);if(e!==void 0&&o!==void 0&&o>e)break;ze=r.pos+1}return this},replay(e,t,n={}){if(!jt("replay"))return Promise.resolve();pt(),te=!0;const r=n.by||u;return oe=r,L=Number.isFinite(n.speed)?Number(n.speed):0,de=ft(e,r),dt([...de.values()]),C=g.filter(o=>{const i=Rt(o,r);return i!==void 0&&i>e&&i<=t}).slice().sort((o,i)=>o.pos-i.pos),J=0,ue=!1,new Promise(o=>{Ee=o,Pt()})},pause(){return ue=!0,V&&(clearTimeout(V),V=null),this},resume(){return ue?(ue=!1,Pt(),this):this},live(){return jt("live")?(pt(),te=!1,de=null,dt([...ft(void 0,u).values()]),ze=R,this):this},get traveling(){return te},get buffered(){return g.length},broadcast(e={}){if(typeof BroadcastChannel!="function")return F("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?(Fe&&(Fe.close(),Fe=null),Fe=new BroadcastChannel(t),Fe.onmessage=Sn,ht({t:"hello"}),this):(F("data-router:broadcast-channel","router.broadcast({ channel }) needs a string channel name; nothing was mirrored."),this)},get broadcasting(){return!!Fe},async query(e,t={}){if(!e||typeof e.execute!="function")return F("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=ne(e.capabilities),r=t||{},o=r.filters||null,i=[];xe=0;const h=he().filter(b=>b.where),w=he().filter(b=>!b.where);for(const b of h){const N=H(o,b.where),B=Z({...r,filters:N},n);let ve=((await e.execute(B.pushed,r)).rows||[]).slice();B.residual&&B.residual.filters&&(ve=ve.filter(rt=>ee(B.residual.filters,rt))),ve=ve.filter(rt=>b.match(rt)),Tn(b,ve),i.push({route:b.grid,pushedFilter:!!(B.pushed&&B.pushed.filters),residual:B.unpushed.slice()})}if(w.length){const b=Z(r,n);let B=((await e.execute(b.pushed,r)).rows||[]).slice();b.residual&&b.residual.filters&&(B=B.filter(M=>ee(b.residual.filters,M))),On(B,w),i.push({base:!0,pushedFilter:!!(b.pushed&&b.pushed.filters),residual:b.unpushed.slice()})}Et=i;for(const b of pe)Ze(b);Qe();for(const b of he())qe(b);return this},lastQueryPlan(){return Et?Et.map(e=>({...e})):null},destroy(){if(Be&&(clearTimeout(Be),Be=null),re&&(clearTimeout(re),re=null),Ie&&(clearTimeout(Ie),Ie=null),Ae&&typeof Ae.close=="function")try{Ae.close()}catch{}st=!1,Ae=null,Fe&&(Fe.close(),Fe=null),et=!1,pt(),Re=!1,te=!1,de=null,g.length=0,c.clear();for(const e of $e.values())e.off();$e.clear();for(const e of _e.values())e();_e.clear(),ot.clear(),Le.clear(),nn(),it.clear(),yt.clear();for(const e of Ue)e.timer&&(clearTimeout(e.timer),e.timer=null);Ue.length=0;for(const e of he())e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null);pe.length=0,we.length=0,Ge.clear(),ae.length=0,v.clear(),K.length=0,Q=null}};return f.config&&je.configure(f.config),je}function Oe(f,I){if(f===I)return!0;if(!f||!I)return!1;const T=Object.keys(f),P=Object.keys(I);if(T.length!==P.length)return!1;for(const s of T)if(f[s]!==I[s])return!1;return!0}const We=se});var gt=Wt("packages/modules/data-router/index.js");typeof module=="object"&&module.exports?module.exports=gt:typeof define=="function"&&define.amd?define(function(){return gt}):rn.LatticeGridDataRouter=gt})(typeof globalThis<"u"?globalThis:this);
6
+ (function(rn){"use strict";var It=Object.create(null),Ct=Object.create(null);function Ve(y,ge){It[y]=ge}function Wt(y){var ge=Ct[y];if(ge)return ge;var ie=Object.create(null);Ct[y]=ie;var F=It[y];if(!F)throw new Error("[lattice] missing module: "+y);return F(ie,Wt),ie}Ve("packages/core/src/internal/util.js",function(y,ge){"use strict";Object.defineProperty(y,"VERSION",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(y,"reportedWarnings",{enumerable:!0,get:function(){return A}}),Object.defineProperty(y,"warnOnce",{enumerable:!0,get:function(){return D}}),Object.defineProperty(y,"infoOnce",{enumerable:!0,get:function(){return z}}),Object.defineProperty(y,"resetWarnings",{enumerable:!0,get:function(){return W}}),Object.defineProperty(y,"fail",{enumerable:!0,get:function(){return G}}),Object.defineProperty(y,"invariant",{enumerable:!0,get:function(){return k}}),Object.defineProperty(y,"DEV",{enumerable:!0,get:function(){return x}}),Object.defineProperty(y,"isObject",{enumerable:!0,get:function(){return $}}),Object.defineProperty(y,"isFunction",{enumerable:!0,get:function(){return U}}),Object.defineProperty(y,"isNil",{enumerable:!0,get:function(){return H}}),Object.defineProperty(y,"isBlank",{enumerable:!0,get:function(){return _}}),Object.defineProperty(y,"isCtor",{enumerable:!0,get:function(){return X}}),Object.defineProperty(y,"pathGetter",{enumerable:!0,get:function(){return se}}),Object.defineProperty(y,"pathSetter",{enumerable:!0,get:function(){return We}}),Object.defineProperty(y,"getPath",{enumerable:!0,get:function(){return f}}),Object.defineProperty(y,"setPath",{enumerable:!0,get:function(){return I}}),Object.defineProperty(y,"humanise",{enumerable:!0,get:function(){return T}}),Object.defineProperty(y,"escapeHtml",{enumerable:!0,get:function(){return s}}),Object.defineProperty(y,"titleCase",{enumerable:!0,get:function(){return d}}),Object.defineProperty(y,"expand",{enumerable:!0,get:function(){return O}}),Object.defineProperty(y,"toArray",{enumerable:!0,get:function(){return S}}),Object.defineProperty(y,"merge",{enumerable:!0,get:function(){return a}}),Object.defineProperty(y,"mergeRow",{enumerable:!0,get:function(){return p}}),Object.defineProperty(y,"Lru",{enumerable:!0,get:function(){return m}}),Object.defineProperty(y,"collator",{enumerable:!0,get:function(){return v}}),Object.defineProperty(y,"defaultCompare",{enumerable:!0,get:function(){return q}}),Object.defineProperty(y,"now",{enumerable:!0,get:function(){return be}}),Object.defineProperty(y,"nextFrame",{enumerable:!0,get:function(){return re}}),Object.defineProperty(y,"cancelFrame",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(y,"frameBatched",{enumerable:!0,get:function(){return le}}),Object.defineProperty(y,"settleDebounce",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(y,"whenIdle",{enumerable:!0,get:function(){return Re}}),Object.defineProperty(y,"uid",{enumerable:!0,get:function(){return Ce}});const ie="1.71.3";async function F(){return ie}const Y="1.71.3",Z=new Set,ne=2e3;function Te(u){if(Z.add(u),Z.size>ne){const c=Z.values().next().value;c!==void 0&&Z.delete(c)}}const me=[],ke=500;function Se(u,c,g){me.push({key:u,level:c,message:g.map(R=>typeof R=="string"?R:j(R)).join(" "),at:Date.now()}),me.length>ke&&me.shift()}function j(u){if(u instanceof Error)return u.message;try{return JSON.stringify(u)}catch{return String(u)}}function A(){return me.map(u=>({...u}))}function D(u,...c){Z.has(u)||(Te(u),Se(u,"warn",c),console.warn("[lattice]",...c))}function z(u,...c){Z.has(u)||(Te(u),Se(u,"info",c),console.info("[lattice]",...c))}function W(){Z.clear(),me.length=0}function G(u,c){const g=new Error(`[lattice] ${u}`);throw c!==void 0&&(g.cause=c),g}function k(u,c){u||G(c)}const x=(()=>{try{return!(typeof process<"u"&&process.env&&process.env.NODE_ENV==="production")}catch{return!0}})();function $(u){return u!==null&&typeof u=="object"&&!Array.isArray(u)}function U(u){return typeof u=="function"}function H(u){return u==null}function _(u){return u==null||u===""}function X(u){return typeof u!="function"?!1:/^class[\s{]/.test(Function.prototype.toString.call(u))?!0:!!(u.prototype&&Object.getOwnPropertyNames(u.prototype).length>1)}const ee=new Map;function se(u){let c=ee.get(u);if(c)return c;if(!u.includes("."))c=g=>g?.[u];else{const g=u.split("."),R=g.length;c=fe=>{let ye=fe;for(let te=0;te<R;te++){if(ye==null)return;ye=ye[g[te]]}return ye}}return ee.set(u,c),c}const Oe=new Map;function We(u){let c=Oe.get(u);if(c)return c;if(!u.includes("."))c=(g,R)=>{g!=null&&(g[u]=R)};else{const g=u.split("."),R=g.length-1;c=(fe,ye)=>{let te=fe;for(let de=0;de<R;de++){if(te==null)return;const C=g[de];te[C]==null&&(te[C]={}),te=te[C]}te!=null&&(te[g[R]]=ye)}}return Oe.set(u,c),c}function f(u,c){return se(c)(u)}function I(u,c,g){We(c)(u,g)}function T(u){return u?(u.includes(".")?u.slice(u.lastIndexOf(".")+1):u).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(/^./,g=>g.toUpperCase()):""}const P={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function s(u){const c=u==null?"":String(u);return/[&<>"']/.test(c)?c.replace(/[&<>"']/g,g=>P[g]):c}function d(u){return String(u).replace(/\w\S*/g,c=>c[0].toUpperCase()+c.slice(1).toLowerCase())}function O(u,c,g){if(u!==void 0)return u===!0?{enabled:!0,...g}:u===!1?{enabled:!1}:$(u)?u:{[c]:u,enabled:!0}}function S(u){return u==null?[]:Array.isArray(u)?u:[u]}const l=Object.freeze(new Set(["__proto__","constructor","prototype"]));function a(u,c){if(!$(u))return $(c)?{...c}:c;if(!$(c))return c===void 0?u:c;const g={...u};for(const R of Object.keys(c)){if(l.has(R))continue;const fe=c[R];fe!==void 0&&(g[R]=$(fe)&&$(g[R])?a(g[R],fe):fe)}return g}function p(u,c){if(!$(u)||!$(c)||u===c)return c;const g=Object.create(Object.getPrototypeOf(u));return Object.assign(g,u,c),g}class m{#n;#e=new Map;#t;constructor(c=256,g=null){this.#n=c,this.#t=g}get size(){return this.#e.size}get max(){return this.#n}set max(c){this.#n=c,this.#r()}has(c){return this.#e.has(c)}get(c){const g=this.#e;if(!g.has(c))return;const R=g.get(c);return g.delete(c),g.set(c,R),R}peek(c){return this.#e.get(c)}set(c,g){const R=this.#e;return R.has(c)&&R.delete(c),R.set(c,g),this.#r(),g}delete(c){const g=this.#e.get(c);return this.#e.delete(c)&&this.#t&&this.#t(g,c),g}clear(){if(this.#t)for(const[c,g]of this.#e)this.#t(g,c);this.#e.clear()}keys(){return this.#e.keys()}values(){return this.#e.values()}#r(){const c=this.#e;for(;c.size>this.#n;){const g=c.keys().next().value,R=c.get(g);c.delete(g),this.#t&&this.#t(R,g)}}}const E=new Map;function v(u,c){const g=`${u||""}|${c?JSON.stringify(c):""}`;let R=E.get(g);return R||(R=new Intl.Collator(u||void 0,{numeric:!0,sensitivity:"variant",...c}),E.set(g,R)),R}function q(u,c){if(u===c)return 0;if(u==null)return 1;if(c==null)return-1;if(typeof u=="number"&&typeof c=="number")return Number.isNaN(u)?Number.isNaN(c)?0:1:Number.isNaN(c)||u<c?-1:u>c?1:0;const g=String(u),R=String(c);return g<R?-1:g>R?1:0}function be(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const ae=typeof requestAnimationFrame=="function";function re(u){return ae?requestAnimationFrame(u):setTimeout(()=>u(be()),16)}function ce(u){u!=null&&(ae?cancelAnimationFrame(u):clearTimeout(u))}function le(u){let c=null,g=null;const R=()=>{c=null;const ye=g;g=null,u(...ye||[])},fe=(...ye)=>{g=ye,c===null&&(c=re(R))};return fe.cancel=()=>{ce(c),c=null,g=null},fe.flush=()=>{c!==null&&(ce(c),R())},fe}function Pe(u,c){let g=null,R=null;const fe=()=>{if(g=null,R===null)return;const de=R;R=null,u(...de),ye()},ye=()=>{g=setTimeout(fe,c),typeof g?.unref=="function"&&g.unref()},te=(...de)=>{g===null?(u(...de),ye()):(R=de,clearTimeout(g),ye())};return te.flush=()=>{if(g!==null&&clearTimeout(g),g=null,R===null)return;const de=R;R=null,u(...de)},te.cancel=()=>{g!==null&&clearTimeout(g),g=null,R=null},te.pending=()=>g!==null||R!==null,te}function Re(u,c=50){return typeof requestIdleCallback=="function"?requestIdleCallback(u,{timeout:c}):setTimeout(()=>u({timeRemaining:()=>0,didTimeout:!0}),1)}let De=0;function Ce(u="l"){return`${u}${(++De).toString(36)}`}}),Ve("packages/core/src/source/filterwire.js",function(y,ge){"use strict";Object.defineProperty(y,"HOST_FILTER_WARN_ID",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(y,"WHERE_PAGE_RELATIVE_WARN_ID",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(y,"warnWherePageRelative",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(y,"warnHostFilterNotApplied",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(y,"WHERE_NOT_APPLIED_WARN_ID",{enumerable:!0,get:function(){return me}}),Object.defineProperty(y,"warnWhereNotApplied",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(y,"WHERE_OVER_THRESHOLD_WARN_ID",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(y,"warnWhereOverThreshold",{enumerable:!0,get:function(){return j}}),Object.defineProperty(y,"RELATIVE_TOKENS",{enumerable:!0,get:function(){return $}}),Object.defineProperty(y,"parseRelativeToken",{enumerable:!0,get:function(){return U}}),Object.defineProperty(y,"resolveRelativeRange",{enumerable:!0,get:function(){return H}}),Object.defineProperty(y,"relativeTokenOf",{enumerable:!0,get:function(){return _}}),Object.defineProperty(y,"relativeTokenHelp",{enumerable:!0,get:function(){return X}}),Object.defineProperty(y,"isResolvableRelative",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(y,"resolveRelativeCondition",{enumerable:!0,get:function(){return se}}),Object.defineProperty(y,"isGroup",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(y,"forEachCondition",{enumerable:!0,get:function(){return We}}),Object.defineProperty(y,"mapConditions",{enumerable:!0,get:function(){return f}}),Object.defineProperty(y,"normaliseFilterSet",{enumerable:!0,get:function(){return T}}),Object.defineProperty(y,"buildFilterSet",{enumerable:!0,get:function(){return P}}),Object.defineProperty(y,"wireFilters",{enumerable:!0,get:function(){return s}}),Object.defineProperty(y,"querySignature",{enumerable:!0,get:function(){return d}});const F=ge("packages/core/src/internal/util.js").warnOnce,Y="source.remote.hostFilter",Z="source.where.pageRelative";function ne(l,a){!Array.isArray(l)||!l.length||F(Z,`filters.where (${l.join(", ")}) runs over the rows the ${a} 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 Te(l){const a=(l||{}).config;!a||!a.hostFilter||F(Y,"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 me="source.where.notApplied";function ke(l,a){F(`${me}:${l}`,`filters.where("${l}") is registered but the ${a} 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 Se="source.where.overThreshold";function j(l,a,p,m){!Array.isArray(l)||!l.length||F(`${Se}:${a}`,`filters.where (${l.join(", ")}) is not applied to the ${a} pushdown source:`,p===null?"the adapter reports no row total, so the size of the matching set is unknown.":`its matching set is ${p.toLocaleString()} rows, at or past the whereRowLimit of ${m.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 A=new Map;function D(l){let a=A.get(l);return a||(a=new Intl.DateTimeFormat("en-US",{timeZone:l,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),A.set(l,a)),a}function z(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function W(l,a){const p=D(a).formatToParts(new Date(l)),m={y:1970,m:1,d:1,h:0,mi:0,s:0};for(const E of p)E.type==="year"?m.y=+E.value:E.type==="month"?m.m=+E.value:E.type==="day"?m.d=+E.value:E.type==="hour"?m.h=+E.value%24:E.type==="minute"?m.mi=+E.value:E.type==="second"&&(m.s=+E.value);return m}function G(l,a){const p=W(l,a);return Date.UTC(p.y,p.m-1,p.d,p.h,p.mi,p.s)-Math.floor(l/1e3)*1e3}function k(l,a,p,m){const E=Date.UTC(l,a-1,p),v=E-G(E,m);return E-G(v,m)}function x(l,a,p){const m=new Date(Date.UTC(l.y,l.m-1,l.d+a));return k(m.getUTCFullYear(),m.getUTCMonth()+1,m.getUTCDate(),p)}const $=Object.freeze(["today","yesterday","lastNDays","thisWeek","thisMonth","thisQuarter","thisYear","quarterToDate","yearToDate"]);function U(l,a){if(typeof l!="string")return null;const p=l.trim().toLowerCase().replace(/[\s_-]+/g,""),m=/^last(\d*|n)days?$/.exec(p);if(m){const E=m[1]==="n"?"":m[1],v=Number(E||a);return!Number.isFinite(v)||v<=0?null:{kind:"lastNDays",n:Math.floor(v)}}switch(p){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 H(l,a={}){const p=U(l,a.n);if(!p)return null;const m=a.tz||z(),E=a.now instanceof Date?a.now.getTime():typeof a.now=="number"?a.now:Date.now(),v=W(E,m),q=k(v.y,v.m,v.d,m),be=x(v,1,m);let ae=q,re=be;switch(p.kind){case"today":break;case"yesterday":ae=x(v,-1,m),re=q;break;case"lastNDays":re=a.includeToday?be:q,ae=x(v,a.includeToday?-(p.n-1):-p.n,m);break;case"thisWeek":{const ce=Number.isFinite(a.weekStartsOn)?Number(a.weekStartsOn):1,Pe=(new Date(Date.UTC(v.y,v.m-1,v.d)).getUTCDay()-ce+7)%7;ae=x(v,-Pe,m),re=x(v,-Pe+7,m);break}case"thisMonth":ae=k(v.y,v.m,1,m),re=k(v.m===12?v.y+1:v.y,v.m===12?1:v.m+1,1,m);break;case"thisQuarter":case"quarterToDate":{const ce=Math.floor((v.m-1)/3)*3+1;ae=k(v.y,ce,1,m),re=p.kind==="quarterToDate"?be:ce===10?k(v.y+1,1,1,m):k(v.y,ce+3,1,m);break}case"thisYear":case"yearToDate":ae=k(v.y,1,1,m),re=p.kind==="yearToDate"?be:k(v.y+1,1,1,m);break;default:return null}return{from:new Date(ae).toISOString(),to:new Date(re).toISOString(),bounds:"[)",tz:m,relative:p.kind==="lastNDays"?`last${p.n}Days`:p.kind,n:p.n}}function _(l){if(!l||typeof l!="object")return null;const a=l.value;if(a&&typeof a=="object"&&!Array.isArray(a)&&"relative"in a)return{token:String(a.relative),n:typeof a.n=="number"?a.n:void 0};if(l.op==="relative"&&typeof l.value=="string")return{token:l.value,n:void 0};const p=l.meta;return p&&typeof p.relative=="string"&&l.value===void 0?{token:p.relative,n:typeof p.n=="number"?p.n:void 0}:null}function X(){return`Known tokens: ${$.filter(a=>a!=="lastNDays").join(", ")}. "lastNDays" needs a count: pass "last7Days", or the value object { relative: 'lastNDays', n: 7 }.`}function ee(l){const a=_(l);return a?U(a.token,a.n)!==null:!1}function se(l,a={}){const p=_(l);if(!p)return l;const m=H(p.token,{...a,n:p.n});return m?{...l,type:l.type||"date",op:"between",value:[m.from,m.to],bounds:l.bounds||m.bounds,meta:{...l.meta||{},relative:m.relative,tz:m.tz}}:(F(`source.relative.${p.token}`,`unknown relative date token "${p.token}"; sending the condition unresolved.`,X()),l)}function Oe(l){return!!l&&typeof l=="object"&&Array.isArray(l.conditions)}function We(l,a){if(l){if(Oe(l)){for(const p of l.conditions)We(p,a);return}a(l)}}function f(l,a){if(!l)return null;if(!Oe(l))return a(l);const p=l;let m=!1;const E=[];for(const v of p.conditions){const q=f(v,a);q!==v&&(m=!0),q&&E.push(q)}return!m&&E.length===p.conditions.length?l:E.length?{...p,conditions:E}:null}function I(l){if(!l)return null;if(!Oe(l))return l;const a=l,p=[];for(const m of a.conditions){const E=I(m);E&&p.push(E)}return p.length?{op:a.op,conditions:p}:null}function T(l){const a=I(l);return a?Oe(a)&&a.op==="and"?a:{op:"and",conditions:[a]}:null}function P(l){const a=(l||[]).filter(Boolean);return a.length?{op:"and",conditions:a}:null}function s(l,a={}){const p=f(l,m=>se(m,a));return T(p)}function d(l){const a=O(l.filters??null);return JSON.stringify([a,l.sort??null,l.quick??"",l.groupBy??null,l.pivotBy??null,S(l.context)])}function O(l){if(!l)return null;if(Oe(l)){const m=l;return{op:m.op,conditions:m.conditions.map(O)}}const a=l,p=a.meta&&typeof a.meta.relative=="string"?a.meta.relative:_(a)?.token;return{col:a.col,op:a.op,bounds:a.bounds??null,caseSensitive:a.caseSensitive??!1,value:p?`rel:${p}`:a.value??null}}function S(l){if(l==null)return null;try{return JSON.parse(JSON.stringify(l))}catch{return F("source.context.unserialisable","config.context is not JSON-serialisable; cache keys ignore it."),"[unserialisable]"}}}),Ve("packages/core/src/source/aggregates.js",function(y,ge){"use strict";Object.defineProperty(y,"STAT_PUSHDOWN",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(y,"pushableAggregates",{enumerable:!0,get:function(){return F}}),Object.defineProperty(y,"fillAggregateSql",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(y,"resolveAggregatesConfig",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(y,"routeAggregate",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(y,"resolveAggregatePlan",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(y,"groupKeysPushable",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(y,"pushdownDocRows",{enumerable:!0,get:function(){return Se}});const ie=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 F(){const j=new Set;for(const[A,D]of Object.entries(ie))D.pushable&&j.add(A);return j}function Y(j,A,D){let z=j.split("%c").join(A);return D!==void 0&&(z=z.split("%w").join(D)),z}function Z(j){const A=j||{},D=A.default==="engine"||A.default==="engine-if-identical"?A.default:"client",z={};if(A.overrides&&typeof A.overrides=="object")for(const[W,G]of Object.entries(A.overrides))(G==="engine"||G==="client")&&(z[W]=G);return{default:D,overrides:z}}function ne(j,A){const D=ie[j];if(!D||!D.pushable)return"client";const z=A.overrides[j];return z==="engine"||z==="client"?z:A.default==="client"?"client":A.default==="engine-if-identical"?D.class==="identical"?"engine":"client":"engine"}function Te(j,A){const D=Z(A),z=[],W=[];for(const G of j||[]){const k=ie[G.fn],x=ne(G.fn,D),$={id:G.id,col:G.col,fn:G.fn,class:k?k.class:"fallback"};G.weight!==void 0&&($.weight=G.weight),G.params!==void 0&&($.params=G.params),x==="engine"?z.push($):($.reason=k&&!k.pushable?k.note||"the engine cannot express this stat":"client by config",W.push($))}return{engine:z,client:W,config:D}}const me=/^[A-Za-z_][A-Za-z0-9_$]*$/;function ke(j){return(j||[]).every(D=>typeof D=="string"&&me.test(D))}function Se(){return Object.entries(ie).map(([j,A])=>({stat:j,class:A.class,sql:A.sql?Y(A.sql,"col",A.twoColumn?"weight":void 0):"",note:A.note||(A.class==="identical"?"Pushes to DuckDB with the same result.":"")}))}}),Ve("packages/core/src/source/pushdown.js",function(y,ge){"use strict";Object.defineProperty(y,"NO_CAPABILITIES",{enumerable:!0,get:function(){return D}}),Object.defineProperty(y,"resolveMutate",{enumerable:!0,get:function(){return z}}),Object.defineProperty(y,"capabilitiesOf",{enumerable:!0,get:function(){return k}}),Object.defineProperty(y,"splitFilters",{enumerable:!0,get:function(){return $}}),Object.defineProperty(y,"planQuery",{enumerable:!0,get:function(){return H}}),Object.defineProperty(y,"applyResidual",{enumerable:!0,get:function(){return X}}),Object.defineProperty(y,"DEFAULT_WHERE_ROW_LIMIT",{enumerable:!0,get:function(){return We}}),Object.defineProperty(y,"createPushdownSource",{enumerable:!0,get:function(){return P}});const ie=ge("packages/core/src/internal/util.js"),F=ie.isFunction,Y=ie.warnOnce,Z=ge("packages/core/src/source/filterwire.js"),ne=Z.isGroup,Te=Z.warnWherePageRelative,me=Z.warnWhereOverThreshold,ke=ge("packages/core/src/source/aggregates.js"),Se=ke.resolveAggregatePlan,j=ke.groupKeysPushable,A=ke.STAT_PUSHDOWN,D=Object.freeze({filter:!1,operators:Object.freeze([]),sort:!1,quick:!1,range:!1,total:!1,group:!1,mutate:!1});function z(s){if(!s||typeof s!="object")return!1;const d=s.returning==="row"||s.returning==="key"?s.returning:"none";return{append:s.append===!0,update:s.update===!0,delete:s.delete===!0,returning:d}}function W(s,d){if(!s||typeof d!="string")return;if(!d.includes("."))return s[d];let O=s;for(const S of d.split(".")){if(O===null||typeof O!="object")return;O=O[S]}return O}function G(s){if(s===!0)return!0;if(!s||typeof s!="object")return!1;const d=s;return d.enabled===!1?!1:d.enabled===!0||F(d.commit)}function k(s){const d={...D,...s||{}};return d.operators=new Set(d.operators||[]),d.mutate=z(d.mutate),d}function x(s,d){return!s||!s.op||!d.operators.size?!1:d.operators.has(s.op)}function $(s,d){if(!s)return{pushed:null,residual:null};if(!d.filter)return{pushed:null,residual:s};if(d.filter==="term"){if(ne(s)){const a=s.conditions||[];if(String(s.op)!=="and")return{pushed:null,residual:s};const p=a.findIndex(E=>!ne(E)&&x(E,d));if(p<0)return{pushed:null,residual:s};const m=a.filter((E,v)=>v!==p);return{pushed:a[p],residual:m.length?{op:"and",conditions:m}:null}}return x(s,d)?{pushed:s,residual:null}:{pushed:null,residual:s}}if(!ne(s))return x(s,d)?{pushed:s,residual:null}:{pushed:null,residual:s};if(String(s.op)!=="and")return(s.conditions||[]).every(p=>ne(p)?$(p,d).residual===null:x(p,d))?{pushed:s,residual:null}:{pushed:null,residual:s};const O=[],S=[];for(const a of s.conditions||[]){if(ne(a)){if(d.filter==="flat"){S.push(a);continue}const p=$(a,d);p.pushed&&O.push(p.pushed),p.residual&&S.push(p.residual);continue}(x(a,d)?O:S).push(a)}const l=a=>a.length===0?null:a.length===1?a[0]:{op:"and",conditions:a};return{pushed:l(O),residual:l(S)}}function U(s,d,O,S,l,a,p){const m=Array.isArray(s.groupBy)?s.groupBy:[],E=Array.isArray(s.groupPath)?s.groupPath:[],v=Array.isArray(s.groupValues)?s.groupValues:null;return d.group?j(m)?O.residual?"the filter did not fully push, so the engine would group a superset of the matching rows":S?l?a?"a host `where` predicate can only run in the browser, over rows the engine grouped":p?"fullDataset holds the whole matching set, so the grid groups it itself":!v||v.length!==E.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 H(s,d,O=!1){const S=$(s.filters||null,d),l=[];S.residual&&l.push("filter");const a=s.sort||[],p=a.length===0||d.sort==="multi"&&a.length>=1||d.sort==="single"&&a.length===1;!p&&a.length&&l.push("sort");const m=s.quick?String(s.quick):"",E=!m||!!d.quick;E||l.push("quick");const v=s.where&&s.where.active?s.where:null;v&&l.push("where");const q={filters:S.residual,sort:p?null:a,quick:E?"":m,where:v},be=!!O,ae=Array.isArray(s.groupBy)&&s.groupBy.length>0,re=ae?U(s,d,S,p,E,v,be):"",ce=ae&&re==="";ae&&!ce&&l.push("group");const le=ce&&Array.isArray(s.groupValues)?s.groupValues.length:0,Pe=ce?!1:be||!!(q.filters||q.sort||q.quick||q.where)||!d.range;return{pushed:{...s,filters:S.pushed,sort:p?a:[],quick:E?m:"",range:Pe?null:s.range},residual:q,needsAll:Pe,unpushed:l,full:be,grouped:ce,groupLevel:le,groupReason:re}}function _(s){const d=Array.isArray(s.totals)?s.totals:[],O=s.totalFns&&typeof s.totalFns=="object"?s.totalFns:{},S=[],l=[];for(const a of d){const p=String(a),m=typeof O[p]=="string"?O[p]:null,E=m?A[m]:null;m?!E||!E.pushable||!E.sql?l.push({id:p,fn:m,class:E?E.class:"fallback",reason:E&&E.note?E.note:`the pushdown map cannot express "${m}"`}):E.twoColumn?l.push({id:p,fn:m,class:E.class,reason:`"${m}" reduces two columns, and a grouped request carries no weight column`}):S.push({id:p,col:p,fn:m,class:E.class}):l.push({id:p,fn:null,class:"fallback",reason:"the column totals with a host function, so there is no named statistic to push"})}return{engine:S,client:l}}function X(s,d,O){if(!d)return s;let S=s;if(d.filters&&F(O.evaluateFilters)){const l={count:S.length,handle:m=>({id:m,get:E=>W(S[E],m)})},a=O.evaluateFilters(d.filters,l),p=[];for(let m=0;m<S.length;m++)a[m]&&p.push(S[m]);S=p}if(d.where&&d.where.active&&(d.whole||Te(d.where.names,"pushdown"),S=S.filter(l=>d.where.passes(l))),d.quick){const l=d.quick.toLowerCase();S=S.filter(a=>{if(!a||typeof a!="object")return!1;for(const p of Object.values(a))if(p!=null&&String(p).toLowerCase().includes(l))return!0;return!1})}if(d.sort&&d.sort.length&&F(O.sortMulti)){const l=[...new Set(d.sort.map(E=>E.col))],a=S,p=l.map(E=>({id:E,get:v=>W(a[v],E)})),m=O.sortMulti(p,d.sort.map(E=>({col:E.col,dir:E.dir})),Uint32Array.from({length:S.length},(E,v)=>v),{});S=Array.from(m,E=>a[E])}return S}function ee(s){return JSON.stringify({filters:s.filters||null,sort:s.sort||[],quick:s.quick||"",groupBy:s.groupBy||[],groupPath:s.groupPath||[],context:s.context??null})}function se(s){if(!s||typeof s!="object")return 16;let d="";try{d=JSON.stringify(s)}catch{return 200}return d.length*2+64}function Oe(s){const d=s||{};return{enabled:!!d.enabled,maxRows:Number.isFinite(d.maxRows)?d.maxRows:1e6,maxBytesEstimate:Number.isFinite(d.maxBytesEstimate)?d.maxBytesEstimate:512*1024*1024}}const We=5e4;function f(s){return Number.isFinite(s)&&s>=0?s:We}function I(s){return!!s&&F(s.then)}async function T(s){if(!s||s.total!==void 0||!I(s.pendingTotal))return s;const d=await s.pendingTotal,{pendingTotal:O,...S}=s;return typeof d=="number"?{...S,total:d}:S}function P(s={}){const d=s.adapter;if(!d||!F(d.execute))return Y("source.pushdown.adapter","createPushdownSource needs an `adapter` with an `execute(query)` function."),{...s,mode:"remote",fetch:async()=>({rows:[],total:0})};const O=k(d.capabilities),S=d.name||"adapter",l=Oe(s.fullDataset),a=!!s.allowPartialResults,p=f(s.whereRowLimit);let m=null;const E=s.aggregates;let v=null,q=null,be=null,ae=null,re=null,ce,le=null,Pe=0,Re=null;const De=()=>!l.enabled||!v?null:(Re!==v.key&&(Pe++,Re=v.key),{rows:v.rows,version:Pe}),Ce=async C=>{const J=C.where&&C.where.active?C.where:null;if(!J)return{request:C,probe:null};const{where:L,...oe}=C,ue=H(oe,O,l.enabled);if(ue.needsAll)return{request:C,probe:null};const V=ee(ue.pushed);let Ee=null;return(!m||m.key!==V)&&(O.total?(Ee=await T(await d.execute(ue.pushed,C)),m={key:V,size:Ee&&typeof Ee.total=="number"?Ee.total:null}):m={key:V,size:null}),m.size!==null&&m.size<p?{request:C,probe:null}:(me(J.names,S,m.size,p),{request:oe,probe:Ee})},u=async(C,J)=>{le=null;const L=_(C.pushed);be={engine:L.engine,client:L.client,groupBy:C.pushed.groupBy},L.client.length&&Y(`source.pushdown.group.totals.${S}.${L.client.map(V=>V.id).join(".")}`,`the ${S} adapter cannot compute the group subtotal for ${L.client.map(V=>`"${V.id}" (${V.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 oe=await d.executeGroupLevel(C.pushed,L.engine,J)||{};let ue=oe.rows||[];return!O.range&&J.range&&(ue=ue.slice(J.range.start,J.range.end)),typeof oe.matchCount=="number"&&(ae=oe.matchCount,re=oe.grand?{totals:oe.grand,leafCount:oe.matchCount}:null,ce===void 0&&F(d.unfilteredCount)&&(ce=null,Promise.resolve(d.unfilteredCount()).then(V=>{ce=typeof V=="number"?V:null}).catch(V=>{Y(`source.pushdown.group.unfiltered.${S}`,`the ${S} adapter could not count the unfiltered set (${V&&V.message?V.message:V}), so "N of M" falls back to the display count for its denominator.`)}))),oe.total===void 0?{rows:ue}:{rows:ue,total:oe.total}},c=(C,J)=>{const L={key:J,state:"pending",value:null};return le=L,C.then(oe=>(le===L&&(le={key:J,state:"settled",value:typeof oe=="number"?oe:null}),oe),oe=>{throw le===L&&(le={key:J,state:"failed",value:null}),oe})},g=async C=>{const J=await Ce(C);let L=H(J.request,O,l.enabled);if(L.grouped&&!F(d.executeGroupLevel)&&(Y(`source.pushdown.group.method.${S}`,`the ${S} 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.`),L=H(J.request,{...O,group:!1},l.enabled)),q=L,L.grouped)return u(L,C);if(L.groupReason&&Y(`source.pushdown.group.${S}.${L.groupReason}`,`the ${S} adapter was not asked to group this query because ${L.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.`),!L.needsAll){const K=J.probe||await d.execute(L.pushed,C),Q=K.rows||[];return I(K.pendingTotal)&&K.total===void 0?{rows:Q,pendingTotal:c(K.pendingTotal,ee(L.pushed))}:(le=null,!O.total&&K.total===void 0?{rows:Q}:{rows:Q,total:K.total??Q.length})}L.unpushed.length&&Y(`source.pushdown.residual.${S}.${L.unpushed.join(".")}`,`the ${S} adapter cannot push ${L.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 oe=ee(L.pushed);if(!v||v.key!==oe){const K=await T(await d.execute(L.pushed,C));le=null;const Q=K.rows||[];if(L.full){const pe=typeof K.total=="number"?Math.max(K.total,Q.length):Q.length;if(pe>l.maxRows)throw new Error(`[lattice] fullDataset refused: the ${S} adapter's matching set is ${pe.toLocaleString()} rows, past the configured maxRows of ${l.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 we=Q.length*se(Q[0]);if(we>l.maxBytesEstimate)throw new Error(`[lattice] fullDataset refused: the ${S} adapter's matching set is an estimated ${Math.round(we/(1024*1024)).toLocaleString()} MB across ${Q.length.toLocaleString()} rows, past the configured maxBytesEstimate of ${Math.round(l.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 K.total=="number"&&Q.length<K.total){const pe=!!(L.residual.filters||L.residual.quick||L.residual.sort&&L.residual.sort.length);if(pe&&!a)throw new Error(`[lattice] the ${S} adapter returned ${Q.length} of ${K.total} matching rows when asked for the whole result, and the query has residual ${L.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.`);pe?Y(`source.pushdown.partial.residual.${S}`,`the ${S} adapter returned ${Q.length} of ${K.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.`):Y(`source.pushdown.partial.${S}`,`the ${S} adapter returned ${Q.length} of ${K.total} matching rows when asked for the whole result. The adapter must follow the engine's own paging before returning.`)}v={key:oe,rows:Q,total:typeof K.total=="number"?K.total:null}}let ue=L;if(L.residual.where){const K=v.total??v.rows.length;if(K>=p){me(L.residual.where.names,S,K,p);const{where:Q,...pe}=J.request;ue=H(pe,O,l.enabled),q=ue}}const V=v.total!==null&&v.rows.length>=v.total,Ee=X(v.rows,{...ue.residual,whole:V},s.compute||{}),He=C.range?C.range.start:0,Ne=C.range?C.range.end:Ee.length;return{rows:Ee.slice(He,Ne),total:Ee.length}},R=async(C,J)=>{const L=H(C,O,l.enabled);q=L;const oe=Se(J,E),ue=Array.isArray(C.groupBy)?C.groupBy:[],V=ue.length>0,Ee=!L.residual.filters,He=!V||j(ue);let Ne=oe.engine,K=oe.client;const Q=$e=>{K=[...Ne.map(Ge=>({...Ge,reason:$e})),...K],Ne=[]};Ne.length&&!Ee?Q("residual filter forces all-client (no mixed provenance)"):Ne.length&&!He&&Q("a grouping key the engine cannot form forces all-client (no mixed provenance)");let pe={},we;return Ne.length&&(F(V?d.executeGroupedAggregates:d.executeAggregates)?V?we=await d.executeGroupedAggregates(L.pushed,ue,Ne)||[]:pe=await d.executeAggregates(L.pushed,Ne)||{}:(Y(`source.pushdown.aggregates.${S}${V?".grouped":""}`,`the ${S} adapter cannot compute ${V?"grouped ":""}aggregates, so every requested statistic is computed client-side. Correct, and slower than it needs to be.`),Q(`adapter cannot compute ${V?"grouped ":""}aggregates`))),be={engine:Ne,client:K,...V?{groupBy:ue}:{}},{values:pe,engine:Ne,client:K,...we!==void 0?{groups:we}:{}}},fe=G(s.edit),ye=s.edit&&typeof s.edit=="object"&&F(s.edit.commit);let te=s.edit;if(fe&&!ye)if(O.mutate&&O.mutate.update){const C=J=>{if(!O.mutate||!O.mutate.update)throw new Error(`[lattice] the ${S} 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 L={kind:"update",key:String(J.key),patch:{[J.colId]:J.value}};return d.mutate(L,J.request||{})};te={...s.edit===!0?{}:s.edit,commit:C}}else Y(`source.pushdown.readonly.${S}`,`edit is enabled but the ${S} adapter declares mutate: ${O.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 de=fe&&O.mutate&&(O.mutate.append||O.mutate.delete)?{append:O.mutate.append===!0,remove:O.mutate.delete===!0,returning:O.mutate.returning,mutate:(C,J)=>d.mutate(C,J||{})}:null;return{...s,edit:te,rowMutate:de,mode:"remote",fetch:g,aggregate:R,lastPlan:()=>q?{...q,...be?{aggregates:be}:{},...le?{total:{deferred:!0,state:le.state,value:le.value}}:{}}:null,fullFrame:De,counts:()=>({match:ae,total:ce??null,pending:!!le&&le.state==="pending"}),grandTotals:()=>re}}}),Ve("packages/core/src/model/rowkey.js",function(y,ge){"use strict";Object.defineProperty(y,"KEY_DEPENDENT_FEATURES",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(y,"compositeKey",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(y,"createRowKey",{enumerable:!0,get:function(){return j}}),Object.defineProperty(y,"warnMissingKeys",{enumerable:!0,get:function(){return z}}),Object.defineProperty(y,"groupPathKey",{enumerable:!0,get:function(){return W}}),Object.defineProperty(y,"splitPathKey",{enumerable:!0,get:function(){return G}});const ie=ge("packages/core/src/internal/util.js"),F=ie.warnOnce,Y=ie.pathGetter,Z=ie.isFunction,ne=ie.isBlank,Te=["changes (rows.apply / rows.queue)","streaming dedupe","selection persistence","remote reload","cell comments"],me="";function ke(k){if(k===null)return"\0n";if(k===void 0)return"\0u";const x=typeof k;if(x==="string")return k;if(x==="number"||x==="bigint"||x==="boolean")return String(k);if(k instanceof Date)return`\0d${k.getTime()}`;try{return`\0o${JSON.stringify(k)}`}catch{return"\0o?"}}function Se(k){if(k.length===1)return ke(k[0]);let x="";for(let $=0;$<k.length;$++)$&&(x+=me),x+=ke(k[$]);return x}function j(k,x={}){const $=x.warn!==!1;if(Z(k)){const U=k;return{stable:!0,fields:[],disabled:[],key(H,_){try{const X=U(H);return Array.isArray(X)?Se(X):ke(X)}catch(X){return F("rowKey.throw","rowKey function threw; falling back to index identity for the affected rows.",X),`#${_??-1}`}},keyEmpty(H){try{const _=U(H);return Array.isArray(_)?_.length===0||_.some(ne):ne(_)}catch{return!1}},missingFields(){return[]}}}if(Array.isArray(k)&&k.length>0){const U=k.filter(X=>typeof X=="string"),H=U.map(X=>Y(X)),_=H.length;return{stable:!0,fields:U,disabled:[],key(X){const ee=new Array(_);for(let se=0;se<_;se++)ee[se]=H[se](X);return Se(ee)},keyEmpty(X){for(let ee=0;ee<_;ee++)if(ne(H[ee](X)))return!0;return!1},missingFields(X){const ee=[];for(let se=0;se<_;se++)ne(H[se](X))&&ee.push(U[se]);return ee}}}if(typeof k=="string"&&k.length>0){const U=Y(k);return{stable:!0,fields:[k],disabled:[],key(H){return ke(U(H))},keyEmpty(H){return ne(U(H))},missingFields(H){return ne(U(H))?[k]:[]}}}return $&&F("rowKey.missing",`no rowKey configured, so rows are identified by object identity. This disables: ${Te.join(", ")}. Set rowKey to a field name, an array of field names, or a function.`),{stable:!1,fields:[],disabled:Te.slice(),key(U,H){if(U===null||typeof U!="object")return`#${H??0}:${String(U)}`;let _=A.get(U);return _===void 0&&(_=`#${D++}`,A.set(U,_)),_}}}const A=new WeakMap;let D=0;function z(k,x){if(!k||k.stable===!1||!Z(k.keyEmpty)||!Array.isArray(x)||x.length===0)return;let $=0,U=null,H;for(let se=0;se<x.length;se++){const Oe=x[se];k.keyEmpty(Oe)&&($++,U===null&&(U=Z(k.missingFields)?k.missingFields(Oe):[],H=Oe))}if($===0)return;const _=k.fields.length?k.fields.join(","):"(function)",X=U&&U.length?U.join(", "):k.fields.length?k.fields.join(", "):"the rowKey function",ee=H!==null&&typeof H=="object"?Object.keys(H).join(", ")||"(no fields)":String(H);F(`rowKey.emptyValue:${_}`,`rowKey ${X} is missing on ${$} of ${x.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 W(k){return Se(k)}function G(k){return k.split(me)}}),Ve("packages/modules/data-router/devtools.js",function(y,ge){"use strict";Object.defineProperty(y,"mountRouterDevtools",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(y,"default",{enumerable:!0,get:function(){return Se}});const F=ge("packages/core/src/internal/util.js").warnOnce,Y="lat-router-devtools";function Z(j,A,D){const z=j.createElement(A);return z.textContent=D==null?"—":String(D),z}function ne(j){return Number.isFinite(j)?`${Math.round(j*10)/10}/s`:"—"}function Te(j,A,D,z){const W=j.createElement("section");W.className=`${Y}-section`;const G=j.createElement("h4");G.textContent=A,W.appendChild(G);const k=j.createElement("table"),x=j.createElement("tr");for(const $ of D)x.appendChild(Z(j,"th",$));k.appendChild(x);for(const $ of z){const U=j.createElement("tr");for(const H of $)U.appendChild(Z(j,"td",H));k.appendChild(U)}return W.appendChild(k),W}function me(j,A,D){A.textContent="";const z=Te(j,"Router",["metric","value"],[["throughput",ne(D.throughput)],["unrouted",D.unrouted],["dropped (duplicate)",D.dropped],["buffer depth",D.buffered],["lag (deltas behind)",D.lag]]);A.appendChild(z),A.appendChild(Te(j,"Routes",["#","label","kind","rows","shown","rows/sec"],D.routes.map(W=>[W.index,W.label,W.kind,W.rows,W.shown,ne(W.throughput)]))),D.sources.length&&A.appendChild(Te(j,"Sources",["id","rows","ingested","rows/sec"],D.sources.map(W=>[W.id,W.rows,W.ingested,ne(W.throughput)])))}function ke(j,A,D={}){const z=A&&A.ownerDocument||(typeof document<"u"?document:null);if(!j||typeof j.metrics!="function"||typeof j.on!="function"||!A||!z)return F("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 W=z.createElement("div");W.className=Y,A.appendChild(W);const G=()=>me(z,W,j.metrics());G();const k=j.on("metrics",()=>G());return{refresh:G,destroy(){k(),W.parentNode&&W.parentNode.removeChild(W)}}}const Se=ke}),Ve("packages/modules/data-router/index.js",function(y,ge){"use strict";Object.defineProperty(y,"createDataRouter",{enumerable:!0,get:function(){return se}}),Object.defineProperty(y,"default",{enumerable:!0,get:function(){return We}});const F=ge("packages/core/src/internal/util.js").warnOnce,Y=ge("packages/core/src/source/pushdown.js"),Z=Y.planQuery,ne=Y.capabilitiesOf,me=ge("packages/core/src/model/rowkey.js").compositeKey,Se=ge("packages/modules/data-router/devtools.js").mountRouterDevtools;function j(f,I){return typeof f=="function"?f:typeof f=="string"?T=>T[f]:I}function A(f){return Array.isArray(f)?"array":f===null?"null":typeof f}function D(f,I){if(f===void 0||typeof f=="string"&&f.length>0)return f;if(typeof f=="function")return T=>{const P=f(T);if(typeof P=="string"||typeof P=="number"&&Number.isFinite(P))return P;throw new Error(`lattice-data-router: rowKey function must return a string or number; got ${A(P)}.`)};throw new Error(`lattice-data-router: rowKey must be a property name or a function; composite keys are not supported on ${I}.`)}function z(f){if(typeof f=="function")return f;if(f&&typeof f=="object"&&typeof f.key=="string"){const I=f.dir==="desc"?-1:1,{key:T}=f;return(P,s)=>{const d=P?P[T]:void 0,O=s?s[T]:void 0;return d<O?-1*I:d>O?1*I:0}}return null}function W(f){if(!f||typeof f!="object")return null;let I=0;Number.isFinite(f.minInterval)&&f.minInterval>0?I=Number(f.minInterval):Number.isFinite(f.maxHz)&&f.maxHz>0&&(I=1e3/Number(f.maxHz));const T=Number.isFinite(f.sample)&&f.sample>1?Math.floor(Number(f.sample)):1,P=Number.isFinite(f.maxLag)&&f.maxLag>=0?Math.floor(Number(f.maxLag)):null;return I===0&&T===1&&P===null?null:{minInterval:I,sample:T,maxLag:P}}let G=0;function k(){return G+=1,`r${G}`}function x(f){const T=(Array.isArray(f)?f:[f]).map(P=>({name:typeof P=="string"?P:null,get:j(P,()=>{})}));return P=>{const s={},d=[];for(const O of T){const S=O.get(P);d.push(S),O.name&&(s[O.name]=S)}return{key:me(d),fields:s}}}function $(f,I){if(typeof f=="function")return f(I);if(f&&typeof f=="object"){const{op:T,field:P}=f;if(T==="count")return I.length;const s=P!=null?I.map(d=>Number(d[P])).filter(d=>Number.isFinite(d)):[];if(T==="sum")return s.reduce((d,O)=>d+O,0);if(T==="avg")return s.length?s.reduce((d,O)=>d+O,0)/s.length:0;if(T==="min")return s.length?Math.min(...s):void 0;if(T==="max")return s.length?Math.max(...s):void 0}}function U(f){return f&&typeof f=="object"&&typeof f.from=="string"&&typeof f.to=="string"?{from:f.to,to:f.from}:(F("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."),f)}function H(f,I){return f?I?{op:"and",conditions:[f,I]}:f:I||null}const _=Object.freeze(["eq","ne","lt","lte","gt","gte","between","notBetween","in","notIn","contains","notContains","startsWith","endsWith","blank","notBlank"]);function X(f,I){const T=I?I[f.col]:void 0,P=f.value,s=d=>f.caseSensitive?String(d):String(d).toLowerCase();switch(f.op){case"eq":return T===P;case"ne":return T!==P;case"lt":return T<P;case"lte":return T<=P;case"gt":return T>P;case"gte":return T>=P;case"between":return Array.isArray(P)&&T>=P[0]&&T<=P[1];case"notBetween":return!(Array.isArray(P)&&T>=P[0]&&T<=P[1]);case"in":return Array.isArray(P)&&P.includes(T);case"notIn":return!(Array.isArray(P)&&P.includes(T));case"contains":return T!=null&&s(T).includes(s(P));case"notContains":return T==null||!s(T).includes(s(P));case"startsWith":return T!=null&&s(T).startsWith(s(P));case"endsWith":return T!=null&&s(T).endsWith(s(P));case"blank":return T==null||T==="";case"notBlank":return!(T==null||T==="");default:throw new Error(`[lattice] query() cannot evaluate the residual filter operator "${String(f.op)}" on column "${String(f.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: ${_.join(", ")}.`)}}function ee(f,I){return f?Array.isArray(f.conditions)?f.op==="or"?f.conditions.some(T=>ee(T,I)):f.op==="not"?!f.conditions.every(T=>ee(T,I)):f.conditions.every(T=>ee(T,I)):X(f,I):!0}function se(f={}){const I=j(f.key,()=>{}),T=j(D(f.rowKey,"routes"),e=>e.rowKey),P=!!f.overlap,s=typeof f.onUnrouted=="function"?f.onUnrouted:null,d=Number.isFinite(f.selectionDebounce)?Number(f.selectionDebounce):16,O=typeof f.onWrite=="function"?f.onWrite:null,S=typeof f.onConflict=="function"?f.onConflict:null,l=f.seq!=null?j(f.seq,()=>{}):null,a=l?f.dedupe!==!1:!1,p=T;let m=null;typeof f.batch=="number"?m=f.batch:f.batch&&Number.isFinite(f.batch.intervalMs)&&(m=Number(f.batch.intervalMs));const E=m!==null||!!f.coalesce,v=new Map;let q,be=0;const ae=[];let re=null;const ce=f.time!=null?j(f.time,()=>{}):null,le=typeof f.now=="function"?f.now:Date.now,Pe=1e4;let Re=!1,De=null,Ce=null,u="time",c=new Map;const g=[];let R=0,fe,ye,te=!1,de=null,C=[],J=0,L=0,oe="time",ue=!1,V=null,Ee=null;const He=e=>{if(e&&Number.isFinite(e.seq))return e.seq;if(l&&e&&e.row){const t=l(e.row);return Number.isFinite(t)?t:void 0}},Ne=e=>{if(e&&Number.isFinite(e.t))return e.t;if(ce&&e&&e.row){const t=ce(e.row);if(Number.isFinite(t))return t}return le()},K=[];let Q=null;const pe=[],we=[],$e=new Map,Ge=new Set;let Be=null,xe=0;const _e=new Map,ot=new Set,Ye=typeof f.rowKey=="string"?f.rowKey:"rowKey",Le=new Map;let $t=0;const Mt=new Map,Me=(e,t)=>{Mt.set(e,(Mt.get(e)||0)+t)};let mt=0;const yt=new Map,it=new Map;let Ke=null;const qt=Number.isFinite(f.metricsInterval)?Number(f.metricsInterval):1e3;let ze=0,Ae=null,bt="lattice-router",wt=250,Ie=null,Xe=null,st=!1,vt=!1,Fe=null,et=!1,Et=null;const Ue=[],he=()=>Q?[...K,Q]:K,Je=e=>he().find(t=>t.grid===e)||null,lt=e=>{const t=[];for(const n of K)if(n.match(e)&&(t.push(n),!P))break;return t.length?t:Q?[Q]:[]},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(i=>i&&i.operation==="remove");if(!r.length)return;const o=e.label||`route ${e.routeId}`;F(`data-router:remove-rejected:${e.routeId}`,`route "${o}" 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.`)},ln=(e,t)=>{for(const n of pe)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},qe=e=>{const t=[];for(const h of e.partition.values())e.filter&&!e.filter(h)||ln(e,h)&&t.push(h);let n;if(e.rollup){const h=new Map;for(const b of t){const{key:N,fields:B}=e.rollup.group(b);let M=h.get(N);M||(M={key:N,fields:B,rows:[]},h.set(N,M)),M.rows.push(b)}let w=[];for(const b of h.values()){const N={...b.fields};for(const[B,M]of e.rollup.specs)N[B]=$(M,b.rows);w.push({gkey:b.key,row:N})}e.sort&&w.sort((b,N)=>e.sort(b.row,N.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 h=t;e.sort&&(h=h.slice().sort(e.sort)),n=new Map;for(const w of h)n.set(me([e.keyOf(w)]),e.transform?e.transform(w):w)}const r=[],o=[],i=[];for(const[h,w]of n)e.keys.has(h)?Oe(e.keys.get(h),w)||o.push(w):r.push(w);for(const h of e.keys.keys())n.has(h)||i.push(h);return e.keys=n,on(e,{add:r,update:o,remove:i})},ut=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),qe(e),e.bpPending=0,e.bpLastFlush=le()},un=(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,ut(e)},n),e.bpTimer&&typeof e.bpTimer.unref=="function"&&e.bpTimer.unref()},an=(e,t)=>{if(!e.bp){qe(e);return}e.bpPending+=t,e.bpCoalesced+=t;const n=e.bp;if(n.maxLag!=null&&e.bpPending<=n.maxLag&&!e.bpTimer){ut(e);return}const r=le(),o=r-e.bpLastFlush>=n.minInterval,i=e.bpPending>=n.sample;if(o&&i){ut(e);return}un(e,r)},cn=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),e.bpPending=0,e.bpLastFlush=le()},kt=(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,o=new Set(t.map(i=>i&&i[n]));return i=>o.has(i&&i[r])}return null},Ht=e=>{const t=Je(e),n=e&&e.selection,r=n&&typeof n.keys=="function"?n.keys():[];return!r.length||!t?[]:r.map(o=>t.partition.get(String(o))).filter(o=>o!==void 0)},Ze=e=>{const t=Ht(e.from);e.predicate=t.length?kt(e.relation,t):null},tt=()=>{const e=new Set;for(const t of we)e.add(t.from),e.add(t.to);return e},Qe=()=>{for(const i of he())i.graphPreds=null;if(!we.length)return;const e=tt(),t=new Map;for(const i of e){const h=Ht(i);h.length&&t.set(i,h)}const n=new Map(t);let r=!0,o=(e.size+1)*2;for(;r&&o-- >0;){r=!1;for(const i of e){if(t.has(i))continue;const h=we.filter(M=>M.to===i&&n.has(M.from));if(!h.length)continue;const w=Je(i);if(!w)continue;const b=h.map(M=>kt(M.rel,n.get(M.from))).filter(Boolean),N=[];for(const M of w.partition.values())b.every(ve=>ve(M))&&N.push(M);const B=n.get(i);if(!B||B.length!==N.length)n.set(i,N),r=!0;else{const M=new Set(B);N.some(ve=>!M.has(ve))&&(n.set(i,N),r=!0)}}}for(const i of we){if(!n.has(i.from))continue;const h=kt(i.rel,n.get(i.from));if(!h)continue;const w=Je(i.to);w&&(w.graphPreds||(w.graphPreds=[])).push(h)}},Bt=e=>{const t=$e.get(e);if(t){t.count+=1;return}const n=e&&typeof e.on=="function"?e.on("selection:changed",()=>fn(e)):()=>{};$e.set(e,{off:n,count:1})},St=()=>{Be&&(clearTimeout(Be),Be=null);const e=Ge;if(!e.size)return;const t=new Set;for(const n of pe)e.has(n.from)&&(Ze(n),t.add(n.to));if(Ge.clear(),we.length){Qe();for(const n of tt())t.add(n)}for(const n of t){const r=Je(n);r&&qe(r)}},fn=e=>{if(Ge.add(e),d<=0){St();return}Be||(Be=setTimeout(St,d))},xt=e=>{const t=$e.get(e);t&&(t.count-=1,t.count<=0&&(t.off(),$e.delete(e)))},dn=e=>typeof e=="function"?t=>e(t):e&&e.rows&&typeof e.rows.apply=="function"?t=>e.rows.apply(t):(F("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."),()=>{}),Tt=(e,t,n)=>({grid:e,routeId:k(),sink:dn(e),match:t,keyOf:j(D(n.rowKey,"routes"),T),partition:new Map,keys:new Map,transform:typeof n.transform=="function"?n.transform:null,filter:typeof n.filter=="function"?n.filter:null,sort:z(n.sort),rollup:n.rollup&&n.rollup.groupBy!=null?{group:x(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:W(n.backpressure),bpPending:0,bpTimer:null,bpLastFlush:-1/0,bpCoalesced:0}),Kt=e=>{if(!P){for(const t of K)if(t.hasPartValue&&t.partValue===e){F(`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},at=(e,t)=>{const n=e.grid;if(!n||!n.edit||typeof n.edit.setCells!="function")return;const r=zt(t.key,t.colId);ot.add(r);try{n.edit.setCells([{key:t.key,colId:t.colId,value:t.before}],"cell")}finally{ot.delete(r)}Me("writeReverted",1)},Ut=e=>{e&&je.apply([{op:"upsert",row:e}])},Vt=(e,t,n)=>{const r=n&&typeof n=="object"?n:null,o=r&&r.conflict!==void 0?r.conflict:null;if(o){const i=e.onConflict||S;if(i)try{i(t,{serverRow:o})}catch{}Me("writeConflicted",1),Ut(r&&r.row?r.row:t.row);return}if(n===!1||r&&r.ok===!1){Me("writeRejected",1),at(e,t);return}Me("writeAccepted",1),Ut(r&&r.row?r.row:t.row)},hn=e=>{const t=String(e);for(const n of Le.values())if(n.live.has(t))return n.handle;return null},gn=(e,t)=>{if(!t||t.key===void 0||t.colId===void 0||ot.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(Me("writeRouted",1),e.readonly){F("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."),at(e,r);return}const o=e.onWrite||O;if(!o){F("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 i;try{i=o(r,{route:e.grid,source:hn(r.key)})}catch{at(e,r),Me("writeRejected",1);return}i&&typeof i.then=="function"?i.then(h=>Vt(e,r,h),()=>{at(e,r),Me("writeRejected",1)}):Vt(e,r,i)},mn=e=>{const t=e.grid;if(!t||typeof t.on!="function"||!t.edit||typeof t.edit.setCells!="function"){F("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(_e.has(t))return;const n=t.on("cell:changed",r=>gn(e,r));_e.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},ct=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},Ot=(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 o=String(e.keyOf(r));if(n.op==="delete"){e.partition.delete(o);continue}e.match(r)?e.partition.set(o,r):e.partition.delete(o)}},nt=()=>{const e=new Map;for(const t of he())for(const n of t.partition.values())e.set(String(p(n)),n);return[...e.values()]},Gt=()=>{c=new Map;for(const e of he())for(const t of e.partition.values())c.set(String(p(t)),t);g.length=0,R=0,fe=q,ye=void 0},Jt=()=>{const e=g.shift();e&&(e.op==="del"?c.delete(e.key):c.set(e.key,e.row),fe=e.seq,ye=e.t)},wn=()=>{if(De!=null)for(;g.length>De;)Jt();if(Ce!=null&&g.length){const e=g[g.length-1].t;for(;g.length>1&&e-g[0].t>Ce;)Jt()}},vn=e=>{!e||!e.row||g.push({pos:R++,seq:He(e),t:Ne(e),op:e.op==="delete"?"del":"set",key:String(p(e.row)),row:e.row})},Rt=(e,t)=>t==="seq"?e.seq:e.t,ft=(e,t)=>{const n=new Map(c);for(const r of g){const o=Rt(r,t);if(e!==void 0&&o!==void 0&&o>e)break;r.op==="del"?n.delete(r.key):n.set(r.key,r.row)}return n},dt=e=>{const t=new Map(he().map(n=>[n,[]]));for(const n of e)for(const r of lt(n))t.get(r).push(n);for(const n of he())n.partition=new Map(t.get(n).map(r=>[String(n.keyOf(r)),r]));for(const n of pe)Ze(n);Qe();for(const n of he())qe(n)},jt=e=>Re?!0:(F("data-router:no-buffer",`${e}() needs a buffered window; call router.buffer({ window, max }) first to record one.`),!1),pt=()=>{if(V&&(clearTimeout(V),V=null),ue=!1,C=[],J=0,Ee){const e=Ee;Ee=null,e()}},En=()=>{if(C=[],J=0,Ee){const e=Ee;Ee=null,e()}},kn=()=>{V=null;const e=C[J++];e.op==="del"?de.delete(e.key):de.set(e.key,e.row),dt([...de.values()]),ze=e.pos+1,Pt()};function Pt(){if(!ue){if(J>=C.length){En();return}V=setTimeout(kn,L)}}function ht(e){if(Fe)try{Fe.postMessage(e)}catch{}}function Qt(){return{t:"snapshot",rows:nt(),seq:q,checkpoint:Object.fromEntries(v)}}function Sn(e){const t=e&&e.data;if(!(!t||typeof t!="object")){if(t.t==="hello"){nt().length&&ht(Qt());return}et=!0;try{t.t==="delta"?je.apply(t.deltas||[]):t.t==="snapshot"&&(je.load(t.rows||[]),t.checkpoint&&je.seenThrough(t.checkpoint))}finally{et=!1}}}function Tn(e,t){e.partition=new Map(t.map(n=>[String(e.keyOf(n)),n]))}function On(e,t){const n=t.filter(o=>!o.isDefault),r=t.find(o=>o.isDefault)||null;for(const o of t)o.partition=new Map;for(const o of e){const i=[];for(const w of n)if(w.match(o)&&(i.push(w),!P))break;const h=i.length?i:r?[r]:[];if(!h.length){xe+=1,s&&s(o);continue}for(const w of h)w.partition.set(String(w.keyOf(o)),o)}}const Rn=(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[Ye]}`},_t=(e,t)=>{const n={...e.map?e.map(t):t};return e.ns&&(n[Ye]=e.ns(n)),n},Yt=(e,t)=>{const n=[];for(const r of t||[]){if(!r||!r.row)continue;const o=_t(e,r.row),i=String(o[Ye]);r.op==="delete"?e.live.delete(i):e.live.set(i,o),n.push({...r,row:o})}return e.ingested+=n.length,Me(`source:${e.id}`,n.length),n},jn=e=>({get id(){return e.id},get size(){return e.live.size},load(t){const n=(t||[]).map(i=>_t(e,i)),r=new Map(n.map(i=>[String(i[Ye]),i])),o=[];for(const[i,h]of e.live)r.has(i)||o.push({op:"delete",row:h});for(const i of n)o.push({op:"upsert",row:i});return e.live=r,e.ingested+=n.length,Me(`source:${e.id}`,n.length),At(e,o,i=>je.apply(i)),this},apply(t){return At(e,Yt(e,t),n=>je.apply(n)),this},push(t){return At(e,Yt(e,Array.isArray(t)?t:[t]),n=>je.push(n)),this},remove(){const t=[];for(const n of e.live.values())t.push({op:"delete",row:n});return e.live.clear(),Le.delete(e.id),t.length&&je.apply(t),je}}),Nt=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 F("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 o;if(typeof r=="function")o=r;else if(typeof r=="string")o=ve=>ve[r];else return F("data-router:join-no-localkey","join needs a `localKey` (a field name or fn); ignoring the join."),null;const i=e.foreignKey!=null?e.foreignKey:e.fromKey;let h,w;if(typeof i=="function")h=i,w=i;else if(typeof i=="string")h=ve=>ve[i],w=i;else if(typeof r=="string")h=ve=>ve[r],w=r;else return F("data-router:join-no-foreignkey","join with a fn `localKey` needs an explicit string/fn `foreignKey`; ignoring the join."),null;let b=null;const N=[],B=e.fields!=null?e.fields:e.select;if(typeof B=="function")b=B;else if(Array.isArray(B))for(const ve of B)N.push([String(ve),String(ve)]);else if(B&&typeof B=="object")for(const[ve,rt]of Object.entries(B))N.push([ve,String(rt)]);else F("data-router:join-no-fields","join has no `fields`/`select`; rows pass through unenriched.");let M=e.missing;return M!=="hold"&&M!=="passthrough"&&M!=="null"&&(M!=null&&F("data-router:join-bad-missing",`join.missing "${M}" is not hold|passthrough|null; using "passthrough".`),M="passthrough"),{from:n,localKey:o,foreignKeyFn:h,ffKey:w,pairs:N,selectFn:b,missing:M,keyIndex:new Map,lastFk:new Map,owner:t,probe:null}},Zt=(e,t,n)=>{const r={...t};if(e.selectFn){const o=e.selectFn(n,t);return o&&typeof o=="object"&&Object.assign(r,o),r}for(const[o,i]of e.pairs)r[i]=n?n[o]: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=Le.get(e.from);if(!r)return null;let o;for(o of n);return r.live.get(o)||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 i=e.keyIndex.get(r);i&&(i.delete(t),i.size||e.keyIndex.delete(r))}if(n==null){e.lastFk.set(t,null);return}let o=e.keyIndex.get(n);o||(o=new Set,e.keyIndex.set(n,o)),o.add(t),e.lastFk.set(t,n)},An=(e,t)=>{const n=e.join,r=[];for(const o of t){const i=String(o.row[Ye]);if(o.op==="delete"){en(n,i,null),n.lastFk.delete(i),r.push(o);continue}const h=Nt(n.localKey(o.row));en(n,i,h);const w=Xt(n,o.row,h);w.emit&&r.push({...o,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,o]of e.live){const i=Nt(n.fn(o));if(i==null)continue;let h=n.index.get(i);h||(h=new Set,n.index.set(i,h)),h.add(r),n.prev.set(r,i)}}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 o=new Set;for(const i of t){const h=String(i.row[Ye]);if(i.op==="delete"){const N=r.prev.get(h);if(N!=null){const B=r.index.get(N);B&&(B.delete(h),B.size||r.index.delete(N)),o.add(N)}r.prev.delete(h);continue}const w=Nt(r.fn(i.row)),b=r.prev.get(h);if(b!=null&&b!==w){const N=r.index.get(b);N&&(N.delete(h),N.size||r.index.delete(b)),o.add(b)}if(w!=null){let N=r.index.get(w);N||(N=new Set,r.index.set(w,N)),N.add(h),o.add(w)}r.prev.set(h,w)}if(o.size)for(const i of r.specs)for(const h of o){const w=i.keyIndex.get(h);if(w)for(const b of w){const N=i.owner.live.get(b);if(!N)continue;const B=Xt(i,N,h);n.push(B.emit?{op:"upsert",row:B.row}:{op:"delete",row:N})}}}n.length&&je.apply(n)},At=(e,t,n)=>{n(e.join?An(e,t):t),e.probes&&e.probes.size&&Fn(e,t)},Ft=(e,t,n)=>{const r=yt.get(e);if(yt.set(e,{cur:t,t:n}),!r)return 0;const o=(n-r.t)/1e3;return o<=0?0:(t-r.cur)/o},Dn=()=>{if(!Re)return 0;let e=0;for(const t of g)t.pos>=ze&&(e+=1);return e},Ln=(e,t)=>{const n=it.get(e);if(n)for(const r of n)try{r(t)}catch{}},In=()=>{Ke||qt<=0||(Ke=setInterval(()=>Ln("metrics",je.metrics()),qt),Ke&&typeof Ke.unref=="function"&&Ke.unref())},nn=()=>{Ke&&(clearInterval(Ke),Ke=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 o=null;const i=()=>o||(o=new Promise((h,w)=>{let b;try{b=t.open(n,1)}catch(N){w(N);return}b.onupgradeneeded=()=>{const N=b.result;N.objectStoreNames.contains(r)||N.createObjectStore(r)},b.onsuccess=()=>h(b.result),b.onerror=()=>w(b.error)}),o);return{set(h,w){return i().then(b=>new Promise((N,B)=>{const M=b.transaction(r,"readwrite");M.objectStore(r).put(w,h),M.oncomplete=()=>N(),M.onerror=()=>B(M.error),M.onabort=()=>B(M.error)}))},get(h){return i().then(w=>new Promise((b,N)=>{const M=w.transaction(r,"readonly").objectStore(r).get(h);M.onsuccess=()=>b(M.result),M.onerror=()=>N(M.error)}))},close(){o&&o.then(h=>{try{h.close()}catch{}},()=>{})}}},Wn=()=>Re?[...ft(void 0,u).values()]:nt(),$n=()=>({v:1,world:Wn(),maxSeq:q,checkpoint:Object.fromEntries(v),buffer:Re?{on:!0,max:De,window:Ce,domain:u,pos:R,baseSeq:fe,baseT:ye,base:[...c.entries()],log:g.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;vt=!0;try{je.load(Array.isArray(e.world)?e.world:[])}finally{vt=!1}e.checkpoint&&je.seenThrough(e.checkpoint),Number.isFinite(e.maxSeq)&&(q===void 0||e.maxSeq>q)&&(q=e.maxSeq);const t=e.buffer;if(t&&t.on){Re=!0,De=Number.isFinite(t.max)?t.max:null,Ce=Number.isFinite(t.window)?t.window:null,u=t.domain==="seq"||t.domain==="time"?t.domain:l?"seq":"time",c=new Map(Array.isArray(t.base)?t.base:[]),g.length=0;for(const n of Array.isArray(t.log)?t.log:[])g.push({...n});R=Number.isFinite(t.pos)?t.pos:g.length,fe=t.baseSeq,ye=t.baseT,ze=R}return!0},Dt=()=>{if(!Ae)return Promise.resolve();const e=$n(),t=Promise.resolve().then(()=>Ae.set(bt,e)).catch(()=>{});return Xe=t,t.then(()=>{Xe===t&&(Xe=null)})},Lt=()=>{if(!(!st||!Ae||vt)){if(wt<=0){Dt();return}Ie||(Ie=setTimeout(()=>{Ie=null,Dt()},wt),Ie&&typeof Ie.unref=="function"&&Ie.unref())}},je={attach(e,t,n={}){const r=typeof t!="function",o=r?h=>I(h)===t:t;r&&Kt(t);const i=Tt(e,o,n);return r&&(i.hasPartValue=!0,i.partValue=t),K.push(i),i.writable&&mn(i),this},attachDefault(e,t={}){return Q=Tt(e,()=>!1,t),Q.isDefault=!0,this},subscribe(e,t,n={}){const r=typeof e!="function",o=r?h=>I(h)===e:e;r&&Kt(e);const i=Tt(t,o,n);return r&&(i.hasPartValue=!0,i.partValue=e),K.push(i),this},alert(e,t,n,r={}){const i={match:typeof e=="function"?e:h=>I(h)===e,keyOf:j(D(r.rowKey,"alerts"),T),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 Ue.push(i),Ot(i,nt()),ct(i),this},monitor(e,t,n,r={}){const i={kind:"monitor",match:typeof e=="function"?e:h=>I(h)===e,keyOf:j(D(r.rowKey,"alerts"),T),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 Ue.push(i),Ot(i,nt()),ct(i),()=>{const h=Ue.indexOf(i);h>=0&&Ue.splice(h,1),i.timer&&(clearTimeout(i.timer),i.timer=null),i.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};pe.push(r),Bt(e),Ze(r);const o=Je(t);return o&&qe(o),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;we.push({from:t.from,to:t.to,rel:n}),t.mutual&&we.push({from:t.to,to:t.from,rel:U(n)})}for(const t of tt())Bt(t);Qe();for(const t of tt()){const n=Je(t);n&&qe(n)}return this},flush(){return St(),this},detach(e){const t=new Set;for(let o=pe.length-1;o>=0;o--){const i=pe[o];(i.from===e||i.to===e)&&(i.to!==e&&t.add(i.to),xt(i.from),pe.splice(o,1))}let n=!1;for(let o=we.length-1;o>=0;o--)(we[o].from===e||we[o].to===e)&&(xt(we[o].from),we.splice(o,1),n=!0);for(let o=K.length-1;o>=0;o--)K[o].grid===e&&K.splice(o,1);Q&&Q.grid===e&&(Q=null),Ge.delete(e);const r=_e.get(e);if(r&&(r(),_e.delete(e)),n){Qe();for(const o of tt())t.add(o)}for(const o of t){const i=Je(o);i&&qe(i)}return this},load(e){xe=0;const t=new Map(he().map(r=>[r,[]]));for(const r of e||[]){const o=lt(r);if(!o.length){xe+=1,s&&s(r);continue}for(const i of o)t.get(i).push(r)}for(const r of he()){const o=t.get(r);r.partition=new Map(o.map(i=>[String(r.keyOf(i)),i])),r.metricRows+=o.length,mt+=o.length}if(l)for(const r of e||[]){const o=l(r);if(!Number.isFinite(o))continue;const i=String(p(r)),h=v.get(i);(h===void 0||o>h)&&v.set(i,o),(q===void 0||o>q)&&(q=o)}for(const r of pe)Ze(r);Qe();for(const r of Ue)Ot(r,e||[]),ct(r);for(const r of he())r.bp&&cn(r);const n=he().map(r=>qe(r));return Re&&Gt(),ze=R,Fe&&!et&&ht(Qt()),Lt(),n},apply(e){let t=(e||[]).filter(o=>o&&o.row);if(a){t=t.map((i,h)=>[i,h]).sort((i,h)=>{const w=He(i[0]),b=He(h[0]);return w===void 0||b===void 0?i[1]-h[1]:w-b||i[1]-h[1]}).map(i=>i[0]);const o=[];for(const i of t){const h=He(i);if(h!==void 0){const w=String(p(i.row)),b=v.get(w);if(b!==void 0&&h<=b){be+=1;continue}v.set(w,h),(q===void 0||h>q)&&(q=h)}o.push(i)}t=o}if(Fe&&!et&&t.length&&ht({t:"delta",deltas:t.map(o=>({op:o.op,row:o.row,seq:o.seq}))}),Re){for(const o of t)vn(o);wn()}for(const o of Ue)bn(o,t),ct(o);if(te){Lt();return}const n=new Map(he().map(o=>[o,new Map]));for(const o of t){const i=o&&o.row;if(!i)continue;if(o.op==="delete"){let w=!1;for(const b of he()){const N=String(b.keyOf(i));(b.partition.has(N)||n.get(b).has(N))&&(n.get(b).set(N,{op:"del"}),w=!0)}!w&&!lt(i).length&&(xe+=1,s&&s(o));continue}const h=lt(i);if(!h.length){xe+=1,s&&s(o);continue}for(const w of he()){if(h.includes(w))continue;const b=String(w.keyOf(i));(w.partition.has(b)||n.get(w).get(b)?.op==="set")&&n.get(w).set(b,{op:"del"})}for(const w of h)n.get(w).set(String(w.keyOf(i)),{op:"set",row:i})}const r=new Map;for(const o of he()){let i=0;const h=n.get(o).size;for(const[w,b]of n.get(o)){if(b.op==="del"){o.partition.delete(w);continue}o.partition.set(w,b.row),i+=1}o.metricRows+=i,mt+=i,r.set(o,h)}for(const o of pe)Ze(o);Qe();for(const o of he())an(o,r.get(o)||0);ze=R,Lt()},push(e){const t=Array.isArray(e)?e:[e];if(!E)return this.apply(t),this;for(const n of t)ae.push(n);return m!==null&&(m<=0?this.flushStream():re||(re=setTimeout(()=>this.flushStream(),m))),this},flushStream(){if(re&&(clearTimeout(re),re=null),!ae.length)return this;const e=ae.splice(0,ae.length);return this.apply(e),this},flushBackpressure(){for(const e of he())e.bp&&(e.bpTimer||e.bpPending>0)&&ut(e);return this},addSource(e,t){let n,r;e&&typeof e=="object"?(r=e,n=r.id!=null?String(r.id):`source${++$t}`):(n=e!=null?String(e):`source${++$t}`,r=t||{});const o=Le.get(n);if(o)return F("data-router:duplicate-source",`addSource("${n}") was already registered; returning the existing source handle. Use a distinct id per feed.`),o.handle;const i={id:n,map:typeof r.map=="function"?r.map:null,ns:Rn(n,r.key),live:new Map,ingested:0};i.handle=jn(i),i.join=Pn(r.join,i),Le.set(n,i),i.join&&Le.has(i.join.from)&&tn(Le.get(i.join.from),i.join);for(const h of Le.values())h!==i&&h.join&&h.join.from===n&&h.join.probe==null&&tn(i,h.join);return i.handle},removeSource(e){const t=e&&typeof e=="object"&&e.id!==void 0?String(e.id):String(e),n=Le.get(t);return n&&n.handle.remove(),this},sources(){return[...Le.keys()]},metrics(){const e=le(),t=he().map((r,o)=>({index:o,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:Ft(`route:${o}`,r.metricRows,e),backpressure:r.bp?{pending:r.bpPending,coalesced:r.bpCoalesced}:null})),n=[...Le.values()].map(r=>({id:r.id,rows:r.live.size,ingested:r.ingested,throughput:Ft(`source:${r.id}`,r.ingested,e)}));return{routes:t,sources:n,unrouted:xe,dropped:be,buffered:g.length,lag:Dn(),throughput:Ft("total",mt,e)}},on(e,t){if(typeof t!="function")return()=>{};let n=it.get(e);return n||(n=new Set,it.set(e,n)),n.add(t),e==="metrics"&&In(),()=>{n.delete(t),e==="metrics"&&n.size===0&&nn()}},mountDevtools(e,t={}){return Se(this,e,t)},get unrouted(){return xe},get dropped(){return be},lastSeq(){return q},checkpoint(){return new Map(v)},seenThrough(e){const t=e instanceof Map?e.entries():Object.entries(e||{});for(const[n,r]of t){const o=Number(r);if(!Number.isFinite(o))continue;const i=v.get(String(n));(i===void 0||o>i)&&v.set(String(n),o),(q===void 0||o>q)&&(q=o)}return this},persist(e={}){if(st=!0,typeof e.key=="string"&&(bt=e.key),Number.isFinite(e.debounce)&&(wt=Number(e.debounce)),e.storage&&typeof e.storage.get=="function"&&typeof e.storage.set=="function")Ae=e.storage;else{let t=null;try{t=Cn(e)}catch{t=null}t?Ae=t:(Ae=null,F("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(!Ae)return!1;let e;try{e=await Ae.get(bt)}catch{return!1}return e==null?!1:Mn(e)},async flushPersist(){return Ie&&(clearTimeout(Ie),Ie=null),await Dt(),Xe&&await Xe,this},get persisting(){return st&&!!Ae},buffer(e={}){return Re=!0,Number.isFinite(e.max)?De=Number(e.max):"max"in e&&e.max==null&&(De=null),Number.isFinite(e.window)?Ce=Number(e.window):"window"in e&&e.window==null&&(Ce=null),De==null&&Ce==null&&(De=Pe,F("data-router:buffer-default-cap",`buffer() called with no window or max; applying a default cap of ${Pe} deltas so the buffer stays bounded. Pass { window } or { max } to size it.`)),u=l?"seq":"time",Gt(),this},scrubTo(e,t={}){if(!jt("scrubTo"))return this;pt(),te=!0;const n=t.by||u;de=ft(e,n),dt([...de.values()]),ze=0;for(const r of g){const o=Rt(r,n);if(e!==void 0&&o!==void 0&&o>e)break;ze=r.pos+1}return this},replay(e,t,n={}){if(!jt("replay"))return Promise.resolve();pt(),te=!0;const r=n.by||u;return oe=r,L=Number.isFinite(n.speed)?Number(n.speed):0,de=ft(e,r),dt([...de.values()]),C=g.filter(o=>{const i=Rt(o,r);return i!==void 0&&i>e&&i<=t}).slice().sort((o,i)=>o.pos-i.pos),J=0,ue=!1,new Promise(o=>{Ee=o,Pt()})},pause(){return ue=!0,V&&(clearTimeout(V),V=null),this},resume(){return ue?(ue=!1,Pt(),this):this},live(){return jt("live")?(pt(),te=!1,de=null,dt([...ft(void 0,u).values()]),ze=R,this):this},get traveling(){return te},get buffered(){return g.length},broadcast(e={}){if(typeof BroadcastChannel!="function")return F("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?(Fe&&(Fe.close(),Fe=null),Fe=new BroadcastChannel(t),Fe.onmessage=Sn,ht({t:"hello"}),this):(F("data-router:broadcast-channel","router.broadcast({ channel }) needs a string channel name; nothing was mirrored."),this)},get broadcasting(){return!!Fe},async query(e,t={}){if(!e||typeof e.execute!="function")return F("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=ne(e.capabilities),r=t||{},o=r.filters||null,i=[];xe=0;const h=he().filter(b=>b.where),w=he().filter(b=>!b.where);for(const b of h){const N=H(o,b.where),B=Z({...r,filters:N},n);let ve=((await e.execute(B.pushed,r)).rows||[]).slice();B.residual&&B.residual.filters&&(ve=ve.filter(rt=>ee(B.residual.filters,rt))),ve=ve.filter(rt=>b.match(rt)),Tn(b,ve),i.push({route:b.grid,pushedFilter:!!(B.pushed&&B.pushed.filters),residual:B.unpushed.slice()})}if(w.length){const b=Z(r,n);let B=((await e.execute(b.pushed,r)).rows||[]).slice();b.residual&&b.residual.filters&&(B=B.filter(M=>ee(b.residual.filters,M))),On(B,w),i.push({base:!0,pushedFilter:!!(b.pushed&&b.pushed.filters),residual:b.unpushed.slice()})}Et=i;for(const b of pe)Ze(b);Qe();for(const b of he())qe(b);return this},lastQueryPlan(){return Et?Et.map(e=>({...e})):null},destroy(){if(Be&&(clearTimeout(Be),Be=null),re&&(clearTimeout(re),re=null),Ie&&(clearTimeout(Ie),Ie=null),Ae&&typeof Ae.close=="function")try{Ae.close()}catch{}st=!1,Ae=null,Fe&&(Fe.close(),Fe=null),et=!1,pt(),Re=!1,te=!1,de=null,g.length=0,c.clear();for(const e of $e.values())e.off();$e.clear();for(const e of _e.values())e();_e.clear(),ot.clear(),Le.clear(),nn(),it.clear(),yt.clear();for(const e of Ue)e.timer&&(clearTimeout(e.timer),e.timer=null);Ue.length=0;for(const e of he())e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null);pe.length=0,we.length=0,Ge.clear(),ae.length=0,v.clear(),K.length=0,Q=null}};return f.config&&je.configure(f.config),je}function Oe(f,I){if(f===I)return!0;if(!f||!I)return!1;const T=Object.keys(f),P=Object.keys(I);if(T.length!==P.length)return!1;for(const s of T)if(f[s]!==I[s])return!1;return!0}const We=se});var gt=Wt("packages/modules/data-router/index.js");typeof module=="object"&&module.exports?module.exports=gt:typeof define=="function"&&define.amd?define(function(){return gt}):rn.LatticeGridDataRouter=gt})(typeof globalThis<"u"?globalThis:this);
7
7
 
8
8
  //# sourceMappingURL=data-router.min.js.map
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Lattice Grid 1.71.1, devtools module type declarations
2
+ * Lattice Grid 1.71.3, devtools module type declarations
3
3
  * Copyright (c) 2026 TOCLOCO Inc. All rights reserved.
4
4
  * https://latticegrid.dev
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Lattice Grid 1.71.1, devtools module
2
+ * Lattice Grid 1.71.3, devtools module
3
3
  * Copyright (c) 2026 TOCLOCO Inc. All rights reserved.
4
4
  * https://latticegrid.dev
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Lattice Grid 1.71.1, devtools module
2
+ * Lattice Grid 1.71.3, devtools module
3
3
  * Copyright (c) 2026 TOCLOCO Inc. All rights reserved.
4
4
  * https://latticegrid.dev
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Lattice Grid 1.71.1, devtools module
2
+ * Lattice Grid 1.71.3, devtools module
3
3
  * Copyright (c) 2026 TOCLOCO Inc. All rights reserved.
4
4
  * https://latticegrid.dev
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Lattice Grid 1.71.1, dhtmlx-compat module type declarations
2
+ * Lattice Grid 1.71.3, dhtmlx-compat module type declarations
3
3
  * Copyright (c) 2026 TOCLOCO Inc. All rights reserved.
4
4
  * https://latticegrid.dev
5
5
  */