chaite
Version:
core for chatgpt-plugin and karin-plugin-chatgpt
133 lines (132 loc) • 24.3 kB
JavaScript
import{aP as re,bz as Re,s as E,bQ as V,p as n,d as K,a6 as ge,ax as H,a7 as R,ay as ue,ak as Te,aa as le,r as k,v as ie,x as U,ae as G,ad as q,ag as me,a1 as Ne,bR as _e,aN as we,bN as he,bD as He,aO as Be,a8 as M,F as oe,bS as De,bT as fe,bU as Ee,T as te,a$ as We,ab as Ve,aG as ne,bw as F,as as Ce,aW as Ze,G as Ae,bV as Xe,aA as Fe,b9 as Ye,aE as Ue,bW as Ge,bA as ve,bX as Ke,aV as qe}from"./index-ODYIy7Xh.js";import{d as Qe}from"./download-C2161hUv.js";function Je(e,t){const l=re(Re,null);return E(()=>e.hljs||l?.mergedHljsRef.value)}const eo=V("download",()=>n("svg",{viewBox:"0 0 16 16",version:"1.1",xmlns:"http://www.w3.org/2000/svg"},n("g",{stroke:"none","stroke-width":"1",fill:"none","fill-rule":"evenodd"},n("g",{fill:"currentColor","fill-rule":"nonzero"},n("path",{d:"M3.5,13 L12.5,13 C12.7761424,13 13,13.2238576 13,13.5 C13,13.7454599 12.8231248,13.9496084 12.5898756,13.9919443 L12.5,14 L3.5,14 C3.22385763,14 3,13.7761424 3,13.5 C3,13.2545401 3.17687516,13.0503916 3.41012437,13.0080557 L3.5,13 L12.5,13 L3.5,13 Z M7.91012437,1.00805567 L8,1 C8.24545989,1 8.44960837,1.17687516 8.49194433,1.41012437 L8.5,1.5 L8.5,10.292 L11.1819805,7.6109127 C11.3555469,7.43734635 11.6249713,7.4180612 11.8198394,7.55305725 L11.8890873,7.6109127 C12.0626536,7.78447906 12.0819388,8.05390346 11.9469427,8.2487716 L11.8890873,8.31801948 L8.35355339,11.8535534 C8.17998704,12.0271197 7.91056264,12.0464049 7.7156945,11.9114088 L7.64644661,11.8535534 L4.1109127,8.31801948 C3.91565056,8.12275734 3.91565056,7.80617485 4.1109127,7.6109127 C4.28447906,7.43734635 4.55390346,7.4180612 4.7487716,7.55305725 L4.81801948,7.6109127 L7.5,10.292 L7.5,1.5 C7.5,1.25454011 7.67687516,1.05039163 7.91012437,1.00805567 L8,1 L7.91012437,1.00805567 Z"}))))),oo=K({name:"ResizeSmall",render(){return n("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20"},n("g",{fill:"none"},n("path",{d:"M5.5 4A1.5 1.5 0 0 0 4 5.5v1a.5.5 0 0 1-1 0v-1A2.5 2.5 0 0 1 5.5 3h1a.5.5 0 0 1 0 1h-1zM16 5.5A1.5 1.5 0 0 0 14.5 4h-1a.5.5 0 0 1 0-1h1A2.5 2.5 0 0 1 17 5.5v1a.5.5 0 0 1-1 0v-1zm0 9a1.5 1.5 0 0 1-1.5 1.5h-1a.5.5 0 0 0 0 1h1a2.5 2.5 0 0 0 2.5-2.5v-1a.5.5 0 0 0-1 0v1zm-12 0A1.5 1.5 0 0 0 5.5 16h1.25a.5.5 0 0 1 0 1H5.5A2.5 2.5 0 0 1 3 14.5v-1.25a.5.5 0 0 1 1 0v1.25zM8.5 7A1.5 1.5 0 0 0 7 8.5v3A1.5 1.5 0 0 0 8.5 13h3a1.5 1.5 0 0 0 1.5-1.5v-3A1.5 1.5 0 0 0 11.5 7h-3zM8 8.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-3z",fill:"currentColor"})))}}),to=V("rotateClockwise",()=>n("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n("path",{d:"M3 10C3 6.13401 6.13401 3 10 3C13.866 3 17 6.13401 17 10C17 12.7916 15.3658 15.2026 13 16.3265V14.5C13 14.2239 12.7761 14 12.5 14C12.2239 14 12 14.2239 12 14.5V17.5C12 17.7761 12.2239 18 12.5 18H15.5C15.7761 18 16 17.7761 16 17.5C16 17.2239 15.7761 17 15.5 17H13.8758C16.3346 15.6357 18 13.0128 18 10C18 5.58172 14.4183 2 10 2C5.58172 2 2 5.58172 2 10C2 10.2761 2.22386 10.5 2.5 10.5C2.77614 10.5 3 10.2761 3 10Z",fill:"currentColor"}),n("path",{d:"M10 12C11.1046 12 12 11.1046 12 10C12 8.89543 11.1046 8 10 8C8.89543 8 8 8.89543 8 10C8 11.1046 8.89543 12 10 12ZM10 11C9.44772 11 9 10.5523 9 10C9 9.44772 9.44772 9 10 9C10.5523 9 11 9.44772 11 10C11 10.5523 10.5523 11 10 11Z",fill:"currentColor"}))),no=V("rotateClockwise",()=>n("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n("path",{d:"M17 10C17 6.13401 13.866 3 10 3C6.13401 3 3 6.13401 3 10C3 12.7916 4.63419 15.2026 7 16.3265V14.5C7 14.2239 7.22386 14 7.5 14C7.77614 14 8 14.2239 8 14.5V17.5C8 17.7761 7.77614 18 7.5 18H4.5C4.22386 18 4 17.7761 4 17.5C4 17.2239 4.22386 17 4.5 17H6.12422C3.66539 15.6357 2 13.0128 2 10C2 5.58172 5.58172 2 10 2C14.4183 2 18 5.58172 18 10C18 10.2761 17.7761 10.5 17.5 10.5C17.2239 10.5 17 10.2761 17 10Z",fill:"currentColor"}),n("path",{d:"M10 12C8.89543 12 8 11.1046 8 10C8 8.89543 8.89543 8 10 8C11.1046 8 12 8.89543 12 10C12 11.1046 11.1046 12 10 12ZM10 11C10.5523 11 11 10.5523 11 10C11 9.44772 10.5523 9 10 9C9.44772 9 9 9.44772 9 10C9 10.5523 9.44772 11 10 11Z",fill:"currentColor"}))),io=V("zoomIn",()=>n("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n("path",{d:"M11.5 8.5C11.5 8.22386 11.2761 8 11 8H9V6C9 5.72386 8.77614 5.5 8.5 5.5C8.22386 5.5 8 5.72386 8 6V8H6C5.72386 8 5.5 8.22386 5.5 8.5C5.5 8.77614 5.72386 9 6 9H8V11C8 11.2761 8.22386 11.5 8.5 11.5C8.77614 11.5 9 11.2761 9 11V9H11C11.2761 9 11.5 8.77614 11.5 8.5Z",fill:"currentColor"}),n("path",{d:"M8.5 3C11.5376 3 14 5.46243 14 8.5C14 9.83879 13.5217 11.0659 12.7266 12.0196L16.8536 16.1464C17.0488 16.3417 17.0488 16.6583 16.8536 16.8536C16.68 17.0271 16.4106 17.0464 16.2157 16.9114L16.1464 16.8536L12.0196 12.7266C11.0659 13.5217 9.83879 14 8.5 14C5.46243 14 3 11.5376 3 8.5C3 5.46243 5.46243 3 8.5 3ZM8.5 4C6.01472 4 4 6.01472 4 8.5C4 10.9853 6.01472 13 8.5 13C10.9853 13 13 10.9853 13 8.5C13 6.01472 10.9853 4 8.5 4Z",fill:"currentColor"}))),ro=V("zoomOut",()=>n("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n("path",{d:"M11 8C11.2761 8 11.5 8.22386 11.5 8.5C11.5 8.77614 11.2761 9 11 9H6C5.72386 9 5.5 8.77614 5.5 8.5C5.5 8.22386 5.72386 8 6 8H11Z",fill:"currentColor"}),n("path",{d:"M14 8.5C14 5.46243 11.5376 3 8.5 3C5.46243 3 3 5.46243 3 8.5C3 11.5376 5.46243 14 8.5 14C9.83879 14 11.0659 13.5217 12.0196 12.7266L16.1464 16.8536L16.2157 16.9114C16.4106 17.0464 16.68 17.0271 16.8536 16.8536C17.0488 16.6583 17.0488 16.3417 16.8536 16.1464L12.7266 12.0196C13.5217 11.0659 14 9.83879 14 8.5ZM4 8.5C4 6.01472 6.01472 4 8.5 4C10.9853 4 13 6.01472 13 8.5C13 10.9853 10.9853 13 8.5 13C6.01472 13 4 10.9853 4 8.5Z",fill:"currentColor"})));function lo(e){const{textColor2:t,fontSize:l,fontWeightStrong:u,textColor3:a}=e;return{textColor:t,fontSize:l,fontWeightStrong:u,"mono-3":"#a0a1a7","hue-1":"#0184bb","hue-2":"#4078f2","hue-3":"#a626a4","hue-4":"#50a14f","hue-5":"#e45649","hue-5-2":"#c91243","hue-6":"#986801","hue-6-2":"#c18401",lineNumberTextColor:a}}const so={common:ge,self:lo},ao=H([R("code",`
font-size: var(--n-font-size);
font-family: var(--n-font-family);
`,[ue("show-line-numbers",`
display: flex;
`),Te("line-numbers",`
user-select: none;
padding-right: 12px;
text-align: right;
transition: color .3s var(--n-bezier);
color: var(--n-line-number-text-color);
`),ue("word-wrap",[H("pre",`
white-space: pre-wrap;
word-break: break-all;
`)]),H("pre",`
margin: 0;
line-height: inherit;
font-size: inherit;
font-family: inherit;
`),H("[class^=hljs]",`
color: var(--n-text-color);
transition:
color .3s var(--n-bezier),
background-color .3s var(--n-bezier);
`)]),({props:e})=>{const t=`${e.bPrefix}code`;return[`${t} .hljs-comment,
${t} .hljs-quote {
color: var(--n-mono-3);
font-style: italic;
}`,`${t} .hljs-doctag,
${t} .hljs-keyword,
${t} .hljs-formula {
color: var(--n-hue-3);
}`,`${t} .hljs-section,
${t} .hljs-name,
${t} .hljs-selector-tag,
${t} .hljs-deletion,
${t} .hljs-subst {
color: var(--n-hue-5);
}`,`${t} .hljs-literal {
color: var(--n-hue-1);
}`,`${t} .hljs-string,
${t} .hljs-regexp,
${t} .hljs-addition,
${t} .hljs-attribute,
${t} .hljs-meta-string {
color: var(--n-hue-4);
}`,`${t} .hljs-built_in,
${t} .hljs-class .hljs-title {
color: var(--n-hue-6-2);
}`,`${t} .hljs-attr,
${t} .hljs-variable,
${t} .hljs-template-variable,
${t} .hljs-type,
${t} .hljs-selector-class,
${t} .hljs-selector-attr,
${t} .hljs-selector-pseudo,
${t} .hljs-number {
color: var(--n-hue-6);
}`,`${t} .hljs-symbol,
${t} .hljs-bullet,
${t} .hljs-link,
${t} .hljs-meta,
${t} .hljs-selector-id,
${t} .hljs-title {
color: var(--n-hue-2);
}`,`${t} .hljs-emphasis {
font-style: italic;
}`,`${t} .hljs-strong {
font-weight: var(--n-font-weight-strong);
}`,`${t} .hljs-link {
text-decoration: underline;
}`]}]),co=Object.assign(Object.assign({},q.props),{language:String,code:{type:String,default:""},trim:{type:Boolean,default:!0},hljs:Object,uri:Boolean,inline:Boolean,wordWrap:Boolean,showLineNumbers:Boolean,internalFontSize:Number,internalNoHighlight:Boolean}),So=K({name:"Code",props:co,setup(e,{slots:t}){const{internalNoHighlight:l}=e,{mergedClsPrefixRef:u,inlineThemeDisabled:a}=le(),w=k(null),b=l?{value:void 0}:Je(e),x=(d,h,m)=>{const{value:S}=b;return!S||!(d&&S.getLanguage(d))?null:S.highlight(m?h.trim():h,{language:d}).value},$=E(()=>e.inline||e.wordWrap?!1:e.showLineNumbers),s=()=>{if(t.default)return;const{value:d}=w;if(!d)return;const{language:h}=e,m=e.uri?window.decodeURIComponent(e.code):e.code;if(h){const j=x(h,m,e.trim);if(j!==null){if(e.inline)d.innerHTML=j;else{const _=d.querySelector(".__code__");_&&d.removeChild(_);const I=document.createElement("pre");I.className="__code__",I.innerHTML=j,d.appendChild(I)}return}}if(e.inline){d.textContent=m;return}const S=d.querySelector(".__code__");if(S)S.textContent=m;else{const j=document.createElement("pre");j.className="__code__",j.textContent=m,d.innerHTML="",d.appendChild(j)}};ie(s),U(G(e,"language"),s),U(G(e,"code"),s),l||U(b,s);const c=q("Code","-code",ao,so,e,u),g=E(()=>{const{common:{cubicBezierEaseInOut:d,fontFamilyMono:h},self:{textColor:m,fontSize:S,fontWeightStrong:j,lineNumberTextColor:_,"mono-3":I,"hue-1":Z,"hue-2":Q,"hue-3":A,"hue-4":X,"hue-5":C,"hue-5-2":J,"hue-6":W,"hue-6-2":T}}=c.value,{internalFontSize:p}=e;return{"--n-font-size":p?`${p}px`:S,"--n-font-family":h,"--n-font-weight-strong":j,"--n-bezier":d,"--n-text-color":m,"--n-mono-3":I,"--n-hue-1":Z,"--n-hue-2":Q,"--n-hue-3":A,"--n-hue-4":X,"--n-hue-5":C,"--n-hue-5-2":J,"--n-hue-6":W,"--n-hue-6-2":T,"--n-line-number-text-color":_}}),y=a?me("code",E(()=>`${e.internalFontSize||"a"}`),g,e):void 0;return{mergedClsPrefix:u,codeRef:w,mergedShowLineNumbers:$,lineNumbers:E(()=>{let d=1;const h=[];let m=!1;for(const S of e.code)S===`
`?(m=!0,h.push(d++)):m=!1;return m||h.push(d++),h.join(`
`)}),cssVars:a?void 0:g,themeClass:y?.themeClass,onRender:y?.onRender}},render(){var e,t;const{mergedClsPrefix:l,wordWrap:u,mergedShowLineNumbers:a,onRender:w}=this;return w?.(),n("code",{class:[`${l}-code`,this.themeClass,u&&`${l}-code--word-wrap`,a&&`${l}-code--show-line-numbers`],style:this.cssVars,ref:"codeRef"},a?n("pre",{class:`${l}-code__line-numbers`},this.lineNumbers):null,(t=(e=this.$slots).default)===null||t===void 0?void 0:t.call(e))}});function uo(){return{toolbarIconColor:"rgba(255, 255, 255, .9)",toolbarColor:"rgba(0, 0, 0, .35)",toolbarBoxShadow:"none",toolbarBorderRadius:"24px"}}const ho=Ne({name:"Image",common:ge,peers:{Tooltip:_e},self:uo});function fo(){return n("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n("path",{d:"M6 5C5.75454 5 5.55039 5.17688 5.50806 5.41012L5.5 5.5V14.5C5.5 14.7761 5.72386 15 6 15C6.24546 15 6.44961 14.8231 6.49194 14.5899L6.5 14.5V5.5C6.5 5.22386 6.27614 5 6 5ZM13.8536 5.14645C13.68 4.97288 13.4106 4.9536 13.2157 5.08859L13.1464 5.14645L8.64645 9.64645C8.47288 9.82001 8.4536 10.0894 8.58859 10.2843L8.64645 10.3536L13.1464 14.8536C13.3417 15.0488 13.6583 15.0488 13.8536 14.8536C14.0271 14.68 14.0464 14.4106 13.9114 14.2157L13.8536 14.1464L9.70711 10L13.8536 5.85355C14.0488 5.65829 14.0488 5.34171 13.8536 5.14645Z",fill:"currentColor"}))}function vo(){return n("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n("path",{d:"M13.5 5C13.7455 5 13.9496 5.17688 13.9919 5.41012L14 5.5V14.5C14 14.7761 13.7761 15 13.5 15C13.2545 15 13.0504 14.8231 13.0081 14.5899L13 14.5V5.5C13 5.22386 13.2239 5 13.5 5ZM5.64645 5.14645C5.82001 4.97288 6.08944 4.9536 6.28431 5.08859L6.35355 5.14645L10.8536 9.64645C11.0271 9.82001 11.0464 10.0894 10.9114 10.2843L10.8536 10.3536L6.35355 14.8536C6.15829 15.0488 5.84171 15.0488 5.64645 14.8536C5.47288 14.68 5.4536 14.4106 5.58859 14.2157L5.64645 14.1464L9.79289 10L5.64645 5.85355C5.45118 5.65829 5.45118 5.34171 5.64645 5.14645Z",fill:"currentColor"}))}function go(){return n("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n("path",{d:"M4.089 4.216l.057-.07a.5.5 0 0 1 .638-.057l.07.057L10 9.293l5.146-5.147a.5.5 0 0 1 .638-.057l.07.057a.5.5 0 0 1 .057.638l-.057.07L10.707 10l5.147 5.146a.5.5 0 0 1 .057.638l-.057.07a.5.5 0 0 1-.638.057l-.07-.057L10 10.707l-5.146 5.147a.5.5 0 0 1-.638.057l-.07-.057a.5.5 0 0 1-.057-.638l.057-.07L9.293 10L4.146 4.854a.5.5 0 0 1-.057-.638l.057-.07l-.057.07z",fill:"currentColor"}))}const pe=Object.assign(Object.assign({},q.props),{onPreviewPrev:Function,onPreviewNext:Function,showToolbar:{type:Boolean,default:!0},showToolbarTooltip:Boolean,renderToolbar:Function}),be=we("n-image"),mo=H([H("body >",[R("image-container","position: fixed;")]),R("image-preview-container",`
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
`),R("image-preview-overlay",`
z-index: -1;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: rgba(0, 0, 0, .3);
`,[he()]),R("image-preview-toolbar",`
z-index: 1;
position: absolute;
left: 50%;
transform: translateX(-50%);
border-radius: var(--n-toolbar-border-radius);
height: 48px;
bottom: 40px;
padding: 0 12px;
background: var(--n-toolbar-color);
box-shadow: var(--n-toolbar-box-shadow);
color: var(--n-toolbar-icon-color);
transition: color .3s var(--n-bezier);
display: flex;
align-items: center;
`,[R("base-icon",`
padding: 0 8px;
font-size: 28px;
cursor: pointer;
`),he()]),R("image-preview-wrapper",`
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
pointer-events: none;
`,[He()]),R("image-preview",`
user-select: none;
-webkit-user-select: none;
pointer-events: all;
margin: auto;
max-height: calc(100vh - 32px);
max-width: calc(100vw - 32px);
transition: transform .3s var(--n-bezier);
`),R("image",`
display: inline-flex;
max-height: 100%;
max-width: 100%;
`,[Be("preview-disabled",`
cursor: pointer;
`),H("img",`
border-radius: inherit;
`)])]),Y=32,wo=K({name:"ImagePreview",props:Object.assign(Object.assign({},pe),{onNext:Function,onPrev:Function,clsPrefix:{type:String,required:!0}}),setup(e){const t=q("Image","-image",mo,ho,e,G(e,"clsPrefix"));let l=null;const u=k(null),a=k(null),w=k(void 0),b=k(!1),x=k(!1),{localeRef:$}=Ve("Image");function s(){const{value:o}=a;if(!l||!o)return;const{style:r}=o,i=l.getBoundingClientRect(),f=i.left+i.width/2,v=i.top+i.height/2;r.transformOrigin=`${f}px ${v}px`}function c(o){var r,i;switch(o.key){case" ":o.preventDefault();break;case"ArrowLeft":(r=e.onPrev)===null||r===void 0||r.call(e);break;case"ArrowRight":(i=e.onNext)===null||i===void 0||i.call(e);break;case"Escape":ae();break}}U(b,o=>{o?ne("keydown",document,c):F("keydown",document,c)}),Ce(()=>{F("keydown",document,c)});let g=0,y=0,d=0,h=0,m=0,S=0,j=0,_=0,I=!1;function Z(o){const{clientX:r,clientY:i}=o;d=r-g,h=i-y,Ye(z)}function Q(o){const{mouseUpClientX:r,mouseUpClientY:i,mouseDownClientX:f,mouseDownClientY:v}=o,L=f-r,P=v-i,O=`vertical${P>0?"Top":"Bottom"}`,N=`horizontal${L>0?"Left":"Right"}`;return{moveVerticalDirection:O,moveHorizontalDirection:N,deltaHorizontal:L,deltaVertical:P}}function A(o){const{value:r}=u;if(!r)return{offsetX:0,offsetY:0};const i=r.getBoundingClientRect(),{moveVerticalDirection:f,moveHorizontalDirection:v,deltaHorizontal:L,deltaVertical:P}=o||{};let O=0,N=0;return i.width<=window.innerWidth?O=0:i.left>0?O=(i.width-window.innerWidth)/2:i.right<window.innerWidth?O=-(i.width-window.innerWidth)/2:v==="horizontalRight"?O=Math.min((i.width-window.innerWidth)/2,m-(L??0)):O=Math.max(-((i.width-window.innerWidth)/2),m-(L??0)),i.height<=window.innerHeight?N=0:i.top>0?N=(i.height-window.innerHeight)/2:i.bottom<window.innerHeight?N=-(i.height-window.innerHeight)/2:f==="verticalBottom"?N=Math.min((i.height-window.innerHeight)/2,S-(P??0)):N=Math.max(-((i.height-window.innerHeight)/2),S-(P??0)),{offsetX:O,offsetY:N}}function X(o){F("mousemove",document,Z),F("mouseup",document,X);const{clientX:r,clientY:i}=o;I=!1;const f=Q({mouseUpClientX:r,mouseUpClientY:i,mouseDownClientX:j,mouseDownClientY:_}),v=A(f);d=v.offsetX,h=v.offsetY,z()}const C=re(be,null);function J(o){var r,i;if((i=(r=C?.previewedImgPropsRef.value)===null||r===void 0?void 0:r.onMousedown)===null||i===void 0||i.call(r,o),o.button!==0)return;const{clientX:f,clientY:v}=o;I=!0,g=f-d,y=v-h,m=d,S=h,j=f,_=v,z(),ne("mousemove",document,Z),ne("mouseup",document,X)}const W=1.5;let T=0,p=1,B=0;function xe(o){var r,i;(i=(r=C?.previewedImgPropsRef.value)===null||r===void 0?void 0:r.onDblclick)===null||i===void 0||i.call(r,o);const f=se();p=p===f?1:f,z()}function ee(){p=1,T=0}function Se(){var o;ee(),B=0,(o=e.onPrev)===null||o===void 0||o.call(e)}function Le(){var o;ee(),B=0,(o=e.onNext)===null||o===void 0||o.call(e)}function $e(){B-=90,z()}function ye(){B+=90,z()}function je(){const{value:o}=u;if(!o)return 1;const{innerWidth:r,innerHeight:i}=window,f=Math.max(1,o.naturalHeight/(i-Y)),v=Math.max(1,o.naturalWidth/(r-Y));return Math.max(3,f*2,v*2)}function se(){const{value:o}=u;if(!o)return 1;const{innerWidth:r,innerHeight:i}=window,f=o.naturalHeight/(i-Y),v=o.naturalWidth/(r-Y);return f<1&&v<1?1:Math.max(f,v)}function Pe(){const o=je();p<o&&(T+=1,p=Math.min(o,Math.pow(W,T)),z())}function ze(){if(p>.5){const o=p;T-=1,p=Math.max(.5,Math.pow(W,T));const r=o-p;z(!1);const i=A();p+=r,z(!1),p-=r,d=i.offsetX,h=i.offsetY,z()}}function Oe(){const o=w.value;o&&Qe(o,void 0)}function z(o=!0){var r;const{value:i}=u;if(!i)return;const{style:f}=i,v=Ae((r=C?.previewedImgPropsRef.value)===null||r===void 0?void 0:r.style);let L="";if(typeof v=="string")L=`${v};`;else for(const O in v)L+=`${Xe(O)}: ${v[O]};`;const P=`transform-origin: center; transform: translateX(${d}px) translateY(${h}px) rotate(${B}deg) scale(${p});`;I?f.cssText=`${L}cursor: grabbing; transition: none;${P}`:f.cssText=`${L}cursor: grab;${P}${o?"":"transition: none;"}`,o||i.offsetHeight}function ae(){b.value=!b.value,x.value=!0}function ke(){p=se(),T=Math.ceil(Math.log(p)/Math.log(W)),d=0,h=0,z()}const Ie={setPreviewSrc:o=>{w.value=o},setThumbnailEl:o=>{l=o},toggleShow:ae};function Me(o,r){if(e.showToolbarTooltip){const{value:i}=t;return n(Fe,{to:!1,theme:i.peers.Tooltip,themeOverrides:i.peerOverrides.Tooltip,keepAliveOnHover:!1},{default:()=>$.value[r],trigger:()=>o})}else return o}const ce=E(()=>{const{common:{cubicBezierEaseInOut:o},self:{toolbarIconColor:r,toolbarBorderRadius:i,toolbarBoxShadow:f,toolbarColor:v}}=t.value;return{"--n-bezier":o,"--n-toolbar-icon-color":r,"--n-toolbar-color":v,"--n-toolbar-border-radius":i,"--n-toolbar-box-shadow":f}}),{inlineThemeDisabled:de}=le(),D=de?me("image-preview",void 0,ce,e):void 0;return Object.assign({previewRef:u,previewWrapperRef:a,previewSrc:w,show:b,appear:Ze(),displayed:x,previewedImgProps:C?.previewedImgPropsRef,handleWheel(o){o.preventDefault()},handlePreviewMousedown:J,handlePreviewDblclick:xe,syncTransformOrigin:s,handleAfterLeave:()=>{ee(),B=0,x.value=!1},handleDragStart:o=>{var r,i;(i=(r=C?.previewedImgPropsRef.value)===null||r===void 0?void 0:r.onDragstart)===null||i===void 0||i.call(r,o),o.preventDefault()},zoomIn:Pe,zoomOut:ze,handleDownloadClick:Oe,rotateCounterclockwise:$e,rotateClockwise:ye,handleSwitchPrev:Se,handleSwitchNext:Le,withTooltip:Me,resizeToOrignalImageSize:ke,cssVars:de?void 0:ce,themeClass:D?.themeClass,onRender:D?.onRender},Ie)},render(){var e,t;const{clsPrefix:l,renderToolbar:u,withTooltip:a}=this,w=a(n(M,{clsPrefix:l,onClick:this.handleSwitchPrev},{default:fo}),"tipPrevious"),b=a(n(M,{clsPrefix:l,onClick:this.handleSwitchNext},{default:vo}),"tipNext"),x=a(n(M,{clsPrefix:l,onClick:this.rotateCounterclockwise},{default:()=>n(no,null)}),"tipCounterclockwise"),$=a(n(M,{clsPrefix:l,onClick:this.rotateClockwise},{default:()=>n(to,null)}),"tipClockwise"),s=a(n(M,{clsPrefix:l,onClick:this.resizeToOrignalImageSize},{default:()=>n(oo,null)}),"tipOriginalSize"),c=a(n(M,{clsPrefix:l,onClick:this.zoomOut},{default:()=>n(ro,null)}),"tipZoomOut"),g=a(n(M,{clsPrefix:l,onClick:this.handleDownloadClick},{default:()=>n(eo,null)}),"tipDownload"),y=a(n(M,{clsPrefix:l,onClick:this.toggleShow},{default:go}),"tipClose"),d=a(n(M,{clsPrefix:l,onClick:this.zoomIn},{default:()=>n(io,null)}),"tipZoomIn");return n(oe,null,(t=(e=this.$slots).default)===null||t===void 0?void 0:t.call(e),n(De,{show:this.show},{default:()=>{var h;return this.show||this.displayed?((h=this.onRender)===null||h===void 0||h.call(this),fe(n("div",{class:[`${l}-image-preview-container`,this.themeClass],style:this.cssVars,onWheel:this.handleWheel},n(te,{name:"fade-in-transition",appear:this.appear},{default:()=>this.show?n("div",{class:`${l}-image-preview-overlay`,onClick:this.toggleShow}):null}),this.showToolbar?n(te,{name:"fade-in-transition",appear:this.appear},{default:()=>this.show?n("div",{class:`${l}-image-preview-toolbar`},u?u({nodes:{prev:w,next:b,rotateCounterclockwise:x,rotateClockwise:$,resizeToOriginalSize:s,zoomOut:c,zoomIn:d,download:g,close:y}}):n(oe,null,this.onPrev?n(oe,null,w,b):null,x,$,s,c,d,g,y)):null}):null,n(te,{name:"fade-in-scale-up-transition",onAfterLeave:this.handleAfterLeave,appear:this.appear,onEnter:this.syncTransformOrigin,onBeforeLeave:this.syncTransformOrigin},{default:()=>{const{previewedImgProps:m={}}=this;return fe(n("div",{class:`${l}-image-preview-wrapper`,ref:"previewWrapperRef"},n("img",Object.assign({},m,{draggable:!1,onMousedown:this.handlePreviewMousedown,onDblclick:this.handlePreviewDblclick,class:[`${l}-image-preview`,m.class],key:this.previewSrc,src:this.previewSrc,ref:"previewRef",onDragstart:this.handleDragStart}))),[[We,this.show]])}})),[[Ee,{enabled:this.show}]])):null}}))}}),Co=we("n-image-group"),po=Object.assign({alt:String,height:[String,Number],imgProps:Object,previewedImgProps:Object,lazy:Boolean,intersectionObserverOptions:Object,objectFit:{type:String,default:"fill"},previewSrc:String,fallbackSrc:String,width:[String,Number],src:String,previewDisabled:Boolean,loadDescription:String,onError:Function,onLoad:Function},pe),Lo=K({name:"Image",props:po,slots:Object,inheritAttrs:!1,setup(e){const t=k(null),l=k(!1),u=k(null),a=re(Co,null),{mergedClsPrefixRef:w}=a||le(e),b={click:()=>{if(e.previewDisabled||l.value)return;const s=e.previewSrc||e.src;if(a){a.setPreviewSrc(s),a.setThumbnailEl(t.value),a.toggleShow();return}const{value:c}=u;c&&(c.setPreviewSrc(s),c.setThumbnailEl(t.value),c.toggleShow())}},x=k(!e.lazy);ie(()=>{var s;(s=t.value)===null||s===void 0||s.setAttribute("data-group-id",a?.groupId||"")}),ie(()=>{if(e.lazy&&e.intersectionObserverOptions){let s;const c=ve(()=>{s?.(),s=void 0,s=Ke(t.value,e.intersectionObserverOptions,x)});Ce(()=>{c(),s?.()})}}),ve(()=>{var s;e.src||((s=e.imgProps)===null||s===void 0||s.src),l.value=!1});const $=k(!1);return qe(be,{previewedImgPropsRef:G(e,"previewedImgProps")}),Object.assign({mergedClsPrefix:w,groupId:a?.groupId,previewInstRef:u,imageRef:t,showError:l,shouldStartLoading:x,loaded:$,mergedOnClick:s=>{var c,g;b.click(),(g=(c=e.imgProps)===null||c===void 0?void 0:c.onClick)===null||g===void 0||g.call(c,s)},mergedOnError:s=>{if(!x.value)return;l.value=!0;const{onError:c,imgProps:{onError:g}={}}=e;c?.(s),g?.(s)},mergedOnLoad:s=>{const{onLoad:c,imgProps:{onLoad:g}={}}=e;c?.(s),g?.(s),$.value=!0}},b)},render(){var e,t;const{mergedClsPrefix:l,imgProps:u={},loaded:a,$attrs:w,lazy:b}=this,x=Ue(this.$slots.error,()=>[]),$=(t=(e=this.$slots).placeholder)===null||t===void 0?void 0:t.call(e),s=this.src||u.src,c=this.showError&&x.length?x:n("img",Object.assign(Object.assign({},u),{ref:"imageRef",width:this.width||u.width,height:this.height||u.height,src:this.showError?this.fallbackSrc:b&&this.intersectionObserverOptions?this.shouldStartLoading?s:void 0:s,alt:this.alt||u.alt,"aria-label":this.alt||u.alt,onClick:this.mergedOnClick,onError:this.mergedOnError,onLoad:this.mergedOnLoad,loading:Ge&&b&&!this.intersectionObserverOptions?"lazy":"eager",style:[u.style||"",$&&!a?{height:"0",width:"0",visibility:"hidden"}:"",{objectFit:this.objectFit}],"data-error":this.showError,"data-preview-src":this.previewSrc||this.src}));return n("div",Object.assign({},w,{role:"none",class:[w.class,`${l}-image`,(this.previewDisabled||this.showError)&&`${l}-image--preview-disabled`]}),this.groupId?c:n(wo,{theme:this.theme,themeOverrides:this.themeOverrides,clsPrefix:l,ref:"previewInstRef",showToolbar:this.showToolbar,showToolbarTooltip:this.showToolbarTooltip,renderToolbar:this.renderToolbar},{default:()=>c}),!a&&$)}});export{Lo as N,So as a};