@farris/ui-vue
Version:
Farris Vue, a Farris Design based Vue3 component library.
2 lines (1 loc) • 29.6 kB
JavaScript
(function(O,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(O=typeof globalThis<"u"?globalThis:O||self,e(O["message-box"]={},O.Vue))})(this,function(O,e){"use strict";var Ye=Object.defineProperty;var Ue=(O,e,W)=>e in O?Ye(O,e,{enumerable:!0,configurable:!0,writable:!0,value:W}):O[e]=W;var X=(O,e,W)=>Ue(O,typeof e!="symbol"?e+"":e,W);const W={width:{Type:Number,default:400},type:{Type:String,default:"info"},title:{Type:String,default:""},detail:{Type:String,default:""},okButtonText:{Type:String,default:"确定"},cancelButtonText:{Type:String,default:"取消"},exceptionInfo:{Type:Object,default:null},promptEditorType:{Type:String,default:"text-area"},buttons:{type:Object,default:[]}};function _(){return new DOMException("The request is not allowed","NotAllowedError")}async function re(t){if(!navigator.clipboard)throw _();return navigator.clipboard.writeText(t)}async function ie(t){const a=document.createElement("span");a.textContent=t,a.style.whiteSpace="pre",a.style.webkitUserSelect="auto",a.style.userSelect="all",document.body.appendChild(a);const n=window.getSelection(),l=window.document.createRange();n==null||n.removeAllRanges(),l.selectNode(a),n==null||n.addRange(l);let s=!1;try{s=window.document.execCommand("copy")}finally{n==null||n.removeAllRanges(),window.document.body.removeChild(a)}if(!s)throw _()}async function ce(t){try{await re(t)}catch(a){try{await ie(t)}catch(n){throw n||a||_()}}}function ue(){async function t(a){await ce(a)}return{onCopy:t}}function de(t,a,n,l){const s=e.ref(14),u=e.ref(140),d=e.ref(""),r=e.ref(l.value.length),c=e.computed(()=>l.value),m=e.computed(()=>({"font-size":`${s.value}px`,height:"100%"}));function g(v){if(v.currentTarget){const M=v.currentTarget.value||"";r.value=M.length}}return()=>e.createVNode(e.Fragment,null,[e.createVNode("textarea",{title:"promptMessage",name:"promptMessage",class:"form-control",style:m.value,rows:"4",maxlength:u.value,onInput:v=>g(v)},[c.value]),e.createVNode("span",{class:"textarea-wordcount",title:d.value,style:"position: absolute; bottom: 76px; right: 32px; cursor: pointer; text-align: right;"},[r.value+" / "+u.value])])}function fe(t,a,n,l){const s=de(t,a,n,l),u=new Map([["text-area",s]]);function d(r){return u.get(r)||null}return{getEditorRender:d}}function he(){const t=e.ref(!1),a=e.ref("复制成功");return{feedbackStyle:e.computed(()=>{const l={position:"absolute",left:"50%",top:"50%",width:"100px",height:"40px",background:"#303C53","line-height":"40px","text-align":"center","margin-left":"-30px","margin-top":"-50px","border-radius":"10px","box-shadow":"0px 2px 8px 0px",color:"#fff",transition:"all .3s ease"};return l.opacity=t.value?"0.8":"0",l.display=t.value?"":"none",l}),feedbackMessage:a,toShowFeedback:t}}function me(t,a){const n=a.getEditorRender(t.promptEditorType);return()=>n&&n()}function ve(t){const a=e.computed(()=>!!t.value&&!!t.value.date),n=e.computed(()=>`发生时间 : ${t.value&&t.value.date||""}`),l=e.computed(()=>!!t.value&&!!t.value.detail),s=e.computed(()=>"详细信息 : "+(t.value&&t.value.detail||"")),u="exp_switch_"+new Date().getTime();return()=>e.createVNode("div",{class:"toast-msg-detail"},[a.value&&e.createVNode("div",null,[n.value]),l.value&&e.createVNode("div",{class:"exception_wrap"},[e.createVNode("input",{type:"checkbox",id:u,class:"d-none exp_switch"},null),e.createVNode("div",{class:"exception_error_msg"},[e.createVNode("label",{class:"swith",htmlFor:u},null),e.createVNode("div",{innerHTML:s.value},null)])])])}function ge(t){return()=>e.createVNode("p",{class:"toast-msg-detail",innerHTML:t.value},null)}function pe(t,a,n,l){const s=e.ref(t.exceptionInfo),u=e.computed(()=>{const M={"f-icon":!0},N=`f-icon-${a.value}`;return M[N]=!0,M}),d=e.computed(()=>n.value||s.value&&s.value.message),r=e.computed(()=>l.value),c=e.computed(()=>!!l.value),m=e.computed(()=>!!s.value);function g(){return m.value?ve(s):c.value?ge(r):()=>null}const v=g();return()=>e.createVNode(e.Fragment,null,[e.createVNode("div",{class:"float-left modal-tips-iconwrap"},[e.createVNode("span",{class:u.value},null)]),e.createVNode("div",{class:"modal-tips-content"},[e.createVNode("p",{class:"toast-msg-title",innerHTML:d.value},null),v()])])}function ye(t,a,n){const{onCopy:l}=a,{toShowFeedback:s}=n,u=e.ref("复制成功"),d=e.ref("复制详细信息"),r=e.ref(t.exceptionInfo||{date:"",message:"",detail:""}),c=e.computed(()=>r.value&&r.value.detail||"");function m(g){l(c.value).catch(v=>{u.value="复制失败"}).finally(()=>{s.value=!0,setTimeout(()=>{s.value=!1},700)})}return()=>e.createVNode("span",{style:"width: 100%;color: #2A87FF;padding-left: 37px;"},[e.createVNode("span",{onClick:m,style:"cursor: pointer;"},[d.value])])}function we(t,a,n,l){const s=e.ref(t.type),u=e.ref(t.buttons),d=e.ref(t.exceptionInfo),r=e.ref(t.okButtonText),c=e.ref(t.cancelButtonText),m=e.ref(!0),g=e.ref(!0),v=e.computed(()=>!!(u.value&&u.value.length)),M=e.computed(()=>d.value&&d.value.date&&d.value.message&&d.value.detail),N=e.computed(()=>!(u.value&&u.value.length)&&(r.value||c.value)),E=e.computed(()=>g.value&&r.value),I=e.computed(()=>m.value&&c.value),T=ye(t,n,l);function S(C){s.value==="question"&&a.emit("reject"),a.emit("close")}function V(C){s.value==="question"&&a.emit("accept"),a.emit("close")}return()=>e.createVNode("div",{class:"modal-footer"},[M.value&&T(),N.value&&I.value&&e.createVNode("button",{type:"button",class:"btn btn-secondary btn-lg",onClick:S},[c.value]),N.value&&E.value&&e.createVNode("button",{type:"button",class:"btn btn-primary btn-lg",onClick:V},[r.value]),v.value&&u.value.length&&u.value.map(C=>e.createVNode("button",{type:"button",onClick:C.handle,class:C.class},[C.iconClass&&e.createVNode("span",{class:C.iconClass},null),C.text]))])}const Y=e.defineComponent({name:"FMessageBox",props:W,emits:["accept","reject","close"],setup(t,a){const n=e.ref(t.type),l=e.ref(t.title),s=e.ref(t.detail),u=e.computed(()=>{const T={"modal-tips":!0,"d-flex":!0,"flex-row":!0},S=`messager-type-${n.value}`;return T[S]=!0,T}),d=e.computed(()=>{const T={};return n.value==="prompt"?T.padding="0.5rem 0.5rem 1rem 1.5rem":n.value==="error"&&(T.padding="0.5rem 1.5rem 1rem 1.5rem"),T}),r=ue(),c=fe(t,n,l,s),m=he(),{feedbackStyle:g,feedbackMessage:v}=m;function M(){return e.createVNode("div",{style:g.value},[v.value])}function N(){switch(n.value){case"prompt":return me(t,c);default:return pe(t,n,l,s)}}const E=N(),I=we(t,a,r,m);return()=>e.createVNode("div",{class:"farris-messager"},[e.createVNode("section",{class:u.value,style:d.value},[E()]),I(),M()])}}),be={allowClickMaskToClose:{type:Boolean,default:!1},beforeClose:{type:Function,default:()=>!0},class:{type:String,default:""},maskClass:{type:String,default:""},title:{type:String,default:""},width:{type:Number,default:500},height:{type:Number,default:320},buttons:{type:Array,default:[]},modelValue:{type:Boolean,default:!1},mask:{type:Boolean,default:!0},showHeader:{type:Boolean,default:!0},showButtons:{type:Boolean,default:!0},fitContent:{type:Boolean,default:!0},showCloseButton:{type:Boolean,default:!0},showMaxButton:{type:Boolean,default:!1},minHeight:{type:Number},maxHeight:{type:Number},minWidth:{type:Number},maxWidth:{type:Number},containment:{type:Object,default:null},resizeable:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},dragHandle:{type:Object,default:null},closedCallback:{type:Function,default:null},resizeHandle:{type:Function,default:null},render:{type:Function,default:null},acceptCallback:{type:Function,default:null},rejectCallback:{type:Function,default:null},enableEsc:{type:Boolean,default:!0},enableEnter:{type:Boolean,default:!1},dialogType:{type:String,default:""},src:{type:String,default:""},footerHeight:{type:Number,default:60}};class B{constructor(a,n){this.x=a,this.y=n}static getTransformInfo(a){const l=window.getComputedStyle(a).getPropertyValue("transform").replace(/[^-\d,]/g,"").split(",");if(l.length>=6){const s=parseInt(l[4],10),u=parseInt(l[5],10);return{x:s,y:u}}return{x:0,y:0}}static fromEvent(a,n=null){if(this.isMouseEvent(a))return new B(a.clientX,a.clientY);if(n===null||a.changedTouches.length===1)return new B(a.changedTouches[0].clientX,a.changedTouches[0].clientY);for(let l=0;l<a.changedTouches.length;l++)if(a.changedTouches[l].target===n)return new B(a.changedTouches[l].clientX,a.changedTouches[l].clientY)}static isMouseEvent(a){return Object.prototype.toString.apply(a).indexOf("MouseEvent")===8}static isIPosition(a){return!!a&&"x"in a&&"y"in a}static getCurrent(a){const n=new B(0,0);if(window){const l=window.getComputedStyle(a);if(l){const s=parseInt(l.getPropertyValue("left"),10),u=parseInt(l.getPropertyValue("top"),10);n.x=isNaN(s)?0:s,n.y=isNaN(u)?0:u}return n}return null}static copy(a){return new B(0,0).set(a)}get value(){return{x:this.x,y:this.y}}add(a){return this.x+=a.x,this.y+=a.y,this}subtract(a){return this.x-=a.x,this.y-=a.y,this}multiply(a){this.x*=a,this.y*=a}divide(a){this.x/=a,this.y/=a}reset(){return this.x=0,this.y=0,this}set(a){return this.x=a.x,this.y=a.y,this}}class A{constructor(a,n){this.width=a,this.height=n}static getCurrent(a){const n=new A(0,0);if(window){const l=window.getComputedStyle(a);return l&&(n.width=parseInt(l.getPropertyValue("width"),10),n.height=parseInt(l.getPropertyValue("height"),10)),n}return null}static copy(a){return new A(0,0).set(a)}set(a){return this.width=a.width,this.height=a.height,this}}function xe(t,a){const n=e.ref(),l=e.ref(),s=e.ref(),u=e.ref(),d=e.ref(),r=e.ref(),c=e.ref(),m=e.ref(),g=e.ref(),v=e.ref(),M=e.ref(),N=e.ref(t.resizeable),E=e.ref(),I=e.ref(t.draggable),T=e.ref(!1);function S(){const i=l.value||document.body,f=window.getComputedStyle(i);if(!f||!n.value)return;const x=B.getTransformInfo(n.value),p={};c.value&&(p.deltaL=n.value.offsetLeft-c.value.x,p.deltaT=n.value.offsetTop-c.value.y);const H=f.getPropertyValue("position");p.width=i.clientWidth,p.height=i.clientHeight,p.pr=parseInt(f.getPropertyValue("padding-right"),10),p.pb=parseInt(f.getPropertyValue("padding-bottom"),10),p.position=f.getPropertyValue("position"),H==="static"&&(i.style.position="relative"),p.translateX=x.x,p.translateY=x.y,v.value=p}function V(i){if(n.value){u.value=A.getCurrent(n.value),d.value=B.getCurrent(n.value),r.value=u.value?A.copy(u.value):null,c.value=d.value?B.copy(d.value):null,S();const f=i.target.getAttribute("type")||"";m.value={n:!!f.match(/n/),s:!!f.match(/s/),w:!!f.match(/w/),e:!!f.match(/e/)}}}function C(){var i,f,x,p;if(n.value){const H=n.value;m.value&&((m.value.n||m.value.s)&&((i=r.value)!=null&&i.height)&&(H.style.height=r.value.height+"px"),(m.value.w||m.value.e)&&((f=r.value)!=null&&f.width)&&(H.style.width=r.value.width+"px"),c.value&&((x=c.value)!=null&&x.x&&(H.style.left=c.value.x+"px"),(p=c.value)!=null&&p.y&&(H.style.top=c.value.y+"px")))}}function D(){const i=t.minHeight?t.minHeight:1,f=t.minWidth?t.minWidth:1;r.value&&c.value&&m.value&&u.value&&(r.value.height<i&&(r.value.height=i,m.value.n&&d.value&&(c.value.y=d.value.y+(u.value.height-i))),r.value.width<f&&(r.value.width=f,m.value.w&&d.value&&(c.value.x=d.value.x+(u.value.width-f))),t.maxHeight&&r.value.height>t.maxHeight&&(r.value.height=t.maxHeight,d.value&&m.value.n&&(c.value.y=d.value.y+(u.value.height-t.maxHeight))),t.maxWidth&&r.value.width>t.maxWidth&&(r.value.width=t.maxWidth,m.value.w&&d.value&&(c.value.x=d.value.x+(u.value.width-t.maxWidth))))}function b(){if(l.value){const i=v.value;if(c.value&&r.value&&m.value&&u.value){const f=i.width-i.pr-i.deltaL-i.translateX-c.value.x,x=i.height-i.pb-i.deltaT-i.translateY-c.value.y;m.value.n&&c.value.y+i.translateY<0&&d.value&&(c.value.y=-i.translateY,r.value.height=u.value.height+d.value.y+i.translateY),m.value.w&&c.value.x+i.translateX<0&&d.value&&(c.value.x=-i.translateX,r.value.width=u.value.width+d.value.x+i.translateX),r.value.width>f&&(r.value.width=f),r.value.height>x&&(r.value.height=x)}}}function z(i){if(!s.value||!u.value||!d.value||!m.value)return;i.subtract(s.value);const f=i.x,x=i.y;m.value.n?(c.value.y=d.value.y+x,r.value.height=u.value.height-x):m.value.s&&(r.value.height=u.value.height+x),m.value.e?r.value.width=u.value.width+f:m.value.w&&(r.value.width=u.value.width-f,c.value.x=d.value.x+f),b(),D(),C()}function h(i){if(!g.value)return;const f=B.fromEvent(i);f&&z(f)}function w(){if(n.value){const{width:i,height:f,x,y:p}=n.value.getBoundingClientRect(),H=B.getTransformInfo(n.value);return{size:{width:i,height:f},position:{x:x-H.x,y:p-H.y}}}return null}function R(i){if(n.value){const f=w();M.value=f}s.value=void 0,u.value=null,d.value=null,r.value=null,c.value=null,m.value=null,g.value=null,document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",R)}function F(){document.addEventListener("mousemove",h),document.addEventListener("mouseup",R)}function k(i){i instanceof MouseEvent&&i.button===2||I.value&&(document.body.click(),i.stopPropagation(),i.preventDefault(),s.value=B.fromEvent(i),g.value=i.target,V(i),F())}function P(i){return n.value=i,N.value&&e.createVNode(e.Fragment,null,[e.createVNode("div",{class:"fv-resizable-handle fv-resizable-n",type:"n",onMousedown:f=>k(f)},null),e.createVNode("div",{class:"fv-resizable-handle fv-resizable-e",type:"e",onMousedown:f=>k(f)},null),e.createVNode("div",{class:"fv-resizable-handle fv-resizable-s",type:"s",onMousedown:f=>k(f)},null),e.createVNode("div",{class:"fv-resizable-handle fv-resizable-w",type:"w",onMousedown:f=>k(f)},null),e.createVNode("div",{class:"fv-resizable-handle fv-resizable-ne",type:"ne",onMousedown:f=>k(f)},null),e.createVNode("div",{class:"fv-resizable-handle fv-resizable-se fv-resizable-diagonal",type:"se",onMousedown:f=>k(f)},null),e.createVNode("div",{class:"fv-resizable-handle fv-resizable-sw",type:"sw",onMousedown:f=>k(f)},null),e.createVNode("div",{class:"fv-resizable-handle fv-resizable-nw",type:"nw",onMousedown:f=>k(f)},null)])}function K(i=!0){document.body.click();const f=l.value||document.body,x=A.getCurrent(f),p=n.value;i&&p&&(E.value=w(),E.value.transform=p.style.transform),x&&p&&(r.value=x,r.value.height-=14,r.value.width-=14,p.style.height=r.value.height+"px",p.style.width=r.value.width+"px",p.style.left="7px",p.style.top="7px",p.style.transform="",M.value={size:r.value,position:{x:0,y:0}},I.value=!1,T.value=!0)}function J(){var i,f;if(document.body.click(),E.value){const x={width:E.value.size.width||0,height:E.value.size.height||0},p={x:(window.innerWidth-x.width)/2,y:(window.innerHeight-x.height)/2};(i=r.value)==null||i.set(x),(f=c.value)==null||f.set(p);const H=n.value;H.style.height=x.height+"px",H.style.width=x.width+"px",H.style.left=`${p.x}px`,H.style.top=`${p.y}px`,H.style.transform="",M.value={size:x,position:p},I.value=t.draggable,T.value=!1}}function G(){if(n.value){const i=A.getCurrent(n.value);if(i){const{width:f,height:x}=i;n.value.style.left=`${(window.innerWidth-f)/2}px`,n.value.style.top=`${(window.innerHeight-x)/2}px`,n.value.style.transform=""}}}function U(){const i=()=>{T.value?K(!1):G(),document.body.click()};return window.addEventListener("resize",i),()=>{window.removeEventListener("resize",i)}}const Q=U();return{renderResizeBar:P,boundingElement:l,resizedEventParam:M,maximize:K,restore:J,allowDrag:I,isMaximized:T,unWindowResizeHandle:Q}}function Ce(t,a,n){const l=e.ref(),s=e.ref(t.draggable),u=e.ref(t.lockAxis),d=e.ref(),r=e.ref(),c=e.ref(!1),m=e.ref(new B(0,0)),g=e.ref(new B(0,0)),v=e.ref(new B(0,0)),M=e.ref(new B(0,0));e.watch(()=>n.value,h=>{d.value.style.cursor=h?"move":"default"});function N(h,w){if(w.tagName==="BUTTON")return!1;if(w===h)return!0;for(const R in w.children)if(Object.prototype.hasOwnProperty.call(w.children,R)&&N(h,w.children[R]))return!0;return!1}function E(){var F,k;let h=v.value.x+g.value.x,w=v.value.y+g.value.y;u.value==="x"?(h=((F=m.value)==null?void 0:F.x)||0,v.value.x=0):u.value==="y"&&(w=((k=m.value)==null?void 0:k.y)||0,v.value.y=0);const R=`translate3d(${Math.round(h)}px, ${Math.round(w)}px, 0px)`;l.value&&(l.value.style.transform=R),M.value.x=h,M.value.y=w}function I(){if(!r.value||!l.value)return null;const h=r.value.getBoundingClientRect(),w=l.value.getBoundingClientRect(),R={top:h.top<w.top,right:h.right>w.right,bottom:h.bottom>w.bottom,left:h.left<w.left};return R.top||(v.value.y-=w.top-h.top),R.bottom||(v.value.y-=w.bottom-h.bottom),R.right||(v.value.x-=w.right-h.right),R.left||(v.value.x-=w.left-h.left),E(),R}function T(h){h&&(m.value&&h.subtract(m.value),v.value.set(h),E(),I())}function S(h){c.value&&s.value&&(h.stopPropagation(),h.preventDefault(),T(B.fromEvent(h,d.value)))}function V(){var h;c.value&&(c.value=!1,g.value.add(v.value),v.value.reset(),(h=l.value)==null||h.classList.remove("ng-dragging"),a.emit("stopMove"),document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",V))}function C(){!c.value&&d.value&&(c.value=!0,d.value.classList.add("ng-dragging"),document.addEventListener("mousemove",S),document.addEventListener("mouseup",V))}function D(){if(l.value){const h=B.getTransformInfo(l.value);g.value.set(h);return}g.value.reset()}function b(h){if(!n.value||h instanceof MouseEvent&&h.button===2)return;const w=h.target||h.srcElement;d.value!==void 0&&w&&!N(w,d.value)||s.value!==!1&&(document.body.click(),h.stopPropagation(),h.preventDefault(),m.value=B.fromEvent(h,l.value),D(),C())}function z(h,w,R){if(s.value&&w){if(h)d.value=h;else if(t.dragHandle){if(t.dragHandle instanceof HTMLElement)d.value=t.dragHandle;else if(typeof t.dragHandle=="string"){const F=w.querySelector(t.dragHandle);F&&(d.value=F)}}l.value=w,r.value=R,d.value?(d.value.classList.add("ng-draggable"),d.value.addEventListener("mousedown",b)):s.value=!1}}return{registerDraggle:z,resetTranslate:D}}function ne(t,a){if(t){const n=l=>{l.key.toLowerCase()===t.toLowerCase()&&a({event:l,key:t})};return document.addEventListener("keydown",n),()=>{document.removeEventListener("keydown",n)}}}function Me(t,a){const n=e.ref(t.enableEsc);let l=null;return n.value?(l=ne("Escape",s=>{a.emit("esc",{event:s.event,type:"esc"})}),{remove:l}):null}function Te(t,a){const n=e.ref(t.enableEnter);let l=null;return n.value?(l=ne("Enter",s=>{a.emit("enter",{event:s.event,type:"enter"})}),{remove:l}):null}const q=e.defineComponent({name:"FModal",props:be,emits:["update:modelValue","accept","cancel","closed","resize","esc","enter","stopMove"],setup(t,a){const n=e.ref(t.width||300),l=e.ref(t.height||200),s=e.ref(t.modelValue),u=e.ref(""),d=e.ref(t.class),r=e.ref(t.fitContent),c=e.ref(t.showHeader),m=e.ref(""),g=e.ref(t.showCloseButton),v=e.ref(t.showMaxButton),M=e.ref(!1),N=e.ref(t.dialogType),E=e.ref(t.src),I=e.ref(""),T=e.ref(t.showButtons),S=e.ref(t.title),V=e.ref(t.containment||null),C=e.ref(),D=e.ref(!1);function b(o,y){Promise.resolve().then(()=>{var j;return(j=t.beforeClose)==null?void 0:j.call(t)}).then(j=>{j&&(s.value=!1,a.emit("update:modelValue",!1),y!=null&&a.emit(y?"accept":"cancel"),a.emit("closed",o))})}const z=[{name:"cancel",text:"取消",class:"btn btn-secondary",handle:o=>{b(o,!1)}},{name:"accept",text:"确定",class:"btn btn-primary",handle:o=>{b(o,!0)}}],h=e.ref(t.buttons&&t.buttons.length?t.buttons:z),w=e.computed(()=>!!m.value),R=e.computed(()=>!!T.value&&!!h.value),F=e.ref(),k=e.ref(),P=e.ref(!1),{renderResizeBar:K,maximize:J,restore:G,boundingElement:U,resizedEventParam:Q,allowDrag:i,unWindowResizeHandle:f}=xe(t),{registerDraggle:x}=Ce(t,a,i);function p(){return!!document.querySelectorAll(".farris-modal").length&&document.body.classList.contains("modal-open")}function H(){const o=document.querySelectorAll(".farris-modal").length;(!o||o-1<=0)&&document.body.classList.remove("modal-open"),C.value&&C.value.classList.remove("show")}e.watch(()=>t.title,(o,y)=>{o!==y&&(S.value=o)}),e.watch(()=>t.modelValue,(o,y)=>{o!==y&&(s.value=o,s.value&&t.draggable&&e.nextTick(()=>{k.value&&!V.value&&(V.value=k.value.parentElement,U.value=V.value,x(F.value,k.value,U.value))}),o||(V.value&&(V.value=null),H())),s.value&&(D.value=p())}),e.watch(()=>t.showHeader,(o,y)=>{o!==y&&(c.value=o)}),e.watch(()=>t.showButtons,(o,y)=>{o!==y&&(T.value=o)}),e.watch(()=>Q.value,(o,y)=>{const j=o||{},$=y||{};JSON.stringify(j)!==JSON.stringify($)&&a.emit("resize",{newSize:o,oldSize:y,isMaximized:P.value})});const Z=e.computed(()=>(s.value&&document.body.classList.add("modal-open"),s.value)),Ne=e.computed(()=>{var j;const o={modal:!0,"farris-modal":!0,fade:!0};o["f-modal-fitContent"]=!!r.value,o.show=!!Z.value;const y=(j=t.maskClass)==null?void 0:j.split(" ");return y==null||y.reduce(($,ae)=>($[ae]=!0,$),o),o}),Ve=e.computed(()=>{var j;const o={"modal-dialog":!0},y=(j=d.value)==null?void 0:j.split(" ");return y==null||y.reduce(($,ae)=>($[ae]=!0,$),o),o}),Ee=e.computed(()=>{const o={position:"absolute",top:`${(window.innerHeight-l.value)/2}px`,left:`${(window.innerWidth-n.value)/2}px`,width:`${n.value}px`,height:r.value?"auto":`${l.value}px`};return t.mask||(o.pointerEvents="auto"),o}),ze=e.computed(()=>{const o={display:"block"};return t.mask||(o.pointerEvents="none",o.backgroundColor="transparent"),D.value&&(o.backgroundColor="transparent"),o}),Se=e.computed(()=>({"modal-content":!0,"modal-content-has-header":c.value})),Re=e.computed(()=>{const o={display:c.value?"":"none"};return o["pointer-events"]=i.value?"auto":"none",o}),He=e.computed(()=>({"f-icon":!0,modal_maximize:!0,modalrevert:P.value})),Oe=e.computed(()=>({"modal-body":!0,"f-utils-flex-column":N.value==="iframe","f-utils-fill":!0}));function Ie(){return{height:`${t.footerHeight||60}px`}}const je=e.computed(()=>{const o={textAlgin:I.value},y=Ie();return Object.assign(o,y)});function se(o){if(o.stopPropagation(),P.value){P.value=!1,G();return}J(),P.value=!0}async function Fe(o,y){o.handle&&await o.handle(y,o)&&a.emit("closed",y)}function Le(o){o.width&&(n.value=o.width),o.height&&(l.value=o.height),o.buttons&&(h.value=o.buttons),o.title&&(S.value=o.title)}let ee=null,te=null;e.onBeforeMount(()=>{D.value=p()}),e.onMounted(()=>{k.value&&!V.value&&(V.value=k.value.parentElement,U.value=V.value,x(F.value,k.value,U.value)),Z.value&&document.body.classList.add("modal-open"),ee=Me(t,a),te=Te(t,a)}),e.onUnmounted(()=>{f&&f(),ee&&ee.remove(),te&&te.remove()}),a.expose({modalElementRef:k,updateModalOptions:Le,close:b,maxDialog:se,isMaximized:P});function De(){return e.createVNode("ul",null,[M.value&&e.createVNode("li",{class:"f-btn-icon f-bare"},[e.createVNode("span",{class:"f-icon modal_minimize"},null)]),v.value&&e.createVNode("li",{onClick:se,class:"f-btn-icon f-bare",style:"pointer-events: auto;"},[e.createVNode("span",{class:He.value},null)]),g.value&&e.createVNode("li",{class:"f-btn-icon f-bare",onClick:o=>b(o,!1),style:"pointer-events: auto;"},[e.createVNode("span",{class:"f-icon modal_close"},null)])])}function Pe(){return e.createVNode("div",{class:"modal-footer",style:je.value},[h.value&&h.value.map(o=>{const y=e.ref(o.disabled);return e.createVNode("button",{name:o.name,type:"button",disabled:y.value,class:o.class+(o.iconClass?" btn-icontext":""),onClick:j=>{Fe(o,j)}},[!!o.iconClass&&e.createVNode("i",{class:o.iconClass},null),o.text])})])}function We(){return e.createVNode("div",{ref:F,class:"modal-header",style:Re.value},[a.slots.headerTemplate?a.slots.headerTemplate():e.createVNode("div",{class:"modal-title"},[w.value&&e.createVNode("span",{class:m.value,style:"margin-right: 8px"},null),e.createVNode("span",{class:"modal-title-label"},[S.value])]),e.createVNode("div",{class:"actions"},[De()])])}function Ae(){return a.slots.footerTemplate?a.slots.footerTemplate():R.value&&Pe()}function $e(o){if(o.stopPropagation(),t.allowClickMaskToClose){if(o.target!==C.value)return;b(o,!1)}}function Xe(){var o,y;return e.createVNode("div",{id:u.value,class:Ve.value,style:Ee.value,ref:k},[e.createVNode("div",{class:Se.value},[c.value&&We(),e.createVNode("div",{class:Oe.value},[(y=(o=a.slots).default)==null?void 0:y.call(o),N.value==="iframe"&&e.createVNode("iframe",{title:u.value,class:"f-utils-fill",width:"100%",frameborder:"0",src:E.value},null)]),Ae()]),!r.value&&k.value&&!P.value&&K(k.value)])}return()=>e.createVNode(e.Teleport,{to:"body"},{default:()=>[Z.value&&e.createVNode(e.Transition,{name:"fade",appear:!0},{default:()=>[e.createVNode("div",{ref:C,class:Ne.value,style:ze.value,onClick:$e},[Xe()])]})]})}});function le(t){if(t.content&&t.content.render)return t.content.render;if(t.render&&typeof t.render=="function")return t.render}function ke(t){const a=document.createElement("div");a.style.display="contents";const n=e.createApp({setup(l,s){e.onUnmounted(()=>{document.body.removeChild(a)});const u=e.ref(),d=e.ref(t.class||""),r=e.ref(!!t.showButtons),c=e.ref(!!t.showHeader),m=e.ref(t.showCloseButton==null?!0:t.showCloseButton),g=e.ref(!0),v=e.ref(t.title||""),M=t.acceptCallback||(()=>{}),N=t.rejectCallback||(()=>{}),E=t.closedCallback||(C=>{}),I=t.resizeHandle||(C=>{}),T=t.stopMoveHandle||(C=>{}),S=le(t),V=C=>{g.value=!1,n.unmount(),E(C)};return e.onMounted(()=>{}),s.expose({modalRef:u}),()=>e.createVNode(q,{ref:u,class:d.value,modelValue:g.value,"onUpdate:modelValue":C=>g.value=C,title:v.value,width:t.width,height:t.height,buttons:t.buttons,"show-header":c.value,"show-buttons":r.value,"show-close-button":m.value,"show-max-button":!1,onAccept:M,onCancel:N,fitContent:t.fitContent==null?!0:t.fitContent,onClosed:V,onResize:I,onStopMove:T},{default:()=>[S&&S(n)]})}});return document.body.appendChild(a),n.mount(a),n}class oe{constructor(a){X(this,"appContext",null);X(this,"modalRef",e.ref());X(this,"activeModalIndex",e.ref(0));X(this,"modalRefs",{});X(this,"isUseEscCloseModal",e.ref(!1));X(this,"activeModalInstance",e.computed(()=>this.modalRefs[this.activeModalIndex.value]));this.app=a,this.appContext=a?a._context:null}getCurrentModal(){return this.activeModalInstance.value}adaptToWindow(a,n){const{width:l,height:s}={width:window.innerWidth,height:window.innerHeight};return l<a&&(a=l-14),s<n&&(n=s-14),{width:a,height:n}}static show(a){const n=Object.assign({title:"",showButtons:!0,showHeader:!0},a);return ke(n)}close(a){var n,l;a?(l=a.value)==null||l.close():(n=this.getCurrentModal())==null||n.close()}open(a){const n=document.createDocumentFragment();a.showMaxButton&&a.fitContent&&(a.showMaxButton=!1);const l=e.shallowRef(Object.assign({title:"",showButtons:!0,showHeader:!0},a)),s=e.ref(!0),u=l.value.acceptCallback||(()=>{}),d=l.value.rejectCallback||(()=>{}),r=l.value.closedCallback||((b,z)=>{}),c=l.value.resizeHandle||(b=>{}),m=a.stopMoveHandle||(b=>{});let g;const v=le(l.value),M=b=>{var h;s.value=!1;const z=(h=b==null?void 0:b.target)==null?void 0:h.classList.contains("modal_close");r(b,this.isUseEscCloseModal.value?"esc":z?"icon":"button")},N=b=>{M(b),g&&e.nextTick(()=>{if(this.modalRefs[this.activeModalIndex.value]&&delete this.modalRefs[this.activeModalIndex.value],e.render(null,n),g=null,this.modalRef.value=null,this.modalRefs){const z=Object.keys(this.modalRefs).map(h=>Number(h));z.length>0?this.activeModalIndex.value=Math.max(...z):this.activeModalIndex.value=0}this.isUseEscCloseModal.value=!1})},E=b=>{var z;this.isUseEscCloseModal.value=!0,this.activeModalInstance&&((z=this.activeModalInstance.value)==null||z.close(b==null?void 0:b.event))},{width:I,height:T}=l.value,S=this.adaptToWindow(I||500,T||320);Object.assign(l.value,S);const V=()=>e.createVNode(q,e.mergeProps({ref:this.modalRef,modelValue:s.value,"onUpdate:modelValue":b=>s.value=b},l.value,{onAccept:u,onCancel:d,onClosed:N,onResize:c,onEsc:E,onStopMove:m}),{default:()=>[v&&v(this.app)]});return g=(b=>{const z=e.h(V,b);return z.appContext=this.appContext,e.render(z,n),z})({...l.value}),this.activeModalIndex.value++,this.modalRefs[this.activeModalIndex.value]=this.modalRef.value,{update:b=>{l.value={...l.value,...b},g&&e.render(e.cloneVNode(g,{...l}),n)},destroy:N,modalRef:this.activeModalInstance,close:this.close}}}const Be=Symbol("FModalService");q.install=t=>{t.component(q.name,q);const a=new oe(t);t.provide(Be,a),t.provide("FModalService",a)};class L{static show(a){const n=e.reactive({...a}),l=!1,s=n.type==="error"||n.type==="prompt",u=n.type==="error"?"错误提示":n.type==="prompt"&&n.title||"",d=n.acceptCallback||(()=>{}),r=n.rejectCallback||(()=>{});let c=null,m=new oe(c);const g=()=>{c&&(c==null||c.destroy(),m=null)};return c=m==null?void 0:m.open({class:"modal-message modal-message-type-info",title:u,showButtons:l,showHeader:s,width:n.width||400,fitContent:!0,showMaxButton:!1,draggable:!0,render:()=>e.createVNode(Y,e.mergeProps(n,{onAccept:d,onReject:r,onClose:g}),null)}),m==null?void 0:m.getCurrentModal()}static info(a,n){const l=e.reactive({type:"info",title:a,detail:n,okButtonText:"知道了",cancelButtonText:""});L.show(l)}static warning(a,n){const l=e.reactive({type:"warning",title:a,detail:n,okButtonText:"知道了",cancelButtonText:""});L.show(l)}static success(a,n){const l=e.reactive({type:"success",title:a,detail:n,okButtonText:"关闭",cancelButtonText:""});L.show(l)}static error(a,n,l){const s=e.reactive({width:500,type:"error",okButtonText:"关闭",cancelButtonText:"",exceptionInfo:{date:l,message:a,detail:n}});L.show(s)}static prompt(a,n){const l=e.reactive({type:"prompt",title:a,detail:n,okButtonText:"确定",cancelButtonText:"取消"});L.show(l)}static question(a,n,l,s){const u=e.reactive({type:"question",title:a,detail:n,okButtonText:"确定",cancelButtonText:"取消",acceptCallback:l,rejectCallback:s});L.show(u)}}Y.install=t=>{t.component(Y.name,Y),t.provide("FMessageBoxService",L)},O.FMessageBox=Y,O.FMessageBoxService=L,O.default=Y,O.messageBoxProps=W,Object.defineProperties(O,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});