@toclocoinc/lattice-grid 1.80.0 → 1.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/angular/package.json +1 -1
- package/docs/API.html +4 -4
- package/docs/THEMING.md +6 -3
- package/docs/api/adapters.html +1 -1
- package/docs/api/ai.html +1 -1
- package/docs/api/alarms.html +1 -1
- package/docs/api/charts.html +1 -1
- package/docs/api/dashboard.html +1 -1
- package/docs/api/data-router.html +1 -1
- package/docs/api/deckgl.html +1 -1
- package/docs/api/gantt.html +1 -1
- package/docs/api/geometry.html +1 -1
- package/docs/api/grid.html +2 -2
- package/docs/api/index.html +1 -1
- package/docs/api/kanban.html +1 -1
- package/docs/api/kpi.html +1 -1
- package/docs/api/layout.html +1 -1
- package/docs/api/leaflet.html +1 -1
- package/docs/api/list.html +1 -1
- package/docs/api/mock-socket.html +1 -1
- package/docs/api/presets.html +1 -1
- package/docs/api/tabs.html +1 -1
- package/docs/api/types.html +1 -1
- package/docs/api-detail.html +4 -4
- package/docs/warnings.json +1 -1
- package/lattice-grid.d.ts +1 -1
- package/lattice-grid.esm.min.js +3 -3
- package/lattice-grid.min.cjs +3 -3
- package/lattice-grid.min.css +1 -1
- package/lattice-grid.min.js +3 -3
- package/modules/ai.d.ts +1 -1
- package/modules/ai.esm.min.js +2 -2
- package/modules/ai.min.cjs +2 -2
- package/modules/ai.min.js +2 -2
- package/modules/alarms.d.ts +1 -1
- package/modules/alarms.esm.min.js +2 -2
- package/modules/alarms.min.cjs +2 -2
- package/modules/alarms.min.js +2 -2
- package/modules/angular.d.ts +1 -1
- package/modules/angular.esm.min.js +2 -2
- package/modules/angular.min.cjs +2 -2
- package/modules/angular.min.js +2 -2
- package/modules/chart-alluvial.d.ts +1 -1
- package/modules/chart-alluvial.esm.min.js +1 -1
- package/modules/chart-alluvial.min.cjs +1 -1
- package/modules/chart-alluvial.min.js +1 -1
- package/modules/chart-arc.d.ts +1 -1
- package/modules/chart-arc.esm.min.js +1 -1
- package/modules/chart-arc.min.cjs +1 -1
- package/modules/chart-arc.min.js +1 -1
- package/modules/chart-bubblemap.d.ts +1 -1
- package/modules/chart-bubblemap.esm.min.js +1 -1
- package/modules/chart-bubblemap.min.cjs +1 -1
- package/modules/chart-bubblemap.min.js +1 -1
- package/modules/chart-bump.d.ts +1 -1
- package/modules/chart-bump.esm.min.js +1 -1
- package/modules/chart-bump.min.cjs +1 -1
- package/modules/chart-bump.min.js +1 -1
- package/modules/chart-calendar.d.ts +1 -1
- package/modules/chart-calendar.esm.min.js +1 -1
- package/modules/chart-calendar.min.cjs +1 -1
- package/modules/chart-calendar.min.js +1 -1
- package/modules/chart-choropleth.d.ts +1 -1
- package/modules/chart-choropleth.esm.min.js +1 -1
- package/modules/chart-choropleth.min.cjs +1 -1
- package/modules/chart-choropleth.min.js +1 -1
- package/modules/chart-decomposition.d.ts +1 -1
- package/modules/chart-decomposition.esm.min.js +1 -1
- package/modules/chart-decomposition.min.cjs +1 -1
- package/modules/chart-decomposition.min.js +1 -1
- package/modules/chart-diverging.d.ts +1 -1
- package/modules/chart-diverging.esm.min.js +1 -1
- package/modules/chart-diverging.min.cjs +1 -1
- package/modules/chart-diverging.min.js +1 -1
- package/modules/chart-dumbbell.d.ts +1 -1
- package/modules/chart-dumbbell.esm.min.js +1 -1
- package/modules/chart-dumbbell.min.cjs +1 -1
- package/modules/chart-dumbbell.min.js +1 -1
- package/modules/chart-fan.d.ts +1 -1
- package/modules/chart-fan.esm.min.js +1 -1
- package/modules/chart-fan.min.cjs +1 -1
- package/modules/chart-fan.min.js +1 -1
- package/modules/chart-hexbin.d.ts +1 -1
- package/modules/chart-hexbin.esm.min.js +1 -1
- package/modules/chart-hexbin.min.cjs +1 -1
- package/modules/chart-hexbin.min.js +1 -1
- package/modules/chart-hexmap.d.ts +1 -1
- package/modules/chart-hexmap.esm.min.js +1 -1
- package/modules/chart-hexmap.min.cjs +1 -1
- package/modules/chart-hexmap.min.js +1 -1
- package/modules/chart-icicle.d.ts +1 -1
- package/modules/chart-icicle.esm.min.js +1 -1
- package/modules/chart-icicle.min.cjs +1 -1
- package/modules/chart-icicle.min.js +1 -1
- package/modules/chart-markermap.d.ts +1 -1
- package/modules/chart-markermap.esm.min.js +1 -1
- package/modules/chart-markermap.min.cjs +1 -1
- package/modules/chart-markermap.min.js +1 -1
- package/modules/chart-parallel.d.ts +1 -1
- package/modules/chart-parallel.esm.min.js +1 -1
- package/modules/chart-parallel.min.cjs +1 -1
- package/modules/chart-parallel.min.js +1 -1
- package/modules/chart-ridgeline.d.ts +1 -1
- package/modules/chart-ridgeline.esm.min.js +1 -1
- package/modules/chart-ridgeline.min.cjs +1 -1
- package/modules/chart-ridgeline.min.js +1 -1
- package/modules/chart-roc.d.ts +1 -1
- package/modules/chart-roc.esm.min.js +1 -1
- package/modules/chart-roc.min.cjs +1 -1
- package/modules/chart-roc.min.js +1 -1
- package/modules/chart-slope.d.ts +1 -1
- package/modules/chart-slope.esm.min.js +1 -1
- package/modules/chart-slope.min.cjs +1 -1
- package/modules/chart-slope.min.js +1 -1
- package/modules/chart-splom.d.ts +1 -1
- package/modules/chart-splom.esm.min.js +1 -1
- package/modules/chart-splom.min.cjs +1 -1
- package/modules/chart-splom.min.js +1 -1
- package/modules/chart-waffle.d.ts +1 -1
- package/modules/chart-waffle.esm.min.js +1 -1
- package/modules/chart-waffle.min.cjs +1 -1
- package/modules/chart-waffle.min.js +1 -1
- package/modules/charts.d.ts +1 -1
- package/modules/charts.esm.min.js +2 -2
- package/modules/charts.min.cjs +2 -2
- package/modules/charts.min.js +2 -2
- package/modules/dashboard.d.ts +1 -1
- package/modules/dashboard.esm.min.js +2 -2
- package/modules/dashboard.min.cjs +2 -2
- package/modules/dashboard.min.js +2 -2
- package/modules/data-router.d.ts +1 -1
- package/modules/data-router.esm.min.js +2 -2
- package/modules/data-router.min.cjs +2 -2
- package/modules/data-router.min.js +2 -2
- package/modules/deckgl.d.ts +1 -1
- package/modules/deckgl.esm.min.js +2 -2
- package/modules/deckgl.min.cjs +2 -2
- package/modules/deckgl.min.js +2 -2
- package/modules/devtools.d.ts +1 -1
- package/modules/devtools.esm.min.js +1 -1
- package/modules/devtools.min.cjs +1 -1
- package/modules/devtools.min.js +1 -1
- package/modules/dhtmlx-compat.d.ts +1 -1
- package/modules/dhtmlx-compat.esm.min.js +2 -2
- package/modules/dhtmlx-compat.min.cjs +2 -2
- package/modules/dhtmlx-compat.min.js +2 -2
- package/modules/gantt.d.ts +1 -1
- package/modules/gantt.esm.min.js +2 -2
- package/modules/gantt.min.cjs +2 -2
- package/modules/gantt.min.js +2 -2
- package/modules/geo-europe-nuts.d.ts +1 -1
- package/modules/geo-europe-nuts.esm.min.js +1 -1
- package/modules/geo-europe-nuts.min.cjs +1 -1
- package/modules/geo-europe-nuts.min.js +1 -1
- package/modules/geo-uk.d.ts +1 -1
- package/modules/geo-uk.esm.min.js +1 -1
- package/modules/geo-uk.min.cjs +1 -1
- package/modules/geo-uk.min.js +1 -1
- package/modules/geo-us-states.d.ts +1 -1
- package/modules/geo-us-states.esm.min.js +1 -1
- package/modules/geo-us-states.min.cjs +1 -1
- package/modules/geo-us-states.min.js +1 -1
- package/modules/geo-world-110m.d.ts +1 -1
- package/modules/geo-world-110m.esm.min.js +1 -1
- package/modules/geo-world-110m.min.cjs +1 -1
- package/modules/geo-world-110m.min.js +1 -1
- package/modules/geo-world-50m.d.ts +1 -1
- package/modules/geo-world-50m.esm.min.js +1 -1
- package/modules/geo-world-50m.min.cjs +1 -1
- package/modules/geo-world-50m.min.js +1 -1
- package/modules/geometry.d.ts +1 -1
- package/modules/geometry.esm.min.js +2 -2
- package/modules/geometry.min.cjs +2 -2
- package/modules/geometry.min.js +2 -2
- package/modules/htmx.d.ts +1 -1
- package/modules/htmx.esm.min.js +3 -3
- package/modules/htmx.min.cjs +3 -3
- package/modules/htmx.min.js +3 -3
- package/modules/kanban.d.ts +1 -1
- package/modules/kanban.esm.min.js +2 -2
- package/modules/kanban.min.cjs +2 -2
- package/modules/kanban.min.js +2 -2
- package/modules/kpi.d.ts +1 -1
- package/modules/kpi.esm.min.js +2 -2
- package/modules/kpi.min.cjs +2 -2
- package/modules/kpi.min.js +2 -2
- package/modules/layout.d.ts +1 -1
- package/modules/layout.esm.min.js +2 -2
- package/modules/layout.min.cjs +2 -2
- package/modules/layout.min.js +2 -2
- package/modules/leaflet.d.ts +1 -1
- package/modules/leaflet.esm.min.js +2 -2
- package/modules/leaflet.min.cjs +2 -2
- package/modules/leaflet.min.js +2 -2
- package/modules/list.d.ts +1 -1
- package/modules/list.esm.min.js +2 -2
- package/modules/list.min.cjs +2 -2
- package/modules/list.min.js +2 -2
- package/modules/mock-socket.d.ts +1 -1
- package/modules/mock-socket.esm.min.js +1 -1
- package/modules/mock-socket.min.cjs +1 -1
- package/modules/mock-socket.min.js +1 -1
- package/modules/presets/antd5.css +23 -0
- package/modules/presets/bootstrap5.css +46 -5
- package/modules/presets/fluent2.css +31 -4
- package/modules/presets/material3.css +53 -5
- package/modules/presets.d.ts +1 -1
- package/modules/presets.esm.min.js +2 -2
- package/modules/presets.min.cjs +2 -2
- package/modules/presets.min.js +2 -2
- package/modules/react.d.ts +1 -1
- package/modules/react.esm.min.js +2 -2
- package/modules/react.min.cjs +2 -2
- package/modules/react.min.js +2 -2
- package/modules/svelte.d.ts +1 -1
- package/modules/svelte.esm.min.js +2 -2
- package/modules/svelte.min.cjs +2 -2
- package/modules/svelte.min.js +2 -2
- package/modules/tabs.d.ts +1 -1
- package/modules/tabs.esm.min.js +2 -2
- package/modules/tabs.min.cjs +2 -2
- package/modules/tabs.min.js +2 -2
- package/modules/vue.d.ts +1 -1
- package/modules/vue.esm.min.js +2 -2
- package/modules/vue.min.cjs +2 -2
- package/modules/vue.min.js +2 -2
- package/modules/webcomponent.d.ts +1 -1
- package/modules/webcomponent.esm.min.js +3 -3
- package/modules/webcomponent.min.cjs +3 -3
- package/modules/webcomponent.min.js +3 -3
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Lattice Grid 1.
|
|
2
|
+
* Lattice Grid 1.81.0, data-router module
|
|
3
3
|
* Copyright (c) 2026 TOCLOCO Inc. All rights reserved.
|
|
4
4
|
* https://latticegrid.dev
|
|
5
5
|
*/
|
|
6
|
-
var sn=Object.create(null),an=Object.create(null);function st(p,Oe){sn[p]=Oe}function un(p){var Oe=an[p];if(Oe)return Oe;var pe=Object.create(null);an[p]=pe;var V=sn[p];if(!V)throw new Error("[lattice] missing module: "+p);return V(pe,un),pe}st("packages/core/src/internal/util.js",function(p,Oe){"use strict";Object.defineProperty(p,"VERSION",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(p,"reportedWarnings",{enumerable:!0,get:function(){return L}}),Object.defineProperty(p,"warnOnce",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(p,"infoOnce",{enumerable:!0,get:function(){return K}}),Object.defineProperty(p,"resetWarnings",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(p,"fail",{enumerable:!0,get:function(){return E}}),Object.defineProperty(p,"invariant",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(p,"DEV",{enumerable:!0,get:function(){return he}}),Object.defineProperty(p,"isObject",{enumerable:!0,get:function(){return U}}),Object.defineProperty(p,"isFunction",{enumerable:!0,get:function(){return se}}),Object.defineProperty(p,"isNil",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(p,"isBlank",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(p,"isCtor",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(p,"pathGetter",{enumerable:!0,get:function(){return De}}),Object.defineProperty(p,"pathSetter",{enumerable:!0,get:function(){return c}}),Object.defineProperty(p,"getPath",{enumerable:!0,get:function(){return q}}),Object.defineProperty(p,"setPath",{enumerable:!0,get:function(){return O}}),Object.defineProperty(p,"humanise",{enumerable:!0,get:function(){return A}}),Object.defineProperty(p,"escapeHtml",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(p,"titleCase",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(p,"expand",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(p,"toArray",{enumerable:!0,get:function(){return d}}),Object.defineProperty(p,"merge",{enumerable:!0,get:function(){return S}}),Object.defineProperty(p,"mergeRow",{enumerable:!0,get:function(){return P}}),Object.defineProperty(p,"Lru",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(p,"collator",{enumerable:!0,get:function(){return de}}),Object.defineProperty(p,"defaultCompare",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(p,"now",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(p,"nextFrame",{enumerable:!0,get:function(){return l}}),Object.defineProperty(p,"cancelFrame",{enumerable:!0,get:function(){return w}}),Object.defineProperty(p,"frameBatched",{enumerable:!0,get:function(){return H}}),Object.defineProperty(p,"settleDebounce",{enumerable:!0,get:function(){return y}}),Object.defineProperty(p,"whenIdle",{enumerable:!0,get:function(){return F}}),Object.defineProperty(p,"uid",{enumerable:!0,get:function(){return M}});const pe="1.80.0";async function V(){return pe}const oe="1.80.0",ve=new Set,ee=2e3;function ke(i){if(ve.add(i),ve.size>ee){const u=ve.values().next().value;u!==void 0&&ve.delete(u)}}const N=[],ye=500;function be(i,u,f){N.push({key:i,level:u,message:f.map(j=>typeof j=="string"?j:T(j)).join(" "),at:Date.now()}),N.length>ye&&N.shift()}function T(i){if(i instanceof Error)return i.message;try{return JSON.stringify(i)}catch{return String(i)}}function L(){return N.map(i=>({...i}))}function B(i){if(i.length===0||typeof i[0]!="string")return i;const u=i[0].replace(/^\[lattice\]\s*/,"");return u===i[0]?i:[u,...i.slice(1)]}function Q(i,...u){if(ve.has(i))return;ke(i);const f=B(u);be(i,"warn",f),console.warn("[lattice]",...f)}function K(i,...u){if(ve.has(i))return;ke(i);const f=B(u);be(i,"info",f),console.info("[lattice]",...f)}function ce(){ve.clear(),N.length=0}function E(i,u){const f=new Error(`[lattice] ${i}`);throw u!==void 0&&(f.cause=u),f}function ie(i,u){i||E(u)}const he=(()=>{try{return!(typeof process<"u"&&process.env&&process.env.NODE_ENV==="production")}catch{return!0}})();function U(i){return i!==null&&typeof i=="object"&&!Array.isArray(i)}function se(i){return typeof i=="function"}function fe(i){return i==null}function ge(i){return i==null||i===""}function Se(i){return typeof i!="function"?!1:/^class[\s{]/.test(Function.prototype.toString.call(i))?!0:!!(i.prototype&&Object.getOwnPropertyNames(i.prototype).length>1)}const Ee=new Map;function De(i){let u=Ee.get(i);if(u)return u;if(!i.includes("."))u=f=>f?.[i];else{const f=i.split("."),j=f.length;u=Z=>{let me=Z;for(let J=0;J<j;J++){if(me==null)return;me=me[f[J]]}return me}}return Ee.set(i,u),u}const tt=new Map;function c(i){let u=tt.get(i);if(u)return u;if(!i.includes("."))u=(f,j)=>{f!=null&&(f[i]=j)};else{const f=i.split("."),j=f.length-1;u=(Z,me)=>{let J=Z;for(let Pe=0;Pe<j;Pe++){if(J==null)return;const Ie=f[Pe];J[Ie]==null&&(J[Ie]={}),J=J[Ie]}J!=null&&(J[f[j]]=me)}}return tt.set(i,u),u}function q(i,u){return De(u)(i)}function O(i,u,f){c(u)(i,f)}function A(i){return i?(i.includes(".")?i.slice(i.lastIndexOf(".")+1):i).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(/^./,f=>f.toUpperCase()):""}const _={"&":"&","<":"<",">":">",'"':""","'":"'"};function ae(i){const u=i==null?"":String(i);return/[&<>"']/.test(u)?u.replace(/[&<>"']/g,f=>_[f]):u}function Te(i){return String(i).replace(/\w\S*/g,u=>u[0].toUpperCase()+u.slice(1).toLowerCase())}function Ze(i,u,f){if(i!==void 0)return i===!0?{enabled:!0,...f}:i===!1?{enabled:!1}:U(i)?i:{[u]:i,enabled:!0}}function d(i){return i==null?[]:Array.isArray(i)?i:[i]}const g=Object.freeze(new Set(["__proto__","constructor","prototype"]));function S(i,u){if(!U(i))return U(u)?{...u}:u;if(!U(u))return u===void 0?i:u;const f={...i};for(const j of Object.keys(u)){if(g.has(j))continue;const Z=u[j];Z!==void 0&&(f[j]=U(Z)&&U(f[j])?S(f[j],Z):Z)}return f}function P(i,u){if(!U(i)||!U(u)||i===u)return u;const f=Object.create(Object.getPrototypeOf(i));return Object.assign(f,i,u),f}class ne{#e;#t=new Map;#n;constructor(u=256,f=null){this.#e=u,this.#n=f}get size(){return this.#t.size}get max(){return this.#e}set max(u){this.#e=u,this.#r()}has(u){return this.#t.has(u)}get(u){const f=this.#t;if(!f.has(u))return;const j=f.get(u);return f.delete(u),f.set(u,j),j}peek(u){return this.#t.get(u)}set(u,f){const j=this.#t;return j.has(u)&&j.delete(u),j.set(u,f),this.#r(),f}delete(u){const f=this.#t.get(u);return this.#t.delete(u)&&this.#n&&this.#n(f,u),f}clear(){if(this.#n)for(const[u,f]of this.#t)this.#n(f,u);this.#t.clear()}keys(){return this.#t.keys()}values(){return this.#t.values()}#r(){const u=this.#t;for(;u.size>this.#e;){const f=u.keys().next().value,j=u.get(f);u.delete(f),this.#n&&this.#n(j,f)}}}const W=new Map;function de(i,u){const f=`${i||""}|${u?JSON.stringify(u):""}`;let j=W.get(f);return j||(j=new Intl.Collator(i||void 0,{numeric:!0,sensitivity:"variant",...u}),W.set(f,j)),j}function Me(i,u){if(i===u)return 0;if(i==null)return 1;if(u==null)return-1;if(typeof i=="number"&&typeof u=="number")return Number.isNaN(i)?Number.isNaN(u)?0:1:Number.isNaN(u)||i<u?-1:i>u?1:0;const f=String(i),j=String(u);return f<j?-1:f>j?1:0}function $e(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const a=typeof requestAnimationFrame=="function";function l(i){return a?requestAnimationFrame(i):setTimeout(()=>i($e()),16)}function w(i){i!=null&&(a?cancelAnimationFrame(i):clearTimeout(i))}function H(i){let u=null,f=null;const j=()=>{u=null;const me=f;f=null,i(...me||[])},Z=(...me)=>{f=me,u===null&&(u=l(j))};return Z.cancel=()=>{w(u),u=null,f=null},Z.flush=()=>{u!==null&&(w(u),j())},Z}function y(i,u){let f=null,j=null;const Z=()=>{if(f=null,j===null)return;const Pe=j;j=null,i(...Pe),me()},me=()=>{f=setTimeout(Z,u),typeof f?.unref=="function"&&f.unref()},J=(...Pe)=>{f===null?(i(...Pe),me()):(j=Pe,clearTimeout(f),me())};return J.flush=()=>{if(f!==null&&clearTimeout(f),f=null,j===null)return;const Pe=j;j=null,i(...Pe)},J.cancel=()=>{f!==null&&clearTimeout(f),f=null,j=null},J.pending=()=>f!==null||j!==null,J}function F(i,u=50){return typeof requestIdleCallback=="function"?requestIdleCallback(i,{timeout:u}):setTimeout(()=>i({timeRemaining:()=>0,didTimeout:!0}),1)}let D=0;function M(i="l"){return`${i}${(++D).toString(36)}`}}),st("packages/core/src/source/filterwire.js",function(p,Oe){"use strict";Object.defineProperty(p,"HOST_FILTER_WARN_ID",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(p,"WHERE_PAGE_RELATIVE_WARN_ID",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(p,"warnWherePageRelative",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(p,"warnHostFilterNotApplied",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(p,"WHERE_NOT_APPLIED_WARN_ID",{enumerable:!0,get:function(){return N}}),Object.defineProperty(p,"warnWhereNotApplied",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(p,"WHERE_OVER_THRESHOLD_WARN_ID",{enumerable:!0,get:function(){return be}}),Object.defineProperty(p,"warnWhereOverThreshold",{enumerable:!0,get:function(){return T}}),Object.defineProperty(p,"RELATIVE_TOKENS",{enumerable:!0,get:function(){return he}}),Object.defineProperty(p,"parseRelativeToken",{enumerable:!0,get:function(){return U}}),Object.defineProperty(p,"resolveRelativeRange",{enumerable:!0,get:function(){return se}}),Object.defineProperty(p,"relativeTokenOf",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(p,"relativeTokenHelp",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(p,"isResolvableRelative",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(p,"resolveRelativeCondition",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(p,"isGroup",{enumerable:!0,get:function(){return De}}),Object.defineProperty(p,"forEachCondition",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(p,"mapConditions",{enumerable:!0,get:function(){return c}}),Object.defineProperty(p,"normaliseFilterSet",{enumerable:!0,get:function(){return O}}),Object.defineProperty(p,"buildFilterSet",{enumerable:!0,get:function(){return A}}),Object.defineProperty(p,"wireFilters",{enumerable:!0,get:function(){return _}}),Object.defineProperty(p,"querySignature",{enumerable:!0,get:function(){return ae}});const V=Oe("packages/core/src/internal/util.js").warnOnce,oe="source.remote.hostFilter",ve="source.where.pageRelative";function ee(d,g){!Array.isArray(d)||!d.length||V(ve,`filters.where (${d.join(", ")}) runs over the rows the ${g} 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 ke(d){const g=(d||{}).config;!g||!g.hostFilter||V(oe,"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 N="source.where.notApplied";function ye(d,g){V(`${N}:${d}`,`filters.where("${d}") is registered but the ${g} 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 be="source.where.overThreshold";function T(d,g,S,P){!Array.isArray(d)||!d.length||V(`${be}:${g}`,`filters.where (${d.join(", ")}) is not applied to the ${g} pushdown source:`,S===null?"the adapter reports no row total, so the size of the matching set is unknown.":`its matching set is ${S.toLocaleString()} rows, at or past the whereRowLimit of ${P.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 L=new Map;function B(d){let g=L.get(d);return g||(g=new Intl.DateTimeFormat("en-US",{timeZone:d,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),L.set(d,g)),g}function Q(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function K(d,g){const S=B(g).formatToParts(new Date(d)),P={y:1970,m:1,d:1,h:0,mi:0,s:0};for(const ne of S)ne.type==="year"?P.y=+ne.value:ne.type==="month"?P.m=+ne.value:ne.type==="day"?P.d=+ne.value:ne.type==="hour"?P.h=+ne.value%24:ne.type==="minute"?P.mi=+ne.value:ne.type==="second"&&(P.s=+ne.value);return P}function ce(d,g){const S=K(d,g);return Date.UTC(S.y,S.m-1,S.d,S.h,S.mi,S.s)-Math.floor(d/1e3)*1e3}function E(d,g,S,P){const ne=Date.UTC(d,g-1,S),W=ne-ce(ne,P);return ne-ce(W,P)}function ie(d,g,S){const P=new Date(Date.UTC(d.y,d.m-1,d.d+g));return E(P.getUTCFullYear(),P.getUTCMonth()+1,P.getUTCDate(),S)}const he=Object.freeze(["today","yesterday","lastNDays","thisWeek","thisMonth","thisQuarter","thisYear","quarterToDate","yearToDate"]);function U(d,g){if(typeof d!="string")return null;const S=d.trim().toLowerCase().replace(/[\s_-]+/g,""),P=/^last(\d*|n)days?$/.exec(S);if(P){const ne=P[1]==="n"?"":P[1],W=Number(ne||g);return!Number.isFinite(W)||W<=0?null:{kind:"lastNDays",n:Math.floor(W)}}switch(S){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 se(d,g={}){const S=U(d,g.n);if(!S)return null;const P=g.tz||Q(),ne=g.now instanceof Date?g.now.getTime():typeof g.now=="number"?g.now:Date.now(),W=K(ne,P),de=E(W.y,W.m,W.d,P),Me=ie(W,1,P);let $e=de,a=Me;switch(S.kind){case"today":break;case"yesterday":$e=ie(W,-1,P),a=de;break;case"lastNDays":a=g.includeToday?Me:de,$e=ie(W,g.includeToday?-(S.n-1):-S.n,P);break;case"thisWeek":{const l=Number.isFinite(g.weekStartsOn)?Number(g.weekStartsOn):1,H=(new Date(Date.UTC(W.y,W.m-1,W.d)).getUTCDay()-l+7)%7;$e=ie(W,-H,P),a=ie(W,-H+7,P);break}case"thisMonth":$e=E(W.y,W.m,1,P),a=E(W.m===12?W.y+1:W.y,W.m===12?1:W.m+1,1,P);break;case"thisQuarter":case"quarterToDate":{const l=Math.floor((W.m-1)/3)*3+1;$e=E(W.y,l,1,P),a=S.kind==="quarterToDate"?Me:l===10?E(W.y+1,1,1,P):E(W.y,l+3,1,P);break}case"thisYear":case"yearToDate":$e=E(W.y,1,1,P),a=S.kind==="yearToDate"?Me:E(W.y+1,1,1,P);break;default:return null}return{from:new Date($e).toISOString(),to:new Date(a).toISOString(),bounds:"[)",tz:P,relative:S.kind==="lastNDays"?`last${S.n}Days`:S.kind,n:S.n}}function fe(d){if(!d||typeof d!="object")return null;const g=d.value;if(g&&typeof g=="object"&&!Array.isArray(g)&&"relative"in g)return{token:String(g.relative),n:typeof g.n=="number"?g.n:void 0};if(d.op==="relative"&&typeof d.value=="string")return{token:d.value,n:void 0};const S=d.meta;return S&&typeof S.relative=="string"&&d.value===void 0?{token:S.relative,n:typeof S.n=="number"?S.n:void 0}:null}function ge(){return`Known tokens: ${he.filter(g=>g!=="lastNDays").join(", ")}. "lastNDays" needs a count: pass "last7Days", or the value object { relative: 'lastNDays', n: 7 }.`}function Se(d){const g=fe(d);return g?U(g.token,g.n)!==null:!1}function Ee(d,g={}){const S=fe(d);if(!S)return d;const P=se(S.token,{...g,n:S.n});return P?{...d,type:d.type||"date",op:"between",value:[P.from,P.to],bounds:d.bounds||P.bounds,meta:{...d.meta||{},relative:P.relative,tz:P.tz}}:(V(`source.relative.${S.token}`,`unknown relative date token "${S.token}"; sending the condition unresolved.`,ge()),d)}function De(d){return!!d&&typeof d=="object"&&Array.isArray(d.conditions)}function tt(d,g){if(d){if(De(d)){for(const S of d.conditions)tt(S,g);return}g(d)}}function c(d,g){if(!d)return null;if(!De(d))return g(d);const S=d;let P=!1;const ne=[];for(const W of S.conditions){const de=c(W,g);de!==W&&(P=!0),de&&ne.push(de)}return!P&&ne.length===S.conditions.length?d:ne.length?{...S,conditions:ne}:null}function q(d){if(!d)return null;if(!De(d))return d;const g=d,S=[];for(const P of g.conditions){const ne=q(P);ne&&S.push(ne)}return S.length?{op:g.op,conditions:S}:null}function O(d){const g=q(d);return g?De(g)&&g.op==="and"?g:{op:"and",conditions:[g]}:null}function A(d){const g=(d||[]).filter(Boolean);return g.length?{op:"and",conditions:g}:null}function _(d,g={}){const S=c(d,P=>Ee(P,g));return O(S)}function ae(d){const g=Te(d.filters??null);return JSON.stringify([g,d.sort??null,d.quick??"",d.groupBy??null,d.pivotBy??null,Ze(d.context)])}function Te(d){if(!d)return null;if(De(d)){const P=d;return{op:P.op,conditions:P.conditions.map(Te)}}const g=d,S=g.meta&&typeof g.meta.relative=="string"?g.meta.relative:fe(g)?.token;return{col:g.col,op:g.op,bounds:g.bounds??null,caseSensitive:g.caseSensitive??!1,value:S?`rel:${S}`:g.value??null}}function Ze(d){if(d==null)return null;try{return JSON.parse(JSON.stringify(d))}catch{return V("source.context.unserialisable","config.context is not JSON-serialisable; cache keys ignore it."),"[unserialisable]"}}}),st("packages/core/src/source/aggregates.js",function(p,Oe){"use strict";Object.defineProperty(p,"STAT_PUSHDOWN",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(p,"pushableAggregates",{enumerable:!0,get:function(){return V}}),Object.defineProperty(p,"fillAggregateSql",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(p,"resolveAggregatesConfig",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(p,"routeAggregate",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(p,"resolveAggregatePlan",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(p,"groupKeysPushable",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(p,"pushdownDocRows",{enumerable:!0,get:function(){return be}});const pe=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 V(){const T=new Set;for(const[L,B]of Object.entries(pe))B.pushable&&T.add(L);return T}function oe(T,L,B){let Q=T.split("%c").join(L);return B!==void 0&&(Q=Q.split("%w").join(B)),Q}function ve(T){const L=T||{},B=L.default==="engine"||L.default==="engine-if-identical"?L.default:"client",Q={};if(L.overrides&&typeof L.overrides=="object")for(const[K,ce]of Object.entries(L.overrides))(ce==="engine"||ce==="client")&&(Q[K]=ce);return{default:B,overrides:Q}}function ee(T,L){const B=pe[T];if(!B||!B.pushable)return"client";const Q=L.overrides[T];return Q==="engine"||Q==="client"?Q:L.default==="client"?"client":L.default==="engine-if-identical"?B.class==="identical"?"engine":"client":"engine"}function ke(T,L){const B=ve(L),Q=[],K=[];for(const ce of T||[]){const E=pe[ce.fn],ie=ee(ce.fn,B),he={id:ce.id,col:ce.col,fn:ce.fn,class:E?E.class:"fallback"};ce.weight!==void 0&&(he.weight=ce.weight),ce.params!==void 0&&(he.params=ce.params),ie==="engine"?Q.push(he):(he.reason=E&&!E.pushable?E.note||"the engine cannot express this stat":"client by config",K.push(he))}return{engine:Q,client:K,config:B}}const N=/^[A-Za-z_][A-Za-z0-9_$]*$/;function ye(T,L=[]){return(T||[]).every(Q=>{if(typeof Q=="string")return N.test(Q);if(!Q||typeof Q!="object")return!1;const K=Q;return Array.isArray(L)&&L.includes(K.bucket)&&typeof K.col=="string"&&N.test(K.col)&&typeof K.size=="number"&&Number.isFinite(K.size)&&K.size>0})}function be(){return Object.entries(pe).map(([T,L])=>({stat:T,class:L.class,sql:L.sql?oe(L.sql,"col",L.twoColumn?"weight":void 0):"",note:L.note||(L.class==="identical"?"Pushes to DuckDB with the same result.":"")}))}}),st("packages/core/src/source/abort.js",function(p,Oe){"use strict";Object.defineProperty(p,"SupersededError",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(p,"RequestToken",{enumerable:!0,get:function(){return V}}),Object.defineProperty(p,"AbortScope",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(p,"createAbortScope",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(p,"isAbortError",{enumerable:!0,get:function(){return ee}});class pe extends Error{constructor(N,ye="superseded"){super(`[lattice] request ${N?`"${N}" `:""}${ye}`),this.name="SupersededError",this.superseded=!0,this.key=N}}class V{#e;constructor(N,ye,be,T){this.#e=N,this.key=ye,this.controller=be,this.signal=be.signal,this.seq=T}get current(){return!this.signal.aborted&&this.#e.tokenFor(this.key)===this}settle(){this.#e.settle(this)}abort(N){this.signal.aborted||this.controller.abort(new pe(this.key,N)),this.#e.settle(this)}}class oe{#e=new Map;#t=0;begin(N="",ye="superseded"){const be=this.#e.get(N);be&&!be.signal.aborted&&be.controller.abort(new pe(N,ye));const T=new V(this,N,new AbortController,++this.#t);return this.#e.set(N,T),T}tokenFor(N){return this.#e.get(N)}pending(N=""){const ye=this.#e.get(N);return!!ye&&!ye.signal.aborted}get size(){return this.#e.size}settle(N){this.#e.get(N.key)===N&&this.#e.delete(N.key)}abort(N="",ye="superseded"){const be=this.#e.get(N);be&&be.abort(ye)}abortAll(N="superseded"){for(const ye of[...this.#e.values()])ye.abort(N);this.#e.clear()}}function ve(){return new oe}function ee(ke){if(!ke||typeof ke!="object")return!1;const N=ke;return N.superseded===!0||N.name==="AbortError"||N.name==="SupersededError"}}),st("packages/core/src/source/pushdown.js",function(p,Oe){"use strict";Object.defineProperty(p,"NO_CAPABILITIES",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(p,"resolveMutate",{enumerable:!0,get:function(){return he}}),Object.defineProperty(p,"capabilitiesOf",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(p,"splitFilters",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(p,"LEAF_COUNT_ID",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(p,"PIVOT_UNSUPPORTED",{enumerable:!0,get:function(){return q}}),Object.defineProperty(p,"GROUP_UNSUPPORTED",{enumerable:!0,get:function(){return O}}),Object.defineProperty(p,"UNGROUPED_LEVEL",{enumerable:!0,get:function(){return A}}),Object.defineProperty(p,"planQuery",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(p,"applyResidual",{enumerable:!0,get:function(){return d}}),Object.defineProperty(p,"DEFAULT_WHERE_ROW_LIMIT",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(p,"createPushdownSource",{enumerable:!0,get:function(){return $e}});const pe=Oe("packages/core/src/internal/util.js"),V=pe.defaultCompare,oe=pe.isFunction,ve=pe.toArray,ee=pe.warnOnce,ke=Oe("packages/core/src/source/filterwire.js"),N=ke.isGroup,ye=ke.warnWherePageRelative,be=ke.warnWhereOverThreshold,T=Oe("packages/core/src/source/aggregates.js"),L=T.resolveAggregatePlan,B=T.groupKeysPushable,Q=T.STAT_PUSHDOWN,ce=Oe("packages/core/src/source/abort.js").SupersededError;function E(a){const l=a&&a.signal;if(!l||!l.aborted)return;const w=l.reason;throw w instanceof Error?w:new ce("","superseded before it was sent")}const ie=Object.freeze({filter:!1,operators:Object.freeze([]),sort:!1,quick:!1,range:!1,total:!1,group:!1,pivot:!1,mutate:!1});function he(a){if(!a||typeof a!="object")return!1;const l=a.returning==="row"||a.returning==="key"?a.returning:"none";return{append:a.append===!0,update:a.update===!0,delete:a.delete===!0,returning:l}}function U(a,l){if(!a||typeof l!="string")return;if(!l.includes("."))return a[l];let w=a;for(const H of l.split(".")){if(w===null||typeof w!="object")return;w=w[H]}return w}function se(a){if(a===!0)return!0;if(!a||typeof a!="object")return!1;const l=a;return l.enabled===!1?!1:l.enabled===!0||oe(l.commit)}function fe(a){const l={...ie,...a||{}};return l.operators=new Set(l.operators||[]),l.mutate=he(l.mutate),l}function ge(a,l){return!a||!a.op||!l.operators.size?!1:l.operators.has(a.op)}function Se(a,l){if(!a)return{pushed:null,residual:null};if(!l.filter)return{pushed:null,residual:a};if(l.filter==="term"){if(N(a)){const F=a.conditions||[];if(String(a.op)!=="and")return{pushed:null,residual:a};const D=F.findIndex(i=>!N(i)&&ge(i,l));if(D<0)return{pushed:null,residual:a};const M=F.filter((i,u)=>u!==D);return{pushed:F[D],residual:M.length?{op:"and",conditions:M}:null}}return ge(a,l)?{pushed:a,residual:null}:{pushed:null,residual:a}}if(!N(a))return ge(a,l)?{pushed:a,residual:null}:{pushed:null,residual:a};if(String(a.op)!=="and")return(a.conditions||[]).every(D=>N(D)?Se(D,l).residual===null:ge(D,l))?{pushed:a,residual:null}:{pushed:null,residual:a};const w=[],H=[];for(const F of a.conditions||[]){if(N(F)){if(l.filter==="flat"){H.push(F);continue}const D=Se(F,l);D.pushed&&w.push(D.pushed),D.residual&&H.push(D.residual);continue}(ge(F,l)?w:H).push(F)}const y=F=>F.length===0?null:F.length===1?F[0]:{op:"and",conditions:F};return{pushed:y(w),residual:y(H)}}const Ee="__lattice_leaves";function De(a){return a.aggregates?a.aggregates instanceof Set?a.aggregates:new Set(ve(a.aggregates)):new Set}function tt(a){const l=De(a);return l.size?l.has("count")?a.filter!=="tree"||!a.operators||!a.operators.has("eq")?"the adapter does not declare the `group` capability, and cannot narrow a group's rows by its key (that needs a `tree` filter with the `eq` operator)":"":"the adapter does not declare the `group` capability, and its declared aggregates have no `count` to give each group its row count":"the adapter does not declare the `group` capability"}function c(a,l,w,H,y,F,D){const M=Array.isArray(a.groupBy)?a.groupBy:[],i=Array.isArray(a.groupPath)?a.groupPath:[],u=Array.isArray(a.groupValues)?a.groupValues:null;if(!l.group){const f=tt(l);if(f)return f}return B(M)?w.residual?"the filter did not fully push, so the engine would group a superset of the matching rows":H?y?F?"a host `where` predicate can only run in the browser, over rows the engine grouped":D?"fullDataset holds the whole matching set, so the grid groups it itself":!u||u.length!==i.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"}const q="pushdown:pivot-unsupported",O="pushdown:group-unsupported",A=Symbol("lattice.remote.ungroupedLevel");function _(a,l,w,H,y,F){const D=Array.isArray(a.pivotBy)?a.pivotBy:[],M=Array.isArray(a.groupBy)?a.groupBy:[],i=Array.isArray(a.groupPath)?a.groupPath:[],u=Array.isArray(a.groupValues)?a.groupValues:null;return l.pivot?B(D)?M.length&&!B(M)?"a grouping key is not a plain column the engine can name in a GROUP BY":w.residual?"the filter did not fully push, so the engine would pivot a superset of the matching rows":H?y?F?"a host `where` predicate can only run in the browser, over rows the engine pivoted":!u||u.length!==i.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 pivot unsearched rows":"the sort did not push, so the engine would order the rows differently":"a pivot column is not a plain column the engine can name in a GROUP BY":"the adapter does not declare the `pivot` capability"}function ae(a,l,w=!1){const H=Se(a.filters||null,l),y=[];H.residual&&y.push("filter");const F=a.sort||[],D=F.length===0||l.sort==="multi"&&F.length>=1||l.sort==="single"&&F.length===1;!D&&F.length&&y.push("sort");const M=a.quick?String(a.quick):"",i=!M||!!l.quick;i||y.push("quick");const u=a.where&&a.where.active?a.where:null;u&&y.push("where");const f={filters:H.residual,sort:D?null:F,quick:i?"":M,where:u},j=!!w,Z=Array.isArray(a.groupBy)&&a.groupBy.length>0,me=Z?c(a,l,H,D,i,u,j):"",J=a.pivotMode!==!1&&Array.isArray(a.pivotBy)&&a.pivotBy.length>0,Pe=J?_(a,l,H,D,i,u):"",Ie=J&&Pe==="";J&&!Ie&&y.push("pivot");const Ge=J?Ie&&Z:Z&&me==="";Z&&!J&&!Ge&&y.push("group");const Fe=(Ge||Ie)&&Array.isArray(a.groupValues)?a.groupValues.length:0,_e=Ge||J?!1:j||!!(f.filters||f.sort||f.quick||f.where)||!l.range;return{pushed:{...a,filters:H.pushed,sort:D?F:[],quick:i?M:"",range:_e?null:a.range},residual:f,needsAll:_e,unpushed:y,full:j,grouped:Ge,groupLevel:Fe,groupReason:J?"":me,pivoted:Ie,pivotReason:Pe}}function Te(a){const l=Array.isArray(a.totals)?a.totals:[],w=a.totalFns&&typeof a.totalFns=="object"?a.totalFns:{},H=[],y=[];for(const F of l){const D=String(F),M=typeof w[D]=="string"?w[D]:null,i=M?Q[M]:null;M?!i||!i.pushable||!i.sql?y.push({id:D,fn:M,class:i?i.class:"fallback",reason:i&&i.note?i.note:`the pushdown map cannot express "${M}"`}):i.twoColumn?y.push({id:D,fn:M,class:i.class,reason:`"${M}" reduces two columns, and a grouped request carries no weight column`}):H.push({id:D,col:D,fn:M,class:i.class}):y.push({id:D,fn:null,class:"fallback",reason:"the column totals with a host function, so there is no named statistic to push"})}return{engine:H,client:y}}const Ze=Object.freeze({items:a=>a==null?[]:Array.isArray(a)?a:[a]});function d(a,l,w){if(!l)return a;let H=a;if(l.filters&&oe(w.evaluateFilters)){const y=H,F={count:H.length,handle:i=>({id:i,get:u=>U(y[u],i)}),itemwise:i=>y.some(u=>Array.isArray(U(u,i)))?Ze:null},D=w.evaluateFilters(l.filters,F),M=[];for(let i=0;i<H.length;i++)D[i]&&M.push(H[i]);H=M}if(l.where&&l.where.active&&(l.whole||ye(l.where.names,"pushdown"),H=H.filter(y=>l.where.passes(y))),l.quick){const y=l.quick.toLowerCase();H=H.filter(F=>{if(!F||typeof F!="object")return!1;for(const D of Object.values(F))if(D!=null&&String(D).toLowerCase().includes(y))return!0;return!1})}if(l.sort&&l.sort.length&&oe(w.sortMulti)){const y=[...new Set(l.sort.map(i=>i.col))],F=H,D=y.map(i=>({id:i,get:u=>U(F[u],i)})),M=w.sortMulti(D,l.sort.map(i=>({col:i.col,dir:i.dir})),Uint32Array.from({length:H.length},(i,u)=>u),{});H=Array.from(M,i=>F[i])}return H}function g(a){return JSON.stringify({filters:a.filters||null,sort:a.sort||[],quick:a.quick||"",groupBy:a.groupBy||[],groupPath:a.groupPath||[],context:a.context??null})}function S(a){if(!a||typeof a!="object")return 16;let l="";try{l=JSON.stringify(a)}catch{return 200}return l.length*2+64}function P(a){const l=a||{};return{enabled:!!l.enabled,maxRows:Number.isFinite(l.maxRows)?l.maxRows:1e6,maxBytesEstimate:Number.isFinite(l.maxBytesEstimate)?l.maxBytesEstimate:512*1024*1024}}const ne=5e4;function W(a){return Number.isFinite(a)&&a>=0?a:ne}function de(a){return!!a&&oe(a.then)}async function Me(a){if(!a||a.total!==void 0||!de(a.pendingTotal))return a;const l=await a.pendingTotal,{pendingTotal:w,...H}=a;return typeof l=="number"?{...H,total:l}:H}function $e(a={}){const l=a.adapter;if(!l||!oe(l.execute))return ee("source.pushdown.adapter","createPushdownSource needs an `adapter` with an `execute(query)` function."),{...a,mode:"remote",fetch:async()=>({rows:[],total:0})};const w=fe(l.capabilities),H=l.capabilities&&Object.getOwnPropertyDescriptor(l.capabilities,"operators");H&&oe(H.get)&&Object.defineProperty(w,"operators",{enumerable:!0,configurable:!0,get:()=>new Set(l.capabilities.operators||[]),set:()=>{}});const y=l.name||"adapter";let F=null;const D=()=>oe(l.ready)?(F||(F=Promise.resolve(l.ready()).then(()=>{Object.assign(w,fe(l.capabilities))},k=>{throw F=null,k})),F):null,M=P(a.fullDataset),i=!!a.allowPartialResults,u=W(a.whereRowLimit);let f=null;const j=a.aggregates;let Z=null,me=null,J=null,Pe=null,Ie=null,Ge,Fe=null,_e=0,Je=null;const nt=()=>!M.enabled||!Z?null:(Je!==Z.key&&(_e++,Je=Z.key),{rows:Z.rows,version:_e}),ft=async k=>{const R=k.where&&k.where.active?k.where:null;if(!R)return{request:k,probe:null};const{where:$,...C}=k,m=ae(C,w,M.enabled);if(m.needsAll)return{request:k,probe:null};const z=g(m.pushed);let ue=null;return(!f||f.key!==z)&&(w.total?(E(k),ue=await Me(await l.execute(m.pushed,k)),f={key:z,size:ue&&typeof ue.total=="number"?ue.total:null}):f={key:z,size:null}),f.size!==null&&f.size<u?{request:k,probe:null}:(be(R.names,y,f.size,u),{request:C,probe:ue})},At=async(k,R)=>{Fe=null;const $=Te(k.pushed);J={engine:$.engine,client:$.client,groupBy:k.pushed.groupBy},$.client.length&&ee(`source.pushdown.group.totals.${y}.${$.client.map(z=>z.id).join(".")}`,`the ${y} adapter cannot compute the group subtotal for ${$.client.map(z=>`"${z.id}" (${z.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 C=await l.executeGroupLevel(k.pushed,$.engine,R)||{};let m=C.rows||[];return!w.range&&R.range&&(m=m.slice(R.range.start,R.range.end)),Ce(C),C.total===void 0?{rows:m}:{rows:m,total:C.total}},Le=new Map,Qe=64,Ve=async(k,R)=>{Fe=null;const $=k.pushed,C=$.groupBy,m=Array.isArray($.groupValues)?$.groupValues:[],z=m.length,ue=[...$.filters?[$.filters]:[],...C.slice(0,z).map((x,qe)=>({col:x,op:"eq",value:m[qe]===void 0?null:m[qe],caseSensitive:!0}))],je=ue.length===0?null:ue.length===1?ue[0]:{op:"and",conditions:ue},we=R.range?R.range.start:0;if(z>=C.length){const x={...$,filters:je,groupBy:[],groupPath:[],groupValues:[],totals:[],totalFns:{}},qe=await Me(await l.execute(x,R))||{};let ze=qe.rows||[];return!w.range&&R.range&&(ze=ze.slice(R.range.start,R.range.end)),typeof qe.total=="number"?{rows:ze,total:qe.total}:{rows:ze}}const te=C[z],Ae=Te($),Ke=De(w),Re=Ae.engine.filter(x=>Ke.has(x.fn)),Be=[...Ae.engine.filter(x=>!Ke.has(x.fn)).map(x=>({id:x.id,fn:x.fn,class:x.class,reason:`the ${y} adapter does not compute "${x.fn}"`})),...Ae.client];J={engine:Re,client:Be,groupBy:C},Be.length&&ee(`source.pushdown.group.totals.${y}.${Be.map(x=>x.id).join(".")}`,`the ${y} adapter cannot compute the group subtotal for ${Be.map(x=>`"${x.id}" (${x.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 re=[...Re.map(x=>({id:x.id,col:x.col,fn:x.fn})),{id:Ee,col:te,fn:"count"}],le={...$,filters:je,range:null},G=JSON.stringify([g(le),m,te,re]);let We=we>0?Le.get(G):void 0;if(!We){for(We=Promise.resolve(l.executeGroupedAggregates(le,[te],re)),Le.delete(G),Le.set(G,We);Le.size>Qe;)Le.delete(Le.keys().next().value);We.catch(()=>{Le.get(G)===We&&Le.delete(G)})}const lt=await We||[];E(R);const Et=x=>{const qe={};for(const ze of Re)qe[ze.id]=x?x[ze.id]:void 0;return qe},kt=($.sort||[]).find(x=>x&&x.col===te),Nt=kt&&kt.dir==="desc"?-1:1,Ue=lt.filter(x=>x&&x.level===1).map(x=>({[te]:x.keys[0]===void 0?null:x.keys[0],leafCount:Number(x.values&&x.values[Ee])||0,totals:Et(x.values)})).sort((x,qe)=>Nt*V(x[te],qe[te]));if(z===0){const x=lt.find(ze=>ze&&ze.level===0),qe=x?Number(x.values&&x.values[Ee]):NaN;Ce({matchCount:Number.isFinite(qe)?qe:Ue.reduce((ze,gt)=>ze+gt.leafCount,0),...x?{grand:Et(x.values)}:{}})}const dt=R.range?R.range.end:Ue.length;return{rows:Ue.slice(we,dt),total:Ue.length}},Ce=k=>{typeof k.matchCount=="number"&&(Pe=k.matchCount,Ie=k.grand?{totals:k.grand,leafCount:k.matchCount}:null,Ge===void 0&&oe(l.unfilteredCount)&&(Ge=null,Promise.resolve(l.unfilteredCount()).then(R=>{Ge=typeof R=="number"?R:null}).catch(R=>{ee(`source.pushdown.group.unfiltered.${y}`,`the ${y} adapter could not count the unfiltered set (${R&&R.message?R.message:R}), so "N of M" falls back to the display count for its denominator.`)})))},rt=async(k,R)=>{Fe=null;const $=Te(k.pushed);J={engine:$.engine,client:$.client,groupBy:k.pushed.groupBy,pivotBy:k.pushed.pivotBy},$.client.length&&ee(`source.pushdown.pivot.totals.${y}.${$.client.map(je=>je.id).join(".")}`,`the ${y} adapter cannot compute the pivot cells for ${$.client.map(je=>`"${je.id}" (${je.reason})`).join(", ")}, so those cells are empty. A figure computed over anything other than the cell would be wrong, so none is shown; \`lastPlan().aggregates.client\` names them.`);const C=await l.executePivotLevel(k.pushed,$.engine,R)||{};let m=C.rows||[];!w.range&&R.range&&(m=m.slice(R.range.start,R.range.end)),Ce(C);const z=C.pivot&&typeof C.pivot=="object"?C.pivot:{},ue={cells:Array.isArray(z.cells)?z.cells:[],...Array.isArray(z.axis)?{axis:z.axis}:{}};return C.total===void 0?{rows:m,pivot:ue}:{rows:m,total:C.total,pivot:ue}},at=k=>{ee(`source.pushdown.pivot.${y}.${k}`,`pushdown:pivot-unsupported: the ${y} adapter cannot pivot this query because ${k}, so no rows are fetched rather than every leaf row being pulled into the browser to pivot there. \`lastPlan().pivotReason\` says the same.`);const R=new Error(`[lattice] ${q}: the ${y} adapter cannot pivot this query because ${k}, so no rows are fetched rather than every leaf row being pulled into the browser to pivot there. \`lastPlan().pivotReason\` says the same.`);throw R.code=q,R.reason=k,R},Xe=(k,R)=>{const $={key:R,state:"pending",value:null};return Fe=$,k.then(C=>(Fe===$&&(Fe={key:R,state:"settled",value:typeof C=="number"?C:null}),C),C=>{throw Fe===$&&(Fe={key:R,state:"failed",value:null}),C})},et=async k=>{const R=D();R&&await R;const C=k&&k.pivotMode!==!1&&Array.isArray(k.pivotBy)&&k.pivotBy.length>0?{request:k,probe:null}:await ft(k);E(k);let m=ae(C.request,w,M.enabled);if(w.group&&m.grouped&&!m.pivoted&&!oe(l.executeGroupLevel)&&(ee(`source.pushdown.group.method.${y}`,`the ${y} adapter declares the \`group\` capability but has no \`executeGroupLevel(query, aggregates, request)\`, so grouping is not pushed and the grid stays ungrouped unless it holds the whole matching set. Implement the method or drop the capability.`),m=ae(C.request,{...w,group:!1,aggregates:null},M.enabled)),m.pivoted&&!oe(l.executePivotLevel)&&(m=ae(C.request,{...w,pivot:!1},M.enabled),m.pivotReason="the adapter declares the `pivot` capability but has no `executePivotLevel(query, aggregates, request)`"),m.grouped&&!m.pivoted&&!w.group&&!oe(l.executeGroupedAggregates)&&(ee(`source.pushdown.group.aggregates.method.${y}`,`the ${y} adapter declares \`aggregates\` but has no \`executeGroupedAggregates(query, groupBy, aggregates)\`, so the grouped view cannot be built from grouped aggregates and the grid stays ungrouped unless it holds the whole matching set. Implement the method, or declare \`group\` and implement \`executeGroupLevel\`.`),m=ae(C.request,{...w,aggregates:null},M.enabled)),me=m,m.pivoted)return rt(m,k);if(m.pivotReason&&at(m.pivotReason),m.grouped)return w.group?At(m,k):Ve(m,k);const ue=!!m.groupReason&&!m.full;ue?ee(`source.pushdown.group-unsupported.${y}.${m.groupReason}`,`pushdown:group-unsupported: the ${y} adapter was not asked to group this query because ${m.groupReason}, so the grid stays ungrouped rather than building group rows, counts and subtotals from a window of leaf rows. \`lastPlan().groupReason\` says the same.`):m.groupReason&&ee(`source.pushdown.group.${y}.${m.groupReason}`,`the ${y} adapter was not asked to group this query because ${m.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.`);const je=re=>ue?{...re,[A]:!0}:re;if(!m.needsAll){const re=C.probe||await l.execute(m.pushed,k),le=re.rows||[];return de(re.pendingTotal)&&re.total===void 0?je({rows:le,pendingTotal:Xe(re.pendingTotal,g(m.pushed))}):(Fe=null,!w.total&&re.total===void 0?je({rows:le}):je({rows:le,total:re.total??le.length}))}m.unpushed.length&&ee(`source.pushdown.residual.${y}.${m.unpushed.join(".")}`,`the ${y} adapter cannot push ${m.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 we=g(m.pushed);if(!Z||Z.key!==we){const re=await Me(await l.execute(m.pushed,k));Fe=null;const le=re.rows||[];if(m.full){const G=typeof re.total=="number"?Math.max(re.total,le.length):le.length;if(G>M.maxRows)throw new Error(`[lattice] fullDataset refused: the ${y} adapter's matching set is ${G.toLocaleString()} rows, past the configured maxRows of ${M.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=le.length*S(le[0]);if(We>M.maxBytesEstimate)throw new Error(`[lattice] fullDataset refused: the ${y} adapter's matching set is an estimated ${Math.round(We/(1024*1024)).toLocaleString()} MB across ${le.length.toLocaleString()} rows, past the configured maxBytesEstimate of ${Math.round(M.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 re.total=="number"&&le.length<re.total){const G=!!(m.residual.filters||m.residual.quick||m.residual.sort&&m.residual.sort.length);if(G&&!i)throw new Error(`[lattice] the ${y} adapter returned ${le.length} of ${re.total} matching rows when asked for the whole result, and the query has residual ${m.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.`);G?ee(`source.pushdown.partial.residual.${y}`,`the ${y} adapter returned ${le.length} of ${re.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.`):ee(`source.pushdown.partial.${y}`,`the ${y} adapter returned ${le.length} of ${re.total} matching rows when asked for the whole result. The adapter must follow the engine's own paging before returning.`)}Z={key:we,rows:le,total:typeof re.total=="number"?re.total:null}}let te=m;if(m.residual.where){const re=Z.total??Z.rows.length;if(re>=u){be(m.residual.where.names,y,re,u);const{where:le,...G}=C.request;te=ae(G,w,M.enabled),me=te}}const Ae=Z.total!==null&&Z.rows.length>=Z.total,Ke=d(Z.rows,{...te.residual,whole:Ae},a.compute||{}),Re=k.range?k.range.start:0,Be=k.range?k.range.end:Ke.length;return je({rows:Ke.slice(Re,Be),total:Ke.length})},ot=async(k,R)=>{const $=D();$&&await $;const C=ae(k,w,M.enabled);me=C;const m=L(R,j),z=Array.isArray(k.groupBy)?k.groupBy:[],ue=z.length>0,je=!C.residual.filters&&!C.residual.quick,we=!ue||B(z,w.buckets);let te=m.engine,Ae=m.client;if(w.aggregates&&te.length){const re=w.aggregates instanceof Set?w.aggregates:new Set(ve(w.aggregates)),le=te.filter(G=>!re.has(G.fn));le.length&&(te=te.filter(G=>re.has(G.fn)),Ae=[...le.map(G=>({...G,reason:`the ${y} adapter does not compute "${G.fn}"`})),...Ae])}const Ke=re=>{Ae=[...te.map(le=>({...le,reason:re})),...Ae],te=[]};te.length&&!je?Ke(C.residual.quick&&!C.residual.filters?"a quick search the adapter cannot push forces all-client (no mixed provenance)":"residual filter forces all-client (no mixed provenance)"):te.length&&!we&&Ke("a grouping key the engine cannot form forces all-client (no mixed provenance)");let Re={},Be;return te.length&&(oe(ue?l.executeGroupedAggregates:l.executeAggregates)?ue?Be=await l.executeGroupedAggregates(C.pushed,z,te)||[]:Re=await l.executeAggregates(C.pushed,te)||{}:(ee(`source.pushdown.aggregates.${y}${ue?".grouped":""}`,`the ${y} adapter cannot compute ${ue?"grouped ":""}aggregates, so every requested statistic is computed client-side. Correct, and slower than it needs to be.`),Ke(`adapter cannot compute ${ue?"grouped ":""}aggregates`))),J={engine:te,client:Ae,...ue?{groupBy:z}:{}},{values:Re,engine:te,client:Ae,...Be!==void 0?{groups:Be}:{}}},ut=se(a.edit),it=a.edit&&typeof a.edit=="object"&&oe(a.edit.commit);let He=a.edit;if(ut&&!it)if(w.mutate&&w.mutate.update){const k=R=>{if(!w.mutate||!w.mutate.update)throw new Error(`[lattice] the ${y} adapter cannot update rows (mutate.update is not declared), so this edit cannot be persisted. The cell is reverted rather than left looking saved.`);const $={kind:"update",key:String(R.key),patch:{[R.colId]:R.value}};return l.mutate($,R.request||{})};He={...a.edit===!0?{}:a.edit,commit:k}}else ee(`source.pushdown.readonly.${y}`,`edit is enabled but the ${y} adapter declares mutate: ${w.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 wt=ut&&w.mutate&&(w.mutate.append||w.mutate.delete)?{append:w.mutate.append===!0,remove:w.mutate.delete===!0,returning:w.mutate.returning,mutate:(k,R)=>l.mutate(k,R||{})}:null,ht=async k=>{const R=D();R&&await R;const{range:$,signal:C,export:m,...z}=k||{},ue={...z,groupBy:[],groupPath:[],groupValues:[],pivotBy:[],pivotMode:!1,totals:[]};return{plan:ae(ue,w,M.enabled),signal:C}};async function*Ye(k,R={}){const{plan:$,signal:C}=await ht(k),m=Math.max(1,Math.floor(Number(R.pageSize))||5e3),z={signal:C,stream:!0};if(!$.needsAll)for(let we=0;;we+=m){E(z);const te=await l.execute({...$.pushed,range:{start:we,end:we+m}},z);te&&de(te.pendingTotal)&&te.pendingTotal.then(null,()=>{});const Ae=te&&te.rows||[];if(Ae.length&&(yield Ae),Ae.length<m)return}E(z);const ue=await Me(await l.execute({...$.pushed,range:void 0},z)),je=d(ue&&ue.rows||[],{...$.residual,whole:!0},a.compute||{});for(let we=0;we<je.length;we+=m)yield je.slice(we,we+m)}return{...a,edit:He,rowMutate:wt,mode:"remote",fetch:et,aggregate:ot,countMatching:async k=>{const{plan:R,signal:$}=await ht(k);if(!R.needsAll&&w.total){E({signal:$});const m=await Me(await l.execute({...R.pushed,range:{start:0,end:0}},{signal:$}));if(m&&typeof m.total=="number")return m.total}let C=0;for await(const m of Ye(k))C+=m.length;return C},streamMatching:Ye,lastPlan:()=>me?{...me,...J?{aggregates:J}:{},...Fe?{total:{deferred:!0,state:Fe.state,value:Fe.value}}:{}}:null,fullFrame:nt,counts:()=>({match:Pe,total:Ge??null,pending:!!Fe&&Fe.state==="pending"}),grandTotals:()=>Ie}}}),st("packages/core/src/model/rowkey.js",function(p,Oe){"use strict";Object.defineProperty(p,"KEY_DEPENDENT_FEATURES",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(p,"compositeKey",{enumerable:!0,get:function(){return be}}),Object.defineProperty(p,"createRowKey",{enumerable:!0,get:function(){return T}}),Object.defineProperty(p,"warnMissingKeys",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(p,"groupPathKey",{enumerable:!0,get:function(){return K}}),Object.defineProperty(p,"splitPathKey",{enumerable:!0,get:function(){return ce}});const pe=Oe("packages/core/src/internal/util.js"),V=pe.warnOnce,oe=pe.pathGetter,ve=pe.isFunction,ee=pe.isBlank,ke=["changes (rows.apply / rows.queue)","streaming dedupe","selection persistence","remote reload","cell comments"],N="";function ye(E){if(E===null)return"\0n";if(E===void 0)return"\0u";const ie=typeof E;if(ie==="string")return E;if(ie==="number"||ie==="bigint"||ie==="boolean")return String(E);if(E instanceof Date)return`\0d${E.getTime()}`;try{return`\0o${JSON.stringify(E)}`}catch{return"\0o?"}}function be(E){if(E.length===1)return ye(E[0]);let ie="";for(let he=0;he<E.length;he++)he&&(ie+=N),ie+=ye(E[he]);return ie}function T(E,ie={}){const he=ie.warn!==!1;if(ve(E)){const U=E;return{stable:!0,fields:[],disabled:[],key(se,fe){try{const ge=U(se);return Array.isArray(ge)?be(ge):ye(ge)}catch(ge){return V("rowKey.throw","rowKey function threw; falling back to index identity for the affected rows.",ge),`#${fe??-1}`}},keyEmpty(se){try{const fe=U(se);return Array.isArray(fe)?fe.length===0||fe.some(ee):ee(fe)}catch{return!1}},missingFields(){return[]}}}if(Array.isArray(E)&&E.length>0){const U=E.filter(ge=>typeof ge=="string"),se=U.map(ge=>oe(ge)),fe=se.length;return{stable:!0,fields:U,disabled:[],key(ge){const Se=new Array(fe);for(let Ee=0;Ee<fe;Ee++)Se[Ee]=se[Ee](ge);return be(Se)},keyEmpty(ge){for(let Se=0;Se<fe;Se++)if(ee(se[Se](ge)))return!0;return!1},missingFields(ge){const Se=[];for(let Ee=0;Ee<fe;Ee++)ee(se[Ee](ge))&&Se.push(U[Ee]);return Se}}}if(typeof E=="string"&&E.length>0){const U=oe(E);return{stable:!0,fields:[E],disabled:[],key(se){return ye(U(se))},keyEmpty(se){return ee(U(se))},missingFields(se){return ee(U(se))?[E]:[]}}}return he&&V("rowKey.missing",`no rowKey configured, so rows are identified by object identity. This disables: ${ke.join(", ")}. Set rowKey to a field name, an array of field names, or a function.`),{stable:!1,fields:[],disabled:ke.slice(),key(U,se){if(U===null||typeof U!="object")return`#${se??0}:${String(U)}`;let fe=L.get(U);return fe===void 0&&(fe=`#${B++}`,L.set(U,fe)),fe}}}const L=new WeakMap;let B=0;function Q(E,ie){if(!E||E.stable===!1||!ve(E.keyEmpty)||!Array.isArray(ie)||ie.length===0)return;let he=0,U=null,se;for(let Ee=0;Ee<ie.length;Ee++){const De=ie[Ee];E.keyEmpty(De)&&(he++,U===null&&(U=ve(E.missingFields)?E.missingFields(De):[],se=De))}if(he===0)return;const fe=E.fields.length?E.fields.join(","):"(function)",ge=U&&U.length?U.join(", "):E.fields.length?E.fields.join(", "):"the rowKey function",Se=se!==null&&typeof se=="object"?Object.keys(se).join(", ")||"(no fields)":String(se);V(`rowKey.emptyValue:${fe}`,`rowKey ${ge} is missing on ${he} of ${ie.length} rows; the first such row has: ${Se}. 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 K(E){return be(E)}function ce(E){return E.split(N)}}),st("packages/modules/data-router/devtools.js",function(p,Oe){"use strict";Object.defineProperty(p,"mountRouterDevtools",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(p,"default",{enumerable:!0,get:function(){return be}});const V=Oe("packages/core/src/internal/util.js").warnOnce,oe="lat-router-devtools";function ve(T,L,B){const Q=T.createElement(L);return Q.textContent=B==null?"—":String(B),Q}function ee(T){return Number.isFinite(T)?`${Math.round(T*10)/10}/s`:"—"}function ke(T,L,B,Q){const K=T.createElement("section");K.className=`${oe}-section`;const ce=T.createElement("h4");ce.textContent=L,K.appendChild(ce);const E=T.createElement("table"),ie=T.createElement("tr");for(const he of B)ie.appendChild(ve(T,"th",he));E.appendChild(ie);for(const he of Q){const U=T.createElement("tr");for(const se of he)U.appendChild(ve(T,"td",se));E.appendChild(U)}return K.appendChild(E),K}function N(T,L,B){L.textContent="";const Q=ke(T,"Router",["metric","value"],[["throughput",ee(B.throughput)],["unrouted",B.unrouted],["dropped (duplicate)",B.dropped],["buffer depth",B.buffered],["lag (deltas behind)",B.lag]]);L.appendChild(Q),L.appendChild(ke(T,"Routes",["#","label","kind","rows","shown","rows/sec"],B.routes.map(K=>[K.index,K.label,K.kind,K.rows,K.shown,ee(K.throughput)]))),B.sources.length&&L.appendChild(ke(T,"Sources",["id","rows","ingested","rows/sec"],B.sources.map(K=>[K.id,K.rows,K.ingested,ee(K.throughput)])))}function ye(T,L,B={}){const Q=L&&L.ownerDocument||(typeof document<"u"?document:null);if(!T||typeof T.metrics!="function"||typeof T.on!="function"||!L||!Q)return V("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 K=Q.createElement("div");K.className=oe,L.appendChild(K);const ce=()=>N(Q,K,T.metrics());ce();const E=T.on("metrics",()=>ce());return{refresh:ce,destroy(){E(),K.parentNode&&K.parentNode.removeChild(K)}}}const be=ye}),st("packages/modules/data-router/index.js",function(p,Oe){"use strict";Object.defineProperty(p,"createDataRouter",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(p,"default",{enumerable:!0,get:function(){return tt}});const V=Oe("packages/core/src/internal/util.js").warnOnce,oe=Oe("packages/core/src/source/pushdown.js"),ve=oe.planQuery,ee=oe.capabilitiesOf,N=Oe("packages/core/src/model/rowkey.js").compositeKey,be=Oe("packages/modules/data-router/devtools.js").mountRouterDevtools;function T(c,q){return typeof c=="function"?c:typeof c=="string"?O=>O[c]:q}function L(c){return Array.isArray(c)?"array":c===null?"null":typeof c}function B(c,q){if(c===void 0||typeof c=="string"&&c.length>0)return c;if(typeof c=="function")return O=>{const A=c(O);if(typeof A=="string"||typeof A=="number"&&Number.isFinite(A))return A;throw new Error(`lattice-data-router: rowKey function must return a string or number; got ${L(A)}.`)};throw new Error(`lattice-data-router: rowKey must be a property name or a function; composite keys are not supported on ${q}.`)}function Q(c){if(typeof c=="function")return c;if(c&&typeof c=="object"&&typeof c.key=="string"){const q=c.dir==="desc"?-1:1,{key:O}=c;return(A,_)=>{const ae=A?A[O]:void 0,Te=_?_[O]:void 0;return ae<Te?-1*q:ae>Te?1*q:0}}return null}function K(c){if(!c||typeof c!="object")return null;let q=0;Number.isFinite(c.minInterval)&&c.minInterval>0?q=Number(c.minInterval):Number.isFinite(c.maxHz)&&c.maxHz>0&&(q=1e3/Number(c.maxHz));const O=Number.isFinite(c.sample)&&c.sample>1?Math.floor(Number(c.sample)):1,A=Number.isFinite(c.maxLag)&&c.maxLag>=0?Math.floor(Number(c.maxLag)):null;return q===0&&O===1&&A===null?null:{minInterval:q,sample:O,maxLag:A}}let ce=0;function E(){return ce+=1,`r${ce}`}function ie(c){const O=(Array.isArray(c)?c:[c]).map(A=>({name:typeof A=="string"?A:null,get:T(A,()=>{})}));return A=>{const _={},ae=[];for(const Te of O){const Ze=Te.get(A);ae.push(Ze),Te.name&&(_[Te.name]=Ze)}return{key:N(ae),fields:_}}}function he(c,q){if(typeof c=="function")return c(q);if(c&&typeof c=="object"){const{op:O,field:A}=c;if(O==="count")return q.length;const _=A!=null?q.map(ae=>Number(ae[A])).filter(ae=>Number.isFinite(ae)):[];if(O==="sum")return _.reduce((ae,Te)=>ae+Te,0);if(O==="avg")return _.length?_.reduce((ae,Te)=>ae+Te,0)/_.length:0;if(O==="min")return _.length?Math.min(..._):void 0;if(O==="max")return _.length?Math.max(..._):void 0}}function U(c){return c&&typeof c=="object"&&typeof c.from=="string"&&typeof c.to=="string"?{from:c.to,to:c.from}:(V("data-router:mutual-fn","relate({ mutual: true }) with a function relation cannot be inverted; the same predicate is applied in both directions. Use a { from, to } key map for a mutual edge."),c)}function se(c,q){return c?q?{op:"and",conditions:[c,q]}:c:q||null}const fe=Object.freeze(["eq","ne","lt","lte","gt","gte","between","notBetween","in","notIn","contains","notContains","startsWith","endsWith","blank","notBlank"]);function ge(c,q){const O=q?q[c.col]:void 0,A=c.value,_=ae=>c.caseSensitive?String(ae):String(ae).toLowerCase();switch(c.op){case"eq":return O===A;case"ne":return O!==A;case"lt":return O<A;case"lte":return O<=A;case"gt":return O>A;case"gte":return O>=A;case"between":return Array.isArray(A)&&O>=A[0]&&O<=A[1];case"notBetween":return!(Array.isArray(A)&&O>=A[0]&&O<=A[1]);case"in":return Array.isArray(A)&&A.includes(O);case"notIn":return!(Array.isArray(A)&&A.includes(O));case"contains":return O!=null&&_(O).includes(_(A));case"notContains":return O==null||!_(O).includes(_(A));case"startsWith":return O!=null&&_(O).startsWith(_(A));case"endsWith":return O!=null&&_(O).endsWith(_(A));case"blank":return O==null||O==="";case"notBlank":return!(O==null||O==="");default:throw new Error(`[lattice] query() cannot evaluate the residual filter operator "${String(c.op)}" on column "${String(c.col)}" client-side, so the query is refused rather than returning rows the filter excludes. Push it down to an adapter that implements it, or use an operator this router evaluates: ${fe.join(", ")}.`)}}function Se(c,q){return c?Array.isArray(c.conditions)?c.op==="or"?c.conditions.some(O=>Se(O,q)):c.op==="not"?!c.conditions.every(O=>Se(O,q)):c.conditions.every(O=>Se(O,q)):ge(c,q):!0}function Ee(c={}){const q=T(c.key,()=>{}),O=T(B(c.rowKey,"routes"),e=>e.rowKey),A=!!c.overlap,_=typeof c.onUnrouted=="function"?c.onUnrouted:null,ae=Number.isFinite(c.selectionDebounce)?Number(c.selectionDebounce):16,Te=typeof c.onWrite=="function"?c.onWrite:null,Ze=typeof c.onConflict=="function"?c.onConflict:null,d=c.seq!=null?T(c.seq,()=>{}):null,g=d?c.dedupe!==!1:!1,S=O;let P=null;typeof c.batch=="number"?P=c.batch:c.batch&&Number.isFinite(c.batch.intervalMs)&&(P=Number(c.batch.intervalMs));const ne=P!==null||!!c.coalesce,W=new Map;let de,Me=0;const $e=[];let a=null;const l=c.time!=null?T(c.time,()=>{}):null,w=typeof c.now=="function"?c.now:Date.now,H=1e4;let y=!1,F=null,D=null,M="time",i=new Map;const u=[];let f=0,j,Z,me=!1,J=null,Pe=[],Ie=0,Ge=0,Fe="time",_e=!1,Je=null,nt=null;const ft=e=>{if(e&&Number.isFinite(e.seq))return e.seq;if(d&&e&&e.row){const t=d(e.row);return Number.isFinite(t)?t:void 0}},At=e=>{if(e&&Number.isFinite(e.t))return e.t;if(l&&e&&e.row){const t=l(e.row);if(Number.isFinite(t))return t}return w()},Le=[];let Qe=null;const Ve=[],Ce=[],rt=new Map,at=new Set;let Xe=null,et=0;const ot=new Map,ut=new Set,it=typeof c.rowKey=="string"?c.rowKey:"rowKey",He=new Map;let wt=0;const ht=new Map,Ye=(e,t)=>{ht.set(e,(ht.get(e)||0)+t)};let vt=0;const k=new Map,R=new Map;let $=null;const C=Number.isFinite(c.metricsInterval)?Number(c.metricsInterval):1e3;let m=0,z=null,ue="lattice-router",je=250,we=null,te=null,Ae=!1,Ke=!1,Re=null,Be=!1,re=null;const le=[],G=()=>Qe?[...Le,Qe]:Le,We=e=>G().find(t=>t.grid===e)||null,lt=e=>{const t=[];for(const n of Le)if(n.match(e)&&(t.push(n),!A))break;return t.length?t:Qe?[Qe]:[]},Et=(e,t)=>{if(t.add.length||t.update.length||t.remove.length){const n=e.sink(t);kt(e,n)}return{added:t.add.length,updated:t.update.length,removed:t.remove.length}},kt=(e,t)=>{const n=t?.rejected;if(!Array.isArray(n)||!n.length)return;const r=n.filter(s=>s&&s.operation==="remove");if(!r.length)return;const o=e.label||`route ${e.routeId}`;V(`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.`)},Nt=(e,t)=>{for(const n of Ve)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},Ue=e=>{const t=[];for(const h of e.partition.values())e.filter&&!e.filter(h)||Nt(e,h)&&t.push(h);let n;if(e.rollup){const h=new Map;for(const b of t){const{key:I,fields:X}=e.rollup.group(b);let Y=h.get(I);Y||(Y={key:I,fields:X,rows:[]},h.set(I,Y)),Y.rows.push(b)}let v=[];for(const b of h.values()){const I={...b.fields};for(const[X,Y]of e.rollup.specs)I[X]=he(Y,b.rows);v.push({gkey:b.key,row:I})}e.sort&&v.sort((b,I)=>e.sort(b.row,I.row)),e.transform&&(v=v.map(b=>({gkey:b.gkey,row:e.transform(b.row)}))),n=new Map(v.map(b=>[b.gkey,b.row]))}else{let h=t;e.sort&&(h=h.slice().sort(e.sort)),n=new Map;for(const v of h)n.set(N([e.keyOf(v)]),e.transform?e.transform(v):v)}const r=[],o=[],s=[];for(const[h,v]of n)e.keys.has(h)?De(e.keys.get(h),v)||o.push(v):r.push(v);for(const h of e.keys.keys())n.has(h)||s.push(h);return e.keys=n,Et(e,{add:r,update:o,remove:s})},dt=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),Ue(e),e.bpPending=0,e.bpLastFlush=w()},x=(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,dt(e)},n),e.bpTimer&&typeof e.bpTimer.unref=="function"&&e.bpTimer.unref()},qe=(e,t)=>{if(!e.bp){Ue(e);return}e.bpPending+=t,e.bpCoalesced+=t;const n=e.bp;if(n.maxLag!=null&&e.bpPending<=n.maxLag&&!e.bpTimer){dt(e);return}const r=w(),o=r-e.bpLastFlush>=n.minInterval,s=e.bpPending>=n.sample;if(o&&s){dt(e);return}x(e,r)},ze=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),e.bpPending=0,e.bpLastFlush=w()},gt=(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(s=>s&&s[n]));return s=>o.has(s&&s[r])}return null},Ft=e=>{const t=We(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)},cn=e=>{const t=e&&e.selection;if(!t||typeof t.predicate!="function")return null;const n=t.predicate();if(!n||n.all!==!0)return null;const r=typeof t.count=="function"?t.count():Promise.resolve(null);return{predicate:n,count:r}},pt=e=>{const t=cn(e.from);if(t){if(typeof e.relation=="function"&&e.relation.length>=2){const r=e.relation(Ft(e.from),t);e.predicate=typeof r=="function"?r:null}else V("data-router:link-predicate-unsupported","link()/relate() source grid has every row matching a filter selected on a source that holds only the rows it has loaded. The relation does not declare it accepts a predicate selection — a function taking (selected, { predicate, count }) as its second parameter — so the link cannot build a target-row predicate from a truncated key list and imposes no constraint."),e.predicate=null;return}const n=Ft(e.from);e.predicate=n.length?gt(e.relation,n):null},mt=()=>{const e=new Set;for(const t of Ce)e.add(t.from),e.add(t.to);return e},ct=()=>{for(const s of G())s.graphPreds=null;if(!Ce.length)return;const e=mt(),t=new Map;for(const s of e){const h=Ft(s);h.length&&t.set(s,h)}const n=new Map(t);let r=!0,o=(e.size+1)*2;for(;r&&o-- >0;){r=!1;for(const s of e){if(t.has(s))continue;const h=Ce.filter(Y=>Y.to===s&&n.has(Y.from));if(!h.length)continue;const v=We(s);if(!v)continue;const b=h.map(Y=>gt(Y.rel,n.get(Y.from))).filter(Boolean),I=[];for(const Y of v.partition.values())b.every(Ne=>Ne(Y))&&I.push(Y);const X=n.get(s);if(!X||X.length!==I.length)n.set(s,I),r=!0;else{const Y=new Set(X);I.some(Ne=>!Y.has(Ne))&&(n.set(s,I),r=!0)}}}for(const s of Ce){if(!n.has(s.from))continue;const h=gt(s.rel,n.get(s.from));if(!h)continue;const v=We(s.to);v&&(v.graphPreds||(v.graphPreds=[])).push(h)}},Kt=e=>{const t=rt.get(e);if(t){t.count+=1;return}const n=e&&typeof e.on=="function"?e.on("selection:changed",()=>fn(e)):()=>{};rt.set(e,{off:n,count:1})},Lt=()=>{Xe&&(clearTimeout(Xe),Xe=null);const e=at;if(!e.size)return;const t=new Set;for(const n of Ve)e.has(n.from)&&(pt(n),t.add(n.to));if(at.clear(),Ce.length){ct();for(const n of mt())t.add(n)}for(const n of t){const r=We(n);r&&Ue(r)}},fn=e=>{if(at.add(e),ae<=0){Lt();return}Xe||(Xe=setTimeout(Lt,ae))},Ut=e=>{const t=rt.get(e);t&&(t.count-=1,t.count<=0&&(t.off(),rt.delete(e)))},dn=e=>typeof e=="function"?t=>e(t):e&&e.rows&&typeof e.rows.apply=="function"?t=>e.rows.apply(t):(V("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."),()=>{}),Dt=(e,t,n)=>({grid:e,routeId:E(),sink:dn(e),match:t,keyOf:T(B(n.rowKey,"routes"),O),partition:new Map,keys:new Map,transform:typeof n.transform=="function"?n.transform:null,filter:typeof n.filter=="function"?n.filter:null,sort:Q(n.sort),rollup:n.rollup&&n.rollup.groupBy!=null?{group:ie(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:K(n.backpressure),bpPending:0,bpTimer:null,bpLastFlush:-1/0,bpCoalesced:0}),zt=e=>{if(!A){for(const t of Le)if(t.hasPartValue&&t.partValue===e){V(`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}}},Vt=(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},St=(e,t)=>{const n=e.grid;if(!n||!n.edit||typeof n.edit.setCells!="function")return;const r=Vt(t.key,t.colId);ut.add(r);try{n.edit.setCells([{key:t.key,colId:t.colId,value:t.before}],"cell")}finally{ut.delete(r)}Ye("writeReverted",1)},Gt=e=>{e&&xe.apply([{op:"upsert",row:e}])},_t=(e,t,n)=>{const r=n&&typeof n=="object"?n:null,o=r&&r.conflict!==void 0?r.conflict:null;if(o){const s=e.onConflict||Ze;if(s)try{s(t,{serverRow:o})}catch{}Ye("writeConflicted",1),Gt(r&&r.row?r.row:t.row);return}if(n===!1||r&&r.ok===!1){Ye("writeRejected",1),St(e,t);return}Ye("writeAccepted",1),Gt(r&&r.row?r.row:t.row)},hn=e=>{const t=String(e);for(const n of He.values())if(n.live.has(t))return n.handle;return null},gn=(e,t)=>{if(!t||t.key===void 0||t.colId===void 0||ut.has(Vt(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(Ye("writeRouted",1),e.readonly){V("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."),St(e,r);return}const o=e.onWrite||Te;if(!o){V("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 s;try{s=o(r,{route:e.grid,source:hn(r.key)})}catch{St(e,r),Ye("writeRejected",1);return}s&&typeof s.then=="function"?s.then(h=>_t(e,r,h),()=>{St(e,r),Ye("writeRejected",1)}):_t(e,r,s)},mn=e=>{const t=e.grid;if(!t||typeof t.on!="function"||!t.edit||typeof t.edit.setCells!="function"){V("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(ot.has(t))return;const n=t.on("cell:changed",r=>gn(e,r));ot.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},Ot=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},$t=(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)}},yt=()=>{const e=new Map;for(const t of G())for(const n of t.partition.values())e.set(String(S(n)),n);return[...e.values()]},Jt=()=>{i=new Map;for(const e of G())for(const t of e.partition.values())i.set(String(S(t)),t);u.length=0,f=0,j=de,Z=void 0},Qt=()=>{const e=u.shift();e&&(e.op==="del"?i.delete(e.key):i.set(e.key,e.row),j=e.seq,Z=e.t)},wn=()=>{if(F!=null)for(;u.length>F;)Qt();if(D!=null&&u.length){const e=u[u.length-1].t;for(;u.length>1&&e-u[0].t>D;)Qt()}},vn=e=>{!e||!e.row||u.push({pos:f++,seq:ft(e),t:At(e),op:e.op==="delete"?"del":"set",key:String(S(e.row)),row:e.row})},It=(e,t)=>t==="seq"?e.seq:e.t,Pt=(e,t)=>{const n=new Map(i);for(const r of u){const o=It(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},Rt=e=>{const t=new Map(G().map(n=>[n,[]]));for(const n of e)for(const r of lt(n))t.get(r).push(n);for(const n of G())n.partition=new Map(t.get(n).map(r=>[String(n.keyOf(r)),r]));for(const n of Ve)pt(n);ct();for(const n of G())Ue(n)},Ct=e=>y?!0:(V("data-router:no-buffer",`${e}() needs a buffered window; call router.buffer({ window, max }) first to record one.`),!1),Tt=()=>{if(Je&&(clearTimeout(Je),Je=null),_e=!1,Pe=[],Ie=0,nt){const e=nt;nt=null,e()}},En=()=>{if(Pe=[],Ie=0,nt){const e=nt;nt=null,e()}},kn=()=>{Je=null;const e=Pe[Ie++];e.op==="del"?J.delete(e.key):J.set(e.key,e.row),Rt([...J.values()]),m=e.pos+1,Wt()};function Wt(){if(!_e){if(Ie>=Pe.length){En();return}Je=setTimeout(kn,Ge)}}function jt(e){if(Re)try{Re.postMessage(e)}catch{}}function Yt(){return{t:"snapshot",rows:yt(),seq:de,checkpoint:Object.fromEntries(W)}}function Sn(e){const t=e&&e.data;if(!(!t||typeof t!="object")){if(t.t==="hello"){yt().length&&jt(Yt());return}Be=!0;try{t.t==="delta"?xe.apply(t.deltas||[]):t.t==="snapshot"&&(xe.load(t.rows||[]),t.checkpoint&&xe.seenThrough(t.checkpoint))}finally{Be=!1}}}function On(e,t){e.partition=new Map(t.map(n=>[String(e.keyOf(n)),n]))}function Pn(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 s=[];for(const v of n)if(v.match(o)&&(s.push(v),!A))break;const h=s.length?s:r?[r]:[];if(!h.length){et+=1,_&&_(o);continue}for(const v of h)v.partition.set(String(v.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[it]}`},Zt=(e,t)=>{const n={...e.map?e.map(t):t};return e.ns&&(n[it]=e.ns(n)),n},Xt=(e,t)=>{const n=[];for(const r of t||[]){if(!r||!r.row)continue;const o=Zt(e,r.row),s=String(o[it]);r.op==="delete"?e.live.delete(s):e.live.set(s,o),n.push({...r,row:o})}return e.ingested+=n.length,Ye(`source:${e.id}`,n.length),n},Tn=e=>({get id(){return e.id},get size(){return e.live.size},load(t){const n=(t||[]).map(s=>Zt(e,s)),r=new Map(n.map(s=>[String(s[it]),s])),o=[];for(const[s,h]of e.live)r.has(s)||o.push({op:"delete",row:h});for(const s of n)o.push({op:"upsert",row:s});return e.live=r,e.ingested+=n.length,Ye(`source:${e.id}`,n.length),Bt(e,o,s=>xe.apply(s)),this},apply(t){return Bt(e,Xt(e,t),n=>xe.apply(n)),this},push(t){return Bt(e,Xt(e,Array.isArray(t)?t:[t]),n=>xe.push(n)),this},remove(){const t=[];for(const n of e.live.values())t.push({op:"delete",row:n});return e.live.clear(),He.delete(e.id),t.length&&xe.apply(t),xe}}),Mt=e=>e==null?null:String(e),jn=(e,t)=>{if(!e||typeof e!="object")return null;const n=e.from!=null?String(e.from):null;if(!n)return V("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=Ne=>Ne[r];else return V("data-router:join-no-localkey","join needs a `localKey` (a field name or fn); ignoring the join."),null;const s=e.foreignKey!=null?e.foreignKey:e.fromKey;let h,v;if(typeof s=="function")h=s,v=s;else if(typeof s=="string")h=Ne=>Ne[s],v=s;else if(typeof r=="string")h=Ne=>Ne[r],v=r;else return V("data-router:join-no-foreignkey","join with a fn `localKey` needs an explicit string/fn `foreignKey`; ignoring the join."),null;let b=null;const I=[],X=e.fields!=null?e.fields:e.select;if(typeof X=="function")b=X;else if(Array.isArray(X))for(const Ne of X)I.push([String(Ne),String(Ne)]);else if(X&&typeof X=="object")for(const[Ne,bt]of Object.entries(X))I.push([Ne,String(bt)]);else V("data-router:join-no-fields","join has no `fields`/`select`; rows pass through unenriched.");let Y=e.missing;return Y!=="hold"&&Y!=="passthrough"&&Y!=="null"&&(Y!=null&&V("data-router:join-bad-missing",`join.missing "${Y}" is not hold|passthrough|null; using "passthrough".`),Y="passthrough"),{from:n,localKey:o,foreignKeyFn:h,ffKey:v,pairs:I,selectFn:b,missing:Y,keyIndex:new Map,lastFk:new Map,owner:t,probe:null}},en=(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,s]of e.pairs)r[s]=n?n[o]:null;return r},An=(e,t)=>{if(t==null||!e.probe)return null;const n=e.probe.index.get(t);if(!n||!n.size)return null;const r=He.get(e.from);if(!r)return null;let o;for(o of n);return r.live.get(o)||null},tn=(e,t,n)=>{const r=An(e,n);return r?{emit:!0,row:en(e,t,r)}:e.missing==="hold"?{emit:!1,row:t}:e.missing==="null"?{emit:!0,row:en(e,t,null)}:{emit:!0,row:{...t}}},nn=(e,t,n)=>{const r=e.lastFk.get(t);if(r!==void 0&&r!==n){const s=e.keyIndex.get(r);s&&(s.delete(t),s.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)},Nn=(e,t)=>{const n=e.join,r=[];for(const o of t){const s=String(o.row[it]);if(o.op==="delete"){nn(n,s,null),n.lastFk.delete(s),r.push(o);continue}const h=Mt(n.localKey(o.row));nn(n,s,h);const v=tn(n,o.row,h);v.emit&&r.push({...o,row:v.row})}return r},rn=(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 s=Mt(n.fn(o));if(s==null)continue;let h=n.index.get(s);h||(h=new Set,n.index.set(s,h)),h.add(r),n.prev.set(r,s)}}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 s of t){const h=String(s.row[it]);if(s.op==="delete"){const I=r.prev.get(h);if(I!=null){const X=r.index.get(I);X&&(X.delete(h),X.size||r.index.delete(I)),o.add(I)}r.prev.delete(h);continue}const v=Mt(r.fn(s.row)),b=r.prev.get(h);if(b!=null&&b!==v){const I=r.index.get(b);I&&(I.delete(h),I.size||r.index.delete(b)),o.add(b)}if(v!=null){let I=r.index.get(v);I||(I=new Set,r.index.set(v,I)),I.add(h),o.add(v)}r.prev.set(h,v)}if(o.size)for(const s of r.specs)for(const h of o){const v=s.keyIndex.get(h);if(v)for(const b of v){const I=s.owner.live.get(b);if(!I)continue;const X=tn(s,I,h);n.push(X.emit?{op:"upsert",row:X.row}:{op:"delete",row:I})}}}n.length&&xe.apply(n)},Bt=(e,t,n)=>{n(e.join?Nn(e,t):t),e.probes&&e.probes.size&&Fn(e,t)},qt=(e,t,n)=>{const r=k.get(e);if(k.set(e,{cur:t,t:n}),!r)return 0;const o=(n-r.t)/1e3;return o<=0?0:(t-r.cur)/o},Ln=()=>{if(!y)return 0;let e=0;for(const t of u)t.pos>=m&&(e+=1);return e},Dn=(e,t)=>{const n=R.get(e);if(n)for(const r of n)try{r(t)}catch{}},$n=()=>{$||C<=0||($=setInterval(()=>Dn("metrics",xe.metrics()),C),$&&typeof $.unref=="function"&&$.unref())},on=()=>{$&&(clearInterval($),$=null)},In=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 s=()=>o||(o=new Promise((h,v)=>{let b;try{b=t.open(n,1)}catch(I){v(I);return}b.onupgradeneeded=()=>{const I=b.result;I.objectStoreNames.contains(r)||I.createObjectStore(r)},b.onsuccess=()=>h(b.result),b.onerror=()=>v(b.error)}),o);return{set(h,v){return s().then(b=>new Promise((I,X)=>{const Y=b.transaction(r,"readwrite");Y.objectStore(r).put(v,h),Y.oncomplete=()=>I(),Y.onerror=()=>X(Y.error),Y.onabort=()=>X(Y.error)}))},get(h){return s().then(v=>new Promise((b,I)=>{const Y=v.transaction(r,"readonly").objectStore(r).get(h);Y.onsuccess=()=>b(Y.result),Y.onerror=()=>I(Y.error)}))},close(){o&&o.then(h=>{try{h.close()}catch{}},()=>{})}}},Cn=()=>y?[...Pt(void 0,M).values()]:yt(),Wn=()=>({v:1,world:Cn(),maxSeq:de,checkpoint:Object.fromEntries(W),buffer:y?{on:!0,max:F,window:D,domain:M,pos:f,baseSeq:j,baseT:Z,base:[...i.entries()],log:u.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;Ke=!0;try{xe.load(Array.isArray(e.world)?e.world:[])}finally{Ke=!1}e.checkpoint&&xe.seenThrough(e.checkpoint),Number.isFinite(e.maxSeq)&&(de===void 0||e.maxSeq>de)&&(de=e.maxSeq);const t=e.buffer;if(t&&t.on){y=!0,F=Number.isFinite(t.max)?t.max:null,D=Number.isFinite(t.window)?t.window:null,M=t.domain==="seq"||t.domain==="time"?t.domain:d?"seq":"time",i=new Map(Array.isArray(t.base)?t.base:[]),u.length=0;for(const n of Array.isArray(t.log)?t.log:[])u.push({...n});f=Number.isFinite(t.pos)?t.pos:u.length,j=t.baseSeq,Z=t.baseT,m=f}return!0},Ht=()=>{if(!z)return Promise.resolve();const e=Wn(),t=Promise.resolve().then(()=>z.set(ue,e)).catch(()=>{});return te=t,t.then(()=>{te===t&&(te=null)})},xt=()=>{if(!(!Ae||!z||Ke)){if(je<=0){Ht();return}we||(we=setTimeout(()=>{we=null,Ht()},je),we&&typeof we.unref=="function"&&we.unref())}},xe={attach(e,t,n={}){const r=typeof t!="function",o=r?h=>q(h)===t:t;r&&zt(t);const s=Dt(e,o,n);return r&&(s.hasPartValue=!0,s.partValue=t),Le.push(s),s.writable&&mn(s),this},attachDefault(e,t={}){return Qe=Dt(e,()=>!1,t),Qe.isDefault=!0,this},subscribe(e,t,n={}){const r=typeof e!="function",o=r?h=>q(h)===e:e;r&&zt(e);const s=Dt(t,o,n);return r&&(s.hasPartValue=!0,s.partValue=e),Le.push(s),this},alert(e,t,n,r={}){const s={match:typeof e=="function"?e:h=>q(h)===e,keyOf:T(B(r.rowKey,"alerts"),O),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 le.push(s),$t(s,yt()),Ot(s),this},monitor(e,t,n,r={}){const s={kind:"monitor",match:typeof e=="function"?e:h=>q(h)===e,keyOf:T(B(r.rowKey,"alerts"),O),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 le.push(s),$t(s,yt()),Ot(s),()=>{const h=le.indexOf(s);h>=0&&le.splice(h,1),s.timer&&(clearTimeout(s.timer),s.timer=null),s.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};Ve.push(r),Kt(e),pt(r);const o=We(t);return o&&Ue(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;Ce.push({from:t.from,to:t.to,rel:n}),t.mutual&&Ce.push({from:t.to,to:t.from,rel:U(n)})}for(const t of mt())Kt(t);ct();for(const t of mt()){const n=We(t);n&&Ue(n)}return this},flush(){return Lt(),this},detach(e){const t=new Set;for(let o=Ve.length-1;o>=0;o--){const s=Ve[o];(s.from===e||s.to===e)&&(s.to!==e&&t.add(s.to),Ut(s.from),Ve.splice(o,1))}let n=!1;for(let o=Ce.length-1;o>=0;o--)(Ce[o].from===e||Ce[o].to===e)&&(Ut(Ce[o].from),Ce.splice(o,1),n=!0);for(let o=Le.length-1;o>=0;o--)Le[o].grid===e&&Le.splice(o,1);Qe&&Qe.grid===e&&(Qe=null),at.delete(e);const r=ot.get(e);if(r&&(r(),ot.delete(e)),n){ct();for(const o of mt())t.add(o)}for(const o of t){const s=We(o);s&&Ue(s)}return this},load(e){et=0;const t=new Map(G().map(r=>[r,[]]));for(const r of e||[]){const o=lt(r);if(!o.length){et+=1,_&&_(r);continue}for(const s of o)t.get(s).push(r)}for(const r of G()){const o=t.get(r);r.partition=new Map(o.map(s=>[String(r.keyOf(s)),s])),r.metricRows+=o.length,vt+=o.length}if(d)for(const r of e||[]){const o=d(r);if(!Number.isFinite(o))continue;const s=String(S(r)),h=W.get(s);(h===void 0||o>h)&&W.set(s,o),(de===void 0||o>de)&&(de=o)}for(const r of Ve)pt(r);ct();for(const r of le)$t(r,e||[]),Ot(r);for(const r of G())r.bp&&ze(r);const n=G().map(r=>Ue(r));return y&&Jt(),m=f,Re&&!Be&&jt(Yt()),xt(),n},apply(e){let t=(e||[]).filter(o=>o&&o.row);if(g){t=t.map((s,h)=>[s,h]).sort((s,h)=>{const v=ft(s[0]),b=ft(h[0]);return v===void 0||b===void 0?s[1]-h[1]:v-b||s[1]-h[1]}).map(s=>s[0]);const o=[];for(const s of t){const h=ft(s);if(h!==void 0){const v=String(S(s.row)),b=W.get(v);if(b!==void 0&&h<=b){Me+=1;continue}W.set(v,h),(de===void 0||h>de)&&(de=h)}o.push(s)}t=o}if(Re&&!Be&&t.length&&jt({t:"delta",deltas:t.map(o=>({op:o.op,row:o.row,seq:o.seq}))}),y){for(const o of t)vn(o);wn()}for(const o of le)bn(o,t),Ot(o);if(me){xt();return}const n=new Map(G().map(o=>[o,new Map]));for(const o of t){const s=o&&o.row;if(!s)continue;if(o.op==="delete"){let v=!1;for(const b of G()){const I=String(b.keyOf(s));(b.partition.has(I)||n.get(b).has(I))&&(n.get(b).set(I,{op:"del"}),v=!0)}!v&&!lt(s).length&&(et+=1,_&&_(o));continue}const h=lt(s);if(!h.length){et+=1,_&&_(o);continue}for(const v of G()){if(h.includes(v))continue;const b=String(v.keyOf(s));(v.partition.has(b)||n.get(v).get(b)?.op==="set")&&n.get(v).set(b,{op:"del"})}for(const v of h)n.get(v).set(String(v.keyOf(s)),{op:"set",row:s})}const r=new Map;for(const o of G()){let s=0;const h=n.get(o).size;for(const[v,b]of n.get(o)){if(b.op==="del"){o.partition.delete(v);continue}o.partition.set(v,b.row),s+=1}o.metricRows+=s,vt+=s,r.set(o,h)}for(const o of Ve)pt(o);ct();for(const o of G())qe(o,r.get(o)||0);m=f,xt()},push(e){const t=Array.isArray(e)?e:[e];if(!ne)return this.apply(t),this;for(const n of t)$e.push(n);return P!==null&&(P<=0?this.flushStream():a||(a=setTimeout(()=>this.flushStream(),P))),this},flushStream(){if(a&&(clearTimeout(a),a=null),!$e.length)return this;const e=$e.splice(0,$e.length);return this.apply(e),this},flushBackpressure(){for(const e of G())e.bp&&(e.bpTimer||e.bpPending>0)&&dt(e);return this},addSource(e,t){let n,r;e&&typeof e=="object"?(r=e,n=r.id!=null?String(r.id):`source${++wt}`):(n=e!=null?String(e):`source${++wt}`,r=t||{});const o=He.get(n);if(o)return V("data-router:duplicate-source",`addSource("${n}") was already registered; returning the existing source handle. Use a distinct id per feed.`),o.handle;const s={id:n,map:typeof r.map=="function"?r.map:null,ns:Rn(n,r.key),live:new Map,ingested:0};s.handle=Tn(s),s.join=jn(r.join,s),He.set(n,s),s.join&&He.has(s.join.from)&&rn(He.get(s.join.from),s.join);for(const h of He.values())h!==s&&h.join&&h.join.from===n&&h.join.probe==null&&rn(s,h.join);return s.handle},removeSource(e){const t=e&&typeof e=="object"&&e.id!==void 0?String(e.id):String(e),n=He.get(t);return n&&n.handle.remove(),this},sources(){return[...He.keys()]},metrics(){const e=w(),t=G().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:qt(`route:${o}`,r.metricRows,e),backpressure:r.bp?{pending:r.bpPending,coalesced:r.bpCoalesced}:null})),n=[...He.values()].map(r=>({id:r.id,rows:r.live.size,ingested:r.ingested,throughput:qt(`source:${r.id}`,r.ingested,e)}));return{routes:t,sources:n,unrouted:et,dropped:Me,buffered:u.length,lag:Ln(),throughput:qt("total",vt,e)}},on(e,t){if(typeof t!="function")return()=>{};let n=R.get(e);return n||(n=new Set,R.set(e,n)),n.add(t),e==="metrics"&&$n(),()=>{n.delete(t),e==="metrics"&&n.size===0&&on()}},mountDevtools(e,t={}){return be(this,e,t)},get unrouted(){return et},get dropped(){return Me},lastSeq(){return de},checkpoint(){return new Map(W)},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 s=W.get(String(n));(s===void 0||o>s)&&W.set(String(n),o),(de===void 0||o>de)&&(de=o)}return this},persist(e={}){if(Ae=!0,typeof e.key=="string"&&(ue=e.key),Number.isFinite(e.debounce)&&(je=Number(e.debounce)),e.storage&&typeof e.storage.get=="function"&&typeof e.storage.set=="function")z=e.storage;else{let t=null;try{t=In(e)}catch{t=null}t?z=t:(z=null,V("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(!z)return!1;let e;try{e=await z.get(ue)}catch{return!1}return e==null?!1:Mn(e)},async flushPersist(){return we&&(clearTimeout(we),we=null),await Ht(),te&&await te,this},get persisting(){return Ae&&!!z},buffer(e={}){return y=!0,Number.isFinite(e.max)?F=Number(e.max):"max"in e&&e.max==null&&(F=null),Number.isFinite(e.window)?D=Number(e.window):"window"in e&&e.window==null&&(D=null),F==null&&D==null&&(F=H,V("data-router:buffer-default-cap",`buffer() called with no window or max; applying a default cap of ${H} deltas so the buffer stays bounded. Pass { window } or { max } to size it.`)),M=d?"seq":"time",Jt(),this},scrubTo(e,t={}){if(!Ct("scrubTo"))return this;Tt(),me=!0;const n=t.by||M;J=Pt(e,n),Rt([...J.values()]),m=0;for(const r of u){const o=It(r,n);if(e!==void 0&&o!==void 0&&o>e)break;m=r.pos+1}return this},replay(e,t,n={}){if(!Ct("replay"))return Promise.resolve();Tt(),me=!0;const r=n.by||M;return Fe=r,Ge=Number.isFinite(n.speed)?Number(n.speed):0,J=Pt(e,r),Rt([...J.values()]),Pe=u.filter(o=>{const s=It(o,r);return s!==void 0&&s>e&&s<=t}).slice().sort((o,s)=>o.pos-s.pos),Ie=0,_e=!1,new Promise(o=>{nt=o,Wt()})},pause(){return _e=!0,Je&&(clearTimeout(Je),Je=null),this},resume(){return _e?(_e=!1,Wt(),this):this},live(){return Ct("live")?(Tt(),me=!1,J=null,Rt([...Pt(void 0,M).values()]),m=f,this):this},get traveling(){return me},get buffered(){return u.length},broadcast(e={}){if(typeof BroadcastChannel!="function")return V("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?(Re&&(Re.close(),Re=null),Re=new BroadcastChannel(t),Re.onmessage=Sn,jt({t:"hello"}),this):(V("data-router:broadcast-channel","router.broadcast({ channel }) needs a string channel name; nothing was mirrored."),this)},get broadcasting(){return!!Re},async query(e,t={}){if(!e||typeof e.execute!="function")return V("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=ee(e.capabilities),r=t||{},o=r.filters||null,s=[];et=0;const h=G().filter(b=>b.where),v=G().filter(b=>!b.where);for(const b of h){const I=se(o,b.where),X=ve({...r,filters:I},n);let Ne=((await e.execute(X.pushed,r)).rows||[]).slice();X.residual&&X.residual.filters&&(Ne=Ne.filter(bt=>Se(X.residual.filters,bt))),Ne=Ne.filter(bt=>b.match(bt)),On(b,Ne),s.push({route:b.grid,pushedFilter:!!(X.pushed&&X.pushed.filters),residual:X.unpushed.slice()})}if(v.length){const b=ve(r,n);let X=((await e.execute(b.pushed,r)).rows||[]).slice();b.residual&&b.residual.filters&&(X=X.filter(Y=>Se(b.residual.filters,Y))),Pn(X,v),s.push({base:!0,pushedFilter:!!(b.pushed&&b.pushed.filters),residual:b.unpushed.slice()})}re=s;for(const b of Ve)pt(b);ct();for(const b of G())Ue(b);return this},lastQueryPlan(){return re?re.map(e=>({...e})):null},destroy(){if(Xe&&(clearTimeout(Xe),Xe=null),a&&(clearTimeout(a),a=null),we&&(clearTimeout(we),we=null),z&&typeof z.close=="function")try{z.close()}catch{}Ae=!1,z=null,Re&&(Re.close(),Re=null),Be=!1,Tt(),y=!1,me=!1,J=null,u.length=0,i.clear();for(const e of rt.values())e.off();rt.clear();for(const e of ot.values())e();ot.clear(),ut.clear(),He.clear(),on(),R.clear(),k.clear();for(const e of le)e.timer&&(clearTimeout(e.timer),e.timer=null);le.length=0;for(const e of G())e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null);Ve.length=0,Ce.length=0,at.clear(),$e.length=0,W.clear(),Le.length=0,Qe=null}};return c.config&&xe.configure(c.config),xe}function De(c,q){if(c===q)return!0;if(!c||!q)return!1;const O=Object.keys(c),A=Object.keys(q);if(O.length!==A.length)return!1;for(const _ of O)if(c[_]!==q[_])return!1;return!0}const tt=Ee});const ln=un("packages/modules/data-router/index.js"),Bn=ln.createDataRouter;var qn=ln.default;export{Bn as createDataRouter,qn as default};
|
|
6
|
+
var sn=Object.create(null),an=Object.create(null);function st(p,Oe){sn[p]=Oe}function un(p){var Oe=an[p];if(Oe)return Oe;var pe=Object.create(null);an[p]=pe;var V=sn[p];if(!V)throw new Error("[lattice] missing module: "+p);return V(pe,un),pe}st("packages/core/src/internal/util.js",function(p,Oe){"use strict";Object.defineProperty(p,"VERSION",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(p,"reportedWarnings",{enumerable:!0,get:function(){return L}}),Object.defineProperty(p,"warnOnce",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(p,"infoOnce",{enumerable:!0,get:function(){return K}}),Object.defineProperty(p,"resetWarnings",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(p,"fail",{enumerable:!0,get:function(){return E}}),Object.defineProperty(p,"invariant",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(p,"DEV",{enumerable:!0,get:function(){return he}}),Object.defineProperty(p,"isObject",{enumerable:!0,get:function(){return U}}),Object.defineProperty(p,"isFunction",{enumerable:!0,get:function(){return se}}),Object.defineProperty(p,"isNil",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(p,"isBlank",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(p,"isCtor",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(p,"pathGetter",{enumerable:!0,get:function(){return De}}),Object.defineProperty(p,"pathSetter",{enumerable:!0,get:function(){return c}}),Object.defineProperty(p,"getPath",{enumerable:!0,get:function(){return q}}),Object.defineProperty(p,"setPath",{enumerable:!0,get:function(){return O}}),Object.defineProperty(p,"humanise",{enumerable:!0,get:function(){return A}}),Object.defineProperty(p,"escapeHtml",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(p,"titleCase",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(p,"expand",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(p,"toArray",{enumerable:!0,get:function(){return d}}),Object.defineProperty(p,"merge",{enumerable:!0,get:function(){return S}}),Object.defineProperty(p,"mergeRow",{enumerable:!0,get:function(){return P}}),Object.defineProperty(p,"Lru",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(p,"collator",{enumerable:!0,get:function(){return de}}),Object.defineProperty(p,"defaultCompare",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(p,"now",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(p,"nextFrame",{enumerable:!0,get:function(){return l}}),Object.defineProperty(p,"cancelFrame",{enumerable:!0,get:function(){return w}}),Object.defineProperty(p,"frameBatched",{enumerable:!0,get:function(){return H}}),Object.defineProperty(p,"settleDebounce",{enumerable:!0,get:function(){return y}}),Object.defineProperty(p,"whenIdle",{enumerable:!0,get:function(){return F}}),Object.defineProperty(p,"uid",{enumerable:!0,get:function(){return M}});const pe="1.81.0";async function V(){return pe}const oe="1.81.0",ve=new Set,ee=2e3;function ke(i){if(ve.add(i),ve.size>ee){const u=ve.values().next().value;u!==void 0&&ve.delete(u)}}const N=[],ye=500;function be(i,u,f){N.push({key:i,level:u,message:f.map(j=>typeof j=="string"?j:T(j)).join(" "),at:Date.now()}),N.length>ye&&N.shift()}function T(i){if(i instanceof Error)return i.message;try{return JSON.stringify(i)}catch{return String(i)}}function L(){return N.map(i=>({...i}))}function B(i){if(i.length===0||typeof i[0]!="string")return i;const u=i[0].replace(/^\[lattice\]\s*/,"");return u===i[0]?i:[u,...i.slice(1)]}function Q(i,...u){if(ve.has(i))return;ke(i);const f=B(u);be(i,"warn",f),console.warn("[lattice]",...f)}function K(i,...u){if(ve.has(i))return;ke(i);const f=B(u);be(i,"info",f),console.info("[lattice]",...f)}function ce(){ve.clear(),N.length=0}function E(i,u){const f=new Error(`[lattice] ${i}`);throw u!==void 0&&(f.cause=u),f}function ie(i,u){i||E(u)}const he=(()=>{try{return!(typeof process<"u"&&process.env&&process.env.NODE_ENV==="production")}catch{return!0}})();function U(i){return i!==null&&typeof i=="object"&&!Array.isArray(i)}function se(i){return typeof i=="function"}function fe(i){return i==null}function ge(i){return i==null||i===""}function Se(i){return typeof i!="function"?!1:/^class[\s{]/.test(Function.prototype.toString.call(i))?!0:!!(i.prototype&&Object.getOwnPropertyNames(i.prototype).length>1)}const Ee=new Map;function De(i){let u=Ee.get(i);if(u)return u;if(!i.includes("."))u=f=>f?.[i];else{const f=i.split("."),j=f.length;u=Z=>{let me=Z;for(let J=0;J<j;J++){if(me==null)return;me=me[f[J]]}return me}}return Ee.set(i,u),u}const tt=new Map;function c(i){let u=tt.get(i);if(u)return u;if(!i.includes("."))u=(f,j)=>{f!=null&&(f[i]=j)};else{const f=i.split("."),j=f.length-1;u=(Z,me)=>{let J=Z;for(let Pe=0;Pe<j;Pe++){if(J==null)return;const Ie=f[Pe];J[Ie]==null&&(J[Ie]={}),J=J[Ie]}J!=null&&(J[f[j]]=me)}}return tt.set(i,u),u}function q(i,u){return De(u)(i)}function O(i,u,f){c(u)(i,f)}function A(i){return i?(i.includes(".")?i.slice(i.lastIndexOf(".")+1):i).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(/^./,f=>f.toUpperCase()):""}const _={"&":"&","<":"<",">":">",'"':""","'":"'"};function ae(i){const u=i==null?"":String(i);return/[&<>"']/.test(u)?u.replace(/[&<>"']/g,f=>_[f]):u}function Te(i){return String(i).replace(/\w\S*/g,u=>u[0].toUpperCase()+u.slice(1).toLowerCase())}function Ze(i,u,f){if(i!==void 0)return i===!0?{enabled:!0,...f}:i===!1?{enabled:!1}:U(i)?i:{[u]:i,enabled:!0}}function d(i){return i==null?[]:Array.isArray(i)?i:[i]}const g=Object.freeze(new Set(["__proto__","constructor","prototype"]));function S(i,u){if(!U(i))return U(u)?{...u}:u;if(!U(u))return u===void 0?i:u;const f={...i};for(const j of Object.keys(u)){if(g.has(j))continue;const Z=u[j];Z!==void 0&&(f[j]=U(Z)&&U(f[j])?S(f[j],Z):Z)}return f}function P(i,u){if(!U(i)||!U(u)||i===u)return u;const f=Object.create(Object.getPrototypeOf(i));return Object.assign(f,i,u),f}class ne{#e;#t=new Map;#n;constructor(u=256,f=null){this.#e=u,this.#n=f}get size(){return this.#t.size}get max(){return this.#e}set max(u){this.#e=u,this.#r()}has(u){return this.#t.has(u)}get(u){const f=this.#t;if(!f.has(u))return;const j=f.get(u);return f.delete(u),f.set(u,j),j}peek(u){return this.#t.get(u)}set(u,f){const j=this.#t;return j.has(u)&&j.delete(u),j.set(u,f),this.#r(),f}delete(u){const f=this.#t.get(u);return this.#t.delete(u)&&this.#n&&this.#n(f,u),f}clear(){if(this.#n)for(const[u,f]of this.#t)this.#n(f,u);this.#t.clear()}keys(){return this.#t.keys()}values(){return this.#t.values()}#r(){const u=this.#t;for(;u.size>this.#e;){const f=u.keys().next().value,j=u.get(f);u.delete(f),this.#n&&this.#n(j,f)}}}const W=new Map;function de(i,u){const f=`${i||""}|${u?JSON.stringify(u):""}`;let j=W.get(f);return j||(j=new Intl.Collator(i||void 0,{numeric:!0,sensitivity:"variant",...u}),W.set(f,j)),j}function Me(i,u){if(i===u)return 0;if(i==null)return 1;if(u==null)return-1;if(typeof i=="number"&&typeof u=="number")return Number.isNaN(i)?Number.isNaN(u)?0:1:Number.isNaN(u)||i<u?-1:i>u?1:0;const f=String(i),j=String(u);return f<j?-1:f>j?1:0}function $e(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const a=typeof requestAnimationFrame=="function";function l(i){return a?requestAnimationFrame(i):setTimeout(()=>i($e()),16)}function w(i){i!=null&&(a?cancelAnimationFrame(i):clearTimeout(i))}function H(i){let u=null,f=null;const j=()=>{u=null;const me=f;f=null,i(...me||[])},Z=(...me)=>{f=me,u===null&&(u=l(j))};return Z.cancel=()=>{w(u),u=null,f=null},Z.flush=()=>{u!==null&&(w(u),j())},Z}function y(i,u){let f=null,j=null;const Z=()=>{if(f=null,j===null)return;const Pe=j;j=null,i(...Pe),me()},me=()=>{f=setTimeout(Z,u),typeof f?.unref=="function"&&f.unref()},J=(...Pe)=>{f===null?(i(...Pe),me()):(j=Pe,clearTimeout(f),me())};return J.flush=()=>{if(f!==null&&clearTimeout(f),f=null,j===null)return;const Pe=j;j=null,i(...Pe)},J.cancel=()=>{f!==null&&clearTimeout(f),f=null,j=null},J.pending=()=>f!==null||j!==null,J}function F(i,u=50){return typeof requestIdleCallback=="function"?requestIdleCallback(i,{timeout:u}):setTimeout(()=>i({timeRemaining:()=>0,didTimeout:!0}),1)}let D=0;function M(i="l"){return`${i}${(++D).toString(36)}`}}),st("packages/core/src/source/filterwire.js",function(p,Oe){"use strict";Object.defineProperty(p,"HOST_FILTER_WARN_ID",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(p,"WHERE_PAGE_RELATIVE_WARN_ID",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(p,"warnWherePageRelative",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(p,"warnHostFilterNotApplied",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(p,"WHERE_NOT_APPLIED_WARN_ID",{enumerable:!0,get:function(){return N}}),Object.defineProperty(p,"warnWhereNotApplied",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(p,"WHERE_OVER_THRESHOLD_WARN_ID",{enumerable:!0,get:function(){return be}}),Object.defineProperty(p,"warnWhereOverThreshold",{enumerable:!0,get:function(){return T}}),Object.defineProperty(p,"RELATIVE_TOKENS",{enumerable:!0,get:function(){return he}}),Object.defineProperty(p,"parseRelativeToken",{enumerable:!0,get:function(){return U}}),Object.defineProperty(p,"resolveRelativeRange",{enumerable:!0,get:function(){return se}}),Object.defineProperty(p,"relativeTokenOf",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(p,"relativeTokenHelp",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(p,"isResolvableRelative",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(p,"resolveRelativeCondition",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(p,"isGroup",{enumerable:!0,get:function(){return De}}),Object.defineProperty(p,"forEachCondition",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(p,"mapConditions",{enumerable:!0,get:function(){return c}}),Object.defineProperty(p,"normaliseFilterSet",{enumerable:!0,get:function(){return O}}),Object.defineProperty(p,"buildFilterSet",{enumerable:!0,get:function(){return A}}),Object.defineProperty(p,"wireFilters",{enumerable:!0,get:function(){return _}}),Object.defineProperty(p,"querySignature",{enumerable:!0,get:function(){return ae}});const V=Oe("packages/core/src/internal/util.js").warnOnce,oe="source.remote.hostFilter",ve="source.where.pageRelative";function ee(d,g){!Array.isArray(d)||!d.length||V(ve,`filters.where (${d.join(", ")}) runs over the rows the ${g} 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 ke(d){const g=(d||{}).config;!g||!g.hostFilter||V(oe,"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 N="source.where.notApplied";function ye(d,g){V(`${N}:${d}`,`filters.where("${d}") is registered but the ${g} 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 be="source.where.overThreshold";function T(d,g,S,P){!Array.isArray(d)||!d.length||V(`${be}:${g}`,`filters.where (${d.join(", ")}) is not applied to the ${g} pushdown source:`,S===null?"the adapter reports no row total, so the size of the matching set is unknown.":`its matching set is ${S.toLocaleString()} rows, at or past the whereRowLimit of ${P.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 L=new Map;function B(d){let g=L.get(d);return g||(g=new Intl.DateTimeFormat("en-US",{timeZone:d,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),L.set(d,g)),g}function Q(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function K(d,g){const S=B(g).formatToParts(new Date(d)),P={y:1970,m:1,d:1,h:0,mi:0,s:0};for(const ne of S)ne.type==="year"?P.y=+ne.value:ne.type==="month"?P.m=+ne.value:ne.type==="day"?P.d=+ne.value:ne.type==="hour"?P.h=+ne.value%24:ne.type==="minute"?P.mi=+ne.value:ne.type==="second"&&(P.s=+ne.value);return P}function ce(d,g){const S=K(d,g);return Date.UTC(S.y,S.m-1,S.d,S.h,S.mi,S.s)-Math.floor(d/1e3)*1e3}function E(d,g,S,P){const ne=Date.UTC(d,g-1,S),W=ne-ce(ne,P);return ne-ce(W,P)}function ie(d,g,S){const P=new Date(Date.UTC(d.y,d.m-1,d.d+g));return E(P.getUTCFullYear(),P.getUTCMonth()+1,P.getUTCDate(),S)}const he=Object.freeze(["today","yesterday","lastNDays","thisWeek","thisMonth","thisQuarter","thisYear","quarterToDate","yearToDate"]);function U(d,g){if(typeof d!="string")return null;const S=d.trim().toLowerCase().replace(/[\s_-]+/g,""),P=/^last(\d*|n)days?$/.exec(S);if(P){const ne=P[1]==="n"?"":P[1],W=Number(ne||g);return!Number.isFinite(W)||W<=0?null:{kind:"lastNDays",n:Math.floor(W)}}switch(S){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 se(d,g={}){const S=U(d,g.n);if(!S)return null;const P=g.tz||Q(),ne=g.now instanceof Date?g.now.getTime():typeof g.now=="number"?g.now:Date.now(),W=K(ne,P),de=E(W.y,W.m,W.d,P),Me=ie(W,1,P);let $e=de,a=Me;switch(S.kind){case"today":break;case"yesterday":$e=ie(W,-1,P),a=de;break;case"lastNDays":a=g.includeToday?Me:de,$e=ie(W,g.includeToday?-(S.n-1):-S.n,P);break;case"thisWeek":{const l=Number.isFinite(g.weekStartsOn)?Number(g.weekStartsOn):1,H=(new Date(Date.UTC(W.y,W.m-1,W.d)).getUTCDay()-l+7)%7;$e=ie(W,-H,P),a=ie(W,-H+7,P);break}case"thisMonth":$e=E(W.y,W.m,1,P),a=E(W.m===12?W.y+1:W.y,W.m===12?1:W.m+1,1,P);break;case"thisQuarter":case"quarterToDate":{const l=Math.floor((W.m-1)/3)*3+1;$e=E(W.y,l,1,P),a=S.kind==="quarterToDate"?Me:l===10?E(W.y+1,1,1,P):E(W.y,l+3,1,P);break}case"thisYear":case"yearToDate":$e=E(W.y,1,1,P),a=S.kind==="yearToDate"?Me:E(W.y+1,1,1,P);break;default:return null}return{from:new Date($e).toISOString(),to:new Date(a).toISOString(),bounds:"[)",tz:P,relative:S.kind==="lastNDays"?`last${S.n}Days`:S.kind,n:S.n}}function fe(d){if(!d||typeof d!="object")return null;const g=d.value;if(g&&typeof g=="object"&&!Array.isArray(g)&&"relative"in g)return{token:String(g.relative),n:typeof g.n=="number"?g.n:void 0};if(d.op==="relative"&&typeof d.value=="string")return{token:d.value,n:void 0};const S=d.meta;return S&&typeof S.relative=="string"&&d.value===void 0?{token:S.relative,n:typeof S.n=="number"?S.n:void 0}:null}function ge(){return`Known tokens: ${he.filter(g=>g!=="lastNDays").join(", ")}. "lastNDays" needs a count: pass "last7Days", or the value object { relative: 'lastNDays', n: 7 }.`}function Se(d){const g=fe(d);return g?U(g.token,g.n)!==null:!1}function Ee(d,g={}){const S=fe(d);if(!S)return d;const P=se(S.token,{...g,n:S.n});return P?{...d,type:d.type||"date",op:"between",value:[P.from,P.to],bounds:d.bounds||P.bounds,meta:{...d.meta||{},relative:P.relative,tz:P.tz}}:(V(`source.relative.${S.token}`,`unknown relative date token "${S.token}"; sending the condition unresolved.`,ge()),d)}function De(d){return!!d&&typeof d=="object"&&Array.isArray(d.conditions)}function tt(d,g){if(d){if(De(d)){for(const S of d.conditions)tt(S,g);return}g(d)}}function c(d,g){if(!d)return null;if(!De(d))return g(d);const S=d;let P=!1;const ne=[];for(const W of S.conditions){const de=c(W,g);de!==W&&(P=!0),de&&ne.push(de)}return!P&&ne.length===S.conditions.length?d:ne.length?{...S,conditions:ne}:null}function q(d){if(!d)return null;if(!De(d))return d;const g=d,S=[];for(const P of g.conditions){const ne=q(P);ne&&S.push(ne)}return S.length?{op:g.op,conditions:S}:null}function O(d){const g=q(d);return g?De(g)&&g.op==="and"?g:{op:"and",conditions:[g]}:null}function A(d){const g=(d||[]).filter(Boolean);return g.length?{op:"and",conditions:g}:null}function _(d,g={}){const S=c(d,P=>Ee(P,g));return O(S)}function ae(d){const g=Te(d.filters??null);return JSON.stringify([g,d.sort??null,d.quick??"",d.groupBy??null,d.pivotBy??null,Ze(d.context)])}function Te(d){if(!d)return null;if(De(d)){const P=d;return{op:P.op,conditions:P.conditions.map(Te)}}const g=d,S=g.meta&&typeof g.meta.relative=="string"?g.meta.relative:fe(g)?.token;return{col:g.col,op:g.op,bounds:g.bounds??null,caseSensitive:g.caseSensitive??!1,value:S?`rel:${S}`:g.value??null}}function Ze(d){if(d==null)return null;try{return JSON.parse(JSON.stringify(d))}catch{return V("source.context.unserialisable","config.context is not JSON-serialisable; cache keys ignore it."),"[unserialisable]"}}}),st("packages/core/src/source/aggregates.js",function(p,Oe){"use strict";Object.defineProperty(p,"STAT_PUSHDOWN",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(p,"pushableAggregates",{enumerable:!0,get:function(){return V}}),Object.defineProperty(p,"fillAggregateSql",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(p,"resolveAggregatesConfig",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(p,"routeAggregate",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(p,"resolveAggregatePlan",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(p,"groupKeysPushable",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(p,"pushdownDocRows",{enumerable:!0,get:function(){return be}});const pe=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 V(){const T=new Set;for(const[L,B]of Object.entries(pe))B.pushable&&T.add(L);return T}function oe(T,L,B){let Q=T.split("%c").join(L);return B!==void 0&&(Q=Q.split("%w").join(B)),Q}function ve(T){const L=T||{},B=L.default==="engine"||L.default==="engine-if-identical"?L.default:"client",Q={};if(L.overrides&&typeof L.overrides=="object")for(const[K,ce]of Object.entries(L.overrides))(ce==="engine"||ce==="client")&&(Q[K]=ce);return{default:B,overrides:Q}}function ee(T,L){const B=pe[T];if(!B||!B.pushable)return"client";const Q=L.overrides[T];return Q==="engine"||Q==="client"?Q:L.default==="client"?"client":L.default==="engine-if-identical"?B.class==="identical"?"engine":"client":"engine"}function ke(T,L){const B=ve(L),Q=[],K=[];for(const ce of T||[]){const E=pe[ce.fn],ie=ee(ce.fn,B),he={id:ce.id,col:ce.col,fn:ce.fn,class:E?E.class:"fallback"};ce.weight!==void 0&&(he.weight=ce.weight),ce.params!==void 0&&(he.params=ce.params),ie==="engine"?Q.push(he):(he.reason=E&&!E.pushable?E.note||"the engine cannot express this stat":"client by config",K.push(he))}return{engine:Q,client:K,config:B}}const N=/^[A-Za-z_][A-Za-z0-9_$]*$/;function ye(T,L=[]){return(T||[]).every(Q=>{if(typeof Q=="string")return N.test(Q);if(!Q||typeof Q!="object")return!1;const K=Q;return Array.isArray(L)&&L.includes(K.bucket)&&typeof K.col=="string"&&N.test(K.col)&&typeof K.size=="number"&&Number.isFinite(K.size)&&K.size>0})}function be(){return Object.entries(pe).map(([T,L])=>({stat:T,class:L.class,sql:L.sql?oe(L.sql,"col",L.twoColumn?"weight":void 0):"",note:L.note||(L.class==="identical"?"Pushes to DuckDB with the same result.":"")}))}}),st("packages/core/src/source/abort.js",function(p,Oe){"use strict";Object.defineProperty(p,"SupersededError",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(p,"RequestToken",{enumerable:!0,get:function(){return V}}),Object.defineProperty(p,"AbortScope",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(p,"createAbortScope",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(p,"isAbortError",{enumerable:!0,get:function(){return ee}});class pe extends Error{constructor(N,ye="superseded"){super(`[lattice] request ${N?`"${N}" `:""}${ye}`),this.name="SupersededError",this.superseded=!0,this.key=N}}class V{#e;constructor(N,ye,be,T){this.#e=N,this.key=ye,this.controller=be,this.signal=be.signal,this.seq=T}get current(){return!this.signal.aborted&&this.#e.tokenFor(this.key)===this}settle(){this.#e.settle(this)}abort(N){this.signal.aborted||this.controller.abort(new pe(this.key,N)),this.#e.settle(this)}}class oe{#e=new Map;#t=0;begin(N="",ye="superseded"){const be=this.#e.get(N);be&&!be.signal.aborted&&be.controller.abort(new pe(N,ye));const T=new V(this,N,new AbortController,++this.#t);return this.#e.set(N,T),T}tokenFor(N){return this.#e.get(N)}pending(N=""){const ye=this.#e.get(N);return!!ye&&!ye.signal.aborted}get size(){return this.#e.size}settle(N){this.#e.get(N.key)===N&&this.#e.delete(N.key)}abort(N="",ye="superseded"){const be=this.#e.get(N);be&&be.abort(ye)}abortAll(N="superseded"){for(const ye of[...this.#e.values()])ye.abort(N);this.#e.clear()}}function ve(){return new oe}function ee(ke){if(!ke||typeof ke!="object")return!1;const N=ke;return N.superseded===!0||N.name==="AbortError"||N.name==="SupersededError"}}),st("packages/core/src/source/pushdown.js",function(p,Oe){"use strict";Object.defineProperty(p,"NO_CAPABILITIES",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(p,"resolveMutate",{enumerable:!0,get:function(){return he}}),Object.defineProperty(p,"capabilitiesOf",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(p,"splitFilters",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(p,"LEAF_COUNT_ID",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(p,"PIVOT_UNSUPPORTED",{enumerable:!0,get:function(){return q}}),Object.defineProperty(p,"GROUP_UNSUPPORTED",{enumerable:!0,get:function(){return O}}),Object.defineProperty(p,"UNGROUPED_LEVEL",{enumerable:!0,get:function(){return A}}),Object.defineProperty(p,"planQuery",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(p,"applyResidual",{enumerable:!0,get:function(){return d}}),Object.defineProperty(p,"DEFAULT_WHERE_ROW_LIMIT",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(p,"createPushdownSource",{enumerable:!0,get:function(){return $e}});const pe=Oe("packages/core/src/internal/util.js"),V=pe.defaultCompare,oe=pe.isFunction,ve=pe.toArray,ee=pe.warnOnce,ke=Oe("packages/core/src/source/filterwire.js"),N=ke.isGroup,ye=ke.warnWherePageRelative,be=ke.warnWhereOverThreshold,T=Oe("packages/core/src/source/aggregates.js"),L=T.resolveAggregatePlan,B=T.groupKeysPushable,Q=T.STAT_PUSHDOWN,ce=Oe("packages/core/src/source/abort.js").SupersededError;function E(a){const l=a&&a.signal;if(!l||!l.aborted)return;const w=l.reason;throw w instanceof Error?w:new ce("","superseded before it was sent")}const ie=Object.freeze({filter:!1,operators:Object.freeze([]),sort:!1,quick:!1,range:!1,total:!1,group:!1,pivot:!1,mutate:!1});function he(a){if(!a||typeof a!="object")return!1;const l=a.returning==="row"||a.returning==="key"?a.returning:"none";return{append:a.append===!0,update:a.update===!0,delete:a.delete===!0,returning:l}}function U(a,l){if(!a||typeof l!="string")return;if(!l.includes("."))return a[l];let w=a;for(const H of l.split(".")){if(w===null||typeof w!="object")return;w=w[H]}return w}function se(a){if(a===!0)return!0;if(!a||typeof a!="object")return!1;const l=a;return l.enabled===!1?!1:l.enabled===!0||oe(l.commit)}function fe(a){const l={...ie,...a||{}};return l.operators=new Set(l.operators||[]),l.mutate=he(l.mutate),l}function ge(a,l){return!a||!a.op||!l.operators.size?!1:l.operators.has(a.op)}function Se(a,l){if(!a)return{pushed:null,residual:null};if(!l.filter)return{pushed:null,residual:a};if(l.filter==="term"){if(N(a)){const F=a.conditions||[];if(String(a.op)!=="and")return{pushed:null,residual:a};const D=F.findIndex(i=>!N(i)&&ge(i,l));if(D<0)return{pushed:null,residual:a};const M=F.filter((i,u)=>u!==D);return{pushed:F[D],residual:M.length?{op:"and",conditions:M}:null}}return ge(a,l)?{pushed:a,residual:null}:{pushed:null,residual:a}}if(!N(a))return ge(a,l)?{pushed:a,residual:null}:{pushed:null,residual:a};if(String(a.op)!=="and")return(a.conditions||[]).every(D=>N(D)?Se(D,l).residual===null:ge(D,l))?{pushed:a,residual:null}:{pushed:null,residual:a};const w=[],H=[];for(const F of a.conditions||[]){if(N(F)){if(l.filter==="flat"){H.push(F);continue}const D=Se(F,l);D.pushed&&w.push(D.pushed),D.residual&&H.push(D.residual);continue}(ge(F,l)?w:H).push(F)}const y=F=>F.length===0?null:F.length===1?F[0]:{op:"and",conditions:F};return{pushed:y(w),residual:y(H)}}const Ee="__lattice_leaves";function De(a){return a.aggregates?a.aggregates instanceof Set?a.aggregates:new Set(ve(a.aggregates)):new Set}function tt(a){const l=De(a);return l.size?l.has("count")?a.filter!=="tree"||!a.operators||!a.operators.has("eq")?"the adapter does not declare the `group` capability, and cannot narrow a group's rows by its key (that needs a `tree` filter with the `eq` operator)":"":"the adapter does not declare the `group` capability, and its declared aggregates have no `count` to give each group its row count":"the adapter does not declare the `group` capability"}function c(a,l,w,H,y,F,D){const M=Array.isArray(a.groupBy)?a.groupBy:[],i=Array.isArray(a.groupPath)?a.groupPath:[],u=Array.isArray(a.groupValues)?a.groupValues:null;if(!l.group){const f=tt(l);if(f)return f}return B(M)?w.residual?"the filter did not fully push, so the engine would group a superset of the matching rows":H?y?F?"a host `where` predicate can only run in the browser, over rows the engine grouped":D?"fullDataset holds the whole matching set, so the grid groups it itself":!u||u.length!==i.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"}const q="pushdown:pivot-unsupported",O="pushdown:group-unsupported",A=Symbol("lattice.remote.ungroupedLevel");function _(a,l,w,H,y,F){const D=Array.isArray(a.pivotBy)?a.pivotBy:[],M=Array.isArray(a.groupBy)?a.groupBy:[],i=Array.isArray(a.groupPath)?a.groupPath:[],u=Array.isArray(a.groupValues)?a.groupValues:null;return l.pivot?B(D)?M.length&&!B(M)?"a grouping key is not a plain column the engine can name in a GROUP BY":w.residual?"the filter did not fully push, so the engine would pivot a superset of the matching rows":H?y?F?"a host `where` predicate can only run in the browser, over rows the engine pivoted":!u||u.length!==i.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 pivot unsearched rows":"the sort did not push, so the engine would order the rows differently":"a pivot column is not a plain column the engine can name in a GROUP BY":"the adapter does not declare the `pivot` capability"}function ae(a,l,w=!1){const H=Se(a.filters||null,l),y=[];H.residual&&y.push("filter");const F=a.sort||[],D=F.length===0||l.sort==="multi"&&F.length>=1||l.sort==="single"&&F.length===1;!D&&F.length&&y.push("sort");const M=a.quick?String(a.quick):"",i=!M||!!l.quick;i||y.push("quick");const u=a.where&&a.where.active?a.where:null;u&&y.push("where");const f={filters:H.residual,sort:D?null:F,quick:i?"":M,where:u},j=!!w,Z=Array.isArray(a.groupBy)&&a.groupBy.length>0,me=Z?c(a,l,H,D,i,u,j):"",J=a.pivotMode!==!1&&Array.isArray(a.pivotBy)&&a.pivotBy.length>0,Pe=J?_(a,l,H,D,i,u):"",Ie=J&&Pe==="";J&&!Ie&&y.push("pivot");const Ge=J?Ie&&Z:Z&&me==="";Z&&!J&&!Ge&&y.push("group");const Fe=(Ge||Ie)&&Array.isArray(a.groupValues)?a.groupValues.length:0,_e=Ge||J?!1:j||!!(f.filters||f.sort||f.quick||f.where)||!l.range;return{pushed:{...a,filters:H.pushed,sort:D?F:[],quick:i?M:"",range:_e?null:a.range},residual:f,needsAll:_e,unpushed:y,full:j,grouped:Ge,groupLevel:Fe,groupReason:J?"":me,pivoted:Ie,pivotReason:Pe}}function Te(a){const l=Array.isArray(a.totals)?a.totals:[],w=a.totalFns&&typeof a.totalFns=="object"?a.totalFns:{},H=[],y=[];for(const F of l){const D=String(F),M=typeof w[D]=="string"?w[D]:null,i=M?Q[M]:null;M?!i||!i.pushable||!i.sql?y.push({id:D,fn:M,class:i?i.class:"fallback",reason:i&&i.note?i.note:`the pushdown map cannot express "${M}"`}):i.twoColumn?y.push({id:D,fn:M,class:i.class,reason:`"${M}" reduces two columns, and a grouped request carries no weight column`}):H.push({id:D,col:D,fn:M,class:i.class}):y.push({id:D,fn:null,class:"fallback",reason:"the column totals with a host function, so there is no named statistic to push"})}return{engine:H,client:y}}const Ze=Object.freeze({items:a=>a==null?[]:Array.isArray(a)?a:[a]});function d(a,l,w){if(!l)return a;let H=a;if(l.filters&&oe(w.evaluateFilters)){const y=H,F={count:H.length,handle:i=>({id:i,get:u=>U(y[u],i)}),itemwise:i=>y.some(u=>Array.isArray(U(u,i)))?Ze:null},D=w.evaluateFilters(l.filters,F),M=[];for(let i=0;i<H.length;i++)D[i]&&M.push(H[i]);H=M}if(l.where&&l.where.active&&(l.whole||ye(l.where.names,"pushdown"),H=H.filter(y=>l.where.passes(y))),l.quick){const y=l.quick.toLowerCase();H=H.filter(F=>{if(!F||typeof F!="object")return!1;for(const D of Object.values(F))if(D!=null&&String(D).toLowerCase().includes(y))return!0;return!1})}if(l.sort&&l.sort.length&&oe(w.sortMulti)){const y=[...new Set(l.sort.map(i=>i.col))],F=H,D=y.map(i=>({id:i,get:u=>U(F[u],i)})),M=w.sortMulti(D,l.sort.map(i=>({col:i.col,dir:i.dir})),Uint32Array.from({length:H.length},(i,u)=>u),{});H=Array.from(M,i=>F[i])}return H}function g(a){return JSON.stringify({filters:a.filters||null,sort:a.sort||[],quick:a.quick||"",groupBy:a.groupBy||[],groupPath:a.groupPath||[],context:a.context??null})}function S(a){if(!a||typeof a!="object")return 16;let l="";try{l=JSON.stringify(a)}catch{return 200}return l.length*2+64}function P(a){const l=a||{};return{enabled:!!l.enabled,maxRows:Number.isFinite(l.maxRows)?l.maxRows:1e6,maxBytesEstimate:Number.isFinite(l.maxBytesEstimate)?l.maxBytesEstimate:512*1024*1024}}const ne=5e4;function W(a){return Number.isFinite(a)&&a>=0?a:ne}function de(a){return!!a&&oe(a.then)}async function Me(a){if(!a||a.total!==void 0||!de(a.pendingTotal))return a;const l=await a.pendingTotal,{pendingTotal:w,...H}=a;return typeof l=="number"?{...H,total:l}:H}function $e(a={}){const l=a.adapter;if(!l||!oe(l.execute))return ee("source.pushdown.adapter","createPushdownSource needs an `adapter` with an `execute(query)` function."),{...a,mode:"remote",fetch:async()=>({rows:[],total:0})};const w=fe(l.capabilities),H=l.capabilities&&Object.getOwnPropertyDescriptor(l.capabilities,"operators");H&&oe(H.get)&&Object.defineProperty(w,"operators",{enumerable:!0,configurable:!0,get:()=>new Set(l.capabilities.operators||[]),set:()=>{}});const y=l.name||"adapter";let F=null;const D=()=>oe(l.ready)?(F||(F=Promise.resolve(l.ready()).then(()=>{Object.assign(w,fe(l.capabilities))},k=>{throw F=null,k})),F):null,M=P(a.fullDataset),i=!!a.allowPartialResults,u=W(a.whereRowLimit);let f=null;const j=a.aggregates;let Z=null,me=null,J=null,Pe=null,Ie=null,Ge,Fe=null,_e=0,Je=null;const nt=()=>!M.enabled||!Z?null:(Je!==Z.key&&(_e++,Je=Z.key),{rows:Z.rows,version:_e}),ft=async k=>{const R=k.where&&k.where.active?k.where:null;if(!R)return{request:k,probe:null};const{where:$,...C}=k,m=ae(C,w,M.enabled);if(m.needsAll)return{request:k,probe:null};const z=g(m.pushed);let ue=null;return(!f||f.key!==z)&&(w.total?(E(k),ue=await Me(await l.execute(m.pushed,k)),f={key:z,size:ue&&typeof ue.total=="number"?ue.total:null}):f={key:z,size:null}),f.size!==null&&f.size<u?{request:k,probe:null}:(be(R.names,y,f.size,u),{request:C,probe:ue})},At=async(k,R)=>{Fe=null;const $=Te(k.pushed);J={engine:$.engine,client:$.client,groupBy:k.pushed.groupBy},$.client.length&&ee(`source.pushdown.group.totals.${y}.${$.client.map(z=>z.id).join(".")}`,`the ${y} adapter cannot compute the group subtotal for ${$.client.map(z=>`"${z.id}" (${z.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 C=await l.executeGroupLevel(k.pushed,$.engine,R)||{};let m=C.rows||[];return!w.range&&R.range&&(m=m.slice(R.range.start,R.range.end)),Ce(C),C.total===void 0?{rows:m}:{rows:m,total:C.total}},Le=new Map,Qe=64,Ve=async(k,R)=>{Fe=null;const $=k.pushed,C=$.groupBy,m=Array.isArray($.groupValues)?$.groupValues:[],z=m.length,ue=[...$.filters?[$.filters]:[],...C.slice(0,z).map((x,qe)=>({col:x,op:"eq",value:m[qe]===void 0?null:m[qe],caseSensitive:!0}))],je=ue.length===0?null:ue.length===1?ue[0]:{op:"and",conditions:ue},we=R.range?R.range.start:0;if(z>=C.length){const x={...$,filters:je,groupBy:[],groupPath:[],groupValues:[],totals:[],totalFns:{}},qe=await Me(await l.execute(x,R))||{};let ze=qe.rows||[];return!w.range&&R.range&&(ze=ze.slice(R.range.start,R.range.end)),typeof qe.total=="number"?{rows:ze,total:qe.total}:{rows:ze}}const te=C[z],Ae=Te($),Ke=De(w),Re=Ae.engine.filter(x=>Ke.has(x.fn)),Be=[...Ae.engine.filter(x=>!Ke.has(x.fn)).map(x=>({id:x.id,fn:x.fn,class:x.class,reason:`the ${y} adapter does not compute "${x.fn}"`})),...Ae.client];J={engine:Re,client:Be,groupBy:C},Be.length&&ee(`source.pushdown.group.totals.${y}.${Be.map(x=>x.id).join(".")}`,`the ${y} adapter cannot compute the group subtotal for ${Be.map(x=>`"${x.id}" (${x.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 re=[...Re.map(x=>({id:x.id,col:x.col,fn:x.fn})),{id:Ee,col:te,fn:"count"}],le={...$,filters:je,range:null},G=JSON.stringify([g(le),m,te,re]);let We=we>0?Le.get(G):void 0;if(!We){for(We=Promise.resolve(l.executeGroupedAggregates(le,[te],re)),Le.delete(G),Le.set(G,We);Le.size>Qe;)Le.delete(Le.keys().next().value);We.catch(()=>{Le.get(G)===We&&Le.delete(G)})}const lt=await We||[];E(R);const Et=x=>{const qe={};for(const ze of Re)qe[ze.id]=x?x[ze.id]:void 0;return qe},kt=($.sort||[]).find(x=>x&&x.col===te),Nt=kt&&kt.dir==="desc"?-1:1,Ue=lt.filter(x=>x&&x.level===1).map(x=>({[te]:x.keys[0]===void 0?null:x.keys[0],leafCount:Number(x.values&&x.values[Ee])||0,totals:Et(x.values)})).sort((x,qe)=>Nt*V(x[te],qe[te]));if(z===0){const x=lt.find(ze=>ze&&ze.level===0),qe=x?Number(x.values&&x.values[Ee]):NaN;Ce({matchCount:Number.isFinite(qe)?qe:Ue.reduce((ze,gt)=>ze+gt.leafCount,0),...x?{grand:Et(x.values)}:{}})}const dt=R.range?R.range.end:Ue.length;return{rows:Ue.slice(we,dt),total:Ue.length}},Ce=k=>{typeof k.matchCount=="number"&&(Pe=k.matchCount,Ie=k.grand?{totals:k.grand,leafCount:k.matchCount}:null,Ge===void 0&&oe(l.unfilteredCount)&&(Ge=null,Promise.resolve(l.unfilteredCount()).then(R=>{Ge=typeof R=="number"?R:null}).catch(R=>{ee(`source.pushdown.group.unfiltered.${y}`,`the ${y} adapter could not count the unfiltered set (${R&&R.message?R.message:R}), so "N of M" falls back to the display count for its denominator.`)})))},rt=async(k,R)=>{Fe=null;const $=Te(k.pushed);J={engine:$.engine,client:$.client,groupBy:k.pushed.groupBy,pivotBy:k.pushed.pivotBy},$.client.length&&ee(`source.pushdown.pivot.totals.${y}.${$.client.map(je=>je.id).join(".")}`,`the ${y} adapter cannot compute the pivot cells for ${$.client.map(je=>`"${je.id}" (${je.reason})`).join(", ")}, so those cells are empty. A figure computed over anything other than the cell would be wrong, so none is shown; \`lastPlan().aggregates.client\` names them.`);const C=await l.executePivotLevel(k.pushed,$.engine,R)||{};let m=C.rows||[];!w.range&&R.range&&(m=m.slice(R.range.start,R.range.end)),Ce(C);const z=C.pivot&&typeof C.pivot=="object"?C.pivot:{},ue={cells:Array.isArray(z.cells)?z.cells:[],...Array.isArray(z.axis)?{axis:z.axis}:{}};return C.total===void 0?{rows:m,pivot:ue}:{rows:m,total:C.total,pivot:ue}},at=k=>{ee(`source.pushdown.pivot.${y}.${k}`,`pushdown:pivot-unsupported: the ${y} adapter cannot pivot this query because ${k}, so no rows are fetched rather than every leaf row being pulled into the browser to pivot there. \`lastPlan().pivotReason\` says the same.`);const R=new Error(`[lattice] ${q}: the ${y} adapter cannot pivot this query because ${k}, so no rows are fetched rather than every leaf row being pulled into the browser to pivot there. \`lastPlan().pivotReason\` says the same.`);throw R.code=q,R.reason=k,R},Xe=(k,R)=>{const $={key:R,state:"pending",value:null};return Fe=$,k.then(C=>(Fe===$&&(Fe={key:R,state:"settled",value:typeof C=="number"?C:null}),C),C=>{throw Fe===$&&(Fe={key:R,state:"failed",value:null}),C})},et=async k=>{const R=D();R&&await R;const C=k&&k.pivotMode!==!1&&Array.isArray(k.pivotBy)&&k.pivotBy.length>0?{request:k,probe:null}:await ft(k);E(k);let m=ae(C.request,w,M.enabled);if(w.group&&m.grouped&&!m.pivoted&&!oe(l.executeGroupLevel)&&(ee(`source.pushdown.group.method.${y}`,`the ${y} adapter declares the \`group\` capability but has no \`executeGroupLevel(query, aggregates, request)\`, so grouping is not pushed and the grid stays ungrouped unless it holds the whole matching set. Implement the method or drop the capability.`),m=ae(C.request,{...w,group:!1,aggregates:null},M.enabled)),m.pivoted&&!oe(l.executePivotLevel)&&(m=ae(C.request,{...w,pivot:!1},M.enabled),m.pivotReason="the adapter declares the `pivot` capability but has no `executePivotLevel(query, aggregates, request)`"),m.grouped&&!m.pivoted&&!w.group&&!oe(l.executeGroupedAggregates)&&(ee(`source.pushdown.group.aggregates.method.${y}`,`the ${y} adapter declares \`aggregates\` but has no \`executeGroupedAggregates(query, groupBy, aggregates)\`, so the grouped view cannot be built from grouped aggregates and the grid stays ungrouped unless it holds the whole matching set. Implement the method, or declare \`group\` and implement \`executeGroupLevel\`.`),m=ae(C.request,{...w,aggregates:null},M.enabled)),me=m,m.pivoted)return rt(m,k);if(m.pivotReason&&at(m.pivotReason),m.grouped)return w.group?At(m,k):Ve(m,k);const ue=!!m.groupReason&&!m.full;ue?ee(`source.pushdown.group-unsupported.${y}.${m.groupReason}`,`pushdown:group-unsupported: the ${y} adapter was not asked to group this query because ${m.groupReason}, so the grid stays ungrouped rather than building group rows, counts and subtotals from a window of leaf rows. \`lastPlan().groupReason\` says the same.`):m.groupReason&&ee(`source.pushdown.group.${y}.${m.groupReason}`,`the ${y} adapter was not asked to group this query because ${m.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.`);const je=re=>ue?{...re,[A]:!0}:re;if(!m.needsAll){const re=C.probe||await l.execute(m.pushed,k),le=re.rows||[];return de(re.pendingTotal)&&re.total===void 0?je({rows:le,pendingTotal:Xe(re.pendingTotal,g(m.pushed))}):(Fe=null,!w.total&&re.total===void 0?je({rows:le}):je({rows:le,total:re.total??le.length}))}m.unpushed.length&&ee(`source.pushdown.residual.${y}.${m.unpushed.join(".")}`,`the ${y} adapter cannot push ${m.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 we=g(m.pushed);if(!Z||Z.key!==we){const re=await Me(await l.execute(m.pushed,k));Fe=null;const le=re.rows||[];if(m.full){const G=typeof re.total=="number"?Math.max(re.total,le.length):le.length;if(G>M.maxRows)throw new Error(`[lattice] fullDataset refused: the ${y} adapter's matching set is ${G.toLocaleString()} rows, past the configured maxRows of ${M.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=le.length*S(le[0]);if(We>M.maxBytesEstimate)throw new Error(`[lattice] fullDataset refused: the ${y} adapter's matching set is an estimated ${Math.round(We/(1024*1024)).toLocaleString()} MB across ${le.length.toLocaleString()} rows, past the configured maxBytesEstimate of ${Math.round(M.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 re.total=="number"&&le.length<re.total){const G=!!(m.residual.filters||m.residual.quick||m.residual.sort&&m.residual.sort.length);if(G&&!i)throw new Error(`[lattice] the ${y} adapter returned ${le.length} of ${re.total} matching rows when asked for the whole result, and the query has residual ${m.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.`);G?ee(`source.pushdown.partial.residual.${y}`,`the ${y} adapter returned ${le.length} of ${re.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.`):ee(`source.pushdown.partial.${y}`,`the ${y} adapter returned ${le.length} of ${re.total} matching rows when asked for the whole result. The adapter must follow the engine's own paging before returning.`)}Z={key:we,rows:le,total:typeof re.total=="number"?re.total:null}}let te=m;if(m.residual.where){const re=Z.total??Z.rows.length;if(re>=u){be(m.residual.where.names,y,re,u);const{where:le,...G}=C.request;te=ae(G,w,M.enabled),me=te}}const Ae=Z.total!==null&&Z.rows.length>=Z.total,Ke=d(Z.rows,{...te.residual,whole:Ae},a.compute||{}),Re=k.range?k.range.start:0,Be=k.range?k.range.end:Ke.length;return je({rows:Ke.slice(Re,Be),total:Ke.length})},ot=async(k,R)=>{const $=D();$&&await $;const C=ae(k,w,M.enabled);me=C;const m=L(R,j),z=Array.isArray(k.groupBy)?k.groupBy:[],ue=z.length>0,je=!C.residual.filters&&!C.residual.quick,we=!ue||B(z,w.buckets);let te=m.engine,Ae=m.client;if(w.aggregates&&te.length){const re=w.aggregates instanceof Set?w.aggregates:new Set(ve(w.aggregates)),le=te.filter(G=>!re.has(G.fn));le.length&&(te=te.filter(G=>re.has(G.fn)),Ae=[...le.map(G=>({...G,reason:`the ${y} adapter does not compute "${G.fn}"`})),...Ae])}const Ke=re=>{Ae=[...te.map(le=>({...le,reason:re})),...Ae],te=[]};te.length&&!je?Ke(C.residual.quick&&!C.residual.filters?"a quick search the adapter cannot push forces all-client (no mixed provenance)":"residual filter forces all-client (no mixed provenance)"):te.length&&!we&&Ke("a grouping key the engine cannot form forces all-client (no mixed provenance)");let Re={},Be;return te.length&&(oe(ue?l.executeGroupedAggregates:l.executeAggregates)?ue?Be=await l.executeGroupedAggregates(C.pushed,z,te)||[]:Re=await l.executeAggregates(C.pushed,te)||{}:(ee(`source.pushdown.aggregates.${y}${ue?".grouped":""}`,`the ${y} adapter cannot compute ${ue?"grouped ":""}aggregates, so every requested statistic is computed client-side. Correct, and slower than it needs to be.`),Ke(`adapter cannot compute ${ue?"grouped ":""}aggregates`))),J={engine:te,client:Ae,...ue?{groupBy:z}:{}},{values:Re,engine:te,client:Ae,...Be!==void 0?{groups:Be}:{}}},ut=se(a.edit),it=a.edit&&typeof a.edit=="object"&&oe(a.edit.commit);let He=a.edit;if(ut&&!it)if(w.mutate&&w.mutate.update){const k=R=>{if(!w.mutate||!w.mutate.update)throw new Error(`[lattice] the ${y} adapter cannot update rows (mutate.update is not declared), so this edit cannot be persisted. The cell is reverted rather than left looking saved.`);const $={kind:"update",key:String(R.key),patch:{[R.colId]:R.value}};return l.mutate($,R.request||{})};He={...a.edit===!0?{}:a.edit,commit:k}}else ee(`source.pushdown.readonly.${y}`,`edit is enabled but the ${y} adapter declares mutate: ${w.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 wt=ut&&w.mutate&&(w.mutate.append||w.mutate.delete)?{append:w.mutate.append===!0,remove:w.mutate.delete===!0,returning:w.mutate.returning,mutate:(k,R)=>l.mutate(k,R||{})}:null,ht=async k=>{const R=D();R&&await R;const{range:$,signal:C,export:m,...z}=k||{},ue={...z,groupBy:[],groupPath:[],groupValues:[],pivotBy:[],pivotMode:!1,totals:[]};return{plan:ae(ue,w,M.enabled),signal:C}};async function*Ye(k,R={}){const{plan:$,signal:C}=await ht(k),m=Math.max(1,Math.floor(Number(R.pageSize))||5e3),z={signal:C,stream:!0};if(!$.needsAll)for(let we=0;;we+=m){E(z);const te=await l.execute({...$.pushed,range:{start:we,end:we+m}},z);te&&de(te.pendingTotal)&&te.pendingTotal.then(null,()=>{});const Ae=te&&te.rows||[];if(Ae.length&&(yield Ae),Ae.length<m)return}E(z);const ue=await Me(await l.execute({...$.pushed,range:void 0},z)),je=d(ue&&ue.rows||[],{...$.residual,whole:!0},a.compute||{});for(let we=0;we<je.length;we+=m)yield je.slice(we,we+m)}return{...a,edit:He,rowMutate:wt,mode:"remote",fetch:et,aggregate:ot,countMatching:async k=>{const{plan:R,signal:$}=await ht(k);if(!R.needsAll&&w.total){E({signal:$});const m=await Me(await l.execute({...R.pushed,range:{start:0,end:0}},{signal:$}));if(m&&typeof m.total=="number")return m.total}let C=0;for await(const m of Ye(k))C+=m.length;return C},streamMatching:Ye,lastPlan:()=>me?{...me,...J?{aggregates:J}:{},...Fe?{total:{deferred:!0,state:Fe.state,value:Fe.value}}:{}}:null,fullFrame:nt,counts:()=>({match:Pe,total:Ge??null,pending:!!Fe&&Fe.state==="pending"}),grandTotals:()=>Ie}}}),st("packages/core/src/model/rowkey.js",function(p,Oe){"use strict";Object.defineProperty(p,"KEY_DEPENDENT_FEATURES",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(p,"compositeKey",{enumerable:!0,get:function(){return be}}),Object.defineProperty(p,"createRowKey",{enumerable:!0,get:function(){return T}}),Object.defineProperty(p,"warnMissingKeys",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(p,"groupPathKey",{enumerable:!0,get:function(){return K}}),Object.defineProperty(p,"splitPathKey",{enumerable:!0,get:function(){return ce}});const pe=Oe("packages/core/src/internal/util.js"),V=pe.warnOnce,oe=pe.pathGetter,ve=pe.isFunction,ee=pe.isBlank,ke=["changes (rows.apply / rows.queue)","streaming dedupe","selection persistence","remote reload","cell comments"],N="";function ye(E){if(E===null)return"\0n";if(E===void 0)return"\0u";const ie=typeof E;if(ie==="string")return E;if(ie==="number"||ie==="bigint"||ie==="boolean")return String(E);if(E instanceof Date)return`\0d${E.getTime()}`;try{return`\0o${JSON.stringify(E)}`}catch{return"\0o?"}}function be(E){if(E.length===1)return ye(E[0]);let ie="";for(let he=0;he<E.length;he++)he&&(ie+=N),ie+=ye(E[he]);return ie}function T(E,ie={}){const he=ie.warn!==!1;if(ve(E)){const U=E;return{stable:!0,fields:[],disabled:[],key(se,fe){try{const ge=U(se);return Array.isArray(ge)?be(ge):ye(ge)}catch(ge){return V("rowKey.throw","rowKey function threw; falling back to index identity for the affected rows.",ge),`#${fe??-1}`}},keyEmpty(se){try{const fe=U(se);return Array.isArray(fe)?fe.length===0||fe.some(ee):ee(fe)}catch{return!1}},missingFields(){return[]}}}if(Array.isArray(E)&&E.length>0){const U=E.filter(ge=>typeof ge=="string"),se=U.map(ge=>oe(ge)),fe=se.length;return{stable:!0,fields:U,disabled:[],key(ge){const Se=new Array(fe);for(let Ee=0;Ee<fe;Ee++)Se[Ee]=se[Ee](ge);return be(Se)},keyEmpty(ge){for(let Se=0;Se<fe;Se++)if(ee(se[Se](ge)))return!0;return!1},missingFields(ge){const Se=[];for(let Ee=0;Ee<fe;Ee++)ee(se[Ee](ge))&&Se.push(U[Ee]);return Se}}}if(typeof E=="string"&&E.length>0){const U=oe(E);return{stable:!0,fields:[E],disabled:[],key(se){return ye(U(se))},keyEmpty(se){return ee(U(se))},missingFields(se){return ee(U(se))?[E]:[]}}}return he&&V("rowKey.missing",`no rowKey configured, so rows are identified by object identity. This disables: ${ke.join(", ")}. Set rowKey to a field name, an array of field names, or a function.`),{stable:!1,fields:[],disabled:ke.slice(),key(U,se){if(U===null||typeof U!="object")return`#${se??0}:${String(U)}`;let fe=L.get(U);return fe===void 0&&(fe=`#${B++}`,L.set(U,fe)),fe}}}const L=new WeakMap;let B=0;function Q(E,ie){if(!E||E.stable===!1||!ve(E.keyEmpty)||!Array.isArray(ie)||ie.length===0)return;let he=0,U=null,se;for(let Ee=0;Ee<ie.length;Ee++){const De=ie[Ee];E.keyEmpty(De)&&(he++,U===null&&(U=ve(E.missingFields)?E.missingFields(De):[],se=De))}if(he===0)return;const fe=E.fields.length?E.fields.join(","):"(function)",ge=U&&U.length?U.join(", "):E.fields.length?E.fields.join(", "):"the rowKey function",Se=se!==null&&typeof se=="object"?Object.keys(se).join(", ")||"(no fields)":String(se);V(`rowKey.emptyValue:${fe}`,`rowKey ${ge} is missing on ${he} of ${ie.length} rows; the first such row has: ${Se}. 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 K(E){return be(E)}function ce(E){return E.split(N)}}),st("packages/modules/data-router/devtools.js",function(p,Oe){"use strict";Object.defineProperty(p,"mountRouterDevtools",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(p,"default",{enumerable:!0,get:function(){return be}});const V=Oe("packages/core/src/internal/util.js").warnOnce,oe="lat-router-devtools";function ve(T,L,B){const Q=T.createElement(L);return Q.textContent=B==null?"—":String(B),Q}function ee(T){return Number.isFinite(T)?`${Math.round(T*10)/10}/s`:"—"}function ke(T,L,B,Q){const K=T.createElement("section");K.className=`${oe}-section`;const ce=T.createElement("h4");ce.textContent=L,K.appendChild(ce);const E=T.createElement("table"),ie=T.createElement("tr");for(const he of B)ie.appendChild(ve(T,"th",he));E.appendChild(ie);for(const he of Q){const U=T.createElement("tr");for(const se of he)U.appendChild(ve(T,"td",se));E.appendChild(U)}return K.appendChild(E),K}function N(T,L,B){L.textContent="";const Q=ke(T,"Router",["metric","value"],[["throughput",ee(B.throughput)],["unrouted",B.unrouted],["dropped (duplicate)",B.dropped],["buffer depth",B.buffered],["lag (deltas behind)",B.lag]]);L.appendChild(Q),L.appendChild(ke(T,"Routes",["#","label","kind","rows","shown","rows/sec"],B.routes.map(K=>[K.index,K.label,K.kind,K.rows,K.shown,ee(K.throughput)]))),B.sources.length&&L.appendChild(ke(T,"Sources",["id","rows","ingested","rows/sec"],B.sources.map(K=>[K.id,K.rows,K.ingested,ee(K.throughput)])))}function ye(T,L,B={}){const Q=L&&L.ownerDocument||(typeof document<"u"?document:null);if(!T||typeof T.metrics!="function"||typeof T.on!="function"||!L||!Q)return V("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 K=Q.createElement("div");K.className=oe,L.appendChild(K);const ce=()=>N(Q,K,T.metrics());ce();const E=T.on("metrics",()=>ce());return{refresh:ce,destroy(){E(),K.parentNode&&K.parentNode.removeChild(K)}}}const be=ye}),st("packages/modules/data-router/index.js",function(p,Oe){"use strict";Object.defineProperty(p,"createDataRouter",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(p,"default",{enumerable:!0,get:function(){return tt}});const V=Oe("packages/core/src/internal/util.js").warnOnce,oe=Oe("packages/core/src/source/pushdown.js"),ve=oe.planQuery,ee=oe.capabilitiesOf,N=Oe("packages/core/src/model/rowkey.js").compositeKey,be=Oe("packages/modules/data-router/devtools.js").mountRouterDevtools;function T(c,q){return typeof c=="function"?c:typeof c=="string"?O=>O[c]:q}function L(c){return Array.isArray(c)?"array":c===null?"null":typeof c}function B(c,q){if(c===void 0||typeof c=="string"&&c.length>0)return c;if(typeof c=="function")return O=>{const A=c(O);if(typeof A=="string"||typeof A=="number"&&Number.isFinite(A))return A;throw new Error(`lattice-data-router: rowKey function must return a string or number; got ${L(A)}.`)};throw new Error(`lattice-data-router: rowKey must be a property name or a function; composite keys are not supported on ${q}.`)}function Q(c){if(typeof c=="function")return c;if(c&&typeof c=="object"&&typeof c.key=="string"){const q=c.dir==="desc"?-1:1,{key:O}=c;return(A,_)=>{const ae=A?A[O]:void 0,Te=_?_[O]:void 0;return ae<Te?-1*q:ae>Te?1*q:0}}return null}function K(c){if(!c||typeof c!="object")return null;let q=0;Number.isFinite(c.minInterval)&&c.minInterval>0?q=Number(c.minInterval):Number.isFinite(c.maxHz)&&c.maxHz>0&&(q=1e3/Number(c.maxHz));const O=Number.isFinite(c.sample)&&c.sample>1?Math.floor(Number(c.sample)):1,A=Number.isFinite(c.maxLag)&&c.maxLag>=0?Math.floor(Number(c.maxLag)):null;return q===0&&O===1&&A===null?null:{minInterval:q,sample:O,maxLag:A}}let ce=0;function E(){return ce+=1,`r${ce}`}function ie(c){const O=(Array.isArray(c)?c:[c]).map(A=>({name:typeof A=="string"?A:null,get:T(A,()=>{})}));return A=>{const _={},ae=[];for(const Te of O){const Ze=Te.get(A);ae.push(Ze),Te.name&&(_[Te.name]=Ze)}return{key:N(ae),fields:_}}}function he(c,q){if(typeof c=="function")return c(q);if(c&&typeof c=="object"){const{op:O,field:A}=c;if(O==="count")return q.length;const _=A!=null?q.map(ae=>Number(ae[A])).filter(ae=>Number.isFinite(ae)):[];if(O==="sum")return _.reduce((ae,Te)=>ae+Te,0);if(O==="avg")return _.length?_.reduce((ae,Te)=>ae+Te,0)/_.length:0;if(O==="min")return _.length?Math.min(..._):void 0;if(O==="max")return _.length?Math.max(..._):void 0}}function U(c){return c&&typeof c=="object"&&typeof c.from=="string"&&typeof c.to=="string"?{from:c.to,to:c.from}:(V("data-router:mutual-fn","relate({ mutual: true }) with a function relation cannot be inverted; the same predicate is applied in both directions. Use a { from, to } key map for a mutual edge."),c)}function se(c,q){return c?q?{op:"and",conditions:[c,q]}:c:q||null}const fe=Object.freeze(["eq","ne","lt","lte","gt","gte","between","notBetween","in","notIn","contains","notContains","startsWith","endsWith","blank","notBlank"]);function ge(c,q){const O=q?q[c.col]:void 0,A=c.value,_=ae=>c.caseSensitive?String(ae):String(ae).toLowerCase();switch(c.op){case"eq":return O===A;case"ne":return O!==A;case"lt":return O<A;case"lte":return O<=A;case"gt":return O>A;case"gte":return O>=A;case"between":return Array.isArray(A)&&O>=A[0]&&O<=A[1];case"notBetween":return!(Array.isArray(A)&&O>=A[0]&&O<=A[1]);case"in":return Array.isArray(A)&&A.includes(O);case"notIn":return!(Array.isArray(A)&&A.includes(O));case"contains":return O!=null&&_(O).includes(_(A));case"notContains":return O==null||!_(O).includes(_(A));case"startsWith":return O!=null&&_(O).startsWith(_(A));case"endsWith":return O!=null&&_(O).endsWith(_(A));case"blank":return O==null||O==="";case"notBlank":return!(O==null||O==="");default:throw new Error(`[lattice] query() cannot evaluate the residual filter operator "${String(c.op)}" on column "${String(c.col)}" client-side, so the query is refused rather than returning rows the filter excludes. Push it down to an adapter that implements it, or use an operator this router evaluates: ${fe.join(", ")}.`)}}function Se(c,q){return c?Array.isArray(c.conditions)?c.op==="or"?c.conditions.some(O=>Se(O,q)):c.op==="not"?!c.conditions.every(O=>Se(O,q)):c.conditions.every(O=>Se(O,q)):ge(c,q):!0}function Ee(c={}){const q=T(c.key,()=>{}),O=T(B(c.rowKey,"routes"),e=>e.rowKey),A=!!c.overlap,_=typeof c.onUnrouted=="function"?c.onUnrouted:null,ae=Number.isFinite(c.selectionDebounce)?Number(c.selectionDebounce):16,Te=typeof c.onWrite=="function"?c.onWrite:null,Ze=typeof c.onConflict=="function"?c.onConflict:null,d=c.seq!=null?T(c.seq,()=>{}):null,g=d?c.dedupe!==!1:!1,S=O;let P=null;typeof c.batch=="number"?P=c.batch:c.batch&&Number.isFinite(c.batch.intervalMs)&&(P=Number(c.batch.intervalMs));const ne=P!==null||!!c.coalesce,W=new Map;let de,Me=0;const $e=[];let a=null;const l=c.time!=null?T(c.time,()=>{}):null,w=typeof c.now=="function"?c.now:Date.now,H=1e4;let y=!1,F=null,D=null,M="time",i=new Map;const u=[];let f=0,j,Z,me=!1,J=null,Pe=[],Ie=0,Ge=0,Fe="time",_e=!1,Je=null,nt=null;const ft=e=>{if(e&&Number.isFinite(e.seq))return e.seq;if(d&&e&&e.row){const t=d(e.row);return Number.isFinite(t)?t:void 0}},At=e=>{if(e&&Number.isFinite(e.t))return e.t;if(l&&e&&e.row){const t=l(e.row);if(Number.isFinite(t))return t}return w()},Le=[];let Qe=null;const Ve=[],Ce=[],rt=new Map,at=new Set;let Xe=null,et=0;const ot=new Map,ut=new Set,it=typeof c.rowKey=="string"?c.rowKey:"rowKey",He=new Map;let wt=0;const ht=new Map,Ye=(e,t)=>{ht.set(e,(ht.get(e)||0)+t)};let vt=0;const k=new Map,R=new Map;let $=null;const C=Number.isFinite(c.metricsInterval)?Number(c.metricsInterval):1e3;let m=0,z=null,ue="lattice-router",je=250,we=null,te=null,Ae=!1,Ke=!1,Re=null,Be=!1,re=null;const le=[],G=()=>Qe?[...Le,Qe]:Le,We=e=>G().find(t=>t.grid===e)||null,lt=e=>{const t=[];for(const n of Le)if(n.match(e)&&(t.push(n),!A))break;return t.length?t:Qe?[Qe]:[]},Et=(e,t)=>{if(t.add.length||t.update.length||t.remove.length){const n=e.sink(t);kt(e,n)}return{added:t.add.length,updated:t.update.length,removed:t.remove.length}},kt=(e,t)=>{const n=t?.rejected;if(!Array.isArray(n)||!n.length)return;const r=n.filter(s=>s&&s.operation==="remove");if(!r.length)return;const o=e.label||`route ${e.routeId}`;V(`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.`)},Nt=(e,t)=>{for(const n of Ve)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},Ue=e=>{const t=[];for(const h of e.partition.values())e.filter&&!e.filter(h)||Nt(e,h)&&t.push(h);let n;if(e.rollup){const h=new Map;for(const b of t){const{key:I,fields:X}=e.rollup.group(b);let Y=h.get(I);Y||(Y={key:I,fields:X,rows:[]},h.set(I,Y)),Y.rows.push(b)}let v=[];for(const b of h.values()){const I={...b.fields};for(const[X,Y]of e.rollup.specs)I[X]=he(Y,b.rows);v.push({gkey:b.key,row:I})}e.sort&&v.sort((b,I)=>e.sort(b.row,I.row)),e.transform&&(v=v.map(b=>({gkey:b.gkey,row:e.transform(b.row)}))),n=new Map(v.map(b=>[b.gkey,b.row]))}else{let h=t;e.sort&&(h=h.slice().sort(e.sort)),n=new Map;for(const v of h)n.set(N([e.keyOf(v)]),e.transform?e.transform(v):v)}const r=[],o=[],s=[];for(const[h,v]of n)e.keys.has(h)?De(e.keys.get(h),v)||o.push(v):r.push(v);for(const h of e.keys.keys())n.has(h)||s.push(h);return e.keys=n,Et(e,{add:r,update:o,remove:s})},dt=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),Ue(e),e.bpPending=0,e.bpLastFlush=w()},x=(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,dt(e)},n),e.bpTimer&&typeof e.bpTimer.unref=="function"&&e.bpTimer.unref()},qe=(e,t)=>{if(!e.bp){Ue(e);return}e.bpPending+=t,e.bpCoalesced+=t;const n=e.bp;if(n.maxLag!=null&&e.bpPending<=n.maxLag&&!e.bpTimer){dt(e);return}const r=w(),o=r-e.bpLastFlush>=n.minInterval,s=e.bpPending>=n.sample;if(o&&s){dt(e);return}x(e,r)},ze=e=>{e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null),e.bpPending=0,e.bpLastFlush=w()},gt=(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(s=>s&&s[n]));return s=>o.has(s&&s[r])}return null},Ft=e=>{const t=We(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)},cn=e=>{const t=e&&e.selection;if(!t||typeof t.predicate!="function")return null;const n=t.predicate();if(!n||n.all!==!0)return null;const r=typeof t.count=="function"?t.count():Promise.resolve(null);return{predicate:n,count:r}},pt=e=>{const t=cn(e.from);if(t){if(typeof e.relation=="function"&&e.relation.length>=2){const r=e.relation(Ft(e.from),t);e.predicate=typeof r=="function"?r:null}else V("data-router:link-predicate-unsupported","link()/relate() source grid has every row matching a filter selected on a source that holds only the rows it has loaded. The relation does not declare it accepts a predicate selection — a function taking (selected, { predicate, count }) as its second parameter — so the link cannot build a target-row predicate from a truncated key list and imposes no constraint."),e.predicate=null;return}const n=Ft(e.from);e.predicate=n.length?gt(e.relation,n):null},mt=()=>{const e=new Set;for(const t of Ce)e.add(t.from),e.add(t.to);return e},ct=()=>{for(const s of G())s.graphPreds=null;if(!Ce.length)return;const e=mt(),t=new Map;for(const s of e){const h=Ft(s);h.length&&t.set(s,h)}const n=new Map(t);let r=!0,o=(e.size+1)*2;for(;r&&o-- >0;){r=!1;for(const s of e){if(t.has(s))continue;const h=Ce.filter(Y=>Y.to===s&&n.has(Y.from));if(!h.length)continue;const v=We(s);if(!v)continue;const b=h.map(Y=>gt(Y.rel,n.get(Y.from))).filter(Boolean),I=[];for(const Y of v.partition.values())b.every(Ne=>Ne(Y))&&I.push(Y);const X=n.get(s);if(!X||X.length!==I.length)n.set(s,I),r=!0;else{const Y=new Set(X);I.some(Ne=>!Y.has(Ne))&&(n.set(s,I),r=!0)}}}for(const s of Ce){if(!n.has(s.from))continue;const h=gt(s.rel,n.get(s.from));if(!h)continue;const v=We(s.to);v&&(v.graphPreds||(v.graphPreds=[])).push(h)}},Kt=e=>{const t=rt.get(e);if(t){t.count+=1;return}const n=e&&typeof e.on=="function"?e.on("selection:changed",()=>fn(e)):()=>{};rt.set(e,{off:n,count:1})},Lt=()=>{Xe&&(clearTimeout(Xe),Xe=null);const e=at;if(!e.size)return;const t=new Set;for(const n of Ve)e.has(n.from)&&(pt(n),t.add(n.to));if(at.clear(),Ce.length){ct();for(const n of mt())t.add(n)}for(const n of t){const r=We(n);r&&Ue(r)}},fn=e=>{if(at.add(e),ae<=0){Lt();return}Xe||(Xe=setTimeout(Lt,ae))},Ut=e=>{const t=rt.get(e);t&&(t.count-=1,t.count<=0&&(t.off(),rt.delete(e)))},dn=e=>typeof e=="function"?t=>e(t):e&&e.rows&&typeof e.rows.apply=="function"?t=>e.rows.apply(t):(V("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."),()=>{}),Dt=(e,t,n)=>({grid:e,routeId:E(),sink:dn(e),match:t,keyOf:T(B(n.rowKey,"routes"),O),partition:new Map,keys:new Map,transform:typeof n.transform=="function"?n.transform:null,filter:typeof n.filter=="function"?n.filter:null,sort:Q(n.sort),rollup:n.rollup&&n.rollup.groupBy!=null?{group:ie(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:K(n.backpressure),bpPending:0,bpTimer:null,bpLastFlush:-1/0,bpCoalesced:0}),zt=e=>{if(!A){for(const t of Le)if(t.hasPartValue&&t.partValue===e){V(`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}}},Vt=(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},St=(e,t)=>{const n=e.grid;if(!n||!n.edit||typeof n.edit.setCells!="function")return;const r=Vt(t.key,t.colId);ut.add(r);try{n.edit.setCells([{key:t.key,colId:t.colId,value:t.before}],"cell")}finally{ut.delete(r)}Ye("writeReverted",1)},Gt=e=>{e&&xe.apply([{op:"upsert",row:e}])},_t=(e,t,n)=>{const r=n&&typeof n=="object"?n:null,o=r&&r.conflict!==void 0?r.conflict:null;if(o){const s=e.onConflict||Ze;if(s)try{s(t,{serverRow:o})}catch{}Ye("writeConflicted",1),Gt(r&&r.row?r.row:t.row);return}if(n===!1||r&&r.ok===!1){Ye("writeRejected",1),St(e,t);return}Ye("writeAccepted",1),Gt(r&&r.row?r.row:t.row)},hn=e=>{const t=String(e);for(const n of He.values())if(n.live.has(t))return n.handle;return null},gn=(e,t)=>{if(!t||t.key===void 0||t.colId===void 0||ut.has(Vt(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(Ye("writeRouted",1),e.readonly){V("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."),St(e,r);return}const o=e.onWrite||Te;if(!o){V("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 s;try{s=o(r,{route:e.grid,source:hn(r.key)})}catch{St(e,r),Ye("writeRejected",1);return}s&&typeof s.then=="function"?s.then(h=>_t(e,r,h),()=>{St(e,r),Ye("writeRejected",1)}):_t(e,r,s)},mn=e=>{const t=e.grid;if(!t||typeof t.on!="function"||!t.edit||typeof t.edit.setCells!="function"){V("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(ot.has(t))return;const n=t.on("cell:changed",r=>gn(e,r));ot.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},Ot=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},$t=(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)}},yt=()=>{const e=new Map;for(const t of G())for(const n of t.partition.values())e.set(String(S(n)),n);return[...e.values()]},Jt=()=>{i=new Map;for(const e of G())for(const t of e.partition.values())i.set(String(S(t)),t);u.length=0,f=0,j=de,Z=void 0},Qt=()=>{const e=u.shift();e&&(e.op==="del"?i.delete(e.key):i.set(e.key,e.row),j=e.seq,Z=e.t)},wn=()=>{if(F!=null)for(;u.length>F;)Qt();if(D!=null&&u.length){const e=u[u.length-1].t;for(;u.length>1&&e-u[0].t>D;)Qt()}},vn=e=>{!e||!e.row||u.push({pos:f++,seq:ft(e),t:At(e),op:e.op==="delete"?"del":"set",key:String(S(e.row)),row:e.row})},It=(e,t)=>t==="seq"?e.seq:e.t,Pt=(e,t)=>{const n=new Map(i);for(const r of u){const o=It(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},Rt=e=>{const t=new Map(G().map(n=>[n,[]]));for(const n of e)for(const r of lt(n))t.get(r).push(n);for(const n of G())n.partition=new Map(t.get(n).map(r=>[String(n.keyOf(r)),r]));for(const n of Ve)pt(n);ct();for(const n of G())Ue(n)},Ct=e=>y?!0:(V("data-router:no-buffer",`${e}() needs a buffered window; call router.buffer({ window, max }) first to record one.`),!1),Tt=()=>{if(Je&&(clearTimeout(Je),Je=null),_e=!1,Pe=[],Ie=0,nt){const e=nt;nt=null,e()}},En=()=>{if(Pe=[],Ie=0,nt){const e=nt;nt=null,e()}},kn=()=>{Je=null;const e=Pe[Ie++];e.op==="del"?J.delete(e.key):J.set(e.key,e.row),Rt([...J.values()]),m=e.pos+1,Wt()};function Wt(){if(!_e){if(Ie>=Pe.length){En();return}Je=setTimeout(kn,Ge)}}function jt(e){if(Re)try{Re.postMessage(e)}catch{}}function Yt(){return{t:"snapshot",rows:yt(),seq:de,checkpoint:Object.fromEntries(W)}}function Sn(e){const t=e&&e.data;if(!(!t||typeof t!="object")){if(t.t==="hello"){yt().length&&jt(Yt());return}Be=!0;try{t.t==="delta"?xe.apply(t.deltas||[]):t.t==="snapshot"&&(xe.load(t.rows||[]),t.checkpoint&&xe.seenThrough(t.checkpoint))}finally{Be=!1}}}function On(e,t){e.partition=new Map(t.map(n=>[String(e.keyOf(n)),n]))}function Pn(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 s=[];for(const v of n)if(v.match(o)&&(s.push(v),!A))break;const h=s.length?s:r?[r]:[];if(!h.length){et+=1,_&&_(o);continue}for(const v of h)v.partition.set(String(v.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[it]}`},Zt=(e,t)=>{const n={...e.map?e.map(t):t};return e.ns&&(n[it]=e.ns(n)),n},Xt=(e,t)=>{const n=[];for(const r of t||[]){if(!r||!r.row)continue;const o=Zt(e,r.row),s=String(o[it]);r.op==="delete"?e.live.delete(s):e.live.set(s,o),n.push({...r,row:o})}return e.ingested+=n.length,Ye(`source:${e.id}`,n.length),n},Tn=e=>({get id(){return e.id},get size(){return e.live.size},load(t){const n=(t||[]).map(s=>Zt(e,s)),r=new Map(n.map(s=>[String(s[it]),s])),o=[];for(const[s,h]of e.live)r.has(s)||o.push({op:"delete",row:h});for(const s of n)o.push({op:"upsert",row:s});return e.live=r,e.ingested+=n.length,Ye(`source:${e.id}`,n.length),Bt(e,o,s=>xe.apply(s)),this},apply(t){return Bt(e,Xt(e,t),n=>xe.apply(n)),this},push(t){return Bt(e,Xt(e,Array.isArray(t)?t:[t]),n=>xe.push(n)),this},remove(){const t=[];for(const n of e.live.values())t.push({op:"delete",row:n});return e.live.clear(),He.delete(e.id),t.length&&xe.apply(t),xe}}),Mt=e=>e==null?null:String(e),jn=(e,t)=>{if(!e||typeof e!="object")return null;const n=e.from!=null?String(e.from):null;if(!n)return V("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=Ne=>Ne[r];else return V("data-router:join-no-localkey","join needs a `localKey` (a field name or fn); ignoring the join."),null;const s=e.foreignKey!=null?e.foreignKey:e.fromKey;let h,v;if(typeof s=="function")h=s,v=s;else if(typeof s=="string")h=Ne=>Ne[s],v=s;else if(typeof r=="string")h=Ne=>Ne[r],v=r;else return V("data-router:join-no-foreignkey","join with a fn `localKey` needs an explicit string/fn `foreignKey`; ignoring the join."),null;let b=null;const I=[],X=e.fields!=null?e.fields:e.select;if(typeof X=="function")b=X;else if(Array.isArray(X))for(const Ne of X)I.push([String(Ne),String(Ne)]);else if(X&&typeof X=="object")for(const[Ne,bt]of Object.entries(X))I.push([Ne,String(bt)]);else V("data-router:join-no-fields","join has no `fields`/`select`; rows pass through unenriched.");let Y=e.missing;return Y!=="hold"&&Y!=="passthrough"&&Y!=="null"&&(Y!=null&&V("data-router:join-bad-missing",`join.missing "${Y}" is not hold|passthrough|null; using "passthrough".`),Y="passthrough"),{from:n,localKey:o,foreignKeyFn:h,ffKey:v,pairs:I,selectFn:b,missing:Y,keyIndex:new Map,lastFk:new Map,owner:t,probe:null}},en=(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,s]of e.pairs)r[s]=n?n[o]:null;return r},An=(e,t)=>{if(t==null||!e.probe)return null;const n=e.probe.index.get(t);if(!n||!n.size)return null;const r=He.get(e.from);if(!r)return null;let o;for(o of n);return r.live.get(o)||null},tn=(e,t,n)=>{const r=An(e,n);return r?{emit:!0,row:en(e,t,r)}:e.missing==="hold"?{emit:!1,row:t}:e.missing==="null"?{emit:!0,row:en(e,t,null)}:{emit:!0,row:{...t}}},nn=(e,t,n)=>{const r=e.lastFk.get(t);if(r!==void 0&&r!==n){const s=e.keyIndex.get(r);s&&(s.delete(t),s.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)},Nn=(e,t)=>{const n=e.join,r=[];for(const o of t){const s=String(o.row[it]);if(o.op==="delete"){nn(n,s,null),n.lastFk.delete(s),r.push(o);continue}const h=Mt(n.localKey(o.row));nn(n,s,h);const v=tn(n,o.row,h);v.emit&&r.push({...o,row:v.row})}return r},rn=(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 s=Mt(n.fn(o));if(s==null)continue;let h=n.index.get(s);h||(h=new Set,n.index.set(s,h)),h.add(r),n.prev.set(r,s)}}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 s of t){const h=String(s.row[it]);if(s.op==="delete"){const I=r.prev.get(h);if(I!=null){const X=r.index.get(I);X&&(X.delete(h),X.size||r.index.delete(I)),o.add(I)}r.prev.delete(h);continue}const v=Mt(r.fn(s.row)),b=r.prev.get(h);if(b!=null&&b!==v){const I=r.index.get(b);I&&(I.delete(h),I.size||r.index.delete(b)),o.add(b)}if(v!=null){let I=r.index.get(v);I||(I=new Set,r.index.set(v,I)),I.add(h),o.add(v)}r.prev.set(h,v)}if(o.size)for(const s of r.specs)for(const h of o){const v=s.keyIndex.get(h);if(v)for(const b of v){const I=s.owner.live.get(b);if(!I)continue;const X=tn(s,I,h);n.push(X.emit?{op:"upsert",row:X.row}:{op:"delete",row:I})}}}n.length&&xe.apply(n)},Bt=(e,t,n)=>{n(e.join?Nn(e,t):t),e.probes&&e.probes.size&&Fn(e,t)},qt=(e,t,n)=>{const r=k.get(e);if(k.set(e,{cur:t,t:n}),!r)return 0;const o=(n-r.t)/1e3;return o<=0?0:(t-r.cur)/o},Ln=()=>{if(!y)return 0;let e=0;for(const t of u)t.pos>=m&&(e+=1);return e},Dn=(e,t)=>{const n=R.get(e);if(n)for(const r of n)try{r(t)}catch{}},$n=()=>{$||C<=0||($=setInterval(()=>Dn("metrics",xe.metrics()),C),$&&typeof $.unref=="function"&&$.unref())},on=()=>{$&&(clearInterval($),$=null)},In=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 s=()=>o||(o=new Promise((h,v)=>{let b;try{b=t.open(n,1)}catch(I){v(I);return}b.onupgradeneeded=()=>{const I=b.result;I.objectStoreNames.contains(r)||I.createObjectStore(r)},b.onsuccess=()=>h(b.result),b.onerror=()=>v(b.error)}),o);return{set(h,v){return s().then(b=>new Promise((I,X)=>{const Y=b.transaction(r,"readwrite");Y.objectStore(r).put(v,h),Y.oncomplete=()=>I(),Y.onerror=()=>X(Y.error),Y.onabort=()=>X(Y.error)}))},get(h){return s().then(v=>new Promise((b,I)=>{const Y=v.transaction(r,"readonly").objectStore(r).get(h);Y.onsuccess=()=>b(Y.result),Y.onerror=()=>I(Y.error)}))},close(){o&&o.then(h=>{try{h.close()}catch{}},()=>{})}}},Cn=()=>y?[...Pt(void 0,M).values()]:yt(),Wn=()=>({v:1,world:Cn(),maxSeq:de,checkpoint:Object.fromEntries(W),buffer:y?{on:!0,max:F,window:D,domain:M,pos:f,baseSeq:j,baseT:Z,base:[...i.entries()],log:u.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;Ke=!0;try{xe.load(Array.isArray(e.world)?e.world:[])}finally{Ke=!1}e.checkpoint&&xe.seenThrough(e.checkpoint),Number.isFinite(e.maxSeq)&&(de===void 0||e.maxSeq>de)&&(de=e.maxSeq);const t=e.buffer;if(t&&t.on){y=!0,F=Number.isFinite(t.max)?t.max:null,D=Number.isFinite(t.window)?t.window:null,M=t.domain==="seq"||t.domain==="time"?t.domain:d?"seq":"time",i=new Map(Array.isArray(t.base)?t.base:[]),u.length=0;for(const n of Array.isArray(t.log)?t.log:[])u.push({...n});f=Number.isFinite(t.pos)?t.pos:u.length,j=t.baseSeq,Z=t.baseT,m=f}return!0},Ht=()=>{if(!z)return Promise.resolve();const e=Wn(),t=Promise.resolve().then(()=>z.set(ue,e)).catch(()=>{});return te=t,t.then(()=>{te===t&&(te=null)})},xt=()=>{if(!(!Ae||!z||Ke)){if(je<=0){Ht();return}we||(we=setTimeout(()=>{we=null,Ht()},je),we&&typeof we.unref=="function"&&we.unref())}},xe={attach(e,t,n={}){const r=typeof t!="function",o=r?h=>q(h)===t:t;r&&zt(t);const s=Dt(e,o,n);return r&&(s.hasPartValue=!0,s.partValue=t),Le.push(s),s.writable&&mn(s),this},attachDefault(e,t={}){return Qe=Dt(e,()=>!1,t),Qe.isDefault=!0,this},subscribe(e,t,n={}){const r=typeof e!="function",o=r?h=>q(h)===e:e;r&&zt(e);const s=Dt(t,o,n);return r&&(s.hasPartValue=!0,s.partValue=e),Le.push(s),this},alert(e,t,n,r={}){const s={match:typeof e=="function"?e:h=>q(h)===e,keyOf:T(B(r.rowKey,"alerts"),O),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 le.push(s),$t(s,yt()),Ot(s),this},monitor(e,t,n,r={}){const s={kind:"monitor",match:typeof e=="function"?e:h=>q(h)===e,keyOf:T(B(r.rowKey,"alerts"),O),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 le.push(s),$t(s,yt()),Ot(s),()=>{const h=le.indexOf(s);h>=0&&le.splice(h,1),s.timer&&(clearTimeout(s.timer),s.timer=null),s.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};Ve.push(r),Kt(e),pt(r);const o=We(t);return o&&Ue(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;Ce.push({from:t.from,to:t.to,rel:n}),t.mutual&&Ce.push({from:t.to,to:t.from,rel:U(n)})}for(const t of mt())Kt(t);ct();for(const t of mt()){const n=We(t);n&&Ue(n)}return this},flush(){return Lt(),this},detach(e){const t=new Set;for(let o=Ve.length-1;o>=0;o--){const s=Ve[o];(s.from===e||s.to===e)&&(s.to!==e&&t.add(s.to),Ut(s.from),Ve.splice(o,1))}let n=!1;for(let o=Ce.length-1;o>=0;o--)(Ce[o].from===e||Ce[o].to===e)&&(Ut(Ce[o].from),Ce.splice(o,1),n=!0);for(let o=Le.length-1;o>=0;o--)Le[o].grid===e&&Le.splice(o,1);Qe&&Qe.grid===e&&(Qe=null),at.delete(e);const r=ot.get(e);if(r&&(r(),ot.delete(e)),n){ct();for(const o of mt())t.add(o)}for(const o of t){const s=We(o);s&&Ue(s)}return this},load(e){et=0;const t=new Map(G().map(r=>[r,[]]));for(const r of e||[]){const o=lt(r);if(!o.length){et+=1,_&&_(r);continue}for(const s of o)t.get(s).push(r)}for(const r of G()){const o=t.get(r);r.partition=new Map(o.map(s=>[String(r.keyOf(s)),s])),r.metricRows+=o.length,vt+=o.length}if(d)for(const r of e||[]){const o=d(r);if(!Number.isFinite(o))continue;const s=String(S(r)),h=W.get(s);(h===void 0||o>h)&&W.set(s,o),(de===void 0||o>de)&&(de=o)}for(const r of Ve)pt(r);ct();for(const r of le)$t(r,e||[]),Ot(r);for(const r of G())r.bp&&ze(r);const n=G().map(r=>Ue(r));return y&&Jt(),m=f,Re&&!Be&&jt(Yt()),xt(),n},apply(e){let t=(e||[]).filter(o=>o&&o.row);if(g){t=t.map((s,h)=>[s,h]).sort((s,h)=>{const v=ft(s[0]),b=ft(h[0]);return v===void 0||b===void 0?s[1]-h[1]:v-b||s[1]-h[1]}).map(s=>s[0]);const o=[];for(const s of t){const h=ft(s);if(h!==void 0){const v=String(S(s.row)),b=W.get(v);if(b!==void 0&&h<=b){Me+=1;continue}W.set(v,h),(de===void 0||h>de)&&(de=h)}o.push(s)}t=o}if(Re&&!Be&&t.length&&jt({t:"delta",deltas:t.map(o=>({op:o.op,row:o.row,seq:o.seq}))}),y){for(const o of t)vn(o);wn()}for(const o of le)bn(o,t),Ot(o);if(me){xt();return}const n=new Map(G().map(o=>[o,new Map]));for(const o of t){const s=o&&o.row;if(!s)continue;if(o.op==="delete"){let v=!1;for(const b of G()){const I=String(b.keyOf(s));(b.partition.has(I)||n.get(b).has(I))&&(n.get(b).set(I,{op:"del"}),v=!0)}!v&&!lt(s).length&&(et+=1,_&&_(o));continue}const h=lt(s);if(!h.length){et+=1,_&&_(o);continue}for(const v of G()){if(h.includes(v))continue;const b=String(v.keyOf(s));(v.partition.has(b)||n.get(v).get(b)?.op==="set")&&n.get(v).set(b,{op:"del"})}for(const v of h)n.get(v).set(String(v.keyOf(s)),{op:"set",row:s})}const r=new Map;for(const o of G()){let s=0;const h=n.get(o).size;for(const[v,b]of n.get(o)){if(b.op==="del"){o.partition.delete(v);continue}o.partition.set(v,b.row),s+=1}o.metricRows+=s,vt+=s,r.set(o,h)}for(const o of Ve)pt(o);ct();for(const o of G())qe(o,r.get(o)||0);m=f,xt()},push(e){const t=Array.isArray(e)?e:[e];if(!ne)return this.apply(t),this;for(const n of t)$e.push(n);return P!==null&&(P<=0?this.flushStream():a||(a=setTimeout(()=>this.flushStream(),P))),this},flushStream(){if(a&&(clearTimeout(a),a=null),!$e.length)return this;const e=$e.splice(0,$e.length);return this.apply(e),this},flushBackpressure(){for(const e of G())e.bp&&(e.bpTimer||e.bpPending>0)&&dt(e);return this},addSource(e,t){let n,r;e&&typeof e=="object"?(r=e,n=r.id!=null?String(r.id):`source${++wt}`):(n=e!=null?String(e):`source${++wt}`,r=t||{});const o=He.get(n);if(o)return V("data-router:duplicate-source",`addSource("${n}") was already registered; returning the existing source handle. Use a distinct id per feed.`),o.handle;const s={id:n,map:typeof r.map=="function"?r.map:null,ns:Rn(n,r.key),live:new Map,ingested:0};s.handle=Tn(s),s.join=jn(r.join,s),He.set(n,s),s.join&&He.has(s.join.from)&&rn(He.get(s.join.from),s.join);for(const h of He.values())h!==s&&h.join&&h.join.from===n&&h.join.probe==null&&rn(s,h.join);return s.handle},removeSource(e){const t=e&&typeof e=="object"&&e.id!==void 0?String(e.id):String(e),n=He.get(t);return n&&n.handle.remove(),this},sources(){return[...He.keys()]},metrics(){const e=w(),t=G().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:qt(`route:${o}`,r.metricRows,e),backpressure:r.bp?{pending:r.bpPending,coalesced:r.bpCoalesced}:null})),n=[...He.values()].map(r=>({id:r.id,rows:r.live.size,ingested:r.ingested,throughput:qt(`source:${r.id}`,r.ingested,e)}));return{routes:t,sources:n,unrouted:et,dropped:Me,buffered:u.length,lag:Ln(),throughput:qt("total",vt,e)}},on(e,t){if(typeof t!="function")return()=>{};let n=R.get(e);return n||(n=new Set,R.set(e,n)),n.add(t),e==="metrics"&&$n(),()=>{n.delete(t),e==="metrics"&&n.size===0&&on()}},mountDevtools(e,t={}){return be(this,e,t)},get unrouted(){return et},get dropped(){return Me},lastSeq(){return de},checkpoint(){return new Map(W)},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 s=W.get(String(n));(s===void 0||o>s)&&W.set(String(n),o),(de===void 0||o>de)&&(de=o)}return this},persist(e={}){if(Ae=!0,typeof e.key=="string"&&(ue=e.key),Number.isFinite(e.debounce)&&(je=Number(e.debounce)),e.storage&&typeof e.storage.get=="function"&&typeof e.storage.set=="function")z=e.storage;else{let t=null;try{t=In(e)}catch{t=null}t?z=t:(z=null,V("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(!z)return!1;let e;try{e=await z.get(ue)}catch{return!1}return e==null?!1:Mn(e)},async flushPersist(){return we&&(clearTimeout(we),we=null),await Ht(),te&&await te,this},get persisting(){return Ae&&!!z},buffer(e={}){return y=!0,Number.isFinite(e.max)?F=Number(e.max):"max"in e&&e.max==null&&(F=null),Number.isFinite(e.window)?D=Number(e.window):"window"in e&&e.window==null&&(D=null),F==null&&D==null&&(F=H,V("data-router:buffer-default-cap",`buffer() called with no window or max; applying a default cap of ${H} deltas so the buffer stays bounded. Pass { window } or { max } to size it.`)),M=d?"seq":"time",Jt(),this},scrubTo(e,t={}){if(!Ct("scrubTo"))return this;Tt(),me=!0;const n=t.by||M;J=Pt(e,n),Rt([...J.values()]),m=0;for(const r of u){const o=It(r,n);if(e!==void 0&&o!==void 0&&o>e)break;m=r.pos+1}return this},replay(e,t,n={}){if(!Ct("replay"))return Promise.resolve();Tt(),me=!0;const r=n.by||M;return Fe=r,Ge=Number.isFinite(n.speed)?Number(n.speed):0,J=Pt(e,r),Rt([...J.values()]),Pe=u.filter(o=>{const s=It(o,r);return s!==void 0&&s>e&&s<=t}).slice().sort((o,s)=>o.pos-s.pos),Ie=0,_e=!1,new Promise(o=>{nt=o,Wt()})},pause(){return _e=!0,Je&&(clearTimeout(Je),Je=null),this},resume(){return _e?(_e=!1,Wt(),this):this},live(){return Ct("live")?(Tt(),me=!1,J=null,Rt([...Pt(void 0,M).values()]),m=f,this):this},get traveling(){return me},get buffered(){return u.length},broadcast(e={}){if(typeof BroadcastChannel!="function")return V("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?(Re&&(Re.close(),Re=null),Re=new BroadcastChannel(t),Re.onmessage=Sn,jt({t:"hello"}),this):(V("data-router:broadcast-channel","router.broadcast({ channel }) needs a string channel name; nothing was mirrored."),this)},get broadcasting(){return!!Re},async query(e,t={}){if(!e||typeof e.execute!="function")return V("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=ee(e.capabilities),r=t||{},o=r.filters||null,s=[];et=0;const h=G().filter(b=>b.where),v=G().filter(b=>!b.where);for(const b of h){const I=se(o,b.where),X=ve({...r,filters:I},n);let Ne=((await e.execute(X.pushed,r)).rows||[]).slice();X.residual&&X.residual.filters&&(Ne=Ne.filter(bt=>Se(X.residual.filters,bt))),Ne=Ne.filter(bt=>b.match(bt)),On(b,Ne),s.push({route:b.grid,pushedFilter:!!(X.pushed&&X.pushed.filters),residual:X.unpushed.slice()})}if(v.length){const b=ve(r,n);let X=((await e.execute(b.pushed,r)).rows||[]).slice();b.residual&&b.residual.filters&&(X=X.filter(Y=>Se(b.residual.filters,Y))),Pn(X,v),s.push({base:!0,pushedFilter:!!(b.pushed&&b.pushed.filters),residual:b.unpushed.slice()})}re=s;for(const b of Ve)pt(b);ct();for(const b of G())Ue(b);return this},lastQueryPlan(){return re?re.map(e=>({...e})):null},destroy(){if(Xe&&(clearTimeout(Xe),Xe=null),a&&(clearTimeout(a),a=null),we&&(clearTimeout(we),we=null),z&&typeof z.close=="function")try{z.close()}catch{}Ae=!1,z=null,Re&&(Re.close(),Re=null),Be=!1,Tt(),y=!1,me=!1,J=null,u.length=0,i.clear();for(const e of rt.values())e.off();rt.clear();for(const e of ot.values())e();ot.clear(),ut.clear(),He.clear(),on(),R.clear(),k.clear();for(const e of le)e.timer&&(clearTimeout(e.timer),e.timer=null);le.length=0;for(const e of G())e.bpTimer&&(clearTimeout(e.bpTimer),e.bpTimer=null);Ve.length=0,Ce.length=0,at.clear(),$e.length=0,W.clear(),Le.length=0,Qe=null}};return c.config&&xe.configure(c.config),xe}function De(c,q){if(c===q)return!0;if(!c||!q)return!1;const O=Object.keys(c),A=Object.keys(q);if(O.length!==A.length)return!1;for(const _ of O)if(c[_]!==q[_])return!1;return!0}const tt=Ee});const ln=un("packages/modules/data-router/index.js"),Bn=ln.createDataRouter;var qn=ln.default;export{Bn as createDataRouter,qn as default};
|
|
7
7
|
|
|
8
8
|
//# sourceMappingURL=data-router.esm.min.js.map
|