apexsankey 1.7.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -77,7 +77,7 @@ The layout can be configured by passing a second argument to `ApexSankey` with t
77
77
  | `onNodeClick` | `(node: SankeyNode) => void` | `undefined` | Callback fired when the user clicks a node. |
78
78
  | `edgeOpacity` | `number` | `0.4` | Opacity of edges (0–1). |
79
79
  | `edgeGradientFill` | `boolean` | `true` | Fill edges with a gradient between source and target node colors. |
80
- | `edgeGap` | `number` | `2` | Gap in pixels between adjacent edges at node connection points. |
80
+ | `edgeGap` | `number` | `0` | Gap in pixels between adjacent edges at node connection points. |
81
81
  | `whitespace` | `number` | `0.18` | Fraction of vertical space used as margins between nodes (0–1). Lower = taller nodes. |
82
82
  | `viewPortWidth` | `number` | `800` | Internal SVG viewport width in pixels. |
83
83
  | `viewPortHeight` | `number` | `500` | Internal SVG viewport height in pixels. |
@@ -98,6 +98,27 @@ The layout can be configured by passing a second argument to `ApexSankey` with t
98
98
  | `fontSize` | `string` | `'14px'` | CSS font-size for node labels. |
99
99
  | `fontWeight` | `string` | `'400'` | CSS font-weight for node labels. |
100
100
  | `a11y` | `{ enabled?: boolean, diagramLabel?: string, description?: string }` | `{ enabled: true }` | WCAG 2.1 AA accessibility options. |
101
+ | `locale` | `{ direction?: 'ltr' \| 'rtl' \| 'auto', messages?: Partial<SankeyMessages> }` | `{ direction: 'ltr' }` | Localization and text-direction. `direction: 'rtl'` mirrors the diagram horizontally (flows read right-to-left) and sets `dir="rtl"` on the container (`'auto'` defers to the document). `messages` overrides the screen-reader strings the diagram generates. |
102
+
103
+ ### Localization & RTL
104
+
105
+ The diagram's screen-reader strings live in `SankeyMessages`; pass a `Partial<SankeyMessages>` via `locale.messages` to translate any subset (unset keys keep their English defaults, exported as `DEFAULT_SANKEY_MESSAGES`). Visible tooltips are localized separately via `tooltipTemplate` / `nodeTooltipTemplate`.
106
+
107
+ | `SankeyMessages` key | Type | Description |
108
+ | --- | --- | --- |
109
+ | `diagramLabel` | `(ctx: SankeyDiagramLabelContext) => string` | SVG root aria-label summary (node/flow counts + largest flow). |
110
+ | `nodeAriaLabel` | `(ctx: SankeyNodeLabelContext) => string` | Per-node aria-label (incoming/outgoing flow summary). |
111
+ | `edgeAriaLabel` | `(ctx: SankeyEdgeLabelContext) => string` | Per-edge aria-label. Default: `Flow from {source} to {target}: {value} units`. |
112
+ | `nodesGroupLabel` | `string` | aria-label for the `<g>` wrapping all nodes. Default: `'Sankey nodes'`. |
113
+
114
+ ```ts
115
+ const sankey = new ApexSankey(el, {
116
+ locale: {
117
+ direction: 'rtl',
118
+ messages: {nodesGroupLabel: 'العقد'},
119
+ },
120
+ });
121
+ ```
101
122
 
102
123
  Default tooltip template
103
124
 
@@ -157,8 +178,6 @@ Passed data should be an object containing nodes, edges and options. Nodes, edge
157
178
  },
158
179
  ```
159
180
 
160
- - _alignLinkTypes_: boolean (default false). Whether to align link types across nodes, or order links to minimise crossings.
161
-
162
181
  **Example**
163
182
 
164
183
  ```js
package/apexsankey.d.ts CHANGED
@@ -23,6 +23,8 @@ declare class WrappedEl {}
23
23
 
24
24
 
25
25
 
26
+ declare type TextDirection = 'ltr' | 'rtl' | 'auto';
27
+
26
28
 
27
29
 
28
30
  /** Options for WCAG 2.1 AA accessibility support */
@@ -48,7 +50,7 @@ export declare interface AnimationOptions {
48
50
  }
49
51
 
50
52
  declare class ApexSankey extends BaseChart {
51
- graph: SankeyGraph;
53
+ graph: SankeyGraphRenderer;
52
54
  options: SankeyOptions;
53
55
  /**
54
56
  * Create a new ApexSankey instance.
@@ -98,7 +100,7 @@ declare class ApexSankey extends BaseChart {
98
100
  * - `edges` — array of `{ source, target, value, type }` objects representing
99
101
  * flow connections between nodes. `value` determines link width.
100
102
  * - `options` — the full resolved `SankeyOptions` for this render.
101
- * @returns The internal `SankeyGraph` instance, which exposes `exportToSvg()`
103
+ * @returns The internal `SankeyGraphRenderer` instance, which exposes `exportToSvg()`
102
104
  * for programmatic SVG export after render.
103
105
  *
104
106
  * @throws {Error} If the container element is not found.
@@ -117,7 +119,7 @@ declare class ApexSankey extends BaseChart {
117
119
  * });
118
120
  * ```
119
121
  */
120
- render(data: GraphData): SankeyGraph;
122
+ render(data: GraphData): SankeyGraphRenderer;
121
123
  }
122
124
  export { ApexSankey }
123
125
  export default ApexSankey;
@@ -136,6 +138,8 @@ export declare interface CommonOptions {
136
138
  readonly enableToolbar: boolean;
137
139
  /** Height of the canvas. Use `'auto'` to derive height from width at a 1.6:1 ratio. @default 'auto' */
138
140
  readonly height: number | string;
141
+ /** Localization and text-direction (RTL) options. See {@link LocaleOptions}. @default { direction: 'ltr' } */
142
+ readonly locale?: LocaleOptions;
139
143
  /** Horizontal spacing between node columns in pixels. @default 20 */
140
144
  readonly spacing: number;
141
145
  /** Internal SVG viewport height in pixels. @default 500 */
@@ -146,6 +150,12 @@ export declare interface CommonOptions {
146
150
  readonly width: number | string;
147
151
  }
148
152
 
153
+ /**
154
+ * English defaults for every {@link SankeyMessages} string. These reproduce the
155
+ * exact screen-reader text the diagram generated before localization support.
156
+ */
157
+ export declare const DEFAULT_SANKEY_MESSAGES: SankeyMessages;
158
+
149
159
  /** Label attached to a graph edge during the layout pipeline */
150
160
  declare interface EdgeLabel {
151
161
  value?: number;
@@ -179,7 +189,7 @@ declare interface EdgeLabel {
179
189
  * at each node connection point.
180
190
  */
181
191
  export declare interface EdgeOptions {
182
- /** Gap in pixels between adjacent edges at their node connection points. @default 2 */
192
+ /** Gap in pixels between adjacent edges at their node connection points. @default 0 */
183
193
  readonly edgeGap: number;
184
194
  /** When true, edges are filled with a gradient between source and target node colors. @default true */
185
195
  readonly edgeGradientFill: boolean;
@@ -271,6 +281,24 @@ export declare interface LayoutOptions {
271
281
  readonly whitespace: number;
272
282
  }
273
283
 
284
+ /**
285
+ * Localization and text-direction options.
286
+ *
287
+ * With the defaults (`direction: 'ltr'`, no message overrides) the output is
288
+ * byte-for-byte identical to builds that predate i18n support.
289
+ */
290
+ export declare interface LocaleOptions {
291
+ /**
292
+ * Text and layout direction. `'rtl'` mirrors the diagram horizontally (flows
293
+ * read right-to-left) and sets `dir="rtl"` on the container; `'auto'` defers
294
+ * to the document/element direction.
295
+ * @default 'ltr'
296
+ */
297
+ readonly direction?: TextDirection;
298
+ /** Overrides for screen-reader strings. See {@link SankeyMessages}. */
299
+ readonly messages?: Partial<SankeyMessages>;
300
+ }
301
+
274
302
  /** Shape of node user data attached to a graph node */
275
303
  export declare interface NodeData {
276
304
  id?: string;
@@ -342,27 +370,32 @@ declare class Paper {
342
370
  get width(): number;
343
371
  }
344
372
 
345
- declare class SankeyGraph extends Paper {
346
- graph: SankeyGraph_2;
347
- maxRank: number;
348
- /** Options resolved with CSS custom property overrides for the current render pass. */
349
- private renderOptions;
350
- /** Accessibility helper — re-created on each render pass. */
351
- private a11yHelper;
352
- /** Path highlighter — re-created on each render pass when feature is enabled. */
353
- private pathHighlighter;
354
- /** Guard: entrance animation plays only on the first render. */
355
- private _hasAnimated;
356
- constructor(element: HTMLElement, options: SankeyOptions, chartContext: ChartContext);
357
- construct(data: GraphData): void;
358
- render({ keepOldPosition }?: {
359
- keepOldPosition?: boolean | undefined;
360
- }): void;
361
- renderEdge(edgeObj: GraphEdge, group: G): void;
373
+ /** Context passed to {@link SankeyMessages.diagramLabel}. */
374
+ export declare interface SankeyDiagramLabelContext {
375
+ /** Number of (non-dummy) nodes in the diagram. */
376
+ readonly nodeCount: number;
377
+ /** Number of flows (edges). */
378
+ readonly flowCount: number;
379
+ /** The single largest flow, omitted when no value-bearing flow exists. */
380
+ readonly largestFlow?: {
381
+ readonly source: string;
382
+ readonly target: string;
383
+ readonly value: number;
384
+ };
385
+ }
386
+
387
+ /** Context passed to {@link SankeyMessages.edgeAriaLabel}. */
388
+ export declare interface SankeyEdgeLabelContext {
389
+ /** Source node name. */
390
+ readonly source: string;
391
+ /** Target node name. */
392
+ readonly target: string;
393
+ /** Flow value. */
394
+ readonly value: number;
362
395
  }
363
396
 
364
397
  /** Generic graph interface for layout algorithms that only need basic traversal. */
365
- declare interface SankeyGraph_2 {
398
+ declare interface SankeyGraph {
366
399
  nodes(): string[];
367
400
  node(id: string): NodeLabel;
368
401
  setNode(id: string, label: NodeLabel): void;
@@ -414,6 +447,57 @@ export declare interface SankeyGraphNode {
414
447
  readonly title: string;
415
448
  }
416
449
 
450
+ declare class SankeyGraphRenderer extends Paper {
451
+ graph: SankeyGraph;
452
+ maxRank: number;
453
+ /** Options resolved with CSS custom property overrides for the current render pass. */
454
+ private renderOptions;
455
+ /** Accessibility helper — re-created on each render pass. */
456
+ private a11yHelper;
457
+ /** Path highlighter — re-created on each render pass when feature is enabled. */
458
+ private pathHighlighter;
459
+ /** Guard: entrance animation plays only on the first render. */
460
+ private _hasAnimated;
461
+ /** Resolved, localized screen-reader strings. */
462
+ private messages;
463
+ constructor(element: HTMLElement, options: SankeyOptions, chartContext: ChartContext);
464
+ /** Resolved, localized screen-reader strings (English defaults + `locale.messages`). */
465
+ getMessages(): SankeyMessages;
466
+ /** Whether the current `locale.direction` resolves to right-to-left. */
467
+ private get isRtl();
468
+ construct(data: GraphData): void;
469
+ /**
470
+ * Mirror the laid-out diagram horizontally so flows read right-to-left.
471
+ * Node centers and edge endpoints are reflected around a common axis (the
472
+ * midpoint of all node centers), which keeps every edge attached to the
473
+ * correct node face. Runs once per `construct`, so re-renders redraw the
474
+ * already-mirrored positions without compounding.
475
+ */
476
+ private mirrorLayoutForRtl;
477
+ render({ keepOldPosition }?: {
478
+ keepOldPosition?: boolean | undefined;
479
+ }): void;
480
+ renderEdge(edgeObj: GraphEdge, group: G): void;
481
+ }
482
+
483
+ /**
484
+ * Every user-facing string the Sankey diagram generates internally (the
485
+ * screen-reader summaries and group labels). Override any subset via
486
+ * {@link LocaleOptions.messages}; unset keys keep their English defaults
487
+ * ({@link DEFAULT_SANKEY_MESSAGES}). Visible tooltips are localized separately
488
+ * through `tooltipTemplate` / `nodeTooltipTemplate`.
489
+ */
490
+ export declare interface SankeyMessages {
491
+ /** Builds the SVG root aria-label summary. */
492
+ readonly diagramLabel: (ctx: SankeyDiagramLabelContext) => string;
493
+ /** Builds an edge path's aria-label. */
494
+ readonly edgeAriaLabel: (ctx: SankeyEdgeLabelContext) => string;
495
+ /** Builds a node group's aria-label. */
496
+ readonly nodeAriaLabel: (ctx: SankeyNodeLabelContext) => string;
497
+ /** aria-label for the `<g>` wrapping all nodes. @default 'Sankey nodes' */
498
+ readonly nodesGroupLabel: string;
499
+ }
500
+
417
501
  /** Data passed to the onNodeClick callback */
418
502
  export declare interface SankeyNode {
419
503
  value?: number;
@@ -427,6 +511,22 @@ export declare interface SankeyNode {
427
511
  data?: NodeData | null;
428
512
  }
429
513
 
514
+ /** Context passed to {@link SankeyMessages.nodeAriaLabel}. */
515
+ export declare interface SankeyNodeLabelContext {
516
+ /** Resolved node display name. */
517
+ readonly name: string;
518
+ /** Incoming flow summary, omitted when the node has no incoming flows. */
519
+ readonly incoming?: {
520
+ readonly total: number;
521
+ readonly sources: readonly string[];
522
+ };
523
+ /** Outgoing flow summary, omitted when the node has no outgoing flows. */
524
+ readonly outgoing?: {
525
+ readonly total: number;
526
+ readonly targets: readonly string[];
527
+ };
528
+ }
529
+
430
530
  /**
431
531
  * Full configuration type for `ApexSankey`. An intersection of all sub-option
432
532
  * interfaces: `CommonOptions & EdgeOptions & FontOptions & InteractionOptions &
@@ -436,6 +536,8 @@ export declare interface SankeyNode {
436
536
  */
437
537
  export declare type SankeyOptions = CommonOptions & EdgeOptions & FontOptions & InteractionOptions & AnimationOptions & LayoutOptions & NodeOptions & TooltipOptions & A11yOptions;
438
538
 
539
+ export { TextDirection }
540
+
439
541
  /** Data passed to the tooltipTemplate callback */
440
542
  export declare interface TooltipContent {
441
543
  source?: NodeData | null;
@@ -1 +1 @@
1
- const t=()=>{};class e{constructor(t,e){this.injectedStyles=new Set,this.instanceId=e||Math.random().toString(36).substr(2,9),this.context=this.detectContext(t),this.chartContainer=t}getChartContainer(){return this.chartContainer}getChartScopedContainer(){return this.context===document?document.body||document.getElementsByTagName("body")[0]:this.chartContainer||this.context}detectContext(t){const e=t.getRootNode();return e instanceof ShadowRoot?e:document}getContext(){return this.context}getInstanceId(){return this.instanceId}isShadowDOM(){return this.context instanceof ShadowRoot}createElement(t){return document.createElement(t)}createElementNS(t,e){return document.createElementNS(t,e)}createTextNode(t){return document.createTextNode(t)}getElementById(t){return this.context===document?document.getElementById(t):this.context.querySelector(`#${t}`)}getElementsByClassName(t){if(this.context===document)return document.getElementsByClassName(t);const e=this.context.querySelectorAll(`.${t}`),n=Array.from(e);return{item:t=>n[t]||null,get length(){return n.length},[Symbol.iterator]:()=>n[Symbol.iterator](),...Object.fromEntries(n.map(((t,e)=>[e,t])))}}querySelector(t){return this.context.querySelector(t)}querySelectorAll(t){return this.context.querySelectorAll(t)}getAppendContainer(){return this.context===document?document.body||document.getElementsByTagName("body")[0]:this.context}getChartBounds(){var t;return(null==(t=this.chartContainer)?void 0:t.getBoundingClientRect())||new DOMRect}getBody(){if(this.context===document)return document.body||document.getElementsByTagName("body")[0];return this.context.host}dispatchEvent(t){this.context===document?document.dispatchEvent(t):this.context.dispatchEvent(t)}addEventListener(t,e,n){this.context===document||"mousemove"===t||"mouseup"===t||"keydown"===t?document.addEventListener(t,e,n):this.context.addEventListener(t,e,n)}removeEventListener(t,e,n){this.context===document||"mousemove"===t||"mouseup"===t||"keydown"===t?document.removeEventListener(t,e,n):this.context.removeEventListener(t,e,n)}injectStyles(t,e,n={}){const{force:o=!1,priority:i="normal"}=n;if(!o&&this.injectedStyles.has(e))return;if(o){const t=this.context.querySelector(`#${e}`);t&&(t.remove(),this.injectedStyles.delete(e))}if(this.context.querySelector(`#${e}`)&&!o)return void this.injectedStyles.add(e);const r=document.createElement("style");if(r.id=e,r.textContent=t,"normal"!==i&&r.setAttribute("data-priority",i),this.context===document)document.head.appendChild(r);else{const t=this.context;"high"===i?t.insertBefore(r,t.firstChild):t.appendChild(r)}this.injectedStyles.add(e)}injectStylesheets(t){t.forEach((({content:t,id:e,options:n})=>{this.injectStyles(t,e,n)}))}hasInjectedStyles(t){return this.injectedStyles.has(t)}removeStyles(t){const e=this.context.querySelector(`#${t}`);e&&(e.remove(),this.injectedStyles.delete(t))}removeAllStyles(){this.injectedStyles.forEach((t=>{const e=this.context.querySelector(`#${t}`);e&&e.remove()})),this.injectedStyles.clear()}getInjectedStyleIds(){return Array.from(this.injectedStyles)}getActiveElement(){if(this.context===document)return document.activeElement;return this.context.activeElement||document.activeElement}destroy(){this.removeAllStyles(),this.injectedStyles.clear()}}class n{constructor(t,n){if(!t)throw new Error("Container element is required");this.element=t,this.chartContext=new e(t,n)}getContext(){return this.chartContext}isShadowDOM(){return this.chartContext.isShadowDOM()}getTooltipContainer(){return this.chartContext.getAppendContainer()}injectStyles(t,e){this.chartContext.injectStyles(t,e)}createElement(t){return this.chartContext.createElement(t)}querySelector(t){return this.chartContext.querySelector(t)}addEventListener(t,e,n){this.chartContext.addEventListener(t,e,n)}removeEventListener(t,e,n){this.chartContext.removeEventListener(t,e,n)}dispatchEvent(t){this.chartContext.dispatchEvent(t)}destroy(){this.chartContext.destroy()}getInstanceId(){return this.chartContext.getInstanceId()}}class o{constructor(t,e="apex"){this.canvas=t,this.prefix=e}getSvgString(){const t=this.canvas.node.cloneNode(!0),e=this.canvas.node.viewBox.baseVal;e.width&&e.height&&(t.setAttribute("width",String(e.width)),t.setAttribute("height",String(e.height)));return(new XMLSerializer).serializeToString(t)}svgUrl(){const t=this.getSvgString(),e=new Blob([t],{type:"image/svg+xml;charset=utf-8"});return URL.createObjectURL(e)}triggerDownload(t,e){const n=document.createElement("a");n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n)}exportToSVG(){this.triggerDownload(this.svgUrl(),`${this.prefix}-${(new Date).getTime()}.svg`)}}const i=globalThis.console;const r=class{static decodeLicenseData(t){try{const e=window.atob(t),n=JSON.parse(e);return n.issueDate&&n.expiryDate&&n.plan?{domains:Array.isArray(n.domains)?n.domains:void 0,expiryDate:n.expiryDate,issueDate:n.issueDate,plan:n.plan,valid:!0}:null}catch{return null}}static generateLicenseKey(t,e,n="standard",o){const i={expiryDate:e,issueDate:t,plan:n};o&&o.length>0&&(i.domains=o);return`APEX-${window.btoa(JSON.stringify(i))}`}static getLicenseStatus(){return this.licenseKey?(this.validationResult||(this.validationResult=this.validateLicense(this.licenseKey)),this.validationResult):{expired:!1,valid:!1}}static isLicenseValid(){return!!this.licenseKey&&(this.validationResult||(this.validationResult=this.validateLicense(this.licenseKey)),this.validationResult.valid)}static setLicense(t){var e;this.licenseKey=t,this.validationResult=this.validateLicense(t),this.validationResult.valid||(e=`[Apex] ${this.validationResult.message}`,i.error(e))}static validateLicense(t){try{if(!t.startsWith("APEX-"))return{expired:!1,message:'Invalid license key format. License key must start with "APEX-".',valid:!1};const e=t.indexOf("-"),n=-1!==e?t.slice(e+1):"";if(!n)return{expired:!1,message:"Invalid license key format. Expected format: APEX-{encoded-data}.",valid:!1};const o=this.decodeLicenseData(n);if(!o)return{expired:!1,message:"Invalid license key. Unable to decode license data.",valid:!1};const i=new Date;if(new Date(o.expiryDate)<i)return{data:o,expired:!0,message:`License expired on ${o.expiryDate}. Please renew your license.`,valid:!1};if(o.domains&&o.domains.length>0){const t="undefined"!=typeof window?window.location.hostname:"";if(!o.domains.some((e=>t===e||t.endsWith(`.${e}`))))return{data:o,expired:!1,message:`License is not valid for this domain (${t}). Allowed domains: ${o.domains.join(", ")}.`,valid:!1}}return{data:o,expired:!1,valid:!0}}catch{return{expired:!1,message:"Invalid license key format or corrupted data.",valid:!1}}}};r.licenseKey=null,r.validationResult=null;let s=r;const a="http://www.w3.org/2000/svg";let d=0;class l{constructor(t){this.node=t}attr(t,e){if("string"==typeof t)return void 0!==e?(this.node.setAttribute(t,String(e)),this):this.node.getAttribute(t);for(const[e,n]of Object.entries(t))null!=n&&this.node.setAttribute(e,String(n));return this}id(t){return this.node.setAttribute("id",t),this}fill(t){if(!t)return this;if(t instanceof SVGElement){const e=t.id;this.node.setAttribute("fill",`url(#${e})`)}else this.node.setAttribute("fill",t);return this}stroke({color:t,width:e,dasharray:n}={}){return void 0!==t&&this.node.setAttribute("stroke",t),void 0!==e&&this.node.setAttribute("stroke-width",String(e)),void 0!==n&&this.node.setAttribute("stroke-dasharray",String(n)),this}opacity(t){return this.node.setAttribute("opacity",String(t)),this}add(t){const e=t instanceof l?t.node:t;return this.node.appendChild(e),this}on(t,e){return this.node.addEventListener(t,e),this}findOne(t){const e=this.node.querySelector(t);return e?new l(e):null}first(){const t=this.node.firstElementChild;return t?new l(t):null}}class h extends l{constructor(t){super(document.createElementNS(a,"g")),t&&this.attr(t)}}class c extends l{constructor(){super(document.createElementNS(a,"rect"))}}class u extends l{constructor(t){super(document.createElementNS(a,"path")),t&&this.attr(t)}}class p extends l{constructor(){super(document.createElementNS(a,"text"))}font({fill:t,size:e}){return void 0!==t&&this.node.setAttribute("fill",t),void 0!==e&&this.node.setAttribute("font-size",String(e)),this}tspan(t){const e=document.createElementNS(a,"tspan");return e.textContent=t,this.node.appendChild(e),this}move(t,e){return this.node.setAttribute("x",String(t)),this.node.setAttribute("y",String(e)),this}}class g{constructor(t){this.gradient=t}stop(t,e){const n=document.createElementNS(a,"stop");n.setAttribute("offset",String(t)),n.setAttribute("stop-color",e??"transparent"),this.gradient.appendChild(n)}}function f(t,e){t.setAttribute("viewBox",`${e.x} ${e.y} ${e.w} ${e.h}`)}class m{constructor(t){this._defs=null,this._panZoomState=null,this.node=t}addTo(t){return t.appendChild(this.node),this}size(t,e){return this.node.setAttribute("width",String(t)),this.node.setAttribute("height",String(e)),this}viewbox(t){if(void 0===t){const t=this.node.viewBox.baseVal;return{x:t.x,y:t.y,width:t.width,height:t.height}}if(this.node.setAttribute("viewBox",t),this._panZoomState){const t=this.node.viewBox.baseVal;this._panZoomState.vb={x:t.x,y:t.y,w:t.width,h:t.height}}return this}attr(t){for(const[e,n]of Object.entries(t))null!=n&&this.node.setAttribute(e,String(n));return this}add(t){return this.node.appendChild(t instanceof l?t.node:t),this}clear(){const t=this._defs;return this.node.innerHTML="",t&&(this.node.appendChild(t),this._defs=t),this}svg(){return this.node.innerHTML}gradient(t,e){this._defs||(this._defs=document.createElementNS(a,"defs"),this.node.insertBefore(this._defs,this.node.firstChild));const n=document.createElementNS(a,"linearGradient"),o="apx-grad-"+ ++d;return n.setAttribute("id",o),n.setAttribute("x1","0%"),n.setAttribute("y1","0%"),n.setAttribute("x2","100%"),n.setAttribute("y2","0%"),e(new g(n)),this._defs.appendChild(n),n}panZoom(t={}){return this._panZoomState=function(t,e){const n=function(t){const e=t.viewBox.baseVal;return{x:e.x,y:e.y,w:e.width,h:e.height}}(t),o={zoomFactor:e.zoomFactor??.2,zoomMin:e.zoomMin??.1,currentZoom:1,baseVb:{...n},vb:{...n}};t.addEventListener("wheel",(e=>{let n;if(e.preventDefault(),e.ctrlKey){const t=.005;n=1+Math.max(-.15,Math.min(.15,e.deltaY*t))}else n=e.deltaY<0?1-o.zoomFactor:1+o.zoomFactor;const i=o.currentZoom/n;if(i<o.zoomMin)return;const r=t.getBoundingClientRect(),s=(e.clientX-r.left)/r.width,a=(e.clientY-r.top)/r.height,{vb:d}=o,l=d.w*n,h=d.h*n,c=d.x+s*(d.w-l),u=d.y+a*(d.h-h);o.vb={x:c,y:u,w:l,h:h},o.currentZoom=i,f(t,o.vb)}),{passive:!1});let i=!1,r=!1,s=-1,a=0,d=0;t.addEventListener("pointerdown",(t=>{0===t.button&&(t.preventDefault(),i=!0,r=!1,s=t.pointerId,a=t.clientX,d=t.clientY)})),t.addEventListener("pointermove",(e=>{if(!i||e.pointerId!==s)return;if(!r){const n=e.clientX-a,o=e.clientY-d;if(Math.abs(n)<4&&Math.abs(o)<4)return;r=!0,t.setPointerCapture(e.pointerId),t.style.cursor="grabbing",t.style.userSelect="none"}const n=t.getBoundingClientRect(),l=o.vb.w/n.width,h=o.vb.h/n.height,c=(e.clientX-a)*l,u=(e.clientY-d)*h;o.vb={x:o.vb.x-c,y:o.vb.y-u,w:o.vb.w,h:o.vb.h},f(t,o.vb),a=e.clientX,d=e.clientY}));const l=e=>{i&&e.pointerId===s&&(r&&(t.releasePointerCapture(e.pointerId),t.style.cursor="",t.style.userSelect=""),i=!1,r=!1,s=-1)};return t.addEventListener("pointerup",l),t.addEventListener("pointercancel",l),o}(this.node,t),this}resetPanZoomBase(){if(!this._panZoomState)return;const t=this.node.viewBox.baseVal;this._panZoomState.baseVb={x:t.x,y:t.y,w:t.width,h:t.height},this._panZoomState.vb={x:t.x,y:t.y,w:t.width,h:t.height},this._panZoomState.currentZoom=1}zoom(t){var e;if(void 0===t)return(null==(e=this._panZoomState)?void 0:e.currentZoom)??1;if(!this._panZoomState)return this;const n=this._panZoomState;if(t<n.zoomMin)return this;const o=n.currentZoom/t,{vb:i}=n,r=i.w*o,s=i.h*o,a=i.x+.5*(i.w-r),d=i.y+.5*(i.h-s);return n.vb={x:a,y:d,w:r,h:s},n.currentZoom=t,f(this.node,n.vb),this}}function v(t,e,n,o){const i=new h;return i.attr({"data-parent":o,"data-self":n,transform:void 0!==t&&void 0!==e?`translate(${t}, ${e})`:void 0}),i}const y={export:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">\n <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>\n <polyline points="7 10 12 15 17 10"/>\n <line x1="12" y1="15" x2="12" y2="3"/>\n </svg>',"zoom-in":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">\n <circle cx="11" cy="11" r="8"/>\n <path d="m21 21-4.35-4.35"/>\n <line x1="11" y1="8" x2="11" y2="14"/>\n <line x1="8" y1="11" x2="14" y2="11"/>\n </svg>',"zoom-out":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">\n <circle cx="11" cy="11" r="8"/>\n <path d="m21 21-4.35-4.35"/>\n <line x1="8" y1="11" x2="14" y2="11"/>\n </svg>',"fit-screen":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">\n <path d="M8 3H5a2 2 0 0 0-2 2v3"/>\n <path d="M21 8V5a2 2 0 0 0-2-2h-3"/>\n <path d="M3 16v3a2 2 0 0 0 2 2h3"/>\n <path d="M16 21h3a2 2 0 0 0 2-2v-3"/>\n </svg>'};class b{constructor(t,n){this.element=t,t&&(this.chartContext=n||new e(t),this.injectStyles())}injectStyles(){const t=`toolbar-styles-${this.chartContext.getInstanceId()}`;this.chartContext.injectStyles("\n #toolbar {\n display: flex;\n gap: 2px;\n position: absolute;\n right: 12px;\n top: 12px;\n z-index: 100;\n user-select: none;\n background: var(--toolbar-bg-color, rgba(255, 255, 255, 0.92));\n border: 1px solid var(--toolbar-border-color, rgba(0, 0, 0, 0.08));\n border-radius: 10px;\n padding: 4px;\n box-shadow:\n 0 1px 3px rgba(0, 0, 0, 0.08),\n 0 4px 12px rgba(0, 0, 0, 0.06);\n backdrop-filter: blur(8px);\n -webkit-backdrop-filter: blur(8px);\n }\n\n .toolbar-item {\n align-items: center;\n background-color: transparent;\n border: none;\n border-radius: 6px;\n color: var(--toolbar-icon-color, #444);\n cursor: pointer;\n display: flex;\n height: 30px;\n justify-content: center;\n width: 30px;\n transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;\n position: relative;\n flex-shrink: 0;\n }\n\n .toolbar-item:hover {\n background-color: var(--toolbar-hover-bg-color, rgba(0, 0, 0, 0.06));\n color: var(--toolbar-icon-hover-color, #111);\n transform: translateY(-1px);\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);\n }\n\n .toolbar-item:active {\n transform: translateY(0);\n box-shadow: none;\n background-color: var(--toolbar-active-bg-color, rgba(0, 0, 0, 0.1));\n }\n\n .toolbar-item:focus-visible {\n outline: none;\n box-shadow: 0 0 0 2px var(--button-bg-color, #0066cc);\n }\n\n .toolbar-item svg {\n width: 15px;\n height: 15px;\n pointer-events: none;\n flex-shrink: 0;\n }\n\n .toolbar-item[disabled] {\n opacity: 0.4;\n cursor: not-allowed;\n pointer-events: none;\n }\n\n /* Tooltip */\n .toolbar-item::after {\n content: attr(data-tooltip);\n position: absolute;\n bottom: calc(100% + 8px);\n left: 50%;\n transform: translateX(-50%);\n background: var(--tooltip-bg-color, rgba(30, 30, 30, 0.92));\n color: var(--tooltip-text-color, #fff);\n padding: 5px 9px;\n border-radius: 6px;\n font-size: 11.5px;\n font-weight: 500;\n white-space: nowrap;\n opacity: 0;\n pointer-events: none;\n transition: opacity 0.15s ease;\n z-index: 1000;\n letter-spacing: 0.01em;\n }\n\n .toolbar-item::before {\n content: '';\n position: absolute;\n bottom: calc(100% + 3px);\n left: 50%;\n transform: translateX(-50%);\n border: 4px solid transparent;\n border-top-color: var(--tooltip-bg-color, rgba(30, 30, 30, 0.92));\n opacity: 0;\n pointer-events: none;\n transition: opacity 0.15s ease;\n z-index: 1000;\n }\n\n .toolbar-item:hover::after,\n .toolbar-item:hover::before {\n opacity: 1;\n }\n\n /* Shadow DOM specific adjustments */\n :host #toolbar {\n display: flex;\n gap: 2px;\n position: absolute;\n right: 12px;\n top: 12px;\n z-index: 100;\n }\n",t)}createToolbarItem(t,e,n){const o=this.chartContext.createElement("div");return o.id=t,o.className="toolbar-item",o.setAttribute("role","button"),o.setAttribute("tabindex","0"),o.innerHTML=e,n&&(o.setAttribute("data-tooltip",n),o.setAttribute("aria-label",n)),o.addEventListener("keydown",(t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),o.click())})),o}render({enableExport:e=!1,enableFitscreen:n=!1,enableZoom:o=!1,onExport:i=t,onFitscreen:r=t,onZoom:s=t}){if(!this.element)return;const a=this.chartContext.querySelector("#toolbar");null==a||a.remove();const d=this.chartContext.createElement("div");if(d.id="toolbar",d.setAttribute("role","toolbar"),d.setAttribute("aria-label","Chart controls"),e){const t=this.createToolbarItem("export",y.export,"Export chart");t.addEventListener("click",(()=>{i()})),d.append(t)}if(o){const t=this.createToolbarItem("zoom-in",y["zoom-in"],"Zoom in"),e=this.createToolbarItem("zoom-out",y["zoom-out"],"Zoom out");t.addEventListener("click",(()=>{s(.1)})),e.addEventListener("click",(()=>{s(-.1)})),d.append(t,e)}if(n){const t=this.createToolbarItem("fit-screen",y["fit-screen"],"Fit to screen");t.addEventListener("click",(()=>{r()})),d.append(t)}this.element.append(d)}destroy(){const t=this.chartContext.querySelector("#toolbar");null==t||t.remove()}}const x=class{static createWatermarkPattern(){const t=this.WATERMARK_TEXT;return`url("data:image/svg+xml,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="300" height="200">\n <text \n x="50%" \n y="50%" \n dominant-baseline="middle" \n text-anchor="middle"\n font-family="-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Arial, sans-serif"\n font-size="18"\n font-weight="600"\n fill="rgba(134, 134, 134, 0.1)"\n transform="rotate(-35, 100, 60)"\n >${t}</text>\n </svg>\n `.trim())}")`}static add(t){this.remove(t);const e=document.createElement("div");e.setAttribute(this.WATERMARK_ATTR,""),Object.assign(e.style,{backgroundImage:this.createWatermarkPattern(),backgroundRepeat:"repeat",bottom:"0",left:"0",msUserSelect:"none",pointerEvents:"none",position:"absolute",right:"0",top:"0",userSelect:"none",webkitUserSelect:"none",zIndex:"10000"}),"static"===getComputedStyle(t).position&&(t.style.position="relative"),t.appendChild(e)}static exists(t){return!!t.querySelector(`[${this.WATERMARK_ATTR}]`)}static remove(t){const e=t.querySelector(`[${this.WATERMARK_ATTR}]`);e&&e.remove()}};x.WATERMARK_ATTR="data-apexcharts-watermark",x.WATERMARK_TEXT="APEXCHARTS";let w=x;const E="aria-hidden",A=(t,e="apex-tooltip-container")=>{let n=t.getElementById(e);if(!n){n=t.createElement("div"),n.id=e,n.setAttribute("role","tooltip"),n.setAttribute(E,"true");t.getAppendContainer().appendChild(n)}return n},S=(t,e="",n,o="")=>{const i=t.getElementById(e);if(!i)return A(t,e),S(t,e,n,o);if(n&&o){const t=o.includes("tooltip-content"),e=n.match(/background-color:\s*([^;]+);?/),r=n.match(/color:\s*([^;]+);?/),s=e?e[1]:"#333",a=r?r[1]:"white";i.innerHTML=t?o:`<div class="tooltip-content" style="background-color: ${s}; color: ${a};">${o}</div>`;const d=n+"; display: block !important; visibility: visible !important; opacity: 1 !important;";i.setAttribute("style",d),i.classList.add("visible"),i.setAttribute(E,"false")}else i.removeAttribute("style"),i.classList.remove("visible"),i.setAttribute(E,"true"),i.innerHTML=""},C=({bgColor:t,borderColor:e,fontColor:n,fontFamily:o,fontSize:i,fontWeight:r,maxWidth:s,padding:a,placement:d="top",x:l,y:h})=>{const c=["position: absolute;","z-index: 1000;","pointer-events: none;"];return c.push("box-sizing: border-box;"),c.push("word-wrap: break-word;"),c.push("overflow-wrap: break-word;"),c.push(`left: ${l}px;`),c.push(`top: ${h}px;`),c.push(`data-placement: ${d};`),s&&(c.push(`width: ${s}px;`),c.push(`max-width: ${s}px;`)),e&&c.push(`border: 1px solid ${e};`),c.push("border-radius: 6px;"),c.push("box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);"),n&&c.push(`color: ${n};`),o&&c.push(`font-family: ${o};`),r&&c.push(`font-weight: ${r};`),i&&c.push(`font-size: ${i};`),t&&c.push(`background-color: ${t};`),void 0!==a&&c.push(`padding: ${a}px;`),c.join(" ")};function k(t,e){let n=null;for(let o=0;o<t.length;++o)if(e(t[o])){n=o;break}return n}function $(t,e){if(0===t.length)return;let n,o=0;for(let i=t.length-1;i>=0;--i)n=(t[i].dy??0)/2,(t[i][e]??0)-n<o&&(t[i][e]=Math.min(t[i].Rmax??0,o+n)),o=(t[i][e]??0)+n;let i=(t[0].Rmax??0)+(t[0].dy??0)/2;for(let o=0;o<t.length;++o)n=(t[o].dy??0)/2,(t[o][e]??0)+n>i&&(t[o][e]=Math.max(n,i-n)),i=(t[o][e]??0)-n}function M(t){const e=t.edgeGap||0;return function(n){!function(t,e,n){t.nodes().forEach((o=>{const i=t.node(o),r=L(t,i.outgoing||[],"outgoing"),s=L(t,i.incoming||[],"incoming"),a=r.length,d=s.length,l=r.reduce(((e,n)=>e+(t.edge(n).dy??0)),0),h=s.reduce(((e,n)=>e+(t.edge(n).dy??0)),0),c=l+Math.max(0,a-1)*n,u=h+Math.max(0,d-1)*n;let p=((i.dy??0)-c)/2,g=((i.dy??0)-u)/2;p=Math.max(0,p),g=Math.max(0,g),r.forEach(((o,r)=>{const s=t.edge(o);s.x0=(i.x??0)+(e.nodeWidth??0)/2,s.y0=(i.y??0)+p+(s.dy??0)/2,s.d0=i.direction||"r",p+=s.dy??0,r<a-1&&(p+=n)})),s.forEach(((o,r)=>{const s=t.edge(o);s.x1=(i.x??0)-(e.nodeWidth??0)/2,s.y1=(i.y??0)+g+(s.dy??0)/2,s.d1=i.direction||"r",g+=s.dy??0,r<d-1&&(g+=n)}))}))}(n,t,e),function(t){t.nodes().forEach((e=>{const n=t.node(e),o=(n.outgoing||[]).map((e=>t.edge(e))),i=(n.incoming||[]).map((e=>t.edge(e)));o.sort(((t,e)=>(t.y0??0)-(e.y0??0))),i.sort(((t,e)=>(t.y1??0)-(e.y1??0))),_(o,"r0"),_(i,"r1")}))}(n);const o=[];return n.edges().forEach((t=>{const e=n.edge(t);e.id=`${t.v}-${t.w}-${t.name}`,o.push(e)})),o}}function L(t,e,n){return e.slice().sort(((e,o)=>{let i,r;if("outgoing"===n){const n=t.node(e.w),s=t.node(o.w);i=(null==n?void 0:n.y)??0,r=(null==s?void 0:s.y)??0}else{const n=t.node(e.v),s=t.node(o.v);i=(null==n?void 0:n.y)??0,r=(null==s?void 0:s.y)??0}if(Math.abs(i-r)>.001)return i-r;if(e.name!==o.name){if("number"==typeof e.name&&"number"==typeof o.name)return e.name-o.name;if("string"==typeof e.name&&"string"==typeof o.name)return e.name.localeCompare(o.name)}return 0}))}function _(t,e){t.forEach((t=>{t.Rmax=function(t){const e=(t.x1??0)-(t.x0??0),n=(t.y1??0)-(t.y0??0);return t.d0!==t.d1?Math.abs(n)/2.1:0!==n?(e*e+n*n)/Math.abs(4*n):1/0}(t),t[e]=Math.max((t.dy??0)/2,t.d0===t.d1?.6*(t.Rmax??0):5+(t.dy??0)/2)}));let n=k(t,"r0"===e?t=>(t.y1??0)>(t.y0??0):t=>(t.y0??0)>(t.y1??0));if(null===n&&(n=t.length),$(t.slice(n),e),n>0){const o=[];for(let e=n-1;e>=0;e--)o.push(t[e]);$(o,e)}}function B(t,e,n,o,i){if(0===o.length)return;const r=o.map((n=>{const o=`__${e.v}_${e.w}_${n}`;return t.setNode(o,{data:null,direction:i,dummy:!0,rank:n}),o})),s=[e.v,...r,e.w];s.forEach(((o,i)=>{i+1<s.length&&t.setEdge(s[i],s[i+1],{data:t.edge(e).data,origEdge:e,origLabel:n,source:t.node(e.v),target:t.node(e.w),value:t.edge(e).value},e.name)})),t.removeEdge(e)}function T(t,e,n){return function(t,e,n){let o,i;e.length>n.length?(o=e,i=n):(o=n,i=e);const r=i.length,s=[];o.forEach((e=>{i.forEach(((n,o)=>{(t.hasEdge(e,n)||t.hasEdge(n,e))&&s.push(o)}))}));let a=1;for(;a<r;)a*=2;const d=2*a-1;a-=1;const l=new Array(d).fill(0);let h=0;return s.forEach((t=>{let e=t+a;for(l[e]++;e>0;)e%2&&(h+=l[e+1]),e=Math.floor((e-1)/2),l[e]++})),h}(t,e,n)}function R(t){const e=[];let n=t.nodes().filter((e=>0===t.node(e).rank)).concat(t.sources());return 0===n.length&&(n=t.nodes().slice(0,1)),function(t,e){const n=new Set,o=[];function i(e){if(!n.has(e)){n.add(e),o.push(e);for(const n of t.successors(e))i(n)}}for(const t of e)i(t);return o}(t,n).forEach((n=>{const o=t.node(n).rank;if(void 0!==o){for(;o>=e.length;)e.push([]);e[o].push(n)}})),e}function N(t,e){let n=!0;for(;n;){n=!1;for(let o=0;o<e.length;++o)for(let i=0;i<e[o].length-1;++i){const r=I(t,e,o);F(e[o],i,i+1);I(t,e,o)<r?n=!0:F(e[o],i,i+1)}}}function I(t,e,n){let o=0;return n>0&&(o+=T(t,e[n-1],e[n])),n+1<e.length&&(o+=T(t,e[n],e[n+1])),o}function F(t,e,n){const o=t[e];t[e]=t[n],t[n]=o}function z(t){const e=Math.floor(t.length/2);if(0===t.length)return-1;if(t.length%2==1)return t[e];if(2===t.length)return(t[0]+t[1])/2;const n=t[e-1]-t[0],o=t[t.length-1]-t[e];return(t[e-1]*o+t[e]*n)/(n+o)}function O(t,e,n=1,o=!1){if(n>0)for(let n=1;n<e.length;++n){const i=new Map;e[n].forEach((r=>{const s=z(W(t,e,n,n-1,r,o));i.set(r,s)})),j(e[n],i)}else for(let n=e.length-2;n>=0;--n){const i=new Map;e[n].forEach((r=>{const s=z(W(t,e,n,n+1,r,o));i.set(r,s)})),j(e[n],i)}}function W(t,e,n,o,i,r=!1){const s=e[n],a=e[o],d=[];return a.forEach(((e,n)=>{t.nodeEdges(e,i).length>0&&d.push(n)})),0===d.length&&r&&s.forEach(((e,n)=>{t.nodeEdges(e,i).length>0&&d.push(n+.5)})),d.sort(((t,e)=>t-e)),d}function j(t,e){const n=new Map(t.map(((t,e)=>[t,e])));for(let o=1;o<t.length;++o)for(let i=o;i>0;--i){let o=i-1,r=e.get(t[o]),s=e.get(t[i]);for(;-1===(r=e.get(t[o]))&&o>0;)o--;if(void 0===s||void 0===r||-1===s||-1===r)break;if(r===s&&(r=n.get(t[o])??r,s=n.get(t[i])??s),s>=r)break;[t[i],t[o]]=[t[o],t[i]]}}function q(t,e){let n=0;for(let o=0;o<e.length-1;++o)n+=T(t,e[o],e[o+1]);return n}function D(t){const e=[];for(const n of t){const t=[];e.push(t);for(const e of n)t.push(e)}return e}const G=(t,e)=>(t||[]).reduce(((t,n)=>t+(e?e(n):n)),0);function H(){let t=[100,100],e=null,n=.18,o=function(t,e,n){return 1};const i=function(t){return t.data.value},r=function(t){return t.data?t.data.direction??"r":"r"};function s(a,d,l=0){null===e&&s.scaleToFit(a,d,l),Y(a,i,r),function(t,e,n,o=0){t.nodes().forEach((e=>{const i=t.node(e),r=t.inEdges(e)||[],s=t.outEdges(e)||[],a=Math.max(0,r.length-1),d=Math.max(0,s.length-1),l=Math.max(a,d);i.dy=i.value*n+l*o})),t.edges().forEach((o=>{const i=t.edge(o);i.value=e(i),i.dy=i.value*n}))}(a,i,e,l);const h=Z(a,d,l,e),c=[];for(let e=0;e<d.length;e++){const i=d[e],r=i.length;let s=0;c[e]=[];for(let d=0;d<i.length;d++){const l=i[d],u=h[d]/G(h)*t[1],p=0===s?0:n*u/5,g=u-2*p,f=l.map(((t,e)=>a.node(t).value&&l[e+1]?o(l[e],l[e+1],a):0)),m=G(l,(t=>a.node(t).dy)),v=Math.max(0,g-m),y=G(f)?v/G(f):0;let b=s+p;1===l.length&&(b+=(g-a.node(l[0]).dy)/2),c[e][d]={margin:p,height:g,gaps:f,kg:y,isFirst:0===d,isLast:d===r-1,startYY:b},s+=u}}let u,p,g=-1,f=-1,m=0,v=0;(function(t){const e=[];for(let n=0;n<t.length;n++){const o=t[n];for(let t=0;t<o.length;t++){const i=o[t];for(let o=0;o<i.length;o++)e.push({rankIndex:n,bandIndex:t,nodeIndex:o,nodeId:i[o]})}}return e})(d).forEach((({rankIndex:t,bandIndex:e,nodeIndex:n,nodeId:o})=>{var i;t===g&&e===f||(g=t,f=e,u=c[t][e],p=d[t][e],m=u.startYY,v=u.isFirst?Number.MAX_VALUE:0);const r=a.node(o);r.y=m,r.spaceAbove=v,r.spaceBelow=u.gaps[n]*u.kg,m+=r.dy+r.spaceBelow,v=r.spaceBelow,void 0!==(null==(i=r.data)?void 0:i.forceY)&&(r.y=u.margin+r.data.forceY*(u.height-r.dy)),n===p.length-1&&(r.spaceBelow=u.isLast?Number.MAX_VALUE:0)}));const y=function(t,e){const n=[];return e.forEach(((o,i)=>{if(i===e.length-1)return;let r=0;o.forEach((e=>{e.forEach((e=>{t.outEdges(e).forEach((e=>{const n=t.edge(e).dy,o=t.node(e.w).y-t.node(e.v).y,i=Math.abs(o)-n,s=n*n-i*i,a=s>=0?Math.sqrt(s):n;a>r&&(r=a)}))}))})),n.push(r)})),n}(a,d);!function(t,e,n,o){const i=o.reduce(((t,e)=>t+e),0);let r;if(i>n)r=o.map((t=>n*t/i));else{const t=n-i;r=o.map((n=>n+t/(e.length-1)))}let s=0;e.forEach(((e,n)=>{e.forEach((e=>{e.forEach((e=>{t.node(e).x=s}))})),s+=r[n]}))}(a,d,t[0],y);const b=[];return a.nodes().forEach((t=>{const e=a.node(t);e.id=t,b.push(e)})),b}return s.scaleToFit=function(o,s,a=0){Y(o,i,r);let d=0;a>0&&o.nodes().forEach((t=>{d=Math.max(d,function(t,e,n){if(n<=0)return 0;const o=t.inEdges(e)||[],i=t.outEdges(e)||[],r=Math.max(0,o.length-1),s=Math.max(0,i.length-1);return Math.max(r,s)*n}(o,t,a))}));const l=G(Z(o,s,0,1));if(l<=0)return void(e=1);const h=t[1]-d;e=h/l,1!==n&&(e*=1-n)},s.size=function(e){return arguments.length?(t=e,s):t},s.separation=function(t){return arguments.length?(o="function"==typeof t?t:()=>t,s):o},s.whitespace=function(t){return arguments.length?(n=t,s):n},s.scale=function(t){return arguments.length?(e=t,s):e},s}function Y(t,e,n){t.nodes().forEach((o=>{const i=G(t.inEdges(o),(n=>e(t.edge(n)))),r=G(t.outEdges(o),(n=>e(t.edge(n))));let s=t.node(o);s||t.setNode(o,s={}),s.value=Math.max(i,r),void 0===s.direction&&(s.direction=n(s)||"r")}))}function Z(t,e,n=0,o=1){if(0===e.length||0===e[0].length)return[];const i=e[0].length,r=new Array(i).fill(0);return e.forEach((e=>{e.forEach(((e,i)=>{const s=G(e,(e=>{const i=t.node(e),r=t.inEdges(e)||[],s=t.outEdges(e)||[],a=Math.max(0,r.length-1),d=Math.max(0,s.length-1),l=Math.max(a,d);return i.value+l*n/o}));r[i]=Math.max(r[i],s)}))})),r}function P(t,e,n){return void 0!==n?`${t}${e}${n}`:`${t}${e}`}class V{constructor(t={}){this._nodes=new Map,this._edges=new Map,this._graphLabel={},this._out=new Map,this._in=new Map,this._isMultigraph=t.multigraph??!1}graph(){return this._graphLabel}setGraph(t){return this._graphLabel=t,this}setNode(t,e){return this._nodes.has(t)?void 0!==e&&this._nodes.set(t,e):(this._nodes.set(t,void 0!==e?e:{}),this._out.set(t,new Set),this._in.set(t,new Set)),this}node(t){return this._nodes.get(t)}hasNode(t){return this._nodes.has(t)}nodes(){return Array.from(this._nodes.keys())}removeNode(t){var e,n;if(!this._nodes.has(t))return this;this._nodes.delete(t);const o=Array.from(this._out.get(t)??[]),i=Array.from(this._in.get(t)??[]);for(const t of o){const n=this._edges.get(t);n&&(null==(e=this._in.get(n.w))||e.delete(t)),this._edges.delete(t)}for(const t of i){const e=this._edges.get(t);e&&(null==(n=this._out.get(e.v))||n.delete(t)),this._edges.delete(t)}return this._out.delete(t),this._in.delete(t),this}sources(){return this.nodes().filter((t=>{var e;return 0===((null==(e=this._in.get(t))?void 0:e.size)??0)}))}successors(t){return this.outEdges(t).map((t=>t.w))}setEdge(t,e,n,o){var i,r;let s,a;"object"==typeof t?(s=t.v,a=t.w,o=t.name,n=e):(s=t,a=e),this.setNode(s),this.setNode(a);const d=this._isMultigraph?P(s,a,o):P(s,a),l=this._edges.get(d);if(l)void 0!==n&&(l.label=n);else{const t={v:s,w:a,name:o,label:void 0!==n?n:{}};this._edges.set(d,t),null==(i=this._out.get(s))||i.add(d),null==(r=this._in.get(a))||r.add(d)}return this}edge(t,e,n){var o;let i;return i="string"==typeof t?this._isMultigraph?P(t,e,n):P(t,e):this._isMultigraph?P(t.v,t.w,t.name):P(t.v,t.w),null==(o=this._edges.get(i))?void 0:o.label}hasEdge(t,e,n){const o=this._isMultigraph?P(t,e,n):P(t,e);return this._edges.has(o)}edges(){return Array.from(this._edges.values()).map((({v:t,w:e,name:n})=>({v:t,w:e,name:n})))}removeEdge(t){var e,n;const o=this._isMultigraph?P(t.v,t.w,t.name):P(t.v,t.w),i=this._edges.get(o);return i?(null==(e=this._out.get(i.v))||e.delete(o),null==(n=this._in.get(i.w))||n.delete(o),this._edges.delete(o),this):this}outEdges(t){const e=this._out.get(t);return e?Array.from(e).flatMap((t=>{const e=this._edges.get(t);return e?[{v:e.v,w:e.w,name:e.name}]:[]})):[]}inEdges(t){const e=this._in.get(t);return e?Array.from(e).flatMap((t=>{const e=this._edges.get(t);return e?[{v:e.v,w:e.w,name:e.name}]:[]})):[]}nodeEdges(t,e){const n=[],o=new Set;for(const i of[...this.inEdges(t),...this.outEdges(t)])if(i.v===e||i.w===e){const t=P(i.v,i.w,i.name);o.has(t)||(o.add(t),n.push(i))}return n}}function X(t){return void 0!==t.name?`${t.v}${t.w}${t.name}`:`${t.v}${t.w}`}function K(t,e){const n=function(t,e){const n=new Set,o=new V({directed:!0}),i=[];if(!t.hasNode(e))throw Error("node not in graph");return U(t,e,n,o,i),t.nodes().forEach((e=>{n.has(e)||U(t,e,n,o,i)})),i.forEach(((t,e)=>{o.node(t).thread=e+1<i.length?i[e+1]:i[0]})),o}(t,e);return t.edges().forEach((e=>{const o=function(t,e,n){const o=t.node(e),i=t.node(n);if((o.depth??0)<(i.depth??0)){let e=o.thread;for(;void 0!==e&&(t.node(e).depth??0)>(o.depth??0);){if(e===n)return 1;e=t.node(e).thread}}else if((i.depth??0)<(o.depth??0)){let n=i.thread;for(;void 0!==n&&(t.node(n).depth??0)>(i.depth??0);){if(n===e)return-1;n=t.node(n).thread}}return 0}(n,e.v,e.w);if(o<0){const n=t.edge(e)||{};n.reversed=!0,t.removeEdge(e),t.setEdge(e.w,e.v,n)}})),t}function U(t,e,n,o,i,r=0){if(!n.has(e)){n.add(e),i.push(e),o.setNode(e,{depth:r});t.outEdges(e).map((t=>t.w)).forEach((s=>{n.has(s)||o.setEdge(e,s,{delta:1}),U(t,s,n,o,i,r+1)}))}}function Q(t,e){if(0===t.nodes().length)return;const n=function(t,e){const n=new V({directed:!0});let o=!1;for(const t of e)if("min"===t.type){o=!0;break}if(!o){const n=t.sources();e=n.length>0?[{nodes:[n[0]],type:"min"},...e]:[{nodes:[t.nodes()[0]],type:"min"},...e]}const i=new Map;let r=0;return e.forEach((t=>{if(!t.nodes||0===t.nodes.length)return;const e=""+r++;t.nodes.forEach((t=>{i.set(t,e)})),n.setNode(e,{nodes:t.nodes,type:t.type})})),t.nodes().forEach((t=>{if(!i.has(t)){const e=""+r++,o={nodes:[t],type:"same"};i.set(t,e),n.setNode(e,o)}})),t.edges().forEach((e=>{const o=i.get(e.v)??e.v,r=i.get(e.w)??e.w,s=t.node(e.v)||{},a=t.node(e.w)||{},d=n.edge(o,r)||{delta:0};o===r?(d.delta=0,n.setEdge(o,r,d)):"l"===s.direction?(d.delta=Math.max(d.delta??0,"l"===a.direction?1:0),n.setEdge(r,o,d)):(d.delta=Math.max(d.delta??0,"l"===a.direction?0:1),n.setEdge(o,r,d))})),n}(t,e);!function(t){t.sources().forEach((e=>{"0"!==e&&t.setEdge("0",e,{delta:0,temp:!0})}))}(n),K(n,"0"),function(t){var e;const n=t.sources(),o=new Set,i=new Set;for(t.edges().forEach((t=>{t.v===t.w&&i.add(X(t))}));n.length>0;){const r=n.shift();if(void 0===r)break;o.add(r);let s=t.node(r);s||t.setNode(r,s={}),s.rank=0;for(const n of t.inEdges(r)){const o=(null==(e=t.edge(n)||{})?void 0:e.delta)??1;s.rank=Math.max(s.rank,(t.node(n.v).rank??0)+o)}for(const e of t.outEdges(r))i.add(X(e));for(const e of t.nodes())n.indexOf(e)<0&&!o.has(e)&&!t.inEdges(e).some((t=>!i.has(X(t))))&&n.push(e)}}(n),function(t){function e(e){const n=t.node(e),o=Math.min(...t.outEdges(e).map((e=>(t.node(e.w).rank??0)-(t.edge(e).delta??0))));void 0!==o&&(n.rank=o)}t.edges().forEach((n=>{t.edge(n).temp&&e(n.w)}))}(n),t.nodes().forEach((e=>{t.node(e)||t.setNode(e,{})})),n.nodes().forEach((e=>{var o;const i=n.node(e);null==(o=i.nodes)||o.forEach((e=>{t.node(e).rank=i.rank}))}))}function J(t){const e=H(),n=M(t);let o=[],i=[],r=null;function s(s=[],a=[],d={}){const l=function(t=[],e=[]){const n=new V({directed:!0,multigraph:!0});return e.forEach((t=>{n.setEdge(t.source,t.target,{data:t,points:[]},t.type)})),n.nodes().forEach((t=>n.setNode(t,{data:{}}))),t.forEach((t=>{n.hasNode(t.id)&&(n.node(t.id).data=t,void 0!==t.direction&&(n.node(t.id).direction=t.direction))})),n.edges().forEach((t=>{n.edge(t).source=n.node(t.v),n.edge(t).target=n.node(t.w)})),n}(a,s);var h;return d.order?(Q(l,d.rankSets||[]),r=d.order,r.length>0&&r[0].length>0&&!Array.isArray(r[0][0])&&(r=r.map((t=>[t]))),r=r.map((t=>t.map((t=>t.filter((t=>void 0!==l.node(t)))))))):(Q(l,d.rankSets||[]),(h=l).edges().forEach((t=>{const e=h.node(t.v),n=h.node(t.w),o=h.edge(t);let i=e.rank;const r=[];if(void 0!==i&&void 0!==n.rank&&i+1<=n.rank){for("l"===e.direction&&r.push(i);++i<n.rank;)r.push(i);"l"===n.direction&&r.push(i),B(h,t,o,r,"r")}else if(void 0!==i&&void 0!==n.rank&&i>n.rank){for("l"!==e.direction&&r.push(i);i-- >n.rank+1;)r.push(i);"l"!==n.direction&&r.push(i),B(h,t,o,r,"l")}})),r=function(t,e=25){const n=R(t);let o=n,i=q(t,n),r=0;for(;r++<e;){O(t,n,r%2==0?1:0),N(t,n);const e=q(t,n);if(e<i&&(o=D(n),i=e),0===i)break}return o.map((t=>[t]))}(l)),o=e(l,r,t.edgeGap||0),function(t,{alignLinkTypes:e=!1}={}){t.nodes().forEach((e=>{const n=t.node(e);n.incoming=t.inEdges(e),n.outgoing=t.outEdges(e)}))}(l,{alignLinkTypes:d.alignLinkTypes||!1}),i=n(l),function(t){t.nodes().filter((t=>t.startsWith("__"))).forEach((e=>{var n;let o=t.node(e);if(!o)return;let i=(null==(n=t.inEdges(e))?void 0:n.map((e=>t.edge(e))))||[];i.forEach((e=>{e.origLabel&&e.origEdge&&(e.origLabel.dy=e.dy,e.origLabel.x0=e.x0,e.origLabel.y0=e.y0,e.origLabel.r0=e.r0,e.origLabel.d0=e.d0,e.origLabel.value=e.value,t.setEdge(e.origEdge,e.origLabel))}));let r,s=i.map((t=>t.r1));for(;o.dummy;)i=t.outEdges(e).map((e=>t.edge(e))),i.forEach(((t,e)=>{t.origLabel&&(t.origLabel.points||(t.origLabel.points=[]),t.origLabel.points.push({d:t.d0,r0:t.r0,r1:s[e],x:o.x,y:t.y0}))})),s=i.map((t=>t.r1)),r=t.successors(e)[0],t.removeNode(e),o=t.node(e=r);i.forEach((t=>{t.origLabel&&(t.origLabel.x1=t.x1,t.origLabel.y1=t.y1,t.origLabel.r1=t.r1,t.origLabel.d1=t.d1)}))}))}(l),function(t){t.edges().forEach((e=>{const n=t.edge(e);n.points||(n.points=[]),n.points.unshift({d:n.d0,ro:n.r0,x:n.x0,y:n.y0}),n.points.push({d:n.d1,ri:n.r1,x:n.x1,y:n.y1})}))}(l),l}return void 0!==t.whitespace&&e.whitespace(t.whitespace),s.nodes=function(){return o},s.links=function(){return i},s.order=function(){return r},s.size=function(t){return arguments.length?(e.size(t),s):e.size()},s.separation=function(t){return arguments.length?(e.separation(t),s):e.separation()},s.whitespace=function(t){return arguments.length?(e.whitespace(t),s):e.whitespace()},s.edgeValue=function(t){return s},s.scale=function(t){return arguments.length?(e.scale(t),s):e.scale()},s}const tt=["#6b9ece","#e07b7b","#7dba8f","#b09ed1","#e0b678","#6dbaba","#d17da8","#b5b56d","#c49a6d","#8fa4b8","#c98aa0","#94bf7d","#e0a08a","#7b9eb5","#a988a8"],et=t=>0===t.dy?0:2;function nt(t){const e=Math.max(et(t),t.dy)/2;let{x0:n}=t,{x1:o}=t,{y0:i}=t,{y1:r}=t;o<n&&([n,o]=[o,n],[i,r]=[r,i]);const s=r>i?1:-1,a=function(t){const e=t.x1-t.x0,n=t.y1-t.y0;return[t.dy/2,(e*e+n*n)/Math.abs(4*n)]}(t),d=Math.max(a[0],Math.min(a[1],(o-n)/3));let l=Math.max(a[0],Math.min(a[1],t.r0||d)),h=Math.max(a[0],Math.min(a[1],t.r1||d));const c=o-n,u=r-i-s*(l+h),p=Math.sqrt(c*c+u*u),g=-s*Math.acos(Math.min(1,(l+h)/p)),f=Math.atan2(u,c);let m=Math.PI/2+s*(f+g),v=e*s*Math.sin(m),y=e*Math.cos(m),b=n+1*l*Math.sin(Math.abs(m)),x=o-1*h*Math.sin(Math.abs(m)),w=i+l*s*(1-Math.cos(m)),E=r-h*s*(1-Math.cos(m));function A(t,n){const o=t*(r-i)>0?1:0;let s=1*t*(r-i)>0?n+e:n-e;return 0===m&&(s=n),`A${s} ${s} ${Math.abs(m)} 0 ${o} `}return(Number.isNaN(m)||Math.abs(m)<.001)&&(m=0,l=0,h=0,b=n,x=o,w=i,E=r,v=0,y=e),`M${[n,i-e]} ${A(1,l)}${[b+v,w-y]} L${[x+v,E-y]} ${A(-1,h)}${[o,r-e]} L${[o,r+e]} ${A(1,h)}${[x-v,E+y]} L${[b-v,w+y]} ${A(-1,l)}${[n,i+e]} Z`}function ot(t){var e;if(1===(null==(e=t.points)?void 0:e.length))return function(t){if(!t.points)return null;const e=t.points[0],n=Math.max(et(t),t.dy??0)/2;return"down-right"===e.style?`M${[(e.x??0)-20,(e.y??0)-n]} L${[e.x??0,(e.y??0)-n]} L${[e.x??0,(e.y??0)+n]} L${[(e.x??0)-20,(e.y??0)+n]} Z`:"right-down"===e.style?`M${[e.x??0,(e.y??0)-n]} L${[(e.x??0)+20,(e.y??0)-n]} L${[(e.x??0)+20,(e.y??0)+n]} L${[e.x??0,(e.y??0)+n]} Z`:null}(t);if(!t.points)return null;let n,o="";for(let e=0;e<t.points.length-1;++e){const i=t.points[e],r=t.points[e+1];n={d0:i.d,d1:r.d,dy:t.dy??0,r0:i.ro,r1:r.ri,x0:i.x??0,x1:r.x??0,y0:i.y??0,y1:r.y??0},o+=nt(n)}return o}const it=(t,e)=>{const n=(null==t?void 0:t.title)??(null==t?void 0:t.id)??"";return e&&n.length>e?`${n.substr(0,15)}...`:n};function rt(t,{fontColor:e,maxRank:n,nodeWidth:o}){const{data:i}=t;if(!i)return null;const r=function(t,e){let n=!1,o=!1;return(t.rank??0)<e/2&&(o=!0,n=!1),{right:o,top:n}}(t,n),{x:s,y:a}=function(t,e,n){const o=e.top?-25:(t.dy??0)/2-10;let i;return i=e.top?e.right?4:-4:e.right?10+n/2:-n/2-10,{x:(t.x??0)+i,y:(t.y??0)+o}}(t,r,o);return function(t="",{fontColor:e="#666767",pointerEvents:n="all",textAnchor:o="start",x:i,y:r}={}){const s=new p;return s.font({fill:e}),s.tspan(t),void 0!==i&&void 0!==r&&s.move(i,r),s.attr({"pointer-events":n,"text-anchor":o}),s}(it(i,r.top?25:15),{fontColor:e,pointerEvents:"none",textAnchor:r.top?"middle":r.right?"start":"end",x:s,y:a})}function st(t,e,n){var o,i;const{dy:r,x:s,y:a}=t,{fontColor:d="#212121",fontSize:l="14px",fontFamily:u,fontWeight:p,nodeBorderColor:g,nodeBorderWidth:f,nodeWidth:m=0,onNodeClick:v,nodeTooltip:y}=n,b=new h({class:"node"}),x=function({borderColor:t="#caced0",color:e="#97cbe6",height:n=0,opacity:o=1,radius:i=0,width:r=0,x:s=0,y:a=0}={}){const d=new c;return d.attr({height:n,opacity:o,rx:i,ry:i,width:r,x:s,y:a}),d.fill(e),d.stroke({color:t,width:1}),d}({height:r,width:m,x:(s??0)-m/2,y:a});if(x.fill(null==(o=t.data)?void 0:o.color),x.stroke({color:g??(null==(i=t.data)?void 0:i.color),width:f}),x.on("click",(()=>{"function"==typeof v&&v(t)})),y){const{chartContext:e,nodeValue:n,tooltipBGColor:o,tooltipBorderColor:i,tooltipFontColor:r,tooltipId:s,nodeTooltipTemplate:a}=y,h=a({node:t.data,value:n});x.on("mouseover",(t=>{const{pageX:n,pageY:a}=t,c=C({bgColor:o,borderColor:i,fontColor:r||d,fontFamily:u??"",fontSize:l??"14px",fontWeight:p??"400",x:n,y:a});S(e,s,c,h)})),x.on("mousemove",(t=>{const{pageX:n,pageY:a}=t,c=C({bgColor:o,borderColor:i,fontColor:r||d,fontFamily:u??"",fontSize:l??"14px",fontWeight:p??"400",x:n,y:a});S(e,s,c,h)})),x.on("mouseout",(()=>{A(e,s).style.display="none"}))}if(b.add(x),t.data&&(r??0)>Number.parseInt(l,10)){const n=rt(t,{fontColor:d,maxRank:e,nodeWidth:m});n&&b.add(n)}return b}class at{constructor(t,e,n){this.element=t,this.options=e,this.chartContext=n,t.innerHTML="",this.canvas=function(){const t=document.createElementNS(a,"svg");return new m(t)}().addTo(t).size("100%","100%").viewbox(`-${this.spacing} -${this.spacing+this.getYShift()} ${this.width+2*this.spacing} ${this.height+this.spacing+this.getYShift()}`).attr({style:this.options.canvasStyle})}getYShift(){return this.options.enableToolbar?30:0}add(t){this.canvas.add(t)}clear(){this.canvas.clear().viewbox(`-${this.spacing} -${this.spacing+this.getYShift()} ${this.width+2*this.spacing} ${this.height+this.spacing+this.getYShift()}`)}exportToSvg(){new o(this.canvas,"apexsankey").exportToSVG()}resetViewBox(){this.canvas.viewbox(`-${this.spacing} -${this.spacing+this.getYShift()} ${this.width+2*this.spacing} ${this.height+this.spacing+this.getYShift()}`)}updateViewBox(t,e,n,o){this.canvas.viewbox(`${t} ${e} ${n} ${o}`)}get height(){return this.options.viewPortHeight}get spacing(){return this.options.spacing}get width(){return this.options.viewPortWidth}}class dt{constructor(t,e,n){this.svgRoot=t,this.graph=e,this.dimOpacity=n}highlightNode(t){const e=this.prefersReducedMotion(),n=[...this.graph.inEdges(t)??[],...this.graph.outEdges(t)??[]],o=new Set([t]);n.forEach((t=>{var e,n,i,r;const s=this.graph.edge(t.v,t.w,t.name),a=null==(n=null==(e=null==s?void 0:s.source)?void 0:e.data)?void 0:n.id,d=null==(r=null==(i=null==s?void 0:s.target)?void 0:i.data)?void 0:r.id;a&&o.add(a),d&&o.add(d)})),this.dimAll(e),n.forEach((t=>{const n=this.svgRoot.querySelector(`[data-edge-source="${t.v}"][data-edge-target="${t.w}"]`);n&&this.setOpacity(n,1,e)})),o.forEach((t=>{const n=this.svgRoot.querySelector(`[data-node-id="${t}"]`);n&&this.setOpacity(n,1,e)}))}highlightEdge(t,e){var n,o,i,r;const s=this.prefersReducedMotion(),a=this.graph.edge(t,e),d=(null==(o=null==(n=null==a?void 0:a.source)?void 0:n.data)?void 0:o.id)??t,l=(null==(r=null==(i=null==a?void 0:a.target)?void 0:i.data)?void 0:r.id)??e;this.dimAll(s),this.svgRoot.querySelectorAll(`[data-edge-source="${t}"][data-edge-target="${e}"]`).forEach((t=>this.setOpacity(t,1,s)));const h=this.svgRoot.querySelector(`[data-node-id="${d}"]`),c=this.svgRoot.querySelector(`[data-node-id="${l}"]`);h&&this.setOpacity(h,1,s),c&&this.setOpacity(c,1,s)}reset(){const t=this.prefersReducedMotion()?"none":"";this.svgRoot.querySelectorAll("[data-edge-source]").forEach((e=>{e.style.transition=t,e.style.opacity=""})),this.svgRoot.querySelectorAll("[data-node-id]").forEach((e=>{e.style.transition=t,e.style.opacity=""}))}dimAll(t){this.svgRoot.querySelectorAll("[data-edge-source]").forEach((e=>{this.setOpacity(e,this.dimOpacity,t)})),this.svgRoot.querySelectorAll("[data-node-id]").forEach((e=>{this.setOpacity(e,this.dimOpacity,t)}))}setOpacity(t,e,n){t.style.transition=n?"none":"opacity 0.2s ease",t.style.opacity=String(e)}prefersReducedMotion(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}}function lt(t,e){const n=e=>function(t,e){return getComputedStyle(t).getPropertyValue(e).trim()}(t,e),o=n("--apex-sankey-edge-opacity"),i=""!==o?Number(o):e.edgeOpacity,r=n("--apex-sankey-node-width"),s=""!==r?Number(r):e.nodeWidth,a=n("--apex-sankey-node-border-width"),d=""!==a?Number(a):e.nodeBorderWidth,l=n("--apex-sankey-edge-gradient"),h=""!==l?"true"===l:e.edgeGradientFill,c=n("--apex-sankey-node-border-color")||e.nodeBorderColor,u=n("--apex-sankey-tooltip-bg")||e.tooltipBGColor,p=n("--apex-sankey-tooltip-border-color")||e.tooltipBorderColor,g=n("--apex-sankey-tooltip-font-color")||e.tooltipFontColor,f=n("--apex-sankey-tooltip-theme"),m="dark"===f||"light"===f?f:e.tooltipTheme;return{...e,edgeGradientFill:h,edgeOpacity:Number.isFinite(i)?i:e.edgeOpacity,fontColor:n("--apex-sankey-label-color")||e.fontColor,fontSize:n("--apex-sankey-label-font-size")||e.fontSize,fontFamily:n("--apex-sankey-font-family")||e.fontFamily,nodeBorderColor:c,nodeBorderWidth:Number.isFinite(d)?d:e.nodeBorderWidth,nodeWidth:Number.isFinite(s)?s:e.nodeWidth,tooltipBGColor:u,tooltipBorderColor:p,tooltipFontColor:g,tooltipTheme:m}}const ht="#005FCC",ct="role",ut="aria-label",pt="data-node-id",gt="data-orig-stroke",ft="data-orig-stroke-width",mt="stroke",vt="stroke-width",yt="forced-colors",bt="apexsankey-desc",xt="data-edge-target";const wt="apexsankey-a11y-styles";class Et{constructor(t,e,n={},o,i){this.svgEl=t,this.graph=e,this.options=n,this.tooltipId=o,this.pathHighlighter=i,this.nodeGroups=[],this.edgePaths=[],this.nodeOutEdges=new Map,this.edgeSourceNode=new Map,this.mediaQuery=null,this.forcedColorsHandler=null,this.isKeyboardUser=!1}apply(){!1!==this.options.enabled&&(this.injectAriaAttributes(),this.setupKeyboardNavigation(),function(){if(document.getElementById(wt))return;const t=document.createElement("style");t.id=wt,t.textContent=`\n /* ApexSankey: keyboard focus ring */\n .node:focus,\n svg path[data-edge-source]:focus { outline: none; }\n .node:focus-visible rect {\n stroke: ${ht};\n stroke-width: 2;\n }\n\n /* High-contrast (Windows Forced Colors) */\n @media (forced-colors: active) {\n .node rect {\n fill: ButtonFace;\n stroke: ButtonText;\n }\n .node text {\n fill: ButtonText;\n }\n .node:focus-visible rect {\n stroke: Highlight;\n stroke-width: 2;\n }\n }\n\n /* Reduced motion */\n @media (prefers-reduced-motion: reduce) {\n .node rect,\n svg path {\n transition: none !important;\n animation: none !important;\n }\n }\n `,document.head.appendChild(t)}(),this.setupHighContrastMode())}destroy(){this.mediaQuery&&this.forcedColorsHandler&&(this.mediaQuery.removeEventListener("change",this.forcedColorsHandler),this.mediaQuery=null,this.forcedColorsHandler=null)}injectAriaAttributes(){const{svgEl:t,graph:e,options:n}=this,o=e.nodes().filter((t=>!e.node(t).dummy)),i=e.edges(),r=function(t,e,n,o){var i,r,s,a;if(o)return o;let d=0,l="",h="";for(const e of n)try{const n=t.edge(e.v,e.w,e.name).value??0;if(n>d){const o=t.node(e.v),c=t.node(e.w);o.dummy||c.dummy||(d=n,l=(null==(i=o.data)?void 0:i.title)??(null==(r=o.data)?void 0:r.id)??e.v,h=(null==(s=c.data)?void 0:s.title)??(null==(a=c.data)?void 0:a.id)??e.w)}}catch{}let c=`Sankey flow diagram: ${e.length} nodes, ${n.length} flows.`;return l&&h&&(c+=` Largest flow: ${l} (${d} units) to ${h}.`),c}(e,o,i,n.diagramLabel);t.setAttribute(ct,"img"),t.setAttribute(ut,r),t.removeAttribute("aria-labelledby");const s=t.querySelector("title");if(s&&s.remove(),n.description){let e=t.querySelector("desc");if(!e){const n=document.createElementNS("http://www.w3.org/2000/svg","desc");n.id=bt,t.insertBefore(n,t.firstChild),e=n}e.textContent=n.description,t.setAttribute("aria-describedby",bt)}const a=Array.from(t.querySelectorAll(`[${pt}]`));a.forEach((t=>{const n=t.getAttribute(pt);n&&(t.setAttribute(ct,"listitem"),t.setAttribute(ut,function(t,e){var n,o,i,r,s,a;const d=e.node(t),l=(null==(n=d.data)?void 0:n.title)??(null==(o=d.data)?void 0:o.id)??t,h=[];let c=0;for(const n of e.inEdges(t))try{const t=e.edge(n.v,n.w,n.name),o=e.node(n.v);o.dummy||(h.push((null==(i=o.data)?void 0:i.title)??(null==(r=o.data)?void 0:r.id)??n.v),c+=t.value??0)}catch{}const u=[];let p=0;for(const n of e.outEdges(t))try{const t=e.edge(n.v,n.w,n.name),o=e.node(n.w);o.dummy||(u.push((null==(s=o.data)?void 0:s.title)??(null==(a=o.data)?void 0:a.id)??n.w),p+=t.value??0)}catch{}let g=l;h.length>0&&(g+=`: receives ${c} units from ${h.join(", ")}`),u.length>0&&(g+=`${h.length>0?"; ":": "}flows ${p} units to ${u.join(", ")}`);return g}(n,e)),t.setAttribute("tabindex","0"))})),this.nodeGroups=a;const d=[],l=new Map,h=new Map;t.querySelectorAll("[data-edge-source]").forEach((t=>{var n,o,i,r;const s=t.getAttribute("data-edge-source"),a=t.getAttribute("data-edge-target"),c=t.getAttribute("data-edge-name")??void 0;if(s&&a)try{const u=e.edge(s,a,c),p=u.source,g=u.target;if(!p||!g)return;const f=(null==(n=p.data)?void 0:n.title)??(null==(o=p.data)?void 0:o.id)??s,m=(null==(i=g.data)?void 0:i.title)??(null==(r=g.data)?void 0:r.id)??a,v=u.value??0;t.setAttribute("role","img"),t.setAttribute("aria-label",`Flow from ${f} to ${m}: ${v} units`),t.setAttribute("focusable","true"),t.setAttribute("tabindex","-1"),d.push(t),h.set(t,s),l.has(s)||l.set(s,[]);const y=l.get(s);y&&y.push(t)}catch{}})),this.edgePaths=d,this.nodeOutEdges=l,this.edgeSourceNode=h}setupKeyboardNavigation(){this.svgEl.addEventListener("pointerdown",(()=>{this.isKeyboardUser=!1})),this.svgEl.addEventListener("keydown",(()=>{this.isKeyboardUser=!0})),this.nodeGroups.forEach(((t,e)=>{t.addEventListener("keydown",(n=>{const o=n.key;if("Enter"===o||" "===o){n.preventDefault();const e=t.querySelector("rect");e&&e.dispatchEvent(new MouseEvent("click",{bubbles:!0}))}else if("Escape"===o)n.preventDefault(),this.restoreFocusRing(t),t.blur(),this.hideTooltip();else if("ArrowRight"===o||"ArrowDown"===o){n.preventDefault();const o=t.getAttribute(pt),i=o?this.nodeOutEdges.get(o)??[]:[];if(i.length>0)i[0].focus();else{this.nodeGroups[(e+1)%this.nodeGroups.length].focus()}}else if("ArrowLeft"===o||"ArrowUp"===o){n.preventDefault();this.nodeGroups[(e-1+this.nodeGroups.length)%this.nodeGroups.length].focus()}})),t.addEventListener("focus",(()=>{var e;if(this.isKeyboardUser){this.applyFocusRing(t);const n=t.getAttribute(pt);n&&(null==(e=this.pathHighlighter)||e.highlightNode(n))}if(this.tooltipId){const e=t.querySelector("rect");if(e){const t=e.getBoundingClientRect();e.dispatchEvent(new MouseEvent("mouseover",{clientX:t.left+t.width/2,clientY:t.top,bubbles:!0}))}}})),t.addEventListener("blur",(()=>{var e;this.restoreFocusRing(t),null==(e=this.pathHighlighter)||e.reset(),this.hideTooltip()}))}));for(const t of this.edgePaths){const e=()=>{const e=this.edgeSourceNode.get(t);return e?this.nodeOutEdges.get(e)??[]:[]},n=()=>{const e=this.edgeSourceNode.get(t),n=e?this.nodeGroups.find((t=>t.getAttribute(pt)===e)):void 0;n&&n.focus()};t.addEventListener("keydown",(o=>{const i=o.key;if("Enter"===i||" "===i)o.preventDefault(),t.dispatchEvent(new MouseEvent("click",{bubbles:!0}));else if("Escape"===i||"ArrowLeft"===i)o.preventDefault(),n();else if("ArrowDown"===i){o.preventDefault();const n=e(),i=n.indexOf(t);n[(i+1)%n.length].focus()}else if("ArrowUp"===i){o.preventDefault();const n=e(),i=n.indexOf(t);n[(i-1+n.length)%n.length].focus()}else if("ArrowRight"===i){o.preventDefault();const e=t.getAttribute(xt),n=e?this.nodeGroups.find((t=>t.getAttribute(pt)===e)):void 0;n&&n.focus()}else if("Tab"===i){const e=this.edgeSourceNode.get(t),n=this.nodeGroups.findIndex((t=>t.getAttribute(pt)===e));if(-1!==n){const t=o.shiftKey?(n-1+this.nodeGroups.length)%this.nodeGroups.length:(n+1)%this.nodeGroups.length;o.preventDefault(),this.nodeGroups[t].focus()}}})),t.addEventListener("focus",(()=>{var e;if(this.isKeyboardUser){const n=t.getAttribute("data-edge-source"),o=t.getAttribute(xt);n&&o&&(null==(e=this.pathHighlighter)||e.highlightEdge(n,o))}if(this.tooltipId){const e=t.getBoundingClientRect();t.dispatchEvent(new MouseEvent("mouseover",{clientX:e.left+e.width/2,clientY:e.top+e.height/2,bubbles:!0}))}})),t.addEventListener("blur",(t=>{var e;const n=t.relatedTarget;n&&this.edgePaths.includes(n)||(null==(e=this.pathHighlighter)||e.reset(),this.hideTooltip())}))}}hideTooltip(){if(this.tooltipId){const t=document.getElementById(this.tooltipId);t&&(t.style.display="none")}}applyFocusRing(t){const e=t.querySelector("rect");e&&(e.setAttribute(gt,e.getAttribute(mt)??""),e.setAttribute(ft,e.getAttribute(vt)??""),e.setAttribute(mt,ht),e.setAttribute(vt,"2"))}restoreFocusRing(t){const e=t.querySelector("rect");if(!e)return;const n=e.getAttribute(gt),o=e.getAttribute(ft);null!==n&&(e.setAttribute(mt,n),e.removeAttribute(gt)),null!==o&&(e.setAttribute(vt,o),e.removeAttribute(ft))}setupHighContrastMode(){if("undefined"!=typeof window&&"function"==typeof window.matchMedia)try{const t=window.matchMedia("(forced-colors: active)");this.mediaQuery=t,t.matches&&this.svgEl.classList.add(yt),this.forcedColorsHandler=t=>{t.matches?this.svgEl.classList.add(yt):this.svgEl.classList.remove(yt)},t.addEventListener("change",this.forcedColorsHandler)}catch{}}}const At="http://www.w3.org/2000/svg";class St extends at{constructor(t,e,n){super(t,e,n),this.a11yHelper=null,this.pathHighlighter=null,this._hasAnimated=!1,this.renderOptions=e}construct(t){const{edgeGap:e,nodeWidth:n,spacing:o,viewPortHeight:i,viewPortWidth:r,whitespace:s}=this.options,a=J({edgeGap:e,nodeWidth:n,whitespace:s});a.size([r-n,i-o]);const d=t.nodes.map(((t,e)=>{const n=e%tt.length;return{...t,color:t.color??tt[n],colorIndex:n}})),l=a(t.edges,d);this.maxRank=(a.order()??[]).length-1,this.graph=l}render({keepOldPosition:t=!1}={}){var e,n;this.renderOptions=lt(this.element,this.options);const{tooltipTheme:o,tooltipBGColor:i,tooltipBorderColor:r,tooltipFontColor:s}=this.renderOptions;"dark"===o?this.renderOptions={...this.renderOptions,tooltipBGColor:"#1e2433",tooltipBorderColor:"#374151",tooltipFontColor:"#e5e7eb"}:"light"===o&&(this.renderOptions={...this.renderOptions,tooltipBGColor:i,tooltipBorderColor:r,tooltipFontColor:s});const{enableTooltip:a,fontColor:d,fontFamily:l,fontSize:h,fontWeight:c,highlightConnectedPath:u,dimOpacity:p,nodeBorderColor:g,nodeBorderWidth:f,nodeWidth:m,nodeTooltipTemplate:y,onNodeClick:b,tooltipBGColor:x,tooltipBorderColor:w,tooltipFontColor:E,tooltipId:S}=this.renderOptions,C=this.canvas.viewbox();this.clear(),this.pathHighlighter=u?new dt(this.canvas.node,this.graph,p):null;const k=((t={})=>{const e=[];for(const o in t){const i=`${n=o,n.replace(/([A-Z])/g,(t=>`-${t.toLowerCase()}`))}: ${t[o]};`;e.push(i)}var n;return e.join(" ")})({color:d,fontFamily:l,fontSize:h,fontWeight:c}),$=v(m/2,0);$.attr("style",k);const M=(null==(e=this.graph)?void 0:e.nodes())||[],L=(null==(n=this.graph)?void 0:n.edges())||[],_=v();L.forEach((t=>{this.renderEdge(t,_)})),$.add(_);const B=v();B.node.setAttribute("role","list"),B.node.setAttribute("aria-label","Sankey nodes"),M.forEach((t=>{const e=this.graph.node(t);if(e.dummy)return;let n;if(a&&y){const e=this.graph.inEdges(t)??[],o=this.graph.outEdges(t)??[],i=e.reduce(((t,e)=>{var n;return t+((null==(n=this.graph.edge(e.v,e.w,e.name))?void 0:n.value)??0)}),0),r=o.reduce(((t,e)=>{var n;return t+((null==(n=this.graph.edge(e.v,e.w,e.name))?void 0:n.value)??0)}),0),s=Math.max(i,r);n={chartContext:this.chartContext,nodeTooltipTemplate:y,nodeValue:s,tooltipBGColor:x,tooltipBorderColor:w,tooltipFontColor:E,tooltipId:S}}const o=st(e,this.maxRank,{fontColor:d,fontFamily:l,fontSize:h,fontWeight:c,nodeBorderColor:g,nodeBorderWidth:f,nodeWidth:m,nodeTooltip:n,onNodeClick:b});if(o.node.setAttribute("data-node-id",t),o.node.setAttribute("data-node-rank",String(e.rank??0)),this.pathHighlighter){const e=this.pathHighlighter;o.node.addEventListener("mouseenter",(()=>e.highlightNode(t))),o.node.addEventListener("mouseleave",(()=>e.reset()))}B.add(o)})),$.add(B),this.add($);const{animation:T}=this.renderOptions;if((null==T?void 0:T.enabled)&&!this._hasAnimated&&(this._hasAnimated=!0,function(t,e,n,o,i){if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;const r=t.viewBox.baseVal,s=r.width,a=r.x,d=t.querySelector("defs")??(()=>{const e=document.createElementNS(At,"defs");return t.insertBefore(e,t.firstChild),e})(),l=`sankey-flow-clip-${Math.random().toString(36).slice(2,9)}`,h=document.createElementNS(At,"clipPath");h.setAttribute("id",l);const c=document.createElementNS(At,"rect");c.setAttribute("x",String(a)),c.setAttribute("y","-9999"),c.setAttribute("height","99999"),c.setAttribute("width","0"),h.appendChild(c),d.appendChild(h),e.setAttribute("clip-path",`url(#${l})`);let u=null;requestAnimationFrame((function t(n){null===u&&(u=n);const o=n-u,r=Math.min(o/i,1),a=((d=r)<.5?2*d*d:(4-2*d)*d-1)*s;var d;c.setAttribute("width",String(a)),r<1?requestAnimationFrame(t):(e.removeAttribute("clip-path"),h.remove())}));const p=n.querySelectorAll("[data-node-rank]"),g=.1*i,f=.7*i-g,m=.45*i;p.forEach((t=>{const e=parseInt(t.getAttribute("data-node-rank")??"0",10),n=g+(o>0?e/o:0)*f;t.style.opacity="0",t.animate([{opacity:"0",transform:"translateY(6px)"},{opacity:"1",transform:"translateY(0px)"}],{duration:m,delay:n,easing:"cubic-bezier(0.4, 0, 0.2, 1)",fill:"forwards"}).onfinish=()=>{t.style.opacity="",t.style.transform=""}}))}(this.canvas.node,_.node,B.node,this.maxRank,T.duration)),t&&this.updateViewBox(C.x,C.y,C.width,C.height),a){const t=A(this.chartContext,S);this.chartContext.getAppendContainer().appendChild(t)}this.a11yHelper&&this.a11yHelper.destroy();const R=this.renderOptions.a11y;!1!==(null==R?void 0:R.enabled)&&(this.a11yHelper=new Et(this.canvas.node,this.graph,R,S,this.pathHighlighter),this.a11yHelper.apply())}renderEdge(t,e){const{edgeGradientFill:n,edgeOpacity:o,enableTooltip:i,fontFamily:r,fontSize:s,fontWeight:a,nodeWidth:d,tooltipBGColor:l,tooltipBorderColor:h,tooltipFontColor:c,tooltipId:p,tooltipTemplate:g}=this.renderOptions,f=this.graph.edge(t.v,t.w,t.name),m=this.graph.node(t.v),v=this.graph.node(t.w),y=f.source,b=f.target;if(!y||!b)return;m.dummy&&(f.x0=(f.x0??0)-d/2),v.dummy&&(f.x1=(f.x1??0)+d/2);const x=ot(f);if(!x)return;const w=function(t,{edgeColor:e,id:n="",opacity:o=1}={}){const i=new u({d:t});return i.id(n),i.fill(e).opacity(o),i}(x,{edgeColor:this.canvas.gradient("linear",(t=>{var e,o,i;t.stop(0,(null==(e=y.data)?void 0:e.color)??""),t.stop(1,n?(null==(o=b.data)?void 0:o.color)??"":(null==(i=y.data)?void 0:i.color)??"")})),id:`${t.v}-${t.w}`,opacity:o});if(w.node.setAttribute("data-edge-source",t.v),w.node.setAttribute("data-edge-target",t.w),void 0!==t.name&&w.node.setAttribute("data-edge-name",t.name),this.pathHighlighter){const e=this.pathHighlighter,n=t.v,o=t.w;w.on("mouseenter",(()=>e.highlightEdge(n,o))),w.on("mouseleave",(()=>e.reset()))}if(i&&y.data&&b.data){const t=g?g({source:y.data,target:b.data,value:f.value}):`${y.data.title} → ${b.data.title}: ${f.value}`;w.on("mouseover",(e=>{const{pageX:n,pageY:o}=e,i=C({bgColor:l,borderColor:h,fontColor:c,fontFamily:r,fontSize:s,fontWeight:a,x:n,y:o});S(this.chartContext,p,i,t)})),w.on("mousemove",(e=>{const{pageX:n,pageY:o}=e,i=C({bgColor:l,borderColor:h,fontColor:c,fontFamily:r,fontSize:s,fontWeight:a,x:n,y:o});S(this.chartContext,p,i,t)})),w.on("mouseout",(()=>{A(this.chartContext,p).style.display="none"}))}e.add(w)}}const Ct={canvasStyle:"border: 1px solid #caced0; box-sizing: border-box",edgeGap:2,edgeGradientFill:!0,edgeOpacity:.4,enableToolbar:!0,enableTooltip:!0,fontColor:"#212121",fontFamily:"",fontSize:"14px",fontWeight:"400",height:"auto",nodeBorderColor:null,nodeBorderWidth:1,nodeWidth:20,onNodeClick:void 0,spacing:20,tooltipBGColor:"#FFFFFF",tooltipBorderColor:"#E2E8F0",tooltipFontColor:"#1a1a1a",tooltipId:"apexsankey-tooltip-container",tooltipTemplate:({source:t,target:e,value:n})=>`\n <div style='display:flex;align-items:center;gap:6px;padding:7px 10px;'>\n <div style='width:10px;height:10px;border-radius:2px;background-color:${null==t?void 0:t.color};flex-shrink:0;'></div>\n <span style='font-weight:500;'>${null==t?void 0:t.title}</span>\n <svg width='14' height='14' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg' style='opacity:0.5;flex-shrink:0;'><path d='M5 12h14M13 6l6 6-6 6' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>\n <div style='width:10px;height:10px;border-radius:2px;background-color:${null==e?void 0:e.color};flex-shrink:0;'></div>\n <span style='font-weight:500;'>${null==e?void 0:e.title}</span>\n <span style='opacity:0.6;margin-left:2px;'>·</span>\n <span style='font-weight:600;'>${n}</span>\n </div>\n `,nodeTooltipTemplate:({node:t,value:e})=>`\n <div style='display:flex;align-items:center;gap:6px;padding:7px 10px;'>\n <div style='width:10px;height:10px;border-radius:2px;background-color:${null==t?void 0:t.color};flex-shrink:0;'></div>\n <span style='font-weight:500;'>${null==t?void 0:t.title}</span>\n <span style='opacity:0.6;'>·</span>\n <span style='font-weight:600;'>${e}</span>\n </div>\n `,viewPortHeight:500,viewPortWidth:800,whitespace:.18,width:"100%",highlightConnectedPath:!0,dimOpacity:.2,animation:{enabled:!0,duration:800},a11y:{enabled:!0}};class kt extends n{constructor(t,e={}){super(t,"sankey_"+crypto.randomUUID().replace(/-/g,"").substring(0,9)),this.options={...Ct,...e};const{height:n,width:o}=this.options;this.graph=new St(this.element,this.options,this.chartContext),this.setupElementDimensions(o,n),this.handleWatermark()}static setLicense(t){s.setLicense(t)}setupElementDimensions(t,e){let n=!1,o=0;"string"==typeof t&&/^\d+(\.\d+)?%$/.test(t)?(o=Number(t.substring(0,t.length-1)),n=!0):o=Number(t);const i="auto"===e?o/1.6:e;this.element.style.width=`${o}${n?"%":"px"}`,this.element.style.height=`${i}${n?"%":"px"}`,this.element.style.position="relative"}handleWatermark(){this.element&&(s.isLicenseValid()?w.remove(this.element):w.add(this.element))}render(t){if(!this.element)throw new Error("Element not found");if(this.graph.construct(t),this.graph.render(),this.options.enableToolbar){new b(this.element,this.chartContext).render({enableExport:!0,onExport:this.graph.exportToSvg.bind(this.graph)})}return this.graph}}"undefined"!=typeof window&&(window.ApexSankey=kt);export{kt as ApexSankey,kt as default};
1
+ const t=()=>{};class e{constructor(t,e){this.injectedStyles=new Set,this.trackedTooltips=new Set,this.instanceId=e||Math.random().toString(36).substr(2,9),this.context=this.detectContext(t),this.chartContainer=t}getChartContainer(){return this.chartContainer}getChartScopedContainer(){return this.context===document?document.body||document.getElementsByTagName("body")[0]:this.chartContainer||this.context}detectContext(t){const e=t.getRootNode();return e instanceof ShadowRoot?e:document}getContext(){return this.context}getInstanceId(){return this.instanceId}isShadowDOM(){return this.context instanceof ShadowRoot}createElement(t){return document.createElement(t)}createElementNS(t,e){return document.createElementNS(t,e)}createTextNode(t){return document.createTextNode(t)}getElementById(t){return this.context===document?document.getElementById(t):this.context.querySelector(`#${t}`)}getElementsByClassName(t){if(this.context===document)return document.getElementsByClassName(t);const e=this.context.querySelectorAll(`.${t}`),o=Array.from(e);return{item:t=>o[t]||null,get length(){return o.length},[Symbol.iterator]:()=>o[Symbol.iterator](),...Object.fromEntries(o.map(((t,e)=>[e,t])))}}querySelector(t){return this.context.querySelector(t)}querySelectorAll(t){return this.context.querySelectorAll(t)}getAppendContainer(){return this.context===document?document.body||document.getElementsByTagName("body")[0]:this.context}getChartBounds(){var t;return(null==(t=this.chartContainer)?void 0:t.getBoundingClientRect())||new DOMRect}getBody(){if(this.context===document)return document.body||document.getElementsByTagName("body")[0];return this.context.host}dispatchEvent(t){this.context===document?document.dispatchEvent(t):this.context.dispatchEvent(t)}addEventListener(t,e,o){this.context===document||"mousemove"===t||"mouseup"===t||"keydown"===t?document.addEventListener(t,e,o):this.context.addEventListener(t,e,o)}removeEventListener(t,e,o){this.context===document||"mousemove"===t||"mouseup"===t||"keydown"===t?document.removeEventListener(t,e,o):this.context.removeEventListener(t,e,o)}injectStyles(t,e,o={}){const{force:n=!1,priority:i="normal"}=o;if(!n&&this.injectedStyles.has(e))return;if(n){const t=this.context.querySelector(`#${e}`);t&&(t.remove(),this.injectedStyles.delete(e))}if(this.context.querySelector(`#${e}`)&&!n)return void this.injectedStyles.add(e);const r=document.createElement("style");if(r.id=e,r.textContent=t,"normal"!==i&&r.setAttribute("data-priority",i),this.context===document)document.head.appendChild(r);else{const t=this.context;"high"===i?t.insertBefore(r,t.firstChild):t.appendChild(r)}this.injectedStyles.add(e)}injectStylesheets(t){t.forEach((({content:t,id:e,options:o})=>{this.injectStyles(t,e,o)}))}hasInjectedStyles(t){return this.injectedStyles.has(t)}removeStyles(t){const e=this.context.querySelector(`#${t}`);e&&(e.remove(),this.injectedStyles.delete(t))}removeAllStyles(){this.injectedStyles.forEach((t=>{const e=this.context.querySelector(`#${t}`);e&&e.remove()})),this.injectedStyles.clear()}getInjectedStyleIds(){return Array.from(this.injectedStyles)}getActiveElement(){if(this.context===document)return document.activeElement;return this.context.activeElement||document.activeElement}trackTooltip(t){this.trackedTooltips.add(t)}destroy(){this.removeAllStyles(),this.injectedStyles.clear(),this.trackedTooltips.forEach((t=>t.remove())),this.trackedTooltips.clear()}}class o{constructor(t,o){if(!t)throw new Error("Container element is required");this.element=t,this.chartContext=new e(t,o)}getContext(){return this.chartContext}isShadowDOM(){return this.chartContext.isShadowDOM()}getTooltipContainer(){return this.chartContext.getAppendContainer()}injectStyles(t,e){this.chartContext.injectStyles(t,e)}createElement(t){return this.chartContext.createElement(t)}querySelector(t){return this.chartContext.querySelector(t)}addEventListener(t,e,o){this.chartContext.addEventListener(t,e,o)}removeEventListener(t,e,o){this.chartContext.removeEventListener(t,e,o)}dispatchEvent(t){this.chartContext.dispatchEvent(t)}destroy(){this.chartContext.destroy()}getInstanceId(){return this.chartContext.getInstanceId()}}class n{constructor(t,e="apex"){this.canvas=t,this.prefix=e}getSvgString(){const t=this.canvas.node.cloneNode(!0),e=this.canvas.node.viewBox.baseVal;e.width&&e.height&&(t.setAttribute("width",String(e.width)),t.setAttribute("height",String(e.height)));return(new XMLSerializer).serializeToString(t)}svgUrl(){const t=this.getSvgString(),e=new Blob([t],{type:"image/svg+xml;charset=utf-8"});return URL.createObjectURL(e)}triggerDownload(t,e){const o=document.createElement("a");o.href=t,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o)}exportToSVG(){this.triggerDownload(this.svgUrl(),`${this.prefix}-${(new Date).getTime()}.svg`)}}const i="http://www.w3.org/2000/svg";let r=0;class s{constructor(t){this.node=t}attr(t,e){if("string"==typeof t)return void 0!==e?(this.node.setAttribute(t,String(e)),this):this.node.getAttribute(t);for(const[e,o]of Object.entries(t))null!=o&&this.node.setAttribute(e,String(o));return this}id(t){return this.node.setAttribute("id",t),this}fill(t){if(!t)return this;if(t instanceof SVGElement){const e=t.id;this.node.setAttribute("fill",`url(#${e})`)}else this.node.setAttribute("fill",t);return this}stroke({color:t,width:e,dasharray:o}={}){return void 0!==t&&this.node.setAttribute("stroke",t),void 0!==e&&this.node.setAttribute("stroke-width",String(e)),void 0!==o&&this.node.setAttribute("stroke-dasharray",String(o)),this}opacity(t){return this.node.setAttribute("opacity",String(t)),this}add(t){const e=t instanceof s?t.node:t;return this.node.appendChild(e),this}on(t,e){return this.node.addEventListener(t,e),this}findOne(t){const e=this.node.querySelector(t);return e?new s(e):null}first(){const t=this.node.firstElementChild;return t?new s(t):null}}class a extends s{constructor(t){super(document.createElementNS(i,"g")),t&&this.attr(t)}}class d extends s{constructor(){super(document.createElementNS(i,"rect"))}}class l extends s{constructor(t){super(document.createElementNS(i,"path")),t&&this.attr(t)}}class c extends s{constructor(){super(document.createElementNS(i,"text"))}font({fill:t,size:e}){return void 0!==t&&this.node.setAttribute("fill",t),void 0!==e&&this.node.setAttribute("font-size",String(e)),this}tspan(t){const e=document.createElementNS(i,"tspan");return e.textContent=t,this.node.appendChild(e),this}move(t,e){return this.node.setAttribute("x",String(t)),this.node.setAttribute("y",String(e)),this}}class h{constructor(t){this.gradient=t}stop(t,e){const o=document.createElementNS(i,"stop");o.setAttribute("offset",String(t)),o.setAttribute("stop-color",e??"transparent"),this.gradient.appendChild(o)}}function u(t,e){t.setAttribute("viewBox",`${e.x} ${e.y} ${e.w} ${e.h}`)}class p{constructor(t){this._defs=null,this._panZoomState=null,this.node=t}addTo(t){return t.appendChild(this.node),this}size(t,e){return this.node.setAttribute("width",String(t)),this.node.setAttribute("height",String(e)),this}viewbox(t){if(void 0===t){const t=this.node.viewBox.baseVal;return{x:t.x,y:t.y,width:t.width,height:t.height}}if(this.node.setAttribute("viewBox",t),this._panZoomState){const t=this.node.viewBox.baseVal;this._panZoomState.vb={x:t.x,y:t.y,w:t.width,h:t.height}}return this}attr(t){for(const[e,o]of Object.entries(t))null!=o&&this.node.setAttribute(e,String(o));return this}add(t){return this.node.appendChild(t instanceof s?t.node:t),this}clear(){const t=this._defs;return this.node.innerHTML="",t&&(this.node.appendChild(t),this._defs=t),this}svg(){return this.node.innerHTML}gradient(t,e){this._defs||(this._defs=document.createElementNS(i,"defs"),this.node.insertBefore(this._defs,this.node.firstChild));const o=document.createElementNS(i,"linearGradient"),n="apx-grad-"+ ++r;return o.setAttribute("id",n),o.setAttribute("x1","0%"),o.setAttribute("y1","0%"),o.setAttribute("x2","100%"),o.setAttribute("y2","0%"),e(new h(o)),this._defs.appendChild(o),o}panZoom(t={}){return this._panZoomState=function(t,e){const o=function(t){const e=t.viewBox.baseVal;return{x:e.x,y:e.y,w:e.width,h:e.height}}(t),n={zoomMin:e.zoomMin??.1,currentZoom:1,baseVb:{...o},vb:{...o}};t.addEventListener("wheel",(e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();const o=1+Math.max(-.12,Math.min(.12,.0025*e.deltaY)),i=n.currentZoom/o;if(i<n.zoomMin)return;const r=t.getBoundingClientRect(),s=(e.clientX-r.left)/r.width,a=(e.clientY-r.top)/r.height,{vb:d}=n,l=d.w*o,c=d.h*o,h=d.x+s*(d.w-l),p=d.y+a*(d.h-c);n.vb={x:h,y:p,w:l,h:c},n.currentZoom=i,u(t,n.vb)}),{passive:!1});let i=!1,r=!1,s=-1,a=0,d=0;t.addEventListener("pointerdown",(t=>{0===t.button&&(t.preventDefault(),i=!0,r=!1,s=t.pointerId,a=t.clientX,d=t.clientY)})),t.addEventListener("pointermove",(e=>{if(!i||e.pointerId!==s)return;if(!r){const o=e.clientX-a,n=e.clientY-d;if(Math.abs(o)<4&&Math.abs(n)<4)return;r=!0,t.setPointerCapture(e.pointerId),t.style.cursor="grabbing",t.style.userSelect="none"}const o=t.getBoundingClientRect(),l=n.vb.w/o.width,c=n.vb.h/o.height,h=(e.clientX-a)*l,p=(e.clientY-d)*c;n.vb={x:n.vb.x-h,y:n.vb.y-p,w:n.vb.w,h:n.vb.h},u(t,n.vb),a=e.clientX,d=e.clientY}));const l=e=>{i&&e.pointerId===s&&(r&&(t.releasePointerCapture(e.pointerId),t.style.cursor="",t.style.userSelect=""),i=!1,r=!1,s=-1)};return t.addEventListener("pointerup",l),t.addEventListener("pointercancel",l),n}(this.node,t),this}resetPanZoomBase(){if(!this._panZoomState)return;const t=this.node.viewBox.baseVal;this._panZoomState.baseVb={x:t.x,y:t.y,w:t.width,h:t.height},this._panZoomState.vb={x:t.x,y:t.y,w:t.width,h:t.height},this._panZoomState.currentZoom=1}zoom(t){var e;if(void 0===t)return(null==(e=this._panZoomState)?void 0:e.currentZoom)??1;if(!this._panZoomState)return this;const o=this._panZoomState;if(t<o.zoomMin)return this;const n=o.currentZoom/t,{vb:i}=o,r=i.w*n,s=i.h*n,a=i.x+.5*(i.w-r),d=i.y+.5*(i.h-s);return o.vb={x:a,y:d,w:r,h:s},o.currentZoom=t,u(this.node,o.vb),this}}function g(t,e,o,n){const i=new a;return i.attr({"data-parent":n,"data-self":o,transform:void 0!==t&&void 0!==e?`translate(${t}, ${e})`:void 0}),i}const f={export:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">\n <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>\n <polyline points="7 10 12 15 17 10"/>\n <line x1="12" y1="15" x2="12" y2="3"/>\n </svg>',"zoom-in":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">\n <circle cx="11" cy="11" r="8"/>\n <path d="m21 21-4.35-4.35"/>\n <line x1="11" y1="8" x2="11" y2="14"/>\n <line x1="8" y1="11" x2="14" y2="11"/>\n </svg>',"zoom-out":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">\n <circle cx="11" cy="11" r="8"/>\n <path d="m21 21-4.35-4.35"/>\n <line x1="8" y1="11" x2="14" y2="11"/>\n </svg>',"fit-screen":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">\n <path d="M8 3H5a2 2 0 0 0-2 2v3"/>\n <path d="M21 8V5a2 2 0 0 0-2-2h-3"/>\n <path d="M3 16v3a2 2 0 0 0 2 2h3"/>\n <path d="M16 21h3a2 2 0 0 0 2-2v-3"/>\n </svg>'};class m{constructor(t,o){this.element=t,t&&(this.chartContext=o||new e(t),this.injectStyles())}injectStyles(){const t=`toolbar-styles-${this.chartContext.getInstanceId()}`;this.chartContext.injectStyles("\n #toolbar {\n display: flex;\n gap: 2px;\n position: absolute;\n /* Logical inset: stays on the right in LTR, mirrors to the left in RTL\n (so it never collides with RTL-flipped chrome such as the search box). */\n inset-inline-end: 12px;\n top: 12px;\n z-index: 100;\n user-select: none;\n background: var(--toolbar-bg-color, rgba(255, 255, 255, 0.92));\n border: 1px solid var(--toolbar-border-color, rgba(0, 0, 0, 0.08));\n border-radius: 10px;\n padding: 4px;\n box-shadow:\n 0 1px 3px rgba(0, 0, 0, 0.08),\n 0 4px 12px rgba(0, 0, 0, 0.06);\n backdrop-filter: blur(8px);\n -webkit-backdrop-filter: blur(8px);\n }\n\n .toolbar-item {\n align-items: center;\n background-color: transparent;\n border: none;\n border-radius: 6px;\n color: var(--toolbar-icon-color, #444);\n cursor: pointer;\n display: flex;\n height: 30px;\n justify-content: center;\n width: 30px;\n transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;\n position: relative;\n flex-shrink: 0;\n }\n\n .toolbar-item:hover {\n background-color: var(--toolbar-hover-bg-color, rgba(0, 0, 0, 0.06));\n color: var(--toolbar-icon-hover-color, #111);\n transform: translateY(-1px);\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);\n }\n\n .toolbar-item:active {\n transform: translateY(0);\n box-shadow: none;\n background-color: var(--toolbar-active-bg-color, rgba(0, 0, 0, 0.1));\n }\n\n .toolbar-item:focus-visible {\n outline: none;\n box-shadow: 0 0 0 2px var(--button-bg-color, #0066cc);\n }\n\n .toolbar-item svg {\n width: 15px;\n height: 15px;\n pointer-events: none;\n flex-shrink: 0;\n }\n\n .toolbar-item[disabled] {\n opacity: 0.4;\n cursor: not-allowed;\n pointer-events: none;\n }\n\n /* Tooltip */\n .toolbar-item::after {\n content: attr(data-tooltip);\n position: absolute;\n bottom: calc(100% + 8px);\n left: 50%;\n transform: translateX(-50%);\n background: var(--tooltip-bg-color, rgba(30, 30, 30, 0.92));\n color: var(--tooltip-text-color, #fff);\n padding: 5px 9px;\n border-radius: 6px;\n font-size: 11.5px;\n font-weight: 500;\n white-space: nowrap;\n opacity: 0;\n pointer-events: none;\n transition: opacity 0.15s ease;\n z-index: 1000;\n letter-spacing: 0.01em;\n }\n\n .toolbar-item::before {\n content: '';\n position: absolute;\n bottom: calc(100% + 3px);\n left: 50%;\n transform: translateX(-50%);\n border: 4px solid transparent;\n border-top-color: var(--tooltip-bg-color, rgba(30, 30, 30, 0.92));\n opacity: 0;\n pointer-events: none;\n transition: opacity 0.15s ease;\n z-index: 1000;\n }\n\n .toolbar-item:hover::after,\n .toolbar-item:hover::before {\n opacity: 1;\n }\n\n /* Shadow DOM specific adjustments */\n :host #toolbar {\n display: flex;\n gap: 2px;\n position: absolute;\n inset-inline-end: 12px;\n top: 12px;\n z-index: 100;\n }\n",t)}createToolbarItem(t,e,o){const n=this.chartContext.createElement("div");return n.id=t,n.className="toolbar-item",n.setAttribute("role","button"),n.setAttribute("tabindex","0"),n.innerHTML=e,o&&(n.setAttribute("data-tooltip",o),n.setAttribute("aria-label",o)),n.addEventListener("keydown",(t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),n.click())})),n}render({enableExport:e=!1,enableFitscreen:o=!1,enableZoom:n=!1,onExport:i=t,onFitscreen:r=t,onZoom:s=t}){if(!this.element)return;const a=this.chartContext.querySelector("#toolbar");null==a||a.remove();const d=this.chartContext.createElement("div");if(d.id="toolbar",d.setAttribute("role","toolbar"),d.setAttribute("aria-label","Chart controls"),e){const t=this.createToolbarItem("export",f.export,"Export chart");t.addEventListener("click",(()=>{i()})),d.append(t)}if(n){const t=this.createToolbarItem("zoom-in",f["zoom-in"],"Zoom in"),e=this.createToolbarItem("zoom-out",f["zoom-out"],"Zoom out");t.addEventListener("click",(()=>{s(.1)})),e.addEventListener("click",(()=>{s(-.1)})),d.append(t,e)}if(o){const t=this.createToolbarItem("fit-screen",f["fit-screen"],"Fit to screen");t.addEventListener("click",(()=>{r()})),d.append(t)}this.element.append(d)}destroy(){const t=this.chartContext.querySelector("#toolbar");null==t||t.remove()}}const v="aria-hidden",y=(t,e="apex-tooltip-container")=>{let o=t.getElementById(e);if(!o){o=t.createElement("div"),o.id=e,o.setAttribute("role","tooltip"),o.setAttribute(v,"true");t.getAppendContainer().appendChild(o),t.trackTooltip(o)}return o},b=(t,e="",o,n="",i=!1)=>{const r=t.getElementById(e);if(!r)return y(t,e),b(t,e,o,n,i);if(o&&n){const e=n.includes("tooltip-content"),s=o.match(/background-color:\s*([^;]+);?/),a=o.match(/color:\s*([^;]+);?/);if(e||!s)r.innerHTML=n;else{const t=s[1],e=a?a[1]:"white";r.innerHTML=`<div class="tooltip-content" style="background-color: ${t}; color: ${e};">${n}</div>`}const d=o+"; display: block !important; visibility: visible !important; opacity: 1 !important;";if(r.setAttribute("style",d),r.classList.add("visible"),r.setAttribute(v,"false"),i&&"undefined"!=typeof window){const e=r.offsetWidth,o=parseFloat(r.style.left),n=t.getChartBounds();if(e>0&&!Number.isNaN(o)&&n.width>0){const t=window.scrollX||document.documentElement.scrollLeft||0,i=n.left+t,s=((t,e,o,n,i=8)=>{if(t+e<=o-i)return t;const r=t-e;return r<n+i?Math.max(n+i,o-e-i):r})(o,e,n.right+t,i);s!==o&&(r.style.left=`${s}px`)}}}else r.removeAttribute("style"),r.classList.remove("visible"),r.setAttribute(v,"true"),r.innerHTML=""},x=({bgColor:t,borderColor:e,fontColor:o,fontFamily:n,fontSize:i,fontWeight:r,maxWidth:s,padding:a,placement:d="top",x:l,y:c})=>{const h=["position: absolute;","z-index: 1000;","pointer-events: none;"];return h.push("box-sizing: border-box;"),h.push("word-wrap: break-word;"),h.push("overflow-wrap: break-word;"),h.push(`left: ${l}px;`),h.push(`top: ${c}px;`),h.push(`data-placement: ${d};`),s&&(h.push(`width: ${s}px;`),h.push(`max-width: ${s}px;`)),e&&h.push(`border: 1px solid ${e};`),o&&h.push(`color: ${o};`),n&&h.push(`font-family: ${n};`),r&&h.push(`font-weight: ${r};`),i&&h.push(`font-size: ${i};`),t&&(h.push(`background-color: ${t};`),h.push("border-radius: 6px;"),h.push("box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);")),void 0!==a&&h.push(`padding: ${a}px;`),h.join(" ")},w=globalThis.console;const E=class{static decodeLicenseData(t){try{const e=window.atob(t),o=JSON.parse(e);return o.issueDate&&o.expiryDate&&o.plan?{domains:Array.isArray(o.domains)?o.domains:void 0,expiryDate:o.expiryDate,issueDate:o.issueDate,plan:o.plan,valid:!0}:null}catch{return null}}static generateLicenseKey(t,e,o="standard",n){const i={expiryDate:e,issueDate:t,plan:o};n&&n.length>0&&(i.domains=n);return`APEX-${window.btoa(JSON.stringify(i))}`}static getLicenseStatus(){return this.licenseKey?(this.validationResult||(this.validationResult=this.validateLicense(this.licenseKey)),this.validationResult):{expired:!1,valid:!1}}static isLicenseValid(){return!!this.licenseKey&&(this.validationResult||(this.validationResult=this.validateLicense(this.licenseKey)),this.validationResult.valid)}static setLicense(t){var e;this.licenseKey=t,this.validationResult=this.validateLicense(t),this.validationResult.valid||(e=`[Apex] ${this.validationResult.message}`,w.error(e))}static validateLicense(t){try{if(!t.startsWith("APEX-"))return{expired:!1,message:'Invalid license key format. License key must start with "APEX-".',valid:!1};const e=t.indexOf("-"),o=-1!==e?t.slice(e+1):"";if(!o)return{expired:!1,message:"Invalid license key format. Expected format: APEX-{encoded-data}.",valid:!1};const n=this.decodeLicenseData(o);if(!n)return{expired:!1,message:"Invalid license key. Unable to decode license data.",valid:!1};const i=new Date;if(new Date(n.expiryDate)<i)return{data:n,expired:!0,message:`License expired on ${n.expiryDate}. Please renew your license.`,valid:!1};if(n.domains&&n.domains.length>0){const t="undefined"!=typeof window?window.location.hostname:"";if(!n.domains.some((e=>t===e||t.endsWith(`.${e}`))))return{data:n,expired:!1,message:`License is not valid for this domain (${t}). Allowed domains: ${n.domains.join(", ")}.`,valid:!1}}return{data:n,expired:!1,valid:!0}}catch{return{expired:!1,message:"Invalid license key format or corrupted data.",valid:!1}}}};E.licenseKey=null,E.validationResult=null;let A=E;const C=class{static createWatermarkPattern(){const t=this.WATERMARK_TEXT;return`url("data:image/svg+xml,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="300" height="200">\n <text \n x="50%" \n y="50%" \n dominant-baseline="middle" \n text-anchor="middle"\n font-family="-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Arial, sans-serif"\n font-size="18"\n font-weight="600"\n fill="rgba(134, 134, 134, 0.1)"\n transform="rotate(-35, 100, 60)"\n >${t}</text>\n </svg>\n `.trim())}")`}static add(t){this.remove(t);const e=document.createElement("div");e.setAttribute(this.WATERMARK_ATTR,""),Object.assign(e.style,{backgroundImage:this.createWatermarkPattern(),backgroundRepeat:"repeat",bottom:"0",left:"0",msUserSelect:"none",pointerEvents:"none",position:"absolute",right:"0",top:"0",userSelect:"none",webkitUserSelect:"none",zIndex:"10000"}),"static"===getComputedStyle(t).position&&(t.style.position="relative"),t.appendChild(e)}static exists(t){return!!t.querySelector(`[${this.WATERMARK_ATTR}]`)}static remove(t){const e=t.querySelector(`[${this.WATERMARK_ATTR}]`);e&&e.remove()}};C.WATERMARK_ATTR="data-apexcharts-watermark",C.WATERMARK_TEXT="APEXCHARTS";let S=C;function k(t,e){let o=null;for(let n=0;n<t.length;++n)if(e(t[n])){o=n;break}return o}function $(t,e){if(0===t.length)return;let o,n=0;for(let i=t.length-1;i>=0;--i)o=(t[i].dy??0)/2,(t[i][e]??0)-o<n&&(t[i][e]=Math.min(t[i].Rmax??0,n+o)),n=(t[i][e]??0)+o;let i=(t[0].Rmax??0)+(t[0].dy??0)/2;for(let n=0;n<t.length;++n)o=(t[n].dy??0)/2,(t[n][e]??0)+o>i&&(t[n][e]=Math.max(o,i-o)),i=(t[n][e]??0)-o}function M(t){const e=t.edgeGap||0;return function(o){!function(t,e,o){t.nodes().forEach((n=>{const i=t.node(n),r=L(t,i.outgoing||[],"outgoing"),s=L(t,i.incoming||[],"incoming"),a=r.length,d=s.length,l=r.reduce(((e,o)=>e+(t.edge(o).dy??0)),0),c=s.reduce(((e,o)=>e+(t.edge(o).dy??0)),0),h=l+Math.max(0,a-1)*o,u=c+Math.max(0,d-1)*o;let p=((i.dy??0)-h)/2,g=((i.dy??0)-u)/2;p=Math.max(0,p),g=Math.max(0,g),r.forEach(((n,r)=>{const s=t.edge(n);s.x0=(i.x??0)+(e.nodeWidth??0)/2,s.y0=(i.y??0)+p+(s.dy??0)/2,s.d0=i.direction||"r",p+=s.dy??0,r<a-1&&(p+=o)})),s.forEach(((n,r)=>{const s=t.edge(n);s.x1=(i.x??0)-(e.nodeWidth??0)/2,s.y1=(i.y??0)+g+(s.dy??0)/2,s.d1=i.direction||"r",g+=s.dy??0,r<d-1&&(g+=o)}))}))}(o,t,e),function(t){t.nodes().forEach((e=>{const o=t.node(e),n=(o.outgoing||[]).map((e=>t.edge(e))),i=(o.incoming||[]).map((e=>t.edge(e)));n.sort(((t,e)=>(t.y0??0)-(e.y0??0))),i.sort(((t,e)=>(t.y1??0)-(e.y1??0))),T(n,"r0"),T(i,"r1")}))}(o);const n=[];return o.edges().forEach((t=>{const e=o.edge(t);e.id=`${t.v}-${t.w}-${t.name}`,n.push(e)})),n}}function L(t,e,o){return e.slice().sort(((e,n)=>{let i,r;if("outgoing"===o){const o=t.node(e.w),s=t.node(n.w);i=(null==o?void 0:o.y)??0,r=(null==s?void 0:s.y)??0}else{const o=t.node(e.v),s=t.node(n.v);i=(null==o?void 0:o.y)??0,r=(null==s?void 0:s.y)??0}if(Math.abs(i-r)>.001)return i-r;if(e.name!==n.name){if("number"==typeof e.name&&"number"==typeof n.name)return e.name-n.name;if("string"==typeof e.name&&"string"==typeof n.name)return e.name.localeCompare(n.name)}return 0}))}function T(t,e){t.forEach((t=>{t.Rmax=function(t){const e=(t.x1??0)-(t.x0??0),o=(t.y1??0)-(t.y0??0);return t.d0!==t.d1?Math.abs(o)/2.1:0!==o?(e*e+o*o)/Math.abs(4*o):1/0}(t),t[e]=Math.max((t.dy??0)/2,t.d0===t.d1?.6*(t.Rmax??0):5+(t.dy??0)/2)}));let o=k(t,"r0"===e?t=>(t.y1??0)>(t.y0??0):t=>(t.y0??0)>(t.y1??0));if(null===o&&(o=t.length),$(t.slice(o),e),o>0){const n=[];for(let e=o-1;e>=0;e--)n.push(t[e]);$(n,e)}}function R(t,e,o,n,i){if(0===n.length)return;const r=n.map((o=>{const n=`__${e.v}_${e.w}_${o}`;return t.setNode(n,{data:null,direction:i,dummy:!0,rank:o}),n})),s=[e.v,...r,e.w];s.forEach(((n,i)=>{i+1<s.length&&t.setEdge(s[i],s[i+1],{data:t.edge(e).data,origEdge:e,origLabel:o,source:t.node(e.v),target:t.node(e.w),value:t.edge(e).value},e.name)})),t.removeEdge(e)}function _(t,e,o){return function(t,e,o){let n,i;e.length>o.length?(n=e,i=o):(n=o,i=e);const r=i.length,s=[];n.forEach((e=>{i.forEach(((o,n)=>{(t.hasEdge(e,o)||t.hasEdge(o,e))&&s.push(n)}))}));let a=1;for(;a<r;)a*=2;const d=2*a-1;a-=1;const l=new Array(d).fill(0);let c=0;return s.forEach((t=>{let e=t+a;for(l[e]++;e>0;)e%2&&(c+=l[e+1]),e=Math.floor((e-1)/2),l[e]++})),c}(t,e,o)}function B(t){const e=[];let o=t.nodes().filter((e=>0===t.node(e).rank)).concat(t.sources());return 0===o.length&&(o=t.nodes().slice(0,1)),function(t,e){const o=new Set,n=[];function i(e){if(!o.has(e)){o.add(e),n.push(e);for(const o of t.successors(e))i(o)}}for(const t of e)i(t);return n}(t,o).forEach((o=>{const n=t.node(o).rank;if(void 0!==n){for(;n>=e.length;)e.push([]);e[n].push(o)}})),e}function N(t,e){let o=!0;for(;o;){o=!1;for(let n=0;n<e.length;++n)for(let i=0;i<e[n].length-1;++i){const r=F(t,e,n);I(e[n],i,i+1);F(t,e,n)<r?o=!0:I(e[n],i,i+1)}}}function F(t,e,o){let n=0;return o>0&&(n+=_(t,e[o-1],e[o])),o+1<e.length&&(n+=_(t,e[o],e[o+1])),n}function I(t,e,o){const n=t[e];t[e]=t[o],t[o]=n}function O(t){const e=Math.floor(t.length/2);if(0===t.length)return-1;if(t.length%2==1)return t[e];if(2===t.length)return(t[0]+t[1])/2;const o=t[e-1]-t[0],n=t[t.length-1]-t[e];return(t[e-1]*n+t[e]*o)/(o+n)}function W(t,e,o=1,n=!1){if(o>0)for(let o=1;o<e.length;++o){const i=new Map;e[o].forEach((r=>{const s=O(z(t,e,o,o-1,r,n));i.set(r,s)})),j(e[o],i)}else for(let o=e.length-2;o>=0;--o){const i=new Map;e[o].forEach((r=>{const s=O(z(t,e,o,o+1,r,n));i.set(r,s)})),j(e[o],i)}}function z(t,e,o,n,i,r=!1){const s=e[o],a=e[n],d=[];return a.forEach(((e,o)=>{t.nodeEdges(e,i).length>0&&d.push(o)})),0===d.length&&r&&s.forEach(((e,o)=>{t.nodeEdges(e,i).length>0&&d.push(o+.5)})),d.sort(((t,e)=>t-e)),d}function j(t,e){const o=new Map(t.map(((t,e)=>[t,e])));for(let n=1;n<t.length;++n)for(let i=n;i>0;--i){let n=i-1,r=e.get(t[n]),s=e.get(t[i]);for(;-1===(r=e.get(t[n]))&&n>0;)n--;if(void 0===s||void 0===r||-1===s||-1===r)break;if(r===s&&(r=o.get(t[n])??r,s=o.get(t[i])??s),s>=r)break;[t[i],t[n]]=[t[n],t[i]]}}function q(t,e){let o=0;for(let n=0;n<e.length-1;++n)o+=_(t,e[n],e[n+1]);return o}function G(t){const e=[];for(const o of t){const t=[];e.push(t);for(const e of o)t.push(e)}return e}const D=(t,e)=>(t||[]).reduce(((t,o)=>t+(e?e(o):o)),0);function H(){let t=[100,100],e=null,o=.18,n=function(t,e,o){return 1};const i=function(t){return t.data.value},r=function(t){return t.data?t.data.direction??"r":"r"};function s(a,d,l=0){null===e&&s.scaleToFit(a,d,l),Y(a,i,r),function(t,e,o,n=0){t.nodes().forEach((e=>{const i=t.node(e),r=t.inEdges(e)||[],s=t.outEdges(e)||[],a=Math.max(0,r.length-1),d=Math.max(0,s.length-1),l=Math.max(a,d);i.dy=i.value*o+l*n})),t.edges().forEach((n=>{const i=t.edge(n);i.value=e(i),i.dy=i.value*o}))}(a,i,e,l);const c=Z(a,d,l,e),h=[];for(let e=0;e<d.length;e++){const i=d[e],r=i.length;let s=0;h[e]=[];for(let d=0;d<i.length;d++){const l=i[d],u=c[d]/D(c)*t[1],p=0===s?0:o*u/5,g=u-2*p,f=l.map(((t,e)=>a.node(t).value&&l[e+1]?n(l[e],l[e+1],a):0)),m=D(l,(t=>a.node(t).dy)),v=Math.max(0,g-m),y=D(f)?v/D(f):0;let b=s+p;1===l.length&&(b+=(g-a.node(l[0]).dy)/2),h[e][d]={margin:p,height:g,gaps:f,kg:y,isFirst:0===d,isLast:d===r-1,startYY:b},s+=u}}let u,p,g=-1,f=-1,m=0,v=0;(function(t){const e=[];for(let o=0;o<t.length;o++){const n=t[o];for(let t=0;t<n.length;t++){const i=n[t];for(let n=0;n<i.length;n++)e.push({rankIndex:o,bandIndex:t,nodeIndex:n,nodeId:i[n]})}}return e})(d).forEach((({rankIndex:t,bandIndex:e,nodeIndex:o,nodeId:n})=>{var i;t===g&&e===f||(g=t,f=e,u=h[t][e],p=d[t][e],m=u.startYY,v=u.isFirst?Number.MAX_VALUE:0);const r=a.node(n);r.y=m,r.spaceAbove=v,r.spaceBelow=u.gaps[o]*u.kg,m+=r.dy+r.spaceBelow,v=r.spaceBelow,void 0!==(null==(i=r.data)?void 0:i.forceY)&&(r.y=u.margin+r.data.forceY*(u.height-r.dy)),o===p.length-1&&(r.spaceBelow=u.isLast?Number.MAX_VALUE:0)}));const y=function(t,e){const o=[];return e.forEach(((n,i)=>{if(i===e.length-1)return;let r=0;n.forEach((e=>{e.forEach((e=>{t.outEdges(e).forEach((e=>{const o=t.edge(e).dy,n=t.node(e.w).y-t.node(e.v).y,i=Math.abs(n)-o,s=o*o-i*i,a=s>=0?Math.sqrt(s):o;a>r&&(r=a)}))}))})),o.push(r)})),o}(a,d);!function(t,e,o,n){const i=n.reduce(((t,e)=>t+e),0);let r;if(i>o)r=n.map((t=>o*t/i));else{const t=o-i;r=n.map((o=>o+t/(e.length-1)))}let s=0;e.forEach(((e,o)=>{e.forEach((e=>{e.forEach((e=>{t.node(e).x=s}))})),s+=r[o]}))}(a,d,t[0],y);const b=[];return a.nodes().forEach((t=>{const e=a.node(t);e.id=t,b.push(e)})),b}return s.scaleToFit=function(n,s,a=0){Y(n,i,r);let d=0;a>0&&n.nodes().forEach((t=>{d=Math.max(d,function(t,e,o){if(o<=0)return 0;const n=t.inEdges(e)||[],i=t.outEdges(e)||[],r=Math.max(0,n.length-1),s=Math.max(0,i.length-1);return Math.max(r,s)*o}(n,t,a))}));const l=D(Z(n,s,0,1));if(l<=0)return void(e=1);const c=t[1]-d;e=c/l,1!==o&&(e*=1-o)},s.size=function(e){return arguments.length?(t=e,s):t},s.separation=function(t){return arguments.length?(n="function"==typeof t?t:()=>t,s):n},s.whitespace=function(t){return arguments.length?(o=t,s):o},s.scale=function(t){return arguments.length?(e=t,s):e},s}function Y(t,e,o){t.nodes().forEach((n=>{const i=D(t.inEdges(n),(o=>e(t.edge(o)))),r=D(t.outEdges(n),(o=>e(t.edge(o))));let s=t.node(n);s||t.setNode(n,s={}),s.value=Math.max(i,r),void 0===s.direction&&(s.direction=o(s)||"r")}))}function Z(t,e,o=0,n=1){if(0===e.length||0===e[0].length)return[];const i=e[0].length,r=new Array(i).fill(0);return e.forEach((e=>{e.forEach(((e,i)=>{const s=D(e,(e=>{const i=t.node(e),r=t.inEdges(e)||[],s=t.outEdges(e)||[],a=Math.max(0,r.length-1),d=Math.max(0,s.length-1),l=Math.max(a,d);return i.value+l*o/n}));r[i]=Math.max(r[i],s)}))})),r}function P(t,e,o){return void 0!==o?`${t}${e}${o}`:`${t}${e}`}class X{constructor(t={}){this._nodes=new Map,this._edges=new Map,this._graphLabel={},this._out=new Map,this._in=new Map,this._isMultigraph=t.multigraph??!1}graph(){return this._graphLabel}setGraph(t){return this._graphLabel=t,this}setNode(t,e){return this._nodes.has(t)?void 0!==e&&this._nodes.set(t,e):(this._nodes.set(t,void 0!==e?e:{}),this._out.set(t,new Set),this._in.set(t,new Set)),this}node(t){return this._nodes.get(t)}hasNode(t){return this._nodes.has(t)}nodes(){return Array.from(this._nodes.keys())}removeNode(t){var e,o;if(!this._nodes.has(t))return this;this._nodes.delete(t);const n=Array.from(this._out.get(t)??[]),i=Array.from(this._in.get(t)??[]);for(const t of n){const o=this._edges.get(t);o&&(null==(e=this._in.get(o.w))||e.delete(t)),this._edges.delete(t)}for(const t of i){const e=this._edges.get(t);e&&(null==(o=this._out.get(e.v))||o.delete(t)),this._edges.delete(t)}return this._out.delete(t),this._in.delete(t),this}sources(){return this.nodes().filter((t=>{var e;return 0===((null==(e=this._in.get(t))?void 0:e.size)??0)}))}successors(t){return this.outEdges(t).map((t=>t.w))}setEdge(t,e,o,n){var i,r;let s,a;"object"==typeof t?(s=t.v,a=t.w,n=t.name,o=e):(s=t,a=e),this.setNode(s),this.setNode(a);const d=this._isMultigraph?P(s,a,n):P(s,a),l=this._edges.get(d);if(l)void 0!==o&&(l.label=o);else{const t={v:s,w:a,name:n,label:void 0!==o?o:{}};this._edges.set(d,t),null==(i=this._out.get(s))||i.add(d),null==(r=this._in.get(a))||r.add(d)}return this}edge(t,e,o){var n;let i;return i="string"==typeof t?this._isMultigraph?P(t,e,o):P(t,e):this._isMultigraph?P(t.v,t.w,t.name):P(t.v,t.w),null==(n=this._edges.get(i))?void 0:n.label}hasEdge(t,e,o){const n=this._isMultigraph?P(t,e,o):P(t,e);return this._edges.has(n)}edges(){return Array.from(this._edges.values()).map((({v:t,w:e,name:o})=>({v:t,w:e,name:o})))}removeEdge(t){var e,o;const n=this._isMultigraph?P(t.v,t.w,t.name):P(t.v,t.w),i=this._edges.get(n);return i?(null==(e=this._out.get(i.v))||e.delete(n),null==(o=this._in.get(i.w))||o.delete(n),this._edges.delete(n),this):this}outEdges(t){const e=this._out.get(t);return e?Array.from(e).flatMap((t=>{const e=this._edges.get(t);return e?[{v:e.v,w:e.w,name:e.name}]:[]})):[]}inEdges(t){const e=this._in.get(t);return e?Array.from(e).flatMap((t=>{const e=this._edges.get(t);return e?[{v:e.v,w:e.w,name:e.name}]:[]})):[]}nodeEdges(t,e){const o=[],n=new Set;for(const i of[...this.inEdges(t),...this.outEdges(t)])if(i.v===e||i.w===e){const t=P(i.v,i.w,i.name);n.has(t)||(n.add(t),o.push(i))}return o}}function K(t){return void 0!==t.name?`${t.v}${t.w}${t.name}`:`${t.v}${t.w}`}function V(t,e){const o=function(t,e){const o=new Set,n=new X({directed:!0}),i=[];if(!t.hasNode(e))throw Error("node not in graph");return U(t,e,o,n,i),t.nodes().forEach((e=>{o.has(e)||U(t,e,o,n,i)})),i.forEach(((t,e)=>{n.node(t).thread=e+1<i.length?i[e+1]:i[0]})),n}(t,e);return t.edges().forEach((e=>{const n=function(t,e,o){const n=t.node(e),i=t.node(o);if((n.depth??0)<(i.depth??0)){let e=n.thread;for(;void 0!==e&&(t.node(e).depth??0)>(n.depth??0);){if(e===o)return 1;e=t.node(e).thread}}else if((i.depth??0)<(n.depth??0)){let o=i.thread;for(;void 0!==o&&(t.node(o).depth??0)>(i.depth??0);){if(o===e)return-1;o=t.node(o).thread}}return 0}(o,e.v,e.w);if(n<0){const o=t.edge(e)||{};o.reversed=!0,t.removeEdge(e),t.setEdge(e.w,e.v,o)}})),t}function U(t,e,o,n,i,r=0){if(!o.has(e)){o.add(e),i.push(e),n.setNode(e,{depth:r});t.outEdges(e).map((t=>t.w)).forEach((s=>{o.has(s)||n.setEdge(e,s,{delta:1}),U(t,s,o,n,i,r+1)}))}}function Q(t,e){if(0===t.nodes().length)return;const o=function(t,e){const o=new X({directed:!0});let n=!1;for(const t of e)if("min"===t.type){n=!0;break}if(!n){const o=t.sources();e=o.length>0?[{nodes:[o[0]],type:"min"},...e]:[{nodes:[t.nodes()[0]],type:"min"},...e]}const i=new Map;let r=0;return e.forEach((t=>{if(!t.nodes||0===t.nodes.length)return;const e=""+r++;t.nodes.forEach((t=>{i.set(t,e)})),o.setNode(e,{nodes:t.nodes,type:t.type})})),t.nodes().forEach((t=>{if(!i.has(t)){const e=""+r++,n={nodes:[t],type:"same"};i.set(t,e),o.setNode(e,n)}})),t.edges().forEach((e=>{const n=i.get(e.v)??e.v,r=i.get(e.w)??e.w,s=t.node(e.v)||{},a=t.node(e.w)||{},d=o.edge(n,r)||{delta:0};n===r?(d.delta=0,o.setEdge(n,r,d)):"l"===s.direction?(d.delta=Math.max(d.delta??0,"l"===a.direction?1:0),o.setEdge(r,n,d)):(d.delta=Math.max(d.delta??0,"l"===a.direction?0:1),o.setEdge(n,r,d))})),o}(t,e);!function(t){t.sources().forEach((e=>{"0"!==e&&t.setEdge("0",e,{delta:0,temp:!0})}))}(o),V(o,"0"),function(t){var e;const o=t.sources(),n=new Set,i=new Set;for(t.edges().forEach((t=>{t.v===t.w&&i.add(K(t))}));o.length>0;){const r=o.shift();if(void 0===r)break;n.add(r);let s=t.node(r);s||t.setNode(r,s={}),s.rank=0;for(const o of t.inEdges(r)){const n=(null==(e=t.edge(o)||{})?void 0:e.delta)??1;s.rank=Math.max(s.rank,(t.node(o.v).rank??0)+n)}for(const e of t.outEdges(r))i.add(K(e));for(const e of t.nodes())o.indexOf(e)<0&&!n.has(e)&&!t.inEdges(e).some((t=>!i.has(K(t))))&&o.push(e)}}(o),function(t){function e(e){const o=t.node(e),n=Math.min(...t.outEdges(e).map((e=>(t.node(e.w).rank??0)-(t.edge(e).delta??0))));void 0!==n&&(o.rank=n)}t.edges().forEach((o=>{t.edge(o).temp&&e(o.w)}))}(o),t.nodes().forEach((e=>{t.node(e)||t.setNode(e,{})})),o.nodes().forEach((e=>{var n;const i=o.node(e);null==(n=i.nodes)||n.forEach((e=>{t.node(e).rank=i.rank}))}))}function J(t){const e=H(),o=M(t);let n=[],i=[],r=null;function s(s=[],a=[],d={}){const l=function(t=[],e=[]){const o=new X({directed:!0,multigraph:!0});return e.forEach((t=>{o.setEdge(t.source,t.target,{data:t,points:[]},t.type)})),o.nodes().forEach((t=>o.setNode(t,{data:{}}))),t.forEach((t=>{o.hasNode(t.id)&&(o.node(t.id).data=t,void 0!==t.direction&&(o.node(t.id).direction=t.direction))})),o.edges().forEach((t=>{o.edge(t).source=o.node(t.v),o.edge(t).target=o.node(t.w)})),o}(a,s);var c;return d.order?(Q(l,d.rankSets||[]),r=d.order,r.length>0&&r[0].length>0&&!Array.isArray(r[0][0])&&(r=r.map((t=>[t]))),r=r.map((t=>t.map((t=>t.filter((t=>void 0!==l.node(t)))))))):(Q(l,d.rankSets||[]),(c=l).edges().forEach((t=>{const e=c.node(t.v),o=c.node(t.w),n=c.edge(t);let i=e.rank;const r=[];if(void 0!==i&&void 0!==o.rank&&i+1<=o.rank){for("l"===e.direction&&r.push(i);++i<o.rank;)r.push(i);"l"===o.direction&&r.push(i),R(c,t,n,r,"r")}else if(void 0!==i&&void 0!==o.rank&&i>o.rank){for("l"!==e.direction&&r.push(i);i-- >o.rank+1;)r.push(i);"l"!==o.direction&&r.push(i),R(c,t,n,r,"l")}})),r=function(t,e=25){const o=B(t);let n=o,i=q(t,o),r=0;for(;r++<e;){W(t,o,r%2==0?1:0),N(t,o);const e=q(t,o);if(e<i&&(n=G(o),i=e),0===i)break}return n.map((t=>[t]))}(l)),n=e(l,r,t.edgeGap||0),function(t){t.nodes().forEach((e=>{const o=t.node(e);o.incoming=t.inEdges(e),o.outgoing=t.outEdges(e)}))}(l),i=o(l),function(t){t.nodes().filter((t=>t.startsWith("__"))).forEach((e=>{var o;let n=t.node(e);if(!n)return;let i=(null==(o=t.inEdges(e))?void 0:o.map((e=>t.edge(e))))||[];i.forEach((e=>{e.origLabel&&e.origEdge&&(e.origLabel.dy=e.dy,e.origLabel.x0=e.x0,e.origLabel.y0=e.y0,e.origLabel.r0=e.r0,e.origLabel.d0=e.d0,e.origLabel.value=e.value,t.setEdge(e.origEdge,e.origLabel))}));let r,s=i.map((t=>t.r1));for(;n.dummy;)i=t.outEdges(e).map((e=>t.edge(e))),i.forEach(((t,e)=>{t.origLabel&&(t.origLabel.points||(t.origLabel.points=[]),t.origLabel.points.push({d:t.d0,r0:t.r0,r1:s[e],x:n.x,y:t.y0}))})),s=i.map((t=>t.r1)),r=t.successors(e)[0],t.removeNode(e),n=t.node(e=r);i.forEach((t=>{t.origLabel&&(t.origLabel.x1=t.x1,t.origLabel.y1=t.y1,t.origLabel.r1=t.r1,t.origLabel.d1=t.d1)}))}))}(l),function(t){t.edges().forEach((e=>{const o=t.edge(e);o.points||(o.points=[]),o.points.unshift({d:o.d0,ro:o.r0,x:o.x0,y:o.y0}),o.points.push({d:o.d1,ri:o.r1,x:o.x1,y:o.y1})}))}(l),l}return void 0!==t.whitespace&&e.whitespace(t.whitespace),s.nodes=function(){return n},s.links=function(){return i},s.order=function(){return r},s.size=function(t){return arguments.length?(e.size(t),s):e.size()},s.separation=function(t){return arguments.length?(e.separation(t),s):e.separation()},s.whitespace=function(t){return arguments.length?(e.whitespace(t),s):e.whitespace()},s.edgeValue=function(t){return s},s.scale=function(t){return arguments.length?(e.scale(t),s):e.scale()},s}const tt=["#6b9ece","#e07b7b","#7dba8f","#b09ed1","#e0b678","#6dbaba","#d17da8","#b5b56d","#c49a6d","#8fa4b8","#c98aa0","#94bf7d","#e0a08a","#7b9eb5","#a988a8"],et=t=>0===t.dy?0:2;function ot(t){const e=Math.max(et(t),t.dy)/2;let{x0:o}=t,{x1:n}=t,{y0:i}=t,{y1:r}=t;n<o&&([o,n]=[n,o],[i,r]=[r,i]);const s=r>i?1:-1,a=function(t){const e=t.x1-t.x0,o=t.y1-t.y0;return[t.dy/2,(e*e+o*o)/Math.abs(4*o)]}(t),d=Math.max(a[0],Math.min(a[1],(n-o)/3));let l=Math.max(a[0],Math.min(a[1],t.r0||d)),c=Math.max(a[0],Math.min(a[1],t.r1||d));const h=n-o,u=r-i-s*(l+c),p=Math.sqrt(h*h+u*u),g=-s*Math.acos(Math.min(1,(l+c)/p)),f=Math.atan2(u,h);let m=Math.PI/2+s*(f+g),v=e*s*Math.sin(m),y=e*Math.cos(m),b=o+1*l*Math.sin(Math.abs(m)),x=n-1*c*Math.sin(Math.abs(m)),w=i+l*s*(1-Math.cos(m)),E=r-c*s*(1-Math.cos(m));function A(t,o){const n=t*(r-i)>0?1:0;let s=1*t*(r-i)>0?o+e:o-e;return 0===m&&(s=o),`A${s} ${s} ${Math.abs(m)} 0 ${n} `}return(Number.isNaN(m)||Math.abs(m)<.001)&&(m=0,l=0,c=0,b=o,x=n,w=i,E=r,v=0,y=e),`M${[o,i-e]} ${A(1,l)}${[b+v,w-y]} L${[x+v,E-y]} ${A(-1,c)}${[n,r-e]} L${[n,r+e]} ${A(1,c)}${[x-v,E+y]} L${[b-v,w+y]} ${A(-1,l)}${[o,i+e]} Z`}function nt(t){var e;if(1===(null==(e=t.points)?void 0:e.length))return function(t){if(!t.points)return null;const e=t.points[0],o=Math.max(et(t),t.dy??0)/2;return"down-right"===e.style?`M${[(e.x??0)-20,(e.y??0)-o]} L${[e.x??0,(e.y??0)-o]} L${[e.x??0,(e.y??0)+o]} L${[(e.x??0)-20,(e.y??0)+o]} Z`:"right-down"===e.style?`M${[e.x??0,(e.y??0)-o]} L${[(e.x??0)+20,(e.y??0)-o]} L${[(e.x??0)+20,(e.y??0)+o]} L${[e.x??0,(e.y??0)+o]} Z`:null}(t);if(!t.points)return null;let o,n="";for(let e=0;e<t.points.length-1;++e){const i=t.points[e],r=t.points[e+1];o={d0:i.d,d1:r.d,dy:t.dy??0,r0:i.ro,r1:r.ri,x0:i.x??0,x1:r.x??0,y0:i.y??0,y1:r.y??0},n+=ot(o)}return n}const it=(t,e)=>{const o=(null==t?void 0:t.title)??(null==t?void 0:t.id)??"";return e&&o.length>e?`${o.substr(0,15)}...`:o};function rt(t,{fontColor:e,isRtl:o,maxRank:n,nodeWidth:i}){const{data:r}=t;if(!r)return null;const s=function(t,e,o){let n=!1,i=!1;return(t.rank??0)<e/2&&(i=!0,n=!1),o&&(i=!i),{right:i,top:n}}(t,n,o),{x:a,y:d}=function(t,e,o){const n=e.top?-25:(t.dy??0)/2-10;let i;return i=e.top?e.right?4:-4:e.right?10+o/2:-o/2-10,{x:(t.x??0)+i,y:(t.y??0)+n}}(t,s,i);return function(t="",{fontColor:e="#666767",pointerEvents:o="all",textAnchor:n="start",x:i,y:r}={}){const s=new c;return s.font({fill:e}),s.tspan(t),void 0!==i&&void 0!==r&&s.move(i,r),s.attr({"pointer-events":o,"text-anchor":n}),s}(it(r,s.top?25:15),{fontColor:e,pointerEvents:"none",textAnchor:s.top?"middle":s.right?"start":"end",x:a,y:d})}function st(t,e,o){var n,i;const{dy:r,x:s,y:l}=t,{fontColor:c="#212121",fontSize:h="14px",fontFamily:u,fontWeight:p,isRtl:g=!1,nodeBorderColor:f,nodeBorderWidth:m,nodeWidth:v=0,onNodeClick:w,nodeTooltip:E}=o,A=new a({class:"node"}),C=function({borderColor:t="#caced0",color:e="#97cbe6",height:o=0,opacity:n=1,radius:i=0,width:r=0,x:s=0,y:a=0}={}){const l=new d;return l.attr({height:o,opacity:n,rx:i,ry:i,width:r,x:s,y:a}),l.fill(e),l.stroke({color:t,width:1}),l}({height:r,width:v,x:(s??0)-v/2,y:l});if(C.fill(null==(n=t.data)?void 0:n.color),C.stroke({color:f??(null==(i=t.data)?void 0:i.color),width:m}),C.on("click",(()=>{"function"==typeof w&&w(t)})),E){const{chartContext:e,isCustomTooltip:o,nodeValue:n,tooltipBGColor:i,tooltipBorderColor:r,tooltipFontColor:s,tooltipId:a,nodeTooltipTemplate:d}=E,l=d({node:t.data,value:n});C.on("mouseover",(t=>{const{pageX:n,pageY:d}=t,g=x({bgColor:o?void 0:i,borderColor:o?void 0:r,fontColor:o?void 0:s||c,fontFamily:o?void 0:u??"",fontSize:o?void 0:h??"14px",fontWeight:o?void 0:p??"400",x:n,y:d});b(e,a,g,l,!0)})),C.on("mousemove",(t=>{const{pageX:n,pageY:d}=t,g=x({bgColor:o?void 0:i,borderColor:o?void 0:r,fontColor:o?void 0:s||c,fontFamily:o?void 0:u??"",fontSize:o?void 0:h??"14px",fontWeight:o?void 0:p??"400",x:n,y:d});b(e,a,g,l,!0)})),C.on("mouseout",(()=>{y(e,a).style.display="none"}))}if(A.add(C),t.data&&(r??0)>Number.parseInt(h,10)){const o=rt(t,{fontColor:c,isRtl:g,maxRank:e,nodeWidth:v});o&&A.add(o)}return A}const at={canvasStyle:"border: 1px solid #caced0; box-sizing: border-box",edgeGap:0,edgeGradientFill:!0,edgeOpacity:.4,enableToolbar:!0,enableTooltip:!0,fontColor:"#212121",fontFamily:"",fontSize:"14px",fontWeight:"400",height:"auto",locale:{direction:"ltr"},nodeBorderColor:null,nodeBorderWidth:1,nodeWidth:20,onNodeClick:void 0,spacing:20,tooltipBGColor:"#FFFFFF",tooltipBorderColor:"#E2E8F0",tooltipFontColor:"#1a1a1a",tooltipId:"apexsankey-tooltip-container",tooltipTemplate:({source:t,target:e,value:o})=>`\n <div style='display:flex;align-items:center;gap:6px;padding:7px 10px;'>\n <div style='width:10px;height:10px;border-radius:2px;background-color:${null==t?void 0:t.color};flex-shrink:0;'></div>\n <span style='font-weight:500;'>${null==t?void 0:t.title}</span>\n <svg width='14' height='14' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg' style='opacity:0.5;flex-shrink:0;'><path d='M5 12h14M13 6l6 6-6 6' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>\n <div style='width:10px;height:10px;border-radius:2px;background-color:${null==e?void 0:e.color};flex-shrink:0;'></div>\n <span style='font-weight:500;'>${null==e?void 0:e.title}</span>\n <span style='opacity:0.6;margin-left:2px;'>·</span>\n <span style='font-weight:600;'>${o}</span>\n </div>\n `,nodeTooltipTemplate:({node:t,value:e})=>`\n <div style='display:flex;align-items:center;gap:6px;padding:7px 10px;'>\n <div style='width:10px;height:10px;border-radius:2px;background-color:${null==t?void 0:t.color};flex-shrink:0;'></div>\n <span style='font-weight:500;'>${null==t?void 0:t.title}</span>\n <span style='opacity:0.6;'>·</span>\n <span style='font-weight:600;'>${e}</span>\n </div>\n `,viewPortHeight:500,viewPortWidth:800,whitespace:.18,width:"100%",highlightConnectedPath:!0,dimOpacity:.2,animation:{enabled:!0,duration:800},a11y:{enabled:!0}},dt={diagramLabel:({flowCount:t,largestFlow:e,nodeCount:o})=>{let n=`Sankey flow diagram: ${o} nodes, ${t} flows.`;return e&&(n+=` Largest flow: ${e.source} (${e.value} units) to ${e.target}.`),n},edgeAriaLabel:({source:t,target:e,value:o})=>`Flow from ${t} to ${e}: ${o} units`,nodeAriaLabel:({incoming:t,name:e,outgoing:o})=>{let n=e;if(t&&(n+=`: receives ${t.total} units from ${t.sources.join(", ")}`),o){n+=`${t?"; ":": "}flows ${o.total} units to ${o.targets.join(", ")}`}return n},nodesGroupLabel:"Sankey nodes"};function lt(t){var e;return function(t,e){if(!e)return{...t};const o={...t};for(const t of Object.keys(e)){const n=e[t];void 0!==n&&(o[t]=n)}return o}(dt,null==(e=t.locale)?void 0:e.messages)}class ct{constructor(t,e,o){this.element=t,this.options=e,this.chartContext=o,t.innerHTML="",this.canvas=function(){const t=document.createElementNS(i,"svg");return new p(t)}().addTo(t).size("100%","100%").viewbox(`-${this.spacing} -${this.spacing+this.getYShift()} ${this.width+2*this.spacing} ${this.height+this.spacing+this.getYShift()}`).attr({style:this.options.canvasStyle})}getYShift(){return this.options.enableToolbar?30:0}add(t){this.canvas.add(t)}clear(){this.canvas.clear().viewbox(`-${this.spacing} -${this.spacing+this.getYShift()} ${this.width+2*this.spacing} ${this.height+this.spacing+this.getYShift()}`)}exportToSvg(){new n(this.canvas,"apexsankey").exportToSVG()}resetViewBox(){this.canvas.viewbox(`-${this.spacing} -${this.spacing+this.getYShift()} ${this.width+2*this.spacing} ${this.height+this.spacing+this.getYShift()}`)}updateViewBox(t,e,o,n){this.canvas.viewbox(`${t} ${e} ${o} ${n}`)}get height(){return this.options.viewPortHeight}get spacing(){return this.options.spacing}get width(){return this.options.viewPortWidth}}class ht{constructor(t,e,o){this.svgRoot=t,this.graph=e,this.dimOpacity=o}highlightNode(t){const e=this.prefersReducedMotion(),o=[...this.graph.inEdges(t)??[],...this.graph.outEdges(t)??[]],n=new Set([t]);o.forEach((t=>{var e,o,i,r;const s=this.graph.edge(t.v,t.w,t.name),a=null==(o=null==(e=null==s?void 0:s.source)?void 0:e.data)?void 0:o.id,d=null==(r=null==(i=null==s?void 0:s.target)?void 0:i.data)?void 0:r.id;a&&n.add(a),d&&n.add(d)})),this.dimAll(e),o.forEach((t=>{const o=this.svgRoot.querySelector(`[data-edge-source="${t.v}"][data-edge-target="${t.w}"]`);o&&this.setOpacity(o,1,e)})),n.forEach((t=>{const o=this.svgRoot.querySelector(`[data-node-id="${t}"]`);o&&this.setOpacity(o,1,e)}))}highlightEdge(t,e){var o,n,i,r;const s=this.prefersReducedMotion(),a=this.graph.edge(t,e),d=(null==(n=null==(o=null==a?void 0:a.source)?void 0:o.data)?void 0:n.id)??t,l=(null==(r=null==(i=null==a?void 0:a.target)?void 0:i.data)?void 0:r.id)??e;this.dimAll(s),this.svgRoot.querySelectorAll(`[data-edge-source="${t}"][data-edge-target="${e}"]`).forEach((t=>this.setOpacity(t,1,s)));const c=this.svgRoot.querySelector(`[data-node-id="${d}"]`),h=this.svgRoot.querySelector(`[data-node-id="${l}"]`);c&&this.setOpacity(c,1,s),h&&this.setOpacity(h,1,s)}reset(){const t=this.prefersReducedMotion()?"none":"";this.svgRoot.querySelectorAll("[data-edge-source]").forEach((e=>{e.style.transition=t,e.style.opacity=""})),this.svgRoot.querySelectorAll("[data-node-id]").forEach((e=>{e.style.transition=t,e.style.opacity=""}))}dimAll(t){this.svgRoot.querySelectorAll("[data-edge-source]").forEach((e=>{this.setOpacity(e,this.dimOpacity,t)})),this.svgRoot.querySelectorAll("[data-node-id]").forEach((e=>{this.setOpacity(e,this.dimOpacity,t)}))}setOpacity(t,e,o){t.style.transition=o?"none":"opacity 0.2s ease",t.style.opacity=String(e)}prefersReducedMotion(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}}function ut(t,e){const o=e=>function(t,e){return getComputedStyle(t).getPropertyValue(e).trim()}(t,e),n=o("--apex-sankey-edge-opacity"),i=""!==n?Number(n):e.edgeOpacity,r=o("--apex-sankey-node-width"),s=""!==r?Number(r):e.nodeWidth,a=o("--apex-sankey-node-border-width"),d=""!==a?Number(a):e.nodeBorderWidth,l=o("--apex-sankey-edge-gradient"),c=""!==l?"true"===l:e.edgeGradientFill,h=o("--apex-sankey-node-border-color")||e.nodeBorderColor,u=o("--apex-sankey-tooltip-bg")||e.tooltipBGColor,p=o("--apex-sankey-tooltip-border-color")||e.tooltipBorderColor,g=o("--apex-sankey-tooltip-font-color")||e.tooltipFontColor,f=o("--apex-sankey-tooltip-theme"),m="dark"===f||"light"===f?f:e.tooltipTheme;return{...e,edgeGradientFill:c,edgeOpacity:Number.isFinite(i)?i:e.edgeOpacity,fontColor:o("--apex-sankey-label-color")||e.fontColor,fontSize:o("--apex-sankey-label-font-size")||e.fontSize,fontFamily:o("--apex-sankey-font-family")||e.fontFamily,nodeBorderColor:h,nodeBorderWidth:Number.isFinite(d)?d:e.nodeBorderWidth,nodeWidth:Number.isFinite(s)?s:e.nodeWidth,tooltipBGColor:u,tooltipBorderColor:p,tooltipFontColor:g,tooltipTheme:m}}const pt="#005FCC",gt="role",ft="aria-label",mt="data-node-id",vt="data-orig-stroke",yt="data-orig-stroke-width",bt="stroke",xt="stroke-width",wt="forced-colors",Et="apexsankey-desc",At="data-edge-target";const Ct="apexsankey-a11y-styles";class St{constructor(t,e,o={},n,i,r=dt){this.svgEl=t,this.graph=e,this.options=o,this.tooltipId=n,this.pathHighlighter=i,this.messages=r,this.nodeGroups=[],this.edgePaths=[],this.nodeOutEdges=new Map,this.edgeSourceNode=new Map,this.mediaQuery=null,this.forcedColorsHandler=null,this.isKeyboardUser=!1}apply(){!1!==this.options.enabled&&(this.injectAriaAttributes(),this.setupKeyboardNavigation(),function(){if(document.getElementById(Ct))return;const t=document.createElement("style");t.id=Ct,t.textContent=`\n /* ApexSankey: keyboard focus ring */\n .node:focus,\n svg path[data-edge-source]:focus { outline: none; }\n .node:focus-visible rect {\n stroke: ${pt};\n stroke-width: 2;\n }\n\n /* High-contrast (Windows Forced Colors) */\n @media (forced-colors: active) {\n .node rect {\n fill: ButtonFace;\n stroke: ButtonText;\n }\n .node text {\n fill: ButtonText;\n }\n .node:focus-visible rect {\n stroke: Highlight;\n stroke-width: 2;\n }\n }\n\n /* Reduced motion */\n @media (prefers-reduced-motion: reduce) {\n .node rect,\n svg path {\n transition: none !important;\n animation: none !important;\n }\n }\n `,document.head.appendChild(t)}(),this.setupHighContrastMode())}destroy(){this.mediaQuery&&this.forcedColorsHandler&&(this.mediaQuery.removeEventListener("change",this.forcedColorsHandler),this.mediaQuery=null,this.forcedColorsHandler=null)}injectAriaAttributes(){const{svgEl:t,graph:e,messages:o,options:n}=this,i=e.nodes().filter((t=>!e.node(t).dummy)),r=e.edges(),s=function(t,e,o,n,i){var r,s,a,d;if(i)return i;let l=0,c="",h="";for(const e of o)try{const o=t.edge(e.v,e.w,e.name).value??0;if(o>l){const n=t.node(e.v),i=t.node(e.w);n.dummy||i.dummy||(l=o,c=(null==(r=n.data)?void 0:r.title)??(null==(s=n.data)?void 0:s.id)??e.v,h=(null==(a=i.data)?void 0:a.title)??(null==(d=i.data)?void 0:d.id)??e.w)}}catch{}const u=c&&h?{source:c,target:h,value:l}:void 0;return n.diagramLabel({flowCount:o.length,largestFlow:u,nodeCount:e.length})}(e,i,r,o,n.diagramLabel);t.setAttribute(gt,"img"),t.setAttribute(ft,s),t.removeAttribute("aria-labelledby");const a=t.querySelector("title");if(a&&a.remove(),n.description){let e=t.querySelector("desc");if(!e){const o=document.createElementNS("http://www.w3.org/2000/svg","desc");o.id=Et,t.insertBefore(o,t.firstChild),e=o}e.textContent=n.description,t.setAttribute("aria-describedby",Et)}const d=Array.from(t.querySelectorAll(`[${mt}]`));d.forEach((t=>{const n=t.getAttribute(mt);n&&(t.setAttribute(gt,"listitem"),t.setAttribute(ft,function(t,e,o){var n,i,r,s,a,d;const l=e.node(t),c=(null==(n=l.data)?void 0:n.title)??(null==(i=l.data)?void 0:i.id)??t,h=[];let u=0;for(const o of e.inEdges(t))try{const t=e.edge(o.v,o.w,o.name),n=e.node(o.v);n.dummy||(h.push((null==(r=n.data)?void 0:r.title)??(null==(s=n.data)?void 0:s.id)??o.v),u+=t.value??0)}catch{}const p=[];let g=0;for(const o of e.outEdges(t))try{const t=e.edge(o.v,o.w,o.name),n=e.node(o.w);n.dummy||(p.push((null==(a=n.data)?void 0:a.title)??(null==(d=n.data)?void 0:d.id)??o.w),g+=t.value??0)}catch{}return o.nodeAriaLabel({incoming:h.length>0?{sources:h,total:u}:void 0,name:c,outgoing:p.length>0?{targets:p,total:g}:void 0})}(n,e,o)),t.setAttribute("tabindex","0"))})),this.nodeGroups=d;const l=[],c=new Map,h=new Map;t.querySelectorAll("[data-edge-source]").forEach((t=>{var n,i,r,s;const a=t.getAttribute("data-edge-source"),d=t.getAttribute("data-edge-target"),u=t.getAttribute("data-edge-name")??void 0;if(a&&d)try{const p=e.edge(a,d,u),g=p.source,f=p.target;if(!g||!f)return;const m=(null==(n=g.data)?void 0:n.title)??(null==(i=g.data)?void 0:i.id)??a,v=(null==(r=f.data)?void 0:r.title)??(null==(s=f.data)?void 0:s.id)??d,y=p.value??0;t.setAttribute("role","img"),t.setAttribute("aria-label",o.edgeAriaLabel({source:m,target:v,value:y})),t.setAttribute("focusable","true"),t.setAttribute("tabindex","-1"),l.push(t),h.set(t,a),c.has(a)||c.set(a,[]);const b=c.get(a);b&&b.push(t)}catch{}})),this.edgePaths=l,this.nodeOutEdges=c,this.edgeSourceNode=h}setupKeyboardNavigation(){this.svgEl.addEventListener("pointerdown",(()=>{this.isKeyboardUser=!1})),this.svgEl.addEventListener("keydown",(()=>{this.isKeyboardUser=!0})),this.nodeGroups.forEach(((t,e)=>{t.addEventListener("keydown",(o=>{const n=o.key;if("Enter"===n||" "===n){o.preventDefault();const e=t.querySelector("rect");e&&e.dispatchEvent(new MouseEvent("click",{bubbles:!0}))}else if("Escape"===n)o.preventDefault(),this.restoreFocusRing(t),t.blur(),this.hideTooltip();else if("ArrowRight"===n||"ArrowDown"===n){o.preventDefault();const n=t.getAttribute(mt),i=n?this.nodeOutEdges.get(n)??[]:[];if(i.length>0)i[0].focus();else{this.nodeGroups[(e+1)%this.nodeGroups.length].focus()}}else if("ArrowLeft"===n||"ArrowUp"===n){o.preventDefault();this.nodeGroups[(e-1+this.nodeGroups.length)%this.nodeGroups.length].focus()}})),t.addEventListener("focus",(()=>{var e;if(this.isKeyboardUser){this.applyFocusRing(t);const o=t.getAttribute(mt);o&&(null==(e=this.pathHighlighter)||e.highlightNode(o))}if(this.tooltipId){const e=t.querySelector("rect");if(e){const t=e.getBoundingClientRect();e.dispatchEvent(new MouseEvent("mouseover",{clientX:t.left+t.width/2,clientY:t.top,bubbles:!0}))}}})),t.addEventListener("blur",(()=>{var e;this.restoreFocusRing(t),null==(e=this.pathHighlighter)||e.reset(),this.hideTooltip()}))}));for(const t of this.edgePaths){const e=()=>{const e=this.edgeSourceNode.get(t);return e?this.nodeOutEdges.get(e)??[]:[]},o=()=>{const e=this.edgeSourceNode.get(t),o=e?this.nodeGroups.find((t=>t.getAttribute(mt)===e)):void 0;o&&o.focus()};t.addEventListener("keydown",(n=>{const i=n.key;if("Enter"===i||" "===i)n.preventDefault(),t.dispatchEvent(new MouseEvent("click",{bubbles:!0}));else if("Escape"===i||"ArrowLeft"===i)n.preventDefault(),o();else if("ArrowDown"===i){n.preventDefault();const o=e(),i=o.indexOf(t);o[(i+1)%o.length].focus()}else if("ArrowUp"===i){n.preventDefault();const o=e(),i=o.indexOf(t);o[(i-1+o.length)%o.length].focus()}else if("ArrowRight"===i){n.preventDefault();const e=t.getAttribute(At),o=e?this.nodeGroups.find((t=>t.getAttribute(mt)===e)):void 0;o&&o.focus()}else if("Tab"===i){const e=this.edgeSourceNode.get(t),o=this.nodeGroups.findIndex((t=>t.getAttribute(mt)===e));if(-1!==o){const t=n.shiftKey?(o-1+this.nodeGroups.length)%this.nodeGroups.length:(o+1)%this.nodeGroups.length;n.preventDefault(),this.nodeGroups[t].focus()}}})),t.addEventListener("focus",(()=>{var e;if(this.isKeyboardUser){const o=t.getAttribute("data-edge-source"),n=t.getAttribute(At);o&&n&&(null==(e=this.pathHighlighter)||e.highlightEdge(o,n))}if(this.tooltipId){const e=t.getBoundingClientRect();t.dispatchEvent(new MouseEvent("mouseover",{clientX:e.left+e.width/2,clientY:e.top+e.height/2,bubbles:!0}))}})),t.addEventListener("blur",(t=>{var e;const o=t.relatedTarget;o&&this.edgePaths.includes(o)||(null==(e=this.pathHighlighter)||e.reset(),this.hideTooltip())}))}}hideTooltip(){if(this.tooltipId){const t=document.getElementById(this.tooltipId);t&&(t.style.display="none")}}applyFocusRing(t){const e=t.querySelector("rect");e&&(e.setAttribute(vt,e.getAttribute(bt)??""),e.setAttribute(yt,e.getAttribute(xt)??""),e.setAttribute(bt,pt),e.setAttribute(xt,"2"))}restoreFocusRing(t){const e=t.querySelector("rect");if(!e)return;const o=e.getAttribute(vt),n=e.getAttribute(yt);null!==o&&(e.setAttribute(bt,o),e.removeAttribute(vt)),null!==n&&(e.setAttribute(xt,n),e.removeAttribute(yt))}setupHighContrastMode(){if("undefined"!=typeof window&&"function"==typeof window.matchMedia)try{const t=window.matchMedia("(forced-colors: active)");this.mediaQuery=t,t.matches&&this.svgEl.classList.add(wt),this.forcedColorsHandler=t=>{t.matches?this.svgEl.classList.add(wt):this.svgEl.classList.remove(wt)},t.addEventListener("change",this.forcedColorsHandler)}catch{}}}const kt="http://www.w3.org/2000/svg";class $t extends ct{constructor(t,e,o){super(t,e,o),this.a11yHelper=null,this.pathHighlighter=null,this._hasAnimated=!1,this.renderOptions=e,this.messages=lt(e)}getMessages(){return this.messages}get isRtl(){var t;return function(t,e){var o;if("rtl"===t)return!0;if("ltr"===t)return!1;if("undefined"==typeof window||"undefined"==typeof document)return!1;if(e){const t=e.closest('[dir="rtl"], [dir="ltr"]');return t?"rtl"===t.getAttribute("dir"):"rtl"===window.getComputedStyle(e).direction}return"rtl"===((null==(o=document.documentElement)?void 0:o.getAttribute("dir"))??document.dir)}((null==(t=this.options.locale)?void 0:t.direction)??"ltr",this.element)}construct(t){const{edgeGap:e,nodeWidth:o,spacing:n,viewPortHeight:i,viewPortWidth:r,whitespace:s}=this.options,a=J({edgeGap:e,nodeWidth:o,whitespace:s});a.size([r-o,i-n]);const d=t.nodes.map(((t,e)=>{const o=e%tt.length;return{...t,color:t.color??tt[o],colorIndex:o}})),l=a(t.edges,d);this.maxRank=(a.order()??[]).length-1,this.graph=l,this.isRtl&&this.mirrorLayoutForRtl()}mirrorLayoutForRtl(){const t=this.graph.nodes();let e=1/0,o=-1/0;for(const n of t){const t=this.graph.node(n).x;void 0!==t&&(e=Math.min(e,t),o=Math.max(o,t))}if(!Number.isFinite(e))return;const n=e+o;for(const e of t){const t=this.graph.node(e);void 0!==t.x&&(t.x=n-t.x)}for(const t of this.graph.edges()){const e=this.graph.edge(t.v,t.w,t.name);if(void 0!==e.x0&&(e.x0=n-e.x0),void 0!==e.x1&&(e.x1=n-e.x1),e.points)for(const t of e.points)void 0!==t.x&&(t.x=n-t.x)}}render({keepOldPosition:t=!1}={}){var e,o;this.renderOptions=ut(this.element,this.options);const{tooltipTheme:n,tooltipBGColor:i,tooltipBorderColor:r,tooltipFontColor:s}=this.renderOptions;"dark"===n?this.renderOptions={...this.renderOptions,tooltipBGColor:"#1e2433",tooltipBorderColor:"#374151",tooltipFontColor:"#e5e7eb"}:"light"===n&&(this.renderOptions={...this.renderOptions,tooltipBGColor:i,tooltipBorderColor:r,tooltipFontColor:s});const{enableTooltip:a,fontColor:d,fontFamily:l,fontSize:c,fontWeight:h,highlightConnectedPath:u,dimOpacity:p,nodeBorderColor:f,nodeBorderWidth:m,nodeWidth:v,nodeTooltipTemplate:b,onNodeClick:x,tooltipBGColor:w,tooltipBorderColor:E,tooltipFontColor:A,tooltipId:C}=this.renderOptions,S=this.canvas.viewbox();this.clear(),this.pathHighlighter=u?new ht(this.canvas.node,this.graph,p):null;const k=((t={})=>{const e=[];for(const n in t){const i=`${o=n,o.replace(/([A-Z])/g,(t=>`-${t.toLowerCase()}`))}: ${t[n]};`;e.push(i)}var o;return e.join(" ")})({color:d,fontFamily:l,fontSize:c,fontWeight:h}),$=g(v/2,0);$.attr("style",k);const M=(null==(e=this.graph)?void 0:e.nodes())||[],L=(null==(o=this.graph)?void 0:o.edges())||[],T=g();L.forEach((t=>{this.renderEdge(t,T)})),$.add(T);const R=g();R.node.setAttribute("role","list"),R.node.setAttribute("aria-label",this.messages.nodesGroupLabel),M.forEach((t=>{const e=this.graph.node(t);if(e.dummy)return;let o;if(a&&b){const e=this.graph.inEdges(t)??[],n=this.graph.outEdges(t)??[],i=e.reduce(((t,e)=>{var o;return t+((null==(o=this.graph.edge(e.v,e.w,e.name))?void 0:o.value)??0)}),0),r=n.reduce(((t,e)=>{var o;return t+((null==(o=this.graph.edge(e.v,e.w,e.name))?void 0:o.value)??0)}),0),s=Math.max(i,r);o={chartContext:this.chartContext,isCustomTooltip:b!==at.nodeTooltipTemplate,nodeTooltipTemplate:b,nodeValue:s,tooltipBGColor:w,tooltipBorderColor:E,tooltipFontColor:A,tooltipId:C}}const n=st(e,this.maxRank,{fontColor:d,fontFamily:l,fontSize:c,fontWeight:h,isRtl:this.isRtl,nodeBorderColor:f,nodeBorderWidth:m,nodeWidth:v,nodeTooltip:o,onNodeClick:x});if(n.node.setAttribute("data-node-id",t),n.node.setAttribute("data-node-rank",String(e.rank??0)),this.pathHighlighter){const e=this.pathHighlighter;n.node.addEventListener("mouseenter",(()=>e.highlightNode(t))),n.node.addEventListener("mouseleave",(()=>e.reset()))}R.add(n)})),$.add(R),this.add($);const{animation:_}=this.renderOptions;if((null==_?void 0:_.enabled)&&!this._hasAnimated&&(this._hasAnimated=!0,function(t,e,o,n,i){if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;const r=t.viewBox.baseVal,s=r.width,a=r.x,d=t.querySelector("defs")??(()=>{const e=document.createElementNS(kt,"defs");return t.insertBefore(e,t.firstChild),e})(),l=`sankey-flow-clip-${Math.random().toString(36).slice(2,9)}`,c=document.createElementNS(kt,"clipPath");c.setAttribute("id",l);const h=document.createElementNS(kt,"rect");h.setAttribute("x",String(a)),h.setAttribute("y","-9999"),h.setAttribute("height","99999"),h.setAttribute("width","0"),c.appendChild(h),d.appendChild(c),e.setAttribute("clip-path",`url(#${l})`);let u=null;requestAnimationFrame((function t(o){null===u&&(u=o);const n=o-u,r=Math.min(n/i,1),a=((d=r)<.5?2*d*d:(4-2*d)*d-1)*s;var d;h.setAttribute("width",String(a)),r<1?requestAnimationFrame(t):(e.removeAttribute("clip-path"),c.remove())}));const p=o.querySelectorAll("[data-node-rank]"),g=.1*i,f=.7*i-g,m=.45*i;p.forEach((t=>{const e=parseInt(t.getAttribute("data-node-rank")??"0",10),o=g+(n>0?e/n:0)*f;t.style.opacity="0",t.animate([{opacity:"0",transform:"translateY(6px)"},{opacity:"1",transform:"translateY(0px)"}],{duration:m,delay:o,easing:"cubic-bezier(0.4, 0, 0.2, 1)",fill:"forwards"}).onfinish=()=>{t.style.opacity="",t.style.transform=""}}))}(this.canvas.node,T.node,R.node,this.maxRank,_.duration)),t&&this.updateViewBox(S.x,S.y,S.width,S.height),a){const t=y(this.chartContext,C);this.chartContext.getAppendContainer().appendChild(t)}this.a11yHelper&&this.a11yHelper.destroy();const B=this.renderOptions.a11y;!1!==(null==B?void 0:B.enabled)&&(this.a11yHelper=new St(this.canvas.node,this.graph,B,C,this.pathHighlighter,this.messages),this.a11yHelper.apply())}renderEdge(t,e){const{edgeGradientFill:o,edgeOpacity:n,enableTooltip:i,fontFamily:r,fontSize:s,fontWeight:a,nodeWidth:d,tooltipBGColor:c,tooltipBorderColor:h,tooltipFontColor:u,tooltipId:p,tooltipTemplate:g}=this.renderOptions,f=this.graph.edge(t.v,t.w,t.name),m=this.graph.node(t.v),v=this.graph.node(t.w),w=f.source,E=f.target;if(!w||!E)return;const A=this.isRtl?-1:1;m.dummy&&(f.x0=(f.x0??0)-d/2*A),v.dummy&&(f.x1=(f.x1??0)+d/2*A);const C=nt(f);if(!C)return;const S=function(t,{edgeColor:e,id:o="",opacity:n=1}={}){const i=new l({d:t});return i.id(o),i.fill(e).opacity(n),i}(C,{edgeColor:this.canvas.gradient("linear",(t=>{var e,n,i;t.stop(0,(null==(e=w.data)?void 0:e.color)??""),t.stop(1,o?(null==(n=E.data)?void 0:n.color)??"":(null==(i=w.data)?void 0:i.color)??"")})),id:`${t.v}-${t.w}`,opacity:n});if(S.node.setAttribute("data-edge-source",t.v),S.node.setAttribute("data-edge-target",t.w),void 0!==t.name&&S.node.setAttribute("data-edge-name",t.name),this.pathHighlighter){const e=this.pathHighlighter,o=t.v,n=t.w;S.on("mouseenter",(()=>e.highlightEdge(o,n))),S.on("mouseleave",(()=>e.reset()))}if(i&&w.data&&E.data){const t=g?g({source:w.data,target:E.data,value:f.value}):`${w.data.title} → ${E.data.title}: ${f.value}`,e=g!==at.tooltipTemplate;S.on("mouseover",(o=>{const{pageX:n,pageY:i}=o,d=x({bgColor:e?void 0:c,borderColor:e?void 0:h,fontColor:e?void 0:u,fontFamily:e?void 0:r,fontSize:e?void 0:s,fontWeight:e?void 0:a,x:n,y:i});b(this.chartContext,p,d,t,!0)})),S.on("mousemove",(o=>{const{pageX:n,pageY:i}=o,d=x({bgColor:e?void 0:c,borderColor:e?void 0:h,fontColor:e?void 0:u,fontFamily:e?void 0:r,fontSize:e?void 0:s,fontWeight:e?void 0:a,x:n,y:i});b(this.chartContext,p,d,t,!0)})),S.on("mouseout",(()=>{y(this.chartContext,p).style.display="none"}))}e.add(S)}}class Mt extends o{constructor(t,e={}){super(t,"sankey_"+crypto.randomUUID().replace(/-/g,"").substring(0,9)),this.options={...at,...e};const{height:o,width:n}=this.options;this.graph=new $t(this.element,this.options,this.chartContext),this.setupElementDimensions(n,o),this.handleWatermark()}static setLicense(t){A.setLicense(t)}setupElementDimensions(t,e){let o=!1,n=0;"string"==typeof t&&/^\d+(\.\d+)?%$/.test(t)?(n=Number(t.substring(0,t.length-1)),o=!0):n=Number(t);const i="auto"===e?n/1.6:e;this.element.style.width=`${n}${o?"%":"px"}`,this.element.style.height=`${i}${o?"%":"px"}`,this.element.style.position="relative"}handleWatermark(){this.element&&(A.isLicenseValid()?S.remove(this.element):S.add(this.element))}render(t){var e,o,n;if(!this.element)throw new Error("Element not found");if(o=this.element,n=(null==(e=this.options.locale)?void 0:e.direction)??"ltr",o&&("ltr"===n?o.removeAttribute("dir"):o.setAttribute("dir",n)),this.graph.construct(t),this.graph.render(),this.options.enableToolbar){new m(this.element,this.chartContext).render({enableExport:!0,onExport:this.graph.exportToSvg.bind(this.graph)})}return this.graph}}"undefined"!=typeof window&&(window.ApexSankey=Mt);export{Mt as ApexSankey,dt as DEFAULT_SANKEY_MESSAGES,Mt as default};