@kodiak-finance/orderly-ui-share 2.8.18-rc.1 → 2.8.19-rc.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/index.mjs CHANGED
@@ -1,13 +1,1552 @@
1
1
  import { useEmblaCarousel, cn, Button, ChevronLeftIcon, ChevronRightIcon, registerSimpleDialog, registerSimpleSheet, Box, Flex, Text, Divider, ScrollArea, Input, CloseCircleFillIcon, toast } from '@kodiak-finance/orderly-ui';
2
- import f, { forwardRef, useImperativeHandle, useMemo, useState, useRef, useEffect, useCallback } from 'react';
2
+ import React, { forwardRef, useImperativeHandle, useMemo, useState, useRef, useEffect, useCallback } from 'react';
3
3
  import { usePoster, useSymbolsInfo, useReferralInfo } from '@kodiak-finance/orderly-hooks';
4
4
  import { i18n, useTranslation } from '@kodiak-finance/orderly-i18n';
5
5
  import { EMPTY_LIST } from '@kodiak-finance/orderly-types';
6
6
  import { jsx, jsxs } from 'react/jsx-runtime';
7
- import { Decimal } from '@kodiak-finance/orderly-utils';
7
+ import { formatNum, Decimal } from '@kodiak-finance/orderly-utils';
8
8
 
9
- var Q=e=>{let{pnl:t,hide:n}=e,r=t?.entity,o=useSymbolsInfo(),{getFirstRefCode:a}=useReferralInfo(),l=useMemo(()=>{let c=a()?.code;return {code:t?.refCode??c,slogan:t?.refSlogan,link:t?.refLink}},[a,t]),u=useMemo(()=>{if(r)return o[r?.symbol]("base_dp")},[r,o]),s=useMemo(()=>{if(r)return o[r?.symbol]("quote_dp")},[r,o]);return {entity:r,baseDp:u,quoteDp:s,referralInfo:l,shareOptions:t,hide:n}};var K=forwardRef((e,t)=>{let{width:n,height:r,className:o,data:a,style:l}=e,{ref:u,download:s,toDataURL:c,copy:i,toBlob:d}=usePoster(a,{ratio:e.ratio});return useImperativeHandle(t,()=>({download:s,toDataURL:c,toBlob:d,copy:i})),jsx("canvas",{ref:u,width:n,height:r,className:o,style:l})});function j(e,t,n,r,o,a,l,u){let{t:s}=useTranslation(),{symbol:c,currency:i}=tt(e.symbol),d={symbol:c,currency:i,side:e.side};switch(r){case "pnl":{e.pnl!=null&&(d.pnl=new Decimal(e.pnl).toFixed(2,Decimal.ROUND_DOWN));break}case "roi":{e.roi!=null&&(d.ROI=new Decimal(e.roi).toFixed(2,Decimal.ROUND_DOWN));break}case "roi_pnl":{e.pnl!=null&&(d.pnl=new Decimal(e.pnl).toFixed(2,Decimal.ROUND_DOWN)),e.roi!=null&&(d.ROI=new Decimal(e.roi).toFixed(2,Decimal.ROUND_DOWN));break}}let h=[];o.has("leverage")&&(d.leverage=e.leverage),["openPrice","closePrice","openTime","closeTime","markPrice","quantity"].forEach(b=>{if(o.has(b))switch(b){case "leverage":break;case "openPrice":{e.openPrice!=null&&h.push({title:s("share.pnl.optionalInfo.openPrice"),value:X(e.openPrice,l||2)});break}case "closePrice":{e.closePrice!=null&&h.push({title:s("share.pnl.optionalInfo.closePrice"),value:X(e.closePrice,l||2)});break}case "openTime":{e.openTime!=null&&h.push({title:s("share.pnl.optionalInfo.openTime"),value:xe(e.openTime)});break}case "closeTime":{e.closeTime!=null&&h.push({title:s("share.pnl.optionalInfo.closeTime"),value:xe(e.closeTime)});break}case "markPrice":{e.markPrice!=null&&h.push({title:s("common.markPrice"),value:X(e.markPrice,l||2)});break}case "quantity":e.quantity!=null&&h.push({title:s("common.quantity"),value:X(e.quantity,a||2)});}}),d.informations=h;let S={position:d,updateTime:ot(new Date),domain:n};return t.length>0&&(S.message=t),typeof u<"u"&&u.code!==void 0&&(S.referral=u),S}function tt(e){let t=e.split("_");if(t.length!==3)return {symbol:e,currency:"USDC"};let[n,r,o]=t;return {symbol:`${r}-${n}`,currency:o||"USDC"}}function ot(e){let t=e instanceof Date?e:new Date(e),n={year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"},o=new Intl.DateTimeFormat("en-US",n).formatToParts(t),a=o.find(i=>i.type==="year"?i.value:"")?.value,l=o.find(i=>i.type==="month"?i.value:"")?.value,u=o.find(i=>i.type==="day"?i.value:"")?.value,s=o.find(i=>i.type==="hour"?i.value:"")?.value,c=o.find(i=>i.type==="minute"?i.value:"")?.value;return `${a}-${l}-${u} ${s}:${c}`}function xe(e){let t=e instanceof Date?e:new Date(e),n={year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"},o=new Intl.DateTimeFormat("en-US",n).formatToParts(t),a=o.find(c=>c.type==="month"?c.value:"")?.value,l=o.find(c=>c.type==="day"?c.value:"")?.value,u=o.find(c=>c.type==="hour"?c.value:"")?.value,s=o.find(c=>c.type==="minute"?c.value:"")?.value;return `${a}-${l} ${u}:${s}`}function X(e,t){return new Decimal(e).toFixed(t,Decimal.ROUND_DOWN)}function ee(e,t,n,r){localStorage.setItem("pnl_config_key",JSON.stringify({bgIndex:n,pnlFormat:e,options:Array.from(t),message:r}));}function te(){let e=localStorage.getItem("pnl_config_key");if(e&&e.length>0)try{return JSON.parse(e)}catch{}return {bgIndex:0,pnlFormat:"roi_pnl",options:["openPrice","closePrice","openTime","closeTime","markPrice","quantity","leverage"],message:""}}var Se=e=>{let{onClickDownload:t,onClickCopy:n}=e,{t:r}=useTranslation();return jsxs(Flex,{px:8,gap:3,mt:3,itemAlign:"center",children:[jsxs(Button,{color:"secondary",className:"oui-flex-1 oui-flex oui-gap-1",onClick:t,children:[jsx("span",{children:jsx(at,{})}),r("common.download")]}),jsxs(Button,{className:"oui-flex-1 oui-flex oui-gap-1",onClick:n,children:[jsx("span",{children:jsx(st,{})}),r("common.copy")]})]})},at=()=>jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M4.66 1.994A2.667 2.667 0 0 0 1.995 4.66v6.666a2.667 2.667 0 0 0 2.667 2.667h6.666a2.667 2.667 0 0 0 2.667-2.667V4.661a2.667 2.667 0 0 0-2.667-2.667zM7.995 4.66c.368 0 .667.298.667.666V8.66h2l-2.667 2.666L5.328 8.66h2V5.327c0-.368.299-.667.667-.667",fill:"#fff",fillOpacity:".98"})}),st=()=>jsx("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M5.166 1.994A2.667 2.667 0 0 0 2.499 4.66v4a2.667 2.667 0 0 0 2.667 2.667 2.667 2.667 0 0 0 2.666 2.667h4a2.667 2.667 0 0 0 2.667-2.667v-4a2.667 2.667 0 0 0-2.667-2.667 2.667 2.667 0 0 0-2.666-2.666zm6.666 4c.737 0 1.334.596 1.334 1.333v4c0 .737-.597 1.334-1.334 1.334h-4A1.333 1.333 0 0 1 6.5 11.327h2.667a2.667 2.667 0 0 0 2.666-2.667z",fill:"#fff",fillOpacity:".98"})});var be=e=>{let{children:t,...n}=e;return jsx("button",{...n,children:jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{width:"20",height:"20",rx:"10",fill:"#333948"}),jsx("path",{d:"M11.186 5.348a.67.67 0 0 0-.436.27l-2.657 4a.69.69 0 0 0 0 .75l2.657 4a.68.68 0 0 0 .934.188.685.685 0 0 0 .187-.937L9.463 9.993 11.87 6.37a.685.685 0 0 0-.187-.938.65.65 0 0 0-.498-.083",fill:"#fff",fillOpacity:".54"})]})})},we=e=>{let{children:t,...n}=e;return jsx("button",{...n,children:jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{width:"20",height:"20",rx:"10",fill:"#333948"}),jsx("path",{d:"M8.777 5.348a.65.65 0 0 0-.498.083.685.685 0 0 0-.187.938L10.5 9.993 8.092 13.62a.685.685 0 0 0 .187.937.68.68 0 0 0 .934-.187l2.657-4a.69.69 0 0 0 0-.75l-2.657-4a.67.67 0 0 0-.436-.271",fill:"#fff",fillOpacity:".54"})]})})};var Ie=e=>{let{backgroundImages:t,selectedSnap:n,setSelectedSnap:r}=e,[o,a]=useEmblaCarousel({containScroll:"keepSnaps",dragFree:true}),l=useCallback(()=>{a&&(a?.canScrollPrev()?a.scrollPrev():n-1>=0&&r(n-1));},[a,n]),u=useCallback(()=>{a&&(a?.canScrollNext()?a.scrollNext():n+1<t.length&&r(n+1));},[a,n]),s=useCallback(c=>{r(c.selectedScrollSnap());},[]);return useEffect(()=>{if(a)return s(a),a.on("reInit",s),a.on("select",s),a?.scrollTo(n),()=>{a.off("reInit",s),a.off("select",s);}},[a,s]),jsxs(Flex,{mt:4,px:2,children:[jsx(be,{onClick:l}),jsx("div",{ref:o,className:"oui-w-full oui-overflow oui-overflow-x-auto oui-scrollbar-hidden oui-hide-scrollbar oui-mx-0",children:jsx(Flex,{children:t.map((c,i)=>jsx(Box,{onClick:()=>{a?.canScrollPrev()||a?.canScrollNext()?a?.scrollTo(i):r(i);},mx:2,my:1,mr:6,r:"base",className:cn("oui-shrink-0 oui-w-[162px]",n===i&&"oui-outline oui-outline-1 oui-outline-primary-darken"),children:jsx("img",{src:c,className:"oui-rounded-sm"})},c))})}),jsx(we,{onClick:u})]})};var oe=e=>{let{size:t=16,className:n}=e;return jsx("button",{type:"button",onClick:r=>{e.onCheckedChange(!e.checked);},className:n,children:e.checked?jsx("svg",{width:t,height:t,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M4.66 1.953A2.667 2.667 0 0 0 1.995 4.62v6.667a2.667 2.667 0 0 0 2.667 2.666h6.666a2.667 2.667 0 0 0 2.667-2.666V4.62a2.667 2.667 0 0 0-2.667-2.667zm6.664 2.922a.8.8 0 0 1 .557-.208c.2 0 .406.063.558.208a.734.734 0 0 1 0 1.063l-5.434 5.179a.826.826 0 0 1-1.115 0l-2.33-2.22a.736.736 0 0 1 0-1.063.827.827 0 0 1 1.117 0l1.77 1.687z",fill:"#fff",fillOpacity:".8"})}):jsx("svg",{width:t,height:t,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M4.66 1.953A2.667 2.667 0 0 0 1.995 4.62v6.667a2.667 2.667 0 0 0 2.667 2.666h6.666a2.667 2.667 0 0 0 2.667-2.666V4.62a2.667 2.667 0 0 0-2.667-2.667zm0 1.334h6.667c.737 0 1.334.596 1.334 1.333v6.667c0 .736-.597 1.333-1.334 1.333H4.661a1.333 1.333 0 0 1-1.334-1.333V4.62c0-.737.597-1.333 1.334-1.333",fill:"#fff",fillOpacity:".8"})})})};var De=e=>{let{message:t,setMessage:n,check:r,setCheck:o}=e,[a,l]=useState(false),u=useRef(null),{t:s}=useTranslation();return jsxs("div",{className:"oui-mt-3 oui-mb-6 oui-flex oui-items-center",children:[jsx(oe,{className:"oui-mt-[2px]",checked:r,onCheckedChange:c=>{o(c);}}),jsx("div",{className:"oui-text-xs oui-text-base-contrast-54 oui-ml-1 hover:oui-cursor-pointer",onClick:()=>{o(!e.check);},children:s("share.pnl.optionalInfo.message")}),jsx("div",{className:"oui-bg-base-900 oui-mx-2 oui-rounded-sm",children:jsx(Input,{ref:u,placeholder:s("share.pnl.optionalInfo.message.placeholder"),classNames:{root:"oui-w-[320px]"},size:"sm",value:t,autoFocus:false,suffix:a&&jsx("button",{className:"oui-mr-3 oui-cursor-pointer",onMouseDown:c=>{n(""),setTimeout(()=>{u.current?.focus();},50),c.stopPropagation();},children:jsx(CloseCircleFillIcon,{size:18,color:"white"})}),onFocus:()=>l(true),onBlur:()=>l(false),onChange:c=>{if(c.target.value.length>25){toast.error(s("share.pnl.optionalInfo.message.maxLength"));return}o(c.target.value.length>0),n(c.target.value);}})})]})};var Fe=e=>{let{type:t,curType:n,setShareOption:r}=e,{t:o}=useTranslation(),a=useMemo(()=>{switch(t){case "openPrice":return o("share.pnl.optionalInfo.openPrice");case "closePrice":return o("share.pnl.optionalInfo.closePrice");case "openTime":return o("share.pnl.optionalInfo.openTime");case "closeTime":return o("share.pnl.optionalInfo.closeTime");case "markPrice":return o("common.markPrice");case "quantity":return o("common.quantity");case "leverage":return o("common.leverage")}},[t,o]),l=n.has(t);return jsxs(Flex,{itemAlign:"center",gap:1,className:cn("hover:oui-cursor-pointer"),onClick:()=>{r(u=>{let s=new Set(u);return l?s.delete(t):s.add(t),s});},children:[jsx(oe,{size:16,checked:l,className:"oui-pt-[2px]",onCheckedChange:u=>{r(s=>{let c=new Set(s);return l?c.delete(t):c.add(t),c});}}),jsx(Text,{size:"xs",intensity:54,children:a})]})};var Le=e=>{let{type:t,curType:n,setPnlFormat:r}=e,{t:o}=useTranslation(),a=useMemo(()=>{switch(t){case "roi_pnl":return o("share.pnl.displayFormat.roi&Pnl");case "roi":return o("share.pnl.displayFormat.roi");case "pnl":return o("share.pnl.displayFormat.pnl")}},[t,o]),l=t===n,u="oui-flex oui-items-center oui-gap-1 oui-cursor-pointer";return l?u+=" oui-text-base-contrast":u+="",jsxs("div",{className:u,onClick:()=>{r(t);},children:[jsx(Tt,{sel:l}),jsx(Text,{size:"xs",intensity:54,className:cn("oui-ml-2 "),children:a})]})},Tt=e=>jsx("button",{type:"button",children:e.sel===true?jsx(Ft,{}):jsx(Lt,{})}),Ft=()=>jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",className:"oui-fill-primary-darken",children:[jsx("path",{d:"M8.01 1.333a6.667 6.667 0 1 0 0 13.333 6.667 6.667 0 0 0 0-13.333m0 1.333a5.334 5.334 0 1 1-.001 10.667 5.334 5.334 0 0 1 0-10.667",fill:"#fff",fillOpacity:".36"}),jsx("circle",{cx:"8",cy:"8",r:"3.333"})]}),Lt=()=>jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M8.01 1.333a6.667 6.667 0 1 0 0 13.333 6.667 6.667 0 0 0 0-13.333m0 1.333a5.334 5.334 0 1 1-.001 10.667 5.334 5.334 0 0 1 0-10.667",fill:"#fff",fillOpacity:".54"})});var Ae=e=>{let{shareOptions:t}=e,{t:n}=useTranslation(),r=te(),a=e.entity.roi!=null&&e.entity.pnl!=null?["roi_pnl","roi","pnl"]:e.entity.roi!=null?["roi"]:e.entity.pnl!=null?["pnl"]:[],[l,u]=useState(a.length==1?a[0]:r.pnlFormat),[s,c]=useState(new Set(r.options)),[i,d]=useState(r.bgIndex),[h,O]=useState(r.message),[S,b]=useState(false),{backgroundImages:W,...I}=t??{backgroundImages:[]},[z,w]=useState(""),v=useRef(null);useEffect(()=>{let N=window.location.hostname;w(N);},[]);let D=useMemo(()=>t?.backgroundImages?.[i],[t?.backgroundImages,i]),$=j(e.entity,S?h:"",z,l,s,e.baseDp,e.quoteDp,e.referral),V=()=>{v.current?.copy().then(()=>{e.hide?.(),toast.success(n("share.pnl.image.copied"));}).catch(N=>{toast.error(()=>jsxs("div",{children:[jsx("div",{children:n("common.copy.failed")}),jsx("div",{className:"oui-mt-2 oui-max-w-[396px] oui-text-2xs oui-text-base-contrast-54",children:n("share.pnl.copy.failed.description")})]}));});},g=()=>{v.current?.download("Poster.png"),e.hide?.();},ne=useMemo(()=>["openPrice","closePrice","markPrice","openTime","closeTime","leverage","quantity"].filter(T=>!!e.entity[T]),[e.entity]);return ee(l,s,i,h),jsxs("div",{className:"oui-relative oui-flex oui-size-full oui-flex-col",children:[jsxs("div",{className:"oui-h-full oui-flex-1 oui-overflow-y-auto",children:[jsxs(Box,{mt:9,height:422,children:[jsx(Flex,{itemAlign:"center",justify:"center",children:jsx(K,{width:552,height:310,data:{backgroundImg:D,...I,data:$},ratio:3,ref:v})}),jsx(Ie,{backgroundImages:t?.backgroundImages??EMPTY_LIST,selectedSnap:i,setSelectedSnap:d})]}),jsxs(Flex,{direction:"column",px:10,mt:6,justify:"start",itemAlign:"start",width:"100%",children:[jsx(Text,{size:"sm",intensity:80,children:n("share.pnl.displayFormat")}),jsx(Flex,{pt:3,gap:3,itemAlign:"center",children:a.map((N,T)=>jsx(Le,{setPnlFormat:u,type:N,curType:l},T))}),jsx(Divider,{className:"oui-w-full oui-border-white/10 oui-pt-6"}),jsxs(Flex,{mt:6,direction:"column",justify:"start",itemAlign:"start",children:[jsx(Text,{size:"sm",intensity:80,children:n("share.pnl.optionalInfo")}),jsx(Flex,{mt:3,gap:4,className:"oui-flex-wrap",children:ne.map((N,T)=>jsx(Fe,{setShareOption:c,type:N,curType:s},T))})]}),jsx(De,{message:h,setMessage:O,check:S,setCheck:b})]})]}),jsx(Se,{onClickCopy:V,onClickDownload:g})]})};var Ee=f.createContext(null);function B(){let e=f.useContext(Ee);if(!e)throw new Error("useCarousel must be used within a <Carousel />");return e}var ie=f.forwardRef((e,t)=>{let{orientation:n="horizontal",opts:r,setApi:o,plugins:a,className:l,children:u,...s}=e,[c,i]=useEmblaCarousel({...r,axis:n==="horizontal"?"x":"y"},a),[d,h]=f.useState(false),[O,S]=f.useState(false),[b,W]=f.useState(s.initIndex||0),[I,z]=f.useState([]),w=f.useCallback(g=>{g&&(I.length===0&&z(g.scrollSnapList()),W(g.selectedScrollSnap()),h(g.canScrollPrev()),S(g.canScrollNext()));},[I]),v=f.useCallback(()=>{i?.scrollPrev();},[i]),D=f.useCallback(()=>{i?.scrollNext();},[i]),$=f.useCallback(g=>{g.key==="ArrowLeft"?(g.preventDefault(),v()):g.key==="ArrowRight"&&(g.preventDefault(),D());},[v,D]);f.useEffect(()=>{!i||!o||o(i);},[i,o]),f.useEffect(()=>{if(i)return w(i),i.on("reInit",w),i.on("select",w),s.initIndex&&i.scrollTo(s.initIndex),()=>{i?.off("select",w);}},[i,w]);let V=f.useMemo(()=>({carouselRef:c,api:i,opts:r,orientation:n||(r?.axis==="y"?"vertical":"horizontal"),scrollPrev:v,scrollNext:D,canScrollPrev:d,canScrollNext:O,selectedIndex:b,scrollSnaps:I}),[c,i,r,n,v,D,d,O,b,I]);return jsx(Ee.Provider,{value:V,children:jsx("div",{ref:t,onKeyDownCapture:$,className:cn("oui-relative",l),role:"region","aria-roledescription":"carousel",...s,children:u})})});ie.displayName="Carousel";var Y=f.forwardRef((e,t)=>{let{className:n,children:r,...o}=e,{carouselRef:a,orientation:l}=B();return jsx("div",{ref:a,className:"oui-overflow-hidden",children:jsx("div",{ref:t,className:cn("oui-flex",l==="horizontal"?"oui--ml-4":"oui--mt-4 oui-flex-col",n),...o,children:r})})});Y.displayName="CarouselContent";var G=f.forwardRef((e,t)=>{let{className:n,children:r,...o}=e,{orientation:a}=B();return jsx("div",{ref:t,role:"group","aria-roledescription":"slide",className:cn("oui-min-w-0 oui-shrink-0 oui-grow-0 oui-basis-full",a==="horizontal"?"oui-pl-4":"oui-pt-4",n),...o,children:r})});G.displayName="CarouselItem";var le=f.forwardRef((e,t)=>{let{className:n,variant:r="contained",size:o="icon",...a}=e,{orientation:l,scrollPrev:u,canScrollPrev:s}=B();return jsxs(Button,{ref:t,variant:r,className:cn("oui-absolute oui-size-8 oui-rounded-full",l==="horizontal"?"oui--left-12 oui-top-1/2 oui--translate-y-1/2":"oui--top-12 oui-left-1/2 oui--translate-x-1/2 oui-rotate-90",n),disabled:!s,onClick:u,...a,children:[jsx(ChevronLeftIcon,{size:20}),jsx("span",{className:"oui-sr-only",children:"Previous slide"})]})});le.displayName="CarouselPrevious";var ce=f.forwardRef((e,t)=>{let{className:n,variant:r="contained",size:o="icon",...a}=e,{orientation:l,scrollNext:u,canScrollNext:s}=B();return jsxs(Button,{ref:t,variant:r,className:cn("oui-absolute oui-size-8 oui-rounded-full",l==="horizontal"?"oui--right-12 oui-top-1/2 oui--translate-y-1/2":"oui--bottom-12 oui-left-1/2 oui--translate-x-1/2 oui-rotate-90",n),disabled:!s,onClick:u,...a,children:[jsx(ChevronRightIcon,{size:20}),jsx("span",{className:"oui-sr-only",children:"Next slide"})]})});ce.displayName="CarouselNext";var ue=e=>{let{scrollSnaps:t,selectedIndex:n}=B();return jsx("div",{className:cn("oui-flex oui-gap-1",e.className),children:t.map((r,o)=>jsx(me,{index:o,active:o===n,onClick:e.onClick,className:e.dotClassName,activeClassName:e.dotActiveClassName},o))})};ue.displayName="CarouselIdentifier";var me=({index:e,active:t,onClick:n,className:r,activeClassName:o})=>jsx("button",{onClick:()=>n?.(e),className:cn("oui-size-2 oui-rounded-full oui-bg-white/30",r,t&&`active ${o||"oui-bg-primary-darken"}`)});var M=ie;M.Content=Y;M.Item=G;M.Next=ce;M.Previous=le;M.indentify=ue;var _e=e=>{let{shareOptions:t}=e,{t:n}=useTranslation(),r=te(),a=e.entity.roi!=null&&e.entity.pnl!=null?["roi_pnl","roi","pnl"]:e.entity.roi!=null?["roi"]:e.entity.pnl!=null?["pnl"]:[],[l,u]=useState(a.length==1?a[0]:r.pnlFormat),[s,c]=useState(new Set(r.options)),[i,d]=useState(r.message),[h,O]=useState(r.bgIndex),{backgroundImages:S,...b}=t??{backgroundImages:[]},[W,I]=useState(""),z=t?.backgroundImages?.map(()=>useRef(null));useEffect(()=>{let p=window.location.hostname;I(p);},[]);let w=j(e.entity,i,W,l,s,e.baseDp,e.quoteDp,e.referral),v=useRef(),D=552/310,[$,V]=useState(1),[g,ne]=useState(0),[N,T]=useState(false),Ce=useRef(null);useEffect(()=>{if(v.current){let p=v.current.offsetWidth,C=p/D;ne(C),V(p/552);}},[v,W]);let Ve=async p=>{if(!p.current)return;let C=p.current?.toDataURL(),Je=Zt(C);try{navigator.share&&await navigator.share({text:i,files:[new File([Je],"image.png",{type:"image/png"})]}),e.hide?.();}catch{}},Ke=useMemo(()=>["openPrice","closePrice","openTime","closeTime","leverage","markPrice","quantity"].filter(C=>!!e.entity[C]),[e.entity]);return ee(l,s,h,i),jsxs("div",{className:"oui-w-full",children:[jsx("div",{ref:v,className:"oui-mt-4 oui-w-full oui-overflow-hidden",style:{height:`${g+20}px`},children:jsxs(M,{className:"oui-w-full oui-overflow-hidden",opts:{align:"start"},initIndex:h,children:[jsx(Y,{style:{height:`${g}px`},children:t?.backgroundImages?.map((p,C)=>jsx(G,{children:jsx(K,{className:"oui-origin-top-left oui-transform",style:{scale:`${$}`},width:552,height:310,data:{backgroundImg:p,...b,data:w},ratio:3,ref:z?.[C]})},C))}),jsx("div",{className:"oui-mb-1 oui-mt-2 oui-flex oui-justify-center",children:jsx(Yt,{dotClassName:"oui-w-[16px] oui-h-[4px] oui-bg-base-300",dotActiveClassName:"!oui-bg-primary-darken oui-w-[20px]",setSelectIndex:O})})]})}),jsxs(ScrollArea,{className:"oui-custom-scrollbar oui-max-h-[200px] oui-overflow-y-auto",children:[jsxs("div",{className:"oui-mt-4",children:[jsx("div",{className:"oui-text-3xs oui-text-base-contrast-54",children:n("share.pnl.displayFormat")}),jsx("div",{className:"oui-row-span-1 oui-grid oui-grid-cols-3 oui-justify-between oui-gap-3 oui-px-1 oui-pt-3",children:a.map((p,C)=>jsx(Kt,{setPnlFormat:u,type:p,curType:l},C))})]}),jsxs("div",{className:"oui-mt-3",children:[jsx("div",{className:"oui-h-[18px] oui-text-3xs oui-text-base-contrast-54",children:n("share.pnl.optionalInfo")}),jsx("div",{className:"oui-mt-3 oui-flex oui-flex-wrap oui-gap-3",children:Ke.map((p,C)=>jsx(Jt,{setShareOption:c,type:p,curType:s},C))})]}),jsxs("div",{className:"oui-mb-8 oui-mt-3",children:[jsx("div",{className:"oui-h-[18px] oui-text-3xs oui-text-base-contrast-54",children:n("share.pnl.optionalInfo.message")}),jsx("div",{className:"oui-bg-base-600 oui-mx-1 oui-mt-3 oui-h-[48px]",children:jsx(Input,{placeholder:n("share.pnl.optionalInfo.message.placeholder"),containerClassName:"oui-bg-transparent oui-h-[48px]",value:i,autoFocus:false,onChange:p=>{if(p.target.value.length>25){toast.error(n("share.pnl.optionalInfo.message.maxLength"));return}d(p.target.value);},ref:Ce,onFocus:()=>T(true),onBlur:()=>T(false),suffix:N&&jsx("button",{className:"oui-mr-3 oui-cursor-pointer",onMouseDown:p=>{d(""),setTimeout(()=>{Ce.current?.focus();},50),p.stopPropagation();},children:jsx(CloseCircleFillIcon,{size:18,color:"white"})})})})]})]}),jsx("div",{className:"oui-pt-2",children:jsx(Button,{fullWidth:true,className:"oui-h-[40px] oui-text-[16px]",onClick:()=>{let p=z?.[h];p&&Ve(p);},children:n("common.share")})})]})},Kt=e=>{let{type:t,curType:n,setPnlFormat:r}=e,{t:o}=useTranslation(),a=useMemo(()=>{switch(t){case "roi_pnl":return o("share.pnl.displayFormat.roi&Pnl");case "roi":return o("share.pnl.displayFormat.roi");case "pnl":return o("share.pnl.displayFormat.pnl")}},[t]);return jsx("div",{className:cn("oui-referral-shadow oui-flex oui-h-[46px] oui-flex-1 oui-items-center oui-rounded-lg oui-bg-base-4 oui-px-3 oui-shadow-lg hover:oui-cursor-pointer",t===n&&"oui-dot-sel oui-bg-primary-darken"),onClick:()=>{r(t);},children:jsx("div",{className:"oui-text-sm oui-text-base-contrast",children:a})})},Jt=e=>{let{type:t,curType:n,setShareOption:r}=e,{t:o}=useTranslation(),a=useMemo(()=>{switch(t){case "openPrice":return o("share.pnl.optionalInfo.openPrice");case "closePrice":return o("share.pnl.optionalInfo.closePrice");case "openTime":return o("share.pnl.optionalInfo.openTime");case "closeTime":return o("share.pnl.optionalInfo.closeTime");case "markPrice":return o("common.markPrice");case "quantity":return o("common.quantity");case "leverage":return o("common.leverage")}},[t,o]),l=n.has(t);return jsxs("div",{className:cn("oui-referral-shadow oui-mt-0 oui-flex oui-h-[46px] oui-w-[calc(50%-6px)] oui-items-center oui-rounded-lg oui-bg-base-4 oui-p-3 oui-shadow-lg hover:oui-cursor-pointer"),onClick:()=>{r(u=>{let s=new Set(u);return l?s.delete(t):s.add(t),s});},children:[jsx("div",{className:"oui-flex-1 oui-text-sm oui-text-base-contrast",children:a}),l&&jsx(Gt,{})]})};function Zt(e){let t=atob(e.split(",")[1]),n=e.split(",")[0].split(":")[1].split(";")[0],r=new ArrayBuffer(t.length),o=new Uint8Array(r);for(let a=0;a<t.length;a++)o[a]=t.charCodeAt(a);return new Blob([r],{type:n})}var Yt=e=>{let{scrollSnaps:t,selectedIndex:n}=B();return useEffect(()=>{e.setSelectIndex(n);},[n]),jsx("div",{className:cn("oui-flex oui-gap-1"),children:t.map((r,o)=>jsx(me,{index:o,active:o===n,onClick:e.onClick,className:e.dotClassName,activeClassName:e.dotActiveClassName},o))})},Gt=()=>jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M2.01416 11.9989C2.01416 6.47589 6.49136 1.9989 12.0142 1.9989C17.5372 1.9989 22.0142 6.47589 22.0142 11.9989C22.0142 17.5219 17.5372 21.9989 12.0142 21.9989C6.49136 21.9989 2.01416 17.5219 2.01416 11.9989ZM16.9853 7.31211C17.2125 7.09537 17.5236 7 17.8218 7C18.1201 7 18.4312 7.09537 18.6583 7.31211C19.1139 7.74546 19.1139 8.47384 18.6583 8.9072L10.5077 16.675C10.0534 17.1083 9.28909 17.1083 8.83472 16.675L5.34077 13.3459C4.88641 12.9126 4.88641 12.1841 5.34077 11.7508C5.79631 11.3175 6.56057 11.3175 7.01493 11.7508L9.67122 14.2822L16.9853 7.31211Z",fill:"white",fillOpacity:"1"})});var qe=e=>{let{entity:t,baseDp:n,quoteDp:r,referralInfo:o,shareOptions:a,hide:l}=e;return !a||!t?null:jsx(Ae,{entity:t,hide:l,baseDp:n,quoteDp:r,referral:o,shareOptions:a})},Ue=e=>{let{entity:t,baseDp:n,quoteDp:r,referralInfo:o,shareOptions:a,hide:l}=e;return !a||!t?null:jsx(_e,{entity:t,hide:l,baseDp:n,quoteDp:r,referral:o,shareOptions:a})};var ye=e=>{let t=Q({hide:e.hide,pnl:e.pnl});return jsx(Ue,{...t})},ve=e=>{let t=Q({hide:e.hide,pnl:e.pnl});return jsx(qe,{...t})};var eo="sharePnLDialog",to="sharePnLBottomSheet";registerSimpleDialog(eo,ve,{classNames:{content:"!oui-max-w-[624px] oui-p-0"}});registerSimpleSheet(to,ye,{title:i18n.t("share.pnl.sharePnl"),classNames:{body:"oui-pb-4 oui-pt-0"}});
9
+ // src/index.ts
10
+ var useSharePnLScript = (props) => {
11
+ const { pnl, hide } = props;
12
+ const entity = pnl?.entity;
13
+ const symbolInfo = useSymbolsInfo();
14
+ const { getFirstRefCode } = useReferralInfo();
15
+ const referralInfo = useMemo(() => {
16
+ const code = getFirstRefCode()?.code;
17
+ const info = {
18
+ code: pnl?.refCode ?? code,
19
+ slogan: pnl?.refSlogan,
20
+ link: pnl?.refLink
21
+ };
22
+ return info;
23
+ }, [getFirstRefCode, pnl]);
24
+ const base_dp = useMemo(() => {
25
+ if (!entity)
26
+ return void 0;
27
+ return symbolInfo[entity?.symbol]("base_dp");
28
+ }, [entity, symbolInfo]);
29
+ const quote_dp = useMemo(() => {
30
+ if (!entity)
31
+ return void 0;
32
+ return symbolInfo[entity?.symbol]("quote_dp");
33
+ }, [entity, symbolInfo]);
34
+ return {
35
+ entity,
36
+ baseDp: base_dp,
37
+ quoteDp: quote_dp,
38
+ referralInfo,
39
+ shareOptions: pnl,
40
+ hide
41
+ };
42
+ };
43
+ var Poster = forwardRef((props, parentRef) => {
44
+ const { width, height, className, data, style } = props;
45
+ const { ref, download, toDataURL, copy, toBlob } = usePoster(data, {
46
+ ratio: props.ratio
47
+ });
48
+ useImperativeHandle(parentRef, () => ({
49
+ download,
50
+ toDataURL,
51
+ toBlob,
52
+ copy
53
+ }));
54
+ return /* @__PURE__ */ jsx(
55
+ "canvas",
56
+ {
57
+ ref,
58
+ width,
59
+ height,
60
+ className,
61
+ style
62
+ }
63
+ );
64
+ });
65
+ function getPnLPosterData(position, message, domain, pnlType, options, baseDp, quoteDp, referral) {
66
+ const { t } = useTranslation();
67
+ const { symbol, currency } = processSymbol(position.symbol);
68
+ const positionData = {
69
+ symbol,
70
+ currency,
71
+ side: position.side
72
+ };
73
+ switch (pnlType) {
74
+ case "pnl": {
75
+ if (position.pnl != null) {
76
+ positionData["pnl"] = formatNum.pnl(position.pnl)?.toFixed(2);
77
+ }
78
+ break;
79
+ }
80
+ case "roi": {
81
+ if (position.roi != null) {
82
+ positionData["ROI"] = formatNum.roi(position.roi)?.toFixed(2);
83
+ }
84
+ break;
85
+ }
86
+ case "roi_pnl": {
87
+ if (position.pnl != null) {
88
+ positionData["pnl"] = formatNum.pnl(position.pnl)?.toFixed(2);
89
+ }
90
+ if (position.roi != null) {
91
+ positionData["ROI"] = formatNum.roi(position.roi)?.toFixed(2);
92
+ }
93
+ break;
94
+ }
95
+ }
96
+ const informations = [];
97
+ if (options.has("leverage")) {
98
+ positionData["leverage"] = position.leverage;
99
+ }
100
+ const array = [
101
+ "openPrice",
102
+ "closePrice",
103
+ "openTime",
104
+ "closeTime",
105
+ "markPrice",
106
+ "quantity"
107
+ ];
108
+ array.forEach((key) => {
109
+ if (options.has(key)) {
110
+ switch (key) {
111
+ case "leverage": {
112
+ break;
113
+ }
114
+ case "openPrice": {
115
+ if (position.openPrice != null) {
116
+ informations.push({
117
+ title: t("share.pnl.optionalInfo.openPrice"),
118
+ value: formatFixed(position.openPrice, quoteDp || 2)
119
+ });
120
+ }
121
+ break;
122
+ }
123
+ case "closePrice": {
124
+ if (position.closePrice != null) {
125
+ informations.push({
126
+ title: t("share.pnl.optionalInfo.closePrice"),
127
+ value: formatFixed(position.closePrice, quoteDp || 2)
128
+ });
129
+ }
130
+ break;
131
+ }
132
+ case "openTime": {
133
+ if (position.openTime != null) {
134
+ informations.push({
135
+ title: t("share.pnl.optionalInfo.openTime"),
136
+ value: formatOpenTime(position.openTime)
137
+ });
138
+ }
139
+ break;
140
+ }
141
+ case "closeTime": {
142
+ if (position.closeTime != null) {
143
+ informations.push({
144
+ title: t("share.pnl.optionalInfo.closeTime"),
145
+ value: formatOpenTime(position.closeTime)
146
+ });
147
+ }
148
+ break;
149
+ }
150
+ case "markPrice": {
151
+ if (position.markPrice != null) {
152
+ informations.push({
153
+ title: t("common.markPrice"),
154
+ value: formatFixed(position.markPrice, quoteDp || 2)
155
+ });
156
+ }
157
+ break;
158
+ }
159
+ case "quantity": {
160
+ if (position.quantity != null) {
161
+ informations.push({
162
+ title: t("common.quantity"),
163
+ value: formatFixed(position.quantity, baseDp || 2)
164
+ });
165
+ }
166
+ }
167
+ }
168
+ }
169
+ });
170
+ positionData["informations"] = informations;
171
+ const data = {
172
+ position: positionData,
173
+ updateTime: formatShareTime(/* @__PURE__ */ new Date()),
174
+ domain
175
+ };
176
+ if (message.length > 0) {
177
+ data["message"] = message;
178
+ }
179
+ if (typeof referral !== "undefined" && referral["code"] !== void 0) {
180
+ data["referral"] = referral;
181
+ }
182
+ return data;
183
+ }
184
+ function processSymbol(symbol) {
185
+ const tokens = symbol.split("_");
186
+ if (tokens.length !== 3) {
187
+ return {
188
+ symbol,
189
+ currency: "USDC"
190
+ };
191
+ }
192
+ const [symbol1, symbol2, symbol3] = tokens;
193
+ const formattedString = `${symbol2}-${symbol1}`;
194
+ return {
195
+ symbol: formattedString,
196
+ currency: symbol3 || "USDC"
197
+ };
198
+ }
199
+ function formatShareTime(input) {
200
+ const date = input instanceof Date ? input : new Date(input);
201
+ const options = {
202
+ year: "numeric",
203
+ month: "2-digit",
204
+ day: "2-digit",
205
+ hour: "2-digit",
206
+ minute: "2-digit",
207
+ hourCycle: "h23"
208
+ };
209
+ const formatter = new Intl.DateTimeFormat("en-US", options);
210
+ const formattedParts = formatter.formatToParts(date);
211
+ const year = formattedParts.find(
212
+ (part) => part.type === "year" ? part.value : ""
213
+ )?.value;
214
+ const month = formattedParts.find(
215
+ (part) => part.type === "month" ? part.value : ""
216
+ )?.value;
217
+ const day = formattedParts.find(
218
+ (part) => part.type === "day" ? part.value : ""
219
+ )?.value;
220
+ const hour = formattedParts.find(
221
+ (part) => part.type === "hour" ? part.value : ""
222
+ )?.value;
223
+ const minute = formattedParts.find(
224
+ (part) => part.type === "minute" ? part.value : ""
225
+ )?.value;
226
+ return `${year}-${month}-${day} ${hour}:${minute}`;
227
+ }
228
+ function formatOpenTime(input) {
229
+ const date = input instanceof Date ? input : new Date(input);
230
+ const options = {
231
+ year: "numeric",
232
+ month: "short",
233
+ day: "2-digit",
234
+ hour: "2-digit",
235
+ minute: "2-digit",
236
+ hourCycle: "h23"
237
+ };
238
+ const formatter = new Intl.DateTimeFormat("en-US", options);
239
+ const formattedParts = formatter.formatToParts(date);
240
+ const month = formattedParts.find(
241
+ (part) => part.type === "month" ? part.value : ""
242
+ )?.value;
243
+ const day = formattedParts.find(
244
+ (part) => part.type === "day" ? part.value : ""
245
+ )?.value;
246
+ const hour = formattedParts.find(
247
+ (part) => part.type === "hour" ? part.value : ""
248
+ )?.value;
249
+ const minute = formattedParts.find(
250
+ (part) => part.type === "minute" ? part.value : ""
251
+ )?.value;
252
+ return `${month}-${day} ${hour}:${minute}`;
253
+ }
254
+ function formatFixed(value, dp) {
255
+ return new Decimal(value).toFixed(dp, Decimal.ROUND_DOWN);
256
+ }
257
+ function savePnlInfo(format, options, bgIndex, message) {
258
+ localStorage.setItem(
259
+ "pnl_config_key",
260
+ JSON.stringify({
261
+ bgIndex,
262
+ pnlFormat: format,
263
+ options: Array.from(options),
264
+ message
265
+ })
266
+ );
267
+ }
268
+ function getPnlInfo() {
269
+ const str = localStorage.getItem("pnl_config_key");
270
+ if (str && str.length > 0) {
271
+ try {
272
+ const json = JSON.parse(str);
273
+ return json;
274
+ } catch (e) {
275
+ }
276
+ }
277
+ return {
278
+ bgIndex: 0,
279
+ pnlFormat: "roi_pnl",
280
+ options: [
281
+ "openPrice",
282
+ "closePrice",
283
+ "openTime",
284
+ "closeTime",
285
+ "markPrice",
286
+ "quantity",
287
+ "leverage"
288
+ ],
289
+ message: ""
290
+ };
291
+ }
292
+ var BottomButtons = (props) => {
293
+ const { onClickDownload, onClickCopy } = props;
294
+ const { t } = useTranslation();
295
+ return /* @__PURE__ */ jsxs(Flex, { px: 8, gap: 3, mt: 3, itemAlign: "center", children: [
296
+ /* @__PURE__ */ jsxs(
297
+ Button,
298
+ {
299
+ color: "secondary",
300
+ className: "oui-flex-1 oui-flex oui-gap-1",
301
+ onClick: onClickDownload,
302
+ children: [
303
+ /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(DownloadIcon, {}) }),
304
+ t("common.download")
305
+ ]
306
+ }
307
+ ),
308
+ /* @__PURE__ */ jsxs(Button, { className: "oui-flex-1 oui-flex oui-gap-1", onClick: onClickCopy, children: [
309
+ /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(CopyIcon, {}) }),
310
+ t("common.copy")
311
+ ] })
312
+ ] });
313
+ };
314
+ var DownloadIcon = () => {
315
+ return /* @__PURE__ */ jsx(
316
+ "svg",
317
+ {
318
+ width: "16",
319
+ height: "16",
320
+ viewBox: "0 0 16 16",
321
+ fill: "none",
322
+ xmlns: "http://www.w3.org/2000/svg",
323
+ children: /* @__PURE__ */ jsx(
324
+ "path",
325
+ {
326
+ d: "M4.66 1.994A2.667 2.667 0 0 0 1.995 4.66v6.666a2.667 2.667 0 0 0 2.667 2.667h6.666a2.667 2.667 0 0 0 2.667-2.667V4.661a2.667 2.667 0 0 0-2.667-2.667zM7.995 4.66c.368 0 .667.298.667.666V8.66h2l-2.667 2.666L5.328 8.66h2V5.327c0-.368.299-.667.667-.667",
327
+ fill: "#fff",
328
+ fillOpacity: ".98"
329
+ }
330
+ )
331
+ }
332
+ );
333
+ };
334
+ var CopyIcon = () => {
335
+ return /* @__PURE__ */ jsx(
336
+ "svg",
337
+ {
338
+ width: "17",
339
+ height: "16",
340
+ viewBox: "0 0 17 16",
341
+ fill: "none",
342
+ xmlns: "http://www.w3.org/2000/svg",
343
+ children: /* @__PURE__ */ jsx(
344
+ "path",
345
+ {
346
+ d: "M5.166 1.994A2.667 2.667 0 0 0 2.499 4.66v4a2.667 2.667 0 0 0 2.667 2.667 2.667 2.667 0 0 0 2.666 2.667h4a2.667 2.667 0 0 0 2.667-2.667v-4a2.667 2.667 0 0 0-2.667-2.667 2.667 2.667 0 0 0-2.666-2.666zm6.666 4c.737 0 1.334.596 1.334 1.333v4c0 .737-.597 1.334-1.334 1.334h-4A1.333 1.333 0 0 1 6.5 11.327h2.667a2.667 2.667 0 0 0 2.666-2.667z",
347
+ fill: "#fff",
348
+ fillOpacity: ".98"
349
+ }
350
+ )
351
+ }
352
+ );
353
+ };
354
+ var PrevButton = (props) => {
355
+ const { children, ...restProps } = props;
356
+ return /* @__PURE__ */ jsx("button", { ...restProps, children: /* @__PURE__ */ jsxs(
357
+ "svg",
358
+ {
359
+ width: "20",
360
+ height: "20",
361
+ viewBox: "0 0 20 20",
362
+ fill: "none",
363
+ xmlns: "http://www.w3.org/2000/svg",
364
+ children: [
365
+ /* @__PURE__ */ jsx("rect", { width: "20", height: "20", rx: "10", fill: "#333948" }),
366
+ /* @__PURE__ */ jsx(
367
+ "path",
368
+ {
369
+ d: "M11.186 5.348a.67.67 0 0 0-.436.27l-2.657 4a.69.69 0 0 0 0 .75l2.657 4a.68.68 0 0 0 .934.188.685.685 0 0 0 .187-.937L9.463 9.993 11.87 6.37a.685.685 0 0 0-.187-.938.65.65 0 0 0-.498-.083",
370
+ fill: "#fff",
371
+ fillOpacity: ".54"
372
+ }
373
+ )
374
+ ]
375
+ }
376
+ ) });
377
+ };
378
+ var NextButton = (props) => {
379
+ const { children, ...restProps } = props;
380
+ return /* @__PURE__ */ jsx("button", { ...restProps, children: /* @__PURE__ */ jsxs(
381
+ "svg",
382
+ {
383
+ width: "20",
384
+ height: "20",
385
+ viewBox: "0 0 20 20",
386
+ fill: "none",
387
+ xmlns: "http://www.w3.org/2000/svg",
388
+ children: [
389
+ /* @__PURE__ */ jsx("rect", { width: "20", height: "20", rx: "10", fill: "#333948" }),
390
+ /* @__PURE__ */ jsx(
391
+ "path",
392
+ {
393
+ d: "M8.777 5.348a.65.65 0 0 0-.498.083.685.685 0 0 0-.187.938L10.5 9.993 8.092 13.62a.685.685 0 0 0 .187.937.68.68 0 0 0 .934-.187l2.657-4a.69.69 0 0 0 0-.75l-2.657-4a.67.67 0 0 0-.436-.271",
394
+ fill: "#fff",
395
+ fillOpacity: ".54"
396
+ }
397
+ )
398
+ ]
399
+ }
400
+ ) });
401
+ };
402
+ var CarouselBackgroundImage = (props) => {
403
+ const { backgroundImages, selectedSnap, setSelectedSnap } = props;
404
+ const [emblaRef, emblaApi] = useEmblaCarousel({
405
+ // loop: true,
406
+ containScroll: "keepSnaps",
407
+ dragFree: true
408
+ });
409
+ const onPrevButtonClick = useCallback(() => {
410
+ if (!emblaApi) {
411
+ return;
412
+ }
413
+ if (emblaApi?.canScrollPrev()) {
414
+ emblaApi.scrollPrev();
415
+ } else if (selectedSnap - 1 >= 0) {
416
+ setSelectedSnap(selectedSnap - 1);
417
+ }
418
+ }, [emblaApi, selectedSnap]);
419
+ const onNextButtonClick = useCallback(() => {
420
+ if (!emblaApi) {
421
+ return;
422
+ }
423
+ if (emblaApi?.canScrollNext()) {
424
+ emblaApi.scrollNext();
425
+ } else if (selectedSnap + 1 < backgroundImages.length) {
426
+ setSelectedSnap(selectedSnap + 1);
427
+ }
428
+ }, [emblaApi, selectedSnap]);
429
+ const onSelect = useCallback((emblaApi2) => {
430
+ setSelectedSnap(emblaApi2.selectedScrollSnap());
431
+ }, []);
432
+ useEffect(() => {
433
+ if (!emblaApi) {
434
+ return;
435
+ }
436
+ onSelect(emblaApi);
437
+ emblaApi.on("reInit", onSelect);
438
+ emblaApi.on("select", onSelect);
439
+ emblaApi?.scrollTo(selectedSnap);
440
+ return () => {
441
+ emblaApi.off("reInit", onSelect);
442
+ emblaApi.off("select", onSelect);
443
+ };
444
+ }, [emblaApi, onSelect]);
445
+ return /* @__PURE__ */ jsxs(Flex, { mt: 4, px: 2, children: [
446
+ /* @__PURE__ */ jsx(PrevButton, { onClick: onPrevButtonClick }),
447
+ /* @__PURE__ */ jsx(
448
+ "div",
449
+ {
450
+ ref: emblaRef,
451
+ className: "oui-w-full oui-overflow oui-overflow-x-auto oui-scrollbar-hidden oui-hide-scrollbar oui-mx-0",
452
+ children: /* @__PURE__ */ jsx(Flex, { children: backgroundImages.map((e, index) => /* @__PURE__ */ jsx(
453
+ Box,
454
+ {
455
+ onClick: () => {
456
+ if (emblaApi?.canScrollPrev() || emblaApi?.canScrollNext()) {
457
+ emblaApi?.scrollTo(index);
458
+ } else {
459
+ setSelectedSnap(index);
460
+ }
461
+ },
462
+ mx: 2,
463
+ my: 1,
464
+ mr: 6,
465
+ r: "base",
466
+ className: cn(
467
+ "oui-shrink-0 oui-w-[162px]",
468
+ selectedSnap === index && "oui-outline oui-outline-1 oui-outline-primary-darken"
469
+ ),
470
+ children: /* @__PURE__ */ jsx("img", { src: e, className: "oui-rounded-sm" })
471
+ },
472
+ e
473
+ )) })
474
+ }
475
+ ),
476
+ /* @__PURE__ */ jsx(NextButton, { onClick: onNextButtonClick })
477
+ ] });
478
+ };
479
+ var Checkbox = (props) => {
480
+ const { size = 16, className } = props;
481
+ return /* @__PURE__ */ jsx(
482
+ "button",
483
+ {
484
+ type: "button",
485
+ onClick: (e) => {
486
+ props.onCheckedChange(!props.checked);
487
+ },
488
+ className,
489
+ children: props.checked ? /* @__PURE__ */ jsx(
490
+ "svg",
491
+ {
492
+ width: size,
493
+ height: size,
494
+ viewBox: "0 0 16 16",
495
+ fill: "none",
496
+ xmlns: "http://www.w3.org/2000/svg",
497
+ children: /* @__PURE__ */ jsx(
498
+ "path",
499
+ {
500
+ fillRule: "evenodd",
501
+ clipRule: "evenodd",
502
+ d: "M4.66 1.953A2.667 2.667 0 0 0 1.995 4.62v6.667a2.667 2.667 0 0 0 2.667 2.666h6.666a2.667 2.667 0 0 0 2.667-2.666V4.62a2.667 2.667 0 0 0-2.667-2.667zm6.664 2.922a.8.8 0 0 1 .557-.208c.2 0 .406.063.558.208a.734.734 0 0 1 0 1.063l-5.434 5.179a.826.826 0 0 1-1.115 0l-2.33-2.22a.736.736 0 0 1 0-1.063.827.827 0 0 1 1.117 0l1.77 1.687z",
503
+ fill: "#fff",
504
+ fillOpacity: ".8"
505
+ }
506
+ )
507
+ }
508
+ ) : /* @__PURE__ */ jsx(
509
+ "svg",
510
+ {
511
+ width: size,
512
+ height: size,
513
+ viewBox: "0 0 16 16",
514
+ fill: "none",
515
+ xmlns: "http://www.w3.org/2000/svg",
516
+ children: /* @__PURE__ */ jsx(
517
+ "path",
518
+ {
519
+ d: "M4.66 1.953A2.667 2.667 0 0 0 1.995 4.62v6.667a2.667 2.667 0 0 0 2.667 2.666h6.666a2.667 2.667 0 0 0 2.667-2.666V4.62a2.667 2.667 0 0 0-2.667-2.667zm0 1.334h6.667c.737 0 1.334.596 1.334 1.333v6.667c0 .736-.597 1.333-1.334 1.333H4.661a1.333 1.333 0 0 1-1.334-1.333V4.62c0-.737.597-1.333 1.334-1.333",
520
+ fill: "#fff",
521
+ fillOpacity: ".8"
522
+ }
523
+ )
524
+ }
525
+ )
526
+ }
527
+ );
528
+ };
529
+ var Message = (props) => {
530
+ const { message, setMessage, check, setCheck } = props;
531
+ const [focus, setFocus] = useState(false);
532
+ const inputRef = useRef(null);
533
+ const { t } = useTranslation();
534
+ return /* @__PURE__ */ jsxs("div", { className: "oui-mt-3 oui-mb-6 oui-flex oui-items-center", children: [
535
+ /* @__PURE__ */ jsx(
536
+ Checkbox,
537
+ {
538
+ className: "oui-mt-[2px]",
539
+ checked: check,
540
+ onCheckedChange: (e) => {
541
+ setCheck(e);
542
+ }
543
+ }
544
+ ),
545
+ /* @__PURE__ */ jsx(
546
+ "div",
547
+ {
548
+ className: "oui-text-xs oui-text-base-contrast-54 oui-ml-1 hover:oui-cursor-pointer",
549
+ onClick: () => {
550
+ setCheck(!props.check);
551
+ },
552
+ children: t("share.pnl.optionalInfo.message")
553
+ }
554
+ ),
555
+ /* @__PURE__ */ jsx("div", { className: "oui-bg-base-900 oui-mx-2 oui-rounded-sm", children: /* @__PURE__ */ jsx(
556
+ Input,
557
+ {
558
+ ref: inputRef,
559
+ placeholder: t("share.pnl.optionalInfo.message.placeholder"),
560
+ classNames: {
561
+ root: "oui-w-[320px]"
562
+ },
563
+ size: "sm",
564
+ value: message,
565
+ autoFocus: false,
566
+ suffix: focus && /* @__PURE__ */ jsx(
567
+ "button",
568
+ {
569
+ className: "oui-mr-3 oui-cursor-pointer",
570
+ onMouseDown: (e) => {
571
+ setMessage("");
572
+ setTimeout(() => {
573
+ inputRef.current?.focus();
574
+ }, 50);
575
+ e.stopPropagation();
576
+ },
577
+ children: /* @__PURE__ */ jsx(CloseCircleFillIcon, { size: 18, color: "white" })
578
+ }
579
+ ),
580
+ onFocus: () => setFocus(true),
581
+ onBlur: () => setFocus(false),
582
+ onChange: (e) => {
583
+ if (e.target.value.length > 25) {
584
+ toast.error(t("share.pnl.optionalInfo.message.maxLength"));
585
+ return;
586
+ }
587
+ setCheck(e.target.value.length > 0);
588
+ setMessage(e.target.value);
589
+ }
590
+ }
591
+ ) })
592
+ ] });
593
+ };
594
+ var ShareOption = (props) => {
595
+ const { type, curType, setShareOption } = props;
596
+ const { t } = useTranslation();
597
+ const text = useMemo(() => {
598
+ switch (type) {
599
+ case "openPrice":
600
+ return t("share.pnl.optionalInfo.openPrice");
601
+ case "closePrice":
602
+ return t("share.pnl.optionalInfo.closePrice");
603
+ case "openTime":
604
+ return t("share.pnl.optionalInfo.openTime");
605
+ case "closeTime":
606
+ return t("share.pnl.optionalInfo.closeTime");
607
+ case "markPrice":
608
+ return t("common.markPrice");
609
+ case "quantity":
610
+ return t("common.quantity");
611
+ case "leverage":
612
+ return t("common.leverage");
613
+ }
614
+ }, [type, t]);
615
+ const isSelected = curType.has(type);
616
+ return /* @__PURE__ */ jsxs(
617
+ Flex,
618
+ {
619
+ itemAlign: "center",
620
+ gap: 1,
621
+ className: cn("hover:oui-cursor-pointer"),
622
+ onClick: () => {
623
+ setShareOption((value) => {
624
+ const updateSet = new Set(value);
625
+ if (isSelected) {
626
+ updateSet.delete(type);
627
+ } else {
628
+ updateSet.add(type);
629
+ }
630
+ return updateSet;
631
+ });
632
+ },
633
+ children: [
634
+ /* @__PURE__ */ jsx(
635
+ Checkbox,
636
+ {
637
+ size: 16,
638
+ checked: isSelected,
639
+ className: "oui-pt-[2px]",
640
+ onCheckedChange: (checked) => {
641
+ setShareOption((value) => {
642
+ const updateSet = new Set(value);
643
+ if (isSelected) {
644
+ updateSet.delete(type);
645
+ } else {
646
+ updateSet.add(type);
647
+ }
648
+ return updateSet;
649
+ });
650
+ }
651
+ }
652
+ ),
653
+ /* @__PURE__ */ jsx(Text, { size: "xs", intensity: 54, children: text })
654
+ ]
655
+ }
656
+ );
657
+ };
658
+ var PnlFormatView = (props) => {
659
+ const { type, curType, setPnlFormat } = props;
660
+ const { t } = useTranslation();
661
+ const text = useMemo(() => {
662
+ switch (type) {
663
+ case "roi_pnl":
664
+ return t("share.pnl.displayFormat.roi&Pnl");
665
+ case "roi":
666
+ return t("share.pnl.displayFormat.roi");
667
+ case "pnl":
668
+ return t("share.pnl.displayFormat.pnl");
669
+ }
670
+ }, [type, t]);
671
+ const isSelected = type === curType;
672
+ let clsName = "oui-flex oui-items-center oui-gap-1 oui-cursor-pointer";
673
+ if (isSelected) {
674
+ clsName += " oui-text-base-contrast";
675
+ } else {
676
+ clsName += "";
677
+ }
678
+ return /* @__PURE__ */ jsxs(
679
+ "div",
680
+ {
681
+ className: clsName,
682
+ onClick: () => {
683
+ setPnlFormat(type);
684
+ },
685
+ children: [
686
+ /* @__PURE__ */ jsx(RadioButton, { sel: isSelected }),
687
+ /* @__PURE__ */ jsx(
688
+ Text,
689
+ {
690
+ size: "xs",
691
+ intensity: 54,
692
+ className: cn(
693
+ "oui-ml-2 "
694
+ // isSelected && "oui-text-base-contrast"
695
+ ),
696
+ children: text
697
+ }
698
+ )
699
+ ]
700
+ }
701
+ );
702
+ };
703
+ var RadioButton = (props) => {
704
+ return /* @__PURE__ */ jsx(
705
+ "button",
706
+ {
707
+ type: "button",
708
+ children: props.sel === true ? /* @__PURE__ */ jsx(SelIcon, {}) : /* @__PURE__ */ jsx(UnselIcon, {})
709
+ }
710
+ );
711
+ };
712
+ var SelIcon = () => {
713
+ return /* @__PURE__ */ jsxs(
714
+ "svg",
715
+ {
716
+ width: "16",
717
+ height: "16",
718
+ viewBox: "0 0 16 16",
719
+ fill: "currentColor",
720
+ xmlns: "http://www.w3.org/2000/svg",
721
+ className: "oui-fill-primary-darken",
722
+ children: [
723
+ /* @__PURE__ */ jsx(
724
+ "path",
725
+ {
726
+ d: "M8.01 1.333a6.667 6.667 0 1 0 0 13.333 6.667 6.667 0 0 0 0-13.333m0 1.333a5.334 5.334 0 1 1-.001 10.667 5.334 5.334 0 0 1 0-10.667",
727
+ fill: "#fff",
728
+ fillOpacity: ".36"
729
+ }
730
+ ),
731
+ /* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "3.333" })
732
+ ]
733
+ }
734
+ );
735
+ };
736
+ var UnselIcon = () => {
737
+ return /* @__PURE__ */ jsx(
738
+ "svg",
739
+ {
740
+ width: "16",
741
+ height: "16",
742
+ viewBox: "0 0 16 16",
743
+ fill: "none",
744
+ xmlns: "http://www.w3.org/2000/svg",
745
+ children: /* @__PURE__ */ jsx(
746
+ "path",
747
+ {
748
+ d: "M8.01 1.333a6.667 6.667 0 1 0 0 13.333 6.667 6.667 0 0 0 0-13.333m0 1.333a5.334 5.334 0 1 1-.001 10.667 5.334 5.334 0 0 1 0-10.667",
749
+ fill: "#fff",
750
+ fillOpacity: ".54"
751
+ }
752
+ )
753
+ }
754
+ );
755
+ };
756
+ var DesktopSharePnLContent = (props) => {
757
+ const { shareOptions } = props;
758
+ const { t } = useTranslation();
759
+ const localPnlConfig = getPnlInfo();
760
+ const hasRoiAndPnl = props.entity.roi != null && props.entity.pnl != null;
761
+ const formats = hasRoiAndPnl ? ["roi_pnl", "roi", "pnl"] : props.entity.roi != null ? ["roi"] : props.entity.pnl != null ? ["pnl"] : [];
762
+ const [pnlFormat, setPnlFormat] = useState(
763
+ formats.length == 1 ? formats[0] : localPnlConfig.pnlFormat
764
+ );
765
+ const [shareOption, setShareOption] = useState(
766
+ new Set(localPnlConfig.options)
767
+ );
768
+ const [selectedSnap, setSelectedSnap] = useState(localPnlConfig.bgIndex);
769
+ const [message, setMessage] = useState(localPnlConfig.message);
770
+ const [check, setCheck] = useState(false);
771
+ const { backgroundImages, ...resetOptions } = shareOptions ?? {
772
+ backgroundImages: []
773
+ };
774
+ const [domain, setDomain] = useState("");
775
+ const posterRef = useRef(null);
776
+ useEffect(() => {
777
+ const currentDomain = window.location.hostname;
778
+ setDomain(currentDomain);
779
+ }, []);
780
+ const curBgImg = useMemo(() => {
781
+ return shareOptions?.backgroundImages?.[selectedSnap];
782
+ }, [shareOptions?.backgroundImages, selectedSnap]);
783
+ const posterData = getPnLPosterData(
784
+ props.entity,
785
+ check ? message : "",
786
+ domain,
787
+ pnlFormat,
788
+ shareOption,
789
+ props.baseDp,
790
+ props.quoteDp,
791
+ props.referral
792
+ );
793
+ const onCopy = () => {
794
+ posterRef.current?.copy().then(() => {
795
+ props.hide?.();
796
+ toast.success(t("share.pnl.image.copied"));
797
+ }).catch((e) => {
798
+ toast.error(() => {
799
+ return /* @__PURE__ */ jsxs("div", { children: [
800
+ /* @__PURE__ */ jsx("div", { children: t("common.copy.failed") }),
801
+ /* @__PURE__ */ jsx("div", { className: "oui-mt-2 oui-max-w-[396px] oui-text-2xs oui-text-base-contrast-54", children: t("share.pnl.copy.failed.description") })
802
+ ] });
803
+ });
804
+ });
805
+ };
806
+ const onDownload = () => {
807
+ posterRef.current?.download("Poster.png");
808
+ props.hide?.();
809
+ };
810
+ const options = useMemo(() => {
811
+ const mapping = [
812
+ "openPrice",
813
+ "closePrice",
814
+ "markPrice",
815
+ "openTime",
816
+ "closeTime",
817
+ "leverage",
818
+ "quantity"
819
+ ];
820
+ return mapping.filter((key) => !!props.entity[key]);
821
+ }, [props.entity]);
822
+ savePnlInfo(pnlFormat, shareOption, selectedSnap, message);
823
+ return /* @__PURE__ */ jsxs("div", { className: "oui-relative oui-flex oui-size-full oui-flex-col", children: [
824
+ /* @__PURE__ */ jsxs("div", { className: "oui-h-full oui-flex-1 oui-overflow-y-auto", children: [
825
+ /* @__PURE__ */ jsxs(Box, { mt: 9, height: 422, children: [
826
+ /* @__PURE__ */ jsx(Flex, { itemAlign: "center", justify: "center", children: /* @__PURE__ */ jsx(
827
+ Poster,
828
+ {
829
+ width: 552,
830
+ height: 310,
831
+ data: {
832
+ backgroundImg: curBgImg,
833
+ ...resetOptions,
834
+ data: posterData
835
+ },
836
+ ratio: 3,
837
+ ref: posterRef
838
+ }
839
+ ) }),
840
+ /* @__PURE__ */ jsx(
841
+ CarouselBackgroundImage,
842
+ {
843
+ backgroundImages: shareOptions?.backgroundImages ?? EMPTY_LIST,
844
+ selectedSnap,
845
+ setSelectedSnap
846
+ }
847
+ )
848
+ ] }),
849
+ /* @__PURE__ */ jsxs(
850
+ Flex,
851
+ {
852
+ direction: "column",
853
+ px: 10,
854
+ mt: 6,
855
+ justify: "start",
856
+ itemAlign: "start",
857
+ width: "100%",
858
+ children: [
859
+ /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 80, children: t("share.pnl.displayFormat") }),
860
+ /* @__PURE__ */ jsx(Flex, { pt: 3, gap: 3, itemAlign: "center", children: formats.map((e, index) => /* @__PURE__ */ jsx(
861
+ PnlFormatView,
862
+ {
863
+ setPnlFormat,
864
+ type: e,
865
+ curType: pnlFormat
866
+ },
867
+ index
868
+ )) }),
869
+ /* @__PURE__ */ jsx(Divider, { className: "oui-w-full oui-border-white/10 oui-pt-6" }),
870
+ /* @__PURE__ */ jsxs(
871
+ Flex,
872
+ {
873
+ mt: 6,
874
+ direction: "column",
875
+ justify: "start",
876
+ itemAlign: "start",
877
+ children: [
878
+ /* @__PURE__ */ jsx(Text, { size: "sm", intensity: 80, children: t("share.pnl.optionalInfo") }),
879
+ /* @__PURE__ */ jsx(Flex, { mt: 3, gap: 4, className: "oui-flex-wrap", children: options.map((item, index) => /* @__PURE__ */ jsx(
880
+ ShareOption,
881
+ {
882
+ setShareOption,
883
+ type: item,
884
+ curType: shareOption
885
+ },
886
+ index
887
+ )) })
888
+ ]
889
+ }
890
+ ),
891
+ /* @__PURE__ */ jsx(
892
+ Message,
893
+ {
894
+ message,
895
+ setMessage,
896
+ check,
897
+ setCheck
898
+ }
899
+ )
900
+ ]
901
+ }
902
+ )
903
+ ] }),
904
+ /* @__PURE__ */ jsx(BottomButtons, { onClickCopy: onCopy, onClickDownload: onDownload })
905
+ ] });
906
+ };
907
+ var CarouselContext = React.createContext(null);
908
+ function useCarousel() {
909
+ const context = React.useContext(CarouselContext);
910
+ if (!context) {
911
+ throw new Error("useCarousel must be used within a <Carousel />");
912
+ }
913
+ return context;
914
+ }
915
+ var Carousel = React.forwardRef((originalProps, ref) => {
916
+ const {
917
+ orientation = "horizontal",
918
+ opts,
919
+ setApi,
920
+ plugins,
921
+ className,
922
+ children,
923
+ ...props
924
+ } = originalProps;
925
+ const [carouselRef, api] = useEmblaCarousel(
926
+ { ...opts, axis: orientation === "horizontal" ? "x" : "y" },
927
+ plugins
928
+ );
929
+ const [canScrollPrev, setCanScrollPrev] = React.useState(false);
930
+ const [canScrollNext, setCanScrollNext] = React.useState(false);
931
+ const [selectedIndex, setSelectedIndex] = React.useState(
932
+ props.initIndex || 0
933
+ );
934
+ const [scrollSnaps, setScrollSnaps] = React.useState([]);
935
+ const onSelect = React.useCallback(
936
+ (api2) => {
937
+ if (!api2) {
938
+ return;
939
+ }
940
+ if (scrollSnaps.length === 0) {
941
+ setScrollSnaps(api2.scrollSnapList());
942
+ }
943
+ setSelectedIndex(api2.selectedScrollSnap());
944
+ setCanScrollPrev(api2.canScrollPrev());
945
+ setCanScrollNext(api2.canScrollNext());
946
+ },
947
+ [scrollSnaps]
948
+ );
949
+ const scrollPrev = React.useCallback(() => {
950
+ api?.scrollPrev();
951
+ }, [api]);
952
+ const scrollNext = React.useCallback(() => {
953
+ api?.scrollNext();
954
+ }, [api]);
955
+ const handleKeyDown = React.useCallback(
956
+ (event) => {
957
+ if (event.key === "ArrowLeft") {
958
+ event.preventDefault();
959
+ scrollPrev();
960
+ } else if (event.key === "ArrowRight") {
961
+ event.preventDefault();
962
+ scrollNext();
963
+ }
964
+ },
965
+ [scrollPrev, scrollNext]
966
+ );
967
+ React.useEffect(() => {
968
+ if (!api || !setApi) {
969
+ return;
970
+ }
971
+ setApi(api);
972
+ }, [api, setApi]);
973
+ React.useEffect(() => {
974
+ if (!api) {
975
+ return;
976
+ }
977
+ onSelect(api);
978
+ api.on("reInit", onSelect);
979
+ api.on("select", onSelect);
980
+ if (props.initIndex) {
981
+ api.scrollTo(props.initIndex);
982
+ }
983
+ return () => {
984
+ api?.off("select", onSelect);
985
+ };
986
+ }, [api, onSelect]);
987
+ const memoizedValue = React.useMemo(() => {
988
+ return {
989
+ carouselRef,
990
+ api,
991
+ opts,
992
+ orientation: orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
993
+ scrollPrev,
994
+ scrollNext,
995
+ canScrollPrev,
996
+ canScrollNext,
997
+ selectedIndex,
998
+ scrollSnaps
999
+ };
1000
+ }, [
1001
+ carouselRef,
1002
+ api,
1003
+ opts,
1004
+ orientation,
1005
+ scrollPrev,
1006
+ scrollNext,
1007
+ canScrollPrev,
1008
+ canScrollNext,
1009
+ selectedIndex,
1010
+ scrollSnaps
1011
+ ]);
1012
+ return /* @__PURE__ */ jsx(CarouselContext.Provider, { value: memoizedValue, children: /* @__PURE__ */ jsx(
1013
+ "div",
1014
+ {
1015
+ ref,
1016
+ onKeyDownCapture: handleKeyDown,
1017
+ className: cn("oui-relative", className),
1018
+ role: "region",
1019
+ "aria-roledescription": "carousel",
1020
+ ...props,
1021
+ children
1022
+ }
1023
+ ) });
1024
+ });
1025
+ Carousel.displayName = "Carousel";
1026
+ var CarouselContent = React.forwardRef((originalProps, ref) => {
1027
+ const { className, children, ...props } = originalProps;
1028
+ const { carouselRef, orientation } = useCarousel();
1029
+ return /* @__PURE__ */ jsx("div", { ref: carouselRef, className: "oui-overflow-hidden", children: /* @__PURE__ */ jsx(
1030
+ "div",
1031
+ {
1032
+ ref,
1033
+ className: cn(
1034
+ "oui-flex",
1035
+ orientation === "horizontal" ? "oui--ml-4" : "oui--mt-4 oui-flex-col",
1036
+ className
1037
+ ),
1038
+ ...props,
1039
+ children
1040
+ }
1041
+ ) });
1042
+ });
1043
+ CarouselContent.displayName = "CarouselContent";
1044
+ var CarouselItem = React.forwardRef((originalProps, ref) => {
1045
+ const { className, children, ...props } = originalProps;
1046
+ const { orientation } = useCarousel();
1047
+ return /* @__PURE__ */ jsx(
1048
+ "div",
1049
+ {
1050
+ ref,
1051
+ role: "group",
1052
+ "aria-roledescription": "slide",
1053
+ className: cn(
1054
+ "oui-min-w-0 oui-shrink-0 oui-grow-0 oui-basis-full",
1055
+ orientation === "horizontal" ? "oui-pl-4" : "oui-pt-4",
1056
+ className
1057
+ ),
1058
+ ...props,
1059
+ children
1060
+ }
1061
+ );
1062
+ });
1063
+ CarouselItem.displayName = "CarouselItem";
1064
+ var CarouselPrevious = React.forwardRef((originalProps, ref) => {
1065
+ const {
1066
+ className,
1067
+ variant = "contained",
1068
+ size = "icon",
1069
+ ...props
1070
+ } = originalProps;
1071
+ const { orientation, scrollPrev, canScrollPrev } = useCarousel();
1072
+ return /* @__PURE__ */ jsxs(
1073
+ Button,
1074
+ {
1075
+ ref,
1076
+ variant,
1077
+ className: cn(
1078
+ "oui-absolute oui-size-8 oui-rounded-full",
1079
+ orientation === "horizontal" ? "oui--left-12 oui-top-1/2 oui--translate-y-1/2" : "oui--top-12 oui-left-1/2 oui--translate-x-1/2 oui-rotate-90",
1080
+ className
1081
+ ),
1082
+ disabled: !canScrollPrev,
1083
+ onClick: scrollPrev,
1084
+ ...props,
1085
+ children: [
1086
+ /* @__PURE__ */ jsx(ChevronLeftIcon, { size: 20 }),
1087
+ /* @__PURE__ */ jsx("span", { className: "oui-sr-only", children: "Previous slide" })
1088
+ ]
1089
+ }
1090
+ );
1091
+ });
1092
+ CarouselPrevious.displayName = "CarouselPrevious";
1093
+ var CarouselNext = React.forwardRef((originalProps, ref) => {
1094
+ const {
1095
+ className,
1096
+ variant = "contained",
1097
+ size = "icon",
1098
+ ...props
1099
+ } = originalProps;
1100
+ const { orientation, scrollNext, canScrollNext } = useCarousel();
1101
+ return /* @__PURE__ */ jsxs(
1102
+ Button,
1103
+ {
1104
+ ref,
1105
+ variant,
1106
+ className: cn(
1107
+ "oui-absolute oui-size-8 oui-rounded-full",
1108
+ orientation === "horizontal" ? "oui--right-12 oui-top-1/2 oui--translate-y-1/2" : "oui--bottom-12 oui-left-1/2 oui--translate-x-1/2 oui-rotate-90",
1109
+ className
1110
+ ),
1111
+ disabled: !canScrollNext,
1112
+ onClick: scrollNext,
1113
+ ...props,
1114
+ children: [
1115
+ /* @__PURE__ */ jsx(ChevronRightIcon, { size: 20 }),
1116
+ /* @__PURE__ */ jsx("span", { className: "oui-sr-only", children: "Next slide" })
1117
+ ]
1118
+ }
1119
+ );
1120
+ });
1121
+ CarouselNext.displayName = "CarouselNext";
1122
+ var CarouselIdentifier = (props) => {
1123
+ const { scrollSnaps, selectedIndex } = useCarousel();
1124
+ return /* @__PURE__ */ jsx("div", { className: cn("oui-flex oui-gap-1", props.className), children: scrollSnaps.map((_, index) => {
1125
+ return /* @__PURE__ */ jsx(
1126
+ Dot,
1127
+ {
1128
+ index,
1129
+ active: index === selectedIndex,
1130
+ onClick: props.onClick,
1131
+ className: props.dotClassName,
1132
+ activeClassName: props.dotActiveClassName
1133
+ },
1134
+ index
1135
+ );
1136
+ }) });
1137
+ };
1138
+ CarouselIdentifier.displayName = "CarouselIdentifier";
1139
+ var Dot = ({ index, active, onClick, className, activeClassName }) => {
1140
+ const activedClassName = activeClassName || "oui-bg-primary-darken";
1141
+ return /* @__PURE__ */ jsx(
1142
+ "button",
1143
+ {
1144
+ onClick: () => onClick?.(index),
1145
+ className: cn(
1146
+ "oui-size-2 oui-rounded-full oui-bg-white/30",
1147
+ className,
1148
+ active && `active ${activedClassName}`
1149
+ )
1150
+ }
1151
+ );
1152
+ };
10
1153
 
11
- export { to as SharePnLBottomSheetId, ye as SharePnLBottomSheetWidget, eo as SharePnLDialogId, ve as SharePnLDialogWidget, Q as useSharePnLScript };
1154
+ // src/sharePnL/carousel/index.tsx
1155
+ var Carousel2 = Carousel;
1156
+ Carousel2.Content = CarouselContent;
1157
+ Carousel2.Item = CarouselItem;
1158
+ Carousel2.Next = CarouselNext;
1159
+ Carousel2.Previous = CarouselPrevious;
1160
+ Carousel2.indentify = CarouselIdentifier;
1161
+ var MobileSharePnLContent = (props) => {
1162
+ const { shareOptions } = props;
1163
+ const { t } = useTranslation();
1164
+ const localPnlConfig = getPnlInfo();
1165
+ const hasRoiAndPnl = props.entity.roi != null && props.entity.pnl != null;
1166
+ const formats = hasRoiAndPnl ? ["roi_pnl", "roi", "pnl"] : props.entity.roi != null ? ["roi"] : props.entity.pnl != null ? ["pnl"] : [];
1167
+ const [pnlFormat, setPnlFormat] = useState(
1168
+ formats.length == 1 ? formats[0] : localPnlConfig.pnlFormat
1169
+ );
1170
+ const [shareOption, setShareOption] = useState(
1171
+ new Set(localPnlConfig.options)
1172
+ );
1173
+ const [message, setMessage] = useState(localPnlConfig.message);
1174
+ const [selectIndex, setSelectIndex] = useState(localPnlConfig.bgIndex);
1175
+ const { backgroundImages, ...resetOptions } = shareOptions ?? {
1176
+ backgroundImages: []
1177
+ };
1178
+ const [domain, setDomain] = useState("");
1179
+ const posterRefs = shareOptions?.backgroundImages?.map(
1180
+ () => useRef(null)
1181
+ );
1182
+ useEffect(() => {
1183
+ const currentDomain = window.location.hostname;
1184
+ setDomain(currentDomain);
1185
+ }, []);
1186
+ const posterData = getPnLPosterData(
1187
+ props.entity,
1188
+ message,
1189
+ domain,
1190
+ pnlFormat,
1191
+ shareOption,
1192
+ props.baseDp,
1193
+ props.quoteDp,
1194
+ props.referral
1195
+ );
1196
+ const carouselRef = useRef();
1197
+ const aspectRatio = 552 / 310;
1198
+ const [scale, setScale] = useState(1);
1199
+ const [carouselHeight, setCarouselHeight] = useState(0);
1200
+ const [focus, setFocus] = useState(false);
1201
+ const inputRef = useRef(null);
1202
+ useEffect(() => {
1203
+ if (carouselRef.current) {
1204
+ const divWidth = carouselRef.current.offsetWidth;
1205
+ const divHeight = divWidth / aspectRatio;
1206
+ setCarouselHeight(divHeight);
1207
+ setScale(divWidth / 552);
1208
+ }
1209
+ }, [carouselRef, domain]);
1210
+ const onSharePnL = async (posterRef) => {
1211
+ if (!posterRef.current)
1212
+ return;
1213
+ const data = posterRef.current?.toDataURL();
1214
+ const blob = dataURItoBlob(data);
1215
+ try {
1216
+ if (navigator.share) {
1217
+ await navigator.share({
1218
+ // title: "Share PnL",
1219
+ text: message,
1220
+ // url: imageUrl,
1221
+ files: [new File([blob], "image.png", { type: "image/png" })]
1222
+ });
1223
+ } else {
1224
+ }
1225
+ props.hide?.();
1226
+ } catch (error) {
1227
+ }
1228
+ };
1229
+ const options = useMemo(() => {
1230
+ const mapping = [
1231
+ "openPrice",
1232
+ "closePrice",
1233
+ "openTime",
1234
+ "closeTime",
1235
+ "leverage",
1236
+ "markPrice",
1237
+ "quantity"
1238
+ ];
1239
+ return mapping.filter((key) => !!props.entity[key]);
1240
+ }, [props.entity]);
1241
+ savePnlInfo(pnlFormat, shareOption, selectIndex, message);
1242
+ return /* @__PURE__ */ jsxs("div", { className: "oui-w-full", children: [
1243
+ /* @__PURE__ */ jsx(
1244
+ "div",
1245
+ {
1246
+ ref: carouselRef,
1247
+ className: "oui-mt-4 oui-w-full oui-overflow-hidden",
1248
+ style: { height: `${carouselHeight + 20}px` },
1249
+ children: /* @__PURE__ */ jsxs(
1250
+ Carousel2,
1251
+ {
1252
+ className: "oui-w-full oui-overflow-hidden",
1253
+ opts: { align: "start" },
1254
+ initIndex: selectIndex,
1255
+ children: [
1256
+ /* @__PURE__ */ jsx(CarouselContent, { style: { height: `${carouselHeight}px` }, children: shareOptions?.backgroundImages?.map((item, index) => /* @__PURE__ */ jsx(CarouselItem, { children: /* @__PURE__ */ jsx(
1257
+ Poster,
1258
+ {
1259
+ className: "oui-origin-top-left oui-transform",
1260
+ style: { scale: `${scale}` },
1261
+ width: 552,
1262
+ height: 310,
1263
+ data: {
1264
+ backgroundImg: item,
1265
+ ...resetOptions,
1266
+ data: posterData
1267
+ },
1268
+ ratio: 3,
1269
+ ref: posterRefs?.[index]
1270
+ }
1271
+ ) }, index)) }),
1272
+ /* @__PURE__ */ jsx("div", { className: "oui-mb-1 oui-mt-2 oui-flex oui-justify-center", children: /* @__PURE__ */ jsx(
1273
+ MyIdentifier,
1274
+ {
1275
+ dotClassName: "oui-w-[16px] oui-h-[4px] oui-bg-base-300",
1276
+ dotActiveClassName: "!oui-bg-primary-darken oui-w-[20px]",
1277
+ setSelectIndex
1278
+ }
1279
+ ) })
1280
+ ]
1281
+ }
1282
+ )
1283
+ }
1284
+ ),
1285
+ /* @__PURE__ */ jsxs(ScrollArea, { className: "oui-custom-scrollbar oui-max-h-[200px] oui-overflow-y-auto", children: [
1286
+ /* @__PURE__ */ jsxs("div", { className: "oui-mt-4", children: [
1287
+ /* @__PURE__ */ jsx("div", { className: "oui-text-3xs oui-text-base-contrast-54", children: t("share.pnl.displayFormat") }),
1288
+ /* @__PURE__ */ jsx("div", { className: "oui-row-span-1 oui-grid oui-grid-cols-3 oui-justify-between oui-gap-3 oui-px-1 oui-pt-3", children: formats.map((item, index) => /* @__PURE__ */ jsx(
1289
+ PnlFormatView2,
1290
+ {
1291
+ setPnlFormat,
1292
+ type: item,
1293
+ curType: pnlFormat
1294
+ },
1295
+ index
1296
+ )) })
1297
+ ] }),
1298
+ /* @__PURE__ */ jsxs("div", { className: "oui-mt-3", children: [
1299
+ /* @__PURE__ */ jsx("div", { className: "oui-h-[18px] oui-text-3xs oui-text-base-contrast-54", children: t("share.pnl.optionalInfo") }),
1300
+ /* @__PURE__ */ jsx("div", { className: "oui-mt-3 oui-flex oui-flex-wrap oui-gap-3", children: options.map((item, index) => /* @__PURE__ */ jsx(
1301
+ ShareOption2,
1302
+ {
1303
+ setShareOption,
1304
+ type: item,
1305
+ curType: shareOption
1306
+ },
1307
+ index
1308
+ )) })
1309
+ ] }),
1310
+ /* @__PURE__ */ jsxs("div", { className: "oui-mb-8 oui-mt-3", children: [
1311
+ /* @__PURE__ */ jsx("div", { className: "oui-h-[18px] oui-text-3xs oui-text-base-contrast-54", children: t("share.pnl.optionalInfo.message") }),
1312
+ /* @__PURE__ */ jsx("div", { className: "oui-bg-base-600 oui-mx-1 oui-mt-3 oui-h-[48px]", children: /* @__PURE__ */ jsx(
1313
+ Input,
1314
+ {
1315
+ placeholder: t("share.pnl.optionalInfo.message.placeholder"),
1316
+ containerClassName: "oui-bg-transparent oui-h-[48px]",
1317
+ value: message,
1318
+ autoFocus: false,
1319
+ onChange: (e) => {
1320
+ if (e.target.value.length > 25) {
1321
+ toast.error(t("share.pnl.optionalInfo.message.maxLength"));
1322
+ return;
1323
+ }
1324
+ setMessage(e.target.value);
1325
+ },
1326
+ ref: inputRef,
1327
+ onFocus: () => setFocus(true),
1328
+ onBlur: () => setFocus(false),
1329
+ suffix: focus && /* @__PURE__ */ jsx(
1330
+ "button",
1331
+ {
1332
+ className: "oui-mr-3 oui-cursor-pointer",
1333
+ onMouseDown: (e) => {
1334
+ setMessage("");
1335
+ setTimeout(() => {
1336
+ inputRef.current?.focus();
1337
+ }, 50);
1338
+ e.stopPropagation();
1339
+ },
1340
+ children: /* @__PURE__ */ jsx(CloseCircleFillIcon, { size: 18, color: "white" })
1341
+ }
1342
+ )
1343
+ }
1344
+ ) })
1345
+ ] })
1346
+ ] }),
1347
+ /* @__PURE__ */ jsx("div", { className: "oui-pt-2", children: /* @__PURE__ */ jsx(
1348
+ Button,
1349
+ {
1350
+ fullWidth: true,
1351
+ className: "oui-h-[40px] oui-text-[16px]",
1352
+ onClick: () => {
1353
+ const ref = posterRefs?.[selectIndex];
1354
+ if (ref) {
1355
+ onSharePnL(ref);
1356
+ }
1357
+ },
1358
+ children: t("common.share")
1359
+ }
1360
+ ) })
1361
+ ] });
1362
+ };
1363
+ var PnlFormatView2 = (props) => {
1364
+ const { type, curType, setPnlFormat } = props;
1365
+ const { t } = useTranslation();
1366
+ const text = useMemo(() => {
1367
+ switch (type) {
1368
+ case "roi_pnl":
1369
+ return t("share.pnl.displayFormat.roi&Pnl");
1370
+ case "roi":
1371
+ return t("share.pnl.displayFormat.roi");
1372
+ case "pnl":
1373
+ return t("share.pnl.displayFormat.pnl");
1374
+ }
1375
+ }, [type]);
1376
+ const isSelected = type === curType;
1377
+ return /* @__PURE__ */ jsx(
1378
+ "div",
1379
+ {
1380
+ className: cn(
1381
+ "oui-referral-shadow oui-flex oui-h-[46px] oui-flex-1 oui-items-center oui-rounded-lg oui-bg-base-4 oui-px-3 oui-shadow-lg hover:oui-cursor-pointer",
1382
+ isSelected && "oui-dot-sel oui-bg-primary-darken"
1383
+ ),
1384
+ onClick: () => {
1385
+ setPnlFormat(type);
1386
+ },
1387
+ children: /* @__PURE__ */ jsx("div", { className: "oui-text-sm oui-text-base-contrast", children: text })
1388
+ }
1389
+ );
1390
+ };
1391
+ var ShareOption2 = (props) => {
1392
+ const { type, curType, setShareOption } = props;
1393
+ const { t } = useTranslation();
1394
+ const text = useMemo(() => {
1395
+ switch (type) {
1396
+ case "openPrice":
1397
+ return t("share.pnl.optionalInfo.openPrice");
1398
+ case "closePrice":
1399
+ return t("share.pnl.optionalInfo.closePrice");
1400
+ case "openTime":
1401
+ return t("share.pnl.optionalInfo.openTime");
1402
+ case "closeTime":
1403
+ return t("share.pnl.optionalInfo.closeTime");
1404
+ case "markPrice":
1405
+ return t("common.markPrice");
1406
+ case "quantity":
1407
+ return t("common.quantity");
1408
+ case "leverage":
1409
+ return t("common.leverage");
1410
+ }
1411
+ }, [type, t]);
1412
+ const isSelected = curType.has(type);
1413
+ return /* @__PURE__ */ jsxs(
1414
+ "div",
1415
+ {
1416
+ className: cn(
1417
+ "oui-referral-shadow oui-mt-0 oui-flex oui-h-[46px] oui-w-[calc(50%-6px)] oui-items-center oui-rounded-lg oui-bg-base-4 oui-p-3 oui-shadow-lg hover:oui-cursor-pointer"
1418
+ ),
1419
+ onClick: () => {
1420
+ setShareOption((value) => {
1421
+ const updateSet = new Set(value);
1422
+ if (isSelected) {
1423
+ updateSet.delete(type);
1424
+ } else {
1425
+ updateSet.add(type);
1426
+ }
1427
+ return updateSet;
1428
+ });
1429
+ },
1430
+ children: [
1431
+ /* @__PURE__ */ jsx("div", { className: "oui-flex-1 oui-text-sm oui-text-base-contrast", children: text }),
1432
+ isSelected && /* @__PURE__ */ jsx(ChoicesFillIcon, {})
1433
+ ]
1434
+ }
1435
+ );
1436
+ };
1437
+ function dataURItoBlob(dataURI) {
1438
+ const byteString = atob(dataURI.split(",")[1]);
1439
+ const mimeString = dataURI.split(",")[0].split(":")[1].split(";")[0];
1440
+ const ab = new ArrayBuffer(byteString.length);
1441
+ const ia = new Uint8Array(ab);
1442
+ for (let i = 0; i < byteString.length; i++) {
1443
+ ia[i] = byteString.charCodeAt(i);
1444
+ }
1445
+ return new Blob([ab], { type: mimeString });
1446
+ }
1447
+ var MyIdentifier = (props) => {
1448
+ const { scrollSnaps, selectedIndex } = useCarousel();
1449
+ useEffect(() => {
1450
+ props.setSelectIndex(selectedIndex);
1451
+ }, [selectedIndex]);
1452
+ return /* @__PURE__ */ jsx("div", { className: cn("oui-flex oui-gap-1"), children: scrollSnaps.map((_, index) => {
1453
+ return /* @__PURE__ */ jsx(
1454
+ Dot,
1455
+ {
1456
+ index,
1457
+ active: index === selectedIndex,
1458
+ onClick: props.onClick,
1459
+ className: props.dotClassName,
1460
+ activeClassName: props.dotActiveClassName
1461
+ },
1462
+ index
1463
+ );
1464
+ }) });
1465
+ };
1466
+ var ChoicesFillIcon = () => {
1467
+ return /* @__PURE__ */ jsx(
1468
+ "svg",
1469
+ {
1470
+ width: "24",
1471
+ height: "24",
1472
+ viewBox: "0 0 24 24",
1473
+ fill: "none",
1474
+ xmlns: "http://www.w3.org/2000/svg",
1475
+ children: /* @__PURE__ */ jsx(
1476
+ "path",
1477
+ {
1478
+ fillRule: "evenodd",
1479
+ clipRule: "evenodd",
1480
+ d: "M2.01416 11.9989C2.01416 6.47589 6.49136 1.9989 12.0142 1.9989C17.5372 1.9989 22.0142 6.47589 22.0142 11.9989C22.0142 17.5219 17.5372 21.9989 12.0142 21.9989C6.49136 21.9989 2.01416 17.5219 2.01416 11.9989ZM16.9853 7.31211C17.2125 7.09537 17.5236 7 17.8218 7C18.1201 7 18.4312 7.09537 18.6583 7.31211C19.1139 7.74546 19.1139 8.47384 18.6583 8.9072L10.5077 16.675C10.0534 17.1083 9.28909 17.1083 8.83472 16.675L5.34077 13.3459C4.88641 12.9126 4.88641 12.1841 5.34077 11.7508C5.79631 11.3175 6.56057 11.3175 7.01493 11.7508L9.67122 14.2822L16.9853 7.31211Z",
1481
+ fill: "white",
1482
+ fillOpacity: "1"
1483
+ }
1484
+ )
1485
+ }
1486
+ );
1487
+ };
1488
+ var DesktopSharePnL = (props) => {
1489
+ const { entity, baseDp, quoteDp, referralInfo, shareOptions, hide } = props;
1490
+ if (!shareOptions || !entity) {
1491
+ return null;
1492
+ }
1493
+ return /* @__PURE__ */ jsx(
1494
+ DesktopSharePnLContent,
1495
+ {
1496
+ entity,
1497
+ hide,
1498
+ baseDp,
1499
+ quoteDp,
1500
+ referral: referralInfo,
1501
+ shareOptions
1502
+ }
1503
+ );
1504
+ };
1505
+ var MobileSharePnL = (props) => {
1506
+ const { entity, baseDp, quoteDp, referralInfo, shareOptions, hide } = props;
1507
+ if (!shareOptions || !entity) {
1508
+ return null;
1509
+ }
1510
+ return /* @__PURE__ */ jsx(
1511
+ MobileSharePnLContent,
1512
+ {
1513
+ entity,
1514
+ hide,
1515
+ baseDp,
1516
+ quoteDp,
1517
+ referral: referralInfo,
1518
+ shareOptions
1519
+ }
1520
+ );
1521
+ };
1522
+ var SharePnLBottomSheetWidget = (props) => {
1523
+ const state = useSharePnLScript({
1524
+ hide: props.hide,
1525
+ pnl: props.pnl
1526
+ });
1527
+ return /* @__PURE__ */ jsx(MobileSharePnL, { ...state });
1528
+ };
1529
+ var SharePnLDialogWidget = (props) => {
1530
+ const state = useSharePnLScript({
1531
+ hide: props.hide,
1532
+ pnl: props.pnl
1533
+ });
1534
+ return /* @__PURE__ */ jsx(DesktopSharePnL, { ...state });
1535
+ };
1536
+ var SharePnLDialogId = "sharePnLDialog";
1537
+ var SharePnLBottomSheetId = "sharePnLBottomSheet";
1538
+ registerSimpleDialog(SharePnLDialogId, SharePnLDialogWidget, {
1539
+ classNames: {
1540
+ content: "!oui-max-w-[624px] oui-p-0"
1541
+ }
1542
+ });
1543
+ registerSimpleSheet(SharePnLBottomSheetId, SharePnLBottomSheetWidget, {
1544
+ title: i18n.t("share.pnl.sharePnl"),
1545
+ classNames: {
1546
+ body: "oui-pb-4 oui-pt-0"
1547
+ }
1548
+ });
1549
+
1550
+ export { SharePnLBottomSheetId, SharePnLBottomSheetWidget, SharePnLDialogId, SharePnLDialogWidget, useSharePnLScript };
12
1551
  //# sourceMappingURL=out.js.map
13
1552
  //# sourceMappingURL=index.mjs.map