@toclocoinc/lattice-grid 1.89.0 → 1.89.1
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 +15 -0
- package/README.md +1 -1
- package/angular/package.json +1 -1
- package/docs/API.html +5 -5
- package/docs/THEMING.md +27 -0
- package/docs/api/adapters.html +1 -1
- package/docs/api/ai.html +1 -1
- package/docs/api/alarms.html +1 -1
- package/docs/api/calendar.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/designer.html +2 -2
- 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/mapview.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/calendar.d.ts +1 -1
- package/modules/calendar.esm.min.js +2 -2
- package/modules/calendar.min.cjs +2 -2
- package/modules/calendar.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-barrace.d.ts +1 -1
- package/modules/chart-barrace.esm.min.js +1 -1
- package/modules/chart-barrace.min.cjs +1 -1
- package/modules/chart-barrace.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-forcetree.d.ts +1 -1
- package/modules/chart-forcetree.esm.min.js +1 -1
- package/modules/chart-forcetree.min.cjs +1 -1
- package/modules/chart-forcetree.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-motion.d.ts +1 -1
- package/modules/chart-motion.esm.min.js +1 -1
- package/modules/chart-motion.min.cjs +1 -1
- package/modules/chart-motion.min.js +1 -1
- package/modules/chart-pack.d.ts +1 -1
- package/modules/chart-pack.esm.min.js +1 -1
- package/modules/chart-pack.min.cjs +1 -1
- package/modules/chart-pack.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-pictorial.d.ts +1 -1
- package/modules/chart-pictorial.esm.min.js +1 -1
- package/modules/chart-pictorial.min.cjs +1 -1
- package/modules/chart-pictorial.min.js +1 -1
- package/modules/chart-polararea.d.ts +1 -1
- package/modules/chart-polararea.esm.min.js +1 -1
- package/modules/chart-polararea.min.cjs +1 -1
- package/modules/chart-polararea.min.js +1 -1
- package/modules/chart-polarscatter.d.ts +1 -1
- package/modules/chart-polarscatter.esm.min.js +1 -1
- package/modules/chart-polarscatter.min.cjs +1 -1
- package/modules/chart-polarscatter.min.js +1 -1
- package/modules/chart-pyramid.d.ts +1 -1
- package/modules/chart-pyramid.esm.min.js +1 -1
- package/modules/chart-pyramid.min.cjs +1 -1
- package/modules/chart-pyramid.min.js +1 -1
- package/modules/chart-radialbar.d.ts +1 -1
- package/modules/chart-radialbar.esm.min.js +1 -1
- package/modules/chart-radialbar.min.cjs +1 -1
- package/modules/chart-radialbar.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-serpentine.d.ts +1 -1
- package/modules/chart-serpentine.esm.min.js +1 -1
- package/modules/chart-serpentine.min.cjs +1 -1
- package/modules/chart-serpentine.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-spiral.d.ts +1 -1
- package/modules/chart-spiral.esm.min.js +1 -1
- package/modules/chart-spiral.min.cjs +1 -1
- package/modules/chart-spiral.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-tree.d.ts +1 -1
- package/modules/chart-tree.esm.min.js +1 -1
- package/modules/chart-tree.min.cjs +1 -1
- package/modules/chart-tree.min.js +1 -1
- package/modules/chart-venn.d.ts +1 -1
- package/modules/chart-venn.esm.min.js +1 -1
- package/modules/chart-venn.min.cjs +1 -1
- package/modules/chart-venn.min.js +1 -1
- package/modules/chart-voronoi.d.ts +1 -1
- package/modules/chart-voronoi.esm.min.js +1 -1
- package/modules/chart-voronoi.min.cjs +1 -1
- package/modules/chart-voronoi.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/chart-wordcloud.d.ts +1 -1
- package/modules/chart-wordcloud.esm.min.js +1 -1
- package/modules/chart-wordcloud.min.cjs +1 -1
- package/modules/chart-wordcloud.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/designer.d.ts +1 -1
- package/modules/designer.esm.min.js +187 -73
- package/modules/designer.esm.min.js.map +2 -2
- package/modules/designer.min.cjs +187 -73
- package/modules/designer.min.js +187 -73
- package/modules/designer.min.js.map +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/mapview.d.ts +1 -1
- package/modules/mapview.esm.min.js +2 -2
- package/modules/mapview.min.cjs +2 -2
- package/modules/mapview.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 +9 -0
- package/modules/presets/bootstrap5.css +9 -0
- package/modules/presets/fluent2.css +9 -0
- package/modules/presets/material3.css +9 -0
- 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,71 +1,82 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Lattice Grid 1.89.
|
|
2
|
+
* Lattice Grid 1.89.1, designer 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 rt(s,ae){Sn[s]=ae}function $n(s){var ae=An[s];if(ae)return ae;var ve=Object.create(null);An[s]=ve;var F=Sn[s];if(!F)throw new Error("[lattice] missing module: "+s);return F(ve,$n),ve}rt("packages/core/src/internal/util.js",function(s,ae){"use strict";Object.defineProperty(s,"VERSION",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"reportedWarnings",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"warnOnce",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"infoOnce",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"resetWarnings",{enumerable:!0,get:function(){return y}}),Object.defineProperty(s,"fail",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"invariant",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"DEV",{enumerable:!0,get:function(){return c}}),Object.defineProperty(s,"isObject",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"isFunction",{enumerable:!0,get:function(){return b}}),Object.defineProperty(s,"isNil",{enumerable:!0,get:function(){return P}}),Object.defineProperty(s,"isBlank",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"isCtor",{enumerable:!0,get:function(){return A}}),Object.defineProperty(s,"pathGetter",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"pathSetter",{enumerable:!0,get:function(){return G}}),Object.defineProperty(s,"getPath",{enumerable:!0,get:function(){return _}}),Object.defineProperty(s,"setPath",{enumerable:!0,get:function(){return T}}),Object.defineProperty(s,"humanise",{enumerable:!0,get:function(){return p}}),Object.defineProperty(s,"escapeHtml",{enumerable:!0,get:function(){return n}}),Object.defineProperty(s,"titleCase",{enumerable:!0,get:function(){return t}}),Object.defineProperty(s,"expand",{enumerable:!0,get:function(){return a}}),Object.defineProperty(s,"toArray",{enumerable:!0,get:function(){return e}}),Object.defineProperty(s,"merge",{enumerable:!0,get:function(){return d}}),Object.defineProperty(s,"mergeRow",{enumerable:!0,get:function(){return E}}),Object.defineProperty(s,"Lru",{enumerable:!0,get:function(){return M}}),Object.defineProperty(s,"collator",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(s,"defaultCompare",{enumerable:!0,get:function(){return q}}),Object.defineProperty(s,"now",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(s,"nextFrame",{enumerable:!0,get:function(){return O}}),Object.defineProperty(s,"cancelFrame",{enumerable:!0,get:function(){return I}}),Object.defineProperty(s,"frameBatched",{enumerable:!0,get:function(){return K}}),Object.defineProperty(s,"settleDebounce",{enumerable:!0,get:function(){return g}}),Object.defineProperty(s,"whenIdle",{enumerable:!0,get:function(){return k}}),Object.defineProperty(s,"uid",{enumerable:!0,get:function(){return R}});const ve="1.89.0";async function F(){return ve}const l="1.89.0",ue=new Set,z=2e3;function fe(N){if(ue.add(N),ue.size>z){const $=ue.values().next().value;$!==void 0&&ue.delete($)}}const J=[],X=500;function ne(N,$,S){J.push({key:N,level:$,message:S.map(Y=>typeof Y=="string"?Y:B(Y)).join(" "),at:Date.now()}),J.length>X&&J.shift()}function B(N){if(N instanceof Error)return N.message;try{return JSON.stringify(N)}catch{return String(N)}}function L(){return J.map(N=>({...N}))}function D(N){if(N.length===0||typeof N[0]!="string")return N;const $=N[0].replace(/^\[lattice\]\s*/,"");return $===N[0]?N:[$,...N.slice(1)]}function o(N,...$){if(ue.has(N))return;fe(N);const S=D($);ne(N,"warn",S),console.warn("[lattice]",...S)}function w(N,...$){if(ue.has(N))return;fe(N);const S=D($);ne(N,"info",S),console.info("[lattice]",...S)}function y(){ue.clear(),J.length=0}function i(N,$){const S=new Error(`[lattice] ${N}`);throw $!==void 0&&(S.cause=$),S}function h(N,$){N||i($)}const c=(()=>{try{return!(typeof process<"u"&&process.env&&process.env.NODE_ENV==="production")}catch{return!0}})();function m(N){return N!==null&&typeof N=="object"&&!Array.isArray(N)}function b(N){return typeof N=="function"}function P(N){return N==null}function u(N){return N==null||N===""}function A(N){return typeof N!="function"?!1:/^class[\s{]/.test(Function.prototype.toString.call(N))?!0:!!(N.prototype&&Object.getOwnPropertyNames(N.prototype).length>1)}const r=new Map;function j(N){let $=r.get(N);if($)return $;if(!N.includes("."))$=S=>S?.[N];else{const S=N.split("."),Y=S.length;$=Z=>{let x=Z;for(let ee=0;ee<Y;ee++){if(x==null)return;x=x[S[ee]]}return x}}return r.set(N,$),$}const C=new Map;function G(N){let $=C.get(N);if($)return $;if(!N.includes("."))$=(S,Y)=>{S!=null&&(S[N]=Y)};else{const S=N.split("."),Y=S.length-1;$=(Z,x)=>{let ee=Z;for(let se=0;se<Y;se++){if(ee==null)return;const de=S[se];ee[de]==null&&(ee[de]={}),ee=ee[de]}ee!=null&&(ee[S[Y]]=x)}}return C.set(N,$),$}function _(N,$){return j($)(N)}function T(N,$,S){G($)(N,S)}function p(N){return N?(N.includes(".")?N.slice(N.lastIndexOf(".")+1):N).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(/^./,S=>S.toUpperCase()):""}const v={"&":"&","<":"<",">":">",'"':""","'":"'"};function n(N){const $=N==null?"":String(N);return/[&<>"']/.test($)?$.replace(/[&<>"']/g,S=>v[S]):$}function t(N){return String(N).replace(/\w\S*/g,$=>$[0].toUpperCase()+$.slice(1).toLowerCase())}function a(N,$,S){if(N!==void 0)return N===!0?{enabled:!0,...S}:N===!1?{enabled:!1}:m(N)?N:{[$]:N,enabled:!0}}function e(N){return N==null?[]:Array.isArray(N)?N:[N]}const f=Object.freeze(new Set(["__proto__","constructor","prototype"]));function d(N,$){if(!m(N))return m($)?{...$}:$;if(!m($))return $===void 0?N:$;const S={...N};for(const Y of Object.keys($)){if(f.has(Y))continue;const Z=$[Y];Z!==void 0&&(S[Y]=m(Z)&&m(S[Y])?d(S[Y],Z):Z)}return S}function E(N,$){if(!m(N)||!m($)||N===$)return $;const S=Object.create(Object.getPrototypeOf(N));return Object.assign(S,N,$),S}class M{#e;#t=new Map;#n;constructor($=256,S=null){this.#e=$,this.#n=S}get size(){return this.#t.size}get max(){return this.#e}set max($){this.#e=$,this.#r()}has($){return this.#t.has($)}get($){const S=this.#t;if(!S.has($))return;const Y=S.get($);return S.delete($),S.set($,Y),Y}peek($){return this.#t.get($)}set($,S){const Y=this.#t;return Y.has($)&&Y.delete($),Y.set($,S),this.#r(),S}delete($){const S=this.#t.get($);return this.#t.delete($)&&this.#n&&this.#n(S,$),S}clear(){if(this.#n)for(const[$,S]of this.#t)this.#n(S,$);this.#t.clear()}keys(){return this.#t.keys()}values(){return this.#t.values()}#r(){const $=this.#t;for(;$.size>this.#e;){const S=$.keys().next().value,Y=$.get(S);$.delete(S),this.#n&&this.#n(Y,S)}}}const W=new Map;function oe(N,$){const S=`${N||""}|${$?JSON.stringify($):""}`;let Y=W.get(S);return Y||(Y=new Intl.Collator(N||void 0,{numeric:!0,sensitivity:"variant",...$}),W.set(S,Y)),Y}function q(N,$){if(N===$)return 0;if(N==null)return 1;if($==null)return-1;if(typeof N=="number"&&typeof $=="number")return Number.isNaN(N)?Number.isNaN($)?0:1:Number.isNaN($)||N<$?-1:N>$?1:0;const S=String(N),Y=String($);return S<Y?-1:S>Y?1:0}function Q(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const H=typeof requestAnimationFrame=="function";function O(N){return H?requestAnimationFrame(N):setTimeout(()=>N(Q()),16)}function I(N){N!=null&&(H?cancelAnimationFrame(N):clearTimeout(N))}function K(N){let $=null,S=null;const Y=()=>{$=null;const x=S;S=null,N(...x||[])},Z=(...x)=>{S=x,$===null&&($=O(Y))};return Z.cancel=()=>{I($),$=null,S=null},Z.flush=()=>{$!==null&&(I($),Y())},Z}function g(N,$){let S=null,Y=null;const Z=()=>{if(S=null,Y===null)return;const se=Y;Y=null,N(...se),x()},x=()=>{S=setTimeout(Z,$),typeof S?.unref=="function"&&S.unref()},ee=(...se)=>{S===null?(N(...se),x()):(Y=se,clearTimeout(S),x())};return ee.flush=()=>{if(S!==null&&clearTimeout(S),S=null,Y===null)return;const se=Y;Y=null,N(...se)},ee.cancel=()=>{S!==null&&clearTimeout(S),S=null,Y=null},ee.pending=()=>S!==null||Y!==null,ee}function k(N,$=50){return typeof requestIdleCallback=="function"?requestIdleCallback(N,{timeout:$}):setTimeout(()=>N({timeRemaining:()=>0,didTimeout:!0}),1)}let V=0;function R(N="l"){return`${N}${(++V).toString(36)}`}}),rt("packages/modules/shared/emitter.js",function(s,ae){"use strict";Object.defineProperty(s,"WILDCARD",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"Emitter",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"gate",{enumerable:!0,get:function(){return X}});const ve=ae("packages/core/src/internal/util.js"),F=ve.isFunction,l=ve.warnOnce,ue="*",z=new Set(["api","user","init","ai"]);function fe(ne,B){return ne&&ne.name?ne.name:`#${B}`}class J{#e=new Map;#t;constructor(B="module"){this.#t=String(B)}on(B,L){if(!F(L))return()=>{};let D=this.#e.get(B);return D||(D=new Set,this.#e.set(B,D)),D.add(L),()=>this.off(B,L)}off(B,L){const D=this.#e.get(B);D&&D.delete(L)}count(B){const L=this.#e.get(B);return L?L.size:0}emit(B,L){const D=this.#e.get(B),o=this.#e.get(ue);if((!D||D.size===0)&&(!o||o.size===0))return;const w={...L||null,type:B};D&&D.size&&this.#n([...D],w,B),o&&o.size&&this.#n([...o],w,ue)}#n(B,L,D){for(let o=0;o<B.length;o++)try{B[o](L)}catch(w){l(`${this.#t}.emit.throw:${D}:${fe(B[o],o)}`,`${this.#t}: a '${D}' handler threw; other handlers were unaffected.`,w)}}emitBefore(B,L,D){const o=D??(L&&L.origin),w=z.has(o)?o:"user";let y=!1,i=null;const h=A=>{y=!0,A!=null&&i===null&&(i=String(A))},c={...L||null,type:B,origin:w,get defaultPrevented(){return y},get reason(){return i},preventDefault(A){h(A)}},m=this.#e.get(B);if(!m||m.size===0)return!0;const b=[...m],P=()=>(y&&i===null&&(i="prevented"),y&&L&&typeof L=="object"&&(L.reason=i),!y),u=[];for(let A=0;A<b.length;A++){const r=b[A];try{const j=r(c);j&&F(j.then)?u.push(j):j===!1&&h("prevented")}catch(j){h("error"),l(`${this.#t}.beforeThrow:${B}:${fe(r,A)}`,`${this.#t}: a '${B}' before-handler threw; the action was cancelled.`,j)}}return u.length===0?P():Promise.allSettled(u).then(A=>{for(const r of A)r.status==="rejected"?(h("error"),l(`${this.#t}.beforeReject:${B}`,`${this.#t}: a '${B}' before-handler rejected; the action was cancelled.`,r.reason)):r.value===!1&&h("prevented");return P()})}clear(){this.#e.clear()}}function X(ne,B,L,D,o){const w=ne.emitBefore(B,D,D.origin),y=()=>(ne.emit(L,{...D,reason:D.reason||"prevented"}),!1);return w===!1?y():w&&F(w.then)?w.then(i=>i?o():y()):o()}}),rt("packages/modules/dashboard/spec.js",function(s,ae){"use strict";Object.defineProperty(s,"PANEL_KINDS",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(s,"SOURCE_KINDS",{enumerable:!0,get:function(){return F}}),Object.defineProperty(s,"MAP_BINDINGS",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"GRID_REF",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"isPlain",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"copySpec",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"sameSpec",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"parseSourceRef",{enumerable:!0,get:function(){return D}}),Object.defineProperty(s,"readRelation",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"inspectSpec",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"validateDashboardSpec",{enumerable:!0,get:function(){return y}});const ve=Object.freeze(["grid","chart","kpi","calendar","map","html"]),F=Object.freeze(["rows","pushdown","router","grid"]),l=Object.freeze(["chart","leaflet","deckgl"]),ue=Object.freeze(["layout","panels","sources","links"]),z=Object.freeze(["id","kind","title","source","options","binding"]),fe=Object.freeze(["from","to","on"]),J=Object.freeze({rows:["kind","rows","columns","rowKey"],router:["kind","router","predicate","route","columns","rowKey"],grid:["kind","of"]}),X="grid:";function ne(i){if(!i||typeof i!="object"||Array.isArray(i))return!1;const h=Object.getPrototypeOf(i);return h===Object.prototype||h===null}function B(i,h){if(h==="rows"&&Array.isArray(i))return i;if(Array.isArray(i))return i.map(m=>B(m));if(!ne(i)||Object.values(i).some(m=>typeof m=="function"))return i;const c={};for(const[m,b]of Object.entries(i))b!==void 0&&(c[m]=B(b,m));return c}function L(i,h){if(i===h)return!0;if(Array.isArray(i)||Array.isArray(h))return!Array.isArray(i)||!Array.isArray(h)||i.length!==h.length?!1:i.every((b,P)=>L(b,h[P]));if(!ne(i)||!ne(h))return!1;const c=Object.keys(i).filter(b=>i[b]!==void 0),m=Object.keys(h).filter(b=>h[b]!==void 0);return c.length!==m.length?!1:c.every(b=>L(i[b],h[b]))}function D(i){return typeof i!="string"||i===""?null:i.startsWith(X)?{kind:"grid",of:i.slice(X.length)}:{kind:"named",id:i}}function o(i){return typeof i=="string"&&i!==""?{from:i,to:i}:typeof i=="function"?i:ne(i)&&typeof i.from=="string"&&i.from!==""&&typeof i.to=="string"&&i.to!==""?{from:i.from,to:i.to}:null}function w(i){const h=[],c=new Set,m=new Set,b=new Set,P=new Set,u={fatal:null,problems:h,badPanels:c,badSources:m,badLinks:b,badWindows:P};if(!ne(i))return u.fatal="the spec is not an object",h.push({path:"",message:"is not an object: a spec is { layout, panels, sources, links }"}),u;const A=i;if(!Array.isArray(A.panels))return u.fatal="spec.panels is not an array",h.push({path:"panels",message:"is not an array of panels"}),u;for(const G of Object.keys(A))ue.includes(G)||h.push({path:G,message:`is not a dashboard spec key (${ue.join(", ")})`});const r=new Map;A.panels.forEach((G,_)=>{const T=`panels[${_}]`;if(!ne(G)){c.add(_),h.push({path:T,message:"is not an object"});return}if(typeof G.id!="string"||G.id===""){c.add(_),h.push({path:`${T}.id`,message:"is missing: every panel needs a unique string id"});return}if(r.has(G.id)){c.add(_),h.push({path:`${T}.id`,panel:G.id,message:`repeats "${G.id}", which panels[${r.get(G.id).index}] already uses`});return}r.set(G.id,{index:_,kind:G.kind})});const j=A.sources===void 0?{}:A.sources;if(!ne(j))h.push({path:"sources",message:"is not an object of named sources"});else for(const[G,_]of Object.entries(j)){const T=`sources.${G}`,p=(n,t)=>{m.add(G),h.push({path:n,message:t})};if(!ne(_)){p(T,"is not an object");continue}if(!F.includes(_.kind)){p(`${T}.kind`,`names no source kind (${F.join(", ")})`);continue}const v=J[_.kind];if(v)for(const n of Object.keys(_))v.includes(n)||h.push({path:`${T}.${n}`,message:`is not a key of a ${_.kind} source (${v.join(", ")})`});if(_.columns!==void 0&&!Array.isArray(_.columns)&&p(`${T}.columns`,"is not an array of columns"),_.kind==="rows"&&!Array.isArray(_.rows)&&p(`${T}.rows`,"is not an array of rows"),_.kind==="pushdown"&&!(_.adapter&&typeof _.adapter.execute=="function")&&p(`${T}.adapter`,"is not a pushdown adapter (an object with execute())"),_.kind==="router"&&(_.router&&typeof _.router.attach=="function"||p(`${T}.router`,"is not a Data Router (an object with attach())"),_.predicate===void 0&&p(`${T}.predicate`,"is missing: name the partition value or predicate the route matches")),_.kind==="grid"){const n=typeof _.of=="string"?r.get(_.of):void 0;n?n.kind!=="grid"&&p(`${T}.of`,`names "${_.of}", a ${n.kind} panel: only a grid panel has a grid to view`):p(`${T}.of`,"names no panel")}}const C=new Map;A.panels.forEach((G,_)=>{if(c.has(_))return;const T=`panels[${_}]`,p=(t,a)=>{c.add(_),h.push({path:t,panel:G.id,message:a})};for(const t of Object.keys(G))z.includes(t)||h.push({path:`${T}.${t}`,panel:G.id,message:`is not a panel key (${z.join(", ")}); a viewer's own settings go in options`});if(!ve.includes(G.kind)){p(`${T}.kind`,`names no panel kind (${ve.join(", ")})`);return}if(G.title!==void 0&&typeof G.title!="string"&&h.push({path:`${T}.title`,panel:G.id,message:"is not a string"}),G.options!==void 0&&!ne(G.options)){p(`${T}.options`,"is not an object");return}if(G.binding!==void 0&&(G.kind!=="map"?p(`${T}.binding`,`is only read on a map panel, and this is a ${G.kind} panel`):l.includes(G.binding)||p(`${T}.binding`,`names no map binding (${l.join(", ")})`)),G.source===void 0){(G.kind==="chart"||G.kind==="map"||G.kind==="calendar")&&p(`${T}.source`,`is missing: a ${G.kind} panel draws a source's rows`);return}if(G.kind==="html"){p(`${T}.source`,"is set on an html panel, which reads no rows");return}const v=D(G.source);if(!v){p(`${T}.source`,"is not a source id");return}let n=null;if(v.kind==="grid")n=v.of;else if(!ne(j)||!Object.hasOwn(j,v.id)){p(`${T}.source`,`names "${v.id}", which is not in sources`);return}else if(m.has(v.id)){p(`${T}.source`,`names "${v.id}", a source that is not usable`);return}else j[v.id].kind==="grid"&&(n=j[v.id].of);if(n!==null){const t=r.get(n);if(!t){p(`${T}.source`,`views the grid of "${n}", which is not a panel`);return}if(t.kind!=="grid"){p(`${T}.source`,`views the grid of "${n}", a ${t.kind} panel`);return}if(n===G.id){p(`${T}.source`,"views its own grid");return}C.set(G.id,n)}});for(let G=!0;G;)G=!1,A.panels.forEach((_,T)=>{if(c.has(T)||!C.has(_.id))return;const p=new Set([_.id]);let v=C.get(_.id);for(;v!==void 0;){const n=r.get(v);if(p.has(v)){c.add(T),h.push({path:`panels[${T}].source`,panel:_.id,message:`is part of a cycle of panels viewing each other's grids (${[...p,v].join(" -> ")})`}),G=!0;return}if(!n||c.has(n.index)){c.add(T),h.push({path:`panels[${T}].source`,panel:_.id,message:`views the grid of "${v}", a panel that was not built`}),G=!0;return}p.add(v),v=C.get(v)}});if(A.links!==void 0&&!Array.isArray(A.links)?h.push({path:"links",message:"is not an array of links"}):(A.links||[]).forEach((G,_)=>{const T=`links[${_}]`,p=(v,n)=>{b.add(_),h.push({path:v,link:_,message:n})};if(!ne(G)){p(T,"is not an object");return}for(const v of Object.keys(G))fe.includes(v)||h.push({path:`${T}.${v}`,link:_,message:`is not a link key (${fe.join(", ")})`});if(typeof G.from!="string"||!r.has(G.from)){p(`${T}.from`,"names no panel");return}if(typeof G.to!="string"||!r.has(G.to)){p(`${T}.to`,"names no panel");return}if(G.from===G.to){p(`${T}.to`,"is the panel the link starts from");return}o(G.on)||p(`${T}.on`,"is not a column name, a { from, to } pair of column names, or a relation function")}),A.layout!==void 0){if(!ne(A.layout))h.push({path:"layout",message:"is not an object"});else if(A.layout.windows!==void 0)if(!Array.isArray(A.layout.windows))h.push({path:"layout.windows",message:"is not an array of windows"});else{const G=new Set;A.layout.windows.forEach((_,T)=>{const p=`layout.windows[${T}]`;!ne(_)||typeof _.id!="string"?(P.add(T),h.push({path:p,message:"is not a window with a string id"})):r.has(_.id)?G.has(_.id)?(P.add(T),h.push({path:`${p}.id`,message:`places "${_.id}" a second time`})):G.add(_.id):(P.add(T),h.push({path:`${p}.id`,message:`names "${_.id}", which is not a panel`}))})}}return u}function y(i){const{problems:h}=w(i);return{ok:h.length===0,problems:h.map(({path:c,message:m})=>({path:c,message:m}))}}}),rt("packages/modules/dashboard/propose.js",function(s,ae){"use strict";Object.defineProperty(s,"PROPOSE_SYSTEM",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"columnRefs",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"proposalRequest",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"parseProposal",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"checkProposal",{enumerable:!0,get:function(){return D}});const ve=ae("packages/modules/dashboard/spec.js"),F=ve.inspectSpec,l=ve.isPlain,ue=ve.copySpec,z=ve.parseSourceRef,fe=["You design dashboards for a data grid. Return ONLY a JSON object of the form",'{ "layout": { "columns": <n>, "rows": <n> }, "panels": [ { "id": "<id>", "kind": "<kind>",','"title": "<title>", "source": "<source id>", "binding": "chart", "options": { ... } } ],','"links": [ { "from": "<grid panel id>", "to": "<panel id>", "on": "<column>" } ] }.',"Use only the panel kinds and the columns listed in SCHEMA, and only the source it names.","A chart panel's options are a chart spec (type, x, y, series); a kpi panel's are",'{ tiles: [ { id, field, aggregation } ] }; a map panel with binding "chart" takes a map chart',`spec (type "markermap", lon, lat); a grid panel's are { columns: [ { field } ] }.`,"A person reviews the proposal before anything is built."].join(" "),J=Object.freeze(["x","y","series","measure","size","value","volume","lon","lat","geometry","label","start","end","source","target","multiples"]);function X(o){const w=new Set,y=l(o.options)?o.options:{},i=h=>{typeof h=="string"&&h!==""&&w.add(h)};if(o.kind==="grid")for(const h of Array.isArray(y.columns)?y.columns:[])l(h)&&i(h.field);else if(o.kind==="kpi"){for(const h of Array.isArray(y.tiles)?y.tiles:[])l(h)&&i(h.field);for(const h of Array.isArray(y.fields)?y.fields:[])i(h)}else if(o.kind==="chart"||o.kind==="map"&&(o.binding||"chart")==="chart")for(const h of J)i(y[h]);else o.kind==="map"&&l(y.position)&&(i(y.position.lon),i(y.position.lat),i(y.position.geometry));return[...w]}function ne(o,w){const y={source:w.source,columns:w.columns,kinds:w.kinds};let i=`${o}
|
|
6
|
+
var An=Object.create(null),$n=Object.create(null);function rt(o,ce){An[o]=ce}function On(o){var ce=$n[o];if(ce)return ce;var ke=Object.create(null);$n[o]=ke;var F=An[o];if(!F)throw new Error("[lattice] missing module: "+o);return F(ke,On),ke}rt("packages/core/src/internal/util.js",function(o,ce){"use strict";Object.defineProperty(o,"VERSION",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"reportedWarnings",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"warnOnce",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"infoOnce",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"resetWarnings",{enumerable:!0,get:function(){return k}}),Object.defineProperty(o,"fail",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"invariant",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"DEV",{enumerable:!0,get:function(){return c}}),Object.defineProperty(o,"isObject",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"isFunction",{enumerable:!0,get:function(){return y}}),Object.defineProperty(o,"isNil",{enumerable:!0,get:function(){return P}}),Object.defineProperty(o,"isBlank",{enumerable:!0,get:function(){return u}}),Object.defineProperty(o,"isCtor",{enumerable:!0,get:function(){return E}}),Object.defineProperty(o,"pathGetter",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"pathSetter",{enumerable:!0,get:function(){return N}}),Object.defineProperty(o,"getPath",{enumerable:!0,get:function(){return T}}),Object.defineProperty(o,"setPath",{enumerable:!0,get:function(){return C}}),Object.defineProperty(o,"humanise",{enumerable:!0,get:function(){return h}}),Object.defineProperty(o,"escapeHtml",{enumerable:!0,get:function(){return a}}),Object.defineProperty(o,"titleCase",{enumerable:!0,get:function(){return n}}),Object.defineProperty(o,"expand",{enumerable:!0,get:function(){return t}}),Object.defineProperty(o,"toArray",{enumerable:!0,get:function(){return e}}),Object.defineProperty(o,"merge",{enumerable:!0,get:function(){return x}}),Object.defineProperty(o,"mergeRow",{enumerable:!0,get:function(){return S}}),Object.defineProperty(o,"Lru",{enumerable:!0,get:function(){return B}}),Object.defineProperty(o,"collator",{enumerable:!0,get:function(){return te}}),Object.defineProperty(o,"defaultCompare",{enumerable:!0,get:function(){return q}}),Object.defineProperty(o,"now",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(o,"nextFrame",{enumerable:!0,get:function(){return M}}),Object.defineProperty(o,"cancelFrame",{enumerable:!0,get:function(){return R}}),Object.defineProperty(o,"frameBatched",{enumerable:!0,get:function(){return H}}),Object.defineProperty(o,"settleDebounce",{enumerable:!0,get:function(){return f}}),Object.defineProperty(o,"whenIdle",{enumerable:!0,get:function(){return g}}),Object.defineProperty(o,"uid",{enumerable:!0,get:function(){return j}});const ke="1.89.1";async function F(){return ke}const l="1.89.1",de=new Set,z=2e3;function fe(A){if(de.add(A),de.size>z){const D=de.values().next().value;D!==void 0&&de.delete(D)}}const J=[],Q=500;function ie(A,D,p){J.push({key:A,level:D,message:p.map(se=>typeof se=="string"?se:W(se)).join(" "),at:Date.now()}),J.length>Q&&J.shift()}function W(A){if(A instanceof Error)return A.message;try{return JSON.stringify(A)}catch{return String(A)}}function L(){return J.map(A=>({...A}))}function _(A){if(A.length===0||typeof A[0]!="string")return A;const D=A[0].replace(/^\[lattice\]\s*/,"");return D===A[0]?A:[D,...A.slice(1)]}function i(A,...D){if(de.has(A))return;fe(A);const p=_(D);ie(A,"warn",p),console.warn("[lattice]",...p)}function v(A,...D){if(de.has(A))return;fe(A);const p=_(D);ie(A,"info",p),console.info("[lattice]",...p)}function k(){de.clear(),J.length=0}function r(A,D){const p=new Error(`[lattice] ${A}`);throw D!==void 0&&(p.cause=D),p}function m(A,D){A||r(D)}const c=(()=>{try{return!(typeof process<"u"&&process.env&&process.env.NODE_ENV==="production")}catch{return!0}})();function b(A){return A!==null&&typeof A=="object"&&!Array.isArray(A)}function y(A){return typeof A=="function"}function P(A){return A==null}function u(A){return A==null||A===""}function E(A){return typeof A!="function"?!1:/^class[\s{]/.test(Function.prototype.toString.call(A))?!0:!!(A.prototype&&Object.getOwnPropertyNames(A.prototype).length>1)}const d=new Map;function w(A){let D=d.get(A);if(D)return D;if(!A.includes("."))D=p=>p?.[A];else{const p=A.split("."),se=p.length;D=V=>{let O=V;for(let X=0;X<se;X++){if(O==null)return;O=O[p[X]]}return O}}return d.set(A,D),D}const G=new Map;function N(A){let D=G.get(A);if(D)return D;if(!A.includes("."))D=(p,se)=>{p!=null&&(p[A]=se)};else{const p=A.split("."),se=p.length-1;D=(V,O)=>{let X=V;for(let oe=0;oe<se;oe++){if(X==null)return;const ue=p[oe];X[ue]==null&&(X[ue]={}),X=X[ue]}X!=null&&(X[p[se]]=O)}}return G.set(A,D),D}function T(A,D){return w(D)(A)}function C(A,D,p){N(D)(A,p)}function h(A){return A?(A.includes(".")?A.slice(A.lastIndexOf(".")+1):A).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(/^./,p=>p.toUpperCase()):""}const $={"&":"&","<":"<",">":">",'"':""","'":"'"};function a(A){const D=A==null?"":String(A);return/[&<>"']/.test(D)?D.replace(/[&<>"']/g,p=>$[p]):D}function n(A){return String(A).replace(/\w\S*/g,D=>D[0].toUpperCase()+D.slice(1).toLowerCase())}function t(A,D,p){if(A!==void 0)return A===!0?{enabled:!0,...p}:A===!1?{enabled:!1}:b(A)?A:{[D]:A,enabled:!0}}function e(A){return A==null?[]:Array.isArray(A)?A:[A]}const s=Object.freeze(new Set(["__proto__","constructor","prototype"]));function x(A,D){if(!b(A))return b(D)?{...D}:D;if(!b(D))return D===void 0?A:D;const p={...A};for(const se of Object.keys(D)){if(s.has(se))continue;const V=D[se];V!==void 0&&(p[se]=b(V)&&b(p[se])?x(p[se],V):V)}return p}function S(A,D){if(!b(A)||!b(D)||A===D)return D;const p=Object.create(Object.getPrototypeOf(A));return Object.assign(p,A,D),p}class B{#e;#t=new Map;#n;constructor(D=256,p=null){this.#e=D,this.#n=p}get size(){return this.#t.size}get max(){return this.#e}set max(D){this.#e=D,this.#r()}has(D){return this.#t.has(D)}get(D){const p=this.#t;if(!p.has(D))return;const se=p.get(D);return p.delete(D),p.set(D,se),se}peek(D){return this.#t.get(D)}set(D,p){const se=this.#t;return se.has(D)&&se.delete(D),se.set(D,p),this.#r(),p}delete(D){const p=this.#t.get(D);return this.#t.delete(D)&&this.#n&&this.#n(p,D),p}clear(){if(this.#n)for(const[D,p]of this.#t)this.#n(p,D);this.#t.clear()}keys(){return this.#t.keys()}values(){return this.#t.values()}#r(){const D=this.#t;for(;D.size>this.#e;){const p=D.keys().next().value,se=D.get(p);D.delete(p),this.#n&&this.#n(se,p)}}}const Y=new Map;function te(A,D){const p=`${A||""}|${D?JSON.stringify(D):""}`;let se=Y.get(p);return se||(se=new Intl.Collator(A||void 0,{numeric:!0,sensitivity:"variant",...D}),Y.set(p,se)),se}function q(A,D){if(A===D)return 0;if(A==null)return 1;if(D==null)return-1;if(typeof A=="number"&&typeof D=="number")return Number.isNaN(A)?Number.isNaN(D)?0:1:Number.isNaN(D)||A<D?-1:A>D?1:0;const p=String(A),se=String(D);return p<se?-1:p>se?1:0}function ne(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const U=typeof requestAnimationFrame=="function";function M(A){return U?requestAnimationFrame(A):setTimeout(()=>A(ne()),16)}function R(A){A!=null&&(U?cancelAnimationFrame(A):clearTimeout(A))}function H(A){let D=null,p=null;const se=()=>{D=null;const O=p;p=null,A(...O||[])},V=(...O)=>{p=O,D===null&&(D=M(se))};return V.cancel=()=>{R(D),D=null,p=null},V.flush=()=>{D!==null&&(R(D),se())},V}function f(A,D){let p=null,se=null;const V=()=>{if(p=null,se===null)return;const oe=se;se=null,A(...oe),O()},O=()=>{p=setTimeout(V,D),typeof p?.unref=="function"&&p.unref()},X=(...oe)=>{p===null?(A(...oe),O()):(se=oe,clearTimeout(p),O())};return X.flush=()=>{if(p!==null&&clearTimeout(p),p=null,se===null)return;const oe=se;se=null,A(...oe)},X.cancel=()=>{p!==null&&clearTimeout(p),p=null,se=null},X.pending=()=>p!==null||se!==null,X}function g(A,D=50){return typeof requestIdleCallback=="function"?requestIdleCallback(A,{timeout:D}):setTimeout(()=>A({timeRemaining:()=>0,didTimeout:!0}),1)}let I=0;function j(A="l"){return`${A}${(++I).toString(36)}`}}),rt("packages/modules/shared/emitter.js",function(o,ce){"use strict";Object.defineProperty(o,"WILDCARD",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"Emitter",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"gate",{enumerable:!0,get:function(){return Q}});const ke=ce("packages/core/src/internal/util.js"),F=ke.isFunction,l=ke.warnOnce,de="*",z=new Set(["api","user","init","ai"]);function fe(ie,W){return ie&&ie.name?ie.name:`#${W}`}class J{#e=new Map;#t;constructor(W="module"){this.#t=String(W)}on(W,L){if(!F(L))return()=>{};let _=this.#e.get(W);return _||(_=new Set,this.#e.set(W,_)),_.add(L),()=>this.off(W,L)}off(W,L){const _=this.#e.get(W);_&&_.delete(L)}count(W){const L=this.#e.get(W);return L?L.size:0}emit(W,L){const _=this.#e.get(W),i=this.#e.get(de);if((!_||_.size===0)&&(!i||i.size===0))return;const v={...L||null,type:W};_&&_.size&&this.#n([..._],v,W),i&&i.size&&this.#n([...i],v,de)}#n(W,L,_){for(let i=0;i<W.length;i++)try{W[i](L)}catch(v){l(`${this.#t}.emit.throw:${_}:${fe(W[i],i)}`,`${this.#t}: a '${_}' handler threw; other handlers were unaffected.`,v)}}emitBefore(W,L,_){const i=_??(L&&L.origin),v=z.has(i)?i:"user";let k=!1,r=null;const m=E=>{k=!0,E!=null&&r===null&&(r=String(E))},c={...L||null,type:W,origin:v,get defaultPrevented(){return k},get reason(){return r},preventDefault(E){m(E)}},b=this.#e.get(W);if(!b||b.size===0)return!0;const y=[...b],P=()=>(k&&r===null&&(r="prevented"),k&&L&&typeof L=="object"&&(L.reason=r),!k),u=[];for(let E=0;E<y.length;E++){const d=y[E];try{const w=d(c);w&&F(w.then)?u.push(w):w===!1&&m("prevented")}catch(w){m("error"),l(`${this.#t}.beforeThrow:${W}:${fe(d,E)}`,`${this.#t}: a '${W}' before-handler threw; the action was cancelled.`,w)}}return u.length===0?P():Promise.allSettled(u).then(E=>{for(const d of E)d.status==="rejected"?(m("error"),l(`${this.#t}.beforeReject:${W}`,`${this.#t}: a '${W}' before-handler rejected; the action was cancelled.`,d.reason)):d.value===!1&&m("prevented");return P()})}clear(){this.#e.clear()}}function Q(ie,W,L,_,i){const v=ie.emitBefore(W,_,_.origin),k=()=>(ie.emit(L,{..._,reason:_.reason||"prevented"}),!1);return v===!1?k():v&&F(v.then)?v.then(r=>r?i():k()):i()}}),rt("packages/modules/dashboard/spec.js",function(o,ce){"use strict";Object.defineProperty(o,"PANEL_KINDS",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(o,"SOURCE_KINDS",{enumerable:!0,get:function(){return F}}),Object.defineProperty(o,"MAP_BINDINGS",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"GRID_REF",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"isPlain",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"copySpec",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"sameSpec",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"parseSourceRef",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"readRelation",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"inspectSpec",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"validateDashboardSpec",{enumerable:!0,get:function(){return k}});const ke=Object.freeze(["grid","chart","kpi","calendar","map","html"]),F=Object.freeze(["rows","pushdown","router","grid"]),l=Object.freeze(["chart","leaflet","deckgl"]),de=Object.freeze(["layout","panels","sources","links"]),z=Object.freeze(["id","kind","title","source","options","binding"]),fe=Object.freeze(["from","to","on"]),J=Object.freeze({rows:["kind","rows","columns","rowKey"],router:["kind","router","predicate","route","columns","rowKey"],grid:["kind","of"]}),Q="grid:";function ie(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const m=Object.getPrototypeOf(r);return m===Object.prototype||m===null}function W(r,m){if(m==="rows"&&Array.isArray(r))return r;if(Array.isArray(r))return r.map(b=>W(b));if(!ie(r)||Object.values(r).some(b=>typeof b=="function"))return r;const c={};for(const[b,y]of Object.entries(r))y!==void 0&&(c[b]=W(y,b));return c}function L(r,m){if(r===m)return!0;if(Array.isArray(r)||Array.isArray(m))return!Array.isArray(r)||!Array.isArray(m)||r.length!==m.length?!1:r.every((y,P)=>L(y,m[P]));if(!ie(r)||!ie(m))return!1;const c=Object.keys(r).filter(y=>r[y]!==void 0),b=Object.keys(m).filter(y=>m[y]!==void 0);return c.length!==b.length?!1:c.every(y=>L(r[y],m[y]))}function _(r){return typeof r!="string"||r===""?null:r.startsWith(Q)?{kind:"grid",of:r.slice(Q.length)}:{kind:"named",id:r}}function i(r){return typeof r=="string"&&r!==""?{from:r,to:r}:typeof r=="function"?r:ie(r)&&typeof r.from=="string"&&r.from!==""&&typeof r.to=="string"&&r.to!==""?{from:r.from,to:r.to}:null}function v(r){const m=[],c=new Set,b=new Set,y=new Set,P=new Set,u={fatal:null,problems:m,badPanels:c,badSources:b,badLinks:y,badWindows:P};if(!ie(r))return u.fatal="the spec is not an object",m.push({path:"",message:"is not an object: a spec is { layout, panels, sources, links }"}),u;const E=r;if(!Array.isArray(E.panels))return u.fatal="spec.panels is not an array",m.push({path:"panels",message:"is not an array of panels"}),u;for(const N of Object.keys(E))de.includes(N)||m.push({path:N,message:`is not a dashboard spec key (${de.join(", ")})`});const d=new Map;E.panels.forEach((N,T)=>{const C=`panels[${T}]`;if(!ie(N)){c.add(T),m.push({path:C,message:"is not an object"});return}if(typeof N.id!="string"||N.id===""){c.add(T),m.push({path:`${C}.id`,message:"is missing: every panel needs a unique string id"});return}if(d.has(N.id)){c.add(T),m.push({path:`${C}.id`,panel:N.id,message:`repeats "${N.id}", which panels[${d.get(N.id).index}] already uses`});return}d.set(N.id,{index:T,kind:N.kind})});const w=E.sources===void 0?{}:E.sources;if(!ie(w))m.push({path:"sources",message:"is not an object of named sources"});else for(const[N,T]of Object.entries(w)){const C=`sources.${N}`,h=(a,n)=>{b.add(N),m.push({path:a,message:n})};if(!ie(T)){h(C,"is not an object");continue}if(!F.includes(T.kind)){h(`${C}.kind`,`names no source kind (${F.join(", ")})`);continue}const $=J[T.kind];if($)for(const a of Object.keys(T))$.includes(a)||m.push({path:`${C}.${a}`,message:`is not a key of a ${T.kind} source (${$.join(", ")})`});if(T.columns!==void 0&&!Array.isArray(T.columns)&&h(`${C}.columns`,"is not an array of columns"),T.kind==="rows"&&!Array.isArray(T.rows)&&h(`${C}.rows`,"is not an array of rows"),T.kind==="pushdown"&&!(T.adapter&&typeof T.adapter.execute=="function")&&h(`${C}.adapter`,"is not a pushdown adapter (an object with execute())"),T.kind==="router"&&(T.router&&typeof T.router.attach=="function"||h(`${C}.router`,"is not a Data Router (an object with attach())"),T.predicate===void 0&&h(`${C}.predicate`,"is missing: name the partition value or predicate the route matches")),T.kind==="grid"){const a=typeof T.of=="string"?d.get(T.of):void 0;a?a.kind!=="grid"&&h(`${C}.of`,`names "${T.of}", a ${a.kind} panel: only a grid panel has a grid to view`):h(`${C}.of`,"names no panel")}}const G=new Map;E.panels.forEach((N,T)=>{if(c.has(T))return;const C=`panels[${T}]`,h=(n,t)=>{c.add(T),m.push({path:n,panel:N.id,message:t})};for(const n of Object.keys(N))z.includes(n)||m.push({path:`${C}.${n}`,panel:N.id,message:`is not a panel key (${z.join(", ")}); a viewer's own settings go in options`});if(!ke.includes(N.kind)){h(`${C}.kind`,`names no panel kind (${ke.join(", ")})`);return}if(N.title!==void 0&&typeof N.title!="string"&&m.push({path:`${C}.title`,panel:N.id,message:"is not a string"}),N.options!==void 0&&!ie(N.options)){h(`${C}.options`,"is not an object");return}if(N.binding!==void 0&&(N.kind!=="map"?h(`${C}.binding`,`is only read on a map panel, and this is a ${N.kind} panel`):l.includes(N.binding)||h(`${C}.binding`,`names no map binding (${l.join(", ")})`)),N.source===void 0){(N.kind==="chart"||N.kind==="map"||N.kind==="calendar")&&h(`${C}.source`,`is missing: a ${N.kind} panel draws a source's rows`);return}if(N.kind==="html"){h(`${C}.source`,"is set on an html panel, which reads no rows");return}const $=_(N.source);if(!$){h(`${C}.source`,"is not a source id");return}let a=null;if($.kind==="grid")a=$.of;else if(!ie(w)||!Object.hasOwn(w,$.id)){h(`${C}.source`,`names "${$.id}", which is not in sources`);return}else if(b.has($.id)){h(`${C}.source`,`names "${$.id}", a source that is not usable`);return}else w[$.id].kind==="grid"&&(a=w[$.id].of);if(a!==null){const n=d.get(a);if(!n){h(`${C}.source`,`views the grid of "${a}", which is not a panel`);return}if(n.kind!=="grid"){h(`${C}.source`,`views the grid of "${a}", a ${n.kind} panel`);return}if(a===N.id){h(`${C}.source`,"views its own grid");return}G.set(N.id,a)}});for(let N=!0;N;)N=!1,E.panels.forEach((T,C)=>{if(c.has(C)||!G.has(T.id))return;const h=new Set([T.id]);let $=G.get(T.id);for(;$!==void 0;){const a=d.get($);if(h.has($)){c.add(C),m.push({path:`panels[${C}].source`,panel:T.id,message:`is part of a cycle of panels viewing each other's grids (${[...h,$].join(" -> ")})`}),N=!0;return}if(!a||c.has(a.index)){c.add(C),m.push({path:`panels[${C}].source`,panel:T.id,message:`views the grid of "${$}", a panel that was not built`}),N=!0;return}h.add($),$=G.get($)}});if(E.links!==void 0&&!Array.isArray(E.links)?m.push({path:"links",message:"is not an array of links"}):(E.links||[]).forEach((N,T)=>{const C=`links[${T}]`,h=($,a)=>{y.add(T),m.push({path:$,link:T,message:a})};if(!ie(N)){h(C,"is not an object");return}for(const $ of Object.keys(N))fe.includes($)||m.push({path:`${C}.${$}`,link:T,message:`is not a link key (${fe.join(", ")})`});if(typeof N.from!="string"||!d.has(N.from)){h(`${C}.from`,"names no panel");return}if(typeof N.to!="string"||!d.has(N.to)){h(`${C}.to`,"names no panel");return}if(N.from===N.to){h(`${C}.to`,"is the panel the link starts from");return}i(N.on)||h(`${C}.on`,"is not a column name, a { from, to } pair of column names, or a relation function")}),E.layout!==void 0){if(!ie(E.layout))m.push({path:"layout",message:"is not an object"});else if(E.layout.windows!==void 0)if(!Array.isArray(E.layout.windows))m.push({path:"layout.windows",message:"is not an array of windows"});else{const N=new Set;E.layout.windows.forEach((T,C)=>{const h=`layout.windows[${C}]`;!ie(T)||typeof T.id!="string"?(P.add(C),m.push({path:h,message:"is not a window with a string id"})):d.has(T.id)?N.has(T.id)?(P.add(C),m.push({path:`${h}.id`,message:`places "${T.id}" a second time`})):N.add(T.id):(P.add(C),m.push({path:`${h}.id`,message:`names "${T.id}", which is not a panel`}))})}}return u}function k(r){const{problems:m}=v(r);return{ok:m.length===0,problems:m.map(({path:c,message:b})=>({path:c,message:b}))}}}),rt("packages/modules/dashboard/propose.js",function(o,ce){"use strict";Object.defineProperty(o,"PROPOSE_SYSTEM",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"columnRefs",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"proposalRequest",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"parseProposal",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"checkProposal",{enumerable:!0,get:function(){return _}});const ke=ce("packages/modules/dashboard/spec.js"),F=ke.inspectSpec,l=ke.isPlain,de=ke.copySpec,z=ke.parseSourceRef,fe=["You design dashboards for a data grid. Return ONLY a JSON object of the form",'{ "layout": { "columns": <n>, "rows": <n> }, "panels": [ { "id": "<id>", "kind": "<kind>",','"title": "<title>", "source": "<source id>", "binding": "chart", "options": { ... } } ],','"links": [ { "from": "<grid panel id>", "to": "<panel id>", "on": "<column>" } ] }.',"Use only the panel kinds and the columns listed in SCHEMA, and only the source it names.","A chart panel's options are a chart spec (type, x, y, series); a kpi panel's are",'{ tiles: [ { id, field, aggregation } ] }; a map panel with binding "chart" takes a map chart',`spec (type "markermap", lon, lat); a grid panel's are { columns: [ { field } ] }.`,"A person reviews the proposal before anything is built."].join(" "),J=Object.freeze(["x","y","series","measure","size","value","volume","lon","lat","geometry","label","start","end","source","target","multiples"]);function Q(i){const v=new Set,k=l(i.options)?i.options:{},r=m=>{typeof m=="string"&&m!==""&&v.add(m)};if(i.kind==="grid")for(const m of Array.isArray(k.columns)?k.columns:[])l(m)&&r(m.field);else if(i.kind==="kpi"){for(const m of Array.isArray(k.tiles)?k.tiles:[])l(m)&&r(m.field);for(const m of Array.isArray(k.fields)?k.fields:[])r(m)}else if(i.kind==="chart"||i.kind==="map"&&(i.binding||"chart")==="chart")for(const m of J)r(k[m]);else i.kind==="map"&&l(k.position)&&(r(k.position.lon),r(k.position.lat),r(k.position.geometry));return[...v]}function ie(i,v){const k={source:v.source,columns:v.columns,kinds:v.kinds};let r=`${i}
|
|
7
7
|
|
|
8
8
|
SCHEMA
|
|
9
|
-
${JSON.stringify(
|
|
9
|
+
${JSON.stringify(k)}`;v.rows&&(r+=`
|
|
10
10
|
|
|
11
11
|
ROWS
|
|
12
|
-
${JSON.stringify(
|
|
12
|
+
${JSON.stringify(v.rows)}`);const m={system:fe,message:r,prompt:`${fe}
|
|
13
13
|
|
|
14
|
-
${i}`,messages:[{role:"system",content:fe},{role:"user",content:i}],schema:y};return w.rows&&(h.rows=w.rows),w.signal&&(h.signal=w.signal),h}function B(o){try{return JSON.parse(o)}catch{}const w=o.indexOf("{"),y=o.lastIndexOf("}");if(w>=0&&y>w)try{return JSON.parse(o.slice(w,y+1))}catch{}return null}function L(o){let w=o;if(typeof o=="string")w=B(o);else if(l(o)){const y=o;y.structured!==void 0?w=y.structured:Array.isArray(y.panels)?w=y:l(y.spec)?w=y.spec:typeof y.text=="string"?w=B(y.text):typeof y.content=="string"&&(w=B(y.content))}return l(w)&&l(w.spec)&&!Array.isArray(w.panels)&&(w=w.spec),l(w)&&Array.isArray(w.panels)?w:null}function D(o,w){const y=[];if(!l(o)||!Array.isArray(o.panels))return{spec:null,warnings:["the model returned no spec: its reply had no panels"]};const i=o,h=new Set(w.columns.map(u=>u.id));i.sources!==void 0&&y.push(`the proposal's own sources were ignored: it reads "${w.source}"`);const c=[],m=new Set;for(const[u,A]of i.panels.entries()){const r=ue(A),j=l(r)&&typeof r.id=="string"?`"${r.id}"`:`panels[${u}]`;if(!l(r)){y.push(`panel ${j} is not an object; dropped`);continue}if(!w.kinds.includes(r.kind)){y.push(`panel ${j} is a ${JSON.stringify(r.kind)} panel, which this page cannot draw (${w.kinds.join(", ")}); dropped`);continue}if(r.kind==="html")l(r.options)&&r.options.html!==void 0&&(delete r.options.html,y.push(`panel ${j}: markup from the model is not applied; its text is kept`)),delete r.source;else{r.source===void 0&&(r.source=w.source);const G=z(r.source);if(!(G&&(G.kind==="grid"||G.id===w.source))){y.push(`panel ${j} reads ${JSON.stringify(r.source)}, not "${w.source}" or another panel's grid; dropped`);continue}}const C=X(r).filter(G=>!h.has(G));if(C.length){y.push(`panel ${j} names ${C.map(G=>`"${G}"`).join(", ")}, which "${w.source}" does not have; dropped`);continue}c.push(r),m.add(r.id)}const b={panels:c,sources:{[w.source]:w.definition}};l(i.layout)&&(b.layout=ue(i.layout),Array.isArray(b.layout.windows)&&(b.layout.windows=b.layout.windows.filter(u=>l(u)&&m.has(u.id)))),i.links!==void 0&&(b.links=ue(i.links));const P=F(b);for(const u of P.problems){const A=/^panels\[(\d+)\]/.exec(u.path),r=A?P.badPanels.has(Number(A[1])):u.link!==void 0&&P.badLinks.has(u.link);y.push(`${u.path} ${u.message}${r?"; dropped":""}`)}if(b.panels=b.panels.filter((u,A)=>!P.badPanels.has(A)),b.links!==void 0&&!Array.isArray(b.links))delete b.links;else if(Array.isArray(b.links)){const u=F(b);for(const A of u.problems)A.link!==void 0&&u.badLinks.has(A.link)&&!P.badLinks.has(A.link)&&y.push(`${A.path} ${A.message}; dropped`);b.links=b.links.filter((A,r)=>!u.badLinks.has(r))}if(b.layout&&Array.isArray(b.layout.windows)){const u=F(b);b.layout.windows=b.layout.windows.filter((A,r)=>!u.badWindows.has(r))}return{spec:b,warnings:y}}}),rt("packages/modules/dashboard/index.js",function(s,ae){"use strict";Object.defineProperty(s,"createDashboard",{enumerable:!0,get:function(){return A}}),Object.defineProperty(s,"validateDashboardSpec",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return r}});const ve=ae("packages/core/src/internal/util.js"),F=ve.warnOnce,l=ve.isFunction,ue=ae("packages/modules/dashboard/spec.js"),z=ue.inspectSpec,fe=ue.validateDashboardSpec,J=ue.copySpec,X=ue.sameSpec,ne=ue.isPlain,B=ue.parseSourceRef,L=ue.readRelation,D=ae("packages/modules/dashboard/propose.js"),o=D.proposalRequest,w=D.parseProposal,y=D.checkProposal,i=Object.freeze({createGrid:"LatticeGrid",createHeadlessGrid:"LatticeGrid",createPushdownSource:"LatticeGrid",createChart:"LatticeGrid",createLayout:"LatticeGridLayout",createKPI:"LatticeGridKPI",createCalendar:"LatticeGridCalendar",bindLeaflet:"LatticeGridLeaflet",bindDeck:"LatticeGridDeck"}),h=50;function c(j){const C=globalThis,G={};for(const[_,T]of Object.entries(i)){const p=j[_],v=C[T];G[_]=l(p)?p:v&&l(v[_])?v[_]:null}return G}function m(j){const C=[];return j.createGrid&&C.push("grid"),j.createChart&&j.createHeadlessGrid&&C.push("chart"),j.createKPI&&C.push("kpi"),j.createCalendar&&C.push("calendar"),j.createChart&&j.createHeadlessGrid&&C.push("map"),C.push("html"),C}function b(j){const C=new Map;for(const G of j.slice(0,h))if(!(!G||typeof G!="object"))for(const[_,T]of Object.entries(G)){const p=typeof T=="number"||T===null||T===void 0;C.set(_,(C.has(_)?C.get(_):!0)&&p)}return[...C].map(([G,_])=>_?{field:G,type:"number"}:{field:G})}function P(j,C){const G=new Set,_=(T,p)=>{if(!(p>3)){if(typeof T=="string"&&T!=="")G.add(T);else if(Array.isArray(T))T.forEach(v=>_(v,p+1));else if(ne(T))for(const[v,n]of Object.entries(T))G.add(v),_(n,p+1)}};_(C,0);for(const T of G)for(const p of['"',"'","`"])if(j.includes(`${p}${T}${p}`))return!0;return!1}function u(j){const C=[],G=console.warn;console.warn=(...T)=>{T[0]==="[lattice]"&&C.push(T.slice(1).map(String).join(" ")),G.apply(console,T)};try{return{value:j(),heard:C}}catch(T){return{error:T,heard:C}}finally{console.warn=G}}function A(j,C,G={}){const _=ne(G)?G:{},T=c(_);let p={panels:[]},v=null,n=new Map,t=[],a=[],e=new Map,f=[],d=new Set,E=null,M=null;const W=[];let oe=0;const q=(te,re,le)=>{f.push({id:te,path:re,message:le})},Q=(te,re)=>{F(`dashboard:panel:${te}`,`createDashboard: panel "${te}" ${re}`)},H=(te,re,le)=>{F(`dashboard:link:${te}->${re}`,`createDashboard: the link from "${te}" to "${re}" ${le}`)};let O=new Map;const I=te=>{let re=te;for(let le=0;re&&re.viewsGridOf&&le<64;le++)re=n.get(re.viewsGridOf);return re||te},K=te=>{const re=B(te),le=re&&re.kind==="grid"?re.of:te,pe=n.get(le);return pe&&pe.grid?pe.grid:null},g=te=>{const re={},le={};if(te.rowKey!==void 0&&(re.rowKey=te.rowKey),Array.isArray(te.columns)&&(re.columns=te.columns),te.kind==="rows")le.rows=te.rows,re.columns||(re.columns=b(te.rows));else if(te.kind==="pushdown"){if(!T.createPushdownSource)return{base:re,data:le,refusal:"its source is a pushdown adapter and there is no createPushdownSource on the page (load the grid, or pass options.createPushdownSource)"};const pe={};for(const[we,je]of Object.entries(te))["kind","columns","rowKey"].includes(we)||(pe[we]=je);le.source=T.createPushdownSource(pe)}return{base:re,data:le}},k=(te,re)=>{te.kind==="router"&&(te.router.attach(re,te.predicate,te.route),e.set(re,te.router))},V=(te,re)=>{const le=K(te);if(le)return{grid:le};const pe=B(te),we=pe&&pe.kind==="grid"?pe.of:te,je=p.sources[we];if(!je)return null;if(!T.createHeadlessGrid)return{refusal:"there is no createHeadlessGrid on the page to hold its related source (load the grid, or pass options.createHeadlessGrid)"};const Be=g(je);if(Be.refusal)return{refusal:Be.refusal};const Ue=T.createHeadlessGrid({...Be.base,...Be.data});return re.push(Ue),k(je,Ue),{grid:Ue}},R=te=>{const re=v.payload(te.id),pe=re.ownerDocument.createElement("div");pe.style.width="100%",pe.style.height="100%",re.appendChild(pe);const we=ne(te.options)?te.options:{},je={id:te.id,kind:te.kind,def:te,el:pe,grid:null,viewer:null,owned:[],ownedMap:null,viewsGridOf:null,sourceId:null,rootKind:"own"},Be=[...O.get(te.id)||[]],Ue=be=>{for(const ge of je.owned.reverse())N(ge);pe.remove(),q(`dashboard:panel:${te.id}`,`panels[${p.panels.indexOf(te)}]`,`was not built: ${be}`),Q(te.id,`was not built: ${be}`)},qe=B(te.source);let ot=null;qe&&qe.kind==="named"?(ot=p.sources[qe.id],je.sourceId=qe.id,ot.kind==="grid"?je.viewsGridOf=ot.of:je.rootKind=ot.kind):qe&&(je.viewsGridOf=qe.of),je.viewsGridOf&&(je.rootKind=I(n.get(je.viewsGridOf)).rootKind);const tt=je.viewsGridOf?n.get(je.viewsGridOf).grid:null,he={grid:"createGrid",chart:"createChart",kpi:"createKPI",calendar:"createCalendar",map:{chart:"createChart",leaflet:"bindLeaflet",deckgl:"bindDeck"}[te.binding||"chart"]}[te.kind];if(he&&!T[he]){Ue(`there is no ${he} on the page (load its module, or pass options.${he})`);return}if(te.kind!=="grid"&&te.kind!=="html"&&ot&&ot.kind!=="grid"&&!T.createHeadlessGrid){Ue("there is no createHeadlessGrid on the page to hold its source (load the grid, or pass options.createHeadlessGrid)");return}let ie=null;if(ot&&ot.kind!=="grid"&&(ie=g(ot),ie.refusal)){Ue(ie.refusal);return}const ce=()=>{if(tt)return tt;if(!ie)return null;const be=T.createHeadlessGrid({...ie.base,...we.selection?{selection:"multiple"}:{},...ie.data});return je.owned.push(be),k(ot,be),be},Oe=u(()=>{if(te.kind==="html")return typeof we.html=="string"?pe.innerHTML=we.html:typeof we.text=="string"&&(pe.textContent=we.text),null;if(te.kind==="grid"){let Ee=we;if(ie){for(const ze of["rows","source"])we[ze]!==void 0&&Be.push(`options.${ze} was not used: the panel's source "${je.sourceId}" supplies its rows`);Ee={...ie.base,...we,...ie.data}}else if(tt){const Ge={...(ne(we.source)&&we.source.mode==="derived"?we.source:null)||{},mode:"derived",from:tt};if(ne(Ge.join)&&typeof Ge.join.with=="string"){const Ke=V(Ge.join.with,je.owned);Ke&&Ke.grid?Ge.join={...Ge.join,with:Ke.grid}:(Be.push(`its join to "${Ge.join.with}" was not made: ${Ke?Ke.refusal:"it names no declared source or widget"}`),delete Ge.join)}Ee={...we,source:Ge},we.columns===void 0&&(Ee.columns=tt.columns.all().map(Ke=>({id:Ke.id,field:Ke.field,title:Ke.title,type:Ke.type})))}const Re=T.createGrid(pe,Ee);return je.owned.push(Re),je.grid=Re,ot&&k(ot,Re),Re}const be=ce();if(je.grid=be,te.kind==="kpi")return T.createKPI(pe,be?{...we,grid:be}:we);if(te.kind==="calendar")return T.createCalendar(pe,be?{...we,grid:be}:we);const ge=te.kind==="map"&&te.binding||"chart";if(ge==="chart"){for(const Ee of["grid","container"])we[Ee]!==void 0&&Be.push(`options.${Ee} was not used: the dashboard sets it from the panel's source and window`);return T.createChart({...we,grid:be,container:pe})}if(ge==="leaflet"){const Ee=l(we.map)?we.map(pe):we.map;return l(we.map)&&(je.ownedMap={map:Ee,end:"remove"}),T.bindLeaflet(be,{...we,map:Ee})}const ke=l(we.deck)?we.deck(pe):we.deck;return l(we.deck)&&(je.ownedMap={map:ke,end:"finalize"}),T.bindDeck(be,{...we,deck:ke})});if(Oe.error){Ue(`${he||"the panel"} threw: ${Oe.error&&Oe.error.message}`);return}je.viewer=Oe.value;for(const be of Oe.heard)P(be,we)&&Be.push(`its ${te.kind} refused part of its options: ${be}`);if(Be.length){const be=Be.join("; ");q(`dashboard:panel:${te.id}`,`panels[${p.panels.indexOf(te)}]`,`was built, but ${be}`),Q(te.id,`was built, but ${be}`)}n.set(te.id,je)},N=te=>{const re=e.get(te);re&&(re.detach(te),e.delete(te)),te&&l(te.destroy)&&te.destroy()},$=(te,re)=>{const le=Oe=>{q(`dashboard:link:${te.from}->${te.to}`,`links[${re}]`,`was not made: ${Oe}`),H(te.from,te.to,`was not made: ${Oe}`)},pe=n.get(te.from),we=n.get(te.to);if(!pe||!we){le(`the ${pe?"target":"source"} panel was not built`);return}if(!pe.grid){le(`"${te.from}" has no grid to read a selection from (a ${pe.kind} panel that reads no source)`);return}if(!we.grid){le(`"${te.to}" has no grid to filter (a ${we.kind} panel that reads no source)`);return}if(we.grid===pe.grid){le(`"${te.to}" draws the grid the link starts from, so it would filter its own selection away`);return}const je=L(te.on),Be=e.get(pe.grid),Ue=e.get(we.grid);if(Be&&Ue){if(Be!==Ue){le("the two panels read routes of two different Data Routers, and a relation is drawn within one");return}Be.relate([{from:pe.grid,to:we.grid,on:je}]),a.push({from:te.from,to:te.to,def:te,teardown:()=>{}});return}if(I(pe).rootKind==="pushdown"&&I(we).rootKind==="pushdown"){le("both panels read pushdown sources and no Data Router is shared between them: the rows selected in one engine cannot filter the other engine's query. Route both through one router to relate them");return}if(l(je)){le("a relation function is the Data Router's form and needs both panels on one router; name the columns instead");return}const qe=`dashboard:${te.from}->${te.to}`,ot=I(we).rootKind==="pushdown",{from:tt,to:he}=je,ie=()=>{const Oe=new Set;for(const ge of pe.grid.selection.rows()){const ke=ge&&ge.data!==void 0?ge.data:ge;ke&&typeof ke=="object"&&Oe.add(ke[tt])}if(!Oe.size){we.grid.filters.where(qe,null);return}const be={deps:[he]};ot&&(be.condition={col:he,op:"in",value:[...Oe]}),we.grid.filters.where(qe,ge=>Oe.has(ge[he]),be)},ce=pe.grid.on("selection:changed",ie);ie(),a.push({from:te.from,to:te.to,def:te,teardown:()=>{ce(),n.get(te.to)===we&&we.grid.filters.where(qe,null)}})},S=te=>{const re=n.get(te);if(re){for(const le of[...n.values()])le.viewsGridOf===te&&(S(le.id),v&&v.windows().includes(le.id)&&v.close(le.id));for(const le of a.filter(pe=>pe.from===te||pe.to===te))le.teardown();a=a.filter(le=>le.from!==te&&le.to!==te),Y(re),n.delete(te),t=t.filter(le=>le!==te)}},Y=te=>{te.viewer&&te.viewer!==te.grid&&l(te.viewer.destroy)&&te.viewer.destroy(),te.ownedMap&&te.ownedMap.map&&l(te.ownedMap.map[te.ownedMap.end])&&te.ownedMap.map[te.ownedMap.end]();for(const re of[...te.owned].reverse())N(re);te.el&&te.el.parentNode&&te.el.remove()},Z=()=>{M&&v&&v.restore(M.seq[M.index]),M=null;for(const te of a)te.teardown();a=[];for(const te of[...t].reverse()){const re=n.get(te);re&&Y(re)}E&&E(),E=null,v&&v.destroy(),v=null,n=new Map,t=[],e=new Map},x=(te,re)=>{if(!v||!ne(te)||te.id==null||String(te.id)==="")return!1;const le=String(te.id);if(n.has(le))return!1;const pe=J(te);if(p.panels.push(pe),!v.windows().includes(le)){const we={...ne(re)?re:{},id:le};we.title===void 0&&typeof pe.title=="string"&&(we.title=pe.title),v.add(we)}return R(pe),n.has(le)?(t.includes(le)||t.push(le),!0):(v.windows().includes(le)&&v.close(le),p.panels=p.panels.filter(we=>we!==pe),!1)},ee=(te,re)=>{if(!v||!ne(te)||te.id==null)return!1;const le=String(te.id);if(!n.has(le))return!1;const pe=t.indexOf(le);S(le);const we=J(te),je=p.panels.findIndex(Be=>ne(Be)&&String(Be.id)===le);return je>=0?p.panels[je]=we:p.panels.push(we),ne(re)&&v.windows().includes(le)&&v.move(le,re),R(we),n.has(le)?(t.includes(le)||t.splice(pe<0?t.length:pe,0,le),!0):!1},se=te=>{if(!v)return!1;const re=String(te),le=n.has(re)||v.windows().includes(re);return S(re),v.windows().includes(re)&&v.close(re),p.panels=p.panels.filter(pe=>!(ne(pe)&&String(pe.id)===re)),le},de=te=>{f=[],d=new Set;const re=z(te);if(re.fatal){p={panels:[]},q("dashboard:spec","",re.fatal),F("dashboard:spec",`createDashboard: ${re.fatal}; a spec is { layout, panels, sources, links }. Nothing was built.`);return}p=J(te),ne(p.sources)||(p.sources={}),Array.isArray(p.links)||(p.links=[]);for(const he of Object.keys(p.sources))re.badSources.has(he)||d.add(he);O=new Map;for(const he of re.problems){const ie=/^panels\[(\d+)\]/.exec(he.path),ce=he.link!==void 0?p.links[he.link]:null;if(he.panel!==void 0&&ie&&re.badPanels.has(Number(ie[1])))q(`dashboard:panel:${he.panel}`,he.path,`was not built: ${he.message}`),Q(he.panel,`was not built: ${he.path} ${he.message}`);else if(he.panel!==void 0)O.set(he.panel,[...O.get(he.panel)||[],`${he.path} ${he.message}`]);else if(ne(ce)&&typeof ce.from=="string"&&typeof ce.to=="string"){const Oe=!re.badLinks.has(he.link);q(`dashboard:link:${ce.from}->${ce.to}`,he.path,Oe?he.message:`was not made: ${he.message}`),H(ce.from,ce.to,`${Oe?"was made, but":"was not made:"} ${he.path} ${he.message}`)}else q(`dashboard:spec:${he.path}`,he.path,he.message),F(`dashboard:spec:${he.path}`,`createDashboard: spec ${he.path} ${he.message}`)}if(!j||!l(j.appendChild)){q("dashboard:el","","the element is not an element"),F("dashboard:el","createDashboard: the first argument is not an element to mount on. Nothing was built.");return}if(!T.createLayout){q("dashboard:layout","layout","there is no createLayout on the page"),F("dashboard:layout","createDashboard: there is no createLayout on the page; load modules/layout or pass options.createLayout. Nothing was built.");return}const le=p.panels.filter((he,ie)=>!re.badPanels.has(ie)),pe=ne(p.layout)?p.layout:{},we=new Map;(Array.isArray(pe.windows)?pe.windows:[]).forEach((he,ie)=>{re.badWindows.has(ie)||we.set(he.id,he)});const je=le.map(he=>{const ie={...we.get(he.id)||{},id:he.id};return ie.title===void 0&&typeof he.title=="string"&&(ie.title=he.title),ie}),{windows:Be,...Ue}=pe;v=T.createLayout(j,{...Ue,windows:je}),E=v.on("window:closed",he=>S(he.id));const qe=he=>{const ie=B(he.source);if(ie&&ie.kind==="grid")return ie.of;const ce=ie?p.sources[ie.id]:null;return ce&&ce.kind==="grid"?ce.of:null},ot=he=>{const ie=ne(he.options)?he.options.source:null;if(!ne(ie)||ie.mode!=="derived"||!ne(ie.join))return[];const ce=B(ie.join.with);return ce&&ce.kind==="grid"?[ce.of]:[]},tt=[...le];for(;tt.length;){const he=tt.findIndex(Oe=>![qe(Oe),...ot(Oe)].filter(Boolean).some(ge=>tt.some(ke=>ke.id===ge))),[ie]=tt.splice(Math.max(he,0),1),ce=qe(ie);ce&&!n.has(ce)?(q(`dashboard:panel:${ie.id}`,`panels[${p.panels.indexOf(ie)}].source`,`was not built: "${ce}", whose grid it views, was not built`),Q(ie.id,`was not built: "${ce}", whose grid it views, was not built`)):R(ie),!n.has(ie.id)&&v.windows().includes(ie.id)&&v.close(ie.id)}t=p.panels.map(he=>he&&he.id).filter(he=>n.has(he)),p.links.forEach((he,ie)=>{re.badLinks.has(ie)||$(he,ie)})},ye=()=>{const te=v?v.getLayout():{windows:[]},re=new Map(te.windows.map(qe=>[qe.id,qe])),le=ne(p.layout)?p.layout:{},pe=new Map((Array.isArray(le.windows)?le.windows:[]).filter(qe=>ne(qe)).map(qe=>[qe.id,qe])),we=t.map(qe=>{const ot=J(pe.get(qe)||{id:qe}),tt=re.get(qe);return tt&&Object.assign(ot,{xPos:tt.xPos,yPos:tt.yPos,xSize:tt.xSize,ySize:tt.ySize}),ot}),{windows:je,...Be}=le,Ue={};for(const qe of Object.keys(p.sources||{}))d.has(qe)&&(Ue[qe]=J(p.sources[qe]));return{layout:{...J(Be),windows:we},panels:t.map(qe=>J(n.get(qe).def)),sources:Ue,links:a.map(qe=>J(qe.def))}},xe=te=>{const re=p.sources[te];if(Array.isArray(re.columns))return re.columns.filter(ne).map(pe=>({id:String(pe.id??pe.field),type:pe.type||"text"}));const le=[...n.values()].find(pe=>pe.grid&&(pe.sourceId===te||re.kind==="grid"&&pe.id===re.of));return le?le.grid.columns.all().map(pe=>({id:pe.id,type:pe.type||"text"})):re.kind==="rows"?b(re.rows).map(pe=>({id:pe.field,type:pe.type||"text"})):[]},me=(te,re)=>{const le=p.sources[te];if(le.kind==="rows")return le.rows.slice(0,re);const pe=[...n.values()].find(we=>we.grid&&we.sourceId===te);return pe?pe.grid.rows.data().slice(0,re):[]},Ne=te=>(F("dashboard:present",`dashboard.present: ${te}; nothing is presented.`),!1);de(C);const Ae={get el(){return j},get layout(){return v},get presenting(){return M?M.seq[M.index]:null},spec(){return ye()},apply(te){const re=e.size>0;return Z(),de(te),re&&e.size&&F("dashboard:router",`dashboard.apply: ${e.size} grid(s) read a Data Router route and were rebuilt; a router does not re-send rows to a route attached after they arrived, so they fill from its next load() or push().`),Ae.problems()},panels(){return[...t]},panel(te){const re=n.get(te);return re?{id:re.id,kind:re.kind,el:re.el,grid:re.grid,viewer:re.viewer}:null},problems(){return f.map(te=>({...te}))},async propose(te,re={}){const le=_.ai,pe=l(le)?le:le&&l(le.ask)?le.ask:null;if(!pe)return F("dashboard:propose","dashboard.propose: there is no AI on this dashboard (options.ai.ask); nothing was asked. Load modules/ai and pass the same ask() createAI takes."),{spec:null,warnings:["there is no AI on this dashboard (options.ai.ask); nothing was asked"]};const we=ne(re)?re:{},je=we.source;if(typeof je!="string"||!d.has(je)){const he=`"${je}" is not a usable source of this dashboard; nothing was asked`;return F("dashboard:proposal",`dashboard.propose: the proposal has problems, each in the returned warnings: ${he}`),{spec:null,warnings:[he]}}const Be=xe(je),Ue=Number.isFinite(we.maxRows)?Math.max(0,we.maxRows):h,qe=o(String(te),{source:je,columns:Be,kinds:m(T),rows:we.rows===!0?me(je,Ue):void 0,signal:we.signal}),ot=await pe(qe),tt=y(w(ot),{source:je,definition:p.sources[je],columns:Be,kinds:m(T)});return tt.warnings.length&&F("dashboard:proposal",`dashboard.propose: the proposal has problems, each in the returned warnings: ${tt.warnings[0]}`),tt},saveView(te){if(typeof te!="string"||te.trim()==="")return F("dashboard:view-name",`dashboard.saveView: ${JSON.stringify(te)} is not a view name; nothing was saved.`),null;const re={},le={};for(const je of t){const Be=n.get(je);Be.kind==="grid"&&Be.grid?re[je]=Be.grid.state.get():Be.kind==="calendar"&&Be.viewer&&l(Be.viewer.getState)&&(le[je]=Be.viewer.getState())}const pe=W.findIndex(je=>je.name===te),we={id:pe>=0?W[pe].id:`view-${++oe}`,name:te,spec:ye(),grids:re,calendars:le};return pe>=0?W[pe]=we:W.push(we),J(we)},views(){return W.map(te=>J(te))},applyView(te){const re=typeof te=="string"?W.find(pe=>pe.id===te):te;if(!ne(re)||!ne(re.spec))return F("dashboard:view",`dashboard.applyView: ${JSON.stringify(typeof te=="string"?te:typeof te)} is not a saved view; nothing was applied.`),!1;const le=pe=>({...pe,layout:ne(pe.layout)?{...pe.layout,windows:(Array.isArray(pe.layout.windows)?pe.layout.windows:[]).map(we=>{const{xPos:je,yPos:Be,xSize:Ue,ySize:qe,...ot}=we;return ot})}:void 0});v&&X(le(ye()),le(J(re.spec)))?v.setLayout(re.spec.layout.windows):Ae.apply(re.spec);for(const[pe,we]of Object.entries(ne(re.grids)?re.grids:{})){const je=n.get(pe);je&&je.kind==="grid"&&je.grid&&je.grid.state.apply(we)}for(const[pe,we]of Object.entries(ne(re.calendars)?re.calendars:{})){const je=n.get(pe);je&&je.kind==="calendar"&&je.viewer&&l(je.viewer.setState)&&je.viewer.setState(we)}return!0},present(te={}){const re=ne(te)?te:{};if(!v||!t.length)return Ne("the dashboard has no panels");let le=[...t];if(Array.isArray(re.panels)){const we=re.panels.filter(je=>!n.has(je));if(we.length)return Ne(`${we.map(je=>JSON.stringify(je)).join(", ")} is not a built panel`);if(le=[...re.panels],!le.length)return Ne("the list of panels is empty")}const pe=Number.isFinite(re.from)?Math.min(Math.max(Math.trunc(re.from),0),le.length-1):0;return M={seq:le,index:pe},v.maximise(le[pe]),!0},step(te=1){if(!M||!v)return-1;const re=Math.min(Math.max(M.index+Math.trunc(Number(te)||0),0),M.seq.length-1);return M.index=re,v.maximise(M.seq[re]),re},stopPresenting(){return M?(v&&v.restore(M.seq[M.index]),M=null,!0):!1},applyConfig(te){const re=ne(te)?te:{},le={added:0,updated:0,removed:0};if(!v)return le;for(const we of Array.isArray(re.remove)?re.remove:[])se(we)&&(le.removed+=1);const pe=we=>{if(!ne(we)||!ne(we.panel))return;const je=we.panel.id!=null?String(we.panel.id):null;je!==null&&(n.has(je)?ee(we.panel,we.window)&&(le.updated+=1):x(we.panel,we.window)&&(le.added+=1))};for(const we of Array.isArray(re.update)?re.update:[])pe(we);for(const we of Array.isArray(re.add)?re.add:[])pe(we);return le},destroy(){Z()}};return Ae}const r=A}),rt("packages/modules/designer/messages.js",function(s,ae){"use strict";Object.defineProperty(s,"MESSAGES",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"resolveMessages",{enumerable:!0,get:function(){return ue}});const F=ae("packages/core/src/internal/util.js").isFunction,l=Object.freeze({"designer.canvas":"Dashboard canvas","designer.chrome":"Designer tools","designer.page":"Page {n}","a11y.designer.edit":"Edit mode","a11y.designer.view":"View mode","designer.toolbar":"Designer toolbar","designer.pages":"Pages","designer.mode.toEdit":"Edit","designer.mode.toView":"View","designer.mode.label":"Edit mode","designer.addNote":"Add text","designer.addGrid":"Add grid","designer.shortcuts":"Keyboard shortcuts","designer.shortcuts.help":"Show keyboard shortcuts","designer.dialog.close":"Close","designer.shortcut.toggleMode":"Switch between edit and view mode","designer.shortcut.addNote":"Add a text widget","designer.shortcut.addGrid":"Add a grid widget","designer.shortcut.nextRegion":"Move focus to the next region (toolbar, palette, canvas, properties)","designer.shortcut.previousRegion":"Move focus to the previous region","designer.shortcut.help":"Show or hide this list","designer.shortcut.moveWidget":"On a widget’s drag handle: Space or Enter grabs, arrow keys move, Space or Enter drops, Escape cancels","designer.shortcut.resizeWidget":"On a widget’s resize handle: Space or Enter grabs, arrow keys resize, Space or Enter drops, Escape cancels","designer.kind.chart":"Chart","designer.kind.grid":"Grid","designer.kind.html":"Text","designer.kind.kpi":"KPI","designer.kind.map":"Map","designer.kind.widget":"Widget","designer.region.toolbar":"Designer toolbar","designer.region.canvas":"Dashboard canvas","a11y.designer.added":"{kind} added: {title}","a11y.designer.page":"Page {title} selected","a11y.designer.region":"{name} region","a11y.designer.noSource":"No data source to add a grid from","a11y.designer.theme":"Theme: {theme}","designer.rail.left":"Palette and data","designer.rail.right":"Properties","designer.rail.collapse":"Collapse {name}","designer.rail.expand":"Expand {name}","designer.rail.section.palette":"Palette","designer.rail.section.data":"Data","a11y.designer.rail.open":"{name} opened","a11y.designer.rail.closed":"{name} closed","designer.palette":"Widget palette","designer.region.palette":"Widget palette","designer.palette.search":"Search widgets","designer.palette.source":"Source for new widgets","designer.palette.empty":"No widget matches","designer.palette.group.widgets":"Widgets","designer.palette.group.filters":"Filters","designer.palette.family.comparison":"Comparison","designer.palette.family.trend":"Trend","designer.palette.family.composition":"Composition","designer.palette.family.distribution":"Distribution","designer.palette.family.flow":"Flow","designer.palette.family.hierarchy":"Hierarchy","designer.palette.family.geo":"Geo","designer.palette.family.specialist":"Specialist","designer.palette.family.statistics":"Statistics","designer.palette.filter.list":"List filter","designer.palette.filter.range":"Range filter","designer.palette.filter.dateRange":"Date range filter","designer.palette.filter.search":"Search filter","designer.palette.needs.source":"needs a data source","designer.palette.needs.fields":"needs a field","designer.palette.needs.date":"needs a date field","designer.palette.needs.twoDate":"needs two date fields","designer.palette.needs.numeric":"needs a numeric field","designer.palette.needs.twoNumeric":"needs two numeric fields","designer.palette.needs.fourNumeric":"needs four numeric fields","designer.palette.needs.categorical":"needs a categorical field","designer.palette.needs.twoCategorical":"needs two categorical fields","designer.palette.needs.text":"needs a text field","designer.palette.needs.geometry":"needs a geometry field","designer.palette.needs.location":"needs a geometry or latitude and longitude fields","designer.palette.disabled":"{name} cannot be added: {reason}","designer.palette.unavailable":"{name} is not available","designer.palette.limit":"This page already holds {limit} widgets","designer.undo":"Undo","designer.redo":"Redo","designer.page.add":"Add page","designer.page.duplicate":"Duplicate page","designer.page.copy":"Copy of {title}","designer.page.rename":"Rename page","designer.page.delete":"Delete page","designer.page.cancel":"Cancel","designer.page.confirm":"Delete {title}?","designer.page.hasWidgets":"It has {n} widgets.","a11y.designer.page.added":"Page {title} added","a11y.designer.page.renamed":"Page renamed to {title}","a11y.designer.page.removed":"Page {title} removed","designer.lock":"Locked by guardrails","designer.data.panel":"Data","designer.data.search":"Search fields","designer.data.sources":"Sources","designer.data.relationships":"Relationships","designer.data.reachable":"Reachable from {source}: {sources}","designer.data.noReachable":"No sources related to {source}.","designer.data.empty":"No fields match {query}.","designer.data.field.add":"Add {field} to the canvas","designer.data.type.number":"Number","designer.data.type.currency":"Currency","designer.data.type.percent":"Percent","designer.data.type.date":"Date","designer.data.type.datetime":"Date & time","designer.data.type.boolean":"Boolean","designer.data.type.text":"Text","designer.data.type.list":"List","designer.data.type.geometry":"Geometry","designer.widget.name":"{kind}: {title}","designer.widget.selected":"{kind}: {title}, selected","a11y.designer.selected":"{name} selected","a11y.designer.removed":"{name} removed","designer.kind.kpi":"KPI","designer.kind.calendar":"Calendar","designer.kind.map":"Map","designer.kind.panel":"Panel","designer.properties":"Properties","designer.properties.empty":"Select a widget to edit its properties.","designer.prop.widget":"Widget","designer.prop.source":"Source","designer.prop.type":"Chart type","designer.prop.title":"Title","designer.section.data":"Data","designer.section.format":"Formatting","designer.section.fields":"Fields","designer.field.none":"(none)","designer.field.pick":"Field {field}: drag it to a role, or press to pick it up","designer.field.picked":"Picked up {field}. Press Enter on a role to bind it; Escape cancels.","designer.move.earlier":"Move {item} earlier","designer.move.later":"Move {item} later","designer.problems":"Problems","designer.role.x":"Category","designer.role.y":"Measure","designer.role.measures":"Measures","designer.role.series":"Series","designer.role.size":"Size","designer.role.source":"From","designer.role.target":"To","designer.role.geometry":"Region","designer.role.lat":"Latitude","designer.role.lon":"Longitude","designer.role.measure":"Measure","designer.role.columns":"Columns","designer.role.date":"Date","designer.role.label":"Label","designer.role.start":"Start","designer.role.end":"End","designer.role.sparkline":"Sparkline","designer.role.sparklineOrder":"Sparkline order","designer.agg":"{role} aggregation","designer.agg.default":"Automatic","designer.agg.sum":"Sum","designer.agg.avg":"Average","designer.agg.min":"Minimum","designer.agg.max":"Maximum","designer.agg.count":"Count","designer.agg.countDistinct":"Distinct count","designer.agg.median":"Median","designer.bucket":"Date bucket","designer.bucket.of":"{role} date bucket","designer.bucket.none":"None","designer.bucket.day":"Day","designer.bucket.week":"Week","designer.bucket.month":"Month","designer.bucket.quarter":"Quarter","designer.bucket.year":"Year","designer.opt.title":"Title","designer.opt.scheme":"Colour scheme","designer.opt.default":"Default","designer.opt.palette":"Colours (theme override)","designer.opt.legend":"Legend","designer.opt.labels":"Data labels","designer.opt.tooltip":"Tooltip","designer.opt.axis.x.title":"X axis title","designer.opt.axis.x.format":"X axis format","designer.opt.axis.y.title":"Y axis title","designer.opt.axis.y.format":"Y axis number format","designer.opt.stack":"Stacking","designer.opt.stack.true":"Stacked","designer.opt.stack.percent":"100% stacked","designer.opt.curve":"Line shape","designer.opt.projection":"Projection","designer.opt.diverging":"Diverging colours","designer.opt.maxRadius":"Largest bubble radius","designer.opt.selection":"Selection","designer.opt.pivot.enabled":"Pivot","designer.opt.grandTotalRow":"Grand total row","designer.opt.groupFooter":"Group totals","designer.opt.text":"Text","designer.opt.tiles.0.label":"Tile label","designer.opt.tiles.0.format":"Number format","designer.opt.tiles.0.baseline":"Compare with","designer.opt.tiles.0.delta":"Comparison shown as","designer.opt.tiles.0.target":"Target","designer.col.layout.hidden":"hidden","designer.col.layout.width":"width","designer.col.format":"format","designer.col.sort":"sort","designer.col.sort.asc":"Ascending","designer.col.sort.desc":"Descending","designer.col.group":"group by","designer.col.pivot":"pivot on","designer.col.total":"total","designer.calc.panel":"Calculated fields","designer.calc.heading":"Calculated fields","designer.calc.source":"Source","designer.calc.name":"Field name","designer.calc.expression":"Expression","designer.calc.placeholder":"e.g. IF(revenue > 100, revenue * 0.9, revenue)","designer.calc.suggestions":"Suggestions","designer.calc.preview":"Preview of the first rows","designer.calc.fields":"Calculated fields in use","designer.calc.type":"Result type: {type}","designer.calc.add":"Add field","designer.calc.save":"Save field","designer.calc.edit":"Edit","designer.calc.remove":"Remove","designer.calc.editField":"Edit {id}","designer.calc.removeField":"Remove {id}","designer.calc.empty":"(empty)","designer.calc.rowError":"Error: {error}","designer.calc.didYouMean":' (did you mean "{name}"?)',"designer.calc.refused":"not applied: {reason}","designer.calc.needName":"a calculated field needs a name","designer.calc.exists":'a field called "{id}" already exists',"designer.calc.noSource":"there is no source to add a calculated field to","designer.chart.switched":"Changed to {type}.","designer.chart.dropped":"Changed to {type}; dropped {roles}.","designer.data.derived":"Derived grids","designer.data.derived.lineage":"←","designer.data.derived.hidden":"hidden","designer.data.derived.show":"Show","designer.derived.engine":"Engine: {engine}","designer.derived.step.filter":"Filter","designer.derived.step.group":"Group","designer.derived.step.pivot":"Pivot","designer.derived.step.join":"Join","designer.derived.step.sort":"Sort","designer.derived.step.topN":"Top N","designer.derived.step.refused":"{step} refused by {engine}","designer.rail.section.assist":"Assist","designer.assist":"AI assistant","designer.assist.prompt":"Ask the AI assistant","designer.assist.placeholder":"Describe what to add or change","designer.assist.propose":"Propose","designer.assist.preview":"Proposed changes","designer.assist.accept":"Accept","designer.assist.reject":"Reject","designer.assist.removed":"{title} (to be removed)","designer.assist.working":"Asking the assistant…","designer.assist.problems":"Problems","designer.pushdown.limits":"What the engine cannot do","designer.pushdown.engine":"Computed in the engine ({adapter}) over every row, not the loaded window.","designer.pushdown.pending":"Asking the engine ({adapter})…","designer.pushdown.client":"Computed in the client: {reason}","designer.pushdown.noReason":"the engine could not answer","designer.pushdown.refused":"{name} is unavailable: {reason}","designer.pushdown.refusedStep":"The {step} step is refused: {reason}","a11y.designer.assist.proposed":"{added} added, {changed} changed, {removed} removed; {problems} refused","designer.filterbar":"Filters","designer.filterbar.context":"Filters applied","designer.filterbar.clearAll":"Clear all","designer.filter.value":"{field} value","designer.filter.list.placeholder":"Comma-separated values","designer.filter.min":"{field} minimum","designer.filter.max":"{field} maximum","designer.filter.from":"{field} from","designer.filter.to":"{field} to","designer.filter.remove":"Remove {field} filter","designer.filter.scope":"Filter scope","designer.filter.scope.page":"This page","designer.filter.scope.global":"All pages","designer.filter.type":"Filter type","designer.filter.source":"Filter source","designer.filter.field":"Filter field","designer.filter.add":"Add filter","designer.filter.contains":"contains","designer.filter.preset":"{field} date preset","designer.filter.preset.last7":"Last 7 days","designer.filter.preset.last30":"Last 30 days","designer.filter.preset.last90":"Last 90 days","designer.filter.preset.thisMonth":"This month","designer.filter.preset.thisQuarter":"This quarter","designer.filter.preset.thisYear":"This year","designer.filter.preset.custom":"Custom","designer.clickFilter":"Clicking this filters","designer.clickFilter.none":"Doesn't filter other widgets","designer.clickFilter.all":"All widgets","designer.clickFilter.chosen":"Chosen widgets","designer.clickFilter.on":"Relate by field"});function ue(z){const fe=(X,ne)=>X.replace(/\{(\w+)\}/g,(B,L)=>ne&&L in ne?String(ne[L]):B),J=(X,ne)=>fe(l[X]||X,ne);return!z||!F(z.t)?J:(X,ne)=>{const B=z.t(X,ne);return typeof B=="string"&&B!==X?B:J(X,ne)}}}),rt("packages/modules/designer/a11y.js",function(s,ae){"use strict";Object.defineProperty(s,"REGION_ORDER",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"firstTabbable",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"comboOf",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"auditChrome",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"createA11y",{enumerable:!0,get:function(){return y}});const ve=ae("packages/core/src/internal/util.js"),F=ve.warnOnce,l=ve.isFunction;let ue=0;const z=Object.freeze({toolbar:0,palette:10,canvas:20,properties:30,data:40,filters:50});function fe(i){if(!i||typeof i.getAttribute!="function"||i.hasAttribute("disabled")||i.hasAttribute("hidden"))return!1;const h=i.getAttribute("tabindex");if(h!==null)return Number(h)>=0;const c=String(i.tagName||"").toLowerCase();return c==="button"||c==="input"||c==="select"||c==="textarea"||c==="a"&&i.hasAttribute("href")}function J(i){for(const h of i.children||[]){if(h.hasAttribute&&h.hasAttribute("hidden"))continue;if(fe(h))return h;const c=J(h);if(c)return c}return null}function X(i,h){for(let c=i;c&&c!==h;c=c.parentNode)if(c.hasAttribute&&c.hasAttribute("hidden"))return!0;return!1}function ne(i){const c=(typeof i.code=="string"&&/^Key[A-Z]$/.test(i.code)?i.code.slice(3):null)||(typeof i.key=="string"&&i.key.length===1?i.key.toUpperCase():i.key);return[...[i.ctrlKey&&"Ctrl",i.altKey&&"Alt",i.shiftKey&&"Shift",i.metaKey&&"Meta"].filter(Boolean),c].join("+")}const B=["button","tab","link","checkbox","radio","switch","menuitem","option","combobox","textbox","slider","spinbutton"],L=["dialog","toolbar","tablist","region","group","listbox","menu","tree","grid"];function D(i,h){const c=i.getAttribute("aria-label");if(c&&c.trim())return c.trim();const m=i.getAttribute("aria-labelledby");if(m){const P=m.split(/\s+/).map(u=>{const A=o(h).find(r=>r.id===u);return A?String(A.textContent||"").trim():""}).join(" ").trim();if(P)return P}const b=String(i.textContent||"").trim();return b||(i.getAttribute("title")||i.getAttribute("alt")||"").trim()}function o(i){const h=[];for(const c of i.children||[])c.hasAttribute("hidden")||String(c.tagName).toLowerCase()==="style"||h.push(c,...o(c));return h}function w(i){const h=[],c=A=>`${String(A.tagName).toLowerCase()}${A.className?`.${String(A.className).split(/\s+/)[0]}`:""}`,m=(A,r,j)=>h.push({rule:A,element:c(r),message:j}),b=o(i),P=new Map;for(const A of b){const r=String(A.tagName).toLowerCase(),j=A.getAttribute("role");if(A.id&&P.set(A.id,(P.get(A.id)||0)+1),(r==="button"||r==="select"||r==="textarea"||r==="input"&&A.getAttribute("type")!=="hidden"||r==="a"&&A.hasAttribute("href")||j&&B.includes(j))&&!D(A,i)&&m("name",A,"a control has no accessible name"),j&&L.includes(j)&&j!=="group"&&j!=="region"&&!D(A,i)&&m("name",A,`a ${j} has no accessible name`),(j==="group"||j==="region")&&!A.getAttribute("aria-label")&&!A.getAttribute("aria-labelledby")&&m("name",A,`a ${j} has no accessible name`),j==="dialog"&&A.getAttribute("aria-modal")!=="true"&&m("dialog",A,"a dialog is not aria-modal"),j==="tab"&&((!A.parentNode||A.parentNode.getAttribute("role")!=="tablist")&&m("tab",A,"a tab is not in a tablist"),A.getAttribute("aria-selected")===null&&m("tab",A,"a tab does not say whether it is selected")),j==="toolbar"||j==="tablist"){const G=o(A).filter(_=>_.getAttribute("tabindex")==="0").length;G!==1&&m("roving",A,`a ${j} has ${G} tab stops; it must have exactly one`)}}for(const[A,r]of P)r>1&&h.push({rule:"id",element:`#${A}`,message:`the id is used ${r} times`});return b.find(A=>A.getAttribute("role")==="status"&&A.getAttribute("aria-live")==="polite")||h.push({rule:"live",element:"root",message:'there is no polite live region (role="status")'}),h}function y({root:i,live:h,t:c}){const m=i.ownerDocument,b=v=>{if(typeof v!="string"||!v)return;h.textContent="";const n=m.createElement("span");n.textContent=v,h.appendChild(n)},P=new Map,u=Object.freeze({register(v){if(!v||typeof v.id!="string"||typeof v.keys!="string"||typeof v.description!="string")return F("designer:shortcut","designer.shortcuts.register: a shortcut is { id, keys, description, run? } with string id, keys and description; nothing was registered."),()=>{};const n={id:v.id,keys:v.keys,description:v.description,run:l(v.run)?v.run:void 0};return P.set(n.id,n),()=>{P.get(n.id)===n&&P.delete(n.id)}},list(){return[...P.values()].map(({id:v,keys:n,description:t})=>({id:v,keys:n,description:t}))}}),A=new Map,r=Object.freeze({register(v,n,t={}){if(typeof v!="string"||!n)return F("designer:region","designer.regions.register: a region is a string name and an element; nothing was registered."),()=>{};const a={name:v,el:n,order:typeof t.order=="number"?t.order:z[v]??100,label:typeof t.label=="string"?t.label:v};return A.set(v,a),()=>{A.get(v)===a&&A.delete(v)}},list(){return[...A.values()].sort((v,n)=>v.order-n.order).map(v=>v.name)},focus(v){const n=A.get(v);if(!n||X(n.el,i))return!1;const t=J(n.el)||(n.el.getAttribute("tabindex")!==null?n.el:null);return t?(t.focus(),b(c("a11y.designer.region",{name:n.label})),!0):!1}}),j=v=>{const n=[...A.values()].sort((e,f)=>e.order-f.order).filter(e=>!X(e.el,i));if(!n.length)return!1;const t=m.activeElement;let a=-1;n.forEach((e,f)=>{(e.el===t||t&&e.el.contains(t))&&(a=f)}),a<0&&(a=v>0?-1:0);for(let e=1;e<=n.length;e+=1){const f=n[(a+v*e+n.length*e)%n.length];if(r.focus(f.name))return!0}return!1};u.register({id:"region.next",keys:"F6",description:c("designer.shortcut.nextRegion"),run:()=>j(1)}),u.register({id:"region.previous",keys:"Shift+F6",description:c("designer.shortcut.previousRegion"),run:()=>j(-1)});const C=v=>{if(v.defaultPrevented)return;const n=ne(v);for(const t of P.values())if(t.run&&t.keys===n){v.preventDefault&&v.preventDefault(),t.run(v);return}};i.addEventListener("keydown",C);let G=null,_=null;const T=()=>{G&&(G.remove(),G=null,_&&_.focus&&i.contains(_)&&_.focus(),_=null)},p=()=>{if(G)return;_=m.activeElement,G=m.createElement("div"),G.className="lattice-designer-scrim";const v=m.createElement("div");v.className="lattice-designer-dialog",v.setAttribute("role","dialog"),v.setAttribute("aria-modal","true"),ue+=1,v.setAttribute("aria-labelledby",`lattice-designer-shortcuts-${ue}`);const n=m.createElement("h2");n.id=`lattice-designer-shortcuts-${ue}`,n.textContent=c("designer.shortcuts");const t=m.createElement("dl");for(const{keys:e,description:f}of u.list()){const d=m.createElement("dt");d.textContent=e;const E=m.createElement("dd");E.textContent=f,t.appendChild(d),t.appendChild(E)}const a=m.createElement("button");a.type="button",a.className="lattice-designer-button lattice-designer-button--primary",a.textContent=c("designer.dialog.close"),a.addEventListener("click",T),v.addEventListener("keydown",e=>{e.key==="Escape"?(e.preventDefault(),e.stopPropagation(),T()):e.key==="Tab"&&(e.preventDefault(),a.focus())}),v.appendChild(n),v.appendChild(t),v.appendChild(a),G.appendChild(v),i.appendChild(G),a.focus()};return u.register({id:"help",keys:"Alt+Shift+K",description:c("designer.shortcut.help"),run:()=>G?T():p()}),{announce:b,shortcuts:u,regions:r,showShortcuts:p,hideShortcuts:T,destroy(){i.removeEventListener("keydown",C),G&&G.remove(),G=null,P.clear(),A.clear()}}}}),rt("packages/modules/designer/rails.js",function(s,ae){"use strict";Object.defineProperty(s,"railsCss",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"createRails",{enumerable:!0,get:function(){return ne}});const F=ae("packages/modules/dashboard/spec.js").isPlain,ue=ae("packages/core/src/internal/util.js").isFunction,z=1100,fe=900,J=()=>`
|
|
15
|
-
.lattice-designer{position:relative;display:grid;box-sizing:border-box;overflow:hidden;
|
|
14
|
+
${r}`,messages:[{role:"system",content:fe},{role:"user",content:r}],schema:k};return v.rows&&(m.rows=v.rows),v.signal&&(m.signal=v.signal),m}function W(i){try{return JSON.parse(i)}catch{}const v=i.indexOf("{"),k=i.lastIndexOf("}");if(v>=0&&k>v)try{return JSON.parse(i.slice(v,k+1))}catch{}return null}function L(i){let v=i;if(typeof i=="string")v=W(i);else if(l(i)){const k=i;k.structured!==void 0?v=k.structured:Array.isArray(k.panels)?v=k:l(k.spec)?v=k.spec:typeof k.text=="string"?v=W(k.text):typeof k.content=="string"&&(v=W(k.content))}return l(v)&&l(v.spec)&&!Array.isArray(v.panels)&&(v=v.spec),l(v)&&Array.isArray(v.panels)?v:null}function _(i,v){const k=[];if(!l(i)||!Array.isArray(i.panels))return{spec:null,warnings:["the model returned no spec: its reply had no panels"]};const r=i,m=new Set(v.columns.map(u=>u.id));r.sources!==void 0&&k.push(`the proposal's own sources were ignored: it reads "${v.source}"`);const c=[],b=new Set;for(const[u,E]of r.panels.entries()){const d=de(E),w=l(d)&&typeof d.id=="string"?`"${d.id}"`:`panels[${u}]`;if(!l(d)){k.push(`panel ${w} is not an object; dropped`);continue}if(!v.kinds.includes(d.kind)){k.push(`panel ${w} is a ${JSON.stringify(d.kind)} panel, which this page cannot draw (${v.kinds.join(", ")}); dropped`);continue}if(d.kind==="html")l(d.options)&&d.options.html!==void 0&&(delete d.options.html,k.push(`panel ${w}: markup from the model is not applied; its text is kept`)),delete d.source;else{d.source===void 0&&(d.source=v.source);const N=z(d.source);if(!(N&&(N.kind==="grid"||N.id===v.source))){k.push(`panel ${w} reads ${JSON.stringify(d.source)}, not "${v.source}" or another panel's grid; dropped`);continue}}const G=Q(d).filter(N=>!m.has(N));if(G.length){k.push(`panel ${w} names ${G.map(N=>`"${N}"`).join(", ")}, which "${v.source}" does not have; dropped`);continue}c.push(d),b.add(d.id)}const y={panels:c,sources:{[v.source]:v.definition}};l(r.layout)&&(y.layout=de(r.layout),Array.isArray(y.layout.windows)&&(y.layout.windows=y.layout.windows.filter(u=>l(u)&&b.has(u.id)))),r.links!==void 0&&(y.links=de(r.links));const P=F(y);for(const u of P.problems){const E=/^panels\[(\d+)\]/.exec(u.path),d=E?P.badPanels.has(Number(E[1])):u.link!==void 0&&P.badLinks.has(u.link);k.push(`${u.path} ${u.message}${d?"; dropped":""}`)}if(y.panels=y.panels.filter((u,E)=>!P.badPanels.has(E)),y.links!==void 0&&!Array.isArray(y.links))delete y.links;else if(Array.isArray(y.links)){const u=F(y);for(const E of u.problems)E.link!==void 0&&u.badLinks.has(E.link)&&!P.badLinks.has(E.link)&&k.push(`${E.path} ${E.message}; dropped`);y.links=y.links.filter((E,d)=>!u.badLinks.has(d))}if(y.layout&&Array.isArray(y.layout.windows)){const u=F(y);y.layout.windows=y.layout.windows.filter((E,d)=>!u.badWindows.has(d))}return{spec:y,warnings:k}}}),rt("packages/modules/dashboard/index.js",function(o,ce){"use strict";Object.defineProperty(o,"createDashboard",{enumerable:!0,get:function(){return E}}),Object.defineProperty(o,"validateDashboardSpec",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return d}});const ke=ce("packages/core/src/internal/util.js"),F=ke.warnOnce,l=ke.isFunction,de=ce("packages/modules/dashboard/spec.js"),z=de.inspectSpec,fe=de.validateDashboardSpec,J=de.copySpec,Q=de.sameSpec,ie=de.isPlain,W=de.parseSourceRef,L=de.readRelation,_=ce("packages/modules/dashboard/propose.js"),i=_.proposalRequest,v=_.parseProposal,k=_.checkProposal,r=Object.freeze({createGrid:"LatticeGrid",createHeadlessGrid:"LatticeGrid",createPushdownSource:"LatticeGrid",createChart:"LatticeGrid",createLayout:"LatticeGridLayout",createKPI:"LatticeGridKPI",createCalendar:"LatticeGridCalendar",bindLeaflet:"LatticeGridLeaflet",bindDeck:"LatticeGridDeck"}),m=50;function c(w){const G=globalThis,N={};for(const[T,C]of Object.entries(r)){const h=w[T],$=G[C];N[T]=l(h)?h:$&&l($[T])?$[T]:null}return N}function b(w){const G=[];return w.createGrid&&G.push("grid"),w.createChart&&w.createHeadlessGrid&&G.push("chart"),w.createKPI&&G.push("kpi"),w.createCalendar&&G.push("calendar"),w.createChart&&w.createHeadlessGrid&&G.push("map"),G.push("html"),G}function y(w){const G=new Map;for(const N of w.slice(0,m))if(!(!N||typeof N!="object"))for(const[T,C]of Object.entries(N)){const h=typeof C=="number"||C===null||C===void 0;G.set(T,(G.has(T)?G.get(T):!0)&&h)}return[...G].map(([N,T])=>T?{field:N,type:"number"}:{field:N})}function P(w,G){const N=new Set,T=(C,h)=>{if(!(h>3)){if(typeof C=="string"&&C!=="")N.add(C);else if(Array.isArray(C))C.forEach($=>T($,h+1));else if(ie(C))for(const[$,a]of Object.entries(C))N.add($),T(a,h+1)}};T(G,0);for(const C of N)for(const h of['"',"'","`"])if(w.includes(`${h}${C}${h}`))return!0;return!1}function u(w){const G=[],N=console.warn;console.warn=(...C)=>{C[0]==="[lattice]"&&G.push(C.slice(1).map(String).join(" ")),N.apply(console,C)};try{return{value:w(),heard:G}}catch(C){return{error:C,heard:G}}finally{console.warn=N}}function E(w,G,N={}){const T=ie(N)?N:{},C=c(T);let h={panels:[]},$=null,a=new Map,n=[],t=[],e=new Map,s=[],x=new Set,S=null,B=null;const Y=[];let te=0;const q=(Z,re,le)=>{s.push({id:Z,path:re,message:le})},ne=(Z,re)=>{F(`dashboard:panel:${Z}`,`createDashboard: panel "${Z}" ${re}`)},U=(Z,re,le)=>{F(`dashboard:link:${Z}->${re}`,`createDashboard: the link from "${Z}" to "${re}" ${le}`)};let M=new Map;const R=Z=>{let re=Z;for(let le=0;re&&re.viewsGridOf&&le<64;le++)re=a.get(re.viewsGridOf);return re||Z},H=Z=>{const re=W(Z),le=re&&re.kind==="grid"?re.of:Z,pe=a.get(le);return pe&&pe.grid?pe.grid:null},f=Z=>{const re={},le={};if(Z.rowKey!==void 0&&(re.rowKey=Z.rowKey),Array.isArray(Z.columns)&&(re.columns=Z.columns),Z.kind==="rows")le.rows=Z.rows,re.columns||(re.columns=y(Z.rows));else if(Z.kind==="pushdown"){if(!C.createPushdownSource)return{base:re,data:le,refusal:"its source is a pushdown adapter and there is no createPushdownSource on the page (load the grid, or pass options.createPushdownSource)"};const pe={};for(const[he,Me]of Object.entries(Z))["kind","columns","rowKey"].includes(he)||(pe[he]=Me);le.source=C.createPushdownSource(pe)}return{base:re,data:le}},g=(Z,re)=>{Z.kind==="router"&&(Z.router.attach(re,Z.predicate,Z.route),e.set(re,Z.router))},I=(Z,re)=>{const le=H(Z);if(le)return{grid:le};const pe=W(Z),he=pe&&pe.kind==="grid"?pe.of:Z,Me=h.sources[he];if(!Me)return null;if(!C.createHeadlessGrid)return{refusal:"there is no createHeadlessGrid on the page to hold its related source (load the grid, or pass options.createHeadlessGrid)"};const Ie=f(Me);if(Ie.refusal)return{refusal:Ie.refusal};const Ke=C.createHeadlessGrid({...Ie.base,...Ie.data});return re.push(Ke),g(Me,Ke),{grid:Ke}},j=Z=>{const re=$.payload(Z.id),pe=re.ownerDocument.createElement("div");pe.style.width="100%",pe.style.height="100%",re.appendChild(pe);const he=ie(Z.options)?Z.options:{},Me={id:Z.id,kind:Z.kind,def:Z,el:pe,grid:null,viewer:null,owned:[],ownedMap:null,viewsGridOf:null,sourceId:null,rootKind:"own"},Ie=[...M.get(Z.id)||[]],Ke=ae=>{for(const ee of Me.owned.reverse())A(ee);pe.remove(),q(`dashboard:panel:${Z.id}`,`panels[${h.panels.indexOf(Z)}]`,`was not built: ${ae}`),ne(Z.id,`was not built: ${ae}`)},qe=W(Z.source);let ot=null;qe&&qe.kind==="named"?(ot=h.sources[qe.id],Me.sourceId=qe.id,ot.kind==="grid"?Me.viewsGridOf=ot.of:Me.rootKind=ot.kind):qe&&(Me.viewsGridOf=qe.of),Me.viewsGridOf&&(Me.rootKind=R(a.get(Me.viewsGridOf)).rootKind);const it=Me.viewsGridOf?a.get(Me.viewsGridOf).grid:null,ge={grid:"createGrid",chart:"createChart",kpi:"createKPI",calendar:"createCalendar",map:{chart:"createChart",leaflet:"bindLeaflet",deckgl:"bindDeck"}[Z.binding||"chart"]}[Z.kind];if(ge&&!C[ge]){Ke(`there is no ${ge} on the page (load its module, or pass options.${ge})`);return}if(Z.kind!=="grid"&&Z.kind!=="html"&&ot&&ot.kind!=="grid"&&!C.createHeadlessGrid){Ke("there is no createHeadlessGrid on the page to hold its source (load the grid, or pass options.createHeadlessGrid)");return}let Le=null;if(ot&&ot.kind!=="grid"&&(Le=f(ot),Le.refusal)){Ke(Le.refusal);return}const He=()=>{if(it)return it;if(!Le)return null;const ae=C.createHeadlessGrid({...Le.base,...he.selection?{selection:"multiple"}:{},...Le.data});return Me.owned.push(ae),g(ot,ae),ae},Ze=u(()=>{if(Z.kind==="html")return typeof he.html=="string"?pe.innerHTML=he.html:typeof he.text=="string"&&(pe.textContent=he.text),null;if(Z.kind==="grid"){let ve=he;if(Le){for(const Ee of["rows","source"])he[Ee]!==void 0&&Ie.push(`options.${Ee} was not used: the panel's source "${Me.sourceId}" supplies its rows`);ve={...Le.base,...he,...Le.data}}else if(it){const $e={...(ie(he.source)&&he.source.mode==="derived"?he.source:null)||{},mode:"derived",from:it};if(ie($e.join)&&typeof $e.join.with=="string"){const Ge=I($e.join.with,Me.owned);Ge&&Ge.grid?$e.join={...$e.join,with:Ge.grid}:(Ie.push(`its join to "${$e.join.with}" was not made: ${Ge?Ge.refusal:"it names no declared source or widget"}`),delete $e.join)}ve={...he,source:$e},he.columns===void 0&&(ve.columns=it.columns.all().map(Ge=>({id:Ge.id,field:Ge.field,title:Ge.title,type:Ge.type})))}const be=C.createGrid(pe,ve);return Me.owned.push(be),Me.grid=be,ot&&g(ot,be),be}const ae=He();if(Me.grid=ae,Z.kind==="kpi")return C.createKPI(pe,ae?{...he,grid:ae}:he);if(Z.kind==="calendar")return C.createCalendar(pe,ae?{...he,grid:ae}:he);const ee=Z.kind==="map"&&Z.binding||"chart";if(ee==="chart"){for(const ve of["grid","container"])he[ve]!==void 0&&Ie.push(`options.${ve} was not used: the dashboard sets it from the panel's source and window`);return C.createChart({...he,grid:ae,container:pe})}if(ee==="leaflet"){const ve=l(he.map)?he.map(pe):he.map;return l(he.map)&&(Me.ownedMap={map:ve,end:"remove"}),C.bindLeaflet(ae,{...he,map:ve})}const ye=l(he.deck)?he.deck(pe):he.deck;return l(he.deck)&&(Me.ownedMap={map:ye,end:"finalize"}),C.bindDeck(ae,{...he,deck:ye})});if(Ze.error){Ke(`${ge||"the panel"} threw: ${Ze.error&&Ze.error.message}`);return}Me.viewer=Ze.value;for(const ae of Ze.heard)P(ae,he)&&Ie.push(`its ${Z.kind} refused part of its options: ${ae}`);if(Ie.length){const ae=Ie.join("; ");q(`dashboard:panel:${Z.id}`,`panels[${h.panels.indexOf(Z)}]`,`was built, but ${ae}`),ne(Z.id,`was built, but ${ae}`)}a.set(Z.id,Me)},A=Z=>{const re=e.get(Z);re&&(re.detach(Z),e.delete(Z)),Z&&l(Z.destroy)&&Z.destroy()},D=(Z,re)=>{const le=Ze=>{q(`dashboard:link:${Z.from}->${Z.to}`,`links[${re}]`,`was not made: ${Ze}`),U(Z.from,Z.to,`was not made: ${Ze}`)},pe=a.get(Z.from),he=a.get(Z.to);if(!pe||!he){le(`the ${pe?"target":"source"} panel was not built`);return}if(!pe.grid){le(`"${Z.from}" has no grid to read a selection from (a ${pe.kind} panel that reads no source)`);return}if(!he.grid){le(`"${Z.to}" has no grid to filter (a ${he.kind} panel that reads no source)`);return}if(he.grid===pe.grid){le(`"${Z.to}" draws the grid the link starts from, so it would filter its own selection away`);return}const Me=L(Z.on),Ie=e.get(pe.grid),Ke=e.get(he.grid);if(Ie&&Ke){if(Ie!==Ke){le("the two panels read routes of two different Data Routers, and a relation is drawn within one");return}Ie.relate([{from:pe.grid,to:he.grid,on:Me}]),t.push({from:Z.from,to:Z.to,def:Z,teardown:()=>{}});return}if(R(pe).rootKind==="pushdown"&&R(he).rootKind==="pushdown"){le("both panels read pushdown sources and no Data Router is shared between them: the rows selected in one engine cannot filter the other engine's query. Route both through one router to relate them");return}if(l(Me)){le("a relation function is the Data Router's form and needs both panels on one router; name the columns instead");return}const qe=`dashboard:${Z.from}->${Z.to}`,ot=R(he).rootKind==="pushdown",{from:it,to:ge}=Me,Le=()=>{const Ze=new Set;for(const ee of pe.grid.selection.rows()){const ye=ee&&ee.data!==void 0?ee.data:ee;ye&&typeof ye=="object"&&Ze.add(ye[it])}if(!Ze.size){he.grid.filters.where(qe,null);return}const ae={deps:[ge]};ot&&(ae.condition={col:ge,op:"in",value:[...Ze]}),he.grid.filters.where(qe,ee=>Ze.has(ee[ge]),ae)},He=pe.grid.on("selection:changed",Le);Le(),t.push({from:Z.from,to:Z.to,def:Z,teardown:()=>{He(),a.get(Z.to)===he&&he.grid.filters.where(qe,null)}})},p=Z=>{const re=a.get(Z);if(re){for(const le of[...a.values()])le.viewsGridOf===Z&&(p(le.id),$&&$.windows().includes(le.id)&&$.close(le.id));for(const le of t.filter(pe=>pe.from===Z||pe.to===Z))le.teardown();t=t.filter(le=>le.from!==Z&&le.to!==Z),se(re),a.delete(Z),n=n.filter(le=>le!==Z)}},se=Z=>{Z.viewer&&Z.viewer!==Z.grid&&l(Z.viewer.destroy)&&Z.viewer.destroy(),Z.ownedMap&&Z.ownedMap.map&&l(Z.ownedMap.map[Z.ownedMap.end])&&Z.ownedMap.map[Z.ownedMap.end]();for(const re of[...Z.owned].reverse())A(re);Z.el&&Z.el.parentNode&&Z.el.remove()},V=()=>{B&&$&&$.restore(B.seq[B.index]),B=null;for(const Z of t)Z.teardown();t=[];for(const Z of[...n].reverse()){const re=a.get(Z);re&&se(re)}S&&S(),S=null,$&&$.destroy(),$=null,a=new Map,n=[],e=new Map},O=(Z,re)=>{if(!$||!ie(Z)||Z.id==null||String(Z.id)==="")return!1;const le=String(Z.id);if(a.has(le))return!1;const pe=J(Z);if(h.panels.push(pe),!$.windows().includes(le)){const he={...ie(re)?re:{},id:le};he.title===void 0&&typeof pe.title=="string"&&(he.title=pe.title),$.add(he)}return j(pe),a.has(le)?(n.includes(le)||n.push(le),!0):($.windows().includes(le)&&$.close(le),h.panels=h.panels.filter(he=>he!==pe),!1)},X=(Z,re)=>{if(!$||!ie(Z)||Z.id==null)return!1;const le=String(Z.id);if(!a.has(le))return!1;const pe=n.indexOf(le);p(le);const he=J(Z),Me=h.panels.findIndex(Ie=>ie(Ie)&&String(Ie.id)===le);return Me>=0?h.panels[Me]=he:h.panels.push(he),ie(re)&&$.windows().includes(le)&&$.move(le,re),j(he),a.has(le)?(n.includes(le)||n.splice(pe<0?n.length:pe,0,le),!0):!1},oe=Z=>{if(!$)return!1;const re=String(Z),le=a.has(re)||$.windows().includes(re);return p(re),$.windows().includes(re)&&$.close(re),h.panels=h.panels.filter(pe=>!(ie(pe)&&String(pe.id)===re)),le},ue=Z=>{s=[],x=new Set;const re=z(Z);if(re.fatal){h={panels:[]},q("dashboard:spec","",re.fatal),F("dashboard:spec",`createDashboard: ${re.fatal}; a spec is { layout, panels, sources, links }. Nothing was built.`);return}h=J(Z),ie(h.sources)||(h.sources={}),Array.isArray(h.links)||(h.links=[]);for(const ge of Object.keys(h.sources))re.badSources.has(ge)||x.add(ge);M=new Map;for(const ge of re.problems){const Le=/^panels\[(\d+)\]/.exec(ge.path),He=ge.link!==void 0?h.links[ge.link]:null;if(ge.panel!==void 0&&Le&&re.badPanels.has(Number(Le[1])))q(`dashboard:panel:${ge.panel}`,ge.path,`was not built: ${ge.message}`),ne(ge.panel,`was not built: ${ge.path} ${ge.message}`);else if(ge.panel!==void 0)M.set(ge.panel,[...M.get(ge.panel)||[],`${ge.path} ${ge.message}`]);else if(ie(He)&&typeof He.from=="string"&&typeof He.to=="string"){const Ze=!re.badLinks.has(ge.link);q(`dashboard:link:${He.from}->${He.to}`,ge.path,Ze?ge.message:`was not made: ${ge.message}`),U(He.from,He.to,`${Ze?"was made, but":"was not made:"} ${ge.path} ${ge.message}`)}else q(`dashboard:spec:${ge.path}`,ge.path,ge.message),F(`dashboard:spec:${ge.path}`,`createDashboard: spec ${ge.path} ${ge.message}`)}if(!w||!l(w.appendChild)){q("dashboard:el","","the element is not an element"),F("dashboard:el","createDashboard: the first argument is not an element to mount on. Nothing was built.");return}if(!C.createLayout){q("dashboard:layout","layout","there is no createLayout on the page"),F("dashboard:layout","createDashboard: there is no createLayout on the page; load modules/layout or pass options.createLayout. Nothing was built.");return}const le=h.panels.filter((ge,Le)=>!re.badPanels.has(Le)),pe=ie(h.layout)?h.layout:{},he=new Map;(Array.isArray(pe.windows)?pe.windows:[]).forEach((ge,Le)=>{re.badWindows.has(Le)||he.set(ge.id,ge)});const Me=le.map(ge=>{const Le={...he.get(ge.id)||{},id:ge.id};return Le.title===void 0&&typeof ge.title=="string"&&(Le.title=ge.title),Le}),{windows:Ie,...Ke}=pe;$=C.createLayout(w,{...Ke,windows:Me}),S=$.on("window:closed",ge=>p(ge.id));const qe=ge=>{const Le=W(ge.source);if(Le&&Le.kind==="grid")return Le.of;const He=Le?h.sources[Le.id]:null;return He&&He.kind==="grid"?He.of:null},ot=ge=>{const Le=ie(ge.options)?ge.options.source:null;if(!ie(Le)||Le.mode!=="derived"||!ie(Le.join))return[];const He=W(Le.join.with);return He&&He.kind==="grid"?[He.of]:[]},it=[...le];for(;it.length;){const ge=it.findIndex(Ze=>![qe(Ze),...ot(Ze)].filter(Boolean).some(ee=>it.some(ye=>ye.id===ee))),[Le]=it.splice(Math.max(ge,0),1),He=qe(Le);He&&!a.has(He)?(q(`dashboard:panel:${Le.id}`,`panels[${h.panels.indexOf(Le)}].source`,`was not built: "${He}", whose grid it views, was not built`),ne(Le.id,`was not built: "${He}", whose grid it views, was not built`)):j(Le),!a.has(Le.id)&&$.windows().includes(Le.id)&&$.close(Le.id)}n=h.panels.map(ge=>ge&&ge.id).filter(ge=>a.has(ge)),h.links.forEach((ge,Le)=>{re.badLinks.has(Le)||D(ge,Le)})},xe=()=>{const Z=$?$.getLayout():{windows:[]},re=new Map(Z.windows.map(qe=>[qe.id,qe])),le=ie(h.layout)?h.layout:{},pe=new Map((Array.isArray(le.windows)?le.windows:[]).filter(qe=>ie(qe)).map(qe=>[qe.id,qe])),he=n.map(qe=>{const ot=J(pe.get(qe)||{id:qe}),it=re.get(qe);return it&&Object.assign(ot,{xPos:it.xPos,yPos:it.yPos,xSize:it.xSize,ySize:it.ySize}),ot}),{windows:Me,...Ie}=le,Ke={};for(const qe of Object.keys(h.sources||{}))x.has(qe)&&(Ke[qe]=J(h.sources[qe]));return{layout:{...J(Ie),windows:he},panels:n.map(qe=>J(a.get(qe).def)),sources:Ke,links:t.map(qe=>J(qe.def))}},me=Z=>{const re=h.sources[Z];if(Array.isArray(re.columns))return re.columns.filter(ie).map(pe=>({id:String(pe.id??pe.field),type:pe.type||"text"}));const le=[...a.values()].find(pe=>pe.grid&&(pe.sourceId===Z||re.kind==="grid"&&pe.id===re.of));return le?le.grid.columns.all().map(pe=>({id:pe.id,type:pe.type||"text"})):re.kind==="rows"?y(re.rows).map(pe=>({id:pe.field,type:pe.type||"text"})):[]},we=(Z,re)=>{const le=h.sources[Z];if(le.kind==="rows")return le.rows.slice(0,re);const pe=[...a.values()].find(he=>he.grid&&he.sourceId===Z);return pe?pe.grid.rows.data().slice(0,re):[]},Pe=Z=>(F("dashboard:present",`dashboard.present: ${Z}; nothing is presented.`),!1);ue(G);const Fe={get el(){return w},get layout(){return $},get presenting(){return B?B.seq[B.index]:null},spec(){return xe()},apply(Z){const re=e.size>0;return V(),ue(Z),re&&e.size&&F("dashboard:router",`dashboard.apply: ${e.size} grid(s) read a Data Router route and were rebuilt; a router does not re-send rows to a route attached after they arrived, so they fill from its next load() or push().`),Fe.problems()},panels(){return[...n]},panel(Z){const re=a.get(Z);return re?{id:re.id,kind:re.kind,el:re.el,grid:re.grid,viewer:re.viewer}:null},problems(){return s.map(Z=>({...Z}))},async propose(Z,re={}){const le=T.ai,pe=l(le)?le:le&&l(le.ask)?le.ask:null;if(!pe)return F("dashboard:propose","dashboard.propose: there is no AI on this dashboard (options.ai.ask); nothing was asked. Load modules/ai and pass the same ask() createAI takes."),{spec:null,warnings:["there is no AI on this dashboard (options.ai.ask); nothing was asked"]};const he=ie(re)?re:{},Me=he.source;if(typeof Me!="string"||!x.has(Me)){const ge=`"${Me}" is not a usable source of this dashboard; nothing was asked`;return F("dashboard:proposal",`dashboard.propose: the proposal has problems, each in the returned warnings: ${ge}`),{spec:null,warnings:[ge]}}const Ie=me(Me),Ke=Number.isFinite(he.maxRows)?Math.max(0,he.maxRows):m,qe=i(String(Z),{source:Me,columns:Ie,kinds:b(C),rows:he.rows===!0?we(Me,Ke):void 0,signal:he.signal}),ot=await pe(qe),it=k(v(ot),{source:Me,definition:h.sources[Me],columns:Ie,kinds:b(C)});return it.warnings.length&&F("dashboard:proposal",`dashboard.propose: the proposal has problems, each in the returned warnings: ${it.warnings[0]}`),it},saveView(Z){if(typeof Z!="string"||Z.trim()==="")return F("dashboard:view-name",`dashboard.saveView: ${JSON.stringify(Z)} is not a view name; nothing was saved.`),null;const re={},le={};for(const Me of n){const Ie=a.get(Me);Ie.kind==="grid"&&Ie.grid?re[Me]=Ie.grid.state.get():Ie.kind==="calendar"&&Ie.viewer&&l(Ie.viewer.getState)&&(le[Me]=Ie.viewer.getState())}const pe=Y.findIndex(Me=>Me.name===Z),he={id:pe>=0?Y[pe].id:`view-${++te}`,name:Z,spec:xe(),grids:re,calendars:le};return pe>=0?Y[pe]=he:Y.push(he),J(he)},views(){return Y.map(Z=>J(Z))},applyView(Z){const re=typeof Z=="string"?Y.find(pe=>pe.id===Z):Z;if(!ie(re)||!ie(re.spec))return F("dashboard:view",`dashboard.applyView: ${JSON.stringify(typeof Z=="string"?Z:typeof Z)} is not a saved view; nothing was applied.`),!1;const le=pe=>({...pe,layout:ie(pe.layout)?{...pe.layout,windows:(Array.isArray(pe.layout.windows)?pe.layout.windows:[]).map(he=>{const{xPos:Me,yPos:Ie,xSize:Ke,ySize:qe,...ot}=he;return ot})}:void 0});$&&Q(le(xe()),le(J(re.spec)))?$.setLayout(re.spec.layout.windows):Fe.apply(re.spec);for(const[pe,he]of Object.entries(ie(re.grids)?re.grids:{})){const Me=a.get(pe);Me&&Me.kind==="grid"&&Me.grid&&Me.grid.state.apply(he)}for(const[pe,he]of Object.entries(ie(re.calendars)?re.calendars:{})){const Me=a.get(pe);Me&&Me.kind==="calendar"&&Me.viewer&&l(Me.viewer.setState)&&Me.viewer.setState(he)}return!0},present(Z={}){const re=ie(Z)?Z:{};if(!$||!n.length)return Pe("the dashboard has no panels");let le=[...n];if(Array.isArray(re.panels)){const he=re.panels.filter(Me=>!a.has(Me));if(he.length)return Pe(`${he.map(Me=>JSON.stringify(Me)).join(", ")} is not a built panel`);if(le=[...re.panels],!le.length)return Pe("the list of panels is empty")}const pe=Number.isFinite(re.from)?Math.min(Math.max(Math.trunc(re.from),0),le.length-1):0;return B={seq:le,index:pe},$.maximise(le[pe]),!0},step(Z=1){if(!B||!$)return-1;const re=Math.min(Math.max(B.index+Math.trunc(Number(Z)||0),0),B.seq.length-1);return B.index=re,$.maximise(B.seq[re]),re},stopPresenting(){return B?($&&$.restore(B.seq[B.index]),B=null,!0):!1},applyConfig(Z){const re=ie(Z)?Z:{},le={added:0,updated:0,removed:0};if(!$)return le;for(const he of Array.isArray(re.remove)?re.remove:[])oe(he)&&(le.removed+=1);const pe=he=>{if(!ie(he)||!ie(he.panel))return;const Me=he.panel.id!=null?String(he.panel.id):null;Me!==null&&(a.has(Me)?X(he.panel,he.window)&&(le.updated+=1):O(he.panel,he.window)&&(le.added+=1))};for(const he of Array.isArray(re.update)?re.update:[])pe(he);for(const he of Array.isArray(re.add)?re.add:[])pe(he);return le},destroy(){V()}};return Fe}const d=E}),rt("packages/modules/designer/messages.js",function(o,ce){"use strict";Object.defineProperty(o,"MESSAGES",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"resolveMessages",{enumerable:!0,get:function(){return de}});const F=ce("packages/core/src/internal/util.js").isFunction,l=Object.freeze({"designer.canvas":"Dashboard canvas","designer.chrome":"Designer tools","designer.page":"Page {n}","a11y.designer.edit":"Edit mode","a11y.designer.view":"View mode","designer.toolbar":"Designer toolbar","designer.pages":"Pages","designer.mode.toEdit":"Edit","designer.mode.toView":"View","designer.mode.label":"Edit mode","designer.addNote":"Add text","designer.addGrid":"Add grid","designer.shortcuts":"Keyboard shortcuts","designer.shortcuts.help":"Show keyboard shortcuts","designer.dialog.close":"Close","designer.shortcut.toggleMode":"Switch between edit and view mode","designer.shortcut.addNote":"Add a text widget","designer.shortcut.addGrid":"Add a grid widget","designer.shortcut.nextRegion":"Move focus to the next region (toolbar, palette, canvas, properties)","designer.shortcut.previousRegion":"Move focus to the previous region","designer.shortcut.help":"Show or hide this list","designer.shortcut.moveWidget":"On a widget’s drag handle: Space or Enter grabs, arrow keys move, Space or Enter drops, Escape cancels","designer.shortcut.resizeWidget":"On a widget’s resize handle: Space or Enter grabs, arrow keys resize, Space or Enter drops, Escape cancels","designer.kind.chart":"Chart","designer.kind.grid":"Grid","designer.kind.html":"Text","designer.kind.kpi":"KPI","designer.kind.map":"Map","designer.kind.widget":"Widget","designer.region.toolbar":"Designer toolbar","designer.region.canvas":"Dashboard canvas","a11y.designer.added":"{kind} added: {title}","a11y.designer.page":"Page {title} selected","a11y.designer.region":"{name} region","a11y.designer.noSource":"No data source to add a grid from","a11y.designer.theme":"Theme: {theme}","designer.rail.left":"Palette and data","designer.rail.right":"Properties","designer.rail.collapse":"Collapse {name}","designer.rail.expand":"Expand {name}","designer.rail.section.palette":"Palette","designer.rail.section.data":"Data","designer.rail.divider":"Resize palette and data","a11y.designer.rail.open":"{name} opened","a11y.designer.rail.closed":"{name} closed","designer.palette":"Widget palette","designer.region.palette":"Widget palette","designer.palette.search":"Search widgets","designer.palette.source":"Source for new widgets","designer.palette.empty":"No widget matches","designer.palette.group.widgets":"Widgets","designer.palette.group.filters":"Filters","designer.palette.family.comparison":"Comparison","designer.palette.family.trend":"Trend","designer.palette.family.composition":"Composition","designer.palette.family.distribution":"Distribution","designer.palette.family.flow":"Flow","designer.palette.family.hierarchy":"Hierarchy","designer.palette.family.geo":"Geo","designer.palette.family.specialist":"Specialist","designer.palette.family.statistics":"Statistics","designer.palette.filter.list":"List filter","designer.palette.filter.range":"Range filter","designer.palette.filter.dateRange":"Date range filter","designer.palette.filter.search":"Search filter","designer.palette.needs.source":"needs a data source","designer.palette.needs.fields":"needs a field","designer.palette.needs.date":"needs a date field","designer.palette.needs.twoDate":"needs two date fields","designer.palette.needs.numeric":"needs a numeric field","designer.palette.needs.twoNumeric":"needs two numeric fields","designer.palette.needs.fourNumeric":"needs four numeric fields","designer.palette.needs.categorical":"needs a categorical field","designer.palette.needs.twoCategorical":"needs two categorical fields","designer.palette.needs.text":"needs a text field","designer.palette.needs.geometry":"needs a geometry field","designer.palette.needs.location":"needs a geometry or latitude and longitude fields","designer.palette.disabled":"{name} cannot be added: {reason}","designer.palette.unavailable":"{name} is not available","designer.palette.limit":"This page already holds {limit} widgets","designer.undo":"Undo","designer.redo":"Redo","designer.page.add":"Add page","designer.page.duplicate":"Duplicate page","designer.page.copy":"Copy of {title}","designer.page.rename":"Rename page","designer.page.delete":"Delete page","designer.page.cancel":"Cancel","designer.page.confirm":"Delete {title}?","designer.page.hasWidgets":"It has {n} widgets.","a11y.designer.page.added":"Page {title} added","a11y.designer.page.renamed":"Page renamed to {title}","a11y.designer.page.removed":"Page {title} removed","designer.lock":"Locked by guardrails","designer.data.panel":"Data","designer.data.search":"Search fields","designer.data.sources":"Sources","designer.data.relationships":"Relationships","designer.data.reachable":"Reachable from {source}: {sources}","designer.data.noReachable":"No sources related to {source}.","designer.data.empty":"No fields match {query}.","designer.data.field.add":"Add {field} to the canvas","designer.data.type.number":"Number","designer.data.type.currency":"Currency","designer.data.type.percent":"Percent","designer.data.type.date":"Date","designer.data.type.datetime":"Date & time","designer.data.type.boolean":"Boolean","designer.data.type.text":"Text","designer.data.type.list":"List","designer.data.type.geometry":"Geometry","designer.widget.name":"{kind}: {title}","designer.widget.selected":"{kind}: {title}, selected","a11y.designer.selected":"{name} selected","a11y.designer.removed":"{name} removed","designer.kind.kpi":"KPI","designer.kind.calendar":"Calendar","designer.kind.map":"Map","designer.kind.panel":"Panel","designer.properties":"Properties","designer.properties.empty":"Select a widget to edit its properties.","designer.prop.widget":"Widget","designer.prop.source":"Source","designer.prop.type":"Chart type","designer.prop.title":"Title","designer.prop.title.hint":"Widget title","designer.opt.empty":"Empty","designer.section.widget":"Widget","designer.section.data":"Data","designer.section.format":"Formatting","designer.section.interactions":"Interactions","designer.section.fields":"Fields","designer.field.none":"(none)","designer.field.pick":"Field {field}: drag it to a role, or press to pick it up","designer.field.picked":"Picked up {field}. Press Enter on a role to bind it; Escape cancels.","designer.move.earlier":"Move {item} earlier","designer.move.later":"Move {item} later","designer.problems":"Problems","designer.role.x":"Category","designer.role.y":"Measure","designer.role.measures":"Measures","designer.role.series":"Series","designer.role.size":"Size","designer.role.source":"From","designer.role.target":"To","designer.role.geometry":"Region","designer.role.lat":"Latitude","designer.role.lon":"Longitude","designer.role.measure":"Measure","designer.role.columns":"Columns","designer.role.date":"Date","designer.role.label":"Label","designer.role.start":"Start","designer.role.end":"End","designer.role.sparkline":"Sparkline","designer.role.sparklineOrder":"Sparkline order","designer.agg":"{role} aggregation","designer.agg.default":"Automatic","designer.agg.sum":"Sum","designer.agg.avg":"Average","designer.agg.min":"Minimum","designer.agg.max":"Maximum","designer.agg.count":"Count","designer.agg.countDistinct":"Distinct count","designer.agg.median":"Median","designer.bucket":"Date bucket","designer.bucket.of":"{role} date bucket","designer.bucket.none":"None","designer.bucket.day":"Day","designer.bucket.week":"Week","designer.bucket.month":"Month","designer.bucket.quarter":"Quarter","designer.bucket.year":"Year","designer.opt.title":"Title","designer.opt.scheme":"Colour scheme","designer.opt.scheme.default":"Default","designer.opt.scheme.bright":"Bright","designer.opt.scheme.earth":"Earth","designer.opt.scheme.mono":"Monochrome","designer.opt.scheme.patterns":"Patterns","designer.opt.default":"Default","designer.opt.palette":"Colours (theme override)","designer.opt.legend":"Legend","designer.opt.labels":"Data labels","designer.opt.tooltip":"Tooltip","designer.opt.axis.x.title":"X axis title","designer.opt.axis.x.format":"X axis format","designer.opt.axis.y.title":"Y axis title","designer.opt.axis.y.format":"Y axis number format","designer.opt.stack":"Stacking","designer.opt.stack.true":"Stacked","designer.opt.stack.percent":"100% stacked","designer.opt.curve":"Line shape","designer.opt.curve.linear":"Straight","designer.opt.curve.monotone":"Smooth","designer.opt.curve.catmullRom":"Smooth (through every point)","designer.opt.curve.step":"Stepped","designer.opt.projection":"Projection","designer.opt.diverging":"Diverging colours","designer.opt.maxRadius":"Largest bubble radius","designer.opt.selection":"Selection","designer.opt.pivot.enabled":"Pivot","designer.opt.grandTotalRow":"Grand total row","designer.opt.groupFooter":"Group totals","designer.opt.text":"Text","designer.opt.tiles.0.label":"Tile label","designer.opt.tiles.0.format":"Number format","designer.opt.tiles.0.baseline":"Compare with","designer.opt.tiles.0.delta":"Comparison shown as","designer.opt.tiles.0.target":"Target","designer.col.layout.hidden":"hidden","designer.col.layout.width":"width","designer.col.format":"format","designer.col.sort":"sort","designer.col.sort.asc":"Ascending","designer.col.sort.desc":"Descending","designer.col.group":"group by","designer.col.pivot":"pivot on","designer.col.total":"total","designer.col.total.sum":"Sum","designer.col.total.avg":"Average","designer.col.total.min":"Minimum","designer.col.total.max":"Maximum","designer.col.total.count":"Count","designer.col.total.countValues":"Count of values","designer.col.total.first":"First","designer.col.total.last":"Last","designer.calc.panel":"Calculated fields","designer.calc.heading":"Calculated fields","designer.calc.source":"Source","designer.calc.name":"Field name","designer.calc.expression":"Expression","designer.calc.placeholder":"e.g. IF(revenue > 100, revenue * 0.9, revenue)","designer.calc.suggestions":"Suggestions","designer.calc.preview":"Preview of the first rows","designer.calc.fields":"Calculated fields in use","designer.calc.type":"Result type: {type}","designer.calc.add":"Add field","designer.calc.save":"Save field","designer.calc.edit":"Edit","designer.calc.remove":"Remove","designer.calc.editField":"Edit {id}","designer.calc.removeField":"Remove {id}","designer.calc.empty":"(empty)","designer.calc.rowError":"Error: {error}","designer.calc.didYouMean":' (did you mean "{name}"?)',"designer.calc.refused":"not applied: {reason}","designer.calc.needName":"a calculated field needs a name","designer.calc.exists":'a field called "{id}" already exists',"designer.calc.noSource":"there is no source to add a calculated field to","designer.chart.switched":"Changed to {type}.","designer.chart.dropped":"Changed to {type}; dropped {roles}.","designer.data.derived":"Derived grids","designer.data.derived.lineage":"←","designer.data.derived.hidden":"hidden","designer.data.derived.show":"Show","designer.derived.engine":"Engine: {engine}","designer.derived.step.filter":"Filter","designer.derived.step.group":"Group","designer.derived.step.pivot":"Pivot","designer.derived.step.join":"Join","designer.derived.step.sort":"Sort","designer.derived.step.topN":"Top N","designer.derived.step.refused":"{step} refused by {engine}","designer.rail.section.assist":"Assist","designer.assist":"AI assistant","designer.assist.prompt":"Ask the AI assistant","designer.assist.placeholder":"Describe what to add or change","designer.assist.propose":"Propose","designer.assist.preview":"Proposed changes","designer.assist.accept":"Accept","designer.assist.reject":"Reject","designer.assist.removed":"{title} (to be removed)","designer.assist.working":"Asking the assistant…","designer.assist.problems":"Problems","designer.pushdown.limits":"What the engine cannot do","designer.pushdown.engine":"Computed in the engine ({adapter}) over every row, not the loaded window.","designer.pushdown.pending":"Asking the engine ({adapter})…","designer.pushdown.client":"Computed in the client: {reason}","designer.pushdown.noReason":"the engine could not answer","designer.pushdown.refused":"{name} is unavailable: {reason}","designer.pushdown.refusedStep":"The {step} step is refused: {reason}","a11y.designer.assist.proposed":"{added} added, {changed} changed, {removed} removed; {problems} refused","designer.filterbar":"Filters","designer.filterbar.context":"Filters applied","designer.filterbar.clearAll":"Clear all","designer.filter.value":"{field} value","designer.filter.list.placeholder":"Comma-separated values","designer.filter.min":"{field} minimum","designer.filter.max":"{field} maximum","designer.filter.from":"{field} from","designer.filter.to":"{field} to","designer.filter.remove":"Remove {field} filter","designer.filter.scope":"Filter scope","designer.filter.scope.page":"This page","designer.filter.scope.global":"All pages","designer.filter.type":"Filter type","designer.filter.source":"Filter source","designer.filter.field":"Filter field","designer.filter.add":"Add filter","designer.filter.contains":"contains","designer.filter.preset":"{field} date preset","designer.filter.preset.last7":"Last 7 days","designer.filter.preset.last30":"Last 30 days","designer.filter.preset.last90":"Last 90 days","designer.filter.preset.thisMonth":"This month","designer.filter.preset.thisQuarter":"This quarter","designer.filter.preset.thisYear":"This year","designer.filter.preset.custom":"Custom","designer.clickFilter":"Clicking this filters","designer.clickFilter.none":"Doesn't filter other widgets","designer.clickFilter.all":"All widgets","designer.clickFilter.chosen":"Chosen widgets","designer.clickFilter.on":"Relate by field"});function de(z){const fe=(Q,ie)=>Q.replace(/\{(\w+)\}/g,(W,L)=>ie&&L in ie?String(ie[L]):W),J=(Q,ie)=>fe(l[Q]||Q,ie);return!z||!F(z.t)?J:(Q,ie)=>{const W=z.t(Q,ie);return typeof W=="string"&&W!==Q?W:J(Q,ie)}}}),rt("packages/modules/designer/a11y.js",function(o,ce){"use strict";Object.defineProperty(o,"REGION_ORDER",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"firstTabbable",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"comboOf",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"auditChrome",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"createA11y",{enumerable:!0,get:function(){return k}});const ke=ce("packages/core/src/internal/util.js"),F=ke.warnOnce,l=ke.isFunction;let de=0;const z=Object.freeze({toolbar:0,palette:10,canvas:20,properties:30,data:40,filters:50});function fe(r){if(!r||typeof r.getAttribute!="function"||r.hasAttribute("disabled")||r.hasAttribute("hidden"))return!1;const m=r.getAttribute("tabindex");if(m!==null)return Number(m)>=0;const c=String(r.tagName||"").toLowerCase();return c==="button"||c==="input"||c==="select"||c==="textarea"||c==="a"&&r.hasAttribute("href")}function J(r){for(const m of r.children||[]){if(m.hasAttribute&&m.hasAttribute("hidden"))continue;if(fe(m))return m;const c=J(m);if(c)return c}return null}function Q(r,m){for(let c=r;c&&c!==m;c=c.parentNode)if(c.hasAttribute&&c.hasAttribute("hidden"))return!0;return!1}function ie(r){const c=(typeof r.code=="string"&&/^Key[A-Z]$/.test(r.code)?r.code.slice(3):null)||(typeof r.key=="string"&&r.key.length===1?r.key.toUpperCase():r.key);return[...[r.ctrlKey&&"Ctrl",r.altKey&&"Alt",r.shiftKey&&"Shift",r.metaKey&&"Meta"].filter(Boolean),c].join("+")}const W=["button","tab","link","checkbox","radio","switch","menuitem","option","combobox","textbox","slider","spinbutton"],L=["dialog","toolbar","tablist","region","group","listbox","menu","tree","grid"];function _(r,m){const c=r.getAttribute("aria-label");if(c&&c.trim())return c.trim();const b=r.getAttribute("aria-labelledby");if(b){const P=b.split(/\s+/).map(u=>{const E=i(m).find(d=>d.id===u);return E?String(E.textContent||"").trim():""}).join(" ").trim();if(P)return P}const y=String(r.textContent||"").trim();return y||(r.getAttribute("title")||r.getAttribute("alt")||"").trim()}function i(r){const m=[];for(const c of r.children||[])c.hasAttribute("hidden")||String(c.tagName).toLowerCase()==="style"||m.push(c,...i(c));return m}function v(r){const m=[],c=E=>`${String(E.tagName).toLowerCase()}${E.className?`.${String(E.className).split(/\s+/)[0]}`:""}`,b=(E,d,w)=>m.push({rule:E,element:c(d),message:w}),y=i(r),P=new Map;for(const E of y){const d=String(E.tagName).toLowerCase(),w=E.getAttribute("role");if(E.id&&P.set(E.id,(P.get(E.id)||0)+1),(d==="button"||d==="select"||d==="textarea"||d==="input"&&E.getAttribute("type")!=="hidden"||d==="a"&&E.hasAttribute("href")||w&&W.includes(w))&&!_(E,r)&&b("name",E,"a control has no accessible name"),w&&L.includes(w)&&w!=="group"&&w!=="region"&&!_(E,r)&&b("name",E,`a ${w} has no accessible name`),(w==="group"||w==="region")&&!E.getAttribute("aria-label")&&!E.getAttribute("aria-labelledby")&&b("name",E,`a ${w} has no accessible name`),w==="dialog"&&E.getAttribute("aria-modal")!=="true"&&b("dialog",E,"a dialog is not aria-modal"),w==="tab"&&((!E.parentNode||E.parentNode.getAttribute("role")!=="tablist")&&b("tab",E,"a tab is not in a tablist"),E.getAttribute("aria-selected")===null&&b("tab",E,"a tab does not say whether it is selected")),w==="toolbar"||w==="tablist"){const N=i(E).filter(T=>T.getAttribute("tabindex")==="0").length;N!==1&&b("roving",E,`a ${w} has ${N} tab stops; it must have exactly one`)}}for(const[E,d]of P)d>1&&m.push({rule:"id",element:`#${E}`,message:`the id is used ${d} times`});return y.find(E=>E.getAttribute("role")==="status"&&E.getAttribute("aria-live")==="polite")||m.push({rule:"live",element:"root",message:'there is no polite live region (role="status")'}),m}function k({root:r,live:m,t:c}){const b=r.ownerDocument,y=$=>{if(typeof $!="string"||!$)return;m.textContent="";const a=b.createElement("span");a.textContent=$,m.appendChild(a)},P=new Map,u=Object.freeze({register($){if(!$||typeof $.id!="string"||typeof $.keys!="string"||typeof $.description!="string")return F("designer:shortcut","designer.shortcuts.register: a shortcut is { id, keys, description, run? } with string id, keys and description; nothing was registered."),()=>{};const a={id:$.id,keys:$.keys,description:$.description,run:l($.run)?$.run:void 0};return P.set(a.id,a),()=>{P.get(a.id)===a&&P.delete(a.id)}},list(){return[...P.values()].map(({id:$,keys:a,description:n})=>({id:$,keys:a,description:n}))}}),E=new Map,d=Object.freeze({register($,a,n={}){if(typeof $!="string"||!a)return F("designer:region","designer.regions.register: a region is a string name and an element; nothing was registered."),()=>{};const t={name:$,el:a,order:typeof n.order=="number"?n.order:z[$]??100,label:typeof n.label=="string"?n.label:$};return E.set($,t),()=>{E.get($)===t&&E.delete($)}},list(){return[...E.values()].sort(($,a)=>$.order-a.order).map($=>$.name)},focus($){const a=E.get($);if(!a||Q(a.el,r))return!1;const n=J(a.el)||(a.el.getAttribute("tabindex")!==null?a.el:null);return n?(n.focus(),y(c("a11y.designer.region",{name:a.label})),!0):!1}}),w=$=>{const a=[...E.values()].sort((e,s)=>e.order-s.order).filter(e=>!Q(e.el,r));if(!a.length)return!1;const n=b.activeElement;let t=-1;a.forEach((e,s)=>{(e.el===n||n&&e.el.contains(n))&&(t=s)}),t<0&&(t=$>0?-1:0);for(let e=1;e<=a.length;e+=1){const s=a[(t+$*e+a.length*e)%a.length];if(d.focus(s.name))return!0}return!1};u.register({id:"region.next",keys:"F6",description:c("designer.shortcut.nextRegion"),run:()=>w(1)}),u.register({id:"region.previous",keys:"Shift+F6",description:c("designer.shortcut.previousRegion"),run:()=>w(-1)});const G=$=>{if($.defaultPrevented)return;const a=ie($);for(const n of P.values())if(n.run&&n.keys===a){$.preventDefault&&$.preventDefault(),n.run($);return}};r.addEventListener("keydown",G);let N=null,T=null;const C=()=>{N&&(N.remove(),N=null,T&&T.focus&&r.contains(T)&&T.focus(),T=null)},h=()=>{if(N)return;T=b.activeElement,N=b.createElement("div"),N.className="lattice-designer-scrim";const $=b.createElement("div");$.className="lattice-designer-dialog",$.setAttribute("role","dialog"),$.setAttribute("aria-modal","true"),de+=1,$.setAttribute("aria-labelledby",`lattice-designer-shortcuts-${de}`);const a=b.createElement("h2");a.id=`lattice-designer-shortcuts-${de}`,a.textContent=c("designer.shortcuts");const n=b.createElement("dl");for(const{keys:e,description:s}of u.list()){const x=b.createElement("dt");x.textContent=e;const S=b.createElement("dd");S.textContent=s,n.appendChild(x),n.appendChild(S)}const t=b.createElement("button");t.type="button",t.className="lattice-designer-button lattice-designer-button--primary",t.textContent=c("designer.dialog.close"),t.addEventListener("click",C),$.addEventListener("keydown",e=>{e.key==="Escape"?(e.preventDefault(),e.stopPropagation(),C()):e.key==="Tab"&&(e.preventDefault(),t.focus())}),$.appendChild(a),$.appendChild(n),$.appendChild(t),N.appendChild($),r.appendChild(N),t.focus()};return u.register({id:"help",keys:"Alt+Shift+K",description:c("designer.shortcut.help"),run:()=>N?C():h()}),{announce:y,shortcuts:u,regions:d,showShortcuts:h,hideShortcuts:C,destroy(){r.removeEventListener("keydown",G),N&&N.remove(),N=null,P.clear(),E.clear()}}}}),rt("packages/modules/designer/rails.js",function(o,ce){"use strict";Object.defineProperty(o,"railsCss",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"createRails",{enumerable:!0,get:function(){return ie}});const F=ce("packages/modules/dashboard/spec.js").isPlain,de=ce("packages/core/src/internal/util.js").isFunction,z=1100,fe=900,J=()=>`
|
|
15
|
+
.lattice-designer{position:relative;display:grid;box-sizing:border-box;overflow:hidden;background:var(--lattice-designer-page-bg);
|
|
16
16
|
grid-template-columns:260px minmax(0,1fr) 0;grid-template-rows:auto auto minmax(0,1fr);
|
|
17
17
|
grid-template-areas:"top top top" "filterbar filterbar filterbar" "left canvas right"}
|
|
18
|
-
.lattice-designer[data-left="collapsed"]{grid-template-columns:
|
|
18
|
+
.lattice-designer[data-left="collapsed"]{grid-template-columns:32px minmax(0,1fr) 0}
|
|
19
19
|
.lattice-designer[data-right="open"]{grid-template-columns:260px minmax(0,1fr) 300px}
|
|
20
|
-
.lattice-designer[data-right="collapsed"]{grid-template-columns:260px minmax(0,1fr)
|
|
21
|
-
.lattice-designer[data-left="collapsed"][data-right="open"]{grid-template-columns:
|
|
22
|
-
.lattice-designer[data-left="collapsed"][data-right="collapsed"]{grid-template-columns:
|
|
20
|
+
.lattice-designer[data-right="collapsed"]{grid-template-columns:260px minmax(0,1fr) 32px}
|
|
21
|
+
.lattice-designer[data-left="collapsed"][data-right="open"]{grid-template-columns:32px minmax(0,1fr) 300px}
|
|
22
|
+
.lattice-designer[data-left="collapsed"][data-right="collapsed"]{grid-template-columns:32px minmax(0,1fr) 32px}
|
|
23
23
|
.lattice-designer[data-mode="view"]{grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr);
|
|
24
24
|
grid-template-areas:"filterbar" "canvas"}
|
|
25
25
|
.lattice-designer-filterbar{grid-area:filterbar;min-width:0;box-sizing:border-box}
|
|
26
26
|
.lattice-designer-filterbar:empty{display:none}
|
|
27
|
-
.lattice-designer-canvas{grid-area:canvas;min-width:
|
|
27
|
+
.lattice-designer-canvas{grid-area:canvas;min-width:480px;min-height:0;position:relative;overflow:hidden;
|
|
28
|
+
background:var(--lattice-designer-panel-bg);border:var(--lattice-border-width,1px) solid var(--lattice-designer-panel-border);
|
|
29
|
+
border-radius:var(--lattice-radius,4px)}
|
|
28
30
|
.lattice-designer-chrome{display:contents}
|
|
29
|
-
.lattice-designer-topbar{grid-area:top;display:flex;flex-wrap:nowrap;align-items:center;column-gap:calc(var(--lattice-space
|
|
30
|
-
row-gap:0;padding:var(--lattice-space
|
|
31
|
-
background:var(--lattice-
|
|
32
|
-
border
|
|
31
|
+
.lattice-designer-topbar{grid-area:top;display:flex;flex-wrap:nowrap;align-items:center;column-gap:calc(var(--lattice-designer-space-2) * 2);
|
|
32
|
+
row-gap:0;padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);box-sizing:border-box;min-width:0;overflow-x:auto;
|
|
33
|
+
background:var(--lattice-designer-panel-bg);color:var(--lattice-foreground);
|
|
34
|
+
border:var(--lattice-border-width,1px) solid var(--lattice-designer-panel-border);border-radius:var(--lattice-radius,4px)}
|
|
33
35
|
.lattice-designer-topbar>*{flex:0 0 auto}
|
|
34
36
|
.lattice-designer-topbar .lattice-designer-tabs{flex:1 1 12em;min-width:0}
|
|
35
37
|
.lattice-designer-rail{display:flex;flex-direction:column;min-width:0;min-height:0;overflow:hidden;box-sizing:border-box;
|
|
36
|
-
background:var(--lattice-
|
|
37
|
-
|
|
38
|
-
.lattice-designer-rail--
|
|
39
|
-
.lattice-designer-rail
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
background:var(--lattice-designer-panel-bg);color:var(--lattice-foreground);
|
|
39
|
+
border:var(--lattice-border-width,1px) solid var(--lattice-designer-panel-border);border-radius:var(--lattice-radius,4px)}
|
|
40
|
+
.lattice-designer-rail--left{grid-area:left}
|
|
41
|
+
.lattice-designer-rail--right{grid-area:right}
|
|
42
|
+
.lattice-designer-rail-head{display:flex;align-items:center;justify-content:space-between;flex:0 0 auto;min-height:calc(var(--lattice-designer-space-4) * 2);
|
|
43
|
+
padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);gap:var(--lattice-designer-space-2);
|
|
44
|
+
border-bottom:var(--lattice-border-width,1px) solid var(--lattice-designer-panel-border)}
|
|
45
|
+
.lattice-designer-rail-title{font:var(--lattice-designer-font-title) var(--lattice-font-family);font-weight:var(--lattice-header-font-weight,600);
|
|
46
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
43
47
|
.lattice-designer-rail-sections{display:flex;flex-direction:column;flex:1 1 auto;min-height:0}
|
|
44
|
-
.lattice-designer-rail-section{display:flex;flex-direction:column;flex:1 1 0;min-height:0;
|
|
45
|
-
border-bottom:var(--lattice-border-width,1px) solid var(--lattice-border
|
|
48
|
+
.lattice-designer-rail-section{display:flex;flex-direction:column;flex:var(--lattice-designer-split,1) 1 0;min-height:0;
|
|
49
|
+
border-bottom:var(--lattice-border-width,1px) solid var(--lattice-designer-panel-border)}
|
|
46
50
|
.lattice-designer-rail-section[data-expanded="false"]{flex:0 0 auto}
|
|
47
|
-
.lattice-designer-rail-section-head{display:flex;align-items:center;gap:var(--lattice-space
|
|
48
|
-
font:
|
|
49
|
-
|
|
51
|
+
.lattice-designer .lattice-designer-rail-section-head{display:flex;align-items:center;gap:var(--lattice-designer-space-2);flex:0 0 auto;width:100%;box-sizing:border-box;
|
|
52
|
+
font:var(--lattice-designer-font-heading) var(--lattice-font-family);font-weight:var(--lattice-header-font-weight,600);
|
|
53
|
+
text-align:start;color:var(--lattice-foreground);
|
|
54
|
+
background:transparent;border:0;margin:0;padding:var(--lattice-designer-space-2) var(--lattice-designer-space-2);cursor:pointer}
|
|
50
55
|
.lattice-designer-rail-section-head:hover{background:var(--lattice-hovered-background)}
|
|
51
|
-
.lattice-designer-rail-section-head:focus-visible,.lattice-designer-rail-toggle:focus-visible{
|
|
56
|
+
.lattice-designer-rail-section-head:focus-visible,.lattice-designer-rail-toggle:focus-visible,.lattice-designer-rail-divider:focus-visible{
|
|
52
57
|
outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:-2px;
|
|
53
58
|
box-shadow:0 0 0 2px var(--lattice-focus-color)}
|
|
54
|
-
.lattice-designer-rail-
|
|
59
|
+
.lattice-designer-rail-divider{flex:0 0 auto;height:var(--lattice-designer-space-2);box-sizing:border-box;cursor:row-resize;
|
|
60
|
+
background:transparent;border:0;padding:0;margin:0}
|
|
61
|
+
.lattice-designer-rail-divider:hover{background:var(--lattice-hovered-background)}
|
|
62
|
+
.lattice-designer-rail-body{flex:1 1 auto;min-height:0;overflow:auto;padding:var(--lattice-designer-space-2)}
|
|
55
63
|
.lattice-designer-rail-body:empty{display:none}
|
|
56
64
|
.lattice-designer-rail--right .lattice-designer-rail-body{padding:0}
|
|
57
|
-
.lattice-designer-rail-toggle{font:
|
|
58
|
-
border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius,4px);
|
|
59
|
-
min-width:
|
|
60
|
-
|
|
61
|
-
.lattice-designer
|
|
65
|
+
.lattice-designer .lattice-designer-rail-toggle{font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);background:transparent;
|
|
66
|
+
border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius,4px);box-sizing:border-box;
|
|
67
|
+
width:28px;height:28px;min-width:28px;min-height:28px;padding:0;margin:0;cursor:pointer;
|
|
68
|
+
display:inline-flex;align-items:center;justify-content:center;line-height:1;flex:0 0 auto}
|
|
69
|
+
.lattice-designer .lattice-designer-rail-toggle:hover{background:var(--lattice-hovered-background)}
|
|
70
|
+
.lattice-designer-rail[data-collapsed="true"]{overflow:hidden}
|
|
71
|
+
.lattice-designer-rail[data-collapsed="true"] .lattice-designer-rail-head{border-bottom:0;justify-content:center;padding:var(--lattice-designer-space-1) 0}
|
|
62
72
|
.lattice-designer-rail[data-collapsed="true"] .lattice-designer-rail-title{display:none}
|
|
73
|
+
.lattice-designer-rail[data-collapsed="true"] .lattice-designer-rail-divider{display:none}
|
|
63
74
|
.lattice-designer-topbar .lattice-designer-rail-toggle{display:none}
|
|
64
75
|
.lattice-designer-topbar [data-rail-toggle="right"]{order:99;margin-inline-start:auto}
|
|
65
76
|
.lattice-designer[data-layout="narrow"][data-right="open"],.lattice-designer[data-layout="narrow"][data-right="collapsed"]{
|
|
66
77
|
grid-template-columns:260px minmax(0,1fr) 0}
|
|
67
78
|
.lattice-designer[data-layout="narrow"][data-left="collapsed"][data-right="open"],
|
|
68
|
-
.lattice-designer[data-layout="narrow"][data-left="collapsed"][data-right="collapsed"]{grid-template-columns:
|
|
79
|
+
.lattice-designer[data-layout="narrow"][data-left="collapsed"][data-right="collapsed"]{grid-template-columns:32px minmax(0,1fr) 0}
|
|
69
80
|
.lattice-designer[data-layout="compact"],.lattice-designer[data-layout="compact"][data-left],.lattice-designer[data-layout="compact"][data-right]{
|
|
70
81
|
grid-template-columns:minmax(0,1fr)}
|
|
71
82
|
.lattice-designer[data-layout="compact"]{grid-template-areas:"top" "filterbar" "canvas"}
|
|
@@ -83,26 +94,28 @@ ${i}`,messages:[{role:"system",content:fe},{role:"user",content:i}],schema:y};re
|
|
|
83
94
|
.lattice-designer[data-layout="compact"] .lattice-designer-rail[data-collapsed="true"] .lattice-designer-rail-title{display:block}
|
|
84
95
|
.lattice-designer[data-layout="compact"] .lattice-designer-rail[data-collapsed="true"] .lattice-designer-rail-head{justify-content:space-between;padding:var(--lattice-space,4px)}
|
|
85
96
|
.lattice-designer[data-mode="view"][data-layout]{grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr);grid-template-areas:"filterbar" "canvas"}
|
|
86
|
-
`;function X(B,L,D,o,w){const y=B.createElement("button");return y.type="button",y.className=L,y.setAttribute("aria-label",D),y.textContent=o,y.addEventListener("click",w),y}function ne(B){const{root:L,chrome:D,t:o,getPanels:w,setCollapsed:y}=B,i=L.ownerDocument,h=i.createElement("div");h.className="lattice-designer-topbar",D.appendChild(h);const c=i.createElement("div");c.className="lattice-designer-filterbar",L.appendChild(c);let m="wide";const b={left:!1,right:!1};let P=!1;const u={},A=(d,E)=>{const M=i.createElement("div");M.className=`lattice-designer-rail lattice-designer-rail--${d}`,M.setAttribute("role","group"),M.setAttribute("aria-label",E);const W=i.createElement("div");W.className="lattice-designer-rail-head";const oe=i.createElement("span");oe.className="lattice-designer-rail-title",oe.textContent=E;const q=X(i,"lattice-designer-rail-toggle",E,"",()=>Q.toggle()),Q={el:M,head:W,toggleBtn:q,get collapsed(){return m==="compact"||m==="narrow"&&d==="right"?!b[d]:r(d)},collapse(){return Q.set(!0)},expand(){return Q.set(!1)},toggle(){return Q.set(!Q.collapsed)},set(H){if(m==="compact"||m==="narrow"&&d==="right"){if(b[d]===!H)return H;if(b[d]=!H,B.announce(d,b[d]),n(),b[d]){const O=M.querySelector('button, input, select, textarea, [tabindex="0"]');O&&O.focus&&O.focus()}return H}return y(d,!!H),Q.collapsed}};return W.appendChild(oe),W.appendChild(q),M.appendChild(W),Q},r=d=>{const E=w()[d];if(F(E)&&E.collapsed===!0)return!0;const M=w().palette;return d==="left"&&F(M)&&M.collapsed===!0},j=A("left",o("designer.rail.left")),C=A("right",o("designer.rail.right")),G=i.createElement("div");G.className="lattice-designer-rail-sections",j.el.appendChild(G);const _=new Map;let T=0;const p=d=>{const E=String(d),M=_.get(E);if(M)return M.body;T+=1;const W=i.createElement("div");W.className="lattice-designer-rail-section",W.setAttribute("data-section",E),W.setAttribute("data-expanded","true");const oe=o(`designer.rail.section.${E}`),q=i.createElement("button");q.type="button",q.className="lattice-designer-rail-section-head",q.setAttribute("aria-expanded","true"),q.textContent=oe===`designer.rail.section.${E}`?E:oe;const Q=i.createElement("div");return Q.className="lattice-designer-rail-body",Q.id=`lattice-designer-rail-${E.replace(/[^a-z0-9_-]/gi,"-")}-${T}`,q.setAttribute("aria-controls",Q.id),q.addEventListener("click",()=>{const H=q.getAttribute("aria-expanded")!=="true";q.setAttribute("aria-expanded",H?"true":"false"),W.setAttribute("data-expanded",H?"true":"false"),H?Q.removeAttribute("hidden"):Q.setAttribute("hidden","")}),W.appendChild(q),W.appendChild(Q),G.appendChild(W),_.set(E,{el:W,head:q,body:Q}),Q};p("palette"),p("data");const v=i.createElement("div");v.className="lattice-designer-rail-body",C.el.appendChild(v),D.appendChild(j.el),D.appendChild(C.el);for(const d of["left","right"]){const E=X(i,"lattice-designer-rail-toggle",o(`designer.rail.${d}`),d==="left"?"☰":"⚙",()=>{b[d]=!b[d],B.announce(d,b[d]),n()});E.setAttribute("data-rail-toggle",d),E.setAttribute("aria-expanded","false"),u[d]=E,h.appendChild(E)}function n(){const d=P,E=m==="compact"||m==="narrow";d||(b.right=!1),L.setAttribute("data-layout",m),L.setAttribute("data-left",m!=="compact"&&r("left")?"collapsed":"open"),L.setAttribute("data-right",d?w().right&&w().right.collapsed===!0?"collapsed":"open":"none");for(const[M,W]of[["left",j],["right",C]]){const oe=!(m==="compact"||m==="narrow"&&M==="right")&&r(M),q=m==="compact"||m==="narrow"&&M==="right";W.el.setAttribute("data-collapsed",oe?"true":"false"),W.el.setAttribute("data-drawer",q?b[M]?"open":"closed":"none");const Q=q?b[M]:!oe;W.toggleBtn.setAttribute("aria-expanded",Q?"true":"false");const H=o(`designer.rail.${Q?"collapse":"expand"}`,{name:o(`designer.rail.${M}`)});W.toggleBtn.setAttribute("aria-label",H),W.toggleBtn.textContent=M==="left"?Q?"‹":"›":Q?"›":"‹";const O=M==="left"?G:v;oe?O.setAttribute("hidden",""):O.removeAttribute("hidden"),M==="right"&&(d?W.el.removeAttribute("hidden"):W.el.setAttribute("hidden",""))}for(const M of["left","right"])(m==="compact"||M==="right"&&E&&d)&&(M==="left"||d)?u[M].removeAttribute("hidden"):u[M].setAttribute("hidden",""),u[M].setAttribute("aria-expanded",b[M]?"true":"false")}const t=()=>{const d=L.getBoundingClientRect?L.getBoundingClientRect().width:0,E=!d||d>=z?"wide":d>=fe?"narrow":"compact";E!==m&&(m=E,b.left=!1,b.right=P&&E!=="wide",n())};let a=null;const e=(L.ownerDocument.defaultView||{}).ResizeObserver;ue(e)&&(a=new e(()=>t()),a.observe(L)),t(),n();const f=Object.freeze({left:Object.freeze({slot:p,get collapsed(){return j.collapsed},collapse:j.collapse,expand:j.expand,toggle:j.toggle,get el(){return j.el}}),right:Object.freeze({slot(){return v},get collapsed(){return C.collapsed},collapse:C.collapse,expand:C.expand,toggle:C.toggle,get el(){return C.el}}),get layout(){return m},get filterBar(){return c}});return{topbar:h,rails:f,sync:n,measure:t,setSelection(d){const E=P;P=!!d,P&&!E&&m!=="wide"&&(b.right=!0),n()},destroy(){a&&a.disconnect(),a=null}}}}),rt("packages/modules/charts/fills.js",function(s,ae){"use strict";Object.defineProperty(s,"PATTERNS",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"GRADIENTS",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"isFill",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"isPaintRef",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"paintFallback",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"normaliseFill",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"swatchCss",{enumerable:!0,get:function(){return y}}),Object.defineProperty(s,"createFillRegistry",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"rowPaint",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"patternSeries",{enumerable:!0,get:function(){return c}}),Object.defineProperty(s,"paintSolid",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"rowFillSource",{enumerable:!0,get:function(){return b}}),Object.defineProperty(s,"nodePaint",{enumerable:!0,get:function(){return P}});const F=ae("packages/core/src/internal/util.js").warnOnce,l=Object.freeze(["hatch","crosshatch","dots","grid"]),ue=Object.freeze(["linear","radial"]),z=8,fe="#0072b2";let J=0;const X=new Map;function ne(u){return!!u&&typeof u=="object"&&!Array.isArray(u)&&(typeof u.gradient=="string"||typeof u.pattern=="string")}function B(u){return typeof u=="string"&&u.startsWith("url(#")}function L(u){if(typeof u!="string")return u==null?"":String(u);if(!u.startsWith("url("))return u;const A=u.indexOf(")");return(A<0?"":u.slice(A+1).trim())||fe}function D(u,A){F(`chart:fill:invalid:${u}`,`a chart fill object was ignored: ${A} The mark was drawn in a solid colour instead. A fill is a gradient object (gradient: "linear" or "radial", with stops of [offset, colour]) or a pattern object (pattern: "hatch", "crosshatch", "dots" or "grid", with a colour).`)}function o(u,A){if(!ne(u))return null;const r=A||fe;if(typeof u.gradient=="string"){if(!ue.includes(u.gradient))return D("gradient",`the gradient "${u.gradient}" is not one of ${ue.join(", ")}.`),null;const _=Array.isArray(u.stops)?u.stops:[],T=[];for(const v of _){const n=Array.isArray(v)?Number(v[0]):Number(v&&v.offset),t=Array.isArray(v)?v[1]:v&&v.colour;!Number.isFinite(n)||typeof t!="string"||!t||T.push({offset:Math.min(1,Math.max(0,n)),colour:t})}if(T.length<2)return D("stops","a gradient needs at least two [offset, colour] stops."),null;T.sort((v,n)=>v.offset-n.offset);const p=Number.isFinite(Number(u.angle))?Number(u.angle):180;return{kind:u.gradient,angle:p,stops:T,solid:T[0].colour}}if(!l.includes(u.pattern))return D("pattern",`the pattern "${u.pattern}" is not one of ${l.join(", ")}.`),null;const j=Number(u.size),C=Number(u.angle),G=typeof u.colour=="string"&&u.colour?u.colour:r;return{kind:"pattern",pattern:u.pattern,colour:G,background:typeof u.background=="string"&&u.background?u.background:null,size:Number.isFinite(j)&&j>=2?j:z,angle:Number.isFinite(C)?C:u.pattern==="grid"||u.pattern==="dots"?0:45,solid:G}}function w(u){if(u.kind==="pattern"){const r=u.colour,j=u.size,C=Math.max(1,j/5),G=u.background||"transparent",_=T=>`repeating-linear-gradient(${T+90}deg,${r} 0 ${C}px,transparent ${C}px ${j}px)`;return u.pattern==="hatch"?`${_(u.angle)},${G}`:u.pattern==="crosshatch"?`${_(u.angle)},${_(u.angle+90)},${G}`:u.pattern==="grid"?`${_(u.angle)},${_(u.angle+90)},${G}`:`radial-gradient(circle at 50% 50%,${r} ${j/6}px,transparent ${j/6+.5}px) 0 0/${j}px ${j}px,${G}`}const A=u.stops.map(r=>`${r.colour} ${Math.round(r.offset*100)}%`).join(",");return u.kind==="radial"?`radial-gradient(circle,${A})`:`linear-gradient(${u.angle}deg,${A})`}function y(u){if(!B(u))return typeof u=="string"?u:"";const A=String(u).indexOf(")"),r=String(u).slice(5,A),j=X.get(r);return j?w(j):L(u)}function i(u){const A=`lattice-fill-${++J}`;let r=new Map,j=0;const C=(_,T)=>{const p=u.ownerDocument.createElementNS("http://www.w3.org/2000/svg",_);for(const v of Object.keys(T))p.setAttribute(v,String(T[v]));return p},G=(_,T)=>{if(T.kind==="pattern"){const v=T.size,n=Math.max(1,v/5),t=C("pattern",{id:_,width:v,height:v,patternUnits:"userSpaceOnUse"});T.angle&&t.setAttribute("patternTransform",`rotate(${T.angle})`),T.background&&t.appendChild(C("rect",{width:v,height:v,fill:T.background}));const a={stroke:T.colour,"stroke-width":n};T.pattern==="dots"?t.appendChild(C("circle",{cx:v/2,cy:v/2,r:Math.max(1,v/6),fill:T.colour})):(t.appendChild(C("line",{x1:v/2,y1:0,x2:v/2,y2:v,...a})),T.pattern!=="hatch"&&t.appendChild(C("line",{x1:0,y1:v/2,x2:v,y2:v/2,...a}))),u.appendChild(t);return}let p;if(T.kind==="radial")p=C("radialGradient",{id:_,cx:.5,cy:.5,r:.5});else{const v=T.angle*Math.PI/180,n=Math.sin(v)/2,t=-Math.cos(v)/2;p=C("linearGradient",{id:_,x1:+(.5-n).toFixed(4),y1:+(.5-t).toFixed(4),x2:+(.5+n).toFixed(4),y2:+(.5+t).toFixed(4)})}for(const v of T.stops)p.appendChild(C("stop",{offset:v.offset,"stop-color":v.colour}));u.appendChild(p)};return{prefix:A,paint(_,T){const p=o(_,T);if(!p)return T||fe;if(!u||!u.ownerDocument)return p.solid;const v=JSON.stringify(p);let n=r.get(v);if(!n){const t=`${A}-${j++}`;G(t,p),X.set(t,p),n=`url(#${t}) ${p.solid}`,r.set(v,n)}return n},reset(){for(const _ of r.values())X.delete(_.slice(5,_.indexOf(")")));if(r=new Map,j=0,u)for(;u.firstChild;)u.removeChild(u.firstChild)},ids(){return[...r.values()].map(_=>_.slice(5,_.indexOf(")")))}}}function h(u,A,r){if(u==null||u==="")return null;const j=L(r);if(ne(u))return A?A.paint(u,j):(o(u,j)||{}).solid||null;if(typeof u=="string"){if(l.includes(u)){const C={pattern:u,colour:j};return A?A.paint(C,j):j}return u}return null}function c(u){const A=[{pattern:"hatch",angle:45},{pattern:"dots"},{pattern:"crosshatch",angle:45},{pattern:"hatch",angle:135},{pattern:"grid"},{pattern:"dots",size:5},{pattern:"hatch",angle:0},{pattern:"crosshatch",angle:0,size:6}];return u.map((r,j)=>({...A[j%A.length],colour:r,background:"var(--lattice-background, #fff)"}))}function m(u){return B(u)?String(u).replace(/^url\([^)]*\)\s*/,""):u}function b(u,A){const r=u.fill;if(ne(r))return(C,G)=>h(r,A.fills,m(G));if(typeof r=="function")return(C,G)=>{let _=null;try{_=r({label:C.label,x:C.x,y:C.y,rowKey:C.rowKey})}catch{_=null}return h(_,A.fills,m(G))};const j=typeof r=="string"?r:r&&typeof r=="object"&&typeof r.col=="string"?r.col:null;return j?(C,G)=>C.rowKey===void 0||C.rowKey===null?null:h(u.grid.rows.value(C.rowKey,j),A.fills,m(G)):null}function P(u,A,r){return u&&u({label:A.label,x:A.value,y:A.total,rowKey:A.rowKey},r)||r}}),rt("packages/modules/charts/scheme.js",function(s,ae){"use strict";Object.defineProperty(s,"PALETTE",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"SCHEMES",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"registerScheme",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"setDefaultScheme",{enumerable:!0,get:function(){return D}}),Object.defineProperty(s,"schemeNames",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"resolveScheme",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"RAMP_SCALES",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"toRgb",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"rampStops",{enumerable:!0,get:function(){return A}});const F=ae("packages/core/src/internal/util.js").warnOnce,l=ae("packages/modules/charts/fills.js"),ue=l.isFill,z=l.patternSeries,fe=l.rowPaint,J=Object.freeze(["#0072b2","#e69f00","#009e73","#cc79a7","#56b4e9","#d55e00","#7a5195","#6b7d8c"]),X=Object.freeze({default:{series:J,sequential:["#ecf3f9","#005280"],diverging:["#b04a00","#f7f7f7","#005280"],positive:"#009e73",negative:"#d55e00"},bright:{series:["#1f77d0","#ff7f0e","#2ca02c","#d62728","#9467bd","#17becf","#e377c2","#7f7f7f"],sequential:["#eef4fb","#1f77d0"],diverging:["#d62728","#f7f7f7","#1f77d0"],positive:"#2ca02c",negative:"#d62728"},earth:{series:["#5b7c6f","#c08b52","#7a6a53","#a4553f","#4e6a83","#8f8259","#6d5566","#8c9196"],sequential:["#f2efe9","#4e6a83"],diverging:["#a4553f","#f2efe9","#4e6a83"],positive:"#5b7c6f",negative:"#a4553f"},mono:{series:["#0b2a3d","#17475f","#2c6480","#4a82a0","#6da0bd","#94bcd6","#bcd7e9","#dfecf5"],sequential:["#eef3f7","#0b2a3d"],diverging:["#7a5c00","#f5f5f5","#0b2a3d"],positive:"#17475f",negative:"#7a5c00"},patterns:{series:z(J),sequential:["#ecf3f9","#005280"],diverging:["#b04a00","#f7f7f7","#005280"],positive:"#009e73",negative:"#d55e00"}}),ne=new Map;let B="default";function L(r,j){!r||!j||ne.set(String(r),j)}function D(r){if(typeof r=="string"){B=r;return}r&&typeof r=="object"&&(ne.set("__default__",r),B="__default__")}function o(){return[...Object.keys(X),...ne.keys()].filter(r=>!r.startsWith("__"))}function w(r){return ne.has(r)?ne.get(r):X[r]||null}const y=["series","sequential","diverging","positive","negative"];function i(r){return!r||typeof r!="object"||Array.isArray(r)?!1:!y.some(j=>j in r)}function h(r,j){const C=j&&j.fills||null,G=w(B)||X.default,_=r&&r.scheme,T=i(_)?_:null,p=Array.isArray(_)&&_.length?_:null,v=typeof _=="string"?w(_):T||Array.isArray(_)?null:_||null,n=(r&&Array.isArray(r.palette)&&r.palette.length?r.palette:null)||p;T&&n&&F("chart:scheme:array-and-map",'chart "scheme" was given as a name map together with a "palette" array; the two do not combine. Colours came from the map and the array was ignored. Pass one or the other.');const t=T?null:n,a={...X.default,...G,...v||{}};t&&(a.series=t);const e=r&&r.ramp&&typeof r.ramp=="object"&&!Array.isArray(r.ramp)?r.ramp:null,f=e?e.colours:r&&r.ramp,d=Array.isArray(f)&&f.length>=2?f:null;d&&(a.sequential=d);const E=e?b(e.scale):null,M=!!(v||t||T),W=a.series&&a.series.length?a.series:J,oe=new Map;let q=0;return{...a,series:(H,O)=>{if(T&&O!==void 0&&O!==null){const I=String(O);return Object.prototype.hasOwnProperty.call(T,I)?c(T[I],C,H):(oe.has(I)||oe.set(I,q++),c(P(W,oe.get(I),!0),C,oe.get(I)))}return c(P(W,H,M),C,H)},explicit:M,nameMap:!!T,rampScale:E,fills:C}}function c(r,j,C){if(!ue(r))return r;const G=J[(C%J.length+J.length)%J.length];return fe(r,j,G)||G}const m=Object.freeze(["linear","log","quantile"]);function b(r){return r==null?null:m.includes(r)?r:(F(`chart:ramp:scale:${String(r)}`,`chart "ramp.scale" was "${String(r)}", which is not a ramp scale; the chart chose one from its values instead. Use "linear", "log" or "quantile".`),null)}function P(r,j,C){const G=(j%r.length+r.length)%r.length;return C||typeof r[G]!="string"?r[G]:`var(--lattice-chart-${G+1}, ${r[G]})`}function u(r){if(typeof r!="string")return null;const j=r.trim(),C=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(j);if(C){const T=C[1];return T.length===3?[0,1,2].map(p=>parseInt(T[p]+T[p],16)):[0,2,4].map(p=>parseInt(T.slice(p,p+2),16))}const G=/^rgba?\(([^)]+)\)$/i.exec(j);if(!G)return null;const _=G[1].split(/[\s,/]+/).filter(Boolean).slice(0,3).map(Number);return _.length===3&&_.every(T=>Number.isFinite(T))?_:null}function A(r,j){const C=j?r.diverging:r.sequential,G=j?X.default.diverging:X.default.sequential,_=(Array.isArray(C)?C:G).map((T,p)=>u(T)||u(G[p])||[0,0,0]);return _.length>=2?_:G.map(T=>u(T))}}),rt("packages/modules/charts/svg.js",function(s,ae){"use strict";Object.defineProperty(s,"SVG_NS",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(s,"el",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"svg",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"attr",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"attrs",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"setText",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"clear",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"append",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"path",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"ribbonPath",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"round",{enumerable:!0,get:function(){return D}}),Object.defineProperty(s,"pathRings",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"insideRings",{enumerable:!0,get:function(){return w}});const ve="http://www.w3.org/2000/svg";function F(y){const i=y.indexOf(")");return i<0?y:y.slice(i+1).trim()||"#0072b2"}function l(y,i,h){const c=y.createElement(i);return h&&c.setAttribute("class",h),c}function ue(y,i,h){const c=y.createElementNS(ve,i);if(h)for(const m of Object.keys(h))c.setAttribute(m,String(h[m]));return c}function z(y,i,h){if(!y)return;if(h==null){y.removeAttribute(i);return}let c=String(h);c.startsWith("url(#")&&(i==="stroke"||i==="fill"&&y.localName==="text")&&(c=F(c)),y.setAttribute(i,c)}function fe(y,i){if(y)for(const h of Object.keys(i))z(y,h,i[h])}function J(y,i){y&&(y.textContent=i==null?"":String(i))}function X(y){if(y)for(;y.firstChild;)y.removeChild(y.firstChild)}function ne(y,i){for(const h of i)h&&y.appendChild(h);return y}function B(y){return y.join(" ")}function L(y){if(!y||y.length<2)return"";const i=["M",y[0].x,y[0].upper];for(let h=1;h<y.length;h++)i.push("L",y[h].x,y[h].upper);for(let h=y.length-1;h>=0;h--)i.push("L",y[h].x,y[h].lower);return i.push("Z"),B(i)}function D(y){return Math.round(y*100)/100}function o(y){const i=[];let h=[];const c=String(y||"").match(/[A-Za-z]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi)||[];let m="",b=[];const P=()=>{if(!m||!b.length){b=[];return}if(m==="M"||m==="L")for(let u=0;u+1<b.length;u+=2)h.push([b[u],b[u+1]]);else m!=="Z"&&b.length>=2&&h.push([b[b.length-2],b[b.length-1]]);b=[]};for(const u of c){if(/[A-Za-z]/.test(u)){if(P(),u==="Z"||u==="z"){h.length>2&&i.push(h),h=[],m="";continue}u==="M"&&h.length>2&&(i.push(h),h=[]),m=u;continue}b.push(Number(u))}return P(),h.length>2&&i.push(h),i}function w(y,i,h){let c=!1;for(const m of y)for(let b=0,P=m.length-1;b<m.length;P=b++){const[u,A]=m[b],[r,j]=m[P];A>h!=j>h&&i<(r-u)*(h-A)/(j-A||1e-12)+u&&(c=!c)}return c}}),rt("packages/modules/charts/curve.js",function(s,ae){"use strict";Object.defineProperty(s,"CURVES",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"STEP_MODES",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"resolveCurve",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"curveCommands",{enumerable:!0,get:function(){return fe}});const F=ae("packages/modules/charts/svg.js").round,l=Object.freeze(["linear","monotone","catmullRom","step"]),ue=Object.freeze(["after","before","middle"]);function z(L,D){let o=L;if(o&&typeof o=="object"&&!Array.isArray(o)&&typeof o.type!="string"&&(o=D!=null&&Object.prototype.hasOwnProperty.call(o,D)?o[D]:void 0),o==null||o===!0||o===!1)return null;if(typeof o=="string")return o==="linear"?null:l.includes(o)?{type:o,tension:1,mode:"after"}:null;if(typeof o=="object"){const w=typeof o.type=="string"&&l.includes(o.type)?o.type:"linear";if(w==="linear")return null;const y=Number.isFinite(o.tension)?Math.max(0,Math.min(1,Number(o.tension))):1,i=ue.includes(o.mode)?o.mode:"after";return{type:w,tension:y,mode:i}}return null}function fe(L,D){return L.length?!D||D.type==="linear"?J(L):D.type==="step"?X(L,D.mode):D.type==="monotone"?ne(L):D.type==="catmullRom"?B(L,D.tension):J(L):[]}function J(L){const D=["M",F(L[0].x),F(L[0].y)];for(let o=1;o<L.length;o++)D.push("L",F(L[o].x),F(L[o].y));return D}function X(L,D){const o=["M",F(L[0].x),F(L[0].y)];for(let w=1;w<L.length;w++){const y=L[w-1].x,i=L[w-1].y,h=L[w].x,c=L[w].y;if(D==="before")o.push("L",F(y),F(c),"L",F(h),F(c));else if(D==="middle"){const m=F((y+h)/2);o.push("L",m,F(i),"L",m,F(c),"L",F(h),F(c))}else o.push("L",F(h),F(i),"L",F(h),F(c))}return o}function ne(L){const D=L.length;if(D<2)return["M",F(L[0].x),F(L[0].y)];if(D===2)return["M",F(L[0].x),F(L[0].y),"L",F(L[1].x),F(L[1].y)];const o=[];for(let i=0;i<D-1;i++){const h=L[i+1].x-L[i].x,c=L[i+1].y-L[i].y;o[i]=h===0?0:c/h}const w=new Array(D);w[0]=o[0],w[D-1]=o[D-2];for(let i=1;i<D-1;i++)w[i]=o[i-1]*o[i]<=0?0:(o[i-1]+o[i])/2;for(let i=0;i<D-1;i++)o[i]===0&&(w[i]=0,w[i+1]=0);for(let i=0;i<10;i++){let h=!1;for(let c=0;c<D-1;c++){if(o[c]===0)continue;const m=w[c]/o[c],b=w[c+1]/o[c],P=m*m+b*b;if(P>9){const u=3/Math.sqrt(P);w[c]=u*m*o[c],w[c+1]=u*b*o[c],h=!0}}if(!h)break}const y=["M",F(L[0].x),F(L[0].y)];for(let i=0;i<D-1;i++){const h=L[i].x,c=L[i].y,m=L[i+1].x,b=L[i+1].y,P=m-h,u=h+P/3,A=c+w[i]*P/3,r=m-P/3,j=b-w[i+1]*P/3;y.push("C",F(u),F(A),F(r),F(j),F(m),F(b))}return y}function B(L,D){const o=L.length;if(o<2)return["M",F(L[0].x),F(L[0].y)];const w=Number.isFinite(D)?Math.max(0,Math.min(1,D)):1,y=["M",F(L[0].x),F(L[0].y)];for(let i=0;i<o-1;i++){const h=L[i-1]||L[i],c=L[i],m=L[i+1],b=L[i+2]||L[i+1],P=c.x+(m.x-h.x)/6*w,u=c.y+(m.y-h.y)/6*w,A=m.x-(b.x-c.x)/6*w,r=m.y-(b.y-c.y)/6*w;y.push("C",F(P),F(u),F(A),F(r),F(m.x),F(m.y))}return y}}),rt("packages/modules/charts/projection.js",function(s,ae){"use strict";Object.defineProperty(s,"MERCATOR_LIMIT",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"equalEarth",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"robinson",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"mercator",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"equirectangular",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"albers",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"transverseMercator",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"PROJECTIONS",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"DEFAULT_PROJECTION",{enumerable:!0,get:function(){return D}}),Object.defineProperty(s,"resolveProjection",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"WRAP_DEGREES",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"splitAntimeridian",{enumerable:!0,get:function(){return y}}),Object.defineProperty(s,"boundsOf",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"fitted",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"graticule",{enumerable:!0,get:function(){return m}});const ve=Math.PI/180,F=Object.freeze([1.340264,-.081106,893e-6,.003796]),l=Object.freeze([[1,0],[.9986,.062],[.9954,.124],[.99,.186],[.9822,.248],[.973,.31],[.96,.372],[.9427,.434],[.9216,.4958],[.8962,.5571],[.8679,.6176],[.835,.6769],[.7986,.7346],[.7597,.7903],[.7186,.8435],[.6732,.8936],[.6213,.9394],[.5722,.9761],[.5322,1]]),ue=85.05113;function z(b,P){const[u,A,r,j]=F,C=P*ve,G=Math.asin(Math.min(1,Math.max(-1,Math.sqrt(3)/2*Math.sin(C)))),_=G*G,T=_*_*_,p=Math.sqrt(3)/2*(u+3*A*_+T*(7*r+9*j*_));return[b*ve*Math.cos(G)/p,G*(u+A*_+T*(r+j*_))]}function fe(b,P){const u=Math.min(Math.abs(P),90),A=Math.min(l.length-2,Math.floor(u/5)),r=(u-A*5)/5,[j,C]=l[A],[G,_]=l[A+1],T=j+(G-j)*r,p=C+(_-C)*r;return[b*ve*T,(P<0?-p:p)*(Math.PI/2)]}function J(b,P){const u=Math.min(ue,Math.max(-ue,P))*ve;return[b*ve,Math.log(Math.tan(Math.PI/4+u/2))]}function X(b,P){return[b*ve,P*ve]}function ne(b={}){const[P,u]=b.parallels||[29.5,45.5],[A,r]=b.centre||[-96,37.5],j=P*ve,C=u*ve,G=Math.sin(j),_=Math.abs(j-C)<1e-9?G:(G+Math.sin(C))/2,T=Math.cos(j)**2+2*_*G,p=Math.sqrt(T-2*_*Math.sin(r*ve))/_;return(v,n)=>{const t=_*((v-A)*ve),a=Math.max(0,T-2*_*Math.sin(n*ve)),e=Math.sqrt(a)/_;return[e*Math.sin(t),p-e*Math.cos(t)]}}function B(b={}){const[P,u]=b.centre||[-2,49];return(A,r)=>{const j=r*ve,C=(A-P)*ve,G=Math.cos(j)*Math.sin(C),_=Math.min(1-1e-12,Math.max(-1+1e-12,G));return[.5*Math.log((1+_)/(1-_)),Math.atan2(Math.tan(j),Math.cos(C))-u*ve]}}const L=Object.freeze({equalEarth:()=>z,robinson:()=>fe,mercator:()=>J,equirectangular:()=>X,albers:ne,transverseMercator:B,britishNationalGrid:b=>B({centre:[-2,49],...b})}),D="equalEarth";function o(b,P={},u){if(typeof b=="function")return b;const r=L[typeof b=="string"&&b?b:D];return r?r(P):(u&&u(`chart projection ${JSON.stringify(b)} is not one this module draws; using '${D}'. Supported: ${Object.keys(L).join(", ")}.`),L[D]({}))}const w=180;function y(b){if(!Array.isArray(b)||b.length<2)return b&&b.length?[b]:[];const P=[];let u=[b[0]];for(let A=1;A<b.length;A++){const[r,j]=b[A-1],[C,G]=b[A],_=C-r;if(Math.abs(_)>w){const T=_>0?-180:180,p=_>0?_-360:_+360,v=p===0?0:Math.min(1,Math.max(0,(T-r)/p)),n=j+(G-j)*v;u.push([T,n]),P.push(u),u=[[-T,n],[C,G]]}else u.push([C,G])}return P.push(u),P.filter(A=>A.length>1)}function i(b){let P=1/0,u=1/0,A=-1/0,r=-1/0;for(const j of b||[])for(const[C,G]of j)C<P&&(P=C),C>A&&(A=C),G<u&&(u=G),G>r&&(r=G);return Number.isFinite(P)?{west:P,south:u,east:A,north:r}:null}function h(b){const{project:P,rings:u,plot:A}=b,r=typeof b.padding=="number"?b.padding:4;let j=1/0,C=1/0,G=-1/0,_=-1/0;for(const Q of u||[])for(const[H,O]of Q){const[I,K]=P(H,O);!Number.isFinite(I)||!Number.isFinite(K)||(I<j&&(j=I),I>G&&(G=I),K<C&&(C=K),K>_&&(_=K))}if(!Number.isFinite(j)||G===j||_===C)return{to:(H,O)=>{const[I,K]=P(H,O);return[A.left+A.width/2+I,A.top+A.height/2-K]},scale:1,width:A.width,height:A.height,left:A.left,top:A.top,aspect:1};const T=Math.max(1,A.width-r*2),p=Math.max(1,A.height-r*2),v=typeof b.zoom=="number"&&b.zoom>0?b.zoom:1,n=Math.min(T/(G-j),p/(_-C))*v,t=(G-j)*n,a=(_-C)*n,[e,f]=b.centre?P(b.centre[0],b.centre[1]):[(j+G)/2,(C+_)/2],d=b.centreOffset||[0,0],E=e+(d[0]||0),M=f+(d[1]||0),W=A.left+A.width/2,oe=A.top+A.height/2;return{to:(Q,H)=>{const[O,I]=P(Q,H);return[W+(O-E)*n,oe-(I-M)*n]},scale:n,width:t,height:a,left:W-t/2,top:oe-a/2,aspect:(G-j)/(_-C)}}const c=2;function m(b={}){const P=b.step&&b.step>0?b.step:30,u=[];for(let A=-180;A<=180;A+=P){const r=[];for(let j=-80;j<=80;j+=c)r.push([A,j]);u.push(r)}for(let A=-60;A<=60;A+=P){const r=[];for(let j=-180;j<=180;j+=c)r.push([j,A]);u.push(r)}return u}}),rt("packages/modules/charts/capabilities.js",function(s,ae){"use strict";Object.defineProperty(s,"AGGREGATIONS_OFFERED",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"CHART_TYPES",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"chartRoles",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"chartOptions",{enumerable:!0,get:function(){return A}}),Object.defineProperty(s,"chartEditorModel",{enumerable:!0,get:function(){return r}});const F=ae("packages/modules/charts/scheme.js").schemeNames,ue=ae("packages/modules/charts/curve.js").CURVES,fe=ae("packages/modules/charts/projection.js").PROJECTIONS,J=Object.freeze(["sum","avg","min","max","count","countDistinct","median"]),X=Object.freeze(["line","step","area","rangeArea","bar","horizontalBar","waterfall","floatingBar","horizontalFloatingBar","populationPyramid","bullet","scatter","bubble","forest","combo","pareto","histogram","boxplot","heatmap","qq","ecdf","lorenz","correlogram","control","capability","movingRange","pie","donut","sunburst","treemap","radar","gauge","funnel","candlestick","ohlc","geomap","sankey","chord","network","stream","marimekko","violin","gantt"]),ne=new Set(["sankey","chord","network"]),B=new Set(["pie","donut","sunburst","treemap"]),L=new Set(["combo","candlestick","ohlc"]),D=new Set(["histogram","boxplot","qq","ecdf","lorenz","violin","control","capability","movingRange"]),o=new Set(["geomap","markermap","bubblemap","choropleth"]),w=new Set(["bubble","scatter"]),y=new Set(["gauge","bullet"]),i=new Set(["profile","distribution","correlation","groupComparison","modelError"]),h=new Set([...B,...ne,...o,...y,...i,"radar","funnel","heatmap"]),c=new Set(["bar","horizontalBar","line","area","scatter","bubble","combo","pareto","histogram","heatmap","pie","donut","sunburst","treemap","radar","geomap","gauge","funnel"]),m=new Set(["bar","horizontalBar","area","combo"]),b=new Set(["line","area","rangeArea"]),P=new Set(["markermap","bubblemap","choropleth"]);function u(j){if(j==="profile")return[{role:"field",accepts:"field",path:"y",required:!0}];if(j==="distribution")return[{role:"field",accepts:"field",path:"y",required:!0}];if(j==="correlation")return[{role:"columns",accepts:"measure",path:"columns",repeatable:!0,required:!0}];if(j==="groupComparison")return[{role:"field",accepts:"measure",path:"y",required:!0},{role:"group",accepts:"dimension",path:"group",required:!0}];if(j==="modelError")return[{role:"response",accepts:"measure",path:"y",required:!0},{role:"predictor",accepts:"measure",path:"x",required:!0}];if(ne.has(j))return[{role:"source",accepts:"dimension",required:!0},{role:"target",accepts:"dimension",required:!0},{role:"y",accepts:"measure",aggregated:!0}];if(j==="geomap")return[{role:"geometry",accepts:"dimension",path:"code",required:!0},{role:"measure",accepts:"measure",path:"y",aggregated:!0}];if(j==="choropleth")return[{role:"geometry",accepts:"field",path:"geometry",required:!0},{role:"measure",accepts:"measure",path:"y"},{role:"label",accepts:"dimension"}];if(o.has(j))return[{role:"geometry",accepts:"field",path:"geometry"},{role:"lat",accepts:"field",path:"lat"},{role:"lon",accepts:"field",path:"lon"},j==="bubblemap"?{role:"size",accepts:"measure",path:"size"}:{role:"measure",accepts:"measure",path:"value"},{role:"label",accepts:"dimension"}];if(B.has(j))return[{role:"x",accepts:"dimension",required:!0},{role:"y",accepts:"measure",aggregated:!0},{role:"colour",accepts:"dimension"}];if(L.has(j))return[{role:"x",accepts:"dimension",bucketable:!0},{role:"measures",accepts:"measure",aggregated:!0,repeatable:!0,required:!0},{role:"series",accepts:"dimension"}];if(D.has(j))return[{role:"x",accepts:"dimension"},{role:"y",accepts:"measure",aggregated:!0,required:!0},{role:"series",accepts:"dimension"}];if(y.has(j))return[{role:"y",accepts:"measure",aggregated:!0,required:!0}];if(j==="radar")return[{role:"x",accepts:"dimension",required:!0},{role:"y",accepts:"measure",aggregated:!0},{role:"series",accepts:"dimension"}];if(j==="funnel")return[{role:"x",accepts:"dimension",required:!0},{role:"y",accepts:"measure",aggregated:!0}];if(j==="gantt")return[{role:"label",accepts:"dimension",required:!0},{role:"start",accepts:"field"},{role:"end",accepts:"field"},{role:"series",accepts:"dimension"}];const C=[{role:"x",accepts:"dimension",bucketable:!0},{role:"y",accepts:"measure",aggregated:!0},{role:"series",accepts:"dimension"}];return w.has(j)&&C.push({role:"size",accepts:"measure",aggregated:!0}),C}function A(j){const C=[{name:"title",type:"string"}];return C.push({name:"scheme",type:"enum",values:F()}),C.push({name:"palette",type:"list",format:"colour"}),!y.has(j)&&!i.has(j)&&C.push({name:"legend",type:"boolean",default:!0}),c.has(j)&&C.push({name:"labels",type:"boolean",default:!1}),C.push({name:"tooltip",type:"boolean",default:!0}),!h.has(j)&&!D.has(j)&&(C.push({name:"axis.x.title",type:"string"}),C.push({name:"axis.x.format",type:"string",format:"date"}),C.push({name:"axis.y.title",type:"string"}),C.push({name:"axis.y.format",type:"string",format:"number"})),m.has(j)&&C.push({name:"stack",type:"enum",values:[!0,"percent"]}),b.has(j)&&C.push({name:"curve",type:"enum",values:[...ue]}),P.has(j)&&C.push({name:"projection",type:"enum",values:Object.keys(fe)}),j==="choropleth"&&C.push({name:"diverging",type:"boolean",default:!1}),j==="bubblemap"&&C.push({name:"maxRadius",type:"number",min:2,max:100,step:1,default:20}),j==="distribution"&&C.push({name:"mode",type:"enum",values:["histogram","box","violin","ecdf"],default:"histogram"}),j==="correlation"&&C.push({name:"method",type:"enum",values:["pearson","spearman"],default:"pearson"}),j==="groupComparison"&&(C.push({name:"test",type:"enum",values:["auto","welch","mannWhitney","chiSquare"],default:"auto"}),C.push({name:"confidence",type:"number",min:.5,max:.999,step:.01,default:.95})),j==="modelError"&&C.push({name:"preset",type:"enum",values:["fit","residuals","influence"],default:"fit"}),j==="forecast"&&(C.push({name:"trend.method",type:"enum",values:["linear","movingAverage","exponential"],default:"linear"}),C.push({name:"trend.forecast",type:"number",min:0,max:60,step:1,default:3}),C.push({name:"trend.band",type:"enum",values:["prediction","confidence"],default:"prediction"}),C.push({name:"curve",type:"enum",values:[...ue]})),C}function r(j){return{type:j,roles:u(j),options:A(j),aggregations:J}}}),rt("packages/modules/charts/registry.js",function(s,ae){"use strict";Object.defineProperty(s,"registerChartType",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"chartTypeDef",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"registeredChartTypes",{enumerable:!0,get:function(){return z}});const ve=Symbol.for("lattice-grid/charts/registry");function F(){return globalThis[ve]||(globalThis[ve]=new Map),globalThis[ve]}function l(fe,J){if(typeof fe!="string"||!fe)throw new TypeError("[lattice] registerChartType needs a non-empty type name.");if(!J||typeof J.draw!="function")throw new TypeError(`[lattice] registerChartType('${fe}') needs a { draw } function.`);F().set(fe,J)}function ue(fe){return F().get(fe)||null}function z(){return[...F().keys()]}}),rt("packages/modules/designer/palette.js",function(s,ae){"use strict";Object.defineProperty(s,"PALETTE_FAMILIES",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"FILTER_TYPES",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"chartFamily",{enumerable:!0,get:function(){return C}}),Object.defineProperty(s,"bindChartDefaults",{enumerable:!0,get:function(){return _}}),Object.defineProperty(s,"paletteCss",{enumerable:!0,get:function(){return T}}),Object.defineProperty(s,"installPalette",{enumerable:!0,get:function(){return t}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return a}});const F=ae("packages/modules/dashboard/spec.js").isPlain,ue=ae("packages/core/src/internal/util.js").isFunction,z=ae("packages/modules/charts/capabilities.js"),fe=z.chartEditorModel,J=z.CHART_TYPES,X=ae("packages/modules/charts/registry.js"),ne=X.registeredChartTypes,B=X.chartTypeDef,D=ae("packages/modules/designer/messages.js").resolveMessages,o=Object.freeze(["comparison","trend","composition","distribution","flow","hierarchy","geo","specialist","statistics"]),w=Object.freeze(["list","range","dateRange","search"]),y=Object.freeze({comparison:["bar","horizontalBar","waterfall","floatingBar","horizontalFloatingBar","populationPyramid","bullet","combo","pareto","barRace","diverging","dumbbell","polarArea","rose","nightingale","pyramid","radialBar","slope"],trend:["line","step","area","rangeArea","candlestick","ohlc","bump","fan","serpentine","spiral","motion"],composition:["pie","donut","stream","marimekko","funnel","pictorial","venn","waffle"],distribution:["scatter","bubble","forest","histogram","boxplot","heatmap","qq","ecdf","lorenz","correlogram","violin","hexbin","polarScatter","ridgeline","splom","voronoiTreemap"],flow:["sankey","chord","network","alluvial","arc"],hierarchy:["sunburst","treemap","decomposition","forceTree","icicle","pack","tree"],geo:["geomap","markermap","bubblemap","choropleth","hexmap"],specialist:["radar","gauge","control","capability","movingRange","gantt","calendar","parallel","roc","wordCloud"]}),i=new Map(Object.entries(y).flatMap(([e,f])=>f.map(d=>[d,e]))),h=new Set(["line","step","area","rangeArea","stream","candlestick","ohlc"]),c=new Set(["candlestick","ohlc"]),m=new Set(["scatter","bubble"]),b=new Set(["histogram","boxplot","qq","ecdf","lorenz","violin","control","capability","movingRange","scatter","bubble","gauge","bullet"]),P=Object.freeze({combo:2,candlestick:4,ohlc:4}),u=new Set(["series","colour","size"]),A=new Set(["number","currency","percent"]),r=new Set(["date","datetime"]),j=new Set(["text","boolean"]);function C(e,f){return f&&o.includes(f.family)?f.family:i.get(e)||"specialist"}const G=e=>{const f=String(e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim().toLowerCase();return f.charAt(0).toUpperCase()+f.slice(1)};function _(e,f,d){const E=d.filter(k=>A.has(k.type)),M=d.filter(k=>r.has(k.type)),W=d.filter(k=>j.has(k.type)),oe=d.filter(k=>k.type==="geometry"),q=new Set,Q=k=>{const V=k.find(R=>!q.has(R.id));return V&&q.add(V.id),V},H={type:e},O=f.some(k=>k.required),I=k=>E.find(V=>!q.has(V.id)&&k.test(V.id));let K=null;const g=k=>{K||(K=k)};for(const k of f){const V=k.path||k.role;if(u.has(k.role)&&!k.required||k.role==="label"&&!k.required)continue;const R=e==="gantt"&&(k.role==="start"||k.role==="end");if(O&&!k.required&&!R&&k.accepts!=="measure"&&V!=="lat"&&V!=="lon")continue;const N=k.required||R||!O&&(k.role==="x"||k.role==="y")||k.role==="y"&&k.accepts==="measure"&&!!k.aggregated;if(k.accepts==="measure"){if(m.has(e)&&k.role==="y")continue;const Y=k.aggregated&&!b.has(e),Z=k.repeatable&&P[e]||1,x=[];for(;x.length<Z;){const se=Q(E);if(!se)break;x.push(se)}const ee=se=>Y?{col:se.id,fn:"sum"}:se.id;k.repeatable?x.length===Z?H[V]=x.map(ee):g(Z===4?"fourNumeric":Z===2?"twoNumeric":"numeric"):x.length?H[V]=ee(x[0]):N&&g("numeric");continue}if(k.role==="source"||k.role==="target"){const Y=Q(W);Y?H[V]=Y.id:g("twoCategorical");continue}if(k.accepts==="field"){if(V==="geometry"){const Y=Q(oe);Y?H[V]=Y.id:k.required&&g("geometry")}else{if(V==="lat"||V==="lon")continue;{const Y=Q(M);Y?H[V]=Y.id:R&&g("twoDate")}}continue}const $=k.path==="code"?[W]:c.has(e)?[M]:h.has(e)?[M,W]:[W,M];let S;if(m.has(e)&&k.role==="x"){S=Q(E);const Y=Q(E);if(!S||!Y){g("twoNumeric");continue}H.x=S.id,H.y=Y.id;continue}for(const Y of $)if(S=Q(Y),S)break;S?H[V]=S.id:N&&g(c.has(e)?"date":"categorical")}if(f.some(k=>k.path==="lat")&&f.some(k=>k.path==="lon")&&H.geometry===void 0){const k=I(/^lat/i);k&&q.add(k.id);const V=I(/^(lon|lng)/i);k&&V?(H.lat=k.id,H.lon=V.id):g("location")}return{options:H,need:K}}const T=()=>`
|
|
97
|
+
`;function Q(W,L,_,i,v){const k=W.createElement("button");return k.type="button",k.className=L,k.setAttribute("aria-label",_),k.textContent=i,k.addEventListener("click",v),k}function ie(W){const{root:L,chrome:_,t:i,getPanels:v,setCollapsed:k}=W,r=L.ownerDocument,m=r.createElement("div");m.className="lattice-designer-topbar",_.appendChild(m);const c=r.createElement("div");c.className="lattice-designer-filterbar",L.appendChild(c);let b="wide";const y={left:!1,right:!1};let P=!1;const u={},E=(U,M)=>{const R=r.createElement("div");R.className=`lattice-designer-rail lattice-designer-rail--${U}`,R.setAttribute("role","group"),R.setAttribute("aria-label",M);const H=r.createElement("div");H.className="lattice-designer-rail-head";const f=r.createElement("span");f.className="lattice-designer-rail-title",f.textContent=M;const g=Q(r,"lattice-designer-rail-toggle",M,"",()=>I.toggle()),I={el:R,head:H,toggleBtn:g,get collapsed(){return b==="compact"||b==="narrow"&&U==="right"?!y[U]:d(U)},collapse(){return I.set(!0)},expand(){return I.set(!1)},toggle(){return I.set(!I.collapsed)},set(j){if(b==="compact"||b==="narrow"&&U==="right"){if(y[U]===!j)return j;if(y[U]=!j,W.announce(U,y[U]),B(),y[U]){const A=R.querySelector('button, input, select, textarea, [tabindex="0"]');A&&A.focus&&A.focus()}return j}return k(U,!!j),I.collapsed}};return H.appendChild(f),H.appendChild(g),R.appendChild(H),I},d=U=>{const M=v()[U];if(F(M)&&M.collapsed===!0)return!0;const R=v().palette;return U==="left"&&F(R)&&R.collapsed===!0},w=E("left",i("designer.rail.left")),G=E("right",i("designer.rail.right")),N=r.createElement("div");N.className="lattice-designer-rail-sections",w.el.appendChild(N);const T=new Map;let C=0;const h=U=>{const M=String(U),R=T.get(M);if(R)return R.body;C+=1;const H=M!=="assist",f=r.createElement("div");f.className="lattice-designer-rail-section",f.setAttribute("data-section",M),f.setAttribute("data-expanded",H?"true":"false");const g=i(`designer.rail.section.${M}`),I=r.createElement("button");I.type="button",I.className="lattice-designer-rail-section-head",I.setAttribute("aria-expanded",H?"true":"false"),I.textContent=g===`designer.rail.section.${M}`?M:g;const j=r.createElement("div");return j.className="lattice-designer-rail-body",j.id=`lattice-designer-rail-${M.replace(/[^a-z0-9_-]/gi,"-")}-${C}`,H||j.setAttribute("hidden",""),I.setAttribute("aria-controls",j.id),I.addEventListener("click",()=>{const A=I.getAttribute("aria-expanded")!=="true";I.setAttribute("aria-expanded",A?"true":"false"),f.setAttribute("data-expanded",A?"true":"false"),A?j.removeAttribute("hidden"):j.setAttribute("hidden","")}),f.appendChild(I),f.appendChild(j),N.appendChild(f),T.set(M,{el:f,head:I,body:j}),j};h("palette"),h("data");const $=T.get("palette").el,a=T.get("data").el,n=r.createElement("div");n.className="lattice-designer-rail-divider",n.setAttribute("role","separator"),n.setAttribute("aria-orientation","horizontal"),n.setAttribute("aria-label",i("designer.rail.divider")),n.tabIndex=0,N.insertBefore(n,a);let t=.5;const e=()=>{$.style.setProperty("--lattice-designer-split",String(t)),a.style.setProperty("--lattice-designer-split",String(1-t))};e();const s=U=>{if(!$.getBoundingClientRect||!a.getBoundingClientRect)return;const M=$.getBoundingClientRect().top,H=a.getBoundingClientRect().bottom-M;H<=0||(t=Math.max(.15,Math.min(.85,(U-M)/H)),e())};let x=!1;n.addEventListener("pointerdown",U=>{if(x=!0,n.setPointerCapture)try{n.setPointerCapture(U.pointerId)}catch{}U.preventDefault()}),n.addEventListener("pointermove",U=>{x&&s(U.clientY)}),n.addEventListener("pointerup",U=>{if(x=!1,n.releasePointerCapture)try{n.releasePointerCapture(U.pointerId)}catch{}}),n.addEventListener("keydown",U=>{U.key==="ArrowUp"?(t=Math.max(.15,t-.05),e(),U.preventDefault()):U.key==="ArrowDown"&&(t=Math.min(.85,t+.05),e(),U.preventDefault())});const S=r.createElement("div");S.className="lattice-designer-rail-body",G.el.appendChild(S),_.appendChild(w.el),_.appendChild(G.el);for(const U of["left","right"]){const M=Q(r,"lattice-designer-rail-toggle",i(`designer.rail.${U}`),U==="left"?"☰":"⚙",()=>{y[U]=!y[U],W.announce(U,y[U]),B()});M.setAttribute("data-rail-toggle",U),M.setAttribute("aria-expanded","false"),u[U]=M,m.appendChild(M)}function B(){const U=P,M=b==="compact"||b==="narrow";U||(y.right=!1),L.setAttribute("data-layout",b),L.setAttribute("data-left",b!=="compact"&&d("left")?"collapsed":"open"),L.setAttribute("data-right",U?v().right&&v().right.collapsed===!0?"collapsed":"open":"none");for(const[R,H]of[["left",w],["right",G]]){const f=!(b==="compact"||b==="narrow"&&R==="right")&&d(R),g=b==="compact"||b==="narrow"&&R==="right";H.el.setAttribute("data-collapsed",f?"true":"false"),H.el.setAttribute("data-drawer",g?y[R]?"open":"closed":"none");const I=g?y[R]:!f;H.toggleBtn.setAttribute("aria-expanded",I?"true":"false");const j=i(`designer.rail.${I?"collapse":"expand"}`,{name:i(`designer.rail.${R}`)});H.toggleBtn.setAttribute("aria-label",j),H.toggleBtn.textContent=R==="left"?I?"‹":"›":I?"›":"‹";const A=R==="left"?N:S;f?A.setAttribute("hidden",""):A.removeAttribute("hidden"),R==="right"&&(U?H.el.removeAttribute("hidden"):H.el.setAttribute("hidden",""))}for(const R of["left","right"])(b==="compact"||R==="right"&&M&&U)&&(R==="left"||U)?u[R].removeAttribute("hidden"):u[R].setAttribute("hidden",""),u[R].setAttribute("aria-expanded",y[R]?"true":"false")}const Y=()=>{const U=L.getBoundingClientRect?L.getBoundingClientRect().width:0,M=!U||U>=z?"wide":U>=fe?"narrow":"compact";M!==b&&(b=M,y.left=!1,y.right=P&&M!=="wide",B())};let te=null;const q=(L.ownerDocument.defaultView||{}).ResizeObserver;de(q)&&(te=new q(()=>Y()),te.observe(L)),Y(),B();const ne=Object.freeze({left:Object.freeze({slot:h,get collapsed(){return w.collapsed},collapse:w.collapse,expand:w.expand,toggle:w.toggle,get el(){return w.el}}),right:Object.freeze({slot(){return S},get collapsed(){return G.collapsed},collapse:G.collapse,expand:G.expand,toggle:G.toggle,get el(){return G.el}}),get layout(){return b},get filterBar(){return c}});return{topbar:m,rails:ne,sync:B,measure:Y,setSelection(U){const M=P;P=!!U,P&&!M&&b!=="wide"&&(y.right=!0),B()},destroy(){te&&te.disconnect(),te=null}}}}),rt("packages/modules/charts/fills.js",function(o,ce){"use strict";Object.defineProperty(o,"PATTERNS",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"GRADIENTS",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"isFill",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"isPaintRef",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"paintFallback",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"normaliseFill",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"swatchCss",{enumerable:!0,get:function(){return k}}),Object.defineProperty(o,"createFillRegistry",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"rowPaint",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"patternSeries",{enumerable:!0,get:function(){return c}}),Object.defineProperty(o,"paintSolid",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"rowFillSource",{enumerable:!0,get:function(){return y}}),Object.defineProperty(o,"nodePaint",{enumerable:!0,get:function(){return P}});const F=ce("packages/core/src/internal/util.js").warnOnce,l=Object.freeze(["hatch","crosshatch","dots","grid"]),de=Object.freeze(["linear","radial"]),z=8,fe="#0072b2";let J=0;const Q=new Map;function ie(u){return!!u&&typeof u=="object"&&!Array.isArray(u)&&(typeof u.gradient=="string"||typeof u.pattern=="string")}function W(u){return typeof u=="string"&&u.startsWith("url(#")}function L(u){if(typeof u!="string")return u==null?"":String(u);if(!u.startsWith("url("))return u;const E=u.indexOf(")");return(E<0?"":u.slice(E+1).trim())||fe}function _(u,E){F(`chart:fill:invalid:${u}`,`a chart fill object was ignored: ${E} The mark was drawn in a solid colour instead. A fill is a gradient object (gradient: "linear" or "radial", with stops of [offset, colour]) or a pattern object (pattern: "hatch", "crosshatch", "dots" or "grid", with a colour).`)}function i(u,E){if(!ie(u))return null;const d=E||fe;if(typeof u.gradient=="string"){if(!de.includes(u.gradient))return _("gradient",`the gradient "${u.gradient}" is not one of ${de.join(", ")}.`),null;const T=Array.isArray(u.stops)?u.stops:[],C=[];for(const $ of T){const a=Array.isArray($)?Number($[0]):Number($&&$.offset),n=Array.isArray($)?$[1]:$&&$.colour;!Number.isFinite(a)||typeof n!="string"||!n||C.push({offset:Math.min(1,Math.max(0,a)),colour:n})}if(C.length<2)return _("stops","a gradient needs at least two [offset, colour] stops."),null;C.sort(($,a)=>$.offset-a.offset);const h=Number.isFinite(Number(u.angle))?Number(u.angle):180;return{kind:u.gradient,angle:h,stops:C,solid:C[0].colour}}if(!l.includes(u.pattern))return _("pattern",`the pattern "${u.pattern}" is not one of ${l.join(", ")}.`),null;const w=Number(u.size),G=Number(u.angle),N=typeof u.colour=="string"&&u.colour?u.colour:d;return{kind:"pattern",pattern:u.pattern,colour:N,background:typeof u.background=="string"&&u.background?u.background:null,size:Number.isFinite(w)&&w>=2?w:z,angle:Number.isFinite(G)?G:u.pattern==="grid"||u.pattern==="dots"?0:45,solid:N}}function v(u){if(u.kind==="pattern"){const d=u.colour,w=u.size,G=Math.max(1,w/5),N=u.background||"transparent",T=C=>`repeating-linear-gradient(${C+90}deg,${d} 0 ${G}px,transparent ${G}px ${w}px)`;return u.pattern==="hatch"?`${T(u.angle)},${N}`:u.pattern==="crosshatch"?`${T(u.angle)},${T(u.angle+90)},${N}`:u.pattern==="grid"?`${T(u.angle)},${T(u.angle+90)},${N}`:`radial-gradient(circle at 50% 50%,${d} ${w/6}px,transparent ${w/6+.5}px) 0 0/${w}px ${w}px,${N}`}const E=u.stops.map(d=>`${d.colour} ${Math.round(d.offset*100)}%`).join(",");return u.kind==="radial"?`radial-gradient(circle,${E})`:`linear-gradient(${u.angle}deg,${E})`}function k(u){if(!W(u))return typeof u=="string"?u:"";const E=String(u).indexOf(")"),d=String(u).slice(5,E),w=Q.get(d);return w?v(w):L(u)}function r(u){const E=`lattice-fill-${++J}`;let d=new Map,w=0;const G=(T,C)=>{const h=u.ownerDocument.createElementNS("http://www.w3.org/2000/svg",T);for(const $ of Object.keys(C))h.setAttribute($,String(C[$]));return h},N=(T,C)=>{if(C.kind==="pattern"){const $=C.size,a=Math.max(1,$/5),n=G("pattern",{id:T,width:$,height:$,patternUnits:"userSpaceOnUse"});C.angle&&n.setAttribute("patternTransform",`rotate(${C.angle})`),C.background&&n.appendChild(G("rect",{width:$,height:$,fill:C.background}));const t={stroke:C.colour,"stroke-width":a};C.pattern==="dots"?n.appendChild(G("circle",{cx:$/2,cy:$/2,r:Math.max(1,$/6),fill:C.colour})):(n.appendChild(G("line",{x1:$/2,y1:0,x2:$/2,y2:$,...t})),C.pattern!=="hatch"&&n.appendChild(G("line",{x1:0,y1:$/2,x2:$,y2:$/2,...t}))),u.appendChild(n);return}let h;if(C.kind==="radial")h=G("radialGradient",{id:T,cx:.5,cy:.5,r:.5});else{const $=C.angle*Math.PI/180,a=Math.sin($)/2,n=-Math.cos($)/2;h=G("linearGradient",{id:T,x1:+(.5-a).toFixed(4),y1:+(.5-n).toFixed(4),x2:+(.5+a).toFixed(4),y2:+(.5+n).toFixed(4)})}for(const $ of C.stops)h.appendChild(G("stop",{offset:$.offset,"stop-color":$.colour}));u.appendChild(h)};return{prefix:E,paint(T,C){const h=i(T,C);if(!h)return C||fe;if(!u||!u.ownerDocument)return h.solid;const $=JSON.stringify(h);let a=d.get($);if(!a){const n=`${E}-${w++}`;N(n,h),Q.set(n,h),a=`url(#${n}) ${h.solid}`,d.set($,a)}return a},reset(){for(const T of d.values())Q.delete(T.slice(5,T.indexOf(")")));if(d=new Map,w=0,u)for(;u.firstChild;)u.removeChild(u.firstChild)},ids(){return[...d.values()].map(T=>T.slice(5,T.indexOf(")")))}}}function m(u,E,d){if(u==null||u==="")return null;const w=L(d);if(ie(u))return E?E.paint(u,w):(i(u,w)||{}).solid||null;if(typeof u=="string"){if(l.includes(u)){const G={pattern:u,colour:w};return E?E.paint(G,w):w}return u}return null}function c(u){const E=[{pattern:"hatch",angle:45},{pattern:"dots"},{pattern:"crosshatch",angle:45},{pattern:"hatch",angle:135},{pattern:"grid"},{pattern:"dots",size:5},{pattern:"hatch",angle:0},{pattern:"crosshatch",angle:0,size:6}];return u.map((d,w)=>({...E[w%E.length],colour:d,background:"var(--lattice-background, #fff)"}))}function b(u){return W(u)?String(u).replace(/^url\([^)]*\)\s*/,""):u}function y(u,E){const d=u.fill;if(ie(d))return(G,N)=>m(d,E.fills,b(N));if(typeof d=="function")return(G,N)=>{let T=null;try{T=d({label:G.label,x:G.x,y:G.y,rowKey:G.rowKey})}catch{T=null}return m(T,E.fills,b(N))};const w=typeof d=="string"?d:d&&typeof d=="object"&&typeof d.col=="string"?d.col:null;return w?(G,N)=>G.rowKey===void 0||G.rowKey===null?null:m(u.grid.rows.value(G.rowKey,w),E.fills,b(N)):null}function P(u,E,d){return u&&u({label:E.label,x:E.value,y:E.total,rowKey:E.rowKey},d)||d}}),rt("packages/modules/charts/scheme.js",function(o,ce){"use strict";Object.defineProperty(o,"PALETTE",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"SCHEMES",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"registerScheme",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"setDefaultScheme",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"schemeNames",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"resolveScheme",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"RAMP_SCALES",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"toRgb",{enumerable:!0,get:function(){return u}}),Object.defineProperty(o,"rampStops",{enumerable:!0,get:function(){return E}});const F=ce("packages/core/src/internal/util.js").warnOnce,l=ce("packages/modules/charts/fills.js"),de=l.isFill,z=l.patternSeries,fe=l.rowPaint,J=Object.freeze(["#0072b2","#e69f00","#009e73","#cc79a7","#56b4e9","#d55e00","#7a5195","#6b7d8c"]),Q=Object.freeze({default:{series:J,sequential:["#ecf3f9","#005280"],diverging:["#b04a00","#f7f7f7","#005280"],positive:"#009e73",negative:"#d55e00"},bright:{series:["#1f77d0","#ff7f0e","#2ca02c","#d62728","#9467bd","#17becf","#e377c2","#7f7f7f"],sequential:["#eef4fb","#1f77d0"],diverging:["#d62728","#f7f7f7","#1f77d0"],positive:"#2ca02c",negative:"#d62728"},earth:{series:["#5b7c6f","#c08b52","#7a6a53","#a4553f","#4e6a83","#8f8259","#6d5566","#8c9196"],sequential:["#f2efe9","#4e6a83"],diverging:["#a4553f","#f2efe9","#4e6a83"],positive:"#5b7c6f",negative:"#a4553f"},mono:{series:["#0b2a3d","#17475f","#2c6480","#4a82a0","#6da0bd","#94bcd6","#bcd7e9","#dfecf5"],sequential:["#eef3f7","#0b2a3d"],diverging:["#7a5c00","#f5f5f5","#0b2a3d"],positive:"#17475f",negative:"#7a5c00"},patterns:{series:z(J),sequential:["#ecf3f9","#005280"],diverging:["#b04a00","#f7f7f7","#005280"],positive:"#009e73",negative:"#d55e00"}}),ie=new Map;let W="default";function L(d,w){!d||!w||ie.set(String(d),w)}function _(d){if(typeof d=="string"){W=d;return}d&&typeof d=="object"&&(ie.set("__default__",d),W="__default__")}function i(){return[...Object.keys(Q),...ie.keys()].filter(d=>!d.startsWith("__"))}function v(d){return ie.has(d)?ie.get(d):Q[d]||null}const k=["series","sequential","diverging","positive","negative"];function r(d){return!d||typeof d!="object"||Array.isArray(d)?!1:!k.some(w=>w in d)}function m(d,w){const G=w&&w.fills||null,N=v(W)||Q.default,T=d&&d.scheme,C=r(T)?T:null,h=Array.isArray(T)&&T.length?T:null,$=typeof T=="string"?v(T):C||Array.isArray(T)?null:T||null,a=(d&&Array.isArray(d.palette)&&d.palette.length?d.palette:null)||h;C&&a&&F("chart:scheme:array-and-map",'chart "scheme" was given as a name map together with a "palette" array; the two do not combine. Colours came from the map and the array was ignored. Pass one or the other.');const n=C?null:a,t={...Q.default,...N,...$||{}};n&&(t.series=n);const e=d&&d.ramp&&typeof d.ramp=="object"&&!Array.isArray(d.ramp)?d.ramp:null,s=e?e.colours:d&&d.ramp,x=Array.isArray(s)&&s.length>=2?s:null;x&&(t.sequential=x);const S=e?y(e.scale):null,B=!!($||n||C),Y=t.series&&t.series.length?t.series:J,te=new Map;let q=0;return{...t,series:(U,M)=>{if(C&&M!==void 0&&M!==null){const R=String(M);return Object.prototype.hasOwnProperty.call(C,R)?c(C[R],G,U):(te.has(R)||te.set(R,q++),c(P(Y,te.get(R),!0),G,te.get(R)))}return c(P(Y,U,B),G,U)},explicit:B,nameMap:!!C,rampScale:S,fills:G}}function c(d,w,G){if(!de(d))return d;const N=J[(G%J.length+J.length)%J.length];return fe(d,w,N)||N}const b=Object.freeze(["linear","log","quantile"]);function y(d){return d==null?null:b.includes(d)?d:(F(`chart:ramp:scale:${String(d)}`,`chart "ramp.scale" was "${String(d)}", which is not a ramp scale; the chart chose one from its values instead. Use "linear", "log" or "quantile".`),null)}function P(d,w,G){const N=(w%d.length+d.length)%d.length;return G||typeof d[N]!="string"?d[N]:`var(--lattice-chart-${N+1}, ${d[N]})`}function u(d){if(typeof d!="string")return null;const w=d.trim(),G=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(w);if(G){const C=G[1];return C.length===3?[0,1,2].map(h=>parseInt(C[h]+C[h],16)):[0,2,4].map(h=>parseInt(C.slice(h,h+2),16))}const N=/^rgba?\(([^)]+)\)$/i.exec(w);if(!N)return null;const T=N[1].split(/[\s,/]+/).filter(Boolean).slice(0,3).map(Number);return T.length===3&&T.every(C=>Number.isFinite(C))?T:null}function E(d,w){const G=w?d.diverging:d.sequential,N=w?Q.default.diverging:Q.default.sequential,T=(Array.isArray(G)?G:N).map((C,h)=>u(C)||u(N[h])||[0,0,0]);return T.length>=2?T:N.map(C=>u(C))}}),rt("packages/modules/charts/svg.js",function(o,ce){"use strict";Object.defineProperty(o,"SVG_NS",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(o,"el",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"svg",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"attr",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"attrs",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"setText",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"clear",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"append",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"path",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"ribbonPath",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"round",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"pathRings",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"insideRings",{enumerable:!0,get:function(){return v}});const ke="http://www.w3.org/2000/svg";function F(k){const r=k.indexOf(")");return r<0?k:k.slice(r+1).trim()||"#0072b2"}function l(k,r,m){const c=k.createElement(r);return m&&c.setAttribute("class",m),c}function de(k,r,m){const c=k.createElementNS(ke,r);if(m)for(const b of Object.keys(m))c.setAttribute(b,String(m[b]));return c}function z(k,r,m){if(!k)return;if(m==null){k.removeAttribute(r);return}let c=String(m);c.startsWith("url(#")&&(r==="stroke"||r==="fill"&&k.localName==="text")&&(c=F(c)),k.setAttribute(r,c)}function fe(k,r){if(k)for(const m of Object.keys(r))z(k,m,r[m])}function J(k,r){k&&(k.textContent=r==null?"":String(r))}function Q(k){if(k)for(;k.firstChild;)k.removeChild(k.firstChild)}function ie(k,r){for(const m of r)m&&k.appendChild(m);return k}function W(k){return k.join(" ")}function L(k){if(!k||k.length<2)return"";const r=["M",k[0].x,k[0].upper];for(let m=1;m<k.length;m++)r.push("L",k[m].x,k[m].upper);for(let m=k.length-1;m>=0;m--)r.push("L",k[m].x,k[m].lower);return r.push("Z"),W(r)}function _(k){return Math.round(k*100)/100}function i(k){const r=[];let m=[];const c=String(k||"").match(/[A-Za-z]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi)||[];let b="",y=[];const P=()=>{if(!b||!y.length){y=[];return}if(b==="M"||b==="L")for(let u=0;u+1<y.length;u+=2)m.push([y[u],y[u+1]]);else b!=="Z"&&y.length>=2&&m.push([y[y.length-2],y[y.length-1]]);y=[]};for(const u of c){if(/[A-Za-z]/.test(u)){if(P(),u==="Z"||u==="z"){m.length>2&&r.push(m),m=[],b="";continue}u==="M"&&m.length>2&&(r.push(m),m=[]),b=u;continue}y.push(Number(u))}return P(),m.length>2&&r.push(m),r}function v(k,r,m){let c=!1;for(const b of k)for(let y=0,P=b.length-1;y<b.length;P=y++){const[u,E]=b[y],[d,w]=b[P];E>m!=w>m&&r<(d-u)*(m-E)/(w-E||1e-12)+u&&(c=!c)}return c}}),rt("packages/modules/charts/curve.js",function(o,ce){"use strict";Object.defineProperty(o,"CURVES",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"STEP_MODES",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"resolveCurve",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"curveCommands",{enumerable:!0,get:function(){return fe}});const F=ce("packages/modules/charts/svg.js").round,l=Object.freeze(["linear","monotone","catmullRom","step"]),de=Object.freeze(["after","before","middle"]);function z(L,_){let i=L;if(i&&typeof i=="object"&&!Array.isArray(i)&&typeof i.type!="string"&&(i=_!=null&&Object.prototype.hasOwnProperty.call(i,_)?i[_]:void 0),i==null||i===!0||i===!1)return null;if(typeof i=="string")return i==="linear"?null:l.includes(i)?{type:i,tension:1,mode:"after"}:null;if(typeof i=="object"){const v=typeof i.type=="string"&&l.includes(i.type)?i.type:"linear";if(v==="linear")return null;const k=Number.isFinite(i.tension)?Math.max(0,Math.min(1,Number(i.tension))):1,r=de.includes(i.mode)?i.mode:"after";return{type:v,tension:k,mode:r}}return null}function fe(L,_){return L.length?!_||_.type==="linear"?J(L):_.type==="step"?Q(L,_.mode):_.type==="monotone"?ie(L):_.type==="catmullRom"?W(L,_.tension):J(L):[]}function J(L){const _=["M",F(L[0].x),F(L[0].y)];for(let i=1;i<L.length;i++)_.push("L",F(L[i].x),F(L[i].y));return _}function Q(L,_){const i=["M",F(L[0].x),F(L[0].y)];for(let v=1;v<L.length;v++){const k=L[v-1].x,r=L[v-1].y,m=L[v].x,c=L[v].y;if(_==="before")i.push("L",F(k),F(c),"L",F(m),F(c));else if(_==="middle"){const b=F((k+m)/2);i.push("L",b,F(r),"L",b,F(c),"L",F(m),F(c))}else i.push("L",F(m),F(r),"L",F(m),F(c))}return i}function ie(L){const _=L.length;if(_<2)return["M",F(L[0].x),F(L[0].y)];if(_===2)return["M",F(L[0].x),F(L[0].y),"L",F(L[1].x),F(L[1].y)];const i=[];for(let r=0;r<_-1;r++){const m=L[r+1].x-L[r].x,c=L[r+1].y-L[r].y;i[r]=m===0?0:c/m}const v=new Array(_);v[0]=i[0],v[_-1]=i[_-2];for(let r=1;r<_-1;r++)v[r]=i[r-1]*i[r]<=0?0:(i[r-1]+i[r])/2;for(let r=0;r<_-1;r++)i[r]===0&&(v[r]=0,v[r+1]=0);for(let r=0;r<10;r++){let m=!1;for(let c=0;c<_-1;c++){if(i[c]===0)continue;const b=v[c]/i[c],y=v[c+1]/i[c],P=b*b+y*y;if(P>9){const u=3/Math.sqrt(P);v[c]=u*b*i[c],v[c+1]=u*y*i[c],m=!0}}if(!m)break}const k=["M",F(L[0].x),F(L[0].y)];for(let r=0;r<_-1;r++){const m=L[r].x,c=L[r].y,b=L[r+1].x,y=L[r+1].y,P=b-m,u=m+P/3,E=c+v[r]*P/3,d=b-P/3,w=y-v[r+1]*P/3;k.push("C",F(u),F(E),F(d),F(w),F(b),F(y))}return k}function W(L,_){const i=L.length;if(i<2)return["M",F(L[0].x),F(L[0].y)];const v=Number.isFinite(_)?Math.max(0,Math.min(1,_)):1,k=["M",F(L[0].x),F(L[0].y)];for(let r=0;r<i-1;r++){const m=L[r-1]||L[r],c=L[r],b=L[r+1],y=L[r+2]||L[r+1],P=c.x+(b.x-m.x)/6*v,u=c.y+(b.y-m.y)/6*v,E=b.x-(y.x-c.x)/6*v,d=b.y-(y.y-c.y)/6*v;k.push("C",F(P),F(u),F(E),F(d),F(b.x),F(b.y))}return k}}),rt("packages/modules/charts/projection.js",function(o,ce){"use strict";Object.defineProperty(o,"MERCATOR_LIMIT",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"equalEarth",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"robinson",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"mercator",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"equirectangular",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"albers",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"transverseMercator",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"PROJECTIONS",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"DEFAULT_PROJECTION",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"resolveProjection",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"WRAP_DEGREES",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"splitAntimeridian",{enumerable:!0,get:function(){return k}}),Object.defineProperty(o,"boundsOf",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"fitted",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"graticule",{enumerable:!0,get:function(){return b}});const ke=Math.PI/180,F=Object.freeze([1.340264,-.081106,893e-6,.003796]),l=Object.freeze([[1,0],[.9986,.062],[.9954,.124],[.99,.186],[.9822,.248],[.973,.31],[.96,.372],[.9427,.434],[.9216,.4958],[.8962,.5571],[.8679,.6176],[.835,.6769],[.7986,.7346],[.7597,.7903],[.7186,.8435],[.6732,.8936],[.6213,.9394],[.5722,.9761],[.5322,1]]),de=85.05113;function z(y,P){const[u,E,d,w]=F,G=P*ke,N=Math.asin(Math.min(1,Math.max(-1,Math.sqrt(3)/2*Math.sin(G)))),T=N*N,C=T*T*T,h=Math.sqrt(3)/2*(u+3*E*T+C*(7*d+9*w*T));return[y*ke*Math.cos(N)/h,N*(u+E*T+C*(d+w*T))]}function fe(y,P){const u=Math.min(Math.abs(P),90),E=Math.min(l.length-2,Math.floor(u/5)),d=(u-E*5)/5,[w,G]=l[E],[N,T]=l[E+1],C=w+(N-w)*d,h=G+(T-G)*d;return[y*ke*C,(P<0?-h:h)*(Math.PI/2)]}function J(y,P){const u=Math.min(de,Math.max(-de,P))*ke;return[y*ke,Math.log(Math.tan(Math.PI/4+u/2))]}function Q(y,P){return[y*ke,P*ke]}function ie(y={}){const[P,u]=y.parallels||[29.5,45.5],[E,d]=y.centre||[-96,37.5],w=P*ke,G=u*ke,N=Math.sin(w),T=Math.abs(w-G)<1e-9?N:(N+Math.sin(G))/2,C=Math.cos(w)**2+2*T*N,h=Math.sqrt(C-2*T*Math.sin(d*ke))/T;return($,a)=>{const n=T*(($-E)*ke),t=Math.max(0,C-2*T*Math.sin(a*ke)),e=Math.sqrt(t)/T;return[e*Math.sin(n),h-e*Math.cos(n)]}}function W(y={}){const[P,u]=y.centre||[-2,49];return(E,d)=>{const w=d*ke,G=(E-P)*ke,N=Math.cos(w)*Math.sin(G),T=Math.min(1-1e-12,Math.max(-1+1e-12,N));return[.5*Math.log((1+T)/(1-T)),Math.atan2(Math.tan(w),Math.cos(G))-u*ke]}}const L=Object.freeze({equalEarth:()=>z,robinson:()=>fe,mercator:()=>J,equirectangular:()=>Q,albers:ie,transverseMercator:W,britishNationalGrid:y=>W({centre:[-2,49],...y})}),_="equalEarth";function i(y,P={},u){if(typeof y=="function")return y;const d=L[typeof y=="string"&&y?y:_];return d?d(P):(u&&u(`chart projection ${JSON.stringify(y)} is not one this module draws; using '${_}'. Supported: ${Object.keys(L).join(", ")}.`),L[_]({}))}const v=180;function k(y){if(!Array.isArray(y)||y.length<2)return y&&y.length?[y]:[];const P=[];let u=[y[0]];for(let E=1;E<y.length;E++){const[d,w]=y[E-1],[G,N]=y[E],T=G-d;if(Math.abs(T)>v){const C=T>0?-180:180,h=T>0?T-360:T+360,$=h===0?0:Math.min(1,Math.max(0,(C-d)/h)),a=w+(N-w)*$;u.push([C,a]),P.push(u),u=[[-C,a],[G,N]]}else u.push([G,N])}return P.push(u),P.filter(E=>E.length>1)}function r(y){let P=1/0,u=1/0,E=-1/0,d=-1/0;for(const w of y||[])for(const[G,N]of w)G<P&&(P=G),G>E&&(E=G),N<u&&(u=N),N>d&&(d=N);return Number.isFinite(P)?{west:P,south:u,east:E,north:d}:null}function m(y){const{project:P,rings:u,plot:E}=y,d=typeof y.padding=="number"?y.padding:4;let w=1/0,G=1/0,N=-1/0,T=-1/0;for(const ne of u||[])for(const[U,M]of ne){const[R,H]=P(U,M);!Number.isFinite(R)||!Number.isFinite(H)||(R<w&&(w=R),R>N&&(N=R),H<G&&(G=H),H>T&&(T=H))}if(!Number.isFinite(w)||N===w||T===G)return{to:(U,M)=>{const[R,H]=P(U,M);return[E.left+E.width/2+R,E.top+E.height/2-H]},scale:1,width:E.width,height:E.height,left:E.left,top:E.top,aspect:1};const C=Math.max(1,E.width-d*2),h=Math.max(1,E.height-d*2),$=typeof y.zoom=="number"&&y.zoom>0?y.zoom:1,a=Math.min(C/(N-w),h/(T-G))*$,n=(N-w)*a,t=(T-G)*a,[e,s]=y.centre?P(y.centre[0],y.centre[1]):[(w+N)/2,(G+T)/2],x=y.centreOffset||[0,0],S=e+(x[0]||0),B=s+(x[1]||0),Y=E.left+E.width/2,te=E.top+E.height/2;return{to:(ne,U)=>{const[M,R]=P(ne,U);return[Y+(M-S)*a,te-(R-B)*a]},scale:a,width:n,height:t,left:Y-n/2,top:te-t/2,aspect:(N-w)/(T-G)}}const c=2;function b(y={}){const P=y.step&&y.step>0?y.step:30,u=[];for(let E=-180;E<=180;E+=P){const d=[];for(let w=-80;w<=80;w+=c)d.push([E,w]);u.push(d)}for(let E=-60;E<=60;E+=P){const d=[];for(let w=-180;w<=180;w+=c)d.push([w,E]);u.push(d)}return u}}),rt("packages/modules/charts/capabilities.js",function(o,ce){"use strict";Object.defineProperty(o,"AGGREGATIONS_OFFERED",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"CHART_TYPES",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"chartRoles",{enumerable:!0,get:function(){return u}}),Object.defineProperty(o,"chartOptions",{enumerable:!0,get:function(){return E}}),Object.defineProperty(o,"chartEditorModel",{enumerable:!0,get:function(){return d}});const F=ce("packages/modules/charts/scheme.js").schemeNames,de=ce("packages/modules/charts/curve.js").CURVES,fe=ce("packages/modules/charts/projection.js").PROJECTIONS,J=Object.freeze(["sum","avg","min","max","count","countDistinct","median"]),Q=Object.freeze(["line","step","area","rangeArea","bar","horizontalBar","waterfall","floatingBar","horizontalFloatingBar","populationPyramid","bullet","scatter","bubble","forest","combo","pareto","histogram","boxplot","heatmap","qq","ecdf","lorenz","correlogram","control","capability","movingRange","pie","donut","sunburst","treemap","radar","gauge","funnel","candlestick","ohlc","geomap","sankey","chord","network","stream","marimekko","violin","gantt"]),ie=new Set(["sankey","chord","network"]),W=new Set(["pie","donut","sunburst","treemap"]),L=new Set(["combo","candlestick","ohlc"]),_=new Set(["histogram","boxplot","qq","ecdf","lorenz","violin","control","capability","movingRange"]),i=new Set(["geomap","markermap","bubblemap","choropleth"]),v=new Set(["bubble","scatter"]),k=new Set(["gauge","bullet"]),r=new Set(["profile","distribution","correlation","groupComparison","modelError"]),m=new Set([...W,...ie,...i,...k,...r,"radar","funnel","heatmap"]),c=new Set(["bar","horizontalBar","line","area","scatter","bubble","combo","pareto","histogram","heatmap","pie","donut","sunburst","treemap","radar","geomap","gauge","funnel"]),b=new Set(["bar","horizontalBar","area","combo"]),y=new Set(["line","area","rangeArea"]),P=new Set(["markermap","bubblemap","choropleth"]);function u(w){if(w==="profile")return[{role:"field",accepts:"field",path:"y",required:!0}];if(w==="distribution")return[{role:"field",accepts:"field",path:"y",required:!0}];if(w==="correlation")return[{role:"columns",accepts:"measure",path:"columns",repeatable:!0,required:!0}];if(w==="groupComparison")return[{role:"field",accepts:"measure",path:"y",required:!0},{role:"group",accepts:"dimension",path:"group",required:!0}];if(w==="modelError")return[{role:"response",accepts:"measure",path:"y",required:!0},{role:"predictor",accepts:"measure",path:"x",required:!0}];if(ie.has(w))return[{role:"source",accepts:"dimension",required:!0},{role:"target",accepts:"dimension",required:!0},{role:"y",accepts:"measure",aggregated:!0}];if(w==="geomap")return[{role:"geometry",accepts:"dimension",path:"code",required:!0},{role:"measure",accepts:"measure",path:"y",aggregated:!0}];if(w==="choropleth")return[{role:"geometry",accepts:"field",path:"geometry",required:!0},{role:"measure",accepts:"measure",path:"y"},{role:"label",accepts:"dimension"}];if(i.has(w))return[{role:"geometry",accepts:"field",path:"geometry"},{role:"lat",accepts:"field",path:"lat"},{role:"lon",accepts:"field",path:"lon"},w==="bubblemap"?{role:"size",accepts:"measure",path:"size"}:{role:"measure",accepts:"measure",path:"value"},{role:"label",accepts:"dimension"}];if(W.has(w))return[{role:"x",accepts:"dimension",required:!0},{role:"y",accepts:"measure",aggregated:!0},{role:"colour",accepts:"dimension"}];if(L.has(w))return[{role:"x",accepts:"dimension",bucketable:!0},{role:"measures",accepts:"measure",aggregated:!0,repeatable:!0,required:!0},{role:"series",accepts:"dimension"}];if(_.has(w))return[{role:"x",accepts:"dimension"},{role:"y",accepts:"measure",aggregated:!0,required:!0},{role:"series",accepts:"dimension"}];if(k.has(w))return[{role:"y",accepts:"measure",aggregated:!0,required:!0}];if(w==="radar")return[{role:"x",accepts:"dimension",required:!0},{role:"y",accepts:"measure",aggregated:!0},{role:"series",accepts:"dimension"}];if(w==="funnel")return[{role:"x",accepts:"dimension",required:!0},{role:"y",accepts:"measure",aggregated:!0}];if(w==="gantt")return[{role:"label",accepts:"dimension",required:!0},{role:"start",accepts:"field"},{role:"end",accepts:"field"},{role:"series",accepts:"dimension"}];const G=[{role:"x",accepts:"dimension",bucketable:!0},{role:"y",accepts:"measure",aggregated:!0},{role:"series",accepts:"dimension"}];return v.has(w)&&G.push({role:"size",accepts:"measure",aggregated:!0}),G}function E(w){const G=[{name:"title",type:"string"}];return G.push({name:"scheme",type:"enum",values:F()}),G.push({name:"palette",type:"list",format:"colour"}),!k.has(w)&&!r.has(w)&&G.push({name:"legend",type:"boolean",default:!0}),c.has(w)&&G.push({name:"labels",type:"boolean",default:!1}),G.push({name:"tooltip",type:"boolean",default:!0}),!m.has(w)&&!_.has(w)&&(G.push({name:"axis.x.title",type:"string"}),G.push({name:"axis.x.format",type:"string",format:"date"}),G.push({name:"axis.y.title",type:"string"}),G.push({name:"axis.y.format",type:"string",format:"number"})),b.has(w)&&G.push({name:"stack",type:"enum",values:[!0,"percent"]}),y.has(w)&&G.push({name:"curve",type:"enum",values:[...de]}),P.has(w)&&G.push({name:"projection",type:"enum",values:Object.keys(fe)}),w==="choropleth"&&G.push({name:"diverging",type:"boolean",default:!1}),w==="bubblemap"&&G.push({name:"maxRadius",type:"number",min:2,max:100,step:1,default:20}),w==="distribution"&&G.push({name:"mode",type:"enum",values:["histogram","box","violin","ecdf"],default:"histogram"}),w==="correlation"&&G.push({name:"method",type:"enum",values:["pearson","spearman"],default:"pearson"}),w==="groupComparison"&&(G.push({name:"test",type:"enum",values:["auto","welch","mannWhitney","chiSquare"],default:"auto"}),G.push({name:"confidence",type:"number",min:.5,max:.999,step:.01,default:.95})),w==="modelError"&&G.push({name:"preset",type:"enum",values:["fit","residuals","influence"],default:"fit"}),w==="forecast"&&(G.push({name:"trend.method",type:"enum",values:["linear","movingAverage","exponential"],default:"linear"}),G.push({name:"trend.forecast",type:"number",min:0,max:60,step:1,default:3}),G.push({name:"trend.band",type:"enum",values:["prediction","confidence"],default:"prediction"}),G.push({name:"curve",type:"enum",values:[...de]})),G}function d(w){return{type:w,roles:u(w),options:E(w),aggregations:J}}}),rt("packages/modules/charts/registry.js",function(o,ce){"use strict";Object.defineProperty(o,"registerChartType",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"chartTypeDef",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"registeredChartTypes",{enumerable:!0,get:function(){return z}});const ke=Symbol.for("lattice-grid/charts/registry");function F(){return globalThis[ke]||(globalThis[ke]=new Map),globalThis[ke]}function l(fe,J){if(typeof fe!="string"||!fe)throw new TypeError("[lattice] registerChartType needs a non-empty type name.");if(!J||typeof J.draw!="function")throw new TypeError(`[lattice] registerChartType('${fe}') needs a { draw } function.`);F().set(fe,J)}function de(fe){return F().get(fe)||null}function z(){return[...F().keys()]}}),rt("packages/modules/designer/palette.js",function(o,ce){"use strict";Object.defineProperty(o,"PALETTE_FAMILIES",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"FILTER_TYPES",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"chartFamily",{enumerable:!0,get:function(){return G}}),Object.defineProperty(o,"bindChartDefaults",{enumerable:!0,get:function(){return T}}),Object.defineProperty(o,"paletteCss",{enumerable:!0,get:function(){return C}}),Object.defineProperty(o,"installPalette",{enumerable:!0,get:function(){return n}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return t}});const F=ce("packages/modules/dashboard/spec.js").isPlain,de=ce("packages/core/src/internal/util.js").isFunction,z=ce("packages/modules/charts/capabilities.js"),fe=z.chartEditorModel,J=z.CHART_TYPES,Q=ce("packages/modules/charts/registry.js"),ie=Q.registeredChartTypes,W=Q.chartTypeDef,_=ce("packages/modules/designer/messages.js").resolveMessages,i=Object.freeze(["comparison","trend","composition","distribution","flow","hierarchy","geo","specialist","statistics"]),v=Object.freeze(["list","range","dateRange","search"]),k=Object.freeze({comparison:["bar","horizontalBar","waterfall","floatingBar","horizontalFloatingBar","populationPyramid","bullet","combo","pareto","barRace","diverging","dumbbell","polarArea","rose","nightingale","pyramid","radialBar","slope"],trend:["line","step","area","rangeArea","candlestick","ohlc","bump","fan","serpentine","spiral","motion"],composition:["pie","donut","stream","marimekko","funnel","pictorial","venn","waffle"],distribution:["scatter","bubble","forest","histogram","boxplot","heatmap","qq","ecdf","lorenz","correlogram","violin","hexbin","polarScatter","ridgeline","splom","voronoiTreemap"],flow:["sankey","chord","network","alluvial","arc"],hierarchy:["sunburst","treemap","decomposition","forceTree","icicle","pack","tree"],geo:["geomap","markermap","bubblemap","choropleth","hexmap"],specialist:["radar","gauge","control","capability","movingRange","gantt","calendar","parallel","roc","wordCloud"]}),r=new Map(Object.entries(k).flatMap(([e,s])=>s.map(x=>[x,e]))),m=new Set(["line","step","area","rangeArea","stream","candlestick","ohlc"]),c=new Set(["candlestick","ohlc"]),b=new Set(["scatter","bubble"]),y=new Set(["histogram","boxplot","qq","ecdf","lorenz","violin","control","capability","movingRange","scatter","bubble","gauge","bullet"]),P=Object.freeze({combo:2,candlestick:4,ohlc:4}),u=new Set(["series","colour","size"]),E=new Set(["number","currency","percent"]),d=new Set(["date","datetime"]),w=new Set(["text","boolean"]);function G(e,s){return s&&i.includes(s.family)?s.family:r.get(e)||"specialist"}const N=e=>{const s=String(e).replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim().toLowerCase();return s.charAt(0).toUpperCase()+s.slice(1)};function T(e,s,x){const S=x.filter(g=>E.has(g.type)),B=x.filter(g=>d.has(g.type)),Y=x.filter(g=>w.has(g.type)),te=x.filter(g=>g.type==="geometry"),q=new Set,ne=g=>{const I=g.find(j=>!q.has(j.id));return I&&q.add(I.id),I},U={type:e},M=s.some(g=>g.required),R=g=>S.find(I=>!q.has(I.id)&&g.test(I.id));let H=null;const f=g=>{H||(H=g)};for(const g of s){const I=g.path||g.role;if(u.has(g.role)&&!g.required||g.role==="label"&&!g.required)continue;const j=e==="gantt"&&(g.role==="start"||g.role==="end");if(M&&!g.required&&!j&&g.accepts!=="measure"&&I!=="lat"&&I!=="lon")continue;const A=g.required||j||!M&&(g.role==="x"||g.role==="y")||g.role==="y"&&g.accepts==="measure"&&!!g.aggregated;if(g.accepts==="measure"){if(b.has(e)&&g.role==="y")continue;const se=g.aggregated&&!y.has(e),V=g.repeatable&&P[e]||1,O=[];for(;O.length<V;){const oe=ne(S);if(!oe)break;O.push(oe)}const X=oe=>se?{col:oe.id,fn:"sum"}:oe.id;g.repeatable?O.length===V?U[I]=O.map(X):f(V===4?"fourNumeric":V===2?"twoNumeric":"numeric"):O.length?U[I]=X(O[0]):A&&f("numeric");continue}if(g.role==="source"||g.role==="target"){const se=ne(Y);se?U[I]=se.id:f("twoCategorical");continue}if(g.accepts==="field"){if(I==="geometry"){const se=ne(te);se?U[I]=se.id:g.required&&f("geometry")}else{if(I==="lat"||I==="lon")continue;{const se=ne(B);se?U[I]=se.id:j&&f("twoDate")}}continue}const D=g.path==="code"?[Y]:c.has(e)?[B]:m.has(e)?[B,Y]:[Y,B];let p;if(b.has(e)&&g.role==="x"){p=ne(S);const se=ne(S);if(!p||!se){f("twoNumeric");continue}U.x=p.id,U.y=se.id;continue}for(const se of D)if(p=ne(se),p)break;p?U[I]=p.id:A&&f(c.has(e)?"date":"categorical")}if(s.some(g=>g.path==="lat")&&s.some(g=>g.path==="lon")&&U.geometry===void 0){const g=R(/^lat/i);g&&q.add(g.id);const I=R(/^(lon|lng)/i);g&&I?(U.lat=g.id,U.lon=I.id):f("location")}return{options:U,need:H}}const C=()=>`
|
|
87
98
|
.lattice-designer-palette{display:flex;flex-direction:column;gap:var(--lattice-space,4px);min-height:0}
|
|
88
99
|
.lattice-designer-palette[hidden]{display:none}
|
|
89
|
-
.lattice-designer-palette input,.lattice-designer-palette select{font:
|
|
90
|
-
border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius,4px);
|
|
91
|
-
padding:var(--lattice-space
|
|
92
|
-
.lattice-designer-palette-group-head{display:flex;align-items:center;gap:var(--lattice-space
|
|
100
|
+
.lattice-designer .lattice-designer-palette input,.lattice-designer .lattice-designer-palette select{font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);background:var(--lattice-surface);
|
|
101
|
+
border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius,4px);margin:0;
|
|
102
|
+
padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);min-width:0;box-sizing:border-box;width:100%}
|
|
103
|
+
.lattice-designer .lattice-designer-palette-group-head{display:flex;align-items:center;gap:var(--lattice-designer-space-2);width:100%;
|
|
104
|
+
font:var(--lattice-designer-font-heading) var(--lattice-font-family);box-sizing:border-box;margin:0;
|
|
93
105
|
font-weight:var(--lattice-header-font-weight,600);color:var(--lattice-foreground);background:transparent;border:0;
|
|
94
|
-
padding:var(--lattice-space
|
|
106
|
+
padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);cursor:pointer;text-align:start}
|
|
95
107
|
.lattice-designer-palette-group-head:hover,.lattice-designer-palette-entry:hover:not([aria-disabled="true"]){background:var(--lattice-hovered-background)}
|
|
96
108
|
.lattice-designer-palette ul{list-style:none;margin:0;padding:0}
|
|
97
|
-
.lattice-designer-palette-entry{display:flex;align-items:center;gap:
|
|
109
|
+
.lattice-designer .lattice-designer-palette-entry{display:flex;align-items:center;gap:var(--lattice-designer-space-2);width:100%;
|
|
110
|
+
font:var(--lattice-designer-font-body) var(--lattice-font-family);box-sizing:border-box;margin:0;
|
|
98
111
|
color:var(--lattice-foreground);background:transparent;border:0;border-radius:var(--lattice-radius,4px);
|
|
99
|
-
padding:var(--lattice-space
|
|
112
|
+
padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);cursor:grab;text-align:start}
|
|
100
113
|
.lattice-designer-palette-entry[aria-disabled="true"]{opacity:.6;cursor:not-allowed}
|
|
101
114
|
.lattice-designer-palette-entry:focus-visible,.lattice-designer-palette-group-head:focus-visible,.lattice-designer-palette-strip button:focus-visible{
|
|
102
115
|
outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:-2px;box-shadow:0 0 0 2px var(--lattice-focus-color)}
|
|
103
116
|
.lattice-designer-palette-entry svg,.lattice-designer-palette-strip svg{flex:0 0 auto;width:16px;height:16px}
|
|
104
117
|
.lattice-designer-palette-name{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
105
|
-
.lattice-designer-palette-reason{display:block;font-
|
|
118
|
+
.lattice-designer-palette-reason{display:block;font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground-muted,inherit)}
|
|
106
119
|
.lattice-designer-palette-empty{padding:var(--lattice-space,4px);color:var(--lattice-foreground-muted,inherit)}
|
|
107
120
|
.lattice-designer-palette-strip{display:none;flex-direction:column;align-items:center;gap:var(--lattice-space,4px);
|
|
108
121
|
padding:var(--lattice-space,4px) 0;overflow:auto;flex:1 1 auto;min-height:0}
|
|
@@ -110,24 +123,108 @@ ${i}`,messages:[{role:"system",content:fe},{role:"user",content:i}],schema:y};re
|
|
|
110
123
|
.lattice-designer-palette-strip button{display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;padding:0;
|
|
111
124
|
color:var(--lattice-foreground);background:transparent;border:var(--lattice-border-width,1px) solid transparent;border-radius:var(--lattice-radius,4px);cursor:pointer}
|
|
112
125
|
.lattice-designer-palette-strip button:hover{background:var(--lattice-hovered-background)}
|
|
113
|
-
`,p=Object.freeze({grid:"M2.5 3.5h11v9h-11zM2.5 7h11M2.5 10h11M6.5 3.5v9",map:"M2.5 4 6 2.5l4 1.5 3.5-1.5v9.5L10 13.5 6 12l-3.5 1.5z",kpi:"M3 12.5V9M7 12.5V6M11 12.5V3.5",text:"M3 4h10M3 8h10M3 12h6",list:"M4 4h8M4 8h8M4 12h8",range:"M2.5 8h11M5 5.5v5M11 5.5v5",dateRange:"M3 3.5h10v10H3zM3 6.5h10M6 9h4",search:"M7 11.5a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9ZM10.3 10.3l3.2 3.2",comparison:"M3 13V8M7 13V4M11 13V6",trend:"M2.5 12 6 8l3 2.5 4.5-6",composition:"M8 2.5a5.5 5.5 0 1 0 5.5 5.5H8z",distribution:"M4 11.5a1 1 0 1 0 0-.1M7 6a1 1 0 1 0 0-.1M10 9a1 1 0 1 0 0-.1M12 4.5a1 1 0 1 0 0-.1",flow:"M2.5 4h4c3 0 3 8 7 8M2.5 12h4c3 0 3-8 7-8",hierarchy:"M2.5 2.5h11v4h-11zM2.5 8.5h5v5h-5zM9 8.5h4.5v5H9z",geo:"M8 14s4.5-4 4.5-7.5a4.5 4.5 0 1 0-9 0C3.5 10 8 14 8 14ZM8 8.5a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z",specialist:"M8 2.5l1.6 3.4 3.7.4-2.8 2.5.8 3.7L8 10.6 4.7 12.5l.8-3.7L2.7 6.3l3.7-.4z",statistics:"M2.5 13h11M3 13c0-4.5 1.3-8 2.6-8s1.3 6 2.4 6 1.4-6 2.6-6 1.9 7.5 2.4 8",line:"M2.5 12 6 8l3 2.5 4.5-6",area:"M2.5 12.5 6 8l3 2.5 4.5-6v8z",pie:"M8 2.5a5.5 5.5 0 1 0 5.5 5.5H8z",donut:"M8 2.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11ZM8 6a2 2 0 1 0 0 4 2 2 0 0 0 0-4Z",scatter:"M4 11.5a1 1 0 1 0 0-.1M7 6a1 1 0 1 0 0-.1M10 9a1 1 0 1 0 0-.1M12 4.5a1 1 0 1 0 0-.1",horizontalBar:"M3 3h8M3 7h5M3 11h10"});function v(e,f,d){const E="http://www.w3.org/2000/svg",M=e.createElementNS(E,"svg");M.setAttribute("viewBox","0 0 16 16"),M.setAttribute("width","16"),M.setAttribute("height","16"),M.setAttribute("aria-hidden","true"),M.setAttribute("focusable","false");const W=e.createElementNS(E,"path");return W.setAttribute("d",p[f]||p[d||"specialist"]),W.setAttribute("fill","none"),W.setAttribute("stroke","currentColor"),W.setAttribute("stroke-width","1.4"),W.setAttribute("stroke-linecap","round"),W.setAttribute("stroke-linejoin","round"),M.appendChild(W),M}const n="application/x-lattice-palette";function t(e,f={}){const d=D(f&&f.messages),E=F(f.factories)?f.factories:{},M=globalThis.LatticeGrid||{},W=(he,ie)=>ue(E[he])?E[he]:ue(M[he])?M[he]:ie,oe=W("chartEditorModel",fe),q=W("registeredChartTypes",ne),Q=W("chartTypeDef",B),H=e.el.ownerDocument,O=(he,ie)=>{const ce=d(he);return ce===he?ie:ce},I=H.createElement("div");I.className="lattice-designer-palette",I.setAttribute("role","region"),I.setAttribute("aria-label",d("designer.palette")),I.setAttribute("tabindex","-1");const K=H.createElement("input");K.type="search",K.className="lattice-designer-palette-search",K.setAttribute("aria-label",d("designer.palette.search")),K.placeholder=d("designer.palette.search");const g=H.createElement("select");g.className="lattice-designer-palette-source",g.setAttribute("aria-label",d("designer.palette.source"));const k=H.createElement("div");k.className="lattice-designer-palette-list",I.appendChild(K),I.appendChild(g),I.appendChild(k),e.rails.left.slot("palette").appendChild(I);const V=H.createElement("div");V.className="lattice-designer-palette-strip",V.setAttribute("role","group"),V.setAttribute("aria-label",d("designer.palette")),e.rails.left.el.appendChild(V);let R="",N=null,$="",S={groups:[],entries:[]};const Y=new Map([["widgets",!0],["comparison",!0]]);let Z=null,x=!1;const ee=()=>e.dataPanel&&ue(e.dataPanel.sources)?e.dataPanel.sources():[],se=()=>{const he=e.getState(),ie=he.pages.find(ce=>F(ce)&&ce.id===he.selectedPageId);return ie&&F(ie.spec)?ie.spec:null},de=()=>{const he=ee();return N&&he.some(ie=>ie.id===N)?N:he.length?he[0].id:null},ye=()=>{const he=ee().find(ie=>ie.id===de());return he?he.fields:[]},xe=()=>[...new Set([...J,...q()])],me=()=>{const he=e.guardrails,ie=ye(),ce=de()!==null,Oe=Ge=>d(`designer.palette.needs.${Ge}`),be=Ge=>ie.find(Ke=>Ge.has(Ke.type)),ge=()=>ce?null:Oe("source"),ke=(Ge,Ke,Ie,$e,Pe,He)=>({id:`${Ge}:${Ke}`,kind:Ge,type:Ke,label:Ie,family:$e,disabled:Pe,icon:He||Ke}),Ee=[],Re=[];if(he.allowsWidget("grid")&&Re.push(ke("grid","grid",d("designer.kind.grid"),"widgets",ge()||(ie.length?null:Oe("fields")),"grid")),["createMap","bindLeaflet","bindDeck"].some(Ge=>ue(E[Ge])||ue(M[Ge]))&&he.allowsWidget("map")&&Re.push(ke("map","map",d("designer.kind.map"),"widgets",ge()||(be(new Set(["geometry"]))||ie.some(Ge=>/^lat/i.test(Ge.id))&&ie.some(Ge=>/^(lon|lng)/i.test(Ge.id))?null:Oe("location")),"map")),he.allowsWidget("kpi")&&Re.push(ke("kpi","kpi",d("designer.kind.kpi"),"widgets",ge()||(be(A)?null:Oe("numeric")),"kpi")),he.allowsWidget("html")&&Re.push(ke("text","text",d("designer.kind.html"),"widgets",null,"text")),Re.length&&Ee.push({id:"widgets",label:d("designer.palette.group.widgets"),entries:Re}),he.allowsWidget("filter")){const Ge={list:[j,"categorical"],range:[A,"numeric"],dateRange:[r,"date"],search:[new Set(["text"]),"text"]};Ee.push({id:"filters",label:d("designer.palette.group.filters"),entries:w.map(Ke=>ke("filter",Ke,d(`designer.palette.filter.${Ke}`),"filters",ge()||(be(Ge[Ke][0])?null:Oe(Ge[Ke][1])),Ke))})}if(he.allowsWidget("chart")){const Ge=new Map(o.map(Ke=>[Ke,[]]));for(const Ke of xe()){if(!he.allowsChartType(Ke))continue;const Ie=ue(Q)?Q(Ke):null,$e=C(Ke,Ie),Pe=ce?_(Ke,oe(Ke).roles,ie):{need:"source"},He=O(`designer.palette.type.${Ke}`,G(Ke));Ge.get($e).push(ke("chart",Ke,He,$e,Pe.need?Oe(Pe.need):null,i.has(Ke)&&p[Ke]?Ke:$e))}for(const Ke of o){const Ie=Ge.get(Ke);Ie.length&&Ee.push({id:Ke,label:d(`designer.palette.family.${Ke}`),entries:Ie})}}return{groups:Ee,entries:Ee.flatMap(Ge=>Ge.entries)}},Ne=he=>{const ie=R.trim().toLowerCase();return!ie||`${he.label} ${he.type} ${he.kind} ${he.family}`.toLowerCase().includes(ie)},Ae=he=>e.announce(he),te=he=>{if(he.disabled){Ae(d("designer.palette.disabled",{name:he.label,reason:he.disabled}));return}e.commands.run("paletteAdd",he.kind,he.type)},re=he=>{const ie=[...k.querySelectorAll(".lattice-designer-palette-entry")].filter(be=>!be.closest("[hidden]")),ce=ie.indexOf(he.target);if(ce<0)return;let Oe=-1;if(he.key==="ArrowDown"?Oe=Math.min(ie.length-1,ce+1):he.key==="ArrowUp"?Oe=Math.max(0,ce-1):he.key==="Home"?Oe=0:he.key==="End"&&(Oe=ie.length-1),!(Oe<0)){he.preventDefault();for(const be of ie)be.setAttribute("tabindex",be===ie[Oe]?"0":"-1");ie[Oe].focus()}};k.addEventListener("keydown",re);const le=()=>{const he=H.activeElement&&k.contains(H.activeElement)?H.activeElement.getAttribute("data-entry"):null;k.textContent="",V.textContent="";const ie=R.trim();let ce=0,Oe=!1;for(const be of S.groups){const ge=be.entries.filter(Ne);if(!ge.length)continue;const ke=ie?!0:Y.get(be.id)===!0,Ee=H.createElement("div");Ee.className="lattice-designer-palette-group",Ee.setAttribute("data-group",be.id);const Re=H.createElement("button");Re.type="button",Re.className="lattice-designer-palette-group-head",Re.setAttribute("aria-expanded",ke?"true":"false");const ze=H.createElement("ul");ze.setAttribute("aria-label",be.label),ze.id=`lattice-designer-palette-${be.id}`,Re.setAttribute("aria-controls",ze.id);const Ge=H.createElement("span");Ge.setAttribute("aria-hidden","true"),Ge.textContent=ke?"▾":"▸";const Ke=H.createElement("span");Ke.textContent=`${be.label} (${ge.length})`,Re.appendChild(Ge),Re.appendChild(Ke),ke||ze.setAttribute("hidden",""),Re.addEventListener("click",()=>{Y.set(be.id,Y.get(be.id)!==!0),$="",pe()}),Ee.appendChild(Re);for(const $e of ge){ce+=1;const Pe=H.createElement("li"),He=H.createElement("button");He.type="button",He.className="lattice-designer-palette-entry",He.setAttribute("data-entry",$e.id),He.setAttribute("data-kind",$e.kind),He.setAttribute("data-type",$e.type),He.setAttribute("data-family",$e.family),He.setAttribute("draggable","true"),He.setAttribute("aria-label",$e.disabled?`${$e.label}, ${$e.disabled}`:$e.label),$e.disabled&&He.setAttribute("aria-disabled","true");const Ye=!Oe&&ke;Ye&&(Oe=!0),He.setAttribute("tabindex",Ye||he===$e.id?"0":"-1"),He.appendChild(v(H,$e.icon,$e.family));const We=H.createElement("span");if(We.className="lattice-designer-palette-name",We.textContent=$e.label,$e.disabled){const nt=H.createElement("span");nt.className="lattice-designer-palette-reason",nt.textContent=$e.disabled,We.appendChild(nt)}He.appendChild(We),He.addEventListener("click",()=>te($e)),He.addEventListener("dragstart",nt=>{if($e.disabled){nt.preventDefault();return}Z={kind:$e.kind,type:$e.type};try{nt.dataTransfer.setData(n,`${$e.kind}:${$e.type}`),nt.dataTransfer.effectAllowed="copy"}catch{}}),He.addEventListener("dragend",()=>{Z=null}),Pe.appendChild(He),ze.appendChild(Pe)}Ee.appendChild(ze),k.appendChild(Ee);const Ie=H.createElement("button");Ie.type="button",Ie.setAttribute("aria-label",be.label),Ie.setAttribute("title",be.label),Ie.setAttribute("data-group",be.id),Ie.appendChild(v(H,be.id==="widgets"?"grid":be.id==="filters"?"search":be.id)),Ie.addEventListener("click",()=>{Y.set(be.id,!0),R="",K.value="",e.rails.left.expand(),$="",pe();const $e=k.querySelector(`[data-group="${be.id}"] .lattice-designer-palette-group-head`);$e&&$e.focus&&$e.focus()}),V.appendChild(Ie)}if(!ce){const be=H.createElement("div");be.className="lattice-designer-palette-empty",be.setAttribute("role","status"),be.textContent=d("designer.palette.empty"),k.appendChild(be)}if(he){const be=k.querySelector(`[data-entry="${he}"]`);be&&be.focus&&be.focus()}},pe=()=>{if(x)return;const he=ee(),ie=de(),ce=he.map(be=>be.id).join(",");if(g.getAttribute("data-sources")!==ce){g.textContent="";for(const be of he){const ge=H.createElement("option");ge.value=be.id,ge.textContent=be.id,g.appendChild(ge)}g.setAttribute("data-sources",ce)}ie!==null&&(g.value=ie),g.hidden=he.length<2,S=me();const Oe=JSON.stringify([S.groups.map(be=>[be.id,be.label,be.entries.map(ge=>[ge.id,ge.label,ge.disabled])]),R,ie,[...Y]]);Oe!==$&&($=Oe,le())};K.addEventListener("input",()=>{R=K.value,pe()}),g.addEventListener("change",()=>{N=g.value,pe()}),I.addEventListener("pointerenter",pe),I.addEventListener("focusin",pe);const we={grid:[.5,.5],chart:[1/3,.5],map:[.5,.5],kpi:[.25,.25],text:[.25,.25]},je=(he,ie)=>{const ce=se()||{},Oe=e.dashboard&&e.dashboard.layout,be=Oe&&ue(Oe.getLayout)?Oe.getLayout():null,ge=F(ce.layout)?ce.layout:{},ke=Math.max(1,be&&be.columns||ge.columns||12),Ee=Math.max(1,be&&be.rows||ge.rows||6),Re=new Map;for(const Ye of[...Array.isArray(ge.windows)?ge.windows:[],...be?be.windows:[]])F(Ye)&&[Ye.xPos,Ye.yPos,Ye.xSize,Ye.ySize].every(Number.isFinite)&&Re.set(Ye.id,Ye);const ze=[...Re.values()],[Ge,Ke]=we[he==="html"?"text":he]||we.grid,Ie=Math.max(1,Math.min(ke,Math.round(ke*Ge))),$e=Math.max(1,Math.min(Ee,Math.round(Ee*Ke))),Pe=(Ye,We)=>ze.some(nt=>Ye<nt.xPos+nt.xSize&&Ye+Ie>nt.xPos&&We<nt.yPos+nt.ySize&&We+$e>nt.yPos);if(ie&&Number.isFinite(ie.col)&&Number.isFinite(ie.row)){const Ye=Math.max(1,Math.min(ke-Ie+1,Math.floor(ie.col))),We=Math.max(1,Math.floor(ie.row));if(!Pe(Ye,We))return{xPos:Ye,yPos:We,xSize:Ie,ySize:$e}}const He=ze.reduce((Ye,We)=>Math.max(Ye,We.yPos+We.ySize),1);for(let Ye=1;Ye<=He;Ye+=1)for(let We=1;We<=ke-Ie+1;We+=1)if(!Pe(We,Ye))return{xPos:We,yPos:Ye,xSize:Ie,ySize:$e};return{xPos:1,yPos:He,xSize:Ie,ySize:$e}},Be=(he,ie,ce)=>{const Oe=ge=>ge.label||ge.id;if(he.kind==="grid")return{kind:"grid",source:ie,options:{columns:ce.map(ge=>({field:ge.id,title:Oe(ge)}))}};if(he.kind==="kpi"){const ge=ce.find(ke=>A.has(ke.type));return{kind:"kpi",title:Oe(ge),source:ie,options:{tiles:[{id:ge.id,label:Oe(ge),aggregation:"sum",field:ge.id,format:ge.format}]}}}if(he.kind==="map"){const ge=ue(E.bindLeaflet)||ue(M.bindLeaflet)?"leaflet":ue(E.bindDeck)||ue(M.bindDeck)?"deckgl":"chart",ke=ce.find(Ge=>Ge.type==="geometry"),Ee=ce.find(Ge=>/^lat/i.test(Ge.id)),Re=ce.find(Ge=>/^(lon|lng)/i.test(Ge.id)),ze=ke?{geometry:ke.id}:{lat:Ee.id,lon:Re.id};return ge==="chart"&&(ze.type="geomap"),{kind:"map",title:he.label,source:ie,binding:ge,options:ze}}if(he.kind==="text")return{kind:"html",options:{text:""}};const be=_(he.type,oe(he.type).roles,ce);return{kind:"chart",title:he.label,source:ie,options:be.options}};e.commands.register("paletteAdd",(he,ie,ce,Oe)=>{pe();const be=ie==="html"?"text":ie,ge=be==="chart"||be==="filter"?ce:be,ke=S.entries.find(Pe=>Pe.kind===be&&Pe.type===ge);if(!ke)return Ae(d("designer.palette.unavailable",{name:String(ce||ie)})),null;if(ke.disabled)return Ae(d("designer.palette.disabled",{name:ke.label,reason:ke.disabled})),null;const Ee=e.guardrails.widgetLimit(),Re=se();if(ke.kind!=="filter"&&Ee!==null&&Re&&Array.isArray(Re.panels)&&Re.panels.length>=Ee)return Ae(d("designer.palette.limit",{limit:Ee})),null;const ze=F(Oe)?Oe:{},Ge=typeof ze.source=="string"?ze.source:de(),Ke=(ee().find(Pe=>Pe.id===Ge)||{fields:[]}).fields;if(ke.kind==="filter"){const Pe=he.getState(),He=Pe.pages.find(st=>F(st)&&st.id===Pe.selectedPageId);if(!He)return null;const Ye={list:j,range:A,dateRange:r,search:new Set(["text"])},We=Ke.find(st=>Ye[ke.type].has(st.type)),nt=Array.isArray(He.filters)?He.filters:[];let ut=nt.length+1;for(;nt.some(st=>F(st)&&st.id===`filter-${ut}`);)ut+=1;const ht=`filter-${ut}`;return He.filters=[...nt,{id:ht,type:ke.type,source:Ge,field:We.id}],he.commit(Pe,"paletteAdd")?(Ae(d("a11y.designer.added",{kind:ke.label,title:We.label||We.id})),ht):null}const Ie=Be(ke,Ge,Ke),$e=je(Ie.kind,F(ze.at)?ze.at:void 0);return e.commands.run("addPanel",{...Ie,placement:$e})});const Ue=he=>{if(Z){he.preventDefault();try{he.dataTransfer.dropEffect="copy"}catch{}}},qe=he=>{if(!Z)return;he.preventDefault(),he.stopPropagation();const ie=Z;Z=null;let ce;const Oe=e.canvas.getBoundingClientRect?e.canvas.getBoundingClientRect():null,be=e.dashboard&&e.dashboard.layout,ge=be&&ue(be.getLayout)?be.getLayout():null;Oe&&Oe.width>0&&Oe.height>0&&ge&&Number.isFinite(he.clientX)&&Number.isFinite(he.clientY)&&(ce={col:Math.floor((he.clientX-Oe.left)/Oe.width*ge.columns)+1,row:Math.floor((he.clientY-Oe.top)/Oe.height*ge.rows)+1}),e.commands.run("paletteAdd",ie.kind,ie.type,ce?{at:ce}:void 0)};e.canvas.addEventListener("dragover",Ue),e.canvas.addEventListener("drop",qe);const ot=e.on("state",pe),tt=e.on("select",he=>{const ie=se(),ce=ie&&Array.isArray(ie.panels)?ie.panels.find(Oe=>F(Oe)&&he&&Oe.id===he.id):null;ce&&typeof ce.source=="string"&&ee().some(Oe=>Oe.id===ce.source)&&(N=ce.source,pe())});return e.regions&&e.regions.register("palette",I,{label:d("designer.region.palette")}),pe(),{get el(){return I},entries(){return pe(),S.entries.map(({id:he,kind:ie,type:ce,label:Oe,family:be,disabled:ge})=>({id:he,kind:ie,type:ce,label:Oe,family:be,disabled:ge}))},add(he,ie){return e.commands.run("paletteAdd",he,ie)},setQuery(he){R=String(he||""),K.value=R,pe()},refresh(){$="",pe()},get collapsed(){return e.rails.left.collapsed},collapse(){return e.rails.left.collapse(),e.rails.left.collapsed},expand(){return e.rails.left.expand(),e.rails.left.collapsed},toggle(){return e.rails.left.toggle(),e.rails.left.collapsed},destroy(){x=!0,ot(),tt(),e.canvas.removeEventListener("dragover",Ue),e.canvas.removeEventListener("drop",qe),I.remove(),V.remove()}}}const a=t}),rt("packages/modules/designer/theme.js",function(s,ae){"use strict";Object.defineProperty(s,"chromeCss",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"injectChromeStyles",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"createTheme",{enumerable:!0,get:function(){return ne}});const F=ae("packages/core/src/internal/util.js").warnOnce,ue=ae("packages/modules/designer/rails.js").railsCss,fe=ae("packages/modules/designer/palette.js").paletteCss,J=()=>`
|
|
114
|
-
.lattice-designer
|
|
115
|
-
|
|
116
|
-
.lattice-designer-
|
|
126
|
+
`,h=Object.freeze({grid:"M2.5 3.5h11v9h-11zM2.5 7h11M2.5 10h11M6.5 3.5v9",map:"M2.5 4 6 2.5l4 1.5 3.5-1.5v9.5L10 13.5 6 12l-3.5 1.5z",kpi:"M3 12.5V9M7 12.5V6M11 12.5V3.5",text:"M3 4h10M3 8h10M3 12h6",list:"M4 4h8M4 8h8M4 12h8",range:"M2.5 8h11M5 5.5v5M11 5.5v5",dateRange:"M3 3.5h10v10H3zM3 6.5h10M6 9h4",search:"M7 11.5a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9ZM10.3 10.3l3.2 3.2",comparison:"M3 13V8M7 13V4M11 13V6",trend:"M2.5 12 6 8l3 2.5 4.5-6",composition:"M8 2.5a5.5 5.5 0 1 0 5.5 5.5H8z",distribution:"M4 11.5a1 1 0 1 0 0-.1M7 6a1 1 0 1 0 0-.1M10 9a1 1 0 1 0 0-.1M12 4.5a1 1 0 1 0 0-.1",flow:"M2.5 4h4c3 0 3 8 7 8M2.5 12h4c3 0 3-8 7-8",hierarchy:"M2.5 2.5h11v4h-11zM2.5 8.5h5v5h-5zM9 8.5h4.5v5H9z",geo:"M8 14s4.5-4 4.5-7.5a4.5 4.5 0 1 0-9 0C3.5 10 8 14 8 14ZM8 8.5a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z",specialist:"M8 2.5l1.6 3.4 3.7.4-2.8 2.5.8 3.7L8 10.6 4.7 12.5l.8-3.7L2.7 6.3l3.7-.4z",statistics:"M2.5 13h11M3 13c0-4.5 1.3-8 2.6-8s1.3 6 2.4 6 1.4-6 2.6-6 1.9 7.5 2.4 8",line:"M2.5 12 6 8l3 2.5 4.5-6",area:"M2.5 12.5 6 8l3 2.5 4.5-6v8z",pie:"M8 2.5a5.5 5.5 0 1 0 5.5 5.5H8z",donut:"M8 2.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11ZM8 6a2 2 0 1 0 0 4 2 2 0 0 0 0-4Z",scatter:"M4 11.5a1 1 0 1 0 0-.1M7 6a1 1 0 1 0 0-.1M10 9a1 1 0 1 0 0-.1M12 4.5a1 1 0 1 0 0-.1",horizontalBar:"M3 3h8M3 7h5M3 11h10"});function $(e,s,x){const S="http://www.w3.org/2000/svg",B=e.createElementNS(S,"svg");B.setAttribute("viewBox","0 0 16 16"),B.setAttribute("width","16"),B.setAttribute("height","16"),B.setAttribute("aria-hidden","true"),B.setAttribute("focusable","false");const Y=e.createElementNS(S,"path");return Y.setAttribute("d",h[s]||h[x||"specialist"]),Y.setAttribute("fill","none"),Y.setAttribute("stroke","currentColor"),Y.setAttribute("stroke-width","1.4"),Y.setAttribute("stroke-linecap","round"),Y.setAttribute("stroke-linejoin","round"),B.appendChild(Y),B}const a="application/x-lattice-palette";function n(e,s={}){const x=_(s&&s.messages),S=F(s.factories)?s.factories:{},B=globalThis.LatticeGrid||{},Y=(ge,Le)=>de(S[ge])?S[ge]:de(B[ge])?B[ge]:Le,te=Y("chartEditorModel",fe),q=Y("registeredChartTypes",ie),ne=Y("chartTypeDef",W),U=e.el.ownerDocument,M=(ge,Le)=>{const He=x(ge);return He===ge?Le:He},R=U.createElement("div");R.className="lattice-designer-palette",R.setAttribute("role","region"),R.setAttribute("aria-label",x("designer.palette")),R.setAttribute("tabindex","-1");const H=U.createElement("input");H.type="search",H.className="lattice-designer-palette-search",H.setAttribute("aria-label",x("designer.palette.search")),H.placeholder=x("designer.palette.search");const f=U.createElement("select");f.className="lattice-designer-palette-source",f.setAttribute("aria-label",x("designer.palette.source"));const g=U.createElement("div");g.className="lattice-designer-palette-list",R.appendChild(H),R.appendChild(f),R.appendChild(g),e.rails.left.slot("palette").appendChild(R);const I=U.createElement("div");I.className="lattice-designer-palette-strip",I.setAttribute("role","group"),I.setAttribute("aria-label",x("designer.palette")),e.rails.left.el.appendChild(I);let j="",A=null,D="",p={groups:[],entries:[]};const se=new Map([["widgets",!0],["comparison",!0]]);let V=null,O=!1;const X=()=>e.dataPanel&&de(e.dataPanel.sources)?e.dataPanel.sources():[],oe=()=>{const ge=e.getState(),Le=ge.pages.find(He=>F(He)&&He.id===ge.selectedPageId);return Le&&F(Le.spec)?Le.spec:null},ue=()=>{const ge=X();return A&&ge.some(Le=>Le.id===A)?A:ge.length?ge[0].id:null},xe=()=>{const ge=X().find(Le=>Le.id===ue());return ge?ge.fields:[]},me=()=>[...new Set([...J,...q()])],we=()=>{const ge=e.guardrails,Le=xe(),He=ue()!==null,Ze=$e=>x(`designer.palette.needs.${$e}`),ae=$e=>Le.find(Ge=>$e.has(Ge.type)),ee=()=>He?null:Ze("source"),ye=($e,Ge,Ye,Se,Ne,Ve)=>({id:`${$e}:${Ge}`,kind:$e,type:Ge,label:Ye,family:Se,disabled:Ne,icon:Ve||Ge}),ve=[],be=[];if(ge.allowsWidget("grid")&&be.push(ye("grid","grid",x("designer.kind.grid"),"widgets",ee()||(Le.length?null:Ze("fields")),"grid")),["createMap","bindLeaflet","bindDeck"].some($e=>de(S[$e])||de(B[$e]))&&ge.allowsWidget("map")&&be.push(ye("map","map",x("designer.kind.map"),"widgets",ee()||(ae(new Set(["geometry"]))||Le.some($e=>/^lat/i.test($e.id))&&Le.some($e=>/^(lon|lng)/i.test($e.id))?null:Ze("location")),"map")),ge.allowsWidget("kpi")&&be.push(ye("kpi","kpi",x("designer.kind.kpi"),"widgets",ee()||(ae(E)?null:Ze("numeric")),"kpi")),ge.allowsWidget("html")&&be.push(ye("text","text",x("designer.kind.html"),"widgets",null,"text")),be.length&&ve.push({id:"widgets",label:x("designer.palette.group.widgets"),entries:be}),ge.allowsWidget("filter")){const $e={list:[w,"categorical"],range:[E,"numeric"],dateRange:[d,"date"],search:[new Set(["text"]),"text"]};ve.push({id:"filters",label:x("designer.palette.group.filters"),entries:v.map(Ge=>ye("filter",Ge,x(`designer.palette.filter.${Ge}`),"filters",ee()||(ae($e[Ge][0])?null:Ze($e[Ge][1])),Ge))})}if(ge.allowsWidget("chart")){const $e=new Map(i.map(Ge=>[Ge,[]]));for(const Ge of me()){if(!ge.allowsChartType(Ge))continue;const Ye=de(ne)?ne(Ge):null,Se=G(Ge,Ye),Ne=He?T(Ge,te(Ge).roles,Le):{need:"source"},Ve=M(`designer.palette.type.${Ge}`,N(Ge));$e.get(Se).push(ye("chart",Ge,Ve,Se,Ne.need?Ze(Ne.need):null,r.has(Ge)&&h[Ge]?Ge:Se))}for(const Ge of i){const Ye=$e.get(Ge);Ye.length&&ve.push({id:Ge,label:x(`designer.palette.family.${Ge}`),entries:Ye})}}return{groups:ve,entries:ve.flatMap($e=>$e.entries)}},Pe=ge=>{const Le=j.trim().toLowerCase();return!Le||`${ge.label} ${ge.type} ${ge.kind} ${ge.family}`.toLowerCase().includes(Le)},Fe=ge=>e.announce(ge),Z=ge=>{if(ge.disabled){Fe(x("designer.palette.disabled",{name:ge.label,reason:ge.disabled}));return}e.commands.run("paletteAdd",ge.kind,ge.type)},re=ge=>{const Le=[...g.querySelectorAll(".lattice-designer-palette-entry")].filter(ae=>!ae.closest("[hidden]")),He=Le.indexOf(ge.target);if(He<0)return;let Ze=-1;if(ge.key==="ArrowDown"?Ze=Math.min(Le.length-1,He+1):ge.key==="ArrowUp"?Ze=Math.max(0,He-1):ge.key==="Home"?Ze=0:ge.key==="End"&&(Ze=Le.length-1),!(Ze<0)){ge.preventDefault();for(const ae of Le)ae.setAttribute("tabindex",ae===Le[Ze]?"0":"-1");Le[Ze].focus()}};g.addEventListener("keydown",re);const le=()=>{const ge=U.activeElement&&g.contains(U.activeElement)?U.activeElement.getAttribute("data-entry"):null;g.textContent="",I.textContent="";const Le=j.trim();let He=0,Ze=!1;for(const ae of p.groups){const ee=ae.entries.filter(Pe);if(!ee.length)continue;const ye=Le?!0:se.get(ae.id)===!0,ve=U.createElement("div");ve.className="lattice-designer-palette-group",ve.setAttribute("data-group",ae.id);const be=U.createElement("button");be.type="button",be.className="lattice-designer-palette-group-head",be.setAttribute("aria-expanded",ye?"true":"false");const Ee=U.createElement("ul");Ee.setAttribute("aria-label",ae.label),Ee.id=`lattice-designer-palette-${ae.id}`,be.setAttribute("aria-controls",Ee.id);const $e=U.createElement("span");$e.setAttribute("aria-hidden","true"),$e.textContent=ye?"▾":"▸";const Ge=U.createElement("span");Ge.textContent=`${ae.label} (${ee.length})`,be.appendChild($e),be.appendChild(Ge),ye||Ee.setAttribute("hidden",""),be.addEventListener("click",()=>{se.set(ae.id,se.get(ae.id)!==!0),D="",pe()}),ve.appendChild(be);for(const Se of ee){He+=1;const Ne=U.createElement("li"),Ve=U.createElement("button");Ve.type="button",Ve.className="lattice-designer-palette-entry",Ve.setAttribute("data-entry",Se.id),Ve.setAttribute("data-kind",Se.kind),Ve.setAttribute("data-type",Se.type),Ve.setAttribute("data-family",Se.family),Ve.setAttribute("draggable","true"),Ve.setAttribute("aria-label",Se.disabled?`${Se.label}, ${Se.disabled}`:Se.label),Se.disabled&&Ve.setAttribute("aria-disabled","true");const Be=!Ze&&ye;Be&&(Ze=!0),Ve.setAttribute("tabindex",Be||ge===Se.id?"0":"-1"),Ve.appendChild($(U,Se.icon,Se.family));const Oe=U.createElement("span");if(Oe.className="lattice-designer-palette-name",Oe.textContent=Se.label,Se.disabled){const Xe=U.createElement("span");Xe.className="lattice-designer-palette-reason",Xe.textContent=Se.disabled,Oe.appendChild(Xe)}Ve.appendChild(Oe),Ve.addEventListener("click",()=>Z(Se)),Ve.addEventListener("dragstart",Xe=>{if(Se.disabled){Xe.preventDefault();return}V={kind:Se.kind,type:Se.type};try{Xe.dataTransfer.setData(a,`${Se.kind}:${Se.type}`),Xe.dataTransfer.effectAllowed="copy"}catch{}}),Ve.addEventListener("dragend",()=>{V=null}),Ne.appendChild(Ve),Ee.appendChild(Ne)}ve.appendChild(Ee),g.appendChild(ve);const Ye=U.createElement("button");Ye.type="button",Ye.setAttribute("aria-label",ae.label),Ye.setAttribute("title",ae.label),Ye.setAttribute("data-group",ae.id),Ye.appendChild($(U,ae.id==="widgets"?"grid":ae.id==="filters"?"search":ae.id)),Ye.addEventListener("click",()=>{se.set(ae.id,!0),j="",H.value="",e.rails.left.expand(),D="",pe();const Se=g.querySelector(`[data-group="${ae.id}"] .lattice-designer-palette-group-head`);Se&&Se.focus&&Se.focus()}),I.appendChild(Ye)}if(!He){const ae=U.createElement("div");ae.className="lattice-designer-palette-empty",ae.setAttribute("role","status"),ae.textContent=x("designer.palette.empty"),g.appendChild(ae)}if(ge){const ae=g.querySelector(`[data-entry="${ge}"]`);ae&&ae.focus&&ae.focus()}},pe=()=>{if(O)return;const ge=X(),Le=ue(),He=ge.map(ae=>ae.id).join(",");if(f.getAttribute("data-sources")!==He){f.textContent="";for(const ae of ge){const ee=U.createElement("option");ee.value=ae.id,ee.textContent=ae.id,f.appendChild(ee)}f.setAttribute("data-sources",He)}Le!==null&&(f.value=Le),f.hidden=ge.length<2,p=we();const Ze=JSON.stringify([p.groups.map(ae=>[ae.id,ae.label,ae.entries.map(ee=>[ee.id,ee.label,ee.disabled])]),j,Le,[...se]]);Ze!==D&&(D=Ze,le())};H.addEventListener("input",()=>{j=H.value,pe()}),f.addEventListener("change",()=>{A=f.value,pe()}),R.addEventListener("pointerenter",pe),R.addEventListener("focusin",pe);const he={grid:[.5,.5],chart:[1/3,.5],map:[.5,.5],kpi:[.25,.25],text:[.25,.25]},Me=(ge,Le)=>{const He=oe()||{},Ze=e.dashboard&&e.dashboard.layout,ae=Ze&&de(Ze.getLayout)?Ze.getLayout():null,ee=F(He.layout)?He.layout:{},ye=Math.max(1,ae&&ae.columns||ee.columns||12),ve=Math.max(1,ae&&ae.rows||ee.rows||6),be=new Map;for(const Be of[...Array.isArray(ee.windows)?ee.windows:[],...ae?ae.windows:[]])F(Be)&&[Be.xPos,Be.yPos,Be.xSize,Be.ySize].every(Number.isFinite)&&be.set(Be.id,Be);const Ee=[...be.values()],[$e,Ge]=he[ge==="html"?"text":ge]||he.grid,Ye=Math.max(1,Math.min(ye,Math.round(ye*$e))),Se=Math.max(1,Math.min(ve,Math.round(ve*Ge))),Ne=(Be,Oe)=>Ee.some(Xe=>Be<Xe.xPos+Xe.xSize&&Be+Ye>Xe.xPos&&Oe<Xe.yPos+Xe.ySize&&Oe+Se>Xe.yPos);if(Le&&Number.isFinite(Le.col)&&Number.isFinite(Le.row)){const Be=Math.max(1,Math.min(ye-Ye+1,Math.floor(Le.col))),Oe=Math.max(1,Math.floor(Le.row));if(!Ne(Be,Oe))return{xPos:Be,yPos:Oe,xSize:Ye,ySize:Se}}const Ve=Ee.reduce((Be,Oe)=>Math.max(Be,Oe.yPos+Oe.ySize),1);for(let Be=1;Be<=Ve;Be+=1)for(let Oe=1;Oe<=ye-Ye+1;Oe+=1)if(!Ne(Oe,Be))return{xPos:Oe,yPos:Be,xSize:Ye,ySize:Se};return{xPos:1,yPos:Ve,xSize:Ye,ySize:Se}},Ie=(ge,Le,He)=>{const Ze=ee=>ee.label||ee.id;if(ge.kind==="grid")return{kind:"grid",source:Le,options:{columns:He.map(ee=>({field:ee.id,title:Ze(ee)}))}};if(ge.kind==="kpi"){const ee=He.find(ye=>E.has(ye.type));return{kind:"kpi",title:Ze(ee),source:Le,options:{tiles:[{id:ee.id,label:Ze(ee),aggregation:"sum",field:ee.id,format:ee.format}]}}}if(ge.kind==="map"){const ee=de(S.bindLeaflet)||de(B.bindLeaflet)?"leaflet":de(S.bindDeck)||de(B.bindDeck)?"deckgl":"chart",ye=He.find($e=>$e.type==="geometry"),ve=He.find($e=>/^lat/i.test($e.id)),be=He.find($e=>/^(lon|lng)/i.test($e.id)),Ee=ye?{geometry:ye.id}:{lat:ve.id,lon:be.id};return ee==="chart"&&(Ee.type="geomap"),{kind:"map",title:ge.label,source:Le,binding:ee,options:Ee}}if(ge.kind==="text")return{kind:"html",options:{text:""}};const ae=T(ge.type,te(ge.type).roles,He);return{kind:"chart",title:ge.label,source:Le,options:ae.options}};e.commands.register("paletteAdd",(ge,Le,He,Ze)=>{pe();const ae=Le==="html"?"text":Le,ee=ae==="chart"||ae==="filter"?He:ae,ye=p.entries.find(Ne=>Ne.kind===ae&&Ne.type===ee);if(!ye)return Fe(x("designer.palette.unavailable",{name:String(He||Le)})),null;if(ye.disabled)return Fe(x("designer.palette.disabled",{name:ye.label,reason:ye.disabled})),null;const ve=e.guardrails.widgetLimit(),be=oe();if(ye.kind!=="filter"&&ve!==null&&be&&Array.isArray(be.panels)&&be.panels.length>=ve)return Fe(x("designer.palette.limit",{limit:ve})),null;const Ee=F(Ze)?Ze:{},$e=typeof Ee.source=="string"?Ee.source:ue(),Ge=(X().find(Ne=>Ne.id===$e)||{fields:[]}).fields;if(ye.kind==="filter"){const Ne=ge.getState(),Ve=Ne.pages.find(ft=>F(ft)&&ft.id===Ne.selectedPageId);if(!Ve)return null;const Be={list:w,range:E,dateRange:d,search:new Set(["text"])},Oe=Ge.find(ft=>Be[ye.type].has(ft.type)),Xe=Array.isArray(Ve.filters)?Ve.filters:[];let nt=Xe.length+1;for(;Xe.some(ft=>F(ft)&&ft.id===`filter-${nt}`);)nt+=1;const st=`filter-${nt}`;return Ve.filters=[...Xe,{id:st,type:ye.type,source:$e,field:Oe.id}],ge.commit(Ne,"paletteAdd")?(Fe(x("a11y.designer.added",{kind:ye.label,title:Oe.label||Oe.id})),st):null}const Ye=Ie(ye,$e,Ge),Se=Me(Ye.kind,F(Ee.at)?Ee.at:void 0);return e.commands.run("addPanel",{...Ye,placement:Se})});const Ke=ge=>{if(V){ge.preventDefault();try{ge.dataTransfer.dropEffect="copy"}catch{}}},qe=ge=>{if(!V)return;ge.preventDefault(),ge.stopPropagation();const Le=V;V=null;let He;const Ze=e.canvas.getBoundingClientRect?e.canvas.getBoundingClientRect():null,ae=e.dashboard&&e.dashboard.layout,ee=ae&&de(ae.getLayout)?ae.getLayout():null;Ze&&Ze.width>0&&Ze.height>0&&ee&&Number.isFinite(ge.clientX)&&Number.isFinite(ge.clientY)&&(He={col:Math.floor((ge.clientX-Ze.left)/Ze.width*ee.columns)+1,row:Math.floor((ge.clientY-Ze.top)/Ze.height*ee.rows)+1}),e.commands.run("paletteAdd",Le.kind,Le.type,He?{at:He}:void 0)};e.canvas.addEventListener("dragover",Ke),e.canvas.addEventListener("drop",qe);const ot=e.on("state",pe),it=e.on("select",ge=>{const Le=oe(),He=Le&&Array.isArray(Le.panels)?Le.panels.find(Ze=>F(Ze)&&ge&&Ze.id===ge.id):null;He&&typeof He.source=="string"&&X().some(Ze=>Ze.id===He.source)&&(A=He.source,pe())});return e.regions&&e.regions.register("palette",R,{label:x("designer.region.palette")}),pe(),{get el(){return R},entries(){return pe(),p.entries.map(({id:ge,kind:Le,type:He,label:Ze,family:ae,disabled:ee})=>({id:ge,kind:Le,type:He,label:Ze,family:ae,disabled:ee}))},add(ge,Le){return e.commands.run("paletteAdd",ge,Le)},setQuery(ge){j=String(ge||""),H.value=j,pe()},refresh(){D="",pe()},get collapsed(){return e.rails.left.collapsed},collapse(){return e.rails.left.collapse(),e.rails.left.collapsed},expand(){return e.rails.left.expand(),e.rails.left.collapsed},toggle(){return e.rails.left.toggle(),e.rails.left.collapsed},destroy(){O=!0,ot(),it(),e.canvas.removeEventListener("dragover",Ke),e.canvas.removeEventListener("drop",qe),R.remove(),I.remove()}}}const t=n}),rt("packages/core/src/registry/widgets.js",function(o,ce){"use strict";Object.defineProperty(o,"WIDGET_AGGREGATIONS",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(o,"widgetKinds",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"widgetEditorModel",{enumerable:!0,get:function(){return z}});const ke=Object.freeze(["sum","avg","min","max","count","countDistinct","median"]),F=Object.freeze([{name:"layout.hidden",type:"boolean",default:!1},{name:"layout.width",type:"number",min:40,max:2e3,step:10},{name:"format",type:"string",format:"number"},{name:"sort",type:"enum",values:["asc","desc"]},{name:"group",type:"boolean",default:!1},{name:"pivot",type:"boolean",default:!1},{name:"total",type:"enum",values:["sum","avg","min","max","count","countValues","first","last"]}]),l=Object.freeze({grid:{roles:[{role:"columns",accepts:"field",path:"columns",repeatable:!0,entryKey:"field",entryOptions:F,orderable:!0}],options:[{name:"pivot.enabled",type:"boolean",default:!1},{name:"grandTotalRow",type:"boolean",default:!1},{name:"groupFooter",type:"boolean",default:!1},{name:"selection",type:"enum",values:["none","single","multiple"]}]},kpi:{aggregations:["sum","avg","min","max","count","countDistinct"],roles:[{role:"measure",accepts:"measure",path:"tiles.0.field",aggPath:"tiles.0.aggregation",aggregated:!0,required:!0},{role:"sparkline",accepts:"measure",path:"tiles.0.sparkline.y"},{role:"sparklineOrder",accepts:"field",path:"tiles.0.sparkline.x"}],options:[{name:"tiles.0.label",type:"string"},{name:"tiles.0.format",type:"enum",values:["number","currency","percent","compact"]},{name:"tiles.0.baseline",type:"number"},{name:"tiles.0.delta",type:"enum",values:["absolute","relative","both"],default:"both"},{name:"tiles.0.target",type:"number"}]},calendar:{roles:[{role:"date",accepts:"field",path:"date"},{role:"measure",accepts:"measure",path:"value",aggregated:!0,aggPath:"aggregation"}],options:[]},html:{roles:[],options:[{name:"text",type:"string"}]}});function de(){return Object.keys(l)}function z(fe){const J=l[fe];return J?{kind:fe,roles:J.roles.map(Q=>({...Q})),options:J.options.map(Q=>({...Q})),aggregations:J.aggregations?Object.freeze([...J.aggregations]):ke}:null}}),rt("packages/modules/designer/properties.js",function(o,ce){"use strict";Object.defineProperty(o,"propertiesCss",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"installProperties",{enumerable:!0,get:function(){return E}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return d}});const F=ce("packages/modules/dashboard/spec.js").isPlain,l=ce("packages/modules/charts/capabilities.js"),de=l.chartEditorModel,z=l.CHART_TYPES,J=ce("packages/modules/charts/registry.js").registeredChartTypes,ie=ce("packages/core/src/registry/widgets.js").widgetEditorModel,L=ce("packages/modules/designer/messages.js").resolveMessages,_=()=>`
|
|
127
|
+
.lattice-designer-properties{display:flex;flex-direction:column;gap:var(--lattice-designer-space-3);min-width:0;box-sizing:border-box;
|
|
128
|
+
padding:var(--lattice-designer-space-3);font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground)}
|
|
129
|
+
.lattice-designer-properties[hidden]{display:none}
|
|
130
|
+
.lattice-designer-properties-empty{margin:0;color:var(--lattice-foreground-muted)}
|
|
131
|
+
.lattice-designer-section{display:flex;flex-direction:column;box-sizing:border-box;
|
|
132
|
+
border:var(--lattice-border-width,1px) solid var(--lattice-designer-panel-border);border-radius:var(--lattice-radius,4px);
|
|
133
|
+
background:var(--lattice-designer-panel-bg);overflow:hidden}
|
|
134
|
+
.lattice-designer-section-title{margin:0;font:var(--lattice-designer-font-heading) var(--lattice-font-family);font-weight:var(--lattice-header-font-weight,600)}
|
|
135
|
+
.lattice-designer .lattice-designer-section-toggle{display:flex;align-items:center;gap:var(--lattice-designer-space-2);width:100%;box-sizing:border-box;
|
|
136
|
+
font:var(--lattice-designer-font-heading) var(--lattice-font-family);font-weight:var(--lattice-header-font-weight,600);color:var(--lattice-foreground);background:transparent;border:0;margin:0;cursor:pointer;text-align:start;
|
|
137
|
+
padding:var(--lattice-designer-space-2) var(--lattice-designer-space-3)}
|
|
138
|
+
.lattice-designer-section-toggle:hover{background:var(--lattice-hovered-background)}
|
|
139
|
+
.lattice-designer-section-toggle:focus-visible{outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:-2px;box-shadow:0 0 0 2px var(--lattice-focus-color)}
|
|
140
|
+
.lattice-designer-section-mark{flex:0 0 auto}
|
|
141
|
+
.lattice-designer-section-label{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
142
|
+
.lattice-designer-section-body{display:flex;flex-direction:column;gap:var(--lattice-designer-space-2);box-sizing:border-box;
|
|
143
|
+
padding:var(--lattice-designer-space-3);border-top:var(--lattice-border-width,1px) solid var(--lattice-designer-panel-border)}
|
|
144
|
+
.lattice-designer-section-body[hidden]{display:none}
|
|
145
|
+
.lattice-designer-field{display:flex;align-items:center;gap:var(--lattice-designer-space-2);margin:0;min-width:0}
|
|
146
|
+
.lattice-designer-field-label{flex:0 0 40%;max-width:40%;min-width:0;box-sizing:border-box;margin:0;
|
|
147
|
+
font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground-muted);
|
|
148
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
149
|
+
.lattice-designer-field>:not(.lattice-designer-field-label){flex:1 1 auto;min-width:0}
|
|
150
|
+
.lattice-designer-role-controls{display:flex;flex:1 1 auto;flex-wrap:wrap;gap:var(--lattice-designer-space-1);min-width:0}
|
|
151
|
+
.lattice-designer-properties .lattice-designer-role-controls>*{flex:1 1 7ch;width:auto;min-width:0}
|
|
152
|
+
.lattice-designer-properties input:not([type=checkbox]):not([type=radio]),.lattice-designer-properties select,.lattice-designer-properties textarea{
|
|
153
|
+
width:100%;min-width:0;box-sizing:border-box;margin:0;
|
|
154
|
+
font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);background:var(--lattice-surface);
|
|
155
|
+
border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius,4px);
|
|
156
|
+
padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2)}
|
|
157
|
+
.lattice-designer-properties input::placeholder,.lattice-designer-properties textarea::placeholder{color:var(--lattice-foreground-muted);opacity:1}
|
|
158
|
+
.lattice-designer-properties input[type=checkbox]{flex:0 0 auto;width:auto;min-width:0;margin:0;margin-inline-end:auto;
|
|
159
|
+
inline-size:calc(var(--lattice-designer-space-4) * 1.1);block-size:calc(var(--lattice-designer-space-3) + var(--lattice-designer-space-1));cursor:pointer}
|
|
160
|
+
.lattice-designer-properties input:focus-visible,.lattice-designer-properties select:focus-visible{
|
|
161
|
+
outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:0;box-shadow:0 0 0 2px var(--lattice-focus-color)}
|
|
162
|
+
.lattice-designer-fields{display:flex;flex-wrap:wrap;gap:var(--lattice-designer-space-1);margin:0;padding:0;list-style:none}
|
|
163
|
+
.lattice-designer-fields li{margin:0}
|
|
164
|
+
.lattice-designer .lattice-designer-field-item{display:inline-flex;align-items:center;max-width:100%;box-sizing:border-box;margin:0;
|
|
165
|
+
font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);background:var(--lattice-surface);
|
|
166
|
+
border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius-pill,999px);
|
|
167
|
+
padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);cursor:grab;
|
|
168
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
169
|
+
.lattice-designer-field-item[aria-pressed=true]{background:var(--lattice-selected-background);color:var(--lattice-selected-foreground);border-color:var(--lattice-accent)}
|
|
170
|
+
.lattice-designer-field-item:focus-visible{outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:-2px;box-shadow:0 0 0 2px var(--lattice-focus-color)}
|
|
171
|
+
.lattice-designer .lattice-designer-move{flex:0 0 auto;font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);
|
|
172
|
+
background:var(--lattice-surface);border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius,4px);
|
|
173
|
+
min-width:calc(var(--lattice-designer-space-4) + var(--lattice-designer-space-2));min-height:calc(var(--lattice-designer-space-4) + var(--lattice-designer-space-2));padding:0;margin:0;cursor:pointer}
|
|
174
|
+
.lattice-designer-move:disabled{opacity:.5;cursor:default}
|
|
175
|
+
.lattice-designer-clickfilter-targets{display:flex;flex-direction:column;gap:var(--lattice-designer-space-1);margin:0;padding:0}
|
|
176
|
+
.lattice-designer-clickfilter-targets label{display:flex;align-items:center;gap:var(--lattice-designer-space-2);margin:0}
|
|
177
|
+
.lattice-designer-pushdown-limits li,.lattice-designer-problem{margin:0}
|
|
178
|
+
.lattice-designer-problem{color:var(--lattice-invalid-border,var(--lattice-foreground))}
|
|
179
|
+
`,i="designer.properties.commit",v=Object.freeze(["markermap","bubblemap","choropleth","geomap"]),k=Object.freeze(["day","week","month","quarter","year"]);function r(w,G){let N=w;for(const T of G.split(".")){if(N==null)return;N=N[T]}return N}function m(w,G,N){const T=G.split(".");let C=w;for(let $=0;$<T.length-1;$++){const a=T[$];C[a]==null&&(C[a]=/^\d+$/.test(T[$+1])?[]:{}),C=C[a]}const h=T[T.length-1];if(N!==void 0){C[h]=N;return}delete C[h];for(let $=T.length-1;$>0;$--){const a=$===1?w:r(w,T.slice(0,$-1).join(".")),n=T[$-1],t=a&&a[n];if(F(t)&&!Object.keys(t).length)delete a[n];else break}}function c(w,G){let N;if(w.type==="boolean"?N=!!G:w.type==="number"?(N=G===""||G==null?void 0:Number(G),Number.isNaN(N)&&(N=void 0)):w.type==="enum"?N=G===""||G==null?void 0:G:w.type==="list"?(N=(Array.isArray(G)?G:String(G??"").split(",")).map(C=>String(C).trim()).filter(Boolean),N.length||(N=void 0)):N=y(G),!(w.type==="boolean"&&N===(w.default===void 0?!1:w.default))&&!(w.default!==void 0&&N===w.default))return N}function b(w){return w==null?"":typeof w=="string"?w:w.col||w.field||""}const y=w=>typeof w=="string"&&w.trim()?w:void 0,P=w=>w.path||w.role,u=w=>{const N=String(w).split(".").pop().replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase();return N.charAt(0).toUpperCase()+N.slice(1)};function E(w,G={}){const N=L(G&&G.messages),T=F(G.factories)?G.factories:{},C=globalThis.LatticeGrid||{},h=(ae,ee)=>typeof T[ae]=="function"?T[ae]:typeof C[ae]=="function"?C[ae]:ee,$=h("chartEditorModel",de),a=h("registeredChartTypes",J),n=w.chrome,t=n.ownerDocument;let e=null,s=!1,x=null;const S=t.createElement("div");S.className="lattice-designer-properties",S.setAttribute("role","group"),S.setAttribute("aria-label",N("designer.properties"));const B=t.createElement("div");B.className="lattice-designer-properties-live",B.setAttribute("role","status"),B.setAttribute("aria-live","polite"),Object.assign(B.style,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"}),S.appendChild(B),(w.rails?w.rails.right.slot():n).appendChild(S);const Y=(ae,ee)=>{const ye=N(ae);return ye===ae?ee:ye},te=ae=>Y(`designer.role.${ae}`,u(ae)),q=(ae,ee="opt")=>Y(`designer.${ee}.${ae}`,u(ae)),ne=(ae,ee,ye="opt")=>Y(`designer.${ye}.${ae}.${String(ee)}`,String(ee));let U=null;const M=()=>{const ae=w.getState();return ae.pages.find(ee=>F(ee)&&ee.id===ae.selectedPageId)||null},R=()=>{const ae=M();return ae&&F(ae.spec)&&Array.isArray(ae.spec.panels)?ae.spec.panels.filter(F):[]},H=()=>R().find(ae=>ae.id===e)||null,f=ae=>{let ee=ae;for(let ye=0;ye<12&&typeof ee=="string"&&ee.startsWith("grid:");ye++){const ve=R().find(be=>be.id===ee.slice(5));ee=ve?ve.source:null}return ee},g=(ae,ee)=>{const ye={...w.context&&w.context.sources,...F(M()&&M().spec.sources)?M().spec.sources:{}},ve=ae&&typeof ae.source=="string"?ye[ae.source]:null,be=ve&&Array.isArray(ve.fields)?ve.fields.find(Ee=>F(Ee)&&String(Ee.id)===String(ee)):null;return be&&be.label!=null?String(be.label):u(String(ee))},I=ae=>{const ee=[],ye=$e=>{$e&&!ee.includes($e)&&ee.push($e)},ve=w.pushdown&&typeof ae.source=="string"&&w.pushdown.isPushdown(ae.source)?w.pushdown.fields(ae.source.startsWith("grid:")?f(ae.source):ae.source):null;if(ve){for(const $e of ve)ye($e.id);return ee}const be=w.dashboard&&w.dashboard.panel(ae.id),Ee=be&&be.grid;if(Ee&&Ee.columns){const $e=typeof Ee.columns.all=="function"?Ee.columns.all():Array.isArray(Ee.columns)?Ee.columns:[];for(const Ge of $e)ye(Ge&&(Ge.field||Ge.id||Ge.key))}if(!ee.length){const $e={...w.context.sources,...F(M().spec.sources)?M().spec.sources:{}},Ge=typeof ae.source=="string"&&ae.source.startsWith("grid:")?null:ae.source,Ye=Ge&&$e[Ge];if(Ye&&Array.isArray(Ye.columns))for(const Se of Ye.columns)ye(typeof Se=="string"?Se:Se&&(Se.field||Se.id));else if(Ye&&Array.isArray(Ye.rows)&&F(Ye.rows[0]))for(const Se of Object.keys(Ye.rows[0]))ye(Se)}return ee},j=ae=>{const ee=M(),ye=Object.keys({...w.context.sources,...ee&&F(ee.spec.sources)?ee.spec.sources:{}}),ve=R().filter(be=>be.kind==="grid"&&be.id!==ae).map(be=>`grid:${be.id}`);return[...ye,...ve]},A=ae=>ae.kind==="chart"?$(ae.options&&ae.options.type||"bar"):ae.kind==="map"?$(ae.options&&ae.options.type||"markermap"):ie(ae.kind),D=ae=>ae.kind==="chart"?[...new Set([...z,...a()])]:ae.kind==="map"?[...new Set([...v,...a()])]:null,p=(ae,ee)=>{const ye=H();if(!ye)return!1;const ve=JSON.parse(JSON.stringify(ye));return ae(ve),ve.kind==="chart"&&typeof ve.source=="string"&&w.pushdown&&w.pushdown.isPushdown(ve.source)&&(ve.options=F(ve.options)?ve.options:{},ve.options.aggregate===void 0&&(ve.options.aggregate="engine")),!!w.commands.run(i,ye.id,ve,ee)},se=ae=>p(ee=>{ee.title=y(ae)},"setTitle"),V=ae=>p(ee=>{ee.source=ae||void 0},"setSource"),O=(ae,ee,ye)=>{const ve=H(),be=ve&&A(ve),Ee=be&&be.options.find($e=>$e.name===ae)||{name:ae,type:ee};return p($e=>{$e.options=F($e.options)?$e.options:{},m($e.options,ae,c(Ee,ye))},"setOption")},X=(ae,ee,ye,ve)=>{const be=(ae.entryOptions||[]).find(Ee=>Ee.name===ye);return be?p(Ee=>{const $e=r(F(Ee.options)?Ee.options:{},P(ae));!Array.isArray($e)||!F($e[ee])||m($e[ee],ye,c(be,ve))},"setOption"):!1},oe=(ae,ee,ye)=>p(ve=>{const be=r(F(ve.options)?ve.options:{},P(ae)),Ee=ee+ye;if(!Array.isArray(be)||ee<0||ee>=be.length||Ee<0||Ee>=be.length)return;const[$e]=be.splice(ee,1);be.splice(Ee,0,$e)},"moveEntry"),ue=(ae,ee,ye,ve)=>me(ve)?!1:p(be=>{be.options=F(be.options)?be.options:{};const Ee=be.options,$e=y(ye),Ge=P(ae);if(ae.repeatable){let Ye=r(Ee,Ge);if(Ye=Array.isArray(Ye)?Ye.slice():[],!$e)ee<Ye.length&&Ye.splice(ee,1);else{const Se=Ye[ee];ae.entryKey?Ye[ee]={...F(Se)?Se:{},[ae.entryKey]:$e}:Ye[ee]=ae.aggregated?ve?{col:$e,fn:ve}:$e:{field:$e}}m(Ee,Ge,Ye.length?Ye:void 0);return}ae.aggregated&&ae.aggPath?(m(Ee,Ge,$e),m(Ee,ae.aggPath,$e&&ve?ve:void 0)):ae.aggregated?m(Ee,Ge,$e?ve?{col:$e,fn:ve}:$e:void 0):m(Ee,Ge,$e)},"setRole"),xe=ae=>{const ee=H();return ae&&ee&&typeof ee.source=="string"&&w.pushdown?w.pushdown.refusal(ee.source,{aggregation:ae}):""},me=ae=>{const ee=xe(ae);return ee?(B.textContent=N("designer.pushdown.refused",{name:ae,reason:ee}),!0):!1},we=ae=>p(ee=>{ee.options=F(ee.options)?ee.options:{},m(ee.options,"bucket",ae||void 0)},"setBucket"),Pe=ae=>{const ee=H();if(!ee||ee.kind!=="chart"&&ee.kind!=="map")return{type:ae,dropped:[]};const ye=A(ee),ve=$(ae).roles,be=new Map(ve.map(Ne=>[Ne.role,Ne])),Ee=F(ee.options)?ee.options:{},$e={type:ae},Ge=[];for(const Ne of ye.roles){const Ve=r(Ee,P(Ne));if(!(Ve!=null&&!(Array.isArray(Ve)&&!Ve.length)))continue;const Oe=be.get(Ne.role);if(!Oe||Oe.accepts!==Ne.accepts){Ge.push(Ne.role);continue}if(m($e,P(Oe),Ve),Ne.aggPath&&Oe.aggPath){const Xe=r(Ee,Ne.aggPath);Xe!==void 0&&m($e,Oe.aggPath,Xe)}}for(const Ne of $(ae).options){const Ve=r(Ee,Ne.name);Ve!==void 0&&m($e,Ne.name,Ve)}p(Ne=>{Ne.options=$e},"setType");const Ye=N(`chart.type.${ae}`),Se=Ye===`chart.type.${ae}`?ae:Ye;return B.textContent=Ge.length?N("designer.chart.dropped",{type:Se,roles:Ge.map(te).join(", ")}):N("designer.chart.switched",{type:Se}),x={type:ae,dropped:Ge},x},Fe=(ae,ee)=>{const ye=t.createElement("label");ye.className="lattice-designer-field";const ve=t.createElement("span");return ve.className="lattice-designer-field-label",ve.textContent=ae,ve.title=ae,ye.appendChild(ve),ye.appendChild(ee),ye},Z=(ae,ee,ye,ve)=>{const be=t.createElement("select");be.setAttribute("aria-label",ae);for(const Ee of ye){const $e=t.createElement("option");$e.value=Ee.value,$e.textContent=Ee.label,Ee.disabled&&($e.disabled=!0,$e.title=Ee.title||""),Ee.value===ee&&($e.selected=!0),be.appendChild($e)}return be.value=ee,be.addEventListener("change",()=>ve(be.value)),be},re=(ae,ee,ye)=>{const ve=t.createElement("button");return ve.type="button",ve.textContent=ae,ve.setAttribute("aria-label",ee),ve.addEventListener("click",ye),ve},le=(ae,ee,ye,ve,be)=>{if(ae.type==="boolean"){const $e=t.createElement("input");return $e.type="checkbox",$e.setAttribute("aria-label",ye),$e.checked=ee===void 0?ae.default===!0:ee===!0,$e.addEventListener("change",()=>be($e.checked)),$e}if(ae.type==="enum"){const Ge=[{value:"",label:ae.default!==void 0?`${N("designer.opt.default")} (${ne(ae.name,ae.default,ve)})`:N("designer.opt.default")},...ae.values.map((Se,Ne)=>({value:String(Ne),label:ne(ae.name,Se,ve)}))],Ye=ae.values.indexOf(ee);return Z(ye,Ye<0?"":String(Ye),Ge,Se=>be(Se===""?void 0:ae.values[Number(Se)]))}const Ee=t.createElement("input");if(Ee.type=ae.type==="number"?"number":"text",Ee.setAttribute("aria-label",ye),Ee.placeholder=ae.default!==void 0?String(ae.default):N("designer.opt.empty"),ae.type==="number")for(const $e of["min","max","step"])typeof ae[$e]=="number"&&Ee.setAttribute($e,String(ae[$e]));return ae.format&&(Ee.dataset.format=ae.format),Array.isArray(ee)?Ee.value=ee.join(", "):ee!=null&&(Ee.value=String(ee)),Ee.value&&(Ee.title=Ee.value),Ee.addEventListener("change",()=>be(Ee.value)),Ee},pe=(ae,ee)=>{ae.dataset.dropTarget="true",ae.addEventListener("dragover",ye=>{ye.preventDefault()}),ae.addEventListener("drop",ye=>{ye.preventDefault();const ve=ye.dataTransfer,be=ve&&typeof ve.getData=="function"&&ve.getData("text/plain")||"";be&&ee(be)})},he=(ae,ee,ye)=>{const ve=I(ae),Ee=[{value:"",label:N("designer.field.none")},...ve.map(Be=>({value:Be,label:g(ae,Be)}))],$e=[{value:"",label:N("designer.agg.default")},...ye.aggregations.map(Be=>{const Oe=xe(Be);return{value:Be,label:Y(`designer.agg.${Be}`,u(Be)),disabled:!!Oe,title:Oe}})],Ge=F(ae.options)?ae.options:{},Ye=r(Ge,P(ee)),Se=ee.repeatable?Array.isArray(Ye)?Ye.slice():[]:[Ye],Ne=[],Ve=ee.repeatable?Se.length+1:1;for(let Be=0;Be<Ve;Be++){const Oe=Se[Be],Xe=b(Oe),nt=ee.aggregated&&ee.aggPath?r(Ge,ee.aggPath)||"":Oe&&typeof Oe=="object"&&Oe.fn||"",st=ee.repeatable?`${te(ee.role)} ${Be+1}`:te(ee.role),ft=t.createElement("span");ft.className="lattice-designer-role-controls";const ht=Z(st,Xe,Ee,dt=>ue(ee,Be,dt,nt));if(ht.dataset.role=ee.role,ht.addEventListener("keydown",dt=>{if(U&&dt.key==="Enter"){dt.preventDefault();const mt=U;U=null,ue(ee,Be,mt,nt)}}),ft.appendChild(ht),ee.aggregated&&ft.appendChild(Z(N("designer.agg",{role:st}),nt,$e,dt=>ue(ee,Be,Xe,dt))),ee.bucketable){const dt=[{value:"",label:N("designer.bucket.none")},...k.map(At=>({value:At,label:N(`designer.bucket.${At}`)}))],mt=r(Ge,"bucket")||"";ft.appendChild(Z(N("designer.bucket.of",{role:st}),mt,dt,At=>we(At)))}if(ee.entryOptions&&F(Oe)){for(const dt of ee.entryOptions){const mt=`${st} ${q(dt.name,"col")}`,At=le(dt,r(Oe,dt.name),mt,"col",ct=>X(ee,Be,dt.name,ct));At.dataset.option=dt.name,ft.appendChild(At)}if(ee.orderable){const dt=re("↑",N("designer.move.earlier",{item:`${st} (${Xe})`}),()=>oe(ee,Be,-1)),mt=re("↓",N("designer.move.later",{item:`${st} (${Xe})`}),()=>oe(ee,Be,1));dt.className="lattice-designer-move",mt.className="lattice-designer-move",dt.disabled=Be===0,mt.disabled=Be>=Se.length-1,ft.appendChild(dt),ft.appendChild(mt)}}const $t=Fe(st,ft);pe($t,dt=>ue(ee,Be,dt,nt)),Ne.push($t)}return Ne},Me=ae=>{if(ae.kind!=="grid"&&ae.kind!=="chart"||!w.filters)return null;const ee=w.getState(),ye=F(ee.panels)&&F(ee.panels[ae.id])?ee.panels[ae.id]:null,ve=ye&&F(ye.clickFilter)?ye.clickFilter:null,be=R().filter(Be=>Be.id!==ae.id&&Be.kind!=="html"),Ee=I(ae),$e=ve&&typeof ve.on=="string"?ve.on:Ee[0]||"",Ge=ve?ve.targets==="all"?"all":"chosen":"none",Ye=ot(N("designer.section.interactions")),Se=Ye.body,Ne=(Be,Oe)=>{if(Be==="none"){w.filters.setClickFilter(ae.id,null);return}w.filters.setClickFilter(ae.id,{targets:Be==="all"?"all":Array.isArray(Oe)?Oe:[],on:$e})},Ve=[{value:"none",label:N("designer.clickFilter.none")},{value:"all",label:N("designer.clickFilter.all")},{value:"chosen",label:N("designer.clickFilter.chosen")}];if(Se.appendChild(Fe(N("designer.clickFilter"),Z(N("designer.clickFilter"),Ge,Ve,Be=>Ne(Be,ve&&Array.isArray(ve.targets)?ve.targets:[])))),Ge!=="none"&&Ee.length&&Se.appendChild(Fe(N("designer.clickFilter.on"),Z(N("designer.clickFilter.on"),$e,Ee.map(Be=>({value:Be,label:g(ae,Be)})),Be=>w.filters.setClickFilter(ae.id,{targets:Ge==="all"?"all":ve&&Array.isArray(ve.targets)?ve.targets:[],on:Be})))),Ge==="chosen"&&be.length){const Be=t.createElement("div");Be.className="lattice-designer-clickfilter-targets";for(const Oe of be){const Xe=t.createElement("label"),nt=t.createElement("input");nt.type="checkbox",nt.checked=!!(ve&&Array.isArray(ve.targets)&&ve.targets.includes(Oe.id)),nt.addEventListener("change",()=>{const st=new Set(ve&&Array.isArray(ve.targets)?ve.targets:[]);nt.checked?st.add(Oe.id):st.delete(Oe.id),w.filters.setClickFilter(ae.id,{targets:[...st],on:$e})}),Xe.appendChild(nt),Xe.appendChild(t.createTextNode(` ${Oe.title||Oe.id}`)),Be.appendChild(Xe)}Se.appendChild(Be)}return Ye.el},Ie=(ae,ee)=>{const ye=r(F(ae.options)?ae.options:{},ee.name),ve=q(ee.name),be=le(ee,ye,ve,"opt",Ee=>O(ee.name,ee.type,Ee));return be.dataset.option=ee.name,Fe(ve,be)},Ke=ae=>{const ee=t.createElement("ul");ee.className="lattice-designer-fields",ee.setAttribute("aria-label",N("designer.section.fields"));for(const ye of I(ae)){const ve=t.createElement("li"),be=re(ye,N("designer.field.pick",{field:ye}),()=>{U=U===ye?null:ye,B.textContent=U?N("designer.field.picked",{field:ye}):"",it()});be.className="lattice-designer-field-item",be.draggable=!0,be.setAttribute("draggable","true"),be.setAttribute("aria-pressed",U===ye?"true":"false"),be.dataset.field=ye,be.addEventListener("dragstart",Ee=>{const $e=Ee.dataTransfer;$e&&typeof $e.setData=="function"&&($e.setData("text/plain",ye),$e.effectAllowed="copy")}),be.addEventListener("keydown",Ee=>{Ee.key==="Escape"&&U&&(U=null,B.textContent="",it())}),ve.appendChild(be),ee.appendChild(ve)}return ee};let qe=0;const ot=(ae,ee=!0)=>{qe+=1;const ye=t.createElement("section");ye.className="lattice-designer-section",ye.setAttribute("data-expanded",ee?"true":"false");const ve=t.createElement("h3");ve.className="lattice-designer-section-title";const be=t.createElement("button");be.type="button",be.className="lattice-designer-section-toggle";const Ee=`lattice-designer-section-${qe}`;be.setAttribute("aria-expanded",ee?"true":"false"),be.setAttribute("aria-controls",Ee),be.setAttribute("aria-label",ae);const $e=t.createElement("span");$e.className="lattice-designer-section-mark",$e.setAttribute("aria-hidden","true"),$e.textContent=ee?"▾":"▸";const Ge=t.createElement("span");Ge.className="lattice-designer-section-label",Ge.textContent=ae,be.appendChild($e),be.appendChild(Ge),ve.appendChild(be);const Ye=t.createElement("div");return Ye.className="lattice-designer-section-body",Ye.id=Ee,ee||Ye.setAttribute("hidden",""),be.addEventListener("click",()=>{const Se=be.getAttribute("aria-expanded")!=="true";be.setAttribute("aria-expanded",Se?"true":"false"),ye.setAttribute("data-expanded",Se?"true":"false"),$e.textContent=Se?"▾":"▸",Se?Ye.removeAttribute("hidden"):Ye.setAttribute("hidden","")}),ye.appendChild(ve),ye.appendChild(Ye),{el:ye,body:Ye}},it=()=>{if(s)return;const ae=R();ae.some(Oe=>Oe.id===e)||(e=ae.length?ae[0].id:null);const ee=t.activeElement,ye=ee&&S.contains(ee)?ge(ee):null;[...S.children].forEach(Oe=>{Oe!==B&&Oe.remove()});const ve=Z(N("designer.prop.widget"),e||"",ae.map(Oe=>({value:Oe.id,label:Oe.title||Oe.id})),Oe=>{e=Oe||null,it()});S.appendChild(Fe(N("designer.prop.widget"),ve));const be=H();if(!be){const Oe=t.createElement("p");Oe.className="lattice-designer-properties-empty",Oe.textContent=N("designer.properties.empty"),S.appendChild(Oe);return}const Ee=ot(N("designer.section.widget")),$e=t.createElement("input");$e.type="text",$e.setAttribute("aria-label",N("designer.prop.title")),$e.placeholder=N("designer.prop.title.hint"),be.title!=null&&($e.value=String(be.title),$e.title=$e.value),$e.addEventListener("change",()=>se($e.value)),Ee.body.appendChild(Fe(N("designer.prop.title"),$e));const Ge=[{value:"",label:N("designer.field.none")},...j(be.id).map(Oe=>({value:Oe,label:Oe}))];Ee.body.appendChild(Fe(N("designer.prop.source"),Z(N("designer.prop.source"),be.source||"",Ge,Oe=>V(Oe))));const Ye=D(be);if(Ye){const Oe=be.options&&be.options.type||Ye[0],Xe=Ye.map(nt=>{const st=N(`chart.type.${nt}`);return{value:nt,label:st===`chart.type.${nt}`?nt:st}});Ee.body.appendChild(Fe(N("designer.prop.type"),Z(N("designer.prop.type"),Oe,Xe,nt=>Pe(nt))))}S.appendChild(Ee.el);const Se=A(be),Ne=w.pushdown&&typeof be.source=="string"&&w.pushdown.isPushdown(be.source)?w.pushdown.refusals(be.source,Se?Se.aggregations:[]):[];if(Se&&Se.roles.length||Ne.length){const Oe=ot(N("designer.section.data"));if(Se&&Se.roles.length){I(be).length&&Oe.body.appendChild(Ke(be));for(const Xe of Se.roles)for(const nt of he(be,Xe,Se))Oe.body.appendChild(nt)}if(Ne.length){const Xe=t.createElement("div");Xe.className="lattice-designer-pushdown-limits";const nt=t.createElement("ul");for(const st of Ne){const ft=t.createElement("li");ft.setAttribute("data-refused",`${st.kind}:${st.name}`),ft.textContent=st.kind==="step"?N("designer.pushdown.refusedStep",{step:st.name,reason:st.reason}):N("designer.pushdown.refused",{name:Y(`designer.agg.${st.name}`,u(st.name)),reason:st.reason}),nt.appendChild(ft)}Xe.appendChild(nt),Oe.body.appendChild(Xe)}S.appendChild(Oe.el)}if(Se&&Se.options.length){const Oe=ot(N("designer.section.format"));for(const Xe of Se.options)Oe.body.appendChild(Ie(be,Xe));S.appendChild(Oe.el)}const Ve=Me(be);Ve&&S.appendChild(Ve);const Be=(w.dashboard?w.dashboard.problems():[]).filter(Oe=>Oe.id===`dashboard:panel:${be.id}`);if(Be.length){const Oe=ot(N("designer.problems"));Oe.el.setAttribute("role","alert");for(const Xe of Be){const nt=t.createElement("p");nt.className="lattice-designer-problem",nt.textContent=Xe.message,Oe.body.appendChild(nt)}S.appendChild(Oe.el)}if(ye){const Oe=Array.from(S.querySelectorAll("select, input, button")).find(Xe=>ge(Xe)===ye);Oe&&typeof Oe.focus=="function"&&Oe.focus()}},ge=ae=>ae.getAttribute&&ae.getAttribute("aria-label")||null;w.commands.register(i,(ae,ee,ye,ve)=>{const be=ae.getState(),Ee=be.pages.find(Ge=>F(Ge)&&Ge.id===be.selectedPageId);if(!Ee||!F(Ee.spec)||!Array.isArray(Ee.spec.panels))return!1;const $e=Ee.spec.panels.findIndex(Ge=>F(Ge)&&Ge.id===ee);return $e<0?!1:(Ee.spec.panels[$e]=ye,ae.commit(be,ve||"setProperty"))});const Le=w.on("state",it),He=w.on("mode",it),Ze=w.pushdown?w.pushdown.onChange(it):()=>{};return it(),{get el(){return S},selectedPanelId(){return e},selectPanel(ae){return R().some(ee=>ee.id===ae)?(e=ae,it(),!0):!1},setTitle:se,setSource:V,setOption:O,setEntryOption:X,moveEntry:oe,editRole:ue,switchType:Pe,fields(){const ae=H();return ae?I(ae):[]},get lastSwitch(){return x},refresh:it,destroy(){s||(s=!0,Le(),He(),Ze(),S.remove())}}}const d=E}),rt("packages/core/src/internal/icon-builtins.js",function(o,ce){"use strict";Object.defineProperty(o,"BUILT_IN_ICONS",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(o,"normaliseIcon",{enumerable:!0,get:function(){return F}});const ke={chevronRight:{viewBox:"0 0 16 16",paths:["M6 3.5 10.5 8 6 12.5"],paint:"stroke"},chevronDown:{viewBox:"0 0 16 16",paths:["M3.5 6 8 10.5 12.5 6"],paint:"stroke"},chevronUp:{viewBox:"0 0 16 16",paths:["M3.5 10 8 5.5 12.5 10"],paint:"stroke"},chevronLeft:{viewBox:"0 0 16 16",paths:["M10 3.5 5.5 8 10 12.5"],paint:"stroke"},check:{viewBox:"0 0 16 16",paths:["M3.5 8.5 6.5 11.5 12.5 4.5"],paint:"stroke"},dash:{viewBox:"0 0 16 16",paths:["M4 8h8"],paint:"stroke"},close:{viewBox:"0 0 16 16",paths:["M4 4l8 8M12 4l-8 8"],paint:"stroke"},plus:{viewBox:"0 0 16 16",paths:["M8 3.5v9M3.5 8h9"],paint:"stroke"},minus:{viewBox:"0 0 16 16",paths:["M3.5 8h9"],paint:"stroke"},info:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm.75 4a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM7.25 7h1.5v4.5h-1.5Z"]},success:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm3.2 4.4-4 4.6-2.4-2.3 1-1.1 1.3 1.2 3-3.4Z"]},warning:{viewBox:"0 0 16 16",paths:["M8 1.5 15 14H1Zm-.75 4v4h1.5v-4Zm0 5v1.5h1.5V10.5Z"]},danger:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm-.75 3h1.5v5h-1.5Zm0 6h1.5V12h-1.5Z"]},clock:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm-.75 3h1.5v3.7l2.5 1.5-.75 1.3-3.25-2Z"]},lock:{viewBox:"0 0 16 16",paths:["M4.5 7V5a3.5 3.5 0 1 1 7 0v2H13v7H3V7Zm1.5 0h4V5a2 2 0 1 0-4 0Z"]},link:{viewBox:"0 0 16 16",paths:["M6.5 9.5a3 3 0 0 1 0-4l2-2a3 3 0 0 1 4 4l-1 1M9.5 6.5a3 3 0 0 1 0 4l-2 2a3 3 0 0 1-4-4l1-1"],paint:"stroke"},external:{viewBox:"0 0 16 16",paths:["M6.5 3.5h-3v9h9v-3M9.5 3.5h3v3M12.5 3.5 7 9"],paint:"stroke"},filter:{viewBox:"0 0 16 16",paths:["M2 3h12l-4.5 5.2V13L6.5 11.5V8.2Z"]},pause:{viewBox:"0 0 16 16",paths:["M4.5 3h2.5v10H4.5zM9 3h2.5v10H9z"]},play:{viewBox:"0 0 16 16",paths:["M4.5 3l8 5-8 5z"]},chart:{viewBox:"0 0 16 16",paths:["M2.5 13.5h11","M4.5 13.5v-4","M8 13.5v-8","M11.5 13.5v-6"],paint:"stroke"},palette:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 0 0 0 13c.7 0 1.2-.5 1.2-1.1 0-.3-.1-.6-.3-.8a1.1 1.1 0 0 1 .8-1.9h1.4A3.4 3.4 0 0 0 14.5 7c0-3-2.9-5.5-6.5-5.5Z","M4.6 7.6a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM6.7 4.6a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM9.9 4.7a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM11.9 6.9a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"]},undo:{viewBox:"0 0 16 16",paths:["M3 8h6.5a3.25 3.25 0 0 1 0 6.5H6M3 8l3-3M3 8l3 3"],paint:"stroke"},redo:{viewBox:"0 0 16 16",paths:["M13 8H6.5a3.25 3.25 0 0 0 0 6.5H10M13 8l-3-3M13 8l-3 3"],paint:"stroke"},columns:{viewBox:"0 0 16 16",paths:["M2.5 2.5h11v11h-11zM6.5 2.5v11M10 2.5v11"],paint:"stroke"},download:{viewBox:"0 0 16 16",paths:["M8 2.5v7.5M8 10 5 7M8 10l3-3M2.5 12.5h11"],paint:"stroke"},restore:{viewBox:"0 0 16 16",paths:["M3 8a5 5 0 1 0 1.6-3.7M3 3v2.8h2.8"],paint:"stroke"},spreadsheet:{viewBox:"0 0 16 16",paths:["M3 2.5h10v11H3zM3 6h10M3 9.5h10M6.5 6v7.5"],paint:"stroke"},print:{viewBox:"0 0 16 16",paths:["M4.5 6V2.5h7V6M4.5 11.5h-2V6h11v5.5h-2M4.5 9.5h7v4h-7z"],paint:"stroke"},maximise:{viewBox:"0 0 16 16",paths:["M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10"],paint:"stroke"},minimise:{viewBox:"0 0 16 16",paths:["M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"],paint:"stroke"},views:{viewBox:"0 0 16 16",paths:["M4 2.5h8v11L8 11l-4 2.5z"],paint:"stroke"},search:{viewBox:"0 0 16 16",paths:["M7 2.5a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9M10.4 10.4 13.5 13.5"],paint:"stroke"},pencil:{viewBox:"0 0 16 16",paths:["M2.5 11.2 11 2.7l2.3 2.3-8.5 8.5-3 .7z"],paint:"stroke"},trash:{viewBox:"0 0 16 16",paths:["M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.7 8.5h5.6l.7-8.5M6.8 7v3.7M9.2 7v3.7"],paint:"stroke"},share:{viewBox:"0 0 16 16",paths:["M11.5 5.5a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6M4.5 9.8a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6M11.5 14.1a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6M6.1 7.1l3.8-1.9M6.1 8.9l3.8 1.9"],paint:"stroke"},pin:{viewBox:"0 0 16 16",paths:["M8 2v6M5 8h6l1 2.5H4zM8 10.5V14"],paint:"stroke"},sortAsc:{viewBox:"0 0 16 16",paths:["M8 3.5 12 8H4Z"]},sortDesc:{viewBox:"0 0 16 16",paths:["M8 12.5 4 8h8Z"]},menu:{viewBox:"0 0 16 16",paths:["M2.5 4.5h11M2.5 8h11M2.5 11.5h11"],paint:"stroke"},drag:{viewBox:"0 0 16 16",paths:["M6 3.5h1.5V5H6Zm3 0h1.5V5H9ZM6 7.25h1.5v1.5H6Zm3 0h1.5v1.5H9ZM6 11h1.5v1.5H6Zm3 0h1.5v1.5H9Z"]},star:{viewBox:"0 0 16 16",paths:["M8 1.6l1.96 3.97 4.38.64-3.17 3.09.75 4.36L8 11.6l-3.92 2.06.75-4.36L1.66 6.21l4.38-.64Z"]},heart:{viewBox:"0 0 16 16",paths:["M8 14.2 2.4 8.6a3.3 3.3 0 0 1 4.67-4.67L8 4.86l.93-.93A3.3 3.3 0 0 1 13.6 8.6Z"]},circleFilled:{viewBox:"0 0 16 16",paths:["M8 2a6 6 0 1 0 0 12A6 6 0 0 0 8 2Z"]},square:{viewBox:"0 0 16 16",paths:["M3 3h10v10H3Z"]},bolt:{viewBox:"0 0 16 16",paths:["M9.5 1.5 3.5 9h3.2l-.7 5.5L12.5 7H9.3Z"]},flag:{viewBox:"0 0 16 16",paths:["M4 1.5h1.5v13H4Zm1.5 1h7.5l-1.6 2.6L13 7.7H5.5Z"]},arrow:{viewBox:"0 0 16 16",paths:["M3 13 12.5 3.5","M7.5 3.5H12.5V8.5"],paint:"stroke"},highlight:{viewBox:"0 0 16 16",paths:["M4 11 10 5l2 2-6 6H4z","M3 14.5h10"],paint:"stroke"},eraser:{viewBox:"0 0 16 16",paths:["M3 11 9 5 13 9 7 15Z","M5 13 9 9"],paint:"stroke"},thumbUp:{viewBox:"0 0 16 16",paths:["M5.5 6.8 8.6 1.5a1.6 1.6 0 0 1 1.5 2.1L9.4 6h3.4a1.4 1.4 0 0 1 1.35 1.78l-1.3 4.6A1.9 1.9 0 0 1 11 13.8H5.5ZM4 6.5H1.5v7.3H4Z"]},eye:{viewBox:"0 0 16 16",paths:["M8 3.2c3.3 0 6 3 6.6 4.5C14 9.3 11.3 12.3 8 12.3S2 9.3 1.4 7.7C2 6.2 4.7 3.2 8 3.2Zm0 2a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5Z"]},eyeOff:{viewBox:"0 0 16 16",paths:["M2.2 2.9 13.1 13.8M8 3.2c3.3 0 6 3 6.6 4.5a9.4 9.4 0 0 1-1.9 2.4M5 4.2A9 9 0 0 0 1.4 7.7C2 9.3 4.7 12.3 8 12.3c.9 0 1.7-.2 2.5-.5M6.3 6a2.5 2.5 0 0 0 3.4 3.5"],paint:"stroke"},copy:{viewBox:"0 0 16 16",paths:["M5.5 2.5h8v8M2.5 5.5h8v8h-8Z"],paint:"stroke"},present:{viewBox:"0 0 16 16",paths:["M2 2.5h12v8H2Z","M8 10.5v3","M6 13.5h4"],paint:"stroke"},cabinet:{viewBox:"0 0 16 16",paths:["M3 2h10v12H3ZM5 4v4h2.5V4ZM8.5 4v4H11V4ZM5 9.5V11h6V9.5Z"]},splice:{viewBox:"0 0 16 16",paths:["M8 4.5a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7ZM8 6.8a1.2 1.2 0 1 1 0 2.4 1.2 1.2 0 0 1 0-2.4ZM1.5 7.2h3v1.6h-3ZM11.5 7.2h3v1.6h-3Z"]},exchange:{viewBox:"0 0 16 16",paths:["M8 1.5 14.5 6v1H1.5V6ZM3 8h2v5H3ZM7 8h2v5H7ZM11 8h2v5h-2ZM1.5 13.5h13V15h-13Z"]},pole:{viewBox:"0 0 16 16",paths:["M7.2 1.5h1.6V15H7.2ZM3 3.5h10V5H3ZM4.5 7h7v1.4h-7Z"]},chamber:{viewBox:"0 0 16 16",paths:["M2.5 3.5h11v9h-11ZM4.5 5.5v5h7v-5ZM6 7h4v1.5H6Z"]},premises:{viewBox:"0 0 16 16",paths:["M8 1.8 14.5 7.5h-2V14h-9V7.5h-2ZM6.8 10.4V14h2.4v-3.6Z"]},fault:{viewBox:"0 0 16 16",paths:["M5.2 1.5h5.6L14.5 5.2v5.6L10.8 14.5H5.2L1.5 10.8V5.2ZM5.4 9.4 6.6 10.6 8 9.2 9.4 10.6 10.6 9.4 9.2 8 10.6 6.6 9.4 5.4 8 6.8 6.6 5.4 5.4 6.6 6.8 8Z"]},blank:{viewBox:"0 0 16 16",paths:[""]}};function F(l){return typeof l=="string"?{viewBox:"0 0 16 16",paths:[l],paint:"fill"}:Array.isArray(l)?{viewBox:"0 0 16 16",paths:l.slice(),paint:"fill"}:{viewBox:l&&l.viewBox||"0 0 16 16",paths:l&&Array.isArray(l.paths)?l.paths.slice():l&&l.path?[l.path]:[],paint:l&&l.paint==="stroke"?"stroke":"fill"}}}),rt("packages/dom/src/cell/icons.js",function(o,ce){"use strict";Object.defineProperty(o,"SVG_NS",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"registerIcon",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"registerIcons",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"icon",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"iconNames",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"createIcon",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"updateIcon",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"isIconMarkup",{enumerable:!0,get:function(){return k}}),Object.defineProperty(o,"renderIconInto",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"resetIcons",{enumerable:!0,get:function(){return m}});const F=ce("packages/core/src/internal/util.js").warnOnce,l=ce("packages/core/src/internal/icon-builtins.js"),de=l.BUILT_IN_ICONS,z=l.normaliseIcon,fe="http://www.w3.org/2000/svg",J=new Map(Object.entries(de));function Q(c,b){J.set(c,z(b))}function ie(c){if(c)for(const b of Object.keys(c))Q(b,c[b])}function W(c){return J.get(c)}function L(){return[...J.keys()]}function _(c,b,y){let P=J.get(b);P||(F(`icon:${b}`,`Unknown icon '${b}'; drew a blank glyph in its place. Register it with grid.icons or config.icons.`),P=J.get("blank"));const u=c.createElementNS(fe,"svg");u.setAttribute("class",y&&y.className||"lat-icon"),u.setAttribute("viewBox",P.viewBox),u.setAttribute("focusable","false"),u.setAttribute("aria-hidden","true"),v(u,P.paint);const E=[];for(const d of P.paths){const w=c.createElementNS(fe,"path");w.setAttribute("d",d),u.appendChild(w),E.push(w)}return u.__latIcon={name:b,nodes:E,paint:P.paint},u}function i(c,b){const y=c&&c.__latIcon;if(!y)return!1;if(y.name===b)return!0;const P=J.get(b);if(!P)return F(`icon:${b}`,`Unknown icon '${b}'. Register it with grid.icons or config.icons.`),!1;if(P.paths.length!==y.nodes.length)return!1;for(let u=0;u<P.paths.length;u++)y.nodes[u].setAttribute("d",P.paths[u]);return c.setAttribute("viewBox",P.viewBox),P.paint!==y.paint&&(v(c,P.paint),y.paint=P.paint),y.name=b,!0}function v(c,b){if(b==="stroke"){c.setAttribute("fill","none"),c.setAttribute("stroke","currentColor"),c.setAttribute("stroke-width","1.5"),c.setAttribute("stroke-linecap","round"),c.setAttribute("stroke-linejoin","round");return}c.setAttribute("fill","currentColor"),c.removeAttribute("stroke"),c.removeAttribute("stroke-width"),c.removeAttribute("stroke-linecap"),c.removeAttribute("stroke-linejoin")}function k(c){if(typeof c!="string")return!1;const b=c.trim();return/^<[a-zA-Z!/]/.test(b)&&b.includes(">")}function r(c,b,y){return c.textContent="",c.removeAttribute("data-icon"),b==null||b===""?(b===""&&F(`icon:empty:${y}`,`An empty icon value at ${y} renders nothing; omit \`icon\` instead.`),c):typeof b!="string"?(F(`icon:type:${y}`,`An icon must be a name, a character, or element markup; got ${typeof b} at ${y}.`),c):k(b)?(c.innerHTML=b,c):(c.setAttribute("data-icon",b),c)}function m(){J.clear();for(const[c,b]of Object.entries(de))J.set(c,b)}}),rt("packages/modules/designer/data-panel.js",function(o,ce){"use strict";Object.defineProperty(o,"dataPanelCss",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"FIELD_TYPES",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"stripDeclaredFields",{enumerable:!0,get:function(){return y}}),Object.defineProperty(o,"resolveSourceFields",{enumerable:!0,get:function(){return P}}),Object.defineProperty(o,"compileRelationships",{enumerable:!0,get:function(){return d}}),Object.defineProperty(o,"reachableSources",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"mountDataPanel",{enumerable:!0,get:function(){return $}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return a}});const ke=ce("packages/core/src/internal/util.js"),F=ke.warnOnce,l=ke.isFunction,z=ce("packages/modules/dashboard/spec.js").isPlain,J=ce("packages/dom/src/cell/icons.js").SVG_NS,Q=()=>`
|
|
180
|
+
.lattice-designer-datapanel{display:flex;flex-direction:column;gap:var(--lattice-designer-space-2);min-width:0;box-sizing:border-box;
|
|
181
|
+
font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground)}
|
|
182
|
+
.lattice-designer .lattice-designer-datapanel__search{width:100%;box-sizing:border-box;margin:0;
|
|
183
|
+
font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);background:var(--lattice-surface);
|
|
184
|
+
border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius,4px);
|
|
185
|
+
padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2)}
|
|
186
|
+
.lattice-designer-datapanel__fields,.lattice-designer-datapanel__derived,.lattice-designer-datapanel__relationships{
|
|
187
|
+
margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:var(--lattice-designer-space-1)}
|
|
188
|
+
.lattice-designer-datapanel__source{display:flex;flex-direction:column;gap:var(--lattice-designer-space-1)}
|
|
189
|
+
.lattice-designer-datapanel__source-title{font:var(--lattice-designer-font-heading) var(--lattice-font-family);
|
|
190
|
+
font-weight:var(--lattice-header-font-weight,600);color:var(--lattice-foreground)}
|
|
191
|
+
.lattice-designer-datapanel__type-group{display:flex;flex-direction:column;gap:var(--lattice-designer-space-1)}
|
|
192
|
+
.lattice-designer-datapanel__type-label{font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground-muted)}
|
|
193
|
+
.lattice-designer-datapanel__field{display:flex;align-items:center;gap:var(--lattice-designer-space-2);min-width:0;box-sizing:border-box;
|
|
194
|
+
font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);
|
|
195
|
+
padding:var(--lattice-designer-space-1);margin:0;cursor:grab;border-radius:var(--lattice-radius,4px)}
|
|
196
|
+
.lattice-designer-datapanel__field:hover{background:var(--lattice-hovered-background)}
|
|
197
|
+
.lattice-designer-datapanel__field:focus-visible{outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:-2px;box-shadow:0 0 0 2px var(--lattice-focus-color)}
|
|
198
|
+
.lattice-designer-datapanel__field-label{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
199
|
+
.lattice-designer-datapanel__field-desc{color:var(--lattice-foreground-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
200
|
+
.lattice-designer-datapanel__icon{flex:0 0 auto;width:16px;height:16px}
|
|
201
|
+
.lattice-designer-datapanel__empty,.lattice-designer-datapanel__reachable{margin:0;color:var(--lattice-foreground-muted)}
|
|
202
|
+
`,ie=Object.freeze(["number","currency","percent","date","datetime","boolean","text","list","geometry"]),W=Object.freeze({number:{viewBox:"0 0 16 16",paths:["M3 13V7l2-2M8 13V5l2-2M12 13V9l2-2"],paint:"stroke"},currency:{viewBox:"0 0 16 16",paths:["M8 2.5v11M10.5 4.8c0-1-1-1.6-2.3-1.6-1.6 0-2.7.8-2.7 2s1 1.7 2.5 2 2.7.8 2.7 2.1-1.1 2-2.7 2c-1.3 0-2.4-.6-2.5-1.6"],paint:"stroke"},percent:{viewBox:"0 0 16 16",paths:["M3.5 12.5 12.5 3.5M5 6a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm6 7a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z"],paint:"stroke"},date:{viewBox:"0 0 16 16",paths:["M3 3.5h10v10H3zM3 6.5h10M5.5 2v3M10.5 2v3"],paint:"stroke"},datetime:{viewBox:"0 0 16 16",paths:["M3 3.5h10v10H3zM3 6.5h10M5.5 2v3M10.5 2v3M8 8.5v2l1.5 1"],paint:"stroke"},boolean:{viewBox:"0 0 16 16",paths:["M5 8.5 7 11l4.5-6"],paint:"stroke"},text:{viewBox:"0 0 16 16",paths:["M3 3.5h10M8 3.5v9"],paint:"stroke"},list:{viewBox:"0 0 16 16",paths:["M4 4h8M4 8h8M4 12h8"],paint:"stroke"},geometry:{viewBox:"0 0 16 16",paths:["M8 2.5 13.5 12.5h-11Z"],paint:"stroke"}});function L(n,t){const e=W[t]||W.text,s=n.createElementNS(J,"svg");s.setAttribute("class","lattice-designer-datapanel__icon lat-icon"),s.setAttribute("viewBox",e.viewBox),s.setAttribute("focusable","false"),s.setAttribute("aria-hidden","true"),e.paint==="stroke"?Object.assign(s.style,{stroke:"currentColor",fill:"none",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}):s.style.fill="currentColor";for(const x of e.paths){const S=n.createElementNS(J,"path");S.setAttribute("d",x),s.appendChild(S)}return s}const _=Object.freeze({text:"text",number:"number",boolean:"boolean",date:"date",dateString:"date",datetime:"datetime",timestamp:"datetime",currency:"currency",usd:"currency",eur:"currency",gbp:"currency",jpy:"currency",percentRate:"percent",ratio:"percent",geometry:"geometry",list:"list"});function i(n){const t=String(n).replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim();return t?t.charAt(0).toUpperCase()+t.slice(1):String(n)}function v(n){return _[n]||"text"}function k(n){return n==null?null:Array.isArray(n)?"list":typeof n=="boolean"?"boolean":typeof n=="number"?"number":n instanceof Date?n.getUTCHours()===0&&n.getUTCMinutes()===0&&n.getUTCSeconds()===0&&n.getUTCMilliseconds()===0?"date":"datetime":z(n)&&typeof n.type=="string"&&Array.isArray(n.coordinates)?"geometry":typeof n=="string"?/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(n)?"datetime":/^\d{4}-\d{2}-\d{2}$/.test(n)?"date":"text":"text"}function r(n){if(!Array.isArray(n))return[];const t=[];for(const e of n){if(typeof e=="string"&&e){t.push({id:e,label:i(e),type:"text",declared:!1});continue}if(!z(e))continue;const s=e.field||e.id;s&&t.push({id:String(s),label:typeof e.title=="string"&&e.title?e.title:i(String(s)),type:v(e.type),format:typeof e.format=="string"?e.format:void 0,declared:!1})}return t}function m(n,t){if(Array.isArray(t)&&t.length)return r(t);const e=Array.isArray(n)?n.slice(0,25):[],s=new Map;for(const S of e)if(z(S))for(const B of Object.keys(S)){if(s.has(B))continue;const Y=k(S[B]);Y&&s.set(B,Y)}const x=e.find(z);if(x)for(const S of Object.keys(x))s.has(S)||s.set(S,"text");return[...s.entries()].map(([S,B])=>({id:S,label:i(S),type:B,declared:!1}))}function c(n,t){if(Array.isArray(t)&&t.length)return r(t);const e=z(n)?Array.isArray(n.schema)?n.schema:Array.isArray(n.columns)?n.columns:null:null;return e?r(e):[]}function b(n,t){const e=t&&l(t.panel)?t.panel(n):null,s=e&&e.grid;return!s||!s.columns||!l(s.columns.all)?[]:r(s.columns.all())}function y(n){if(!z(n))return n;const t={};for(const e of Object.keys(n)){const s=n[e];if(z(s)&&"fields"in s){const{fields:x,...S}=s;t[e]=S}else t[e]=s}return t}function P(n,t){return z(n)?Array.isArray(n.fields)&&n.fields.length?n.fields.filter(z).filter(e=>e.id!=null).map(e=>({id:String(e.id),label:e.label!=null?String(e.label):i(String(e.id)),type:ie.includes(e.type)?e.type:"text",format:typeof e.format=="string"?e.format:void 0,description:typeof e.description=="string"?e.description:void 0,declared:!0})):n.kind==="rows"?m(n.rows,n.columns):n.kind==="pushdown"?c(n.adapter,n.columns):n.kind==="router"?r(n.columns):n.kind==="grid"?b(n.of,t):[]:[]}function u(n,t,e){const s=z(e)&&Array.isArray(e.fields)&&e.fields.length,x=z(e)?e.adapter:null;if(!s&&z(e)&&e.kind==="pushdown"&&n.pushdown&&x&&l(x.describe)){const S=n.pushdown.fields(t);if(S===null)return[];if(S.length)return S}return P(e,n.dashboard)}function E(n){if(typeof n!="string")return null;const t=n.indexOf(".");return t<1||t===n.length-1?null:{source:n.slice(0,t),field:n.slice(t+1)}}function d(n){const t=[];if(!Array.isArray(n))return t;for(const e of n){if(!z(e))continue;const s=E(e.from),x=E(e.to);if(!s||!x){F(`designer:relationship:${JSON.stringify(e.from)}:${JSON.stringify(e.to)}`,`designer: a relationship names "source.field" on both \`from\` and \`to\`; ${JSON.stringify(e.from)} -> ${JSON.stringify(e.to)} was ignored.`);continue}const S=e.type==="one-to-many"||e.type==="one-to-one"?e.type:"many-to-one",B={from:x.source,localKey:s.field,foreignKey:x.field};S==="one-to-many"?(B.many=!0,B.as=typeof e.as=="string"&&e.as?e.as:x.source):e.fields!==void 0&&(B.fields=e.fields),t.push({sourceId:s.source,relatedSourceId:x.source,field:s.field,relatedField:x.field,type:S,join:B})}return t}function w(n,t){const e=new Map,s=(B,Y)=>{e.has(B)||e.set(B,new Set),e.get(B).add(Y)};if(Array.isArray(t))for(const B of t){if(!z(B))continue;const Y=E(B.from),te=E(B.to);!Y||!te||(s(Y.source,te.source),s(te.source,Y.source))}const x=new Set([n]),S=[n];for(;S.length;){const B=S.shift();for(const Y of e.get(B)||[])x.has(Y)||(x.add(Y),S.push(Y))}return x.delete(n),[...x]}function G(n,t){return!!n&&l(n.allowsSource)&&!n.allowsSource(t)}function N(n,t,e){return!!n&&l(n.allowsField)&&!n.allowsField(t,e)}function T(n,t){let e=t,s=2;for(;n.includes(e);)e=`${t}-${s++}`;return e}const C=Object.freeze(["number","currency","percent"]);function h(n,t,e){const s=T(e,`${n}-${t.id}`),x=t.label||t.id;return C.includes(t.type)?{id:s,kind:"kpi",title:x,source:n,options:{tiles:[{id:t.id,label:x,aggregation:"sum",field:t.id,format:t.format}]}}:t.type==="boolean"?{id:s,kind:"kpi",title:x,source:n,options:{tiles:[{id:t.id,label:x,aggregation:"count",field:t.id}]}}:{id:s,kind:"grid",title:x,source:n,options:{columns:[{field:t.id,title:x}]}}}function $(n,{doc:t,t:e}){let s="",x=null,S=null;const B=[],Y=t.createElement("div");Y.className="lattice-designer-datapanel",Y.setAttribute("role","region"),Y.setAttribute("aria-label",e("designer.data.panel"));const te=t.createElement("input");te.type="search",te.className="lattice-designer-datapanel__search",te.setAttribute("aria-label",e("designer.data.search")),te.placeholder=e("designer.data.search");const q=t.createElement("div");q.className="lattice-designer-datapanel__reachable",q.setAttribute("role","status"),q.setAttribute("aria-live","polite");const ne=t.createElement("ul");ne.className="lattice-designer-datapanel__relationships",ne.setAttribute("aria-label",e("designer.data.relationships"));const U=t.createElement("ul");U.className="lattice-designer-datapanel__fields",U.setAttribute("role","listbox"),U.setAttribute("aria-label",e("designer.data.sources"));const M=t.createElement("ul");M.className="lattice-designer-datapanel__derived",M.setAttribute("aria-label",e("designer.data.derived")),Y.appendChild(te),Y.appendChild(q),Y.appendChild(ne),Y.appendChild(U),Y.appendChild(M),(n.rails?n.rails.left.slot("data"):n.chrome).appendChild(Y);const R=()=>{const V=n.guardrails,O=z(n.context.sources)?n.context.sources:{},X=n.getState(),oe=Array.isArray(X.pages)?X.pages.find(we=>z(we)&&we.id===X.selectedPageId):null,ue=oe&&z(oe.spec)&&z(oe.spec.sources)?oe.spec.sources:{},xe={...O,...ue},me=[];for(const we of Object.keys(xe)){if(G(V,we))continue;const Pe=xe[we],Fe=u(n,we,Pe).filter(Z=>!N(V,we,Z.id));me.push({id:we,kind:z(Pe)?Pe.kind:void 0,fields:Fe})}return me},H=()=>{if(!x)return null;const V=n.getState(),O=Array.isArray(V.pages)?V.pages.find(ue=>z(ue)&&ue.id===V.selectedPageId):null,oe=(O&&z(O.spec)&&Array.isArray(O.spec.panels)?O.spec.panels:[]).find(ue=>z(ue)&&ue.id===x);return oe&&typeof oe.source=="string"?oe.source:null},f=(V,O)=>{const X=t.createElement("li");X.className="lattice-designer-datapanel__field",X.setAttribute("role","option"),X.setAttribute("tabindex","0"),X.setAttribute("draggable","true"),X.setAttribute("data-source-id",V),X.setAttribute("data-field-id",O.id),X.appendChild(L(t,O.type));const oe=t.createElement("span");oe.className="lattice-designer-datapanel__field-label",oe.textContent=O.label,X.appendChild(oe);const ue=[e(`designer.data.type.${O.type}`)];if(O.description&&ue.push(O.description),X.setAttribute("aria-label",e("designer.data.field.add",{field:O.label})),X.title=ue.join(" — "),O.description){const me=t.createElement("span");me.className="lattice-designer-datapanel__field-desc",me.textContent=O.description,X.appendChild(me)}const xe=()=>n.commands.run("dropField",{sourceId:V,fieldId:O.id});return X.addEventListener("dragstart",me=>{S={sourceId:V,fieldId:O.id};try{me.dataTransfer&&me.dataTransfer.setData("text/plain",`${V}.${O.id}`)}catch{}}),X.addEventListener("dragend",()=>{S=null}),X.addEventListener("keydown",me=>{(me.key==="Enter"||me.key===" "||me.key==="Spacebar")&&(me.preventDefault(),xe())}),X},g=V=>{const O=n.getState(),X=Array.isArray(O.pages)?O.pages.find(xe=>z(xe)&&xe.id===O.selectedPageId):null,oe=X&&z(X.spec)&&Array.isArray(X.spec.panels)?X.spec.panels:[],ue=oe.find(xe=>z(xe)&&xe.id===V)||oe.find(xe=>z(xe)&&xe.source===V);ue&&l(n.selectWidget)&&n.selectWidget(ue.id)},I=()=>{const V=R(),O=s.trim().toLowerCase();U.textContent="";let X=0;for(const me of V){const we=O?me.fields.filter(Z=>`${me.id} ${Z.id} ${Z.label} ${Z.description||""}`.toLowerCase().includes(O)):me.fields;if(!we.length)continue;const Pe=t.createElement("li");Pe.className="lattice-designer-datapanel__source";const Fe=t.createElement("div");Fe.className="lattice-designer-datapanel__source-title",Fe.textContent=me.id,Pe.appendChild(Fe);for(const Z of ie){const re=we.filter(he=>he.type===Z);if(!re.length)continue;const le=t.createElement("div");le.className="lattice-designer-datapanel__type-group",le.setAttribute("role","group"),le.setAttribute("aria-label",e(`designer.data.type.${Z}`));const pe=t.createElement("div");pe.className="lattice-designer-datapanel__type-label",pe.textContent=e(`designer.data.type.${Z}`),le.appendChild(pe);for(const he of re)le.appendChild(f(me.id,he)),X+=1;Pe.appendChild(le)}U.appendChild(Pe)}if(!X){const me=t.createElement("li");me.className="lattice-designer-datapanel__empty",me.textContent=e("designer.data.empty",{query:JSON.stringify(s)}),U.appendChild(me)}M.textContent="";const oe=n.derived;if(oe&&l(oe.steps)&&l(oe.refusals)&&l(oe.provenance)){const me=n.getState(),we=Array.isArray(me.pages)?me.pages.find(Z=>z(Z)&&Z.id===me.selectedPageId):null,Pe=we&&z(we.spec)&&Array.isArray(we.spec.panels)?we.spec.panels:[],Fe=z(me.panels)?Object.keys(me.panels).filter(Z=>z(me.panels[Z])&&z(me.panels[Z].derived)):[];for(const Z of Fe){const re=me.panels[Z].derived,le=Pe.find(ee=>z(ee)&&ee.id===Z),pe=le&&le.title!=null?String(le.title):Z,he=t.createElement("li");he.className="lattice-designer-datapanel__derived-grid",he.setAttribute("data-derived-id",Z);const Me=t.createElement("div");if(Me.className="lattice-designer-datapanel__derived-title",Me.textContent=pe,he.appendChild(Me),re.hidden){const ee=t.createElement("span");ee.className="lattice-designer-datapanel__derived-hidden",ee.textContent=e("designer.data.derived.hidden"),Me.appendChild(ee);const ye=t.createElement("button");ye.type="button",ye.className="lattice-designer-datapanel__derived-show",ye.textContent=e("designer.data.derived.show"),ye.addEventListener("click",()=>n.commands.run("setDerivedHidden",Z,!1)),Me.appendChild(ye)}const Ie=t.createElement("div");Ie.className="lattice-designer-datapanel__derived-lineage";const Ke=t.createElement("span");Ke.textContent=`${pe} ${e("designer.data.derived.lineage")} `,Ie.appendChild(Ke);const qe=[{id:re.from,label:re.fromLabel||re.from}],ot=z(re.lineage)&&Array.isArray(re.lineage.related)?re.lineage.related:[];for(const ee of ot)qe.push({id:ee,label:ee});qe.forEach((ee,ye)=>{ye&&Ie.appendChild(t.createTextNode(" + "));const ve=t.createElement("button");ve.type="button",ve.className="lattice-designer-datapanel__derived-parent",ve.setAttribute("data-parent-id",ee.id),ve.textContent=ee.label,ve.addEventListener("click",()=>g(ee.id)),Ie.appendChild(ve)}),he.appendChild(Ie);const it=oe.steps(Z)||[],ge=oe.refusals(Z)||[],Le=new Map(ge.map(ee=>[ee.index,ee])),He=ge.find(ee=>ee.index===-1),Ze=oe.provenance(Z).engine;if(He){const ee=t.createElement("div");ee.className="lattice-designer-datapanel__derived-from-refused",ee.setAttribute("data-refused",He.name),ee.textContent=He.reason,he.appendChild(ee)}const ae=t.createElement("ol");ae.className="lattice-designer-datapanel__derived-steps",it.forEach((ee,ye)=>{const ve=t.createElement("li");ve.className="lattice-designer-datapanel__derived-step",ve.setAttribute("data-step-kind",ee.kind),ve.textContent=e(`designer.derived.step.${ee.kind}`);const be=Le.get(ye);if(be){ve.setAttribute("data-refused",be.name);const Ee=t.createElement("span");Ee.className="lattice-designer-datapanel__derived-step-refused",Ee.textContent=` — ${be.name==="join"?be.reason:e("designer.derived.step.refused",{step:be.name,engine:Ze||"engine"})}`,ve.appendChild(Ee)}ae.appendChild(ve)}),he.appendChild(ae),M.appendChild(he)}}ne.textContent="";const ue=d(n.context.relationships);for(const me of ue){const we=t.createElement("li");we.textContent=`${me.sourceId}.${me.field} → ${me.relatedSourceId}.${me.relatedField} (${me.type})`,ne.appendChild(we)}const xe=H();if(!xe)q.textContent="";else{const me=w(xe,n.context.relationships);q.textContent=me.length?e("designer.data.reachable",{source:xe,sources:me.join(", ")}):e("designer.data.noReachable",{source:xe})}};n.commands.register("dropField",(V,{sourceId:O,fieldId:X}={})=>{const oe=V.getState(),ue=Array.isArray(oe.pages)?oe.pages.find(Pe=>z(Pe)&&Pe.id===oe.selectedPageId):null;if(!ue)return!1;const xe=R().find(Pe=>Pe.id===O),me=xe&&xe.fields.find(Pe=>Pe.id===X);if(!me)return F(`designer:drop-field:${O}:${X}`,`designer: there is no visible field ${JSON.stringify(X)} on source ${JSON.stringify(O)}; nothing was added.`),!1;z(ue.spec)||(ue.spec={panels:[]}),Array.isArray(ue.spec.panels)||(ue.spec.panels=[]);const we=ue.spec.panels.filter(z).map(Pe=>Pe.id);return ue.spec.panels.push(h(O,me,we)),V.commit(oe,"dropField")});const j=V=>{S&&V.preventDefault()},A=V=>{S&&(V.preventDefault(),n.commands.run("dropField",S))};n.canvas.addEventListener("dragover",j),n.canvas.addEventListener("drop",A);const D=V=>{const O=l(V.target.closest)?V.target.closest("[data-window-id]"):null;x=O?O.getAttribute("data-window-id"):null,I()};n.canvas.addEventListener("click",D);const p=n.on("state",I),se=n.pushdown?n.pushdown.onChange(I):()=>{};return te.addEventListener("input",()=>{s=te.value,I()}),I(),{get el(){return Y},sources(){return R()},reachable(V){return w(V,n.context.relationships)},compiledRelationships(){return d(n.context.relationships)},setQuery(V){te.value=String(V||""),s=te.value,I()},selectSource(V){x=V||null,I()},registerRoleTarget(V,O){const X=xe=>{S&&xe.preventDefault()},oe=xe=>{if(!S)return;xe.preventDefault(),xe.stopPropagation();const me=S;l(O)&&O(me)};V.addEventListener("dragover",X),V.addEventListener("drop",oe);const ue=()=>{V.removeEventListener("dragover",X),V.removeEventListener("drop",oe)};return B.push(ue),ue},destroy(){p(),se(),B.splice(0).forEach(V=>V()),n.canvas.removeEventListener("dragover",j),n.canvas.removeEventListener("drop",A),n.canvas.removeEventListener("click",D),Y.remove()}}}const a=$}),rt("packages/modules/designer/theme.js",function(o,ce){"use strict";Object.defineProperty(o,"scopeChrome",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"chromeCss",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"injectChromeStyles",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"createTheme",{enumerable:!0,get:function(){return v}});const F=ce("packages/core/src/internal/util.js").warnOnce,de=ce("packages/modules/designer/rails.js").railsCss,fe=ce("packages/modules/designer/palette.js").paletteCss,Q=ce("packages/modules/designer/properties.js").propertiesCss,W=ce("packages/modules/designer/data-panel.js").dataPanelCss;function L(k){return k.replace(/(^|[{}])([^{}@]+)\{/g,(r,m,c)=>{const b=c.split(",").map(y=>{const P=y.match(/^\s*/)[0],u=y.slice(P.length);return/^\.lattice-designer-/.test(u)?`${P}.lattice-designer ${u}`:y}).join(",");return`${m}${b}{`})}const _=()=>`
|
|
203
|
+
.lattice-designer [hidden]{display:none !important}
|
|
204
|
+
.lattice-designer,.lattice-designer *{box-sizing:border-box}
|
|
205
|
+
.lattice-designer{font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);
|
|
206
|
+
background:var(--lattice-designer-page-bg)}
|
|
207
|
+
.lattice-designer :is(h1,h2,h3,h4,h5,h6){margin:0;font:var(--lattice-designer-font-heading) var(--lattice-font-family);
|
|
208
|
+
font-weight:var(--lattice-header-font-weight,600);color:var(--lattice-foreground)}
|
|
209
|
+
.lattice-designer ul,.lattice-designer ol{margin:0;padding:0;list-style:none}
|
|
210
|
+
.lattice-designer input,.lattice-designer select,.lattice-designer textarea{font:var(--lattice-designer-font-body) var(--lattice-font-family);margin:0}
|
|
211
|
+
.lattice-designer-toolbar{display:flex;flex-wrap:nowrap;flex:0 0 auto;align-items:center;gap:var(--lattice-designer-space-2)}
|
|
212
|
+
.lattice-designer .lattice-designer-button{font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);background:var(--lattice-background);
|
|
117
213
|
border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius,4px);
|
|
118
|
-
padding:var(--lattice-space
|
|
214
|
+
padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);min-height:24px;cursor:pointer;margin:0;box-sizing:border-box;
|
|
119
215
|
flex:0 0 auto;white-space:nowrap;max-width:16em;overflow:hidden;text-overflow:ellipsis;
|
|
120
216
|
transition:background-color var(--lattice-motion-duration,120ms) var(--lattice-motion-easing,ease)}
|
|
121
|
-
.lattice-designer-button:hover{background:var(--lattice-hovered-background)}
|
|
122
|
-
.lattice-designer-button--primary{background:var(--lattice-selected-background);color:var(--lattice-selected-foreground);
|
|
217
|
+
.lattice-designer .lattice-designer-button:hover{background:var(--lattice-hovered-background)}
|
|
218
|
+
.lattice-designer .lattice-designer-button--primary{background:var(--lattice-selected-background);color:var(--lattice-selected-foreground);
|
|
123
219
|
border:2px solid var(--lattice-accent)}
|
|
124
|
-
.lattice-designer-button--primary:hover{background:var(--lattice-selected-background);color:var(--lattice-selected-foreground)}
|
|
125
|
-
.lattice-designer-tabs{display:flex;flex-wrap:nowrap;gap:var(--lattice-space
|
|
126
|
-
.lattice-designer-
|
|
127
|
-
|
|
220
|
+
.lattice-designer .lattice-designer-button--primary:hover{background:var(--lattice-selected-background);color:var(--lattice-selected-foreground)}
|
|
221
|
+
.lattice-designer-tabs{display:flex;flex-wrap:nowrap;gap:var(--lattice-designer-space-1);overflow-x:auto;min-width:0}
|
|
222
|
+
.lattice-designer-page-actions{display:inline-flex;align-items:center;gap:var(--lattice-designer-space-1)}
|
|
223
|
+
.lattice-designer .lattice-designer-tab{font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground-muted);background:transparent;border:0;margin:0;
|
|
224
|
+
border-bottom:2px solid transparent;padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);
|
|
128
225
|
min-height:24px;cursor:pointer;flex:0 0 auto;white-space:nowrap;max-width:16em;overflow:hidden;text-overflow:ellipsis}
|
|
129
|
-
.lattice-designer-tab:hover{background:var(--lattice-hovered-background);color:var(--lattice-foreground)}
|
|
130
|
-
.lattice-designer-tab[aria-selected="true"]{color:var(--lattice-foreground);border-bottom-color:var(--lattice-accent);
|
|
226
|
+
.lattice-designer .lattice-designer-tab:hover{background:var(--lattice-hovered-background);color:var(--lattice-foreground)}
|
|
227
|
+
.lattice-designer .lattice-designer-tab[aria-selected="true"]{color:var(--lattice-foreground);border-bottom-color:var(--lattice-accent);
|
|
131
228
|
font-weight:var(--lattice-header-font-weight,600)}
|
|
132
229
|
.lattice-designer-button:focus-visible,.lattice-designer-tab:focus-visible,.lattice-designer-canvas:focus-visible{
|
|
133
230
|
outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:2px;
|
|
@@ -138,34 +235,51 @@ ${i}`,messages:[{role:"system",content:fe},{role:"user",content:i}],schema:y};re
|
|
|
138
235
|
padding:calc(var(--lattice-space,4px) * 4);background:var(--lattice-background);color:var(--lattice-foreground);
|
|
139
236
|
border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);border-radius:var(--lattice-radius,4px);
|
|
140
237
|
box-shadow:var(--lattice-popup-shadow)}
|
|
141
|
-
.lattice-designer-dialog h2{margin:0 0 var(--lattice-space,4px);font
|
|
238
|
+
.lattice-designer-dialog h2{margin:0 0 var(--lattice-space,4px);font:var(--lattice-designer-font-title) var(--lattice-font-family);font-weight:var(--lattice-header-font-weight,600)}
|
|
142
239
|
.lattice-designer-dialog dl{margin:0 0 calc(var(--lattice-space,4px) * 3)}
|
|
143
240
|
.lattice-designer-dialog dt{font-family:var(--lattice-font-mono);font-weight:var(--lattice-header-font-weight,600);margin-top:var(--lattice-space,4px)}
|
|
144
241
|
.lattice-designer-dialog dd{margin:0;color:var(--lattice-foreground-muted)}
|
|
145
242
|
@media (prefers-reduced-motion:reduce){
|
|
146
243
|
.lattice-designer-button,.lattice-designer-tab{transition:none}
|
|
147
244
|
}
|
|
148
|
-
${
|
|
149
|
-
${fe()}`;function X(B){const L=B.ownerDocument.createElement("style");L.setAttribute("data-designer-styles",""),L.textContent=J(),B.insertBefore(L,B.firstChild)}function ne(B,L,D,o){const w=i=>i==null||i===""?(B.removeAttribute("data-theme"),!0):typeof i!="string"?(F("designer:theme",`designer theme: ${JSON.stringify(i)} is not a theme name such as 'light', 'dark', 'auto' or 'high-contrast'; the theme was kept.`),!1):(B.setAttribute("data-theme",i),!0);w(L);const y=()=>B.getAttribute("data-theme")||null;return{get:y,set(i){const h=y();return w(i)&&y()!==h&&D(o("a11y.designer.theme",{theme:y()||"auto"})),y()}}}}),rt("packages/modules/designer/toolbar.js",function(s,ae){"use strict";Object.defineProperty(s,"installChrome",{enumerable:!0,get:function(){return o}});const F=ae("packages/modules/dashboard/spec.js").isPlain,ue=ae("packages/core/src/internal/util.js").warnOnce,z=ae("packages/modules/designer/a11y.js"),fe=z.createA11y,J=z.auditChrome,X=ae("packages/modules/designer/theme.js"),ne=X.injectChromeStyles,B=X.createTheme,L=Object.freeze({chart:"designer.kind.chart",grid:"designer.kind.grid",html:"designer.kind.html",kpi:"designer.kind.kpi",map:"designer.kind.map"});function D(w,y,i,h){const c=m=>{const b=y(),P=b.includes(m)?m:b.find(u=>u.getAttribute("tabindex")==="0")||b[0];for(const u of b)u.setAttribute("tabindex",u===P?"0":"-1")};return w.addEventListener("focusin",m=>{y().includes(m.target)&&c(m.target)}),w.addEventListener("keydown",m=>{const b=y(),P=b.indexOf(m.target);if(P<0||m.altKey)return;let u=-1;m.key===i[1]?u=(P+1)%b.length:m.key===i[0]?u=(P-1+b.length)%b.length:m.key==="Home"?u=0:m.key==="End"&&(u=b.length-1),!(u<0)&&(m.preventDefault(),c(b[u]),b[u].focus(),h&&h(b[u]))}),()=>c(void 0)}function o(w){const{root:y,chrome:i,canvas:h,t:c,commands:m,emitter:b,sources:P}=w,u=w.topbar||i,A=y.ownerDocument;ne(y);const r=fe({root:y,live:w.live,t:c}),j=B(y,w.theme,r.announce,c),C=()=>w.designer(),G=(S,Y,Z)=>{const x=A.createElement("button");return x.type="button",x.className=`lattice-designer-button${Z?` ${Z}`:""}`,x.textContent=S,x.addEventListener("click",Y),x};m.register("addPanel",(S,Y)=>{const Z=F(Y)?Y:{},x=S.getState(),ee=x.pages.find(pe=>F(pe)&&pe.id===x.selectedPageId);if(!ee||!F(ee.spec))return ue("designer:addPanel","designer addPanel: there is no page with a spec to add to; nothing was added."),null;const se=typeof Z.kind=="string"&&Z.kind?Z.kind:"html",de=c(L[se]||"designer.kind.widget");Array.isArray(ee.spec.panels)||(ee.spec.panels=[]);const ye=ee.spec.panels,xe=new Set(ye.filter(F).map(pe=>pe.id));let me=ye.filter(pe=>F(pe)&&pe.kind===se).length+1;for(;xe.has(`${se}-${me}`);)me+=1;const Ne=typeof Z.id=="string"&&Z.id&&!xe.has(Z.id)?Z.id:`${se}-${me}`,Ae=typeof Z.title=="string"&&Z.title?Z.title:`${de} ${me}`,{placement:te,...re}=Z,le={...re,id:Ne,kind:se,title:Ae};return se==="html"&&le.options===void 0&&(le.options={text:""}),ye.push(le),F(te)&&(F(ee.spec.layout)||(ee.spec.layout={}),Array.isArray(ee.spec.layout.windows)||(ee.spec.layout.windows=[]),ee.spec.layout.windows.push({id:Ne,...te})),S.commit(x,"addPanel")?(r.announce(c("a11y.designer.added",{kind:de,title:Ae})),Ne):null});const _=()=>{const S=Object.keys(P)[0];return S?m.run("addPanel",{kind:"grid",source:S}):(r.announce(c("a11y.designer.noSource")),null)},T=()=>C().setMode(C().mode==="edit"?"view":"edit"),{shortcuts:p}=r;p.register({id:"mode",keys:"Alt+Shift+M",description:c("designer.shortcut.toggleMode"),run:T}),p.register({id:"addNote",keys:"Alt+Shift+N",description:c("designer.shortcut.addNote"),run:()=>m.run("addPanel",{kind:"html"})}),p.register({id:"addGrid",keys:"Alt+Shift+G",description:c("designer.shortcut.addGrid"),run:_}),p.register({id:"layout.move",keys:"Space, arrows, Escape",description:c("designer.shortcut.moveWidget")}),p.register({id:"layout.resize",keys:"Space, arrows, Escape (resize handle)",description:c("designer.shortcut.resizeWidget")});const v=A.createElement("div");v.className="lattice-designer-toolbar",v.setAttribute("role","toolbar"),v.setAttribute("aria-label",c("designer.toolbar"));const n=G("",T,"lattice-designer-button--primary"),t=[n,G(c("designer.addNote"),()=>m.run("addPanel",{kind:"html"})),G(c("designer.addGrid"),_),G(c("designer.shortcuts.help"),r.showShortcuts)];for(const S of t)v.appendChild(S);const a=D(v,()=>t,["ArrowLeft","ArrowRight"]),e=A.createElement("div");e.className="lattice-designer-tabs",e.setAttribute("role","tablist"),e.setAttribute("aria-label",c("designer.pages"));let f=[],d="";const E=D(e,()=>f,["ArrowLeft","ArrowRight"],S=>C().selectPage(S.getAttribute("data-page-id")));let M=null,W=null,oe=0,q=null;const Q=A.createElement("div");Q.className="lattice-designer-page-actions";const H=G(c("designer.page.add"),()=>m.run("addPage",{})),O=G(c("designer.page.duplicate"),()=>{const S=C().getProperty("selectedPageId");S!==null&&m.run("addPage",{duplicate:S})});Q.appendChild(H),Q.appendChild(O);const I=S=>{const Z=C().getState().pages.find(x=>F(x)&&x.id===S);return!Z||!F(Z.spec)||!Array.isArray(Z.spec.panels)?0:Z.spec.panels.filter(F).length},K=()=>{if(!W)return;W.scrim.remove(),W=null;const S=f.find(Y=>Y.getAttribute("tabindex")==="0")||f[0];S&&S.isConnected&&S.focus()},g=S=>{W&&K();const Z=C().getState().pages.find(re=>F(re)&&re.id===S),x=Z&&Z.title!=null?String(Z.title):String(S),ee=I(S),se=()=>{m.run("removePage",S),K()};if(ee===0){se();return}const de=A.createElement("div");de.className="lattice-designer-scrim";const ye=A.createElement("div");ye.className="lattice-designer-dialog",ye.setAttribute("role","dialog"),ye.setAttribute("aria-modal","true"),oe+=1;const xe=`lattice-designer-page-confirm-${oe}`;ye.setAttribute("aria-labelledby",xe);const me=A.createElement("h2");me.id=xe,me.textContent=c("designer.page.confirm",{title:x});const Ne=A.createElement("p");Ne.textContent=c("designer.page.hasWidgets",{n:ee});const Ae=G(c("designer.page.cancel"),K),te=G(c("designer.page.delete"),se,"lattice-designer-button--primary");ye.appendChild(me),ye.appendChild(Ne),ye.appendChild(Ae),ye.appendChild(te),ye.addEventListener("keydown",re=>{re.key==="Escape"&&(re.preventDefault(),re.stopPropagation(),K())}),de.appendChild(ye),h.appendChild(de),W={scrim:de},te.focus()},k=(S,Y)=>{if(M)return;const Z=S.textContent;M={id:Y,tab:S};const x=A.createElement("input");x.type="text",x.className="lattice-designer-tab-rename",x.value=Z,x.setAttribute("aria-label",c("designer.page.rename")),S.textContent="",S.appendChild(x),x.focus(),typeof x.select=="function"&&x.select();let ee=!1;const se=de=>{if(ee)return;ee=!0;const ye=x.value.trim();x.remove(),M=null,de&&ye!==""&&ye!==Z&&m.run("renamePage",Y,ye),S.isConnected&&!de&&(S.textContent=Z),V(),(f.find(me=>me.getAttribute("data-page-id")===String(Y))||S).focus()};x.addEventListener("keydown",de=>{de.stopPropagation(),de.key==="Enter"?(de.preventDefault(),se(!0)):de.key==="Escape"&&(de.preventDefault(),se(!1))}),x.addEventListener("blur",()=>se(!0))};e.addEventListener("keydown",S=>{if(!S.target||!S.target.closest)return;const Y=S.target.closest("[data-page-id]");if(!Y||C().mode!=="edit")return;const Z=Y.getAttribute("data-page-id");S.altKey&&(S.key==="ArrowLeft"||S.key==="ArrowRight")?(S.preventDefault(),m.run("movePage",Z,S.key==="ArrowRight"?1:-1)):S.key==="F2"?(S.preventDefault(),k(Y,Z)):S.key==="Delete"&&(S.preventDefault(),g(Z))}),e.addEventListener("dragstart",S=>{if(C().mode!=="edit")return;const Y=S.target&&S.target.closest?S.target.closest("[data-page-id]"):null;Y&&(q=Y.getAttribute("data-page-id"),S.dataTransfer&&(S.dataTransfer.effectAllowed="move",S.dataTransfer.setData&&S.dataTransfer.setData("text/plain",q)))}),e.addEventListener("dragover",S=>{q!==null&&(S.preventDefault&&S.preventDefault(),S.dataTransfer&&(S.dataTransfer.dropEffect="move"))}),e.addEventListener("drop",S=>{if(q===null)return;const Y=q;q=null,S.preventDefault&&S.preventDefault();const Z=S.target&&S.target.closest?S.target.closest("[data-page-id]"):null;if(!Z)return;const x=C().pages().map(de=>String(de.id)),ee=x.indexOf(Y),se=x.indexOf(Z.getAttribute("data-page-id"));ee<0||se<0||ee===se||m.run("movePage",Y,se-ee)}),e.addEventListener("dragend",()=>{q=null});const V=()=>{const S=C().pages(),Y=C().getProperty("selectedPageId"),Z=JSON.stringify(S.map(x=>[x.id,x.title]));if(Z!==d){const x=f.includes(A.activeElement)?A.activeElement.getAttribute("data-page-id"):null;if(e.textContent="",f=S.map(ee=>{const se=A.createElement("button");return se.type="button",se.className="lattice-designer-tab",se.setAttribute("role","tab"),se.setAttribute("data-page-id",String(ee.id)),se.textContent=typeof ee.title=="string"?ee.title:String(ee.id),se.addEventListener("click",()=>C().selectPage(ee.id)),e.appendChild(se),se}),d=Z,x!==null){const ee=f.find(se=>se.getAttribute("data-page-id")===x);ee&&ee.focus()}}for(const x of f){const ee=x.getAttribute("data-page-id")===String(Y);x.setAttribute("aria-selected",ee?"true":"false"),x.setAttribute("tabindex",ee?"0":"-1")}!f.some(x=>x.getAttribute("tabindex")==="0")&&f[0]&&f[0].setAttribute("tabindex","0"),E()},R=()=>{const S=C().mode==="edit";n.textContent=c(S?"designer.mode.toView":"designer.mode.toEdit"),S?Q.removeAttribute("hidden"):Q.setAttribute("hidden","")};u.appendChild(v),u.appendChild(e),u.appendChild(Q),h.setAttribute("tabindex","-1"),r.regions.register("toolbar",i,{label:c("designer.region.toolbar")}),r.regions.register("canvas",h,{label:c("designer.region.canvas")}),a();const N=b.on("state",({cause:S})=>{if(V(),S==="selectPage"){const Y=C().pages().find(Z=>Z.id===C().getProperty("selectedPageId"));Y&&r.announce(c("a11y.designer.page",{title:Y.title}))}}),$=b.on("mode",R);return{announce:r.announce,shortcuts:p,audit:()=>J(y),regions:r.regions,theme:j,start(){V(),R()},destroy(){N(),$(),r.destroy()}}}}),rt("packages/modules/designer/migrate.js",function(s,ae){"use strict";Object.defineProperty(s,"SCHEMA_VERSION",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"v0Fixture",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"migrations",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"migrateState",{enumerable:!0,get:function(){return ne}});const F=ae("packages/modules/dashboard/spec.js").isPlain,l=1;function ue(B){if(Array.isArray(B))return B.map(ue);if(!F(B))return B;const L={};for(const D of Object.keys(B))L[D]=ue(B[D]);return L}const z=B=>`Page ${B}`,fe=B=>(L,D)=>B?B(L,D):L==="designer.page"&&D&&typeof D.n=="number"?z(D.n):L,J=Object.freeze({layout:{columns:2,rows:1},panels:[{id:"table",kind:"grid",title:"Orders",source:"sales"},{id:"note",kind:"html",title:"Note",options:{text:"Provisional figures.",custom:"kept"}}]}),X=Object.freeze([Object.freeze({version:1,fixture:J,describe:"a plain dashboard spec (no pages) is wrapped into a one-page state, and schemaVersion is stamped",migrate(B,L){if(Array.isArray(B.pages))return{...B,schemaVersion:l};const D={...B};return delete D.schemaVersion,{schemaVersion:l,pages:[{id:"page-1",title:L("designer.page",{n:1}),spec:D}],selectedPageId:"page-1",panels:{}}}})]);function ne(B,L){const D=fe(L),o=F(B)?ue(B):{},w=typeof o.schemaVersion=="number"&&Number.isFinite(o.schemaVersion)?o.schemaVersion:0;if(w>l)return{ok:!1,reason:"newer",schemaVersion:l,from:w,to:l,applied:!1,changes:[],state:null};let y=o;const i=[];for(const h of X)h.version<=w||(y=h.migrate(y,D),i.push(h.describe));return{ok:!0,reason:null,schemaVersion:l,from:w,to:l,applied:i.length>0,changes:i,state:y}}}),rt("packages/modules/designer/undo.js",function(s,ae){"use strict";Object.defineProperty(s,"DEFAULT_DEPTH",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(s,"createHistory",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"installUndo",{enumerable:!0,get:function(){return X}});const ve=100;function F(ne){return ne&&Number.isInteger(ne.historyDepth)&&ne.historyDepth>0?ne.historyDepth:ve}function l(ne={}){const B=F(ne);let L=[],D=[];return Object.freeze({record(o,w,y,i){i!==void 0&&L.length&&L[L.length-1].coalesce===i?L[L.length-1]={...L[L.length-1],after:w,cause:y}:(L.push({before:o,after:w,cause:y,coalesce:i}),L.length>B&&L.shift()),D.length=0},undo(){const o=L.pop();return o?(D.push(o),o.before):null},redo(){const o=D.pop();return o?(L.push(o),o.after):null},canUndo(){return L.length>0},canRedo(){return D.length>0},clear(){L=[],D=[]},get depth(){return L.length},get max(){return B}})}const ue="lattice-designer-styles";function z(ne){if(!ne||ne.getElementById&&ne.getElementById(ue))return;const B=ne.createElement("style");B.id=ue,B.textContent=`
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
245
|
+
${de()}
|
|
246
|
+
${fe()}
|
|
247
|
+
${Q()}
|
|
248
|
+
${W()}
|
|
249
|
+
.lattice-designer-properties .lattice-designer-role-controls>*{flex:1 1 9em;min-width:9em}
|
|
250
|
+
.lattice-designer-filterbar{display:flex;flex-wrap:wrap;align-items:center;gap:var(--lattice-designer-space-2);
|
|
251
|
+
padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);margin:var(--lattice-designer-space-1) 0;
|
|
252
|
+
background:var(--lattice-designer-panel-bg);border:var(--lattice-border-width,1px) solid var(--lattice-designer-panel-border);
|
|
253
|
+
border-radius:var(--lattice-radius,4px)}
|
|
254
|
+
.lattice-designer-filterbar-controls:empty,.lattice-designer-filterbar-context:empty{display:none}
|
|
255
|
+
.lattice-designer-filterbar-controls,.lattice-designer-filter-add{display:flex;flex-wrap:wrap;align-items:center;gap:var(--lattice-designer-space-2)}
|
|
256
|
+
.lattice-designer-filterbar select{font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);
|
|
257
|
+
background:var(--lattice-background);border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);
|
|
258
|
+
border-radius:var(--lattice-radius,4px);padding:var(--lattice-designer-space-1) var(--lattice-designer-space-2);min-height:28px;max-width:14em}
|
|
259
|
+
.lattice-designer-filterbar button{font:var(--lattice-designer-font-body) var(--lattice-font-family);color:var(--lattice-foreground);
|
|
260
|
+
background:var(--lattice-background);border:var(--lattice-border-width,1px) solid var(--lattice-border-strong);
|
|
261
|
+
border-radius:var(--lattice-radius,4px);padding:var(--lattice-designer-space-1) var(--lattice-designer-space-3);min-height:28px;cursor:pointer}
|
|
262
|
+
.lattice-designer-filterbar button:hover{background:var(--lattice-hovered-background)}
|
|
263
|
+
`;function i(k){const r=k.ownerDocument.createElement("style");r.setAttribute("data-designer-styles",""),r.textContent=L(_()),k.insertBefore(r,k.firstChild)}function v(k,r,m,c){const b=P=>P==null||P===""?(k.removeAttribute("data-theme"),!0):typeof P!="string"?(F("designer:theme",`designer theme: ${JSON.stringify(P)} is not a theme name such as 'light', 'dark', 'auto' or 'high-contrast'; the theme was kept.`),!1):(k.setAttribute("data-theme",P),!0);b(r);const y=()=>k.getAttribute("data-theme")||null;return{get:y,set(P){const u=y();return b(P)&&y()!==u&&m(c("a11y.designer.theme",{theme:y()||"auto"})),y()}}}}),rt("packages/modules/designer/toolbar.js",function(o,ce){"use strict";Object.defineProperty(o,"installChrome",{enumerable:!0,get:function(){return i}});const F=ce("packages/modules/dashboard/spec.js").isPlain,de=ce("packages/core/src/internal/util.js").warnOnce,z=ce("packages/modules/designer/a11y.js"),fe=z.createA11y,J=z.auditChrome,Q=ce("packages/modules/designer/theme.js"),ie=Q.injectChromeStyles,W=Q.createTheme,L=Object.freeze({chart:"designer.kind.chart",grid:"designer.kind.grid",html:"designer.kind.html",kpi:"designer.kind.kpi",map:"designer.kind.map"});function _(v,k,r,m){const c=b=>{const y=k(),P=y.includes(b)?b:y.find(u=>u.getAttribute("tabindex")==="0")||y[0];for(const u of y)u.setAttribute("tabindex",u===P?"0":"-1")};return v.addEventListener("focusin",b=>{k().includes(b.target)&&c(b.target)}),v.addEventListener("keydown",b=>{const y=k(),P=y.indexOf(b.target);if(P<0||b.altKey)return;let u=-1;b.key===r[1]?u=(P+1)%y.length:b.key===r[0]?u=(P-1+y.length)%y.length:b.key==="Home"?u=0:b.key==="End"&&(u=y.length-1),!(u<0)&&(b.preventDefault(),c(y[u]),y[u].focus(),m&&m(y[u]))}),()=>c(void 0)}function i(v){const{root:k,chrome:r,canvas:m,t:c,commands:b,emitter:y,sources:P}=v,u=v.topbar||r,E=k.ownerDocument;ie(k);const d=fe({root:k,live:v.live,t:c}),w=W(k,v.theme,d.announce,c),G=()=>v.designer(),N=(p,se,V)=>{const O=E.createElement("button");return O.type="button",O.className=`lattice-designer-button${V?` ${V}`:""}`,O.textContent=p,O.addEventListener("click",se),O};b.register("addPanel",(p,se)=>{const V=F(se)?se:{},O=p.getState(),X=O.pages.find(pe=>F(pe)&&pe.id===O.selectedPageId);if(!X||!F(X.spec))return de("designer:addPanel","designer addPanel: there is no page with a spec to add to; nothing was added."),null;const oe=typeof V.kind=="string"&&V.kind?V.kind:"html",ue=c(L[oe]||"designer.kind.widget");Array.isArray(X.spec.panels)||(X.spec.panels=[]);const xe=X.spec.panels,me=new Set(xe.filter(F).map(pe=>pe.id));let we=xe.filter(pe=>F(pe)&&pe.kind===oe).length+1;for(;me.has(`${oe}-${we}`);)we+=1;const Pe=typeof V.id=="string"&&V.id&&!me.has(V.id)?V.id:`${oe}-${we}`,Fe=typeof V.title=="string"&&V.title?V.title:`${ue} ${we}`,{placement:Z,...re}=V,le={...re,id:Pe,kind:oe,title:Fe};return oe==="html"&&le.options===void 0&&(le.options={text:""}),xe.push(le),F(Z)&&(F(X.spec.layout)||(X.spec.layout={}),Array.isArray(X.spec.layout.windows)||(X.spec.layout.windows=[]),X.spec.layout.windows.push({id:Pe,...Z})),p.commit(O,"addPanel")?(d.announce(c("a11y.designer.added",{kind:ue,title:Fe})),Pe):null});const T=()=>{const p=Object.keys(P)[0];return p?b.run("addPanel",{kind:"grid",source:p}):(d.announce(c("a11y.designer.noSource")),null)},C=()=>G().setMode(G().mode==="edit"?"view":"edit"),{shortcuts:h}=d;h.register({id:"mode",keys:"Alt+Shift+M",description:c("designer.shortcut.toggleMode"),run:C}),h.register({id:"addNote",keys:"Alt+Shift+N",description:c("designer.shortcut.addNote"),run:()=>b.run("addPanel",{kind:"html"})}),h.register({id:"addGrid",keys:"Alt+Shift+G",description:c("designer.shortcut.addGrid"),run:T}),h.register({id:"layout.move",keys:"Space, arrows, Escape",description:c("designer.shortcut.moveWidget")}),h.register({id:"layout.resize",keys:"Space, arrows, Escape (resize handle)",description:c("designer.shortcut.resizeWidget")});const $=E.createElement("div");$.className="lattice-designer-toolbar",$.setAttribute("role","toolbar"),$.setAttribute("aria-label",c("designer.toolbar"));const a=N("",C,"lattice-designer-button--primary"),n=[a,N(c("designer.addNote"),()=>b.run("addPanel",{kind:"html"})),N(c("designer.addGrid"),T),N(c("designer.shortcuts.help"),d.showShortcuts)];for(const p of n)$.appendChild(p);const t=_($,()=>n,["ArrowLeft","ArrowRight"]),e=E.createElement("div");e.className="lattice-designer-tabs",e.setAttribute("role","tablist"),e.setAttribute("aria-label",c("designer.pages"));let s=[],x="";const S=_(e,()=>s,["ArrowLeft","ArrowRight"],p=>G().selectPage(p.getAttribute("data-page-id")));let B=null,Y=null,te=0,q=null;const ne=E.createElement("div");ne.className="lattice-designer-page-actions";const U=N(c("designer.page.add"),()=>b.run("addPage",{})),M=N(c("designer.page.duplicate"),()=>{const p=G().getProperty("selectedPageId");p!==null&&b.run("addPage",{duplicate:p})});ne.appendChild(U),ne.appendChild(M);const R=p=>{const V=G().getState().pages.find(O=>F(O)&&O.id===p);return!V||!F(V.spec)||!Array.isArray(V.spec.panels)?0:V.spec.panels.filter(F).length},H=()=>{if(!Y)return;Y.scrim.remove(),Y=null;const p=s.find(se=>se.getAttribute("tabindex")==="0")||s[0];p&&p.isConnected&&p.focus()},f=p=>{Y&&H();const V=G().getState().pages.find(re=>F(re)&&re.id===p),O=V&&V.title!=null?String(V.title):String(p),X=R(p),oe=()=>{b.run("removePage",p),H()};if(X===0){oe();return}const ue=E.createElement("div");ue.className="lattice-designer-scrim";const xe=E.createElement("div");xe.className="lattice-designer-dialog",xe.setAttribute("role","dialog"),xe.setAttribute("aria-modal","true"),te+=1;const me=`lattice-designer-page-confirm-${te}`;xe.setAttribute("aria-labelledby",me);const we=E.createElement("h2");we.id=me,we.textContent=c("designer.page.confirm",{title:O});const Pe=E.createElement("p");Pe.textContent=c("designer.page.hasWidgets",{n:X});const Fe=N(c("designer.page.cancel"),H),Z=N(c("designer.page.delete"),oe,"lattice-designer-button--primary");xe.appendChild(we),xe.appendChild(Pe),xe.appendChild(Fe),xe.appendChild(Z),xe.addEventListener("keydown",re=>{re.key==="Escape"&&(re.preventDefault(),re.stopPropagation(),H())}),ue.appendChild(xe),m.appendChild(ue),Y={scrim:ue},Z.focus()},g=(p,se)=>{if(B)return;const V=p.textContent;B={id:se,tab:p};const O=E.createElement("input");O.type="text",O.className="lattice-designer-tab-rename",O.value=V,O.setAttribute("aria-label",c("designer.page.rename")),p.textContent="",p.appendChild(O),O.focus(),typeof O.select=="function"&&O.select();let X=!1;const oe=ue=>{if(X)return;X=!0;const xe=O.value.trim();O.remove(),B=null,ue&&xe!==""&&xe!==V&&b.run("renamePage",se,xe),p.isConnected&&!ue&&(p.textContent=V),I(),(s.find(we=>we.getAttribute("data-page-id")===String(se))||p).focus()};O.addEventListener("keydown",ue=>{ue.stopPropagation(),ue.key==="Enter"?(ue.preventDefault(),oe(!0)):ue.key==="Escape"&&(ue.preventDefault(),oe(!1))}),O.addEventListener("blur",()=>oe(!0))};e.addEventListener("keydown",p=>{if(!p.target||!p.target.closest)return;const se=p.target.closest("[data-page-id]");if(!se||G().mode!=="edit")return;const V=se.getAttribute("data-page-id");p.altKey&&(p.key==="ArrowLeft"||p.key==="ArrowRight")?(p.preventDefault(),b.run("movePage",V,p.key==="ArrowRight"?1:-1)):p.key==="F2"?(p.preventDefault(),g(se,V)):p.key==="Delete"&&(p.preventDefault(),f(V))}),e.addEventListener("dragstart",p=>{if(G().mode!=="edit")return;const se=p.target&&p.target.closest?p.target.closest("[data-page-id]"):null;se&&(q=se.getAttribute("data-page-id"),p.dataTransfer&&(p.dataTransfer.effectAllowed="move",p.dataTransfer.setData&&p.dataTransfer.setData("text/plain",q)))}),e.addEventListener("dragover",p=>{q!==null&&(p.preventDefault&&p.preventDefault(),p.dataTransfer&&(p.dataTransfer.dropEffect="move"))}),e.addEventListener("drop",p=>{if(q===null)return;const se=q;q=null,p.preventDefault&&p.preventDefault();const V=p.target&&p.target.closest?p.target.closest("[data-page-id]"):null;if(!V)return;const O=G().pages().map(ue=>String(ue.id)),X=O.indexOf(se),oe=O.indexOf(V.getAttribute("data-page-id"));X<0||oe<0||X===oe||b.run("movePage",se,oe-X)}),e.addEventListener("dragend",()=>{q=null});const I=()=>{const p=G().pages(),se=G().getProperty("selectedPageId"),V=JSON.stringify(p.map(O=>[O.id,O.title]));if(V!==x){const O=s.includes(E.activeElement)?E.activeElement.getAttribute("data-page-id"):null;if(e.textContent="",s=p.map(X=>{const oe=E.createElement("button");return oe.type="button",oe.className="lattice-designer-tab",oe.setAttribute("role","tab"),oe.setAttribute("data-page-id",String(X.id)),oe.textContent=typeof X.title=="string"?X.title:String(X.id),oe.addEventListener("click",()=>G().selectPage(X.id)),e.appendChild(oe),oe}),x=V,O!==null){const X=s.find(oe=>oe.getAttribute("data-page-id")===O);X&&X.focus()}}for(const O of s){const X=O.getAttribute("data-page-id")===String(se);O.setAttribute("aria-selected",X?"true":"false"),O.setAttribute("tabindex",X?"0":"-1")}!s.some(O=>O.getAttribute("tabindex")==="0")&&s[0]&&s[0].setAttribute("tabindex","0"),S()},j=()=>{const p=G().mode==="edit";a.textContent=c(p?"designer.mode.toView":"designer.mode.toEdit"),p?ne.removeAttribute("hidden"):ne.setAttribute("hidden","")};u.appendChild($),u.appendChild(e),u.appendChild(ne),m.setAttribute("tabindex","-1"),d.regions.register("toolbar",r,{label:c("designer.region.toolbar")}),d.regions.register("canvas",m,{label:c("designer.region.canvas")}),t();const A=y.on("state",({cause:p})=>{if(I(),p==="selectPage"){const se=G().pages().find(V=>V.id===G().getProperty("selectedPageId"));se&&d.announce(c("a11y.designer.page",{title:se.title}))}}),D=y.on("mode",j);return{announce:d.announce,shortcuts:h,audit:()=>J(k),regions:d.regions,theme:w,start(){I(),j()},destroy(){A(),D(),d.destroy()}}}}),rt("packages/modules/designer/migrate.js",function(o,ce){"use strict";Object.defineProperty(o,"SCHEMA_VERSION",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"v0Fixture",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"migrations",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"migrateState",{enumerable:!0,get:function(){return ie}});const F=ce("packages/modules/dashboard/spec.js").isPlain,l=1;function de(W){if(Array.isArray(W))return W.map(de);if(!F(W))return W;const L={};for(const _ of Object.keys(W))L[_]=de(W[_]);return L}const z=W=>`Page ${W}`,fe=W=>(L,_)=>W?W(L,_):L==="designer.page"&&_&&typeof _.n=="number"?z(_.n):L,J=Object.freeze({layout:{columns:2,rows:1},panels:[{id:"table",kind:"grid",title:"Orders",source:"sales"},{id:"note",kind:"html",title:"Note",options:{text:"Provisional figures.",custom:"kept"}}]}),Q=Object.freeze([Object.freeze({version:1,fixture:J,describe:"a plain dashboard spec (no pages) is wrapped into a one-page state, and schemaVersion is stamped",migrate(W,L){if(Array.isArray(W.pages))return{...W,schemaVersion:l};const _={...W};return delete _.schemaVersion,{schemaVersion:l,pages:[{id:"page-1",title:L("designer.page",{n:1}),spec:_}],selectedPageId:"page-1",panels:{}}}})]);function ie(W,L){const _=fe(L),i=F(W)?de(W):{},v=typeof i.schemaVersion=="number"&&Number.isFinite(i.schemaVersion)?i.schemaVersion:0;if(v>l)return{ok:!1,reason:"newer",schemaVersion:l,from:v,to:l,applied:!1,changes:[],state:null};let k=i;const r=[];for(const m of Q)m.version<=v||(k=m.migrate(k,_),r.push(m.describe));return{ok:!0,reason:null,schemaVersion:l,from:v,to:l,applied:r.length>0,changes:r,state:k}}}),rt("packages/modules/designer/undo.js",function(o,ce){"use strict";Object.defineProperty(o,"DEFAULT_DEPTH",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(o,"createHistory",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"installUndo",{enumerable:!0,get:function(){return Q}});const ke=100;function F(ie){return ie&&Number.isInteger(ie.historyDepth)&&ie.historyDepth>0?ie.historyDepth:ke}function l(ie={}){const W=F(ie);let L=[],_=[];return Object.freeze({record(i,v,k,r){r!==void 0&&L.length&&L[L.length-1].coalesce===r?L[L.length-1]={...L[L.length-1],after:v,cause:k}:(L.push({before:i,after:v,cause:k,coalesce:r}),L.length>W&&L.shift()),_.length=0},undo(){const i=L.pop();return i?(_.push(i),i.before):null},redo(){const i=_.pop();return i?(L.push(i),i.after):null},canUndo(){return L.length>0},canRedo(){return _.length>0},clear(){L=[],_=[]},get depth(){return L.length},get max(){return W}})}const de="lattice-designer-styles";function z(ie){if(!ie||ie.getElementById&&ie.getElementById(de))return;const W=ie.createElement("style");W.id=de,W.textContent=`
|
|
264
|
+
.lattice-designer-tools{display:flex;align-items:center;gap:var(--lattice-designer-space-1,4px)}
|
|
265
|
+
.lattice-designer .lattice-designer-tool{appearance:none;font:var(--lattice-designer-font-body,13px/18px) var(--lattice-font-family);
|
|
266
|
+
color:var(--lattice-foreground,#1a1a1a);margin:0;box-sizing:border-box;
|
|
153
267
|
background:var(--lattice-background,#fff);border:1px solid var(--lattice-border-color,#d7dbe0);
|
|
154
|
-
border-radius:var(--lattice-radius,4px);padding:
|
|
155
|
-
.lattice-designer-tool:hover:not(:disabled){background:var(--lattice-hovered-background,#f2f5f8)}
|
|
156
|
-
.lattice-designer-tool:focus-visible{outline:var(--lattice-focus-width,2px) solid var(--lattice-focus-color,#1a6bc7);
|
|
268
|
+
border-radius:var(--lattice-radius,4px);padding:var(--lattice-designer-space-1,4px) var(--lattice-designer-space-2,8px);cursor:pointer;min-width:2em}
|
|
269
|
+
.lattice-designer .lattice-designer-tool:hover:not(:disabled){background:var(--lattice-hovered-background,#f2f5f8)}
|
|
270
|
+
.lattice-designer .lattice-designer-tool:focus-visible{outline:var(--lattice-focus-width,2px) solid var(--lattice-focus-color,#1a6bc7);
|
|
157
271
|
outline-offset:var(--lattice-focus-offset,-2px)}
|
|
158
|
-
.lattice-designer-tool:disabled{opacity:.45;cursor:default}`,(ne.head||ne.documentElement).appendChild(B)}function fe(ne,B){for(let L=ne;L&&L!==B;L=L.parentNode){const D=L.tagName?String(L.tagName).toLowerCase():"";if(D==="input"||D==="textarea"||D==="select"||L.isContentEditable||L.classList&&L.classList.contains("lattice"))return!0}return!1}function J(ne,B,L,D){const o=ne.createElement("button");return o.type="button",o.className="lattice-designer-tool",o.textContent=L,o.setAttribute("aria-label",B),o.addEventListener("click",()=>{D()}),o}function X(ne){const{chrome:B,root:L,doc:D,t:o,undo:w,redo:y,canUndo:i,canRedo:h}=ne;z(D);const c=D.createElement("div");c.className="lattice-designer-tools";const m=J(D,o("designer.undo"),"↶",w),b=J(D,o("designer.redo"),"↷",y);c.appendChild(m),c.appendChild(b),(ne.topbar||B).appendChild(c);const P=()=>{m.disabled=!i(),b.disabled=!h()};P();const u=r=>{if(!r||!(r.ctrlKey||r.metaKey))return;const j=typeof r.key=="string"?r.key.toLowerCase():"";let C;if(j==="z"&&!r.shiftKey)C=w;else if(j==="z"&&r.shiftKey||j==="y")C=y;else return;fe(r.target,L)||C()&&r.preventDefault()};return L.addEventListener("keydown",u),{refresh:P,off:()=>L.removeEventListener("keydown",u)}}}),rt("packages/modules/designer/guardrails.js",function(s,ae){"use strict";Object.defineProperty(s,"PANEL_KINDS",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"FORMATTING_LEVELS",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"PAGE_ACTIONS",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"BASIC_FORMATTING",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"CHART_FAMILIES",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"normaliseGuardrails",{enumerable:!0,get:function(){return D}}),Object.defineProperty(s,"createGuardrails",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return w}});const F=ae("packages/modules/dashboard/spec.js").isPlain,l=Object.freeze(["grid","chart","kpi","calendar","map","html"]),ue=Object.freeze(["full","basic","none"]),z=Object.freeze(["add","remove","rename","reorder"]),fe=Object.freeze(["preset","alignment","wrap"]),J=Object.freeze({bar:Object.freeze(["bar","horizontalBar","waterfall","floatingBar","horizontalFloatingBar","populationPyramid","bullet","combo","pareto"]),line:Object.freeze(["line","step","area","rangeArea"]),scatter:Object.freeze(["scatter","bubble","forest"]),distribution:Object.freeze(["histogram","boxplot","heatmap","qq","ecdf","lorenz","correlogram","control","capability","movingRange"]),hierarchy:Object.freeze(["pie","donut","sunburst","treemap"]),radial:Object.freeze(["radar","gauge"]),time:Object.freeze(["candlestick","ohlc","gantt"]),flow:Object.freeze(["sankey","chord","network","stream","marimekko","violin"]),geo:Object.freeze(["geomap"]),process:Object.freeze(["funnel"])});function X(y){if(!Array.isArray(y))return null;const i=[...new Set(y.filter(h=>typeof h=="string"&&h!==""))];return i.length?i:null}function ne(y){if(Array.isArray(y))return X(y);if(F(y)&&Array.isArray(y.families)){const i=new Set;for(const h of X(y.families)||[]){const c=J[h];if(c)for(const m of c)i.add(m);else i.add(h)}return i.size?[...i]:null}return null}function B(y){return ue.includes(y)?{level:y,options:null}:{level:null,options:X(y)}}function L(y){const i={add:!0,remove:!0,rename:!0,reorder:!0};if(F(y))for(const h of z)typeof y[h]=="boolean"&&(i[h]=y[h]);return i}function D(y){const i=F(y)?y:{};let h=null;if(F(i.fields)){const m={};for(const[b,P]of Object.entries(i.fields)){if(!F(P))continue;const u=X(P.allow),A=X(P.deny);(u||A)&&(m[b]=Object.freeze({allow:u,deny:A}))}Object.keys(m).length&&(h=Object.freeze(m))}const c=i.maxWidgetsPerPage;return Object.freeze({sources:X(i.sources),fields:h,widgets:X(i.widgets),chartTypes:ne(i.chartTypes),formatting:Object.freeze(B(i.formatting)),pages:Object.freeze(L(i.pages)),calculatedFields:i.calculatedFields!==!1,derivedGrids:i.derivedGrids!==!1,ai:i.ai!==!1,maxWidgetsPerPage:Number.isFinite(c)&&c>=0?c:null})}function o(y){const i=D(y),h=(b,P,u)=>{switch(b){case"source":return i.sources&&!i.sources.includes(P)?"sources":null;case"field":{if(!i.fields)return null;const A=i.fields[P];return A&&(A.deny&&A.deny.includes(u)||A.allow&&!A.allow.includes(u))?"fields":null}case"widget":return i.widgets&&!i.widgets.includes(P)?"widgets":null;case"chartType":return i.chartTypes&&!i.chartTypes.includes(P)?"chartTypes":null;case"formatting":return!i.formatting.level&&!i.formatting.options?null:i.formatting.level==="none"?"formatting":i.formatting.level==="full"?null:i.formatting.level==="basic"?fe.includes(P)?null:"formatting":i.formatting.options.includes(P)?null:"formatting";case"page":return i.pages[P]===!1?"pages":null;case"calculatedFields":return i.calculatedFields?null:"calculatedFields";case"derivedGrids":return i.derivedGrids?null:"derivedGrids";case"ai":return i.ai?null:"ai";default:return null}},c=(b,P,u)=>h(b,P,u)===null;return Object.freeze({get value(){return i},allowsSource:b=>c("source",b),allowsField:(b,P)=>c("field",b,P),allowsWidget:b=>c("widget",b),allowsChartType:b=>c("chartType",b),allowsFormatting:b=>c("formatting",b),allowsPage:b=>c("page",b),allowsCalculatedFields:()=>c("calculatedFields"),allowsDerivedGrids:()=>c("derivedGrids"),allowsAi:()=>c("ai"),widgetLimit:()=>i.maxWidgetsPerPage,refuse:h,restrictPanel:b=>{if(!F(b))return null;const P=b.kind;if(i.widgets&&!i.widgets.includes(P))return"widgets";const u=b.source;if(i.sources&&typeof u=="string"&&u!==""&&!u.startsWith("grid:")&&!i.sources.includes(u))return"sources";if((P==="chart"||P==="map")&&i.chartTypes){const A=b.options,r=F(A)?A.type:void 0;if(typeof r=="string"&&r!==""&&!i.chartTypes.includes(r))return"chartTypes"}return null}})}const w=o}),rt("packages/core/src/internal/icon-builtins.js",function(s,ae){"use strict";Object.defineProperty(s,"BUILT_IN_ICONS",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(s,"normaliseIcon",{enumerable:!0,get:function(){return F}});const ve={chevronRight:{viewBox:"0 0 16 16",paths:["M6 3.5 10.5 8 6 12.5"],paint:"stroke"},chevronDown:{viewBox:"0 0 16 16",paths:["M3.5 6 8 10.5 12.5 6"],paint:"stroke"},chevronUp:{viewBox:"0 0 16 16",paths:["M3.5 10 8 5.5 12.5 10"],paint:"stroke"},chevronLeft:{viewBox:"0 0 16 16",paths:["M10 3.5 5.5 8 10 12.5"],paint:"stroke"},check:{viewBox:"0 0 16 16",paths:["M3.5 8.5 6.5 11.5 12.5 4.5"],paint:"stroke"},dash:{viewBox:"0 0 16 16",paths:["M4 8h8"],paint:"stroke"},close:{viewBox:"0 0 16 16",paths:["M4 4l8 8M12 4l-8 8"],paint:"stroke"},plus:{viewBox:"0 0 16 16",paths:["M8 3.5v9M3.5 8h9"],paint:"stroke"},minus:{viewBox:"0 0 16 16",paths:["M3.5 8h9"],paint:"stroke"},info:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm.75 4a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM7.25 7h1.5v4.5h-1.5Z"]},success:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm3.2 4.4-4 4.6-2.4-2.3 1-1.1 1.3 1.2 3-3.4Z"]},warning:{viewBox:"0 0 16 16",paths:["M8 1.5 15 14H1Zm-.75 4v4h1.5v-4Zm0 5v1.5h1.5V10.5Z"]},danger:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm-.75 3h1.5v5h-1.5Zm0 6h1.5V12h-1.5Z"]},clock:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm-.75 3h1.5v3.7l2.5 1.5-.75 1.3-3.25-2Z"]},lock:{viewBox:"0 0 16 16",paths:["M4.5 7V5a3.5 3.5 0 1 1 7 0v2H13v7H3V7Zm1.5 0h4V5a2 2 0 1 0-4 0Z"]},link:{viewBox:"0 0 16 16",paths:["M6.5 9.5a3 3 0 0 1 0-4l2-2a3 3 0 0 1 4 4l-1 1M9.5 6.5a3 3 0 0 1 0 4l-2 2a3 3 0 0 1-4-4l1-1"],paint:"stroke"},external:{viewBox:"0 0 16 16",paths:["M6.5 3.5h-3v9h9v-3M9.5 3.5h3v3M12.5 3.5 7 9"],paint:"stroke"},filter:{viewBox:"0 0 16 16",paths:["M2 3h12l-4.5 5.2V13L6.5 11.5V8.2Z"]},pause:{viewBox:"0 0 16 16",paths:["M4.5 3h2.5v10H4.5zM9 3h2.5v10H9z"]},play:{viewBox:"0 0 16 16",paths:["M4.5 3l8 5-8 5z"]},chart:{viewBox:"0 0 16 16",paths:["M2.5 13.5h11","M4.5 13.5v-4","M8 13.5v-8","M11.5 13.5v-6"],paint:"stroke"},palette:{viewBox:"0 0 16 16",paths:["M8 1.5a6.5 6.5 0 0 0 0 13c.7 0 1.2-.5 1.2-1.1 0-.3-.1-.6-.3-.8a1.1 1.1 0 0 1 .8-1.9h1.4A3.4 3.4 0 0 0 14.5 7c0-3-2.9-5.5-6.5-5.5Z","M4.6 7.6a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM6.7 4.6a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM9.9 4.7a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM11.9 6.9a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"]},undo:{viewBox:"0 0 16 16",paths:["M3 8h6.5a3.25 3.25 0 0 1 0 6.5H6M3 8l3-3M3 8l3 3"],paint:"stroke"},redo:{viewBox:"0 0 16 16",paths:["M13 8H6.5a3.25 3.25 0 0 0 0 6.5H10M13 8l-3-3M13 8l-3 3"],paint:"stroke"},columns:{viewBox:"0 0 16 16",paths:["M2.5 2.5h11v11h-11zM6.5 2.5v11M10 2.5v11"],paint:"stroke"},download:{viewBox:"0 0 16 16",paths:["M8 2.5v7.5M8 10 5 7M8 10l3-3M2.5 12.5h11"],paint:"stroke"},restore:{viewBox:"0 0 16 16",paths:["M3 8a5 5 0 1 0 1.6-3.7M3 3v2.8h2.8"],paint:"stroke"},spreadsheet:{viewBox:"0 0 16 16",paths:["M3 2.5h10v11H3zM3 6h10M3 9.5h10M6.5 6v7.5"],paint:"stroke"},print:{viewBox:"0 0 16 16",paths:["M4.5 6V2.5h7V6M4.5 11.5h-2V6h11v5.5h-2M4.5 9.5h7v4h-7z"],paint:"stroke"},maximise:{viewBox:"0 0 16 16",paths:["M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10"],paint:"stroke"},minimise:{viewBox:"0 0 16 16",paths:["M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"],paint:"stroke"},views:{viewBox:"0 0 16 16",paths:["M4 2.5h8v11L8 11l-4 2.5z"],paint:"stroke"},search:{viewBox:"0 0 16 16",paths:["M7 2.5a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9M10.4 10.4 13.5 13.5"],paint:"stroke"},pencil:{viewBox:"0 0 16 16",paths:["M2.5 11.2 11 2.7l2.3 2.3-8.5 8.5-3 .7z"],paint:"stroke"},trash:{viewBox:"0 0 16 16",paths:["M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.7 8.5h5.6l.7-8.5M6.8 7v3.7M9.2 7v3.7"],paint:"stroke"},share:{viewBox:"0 0 16 16",paths:["M11.5 5.5a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6M4.5 9.8a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6M11.5 14.1a1.8 1.8 0 1 0 0-3.6 1.8 1.8 0 0 0 0 3.6M6.1 7.1l3.8-1.9M6.1 8.9l3.8 1.9"],paint:"stroke"},pin:{viewBox:"0 0 16 16",paths:["M8 2v6M5 8h6l1 2.5H4zM8 10.5V14"],paint:"stroke"},sortAsc:{viewBox:"0 0 16 16",paths:["M8 3.5 12 8H4Z"]},sortDesc:{viewBox:"0 0 16 16",paths:["M8 12.5 4 8h8Z"]},menu:{viewBox:"0 0 16 16",paths:["M2.5 4.5h11M2.5 8h11M2.5 11.5h11"],paint:"stroke"},drag:{viewBox:"0 0 16 16",paths:["M6 3.5h1.5V5H6Zm3 0h1.5V5H9ZM6 7.25h1.5v1.5H6Zm3 0h1.5v1.5H9ZM6 11h1.5v1.5H6Zm3 0h1.5v1.5H9Z"]},star:{viewBox:"0 0 16 16",paths:["M8 1.6l1.96 3.97 4.38.64-3.17 3.09.75 4.36L8 11.6l-3.92 2.06.75-4.36L1.66 6.21l4.38-.64Z"]},heart:{viewBox:"0 0 16 16",paths:["M8 14.2 2.4 8.6a3.3 3.3 0 0 1 4.67-4.67L8 4.86l.93-.93A3.3 3.3 0 0 1 13.6 8.6Z"]},circleFilled:{viewBox:"0 0 16 16",paths:["M8 2a6 6 0 1 0 0 12A6 6 0 0 0 8 2Z"]},square:{viewBox:"0 0 16 16",paths:["M3 3h10v10H3Z"]},bolt:{viewBox:"0 0 16 16",paths:["M9.5 1.5 3.5 9h3.2l-.7 5.5L12.5 7H9.3Z"]},flag:{viewBox:"0 0 16 16",paths:["M4 1.5h1.5v13H4Zm1.5 1h7.5l-1.6 2.6L13 7.7H5.5Z"]},arrow:{viewBox:"0 0 16 16",paths:["M3 13 12.5 3.5","M7.5 3.5H12.5V8.5"],paint:"stroke"},highlight:{viewBox:"0 0 16 16",paths:["M4 11 10 5l2 2-6 6H4z","M3 14.5h10"],paint:"stroke"},eraser:{viewBox:"0 0 16 16",paths:["M3 11 9 5 13 9 7 15Z","M5 13 9 9"],paint:"stroke"},thumbUp:{viewBox:"0 0 16 16",paths:["M5.5 6.8 8.6 1.5a1.6 1.6 0 0 1 1.5 2.1L9.4 6h3.4a1.4 1.4 0 0 1 1.35 1.78l-1.3 4.6A1.9 1.9 0 0 1 11 13.8H5.5ZM4 6.5H1.5v7.3H4Z"]},eye:{viewBox:"0 0 16 16",paths:["M8 3.2c3.3 0 6 3 6.6 4.5C14 9.3 11.3 12.3 8 12.3S2 9.3 1.4 7.7C2 6.2 4.7 3.2 8 3.2Zm0 2a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5Z"]},eyeOff:{viewBox:"0 0 16 16",paths:["M2.2 2.9 13.1 13.8M8 3.2c3.3 0 6 3 6.6 4.5a9.4 9.4 0 0 1-1.9 2.4M5 4.2A9 9 0 0 0 1.4 7.7C2 9.3 4.7 12.3 8 12.3c.9 0 1.7-.2 2.5-.5M6.3 6a2.5 2.5 0 0 0 3.4 3.5"],paint:"stroke"},copy:{viewBox:"0 0 16 16",paths:["M5.5 2.5h8v8M2.5 5.5h8v8h-8Z"],paint:"stroke"},present:{viewBox:"0 0 16 16",paths:["M2 2.5h12v8H2Z","M8 10.5v3","M6 13.5h4"],paint:"stroke"},cabinet:{viewBox:"0 0 16 16",paths:["M3 2h10v12H3ZM5 4v4h2.5V4ZM8.5 4v4H11V4ZM5 9.5V11h6V9.5Z"]},splice:{viewBox:"0 0 16 16",paths:["M8 4.5a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7ZM8 6.8a1.2 1.2 0 1 1 0 2.4 1.2 1.2 0 0 1 0-2.4ZM1.5 7.2h3v1.6h-3ZM11.5 7.2h3v1.6h-3Z"]},exchange:{viewBox:"0 0 16 16",paths:["M8 1.5 14.5 6v1H1.5V6ZM3 8h2v5H3ZM7 8h2v5H7ZM11 8h2v5h-2ZM1.5 13.5h13V15h-13Z"]},pole:{viewBox:"0 0 16 16",paths:["M7.2 1.5h1.6V15H7.2ZM3 3.5h10V5H3ZM4.5 7h7v1.4h-7Z"]},chamber:{viewBox:"0 0 16 16",paths:["M2.5 3.5h11v9h-11ZM4.5 5.5v5h7v-5ZM6 7h4v1.5H6Z"]},premises:{viewBox:"0 0 16 16",paths:["M8 1.8 14.5 7.5h-2V14h-9V7.5h-2ZM6.8 10.4V14h2.4v-3.6Z"]},fault:{viewBox:"0 0 16 16",paths:["M5.2 1.5h5.6L14.5 5.2v5.6L10.8 14.5H5.2L1.5 10.8V5.2ZM5.4 9.4 6.6 10.6 8 9.2 9.4 10.6 10.6 9.4 9.2 8 10.6 6.6 9.4 5.4 8 6.8 6.6 5.4 5.4 6.6 6.8 8Z"]},blank:{viewBox:"0 0 16 16",paths:[""]}};function F(l){return typeof l=="string"?{viewBox:"0 0 16 16",paths:[l],paint:"fill"}:Array.isArray(l)?{viewBox:"0 0 16 16",paths:l.slice(),paint:"fill"}:{viewBox:l&&l.viewBox||"0 0 16 16",paths:l&&Array.isArray(l.paths)?l.paths.slice():l&&l.path?[l.path]:[],paint:l&&l.paint==="stroke"?"stroke":"fill"}}}),rt("packages/dom/src/cell/icons.js",function(s,ae){"use strict";Object.defineProperty(s,"SVG_NS",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"registerIcon",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"registerIcons",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"icon",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"iconNames",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"createIcon",{enumerable:!0,get:function(){return D}}),Object.defineProperty(s,"updateIcon",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"isIconMarkup",{enumerable:!0,get:function(){return y}}),Object.defineProperty(s,"renderIconInto",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"resetIcons",{enumerable:!0,get:function(){return h}});const F=ae("packages/core/src/internal/util.js").warnOnce,l=ae("packages/core/src/internal/icon-builtins.js"),ue=l.BUILT_IN_ICONS,z=l.normaliseIcon,fe="http://www.w3.org/2000/svg",J=new Map(Object.entries(ue));function X(c,m){J.set(c,z(m))}function ne(c){if(c)for(const m of Object.keys(c))X(m,c[m])}function B(c){return J.get(c)}function L(){return[...J.keys()]}function D(c,m,b){let P=J.get(m);P||(F(`icon:${m}`,`Unknown icon '${m}'; drew a blank glyph in its place. Register it with grid.icons or config.icons.`),P=J.get("blank"));const u=c.createElementNS(fe,"svg");u.setAttribute("class",b&&b.className||"lat-icon"),u.setAttribute("viewBox",P.viewBox),u.setAttribute("focusable","false"),u.setAttribute("aria-hidden","true"),w(u,P.paint);const A=[];for(const r of P.paths){const j=c.createElementNS(fe,"path");j.setAttribute("d",r),u.appendChild(j),A.push(j)}return u.__latIcon={name:m,nodes:A,paint:P.paint},u}function o(c,m){const b=c&&c.__latIcon;if(!b)return!1;if(b.name===m)return!0;const P=J.get(m);if(!P)return F(`icon:${m}`,`Unknown icon '${m}'. Register it with grid.icons or config.icons.`),!1;if(P.paths.length!==b.nodes.length)return!1;for(let u=0;u<P.paths.length;u++)b.nodes[u].setAttribute("d",P.paths[u]);return c.setAttribute("viewBox",P.viewBox),P.paint!==b.paint&&(w(c,P.paint),b.paint=P.paint),b.name=m,!0}function w(c,m){if(m==="stroke"){c.setAttribute("fill","none"),c.setAttribute("stroke","currentColor"),c.setAttribute("stroke-width","1.5"),c.setAttribute("stroke-linecap","round"),c.setAttribute("stroke-linejoin","round");return}c.setAttribute("fill","currentColor"),c.removeAttribute("stroke"),c.removeAttribute("stroke-width"),c.removeAttribute("stroke-linecap"),c.removeAttribute("stroke-linejoin")}function y(c){if(typeof c!="string")return!1;const m=c.trim();return/^<[a-zA-Z!/]/.test(m)&&m.includes(">")}function i(c,m,b){return c.textContent="",c.removeAttribute("data-icon"),m==null||m===""?(m===""&&F(`icon:empty:${b}`,`An empty icon value at ${b} renders nothing; omit \`icon\` instead.`),c):typeof m!="string"?(F(`icon:type:${b}`,`An icon must be a name, a character, or element markup; got ${typeof m} at ${b}.`),c):y(m)?(c.innerHTML=m,c):(c.setAttribute("data-icon",m),c)}function h(){J.clear();for(const[c,m]of Object.entries(ue))J.set(c,m)}}),rt("packages/modules/designer/data-panel.js",function(s,ae){"use strict";Object.defineProperty(s,"FIELD_TYPES",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"stripDeclaredFields",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"resolveSourceFields",{enumerable:!0,get:function(){return b}}),Object.defineProperty(s,"compileRelationships",{enumerable:!0,get:function(){return A}}),Object.defineProperty(s,"reachableSources",{enumerable:!0,get:function(){return r}}),Object.defineProperty(s,"mountDataPanel",{enumerable:!0,get:function(){return p}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return v}});const ve=ae("packages/core/src/internal/util.js"),F=ve.warnOnce,l=ve.isFunction,z=ae("packages/modules/dashboard/spec.js").isPlain,J=ae("packages/dom/src/cell/icons.js").SVG_NS,X=Object.freeze(["number","currency","percent","date","datetime","boolean","text","list","geometry"]),ne=Object.freeze({number:{viewBox:"0 0 16 16",paths:["M3 13V7l2-2M8 13V5l2-2M12 13V9l2-2"],paint:"stroke"},currency:{viewBox:"0 0 16 16",paths:["M8 2.5v11M10.5 4.8c0-1-1-1.6-2.3-1.6-1.6 0-2.7.8-2.7 2s1 1.7 2.5 2 2.7.8 2.7 2.1-1.1 2-2.7 2c-1.3 0-2.4-.6-2.5-1.6"],paint:"stroke"},percent:{viewBox:"0 0 16 16",paths:["M3.5 12.5 12.5 3.5M5 6a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm6 7a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z"],paint:"stroke"},date:{viewBox:"0 0 16 16",paths:["M3 3.5h10v10H3zM3 6.5h10M5.5 2v3M10.5 2v3"],paint:"stroke"},datetime:{viewBox:"0 0 16 16",paths:["M3 3.5h10v10H3zM3 6.5h10M5.5 2v3M10.5 2v3M8 8.5v2l1.5 1"],paint:"stroke"},boolean:{viewBox:"0 0 16 16",paths:["M5 8.5 7 11l4.5-6"],paint:"stroke"},text:{viewBox:"0 0 16 16",paths:["M3 3.5h10M8 3.5v9"],paint:"stroke"},list:{viewBox:"0 0 16 16",paths:["M4 4h8M4 8h8M4 12h8"],paint:"stroke"},geometry:{viewBox:"0 0 16 16",paths:["M8 2.5 13.5 12.5h-11Z"],paint:"stroke"}});function B(n,t){const a=ne[t]||ne.text,e=n.createElementNS(J,"svg");e.setAttribute("class","lattice-designer-datapanel__icon lat-icon"),e.setAttribute("viewBox",a.viewBox),e.setAttribute("focusable","false"),e.setAttribute("aria-hidden","true"),a.paint==="stroke"?Object.assign(e.style,{stroke:"currentColor",fill:"none",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}):e.style.fill="currentColor";for(const f of a.paths){const d=n.createElementNS(J,"path");d.setAttribute("d",f),e.appendChild(d)}return e}const L=Object.freeze({text:"text",number:"number",boolean:"boolean",date:"date",dateString:"date",datetime:"datetime",timestamp:"datetime",currency:"currency",usd:"currency",eur:"currency",gbp:"currency",jpy:"currency",percentRate:"percent",ratio:"percent",geometry:"geometry",list:"list"});function D(n){const t=String(n).replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim();return t?t.charAt(0).toUpperCase()+t.slice(1):String(n)}function o(n){return L[n]||"text"}function w(n){return n==null?null:Array.isArray(n)?"list":typeof n=="boolean"?"boolean":typeof n=="number"?"number":n instanceof Date?n.getUTCHours()===0&&n.getUTCMinutes()===0&&n.getUTCSeconds()===0&&n.getUTCMilliseconds()===0?"date":"datetime":z(n)&&typeof n.type=="string"&&Array.isArray(n.coordinates)?"geometry":typeof n=="string"?/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(n)?"datetime":/^\d{4}-\d{2}-\d{2}$/.test(n)?"date":"text":"text"}function y(n){if(!Array.isArray(n))return[];const t=[];for(const a of n){if(typeof a=="string"&&a){t.push({id:a,label:D(a),type:"text",declared:!1});continue}if(!z(a))continue;const e=a.field||a.id;e&&t.push({id:String(e),label:typeof a.title=="string"&&a.title?a.title:D(String(e)),type:o(a.type),format:typeof a.format=="string"?a.format:void 0,declared:!1})}return t}function i(n,t){if(Array.isArray(t)&&t.length)return y(t);const a=Array.isArray(n)?n.slice(0,25):[],e=new Map;for(const d of a)if(z(d))for(const E of Object.keys(d)){if(e.has(E))continue;const M=w(d[E]);M&&e.set(E,M)}const f=a.find(z);if(f)for(const d of Object.keys(f))e.has(d)||e.set(d,"text");return[...e.entries()].map(([d,E])=>({id:d,label:D(d),type:E,declared:!1}))}function h(n,t){if(Array.isArray(t)&&t.length)return y(t);const a=z(n)?Array.isArray(n.schema)?n.schema:Array.isArray(n.columns)?n.columns:null:null;return a?y(a):[]}function c(n,t){const a=t&&l(t.panel)?t.panel(n):null,e=a&&a.grid;return!e||!e.columns||!l(e.columns.all)?[]:y(e.columns.all())}function m(n){if(!z(n))return n;const t={};for(const a of Object.keys(n)){const e=n[a];if(z(e)&&"fields"in e){const{fields:f,...d}=e;t[a]=d}else t[a]=e}return t}function b(n,t){return z(n)?Array.isArray(n.fields)&&n.fields.length?n.fields.filter(z).filter(a=>a.id!=null).map(a=>({id:String(a.id),label:a.label!=null?String(a.label):D(String(a.id)),type:X.includes(a.type)?a.type:"text",format:typeof a.format=="string"?a.format:void 0,description:typeof a.description=="string"?a.description:void 0,declared:!0})):n.kind==="rows"?i(n.rows,n.columns):n.kind==="pushdown"?h(n.adapter,n.columns):n.kind==="router"?y(n.columns):n.kind==="grid"?c(n.of,t):[]:[]}function P(n,t,a){const e=z(a)&&Array.isArray(a.fields)&&a.fields.length,f=z(a)?a.adapter:null;if(!e&&z(a)&&a.kind==="pushdown"&&n.pushdown&&f&&l(f.describe)){const d=n.pushdown.fields(t);if(d===null)return[];if(d.length)return d}return b(a,n.dashboard)}function u(n){if(typeof n!="string")return null;const t=n.indexOf(".");return t<1||t===n.length-1?null:{source:n.slice(0,t),field:n.slice(t+1)}}function A(n){const t=[];if(!Array.isArray(n))return t;for(const a of n){if(!z(a))continue;const e=u(a.from),f=u(a.to);if(!e||!f){F(`designer:relationship:${JSON.stringify(a.from)}:${JSON.stringify(a.to)}`,`designer: a relationship names "source.field" on both \`from\` and \`to\`; ${JSON.stringify(a.from)} -> ${JSON.stringify(a.to)} was ignored.`);continue}const d=a.type==="one-to-many"||a.type==="one-to-one"?a.type:"many-to-one",E={from:f.source,localKey:e.field,foreignKey:f.field};d==="one-to-many"?(E.many=!0,E.as=typeof a.as=="string"&&a.as?a.as:f.source):a.fields!==void 0&&(E.fields=a.fields),t.push({sourceId:e.source,relatedSourceId:f.source,field:e.field,relatedField:f.field,type:d,join:E})}return t}function r(n,t){const a=new Map,e=(E,M)=>{a.has(E)||a.set(E,new Set),a.get(E).add(M)};if(Array.isArray(t))for(const E of t){if(!z(E))continue;const M=u(E.from),W=u(E.to);!M||!W||(e(M.source,W.source),e(W.source,M.source))}const f=new Set([n]),d=[n];for(;d.length;){const E=d.shift();for(const M of a.get(E)||[])f.has(M)||(f.add(M),d.push(M))}return f.delete(n),[...f]}function j(n,t){return!!n&&l(n.allowsSource)&&!n.allowsSource(t)}function C(n,t,a){return!!n&&l(n.allowsField)&&!n.allowsField(t,a)}function G(n,t){let a=t,e=2;for(;n.includes(a);)a=`${t}-${e++}`;return a}const _=Object.freeze(["number","currency","percent"]);function T(n,t,a){const e=G(a,`${n}-${t.id}`),f=t.label||t.id;return _.includes(t.type)?{id:e,kind:"kpi",title:f,source:n,options:{tiles:[{id:t.id,label:f,aggregation:"sum",field:t.id,format:t.format}]}}:t.type==="boolean"?{id:e,kind:"kpi",title:f,source:n,options:{tiles:[{id:t.id,label:f,aggregation:"count",field:t.id}]}}:{id:e,kind:"grid",title:f,source:n,options:{columns:[{field:t.id,title:f}]}}}function p(n,{doc:t,t:a}){let e="",f=null,d=null;const E=[],M=t.createElement("div");M.className="lattice-designer-datapanel",M.setAttribute("role","region"),M.setAttribute("aria-label",a("designer.data.panel")),Object.assign(M.style,{display:"flex",flexDirection:"column",gap:"0.5em",font:"inherit",color:"var(--lat-chrome-ink, inherit)"});const W=t.createElement("input");W.type="search",W.className="lattice-designer-datapanel__search",W.setAttribute("aria-label",a("designer.data.search")),W.placeholder=a("designer.data.search");const oe=t.createElement("div");oe.className="lattice-designer-datapanel__reachable",oe.setAttribute("role","status"),oe.setAttribute("aria-live","polite");const q=t.createElement("ul");q.className="lattice-designer-datapanel__relationships",q.setAttribute("aria-label",a("designer.data.relationships"));const Q=t.createElement("ul");Q.className="lattice-designer-datapanel__fields",Q.setAttribute("role","listbox"),Q.setAttribute("aria-label",a("designer.data.sources"));const H=t.createElement("ul");H.className="lattice-designer-datapanel__derived",H.setAttribute("aria-label",a("designer.data.derived")),M.appendChild(W),M.appendChild(oe),M.appendChild(q),M.appendChild(Q),M.appendChild(H),(n.rails?n.rails.left.slot("data"):n.chrome).appendChild(M);const O=()=>{const Y=n.guardrails,Z=z(n.context.sources)?n.context.sources:{},x=n.getState(),ee=Array.isArray(x.pages)?x.pages.find(xe=>z(xe)&&xe.id===x.selectedPageId):null,se=ee&&z(ee.spec)&&z(ee.spec.sources)?ee.spec.sources:{},de={...Z,...se},ye=[];for(const xe of Object.keys(de)){if(j(Y,xe))continue;const me=de[xe],Ne=P(n,xe,me).filter(Ae=>!C(Y,xe,Ae.id));ye.push({id:xe,kind:z(me)?me.kind:void 0,fields:Ne})}return ye},I=()=>{if(!f)return null;const Y=n.getState(),Z=Array.isArray(Y.pages)?Y.pages.find(se=>z(se)&&se.id===Y.selectedPageId):null,ee=(Z&&z(Z.spec)&&Array.isArray(Z.spec.panels)?Z.spec.panels:[]).find(se=>z(se)&&se.id===f);return ee&&typeof ee.source=="string"?ee.source:null},K=(Y,Z)=>{const x=t.createElement("li");x.className="lattice-designer-datapanel__field",x.setAttribute("role","option"),x.setAttribute("tabindex","0"),x.setAttribute("draggable","true"),x.setAttribute("data-source-id",Y),x.setAttribute("data-field-id",Z.id),Object.assign(x.style,{display:"flex",alignItems:"center",gap:"0.4em",cursor:"grab"}),x.appendChild(B(t,Z.type));const ee=t.createElement("span");ee.className="lattice-designer-datapanel__field-label",ee.textContent=Z.label,x.appendChild(ee);const se=[a(`designer.data.type.${Z.type}`)];if(Z.description&&se.push(Z.description),x.setAttribute("aria-label",a("designer.data.field.add",{field:Z.label})),x.title=se.join(" — "),Z.description){const ye=t.createElement("span");ye.className="lattice-designer-datapanel__field-desc",ye.textContent=Z.description,Object.assign(ye.style,{opacity:"0.7",fontSize:"0.85em"}),x.appendChild(ye)}const de=()=>n.commands.run("dropField",{sourceId:Y,fieldId:Z.id});return x.addEventListener("dragstart",ye=>{d={sourceId:Y,fieldId:Z.id};try{ye.dataTransfer&&ye.dataTransfer.setData("text/plain",`${Y}.${Z.id}`)}catch{}}),x.addEventListener("dragend",()=>{d=null}),x.addEventListener("keydown",ye=>{(ye.key==="Enter"||ye.key===" "||ye.key==="Spacebar")&&(ye.preventDefault(),de())}),x},g=Y=>{const Z=n.getState(),x=Array.isArray(Z.pages)?Z.pages.find(de=>z(de)&&de.id===Z.selectedPageId):null,ee=x&&z(x.spec)&&Array.isArray(x.spec.panels)?x.spec.panels:[],se=ee.find(de=>z(de)&&de.id===Y)||ee.find(de=>z(de)&&de.source===Y);se&&l(n.selectWidget)&&n.selectWidget(se.id)},k=()=>{const Y=O(),Z=e.trim().toLowerCase();Q.textContent="";let x=0;for(const ye of Y){const xe=Z?ye.fields.filter(Ae=>`${ye.id} ${Ae.id} ${Ae.label} ${Ae.description||""}`.toLowerCase().includes(Z)):ye.fields;if(!xe.length)continue;const me=t.createElement("li");me.className="lattice-designer-datapanel__source";const Ne=t.createElement("div");Ne.className="lattice-designer-datapanel__source-title",Ne.textContent=ye.id,me.appendChild(Ne);for(const Ae of X){const te=xe.filter(pe=>pe.type===Ae);if(!te.length)continue;const re=t.createElement("div");re.className="lattice-designer-datapanel__type-group",re.setAttribute("role","group"),re.setAttribute("aria-label",a(`designer.data.type.${Ae}`));const le=t.createElement("div");le.className="lattice-designer-datapanel__type-label",le.textContent=a(`designer.data.type.${Ae}`),Object.assign(le.style,{opacity:"0.6",fontSize:"0.8em"}),re.appendChild(le);for(const pe of te)re.appendChild(K(ye.id,pe)),x+=1;me.appendChild(re)}Q.appendChild(me)}if(!x){const ye=t.createElement("li");ye.className="lattice-designer-datapanel__empty",ye.textContent=a("designer.data.empty",{query:JSON.stringify(e)}),Q.appendChild(ye)}H.textContent="";const ee=n.derived;if(ee&&l(ee.steps)&&l(ee.refusals)&&l(ee.provenance)){const ye=n.getState(),xe=Array.isArray(ye.pages)?ye.pages.find(Ae=>z(Ae)&&Ae.id===ye.selectedPageId):null,me=xe&&z(xe.spec)&&Array.isArray(xe.spec.panels)?xe.spec.panels:[],Ne=z(ye.panels)?Object.keys(ye.panels).filter(Ae=>z(ye.panels[Ae])&&z(ye.panels[Ae].derived)):[];for(const Ae of Ne){const te=ye.panels[Ae].derived,re=me.find(ce=>z(ce)&&ce.id===Ae),le=re&&re.title!=null?String(re.title):Ae,pe=t.createElement("li");pe.className="lattice-designer-datapanel__derived-grid",pe.setAttribute("data-derived-id",Ae);const we=t.createElement("div");if(we.className="lattice-designer-datapanel__derived-title",we.textContent=le,pe.appendChild(we),te.hidden){const ce=t.createElement("span");ce.className="lattice-designer-datapanel__derived-hidden",ce.textContent=a("designer.data.derived.hidden"),we.appendChild(ce);const Oe=t.createElement("button");Oe.type="button",Oe.className="lattice-designer-datapanel__derived-show",Oe.textContent=a("designer.data.derived.show"),Oe.addEventListener("click",()=>n.commands.run("setDerivedHidden",Ae,!1)),we.appendChild(Oe)}const je=t.createElement("div");je.className="lattice-designer-datapanel__derived-lineage";const Be=t.createElement("span");Be.textContent=`${le} ${a("designer.data.derived.lineage")} `,je.appendChild(Be);const Ue=[{id:te.from,label:te.fromLabel||te.from}],qe=z(te.lineage)&&Array.isArray(te.lineage.related)?te.lineage.related:[];for(const ce of qe)Ue.push({id:ce,label:ce});Ue.forEach((ce,Oe)=>{Oe&&je.appendChild(t.createTextNode(" + "));const be=t.createElement("button");be.type="button",be.className="lattice-designer-datapanel__derived-parent",be.setAttribute("data-parent-id",ce.id),be.textContent=ce.label,be.addEventListener("click",()=>g(ce.id)),je.appendChild(be)}),pe.appendChild(je);const ot=ee.steps(Ae)||[],tt=new Map(ee.refusals(Ae).map(ce=>[ce.index,ce])),he=ee.provenance(Ae).engine,ie=t.createElement("ol");ie.className="lattice-designer-datapanel__derived-steps",ot.forEach((ce,Oe)=>{const be=t.createElement("li");be.className="lattice-designer-datapanel__derived-step",be.setAttribute("data-step-kind",ce.kind),be.textContent=a(`designer.derived.step.${ce.kind}`);const ge=tt.get(Oe);if(ge){be.setAttribute("data-refused",ge.name);const ke=t.createElement("span");ke.className="lattice-designer-datapanel__derived-step-refused",ke.textContent=` — ${ge.name==="join"?ge.reason:a("designer.derived.step.refused",{step:ge.name,engine:he||"engine"})}`,be.appendChild(ke)}ie.appendChild(be)}),pe.appendChild(ie),H.appendChild(pe)}}q.textContent="";const se=A(n.context.relationships);for(const ye of se){const xe=t.createElement("li");xe.textContent=`${ye.sourceId}.${ye.field} → ${ye.relatedSourceId}.${ye.relatedField} (${ye.type})`,q.appendChild(xe)}const de=I();if(!de)oe.textContent="";else{const ye=r(de,n.context.relationships);oe.textContent=ye.length?a("designer.data.reachable",{source:de,sources:ye.join(", ")}):a("designer.data.noReachable",{source:de})}};n.commands.register("dropField",(Y,{sourceId:Z,fieldId:x}={})=>{const ee=Y.getState(),se=Array.isArray(ee.pages)?ee.pages.find(me=>z(me)&&me.id===ee.selectedPageId):null;if(!se)return!1;const de=O().find(me=>me.id===Z),ye=de&&de.fields.find(me=>me.id===x);if(!ye)return F(`designer:drop-field:${Z}:${x}`,`designer: there is no visible field ${JSON.stringify(x)} on source ${JSON.stringify(Z)}; nothing was added.`),!1;z(se.spec)||(se.spec={panels:[]}),Array.isArray(se.spec.panels)||(se.spec.panels=[]);const xe=se.spec.panels.filter(z).map(me=>me.id);return se.spec.panels.push(T(Z,ye,xe)),Y.commit(ee,"dropField")});const V=Y=>{d&&Y.preventDefault()},R=Y=>{d&&(Y.preventDefault(),n.commands.run("dropField",d))};n.canvas.addEventListener("dragover",V),n.canvas.addEventListener("drop",R);const N=Y=>{const Z=l(Y.target.closest)?Y.target.closest("[data-window-id]"):null;f=Z?Z.getAttribute("data-window-id"):null,k()};n.canvas.addEventListener("click",N);const $=n.on("state",k),S=n.pushdown?n.pushdown.onChange(k):()=>{};return W.addEventListener("input",()=>{e=W.value,k()}),k(),{get el(){return M},sources(){return O()},reachable(Y){return r(Y,n.context.relationships)},compiledRelationships(){return A(n.context.relationships)},setQuery(Y){W.value=String(Y||""),e=W.value,k()},selectSource(Y){f=Y||null,k()},registerRoleTarget(Y,Z){const x=de=>{d&&de.preventDefault()},ee=de=>{if(!d)return;de.preventDefault(),de.stopPropagation();const ye=d;l(Z)&&Z(ye)};Y.addEventListener("dragover",x),Y.addEventListener("drop",ee);const se=()=>{Y.removeEventListener("dragover",x),Y.removeEventListener("drop",ee)};return E.push(se),se},destroy(){$(),S(),E.splice(0).forEach(Y=>Y()),n.canvas.removeEventListener("dragover",V),n.canvas.removeEventListener("drop",R),n.canvas.removeEventListener("click",N),M.remove()}}}const v=p}),rt("packages/modules/designer/canvas.js",function(s,ae){"use strict";Object.defineProperty(s,"removeWidgetState",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"addWidgetState",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"wireCanvas",{enumerable:!0,get:function(){return o}});const ve=ae("packages/modules/dashboard/spec.js"),F=ve.isPlain,l=ve.sameSpec,z=ae("packages/modules/designer/messages.js").resolveMessages,fe="lat-layout",J=Object.freeze(["xPos","yPos","xSize","ySize"]),X=Object.freeze(["grid","chart","kpi","calendar","map","html"]);function ne(w){return!F(w)||!Array.isArray(w.pages)?null:w.pages.find(y=>F(y)&&y.id===w.selectedPageId)||null}function B(w,y){const i=ne(w);if(!i||!F(i.spec)||!Array.isArray(i.spec.panels))return null;const h=i.spec,c=h.panels.findIndex(m=>F(m)&&m.id===y);if(c<0)return null;if(h.panels.splice(c,1),F(h.layout)&&Array.isArray(h.layout.windows)){const m=h.layout.windows.findIndex(b=>F(b)&&b.id===y);m>=0&&h.layout.windows.splice(m,1)}return w}function L(w,y,i){if(!F(y)||y.id==null||String(y.id)==="")return null;const h=ne(w);if(!h)return null;F(h.spec)||(h.spec={panels:[]});const c=h.spec;return Array.isArray(c.panels)||(c.panels=[]),c.panels.some(m=>F(m)&&m.id===y.id)?null:(c.panels.push({...y}),F(i)&&(F(c.layout)||(c.layout={}),Array.isArray(c.layout.windows)||(c.layout.windows=[]),c.layout.windows.push({id:y.id,...i})),w)}function D(w,y){const i=w.getLayout().windows,h=F(y.layout)?JSON.parse(JSON.stringify(y.layout)):y.layout;F(y.layout)||(y.layout={}),Array.isArray(y.layout.windows)||(y.layout.windows=[]);const c=y.layout.windows;for(const m of i){let b=c.find(P=>F(P)&&P.id===m.id);b||(b={id:m.id},c.push(b));for(const P of J)m[P]!==void 0&&(b[P]=m[P])}return!l(h,y.layout)}function o(w){const{layout:y,canvas:i,page:h,emitState:c,removeWidget:m,emit:b,announce:P}=w,u=z(w.messages);let A=null;y.setInteractive({movable:!0,resizable:!0,closable:!0});const r=()=>[...i.querySelectorAll(`.${fe}__window`)],j=e=>r().find(f=>f.getAttribute("data-window-id")===e)||null,C=e=>{const f=h();return!F(f)||!F(f.spec)||!Array.isArray(f.spec.panels)?null:f.spec.panels.find(d=>F(d)&&d.id===e)||null},G=e=>e?X.includes(e)?u(`designer.kind.${e}`):e.charAt(0).toUpperCase()+e.slice(1):u("designer.kind.panel"),_=(e,f)=>{const d=C(e),E=G(d&&d.kind),M=d&&d.title!=null?String(d.title):e;return u(f?"designer.widget.selected":"designer.widget.name",{kind:E,title:M})},T=()=>{for(const e of r()){const f=e.getAttribute("data-window-id");e.getAttribute("tabindex")==null&&e.setAttribute("tabindex","0"),e.setAttribute("aria-label",_(f,f===A))}},p={selectWidget(e,f){const d=e==null?null:String(e);return d!=null&&!j(d)||(A=y.select(d),T(),b("select",{id:A,panel:A==null?null:C(A),type:"select"}),A!=null&&P(u("a11y.designer.selected",{name:_(A,!1)}))),A},selectedWidget(){return A==null?null:{id:A,panel:C(A)}},dispose(){i.removeEventListener("click",v),i.removeEventListener("keydown",n),t(),a()}};function v(e){const f=e.target&&e.target.closest?e.target.closest(`.${fe}__window`):null;f&&i.contains(f)&&p.selectWidget(f.getAttribute("data-window-id"),"user")}function n(e){if(e.key==="Enter"){const f=e.target&&e.target.classList&&e.target.classList.contains(`${fe}__window`)?e.target:null;f&&(e.preventDefault&&e.preventDefault(),p.selectWidget(f.getAttribute("data-window-id"),"user"));return}if((e.key==="Delete"||e.key==="Del")&&A!=null){const f=e.target&&e.target.tagName;if(f==="INPUT"||f==="TEXTAREA"||e.target&&e.target.isContentEditable)return;e.preventDefault&&e.preventDefault();const d=A,E=_(d,!1);m(d)&&P(u("a11y.designer.removed",{name:E}))}}const t=y.on("layout:changed",e=>{if(e.cause!=="move"&&e.cause!=="resize")return;const f=h();!F(f)||!F(f.spec)||D(y,f.spec)&&c(e.cause)}),a=y.on("window:closed",e=>{m(e.id)});return i.addEventListener("click",v),i.addEventListener("keydown",n),T(),p}}),rt("packages/core/src/registry/widgets.js",function(s,ae){"use strict";Object.defineProperty(s,"WIDGET_AGGREGATIONS",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(s,"widgetKinds",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"widgetEditorModel",{enumerable:!0,get:function(){return z}});const ve=Object.freeze(["sum","avg","min","max","count","countDistinct","median"]),F=Object.freeze([{name:"layout.hidden",type:"boolean",default:!1},{name:"layout.width",type:"number",min:40,max:2e3,step:10},{name:"format",type:"string",format:"number"},{name:"sort",type:"enum",values:["asc","desc"]},{name:"group",type:"boolean",default:!1},{name:"pivot",type:"boolean",default:!1},{name:"total",type:"enum",values:["sum","avg","min","max","count","countValues","first","last"]}]),l=Object.freeze({grid:{roles:[{role:"columns",accepts:"field",path:"columns",repeatable:!0,entryKey:"field",entryOptions:F,orderable:!0}],options:[{name:"pivot.enabled",type:"boolean",default:!1},{name:"grandTotalRow",type:"boolean",default:!1},{name:"groupFooter",type:"boolean",default:!1},{name:"selection",type:"enum",values:["none","single","multiple"]}]},kpi:{aggregations:["sum","avg","min","max","count","countDistinct"],roles:[{role:"measure",accepts:"measure",path:"tiles.0.field",aggPath:"tiles.0.aggregation",aggregated:!0,required:!0},{role:"sparkline",accepts:"measure",path:"tiles.0.sparkline.y"},{role:"sparklineOrder",accepts:"field",path:"tiles.0.sparkline.x"}],options:[{name:"tiles.0.label",type:"string"},{name:"tiles.0.format",type:"enum",values:["number","currency","percent","compact"]},{name:"tiles.0.baseline",type:"number"},{name:"tiles.0.delta",type:"enum",values:["absolute","relative","both"],default:"both"},{name:"tiles.0.target",type:"number"}]},calendar:{roles:[{role:"date",accepts:"field",path:"date"},{role:"measure",accepts:"measure",path:"value",aggregated:!0,aggPath:"aggregation"}],options:[]},html:{roles:[],options:[{name:"text",type:"string"}]}});function ue(){return Object.keys(l)}function z(fe){const J=l[fe];return J?{kind:fe,roles:J.roles.map(X=>({...X})),options:J.options.map(X=>({...X})),aggregations:J.aggregations?Object.freeze([...J.aggregations]):ve}:null}}),rt("packages/modules/designer/properties.js",function(s,ae){"use strict";Object.defineProperty(s,"installProperties",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return A}});const F=ae("packages/modules/dashboard/spec.js").isPlain,l=ae("packages/modules/charts/capabilities.js"),ue=l.chartEditorModel,z=l.CHART_TYPES,J=ae("packages/modules/charts/registry.js").registeredChartTypes,ne=ae("packages/core/src/registry/widgets.js").widgetEditorModel,L=ae("packages/modules/designer/messages.js").resolveMessages,D="designer.properties.commit",o=Object.freeze(["markermap","bubblemap","choropleth","geomap"]),w=Object.freeze(["day","week","month","quarter","year"]);function y(r,j){let C=r;for(const G of j.split(".")){if(C==null)return;C=C[G]}return C}function i(r,j,C){const G=j.split(".");let _=r;for(let p=0;p<G.length-1;p++){const v=G[p];_[v]==null&&(_[v]=/^\d+$/.test(G[p+1])?[]:{}),_=_[v]}const T=G[G.length-1];if(C!==void 0){_[T]=C;return}delete _[T];for(let p=G.length-1;p>0;p--){const v=p===1?r:y(r,G.slice(0,p-1).join(".")),n=G[p-1],t=v&&v[n];if(F(t)&&!Object.keys(t).length)delete v[n];else break}}function h(r,j){let C;if(r.type==="boolean"?C=!!j:r.type==="number"?(C=j===""||j==null?void 0:Number(j),Number.isNaN(C)&&(C=void 0)):r.type==="enum"?C=j===""||j==null?void 0:j:r.type==="list"?(C=(Array.isArray(j)?j:String(j??"").split(",")).map(_=>String(_).trim()).filter(Boolean),C.length||(C=void 0)):C=m(j),!(r.type==="boolean"&&C===(r.default===void 0?!1:r.default))&&!(r.default!==void 0&&C===r.default))return C}function c(r){return r==null?"":typeof r=="string"?r:r.col||r.field||""}const m=r=>typeof r=="string"&&r.trim()?r:void 0,b=r=>r.path||r.role,P=r=>{const C=String(r).split(".").pop().replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase();return C.charAt(0).toUpperCase()+C.slice(1)};function u(r,j={}){const C=L(j&&j.messages),G=F(j.factories)?j.factories:{},_=globalThis.LatticeGrid||{},T=(ie,ce)=>typeof G[ie]=="function"?G[ie]:typeof _[ie]=="function"?_[ie]:ce,p=T("chartEditorModel",ue),v=T("registeredChartTypes",J),n=r.chrome,t=n.ownerDocument;let a=null,e=!1,f=null;const d=t.createElement("div");d.className="lattice-designer-properties",d.setAttribute("role","group"),d.setAttribute("aria-label",C("designer.properties"));const E=t.createElement("div");E.className="lattice-designer-properties-live",E.setAttribute("role","status"),E.setAttribute("aria-live","polite"),Object.assign(E.style,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"}),d.appendChild(E),(r.rails?r.rails.right.slot():n).appendChild(d);const M=(ie,ce)=>{const Oe=C(ie);return Oe===ie?ce:Oe},W=ie=>M(`designer.role.${ie}`,P(ie)),oe=(ie,ce="opt")=>M(`designer.${ce}.${ie}`,P(ie)),q=(ie,ce,Oe="opt")=>M(`designer.${Oe}.${ie}.${String(ce)}`,String(ce));let Q=null;const H=()=>{const ie=r.getState();return ie.pages.find(ce=>F(ce)&&ce.id===ie.selectedPageId)||null},O=()=>{const ie=H();return ie&&F(ie.spec)&&Array.isArray(ie.spec.panels)?ie.spec.panels.filter(F):[]},I=()=>O().find(ie=>ie.id===a)||null,K=ie=>{let ce=ie;for(let Oe=0;Oe<12&&typeof ce=="string"&&ce.startsWith("grid:");Oe++){const be=O().find(ge=>ge.id===ce.slice(5));ce=be?be.source:null}return ce},g=ie=>{const ce=[],Oe=Ee=>{Ee&&!ce.includes(Ee)&&ce.push(Ee)},be=r.pushdown&&typeof ie.source=="string"&&r.pushdown.isPushdown(ie.source)?r.pushdown.fields(ie.source.startsWith("grid:")?K(ie.source):ie.source):null;if(be){for(const Ee of be)Oe(Ee.id);return ce}const ge=r.dashboard&&r.dashboard.panel(ie.id),ke=ge&&ge.grid;if(ke&&ke.columns){const Ee=typeof ke.columns.all=="function"?ke.columns.all():Array.isArray(ke.columns)?ke.columns:[];for(const Re of Ee)Oe(Re&&(Re.field||Re.id||Re.key))}if(!ce.length){const Ee={...r.context.sources,...F(H().spec.sources)?H().spec.sources:{}},Re=typeof ie.source=="string"&&ie.source.startsWith("grid:")?null:ie.source,ze=Re&&Ee[Re];if(ze&&Array.isArray(ze.columns))for(const Ge of ze.columns)Oe(typeof Ge=="string"?Ge:Ge&&(Ge.field||Ge.id));else if(ze&&Array.isArray(ze.rows)&&F(ze.rows[0]))for(const Ge of Object.keys(ze.rows[0]))Oe(Ge)}return ce},k=ie=>{const ce=H(),Oe=Object.keys({...r.context.sources,...ce&&F(ce.spec.sources)?ce.spec.sources:{}}),be=O().filter(ge=>ge.kind==="grid"&&ge.id!==ie).map(ge=>`grid:${ge.id}`);return[...Oe,...be]},V=ie=>ie.kind==="chart"?p(ie.options&&ie.options.type||"bar"):ie.kind==="map"?p(ie.options&&ie.options.type||"markermap"):ne(ie.kind),R=ie=>ie.kind==="chart"?[...new Set([...z,...v()])]:ie.kind==="map"?[...new Set([...o,...v()])]:null,N=(ie,ce)=>{const Oe=I();if(!Oe)return!1;const be=JSON.parse(JSON.stringify(Oe));return ie(be),be.kind==="chart"&&typeof be.source=="string"&&r.pushdown&&r.pushdown.isPushdown(be.source)&&(be.options=F(be.options)?be.options:{},be.options.aggregate===void 0&&(be.options.aggregate="engine")),!!r.commands.run(D,Oe.id,be,ce)},$=ie=>N(ce=>{ce.title=m(ie)},"setTitle"),S=ie=>N(ce=>{ce.source=ie||void 0},"setSource"),Y=(ie,ce,Oe)=>{const be=I(),ge=be&&V(be),ke=ge&&ge.options.find(Ee=>Ee.name===ie)||{name:ie,type:ce};return N(Ee=>{Ee.options=F(Ee.options)?Ee.options:{},i(Ee.options,ie,h(ke,Oe))},"setOption")},Z=(ie,ce,Oe,be)=>{const ge=(ie.entryOptions||[]).find(ke=>ke.name===Oe);return ge?N(ke=>{const Ee=y(F(ke.options)?ke.options:{},b(ie));!Array.isArray(Ee)||!F(Ee[ce])||i(Ee[ce],Oe,h(ge,be))},"setOption"):!1},x=(ie,ce,Oe)=>N(be=>{const ge=y(F(be.options)?be.options:{},b(ie)),ke=ce+Oe;if(!Array.isArray(ge)||ce<0||ce>=ge.length||ke<0||ke>=ge.length)return;const[Ee]=ge.splice(ce,1);ge.splice(ke,0,Ee)},"moveEntry"),ee=(ie,ce,Oe,be)=>de(be)?!1:N(ge=>{ge.options=F(ge.options)?ge.options:{};const ke=ge.options,Ee=m(Oe),Re=b(ie);if(ie.repeatable){let ze=y(ke,Re);if(ze=Array.isArray(ze)?ze.slice():[],!Ee)ce<ze.length&&ze.splice(ce,1);else{const Ge=ze[ce];ie.entryKey?ze[ce]={...F(Ge)?Ge:{},[ie.entryKey]:Ee}:ze[ce]=ie.aggregated?be?{col:Ee,fn:be}:Ee:{field:Ee}}i(ke,Re,ze.length?ze:void 0);return}ie.aggregated&&ie.aggPath?(i(ke,Re,Ee),i(ke,ie.aggPath,Ee&&be?be:void 0)):ie.aggregated?i(ke,Re,Ee?be?{col:Ee,fn:be}:Ee:void 0):i(ke,Re,Ee)},"setRole"),se=ie=>{const ce=I();return ie&&ce&&typeof ce.source=="string"&&r.pushdown?r.pushdown.refusal(ce.source,{aggregation:ie}):""},de=ie=>{const ce=se(ie);return ce?(E.textContent=C("designer.pushdown.refused",{name:ie,reason:ce}),!0):!1},ye=ie=>N(ce=>{ce.options=F(ce.options)?ce.options:{},i(ce.options,"bucket",ie||void 0)},"setBucket"),xe=ie=>{const ce=I();if(!ce||ce.kind!=="chart"&&ce.kind!=="map")return{type:ie,dropped:[]};const Oe=V(ce),be=p(ie).roles,ge=new Map(be.map(Ke=>[Ke.role,Ke])),ke=F(ce.options)?ce.options:{},Ee={type:ie},Re=[];for(const Ke of Oe.roles){const Ie=y(ke,b(Ke));if(!(Ie!=null&&!(Array.isArray(Ie)&&!Ie.length)))continue;const Pe=ge.get(Ke.role);if(!Pe||Pe.accepts!==Ke.accepts){Re.push(Ke.role);continue}if(i(Ee,b(Pe),Ie),Ke.aggPath&&Pe.aggPath){const He=y(ke,Ke.aggPath);He!==void 0&&i(Ee,Pe.aggPath,He)}}for(const Ke of p(ie).options){const Ie=y(ke,Ke.name);Ie!==void 0&&i(Ee,Ke.name,Ie)}N(Ke=>{Ke.options=Ee},"setType");const ze=C(`chart.type.${ie}`),Ge=ze===`chart.type.${ie}`?ie:ze;return E.textContent=Re.length?C("designer.chart.dropped",{type:Ge,roles:Re.map(W).join(", ")}):C("designer.chart.switched",{type:Ge}),f={type:ie,dropped:Re},f},me=(ie,ce)=>{const Oe=t.createElement("label");Oe.className="lattice-designer-field";const be=t.createElement("span");return be.className="lattice-designer-field-label",be.textContent=ie,Oe.appendChild(be),Oe.appendChild(ce),Oe},Ne=(ie,ce,Oe,be)=>{const ge=t.createElement("select");ge.setAttribute("aria-label",ie);for(const ke of Oe){const Ee=t.createElement("option");Ee.value=ke.value,Ee.textContent=ke.label,ke.disabled&&(Ee.disabled=!0,Ee.title=ke.title||""),ke.value===ce&&(Ee.selected=!0),ge.appendChild(Ee)}return ge.value=ce,ge.addEventListener("change",()=>be(ge.value)),ge},Ae=(ie,ce,Oe)=>{const be=t.createElement("button");return be.type="button",be.textContent=ie,be.setAttribute("aria-label",ce),be.addEventListener("click",Oe),be},te=(ie,ce,Oe,be,ge)=>{if(ie.type==="boolean"){const Ee=t.createElement("input");return Ee.type="checkbox",Ee.setAttribute("aria-label",Oe),Ee.checked=ce===void 0?ie.default===!0:ce===!0,Ee.addEventListener("change",()=>ge(Ee.checked)),Ee}if(ie.type==="enum"){const Re=[{value:"",label:ie.default!==void 0?`${C("designer.opt.default")} (${q(ie.name,ie.default,be)})`:C("designer.opt.default")},...ie.values.map((Ge,Ke)=>({value:String(Ke),label:q(ie.name,Ge,be)}))],ze=ie.values.indexOf(ce);return Ne(Oe,ze<0?"":String(ze),Re,Ge=>ge(Ge===""?void 0:ie.values[Number(Ge)]))}const ke=t.createElement("input");if(ke.type=ie.type==="number"?"number":"text",ke.setAttribute("aria-label",Oe),ie.type==="number"){for(const Ee of["min","max","step"])typeof ie[Ee]=="number"&&ke.setAttribute(Ee,String(ie[Ee]));ie.default!==void 0&&ke.setAttribute("placeholder",String(ie.default))}return ie.format&&(ke.dataset.format=ie.format),Array.isArray(ce)?ke.value=ce.join(", "):ce!=null&&(ke.value=String(ce)),ke.addEventListener("change",()=>ge(ke.value)),ke},re=(ie,ce)=>{ie.dataset.dropTarget="true",ie.addEventListener("dragover",Oe=>{Oe.preventDefault()}),ie.addEventListener("drop",Oe=>{Oe.preventDefault();const be=Oe.dataTransfer,ge=be&&typeof be.getData=="function"&&be.getData("text/plain")||"";ge&&ce(ge)})},le=(ie,ce,Oe)=>{const be=g(ie),ke=[{value:"",label:C("designer.field.none")},...be.map($e=>({value:$e,label:$e}))],Ee=[{value:"",label:C("designer.agg.default")},...Oe.aggregations.map($e=>{const Pe=se($e);return{value:$e,label:M(`designer.agg.${$e}`,P($e)),disabled:!!Pe,title:Pe}})],Re=F(ie.options)?ie.options:{},ze=y(Re,b(ce)),Ge=ce.repeatable?Array.isArray(ze)?ze.slice():[]:[ze],Ke=[],Ie=ce.repeatable?Ge.length+1:1;for(let $e=0;$e<Ie;$e++){const Pe=Ge[$e],He=c(Pe),Ye=ce.aggregated&&ce.aggPath?y(Re,ce.aggPath)||"":Pe&&typeof Pe=="object"&&Pe.fn||"",We=ce.repeatable?`${W(ce.role)} ${$e+1}`:W(ce.role),nt=t.createElement("span");nt.className="lattice-designer-role-controls";const ut=Ne(We,He,ke,st=>ee(ce,$e,st,Ye));if(ut.dataset.role=ce.role,ut.addEventListener("keydown",st=>{if(Q&&st.key==="Enter"){st.preventDefault();const dt=Q;Q=null,ee(ce,$e,dt,Ye)}}),nt.appendChild(ut),ce.aggregated&&nt.appendChild(Ne(C("designer.agg",{role:We}),Ye,Ee,st=>ee(ce,$e,He,st))),ce.bucketable){const st=[{value:"",label:C("designer.bucket.none")},...w.map(vt=>({value:vt,label:C(`designer.bucket.${vt}`)}))],dt=y(Re,"bucket")||"";nt.appendChild(Ne(C("designer.bucket.of",{role:We}),dt,st,vt=>ye(vt)))}if(ce.entryOptions&&F(Pe)){for(const st of ce.entryOptions){const dt=`${We} ${oe(st.name,"col")}`,vt=te(st,y(Pe,st.name),dt,"col",St=>Z(ce,$e,st.name,St));vt.dataset.option=st.name,nt.appendChild(vt)}if(ce.orderable){const st=Ae("↑",C("designer.move.earlier",{item:`${We} (${He})`}),()=>x(ce,$e,-1)),dt=Ae("↓",C("designer.move.later",{item:`${We} (${He})`}),()=>x(ce,$e,1));st.disabled=$e===0,dt.disabled=$e>=Ge.length-1,nt.appendChild(st),nt.appendChild(dt)}}const ht=me(We,nt);re(ht,st=>ee(ce,$e,st,Ye)),Ke.push(ht)}return Ke},pe=ie=>{if(ie.kind!=="grid"&&ie.kind!=="chart"||!r.filters)return null;const ce=r.getState(),Oe=F(ce.panels)&&F(ce.panels[ie.id])?ce.panels[ie.id]:null,be=Oe&&F(Oe.clickFilter)?Oe.clickFilter:null,ge=O().filter(Ie=>Ie.id!==ie.id&&Ie.kind!=="html"),ke=g(ie),Ee=be&&typeof be.on=="string"?be.on:ke[0]||"",Re=be?be.targets==="all"?"all":"chosen":"none",ze=Be(C("designer.clickFilter")),Ge=(Ie,$e)=>{if(Ie==="none"){r.filters.setClickFilter(ie.id,null);return}r.filters.setClickFilter(ie.id,{targets:Ie==="all"?"all":Array.isArray($e)?$e:[],on:Ee})},Ke=[{value:"none",label:C("designer.clickFilter.none")},{value:"all",label:C("designer.clickFilter.all")},{value:"chosen",label:C("designer.clickFilter.chosen")}];if(ze.appendChild(me(C("designer.clickFilter"),Ne(C("designer.clickFilter"),Re,Ke,Ie=>Ge(Ie,be&&Array.isArray(be.targets)?be.targets:[])))),Re!=="none"&&ke.length&&ze.appendChild(me(C("designer.clickFilter.on"),Ne(C("designer.clickFilter.on"),Ee,ke.map(Ie=>({value:Ie,label:Ie})),Ie=>r.filters.setClickFilter(ie.id,{targets:Re==="all"?"all":be&&Array.isArray(be.targets)?be.targets:[],on:Ie})))),Re==="chosen"&&ge.length){const Ie=t.createElement("div");Ie.className="lattice-designer-clickfilter-targets";for(const $e of ge){const Pe=t.createElement("label"),He=t.createElement("input");He.type="checkbox",He.checked=!!(be&&Array.isArray(be.targets)&&be.targets.includes($e.id)),He.addEventListener("change",()=>{const Ye=new Set(be&&Array.isArray(be.targets)?be.targets:[]);He.checked?Ye.add($e.id):Ye.delete($e.id),r.filters.setClickFilter(ie.id,{targets:[...Ye],on:Ee})}),Pe.appendChild(He),Pe.appendChild(t.createTextNode(` ${$e.title||$e.id}`)),Ie.appendChild(Pe)}ze.appendChild(Ie)}return ze},we=(ie,ce)=>{const Oe=y(F(ie.options)?ie.options:{},ce.name),be=oe(ce.name),ge=te(ce,Oe,be,"opt",ke=>Y(ce.name,ce.type,ke));return ge.dataset.option=ce.name,me(be,ge)},je=ie=>{const ce=Be(C("designer.section.fields")),Oe=t.createElement("ul");Oe.className="lattice-designer-fields",Oe.setAttribute("aria-label",C("designer.section.fields"));for(const be of g(ie)){const ge=t.createElement("li"),ke=Ae(be,C("designer.field.pick",{field:be}),()=>{Q=Q===be?null:be,E.textContent=Q?C("designer.field.picked",{field:be}):"",Ue()});ke.className="lattice-designer-field-item",ke.draggable=!0,ke.setAttribute("draggable","true"),ke.setAttribute("aria-pressed",Q===be?"true":"false"),ke.dataset.field=be,ke.addEventListener("dragstart",Ee=>{const Re=Ee.dataTransfer;Re&&typeof Re.setData=="function"&&(Re.setData("text/plain",be),Re.effectAllowed="copy")}),ke.addEventListener("keydown",Ee=>{Ee.key==="Escape"&&Q&&(Q=null,E.textContent="",Ue())}),ge.appendChild(ke),Oe.appendChild(ge)}return ce.appendChild(Oe),ce},Be=ie=>{const ce=t.createElement("div");ce.className="lattice-designer-section";const Oe=t.createElement("h3");return Oe.className="lattice-designer-section-title",Oe.textContent=ie,ce.appendChild(Oe),ce},Ue=()=>{if(e)return;const ie=O();ie.some(Ie=>Ie.id===a)||(a=ie.length?ie[0].id:null);const ce=t.activeElement,Oe=ce&&d.contains(ce)?qe(ce):null;[...d.children].forEach(Ie=>{Ie!==E&&Ie.remove()});const be=Ne(C("designer.prop.widget"),a||"",ie.map(Ie=>({value:Ie.id,label:Ie.title||Ie.id})),Ie=>{a=Ie||null,Ue()});d.appendChild(me(C("designer.prop.widget"),be));const ge=I();if(!ge){const Ie=t.createElement("p");Ie.className="lattice-designer-properties-empty",Ie.textContent=C("designer.properties.empty"),d.appendChild(Ie);return}const ke=t.createElement("input");ke.type="text",ke.setAttribute("aria-label",C("designer.prop.title")),ge.title!=null&&(ke.value=String(ge.title)),ke.addEventListener("change",()=>$(ke.value)),d.appendChild(me(C("designer.prop.title"),ke));const Ee=[{value:"",label:C("designer.field.none")},...k(ge.id).map(Ie=>({value:Ie,label:Ie}))];d.appendChild(me(C("designer.prop.source"),Ne(C("designer.prop.source"),ge.source||"",Ee,Ie=>S(Ie))));const Re=R(ge);if(Re){const Ie=ge.options&&ge.options.type||Re[0],$e=Re.map(Pe=>{const He=C(`chart.type.${Pe}`);return{value:Pe,label:He===`chart.type.${Pe}`?Pe:He}});d.appendChild(me(C("designer.prop.type"),Ne(C("designer.prop.type"),Ie,$e,Pe=>xe(Pe))))}const ze=V(ge);if(ze&&ze.roles.length){g(ge).length&&d.appendChild(je(ge));const Ie=Be(C("designer.section.data"));for(const $e of ze.roles)for(const Pe of le(ge,$e,ze))Ie.appendChild(Pe);d.appendChild(Ie)}if(r.pushdown&&typeof ge.source=="string"&&r.pushdown.isPushdown(ge.source)){const Ie=r.pushdown.refusals(ge.source,ze?ze.aggregations:[]);if(Ie.length){const $e=Be(C("designer.pushdown.limits"));$e.className+=" lattice-designer-pushdown-limits";const Pe=t.createElement("ul");for(const He of Ie){const Ye=t.createElement("li");Ye.setAttribute("data-refused",`${He.kind}:${He.name}`),Ye.textContent=He.kind==="step"?C("designer.pushdown.refusedStep",{step:He.name,reason:He.reason}):C("designer.pushdown.refused",{name:M(`designer.agg.${He.name}`,P(He.name)),reason:He.reason}),Pe.appendChild(Ye)}$e.appendChild(Pe),d.appendChild($e)}}if(ze&&ze.options.length){const Ie=Be(C("designer.section.format"));for(const $e of ze.options)Ie.appendChild(we(ge,$e));d.appendChild(Ie)}const Ge=pe(ge);Ge&&d.appendChild(Ge);const Ke=(r.dashboard?r.dashboard.problems():[]).filter(Ie=>Ie.id===`dashboard:panel:${ge.id}`);if(Ke.length){const Ie=Be(C("designer.problems"));Ie.setAttribute("role","alert");for(const $e of Ke){const Pe=t.createElement("p");Pe.className="lattice-designer-problem",Pe.textContent=$e.message,Ie.appendChild(Pe)}d.appendChild(Ie)}if(Oe){const Ie=Array.from(d.querySelectorAll("select, input, button")).find($e=>qe($e)===Oe);Ie&&typeof Ie.focus=="function"&&Ie.focus()}},qe=ie=>ie.getAttribute&&ie.getAttribute("aria-label")||null;r.commands.register(D,(ie,ce,Oe,be)=>{const ge=ie.getState(),ke=ge.pages.find(Re=>F(Re)&&Re.id===ge.selectedPageId);if(!ke||!F(ke.spec)||!Array.isArray(ke.spec.panels))return!1;const Ee=ke.spec.panels.findIndex(Re=>F(Re)&&Re.id===ce);return Ee<0?!1:(ke.spec.panels[Ee]=Oe,ie.commit(ge,be||"setProperty"))});const ot=r.on("state",Ue),tt=r.on("mode",Ue),he=r.pushdown?r.pushdown.onChange(Ue):()=>{};return Ue(),{get el(){return d},selectedPanelId(){return a},selectPanel(ie){return O().some(ce=>ce.id===ie)?(a=ie,Ue(),!0):!1},setTitle:$,setSource:S,setOption:Y,setEntryOption:Z,moveEntry:x,editRole:ee,switchType:xe,fields(){const ie=I();return ie?g(ie):[]},get lastSwitch(){return f},refresh:Ue,destroy(){e||(e=!0,ot(),tt(),he(),d.remove())}}}const A=u}),rt("packages/core/src/formula/parse.js",function(s,ae){"use strict";Object.defineProperty(s,"FormulaError",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"tokenise",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"parseFormula",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"referencesOf",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"looksLikeFormula",{enumerable:!0,get:function(){return c}});const ve="num",F="str",l="ref",ue="name",z="op",fe="end",J=["<=",">=","<>","!="],X="+-*/^%(),<>=";class ne extends Error{constructor(b,P){super(b),this.name="FormulaError",this.at=P}}function B(m){const b=[];let P=0;for(;P<m.length;){const u=m[P];if(u===" "||u===" "||u===`
|
|
159
|
-
`||u==="\r"){P++;continue}if(u>="0"&&u<="9"){P=D(m,P,b);continue}if(u==="."&&m[P+1]>="0"&&m[P+1]<="9"){P=D(m,P,b);continue}if(u==='"'||u==="'"){P=o(m,P,b);continue}if(u==="["){const r=m.indexOf("]",P+1);if(r<0)throw new ne("a [column reference] was opened and never closed",P);b.push({kind:l,value:m.slice(P+1,r).trim(),at:P}),P=r+1;continue}if(L(u)){P=w(m,P,b);continue}const A=m.slice(P,P+2);if(J.includes(A)){b.push({kind:z,value:A==="!="?"<>":A,at:P}),P+=2;continue}if(X.includes(u)){b.push({kind:z,value:u,at:P}),P++;continue}throw new ne(`unexpected character ${JSON.stringify(u)}`,P)}return b.push({kind:fe,value:null,at:m.length}),b}function L(m){return/[A-Za-z_À-]/.test(m)}function D(m,b,P){let u=b,A=!1;for(;u<m.length;){const r=m[u];if(r>="0"&&r<="9"){u++;continue}if(r==="."&&!A){A=!0,u++;continue}if((r==="e"||r==="E")&&/[0-9+-]/.test(m[u+1]||"")){for(u+=2;u<m.length&&m[u]>="0"&&m[u]<="9";)u++;break}break}return P.push({kind:ve,value:Number(m.slice(b,u)),at:b}),u}function o(m,b,P){const u=m[b];let A=b+1,r="";for(;A<m.length;){if(m[A]===u){if(m[A+1]===u){r+=u,A+=2;continue}return P.push({kind:F,value:r,at:b}),A+1}r+=m[A],A++}throw new ne("a string was opened and never closed",b)}function w(m,b,P){let u=b;for(;u<m.length&&/[A-Za-z0-9_.À-]/.test(m[u]);)u++;const A=m.slice(b,u);let r=u;for(;r<m.length&&m[r]===" ";)r++;return P.push({kind:m[r]==="("?ue:l,value:A,at:b}),u}const y={"=":1,"<>":1,"<":1,"<=":1,">":1,">=":1,"+":2,"-":2,"*":3,"/":3,"^":4};function i(m){const b=String(m??"").replace(/^\s*=/,"");if(!b.trim())throw new ne("the formula is empty");const P=B(b);let u=0;const A=()=>P[u],r=()=>P[u++],j=n=>{const t=A();if(t.kind!==z||t.value!==n)throw new ne(`expected ${JSON.stringify(n)}`,t.at);u++},C=n=>{let t=G();for(;;){const a=A();if(a.kind!==z)break;const e=y[a.value];if(!e||e<n)break;u++;const f=C(a.value==="^"?e:e+1);t={kind:"bin",op:a.value,left:t,right:f}}return t},G=()=>{const n=A();return n.kind===z&&(n.value==="-"||n.value==="+")?(u++,{kind:"unary",op:n.value,arg:G()}):_()},_=()=>{let n=T();for(;A().kind===z&&A().value==="%";)u++,n={kind:"unary",op:"%",arg:n};return n},T=()=>{const n=r();if(n.kind===ve)return{kind:"num",value:n.value};if(n.kind===F)return{kind:"str",value:n.value};if(n.kind===l)return{kind:"ref",name:n.value};if(n.kind===ue){j("(");const t=[];if(!(A().kind===z&&A().value===")"))for(;;){if(t.push(C(1)),A().kind===z&&A().value===","){u++;continue}break}return j(")"),{kind:"call",name:String(n.value).toUpperCase(),args:t}}if(n.kind===z&&n.value==="("){const t=C(1);return j(")"),t}throw n.kind===fe?new ne("the formula ends unexpectedly",n.at):new ne(`unexpected ${JSON.stringify(n.value)}`,n.at)},p=C(1),v=A();if(v.kind!==fe)throw new ne(`unexpected ${JSON.stringify(v.value)}: is an operator missing?`,v.at);return p}function h(m){const b=new Set,P=u=>{if(!(!u||typeof u!="object")){if(u.kind==="ref"){b.add(String(u.name));return}if(u.kind==="bin"){P(u.left),P(u.right);return}if(u.kind==="unary"){P(u.arg);return}if(u.kind==="call")for(const A of u.args)P(A)}};return P(m),[...b]}function c(m){return typeof m=="string"&&/^\s*=/.test(m)&&m.trim()!=="="}}),rt("packages/core/src/formula/evaluate.js",function(s,ae){"use strict";Object.defineProperty(s,"FUNCTIONS",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"evaluateAst",{enumerable:!0,get:function(){return D}});const F=ae("packages/core/src/formula/parse.js").FormulaError;function l(o){if(o==null||o==="")return 0;if(typeof o=="boolean")return o?1:0;if(o instanceof Date)return o.getTime();const w=typeof o=="number"?o:Number(String(o).replace(/[,\s]/g,""));if(!Number.isFinite(w))throw new F(`${JSON.stringify(o)} is not a number`);return w}function ue(o){return o==null?"":String(o)}function z(o){if(typeof o=="boolean")return o;if(o==null||o==="")return!1;if(typeof o=="number")return o!==0;const w=String(o).trim().toLowerCase();return w==="false"||w==="no"||w==="0"?!1:w!==""}function fe(o){const w=[];for(const y of o){if(Array.isArray(y)){for(const i of y)i!=null&&i!==""&&w.push(l(i));continue}y==null||y===""||w.push(l(y))}return w}function J(o,w){const y=10**w,i=o*y;return Math.sign(i)*Math.round(Math.abs(i)+Number.EPSILON*Math.abs(i))/y}function X(o,w){if(!o.length)return 0;const y=o.slice().sort((m,b)=>m-b),i=(y.length-1)*Math.min(1,Math.max(0,w)),h=Math.floor(i),c=Math.ceil(i);return h===c?y[h]:y[h]+(i-h)*(y[c]-y[h])}function ne(o,w){let y=0,i=0,h=0;for(const m of o){y++;const b=m-i;i+=b/y,h+=b*(m-i)}const c=w?y-1:y;return c>0?Math.sqrt(h/c):0}const B={SUM:o=>fe(o).reduce((w,y)=>w+y,0),AVERAGE:o=>{const w=fe(o);return w.length?w.reduce((y,i)=>y+i,0)/w.length:0},MIN:o=>{const w=fe(o);return w.length?Math.min(...w):0},MAX:o=>{const w=fe(o);return w.length?Math.max(...w):0},COUNT:o=>fe(o).length,PRODUCT:o=>fe(o).reduce((w,y)=>w*y,1),ROUND:o=>J(l(o[0]),o.length>1?l(o[1]):0),ROUNDDOWN:o=>{const w=10**(o.length>1?l(o[1]):0),y=l(o[0])*w;return(y<0?Math.ceil(y):Math.floor(y))/w},ROUNDUP:o=>{const w=10**(o.length>1?l(o[1]):0),y=l(o[0])*w;return(y<0?Math.floor(y):Math.ceil(y))/w},ABS:o=>Math.abs(l(o[0])),FLOOR:o=>Math.floor(l(o[0])),CEILING:o=>Math.ceil(l(o[0])),SQRT:o=>Math.sqrt(l(o[0])),POWER:o=>l(o[0])**l(o[1]),MOD:o=>{const w=l(o[1]);if(w===0)throw new F("MOD by zero");return(l(o[0])%w+w)%w},IF:o=>z(o[0])?o[1]:o.length>2?o[2]:!1,AND:o=>o.every(z),OR:o=>o.some(z),NOT:o=>!z(o[0]),COALESCE:o=>o.find(w=>w!=null&&w!=="")??null,CONCAT:o=>o.map(ue).join(""),LEN:o=>ue(o[0]).length,UPPER:o=>ue(o[0]).toUpperCase(),LOWER:o=>ue(o[0]).toLowerCase(),TRIM:o=>ue(o[0]).trim(),LEFT:o=>ue(o[0]).slice(0,o.length>1?l(o[1]):1),RIGHT:o=>{const w=o.length>1?l(o[1]):1;return w<=0?"":ue(o[0]).slice(-w)},MEDIAN:o=>X(fe(o),.5),PERCENTILE:o=>{const w=l(o[o.length-1]);return X(fe(o.slice(0,-1)),w>1?w/100:w)},QUARTILE1:o=>X(fe(o),.25),QUARTILE3:o=>X(fe(o),.75),STDEV:o=>ne(fe(o),!0),STDEVP:o=>ne(fe(o),!1),VAR:o=>{const w=ne(fe(o),!0);return w*w},VARP:o=>{const w=ne(fe(o),!1);return w*w},COUNTDISTINCT:o=>{const w=new Set;for(const y of o){const i=Array.isArray(y)?y:[y];for(const h of i)h!=null&&h!==""&&w.add(h)}return w.size},IQR:o=>{const w=fe(o);return X(w,.75)-X(w,.25)}};B.AVG=B.AVERAGE,B.CEIL=B.CEILING,B.POW=B.POWER,B.STDEVS=B.STDEV,B.PERCENTILEINC=B.PERCENTILE;function L(o,w){const y=Number(o),i=Number(w);if(o!==null&&o!==""&&w!==null&&w!==""&&Number.isFinite(y)&&Number.isFinite(i))return y<i?-1:y>i?1:0;const c=ue(o).toLowerCase(),m=ue(w).toLowerCase();return c<m?-1:c>m?1:0}function D(o,w={}){const y=typeof w.lookup=="function"?w.lookup:null,i=w.functions?{...B,...w.functions}:B,h=c=>{switch(c.kind){case"num":return c.value;case"str":return c.value;case"ref":{if(!y)throw new F(`there is no column called ${JSON.stringify(c.name)} here`);const m=y(String(c.name));if(m===void 0)throw new F(`there is no column called ${JSON.stringify(c.name)}`);return m}case"unary":{if(c.op==="%")return l(h(c.arg))/100;const m=l(h(c.arg));return c.op==="-"?-m:m}case"bin":{const m=c.op;if(m==="=")return L(h(c.left),h(c.right))===0;if(m==="<>")return L(h(c.left),h(c.right))!==0;if(m==="<")return L(h(c.left),h(c.right))<0;if(m==="<=")return L(h(c.left),h(c.right))<=0;if(m===">")return L(h(c.left),h(c.right))>0;if(m===">=")return L(h(c.left),h(c.right))>=0;const b=l(h(c.left)),P=l(h(c.right));if(m==="+")return b+P;if(m==="-")return b-P;if(m==="*")return b*P;if(m==="^")return b**P;if(m==="/"){if(P===0)throw new F("division by zero");return b/P}throw new F(`unknown operator ${JSON.stringify(m)}`)}case"call":{const m=w.lazy&&w.lazy[c.name];if(typeof m=="function")return m(c.args,h,w);const b=i[c.name];if(typeof b!="function")throw new F(`there is no function called ${c.name}`);return b(c.args.map(h),w)}default:throw new F("the formula could not be read")}};return h(o)}}),rt("packages/core/src/formula/index.js",function(s,ae){"use strict";Object.defineProperty(s,"parseFormula",{enumerable:!0,get:function(){return F}}),Object.defineProperty(s,"referencesOf",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"looksLikeFormula",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"FormulaError",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"tokenise",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"evaluateAst",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"FUNCTIONS",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"rowLookup",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"evaluateFormula",{enumerable:!0,get:function(){return L}});const ve=ae("packages/core/src/formula/parse.js"),F=ve.parseFormula,l=ve.referencesOf,ue=ve.looksLikeFormula,z=ve.FormulaError,fe=ve.tokenise,J=ae("packages/core/src/formula/evaluate.js"),X=J.evaluateAst,ne=J.FUNCTIONS;function B(D){const{grid:o,row:w,data:y}=D||{},i=P=>String(P).toLowerCase().replace(/[\s_-]/g,""),h=o&&o.columns&&typeof o.columns.all=="function"?o.columns.all():[],c=o&&o.permissions,m=c&&typeof c.isReadable=="function"?P=>c.isReadable(P):()=>!0,b=new Set;for(const P of h)m(P)||(b.add(i(P.id)),P.field&&b.add(i(P.field)),P.title&&b.add(i(P.title)));return P=>{const u=i(P);if(b.has(u))throw new z(`"${P}" cannot be read`);for(const A of h)if(i(A.id)===u||A.field&&i(A.field)===u||A.title&&i(A.title)===u)return w&&o.rows&&typeof o.rows.value=="function"?o.rows.value(w.key,A.id):y?y[A.field||A.id]:void 0;if(y&&typeof y=="object"){for(const A of Object.keys(y))if(i(A)===u){if(!m(A))throw new z(`"${P}" cannot be read`);return y[A]}}}}function L(D,o={}){try{const w=F(D);return{ok:!0,value:X(w,{lookup:B(o),functions:o.formulaFunctions}),references:l(w)}}catch(w){return{ok:!1,error:w instanceof z?w.message:"the formula could not be read",at:w instanceof z?w.at:void 0}}}}),rt("packages/modules/designer/calculated.js",function(s,ae){"use strict";Object.defineProperty(s,"PREVIEW_ROWS",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"functionCatalogue",{enumerable:!0,get:function(){return v}}),Object.defineProperty(s,"analyseExpression",{enumerable:!0,get:function(){return d}}),Object.defineProperty(s,"scopeOf",{enumerable:!0,get:function(){return W}}),Object.defineProperty(s,"compileCalculatedField",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(s,"previewExpression",{enumerable:!0,get:function(){return q}}),Object.defineProperty(s,"suggestCompletions",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(s,"calculatedOf",{enumerable:!0,get:function(){return H}}),Object.defineProperty(s,"applyCalculated",{enumerable:!0,get:function(){return O}}),Object.defineProperty(s,"installCalculated",{enumerable:!0,get:function(){return I}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return K}});const F=ae("packages/core/src/internal/util.js").isFunction,l=ae("packages/core/src/formula/index.js"),ue=l.parseFormula,z=l.tokenise,fe=l.evaluateAst,J=l.FormulaError,X=l.FUNCTIONS,B=ae("packages/modules/dashboard/spec.js").isPlain,L=ae("packages/modules/designer/data-panel.js"),D=L.resolveSourceFields,o=L.compileRelationships,y=ae("packages/modules/designer/messages.js").resolveMessages,i="designer.calculated.commit",h=5,c=g=>g==null||g==="";function m(g){if(typeof g=="boolean")return g;if(c(g))return!1;if(typeof g=="number")return g!==0;const k=String(g).trim().toLowerCase();return!(k==="false"||k==="no"||k==="0"||k==="")}function b(g){if(g instanceof Date&&!Number.isNaN(g.getTime()))return g;if(typeof g=="number"&&Number.isFinite(g))return new Date(g);if(typeof g=="string"&&g.trim()){const k=/^(\d{4})-(\d{2})-(\d{2})$/.exec(g.trim()),V=k?new Date(Date.UTC(+k[1],+k[2]-1,+k[3])):new Date(g);if(!Number.isNaN(V.getTime()))return V}throw new J(`${JSON.stringify(g)} is not a date`)}function P(g){if(c(g))return 0;const k=Number(g);if(!Number.isFinite(k))throw new J(`${JSON.stringify(g)} is not a number`);return k}const u=["year","month","week","day","hour","minute","second"],A={week:6048e5,day:864e5,hour:36e5,minute:6e4,second:1e3};function r(g){const k=String(g??"day").toLowerCase().replace(/s$/,"");if(!u.includes(k))throw new J(`unknown unit ${JSON.stringify(g)}; use ${u.join(", ")}`);return k}function j(g){const k=new Date(Date.UTC(g.getUTCFullYear(),g.getUTCMonth(),g.getUTCDate())),V=k.getUTCDay()||7;k.setUTCDate(k.getUTCDate()+4-V);const R=Date.UTC(k.getUTCFullYear(),0,1);return Math.ceil(((k.getTime()-R)/864e5+1)/7)}function C(g,k){return typeof k=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(k.trim())?g.toISOString().slice(0,10):g.toISOString()}const G={ABS:{family:"arithmetic",min:1,max:1,returns:"number",doc:"ABS(x): absolute value"},ROUND:{family:"arithmetic",min:1,max:2,returns:"number",doc:"ROUND(x, places): round half away from zero"},ROUNDDOWN:{family:"arithmetic",min:1,max:2,returns:"number",doc:"ROUNDDOWN(x, places): round towards zero"},ROUNDUP:{family:"arithmetic",min:1,max:2,returns:"number",doc:"ROUNDUP(x, places): round away from zero"},FLOOR:{family:"arithmetic",min:1,max:1,returns:"number",doc:"FLOOR(x): round down"},CEILING:{family:"arithmetic",min:1,max:1,returns:"number",doc:"CEILING(x): round up"},SQRT:{family:"arithmetic",min:1,max:1,returns:"number",doc:"SQRT(x): square root"},POWER:{family:"arithmetic",min:2,max:2,returns:"number",doc:"POWER(x, y): x to the power y"},MOD:{family:"arithmetic",min:2,max:2,returns:"number",doc:"MOD(x, y): remainder"},MIN:{family:"arithmetic",min:1,max:32,returns:"number",doc:"MIN(a, b, …): the smallest"},MAX:{family:"arithmetic",min:1,max:32,returns:"number",doc:"MAX(a, b, …): the largest"},IF:{family:"condition",min:2,max:3,returns:"same",doc:"IF(test, then, else): one of two values"},CASE:{family:"condition",min:2,max:64,returns:"same",doc:"CASE(test1, value1, test2, value2, …, otherwise): the first matching value"},AND:{family:"condition",min:1,max:32,returns:"boolean",doc:"AND(a, b, …): true when all are"},OR:{family:"condition",min:1,max:32,returns:"boolean",doc:"OR(a, b, …): true when any is"},NOT:{family:"condition",min:1,max:1,returns:"boolean",doc:"NOT(x): the negation"},COALESCE:{family:"null",min:1,max:32,returns:"same",doc:"COALESCE(a, b, …): the first value that is not blank"},ISNULL:{family:"null",min:1,max:1,returns:"boolean",doc:"ISNULL(x): true when blank"},YEAR:{family:"date",min:1,max:1,returns:"number",doc:"YEAR(date): the year"},MONTH:{family:"date",min:1,max:1,returns:"number",doc:"MONTH(date): the month, 1 to 12"},DAY:{family:"date",min:1,max:1,returns:"number",doc:"DAY(date): the day of the month"},WEEK:{family:"date",min:1,max:1,returns:"number",doc:"WEEK(date): the ISO week, 1 to 53"},QUARTER:{family:"date",min:1,max:1,returns:"number",doc:"QUARTER(date): the quarter, 1 to 4"},DATEDIFF:{family:"date",min:2,max:3,returns:"number",doc:"DATEDIFF(end, start, unit): whole units from start to end (default day)"},DATEADD:{family:"date",min:2,max:3,returns:"date",doc:"DATEADD(date, amount, unit): the date moved by units (default day)"},CONCAT:{family:"text",min:1,max:32,returns:"text",doc:"CONCAT(a, b, …): joined text"},UPPER:{family:"text",min:1,max:1,returns:"text",doc:"UPPER(text): upper case"},LOWER:{family:"text",min:1,max:1,returns:"text",doc:"LOWER(text): lower case"},TRIM:{family:"text",min:1,max:1,returns:"text",doc:"TRIM(text): without surrounding spaces"},LEN:{family:"text",min:1,max:1,returns:"number",doc:"LEN(text): the length"},LEFT:{family:"text",min:1,max:2,returns:"text",doc:"LEFT(text, n): the first n characters"},RIGHT:{family:"text",min:1,max:2,returns:"text",doc:"RIGHT(text, n): the last n characters"},CONTAINS:{family:"text",min:2,max:2,returns:"boolean",doc:"CONTAINS(text, part): true when text includes part (any case)"},STARTSWITH:{family:"text",min:2,max:2,returns:"boolean",doc:"STARTSWITH(text, part): true when text begins with part (any case)"},ENDSWITH:{family:"text",min:2,max:2,returns:"boolean",doc:"ENDSWITH(text, part): true when text ends with part (any case)"}},_={ISNULL:g=>c(g[0]),YEAR:g=>b(g[0]).getUTCFullYear(),MONTH:g=>b(g[0]).getUTCMonth()+1,DAY:g=>b(g[0]).getUTCDate(),WEEK:g=>j(b(g[0])),QUARTER:g=>Math.floor(b(g[0]).getUTCMonth()/3)+1,DATEDIFF:g=>{const k=b(g[0]),V=b(g[1]),R=r(g[2]);if(R==="year")return k.getUTCFullYear()-V.getUTCFullYear();if(R==="month")return(k.getUTCFullYear()-V.getUTCFullYear())*12+k.getUTCMonth()-V.getUTCMonth();const N=(k.getTime()-V.getTime())/A[R];return N<0?Math.ceil(N):Math.floor(N)},DATEADD:g=>{const k=new Date(b(g[0]).getTime()),V=Math.trunc(P(g[1])),R=r(g[2]);return R==="year"?k.setUTCFullYear(k.getUTCFullYear()+V):R==="month"?k.setUTCMonth(k.getUTCMonth()+V):k.setTime(k.getTime()+V*A[R]),C(k,g[0])},CONTAINS:g=>String(g[0]??"").toLowerCase().includes(String(g[1]??"").toLowerCase()),STARTSWITH:g=>String(g[0]??"").toLowerCase().startsWith(String(g[1]??"").toLowerCase()),ENDSWITH:g=>String(g[0]??"").toLowerCase().endsWith(String(g[1]??"").toLowerCase())},T={};for(const g of Object.keys(G))_[g]?T[g]=_[g]:F(X[g])&&(T[g]=X[g]);const p={IF:(g,k)=>m(k(g[0]))?k(g[1]):g.length>2?k(g[2]):!1,AND:(g,k)=>{for(const V of g)if(!m(k(V)))return!1;return!0},OR:(g,k)=>{for(const V of g)if(m(k(V)))return!0;return!1},COALESCE:(g,k)=>{for(const V of g){const R=k(V);if(!c(R))return R}return null},CASE:(g,k)=>{let V=0;for(;V+1<g.length;V+=2)if(m(k(g[V])))return k(g[V+1]);return V<g.length?k(g[V]):null}};function v(){return Object.keys(G).map(g=>({name:g,family:G[g].family,doc:G[g].doc,returns:G[g].returns}))}const n={number:"number",currency:"number",percent:"number",date:"date",datetime:"datetime",boolean:"boolean",text:"text"},t=g=>String(g).toLowerCase().replace(/[\s_-]/g,"");function a(g,k){const V=Array.from({length:k.length+1},(R,N)=>N);for(let R=1;R<=g.length;R++){let N=V[0];V[0]=R;for(let $=1;$<=k.length;$++){const S=V[$];V[$]=Math.min(V[$]+1,V[$-1]+1,N+(g[R-1]===k[$-1]?0:1)),N=S}}return V[k.length]}function e(g,k){let V,R=1/0;for(const N of k){const $=a(t(g),t(N));$<R&&(V=N,R=$)}return V!==void 0&&R<=Math.max(1,Math.floor(t(g).length/3))?V:void 0}function f(g){const k=[];for(const V of g.fields||[])k.push({name:V.id,field:V,key:t(V.id),alt:V.label?t(V.label):null});for(const[V,R]of Object.entries(g.related||{}))for(const N of R)k.push({name:`${V}.${N.id}`,field:N,source:V,key:t(`${V}.${N.id}`),alt:null});return k}function d(g,k){const V=String(g??""),R=/^\s*=/.exec(V),N=R?R[0].length:0,$=V.slice(N),S=(te,re,le,pe)=>({ok:!1,errors:[{message:te,at:re+N,token:le,...pe?{suggestion:pe}:{}}]});if(!$.trim())return S("the expression is empty",0,"");let Y,Z;try{Y=z($),Z=ue($)}catch(te){const re=te instanceof J&&typeof te.at=="number"?te.at:0,le=te instanceof J?te.message:"the expression could not be read";return S(`${le} at ${re+N}`,re,$.slice(re,re+1))}const x=f(k),ee=Y.filter(te=>te.kind==="ref"),se=Y.filter(te=>te.kind==="name");let de=0,ye=0;const xe=[],me=[],Ne=te=>{switch(te.kind){case"num":return"number";case"str":return"text";case"ref":{const re=ee[de++],le=re?re.at:0,pe=x.find(we=>we.key===t(te.name))||x.find(we=>we.alt&&we.alt===t(te.name));if(!pe){const we=e(String(te.name),x.map(je=>je.name));return xe.push({message:`unknown field ${JSON.stringify(te.name)} at ${le+N}`,at:le+N,token:String(te.name),...we?{suggestion:we}:{}}),"unknown"}return me.push({name:String(te.name),...pe.source?{source:pe.source}:{},field:pe.field.id}),n[pe.field.type]||"text"}case"unary":return Ne(te.arg),"number";case"bin":return Ne(te.left),Ne(te.right),["=","<>","<","<=",">",">="].includes(te.op)?"boolean":"number";case"call":{const re=se[ye++],le=(re?re.at:0)+N,pe=te.args.map(Ne),we=G[te.name];if(!we){const je=e(te.name,Object.keys(G));return xe.push({message:`unknown function ${JSON.stringify(te.name)} at ${le}`,at:le,token:te.name,...je?{suggestion:je}:{}}),"unknown"}if(te.args.length<we.min||te.args.length>we.max){const je=we.min===we.max?`${we.min}`:`${we.min} to ${we.max}`;return xe.push({message:`${te.name} takes ${je} argument${we.max===1?"":"s"}, not ${te.args.length}, at ${le}`,at:le,token:te.name}),"unknown"}if(we.returns==="same"){let je=pe;te.name==="IF"&&(je=pe.slice(1)),te.name==="CASE"&&(je=pe.filter((qe,ot)=>ot%2===1||ot===pe.length-1&&pe.length%2===1));const Be=je.filter(qe=>qe!=="unknown"),Ue=Be[0];return Be.length&&Be.every(qe=>qe===Ue)?Ue:Be.length?"text":"unknown"}return te.name==="DATEADD"?pe[0]==="datetime"?"datetime":"date":we.returns}default:return"unknown"}},Ae=Ne(Z);return xe.length?{ok:!1,errors:xe}:{ok:!0,type:Ae==="unknown"?"text":Ae,ast:Z,references:me}}function E(g,k,V){for(const R of o(g)){if(R.sourceId===k&&R.relatedSourceId===V&&R.type!=="one-to-many")return{local:R.field,foreign:R.relatedField};if(R.sourceId===V&&R.relatedSourceId===k&&R.type==="one-to-many")return{local:R.relatedField,foreign:R.field}}return null}function M(g,k){return fe(g,{lookup:k,functions:T,lazy:p})}function W(g,k,V){const R=B(g.sources)?g.sources:{},N=R[k],$=D(N,g.dashboard).map(Z=>({id:Z.id,label:Z.label,type:Z.type})),S=g.calculated&&g.calculated[k]||[];for(const Z of S){if(Z.id===V)break;const x=d(Z.expression,{fields:$,related:{}});$.some(ee=>ee.id===Z.id)||$.push({id:Z.id,label:Z.label||Z.id,type:x.ok?x.type:"text"})}const Y={};for(const Z of o(g.relationships)){const x=Z.sourceId===k&&Z.type!=="one-to-many"?Z.relatedSourceId:Z.relatedSourceId===k&&Z.type==="one-to-many"?Z.sourceId:null;x&&R[x]&&!Y[x]&&(Y[x]=D(R[x],g.dashboard).map(ee=>({id:ee.id,label:ee.label,type:ee.type})))}return{fields:$,related:Y}}function oe(g,k,V){const R=B(V.sources)?V.sources:{},N=R[k],$=W(V,k,g.id),S=d(g.expression,$);if(!S.ok)return{ok:!1,errors:S.errors};const Y=xe=>({ok:!1,errors:[],refused:xe});if(!B(N))return Y(`there is no source "${k}"`);const Z=g.label||g.id,x={id:g.id,field:g.id,title:Z,type:S.type==="text"?"text":S.type};if(N.kind==="pushdown"){if(S.references.some(Ne=>Ne.source))return Y(`a pushdown source cannot read another source's fields (${S.references.find(Ne=>Ne.source).name}); the join is not pushed`);const xe=N.adapter;if(!xe||!F(xe.translateExpression))return Y(`the adapter for "${k}" cannot translate expressions, and an expression is never computed over one page of a pushdown source`);let me;try{me=xe.translateExpression({expression:String(g.expression).replace(/^\s*=/,""),ast:S.ast,fields:$.fields,source:k,id:g.id})}catch(Ne){return Y(`the adapter for "${k}" could not translate it: ${Ne&&Ne.message?Ne.message:Ne}`)}return!me||me.refused!==void 0||typeof me.expression!="string"?Y(`the adapter for "${k}" cannot translate it${me&&me.refused?`: ${me.refused}`:""}`):{ok:!0,type:S.type,column:x,via:"pushdown",provenance:typeof me.provenance=="string"?me.provenance:`pushed to ${k}'s adapter`}}if(N.kind!=="rows")return Y(`a "${N.kind}" source's rows are not here to compute over; calculated fields need a rows or pushdown source`);const ee=new Map;for(const xe of S.references){if(!xe.source||ee.has(xe.source))continue;const me=R[xe.source];if(!B(me)||me.kind!=="rows"||!Array.isArray(me.rows))return Y(`"${xe.source}" is not an in-memory rows source, so ${xe.name} cannot be looked up`);const Ne=E(V.relationships,k,xe.source);if(!Ne)return Y(`no relationship reaches "${xe.source}" from "${k}"`);let Ae;ee.set(xe.source,{pair:Ne,rows:me.rows,get index(){if(!Ae){Ae=new Map;for(const te of me.rows)B(te)&&!Ae.has(te[Ne.foreign])&&Ae.set(te[Ne.foreign],te)}return Ae}})}const se=[];for(const xe of S.references){const me=xe.source?ee.get(xe.source).pair.local:xe.field;se.includes(me)||se.push(me)}const de=new Map;for(const xe of f($))de.set(xe.key,xe);for(const xe of f($))xe.alt&&!de.has(xe.alt)&&de.set(xe.alt,xe);const ye=xe=>M(S.ast,me=>{const Ne=de.get(t(me));if(!Ne)return null;if(Ne.source){const te=ee.get(Ne.source),re=te.index.get(xe[te.pair.local]);return re&&re[Ne.field.id]!==void 0?re[Ne.field.id]:null}const Ae=xe[Ne.field.id];return Ae===void 0?null:Ae});return x.value={deps:se,pure:!0,compute:xe=>{try{return ye(xe)}catch(me){if(me instanceof J)return null;throw me}}},{ok:!0,type:S.type,column:x,via:"browser",run:ye}}function q(g,k,V,R={}){const N=oe({id:R.before||"__preview",expression:g},k,V);if(!N.ok)return{ok:!1,rows:[],errors:N.errors,...N.refused?{refused:N.refused}:{}};if(N.via==="pushdown")return{ok:!0,type:N.type,rows:[],via:"pushdown",provenance:N.provenance};const $=[],S=W(V,k,R.before).fields,Y=[];for(const Z of V.calculated&&V.calculated[k]||[]){if(Z.id===R.before)break;const x=oe(Z,k,V);x.ok&&x.column.value&&Y.push({id:Z.id,compute:x.column.value.compute})}for(const Z of V.sources[k].rows.slice(0,R.rows||h)){const x={};for(const ee of S)x[ee.id]=Z&&Z[ee.id];for(const ee of Y)x[ee.id]=ee.compute(x);try{const ee=N.run(x);$.push({value:ee===void 0?null:ee})}catch(ee){$.push({value:null,error:ee instanceof J?ee.message:String(ee&&ee.message)})}}return{ok:!0,type:N.type,rows:$,via:"browser"}}function Q(g,k,V){const R=String(g||""),N=Math.max(0,Math.min(Number.isFinite(k)?k:R.length,R.length));let $=N;for(;$>0&&/[A-Za-z0-9_.À-]/.test(R[$-1]);)$--;const Y=R.slice($,N).toLowerCase(),Z=[],x=ee=>!Y||ee.toLowerCase().startsWith(Y)||ee.includes(".")&&ee.toLowerCase().split(".")[1].startsWith(Y);for(const ee of f(V))x(ee.name)&&Z.push({label:ee.name,insert:ee.name,kind:ee.source?"related":"field",type:n[ee.field.type]||"text"});for(const ee of v())Y&&!ee.name.toLowerCase().startsWith(Y)||Z.push({label:ee.name,insert:`${ee.name}(`,kind:"function",type:ee.returns,family:ee.family,doc:ee.doc});return{from:$,to:N,items:Z}}function H(g){const k=g&&B(g.panels)&&B(g.panels.calculated)?g.panels.calculated:{},V={};for(const R of Object.keys(k))Array.isArray(k[R])&&(V[R]=k[R].filter(N=>B(N)&&typeof N.id=="string"&&typeof N.expression=="string"));return V}function O(g,k,V){const R=V.calculated&&V.calculated[g]||[],N={};if(!R.length||!B(k))return{source:k,status:N};const $=[];for(const x of R){const ee=oe(x,g,V);N[x.id]=ee,ee.ok&&$.push(ee)}if(!$.length)return{source:k,status:N};const S=D(k,V.dashboard);let Y=Array.isArray(k.columns)?k.columns.slice():null;if(!Y){if(!S.length)return{source:k,status:N};Y=S.map(x=>({field:x.id,...x.declared?{title:x.label}:{},...x.type==="number"?{type:"number"}:{}}))}const Z={...k,columns:[...Y,...$.map(x=>x.column)]};return k.kind==="rows"&&Array.isArray(k.rows)&&(Z.rows=k.rows.map(x=>{if(!B(x))return x;const ee={...x};for(const se of $)se.column.value&&(ee[se.column.id]=se.column.value.compute(ee));return ee})),Array.isArray(k.fields)&&k.fields.length&&(Z.fields=[...k.fields,...$.map(x=>({id:x.column.id,label:x.column.title,type:x.type==="datetime"?"datetime":x.type}))]),{source:Z,status:N}}function I(g,k={}){const V=y(k&&k.messages),R=g.chrome.ownerDocument,N=g.context.sources;let $=!1,S=null,Y="",Z="",x=null,ee={};const se=()=>({sources:{...N},relationships:g.context.relationships,calculated:H(g.getState()),dashboard:g.dashboard}),de={},ye=new Map;for(const ge of Object.keys(N)){const ke=Object.getOwnPropertyDescriptor(N,ge);!ke||!("value"in ke)||!ke.configurable||(de[ge]=ke.value,Object.defineProperty(N,ge,{enumerable:!0,configurable:!0,get(){if($)return de[ge];const Ee=H(g.getState());if(!Ee[ge]||!Ee[ge].length)return de[ge];const Re=JSON.stringify(Ee),ze=ye.get(ge);if(ze&&ze.sig===Re)return ze.source;const{source:Ge,status:Ke}=O(ge,de[ge],{sources:de,relationships:g.context.relationships,calculated:Ee,dashboard:null});for(const Ie of Object.keys(Ke))ee[`${ge}.${Ie}`]=Ke[Ie];return ye.set(ge,{sig:Re,source:Ge}),Ge},set(Ee){de[ge]=Ee,ye.delete(ge)}}))}const xe=()=>({...se(),sources:{...de}}),me=R.createElement("div");me.className="lattice-designer-calculated",me.setAttribute("role","group"),me.setAttribute("aria-label",V("designer.calc.panel")),Object.assign(me.style,{display:"flex",flexDirection:"column",gap:"0.4em",font:"inherit",color:"var(--lat-chrome-ink, inherit)"});const Ne=R.createElement("div");Ne.className="lattice-designer-calculated__heading",Ne.textContent=V("designer.calc.heading");const Ae=R.createElement("select");Ae.className="lattice-designer-calculated__source",Ae.setAttribute("aria-label",V("designer.calc.source"));const te=R.createElement("input");te.className="lattice-designer-calculated__name",te.setAttribute("aria-label",V("designer.calc.name")),te.placeholder=V("designer.calc.name");const re=R.createElement("textarea");re.className="lattice-designer-calculated__expression",re.setAttribute("aria-label",V("designer.calc.expression")),re.setAttribute("spellcheck","false"),re.placeholder=V("designer.calc.placeholder");const le=R.createElement("ul");le.className="lattice-designer-calculated__suggest",le.setAttribute("role","listbox"),le.setAttribute("aria-label",V("designer.calc.suggestions"));const pe=R.createElement("div");pe.className="lattice-designer-calculated__type",pe.setAttribute("role","status"),pe.setAttribute("aria-live","polite");const we=R.createElement("div");we.className="lattice-designer-calculated__error",we.setAttribute("role","alert");const je=R.createElement("ol");je.className="lattice-designer-calculated__preview",je.setAttribute("aria-label",V("designer.calc.preview"));const Be=R.createElement("button");Be.type="button",Be.className="lattice-designer-calculated__save";const Ue=R.createElement("ul");Ue.className="lattice-designer-calculated__list",Ue.setAttribute("aria-label",V("designer.calc.fields"));for(const ge of[Ne,Ae,te,re,le,pe,we,je,Be,Ue])me.appendChild(ge);(g.rails?g.rails.left.slot("data"):g.chrome).appendChild(me);const qe=()=>Object.keys(de);g.commands.register(i,(ge,ke,Ee)=>{const Re=ge.getState();B(Re.panels)||(Re.panels={});const ze=B(Re.panels.calculated)?{...Re.panels.calculated}:{};for(const Ge of Object.keys(ke))ke[Ge].length?ze[Ge]=ke[Ge]:delete ze[Ge];return Re.panels.calculated=ze,ge.commit(Re,Ee)});const ot=(ge,ke,Ee)=>oe({id:Ee||"__draft",expression:ke},ge,xe()),tt=(ge,ke,Ee)=>{if(!qe().includes(ge))return{ok:!1,errors:[],refused:`there is no source "${ge}"`};const Re=String(ke&&ke.id||"").trim();if(!Re)return{ok:!1,errors:[{message:V("designer.calc.needName"),at:0,token:""}]};const ze=(H(g.getState())[ge]||[]).slice(),Ge=ze.findIndex($e=>$e.id===Re);if(Ge<0&&W(xe(),ge).fields.some($e=>$e.id===Re))return{ok:!1,errors:[{message:V("designer.calc.exists",{id:Re}),at:0,token:Re}]};const Ke={id:Re,...ke.label?{label:String(ke.label)}:{},expression:String(ke.expression==null?"":ke.expression).replace(/^\s*=/,"")},Ie=oe(Ke,ge,{...xe(),calculated:{...H(g.getState()),[ge]:Ge<0?ze:ze.slice(0,Ge)}});return Ie.ok?(Ge<0?ze.push(Ke):ze[Ge]=Ke,g.commands.run(i,{[ge]:ze},Ee),{ok:!0,type:Ie.type,via:Ie.via,...Ie.provenance?{provenance:Ie.provenance}:{}}):Ie},he=()=>{if($)return;const ge=qe();(!S||!ge.includes(S))&&(S=ge[0]||null),Ae.textContent="";for(const Re of ge){const ze=R.createElement("option");ze.value=Re,ze.textContent=Re,Re===S&&(ze.selected=!0),Ae.appendChild(ze)}Ae.value!==S&&S&&(Ae.value=S),te.value=Y,re.value=Z,Be.textContent=V(x?"designer.calc.save":"designer.calc.add");const ke=S&&Z.trim()?q(Z,S,xe(),{before:x||void 0}):null;if(je.textContent="",we.textContent="",pe.textContent="",ke&&ke.ok){pe.textContent=V("designer.calc.type",{type:ke.type}),ke.via==="pushdown"&&(pe.textContent+=` — ${ke.provenance}`);for(const Re of ke.rows){const ze=R.createElement("li");ze.textContent=Re.error?V("designer.calc.rowError",{error:Re.error}):Re.value===null?V("designer.calc.empty"):String(Re.value),je.appendChild(ze)}}else ke&&(we.textContent=ke.refused||ke.errors.map(Re=>Re.message+(Re.suggestion?V("designer.calc.didYouMean",{name:Re.suggestion}):"")).join("; "));re.setAttribute("aria-invalid",ke&&!ke.ok?"true":"false"),le.textContent="";const Ee=typeof re.selectionStart=="number"?re.selectionStart:Z.length;if(S&&Z){const Re=Q(Z,Ee,W(xe(),S,x||void 0));if(Re.to>Re.from)for(const ze of Re.items.slice(0,8)){const Ge=R.createElement("li");Ge.setAttribute("role","option"),Ge.className="lattice-designer-calculated__option",Ge.textContent=ze.kind==="function"?`${ze.label} — ${ze.doc}`:`${ze.label} (${ze.type})`,Ge.addEventListener("mousedown",Ke=>{Ke.preventDefault&&Ke.preventDefault(),Oe.accept(ze)}),le.appendChild(Ge)}}Ue.textContent="";for(const Re of ge)for(const ze of H(g.getState())[Re]||[]){const Ge=R.createElement("li");Ge.className="lattice-designer-calculated__item";const Ke=ee[`${Re}.${ze.id}`]||oe(ze,Re,xe()),Ie=R.createElement("span");Ie.textContent=`${Re}.${ze.id} = ${ze.expression}${Ke.ok?"":` — ${V("designer.calc.refused",{reason:Ke.refused||Ke.errors[0]&&Ke.errors[0].message||""})}`}`;const $e=R.createElement("button");$e.type="button",$e.textContent=V("designer.calc.edit"),$e.setAttribute("aria-label",V("designer.calc.editField",{id:ze.id})),$e.addEventListener("click",()=>Oe.edit(Re,ze.id));const Pe=R.createElement("button");Pe.type="button",Pe.textContent=V("designer.calc.remove"),Pe.setAttribute("aria-label",V("designer.calc.removeField",{id:ze.id})),Pe.addEventListener("click",()=>Oe.remove(Re,ze.id)),Ge.appendChild(Ie),Ge.appendChild($e),Ge.appendChild(Pe),Ue.appendChild(Ge)}};Ae.addEventListener("change",()=>{S=Ae.value,he()}),te.addEventListener("input",()=>{Y=te.value}),re.addEventListener("input",()=>{Z=re.value,he()}),Be.addEventListener("click",()=>{Oe.submit()});let ie=JSON.stringify(H(g.getState()));ie!=="{}"&&g.setGuardrails(g.guardrails&&g.guardrails.value);const ce=g.on("state",()=>{const ge=JSON.stringify(H(g.getState()));ge!==ie&&(ie=ge,ee={},g.setGuardrails(g.guardrails&&g.guardrails.value),g.properties&&F(g.properties.refresh)&&g.properties.refresh()),he()}),Oe={get el(){return me},list(ge){const ke=H(g.getState());return ge===void 0?ke:ke[ge]||[]},add(ge,ke){return tt(ge,ke,"addCalculated")},update(ge,ke,Ee){const Re=(H(g.getState())[ge]||[]).find(ze=>ze.id===ke);return Re?tt(ge,{...Re,...Ee,id:ke},"updateCalculated"):{ok:!1,errors:[],refused:`there is no calculated field "${ke}" on "${ge}"`}},remove(ge,ke){const Ee=H(g.getState())[ge]||[];return Ee.some(Re=>Re.id===ke)?(g.commands.run(i,{[ge]:Ee.filter(Re=>Re.id!==ke)},"removeCalculated"),!0):!1},analyse(ge,ke){const Ee=d(ke,W(xe(),ge));return Ee.ok?{ok:!0,type:Ee.type,references:Ee.references}:Ee},preview(ge,ke){return q(ke,ge,xe())},suggest(ge,ke,Ee){return Q(ke,Ee===void 0?String(ke).length:Ee,W(xe(),ge))},status(ge,ke){const Ee=(H(g.getState())[ge]||[]).find(ze=>ze.id===ke);if(!Ee)return null;const Re=oe(Ee,ge,xe());return Re.ok?{ok:!0,type:Re.type,via:Re.via,...Re.provenance?{provenance:Re.provenance}:{}}:Re},setSource(ge){S=ge,he()},setExpression(ge,ke){Z=String(ge),ke!==void 0&&(Y=String(ke)),he()},edit(ge,ke){const Ee=(H(g.getState())[ge]||[]).find(Re=>Re.id===ke);return Ee?(S=ge,Y=Ee.id,Z=Ee.expression,x=Ee.id,he(),!0):!1},accept(ge){const ke=typeof re.selectionStart=="number"?re.selectionStart:Z.length,Ee=Q(Z,ke,W(xe(),S,x||void 0));Z=Z.slice(0,Ee.from)+ge.insert+Z.slice(Ee.to),he()},submit(){if(!S)return{ok:!1,errors:[],refused:V("designer.calc.noSource")};const ge=x?tt(S,{id:x,expression:Z,label:(H(g.getState())[S]||[]).find(ke=>ke.id===x)?.label},"updateCalculated"):tt(S,{id:Y,expression:Z},"addCalculated");return ge.ok&&(Y="",Z="",x=null),he(),!ge.ok&&ge.errors&&ge.errors.length?we.textContent=ge.errors.map(ke=>ke.message).join("; "):!ge.ok&&ge.refused&&(we.textContent=ge.refused),ge},refresh:he,destroy(){if(!$){$=!0,ce();for(const ge of Object.keys(de))Object.defineProperty(N,ge,{value:de[ge],writable:!0,enumerable:!0,configurable:!0});me.remove()}}},be=g.destroy;return g.destroy=()=>{Oe.destroy(),be.call(g)},he(),Oe}const K=I}),rt("packages/modules/designer/derived.js",function(s,ae){"use strict";Object.defineProperty(s,"STEP_KINDS",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"normaliseStep",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"measureFormat",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"compileJoinStep",{enumerable:!0,get:function(){return b}}),Object.defineProperty(s,"compileDerived",{enumerable:!0,get:function(){return P}}),Object.defineProperty(s,"withDerivedFormats",{enumerable:!0,get:function(){return r}}),Object.defineProperty(s,"lineageText",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"hiddenDerivedIds",{enumerable:!0,get:function(){return C}}),Object.defineProperty(s,"adapterName",{enumerable:!0,get:function(){return G}}),Object.defineProperty(s,"pushdownStepRefusals",{enumerable:!0,get:function(){return _}}),Object.defineProperty(s,"buildCollectSource",{enumerable:!0,get:function(){return p}}),Object.defineProperty(s,"installDerived",{enumerable:!0,get:function(){return v}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return n}});const ve=ae("packages/core/src/internal/util.js"),F=ve.warnOnce,l=ve.isFunction,z=ae("packages/modules/dashboard/spec.js").isPlain,J=ae("packages/modules/designer/data-panel.js").compileRelationships,ne=ae("packages/modules/designer/messages.js").resolveMessages,B=Object.freeze(["filter","group","pivot","join","sort","topN"]),L=Object.freeze(["sum","avg","min","max","count","countDistinct","median","p95","stddev","distinct","first","last"]);function D(t){return typeof t=="string"&&t?t:null}function o(t){if(!z(t))return null;const a=L.includes(t.fn)?t.fn:"sum",e=D(t.of)||void 0;return!e&&a!=="count"?null:{id:D(t.id)||(e?`${e}_${a}`:"count"),of:e,fn:a}}function w(t){if(!z(t)||!B.includes(t.kind))return null;if(t.kind==="filter")return z(t.where)?{kind:"filter",where:t.where}:null;if(t.kind==="group"){const M=(Array.isArray(t.by)?t.by:[t.by]).map(D).filter(Boolean),W=(Array.isArray(t.measures)?t.measures:[]).map(o).filter(Boolean);return M.length?{kind:"group",by:M,measures:W}:null}if(t.kind==="pivot"){const M=(Array.isArray(t.rows)?t.rows:[t.rows]).map(D).filter(Boolean),W=D(t.column),oe=(Array.isArray(t.measures)?t.measures:[t.measure]).map(o).filter(Boolean);return M.length&&W&&oe.length?{kind:"pivot",rows:M,column:W,measures:oe}:null}if(t.kind==="join"){const M=D(t.to);if(!M)return null;const W=z(t.on)?{left:D(t.on.left),right:D(t.on.right)}:null,oe=["one-to-many","one-to-one","many-to-one"].includes(t.cardinality)?t.cardinality:"many-to-one",q=Array.isArray(t.fields)?t.fields.map(D).filter(Boolean):void 0,Q=D(t.as)||void 0;return{kind:"join",to:M,on:W&&W.left&&W.right?W:null,cardinality:oe,fields:q,as:Q}}if(t.kind==="sort"){const M=(Array.isArray(t.by)?t.by:[]).map(W=>z(W)&&D(W.col)?{col:W.col,dir:W.dir==="desc"?"desc":"asc"}:null).filter(Boolean);return M.length?{kind:"sort",by:M}:null}const a=Number.isFinite(t.limit)&&t.limit>0?Math.floor(t.limit):null;if(!a)return null;const e=(Array.isArray(t.by)?t.by:t.by!=null?[t.by]:[]).map(D).filter(Boolean),f=(Array.isArray(t.measures)?t.measures:[]).map(o).filter(Boolean),d=(Array.isArray(t.sort)?t.sort:[]).map(M=>z(M)&&D(M.col)?{col:M.col,dir:M.dir==="desc"?"desc":"asc"}:null).filter(Boolean),E=D(t.per)||void 0;return{kind:"topN",limit:a,by:e,measures:f,sort:d,per:E}}function y(t){return t==="count"?"count":t==="countDistinct"||t==="distinct"?"distinctCount":t}function i(t,a,e){const f=t.pushdown;if(!f||!f.isPushdown(a))return"";if(e.kind==="filter"||e.kind==="sort"||e.kind==="group"||e.kind==="pivot"){const d=f.refusal(a,{step:e.kind});if(d)return d}if(e.kind==="topN")return f.refusal(a,{step:"sort"})||f.refusal(a,{step:"group"});for(const d of Array.isArray(e.measures)?e.measures:[]){const E=z(d)?d.fn||d.agg:null,M=E?f.refusal(a,{aggregation:E}):"";if(M)return M}return""}function h(t){const a=String(t);if(/[eE]/.test(a))return 0;const e=a.indexOf(".");return e===-1?0:a.length-e-1}function c(t){let a=0,e=!1;for(const f of Array.isArray(t)?t:[]){const d=Number(f);Number.isFinite(d)&&(e=!0,a=Math.max(a,h(d)))}return e?Math.min(a,6):null}function m(t,a,e,f){if(!t)return;if(t.fn==="count"||t.fn==="countDistinct"||t.fn==="distinct")return{type:"number",decimals:0,thousandsSeparator:!1};if(a&&a.format!==void 0&&a.format!=="")return a.format;if(e&&e.format!==void 0&&e.format!=="")return e.format;const d=c(f);return d===null?void 0:{type:"number",maxDecimals:d,thousandsSeparator:!1}}function b(t,a,e){const d=J(e).find(W=>W.sourceId===a&&W.relatedSourceId===t.to||W.sourceId===t.to&&W.relatedSourceId===a),E=t.on||(d?d.sourceId===a?{left:d.field,right:d.relatedField}:{left:d.relatedField,right:d.field}:null);if(!E)return{relatedId:t.to,refusal:`join to "${t.to}" needs a declared relationship or an \`on\` key pair`};if(t.cardinality==="one-to-many"){const W={from:t.to,localKey:E.left,foreignKey:E.right,many:!0,as:t.as||t.to};return t.fields&&t.fields.length===1?W.select=t.fields[0]:t.fields&&t.fields.length&&(W.select=t.fields),{collect:W,relatedId:t.to}}const M={with:`grid:${t.to}`,on:{left:E.left,right:E.right}};return t.fields&&t.fields.length&&(M.select=t.fields),{lookup:M,relatedId:t.to}}function P(t,a={}){const e=D(a.fromId),f=(Array.isArray(t)?t:[]).map(w).filter(Boolean),d=[],E=[],M={},W=new Map,oe=a.display===!0,q=new Map;for(const $ of a.columns||[]){const S=$&&($.id||$.field);S!=null&&!q.has(S)&&q.set(S,$)}const Q=$=>{if(!W.has($)){const S=q.get($);W.set($,{field:$,...S&&S.type?{type:S.type}:{}})}return W.get($)},H=$=>{if(!oe)return;const S=$.of,Y=S?q.get(S):void 0,Z=S?(a.sourceColumns||[]).find(ee=>(ee.id||ee.field)===S):void 0,x=S&&a.sourceValues?a.sourceValues[S]:void 0;return m($,Y,Z,x)},O=[],I=[],K=[],g={};let k=null,V=!1;if(!f.some($=>$.kind==="group"||$.kind==="pivot"||$.kind==="topN"&&$.by.length))for(const $ of a.columns||[])$&&($.id||$.field)&&Q($.id||$.field);f.forEach(($,S)=>{if($.kind==="filter"){I.push($.where);return}if($.kind==="group"){$.by.forEach(Y=>{Q(Y).group={enabled:!0,index:O.length},O.push(Y)});for(const Y of $.measures){if(!Y.of)continue;const Z=Q(Y.of);Z.total=y(Y.fn);const x=H(Y);x!==void 0&&(Z.format=x)}return}if($.kind==="pivot"){V=!0,$.rows.forEach((Y,Z)=>{Q(Y).group={enabled:!0,index:Z}}),Q($.column).pivot={enabled:!0,index:0};for(const Y of $.measures){if(!Y.of)continue;const Z=Q(Y.of);Z.total=y(Y.fn);const x=H(Y);x!==void 0&&(Z.format=x)}return}if($.kind==="sort"){$.by.forEach(Y=>K.push(Y));return}if($.kind==="join"){const Y=b($,e,a.relationships);if(Y.refusal){d.push({index:S,name:"join",reason:Y.refusal});return}E.push(Y.relatedId),Y.lookup&&(g.join=Y.lookup,$.fields&&$.fields.forEach(Z=>Q(Z))),Y.collect&&(k=Y.collect,Q(Y.collect.as).type="list");return}if($.by.length){g.groupBy=$.by.length===1?$.by[0]:$.by,g.select={};for(const Y of $.measures)g.select[Y.id]=Y.of?{of:Y.of,fn:Y.fn}:{fn:Y.fn};W.clear(),$.by.forEach(Y=>Q(Y));for(const Y of $.measures){const Z=Q(Y.id);Z.type="number";const x=H(Y);x!==void 0&&(Z.format=x)}}$.sort.length&&(g.sort=$.sort.slice()),g.limit=$.limit,$.per&&(g.limitPer=$.per)});const N={};return I.length&&(N.filters=I.length===1?I[0]:{op:"and",conditions:I}),K.length&&(N.sort=K),Object.keys(N).length&&(M.state=N),V&&(M.pivot={enabled:!0}),W.size&&(M.columns=[...W.values()]),Object.keys(g).length&&(M.source={mode:"derived",...g}),{source:e?`grid:${e}`:void 0,options:M,collect:k,lineage:{from:a.fromLabel||e,related:E},refusals:d}}function u(t,a,e,f){const d=z(e)&&z(e[t])?e[t]:null;let E=null,M=null;if(d){if(Array.isArray(d.fields)){const oe=d.fields.find(q=>z(q)&&String(q.id)===a);oe&&(E={type:oe.type,format:typeof oe.format=="string"?oe.format:void 0})}if(Array.isArray(d.columns)){const oe=d.columns.find(q=>(z(q)?String(q.field||q.id):String(q))===a);z(oe)&&(M={type:oe.type,format:oe.format})}}const W=(Array.isArray(f)?f:[]).find(oe=>z(oe)&&String(oe.id)===t);if(W&&z(W.options)&&Array.isArray(W.options.columns)){const oe=W.options.columns.find(q=>z(q)&&String(q.field||q.id)===a);oe&&(!M||oe.format!==void 0&&oe.format!=="")&&(M={type:oe.type,format:oe.format})}return{field:E,column:M}}function A(t,a,e){const f=z(e)&&z(e[t])?e[t]:null;if(!(!f||!Array.isArray(f.rows)))return f.rows.map(d=>z(d)?d[a]:void 0)}function r(t,a,e){if(!Array.isArray(t))return t;const f=z(a)&&z(a.panels)?a.panels:{},d=z(e)?e:{};let E=!1;const M=t.map(W=>{if(!z(W)||!z(W.options)||!Array.isArray(W.options.columns))return W;const oe=z(f[W.id])&&z(f[W.id].derived)?f[W.id].derived:null;if(!oe)return W;const q=(Array.isArray(oe.steps)?oe.steps:[]).map(w).filter(Boolean);let Q=null;for(const H of q)if(!(H.kind!=="group"&&H.kind!=="pivot"&&H.kind!=="topN"))for(const O of H.measures){const I=H.kind==="topN"?O.id:O.of;if(!I)continue;const K=(Q||W.options.columns).find($=>z($)&&String($.field||$.id)===I);if(!K||K.format!==void 0)continue;const g=O.of||void 0,{field:k,column:V}=g?u(oe.from,g,d,t):{field:null,column:null},R=m(O,k,V,g?A(oe.from,g,d):void 0);if(R===void 0)continue;Q||(Q=W.options.columns.map($=>z($)?{...$}:$));const N=Q.find($=>z($)&&String($.field||$.id)===I);N&&(N.format=R),E=!0}return Q?{...W,options:{...W.options,columns:Q}}:W});return E?M:t}function j(t,a){const e=[a.from,...a.related||[]].filter(Boolean);return`${t} ← ${e.join(" + ")}`}function C(t){const a=new Set;if(!z(t)||!z(t.panels))return a;for(const[e,f]of Object.entries(t.panels))z(f)&&z(f.derived)&&f.derived.hidden&&a.add(e);return a}function G(t){return t&&typeof t.name=="string"&&t.name?t.name:t&&typeof t.type=="string"&&t.type?t.type:null}function _(t,a){const e=[];if(!a)return e;const f=z(a.capabilities)?a.capabilities:{};return(Array.isArray(t)?t:[]).forEach((d,E)=>{if(!z(d))return;const M=G(a)||"adapter";d.kind==="group"&&(!f.group||!l(a.executeGroupLevel))?e.push({index:E,name:"group",reason:`group is not supported by the ${M} engine`}):d.kind==="pivot"&&(!f.pivot||!l(a.executePivotLevel))&&e.push({index:E,name:"pivot",reason:`pivot is not supported by the ${M} engine`})}),e}function T(t){const a=new Set;let e=t;for(;e&&l(e.config)&&!a.has(e);){a.add(e);const f=e.config(),d=z(f)&&z(f.source)?f.source:null;if(d&&l(d.lastPlan))return d;if(d&&d.mode==="derived"&&d.from&&l(d.from.config)){e=d.from;continue}return null}return null}function p(t){const a=t.rowKey||"id",e=t.createDataRouter({key:"__kind",rowKey:a}),f=e.addSource(t.relatedId),d=e.addSource(t.parentId,{join:t.collect});return t.attachTo&&e.attach(t.attachTo,t.parentId),f.load(t.relatedRows.map(E=>({...E,__kind:t.relatedId}))),d.load(t.parentRows.map(E=>({...E,__kind:t.parentId}))),{router:e,parent:d,related:f,destroy:()=>{l(e.destroy)&&e.destroy()}}}function v(t,a={}){const e=ne(a.messages),f=t.commands,d=H=>Array.isArray(H.pages)&&H.pages.find(O=>z(O)&&O.id===H.selectedPageId)||null,E=H=>{const O=t.dataPanel,I=O&&l(O.sources)?O.sources():[],K=H.startsWith("grid:")?H.slice(5):H,g=I.find(k=>k.id===K);return g?g.fields:[]},M=H=>{const I=(z(t.context.sources)?t.context.sources:{})[H];return z(I)&&I.kind==="pushdown"?H:`grid:${H}`},W=(H,O)=>{const I=z(H.panels)?H.panels[O]:null,K=I&&z(I.derived)?I.derived:null,g=d(H);if(!K||!g||!z(g.spec)||!Array.isArray(g.spec.panels))return null;const k=g.spec.panels.find(R=>z(R)&&R.id===O);if(!k)return null;const V=P(K.steps,{fromId:K.from,fromLabel:K.fromLabel,columns:E(K.from),relationships:t.context.relationships});return k.source=M(K.from),k.options=V.options,K.lineage=V.lineage,{refusals:V.refusals,lineage:V.lineage}};f.register("addDerivedGrid",(H,O={})=>{const I=D(O.from);if(!I)return F("designer:derived:from","designer.addDerivedGrid: `from` must be a source or panel id; nothing was added."),null;const K=H.getState(),g=d(K);if(!g)return null;z(g.spec)||(g.spec={panels:[]}),Array.isArray(g.spec.panels)||(g.spec.panels=[]),z(K.panels)||(K.panels={});const k=g.spec.panels.filter(z).map($=>$.id);let V=D(O.id)||`derived-${I}`,R=2;for(;k.includes(V);)V=`derived-${I}-${R++}`;const N=(Array.isArray(O.steps)?O.steps:[]).map(w).filter(Boolean);return g.spec.panels.push({id:V,kind:"grid",title:D(O.title)||V,source:M(I),options:{}}),K.panels[V]={derived:{from:I,fromLabel:D(O.fromLabel)||I,steps:N,hidden:!!O.hidden}},W(K,V),H.commit(K,"addDerivedGrid")?V:null}),f.register("addDerivedStep",(H,O,I)=>{const K=w(I);if(!K)return F(`designer:derived:step:${z(I)?I.kind:typeof I}`,`designer.addDerivedStep: ${JSON.stringify(z(I)?I.kind:I)} is not a filter, group, pivot, join, sort or topN step; nothing was added.`),!1;const g=H.getState(),k=z(g.panels)?g.panels[O]:null;if(!k||!z(k.derived))return!1;const V=i(t,`grid:${k.derived.from}`,K);return V?(F(`designer:derived:pushdown:${K.kind}:${V}`,`designer.addDerivedStep: the ${K.kind} step is refused: ${V}; nothing was added.`),!1):(k.derived.steps=[...Array.isArray(k.derived.steps)?k.derived.steps:[],K],W(g,O),H.commit(g,"addDerivedStep"))}),f.register("removeDerivedStep",(H,O,I)=>{const K=H.getState(),g=z(K.panels)?K.panels[O]:null;return!g||!z(g.derived)||!Array.isArray(g.derived.steps)||I<0||I>=g.derived.steps.length?!1:(g.derived.steps=g.derived.steps.filter((k,V)=>V!==I),W(K,O),H.commit(K,"removeDerivedStep"))}),f.register("moveDerivedStep",(H,O,I,K)=>{const g=H.getState(),k=z(g.panels)?g.panels[O]:null;if(!k||!z(k.derived)||!Array.isArray(k.derived.steps))return!1;const V=k.derived.steps;if(I<0||I>=V.length||K<0||K>=V.length||I===K)return!1;const[R]=V.splice(I,1);return V.splice(K,0,R),W(g,O),H.commit(g,"moveDerivedStep")}),f.register("setDerivedHidden",(H,O,I)=>{const K=H.getState(),g=z(K.panels)?K.panels[O]:null;return!g||!z(g.derived)?!1:(g.derived.hidden=!!I,H.commit(K,"setDerivedHidden"))});const oe=H=>{const O=t.dashboard,I=O&&l(O.panel)?O.panel(H):null,K=T(I&&I.grid),g=K&&l(K.lastPlan)?K.lastPlan():null,k=[],V=[];return g&&((g.grouped?k:V).push("group"),g.pivoted!==void 0&&(g.pivoted?k:V).push("pivot")),{engine:K?G(K.adapter):null,pushed:k,client:V}},q=H=>{const O=t.getState(),I=z(O.panels)?O.panels[H]:null;if(!I||!z(I.derived))return[];const K=t.dashboard,g=K&&l(K.panel)?K.panel(H):null,k=T(g&&g.grid),V=_(I.derived.steps,k&&k.adapter),R=P(I.derived.steps,{fromId:I.derived.from,fromLabel:I.derived.fromLabel,relationships:t.context.relationships});return[...V,...R.refusals]},Q=()=>{const H=t.canvas;if(!H||!l(H.querySelectorAll))return;const O=t.getState(),I=new Set(z(O.panels)?Object.keys(O.panels):[]);for(const K of H.querySelectorAll(".lat-layout__window")){const g=K.getAttribute("data-window-id");if(!g||!I.has(g))continue;const k=oe(g);if(!k.engine){K.removeAttribute("title");continue}K.setAttribute("title",e("designer.derived.engine",{engine:k.engine}))}};return t.on("state",Q),Q(),{compile(H,O){return P(H,O)},steps(H){const O=t.getState(),I=z(O.panels)?O.panels[H]:null;return I&&z(I.derived)&&Array.isArray(I.derived.steps)?I.derived.steps:null},lineage(H){const O=t.getState(),I=z(O.panels)?O.panels[H]:null;if(!I||!z(I.derived))return null;const K=d(O),g=K&&z(K.spec)&&Array.isArray(K.spec.panels)?K.spec.panels.find(R=>z(R)&&R.id===H):null,k=g&&g.title!=null?String(g.title):H,V=z(I.derived.lineage)?I.derived.lineage:P(I.derived.steps,{fromId:I.derived.from,fromLabel:I.derived.fromLabel,relationships:t.context.relationships}).lineage;return j(k,V)},provenance:oe,refusals:q}}const n=v}),rt("packages/modules/designer/assist.js",function(s,ae){"use strict";Object.defineProperty(s,"mountAssist",{enumerable:!0,get:function(){return C}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return G}});const ve=ae("packages/core/src/internal/util.js"),F=ve.warnOnce,l=ve.isFunction,ue=ae("packages/modules/dashboard/spec.js"),z=ue.isPlain,fe=ue.sameSpec,J=ue.copySpec,ne=ae("packages/modules/dashboard/index.js").createDashboard,B=ae("packages/modules/dashboard/propose.js"),L=B.PROPOSE_SYSTEM,D=B.proposalRequest,o=B.parseProposal,w=B.checkProposal,y=B.columnRefs,i=ae("packages/modules/designer/data-panel.js"),h=i.stripDeclaredFields,c=i.resolveSourceFields,m=Object.freeze({createGrid:"LatticeGrid",createHeadlessGrid:"LatticeGrid",createChart:"LatticeGrid",createKPI:"LatticeGridKPI",createCalendar:"LatticeGridCalendar"});function b(_,T){if(l(_[T]))return!0;const p=globalThis,v=p&&p[m[T]];return!!(v&&l(v[T]))}function P(_){const T=[];return b(_,"createGrid")&&T.push("grid"),b(_,"createChart")&&b(_,"createHeadlessGrid")&&T.push("chart"),b(_,"createKPI")&&T.push("kpi"),b(_,"createCalendar")&&T.push("calendar"),b(_,"createChart")&&b(_,"createHeadlessGrid")&&T.push("map"),T.push("html"),T}function u(_){if(l(_))return{ask:_,sendSampleRows:0};if(z(_)&&l(_.ask)){const T=_.sendSampleRows;return{ask:_.ask,sendSampleRows:Number.isFinite(T)&&T>0?Math.max(0,Math.floor(T)):0}}return{ask:null,sendSampleRows:0}}function A(_,T){return z(_)&&_.kind==="rows"&&Array.isArray(_.rows)?_.rows.slice(0,T):[]}const r=()=>({added:[],changed:[],removed:[]});function j(_,T){const p=new Map(_.filter(z).map(e=>[e.id,e])),v=new Map(T.filter(z).map(e=>[e.id,e])),n=[],t=[];for(const e of T){if(!z(e)||typeof e.id!="string")continue;const f=p.get(e.id);f===void 0?n.push(e.id):fe(f,e)||t.push(e.id)}const a=[];for(const e of _)z(e)&&typeof e.id=="string"&&!v.has(e.id)&&a.push(e.id);return{added:n,changed:t,removed:a}}function C(_,{doc:T,t:p,factories:v}){let n=!1,t=null,a=null,e=null,f=null;const d=T.createElement("div");d.className="lattice-designer-assist",d.setAttribute("role","region"),d.setAttribute("aria-label",p("designer.assist")),Object.assign(d.style,{display:"flex",flexDirection:"column",gap:"0.5em",font:"inherit",color:"var(--lat-chrome-ink, inherit)"});const E=T.createElement("form");E.className="lattice-designer-assist__form",Object.assign(E.style,{display:"flex",gap:"0.4em"});const M=T.createElement("input");M.type="text",M.className="lattice-designer-assist__input",M.setAttribute("aria-label",p("designer.assist.prompt")),M.placeholder=p("designer.assist.placeholder"),Object.assign(M.style,{flex:"1 1 auto",minWidth:"0"});const W=T.createElement("button");W.type="submit",W.className="lattice-designer-button",W.textContent=p("designer.assist.propose"),E.appendChild(M),E.appendChild(W),d.appendChild(E);const oe=T.createElement("ul");oe.className="lattice-designer-assist__problems",oe.setAttribute("aria-label",p("designer.assist.problems")),Object.assign(oe.style,{margin:"0",paddingInlineStart:"1.2em",display:"flex",flexDirection:"column",gap:"0.25em"}),d.appendChild(oe),(_.rails?_.rails.left.slot("assist"):_.chrome).appendChild(d);const q=()=>{const Z=z(_.context.sources)?_.context.sources:{},x=_.getState(),ee=Array.isArray(x.pages)?x.pages.find(de=>z(de)&&de.id===x.selectedPageId):null,se=ee&&z(ee.spec)&&z(ee.spec.sources)?ee.spec.sources:{};return{...Z,...se}},Q=()=>{const Z=_.getState();return Array.isArray(Z.pages)&&Z.pages.find(x=>z(x)&&x.id===Z.selectedPageId)||null},H=()=>{const Z=_.guardrails,x=q(),ee=[],se=[];let de=null;for(const xe of Object.keys(x)){if(!Z.allowsSource(xe))continue;const me=x[xe],Ne=c(me,_.dashboard).filter(Ae=>Z.allowsField(xe,Ae.id));if(Ne.length){de===null&&(de=xe),ee.push({id:xe,kind:z(me)?me.kind:void 0});for(const Ae of Ne)se.push({source:xe,id:Ae.id,label:Ae.label,type:Ae.type})}}const ye=se.filter(xe=>xe.source===de).map(xe=>({id:xe.id,type:xe.type}));return{primary:de,sources:ee,fields:se,columns:ye,merged:x}},O=()=>{a&&(a.destroy(),a=null),e&&(e.remove(),e=null,f=null)},I=()=>{if(oe.textContent="",!!t)for(const Z of t.warnings){const x=T.createElement("li");x.textContent=Z,oe.appendChild(x)}},K=()=>{const Z=t.spec,x=(Array.isArray(Z.panels)?Z.panels:[]).map(de=>J(de)),ee=new Map((Q()&&z(Q().spec)&&Array.isArray(Q().spec.panels)?Q().spec.panels:[]).filter(z).map(de=>[de.id,de]));for(const de of t.diff.removed){const ye=ee.get(de),xe=z(ye)&&typeof ye.title=="string"&&ye.title?ye.title:de;x.push({id:de,kind:"html",title:xe,options:{text:p("designer.assist.removed",{title:xe})}})}return{...J(Z),panels:x}},g=()=>{if(!f)return;const Z=f.querySelectorAll(".lat-layout__window"),x=(ee,se)=>{const de=[...Z].find(ye=>ye.getAttribute("data-window-id")===String(ee));de&&de.setAttribute("data-assist",se)};for(const ee of t.diff.added)x(ee,"added");for(const ee of t.diff.changed)x(ee,"changed");for(const ee of t.diff.removed)x(ee,"removed")},k=()=>{if(O(),!t)return;e=T.createElement("div"),e.className="lattice-designer-assist-preview",e.setAttribute("role","region"),e.setAttribute("aria-label",p("designer.assist.preview"));const Z=T.createElement("style");Z.textContent=[".lattice-designer-assist-preview{position:absolute;inset:0;display:flex;flex-direction:column;background:var(--lattice-surface,#fff);z-index:5}",".lattice-designer-assist-preview__bar{display:flex;align-items:center;gap:calc(var(--lattice-space,4px)*2);padding:var(--lattice-space,4px);flex:0 0 auto;border-bottom:var(--lattice-border-width,1px) solid var(--lattice-border-color)}",".lattice-designer-assist-preview__title{font-weight:var(--lattice-header-font-weight,600);flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",".lattice-designer-assist-preview__body{flex:1 1 auto;min-height:0;position:relative;overflow:hidden}",'.lattice-designer-assist-preview [data-assist="added"]{outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:2px}','.lattice-designer-assist-preview [data-assist="changed"]{outline:var(--lattice-focus-width,2px) dashed var(--lattice-foreground);outline-offset:2px}','.lattice-designer-assist-preview [data-assist="removed"]{opacity:0.5;outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:2px}'].join(`
|
|
160
|
-
`),e.appendChild(
|
|
272
|
+
.lattice-designer .lattice-designer-tool:disabled{opacity:.45;cursor:default}`,(ie.head||ie.documentElement).appendChild(W)}function fe(ie,W){for(let L=ie;L&&L!==W;L=L.parentNode){const _=L.tagName?String(L.tagName).toLowerCase():"";if(_==="input"||_==="textarea"||_==="select"||L.isContentEditable||L.classList&&L.classList.contains("lattice"))return!0}return!1}function J(ie,W,L,_){const i=ie.createElement("button");return i.type="button",i.className="lattice-designer-tool",i.textContent=L,i.setAttribute("aria-label",W),i.addEventListener("click",()=>{_()}),i}function Q(ie){const{chrome:W,root:L,doc:_,t:i,undo:v,redo:k,canUndo:r,canRedo:m}=ie;z(_);const c=_.createElement("div");c.className="lattice-designer-tools";const b=J(_,i("designer.undo"),"↶",v),y=J(_,i("designer.redo"),"↷",k);c.appendChild(b),c.appendChild(y),(ie.topbar||W).appendChild(c);const P=()=>{b.disabled=!r(),y.disabled=!m()};P();const u=d=>{if(!d||!(d.ctrlKey||d.metaKey))return;const w=typeof d.key=="string"?d.key.toLowerCase():"";let G;if(w==="z"&&!d.shiftKey)G=v;else if(w==="z"&&d.shiftKey||w==="y")G=k;else return;fe(d.target,L)||G()&&d.preventDefault()};return L.addEventListener("keydown",u),{refresh:P,off:()=>L.removeEventListener("keydown",u)}}}),rt("packages/modules/designer/guardrails.js",function(o,ce){"use strict";Object.defineProperty(o,"PANEL_KINDS",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"FORMATTING_LEVELS",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"PAGE_ACTIONS",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"BASIC_FORMATTING",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"CHART_FAMILIES",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"normaliseGuardrails",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"createGuardrails",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return v}});const F=ce("packages/modules/dashboard/spec.js").isPlain,l=Object.freeze(["grid","chart","kpi","calendar","map","html"]),de=Object.freeze(["full","basic","none"]),z=Object.freeze(["add","remove","rename","reorder"]),fe=Object.freeze(["preset","alignment","wrap"]),J=Object.freeze({bar:Object.freeze(["bar","horizontalBar","waterfall","floatingBar","horizontalFloatingBar","populationPyramid","bullet","combo","pareto"]),line:Object.freeze(["line","step","area","rangeArea"]),scatter:Object.freeze(["scatter","bubble","forest"]),distribution:Object.freeze(["histogram","boxplot","heatmap","qq","ecdf","lorenz","correlogram","control","capability","movingRange"]),hierarchy:Object.freeze(["pie","donut","sunburst","treemap"]),radial:Object.freeze(["radar","gauge"]),time:Object.freeze(["candlestick","ohlc","gantt"]),flow:Object.freeze(["sankey","chord","network","stream","marimekko","violin"]),geo:Object.freeze(["geomap"]),process:Object.freeze(["funnel"])});function Q(k){if(!Array.isArray(k))return null;const r=[...new Set(k.filter(m=>typeof m=="string"&&m!==""))];return r.length?r:null}function ie(k){if(Array.isArray(k))return Q(k);if(F(k)&&Array.isArray(k.families)){const r=new Set;for(const m of Q(k.families)||[]){const c=J[m];if(c)for(const b of c)r.add(b);else r.add(m)}return r.size?[...r]:null}return null}function W(k){return de.includes(k)?{level:k,options:null}:{level:null,options:Q(k)}}function L(k){const r={add:!0,remove:!0,rename:!0,reorder:!0};if(F(k))for(const m of z)typeof k[m]=="boolean"&&(r[m]=k[m]);return r}function _(k){const r=F(k)?k:{};let m=null;if(F(r.fields)){const b={};for(const[y,P]of Object.entries(r.fields)){if(!F(P))continue;const u=Q(P.allow),E=Q(P.deny);(u||E)&&(b[y]=Object.freeze({allow:u,deny:E}))}Object.keys(b).length&&(m=Object.freeze(b))}const c=r.maxWidgetsPerPage;return Object.freeze({sources:Q(r.sources),fields:m,widgets:Q(r.widgets),chartTypes:ie(r.chartTypes),formatting:Object.freeze(W(r.formatting)),pages:Object.freeze(L(r.pages)),calculatedFields:r.calculatedFields!==!1,derivedGrids:r.derivedGrids!==!1,ai:r.ai!==!1,maxWidgetsPerPage:Number.isFinite(c)&&c>=0?c:null})}function i(k){const r=_(k),m=(y,P,u)=>{switch(y){case"source":return r.sources&&!r.sources.includes(P)?"sources":null;case"field":{if(!r.fields)return null;const E=r.fields[P];return E&&(E.deny&&E.deny.includes(u)||E.allow&&!E.allow.includes(u))?"fields":null}case"widget":return r.widgets&&!r.widgets.includes(P)?"widgets":null;case"chartType":return r.chartTypes&&!r.chartTypes.includes(P)?"chartTypes":null;case"formatting":return!r.formatting.level&&!r.formatting.options?null:r.formatting.level==="none"?"formatting":r.formatting.level==="full"?null:r.formatting.level==="basic"?fe.includes(P)?null:"formatting":r.formatting.options.includes(P)?null:"formatting";case"page":return r.pages[P]===!1?"pages":null;case"calculatedFields":return r.calculatedFields?null:"calculatedFields";case"derivedGrids":return r.derivedGrids?null:"derivedGrids";case"ai":return r.ai?null:"ai";default:return null}},c=(y,P,u)=>m(y,P,u)===null;return Object.freeze({get value(){return r},allowsSource:y=>c("source",y),allowsField:(y,P)=>c("field",y,P),allowsWidget:y=>c("widget",y),allowsChartType:y=>c("chartType",y),allowsFormatting:y=>c("formatting",y),allowsPage:y=>c("page",y),allowsCalculatedFields:()=>c("calculatedFields"),allowsDerivedGrids:()=>c("derivedGrids"),allowsAi:()=>c("ai"),widgetLimit:()=>r.maxWidgetsPerPage,refuse:m,restrictPanel:y=>{if(!F(y))return null;const P=y.kind;if(r.widgets&&!r.widgets.includes(P))return"widgets";const u=y.source;if(r.sources&&typeof u=="string"&&u!==""&&!u.startsWith("grid:")&&!r.sources.includes(u))return"sources";if((P==="chart"||P==="map")&&r.chartTypes){const E=y.options,d=F(E)?E.type:void 0;if(typeof d=="string"&&d!==""&&!r.chartTypes.includes(d))return"chartTypes"}return null}})}const v=i}),rt("packages/modules/designer/canvas.js",function(o,ce){"use strict";Object.defineProperty(o,"removeWidgetState",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"addWidgetState",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"wireCanvas",{enumerable:!0,get:function(){return i}});const ke=ce("packages/modules/dashboard/spec.js"),F=ke.isPlain,l=ke.sameSpec,z=ce("packages/modules/designer/messages.js").resolveMessages,fe="lat-layout",J=Object.freeze(["xPos","yPos","xSize","ySize"]),Q=Object.freeze(["grid","chart","kpi","calendar","map","html"]);function ie(v){return!F(v)||!Array.isArray(v.pages)?null:v.pages.find(k=>F(k)&&k.id===v.selectedPageId)||null}function W(v,k){const r=ie(v);if(!r||!F(r.spec)||!Array.isArray(r.spec.panels))return null;const m=r.spec,c=m.panels.findIndex(b=>F(b)&&b.id===k);if(c<0)return null;if(m.panels.splice(c,1),F(m.layout)&&Array.isArray(m.layout.windows)){const b=m.layout.windows.findIndex(y=>F(y)&&y.id===k);b>=0&&m.layout.windows.splice(b,1)}return v}function L(v,k,r){if(!F(k)||k.id==null||String(k.id)==="")return null;const m=ie(v);if(!m)return null;F(m.spec)||(m.spec={panels:[]});const c=m.spec;return Array.isArray(c.panels)||(c.panels=[]),c.panels.some(b=>F(b)&&b.id===k.id)?null:(c.panels.push({...k}),F(r)&&(F(c.layout)||(c.layout={}),Array.isArray(c.layout.windows)||(c.layout.windows=[]),c.layout.windows.push({id:k.id,...r})),v)}function _(v,k){const r=v.getLayout().windows,m=F(k.layout)?JSON.parse(JSON.stringify(k.layout)):k.layout;F(k.layout)||(k.layout={}),Array.isArray(k.layout.windows)||(k.layout.windows=[]);const c=k.layout.windows;for(const b of r){let y=c.find(P=>F(P)&&P.id===b.id);y||(y={id:b.id},c.push(y));for(const P of J)b[P]!==void 0&&(y[P]=b[P])}return!l(m,k.layout)}function i(v){const{layout:k,canvas:r,page:m,emitState:c,removeWidget:b,emit:y,announce:P}=v,u=z(v.messages);let E=null;k.setInteractive({movable:!0,resizable:!0,closable:!0});const d=()=>[...r.querySelectorAll(`.${fe}__window`)],w=e=>d().find(s=>s.getAttribute("data-window-id")===e)||null,G=e=>{const s=m();return!F(s)||!F(s.spec)||!Array.isArray(s.spec.panels)?null:s.spec.panels.find(x=>F(x)&&x.id===e)||null},N=e=>e?Q.includes(e)?u(`designer.kind.${e}`):e.charAt(0).toUpperCase()+e.slice(1):u("designer.kind.panel"),T=(e,s)=>{const x=G(e),S=N(x&&x.kind),B=x&&x.title!=null?String(x.title):e;return u(s?"designer.widget.selected":"designer.widget.name",{kind:S,title:B})},C=()=>{for(const e of d()){const s=e.getAttribute("data-window-id");e.getAttribute("tabindex")==null&&e.setAttribute("tabindex","0"),e.setAttribute("aria-label",T(s,s===E))}},h={selectWidget(e,s){const x=e==null?null:String(e);return x!=null&&!w(x)||(E=k.select(x),C(),y("select",{id:E,panel:E==null?null:G(E),type:"select"}),E!=null&&P(u("a11y.designer.selected",{name:T(E,!1)}))),E},selectedWidget(){return E==null?null:{id:E,panel:G(E)}},dispose(){r.removeEventListener("click",$),r.removeEventListener("keydown",a),n(),t()}};function $(e){const s=e.target&&e.target.closest?e.target.closest(`.${fe}__window`):null;s&&r.contains(s)&&h.selectWidget(s.getAttribute("data-window-id"),"user")}function a(e){if(e.key==="Enter"){const s=e.target&&e.target.classList&&e.target.classList.contains(`${fe}__window`)?e.target:null;s&&(e.preventDefault&&e.preventDefault(),h.selectWidget(s.getAttribute("data-window-id"),"user"));return}if((e.key==="Delete"||e.key==="Del")&&E!=null){const s=e.target&&e.target.tagName;if(s==="INPUT"||s==="TEXTAREA"||e.target&&e.target.isContentEditable)return;e.preventDefault&&e.preventDefault();const x=E,S=T(x,!1);b(x)&&P(u("a11y.designer.removed",{name:S}))}}const n=k.on("layout:changed",e=>{if(e.cause!=="move"&&e.cause!=="resize")return;const s=m();!F(s)||!F(s.spec)||_(k,s.spec)&&c(e.cause)}),t=k.on("window:closed",e=>{b(e.id)});return r.addEventListener("click",$),r.addEventListener("keydown",a),C(),h}}),rt("packages/core/src/formula/parse.js",function(o,ce){"use strict";Object.defineProperty(o,"FormulaError",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"tokenise",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"parseFormula",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"referencesOf",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"looksLikeFormula",{enumerable:!0,get:function(){return c}});const ke="num",F="str",l="ref",de="name",z="op",fe="end",J=["<=",">=","<>","!="],Q="+-*/^%(),<>=";class ie extends Error{constructor(y,P){super(y),this.name="FormulaError",this.at=P}}function W(b){const y=[];let P=0;for(;P<b.length;){const u=b[P];if(u===" "||u===" "||u===`
|
|
273
|
+
`||u==="\r"){P++;continue}if(u>="0"&&u<="9"){P=_(b,P,y);continue}if(u==="."&&b[P+1]>="0"&&b[P+1]<="9"){P=_(b,P,y);continue}if(u==='"'||u==="'"){P=i(b,P,y);continue}if(u==="["){const d=b.indexOf("]",P+1);if(d<0)throw new ie("a [column reference] was opened and never closed",P);y.push({kind:l,value:b.slice(P+1,d).trim(),at:P}),P=d+1;continue}if(L(u)){P=v(b,P,y);continue}const E=b.slice(P,P+2);if(J.includes(E)){y.push({kind:z,value:E==="!="?"<>":E,at:P}),P+=2;continue}if(Q.includes(u)){y.push({kind:z,value:u,at:P}),P++;continue}throw new ie(`unexpected character ${JSON.stringify(u)}`,P)}return y.push({kind:fe,value:null,at:b.length}),y}function L(b){return/[A-Za-z_À-]/.test(b)}function _(b,y,P){let u=y,E=!1;for(;u<b.length;){const d=b[u];if(d>="0"&&d<="9"){u++;continue}if(d==="."&&!E){E=!0,u++;continue}if((d==="e"||d==="E")&&/[0-9+-]/.test(b[u+1]||"")){for(u+=2;u<b.length&&b[u]>="0"&&b[u]<="9";)u++;break}break}return P.push({kind:ke,value:Number(b.slice(y,u)),at:y}),u}function i(b,y,P){const u=b[y];let E=y+1,d="";for(;E<b.length;){if(b[E]===u){if(b[E+1]===u){d+=u,E+=2;continue}return P.push({kind:F,value:d,at:y}),E+1}d+=b[E],E++}throw new ie("a string was opened and never closed",y)}function v(b,y,P){let u=y;for(;u<b.length&&/[A-Za-z0-9_.À-]/.test(b[u]);)u++;const E=b.slice(y,u);let d=u;for(;d<b.length&&b[d]===" ";)d++;return P.push({kind:b[d]==="("?de:l,value:E,at:y}),u}const k={"=":1,"<>":1,"<":1,"<=":1,">":1,">=":1,"+":2,"-":2,"*":3,"/":3,"^":4};function r(b){const y=String(b??"").replace(/^\s*=/,"");if(!y.trim())throw new ie("the formula is empty");const P=W(y);let u=0;const E=()=>P[u],d=()=>P[u++],w=a=>{const n=E();if(n.kind!==z||n.value!==a)throw new ie(`expected ${JSON.stringify(a)}`,n.at);u++},G=a=>{let n=N();for(;;){const t=E();if(t.kind!==z)break;const e=k[t.value];if(!e||e<a)break;u++;const s=G(t.value==="^"?e:e+1);n={kind:"bin",op:t.value,left:n,right:s}}return n},N=()=>{const a=E();return a.kind===z&&(a.value==="-"||a.value==="+")?(u++,{kind:"unary",op:a.value,arg:N()}):T()},T=()=>{let a=C();for(;E().kind===z&&E().value==="%";)u++,a={kind:"unary",op:"%",arg:a};return a},C=()=>{const a=d();if(a.kind===ke)return{kind:"num",value:a.value};if(a.kind===F)return{kind:"str",value:a.value};if(a.kind===l)return{kind:"ref",name:a.value};if(a.kind===de){w("(");const n=[];if(!(E().kind===z&&E().value===")"))for(;;){if(n.push(G(1)),E().kind===z&&E().value===","){u++;continue}break}return w(")"),{kind:"call",name:String(a.value).toUpperCase(),args:n}}if(a.kind===z&&a.value==="("){const n=G(1);return w(")"),n}throw a.kind===fe?new ie("the formula ends unexpectedly",a.at):new ie(`unexpected ${JSON.stringify(a.value)}`,a.at)},h=G(1),$=E();if($.kind!==fe)throw new ie(`unexpected ${JSON.stringify($.value)}: is an operator missing?`,$.at);return h}function m(b){const y=new Set,P=u=>{if(!(!u||typeof u!="object")){if(u.kind==="ref"){y.add(String(u.name));return}if(u.kind==="bin"){P(u.left),P(u.right);return}if(u.kind==="unary"){P(u.arg);return}if(u.kind==="call")for(const E of u.args)P(E)}};return P(b),[...y]}function c(b){return typeof b=="string"&&/^\s*=/.test(b)&&b.trim()!=="="}}),rt("packages/core/src/formula/evaluate.js",function(o,ce){"use strict";Object.defineProperty(o,"FUNCTIONS",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"evaluateAst",{enumerable:!0,get:function(){return _}});const F=ce("packages/core/src/formula/parse.js").FormulaError;function l(i){if(i==null||i==="")return 0;if(typeof i=="boolean")return i?1:0;if(i instanceof Date)return i.getTime();const v=typeof i=="number"?i:Number(String(i).replace(/[,\s]/g,""));if(!Number.isFinite(v))throw new F(`${JSON.stringify(i)} is not a number`);return v}function de(i){return i==null?"":String(i)}function z(i){if(typeof i=="boolean")return i;if(i==null||i==="")return!1;if(typeof i=="number")return i!==0;const v=String(i).trim().toLowerCase();return v==="false"||v==="no"||v==="0"?!1:v!==""}function fe(i){const v=[];for(const k of i){if(Array.isArray(k)){for(const r of k)r!=null&&r!==""&&v.push(l(r));continue}k==null||k===""||v.push(l(k))}return v}function J(i,v){const k=10**v,r=i*k;return Math.sign(r)*Math.round(Math.abs(r)+Number.EPSILON*Math.abs(r))/k}function Q(i,v){if(!i.length)return 0;const k=i.slice().sort((b,y)=>b-y),r=(k.length-1)*Math.min(1,Math.max(0,v)),m=Math.floor(r),c=Math.ceil(r);return m===c?k[m]:k[m]+(r-m)*(k[c]-k[m])}function ie(i,v){let k=0,r=0,m=0;for(const b of i){k++;const y=b-r;r+=y/k,m+=y*(b-r)}const c=v?k-1:k;return c>0?Math.sqrt(m/c):0}const W={SUM:i=>fe(i).reduce((v,k)=>v+k,0),AVERAGE:i=>{const v=fe(i);return v.length?v.reduce((k,r)=>k+r,0)/v.length:0},MIN:i=>{const v=fe(i);return v.length?Math.min(...v):0},MAX:i=>{const v=fe(i);return v.length?Math.max(...v):0},COUNT:i=>fe(i).length,PRODUCT:i=>fe(i).reduce((v,k)=>v*k,1),ROUND:i=>J(l(i[0]),i.length>1?l(i[1]):0),ROUNDDOWN:i=>{const v=10**(i.length>1?l(i[1]):0),k=l(i[0])*v;return(k<0?Math.ceil(k):Math.floor(k))/v},ROUNDUP:i=>{const v=10**(i.length>1?l(i[1]):0),k=l(i[0])*v;return(k<0?Math.floor(k):Math.ceil(k))/v},ABS:i=>Math.abs(l(i[0])),FLOOR:i=>Math.floor(l(i[0])),CEILING:i=>Math.ceil(l(i[0])),SQRT:i=>Math.sqrt(l(i[0])),POWER:i=>l(i[0])**l(i[1]),MOD:i=>{const v=l(i[1]);if(v===0)throw new F("MOD by zero");return(l(i[0])%v+v)%v},IF:i=>z(i[0])?i[1]:i.length>2?i[2]:!1,AND:i=>i.every(z),OR:i=>i.some(z),NOT:i=>!z(i[0]),COALESCE:i=>i.find(v=>v!=null&&v!=="")??null,CONCAT:i=>i.map(de).join(""),LEN:i=>de(i[0]).length,UPPER:i=>de(i[0]).toUpperCase(),LOWER:i=>de(i[0]).toLowerCase(),TRIM:i=>de(i[0]).trim(),LEFT:i=>de(i[0]).slice(0,i.length>1?l(i[1]):1),RIGHT:i=>{const v=i.length>1?l(i[1]):1;return v<=0?"":de(i[0]).slice(-v)},MEDIAN:i=>Q(fe(i),.5),PERCENTILE:i=>{const v=l(i[i.length-1]);return Q(fe(i.slice(0,-1)),v>1?v/100:v)},QUARTILE1:i=>Q(fe(i),.25),QUARTILE3:i=>Q(fe(i),.75),STDEV:i=>ie(fe(i),!0),STDEVP:i=>ie(fe(i),!1),VAR:i=>{const v=ie(fe(i),!0);return v*v},VARP:i=>{const v=ie(fe(i),!1);return v*v},COUNTDISTINCT:i=>{const v=new Set;for(const k of i){const r=Array.isArray(k)?k:[k];for(const m of r)m!=null&&m!==""&&v.add(m)}return v.size},IQR:i=>{const v=fe(i);return Q(v,.75)-Q(v,.25)}};W.AVG=W.AVERAGE,W.CEIL=W.CEILING,W.POW=W.POWER,W.STDEVS=W.STDEV,W.PERCENTILEINC=W.PERCENTILE;function L(i,v){const k=Number(i),r=Number(v);if(i!==null&&i!==""&&v!==null&&v!==""&&Number.isFinite(k)&&Number.isFinite(r))return k<r?-1:k>r?1:0;const c=de(i).toLowerCase(),b=de(v).toLowerCase();return c<b?-1:c>b?1:0}function _(i,v={}){const k=typeof v.lookup=="function"?v.lookup:null,r=v.functions?{...W,...v.functions}:W,m=c=>{switch(c.kind){case"num":return c.value;case"str":return c.value;case"ref":{if(!k)throw new F(`there is no column called ${JSON.stringify(c.name)} here`);const b=k(String(c.name));if(b===void 0)throw new F(`there is no column called ${JSON.stringify(c.name)}`);return b}case"unary":{if(c.op==="%")return l(m(c.arg))/100;const b=l(m(c.arg));return c.op==="-"?-b:b}case"bin":{const b=c.op;if(b==="=")return L(m(c.left),m(c.right))===0;if(b==="<>")return L(m(c.left),m(c.right))!==0;if(b==="<")return L(m(c.left),m(c.right))<0;if(b==="<=")return L(m(c.left),m(c.right))<=0;if(b===">")return L(m(c.left),m(c.right))>0;if(b===">=")return L(m(c.left),m(c.right))>=0;const y=l(m(c.left)),P=l(m(c.right));if(b==="+")return y+P;if(b==="-")return y-P;if(b==="*")return y*P;if(b==="^")return y**P;if(b==="/"){if(P===0)throw new F("division by zero");return y/P}throw new F(`unknown operator ${JSON.stringify(b)}`)}case"call":{const b=v.lazy&&v.lazy[c.name];if(typeof b=="function")return b(c.args,m,v);const y=r[c.name];if(typeof y!="function")throw new F(`there is no function called ${c.name}`);return y(c.args.map(m),v)}default:throw new F("the formula could not be read")}};return m(i)}}),rt("packages/core/src/formula/index.js",function(o,ce){"use strict";Object.defineProperty(o,"parseFormula",{enumerable:!0,get:function(){return F}}),Object.defineProperty(o,"referencesOf",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"looksLikeFormula",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"FormulaError",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"tokenise",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"evaluateAst",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"FUNCTIONS",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"rowLookup",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"evaluateFormula",{enumerable:!0,get:function(){return L}});const ke=ce("packages/core/src/formula/parse.js"),F=ke.parseFormula,l=ke.referencesOf,de=ke.looksLikeFormula,z=ke.FormulaError,fe=ke.tokenise,J=ce("packages/core/src/formula/evaluate.js"),Q=J.evaluateAst,ie=J.FUNCTIONS;function W(_){const{grid:i,row:v,data:k}=_||{},r=P=>String(P).toLowerCase().replace(/[\s_-]/g,""),m=i&&i.columns&&typeof i.columns.all=="function"?i.columns.all():[],c=i&&i.permissions,b=c&&typeof c.isReadable=="function"?P=>c.isReadable(P):()=>!0,y=new Set;for(const P of m)b(P)||(y.add(r(P.id)),P.field&&y.add(r(P.field)),P.title&&y.add(r(P.title)));return P=>{const u=r(P);if(y.has(u))throw new z(`"${P}" cannot be read`);for(const E of m)if(r(E.id)===u||E.field&&r(E.field)===u||E.title&&r(E.title)===u)return v&&i.rows&&typeof i.rows.value=="function"?i.rows.value(v.key,E.id):k?k[E.field||E.id]:void 0;if(k&&typeof k=="object"){for(const E of Object.keys(k))if(r(E)===u){if(!b(E))throw new z(`"${P}" cannot be read`);return k[E]}}}}function L(_,i={}){try{const v=F(_);return{ok:!0,value:Q(v,{lookup:W(i),functions:i.formulaFunctions}),references:l(v)}}catch(v){return{ok:!1,error:v instanceof z?v.message:"the formula could not be read",at:v instanceof z?v.at:void 0}}}}),rt("packages/modules/designer/calculated.js",function(o,ce){"use strict";Object.defineProperty(o,"PREVIEW_ROWS",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"functionCatalogue",{enumerable:!0,get:function(){return $}}),Object.defineProperty(o,"analyseExpression",{enumerable:!0,get:function(){return x}}),Object.defineProperty(o,"scopeOf",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(o,"compileCalculatedField",{enumerable:!0,get:function(){return te}}),Object.defineProperty(o,"previewExpression",{enumerable:!0,get:function(){return q}}),Object.defineProperty(o,"suggestCompletions",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(o,"calculatedOf",{enumerable:!0,get:function(){return U}}),Object.defineProperty(o,"applyCalculated",{enumerable:!0,get:function(){return M}}),Object.defineProperty(o,"installCalculated",{enumerable:!0,get:function(){return R}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return H}});const F=ce("packages/core/src/internal/util.js").isFunction,l=ce("packages/core/src/formula/index.js"),de=l.parseFormula,z=l.tokenise,fe=l.evaluateAst,J=l.FormulaError,Q=l.FUNCTIONS,W=ce("packages/modules/dashboard/spec.js").isPlain,L=ce("packages/modules/designer/data-panel.js"),_=L.resolveSourceFields,i=L.compileRelationships,k=ce("packages/modules/designer/messages.js").resolveMessages,r="designer.calculated.commit",m=5,c=f=>f==null||f==="";function b(f){if(typeof f=="boolean")return f;if(c(f))return!1;if(typeof f=="number")return f!==0;const g=String(f).trim().toLowerCase();return!(g==="false"||g==="no"||g==="0"||g==="")}function y(f){if(f instanceof Date&&!Number.isNaN(f.getTime()))return f;if(typeof f=="number"&&Number.isFinite(f))return new Date(f);if(typeof f=="string"&&f.trim()){const g=/^(\d{4})-(\d{2})-(\d{2})$/.exec(f.trim()),I=g?new Date(Date.UTC(+g[1],+g[2]-1,+g[3])):new Date(f);if(!Number.isNaN(I.getTime()))return I}throw new J(`${JSON.stringify(f)} is not a date`)}function P(f){if(c(f))return 0;const g=Number(f);if(!Number.isFinite(g))throw new J(`${JSON.stringify(f)} is not a number`);return g}const u=["year","month","week","day","hour","minute","second"],E={week:6048e5,day:864e5,hour:36e5,minute:6e4,second:1e3};function d(f){const g=String(f??"day").toLowerCase().replace(/s$/,"");if(!u.includes(g))throw new J(`unknown unit ${JSON.stringify(f)}; use ${u.join(", ")}`);return g}function w(f){const g=new Date(Date.UTC(f.getUTCFullYear(),f.getUTCMonth(),f.getUTCDate())),I=g.getUTCDay()||7;g.setUTCDate(g.getUTCDate()+4-I);const j=Date.UTC(g.getUTCFullYear(),0,1);return Math.ceil(((g.getTime()-j)/864e5+1)/7)}function G(f,g){return typeof g=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(g.trim())?f.toISOString().slice(0,10):f.toISOString()}const N={ABS:{family:"arithmetic",min:1,max:1,returns:"number",doc:"ABS(x): absolute value"},ROUND:{family:"arithmetic",min:1,max:2,returns:"number",doc:"ROUND(x, places): round half away from zero"},ROUNDDOWN:{family:"arithmetic",min:1,max:2,returns:"number",doc:"ROUNDDOWN(x, places): round towards zero"},ROUNDUP:{family:"arithmetic",min:1,max:2,returns:"number",doc:"ROUNDUP(x, places): round away from zero"},FLOOR:{family:"arithmetic",min:1,max:1,returns:"number",doc:"FLOOR(x): round down"},CEILING:{family:"arithmetic",min:1,max:1,returns:"number",doc:"CEILING(x): round up"},SQRT:{family:"arithmetic",min:1,max:1,returns:"number",doc:"SQRT(x): square root"},POWER:{family:"arithmetic",min:2,max:2,returns:"number",doc:"POWER(x, y): x to the power y"},MOD:{family:"arithmetic",min:2,max:2,returns:"number",doc:"MOD(x, y): remainder"},MIN:{family:"arithmetic",min:1,max:32,returns:"number",doc:"MIN(a, b, …): the smallest"},MAX:{family:"arithmetic",min:1,max:32,returns:"number",doc:"MAX(a, b, …): the largest"},IF:{family:"condition",min:2,max:3,returns:"same",doc:"IF(test, then, else): one of two values"},CASE:{family:"condition",min:2,max:64,returns:"same",doc:"CASE(test1, value1, test2, value2, …, otherwise): the first matching value"},AND:{family:"condition",min:1,max:32,returns:"boolean",doc:"AND(a, b, …): true when all are"},OR:{family:"condition",min:1,max:32,returns:"boolean",doc:"OR(a, b, …): true when any is"},NOT:{family:"condition",min:1,max:1,returns:"boolean",doc:"NOT(x): the negation"},COALESCE:{family:"null",min:1,max:32,returns:"same",doc:"COALESCE(a, b, …): the first value that is not blank"},ISNULL:{family:"null",min:1,max:1,returns:"boolean",doc:"ISNULL(x): true when blank"},YEAR:{family:"date",min:1,max:1,returns:"number",doc:"YEAR(date): the year"},MONTH:{family:"date",min:1,max:1,returns:"number",doc:"MONTH(date): the month, 1 to 12"},DAY:{family:"date",min:1,max:1,returns:"number",doc:"DAY(date): the day of the month"},WEEK:{family:"date",min:1,max:1,returns:"number",doc:"WEEK(date): the ISO week, 1 to 53"},QUARTER:{family:"date",min:1,max:1,returns:"number",doc:"QUARTER(date): the quarter, 1 to 4"},DATEDIFF:{family:"date",min:2,max:3,returns:"number",doc:"DATEDIFF(end, start, unit): whole units from start to end (default day)"},DATEADD:{family:"date",min:2,max:3,returns:"date",doc:"DATEADD(date, amount, unit): the date moved by units (default day)"},CONCAT:{family:"text",min:1,max:32,returns:"text",doc:"CONCAT(a, b, …): joined text"},UPPER:{family:"text",min:1,max:1,returns:"text",doc:"UPPER(text): upper case"},LOWER:{family:"text",min:1,max:1,returns:"text",doc:"LOWER(text): lower case"},TRIM:{family:"text",min:1,max:1,returns:"text",doc:"TRIM(text): without surrounding spaces"},LEN:{family:"text",min:1,max:1,returns:"number",doc:"LEN(text): the length"},LEFT:{family:"text",min:1,max:2,returns:"text",doc:"LEFT(text, n): the first n characters"},RIGHT:{family:"text",min:1,max:2,returns:"text",doc:"RIGHT(text, n): the last n characters"},CONTAINS:{family:"text",min:2,max:2,returns:"boolean",doc:"CONTAINS(text, part): true when text includes part (any case)"},STARTSWITH:{family:"text",min:2,max:2,returns:"boolean",doc:"STARTSWITH(text, part): true when text begins with part (any case)"},ENDSWITH:{family:"text",min:2,max:2,returns:"boolean",doc:"ENDSWITH(text, part): true when text ends with part (any case)"}},T={ISNULL:f=>c(f[0]),YEAR:f=>y(f[0]).getUTCFullYear(),MONTH:f=>y(f[0]).getUTCMonth()+1,DAY:f=>y(f[0]).getUTCDate(),WEEK:f=>w(y(f[0])),QUARTER:f=>Math.floor(y(f[0]).getUTCMonth()/3)+1,DATEDIFF:f=>{const g=y(f[0]),I=y(f[1]),j=d(f[2]);if(j==="year")return g.getUTCFullYear()-I.getUTCFullYear();if(j==="month")return(g.getUTCFullYear()-I.getUTCFullYear())*12+g.getUTCMonth()-I.getUTCMonth();const A=(g.getTime()-I.getTime())/E[j];return A<0?Math.ceil(A):Math.floor(A)},DATEADD:f=>{const g=new Date(y(f[0]).getTime()),I=Math.trunc(P(f[1])),j=d(f[2]);return j==="year"?g.setUTCFullYear(g.getUTCFullYear()+I):j==="month"?g.setUTCMonth(g.getUTCMonth()+I):g.setTime(g.getTime()+I*E[j]),G(g,f[0])},CONTAINS:f=>String(f[0]??"").toLowerCase().includes(String(f[1]??"").toLowerCase()),STARTSWITH:f=>String(f[0]??"").toLowerCase().startsWith(String(f[1]??"").toLowerCase()),ENDSWITH:f=>String(f[0]??"").toLowerCase().endsWith(String(f[1]??"").toLowerCase())},C={};for(const f of Object.keys(N))T[f]?C[f]=T[f]:F(Q[f])&&(C[f]=Q[f]);const h={IF:(f,g)=>b(g(f[0]))?g(f[1]):f.length>2?g(f[2]):!1,AND:(f,g)=>{for(const I of f)if(!b(g(I)))return!1;return!0},OR:(f,g)=>{for(const I of f)if(b(g(I)))return!0;return!1},COALESCE:(f,g)=>{for(const I of f){const j=g(I);if(!c(j))return j}return null},CASE:(f,g)=>{let I=0;for(;I+1<f.length;I+=2)if(b(g(f[I])))return g(f[I+1]);return I<f.length?g(f[I]):null}};function $(){return Object.keys(N).map(f=>({name:f,family:N[f].family,doc:N[f].doc,returns:N[f].returns}))}const a={number:"number",currency:"number",percent:"number",date:"date",datetime:"datetime",boolean:"boolean",text:"text"},n=f=>String(f).toLowerCase().replace(/[\s_-]/g,"");function t(f,g){const I=Array.from({length:g.length+1},(j,A)=>A);for(let j=1;j<=f.length;j++){let A=I[0];I[0]=j;for(let D=1;D<=g.length;D++){const p=I[D];I[D]=Math.min(I[D]+1,I[D-1]+1,A+(f[j-1]===g[D-1]?0:1)),A=p}}return I[g.length]}function e(f,g){let I,j=1/0;for(const A of g){const D=t(n(f),n(A));D<j&&(I=A,j=D)}return I!==void 0&&j<=Math.max(1,Math.floor(n(f).length/3))?I:void 0}function s(f){const g=[];for(const I of f.fields||[])g.push({name:I.id,field:I,key:n(I.id),alt:I.label?n(I.label):null});for(const[I,j]of Object.entries(f.related||{}))for(const A of j)g.push({name:`${I}.${A.id}`,field:A,source:I,key:n(`${I}.${A.id}`),alt:null});return g}function x(f,g){const I=String(f??""),j=/^\s*=/.exec(I),A=j?j[0].length:0,D=I.slice(A),p=(Z,re,le,pe)=>({ok:!1,errors:[{message:Z,at:re+A,token:le,...pe?{suggestion:pe}:{}}]});if(!D.trim())return p("the expression is empty",0,"");let se,V;try{se=z(D),V=de(D)}catch(Z){const re=Z instanceof J&&typeof Z.at=="number"?Z.at:0,le=Z instanceof J?Z.message:"the expression could not be read";return p(`${le} at ${re+A}`,re,D.slice(re,re+1))}const O=s(g),X=se.filter(Z=>Z.kind==="ref"),oe=se.filter(Z=>Z.kind==="name");let ue=0,xe=0;const me=[],we=[],Pe=Z=>{switch(Z.kind){case"num":return"number";case"str":return"text";case"ref":{const re=X[ue++],le=re?re.at:0,pe=O.find(he=>he.key===n(Z.name))||O.find(he=>he.alt&&he.alt===n(Z.name));if(!pe){const he=e(String(Z.name),O.map(Me=>Me.name));return me.push({message:`unknown field ${JSON.stringify(Z.name)} at ${le+A}`,at:le+A,token:String(Z.name),...he?{suggestion:he}:{}}),"unknown"}return we.push({name:String(Z.name),...pe.source?{source:pe.source}:{},field:pe.field.id}),a[pe.field.type]||"text"}case"unary":return Pe(Z.arg),"number";case"bin":return Pe(Z.left),Pe(Z.right),["=","<>","<","<=",">",">="].includes(Z.op)?"boolean":"number";case"call":{const re=oe[xe++],le=(re?re.at:0)+A,pe=Z.args.map(Pe),he=N[Z.name];if(!he){const Me=e(Z.name,Object.keys(N));return me.push({message:`unknown function ${JSON.stringify(Z.name)} at ${le}`,at:le,token:Z.name,...Me?{suggestion:Me}:{}}),"unknown"}if(Z.args.length<he.min||Z.args.length>he.max){const Me=he.min===he.max?`${he.min}`:`${he.min} to ${he.max}`;return me.push({message:`${Z.name} takes ${Me} argument${he.max===1?"":"s"}, not ${Z.args.length}, at ${le}`,at:le,token:Z.name}),"unknown"}if(he.returns==="same"){let Me=pe;Z.name==="IF"&&(Me=pe.slice(1)),Z.name==="CASE"&&(Me=pe.filter((qe,ot)=>ot%2===1||ot===pe.length-1&&pe.length%2===1));const Ie=Me.filter(qe=>qe!=="unknown"),Ke=Ie[0];return Ie.length&&Ie.every(qe=>qe===Ke)?Ke:Ie.length?"text":"unknown"}return Z.name==="DATEADD"?pe[0]==="datetime"?"datetime":"date":he.returns}default:return"unknown"}},Fe=Pe(V);return me.length?{ok:!1,errors:me}:{ok:!0,type:Fe==="unknown"?"text":Fe,ast:V,references:we}}function S(f,g,I){for(const j of i(f)){if(j.sourceId===g&&j.relatedSourceId===I&&j.type!=="one-to-many")return{local:j.field,foreign:j.relatedField};if(j.sourceId===I&&j.relatedSourceId===g&&j.type==="one-to-many")return{local:j.relatedField,foreign:j.field}}return null}function B(f,g){return fe(f,{lookup:g,functions:C,lazy:h})}function Y(f,g,I){const j=W(f.sources)?f.sources:{},A=j[g],D=_(A,f.dashboard).map(V=>({id:V.id,label:V.label,type:V.type})),p=f.calculated&&f.calculated[g]||[];for(const V of p){if(V.id===I)break;const O=x(V.expression,{fields:D,related:{}});D.some(X=>X.id===V.id)||D.push({id:V.id,label:V.label||V.id,type:O.ok?O.type:"text"})}const se={};for(const V of i(f.relationships)){const O=V.sourceId===g&&V.type!=="one-to-many"?V.relatedSourceId:V.relatedSourceId===g&&V.type==="one-to-many"?V.sourceId:null;O&&j[O]&&!se[O]&&(se[O]=_(j[O],f.dashboard).map(X=>({id:X.id,label:X.label,type:X.type})))}return{fields:D,related:se}}function te(f,g,I){const j=W(I.sources)?I.sources:{},A=j[g],D=Y(I,g,f.id),p=x(f.expression,D);if(!p.ok)return{ok:!1,errors:p.errors};const se=me=>({ok:!1,errors:[],refused:me});if(!W(A))return se(`there is no source "${g}"`);const V=f.label||f.id,O={id:f.id,field:f.id,title:V,type:p.type==="text"?"text":p.type};if(A.kind==="pushdown"){if(p.references.some(Pe=>Pe.source))return se(`a pushdown source cannot read another source's fields (${p.references.find(Pe=>Pe.source).name}); the join is not pushed`);const me=A.adapter;if(!me||!F(me.translateExpression))return se(`the adapter for "${g}" cannot translate expressions, and an expression is never computed over one page of a pushdown source`);let we;try{we=me.translateExpression({expression:String(f.expression).replace(/^\s*=/,""),ast:p.ast,fields:D.fields,source:g,id:f.id})}catch(Pe){return se(`the adapter for "${g}" could not translate it: ${Pe&&Pe.message?Pe.message:Pe}`)}return!we||we.refused!==void 0||typeof we.expression!="string"?se(`the adapter for "${g}" cannot translate it${we&&we.refused?`: ${we.refused}`:""}`):{ok:!0,type:p.type,column:O,via:"pushdown",provenance:typeof we.provenance=="string"?we.provenance:`pushed to ${g}'s adapter`}}if(A.kind!=="rows")return se(`a "${A.kind}" source's rows are not here to compute over; calculated fields need a rows or pushdown source`);const X=new Map;for(const me of p.references){if(!me.source||X.has(me.source))continue;const we=j[me.source];if(!W(we)||we.kind!=="rows"||!Array.isArray(we.rows))return se(`"${me.source}" is not an in-memory rows source, so ${me.name} cannot be looked up`);const Pe=S(I.relationships,g,me.source);if(!Pe)return se(`no relationship reaches "${me.source}" from "${g}"`);let Fe;X.set(me.source,{pair:Pe,rows:we.rows,get index(){if(!Fe){Fe=new Map;for(const Z of we.rows)W(Z)&&!Fe.has(Z[Pe.foreign])&&Fe.set(Z[Pe.foreign],Z)}return Fe}})}const oe=[];for(const me of p.references){const we=me.source?X.get(me.source).pair.local:me.field;oe.includes(we)||oe.push(we)}const ue=new Map;for(const me of s(D))ue.set(me.key,me);for(const me of s(D))me.alt&&!ue.has(me.alt)&&ue.set(me.alt,me);const xe=me=>B(p.ast,we=>{const Pe=ue.get(n(we));if(!Pe)return null;if(Pe.source){const Z=X.get(Pe.source),re=Z.index.get(me[Z.pair.local]);return re&&re[Pe.field.id]!==void 0?re[Pe.field.id]:null}const Fe=me[Pe.field.id];return Fe===void 0?null:Fe});return O.value={deps:oe,pure:!0,compute:me=>{try{return xe(me)}catch(we){if(we instanceof J)return null;throw we}}},{ok:!0,type:p.type,column:O,via:"browser",run:xe}}function q(f,g,I,j={}){const A=te({id:j.before||"__preview",expression:f},g,I);if(!A.ok)return{ok:!1,rows:[],errors:A.errors,...A.refused?{refused:A.refused}:{}};if(A.via==="pushdown")return{ok:!0,type:A.type,rows:[],via:"pushdown",provenance:A.provenance};const D=[],p=Y(I,g,j.before).fields,se=[];for(const V of I.calculated&&I.calculated[g]||[]){if(V.id===j.before)break;const O=te(V,g,I);O.ok&&O.column.value&&se.push({id:V.id,compute:O.column.value.compute})}for(const V of I.sources[g].rows.slice(0,j.rows||m)){const O={};for(const X of p)O[X.id]=V&&V[X.id];for(const X of se)O[X.id]=X.compute(O);try{const X=A.run(O);D.push({value:X===void 0?null:X})}catch(X){D.push({value:null,error:X instanceof J?X.message:String(X&&X.message)})}}return{ok:!0,type:A.type,rows:D,via:"browser"}}function ne(f,g,I){const j=String(f||""),A=Math.max(0,Math.min(Number.isFinite(g)?g:j.length,j.length));let D=A;for(;D>0&&/[A-Za-z0-9_.À-]/.test(j[D-1]);)D--;const se=j.slice(D,A).toLowerCase(),V=[],O=X=>!se||X.toLowerCase().startsWith(se)||X.includes(".")&&X.toLowerCase().split(".")[1].startsWith(se);for(const X of s(I))O(X.name)&&V.push({label:X.name,insert:X.name,kind:X.source?"related":"field",type:a[X.field.type]||"text"});for(const X of $())se&&!X.name.toLowerCase().startsWith(se)||V.push({label:X.name,insert:`${X.name}(`,kind:"function",type:X.returns,family:X.family,doc:X.doc});return{from:D,to:A,items:V}}function U(f){const g=f&&W(f.panels)&&W(f.panels.calculated)?f.panels.calculated:{},I={};for(const j of Object.keys(g))Array.isArray(g[j])&&(I[j]=g[j].filter(A=>W(A)&&typeof A.id=="string"&&typeof A.expression=="string"));return I}function M(f,g,I){const j=I.calculated&&I.calculated[f]||[],A={};if(!j.length||!W(g))return{source:g,status:A};const D=[];for(const O of j){const X=te(O,f,I);A[O.id]=X,X.ok&&D.push(X)}if(!D.length)return{source:g,status:A};const p=_(g,I.dashboard);let se=Array.isArray(g.columns)?g.columns.slice():null;if(!se){if(!p.length)return{source:g,status:A};se=p.map(O=>({field:O.id,...O.declared?{title:O.label}:{},...O.type==="number"?{type:"number"}:{}}))}const V={...g,columns:[...se,...D.map(O=>O.column)]};return g.kind==="rows"&&Array.isArray(g.rows)&&(V.rows=g.rows.map(O=>{if(!W(O))return O;const X={...O};for(const oe of D)oe.column.value&&(X[oe.column.id]=oe.column.value.compute(X));return X})),Array.isArray(g.fields)&&g.fields.length&&(V.fields=[...g.fields,...D.map(O=>({id:O.column.id,label:O.column.title,type:O.type==="datetime"?"datetime":O.type}))]),{source:V,status:A}}function R(f,g={}){const I=k(g&&g.messages),j=f.chrome.ownerDocument,A=f.context.sources;let D=!1,p=null,se="",V="",O=null,X={};const oe=()=>({sources:{...A},relationships:f.context.relationships,calculated:U(f.getState()),dashboard:f.dashboard}),ue={},xe=new Map;for(const ee of Object.keys(A)){const ye=Object.getOwnPropertyDescriptor(A,ee);!ye||!("value"in ye)||!ye.configurable||(ue[ee]=ye.value,Object.defineProperty(A,ee,{enumerable:!0,configurable:!0,get(){if(D)return ue[ee];const ve=U(f.getState());if(!ve[ee]||!ve[ee].length)return ue[ee];const be=JSON.stringify(ve),Ee=xe.get(ee);if(Ee&&Ee.sig===be)return Ee.source;const{source:$e,status:Ge}=M(ee,ue[ee],{sources:ue,relationships:f.context.relationships,calculated:ve,dashboard:null});for(const Ye of Object.keys(Ge))X[`${ee}.${Ye}`]=Ge[Ye];return xe.set(ee,{sig:be,source:$e}),$e},set(ve){ue[ee]=ve,xe.delete(ee)}}))}const me=()=>({...oe(),sources:{...ue}}),we=j.createElement("div");we.className="lattice-designer-calculated",we.setAttribute("role","group"),we.setAttribute("aria-label",I("designer.calc.panel")),Object.assign(we.style,{display:"flex",flexDirection:"column",gap:"0.4em",font:"inherit",color:"var(--lat-chrome-ink, inherit)"});const Pe=j.createElement("div");Pe.className="lattice-designer-calculated__heading",Pe.textContent=I("designer.calc.heading");const Fe=j.createElement("select");Fe.className="lattice-designer-calculated__source",Fe.setAttribute("aria-label",I("designer.calc.source"));const Z=j.createElement("input");Z.className="lattice-designer-calculated__name",Z.setAttribute("aria-label",I("designer.calc.name")),Z.placeholder=I("designer.calc.name");const re=j.createElement("textarea");re.className="lattice-designer-calculated__expression",re.setAttribute("aria-label",I("designer.calc.expression")),re.setAttribute("spellcheck","false"),re.placeholder=I("designer.calc.placeholder");const le=j.createElement("ul");le.className="lattice-designer-calculated__suggest",le.setAttribute("role","listbox"),le.setAttribute("aria-label",I("designer.calc.suggestions"));const pe=j.createElement("div");pe.className="lattice-designer-calculated__type",pe.setAttribute("role","status"),pe.setAttribute("aria-live","polite");const he=j.createElement("div");he.className="lattice-designer-calculated__error",he.setAttribute("role","alert");const Me=j.createElement("ol");Me.className="lattice-designer-calculated__preview",Me.setAttribute("aria-label",I("designer.calc.preview"));const Ie=j.createElement("button");Ie.type="button",Ie.className="lattice-designer-calculated__save";const Ke=j.createElement("ul");Ke.className="lattice-designer-calculated__list",Ke.setAttribute("aria-label",I("designer.calc.fields"));for(const ee of[Pe,Fe,Z,re,le,pe,he,Me,Ie,Ke])we.appendChild(ee);(f.rails?f.rails.left.slot("data"):f.chrome).appendChild(we);const qe=()=>Object.keys(ue);f.commands.register(r,(ee,ye,ve)=>{const be=ee.getState();W(be.panels)||(be.panels={});const Ee=W(be.panels.calculated)?{...be.panels.calculated}:{};for(const $e of Object.keys(ye))ye[$e].length?Ee[$e]=ye[$e]:delete Ee[$e];return be.panels.calculated=Ee,ee.commit(be,ve)});const ot=(ee,ye,ve)=>te({id:ve||"__draft",expression:ye},ee,me()),it=(ee,ye,ve)=>{if(!qe().includes(ee))return{ok:!1,errors:[],refused:`there is no source "${ee}"`};const be=String(ye&&ye.id||"").trim();if(!be)return{ok:!1,errors:[{message:I("designer.calc.needName"),at:0,token:""}]};const Ee=(U(f.getState())[ee]||[]).slice(),$e=Ee.findIndex(Se=>Se.id===be);if($e<0&&Y(me(),ee).fields.some(Se=>Se.id===be))return{ok:!1,errors:[{message:I("designer.calc.exists",{id:be}),at:0,token:be}]};const Ge={id:be,...ye.label?{label:String(ye.label)}:{},expression:String(ye.expression==null?"":ye.expression).replace(/^\s*=/,"")},Ye=te(Ge,ee,{...me(),calculated:{...U(f.getState()),[ee]:$e<0?Ee:Ee.slice(0,$e)}});return Ye.ok?($e<0?Ee.push(Ge):Ee[$e]=Ge,f.commands.run(r,{[ee]:Ee},ve),{ok:!0,type:Ye.type,via:Ye.via,...Ye.provenance?{provenance:Ye.provenance}:{}}):Ye},ge=()=>{if(D)return;const ee=qe();(!p||!ee.includes(p))&&(p=ee[0]||null),Fe.textContent="";for(const be of ee){const Ee=j.createElement("option");Ee.value=be,Ee.textContent=be,be===p&&(Ee.selected=!0),Fe.appendChild(Ee)}Fe.value!==p&&p&&(Fe.value=p),Z.value=se,re.value=V,Ie.textContent=I(O?"designer.calc.save":"designer.calc.add");const ye=p&&V.trim()?q(V,p,me(),{before:O||void 0}):null;if(Me.textContent="",he.textContent="",pe.textContent="",ye&&ye.ok){pe.textContent=I("designer.calc.type",{type:ye.type}),ye.via==="pushdown"&&(pe.textContent+=` — ${ye.provenance}`);for(const be of ye.rows){const Ee=j.createElement("li");Ee.textContent=be.error?I("designer.calc.rowError",{error:be.error}):be.value===null?I("designer.calc.empty"):String(be.value),Me.appendChild(Ee)}}else ye&&(he.textContent=ye.refused||ye.errors.map(be=>be.message+(be.suggestion?I("designer.calc.didYouMean",{name:be.suggestion}):"")).join("; "));re.setAttribute("aria-invalid",ye&&!ye.ok?"true":"false"),le.textContent="";const ve=typeof re.selectionStart=="number"?re.selectionStart:V.length;if(p&&V){const be=ne(V,ve,Y(me(),p,O||void 0));if(be.to>be.from)for(const Ee of be.items.slice(0,8)){const $e=j.createElement("li");$e.setAttribute("role","option"),$e.className="lattice-designer-calculated__option",$e.textContent=Ee.kind==="function"?`${Ee.label} — ${Ee.doc}`:`${Ee.label} (${Ee.type})`,$e.addEventListener("mousedown",Ge=>{Ge.preventDefault&&Ge.preventDefault(),Ze.accept(Ee)}),le.appendChild($e)}}Ke.textContent="";for(const be of ee)for(const Ee of U(f.getState())[be]||[]){const $e=j.createElement("li");$e.className="lattice-designer-calculated__item";const Ge=X[`${be}.${Ee.id}`]||te(Ee,be,me()),Ye=j.createElement("span");Ye.textContent=`${be}.${Ee.id} = ${Ee.expression}${Ge.ok?"":` — ${I("designer.calc.refused",{reason:Ge.refused||Ge.errors[0]&&Ge.errors[0].message||""})}`}`;const Se=j.createElement("button");Se.type="button",Se.textContent=I("designer.calc.edit"),Se.setAttribute("aria-label",I("designer.calc.editField",{id:Ee.id})),Se.addEventListener("click",()=>Ze.edit(be,Ee.id));const Ne=j.createElement("button");Ne.type="button",Ne.textContent=I("designer.calc.remove"),Ne.setAttribute("aria-label",I("designer.calc.removeField",{id:Ee.id})),Ne.addEventListener("click",()=>Ze.remove(be,Ee.id)),$e.appendChild(Ye),$e.appendChild(Se),$e.appendChild(Ne),Ke.appendChild($e)}};Fe.addEventListener("change",()=>{p=Fe.value,ge()}),Z.addEventListener("input",()=>{se=Z.value}),re.addEventListener("input",()=>{V=re.value,ge()}),Ie.addEventListener("click",()=>{Ze.submit()});let Le=JSON.stringify(U(f.getState()));Le!=="{}"&&f.setGuardrails(f.guardrails&&f.guardrails.value);const He=f.on("state",()=>{const ee=JSON.stringify(U(f.getState()));ee!==Le&&(Le=ee,X={},f.setGuardrails(f.guardrails&&f.guardrails.value),f.properties&&F(f.properties.refresh)&&f.properties.refresh()),ge()}),Ze={get el(){return we},list(ee){const ye=U(f.getState());return ee===void 0?ye:ye[ee]||[]},add(ee,ye){return it(ee,ye,"addCalculated")},update(ee,ye,ve){const be=(U(f.getState())[ee]||[]).find(Ee=>Ee.id===ye);return be?it(ee,{...be,...ve,id:ye},"updateCalculated"):{ok:!1,errors:[],refused:`there is no calculated field "${ye}" on "${ee}"`}},remove(ee,ye){const ve=U(f.getState())[ee]||[];return ve.some(be=>be.id===ye)?(f.commands.run(r,{[ee]:ve.filter(be=>be.id!==ye)},"removeCalculated"),!0):!1},analyse(ee,ye){const ve=x(ye,Y(me(),ee));return ve.ok?{ok:!0,type:ve.type,references:ve.references}:ve},preview(ee,ye){return q(ye,ee,me())},suggest(ee,ye,ve){return ne(ye,ve===void 0?String(ye).length:ve,Y(me(),ee))},status(ee,ye){const ve=(U(f.getState())[ee]||[]).find(Ee=>Ee.id===ye);if(!ve)return null;const be=te(ve,ee,me());return be.ok?{ok:!0,type:be.type,via:be.via,...be.provenance?{provenance:be.provenance}:{}}:be},setSource(ee){p=ee,ge()},setExpression(ee,ye){V=String(ee),ye!==void 0&&(se=String(ye)),ge()},edit(ee,ye){const ve=(U(f.getState())[ee]||[]).find(be=>be.id===ye);return ve?(p=ee,se=ve.id,V=ve.expression,O=ve.id,ge(),!0):!1},accept(ee){const ye=typeof re.selectionStart=="number"?re.selectionStart:V.length,ve=ne(V,ye,Y(me(),p,O||void 0));V=V.slice(0,ve.from)+ee.insert+V.slice(ve.to),ge()},submit(){if(!p)return{ok:!1,errors:[],refused:I("designer.calc.noSource")};const ee=O?it(p,{id:O,expression:V,label:(U(f.getState())[p]||[]).find(ye=>ye.id===O)?.label},"updateCalculated"):it(p,{id:se,expression:V},"addCalculated");return ee.ok&&(se="",V="",O=null),ge(),!ee.ok&&ee.errors&&ee.errors.length?he.textContent=ee.errors.map(ye=>ye.message).join("; "):!ee.ok&&ee.refused&&(he.textContent=ee.refused),ee},refresh:ge,destroy(){if(!D){D=!0,He();for(const ee of Object.keys(ue))Object.defineProperty(A,ee,{value:ue[ee],writable:!0,enumerable:!0,configurable:!0});we.remove()}}},ae=f.destroy;return f.destroy=()=>{Ze.destroy(),ae.call(f)},ge(),Ze}const H=R}),rt("packages/modules/designer/derived.js",function(o,ce){"use strict";Object.defineProperty(o,"STEP_KINDS",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"normaliseStep",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"measureFormat",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"compileJoinStep",{enumerable:!0,get:function(){return y}}),Object.defineProperty(o,"compileDerived",{enumerable:!0,get:function(){return P}}),Object.defineProperty(o,"withDerivedFormats",{enumerable:!0,get:function(){return d}}),Object.defineProperty(o,"lineageText",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"hiddenDerivedIds",{enumerable:!0,get:function(){return G}}),Object.defineProperty(o,"headlessSourceIds",{enumerable:!0,get:function(){return N}}),Object.defineProperty(o,"adapterName",{enumerable:!0,get:function(){return T}}),Object.defineProperty(o,"pushdownStepRefusals",{enumerable:!0,get:function(){return C}}),Object.defineProperty(o,"buildCollectSource",{enumerable:!0,get:function(){return $}}),Object.defineProperty(o,"installDerived",{enumerable:!0,get:function(){return a}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return n}});const ke=ce("packages/core/src/internal/util.js"),F=ke.warnOnce,l=ke.isFunction,z=ce("packages/modules/dashboard/spec.js").isPlain,J=ce("packages/modules/designer/data-panel.js").compileRelationships,ie=ce("packages/modules/designer/messages.js").resolveMessages,W=Object.freeze(["filter","group","pivot","join","sort","topN"]),L=Object.freeze(["sum","avg","min","max","count","countDistinct","median","p95","stddev","distinct","first","last"]);function _(t){return typeof t=="string"&&t?t:null}function i(t){if(!z(t))return null;const e=L.includes(t.fn)?t.fn:"sum",s=_(t.of)||void 0;return!s&&e!=="count"?null:{id:_(t.id)||(s?`${s}_${e}`:"count"),of:s,fn:e}}function v(t){if(!z(t)||!W.includes(t.kind))return null;if(t.kind==="filter")return z(t.where)?{kind:"filter",where:t.where}:null;if(t.kind==="group"){const Y=(Array.isArray(t.by)?t.by:[t.by]).map(_).filter(Boolean),te=(Array.isArray(t.measures)?t.measures:[]).map(i).filter(Boolean);return Y.length?{kind:"group",by:Y,measures:te}:null}if(t.kind==="pivot"){const Y=(Array.isArray(t.rows)?t.rows:[t.rows]).map(_).filter(Boolean),te=_(t.column),q=(Array.isArray(t.measures)?t.measures:[t.measure]).map(i).filter(Boolean);return Y.length&&te&&q.length?{kind:"pivot",rows:Y,column:te,measures:q}:null}if(t.kind==="join"){const Y=_(t.to);if(!Y)return null;const te=z(t.on)?{left:_(t.on.left),right:_(t.on.right)}:null,q=["one-to-many","one-to-one","many-to-one"].includes(t.cardinality)?t.cardinality:"many-to-one",ne=Array.isArray(t.fields)?t.fields.map(_).filter(Boolean):void 0,U=_(t.as)||void 0;return{kind:"join",to:Y,on:te&&te.left&&te.right?te:null,cardinality:q,fields:ne,as:U}}if(t.kind==="sort"){const Y=(Array.isArray(t.by)?t.by:[]).map(te=>z(te)&&_(te.col)?{col:te.col,dir:te.dir==="desc"?"desc":"asc"}:null).filter(Boolean);return Y.length?{kind:"sort",by:Y}:null}const e=Number.isFinite(t.limit)&&t.limit>0?Math.floor(t.limit):null;if(!e)return null;const s=(Array.isArray(t.by)?t.by:t.by!=null?[t.by]:[]).map(_).filter(Boolean),x=(Array.isArray(t.measures)?t.measures:[]).map(i).filter(Boolean),S=(Array.isArray(t.sort)?t.sort:[]).map(Y=>z(Y)&&_(Y.col)?{col:Y.col,dir:Y.dir==="desc"?"desc":"asc"}:null).filter(Boolean),B=_(t.per)||void 0;return{kind:"topN",limit:e,by:s,measures:x,sort:S,per:B}}function k(t){return t==="count"?"count":t==="countDistinct"||t==="distinct"?"distinctCount":t}function r(t,e,s){const x=t.pushdown;if(!x||!x.isPushdown(e))return"";if(s.kind==="filter"||s.kind==="sort"||s.kind==="group"||s.kind==="pivot"){const S=x.refusal(e,{step:s.kind});if(S)return S}if(s.kind==="topN")return x.refusal(e,{step:"sort"})||x.refusal(e,{step:"group"});for(const S of Array.isArray(s.measures)?s.measures:[]){const B=z(S)?S.fn||S.agg:null,Y=B?x.refusal(e,{aggregation:B}):"";if(Y)return Y}return""}function m(t){const e=String(t);if(/[eE]/.test(e))return 0;const s=e.indexOf(".");return s===-1?0:e.length-s-1}function c(t){let e=0,s=!1;for(const x of Array.isArray(t)?t:[]){const S=Number(x);Number.isFinite(S)&&(s=!0,e=Math.max(e,m(S)))}return s?Math.min(e,6):null}function b(t,e,s,x){if(!t)return;if(t.fn==="count"||t.fn==="countDistinct"||t.fn==="distinct")return{type:"number",decimals:0,thousandsSeparator:!1};if(e&&e.format!==void 0&&e.format!=="")return e.format;if(s&&s.format!==void 0&&s.format!=="")return s.format;const S=c(x);return S===null?void 0:{type:"number",maxDecimals:S,thousandsSeparator:!1}}function y(t,e,s){const S=J(s).find(te=>te.sourceId===e&&te.relatedSourceId===t.to||te.sourceId===t.to&&te.relatedSourceId===e),B=t.on||(S?S.sourceId===e?{left:S.field,right:S.relatedField}:{left:S.relatedField,right:S.field}:null);if(!B)return{relatedId:t.to,refusal:`join to "${t.to}" needs a declared relationship or an \`on\` key pair`};if(t.cardinality==="one-to-many"){const te={from:t.to,localKey:B.left,foreignKey:B.right,many:!0,as:t.as||t.to};return t.fields&&t.fields.length===1?te.select=t.fields[0]:t.fields&&t.fields.length&&(te.select=t.fields),{collect:te,relatedId:t.to}}const Y={with:`grid:${t.to}`,on:{left:B.left,right:B.right}};return t.fields&&t.fields.length&&(Y.select=t.fields),{lookup:Y,relatedId:t.to}}function P(t,e={}){const s=_(e.fromId),x=(Array.isArray(t)?t:[]).map(v).filter(Boolean),S=[],B=[],Y={},te=new Map,q=e.display===!0,ne=new Map;for(const p of e.columns||[]){const se=p&&(p.id||p.field);se!=null&&!ne.has(se)&&ne.set(se,p)}const U=p=>{if(!te.has(p)){const se=ne.get(p);te.set(p,{field:p,...se&&se.type?{type:se.type}:{}})}return te.get(p)},M=p=>{if(!q)return;const se=p.of,V=se?ne.get(se):void 0,O=se?(e.sourceColumns||[]).find(oe=>(oe.id||oe.field)===se):void 0,X=se&&e.sourceValues?e.sourceValues[se]:void 0;return b(p,V,O,X)},R=[],H=[],f=[],g={};let I=null,j=!1;if(!x.some(p=>p.kind==="group"||p.kind==="pivot"||p.kind==="topN"&&p.by.length))for(const p of e.columns||[])p&&(p.id||p.field)&&U(p.id||p.field);x.forEach((p,se)=>{if(p.kind==="filter"){H.push(p.where);return}if(p.kind==="group"){p.by.forEach(V=>{U(V).group={enabled:!0,index:R.length},R.push(V)});for(const V of p.measures){if(!V.of)continue;const O=U(V.of);O.total=k(V.fn);const X=M(V);X!==void 0&&(O.format=X)}return}if(p.kind==="pivot"){j=!0,p.rows.forEach((V,O)=>{U(V).group={enabled:!0,index:O}}),U(p.column).pivot={enabled:!0,index:0};for(const V of p.measures){if(!V.of)continue;const O=U(V.of);O.total=k(V.fn);const X=M(V);X!==void 0&&(O.format=X)}return}if(p.kind==="sort"){p.by.forEach(V=>f.push(V));return}if(p.kind==="join"){const V=y(p,s,e.relationships);if(V.refusal){S.push({index:se,name:"join",reason:V.refusal});return}B.push(V.relatedId),V.lookup&&(g.join=V.lookup,p.fields&&p.fields.forEach(O=>U(O))),V.collect&&(I=V.collect,U(V.collect.as).type="list");return}if(p.by.length){g.groupBy=p.by.length===1?p.by[0]:p.by,g.select={};for(const V of p.measures)g.select[V.id]=V.of?{of:V.of,fn:V.fn}:{fn:V.fn};te.clear(),p.by.forEach(V=>U(V));for(const V of p.measures){const O=U(V.id);O.type="number";const X=M(V);X!==void 0&&(O.format=X)}}p.sort.length&&(g.sort=p.sort.slice()),g.limit=p.limit,p.per&&(g.limitPer=p.per)});const D={};return H.length&&(D.filters=H.length===1?H[0]:{op:"and",conditions:H}),f.length&&(D.sort=f),Object.keys(D).length&&(Y.state=D),j&&(Y.pivot={enabled:!0}),te.size&&(Y.columns=[...te.values()]),Object.keys(g).length&&(Y.source={mode:"derived",...g}),{source:s?`grid:${s}`:void 0,options:Y,collect:I,lineage:{from:e.fromLabel||s,related:B},refusals:S}}function u(t,e,s,x){const S=z(s)&&z(s[t])?s[t]:null;let B=null,Y=null;if(S){if(Array.isArray(S.fields)){const q=S.fields.find(ne=>z(ne)&&String(ne.id)===e);q&&(B={type:q.type,format:typeof q.format=="string"?q.format:void 0})}if(Array.isArray(S.columns)){const q=S.columns.find(ne=>(z(ne)?String(ne.field||ne.id):String(ne))===e);z(q)&&(Y={type:q.type,format:q.format})}}const te=(Array.isArray(x)?x:[]).find(q=>z(q)&&String(q.id)===t);if(te&&z(te.options)&&Array.isArray(te.options.columns)){const q=te.options.columns.find(ne=>z(ne)&&String(ne.field||ne.id)===e);q&&(!Y||q.format!==void 0&&q.format!=="")&&(Y={type:q.type,format:q.format})}return{field:B,column:Y}}function E(t,e,s){const x=z(s)&&z(s[t])?s[t]:null;if(!(!x||!Array.isArray(x.rows)))return x.rows.map(S=>z(S)?S[e]:void 0)}function d(t,e,s){if(!Array.isArray(t))return t;const x=z(e)&&z(e.panels)?e.panels:{},S=z(s)?s:{};let B=!1;const Y=t.map(te=>{if(!z(te)||!z(te.options)||!Array.isArray(te.options.columns))return te;const q=z(x[te.id])&&z(x[te.id].derived)?x[te.id].derived:null;if(!q)return te;const ne=(Array.isArray(q.steps)?q.steps:[]).map(v).filter(Boolean);let U=null;for(const M of ne)if(!(M.kind!=="group"&&M.kind!=="pivot"&&M.kind!=="topN"))for(const R of M.measures){const H=M.kind==="topN"?R.id:R.of;if(!H)continue;const f=(U||te.options.columns).find(p=>z(p)&&String(p.field||p.id)===H);if(!f||f.format!==void 0)continue;const g=R.of||void 0,{field:I,column:j}=g?u(q.from,g,S,t):{field:null,column:null},A=b(R,I,j,g?E(q.from,g,S):void 0);if(A===void 0)continue;U||(U=te.options.columns.map(p=>z(p)?{...p}:p));const D=U.find(p=>z(p)&&String(p.field||p.id)===H);D&&(D.format=A),B=!0}return U?{...te,options:{...te.options,columns:U}}:te});return B?Y:t}function w(t,e){const s=[e.from,...e.related||[]].filter(Boolean);return`${t} ← ${s.join(" + ")}`}function G(t){const e=new Set;if(!z(t)||!z(t.panels))return e;for(const[s,x]of Object.entries(t.panels))z(x)&&z(x.derived)&&x.derived.hidden&&e.add(s);return e}function N(t,e,s){const x=new Set;if(!z(t)||!z(t.spec)||!Array.isArray(t.spec.panels))return x;const S=z(e)&&z(e.panels)?e.panels:{},B=z(s)?s:{},Y=new Map(t.spec.panels.filter(z).map(te=>[te.id,te]));for(const te of t.spec.panels){if(!z(te))continue;const q=z(S[te.id])&&z(S[te.id].derived)?S[te.id].derived:null;if(!q)continue;const ne=_(q.from);if(!ne||Y.has(ne))continue;const U=B[ne];!z(U)||U.kind==="pushdown"||x.add(ne)}return x}function T(t){return t&&typeof t.name=="string"&&t.name?t.name:t&&typeof t.type=="string"&&t.type?t.type:null}function C(t,e){const s=[];if(!e)return s;const x=z(e.capabilities)?e.capabilities:{};return(Array.isArray(t)?t:[]).forEach((S,B)=>{if(!z(S))return;const Y=T(e)||"adapter";S.kind==="group"&&(!x.group||!l(e.executeGroupLevel))?s.push({index:B,name:"group",reason:`group is not supported by the ${Y} engine`}):S.kind==="pivot"&&(!x.pivot||!l(e.executePivotLevel))&&s.push({index:B,name:"pivot",reason:`pivot is not supported by the ${Y} engine`})}),s}function h(t){const e=new Set;let s=t;for(;s&&l(s.config)&&!e.has(s);){e.add(s);const x=s.config(),S=z(x)&&z(x.source)?x.source:null;if(S&&l(S.lastPlan))return S;if(S&&S.mode==="derived"&&S.from&&l(S.from.config)){s=S.from;continue}return null}return null}function $(t){const e=t.rowKey||"id",s=t.createDataRouter({key:"__kind",rowKey:e}),x=s.addSource(t.relatedId),S=s.addSource(t.parentId,{join:t.collect});return t.attachTo&&s.attach(t.attachTo,t.parentId),x.load(t.relatedRows.map(B=>({...B,__kind:t.relatedId}))),S.load(t.parentRows.map(B=>({...B,__kind:t.parentId}))),{router:s,parent:S,related:x,destroy:()=>{l(s.destroy)&&s.destroy()}}}function a(t,e={}){const s=ie(e.messages),x=t.commands,S=R=>Array.isArray(R.pages)&&R.pages.find(H=>z(H)&&H.id===R.selectedPageId)||null,B=R=>{const H=t.dataPanel,f=H&&l(H.sources)?H.sources():[],g=R.startsWith("grid:")?R.slice(5):R,I=f.find(j=>j.id===g);return I?I.fields:[]},Y=R=>{const f=(z(t.context.sources)?t.context.sources:{})[R];return z(f)&&f.kind==="pushdown"?R:`grid:${R}`},te=R=>{const H=z(t.context.sources)?t.context.sources:{},f=S(t.getState()),g=f&&z(f.spec)&&z(f.spec.sources)?f.spec.sources:{};return Object.hasOwn(H,R)||Object.hasOwn(g,R)},q=(R,H)=>{const f=z(R.panels)?R.panels[H]:null,g=f&&z(f.derived)?f.derived:null,I=S(R);if(!g||!I||!z(I.spec)||!Array.isArray(I.spec.panels))return null;const j=I.spec.panels.find(D=>z(D)&&D.id===H);if(!j)return null;const A=P(g.steps,{fromId:g.from,fromLabel:g.fromLabel,columns:B(g.from),relationships:t.context.relationships});return j.source=Y(g.from),j.options=A.options,g.lineage=A.lineage,{refusals:A.refusals,lineage:A.lineage}};x.register("addDerivedGrid",(R,H={})=>{const f=_(H.from);if(!f)return F("designer:derived:from","designer.addDerivedGrid: `from` must be a source or panel id; nothing was added."),null;const g=R.getState(),I=S(g);if(!I)return null;z(I.spec)||(I.spec={panels:[]}),Array.isArray(I.spec.panels)||(I.spec.panels=[]),z(g.panels)||(g.panels={});const j=I.spec.panels.filter(z).map(se=>se.id);let A=_(H.id)||`derived-${f}`,D=2;for(;j.includes(A);)A=`derived-${f}-${D++}`;const p=(Array.isArray(H.steps)?H.steps:[]).map(v).filter(Boolean);return I.spec.panels.push({id:A,kind:"grid",title:_(H.title)||A,source:Y(f),options:{}}),g.panels[A]={derived:{from:f,fromLabel:_(H.fromLabel)||f,steps:p,hidden:!!H.hidden}},q(g,A),R.commit(g,"addDerivedGrid")?A:null}),x.register("addDerivedStep",(R,H,f)=>{const g=v(f);if(!g)return F(`designer:derived:step:${z(f)?f.kind:typeof f}`,`designer.addDerivedStep: ${JSON.stringify(z(f)?f.kind:f)} is not a filter, group, pivot, join, sort or topN step; nothing was added.`),!1;const I=R.getState(),j=z(I.panels)?I.panels[H]:null;if(!j||!z(j.derived))return!1;const A=r(t,`grid:${j.derived.from}`,g);return A?(F(`designer:derived:pushdown:${g.kind}:${A}`,`designer.addDerivedStep: the ${g.kind} step is refused: ${A}; nothing was added.`),!1):(j.derived.steps=[...Array.isArray(j.derived.steps)?j.derived.steps:[],g],q(I,H),R.commit(I,"addDerivedStep"))}),x.register("removeDerivedStep",(R,H,f)=>{const g=R.getState(),I=z(g.panels)?g.panels[H]:null;return!I||!z(I.derived)||!Array.isArray(I.derived.steps)||f<0||f>=I.derived.steps.length?!1:(I.derived.steps=I.derived.steps.filter((j,A)=>A!==f),q(g,H),R.commit(g,"removeDerivedStep"))}),x.register("moveDerivedStep",(R,H,f,g)=>{const I=R.getState(),j=z(I.panels)?I.panels[H]:null;if(!j||!z(j.derived)||!Array.isArray(j.derived.steps))return!1;const A=j.derived.steps;if(f<0||f>=A.length||g<0||g>=A.length||f===g)return!1;const[D]=A.splice(f,1);return A.splice(g,0,D),q(I,H),R.commit(I,"moveDerivedStep")}),x.register("setDerivedHidden",(R,H,f)=>{const g=R.getState(),I=z(g.panels)?g.panels[H]:null;return!I||!z(I.derived)?!1:(I.derived.hidden=!!f,R.commit(g,"setDerivedHidden"))});const ne=R=>{const H=t.dashboard,f=H&&l(H.panel)?H.panel(R):null,g=h(f&&f.grid),I=g&&l(g.lastPlan)?g.lastPlan():null,j=[],A=[];return I&&((I.grouped?j:A).push("group"),I.pivoted!==void 0&&(I.pivoted?j:A).push("pivot")),{engine:g?T(g.adapter):null,pushed:j,client:A}},U=R=>{const H=t.getState(),f=z(H.panels)?H.panels[R]:null;if(!f||!z(f.derived))return[];const g=t.dashboard,I=g&&l(g.panel)?g.panel(R):null,j=h(I&&I.grid),A=C(f.derived.steps,j&&j.adapter),D=P(f.derived.steps,{fromId:f.derived.from,fromLabel:f.derived.fromLabel,relationships:t.context.relationships}),p=_(f.derived.from),se=S(H),V=new Set(se&&z(se.spec)&&Array.isArray(se.spec.panels)?se.spec.panels.filter(z).map(X=>X.id):[]);return[...p&&!V.has(p)&&!te(p)?[{index:-1,name:"from",reason:`from "${p}" names no declared source or grid widget`}]:[],...A,...D.refusals]},M=()=>{const R=t.canvas;if(!R||!l(R.querySelectorAll))return;const H=t.getState(),f=new Set(z(H.panels)?Object.keys(H.panels):[]);for(const g of R.querySelectorAll(".lat-layout__window")){const I=g.getAttribute("data-window-id");if(!I||!f.has(I))continue;const j=ne(I);if(!j.engine){g.removeAttribute("title");continue}g.setAttribute("title",s("designer.derived.engine",{engine:j.engine}))}};return t.on("state",M),M(),{compile(R,H){return P(R,H)},steps(R){const H=t.getState(),f=z(H.panels)?H.panels[R]:null;return f&&z(f.derived)&&Array.isArray(f.derived.steps)?f.derived.steps:null},lineage(R){const H=t.getState(),f=z(H.panels)?H.panels[R]:null;if(!f||!z(f.derived))return null;const g=S(H),I=g&&z(g.spec)&&Array.isArray(g.spec.panels)?g.spec.panels.find(D=>z(D)&&D.id===R):null,j=I&&I.title!=null?String(I.title):R,A=z(f.derived.lineage)?f.derived.lineage:P(f.derived.steps,{fromId:f.derived.from,fromLabel:f.derived.fromLabel,relationships:t.context.relationships}).lineage;return w(j,A)},provenance:ne,refusals:U}}const n=a}),rt("packages/modules/designer/assist.js",function(o,ce){"use strict";Object.defineProperty(o,"mountAssist",{enumerable:!0,get:function(){return G}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return N}});const ke=ce("packages/core/src/internal/util.js"),F=ke.warnOnce,l=ke.isFunction,de=ce("packages/modules/dashboard/spec.js"),z=de.isPlain,fe=de.sameSpec,J=de.copySpec,ie=ce("packages/modules/dashboard/index.js").createDashboard,W=ce("packages/modules/dashboard/propose.js"),L=W.PROPOSE_SYSTEM,_=W.proposalRequest,i=W.parseProposal,v=W.checkProposal,k=W.columnRefs,r=ce("packages/modules/designer/data-panel.js"),m=r.stripDeclaredFields,c=r.resolveSourceFields,b=Object.freeze({createGrid:"LatticeGrid",createHeadlessGrid:"LatticeGrid",createChart:"LatticeGrid",createKPI:"LatticeGridKPI",createCalendar:"LatticeGridCalendar"});function y(T,C){if(l(T[C]))return!0;const h=globalThis,$=h&&h[b[C]];return!!($&&l($[C]))}function P(T){const C=[];return y(T,"createGrid")&&C.push("grid"),y(T,"createChart")&&y(T,"createHeadlessGrid")&&C.push("chart"),y(T,"createKPI")&&C.push("kpi"),y(T,"createCalendar")&&C.push("calendar"),y(T,"createChart")&&y(T,"createHeadlessGrid")&&C.push("map"),C.push("html"),C}function u(T){if(l(T))return{ask:T,sendSampleRows:0};if(z(T)&&l(T.ask)){const C=T.sendSampleRows;return{ask:T.ask,sendSampleRows:Number.isFinite(C)&&C>0?Math.max(0,Math.floor(C)):0}}return{ask:null,sendSampleRows:0}}function E(T,C){return z(T)&&T.kind==="rows"&&Array.isArray(T.rows)?T.rows.slice(0,C):[]}const d=()=>({added:[],changed:[],removed:[]});function w(T,C){const h=new Map(T.filter(z).map(e=>[e.id,e])),$=new Map(C.filter(z).map(e=>[e.id,e])),a=[],n=[];for(const e of C){if(!z(e)||typeof e.id!="string")continue;const s=h.get(e.id);s===void 0?a.push(e.id):fe(s,e)||n.push(e.id)}const t=[];for(const e of T)z(e)&&typeof e.id=="string"&&!$.has(e.id)&&t.push(e.id);return{added:a,changed:n,removed:t}}function G(T,{doc:C,t:h,factories:$}){let a=!1,n=null,t=null,e=null,s=null;const x=C.createElement("div");x.className="lattice-designer-assist",x.setAttribute("role","region"),x.setAttribute("aria-label",h("designer.assist")),Object.assign(x.style,{display:"flex",flexDirection:"column",gap:"0.5em",font:"inherit",color:"var(--lat-chrome-ink, inherit)"});const S=C.createElement("form");S.className="lattice-designer-assist__form",Object.assign(S.style,{display:"flex",gap:"0.4em"});const B=C.createElement("input");B.type="text",B.className="lattice-designer-assist__input",B.setAttribute("aria-label",h("designer.assist.prompt")),B.placeholder=h("designer.assist.placeholder"),Object.assign(B.style,{flex:"1 1 auto",minWidth:"0"});const Y=C.createElement("button");Y.type="submit",Y.className="lattice-designer-button",Y.textContent=h("designer.assist.propose"),S.appendChild(B),S.appendChild(Y),x.appendChild(S);const te=C.createElement("ul");te.className="lattice-designer-assist__problems",te.setAttribute("aria-label",h("designer.assist.problems")),Object.assign(te.style,{margin:"0",paddingInlineStart:"1.2em",display:"flex",flexDirection:"column",gap:"0.25em"}),x.appendChild(te),(T.rails?T.rails.left.slot("assist"):T.chrome).appendChild(x);const q=()=>{const V=z(T.context.sources)?T.context.sources:{},O=T.getState(),X=Array.isArray(O.pages)?O.pages.find(ue=>z(ue)&&ue.id===O.selectedPageId):null,oe=X&&z(X.spec)&&z(X.spec.sources)?X.spec.sources:{};return{...V,...oe}},ne=()=>{const V=T.getState();return Array.isArray(V.pages)&&V.pages.find(O=>z(O)&&O.id===V.selectedPageId)||null},U=()=>{const V=T.guardrails,O=q(),X=[],oe=[];let ue=null;for(const me of Object.keys(O)){if(!V.allowsSource(me))continue;const we=O[me],Pe=c(we,T.dashboard).filter(Fe=>V.allowsField(me,Fe.id));if(Pe.length){ue===null&&(ue=me),X.push({id:me,kind:z(we)?we.kind:void 0});for(const Fe of Pe)oe.push({source:me,id:Fe.id,label:Fe.label,type:Fe.type})}}const xe=oe.filter(me=>me.source===ue).map(me=>({id:me.id,type:me.type}));return{primary:ue,sources:X,fields:oe,columns:xe,merged:O}},M=()=>{t&&(t.destroy(),t=null),e&&(e.remove(),e=null,s=null)},R=()=>{if(te.textContent="",!!n)for(const V of n.warnings){const O=C.createElement("li");O.textContent=V,te.appendChild(O)}},H=()=>{const V=n.spec,O=(Array.isArray(V.panels)?V.panels:[]).map(ue=>J(ue)),X=new Map((ne()&&z(ne().spec)&&Array.isArray(ne().spec.panels)?ne().spec.panels:[]).filter(z).map(ue=>[ue.id,ue]));for(const ue of n.diff.removed){const xe=X.get(ue),me=z(xe)&&typeof xe.title=="string"&&xe.title?xe.title:ue;O.push({id:ue,kind:"html",title:me,options:{text:h("designer.assist.removed",{title:me})}})}return{...J(V),panels:O}},f=()=>{if(!s)return;const V=s.querySelectorAll(".lat-layout__window"),O=(X,oe)=>{const ue=[...V].find(xe=>xe.getAttribute("data-window-id")===String(X));ue&&ue.setAttribute("data-assist",oe)};for(const X of n.diff.added)O(X,"added");for(const X of n.diff.changed)O(X,"changed");for(const X of n.diff.removed)O(X,"removed")},g=()=>{if(M(),!n)return;e=C.createElement("div"),e.className="lattice-designer-assist-preview",e.setAttribute("role","region"),e.setAttribute("aria-label",h("designer.assist.preview"));const V=C.createElement("style");V.textContent=[".lattice-designer-assist-preview{position:absolute;inset:0;display:flex;flex-direction:column;background:var(--lattice-surface,#fff);z-index:5}",".lattice-designer-assist-preview__bar{display:flex;align-items:center;gap:calc(var(--lattice-space,4px)*2);padding:var(--lattice-space,4px);flex:0 0 auto;border-bottom:var(--lattice-border-width,1px) solid var(--lattice-border-color)}",".lattice-designer-assist-preview__title{font-weight:var(--lattice-header-font-weight,600);flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",".lattice-designer-assist-preview__body{flex:1 1 auto;min-height:0;position:relative;overflow:hidden}",'.lattice-designer-assist-preview [data-assist="added"]{outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:2px}','.lattice-designer-assist-preview [data-assist="changed"]{outline:var(--lattice-focus-width,2px) dashed var(--lattice-foreground);outline-offset:2px}','.lattice-designer-assist-preview [data-assist="removed"]{opacity:0.5;outline:var(--lattice-focus-width,2px) solid var(--lattice-foreground);outline-offset:2px}'].join(`
|
|
274
|
+
`),e.appendChild(V);const O=C.createElement("div");O.className="lattice-designer-assist-preview__bar";const X=C.createElement("span");X.className="lattice-designer-assist-preview__title",X.textContent=h("designer.assist.preview"),O.appendChild(X);const oe=C.createElement("button");oe.type="button",oe.className="lattice-designer-button lattice-designer-button--primary",oe.textContent=h("designer.assist.accept"),oe.addEventListener("click",()=>{j.accept()});const ue=C.createElement("button");ue.type="button",ue.className="lattice-designer-button",ue.textContent=h("designer.assist.reject"),ue.addEventListener("click",()=>{j.reject()}),O.appendChild(oe),O.appendChild(ue),e.appendChild(O),s=C.createElement("div"),s.className="lattice-designer-assist-preview__body",e.appendChild(s),T.canvas.appendChild(e),t=ie(s,H(),$),f()},I=V=>({ok:!1,spec:null,warnings:V,diff:d()}),j={get el(){return x},get pending(){return n?{spec:J(n.spec),warnings:[...n.warnings],diff:{...n.diff,added:[...n.diff.added],changed:[...n.diff.changed],removed:[...n.diff.removed]}}:null},async propose(V){if(a)return I(["the assistant is already asking; nothing more was sent"]);const O=T.guardrails;if(!O.allowsAi())return F("designer:assist:ai","designer.assist: the guardrails disable the AI assistant (guardrails.ai: false); nothing was asked."),I(["the guardrails disable the AI assistant (guardrails.ai: false); nothing was asked"]);const{ask:X,sendSampleRows:oe}=u(T.context.llm);if(!X)return F("designer:assist","designer.assist: there is no AI on this designer (options.llm); nothing was asked. Pass llm as the same ask() createAI takes, or as an object with ask and sendSampleRows to opt into sample rows."),I(["there is no AI on this designer (options.llm); nothing was asked"]);const ue=U();if(ue.primary===null)return F("designer:assist:source","designer.assist: there is no source the guardrails allow with any fields; nothing was asked."),I(["there is no source the guardrails allow with any fields; nothing was asked"]);const xe=P($),me=oe>0?E(ue.merged[ue.primary],oe):void 0,we=String(V??""),Pe=_(we,{source:ue.primary,columns:ue.columns,kinds:xe,rows:me}),Fe=ne(),Z={...z(Fe&&Fe.spec)?Fe.spec:{}};delete Z.sources,Pe.schema={...Pe.schema,sources:ue.sources,fields:ue.fields,relationships:T.context.relationships,page:Z,guardrails:O.value};const re=`${we}
|
|
161
275
|
|
|
162
276
|
SCHEMA
|
|
163
|
-
${JSON.stringify(
|
|
277
|
+
${JSON.stringify(Pe.schema)}${me?`
|
|
164
278
|
|
|
165
279
|
ROWS
|
|
166
|
-
${JSON.stringify(
|
|
280
|
+
${JSON.stringify(me)}`:""}`;Pe.message=re,Pe.prompt=`${L}
|
|
167
281
|
|
|
168
|
-
${re}`,
|
|
282
|
+
${re}`,Pe.messages=[{role:"system",content:L},{role:"user",content:re}],a=!0,Y.disabled=!0,T.announce(h("designer.assist.working"));let le;try{le=await X(Pe)}catch(ge){return a=!1,Y.disabled=!1,I([`the model's ask() threw: ${ge&&ge.message?ge.message:String(ge)}`])}finally{a=!1,Y.disabled=!1}const pe=i(le);if(pe===null)return F("designer:assist:reply","designer.assist: the model's reply was not a proposal; nothing was shown. Return a JSON object with a panels array, or an object whose structured, spec or text carries that JSON."),I(["the model returned no proposal: its reply had no panels"]);const he=m(ue.merged),Me=v(pe,{source:ue.primary,definition:he[ue.primary],columns:ue.columns,kinds:xe}),Ie=[...Me.warnings],Ke=[];for(const ge of Me.spec.panels){const Le=z(ge)&&typeof ge.id=="string"?`"${ge.id}"`:"a panel",He=O.restrictPanel(ge);if(He){Ie.push(`panel ${Le} is refused by the "${He}" guardrail; dropped`);continue}const Ze=k(ge).filter(ae=>!O.allowsField(ue.primary,ae));if(Ze.length){Ie.push(`panel ${Le} names ${Ze.map(ae=>`"${ae}"`).join(", ")}, which the "fields" guardrail does not allow on "${ue.primary}"; dropped`);continue}Ke.push(ge)}const qe=O.widgetLimit();if(qe!==null&&Ke.length>qe){for(const ge of Ke.slice(qe)){const Le=z(ge)&&typeof ge.id=="string"?`"${ge.id}"`:"a panel";Ie.push(`panel ${Le} exceeds the "maxWidgetsPerPage" guardrail (${qe}); dropped`)}Ke.splice(qe)}if(Me.spec.panels=Ke,!Ke.length)return I(Ie);const ot=Fe&&z(Fe.spec)&&Array.isArray(Fe.spec.panels)?Fe.spec.panels:[],it=w(ot,Ke);return n={spec:Me.spec,warnings:Ie,diff:it},R(),g(),T.announce(h("a11y.designer.assist.proposed",{added:it.added.length,changed:it.changed.length,removed:it.removed.length,problems:Ie.length})),{ok:!0,spec:J(Me.spec),warnings:[...Ie],diff:{added:[...it.added],changed:[...it.changed],removed:[...it.removed]}}},accept(){if(!n)return!1;const V=J(n.spec);return n=null,te.textContent="",M(),T.commands.run("acceptProposal",V)},reject(){n&&(n=null,te.textContent="",M())},destroy(){M(),A(),D(),p(),x.remove()}},A=T.commands.register("acceptProposal",(V,O)=>{const X=V.getState(),oe=Array.isArray(X.pages)?X.pages.find(xe=>z(xe)&&xe.id===X.selectedPageId):null;if(!oe||!z(oe.spec)||!z(O))return F("designer:assist:accept","designer.assist.accept: there is no page and no proposal to accept; nothing was applied."),!1;const ue={...oe.spec};return ue.panels=(Array.isArray(O.panels)?O.panels:[]).map(xe=>J(xe)),z(O.layout)?ue.layout=J(O.layout):delete ue.layout,O.links!==void 0?ue.links=J(O.links):delete ue.links,oe.spec=ue,V.commit(X,"acceptProposal")}),D=T.on("state",V=>{V&&V.cause!=="acceptProposal"&&n&&(n=null,te.textContent="",M())}),p=T.on("mode",()=>{n&&(n=null,te.textContent="",M())});S.addEventListener("submit",V=>{V.preventDefault(),j.propose(B.value)});const se=T.destroy.bind(T);return T.destroy=()=>{j.destroy(),se()},j}const N=G}),rt("packages/modules/charts/typography.js",function(o,ce){"use strict";Object.defineProperty(o,"BASE_SIZE",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(o,"BASE_FAMILY",{enumerable:!0,get:function(){return F}}),Object.defineProperty(o,"CHAR_RATIO",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"resolveType",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"textWidth",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"widestLabel",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"truncateTo",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"applySize",{enumerable:!0,get:function(){return ie}});const ke=12,F="var(--lattice-font-family, system-ui, -apple-system, sans-serif)",l=.62;function de(W){const L=W&&W.font,_=typeof L=="number"?{size:L}:L||{},i=z(_.size,ke);return{family:_.family||F,size:i,small:z(_.small??_.tickSize,Math.max(9,i-1)),title:z(_.title,Math.round(i*1.15)),axisTitle:z(_.axisTitle,Math.max(10,i-1)),weight:_.weight||"inherit"}}function z(W,L){const _=Number(W);return Number.isFinite(_)&&_>0?_:L}function fe(W,L){return String(W??"").length*L*l}function J(W,L){let _=0;for(const i of W||[]){const v=fe(i,L);v>_&&(_=v)}return _}function Q(W,L,_){const i=String(W??""),v=Math.floor(L/(_*l));return v<=0?"":i.length<=v?i:v===1?"…":`${i.slice(0,v-1)}…`}function ie(W,L){!W||!Number.isFinite(L)||(W.style?W.style.fontSize=`${L}px`:W.setAttribute("style",`font-size:${L}px`))}}),rt("packages/modules/charts/frame.js",function(o,ce){"use strict";Object.defineProperty(o,"LABEL_GAP",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"LABEL_GUTTER_SHARE",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"resolveMargin",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"plotRect",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"shouldRotate",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"Pool",{enumerable:!0,get:function(){return _}});const F=ce("packages/modules/charts/svg.js").SVG_NS,l=ce("packages/modules/charts/typography.js"),de=l.textWidth,z=l.widestLabel,fe=8,J=6,Q=.4;function ie(i,v){const k=typeof i=="number"?i:v,r=i&&typeof i=="object"?i:{},m=c=>Number.isFinite(c)&&c>=0?Number(c):k;return{base:k,top:m(r.top),right:m(r.right),bottom:m(r.bottom),left:m(r.left)}}function W(i){const v=ie(i.margin,typeof i.padding=="number"?i.padding:8),k=v.base,r=i.fontSize||12,m=i.yLabels||[],c=i.xLabels||[],b=i.ySide==="right"?"right":"left",y=b==="right"?"left":"right",P=i.titles||{},u=i.titleSize||r,E=t=>t?u+J:0,d=z(m,r),w=m.length?Math.min(i.width*Q,v[b]+d+J):Math.max(fe,v[b]),G=v[y]+(i.rightGutter||0),N=(b==="left"?w:G)+E(P.left),T=z(c.map(t=>String(t).slice(0,14)),r),C=(c.length?i.rotated?Math.min(i.height*Q,J+T):r+J+v.bottom:Math.max(fe,v.bottom))+E(P.bottom),h=(b==="right"?w:G)+E(P.right),$=v.top+(i.topGutter||0),a=Math.max(0,i.width-N-h),n=Math.max(0,i.height-$-C);return{left:N,top:$,width:a,height:n,right:N+a,bottom:$+n,gutter:{left:N,bottom:C,right:h,top:$}}}function L(i,v,k,r){if(!i.length||v<=0)return!1;const m=Number.isFinite(r)&&r>0?Number(r):1;return z(i,k)>v*m-4}class _{#e;#t=0;static#n="data-pool-key";constructor(v,k=0){this.#e=v,this.#t=k>0?k:0}next(v,k,r){if(r!=null)return this.#r(v,k,String(r));const m=this.#e.childNodes[this.#t],c=m&&m.tagName,b=/(^|\s)\S*__axis-title(\s|$)/,y=c&&b.test(String(m.getAttribute("class")||"")),P=!!k&&b.test(String(k));if(c&&(!y||P)&&String(c).toLowerCase()===v.toLowerCase())return k&&m.setAttribute("class",k),this.#t++,m;const u=this.#e.ownerDocument.createElementNS(F,v);return k&&u.setAttribute("class",k),m?this.#e.insertBefore(u,m):this.#e.appendChild(u),this.#t++,u}#r(v,k,r){const m=v.toLowerCase();for(let y=this.#t;y<this.#e.childNodes.length;y++){const P=this.#e.childNodes[y],u=P&&P.tagName;if(u&&String(u).toLowerCase()===m&&P.getAttribute(_.#n)===r)return y!==this.#t&&this.#e.insertBefore(P,this.#e.childNodes[this.#t]),k&&P.setAttribute("class",k),this.#t++,P}const c=this.#e.ownerDocument.createElementNS(F,v);c.setAttribute(_.#n,r),k&&c.setAttribute("class",k);const b=this.#e.childNodes[this.#t];return b?this.#e.insertBefore(c,b):this.#e.appendChild(c),this.#t++,c}finish(){for(;this.#e.childNodes.length>this.#t;)this.#e.removeChild(this.#e.lastChild);this.#t=0}}}),rt("packages/modules/charts/styles.js",function(o,ce){"use strict";Object.defineProperty(o,"NS",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"seriesColour",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"css",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"injectStyles",{enumerable:!0,get:function(){return J}});const F=ce("packages/modules/charts/scheme.js").PALETTE,l="lat-chartview",de="data-lattice-chartview";function z(Q){const ie=(Q%F.length+F.length)%F.length;return`var(--lattice-chart-${ie+1}, ${F[ie]})`}function fe(){return`
|
|
169
283
|
.${l}{position:relative;display:flex;flex-direction:column;min-width:0;min-height:0;
|
|
170
284
|
width:100%;height:100%;box-sizing:border-box;
|
|
171
285
|
font-family:var(--lattice-font-family,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif);
|
|
@@ -572,6 +686,6 @@ ${re}`,Ne.messages=[{role:"system",content:L},{role:"user",content:re}],n=!0,W.d
|
|
|
572
686
|
.${l}__swatch{border:1px solid CanvasText}
|
|
573
687
|
.${l}__mark[data-dim]{opacity:1;fill:GrayText}
|
|
574
688
|
}
|
|
575
|
-
`}function J(X){const ne=X.documentElement;if(!ne||ne.getAttribute(ue))return;ne.setAttribute(ue,"1");const B=X.createElement("style");B.textContent=fe(),(X.head||X.body||ne).appendChild(B)}}),rt("packages/modules/charts/scale.js",function(s,ae){"use strict";Object.defineProperty(s,"isNumber",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"toNumber",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"toTime",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"extent",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"niceStep",{enumerable:!0,get:function(){return D}}),Object.defineProperty(s,"niceDomain",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"measureDomain",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"linearTicks",{enumerable:!0,get:function(){return y}}),Object.defineProperty(s,"timeStepFor",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"MONTH_STEPS",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"timeTicks",{enumerable:!0,get:function(){return r}}),Object.defineProperty(s,"linearScale",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"timeScale",{enumerable:!0,get:function(){return C}}),Object.defineProperty(s,"key",{enumerable:!0,get:function(){return G}}),Object.defineProperty(s,"bandScale",{enumerable:!0,get:function(){return _}}),Object.defineProperty(s,"sqrtScale",{enumerable:!0,get:function(){return T}});const ve=[1,2,2.5,5,10],F=6e4,l=36e5,ue=864e5,z=365.25*ue,fe=[1,2,5,10,20,25,50,100],J=[1,5,10,25,50,100,250,500,1e3,5e3,15e3,3e4,F,5*F,15*F,30*F,l,3*l,6*l,12*l,ue,2*ue,7*ue,14*ue,30*ue,90*ue,180*ue,...fe.map(p=>p*z)];function X(p){return typeof p=="number"&&Number.isFinite(p)}function ne(p){if(p==null||p==="")return null;if(p instanceof Date){const n=p.getTime();return Number.isFinite(n)?n:null}if(typeof p=="boolean")return p?1:0;const v=Number(p);return Number.isFinite(v)?v:null}function B(p){if(p==null||p==="")return null;if(p instanceof Date){const n=p.getTime();return Number.isFinite(n)?n:null}if(typeof p=="number")return Number.isFinite(p)?p:null;const v=Date.parse(String(p));return Number.isFinite(v)?v:null}function L(p){let v=1/0,n=-1/0;for(let t=0;t<p.length;t++){const a=p[t];X(a)&&(a<v&&(v=a),a>n&&(n=a))}return v===1/0?null:{min:v,max:n}}function D(p){if(!(p>0))return 1;const v=10**Math.floor(Math.log10(p));for(const n of ve)if(p<=n*v)return n*v;return 10*v}function o(p,v=5){const n=D((p.max-p.min)/Math.max(1,v));return{min:Math.floor(p.min/n)*n,max:Math.ceil(p.max/n)*n,step:n}}function w(p,v={}){const n=L(p)||{min:0,max:1};let{min:t,max:a}=n;if(v.zero&&(t>0&&(t=0),a<0&&(a=0)),t===a){const e=Math.abs(t)>0?Math.abs(t)/10:1;t-=e,a+=e}if(v.nice!==!1){const e=o({min:t,max:a},v.ticks||5);t=e.min,a=e.max}return X(v.min)&&(t=v.min),X(v.max)&&(a=v.max),t===a&&(a=t+1),{min:t,max:a}}function y(p,v=5){const n=D((p.max-p.min)/Math.max(1,v)),t=Math.ceil(p.min/n),a=Math.floor(p.max/n),e=[];for(let f=t;f<=a;f++){const d=f*n;e.push(Math.abs(d)<n/1e6?0:Number(d.toPrecision(12)))}return e}function i(p,v=5){const n=Math.max(1,v),t=p/n;let a=J[J.length-1];for(const d of J)if(d>=t){a=d;break}if(a<z)return a;let e=a,f=Math.abs(p/a-n);for(const d of J){if(d<z)continue;const E=Math.abs(p/d-n);E<f&&(f=E,e=d)}return e}const h=new Map;function c(p){let v=h.get(p);return v||(v=new Intl.DateTimeFormat("en-US",{timeZone:p,year:"numeric",month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),h.set(p,v)),v}function m(p,v){const n={year:0,month:0,day:1,hour:0,minute:0,second:0};for(const t of c(v).formatToParts(new Date(p)))switch(t.type){case"year":n.year=Number(t.value);break;case"month":n.month=Number(t.value)-1;break;case"day":n.day=Number(t.value);break;case"hour":n.hour=Number(t.value)%24;break;case"minute":n.minute=Number(t.value);break;case"second":n.second=Number(t.value);break;default:break}return n}function b(p,v,n){const t=Date.UTC(p,v,1);let a=t;for(let e=0;e<2;e++){const f=m(a,n),d=Date.UTC(f.year,f.month,f.day,f.hour,f.minute,f.second),E=t-d;if(E===0)break;a+=E}return a}function P(p,v,n){const t=n?m(p.min,n).year:new Date(p.min).getUTCFullYear();let a=Math.ceil(t/v)*v;const e=d=>n?b(d,0,n):Date.UTC(d,0,1);e(a)<p.min&&(a+=v);const f=[];for(;e(a)<=p.max;a+=v)f.push(e(a));return f}const u=new Map([[30*ue,1],[90*ue,3],[180*ue,6]]);function A(p,v,n){const t=n?m(p.min,n):{year:new Date(p.min).getUTCFullYear(),month:new Date(p.min).getUTCMonth()};let a=t.year*12+t.month;const e=d=>{const E=Math.floor(d/12),M=d-E*12;return n?b(E,M,n):Date.UTC(E,M,1)};e(a)<p.min&&(a+=1),a=Math.ceil(a/v)*v;const f=[];for(;;a+=v){const d=e(a);if(d>p.max)break;f.push(d)}return f}function r(p,v=5,n){const t=i(p.max-p.min,v);if(t>=z)return P(p,Math.round(t/z),n);const a=u.get(t);if(a)return A(p,a,n);const e=[],f=Math.ceil(p.min/t)*t;for(let d=f;d<=p.max;d+=t)e.push(d);return e}function j(p,v){const n=p.max-p.min||1,[t,a]=v;return{kind:"linear",domain:p,range:v,of(e){return t+(e-p.min)/n*(a-t)},invert(e){return p.min+(e-t)/(a-t||1)*n},ticks(e=5){return y(p,e)}}}function C(p,v){return{...j(p,v),kind:"time",ticks(t=5,a){return r(p,t,a)}}}function G(p){if(p==null)return" null";if(p instanceof Date)return` date:${p.getTime()}`;if(typeof p=="object"){const v=p,n=v.id??v.key??v.value;return n!==void 0&&typeof n!="object"?` obj:${String(n)}`:` obj:${String(p)}`}return String(p)}function _(p,v,n=.2){const t=Math.min(.9,Math.max(0,n)),[a,e]=v,f=new Map;for(let M=0;M<p.length;M++){const W=G(p[M]);f.has(W)||f.set(W,M)}const d=p.length?(e-a)/p.length:e-a,E=Math.max(0,d*(1-t));return{kind:"band",domain:p,range:v,bandwidth:E,step:d,of(M){const W=f.get(G(M));return W===void 0?NaN:a+W*d+(d-E)/2},centre(M){const W=this.of(M);return Number.isNaN(W)?NaN:W+E/2},ticks(){return p}}}function T(p,v){const[n,t]=v,a=Math.max(Math.abs(p.max),Math.abs(p.min),0)||1;return{kind:"sqrt",domain:p,range:v,of(e){const f=Math.sqrt(Math.abs(e)/a);return n+f*(t-n)}}}}),rt("packages/core/src/format/number.js",function(s,ae){"use strict";Object.defineProperty(s,"compileNumber",{enumerable:!0,get:function(){return l}});const F=ae("packages/core/src/internal/util.js").isNil;function l(ue,z){const fe=ue||{},J=fe.locale||z||void 0,X=fe.style||"decimal",ne=typeof fe.scale=="number"?fe.scale:1,B=fe.nullDisplay??"",L=fe.zeroDisplay,D=fe.prefix||"",o=fe.suffix||"",w=fe.negative||"minus",y=fe.signed===!0,i={style:X,notation:fe.notation||"standard"};X==="currency"&&(i.currency=fe.currency||"USD",fe.currencyDisplay&&(i.currencyDisplay=fe.currencyDisplay)),typeof fe.decimals=="number"?(i.minimumFractionDigits=fe.decimals,i.maximumFractionDigits=fe.decimals):(typeof fe.minDecimals=="number"&&(i.minimumFractionDigits=fe.minDecimals),typeof fe.maxDecimals=="number"&&(i.maximumFractionDigits=fe.maxDecimals),i.minimumFractionDigits>(i.maximumFractionDigits??20)&&(i.maximumFractionDigits=i.minimumFractionDigits)),fe.thousandsSeparator===!1&&(i.useGrouping=!1),i.notation==="compact"&&(i.compactDisplay=fe.compactDisplay||"short");const h=new Intl.NumberFormat(J,i),c=typeof fe.thousandsSeparator=="string"?fe.thousandsSeparator:null,m=typeof fe.decimalSeparator=="string"?fe.decimalSeparator:null;let b=",",P=".";if(c||m)for(const G of h.formatToParts(12345.6))G.type==="group"?b=G.value:G.type==="decimal"&&(P=G.value);const u=G=>{let _=G;return c&&(_=_.split(b).join("")),m&&(_=_.split(P).join("")),c&&(_=_.split("").join(c)),m&&(_=_.split("").join(m)),_},A=!!(c||m),r=D!==""&&X==="currency",j=G=>{let _;if(r){const T=h.formatToParts(G);let p=!1;_="";for(const v of T)_+=v.value,!p&&v.type==="currency"&&(_+=D,p=!0);p||(_=D+_)}else _=D+h.format(G);return A&&(_=u(_)),_+o},C=G=>{if(F(G)||G==="")return B;const _=typeof G=="number"?G:Number(G);if(Number.isNaN(_))return B;const T=ne===1?_:_*ne;return T===0&&L!==void 0?L:T<0?w==="parentheses"?`(${j(-T)})`:w==="suffix"?`${j(-T)}-`:j(T):y&&T>0?`+${j(T)}`:j(T)};return C.negativeClass=fe.negativeClass||null,C.spec=fe,C}}),rt("packages/core/src/format/date.js",function(s,ae){"use strict";Object.defineProperty(s,"scanPattern",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"toDate",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"compilePattern",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"compileDate",{enumerable:!0,get:function(){return D}}),Object.defineProperty(s,"toIsoDate",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"toIsoDateTime",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"compareIso",{enumerable:!0,get:function(){return h}});const ve=ae("packages/core/src/internal/util.js"),F=ve.isNil,l=ve.warnOnce,ue=["yyyy","yy","MMMM","MMM","MM","M","dd","d","EEEE","EEE","HH","H","hh","h","mm","m","ss","s","SSS","a"];function z(c){const m=[];let b=0,P="";const u=()=>{P&&(m.push({token:null,text:P}),P="")};for(;b<c.length;){const A=c[b];if(A==="'"){if(c[b+1]==="'"){P+="'",b+=2;continue}const j=c.indexOf("'",b+1);if(j===-1){P+=c.slice(b+1),b=c.length;continue}P+=c.slice(b+1,j),b=j+1;continue}const r=ue.find(j=>c.startsWith(j,b));if(r){u(),m.push({token:r,text:r}),b+=r.length;continue}/[A-Za-z]/.test(A)&&l(`date.pattern.token:${A}`,`the date pattern "${c}" contains '${A}', which is not a supported token, so it is rendered as text. Quote it as a literal to silence this. Supported: ${ue.join(" ")}.`),P+=A,b+=1}return u(),m}const fe=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?)?$/;function J(c){if(F(c)||c==="")return null;if(c instanceof Date)return Number.isNaN(c.getTime())?null:c;if(typeof c=="number")return Number.isNaN(c)?null:new Date(c);if(typeof c=="string"){const m=fe.exec(c.trim());if(m){const[,P,u,A,r="0",j="0",C="0"]=m;return new Date(+P,+u-1,+A,+r,+j,+C)}const b=new Date(c);return Number.isNaN(b.getTime())?null:b}return null}function X(c,m){return String(c).padStart(m,"0")}function ne(c){if(!c)return P=>({year:P.getFullYear(),month:P.getMonth()+1,day:P.getDate(),hour:P.getHours(),minute:P.getMinutes(),second:P.getSeconds(),ms:P.getMilliseconds(),weekday:P.getDay()});const m=new Intl.DateTimeFormat("en-US",{timeZone:c,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,weekday:"short"}),b={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return P=>{const u={year:0,month:1,day:1,hour:0,minute:0,second:0,ms:P.getMilliseconds(),weekday:0};for(const A of m.formatToParts(P))switch(A.type){case"year":u.year=Number(A.value);break;case"month":u.month=Number(A.value);break;case"day":u.day=Number(A.value);break;case"hour":u.hour=Number(A.value)%24;break;case"minute":u.minute=Number(A.value);break;case"second":u.second=Number(A.value);break;case"weekday":u.weekday=b[A.value]??0;break;default:break}return u}}function B(c,m,b){const P=z(c),u=ne(b),A=new Set(P.filter(_=>_.token).map(_=>_.token)),r=A.has("MMM")?new Intl.DateTimeFormat(m,{month:"short",timeZone:b}):null,j=A.has("MMMM")?new Intl.DateTimeFormat(m,{month:"long",timeZone:b}):null,C=A.has("EEE")?new Intl.DateTimeFormat(m,{weekday:"short",timeZone:b}):null,G=A.has("EEEE")?new Intl.DateTimeFormat(m,{weekday:"long",timeZone:b}):null;return _=>{const T=u(_);let p="";for(const v of P){if(!v.token){p+=v.text;continue}switch(v.token){case"yyyy":p+=X(T.year,4);break;case"yy":p+=X(T.year%100,2);break;case"MMMM":p+=j.format(_);break;case"MMM":p+=r.format(_);break;case"MM":p+=X(T.month,2);break;case"M":p+=String(T.month);break;case"dd":p+=X(T.day,2);break;case"d":p+=String(T.day);break;case"EEEE":p+=G.format(_);break;case"EEE":p+=C.format(_);break;case"HH":p+=X(T.hour,2);break;case"H":p+=String(T.hour);break;case"hh":p+=X(T.hour%12===0?12:T.hour%12,2);break;case"h":p+=String(T.hour%12===0?12:T.hour%12);break;case"mm":p+=X(T.minute,2);break;case"m":p+=String(T.minute);break;case"ss":p+=X(T.second,2);break;case"s":p+=String(T.second);break;case"SSS":p+=X(T.ms,3);break;case"a":p+=T.hour<12?"AM":"PM";break;default:p+=v.text;break}}return p}}const L=[["year",365*24*36e5],["month",720*36e5],["week",168*36e5],["day",24*36e5],["hour",36e5],["minute",6e4],["second",1e3]];function D(c,m){const b=c||{},P=b.locale||m||void 0,u=b.nullDisplay??"",A=b.timeZone;let r;if(b.pattern)r=B(b.pattern,P,A);else if(b.dateStyle||b.timeStyle){const T={timeZone:A};b.dateStyle&&(T.dateStyle=b.dateStyle),b.timeStyle&&(T.timeStyle=b.timeStyle);const p=new Intl.DateTimeFormat(P,T);r=v=>p.format(v)}else{const T=new Intl.DateTimeFormat(P,{dateStyle:"medium",timeZone:A});r=p=>T.format(p)}const j=b.relative?new Intl.RelativeTimeFormat(P,{numeric:"auto"}):null,G=(typeof b.relative=="object"&&b.relative?b.relative.threshold??7:7)*24*36e5,_=(T,p)=>{const v=J(T);if(!v)return u;if(j){const n=p&&typeof p.now=="number"?p.now:Date.now(),t=v.getTime()-n;if(Math.abs(t)<G){for(const[a,e]of L)if(Math.abs(t)>=e||a==="second")return j.format(Math.round(t/e),a)}}return r(v)};return _.spec=b,_}function o(c){if(F(c)||c==="")return null;if(typeof c=="string"){const P=/^(\d{4}-\d{2}-\d{2})/.exec(c.trim());if(P)return P[1];const u=J(c);return u?o(u):null}const m=J(c);if(!m)return null;const b=P=>String(P).padStart(2,"0");return`${m.getFullYear()}-${b(m.getMonth()+1)}-${b(m.getDate())}`}function w(c,m){if(F(c)||c==="")return null;if(typeof c=="string"){const P=c.trim();if(y.test(P)){const r=J(P);return r?i(r,m):null}const u=/^(\d{4}-\d{2}-\d{2})[T ](\d{2}):(\d{2})(?::(\d{2}))?/.exec(P);if(u){const[,r,j,C,G]=u;return`${r}T${j}:${C}${G&&G!=="00"?`:${G}`:""}`}if(/^\d{4}-\d{2}-\d{2}$/.test(P))return`${P}T00:00`;const A=J(P);return A?w(A):null}const b=J(c);return b?i(b,m):null}const y=/(?:Z|[+-]\d{2}:?\d{2})$/i;function i(c,m){const b=r=>String(r).padStart(2,"0");if(m)try{const r=new Intl.DateTimeFormat("en-CA",{timeZone:m,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(c).reduce((G,_)=>(_.type!=="literal"&&(G[_.type]=_.value),G),{}),j=r.hour==="24"?"00":r.hour,C=Number(r.second);return`${r.year}-${r.month}-${r.day}T${j}:${r.minute}`+(C?`:${r.second}`:"")}catch{}const P=`${c.getFullYear()}-${b(c.getMonth()+1)}-${b(c.getDate())}`,u=c.getSeconds(),A=`${b(c.getHours())}:${b(c.getMinutes())}${u?`:${b(u)}`:""}`;return`${P}T${A}`}function h(c,m){const b=F(c)||c===""?null:String(c),P=F(m)||m===""?null:String(m);return b===null?P===null?0:1:P===null||b<P?-1:b>P?1:0}}),rt("packages/core/src/format/boolean.js",function(s,ae){"use strict";Object.defineProperty(s,"toTriState",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"compileBoolean",{enumerable:!0,get:function(){return fe}});const F=ae("packages/core/src/internal/util.js").isNil,l={true:"☑",false:"☐",null:""},ue={true:"◉",false:"◯",null:""};function z(J){if(F(J)||J==="")return null;if(typeof J=="boolean")return J;if(typeof J=="number")return J!==0;const X=String(J).trim().toLowerCase();return X==="true"||X==="yes"||X==="y"||X==="1"?!0:X==="false"||X==="no"||X==="n"||X==="0"?!1:null}function fe(J,X){const ne=J||{},B=ne.display||"text",L=ne.trueLabel??"Yes",D=ne.falseLabel??"No",o=ne.nullLabel??"";let w=L,y=D;const i=o;B==="checkbox"?(w=l.true,y=l.false):B==="switch"?(w=ue.true,y=ue.false):B==="icon"&&(w=ne.trueIcon??L,y=ne.falseIcon??D);const h=c=>{const m=z(c);return m===null?i:m?w:y};return h.display=B,h.labels={true:L,false:D,null:o},h.locale=X,h.spec=ne,h}}),rt("packages/core/src/format/text.js",function(s,ae){"use strict";Object.defineProperty(s,"compileText",{enumerable:!0,get:function(){return ue}});const ve=ae("packages/core/src/internal/util.js"),F=ve.isNil,l=ve.titleCase;function ue(z,fe){const J=z||{},X=J.locale||fe||void 0,ne=J.nullDisplay??"",B=J.emptyDisplay??"",L=J.transform||"none",D=typeof J.truncate=="number"?{chars:J.truncate}:J.truncate||null,o=D?D.chars:0,w=D?D.ellipsis??"…":"",y=h=>{switch(L){case"upper":return X?h.toLocaleUpperCase(X):h.toUpperCase();case"lower":return X?h.toLocaleLowerCase(X):h.toLowerCase();case"title":return l(h);default:return h}},i=h=>{if(F(h))return ne;let c=typeof h=="string"?h:String(h);return c===""?B:(L!=="none"&&(c=y(c)),o>0&&c.length>o&&(c=c.slice(0,o)+w),c)};return i.spec=J,i}}),rt("packages/core/src/format/mask.js",function(s,ae){"use strict";Object.defineProperty(s,"splitSections",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"parseSection",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"compileMask",{enumerable:!0,get:function(){return fe}});const ve=new Set(["0","#","?",",","."]),F="\0";function l(X){const ne=[];let B="",L=!1;for(let D=0;D<X.length;D++){const o=X[D];if(o==="\\"){B+=o+(X[D+1]??""),D+=1;continue}if(o==='"'){L=!L,B+=o;continue}if(o===";"&&!L){ne.push(B),B="";continue}B+=o}return ne.push(B),ne}function ue(X){let ne="",B="",L="",D=1,o=!1,w=!1;const y=r=>{w?B+=r:ne+=r};for(let r=0;r<X.length;r++){const j=X[r];if(j==="\\"){y(X[r+1]??""),r+=1;continue}if(j==='"'){const C=X.indexOf('"',r+1);y(C===-1?X.slice(r+1):X.slice(r+1,C)),r=C===-1?X.length:C;continue}if(j==="%"){D*=100,y("%");continue}if(j==="@"){o=!0,y("\0");continue}if(ve.has(j)){L+=j,w=!0;continue}y(j)}let i=-1;for(let r=L.length-1;r>=0;r--){const j=L[r];if(j==="0"||j==="#"||j==="?"){i=r;break}}let h=!1,c="";for(let r=0;r<L.length;r++){const j=L[r];if(j===","){r>i?D/=1e3:h=!0;continue}c+=j}const m=c.indexOf("."),b=m===-1?c:c.slice(0,m),P=m===-1?"":c.slice(m+1);let u=0;for(const r of b)r==="0"&&(u+=1);let A=0;for(const r of P)r==="0"&&(A+=1);return{prefix:ne,suffix:B,minInt:u,minDec:A,maxDec:P.length,grouping:h,scale:D,hasNumber:i!==-1,isText:o}}function z(X,ne){const B=new Intl.NumberFormat(ne,{minimumIntegerDigits:Math.max(X.minInt,1),minimumFractionDigits:X.minDec,maximumFractionDigits:Math.max(X.maxDec,X.minDec),useGrouping:X.grouping}),{prefix:L,suffix:D,scale:o,hasNumber:w}=X;return y=>{if(!w)return L+D;const i=o===1?y:y*o;return L+B.format(i)+D}}function fe(X,ne){const L=l(String(X)).map(ue),D=L.map(c=>z(c,ne)),o=0,w=L.length>1?1:-1,y=L.length>2?2:-1,i=L.length>3?3:-1,h=c=>{if(c==null||c==="")return"";if(typeof c!="number"||Number.isNaN(c)){const m=Number(c);if(Number.isNaN(m))return i===-1?String(c):(L[i].prefix+L[i].suffix).split("\0").join(String(c));c=m}return c===0&&y!==-1?D[y](0):c<0&&w!==-1?D[w](-c):D[o](c)};return h.spec={mask:X},{format:h,ooxml:J(String(X))}}function J(X){return X.trim()}}),rt("packages/core/src/format/shorthand.js",function(s,ae){"use strict";Object.defineProperty(s,"looksLikeMask",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"looksLikeDatePattern",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"parseShorthand",{enumerable:!0,get:function(){return J}});const ve=["currency","number","percent","date","boolean","text","relative"],F=/[#0?@;"\\]/,l=/(yyyy|yy|MMMM|MMM|MM|EEEE|EEE|dd|HH|hh|mm|ss|SSS)/;function ue(X){return typeof X!="string"||X===""||fe(X)?!1:F.test(X)}function z(X){return typeof X!="string"||X===""||fe(X)?!1:l.test(X)}function fe(X){const ne=X.indexOf(":"),B=ne===-1?X:X.slice(0,ne);return ve.includes(B)?B:null}function J(X){const ne=fe(X);if(!ne)return null;const B=X.indexOf(":"),L=B===-1?"":X.slice(B+1),D=L===""?[]:L.split(":");switch(ne){case"currency":{const o={type:"number",style:"currency",currency:D[0]||"USD"};return D[1]!==void 0&&D[1]!==""&&(o.decimals=Number(D[1])),o}case"number":{const o={type:"number",style:"decimal"};return D[0]!==void 0&&D[0]!==""&&(o.decimals=Number(D[0])),o}case"percent":{const o={type:"number",style:"percent"};return D[0]!==void 0&&D[0]!==""&&(o.decimals=Number(D[0])),o}case"date":return{type:"date",pattern:L||void 0};case"relative":return{type:"date",relative:!0};case"boolean":{const o=L.split("/"),w={type:"boolean",display:"text"};return o[0]!==void 0&&o[0]!==""&&(w.trueLabel=o[0]),o[1]!==void 0&&o[1]!==""&&(w.falseLabel=o[1]),o[2]!==void 0&&(w.nullLabel=o[2]),w}case"text":{const o={type:"text"};return D[0]&&(o.transform=D[0]),D[1]!==void 0&&D[1]!==""&&(o.truncate=Number(D[1])),o}default:return null}}}),rt("packages/core/src/format/index.js",function(s,ae){"use strict";Object.defineProperty(s,"compileFormat",{enumerable:!0,get:function(){return _}}),Object.defineProperty(s,"specToOoxml",{enumerable:!0,get:function(){return p}});const ve=ae("packages/core/src/internal/util.js"),F=ve.isFunction,l=ve.isObject,ue=ve.warnOnce,z=ae("packages/core/src/format/number.js"),fe=z.compileNumber,J=ae("packages/core/src/format/date.js"),X=J.compileDate,ne=J.scanPattern,B=ae("packages/core/src/format/boolean.js"),L=B.compileBoolean,D=ae("packages/core/src/format/text.js"),o=D.compileText,w=ae("packages/core/src/format/mask.js"),y=w.compileMask,i=ae("packages/core/src/format/shorthand.js"),h=i.parseShorthand,c=i.looksLikeMask,m=i.looksLikeDatePattern;Object.defineProperty(s,"compileNumber",{enumerable:!0,get:function(){return z.compileNumber}}),Object.defineProperty(s,"compileDate",{enumerable:!0,get:function(){return J.compileDate}}),Object.defineProperty(s,"compilePattern",{enumerable:!0,get:function(){return J.compilePattern}}),Object.defineProperty(s,"scanPattern",{enumerable:!0,get:function(){return J.scanPattern}}),Object.defineProperty(s,"toDate",{enumerable:!0,get:function(){return J.toDate}}),Object.defineProperty(s,"compileBoolean",{enumerable:!0,get:function(){return B.compileBoolean}}),Object.defineProperty(s,"toTriState",{enumerable:!0,get:function(){return B.toTriState}}),Object.defineProperty(s,"compileText",{enumerable:!0,get:function(){return D.compileText}}),Object.defineProperty(s,"compileMask",{enumerable:!0,get:function(){return w.compileMask}}),Object.defineProperty(s,"splitSections",{enumerable:!0,get:function(){return w.splitSections}}),Object.defineProperty(s,"parseSection",{enumerable:!0,get:function(){return w.parseSection}}),Object.defineProperty(s,"parseShorthand",{enumerable:!0,get:function(){return i.parseShorthand}}),Object.defineProperty(s,"looksLikeMask",{enumerable:!0,get:function(){return i.looksLikeMask}}),Object.defineProperty(s,"looksLikeDatePattern",{enumerable:!0,get:function(){return i.looksLikeDatePattern}});const b=new Set(["decimal","currency","percent","unit"]),P=new Set(["type","locale"]),u={number:new Set(["style","currency","currencyDisplay","decimals","minDecimals","maxDecimals","thousandsSeparator","decimalSeparator","notation","compactDisplay","negative","negativeClass","signed","prefix","suffix","zeroDisplay","nullDisplay","messages","scale"]),date:new Set(["pattern","dateStyle","timeStyle","timeZone","relative","nullDisplay"]),boolean:new Set(["display","trueLabel","falseLabel","nullLabel","trueIcon","falseIcon"]),text:new Set(["transform","truncate","nullDisplay","emptyDisplay"])},A=new Set(["number","date","boolean","text"]);function r(a,e){const f=a.type;if(f===void 0||A.has(f)||!b.has(String(f)))return;const d=e?`"${e}"`:"with no id";ue(`format:unknown-style-key:${e||""}:${f}`,`column ${d} has format: { type: "${f}" }, which is not a valid format type ("number", "date", "boolean" or "text") and is ignored; did you mean style: "${f}" instead?`)}function j(a,e,f){const d=u[e],E=f?`"${f}"`:"with no id";for(const M of a){if(P.has(M)||d.has(M))continue;const W=Object.keys(u).find(oe=>oe!==e&&u[oe].has(M));W?ue(`format:inapplicable:${f||""}:${M}`,`column ${E} has format key "${M}", which applies to a ${W} column, not the ${e} column it was applied to; it is ignored.`):ue(`format:unknown:${f||""}:${M}`,`column ${E} has an unrecognised format key "${M}" for its ${e} format; it is ignored.`)}}function C(a){if(a.type==="number"||a.type==="date"||a.type==="boolean"||a.type==="text")return!0;const e=b.has(String(a.style));return!!(a.pattern||a.dateStyle||a.timeStyle||a.relative||a.timeZone||a.trueLabel||a.falseLabel||a.display||a.trueIcon||a.falseIcon||a.transform||a.truncate||a.emptyDisplay||e||a.currency||a.decimals!==void 0||a.minDecimals!==void 0||a.maxDecimals!==void 0||a.notation||a.negative||a.scale!==void 0||a.prefix||a.suffix||a.zeroDisplay!==void 0)}function G(a,e){if(a.type==="number"||a.type==="date"||a.type==="boolean"||a.type==="text")return a.type;if(a.pattern||a.dateStyle||a.timeStyle||a.relative||a.timeZone)return"date";if(a.trueLabel||a.falseLabel||a.display||a.trueIcon||a.falseIcon)return"boolean";if(a.transform||a.truncate||a.emptyDisplay)return"text";if(a.style||a.currency||a.decimals!==void 0||a.minDecimals!==void 0||a.maxDecimals!==void 0||a.notation||a.negative||a.scale!==void 0||a.prefix||a.suffix||a.zeroDisplay!==void 0)return"number";const f=e&&e.base;return f==="number"?"number":f==="date"||f==="dateString"?"date":f==="boolean"?"boolean":"text"}function _(a,e=null,f=void 0,d=void 0,E=void 0){if(a==null||a==="")return null;const M=l(a)?Object.keys(a):null;if(typeof a=="function"){const q=(Q,H)=>String(a({...H||{},value:Q,locale:f})??"");return q.ooxml=e&&e.excel||"General",q}if(typeof a=="string"){if(c(a)){const{format:Q,ooxml:H}=y(a,f);return Q.ooxml=H,Q}const q=h(a)||(m(a)?{type:"date",pattern:a}:null);return q?_(q,e,f,d,E):(ue(`format:${a}`,`unrecognised format string "${a}"; the value will be stringified`),null)}if(!l(a))return ue("format:shape","format must be a spec object or a string; ignoring",a),null;if(e&&F(e.format)&&!C(a)||e&&F(e.format)&&Array.isArray(e.formatPatterns)&&a.type===void 0)return null;const W=G(a,e);W==="date"&&d&&a.timeZone===void 0&&(a={...a,timeZone:d}),r(a,E),j(M||Object.keys(a),W,E);let oe;switch(W){case"number":oe=fe(a,f);break;case"date":oe=X(a,f);break;case"boolean":oe=L(a,f);break;default:oe=o(a,f);break}return oe.ooxml=p(a,W,f,e),oe.kind=W,oe}const T={yyyy:"yyyy",yy:"yy",MMMM:"mmmm",MMM:"mmm",MM:"mm",M:"m",dd:"dd",d:"d",EEEE:"dddd",EEE:"ddd",HH:"hh",H:"h",hh:"hh",h:"h",mm:"mm",m:"m",ss:"ss",s:"s",SSS:"000",a:"AM/PM"};function p(a,e,f=void 0,d=null){if(e==="date"){if(a.pattern){let q="";for(const Q of ne(a.pattern))q+=Q.token?T[Q.token]??Q.text:Q.text;return q}return d&&d.excel||"yyyy-mm-dd"}if(e==="boolean")return"General";if(e==="text")return"@";if(a.notation==="compact"||a.notation==="scientific")return"General";const E=typeof a.decimals=="number"?a.decimals:typeof a.minDecimals=="number"?a.minDecimals:a.style==="currency"?2:0;let W=`${a.thousandsSeparator===!1?"":"#,#"}#0${E>0?`.${"0".repeat(E)}`:""}`,oe="";return a.style==="currency"&&(oe+=v(t(a.currency||"USD",f))),a.prefix&&(oe+=v(a.prefix)),W=oe+W,a.style==="percent"&&(W=`${W}%`),a.suffix&&(W+=v(a.suffix)),a.negative==="parentheses"?`${W};(${W})`:a.negative==="suffix"?`${W};${W}-`:W}function v(a){return`"${String(a).split('"').join("")}"`}const n=new Map;function t(a,e){const f=`${a}|${e||""}`;let d=n.get(f);if(d!==void 0)return d;d=a;try{const M=new Intl.NumberFormat(e,{style:"currency",currency:a}).formatToParts(0).find(W=>W.type==="currency");M&&(d=M.value)}catch{}return n.set(f,d),d}}),rt("packages/modules/charts/format.js",function(s,ae){"use strict";Object.defineProperty(s,"precisionFor",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"axisNumber",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"r2Digits",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"dateFormatFor",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"resolveTimeZone",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"formatters",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"measureText",{enumerable:!0,get:function(){return y}}),Object.defineProperty(s,"measureFormat",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"stringFormatter",{enumerable:!0,get:function(){return c}});const ve=ae("packages/modules/charts/scale.js"),F=ve.MONTH_STEPS,l=ve.timeStepFor,z=ae("packages/core/src/format/index.js").compileFormat,J=ae("packages/core/src/internal/util.js").warnOnce;function X(m){if(!Number.isFinite(m)||m<=0)return 0;const b=Math.ceil(-Math.log10(m));return Math.min(6,Math.max(0,b))}function ne(m,b,P=0){return Number.isFinite(m)?Math.abs(m)>=1e4?b.number(m,{notation:"compact",maximumFractionDigits:1}):b.number(m,{minimumFractionDigits:P,maximumFractionDigits:P}):""}function B(m,b){const P=m&&m.messages;return!P||typeof P.number!="function"?Number(b).toFixed(2):P.number(b,{minimumFractionDigits:2,maximumFractionDigits:2})}function L(m){const P=m>0?l(m):0;return P>0&&P<1e3?{minute:"2-digit",second:"2-digit",fractionalSecondDigits:3}:P>0&&P<6e4?{hour:"2-digit",minute:"2-digit",second:"2-digit"}:m<=864e5?{hour:"2-digit",minute:"2-digit"}:m<=180*864e5?F.has(P)?{month:"short"}:P>0&&P<864e5?{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}:{day:"numeric",month:"short"}:m<=3*365*864e5?{month:"short",year:"numeric"}:{year:"numeric"}}let D;function o(m,b){const P=b&&b.format&&b.format.timeZone;if(P)return P;const u=m&&typeof m.get=="function"&&m.get("timeZone");return u||(D||(D=Intl.DateTimeFormat().resolvedOptions().timeZone),D)}function w(m,b,P){const u=m.messages,A=u.locale,r=o(m,P);if(b.kind==="time"){const C=L(b.span||0),G=new Intl.DateTimeFormat(A,{...C,timeZone:r}),_=new Intl.DateTimeFormat(A,{dateStyle:"medium",timeStyle:"short",timeZone:r});return{tick:T=>Number.isFinite(Number(T))?G.format(new Date(Number(T))):"",value:T=>Number.isFinite(Number(T))?_.format(new Date(Number(T))):""}}const j=X(b.step||0);return{tick:C=>typeof C=="number"?ne(C,u,j):String(C??""),value:C=>typeof C=="number"?u.number(C):String(C??"")}}function y(m,b){if(m==null||!Number.isFinite(m))return"";const P=Math.abs(m)>=1e-6?Number(m.toPrecision(6)):m;return b.number(P)}function i(m,b,P){return m==null||!Number.isFinite(Number(m))?"":b&&b.format&&typeof b.formatValue=="function"?String(b.formatValue(m,null)):y(Number(m),P&&P.messages)}const h=new Map;function c(m,b,P){const u=b&&b.messages&&b.messages.locale,A=`${u}\0${m}`;if(!h.has(A)){let j=null;try{j=z(m,null,u)}catch{j=null}h.set(A,j)}const r=h.get(A);return r?j=>String(r(j)):(J(`chart.format.string:${P}:${m}`,`${P}: the format string "${m}" is not understood; values are drawn unformatted`),null)}}),rt("packages/modules/charts/axis.js",function(s,ae){"use strict";Object.defineProperty(s,"pinXDomain",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"labelGap",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"TICK_FLOOR",{enumerable:!0,get:function(){return C}}),Object.defineProperty(s,"tickFloor",{enumerable:!0,get:function(){return G}}),Object.defineProperty(s,"fitBandLabels",{enumerable:!0,get:function(){return _}}),Object.defineProperty(s,"normaliseAxes",{enumerable:!0,get:function(){return n}}),Object.defineProperty(s,"tickValues",{enumerable:!0,get:function(){return t}}),Object.defineProperty(s,"tickLabeller",{enumerable:!0,get:function(){return a}}),Object.defineProperty(s,"drawAxisTitle",{enumerable:!0,get:function(){return e}}),Object.defineProperty(s,"labelEvery",{enumerable:!0,get:function(){return f}}),Object.defineProperty(s,"drawMeasureAxis",{enumerable:!0,get:function(){return d}}),Object.defineProperty(s,"heldInside",{enumerable:!0,get:function(){return E}}),Object.defineProperty(s,"drawCategoryAxis",{enumerable:!0,get:function(){return M}}),Object.defineProperty(s,"turnedFirstLabelBox",{enumerable:!0,get:function(){return W}}),Object.defineProperty(s,"leftLabelRoom",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(s,"setLabelText",{enumerable:!0,get:function(){return q}}),Object.defineProperty(s,"drawBandLabels",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(s,"drawContinuousAxis",{enumerable:!0,get:function(){return H}}),Object.defineProperty(s,"drawAxisLines",{enumerable:!0,get:function(){return O}}),Object.defineProperty(s,"createGroups",{enumerable:!0,get:function(){return K}}),Object.defineProperty(s,"MARK_OVERHANG",{enumerable:!0,get:function(){return g}}),Object.defineProperty(s,"overhangFor",{enumerable:!0,get:function(){return k}}),Object.defineProperty(s,"setPlotClip",{enumerable:!0,get:function(){return V}});const F=ae("packages/modules/charts/frame.js").Pool,l=ae("packages/modules/charts/svg.js"),ue=l.attrs,z=l.round,fe=l.setText,J=l.svg,X=ae("packages/modules/charts/typography.js"),ne=X.applySize,B=X.CHAR_RATIO,L=X.truncateTo,o=ae("packages/modules/charts/styles.js").NS,w=ae("packages/modules/charts/scale.js"),y=w.toNumber,i=w.toTime,h=ae("packages/modules/charts/format.js"),c=h.resolveTimeZone,m=h.stringFormatter,P=ae("packages/core/src/internal/util.js").warnOnce;function u(R,N,$){const S=N&&N.kind==="time"?i:y,Y=ye=>ye==null||ye===""?null:S(ye),Z=Y($&&$.min),x=Y($&&$.max);if(Z===null&&x===null)return R;if(Z!==null&&x!==null)return Z<x?{min:Z,max:x}:(P("chart.axis.x.domain.inverted",`axis.x.min (${Z}) is not below axis.x.max (${x}), which is a mirrored axis rather than a narrow one, so both were ignored and the x domain was taken from the data. On a time axis both are epoch milliseconds.`),R);const ee=Z!==null?Z:R.min,se=x!==null?x:R.max;if(ee<se)return{min:ee,max:se};const de=Math.abs(R.max-R.min)||1;return P("chart.axis.x.domain.beyond",`axis.x.${Z!==null?"min":"max"} is outside the x values entirely, so the plot is empty. The pin was kept and the other edge moved to hold the axis width; check the units (a time axis is pinned in epoch milliseconds).`),Z!==null?{min:ee,max:ee+de}:{min:se-de,max:se}}const A=6,r=.53;function j(R){return Number.isFinite(R)&&R>0?Math.max(A,Math.ceil(R)+1):A}const C=9;function G(R){const N=R&&R.ownerDocument,$=N&&N.defaultView;if(!$||typeof $.getComputedStyle!="function")return C;const S=$.getComputedStyle(R).getPropertyValue("--lattice-chart-tick-min"),Y=parseFloat(S);return Number.isFinite(Y)&&Y>0?Y:C}function _(R){const{size:N,floor:$,slot:S,per:Y}=R,Z=Number.isFinite(R.every)&&R.every>0?Number(R.every):null;if(Z!==null&&Z!==1)return{size:N,every:Z,thinned:!1};if(!(S>0)||!(Y>0))return{size:N,every:1,thinned:!1};const x=Math.min(N,S/Y);return x>=$?{size:x,every:1,thinned:!1}:{size:$,every:Math.max(1,Math.ceil($*Y/S)),thinned:!0}}function T(R,N){P("chart.axis.band.every.impossible",`axis.x.every/axis.y.every is set to ${N}, which on ${R} band(s) never shows a second label no matter how much room the axis is given. Lower it, or drop it to let the axis thin automatically.`)}function p(R,N){const $=Number.isFinite(N)&&N>0?Number(N):null;$!==null&&$>1&&R>1&&$>=R&&T(R,$)}const v=1.2;function n(R){if(R===!1){const S={labels:!1,grid:!1};return{x:{...S},y:{...S},y2:{...S}}}const N=R&&typeof R=="object"?R:{},$=S=>typeof S=="string"?{title:S}:S&&typeof S=="object"?{...S}:{};return{x:$(N.x),y:$(N.y),y2:$(N.y2||N.right)}}function t(R,N,$){const S=N&&N.ticks;if(Array.isArray(S)){const Z=R.domain;return!Z||Z.min===void 0?S:S.filter(x=>Number(x)>=Z.min&&Number(x)<=Z.max)}const Y=Number.isFinite(S)&&S>0?Number(S):5;return R.ticks(Y,$)}function a(R,N,$,S){const Y=R&&R.format;if(typeof Y=="function")return Z=>String(Y(Z));if(typeof Y=="string"){const Z=m(Y,$,"axis.<x|y|y2>.format");if(Z)return Z}return S&&S.format&&S.format.pattern&&typeof S.formatValue=="function"?Z=>String(S.formatValue(Z,null)):N.tick}function e(R){if(!R.text)return;const N=R.side==="left"||R.side==="right"?R.plot.height:R.plot.width,$=Number.isFinite(N)?L(String(R.text),Math.max(0,N),R.size):String(R.text);if(!$||$==="…")return;const S=J(R.group.ownerDocument,"text",{class:`${o}__axis-title`});if(ne(S,R.size),R.side==="left"){const Y=Math.max(R.size*1.15,R.plot.left-R.plot.gutter.left+R.size*1.15),Z=R.plot.top+R.plot.height/2;ue(S,{transform:`translate(${z(Y)} ${z(Z)}) rotate(-90)`,"text-anchor":"middle"})}else if(R.side==="right"){const Y=R.plot.right+R.plot.gutter.right-R.size*1.15,Z=R.plot.top+R.plot.height/2;ue(S,{transform:`translate(${z(Y)} ${z(Z)}) rotate(90)`,"text-anchor":"middle"})}else ue(S,{x:z(R.plot.left+R.plot.width/2),y:z(R.plot.bottom+R.plot.gutter.bottom-2),"text-anchor":"middle"});fe(S,$),$!==String(R.text)&&S.setAttribute("aria-label",String(R.text)),R.group.appendChild(S)}function f(R){const{values:N,scale:$,size:S,horizontal:Y,label:Z}=R;if(N.length<2)return 1;let x=1/0;for(let se=1;se<N.length;se++){const de=Math.abs($.of(N[se])-$.of(N[se-1]));Number.isFinite(de)&&de<x&&(x=de)}if(!Number.isFinite(x))return 1;if(x<=0)return N.length;let ee=S*v+2;if(Y){let se=0;for(const de of N){const ye=String(Z(de)||"").length*S*B;ye>se&&(se=ye)}ee=se+A}return Math.max(1,Math.ceil(ee/x))}function d(R){const{gridGroup:N,axisGroup:$,plot:S,scale:Y,format:Z}=R,x=R.config||{},ee=Y.kind==="time"&&R.grid?c(R.grid,R.column):void 0,se=t(Y,x,ee),de=a(x,Z,R.grid),ye=R.size||11,xe=f({values:se,scale:Y,size:ye,horizontal:!!R.horizontal,label:de}),me=j(R.overhang),Ne=x.grid===!1?null:N,Ae=Ne?new F(Ne):null,te=new F($);for(let re=0;re<se.length;re++){const le=se[re],pe=z(Y.of(le)),we=le===0,je=re%xe!==0;if(R.horizontal){if(Ae&&ue(Ae.next("line",`${o}__gridline`),{x1:pe,x2:pe,y1:z(S.top),y2:z(S.bottom),"stroke-opacity":we?1:.6,"stroke-width":we?1.5:1}),x.labels===!1||je)continue;const Be=de(le),Ue=String(Be).length*ye*B/2,qe=S.gutter;if(qe&&(pe-Ue<S.left-(qe.left||0)||pe+Ue>S.right+(qe.right||0)))continue;const ot=te.next("text",`${o}__tick`);ne(ot,ye),ue(ot,{x:pe,y:z(S.bottom+me),"text-anchor":"middle","dominant-baseline":"hanging"}),fe(ot,Be)}else{if(Ae&&ue(Ae.next("line",`${o}__gridline`),{x1:z(S.left),x2:z(S.right),y1:pe,y2:pe,"stroke-opacity":we?1:.6,"stroke-width":we?1.5:1}),x.labels===!1||je)continue;const Be=R.side==="right",Ue=de(le),qe=E(pe,S,ye);if(R.dropBottom&&Math.abs(pe-S.bottom)<=1){if(R.dropBottom===!0)continue;const tt=String(Ue).length*ye*B,he=Be?{left:S.right+me,right:S.right+me+tt}:{left:S.left-me-tt,right:S.left-me};he.top=qe-ye*.85,he.bottom=qe+ye*.6;const ie=R.dropBottom,ce=3;if(he.left<ie.right+ce&&he.right>ie.left-ce&&he.top<ie.bottom+ce&&he.bottom>ie.top-ce)continue}const ot=te.next("text",`${o}__tick`);ne(ot,ye),ue(ot,{x:z(Be?S.right+me:S.left-me),y:qe,"text-anchor":Be?"start":"end","dominant-baseline":"middle"}),fe(ot,Ue)}}return Ae?Ae.finish():new F(N).finish(),te.finish(),se}function E(R,N,$){const S=N&&N.gutter;if(!S)return R;const Y=N.top-(Number.isFinite(S.top)?S.top:0)+$*.85+1,Z=N.bottom+(Number.isFinite(S.bottom)?S.bottom:0)-$*.6-1;return z(Math.min(Math.max(R,Y),Math.max(Y,Z)))}function M(R){const{group:N,plot:$,scale:S,labels:Y}=R,Z=R.config||{};if(Z.labels===!1){new F(N).finish();return}const x=new F(N),ee=S.domain,se=S.step,de=Z.rotate===void 0||Z.rotate==="auto"?R.rotated:!!Z.rotate,ye=de?_({size:R.fontSize,floor:G(N),slot:se,per:Math.SQRT2,every:Z.every}):{size:R.fontSize,every:Number.isFinite(Z.every)&&Z.every>0?Number(Z.every):1,thinned:!1},{size:xe,every:me}=ye;p(ee.length,Z.every);const Ne=se*me;for(let Ae=0;Ae<ee.length;Ae++){const te=z(S.centre(ee[Ae]));if(Number.isNaN(te)||Ae%me!==0)continue;const re=x.next("text",`${o}__tick`);ne(re,xe);const le=Y[Ae]===void 0?"":Y[Ae];if(de){ue(re,{x:0,y:0,"text-anchor":"end","dominant-baseline":"middle",transform:`translate(${te} ${z($.bottom+A+2)}) rotate(-45)`});const pe=Ne*Math.SQRT2-xe*1.5,we=Math.max(0,$.gutter.bottom-A)*Math.SQRT2;q(re,le,Math.max(0,Math.min(we,pe)),xe)}else ue(re,{x:te,y:z($.bottom+A),"text-anchor":"middle","dominant-baseline":"hanging",transform:null}),q(re,le,Ne,xe)}x.finish()}function W(R){const{group:N,plot:$,scale:S,labels:Y,fontSize:Z}=R,x=R.config||{};if(x.labels===!1)return null;const ee=S.domain;if(!ee||!ee.length||!$.gutter)return null;const se=S.step,de=_({size:Z,floor:G(N),slot:se,per:Math.SQRT2,every:x.every}),{size:ye,every:xe}=de,me=z(S.centre(ee[0]));if(Number.isNaN(me))return null;const Ae=se*xe*Math.SQRT2-ye*1.5,te=Math.max(0,$.gutter.bottom-A)*Math.SQRT2,re=Math.max(0,Math.min(te,Ae)),le=String(Y[0]===void 0?"":Y[0]),we=L(le,re,ye).length*ye*r,je=ye*.6,Be=z($.bottom+A),Ue=Math.SQRT1_2;return{left:me-Ue*(we+je),right:me+Ue*je,top:Be-Ue*je,bottom:Be+Ue*(we+je)}}function oe(R){return Math.max(0,(R.gutter?R.gutter.left:R.left)-A)}function q(R,N,$,S){const Y=String(N??""),Z=L(Y,$,S);return fe(R,Z),Z!==Y?R.setAttribute("aria-label",Y):R.removeAttribute("aria-label"),Z}function Q(R){const{group:N,plot:$,scale:S,labels:Y}=R,Z=R.config||{},x=new F(N),ee=S.domain,se=oe($),de=Number.isFinite(R.per)&&R.per>0?R.per:v,ye=_({size:R.fontSize,floor:G(N),slot:S.step,per:de,every:Z.every}),{size:xe,every:me}=ye;p(ee.length,Z.every);for(let Ne=0;Ne<ee.length;Ne++){if(Ne%me!==0)continue;const Ae=z(S.centre(ee[Ne]));if(Number.isNaN(Ae))continue;const te=x.next("text",`${o}__tick`);ue(te,{x:z($.left-A),y:Ae,"text-anchor":"end","dominant-baseline":"middle"}),ne(te,xe),q(te,Y[Ne],se,xe)}x.finish()}function H(R){const{group:N,plot:$,scale:S,format:Y}=R,Z=R.config||{};if(Z.labels===!1){new F(N).finish();return}const x=a(Z,Y,R.grid,R.column),ee=R.size||11,se=$&&$.gutter,de=se&&Number.isFinite(se.left)?$.left-se.left:-1/0,ye=se&&Number.isFinite(se.right)?$.right+se.right:1/0,xe=j(R.overhang),me=new F(N),Ne=S.kind==="time"&&R.grid?c(R.grid,R.column):void 0;for(const Ae of t(S,Z,Ne)){const te=z(S.of(Ae));if(te<$.left-1||te>$.right+1)continue;const re=x(Ae),le=String(re).length*ee*B/2;if(te-le<de||te+le>ye)continue;const pe=me.next("text",`${o}__tick`);ne(pe,ee),ue(pe,{x:te,y:z($.bottom+xe),"text-anchor":"middle","dominant-baseline":"hanging"}),fe(pe,re)}me.finish()}function O(R){const{group:N,plot:$}=R,S=R.side==="right"?$.right:$.left,Y=new F(N);ue(Y.next("line"),{x1:z(S),x2:z(S),y1:z($.top),y2:z($.bottom)}),ue(Y.next("line"),{x1:z($.left),x2:z($.right),y1:z($.bottom),y2:z($.bottom)}),Y.finish()}let I=0;function K(R,N){const $=`${o}-plot-clip-${++I}`,S=J(R,"rect"),Y=J(R,"clipPath",{id:$});Y.appendChild(S);const Z=`${o}-box-clip-${I}`,x=J(R,"clipPath",{id:Z});x.appendChild(J(R,"rect",{x:0,y:0,width:"100%",height:"100%"}));const ee=J(R,"defs");ee.appendChild(Y),ee.appendChild(x);const se={grid:J(R,"g",{class:`${o}__grid`}),marks:J(R,"g",{class:`${o}__marks`}),rules:J(R,"g",{class:`${o}__axis`}),axis:J(R,"g",{class:`${o}__axis`}),labels:J(R,"g",{class:`${o}__labels`}),overlay:J(R,"g",{class:`${o}__overlay`}),clip:S,clipId:$,boxClipId:Z};N.appendChild(ee);for(const de of["grid","marks","rules","axis","labels","overlay"])N.appendChild(se[de]);return se}const g=30;function k(R){return R==="bubble"?g:R==="scatter"?6:3}function V(R,N,$){if(!R||!R.marks||!R.clip)return;if(!N||!Number.isFinite(N.width)||!Number.isFinite(N.height)){R.marks.removeAttribute("clip-path");return}const S=Number.isFinite($)&&$>=0?Number($):g;ue(R.clip,{x:z(N.left-S),y:z(N.top-S),width:z(Math.max(0,N.width)+S*2),height:z(Math.max(0,N.height)+S*2)}),R.marks.setAttribute("clip-path",`url(#${R.clipId})`)}}),rt("packages/modules/charts/stack.js",function(s,ae){"use strict";Object.defineProperty(s,"measureValues",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"stacker",{enumerable:!0,get:function(){return ue}});const F=ae("packages/modules/charts/scale.js").isNumber;function l(z,fe,J){if(J)return[0,100];if(!fe){const L=[];for(const D of z)for(const o of D.points)L.push(o.y);return L}const X=[],ne=[],B=z[0]?z[0].points.length:0;for(let L=0;L<B;L++){let D=0,o=0;for(const w of z){const y=w.points[L]?w.points[L].y:null;F(y)&&(y>=0?D+=y:o+=y)}X.push(D),ne.push(o)}return[...X,...ne]}function ue(z,fe){const J=new Float64Array(z),X=new Float64Array(z);return{take(ne,B){const L=fe?fe[ne]:0,D=fe?L?B/L*100:0:B;if(D>=0){const w=J[ne];return J[ne]+=D,[w,J[ne]]}const o=X[ne];return X[ne]+=D,[o,X[ne]]}}}}),rt("packages/modules/charts/labels.js",function(s,ae){"use strict";Object.defineProperty(s,"resolveLabels",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"collides",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"placeLabels",{enumerable:!0,get:function(){return c}}),Object.defineProperty(s,"labelText",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"drawAnchoredLabels",{enumerable:!0,get:function(){return b}}),Object.defineProperty(s,"drawDataLabels",{enumerable:!0,get:function(){return P}});const F=ae("packages/modules/charts/frame.js").Pool,l=ae("packages/modules/charts/format.js"),ue=l.measureText,z=l.stringFormatter,fe=ae("packages/modules/charts/svg.js"),J=fe.attrs,X=fe.round,ne=fe.setText,L=ae("packages/modules/charts/styles.js").NS,D=ae("packages/modules/charts/typography.js"),o=D.applySize,w=D.textWidth,y=4;function i(u){const A=u&&u.labels;if(!A)return{show:!1,names:A!==!1,position:"outside",format:null,minGap:2,total:!1};const r=typeof A=="object"?A:{};return{show:!0,names:!0,position:["outside","inside","auto"].includes(r.position)?r.position:"outside",format:r.format||null,minGap:Number.isFinite(r.minGap)?Number(r.minGap):2,total:!!r.total}}function h(u,A,r){for(const j of A)if(u.x-r<j.x+j.width&&u.x+u.width+r>j.x&&u.y-r<j.y+j.height&&u.y+u.height+r>j.y)return!0;return!1}function c(u){const{points:A,plot:r,size:j}=u,C=u.minGap===void 0?2:u.minGap,G=[],_=[];for(const T of A){if(T.px===void 0||T.py===void 0)continue;const p=u.text(T);if(!p)continue;const v=w(p,j),n=j;let t=T.px,a=T.py-y,e="middle",f=!1;u.horizontal?(t=T.px+y,a=T.py,e="start",u.position!=="outside"&&T.pbase!==void 0&&Math.abs(T.px-T.pbase)>v+y*2&&(t=T.px-y,e="end",f=!0)):u.position!=="outside"&&T.pbase!==void 0&&Math.abs(T.pbase-T.py)>n+y*2&&(a=T.py+n+y,f=!0);const d=()=>({x:e==="middle"?t-v/2:e==="end"?t-v:t,y:a-n,width:v,height:n});let E=d();!(E.y>=r.top-1)&&!f&&!u.horizontal&&T.pbase!==void 0&&Math.abs(T.pbase-T.py)>n+y*2&&(a=T.py+n+y,f=!0,E=d()),!(E.x+E.width<=r.right+1)&&!f&&u.horizontal&&T.pbase!==void 0&&Math.abs(T.px-T.pbase)>v+y*2&&(t=T.px-y,e="end",f=!0,E=d()),!(E.x<r.left-1||E.x+E.width>r.right+1)&&(E.y<r.top-1||E.y+E.height>r.bottom+n||h(E,G,C)||(G.push(E),_.push({x:X(t),y:X(a),text:p,anchor:e,inside:f})))}return _}function m(u,A,r){if(u==null)return"";if(typeof A.format=="function")return String(A.format(u));if(typeof A.format=="string"){const j=z(A.format,r,"labels.format");if(j)return j(u)}return ue(u,r&&r.messages)}function b(u){const A=new F(u.group),r=u.minGap===void 0?2:u.minGap,j=u.size,C=[];let G=0;for(const _ of u.anchors){if(!_||!_.text)continue;const T=_.width===void 0?w(_.text,u.size):_.width,p=_.anchor||"middle",n={x:p==="end"?_.x-T:p==="start"?_.x:_.x-T/2,y:_.y-j/2,width:T,height:j};if(u.plot&&(n.x<u.plot.left-1||n.x+n.width>u.plot.right+1||n.y<u.plot.top-1||n.y+n.height>u.plot.bottom+1)||_.width!==void 0&&T>_.width||_.height!==void 0&&j>_.height||h(n,C,r))continue;C.push(n);const t=A.next("text",_.className||`${L}__data-label`);o(t,u.size),J(t,{x:X(_.x),y:X(_.y),"text-anchor":p,"dominant-baseline":_.baseline||"middle","data-inside":_.inside?"true":null}),ne(t,_.text),G++}return A.finish(),G}function P(u){const A=new F(u.group),{options:r}=u;let j=0;const C=G=>typeof r.format=="function"&&G.y!==null&&G.y!==void 0?String(r.format(G.y,G)):m(G.y,r,u.grid);for(const G of u.series){const _=c({points:G.points,plot:u.plot,size:u.size,position:r.position,horizontal:u.horizontal,minGap:r.minGap,text:C});for(const T of _){const p=A.next("text",`${L}__data-label`);o(p,u.size),J(p,{x:T.x,y:T.y,"text-anchor":T.anchor,"data-inside":T.inside?"true":null}),ne(p,T.text),j++}}return A.finish(),j}}),rt("packages/modules/charts/dense.js",function(s,ae){"use strict";Object.defineProperty(s,"CANVAS_THRESHOLD",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(s,"downsample",{enumerable:!0,get:function(){return F}}),Object.defineProperty(s,"markCount",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"wantsCanvas",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"paintDense",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"sizeCanvas",{enumerable:!0,get:function(){return fe}});const ve=3e3;function F(J,X){const ne=J.length;if(!Number.isFinite(X)||X>=ne||X<3||ne<3)return J;const B=[J[0]],L=(ne-2)/(X-2);let D=0;for(let o=0;o<X-2;o++){const w=Math.floor(o*L)+1,y=Math.min(Math.floor((o+1)*L)+1,ne-1),i=y,h=Math.min(Math.floor((o+2)*L)+1,ne);let c=0,m=0,b=0;for(let r=i;r<h;r++){const j=J[r];!j||!Number.isFinite(j.y)||(c+=j.x,m+=j.y,b++)}b&&(c/=b,m/=b);const P=J[D];if(w>=y)continue;let u=w,A=-1;for(let r=w;r<y;r++){const j=J[r];if(!j||!Number.isFinite(j.y))continue;const C=Math.abs((P.x-c)*(j.y-P.y)-(P.x-j.x)*(m-P.y));C>A&&(A=C,u=r)}u<=D||(B.push(J[u]),D=u)}return B.push(J[ne-1]),B}function l(J){let X=0;for(const ne of J)X+=ne.points.length;return X}function ue(J){if(J.canvas===!0)return!0;if(J.canvas===!1)return!1;const X=Number.isFinite(J.canvas)?Number(J.canvas):ve;return l(J.series)>X}function z(J){const{context:X,series:ne,ratio:B}=J;X.save(),X.scale(B,B);for(const L of ne){const D=J.colour(L.index);if(J.type==="scatter"||J.type==="bubble"){X.fillStyle=D;for(const w of L.points)w.px!==void 0&&(X.beginPath(),X.arc(w.px,w.py,w.pr||2,0,Math.PI*2),X.fill());continue}X.strokeStyle=D,X.lineWidth=2,X.lineJoin="round",X.beginPath();let o=!1;for(const w of L.points){if(w.px===void 0||w.py===void 0){o=!1;continue}o?X.lineTo(w.px,w.py):X.moveTo(w.px,w.py),o=!0}X.stroke()}X.restore()}function fe(J){const{canvas:X}=J;return X.width=Math.max(1,Math.round(J.width*J.ratio)),X.height=Math.max(1,Math.round(J.height*J.ratio)),X.style&&(X.style.width=`${J.width}px`,X.style.height=`${J.height}px`),typeof X.getContext=="function"?X.getContext("2d"):null}}),rt("packages/modules/charts/annotations.js",function(s,ae){"use strict";Object.defineProperty(s,"overlayLayer",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"annotationValue",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"annotationAxis",{enumerable:!0,get:function(){return C}}),Object.defineProperty(s,"annotationText",{enumerable:!0,get:function(){return G}}),Object.defineProperty(s,"drawAnnotations",{enumerable:!0,get:function(){return T}});const F=ae("packages/modules/charts/frame.js").Pool,l=ae("packages/modules/charts/scale.js"),ue=l.isNumber,z=l.toNumber,fe=l.toTime,J=ae("packages/modules/charts/svg.js"),X=J.attrs,ne=J.path,B=J.round,L=J.setText,D=J.SVG_NS,w=ae("packages/modules/charts/styles.js").NS,i=ae("packages/core/src/internal/util.js").warnOnce;function h(p,v){for(const t of p.childNodes||[])if(t&&String(t.getAttribute&&t.getAttribute("class"))===v)return t;const n=p.ownerDocument.createElementNS(D,"g");return n.setAttribute("class",v),p.appendChild(n),n}const c=new Set(["line","target","band","callout","event"]);function m(p,v){return p.kind==="time"?fe(v):z(v)}function b(p,v,n){if(p.kind==="band"){const a=p.of(v);if(!Number.isFinite(a))return NaN;const e=Number(p.bandwidth)||0;return n==="right"?a+e:a}const t=m(p,v);return t===null?NaN:p.of(t)}function P(p,v,n){const t=p.kind||"line",a=p.label?` (${JSON.stringify(p.label)})`:"";i(`chart:annotation:dropped:${t}:${v}:${n}`,`chart annotation${a} of kind ${JSON.stringify(t)}, reading the ${v} axis, was not drawn: ${n}.`)}function u(p,v){if(p instanceof Date){const t=p.getTime();return Number.isFinite(t)?p.toISOString().slice(0,10):String(p)}if(typeof p=="number")return Number.isFinite(p)?v(p):String(p);const n=z(p);return n===null||typeof p=="string"?String(p):v(n)}function A(p,v,n){const t=[];for(const a of p)if((a.axis==="right"?"right":"left")===n&&!(v.series!==void 0&&a.key!==v.series))for(const f of a.points)ue(f.y)&&t.push(Number(f.y));return t}function r(p,v){if(!p.length)return null;const n=[...p].sort((f,d)=>f-d);if(n.length===1)return n[0];const t=Math.min(100,Math.max(0,v))/100*(n.length-1),a=Math.floor(t),e=Math.ceil(t);return a===e?n[a]:n[a]+(n[e]-n[a])*(t-a)}function j(p,v,n){if(!p.compute)return z(p.value);const t=A(v,p,n);if(!t.length)return null;const a=String(p.compute).toLowerCase();if(a==="mean"||a==="avg")return t.reduce((f,d)=>f+d,0)/t.length;if(a==="median"||a==="p50")return r(t,50);if(a==="min")return Math.min(...t);if(a==="max")return Math.max(...t);const e=/^p(\d+(?:\.\d+)?)$/.exec(a);return e?r(t,Number(e[1])):null}function C(p){return p.axis==="right"||p.axis==="y2"?"right":"left"}function G(p,v,n,t){const a=p.label?`${p.label}: `:"",e=t?` (${C(p)==="right"?"right axis":"left axis"})`:"",f=p.kind||"line";if(f==="band"){if(!Array.isArray(v)||v[0]===null||v[1]===null)return"";const[E,M]=v;return`${a||"Band: "}${n(Math.min(E,M))} to ${n(Math.max(E,M))}${e}`}return v==null?"":`${a||`${f==="target"?"Target":f==="callout"?"Callout":"Reference"}: `}${n(v)}${e}`}function _(p){return(p.kind||"line")==="band"?0:1}function T(p){const{group:v,plot:n,xScale:t,yScale:a,rightScale:e,series:f,format:d}=p,E=new F(h(v,`${w}__annotations`)),M=[],oe=[...Array.isArray(p.annotations)?p.annotations:[]].sort((q,Q)=>_(q)-_(Q));for(const q of oe){const Q=q.kind||"line";if(!c.has(Q))continue;const H=C(q),O=H==="right"&&e?e:a;if(Q==="band"){if(q.orient==="vertical"){const $=b(t,q.from,"left"),S=b(t,q.to,"right");if(Number.isNaN($)||Number.isNaN(S)){const ee=Number.isNaN($)&&Number.isNaN(S)?"from and to":Number.isNaN($)?"from":"to";P(q,H,`its ${ee} value could not be placed on the x scale`);continue}const Y=B(Math.min($,S)),Z=B(Math.max($,S));if(X(E.next("rect",`${w}__annotation-band ${q.className||""}`.trim()),{x:Y,y:B(n.top),width:Math.max(0,Z-Y),height:B(Math.max(0,n.bottom-n.top)),fill:q.colour||"currentColor","fill-opacity":q.opacity===void 0?.12:q.opacity}),q.label){const ee=E.next("text",`${w}__annotation-label`);X(ee,{x:Y+4,y:B(n.top+12),"text-anchor":"start"}),L(ee,q.label)}const x=q.label?`${q.label}: `:"Event window: ";M.push({text:`${x}${u(q.from,d)} to ${u(q.to,d)}`});continue}const k=j({...q,value:q.from,compute:q.fromCompute},f,H),V=j({...q,value:q.to,compute:q.toCompute},f,H);if(k===null||V===null){P(q,H,`its ${k===null&&V===null?"from and to":k===null?"from":"to"} value could not be resolved (a number, or a compute that finds values)`);continue}const R=B(O.of(k)),N=B(O.of(V));if(X(E.next("rect",`${w}__annotation-band ${q.className||""}`.trim()),{x:B(n.left),y:Math.min(R,N),width:B(Math.max(0,n.right-n.left)),height:Math.max(0,Math.abs(N-R)),fill:q.colour||"currentColor","fill-opacity":q.opacity===void 0?.12:q.opacity}),q.label){const $=E.next("text",`${w}__annotation-label`);X($,{x:B(n.left+4),y:Math.min(R,N)+12,"text-anchor":"start"}),L($,q.label)}M.push({text:G(q,[k,V],d,p.dual)});continue}if(Q==="event"){const k=q.x!==void 0?q.x:q.at,V=B(b(t,k,"left")+(t.kind==="band"?(Number(t.bandwidth)||0)/2:0));if(Number.isNaN(V)){P(q,H,"its x value could not be placed on the x scale");continue}if(X(E.next("path",`${w}__annotation-event`),{d:ne(["M",V,B(n.top),"L",V,B(n.bottom)]),stroke:q.colour||"currentColor",fill:"none"}),X(E.next("circle",`${w}__annotation-event-flag`),{cx:V,cy:B(n.top),r:3,fill:q.colour||"currentColor"}),q.label){const N=E.next("text",`${w}__annotation-label`);X(N,{x:V+5,y:B(n.top+10),"text-anchor":"start"}),L(N,q.label)}const R=q.label?`${q.label} — `:"Event — ";M.push({text:`${R}at ${u(k,d)}`});continue}if(Q==="callout"){const k=j(q,f,H);if(k===null){P(q,H,"its value could not be resolved (a number, or a compute that finds values)");continue}const V=q.at!==void 0?B(t.kind==="band"?t.centre(q.at):t.of(m(t,q.at)??NaN)):B(n.right-4),R=B(O.of(k));if(Number.isNaN(V)){P(q,H,"its x value could not be placed on the x scale");continue}if(X(E.next("circle",`${w}__annotation-point`),{cx:V,cy:R,r:3.5,fill:q.colour||"currentColor"}),q.label){const N=E.next("text",`${w}__annotation-label`);X(N,{x:V+6,y:R-6,"text-anchor":"start"}),L(N,q.label)}M.push({text:G(q,k,d,p.dual)});continue}if(q.orient==="vertical"||q.x!==void 0){const k=q.x!==void 0?q.x:q.value,V=t.kind==="band"?B(t.centre(k)):B(t.of(m(t,k)??NaN));if(Number.isNaN(V)){P(q,H,"its x value could not be placed on the x scale");continue}const R=Q==="target"?`${w}__annotation-target`:`${w}__annotation-line`;if(X(E.next("path",R),{d:ne(["M",V,B(n.top),"L",V,B(n.bottom)]),stroke:q.colour||"currentColor",fill:"none"}),q.label){const N=E.next("text",`${w}__annotation-label`);X(N,{x:V+4,y:B(n.top+10),"text-anchor":"start"}),L(N,q.label)}M.push({text:q.label?`${q.label} — at ${u(k,d)}`:""});continue}const I=j(q,f,H);if(I===null){P(q,H,"its value could not be resolved (a number, or a compute that finds values)");continue}const K=B(O.of(I)),g=Q==="target"?`${w}__annotation-target`:`${w}__annotation-line`;if(X(E.next("path",g),{d:p.horizontal?ne(["M",K,B(n.top),"L",K,B(n.bottom)]):ne(["M",B(n.left),K,"L",B(n.right),K]),stroke:q.colour||"currentColor",fill:"none"}),q.label){const k=E.next("text",`${w}__annotation-label`);X(k,p.horizontal?{x:K+4,y:B(n.top+10),"text-anchor":"start"}:{x:B(n.right-4),y:K-4,"text-anchor":"end"}),L(k,q.label)}M.push({text:G(q,I,d,p.dual)})}return E.finish(),M.filter(q=>q.text)}}),rt("packages/modules/charts/combo.js",function(s,ae){"use strict";Object.defineProperty(s,"toPareto",{enumerable:!0,get:function(){return N}}),Object.defineProperty(s,"drawCombo",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(s,"drawRightAxis",{enumerable:!0,get:function(){return Z}});const ve=ae("packages/modules/charts/axis.js"),F=ve.drawAxisLines,l=ve.drawAxisTitle,ue=ve.drawCategoryAxis,z=ve.drawContinuousAxis,fe=ve.drawMeasureAxis,J=ve.heldInside,X=ve.turnedFirstLabelBox,ne=ve.labelGap,B=ve.overhangFor,L=ve.pinXDomain,D=ve.setPlotClip,o=ve.tickLabeller,w=ve.tickValues,y=ae("packages/modules/charts/frame.js"),i=y.Pool,h=y.shouldRotate,m=ae("packages/modules/charts/format.js").formatters,b=ae("packages/modules/charts/scale.js"),P=b.bandScale,u=b.extent,A=b.isNumber,r=b.linearScale,j=b.measureDomain,C=b.timeScale,G=b.toNumber,_=b.toTime,T=ae("packages/modules/charts/stack.js"),p=T.measureValues,v=T.stacker,n=ae("packages/modules/charts/svg.js"),t=n.attrs,a=n.path,e=n.round,d=ae("packages/modules/charts/styles.js").NS,M=ae("packages/modules/charts/scheme.js").resolveScheme,oe=ae("packages/modules/charts/labels.js").drawDataLabels,Q=ae("packages/modules/charts/annotations.js").drawAnnotations,H=ae("packages/modules/charts/curve.js"),O=H.curveCommands,I=H.resolveCurve;function K(x){return{left:x.filter(ee=>ee.axis!=="right"),right:x.filter(ee=>ee.axis==="right")}}function g(x,ee){const se=x&&x.seriesStyle&&x.seriesStyle[ee];if(se)return{width:se.width!=null?String(se.width):null,dash:Array.isArray(se.dash)&&se.dash.length?se.dash.join(" "):null,opacity:null,emphasized:!1};const de=x&&Array.isArray(x.emphasis)?x.emphasis:null;if(!de||!de.length)return{width:null,dash:null,opacity:null,emphasized:!1};const ye=de.includes(ee);return{width:ye?"var(--lattice-chart-emphasis-width, 3.5)":null,dash:null,opacity:ye?null:"var(--lattice-chart-muted-opacity, .35)",emphasized:ye}}function k(x,ee,se,de,ye=null){const xe=[];let me=[];const Ne=()=>{me.length===1?xe.push("M",me[0].x,me[0].y):me.length>1&&xe.push(...O(me,ye)),me=[]};for(const Ae of ee.points){if(Ae.px===void 0){Ne();continue}me.push({x:Ae.px,y:Ae.py})}Ne(),t(x.next("path",`${d}__line ${d}__mark`),{d:xe.length?a(xe):"",stroke:se,"data-series":ee.index,"stroke-width":de.width,"stroke-dasharray":de.dash,opacity:de.opacity});for(const Ae of ee.points)Ae.px!==void 0&&t(x.next("circle",`${d}__point ${d}__mark`),{cx:Ae.px,cy:Ae.py,r:3,fill:se})}function V(x,ee){return ee?{tick:se=>`${x.tick(se)}%`,value:se=>`${x.value(se)}%`}:x}function R(x,ee,se,de,ye){const xe=x.filter(Ae=>(Ae.mark||"bar")==="bar"),me=x.filter(Ae=>(Ae.mark||"bar")!=="bar"),Ne=de?p(xe,!0,!0):se?[...p(xe,!0,!1),...me.length?p(me,!1,!1):[]]:p(x,!1,!1);return j(Ne,{zero:ee,min:ye&&ye.min,max:ye&&ye.max})}function N(x){const ee=x.series[0];if(!ee)return x;const se=ee.points.map((me,Ne)=>({point:me,label:x.labels[Ne],category:x.categories[Ne]})).filter(me=>A(me.point.y)).sort((me,Ne)=>Ne.point.y-me.point.y),de=se.reduce((me,Ne)=>me+Ne.point.y,0);let ye=0;const xe=se.map(me=>(ye+=me.point.y,de>0?ye/de*100:0));return{...x,categories:se.map(me=>me.category),labels:se.map(me=>me.label),series:[{...ee,index:0,mark:"bar",axis:"left",points:se.map(me=>me.point)},{key:"cumulative",label:x.cumulativeLabel||"%",index:1,mark:"line",axis:"right",points:se.map((me,Ne)=>({x:me.category,xKey:me.point.xKey,label:me.label,y:xe[Ne],rows:me.point.rows,rowKey:me.point.rowKey}))}]}}function $(x,ee,se){const de=[ee.left,ee.right];if(x.kind!=="time"&&x.kind!=="linear")return P(x.categories,de,.2);const ye=x.kind==="time"?x.categories.map(_):x.categories.map(G);if(x.kind==="time"){const Ne=u(ye);if(Ne&&Ne.min===Ne.max)return C(L({min:Ne.min-3e4,max:Ne.max+3e4},x,se),de)}const xe=x.xDomain||j(ye,{zero:!1,nice:x.kind!=="time"}),me=x.xDomain?xe:L(xe,x,se);return x.kind==="time"?C(me,de):r(me,de)}function S(x,ee){const se=[...new Set(x.filter(Ne=>Number.isFinite(Ne)))].sort((Ne,Ae)=>Ne-Ae);if(se.length<2){const[Ne,Ae]=ee.range;return Math.max(4,(Ae-Ne)/10)}const de=[];for(let Ne=1;Ne<se.length;Ne++)de.push(se[Ne]-se[Ne-1]);de.sort((Ne,Ae)=>Ne-Ae);const ye=Math.floor(de.length/2),xe=de.length%2?de[ye]:(de[ye-1]+de[ye])/2,me=Math.abs(ee.of(se[0]+xe)-ee.of(se[0]));return Math.max(1,me*.8)}function Y(x){const ee=x.scheme||M(),se=x.axis||{x:{},y:{},y2:{}},{plot:de}=x,ye=x.pareto?N(x.bound):x.bound,xe=ye.series.filter(Pe=>!x.hidden.has(Pe.key)),me=K(xe),Ne=Pe=>(Pe.mark||"bar")==="bar",Ae=me.left.some(Ne),te=me.left.filter(Ne),re=x.stack==="percent"&&te.length>1&&!me.right.length,le=(re||!!x.stack)&&te.length>1&&!me.right.length,pe=ye.yDomain||R(me.left,Ae,le,re,se.y),we=r(pe,[de.bottom,de.top]),je=me.right.length?x.pareto?{min:0,max:100}:R(me.right,me.right.some(Ne),!1,!1,se.y2):null,Be=je?r(je,[de.bottom,de.top]):null,Ue=$(ye,de,se.x),qe=Ue.kind!=="band",ot=qe?ye.categories.map(Pe=>ye.kind==="time"?_(Pe):G(Pe)):null,tt=qe&&xe.some(Pe=>(Pe.mark||"bar")==="bar")?S(ot,Ue)/2:0,ie=!qe&&(se.x.rotate===void 0||se.x.rotate==="auto"?h(ye.labels,Ue.step,x.fontSize):!!se.x.rotate)&&X({group:x.groups.overlay,plot:de,scale:Ue,labels:ye.labels,fontSize:x.fontSize,config:se.x}),ce=se.y.position==="right"?"right":"left";fe({gridGroup:x.groups.grid,axisGroup:x.groups.axis,plot:de,scale:we,format:V(m(x.grid,{kind:"linear",step:(pe.max-pe.min)/5}),re),config:se.y,grid:x.grid,size:x.fontSize,side:ce,overhang:tt,dropBottom:ie});const Oe=ye.dimension&&ye.dimension.col?x.grid.columns.get(ye.dimension.col):void 0;qe?z({group:x.groups.overlay,plot:de,scale:Ue,format:m(x.grid,{kind:ye.kind,span:Ue.domain.max-Ue.domain.min,step:(Ue.domain.max-Ue.domain.min)/5},Oe),config:se.x,grid:x.grid,column:Oe,size:x.fontSize}):ue({group:x.groups.overlay,plot:de,scale:Ue,labels:ye.labels,fontSize:x.fontSize,rotated:h(ye.labels,Ue.step,x.fontSize),config:se.x}),F({group:x.groups.rules,plot:de,side:ce});const be=x.typography&&x.typography.axisTitle||x.fontSize;if(l({group:x.groups.axis,plot:de,text:se.y.title,side:ce,size:be}),l({group:x.groups.axis,plot:de,text:se.x.title,side:"bottom",size:be}),Be){Z({group:x.groups.axis,plot:de,scale:Be,colour:ee.series(me.right[0].index,me.right[0].label),format:m(x.grid,{kind:"linear",step:(je.max-je.min)/5}),config:se.y2,grid:x.grid,suffix:x.pareto?"%":"",side:ce==="right"?"left":"right",overhang:tt});const Pe=se.y2.title||(me.right.length===1?me.right[0].label:"");l({group:x.groups.axis,plot:de,text:Pe,side:ce==="right"?"left":"right",size:be})}D(x.groups,de,B(x.type));const ge=new i(x.groups.marks),ke=xe.filter(Pe=>(Pe.mark||"bar")==="bar"),Ee=qe?S(ot,Ue):Ue.bandwidth,Re=le?Ee:ke.length?Ee/ke.length:Ee,ze=re?ye.categories.map((Pe,He)=>te.reduce((Ye,We)=>{const nt=We.points[He]?We.points[He].y:null;return A(nt)?Ye+Math.abs(nt):Ye},0)):null,Ge=le?v(ye.categories.length,ze):null;let Ke=0;const Ie=[];for(const Pe of xe){const He=Pe.mark||"bar",Ye=Pe.axis==="right"&&Be?Be:we,We=ee.series(Pe.index,Pe.label);if(He==="bar"){const ht=le?0:Ke*Re;Ke++;const st=Ye.of(Math.max(Ye.domain.min,0));for(let dt=0;dt<Pe.points.length;dt++){const vt=Pe.points[dt];if(!A(vt.y))continue;let St;if(qe){const Pt=ye.kind==="time"?_(vt.x):G(vt.x);St=Pt===null?NaN:Ue.of(Pt)-Ee/2}else St=Ue.of(vt.x);if(Number.isNaN(St))continue;const $t=Ge?Ge.take(dt,vt.y):null,At=Ye.of($t?$t[1]:vt.y),ft=$t?Ye.of($t[0]):st;t(ge.next("rect",`${d}__bar ${d}__mark`),{x:e(St+ht),y:e(Math.min(At,ft)),width:e(Math.max(0,Re)),height:e(Math.max(1,Math.abs(ft-At))),fill:We,"data-series":Pe.index,"data-point":dt}),vt.px=e(St+ht+Re/2),vt.py=e(Math.min(At,ft))}continue}for(const ht of Pe.points){if(!A(ht.y)){ht.px=void 0;continue}let st;if(qe){const vt=ye.kind==="time"?_(ht.x):G(ht.x);st=vt===null?NaN:e(Ue.of(vt))}else st=e(Ue.centre(ht.x));if(Number.isNaN(st)){ht.px=void 0;continue}const dt=e(Ye.of(ht.y));ht.px=st,ht.py=dt}const nt=g(x,Pe.label),ut=I(x.curve,Pe.label);nt.emphasized?Ie.push({series:Pe,colour:We,style:nt,curve:ut}):k(ge,Pe,We,nt,ut)}for(const Pe of Ie)k(ge,Pe.series,Pe.colour,Pe.style,Pe.curve);ge.finish(),x.labels&&x.labels.show&&oe({group:x.groups.labels,series:xe,plot:de,options:x.labels,grid:x.grid,size:x.typography&&x.typography.small||x.fontSize});let $e=null;return x.annotations&&x.annotations.length&&($e=Q({group:x.groups.overlay,plot:de,xScale:Ue,yScale:we,rightScale:Be,series:xe,annotations:x.annotations,dual:!!Be,format:m(x.grid,{kind:"linear",step:(pe.max-pe.min)/5}).tick})),{xScale:Ue,yScale:we,rightScale:Be,dual:!!Be,series:xe,bound:ye,annotations:$e,percent:re,percentTotals:ze}}function Z(x){const{group:ee,plot:se,scale:de,format:ye}=x,xe=x.config||{},me=x.side==="left"?"left":"right",Ne=me==="right"?se.right:se.left,Ae=o(xe,ye,x.grid),te=new i(ee,ee.childNodes.length),re=ne(x.overhang);t(te.next("line",`${d}__axis-right`),{x1:e(Ne),x2:e(Ne),y1:e(se.top),y2:e(se.bottom),stroke:x.colour});for(const le of w(de,xe)){const pe=e(de.of(le)),we=te.next("text",`${d}__tick`);t(we,{x:e(me==="right"?se.right+re:se.left-re),y:J(pe,se,11),"text-anchor":me==="right"?"start":"end","dominant-baseline":"middle",fill:x.colour}),we.textContent=`${Ae(le)}${x.suffix||""}`}te.finish()}}),rt("packages/modules/charts/quantile.js",function(s,ae){"use strict";Object.defineProperty(s,"normalQuantile",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"studentTQuantile",{enumerable:!0,get:function(){return B}});const ve=Object.freeze([676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23]),F=3e-12,l=1e-300;function ue(L){if(L<.5)return Math.log(Math.PI/Math.sin(Math.PI*L))-ue(1-L);const D=L-1;let o=.9999999999998099;const w=D+7.5;for(let y=0;y<ve.length;y++)o+=ve[y]/(D+y+1);return .5*Math.log(2*Math.PI)+(D+.5)*Math.log(w)-w+Math.log(o)}function z(L,D,o){const w=L+D,y=L+1,i=L-1;let h=1,c=1-w*o/y;Math.abs(c)<l&&(c=l),c=1/c;let m=c;for(let b=1;b<=300;b++){const P=2*b;let u=b*(D-b)*o/((i+P)*(L+P));c=1+u*c,Math.abs(c)<l&&(c=l),h=1+u/h,Math.abs(h)<l&&(h=l),c=1/c,m*=c*h,u=-(L+b)*(w+b)*o/((L+P)*(y+P)),c=1+u*c,Math.abs(c)<l&&(c=l),h=1+u/h,Math.abs(h)<l&&(h=l),c=1/c;const A=c*h;if(m*=A,Math.abs(A-1)<F)break}return m}function fe(L,D,o){if(!(L>0)||!(D>0)||!Number.isFinite(o))return Number.NaN;if(o<=0)return 0;if(o>=1)return 1;const w=Math.exp(ue(L+D)-ue(L)-ue(D)+L*Math.log(o)+D*Math.log(1-o));return o<(L+1)/(L+D+2)?w*z(L,D,o)/L:1-w*z(D,L,1-o)/D}function J(L){const D=Math.abs(L),o=2/(2+D),w=4*o-2,y=[-1.3026537197817094,.6419697923564902,.019476473204185836,-.00956151478680863,-.000946595344482036,.000366839497852761,42523324806907e-18,-20278578112534e-18,-1624290004647e-18,130365583558e-17,15626441722e-18,-85238095915e-18,6529054439e-18,5059343495e-18,-991364156e-18,-227365122e-18,96467911e-18,2394038e-18,-6886027e-18,894487e-18,313092e-18,-112708e-18,381e-18,7106e-18];let i=0,h=0,c;for(let b=y.length-1;b>0;b--)c=h,h=w*h-i+y[b],i=c;const m=o*Math.exp(-D*D+.5*(y[0]+w*h)-i);return L>=0?m:2-m}function X(L){if(!(L>0)||!(L<1))return L===0?-1/0:L===1?1/0:Number.NaN;const D=[-39.69683028665376,220.9460984245205,-275.9285104469687,138.357751867269,-30.66479806614716,2.506628277459239],o=[-54.47609879822406,161.5858368580409,-155.6989798598866,66.80131188771972,-13.28068155288572],w=[-.007784894002430293,-.3223964580411365,-2.400758277161838,-2.549732539343734,4.374664141464968,2.938163982698783],y=[.007784695709041462,.3224671290700398,2.445134137142996,3.754408661907416],i=.02425;let h,c,m;L<i?(h=Math.sqrt(-2*Math.log(L)),m=(((((w[0]*h+w[1])*h+w[2])*h+w[3])*h+w[4])*h+w[5])/((((y[0]*h+y[1])*h+y[2])*h+y[3])*h+1)):L<=1-i?(h=L-.5,c=h*h,m=(((((D[0]*c+D[1])*c+D[2])*c+D[3])*c+D[4])*c+D[5])*h/(((((o[0]*c+o[1])*c+o[2])*c+o[3])*c+o[4])*c+1)):(h=Math.sqrt(-2*Math.log(1-L)),m=-(((((w[0]*h+w[1])*h+w[2])*h+w[3])*h+w[4])*h+w[5])/((((y[0]*h+y[1])*h+y[2])*h+y[3])*h+1));const P=(.5*J(-m/Math.SQRT2)-L)*Math.sqrt(2*Math.PI)*Math.exp(m*m/2);return m-P/(1+m*P/2)}function ne(L,D){if(!(D>0)||!Number.isFinite(L))return Number.NaN;const o=.5*fe(D/2,.5,D/(D+L*L));return L>0?1-o:o}function B(L,D){if(!(L>0)||!(L<1)||!(D>0))return Number.NaN;if(D>1e7)return X(L);let o=-1e4,w=1e4,y=X(L);const i=ue(D/2)+ue(.5)-ue((D+1)/2);for(let h=0;h<60;h++){const c=ne(y,D);c<L?o=y:w=y;const m=Math.exp(-((D+1)/2)*Math.log(1+y*y/D)-i)/Math.sqrt(D),b=m>0?(c-L)/m:0;if(Math.abs(b)<1e-12)break;const P=y-b;if(y=P>o&&P<w&&Number.isFinite(P)?P:(o+w)/2,w-o<1e-12)break}return y}}),rt("packages/modules/charts/trendline.js",function(s,ae){"use strict";Object.defineProperty(s,"normaliseTrends",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"linearTrend",{enumerable:!0,get:function(){return T}}),Object.defineProperty(s,"movingAverageTrend",{enumerable:!0,get:function(){return p}}),Object.defineProperty(s,"exponentialTrend",{enumerable:!0,get:function(){return a}}),Object.defineProperty(s,"computeTrend",{enumerable:!0,get:function(){return e}}),Object.defineProperty(s,"trendText",{enumerable:!0,get:function(){return f}}),Object.defineProperty(s,"drawTrendlines",{enumerable:!0,get:function(){return d}});const F=ae("packages/modules/charts/frame.js").Pool,l=ae("packages/modules/charts/svg.js"),ue=l.attrs,z=l.path,fe=l.ribbonPath,J=l.round,X=l.setText,ne=l.SVG_NS,L=ae("packages/modules/charts/typography.js").applySize,o=ae("packages/modules/charts/styles.js").NS,w=ae("packages/modules/charts/scale.js"),y=w.toNumber,i=w.toTime,c=ae("packages/modules/charts/quantile.js").studentTQuantile,b=ae("packages/modules/charts/format.js").r2Digits,P={linear:new Set(["linear","lr","ols","regression","least-squares"]),movingAverage:new Set(["movingaverage","moving-average","ma","sma","rolling"]),exponential:new Set(["exponential","exp","ewma","ses","holt","smoothing"])},u=1e-4,A=1-1e-4;function r(E){const M=String(E||"linear").toLowerCase();return P.linear.has(M)?"linear":P.movingAverage.has(M)?"movingAverage":P.exponential.has(M)?"exponential":null}function j(E){if(!E)return[];const M=Array.isArray(E)?E:[E],W=[];for(const oe of M){if(oe===!0){W.push({method:"linear"});continue}if(typeof oe=="string"){const q=r(oe);q&&W.push({method:q});continue}if(oe&&typeof oe=="object"){const q=r(oe.method);q&&W.push({...oe,method:q})}}return W}function C(E,M){if(E.kind==="band")return E.centre(M);const W=E.kind==="time"?i(M):y(M);return W===null?NaN:E.of(W)}function G(E){const M=[];for(const W of E.points){const oe=Number(W.y);M.push({value:Number.isFinite(oe)?oe:null,rawX:W.x})}return M}function _(E,M){const W=[];for(const oe of E.points){const q=M.kind==="time"?i(oe.x):y(oe.x),Q=Number(oe.y);q===null||!Number.isFinite(q)||!Number.isFinite(Q)||W.push({x:q,y:Q})}return W.sort((oe,q)=>oe.x-q.x),W}function T(E,M,W={}){const oe=E.length;if(oe<2)return null;let q=0,Q=0;for(const x of E)q+=x.x,Q+=x.y;q/=oe,Q/=oe;let H=0,O=0,I=0;for(const x of E){const ee=x.x-q,se=x.y-Q;H+=ee*ee,O+=ee*se,I+=se*se}if(H===0)return null;const K=O/H,g=Q-K*q,k=I===0?1:Math.max(0,Math.min(1,O*O/(H*I))),V=E[0].x,R=E[oe-1].x,N=x=>({x,y:g+K*x}),$=[N(V),N(R)],S=[];let Y=null;const Z=Math.max(0,Math.floor(Number(M)||0));if(Z>0&&R>V){const x=(R-V)/(oe-1);if(x>0&&(S.push(N(R),N(R+Z*x)),oe>2)){const ee=Number.isFinite(W.confidence)&&W.confidence>0&&W.confidence<1?Number(W.confidence):.95,se=1-(1-ee)/2,de=Math.max(0,I-K*O),ye=Math.sqrt(de/(oe-2)),xe=c(se,oe-2),me=[];for(let Ne=0;Ne<=Z;Ne++){const Ae=R+Ne*x,te=g+K*Ae,re=1/oe+(Ae-q)**2/H,le=ye*Math.sqrt(1+re),pe=ye*Math.sqrt(re);me.push({x:Ae,mean:te,lower:te-xe*le,upper:te+xe*le,lowerMean:te-xe*pe,upperMean:te+xe*pe})}Y={confidence:ee,points:me}}}return{fit:$,forecast:S,band:Y,stats:{method:"linear",slope:K,intercept:g,r2:k,n:oe,forecast:S.length?Z:0,confidence:Y?Y.confidence:null}}}function p(E,M){const W=Math.max(1,Math.floor(Number(M)||3)),oe=[];let q=0;const Q=[];for(const H of E)Number.isFinite(H.value)&&(oe.push(H.value),q+=H.value,oe.length>W&&(q-=oe.shift())),oe.length&&Q.push({x:H.rawX,y:q/oe.length});return Q.length<2?null:{fit:Q,stats:{method:"movingAverage",window:W}}}function v(E,M){const W=E.length,oe=new Array(W).fill(null);let q=null,Q=0;for(let H=0;H<W;H++){const O=E[H];if(!Number.isFinite(O)){q!==null&&(oe[H]=q);continue}if(q===null){q=O,oe[H]=O;continue}Q+=(O-q)**2,q=M*O+(1-M)*q,oe[H]=q}return{smoothed:oe,sse:Q}}function n(E,M,W){const oe=E.length,q=new Array(oe).fill(null);let Q=null,H=null,O=0;for(let I=0;I<oe;I++){const K=E[I];if(!Number.isFinite(K)){Q!==null&&(Q+=H,q[I]=Q);continue}if(Q===null){Q=K,q[I]=K;continue}if(H===null){H=K-Q;const V=Q+H;O+=(K-V)**2;const R=Q;Q=M*K+(1-M)*(R+H),H=W*(Q-R)+(1-W)*H,q[I]=Q;continue}const g=Q+H;O+=(K-g)**2;const k=Q;Q=M*K+(1-M)*(k+H),H=W*(Q-k)+(1-W)*H,q[I]=Q}return{smoothed:q,sse:O}}function t(E,M,W,oe=80){const q=(Math.sqrt(5)-1)/2;let Q=M,H=W,O=H-q*(H-Q),I=Q+q*(H-Q),K=E(O),g=E(I);for(let k=0;k<oe;k++)K<g?(H=I,I=O,g=K,O=H-q*(H-Q),K=E(O)):(Q=O,O=I,K=g,I=Q+q*(H-Q),g=E(I));return(Q+H)/2}function a(E,M){const W=String(M.kind||M.model||"").toLowerCase()==="holt",oe=E.map(g=>Number.isFinite(g.value)?g.value:null);if(oe.filter(g=>g!==null).length<(W?2:1))return null;const Q=g=>Math.min(A,Math.max(u,g));let H=Number.isFinite(M.alpha)?Q(Number(M.alpha)):null,O=W&&Number.isFinite(M.beta)?Q(Number(M.beta)):null;if(W){if(H===null||O===null){let g=H===null?.5:H,k=O===null?.5:O;for(let V=0;V<6;V++)H===null&&(g=t(R=>n(oe,R,k).sse,u,A)),O===null&&(k=t(R=>n(oe,g,R).sse,u,A));H=H===null?g:H,O=O===null?k:O}}else H===null&&(H=t(g=>v(oe,g).sse,u,A));const I=W?n(oe,H,O):v(oe,H),K=[];for(let g=0;g<E.length;g++){const k=I.smoothed[g];k===null||!Number.isFinite(k)||K.push({x:E[g].rawX,y:k})}return K.length<2?null:{fit:K,stats:{method:"exponential",kind:W?"holt":"ses",alpha:H,beta:W?O:null}}}function e(E,M,W){if(M.method==="linear"){const q=_(E,W);return T(q,M.forecast,{confidence:M.confidence})}const oe=G(E);return M.method==="movingAverage"?p(oe,M.window||M.period):a(oe,M)}function f(E,M,W,oe,q,Q){const H=M?` for ${M}`:"";if(E.method==="linear"){const g=Number.isFinite(E.r2)?`, R² ${E.r2.toFixed(2)}`:"";let k=`Trend (linear)${H}: slope ${W(E.slope)}${g}`;if(E.forecast>0&&oe&&oe.length){const V=oe[oe.length-1];if(k+=`; forecast ${E.forecast} step${E.forecast===1?"":"s"} ahead to ${W(V.y)}`,q&&q.points.length){const R=q.points[q.points.length-1],N=Q==="confidence"||Q==="mean",$=N?R.lowerMean:R.lower,S=N?R.upperMean:R.upper,Y=N?"confidence":"prediction",Z=Math.round(q.confidence*100);k+=`; ${Z}% ${Y} band ${W($)} to ${W(S)} at the horizon`}}return k}if(E.method==="movingAverage")return`Trend (moving average, window ${E.window})${H}`;const O=E.kind==="holt"?"Holt":"single",I=Number.isFinite(E.alpha)?`, α ${E.alpha.toFixed(2)}`:"",K=Number.isFinite(E.beta)?`, β ${E.beta.toFixed(2)}`:"";return`Trend (exponential, ${O})${H}${I}${K}`}function d(E){const M=j(E.trend);if(!M.length)return[];const W=E.group.ownerDocument;let oe=null;for(const H of E.group.childNodes||[])if(H&&String(H.getAttribute&&H.getAttribute("class"))===`${o}__trends`){oe=H;break}oe||(oe=W.createElementNS(ne,"g"),oe.setAttribute("class",`${o}__trends`),E.group.appendChild(oe)),E.clip?oe.setAttribute("clip-path",`url(#${E.clip})`):oe.removeAttribute("clip-path");const q=new F(oe),Q=[];for(const H of M)for(const O of E.series){const I=O.axis==="right"&&E.rightScale?E.rightScale:E.yScale,K=e(O,H,E.xScale);if(!K)continue;const g=E.scheme.series(O.index),k=[];for(const N of K.fit){const $=C(E.xScale,N.x),S=I.of(N.y);!Number.isFinite($)||!Number.isFinite(S)||k.push(k.length?"L":"M",J($),J(S))}if(k.length<4)continue;if(ue(q.next("path",`${o}__trend`),{d:z(k),fill:"none",stroke:g,"data-series":O.index}),H.band!==!1&&K.band&&K.band.points.length>=2){const N=H.band==="confidence"||H.band==="mean",$=[];for(const Y of K.band.points){const Z=C(E.xScale,Y.x),x=N?Y.lowerMean:Y.lower,ee=N?Y.upperMean:Y.upper,se=I.of(x),de=I.of(ee);!Number.isFinite(Z)||!Number.isFinite(se)||!Number.isFinite(de)||$.push({x:J(Z),lower:J(se),upper:J(de)})}const S=fe($);S&&ue(q.next("path",`${o}__trend-band`),{d:S,fill:g,"fill-opacity":.15,stroke:"none","data-series":O.index})}const R=K.forecast||[];if(R.length>=2){const N=[];for(const $ of R){const S=C(E.xScale,$.x),Y=I.of($.y);!Number.isFinite(S)||!Number.isFinite(Y)||N.push(N.length?"L":"M",J(S),J(Y))}N.length>=4&&ue(q.next("path",`${o}__trend-forecast`),{d:z(N),fill:"none",stroke:g,"data-series":O.index})}if(H.label!==!1&&K.stats.method==="linear"&&Number.isFinite(K.stats.r2)){const N=K.fit[K.fit.length-1],$=q.next("text",`${o}__trend-label`);L($,E.size),ue($,{x:J(C(E.xScale,N.x)),y:J(I.of(N.y))-4,"text-anchor":"end",fill:g}),X($,E.grid.messages.t("chart.r2",{value:b(E.grid,K.stats.r2)}))}Q.push({text:f(K.stats,O.label,E.format,R,H.band===!1?null:K.band,H.band)})}return q.finish(),Q.filter(H=>H.text)}}),rt("packages/modules/charts/rulecolour.js",function(s,ae){"use strict";Object.defineProperty(s,"colourOf",{enumerable:!0,get:function(){return F}}),Object.defineProperty(s,"ruleColour",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"ruleLegend",{enumerable:!0,get:function(){return ue}});const ve="*";function F(z){if(!z||typeof z!="object")return null;for(const fe of["background","backgroundColor","color"]){const J=z[fe];if(typeof J=="string"&&J.trim())return J.trim()}return null}function l(z){const{grid:fe,col:J,value:X}=z;if(!fe||!J||!fe.formatting||typeof fe.formatting.styleFor!="function")return null;try{return F(fe.formatting.styleFor(J,X))}catch{return null}}function ue(z){const{grid:fe,col:J}=z,X=new Set([...z.colours||[]].filter(Boolean));if(!X.size||!fe||!fe.formatting||typeof fe.formatting.list!="function")return[];let ne;try{ne=[...fe.formatting.list(ve)||[],...J?fe.formatting.list(J)||[]:[]]}catch{return[]}const B=[],L=new Set;for(const D of ne){if(!D||D.enabled===!1)continue;const o=F(D.style);!o||!X.has(o)||L.has(o)||(L.add(o),B.push({key:D.id||`rule:${B.length}`,label:D.label||D.id||o,colour:o,index:B.length}))}return B}}),rt("packages/modules/charts/glyph.js",function(s,ae){"use strict";Object.defineProperty(s,"glyphFor",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"glyphTransform",{enumerable:!0,get:function(){return fe}});const F=ae("packages/core/src/internal/util.js").warnOnce,ue=ae("packages/modules/charts/svg.js").round;function z(J,X,ne="node"){if(!X)return null;const B=ne==="marker",L=B?"a chart image marker":"a network node",D=J&&J.icons;if(!D||typeof D.get!="function")return F(`chart:icons:${X}`,`${L.charAt(0).toUpperCase()}${L.slice(1)} asked for the icon '${X}', but this grid publishes no icon registry — a headless grid has no sprites. The ${B?"point":"node"} drew as ${B?"its default marker":"a plain disc"}.`),null;const o=D.get(X);return o||(F(`chart:icon:${X}`,`Unknown icon '${X}' on ${L}; ${B?"kept the default marker":"drew a plain disc"} instead. Register it with registerIcon or config.icons, or name a built-in.`),null)}function fe(J,X){const ne=String(J.viewBox||"0 0 16 16").trim().split(/[\s,]+/).map(Number),[B,L,D,o]=ne.length===4&&ne.every(Number.isFinite)?ne:[0,0,16,16],w=Math.max(D||16,o||16),y=X.size/w,i=X.x-D*y/2,h=X.y-o*y/2;return`translate(${ue(i-B*y)} ${ue(h-L*y)}) scale(${ue(y)})`}}),rt("packages/modules/charts/markers.js",function(s,ae){"use strict";Object.defineProperty(s,"MARKER_SIZE",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"clearMarkerImages",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"resolveMarker",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"safeImageUrl",{enumerable:!0,get:function(){return y}}),Object.defineProperty(s,"imageOf",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"imageState",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"markerFor",{enumerable:!0,get:function(){return c}}),Object.defineProperty(s,"placeMarker",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"markerBoxHit",{enumerable:!0,get:function(){return b}});const F=ae("packages/core/src/internal/util.js").warnOnce,l=ae("packages/modules/charts/glyph.js"),ue=l.glyphFor,z=l.glyphTransform,J=ae("packages/modules/charts/styles.js").NS,X=16,ne=[6,64],B=/^data:image\/(png|jpe?g|gif|webp|avif|bmp|svg\+xml)[;,]/i,L=/^(https?:|blob:|data:|javascript:|vbscript:|file:|\/|\.\.?\/)|[/.]/i,D=new Map;function o(){D.clear()}function w(P){if(!P||typeof P!="object"||Array.isArray(P))return null;const u=P.image;if(u==null||u==="")return F("chart:marker:no-image",'chart "marker" needs an "image": an icon name, a URL, { col } or a function. No markers were drawn from it.'),null;const A=Number(P.size);return{image:u,size:Number.isFinite(A)?Math.min(ne[1],Math.max(ne[0],A)):X,explicitSize:Number.isFinite(A)}}function y(P){const u=String(P).trim(),A=/^([a-z][a-z0-9+.-]*):/i.exec(u);if(A){const r=A[1].toLowerCase();return r==="data"?B.test(u)?u:null:r==="http"||r==="https"||r==="blob"?u:null}return/^[^/]*:/.test(u)?null:u}function i(P,u,A){let r=P.image;if(typeof r=="function")try{r=r(u)}catch{r=null}else r&&typeof r=="object"&&typeof r.col=="string"&&(r=A&&A.rows&&u&&u.rowKey!==void 0&&u.rowKey!==null?A.rows.value(u.rowKey,r.col):null);return typeof r=="string"&&r.trim()?r.trim():null}function h(P,u,A){let r=D.get(P);if(r)return r.state==="loading"&&A&&r.waiting.add(A),r.state;const j=u&&u.defaultView,C=j&&j.Image;if(typeof C!="function")return"ok";r={state:"loading",waiting:new Set(A?[A]:[])},D.set(P,r);const G=new C,_=T=>{if(r.state=T,T==="failed"){const p=P.length>80?P.slice(0,77):P;F(`chart:marker:image-failed:${P}`,`a chart marker image could not be loaded (${p}); those points keep the default marker. Check the URL, and that the server allows the page to load it.`)}for(const p of r.waiting)try{p()}catch{}r.waiting.clear()};return G.onload=()=>_("ok"),G.onerror=()=>_("failed"),G.src=P,"loading"}function c(P,u,A){const r=i(P,u,A.grid);if(!r)return null;if(!L.test(r)){const C=ue(A.grid,r,"marker");return C?{kind:"icon",def:C}:null}const j=y(r);if(!j){const C=r.slice(0,40);return F(`chart:marker:unsafe-url:${C}`,`a chart marker image URL was refused (${C}): only http, https, blob, relative and data:image URLs are drawn. Those points keep the default marker.`),null}return h(j,A.doc,A.redraw)==="ok"?{kind:"image",href:j}:null}function m(P,u,A){const r=A.size/2;if(u.kind==="icon"){const C=u.def,G=C.paint==="stroke",_=P.next("path",`${J}__marker-icon ${J}__mark`);return A.attrs(_,{d:C.paths.join(" "),transform:z(C,{x:A.x,y:A.y,size:A.size}),fill:G?"none":A.colour,stroke:G?A.colour:null,"stroke-width":G?1.5:null,class:`${J}__marker-icon ${J}__mark`,...A.extra||{}}),_}const j=P.next("image",`${J}__marker-image ${J}__mark`);return A.attrs(j,{href:u.href,x:A.round(A.x-r),y:A.round(A.y-r),width:A.size,height:A.size,preserveAspectRatio:"xMidYMid meet",class:`${J}__marker-image ${J}__mark`,...A.extra||{}}),j}function b(P,u,A){return Math.abs(u-P.x)<=P.half&&Math.abs(A-P.y)<=P.half}}),rt("packages/modules/charts/cartesian.js",function(s,ae){"use strict";Object.defineProperty(s,"CARTESIAN",{enumerable:!0,get:function(){return Be}}),Object.defineProperty(s,"WATERFALL_TOTAL",{enumerable:!0,get:function(){return ot}}),Object.defineProperty(s,"withWaterfallTotal",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(s,"axisWindowSpan",{enumerable:!0,get:function(){return he}}),Object.defineProperty(s,"axisWindowNow",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(s,"rollingDomain",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(s,"WINDOW_LEAD",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(s,"aheadOfWindow",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(s,"staleWindow",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(s,"windowedBound",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(s,"slotPadFor",{enumerable:!0,get:function(){return Ge}}),Object.defineProperty(s,"pinnedContinuousX",{enumerable:!0,get:function(){return Ie}}),Object.defineProperty(s,"continuousX",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(s,"bandedX",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(s,"dataInterval",{enumerable:!0,get:function(){return He}}),Object.defineProperty(s,"continuousSlot",{enumerable:!0,get:function(){return Ye}}),Object.defineProperty(s,"xDomainFor",{enumerable:!0,get:function(){return We}}),Object.defineProperty(s,"xScaleFor",{enumerable:!0,get:function(){return nt}}),Object.defineProperty(s,"drawFits",{enumerable:!0,get:function(){return Lt}}),Object.defineProperty(s,"drawConfidenceBand",{enumerable:!0,get:function(){return Gt}}),Object.defineProperty(s,"drawBoundErrorBars",{enumerable:!0,get:function(){return gt}}),Object.defineProperty(s,"drawForest",{enumerable:!0,get:function(){return Vt}}),Object.defineProperty(s,"drawReferenceLines",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(s,"drawCartesian",{enumerable:!0,get:function(){return pt}}),Object.defineProperty(s,"HIT_TOLERANCE",{enumerable:!0,get:function(){return Mt}}),Object.defineProperty(s,"nearestDrawnPoint",{enumerable:!0,get:function(){return Zt}}),Object.defineProperty(s,"nearestCategory",{enumerable:!0,get:function(){return tn}}),Object.defineProperty(s,"categoryKeyAt",{enumerable:!0,get:function(){return Pn}});const ve=ae("packages/modules/charts/axis.js"),F=ve.drawAxisLines,l=ve.drawAxisTitle,ue=ve.drawBandLabels,z=ve.drawCategoryAxis,fe=ve.drawContinuousAxis,J=ve.drawMeasureAxis,X=ve.overhangFor,ne=ve.pinXDomain,B=ve.setPlotClip,L=ve.turnedFirstLabelBox,D=ae("packages/modules/charts/frame.js"),o=D.Pool,w=D.shouldRotate,y=ae("packages/modules/charts/format.js"),i=y.formatters,h=y.r2Digits,c=ae("packages/modules/charts/scale.js"),m=c.bandScale,b=c.extent,P=c.isNumber,u=c.key,A=c.linearScale,r=c.measureDomain,j=c.timeScale,C=c.toNumber,G=c.toTime,_=ae("packages/modules/charts/stack.js"),T=_.measureValues,p=_.stacker,v=ae("packages/modules/charts/svg.js"),n=v.attrs,t=v.path,a=v.ribbonPath,e=v.round,f=v.setText,d=v.SVG_NS,M=ae("packages/modules/charts/styles.js").NS,oe=ae("packages/modules/charts/labels.js").drawDataLabels,Q=ae("packages/modules/charts/dense.js").downsample,O=ae("packages/modules/charts/scheme.js").resolveScheme,K=ae("packages/modules/charts/typography.js").applySize,k=ae("packages/modules/charts/combo.js").drawRightAxis,V=ae("packages/modules/charts/annotations.js"),R=V.drawAnnotations,N=V.overlayLayer,S=ae("packages/modules/charts/trendline.js").drawTrendlines,Y=ae("packages/modules/charts/rulecolour.js"),Z=Y.ruleColour,x=Y.ruleLegend,ee=ae("packages/modules/charts/curve.js"),se=ee.curveCommands,de=ee.resolveCurve,xe=ae("packages/core/src/internal/util.js").warnOnce,me=ae("packages/modules/charts/fills.js"),Ne=me.isPaintRef,Ae=me.paintSolid,te=me.rowFillSource,re=ae("packages/modules/charts/markers.js"),le=re.markerFor,pe=re.placeMarker,we=re.resolveMarker,je=3.5,Be=Object.freeze({line:{zero:!1,marks:"path"},step:{zero:!1,marks:"path"},area:{zero:!0,marks:"path"},rangeArea:{zero:!1,marks:"path"},bar:{zero:!0,marks:"rect"},horizontalBar:{zero:!0,marks:"rect",horizontal:!0},waterfall:{zero:!0,marks:"rect"},scatter:{zero:!1,marks:"circle"},bubble:{zero:!1,marks:"circle"},candlestick:{zero:!1,marks:"rect"},ohlc:{zero:!1,marks:"rect"}});function Ue(U){const Ce=[];for(let Se=0;Se<U.length;Se++){const Te=U[Se];if(Se===0){Ce.push("M",Te.x,Te.y);continue}Ce.push("L",Te.x,U[Se-1].y),Ce.push("L",Te.x,Te.y)}return Ce}function qe(U){const Ce=[0];if(!U)return Ce;let Se=0;for(const Te of U.points)P(Te.y)&&Te.total!==!0&&(Se+=Te.y,Ce.push(Se));return Ce}const ot=Object.freeze({key:"lattice:waterfall-total"});function tt(U,Ce,Se){if(!Ce||typeof Ce!="object"||!Ce.total||!U||U.empty||!Array.isArray(U.series)||!U.series.length)return U;const Te=typeof Ce.total=="string"&&Ce.total.trim()!==""?Ce.total:Se,Le=U.series.map(_e=>{let De=0,Je=0,Fe=!1;for(const Qe of _e.points)Je+=Number.isFinite(Qe.rows)?Qe.rows:0,P(Qe.y)&&(De+=Qe.y,Fe=!0);const Ve={x:ot,xKey:u(ot),label:Te,y:Fe?De:null,size:null,rows:Je,rowKey:null,values:null,total:!0};return{..._e,points:[..._e.points,Ve]}});return{...U,kind:"category",series:Le,categories:[...U.categories||[],ot],labels:[...U.labels||[],Te]}}function he(U){const Ce=U&&U.window;if(!Ce||typeof Ce!="object")return 0;const Se=Number(Ce.span);return!Number.isFinite(Se)||Se<=0?0:Ce.kind!=="time"?(xe("chart.axis.window.kind",`axis window kind "${Ce.kind}" is not supported on a chart axis; only { kind: "time", span } rolls the domain. Bound the row count with the source's maxRows instead.`),0):Se}function ie(U,Ce){const Se=U&&U.window;if(!Se||typeof Se!="object"||typeof Se.now!="function")return Ce;const Te=Number(Se.now());return Number.isFinite(Te)?Te:(xe("chart.axis.window.now","axis.x.window.now did not return a time, so the rolling window is measured from this device's clock instead. It must return epoch milliseconds — the same number Date.now() returns — because that is what the x values are compared against."),Ce)}function ce(U,Ce,Se){const Te=Se+U*Oe;let Le=Se;for(const _e of Ce)Number.isFinite(_e)&&_e>Le&&_e<=Te&&(Le=_e);return{min:Le-U,max:Le}}const Oe=.25;function be(U,Ce,Se){const Te=he(Ce);if(!Te||!U||!Array.isArray(U.categories))return null;const Le=Be[Se];if(!Le||Le.horizontal||U.kind==="category"||Se==="bar"&&!$e(U,Se,Ce))return null;const _e=U.categories.map(De=>U.kind==="time"?G(De):C(De));return{span:Te,values:_e}}function ge(U,Ce,Se,Te){const Le=be(U,Ce,Se);if(!Le)return null;const _e=Le.span*Oe;let De=0,Je=0;for(const Fe of Le.values)Fe===null||!Number.isFinite(Fe)||Fe-Te<=_e||(De+=1,Fe-Te>Je&&(Je=Fe-Te));return De?{span:Le.span,limit:_e,count:De,lead:Je}:null}function ke(U,Ce,Se,Te){const Le=be(U,Ce,Se);if(!Le)return null;const{span:_e}=Le,De=Le.values.filter(Qe=>Qe!==null&&Number.isFinite(Qe));if(!De.length)return null;const{min:Je,max:Fe}=ce(_e,De,Te);let Ve=-1/0;for(const Qe of De){if(Qe>=Je&&Qe<=Fe)return null;Qe<Je&&Qe>Ve&&(Ve=Qe)}return Ve===-1/0?{span:_e,newest:null,age:null,points:De.length}:{span:_e,newest:Ve,age:Te-Ve,points:De.length}}function Ee(U,Ce,Se,Te){const Le=be(U,Ce,Se);if(!Le)return U;const{span:_e,values:De}=Le,Je=De.filter(Xe=>Xe!==null&&Number.isFinite(Xe));if(!Je.length)return U;const{min:Fe,max:Ve}=ce(_e,Je,Te),Qe=[];for(let Xe=0;Xe<De.length;Xe++){const ct=De[Xe];(ct===null||!Number.isFinite(ct)||ct>=Fe&&ct<=Ve)&&Qe.push(Xe)}return Qe.length===De.length?U:{...U,categories:Qe.map(Xe=>U.categories[Xe]),labels:Array.isArray(U.labels)?Qe.map(Xe=>U.labels[Xe]):U.labels,series:(U.series||[]).map(Xe=>({...Xe,points:Array.isArray(Xe.points)?Qe.map(ct=>Xe.points[ct]).filter(ct=>ct!==void 0):Xe.points})),windowed:De.length-Qe.length}}const Re=Object.freeze({bar:.2,candlestick:.3,ohlc:.3}),ze=.4;function Ge(U){return Object.hasOwn(Re,U)?Re[U]:ze}const Ke=new Set(["bar","candlestick","ohlc"]);function Ie(U){const Ce=U&&typeof U.scale=="string"?U.scale:"";return Ce==="time"||Ce==="linear"}function $e(U,Ce,Se){if(!U||U.kind==="category")return!1;const Te=Be[Ce];return Te&&Te.horizontal?!1:Ke.has(Ce)?Ie(Se):!0}function Pe(U,Ce,Se){return!$e(U,Ce,Se)}function He(U){const Ce=U.filter(Le=>typeof Le=="number"&&Number.isFinite(Le)).slice().sort((Le,_e)=>Le-_e),Se=[];for(let Le=1;Le<Ce.length;Le++){const _e=Ce[Le]-Ce[Le-1];_e>0&&Se.push(_e)}if(!Se.length)return 0;Se.sort((Le,_e)=>Le-_e);const Te=Math.floor(Se.length/2);return Se.length%2?Se[Te]:(Se[Te-1]+Se[Te])/2}function Ye(U){const{bound:Ce,scale:Se,config:Te,padding:Le}=U,_e=Te?Number(Te.barWidth):NaN,De=Number.isFinite(_e)&&_e>0,Je=(Ce.categories||[]).map(Xe=>Ce.kind==="time"?G(Xe):C(Xe)),Fe=De?_e:He(Je),Ve=Math.abs(Se.range[1]-Se.range[0]);if(!Fe)return Math.max(1,Ve/20*(1-Le));const Qe=Math.abs(Se.of(Se.domain.min+Fe)-Se.of(Se.domain.min));return Math.max(1,De?Qe:Qe*(1-Le))}function We(U,Ce,Se,Te){if(Pe(U,Ce,Se))return null;const Le=he(Se),_e=U.kind==="time"?U.categories.map(G):U.categories.map(C);if(U.kind==="time"&&!Le){const Je=b(_e);if(Je&&Je.min===Je.max)return ne({min:Je.min-3e4,max:Je.max+3e4},U,Se)}const De=Le?ce(Le,_e,Number.isFinite(Te)?Te:ie(Se,Date.now())):r(_e,{zero:!1,nice:U.kind!=="time"});return ne(De,U,Se)}function nt(U,Ce,Se,Te){const Le=[Ce.left,Ce.right];if(Pe(U,Se,Te))return he(Te)&&xe("chart.axis.window.band","a rolling time window needs a continuous x axis; this chart bands its x values, so the window is ignored. Bind a date or numeric column to x, or put this type on a continuous axis with axis.x.scale."),m(U.categories,Le,Ge(Se));const _e=U.xDomain||We(U,Se,Te);return U.kind==="time"?j(_e,Le):A(_e,Le)}function ut(U,Ce){if(U.kind==="band")return U.centre(Ce.x);const Se=U.kind==="time"?G(Ce.x):C(Ce.x);return Se===null?NaN:U.of(Se)}function ht(U,Ce){const Se=U&&U.seriesStyle&&U.seriesStyle[Ce];if(Se)return{width:Se.width!=null?String(Se.width):null,dash:Array.isArray(Se.dash)&&Se.dash.length?Se.dash.join(" "):null,opacity:null,emphasized:!1};const Te=U&&Array.isArray(U.emphasis)?U.emphasis:null;if(!Te||!Te.length)return{width:null,dash:null,opacity:null,emphasized:!1};const Le=Te.includes(Ce);return{width:Le?"var(--lattice-chart-emphasis-width, 3.5)":null,dash:null,opacity:Le?null:"var(--lattice-chart-muted-opacity, .35)",emphasized:Le}}function st(U){const{series:Ce,xScale:Se,yScale:Te,baseline:Le,fill:_e,colour:De,stack:Je,style:Fe}=U,Ve=[],Qe=[];let Xe=[];const ct=()=>{Xe.length===1?Ve.push("M",Xe[0].x,Xe[0].y):Xe.length>1&&Ve.push(...se(Xe,U.curve||null)),Xe=[]};for(let Ot=0;Ot<Ce.points.length;Ot++){const jt=Ce.points[Ot],It=e(ut(Se,jt));if(!P(jt.y)||Number.isNaN(It)){ct();continue}Qe[Ot]=!0;const zt=jt.y,Dt=U.lower?U.lower.points[Ot]:null;if(U.lower&&!(Dt&&P(Dt.y))){ct();continue}const Nt=Je?Je.take(Ot,zt):null,Rt=e(Te.of(Nt?Nt[1]:zt)),Bt=e(Te.of(Nt?Nt[0]:Dt?Dt.y:Le));Xe.push({x:It,y:Rt,base:Bt}),jt.px=It,jt.py=Rt,jt.pbase=Bt}ct(),n(U.pool.next("path",`${M}__line ${M}__mark`),{d:Ve.length?t(Ve):"",stroke:De,"data-series":U.index,"stroke-width":Fe?Fe.width:null,"stroke-dasharray":Fe?Fe.dash:null,opacity:Fe?Fe.opacity:null});const at=!!U.marker&&!!U.markerEnv;if(at&&!_e&&dt(U,Qe),!_e){at||vt({...U,placed:Qe});return}const yt=[];let xt=[];const wt=()=>{if(xt.length<2){xt=[];return}const Ot=se(xt,U.curve||null);Ot[0]="L",yt.push("M",xt[0].x,xt[0].base),yt.push(...Ot);for(let jt=xt.length-1;jt>=0;jt--)yt.push("L",xt[jt].x,xt[jt].base);yt.push("Z"),xt=[]};for(const Ot of Ce.points){if(!P(Ot.y)||Ot.px===void 0){wt();continue}xt.push({x:Ot.px,y:Ot.py,base:Ot.pbase})}wt(),n(U.pool.next("path",`${M}__area ${M}__mark`),{d:yt.length?t(yt):"",fill:De,"data-series":U.index,opacity:Ne(De)?"1":Fe?Fe.emphasized?"1":Fe.opacity:null}),at?dt(U,Qe):vt({...U,placed:Qe})}function dt(U,Ce){const{series:Se}=U;for(let Te=0;Te<Se.points.length;Te++){if(!Ce[Te])continue;const Le=Se.points[Te];et(U,Le,Te,Le.px,Le.py,je*2,U.colour)||n(U.pool.next("circle",`${M}__point ${M}__mark`),{cx:Le.px,cy:Le.py,r:je,fill:U.colour,"data-series":U.index,"data-point":Te})}}function vt(U){const{series:Ce,placed:Se}=U;for(let Te=0;Te<Ce.points.length;Te++){if(!Se[Te]||Se[Te-1]||Se[Te+1])continue;const Le=Ce.points[Te];n(U.pool.next("circle",`${M}__point ${M}__mark`),{cx:Le.px,cy:Le.py,r:je,fill:U.colour,"data-series":U.index,"data-point":Te})}}function St(U,Ce){const Se=U&&U.range;if(!Array.isArray(Se)||Se.length!==2)return Ce;const[Te,Le]=Se;return!Number.isFinite(Te)||!Number.isFinite(Le)||!Number.isFinite(Ce)?Ce:Math.min(Math.max(Te,Le),Math.max(Math.min(Te,Le),Ce))}function $t(U){const{series:Ce,xScale:Se,yScale:Te,baseline:Le,colour:_e,stack:De,slot:Je}=U;for(let Fe=0;Fe<Ce.points.length;Fe++){const Ve=Ce.points[Fe];if(!P(Ve.y))continue;const Qe=Se.kind==="band"?Se.of(Ve.x):ut(Se,Ve)-Je.span/2;if(Number.isNaN(Qe))continue;const Xe=Ve.y,ct=U.pointColour&&U.pointColour(Ve,_e)||_e,at=De?De.take(Fe,Xe):[Le,Xe],yt=St(Te,Te.of(at[1])),xt=St(Te,Te.of(at[0])),wt=Qe+Je.offset,Ot=Se.kind==="band"?wt:St(Se,wt),jt=Se.kind==="band"?wt+Je.width:St(Se,wt+Je.width),It=U.pool.next("rect",`${M}__bar ${M}__mark`,`${Ce.key}:${u(Ve.x)}`);n(It,{x:e(Ot),y:e(Math.min(yt,xt)),width:e(Math.max(0,jt-Ot)),height:e(Math.max(1,Math.abs(xt-yt))),fill:ct,"data-series":U.index,"data-point":Fe}),Ve.px=e(Qe+Je.offset+Je.width/2),Ve.py=e(Math.min(yt,xt)),Ve.pbase=e(Math.max(yt,xt))}}function At(U){const{series:Ce,xScale:Se,yScale:Te}=U;let Le=0;for(let _e=0;_e<Ce.points.length;_e++){const De=Ce.points[_e];if(!P(De.y))continue;const Je=De.y,Fe=De.total===!0,Ve=Fe?0:Le,Qe=Fe?Je:Le+Je;Fe||(Le+=Je);const Xe=St(Te,Te.of(Math.max(Ve,Qe))),ct=St(Te,Te.of(Math.min(Ve,Qe))),at=U.pool.next("rect",`${M}__bar ${M}__mark`,`${Ce.key}:${u(De.x)}`);n(at,{x:e(Se.of(De.x)),y:e(Xe),width:e(Se.bandwidth),height:e(Math.max(1,ct-Xe)),fill:Je>=0?U.positive:U.negative,"data-series":U.index,"data-point":_e,"data-total":Fe?"true":null}),De.px=e(Se.of(De.x)+Se.bandwidth/2),De.py=e(Xe)}}function ft(U){const{series:Ce,valueScale:Se,baseline:Te,colour:Le,stack:_e,slot:De}=U;for(let Je=0;Je<Ce.points.length;Je++){const Fe=Ce.points[Je];if(!P(Fe.y))continue;const Ve=U.bandScale.of(Fe.x);if(Number.isNaN(Ve))continue;const Qe=Fe.y,Xe=U.pointColour&&U.pointColour(Fe,Le)||Le,ct=_e?_e.take(Je,Qe):[Te,Qe],at=St(Se,Se.of(ct[0])),yt=St(Se,Se.of(ct[1]));n(U.pool.next("rect",`${M}__bar ${M}__mark`,`${Ce.key}:${u(Fe.x)}`),{x:e(Math.min(at,yt)),y:e(Ve+De.offset),width:e(Math.max(1,Math.abs(yt-at))),height:e(Math.max(0,De.width)),fill:Xe,"data-series":U.index,"data-point":Je}),Fe.px=e(yt),Fe.py=e(Ve+De.offset+De.width/2),Fe.pbase=e(at)}}function Pt(U){const{series:Ce,xScale:Se,yScale:Te,baseline:Le,colour:_e,stack:De,slot:Je}=U;for(let Fe=0;Fe<Ce.points.length;Fe++){const Ve=Ce.points[Fe];if(!P(Ve.y))continue;const Qe=Se.kind==="band"?Se.of(Ve.x):ut(Se,Ve)-Je.span/2;if(Number.isNaN(Qe))continue;const Xe=Ve.y,ct=U.pointColour&&U.pointColour(Ve,_e)||_e,at=De?De.take(Fe,Xe):[Le,Xe],yt=St(Te,Te.of(at[1])),xt=St(Te,Te.of(at[0])),wt=e(Qe+Je.offset+Je.width/2);n(U.pool.next("line",`${M}__lollipop-stem ${M}__mark`,`${Ce.key}:${u(Ve.x)}`),{x1:wt,y1:e(xt),x2:wt,y2:e(yt),stroke:ct,"stroke-width":2,"data-series":U.index,"data-point":Fe}),n(U.pool.next("circle",`${M}__lollipop-dot ${M}__mark`,`${Ce.key}:${u(Ve.x)}`),{cx:wt,cy:e(yt),r:4,fill:ct,"data-series":U.index,"data-point":Fe}),Ve.px=wt,Ve.py=e(yt),Ve.pbase=e(xt)}}function _t(U){const{series:Ce,valueScale:Se,baseline:Te,colour:Le,stack:_e,slot:De}=U;for(let Je=0;Je<Ce.points.length;Je++){const Fe=Ce.points[Je];if(!P(Fe.y))continue;const Ve=U.bandScale.of(Fe.x);if(Number.isNaN(Ve))continue;const Qe=Fe.y,Xe=U.pointColour&&U.pointColour(Fe,Le)||Le,ct=_e?_e.take(Je,Qe):[Te,Qe],at=St(Se,Se.of(ct[0])),yt=St(Se,Se.of(ct[1])),xt=e(Ve+De.offset+De.width/2);n(U.pool.next("line",`${M}__lollipop-stem ${M}__mark`,`${Ce.key}:${u(Fe.x)}`),{x1:e(at),y1:xt,x2:e(yt),y2:xt,stroke:Xe,"stroke-width":2,"data-series":U.index,"data-point":Je}),n(U.pool.next("circle",`${M}__lollipop-dot ${M}__mark`,`${Ce.key}:${u(Fe.x)}`),{cx:e(yt),cy:xt,r:4,fill:Xe,"data-series":U.index,"data-point":Je}),Fe.px=e(yt),Fe.py=xt,Fe.pbase=e(at)}}function Lt(U){const Ce=U.group.ownerDocument;let Se=null;for(const _e of U.group.childNodes||[])if(_e&&String(_e.getAttribute&&_e.getAttribute("class"))===`${M}__fits`){Se=_e;break}Se||(Se=Ce.createElementNS(d,"g"),Se.setAttribute("class",`${M}__fits`),U.group.appendChild(Se));const Te=new o(Se),Le=[];for(const _e of U.series){const De=_e.allPoints||_e.points;let Je=0,Fe=0,Ve=0;for(const Dt of De){const Nt=Number(Dt.x),Rt=Number(Dt.y);!Number.isFinite(Nt)||!Number.isFinite(Rt)||(Je++,Fe+=Nt,Ve+=Rt)}if(Je<2)continue;const Qe=Fe/Je,Xe=Ve/Je;let ct=0,at=0,yt=0,xt=1/0,wt=-1/0;for(const Dt of De){const Nt=Number(Dt.x),Rt=Number(Dt.y);if(!Number.isFinite(Nt)||!Number.isFinite(Rt))continue;const Bt=Nt-Qe,qt=Rt-Xe;ct+=Bt*Bt,at+=Bt*qt,yt+=qt*qt,Nt<xt&&(xt=Nt),Nt>wt&&(wt=Nt)}if(ct===0)continue;const Ot=at/ct,jt=Xe-Ot*Qe,It=yt===0?1:Math.max(0,Math.min(1,at*at/(ct*yt))),zt=U.scheme.series(_e.index);if(n(Te.next("path",`${M}__fit`),{d:t(["M",e(U.xScale.of(xt)),e(U.yScale.of(jt+Ot*xt)),"L",e(U.xScale.of(wt)),e(U.yScale.of(jt+Ot*wt))]),fill:"none",stroke:zt,"data-series":_e.index}),U.showR2){const Dt=Te.next("text",`${M}__fit-label`);K(Dt,U.size),n(Dt,{x:e(U.xScale.of(wt)),y:e(U.yScale.of(jt+Ot*wt))-4,"text-anchor":"end",fill:zt}),f(Dt,U.grid.messages.t("chart.r2",{value:h(U.grid,It)}))}Le.push({key:_e.key,slope:Ot,intercept:jt,r2:It,n:Je})}return Te.finish(),Le}function Gt(U){const Ce=U.group.ownerDocument;let Se=null;for(const Ve of U.group.childNodes||[])if(Ve&&String(Ve.getAttribute&&Ve.getAttribute("class"))===`${M}__band`){Se=Ve;break}Se||(Se=Ce.createElementNS(d,"g"),Se.setAttribute("class",`${M}__band`),U.group.firstChild?U.group.insertBefore(Se,U.group.firstChild):U.group.appendChild(Se));const Te=new o(Se),Le=U.band&&Array.isArray(U.band.points)?U.band.points:[],_e=Number.isFinite(U.index)?Number(U.index):0,De=U.scheme.series(_e),Je=Number.isFinite(U.opacity)?Number(U.opacity):.15,Fe=[];for(const Ve of Le){const Qe=Number(Ve.x),Xe=Number(Ve.lower),ct=Number(Ve.upper);if(!Number.isFinite(Qe)||!Number.isFinite(Xe)||!Number.isFinite(ct))continue;const at=Number(Ve.yhat);Fe.push({x:e(U.xScale.of(Qe)),lower:e(U.yScale.of(Xe)),upper:e(U.yScale.of(ct)),yhat:Number.isFinite(at)?e(U.yScale.of(at)):null})}if(Fe.length>=2&&(n(Te.next("path",`${M}__band-fill`),{d:a(Fe),fill:De,"fill-opacity":Je,stroke:"none","data-series":_e}),U.line!==!1)){const Ve=[];let Qe=!1;for(const Xe of Fe){if(Xe.yhat===null){Qe=!1;continue}Ve.push(Qe?"L":"M",Xe.x,Xe.yhat),Qe=!0}n(Te.next("path",`${M}__band-line`),{d:Ve.length?t(Ve):"",fill:"none",stroke:De,"data-series":_e})}return Te.finish(),{points:Fe.length,confidence:U.band&&Number.isFinite(U.band.confidence)?Number(U.band.confidence):null}}function gt(U){const Ce=U.group.ownerDocument;let Se=null;for(const Fe of U.group.childNodes||[])if(Fe&&String(Fe.getAttribute&&Fe.getAttribute("class"))===`${M}__whiskers`){Se=Fe;break}Se||(Se=Ce.createElementNS(d,"g"),Se.setAttribute("class",`${M}__whiskers`),U.group.appendChild(Se));const Te=new o(Se),Le=Number.isFinite(U.cap)?Number(U.cap):4,_e=U.colour||"currentColor",De=U.orient!=="v";let Je=0;for(const Fe of U.points||[]){const Ve=Number(Fe.main),Qe=Number(Fe.lo),Xe=Number(Fe.hi);if(!Number.isFinite(Ve)||!Number.isFinite(Qe)||!Number.isFinite(Xe))continue;const ct=De?["M",Qe,Ve,"L",Xe,Ve,"M",Qe,Ve-Le,"L",Qe,Ve+Le,"M",Xe,Ve-Le,"L",Xe,Ve+Le]:["M",Ve,Qe,"L",Ve,Xe,"M",Ve-Le,Qe,"L",Ve+Le,Qe,"M",Ve-Le,Xe,"L",Ve+Le,Xe];n(Te.next("path",`${M}__whisker`),{d:t(ct),stroke:_e,fill:"none"}),Je++}return Te.finish(),Je}function Vt(U){const Ce=U.scheme||O(),Se=U.typography||{small:U.fontSize||11,axisTitle:11},{bound:Te}=U,Le=Me(U.plot,Se.small),_e=Te.series[0]&&Te.series[0].points||[],De=_e.map(at=>at.label),Je=Ce.series(0),Fe=m(De,[Le.top,Le.bottom],.4),Ve=[0];for(const at of _e)for(const yt of[at.x,at.lower,at.upper])Number.isFinite(yt)&&Ve.push(yt);const Qe=A(r(Ve,{zero:!1}),[Le.left,Le.right]);gt({group:U.groups.overlay,orient:"h",colour:Je,points:_e.map(at=>({main:e(Fe.centre(at.label)),lo:e(Qe.of(at.lower)),hi:e(Qe.of(at.upper))}))});const Xe=new o(U.groups.marks);let ct=0;for(const at of _e)Number.isFinite(at.x)&&(n(Xe.next("circle",`${M}__point ${M}__mark`),{cx:e(Qe.of(at.x)),cy:e(Fe.centre(at.label)),r:je,fill:Je}),ct++);return Xe.finish(),Ze({group:U.groups.rules,plot:Le,scale:Qe,lines:[{value:0}]}),fe({group:U.groups.axis,plot:Le,scale:Qe,format:i(U.grid,{kind:"linear",step:(Qe.domain.max-Qe.domain.min)/5}),config:{},grid:U.grid,size:Se.small}),ue({group:U.groups.labels,plot:Le,scale:Fe,labels:De,fontSize:Se.small,config:{}}),{series:[],marks:ct}}function Me(U,Ce){const Se=6+Ce*1.3+2,Te=U&&U.gutter&&Number.isFinite(U.gutter.bottom)?U.gutter.bottom:Se,Le=Math.min(Math.max(0,Se-Te),Math.max(0,U.height-10));return Le>0?{...U,height:U.height-Le,bottom:U.bottom-Le,gutter:{...U.gutter,bottom:Te+Le}}:U}function Ze(U){const Ce=new o(N(U.group,`${M}__reflines`));for(const Se of U.lines||[]){if(!P(Se.value))continue;const Te=e(U.scale.of(Se.value));if(n(Ce.next("path",`${M}__reference`),{d:U.vertical?t(["M",Te,e(U.plot.top),"L",Te,e(U.plot.bottom)]):t(["M",e(U.plot.left),Te,"L",e(U.plot.right),Te]),stroke:Se.colour||"currentColor","stroke-dasharray":"4 3",fill:"none"}),!Se.label)continue;const Le=Ce.next("text",`${M}__reference-label`);n(Le,U.vertical?{x:Te+4,y:e(U.plot.top+10),"text-anchor":"start"}:{x:e(U.plot.right-4),y:Te-4,"text-anchor":"end"}),f(Le,Se.label)}Ce.finish()}function it(U){const{series:Ce,xScale:Se,yScale:Te,colour:Le,plot:_e}=U,De=U.size||null;for(let Je=0;Je<Ce.points.length;Je++){const Fe=Ce.points[Je];if(!P(Fe.y))continue;const Ve=e(ut(Se,Fe));if(Number.isNaN(Ve))continue;const Qe=e(Te.of(Fe.y));let Xe=De&&P(Fe.size)?e(De.of(Fe.size)):je;if(_e){const at=Math.min(Ve-_e.left,_e.right-Ve,Qe-_e.top,_e.bottom-Qe);Number.isFinite(at)&&(Xe=Math.max(1,Math.min(Xe,at)))}const ct=U.pointColour&&U.pointColour(Fe,Le)||Le;et(U,Fe,Je,Ve,Qe,Xe*2,ct)||n(U.pool.next("circle",`${M}__point ${M}__mark`),{cx:Ve,cy:Qe,r:Xe,fill:ct,"fill-opacity":De?.7:1,"data-series":U.index,"data-point":Je}),Fe.px=Ve,Fe.py=Qe}}function et(U,Ce,Se,Te,Le,_e,De){if(!U.marker||!U.markerEnv)return!1;const Je=le(U.marker,Ce,U.markerEnv);if(Ce.markerHalf=0,!Je)return!1;const Fe=U.marker.explicitSize?U.marker.size:Math.max(U.marker.size,_e);return pe(U.pool,Je,{x:Te,y:Le,size:Fe,colour:Ae(De),attrs:n,round:e,extra:{"data-series":U.index,"data-point":Se}}),Ce.markerHalf=Fe/2,!0}function mt(U){const{group:Ce,series:Se,xScale:Te,yScale:Le,options:_e}=U,De=U.grid&&U.grid.statistics,Je=De&&typeof De.intervalOf=="function"?(xt,wt)=>De.intervalOf(xt,wt):null,Fe=new o(N(Ce,`${M}__errorbars`)),Ve=Number.isFinite(Number(_e.confidence))?Number(_e.confidence):.95,Qe=4;let Xe=0,ct=0,at=0,yt=0;for(const xt of Se)for(const wt of xt.points){if(wt.y===null||wt.y===void 0)continue;ct++;const Ot=Array.isArray(wt.values)&&wt.values.length===1;Ot&&at++;let jt=null,It=null;if(_e.of!==void 0&&Number.isFinite(Number(wt[_e.of]))){const Rt=Math.abs(Number(wt[_e.of]));jt=wt.y-Rt,It=wt.y+Rt}else if(Array.isArray(wt.values)&&wt.values.length>1&&Je){const Rt=Je(wt.values,Ve);Rt&&(jt=Rt.lower,It=Rt.upper)}if(jt===null||!Number.isFinite(jt)||!Number.isFinite(It)){Ot&&yt++;continue}const zt=e(Te.of(wt.xKey!==void 0?wt.xKey:wt.x)+(Te.bandwidth?Te.bandwidth/2:0)),Dt=e(Le.of(It)),Nt=e(Le.of(jt));n(Fe.next("path",`${M}__error-bar ${M}__mark`),{d:t(["M",zt-Qe,Dt,"L",zt+Qe,Dt,"M",zt,Dt,"L",zt,Nt,"M",zt-Qe,Nt,"L",zt+Qe,Nt]),fill:"none",stroke:"currentColor","data-lower":jt,"data-upper":It}),Xe++}return Fe.finish(),{drawn:Xe,marks:ct,single:at,singleSkipped:yt}}function bt(U,Ce){if(Ce&&Ce.size){const _e=new Set;for(let De=0;De<U.length;De++)U[De].rowKey!=null&&Ce.has(String(U[De].rowKey))&&_e.add(De);return _e}const Se=5,Te=_e=>[...U.keys()].filter(De=>Number.isFinite(_e(U[De]))).sort((De,Je)=>_e(U[Je])-_e(U[De])).slice(0,Se),Le=new Set(Te(_e=>Math.abs(Number(_e.y))));for(const _e of Te(De=>Number(De.x)))Le.add(_e);if(U.some(_e=>P(_e.size)))for(const _e of Te(De=>P(De.size)?Number(De.size):-1/0))Le.add(_e);return Le}function pt(U){const Ce=U.scheme||O(),Se=U.axis||{x:{},y:{},y2:{}},Te=U.typography||{small:U.fontSize||11,axisTitle:11},{bound:Le,plot:_e,type:De}=U,Je=Be[De]||Be.line,Fe=Le.series.filter(lt=>!U.hidden.has(lt.key)),Ve=!!Je.horizontal,Qe=U.mark==="lollipop"&&(De==="bar"||De==="horizontalBar"),Xe=!Ve&&Se.y.position==="right"?"right":"left",ct=Xe==="right"?"left":"right",at=(De==="bar"||De==="horizontalBar")&&U.byRuleColour&&Fe.length===1&&Le.measure&&Le.measure.col||null,yt=at?new Set:null,xt=at?lt=>{const kt=Z({grid:U.grid,col:at,value:lt.y});return kt&&yt.add(kt),kt}:null,Ot=(De==="bar"||De==="horizontalBar")&&U.byRuleColour&&Fe.length===1&&Ce.nameMap?lt=>Ce.series(0,lt.label):null,jt=U.fill?te(U,Ce):null,It=jt||xt||Ot?(lt,kt)=>jt&&jt(lt,kt)||xt&&xt(lt)||Ot&&Ot(lt)||null:null,zt=we(U.marker),Dt=zt?{grid:U.grid,doc:U.doc,redraw:U.redraw}:null,Nt=!Ve&&De!=="waterfall"?Fe.filter(lt=>lt.axis==="right"):[],Rt=Nt.length?Fe.filter(lt=>lt.axis!=="right"):Fe,Bt=Nt.length>0,qt=(De==="bar"||De==="area"||De==="horizontalBar")&&!Bt,Jt=U.stack==="percent"&&qt&&Rt.length>1,Xt=(Jt||!!U.stack)&&Rt.length>1&&qt,jn=De==="waterfall"?qe(Fe[0]):T(Rt,Xt,Jt),Kt=Le.yDomain||U.domain||r(jn,{zero:Je.zero,min:Se.y.min,max:Se.y.max}),Wt=Ve?A(Kt,[_e.left,_e.right]):A(Kt,[_e.bottom,_e.top]),Et=Ve?m(Le.categories,[_e.top,_e.bottom],.2):nt(Le,_e,De,Se.x),ln=Kt.min<=0&&Kt.max>=0?0:Kt.min,En=Nt.some(lt=>(lt.mark||(De==="bar"?"bar":De))==="bar"),Yt=Bt?r(T(Nt,!1,!1),{zero:En,min:Se.y2.min,max:Se.y2.max}):null,Ht=Yt?A(Yt,[_e.bottom,_e.top]):null,cn=i(U.grid,{kind:"linear",step:(Kt.max-Kt.min)/5}),un=Jt?{tick:lt=>`${cn.tick(lt)}%`,value:lt=>`${cn.value(lt)}%`}:cn,nn=U.axes!==!1,Ut={left:0,right:0,bottom:0};if(De==="scatter"||De==="bubble")for(const lt of Fe)for(const kt of lt.points){if(!P(kt.y))continue;const Ct=ut(Et,kt),Ft=Wt.of(kt.y);if(!Number.isFinite(Ct)||!Number.isFinite(Ft))continue;const Tt=(U.sizes&&P(kt.size)?U.sizes.of(kt.size):je)+2;Ut.left=Math.max(Ut.left,Tt-(Ct-_e.left)),Ut.right=Math.max(Ut.right,Tt-(_e.right-Ct)),Ut.bottom=Math.max(Ut.bottom,Tt-(_e.bottom-Ft))}const Nn=!Ve&&Et.kind==="band"&&(Se.x.rotate===void 0||Se.x.rotate==="auto"?w(Le.labels,Et.step,Te.small,Se.x.every):!!Se.x.rotate)&&L({group:U.groups.overlay,plot:_e,scale:Et,labels:Le.labels,fontSize:Te.small,config:Se.x});if(nn&&J({gridGroup:U.groups.grid,axisGroup:U.groups.axis,plot:_e,scale:Wt,format:un,horizontal:Ve,side:Xe,config:Se.y,grid:U.grid,size:Te.small,overhang:Xe==="right"?Ut.right:Ut.left,dropBottom:Nn}),nn)if(Ve)ue({group:U.groups.overlay,plot:_e,scale:Et,labels:Le.labels,fontSize:Te.small,config:Se.x});else if(Et.kind==="band")z({group:U.groups.overlay,plot:_e,scale:Et,labels:Le.labels,fontSize:Te.small,rotated:w(Le.labels,Et.step,Te.small,Se.x.every),config:Se.x});else{const lt=Le.dimension&&Le.dimension.col?U.grid.columns.get(Le.dimension.col):void 0;fe({group:U.groups.overlay,plot:_e,scale:Et,format:i(U.grid,{kind:Le.kind,span:Et.domain.max-Et.domain.min,step:(Et.domain.max-Et.domain.min)/5},lt),config:Se.x,grid:U.grid,column:lt,size:Te.small,overhang:Ut.bottom})}if(nn&&(F({group:U.groups.rules,plot:_e,side:Xe}),l({group:U.groups.axis,plot:_e,text:Se.y.title,side:Ve?"bottom":Xe,size:Te.axisTitle}),l({group:U.groups.axis,plot:_e,text:Se.x.title,side:Ve?"left":"bottom",size:Te.axisTitle})),nn&&Ht){k({group:U.groups.axis,plot:_e,scale:Ht,colour:Ce.series(Nt[0].index),side:ct,format:i(U.grid,{kind:"linear",step:(Yt.max-Yt.min)/5})});const lt=Se.y2.title||(Nt.length===1?Nt[0].label:"");l({group:U.groups.axis,plot:_e,text:lt,side:ct,size:Te.axisTitle}),!Se.y.title&&Rt.length===1&&Rt[0].label&&l({group:U.groups.axis,plot:_e,text:Rt[0].label,side:Xe,size:Te.axisTitle})}const mn=Number.isFinite(U.downsampleTo)?Number(U.downsampleTo):Math.max(2,Math.round(_e.width));let hn=!1;if(Je.marks==="path"||De==="scatter"||De==="bubble"){for(const lt of Fe)if(lt.kept=null,lt.allPoints=lt.points,lt.points.length>mn*1.5){const kt=lt.points.map((Ft,Tt)=>({x:Tt,y:Ft.y,point:Ft})),Ct=Q(kt,mn);if(U.keepInfluential){const Ft=new Set(Ct.map(Tt=>Tt.x));for(const Tt of bt(lt.points,U.keepRows))Ft.has(Tt)||(Ct.push({x:Tt,y:lt.points[Tt].y,point:lt.points[Tt]}),Ft.add(Tt));Ct.sort((Tt,gn)=>Tt.x-gn.x)}lt.points=Ct.map(Ft=>Ft.point),lt.kept=Ct.map(Ft=>Ft.x),hn=!0}}U.pool||B(U.groups,_e,X(De));const Qt=U.pool||new o(U.groups.marks),bn=Jt?Le.categories.map((lt,kt)=>Fe.reduce((Ct,Ft)=>{const Tt=Ft.points[kt]?Ft.points[kt].y:null;return P(Tt)?Ct+Math.abs(Tt):Ct},0)):null,dn=Xt?p(Le.categories.length,bn):null,fn=Bt?Fe.filter(lt=>(lt.mark||(De==="bar"?"bar":De))==="bar"):Fe,Mn=Bt?Math.max(1,fn.length):Math.max(1,Fe.length),Cn=De==="bar"||Bt&&fn.length>0,rn=Et.kind==="band"?Et.bandwidth:Cn?Ye({bound:Le,scale:Et,config:Se.x,padding:Ge("bar")}):0,on=Xt?rn:rn/Mn,sn=new Map;for(const lt of fn)sn.set(lt.key,sn.size);const yn=[],an=De==="rangeArea"&&Le.series.length>=2?Le.series[0]:null,wn=an?Le.series[1]:null;for(let lt=0;lt<Fe.length;lt++){const kt=Fe[lt],Ct=Ce.series(kt.index,kt.label),Ft=kt.axis==="right"&&Ht?Ht:Wt,Tt=Bt?kt.mark||(De==="bar"?"bar":De):De,gn=Bt&&sn.has(kt.key)?sn.get(kt.key):lt;if(De==="horizontalBar")(Qe?_t:ft)({pool:Qt,series:kt,bandScale:Et,valueScale:Wt,baseline:ln,colour:Ct,stack:dn,index:kt.index,slot:{offset:Xt?0:lt*on,width:on,span:rn},pointColour:It});else if(De==="waterfall")At({pool:Qt,series:kt,xScale:Et,yScale:Wt,index:kt.index,positive:Ce.positive,negative:Ce.negative});else if(Tt==="bar")(Qe?Pt:$t)({pool:Qt,series:kt,xScale:Et,yScale:Ft,baseline:Ft===Ht?Yt.min<=0&&Yt.max>=0?0:Yt.min:ln,colour:Ct,stack:dn,index:kt.index,slot:{offset:Xt?0:gn*on,width:on,span:rn},pointColour:It});else if(De==="scatter"||De==="bubble")it({pool:Qt,series:kt,xScale:Et,yScale:Ft,colour:Ct,index:kt.index,size:De==="bubble"?U.sizes:null,pointColour:It,marker:zt,markerEnv:Dt,plot:_e});else{const vn=ht(U,kt.label),_n=Tt==="step"?{type:"step",tension:1,mode:"after"}:de(U.curve,kt.label),xn={pool:Qt,series:kt,xScale:Et,yScale:Ft,baseline:ln,fill:an?kt===wn:Tt==="area"||Tt==="rangeArea",lower:an&&kt===wn?an:null,curve:_n,colour:Ct,stack:dn,index:kt.index,style:vn,marker:zt,markerEnv:Dt};vn.emphasized?yn.push(xn):st(xn)}}for(const lt of yn)st(lt);U.pool||Qt.finish(),U.band&&typeof Et.invert=="function"&&Gt({group:U.groups.overlay,band:U.band,xScale:Et,yScale:Wt,scheme:Ce,index:0,line:U.band.line!==!1&&!U.fit}),U.fit&&(De==="scatter"||De==="bubble")&&typeof Et.invert=="function"&&Lt({group:U.groups.overlay,series:Fe,xScale:Et,yScale:Wt,plot:_e,scheme:Ce,grid:U.grid,size:Te.small,showR2:U.fit!=="line"});let en=null;U.trend&&(en=S({group:U.groups.overlay,series:Fe,xScale:Et,yScale:Wt,rightScale:Ht,plot:_e,scheme:Ce,trend:U.trend,grid:U.grid,format:lt=>un.tick(lt),size:Te.small,clip:U.groups.boxClipId}));let kn=null;if(U.error&&(kn=mt({group:U.groups.overlay,series:Fe,xScale:Et,yScale:Wt,grid:U.grid,options:U.error===!0?{}:U.error})),U.labels&&U.labels.show&&oe({group:U.groups.labels,series:Fe,plot:_e,options:U.labels,grid:U.grid,size:Te.small,horizontal:Ve}),U.reference&&U.reference.length){const lt=Ve?U.reference:U.reference.filter(Ct=>!(Ct.axis==="right"||Ct.axis==="y2")),kt=Ht?U.reference.filter(Ct=>Ct.axis==="right"||Ct.axis==="y2"):[];lt.length&&Ze({group:U.groups.overlay,plot:_e,scale:Wt,lines:lt,vertical:Ve}),kt.length&&Ze({group:U.groups.overlay,plot:_e,scale:Ht,lines:kt})}let pn=null;U.annotations&&U.annotations.length&&(pn=R({group:U.groups.overlay,plot:_e,xScale:Et,yScale:Wt,rightScale:Ht,series:Fe,annotations:U.annotations,dual:Bt,horizontal:Ve,format:lt=>un.tick(lt),size:Te.small}));const Tn=Array.isArray(en)&&en.length?[...pn||[],...en]:pn;return{xScale:Et,yScale:Wt,rightScale:Ht,dual:Bt,series:Fe,horizontal:Ve,percent:Jt,percentTotals:Jt?bn:null,plot:_e,errorBars:kn,annotations:Tn,trendlines:en,reduced:hn,legend:at?x({grid:U.grid,col:at,colours:yt}):null}}const Mt=32;function Zt(U){const{series:Ce,xScale:Se,at:Te}=U,Le=Number.isFinite(U.tolerance)?Number(U.tolerance):Mt,_e=[];let De=-1,Je=1/0;for(const Fe of Ce){let Ve=null,Qe=-1,Xe=1/0;const ct=Fe.points||[];for(let at=0;at<ct.length;at++){const yt=ct[at];if(!yt||!P(yt.y))continue;const xt=ut(Se,yt);if(Number.isNaN(xt))continue;const wt=Math.abs(xt-Te);wt>=Xe||(Xe=wt,Ve=yt,Qe=Array.isArray(Fe.kept)?Fe.kept[at]:at)}!Ve||Xe>Le||(_e.push({series:Fe,point:Ve}),Xe<Je&&(Je=Xe,De=Qe))}return De<0?null:{index:De,entries:_e}}function tn(U){const{bound:Ce,xScale:Se,at:Te}=U;if(!Ce.categories.length)return-1;if(Se.kind==="band"){const De=Math.floor((Te-Se.range[0])/(Se.step||1));return De>=0&&De<Ce.categories.length?De:-1}let Le=-1,_e=1/0;for(let De=0;De<Ce.categories.length;De++){const Je=Se.kind==="time"?G(Ce.categories[De]):C(Ce.categories[De]);if(Je===null)continue;const Fe=Math.abs(Se.of(Je)-Te);Fe<_e&&(_e=Fe,Le=De)}return Le}function Pn(U,Ce){return Ce<0||Ce>=U.categories.length?"":u(U.categories[Ce])}}),rt("packages/core/src/source/filterwire.js",function(s,ae){"use strict";Object.defineProperty(s,"HOST_FILTER_WARN_ID",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"WHERE_PAGE_RELATIVE_WARN_ID",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"warnWherePageRelative",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"warnHostFilterNotApplied",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"WHERE_NOT_APPLIED_WARN_ID",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"warnWhereNotApplied",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"WHERE_OVER_THRESHOLD_WARN_ID",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"warnWhereOverThreshold",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"RELATIVE_TOKENS",{enumerable:!0,get:function(){return c}}),Object.defineProperty(s,"parseRelativeToken",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"resolveRelativeRange",{enumerable:!0,get:function(){return b}}),Object.defineProperty(s,"relativeTokenOf",{enumerable:!0,get:function(){return P}}),Object.defineProperty(s,"relativeTokenHelp",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"isResolvableRelative",{enumerable:!0,get:function(){return A}}),Object.defineProperty(s,"resolveRelativeCondition",{enumerable:!0,get:function(){return r}}),Object.defineProperty(s,"isGroup",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"forEachCondition",{enumerable:!0,get:function(){return C}}),Object.defineProperty(s,"mapConditions",{enumerable:!0,get:function(){return G}}),Object.defineProperty(s,"normaliseFilterSet",{enumerable:!0,get:function(){return T}}),Object.defineProperty(s,"buildFilterSet",{enumerable:!0,get:function(){return p}}),Object.defineProperty(s,"wireFilters",{enumerable:!0,get:function(){return v}}),Object.defineProperty(s,"querySignature",{enumerable:!0,get:function(){return n}});const F=ae("packages/core/src/internal/util.js").warnOnce,l="source.remote.hostFilter",ue="source.where.pageRelative";function z(e,f){!Array.isArray(e)||!e.length||F(ue,`filters.where (${e.join(", ")}) runs over the rows the ${f} 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 fe(e){const f=(e||{}).config;!f||!f.hostFilter||F(l,"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 J="source.where.notApplied";function X(e,f){F(`${J}:${e}`,`filters.where("${e}") is registered but the ${f} source holds only its fetched window`,"and cannot run the predicate over it: the predicate is not applied there, and rows it would","exclude stay on screen.","Give it a { condition } twin so the engine can narrow the fetch itself — that is the","supported route for a paged or remote source.")}const ne="source.where.overThreshold";function B(e,f,d,E){!Array.isArray(e)||!e.length||F(`${ne}:${f}`,`filters.where (${e.join(", ")}) is not applied to the ${f} pushdown source:`,d===null?"the adapter reports no row total, so the size of the matching set is unknown.":`its matching set is ${d.toLocaleString()} rows, at or past the whereRowLimit of ${E.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 D(e){let f=L.get(e);return f||(f=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),L.set(e,f)),f}function o(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function w(e,f){const d=D(f).formatToParts(new Date(e)),E={y:1970,m:1,d:1,h:0,mi:0,s:0};for(const M of d)M.type==="year"?E.y=+M.value:M.type==="month"?E.m=+M.value:M.type==="day"?E.d=+M.value:M.type==="hour"?E.h=+M.value%24:M.type==="minute"?E.mi=+M.value:M.type==="second"&&(E.s=+M.value);return E}function y(e,f){const d=w(e,f);return Date.UTC(d.y,d.m-1,d.d,d.h,d.mi,d.s)-Math.floor(e/1e3)*1e3}function i(e,f,d,E){const M=Date.UTC(e,f-1,d),W=M-y(M,E);return M-y(W,E)}function h(e,f,d){const E=new Date(Date.UTC(e.y,e.m-1,e.d+f));return i(E.getUTCFullYear(),E.getUTCMonth()+1,E.getUTCDate(),d)}const c=Object.freeze(["today","yesterday","lastNDays","thisWeek","thisMonth","thisQuarter","thisYear","quarterToDate","yearToDate"]);function m(e,f){if(typeof e!="string")return null;const d=e.trim().toLowerCase().replace(/[\s_-]+/g,""),E=/^last(\d*|n)days?$/.exec(d);if(E){const M=E[1]==="n"?"":E[1],W=Number(M||f);return!Number.isFinite(W)||W<=0?null:{kind:"lastNDays",n:Math.floor(W)}}switch(d){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 b(e,f={}){const d=m(e,f.n);if(!d)return null;const E=f.tz||o(),M=f.now instanceof Date?f.now.getTime():typeof f.now=="number"?f.now:Date.now(),W=w(M,E),oe=i(W.y,W.m,W.d,E),q=h(W,1,E);let Q=oe,H=q;switch(d.kind){case"today":break;case"yesterday":Q=h(W,-1,E),H=oe;break;case"lastNDays":H=f.includeToday?q:oe,Q=h(W,f.includeToday?-(d.n-1):-d.n,E);break;case"thisWeek":{const O=Number.isFinite(f.weekStartsOn)?Number(f.weekStartsOn):1,K=(new Date(Date.UTC(W.y,W.m-1,W.d)).getUTCDay()-O+7)%7;Q=h(W,-K,E),H=h(W,-K+7,E);break}case"thisMonth":Q=i(W.y,W.m,1,E),H=i(W.m===12?W.y+1:W.y,W.m===12?1:W.m+1,1,E);break;case"thisQuarter":case"quarterToDate":{const O=Math.floor((W.m-1)/3)*3+1;Q=i(W.y,O,1,E),H=d.kind==="quarterToDate"?q:O===10?i(W.y+1,1,1,E):i(W.y,O+3,1,E);break}case"thisYear":case"yearToDate":Q=i(W.y,1,1,E),H=d.kind==="yearToDate"?q:i(W.y+1,1,1,E);break;default:return null}return{from:new Date(Q).toISOString(),to:new Date(H).toISOString(),bounds:"[)",tz:E,relative:d.kind==="lastNDays"?`last${d.n}Days`:d.kind,n:d.n}}function P(e){if(!e||typeof e!="object")return null;const f=e.value;if(f&&typeof f=="object"&&!Array.isArray(f)&&"relative"in f)return{token:String(f.relative),n:typeof f.n=="number"?f.n:void 0};if(e.op==="relative"&&typeof e.value=="string")return{token:e.value,n:void 0};const d=e.meta;return d&&typeof d.relative=="string"&&e.value===void 0?{token:d.relative,n:typeof d.n=="number"?d.n:void 0}:null}function u(){return`Known tokens: ${c.filter(f=>f!=="lastNDays").join(", ")}. "lastNDays" needs a count: pass "last7Days", or the value object { relative: 'lastNDays', n: 7 }.`}function A(e){const f=P(e);return f?m(f.token,f.n)!==null:!1}function r(e,f={}){const d=P(e);if(!d)return e;const E=b(d.token,{...f,n:d.n});return E?{...e,type:e.type||"date",op:"between",value:[E.from,E.to],bounds:e.bounds||E.bounds,meta:{...e.meta||{},relative:E.relative,tz:E.tz}}:(F(`source.relative.${d.token}`,`unknown relative date token "${d.token}"; sending the condition unresolved.`,u()),e)}function j(e){return!!e&&typeof e=="object"&&Array.isArray(e.conditions)}function C(e,f){if(e){if(j(e)){for(const d of e.conditions)C(d,f);return}f(e)}}function G(e,f){if(!e)return null;if(!j(e))return f(e);const d=e;let E=!1;const M=[];for(const W of d.conditions){const oe=G(W,f);oe!==W&&(E=!0),oe&&M.push(oe)}return!E&&M.length===d.conditions.length?e:M.length?{...d,conditions:M}:null}function _(e){if(!e)return null;if(!j(e))return e;const f=e,d=[];for(const E of f.conditions){const M=_(E);M&&d.push(M)}return d.length?{op:f.op,conditions:d}:null}function T(e){const f=_(e);return f?j(f)&&f.op==="and"?f:{op:"and",conditions:[f]}:null}function p(e){const f=(e||[]).filter(Boolean);return f.length?{op:"and",conditions:f}:null}function v(e,f={}){const d=G(e,E=>r(E,f));return T(d)}function n(e){const f=t(e.filters??null);return JSON.stringify([f,e.sort??null,e.quick??"",e.groupBy??null,e.pivotBy??null,a(e.context)])}function t(e){if(!e)return null;if(j(e)){const E=e;return{op:E.op,conditions:E.conditions.map(t)}}const f=e,d=f.meta&&typeof f.meta.relative=="string"?f.meta.relative:P(f)?.token;return{col:f.col,op:f.op,bounds:f.bounds??null,caseSensitive:f.caseSensitive??!1,value:d?`rel:${d}`:f.value??null}}function a(e){if(e==null)return null;try{return JSON.parse(JSON.stringify(e))}catch{return F("source.context.unserialisable","config.context is not JSON-serialisable; cache keys ignore it."),"[unserialisable]"}}}),rt("packages/core/src/source/aggregates.js",function(s,ae){"use strict";Object.defineProperty(s,"STAT_PUSHDOWN",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(s,"pushableAggregates",{enumerable:!0,get:function(){return F}}),Object.defineProperty(s,"fillAggregateSql",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"resolveAggregatesConfig",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"routeAggregate",{enumerable:!0,get:function(){return z}}),Object.defineProperty(s,"resolveAggregatePlan",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"groupKeysPushable",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"pushdownDocRows",{enumerable:!0,get:function(){return ne}});const ve=Object.freeze({sum:{pushable:!0,class:"identical",sql:"sum(%c)"},avg:{pushable:!0,class:"identical",sql:"avg(%c)"},min:{pushable:!0,class:"identical",sql:"min(%c)"},max:{pushable:!0,class:"identical",sql:"max(%c)"},count:{pushable:!0,class:"identical",sql:"count(*)"},countValues:{pushable:!0,class:"identical",sql:"count(%c)",blankAware:!0},range:{pushable:!0,class:"identical",sql:"(max(%c) - min(%c))"},variance:{pushable:!0,class:"identical",sql:"var_samp(%c)"},varianceP:{pushable:!0,class:"identical",sql:"var_pop(%c)"},stddev:{pushable:!0,class:"identical",sql:"stddev_samp(%c)"},stddevP:{pushable:!0,class:"identical",sql:"stddev_pop(%c)"},sumSquares:{pushable:!0,class:"identical",sql:"sum(%c * %c)"},median:{pushable:!0,class:"identical",sql:"median(%c)"},p25:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.25)"},p75:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.75)"},p90:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.9)"},p95:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.95)"},p99:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.99)"},iqr:{pushable:!0,class:"identical",sql:"(quantile_cont(%c, 0.75) - quantile_cont(%c, 0.25))"},mad:{pushable:!0,class:"identical",sql:"mad(%c)"},distinct:{pushable:!0,class:"identical",sql:"count(DISTINCT %c)",blankAware:!0},skewness:{pushable:!0,class:"identical",sql:"skewness(%c)"},kurtosis:{pushable:!0,class:"identical",sql:"kurtosis(%c)"},geomean:{pushable:!0,class:"identical",sql:"exp(avg(ln(%c)))"},harmean:{pushable:!0,class:"identical",sql:"(count(%c) / sum(1.0 / %c))"},entropy:{pushable:!0,class:"identical",sql:"entropy(%c)",blankAware:!0},correlation:{pushable:!0,class:"identical",sql:"corr(%w, %c)",twoColumn:!0},hhi:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_transform(map_values(histogram(%c)), lambda v: (v::DOUBLE/count(%c))*(v::DOUBLE/count(%c)))) END"},evenness:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL WHEN count(DISTINCT %c)<2 THEN 1.0 ELSE entropy(%c)/log2(count(DISTINCT %c)) END"},top3Share:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_slice(list_sort(map_values(histogram(%c)),'DESC'),1,3))::DOUBLE/count(%c) END"},top10Share:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_slice(list_sort(map_values(histogram(%c)),'DESC'),1,10))::DOUBLE/count(%c) END"},gini:{pushable:!0,class:"identical",sql:"CASE WHEN list_min(list(%c) FILTER (WHERE isfinite(%c)))<0 THEN NULL WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL WHEN list_sum(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN 0 ELSE 2.0*list_sum(list_transform(list_sort(list(%c) FILTER (WHERE isfinite(%c))), lambda v, i: i*v))/(len(list(%c) FILTER (WHERE isfinite(%c)))*list_sum(list(%c) FILTER (WHERE isfinite(%c))))-(len(list(%c) FILTER (WHERE isfinite(%c)))+1.0)/len(list(%c) FILTER (WHERE isfinite(%c))) END"},trimmedMean:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL ELSE list_avg(list_slice(list_sort(list(%c) FILTER (WHERE isfinite(%c))), floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT+1, len(list(%c) FILTER (WHERE isfinite(%c)))-floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT)) END"},winsorizedMean:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL ELSE list_avg(list_transform(list_sort(list(%c) FILTER (WHERE isfinite(%c))), lambda v: least(list_sort(list(%c) FILTER (WHERE isfinite(%c)))[len(list(%c) FILTER (WHERE isfinite(%c)))-floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT], greatest(list_sort(list(%c) FILTER (WHERE isfinite(%c)))[floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT+1], v)))) END"},robustOutliers:{pushable:!0,class:"identical",sql:"(SELECT CASE WHEN len(d.a)=0 THEN NULL WHEN d.mad=0 THEN NULL ELSE len(list_filter(d.a, lambda v: abs(0.6745*(v-d.med)/d.mad)>3.5)) END FROM (SELECT xs AS a, list_median(xs) AS med, list_median(list_transform(xs, lambda w: abs(w-list_median(xs)))) AS mad FROM (SELECT list(%c) FILTER (WHERE isfinite(%c)) AS xs)) d)"},jarqueBera:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))<8 THEN NULL WHEN list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2)))=0 THEN NULL ELSE (len(list(%c) FILTER (WHERE isfinite(%c)))/6.0)*(power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),3)))/power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2))),1.5),2)+power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),4)))/power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2))),2)-3,2)/4.0) END"},weightedAvg:{pushable:!0,class:"identical",twoColumn:!0,sql:"sum(%c*%w) FILTER (WHERE isfinite(%c) AND isfinite(%w))/nullif(sum(%w) FILTER (WHERE isfinite(%c) AND isfinite(%w)),0)"},mode:{pushable:!0,class:"may-differ",sql:"mode(%c)",note:"DuckDB returns a modal value even for an all-distinct column; the grid returns null. Tie-breaking can also differ, and on a text column an empty string counts as a value. Under pushdown you will see a value."},weightedQuantile:{pushable:!1,class:"fallback",note:"No SQL equivalent for the grid's weighted-quantile midpoint convention; always computed client-side (needs a full-dataset pull for a correct figure over a remote source)."}});function F(){const B=new Set;for(const[L,D]of Object.entries(ve))D.pushable&&B.add(L);return B}function l(B,L,D){let o=B.split("%c").join(L);return D!==void 0&&(o=o.split("%w").join(D)),o}function ue(B){const L=B||{},D=L.default==="engine"||L.default==="engine-if-identical"?L.default:"client",o={};if(L.overrides&&typeof L.overrides=="object")for(const[w,y]of Object.entries(L.overrides))(y==="engine"||y==="client")&&(o[w]=y);return{default:D,overrides:o}}function z(B,L){const D=ve[B];if(!D||!D.pushable)return"client";const o=L.overrides[B];return o==="engine"||o==="client"?o:L.default==="client"?"client":L.default==="engine-if-identical"?D.class==="identical"?"engine":"client":"engine"}function fe(B,L){const D=ue(L),o=[],w=[];for(const y of B||[]){const i=ve[y.fn],h=z(y.fn,D),c={id:y.id,col:y.col,fn:y.fn,class:i?i.class:"fallback"};y.weight!==void 0&&(c.weight=y.weight),y.params!==void 0&&(c.params=y.params),h==="engine"?o.push(c):(c.reason=i&&!i.pushable?i.note||"the engine cannot express this stat":"client by config",w.push(c))}return{engine:o,client:w,config:D}}const J=/^[A-Za-z_][A-Za-z0-9_$]*$/;function X(B,L=[]){return(B||[]).every(o=>{if(typeof o=="string")return J.test(o);if(!o||typeof o!="object")return!1;const w=o;return Array.isArray(L)&&L.includes(w.bucket)&&typeof w.col=="string"&&J.test(w.col)&&typeof w.size=="number"&&Number.isFinite(w.size)&&w.size>0})}function ne(){return Object.entries(ve).map(([B,L])=>({stat:B,class:L.class,sql:L.sql?l(L.sql,"col",L.twoColumn?"weight":void 0):"",note:L.note||(L.class==="identical"?"Pushes to DuckDB with the same result.":"")}))}}),rt("packages/core/src/source/abort.js",function(s,ae){"use strict";Object.defineProperty(s,"SupersededError",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(s,"RequestToken",{enumerable:!0,get:function(){return F}}),Object.defineProperty(s,"AbortScope",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"createAbortScope",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(s,"isAbortError",{enumerable:!0,get:function(){return z}});class ve extends Error{constructor(J,X="superseded"){super(`[lattice] request ${J?`"${J}" `:""}${X}`),this.name="SupersededError",this.superseded=!0,this.key=J}}class F{#e;constructor(J,X,ne,B){this.#e=J,this.key=X,this.controller=ne,this.signal=ne.signal,this.seq=B}get current(){return!this.signal.aborted&&this.#e.tokenFor(this.key)===this}settle(){this.#e.settle(this)}abort(J){this.signal.aborted||this.controller.abort(new ve(this.key,J)),this.#e.settle(this)}}class l{#e=new Map;#t=0;begin(J="",X="superseded"){const ne=this.#e.get(J);ne&&!ne.signal.aborted&&ne.controller.abort(new ve(J,X));const B=new F(this,J,new AbortController,++this.#t);return this.#e.set(J,B),B}tokenFor(J){return this.#e.get(J)}pending(J=""){const X=this.#e.get(J);return!!X&&!X.signal.aborted}get size(){return this.#e.size}settle(J){this.#e.get(J.key)===J&&this.#e.delete(J.key)}abort(J="",X="superseded"){const ne=this.#e.get(J);ne&&ne.abort(X)}abortAll(J="superseded"){for(const X of[...this.#e.values()])X.abort(J);this.#e.clear()}}function ue(){return new l}function z(fe){if(!fe||typeof fe!="object")return!1;const J=fe;return J.superseded===!0||J.name==="AbortError"||J.name==="SupersededError"}}),rt("packages/core/src/source/pushdown.js",function(s,ae){"use strict";Object.defineProperty(s,"FOREGROUND_WAIT_MS",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"NO_CAPABILITIES",{enumerable:!0,get:function(){return c}}),Object.defineProperty(s,"resolveMutate",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"capabilitiesOf",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"splitFilters",{enumerable:!0,get:function(){return r}}),Object.defineProperty(s,"LEAF_COUNT_ID",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"PIVOT_UNSUPPORTED",{enumerable:!0,get:function(){return T}}),Object.defineProperty(s,"GROUP_UNSUPPORTED",{enumerable:!0,get:function(){return p}}),Object.defineProperty(s,"UNGROUPED_LEVEL",{enumerable:!0,get:function(){return v}}),Object.defineProperty(s,"planQuery",{enumerable:!0,get:function(){return t}}),Object.defineProperty(s,"applyResidual",{enumerable:!0,get:function(){return f}}),Object.defineProperty(s,"DEFAULT_WHERE_ROW_LIMIT",{enumerable:!0,get:function(){return W}}),Object.defineProperty(s,"createPushdownSource",{enumerable:!0,get:function(){return H}});const ve=ae("packages/core/src/internal/util.js"),F=ve.defaultCompare,l=ve.isFunction,ue=ve.toArray,z=ve.warnOnce,fe=ae("packages/core/src/source/filterwire.js"),J=fe.isGroup,X=fe.warnWherePageRelative,ne=fe.warnWhereOverThreshold,B=ae("packages/core/src/source/aggregates.js"),L=B.resolveAggregatePlan,D=B.groupKeysPushable,o=B.STAT_PUSHDOWN,y=ae("packages/core/src/source/abort.js").SupersededError,i=1e3;function h(O){const I=O&&O.signal;if(!I||!I.aborted)return;const K=I.reason;throw K instanceof Error?K:new y("","superseded before it was sent")}const c=Object.freeze({filter:!1,operators:Object.freeze([]),sort:!1,quick:!1,range:!1,total:!1,group:!1,pivot:!1,mutate:!1});function m(O){if(!O||typeof O!="object")return!1;const I=O.returning==="row"||O.returning==="key"?O.returning:"none";return{append:O.append===!0,update:O.update===!0,delete:O.delete===!0,returning:I}}function b(O,I){if(!O||typeof I!="string")return;if(!I.includes("."))return O[I];let K=O;for(const g of I.split(".")){if(K===null||typeof K!="object")return;K=K[g]}return K}function P(O){if(O===!0)return!0;if(!O||typeof O!="object")return!1;const I=O;return I.enabled===!1?!1:I.enabled===!0||l(I.commit)}function u(O){const I={...c,...O||{}};return I.operators=new Set(I.operators||[]),I.mutate=m(I.mutate),I}function A(O,I){return!O||!O.op||!I.operators.size?!1:I.operators.has(O.op)}function r(O,I){if(!O)return{pushed:null,residual:null};if(!I.filter)return{pushed:null,residual:O};if(I.filter==="term"){if(J(O)){const V=O.conditions||[];if(String(O.op)!=="and")return{pushed:null,residual:O};const R=V.findIndex($=>!J($)&&A($,I));if(R<0)return{pushed:null,residual:O};const N=V.filter(($,S)=>S!==R);return{pushed:V[R],residual:N.length?{op:"and",conditions:N}:null}}return A(O,I)?{pushed:O,residual:null}:{pushed:null,residual:O}}if(!J(O))return A(O,I)?{pushed:O,residual:null}:{pushed:null,residual:O};if(String(O.op)!=="and")return(O.conditions||[]).every(R=>J(R)?r(R,I).residual===null:A(R,I))?{pushed:O,residual:null}:{pushed:null,residual:O};const K=[],g=[];for(const V of O.conditions||[]){if(J(V)){if(I.filter==="flat"){g.push(V);continue}const R=r(V,I);R.pushed&&K.push(R.pushed),R.residual&&g.push(R.residual);continue}(A(V,I)?K:g).push(V)}const k=V=>V.length===0?null:V.length===1?V[0]:{op:"and",conditions:V};return{pushed:k(K),residual:k(g)}}const j="__lattice_leaves";function C(O){return O.aggregates?O.aggregates instanceof Set?O.aggregates:new Set(ue(O.aggregates)):new Set}function G(O){const I=C(O);return I.size?I.has("count")?O.filter!=="tree"||!O.operators||!O.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 _(O,I,K,g,k,V,R){const N=Array.isArray(O.groupBy)?O.groupBy:[],$=Array.isArray(O.groupPath)?O.groupPath:[],S=Array.isArray(O.groupValues)?O.groupValues:null;if(!I.group){const Y=G(I);if(Y)return Y}return D(N)?K.residual?"the filter did not fully push, so the engine would group a superset of the matching rows":g?k?V?"a host `where` predicate can only run in the browser, over rows the engine grouped":R?"fullDataset holds the whole matching set, so the grid groups it itself":!S||S.length!==$.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 T="pushdown:pivot-unsupported",p="pushdown:group-unsupported",v=Symbol("lattice.remote.ungroupedLevel");function n(O,I,K,g,k,V){const R=Array.isArray(O.pivotBy)?O.pivotBy:[],N=Array.isArray(O.groupBy)?O.groupBy:[],$=Array.isArray(O.groupPath)?O.groupPath:[],S=Array.isArray(O.groupValues)?O.groupValues:null;return I.pivot?D(R)?N.length&&!D(N)?"a grouping key is not a plain column the engine can name in a GROUP BY":K.residual?"the filter did not fully push, so the engine would pivot a superset of the matching rows":g?k?V?"a host `where` predicate can only run in the browser, over rows the engine pivoted":!S||S.length!==$.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 t(O,I,K=!1){const g=r(O.filters||null,I),k=[];g.residual&&k.push("filter");const V=O.sort||[],R=V.length===0||I.sort==="multi"&&V.length>=1||I.sort==="single"&&V.length===1;!R&&V.length&&k.push("sort");const N=O.quick?String(O.quick):"",$=!N||!!I.quick;$||k.push("quick");const S=O.where&&O.where.active?O.where:null;S&&k.push("where");const Y={filters:g.residual,sort:R?null:V,quick:$?"":N,where:S},Z=!!K,x=Array.isArray(O.groupBy)&&O.groupBy.length>0,ee=x?_(O,I,g,R,$,S,Z):"",se=O.pivotMode!==!1&&Array.isArray(O.pivotBy)&&O.pivotBy.length>0,de=se?n(O,I,g,R,$,S):"",ye=se&&de==="";se&&!ye&&k.push("pivot");const xe=se?ye&&x:x&&ee==="";x&&!se&&!xe&&k.push("group");const me=(xe||ye)&&Array.isArray(O.groupValues)?O.groupValues.length:0,Ne=xe||se?!1:Z||!!(Y.filters||Y.sort||Y.quick||Y.where)||!I.range;return{pushed:{...O,filters:g.pushed,sort:R?V:[],quick:$?N:"",range:Ne?null:O.range},residual:Y,needsAll:Ne,unpushed:k,full:Z,grouped:xe,groupLevel:me,groupReason:se?"":ee,pivoted:ye,pivotReason:de}}function a(O){const I=Array.isArray(O.totals)?O.totals:[],K=O.totalFns&&typeof O.totalFns=="object"?O.totalFns:{},g=[],k=[];for(const V of I){const R=String(V),N=typeof K[R]=="string"?K[R]:null,$=N?o[N]:null;N?!$||!$.pushable||!$.sql?k.push({id:R,fn:N,class:$?$.class:"fallback",reason:$&&$.note?$.note:`the pushdown map cannot express "${N}"`}):$.twoColumn?k.push({id:R,fn:N,class:$.class,reason:`"${N}" reduces two columns, and a grouped request carries no weight column`}):g.push({id:R,col:R,fn:N,class:$.class}):k.push({id:R,fn:null,class:"fallback",reason:"the column totals with a host function, so there is no named statistic to push"})}return{engine:g,client:k}}const e=Object.freeze({items:O=>O==null?[]:Array.isArray(O)?O:[O]});function f(O,I,K){if(!I)return O;let g=O;if(I.filters&&l(K.evaluateFilters)){const k=g,V={count:g.length,handle:$=>({id:$,get:S=>b(k[S],$)}),itemwise:$=>k.some(S=>Array.isArray(b(S,$)))?e:null},R=K.evaluateFilters(I.filters,V),N=[];for(let $=0;$<g.length;$++)R[$]&&N.push(g[$]);g=N}if(I.where&&I.where.active&&(I.whole||X(I.where.names,"pushdown"),g=g.filter(k=>I.where.passes(k))),I.quick){const k=I.quick.toLowerCase();g=g.filter(V=>{if(!V||typeof V!="object")return!1;for(const R of Object.values(V))if(R!=null&&String(R).toLowerCase().includes(k))return!0;return!1})}if(I.sort&&I.sort.length&&l(K.sortMulti)){const k=[...new Set(I.sort.map($=>$.col))],V=g,R=k.map($=>({id:$,get:S=>b(V[S],$)})),N=K.sortMulti(R,I.sort.map($=>({col:$.col,dir:$.dir})),Uint32Array.from({length:g.length},($,S)=>S),{});g=Array.from(N,$=>V[$])}return g}function d(O){return JSON.stringify({filters:O.filters||null,sort:O.sort||[],quick:O.quick||"",groupBy:O.groupBy||[],groupPath:O.groupPath||[],context:O.context??null})}function E(O){if(!O||typeof O!="object")return 16;let I="";try{I=JSON.stringify(O)}catch{return 200}return I.length*2+64}function M(O){const I=O||{};return{enabled:!!I.enabled,maxRows:Number.isFinite(I.maxRows)?I.maxRows:1e6,maxBytesEstimate:Number.isFinite(I.maxBytesEstimate)?I.maxBytesEstimate:512*1024*1024}}const W=5e4;function oe(O){return Number.isFinite(O)&&O>=0?O:W}function q(O){return!!O&&l(O.then)}async function Q(O){if(!O||O.total!==void 0||!q(O.pendingTotal))return O;const I=await O.pendingTotal,{pendingTotal:K,...g}=O;return typeof I=="number"?{...g,total:I}:g}function H(O={}){const I=O.adapter;if(!I||!l(I.execute))return z("source.pushdown.adapter","createPushdownSource needs an `adapter` with an `execute(query)` function."),{...O,mode:"remote",fetch:async()=>({rows:[],total:0})};const K=u(I.capabilities),g=I.capabilities&&Object.getOwnPropertyDescriptor(I.capabilities,"operators");g&&l(g.get)&&Object.defineProperty(K,"operators",{enumerable:!0,configurable:!0,get:()=>new Set(I.capabilities.operators||[]),set:()=>{}});const k=I.name||"adapter";let V=null;const R=()=>l(I.ready)?(V||(V=Promise.resolve(I.ready()).then(()=>{Object.assign(K,u(I.capabilities))},$e=>{throw V=null,$e})),V):null,N=M(O.fullDataset),$=!!O.allowPartialResults,S=oe(O.whereRowLimit);let Y=null;const Z=O.aggregates;let x=null,ee=null,se=null,de=null,ye=null,xe,me=null,Ne=0,Ae=null;const te=()=>!N.enabled||!x?null:(Ae!==x.key&&(Ne++,Ae=x.key),{rows:x.rows,version:Ne}),re=async $e=>{const Pe=$e.where&&$e.where.active?$e.where:null;if(!Pe)return{request:$e,probe:null};const{where:He,...Ye}=$e,We=t(Ye,K,N.enabled);if(We.needsAll)return{request:$e,probe:null};const nt=d(We.pushed);let ut=null;return(!Y||Y.key!==nt)&&(K.total?(h($e),ut=await Q(await I.execute(We.pushed,$e)),Y={key:nt,size:ut&&typeof ut.total=="number"?ut.total:null}):Y={key:nt,size:null}),Y.size!==null&&Y.size<S?{request:$e,probe:null}:(ne(Pe.names,k,Y.size,S),{request:Ye,probe:ut})},le=async($e,Pe)=>{me=null;const He=a($e.pushed);se={engine:He.engine,client:He.client,groupBy:$e.pushed.groupBy},He.client.length&&z(`source.pushdown.group.totals.${k}.${He.client.map(nt=>nt.id).join(".")}`,`the ${k} adapter cannot compute the group subtotal for ${He.client.map(nt=>`"${nt.id}" (${nt.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 Ye=await I.executeGroupLevel($e.pushed,He.engine,Pe)||{};let We=Ye.rows||[];return!K.range&&Pe.range&&(We=We.slice(Pe.range.start,Pe.range.end)),Be(Ye),Ye.total===void 0?{rows:We}:{rows:We,total:Ye.total}},pe=new Map,we=64,je=async($e,Pe)=>{me=null;const He=$e.pushed,Ye=He.groupBy,We=Array.isArray(He.groupValues)?He.groupValues:[],nt=We.length,ut=[...He.filters?[He.filters]:[],...Ye.slice(0,nt).map((et,mt)=>({col:et,op:"eq",value:We[mt]===void 0?null:We[mt],caseSensitive:!0}))],ht=ut.length===0?null:ut.length===1?ut[0]:{op:"and",conditions:ut},st=Pe.range?Pe.range.start:0;if(nt>=Ye.length){const et={...He,filters:ht,groupBy:[],groupPath:[],groupValues:[],totals:[],totalFns:{}},mt=await Q(await I.execute(et,Pe))||{};let bt=mt.rows||[];return!K.range&&Pe.range&&(bt=bt.slice(Pe.range.start,Pe.range.end)),typeof mt.total=="number"?{rows:bt,total:mt.total}:{rows:bt}}const dt=Ye[nt],vt=a(He),St=C(K),$t=vt.engine.filter(et=>St.has(et.fn)),At=[...vt.engine.filter(et=>!St.has(et.fn)).map(et=>({id:et.id,fn:et.fn,class:et.class,reason:`the ${k} adapter does not compute "${et.fn}"`})),...vt.client];se={engine:$t,client:At,groupBy:Ye},At.length&&z(`source.pushdown.group.totals.${k}.${At.map(et=>et.id).join(".")}`,`the ${k} adapter cannot compute the group subtotal for ${At.map(et=>`"${et.id}" (${et.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 ft=[...$t.map(et=>({id:et.id,col:et.col,fn:et.fn})),{id:j,col:dt,fn:"count"}],Pt={...He,filters:ht,range:null},_t=JSON.stringify([d(Pt),We,dt,ft]);let Lt=st>0?pe.get(_t):void 0;if(!Lt){for(Lt=Promise.resolve(I.executeGroupedAggregates(Pt,[dt],ft)),pe.delete(_t),pe.set(_t,Lt);pe.size>we;)pe.delete(pe.keys().next().value);Lt.catch(()=>{pe.get(_t)===Lt&&pe.delete(_t)})}const Gt=await Lt||[];h(Pe);const gt=et=>{const mt={};for(const bt of $t)mt[bt.id]=et?et[bt.id]:void 0;return mt},Vt=(He.sort||[]).find(et=>et&&et.col===dt),Me=Vt&&Vt.dir==="desc"?-1:1,Ze=Gt.filter(et=>et&&et.level===1).map(et=>({[dt]:et.keys[0]===void 0?null:et.keys[0],leafCount:Number(et.values&&et.values[j])||0,totals:gt(et.values)})).sort((et,mt)=>Me*F(et[dt],mt[dt]));if(nt===0){const et=Gt.find(bt=>bt&&bt.level===0),mt=et?Number(et.values&&et.values[j]):NaN;Be({matchCount:Number.isFinite(mt)?mt:Ze.reduce((bt,pt)=>bt+pt.leafCount,0),...et?{grand:gt(et.values)}:{}})}const it=Pe.range?Pe.range.end:Ze.length;return{rows:Ze.slice(st,it),total:Ze.length}},Be=$e=>{typeof $e.matchCount=="number"&&(de=$e.matchCount,ye=$e.grand?{totals:$e.grand,leafCount:$e.matchCount}:null,xe===void 0&&l(I.unfilteredCount)&&(xe=null,Promise.resolve(I.unfilteredCount()).then(Pe=>{xe=typeof Pe=="number"?Pe:null}).catch(Pe=>{z(`source.pushdown.group.unfiltered.${k}`,`the ${k} adapter could not count the unfiltered set (${Pe&&Pe.message?Pe.message:Pe}), so "N of M" falls back to the display count for its denominator.`)})))},Ue=async($e,Pe)=>{me=null;const He=a($e.pushed);se={engine:He.engine,client:He.client,groupBy:$e.pushed.groupBy,pivotBy:$e.pushed.pivotBy},He.client.length&&z(`source.pushdown.pivot.totals.${k}.${He.client.map(ht=>ht.id).join(".")}`,`the ${k} adapter cannot compute the pivot cells for ${He.client.map(ht=>`"${ht.id}" (${ht.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 Ye=await I.executePivotLevel($e.pushed,He.engine,Pe)||{};let We=Ye.rows||[];!K.range&&Pe.range&&(We=We.slice(Pe.range.start,Pe.range.end)),Be(Ye);const nt=Ye.pivot&&typeof Ye.pivot=="object"?Ye.pivot:{},ut={cells:Array.isArray(nt.cells)?nt.cells:[],...Array.isArray(nt.axis)?{axis:nt.axis}:{}};return Ye.total===void 0?{rows:We,pivot:ut}:{rows:We,total:Ye.total,pivot:ut}},qe=$e=>{z(`source.pushdown.pivot.${k}.${$e}`,`pushdown:pivot-unsupported: the ${k} adapter cannot pivot this query because ${$e}, so no rows are fetched rather than every leaf row being pulled into the browser to pivot there. \`lastPlan().pivotReason\` says the same.`);const Pe=new Error(`[lattice] ${T}: the ${k} adapter cannot pivot this query because ${$e}, so no rows are fetched rather than every leaf row being pulled into the browser to pivot there. \`lastPlan().pivotReason\` says the same.`);throw Pe.code=T,Pe.reason=$e,Pe},ot=($e,Pe)=>{const He={key:Pe,state:"pending",value:null};return me=He,$e.then(Ye=>(me===He&&(me={key:Pe,state:"settled",value:typeof Ye=="number"?Ye:null}),Ye),Ye=>{throw me===He&&(me={key:Pe,state:"failed",value:null}),Ye})};let tt=0,he=[];const ie=()=>tt===0?null:new Promise($e=>{const Pe=setTimeout($e,i);he.push(()=>{clearTimeout(Pe),$e()})});let ce;const Oe=async $e=>{const Pe=R();Pe&&await Pe;const Ye=$e&&$e.pivotMode!==!1&&Array.isArray($e.pivotBy)&&$e.pivotBy.length>0?{request:$e,probe:null}:await re($e);h($e);let We=t(Ye.request,K,N.enabled);if(K.group&&We.grouped&&!We.pivoted&&!l(I.executeGroupLevel)&&(z(`source.pushdown.group.method.${k}`,`the ${k} 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.`),We=t(Ye.request,{...K,group:!1,aggregates:null},N.enabled)),We.pivoted&&!l(I.executePivotLevel)&&(We=t(Ye.request,{...K,pivot:!1},N.enabled),We.pivotReason="the adapter declares the `pivot` capability but has no `executePivotLevel(query, aggregates, request)`"),We.grouped&&!We.pivoted&&!K.group&&!l(I.executeGroupedAggregates)&&(z(`source.pushdown.group.aggregates.method.${k}`,`the ${k} 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\`.`),We=t(Ye.request,{...K,aggregates:null},N.enabled)),ee=We,We.pivoted)return Ue(We,$e);if(We.pivotReason&&qe(We.pivotReason),We.grouped)return K.group?le(We,$e):je(We,$e);const ut=!!We.groupReason&&!We.full;ut?z(`source.pushdown.group-unsupported.${k}.${We.groupReason}`,`pushdown:group-unsupported: the ${k} adapter was not asked to group this query because ${We.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.`):We.groupReason&&z(`source.pushdown.group.${k}.${We.groupReason}`,`the ${k} adapter was not asked to group this query because ${We.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 ht=ft=>ut?{...ft,[v]:!0}:ft;if(!We.needsAll){const ft=Ye.probe||await I.execute(We.pushed,$e),Pt=ft.rows||[];return q(ft.pendingTotal)&&ft.total===void 0?ht({rows:Pt,pendingTotal:ot(ft.pendingTotal,d(We.pushed))}):(me=null,!K.total&&ft.total===void 0?ht({rows:Pt}):ht({rows:Pt,total:ft.total??Pt.length}))}We.unpushed.length&&z(`source.pushdown.residual.${k}.${We.unpushed.join(".")}`,`the ${k} adapter cannot push ${We.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 st=d(We.pushed);if(!x||x.key!==st){const ft=await Q(await I.execute(We.pushed,$e));me=null;const Pt=ft.rows||[];if(We.full){const _t=typeof ft.total=="number"?Math.max(ft.total,Pt.length):Pt.length;if(_t>N.maxRows)throw new Error(`[lattice] fullDataset refused: the ${k} adapter's matching set is ${_t.toLocaleString()} rows, past the configured maxRows of ${N.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 Lt=Pt.length*E(Pt[0]);if(Lt>N.maxBytesEstimate)throw new Error(`[lattice] fullDataset refused: the ${k} adapter's matching set is an estimated ${Math.round(Lt/(1024*1024)).toLocaleString()} MB across ${Pt.length.toLocaleString()} rows, past the configured maxBytesEstimate of ${Math.round(N.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 ft.total=="number"&&Pt.length<ft.total){const _t=!!(We.residual.filters||We.residual.quick||We.residual.sort&&We.residual.sort.length);if(_t&&!$)throw new Error(`[lattice] the ${k} adapter returned ${Pt.length} of ${ft.total} matching rows when asked for the whole result, and the query has residual ${We.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.`);_t?z(`source.pushdown.partial.residual.${k}`,`the ${k} adapter returned ${Pt.length} of ${ft.total} matching rows when asked for the whole result, and residual work will run over that fraction. allowPartialResults is set, so the result is used as-is — it may be wrong. The adapter must follow the engine's own paging to be correct.`):z(`source.pushdown.partial.${k}`,`the ${k} adapter returned ${Pt.length} of ${ft.total} matching rows when asked for the whole result. The adapter must follow the engine's own paging before returning.`)}x={key:st,rows:Pt,total:typeof ft.total=="number"?ft.total:null}}let dt=We;if(We.residual.where){const ft=x.total??x.rows.length;if(ft>=S){ne(We.residual.where.names,k,ft,S);const{where:Pt,..._t}=Ye.request;dt=t(_t,K,N.enabled),ee=dt}}const vt=x.total!==null&&x.rows.length>=x.total,St=f(x.rows,{...dt.residual,whole:vt},O.compute||{}),$t=$e.range?$e.range.start:0,At=$e.range?$e.range.end:St.length;return ht({rows:St.slice($t,At),total:St.length})},be=async($e,Pe,He)=>{const We=He&&He.waitForPage&&ce&&l(ce.pageForegroundIdle)?ce.pageForegroundIdle():ie();We&&await We;const nt=R();nt&&await nt;const ut=t($e,K,N.enabled);ee=ut;const ht=L(Pe,Z),st=Array.isArray($e.groupBy)?$e.groupBy:[],dt=st.length>0,vt=!ut.residual.filters&&!ut.residual.quick,St=!dt||D(st,K.buckets);let $t=ht.engine,At=ht.client;if(K.aggregates&&$t.length){const Lt=K.aggregates instanceof Set?K.aggregates:new Set(ue(K.aggregates)),Gt=$t.filter(gt=>!Lt.has(gt.fn));Gt.length&&($t=$t.filter(gt=>Lt.has(gt.fn)),At=[...Gt.map(gt=>({...gt,reason:`the ${k} adapter does not compute "${gt.fn}"`})),...At])}const ft=Lt=>{At=[...$t.map(Gt=>({...Gt,reason:Lt})),...At],$t=[]};$t.length&&!vt?ft(ut.residual.quick&&!ut.residual.filters?"a quick search the adapter cannot push forces all-client (no mixed provenance)":"residual filter forces all-client (no mixed provenance)"):$t.length&&!St&&ft("a grouping key the engine cannot form forces all-client (no mixed provenance)");let Pt={},_t;return $t.length&&(l(dt?I.executeGroupedAggregates:I.executeAggregates)?dt?_t=await I.executeGroupedAggregates(ut.pushed,st,$t)||[]:Pt=await I.executeAggregates(ut.pushed,$t)||{}:(z(`source.pushdown.aggregates.${k}${dt?".grouped":""}`,`the ${k} adapter cannot compute ${dt?"grouped ":""}aggregates, so every requested statistic is computed client-side. Correct, and slower than it needs to be.`),ft(`adapter cannot compute ${dt?"grouped ":""}aggregates`))),se={engine:$t,client:At,...dt?{groupBy:st}:{}},{values:Pt,engine:$t,client:At,..._t!==void 0?{groups:_t}:{}}},ge=async $e=>{tt++;try{return await Oe($e)}finally{if(tt--,tt===0&&he.length){const Pe=he;he=[];for(const He of Pe)He()}}},ke=P(O.edit),Ee=O.edit&&typeof O.edit=="object"&&l(O.edit.commit);let Re=O.edit;if(ke&&!Ee)if(K.mutate&&K.mutate.update){const $e=Pe=>{if(!K.mutate||!K.mutate.update)throw new Error(`[lattice] the ${k} 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 He={kind:"update",key:String(Pe.key),patch:{[Pe.colId]:Pe.value}};return I.mutate(He,Pe.request||{})};Re={...O.edit===!0?{}:O.edit,commit:$e}}else z(`source.pushdown.readonly.${k}`,`edit is enabled but the ${k} adapter declares mutate: ${K.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 ze=ke&&K.mutate&&(K.mutate.append||K.mutate.delete)?{append:K.mutate.append===!0,remove:K.mutate.delete===!0,returning:K.mutate.returning,mutate:($e,Pe)=>I.mutate($e,Pe||{})}:null,Ge=async $e=>{const Pe=R();Pe&&await Pe;const{range:He,signal:Ye,export:We,...nt}=$e||{},ut={...nt,groupBy:[],groupPath:[],groupValues:[],pivotBy:[],pivotMode:!1,totals:[]};return{plan:t(ut,K,N.enabled),signal:Ye}};async function*Ke($e,Pe={}){const{plan:He,signal:Ye}=await Ge($e),We=Math.max(1,Math.floor(Number(Pe.pageSize))||5e3),nt={signal:Ye,stream:!0};if(!He.needsAll)for(let st=0;;st+=We){h(nt);const dt=await I.execute({...He.pushed,range:{start:st,end:st+We}},nt);dt&&q(dt.pendingTotal)&&dt.pendingTotal.then(null,()=>{});const vt=dt&&dt.rows||[];if(vt.length&&(yield vt),vt.length<We)return}h(nt);const ut=await Q(await I.execute({...He.pushed,range:void 0},nt)),ht=f(ut&&ut.rows||[],{...He.residual,whole:!0},O.compute||{});for(let st=0;st<ht.length;st+=We)yield ht.slice(st,st+We)}return ce={...O,edit:Re,rowMutate:ze,mode:"remote",fetch:ge,foregroundIdle:ie,aggregate:be,countMatching:async $e=>{const{plan:Pe,signal:He}=await Ge($e);if(!Pe.needsAll&&K.total){h({signal:He});const We=await Q(await I.execute({...Pe.pushed,range:{start:0,end:0}},{signal:He}));if(We&&typeof We.total=="number")return We.total}let Ye=0;for await(const We of Ke($e))Ye+=We.length;return Ye},streamMatching:Ke,lastPlan:()=>ee?{...ee,...se?{aggregates:se}:{},...me?{total:{deferred:!0,state:me.state,value:me.value}}:{}}:null,fullFrame:te,counts:()=>({match:de,total:xe??null,pending:!!me&&me.state==="pending"}),grandTotals:()=>ye},ce}}),rt("packages/modules/shared/engine.js",function(s,ae){"use strict";Object.defineProperty(s,"sourceId",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"engineSource",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"gridPivoted",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"loadedAndMatching",{enumerable:!0,get:function(){return L}}),Object.defineProperty(s,"gridHoldsWindow",{enumerable:!0,get:function(){return D}}),Object.defineProperty(s,"gridEngineRequest",{enumerable:!0,get:function(){return w}}),Object.defineProperty(s,"EngineFlight",{enumerable:!0,get:function(){return y}});const ve=ae("packages/core/src/source/pushdown.js"),F=ve.capabilitiesOf,l=ve.planQuery,z=ae("packages/core/src/source/filterwire.js").wireFilters,fe=new WeakMap;let J=0;function X(i){let h=fe.get(i);return h===void 0&&(h=++J,fe.set(i,h)),h}function ne(i){const h=i&&typeof i.config=="function"?i.config():null,c=h&&h.source&&typeof h.source=="object"?h.source:null;if(!c||typeof c.aggregate!="function")return{reason:"the grid's source has no aggregate() — it is not a pushdown source"};const m=F(c.adapter&&c.adapter.capabilities);return{source:c,caps:m,config:h}}function B(i){const h=i&&typeof i.config=="function"?i.config():null,c=h&&h.source&&typeof h.source=="object"?h.source:null;if(!c||typeof c.lastPlan!="function")return!1;const m=i&&i.state&&typeof i.state.get=="function"?i.state.get():null,b=m&&m.pivot;return!!(b&&b.enabled&&Array.isArray(b.columns)&&b.columns.length>0)}function L(i){const h=i.rows&&typeof i.rows.residentCount=="function"?i.rows.residentCount():0,c=typeof i.rows.matchCount=="function"?i.rows.matchCount():NaN;return{loaded:h,total:Number.isFinite(c)?c:NaN}}function D(i){const h=i&&typeof i.config=="function"?i.config():null,c=h&&h.source&&typeof h.source=="object"?h.source:null;if(!c||c.mode!=="remote"&&c.mode!=="paged")return!1;if(typeof i.rows.matchCount=="function"&&i.rows.matchCount()===null)return!0;const{loaded:m,total:b}=L(i);return Number.isFinite(b)&&m<b}function o(i,h){return h?i?{op:"and",conditions:[i,h]}:h:i||null}function w(i,h,c=null){const m=i.filters&&typeof i.filters.where=="function"?i.filters.where():[];if(Array.isArray(m)&&m.length)return{reason:`a \`where\` predicate is in force (${m.join(", ")}), which only the browser can run`};const b=i.filters&&typeof i.filters.quickState=="function"?i.filters.quickState():{text:""},P=b&&b.text?String(b.text):"",{config:u,caps:A}=h,r={filters:z(o(i.filters.get(),c),{tz:u.timeZone,weekStartsOn:u.weekStartsOn}),sort:[],range:null,context:u.context??null,...P?{quick:P}:{}},j=l(r,A);return j.unpushed.includes("filter")?{reason:c?"the grid's filter, or the viewport condition, did not fully push to the engine":"the grid's filter did not fully push to the engine"}:j.unpushed.includes("quick")?{reason:"the quick search did not push to the engine"}:{request:r,quick:P}}class y{#e=null;#t=null;#n=!1;answer(h){return this.#t&&this.#t.key===h?this.#t:null}last(){return this.#t}get busy(){return this.#e!==null}ask(h,c,m){const b=this.#e;if(b){b.key!==h&&b.controller&&b.controller.abort();return}const P=globalThis.AbortController,u=typeof P=="function"?new P:null,A={key:h,controller:u};this.#e=A;let r;Promise.resolve().then(()=>c(u?u.signal:null)).then(j=>{r={key:h,result:j}},j=>{r={key:h,error:j}}).then(()=>{this.#e===A&&(this.#e=null),!this.#n&&(u&&u.signal.aborted||(this.#t=r),m())})}abort(){const h=this.#e;h&&h.controller&&h.controller.abort()}close(){this.#n=!0,this.abort()}}}),rt("packages/modules/charts/stat-widgets.js",function(s,ae){"use strict";const F=ae("packages/modules/charts/registry.js").registerChartType,ue=ae("packages/modules/charts/cartesian.js").drawCartesian,z=ae("packages/modules/shared/engine.js"),fe=z.engineSource,J=z.gridHoldsWindow,X=z.gridPivoted,ne="http://www.w3.org/2000/svg";function B(e){return e==null||typeof e!="number"||!Number.isFinite(e)?"—":Math.abs(e)>=100?e.toFixed(0):e.toFixed(2)}function L(e){return!e||"reason"in fe(e)?!1:J(e)||X(e)}function D(e){return{empty:!1,legend:[],refusal:{stat:e,lines:[`${e}: not computed`,"a pushdown source holds a window of its rows, and this","statistic needs every matching row — refused, not drawn","over the loaded window."]}}}function o(e,f){for(const E of e.childNodes||[])if(E&&E.getAttribute&&E.getAttribute("class")===f)return E;const d=e.ownerDocument.createElementNS(ne,"g");return d.setAttribute("class",f),e.appendChild(d),d}function w(e,f,d){const{plot:E,groups:M,helpers:W}=e,{Pool:oe,attrs:q,round:Q,setText:H,NS:O}=W,I=new oe(M.overlay),K=E.top+14;return f.forEach((g,k)=>{const V=I.next("text",`${O}__${d}`);H(V,g),q(V,{x:Q(E.left),y:Q(K+k*16),"font-size":12})}),I.finish(),K+f.length*16+10}function y(e,f){return w(e,f.lines,"stat-refusal"),new e.helpers.Pool(e.groups.marks).finish(),new e.helpers.Pool(e.groups.axis).finish(),{empty:!1,refusal:f,readout:f.lines,legend:[]}}function i(e,f){const d=f&&(f.y||f.field)||null;if(!d||!e||!e.statistics||typeof e.statistics.profile!="function")return{empty:!0};if(L(e)&&typeof e.statistics.profileAsync=="function")return{empty:!1,mode:"engine",field:d,legend:[]};const E=e.statistics.profile(d);return E?{profile:E,field:d,empty:!1}:{empty:!0}}const h=new WeakMap;function c(e){let f=h.get(e);return f||(f=new Map,h.set(e,f)),f}function m(e){try{const f=e.filters&&typeof e.filters.get=="function"?e.filters.get():null,d=e.filters&&typeof e.filters.quickState=="function"?(e.filters.quickState()||{}).text:"";return JSON.stringify([f||null,d||""])}catch{return""}}function b(e,f,d){const{plot:E,groups:M,helpers:W}=e,{Pool:oe,attrs:q,round:Q,setText:H,linearScale:O,NS:I}=W,K=Array.isArray(f.unavailable)?f.unavailable.map(S=>S.stat):[],g=[`column profile · n=${f.rows}${d?" · computed in the data engine":""}`,`distinct ${f.distinct} missing ${f.missing} mean ${B(f.mean)} median ${B(f.median)} sd ${B(f.stddev)}`,`q1 ${B(f.q1)} q3 ${B(f.q3)} iqr ${B(f.iqr)} outliers ${f.outliers==null?"—":f.outliers}`];K.length&&g.push(`not computed in the engine: ${K.join(", ")}`);const k=w(e,g,"profile-stat"),V=Array.isArray(f.histogram)?f.histogram:[],R=new oe(M.marks),N=new oe(M.axis),$=E.bottom;if(V.length&&$>k){const S={min:V[0].from,max:V[V.length-1].to};S.max<=S.min&&(S.max=S.min+1);const Y=O(S,[E.left,E.right]),Z=V.reduce((x,ee)=>Math.max(x,ee.count),0)||1;V.forEach((x,ee)=>{const se=Y.of(x.from),de=Y.of(x.to),ye=($-k)*x.count/Z;q(R.next("rect",`${I}__mark ${I}__profile-bar`),{x:Q(Math.min(se,de)),y:Q($-ye),width:Q(Math.max(1,Math.abs(de-se)-1)),height:Q(Math.max(0,ye)),fill:"currentColor","fill-opacity":.65,"data-point":ee})}),q(N.next("line",`${I}__gridline`),{x1:Q(E.left),y1:Q($),x2:Q(E.right),y2:Q($),stroke:"currentColor","stroke-opacity":.3})}return R.finish(),N.finish(),{profile:f,provenance:d?"engine":"client",readout:g,method:"column profile",n:f.rows,legend:[]}}function P(e){const f=e.bound||{};if(f.refusal)return y(e,f.refusal);if(f.mode==="engine"){const d=e.grid,E=c(d),M=`${f.field} ${m(d)}`;let W=E.get(M);if(W||(W={status:"pending",profile:null},E.set(M,W),Promise.resolve(d.statistics.profileAsync(f.field)).then(oe=>{W.status="done",W.profile=oe,typeof e.redraw=="function"&&e.redraw()},()=>{W.status="done",W.profile=null})),W.status!=="done"){const oe=["column profile · computing in the data engine…"];return w(e,oe,"profile-stat"),new e.helpers.Pool(e.groups.marks).finish(),new e.helpers.Pool(e.groups.axis).finish(),{pending:!0,provenance:"engine",readout:oe,legend:[]}}if(!W.profile){const oe=["column profile: the data engine returned no answer."];return w(e,oe,"profile-stat"),new e.helpers.Pool(e.groups.marks).finish(),new e.helpers.Pool(e.groups.axis).finish(),{empty:!0,provenance:"engine",readout:oe,legend:[]}}return b(e,W.profile,!0)}return f.profile?b(e,f.profile,f.profile.computed==="source"):{empty:!0,legend:[]}}F("profile",{draw:P,bind:i,freeform:!0,family:"statistics"});const u=Object.freeze(["histogram","box","violin","ecdf"]);function A(e,f){const d=[];return e&&e.rows&&typeof e.rows.forEach=="function"&&typeof e.rows.value=="function"&&e.rows.forEach(E=>{if(!E||E.group||E.key==null)return;const M=Number(e.rows.value(E.key,f));Number.isFinite(M)&&d.push(M)}),d.sort((E,M)=>E-M),d}function r(e,f){const d=f&&(f.y||f.field)||null;if(!d||!e||!e.statistics||typeof e.statistics.profile!="function")return{empty:!0};if(L(e))return D("distribution");const E=e.statistics.profile(d);if(!E||!E.rows)return{empty:!0};const M=u.includes(f&&f.mode)?f.mode:"histogram",W=typeof e.statistics.reduce=="function"?e.statistics.reduce(d,"jarqueBera"):null,oe=M==="ecdf"||M==="violin"?A(e,d):null;return{profile:E,field:d,mode:M,jb:W,values:oe,empty:!1,legend:[]}}function j(e){const f=e.bound||{};if(f.refusal)return y(e,f.refusal);if(!f.profile)return{empty:!0,legend:[]};const{plot:d,groups:E,helpers:M}=e,{Pool:W,attrs:oe,round:q,linearScale:Q,NS:H}=M,{profile:O,mode:I,jb:K,values:g}=f,k=O.rows,V=K==null?"n/a (too few)":K<=5.99?"normal":"non-normal",R=[`distribution (${I}) · n=${k}`,`Jarque–Bera ${B(K)} — ${V} at 5%`],N=w(e,R,"distribution-stat"),$=d.bottom,S=new W(E.marks),Y=new W(E.axis),Z=O.min,x=O.max;if($>N&&Number.isFinite(Z)&&Number.isFinite(x)){const ee={min:Z,max:x<=Z?Z+1:x},se=Q(ee,[d.left,d.right]);if(I==="box"){const de=(N+$)/2,ye=Math.max(8,($-N)/4);oe(S.next("line",`${H}__mark ${H}__dist-whisker`),{x1:q(se.of(Z)),y1:q(de),x2:q(se.of(x)),y2:q(de),stroke:"currentColor","stroke-opacity":.6}),oe(S.next("rect",`${H}__mark ${H}__dist-box`),{x:q(se.of(O.q1)),y:q(de-ye),width:q(Math.max(1,se.of(O.q3)-se.of(O.q1))),height:q(ye*2),fill:"currentColor","fill-opacity":.25,stroke:"currentColor"}),oe(S.next("line",`${H}__mark ${H}__dist-median`),{x1:q(se.of(O.median)),y1:q(de-ye),x2:q(se.of(O.median)),y2:q(de+ye),stroke:"currentColor","stroke-width":2})}else if(I==="ecdf"&&Array.isArray(g)&&g.length){const de=Q({min:0,max:1},[$,N]),ye=g.map((xe,me)=>`${q(se.of(xe))},${q(de.of((me+1)/g.length))}`);oe(S.next("path",`${H}__mark ${H}__dist-ecdf`),{d:`M${ye.join("L")}`,fill:"none",stroke:"currentColor","stroke-width":1.5})}else{const de=Array.isArray(O.histogram)?O.histogram:[],ye=de.reduce((me,Ne)=>Math.max(me,Ne.count),0)||1,xe=(N+$)/2;de.forEach((me,Ne)=>{const Ae=se.of(me.from),te=se.of(me.to),re=q(Math.max(1,Math.abs(te-Ae)-1));if(I==="violin"){const le=($-N)/2*(me.count/ye);oe(S.next("rect",`${H}__mark ${H}__dist-violin`),{x:q(Math.min(Ae,te)),y:q(xe-le),width:re,height:q(le*2),fill:"currentColor","fill-opacity":.5,"data-point":Ne})}else{const le=($-N)*(me.count/ye);oe(S.next("rect",`${H}__mark ${H}__dist-bar`),{x:q(Math.min(Ae,te)),y:q($-le),width:re,height:q(Math.max(0,le)),fill:"currentColor","fill-opacity":.65,"data-point":Ne})}})}oe(Y.next("line",`${H}__gridline`),{x1:q(d.left),y1:q($),x2:q(d.right),y2:q($),stroke:"currentColor","stroke-opacity":.3})}return S.finish(),Y.finish(),{profile:O,mode:I,jb:K,readout:R,method:I,n:k,legend:[]}}F("distribution",{draw:j,bind:r,freeform:!0,family:"statistics"});function C(e,f){const d=Array.isArray(f&&f.columns)?f.columns.filter(Q=>typeof Q=="string"&&Q):[];if(d.length<2||!e||!e.statistics)return{empty:!0};if(L(e))return D("correlation");const E=f.method==="spearman"?"spearman":"pearson",M=E==="spearman"?e.statistics.spearman:e.statistics.correlation;if(typeof M!="function")return{empty:!0};const W=d.map(Q=>d.map(H=>{if(Q===H)return 1;const O=M.call(e.statistics,Q,H);return typeof O=="number"&&Number.isFinite(O)?O:null})),oe=typeof e.statistics.profile=="function"?e.statistics.profile(d[0]):null,q=oe?oe.numeric!=null?oe.numeric:oe.rows:0;return{columns:d,matrix:W,method:E,n:q,empty:!1,legend:[]}}function G(e){const f=e.bound||{};if(f.refusal)return y(e,f.refusal);if(!f.matrix)return{empty:!0,legend:[]};const{plot:d,groups:E,helpers:M}=e,{Pool:W,attrs:oe,round:q,setText:Q,NS:H}=M,{columns:O,matrix:I,method:K,n:g}=f,k=[`correlation (${K}) · n=${g}`],V=w(e,k,"correlation-stat"),R=new W(E.marks),N=new W(o(E.overlay,`${H}__correlation-cells`)),$=O.length,S=Math.min((d.right-d.left)/$,(d.bottom-V)/$);if(S>0)for(let Y=0;Y<$;Y++)for(let Z=0;Z<$;Z++){const x=I[Y][Z],ee=d.left+Z*S,se=V+Y*S;oe(R.next("rect",`${H}__mark ${H}__correlation-cell`),{x:q(ee),y:q(se),width:q(S-1),height:q(S-1),fill:"currentColor","fill-opacity":x==null?0:Math.min(1,Math.abs(x)),stroke:"currentColor","stroke-opacity":.25,"data-point":Y*$+Z});const de=N.next("text",`${H}__correlation-value`);Q(de,x==null?"—":x.toFixed(2)),oe(de,{x:q(ee+S/2),y:q(se+S/2+4),"font-size":10,"text-anchor":"middle"})}return R.finish(),N.finish(),{columns:O,matrix:I,method:K,n:g,readout:k,legend:[]}}F("correlation",{draw:G,bind:C,freeform:!0,family:"statistics"});function _(e,f){const d=f||{},E=d.y||d.field,M=d.group||d.by;if(!E||!M||!e||!e.statistics||typeof e.statistics.compareGroups!="function")return{empty:!0};if(L(e))return D("group comparison");const W=e.statistics.compareGroups(E,{by:M,groups:Array.isArray(d.groups)?d.groups:void 0,test:d.test,confidence:d.confidence});return W?{comparison:W,empty:!1}:{empty:!0}}function T(e){const f=e.bound||{};if(f.refusal)return y(e,f.refusal);const{plot:d,groups:E,helpers:M}=e,{Pool:W,attrs:oe,round:q,linearScale:Q,NS:H}=M,O=f.comparison;if(!O)return{empty:!0,legend:[]};const I=O.interval||{},K=I.lower,g=I.upper,k=I.estimate!==void 0?I.estimate:Number.isFinite(K)&&Number.isFinite(g)?(K+g)/2:null,V=Array.isArray(O.groups)?O.groups.map(String):["A","B"],R=Math.round((I.confidence||.95)*100),N=[`${V[0]} vs ${V[1]}: difference ${B(k)} [${B(K)}, ${B(g)}] (${R}% CI)`,`${O.test} p=${B(O.pValue)} effect size ${B(O.effectSize)} n=${O.nA}/${O.nB}`],$=w(e,N,"groupcomparison-stat")+6,S=d.bottom,Y=new W(E.marks),Z=new W(E.axis);if(Number.isFinite(K)&&Number.isFinite(g)&&S>$){const x=Math.max(Math.abs(g-K)*.4,1),ee={min:Math.min(0,K-x),max:Math.max(0,g+x)},se=Q(ee,[d.left,d.right]),de=$+(S-$)/2;oe(Z.next("line",`${H}__reference`),{x1:q(se.of(0)),y1:q($),x2:q(se.of(0)),y2:q(S),stroke:"currentColor","stroke-opacity":.3,"stroke-dasharray":"3 3"}),oe(Y.next("line",`${H}__mark ${H}__groupcomparison-interval`),{x1:q(se.of(K)),y1:q(de),x2:q(se.of(g)),y2:q(de),stroke:"currentColor","stroke-width":2}),oe(Y.next("circle",`${H}__mark ${H}__groupcomparison-estimate`),{cx:q(se.of(k)),cy:q(de),r:5,fill:"currentColor","data-point":0})}return Y.finish(),Z.finish(),{comparison:O,readout:N,method:O.test,n:`${O.nA}/${O.nB}`,legend:[]}}F("groupComparison",{draw:T,bind:_,freeform:!0,family:"statistics"});function p(e,f){const d=f||{},E=d.x,M=d.y;if(!E||!M||!e||!e.statistics||typeof e.statistics.regressionModel!="function")return{empty:!0};if(L(e))return D("model errors");const W=e.statistics.regressionModel({predictors:[E],response:M});if(!W||!Array.isArray(W.rows)||!W.rows.length)return{empty:!0};const oe=new Map(W.rows.map((Q,H)=>[Q,H])),q=new Array(W.rows.length);return e.rows&&typeof e.rows.forEachAll=="function"&&typeof e.rows.value=="function"&&e.rows.forEachAll((Q,H)=>{if(!oe.has(H)||!Q||Q.key==null)return;const O=oe.get(H),I=Number(e.rows.value(Q.key,E));Number.isFinite(I)&&(q[O]={x:I,fitted:W.fitted[O],residual:W.residuals[O],leverage:W.leverage[O],cooksD:W.cooksD[O]})}),{model:W,rows:q.filter(Boolean),predictor:E,response:M,empty:!1}}const v=Object.freeze(["fit","residuals","influence"]);function n(e,f){if(e==="residuals")return{points:f.map(d=>({x:d.fitted,y:d.residual})),xLabel:"Fitted",yLabel:"Residual",zero:!0};if(e==="influence"){const d=f.reduce((E,M)=>Math.max(E,M.cooksD||0),0)||1;return{points:f.map(E=>({x:E.leverage,y:E.residual,size:(E.cooksD||0)/d})),xLabel:"Leverage",yLabel:"Residual",zero:!0}}return{points:f.map(d=>({x:d.x,y:d.fitted+d.residual})),xLabel:"Predictor",yLabel:"Response",zero:!1}}function t(e){const f=e.bound||{};if(f.refusal)return y(e,f.refusal);const{plot:d,groups:E,spec:M,helpers:W}=e,{Pool:oe,attrs:q,round:Q,linearScale:H,measureDomain:O,NS:I}=W;if(!f.model||!f.rows||!f.rows.length)return{empty:!0,legend:[]};const K=v.includes(M&&M.preset)?M.preset:"fit",g=n(K,f.rows),{model:k}=f,V=Array.isArray(f.rows)?f.rows.length:k.n,R=k.cooksD?k.cooksD.filter(ee=>ee>4/V).length:0,N=typeof k.method=="string"?k.method.toUpperCase():"OLS",$=[`model error · ${N} · ${K} · R²=${B(k.r2)} · n=${V} · influential=${R}`],S=w(e,$,"modelerror-stat"),Y=d.bottom,Z=new oe(E.marks),x=new oe(E.axis);if(g.points.length&&Y>S){const ee=O(g.points.map(xe=>xe.x),{zero:!1}),se=O(g.points.map(xe=>xe.y),{zero:g.zero}),de=H(ee,[d.left,d.right]),ye=H(se,[Y,S]);if(g.zero&&se.min<=0&&se.max>=0&&q(x.next("line",`${I}__reference`),{x1:Q(d.left),y1:Q(ye.of(0)),x2:Q(d.right),y2:Q(ye.of(0)),stroke:"currentColor","stroke-opacity":.3,"stroke-dasharray":"3 3"}),g.points.forEach((xe,me)=>{const Ne=xe.size!==void 0?3+xe.size*7:3;q(Z.next("circle",`${I}__mark ${I}__modelerror-point`),{cx:Q(de.of(xe.x)),cy:Q(ye.of(xe.y)),r:Q(Ne),fill:"currentColor","fill-opacity":.6,"data-point":me})}),K==="fit"&&k.band&&Array.isArray(k.band.points)&&k.band.points.length>1){const xe=k.band.points.map(me=>`${Q(de.of(me.x))},${Q(ye.of(me.yhat))}`);q(Z.next("path",`${I}__mark ${I}__modelerror-fit`),{d:`M${xe.join("L")}`,fill:"none",stroke:"currentColor","stroke-width":1.5})}}return Z.finish(),x.finish(),{model:k,preset:K,readout:$,method:N,n:V,legend:[]}}F("modelError",{draw:t,bind:p,freeform:!0,family:"statistics"});function a(e){if(L(e.grid)){const $=D("forecast").refusal;return y(e,$)}const f=e.spec||{},d=f.trend&&typeof f.trend=="object"?f.trend:{},E=ue({...e,type:"line",fit:f.fit,trend:f.trend||!0,band:f.band,byRuleColour:!f.series,fill:f.fill,marker:f.marker,stack:f.stack,mark:f.mark,reference:f.reference,annotations:f.annotations,emphasis:f.emphasis,seriesStyle:f.seriesStyle,curve:f.curve,downsampleTo:f.downsample,keepInfluential:!!f.perRow,keepRows:Array.isArray(f.keepRows)?new Set(f.keepRows.map(String)):void 0})||{},M=typeof d.method=="string"?d.method:"linear",W=Number.isFinite(d.forecast)?d.forecast:0,oe=Array.isArray(E.series)?E.series.reduce(($,S)=>$+(Array.isArray(S.points)?S.points.length:0),0):0,q=[`forecast · ${M} · horizon ${W} · n=${oe}`],{plot:Q,groups:H,helpers:O}=e,{Pool:I,attrs:K,round:g,setText:k,NS:V}=O,R=new I(o(H.overlay,`${V}__forecast-readout`)),N=R.next("text",`${V}__forecast-stat`);return k(N,q[0]),K(N,{x:g(Q.left),y:g(Q.top+14),"font-size":12}),R.finish(),{...E,readout:q,method:M,horizon:W,n:oe}}F("forecast",{draw:a,labelled:!0,family:"statistics"})}),rt("packages/modules/designer/statistics-widgets.js",function(s,ae){"use strict";Object.defineProperty(s,"installStatisticsWidgets",{enumerable:!0,get:function(){return l}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return ue}});const ve=ae("packages/modules/charts/stat-widgets.js"),F=Object.freeze({columnProfile:Object.freeze({type:"profile"}),distribution:Object.freeze({type:"distribution",options:{mode:"histogram"}}),correlation:Object.freeze({type:"correlation",options:{method:"pearson"}}),groupComparison:Object.freeze({type:"groupComparison"}),forecast:Object.freeze({type:"forecast",options:{trend:{method:"linear",forecast:3,band:"prediction"}}}),modelError:Object.freeze({type:"modelError",options:{preset:"fit"}})});function l(z,fe={}){let J=!1;return{get kinds(){return Object.keys(F)},defaults(X){const ne=F[X];return ne?{type:ne.type,...ne.options?{options:{...ne.options}}:{}}:null},add(X,ne,B={}){if(J)return!1;const L=F[X];if(!L||!ne)return!1;const{placement:D,options:o,...w}=B,y={id:ne,kind:"chart",...w,options:{...L.options?L.options:{},...o||{},type:L.type}};return z.addWidget(y,D)},destroy(){J=!0}}}const ue=l}),rt("packages/modules/designer/pages.js",function(s,ae){"use strict";Object.defineProperty(s,"addPageState",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"renamePageState",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"movePageState",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"removePageState",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(s,"installPages",{enumerable:!0,get:function(){return B}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return L}});const F=ae("packages/modules/dashboard/spec.js").isPlain,ue=ae("packages/core/src/internal/util.js").warnOnce;function z(D){if(Array.isArray(D))return D.map(z);if(!F(D))return D;const o={};for(const w of Object.keys(D))o[w]=z(D[w]);return o}function fe(D,o,w){if(!F(D)||!Array.isArray(D.pages))return null;const y=F(o)?o:{},i=D.pages,h=new Set(i.filter(F).map(P=>String(P.id)));let c=i.length+1;for(;h.has(`page-${c}`);)c+=1;const m=typeof y.id=="string"&&y.id!==""&&!h.has(y.id)?y.id:`page-${c}`;let b;if(typeof y.duplicate=="string"&&y.duplicate!==""){const P=i.find(u=>F(u)&&u.id===y.duplicate);if(!P)return null;b=z(P),b.id=m,b.title=typeof y.title=="string"&&y.title!==""?y.title:w("designer.page.copy",{title:typeof P.title=="string"?P.title:String(P.id)})}else b={id:m,title:typeof y.title=="string"&&y.title!==""?y.title:w("designer.page",{n:c}),spec:{panels:[]}};return i.push(b),m}function J(D,o,w){if(!F(D)||!Array.isArray(D.pages))return null;const y=D.pages.find(h=>F(h)&&h.id===o);if(!y)return null;const i=typeof w=="string"?w.trim():"";return i===""?null:(y.title=i,D)}function X(D,o,w){if(!F(D)||!Array.isArray(D.pages))return null;const y=D.pages,i=y.findIndex(b=>F(b)&&b.id===o);if(i<0)return null;const h=Number.isFinite(w)?w:0;if(h===0)return null;const c=Math.max(0,Math.min(y.length-1,i+h));if(c===i)return null;const[m]=y.splice(i,1);return y.splice(c,0,m),D}function ne(D,o){if(!F(D)||!Array.isArray(D.pages))return null;const w=D.pages,y=w.findIndex(h=>F(h)&&h.id===o);if(y<0)return null;const[i]=w.splice(y,1);return D.selectedPageId===o&&(D.selectedPageId=w.length?w[Math.min(y,w.length-1)].id:null),i}function B(D,o){D.register("addPage",(w,y)=>{if(!w.designer.guardrails.allowsPage("add"))return ue("designer:page:add","designer.addPage: adding a page is not allowed by guardrails.pages.add; nothing was added."),null;const i=w.getState(),h=fe(i,y,o);if(h===null||(i.selectedPageId=h,!w.commit(i,"addPage")))return null;const c=i.pages.find(m=>F(m)&&m.id===h);return w.designer.announce(o("a11y.designer.page.added",{title:c&&c.title!=null?c.title:h})),h}),D.register("renamePage",(w,y,i)=>{if(!w.designer.guardrails.allowsPage("rename"))return ue("designer:page:rename","designer.renamePage: renaming a page is not allowed by guardrails.pages.rename; nothing was changed."),!1;const h=w.getState();if(!J(h,y,i)||!w.commit(h,"renamePage"))return!1;const c=h.pages.find(m=>F(m)&&m.id===y);return w.designer.announce(o("a11y.designer.page.renamed",{title:c&&c.title!=null?c.title:y})),!0}),D.register("movePage",(w,y,i)=>{if(!w.designer.guardrails.allowsPage("reorder"))return ue("designer:page:reorder","designer.movePage: reordering a page is not allowed by guardrails.pages.reorder; nothing was moved."),!1;const h=w.getState();return X(h,y,i)?w.commit(h,"movePage"):!1}),D.register("removePage",(w,y)=>{if(!w.designer.guardrails.allowsPage("remove"))return ue("designer:page:remove","designer.removePage: removing a page is not allowed by guardrails.pages.remove; nothing was removed."),!1;const i=w.getState(),h=ne(i,y);if(!h)return!1;const c=h.title!=null?h.title:y;return w.commit(i,"removePage")?(w.designer.announce(o("a11y.designer.page.removed",{title:c})),!0):!1})}const L=B}),rt("packages/modules/designer/config-router.js",function(s,ae){"use strict";Object.defineProperty(s,"stateToConfigRows",{enumerable:!0,get:function(){return c}}),Object.defineProperty(s,"configRowsToState",{enumerable:!0,get:function(){return P}}),Object.defineProperty(s,"installConfigRouting",{enumerable:!0,get:function(){return A}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return r}});const ve=ae("packages/core/src/internal/util.js"),F=ve.warnOnce,l=ve.isFunction,ue=ae("packages/modules/dashboard/spec.js"),z=ue.isPlain,fe=ue.copySpec,J=ue.sameSpec,ne=ae("packages/modules/designer/migrate.js").SCHEMA_VERSION,B="page",L="filter",D="relationship",o="@page/",w="@filter/",y="@rel/";function i(j,C){const G={};for(const _ of Object.keys(j))C.includes(_)||(G[_]=fe(j[_],_));return G}function h(j){return Array.isArray(j)&&j.length>0&&j.every(C=>z(C)&&C.id!=null&&String(C.id)!=="")}function c(j){const C=[];if(!z(j)||!Array.isArray(j.pages))return C;for(const G of j.pages){if(!z(G))continue;const _=G.id,T=z(G.spec)?G.spec:{},p=Array.isArray(T.panels)?T.panels.filter(z):[],v=z(T.layout)?T.layout:null,n=v&&Array.isArray(v.windows)?v.windows.filter(z):[],t=new Set(p.map(M=>String(M.id))),a=["panels"],e=Array.isArray(T.links)&&T.links.length?T.links.filter(z):null;e&&a.push("links");const f=h(G.filters),d=i(T,a);if(v){const M=n.filter(oe=>!t.has(String(oe.id))),W=i(v,["windows"]);M.length&&(W.windows=M.map(oe=>fe(oe))),d.layout=W}const E=i(G,["id","spec",...f?["filters"]:[]]);_===j.selectedPageId&&(E.selected=!0),C.push({id:`${o}${_}`,page:_,kind:B,source:null,mapping:E,format:d,placement:null,seq:0});for(const M of p){const W=String(M.id),oe=n.find(q=>String(q.id)===W);C.push({id:W,page:_,kind:M.kind,source:M.source!==void 0?M.source:null,mapping:M.options!==void 0?fe(M.options):null,format:i(M,["id","kind","source","options"]),placement:oe?i(oe,["id"]):null,seq:0})}e&&e.forEach((M,W)=>C.push({id:`${y}${_}/${M.id!=null?M.id:`${M.from}->${M.to}`}#${W}`,page:_,kind:D,source:M.from!==void 0?M.from:null,mapping:null,format:fe(M),placement:null,seq:0})),f&&G.filters.forEach((M,W)=>C.push({id:`${w}${_}/${M.id}#${W}`,page:_,kind:L,source:M.source!==void 0?M.source:null,mapping:null,format:fe(M),placement:null,seq:0}))}return C}function m(j){const C={id:j.id};return z(j.format)&&Object.assign(C,fe(j.format)),C.kind=j.kind,j.source!==null&&j.source!==void 0&&(C.source=j.source),j.mapping!==null&&j.mapping!==void 0&&(C.options=fe(j.mapping)),C}function b(j){return j.placement===null||j.placement===void 0?null:{id:j.id,...z(j.placement)?fe(j.placement):{}}}function P(j){const C=Array.isArray(j)?j.filter(z):[],G=new Map,_=[];for(const v of C){const n=v.page;G.has(n)||(G.set(n,{meta:null,widgets:[],links:[],filters:[]}),_.push(n));const t=G.get(n);v.kind===B?t.meta=v:v.kind===D?t.links.push(v):v.kind===L?t.filters.push(v):t.widgets.push(v)}const T=[];let p=null;for(const v of _){const n=G.get(v),t=n.meta,a={};t&&z(t.mapping)&&Object.assign(a,i(t.mapping,["selected"])),a.id=v,t&&z(t.mapping)&&t.mapping.selected&&(p=v);const e=t&&z(t.format)?fe(t.format):{},f=z(e.layout)&&Array.isArray(e.layout.windows)?e.layout.windows.map(d=>fe(d)):[];e.panels=n.widgets.map(d=>{const E=b(d);return E&&f.push(E),m(d)}),f.length&&(e.layout={...z(e.layout)?e.layout:{},windows:f}),n.links.length&&(e.links=n.links.map(d=>fe(d.format))),a.spec=e,n.filters.length&&(a.filters=n.filters.map(d=>fe(d.format))),T.push(a)}return p===null&&T.length&&(p=T[0].id),{schemaVersion:ne,pages:T,selectedPageId:p,panels:{}}}function u(j){return z(j)&&j.kind!==B&&j.kind!==L&&j.kind!==D}function A(j,C){const{commit:G,getState:_,selectedPageId:T,dashboard:p,guardrails:v,on:n}=C;let t=null,a=new Map,e=0;const f=W=>{const oe=new Map;for(const q of c(_()))q.page===W&&oe.set(q.id,q);return oe},d=W=>{if(!t)return;const oe=t.page,q=[],Q=[],H=[],O=_(),I=Array.isArray(O.pages)?O.pages.find(x=>z(x)&&x.id===oe):null,K=I&&z(I.spec)?I.spec:null,g=K&&Array.isArray(K.panels)?K.panels.filter(z):[],k=new Set(g.map(x=>String(x.id))),V=(x,ee)=>{if(!u(x))return;const se=m(x),de=v()&&l(v().restrictPanel)?v().restrictPanel(se):null;if(de){F(`designer:route:refused:${se.id}`,`designer: the routed widget ${JSON.stringify(String(se.id))} is not allowed here, so it was refused — the same answer the ${de} guardrail gives an authored widget.`);return}ee.push({panel:se,window:b(x),id:String(se.id)})};for(const x of Array.isArray(W.add)?W.add:[])V(x,q);for(const x of Array.isArray(W.update)?W.update:[])V(x,Q);for(const x of Array.isArray(W.remove)?W.remove:[]){const ee=String(x);!ee.startsWith(o)&&!ee.startsWith(w)&&!ee.startsWith(y)&&H.push(ee)}if(!q.length&&!Q.length&&!H.length)return;const R=p();R&&l(R.applyConfig)&&oe===T()&&R.applyConfig({add:q,update:Q,remove:H});const N=_(),$=Array.isArray(N.pages)?N.pages.find(x=>z(x)&&x.id===oe):null;if(!$){R&&oe===T()&&G(N,"route",{record:!1,render:!1});return}z($.spec)||($.spec={panels:[]}),Array.isArray($.spec.panels)||($.spec.panels=[]);const S=$.spec,Y=()=>(z(S.layout)||(S.layout={}),Array.isArray(S.layout.windows)||(S.layout.windows=[]),S.layout.windows),Z=({panel:x,window:ee})=>{const se=S.panels.findIndex(de=>z(de)&&String(de.id)===String(x.id));if(se<0?S.panels.push(x):S.panels[se]=x,ee){const de=Y(),ye=de.findIndex(xe=>z(xe)&&String(xe.id)===String(x.id));ye<0?de.push(ee):de[ye]=ee}};for(const x of Q)Z(x);for(const x of q)k.has(x.id)||Z(x);for(const x of H){const ee=S.panels.findIndex(se=>z(se)&&String(se.id)===x);if(ee>=0&&S.panels.splice(ee,1),z(S.layout)&&Array.isArray(S.layout.windows)){const se=S.layout.windows.findIndex(de=>z(de)&&String(de.id)===x);se>=0&&S.layout.windows.splice(se,1)}}G(N,"route",{record:!1,render:!(R&&oe===T())})},E=W=>{if(!t)return;const oe=f(t.page),q=W&&W.cause;if(!(q==="route"||q==="setState"||q==="migrate")&&t.onWrite){for(const[H,O]of oe){const I=a.get(H);(!I||!J(I,O))&&t.onWrite({op:"upsert",row:{...O,seq:++e},before:I||null},{route:t.page,page:t.page,source:"author"})}for(const[H,O]of a)oe.has(H)||t.onWrite({op:"delete",row:{...O,seq:++e},before:O},{route:t.page,page:t.page,source:"author"})}a=oe},M={rows(){return c(_())},toRows(W){return c(W)},fromRows(W){return P(W)},connect(W,oe={}){if(!W||!l(W.subscribe))return F("designer:config-router:connect","designer.configRouter.connect: the first argument is not a Data Router (no subscribe); nothing was connected."),()=>{};M.disconnect();const q=z(oe)?oe:{},Q=q.page!==void 0?q.page:T(),H={};return typeof q.label=="string"&&(H.label=q.label),l(q.filter)&&(H.filter=q.filter),l(q.transform)&&(H.transform=q.transform),W.subscribe(Q,d,{rowKey:"id",...H}),t={router:W,page:Q,onWrite:l(q.onWrite)?q.onWrite:null,offState:n("state",E)},a=f(Q),M.disconnect},disconnect(){t&&(t.offState&&t.offState(),t.router&&l(t.router.detach)&&t.router.detach(d),t=null,a=new Map)},get router(){return t?t.router:null},get page(){return t?t.page:null},explain(W){return t&&l(t.router.explain)?t.router.explain(W):null},get trace(){return t&&t.router.trace?t.router.trace:null},destroy(){M.disconnect()}};return M}const r=A}),rt("packages/modules/designer/data-routes.js",function(s,ae){"use strict";Object.defineProperty(s,"compileWidgetRoute",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"routeRequest",{enumerable:!0,get:function(){return C}}),Object.defineProperty(s,"issueQuery",{enumerable:!0,get:function(){return G}}),Object.defineProperty(s,"executeRouteOverRows",{enumerable:!0,get:function(){return T}}),Object.defineProperty(s,"installDataRouting",{enumerable:!0,get:function(){return p}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return v}});const ve=ae("packages/core/src/internal/util.js"),F=ve.warnOnce,l=ve.isFunction,ue=ae("packages/modules/dashboard/spec.js"),z=ue.isPlain,fe=ue.sameSpec,X=ae("packages/modules/designer/data-panel.js").compileRelationships,B=ae("packages/modules/designer/config-router.js").stateToConfigRows,D=ae("packages/modules/charts/capabilities.js").chartEditorModel,w=ae("packages/core/src/registry/widgets.js").widgetEditorModel,y=ae("packages/core/src/source/pushdown.js"),i=y.planQuery,h=y.capabilitiesOf,c=Object.freeze(["page","filter","relationship"]);function m(n){return z(n)&&!c.includes(n.kind)}function b(n,t){let a=n;for(const e of String(t).split(".")){if(a==null)return;a=a[e]}return a}function P(n){return n==null?"":typeof n=="string"?n:z(n)&&(n.col||n.field)||""}function u(n){const t=z(n.mapping)?n.mapping:{};return n.kind==="chart"||n.kind==="map"?D(typeof t.type=="string"&&t.type?t.type:"bar"):w(n.kind)}function A(n){return n===!0||z(n)&&n.enabled===!0}function r(n,t){const a=n.path||n.role,e=b(t,a),f=n.repeatable?Array.isArray(e)?e:[]:e==null||e===""?[]:[e],d=[];for(const E of f){const M=n.entryKey&&z(E)?E[n.entryKey]:P(E);if(!M)continue;let W,oe=!1;n.entryKey&&z(E)?(typeof E.total=="string"&&E.total&&(W=E.total),oe=A(E.group)||A(E.pivot)):z(E)&&typeof E.fn=="string"&&E.fn&&(W=E.fn),d.push({role:n.role,field:String(M),fn:W,group:oe})}if(!n.repeatable&&n.aggregated&&n.aggPath&&d.length){const E=b(t,n.aggPath);typeof E=="string"&&E&&(d[0].fn=E)}return d}function j(n,t={}){if(!m(n))return null;const a=typeof n.source=="string"?n.source:null,e=Array.isArray(t.relationships)?t.relationships:[],f=Array.isArray(t.filters)?t.filters.filter(z):[],d=z(n.mapping)?n.mapping:{},E=u(n),M=[],W=[];if(E&&Array.isArray(E.roles))for(const g of E.roles)W.push(...r(g,d));const oe=X(e),q=g=>oe.find(k=>k.sourceId===a&&k.relatedSourceId===g),Q=new Map,H=[],O=new Set,I=[],K=[];for(const g of W){let k=g.field;const V=k.indexOf(".");if(V>0&&V<k.length-1){const R=k.slice(0,V),N=k.slice(V+1);if(R!==a){const $=q(R);if(!$){F(`designer:route:unreachable:${n.id}:${R}`,`designer: the widget ${JSON.stringify(n.id)}'s ${JSON.stringify(g.role)} role binds ${JSON.stringify(g.field)}, and no declared relationship reaches ${JSON.stringify(R)} from ${JSON.stringify(a)}; the field was left out of its route.`),M.push(`${g.role}: ${JSON.stringify(g.field)} is not reachable from ${JSON.stringify(a)}`);continue}Q.set(R,$),k=`${R}.${N}`}else k=N}O.has(k)||(O.add(k),H.push(k)),g.group&&!I.includes(k)&&I.push(k),g.fn&&K.push({id:`${g.role}:${k}`,col:k,fn:g.fn,role:g.role})}return{widgetId:n.id,page:n.page,kind:n.kind,sourceId:a,fields:H,groupBy:I,aggregates:K,joins:[...Q.values()],filters:{page:f.filter(g=>g.source===a),global:f.filter(g=>g.source===void 0||g.source===null)},refusals:M}}function C(n,t={}){const a=[...n.filters.page,...n.filters.global].filter(d=>d&&d.field!==void 0&&d.op!==void 0).map(d=>({col:d.field,op:d.op,value:d.value})),e=a.length===0?null:a.length===1?a[0]:{op:"and",conditions:a},f=n.groupBy.length>0||n.aggregates.length>0;return{fields:[...n.fields],filters:e,sort:f?null:Array.isArray(t.sort)?t.sort:null,range:f?null:t.range!==void 0?t.range:null}}async function G(n,t,a={}){const e=n.groupBy.length>0||n.aggregates.length>0,f=t&&l(t.executeGroupedAggregates);if(!t||!(e&&f)&&!l(t.execute))return F("designer:route:no-adapter","designer: issueQuery needs an adapter with an execute(query) function (or executeGroupedAggregates for a grouped route); nothing was asked."),{rows:[],total:0,plan:null};const d=C(n,a),E=h(t.capabilities),M=i(d,E),W={...M.pushed,fields:n.fields};if(e&&f){const q=n.aggregates.map((K,g)=>`lattice_agg_${g}`),Q=n.aggregates.map((K,g)=>({id:q[g],col:K.col,fn:K.fn})),H=new Map(q.map((K,g)=>[K,n.aggregates[g].id])),O=await t.executeGroupedAggregates(W,n.groupBy,Q);return{groups:(Array.isArray(O)?O:[]).map(K=>({...K,values:Object.fromEntries(Object.entries(K.values||{}).map(([g,k])=>[H.get(g)||g,k]))})),plan:M}}const oe=await t.execute(W,d)||{};return{rows:oe.rows||[],total:oe.total,plan:M}}const _=Object.freeze({sum:n=>n.reduce((t,a)=>t+(Number(a)||0),0),avg:n=>n.length?n.reduce((t,a)=>t+(Number(a)||0),0)/n.length:null,min:n=>n.length?n.reduce((t,a)=>a<t?a:t):null,max:n=>n.length?n.reduce((t,a)=>a>t?a:t):null,count:n=>n.length,countDistinct:n=>new Set(n).size,median:n=>{if(!n.length)return null;const t=[...n].map(Number).sort((e,f)=>e-f),a=Math.floor(t.length/2);return t.length%2?t[a]:(t[a-1]+t[a])/2}});function T(n,t){let e=(Array.isArray(t[n.sourceId])?t[n.sourceId]:[]).map(d=>({...d}));for(const d of n.joins){const E=Array.isArray(t[d.relatedSourceId])?t[d.relatedSourceId]:[];if(d.type==="one-to-many"){const M=d.join.as;e=e.map(W=>({...W,[M]:E.filter(oe=>oe[d.join.foreignKey]===W[d.join.localKey])}))}else{const M=new Map(E.map(W=>[W[d.join.foreignKey],W]));e=e.map(W=>{const oe=M.get(W[d.join.localKey]),q={...W};if(oe)for(const Q of Object.keys(oe))q[`${d.relatedSourceId}.${Q}`]=oe[Q];return q})}}if(!n.groupBy.length&&!n.aggregates.length)return{rows:e.map(d=>Object.fromEntries(n.fields.map(E=>[E,d[E]])))};const f=new Map;for(const d of e){const E=n.groupBy.map(W=>d[W]),M=JSON.stringify(E);f.has(M)||f.set(M,{keys:E,rows:[]}),f.get(M).rows.push(d)}return{groups:[...f.values()].map(d=>({keys:d.keys,values:Object.fromEntries(n.aggregates.map(E=>[E.id,(_[E.fn]||_.sum)(d.rows.map(M=>M[E.col]))]))}))}}function p(n){const t=new Map,a=new Map,e=[];let f=new Map,d=new Map,E=0;const M=K=>{const g=n.getState(),k=Array.isArray(g.pages)?g.pages.find(V=>z(V)&&V.id===K):null;return k&&Array.isArray(k.filters)?k.filters:[]},W=K=>({relationships:n.context.relationships,filters:M(K)}),oe=K=>{const g=n.context.sources;return z(g)?g[K]:void 0},q=()=>{const K=n.context.sources,g={};if(z(K))for(const k of Object.keys(K)){const V=K[k];z(V)&&V.kind==="rows"&&Array.isArray(V.rows)&&(g[k]=V.rows)}return g},Q=K=>{const g=oe(K.sourceId);!z(g)||g.kind!=="rows"||(E+=1,e.push({widgetId:K.widgetId,seq:E}),a.set(K.widgetId,T(K,q())))},H=K=>{const g=j(K,W(K.page));g&&(t.set(K.id,g),Q(g))},O=()=>{const K=new Map;for(const R of B(n.getState()))m(R)&&K.set(R.id,R);const g=new Set([...K.values()].map(R=>R.page)),k=new Set,V=new Map;for(const R of g){const N=M(R);V.set(R,N),fe(d.get(R)||[],N)||k.add(R)}d=V;for(const[R,N]of K){const $=f.get(R);(!$||!fe($,N)||k.has(N.page))&&H(N)}for(const R of f.keys())K.has(R)||(t.delete(R),a.delete(R));f=K},I=n.on("state",O);return O(),{routes(){return[...t.values()]},route(K){return t.get(K)||null},result(K){return a.get(K)||null},requests(){return e.slice()},explain(){const K={};for(const[g,k]of t)K[g]=k;return K},refresh(){f=new Map,d=new Map,O()},destroy(){I(),t.clear(),a.clear(),f=new Map,d=new Map}}}const v=p}),rt("packages/modules/designer/filters.js",function(s,ae){"use strict";Object.defineProperty(s,"FILTER_TYPES",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(s,"DEFAULT_OPERATOR",{enumerable:!0,get:function(){return J}}),Object.defineProperty(s,"DATE_PRESETS",{enumerable:!0,get:function(){return X}}),Object.defineProperty(s,"datePresetRange",{enumerable:!0,get:function(){return y}}),Object.defineProperty(s,"filterPredicate",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"rootSourceOf",{enumerable:!0,get:function(){return h}}),Object.defineProperty(s,"compileClickFilterLinks",{enumerable:!0,get:function(){return c}}),Object.defineProperty(s,"filterChipText",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"installFilters",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return A}});const F=ae("packages/modules/dashboard/spec.js").isPlain,ue=ae("packages/modules/designer/messages.js").resolveMessages,fe=ae("packages/modules/designer/palette.js").FILTER_TYPES,J=Object.freeze({list:"in",range:"between",dateRange:"between",search:"contains"}),X=Object.freeze(["last7","last30","last90","thisMonth","thisQuarter","thisYear","custom"]),ne="designer.filters.add",B="designer.filters.remove",L="designer.filters.setValue",D="designer.filters.clearAll",o="designer.filters.setClickFilter",w=r=>`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`;function y(r,j=new Date){const C=new Date(j.getFullYear(),j.getMonth(),j.getDate());if(r==="last7"||r==="last30"||r==="last90"){const G={last7:7,last30:30,last90:90}[r],_=new Date(C);return _.setDate(_.getDate()-(G-1)),{from:w(_),to:w(C)}}if(r==="thisMonth")return{from:w(new Date(C.getFullYear(),C.getMonth(),1)),to:w(C)};if(r==="thisQuarter"){const G=Math.floor(C.getMonth()/3);return{from:w(new Date(C.getFullYear(),G*3,1)),to:w(C)}}return r==="thisYear"?{from:w(new Date(C.getFullYear(),0,1)),to:w(C)}:null}function i(r){if(!F(r)||typeof r.field!="string"||r.field==="")return null;const j=r.field;if(r.type==="list"){const C=Array.isArray(r.value)?r.value.filter(_=>_!==""&&_!=null).map(String):[];if(!C.length)return null;const G=new Set(C);return{fn:_=>G.has(String(_[j])),condition:{col:j,op:"in",value:C}}}if(r.type==="range"){const C=Array.isArray(r.value)?r.value:[],G=C[0]===""||C[0]==null?null:Number(C[0]),_=C[1]===""||C[1]==null?null:Number(C[1]),T=Number.isFinite(G)?G:null,p=Number.isFinite(_)?_:null;if(T===null&&p===null)return null;const v=n=>{const t=Number(n[j]);return!(Number.isNaN(t)||T!==null&&t<T||p!==null&&t>p)};return T!==null&&p!==null?{fn:v,condition:{col:j,op:"between",value:[T,p]}}:{fn:v,condition:T!==null?{col:j,op:"gte",value:T}:{col:j,op:"lte",value:p}}}if(r.type==="dateRange"){const C=F(r.value)?r.value:{},G=typeof C.from=="string"&&C.from!==""?C.from:null,_=typeof C.to=="string"&&C.to!==""?C.to:null;if(!G&&!_)return null;const T=p=>{const v=p[j];if(v==null)return!1;const n=String(v).slice(0,10);return!(G&&n<G||_&&n>_)};return G&&_?{fn:T,condition:{col:j,op:"between",value:[G,_]}}:{fn:T,condition:G?{col:j,op:"gte",value:G}:{col:j,op:"lte",value:_}}}if(r.type==="search"){const C=typeof r.value=="string"?r.value.trim():"";if(!C)return null;const G=C.toLowerCase();return{fn:_=>String(_[j]??"").toLowerCase().includes(G),condition:{col:j,op:"contains",value:C}}}return null}function h(r,j,C=new Set){if(C.has(j))return null;C.add(j);const G=r.find(_=>F(_)&&_.id===j);return!G||typeof G.source!="string"||G.source===""?null:G.source.startsWith("grid:")?h(r,G.source.slice(5),C):G.source}function c(r,j){const C=[],G=F(j)?j:{};for(const _ of r){if(!F(_))continue;const T=F(G[_.id])?G[_.id]:null,p=T&&F(T.clickFilter)?T.clickFilter:null;if(!p||typeof p.on!="string"||p.on==="")continue;const v=p.targets==="all"?r.filter(n=>F(n)&&n.id!==_.id).map(n=>n.id):Array.isArray(p.targets)?p.targets.filter(n=>n!==_.id&&r.some(t=>F(t)&&t.id===n)):[];for(const n of v)C.push({from:_.id,to:n,on:p.on})}return C}function m(r,j){if(!F(r))return"";const C=r.field;if(r.type==="list"){const G=Array.isArray(r.value)?r.value.filter(_=>_!==""&&_!=null):[];return G.length?`${C} = ${G.join(", ")}`:""}if(r.type==="range"){const G=Array.isArray(r.value)?r.value:[];return(G[0]===""||G[0]==null)&&(G[1]===""||G[1]==null)?"":`${C} ${G[0]??""}–${G[1]??""}`}if(r.type==="dateRange"){const G=F(r.value)?r.value:{};if(!G.from&&!G.to)return"";const _=typeof G.preset=="string"&&G.preset!=="custom"?j(`designer.filter.preset.${G.preset}`):`${G.from||""}–${G.to||""}`;return`${C}: ${_}`}return r.type==="search"&&typeof r.value=="string"&&r.value.trim()?`${C} ${j("designer.filter.contains")} "${r.value.trim()}"`:""}const b=r=>Array.isArray(r.filters)?r.filters.filter(F):[],P=r=>r&&Array.isArray(r.filters)?r.filters.filter(F):[];function u(r,j={}){const C=ue(j&&j.messages),G=r.rails.filterBar,_=G.ownerDocument;let T=!1;const p=()=>{const Q=r.getState();return Q.pages.find(H=>F(H)&&H.id===Q.selectedPageId)||null},v=()=>{const Q=r.getState(),H=p();return[...b(Q).map(O=>({...O,scope:"global"})),...P(H).map(O=>({...O,scope:"page"}))]},n=()=>{const Q=r.dashboard;if(!Q)return;const H=p();if(!H||!F(H.spec)||!Array.isArray(H.spec.panels))return;const O=H.spec.panels.filter(F),I=v(),K=new Set(I.map(g=>`designer:filter:${g.id}`));for(const g of O){const k=Q.panel(g.id);if(!k||!k.grid)continue;const V=h(O,g.id),R=k.grid.filters.where()||[];for(const N of R)N.startsWith("designer:filter:")&&!K.has(N)&&k.grid.filters.where(N,null);for(const N of I){if(N.source!==V)continue;const $=`designer:filter:${N.id}`,S=i(N);if(!S){k.grid.filters.where($,null);continue}k.grid.filters.where($,S.fn,{condition:S.condition,deps:[N.field]})}}},t=(Q,H,O)=>{if(H==="global"){const g=O(b(Q));return(g.length||Array.isArray(Q.filters))&&(Q.filters=g),!0}const I=Q.pages.find(g=>F(g)&&g.id===Q.selectedPageId);if(!I)return!1;const K=O(P(I));return(K.length||Array.isArray(I.filters))&&(I.filters=K),!0};r.commands.register(ne,(Q,H)=>{const O=F(H)?H:{};if(!fe.includes(O.type)||typeof O.source!="string"||O.source===""||typeof O.field!="string"||O.field==="")return null;const I=O.scope==="global"?"global":"page",K=Q.getState(),g=K.pages.find($=>F($)&&$.id===K.selectedPageId),k=new Set([...b(K),...P(g)].map($=>$.id));let V=k.size+1;for(;k.has(`filter-${V}`);)V+=1;const R=`filter-${V}`;return!t(K,I,$=>[...$,{id:R,type:O.type,source:O.source,field:O.field,operator:J[O.type]}])||!Q.commit(K,"addFilter")?null:R}),r.commands.register(B,(Q,H)=>{const O=Q.getState();let I=!1;const K=g=>{const k=g.filter(V=>V.id!==H);return k.length!==g.length&&(I=!0),k};return t(O,"global",K),t(O,"page",K),I?Q.commit(O,"removeFilter"):!1}),r.commands.register(L,(Q,H,O,I)=>{const K=Q.getState();let g=!1;const k=R=>R.map(N=>N.id!==H?N:(g=!0,{...N,value:O}));if(t(K,"global",k),t(K,"page",k),!g)return!1;const V=F(I)?I:{};return Q.commit(K,"setFilterValue",V.coalesce!==void 0?{coalesce:V.coalesce}:void 0)}),r.commands.register(D,Q=>{const H=Q.getState();let O=!1;const I=K=>K.map(g=>{if(g.value===void 0)return g;O=!0;const{value:k,...V}=g;return V});return t(H,"global",I),t(H,"page",I),O?Q.commit(H,"clearFilters"):!1}),r.commands.register(o,(Q,H,O)=>{const I=Q.getState(),K=I.pages.find(V=>F(V)&&V.id===I.selectedPageId);if(!K||!F(K.spec)||!Array.isArray(K.spec.panels))return!1;const g=K.spec.panels.filter(F);if(!g.some(V=>V.id===H))return!1;F(I.panels)||(I.panels={});const k={...F(I.panels[H])?I.panels[H]:{}};return O==null?delete k.clickFilter:k.clickFilter={targets:O.targets==="all"?"all":Array.isArray(O.targets)?[...O.targets]:[],on:O.on},Object.keys(k).length?I.panels[H]=k:delete I.panels[H],K.spec.links=c(g,I.panels),Q.commit(I,"setClickFilter")}),G.className="lattice-designer-filterbar",G.setAttribute("role","region"),G.setAttribute("aria-label",C("designer.filterbar"));const a=(Q,H)=>{const O=_.createElement("label");O.className="lattice-designer-filter-field";const I=_.createElement("span");return I.className="lattice-designer-filter-field-label",I.textContent=Q,O.appendChild(I),O.appendChild(H),O},e=(Q,H,O,I)=>{const K=_.createElement("select");K.setAttribute("aria-label",Q);for(const g of O){const k=_.createElement("option");k.value=g.value,k.textContent=g.label,K.appendChild(k)}return K.value=H,K.addEventListener("change",()=>I(K.value)),K},f=Q=>{const H=`filter-value-${Q.id}`;if(Q.type==="list"){const I=_.createElement("input");return I.type="text",I.setAttribute("aria-label",C("designer.filter.value",{field:Q.field})),I.placeholder=C("designer.filter.list.placeholder"),I.value=Array.isArray(Q.value)?Q.value.join(", "):"",I.addEventListener("change",()=>{const K=I.value.split(",").map(g=>g.trim()).filter(Boolean);r.commands.run(L,Q.id,K.length?K:void 0)}),I}if(Q.type==="range"){const I=_.createElement("span");I.className="lattice-designer-filter-range";const K=Array.isArray(Q.value)?Q.value:["",""],g=(R,N)=>{const $=R===""&&N===""?void 0:[R,N];r.commands.run(L,Q.id,$,{coalesce:H})},k=_.createElement("input");k.type="number",k.setAttribute("aria-label",C("designer.filter.min",{field:Q.field})),k.value=K[0]??"";const V=_.createElement("input");return V.type="number",V.setAttribute("aria-label",C("designer.filter.max",{field:Q.field})),V.value=K[1]??"",k.addEventListener("change",()=>g(k.value,V.value)),V.addEventListener("change",()=>g(k.value,V.value)),I.appendChild(k),I.appendChild(V),I}if(Q.type==="dateRange"){const I=_.createElement("span");I.className="lattice-designer-filter-daterange";const K=F(Q.value)?Q.value:{},g=typeof K.preset=="string"&&X.includes(K.preset)?K.preset:"custom",k=X.map(S=>({value:S,label:C(`designer.filter.preset.${S}`)})),V=_.createElement("input");V.type="date",V.setAttribute("aria-label",C("designer.filter.from",{field:Q.field})),V.value=K.from||"";const R=_.createElement("input");R.type="date",R.setAttribute("aria-label",C("designer.filter.to",{field:Q.field})),R.value=K.to||"";const N=()=>{const S=V.value||R.value?{preset:"custom",from:V.value||void 0,to:R.value||void 0}:void 0;r.commands.run(L,Q.id,S)};V.addEventListener("change",N),R.addEventListener("change",N);const $=e(C("designer.filter.preset",{field:Q.field}),g,k,S=>{if(S==="custom"){N();return}const Y=y(S);r.commands.run(L,Q.id,{preset:S,from:Y.from,to:Y.to})});return V.disabled=g!=="custom",R.disabled=g!=="custom",I.appendChild($),I.appendChild(V),I.appendChild(R),I}const O=_.createElement("input");return O.type="search",O.setAttribute("aria-label",C("designer.filter.value",{field:Q.field})),O.value=typeof Q.value=="string"?Q.value:"",O.addEventListener("input",()=>{r.commands.run(L,Q.id,O.value.trim()===""?void 0:O.value,{coalesce:H})}),O},d=(Q,H)=>{const O=_.createElement("span");if(O.className="lattice-designer-filter",O.setAttribute("data-filter",Q.id),O.setAttribute("data-scope",Q.scope),O.appendChild(a(Q.field,f(Q))),H){const I=_.createElement("button");I.type="button",I.className="lattice-designer-filter-remove",I.setAttribute("aria-label",C("designer.filter.remove",{field:Q.field})),I.textContent="×",I.addEventListener("click",()=>r.commands.run(B,Q.id)),O.appendChild(I)}return O},E=()=>{const Q=p(),H=r.dataPanel&&typeof r.dataPanel.sources=="function"?r.dataPanel.sources():[],O=_.createElement("span");if(O.className="lattice-designer-filter-add",!H.length||!Q)return O;let I="page",K=fe[0],g=H[0].id;const k=Z=>(H.find(x=>x.id===Z)||{fields:[]}).fields;let V=k(g)[0]&&k(g)[0].id;const R=e(C("designer.filter.scope"),I,[{value:"page",label:C("designer.filter.scope.page")},{value:"global",label:C("designer.filter.scope.global")}],Z=>{I=Z}),N=e(C("designer.filter.type"),K,fe.map(Z=>({value:Z,label:C(`designer.palette.filter.${Z}`)})),Z=>{K=Z}),$=e(C("designer.filter.source"),g,H.map(Z=>({value:Z.id,label:Z.id})),Z=>{g=Z,V=k(g)[0]&&k(g)[0].id,S.textContent="";for(const x of k(g)){const ee=_.createElement("option");ee.value=x.id,ee.textContent=x.label||x.id,S.appendChild(ee)}V&&(S.value=V)}),S=e(C("designer.filter.field"),V||"",k(g).map(Z=>({value:Z.id,label:Z.label||Z.id})),Z=>{V=Z}),Y=_.createElement("button");return Y.type="button",Y.textContent=C("designer.filter.add"),Y.setAttribute("aria-label",C("designer.filter.add")),Y.addEventListener("click",()=>{V&&r.commands.run(ne,{scope:I,type:K,source:g,field:V})}),O.appendChild(R),O.appendChild(N),O.appendChild($),O.appendChild(S),O.appendChild(Y),O},M=()=>{if(T)return;G.textContent="";const Q=v();if(!Q.length&&r.mode!=="edit")return;const H=r.mode==="edit",O=_.createElement("span");O.className="lattice-designer-filterbar-controls";for(const K of Q)O.appendChild(d(K,H));G.appendChild(O);const I=Q.map(K=>m(K,C)).filter(Boolean);if(I.length||H){const K=_.createElement("span");K.className="lattice-designer-filterbar-context",K.setAttribute("role","status"),K.setAttribute("aria-label",C("designer.filterbar.context"));for(const g of I){const k=_.createElement("span");k.className="lattice-designer-filterbar-chip",k.textContent=g,K.appendChild(k)}if(I.length){const g=_.createElement("button");g.type="button",g.className="lattice-designer-filterbar-clear",g.textContent=C("designer.filterbar.clearAll"),g.setAttribute("aria-label",C("designer.filterbar.clearAll")),g.addEventListener("click",()=>r.commands.run(D)),K.appendChild(g)}G.appendChild(K)}H&&G.appendChild(E())},W=()=>{M(),n()},oe=r.on("state",W),q=r.on("mode",W);return W(),{get el(){return G},active(){return v()},addFilter(Q){return r.commands.run(ne,Q)},removeFilter(Q){return r.commands.run(B,Q)},setValue(Q,H){return r.commands.run(L,Q,H)},clearAll(){return r.commands.run(D)},setClickFilter(Q,H){return r.commands.run(o,Q,H)},refresh:W,destroy(){T||(T=!0,oe(),q(),G.textContent="")}}}const A=u}),rt("packages/modules/designer/pushdown.js",function(s,ae){"use strict";Object.defineProperty(s,"DEFAULT_DEBOUNCE_MS",{enumerable:!0,get:function(){return o}}),Object.defineProperty(s,"PUSHDOWN_STEPS",{enumerable:!0,get:function(){return y}}),Object.defineProperty(s,"mapEngineType",{enumerable:!0,get:function(){return i}}),Object.defineProperty(s,"normaliseSchema",{enumerable:!0,get:function(){return c}}),Object.defineProperty(s,"describeSource",{enumerable:!0,get:function(){return m}}),Object.defineProperty(s,"aggregationRefusal",{enumerable:!0,get:function(){return u}}),Object.defineProperty(s,"stepRefusal",{enumerable:!0,get:function(){return A}}),Object.defineProperty(s,"refusalsOf",{enumerable:!0,get:function(){return r}}),Object.defineProperty(s,"provenanceFor",{enumerable:!0,get:function(){return j}}),Object.defineProperty(s,"installPushdown",{enumerable:!0,get:function(){return G}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return _}});const F=ae("packages/core/src/internal/util.js").isFunction,ue=ae("packages/modules/dashboard/spec.js").isPlain,fe=ae("packages/core/src/source/pushdown.js").capabilitiesOf,J=ae("packages/core/src/source/aggregates.js"),X=J.STAT_PUSHDOWN,ne=J.routeAggregate,B=J.resolveAggregatesConfig,D=ae("packages/core/src/source/abort.js").SupersededError,o=150,w=new Set(["profile","distribution","correlation","groupComparison","modelError","forecast"]),y=Object.freeze(["filter","sort","group","pivot","total"]);function i(T){let p=String(T??"").trim();for(let a=0;a<4;a++){const e=/^(Nullable|LowCardinality|SimpleAggregateFunction)\((.*)\)$/i.exec(p);if(!e)break;p=e[2].trim()}const v=p.toLowerCase();if(!v)return"text";const n={currency:"currency",percent:"percent",ratio:"percent",percentrate:"percent",datestring:"date",usd:"currency",eur:"currency",gbp:"currency",jpy:"currency"}[v];if(n)return n;if(/\[\]$/.test(v)||/^(array|list)\b/.test(v))return"list";if(/^(struct|map|nested|object|json)/.test(v))return"text";const t=v.replace(/^edm\./,"").replace(/\(.*$/,"").replace(/\s.*$/,"");return/^(bool|boolean)$/.test(t)?"boolean":/^(datetime|timestamp|timestamptz|datetimeoffset|date_nanos|_time|instant)/.test(t)||/^timestamp/.test(v)?"datetime":/^(date|dateonly)$/.test(t)?"date":/^(geometry|geography|geo_point|geo_shape|point|wkb_blob)/.test(t)?"geometry":/^(decimal|numeric|money|currency)$/.test(t)||/^(u?int\d*|u?tinyint|u?smallint|u?bigint|u?hugeint|integer|long|short|byte|sbyte|float\d*|double|real|half_float|scaled_float|number|single)$/.test(t)?"number":"text"}function h(T){const p=String(T).replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim();return p?p.charAt(0).toUpperCase()+p.slice(1):String(T)}function c(T){let p=[];if(T instanceof Map)p=[...T.entries()].map(([v,n])=>[String(v),n]);else if(Array.isArray(T)){for(const v of T)if(typeof v=="string")p.push([v,void 0]);else if(ue(v)){const n=v.name??v.field??v.id??v.column_name??v.column;n!=null&&p.push([String(n),v.type??v.column_type??v.dataType??v.datatype])}}else ue(T)&&(p=Object.entries(T).map(([v,n])=>[v,ue(n)?n.type??n.column_type:n]));return p.map(([v,n])=>{const t=n==null?void 0:String(n);return{id:v,label:h(v),type:i(t),...t?{engineType:t}:{},declared:!1}})}async function m(T){const p=ue(T)||T&&typeof T=="object"?T.adapter:null;if(p&&F(p.describe)){const v=await p.describe(),n=c(v);if(n.length)return n}if(p){const v=p.schema??p.columns;if(v&&!F(v)){const n=c(v);if(n.length)return n}}return c(Array.isArray(T&&T.columns)?T.columns:[])}function b(T){const p=T&&T.adapter;return p&&typeof p.name=="string"&&p.name?p.name:"pushdown"}function P(T){const p=T.aggregates;return p?p instanceof Set?p:new Set(Array.isArray(p)?p:[p]):new Set}function u(T,p){const v=T&&T.adapter,n=b(T);if(!v||!(F(v.executeAggregates)||F(v.executeGroupedAggregates)))return`the ${n} adapter has no aggregate query, so "${p}" would be computed over the loaded window`;const t=X[p];if(t&&!t.pushable)return`the engine cannot express "${p}" (${t.note||"no SQL equivalent"}), so it would be computed over the loaded window`;const a=fe(v.capabilities),e=P(a);return e.size&&!e.has(p)?`the ${n} adapter does not compute "${p}"`:ne(p,B(T.aggregates))==="client"?`the source is configured to compute "${p}" in the client, over the loaded window`:""}function A(T,p){const v=T&&T.adapter,n=b(T),t=fe(v&&v.capabilities),a=P(t).size>0&&v&&F(v.executeGroupedAggregates);return p==="filter"?t.filter?"":`the ${n} adapter does not declare the \`filter\` capability`:p==="sort"?t.sort?"":`the ${n} adapter does not declare the \`sort\` capability`:p==="group"?t.group||a?"":`the ${n} adapter does not declare the \`group\` capability`:p==="pivot"?t.pivot?"":`the ${n} adapter does not declare the \`pivot\` capability`:p==="total"?t.group||a||v&&F(v.executeAggregates)?"":`the ${n} adapter can neither group nor aggregate, so a total would be the loaded window's`:""}function r(T,p=Object.keys(X)){const v=[];for(const n of y){const t=A(T,n);t&&v.push({kind:"step",name:n,reason:t})}for(const n of p){const t=u(T,n);t&&v.push({kind:"aggregation",name:n,reason:t})}return v}function j(T,p){if(!T)return null;const v=T.viewer,n=T.grid,t=n&&F(n.config)?n.config():null,a=t&&t.source&&typeof t.source=="object"?t.source:null;if(!a||!F(a.aggregate))return null;if(T.kind==="chart"&&p==="profile"){const d=T.el&&T.el.textContent?T.el.textContent:"";return/computed in the data engine/.test(d)?{computed:"engine",reason:null,measures:[]}:/computing in the data engine/.test(d)?{computed:"pending",reason:null,measures:[]}:/returned no answer/.test(d)?{computed:"client",reason:"the data engine returned no answer for the profile",measures:[]}:/column profile/.test(d)?{computed:"client",reason:"the profile was computed over the loaded window",measures:[]}:{computed:"pending",reason:null,measures:[]}}if(T.kind==="chart"&&v&&F(v.provenance)){const d=v.provenance();return d.pending?{computed:"pending",reason:null,measures:d.measures||[]}:{computed:d.source==="engine"?"engine":"client",reason:d.reason||null,measures:d.measures||[]}}if(T.kind==="kpi"&&v&&F(v.tiles)){const d=v.tiles();if(!d.length)return{computed:"pending",reason:null,measures:[]};const E=d.find(M=>M.computed!=="engine");return{computed:E?"client":"engine",reason:E?`the "${E.label}" tile was computed client-side`:null,measures:d.map(M=>({col:M.field??null,fn:M.agg??M.fn??"",computed:M.computed==="engine"?"engine":"client"}))}}const e=F(a.lastPlan)?a.lastPlan():null;if(!e)return{computed:"pending",reason:null,measures:[]};const f=Array.isArray(e.unpushed)?e.unpushed:[];return{computed:f.length?"client":"engine",reason:f.length?`not pushed: ${f.join(", ")}`:null,measures:[]}}function C(T,p){const v={...T};for(const n of["executeAggregates","executeGroupedAggregates"])F(T[n])&&(v[n]=(...t)=>p(()=>T[n](...t)));return v}function G(T,p={},v=n=>n){const n=ue(T.context&&T.context.sources)?T.context.sources:{},t=Number(p&&p.pushdownDebounceMs);let a=Number.isFinite(t)&&t>=0?t:o,e=!1;const f=new Map,d=new Set,E=new Map;let M=[],W=null,oe=null;const q={queries:0,superseded:0},Q=()=>{for(const re of[...d])re()},H=re=>!!(re.signal&&re.signal.aborted),O=re=>{q.superseded+=1,re.reject(new D("designer:aggregate"))},I=()=>{W=null;const re=M;M=[];for(const le of re){if(H(le)){O(le);continue}q.queries+=1,Promise.resolve().then(le.run).then(pe=>{H(le)?O(le):le.resolve(pe)},le.reject)}},K=()=>{W&&clearTimeout(W),W=setTimeout(I,a)},g=(re,le)=>new Promise((pe,we)=>{if(e){Promise.resolve().then(re).then(pe,we);return}M.push({signal:le,run:re,resolve:pe,reject:we}),K()}),k=ue(p&&p.factories)?p.factories:null,V=globalThis.LatticeGrid||{},R=k&&(F(k.createPushdownSource)?k.createPushdownSource:V.createPushdownSource);let N=null;if(k&&F(R)){const re=Object.prototype.hasOwnProperty.call(k,"createPushdownSource"),le=k.createPushdownSource;k.createPushdownSource=(...pe)=>{const we=R(...pe);if(we&&F(we.aggregate)){const je=we.aggregate.bind(we);try{we.aggregate=(Be,Ue,qe)=>g(()=>je(Be,Ue,qe),Be&&Be.signal)}catch{}}return we},N=()=>{re?k.createPushdownSource=le:delete k.createPushdownSource}}else for(const re of Object.keys(n)){const le=n[re];ue(le)&&le.kind==="pushdown"&&le.adapter&&typeof le.adapter=="object"&&(E.set(re,le),n[re]={...le,adapter:C(le.adapter,g)})}const $=re=>{let le=f.get(re);if(le)return le;const pe=n[re];return le={fields:null,error:null,promise:null},f.set(re,le),le.promise=m(pe).then(we=>{le.fields=we},we=>{le.fields=[],le.error=we&&we.message?we.message:String(we)}).then(()=>{if(e)return;const we=n[re];le.fields.length&&ue(we)&&!Array.isArray(we.columns)&&(n[re]={...we,columns:le.fields.map(je=>({field:je.id,type:je.type}))},Z(re)&&x()),Q()}),le},S=re=>{const le=n[re];return ue(le)&&le.kind==="pushdown"?le:null},Y=re=>{let le=typeof re=="string"?re:null;const pe=T.getState(),we=pe.pages.find(Be=>ue(Be)&&Be.id===pe.selectedPageId),je=we&&ue(we.spec)&&Array.isArray(we.spec.panels)?we.spec.panels:[];for(let Be=0;le&&Be<12;Be++){if(!le.startsWith("grid:"))return le;const Ue=je.find(ot=>ue(ot)&&ot.id===le.slice(5)),qe=ue(pe.panels)?pe.panels[le.slice(5)]:null;if(qe&&ue(qe.derived))le=`grid:${qe.derived.from}`;else if(Ue)le=typeof Ue.source=="string"?Ue.source:null;else return le.slice(5)}return null},Z=re=>se().some(le=>Y(le.source)===re),x=()=>{T.setGuardrails(T.guardrails.value)};for(const re of Object.keys(n))S(re)&&$(re);const ee=(re,le)=>{const pe=b(le);return re.computed==="engine"?v("designer.pushdown.engine",{adapter:pe}):re.computed==="pending"?v("designer.pushdown.pending",{adapter:pe}):v("designer.pushdown.client",{reason:re.reason||v("designer.pushdown.noReason")})},se=()=>{const re=T.getState(),le=re.pages.find(pe=>ue(pe)&&pe.id===re.selectedPageId);return le&&ue(le.spec)&&Array.isArray(le.spec.panels)?le.spec.panels.filter(ue):[]},de=re=>{const le=T.dashboard,pe=le&&F(le.panel)?le.panel(re):null,we=se().find(qe=>qe.id===re),je=we?Y(we.source):null,Be=je?S(je):null;if(!Be)return null;const Ue=j(pe,we&&we.options?we.options.type:void 0);return Ue?{...Ue,source:je,text:ee(Ue,Be)}:null},ye=new WeakSet,xe=()=>{const re=T.dashboard;if(!(!re||!F(re.panel)))for(const le of se()){if(le.kind!=="chart"||!le.options||!w.has(le.options.type))continue;const pe=Y(le.source);if(!pe||!S(pe))continue;const we=re.panel(le.id),je=we&&we.grid;if(!je||ye.has(je)||!F(je.rendererHost))continue;const Be=je.rendererHost();Be&&F(Be.hint)&&(ye.add(je),Be.hint(0,1))}},me=()=>{if(e||!T.canvas||!Object.keys(n).some(pe=>S(pe)))return!0;xe();let re=!0;const le=[...T.canvas.querySelectorAll(".lat-layout__window")];for(const pe of le){const we=pe.getAttribute("data-window-id"),je=we?de(we):null,Be=pe.querySelector(".lattice-designer-info");if(!je){Be&&Be.remove();continue}je.computed==="pending"&&(re=!1);const Ue=Be||T.canvas.ownerDocument.createElement("span");Be||(Ue.className="lattice-designer-info",Ue.setAttribute("role","img"),Object.assign(Ue.style,{display:"inline-flex",marginLeft:"6px",fontSize:"0.85em",cursor:"help",color:"var(--lattice-foreground-muted, inherit)"}),Ue.textContent="ⓘ",(pe.querySelector(".lat-layout__chrome")||pe).appendChild(Ue)),Ue.setAttribute("title",je.text),Ue.setAttribute("aria-label",je.text),Ue.setAttribute("data-computed",je.computed)}return re},Ne=(re=40)=>{oe&&clearTimeout(oe),oe=setTimeout(()=>{if(oe=null,e)return;!me()&&re>0&&Ne(re-1)},Math.max(60,a/2))},Ae=T.on("state",()=>{M.length&&K(),Ne()}),te=T.on("mode",()=>Ne());return Ne(),{fields(re){return S(re)?$(re).fields:null},describe(re){if(!S(re))return Promise.resolve([]);const le=$(re);return le.promise.then(()=>le.fields||[])},isPushdown(re){return!!S(Y(re))},refusals(re,le){const pe=S(Y(re));return pe?r(pe,le):[]},refusal(re,le){const pe=S(Y(re));return!pe||!ue(le)?"":typeof le.aggregation=="string"?u(pe,le.aggregation):typeof le.step=="string"?A(pe,le.step):""},provenance:de,refreshInfo(){me()},stats(){return{...q,held:M.length}},onChange(re){return d.add(re),()=>d.delete(re)},get debounceMs(){return a},set debounceMs(re){const le=Number(re);Number.isFinite(le)&&le>=0&&(a=le)},destroy(){if(e)return;e=!0,Ae(),te(),W&&clearTimeout(W),oe&&clearTimeout(oe);const re=M;M=[];for(const le of re)Promise.resolve().then(le.run).then(le.resolve,le.reject);for(const[le,pe]of E)n[le]=pe;N&&N(),d.clear()}}}const _=G}),rt("packages/modules/designer/index.js",function(s,ae){"use strict";Object.defineProperty(s,"createDesigner",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return xe}});const ve=ae("packages/core/src/internal/util.js"),F=ve.warnOnce,l=ve.isFunction,z=ae("packages/modules/shared/emitter.js").Emitter,J=ae("packages/modules/dashboard/index.js").createDashboard,X=ae("packages/modules/dashboard/spec.js"),ne=X.inspectSpec,B=X.isPlain,L=X.sameSpec,o=ae("packages/modules/designer/messages.js").resolveMessages,y=ae("packages/modules/designer/toolbar.js").installChrome,i=ae("packages/modules/designer/migrate.js"),h=i.migrateState,c=i.SCHEMA_VERSION,m=ae("packages/modules/designer/undo.js"),b=m.createHistory,P=m.installUndo,A=ae("packages/modules/designer/guardrails.js").createGuardrails,r=ae("packages/modules/designer/data-panel.js"),j=r.mountDataPanel,C=r.stripDeclaredFields,G=ae("packages/modules/designer/canvas.js"),_=G.wireCanvas,T=G.removeWidgetState,p=G.addWidgetState,n=ae("packages/modules/designer/properties.js").installProperties,a=ae("packages/modules/designer/calculated.js").installCalculated,e=ae("packages/modules/designer/derived.js"),f=e.installDerived,d=e.withDerivedFormats,E=e.hiddenDerivedIds,W=ae("packages/modules/designer/assist.js").mountAssist,q=ae("packages/modules/designer/statistics-widgets.js").installStatisticsWidgets,H=ae("packages/modules/designer/pages.js").installPages,I=ae("packages/modules/designer/rails.js").createRails,g=ae("packages/modules/designer/palette.js").installPalette,V=ae("packages/modules/designer/config-router.js").installConfigRouting,N=ae("packages/modules/designer/data-routes.js").installDataRouting,S=ae("packages/modules/designer/filters.js").installFilters,Z=ae("packages/modules/designer/pushdown.js").installPushdown,x=Object.freeze(["edit","view"]);function ee(me){if(Array.isArray(me))return me.map(ee);if(!B(me))return me;const Ne={};for(const Ae of Object.keys(me))Ne[Ae]=ee(me[Ae]);return Ne}function se(me,Ne){const Ae=B(me)?ee(me):{};Ae.schemaVersion===void 0&&(Ae.schemaVersion=c),Array.isArray(Ae.pages)||(Ae.pages=[{id:"page-1",title:Ne("designer.page",{n:1}),spec:{panels:[]}}]),B(Ae.panels)||(Ae.panels={});const te=Ae.pages.filter(B).map(re=>re.id);return te.includes(Ae.selectedPageId)||(Ae.selectedPageId=te.length?te[0]:null),Ae}function de(me){F(`designer:property:${me}`,`designer.getProperty/setProperty: there is no property ${JSON.stringify(me)}; nothing was read or changed. The properties are mode, state, selectedPageId, guardrails.`)}function ye(me,Ne={}){const Ae=B(Ne)?Ne:{},te=o(Ae.messages),re=new z("designer"),le=B(Ae.sources)?Ae.sources:{},pe=B(Ae.factories)?Ae.factories:{},we=Object.freeze({sources:le,relationships:Ae.relationships,guardrails:Ae.guardrails,llm:Ae.llm});let je=x.includes(Ae.mode)?Ae.mode:"view";Ae.mode!==void 0&&!x.includes(Ae.mode)&&F("designer:mode",`createDesigner: mode ${JSON.stringify(Ae.mode)} is not 'edit' or 'view'; the designer opened in view mode.`);let Be=A(Ae.guardrails);const Ue=Ae.keepPagesAlive===!0,qe=Me=>F("designer:state:newer",`designer: the state's schemaVersion ${Me} is newer than this designer's ${c}; the state was refused, nothing was loaded.`),ot=Me=>{const Ze=h(Me,te);return Ze.ok?Ze.state:(qe(Ze.from),null)};let tt;if(Ae.state===void 0)tt=se(void 0,te);else{const Me=ot(Ae.state);tt=se(Me===null?void 0:Me,te)}let he=null,ie=null;const ce=new Map;let Oe=null,be=!1,ge=null,ke=()=>{};const Ee=b({historyDepth:Ae.historyDepth});let Re=null;const ze=me.ownerDocument,Ge=ze.createElement("div");Ge.className="lattice-designer lattice",Object.assign(Ge.style,{width:"100%",height:"100%"});const Ke=ze.createElement("div");Ke.className="lattice-designer-chrome",Ke.setAttribute("role","group"),Ke.setAttribute("aria-label",te("designer.chrome"));const Ie=ze.createElement("div");Ie.className="lattice-designer-canvas",Ie.setAttribute("role","region"),Ie.setAttribute("aria-label",te("designer.canvas")),Object.assign(Ie.style,{minWidth:"0",minHeight:"0",position:"relative"});const $e=ze.createElement("div");$e.className="lattice-designer-status",$e.setAttribute("role","status"),$e.setAttribute("aria-live","polite"),Object.assign($e.style,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"}),Ge.appendChild(Ke),Ge.appendChild(Ie),Ge.appendChild($e),me.appendChild(Ge);const Pe=I({root:Ge,chrome:Ke,t:te,getPanels:()=>tt.panels,setCollapsed:(Me,Ze)=>{const it=ee(tt);it.panels[Me]={...B(it.panels[Me])?it.panels[Me]:{},collapsed:Ze},Me==="left"&&(it.panels.palette={...B(it.panels.palette)?it.panels.palette:{},collapsed:Ze}),St(it,"panels",{record:!1,render:!1})},announce:(Me,Ze)=>ft.announce(te(`a11y.designer.rail.${Ze?"open":"closed"}`,{name:te(`designer.rail.${Me}`)}))}),He=()=>tt.pages.find(Me=>B(Me)&&Me.id===tt.selectedPageId)||null,Ye=Me=>{if(!B(Me)||!B(Me.spec))return B(Me)?Me.spec:void 0;const Ze=B(Me.spec.sources)?Me.spec.sources:{};return{...Me.spec,sources:C({...le,...Ze})}},We=Me=>{re.emit("state",{state:ee(tt),cause:Me})},nt=()=>{ie&&ie.dispose(),ie=null,he&&he.destroy(),he=null;for(const Me of ce.values())Me!==Oe&&(Me.canvasCtl&&Me.canvasCtl.dispose(),Me.dashboard&&Me.dashboard.destroy());ce.clear(),Oe=null,Ie.textContent=""},ut=()=>{const Me=new Map,Ze=He();if(!Ze||!B(Ze.spec)||!Array.isArray(Ze.spec.panels))return Me;for(const it of Ze.spec.panels)if(B(it)&&it.id!=null){const et=Be.restrictPanel(it);et&&Me.set(String(it.id),et)}return Me},ht=Me=>{const Ze="http://www.w3.org/2000/svg",it=Me.createElementNS(Ze,"svg");it.setAttribute("viewBox","0 0 24 24"),it.setAttribute("width","12"),it.setAttribute("height","12"),it.setAttribute("aria-hidden","true");const et=Me.createElementNS(Ze,"rect");et.setAttribute("x","4"),et.setAttribute("y","10"),et.setAttribute("width","16"),et.setAttribute("height","10"),et.setAttribute("rx","2"),et.setAttribute("fill","currentColor");const mt=Me.createElementNS(Ze,"path");return mt.setAttribute("d","M8 10V7a4 4 0 0 1 8 0v3"),mt.setAttribute("fill","none"),mt.setAttribute("stroke","currentColor"),mt.setAttribute("stroke-width","2"),it.appendChild(et),it.appendChild(mt),it},st=(Me,Ze,it=Ie)=>{const et=[...it.querySelectorAll(".lat-layout__window")].find(pt=>pt.getAttribute("data-window-id")===Me);if(!et)return;et.setAttribute("data-locked",Ze);const mt=ze.createElement("span");mt.className="lattice-designer-lock",mt.setAttribute("role","img"),mt.setAttribute("aria-label",te("designer.lock")),mt.setAttribute("title",te("designer.lock")),mt.setAttribute("data-guardrail",Ze),Object.assign(mt.style,{display:"inline-flex",alignItems:"center",marginLeft:"calc(var(--lattice-space, 4px) * 1.5)",color:"var(--lattice-foreground-muted, inherit)"}),mt.appendChild(ht(ze)),(et.querySelector(".lat-layout__chrome")||et).appendChild(mt)},dt=(Me,Ze,it,et)=>{if(he=J(Me,Ze,pe),et.size)for(const pt of Me.querySelectorAll(".lat-layout__window"))et.has(pt.getAttribute("data-window-id"))&&pt.remove();const mt=he.layout;if(je!=="edit"||!mt)return;for(const[pt,Mt]of it)st(pt,Mt,Me);let bt=null;ie=_({layout:mt,canvas:Me,page:()=>(bt=ee(tt),bt.pages.find(pt=>B(pt)&&pt.id===bt.selectedPageId)||null),emitState:pt=>{const Mt=bt;bt=null,Mt&&St(Mt,pt,{render:!1})},removeWidget:pt=>At.run("removeWidget",pt),emit:(pt,Mt)=>re.emit(pt,Mt),announce:pt=>ft.announce(pt),messages:Ae.messages})},vt=()=>{Ue?(Oe&&Oe.wrapper&&Oe.wrapper.parentNode===Ie&&Ie.removeChild(Oe.wrapper),Oe=null,ie=null,he=null):nt(),Ge.setAttribute("data-mode",je),je==="edit"?Ke.removeAttribute("hidden"):Ke.setAttribute("hidden","");const Me=He();if((Me&&B(Me.spec)&&Array.isArray(Me.spec.panels)?Me.spec.panels:[]).some(bt=>B(bt)&&bt.id===Re)||(Re=null),Pe.setSelection(je==="edit"&&Re!==null),!Me)return;const it=Ye(Me),et=je==="edit"?ut():new Map;if(et.size&&B(it)){const bt=B(it.layout)?it.layout:{},pt=(Array.isArray(bt.windows)?bt.windows:[]).map(Mt=>B(Mt)?{...Mt}:Mt);for(const Mt of et.keys()){const Zt=pt.find(tn=>B(tn)&&String(tn.id)===Mt);Zt?(Zt.movable=!1,Zt.resizable=!1):pt.push({id:Mt,movable:!1,resizable:!1})}it.layout={...bt,windows:pt}}if(B(it)&&Array.isArray(it.panels)){const bt=B(Me.spec.sources)?Me.spec.sources:{};it.panels=d(it.panels,tt,{...le,...bt})}const mt=E(tt);if(Ue){const bt=JSON.stringify([je,it,[...mt].sort()]),pt=ce.get(Me.id);if(pt&&pt.key===bt){Ie.appendChild(pt.wrapper),Oe=pt,he=pt.dashboard,ie=pt.canvasCtl;return}pt&&(pt.canvasCtl&&pt.canvasCtl.dispose(),pt.dashboard&&pt.dashboard.destroy(),ce.delete(Me.id));const Mt=ze.createElement("div");Mt.className="lattice-designer-page",Object.assign(Mt.style,{width:"100%",height:"100%",position:"relative"}),dt(Mt,it,et,mt),Ie.appendChild(Mt),Oe={wrapper:Mt,dashboard:he,canvasCtl:ie,key:bt},ce.set(Me.id,Oe);return}dt(Ie,it,et,mt)},St=(Me,Ze,it)=>{if(be)return!1;const et=ee(tt),mt=se(Me,te);if(L(mt,tt))return!1;const bt=He();tt=mt,Pe.sync();const pt=He();(bt?bt.id:null)!==(pt?pt.id:null)&&re.emit("page",{id:pt?pt.id:null,page:pt?{id:pt.id,title:pt.title}:null,previousId:bt?bt.id:null,type:"page"});const Mt=!L(et.panels,mt.panels);return!(it&&it.render===!1)&&(Mt||!bt||!pt||bt.id!==pt.id||!L(bt.spec,pt.spec))&&vt(),it&&it.record===!1||Ee.record(et,ee(tt),Ze,it&&it.coalesce),ke(),We(Ze),!0},$t=new Map,At=Object.freeze({register(Me,Ze){return typeof Me!="string"||!l(Ze)?(F("designer:command","designer.commands.register: a command is a string name and a function; nothing was registered."),()=>{}):($t.set(Me,Ze),()=>{$t.get(Me)===Ze&&$t.delete(Me)})},run(Me,...Ze){const it=$t.get(Me);if(!it){F(`designer:command:${Me}`,`designer.commands.run: there is no command "${Me}"; nothing was run.`);return}return it({designer:gt,getState:()=>ee(tt),commit:St},...Ze)},has(Me){return $t.has(Me)},list(){return[...$t.keys()]}});At.register("selectPage",(Me,Ze)=>tt.pages.some(it=>B(it)&&it.id===Ze)?(Ze===tt.selectedPageId||Me.commit({...Me.getState(),selectedPageId:Ze},"selectPage"),!0):(F(`designer:page:${Ze}`,`designer.selectPage: there is no page ${JSON.stringify(Ze)}; the selection was kept.`),!1)),At.register("setMode",(Me,Ze)=>x.includes(Ze)?(Ze===je||be||(je=Ze,vt(),ft.announce(te(`a11y.designer.${je}`)),re.emit("mode",{mode:je})),je):(F("designer:set-mode",`designer.setMode: ${JSON.stringify(Ze)} is not 'edit' or 'view'; the mode was kept.`),je));const ft=y({root:Ge,chrome:Ke,topbar:Pe.topbar,canvas:Ie,live:$e,t:te,theme:Ae.theme,commands:At,emitter:re,sources:le,designer:()=>gt}),Pt=()=>{const Me=Ee.undo();return Me===null?!1:St(Me,"undo",{record:!1})},_t=()=>{const Me=Ee.redo();return Me===null?!1:St(Me,"redo",{record:!1})},Lt=()=>Ee.canUndo(),Gt=()=>Ee.canRedo();At.register("removeWidget",(Me,Ze)=>{const it=T(Me.getState(),Ze);return it?Me.commit(it,"removeWidget"):!1}),At.register("addWidget",(Me,Ze,it)=>{const et=p(Me.getState(),Ze,it);return et?Me.commit(et,"addWidget"):!1});const gt={get el(){return me},get mode(){return je},get chrome(){return Ke},get rails(){return Pe.rails},get canvas(){return Ie},get dashboard(){return he},get commands(){return At},get shortcuts(){return ft.shortcuts},get regions(){return ft.regions},audit(){return ft.audit()},get theme(){return ft.theme.get()},setTheme(Me){return ft.theme.set(Me)},announce(Me){ft.announce(Me)},get context(){return we},get guardrails(){return Be},getState(){return ee(tt)},setState(Me,Ze){if(!B(Me))return F("designer:state",`designer.setState: the state is not an object (${Array.isArray(Me)?"array":typeof Me}); the state was kept.`),!1;const it=ot(Me);if(it===null)return!1;const et=!!(Ze&&Ze.keepHistory);return et||(Ee.clear(),ke()),St(it,"setState",{record:et})},migrate(Me,Ze={}){const it=h(Me,te);return it.ok?(Ze.dryRun||St(it.state,"migrate"),it):(Ze.dryRun||qe(it.from),it)},setGuardrails(Me){return Me!==void 0&&!B(Me)?(F("designer:guardrails",`designer.setGuardrails: the guardrails are not an object (${Array.isArray(Me)?"array":typeof Me}); the guardrails were kept.`),!1):(Be=A(Me),vt(),gt.palette&>.palette.refresh(),!0)},setMode(Me){return At.run("setMode",Me)},pages(){return tt.pages.map(Me=>B(Me)?{id:Me.id,title:Me.title}:{id:void 0,title:void 0})},selectPage(Me){return At.run("selectPage",Me)},addPage(Me){return At.run("addPage",Me)},renamePage(Me,Ze){return At.run("renamePage",Me,Ze)},movePage(Me,Ze){return At.run("movePage",Me,Ze)},removePage(Me){return At.run("removePage",Me)},undo:Pt,redo:_t,canUndo:Lt,canRedo:Gt,selectWidget(Me){return ie?ie.selectWidget(Me,"api"):null},selectedWidget(){return ie?ie.selectedWidget():null},removeWidget(Me){return At.run("removeWidget",Me)},addWidget(Me,Ze){return At.run("addWidget",Me,Ze)},getProperty(Me){if(Me==="mode")return je;if(Me==="state")return ee(tt);if(Me==="selectedPageId")return tt.selectedPageId;if(Me==="guardrails")return ee(Be.value);de(Me)},setProperty(Me,Ze){return Me==="mode"?gt.setMode(Ze)===Ze:Me==="state"?(gt.setState(Ze),B(Ze)):Me==="selectedPageId"?gt.selectPage(Ze):Me==="guardrails"?gt.setGuardrails(Ze):(de(Me),!1)},problems(){const Me=[];return tt.pages.forEach((Ze,it)=>{if(!B(Ze)){Me.push({page:void 0,path:`pages[${it}]`,message:"is not an object"});return}for(const et of ne(Ye(Ze)).problems)Me.push({page:Ze.id,path:et.path,message:et.message})}),Me},on(Me,Ze){return re.on(Me,Ze)},onStateUpdated(Me){return re.on("state",Me)},destroy(){be||(be=!0,ge&&ge(),ge=null,gt.palette.destroy(),gt.dataPanel.destroy(),nt(),ft.destroy(),Pe.destroy(),re.clear(),$t.clear(),Ge.remove())}};ft.start();const Vt=P({chrome:Ke,topbar:Pe.topbar,root:Ge,doc:ze,t:te,undo:Pt,redo:_t,canUndo:Lt,canRedo:Gt});return ke=Vt.refresh,ge=Vt.off,gt.pushdown=Z(gt,Ae,te),vt(),gt.dataPanel=j(gt,{doc:ze,t:te}),gt.palette=g(gt,Ae),gt.properties=n(gt,Ae),gt.calculated=a(gt,Ae),gt.configRouter=V(gt,{commit:St,getState:()=>ee(tt),selectedPageId:()=>tt.selectedPageId,dashboard:()=>he,guardrails:()=>Be,on:(Me,Ze)=>re.on(Me,Ze)}),gt.derived=f(gt,Ae),gt.dataRoutes=N(gt),gt.assist=W(gt,{doc:ze,t:te,factories:pe}),gt.statisticsWidgets=q(gt,Ae),H(At,te),gt.filters=S(gt,Ae),re.on("select",Me=>{const Ze=Me&&Me.id!=null?Me.id:null;Re=Ze,Pe.setSelection(Ze!==null&&je==="edit"),Ze!==null&>.properties.selectPanel(Ze)}),gt}const xe=ye});const On=$n("packages/modules/designer/index.js"),Ln=On.createDesigner;var Dn=On.default;export{Ln as createDesigner,Dn as default};
|
|
689
|
+
`}function J(Q){const ie=Q.documentElement;if(!ie||ie.getAttribute(de))return;ie.setAttribute(de,"1");const W=Q.createElement("style");W.textContent=fe(),(Q.head||Q.body||ie).appendChild(W)}}),rt("packages/modules/charts/scale.js",function(o,ce){"use strict";Object.defineProperty(o,"isNumber",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"toNumber",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"toTime",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"extent",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"niceStep",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"niceDomain",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"measureDomain",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"linearTicks",{enumerable:!0,get:function(){return k}}),Object.defineProperty(o,"timeStepFor",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"MONTH_STEPS",{enumerable:!0,get:function(){return u}}),Object.defineProperty(o,"timeTicks",{enumerable:!0,get:function(){return d}}),Object.defineProperty(o,"linearScale",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"timeScale",{enumerable:!0,get:function(){return G}}),Object.defineProperty(o,"key",{enumerable:!0,get:function(){return N}}),Object.defineProperty(o,"bandScale",{enumerable:!0,get:function(){return T}}),Object.defineProperty(o,"sqrtScale",{enumerable:!0,get:function(){return C}});const ke=[1,2,2.5,5,10],F=6e4,l=36e5,de=864e5,z=365.25*de,fe=[1,2,5,10,20,25,50,100],J=[1,5,10,25,50,100,250,500,1e3,5e3,15e3,3e4,F,5*F,15*F,30*F,l,3*l,6*l,12*l,de,2*de,7*de,14*de,30*de,90*de,180*de,...fe.map(h=>h*z)];function Q(h){return typeof h=="number"&&Number.isFinite(h)}function ie(h){if(h==null||h==="")return null;if(h instanceof Date){const a=h.getTime();return Number.isFinite(a)?a:null}if(typeof h=="boolean")return h?1:0;const $=Number(h);return Number.isFinite($)?$:null}function W(h){if(h==null||h==="")return null;if(h instanceof Date){const a=h.getTime();return Number.isFinite(a)?a:null}if(typeof h=="number")return Number.isFinite(h)?h:null;const $=Date.parse(String(h));return Number.isFinite($)?$:null}function L(h){let $=1/0,a=-1/0;for(let n=0;n<h.length;n++){const t=h[n];Q(t)&&(t<$&&($=t),t>a&&(a=t))}return $===1/0?null:{min:$,max:a}}function _(h){if(!(h>0))return 1;const $=10**Math.floor(Math.log10(h));for(const a of ke)if(h<=a*$)return a*$;return 10*$}function i(h,$=5){const a=_((h.max-h.min)/Math.max(1,$));return{min:Math.floor(h.min/a)*a,max:Math.ceil(h.max/a)*a,step:a}}function v(h,$={}){const a=L(h)||{min:0,max:1};let{min:n,max:t}=a;if($.zero&&(n>0&&(n=0),t<0&&(t=0)),n===t){const e=Math.abs(n)>0?Math.abs(n)/10:1;n-=e,t+=e}if($.nice!==!1){const e=i({min:n,max:t},$.ticks||5);n=e.min,t=e.max}return Q($.min)&&(n=$.min),Q($.max)&&(t=$.max),n===t&&(t=n+1),{min:n,max:t}}function k(h,$=5){const a=_((h.max-h.min)/Math.max(1,$)),n=Math.ceil(h.min/a),t=Math.floor(h.max/a),e=[];for(let s=n;s<=t;s++){const x=s*a;e.push(Math.abs(x)<a/1e6?0:Number(x.toPrecision(12)))}return e}function r(h,$=5){const a=Math.max(1,$),n=h/a;let t=J[J.length-1];for(const x of J)if(x>=n){t=x;break}if(t<z)return t;let e=t,s=Math.abs(h/t-a);for(const x of J){if(x<z)continue;const S=Math.abs(h/x-a);S<s&&(s=S,e=x)}return e}const m=new Map;function c(h){let $=m.get(h);return $||($=new Intl.DateTimeFormat("en-US",{timeZone:h,year:"numeric",month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),m.set(h,$)),$}function b(h,$){const a={year:0,month:0,day:1,hour:0,minute:0,second:0};for(const n of c($).formatToParts(new Date(h)))switch(n.type){case"year":a.year=Number(n.value);break;case"month":a.month=Number(n.value)-1;break;case"day":a.day=Number(n.value);break;case"hour":a.hour=Number(n.value)%24;break;case"minute":a.minute=Number(n.value);break;case"second":a.second=Number(n.value);break;default:break}return a}function y(h,$,a){const n=Date.UTC(h,$,1);let t=n;for(let e=0;e<2;e++){const s=b(t,a),x=Date.UTC(s.year,s.month,s.day,s.hour,s.minute,s.second),S=n-x;if(S===0)break;t+=S}return t}function P(h,$,a){const n=a?b(h.min,a).year:new Date(h.min).getUTCFullYear();let t=Math.ceil(n/$)*$;const e=x=>a?y(x,0,a):Date.UTC(x,0,1);e(t)<h.min&&(t+=$);const s=[];for(;e(t)<=h.max;t+=$)s.push(e(t));return s}const u=new Map([[30*de,1],[90*de,3],[180*de,6]]);function E(h,$,a){const n=a?b(h.min,a):{year:new Date(h.min).getUTCFullYear(),month:new Date(h.min).getUTCMonth()};let t=n.year*12+n.month;const e=x=>{const S=Math.floor(x/12),B=x-S*12;return a?y(S,B,a):Date.UTC(S,B,1)};e(t)<h.min&&(t+=1),t=Math.ceil(t/$)*$;const s=[];for(;;t+=$){const x=e(t);if(x>h.max)break;s.push(x)}return s}function d(h,$=5,a){const n=r(h.max-h.min,$);if(n>=z)return P(h,Math.round(n/z),a);const t=u.get(n);if(t)return E(h,t,a);const e=[],s=Math.ceil(h.min/n)*n;for(let x=s;x<=h.max;x+=n)e.push(x);return e}function w(h,$){const a=h.max-h.min||1,[n,t]=$;return{kind:"linear",domain:h,range:$,of(e){return n+(e-h.min)/a*(t-n)},invert(e){return h.min+(e-n)/(t-n||1)*a},ticks(e=5){return k(h,e)}}}function G(h,$){return{...w(h,$),kind:"time",ticks(n=5,t){return d(h,n,t)}}}function N(h){if(h==null)return" null";if(h instanceof Date)return` date:${h.getTime()}`;if(typeof h=="object"){const $=h,a=$.id??$.key??$.value;return a!==void 0&&typeof a!="object"?` obj:${String(a)}`:` obj:${String(h)}`}return String(h)}function T(h,$,a=.2){const n=Math.min(.9,Math.max(0,a)),[t,e]=$,s=new Map;for(let B=0;B<h.length;B++){const Y=N(h[B]);s.has(Y)||s.set(Y,B)}const x=h.length?(e-t)/h.length:e-t,S=Math.max(0,x*(1-n));return{kind:"band",domain:h,range:$,bandwidth:S,step:x,of(B){const Y=s.get(N(B));return Y===void 0?NaN:t+Y*x+(x-S)/2},centre(B){const Y=this.of(B);return Number.isNaN(Y)?NaN:Y+S/2},ticks(){return h}}}function C(h,$){const[a,n]=$,t=Math.max(Math.abs(h.max),Math.abs(h.min),0)||1;return{kind:"sqrt",domain:h,range:$,of(e){const s=Math.sqrt(Math.abs(e)/t);return a+s*(n-a)}}}}),rt("packages/core/src/format/number.js",function(o,ce){"use strict";Object.defineProperty(o,"compileNumber",{enumerable:!0,get:function(){return l}});const F=ce("packages/core/src/internal/util.js").isNil;function l(de,z){const fe=de||{},J=fe.locale||z||void 0,Q=fe.style||"decimal",ie=typeof fe.scale=="number"?fe.scale:1,W=fe.nullDisplay??"",L=fe.zeroDisplay,_=fe.prefix||"",i=fe.suffix||"",v=fe.negative||"minus",k=fe.signed===!0,r={style:Q,notation:fe.notation||"standard"};Q==="currency"&&(r.currency=fe.currency||"USD",fe.currencyDisplay&&(r.currencyDisplay=fe.currencyDisplay)),typeof fe.decimals=="number"?(r.minimumFractionDigits=fe.decimals,r.maximumFractionDigits=fe.decimals):(typeof fe.minDecimals=="number"&&(r.minimumFractionDigits=fe.minDecimals),typeof fe.maxDecimals=="number"&&(r.maximumFractionDigits=fe.maxDecimals),r.minimumFractionDigits>(r.maximumFractionDigits??20)&&(r.maximumFractionDigits=r.minimumFractionDigits)),fe.thousandsSeparator===!1&&(r.useGrouping=!1),r.notation==="compact"&&(r.compactDisplay=fe.compactDisplay||"short");const m=new Intl.NumberFormat(J,r),c=typeof fe.thousandsSeparator=="string"?fe.thousandsSeparator:null,b=typeof fe.decimalSeparator=="string"?fe.decimalSeparator:null;let y=",",P=".";if(c||b)for(const N of m.formatToParts(12345.6))N.type==="group"?y=N.value:N.type==="decimal"&&(P=N.value);const u=N=>{let T=N;return c&&(T=T.split(y).join("")),b&&(T=T.split(P).join("")),c&&(T=T.split("").join(c)),b&&(T=T.split("").join(b)),T},E=!!(c||b),d=_!==""&&Q==="currency",w=N=>{let T;if(d){const C=m.formatToParts(N);let h=!1;T="";for(const $ of C)T+=$.value,!h&&$.type==="currency"&&(T+=_,h=!0);h||(T=_+T)}else T=_+m.format(N);return E&&(T=u(T)),T+i},G=N=>{if(F(N)||N==="")return W;const T=typeof N=="number"?N:Number(N);if(Number.isNaN(T))return W;const C=ie===1?T:T*ie;return C===0&&L!==void 0?L:C<0?v==="parentheses"?`(${w(-C)})`:v==="suffix"?`${w(-C)}-`:w(C):k&&C>0?`+${w(C)}`:w(C)};return G.negativeClass=fe.negativeClass||null,G.spec=fe,G}}),rt("packages/core/src/format/date.js",function(o,ce){"use strict";Object.defineProperty(o,"scanPattern",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"toDate",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"compilePattern",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"compileDate",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"toIsoDate",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"toIsoDateTime",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"compareIso",{enumerable:!0,get:function(){return m}});const ke=ce("packages/core/src/internal/util.js"),F=ke.isNil,l=ke.warnOnce,de=["yyyy","yy","MMMM","MMM","MM","M","dd","d","EEEE","EEE","HH","H","hh","h","mm","m","ss","s","SSS","a"];function z(c){const b=[];let y=0,P="";const u=()=>{P&&(b.push({token:null,text:P}),P="")};for(;y<c.length;){const E=c[y];if(E==="'"){if(c[y+1]==="'"){P+="'",y+=2;continue}const w=c.indexOf("'",y+1);if(w===-1){P+=c.slice(y+1),y=c.length;continue}P+=c.slice(y+1,w),y=w+1;continue}const d=de.find(w=>c.startsWith(w,y));if(d){u(),b.push({token:d,text:d}),y+=d.length;continue}/[A-Za-z]/.test(E)&&l(`date.pattern.token:${E}`,`the date pattern "${c}" contains '${E}', which is not a supported token, so it is rendered as text. Quote it as a literal to silence this. Supported: ${de.join(" ")}.`),P+=E,y+=1}return u(),b}const fe=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?)?$/;function J(c){if(F(c)||c==="")return null;if(c instanceof Date)return Number.isNaN(c.getTime())?null:c;if(typeof c=="number")return Number.isNaN(c)?null:new Date(c);if(typeof c=="string"){const b=fe.exec(c.trim());if(b){const[,P,u,E,d="0",w="0",G="0"]=b;return new Date(+P,+u-1,+E,+d,+w,+G)}const y=new Date(c);return Number.isNaN(y.getTime())?null:y}return null}function Q(c,b){return String(c).padStart(b,"0")}function ie(c){if(!c)return P=>({year:P.getFullYear(),month:P.getMonth()+1,day:P.getDate(),hour:P.getHours(),minute:P.getMinutes(),second:P.getSeconds(),ms:P.getMilliseconds(),weekday:P.getDay()});const b=new Intl.DateTimeFormat("en-US",{timeZone:c,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,weekday:"short"}),y={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return P=>{const u={year:0,month:1,day:1,hour:0,minute:0,second:0,ms:P.getMilliseconds(),weekday:0};for(const E of b.formatToParts(P))switch(E.type){case"year":u.year=Number(E.value);break;case"month":u.month=Number(E.value);break;case"day":u.day=Number(E.value);break;case"hour":u.hour=Number(E.value)%24;break;case"minute":u.minute=Number(E.value);break;case"second":u.second=Number(E.value);break;case"weekday":u.weekday=y[E.value]??0;break;default:break}return u}}function W(c,b,y){const P=z(c),u=ie(y),E=new Set(P.filter(T=>T.token).map(T=>T.token)),d=E.has("MMM")?new Intl.DateTimeFormat(b,{month:"short",timeZone:y}):null,w=E.has("MMMM")?new Intl.DateTimeFormat(b,{month:"long",timeZone:y}):null,G=E.has("EEE")?new Intl.DateTimeFormat(b,{weekday:"short",timeZone:y}):null,N=E.has("EEEE")?new Intl.DateTimeFormat(b,{weekday:"long",timeZone:y}):null;return T=>{const C=u(T);let h="";for(const $ of P){if(!$.token){h+=$.text;continue}switch($.token){case"yyyy":h+=Q(C.year,4);break;case"yy":h+=Q(C.year%100,2);break;case"MMMM":h+=w.format(T);break;case"MMM":h+=d.format(T);break;case"MM":h+=Q(C.month,2);break;case"M":h+=String(C.month);break;case"dd":h+=Q(C.day,2);break;case"d":h+=String(C.day);break;case"EEEE":h+=N.format(T);break;case"EEE":h+=G.format(T);break;case"HH":h+=Q(C.hour,2);break;case"H":h+=String(C.hour);break;case"hh":h+=Q(C.hour%12===0?12:C.hour%12,2);break;case"h":h+=String(C.hour%12===0?12:C.hour%12);break;case"mm":h+=Q(C.minute,2);break;case"m":h+=String(C.minute);break;case"ss":h+=Q(C.second,2);break;case"s":h+=String(C.second);break;case"SSS":h+=Q(C.ms,3);break;case"a":h+=C.hour<12?"AM":"PM";break;default:h+=$.text;break}}return h}}const L=[["year",365*24*36e5],["month",720*36e5],["week",168*36e5],["day",24*36e5],["hour",36e5],["minute",6e4],["second",1e3]];function _(c,b){const y=c||{},P=y.locale||b||void 0,u=y.nullDisplay??"",E=y.timeZone;let d;if(y.pattern)d=W(y.pattern,P,E);else if(y.dateStyle||y.timeStyle){const C={timeZone:E};y.dateStyle&&(C.dateStyle=y.dateStyle),y.timeStyle&&(C.timeStyle=y.timeStyle);const h=new Intl.DateTimeFormat(P,C);d=$=>h.format($)}else{const C=new Intl.DateTimeFormat(P,{dateStyle:"medium",timeZone:E});d=h=>C.format(h)}const w=y.relative?new Intl.RelativeTimeFormat(P,{numeric:"auto"}):null,N=(typeof y.relative=="object"&&y.relative?y.relative.threshold??7:7)*24*36e5,T=(C,h)=>{const $=J(C);if(!$)return u;if(w){const a=h&&typeof h.now=="number"?h.now:Date.now(),n=$.getTime()-a;if(Math.abs(n)<N){for(const[t,e]of L)if(Math.abs(n)>=e||t==="second")return w.format(Math.round(n/e),t)}}return d($)};return T.spec=y,T}function i(c){if(F(c)||c==="")return null;if(typeof c=="string"){const P=/^(\d{4}-\d{2}-\d{2})/.exec(c.trim());if(P)return P[1];const u=J(c);return u?i(u):null}const b=J(c);if(!b)return null;const y=P=>String(P).padStart(2,"0");return`${b.getFullYear()}-${y(b.getMonth()+1)}-${y(b.getDate())}`}function v(c,b){if(F(c)||c==="")return null;if(typeof c=="string"){const P=c.trim();if(k.test(P)){const d=J(P);return d?r(d,b):null}const u=/^(\d{4}-\d{2}-\d{2})[T ](\d{2}):(\d{2})(?::(\d{2}))?/.exec(P);if(u){const[,d,w,G,N]=u;return`${d}T${w}:${G}${N&&N!=="00"?`:${N}`:""}`}if(/^\d{4}-\d{2}-\d{2}$/.test(P))return`${P}T00:00`;const E=J(P);return E?v(E):null}const y=J(c);return y?r(y,b):null}const k=/(?:Z|[+-]\d{2}:?\d{2})$/i;function r(c,b){const y=d=>String(d).padStart(2,"0");if(b)try{const d=new Intl.DateTimeFormat("en-CA",{timeZone:b,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(c).reduce((N,T)=>(T.type!=="literal"&&(N[T.type]=T.value),N),{}),w=d.hour==="24"?"00":d.hour,G=Number(d.second);return`${d.year}-${d.month}-${d.day}T${w}:${d.minute}`+(G?`:${d.second}`:"")}catch{}const P=`${c.getFullYear()}-${y(c.getMonth()+1)}-${y(c.getDate())}`,u=c.getSeconds(),E=`${y(c.getHours())}:${y(c.getMinutes())}${u?`:${y(u)}`:""}`;return`${P}T${E}`}function m(c,b){const y=F(c)||c===""?null:String(c),P=F(b)||b===""?null:String(b);return y===null?P===null?0:1:P===null||y<P?-1:y>P?1:0}}),rt("packages/core/src/format/boolean.js",function(o,ce){"use strict";Object.defineProperty(o,"toTriState",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"compileBoolean",{enumerable:!0,get:function(){return fe}});const F=ce("packages/core/src/internal/util.js").isNil,l={true:"☑",false:"☐",null:""},de={true:"◉",false:"◯",null:""};function z(J){if(F(J)||J==="")return null;if(typeof J=="boolean")return J;if(typeof J=="number")return J!==0;const Q=String(J).trim().toLowerCase();return Q==="true"||Q==="yes"||Q==="y"||Q==="1"?!0:Q==="false"||Q==="no"||Q==="n"||Q==="0"?!1:null}function fe(J,Q){const ie=J||{},W=ie.display||"text",L=ie.trueLabel??"Yes",_=ie.falseLabel??"No",i=ie.nullLabel??"";let v=L,k=_;const r=i;W==="checkbox"?(v=l.true,k=l.false):W==="switch"?(v=de.true,k=de.false):W==="icon"&&(v=ie.trueIcon??L,k=ie.falseIcon??_);const m=c=>{const b=z(c);return b===null?r:b?v:k};return m.display=W,m.labels={true:L,false:_,null:i},m.locale=Q,m.spec=ie,m}}),rt("packages/core/src/format/text.js",function(o,ce){"use strict";Object.defineProperty(o,"compileText",{enumerable:!0,get:function(){return de}});const ke=ce("packages/core/src/internal/util.js"),F=ke.isNil,l=ke.titleCase;function de(z,fe){const J=z||{},Q=J.locale||fe||void 0,ie=J.nullDisplay??"",W=J.emptyDisplay??"",L=J.transform||"none",_=typeof J.truncate=="number"?{chars:J.truncate}:J.truncate||null,i=_?_.chars:0,v=_?_.ellipsis??"…":"",k=m=>{switch(L){case"upper":return Q?m.toLocaleUpperCase(Q):m.toUpperCase();case"lower":return Q?m.toLocaleLowerCase(Q):m.toLowerCase();case"title":return l(m);default:return m}},r=m=>{if(F(m))return ie;let c=typeof m=="string"?m:String(m);return c===""?W:(L!=="none"&&(c=k(c)),i>0&&c.length>i&&(c=c.slice(0,i)+v),c)};return r.spec=J,r}}),rt("packages/core/src/format/mask.js",function(o,ce){"use strict";Object.defineProperty(o,"splitSections",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"parseSection",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"compileMask",{enumerable:!0,get:function(){return fe}});const ke=new Set(["0","#","?",",","."]),F="\0";function l(Q){const ie=[];let W="",L=!1;for(let _=0;_<Q.length;_++){const i=Q[_];if(i==="\\"){W+=i+(Q[_+1]??""),_+=1;continue}if(i==='"'){L=!L,W+=i;continue}if(i===";"&&!L){ie.push(W),W="";continue}W+=i}return ie.push(W),ie}function de(Q){let ie="",W="",L="",_=1,i=!1,v=!1;const k=d=>{v?W+=d:ie+=d};for(let d=0;d<Q.length;d++){const w=Q[d];if(w==="\\"){k(Q[d+1]??""),d+=1;continue}if(w==='"'){const G=Q.indexOf('"',d+1);k(G===-1?Q.slice(d+1):Q.slice(d+1,G)),d=G===-1?Q.length:G;continue}if(w==="%"){_*=100,k("%");continue}if(w==="@"){i=!0,k("\0");continue}if(ke.has(w)){L+=w,v=!0;continue}k(w)}let r=-1;for(let d=L.length-1;d>=0;d--){const w=L[d];if(w==="0"||w==="#"||w==="?"){r=d;break}}let m=!1,c="";for(let d=0;d<L.length;d++){const w=L[d];if(w===","){d>r?_/=1e3:m=!0;continue}c+=w}const b=c.indexOf("."),y=b===-1?c:c.slice(0,b),P=b===-1?"":c.slice(b+1);let u=0;for(const d of y)d==="0"&&(u+=1);let E=0;for(const d of P)d==="0"&&(E+=1);return{prefix:ie,suffix:W,minInt:u,minDec:E,maxDec:P.length,grouping:m,scale:_,hasNumber:r!==-1,isText:i}}function z(Q,ie){const W=new Intl.NumberFormat(ie,{minimumIntegerDigits:Math.max(Q.minInt,1),minimumFractionDigits:Q.minDec,maximumFractionDigits:Math.max(Q.maxDec,Q.minDec),useGrouping:Q.grouping}),{prefix:L,suffix:_,scale:i,hasNumber:v}=Q;return k=>{if(!v)return L+_;const r=i===1?k:k*i;return L+W.format(r)+_}}function fe(Q,ie){const L=l(String(Q)).map(de),_=L.map(c=>z(c,ie)),i=0,v=L.length>1?1:-1,k=L.length>2?2:-1,r=L.length>3?3:-1,m=c=>{if(c==null||c==="")return"";if(typeof c!="number"||Number.isNaN(c)){const b=Number(c);if(Number.isNaN(b))return r===-1?String(c):(L[r].prefix+L[r].suffix).split("\0").join(String(c));c=b}return c===0&&k!==-1?_[k](0):c<0&&v!==-1?_[v](-c):_[i](c)};return m.spec={mask:Q},{format:m,ooxml:J(String(Q))}}function J(Q){return Q.trim()}}),rt("packages/core/src/format/shorthand.js",function(o,ce){"use strict";Object.defineProperty(o,"looksLikeMask",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"looksLikeDatePattern",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"parseShorthand",{enumerable:!0,get:function(){return J}});const ke=["currency","number","percent","date","boolean","text","relative"],F=/[#0?@;"\\]/,l=/(yyyy|yy|MMMM|MMM|MM|EEEE|EEE|dd|HH|hh|mm|ss|SSS)/;function de(Q){return typeof Q!="string"||Q===""||fe(Q)?!1:F.test(Q)}function z(Q){return typeof Q!="string"||Q===""||fe(Q)?!1:l.test(Q)}function fe(Q){const ie=Q.indexOf(":"),W=ie===-1?Q:Q.slice(0,ie);return ke.includes(W)?W:null}function J(Q){const ie=fe(Q);if(!ie)return null;const W=Q.indexOf(":"),L=W===-1?"":Q.slice(W+1),_=L===""?[]:L.split(":");switch(ie){case"currency":{const i={type:"number",style:"currency",currency:_[0]||"USD"};return _[1]!==void 0&&_[1]!==""&&(i.decimals=Number(_[1])),i}case"number":{const i={type:"number",style:"decimal"};return _[0]!==void 0&&_[0]!==""&&(i.decimals=Number(_[0])),i}case"percent":{const i={type:"number",style:"percent"};return _[0]!==void 0&&_[0]!==""&&(i.decimals=Number(_[0])),i}case"date":return{type:"date",pattern:L||void 0};case"relative":return{type:"date",relative:!0};case"boolean":{const i=L.split("/"),v={type:"boolean",display:"text"};return i[0]!==void 0&&i[0]!==""&&(v.trueLabel=i[0]),i[1]!==void 0&&i[1]!==""&&(v.falseLabel=i[1]),i[2]!==void 0&&(v.nullLabel=i[2]),v}case"text":{const i={type:"text"};return _[0]&&(i.transform=_[0]),_[1]!==void 0&&_[1]!==""&&(i.truncate=Number(_[1])),i}default:return null}}}),rt("packages/core/src/format/index.js",function(o,ce){"use strict";Object.defineProperty(o,"compileFormat",{enumerable:!0,get:function(){return T}}),Object.defineProperty(o,"specToOoxml",{enumerable:!0,get:function(){return h}});const ke=ce("packages/core/src/internal/util.js"),F=ke.isFunction,l=ke.isObject,de=ke.warnOnce,z=ce("packages/core/src/format/number.js"),fe=z.compileNumber,J=ce("packages/core/src/format/date.js"),Q=J.compileDate,ie=J.scanPattern,W=ce("packages/core/src/format/boolean.js"),L=W.compileBoolean,_=ce("packages/core/src/format/text.js"),i=_.compileText,v=ce("packages/core/src/format/mask.js"),k=v.compileMask,r=ce("packages/core/src/format/shorthand.js"),m=r.parseShorthand,c=r.looksLikeMask,b=r.looksLikeDatePattern;Object.defineProperty(o,"compileNumber",{enumerable:!0,get:function(){return z.compileNumber}}),Object.defineProperty(o,"compileDate",{enumerable:!0,get:function(){return J.compileDate}}),Object.defineProperty(o,"compilePattern",{enumerable:!0,get:function(){return J.compilePattern}}),Object.defineProperty(o,"scanPattern",{enumerable:!0,get:function(){return J.scanPattern}}),Object.defineProperty(o,"toDate",{enumerable:!0,get:function(){return J.toDate}}),Object.defineProperty(o,"compileBoolean",{enumerable:!0,get:function(){return W.compileBoolean}}),Object.defineProperty(o,"toTriState",{enumerable:!0,get:function(){return W.toTriState}}),Object.defineProperty(o,"compileText",{enumerable:!0,get:function(){return _.compileText}}),Object.defineProperty(o,"compileMask",{enumerable:!0,get:function(){return v.compileMask}}),Object.defineProperty(o,"splitSections",{enumerable:!0,get:function(){return v.splitSections}}),Object.defineProperty(o,"parseSection",{enumerable:!0,get:function(){return v.parseSection}}),Object.defineProperty(o,"parseShorthand",{enumerable:!0,get:function(){return r.parseShorthand}}),Object.defineProperty(o,"looksLikeMask",{enumerable:!0,get:function(){return r.looksLikeMask}}),Object.defineProperty(o,"looksLikeDatePattern",{enumerable:!0,get:function(){return r.looksLikeDatePattern}});const y=new Set(["decimal","currency","percent","unit"]),P=new Set(["type","locale"]),u={number:new Set(["style","currency","currencyDisplay","decimals","minDecimals","maxDecimals","thousandsSeparator","decimalSeparator","notation","compactDisplay","negative","negativeClass","signed","prefix","suffix","zeroDisplay","nullDisplay","messages","scale"]),date:new Set(["pattern","dateStyle","timeStyle","timeZone","relative","nullDisplay"]),boolean:new Set(["display","trueLabel","falseLabel","nullLabel","trueIcon","falseIcon"]),text:new Set(["transform","truncate","nullDisplay","emptyDisplay"])},E=new Set(["number","date","boolean","text"]);function d(t,e){const s=t.type;if(s===void 0||E.has(s)||!y.has(String(s)))return;const x=e?`"${e}"`:"with no id";de(`format:unknown-style-key:${e||""}:${s}`,`column ${x} has format: { type: "${s}" }, which is not a valid format type ("number", "date", "boolean" or "text") and is ignored; did you mean style: "${s}" instead?`)}function w(t,e,s){const x=u[e],S=s?`"${s}"`:"with no id";for(const B of t){if(P.has(B)||x.has(B))continue;const Y=Object.keys(u).find(te=>te!==e&&u[te].has(B));Y?de(`format:inapplicable:${s||""}:${B}`,`column ${S} has format key "${B}", which applies to a ${Y} column, not the ${e} column it was applied to; it is ignored.`):de(`format:unknown:${s||""}:${B}`,`column ${S} has an unrecognised format key "${B}" for its ${e} format; it is ignored.`)}}function G(t){if(t.type==="number"||t.type==="date"||t.type==="boolean"||t.type==="text")return!0;const e=y.has(String(t.style));return!!(t.pattern||t.dateStyle||t.timeStyle||t.relative||t.timeZone||t.trueLabel||t.falseLabel||t.display||t.trueIcon||t.falseIcon||t.transform||t.truncate||t.emptyDisplay||e||t.currency||t.decimals!==void 0||t.minDecimals!==void 0||t.maxDecimals!==void 0||t.notation||t.negative||t.scale!==void 0||t.prefix||t.suffix||t.zeroDisplay!==void 0)}function N(t,e){if(t.type==="number"||t.type==="date"||t.type==="boolean"||t.type==="text")return t.type;if(t.pattern||t.dateStyle||t.timeStyle||t.relative||t.timeZone)return"date";if(t.trueLabel||t.falseLabel||t.display||t.trueIcon||t.falseIcon)return"boolean";if(t.transform||t.truncate||t.emptyDisplay)return"text";if(t.style||t.currency||t.decimals!==void 0||t.minDecimals!==void 0||t.maxDecimals!==void 0||t.notation||t.negative||t.scale!==void 0||t.prefix||t.suffix||t.zeroDisplay!==void 0)return"number";const s=e&&e.base;return s==="number"?"number":s==="date"||s==="dateString"?"date":s==="boolean"?"boolean":"text"}function T(t,e=null,s=void 0,x=void 0,S=void 0){if(t==null||t==="")return null;const B=l(t)?Object.keys(t):null;if(typeof t=="function"){const q=(ne,U)=>String(t({...U||{},value:ne,locale:s})??"");return q.ooxml=e&&e.excel||"General",q}if(typeof t=="string"){if(c(t)){const{format:ne,ooxml:U}=k(t,s);return ne.ooxml=U,ne}const q=m(t)||(b(t)?{type:"date",pattern:t}:null);return q?T(q,e,s,x,S):(de(`format:${t}`,`unrecognised format string "${t}"; the value will be stringified`),null)}if(!l(t))return de("format:shape","format must be a spec object or a string; ignoring",t),null;if(e&&F(e.format)&&!G(t)||e&&F(e.format)&&Array.isArray(e.formatPatterns)&&t.type===void 0)return null;const Y=N(t,e);Y==="date"&&x&&t.timeZone===void 0&&(t={...t,timeZone:x}),d(t,S),w(B||Object.keys(t),Y,S);let te;switch(Y){case"number":te=fe(t,s);break;case"date":te=Q(t,s);break;case"boolean":te=L(t,s);break;default:te=i(t,s);break}return te.ooxml=h(t,Y,s,e),te.kind=Y,te}const C={yyyy:"yyyy",yy:"yy",MMMM:"mmmm",MMM:"mmm",MM:"mm",M:"m",dd:"dd",d:"d",EEEE:"dddd",EEE:"ddd",HH:"hh",H:"h",hh:"hh",h:"h",mm:"mm",m:"m",ss:"ss",s:"s",SSS:"000",a:"AM/PM"};function h(t,e,s=void 0,x=null){if(e==="date"){if(t.pattern){let q="";for(const ne of ie(t.pattern))q+=ne.token?C[ne.token]??ne.text:ne.text;return q}return x&&x.excel||"yyyy-mm-dd"}if(e==="boolean")return"General";if(e==="text")return"@";if(t.notation==="compact"||t.notation==="scientific")return"General";const S=typeof t.decimals=="number"?t.decimals:typeof t.minDecimals=="number"?t.minDecimals:t.style==="currency"?2:0;let Y=`${t.thousandsSeparator===!1?"":"#,#"}#0${S>0?`.${"0".repeat(S)}`:""}`,te="";return t.style==="currency"&&(te+=$(n(t.currency||"USD",s))),t.prefix&&(te+=$(t.prefix)),Y=te+Y,t.style==="percent"&&(Y=`${Y}%`),t.suffix&&(Y+=$(t.suffix)),t.negative==="parentheses"?`${Y};(${Y})`:t.negative==="suffix"?`${Y};${Y}-`:Y}function $(t){return`"${String(t).split('"').join("")}"`}const a=new Map;function n(t,e){const s=`${t}|${e||""}`;let x=a.get(s);if(x!==void 0)return x;x=t;try{const B=new Intl.NumberFormat(e,{style:"currency",currency:t}).formatToParts(0).find(Y=>Y.type==="currency");B&&(x=B.value)}catch{}return a.set(s,x),x}}),rt("packages/modules/charts/format.js",function(o,ce){"use strict";Object.defineProperty(o,"precisionFor",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"axisNumber",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"r2Digits",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"dateFormatFor",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"resolveTimeZone",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"formatters",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"measureText",{enumerable:!0,get:function(){return k}}),Object.defineProperty(o,"measureFormat",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"stringFormatter",{enumerable:!0,get:function(){return c}});const ke=ce("packages/modules/charts/scale.js"),F=ke.MONTH_STEPS,l=ke.timeStepFor,z=ce("packages/core/src/format/index.js").compileFormat,J=ce("packages/core/src/internal/util.js").warnOnce;function Q(b){if(!Number.isFinite(b)||b<=0)return 0;const y=Math.ceil(-Math.log10(b));return Math.min(6,Math.max(0,y))}function ie(b,y,P=0){return Number.isFinite(b)?Math.abs(b)>=1e4?y.number(b,{notation:"compact",maximumFractionDigits:1}):y.number(b,{minimumFractionDigits:P,maximumFractionDigits:P}):""}function W(b,y){const P=b&&b.messages;return!P||typeof P.number!="function"?Number(y).toFixed(2):P.number(y,{minimumFractionDigits:2,maximumFractionDigits:2})}function L(b){const P=b>0?l(b):0;return P>0&&P<1e3?{minute:"2-digit",second:"2-digit",fractionalSecondDigits:3}:P>0&&P<6e4?{hour:"2-digit",minute:"2-digit",second:"2-digit"}:b<=864e5?{hour:"2-digit",minute:"2-digit"}:b<=180*864e5?F.has(P)?{month:"short"}:P>0&&P<864e5?{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}:{day:"numeric",month:"short"}:b<=3*365*864e5?{month:"short",year:"numeric"}:{year:"numeric"}}let _;function i(b,y){const P=y&&y.format&&y.format.timeZone;if(P)return P;const u=b&&typeof b.get=="function"&&b.get("timeZone");return u||(_||(_=Intl.DateTimeFormat().resolvedOptions().timeZone),_)}function v(b,y,P){const u=b.messages,E=u.locale,d=i(b,P);if(y.kind==="time"){const G=L(y.span||0),N=new Intl.DateTimeFormat(E,{...G,timeZone:d}),T=new Intl.DateTimeFormat(E,{dateStyle:"medium",timeStyle:"short",timeZone:d});return{tick:C=>Number.isFinite(Number(C))?N.format(new Date(Number(C))):"",value:C=>Number.isFinite(Number(C))?T.format(new Date(Number(C))):""}}const w=Q(y.step||0);return{tick:G=>typeof G=="number"?ie(G,u,w):String(G??""),value:G=>typeof G=="number"?u.number(G):String(G??"")}}function k(b,y){if(b==null||!Number.isFinite(b))return"";const P=Math.abs(b)>=1e-6?Number(b.toPrecision(6)):b;return y.number(P)}function r(b,y,P){return b==null||!Number.isFinite(Number(b))?"":y&&y.format&&typeof y.formatValue=="function"?String(y.formatValue(b,null)):k(Number(b),P&&P.messages)}const m=new Map;function c(b,y,P){const u=y&&y.messages&&y.messages.locale,E=`${u}\0${b}`;if(!m.has(E)){let w=null;try{w=z(b,null,u)}catch{w=null}m.set(E,w)}const d=m.get(E);return d?w=>String(d(w)):(J(`chart.format.string:${P}:${b}`,`${P}: the format string "${b}" is not understood; values are drawn unformatted`),null)}}),rt("packages/modules/charts/axis.js",function(o,ce){"use strict";Object.defineProperty(o,"pinXDomain",{enumerable:!0,get:function(){return u}}),Object.defineProperty(o,"labelGap",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"TICK_FLOOR",{enumerable:!0,get:function(){return G}}),Object.defineProperty(o,"tickFloor",{enumerable:!0,get:function(){return N}}),Object.defineProperty(o,"fitBandLabels",{enumerable:!0,get:function(){return T}}),Object.defineProperty(o,"normaliseAxes",{enumerable:!0,get:function(){return a}}),Object.defineProperty(o,"tickValues",{enumerable:!0,get:function(){return n}}),Object.defineProperty(o,"tickLabeller",{enumerable:!0,get:function(){return t}}),Object.defineProperty(o,"drawAxisTitle",{enumerable:!0,get:function(){return e}}),Object.defineProperty(o,"labelEvery",{enumerable:!0,get:function(){return s}}),Object.defineProperty(o,"drawMeasureAxis",{enumerable:!0,get:function(){return x}}),Object.defineProperty(o,"heldInside",{enumerable:!0,get:function(){return S}}),Object.defineProperty(o,"drawCategoryAxis",{enumerable:!0,get:function(){return B}}),Object.defineProperty(o,"turnedFirstLabelBox",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(o,"leftLabelRoom",{enumerable:!0,get:function(){return te}}),Object.defineProperty(o,"setLabelText",{enumerable:!0,get:function(){return q}}),Object.defineProperty(o,"drawBandLabels",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(o,"drawContinuousAxis",{enumerable:!0,get:function(){return U}}),Object.defineProperty(o,"drawAxisLines",{enumerable:!0,get:function(){return M}}),Object.defineProperty(o,"createGroups",{enumerable:!0,get:function(){return H}}),Object.defineProperty(o,"MARK_OVERHANG",{enumerable:!0,get:function(){return f}}),Object.defineProperty(o,"overhangFor",{enumerable:!0,get:function(){return g}}),Object.defineProperty(o,"setPlotClip",{enumerable:!0,get:function(){return I}});const F=ce("packages/modules/charts/frame.js").Pool,l=ce("packages/modules/charts/svg.js"),de=l.attrs,z=l.round,fe=l.setText,J=l.svg,Q=ce("packages/modules/charts/typography.js"),ie=Q.applySize,W=Q.CHAR_RATIO,L=Q.truncateTo,i=ce("packages/modules/charts/styles.js").NS,v=ce("packages/modules/charts/scale.js"),k=v.toNumber,r=v.toTime,m=ce("packages/modules/charts/format.js"),c=m.resolveTimeZone,b=m.stringFormatter,P=ce("packages/core/src/internal/util.js").warnOnce;function u(j,A,D){const p=A&&A.kind==="time"?r:k,se=xe=>xe==null||xe===""?null:p(xe),V=se(D&&D.min),O=se(D&&D.max);if(V===null&&O===null)return j;if(V!==null&&O!==null)return V<O?{min:V,max:O}:(P("chart.axis.x.domain.inverted",`axis.x.min (${V}) is not below axis.x.max (${O}), which is a mirrored axis rather than a narrow one, so both were ignored and the x domain was taken from the data. On a time axis both are epoch milliseconds.`),j);const X=V!==null?V:j.min,oe=O!==null?O:j.max;if(X<oe)return{min:X,max:oe};const ue=Math.abs(j.max-j.min)||1;return P("chart.axis.x.domain.beyond",`axis.x.${V!==null?"min":"max"} is outside the x values entirely, so the plot is empty. The pin was kept and the other edge moved to hold the axis width; check the units (a time axis is pinned in epoch milliseconds).`),V!==null?{min:X,max:X+ue}:{min:oe-ue,max:oe}}const E=6,d=.53;function w(j){return Number.isFinite(j)&&j>0?Math.max(E,Math.ceil(j)+1):E}const G=9;function N(j){const A=j&&j.ownerDocument,D=A&&A.defaultView;if(!D||typeof D.getComputedStyle!="function")return G;const p=D.getComputedStyle(j).getPropertyValue("--lattice-chart-tick-min"),se=parseFloat(p);return Number.isFinite(se)&&se>0?se:G}function T(j){const{size:A,floor:D,slot:p,per:se}=j,V=Number.isFinite(j.every)&&j.every>0?Number(j.every):null;if(V!==null&&V!==1)return{size:A,every:V,thinned:!1};if(!(p>0)||!(se>0))return{size:A,every:1,thinned:!1};const O=Math.min(A,p/se);return O>=D?{size:O,every:1,thinned:!1}:{size:D,every:Math.max(1,Math.ceil(D*se/p)),thinned:!0}}function C(j,A){P("chart.axis.band.every.impossible",`axis.x.every/axis.y.every is set to ${A}, which on ${j} band(s) never shows a second label no matter how much room the axis is given. Lower it, or drop it to let the axis thin automatically.`)}function h(j,A){const D=Number.isFinite(A)&&A>0?Number(A):null;D!==null&&D>1&&j>1&&D>=j&&C(j,D)}const $=1.2;function a(j){if(j===!1){const p={labels:!1,grid:!1};return{x:{...p},y:{...p},y2:{...p}}}const A=j&&typeof j=="object"?j:{},D=p=>typeof p=="string"?{title:p}:p&&typeof p=="object"?{...p}:{};return{x:D(A.x),y:D(A.y),y2:D(A.y2||A.right)}}function n(j,A,D){const p=A&&A.ticks;if(Array.isArray(p)){const V=j.domain;return!V||V.min===void 0?p:p.filter(O=>Number(O)>=V.min&&Number(O)<=V.max)}const se=Number.isFinite(p)&&p>0?Number(p):5;return j.ticks(se,D)}function t(j,A,D,p){const se=j&&j.format;if(typeof se=="function")return V=>String(se(V));if(typeof se=="string"){const V=b(se,D,"axis.<x|y|y2>.format");if(V)return V}return p&&p.format&&p.format.pattern&&typeof p.formatValue=="function"?V=>String(p.formatValue(V,null)):A.tick}function e(j){if(!j.text)return;const A=j.side==="left"||j.side==="right"?j.plot.height:j.plot.width,D=Number.isFinite(A)?L(String(j.text),Math.max(0,A),j.size):String(j.text);if(!D||D==="…")return;const p=J(j.group.ownerDocument,"text",{class:`${i}__axis-title`});if(ie(p,j.size),j.side==="left"){const se=Math.max(j.size*1.15,j.plot.left-j.plot.gutter.left+j.size*1.15),V=j.plot.top+j.plot.height/2;de(p,{transform:`translate(${z(se)} ${z(V)}) rotate(-90)`,"text-anchor":"middle"})}else if(j.side==="right"){const se=j.plot.right+j.plot.gutter.right-j.size*1.15,V=j.plot.top+j.plot.height/2;de(p,{transform:`translate(${z(se)} ${z(V)}) rotate(90)`,"text-anchor":"middle"})}else de(p,{x:z(j.plot.left+j.plot.width/2),y:z(j.plot.bottom+j.plot.gutter.bottom-2),"text-anchor":"middle"});fe(p,D),D!==String(j.text)&&p.setAttribute("aria-label",String(j.text)),j.group.appendChild(p)}function s(j){const{values:A,scale:D,size:p,horizontal:se,label:V}=j;if(A.length<2)return 1;let O=1/0;for(let oe=1;oe<A.length;oe++){const ue=Math.abs(D.of(A[oe])-D.of(A[oe-1]));Number.isFinite(ue)&&ue<O&&(O=ue)}if(!Number.isFinite(O))return 1;if(O<=0)return A.length;let X=p*$+2;if(se){let oe=0;for(const ue of A){const xe=String(V(ue)||"").length*p*W;xe>oe&&(oe=xe)}X=oe+E}return Math.max(1,Math.ceil(X/O))}function x(j){const{gridGroup:A,axisGroup:D,plot:p,scale:se,format:V}=j,O=j.config||{},X=se.kind==="time"&&j.grid?c(j.grid,j.column):void 0,oe=n(se,O,X),ue=t(O,V,j.grid),xe=j.size||11,me=s({values:oe,scale:se,size:xe,horizontal:!!j.horizontal,label:ue}),we=w(j.overhang),Pe=O.grid===!1?null:A,Fe=Pe?new F(Pe):null,Z=new F(D);for(let re=0;re<oe.length;re++){const le=oe[re],pe=z(se.of(le)),he=le===0,Me=re%me!==0;if(j.horizontal){if(Fe&&de(Fe.next("line",`${i}__gridline`),{x1:pe,x2:pe,y1:z(p.top),y2:z(p.bottom),"stroke-opacity":he?1:.6,"stroke-width":he?1.5:1}),O.labels===!1||Me)continue;const Ie=ue(le),Ke=String(Ie).length*xe*W/2,qe=p.gutter;if(qe&&(pe-Ke<p.left-(qe.left||0)||pe+Ke>p.right+(qe.right||0)))continue;const ot=Z.next("text",`${i}__tick`);ie(ot,xe),de(ot,{x:pe,y:z(p.bottom+we),"text-anchor":"middle","dominant-baseline":"hanging"}),fe(ot,Ie)}else{if(Fe&&de(Fe.next("line",`${i}__gridline`),{x1:z(p.left),x2:z(p.right),y1:pe,y2:pe,"stroke-opacity":he?1:.6,"stroke-width":he?1.5:1}),O.labels===!1||Me)continue;const Ie=j.side==="right",Ke=ue(le),qe=S(pe,p,xe);if(j.dropBottom&&Math.abs(pe-p.bottom)<=1){if(j.dropBottom===!0)continue;const it=String(Ke).length*xe*W,ge=Ie?{left:p.right+we,right:p.right+we+it}:{left:p.left-we-it,right:p.left-we};ge.top=qe-xe*.85,ge.bottom=qe+xe*.6;const Le=j.dropBottom,He=3;if(ge.left<Le.right+He&&ge.right>Le.left-He&&ge.top<Le.bottom+He&&ge.bottom>Le.top-He)continue}const ot=Z.next("text",`${i}__tick`);ie(ot,xe),de(ot,{x:z(Ie?p.right+we:p.left-we),y:qe,"text-anchor":Ie?"start":"end","dominant-baseline":"middle"}),fe(ot,Ke)}}return Fe?Fe.finish():new F(A).finish(),Z.finish(),oe}function S(j,A,D){const p=A&&A.gutter;if(!p)return j;const se=A.top-(Number.isFinite(p.top)?p.top:0)+D*.85+1,V=A.bottom+(Number.isFinite(p.bottom)?p.bottom:0)-D*.6-1;return z(Math.min(Math.max(j,se),Math.max(se,V)))}function B(j){const{group:A,plot:D,scale:p,labels:se}=j,V=j.config||{};if(V.labels===!1){new F(A).finish();return}const O=new F(A),X=p.domain,oe=p.step,ue=V.rotate===void 0||V.rotate==="auto"?j.rotated:!!V.rotate,xe=ue?T({size:j.fontSize,floor:N(A),slot:oe,per:Math.SQRT2,every:V.every}):{size:j.fontSize,every:Number.isFinite(V.every)&&V.every>0?Number(V.every):1,thinned:!1},{size:me,every:we}=xe;h(X.length,V.every);const Pe=oe*we;for(let Fe=0;Fe<X.length;Fe++){const Z=z(p.centre(X[Fe]));if(Number.isNaN(Z)||Fe%we!==0)continue;const re=O.next("text",`${i}__tick`);ie(re,me);const le=se[Fe]===void 0?"":se[Fe];if(ue){de(re,{x:0,y:0,"text-anchor":"end","dominant-baseline":"middle",transform:`translate(${Z} ${z(D.bottom+E+2)}) rotate(-45)`});const pe=Pe*Math.SQRT2-me*1.5,he=Math.max(0,D.gutter.bottom-E)*Math.SQRT2;q(re,le,Math.max(0,Math.min(he,pe)),me)}else de(re,{x:Z,y:z(D.bottom+E),"text-anchor":"middle","dominant-baseline":"hanging",transform:null}),q(re,le,Pe,me)}O.finish()}function Y(j){const{group:A,plot:D,scale:p,labels:se,fontSize:V}=j,O=j.config||{};if(O.labels===!1)return null;const X=p.domain;if(!X||!X.length||!D.gutter)return null;const oe=p.step,ue=T({size:V,floor:N(A),slot:oe,per:Math.SQRT2,every:O.every}),{size:xe,every:me}=ue,we=z(p.centre(X[0]));if(Number.isNaN(we))return null;const Fe=oe*me*Math.SQRT2-xe*1.5,Z=Math.max(0,D.gutter.bottom-E)*Math.SQRT2,re=Math.max(0,Math.min(Z,Fe)),le=String(se[0]===void 0?"":se[0]),he=L(le,re,xe).length*xe*d,Me=xe*.6,Ie=z(D.bottom+E),Ke=Math.SQRT1_2;return{left:we-Ke*(he+Me),right:we+Ke*Me,top:Ie-Ke*Me,bottom:Ie+Ke*(he+Me)}}function te(j){return Math.max(0,(j.gutter?j.gutter.left:j.left)-E)}function q(j,A,D,p){const se=String(A??""),V=L(se,D,p);return fe(j,V),V!==se?j.setAttribute("aria-label",se):j.removeAttribute("aria-label"),V}function ne(j){const{group:A,plot:D,scale:p,labels:se}=j,V=j.config||{},O=new F(A),X=p.domain,oe=te(D),ue=Number.isFinite(j.per)&&j.per>0?j.per:$,xe=T({size:j.fontSize,floor:N(A),slot:p.step,per:ue,every:V.every}),{size:me,every:we}=xe;h(X.length,V.every);for(let Pe=0;Pe<X.length;Pe++){if(Pe%we!==0)continue;const Fe=z(p.centre(X[Pe]));if(Number.isNaN(Fe))continue;const Z=O.next("text",`${i}__tick`);de(Z,{x:z(D.left-E),y:Fe,"text-anchor":"end","dominant-baseline":"middle"}),ie(Z,me),q(Z,se[Pe],oe,me)}O.finish()}function U(j){const{group:A,plot:D,scale:p,format:se}=j,V=j.config||{};if(V.labels===!1){new F(A).finish();return}const O=t(V,se,j.grid,j.column),X=j.size||11,oe=D&&D.gutter,ue=oe&&Number.isFinite(oe.left)?D.left-oe.left:-1/0,xe=oe&&Number.isFinite(oe.right)?D.right+oe.right:1/0,me=w(j.overhang),we=new F(A),Pe=p.kind==="time"&&j.grid?c(j.grid,j.column):void 0;for(const Fe of n(p,V,Pe)){const Z=z(p.of(Fe));if(Z<D.left-1||Z>D.right+1)continue;const re=O(Fe),le=String(re).length*X*W/2;if(Z-le<ue||Z+le>xe)continue;const pe=we.next("text",`${i}__tick`);ie(pe,X),de(pe,{x:Z,y:z(D.bottom+me),"text-anchor":"middle","dominant-baseline":"hanging"}),fe(pe,re)}we.finish()}function M(j){const{group:A,plot:D}=j,p=j.side==="right"?D.right:D.left,se=new F(A);de(se.next("line"),{x1:z(p),x2:z(p),y1:z(D.top),y2:z(D.bottom)}),de(se.next("line"),{x1:z(D.left),x2:z(D.right),y1:z(D.bottom),y2:z(D.bottom)}),se.finish()}let R=0;function H(j,A){const D=`${i}-plot-clip-${++R}`,p=J(j,"rect"),se=J(j,"clipPath",{id:D});se.appendChild(p);const V=`${i}-box-clip-${R}`,O=J(j,"clipPath",{id:V});O.appendChild(J(j,"rect",{x:0,y:0,width:"100%",height:"100%"}));const X=J(j,"defs");X.appendChild(se),X.appendChild(O);const oe={grid:J(j,"g",{class:`${i}__grid`}),marks:J(j,"g",{class:`${i}__marks`}),rules:J(j,"g",{class:`${i}__axis`}),axis:J(j,"g",{class:`${i}__axis`}),labels:J(j,"g",{class:`${i}__labels`}),overlay:J(j,"g",{class:`${i}__overlay`}),clip:p,clipId:D,boxClipId:V};A.appendChild(X);for(const ue of["grid","marks","rules","axis","labels","overlay"])A.appendChild(oe[ue]);return oe}const f=30;function g(j){return j==="bubble"?f:j==="scatter"?6:3}function I(j,A,D){if(!j||!j.marks||!j.clip)return;if(!A||!Number.isFinite(A.width)||!Number.isFinite(A.height)){j.marks.removeAttribute("clip-path");return}const p=Number.isFinite(D)&&D>=0?Number(D):f;de(j.clip,{x:z(A.left-p),y:z(A.top-p),width:z(Math.max(0,A.width)+p*2),height:z(Math.max(0,A.height)+p*2)}),j.marks.setAttribute("clip-path",`url(#${j.clipId})`)}}),rt("packages/modules/charts/stack.js",function(o,ce){"use strict";Object.defineProperty(o,"measureValues",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"stacker",{enumerable:!0,get:function(){return de}});const F=ce("packages/modules/charts/scale.js").isNumber;function l(z,fe,J){if(J)return[0,100];if(!fe){const L=[];for(const _ of z)for(const i of _.points)L.push(i.y);return L}const Q=[],ie=[],W=z[0]?z[0].points.length:0;for(let L=0;L<W;L++){let _=0,i=0;for(const v of z){const k=v.points[L]?v.points[L].y:null;F(k)&&(k>=0?_+=k:i+=k)}Q.push(_),ie.push(i)}return[...Q,...ie]}function de(z,fe){const J=new Float64Array(z),Q=new Float64Array(z);return{take(ie,W){const L=fe?fe[ie]:0,_=fe?L?W/L*100:0:W;if(_>=0){const v=J[ie];return J[ie]+=_,[v,J[ie]]}const i=Q[ie];return Q[ie]+=_,[i,Q[ie]]}}}}),rt("packages/modules/charts/labels.js",function(o,ce){"use strict";Object.defineProperty(o,"resolveLabels",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"collides",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"placeLabels",{enumerable:!0,get:function(){return c}}),Object.defineProperty(o,"labelText",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"drawAnchoredLabels",{enumerable:!0,get:function(){return y}}),Object.defineProperty(o,"drawDataLabels",{enumerable:!0,get:function(){return P}});const F=ce("packages/modules/charts/frame.js").Pool,l=ce("packages/modules/charts/format.js"),de=l.measureText,z=l.stringFormatter,fe=ce("packages/modules/charts/svg.js"),J=fe.attrs,Q=fe.round,ie=fe.setText,L=ce("packages/modules/charts/styles.js").NS,_=ce("packages/modules/charts/typography.js"),i=_.applySize,v=_.textWidth,k=4;function r(u){const E=u&&u.labels;if(!E)return{show:!1,names:E!==!1,position:"outside",format:null,minGap:2,total:!1};const d=typeof E=="object"?E:{};return{show:!0,names:!0,position:["outside","inside","auto"].includes(d.position)?d.position:"outside",format:d.format||null,minGap:Number.isFinite(d.minGap)?Number(d.minGap):2,total:!!d.total}}function m(u,E,d){for(const w of E)if(u.x-d<w.x+w.width&&u.x+u.width+d>w.x&&u.y-d<w.y+w.height&&u.y+u.height+d>w.y)return!0;return!1}function c(u){const{points:E,plot:d,size:w}=u,G=u.minGap===void 0?2:u.minGap,N=[],T=[];for(const C of E){if(C.px===void 0||C.py===void 0)continue;const h=u.text(C);if(!h)continue;const $=v(h,w),a=w;let n=C.px,t=C.py-k,e="middle",s=!1;u.horizontal?(n=C.px+k,t=C.py,e="start",u.position!=="outside"&&C.pbase!==void 0&&Math.abs(C.px-C.pbase)>$+k*2&&(n=C.px-k,e="end",s=!0)):u.position!=="outside"&&C.pbase!==void 0&&Math.abs(C.pbase-C.py)>a+k*2&&(t=C.py+a+k,s=!0);const x=()=>({x:e==="middle"?n-$/2:e==="end"?n-$:n,y:t-a,width:$,height:a});let S=x();!(S.y>=d.top-1)&&!s&&!u.horizontal&&C.pbase!==void 0&&Math.abs(C.pbase-C.py)>a+k*2&&(t=C.py+a+k,s=!0,S=x()),!(S.x+S.width<=d.right+1)&&!s&&u.horizontal&&C.pbase!==void 0&&Math.abs(C.px-C.pbase)>$+k*2&&(n=C.px-k,e="end",s=!0,S=x()),!(S.x<d.left-1||S.x+S.width>d.right+1)&&(S.y<d.top-1||S.y+S.height>d.bottom+a||m(S,N,G)||(N.push(S),T.push({x:Q(n),y:Q(t),text:h,anchor:e,inside:s})))}return T}function b(u,E,d){if(u==null)return"";if(typeof E.format=="function")return String(E.format(u));if(typeof E.format=="string"){const w=z(E.format,d,"labels.format");if(w)return w(u)}return de(u,d&&d.messages)}function y(u){const E=new F(u.group),d=u.minGap===void 0?2:u.minGap,w=u.size,G=[];let N=0;for(const T of u.anchors){if(!T||!T.text)continue;const C=T.width===void 0?v(T.text,u.size):T.width,h=T.anchor||"middle",a={x:h==="end"?T.x-C:h==="start"?T.x:T.x-C/2,y:T.y-w/2,width:C,height:w};if(u.plot&&(a.x<u.plot.left-1||a.x+a.width>u.plot.right+1||a.y<u.plot.top-1||a.y+a.height>u.plot.bottom+1)||T.width!==void 0&&C>T.width||T.height!==void 0&&w>T.height||m(a,G,d))continue;G.push(a);const n=E.next("text",T.className||`${L}__data-label`);i(n,u.size),J(n,{x:Q(T.x),y:Q(T.y),"text-anchor":h,"dominant-baseline":T.baseline||"middle","data-inside":T.inside?"true":null}),ie(n,T.text),N++}return E.finish(),N}function P(u){const E=new F(u.group),{options:d}=u;let w=0;const G=N=>typeof d.format=="function"&&N.y!==null&&N.y!==void 0?String(d.format(N.y,N)):b(N.y,d,u.grid);for(const N of u.series){const T=c({points:N.points,plot:u.plot,size:u.size,position:d.position,horizontal:u.horizontal,minGap:d.minGap,text:G});for(const C of T){const h=E.next("text",`${L}__data-label`);i(h,u.size),J(h,{x:C.x,y:C.y,"text-anchor":C.anchor,"data-inside":C.inside?"true":null}),ie(h,C.text),w++}}return E.finish(),w}}),rt("packages/modules/charts/dense.js",function(o,ce){"use strict";Object.defineProperty(o,"CANVAS_THRESHOLD",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(o,"downsample",{enumerable:!0,get:function(){return F}}),Object.defineProperty(o,"markCount",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"wantsCanvas",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"paintDense",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"sizeCanvas",{enumerable:!0,get:function(){return fe}});const ke=3e3;function F(J,Q){const ie=J.length;if(!Number.isFinite(Q)||Q>=ie||Q<3||ie<3)return J;const W=[J[0]],L=(ie-2)/(Q-2);let _=0;for(let i=0;i<Q-2;i++){const v=Math.floor(i*L)+1,k=Math.min(Math.floor((i+1)*L)+1,ie-1),r=k,m=Math.min(Math.floor((i+2)*L)+1,ie);let c=0,b=0,y=0;for(let d=r;d<m;d++){const w=J[d];!w||!Number.isFinite(w.y)||(c+=w.x,b+=w.y,y++)}y&&(c/=y,b/=y);const P=J[_];if(v>=k)continue;let u=v,E=-1;for(let d=v;d<k;d++){const w=J[d];if(!w||!Number.isFinite(w.y))continue;const G=Math.abs((P.x-c)*(w.y-P.y)-(P.x-w.x)*(b-P.y));G>E&&(E=G,u=d)}u<=_||(W.push(J[u]),_=u)}return W.push(J[ie-1]),W}function l(J){let Q=0;for(const ie of J)Q+=ie.points.length;return Q}function de(J){if(J.canvas===!0)return!0;if(J.canvas===!1)return!1;const Q=Number.isFinite(J.canvas)?Number(J.canvas):ke;return l(J.series)>Q}function z(J){const{context:Q,series:ie,ratio:W}=J;Q.save(),Q.scale(W,W);for(const L of ie){const _=J.colour(L.index);if(J.type==="scatter"||J.type==="bubble"){Q.fillStyle=_;for(const v of L.points)v.px!==void 0&&(Q.beginPath(),Q.arc(v.px,v.py,v.pr||2,0,Math.PI*2),Q.fill());continue}Q.strokeStyle=_,Q.lineWidth=2,Q.lineJoin="round",Q.beginPath();let i=!1;for(const v of L.points){if(v.px===void 0||v.py===void 0){i=!1;continue}i?Q.lineTo(v.px,v.py):Q.moveTo(v.px,v.py),i=!0}Q.stroke()}Q.restore()}function fe(J){const{canvas:Q}=J;return Q.width=Math.max(1,Math.round(J.width*J.ratio)),Q.height=Math.max(1,Math.round(J.height*J.ratio)),Q.style&&(Q.style.width=`${J.width}px`,Q.style.height=`${J.height}px`),typeof Q.getContext=="function"?Q.getContext("2d"):null}}),rt("packages/modules/charts/annotations.js",function(o,ce){"use strict";Object.defineProperty(o,"overlayLayer",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"annotationValue",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"annotationAxis",{enumerable:!0,get:function(){return G}}),Object.defineProperty(o,"annotationText",{enumerable:!0,get:function(){return N}}),Object.defineProperty(o,"drawAnnotations",{enumerable:!0,get:function(){return C}});const F=ce("packages/modules/charts/frame.js").Pool,l=ce("packages/modules/charts/scale.js"),de=l.isNumber,z=l.toNumber,fe=l.toTime,J=ce("packages/modules/charts/svg.js"),Q=J.attrs,ie=J.path,W=J.round,L=J.setText,_=J.SVG_NS,v=ce("packages/modules/charts/styles.js").NS,r=ce("packages/core/src/internal/util.js").warnOnce;function m(h,$){for(const n of h.childNodes||[])if(n&&String(n.getAttribute&&n.getAttribute("class"))===$)return n;const a=h.ownerDocument.createElementNS(_,"g");return a.setAttribute("class",$),h.appendChild(a),a}const c=new Set(["line","target","band","callout","event"]);function b(h,$){return h.kind==="time"?fe($):z($)}function y(h,$,a){if(h.kind==="band"){const t=h.of($);if(!Number.isFinite(t))return NaN;const e=Number(h.bandwidth)||0;return a==="right"?t+e:t}const n=b(h,$);return n===null?NaN:h.of(n)}function P(h,$,a){const n=h.kind||"line",t=h.label?` (${JSON.stringify(h.label)})`:"";r(`chart:annotation:dropped:${n}:${$}:${a}`,`chart annotation${t} of kind ${JSON.stringify(n)}, reading the ${$} axis, was not drawn: ${a}.`)}function u(h,$){if(h instanceof Date){const n=h.getTime();return Number.isFinite(n)?h.toISOString().slice(0,10):String(h)}if(typeof h=="number")return Number.isFinite(h)?$(h):String(h);const a=z(h);return a===null||typeof h=="string"?String(h):$(a)}function E(h,$,a){const n=[];for(const t of h)if((t.axis==="right"?"right":"left")===a&&!($.series!==void 0&&t.key!==$.series))for(const s of t.points)de(s.y)&&n.push(Number(s.y));return n}function d(h,$){if(!h.length)return null;const a=[...h].sort((s,x)=>s-x);if(a.length===1)return a[0];const n=Math.min(100,Math.max(0,$))/100*(a.length-1),t=Math.floor(n),e=Math.ceil(n);return t===e?a[t]:a[t]+(a[e]-a[t])*(n-t)}function w(h,$,a){if(!h.compute)return z(h.value);const n=E($,h,a);if(!n.length)return null;const t=String(h.compute).toLowerCase();if(t==="mean"||t==="avg")return n.reduce((s,x)=>s+x,0)/n.length;if(t==="median"||t==="p50")return d(n,50);if(t==="min")return Math.min(...n);if(t==="max")return Math.max(...n);const e=/^p(\d+(?:\.\d+)?)$/.exec(t);return e?d(n,Number(e[1])):null}function G(h){return h.axis==="right"||h.axis==="y2"?"right":"left"}function N(h,$,a,n){const t=h.label?`${h.label}: `:"",e=n?` (${G(h)==="right"?"right axis":"left axis"})`:"",s=h.kind||"line";if(s==="band"){if(!Array.isArray($)||$[0]===null||$[1]===null)return"";const[S,B]=$;return`${t||"Band: "}${a(Math.min(S,B))} to ${a(Math.max(S,B))}${e}`}return $==null?"":`${t||`${s==="target"?"Target":s==="callout"?"Callout":"Reference"}: `}${a($)}${e}`}function T(h){return(h.kind||"line")==="band"?0:1}function C(h){const{group:$,plot:a,xScale:n,yScale:t,rightScale:e,series:s,format:x}=h,S=new F(m($,`${v}__annotations`)),B=[],te=[...Array.isArray(h.annotations)?h.annotations:[]].sort((q,ne)=>T(q)-T(ne));for(const q of te){const ne=q.kind||"line";if(!c.has(ne))continue;const U=G(q),M=U==="right"&&e?e:t;if(ne==="band"){if(q.orient==="vertical"){const D=y(n,q.from,"left"),p=y(n,q.to,"right");if(Number.isNaN(D)||Number.isNaN(p)){const X=Number.isNaN(D)&&Number.isNaN(p)?"from and to":Number.isNaN(D)?"from":"to";P(q,U,`its ${X} value could not be placed on the x scale`);continue}const se=W(Math.min(D,p)),V=W(Math.max(D,p));if(Q(S.next("rect",`${v}__annotation-band ${q.className||""}`.trim()),{x:se,y:W(a.top),width:Math.max(0,V-se),height:W(Math.max(0,a.bottom-a.top)),fill:q.colour||"currentColor","fill-opacity":q.opacity===void 0?.12:q.opacity}),q.label){const X=S.next("text",`${v}__annotation-label`);Q(X,{x:se+4,y:W(a.top+12),"text-anchor":"start"}),L(X,q.label)}const O=q.label?`${q.label}: `:"Event window: ";B.push({text:`${O}${u(q.from,x)} to ${u(q.to,x)}`});continue}const g=w({...q,value:q.from,compute:q.fromCompute},s,U),I=w({...q,value:q.to,compute:q.toCompute},s,U);if(g===null||I===null){P(q,U,`its ${g===null&&I===null?"from and to":g===null?"from":"to"} value could not be resolved (a number, or a compute that finds values)`);continue}const j=W(M.of(g)),A=W(M.of(I));if(Q(S.next("rect",`${v}__annotation-band ${q.className||""}`.trim()),{x:W(a.left),y:Math.min(j,A),width:W(Math.max(0,a.right-a.left)),height:Math.max(0,Math.abs(A-j)),fill:q.colour||"currentColor","fill-opacity":q.opacity===void 0?.12:q.opacity}),q.label){const D=S.next("text",`${v}__annotation-label`);Q(D,{x:W(a.left+4),y:Math.min(j,A)+12,"text-anchor":"start"}),L(D,q.label)}B.push({text:N(q,[g,I],x,h.dual)});continue}if(ne==="event"){const g=q.x!==void 0?q.x:q.at,I=W(y(n,g,"left")+(n.kind==="band"?(Number(n.bandwidth)||0)/2:0));if(Number.isNaN(I)){P(q,U,"its x value could not be placed on the x scale");continue}if(Q(S.next("path",`${v}__annotation-event`),{d:ie(["M",I,W(a.top),"L",I,W(a.bottom)]),stroke:q.colour||"currentColor",fill:"none"}),Q(S.next("circle",`${v}__annotation-event-flag`),{cx:I,cy:W(a.top),r:3,fill:q.colour||"currentColor"}),q.label){const A=S.next("text",`${v}__annotation-label`);Q(A,{x:I+5,y:W(a.top+10),"text-anchor":"start"}),L(A,q.label)}const j=q.label?`${q.label} — `:"Event — ";B.push({text:`${j}at ${u(g,x)}`});continue}if(ne==="callout"){const g=w(q,s,U);if(g===null){P(q,U,"its value could not be resolved (a number, or a compute that finds values)");continue}const I=q.at!==void 0?W(n.kind==="band"?n.centre(q.at):n.of(b(n,q.at)??NaN)):W(a.right-4),j=W(M.of(g));if(Number.isNaN(I)){P(q,U,"its x value could not be placed on the x scale");continue}if(Q(S.next("circle",`${v}__annotation-point`),{cx:I,cy:j,r:3.5,fill:q.colour||"currentColor"}),q.label){const A=S.next("text",`${v}__annotation-label`);Q(A,{x:I+6,y:j-6,"text-anchor":"start"}),L(A,q.label)}B.push({text:N(q,g,x,h.dual)});continue}if(q.orient==="vertical"||q.x!==void 0){const g=q.x!==void 0?q.x:q.value,I=n.kind==="band"?W(n.centre(g)):W(n.of(b(n,g)??NaN));if(Number.isNaN(I)){P(q,U,"its x value could not be placed on the x scale");continue}const j=ne==="target"?`${v}__annotation-target`:`${v}__annotation-line`;if(Q(S.next("path",j),{d:ie(["M",I,W(a.top),"L",I,W(a.bottom)]),stroke:q.colour||"currentColor",fill:"none"}),q.label){const A=S.next("text",`${v}__annotation-label`);Q(A,{x:I+4,y:W(a.top+10),"text-anchor":"start"}),L(A,q.label)}B.push({text:q.label?`${q.label} — at ${u(g,x)}`:""});continue}const R=w(q,s,U);if(R===null){P(q,U,"its value could not be resolved (a number, or a compute that finds values)");continue}const H=W(M.of(R)),f=ne==="target"?`${v}__annotation-target`:`${v}__annotation-line`;if(Q(S.next("path",f),{d:h.horizontal?ie(["M",H,W(a.top),"L",H,W(a.bottom)]):ie(["M",W(a.left),H,"L",W(a.right),H]),stroke:q.colour||"currentColor",fill:"none"}),q.label){const g=S.next("text",`${v}__annotation-label`);Q(g,h.horizontal?{x:H+4,y:W(a.top+10),"text-anchor":"start"}:{x:W(a.right-4),y:H-4,"text-anchor":"end"}),L(g,q.label)}B.push({text:N(q,R,x,h.dual)})}return S.finish(),B.filter(q=>q.text)}}),rt("packages/modules/charts/combo.js",function(o,ce){"use strict";Object.defineProperty(o,"toPareto",{enumerable:!0,get:function(){return A}}),Object.defineProperty(o,"drawCombo",{enumerable:!0,get:function(){return se}}),Object.defineProperty(o,"drawRightAxis",{enumerable:!0,get:function(){return V}});const ke=ce("packages/modules/charts/axis.js"),F=ke.drawAxisLines,l=ke.drawAxisTitle,de=ke.drawCategoryAxis,z=ke.drawContinuousAxis,fe=ke.drawMeasureAxis,J=ke.heldInside,Q=ke.turnedFirstLabelBox,ie=ke.labelGap,W=ke.overhangFor,L=ke.pinXDomain,_=ke.setPlotClip,i=ke.tickLabeller,v=ke.tickValues,k=ce("packages/modules/charts/frame.js"),r=k.Pool,m=k.shouldRotate,b=ce("packages/modules/charts/format.js").formatters,y=ce("packages/modules/charts/scale.js"),P=y.bandScale,u=y.extent,E=y.isNumber,d=y.linearScale,w=y.measureDomain,G=y.timeScale,N=y.toNumber,T=y.toTime,C=ce("packages/modules/charts/stack.js"),h=C.measureValues,$=C.stacker,a=ce("packages/modules/charts/svg.js"),n=a.attrs,t=a.path,e=a.round,x=ce("packages/modules/charts/styles.js").NS,B=ce("packages/modules/charts/scheme.js").resolveScheme,te=ce("packages/modules/charts/labels.js").drawDataLabels,ne=ce("packages/modules/charts/annotations.js").drawAnnotations,U=ce("packages/modules/charts/curve.js"),M=U.curveCommands,R=U.resolveCurve;function H(O){return{left:O.filter(X=>X.axis!=="right"),right:O.filter(X=>X.axis==="right")}}function f(O,X){const oe=O&&O.seriesStyle&&O.seriesStyle[X];if(oe)return{width:oe.width!=null?String(oe.width):null,dash:Array.isArray(oe.dash)&&oe.dash.length?oe.dash.join(" "):null,opacity:null,emphasized:!1};const ue=O&&Array.isArray(O.emphasis)?O.emphasis:null;if(!ue||!ue.length)return{width:null,dash:null,opacity:null,emphasized:!1};const xe=ue.includes(X);return{width:xe?"var(--lattice-chart-emphasis-width, 3.5)":null,dash:null,opacity:xe?null:"var(--lattice-chart-muted-opacity, .35)",emphasized:xe}}function g(O,X,oe,ue,xe=null){const me=[];let we=[];const Pe=()=>{we.length===1?me.push("M",we[0].x,we[0].y):we.length>1&&me.push(...M(we,xe)),we=[]};for(const Fe of X.points){if(Fe.px===void 0){Pe();continue}we.push({x:Fe.px,y:Fe.py})}Pe(),n(O.next("path",`${x}__line ${x}__mark`),{d:me.length?t(me):"",stroke:oe,"data-series":X.index,"stroke-width":ue.width,"stroke-dasharray":ue.dash,opacity:ue.opacity});for(const Fe of X.points)Fe.px!==void 0&&n(O.next("circle",`${x}__point ${x}__mark`),{cx:Fe.px,cy:Fe.py,r:3,fill:oe})}function I(O,X){return X?{tick:oe=>`${O.tick(oe)}%`,value:oe=>`${O.value(oe)}%`}:O}function j(O,X,oe,ue,xe){const me=O.filter(Fe=>(Fe.mark||"bar")==="bar"),we=O.filter(Fe=>(Fe.mark||"bar")!=="bar"),Pe=ue?h(me,!0,!0):oe?[...h(me,!0,!1),...we.length?h(we,!1,!1):[]]:h(O,!1,!1);return w(Pe,{zero:X,min:xe&&xe.min,max:xe&&xe.max})}function A(O){const X=O.series[0];if(!X)return O;const oe=X.points.map((we,Pe)=>({point:we,label:O.labels[Pe],category:O.categories[Pe]})).filter(we=>E(we.point.y)).sort((we,Pe)=>Pe.point.y-we.point.y),ue=oe.reduce((we,Pe)=>we+Pe.point.y,0);let xe=0;const me=oe.map(we=>(xe+=we.point.y,ue>0?xe/ue*100:0));return{...O,categories:oe.map(we=>we.category),labels:oe.map(we=>we.label),series:[{...X,index:0,mark:"bar",axis:"left",points:oe.map(we=>we.point)},{key:"cumulative",label:O.cumulativeLabel||"%",index:1,mark:"line",axis:"right",points:oe.map((we,Pe)=>({x:we.category,xKey:we.point.xKey,label:we.label,y:me[Pe],rows:we.point.rows,rowKey:we.point.rowKey}))}]}}function D(O,X,oe){const ue=[X.left,X.right];if(O.kind!=="time"&&O.kind!=="linear")return P(O.categories,ue,.2);const xe=O.kind==="time"?O.categories.map(T):O.categories.map(N);if(O.kind==="time"){const Pe=u(xe);if(Pe&&Pe.min===Pe.max)return G(L({min:Pe.min-3e4,max:Pe.max+3e4},O,oe),ue)}const me=O.xDomain||w(xe,{zero:!1,nice:O.kind!=="time"}),we=O.xDomain?me:L(me,O,oe);return O.kind==="time"?G(we,ue):d(we,ue)}function p(O,X){const oe=[...new Set(O.filter(Pe=>Number.isFinite(Pe)))].sort((Pe,Fe)=>Pe-Fe);if(oe.length<2){const[Pe,Fe]=X.range;return Math.max(4,(Fe-Pe)/10)}const ue=[];for(let Pe=1;Pe<oe.length;Pe++)ue.push(oe[Pe]-oe[Pe-1]);ue.sort((Pe,Fe)=>Pe-Fe);const xe=Math.floor(ue.length/2),me=ue.length%2?ue[xe]:(ue[xe-1]+ue[xe])/2,we=Math.abs(X.of(oe[0]+me)-X.of(oe[0]));return Math.max(1,we*.8)}function se(O){const X=O.scheme||B(),oe=O.axis||{x:{},y:{},y2:{}},{plot:ue}=O,xe=O.pareto?A(O.bound):O.bound,me=xe.series.filter(Ne=>!O.hidden.has(Ne.key)),we=H(me),Pe=Ne=>(Ne.mark||"bar")==="bar",Fe=we.left.some(Pe),Z=we.left.filter(Pe),re=O.stack==="percent"&&Z.length>1&&!we.right.length,le=(re||!!O.stack)&&Z.length>1&&!we.right.length,pe=xe.yDomain||j(we.left,Fe,le,re,oe.y),he=d(pe,[ue.bottom,ue.top]),Me=we.right.length?O.pareto?{min:0,max:100}:j(we.right,we.right.some(Pe),!1,!1,oe.y2):null,Ie=Me?d(Me,[ue.bottom,ue.top]):null,Ke=D(xe,ue,oe.x),qe=Ke.kind!=="band",ot=qe?xe.categories.map(Ne=>xe.kind==="time"?T(Ne):N(Ne)):null,it=qe&&me.some(Ne=>(Ne.mark||"bar")==="bar")?p(ot,Ke)/2:0,Le=!qe&&(oe.x.rotate===void 0||oe.x.rotate==="auto"?m(xe.labels,Ke.step,O.fontSize):!!oe.x.rotate)&&Q({group:O.groups.overlay,plot:ue,scale:Ke,labels:xe.labels,fontSize:O.fontSize,config:oe.x}),He=oe.y.position==="right"?"right":"left";fe({gridGroup:O.groups.grid,axisGroup:O.groups.axis,plot:ue,scale:he,format:I(b(O.grid,{kind:"linear",step:(pe.max-pe.min)/5}),re),config:oe.y,grid:O.grid,size:O.fontSize,side:He,overhang:it,dropBottom:Le});const Ze=xe.dimension&&xe.dimension.col?O.grid.columns.get(xe.dimension.col):void 0;qe?z({group:O.groups.overlay,plot:ue,scale:Ke,format:b(O.grid,{kind:xe.kind,span:Ke.domain.max-Ke.domain.min,step:(Ke.domain.max-Ke.domain.min)/5},Ze),config:oe.x,grid:O.grid,column:Ze,size:O.fontSize}):de({group:O.groups.overlay,plot:ue,scale:Ke,labels:xe.labels,fontSize:O.fontSize,rotated:m(xe.labels,Ke.step,O.fontSize),config:oe.x}),F({group:O.groups.rules,plot:ue,side:He});const ae=O.typography&&O.typography.axisTitle||O.fontSize;if(l({group:O.groups.axis,plot:ue,text:oe.y.title,side:He,size:ae}),l({group:O.groups.axis,plot:ue,text:oe.x.title,side:"bottom",size:ae}),Ie){V({group:O.groups.axis,plot:ue,scale:Ie,colour:X.series(we.right[0].index,we.right[0].label),format:b(O.grid,{kind:"linear",step:(Me.max-Me.min)/5}),config:oe.y2,grid:O.grid,suffix:O.pareto?"%":"",side:He==="right"?"left":"right",overhang:it});const Ne=oe.y2.title||(we.right.length===1?we.right[0].label:"");l({group:O.groups.axis,plot:ue,text:Ne,side:He==="right"?"left":"right",size:ae})}_(O.groups,ue,W(O.type));const ee=new r(O.groups.marks),ye=me.filter(Ne=>(Ne.mark||"bar")==="bar"),ve=qe?p(ot,Ke):Ke.bandwidth,be=le?ve:ye.length?ve/ye.length:ve,Ee=re?xe.categories.map((Ne,Ve)=>Z.reduce((Be,Oe)=>{const Xe=Oe.points[Ve]?Oe.points[Ve].y:null;return E(Xe)?Be+Math.abs(Xe):Be},0)):null,$e=le?$(xe.categories.length,Ee):null;let Ge=0;const Ye=[];for(const Ne of me){const Ve=Ne.mark||"bar",Be=Ne.axis==="right"&&Ie?Ie:he,Oe=X.series(Ne.index,Ne.label);if(Ve==="bar"){const st=le?0:Ge*be;Ge++;const ft=Be.of(Math.max(Be.domain.min,0));for(let ht=0;ht<Ne.points.length;ht++){const $t=Ne.points[ht];if(!E($t.y))continue;let dt;if(qe){const kt=xe.kind==="time"?T($t.x):N($t.x);dt=kt===null?NaN:Ke.of(kt)-ve/2}else dt=Ke.of($t.x);if(Number.isNaN(dt))continue;const mt=$e?$e.take(ht,$t.y):null,At=Be.of(mt?mt[1]:$t.y),ct=mt?Be.of(mt[0]):ft;n(ee.next("rect",`${x}__bar ${x}__mark`),{x:e(dt+st),y:e(Math.min(At,ct)),width:e(Math.max(0,be)),height:e(Math.max(1,Math.abs(ct-At))),fill:Oe,"data-series":Ne.index,"data-point":ht}),$t.px=e(dt+st+be/2),$t.py=e(Math.min(At,ct))}continue}for(const st of Ne.points){if(!E(st.y)){st.px=void 0;continue}let ft;if(qe){const $t=xe.kind==="time"?T(st.x):N(st.x);ft=$t===null?NaN:e(Ke.of($t))}else ft=e(Ke.centre(st.x));if(Number.isNaN(ft)){st.px=void 0;continue}const ht=e(Be.of(st.y));st.px=ft,st.py=ht}const Xe=f(O,Ne.label),nt=R(O.curve,Ne.label);Xe.emphasized?Ye.push({series:Ne,colour:Oe,style:Xe,curve:nt}):g(ee,Ne,Oe,Xe,nt)}for(const Ne of Ye)g(ee,Ne.series,Ne.colour,Ne.style,Ne.curve);ee.finish(),O.labels&&O.labels.show&&te({group:O.groups.labels,series:me,plot:ue,options:O.labels,grid:O.grid,size:O.typography&&O.typography.small||O.fontSize});let Se=null;return O.annotations&&O.annotations.length&&(Se=ne({group:O.groups.overlay,plot:ue,xScale:Ke,yScale:he,rightScale:Ie,series:me,annotations:O.annotations,dual:!!Ie,format:b(O.grid,{kind:"linear",step:(pe.max-pe.min)/5}).tick})),{xScale:Ke,yScale:he,rightScale:Ie,dual:!!Ie,series:me,bound:xe,annotations:Se,percent:re,percentTotals:Ee}}function V(O){const{group:X,plot:oe,scale:ue,format:xe}=O,me=O.config||{},we=O.side==="left"?"left":"right",Pe=we==="right"?oe.right:oe.left,Fe=i(me,xe,O.grid),Z=new r(X,X.childNodes.length),re=ie(O.overhang);n(Z.next("line",`${x}__axis-right`),{x1:e(Pe),x2:e(Pe),y1:e(oe.top),y2:e(oe.bottom),stroke:O.colour});for(const le of v(ue,me)){const pe=e(ue.of(le)),he=Z.next("text",`${x}__tick`);n(he,{x:e(we==="right"?oe.right+re:oe.left-re),y:J(pe,oe,11),"text-anchor":we==="right"?"start":"end","dominant-baseline":"middle",fill:O.colour}),he.textContent=`${Fe(le)}${O.suffix||""}`}Z.finish()}}),rt("packages/modules/charts/quantile.js",function(o,ce){"use strict";Object.defineProperty(o,"normalQuantile",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"studentTQuantile",{enumerable:!0,get:function(){return W}});const ke=Object.freeze([676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23]),F=3e-12,l=1e-300;function de(L){if(L<.5)return Math.log(Math.PI/Math.sin(Math.PI*L))-de(1-L);const _=L-1;let i=.9999999999998099;const v=_+7.5;for(let k=0;k<ke.length;k++)i+=ke[k]/(_+k+1);return .5*Math.log(2*Math.PI)+(_+.5)*Math.log(v)-v+Math.log(i)}function z(L,_,i){const v=L+_,k=L+1,r=L-1;let m=1,c=1-v*i/k;Math.abs(c)<l&&(c=l),c=1/c;let b=c;for(let y=1;y<=300;y++){const P=2*y;let u=y*(_-y)*i/((r+P)*(L+P));c=1+u*c,Math.abs(c)<l&&(c=l),m=1+u/m,Math.abs(m)<l&&(m=l),c=1/c,b*=c*m,u=-(L+y)*(v+y)*i/((L+P)*(k+P)),c=1+u*c,Math.abs(c)<l&&(c=l),m=1+u/m,Math.abs(m)<l&&(m=l),c=1/c;const E=c*m;if(b*=E,Math.abs(E-1)<F)break}return b}function fe(L,_,i){if(!(L>0)||!(_>0)||!Number.isFinite(i))return Number.NaN;if(i<=0)return 0;if(i>=1)return 1;const v=Math.exp(de(L+_)-de(L)-de(_)+L*Math.log(i)+_*Math.log(1-i));return i<(L+1)/(L+_+2)?v*z(L,_,i)/L:1-v*z(_,L,1-i)/_}function J(L){const _=Math.abs(L),i=2/(2+_),v=4*i-2,k=[-1.3026537197817094,.6419697923564902,.019476473204185836,-.00956151478680863,-.000946595344482036,.000366839497852761,42523324806907e-18,-20278578112534e-18,-1624290004647e-18,130365583558e-17,15626441722e-18,-85238095915e-18,6529054439e-18,5059343495e-18,-991364156e-18,-227365122e-18,96467911e-18,2394038e-18,-6886027e-18,894487e-18,313092e-18,-112708e-18,381e-18,7106e-18];let r=0,m=0,c;for(let y=k.length-1;y>0;y--)c=m,m=v*m-r+k[y],r=c;const b=i*Math.exp(-_*_+.5*(k[0]+v*m)-r);return L>=0?b:2-b}function Q(L){if(!(L>0)||!(L<1))return L===0?-1/0:L===1?1/0:Number.NaN;const _=[-39.69683028665376,220.9460984245205,-275.9285104469687,138.357751867269,-30.66479806614716,2.506628277459239],i=[-54.47609879822406,161.5858368580409,-155.6989798598866,66.80131188771972,-13.28068155288572],v=[-.007784894002430293,-.3223964580411365,-2.400758277161838,-2.549732539343734,4.374664141464968,2.938163982698783],k=[.007784695709041462,.3224671290700398,2.445134137142996,3.754408661907416],r=.02425;let m,c,b;L<r?(m=Math.sqrt(-2*Math.log(L)),b=(((((v[0]*m+v[1])*m+v[2])*m+v[3])*m+v[4])*m+v[5])/((((k[0]*m+k[1])*m+k[2])*m+k[3])*m+1)):L<=1-r?(m=L-.5,c=m*m,b=(((((_[0]*c+_[1])*c+_[2])*c+_[3])*c+_[4])*c+_[5])*m/(((((i[0]*c+i[1])*c+i[2])*c+i[3])*c+i[4])*c+1)):(m=Math.sqrt(-2*Math.log(1-L)),b=-(((((v[0]*m+v[1])*m+v[2])*m+v[3])*m+v[4])*m+v[5])/((((k[0]*m+k[1])*m+k[2])*m+k[3])*m+1));const P=(.5*J(-b/Math.SQRT2)-L)*Math.sqrt(2*Math.PI)*Math.exp(b*b/2);return b-P/(1+b*P/2)}function ie(L,_){if(!(_>0)||!Number.isFinite(L))return Number.NaN;const i=.5*fe(_/2,.5,_/(_+L*L));return L>0?1-i:i}function W(L,_){if(!(L>0)||!(L<1)||!(_>0))return Number.NaN;if(_>1e7)return Q(L);let i=-1e4,v=1e4,k=Q(L);const r=de(_/2)+de(.5)-de((_+1)/2);for(let m=0;m<60;m++){const c=ie(k,_);c<L?i=k:v=k;const b=Math.exp(-((_+1)/2)*Math.log(1+k*k/_)-r)/Math.sqrt(_),y=b>0?(c-L)/b:0;if(Math.abs(y)<1e-12)break;const P=k-y;if(k=P>i&&P<v&&Number.isFinite(P)?P:(i+v)/2,v-i<1e-12)break}return k}}),rt("packages/modules/charts/trendline.js",function(o,ce){"use strict";Object.defineProperty(o,"normaliseTrends",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"linearTrend",{enumerable:!0,get:function(){return C}}),Object.defineProperty(o,"movingAverageTrend",{enumerable:!0,get:function(){return h}}),Object.defineProperty(o,"exponentialTrend",{enumerable:!0,get:function(){return t}}),Object.defineProperty(o,"computeTrend",{enumerable:!0,get:function(){return e}}),Object.defineProperty(o,"trendText",{enumerable:!0,get:function(){return s}}),Object.defineProperty(o,"drawTrendlines",{enumerable:!0,get:function(){return x}});const F=ce("packages/modules/charts/frame.js").Pool,l=ce("packages/modules/charts/svg.js"),de=l.attrs,z=l.path,fe=l.ribbonPath,J=l.round,Q=l.setText,ie=l.SVG_NS,L=ce("packages/modules/charts/typography.js").applySize,i=ce("packages/modules/charts/styles.js").NS,v=ce("packages/modules/charts/scale.js"),k=v.toNumber,r=v.toTime,c=ce("packages/modules/charts/quantile.js").studentTQuantile,y=ce("packages/modules/charts/format.js").r2Digits,P={linear:new Set(["linear","lr","ols","regression","least-squares"]),movingAverage:new Set(["movingaverage","moving-average","ma","sma","rolling"]),exponential:new Set(["exponential","exp","ewma","ses","holt","smoothing"])},u=1e-4,E=1-1e-4;function d(S){const B=String(S||"linear").toLowerCase();return P.linear.has(B)?"linear":P.movingAverage.has(B)?"movingAverage":P.exponential.has(B)?"exponential":null}function w(S){if(!S)return[];const B=Array.isArray(S)?S:[S],Y=[];for(const te of B){if(te===!0){Y.push({method:"linear"});continue}if(typeof te=="string"){const q=d(te);q&&Y.push({method:q});continue}if(te&&typeof te=="object"){const q=d(te.method);q&&Y.push({...te,method:q})}}return Y}function G(S,B){if(S.kind==="band")return S.centre(B);const Y=S.kind==="time"?r(B):k(B);return Y===null?NaN:S.of(Y)}function N(S){const B=[];for(const Y of S.points){const te=Number(Y.y);B.push({value:Number.isFinite(te)?te:null,rawX:Y.x})}return B}function T(S,B){const Y=[];for(const te of S.points){const q=B.kind==="time"?r(te.x):k(te.x),ne=Number(te.y);q===null||!Number.isFinite(q)||!Number.isFinite(ne)||Y.push({x:q,y:ne})}return Y.sort((te,q)=>te.x-q.x),Y}function C(S,B,Y={}){const te=S.length;if(te<2)return null;let q=0,ne=0;for(const O of S)q+=O.x,ne+=O.y;q/=te,ne/=te;let U=0,M=0,R=0;for(const O of S){const X=O.x-q,oe=O.y-ne;U+=X*X,M+=X*oe,R+=oe*oe}if(U===0)return null;const H=M/U,f=ne-H*q,g=R===0?1:Math.max(0,Math.min(1,M*M/(U*R))),I=S[0].x,j=S[te-1].x,A=O=>({x:O,y:f+H*O}),D=[A(I),A(j)],p=[];let se=null;const V=Math.max(0,Math.floor(Number(B)||0));if(V>0&&j>I){const O=(j-I)/(te-1);if(O>0&&(p.push(A(j),A(j+V*O)),te>2)){const X=Number.isFinite(Y.confidence)&&Y.confidence>0&&Y.confidence<1?Number(Y.confidence):.95,oe=1-(1-X)/2,ue=Math.max(0,R-H*M),xe=Math.sqrt(ue/(te-2)),me=c(oe,te-2),we=[];for(let Pe=0;Pe<=V;Pe++){const Fe=j+Pe*O,Z=f+H*Fe,re=1/te+(Fe-q)**2/U,le=xe*Math.sqrt(1+re),pe=xe*Math.sqrt(re);we.push({x:Fe,mean:Z,lower:Z-me*le,upper:Z+me*le,lowerMean:Z-me*pe,upperMean:Z+me*pe})}se={confidence:X,points:we}}}return{fit:D,forecast:p,band:se,stats:{method:"linear",slope:H,intercept:f,r2:g,n:te,forecast:p.length?V:0,confidence:se?se.confidence:null}}}function h(S,B){const Y=Math.max(1,Math.floor(Number(B)||3)),te=[];let q=0;const ne=[];for(const U of S)Number.isFinite(U.value)&&(te.push(U.value),q+=U.value,te.length>Y&&(q-=te.shift())),te.length&&ne.push({x:U.rawX,y:q/te.length});return ne.length<2?null:{fit:ne,stats:{method:"movingAverage",window:Y}}}function $(S,B){const Y=S.length,te=new Array(Y).fill(null);let q=null,ne=0;for(let U=0;U<Y;U++){const M=S[U];if(!Number.isFinite(M)){q!==null&&(te[U]=q);continue}if(q===null){q=M,te[U]=M;continue}ne+=(M-q)**2,q=B*M+(1-B)*q,te[U]=q}return{smoothed:te,sse:ne}}function a(S,B,Y){const te=S.length,q=new Array(te).fill(null);let ne=null,U=null,M=0;for(let R=0;R<te;R++){const H=S[R];if(!Number.isFinite(H)){ne!==null&&(ne+=U,q[R]=ne);continue}if(ne===null){ne=H,q[R]=H;continue}if(U===null){U=H-ne;const I=ne+U;M+=(H-I)**2;const j=ne;ne=B*H+(1-B)*(j+U),U=Y*(ne-j)+(1-Y)*U,q[R]=ne;continue}const f=ne+U;M+=(H-f)**2;const g=ne;ne=B*H+(1-B)*(g+U),U=Y*(ne-g)+(1-Y)*U,q[R]=ne}return{smoothed:q,sse:M}}function n(S,B,Y,te=80){const q=(Math.sqrt(5)-1)/2;let ne=B,U=Y,M=U-q*(U-ne),R=ne+q*(U-ne),H=S(M),f=S(R);for(let g=0;g<te;g++)H<f?(U=R,R=M,f=H,M=U-q*(U-ne),H=S(M)):(ne=M,M=R,H=f,R=ne+q*(U-ne),f=S(R));return(ne+U)/2}function t(S,B){const Y=String(B.kind||B.model||"").toLowerCase()==="holt",te=S.map(f=>Number.isFinite(f.value)?f.value:null);if(te.filter(f=>f!==null).length<(Y?2:1))return null;const ne=f=>Math.min(E,Math.max(u,f));let U=Number.isFinite(B.alpha)?ne(Number(B.alpha)):null,M=Y&&Number.isFinite(B.beta)?ne(Number(B.beta)):null;if(Y){if(U===null||M===null){let f=U===null?.5:U,g=M===null?.5:M;for(let I=0;I<6;I++)U===null&&(f=n(j=>a(te,j,g).sse,u,E)),M===null&&(g=n(j=>a(te,f,j).sse,u,E));U=U===null?f:U,M=M===null?g:M}}else U===null&&(U=n(f=>$(te,f).sse,u,E));const R=Y?a(te,U,M):$(te,U),H=[];for(let f=0;f<S.length;f++){const g=R.smoothed[f];g===null||!Number.isFinite(g)||H.push({x:S[f].rawX,y:g})}return H.length<2?null:{fit:H,stats:{method:"exponential",kind:Y?"holt":"ses",alpha:U,beta:Y?M:null}}}function e(S,B,Y){if(B.method==="linear"){const q=T(S,Y);return C(q,B.forecast,{confidence:B.confidence})}const te=N(S);return B.method==="movingAverage"?h(te,B.window||B.period):t(te,B)}function s(S,B,Y,te,q,ne){const U=B?` for ${B}`:"";if(S.method==="linear"){const f=Number.isFinite(S.r2)?`, R² ${S.r2.toFixed(2)}`:"";let g=`Trend (linear)${U}: slope ${Y(S.slope)}${f}`;if(S.forecast>0&&te&&te.length){const I=te[te.length-1];if(g+=`; forecast ${S.forecast} step${S.forecast===1?"":"s"} ahead to ${Y(I.y)}`,q&&q.points.length){const j=q.points[q.points.length-1],A=ne==="confidence"||ne==="mean",D=A?j.lowerMean:j.lower,p=A?j.upperMean:j.upper,se=A?"confidence":"prediction",V=Math.round(q.confidence*100);g+=`; ${V}% ${se} band ${Y(D)} to ${Y(p)} at the horizon`}}return g}if(S.method==="movingAverage")return`Trend (moving average, window ${S.window})${U}`;const M=S.kind==="holt"?"Holt":"single",R=Number.isFinite(S.alpha)?`, α ${S.alpha.toFixed(2)}`:"",H=Number.isFinite(S.beta)?`, β ${S.beta.toFixed(2)}`:"";return`Trend (exponential, ${M})${U}${R}${H}`}function x(S){const B=w(S.trend);if(!B.length)return[];const Y=S.group.ownerDocument;let te=null;for(const U of S.group.childNodes||[])if(U&&String(U.getAttribute&&U.getAttribute("class"))===`${i}__trends`){te=U;break}te||(te=Y.createElementNS(ie,"g"),te.setAttribute("class",`${i}__trends`),S.group.appendChild(te)),S.clip?te.setAttribute("clip-path",`url(#${S.clip})`):te.removeAttribute("clip-path");const q=new F(te),ne=[];for(const U of B)for(const M of S.series){const R=M.axis==="right"&&S.rightScale?S.rightScale:S.yScale,H=e(M,U,S.xScale);if(!H)continue;const f=S.scheme.series(M.index),g=[];for(const A of H.fit){const D=G(S.xScale,A.x),p=R.of(A.y);!Number.isFinite(D)||!Number.isFinite(p)||g.push(g.length?"L":"M",J(D),J(p))}if(g.length<4)continue;if(de(q.next("path",`${i}__trend`),{d:z(g),fill:"none",stroke:f,"data-series":M.index}),U.band!==!1&&H.band&&H.band.points.length>=2){const A=U.band==="confidence"||U.band==="mean",D=[];for(const se of H.band.points){const V=G(S.xScale,se.x),O=A?se.lowerMean:se.lower,X=A?se.upperMean:se.upper,oe=R.of(O),ue=R.of(X);!Number.isFinite(V)||!Number.isFinite(oe)||!Number.isFinite(ue)||D.push({x:J(V),lower:J(oe),upper:J(ue)})}const p=fe(D);p&&de(q.next("path",`${i}__trend-band`),{d:p,fill:f,"fill-opacity":.15,stroke:"none","data-series":M.index})}const j=H.forecast||[];if(j.length>=2){const A=[];for(const D of j){const p=G(S.xScale,D.x),se=R.of(D.y);!Number.isFinite(p)||!Number.isFinite(se)||A.push(A.length?"L":"M",J(p),J(se))}A.length>=4&&de(q.next("path",`${i}__trend-forecast`),{d:z(A),fill:"none",stroke:f,"data-series":M.index})}if(U.label!==!1&&H.stats.method==="linear"&&Number.isFinite(H.stats.r2)){const A=H.fit[H.fit.length-1],D=q.next("text",`${i}__trend-label`);L(D,S.size),de(D,{x:J(G(S.xScale,A.x)),y:J(R.of(A.y))-4,"text-anchor":"end",fill:f}),Q(D,S.grid.messages.t("chart.r2",{value:y(S.grid,H.stats.r2)}))}ne.push({text:s(H.stats,M.label,S.format,j,U.band===!1?null:H.band,U.band)})}return q.finish(),ne.filter(U=>U.text)}}),rt("packages/modules/charts/rulecolour.js",function(o,ce){"use strict";Object.defineProperty(o,"colourOf",{enumerable:!0,get:function(){return F}}),Object.defineProperty(o,"ruleColour",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"ruleLegend",{enumerable:!0,get:function(){return de}});const ke="*";function F(z){if(!z||typeof z!="object")return null;for(const fe of["background","backgroundColor","color"]){const J=z[fe];if(typeof J=="string"&&J.trim())return J.trim()}return null}function l(z){const{grid:fe,col:J,value:Q}=z;if(!fe||!J||!fe.formatting||typeof fe.formatting.styleFor!="function")return null;try{return F(fe.formatting.styleFor(J,Q))}catch{return null}}function de(z){const{grid:fe,col:J}=z,Q=new Set([...z.colours||[]].filter(Boolean));if(!Q.size||!fe||!fe.formatting||typeof fe.formatting.list!="function")return[];let ie;try{ie=[...fe.formatting.list(ke)||[],...J?fe.formatting.list(J)||[]:[]]}catch{return[]}const W=[],L=new Set;for(const _ of ie){if(!_||_.enabled===!1)continue;const i=F(_.style);!i||!Q.has(i)||L.has(i)||(L.add(i),W.push({key:_.id||`rule:${W.length}`,label:_.label||_.id||i,colour:i,index:W.length}))}return W}}),rt("packages/modules/charts/glyph.js",function(o,ce){"use strict";Object.defineProperty(o,"glyphFor",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"glyphTransform",{enumerable:!0,get:function(){return fe}});const F=ce("packages/core/src/internal/util.js").warnOnce,de=ce("packages/modules/charts/svg.js").round;function z(J,Q,ie="node"){if(!Q)return null;const W=ie==="marker",L=W?"a chart image marker":"a network node",_=J&&J.icons;if(!_||typeof _.get!="function")return F(`chart:icons:${Q}`,`${L.charAt(0).toUpperCase()}${L.slice(1)} asked for the icon '${Q}', but this grid publishes no icon registry — a headless grid has no sprites. The ${W?"point":"node"} drew as ${W?"its default marker":"a plain disc"}.`),null;const i=_.get(Q);return i||(F(`chart:icon:${Q}`,`Unknown icon '${Q}' on ${L}; ${W?"kept the default marker":"drew a plain disc"} instead. Register it with registerIcon or config.icons, or name a built-in.`),null)}function fe(J,Q){const ie=String(J.viewBox||"0 0 16 16").trim().split(/[\s,]+/).map(Number),[W,L,_,i]=ie.length===4&&ie.every(Number.isFinite)?ie:[0,0,16,16],v=Math.max(_||16,i||16),k=Q.size/v,r=Q.x-_*k/2,m=Q.y-i*k/2;return`translate(${de(r-W*k)} ${de(m-L*k)}) scale(${de(k)})`}}),rt("packages/modules/charts/markers.js",function(o,ce){"use strict";Object.defineProperty(o,"MARKER_SIZE",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"clearMarkerImages",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"resolveMarker",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"safeImageUrl",{enumerable:!0,get:function(){return k}}),Object.defineProperty(o,"imageOf",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"imageState",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"markerFor",{enumerable:!0,get:function(){return c}}),Object.defineProperty(o,"placeMarker",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"markerBoxHit",{enumerable:!0,get:function(){return y}});const F=ce("packages/core/src/internal/util.js").warnOnce,l=ce("packages/modules/charts/glyph.js"),de=l.glyphFor,z=l.glyphTransform,J=ce("packages/modules/charts/styles.js").NS,Q=16,ie=[6,64],W=/^data:image\/(png|jpe?g|gif|webp|avif|bmp|svg\+xml)[;,]/i,L=/^(https?:|blob:|data:|javascript:|vbscript:|file:|\/|\.\.?\/)|[/.]/i,_=new Map;function i(){_.clear()}function v(P){if(!P||typeof P!="object"||Array.isArray(P))return null;const u=P.image;if(u==null||u==="")return F("chart:marker:no-image",'chart "marker" needs an "image": an icon name, a URL, { col } or a function. No markers were drawn from it.'),null;const E=Number(P.size);return{image:u,size:Number.isFinite(E)?Math.min(ie[1],Math.max(ie[0],E)):Q,explicitSize:Number.isFinite(E)}}function k(P){const u=String(P).trim(),E=/^([a-z][a-z0-9+.-]*):/i.exec(u);if(E){const d=E[1].toLowerCase();return d==="data"?W.test(u)?u:null:d==="http"||d==="https"||d==="blob"?u:null}return/^[^/]*:/.test(u)?null:u}function r(P,u,E){let d=P.image;if(typeof d=="function")try{d=d(u)}catch{d=null}else d&&typeof d=="object"&&typeof d.col=="string"&&(d=E&&E.rows&&u&&u.rowKey!==void 0&&u.rowKey!==null?E.rows.value(u.rowKey,d.col):null);return typeof d=="string"&&d.trim()?d.trim():null}function m(P,u,E){let d=_.get(P);if(d)return d.state==="loading"&&E&&d.waiting.add(E),d.state;const w=u&&u.defaultView,G=w&&w.Image;if(typeof G!="function")return"ok";d={state:"loading",waiting:new Set(E?[E]:[])},_.set(P,d);const N=new G,T=C=>{if(d.state=C,C==="failed"){const h=P.length>80?P.slice(0,77):P;F(`chart:marker:image-failed:${P}`,`a chart marker image could not be loaded (${h}); those points keep the default marker. Check the URL, and that the server allows the page to load it.`)}for(const h of d.waiting)try{h()}catch{}d.waiting.clear()};return N.onload=()=>T("ok"),N.onerror=()=>T("failed"),N.src=P,"loading"}function c(P,u,E){const d=r(P,u,E.grid);if(!d)return null;if(!L.test(d)){const G=de(E.grid,d,"marker");return G?{kind:"icon",def:G}:null}const w=k(d);if(!w){const G=d.slice(0,40);return F(`chart:marker:unsafe-url:${G}`,`a chart marker image URL was refused (${G}): only http, https, blob, relative and data:image URLs are drawn. Those points keep the default marker.`),null}return m(w,E.doc,E.redraw)==="ok"?{kind:"image",href:w}:null}function b(P,u,E){const d=E.size/2;if(u.kind==="icon"){const G=u.def,N=G.paint==="stroke",T=P.next("path",`${J}__marker-icon ${J}__mark`);return E.attrs(T,{d:G.paths.join(" "),transform:z(G,{x:E.x,y:E.y,size:E.size}),fill:N?"none":E.colour,stroke:N?E.colour:null,"stroke-width":N?1.5:null,class:`${J}__marker-icon ${J}__mark`,...E.extra||{}}),T}const w=P.next("image",`${J}__marker-image ${J}__mark`);return E.attrs(w,{href:u.href,x:E.round(E.x-d),y:E.round(E.y-d),width:E.size,height:E.size,preserveAspectRatio:"xMidYMid meet",class:`${J}__marker-image ${J}__mark`,...E.extra||{}}),w}function y(P,u,E){return Math.abs(u-P.x)<=P.half&&Math.abs(E-P.y)<=P.half}}),rt("packages/modules/charts/cartesian.js",function(o,ce){"use strict";Object.defineProperty(o,"CARTESIAN",{enumerable:!0,get:function(){return Ie}}),Object.defineProperty(o,"WATERFALL_TOTAL",{enumerable:!0,get:function(){return ot}}),Object.defineProperty(o,"withWaterfallTotal",{enumerable:!0,get:function(){return it}}),Object.defineProperty(o,"axisWindowSpan",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(o,"axisWindowNow",{enumerable:!0,get:function(){return Le}}),Object.defineProperty(o,"rollingDomain",{enumerable:!0,get:function(){return He}}),Object.defineProperty(o,"WINDOW_LEAD",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(o,"aheadOfWindow",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(o,"staleWindow",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(o,"windowedBound",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(o,"slotPadFor",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(o,"pinnedContinuousX",{enumerable:!0,get:function(){return Ye}}),Object.defineProperty(o,"continuousX",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(o,"bandedX",{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(o,"dataInterval",{enumerable:!0,get:function(){return Ve}}),Object.defineProperty(o,"continuousSlot",{enumerable:!0,get:function(){return Be}}),Object.defineProperty(o,"xDomainFor",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(o,"xScaleFor",{enumerable:!0,get:function(){return Xe}}),Object.defineProperty(o,"drawFits",{enumerable:!0,get:function(){return Lt}}),Object.defineProperty(o,"drawConfidenceBand",{enumerable:!0,get:function(){return Ht}}),Object.defineProperty(o,"drawBoundErrorBars",{enumerable:!0,get:function(){return Gt}}),Object.defineProperty(o,"drawForest",{enumerable:!0,get:function(){return xt}}),Object.defineProperty(o,"drawReferenceLines",{enumerable:!0,get:function(){return je}}),Object.defineProperty(o,"drawCartesian",{enumerable:!0,get:function(){return Et}}),Object.defineProperty(o,"HIT_TOLERANCE",{enumerable:!0,get:function(){return gt}}),Object.defineProperty(o,"nearestDrawnPoint",{enumerable:!0,get:function(){return Nt}}),Object.defineProperty(o,"nearestCategory",{enumerable:!0,get:function(){return Wt}}),Object.defineProperty(o,"categoryKeyAt",{enumerable:!0,get:function(){return en}});const ke=ce("packages/modules/charts/axis.js"),F=ke.drawAxisLines,l=ke.drawAxisTitle,de=ke.drawBandLabels,z=ke.drawCategoryAxis,fe=ke.drawContinuousAxis,J=ke.drawMeasureAxis,Q=ke.overhangFor,ie=ke.pinXDomain,W=ke.setPlotClip,L=ke.turnedFirstLabelBox,_=ce("packages/modules/charts/frame.js"),i=_.Pool,v=_.shouldRotate,k=ce("packages/modules/charts/format.js"),r=k.formatters,m=k.r2Digits,c=ce("packages/modules/charts/scale.js"),b=c.bandScale,y=c.extent,P=c.isNumber,u=c.key,E=c.linearScale,d=c.measureDomain,w=c.timeScale,G=c.toNumber,N=c.toTime,T=ce("packages/modules/charts/stack.js"),C=T.measureValues,h=T.stacker,$=ce("packages/modules/charts/svg.js"),a=$.attrs,n=$.path,t=$.ribbonPath,e=$.round,s=$.setText,x=$.SVG_NS,B=ce("packages/modules/charts/styles.js").NS,te=ce("packages/modules/charts/labels.js").drawDataLabels,ne=ce("packages/modules/charts/dense.js").downsample,M=ce("packages/modules/charts/scheme.js").resolveScheme,H=ce("packages/modules/charts/typography.js").applySize,g=ce("packages/modules/charts/combo.js").drawRightAxis,I=ce("packages/modules/charts/annotations.js"),j=I.drawAnnotations,A=I.overlayLayer,p=ce("packages/modules/charts/trendline.js").drawTrendlines,se=ce("packages/modules/charts/rulecolour.js"),V=se.ruleColour,O=se.ruleLegend,X=ce("packages/modules/charts/curve.js"),oe=X.curveCommands,ue=X.resolveCurve,me=ce("packages/core/src/internal/util.js").warnOnce,we=ce("packages/modules/charts/fills.js"),Pe=we.isPaintRef,Fe=we.paintSolid,Z=we.rowFillSource,re=ce("packages/modules/charts/markers.js"),le=re.markerFor,pe=re.placeMarker,he=re.resolveMarker,Me=3.5,Ie=Object.freeze({line:{zero:!1,marks:"path"},step:{zero:!1,marks:"path"},area:{zero:!0,marks:"path"},rangeArea:{zero:!1,marks:"path"},bar:{zero:!0,marks:"rect"},horizontalBar:{zero:!0,marks:"rect",horizontal:!0},waterfall:{zero:!0,marks:"rect"},scatter:{zero:!1,marks:"circle"},bubble:{zero:!1,marks:"circle"},candlestick:{zero:!1,marks:"rect"},ohlc:{zero:!1,marks:"rect"}});function Ke(K){const Ce=[];for(let Ae=0;Ae<K.length;Ae++){const Te=K[Ae];if(Ae===0){Ce.push("M",Te.x,Te.y);continue}Ce.push("L",Te.x,K[Ae-1].y),Ce.push("L",Te.x,Te.y)}return Ce}function qe(K){const Ce=[0];if(!K)return Ce;let Ae=0;for(const Te of K.points)P(Te.y)&&Te.total!==!0&&(Ae+=Te.y,Ce.push(Ae));return Ce}const ot=Object.freeze({key:"lattice:waterfall-total"});function it(K,Ce,Ae){if(!Ce||typeof Ce!="object"||!Ce.total||!K||K.empty||!Array.isArray(K.series)||!K.series.length)return K;const Te=typeof Ce.total=="string"&&Ce.total.trim()!==""?Ce.total:Ae,Re=K.series.map(_e=>{let De=0,Je=0,ze=!1;for(const Qe of _e.points)Je+=Number.isFinite(Qe.rows)?Qe.rows:0,P(Qe.y)&&(De+=Qe.y,ze=!0);const Ue={x:ot,xKey:u(ot),label:Te,y:ze?De:null,size:null,rows:Je,rowKey:null,values:null,total:!0};return{..._e,points:[..._e.points,Ue]}});return{...K,kind:"category",series:Re,categories:[...K.categories||[],ot],labels:[...K.labels||[],Te]}}function ge(K){const Ce=K&&K.window;if(!Ce||typeof Ce!="object")return 0;const Ae=Number(Ce.span);return!Number.isFinite(Ae)||Ae<=0?0:Ce.kind!=="time"?(me("chart.axis.window.kind",`axis window kind "${Ce.kind}" is not supported on a chart axis; only { kind: "time", span } rolls the domain. Bound the row count with the source's maxRows instead.`),0):Ae}function Le(K,Ce){const Ae=K&&K.window;if(!Ae||typeof Ae!="object"||typeof Ae.now!="function")return Ce;const Te=Number(Ae.now());return Number.isFinite(Te)?Te:(me("chart.axis.window.now","axis.x.window.now did not return a time, so the rolling window is measured from this device's clock instead. It must return epoch milliseconds — the same number Date.now() returns — because that is what the x values are compared against."),Ce)}function He(K,Ce,Ae){const Te=Ae+K*Ze;let Re=Ae;for(const _e of Ce)Number.isFinite(_e)&&_e>Re&&_e<=Te&&(Re=_e);return{min:Re-K,max:Re}}const Ze=.25;function ae(K,Ce,Ae){const Te=ge(Ce);if(!Te||!K||!Array.isArray(K.categories))return null;const Re=Ie[Ae];if(!Re||Re.horizontal||K.kind==="category"||Ae==="bar"&&!Se(K,Ae,Ce))return null;const _e=K.categories.map(De=>K.kind==="time"?N(De):G(De));return{span:Te,values:_e}}function ee(K,Ce,Ae,Te){const Re=ae(K,Ce,Ae);if(!Re)return null;const _e=Re.span*Ze;let De=0,Je=0;for(const ze of Re.values)ze===null||!Number.isFinite(ze)||ze-Te<=_e||(De+=1,ze-Te>Je&&(Je=ze-Te));return De?{span:Re.span,limit:_e,count:De,lead:Je}:null}function ye(K,Ce,Ae,Te){const Re=ae(K,Ce,Ae);if(!Re)return null;const{span:_e}=Re,De=Re.values.filter(Qe=>Qe!==null&&Number.isFinite(Qe));if(!De.length)return null;const{min:Je,max:ze}=He(_e,De,Te);let Ue=-1/0;for(const Qe of De){if(Qe>=Je&&Qe<=ze)return null;Qe<Je&&Qe>Ue&&(Ue=Qe)}return Ue===-1/0?{span:_e,newest:null,age:null,points:De.length}:{span:_e,newest:Ue,age:Te-Ue,points:De.length}}function ve(K,Ce,Ae,Te){const Re=ae(K,Ce,Ae);if(!Re)return K;const{span:_e,values:De}=Re,Je=De.filter(tt=>tt!==null&&Number.isFinite(tt));if(!Je.length)return K;const{min:ze,max:Ue}=He(_e,Je,Te),Qe=[];for(let tt=0;tt<De.length;tt++){const pt=De[tt];(pt===null||!Number.isFinite(pt)||pt>=ze&&pt<=Ue)&&Qe.push(tt)}return Qe.length===De.length?K:{...K,categories:Qe.map(tt=>K.categories[tt]),labels:Array.isArray(K.labels)?Qe.map(tt=>K.labels[tt]):K.labels,series:(K.series||[]).map(tt=>({...tt,points:Array.isArray(tt.points)?Qe.map(pt=>tt.points[pt]).filter(pt=>pt!==void 0):tt.points})),windowed:De.length-Qe.length}}const be=Object.freeze({bar:.2,candlestick:.3,ohlc:.3}),Ee=.4;function $e(K){return Object.hasOwn(be,K)?be[K]:Ee}const Ge=new Set(["bar","candlestick","ohlc"]);function Ye(K){const Ce=K&&typeof K.scale=="string"?K.scale:"";return Ce==="time"||Ce==="linear"}function Se(K,Ce,Ae){if(!K||K.kind==="category")return!1;const Te=Ie[Ce];return Te&&Te.horizontal?!1:Ge.has(Ce)?Ye(Ae):!0}function Ne(K,Ce,Ae){return!Se(K,Ce,Ae)}function Ve(K){const Ce=K.filter(Re=>typeof Re=="number"&&Number.isFinite(Re)).slice().sort((Re,_e)=>Re-_e),Ae=[];for(let Re=1;Re<Ce.length;Re++){const _e=Ce[Re]-Ce[Re-1];_e>0&&Ae.push(_e)}if(!Ae.length)return 0;Ae.sort((Re,_e)=>Re-_e);const Te=Math.floor(Ae.length/2);return Ae.length%2?Ae[Te]:(Ae[Te-1]+Ae[Te])/2}function Be(K){const{bound:Ce,scale:Ae,config:Te,padding:Re}=K,_e=Te?Number(Te.barWidth):NaN,De=Number.isFinite(_e)&&_e>0,Je=(Ce.categories||[]).map(tt=>Ce.kind==="time"?N(tt):G(tt)),ze=De?_e:Ve(Je),Ue=Math.abs(Ae.range[1]-Ae.range[0]);if(!ze)return Math.max(1,Ue/20*(1-Re));const Qe=Math.abs(Ae.of(Ae.domain.min+ze)-Ae.of(Ae.domain.min));return Math.max(1,De?Qe:Qe*(1-Re))}function Oe(K,Ce,Ae,Te){if(Ne(K,Ce,Ae))return null;const Re=ge(Ae),_e=K.kind==="time"?K.categories.map(N):K.categories.map(G);if(K.kind==="time"&&!Re){const Je=y(_e);if(Je&&Je.min===Je.max)return ie({min:Je.min-3e4,max:Je.max+3e4},K,Ae)}const De=Re?He(Re,_e,Number.isFinite(Te)?Te:Le(Ae,Date.now())):d(_e,{zero:!1,nice:K.kind!=="time"});return ie(De,K,Ae)}function Xe(K,Ce,Ae,Te){const Re=[Ce.left,Ce.right];if(Ne(K,Ae,Te))return ge(Te)&&me("chart.axis.window.band","a rolling time window needs a continuous x axis; this chart bands its x values, so the window is ignored. Bind a date or numeric column to x, or put this type on a continuous axis with axis.x.scale."),b(K.categories,Re,$e(Ae));const _e=K.xDomain||Oe(K,Ae,Te);return K.kind==="time"?w(_e,Re):E(_e,Re)}function nt(K,Ce){if(K.kind==="band")return K.centre(Ce.x);const Ae=K.kind==="time"?N(Ce.x):G(Ce.x);return Ae===null?NaN:K.of(Ae)}function st(K,Ce){const Ae=K&&K.seriesStyle&&K.seriesStyle[Ce];if(Ae)return{width:Ae.width!=null?String(Ae.width):null,dash:Array.isArray(Ae.dash)&&Ae.dash.length?Ae.dash.join(" "):null,opacity:null,emphasized:!1};const Te=K&&Array.isArray(K.emphasis)?K.emphasis:null;if(!Te||!Te.length)return{width:null,dash:null,opacity:null,emphasized:!1};const Re=Te.includes(Ce);return{width:Re?"var(--lattice-chart-emphasis-width, 3.5)":null,dash:null,opacity:Re?null:"var(--lattice-chart-muted-opacity, .35)",emphasized:Re}}function ft(K){const{series:Ce,xScale:Ae,yScale:Te,baseline:Re,fill:_e,colour:De,stack:Je,style:ze}=K,Ue=[],Qe=[];let tt=[];const pt=()=>{tt.length===1?Ue.push("M",tt[0].x,tt[0].y):tt.length>1&&Ue.push(...oe(tt,K.curve||null)),tt=[]};for(let Ot=0;Ot<Ce.points.length;Ot++){const Pt=Ce.points[Ot],It=e(nt(Ae,Pt));if(!P(Pt.y)||Number.isNaN(It)){pt();continue}Qe[Ot]=!0;const zt=Pt.y,Dt=K.lower?K.lower.points[Ot]:null;if(K.lower&&!(Dt&&P(Dt.y))){pt();continue}const Mt=Je?Je.take(Ot,zt):null,Rt=e(Te.of(Mt?Mt[1]:zt)),Bt=e(Te.of(Mt?Mt[0]:Dt?Dt.y:Re));tt.push({x:It,y:Rt,base:Bt}),Pt.px=It,Pt.py=Rt,Pt.pbase=Bt}pt(),a(K.pool.next("path",`${B}__line ${B}__mark`),{d:Ue.length?n(Ue):"",stroke:De,"data-series":K.index,"stroke-width":ze?ze.width:null,"stroke-dasharray":ze?ze.dash:null,opacity:ze?ze.opacity:null});const at=!!K.marker&&!!K.markerEnv;if(at&&!_e&&ht(K,Qe),!_e){at||$t({...K,placed:Qe});return}const bt=[];let St=[];const wt=()=>{if(St.length<2){St=[];return}const Ot=oe(St,K.curve||null);Ot[0]="L",bt.push("M",St[0].x,St[0].base),bt.push(...Ot);for(let Pt=St.length-1;Pt>=0;Pt--)bt.push("L",St[Pt].x,St[Pt].base);bt.push("Z"),St=[]};for(const Ot of Ce.points){if(!P(Ot.y)||Ot.px===void 0){wt();continue}St.push({x:Ot.px,y:Ot.py,base:Ot.pbase})}wt(),a(K.pool.next("path",`${B}__area ${B}__mark`),{d:bt.length?n(bt):"",fill:De,"data-series":K.index,opacity:Pe(De)?"1":ze?ze.emphasized?"1":ze.opacity:null}),at?ht(K,Qe):$t({...K,placed:Qe})}function ht(K,Ce){const{series:Ae}=K;for(let Te=0;Te<Ae.points.length;Te++){if(!Ce[Te])continue;const Re=Ae.points[Te];We(K,Re,Te,Re.px,Re.py,Me*2,K.colour)||a(K.pool.next("circle",`${B}__point ${B}__mark`),{cx:Re.px,cy:Re.py,r:Me,fill:K.colour,"data-series":K.index,"data-point":Te})}}function $t(K){const{series:Ce,placed:Ae}=K;for(let Te=0;Te<Ce.points.length;Te++){if(!Ae[Te]||Ae[Te-1]||Ae[Te+1])continue;const Re=Ce.points[Te];a(K.pool.next("circle",`${B}__point ${B}__mark`),{cx:Re.px,cy:Re.py,r:Me,fill:K.colour,"data-series":K.index,"data-point":Te})}}function dt(K,Ce){const Ae=K&&K.range;if(!Array.isArray(Ae)||Ae.length!==2)return Ce;const[Te,Re]=Ae;return!Number.isFinite(Te)||!Number.isFinite(Re)||!Number.isFinite(Ce)?Ce:Math.min(Math.max(Te,Re),Math.max(Math.min(Te,Re),Ce))}function mt(K){const{series:Ce,xScale:Ae,yScale:Te,baseline:Re,colour:_e,stack:De,slot:Je}=K;for(let ze=0;ze<Ce.points.length;ze++){const Ue=Ce.points[ze];if(!P(Ue.y))continue;const Qe=Ae.kind==="band"?Ae.of(Ue.x):nt(Ae,Ue)-Je.span/2;if(Number.isNaN(Qe))continue;const tt=Ue.y,pt=K.pointColour&&K.pointColour(Ue,_e)||_e,at=De?De.take(ze,tt):[Re,tt],bt=dt(Te,Te.of(at[1])),St=dt(Te,Te.of(at[0])),wt=Qe+Je.offset,Ot=Ae.kind==="band"?wt:dt(Ae,wt),Pt=Ae.kind==="band"?wt+Je.width:dt(Ae,wt+Je.width),It=K.pool.next("rect",`${B}__bar ${B}__mark`,`${Ce.key}:${u(Ue.x)}`);a(It,{x:e(Ot),y:e(Math.min(bt,St)),width:e(Math.max(0,Pt-Ot)),height:e(Math.max(1,Math.abs(St-bt))),fill:pt,"data-series":K.index,"data-point":ze}),Ue.px=e(Qe+Je.offset+Je.width/2),Ue.py=e(Math.min(bt,St)),Ue.pbase=e(Math.max(bt,St))}}function At(K){const{series:Ce,xScale:Ae,yScale:Te}=K;let Re=0;for(let _e=0;_e<Ce.points.length;_e++){const De=Ce.points[_e];if(!P(De.y))continue;const Je=De.y,ze=De.total===!0,Ue=ze?0:Re,Qe=ze?Je:Re+Je;ze||(Re+=Je);const tt=dt(Te,Te.of(Math.max(Ue,Qe))),pt=dt(Te,Te.of(Math.min(Ue,Qe))),at=K.pool.next("rect",`${B}__bar ${B}__mark`,`${Ce.key}:${u(De.x)}`);a(at,{x:e(Ae.of(De.x)),y:e(tt),width:e(Ae.bandwidth),height:e(Math.max(1,pt-tt)),fill:Je>=0?K.positive:K.negative,"data-series":K.index,"data-point":_e,"data-total":ze?"true":null}),De.px=e(Ae.of(De.x)+Ae.bandwidth/2),De.py=e(tt)}}function ct(K){const{series:Ce,valueScale:Ae,baseline:Te,colour:Re,stack:_e,slot:De}=K;for(let Je=0;Je<Ce.points.length;Je++){const ze=Ce.points[Je];if(!P(ze.y))continue;const Ue=K.bandScale.of(ze.x);if(Number.isNaN(Ue))continue;const Qe=ze.y,tt=K.pointColour&&K.pointColour(ze,Re)||Re,pt=_e?_e.take(Je,Qe):[Te,Qe],at=dt(Ae,Ae.of(pt[0])),bt=dt(Ae,Ae.of(pt[1]));a(K.pool.next("rect",`${B}__bar ${B}__mark`,`${Ce.key}:${u(ze.x)}`),{x:e(Math.min(at,bt)),y:e(Ue+De.offset),width:e(Math.max(1,Math.abs(bt-at))),height:e(Math.max(0,De.width)),fill:tt,"data-series":K.index,"data-point":Je}),ze.px=e(bt),ze.py=e(Ue+De.offset+De.width/2),ze.pbase=e(at)}}function kt(K){const{series:Ce,xScale:Ae,yScale:Te,baseline:Re,colour:_e,stack:De,slot:Je}=K;for(let ze=0;ze<Ce.points.length;ze++){const Ue=Ce.points[ze];if(!P(Ue.y))continue;const Qe=Ae.kind==="band"?Ae.of(Ue.x):nt(Ae,Ue)-Je.span/2;if(Number.isNaN(Qe))continue;const tt=Ue.y,pt=K.pointColour&&K.pointColour(Ue,_e)||_e,at=De?De.take(ze,tt):[Re,tt],bt=dt(Te,Te.of(at[1])),St=dt(Te,Te.of(at[0])),wt=e(Qe+Je.offset+Je.width/2);a(K.pool.next("line",`${B}__lollipop-stem ${B}__mark`,`${Ce.key}:${u(Ue.x)}`),{x1:wt,y1:e(St),x2:wt,y2:e(bt),stroke:pt,"stroke-width":2,"data-series":K.index,"data-point":ze}),a(K.pool.next("circle",`${B}__lollipop-dot ${B}__mark`,`${Ce.key}:${u(Ue.x)}`),{cx:wt,cy:e(bt),r:4,fill:pt,"data-series":K.index,"data-point":ze}),Ue.px=wt,Ue.py=e(bt),Ue.pbase=e(St)}}function _t(K){const{series:Ce,valueScale:Ae,baseline:Te,colour:Re,stack:_e,slot:De}=K;for(let Je=0;Je<Ce.points.length;Je++){const ze=Ce.points[Je];if(!P(ze.y))continue;const Ue=K.bandScale.of(ze.x);if(Number.isNaN(Ue))continue;const Qe=ze.y,tt=K.pointColour&&K.pointColour(ze,Re)||Re,pt=_e?_e.take(Je,Qe):[Te,Qe],at=dt(Ae,Ae.of(pt[0])),bt=dt(Ae,Ae.of(pt[1])),St=e(Ue+De.offset+De.width/2);a(K.pool.next("line",`${B}__lollipop-stem ${B}__mark`,`${Ce.key}:${u(ze.x)}`),{x1:e(at),y1:St,x2:e(bt),y2:St,stroke:tt,"stroke-width":2,"data-series":K.index,"data-point":Je}),a(K.pool.next("circle",`${B}__lollipop-dot ${B}__mark`,`${Ce.key}:${u(ze.x)}`),{cx:e(bt),cy:St,r:4,fill:tt,"data-series":K.index,"data-point":Je}),ze.px=e(bt),ze.py=St,ze.pbase=e(at)}}function Lt(K){const Ce=K.group.ownerDocument;let Ae=null;for(const _e of K.group.childNodes||[])if(_e&&String(_e.getAttribute&&_e.getAttribute("class"))===`${B}__fits`){Ae=_e;break}Ae||(Ae=Ce.createElementNS(x,"g"),Ae.setAttribute("class",`${B}__fits`),K.group.appendChild(Ae));const Te=new i(Ae),Re=[];for(const _e of K.series){const De=_e.allPoints||_e.points;let Je=0,ze=0,Ue=0;for(const Dt of De){const Mt=Number(Dt.x),Rt=Number(Dt.y);!Number.isFinite(Mt)||!Number.isFinite(Rt)||(Je++,ze+=Mt,Ue+=Rt)}if(Je<2)continue;const Qe=ze/Je,tt=Ue/Je;let pt=0,at=0,bt=0,St=1/0,wt=-1/0;for(const Dt of De){const Mt=Number(Dt.x),Rt=Number(Dt.y);if(!Number.isFinite(Mt)||!Number.isFinite(Rt))continue;const Bt=Mt-Qe,Jt=Rt-tt;pt+=Bt*Bt,at+=Bt*Jt,bt+=Jt*Jt,Mt<St&&(St=Mt),Mt>wt&&(wt=Mt)}if(pt===0)continue;const Ot=at/pt,Pt=tt-Ot*Qe,It=bt===0?1:Math.max(0,Math.min(1,at*at/(pt*bt))),zt=K.scheme.series(_e.index);if(a(Te.next("path",`${B}__fit`),{d:n(["M",e(K.xScale.of(St)),e(K.yScale.of(Pt+Ot*St)),"L",e(K.xScale.of(wt)),e(K.yScale.of(Pt+Ot*wt))]),fill:"none",stroke:zt,"data-series":_e.index}),K.showR2){const Dt=Te.next("text",`${B}__fit-label`);H(Dt,K.size),a(Dt,{x:e(K.xScale.of(wt)),y:e(K.yScale.of(Pt+Ot*wt))-4,"text-anchor":"end",fill:zt}),s(Dt,K.grid.messages.t("chart.r2",{value:m(K.grid,It)}))}Re.push({key:_e.key,slope:Ot,intercept:Pt,r2:It,n:Je})}return Te.finish(),Re}function Ht(K){const Ce=K.group.ownerDocument;let Ae=null;for(const Ue of K.group.childNodes||[])if(Ue&&String(Ue.getAttribute&&Ue.getAttribute("class"))===`${B}__band`){Ae=Ue;break}Ae||(Ae=Ce.createElementNS(x,"g"),Ae.setAttribute("class",`${B}__band`),K.group.firstChild?K.group.insertBefore(Ae,K.group.firstChild):K.group.appendChild(Ae));const Te=new i(Ae),Re=K.band&&Array.isArray(K.band.points)?K.band.points:[],_e=Number.isFinite(K.index)?Number(K.index):0,De=K.scheme.series(_e),Je=Number.isFinite(K.opacity)?Number(K.opacity):.15,ze=[];for(const Ue of Re){const Qe=Number(Ue.x),tt=Number(Ue.lower),pt=Number(Ue.upper);if(!Number.isFinite(Qe)||!Number.isFinite(tt)||!Number.isFinite(pt))continue;const at=Number(Ue.yhat);ze.push({x:e(K.xScale.of(Qe)),lower:e(K.yScale.of(tt)),upper:e(K.yScale.of(pt)),yhat:Number.isFinite(at)?e(K.yScale.of(at)):null})}if(ze.length>=2&&(a(Te.next("path",`${B}__band-fill`),{d:t(ze),fill:De,"fill-opacity":Je,stroke:"none","data-series":_e}),K.line!==!1)){const Ue=[];let Qe=!1;for(const tt of ze){if(tt.yhat===null){Qe=!1;continue}Ue.push(Qe?"L":"M",tt.x,tt.yhat),Qe=!0}a(Te.next("path",`${B}__band-line`),{d:Ue.length?n(Ue):"",fill:"none",stroke:De,"data-series":_e})}return Te.finish(),{points:ze.length,confidence:K.band&&Number.isFinite(K.band.confidence)?Number(K.band.confidence):null}}function Gt(K){const Ce=K.group.ownerDocument;let Ae=null;for(const ze of K.group.childNodes||[])if(ze&&String(ze.getAttribute&&ze.getAttribute("class"))===`${B}__whiskers`){Ae=ze;break}Ae||(Ae=Ce.createElementNS(x,"g"),Ae.setAttribute("class",`${B}__whiskers`),K.group.appendChild(Ae));const Te=new i(Ae),Re=Number.isFinite(K.cap)?Number(K.cap):4,_e=K.colour||"currentColor",De=K.orient!=="v";let Je=0;for(const ze of K.points||[]){const Ue=Number(ze.main),Qe=Number(ze.lo),tt=Number(ze.hi);if(!Number.isFinite(Ue)||!Number.isFinite(Qe)||!Number.isFinite(tt))continue;const pt=De?["M",Qe,Ue,"L",tt,Ue,"M",Qe,Ue-Re,"L",Qe,Ue+Re,"M",tt,Ue-Re,"L",tt,Ue+Re]:["M",Ue,Qe,"L",Ue,tt,"M",Ue-Re,Qe,"L",Ue+Re,Qe,"M",Ue-Re,tt,"L",Ue+Re,tt];a(Te.next("path",`${B}__whisker`),{d:n(pt),stroke:_e,fill:"none"}),Je++}return Te.finish(),Je}function xt(K){const Ce=K.scheme||M(),Ae=K.typography||{small:K.fontSize||11,axisTitle:11},{bound:Te}=K,Re=qt(K.plot,Ae.small),_e=Te.series[0]&&Te.series[0].points||[],De=_e.map(at=>at.label),Je=Ce.series(0),ze=b(De,[Re.top,Re.bottom],.4),Ue=[0];for(const at of _e)for(const bt of[at.x,at.lower,at.upper])Number.isFinite(bt)&&Ue.push(bt);const Qe=E(d(Ue,{zero:!1}),[Re.left,Re.right]);Gt({group:K.groups.overlay,orient:"h",colour:Je,points:_e.map(at=>({main:e(ze.centre(at.label)),lo:e(Qe.of(at.lower)),hi:e(Qe.of(at.upper))}))});const tt=new i(K.groups.marks);let pt=0;for(const at of _e)Number.isFinite(at.x)&&(a(tt.next("circle",`${B}__point ${B}__mark`),{cx:e(Qe.of(at.x)),cy:e(ze.centre(at.label)),r:Me,fill:Je}),pt++);return tt.finish(),je({group:K.groups.rules,plot:Re,scale:Qe,lines:[{value:0}]}),fe({group:K.groups.axis,plot:Re,scale:Qe,format:r(K.grid,{kind:"linear",step:(Qe.domain.max-Qe.domain.min)/5}),config:{},grid:K.grid,size:Ae.small}),de({group:K.groups.labels,plot:Re,scale:ze,labels:De,fontSize:Ae.small,config:{}}),{series:[],marks:pt}}function qt(K,Ce){const Ae=6+Ce*1.3+2,Te=K&&K.gutter&&Number.isFinite(K.gutter.bottom)?K.gutter.bottom:Ae,Re=Math.min(Math.max(0,Ae-Te),Math.max(0,K.height-10));return Re>0?{...K,height:K.height-Re,bottom:K.bottom-Re,gutter:{...K.gutter,bottom:Te+Re}}:K}function je(K){const Ce=new i(A(K.group,`${B}__reflines`));for(const Ae of K.lines||[]){if(!P(Ae.value))continue;const Te=e(K.scale.of(Ae.value));if(a(Ce.next("path",`${B}__reference`),{d:K.vertical?n(["M",Te,e(K.plot.top),"L",Te,e(K.plot.bottom)]):n(["M",e(K.plot.left),Te,"L",e(K.plot.right),Te]),stroke:Ae.colour||"currentColor","stroke-dasharray":"4 3",fill:"none"}),!Ae.label)continue;const Re=Ce.next("text",`${B}__reference-label`);a(Re,K.vertical?{x:Te+4,y:e(K.plot.top+10),"text-anchor":"start"}:{x:e(K.plot.right-4),y:Te-4,"text-anchor":"end"}),s(Re,Ae.label)}Ce.finish()}function et(K){const{series:Ce,xScale:Ae,yScale:Te,colour:Re,plot:_e}=K,De=K.size||null;for(let Je=0;Je<Ce.points.length;Je++){const ze=Ce.points[Je];if(!P(ze.y))continue;const Ue=e(nt(Ae,ze));if(Number.isNaN(Ue))continue;const Qe=e(Te.of(ze.y));let tt=De&&P(ze.size)?e(De.of(ze.size)):Me;if(_e){const at=Math.min(Ue-_e.left,_e.right-Ue,Qe-_e.top,_e.bottom-Qe);Number.isFinite(at)&&(tt=Math.max(1,Math.min(tt,at)))}const pt=K.pointColour&&K.pointColour(ze,Re)||Re;We(K,ze,Je,Ue,Qe,tt*2,pt)||a(K.pool.next("circle",`${B}__point ${B}__mark`),{cx:Ue,cy:Qe,r:tt,fill:pt,"fill-opacity":De?.7:1,"data-series":K.index,"data-point":Je}),ze.px=Ue,ze.py=Qe}}function We(K,Ce,Ae,Te,Re,_e,De){if(!K.marker||!K.markerEnv)return!1;const Je=le(K.marker,Ce,K.markerEnv);if(Ce.markerHalf=0,!Je)return!1;const ze=K.marker.explicitSize?K.marker.size:Math.max(K.marker.size,_e);return pe(K.pool,Je,{x:Te,y:Re,size:ze,colour:Fe(De),attrs:a,round:e,extra:{"data-series":K.index,"data-point":Ae}}),Ce.markerHalf=ze/2,!0}function ut(K){const{group:Ce,series:Ae,xScale:Te,yScale:Re,options:_e}=K,De=K.grid&&K.grid.statistics,Je=De&&typeof De.intervalOf=="function"?(St,wt)=>De.intervalOf(St,wt):null,ze=new i(A(Ce,`${B}__errorbars`)),Ue=Number.isFinite(Number(_e.confidence))?Number(_e.confidence):.95,Qe=4;let tt=0,pt=0,at=0,bt=0;for(const St of Ae)for(const wt of St.points){if(wt.y===null||wt.y===void 0)continue;pt++;const Ot=Array.isArray(wt.values)&&wt.values.length===1;Ot&&at++;let Pt=null,It=null;if(_e.of!==void 0&&Number.isFinite(Number(wt[_e.of]))){const Rt=Math.abs(Number(wt[_e.of]));Pt=wt.y-Rt,It=wt.y+Rt}else if(Array.isArray(wt.values)&&wt.values.length>1&&Je){const Rt=Je(wt.values,Ue);Rt&&(Pt=Rt.lower,It=Rt.upper)}if(Pt===null||!Number.isFinite(Pt)||!Number.isFinite(It)){Ot&&bt++;continue}const zt=e(Te.of(wt.xKey!==void 0?wt.xKey:wt.x)+(Te.bandwidth?Te.bandwidth/2:0)),Dt=e(Re.of(It)),Mt=e(Re.of(Pt));a(ze.next("path",`${B}__error-bar ${B}__mark`),{d:n(["M",zt-Qe,Dt,"L",zt+Qe,Dt,"M",zt,Dt,"L",zt,Mt,"M",zt-Qe,Mt,"L",zt+Qe,Mt]),fill:"none",stroke:"currentColor","data-lower":Pt,"data-upper":It}),tt++}return ze.finish(),{drawn:tt,marks:pt,single:at,singleSkipped:bt}}function yt(K,Ce){if(Ce&&Ce.size){const _e=new Set;for(let De=0;De<K.length;De++)K[De].rowKey!=null&&Ce.has(String(K[De].rowKey))&&_e.add(De);return _e}const Ae=5,Te=_e=>[...K.keys()].filter(De=>Number.isFinite(_e(K[De]))).sort((De,Je)=>_e(K[Je])-_e(K[De])).slice(0,Ae),Re=new Set(Te(_e=>Math.abs(Number(_e.y))));for(const _e of Te(De=>Number(De.x)))Re.add(_e);if(K.some(_e=>P(_e.size)))for(const _e of Te(De=>P(De.size)?Number(De.size):-1/0))Re.add(_e);return Re}function Et(K){const Ce=K.scheme||M(),Ae=K.axis||{x:{},y:{},y2:{}},Te=K.typography||{small:K.fontSize||11,axisTitle:11},{bound:Re,plot:_e,type:De}=K,Je=Ie[De]||Ie.line,ze=Re.series.filter(lt=>!K.hidden.has(lt.key)),Ue=!!Je.horizontal,Qe=K.mark==="lollipop"&&(De==="bar"||De==="horizontalBar"),tt=!Ue&&Ae.y.position==="right"?"right":"left",pt=tt==="right"?"left":"right",at=(De==="bar"||De==="horizontalBar")&&K.byRuleColour&&ze.length===1&&Re.measure&&Re.measure.col||null,bt=at?new Set:null,St=at?lt=>{const vt=V({grid:K.grid,col:at,value:lt.y});return vt&&bt.add(vt),vt}:null,Ot=(De==="bar"||De==="horizontalBar")&&K.byRuleColour&&ze.length===1&&Ce.nameMap?lt=>Ce.series(0,lt.label):null,Pt=K.fill?Z(K,Ce):null,It=Pt||St||Ot?(lt,vt)=>Pt&&Pt(lt,vt)||St&&St(lt)||Ot&&Ot(lt)||null:null,zt=he(K.marker),Dt=zt?{grid:K.grid,doc:K.doc,redraw:K.redraw}:null,Mt=!Ue&&De!=="waterfall"?ze.filter(lt=>lt.axis==="right"):[],Rt=Mt.length?ze.filter(lt=>lt.axis!=="right"):ze,Bt=Mt.length>0,Jt=(De==="bar"||De==="area"||De==="horizontalBar")&&!Bt,Qt=K.stack==="percent"&&Jt&&Rt.length>1,tn=(Qt||!!K.stack)&&Rt.length>1&&Jt,jn=De==="waterfall"?qe(ze[0]):C(Rt,tn,Qt),Yt=Re.yDomain||K.domain||d(jn,{zero:Je.zero,min:Ae.y.min,max:Ae.y.max}),Ut=Ue?E(Yt,[_e.left,_e.right]):E(Yt,[_e.bottom,_e.top]),jt=Ue?b(Re.categories,[_e.top,_e.bottom],.2):Xe(Re,_e,De,Ae.x),cn=Yt.min<=0&&Yt.max>=0?0:Yt.min,En=Mt.some(lt=>(lt.mark||(De==="bar"?"bar":De))==="bar"),Zt=Bt?d(C(Mt,!1,!1),{zero:En,min:Ae.y2.min,max:Ae.y2.max}):null,Vt=Zt?E(Zt,[_e.bottom,_e.top]):null,un=r(K.grid,{kind:"linear",step:(Yt.max-Yt.min)/5}),dn=Qt?{tick:lt=>`${un.tick(lt)}%`,value:lt=>`${un.value(lt)}%`}:un,rn=K.axes!==!1,Kt={left:0,right:0,bottom:0};if(De==="scatter"||De==="bubble")for(const lt of ze)for(const vt of lt.points){if(!P(vt.y))continue;const Ct=nt(jt,vt),Ft=Ut.of(vt.y);if(!Number.isFinite(Ct)||!Number.isFinite(Ft))continue;const Tt=(K.sizes&&P(vt.size)?K.sizes.of(vt.size):Me)+2;Kt.left=Math.max(Kt.left,Tt-(Ct-_e.left)),Kt.right=Math.max(Kt.right,Tt-(_e.right-Ct)),Kt.bottom=Math.max(Kt.bottom,Tt-(_e.bottom-Ft))}const Nn=!Ue&&jt.kind==="band"&&(Ae.x.rotate===void 0||Ae.x.rotate==="auto"?v(Re.labels,jt.step,Te.small,Ae.x.every):!!Ae.x.rotate)&&L({group:K.groups.overlay,plot:_e,scale:jt,labels:Re.labels,fontSize:Te.small,config:Ae.x});if(rn&&J({gridGroup:K.groups.grid,axisGroup:K.groups.axis,plot:_e,scale:Ut,format:dn,horizontal:Ue,side:tt,config:Ae.y,grid:K.grid,size:Te.small,overhang:tt==="right"?Kt.right:Kt.left,dropBottom:Nn}),rn)if(Ue)de({group:K.groups.overlay,plot:_e,scale:jt,labels:Re.labels,fontSize:Te.small,config:Ae.x});else if(jt.kind==="band")z({group:K.groups.overlay,plot:_e,scale:jt,labels:Re.labels,fontSize:Te.small,rotated:v(Re.labels,jt.step,Te.small,Ae.x.every),config:Ae.x});else{const lt=Re.dimension&&Re.dimension.col?K.grid.columns.get(Re.dimension.col):void 0;fe({group:K.groups.overlay,plot:_e,scale:jt,format:r(K.grid,{kind:Re.kind,span:jt.domain.max-jt.domain.min,step:(jt.domain.max-jt.domain.min)/5},lt),config:Ae.x,grid:K.grid,column:lt,size:Te.small,overhang:Kt.bottom})}if(rn&&(F({group:K.groups.rules,plot:_e,side:tt}),l({group:K.groups.axis,plot:_e,text:Ae.y.title,side:Ue?"bottom":tt,size:Te.axisTitle}),l({group:K.groups.axis,plot:_e,text:Ae.x.title,side:Ue?"left":"bottom",size:Te.axisTitle})),rn&&Vt){g({group:K.groups.axis,plot:_e,scale:Vt,colour:Ce.series(Mt[0].index),side:pt,format:r(K.grid,{kind:"linear",step:(Zt.max-Zt.min)/5})});const lt=Ae.y2.title||(Mt.length===1?Mt[0].label:"");l({group:K.groups.axis,plot:_e,text:lt,side:pt,size:Te.axisTitle}),!Ae.y.title&&Rt.length===1&&Rt[0].label&&l({group:K.groups.axis,plot:_e,text:Rt[0].label,side:tt,size:Te.axisTitle})}const hn=Number.isFinite(K.downsampleTo)?Number(K.downsampleTo):Math.max(2,Math.round(_e.width));let bn=!1;if(Je.marks==="path"||De==="scatter"||De==="bubble"){for(const lt of ze)if(lt.kept=null,lt.allPoints=lt.points,lt.points.length>hn*1.5){const vt=lt.points.map((Ft,Tt)=>({x:Tt,y:Ft.y,point:Ft})),Ct=ne(vt,hn);if(K.keepInfluential){const Ft=new Set(Ct.map(Tt=>Tt.x));for(const Tt of yt(lt.points,K.keepRows))Ft.has(Tt)||(Ct.push({x:Tt,y:lt.points[Tt].y,point:lt.points[Tt]}),Ft.add(Tt));Ct.sort((Tt,mn)=>Tt.x-mn.x)}lt.points=Ct.map(Ft=>Ft.point),lt.kept=Ct.map(Ft=>Ft.x),bn=!0}}K.pool||W(K.groups,_e,Q(De));const Xt=K.pool||new i(K.groups.marks),yn=Qt?Re.categories.map((lt,vt)=>ze.reduce((Ct,Ft)=>{const Tt=Ft.points[vt]?Ft.points[vt].y:null;return P(Tt)?Ct+Math.abs(Tt):Ct},0)):null,fn=tn?h(Re.categories.length,yn):null,pn=Bt?ze.filter(lt=>(lt.mark||(De==="bar"?"bar":De))==="bar"):ze,Mn=Bt?Math.max(1,pn.length):Math.max(1,ze.length),Cn=De==="bar"||Bt&&pn.length>0,on=jt.kind==="band"?jt.bandwidth:Cn?Be({bound:Re,scale:jt,config:Ae.x,padding:$e("bar")}):0,sn=tn?on:on/Mn,an=new Map;for(const lt of pn)an.set(lt.key,an.size);const wn=[],ln=De==="rangeArea"&&Re.series.length>=2?Re.series[0]:null,vn=ln?Re.series[1]:null;for(let lt=0;lt<ze.length;lt++){const vt=ze[lt],Ct=Ce.series(vt.index,vt.label),Ft=vt.axis==="right"&&Vt?Vt:Ut,Tt=Bt?vt.mark||(De==="bar"?"bar":De):De,mn=Bt&&an.has(vt.key)?an.get(vt.key):lt;if(De==="horizontalBar")(Qe?_t:ct)({pool:Xt,series:vt,bandScale:jt,valueScale:Ut,baseline:cn,colour:Ct,stack:fn,index:vt.index,slot:{offset:tn?0:lt*sn,width:sn,span:on},pointColour:It});else if(De==="waterfall")At({pool:Xt,series:vt,xScale:jt,yScale:Ut,index:vt.index,positive:Ce.positive,negative:Ce.negative});else if(Tt==="bar")(Qe?kt:mt)({pool:Xt,series:vt,xScale:jt,yScale:Ft,baseline:Ft===Vt?Zt.min<=0&&Zt.max>=0?0:Zt.min:cn,colour:Ct,stack:fn,index:vt.index,slot:{offset:tn?0:mn*sn,width:sn,span:on},pointColour:It});else if(De==="scatter"||De==="bubble")et({pool:Xt,series:vt,xScale:jt,yScale:Ft,colour:Ct,index:vt.index,size:De==="bubble"?K.sizes:null,pointColour:It,marker:zt,markerEnv:Dt,plot:_e});else{const xn=st(K,vt.label),_n=Tt==="step"?{type:"step",tension:1,mode:"after"}:ue(K.curve,vt.label),Sn={pool:Xt,series:vt,xScale:jt,yScale:Ft,baseline:cn,fill:ln?vt===vn:Tt==="area"||Tt==="rangeArea",lower:ln&&vt===vn?ln:null,curve:_n,colour:Ct,stack:fn,index:vt.index,style:xn,marker:zt,markerEnv:Dt};xn.emphasized?wn.push(Sn):ft(Sn)}}for(const lt of wn)ft(lt);K.pool||Xt.finish(),K.band&&typeof jt.invert=="function"&&Ht({group:K.groups.overlay,band:K.band,xScale:jt,yScale:Ut,scheme:Ce,index:0,line:K.band.line!==!1&&!K.fit}),K.fit&&(De==="scatter"||De==="bubble")&&typeof jt.invert=="function"&&Lt({group:K.groups.overlay,series:ze,xScale:jt,yScale:Ut,plot:_e,scheme:Ce,grid:K.grid,size:Te.small,showR2:K.fit!=="line"});let nn=null;K.trend&&(nn=p({group:K.groups.overlay,series:ze,xScale:jt,yScale:Ut,rightScale:Vt,plot:_e,scheme:Ce,trend:K.trend,grid:K.grid,format:lt=>dn.tick(lt),size:Te.small,clip:K.groups.boxClipId}));let kn=null;if(K.error&&(kn=ut({group:K.groups.overlay,series:ze,xScale:jt,yScale:Ut,grid:K.grid,options:K.error===!0?{}:K.error})),K.labels&&K.labels.show&&te({group:K.groups.labels,series:ze,plot:_e,options:K.labels,grid:K.grid,size:Te.small,horizontal:Ue}),K.reference&&K.reference.length){const lt=Ue?K.reference:K.reference.filter(Ct=>!(Ct.axis==="right"||Ct.axis==="y2")),vt=Vt?K.reference.filter(Ct=>Ct.axis==="right"||Ct.axis==="y2"):[];lt.length&&je({group:K.groups.overlay,plot:_e,scale:Ut,lines:lt,vertical:Ue}),vt.length&&je({group:K.groups.overlay,plot:_e,scale:Vt,lines:vt})}let gn=null;K.annotations&&K.annotations.length&&(gn=j({group:K.groups.overlay,plot:_e,xScale:jt,yScale:Ut,rightScale:Vt,series:ze,annotations:K.annotations,dual:Bt,horizontal:Ue,format:lt=>dn.tick(lt),size:Te.small}));const Tn=Array.isArray(nn)&&nn.length?[...gn||[],...nn]:gn;return{xScale:jt,yScale:Ut,rightScale:Vt,dual:Bt,series:ze,horizontal:Ue,percent:Qt,percentTotals:Qt?yn:null,plot:_e,errorBars:kn,annotations:Tn,trendlines:nn,reduced:bn,legend:at?O({grid:K.grid,col:at,colours:bt}):null}}const gt=32;function Nt(K){const{series:Ce,xScale:Ae,at:Te}=K,Re=Number.isFinite(K.tolerance)?Number(K.tolerance):gt,_e=[];let De=-1,Je=1/0;for(const ze of Ce){let Ue=null,Qe=-1,tt=1/0;const pt=ze.points||[];for(let at=0;at<pt.length;at++){const bt=pt[at];if(!bt||!P(bt.y))continue;const St=nt(Ae,bt);if(Number.isNaN(St))continue;const wt=Math.abs(St-Te);wt>=tt||(tt=wt,Ue=bt,Qe=Array.isArray(ze.kept)?ze.kept[at]:at)}!Ue||tt>Re||(_e.push({series:ze,point:Ue}),tt<Je&&(Je=tt,De=Qe))}return De<0?null:{index:De,entries:_e}}function Wt(K){const{bound:Ce,xScale:Ae,at:Te}=K;if(!Ce.categories.length)return-1;if(Ae.kind==="band"){const De=Math.floor((Te-Ae.range[0])/(Ae.step||1));return De>=0&&De<Ce.categories.length?De:-1}let Re=-1,_e=1/0;for(let De=0;De<Ce.categories.length;De++){const Je=Ae.kind==="time"?N(Ce.categories[De]):G(Ce.categories[De]);if(Je===null)continue;const ze=Math.abs(Ae.of(Je)-Te);ze<_e&&(_e=ze,Re=De)}return Re}function en(K,Ce){return Ce<0||Ce>=K.categories.length?"":u(K.categories[Ce])}}),rt("packages/core/src/source/filterwire.js",function(o,ce){"use strict";Object.defineProperty(o,"HOST_FILTER_WARN_ID",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"WHERE_PAGE_RELATIVE_WARN_ID",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"warnWherePageRelative",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"warnHostFilterNotApplied",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"WHERE_NOT_APPLIED_WARN_ID",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"warnWhereNotApplied",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"WHERE_OVER_THRESHOLD_WARN_ID",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"warnWhereOverThreshold",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"RELATIVE_TOKENS",{enumerable:!0,get:function(){return c}}),Object.defineProperty(o,"parseRelativeToken",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"resolveRelativeRange",{enumerable:!0,get:function(){return y}}),Object.defineProperty(o,"relativeTokenOf",{enumerable:!0,get:function(){return P}}),Object.defineProperty(o,"relativeTokenHelp",{enumerable:!0,get:function(){return u}}),Object.defineProperty(o,"isResolvableRelative",{enumerable:!0,get:function(){return E}}),Object.defineProperty(o,"resolveRelativeCondition",{enumerable:!0,get:function(){return d}}),Object.defineProperty(o,"isGroup",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"forEachCondition",{enumerable:!0,get:function(){return G}}),Object.defineProperty(o,"mapConditions",{enumerable:!0,get:function(){return N}}),Object.defineProperty(o,"normaliseFilterSet",{enumerable:!0,get:function(){return C}}),Object.defineProperty(o,"buildFilterSet",{enumerable:!0,get:function(){return h}}),Object.defineProperty(o,"wireFilters",{enumerable:!0,get:function(){return $}}),Object.defineProperty(o,"querySignature",{enumerable:!0,get:function(){return a}});const F=ce("packages/core/src/internal/util.js").warnOnce,l="source.remote.hostFilter",de="source.where.pageRelative";function z(e,s){!Array.isArray(e)||!e.length||F(de,`filters.where (${e.join(", ")}) runs over the rows the ${s} source fetched,`,"not the whole dataset: match counts and totals are page-relative.","Give the predicate a { condition } twin so the engine can narrow the fetch itself.")}function fe(e){const s=(e||{}).config;!s||!s.hostFilter||F(l,"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 J="source.where.notApplied";function Q(e,s){F(`${J}:${e}`,`filters.where("${e}") is registered but the ${s} source holds only its fetched window`,"and cannot run the predicate over it: the predicate is not applied there, and rows it would","exclude stay on screen.","Give it a { condition } twin so the engine can narrow the fetch itself — that is the","supported route for a paged or remote source.")}const ie="source.where.overThreshold";function W(e,s,x,S){!Array.isArray(e)||!e.length||F(`${ie}:${s}`,`filters.where (${e.join(", ")}) is not applied to the ${s} pushdown source:`,x===null?"the adapter reports no row total, so the size of the matching set is unknown.":`its matching set is ${x.toLocaleString()} rows, at or past the whereRowLimit of ${S.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 _(e){let s=L.get(e);return s||(s=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),L.set(e,s)),s}function i(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function v(e,s){const x=_(s).formatToParts(new Date(e)),S={y:1970,m:1,d:1,h:0,mi:0,s:0};for(const B of x)B.type==="year"?S.y=+B.value:B.type==="month"?S.m=+B.value:B.type==="day"?S.d=+B.value:B.type==="hour"?S.h=+B.value%24:B.type==="minute"?S.mi=+B.value:B.type==="second"&&(S.s=+B.value);return S}function k(e,s){const x=v(e,s);return Date.UTC(x.y,x.m-1,x.d,x.h,x.mi,x.s)-Math.floor(e/1e3)*1e3}function r(e,s,x,S){const B=Date.UTC(e,s-1,x),Y=B-k(B,S);return B-k(Y,S)}function m(e,s,x){const S=new Date(Date.UTC(e.y,e.m-1,e.d+s));return r(S.getUTCFullYear(),S.getUTCMonth()+1,S.getUTCDate(),x)}const c=Object.freeze(["today","yesterday","lastNDays","thisWeek","thisMonth","thisQuarter","thisYear","quarterToDate","yearToDate"]);function b(e,s){if(typeof e!="string")return null;const x=e.trim().toLowerCase().replace(/[\s_-]+/g,""),S=/^last(\d*|n)days?$/.exec(x);if(S){const B=S[1]==="n"?"":S[1],Y=Number(B||s);return!Number.isFinite(Y)||Y<=0?null:{kind:"lastNDays",n:Math.floor(Y)}}switch(x){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 y(e,s={}){const x=b(e,s.n);if(!x)return null;const S=s.tz||i(),B=s.now instanceof Date?s.now.getTime():typeof s.now=="number"?s.now:Date.now(),Y=v(B,S),te=r(Y.y,Y.m,Y.d,S),q=m(Y,1,S);let ne=te,U=q;switch(x.kind){case"today":break;case"yesterday":ne=m(Y,-1,S),U=te;break;case"lastNDays":U=s.includeToday?q:te,ne=m(Y,s.includeToday?-(x.n-1):-x.n,S);break;case"thisWeek":{const M=Number.isFinite(s.weekStartsOn)?Number(s.weekStartsOn):1,H=(new Date(Date.UTC(Y.y,Y.m-1,Y.d)).getUTCDay()-M+7)%7;ne=m(Y,-H,S),U=m(Y,-H+7,S);break}case"thisMonth":ne=r(Y.y,Y.m,1,S),U=r(Y.m===12?Y.y+1:Y.y,Y.m===12?1:Y.m+1,1,S);break;case"thisQuarter":case"quarterToDate":{const M=Math.floor((Y.m-1)/3)*3+1;ne=r(Y.y,M,1,S),U=x.kind==="quarterToDate"?q:M===10?r(Y.y+1,1,1,S):r(Y.y,M+3,1,S);break}case"thisYear":case"yearToDate":ne=r(Y.y,1,1,S),U=x.kind==="yearToDate"?q:r(Y.y+1,1,1,S);break;default:return null}return{from:new Date(ne).toISOString(),to:new Date(U).toISOString(),bounds:"[)",tz:S,relative:x.kind==="lastNDays"?`last${x.n}Days`:x.kind,n:x.n}}function P(e){if(!e||typeof e!="object")return null;const s=e.value;if(s&&typeof s=="object"&&!Array.isArray(s)&&"relative"in s)return{token:String(s.relative),n:typeof s.n=="number"?s.n:void 0};if(e.op==="relative"&&typeof e.value=="string")return{token:e.value,n:void 0};const x=e.meta;return x&&typeof x.relative=="string"&&e.value===void 0?{token:x.relative,n:typeof x.n=="number"?x.n:void 0}:null}function u(){return`Known tokens: ${c.filter(s=>s!=="lastNDays").join(", ")}. "lastNDays" needs a count: pass "last7Days", or the value object { relative: 'lastNDays', n: 7 }.`}function E(e){const s=P(e);return s?b(s.token,s.n)!==null:!1}function d(e,s={}){const x=P(e);if(!x)return e;const S=y(x.token,{...s,n:x.n});return S?{...e,type:e.type||"date",op:"between",value:[S.from,S.to],bounds:e.bounds||S.bounds,meta:{...e.meta||{},relative:S.relative,tz:S.tz}}:(F(`source.relative.${x.token}`,`unknown relative date token "${x.token}"; sending the condition unresolved.`,u()),e)}function w(e){return!!e&&typeof e=="object"&&Array.isArray(e.conditions)}function G(e,s){if(e){if(w(e)){for(const x of e.conditions)G(x,s);return}s(e)}}function N(e,s){if(!e)return null;if(!w(e))return s(e);const x=e;let S=!1;const B=[];for(const Y of x.conditions){const te=N(Y,s);te!==Y&&(S=!0),te&&B.push(te)}return!S&&B.length===x.conditions.length?e:B.length?{...x,conditions:B}:null}function T(e){if(!e)return null;if(!w(e))return e;const s=e,x=[];for(const S of s.conditions){const B=T(S);B&&x.push(B)}return x.length?{op:s.op,conditions:x}:null}function C(e){const s=T(e);return s?w(s)&&s.op==="and"?s:{op:"and",conditions:[s]}:null}function h(e){const s=(e||[]).filter(Boolean);return s.length?{op:"and",conditions:s}:null}function $(e,s={}){const x=N(e,S=>d(S,s));return C(x)}function a(e){const s=n(e.filters??null);return JSON.stringify([s,e.sort??null,e.quick??"",e.groupBy??null,e.pivotBy??null,t(e.context)])}function n(e){if(!e)return null;if(w(e)){const S=e;return{op:S.op,conditions:S.conditions.map(n)}}const s=e,x=s.meta&&typeof s.meta.relative=="string"?s.meta.relative:P(s)?.token;return{col:s.col,op:s.op,bounds:s.bounds??null,caseSensitive:s.caseSensitive??!1,value:x?`rel:${x}`:s.value??null}}function t(e){if(e==null)return null;try{return JSON.parse(JSON.stringify(e))}catch{return F("source.context.unserialisable","config.context is not JSON-serialisable; cache keys ignore it."),"[unserialisable]"}}}),rt("packages/core/src/source/aggregates.js",function(o,ce){"use strict";Object.defineProperty(o,"STAT_PUSHDOWN",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(o,"pushableAggregates",{enumerable:!0,get:function(){return F}}),Object.defineProperty(o,"fillAggregateSql",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"resolveAggregatesConfig",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"routeAggregate",{enumerable:!0,get:function(){return z}}),Object.defineProperty(o,"resolveAggregatePlan",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"groupKeysPushable",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"pushdownDocRows",{enumerable:!0,get:function(){return ie}});const ke=Object.freeze({sum:{pushable:!0,class:"identical",sql:"sum(%c)"},avg:{pushable:!0,class:"identical",sql:"avg(%c)"},min:{pushable:!0,class:"identical",sql:"min(%c)"},max:{pushable:!0,class:"identical",sql:"max(%c)"},count:{pushable:!0,class:"identical",sql:"count(*)"},countValues:{pushable:!0,class:"identical",sql:"count(%c)",blankAware:!0},range:{pushable:!0,class:"identical",sql:"(max(%c) - min(%c))"},variance:{pushable:!0,class:"identical",sql:"var_samp(%c)"},varianceP:{pushable:!0,class:"identical",sql:"var_pop(%c)"},stddev:{pushable:!0,class:"identical",sql:"stddev_samp(%c)"},stddevP:{pushable:!0,class:"identical",sql:"stddev_pop(%c)"},sumSquares:{pushable:!0,class:"identical",sql:"sum(%c * %c)"},median:{pushable:!0,class:"identical",sql:"median(%c)"},p25:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.25)"},p75:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.75)"},p90:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.9)"},p95:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.95)"},p99:{pushable:!0,class:"identical",sql:"quantile_cont(%c, 0.99)"},iqr:{pushable:!0,class:"identical",sql:"(quantile_cont(%c, 0.75) - quantile_cont(%c, 0.25))"},mad:{pushable:!0,class:"identical",sql:"mad(%c)"},distinct:{pushable:!0,class:"identical",sql:"count(DISTINCT %c)",blankAware:!0},skewness:{pushable:!0,class:"identical",sql:"skewness(%c)"},kurtosis:{pushable:!0,class:"identical",sql:"kurtosis(%c)"},geomean:{pushable:!0,class:"identical",sql:"exp(avg(ln(%c)))"},harmean:{pushable:!0,class:"identical",sql:"(count(%c) / sum(1.0 / %c))"},entropy:{pushable:!0,class:"identical",sql:"entropy(%c)",blankAware:!0},correlation:{pushable:!0,class:"identical",sql:"corr(%w, %c)",twoColumn:!0},hhi:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_transform(map_values(histogram(%c)), lambda v: (v::DOUBLE/count(%c))*(v::DOUBLE/count(%c)))) END"},evenness:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL WHEN count(DISTINCT %c)<2 THEN 1.0 ELSE entropy(%c)/log2(count(DISTINCT %c)) END"},top3Share:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_slice(list_sort(map_values(histogram(%c)),'DESC'),1,3))::DOUBLE/count(%c) END"},top10Share:{pushable:!0,class:"identical",blankAware:!0,sql:"CASE WHEN count(%c)=0 THEN NULL ELSE list_sum(list_slice(list_sort(map_values(histogram(%c)),'DESC'),1,10))::DOUBLE/count(%c) END"},gini:{pushable:!0,class:"identical",sql:"CASE WHEN list_min(list(%c) FILTER (WHERE isfinite(%c)))<0 THEN NULL WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL WHEN list_sum(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN 0 ELSE 2.0*list_sum(list_transform(list_sort(list(%c) FILTER (WHERE isfinite(%c))), lambda v, i: i*v))/(len(list(%c) FILTER (WHERE isfinite(%c)))*list_sum(list(%c) FILTER (WHERE isfinite(%c))))-(len(list(%c) FILTER (WHERE isfinite(%c)))+1.0)/len(list(%c) FILTER (WHERE isfinite(%c))) END"},trimmedMean:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL ELSE list_avg(list_slice(list_sort(list(%c) FILTER (WHERE isfinite(%c))), floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT+1, len(list(%c) FILTER (WHERE isfinite(%c)))-floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT)) END"},winsorizedMean:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))=0 THEN NULL ELSE list_avg(list_transform(list_sort(list(%c) FILTER (WHERE isfinite(%c))), lambda v: least(list_sort(list(%c) FILTER (WHERE isfinite(%c)))[len(list(%c) FILTER (WHERE isfinite(%c)))-floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT], greatest(list_sort(list(%c) FILTER (WHERE isfinite(%c)))[floor(len(list(%c) FILTER (WHERE isfinite(%c)))*0.1)::BIGINT+1], v)))) END"},robustOutliers:{pushable:!0,class:"identical",sql:"(SELECT CASE WHEN len(d.a)=0 THEN NULL WHEN d.mad=0 THEN NULL ELSE len(list_filter(d.a, lambda v: abs(0.6745*(v-d.med)/d.mad)>3.5)) END FROM (SELECT xs AS a, list_median(xs) AS med, list_median(list_transform(xs, lambda w: abs(w-list_median(xs)))) AS mad FROM (SELECT list(%c) FILTER (WHERE isfinite(%c)) AS xs)) d)"},jarqueBera:{pushable:!0,class:"identical",sql:"CASE WHEN len(list(%c) FILTER (WHERE isfinite(%c)))<8 THEN NULL WHEN list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2)))=0 THEN NULL ELSE (len(list(%c) FILTER (WHERE isfinite(%c)))/6.0)*(power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),3)))/power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2))),1.5),2)+power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),4)))/power(list_avg(list_transform(list(%c) FILTER (WHERE isfinite(%c)), lambda v: power(v-list_avg(list(%c) FILTER (WHERE isfinite(%c))),2))),2)-3,2)/4.0) END"},weightedAvg:{pushable:!0,class:"identical",twoColumn:!0,sql:"sum(%c*%w) FILTER (WHERE isfinite(%c) AND isfinite(%w))/nullif(sum(%w) FILTER (WHERE isfinite(%c) AND isfinite(%w)),0)"},mode:{pushable:!0,class:"may-differ",sql:"mode(%c)",note:"DuckDB returns a modal value even for an all-distinct column; the grid returns null. Tie-breaking can also differ, and on a text column an empty string counts as a value. Under pushdown you will see a value."},weightedQuantile:{pushable:!1,class:"fallback",note:"No SQL equivalent for the grid's weighted-quantile midpoint convention; always computed client-side (needs a full-dataset pull for a correct figure over a remote source)."}});function F(){const W=new Set;for(const[L,_]of Object.entries(ke))_.pushable&&W.add(L);return W}function l(W,L,_){let i=W.split("%c").join(L);return _!==void 0&&(i=i.split("%w").join(_)),i}function de(W){const L=W||{},_=L.default==="engine"||L.default==="engine-if-identical"?L.default:"client",i={};if(L.overrides&&typeof L.overrides=="object")for(const[v,k]of Object.entries(L.overrides))(k==="engine"||k==="client")&&(i[v]=k);return{default:_,overrides:i}}function z(W,L){const _=ke[W];if(!_||!_.pushable)return"client";const i=L.overrides[W];return i==="engine"||i==="client"?i:L.default==="client"?"client":L.default==="engine-if-identical"?_.class==="identical"?"engine":"client":"engine"}function fe(W,L){const _=de(L),i=[],v=[];for(const k of W||[]){const r=ke[k.fn],m=z(k.fn,_),c={id:k.id,col:k.col,fn:k.fn,class:r?r.class:"fallback"};k.weight!==void 0&&(c.weight=k.weight),k.params!==void 0&&(c.params=k.params),m==="engine"?i.push(c):(c.reason=r&&!r.pushable?r.note||"the engine cannot express this stat":"client by config",v.push(c))}return{engine:i,client:v,config:_}}const J=/^[A-Za-z_][A-Za-z0-9_$]*$/;function Q(W,L=[]){return(W||[]).every(i=>{if(typeof i=="string")return J.test(i);if(!i||typeof i!="object")return!1;const v=i;return Array.isArray(L)&&L.includes(v.bucket)&&typeof v.col=="string"&&J.test(v.col)&&typeof v.size=="number"&&Number.isFinite(v.size)&&v.size>0})}function ie(){return Object.entries(ke).map(([W,L])=>({stat:W,class:L.class,sql:L.sql?l(L.sql,"col",L.twoColumn?"weight":void 0):"",note:L.note||(L.class==="identical"?"Pushes to DuckDB with the same result.":"")}))}}),rt("packages/core/src/source/abort.js",function(o,ce){"use strict";Object.defineProperty(o,"SupersededError",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(o,"RequestToken",{enumerable:!0,get:function(){return F}}),Object.defineProperty(o,"AbortScope",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"createAbortScope",{enumerable:!0,get:function(){return de}}),Object.defineProperty(o,"isAbortError",{enumerable:!0,get:function(){return z}});class ke extends Error{constructor(J,Q="superseded"){super(`[lattice] request ${J?`"${J}" `:""}${Q}`),this.name="SupersededError",this.superseded=!0,this.key=J}}class F{#e;constructor(J,Q,ie,W){this.#e=J,this.key=Q,this.controller=ie,this.signal=ie.signal,this.seq=W}get current(){return!this.signal.aborted&&this.#e.tokenFor(this.key)===this}settle(){this.#e.settle(this)}abort(J){this.signal.aborted||this.controller.abort(new ke(this.key,J)),this.#e.settle(this)}}class l{#e=new Map;#t=0;begin(J="",Q="superseded"){const ie=this.#e.get(J);ie&&!ie.signal.aborted&&ie.controller.abort(new ke(J,Q));const W=new F(this,J,new AbortController,++this.#t);return this.#e.set(J,W),W}tokenFor(J){return this.#e.get(J)}pending(J=""){const Q=this.#e.get(J);return!!Q&&!Q.signal.aborted}get size(){return this.#e.size}settle(J){this.#e.get(J.key)===J&&this.#e.delete(J.key)}abort(J="",Q="superseded"){const ie=this.#e.get(J);ie&&ie.abort(Q)}abortAll(J="superseded"){for(const Q of[...this.#e.values()])Q.abort(J);this.#e.clear()}}function de(){return new l}function z(fe){if(!fe||typeof fe!="object")return!1;const J=fe;return J.superseded===!0||J.name==="AbortError"||J.name==="SupersededError"}}),rt("packages/core/src/source/pushdown.js",function(o,ce){"use strict";Object.defineProperty(o,"FOREGROUND_WAIT_MS",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"NO_CAPABILITIES",{enumerable:!0,get:function(){return c}}),Object.defineProperty(o,"resolveMutate",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"capabilitiesOf",{enumerable:!0,get:function(){return u}}),Object.defineProperty(o,"splitFilters",{enumerable:!0,get:function(){return d}}),Object.defineProperty(o,"LEAF_COUNT_ID",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"PIVOT_UNSUPPORTED",{enumerable:!0,get:function(){return C}}),Object.defineProperty(o,"GROUP_UNSUPPORTED",{enumerable:!0,get:function(){return h}}),Object.defineProperty(o,"UNGROUPED_LEVEL",{enumerable:!0,get:function(){return $}}),Object.defineProperty(o,"planQuery",{enumerable:!0,get:function(){return n}}),Object.defineProperty(o,"applyResidual",{enumerable:!0,get:function(){return s}}),Object.defineProperty(o,"DEFAULT_WHERE_ROW_LIMIT",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(o,"createPushdownSource",{enumerable:!0,get:function(){return U}});const ke=ce("packages/core/src/internal/util.js"),F=ke.defaultCompare,l=ke.isFunction,de=ke.toArray,z=ke.warnOnce,fe=ce("packages/core/src/source/filterwire.js"),J=fe.isGroup,Q=fe.warnWherePageRelative,ie=fe.warnWhereOverThreshold,W=ce("packages/core/src/source/aggregates.js"),L=W.resolveAggregatePlan,_=W.groupKeysPushable,i=W.STAT_PUSHDOWN,k=ce("packages/core/src/source/abort.js").SupersededError,r=1e3;function m(M){const R=M&&M.signal;if(!R||!R.aborted)return;const H=R.reason;throw H instanceof Error?H:new k("","superseded before it was sent")}const c=Object.freeze({filter:!1,operators:Object.freeze([]),sort:!1,quick:!1,range:!1,total:!1,group:!1,pivot:!1,mutate:!1});function b(M){if(!M||typeof M!="object")return!1;const R=M.returning==="row"||M.returning==="key"?M.returning:"none";return{append:M.append===!0,update:M.update===!0,delete:M.delete===!0,returning:R}}function y(M,R){if(!M||typeof R!="string")return;if(!R.includes("."))return M[R];let H=M;for(const f of R.split(".")){if(H===null||typeof H!="object")return;H=H[f]}return H}function P(M){if(M===!0)return!0;if(!M||typeof M!="object")return!1;const R=M;return R.enabled===!1?!1:R.enabled===!0||l(R.commit)}function u(M){const R={...c,...M||{}};return R.operators=new Set(R.operators||[]),R.mutate=b(R.mutate),R}function E(M,R){return!M||!M.op||!R.operators.size?!1:R.operators.has(M.op)}function d(M,R){if(!M)return{pushed:null,residual:null};if(!R.filter)return{pushed:null,residual:M};if(R.filter==="term"){if(J(M)){const I=M.conditions||[];if(String(M.op)!=="and")return{pushed:null,residual:M};const j=I.findIndex(D=>!J(D)&&E(D,R));if(j<0)return{pushed:null,residual:M};const A=I.filter((D,p)=>p!==j);return{pushed:I[j],residual:A.length?{op:"and",conditions:A}:null}}return E(M,R)?{pushed:M,residual:null}:{pushed:null,residual:M}}if(!J(M))return E(M,R)?{pushed:M,residual:null}:{pushed:null,residual:M};if(String(M.op)!=="and")return(M.conditions||[]).every(j=>J(j)?d(j,R).residual===null:E(j,R))?{pushed:M,residual:null}:{pushed:null,residual:M};const H=[],f=[];for(const I of M.conditions||[]){if(J(I)){if(R.filter==="flat"){f.push(I);continue}const j=d(I,R);j.pushed&&H.push(j.pushed),j.residual&&f.push(j.residual);continue}(E(I,R)?H:f).push(I)}const g=I=>I.length===0?null:I.length===1?I[0]:{op:"and",conditions:I};return{pushed:g(H),residual:g(f)}}const w="__lattice_leaves";function G(M){return M.aggregates?M.aggregates instanceof Set?M.aggregates:new Set(de(M.aggregates)):new Set}function N(M){const R=G(M);return R.size?R.has("count")?M.filter!=="tree"||!M.operators||!M.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 T(M,R,H,f,g,I,j){const A=Array.isArray(M.groupBy)?M.groupBy:[],D=Array.isArray(M.groupPath)?M.groupPath:[],p=Array.isArray(M.groupValues)?M.groupValues:null;if(!R.group){const se=N(R);if(se)return se}return _(A)?H.residual?"the filter did not fully push, so the engine would group a superset of the matching rows":f?g?I?"a host `where` predicate can only run in the browser, over rows the engine grouped":j?"fullDataset holds the whole matching set, so the grid groups it itself":!p||p.length!==D.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 C="pushdown:pivot-unsupported",h="pushdown:group-unsupported",$=Symbol("lattice.remote.ungroupedLevel");function a(M,R,H,f,g,I){const j=Array.isArray(M.pivotBy)?M.pivotBy:[],A=Array.isArray(M.groupBy)?M.groupBy:[],D=Array.isArray(M.groupPath)?M.groupPath:[],p=Array.isArray(M.groupValues)?M.groupValues:null;return R.pivot?_(j)?A.length&&!_(A)?"a grouping key is not a plain column the engine can name in a GROUP BY":H.residual?"the filter did not fully push, so the engine would pivot a superset of the matching rows":f?g?I?"a host `where` predicate can only run in the browser, over rows the engine pivoted":!p||p.length!==D.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 n(M,R,H=!1){const f=d(M.filters||null,R),g=[];f.residual&&g.push("filter");const I=M.sort||[],j=I.length===0||R.sort==="multi"&&I.length>=1||R.sort==="single"&&I.length===1;!j&&I.length&&g.push("sort");const A=M.quick?String(M.quick):"",D=!A||!!R.quick;D||g.push("quick");const p=M.where&&M.where.active?M.where:null;p&&g.push("where");const se={filters:f.residual,sort:j?null:I,quick:D?"":A,where:p},V=!!H,O=Array.isArray(M.groupBy)&&M.groupBy.length>0,X=O?T(M,R,f,j,D,p,V):"",oe=M.pivotMode!==!1&&Array.isArray(M.pivotBy)&&M.pivotBy.length>0,ue=oe?a(M,R,f,j,D,p):"",xe=oe&&ue==="";oe&&!xe&&g.push("pivot");const me=oe?xe&&O:O&&X==="";O&&!oe&&!me&&g.push("group");const we=(me||xe)&&Array.isArray(M.groupValues)?M.groupValues.length:0,Pe=me||oe?!1:V||!!(se.filters||se.sort||se.quick||se.where)||!R.range;return{pushed:{...M,filters:f.pushed,sort:j?I:[],quick:D?A:"",range:Pe?null:M.range},residual:se,needsAll:Pe,unpushed:g,full:V,grouped:me,groupLevel:we,groupReason:oe?"":X,pivoted:xe,pivotReason:ue}}function t(M){const R=Array.isArray(M.totals)?M.totals:[],H=M.totalFns&&typeof M.totalFns=="object"?M.totalFns:{},f=[],g=[];for(const I of R){const j=String(I),A=typeof H[j]=="string"?H[j]:null,D=A?i[A]:null;A?!D||!D.pushable||!D.sql?g.push({id:j,fn:A,class:D?D.class:"fallback",reason:D&&D.note?D.note:`the pushdown map cannot express "${A}"`}):D.twoColumn?g.push({id:j,fn:A,class:D.class,reason:`"${A}" reduces two columns, and a grouped request carries no weight column`}):f.push({id:j,col:j,fn:A,class:D.class}):g.push({id:j,fn:null,class:"fallback",reason:"the column totals with a host function, so there is no named statistic to push"})}return{engine:f,client:g}}const e=Object.freeze({items:M=>M==null?[]:Array.isArray(M)?M:[M]});function s(M,R,H){if(!R)return M;let f=M;if(R.filters&&l(H.evaluateFilters)){const g=f,I={count:f.length,handle:D=>({id:D,get:p=>y(g[p],D)}),itemwise:D=>g.some(p=>Array.isArray(y(p,D)))?e:null},j=H.evaluateFilters(R.filters,I),A=[];for(let D=0;D<f.length;D++)j[D]&&A.push(f[D]);f=A}if(R.where&&R.where.active&&(R.whole||Q(R.where.names,"pushdown"),f=f.filter(g=>R.where.passes(g))),R.quick){const g=R.quick.toLowerCase();f=f.filter(I=>{if(!I||typeof I!="object")return!1;for(const j of Object.values(I))if(j!=null&&String(j).toLowerCase().includes(g))return!0;return!1})}if(R.sort&&R.sort.length&&l(H.sortMulti)){const g=[...new Set(R.sort.map(D=>D.col))],I=f,j=g.map(D=>({id:D,get:p=>y(I[p],D)})),A=H.sortMulti(j,R.sort.map(D=>({col:D.col,dir:D.dir})),Uint32Array.from({length:f.length},(D,p)=>p),{});f=Array.from(A,D=>I[D])}return f}function x(M){return JSON.stringify({filters:M.filters||null,sort:M.sort||[],quick:M.quick||"",groupBy:M.groupBy||[],groupPath:M.groupPath||[],context:M.context??null})}function S(M){if(!M||typeof M!="object")return 16;let R="";try{R=JSON.stringify(M)}catch{return 200}return R.length*2+64}function B(M){const R=M||{};return{enabled:!!R.enabled,maxRows:Number.isFinite(R.maxRows)?R.maxRows:1e6,maxBytesEstimate:Number.isFinite(R.maxBytesEstimate)?R.maxBytesEstimate:512*1024*1024}}const Y=5e4;function te(M){return Number.isFinite(M)&&M>=0?M:Y}function q(M){return!!M&&l(M.then)}async function ne(M){if(!M||M.total!==void 0||!q(M.pendingTotal))return M;const R=await M.pendingTotal,{pendingTotal:H,...f}=M;return typeof R=="number"?{...f,total:R}:f}function U(M={}){const R=M.adapter;if(!R||!l(R.execute))return z("source.pushdown.adapter","createPushdownSource needs an `adapter` with an `execute(query)` function."),{...M,mode:"remote",fetch:async()=>({rows:[],total:0})};const H=u(R.capabilities),f=R.capabilities&&Object.getOwnPropertyDescriptor(R.capabilities,"operators");f&&l(f.get)&&Object.defineProperty(H,"operators",{enumerable:!0,configurable:!0,get:()=>new Set(R.capabilities.operators||[]),set:()=>{}});const g=R.name||"adapter";let I=null;const j=()=>l(R.ready)?(I||(I=Promise.resolve(R.ready()).then(()=>{Object.assign(H,u(R.capabilities))},Se=>{throw I=null,Se})),I):null,A=B(M.fullDataset),D=!!M.allowPartialResults,p=te(M.whereRowLimit);let se=null;const V=M.aggregates;let O=null,X=null,oe=null,ue=null,xe=null,me,we=null,Pe=0,Fe=null;const Z=()=>!A.enabled||!O?null:(Fe!==O.key&&(Pe++,Fe=O.key),{rows:O.rows,version:Pe}),re=async Se=>{const Ne=Se.where&&Se.where.active?Se.where:null;if(!Ne)return{request:Se,probe:null};const{where:Ve,...Be}=Se,Oe=n(Be,H,A.enabled);if(Oe.needsAll)return{request:Se,probe:null};const Xe=x(Oe.pushed);let nt=null;return(!se||se.key!==Xe)&&(H.total?(m(Se),nt=await ne(await R.execute(Oe.pushed,Se)),se={key:Xe,size:nt&&typeof nt.total=="number"?nt.total:null}):se={key:Xe,size:null}),se.size!==null&&se.size<p?{request:Se,probe:null}:(ie(Ne.names,g,se.size,p),{request:Be,probe:nt})},le=async(Se,Ne)=>{we=null;const Ve=t(Se.pushed);oe={engine:Ve.engine,client:Ve.client,groupBy:Se.pushed.groupBy},Ve.client.length&&z(`source.pushdown.group.totals.${g}.${Ve.client.map(Xe=>Xe.id).join(".")}`,`the ${g} adapter cannot compute the group subtotal for ${Ve.client.map(Xe=>`"${Xe.id}" (${Xe.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 Be=await R.executeGroupLevel(Se.pushed,Ve.engine,Ne)||{};let Oe=Be.rows||[];return!H.range&&Ne.range&&(Oe=Oe.slice(Ne.range.start,Ne.range.end)),Ie(Be),Be.total===void 0?{rows:Oe}:{rows:Oe,total:Be.total}},pe=new Map,he=64,Me=async(Se,Ne)=>{we=null;const Ve=Se.pushed,Be=Ve.groupBy,Oe=Array.isArray(Ve.groupValues)?Ve.groupValues:[],Xe=Oe.length,nt=[...Ve.filters?[Ve.filters]:[],...Be.slice(0,Xe).map((We,ut)=>({col:We,op:"eq",value:Oe[ut]===void 0?null:Oe[ut],caseSensitive:!0}))],st=nt.length===0?null:nt.length===1?nt[0]:{op:"and",conditions:nt},ft=Ne.range?Ne.range.start:0;if(Xe>=Be.length){const We={...Ve,filters:st,groupBy:[],groupPath:[],groupValues:[],totals:[],totalFns:{}},ut=await ne(await R.execute(We,Ne))||{};let yt=ut.rows||[];return!H.range&&Ne.range&&(yt=yt.slice(Ne.range.start,Ne.range.end)),typeof ut.total=="number"?{rows:yt,total:ut.total}:{rows:yt}}const ht=Be[Xe],$t=t(Ve),dt=G(H),mt=$t.engine.filter(We=>dt.has(We.fn)),At=[...$t.engine.filter(We=>!dt.has(We.fn)).map(We=>({id:We.id,fn:We.fn,class:We.class,reason:`the ${g} adapter does not compute "${We.fn}"`})),...$t.client];oe={engine:mt,client:At,groupBy:Be},At.length&&z(`source.pushdown.group.totals.${g}.${At.map(We=>We.id).join(".")}`,`the ${g} adapter cannot compute the group subtotal for ${At.map(We=>`"${We.id}" (${We.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 ct=[...mt.map(We=>({id:We.id,col:We.col,fn:We.fn})),{id:w,col:ht,fn:"count"}],kt={...Ve,filters:st,range:null},_t=JSON.stringify([x(kt),Oe,ht,ct]);let Lt=ft>0?pe.get(_t):void 0;if(!Lt){for(Lt=Promise.resolve(R.executeGroupedAggregates(kt,[ht],ct)),pe.delete(_t),pe.set(_t,Lt);pe.size>he;)pe.delete(pe.keys().next().value);Lt.catch(()=>{pe.get(_t)===Lt&&pe.delete(_t)})}const Ht=await Lt||[];m(Ne);const Gt=We=>{const ut={};for(const yt of mt)ut[yt.id]=We?We[yt.id]:void 0;return ut},xt=(Ve.sort||[]).find(We=>We&&We.col===ht),qt=xt&&xt.dir==="desc"?-1:1,je=Ht.filter(We=>We&&We.level===1).map(We=>({[ht]:We.keys[0]===void 0?null:We.keys[0],leafCount:Number(We.values&&We.values[w])||0,totals:Gt(We.values)})).sort((We,ut)=>qt*F(We[ht],ut[ht]));if(Xe===0){const We=Ht.find(yt=>yt&&yt.level===0),ut=We?Number(We.values&&We.values[w]):NaN;Ie({matchCount:Number.isFinite(ut)?ut:je.reduce((yt,Et)=>yt+Et.leafCount,0),...We?{grand:Gt(We.values)}:{}})}const et=Ne.range?Ne.range.end:je.length;return{rows:je.slice(ft,et),total:je.length}},Ie=Se=>{typeof Se.matchCount=="number"&&(ue=Se.matchCount,xe=Se.grand?{totals:Se.grand,leafCount:Se.matchCount}:null,me===void 0&&l(R.unfilteredCount)&&(me=null,Promise.resolve(R.unfilteredCount()).then(Ne=>{me=typeof Ne=="number"?Ne:null}).catch(Ne=>{z(`source.pushdown.group.unfiltered.${g}`,`the ${g} adapter could not count the unfiltered set (${Ne&&Ne.message?Ne.message:Ne}), so "N of M" falls back to the display count for its denominator.`)})))},Ke=async(Se,Ne)=>{we=null;const Ve=t(Se.pushed);oe={engine:Ve.engine,client:Ve.client,groupBy:Se.pushed.groupBy,pivotBy:Se.pushed.pivotBy},Ve.client.length&&z(`source.pushdown.pivot.totals.${g}.${Ve.client.map(st=>st.id).join(".")}`,`the ${g} adapter cannot compute the pivot cells for ${Ve.client.map(st=>`"${st.id}" (${st.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 Be=await R.executePivotLevel(Se.pushed,Ve.engine,Ne)||{};let Oe=Be.rows||[];!H.range&&Ne.range&&(Oe=Oe.slice(Ne.range.start,Ne.range.end)),Ie(Be);const Xe=Be.pivot&&typeof Be.pivot=="object"?Be.pivot:{},nt={cells:Array.isArray(Xe.cells)?Xe.cells:[],...Array.isArray(Xe.axis)?{axis:Xe.axis}:{}};return Be.total===void 0?{rows:Oe,pivot:nt}:{rows:Oe,total:Be.total,pivot:nt}},qe=Se=>{z(`source.pushdown.pivot.${g}.${Se}`,`pushdown:pivot-unsupported: the ${g} adapter cannot pivot this query because ${Se}, so no rows are fetched rather than every leaf row being pulled into the browser to pivot there. \`lastPlan().pivotReason\` says the same.`);const Ne=new Error(`[lattice] ${C}: the ${g} adapter cannot pivot this query because ${Se}, so no rows are fetched rather than every leaf row being pulled into the browser to pivot there. \`lastPlan().pivotReason\` says the same.`);throw Ne.code=C,Ne.reason=Se,Ne},ot=(Se,Ne)=>{const Ve={key:Ne,state:"pending",value:null};return we=Ve,Se.then(Be=>(we===Ve&&(we={key:Ne,state:"settled",value:typeof Be=="number"?Be:null}),Be),Be=>{throw we===Ve&&(we={key:Ne,state:"failed",value:null}),Be})};let it=0,ge=[];const Le=()=>it===0?null:new Promise(Se=>{const Ne=setTimeout(Se,r);ge.push(()=>{clearTimeout(Ne),Se()})});let He;const Ze=async Se=>{const Ne=j();Ne&&await Ne;const Be=Se&&Se.pivotMode!==!1&&Array.isArray(Se.pivotBy)&&Se.pivotBy.length>0?{request:Se,probe:null}:await re(Se);m(Se);let Oe=n(Be.request,H,A.enabled);if(H.group&&Oe.grouped&&!Oe.pivoted&&!l(R.executeGroupLevel)&&(z(`source.pushdown.group.method.${g}`,`the ${g} 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.`),Oe=n(Be.request,{...H,group:!1,aggregates:null},A.enabled)),Oe.pivoted&&!l(R.executePivotLevel)&&(Oe=n(Be.request,{...H,pivot:!1},A.enabled),Oe.pivotReason="the adapter declares the `pivot` capability but has no `executePivotLevel(query, aggregates, request)`"),Oe.grouped&&!Oe.pivoted&&!H.group&&!l(R.executeGroupedAggregates)&&(z(`source.pushdown.group.aggregates.method.${g}`,`the ${g} 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\`.`),Oe=n(Be.request,{...H,aggregates:null},A.enabled)),X=Oe,Oe.pivoted)return Ke(Oe,Se);if(Oe.pivotReason&&qe(Oe.pivotReason),Oe.grouped)return H.group?le(Oe,Se):Me(Oe,Se);const nt=!!Oe.groupReason&&!Oe.full;nt?z(`source.pushdown.group-unsupported.${g}.${Oe.groupReason}`,`pushdown:group-unsupported: the ${g} adapter was not asked to group this query because ${Oe.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.`):Oe.groupReason&&z(`source.pushdown.group.${g}.${Oe.groupReason}`,`the ${g} adapter was not asked to group this query because ${Oe.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 st=ct=>nt?{...ct,[$]:!0}:ct;if(!Oe.needsAll){const ct=Be.probe||await R.execute(Oe.pushed,Se),kt=ct.rows||[];return q(ct.pendingTotal)&&ct.total===void 0?st({rows:kt,pendingTotal:ot(ct.pendingTotal,x(Oe.pushed))}):(we=null,!H.total&&ct.total===void 0?st({rows:kt}):st({rows:kt,total:ct.total??kt.length}))}Oe.unpushed.length&&z(`source.pushdown.residual.${g}.${Oe.unpushed.join(".")}`,`the ${g} adapter cannot push ${Oe.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 ft=x(Oe.pushed);if(!O||O.key!==ft){const ct=await ne(await R.execute(Oe.pushed,Se));we=null;const kt=ct.rows||[];if(Oe.full){const _t=typeof ct.total=="number"?Math.max(ct.total,kt.length):kt.length;if(_t>A.maxRows)throw new Error(`[lattice] fullDataset refused: the ${g} adapter's matching set is ${_t.toLocaleString()} rows, past the configured maxRows of ${A.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 Lt=kt.length*S(kt[0]);if(Lt>A.maxBytesEstimate)throw new Error(`[lattice] fullDataset refused: the ${g} adapter's matching set is an estimated ${Math.round(Lt/(1024*1024)).toLocaleString()} MB across ${kt.length.toLocaleString()} rows, past the configured maxBytesEstimate of ${Math.round(A.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 ct.total=="number"&&kt.length<ct.total){const _t=!!(Oe.residual.filters||Oe.residual.quick||Oe.residual.sort&&Oe.residual.sort.length);if(_t&&!D)throw new Error(`[lattice] the ${g} adapter returned ${kt.length} of ${ct.total} matching rows when asked for the whole result, and the query has residual ${Oe.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.`);_t?z(`source.pushdown.partial.residual.${g}`,`the ${g} adapter returned ${kt.length} of ${ct.total} matching rows when asked for the whole result, and residual work will run over that fraction. allowPartialResults is set, so the result is used as-is — it may be wrong. The adapter must follow the engine's own paging to be correct.`):z(`source.pushdown.partial.${g}`,`the ${g} adapter returned ${kt.length} of ${ct.total} matching rows when asked for the whole result. The adapter must follow the engine's own paging before returning.`)}O={key:ft,rows:kt,total:typeof ct.total=="number"?ct.total:null}}let ht=Oe;if(Oe.residual.where){const ct=O.total??O.rows.length;if(ct>=p){ie(Oe.residual.where.names,g,ct,p);const{where:kt,..._t}=Be.request;ht=n(_t,H,A.enabled),X=ht}}const $t=O.total!==null&&O.rows.length>=O.total,dt=s(O.rows,{...ht.residual,whole:$t},M.compute||{}),mt=Se.range?Se.range.start:0,At=Se.range?Se.range.end:dt.length;return st({rows:dt.slice(mt,At),total:dt.length})},ae=async(Se,Ne,Ve)=>{const Oe=Ve&&Ve.waitForPage&&He&&l(He.pageForegroundIdle)?He.pageForegroundIdle():Le();Oe&&await Oe;const Xe=j();Xe&&await Xe;const nt=n(Se,H,A.enabled);X=nt;const st=L(Ne,V),ft=Array.isArray(Se.groupBy)?Se.groupBy:[],ht=ft.length>0,$t=!nt.residual.filters&&!nt.residual.quick,dt=!ht||_(ft,H.buckets);let mt=st.engine,At=st.client;if(H.aggregates&&mt.length){const Lt=H.aggregates instanceof Set?H.aggregates:new Set(de(H.aggregates)),Ht=mt.filter(Gt=>!Lt.has(Gt.fn));Ht.length&&(mt=mt.filter(Gt=>Lt.has(Gt.fn)),At=[...Ht.map(Gt=>({...Gt,reason:`the ${g} adapter does not compute "${Gt.fn}"`})),...At])}const ct=Lt=>{At=[...mt.map(Ht=>({...Ht,reason:Lt})),...At],mt=[]};mt.length&&!$t?ct(nt.residual.quick&&!nt.residual.filters?"a quick search the adapter cannot push forces all-client (no mixed provenance)":"residual filter forces all-client (no mixed provenance)"):mt.length&&!dt&&ct("a grouping key the engine cannot form forces all-client (no mixed provenance)");let kt={},_t;return mt.length&&(l(ht?R.executeGroupedAggregates:R.executeAggregates)?ht?_t=await R.executeGroupedAggregates(nt.pushed,ft,mt)||[]:kt=await R.executeAggregates(nt.pushed,mt)||{}:(z(`source.pushdown.aggregates.${g}${ht?".grouped":""}`,`the ${g} adapter cannot compute ${ht?"grouped ":""}aggregates, so every requested statistic is computed client-side. Correct, and slower than it needs to be.`),ct(`adapter cannot compute ${ht?"grouped ":""}aggregates`))),oe={engine:mt,client:At,...ht?{groupBy:ft}:{}},{values:kt,engine:mt,client:At,..._t!==void 0?{groups:_t}:{}}},ee=async Se=>{it++;try{return await Ze(Se)}finally{if(it--,it===0&&ge.length){const Ne=ge;ge=[];for(const Ve of Ne)Ve()}}},ye=P(M.edit),ve=M.edit&&typeof M.edit=="object"&&l(M.edit.commit);let be=M.edit;if(ye&&!ve)if(H.mutate&&H.mutate.update){const Se=Ne=>{if(!H.mutate||!H.mutate.update)throw new Error(`[lattice] the ${g} 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 Ve={kind:"update",key:String(Ne.key),patch:{[Ne.colId]:Ne.value}};return R.mutate(Ve,Ne.request||{})};be={...M.edit===!0?{}:M.edit,commit:Se}}else z(`source.pushdown.readonly.${g}`,`edit is enabled but the ${g} adapter declares mutate: ${H.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 Ee=ye&&H.mutate&&(H.mutate.append||H.mutate.delete)?{append:H.mutate.append===!0,remove:H.mutate.delete===!0,returning:H.mutate.returning,mutate:(Se,Ne)=>R.mutate(Se,Ne||{})}:null,$e=async Se=>{const Ne=j();Ne&&await Ne;const{range:Ve,signal:Be,export:Oe,...Xe}=Se||{},nt={...Xe,groupBy:[],groupPath:[],groupValues:[],pivotBy:[],pivotMode:!1,totals:[]};return{plan:n(nt,H,A.enabled),signal:Be}};async function*Ge(Se,Ne={}){const{plan:Ve,signal:Be}=await $e(Se),Oe=Math.max(1,Math.floor(Number(Ne.pageSize))||5e3),Xe={signal:Be,stream:!0};if(!Ve.needsAll)for(let ft=0;;ft+=Oe){m(Xe);const ht=await R.execute({...Ve.pushed,range:{start:ft,end:ft+Oe}},Xe);ht&&q(ht.pendingTotal)&&ht.pendingTotal.then(null,()=>{});const $t=ht&&ht.rows||[];if($t.length&&(yield $t),$t.length<Oe)return}m(Xe);const nt=await ne(await R.execute({...Ve.pushed,range:void 0},Xe)),st=s(nt&&nt.rows||[],{...Ve.residual,whole:!0},M.compute||{});for(let ft=0;ft<st.length;ft+=Oe)yield st.slice(ft,ft+Oe)}return He={...M,edit:be,rowMutate:Ee,mode:"remote",fetch:ee,foregroundIdle:Le,aggregate:ae,countMatching:async Se=>{const{plan:Ne,signal:Ve}=await $e(Se);if(!Ne.needsAll&&H.total){m({signal:Ve});const Oe=await ne(await R.execute({...Ne.pushed,range:{start:0,end:0}},{signal:Ve}));if(Oe&&typeof Oe.total=="number")return Oe.total}let Be=0;for await(const Oe of Ge(Se))Be+=Oe.length;return Be},streamMatching:Ge,lastPlan:()=>X?{...X,...oe?{aggregates:oe}:{},...we?{total:{deferred:!0,state:we.state,value:we.value}}:{}}:null,fullFrame:Z,counts:()=>({match:ue,total:me??null,pending:!!we&&we.state==="pending"}),grandTotals:()=>xe},He}}),rt("packages/modules/shared/engine.js",function(o,ce){"use strict";Object.defineProperty(o,"sourceId",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"engineSource",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"gridPivoted",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"loadedAndMatching",{enumerable:!0,get:function(){return L}}),Object.defineProperty(o,"gridHoldsWindow",{enumerable:!0,get:function(){return _}}),Object.defineProperty(o,"gridEngineRequest",{enumerable:!0,get:function(){return v}}),Object.defineProperty(o,"EngineFlight",{enumerable:!0,get:function(){return k}});const ke=ce("packages/core/src/source/pushdown.js"),F=ke.capabilitiesOf,l=ke.planQuery,z=ce("packages/core/src/source/filterwire.js").wireFilters,fe=new WeakMap;let J=0;function Q(r){let m=fe.get(r);return m===void 0&&(m=++J,fe.set(r,m)),m}function ie(r){const m=r&&typeof r.config=="function"?r.config():null,c=m&&m.source&&typeof m.source=="object"?m.source:null;if(!c||typeof c.aggregate!="function")return{reason:"the grid's source has no aggregate() — it is not a pushdown source"};const b=F(c.adapter&&c.adapter.capabilities);return{source:c,caps:b,config:m}}function W(r){const m=r&&typeof r.config=="function"?r.config():null,c=m&&m.source&&typeof m.source=="object"?m.source:null;if(!c||typeof c.lastPlan!="function")return!1;const b=r&&r.state&&typeof r.state.get=="function"?r.state.get():null,y=b&&b.pivot;return!!(y&&y.enabled&&Array.isArray(y.columns)&&y.columns.length>0)}function L(r){const m=r.rows&&typeof r.rows.residentCount=="function"?r.rows.residentCount():0,c=typeof r.rows.matchCount=="function"?r.rows.matchCount():NaN;return{loaded:m,total:Number.isFinite(c)?c:NaN}}function _(r){const m=r&&typeof r.config=="function"?r.config():null,c=m&&m.source&&typeof m.source=="object"?m.source:null;if(!c||c.mode!=="remote"&&c.mode!=="paged")return!1;if(typeof r.rows.matchCount=="function"&&r.rows.matchCount()===null)return!0;const{loaded:b,total:y}=L(r);return Number.isFinite(y)&&b<y}function i(r,m){return m?r?{op:"and",conditions:[r,m]}:m:r||null}function v(r,m,c=null){const b=r.filters&&typeof r.filters.where=="function"?r.filters.where():[];if(Array.isArray(b)&&b.length)return{reason:`a \`where\` predicate is in force (${b.join(", ")}), which only the browser can run`};const y=r.filters&&typeof r.filters.quickState=="function"?r.filters.quickState():{text:""},P=y&&y.text?String(y.text):"",{config:u,caps:E}=m,d={filters:z(i(r.filters.get(),c),{tz:u.timeZone,weekStartsOn:u.weekStartsOn}),sort:[],range:null,context:u.context??null,...P?{quick:P}:{}},w=l(d,E);return w.unpushed.includes("filter")?{reason:c?"the grid's filter, or the viewport condition, did not fully push to the engine":"the grid's filter did not fully push to the engine"}:w.unpushed.includes("quick")?{reason:"the quick search did not push to the engine"}:{request:d,quick:P}}class k{#e=null;#t=null;#n=!1;answer(m){return this.#t&&this.#t.key===m?this.#t:null}last(){return this.#t}get busy(){return this.#e!==null}ask(m,c,b){const y=this.#e;if(y){y.key!==m&&y.controller&&y.controller.abort();return}const P=globalThis.AbortController,u=typeof P=="function"?new P:null,E={key:m,controller:u};this.#e=E;let d;Promise.resolve().then(()=>c(u?u.signal:null)).then(w=>{d={key:m,result:w}},w=>{d={key:m,error:w}}).then(()=>{this.#e===E&&(this.#e=null),!this.#n&&(u&&u.signal.aborted||(this.#t=d),b())})}abort(){const m=this.#e;m&&m.controller&&m.controller.abort()}close(){this.#n=!0,this.abort()}}}),rt("packages/modules/charts/stat-widgets.js",function(o,ce){"use strict";const F=ce("packages/modules/charts/registry.js").registerChartType,de=ce("packages/modules/charts/cartesian.js").drawCartesian,z=ce("packages/modules/shared/engine.js"),fe=z.engineSource,J=z.gridHoldsWindow,Q=z.gridPivoted,ie="http://www.w3.org/2000/svg";function W(e){return e==null||typeof e!="number"||!Number.isFinite(e)?"—":Math.abs(e)>=100?e.toFixed(0):e.toFixed(2)}function L(e){return!e||"reason"in fe(e)?!1:J(e)||Q(e)}function _(e){return{empty:!1,legend:[],refusal:{stat:e,lines:[`${e}: not computed`,"a pushdown source holds a window of its rows, and this","statistic needs every matching row — refused, not drawn","over the loaded window."]}}}function i(e,s){for(const S of e.childNodes||[])if(S&&S.getAttribute&&S.getAttribute("class")===s)return S;const x=e.ownerDocument.createElementNS(ie,"g");return x.setAttribute("class",s),e.appendChild(x),x}function v(e,s,x){const{plot:S,groups:B,helpers:Y}=e,{Pool:te,attrs:q,round:ne,setText:U,NS:M}=Y,R=new te(B.overlay),H=S.top+14;return s.forEach((f,g)=>{const I=R.next("text",`${M}__${x}`);U(I,f),q(I,{x:ne(S.left),y:ne(H+g*16),"font-size":12})}),R.finish(),H+s.length*16+10}function k(e,s){return v(e,s.lines,"stat-refusal"),new e.helpers.Pool(e.groups.marks).finish(),new e.helpers.Pool(e.groups.axis).finish(),{empty:!1,refusal:s,readout:s.lines,legend:[]}}function r(e,s){const x=s&&(s.y||s.field)||null;if(!x||!e||!e.statistics||typeof e.statistics.profile!="function")return{empty:!0};if(L(e)&&typeof e.statistics.profileAsync=="function")return{empty:!1,mode:"engine",field:x,legend:[]};const S=e.statistics.profile(x);return S?{profile:S,field:x,empty:!1}:{empty:!0}}const m=new WeakMap;function c(e){let s=m.get(e);return s||(s=new Map,m.set(e,s)),s}function b(e){try{const s=e.filters&&typeof e.filters.get=="function"?e.filters.get():null,x=e.filters&&typeof e.filters.quickState=="function"?(e.filters.quickState()||{}).text:"";return JSON.stringify([s||null,x||""])}catch{return""}}function y(e,s,x){const{plot:S,groups:B,helpers:Y}=e,{Pool:te,attrs:q,round:ne,setText:U,linearScale:M,NS:R}=Y,H=Array.isArray(s.unavailable)?s.unavailable.map(p=>p.stat):[],f=[`column profile · n=${s.rows}${x?" · computed in the data engine":""}`,`distinct ${s.distinct} missing ${s.missing} mean ${W(s.mean)} median ${W(s.median)} sd ${W(s.stddev)}`,`q1 ${W(s.q1)} q3 ${W(s.q3)} iqr ${W(s.iqr)} outliers ${s.outliers==null?"—":s.outliers}`];H.length&&f.push(`not computed in the engine: ${H.join(", ")}`);const g=v(e,f,"profile-stat"),I=Array.isArray(s.histogram)?s.histogram:[],j=new te(B.marks),A=new te(B.axis),D=S.bottom;if(I.length&&D>g){const p={min:I[0].from,max:I[I.length-1].to};p.max<=p.min&&(p.max=p.min+1);const se=M(p,[S.left,S.right]),V=I.reduce((O,X)=>Math.max(O,X.count),0)||1;I.forEach((O,X)=>{const oe=se.of(O.from),ue=se.of(O.to),xe=(D-g)*O.count/V;q(j.next("rect",`${R}__mark ${R}__profile-bar`),{x:ne(Math.min(oe,ue)),y:ne(D-xe),width:ne(Math.max(1,Math.abs(ue-oe)-1)),height:ne(Math.max(0,xe)),fill:"currentColor","fill-opacity":.65,"data-point":X})}),q(A.next("line",`${R}__gridline`),{x1:ne(S.left),y1:ne(D),x2:ne(S.right),y2:ne(D),stroke:"currentColor","stroke-opacity":.3})}return j.finish(),A.finish(),{profile:s,provenance:x?"engine":"client",readout:f,method:"column profile",n:s.rows,legend:[]}}function P(e){const s=e.bound||{};if(s.refusal)return k(e,s.refusal);if(s.mode==="engine"){const x=e.grid,S=c(x),B=`${s.field} ${b(x)}`;let Y=S.get(B);if(Y||(Y={status:"pending",profile:null},S.set(B,Y),Promise.resolve(x.statistics.profileAsync(s.field)).then(te=>{Y.status="done",Y.profile=te,typeof e.redraw=="function"&&e.redraw()},()=>{Y.status="done",Y.profile=null})),Y.status!=="done"){const te=["column profile · computing in the data engine…"];return v(e,te,"profile-stat"),new e.helpers.Pool(e.groups.marks).finish(),new e.helpers.Pool(e.groups.axis).finish(),{pending:!0,provenance:"engine",readout:te,legend:[]}}if(!Y.profile){const te=["column profile: the data engine returned no answer."];return v(e,te,"profile-stat"),new e.helpers.Pool(e.groups.marks).finish(),new e.helpers.Pool(e.groups.axis).finish(),{empty:!0,provenance:"engine",readout:te,legend:[]}}return y(e,Y.profile,!0)}return s.profile?y(e,s.profile,s.profile.computed==="source"):{empty:!0,legend:[]}}F("profile",{draw:P,bind:r,freeform:!0,family:"statistics"});const u=Object.freeze(["histogram","box","violin","ecdf"]);function E(e,s){const x=[];return e&&e.rows&&typeof e.rows.forEach=="function"&&typeof e.rows.value=="function"&&e.rows.forEach(S=>{if(!S||S.group||S.key==null)return;const B=Number(e.rows.value(S.key,s));Number.isFinite(B)&&x.push(B)}),x.sort((S,B)=>S-B),x}function d(e,s){const x=s&&(s.y||s.field)||null;if(!x||!e||!e.statistics||typeof e.statistics.profile!="function")return{empty:!0};if(L(e))return _("distribution");const S=e.statistics.profile(x);if(!S||!S.rows)return{empty:!0};const B=u.includes(s&&s.mode)?s.mode:"histogram",Y=typeof e.statistics.reduce=="function"?e.statistics.reduce(x,"jarqueBera"):null,te=B==="ecdf"||B==="violin"?E(e,x):null;return{profile:S,field:x,mode:B,jb:Y,values:te,empty:!1,legend:[]}}function w(e){const s=e.bound||{};if(s.refusal)return k(e,s.refusal);if(!s.profile)return{empty:!0,legend:[]};const{plot:x,groups:S,helpers:B}=e,{Pool:Y,attrs:te,round:q,linearScale:ne,NS:U}=B,{profile:M,mode:R,jb:H,values:f}=s,g=M.rows,I=H==null?"n/a (too few)":H<=5.99?"normal":"non-normal",j=[`distribution (${R}) · n=${g}`,`Jarque–Bera ${W(H)} — ${I} at 5%`],A=v(e,j,"distribution-stat"),D=x.bottom,p=new Y(S.marks),se=new Y(S.axis),V=M.min,O=M.max;if(D>A&&Number.isFinite(V)&&Number.isFinite(O)){const X={min:V,max:O<=V?V+1:O},oe=ne(X,[x.left,x.right]);if(R==="box"){const ue=(A+D)/2,xe=Math.max(8,(D-A)/4);te(p.next("line",`${U}__mark ${U}__dist-whisker`),{x1:q(oe.of(V)),y1:q(ue),x2:q(oe.of(O)),y2:q(ue),stroke:"currentColor","stroke-opacity":.6}),te(p.next("rect",`${U}__mark ${U}__dist-box`),{x:q(oe.of(M.q1)),y:q(ue-xe),width:q(Math.max(1,oe.of(M.q3)-oe.of(M.q1))),height:q(xe*2),fill:"currentColor","fill-opacity":.25,stroke:"currentColor"}),te(p.next("line",`${U}__mark ${U}__dist-median`),{x1:q(oe.of(M.median)),y1:q(ue-xe),x2:q(oe.of(M.median)),y2:q(ue+xe),stroke:"currentColor","stroke-width":2})}else if(R==="ecdf"&&Array.isArray(f)&&f.length){const ue=ne({min:0,max:1},[D,A]),xe=f.map((me,we)=>`${q(oe.of(me))},${q(ue.of((we+1)/f.length))}`);te(p.next("path",`${U}__mark ${U}__dist-ecdf`),{d:`M${xe.join("L")}`,fill:"none",stroke:"currentColor","stroke-width":1.5})}else{const ue=Array.isArray(M.histogram)?M.histogram:[],xe=ue.reduce((we,Pe)=>Math.max(we,Pe.count),0)||1,me=(A+D)/2;ue.forEach((we,Pe)=>{const Fe=oe.of(we.from),Z=oe.of(we.to),re=q(Math.max(1,Math.abs(Z-Fe)-1));if(R==="violin"){const le=(D-A)/2*(we.count/xe);te(p.next("rect",`${U}__mark ${U}__dist-violin`),{x:q(Math.min(Fe,Z)),y:q(me-le),width:re,height:q(le*2),fill:"currentColor","fill-opacity":.5,"data-point":Pe})}else{const le=(D-A)*(we.count/xe);te(p.next("rect",`${U}__mark ${U}__dist-bar`),{x:q(Math.min(Fe,Z)),y:q(D-le),width:re,height:q(Math.max(0,le)),fill:"currentColor","fill-opacity":.65,"data-point":Pe})}})}te(se.next("line",`${U}__gridline`),{x1:q(x.left),y1:q(D),x2:q(x.right),y2:q(D),stroke:"currentColor","stroke-opacity":.3})}return p.finish(),se.finish(),{profile:M,mode:R,jb:H,readout:j,method:R,n:g,legend:[]}}F("distribution",{draw:w,bind:d,freeform:!0,family:"statistics"});function G(e,s){const x=Array.isArray(s&&s.columns)?s.columns.filter(ne=>typeof ne=="string"&&ne):[];if(x.length<2||!e||!e.statistics)return{empty:!0};if(L(e))return _("correlation");const S=s.method==="spearman"?"spearman":"pearson",B=S==="spearman"?e.statistics.spearman:e.statistics.correlation;if(typeof B!="function")return{empty:!0};const Y=x.map(ne=>x.map(U=>{if(ne===U)return 1;const M=B.call(e.statistics,ne,U);return typeof M=="number"&&Number.isFinite(M)?M:null})),te=typeof e.statistics.profile=="function"?e.statistics.profile(x[0]):null,q=te?te.numeric!=null?te.numeric:te.rows:0;return{columns:x,matrix:Y,method:S,n:q,empty:!1,legend:[]}}function N(e){const s=e.bound||{};if(s.refusal)return k(e,s.refusal);if(!s.matrix)return{empty:!0,legend:[]};const{plot:x,groups:S,helpers:B}=e,{Pool:Y,attrs:te,round:q,setText:ne,NS:U}=B,{columns:M,matrix:R,method:H,n:f}=s,g=[`correlation (${H}) · n=${f}`],I=v(e,g,"correlation-stat"),j=new Y(S.marks),A=new Y(i(S.overlay,`${U}__correlation-cells`)),D=M.length,p=Math.min((x.right-x.left)/D,(x.bottom-I)/D);if(p>0)for(let se=0;se<D;se++)for(let V=0;V<D;V++){const O=R[se][V],X=x.left+V*p,oe=I+se*p;te(j.next("rect",`${U}__mark ${U}__correlation-cell`),{x:q(X),y:q(oe),width:q(p-1),height:q(p-1),fill:"currentColor","fill-opacity":O==null?0:Math.min(1,Math.abs(O)),stroke:"currentColor","stroke-opacity":.25,"data-point":se*D+V});const ue=A.next("text",`${U}__correlation-value`);ne(ue,O==null?"—":O.toFixed(2)),te(ue,{x:q(X+p/2),y:q(oe+p/2+4),"font-size":10,"text-anchor":"middle"})}return j.finish(),A.finish(),{columns:M,matrix:R,method:H,n:f,readout:g,legend:[]}}F("correlation",{draw:N,bind:G,freeform:!0,family:"statistics"});function T(e,s){const x=s||{},S=x.y||x.field,B=x.group||x.by;if(!S||!B||!e||!e.statistics||typeof e.statistics.compareGroups!="function")return{empty:!0};if(L(e))return _("group comparison");const Y=e.statistics.compareGroups(S,{by:B,groups:Array.isArray(x.groups)?x.groups:void 0,test:x.test,confidence:x.confidence});return Y?{comparison:Y,empty:!1}:{empty:!0}}function C(e){const s=e.bound||{};if(s.refusal)return k(e,s.refusal);const{plot:x,groups:S,helpers:B}=e,{Pool:Y,attrs:te,round:q,linearScale:ne,NS:U}=B,M=s.comparison;if(!M)return{empty:!0,legend:[]};const R=M.interval||{},H=R.lower,f=R.upper,g=R.estimate!==void 0?R.estimate:Number.isFinite(H)&&Number.isFinite(f)?(H+f)/2:null,I=Array.isArray(M.groups)?M.groups.map(String):["A","B"],j=Math.round((R.confidence||.95)*100),A=[`${I[0]} vs ${I[1]}: difference ${W(g)} [${W(H)}, ${W(f)}] (${j}% CI)`,`${M.test} p=${W(M.pValue)} effect size ${W(M.effectSize)} n=${M.nA}/${M.nB}`],D=v(e,A,"groupcomparison-stat")+6,p=x.bottom,se=new Y(S.marks),V=new Y(S.axis);if(Number.isFinite(H)&&Number.isFinite(f)&&p>D){const O=Math.max(Math.abs(f-H)*.4,1),X={min:Math.min(0,H-O),max:Math.max(0,f+O)},oe=ne(X,[x.left,x.right]),ue=D+(p-D)/2;te(V.next("line",`${U}__reference`),{x1:q(oe.of(0)),y1:q(D),x2:q(oe.of(0)),y2:q(p),stroke:"currentColor","stroke-opacity":.3,"stroke-dasharray":"3 3"}),te(se.next("line",`${U}__mark ${U}__groupcomparison-interval`),{x1:q(oe.of(H)),y1:q(ue),x2:q(oe.of(f)),y2:q(ue),stroke:"currentColor","stroke-width":2}),te(se.next("circle",`${U}__mark ${U}__groupcomparison-estimate`),{cx:q(oe.of(g)),cy:q(ue),r:5,fill:"currentColor","data-point":0})}return se.finish(),V.finish(),{comparison:M,readout:A,method:M.test,n:`${M.nA}/${M.nB}`,legend:[]}}F("groupComparison",{draw:C,bind:T,freeform:!0,family:"statistics"});function h(e,s){const x=s||{},S=x.x,B=x.y;if(!S||!B||!e||!e.statistics||typeof e.statistics.regressionModel!="function")return{empty:!0};if(L(e))return _("model errors");const Y=e.statistics.regressionModel({predictors:[S],response:B});if(!Y||!Array.isArray(Y.rows)||!Y.rows.length)return{empty:!0};const te=new Map(Y.rows.map((ne,U)=>[ne,U])),q=new Array(Y.rows.length);return e.rows&&typeof e.rows.forEachAll=="function"&&typeof e.rows.value=="function"&&e.rows.forEachAll((ne,U)=>{if(!te.has(U)||!ne||ne.key==null)return;const M=te.get(U),R=Number(e.rows.value(ne.key,S));Number.isFinite(R)&&(q[M]={x:R,fitted:Y.fitted[M],residual:Y.residuals[M],leverage:Y.leverage[M],cooksD:Y.cooksD[M]})}),{model:Y,rows:q.filter(Boolean),predictor:S,response:B,empty:!1}}const $=Object.freeze(["fit","residuals","influence"]);function a(e,s){if(e==="residuals")return{points:s.map(x=>({x:x.fitted,y:x.residual})),xLabel:"Fitted",yLabel:"Residual",zero:!0};if(e==="influence"){const x=s.reduce((S,B)=>Math.max(S,B.cooksD||0),0)||1;return{points:s.map(S=>({x:S.leverage,y:S.residual,size:(S.cooksD||0)/x})),xLabel:"Leverage",yLabel:"Residual",zero:!0}}return{points:s.map(x=>({x:x.x,y:x.fitted+x.residual})),xLabel:"Predictor",yLabel:"Response",zero:!1}}function n(e){const s=e.bound||{};if(s.refusal)return k(e,s.refusal);const{plot:x,groups:S,spec:B,helpers:Y}=e,{Pool:te,attrs:q,round:ne,linearScale:U,measureDomain:M,NS:R}=Y;if(!s.model||!s.rows||!s.rows.length)return{empty:!0,legend:[]};const H=$.includes(B&&B.preset)?B.preset:"fit",f=a(H,s.rows),{model:g}=s,I=Array.isArray(s.rows)?s.rows.length:g.n,j=g.cooksD?g.cooksD.filter(X=>X>4/I).length:0,A=typeof g.method=="string"?g.method.toUpperCase():"OLS",D=[`model error · ${A} · ${H} · R²=${W(g.r2)} · n=${I} · influential=${j}`],p=v(e,D,"modelerror-stat"),se=x.bottom,V=new te(S.marks),O=new te(S.axis);if(f.points.length&&se>p){const X=M(f.points.map(me=>me.x),{zero:!1}),oe=M(f.points.map(me=>me.y),{zero:f.zero}),ue=U(X,[x.left,x.right]),xe=U(oe,[se,p]);if(f.zero&&oe.min<=0&&oe.max>=0&&q(O.next("line",`${R}__reference`),{x1:ne(x.left),y1:ne(xe.of(0)),x2:ne(x.right),y2:ne(xe.of(0)),stroke:"currentColor","stroke-opacity":.3,"stroke-dasharray":"3 3"}),f.points.forEach((me,we)=>{const Pe=me.size!==void 0?3+me.size*7:3;q(V.next("circle",`${R}__mark ${R}__modelerror-point`),{cx:ne(ue.of(me.x)),cy:ne(xe.of(me.y)),r:ne(Pe),fill:"currentColor","fill-opacity":.6,"data-point":we})}),H==="fit"&&g.band&&Array.isArray(g.band.points)&&g.band.points.length>1){const me=g.band.points.map(we=>`${ne(ue.of(we.x))},${ne(xe.of(we.yhat))}`);q(V.next("path",`${R}__mark ${R}__modelerror-fit`),{d:`M${me.join("L")}`,fill:"none",stroke:"currentColor","stroke-width":1.5})}}return V.finish(),O.finish(),{model:g,preset:H,readout:D,method:A,n:I,legend:[]}}F("modelError",{draw:n,bind:h,freeform:!0,family:"statistics"});function t(e){if(L(e.grid)){const D=_("forecast").refusal;return k(e,D)}const s=e.spec||{},x=s.trend&&typeof s.trend=="object"?s.trend:{},S=de({...e,type:"line",fit:s.fit,trend:s.trend||!0,band:s.band,byRuleColour:!s.series,fill:s.fill,marker:s.marker,stack:s.stack,mark:s.mark,reference:s.reference,annotations:s.annotations,emphasis:s.emphasis,seriesStyle:s.seriesStyle,curve:s.curve,downsampleTo:s.downsample,keepInfluential:!!s.perRow,keepRows:Array.isArray(s.keepRows)?new Set(s.keepRows.map(String)):void 0})||{},B=typeof x.method=="string"?x.method:"linear",Y=Number.isFinite(x.forecast)?x.forecast:0,te=Array.isArray(S.series)?S.series.reduce((D,p)=>D+(Array.isArray(p.points)?p.points.length:0),0):0,q=[`forecast · ${B} · horizon ${Y} · n=${te}`],{plot:ne,groups:U,helpers:M}=e,{Pool:R,attrs:H,round:f,setText:g,NS:I}=M,j=new R(i(U.overlay,`${I}__forecast-readout`)),A=j.next("text",`${I}__forecast-stat`);return g(A,q[0]),H(A,{x:f(ne.left),y:f(ne.top+14),"font-size":12}),j.finish(),{...S,readout:q,method:B,horizon:Y,n:te}}F("forecast",{draw:t,labelled:!0,family:"statistics"})}),rt("packages/modules/designer/statistics-widgets.js",function(o,ce){"use strict";Object.defineProperty(o,"installStatisticsWidgets",{enumerable:!0,get:function(){return l}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return de}});const ke=ce("packages/modules/charts/stat-widgets.js"),F=Object.freeze({columnProfile:Object.freeze({type:"profile"}),distribution:Object.freeze({type:"distribution",options:{mode:"histogram"}}),correlation:Object.freeze({type:"correlation",options:{method:"pearson"}}),groupComparison:Object.freeze({type:"groupComparison"}),forecast:Object.freeze({type:"forecast",options:{trend:{method:"linear",forecast:3,band:"prediction"}}}),modelError:Object.freeze({type:"modelError",options:{preset:"fit"}})});function l(z,fe={}){let J=!1;return{get kinds(){return Object.keys(F)},defaults(Q){const ie=F[Q];return ie?{type:ie.type,...ie.options?{options:{...ie.options}}:{}}:null},add(Q,ie,W={}){if(J)return!1;const L=F[Q];if(!L||!ie)return!1;const{placement:_,options:i,...v}=W,k={id:ie,kind:"chart",...v,options:{...L.options?L.options:{},...i||{},type:L.type}};return z.addWidget(k,_)},destroy(){J=!0}}}const de=l}),rt("packages/modules/designer/pages.js",function(o,ce){"use strict";Object.defineProperty(o,"addPageState",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"renamePageState",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"movePageState",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"removePageState",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(o,"installPages",{enumerable:!0,get:function(){return W}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return L}});const F=ce("packages/modules/dashboard/spec.js").isPlain,de=ce("packages/core/src/internal/util.js").warnOnce;function z(_){if(Array.isArray(_))return _.map(z);if(!F(_))return _;const i={};for(const v of Object.keys(_))i[v]=z(_[v]);return i}function fe(_,i,v){if(!F(_)||!Array.isArray(_.pages))return null;const k=F(i)?i:{},r=_.pages,m=new Set(r.filter(F).map(P=>String(P.id)));let c=r.length+1;for(;m.has(`page-${c}`);)c+=1;const b=typeof k.id=="string"&&k.id!==""&&!m.has(k.id)?k.id:`page-${c}`;let y;if(typeof k.duplicate=="string"&&k.duplicate!==""){const P=r.find(u=>F(u)&&u.id===k.duplicate);if(!P)return null;y=z(P),y.id=b,y.title=typeof k.title=="string"&&k.title!==""?k.title:v("designer.page.copy",{title:typeof P.title=="string"?P.title:String(P.id)})}else y={id:b,title:typeof k.title=="string"&&k.title!==""?k.title:v("designer.page",{n:c}),spec:{panels:[]}};return r.push(y),b}function J(_,i,v){if(!F(_)||!Array.isArray(_.pages))return null;const k=_.pages.find(m=>F(m)&&m.id===i);if(!k)return null;const r=typeof v=="string"?v.trim():"";return r===""?null:(k.title=r,_)}function Q(_,i,v){if(!F(_)||!Array.isArray(_.pages))return null;const k=_.pages,r=k.findIndex(y=>F(y)&&y.id===i);if(r<0)return null;const m=Number.isFinite(v)?v:0;if(m===0)return null;const c=Math.max(0,Math.min(k.length-1,r+m));if(c===r)return null;const[b]=k.splice(r,1);return k.splice(c,0,b),_}function ie(_,i){if(!F(_)||!Array.isArray(_.pages))return null;const v=_.pages,k=v.findIndex(m=>F(m)&&m.id===i);if(k<0)return null;const[r]=v.splice(k,1);return _.selectedPageId===i&&(_.selectedPageId=v.length?v[Math.min(k,v.length-1)].id:null),r}function W(_,i){_.register("addPage",(v,k)=>{if(!v.designer.guardrails.allowsPage("add"))return de("designer:page:add","designer.addPage: adding a page is not allowed by guardrails.pages.add; nothing was added."),null;const r=v.getState(),m=fe(r,k,i);if(m===null||(r.selectedPageId=m,!v.commit(r,"addPage")))return null;const c=r.pages.find(b=>F(b)&&b.id===m);return v.designer.announce(i("a11y.designer.page.added",{title:c&&c.title!=null?c.title:m})),m}),_.register("renamePage",(v,k,r)=>{if(!v.designer.guardrails.allowsPage("rename"))return de("designer:page:rename","designer.renamePage: renaming a page is not allowed by guardrails.pages.rename; nothing was changed."),!1;const m=v.getState();if(!J(m,k,r)||!v.commit(m,"renamePage"))return!1;const c=m.pages.find(b=>F(b)&&b.id===k);return v.designer.announce(i("a11y.designer.page.renamed",{title:c&&c.title!=null?c.title:k})),!0}),_.register("movePage",(v,k,r)=>{if(!v.designer.guardrails.allowsPage("reorder"))return de("designer:page:reorder","designer.movePage: reordering a page is not allowed by guardrails.pages.reorder; nothing was moved."),!1;const m=v.getState();return Q(m,k,r)?v.commit(m,"movePage"):!1}),_.register("removePage",(v,k)=>{if(!v.designer.guardrails.allowsPage("remove"))return de("designer:page:remove","designer.removePage: removing a page is not allowed by guardrails.pages.remove; nothing was removed."),!1;const r=v.getState(),m=ie(r,k);if(!m)return!1;const c=m.title!=null?m.title:k;return v.commit(r,"removePage")?(v.designer.announce(i("a11y.designer.page.removed",{title:c})),!0):!1})}const L=W}),rt("packages/modules/designer/config-router.js",function(o,ce){"use strict";Object.defineProperty(o,"stateToConfigRows",{enumerable:!0,get:function(){return c}}),Object.defineProperty(o,"configRowsToState",{enumerable:!0,get:function(){return P}}),Object.defineProperty(o,"installConfigRouting",{enumerable:!0,get:function(){return E}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return d}});const ke=ce("packages/core/src/internal/util.js"),F=ke.warnOnce,l=ke.isFunction,de=ce("packages/modules/dashboard/spec.js"),z=de.isPlain,fe=de.copySpec,J=de.sameSpec,ie=ce("packages/modules/designer/migrate.js").SCHEMA_VERSION,W="page",L="filter",_="relationship",i="@page/",v="@filter/",k="@rel/";function r(w,G){const N={};for(const T of Object.keys(w))G.includes(T)||(N[T]=fe(w[T],T));return N}function m(w){return Array.isArray(w)&&w.length>0&&w.every(G=>z(G)&&G.id!=null&&String(G.id)!=="")}function c(w){const G=[];if(!z(w)||!Array.isArray(w.pages))return G;for(const N of w.pages){if(!z(N))continue;const T=N.id,C=z(N.spec)?N.spec:{},h=Array.isArray(C.panels)?C.panels.filter(z):[],$=z(C.layout)?C.layout:null,a=$&&Array.isArray($.windows)?$.windows.filter(z):[],n=new Set(h.map(B=>String(B.id))),t=["panels"],e=Array.isArray(C.links)&&C.links.length?C.links.filter(z):null;e&&t.push("links");const s=m(N.filters),x=r(C,t);if($){const B=a.filter(te=>!n.has(String(te.id))),Y=r($,["windows"]);B.length&&(Y.windows=B.map(te=>fe(te))),x.layout=Y}const S=r(N,["id","spec",...s?["filters"]:[]]);T===w.selectedPageId&&(S.selected=!0),G.push({id:`${i}${T}`,page:T,kind:W,source:null,mapping:S,format:x,placement:null,seq:0});for(const B of h){const Y=String(B.id),te=a.find(q=>String(q.id)===Y);G.push({id:Y,page:T,kind:B.kind,source:B.source!==void 0?B.source:null,mapping:B.options!==void 0?fe(B.options):null,format:r(B,["id","kind","source","options"]),placement:te?r(te,["id"]):null,seq:0})}e&&e.forEach((B,Y)=>G.push({id:`${k}${T}/${B.id!=null?B.id:`${B.from}->${B.to}`}#${Y}`,page:T,kind:_,source:B.from!==void 0?B.from:null,mapping:null,format:fe(B),placement:null,seq:0})),s&&N.filters.forEach((B,Y)=>G.push({id:`${v}${T}/${B.id}#${Y}`,page:T,kind:L,source:B.source!==void 0?B.source:null,mapping:null,format:fe(B),placement:null,seq:0}))}return G}function b(w){const G={id:w.id};return z(w.format)&&Object.assign(G,fe(w.format)),G.kind=w.kind,w.source!==null&&w.source!==void 0&&(G.source=w.source),w.mapping!==null&&w.mapping!==void 0&&(G.options=fe(w.mapping)),G}function y(w){return w.placement===null||w.placement===void 0?null:{id:w.id,...z(w.placement)?fe(w.placement):{}}}function P(w){const G=Array.isArray(w)?w.filter(z):[],N=new Map,T=[];for(const $ of G){const a=$.page;N.has(a)||(N.set(a,{meta:null,widgets:[],links:[],filters:[]}),T.push(a));const n=N.get(a);$.kind===W?n.meta=$:$.kind===_?n.links.push($):$.kind===L?n.filters.push($):n.widgets.push($)}const C=[];let h=null;for(const $ of T){const a=N.get($),n=a.meta,t={};n&&z(n.mapping)&&Object.assign(t,r(n.mapping,["selected"])),t.id=$,n&&z(n.mapping)&&n.mapping.selected&&(h=$);const e=n&&z(n.format)?fe(n.format):{},s=z(e.layout)&&Array.isArray(e.layout.windows)?e.layout.windows.map(x=>fe(x)):[];e.panels=a.widgets.map(x=>{const S=y(x);return S&&s.push(S),b(x)}),s.length&&(e.layout={...z(e.layout)?e.layout:{},windows:s}),a.links.length&&(e.links=a.links.map(x=>fe(x.format))),t.spec=e,a.filters.length&&(t.filters=a.filters.map(x=>fe(x.format))),C.push(t)}return h===null&&C.length&&(h=C[0].id),{schemaVersion:ie,pages:C,selectedPageId:h,panels:{}}}function u(w){return z(w)&&w.kind!==W&&w.kind!==L&&w.kind!==_}function E(w,G){const{commit:N,getState:T,selectedPageId:C,dashboard:h,guardrails:$,on:a}=G;let n=null,t=new Map,e=0;const s=Y=>{const te=new Map;for(const q of c(T()))q.page===Y&&te.set(q.id,q);return te},x=Y=>{if(!n)return;const te=n.page,q=[],ne=[],U=[],M=T(),R=Array.isArray(M.pages)?M.pages.find(O=>z(O)&&O.id===te):null,H=R&&z(R.spec)?R.spec:null,f=H&&Array.isArray(H.panels)?H.panels.filter(z):[],g=new Set(f.map(O=>String(O.id))),I=(O,X)=>{if(!u(O))return;const oe=b(O),ue=$()&&l($().restrictPanel)?$().restrictPanel(oe):null;if(ue){F(`designer:route:refused:${oe.id}`,`designer: the routed widget ${JSON.stringify(String(oe.id))} is not allowed here, so it was refused — the same answer the ${ue} guardrail gives an authored widget.`);return}X.push({panel:oe,window:y(O),id:String(oe.id)})};for(const O of Array.isArray(Y.add)?Y.add:[])I(O,q);for(const O of Array.isArray(Y.update)?Y.update:[])I(O,ne);for(const O of Array.isArray(Y.remove)?Y.remove:[]){const X=String(O);!X.startsWith(i)&&!X.startsWith(v)&&!X.startsWith(k)&&U.push(X)}if(!q.length&&!ne.length&&!U.length)return;const j=h();j&&l(j.applyConfig)&&te===C()&&j.applyConfig({add:q,update:ne,remove:U});const A=T(),D=Array.isArray(A.pages)?A.pages.find(O=>z(O)&&O.id===te):null;if(!D){j&&te===C()&&N(A,"route",{record:!1,render:!1});return}z(D.spec)||(D.spec={panels:[]}),Array.isArray(D.spec.panels)||(D.spec.panels=[]);const p=D.spec,se=()=>(z(p.layout)||(p.layout={}),Array.isArray(p.layout.windows)||(p.layout.windows=[]),p.layout.windows),V=({panel:O,window:X})=>{const oe=p.panels.findIndex(ue=>z(ue)&&String(ue.id)===String(O.id));if(oe<0?p.panels.push(O):p.panels[oe]=O,X){const ue=se(),xe=ue.findIndex(me=>z(me)&&String(me.id)===String(O.id));xe<0?ue.push(X):ue[xe]=X}};for(const O of ne)V(O);for(const O of q)g.has(O.id)||V(O);for(const O of U){const X=p.panels.findIndex(oe=>z(oe)&&String(oe.id)===O);if(X>=0&&p.panels.splice(X,1),z(p.layout)&&Array.isArray(p.layout.windows)){const oe=p.layout.windows.findIndex(ue=>z(ue)&&String(ue.id)===O);oe>=0&&p.layout.windows.splice(oe,1)}}N(A,"route",{record:!1,render:!(j&&te===C())})},S=Y=>{if(!n)return;const te=s(n.page),q=Y&&Y.cause;if(!(q==="route"||q==="setState"||q==="migrate")&&n.onWrite){for(const[U,M]of te){const R=t.get(U);(!R||!J(R,M))&&n.onWrite({op:"upsert",row:{...M,seq:++e},before:R||null},{route:n.page,page:n.page,source:"author"})}for(const[U,M]of t)te.has(U)||n.onWrite({op:"delete",row:{...M,seq:++e},before:M},{route:n.page,page:n.page,source:"author"})}t=te},B={rows(){return c(T())},toRows(Y){return c(Y)},fromRows(Y){return P(Y)},connect(Y,te={}){if(!Y||!l(Y.subscribe))return F("designer:config-router:connect","designer.configRouter.connect: the first argument is not a Data Router (no subscribe); nothing was connected."),()=>{};B.disconnect();const q=z(te)?te:{},ne=q.page!==void 0?q.page:C(),U={};return typeof q.label=="string"&&(U.label=q.label),l(q.filter)&&(U.filter=q.filter),l(q.transform)&&(U.transform=q.transform),Y.subscribe(ne,x,{rowKey:"id",...U}),n={router:Y,page:ne,onWrite:l(q.onWrite)?q.onWrite:null,offState:a("state",S)},t=s(ne),B.disconnect},disconnect(){n&&(n.offState&&n.offState(),n.router&&l(n.router.detach)&&n.router.detach(x),n=null,t=new Map)},get router(){return n?n.router:null},get page(){return n?n.page:null},explain(Y){return n&&l(n.router.explain)?n.router.explain(Y):null},get trace(){return n&&n.router.trace?n.router.trace:null},destroy(){B.disconnect()}};return B}const d=E}),rt("packages/modules/designer/data-routes.js",function(o,ce){"use strict";Object.defineProperty(o,"compileWidgetRoute",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"routeRequest",{enumerable:!0,get:function(){return G}}),Object.defineProperty(o,"issueQuery",{enumerable:!0,get:function(){return N}}),Object.defineProperty(o,"executeRouteOverRows",{enumerable:!0,get:function(){return C}}),Object.defineProperty(o,"installDataRouting",{enumerable:!0,get:function(){return h}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return $}});const ke=ce("packages/core/src/internal/util.js"),F=ke.warnOnce,l=ke.isFunction,de=ce("packages/modules/dashboard/spec.js"),z=de.isPlain,fe=de.sameSpec,Q=ce("packages/modules/designer/data-panel.js").compileRelationships,W=ce("packages/modules/designer/config-router.js").stateToConfigRows,_=ce("packages/modules/charts/capabilities.js").chartEditorModel,v=ce("packages/core/src/registry/widgets.js").widgetEditorModel,k=ce("packages/core/src/source/pushdown.js"),r=k.planQuery,m=k.capabilitiesOf,c=Object.freeze(["page","filter","relationship"]);function b(a){return z(a)&&!c.includes(a.kind)}function y(a,n){let t=a;for(const e of String(n).split(".")){if(t==null)return;t=t[e]}return t}function P(a){return a==null?"":typeof a=="string"?a:z(a)&&(a.col||a.field)||""}function u(a){const n=z(a.mapping)?a.mapping:{};return a.kind==="chart"||a.kind==="map"?_(typeof n.type=="string"&&n.type?n.type:"bar"):v(a.kind)}function E(a){return a===!0||z(a)&&a.enabled===!0}function d(a,n){const t=a.path||a.role,e=y(n,t),s=a.repeatable?Array.isArray(e)?e:[]:e==null||e===""?[]:[e],x=[];for(const S of s){const B=a.entryKey&&z(S)?S[a.entryKey]:P(S);if(!B)continue;let Y,te=!1;a.entryKey&&z(S)?(typeof S.total=="string"&&S.total&&(Y=S.total),te=E(S.group)||E(S.pivot)):z(S)&&typeof S.fn=="string"&&S.fn&&(Y=S.fn),x.push({role:a.role,field:String(B),fn:Y,group:te})}if(!a.repeatable&&a.aggregated&&a.aggPath&&x.length){const S=y(n,a.aggPath);typeof S=="string"&&S&&(x[0].fn=S)}return x}function w(a,n={}){if(!b(a))return null;const t=typeof a.source=="string"?a.source:null,e=Array.isArray(n.relationships)?n.relationships:[],s=Array.isArray(n.filters)?n.filters.filter(z):[],x=z(a.mapping)?a.mapping:{},S=u(a),B=[],Y=[];if(S&&Array.isArray(S.roles))for(const f of S.roles)Y.push(...d(f,x));const te=Q(e),q=f=>te.find(g=>g.sourceId===t&&g.relatedSourceId===f),ne=new Map,U=[],M=new Set,R=[],H=[];for(const f of Y){let g=f.field;const I=g.indexOf(".");if(I>0&&I<g.length-1){const j=g.slice(0,I),A=g.slice(I+1);if(j!==t){const D=q(j);if(!D){F(`designer:route:unreachable:${a.id}:${j}`,`designer: the widget ${JSON.stringify(a.id)}'s ${JSON.stringify(f.role)} role binds ${JSON.stringify(f.field)}, and no declared relationship reaches ${JSON.stringify(j)} from ${JSON.stringify(t)}; the field was left out of its route.`),B.push(`${f.role}: ${JSON.stringify(f.field)} is not reachable from ${JSON.stringify(t)}`);continue}ne.set(j,D),g=`${j}.${A}`}else g=A}M.has(g)||(M.add(g),U.push(g)),f.group&&!R.includes(g)&&R.push(g),f.fn&&H.push({id:`${f.role}:${g}`,col:g,fn:f.fn,role:f.role})}return{widgetId:a.id,page:a.page,kind:a.kind,sourceId:t,fields:U,groupBy:R,aggregates:H,joins:[...ne.values()],filters:{page:s.filter(f=>f.source===t),global:s.filter(f=>f.source===void 0||f.source===null)},refusals:B}}function G(a,n={}){const t=[...a.filters.page,...a.filters.global].filter(x=>x&&x.field!==void 0&&x.op!==void 0).map(x=>({col:x.field,op:x.op,value:x.value})),e=t.length===0?null:t.length===1?t[0]:{op:"and",conditions:t},s=a.groupBy.length>0||a.aggregates.length>0;return{fields:[...a.fields],filters:e,sort:s?null:Array.isArray(n.sort)?n.sort:null,range:s?null:n.range!==void 0?n.range:null}}async function N(a,n,t={}){const e=a.groupBy.length>0||a.aggregates.length>0,s=n&&l(n.executeGroupedAggregates);if(!n||!(e&&s)&&!l(n.execute))return F("designer:route:no-adapter","designer: issueQuery needs an adapter with an execute(query) function (or executeGroupedAggregates for a grouped route); nothing was asked."),{rows:[],total:0,plan:null};const x=G(a,t),S=m(n.capabilities),B=r(x,S),Y={...B.pushed,fields:a.fields};if(e&&s){const q=a.aggregates.map((H,f)=>`lattice_agg_${f}`),ne=a.aggregates.map((H,f)=>({id:q[f],col:H.col,fn:H.fn})),U=new Map(q.map((H,f)=>[H,a.aggregates[f].id])),M=await n.executeGroupedAggregates(Y,a.groupBy,ne);return{groups:(Array.isArray(M)?M:[]).map(H=>({...H,values:Object.fromEntries(Object.entries(H.values||{}).map(([f,g])=>[U.get(f)||f,g]))})),plan:B}}const te=await n.execute(Y,x)||{};return{rows:te.rows||[],total:te.total,plan:B}}const T=Object.freeze({sum:a=>a.reduce((n,t)=>n+(Number(t)||0),0),avg:a=>a.length?a.reduce((n,t)=>n+(Number(t)||0),0)/a.length:null,min:a=>a.length?a.reduce((n,t)=>t<n?t:n):null,max:a=>a.length?a.reduce((n,t)=>t>n?t:n):null,count:a=>a.length,countDistinct:a=>new Set(a).size,median:a=>{if(!a.length)return null;const n=[...a].map(Number).sort((e,s)=>e-s),t=Math.floor(n.length/2);return n.length%2?n[t]:(n[t-1]+n[t])/2}});function C(a,n){let e=(Array.isArray(n[a.sourceId])?n[a.sourceId]:[]).map(x=>({...x}));for(const x of a.joins){const S=Array.isArray(n[x.relatedSourceId])?n[x.relatedSourceId]:[];if(x.type==="one-to-many"){const B=x.join.as;e=e.map(Y=>({...Y,[B]:S.filter(te=>te[x.join.foreignKey]===Y[x.join.localKey])}))}else{const B=new Map(S.map(Y=>[Y[x.join.foreignKey],Y]));e=e.map(Y=>{const te=B.get(Y[x.join.localKey]),q={...Y};if(te)for(const ne of Object.keys(te))q[`${x.relatedSourceId}.${ne}`]=te[ne];return q})}}if(!a.groupBy.length&&!a.aggregates.length)return{rows:e.map(x=>Object.fromEntries(a.fields.map(S=>[S,x[S]])))};const s=new Map;for(const x of e){const S=a.groupBy.map(Y=>x[Y]),B=JSON.stringify(S);s.has(B)||s.set(B,{keys:S,rows:[]}),s.get(B).rows.push(x)}return{groups:[...s.values()].map(x=>({keys:x.keys,values:Object.fromEntries(a.aggregates.map(S=>[S.id,(T[S.fn]||T.sum)(x.rows.map(B=>B[S.col]))]))}))}}function h(a){const n=new Map,t=new Map,e=[];let s=new Map,x=new Map,S=0;const B=H=>{const f=a.getState(),g=Array.isArray(f.pages)?f.pages.find(I=>z(I)&&I.id===H):null;return g&&Array.isArray(g.filters)?g.filters:[]},Y=H=>({relationships:a.context.relationships,filters:B(H)}),te=H=>{const f=a.context.sources;return z(f)?f[H]:void 0},q=()=>{const H=a.context.sources,f={};if(z(H))for(const g of Object.keys(H)){const I=H[g];z(I)&&I.kind==="rows"&&Array.isArray(I.rows)&&(f[g]=I.rows)}return f},ne=H=>{const f=te(H.sourceId);!z(f)||f.kind!=="rows"||(S+=1,e.push({widgetId:H.widgetId,seq:S}),t.set(H.widgetId,C(H,q())))},U=H=>{const f=w(H,Y(H.page));f&&(n.set(H.id,f),ne(f))},M=()=>{const H=new Map;for(const j of W(a.getState()))b(j)&&H.set(j.id,j);const f=new Set([...H.values()].map(j=>j.page)),g=new Set,I=new Map;for(const j of f){const A=B(j);I.set(j,A),fe(x.get(j)||[],A)||g.add(j)}x=I;for(const[j,A]of H){const D=s.get(j);(!D||!fe(D,A)||g.has(A.page))&&U(A)}for(const j of s.keys())H.has(j)||(n.delete(j),t.delete(j));s=H},R=a.on("state",M);return M(),{routes(){return[...n.values()]},route(H){return n.get(H)||null},result(H){return t.get(H)||null},requests(){return e.slice()},explain(){const H={};for(const[f,g]of n)H[f]=g;return H},refresh(){s=new Map,x=new Map,M()},destroy(){R(),n.clear(),t.clear(),s=new Map,x=new Map}}}const $=h}),rt("packages/modules/designer/filters.js",function(o,ce){"use strict";Object.defineProperty(o,"FILTER_TYPES",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(o,"DEFAULT_OPERATOR",{enumerable:!0,get:function(){return J}}),Object.defineProperty(o,"DATE_PRESETS",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(o,"datePresetRange",{enumerable:!0,get:function(){return k}}),Object.defineProperty(o,"filterPredicate",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"rootSourceOf",{enumerable:!0,get:function(){return m}}),Object.defineProperty(o,"compileClickFilterLinks",{enumerable:!0,get:function(){return c}}),Object.defineProperty(o,"filterChipText",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"installFilters",{enumerable:!0,get:function(){return u}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return E}});const F=ce("packages/modules/dashboard/spec.js").isPlain,de=ce("packages/modules/designer/messages.js").resolveMessages,fe=ce("packages/modules/designer/palette.js").FILTER_TYPES,J=Object.freeze({list:"in",range:"between",dateRange:"between",search:"contains"}),Q=Object.freeze(["last7","last30","last90","thisMonth","thisQuarter","thisYear","custom"]),ie="designer.filters.add",W="designer.filters.remove",L="designer.filters.setValue",_="designer.filters.clearAll",i="designer.filters.setClickFilter",v=d=>`${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,"0")}-${String(d.getDate()).padStart(2,"0")}`;function k(d,w=new Date){const G=new Date(w.getFullYear(),w.getMonth(),w.getDate());if(d==="last7"||d==="last30"||d==="last90"){const N={last7:7,last30:30,last90:90}[d],T=new Date(G);return T.setDate(T.getDate()-(N-1)),{from:v(T),to:v(G)}}if(d==="thisMonth")return{from:v(new Date(G.getFullYear(),G.getMonth(),1)),to:v(G)};if(d==="thisQuarter"){const N=Math.floor(G.getMonth()/3);return{from:v(new Date(G.getFullYear(),N*3,1)),to:v(G)}}return d==="thisYear"?{from:v(new Date(G.getFullYear(),0,1)),to:v(G)}:null}function r(d){if(!F(d)||typeof d.field!="string"||d.field==="")return null;const w=d.field;if(d.type==="list"){const G=Array.isArray(d.value)?d.value.filter(T=>T!==""&&T!=null).map(String):[];if(!G.length)return null;const N=new Set(G);return{fn:T=>N.has(String(T[w])),condition:{col:w,op:"in",value:G}}}if(d.type==="range"){const G=Array.isArray(d.value)?d.value:[],N=G[0]===""||G[0]==null?null:Number(G[0]),T=G[1]===""||G[1]==null?null:Number(G[1]),C=Number.isFinite(N)?N:null,h=Number.isFinite(T)?T:null;if(C===null&&h===null)return null;const $=a=>{const n=Number(a[w]);return!(Number.isNaN(n)||C!==null&&n<C||h!==null&&n>h)};return C!==null&&h!==null?{fn:$,condition:{col:w,op:"between",value:[C,h]}}:{fn:$,condition:C!==null?{col:w,op:"gte",value:C}:{col:w,op:"lte",value:h}}}if(d.type==="dateRange"){const G=F(d.value)?d.value:{},N=typeof G.from=="string"&&G.from!==""?G.from:null,T=typeof G.to=="string"&&G.to!==""?G.to:null;if(!N&&!T)return null;const C=h=>{const $=h[w];if($==null)return!1;const a=String($).slice(0,10);return!(N&&a<N||T&&a>T)};return N&&T?{fn:C,condition:{col:w,op:"between",value:[N,T]}}:{fn:C,condition:N?{col:w,op:"gte",value:N}:{col:w,op:"lte",value:T}}}if(d.type==="search"){const G=typeof d.value=="string"?d.value.trim():"";if(!G)return null;const N=G.toLowerCase();return{fn:T=>String(T[w]??"").toLowerCase().includes(N),condition:{col:w,op:"contains",value:G}}}return null}function m(d,w,G=new Set){if(G.has(w))return null;G.add(w);const N=d.find(T=>F(T)&&T.id===w);return!N||typeof N.source!="string"||N.source===""?null:N.source.startsWith("grid:")?m(d,N.source.slice(5),G):N.source}function c(d,w){const G=[],N=F(w)?w:{};for(const T of d){if(!F(T))continue;const C=F(N[T.id])?N[T.id]:null,h=C&&F(C.clickFilter)?C.clickFilter:null;if(!h||typeof h.on!="string"||h.on==="")continue;const $=h.targets==="all"?d.filter(a=>F(a)&&a.id!==T.id).map(a=>a.id):Array.isArray(h.targets)?h.targets.filter(a=>a!==T.id&&d.some(n=>F(n)&&n.id===a)):[];for(const a of $)G.push({from:T.id,to:a,on:h.on})}return G}function b(d,w){if(!F(d))return"";const G=d.field;if(d.type==="list"){const N=Array.isArray(d.value)?d.value.filter(T=>T!==""&&T!=null):[];return N.length?`${G} = ${N.join(", ")}`:""}if(d.type==="range"){const N=Array.isArray(d.value)?d.value:[];return(N[0]===""||N[0]==null)&&(N[1]===""||N[1]==null)?"":`${G} ${N[0]??""}–${N[1]??""}`}if(d.type==="dateRange"){const N=F(d.value)?d.value:{};if(!N.from&&!N.to)return"";const T=typeof N.preset=="string"&&N.preset!=="custom"?w(`designer.filter.preset.${N.preset}`):`${N.from||""}–${N.to||""}`;return`${G}: ${T}`}return d.type==="search"&&typeof d.value=="string"&&d.value.trim()?`${G} ${w("designer.filter.contains")} "${d.value.trim()}"`:""}const y=d=>Array.isArray(d.filters)?d.filters.filter(F):[],P=d=>d&&Array.isArray(d.filters)?d.filters.filter(F):[];function u(d,w={}){const G=de(w&&w.messages),N=d.rails.filterBar,T=N.ownerDocument;let C=!1;const h=()=>{const ne=d.getState();return ne.pages.find(U=>F(U)&&U.id===ne.selectedPageId)||null},$=()=>{const ne=d.getState(),U=h();return[...y(ne).map(M=>({...M,scope:"global"})),...P(U).map(M=>({...M,scope:"page"}))]},a=()=>{const ne=d.dashboard;if(!ne)return;const U=h();if(!U||!F(U.spec)||!Array.isArray(U.spec.panels))return;const M=U.spec.panels.filter(F),R=$(),H=new Set(R.map(f=>`designer:filter:${f.id}`));for(const f of M){const g=ne.panel(f.id);if(!g||!g.grid)continue;const I=m(M,f.id),j=g.grid.filters.where()||[];for(const A of j)A.startsWith("designer:filter:")&&!H.has(A)&&g.grid.filters.where(A,null);for(const A of R){if(A.source!==I)continue;const D=`designer:filter:${A.id}`,p=r(A);if(!p){g.grid.filters.where(D,null);continue}g.grid.filters.where(D,p.fn,{condition:p.condition,deps:[A.field]})}}},n=(ne,U,M)=>{if(U==="global"){const f=M(y(ne));return(f.length||Array.isArray(ne.filters))&&(ne.filters=f),!0}const R=ne.pages.find(f=>F(f)&&f.id===ne.selectedPageId);if(!R)return!1;const H=M(P(R));return(H.length||Array.isArray(R.filters))&&(R.filters=H),!0};d.commands.register(ie,(ne,U)=>{const M=F(U)?U:{};if(!fe.includes(M.type)||typeof M.source!="string"||M.source===""||typeof M.field!="string"||M.field==="")return null;const R=M.scope==="global"?"global":"page",H=ne.getState(),f=H.pages.find(D=>F(D)&&D.id===H.selectedPageId),g=new Set([...y(H),...P(f)].map(D=>D.id));let I=g.size+1;for(;g.has(`filter-${I}`);)I+=1;const j=`filter-${I}`;return!n(H,R,D=>[...D,{id:j,type:M.type,source:M.source,field:M.field,operator:J[M.type]}])||!ne.commit(H,"addFilter")?null:j}),d.commands.register(W,(ne,U)=>{const M=ne.getState();let R=!1;const H=f=>{const g=f.filter(I=>I.id!==U);return g.length!==f.length&&(R=!0),g};return n(M,"global",H),n(M,"page",H),R?ne.commit(M,"removeFilter"):!1}),d.commands.register(L,(ne,U,M,R)=>{const H=ne.getState();let f=!1;const g=j=>j.map(A=>A.id!==U?A:(f=!0,{...A,value:M}));if(n(H,"global",g),n(H,"page",g),!f)return!1;const I=F(R)?R:{};return ne.commit(H,"setFilterValue",I.coalesce!==void 0?{coalesce:I.coalesce}:void 0)}),d.commands.register(_,ne=>{const U=ne.getState();let M=!1;const R=H=>H.map(f=>{if(f.value===void 0)return f;M=!0;const{value:g,...I}=f;return I});return n(U,"global",R),n(U,"page",R),M?ne.commit(U,"clearFilters"):!1}),d.commands.register(i,(ne,U,M)=>{const R=ne.getState(),H=R.pages.find(I=>F(I)&&I.id===R.selectedPageId);if(!H||!F(H.spec)||!Array.isArray(H.spec.panels))return!1;const f=H.spec.panels.filter(F);if(!f.some(I=>I.id===U))return!1;F(R.panels)||(R.panels={});const g={...F(R.panels[U])?R.panels[U]:{}};return M==null?delete g.clickFilter:g.clickFilter={targets:M.targets==="all"?"all":Array.isArray(M.targets)?[...M.targets]:[],on:M.on},Object.keys(g).length?R.panels[U]=g:delete R.panels[U],H.spec.links=c(f,R.panels),ne.commit(R,"setClickFilter")}),N.className="lattice-designer-filterbar",N.setAttribute("role","region"),N.setAttribute("aria-label",G("designer.filterbar"));const t=(ne,U)=>{const M=T.createElement("label");M.className="lattice-designer-filter-field";const R=T.createElement("span");return R.className="lattice-designer-filter-field-label",R.textContent=ne,M.appendChild(R),M.appendChild(U),M},e=(ne,U,M,R)=>{const H=T.createElement("select");H.setAttribute("aria-label",ne);for(const f of M){const g=T.createElement("option");g.value=f.value,g.textContent=f.label,H.appendChild(g)}return H.value=U,H.addEventListener("change",()=>R(H.value)),H},s=ne=>{const U=`filter-value-${ne.id}`;if(ne.type==="list"){const R=T.createElement("input");return R.type="text",R.setAttribute("aria-label",G("designer.filter.value",{field:ne.field})),R.placeholder=G("designer.filter.list.placeholder"),R.value=Array.isArray(ne.value)?ne.value.join(", "):"",R.addEventListener("change",()=>{const H=R.value.split(",").map(f=>f.trim()).filter(Boolean);d.commands.run(L,ne.id,H.length?H:void 0)}),R}if(ne.type==="range"){const R=T.createElement("span");R.className="lattice-designer-filter-range";const H=Array.isArray(ne.value)?ne.value:["",""],f=(j,A)=>{const D=j===""&&A===""?void 0:[j,A];d.commands.run(L,ne.id,D,{coalesce:U})},g=T.createElement("input");g.type="number",g.setAttribute("aria-label",G("designer.filter.min",{field:ne.field})),g.value=H[0]??"";const I=T.createElement("input");return I.type="number",I.setAttribute("aria-label",G("designer.filter.max",{field:ne.field})),I.value=H[1]??"",g.addEventListener("change",()=>f(g.value,I.value)),I.addEventListener("change",()=>f(g.value,I.value)),R.appendChild(g),R.appendChild(I),R}if(ne.type==="dateRange"){const R=T.createElement("span");R.className="lattice-designer-filter-daterange";const H=F(ne.value)?ne.value:{},f=typeof H.preset=="string"&&Q.includes(H.preset)?H.preset:"custom",g=Q.map(p=>({value:p,label:G(`designer.filter.preset.${p}`)})),I=T.createElement("input");I.type="date",I.setAttribute("aria-label",G("designer.filter.from",{field:ne.field})),I.value=H.from||"";const j=T.createElement("input");j.type="date",j.setAttribute("aria-label",G("designer.filter.to",{field:ne.field})),j.value=H.to||"";const A=()=>{const p=I.value||j.value?{preset:"custom",from:I.value||void 0,to:j.value||void 0}:void 0;d.commands.run(L,ne.id,p)};I.addEventListener("change",A),j.addEventListener("change",A);const D=e(G("designer.filter.preset",{field:ne.field}),f,g,p=>{if(p==="custom"){A();return}const se=k(p);d.commands.run(L,ne.id,{preset:p,from:se.from,to:se.to})});return I.disabled=f!=="custom",j.disabled=f!=="custom",R.appendChild(D),R.appendChild(I),R.appendChild(j),R}const M=T.createElement("input");return M.type="search",M.setAttribute("aria-label",G("designer.filter.value",{field:ne.field})),M.value=typeof ne.value=="string"?ne.value:"",M.addEventListener("input",()=>{d.commands.run(L,ne.id,M.value.trim()===""?void 0:M.value,{coalesce:U})}),M},x=(ne,U)=>{const M=T.createElement("span");if(M.className="lattice-designer-filter",M.setAttribute("data-filter",ne.id),M.setAttribute("data-scope",ne.scope),M.appendChild(t(ne.field,s(ne))),U){const R=T.createElement("button");R.type="button",R.className="lattice-designer-filter-remove",R.setAttribute("aria-label",G("designer.filter.remove",{field:ne.field})),R.textContent="×",R.addEventListener("click",()=>d.commands.run(W,ne.id)),M.appendChild(R)}return M},S=()=>{const ne=h(),U=d.dataPanel&&typeof d.dataPanel.sources=="function"?d.dataPanel.sources():[],M=T.createElement("span");if(M.className="lattice-designer-filter-add",!U.length||!ne)return M;let R="page",H=fe[0],f=U[0].id;const g=V=>(U.find(O=>O.id===V)||{fields:[]}).fields;let I=g(f)[0]&&g(f)[0].id;const j=e(G("designer.filter.scope"),R,[{value:"page",label:G("designer.filter.scope.page")},{value:"global",label:G("designer.filter.scope.global")}],V=>{R=V}),A=e(G("designer.filter.type"),H,fe.map(V=>({value:V,label:G(`designer.palette.filter.${V}`)})),V=>{H=V}),D=e(G("designer.filter.source"),f,U.map(V=>({value:V.id,label:V.id})),V=>{f=V,I=g(f)[0]&&g(f)[0].id,p.textContent="";for(const O of g(f)){const X=T.createElement("option");X.value=O.id,X.textContent=O.label||O.id,p.appendChild(X)}I&&(p.value=I)}),p=e(G("designer.filter.field"),I||"",g(f).map(V=>({value:V.id,label:V.label||V.id})),V=>{I=V}),se=T.createElement("button");return se.type="button",se.textContent=G("designer.filter.add"),se.setAttribute("aria-label",G("designer.filter.add")),se.addEventListener("click",()=>{I&&d.commands.run(ie,{scope:R,type:H,source:f,field:I})}),M.appendChild(j),M.appendChild(A),M.appendChild(D),M.appendChild(p),M.appendChild(se),M},B=()=>{if(C)return;N.textContent="";const ne=$();if(!ne.length&&d.mode!=="edit")return;const U=d.mode==="edit",M=T.createElement("span");M.className="lattice-designer-filterbar-controls";for(const H of ne)M.appendChild(x(H,U));N.appendChild(M);const R=ne.map(H=>b(H,G)).filter(Boolean);if(R.length||U){const H=T.createElement("span");H.className="lattice-designer-filterbar-context",H.setAttribute("role","status"),H.setAttribute("aria-label",G("designer.filterbar.context"));for(const f of R){const g=T.createElement("span");g.className="lattice-designer-filterbar-chip",g.textContent=f,H.appendChild(g)}if(R.length){const f=T.createElement("button");f.type="button",f.className="lattice-designer-filterbar-clear",f.textContent=G("designer.filterbar.clearAll"),f.setAttribute("aria-label",G("designer.filterbar.clearAll")),f.addEventListener("click",()=>d.commands.run(_)),H.appendChild(f)}N.appendChild(H)}U&&N.appendChild(S())},Y=()=>{B(),a()},te=d.on("state",Y),q=d.on("mode",Y);return Y(),{get el(){return N},active(){return $()},addFilter(ne){return d.commands.run(ie,ne)},removeFilter(ne){return d.commands.run(W,ne)},setValue(ne,U){return d.commands.run(L,ne,U)},clearAll(){return d.commands.run(_)},setClickFilter(ne,U){return d.commands.run(i,ne,U)},refresh:Y,destroy(){C||(C=!0,te(),q(),N.textContent="")}}}const E=u}),rt("packages/modules/designer/pushdown.js",function(o,ce){"use strict";Object.defineProperty(o,"DEFAULT_DEBOUNCE_MS",{enumerable:!0,get:function(){return i}}),Object.defineProperty(o,"PUSHDOWN_STEPS",{enumerable:!0,get:function(){return k}}),Object.defineProperty(o,"mapEngineType",{enumerable:!0,get:function(){return r}}),Object.defineProperty(o,"normaliseSchema",{enumerable:!0,get:function(){return c}}),Object.defineProperty(o,"describeSource",{enumerable:!0,get:function(){return b}}),Object.defineProperty(o,"aggregationRefusal",{enumerable:!0,get:function(){return u}}),Object.defineProperty(o,"stepRefusal",{enumerable:!0,get:function(){return E}}),Object.defineProperty(o,"refusalsOf",{enumerable:!0,get:function(){return d}}),Object.defineProperty(o,"provenanceFor",{enumerable:!0,get:function(){return w}}),Object.defineProperty(o,"installPushdown",{enumerable:!0,get:function(){return N}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return T}});const F=ce("packages/core/src/internal/util.js").isFunction,de=ce("packages/modules/dashboard/spec.js").isPlain,fe=ce("packages/core/src/source/pushdown.js").capabilitiesOf,J=ce("packages/core/src/source/aggregates.js"),Q=J.STAT_PUSHDOWN,ie=J.routeAggregate,W=J.resolveAggregatesConfig,_=ce("packages/core/src/source/abort.js").SupersededError,i=150,v=new Set(["profile","distribution","correlation","groupComparison","modelError","forecast"]),k=Object.freeze(["filter","sort","group","pivot","total"]);function r(C){let h=String(C??"").trim();for(let t=0;t<4;t++){const e=/^(Nullable|LowCardinality|SimpleAggregateFunction)\((.*)\)$/i.exec(h);if(!e)break;h=e[2].trim()}const $=h.toLowerCase();if(!$)return"text";const a={currency:"currency",percent:"percent",ratio:"percent",percentrate:"percent",datestring:"date",usd:"currency",eur:"currency",gbp:"currency",jpy:"currency"}[$];if(a)return a;if(/\[\]$/.test($)||/^(array|list)\b/.test($))return"list";if(/^(struct|map|nested|object|json)/.test($))return"text";const n=$.replace(/^edm\./,"").replace(/\(.*$/,"").replace(/\s.*$/,"");return/^(bool|boolean)$/.test(n)?"boolean":/^(datetime|timestamp|timestamptz|datetimeoffset|date_nanos|_time|instant)/.test(n)||/^timestamp/.test($)?"datetime":/^(date|dateonly)$/.test(n)?"date":/^(geometry|geography|geo_point|geo_shape|point|wkb_blob)/.test(n)?"geometry":/^(decimal|numeric|money|currency)$/.test(n)||/^(u?int\d*|u?tinyint|u?smallint|u?bigint|u?hugeint|integer|long|short|byte|sbyte|float\d*|double|real|half_float|scaled_float|number|single)$/.test(n)?"number":"text"}function m(C){const h=String(C).replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim();return h?h.charAt(0).toUpperCase()+h.slice(1):String(C)}function c(C){let h=[];if(C instanceof Map)h=[...C.entries()].map(([$,a])=>[String($),a]);else if(Array.isArray(C)){for(const $ of C)if(typeof $=="string")h.push([$,void 0]);else if(de($)){const a=$.name??$.field??$.id??$.column_name??$.column;a!=null&&h.push([String(a),$.type??$.column_type??$.dataType??$.datatype])}}else de(C)&&(h=Object.entries(C).map(([$,a])=>[$,de(a)?a.type??a.column_type:a]));return h.map(([$,a])=>{const n=a==null?void 0:String(a);return{id:$,label:m($),type:r(n),...n?{engineType:n}:{},declared:!1}})}async function b(C){const h=de(C)||C&&typeof C=="object"?C.adapter:null;if(h&&F(h.describe)){const $=await h.describe(),a=c($);if(a.length)return a}if(h){const $=h.schema??h.columns;if($&&!F($)){const a=c($);if(a.length)return a}}return c(Array.isArray(C&&C.columns)?C.columns:[])}function y(C){const h=C&&C.adapter;return h&&typeof h.name=="string"&&h.name?h.name:"pushdown"}function P(C){const h=C.aggregates;return h?h instanceof Set?h:new Set(Array.isArray(h)?h:[h]):new Set}function u(C,h){const $=C&&C.adapter,a=y(C);if(!$||!(F($.executeAggregates)||F($.executeGroupedAggregates)))return`the ${a} adapter has no aggregate query, so "${h}" would be computed over the loaded window`;const n=Q[h];if(n&&!n.pushable)return`the engine cannot express "${h}" (${n.note||"no SQL equivalent"}), so it would be computed over the loaded window`;const t=fe($.capabilities),e=P(t);return e.size&&!e.has(h)?`the ${a} adapter does not compute "${h}"`:ie(h,W(C.aggregates))==="client"?`the source is configured to compute "${h}" in the client, over the loaded window`:""}function E(C,h){const $=C&&C.adapter,a=y(C),n=fe($&&$.capabilities),t=P(n).size>0&&$&&F($.executeGroupedAggregates);return h==="filter"?n.filter?"":`the ${a} adapter does not declare the \`filter\` capability`:h==="sort"?n.sort?"":`the ${a} adapter does not declare the \`sort\` capability`:h==="group"?n.group||t?"":`the ${a} adapter does not declare the \`group\` capability`:h==="pivot"?n.pivot?"":`the ${a} adapter does not declare the \`pivot\` capability`:h==="total"?n.group||t||$&&F($.executeAggregates)?"":`the ${a} adapter can neither group nor aggregate, so a total would be the loaded window's`:""}function d(C,h=Object.keys(Q)){const $=[];for(const a of k){const n=E(C,a);n&&$.push({kind:"step",name:a,reason:n})}for(const a of h){const n=u(C,a);n&&$.push({kind:"aggregation",name:a,reason:n})}return $}function w(C,h){if(!C)return null;const $=C.viewer,a=C.grid,n=a&&F(a.config)?a.config():null,t=n&&n.source&&typeof n.source=="object"?n.source:null;if(!t||!F(t.aggregate))return null;if(C.kind==="chart"&&h==="profile"){const x=C.el&&C.el.textContent?C.el.textContent:"";return/computed in the data engine/.test(x)?{computed:"engine",reason:null,measures:[]}:/computing in the data engine/.test(x)?{computed:"pending",reason:null,measures:[]}:/returned no answer/.test(x)?{computed:"client",reason:"the data engine returned no answer for the profile",measures:[]}:/column profile/.test(x)?{computed:"client",reason:"the profile was computed over the loaded window",measures:[]}:{computed:"pending",reason:null,measures:[]}}if(C.kind==="chart"&&$&&F($.provenance)){const x=$.provenance();return x.pending?{computed:"pending",reason:null,measures:x.measures||[]}:{computed:x.source==="engine"?"engine":"client",reason:x.reason||null,measures:x.measures||[]}}if(C.kind==="kpi"&&$&&F($.tiles)){const x=$.tiles();if(!x.length)return{computed:"pending",reason:null,measures:[]};const S=x.find(B=>B.computed!=="engine");return{computed:S?"client":"engine",reason:S?`the "${S.label}" tile was computed client-side`:null,measures:x.map(B=>({col:B.field??null,fn:B.agg??B.fn??"",computed:B.computed==="engine"?"engine":"client"}))}}const e=F(t.lastPlan)?t.lastPlan():null;if(!e)return{computed:"pending",reason:null,measures:[]};const s=Array.isArray(e.unpushed)?e.unpushed:[];return{computed:s.length?"client":"engine",reason:s.length?`not pushed: ${s.join(", ")}`:null,measures:[]}}function G(C,h){const $={...C};for(const a of["executeAggregates","executeGroupedAggregates"])F(C[a])&&($[a]=(...n)=>h(()=>C[a](...n)));return $}function N(C,h={},$=a=>a){const a=de(C.context&&C.context.sources)?C.context.sources:{},n=Number(h&&h.pushdownDebounceMs);let t=Number.isFinite(n)&&n>=0?n:i,e=!1;const s=new Map,x=new Set,S=new Map;let B=[],Y=null,te=null;const q={queries:0,superseded:0},ne=()=>{for(const re of[...x])re()},U=re=>!!(re.signal&&re.signal.aborted),M=re=>{q.superseded+=1,re.reject(new _("designer:aggregate"))},R=()=>{Y=null;const re=B;B=[];for(const le of re){if(U(le)){M(le);continue}q.queries+=1,Promise.resolve().then(le.run).then(pe=>{U(le)?M(le):le.resolve(pe)},le.reject)}},H=()=>{Y&&clearTimeout(Y),Y=setTimeout(R,t)},f=(re,le)=>new Promise((pe,he)=>{if(e){Promise.resolve().then(re).then(pe,he);return}B.push({signal:le,run:re,resolve:pe,reject:he}),H()}),g=de(h&&h.factories)?h.factories:null,I=globalThis.LatticeGrid||{},j=g&&(F(g.createPushdownSource)?g.createPushdownSource:I.createPushdownSource);let A=null;if(g&&F(j)){const re=Object.prototype.hasOwnProperty.call(g,"createPushdownSource"),le=g.createPushdownSource;g.createPushdownSource=(...pe)=>{const he=j(...pe);if(he&&F(he.aggregate)){const Me=he.aggregate.bind(he);try{he.aggregate=(Ie,Ke,qe)=>f(()=>Me(Ie,Ke,qe),Ie&&Ie.signal)}catch{}}return he},A=()=>{re?g.createPushdownSource=le:delete g.createPushdownSource}}else for(const re of Object.keys(a)){const le=a[re];de(le)&&le.kind==="pushdown"&&le.adapter&&typeof le.adapter=="object"&&(S.set(re,le),a[re]={...le,adapter:G(le.adapter,f)})}const D=re=>{let le=s.get(re);if(le)return le;const pe=a[re];return le={fields:null,error:null,promise:null},s.set(re,le),le.promise=b(pe).then(he=>{le.fields=he},he=>{le.fields=[],le.error=he&&he.message?he.message:String(he)}).then(()=>{if(e)return;const he=a[re];le.fields.length&&de(he)&&!Array.isArray(he.columns)&&(a[re]={...he,columns:le.fields.map(Me=>({field:Me.id,type:Me.type}))},V(re)&&O()),ne()}),le},p=re=>{const le=a[re];return de(le)&&le.kind==="pushdown"?le:null},se=re=>{let le=typeof re=="string"?re:null;const pe=C.getState(),he=pe.pages.find(Ie=>de(Ie)&&Ie.id===pe.selectedPageId),Me=he&&de(he.spec)&&Array.isArray(he.spec.panels)?he.spec.panels:[];for(let Ie=0;le&&Ie<12;Ie++){if(!le.startsWith("grid:"))return le;const Ke=Me.find(ot=>de(ot)&&ot.id===le.slice(5)),qe=de(pe.panels)?pe.panels[le.slice(5)]:null;if(qe&&de(qe.derived))le=`grid:${qe.derived.from}`;else if(Ke)le=typeof Ke.source=="string"?Ke.source:null;else return le.slice(5)}return null},V=re=>oe().some(le=>se(le.source)===re),O=()=>{C.setGuardrails(C.guardrails.value)};for(const re of Object.keys(a))p(re)&&D(re);const X=(re,le)=>{const pe=y(le);return re.computed==="engine"?$("designer.pushdown.engine",{adapter:pe}):re.computed==="pending"?$("designer.pushdown.pending",{adapter:pe}):$("designer.pushdown.client",{reason:re.reason||$("designer.pushdown.noReason")})},oe=()=>{const re=C.getState(),le=re.pages.find(pe=>de(pe)&&pe.id===re.selectedPageId);return le&&de(le.spec)&&Array.isArray(le.spec.panels)?le.spec.panels.filter(de):[]},ue=re=>{const le=C.dashboard,pe=le&&F(le.panel)?le.panel(re):null,he=oe().find(qe=>qe.id===re),Me=he?se(he.source):null,Ie=Me?p(Me):null;if(!Ie)return null;const Ke=w(pe,he&&he.options?he.options.type:void 0);return Ke?{...Ke,source:Me,text:X(Ke,Ie)}:null},xe=new WeakSet,me=()=>{const re=C.dashboard;if(!(!re||!F(re.panel)))for(const le of oe()){if(le.kind!=="chart"||!le.options||!v.has(le.options.type))continue;const pe=se(le.source);if(!pe||!p(pe))continue;const he=re.panel(le.id),Me=he&&he.grid;if(!Me||xe.has(Me)||!F(Me.rendererHost))continue;const Ie=Me.rendererHost();Ie&&F(Ie.hint)&&(xe.add(Me),Ie.hint(0,1))}},we=()=>{if(e||!C.canvas||!Object.keys(a).some(pe=>p(pe)))return!0;me();let re=!0;const le=[...C.canvas.querySelectorAll(".lat-layout__window")];for(const pe of le){const he=pe.getAttribute("data-window-id"),Me=he?ue(he):null,Ie=pe.querySelector(".lattice-designer-info");if(!Me){Ie&&Ie.remove();continue}Me.computed==="pending"&&(re=!1);const Ke=Ie||C.canvas.ownerDocument.createElement("span");Ie||(Ke.className="lattice-designer-info",Ke.setAttribute("role","img"),Object.assign(Ke.style,{display:"inline-flex",marginLeft:"6px",fontSize:"0.85em",cursor:"help",color:"var(--lattice-foreground-muted, inherit)"}),Ke.textContent="ⓘ",(pe.querySelector(".lat-layout__chrome")||pe).appendChild(Ke)),Ke.setAttribute("title",Me.text),Ke.setAttribute("aria-label",Me.text),Ke.setAttribute("data-computed",Me.computed)}return re},Pe=(re=40)=>{te&&clearTimeout(te),te=setTimeout(()=>{if(te=null,e)return;!we()&&re>0&&Pe(re-1)},Math.max(60,t/2))},Fe=C.on("state",()=>{B.length&&H(),Pe()}),Z=C.on("mode",()=>Pe());return Pe(),{fields(re){return p(re)?D(re).fields:null},describe(re){if(!p(re))return Promise.resolve([]);const le=D(re);return le.promise.then(()=>le.fields||[])},isPushdown(re){return!!p(se(re))},refusals(re,le){const pe=p(se(re));return pe?d(pe,le):[]},refusal(re,le){const pe=p(se(re));return!pe||!de(le)?"":typeof le.aggregation=="string"?u(pe,le.aggregation):typeof le.step=="string"?E(pe,le.step):""},provenance:ue,refreshInfo(){we()},stats(){return{...q,held:B.length}},onChange(re){return x.add(re),()=>x.delete(re)},get debounceMs(){return t},set debounceMs(re){const le=Number(re);Number.isFinite(le)&&le>=0&&(t=le)},destroy(){if(e)return;e=!0,Fe(),Z(),Y&&clearTimeout(Y),te&&clearTimeout(te);const re=B;B=[];for(const le of re)Promise.resolve().then(le.run).then(le.resolve,le.reject);for(const[le,pe]of S)a[le]=pe;A&&A(),x.clear()}}}const T=N}),rt("packages/modules/designer/index.js",function(o,ce){"use strict";Object.defineProperty(o,"createDesigner",{enumerable:!0,get:function(){return me}}),Object.defineProperty(o,"default",{enumerable:!0,get:function(){return we}});const ke=ce("packages/core/src/internal/util.js"),F=ke.warnOnce,l=ke.isFunction,z=ce("packages/modules/shared/emitter.js").Emitter,J=ce("packages/modules/dashboard/index.js").createDashboard,Q=ce("packages/modules/dashboard/spec.js"),ie=Q.inspectSpec,W=Q.isPlain,L=Q.sameSpec,i=ce("packages/modules/designer/messages.js").resolveMessages,k=ce("packages/modules/designer/toolbar.js").installChrome,r=ce("packages/modules/designer/migrate.js"),m=r.migrateState,c=r.SCHEMA_VERSION,b=ce("packages/modules/designer/undo.js"),y=b.createHistory,P=b.installUndo,E=ce("packages/modules/designer/guardrails.js").createGuardrails,d=ce("packages/modules/designer/data-panel.js"),w=d.mountDataPanel,G=d.stripDeclaredFields,N=ce("packages/modules/designer/canvas.js"),T=N.wireCanvas,C=N.removeWidgetState,h=N.addWidgetState,a=ce("packages/modules/designer/properties.js").installProperties,t=ce("packages/modules/designer/calculated.js").installCalculated,e=ce("packages/modules/designer/derived.js"),s=e.installDerived,x=e.withDerivedFormats,S=e.hiddenDerivedIds,B=e.headlessSourceIds,te=ce("packages/modules/designer/assist.js").mountAssist,ne=ce("packages/modules/designer/statistics-widgets.js").installStatisticsWidgets,M=ce("packages/modules/designer/pages.js").installPages,H=ce("packages/modules/designer/rails.js").createRails,g=ce("packages/modules/designer/palette.js").installPalette,j=ce("packages/modules/designer/config-router.js").installConfigRouting,D=ce("packages/modules/designer/data-routes.js").installDataRouting,se=ce("packages/modules/designer/filters.js").installFilters,O=ce("packages/modules/designer/pushdown.js").installPushdown,X=Object.freeze(["edit","view"]);function oe(Pe){if(Array.isArray(Pe))return Pe.map(oe);if(!W(Pe))return Pe;const Fe={};for(const Z of Object.keys(Pe))Fe[Z]=oe(Pe[Z]);return Fe}function ue(Pe,Fe){const Z=W(Pe)?oe(Pe):{};Z.schemaVersion===void 0&&(Z.schemaVersion=c),Array.isArray(Z.pages)||(Z.pages=[{id:"page-1",title:Fe("designer.page",{n:1}),spec:{panels:[]}}]),W(Z.panels)||(Z.panels={});const re=Z.pages.filter(W).map(le=>le.id);return re.includes(Z.selectedPageId)||(Z.selectedPageId=re.length?re[0]:null),Z}function xe(Pe){F(`designer:property:${Pe}`,`designer.getProperty/setProperty: there is no property ${JSON.stringify(Pe)}; nothing was read or changed. The properties are mode, state, selectedPageId, guardrails.`)}function me(Pe,Fe={}){const Z=W(Fe)?Fe:{},re=i(Z.messages),le=new z("designer"),pe=W(Z.sources)?Z.sources:{},he=W(Z.factories)?Z.factories:{},Me=Object.freeze({sources:pe,relationships:Z.relationships,guardrails:Z.guardrails,llm:Z.llm});let Ie=X.includes(Z.mode)?Z.mode:"view";Z.mode!==void 0&&!X.includes(Z.mode)&&F("designer:mode",`createDesigner: mode ${JSON.stringify(Z.mode)} is not 'edit' or 'view'; the designer opened in view mode.`);let Ke=E(Z.guardrails);const qe=Z.keepPagesAlive===!0,ot=je=>F("designer:state:newer",`designer: the state's schemaVersion ${je} is newer than this designer's ${c}; the state was refused, nothing was loaded.`),it=je=>{const et=m(je,re);return et.ok?et.state:(ot(et.from),null)};let ge;if(Z.state===void 0)ge=ue(void 0,re);else{const je=it(Z.state);ge=ue(je===null?void 0:je,re)}let Le=null,He=null;const Ze=new Map;let ae=null,ee=!1,ye=null,ve=()=>{};const be=y({historyDepth:Z.historyDepth});let Ee=null;const $e=Pe.ownerDocument,Ge=$e.createElement("div");Ge.className="lattice-designer lattice",Object.assign(Ge.style,{width:"100%",height:"100%"});const Ye=$e.createElement("div");Ye.className="lattice-designer-chrome",Ye.setAttribute("role","group"),Ye.setAttribute("aria-label",re("designer.chrome"));const Se=$e.createElement("div");Se.className="lattice-designer-canvas",Se.setAttribute("role","region"),Se.setAttribute("aria-label",re("designer.canvas")),Object.assign(Se.style,{minWidth:"0",minHeight:"0",position:"relative"});const Ne=$e.createElement("div");Ne.className="lattice-designer-status",Ne.setAttribute("role","status"),Ne.setAttribute("aria-live","polite"),Object.assign(Ne.style,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"}),Ge.appendChild(Ye),Ge.appendChild(Se),Ge.appendChild(Ne),Pe.appendChild(Ge);const Ve=H({root:Ge,chrome:Ye,t:re,getPanels:()=>ge.panels,setCollapsed:(je,et)=>{const We=oe(ge);We.panels[je]={...W(We.panels[je])?We.panels[je]:{},collapsed:et},je==="left"&&(We.panels.palette={...W(We.panels.palette)?We.panels.palette:{},collapsed:et}),mt(We,"panels",{record:!1,render:!1})},announce:(je,et)=>kt.announce(re(`a11y.designer.rail.${et?"open":"closed"}`,{name:re(`designer.rail.${je}`)}))}),Be=()=>ge.pages.find(je=>W(je)&&je.id===ge.selectedPageId)||null,Oe=je=>{if(!W(je)||!W(je.spec))return W(je)?je.spec:void 0;const et=W(je.spec.sources)?je.spec.sources:{},We=G({...pe,...et}),ut=Array.isArray(je.spec.panels)?je.spec.panels:[],Et=[...B(je,ge,We)].map(gt=>({id:gt,kind:"grid",title:gt,source:gt}));return{...je.spec,sources:We,panels:Et.length?[...ut,...Et]:ut}},Xe=je=>{le.emit("state",{state:oe(ge),cause:je})},nt=()=>{He&&He.dispose(),He=null,Le&&Le.destroy(),Le=null;for(const je of Ze.values())je!==ae&&(je.canvasCtl&&je.canvasCtl.dispose(),je.dashboard&&je.dashboard.destroy());Ze.clear(),ae=null,Se.textContent=""},st=()=>{const je=new Map,et=Be();if(!et||!W(et.spec)||!Array.isArray(et.spec.panels))return je;for(const We of et.spec.panels)if(W(We)&&We.id!=null){const ut=Ke.restrictPanel(We);ut&&je.set(String(We.id),ut)}return je},ft=je=>{const et="http://www.w3.org/2000/svg",We=je.createElementNS(et,"svg");We.setAttribute("viewBox","0 0 24 24"),We.setAttribute("width","12"),We.setAttribute("height","12"),We.setAttribute("aria-hidden","true");const ut=je.createElementNS(et,"rect");ut.setAttribute("x","4"),ut.setAttribute("y","10"),ut.setAttribute("width","16"),ut.setAttribute("height","10"),ut.setAttribute("rx","2"),ut.setAttribute("fill","currentColor");const yt=je.createElementNS(et,"path");return yt.setAttribute("d","M8 10V7a4 4 0 0 1 8 0v3"),yt.setAttribute("fill","none"),yt.setAttribute("stroke","currentColor"),yt.setAttribute("stroke-width","2"),We.appendChild(ut),We.appendChild(yt),We},ht=(je,et,We=Se)=>{const ut=[...We.querySelectorAll(".lat-layout__window")].find(gt=>gt.getAttribute("data-window-id")===je);if(!ut)return;ut.setAttribute("data-locked",et);const yt=$e.createElement("span");yt.className="lattice-designer-lock",yt.setAttribute("role","img"),yt.setAttribute("aria-label",re("designer.lock")),yt.setAttribute("title",re("designer.lock")),yt.setAttribute("data-guardrail",et),Object.assign(yt.style,{display:"inline-flex",alignItems:"center",marginLeft:"calc(var(--lattice-space, 4px) * 1.5)",color:"var(--lattice-foreground-muted, inherit)"}),yt.appendChild(ft($e)),(ut.querySelector(".lat-layout__chrome")||ut).appendChild(yt)},$t=(je,et,We,ut)=>{if(Le=J(je,et,he),ut.size)for(const gt of je.querySelectorAll(".lat-layout__window"))ut.has(gt.getAttribute("data-window-id"))&>.remove();const yt=Le.layout;if(Ie!=="edit"||!yt)return;for(const[gt,Nt]of We)ht(gt,Nt,je);let Et=null;He=T({layout:yt,canvas:je,page:()=>(Et=oe(ge),Et.pages.find(gt=>W(gt)&>.id===Et.selectedPageId)||null),emitState:gt=>{const Nt=Et;Et=null,Nt&&mt(Nt,gt,{render:!1})},removeWidget:gt=>ct.run("removeWidget",gt),emit:(gt,Nt)=>le.emit(gt,Nt),announce:gt=>kt.announce(gt),messages:Z.messages})},dt=()=>{qe?(ae&&ae.wrapper&&ae.wrapper.parentNode===Se&&Se.removeChild(ae.wrapper),ae=null,He=null,Le=null):nt(),Ge.setAttribute("data-mode",Ie),Ie==="edit"?Ye.removeAttribute("hidden"):Ye.setAttribute("hidden","");const je=Be();if((je&&W(je.spec)&&Array.isArray(je.spec.panels)?je.spec.panels:[]).some(gt=>W(gt)&>.id===Ee)||(Ee=null),Ve.setSelection(Ie==="edit"&&Ee!==null),!je)return;const We=Oe(je),ut=Ie==="edit"?st():new Map;if(ut.size&&W(We)){const gt=W(We.layout)?We.layout:{},Nt=(Array.isArray(gt.windows)?gt.windows:[]).map(Wt=>W(Wt)?{...Wt}:Wt);for(const Wt of ut.keys()){const en=Nt.find(K=>W(K)&&String(K.id)===Wt);en?(en.movable=!1,en.resizable=!1):Nt.push({id:Wt,movable:!1,resizable:!1})}We.layout={...gt,windows:Nt}}const yt=W(je.spec.sources)?je.spec.sources:{};W(We)&&Array.isArray(We.panels)&&(We.panels=x(We.panels,ge,{...pe,...yt}));const Et=S(ge);for(const gt of B(je,ge,G({...pe,...yt})))Et.add(gt);if(qe){const gt=JSON.stringify([Ie,We,[...Et].sort()]),Nt=Ze.get(je.id);if(Nt&&Nt.key===gt){Se.appendChild(Nt.wrapper),ae=Nt,Le=Nt.dashboard,He=Nt.canvasCtl;return}Nt&&(Nt.canvasCtl&&Nt.canvasCtl.dispose(),Nt.dashboard&&Nt.dashboard.destroy(),Ze.delete(je.id));const Wt=$e.createElement("div");Wt.className="lattice-designer-page",Object.assign(Wt.style,{width:"100%",height:"100%",position:"relative"}),$t(Wt,We,ut,Et),Se.appendChild(Wt),ae={wrapper:Wt,dashboard:Le,canvasCtl:He,key:gt},Ze.set(je.id,ae);return}$t(Se,We,ut,Et)},mt=(je,et,We)=>{if(ee)return!1;const ut=oe(ge),yt=ue(je,re);if(L(yt,ge))return!1;const Et=Be();ge=yt,Ve.sync();const gt=Be();(Et?Et.id:null)!==(gt?gt.id:null)&&le.emit("page",{id:gt?gt.id:null,page:gt?{id:gt.id,title:gt.title}:null,previousId:Et?Et.id:null,type:"page"});const Nt=!L(ut.panels,yt.panels);return!(We&&We.render===!1)&&(Nt||!Et||!gt||Et.id!==gt.id||!L(Et.spec,gt.spec))&&dt(),We&&We.record===!1||be.record(ut,oe(ge),et,We&&We.coalesce),ve(),Xe(et),!0},At=new Map,ct=Object.freeze({register(je,et){return typeof je!="string"||!l(et)?(F("designer:command","designer.commands.register: a command is a string name and a function; nothing was registered."),()=>{}):(At.set(je,et),()=>{At.get(je)===et&&At.delete(je)})},run(je,...et){const We=At.get(je);if(!We){F(`designer:command:${je}`,`designer.commands.run: there is no command "${je}"; nothing was run.`);return}return We({designer:xt,getState:()=>oe(ge),commit:mt},...et)},has(je){return At.has(je)},list(){return[...At.keys()]}});ct.register("selectPage",(je,et)=>ge.pages.some(We=>W(We)&&We.id===et)?(et===ge.selectedPageId||je.commit({...je.getState(),selectedPageId:et},"selectPage"),!0):(F(`designer:page:${et}`,`designer.selectPage: there is no page ${JSON.stringify(et)}; the selection was kept.`),!1)),ct.register("setMode",(je,et)=>X.includes(et)?(et===Ie||ee||(Ie=et,dt(),kt.announce(re(`a11y.designer.${Ie}`)),le.emit("mode",{mode:Ie})),Ie):(F("designer:set-mode",`designer.setMode: ${JSON.stringify(et)} is not 'edit' or 'view'; the mode was kept.`),Ie));const kt=k({root:Ge,chrome:Ye,topbar:Ve.topbar,canvas:Se,live:Ne,t:re,theme:Z.theme,commands:ct,emitter:le,sources:pe,designer:()=>xt}),_t=()=>{const je=be.undo();return je===null?!1:mt(je,"undo",{record:!1})},Lt=()=>{const je=be.redo();return je===null?!1:mt(je,"redo",{record:!1})},Ht=()=>be.canUndo(),Gt=()=>be.canRedo();ct.register("removeWidget",(je,et)=>{const We=C(je.getState(),et);return We?je.commit(We,"removeWidget"):!1}),ct.register("addWidget",(je,et,We)=>{const ut=h(je.getState(),et,We);return ut?je.commit(ut,"addWidget"):!1});const xt={get el(){return Pe},get mode(){return Ie},get chrome(){return Ye},get rails(){return Ve.rails},get canvas(){return Se},get dashboard(){return Le},get commands(){return ct},get shortcuts(){return kt.shortcuts},get regions(){return kt.regions},audit(){return kt.audit()},get theme(){return kt.theme.get()},setTheme(je){return kt.theme.set(je)},announce(je){kt.announce(je)},get context(){return Me},get guardrails(){return Ke},getState(){return oe(ge)},setState(je,et){if(!W(je))return F("designer:state",`designer.setState: the state is not an object (${Array.isArray(je)?"array":typeof je}); the state was kept.`),!1;const We=it(je);if(We===null)return!1;const ut=!!(et&&et.keepHistory);return ut||(be.clear(),ve()),mt(We,"setState",{record:ut})},migrate(je,et={}){const We=m(je,re);return We.ok?(et.dryRun||mt(We.state,"migrate"),We):(et.dryRun||ot(We.from),We)},setGuardrails(je){return je!==void 0&&!W(je)?(F("designer:guardrails",`designer.setGuardrails: the guardrails are not an object (${Array.isArray(je)?"array":typeof je}); the guardrails were kept.`),!1):(Ke=E(je),dt(),xt.palette&&xt.palette.refresh(),!0)},setMode(je){return ct.run("setMode",je)},pages(){return ge.pages.map(je=>W(je)?{id:je.id,title:je.title}:{id:void 0,title:void 0})},selectPage(je){return ct.run("selectPage",je)},addPage(je){return ct.run("addPage",je)},renamePage(je,et){return ct.run("renamePage",je,et)},movePage(je,et){return ct.run("movePage",je,et)},removePage(je){return ct.run("removePage",je)},undo:_t,redo:Lt,canUndo:Ht,canRedo:Gt,selectWidget(je){return He?He.selectWidget(je,"api"):null},selectedWidget(){return He?He.selectedWidget():null},removeWidget(je){return ct.run("removeWidget",je)},addWidget(je,et){return ct.run("addWidget",je,et)},getProperty(je){if(je==="mode")return Ie;if(je==="state")return oe(ge);if(je==="selectedPageId")return ge.selectedPageId;if(je==="guardrails")return oe(Ke.value);xe(je)},setProperty(je,et){return je==="mode"?xt.setMode(et)===et:je==="state"?(xt.setState(et),W(et)):je==="selectedPageId"?xt.selectPage(et):je==="guardrails"?xt.setGuardrails(et):(xe(je),!1)},problems(){const je=[];return ge.pages.forEach((et,We)=>{if(!W(et)){je.push({page:void 0,path:`pages[${We}]`,message:"is not an object"});return}for(const ut of ie(Oe(et)).problems)je.push({page:et.id,path:ut.path,message:ut.message})}),je},on(je,et){return le.on(je,et)},onStateUpdated(je){return le.on("state",je)},destroy(){ee||(ee=!0,ye&&ye(),ye=null,xt.palette.destroy(),xt.dataPanel.destroy(),nt(),kt.destroy(),Ve.destroy(),le.clear(),At.clear(),Ge.remove())}};kt.start();const qt=P({chrome:Ye,topbar:Ve.topbar,root:Ge,doc:$e,t:re,undo:_t,redo:Lt,canUndo:Ht,canRedo:Gt});return ve=qt.refresh,ye=qt.off,xt.pushdown=O(xt,Z,re),dt(),xt.dataPanel=w(xt,{doc:$e,t:re}),xt.palette=g(xt,Z),xt.properties=a(xt,Z),xt.calculated=t(xt,Z),xt.configRouter=j(xt,{commit:mt,getState:()=>oe(ge),selectedPageId:()=>ge.selectedPageId,dashboard:()=>Le,guardrails:()=>Ke,on:(je,et)=>le.on(je,et)}),xt.derived=s(xt,Z),xt.dataRoutes=D(xt),xt.assist=te(xt,{doc:$e,t:re,factories:he}),xt.statisticsWidgets=ne(xt,Z),M(ct,re),xt.filters=se(xt,Z),le.on("select",je=>{const et=je&&je.id!=null?je.id:null;Ee=et,Ve.setSelection(et!==null&&Ie==="edit"),et!==null&&xt.properties.selectPanel(et)}),xt}const we=me});const Pn=On("packages/modules/designer/index.js"),Ln=Pn.createDesigner;var Dn=Pn.default;export{Ln as createDesigner,Dn as default};
|
|
576
690
|
|
|
577
691
|
//# sourceMappingURL=designer.esm.min.js.map
|