@bino-bi/bn-template-engine 1.0.0-next.36 → 1.0.0-next.37

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.
@@ -131,6 +131,9 @@ export declare class BnTableRenderer {
131
131
  private barColumnLayouts;
132
132
  private stores;
133
133
  constructor();
134
+ private readonly relayout;
135
+ connectedCallback(): void;
136
+ disconnectedCallback(): void;
134
137
  /**
135
138
  * Collects the table's layout-state contribution: header/body regions,
136
139
  * counts, and - with `detail: "full"` - per-cell geometry paired with the
@@ -149,6 +152,8 @@ export declare class BnTableRenderer {
149
152
  * Scenario styles (ac, pp, fc, pl) use barStyles for IBCS-compliant grayscale coloring.
150
153
  */
151
154
  private prepareBarChartStyles;
155
+ /** Font family of the bar and pin labels, also used to measure them. */
156
+ private labelFontFamily;
152
157
  /** The table's true em in px - the unit `.category-wN` and the bar columns share. */
153
158
  private emPx;
154
159
  /**
@@ -49,6 +49,8 @@ export interface CellBarChartProps {
49
49
  columnWidthEm?: number;
50
50
  /** Widest label per side over the drawn cells of the column; without it only this cell's label counts. */
51
51
  labelWidths?: SideLabels;
52
+ /** Largest absolute drawn value per side over the column; without it the column statistics count. */
53
+ sideMax?: SideLabels;
52
54
  styles?: CellBarChartStyles;
53
55
  }
54
56
  export declare const DEFAULT_STYLES: CellBarChartStyles;
@@ -20,6 +20,11 @@ export declare const VARIANCE_AXIS_EM = 0.25;
20
20
  export declare const PIN_HEAD_SIZE = 10;
21
21
  /** Estimated rendered width of a value label in px, with a margin for wider fonts. */
22
22
  export declare function estimateLabelWidth(text: string, fontSize: number): number;
23
+ /**
24
+ * Rendered width of a value label in px, measured with the font the SVG text uses. Falls
25
+ * back to estimateLabelWidth where no canvas can measure.
26
+ */
27
+ export declare function labelWidth(text: string, fontSize: number, fontFamily: string, italic: boolean): number;
23
28
  /** Widest value label in px per side of the axis; a side without drawn values is undefined. */
24
29
  export interface SideLabels {
25
30
  neg?: number;
@@ -43,13 +48,22 @@ export interface AbsoluteBarGeometry {
43
48
  export declare function absoluteBarGeometry(widthEm: number, emPx: number, labels: SideLabels): AbsoluteBarGeometry;
44
49
  export interface RelativePinGeometry {
45
50
  totalWidth: number;
46
- /** Max pin extent on one side of the axis, to the centre of the head or the base of the arrow tip. */
51
+ /** Max pin extent of the longer side, to the centre of the head or the base of the arrow tip. */
47
52
  maxPinLength: number;
53
+ /** Max pin extent per side; a longer pin is cut and ends in an arrow. */
54
+ negPinLength: number;
55
+ posPinLength: number;
48
56
  axisX: number;
49
57
  /** Gap between the pin head and its value label. */
50
58
  labelGap: number;
51
59
  }
52
- export declare function relativePinGeometry(widthEm: number, emPx: number, labels: SideLabels, headSize: number): RelativePinGeometry;
60
+ /**
61
+ * `reach` is the length in px the longest pin of each side wants at the column's scale.
62
+ * With it, the pin room is split by what each side needs, so a side with shorter pins
63
+ * gives its room to the other; room left after both is shared equally. Without it, both
64
+ * sides get the same extent.
65
+ */
66
+ export declare function relativePinGeometry(widthEm: number, emPx: number, labels: SideLabels, headSize: number, reach?: SideLabels): RelativePinGeometry;
53
67
  export interface WaterfallGeometry {
54
68
  totalWidth: number;
55
69
  /** One gutter on each side; a waterfall always spans its full range. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bino-bi/bn-template-engine",
3
- "version": "1.0.0-next.36",
3
+ "version": "1.0.0-next.37",
4
4
  "description": "IBCS-compliant web components for business intelligence tables and charts",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -1 +0,0 @@
1
- import{h as t,p as e,H as o,a as i,t as n}from"./p-D6YGOYV1.js";import{m as s,a as r,b as l}from"./p-DaOm9YwQ.js";import{p as a,n as h,r as c,d as u}from"./p-BzjGUtYh.js";import{F as d,V as f,Q as p,s as $,a as v,I as m,b as g}from"./p-CniN8ALm.js";import{S as b,I as w,D as E,C as S,d as R,M as y}from"./p-B5tixDPM.js";import{N as O,r as M}from"./p-fCjsrD7I.js";import{D as N,w as U}from"./p-Dq9dG0Kr.js";import{D as G,b as T}from"./p-sLbQ7yZ1.js";import{F as _}from"./p-DCPLGEs_.js";import{p as L,c as x}from"./p-16rjcQ0t.js";import{d as C,g as k}from"./p-DDvWTgk1.js";import{D as A,a as P,b as D}from"./p-7ieJFBUk.js";import{A as W}from"./p-BXg3v5AO.js";import{S as B}from"./p-BPGLOHUe.js";import{S as F}from"./p-CeE4_3wQ.js";import{w as Y}from"./p-DjPWZfry.js";var H,j,I,z,Q;!function(t){t[t.ALL=-1]="ALL"}(H||(H={})),function(t){t[t.UP_TO_DATE=0]="UP_TO_DATE",t[t.DIRTY=1]="DIRTY"}(j||(j={})),function(t){t.LIST="list",t.SUM="sum",t.SUMNOTOTAL="sumnototal",t.OPT="opt",t.OPTNOTOTAL="optnototal"}(I||(I={})),function(t){t.ASC="asc",t.DESC="desc"}(z||(z={})),function(t){t.HEADER="HEADER",t.GROUPHEAD="GROUPHEAD",t.SEPERATORLINE="SEPERATORLINE",t.SUM="SUM",t.GROUPSUM="GROUP_SUM",t.DRILLELEMENT="DRILLELEMENT",t.STANDARD="STANDARD",t.PARTELEMENT="PARTELEMENT",t.ENTRY="ENTRY"}(Q||(Q={}));const V="none",X="setname";function q(t){return t===X?"COALESCE([setname],[setName])":`normalizeDate([date], '${t}')`}function K(t){if(null==t)return"";if("string"==typeof t)return t.trim();const e=Z(t);return e?e.toISO():String(t)}function Z(t){if(null!=t){if("string"==typeof t){const e=N.fromISO(t,{zone:"utc"});return e.isValid?e:void 0}if("number"==typeof t){const e=N.fromMillis(t,{zone:"utc"});return e.isValid?e:void 0}if("boolean"==typeof t.isValid)return t.isValid?t:void 0}}const J=/[\s\u200e\u200f\u061c]*[%\u066a][\s\u200e\u200f\u061c]*/;class tt{constructor(t,e,o,i,n,s,r,l,a){this.prefixStyle="prefix",this.isBarChart=!1,this.key=t,this.index=e,this.value=o,this.prefix=s||"",this.cssStyle=i||"",this.prefixStyle=r||"prefix",this.type=n,this.mark=void 0,this.colSpan=l||1,this.measureScale=a||1}getAsHeaderList(){if(null==this.value)return[""];const t=[];for(const e of this.value.toString().split("<br/>"))t.push(e);return t}draw(t,e){let o=this.value;if("undefined"===o||void 0===o||null==o)return"";if(Number.isNaN(Number(o)))return o;if(""===this.type||void 0===this.type||null==this.type)return o;let i=t.percent,n=t.percent;return"percentpoint"===this.type?d.number(Number(o),"percent",i,n,1,e).replace(J,""):("decimal"===this.type&&(o=+o/this.measureScale,i=t.decimal,n=t.decimal),d.number(Number(o),this.type,i,n,1,e))}drawPrefix(){return null==this.prefix?"":this.prefix}}class et{constructor(t,e,o){this.index=t,this.groupindex=e,this.type=o,this.cssStyle=this.initCssStyle(),this.elements=[]}initCssStyle(){switch(this.type){case Q.HEADER:return"groupheader";case Q.SEPERATORLINE:return"";case Q.DRILLELEMENT:return"ofit";case Q.PARTELEMENT:return"partof";case Q.STANDARD:return"";case Q.SUM:return"sum";default:return""}}getCells(){return this.elements}createElement(t,e,o,i,n,s,r,l,a,h=!1,c,u=1,d){let f=s;"category"===e&&null!=l&&(f=`category-${l.toString()}`),this.type===Q.HEADER?f="headerlabel":this.type===Q.SEPERATORLINE&&(f=null!=s?s:e),this.type===Q.PARTELEMENT&&("percent"===i&&(t="-"),"category"!==e&&"operation"!==e&&(i="percent",f="")),("-"===t||t===O&&"percent"===i)&&(f="");let p="prefix-first";r&&(p="prefix-second"),o&&(f=`${f} ${o}`);const $=new tt(e,this.elements.length,t,f,i,n,p,u,a);$.isBarChart=h,$.columnStats=c,$.waterfall=d,this.elements.push($)}}const ot=.85,it=.3,nt=.25,st={".":.28,",":.28,"-":.34,"%":.89," ":.28," ":.28," ":.28,M:.9};function rt(t,e){var o;let i=0;for(const e of t)i+=null!==(o=st[e])&&void 0!==o?o:/[0-9+]/.test(e)?.59:.72;return i*e*1.1}function lt(t,e){return Math.max(0,(t-.5)*e)}function at(t,e,o){const i=void 0!==t.neg,n=void 0!==t.pos||!i,s=(t,i)=>t?e+o+(null!=i?i:0):0;return{sides:(i?1:0)+(n?1:0),neg:s(i,t.neg),pos:s(n,t.pos)}}function ht(t,e,o,i){const{sides:n,neg:s,pos:r}=at(e,o,i),l=s+r>0?Math.min(1,t/(s+r)):1,a=Math.max(0,(t-(s+r)*l)/n);return{extent:a,axisX:void 0!==e.neg?s*l+a:0}}function ct(t,e,o,i){const n=lt(t,e),{sides:s,neg:r,pos:l}=at(o,i/2,it*e);return r+l+s*function(t,e,o){return Math.min(1*e,t/(2*o))}(n,e,s)<=n+1e-6}function ut(t,e,o){const i=lt(t,e),n=it*e,{extent:s,axisX:r}=ht(i,o,nt*e/2,n),l=Math.min(.3*e,.2*s),a=.15*s;return{totalWidth:i,maxBarWidth:s,axisX:r,breakGap:l,overdriveZoneWidth:a,cutWidth:Math.max(0,s-l-a),labelGap:n}}function dt(t,e,o,i){const n=lt(t,e),s=it*e,{extent:r,axisX:l}=ht(n,o,i/2,s);return{totalWidth:n,maxPinLength:r,axisX:l,labelGap:s}}const ft={positive:{stroke:"#008f96",fill:"#008f96",fillpattern:"solid"},negative:{stroke:"#ff0000",fill:"#ff0000",fillpattern:"solid"},neutral:{stroke:"#808080",fill:"#808080",fillpattern:"outlined"},scenarios:{ac:{stroke:"#404040",fill:"#404040",fillpattern:"solid"},pp:{stroke:"#A6A6A6",fill:"#A6A6A6",fillpattern:"solid"},fc:{stroke:"#404040",fill:"#ffffff",fillpattern:"hatched"},pl:{stroke:"#404040",fill:"#ffffff",fillpattern:"outlined"}},fontColor:"#000000",fontSize:11.333305,emPx:13.3333,fontFamily:"'Noto Sans', sans-serif",unitScaling:.01,percentageScaling:.5,scaleFactor:1},pt="#666666";function $t(t,e){return`pattern-${t}-${e.replace("#","")}`}const vt=({styles:e})=>{const o=e.scaleFactor,i=6*o,n=[{id:$t("pos",e.positive.stroke),stroke:e.positive.stroke,fill:e.positive.fill},{id:$t("neg",e.negative.stroke),stroke:e.negative.stroke,fill:e.negative.fill},{id:$t("neu",e.neutral.stroke),stroke:e.neutral.stroke,fill:e.neutral.fill},...["ac","pp","fc","pl"].map((t=>({id:$t(t,e.scenarios[t].stroke),stroke:e.scenarios[t].stroke,fill:e.scenarios[t].fill})))];return t("defs",null,n.map((e=>t("pattern",{id:e.id,patternUnits:"userSpaceOnUse",width:i,height:i},t("rect",{width:i,height:i,fill:"#ffffff"}),t("line",{x1:"0",y1:i,x2:i,y2:"0",stroke:e.stroke,"stroke-width":1.5*o})))))};function mt(t,e,o=1,i,n=0,s=!0){const r=(e,o)=>(t>0&&e!==o?"+":"")+e;if(e){const e=(t,e)=>s?d.number(t,"percent",e,e,1,i):d.number(100*t,"decimal",e,e,1,i),o=o=>r(e(t,o),e(0,o));let l=Math.min(20,Math.max(0,Math.trunc(n)||0));for(;l>0&&o(l).length>7;)l--;return o(l)}const l=t/o,a=Math.abs(l);let h=1,c="";a>=9995e5?(h=1e9,c="B"):a>=999500?(h=1e6,c="M"):a>=999.5&&(h=1e3,c="K");const u=a>=10*h?0:1;return r(d.number(l/h,"decimal",u,0,1,i),d.number(0,"decimal",u,0,1,i))+c}function gt(t){const e=t.slice(0,2).toLowerCase();return["ac","pp","fc","pl"].includes(e)}function bt(t){const e=t.slice(0,2).toLowerCase();return"pp"===e?"pp":"fc"===e?"fc":"pl"===e?"pl":"ac"}function wt(t,e){if(gt(t))return null;const o=new f(t);if(!o.isValid)return null;const i=bt(o.base),n=bt(o.delta);return{minuend:e.scenarios[i],minuendSlot:i,reference:e.scenarios[n],referenceSlot:n}}const Et=({x:e,height:o,look:i,styles:n})=>{const s=n.scaleFactor,r=nt*n.emPx,{reference:l,referenceSlot:a}=i;let h;if("outlined"===l.fillpattern){const i=r/2-.5*s;h=[e-i,e+i].map((e=>t("line",{x1:e,y1:0,x2:e,y2:o,stroke:l.stroke,"stroke-width":1*s})))}else h=t("line","hatched"===l.fillpattern?{x1:e,y1:0,x2:e,y2:o,stroke:l.stroke,"stroke-width":r,"stroke-dasharray":""+2*s}:{x1:e,y1:0,x2:e,y2:o,stroke:l.fill,"stroke-width":r});return t("g",{class:`variance-axis axis-${a}`},h)};function St(t){return void 0!==t.pos||void 0===t.neg}function Rt(t,e){return{neg:t.min<0?e:void 0,pos:t.max>0?e:void 0}}function yt(t,e,o,i){return gt(t)?function(t,e){const o=bt(t);return e.scenarios[o]}(t,i):function(t,e,o){const i=t>=0;return e?i?o.positive:o.negative:i?o.negative:o.positive}(e,o,i)}function Ot(t,e){const o=t.fillpattern;return"hatched"===o?`url(#${$t(e,t.stroke)})`:"outlined"===o?"transparent":t.fill}function Mt(t){return"outlined"===t.fillpattern?{stroke:t.stroke,strokeWidth:1.5}:{stroke:"none",strokeWidth:0}}const Nt=e=>{const{value:o,scenario:i,columnStats:n,height:s,isPositiveGood:r,formattedValue:l,measureScale:a,locale:h,columnWidthEm:c=10,labelWidths:u,styles:d=ft}=e,f=d.scaleFactor,p=d.fontSize,$=l||mt(o,!1,a,h),v=null!=u?u:Rt(n,rt($,p)),{totalWidth:m,axisX:g,breakGap:b,overdriveZoneWidth:w,cutWidth:E,labelGap:S}=ut(c,d.emPx,v),R=Math.abs(o)*d.unitScaling*p,y=R-E>1e-6,O=Math.max(0,n.absMax*d.unitScaling*p-E),M=Math.max(0,R-E),N=O>0?M/O*w:0,U=2*f,G=s-2*U,T=U,_=o>0||0===o&&St(v),L=wt(i,d),x=yt(i,o,r,d),C=null==L?void 0:L.minuend.fillpattern,k="hatched"===C||"outlined"===C?Object.assign(Object.assign({},x),{fillpattern:C}):x,A=Ot(k,gt(i)?bt(i):r?_?"pos":"neg":_?"neg":"pos"),{stroke:P,strokeWidth:D}=L&&"hatched"===k.fillpattern?{stroke:k.stroke,strokeWidth:1}:Mt(k),W=L?nt*d.emPx/2:0,B=_?g+W:g-W,F=y?E:R,Y=y?E+b+N:R,H=_?B+Y+S:B-Y-S,j=_?"start":"end";return t("svg",{width:m,height:s,class:"cell-bar-chart absolute-variance",style:{overflow:"visible"}},t(vt,{styles:d}),!L&&t("line",{x1:g,y1:0,x2:g,y2:s,stroke:pt,"stroke-width":1*f}),F>0&&t("rect",{x:_?B:B-F,y:T,width:F,height:G,fill:A,stroke:P,"stroke-width":D*f}),y&&N>0&&t("rect",{x:_?B+E+b:B-E-b-N,y:T,width:N,height:G,fill:A,stroke:P,"stroke-width":D*f}),y&&function(e,o,i,n,s){const r=e+o/2,l=.35*o,a=n/3,h=.3*o;let c=`M ${r-l} ${i}`;for(let t=0;t<3;t++)c+=` L ${r-l-h} ${i+a*(t+.5)} L ${r-l} ${i+a*(t+1)}`;let u=`M ${r+l} ${i}`;for(let t=0;t<3;t++)u+=` L ${r+l+h} ${i+a*(t+.5)} L ${r+l} ${i+a*(t+1)}`;return[t("rect",{x:e,y:i-1,width:o,height:n+2,fill:"#ffffff"}),t("path",{d:c,fill:"none",stroke:"#000000","stroke-width":1*s}),t("path",{d:u,fill:"none",stroke:"#000000","stroke-width":1*s})]}(_?B+E:B-E-b,b,T,G,f),L&&t(Et,{x:g,height:s,look:L,styles:d}),t("text",{x:H,y:s/2,dy:"0.35em","text-anchor":j,fill:d.fontColor,"font-size":p,"font-family":d.fontFamily},$))},Ut=e=>{var o,i;const{value:n,scenario:s,columnStats:r,height:l,isPositiveGood:a,formattedValue:h,measureScale:c,locale:u,percentDigits:d,percentSign:f,columnWidthEm:p=10,labelWidths:$,styles:v=ft}=e,m=v.scaleFactor,g=v.fontSize,b=10*m,w=h||mt(n,!0,c,u,d,f),E=null!=$?$:Rt(r,rt(w,g)),{totalWidth:S,maxPinLength:R,axisX:y,labelGap:O}=dt(p,v.emPx,E,b),M=l/2,N=100*Math.abs(n)*v.percentageScaling*g,U=N-R>1e-6,G=Math.min(N,R),T=n>0||0===n&&St(E),_=T?1:-1,L=y+_*G,x=yt(s,n,a,v),C=wt(s,v),k=null!==(o=null==C?void 0:C.minuend)&&void 0!==o?o:v.scenarios.ac,A=y+_*(R+b/2),P=A-_*b,D=(U?A:L+_*(b/2))+_*O;return t("svg",{width:S,height:l,class:"cell-bar-chart relative-variance",style:{overflow:"visible"}},t(vt,{styles:v}),C?t(Et,{x:y,height:l,look:C,styles:v}):t("line",{x1:y,y1:0,x2:y,y2:l,stroke:pt,"stroke-width":1*m}),t("line",{x1:y,y1:M,x2:U?P:L,y2:M,stroke:x.fill,"stroke-width":3*m}),U?t("polygon",{points:`${A},${M} ${P},${M-b/2} ${P},${M+b/2}`,fill:x.fill}):t("rect",{x:L-b/2,y:M-b/2,width:b,height:b,fill:"outlined"===k.fillpattern?"#ffffff":Ot(k,null!==(i=null==C?void 0:C.minuendSlot)&&void 0!==i?i:"ac"),stroke:k.stroke,"stroke-width":1*m}),t("text",{x:D,y:l/2,dy:"0.35em","text-anchor":T?"start":"end",fill:v.fontColor,"font-size":g,"font-style":"italic","font-family":v.fontFamily},w))},Gt=e=>{const{value:o,columnStats:i,isRelative:n,styles:s=ft}=e;return null==o||isNaN(o)||!i||0===i.absMax?t("span",{class:"bar-chart-empty",style:{color:s.fontColor,fontStyle:"italic"}},"-"):t(n?Ut:Nt,Object.assign({},e))},Tt=e=>{const{value:o,scenario:i,height:n,measureScale:s,locale:r,columnWidthEm:l=10,styles:a=ft,waterfall:h}=e,c=a.scaleFactor,u=a.fontSize,d=h.max-h.min;if(null==o||isNaN(o)||d<=0)return t("span",{class:"bar-chart-empty",style:{color:a.fontColor,fontStyle:"italic"}},"-");const{totalWidth:f,labelAreaWidth:p,barAreaWidth:$,labelGap:v}=function(t,e){const o=lt(t,e),i=Math.min(2.85*e,o/4);return{totalWidth:o,labelAreaWidth:i,barAreaWidth:o-2*i,labelGap:it*e}}(l,a.emPx),m=$/d,g=t=>p+(t-h.min)*m,b=2*c,w=n-2*b,E=b,S=g(0),R=g(h.start),y=g(h.end),O=Math.min(R,y),M=Math.abs(y-R),N=yt(i,o,!1,a),U=Ot(N,bt(i)),{stroke:G,strokeWidth:T}=Mt(N),_=mt(o,"partof"===h.kind,s,r).replace(/^\+/,""),L=y<R,x=L?O-v:O+M+v,C=L?"end":"start";return t("svg",{width:f,height:n,class:"cell-bar-chart waterfall-bar",style:{overflow:"visible"}},t(vt,{styles:a}),t("line",{x1:S,y1:0,x2:S,y2:n,stroke:pt,"stroke-width":1*c}),void 0!==h.parentStart&&void 0!==h.parentEnd&&t("line",{x1:g(h.parentStart),y1:0,x2:g(h.parentStart),y2:n,stroke:pt,"stroke-width":1*c,"stroke-dasharray":`${2*c},${2*c}`}),void 0!==h.parentStart&&void 0!==h.parentEnd&&t("line",{x1:g(h.parentEnd),y1:0,x2:g(h.parentEnd),y2:n,stroke:pt,"stroke-width":1*c,"stroke-dasharray":`${2*c},${2*c}`}),M>0&&t("rect",{x:O,y:E,width:M,height:w,fill:U,stroke:G,"stroke-width":T*c}),t("text",{x,y:n/2,dy:"0.35em","text-anchor":C,fill:a.fontColor,"font-size":u,"font-family":a.fontFamily},_))},_t=`IFNULL(${p.ROWGROUP}, '')`;class Lt{constructor(t){this.groups=[p.CATEGORY,p.CATEGORYINDEX],I.OPT!==t.type&&I.OPTNOTOTAL!==t.type||this.groups.unshift(p.OPERATION),t.grouped&&(this.groups.push(p.ROWGROUP),this.groups.push(p.ROWGROUPINDEX))}toString(){return this.groups.map((t=>t===p.ROWGROUP?_t:t)).toString()}select(){return this.groups.map((t=>t===p.ROWGROUP?`${_t} as ${t}`:t)).toString()}noCategory(){return this.groups.filter((t=>t!==p.CATEGORY))}toArray(){return this.groups}}class xt{constructor(t,e){this.hasPartOf=!1,this.params=[],this.sortSelect="",this.hasBlankRowGroup=!1,this.config=t,this.i18n=e}execute(t,e){var o;this.db=t,this.fromExpr=e;for(const t of[...this.config.scenarios,...this.config.categoryThereOf.keys()])if(!_.test(t))throw new Error(`invalid identifier "${t}"`);const i=[],n=[],s=[],r=this.config.scenarios.map((t=>this.translateScenarioSQL(t,!1,this.config.type))).toString(),l=this.config.scenarios.map((t=>this.translateScenarioSQL(t,!0,this.config.type))).toString(),a=this.getRelativeScenarios(),h=this.config.attributes.map((t=>this.translateAttributeSQL(t))).toString(),c=new Lt(this.config),u=this.config.interval===X?this.config.sortOrder:{hierarchy:this.config.sortOrder.hierarchy.map((t=>{var e,o;return null!==(o=null===(e=L(t))||void 0===e?void 0:e.column)&&void 0!==o?o:t})),direction:this.config.sortOrder.direction};let d=["",""];u.hierarchy.length>0&&(d=this.createOrderString(u)),this.hasPartOf=this.checkConfigForPartOf();const{hierarchy:f,direction:$}=u,v=f.filter((t=>t===p.ROWGROUP||t===p.ROWGROUPINDEX||t.toUpperCase()in b)),m=v.filter((t=>t.toUpperCase()in b)).map((t=>`, SUM(${t} * transformOperator(operation)) as ${t}`)).join(""),g=v.length>0?v.map((t=>`${t} ${$}`)).toString():`${p.ROWGROUPINDEX} asc`,w=t.exec(`SELECT COUNT(DISTINCT ${p.CATEGORY}) as ${p.TOTALROWCOUNT} ${this.config.grouped?`, ${_t} as ${p.ROWGROUP}, FIRST(${p.ROWGROUPINDEX}) as ${p.ROWGROUPINDEX}${m}`:""}\n FROM ${e} ${this.config.grouped?`GROUP BY ${_t} ORDER BY ${g}`:""}`);return 0===w.length||1===w.length&&0===(null!==(o=w[0][p.TOTALROWCOUNT])&&void 0!==o?o:0)&&!this.config.grouped?[]:(this.hasBlankRowGroup=this.config.grouped&&w.some((t=>""===t.rowGroup)),w.forEach((t=>{const e=this.config.grouped?""===t.rowGroup?`WHERE (${p.ROWGROUP} IS NULL OR ${p.ROWGROUP} = '')`:`WHERE ${p.ROWGROUP} = ${this.bind(t.rowGroup)}`:"";let o="";this.config.limit&&(o=`LIMIT ${this.config.limit}`),this.createGroupHeaderRow(t,i),this.createDataRow(i,t,c,r,h,e,d,o),this.createRestRow(t,i,c,r,e,d),this.createGroupSumRow(i,n,t,l,e,d)})),this.createTotalSumRow(i,n,l),i.forEach((t=>s.push(this.exec(t)))),this.detectNaNCells(this.config.scenarios,s),this.createThereOfDrillRows(r,h,d,s),this.createPartOfDrillRows(r,d,n,s),this.createIntervalColumns(s),this.createThereOfDrillColumns(this.config.categoryThereOf,s),this.calculateColumnGroupRest(s,this.config.categoryThereOf),this.calculateRelativeVariances(s,a),s)}detectNaNCells(t,e){e.forEach((e=>{e.map((e=>(t.forEach((t=>{const o=new f(t);!0===o.isValid?0!==e[o.base+"_cnt"]&&0!==e[o.delta+"_cnt"]||(e[t]=Number.NaN):0===e[t+"_cnt"]&&(e[t]=Number.NaN)})),e)))}))}createPartOfDrillRows(t,e,o,i){if(null==this.config.partOf||0===this.config.partOf.length||this.config.type===I.LIST)return;const n=this.createPartOfQuery(t,e);let s=[];const r=this.db,l=this.params;n.forEach((t=>{s.push(...this.exec(t))}));const a=this.exctractScenarioNames(t),h=[];o.forEach((function(t){h.push(...r.exec(t,l))}));const c=new Map;h.forEach((t=>c.set(t[p.ROWGROUP],t))),s=this.reduceResDrillByCategoryGroups(s,a),s.forEach((function(t){a.forEach((e=>{try{t[e]=t[e]/c.get(t[p.ROWGROUP])[e]}catch(o){console.error("DataQuery: partOf drill row calculation failed",e,o),t[e]=Number.NaN}}))})),this.injectDrillRowsToResultRows(s,i)}createRestRow(t,e,o,i,n,s){var r;if(t.totalRowCnt-this.config.limit>0&&0!==this.config.limit){const l=this.exctractScenarioNames(i).map((t=>`SUM(${t}) as ${t}`)).join(", "),a=I.OPT===this.config.type||I.OPTNOTOTAL===this.config.type?", CASE WHEN MAX(transformOperator(operation)) = -1 THEN '-' ELSE '+' END as restOperation":"";e.push(`SELECT ${p.ROWNR}, 1 as ${p.ROWGROUPINDEX} , 'ENTRY' as ${p.TYPE}, 'NO_GROUP' as ${p.ROWGROUP}, ${this.bind(String(null!==(r=t.rowGroup)&&void 0!==r?r:""))} as restRowGroup, 'REST' as ${p.CATEGORY}${a} ${l.length>0?", "+l:""} FROM (SELECT ROWNUM() AS ${p.ROWNR}, ${e.length} as ${p.ROWGROUPINDEX} , 'ENTRY' as ${p.TYPE}, ${this.bind(String(t.rowGroup||"NO_GROUP"))} as ${p.ROWGROUP}, ${o.select()} ${i.length>0?",".concat(i):""}${this.sortSelect} FROM ${this.fromExpr} ${n} GROUP BY ${o} ORDER BY ${s[0]}) t WHERE t.rowNr > ${this.config.limit}`)}}createDataRow(t,e,o,i,n,s,r,l){t.push(`SELECT ROWNUM() AS ${p.ROWNR},\n ${t.length} as ${p.ROWGROUPINDEX},\n 'ENTRY' as ${p.TYPE},\n ${this.bind(String(e.rowGroup||"NO_GROUP"))} as ${p.ROWGROUP},\n '${p.CATEGORYINDEX}',\n ${o.select()} ${i.length>0?",".concat(i):""} ${n.length>0?",".concat(n):""}${this.sortSelect}\n FROM ${this.fromExpr} ${s}\n GROUP BY ${o}\n ORDER BY ${r[0]} ${l}`)}createGroupHeaderRow(t,e){if(!0===this.config.grouped){const o=this.bind(String(t.rowGroup)),i=""===t.rowGroup?this.bind("-"):o;e.push(`SELECT ROWNUM() AS ${p.ROWNR},\n ${e.length} as ${p.ROWGROUPINDEX},\n 'GROUPHEAD' as ${p.TYPE},\n ${o} as ${p.ROWGROUP} ${this.config.showGroupTitle?`,${i} as ${p.CATEGORY}`:""}\n FROM ${this.fromExpr}\n GROUP BY '1'`)}}createGroupSumRow(t,e,o,i,n,s){if(!0===this.config.grouped&&(I.SUM===this.config.type||I.SUMNOTOTAL===this.config.type||I.OPT===this.config.type||I.OPTNOTOTAL===this.config.type)){const r=this.bind(String(o.rowGroup));t.push(`SELECT ${t.length} as ${p.ROWGROUPINDEX},\n '=' as ${p.OPERATION},\n ${r} as ${p.ROWGROUP},\n ROWNUM() AS ${p.ROWNR},\n 'GROUP_SUM' as ${p.TYPE} ${i.length>0?",".concat(i):""}\n FROM ${this.fromExpr} ${n}\n ORDER BY ${s[0]} `),e.push(`SELECT ${t.length} as ${p.ROWGROUPINDEX},\n '=' as ${p.OPERATION},\n ${r} as ${p.ROWGROUP},\n ROWNUM() AS ${p.ROWNR},\n 'GROUP_SUM' as ${p.TYPE} ${i.length>0?",".concat(i):""}\n FROM ${this.fromExpr} ${n}\n ORDER BY ${s[0]} `)}}createTotalSumRow(t,e,o){var i;if(I.SUM===this.config.type||I.OPT===this.config.type){const e=(null===(i=this.config.title)||void 0===i?void 0:i.trim())||"SUM_TOTAL",n=this.hasPartOf&&!1===this.config.grouped&&"SUM_TOTAL"!==e?`${this.i18n.get("SUM_TOTAL")||"SUM_TOTAL"} ${e}`:e;t.push(`SELECT ${t.length} as ${p.ROWGROUPINDEX},\n ${this.bind(n)} as ${p.ROWGROUP},\n '=' as ${p.OPERATION},\n 'SUM' as ${p.TYPE} ${o.length>0?",".concat(o):""}\n FROM ${this.fromExpr} `)}e.push(`SELECT ${t.length} as ${p.ROWGROUPINDEX},\n 'SUM_TOTAL' as ${p.ROWGROUP},\n '=' as ${p.OPERATION},\n 'SUM' as ${p.TYPE} ${o.length>0?",".concat(o):""}\n FROM ${this.fromExpr} `)}reduceResDrillByCategoryGroups(t,e){const o=new Map;return t.forEach((function(t){const i=t.rowNr+t.rowGroup+t.type+t.category;if(o.has(i)){const n=o.get(i);e.forEach((e=>{try{n[e]+=t[e]}catch(t){console.error("DataQuery: drill row aggregation failed",e,t)}}))}else o.set(i,t)})),[...o.values()]}injectDrillRowsToResultRows(t,e){const o=new Map;if(!0===this.config.grouped)t.forEach((function(t){e.forEach((function(e){const i=e.findIndex((e=>e.category===t.category&&e.rowGroup===t.rowGroup));if(i>=0){if(o.has(`${t.category}_${t.rowGroup}`)){const e=o.get(`${t.category}_${t.rowGroup}`)||0;o.set(`${t.category}_${t.rowGroup}`,e+1)}else o.set(`${t.category}_${t.rowGroup}`,1);t[p.ROWNR]=o.get(`${t.category}_${t.rowGroup}`),e.splice(i+t[p.ROWNR],0,t)}}))}));else{const i=this.findDuplicateSubCategories(t);t.forEach((function(t){e.forEach((function(e){const n=e.findIndex((e=>null!=e.category&&e.category===t.category));if(n>=0){if(o.has(`${t.category}`)){const e=o.get(`${t.category}`)||0;o.set(`${t.category}`,e+1)}else o.set(`${t.category}`,1);null!=t.rowGroup&&""!==t.rowGroup&&i.includes(`${t.category}##${t.subCategory}`)&&(t.rawSubCategory=t.subCategory,t.subCategory=`${t.subCategory} (${t.rowGroup})`),e.splice(n+t[p.ROWNR],0,t)}}))}))}}createThereOfDrillRows(t,e,o,i){if(void 0===this.config.thereOf||0===this.config.thereOf.length)return;const n=[],s=[];this.config.thereOf.forEach((i=>{let s=!0,r="1 <> 1 OR ( ";null!=i.category&&0!==i.category.length&&i.category.trim()&&(r+=` ${p.CATEGORY} = ${this.bind(i.category)}`,s=!1),null!=i.rowGroup&&0!==i.rowGroup.length&&i.rowGroup.trim()&&(r+=` ${s?"":"AND"} ${p.ROWGROUP} = ${this.bind(i.rowGroup)}`,s=!1),null!=i.subCategory&&0!==i.subCategory.length&&i.subCategory.trim()&&(r+=` ${s?"":"AND"} ${p.SUBCATEGORY} = ${this.bind(i.subCategory)}`),r+=")",n.push(`SELECT ROWNUM() AS ${p.ROWNR},\n null as operation,\n 'DRILLELEMENT' as ${p.TYPE},\n ${p.CATEGORY},\n ${p.SUBCATEGORY},\n ${this.drillRowGroup} as ${p.ROWGROUP},\n ${t} ${e.length>0?",".concat(e):""}${this.sortSelect}\n FROM ${this.fromExpr}\n WHERE ${r}\n GROUP BY ${this.drillRowGroup}, ${p.CATEGORY}, ${p.SUBCATEGORY}\n ORDER BY ${o[1]}`)})),n.forEach((t=>{s.push(...this.exec(t))})),this.injectDrillRowsToResultRows(s,i)}calculateRelativeVariances(t,e){t.forEach((t=>{t.forEach((t=>{"GROUPHEAD"!==t[p.TYPE]&&e.forEach(((e,o)=>{var i;t[o]=null!==(i=M(t[o],t[e]))&&void 0!==i?i:O}))}))}))}calculateColumnGroupRest(t,e){if(null==e||0===e.size)return;const o=new Map,i=new Map;e.forEach(((t,e)=>{const n=t,s=[];for(const t of n)s.push(`${e}##${t.name}`);o.set(e,s),i.set(`${e}##REST`,!1)})),t.forEach((t=>{t.forEach((t=>{"GROUPHEAD"!==t[p.TYPE]&&o.forEach(((e,o)=>{let n=0;e.forEach((e=>{void 0!==t[e]&&(n+=t[e])})),t[`${o}##REST`]=t[o]-n,0!==t[`${o}##REST`]&&i.set(`${o}##REST`,!0)}))}))}));const n=Array.from(i.entries()).filter((([t,e])=>!e)).map((([t])=>t));t.forEach((t=>{t.forEach((t=>{for(const e of n)delete t[e]}))}))}createIntervalColumns(t){var e,o,i,n,s;if(this.config.interval===V||this.config.categoryThereOf.size>0||0===this.config.scenarios.length)return;const r="##",l=`(SELECT *, ${q(this.config.interval)} as __interval FROM ${this.fromExpr}) as p`,a=this.config.scenarios.map((t=>this.translateScenarioSQL(t,!1,this.config.type))).toString(),h=this.config.scenarios.map((t=>this.translateScenarioSQL(t,!0,this.config.type))).toString(),c=[...new Set(this.exctractScenarioNames(a))],u=this.getRelativeScenarios(),d=new Lt(this.config),$=I.OPT===this.config.type||I.OPTNOTOTAL===this.config.type,v=this.config.grouped&&(I.SUM===this.config.type||I.SUMNOTOTAL===this.config.type||I.OPT===this.config.type||I.OPTNOTOTAL===this.config.type),m=this.checkConfigForPartOf()&&this.config.type!==I.LIST,g=t=>this.exec(t),b=t=>(this.config.scenarios.forEach((e=>{const o=new f(e);!0===o.isValid?0!==t[o.base+"_cnt"]&&0!==t[o.delta+"_cnt"]||(t[e]=Number.NaN):0===t[e+"_cnt"]&&(t[e]=Number.NaN)})),u.forEach(((e,o)=>{var i;t[o]=null!==(i=M(t[o],t[e]))&&void 0!==i?i:O})),t),w=(t,e,o)=>{for(const i of this.config.scenarios)t[i+r+o]=e[i]},E=g(`SELECT ${d.select()}, __interval ${a.length>0?",".concat(a):""}\n FROM ${l}\n GROUP BY ${d}, __interval`);if(this.config.limit>0)for(let i=0;i<t.length;i++){const n=t[i].find((t=>"ENTRY"===t.type&&"REST"===t.category));if(!n)continue;let s;for(let e=i-1;e>=0&&!s;e--){const o=t[e].filter((t=>"ENTRY"===t.type&&"REST"!==t.category));o.length>0&&(s=o)}if(!s)continue;const r=new Set(s.map((t=>t.category))),l=s[0].rowGroup,a=new Map;for(const t of E){if(this.config.grouped&&t.rowGroup!==l)continue;if(r.has(t.category))continue;const i=K(t.__interval);let n=a.get(i);n||(n={},a.set(i,n));for(const i of c)n[i]=(null!==(e=n[i])&&void 0!==e?e:0)+(null!==(o=t[i])&&void 0!==o?o:0)}a.forEach(((t,e)=>{w(n,b(t),e)}))}for(const e of E){const o=K(e.__interval);b(e);for(const i of t)for(const t of i)"ENTRY"===t.type&&"REST"!==t.category&&t.category===e.category&&(this.config.grouped&&t.rowGroup!==e.rowGroup||$&&t.operation!==e.operation||w(t,e,o))}const S=v||m&&this.config.grouped?g(`SELECT ${_t} as ${p.ROWGROUP}, __interval ${h.length>0?",".concat(h):""}\n FROM ${l}\n GROUP BY ${_t}, __interval`):[],R=new Map;if(S.forEach((t=>R.set(`${t.rowGroup}${r}${K(t.__interval)}`,t))),v)for(const e of S){const o=K(e.__interval),i=b(Object.assign({},e));for(const n of t)for(const t of n)"GROUP_SUM"===t.type&&t.rowGroup===e.rowGroup&&w(t,i,o)}const y=I.SUM===this.config.type||I.OPT===this.config.type,N=y||m&&!this.config.grouped?g(`SELECT __interval ${h.length>0?",".concat(h):""}\n FROM ${l}\n GROUP BY __interval`):[],U=new Map;if(N.forEach((t=>U.set(K(t.__interval),t))),y)for(const e of N){const o=K(e.__interval),i=b(Object.assign({},e));for(const e of t)for(const t of e)"SUM"===t.type&&w(t,i,o)}if(null!=this.config.thereOf&&this.config.thereOf.length>0){const e=[];this.config.thereOf.forEach((t=>{e.push(...g(`SELECT ${this.drillRowGroup} as ${p.ROWGROUP}, ${p.CATEGORY}, ${p.SUBCATEGORY}, __interval ${a.length>0?",".concat(a):""}\n FROM ${l}\n WHERE ${this.createThereOfWhereClause(t)}\n GROUP BY ${this.drillRowGroup}, ${p.CATEGORY}, ${p.SUBCATEGORY}, __interval`))}));for(const o of e){const e=K(o.__interval);b(o);for(const i of t)for(const t of i)"DRILLELEMENT"===t.type&&t.category===o.category&&t.rowGroup===o.rowGroup&&(t.subCategory!==o.subCategory&&t.subCategory!==`${o.subCategory} (${o.rowGroup})`||w(t,o,e))}}if(m){let e="1 <> 1 ";null===(i=this.config.partOf)||void 0===i||i.forEach((t=>{e+=`OR (${p.CATEGORY} = ${this.bind(t.category)}`,null!=t.rowGroup&&0!==t.rowGroup.length&&t.rowGroup.trim()&&(e+=`and ${p.ROWGROUP} = ${this.bind(t.rowGroup)}`),e+=")"}));const o=g(`SELECT ${p.CATEGORY}, ${this.config.grouped?`${p.ROWGROUP}`:`'SUM_TOTAL' as ${p.ROWGROUP}`}, __interval ${a.length>0?",".concat(a):""}\n FROM ${l}\n WHERE ${e}\n GROUP BY ${p.ROWGROUP}, ${p.CATEGORY}, __interval`),h=new Map;for(const t of o){const e=`${t.rowGroup}${r}${t.category}${r}${K(t.__interval)}`,o=h.get(e);if(o)for(const e of c)o[e]=(null!==(n=o[e])&&void 0!==n?n:0)+(null!==(s=t[e])&&void 0!==s?s:0);else h.set(e,t)}h.forEach((e=>{const o=K(e.__interval),i=this.config.grouped?R.get(`${e.rowGroup}${r}${o}`):U.get(o);for(const t of c)e[t]=e[t]/(i?i[t]:Number.NaN);b(e);for(const i of t)for(const t of i)"PARTELEMENT"===t.type&&t.category===e.category&&t.rowGroup===e.rowGroup&&w(t,e,o)}))}}createThereOfWhereClause(t){let e=!0,o="1 <> 1 OR ( ";return null!=t.category&&0!==t.category.length&&t.category.trim()&&(o+=` ${p.CATEGORY} = ${this.bind(t.category)}`,e=!1),null!=t.rowGroup&&0!==t.rowGroup.length&&t.rowGroup.trim()&&(o+=` ${e?"":"AND"} ${p.ROWGROUP} = ${this.bind(t.rowGroup)}`,e=!1),null!=t.subCategory&&0!==t.subCategory.length&&t.subCategory.trim()&&(o+=` ${e?"":"AND"} ${p.SUBCATEGORY} = ${this.bind(t.subCategory)}`),o+")"}getRelativeScenarios(){const t=new Map;return this.config.scenarios.forEach((e=>{const o=this.createRelativeScenario(e);null!=o&&t.set(o.key,o.value)})),t}translateScenarioSQL(t,e,o){const i=new f(t);if(I.OPT===o||I.OPTNOTOTAL===o){if(i.isValid){const o=e?" * transformOperator(operation)":"",n=e?`SUM((${i.base} - ${i.delta})${o}) as ${t}`:`SUM(${i.base} - ${i.delta}) as ${t}`;return"dr"===i.type?`${n}, SUM(${i.delta}${o}) as dr_${i.delta}`:n}return e?`SUM(${t} * transformOperator(operation)) as ${t}, COUNT(ISNULL(${t})) as ${t}_cnt`:`SUM(${t}) as ${t}, COUNT(ISNULL(${t})) as ${t}_cnt`}return i.isValid?"dr"===i.type?`SUM((${i.base} * transformOperator(operation)) - (${i.delta} * transformOperator(operation))) as ${t}, SUM(${i.delta} * transformOperator(operation)) as dr_${i.delta}`:`SUM((${i.base} * transformOperator(operation))- (${i.delta} * transformOperator(operation))) as ${t}`:`SUM(${t} * transformOperator(operation)) as ${t}, COUNT(ISNULL(${t})) as ${t}_cnt`}translateAttributeSQL(t){const e=`[${t.arg}]`,o=/^(ac|pp|fc|pl)[1-4]$/.test(t.arg)&&this.config.type!==I.OPT&&this.config.type!==I.OPTNOTOTAL;switch(t.fn){case"set":return`SETAGG(${e}) as ${t.alias}`;case"first":return`FIRST(${e}) as ${t.alias}`;case"last":return`LAST(${e}) as ${t.alias}`;case"min":return`MIN(${e}) as ${t.alias}`;case"max":return`MAX(${e}) as ${t.alias}`;case"avg":return o?`AVG(${e} * transformOperator(operation)) as ${t.alias}`:`AVG(${e}) as ${t.alias}`;case"sum":return o?`SUM(${e} * transformOperator(operation)) as ${t.alias}`:`SUM(${e}) as ${t.alias}`;case"lit":{const e=t.arg;return`${this.bind(""===e||Number.isNaN(Number(e))?e:Number(e))} as ${t.alias}`}}}get drillRowGroup(){return this.config.grouped?_t:p.ROWGROUP}exec(t){const e=this.db.exec(t,this.params);return this.config.grouped&&e.forEach((t=>t.rowGroup=null==t.rowGroup?"":String(t.rowGroup))),e}bind(t){return`$${this.params.push(t)-1} `}createOrderString(t){const e=z.ASC===t.direction?z.DESC:z.ASC,o=new Map;t.hierarchy.forEach(((t,e)=>{const i=L(t),n=null==i?void 0:i.bucket;("variance"===(null==i?void 0:i.kind)||"scenario"===(null==i?void 0:i.kind)&&void 0!==n)&&o.set(e,this.translateSortKeySQL(i,n,e))})),this.sortSelect=[...o.values()].map((t=>`, ${t}`)).join("");const i=(t,e,i)=>o.has(e)?`__sortnull${e} asc, __sort${e} ${i}`:`${t} ${i}`;return[t.hierarchy.map(((e,o)=>i(e,o,t.direction))).toString(),t.hierarchy.map(((t,o)=>i(t,o,e))).toString()]}translateSortKeySQL(t,e,o){const i=I.OPT===this.config.type||I.OPTNOTOTAL===this.config.type?"":" * transformOperator(operation)",n=void 0===e?"":`TRIM(CAST(${q(X)} AS STRING)) = ${this.bind(e)}`,s=t=>`SUM(${n?`(CASE WHEN ${n} THEN ${t} ELSE 0 END)`:t}${i})`,r=t=>`SUM(CASE WHEN ${n?`${n} AND `:""}${t} IS NOT NULL THEN 1 ELSE 0 END) = 0`;if("scenario"===t.kind)return`${s(t.column)} as __sort${o}, CASE WHEN ${r(t.column)} THEN 1 ELSE 0 END as __sortnull${o}`;const l=`(${s(t.base)} - ${s(t.delta)})`;let a=l,h=`${r(t.base)} OR ${r(t.delta)}`;if("dr"===t.type){const e=s(t.delta),o=`ABS(${e}) <= ABS(${l}) * 0.000000001`;a=`CASE WHEN ${o} THEN 0 ELSE ${l} / ABS(${e}) END`,h+=` OR ${o}`}return`${a} as __sort${o}, CASE WHEN ${h} THEN 1 ELSE 0 END as __sortnull${o}`}createRelativeScenario(t){const e=new f(t);return e.isValid&&"dr"===e.type?{key:`${t}`,value:`dr_${e.delta}`}:null}exctractScenarioNames(t){const e=[];return t.split(",").forEach((t=>t.length>=2?e.push(t.split("as")[1].trim()):null)),e}findDuplicateSubCategories(t){const e=t.map((t=>({count:1,subCategory:`${t.category}##${t.subCategory}`}))).reduce(((t,e)=>(t[e.subCategory]=(t[e.subCategory]||0)+e.count,t)),{});return Object.keys(e).filter((t=>e[t]>1))}createPartOfQuery(t,e){var o;const i=[];let n="1 <> 1 ",s=` ${this.drillRowGroup} as ${p.ROWGROUP}`,r="ROWNUM()";return null===(o=this.config.partOf)||void 0===o||o.forEach((t=>{n+=`OR (${p.CATEGORY} = ${this.bind(t.category)}`,null!=t.rowGroup&&0!==t.rowGroup.length&&t.rowGroup.trim()&&(n+=`and ${p.ROWGROUP} = ${this.bind(t.rowGroup)}`),!1===this.config.grouped&&(s=` 'SUM_TOTAL' as ${p.ROWGROUP} `,r="1"),n+=")"})),i.push(`SELECT ${r} AS ${p.ROWNR},\n 'PARTELEMENT' as ${p.TYPE},\n ${p.CATEGORY},\n ${s},\n ${t}${this.sortSelect}\n FROM ${this.fromExpr}\n WHERE ${n}\n GROUP BY ${this.drillRowGroup}, ${p.CATEGORY}, ${p.TYPE}\n ORDER BY ${e[1]}`),i}checkConfigForPartOf(){return null!=this.config.partOf&&0!==this.config.partOf.length}createThereOfDrillColumns(t,e){if(null==t||0===t.size)return;const o=[],i=[],n=this.fromExpr;t.forEach(((t,e)=>{let i="1 <> 1 ";t.forEach((t=>{i+=` or columnGroup = ${this.bind(String(t.name))} `})),o.push(`SELECT 'ENTRY' as rowlevel,\n 'COLUMNGROUP' as columnlevel,\n rowGroup,\n category,\n columnGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${n}\n WHERE ${i}\n GROUP BY rowlevel, rowGroup, category, columnGroup, scenario`),o.push(`SELECT 'ENTRY' as rowlevel,\n 'SUBGROUP' as columnlevel,\n rowGroup,\n category,\n columnGroup,\n columnSubGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${n}\n WHERE ${i}\n GROUP BY rowlevel, rowGroup, category, columnGroup, columnSubGroup, scenario`),o.push(`SELECT 'DRILLELEMENT' as rowlevel,\n 'COLUMNGROUP' as columnlevel,\n rowGroup,\n category,\n subCategory,\n columnGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${n}\n WHERE ${i}\n GROUP BY rowlevel, rowGroup, category, subCategory, columnGroup, scenario`),o.push(`SELECT 'DRILLELEMENT' as rowlevel,\n 'SUBGROUP' as columnlevel,\n rowGroup,\n category,\n subCategory,\n columnGroup,\n columnSubGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${n}\n WHERE ${i}\n GROUP BY rowlevel, rowGroup, category, subCategory, columnGroup, columnSubGroup, scenario`),o.push(`SELECT 'GROUP_SUM' as rowlevel,\n 'COLUMNGROUP' as columnlevel,\n rowGroup,\n columnGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${n}\n WHERE ${i}\n GROUP BY rowlevel, rowGroup, columnGroup, scenario`),o.push(`SELECT 'GROUP_SUM' as rowlevel,\n 'SUBGROUP' as columnlevel,\n rowGroup,\n columnGroup,\n columnSubGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${n}\n WHERE ${i}\n GROUP BY rowlevel, rowGroup, columnGroup, columnSubGroup, scenario`),o.push(`SELECT 'SUM' as rowlevel,\n 'COLUMNGROUP' as columnlevel,\n columnGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${n}\n WHERE ${i}\n GROUP BY rowlevel, columnGroup, scenario`),o.push(`SELECT 'SUM' as rowlevel,\n 'SUBGROUP' as columnlevel,\n columnGroup,\n columnSubGroup,\n '${e}' as scenario,\n sum(${e} * transformOperator(operation)) as val\n FROM ${n}\n WHERE ${i}\n GROUP BY rowlevel, columnGroup, columnSubGroup, scenario`)}));for(const t of o)i.push(...this.db.exec(t,this.params));this.injectDrillColumnsToResultRows(i,e)}injectDrillColumnsToResultRows(t,e){const o="##";for(const i of t)for(const t of e)for(const e of t)if(e.type===i.rowlevel)if("ENTRY"===i.rowlevel)"COLUMNGROUP"===i.columnlevel&&e.category===i.category?e[i.scenario+o+i.columnGroup]=i.val:"SUBGROUP"===i.columnlevel&&e.category===i.category&&(e[i.scenario+o+i.columnGroup+o+i.columnSubGroup]=i.val);else if("DRILLELEMENT"===i.rowlevel){if(!this.config.grouped&&e.rowGroup!==i.rowGroup)continue;"COLUMNGROUP"===i.columnlevel&&e.category===i.category&&e.subCategory===i.subCategory?e[i.scenario+o+i.columnGroup]=i.val:"SUBGROUP"===i.columnlevel&&e.category===i.category&&e.subCategory===i.subCategory?e[i.scenario+o+i.columnGroup+o+i.columnSubGroup]=i.val:"COLUMNGROUP"===i.columnlevel&&e.category===i.category&&e.subCategory===`${i.subCategory} (${i.rowGroup})`?e[i.scenario+o+i.columnGroup]=i.val:"SUBGROUP"===i.columnlevel&&e.category===i.category&&e.subCategory===`${i.subCategory} (${i.rowGroup})`&&(e[i.scenario+o+i.columnGroup+o+i.columnSubGroup]=i.val)}else("SUM"===i.rowlevel||"GROUP_SUM"===i.rowlevel)&&("COLUMNGROUP"===i.columnlevel&&e.category===i.category&&e.subCategory===i.subCategory&&(e[i.scenario+o+i.columnGroup]=i.val),"SUBGROUP"===i.columnlevel&&e.category===i.category&&e.subCategory===i.subCategory&&(e[i.scenario+o+i.columnGroup+o+i.columnSubGroup]=i.val))}}class Ct{constructor(){this.geometry=new Map}set(t,e,o){let i=this.geometry.get(t);i||(i=new Map,this.geometry.set(t,i)),i.set(e,o)}get(t,e){var o;return null===(o=this.geometry.get(t))||void 0===o?void 0:o.get(e)}}function kt(t,e,o){const i=t[e];if(null==i)return null;const n=Number(i);return isNaN(n)?null:o!==I.OPT&&o!==I.OPTNOTOTAL||t[p.TYPE]!==Q.ENTRY||"-"!==t[p.OPERATION]?n:-n}class At{constructor(t){this.ruleSet=t,this.normalizedHeader=[],this.attributesByAlias=new Map,this.hasBlankRowGroup=!1,this.dateBuckets=!1,this.unsignedEntries=!1}underlineClass(t){return this.ruleSet&&/^(ac|pp|fc|pl)[1-4]$/.test(t)?$(this.ruleSet.getScenarioColorIndex(t))+t.slice(2):null}getNormalizedHeader(){return this.normalizedHeader}createHeader(t,e,o,i,n,s,r=[]){const l=[];this.attributesByAlias=new Map(r.map((t=>[t.alias,t]))),this.normalizedHeader=this.normalizeHeader(t,e,r);const a=this.normalizedHeader.some((t=>void 0!==t.bucket));a&&l.push(this.createIntervalBandRow());const h=new et(a?1:0,0,Q.HEADER),c=new et(a?2:1,0,Q.SEPERATORLINE);for(const t of this.normalizedHeader){const e=this.attributesByAlias.get(t.name);h.createElement(e?o.get(e.label)||e.label:d.translateScenarioLabel(t.name,o),t.type,this.createColumnType(t),null,this.setHeaderPrefix(t,o,i,n,s),null,null,null,null),c.createElement(null,t.type,this.createColumnType(t),null,null,this.underlineClass(t.type),null,null,null)}return l.push(h),l.push(c),l}createIntervalBandRow(){const t=new et(0,0,Q.HEADER);let e=0;for(;e<this.normalizedHeader.length;){const o=this.normalizedHeader[e];if(void 0===o.bucket){t.createElement(null,o.type,"filler",null,null,null,null,null,null),e+=1;continue}let i=1;for(;e+i<this.normalizedHeader.length&&this.normalizedHeader[e+i].bucket===o.bucket;)i+=1;t.createElement(o.bucketLabel,o.type,"intervalGroup",null,null,null,null,null,null,!1,void 0,i),e+=i}return t}setHeaderPrefix(t,e,o,i,n){let s="";return"category"===t.name&&n&&(0===o.prefix.length&&0===i.length||(s=d.translateScenarioLabel("in",e)+" "+o.prefix+i)),t.order&&(s+=d.translateScenarioLabel("ORDER_"+t.order,e)),s}normalizeHeader(t,e,o){let i=[{name:p.CATEGORY,group:p.CATEGORY,type:p.CATEGORY,order:void 0}];I.OPT!==t&&I.OPTNOTOTAL!==t||(i=[{name:p.OPERATION,group:p.OPERATION,type:p.OPERATION,order:void 0},{name:p.CATEGORY,group:p.CATEGORY,type:p.CATEGORY,order:void 0}]);const n=o.map((t=>({name:t.alias,group:t.alias,type:t.alias,order:void 0})));return[...i,...n,...e]}createBodyRows(t,e,o,i){var n;const s=[];let r=-1;const l=new xt(t,e);var a;this.dateBuckets=(a=t.interval)!==V&&a!==X,this.unsignedEntries=I.OPT===t.type||I.OPTNOTOTAL===t.type;const h=l.execute(o,i);this.hasBlankRowGroup=l.hasBlankRowGroup;const c=this.calculateColumnStatistics(h,t.barColumns,t.interval!==V),u=(null!==(n=t.barColumns)&&void 0!==n?n:[]).filter((t=>t.toUpperCase().trim()in b)),d=u.length>0&&t.interval===V&&0===t.categoryThereOf.size&&function(t){for(const e of t)for(const t of e){const e=t[p.TYPE];if(e===Q.SUM||e===Q.GROUPSUM||e===Q.DRILLELEMENT||e===Q.PARTELEMENT)return!0}return!1}(h)?function(t,e,o){const i=new Ct;for(const n of e){let e,s=0,r=0;const l=[],a=(t,e)=>{l.push(e),i.set(t,n,e)};for(const i of t)for(const t of i){const i=t[p.TYPE];if(i===Q.GROUPHEAD){e=void 0;continue}const l=kt(t,n,o);if(i===Q.ENTRY){if(null===l){e=void 0;continue}a(t,{start:s,end:s+l,min:0,max:0,kind:"cascade"}),e={start:s,end:s+l},r=e.start,s+=l}else if(i===Q.SUM||i===Q.GROUPSUM){if(null===l){e=void 0;continue}a(t,{start:0,end:l,min:0,max:0,kind:"anchor"}),e={start:0,end:l},r=0,s=l}else if(i===Q.DRILLELEMENT){if(null===l||void 0===e)continue;const o=r+(Math.sign(e.end-e.start)||1)*Math.abs(l);a(t,{start:r,end:o,min:0,max:0,kind:"thereof",parentStart:e.start,parentEnd:e.end}),r=o}else if(i===Q.PARTELEMENT){if(null===l||void 0===e)continue;const o=r+l*(e.end-e.start);a(t,{start:r,end:o,min:0,max:0,kind:"partof",parentStart:e.start,parentEnd:e.end}),r=o}}let h=0,c=0;for(const t of l)h=Math.min(h,t.start,t.end),c=Math.max(c,t.start,t.end);for(const t of l)t.min=h,t.max=c}return i}(h,u,t.type):void 0;for(const o of h)r+=1,s.push(...this.createRow(t.i18n,e,t.scenariosUnitType,o,r,-1,t.categoryWidth,t.measureScale,t.barColumns,c,d));return s}calculateColumnStatistics(t,e,o=!1){const i=new Map;if(!e||0===e.length)return i;const n=new Map;for(const t of e)i.set(t,{min:1/0,max:-1/0,absMax:0,median:0}),n.set(t,[]);for(const s of t)for(const t of s){const s=t[p.TYPE];if(s!==Q.SUM&&s!==Q.GROUPSUM)for(const s of e){const e=o?this.extractIntervalColumnValues(t,s):[this.extractColumnValue(t,s)];for(const t of e)if(null!==t&&!isNaN(t)){const e=i.get(s);e.min=Math.min(e.min,t),e.max=Math.max(e.max,t),n.get(s).push(Math.abs(t))}}}for(const[t,e]of i){e.min!==1/0&&e.max!==-1/0||(e.min=0,e.max=0),e.absMax=Math.max(Math.abs(e.min),Math.abs(e.max));const o=n.get(t);if(o.length>0){o.sort(((t,e)=>t-e));const t=Math.floor(o.length/2);e.median=o.length%2==0?(o[t-1]+o[t])/2:o[t]}i.set(t,e)}return i}extractIntervalColumnValues(t,e){const o=e+"##",i=[];for(const e of Object.keys(t))if(e.startsWith(o)){const o=Number(t[e]);i.push(isNaN(o)?null:o)}return i}extractColumnValue(t,e){if(void 0!==t[e]){const o=Number(t[e]);return isNaN(o)?null:o}for(const o of Object.keys(t))if(o===e||o.endsWith("##"+e)||o===e+"##"+e){const e=Number(t[o]);if(!isNaN(e))return e}return null}createRow(t,e,o,i,n,s,r,l,h,c,u){var d,$,v;const m=[];let g;for(const b of i){const w=b[p.ROWGROUP],E=""===w?"-":w,S=b[p.SUBCATEGORY],R=b[p.TYPE],y=b[p.ROWNR]>=2;g=null!==($=null!==(d=b.operation)&&void 0!==d?d:b.restOperation)&&void 0!==$?$:g;const O=this.createDetailRow(R,s+=1,n,i.length);O.key=this.rowKey(b);for(const i of this.normalizedHeader){const n=this.getRawDataRowElement(b,i),s=null!==(v=null==h?void 0:h.includes(i.type))&&void 0!==v&&v,d=s?null==c?void 0:c.get(i.type):void 0,p=s&&void 0===i.bucket&&i.name===i.group&&i.name===i.type?null==u?void 0:u.get(b,i.type):void 0;O.createElement(this.translateSumCellLabel(t,e,n,E,S,R,i.type),i.type,this.createColumnType(i),this.setCellType(i.type,o),this.translateCellPrefix(e,R,i.type),this.translateScenarioCSS(i.type,n,g),y,r,null==l?void 0:l.value,s,d,1,p);const $=O.elements[O.elements.length-1];this.dateBuckets&&void 0!==i.bucket&&($.date=a(i.bucket));const m=new f(i.type);m.isValid&&($.direction=this.resolveDirection(m,g))}m.push(O)}return m}rowKey(t){var e;const o=null!=t.restRowGroup?t.restRowGroup:"NO_GROUP"===t.rowGroup?void 0:t.rowGroup;switch(t.type){case Q.ENTRY:return{rowGroup:o,category:t.category,subCategory:t.subCategory};case Q.DRILLELEMENT:return{rowGroup:o,category:t.category,subCategory:null!==(e=t.rawSubCategory)&&void 0!==e?e:t.subCategory};case Q.GROUPSUM:return{rowGroup:o,row:"subtotal"};case Q.SUM:return{row:"total"};default:return}}getRawDataRowElement(t,e){return void 0!==e.bucket?t[e.type+"##"+e.bucket]:e.name===e.group&&e.name===e.type?t[e.name]:e.name===e.group&&e.name!==e.type?t[e.type+"##"+e.name]:t[e.type+"##"+e.group+"##"+e.name]}createDetailRow(t,e,o,i){switch(t){case Q.GROUPHEAD:return new et(e,o,Q.HEADER);case Q.SUM:case Q.GROUPSUM:return new et(i+2,o,Q.SUM);case Q.DRILLELEMENT:return new et(i+2,o,Q.DRILLELEMENT);case Q.PARTELEMENT:return new et(i+2,o,Q.PARTELEMENT);default:return new et(e,o,Q.STANDARD)}}translateSumCellLabel(t,e,o,i,n,s,r){return this.attributesByAlias.has(r)||!1===Number.isNaN(Number(o))||this.isOperationColumn(r)?o:this.isGroupHeadCategory(s,r)?t===w.ALL?`${e.get(o)||o}`:o:this.isEntryCategory(s,r)?t===w.ALL||"REST"===o?`${e.get(o)||o}`:o:this.isDrillElementCategory(s,r)?t===w.ALL?`${e.get(n)||n}`:`${n}`:this.isPartElementCategory(s,r)?t===w.ALL||"SUM_TOTAL"===i?`${e.get(i)||i}`:`${i}`:this.isSumElementCategory(s,r)?t===w.ALL||"SUM_TOTAL"===i?`${e.get(i)||i}`:i:"GROUPHEAD"===s&&null==o||o===O?o:Number.isNaN(Number(o))?"-":Number(o)}isOperationColumn(t){return"operation"===t}translateScenarioCSS(t,e,o){if(this.attributesByAlias.has(t))return"attribute";const i=new f(t);let n="pos";return e<0&&(n="neg"),i.isValid?n+"_"+this.resolveDirection(i,o)+("dr"===i.type?" relative_variance":""):t}resolveDirection(t,e){return v(t.direction,e,!this.unsignedEntries)}setCellType(t,e){if("category"===t)return"";const o=this.attributesByAlias.get(t);if(o)return o.isNumeric?"decimal":"";let i;const n=new f(t);return e===E.PERCENT?(i="percent",n.isValid&&"d"===n.type&&(i="percentpoint")):(i="decimal",n.isValid&&"dr"===n.type&&(i="percent")),i}isDrillElementCategory(t,e){return"DRILLELEMENT"===t&&"category"===e}isPartElementCategory(t,e){return"PARTELEMENT"===t&&"category"===e}isSumElementCategory(t,e){return("GROUP_SUM"===t||"SUM"===t)&&"category"===e}isEntryCategory(t,e){return"ENTRY"===t&&"category"===e}isGroupHeadCategory(t,e){return"GROUPHEAD"===t&&"category"===e}translateCellPrefix(t,e,o){return this.isOperationColumn(o)||this.isGroupHeadCategory(e,o)||this.isEntryCategory(e,o)?null:this.isDrillElementCategory(e,o)?`${t.get("thereof")} `:this.isPartElementCategory(e,o)?`${t.get("part_of")} `:null}createColumnType(t){return t.name===t.group&&t.name===t.type?"base":t.name===t.group?"columnGroup":"columnSubGroup"}}class Pt{constructor(t,e,o,i){this.fromExpr="",this.rowCount=0,this.headerRows=[],this.bodyRows=[],this.intervalBuckets=[],this.ruleSet=t||new m,this.db=e,this.dataSetFactory=new At(this.ruleSet),this.config=this.initConfig(i),this.i18n=this.initI18n(new Map),this.setSource(o,i.filter)}setI18n(t){this.i18n=this.initI18n(t)}initI18n(t){const e=new Map([["",""],["SEPARATOR_WS",", "],["in","in"],["ORDER_asc","↑"],["ORDER_desc","↓"],["ac1","AC"],["pp1","PY"],["fc1","FC"],["pl1","PL"],["ac2","AC2"],["pp2","PY2"],["fc2","FC2"],["pl2","PL2"],["ac3","AC3"],["pp3","PY3"],["fc3","FC3"],["pl3","PL3"],["ac4","AC4"],["pp4","PY4"],["fc4","FC4"],["pl4","PL4"],["category"," "],["operation"," "],["thereof","davon"],["part_of","in % von"],["ibcssymbol_delta_ac","Δ{%}"],["ibcssymbol_delta_generic","Δ({%})"],["ibcssymbol_delta_ac_relative","Δ{%}%"],["ibcssymbol_delta_generic_relative","Δ({%})%"],["SUM_TOTAL","❖"]]);return this.state=j.DIRTY,new Map([...e,...t||new Map])}initConfig(t){this.state=j.DIRTY;const e=t,o=this;return t.scenarios.sort(((t,e)=>o.ruleSet.getScenarioSorIndex(t)-o.ruleSet.getScenarioSorIndex(e))),e}setConfig(t){this.config=this.initConfig(t)}setSource(t,e){var o,i;if(this.state=j.DIRTY,this.fromExpr=C(this.db,t,e),!this.fromExpr)return void(this.rowCount=0);const n=this.db.exec(`SELECT COUNT(*) AS cnt FROM ${this.fromExpr}`);this.rowCount=null!==(i=null===(o=n[0])||void 0===o?void 0:o.cnt)&&void 0!==i?i:0}update(){this.prepareIntervalBuckets();const t=this.normalizeScenarios(this.config.scenarios,this.config.categoryThereOf,this.config.sortOrder,this.intervalBuckets);this.headerRows=this.dataSetFactory.createHeader(this.config.type,t,this.i18n,this.config.measureScale,this.config.measureUnit,this.config.showMeasureScale,this.config.attributes),this.bodyRows=0!==this.rowCount&&this.fromExpr?this.dataSetFactory.createBodyRows(this.config,this.i18n,this.db,this.fromExpr):[],this.state=j.UP_TO_DATE}getHeader(){return this.state===j.DIRTY&&this.update(),this.headerRows}getBody(){return this.state===j.DIRTY&&this.update(),this.bodyRows}getColumns(){return this.state===j.DIRTY&&this.update(),this.dataSetFactory.getNormalizedHeader()}prepareIntervalBuckets(){this.intervalBuckets=[],this.config.interval===V||!this.fromExpr||this.config.categoryThereOf.size>0?this.config.interval=V:(this.config.interval=function(t,e,o){var i;if(o!==G.AUTO)return o;const n=t.exec(`SELECT [date] as d FROM ${e}`);let s,r;for(const t of n){const e=null===(i=Z(t.d))||void 0===i?void 0:i.toMillis();void 0!==e&&(s=void 0===s?e:Math.min(s,e),r=void 0===r?e:Math.max(r,e))}return void 0===s||void 0===r?G.DAY:(new T).calculateDistanceType(N.fromMillis(s),N.fromMillis(r))}(this.db,this.fromExpr,this.config.interval),this.intervalBuckets=function(t,e,o,i){const n=t.exec(`SELECT ${q(o)} as __interval FROM ${e}`);if(o===X){const t=new Set,e=[];for(const o of n){const i=K(o.__interval);t.has(i)||(t.add(i),e.push({key:i,label:0===i.length?"-":i}))}return e}const s=new Set,r=[];for(const t of n){const e=Z(t.__interval);if(!e)continue;const o=e.toISO();s.has(o)||(s.add(o),r.push(e))}r.sort(((t,e)=>t.toMillis()-e.toMillis()));const l=new T;return l.setLocale(i),r.map((t=>({key:t.toISO(),label:l.getDateString(t,o)})))}(this.db,this.fromExpr,this.config.interval,this.config.locale),0===this.intervalBuckets.length&&(this.config.interval=V))}normalizeScenarios(t,e,o,i=[]){var n;const s=[],r=null===(n=null==o?void 0:o.hierarchy)||void 0===n?void 0:n.map((t=>L(t))).find((t=>"dim"!==(null==t?void 0:t.kind))),l=this.config.interval===X?null==r?void 0:r.bucket:void 0,a=(t,e)=>{var i;return null==r||(null===(i=L(t))||void 0===i?void 0:i.column)!==r.column||void 0!==l&&l!==e?void 0:o.direction};if(i.length>0){for(const e of i)for(const o of t)s.push({name:o,group:o,type:o,order:a(o,e.key),bucket:e.key,bucketLabel:e.label});return s}for(const o of t){if(null==e?void 0:e.has(o)){const t=e.get(o);for(const e of t){s.push({name:e.name,group:e.name,type:o,order:void 0});for(const t of e.subGroups)s.push({name:t,group:e.name,type:o,order:void 0})}s.push({name:"REST",group:"REST",type:o,order:void 0})}s.push({name:o,group:o,type:o,order:a(o)})}return s}hasNoData(){return 0===this.rowCount}orderBucketWarning(){var t,e;if(this.hasNoData()||this.state!==j.UP_TO_DATE)return;const o=(null!==(e=null===(t=this.config.sortOrder)||void 0===t?void 0:t.hierarchy)&&void 0!==e?e:[]).map((t=>{var e;return null===(e=L(t))||void 0===e?void 0:e.bucket})).filter((t=>void 0!==t));if(0===o.length)return;if(this.config.interval!==X)return`order: '@${o[0]}' needs interval setname, the bucket is ignored.`;const i=o.find((t=>!this.intervalBuckets.some((e=>e.key===t))));return void 0===i?void 0:`order: setname '${i}' not found, the rows are not sorted by it.`}hasBlankRowGroup(){return this.dataSetFactory.hasBlankRowGroup}}class Dt{constructor(){this.title="",this.scenarios=[],this.scenariosUnitType=E.DECIMAL,this.grouped=!1,this.showGroupTitle=!0,this.thereOf=[],this.categoryThereOf=new Map,this.partOf=[],this.attributes=[],this.sortOrder=new x(new B).default(),this.type=I.LIST,this.limit=0,this.i18n=w.ALL,this.categoryWidth=R.W25,this.measureScale=new F,this.measureUnit="",this.measureType=y.VOLUME,this.showMeasureScale=!0,this.filter="",this.barColumns=[],this.interval="none",this.locale="de"}}class Wt{constructor(t,e,o,i,n,s){this.tableDrillGroupAdapter=t,this.stringAdapter=e,this.orderAdapter=o,this.db=i,this.fromExpr=n,this.onQueryError=s}adapt(t){const e=new Dt;return S.isString(t.title)&&(e.title=t.title),S.isArray(t.scenarios)&&(e.scenarios=W.adaptArray(t.scenarios,this.stringAdapter)),S.isExisting(t.scenariosUnitType)&&(e.scenariosUnitType=t.scenariosUnitType),S.isBoolean(t.grouped)&&(e.grouped=t.grouped),S.isBoolean(t.showGroupTitle)&&(e.showGroupTitle=t.showGroupTitle),S.isBoolean(t.showMeasureScale)&&(e.showMeasureScale=t.showMeasureScale),S.isArray(t.thereOf)&&(e.thereOf=W.adaptArray(t.thereOf,this.tableDrillGroupAdapter)),S.isExisting(t.categoryThereOf)&&(e.categoryThereOf=t.categoryThereOf),S.isArray(t.partOf)&&(e.partOf=W.adaptArray(t.partOf,this.tableDrillGroupAdapter)),S.isArray(t.attributes)&&(e.attributes=t.attributes),S.isExisting(t.order)&&(e.sortOrder=this.orderAdapter.adapt(t.order)),S.isExisting(t.type)&&(e.type=t.type),S.isNumber(t.limit)&&(e.limit=t.limit),S.isExisting(t.i18n)&&(e.i18n=t.i18n),S.isExisting(t.categoryWidth)&&(e.categoryWidth=t.categoryWidth),S.isExisting(t.measureScale)&&(e.measureScale=A.calculateMeasureScale(this.db,this.fromExpr,e.scenarios,t.measureScale,this.onQueryError)),S.isExisting(t.measureType)&&(e.measureType=t.measureType),S.isString(t.measureUnit)&&(e.measureUnit=t.measureUnit),S.isString(t.filter)&&(e.filter=t.filter.trim()),S.isArray(t.barColumns)&&(e.barColumns=t.barColumns),S.isString(t.interval)&&(e.interval=t.interval),S.isString(t.locale)&&(e.locale=t.locale),e}default(){return new Dt}}class Bt{constructor(){this.rowGroup="",this.category="",this.subCategory="",this.partOf=""}}class Ft{constructor(){}adapt(t){const e=new Bt;return S.isString(t.rowGroup)&&(e.rowGroup=t.rowGroup),S.isString(t.category)&&(e.category=t.category),S.isString(t.subCategory)&&(e.subCategory=t.subCategory),S.isString(t.partOf)&&(e.partOf=t.partOf),e}default(){return new Bt}}const Yt=e(class extends o{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.tableName="",this.dataVersion=0,this.sumTitle="SUM_TOTAL",this.scenarios=[],this.scenariosDataFormat=E.DECIMAL,this.grouped=!1,this.limit=0,this.showGroupTitle=!0,this.thereof=[],this.partof=[],this.order={hierarchy:[],direction:z.ASC},this.categorythereof=new Map,this.attributeColumns=[],this.type=I.LIST,this.categoryWidth=R.INF,this.dataFormatDigits={percent:2,decimal:1},this.i18n=new Map,this.i18nMode=w.ALL,this.measureScale="_",this.measureUnit="",this.showMeasureScale=!0,this.measureType=y.VOLUME,this.filter="",this.barColumns=[],this.interval="none",this.barColumnMaxWidth=30,this.unitScaling=.01,this.percentageScaling=.5,this.scaleFactor=1,this.componentDataFormatDigits=new P,this.barColumnLayouts=new Map,U(this),this.componentStyle=Y(this)}async getLayoutDetail(t,e){var o,i,n;const a={regions:[],metadata:{},diagnostics:[]},h=null===(o=this.element.shadowRoot)||void 0===o?void 0:o.querySelector("table");if(a.metadata.hasNoData=null===(n=null===(i=this.table)||void 0===i?void 0:i.hasNoData())||void 0===n||n,!this.table||!h)return a;const u=h.querySelector("thead"),d=h.querySelector("tbody");u&&a.regions.push({id:"header",rect:s(u,t)}),d&&a.regions.push({id:"body",rect:s(d,t)});const f=this.table.getHeader(),p=this.table.getBody(),$=this.table.getColumns();if(a.metadata.headerRowCount=f.length,a.metadata.rowCount=p.length,a.metadata.columnCount=$.length,a.metadata.cellCount=p.reduce(((t,e)=>t+e.getCells().length),0),"full"!==e)return a;const v=[],m=[],g=(e,o,i)=>{const n=i?Array.from(i.children).filter((t=>"tr"===t.localName)):[];o.forEach(((o,i)=>{const h=n[i];if(!h)return;v.push({section:e,index:i,type:o.type,rect:s(h,t),point:c(h)});const u=o.getCells(),d=Array.from(h.children);u.length===d.length?u.forEach(((o,n)=>{var a,h;const u=d[n],f={kind:"header"===e?"headerCell":"cell",row:i,column:o.index,key:o.key||void 0,colSpan:o.colSpan,value:null!==(a=o.value)&&void 0!==a?a:void 0,text:(null===(h=u.textContent)||void 0===h?void 0:h.trim())||void 0,type:o.type||void 0,rect:s(u,t),point:c(u)};f.point&&(f.content=r(u,t),f.contentSign=l(u)||void 0);const p=u.querySelector("svg.cell-bar-chart");p&&(f.bar={variant:p.classList.contains("waterfall-bar")?"waterfall":p.classList.contains("relative-variance")?"relative":"absolute",rect:s(p,t)}),m.push(f)})):a.diagnostics.push({id:`WARN_layout_cell_pairing_${e}_${i}`,type:"warning",message:`layout-state: model/DOM cell count mismatch in ${e} row ${i} (${u.length} vs ${d.length}); cell details skipped for this row.`})}))};return g("header",f,u),g("body",p,d),a.elements=m,a.table={rows:v,columns:$.map(((t,e)=>({index:e,key:t.name,group:t.group,type:t.type,bucket:t.bucket})))},a}render(){var e;return t(i,{class:{"no-data":!0===(null===(e=this.table)||void 0===e?void 0:e.hasNoData())}},(()=>{var e,o,i,n;if(void 0===this.table)return;if(this.table.hasNoData()){const o=null!==(e=this.i18n.get("no-data"))&&void 0!==e?e:"No Data";return t("div",{class:"empty-state"},o)}const s=null===(n=null===(i=null===(o=this.stores)||void 0===o?void 0:o.context)||void 0===i?void 0:i.state)||void 0===n?void 0:n.locale;return t("table",null,t("thead",null,this.table.getHeader().map((e=>t("tr",{class:e.cssStyle},e.getCells().map((e=>t("th",{colSpan:e.colSpan,class:e.cssStyle},e.getAsHeaderList().map(((o,i,n)=>t("span",null,i===n.length-1?t("span",{class:" "===o?"table-footer":""},o,e.drawPrefix()," "):t("span",null,o,e.drawPrefix(),t("br",null)))))))))))),t("tbody",null,this.table.getBody().map((e=>t("tr",Object.assign({class:e.cssStyle},u(e.key,"element")),null==e?void 0:e.getCells().map((o=>{var i,n,r,l;return t("td",Object.assign({colSpan:o.colSpan,class:o.type?`${o.cssStyle} ${o.type}`:o.cssStyle},e.key&&null!=o.value&&""!==o.value&&"-"!==o.value?u(Object.assign(Object.assign({},e.key),{date:o.date,scenario:o.key}),"element"):{}),null!=o.prefix?t("span",{class:o.cssStyle+" "+o.prefixStyle},o.drawPrefix()):"",o.isBarChart&&o.columnStats&&o.value!==O&&(void 0!==o.waterfall||e.type!==Q.SUM)?void 0!==o.waterfall?t(Tt,{value:o.value,scenario:o.key,columnStats:o.columnStats,height:18*this.scaleFactor,isRelative:!1,isPositiveGood:"pos"===o.direction,measureScale:o.measureScale,locale:s,columnWidthEm:this.barColumnMaxWidth,styles:this.barChartStyles,waterfall:o.waterfall}):t(Gt,{value:o.value,scenario:o.key,columnStats:o.columnStats,height:18*this.scaleFactor,isRelative:o.key.startsWith("dr"),isPositiveGood:"pos"===o.direction,measureScale:Ht(o),locale:s,percentDigits:null!==(n=null===(i=this.barColumnLayouts.get(o.key))||void 0===i?void 0:i.percentDigits)&&void 0!==n?n:this.componentDataFormatDigits.percent,percentSign:null===(r=this.barColumnLayouts.get(o.key))||void 0===r?void 0:r.percentSign,columnWidthEm:this.barColumnMaxWidth,labelWidths:null===(l=this.barColumnLayouts.get(o.key))||void 0===l?void 0:l.labels,styles:this.barChartStyles}):o.draw(this.componentDataFormatDigits,s))})))))))})())}componentWillRender(){var t,e,o,i,n,s,r,l;this.stores||(this.stores=k(this.element));const a=this.stores.db.db;this.componentDataFormatDigits=(new D).adapt(this.dataFormatDigits);try{const e=this.prepareConfig(a);this.table=new Pt(new m(this.ruleSetConfig),a,this.tableName,e),this.table.setI18n(this.i18n),this.table.hasNoData()||this.table.getBody(),null===(t=this.errors)||void 0===t||t.remove("ERR_sql")}catch(t){console.error("bn-table-renderer: query failed",t),this.table=void 0,null===(e=this.errors)||void 0===e||e.addOrReplace({id:"ERR_sql",type:"error",message:`Query failed: ${t instanceof Error?t.message:t}`})}(null===(o=this.table)||void 0===o?void 0:o.hasBlankRowGroup())?null===(i=this.errors)||void 0===i||i.addOrReplace({id:"WARN_blankRowGroup",type:"warning",message:"grouped: rows with blank rowGroup found, they are grouped under '-'."}):null===(n=this.errors)||void 0===n||n.remove("WARN_blankRowGroup");const h=null===(s=this.table)||void 0===s?void 0:s.orderBucketWarning();h?null===(r=this.errors)||void 0===r||r.addOrReplace({id:"WARN_orderBucket",type:"warning",message:h}):null===(l=this.errors)||void 0===l||l.remove("WARN_orderBucket"),this.barColumnLayouts=this.collectBarColumnLayouts(),this.barChartStyles=this.prepareBarChartStyles()}prepareConfig(t){var e,o,i;const n=C(t,this.tableName,this.filter);return new Wt(new Ft,new B,new x(new B,!0),t,n,(t=>{throw t})).adapt({title:this.sumTitle,scenarios:this.scenarios,scenariosUnitType:this.scenariosDataFormat,grouped:this.grouped,showGroupTitle:this.showGroupTitle,thereOf:this.thereof,partOf:this.partof,categoryThereOf:this.categorythereof,attributes:this.attributeColumns,order:this.order,type:this.type,limit:this.limit,i18n:this.i18nMode,categoryWidth:this.categoryWidth,measureScale:this.measureScale,measureUnit:this.measureUnit,measureType:this.measureType,showMeasureScale:this.showMeasureScale,filter:this.filter,barColumns:this.barColumns,interval:this.interval,locale:(null===(i=null===(o=null===(e=this.stores)||void 0===e?void 0:e.context)||void 0===o?void 0:o.state)||void 0===i?void 0:i.locale)||"de"})}prepareBarChartStyles(){var t;const e=!(this.unitScaling>0),o=!(this.percentageScaling>0),i=e?this.autoUnitScaling():this.unitScaling,n=o?this.autoPercentageScaling():this.percentageScaling;return(e||o)&&(null===(t=this.reportAutoScaling)||void 0===t||t.call(this,{unit:e?i:void 0,percentage:o?n:void 0})),this.componentStyle((t=>{var e,o,s,r,l,a,c,u,d,f,p,$,v,b,w,E,S,R,y,O,M,N,U,G,T,_,L;const x=null===(e=t["bn-chart-time"])||void 0===e?void 0:e.varianceStyles,C=null===(o=t["bn-chart-time"])||void 0===o?void 0:o.barStyles;return{positive:{stroke:(null===(s=null==x?void 0:x.pos)||void 0===s?void 0:s.stroke)||"#008f96",fill:(null===(r=null==x?void 0:x.pos)||void 0===r?void 0:r.fill)||"#008f96",fillpattern:h(null===(l=null==x?void 0:x.pos)||void 0===l?void 0:l.fillpattern)||"solid"},negative:{stroke:(null===(a=null==x?void 0:x.neg)||void 0===a?void 0:a.stroke)||"#ff0000",fill:(null===(c=null==x?void 0:x.neg)||void 0===c?void 0:c.fill)||"#ff0000",fillpattern:h(null===(u=null==x?void 0:x.neg)||void 0===u?void 0:u.fillpattern)||"solid"},neutral:{stroke:(null===(d=null==x?void 0:x.neu)||void 0===d?void 0:d.stroke)||"#808080",fill:(null===(f=null==x?void 0:x.neu)||void 0===f?void 0:f.fill)||"#808080",fillpattern:h(null===(p=null==x?void 0:x.neu)||void 0===p?void 0:p.fillpattern)||"outlined"},scenarios:g({ac:{stroke:(null===($=null==C?void 0:C.ac)||void 0===$?void 0:$.stroke)||"#404040",fill:(null===(v=null==C?void 0:C.ac)||void 0===v?void 0:v.fill)||"#404040",fillpattern:h(null===(b=null==C?void 0:C.ac)||void 0===b?void 0:b.fillpattern)||"solid"},pp:{stroke:(null===(w=null==C?void 0:C.pp)||void 0===w?void 0:w.stroke)||"#A6A6A6",fill:(null===(E=null==C?void 0:C.pp)||void 0===E?void 0:E.fill)||"#A6A6A6",fillpattern:h(null===(S=null==C?void 0:C.pp)||void 0===S?void 0:S.fillpattern)||"solid"},fc:{stroke:(null===(R=null==C?void 0:C.fc)||void 0===R?void 0:R.stroke)||"#404040",fill:(null===(y=null==C?void 0:C.fc)||void 0===y?void 0:y.fill)||"#ffffff",fillpattern:h(null===(O=null==C?void 0:C.fc)||void 0===O?void 0:O.fillpattern)||"hatched"},pl:{stroke:(null===(M=null==C?void 0:C.pl)||void 0===M?void 0:M.stroke)||"#404040",fill:(null===(N=null==C?void 0:C.pl)||void 0===N?void 0:N.fill)||"#ffffff",fillpattern:h(null===(U=null==C?void 0:C.pl)||void 0===U?void 0:U.fillpattern)||"outlined"}},new m(this.ruleSetConfig)),fontColor:(null===(G=t.global)||void 0===G?void 0:G.fontColor)||"#000000",fontSize:((null===(T=t.global)||void 0===T?void 0:T.fontSizePx)||13.3333)*ot*this.scaleFactor,emPx:((null===(_=t.global)||void 0===_?void 0:_.fontSizePx)||13.3333)*this.scaleFactor,fontFamily:(null===(L=t.global)||void 0===L?void 0:L.fontFamily)||"'Noto Sans', sans-serif",unitScaling:i,percentageScaling:n,scaleFactor:this.scaleFactor}}))}emPx(){return this.componentStyle((t=>{var e;return(null===(e=t.global)||void 0===e?void 0:e.fontSizePx)||13.3333}))*this.scaleFactor}autoUnitScaling(){const t=this.emPx(),e=t*ot;let o=1/0;for(const{isRelative:i,absMax:n,labels:s}of this.barColumnLayouts.values()){if(i||n<=0)continue;const{maxBarWidth:r,cutWidth:l}=ut(this.barColumnMaxWidth,t,s);o=Math.min(o,Math.min(.8*r,l)/(n*e))}return Number.isFinite(o)&&e>0?o:.01}autoPercentageScaling(){const t=this.emPx(),e=t*ot;let o=1/0;for(const{isRelative:i,absMax:n,labels:s}of this.barColumnLayouts.values()){if(!i||n<=0)continue;const r=10*this.scaleFactor,{maxPinLength:l}=dt(this.barColumnMaxWidth,t,s,r);o=Math.min(o,l/(n*e))}return Number.isFinite(o)&&e>0?o:.5}collectBarColumnLayouts(){var t,e,o,i;const n=new Map;if(!this.table||this.table.hasNoData())return n;const s=new Map;for(const e of this.table.getBody())if(e.type!==Q.SUM)for(const o of e.getCells())o.isBarChart&&o.columnStats&&void 0===o.waterfall&&("number"!=typeof o.value||isNaN(o.value)||s.set(o.key,[...null!==(t=s.get(o.key))&&void 0!==t?t:[],o]));const r=this.emPx(),l=r*ot,a=10*this.scaleFactor,h=null===(i=null===(o=null===(e=this.stores)||void 0===e?void 0:e.context)||void 0===o?void 0:o.state)||void 0===i?void 0:i.locale;for(const[t,e]of s){const o=t.startsWith("dr"),i=e.map((t=>t.value)),s=(t,n)=>{var s;const r={neg:i.some((t=>t<0))?0:void 0,pos:i.some((t=>t>0))?0:void 0},a=St(r);for(const i of e){const e=i.value,c=e>0||0===e&&a?"pos":"neg",u=mt(e,o,Ht(i),h,t,n);r[c]=Math.max(null!==(s=r[c])&&void 0!==s?s:0,rt(u,l))}return r};let c=Math.min(20,Math.max(0,Math.trunc(this.componentDataFormatDigits.percent)||0)),u=!0,d=s(c,u);for(;o&&(c>0||u)&&!ct(this.barColumnMaxWidth,r,d,a);)c>0?c--:u=!1,d=s(c,u);const f=Math.max(...i.map(Math.abs))*(o?100:1);n.set(t,{isRelative:o,absMax:f,labels:d,percentDigits:c,percentSign:u})}return n}get element(){return this}static get style(){return':host(.no-data){display:block;box-sizing:border-box;width:100%;height:100%}:host(.no-data)>div{float:none;width:100%;height:100%}:host(.no-data) .no-data~.no-data{display:none}.empty-state{box-sizing:border-box;display:flex;align-items:center;justify-content:center;float:none;width:100%;height:100%;min-height:3em;margin:0;padding:0.5em;overflow:hidden;border:0.1em dashed #ddd;color:#808080;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);font-style:normal;text-align:center}:host{position:relative;display:inline-block}table{background-color:var(--bn-font-background, white);font-size:var(--bn-font-size, 1em);color:var(--bn-font-color, black);font-family:var(--bn-font-family, "Noto Sans", "Helvetica Neue", Helvetica, sans-serif);border-spacing:0.3em 0}thead{border-style:none}tr:first-child td{border-top:none;padding-top:0.5em}td.ac1,td.ac2,td.ac3,td.ac4,td.pp1,td.pp2,td.pp3,td.pp4,td.pl1,td.pl2,td.pl3,td.pl4,td.fc1,td.fc2,td.fc3,td.fc4,td.share,td.variance,td.pos_pos,td.pos_neg,td.neg_pos,td.neg_neg,td.pos_neutral,td.neg_neutral{text-align:right}.category-w100{min-width:100em;max-width:100em}.category-w50{min-width:50em;max-width:50em}.category-w25{min-width:25em;max-width:25em}.category-w20{min-width:20em;max-width:20em}.category-w15{min-width:15em;max-width:15em}.category-w10{min-width:10em;max-width:10em}.category-w5{min-width:5em;max-width:5em}.prefix-second{color:transparent;font-style:normal}.prefix-first{font-style:normal}th{border-bottom:0.1em solid black;text-align:right;font-weight:normal;vertical-align:text-top}td.columnGroup,th.columnGroup{font-size:0.6em}td.columnSubGroup,th.columnSubGroup{font-size:0.6em;border-spacing:0em 0;font-style:italic}td.base,th.base{font-style:normal}th.ofit,td.ofit,tr.ofit,th.partof,td.partof,tr.partof{font-size:0.6em;font-style:italic}td.ofit,td.partof{font-size:0.6em;font-style:italic}th.ofit td,tr.ofit td,th.partof td,tr.partof td{border-top:0em solid black;padding-left:1em}th.ofit share,th.partof share,tr.share td{border-top:0em solid black}th.share,tr.share,td.share{font-size:0.6em;font-style:italic}th.filler{border-bottom:0em solid black;text-align:right}td.filler{border-top:0em none !important;border-bottom:0em none;text-align:right}th.group{text-align:center;border-spacing:1em 0}th.headerlabel{border-bottom:0em none black;padding-bottom:0em}th.intervalGroup{border-bottom:0.1em solid black;text-align:center;font-weight:bold}td.variance:after{content:"%"}td.relative_variance{font-style:italic}td.percent{font-style:italic;text-align:right}td.decimal,td.percentpoint{text-align:right}td.pos_pos{color:#008f96}td.neg_pos{color:#ff0000}td.pos_neg{color:#ff0000}td.neg_neg{color:#008f96}td.pos_pos:before{content:"+"}td.pos_neg:before{content:"+"}td.pos_neu:before{content:"+"}th.ac1,th.ac2,th.ac3,th.ac4{padding-top:0em;border-bottom:0.3em solid black}th.pp1,th.pp2,th.pp3,th.pp4{padding-top:0em;border-bottom:0.3em solid grey}th.pl1,th.pl2,th.pl3,th.pl4{padding-top:0em;border-bottom:0.3em double black}th.fc1,th.fc2,th.fc3,th.fc4{border-bottom:0.3em solid;border-image:repeating-linear-gradient(-45deg, white, white, black, white, white 0.3em) 2}td.colsum{font-weight:bold}th.colsum{padding-top:0em;font-weight:bold}tr.sum td{border-top:0.1em solid black;font-weight:bold;padding-bottom:0.5em}tr.groupheader td{border-top:0em dotted #ddd;padding-top:0.5em;font-weight:bold;font-style:italic}tr.begingroup td{border-top:0em dotted #ddd;padding-top:0.5em}th.begin-group{padding-left:0.75em}th.end-group{padding-left:0.75em}td{box-sizing:border-box;-webkit-box-sizing:border-box;border-top:0.1em dashed #ddd;padding-left:0.5em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.table-footer{font-size:0.6em}.cell-bar-chart{display:inline-block;vertical-align:middle}.bar-chart-empty{color:#999}td:has(.cell-bar-chart){padding:0 0.25em;vertical-align:middle}td:has(.cell-bar-chart).pos_pos:before,td:has(.cell-bar-chart).pos_neg:before,td:has(.cell-bar-chart).pos_neu:before{content:none}td:has(.cell-bar-chart).variance:after{content:none}'}},[1,"bn-table-renderer",{tableName:[1,"table-name"],dataVersion:[2,"data-version"],selectedStyle:[513,"selected-style"],sumTitle:[1,"sum-title"],scenarios:[16],scenariosDataFormat:[1,"scenarios-data-format"],grouped:[4],limit:[2],showGroupTitle:[4,"show-group-title"],thereof:[16],partof:[16],order:[16],categorythereof:[16],attributeColumns:[16],type:[1],categoryWidth:[1,"category-width"],dataFormatDigits:[16],ruleSetConfig:[16],i18n:[1040],i18nMode:[1,"i18n-mode"],measureScale:[1,"measure-scale"],measureUnit:[1,"measure-unit"],showMeasureScale:[4,"show-measure-scale"],measureType:[1,"measure-type"],filter:[1],barColumns:[16],interval:[1],barColumnMaxWidth:[2,"bar-column-max-width"],unitScaling:[2,"unit-scaling"],percentageScaling:[2,"percentage-scaling"],reportAutoScaling:[16],errors:[16],scaleFactor:[2,"scale-factor"],getLayoutDetail:[64]}]);function Ht(t){return"percentpoint"===t.type?.01:t.measureScale}function jt(){"undefined"!=typeof customElements&&["bn-table-renderer"].forEach((t=>{"bn-table-renderer"===t&&(customElements.get(n(t))||customElements.define(n(t),Yt))}))}export{Yt as B,V as I,I as T,X as a,jt as d}