@fox-js/navigation 4.0.1-23 → 4.0.1-25
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/README.md +53 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +485 -562
- package/dist/index.umd.js +1 -1
- package/dist/style.css +2 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/README.md
CHANGED
|
@@ -381,3 +381,56 @@ onMounted(() => {
|
|
|
381
381
|
| 名称 | 说明 |
|
|
382
382
|
|---------|------------------|
|
|
383
383
|
| default | 内容 |
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
### fox-stack-navigator
|
|
388
|
+
|
|
389
|
+
stack导航组件,支持动画(和fox-root-navigator类型),支持拖曳新打开新页面/切换页面
|
|
390
|
+
|
|
391
|
+
#### 基础用法
|
|
392
|
+
|
|
393
|
+
```
|
|
394
|
+
<script setup lang="ts">
|
|
395
|
+
import { usePageHelper } from '@/utils/custom'
|
|
396
|
+
// 获取page helper
|
|
397
|
+
const pageHelper = usePageHelper()
|
|
398
|
+
// 定义remove page函数
|
|
399
|
+
const removePage = () => {
|
|
400
|
+
pageHelper.remove()
|
|
401
|
+
}
|
|
402
|
+
</script>
|
|
403
|
+
|
|
404
|
+
<template>
|
|
405
|
+
<fox-stack-navigator :remove-page="removePage"></fox-stack-navigator>
|
|
406
|
+
</template>
|
|
407
|
+
|
|
408
|
+
<style lang="scss">
|
|
409
|
+
</style>
|
|
410
|
+
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
#### Props
|
|
414
|
+
|
|
415
|
+
| 字段 | 说明 | 类型 | 默认值 |
|
|
416
|
+
|------------------|----------------------------------------|---------|-----------|
|
|
417
|
+
| open-page | 打开页面方法 | Function | |
|
|
418
|
+
| router-view-name | router view名称 | String | `default` |
|
|
419
|
+
| routes | 路由列表 | Route[] | |
|
|
420
|
+
| active-path | 激活路径 | String | |
|
|
421
|
+
| height | 导航容器高度 | Number | |
|
|
422
|
+
| width | 导航容器宽度 | Number | |
|
|
423
|
+
| drag | 是否支持拖曳 | Boolean | |
|
|
424
|
+
| swipe-duration | 滑动页面动画时间 | Number ||
|
|
425
|
+
| scroll-time | 切换页面动画时间 | Number | |
|
|
426
|
+
| move-ratio | 触发页面移动的比例(相对页面宽度) | Number | 0.5 |
|
|
427
|
+
| momentum-reduce-ratio | 惯性削减比例 | Number | 1 |
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
#### 插槽
|
|
433
|
+
|
|
434
|
+
| 名称 | 说明 |
|
|
435
|
+
|---------|------------------|
|
|
436
|
+
| default | 内容 |
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("vue"),D=require("@fox-js/fox"),F=m.defineComponent({__name:"index",props:{routerViewName:{},transition:{type:[Function,Boolean],default:!0}},setup(t){return(e,n)=>{const o=m.resolveComponent("fox-router-view");return m.openBlock(),m.createBlock(o,{transition:!1,multi:!1,name:t.routerViewName},{default:m.withCtx(({Component:r})=>[m.createVNode(m.Transition,{name:"fox-default-navigator__trans"},{default:m.withCtx(()=>[(m.openBlock(),m.createBlock(m.resolveDynamicComponent(r)))]),_:2},1024)]),_:1},8,["name"])}}}),B=10;function Q(t,e){return t>e&&t>B?"horizontal":e>t&&e>B?"vertical":""}function I(){const t={startX:0,startY:0,startTime:0,duration:0,moveX:0,moveY:0,deltaX:0,deltaY:0,offsetX:0,offsetY:0,direction:""},e=()=>t.direction==="vertical",n=()=>t.direction==="horizontal",o=()=>{t.deltaX=0,t.deltaY=0,t.offsetX=0,t.offsetY=0,t.direction="",t.startTime=0};return{move:(h=>{if(h.touches){const w=h.touches[0];t.deltaX=w.clientX-t.startX,t.deltaY=w.clientY-t.startY,t.moveX=w.clientX,t.moveY=w.clientY}else t.deltaX=h.clientX-t.startX,t.deltaY=h.clientY-t.startY,t.moveX=h.clientX,t.moveY=h.clientY;t.offsetX=Math.abs(t.deltaX),t.offsetY=Math.abs(t.deltaY),t.duration=Date.now()-t.startTime,t.direction||(t.direction=Q(t.offsetX,t.offsetY))}),start:(h=>{if(o(),h.touches){const w=h.touches[0];t.startX=w.clientX,t.startY=w.clientY}else t.startX=h.clientX,t.startY=h.clientY;t.startTime=Date.now()}),reset:o,isVertical:e,isHorizontal:n,state:t}}function Z(t){return t===window}const W=t=>{const e=m.unref(t);if(Z(e)){const n=e.innerWidth,o=e.innerHeight;return{top:0,left:0,right:n,bottom:o,width:n,height:o}}return e&&e.getBoundingClientRect?e.getBoundingClientRect():{top:0,left:0,right:0,bottom:0,width:0,height:0}},z=(t,e,n)=>{e=e??{bubbles:!1,cancelable:!1,detail:void 0};const o=document.createEvent("Events");let r=!0,v=!0;for(let w in e)w==="bubbles"?r=!!e[w]:w==="cancelable"?v=!!e[w]:o[w]=e[w];o.initEvent(t,r,v),(n??document).dispatchEvent(o)},tt=15,et=300,nt=200;function ot(t){t.stopPropagation()}function it(t,e,n=1){return t=Math.abs(t/e)/.003*(t<0?-1:1),t*n}function C(t,e=0,n,o=nt){n==="end"?t.style.transition=`transform ${o}ms linear`:t.style.transition="transform 0ms linear",t.style.transform=`translate3d(${e}px, 0, 0)`}function V(t){t.style.transition="",t.style.transform=""}const at=/^matrix\((.+)\)$/;function X(t){let e=0;const n=t,{transform:o}=window.getComputedStyle(n);if(o){const r=at.exec(o);r&&(e=+r[1].split(/,\s*/)[4])}return e}const S=new WeakMap;function st(t,e,n,o,r,v,h=600,w=60,$=null){const s={active:!0,startDistance:0,scrollDistance:0,scrollTime:0,moving:!1,dragging:!1,transitionEndTrigger:null},T=t.previousSibling,g=I(),a=(i,d,p,x)=>{let l=d+s.startDistance;if(p==="end"){const y=W(i);let E=y.width*e;l<E?l=0:l=y.width,s.transitionEndTrigger=()=>{s.moving=!1,i.classList.remove(v),setTimeout(()=>{T&&V(T),l==0?V(i):z(D.FoxLeaveEnd,{},i),s.moving=!1},w)},T&&C(T,0,"",0),l>0&&typeof o=="function"&&o(r),C(i,l,"end",x)}else l<0&&(l=0),C(i,l,"",0)},u=()=>{s.transitionEndTrigger&&(s.transitionEndTrigger(),s.transitionEndTrigger=null)},c=i=>{if(g.start(i),s.draging=$?$(t,g.state.startX,g.state.startY):!0,!s.draging){g.reset();return}s.scrollDistance=0,s.moving&&(s.scrollDistance=X(t)),t.classList.add(v),s.transitionEndTrigger=null,s.moving=!0},L=i=>{!s.draging||(s.moving=!0,g.move(i),g.isVertical())||X(t)===0&&g.state.deltaX<0||(ot(i),a(t,g.state.deltaX,"",0))},f=()=>{if(!s.draging||(s.draging=!1,g.isVertical())||X(t)===0&&g.state.deltaX<0)return;const d=g.state.deltaX;if(d===0){t.classList.remove(v),s.moving=!1;return}const p=g.state.duration;if(p<et&&Math.abs(d)>tt){const l=it(d,p,n);a(t,l,"end",h)}else a(t,d,"end",h)};t.addEventListener("transitionend",u),t.addEventListener("transitioncancel",u),t.addEventListener("touchstart",c),t.addEventListener("touchmove",L),t.addEventListener("touchend",f),t.addEventListener("touchcancel",f),S.set(t,{state:s,transitionend:u,transitioncancel:u,touchstart:c,touchmove:L,touchend:f,touchcancel:f})}function rt(t){const e=S.get(t);e&&(S.delete(t),t.addEventListener("transitionend",e.transitionend),t.addEventListener("transitioncancel",e.transitioncancel),t.addEventListener("touchstart",e.touchstart),t.addEventListener("touchmove",e.touchmove),t.addEventListener("touchend",e.touchend),t.addEventListener("touchcancel",e.touchcancel))}const U=m.defineComponent({__name:"index",props:{dragRemove:{type:Boolean,default:!0},removeViewPage:{},removeMoveRatio:{default:.5},momentumReduceRatio:{default:1},resetDelay:{default:120},swipeDuration:{default:60},draggableArea:{},routerViewName:{},viewTag:{type:[Function,String],default:"div"},transition:{type:[Function,Boolean],default:!0},transitionDuration:{},viewClass:{type:[Function,String],default:"fox-root-navigator__item"}},setup(t){const e=t;let n=null,o=null;function r(a){return(a.params&&a.params.animationType)??"slide"}function v(a){return(a.params&&a.params.dragRemove)??e.dragRemove}const h=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const f=r(c),i=u?"show":"enter";if(i==="show"&&(f==="pop"||o!=="leave"||(n?r(n):"")==="pop"))return;i==="enter"&&(n=c,o="enter");const d=`fox-root-navigator--${f}-${i}-from`,p=`fox-root-navigator--${f}-${i}-active`;a.classList.add(d),a.classList.add(p)}},w=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const f=r(c),i=u?"show":"enter";if(i==="show"&&(f==="pop"||o!=="leave"||(n?r(n):"")==="pop"))return;const d=`fox-root-navigator--${f}-${i}-from`,p=`fox-root-navigator--${f}-${i}-to`;a.classList.remove(d),a.classList.add(p)}},$=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const i=r(c),d=u?"show":"enter";if(d==="enter"&&(n=null,o=null),i!=="pop"){const p=`fox-root-navigator--${i}-${d}-active`,x=`fox-root-navigator--${i}-${d}-to`;a.classList.remove(p),a.classList.remove(x)}}if(v(c)===!0&&!u&&c.opsType===D.OperationType.Append){let i=null;e.draggableArea&&(i=function(d,p,x){const l=p-d.offsetLeft,y=x-d.offsetTop;return!(e.draggableArea?.left&&l<e.draggableArea?.left||e.draggableArea?.right&&l>e.draggableArea?.right||e.draggableArea?.top&&y<e.draggableArea?.top||e.draggableArea?.bottom&&y>e.draggableArea?.bottom)}),st(a,e.removeMoveRatio,e.momentumReduceRatio,e.removeViewPage,c,"fox-root-navigator__item--moving",e.swipeDuration,e.resetDelay,i)}},s=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const f=r(c),i=u?"hide":"leave";if(i==="hide"&&(f==="pop"||o!=="enter"||(n?r(n):"")==="pop"))return;i==="leave"&&(n=c,o="leave");const d=`fox-root-navigator--${f}-${i}-from`,p=`fox-root-navigator--${f}-${i}-active`;a.classList.add(d),a.classList.add(p)}},T=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const f=r(c),i=u?"hide":"leave";if(i==="hide"&&(f==="pop"||o!=="enter"||(n?r(n):"")==="pop"))return;const d=`fox-root-navigator--${f}-${i}-from`,p=`fox-root-navigator--${f}-${i}-to`;a.classList.remove(d),a.classList.add(p)}},g=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const i=r(c),d=u?"hide":"leave";if(d==="leave"&&(n=null,o=null),i!=="pop"){const p=`fox-root-navigator--${i}-${d}-active`,x=`fox-root-navigator--${i}-${d}-to`;a.classList.remove(p),a.classList.remove(x)}}v(c)&&!u&&rt(a)};return(a,u)=>{const c=m.resolveComponent("fox-router-view");return m.openBlock(),m.createBlock(c,{class:"fox-root-navigator","view-class":t.viewClass,"before-enter":h,enter:w,"after-enter":$,"before-leave":s,leave:T,"after-leave":g,multi:!0,name:t.routerViewName,"view-tag":t.viewTag,transition:t.transition,"transition-duration":t.transitionDuration},null,8,["view-class","name","view-tag","transition","transition-duration"])}}}),q=m.defineComponent({__name:"index",props:{routerViewName:{},transition:{type:[Function,Boolean],default:!1}},setup(t){return(e,n)=>{const o=m.resolveComponent("fox-router-view");return m.openBlock(),m.createBlock(o,{class:"fox-card-navigator","view-class":"fox-card-navigator__item","view-active-class":"fox-card-navigator__item-active","view-inactive-class":"fox-card-navigator__item-inactive","transition-name":"fox-card-navigator__trans",transition:t.transition,multi:!0,name:t.routerViewName},null,8,["transition","name"])}}}),ct=15,lt=300,dt=200;function ut(t){t.stopPropagation()}function ft(t,e,n=1){return t=Math.abs(t/e)/.003*(t<0?-1:1),t*n}function O(t,e=0,n,o=dt){n==="end"?t.style.transition=`transform ${o}ms linear`:t.style.transition="transform 0ms linear",t.style.transform=`translate3d(${e}px, 0, 0)`}function N(t){t.style.transition="",t.style.transform=""}const mt=/^matrix\((.+)\)$/;function P(t){let e=0;const n=t,{transform:o}=window.getComputedStyle(n);if(o){const r=mt.exec(o);r&&(e=+r[1].split(/,\s*/)[4])}return e}const k=new WeakMap;function gt(t,e,n,o,r,v,h=600,w=60,$=null){const s={active:!0,startDistance:0,scrollDistance:0,scrollTime:0,moving:!1,dragging:!1,transitionEndTrigger:null},T=t.previousSibling,g=I(),a=(i,d,p,x)=>{let l=d+s.startDistance;if(p==="end"){const y=W(i);let E=y.width*e;l<E?l=0:l=y.width,s.transitionEndTrigger=()=>{s.moving=!1,i.classList.remove(v),setTimeout(()=>{T&&N(T),l==0?N(i):z(D.FoxLeaveEnd,{},i),s.moving=!1},w)},T&&O(T,0,"",0),l>0&&typeof o=="function"&&o(r),O(i,l,"end",x)}else l<0&&(l=0),O(i,l,"",0)},u=()=>{s.transitionEndTrigger&&(s.transitionEndTrigger(),s.transitionEndTrigger=null)},c=i=>{if(g.start(i),s.draging=$?$(t,g.state.startX,g.state.startY):!0,!s.draging){g.reset();return}s.scrollDistance=0,s.moving&&(s.scrollDistance=P(t)),t.classList.add(v),s.transitionEndTrigger=null,s.moving=!0},L=i=>{!s.draging||(s.moving=!0,g.move(i),g.isVertical())||P(t)===0&&g.state.deltaX<0||(ut(i),a(t,g.state.deltaX,"",0))},f=()=>{if(!s.draging||(s.draging=!1,g.isVertical())||P(t)===0&&g.state.deltaX<0)return;const d=g.state.deltaX;if(d===0){t.classList.remove(v),s.moving=!1;return}const p=g.state.duration;if(p<lt&&Math.abs(d)>ct){const l=ft(d,p,n);a(t,l,"end",h)}else a(t,d,"end",h)};t.addEventListener("transitionend",u),t.addEventListener("transitioncancel",u),t.addEventListener("touchstart",c),t.addEventListener("touchmove",L),t.addEventListener("touchend",f),t.addEventListener("touchcancel",f),k.set(t,{state:s,transitionend:u,transitioncancel:u,touchstart:c,touchmove:L,touchend:f,touchcancel:f})}function pt(t){const e=k.get(t);e&&(k.delete(t),t.addEventListener("transitionend",e.transitionend),t.addEventListener("transitioncancel",e.transitioncancel),t.addEventListener("touchstart",e.touchstart),t.addEventListener("touchmove",e.touchmove),t.addEventListener("touchend",e.touchend),t.addEventListener("touchcancel",e.touchcancel))}const H=m.defineComponent({__name:"index",props:{dragRemove:{type:Boolean,default:!0},removeViewPage:{},removeMoveRatio:{default:.5},momentumReduceRatio:{default:1},resetDelay:{default:120},swipeDuration:{default:60},draggableArea:{},routerViewName:{},viewTag:{type:[Function,String],default:"div"},transition:{type:[Function,Boolean],default:!0},transitionDuration:{},viewClass:{type:[Function,String],default:"fox-stack-navigator__item"}},setup(t){const e=t;let n=null,o=null;function r(a){return(a.params&&a.params.animationType)??"slide"}function v(a){return(a.params&&a.params.dragRemove)??e.dragRemove}const h=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const f=r(c),i=u?"show":"enter";if(i==="show"&&(f==="pop"||o!=="leave"||(n?r(n):"")==="pop"))return;i==="enter"&&(n=c,o="enter");const d=`fox-stack-navigator--${f}-${i}-from`,p=`fox-stack-navigator--${f}-${i}-active`;a.classList.add(d),a.classList.add(p)}},w=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const f=r(c),i=u?"show":"enter";if(i==="show"&&(f==="pop"||o!=="leave"||(n?r(n):"")==="pop"))return;const d=`fox-stack-navigator--${f}-${i}-from`,p=`fox-stack-navigator--${f}-${i}-to`;a.classList.remove(d),a.classList.add(p)}},$=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const i=r(c),d=u?"show":"enter";if(d==="enter"&&(n=null,o=null),i!=="pop"){const p=`fox-stack-navigator--${i}-${d}-active`,x=`fox-stack-navigator--${i}-${d}-to`;a.classList.remove(p),a.classList.remove(x)}}if(v(c)===!0&&!u&&c.opsType===D.OperationType.Append){let i=null;e.draggableArea&&(i=function(d,p,x){const l=p-d.offsetLeft,y=x-d.offsetTop;return!(e.draggableArea?.left&&l<e.draggableArea?.left||e.draggableArea?.right&&l>e.draggableArea?.right||e.draggableArea?.top&&y<e.draggableArea?.top||e.draggableArea?.bottom&&y>e.draggableArea?.bottom)}),gt(a,e.removeMoveRatio,e.momentumReduceRatio,e.removeViewPage,c,"fox-stack-navigator__item--moving",e.swipeDuration,e.resetDelay,i)}},s=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const f=r(c),i=u?"hide":"leave";if(i==="hide"&&(f==="pop"||o!=="enter"||(n?r(n):"")==="pop"))return;i==="leave"&&(n=c,o="leave");const d=`fox-stack-navigator--${f}-${i}-from`,p=`fox-stack-navigator--${f}-${i}-active`;a.classList.add(d),a.classList.add(p)}},T=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const f=r(c),i=u?"hide":"leave";if(i==="hide"&&(f==="pop"||o!=="enter"||(n?r(n):"")==="pop"))return;const d=`fox-stack-navigator--${f}-${i}-from`,p=`fox-stack-navigator--${f}-${i}-to`;a.classList.remove(d),a.classList.add(p)}},g=(a,u,c,L)=>{if(c.opsType===D.OperationType.Append||u){const i=r(c),d=u?"hide":"leave";if(d==="leave"&&(n=null,o=null),i!=="pop"){const p=`fox-stack-navigator--${i}-${d}-active`,x=`fox-stack-navigator--${i}-${d}-to`;a.classList.remove(p),a.classList.remove(x)}}v(c)&&!u&&pt(a)};return(a,u)=>{const c=m.resolveComponent("fox-router-view");return m.openBlock(),m.createBlock(c,{class:"fox-stack-navigator","view-class":t.viewClass,"before-enter":h,enter:w,"after-enter":$,"before-leave":s,leave:T,"after-leave":g,multi:!0,name:t.routerViewName,"view-tag":t.viewTag,transition:t.transition,"transition-duration":t.transitionDuration},null,8,["view-class","name","view-tag","transition","transition-duration"])}}}),vt={class:"fox-swiper-navigator"},ht=m.defineComponent({__name:"swiper",props:{width:{},scrollDistance:{},scrollDuration:{},direction:{}},setup(t){const e=t,n=m.computed(()=>{const o={transform:`translate3d(${e.scrollDistance}px, 0, 0)`,width:`${e.width}`};return e.scrollDuration>0&&(o["transition-duration"]=`${e.scrollDuration}ms`),o});return(o,r)=>(m.openBlock(),m.createElementBlock("div",vt,[m.createElementVNode("div",{class:"fox-swiper-navigator__inner",style:m.normalizeStyle(n.value)},[m.renderSlot(o.$slots,"default")],4)]))}});let Tt=0;function wt(){return++Tt}const yt=15,xt=300,Et=200;function Lt(t){t.stopPropagation()}function $t(t,e,n=1){return t=Math.abs(t/e)/.003*(t<0?-1:1),t*n}function Y(t,e=0,n,o=Et){n==="end"?t.style.transition=`transform ${o}ms linear`:t.style.transition="transform 0ms linear",t.style.transform=`translate3d(${e}px, 0, 0)`}class Dt{width=0;columnWidth=0;max=0;min=0;el=null;swipeDuration=360;transitionEndTrigger=null;moving=!1;startDistance=0;scrollDistance=0;getStartDistance;openPage;isPageOpened;pageOpened;moveRatio=.5;momentumReduceRatio=1;transitionend=null;touchstart=null;touchmove=null;touchend=null;touchcancel=null;constructor(e,n,o,r,v,h){this.getStartDistance=e,this.openPage=n,this.isPageOpened=o,this.pageOpened=r,this.moveRatio=v,this.momentumReduceRatio=h}open(){const e=this.el,n=I(),o=(r,v,h,w)=>{let $=v+this.startDistance;const s=this.columnWidth*this.moveRatio;if(h==="end"){if(v==0){this.moving=!1;return}Math.abs(v)>s?v>0?$=this.startDistance+this.columnWidth:$=this.startDistance-this.columnWidth:$=this.startDistance;let T=-$;T<0?T=0:T>this.width-this.columnWidth&&(T=this.width-this.columnWidth);const g=Math.floor(T/this.columnWidth);this.isPageOpened(g)||this.openPage(g),$=-g*this.columnWidth,w&&w>0&&(this.transitionEndTrigger=()=>{this.moving=!1,this.pageOpened(g)}),Y(r,$,"end",w),this.scrollDistance=$}else{if(Math.abs(v)>s){let g=0;if(v>0?g=Math.abs(this.startDistance+this.columnWidth):g=Math.abs(this.startDistance-this.columnWidth),g>=0&&g<this.width){const a=Math.floor(g/this.columnWidth);this.isPageOpened(a)||this.openPage(a)}}let T=-$;T<this.min?T=this.min:T>this.max&&(T=this.max),Y(r,-T,"",0)}};this.transitionend=()=>{e.style.transition="",this.transitionEndTrigger&&(this.transitionEndTrigger(),this.transitionEndTrigger=null)},this.touchstart=r=>{this.moving||(n.start(r),this.startDistance=this.getStartDistance(),this.transitionEndTrigger=null,this.moving=!0)},this.touchmove=r=>{n.move(r),!n.isVertical()&&(Lt(r),o(e,n.state.deltaX,"",0))},this.touchend=()=>{if(n.isVertical())return;const r=n.state.deltaX;if(r==0)return;const v=n.state.duration;if(v<xt&&Math.abs(r)>yt){const w=$t(r,v,this.momentumReduceRatio);o(e,w,"end",this.swipeDuration)}else o(e,r,"end",this.swipeDuration)},e.addEventListener("transitionend",this.transitionend),e.addEventListener("touchstart",this.touchstart),e.addEventListener("touchmove",this.touchmove),e.addEventListener("touchend",this.touchend),e.addEventListener("touchcancel",this.touchend)}close(){const e=this.el;this.transitionend&&e.addEventListener("transitionend",this.transitionend),this.touchstart&&e.addEventListener("touchstart",this.touchstart),this.touchmove&&e.addEventListener("touchmove",this.touchmove),this.touchend&&e.addEventListener("touchend",this.touchend),this.touchcancel&&e.addEventListener("touchcancel",this.touchcancel),this.el=null}}function Rt(t,e,n,o,r,v){return new Dt(t,e,n,o,r,v)}function _t(t){const e=m.unref(t),n=window.getComputedStyle(e,null),o=parseFloat(n.getPropertyValue("padding-left")),r=parseFloat(n.getPropertyValue("padding-right")),v=parseFloat(n.getPropertyValue("padding-top")),h=parseFloat(n.getPropertyValue("padding-bottom"));return{width:e.clientWidth-o-r,height:e.clientHeight-v-h}}const j=m.defineComponent({__name:"index",props:{activePath:{},routes:{},height:{default:-1},width:{default:-1},draggable:{type:Boolean,default:!0},openViewPage:{},routerViewName:{},moveRatio:{default:.5},momentumReduceRatio:{default:1},direction:{default:"horizontal"},transition:{type:[Function,Boolean],default:!0},swipeDuration:{default:360},scrollDuration:{},customClass:{},customStyle:{}},emits:["update:activePath"],setup(t,{emit:e}){const n=t,o=m.reactive({scrollDistance:0,index:-1,openedIndexList:[],width:n.width,height:n.height}),r=e,v=()=>o.scrollDistance,h=l=>{if(o.openedIndexList.indexOf(l)===-1){o.openedIndexList.push(l);const y=n.routes[l];try{n.openViewPage(y,l)}catch(E){console.error(E)}}},w=l=>o.openedIndexList.indexOf(l)!==-1,$=l=>{o.index=l,o.width>0?o.scrollDistance=-o.index*o.width:o.scrollDistance=0;const y=n.routes[l];r("update:activePath",y.path)};let s=null;n.draggable&&(s=Rt(v,h,w,$,n.moveRatio,n.momentumReduceRatio));let T=null;m.onMounted(()=>{const l=f(),y=()=>{const E=_t(l);g(n.activePath,n.routes,E.width,E.height,n.swipeDuration,n.direction)};if(window.ResizeObserver&&(T=new window.ResizeObserver(y),T.observe(l)),y(),s){const E=d();s.el=E,s.open()}}),m.onBeforeUnmount(()=>{T&&(T.disconnect(),T=null),s&&s.close()}),m.watch([()=>n.activePath,()=>n.routes,()=>n.width,()=>n.height,()=>n.swipeDuration,()=>n.direction],([l,y,E,_,b,A])=>{const M=E<=0?o.width:E,R=_<=0?o.height:_;g(l,y,M,R,b,A)});const g=(l,y,E,_,b,A="horizontal")=>{const M=l;if(o.index=y.findIndex(R=>R.path===M),A==="horizontal"){const R=E;if(R>0){o.width=E;const G=R*n.routes.length,J=-R/3,K=R*(y.length-1)+R/3;s&&(s.columnWidth=R,s.width=G,s.min=J,s.max=K),o.index!==-1&&(o.openedIndexList.push(o.index),o.scrollDistance=-R*o.index)}}s&&(s.swipeDuration=b)},a=`fox-swiper-navigator-${wt()}`,u=m.computed(()=>{const l=[a];return n.customClass&&l.push(n.customClass),l}),c=m.computed(()=>{const l={},y=o.width>0?o.width:n.width;y>0&&(l.width=`${y}px`);const E=o.height>0?o.height:n.height;return E>0&&(l.height=`${E}px`),n.customStyle&&Object.assign(l,n.customStyle),l});let L=null;function f(){return L||(L=document.querySelector(`.${a}`),L)}let i=null;function d(){return i||(i=document.querySelector(`.${a}>.fox-swiper-navigator__inner`),i)}const p=m.computed(()=>o.width>0?`${o.width*n.routes.length}px`:"100%"),x=(l,y)=>{const E=n.routes.findIndex(_=>{const b=l.path??l.name??"";return _.path==b});return o.width<=0?{}:{style:{left:`${E*o.width}px`,width:`${o.width}px`}}};return(l,y)=>{const E=m.resolveComponent("fox-router-view");return m.openBlock(),m.createBlock(E,{class:m.normalizeClass(u.value),style:m.normalizeStyle(c.value),"view-class":"fox-swiper-navigator__item",tag:ht,"view-tag-props":x,multi:!0,name:t.routerViewName,transition:t.transition,"scroll-distance":o.scrollDistance,"scroll-duration":t.scrollDuration,direction:t.direction,width:p.value},null,8,["class","style","name","transition","scroll-distance","scroll-duration","direction","width"])}}}),bt={install(t,e="fox"){t.component(`${e}-default-navigator`,F),t.component(`${e}-root-navigator`,U),t.component(`${e}-card-navigator`,q),t.component(`${e}-stack-navigator`,H),t.component(`${e}-swiper-navigator`,j)}};exports.FoxCardNavigator=q;exports.FoxDefaultNavigator=F;exports.FoxRootNavigator=U;exports.FoxStackNavigator=H;exports.FoxSwiperNavigator=j;exports.default=bt;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});let f=require("vue"),$=require("@fox-js/fox");var Q=(0,f.defineComponent)({__name:"index",props:{routerViewName:{},transition:{type:[Function,Boolean],default:!0}},setup(t){return(e,o)=>{const n=(0,f.resolveComponent)("fox-router-view");return(0,f.openBlock)(),(0,f.createBlock)(n,{transition:!1,multi:!1,name:t.routerViewName},{default:(0,f.withCtx)(({Component:l})=>[(0,f.createVNode)(f.Transition,{name:"fox-default-navigator__trans"},{default:(0,f.withCtx)(()=>[((0,f.openBlock)(),(0,f.createBlock)((0,f.resolveDynamicComponent)(l)))]),_:2},1024)]),_:1},8,["name"])}}}),N=Q,B=10;function Z(t,e){return t>e&&t>B?"horizontal":e>t&&e>B?"vertical":""}function I(){const t={startX:0,startY:0,startTime:0,duration:0,moveX:0,moveY:0,deltaX:0,deltaY:0,offsetX:0,offsetY:0,direction:""},e=()=>t.direction==="vertical",o=()=>t.direction==="horizontal",n=()=>{t.deltaX=0,t.deltaY=0,t.offsetX=0,t.offsetY=0,t.direction="",t.startTime=0};return{move:(m=>{if(m.touches){const w=m.touches[0];t.deltaX=w.clientX-t.startX,t.deltaY=w.clientY-t.startY,t.moveX=w.clientX,t.moveY=w.clientY}else t.deltaX=m.clientX-t.startX,t.deltaY=m.clientY-t.startY,t.moveX=m.clientX,t.moveY=m.clientY;t.offsetX=Math.abs(t.deltaX),t.offsetY=Math.abs(t.deltaY),t.duration=Date.now()-t.startTime,t.direction||(t.direction=Z(t.offsetX,t.offsetY))}),start:(m=>{if(n(),m.touches){const w=m.touches[0];t.startX=w.clientX,t.startY=w.clientY}else t.startX=m.clientX,t.startY=m.clientY;t.startTime=Date.now()}),reset:n,isVertical:e,isHorizontal:o,state:t}}function tt(t){return t===window}var W=t=>{const e=(0,f.unref)(t);if(tt(e)){const o=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:o,bottom:n,width:o,height:n}}return e&&e.getBoundingClientRect?e.getBoundingClientRect():{top:0,left:0,right:0,bottom:0,width:0,height:0}},z=(t,e,o)=>{e=e??{bubbles:!1,cancelable:!1,detail:void 0};const n=document.createEvent("Events");let l=!0,p=!0;for(let m in e)m==="bubbles"?l=!!e[m]:m==="cancelable"?p=!!e[m]:n[m]=e[m];n.initEvent(t,l,p),(o??document).dispatchEvent(n)},et=15,nt=300,ot=200;function it(t){t.stopPropagation()}function at(t,e,o=1){return t=Math.abs(t/e)/.003*(t<0?-1:1),t*o}function R(t,e=0,o,n=ot){o==="end"?t.style.transition=`transform ${n}ms linear`:t.style.transition="transform 0ms linear",t.style.transform=`translate3d(${e}px, 0, 0)`}function V(t){t.style.transition="",t.style.transform=""}var rt=/^matrix\((.+)\)$/;function O(t){let e=0;const o=t,{transform:n}=window.getComputedStyle(o);if(n){const l=rt.exec(n);l&&(e=+l[1].split(/,\s*/)[4])}return e}var k=new WeakMap;function st(t,e,o,n,l,p,m=600,w=60,E=null){const a={active:!0,startDistance:0,scrollDistance:0,scrollTime:0,moving:!1,dragging:!1,transitionEndTrigger:null},T=t.previousSibling,h=I(),r=(i,v,g,L)=>{let u=v+a.startDistance;if(g==="end"){const y=W(i);let _=y.width*e;u<_?u=0:u=y.width,a.transitionEndTrigger=()=>{a.moving=!1,p&&i.classList.remove(p),setTimeout(()=>{T&&V(T),u==0?V(i):z($.FoxLeaveEnd,{},i),a.moving=!1},w)},T&&R(T,0,"",0),u>0&&typeof n=="function"&&n(l),R(i,u,"end",L)}else u<0&&(u=0),R(i,u,"",0)},d=()=>{a.transitionEndTrigger&&(a.transitionEndTrigger(),a.transitionEndTrigger=null)},c=i=>{if(h.start(i),a.draging=E?E(t,h.state.startX,h.state.startY):!0,!a.draging){h.reset();return}a.scrollDistance=0,a.moving&&(a.scrollDistance=O(t)),p&&t.classList.add(p),a.transitionEndTrigger=null,a.moving=!0},x=i=>{a.draging&&(a.moving=!0,h.move(i),!h.isVertical()&&(O(t)===0&&h.state.deltaX<0||(it(i),r(t,h.state.deltaX,"",0))))},s=()=>{if(!a.draging||(a.draging=!1,h.isVertical())||O(t)===0&&h.state.deltaX<0)return;const i=h.state.deltaX;if(i===0){p&&t.classList.remove(p),a.moving=!1;return}const v=h.state.duration;if(v<nt&&Math.abs(i)>et){const g=at(i,v,o);r(t,g,"end",m)}else r(t,i,"end",m)};t.addEventListener("transitionend",d),t.addEventListener("transitioncancel",d),t.addEventListener("touchstart",c),t.addEventListener("touchmove",x),t.addEventListener("touchend",s),t.addEventListener("touchcancel",s),k.set(t,{state:a,transitionend:d,transitioncancel:d,touchstart:c,touchmove:x,touchend:s,touchcancel:s})}function ct(t){const e=k.get(t);e&&(k.delete(t),t.removeEventListener("transitionend",e.transitionend),t.removeEventListener("transitioncancel",e.transitioncancel),t.removeEventListener("touchstart",e.touchstart),t.removeEventListener("touchmove",e.touchmove),t.removeEventListener("touchend",e.touchend),t.removeEventListener("touchcancel",e.touchcancel))}var lt=(0,f.defineComponent)({__name:"index",props:{dragRemove:{type:Boolean,default:!0},removeViewPage:{},removeMoveRatio:{default:.5},momentumReduceRatio:{default:1},resetDelay:{default:120},swipeDuration:{default:60},draggableArea:{},routerViewName:{},viewTag:{type:[Function,String],default:"div"},transition:{type:[Function,Boolean],default:!0},transitionDuration:{},viewClass:{type:[Function,String],default:"fox-root-navigator__item"}},setup(t){const e=t;let o=null,n=null;function l(r){return(r&&r.params&&r.params.animationType)??"slide"}function p(r){return(r&&r.params&&r.params.dragRemove)??e.dragRemove}const m=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"show":"enter";if(i==="show"&&(s==="pop"||n!=="leave"||(o?l(o):"")==="pop"))return;i==="enter"&&(o=c,n="enter");const v=`fox-root-navigator--${s}-${i}-from`,g=`fox-root-navigator--${s}-${i}-active`;r.classList.add(v),r.classList.add(g)}},w=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"show":"enter";if(i==="show"&&(s==="pop"||n!=="leave"||(o?l(o):"")==="pop"))return;const v=`fox-root-navigator--${s}-${i}-from`,g=`fox-root-navigator--${s}-${i}-to`;r.classList.remove(v),r.classList.add(g)}},E=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"show":"enter";if(i==="enter"&&(o=null,n=null),s!=="pop"){const v=`fox-root-navigator--${s}-${i}-active`,g=`fox-root-navigator--${s}-${i}-to`;r.classList.remove(v),r.classList.remove(g)}}if(p(c)===!0&&!d&&c?.opsType===$.OperationType.Append){let s=null;e.draggableArea&&(s=function(i,v,g){const L=v-i.offsetLeft,u=g-i.offsetTop;return!(e.draggableArea?.left&&L<e.draggableArea?.left||e.draggableArea?.right&&L>e.draggableArea?.right||e.draggableArea?.top&&u<e.draggableArea?.top||e.draggableArea?.bottom&&u>e.draggableArea?.bottom)}),st(r,e.removeMoveRatio,e.momentumReduceRatio,e.removeViewPage,c,"fox-root-navigator__item--moving",e.swipeDuration,e.resetDelay,s)}},a=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"hide":"leave";if(i==="hide"&&(s==="pop"||n!=="enter"||(o?l(o):"")==="pop"))return;i==="leave"&&(o=c,n="leave");const v=`fox-root-navigator--${s}-${i}-from`,g=`fox-root-navigator--${s}-${i}-active`;r.classList.add(v),r.classList.add(g)}},T=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"hide":"leave";if(i==="hide"&&(s==="pop"||n!=="enter"||(o?l(o):"")==="pop"))return;const v=`fox-root-navigator--${s}-${i}-from`,g=`fox-root-navigator--${s}-${i}-to`;r.classList.remove(v),r.classList.add(g)}},h=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"hide":"leave";if(i==="leave"&&(o=null,n=null),s!=="pop"){const v=`fox-root-navigator--${s}-${i}-active`,g=`fox-root-navigator--${s}-${i}-to`;r.classList.remove(v),r.classList.remove(g)}}p(c)&&!d&&ct(r)};return(r,d)=>{const c=(0,f.resolveComponent)("fox-router-view");return(0,f.openBlock)(),(0,f.createBlock)(c,{class:"fox-root-navigator","view-class":t.viewClass,"before-enter":m,enter:w,"after-enter":E,"before-leave":a,leave:T,"after-leave":h,multi:!0,name:t.routerViewName,"view-tag":t.viewTag,transition:t.transition,"transition-duration":t.transitionDuration},null,8,["view-class","name","view-tag","transition","transition-duration"])}}}),U=lt,ut=(0,f.defineComponent)({__name:"index",props:{routerViewName:{},transition:{type:[Function,Boolean],default:!1}},setup(t){return(e,o)=>{const n=(0,f.resolveComponent)("fox-router-view");return(0,f.openBlock)(),(0,f.createBlock)(n,{class:"fox-card-navigator","view-class":"fox-card-navigator__item","view-active-class":"fox-card-navigator__item-active","view-inactive-class":"fox-card-navigator__item-inactive","transition-name":"fox-card-navigator__trans",transition:t.transition,multi:!0,name:t.routerViewName},null,8,["transition","name"])}}}),q=ut,dt=15,ft=300,vt=200;function gt(t){t.stopPropagation()}function mt(t,e,o=1){return t=Math.abs(t/e)/.003*(t<0?-1:1),t*o}function P(t,e=0,o,n=vt){o==="end"?t.style.transition=`transform ${n}ms linear`:t.style.transition="transform 0ms linear",t.style.transform=`translate3d(${e}px, 0, 0)`}function Y(t){t.style.transition="",t.style.transform=""}var pt=/^matrix\((.+)\)$/;function X(t){let e=0;const o=t,{transform:n}=window.getComputedStyle(o);if(n){const l=pt.exec(n);l&&(e=+l[1].split(/,\s*/)[4])}return e}var S=new WeakMap;function ht(t,e,o,n,l,p,m=600,w=60,E=null){const a={active:!0,startDistance:0,scrollDistance:0,scrollTime:0,moving:!1,dragging:!1,transitionEndTrigger:null},T=t.previousSibling,h=I(),r=(i,v,g,L)=>{let u=v+a.startDistance;if(g==="end"){const y=W(i);let _=y.width*e;u<_?u=0:u=y.width,a.transitionEndTrigger=()=>{a.moving=!1,p&&i.classList.remove(p),setTimeout(()=>{T&&Y(T),u==0?Y(i):z($.FoxLeaveEnd,{},i),a.moving=!1},w)},T&&P(T,0,"",0),u>0&&typeof n=="function"&&n(l),P(i,u,"end",L)}else u<0&&(u=0),P(i,u,"",0)},d=()=>{a.transitionEndTrigger&&(a.transitionEndTrigger(),a.transitionEndTrigger=null)},c=i=>{if(h.start(i),a.draging=E?E(t,h.state.startX,h.state.startY):!0,!a.draging){h.reset();return}a.scrollDistance=0,a.moving&&(a.scrollDistance=X(t)),p&&t.classList.add(p),a.transitionEndTrigger=null,a.moving=!0},x=i=>{a.draging&&(a.moving=!0,h.move(i),!h.isVertical()&&(X(t)===0&&h.state.deltaX<0||(gt(i),r(t,h.state.deltaX,"",0))))},s=()=>{if(!a.draging||(a.draging=!1,h.isVertical())||X(t)===0&&h.state.deltaX<0)return;const i=h.state.deltaX;if(i===0){p&&t.classList.remove(p),a.moving=!1;return}const v=h.state.duration;if(v<ft&&Math.abs(i)>dt){const g=mt(i,v,o);r(t,g,"end",m)}else r(t,i,"end",m)};t.addEventListener("transitionend",d),t.addEventListener("transitioncancel",d),t.addEventListener("touchstart",c),t.addEventListener("touchmove",x),t.addEventListener("touchend",s),t.addEventListener("touchcancel",s),S.set(t,{state:a,transitionend:d,transitioncancel:d,touchstart:c,touchmove:x,touchend:s,touchcancel:s})}function Tt(t){const e=S.get(t);e&&(S.delete(t),t.removeEventListener("transitionend",e.transitionend),t.removeEventListener("transitioncancel",e.transitioncancel),t.removeEventListener("touchstart",e.touchstart),t.removeEventListener("touchmove",e.touchmove),t.removeEventListener("touchend",e.touchend),t.removeEventListener("touchcancel",e.touchcancel))}var wt=(0,f.defineComponent)({__name:"index",props:{dragRemove:{type:Boolean,default:!0},removeViewPage:{},removeMoveRatio:{default:.5},momentumReduceRatio:{default:1},resetDelay:{default:120},swipeDuration:{default:60},draggableArea:{},routerViewName:{},viewTag:{type:[Function,String],default:"div"},transition:{type:[Function,Boolean],default:!0},transitionDuration:{},viewClass:{type:[Function,String],default:"fox-stack-navigator__item"}},setup(t){const e=t;let o=null,n=null;function l(r){return(r&&r.params&&r.params.animationType)??"slide"}function p(r){return(r&&r.params&&r.params.dragRemove)??e.dragRemove}const m=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"show":"enter";if(i==="show"&&(s==="pop"||n!=="leave"||(o?l(o):"")==="pop"))return;i==="enter"&&(o=c,n="enter");const v=`fox-stack-navigator--${s}-${i}-from`,g=`fox-stack-navigator--${s}-${i}-active`;r.classList.add(v),r.classList.add(g)}},w=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"show":"enter";if(i==="show"&&(s==="pop"||n!=="leave"||(o?l(o):"")==="pop"))return;const v=`fox-stack-navigator--${s}-${i}-from`,g=`fox-stack-navigator--${s}-${i}-to`;r.classList.remove(v),r.classList.add(g)}},E=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"show":"enter";if(i==="enter"&&(o=null,n=null),s!=="pop"){const v=`fox-stack-navigator--${s}-${i}-active`,g=`fox-stack-navigator--${s}-${i}-to`;r.classList.remove(v),r.classList.remove(g)}}if(p(c)===!0&&!d&&c?.opsType===$.OperationType.Append){let s=null;e.draggableArea&&(s=function(i,v,g){const L=v-i.offsetLeft,u=g-i.offsetTop;return!(e.draggableArea?.left&&L<e.draggableArea?.left||e.draggableArea?.right&&L>e.draggableArea?.right||e.draggableArea?.top&&u<e.draggableArea?.top||e.draggableArea?.bottom&&u>e.draggableArea?.bottom)}),ht(r,e.removeMoveRatio,e.momentumReduceRatio,e.removeViewPage,c,"fox-stack-navigator__item--moving",e.swipeDuration,e.resetDelay,s)}},a=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"hide":"leave";if(i==="hide"&&(s==="pop"||n!=="enter"||(o?l(o):"")==="pop"))return;i==="leave"&&(o=c,n="leave");const v=`fox-stack-navigator--${s}-${i}-from`,g=`fox-stack-navigator--${s}-${i}-active`;r.classList.add(v),r.classList.add(g)}},T=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"hide":"leave";if(i==="hide"&&(s==="pop"||n!=="enter"||(o?l(o):"")==="pop"))return;const v=`fox-stack-navigator--${s}-${i}-from`,g=`fox-stack-navigator--${s}-${i}-to`;r.classList.remove(v),r.classList.add(g)}},h=(r,d,c,x)=>{if(c?.opsType===$.OperationType.Append||d){const s=l(c),i=d?"hide":"leave";if(i==="leave"&&(o=null,n=null),s!=="pop"){const v=`fox-stack-navigator--${s}-${i}-active`,g=`fox-stack-navigator--${s}-${i}-to`;r.classList.remove(v),r.classList.remove(g)}}p(c)&&!d&&Tt(r)};return(r,d)=>{const c=(0,f.resolveComponent)("fox-router-view");return(0,f.openBlock)(),(0,f.createBlock)(c,{class:"fox-stack-navigator","view-class":t.viewClass,"before-enter":m,enter:w,"after-enter":E,"before-leave":a,leave:T,"after-leave":h,multi:!0,name:t.routerViewName,"view-tag":t.viewTag,transition:t.transition,"transition-duration":t.transitionDuration},null,8,["view-class","name","view-tag","transition","transition-duration"])}}}),j=wt,_t={class:"fox-swiper-navigator"},xt=(0,f.defineComponent)({__name:"swiper",props:{width:{},scrollDistance:{},scrollDuration:{},direction:{}},setup(t){const e=t,o=(0,f.computed)(()=>{const n={transform:`translate3d(${e.scrollDistance}px, 0, 0)`,width:`${e.width}`};return e.scrollDuration>0&&(n["transition-duration"]=`${e.scrollDuration}ms`),n});return(n,l)=>((0,f.openBlock)(),(0,f.createElementBlock)("div",_t,[(0,f.createElementVNode)("div",{class:"fox-swiper-navigator__inner",style:(0,f.normalizeStyle)(o.value)},[(0,f.renderSlot)(n.$slots,"default")],4)]))}}),yt=xt,$t=0;function Et(){return++$t}var Lt=15,Dt=300,bt=200;function Mt(t){t.stopPropagation()}function At(t,e,o=1){return t=Math.abs(t/e)/.003*(t<0?-1:1),t*o}function F(t,e=0,o,n=bt){o==="end"?t.style.transition=`transform ${n}ms linear`:t.style.transition="transform 0ms linear",t.style.transform=`translate3d(${e}px, 0, 0)`}var Ct=class{width=0;columnWidth=0;max=0;min=0;el=null;swipeDuration=360;transitionEndTrigger=null;moving=!1;startDistance=0;scrollDistance=0;getStartDistance;openPage;isPageOpened;pageOpened;moveRatio=.5;momentumReduceRatio=1;transitionend=null;touchstart=null;touchmove=null;touchend=null;touchcancel=null;constructor(t,e,o,n,l,p){this.getStartDistance=t,this.openPage=e,this.isPageOpened=o,this.pageOpened=n,this.moveRatio=l,this.momentumReduceRatio=p}open(){const t=this.el,e=I(),o=(n,l,p,m)=>{let w=l+this.startDistance;const E=this.columnWidth*this.moveRatio;if(p==="end"){if(l==0){this.moving=!1;return}Math.abs(l)>E?l>0?w=this.startDistance+this.columnWidth:w=this.startDistance-this.columnWidth:w=this.startDistance;let a=-w;a<0?a=0:a>this.width-this.columnWidth&&(a=this.width-this.columnWidth);const T=Math.floor(a/this.columnWidth);this.isPageOpened(T)||this.openPage(T),w=-T*this.columnWidth,m&&m>0&&(this.transitionEndTrigger=()=>{this.moving=!1,this.pageOpened(T)}),F(n,w,"end",m),this.scrollDistance=w}else{if(Math.abs(l)>E){let T=0;if(l>0?T=Math.abs(this.startDistance+this.columnWidth):T=Math.abs(this.startDistance-this.columnWidth),T>=0&&T<this.width){const h=Math.floor(T/this.columnWidth);this.isPageOpened(h)||this.openPage(h)}}let a=-w;a<this.min?a=this.min:a>this.max&&(a=this.max),F(n,-a,"",0)}};this.transitionend=()=>{t.style.transition="",this.transitionEndTrigger&&(this.transitionEndTrigger(),this.transitionEndTrigger=null)},this.touchstart=n=>{this.moving||(e.start(n),this.startDistance=this.getStartDistance(),this.transitionEndTrigger=null,this.moving=!0)},this.touchmove=n=>{e.move(n),!e.isVertical()&&(Mt(n),o(t,e.state.deltaX,"",0))},this.touchend=()=>{if(e.isVertical())return;const n=e.state.deltaX;if(n==0)return;const l=e.state.duration;if(l<Dt&&Math.abs(n)>Lt){const p=At(n,l,this.momentumReduceRatio);o(t,p,"end",this.swipeDuration)}else o(t,n,"end",this.swipeDuration)},t.addEventListener("transitionend",this.transitionend),t.addEventListener("touchstart",this.touchstart),t.addEventListener("touchmove",this.touchmove),t.addEventListener("touchend",this.touchend),t.addEventListener("touchcancel",this.touchend)}close(){const t=this.el;this.transitionend&&t.removeEventListener("transitionend",this.transitionend),this.touchstart&&t.removeEventListener("touchstart",this.touchstart),this.touchmove&&t.removeEventListener("touchmove",this.touchmove),this.touchend&&t.removeEventListener("touchend",this.touchend),this.touchcancel&&t.removeEventListener("touchcancel",this.touchcancel),this.el=null}};function Rt(t,e,o,n,l,p){return new Ct(t,e,o,n,l,p)}function Ot(t){const e=(0,f.unref)(t),o=window.getComputedStyle(e,null),n=parseFloat(o.getPropertyValue("padding-left")),l=parseFloat(o.getPropertyValue("padding-right")),p=parseFloat(o.getPropertyValue("padding-top")),m=parseFloat(o.getPropertyValue("padding-bottom"));return{width:e.clientWidth-n-l,height:e.clientHeight-p-m}}var Pt=(0,f.defineComponent)({__name:"index",props:{activePath:{},routes:{},height:{default:-1},width:{default:-1},draggable:{type:Boolean,default:!0},openViewPage:{},routerViewName:{},moveRatio:{default:.5},momentumReduceRatio:{default:1},direction:{default:"horizontal"},transition:{type:[Function,Boolean],default:!0},swipeDuration:{default:360},scrollDuration:{},customClass:{},customStyle:{}},emits:["update:activePath"],setup(t,{emit:e}){const o=t,n=(0,f.reactive)({scrollDistance:0,index:-1,openedIndexList:[],width:o.width,height:o.height}),l=e,p=()=>n.scrollDistance,m=u=>{if(n.openedIndexList.indexOf(u)===-1){n.openedIndexList.push(u);const y=o.routes[u];try{o.openViewPage(y,u)}catch(_){console.error(_)}}},w=u=>n.openedIndexList.indexOf(u)!==-1,E=u=>{n.index=u,n.width>0?n.scrollDistance=-n.index*n.width:n.scrollDistance=0;const y=o.routes[u];l("update:activePath",y.path)};let a=null;o.draggable&&(a=Rt(p,m,w,E,o.moveRatio,o.momentumReduceRatio));let T=null;(0,f.onMounted)(()=>{const u=s(),y=()=>{const _=Ot(u);h(o.activePath,o.routes,_.width,_.height,o.swipeDuration,o.direction)};if(window.ResizeObserver&&(T=new window.ResizeObserver(y),T.observe(u)),y(),a){const _=v();a.el=_,a.open()}}),(0,f.onBeforeUnmount)(()=>{T&&(T.disconnect(),T=null),a&&a.close()}),(0,f.watch)([()=>o.activePath,()=>o.routes,()=>o.width,()=>o.height,()=>o.swipeDuration,()=>o.direction],([u,y,_,b,M,A])=>{const C=_<=0?n.width:_,D=b<=0?n.height:b;h(u,y,C,D,M,A)});const h=(u,y,_,b,M,A="horizontal")=>{const C=u;if(n.index=y.findIndex(D=>D.path===C),A==="horizontal"){const D=_;if(D>0){n.width=_;const G=D*o.routes.length,J=-D/3,K=D*(y.length-1)+D/3;a&&(a.columnWidth=D,a.width=G,a.min=J,a.max=K),n.index!==-1&&(n.openedIndexList.push(n.index),n.scrollDistance=-D*n.index)}}a&&(a.swipeDuration=M)},r=`fox-swiper-navigator-${Et()}`,d=(0,f.computed)(()=>{const u=[r];return o.customClass&&u.push(o.customClass),u}),c=(0,f.computed)(()=>{const u={},y=n.width>0?n.width:o.width;y>0&&(u.width=`${y}px`);const _=n.height>0?n.height:o.height;return _>0&&(u.height=`${_}px`),o.customStyle&&Object.assign(u,o.customStyle),u});let x=null;function s(){return x||(x=document.querySelector(`.${r}`),x)}let i=null;function v(){return i||(i=document.querySelector(`.${r}>.fox-swiper-navigator__inner`),i)}const g=(0,f.computed)(()=>n.width>0?`${n.width*o.routes.length}px`:"100%"),L=(u,y)=>{const _=o.routes.findIndex(b=>{const M=u.path??u.name??"";return b.path==M});return n.width<=0?{}:{style:{left:`${_*n.width}px`,width:`${n.width}px`}}};return(u,y)=>{const _=(0,f.resolveComponent)("fox-router-view");return(0,f.openBlock)(),(0,f.createBlock)(_,{class:(0,f.normalizeClass)(d.value),style:(0,f.normalizeStyle)(c.value),"view-class":"fox-swiper-navigator__item",tag:yt,"view-tag-props":L,multi:!0,name:t.routerViewName,transition:t.transition,"scroll-distance":n.scrollDistance,"scroll-duration":t.scrollDuration,direction:t.direction,width:g.value},null,8,["class","style","name","transition","scroll-distance","scroll-duration","direction","width"])}}}),H=Pt,Xt={install(t,e="fox"){t.component(`${e}-default-navigator`,N),t.component(`${e}-root-navigator`,U),t.component(`${e}-card-navigator`,q),t.component(`${e}-stack-navigator`,j),t.component(`${e}-swiper-navigator`,H)}};exports.FoxCardNavigator=q;exports.FoxDefaultNavigator=N;exports.FoxRootNavigator=U;exports.FoxStackNavigator=j;exports.FoxSwiperNavigator=H;exports.default=Xt;
|