@luxfi/ui 6.1.2 → 7.0.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/dist/accordion.cjs +213 -0
- package/dist/accordion.d.cts +74 -0
- package/dist/accordion.d.ts +74 -0
- package/dist/accordion.js +186 -0
- package/dist/alert.cjs +553 -0
- package/dist/alert.d.cts +30 -0
- package/dist/alert.d.ts +30 -0
- package/dist/alert.js +531 -0
- package/dist/avatar.cjs +149 -0
- package/dist/avatar.d.cts +25 -0
- package/dist/avatar.d.ts +25 -0
- package/dist/avatar.js +125 -0
- package/dist/badge.cjs +611 -0
- package/dist/badge.d.cts +23 -0
- package/dist/badge.d.ts +23 -0
- package/dist/badge.js +589 -0
- package/dist/bank.cjs +272 -0
- package/dist/bank.d.cts +76 -0
- package/dist/bank.d.ts +76 -0
- package/dist/bank.js +258 -0
- package/dist/button.cjs +689 -0
- package/dist/button.d.cts +52 -0
- package/dist/button.d.ts +52 -0
- package/dist/button.js +664 -0
- package/dist/checkbox.cjs +265 -0
- package/dist/checkbox.d.cts +31 -0
- package/dist/checkbox.d.ts +31 -0
- package/dist/checkbox.js +241 -0
- package/dist/close-button.cjs +73 -0
- package/dist/close-button.d.cts +9 -0
- package/dist/close-button.d.ts +9 -0
- package/dist/close-button.js +51 -0
- package/dist/collapsible.cjs +702 -0
- package/dist/collapsible.d.cts +23 -0
- package/dist/collapsible.d.ts +23 -0
- package/dist/collapsible.js +679 -0
- package/dist/color-mode.cjs +96 -0
- package/dist/color-mode.d.cts +25 -0
- package/dist/color-mode.d.ts +25 -0
- package/dist/color-mode.js +72 -0
- package/dist/dialog.cjs +279 -0
- package/dist/dialog.d.cts +66 -0
- package/dist/dialog.d.ts +66 -0
- package/dist/dialog.js +246 -0
- package/dist/drawer.cjs +207 -0
- package/dist/drawer.d.cts +36 -0
- package/dist/drawer.d.ts +36 -0
- package/dist/drawer.js +175 -0
- package/dist/empty-state.cjs +93 -0
- package/dist/empty-state.d.cts +13 -0
- package/dist/empty-state.d.ts +13 -0
- package/dist/empty-state.js +71 -0
- package/dist/expiration-selector.cjs +138 -0
- package/dist/expiration-selector.d.cts +16 -0
- package/dist/expiration-selector.d.ts +16 -0
- package/dist/expiration-selector.js +116 -0
- package/dist/field.cjs +183 -0
- package/dist/field.d.cts +24 -0
- package/dist/field.d.ts +24 -0
- package/dist/field.js +160 -0
- package/dist/greeks-display.cjs +114 -0
- package/dist/greeks-display.d.cts +14 -0
- package/dist/greeks-display.d.ts +14 -0
- package/dist/greeks-display.js +92 -0
- package/dist/heading.cjs +46 -0
- package/dist/heading.d.cts +10 -0
- package/dist/heading.d.ts +10 -0
- package/dist/heading.js +40 -0
- package/dist/icon-button.cjs +491 -0
- package/dist/icon-button.d.cts +33 -0
- package/dist/icon-button.d.ts +33 -0
- package/dist/icon-button.js +470 -0
- package/dist/image.cjs +572 -0
- package/dist/image.d.cts +57 -0
- package/dist/image.d.ts +57 -0
- package/dist/image.js +551 -0
- package/dist/index.cjs +7316 -0
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +7137 -0
- package/dist/input-group.cjs +155 -0
- package/dist/input-group.d.cts +17 -0
- package/dist/input-group.d.ts +17 -0
- package/dist/input-group.js +133 -0
- package/dist/input.cjs +65 -0
- package/dist/input.d.cts +11 -0
- package/dist/input.d.ts +11 -0
- package/dist/input.js +59 -0
- package/dist/link.cjs +630 -0
- package/dist/link.d.cts +37 -0
- package/dist/link.d.ts +37 -0
- package/dist/link.js +606 -0
- package/dist/menu.cjs +305 -0
- package/dist/menu.d.cts +84 -0
- package/dist/menu.d.ts +84 -0
- package/dist/menu.js +269 -0
- package/dist/option-chain.cjs +221 -0
- package/dist/option-chain.d.cts +37 -0
- package/dist/option-chain.d.ts +37 -0
- package/dist/option-chain.js +199 -0
- package/dist/option-position.cjs +164 -0
- package/dist/option-position.d.cts +29 -0
- package/dist/option-position.d.ts +29 -0
- package/dist/option-position.js +142 -0
- package/dist/pin-input.cjs +182 -0
- package/dist/pin-input.d.cts +25 -0
- package/dist/pin-input.d.ts +25 -0
- package/dist/pin-input.js +160 -0
- package/dist/pnl-diagram.cjs +453 -0
- package/dist/pnl-diagram.d.cts +11 -0
- package/dist/pnl-diagram.d.ts +11 -0
- package/dist/pnl-diagram.js +431 -0
- package/dist/popover.cjs +327 -0
- package/dist/popover.d.cts +73 -0
- package/dist/popover.d.ts +73 -0
- package/dist/popover.js +294 -0
- package/dist/progress-circle.cjs +152 -0
- package/dist/progress-circle.d.cts +47 -0
- package/dist/progress-circle.d.ts +47 -0
- package/dist/progress-circle.js +128 -0
- package/dist/progress.cjs +117 -0
- package/dist/progress.d.cts +28 -0
- package/dist/progress.d.ts +28 -0
- package/dist/progress.js +94 -0
- package/dist/provider.cjs +62 -0
- package/dist/provider.d.cts +7 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +40 -0
- package/dist/radio.cjs +177 -0
- package/dist/radio.d.cts +53 -0
- package/dist/radio.d.ts +53 -0
- package/dist/radio.js +153 -0
- package/dist/rating.cjs +80 -0
- package/dist/rating.d.cts +14 -0
- package/dist/rating.d.ts +14 -0
- package/dist/rating.js +58 -0
- package/dist/select.cjs +791 -0
- package/dist/select.d.cts +130 -0
- package/dist/select.d.ts +130 -0
- package/dist/select.js +757 -0
- package/dist/separator.cjs +57 -0
- package/dist/separator.d.cts +13 -0
- package/dist/separator.d.ts +13 -0
- package/dist/separator.js +51 -0
- package/dist/skeleton.cjs +370 -0
- package/dist/skeleton.d.cts +60 -0
- package/dist/skeleton.d.ts +60 -0
- package/dist/skeleton.js +346 -0
- package/dist/slider.cjs +138 -0
- package/dist/slider.d.cts +24 -0
- package/dist/slider.d.ts +24 -0
- package/dist/slider.js +115 -0
- package/dist/strategy-builder.cjs +373 -0
- package/dist/strategy-builder.d.cts +26 -0
- package/dist/strategy-builder.d.ts +26 -0
- package/dist/strategy-builder.js +351 -0
- package/dist/switch.cjs +163 -0
- package/dist/switch.d.cts +27 -0
- package/dist/switch.d.ts +27 -0
- package/dist/switch.js +140 -0
- package/dist/table.cjs +1044 -0
- package/dist/table.d.cts +107 -0
- package/dist/table.d.ts +107 -0
- package/dist/table.js +1013 -0
- package/dist/tabs.cjs +240 -0
- package/dist/tabs.d.cts +78 -0
- package/dist/tabs.d.ts +78 -0
- package/dist/tabs.js +213 -0
- package/dist/tag.cjs +651 -0
- package/dist/tag.d.cts +21 -0
- package/dist/tag.d.ts +21 -0
- package/dist/tag.js +628 -0
- package/dist/textarea.cjs +65 -0
- package/dist/textarea.d.cts +11 -0
- package/dist/textarea.d.ts +11 -0
- package/dist/textarea.js +59 -0
- package/dist/toaster.cjs +99 -0
- package/dist/toaster.d.cts +29 -0
- package/dist/toaster.d.ts +29 -0
- package/dist/toaster.js +96 -0
- package/dist/tooltip.cjs +171 -0
- package/dist/tooltip.d.cts +39 -0
- package/dist/tooltip.d.ts +39 -0
- package/dist/tooltip.js +148 -0
- package/dist/utils.cjs +11 -0
- package/dist/utils.d.cts +5 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +9 -0
- package/package.json +284 -85
- package/src/accordion.tsx +285 -0
- package/src/alert.tsx +221 -0
- package/src/avatar.tsx +174 -0
- package/src/badge.tsx +158 -0
- package/src/bank.tsx +325 -0
- package/src/button.tsx +411 -0
- package/src/checkbox.tsx +307 -0
- package/src/close-button.tsx +51 -0
- package/src/collapsible.tsx +126 -0
- package/src/color-mode.tsx +125 -0
- package/src/dialog.tsx +356 -0
- package/src/drawer.tsx +186 -0
- package/src/empty-state.tsx +97 -0
- package/src/expiration-selector.tsx +163 -0
- package/src/field.tsx +202 -0
- package/src/greeks-display.tsx +138 -0
- package/src/heading.tsx +55 -0
- package/src/icon-button.tsx +192 -0
- package/src/image.tsx +280 -0
- package/src/index.ts +268 -0
- package/src/input-group.tsx +159 -0
- package/src/input.tsx +60 -0
- package/src/link.tsx +326 -0
- package/src/menu.tsx +471 -0
- package/src/option-chain.tsx +261 -0
- package/src/option-position.tsx +200 -0
- package/src/pin-input.tsx +187 -0
- package/src/pnl-diagram.tsx +458 -0
- package/src/popover.tsx +400 -0
- package/src/progress-circle.tsx +180 -0
- package/src/progress.tsx +109 -0
- package/src/provider.tsx +12 -0
- package/src/radio.tsx +175 -0
- package/src/rating.tsx +79 -0
- package/src/select.tsx +696 -0
- package/src/separator.tsx +59 -0
- package/src/skeleton.tsx +302 -0
- package/src/slider.tsx +152 -0
- package/src/strategy-builder.tsx +466 -0
- package/src/switch.tsx +158 -0
- package/src/table.tsx +621 -0
- package/src/tabs.tsx +354 -0
- package/src/tag.tsx +159 -0
- package/src/textarea.tsx +60 -0
- package/src/toaster.tsx +117 -0
- package/src/tokens.css +438 -0
- package/src/tooltip.tsx +184 -0
- package/src/utils/cn.ts +7 -0
- package/src/utils.ts +6 -0
- package/tokens.css +438 -0
- package/README.md +0 -109
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
|
+
import { twMerge } from 'tailwind-merge';
|
|
5
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
function cn(...inputs) {
|
|
8
|
+
return twMerge(clsx(inputs));
|
|
9
|
+
}
|
|
10
|
+
function calcLegPnl(leg, price, multiplier) {
|
|
11
|
+
const premium = leg.premium ?? 0;
|
|
12
|
+
let intrinsic;
|
|
13
|
+
if (leg.type === "call") {
|
|
14
|
+
intrinsic = Math.max(price - leg.strike, 0);
|
|
15
|
+
} else {
|
|
16
|
+
intrinsic = Math.max(leg.strike - price, 0);
|
|
17
|
+
}
|
|
18
|
+
const sign = leg.action === "buy" ? 1 : -1;
|
|
19
|
+
return sign * (intrinsic - premium) * leg.quantity * multiplier;
|
|
20
|
+
}
|
|
21
|
+
function calcTotalPnl(legs, price, multiplier) {
|
|
22
|
+
return legs.reduce((sum, leg) => sum + calcLegPnl(leg, price, multiplier), 0);
|
|
23
|
+
}
|
|
24
|
+
function buildPath(points, vb, width, height) {
|
|
25
|
+
if (points.length === 0) return "";
|
|
26
|
+
const scaleX = (x) => (x - vb.xMin) / (vb.xMax - vb.xMin) * width;
|
|
27
|
+
const scaleY = (y) => height - (y - vb.yMin) / (vb.yMax - vb.yMin) * height;
|
|
28
|
+
const parts = points.map((p, i) => {
|
|
29
|
+
const sx = scaleX(p.x);
|
|
30
|
+
const sy = scaleY(p.y);
|
|
31
|
+
return i === 0 ? `M${sx},${sy}` : `L${sx},${sy}`;
|
|
32
|
+
});
|
|
33
|
+
return parts.join(" ");
|
|
34
|
+
}
|
|
35
|
+
var LEG_COLORS = ["#6366f1", "#f59e0b", "#ec4899", "#06b6d4"];
|
|
36
|
+
var PnlDiagram = React.forwardRef(
|
|
37
|
+
function PnlDiagram2(props, ref) {
|
|
38
|
+
const {
|
|
39
|
+
legs,
|
|
40
|
+
spotPrice,
|
|
41
|
+
multiplier = 100,
|
|
42
|
+
className,
|
|
43
|
+
...rest
|
|
44
|
+
} = props;
|
|
45
|
+
const containerRef = React.useRef(null);
|
|
46
|
+
const [hoverX, setHoverX] = React.useState(null);
|
|
47
|
+
const [dims, setDims] = React.useState({ width: 600, height: 240 });
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
const el = containerRef.current;
|
|
50
|
+
if (!el) return;
|
|
51
|
+
const observer = new ResizeObserver((entries) => {
|
|
52
|
+
const entry = entries[0];
|
|
53
|
+
if (entry) {
|
|
54
|
+
setDims({
|
|
55
|
+
width: Math.max(entry.contentRect.width, 200),
|
|
56
|
+
height: Math.max(entry.contentRect.height, 120)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
observer.observe(el);
|
|
61
|
+
return () => observer.disconnect();
|
|
62
|
+
}, []);
|
|
63
|
+
const allStrikes = legs.map((l) => l.strike);
|
|
64
|
+
const minStrike = Math.min(...allStrikes, spotPrice);
|
|
65
|
+
const maxStrike = Math.max(...allStrikes, spotPrice);
|
|
66
|
+
const range = maxStrike - minStrike || spotPrice * 0.1;
|
|
67
|
+
const xMin = minStrike - range * 0.3;
|
|
68
|
+
const xMax = maxStrike + range * 0.3;
|
|
69
|
+
const SAMPLES = 200;
|
|
70
|
+
const step = (xMax - xMin) / SAMPLES;
|
|
71
|
+
const combinedPoints = React.useMemo(() => {
|
|
72
|
+
const pts = [];
|
|
73
|
+
for (let i = 0; i <= SAMPLES; i++) {
|
|
74
|
+
const price = xMin + i * step;
|
|
75
|
+
pts.push({ x: price, y: calcTotalPnl(legs, price, multiplier) });
|
|
76
|
+
}
|
|
77
|
+
return pts;
|
|
78
|
+
}, [legs, multiplier, xMin, step]);
|
|
79
|
+
const legPointSets = React.useMemo(() => {
|
|
80
|
+
return legs.map((leg) => {
|
|
81
|
+
const pts = [];
|
|
82
|
+
for (let i = 0; i <= SAMPLES; i++) {
|
|
83
|
+
const price = xMin + i * step;
|
|
84
|
+
pts.push({ x: price, y: calcLegPnl(leg, price, multiplier) });
|
|
85
|
+
}
|
|
86
|
+
return pts;
|
|
87
|
+
});
|
|
88
|
+
}, [legs, multiplier, xMin, step]);
|
|
89
|
+
const allY = combinedPoints.map((p) => p.y);
|
|
90
|
+
const rawYMin = Math.min(...allY);
|
|
91
|
+
const rawYMax = Math.max(...allY);
|
|
92
|
+
const yPad = Math.max((rawYMax - rawYMin) * 0.15, 10);
|
|
93
|
+
const vb = { xMin, xMax, yMin: rawYMin - yPad, yMax: rawYMax + yPad };
|
|
94
|
+
const { width, height } = dims;
|
|
95
|
+
const PADDING = { top: 20, bottom: 28, left: 56, right: 16 };
|
|
96
|
+
const chartW = width - PADDING.left - PADDING.right;
|
|
97
|
+
const chartH = height - PADDING.top - PADDING.bottom;
|
|
98
|
+
const scaleX = (x) => PADDING.left + (x - vb.xMin) / (vb.xMax - vb.xMin) * chartW;
|
|
99
|
+
const scaleY = (y) => PADDING.top + chartH - (y - vb.yMin) / (vb.yMax - vb.yMin) * chartH;
|
|
100
|
+
const breakevens = React.useMemo(() => {
|
|
101
|
+
const pts = [];
|
|
102
|
+
for (let i = 1; i < combinedPoints.length; i++) {
|
|
103
|
+
const prev = combinedPoints[i - 1];
|
|
104
|
+
const curr = combinedPoints[i];
|
|
105
|
+
if (prev.y <= 0 && curr.y >= 0 || prev.y >= 0 && curr.y <= 0) {
|
|
106
|
+
const ratio = Math.abs(prev.y) / (Math.abs(prev.y) + Math.abs(curr.y));
|
|
107
|
+
pts.push(prev.x + ratio * (curr.x - prev.x));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return pts;
|
|
111
|
+
}, [combinedPoints]);
|
|
112
|
+
const maxGain = Math.max(...allY);
|
|
113
|
+
const maxLoss = Math.min(...allY);
|
|
114
|
+
const maxGainPoint = combinedPoints.find((p) => p.y === maxGain);
|
|
115
|
+
const maxLossPoint = combinedPoints.find((p) => p.y === maxLoss);
|
|
116
|
+
const zeroY = scaleY(0);
|
|
117
|
+
const handleMouseMove = React.useCallback(
|
|
118
|
+
(e) => {
|
|
119
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
120
|
+
const mouseX = e.clientX - rect.left;
|
|
121
|
+
const price = vb.xMin + (mouseX - PADDING.left) / chartW * (vb.xMax - vb.xMin);
|
|
122
|
+
if (price >= vb.xMin && price <= vb.xMax) {
|
|
123
|
+
setHoverX(price);
|
|
124
|
+
} else {
|
|
125
|
+
setHoverX(null);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
[vb.xMin, vb.xMax, chartW]
|
|
129
|
+
);
|
|
130
|
+
const handleMouseLeave = React.useCallback(() => setHoverX(null), []);
|
|
131
|
+
const hoverPnl = hoverX !== null ? calcTotalPnl(legs, hoverX, multiplier) : null;
|
|
132
|
+
buildPath(
|
|
133
|
+
combinedPoints.map((p) => ({ x: scaleX(p.x), y: scaleY(p.y) })).map((p) => ({ x: p.x - PADDING.left, y: p.y - PADDING.top })),
|
|
134
|
+
{ xMin: 0, xMax: chartW, yMin: 0, yMax: chartH },
|
|
135
|
+
chartW,
|
|
136
|
+
chartH
|
|
137
|
+
);
|
|
138
|
+
return /* @__PURE__ */ jsxs(
|
|
139
|
+
"div",
|
|
140
|
+
{
|
|
141
|
+
ref,
|
|
142
|
+
className: cn("w-full", className),
|
|
143
|
+
...rest,
|
|
144
|
+
children: [
|
|
145
|
+
/* @__PURE__ */ jsx("div", { ref: containerRef, className: "w-full h-full min-h-[200px]", children: /* @__PURE__ */ jsxs(
|
|
146
|
+
"svg",
|
|
147
|
+
{
|
|
148
|
+
width,
|
|
149
|
+
height,
|
|
150
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
151
|
+
className: "select-none",
|
|
152
|
+
onMouseMove: handleMouseMove,
|
|
153
|
+
onMouseLeave: handleMouseLeave,
|
|
154
|
+
children: [
|
|
155
|
+
/* @__PURE__ */ jsx("rect", { x: PADDING.left, y: PADDING.top, width: chartW, height: chartH, fill: "#09090b", rx: "2" }),
|
|
156
|
+
Array.from({ length: 5 }).map((_, i) => {
|
|
157
|
+
const y = PADDING.top + chartH / 4 * i;
|
|
158
|
+
const val = vb.yMax - (vb.yMax - vb.yMin) / 4 * i;
|
|
159
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
160
|
+
/* @__PURE__ */ jsx(
|
|
161
|
+
"line",
|
|
162
|
+
{
|
|
163
|
+
x1: PADDING.left,
|
|
164
|
+
y1: y,
|
|
165
|
+
x2: PADDING.left + chartW,
|
|
166
|
+
y2: y,
|
|
167
|
+
stroke: "#27272a",
|
|
168
|
+
strokeWidth: "1",
|
|
169
|
+
strokeDasharray: "2,2"
|
|
170
|
+
}
|
|
171
|
+
),
|
|
172
|
+
/* @__PURE__ */ jsxs(
|
|
173
|
+
"text",
|
|
174
|
+
{
|
|
175
|
+
x: PADDING.left - 4,
|
|
176
|
+
y: y + 3,
|
|
177
|
+
fill: "#71717a",
|
|
178
|
+
fontSize: "9",
|
|
179
|
+
fontFamily: "monospace",
|
|
180
|
+
textAnchor: "end",
|
|
181
|
+
children: [
|
|
182
|
+
val >= 0 ? "+" : "",
|
|
183
|
+
val.toFixed(0)
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
] }, `grid-y-${i}`);
|
|
188
|
+
}),
|
|
189
|
+
zeroY >= PADDING.top && zeroY <= PADDING.top + chartH && /* @__PURE__ */ jsx(
|
|
190
|
+
"line",
|
|
191
|
+
{
|
|
192
|
+
x1: PADDING.left,
|
|
193
|
+
y1: zeroY,
|
|
194
|
+
x2: PADDING.left + chartW,
|
|
195
|
+
y2: zeroY,
|
|
196
|
+
stroke: "#3f3f46",
|
|
197
|
+
strokeWidth: "1"
|
|
198
|
+
}
|
|
199
|
+
),
|
|
200
|
+
legPointSets.map((pts, i) => {
|
|
201
|
+
const path = pts.map((p, j) => {
|
|
202
|
+
const sx = scaleX(p.x);
|
|
203
|
+
const sy = scaleY(p.y);
|
|
204
|
+
return j === 0 ? `M${sx},${sy}` : `L${sx},${sy}`;
|
|
205
|
+
}).join(" ");
|
|
206
|
+
return /* @__PURE__ */ jsx(
|
|
207
|
+
"path",
|
|
208
|
+
{
|
|
209
|
+
d: path,
|
|
210
|
+
fill: "none",
|
|
211
|
+
stroke: LEG_COLORS[i % LEG_COLORS.length],
|
|
212
|
+
strokeWidth: "1",
|
|
213
|
+
strokeDasharray: "4,3",
|
|
214
|
+
opacity: "0.5"
|
|
215
|
+
},
|
|
216
|
+
`leg-${i}`
|
|
217
|
+
);
|
|
218
|
+
}),
|
|
219
|
+
combinedPoints.length > 0 && (() => {
|
|
220
|
+
const path = combinedPoints.map((p, i) => {
|
|
221
|
+
const sx = scaleX(p.x);
|
|
222
|
+
const sy = scaleY(p.y);
|
|
223
|
+
return i === 0 ? `M${sx},${sy}` : `L${sx},${sy}`;
|
|
224
|
+
}).join(" ");
|
|
225
|
+
const lastX = scaleX(combinedPoints[combinedPoints.length - 1].x);
|
|
226
|
+
const firstX = scaleX(combinedPoints[0].x);
|
|
227
|
+
const clampedZeroY = Math.max(PADDING.top, Math.min(PADDING.top + chartH, zeroY));
|
|
228
|
+
const fillPath = `${path} L${lastX},${clampedZeroY} L${firstX},${clampedZeroY} Z`;
|
|
229
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
230
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: "pnl-grad", x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
231
|
+
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#22c55e", stopOpacity: "0.15" }),
|
|
232
|
+
/* @__PURE__ */ jsx("stop", { offset: "50%", stopColor: "#22c55e", stopOpacity: "0.02" }),
|
|
233
|
+
/* @__PURE__ */ jsx("stop", { offset: "50%", stopColor: "#ef4444", stopOpacity: "0.02" }),
|
|
234
|
+
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "#ef4444", stopOpacity: "0.15" })
|
|
235
|
+
] }) }),
|
|
236
|
+
/* @__PURE__ */ jsx("path", { d: fillPath, fill: "url(#pnl-grad)" })
|
|
237
|
+
] });
|
|
238
|
+
})(),
|
|
239
|
+
combinedPoints.length > 0 && /* @__PURE__ */ jsx(
|
|
240
|
+
"path",
|
|
241
|
+
{
|
|
242
|
+
d: combinedPoints.map((p, i) => {
|
|
243
|
+
const sx = scaleX(p.x);
|
|
244
|
+
const sy = scaleY(p.y);
|
|
245
|
+
return i === 0 ? `M${sx},${sy}` : `L${sx},${sy}`;
|
|
246
|
+
}).join(" "),
|
|
247
|
+
fill: "none",
|
|
248
|
+
stroke: "#e4e4e7",
|
|
249
|
+
strokeWidth: "1.5"
|
|
250
|
+
}
|
|
251
|
+
),
|
|
252
|
+
/* @__PURE__ */ jsx(
|
|
253
|
+
"line",
|
|
254
|
+
{
|
|
255
|
+
x1: scaleX(spotPrice),
|
|
256
|
+
y1: PADDING.top,
|
|
257
|
+
x2: scaleX(spotPrice),
|
|
258
|
+
y2: PADDING.top + chartH,
|
|
259
|
+
stroke: "#a1a1aa",
|
|
260
|
+
strokeWidth: "1",
|
|
261
|
+
strokeDasharray: "3,3"
|
|
262
|
+
}
|
|
263
|
+
),
|
|
264
|
+
/* @__PURE__ */ jsx(
|
|
265
|
+
"text",
|
|
266
|
+
{
|
|
267
|
+
x: scaleX(spotPrice),
|
|
268
|
+
y: PADDING.top + chartH + 14,
|
|
269
|
+
fill: "#a1a1aa",
|
|
270
|
+
fontSize: "9",
|
|
271
|
+
fontFamily: "monospace",
|
|
272
|
+
textAnchor: "middle",
|
|
273
|
+
children: spotPrice.toFixed(2)
|
|
274
|
+
}
|
|
275
|
+
),
|
|
276
|
+
breakevens.map((be, i) => /* @__PURE__ */ jsxs("g", { children: [
|
|
277
|
+
/* @__PURE__ */ jsx("circle", { cx: scaleX(be), cy: zeroY, r: "3", fill: "#fbbf24", stroke: "#18181b", strokeWidth: "1" }),
|
|
278
|
+
/* @__PURE__ */ jsx(
|
|
279
|
+
"text",
|
|
280
|
+
{
|
|
281
|
+
x: scaleX(be),
|
|
282
|
+
y: PADDING.top + chartH + 14,
|
|
283
|
+
fill: "#fbbf24",
|
|
284
|
+
fontSize: "8",
|
|
285
|
+
fontFamily: "monospace",
|
|
286
|
+
textAnchor: "middle",
|
|
287
|
+
children: be.toFixed(1)
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
] }, `be-${i}`)),
|
|
291
|
+
maxGainPoint && maxGain > 0 && /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
|
|
292
|
+
"polygon",
|
|
293
|
+
{
|
|
294
|
+
points: `${scaleX(maxGainPoint.x)},${scaleY(maxGainPoint.y) - 8} ${scaleX(maxGainPoint.x) - 4},${scaleY(maxGainPoint.y) - 2} ${scaleX(maxGainPoint.x) + 4},${scaleY(maxGainPoint.y) - 2}`,
|
|
295
|
+
fill: "#22c55e"
|
|
296
|
+
}
|
|
297
|
+
) }),
|
|
298
|
+
maxLossPoint && maxLoss < 0 && /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
|
|
299
|
+
"polygon",
|
|
300
|
+
{
|
|
301
|
+
points: `${scaleX(maxLossPoint.x)},${scaleY(maxLossPoint.y) + 8} ${scaleX(maxLossPoint.x) - 4},${scaleY(maxLossPoint.y) + 2} ${scaleX(maxLossPoint.x) + 4},${scaleY(maxLossPoint.y) + 2}`,
|
|
302
|
+
fill: "#ef4444"
|
|
303
|
+
}
|
|
304
|
+
) }),
|
|
305
|
+
hoverX !== null && hoverPnl !== null && /* @__PURE__ */ jsxs("g", { children: [
|
|
306
|
+
/* @__PURE__ */ jsx(
|
|
307
|
+
"line",
|
|
308
|
+
{
|
|
309
|
+
x1: scaleX(hoverX),
|
|
310
|
+
y1: PADDING.top,
|
|
311
|
+
x2: scaleX(hoverX),
|
|
312
|
+
y2: PADDING.top + chartH,
|
|
313
|
+
stroke: "#52525b",
|
|
314
|
+
strokeWidth: "1"
|
|
315
|
+
}
|
|
316
|
+
),
|
|
317
|
+
/* @__PURE__ */ jsx(
|
|
318
|
+
"circle",
|
|
319
|
+
{
|
|
320
|
+
cx: scaleX(hoverX),
|
|
321
|
+
cy: scaleY(hoverPnl),
|
|
322
|
+
r: "3",
|
|
323
|
+
fill: hoverPnl >= 0 ? "#22c55e" : "#ef4444",
|
|
324
|
+
stroke: "#18181b",
|
|
325
|
+
strokeWidth: "1"
|
|
326
|
+
}
|
|
327
|
+
),
|
|
328
|
+
/* @__PURE__ */ jsx(
|
|
329
|
+
"rect",
|
|
330
|
+
{
|
|
331
|
+
x: scaleX(hoverX) + 8,
|
|
332
|
+
y: scaleY(hoverPnl) - 20,
|
|
333
|
+
width: "90",
|
|
334
|
+
height: "28",
|
|
335
|
+
rx: "3",
|
|
336
|
+
fill: "#18181b",
|
|
337
|
+
stroke: "#3f3f46",
|
|
338
|
+
strokeWidth: "1"
|
|
339
|
+
}
|
|
340
|
+
),
|
|
341
|
+
/* @__PURE__ */ jsxs(
|
|
342
|
+
"text",
|
|
343
|
+
{
|
|
344
|
+
x: scaleX(hoverX) + 14,
|
|
345
|
+
y: scaleY(hoverPnl) - 10,
|
|
346
|
+
fill: "#a1a1aa",
|
|
347
|
+
fontSize: "8",
|
|
348
|
+
fontFamily: "monospace",
|
|
349
|
+
children: [
|
|
350
|
+
"$",
|
|
351
|
+
hoverX.toFixed(2)
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
),
|
|
355
|
+
/* @__PURE__ */ jsxs(
|
|
356
|
+
"text",
|
|
357
|
+
{
|
|
358
|
+
x: scaleX(hoverX) + 14,
|
|
359
|
+
y: scaleY(hoverPnl) + 1,
|
|
360
|
+
fill: hoverPnl >= 0 ? "#22c55e" : "#ef4444",
|
|
361
|
+
fontSize: "9",
|
|
362
|
+
fontFamily: "monospace",
|
|
363
|
+
fontWeight: "600",
|
|
364
|
+
children: [
|
|
365
|
+
hoverPnl >= 0 ? "+" : "",
|
|
366
|
+
hoverPnl.toFixed(2)
|
|
367
|
+
]
|
|
368
|
+
}
|
|
369
|
+
)
|
|
370
|
+
] }),
|
|
371
|
+
Array.from({ length: 5 }).map((_, i) => {
|
|
372
|
+
const x = vb.xMin + (vb.xMax - vb.xMin) / 4 * i;
|
|
373
|
+
return /* @__PURE__ */ jsx(
|
|
374
|
+
"text",
|
|
375
|
+
{
|
|
376
|
+
x: scaleX(x),
|
|
377
|
+
y: PADDING.top + chartH + 14,
|
|
378
|
+
fill: "#52525b",
|
|
379
|
+
fontSize: "8",
|
|
380
|
+
fontFamily: "monospace",
|
|
381
|
+
textAnchor: "middle",
|
|
382
|
+
children: x.toFixed(0)
|
|
383
|
+
},
|
|
384
|
+
`x-label-${i}`
|
|
385
|
+
);
|
|
386
|
+
})
|
|
387
|
+
]
|
|
388
|
+
}
|
|
389
|
+
) }),
|
|
390
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-4 px-2 pt-1", children: [
|
|
391
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
392
|
+
/* @__PURE__ */ jsx("div", { className: "h-0.5 w-4 bg-zinc-200 rounded" }),
|
|
393
|
+
/* @__PURE__ */ jsx("span", { className: "text-[10px] text-zinc-400", children: "Combined" })
|
|
394
|
+
] }),
|
|
395
|
+
legs.map((leg, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
396
|
+
/* @__PURE__ */ jsx(
|
|
397
|
+
"div",
|
|
398
|
+
{
|
|
399
|
+
className: "h-0.5 w-4 rounded",
|
|
400
|
+
style: {
|
|
401
|
+
backgroundColor: LEG_COLORS[i % LEG_COLORS.length],
|
|
402
|
+
opacity: 0.6,
|
|
403
|
+
backgroundImage: `repeating-linear-gradient(90deg, transparent, transparent 2px, ${LEG_COLORS[i % LEG_COLORS.length]}00 2px, ${LEG_COLORS[i % LEG_COLORS.length]}00 5px)`
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
),
|
|
407
|
+
/* @__PURE__ */ jsxs("span", { className: "text-[10px] text-zinc-500", children: [
|
|
408
|
+
leg.action === "buy" ? "B" : "S",
|
|
409
|
+
" ",
|
|
410
|
+
leg.quantity,
|
|
411
|
+
" ",
|
|
412
|
+
leg.strike,
|
|
413
|
+
" ",
|
|
414
|
+
leg.type === "call" ? "C" : "P"
|
|
415
|
+
] })
|
|
416
|
+
] }, i)),
|
|
417
|
+
breakevens.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
418
|
+
/* @__PURE__ */ jsx("div", { className: "h-1.5 w-1.5 rounded-full bg-amber-400" }),
|
|
419
|
+
/* @__PURE__ */ jsxs("span", { className: "text-[10px] text-zinc-500", children: [
|
|
420
|
+
"BE: ",
|
|
421
|
+
breakevens.map((b) => b.toFixed(1)).join(", ")
|
|
422
|
+
] })
|
|
423
|
+
] })
|
|
424
|
+
] })
|
|
425
|
+
]
|
|
426
|
+
}
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
export { PnlDiagram };
|