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