@fox-js/navigation 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,255 @@
1
+ # fox-navigation
2
+
3
+ 导航组件,支持动画过渡
4
+
5
+ ## Install
6
+
7
+ ### NPM
8
+
9
+ ```shell
10
+ npm i @fox-js/navigation -S
11
+ ```
12
+
13
+ ### YARN
14
+
15
+ ```shell
16
+ yarn add @fox-js/navigation
17
+ ```
18
+
19
+ ### PNPM
20
+
21
+ ```shell
22
+ pnpm add @fox-js/navigation
23
+ ```
24
+
25
+ ## 使用说明
26
+
27
+ ### fox-root-navigator
28
+
29
+ root导航组件,在入口vue文件(App.vue)上使用,支持新增页面的动画效果和拖曳关闭页面。
30
+
31
+ #### 基础用法
32
+
33
+ ```
34
+ <script setup lang="ts">
35
+ import { usePageHelper } from '@/utils/custom'
36
+ // 获取page helper
37
+ const pageHelper = usePageHelper()
38
+ // 定义remove page函数
39
+ const removePage = () => {
40
+ pageHelper.remove()
41
+ }
42
+ </script>
43
+
44
+ <template>
45
+ <fox-root-navigator :remove-page="removePage"></fox-root-navigator>
46
+ </template>
47
+
48
+ <style lang="scss">
49
+ </style>
50
+
51
+ ```
52
+
53
+ #### Props
54
+
55
+ | 字段 | 说明 | 类型 | 默认值 |
56
+ |------------------|----------------------------------------|---------|-----------|
57
+ | drag-remove | 是否支持拖曳关闭 | Boolean | true |
58
+ | remove-page | 关闭顶层页面方法 | Function | |
59
+ | router-view-name | router view名称 | String | `default` |
60
+ | view-tag | view tag标签 | Function/String | `div` |
61
+
62
+
63
+
64
+ ## 插槽
65
+
66
+ | 名称 | 说明 |
67
+ |---------|------------------|
68
+ | default | 内容 |
69
+
70
+
71
+
72
+ ### fox-card-navigator
73
+
74
+ 卡片导航组件,配合多标签页容器使用,具备缓存页面的能力。
75
+
76
+
77
+
78
+ #### 基础用法
79
+
80
+ ```
81
+ <script setup lang="ts">
82
+ const rootName = $ref('_tab_view')
83
+ </script>
84
+
85
+ <template>
86
+ <fox-card-navigator
87
+ :router-view-name="rootName"
88
+ :transition="true"
89
+ ></fox-card-navigator>
90
+ </template>
91
+
92
+ <style lang="scss">
93
+ </style>
94
+
95
+ ```
96
+
97
+ #### Props
98
+
99
+ | 字段 | 说明 | 类型 | 默认值 |
100
+ |------------------|----------------------------------------|---------|-----------|
101
+ | router-view-name | router view名称 | String | `default` |
102
+ | transition | 是否支持过渡动画 | Boolean | false |
103
+
104
+
105
+
106
+ ## 插槽
107
+
108
+ | 名称 | 说明 |
109
+ |---------|------------------|
110
+ | default | 内容 |
111
+
112
+
113
+ ### fox-swiper-navigator
114
+
115
+ swiper导航组件,配合tab标签使用(例如手机端的主界面),支持拖曳新打开新页面/切换页面
116
+
117
+ #### 基础用法
118
+
119
+ ```
120
+ <script lang="ts" setup>
121
+ import { onMounted, ref, computed } from 'vue'
122
+ import { usePageHelper } from '@/utils/custom'
123
+ import store from '@/store'
124
+ import tabs from './data'
125
+ const contentPadding = {
126
+ left: 0,
127
+ top: 0,
128
+ right: 0,
129
+ bottom: 0
130
+ }
131
+ // -------------- 导航设置 ---------------
132
+ // content width/height
133
+ const contentWidth = ref(0)
134
+ const contentHeight = ref(0)
135
+ // page ref
136
+ const pageRef = ref(null)
137
+ // root name
138
+ const rootName = ref('_tab_view')
139
+ // routes
140
+ const routes = computed(() => {
141
+ return tabs.map(tab => {
142
+ return {
143
+ path: tab.route
144
+ }
145
+ })
146
+ })
147
+ // active route path
148
+ const activeRoutePath = computed({
149
+ set: (newVal: string) => {
150
+ // 更新tab bar的index
151
+ index.value = routes.value.findIndex(r => {
152
+ return r.path === newVal
153
+ })
154
+ store.setCurrentRoutePath(newVal, rootName.value)
155
+ },
156
+ get: (): string => {
157
+ return store.getCurrentRoutePath(rootName.value) as string
158
+ }
159
+ })
160
+ // open page
161
+ const openPage = (route: any, index: number) => {
162
+ onTabChange(index)
163
+ }
164
+
165
+ // -------------tab bar 设置 ------------------
166
+ //当前tab索引
167
+ const index = ref(0)
168
+ // 获取page helper
169
+ const pageHelper = usePageHelper()
170
+ // tab change事件
171
+ const onTabChange = (index: any) => {
172
+ const tab = tabs[index]
173
+ // open页面
174
+ pageHelper.open(tab.route)
175
+ // 当前的route path到公共store中
176
+ store.setCurrentRoutePath(tab.route, rootName.value)
177
+ }
178
+ // content应用
179
+ const contentRef = ref(null)
180
+ // 加载后处理
181
+ onMounted(() => {
182
+ if (pageRef.value) {
183
+ const anyPage: any = pageRef.value
184
+ contentWidth.value = anyPage.getPageContentWidth()
185
+ if (contentWidth.value === 0) {
186
+ const anyContent: any = contentRef.value
187
+ contentWidth.value = anyContent.$el.offsetWidth
188
+ }
189
+ contentHeight.value = anyPage.getPageContentHeight()
190
+ }
191
+ // 当前选中tab index
192
+ let curIndex = index.value
193
+ // 获取之前保存的route path
194
+ let path = store.getCurrentRoutePath(rootName.value)
195
+ if (path) {
196
+ let i = tabs.findIndex(tab => {
197
+ return tab.route === path
198
+ })
199
+ curIndex = i !== -1 ? i : curIndex
200
+ // 更新tab的model
201
+ index.value = curIndex
202
+ }
203
+ // 触发页面跳转
204
+ onTabChange(curIndex)
205
+ })
206
+ </script>
207
+
208
+ <template>
209
+ <fox-page :content-padding="contentPadding" ref="pageRef">
210
+ <fox-footer>
211
+ <fox-tabbar v-model="index" @change="onTabChange">
212
+ <template v-for="tab in tabs" :key="tab.title">
213
+ <fox-tabbar-item :title="tab.title" :icon="tab.icon"></fox-tabbar-item>
214
+ </template>
215
+ </fox-tabbar>
216
+ </fox-footer>
217
+ <fox-content ref="contentRef">
218
+ <fox-swiper-navigator
219
+ v-model:activePath="activeRoutePath"
220
+ :router-view-name="rootName"
221
+ :routes="routes"
222
+ :open-page="openPage"
223
+ :transition="true"
224
+ :width="contentWidth"
225
+ :height="contentHeight"
226
+ ></fox-swiper-navigator>
227
+ </fox-content>
228
+ </fox-page>
229
+ </template>
230
+
231
+ <style lang="scss" scoped></style>
232
+
233
+ ```
234
+
235
+ #### Props
236
+
237
+ | 字段 | 说明 | 类型 | 默认值 |
238
+ |------------------|----------------------------------------|---------|-----------|
239
+ | open-page | 打开页面方法 | Function | |
240
+ | router-view-name | router view名称 | String | `default` |
241
+ | routes | 路由列表 | Route[] | |
242
+ | active-path | 激活路径 | String | |
243
+ | height | 导航容器高度 | Number | |
244
+ | width | 导航容器宽度 | Number | |
245
+ | drag | 是否支持拖曳 | Boolean | |
246
+ | swipe-duration | 滑动页面动画时间 | Number ||
247
+ | scroll-time | 切换页面动画时间 | Number | |
248
+
249
+
250
+
251
+ ## 插槽
252
+
253
+ | 名称 | 说明 |
254
+ |---------|------------------|
255
+ | default | 内容 |
@@ -0,0 +1,3 @@
1
+ "use strict";/*!
2
+ * @fox-js/navigation v4.0.0 Mon Sep 26 2022 12:00:20 GMT+0800 (中国标准时间)
3
+ */const s=require("vue"),P=s.defineComponent({__name:"index",props:{routerViewName:null,transition:{type:[Object,Boolean],default:!1}},setup(t){const e=t;return(n,a)=>{const r=s.resolveComponent("fox-router-view");return s.openBlock(),s.createBlock(r,{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:e.transition,multi:!0,name:e.routerViewName},null,8,["transition","name"])}}});const O=Object.freeze(Object.defineProperty({__proto__:null,default:P},Symbol.toStringTag,{value:"Module"})),D=10;function I(t,e){return t>e&&t>D?"horizontal":e>t&&e>D?"vertical":""}function L(){const t=s.ref(0),e=s.ref(0),n=s.ref(0),a=s.ref(0),r=s.ref(0),p=s.ref(0),m=s.ref(0),g=s.ref(0),f=s.ref(0),l=s.ref(0),o=s.ref(""),i=()=>o.value==="vertical",h=()=>o.value==="horizontal",d=()=>{m.value=0,g.value=0,f.value=0,l.value=0,o.value="",n.value=0};return{move:c=>{const _=c.touches[0];m.value=_.clientX-t.value,g.value=_.clientY-e.value,r.value=_.clientX,p.value=_.clientY,f.value=Math.abs(m.value),l.value=Math.abs(g.value),a.value=Date.now()-n.value,o.value||(o.value=I(f.value,l.value))},start:c=>{d(),t.value=c.touches[0].clientX,e.value=c.touches[0].clientY,n.value=Date.now()},reset:d,startX:t,startY:e,startTime:n,duration:a,moveX:r,moveY:p,deltaX:m,deltaY:g,offsetX:f,offsetY:l,direction:o,isVertical:i,isHorizontal:h}}function C(t){return t===window}const S=t=>{const e=s.unref(t);if(C(e)){const n=e.innerWidth,a=e.innerHeight;return{top:0,left:0,right:n,bottom:a,width:n,height:a}}return e&&e.getBoundingClientRect?e.getBoundingClientRect():{top:0,left:0,right:0,bottom:0,width:0,height:0}},W=15,B=300,z=200;function N(t){t.stopPropagation()}function X(t,e){(typeof t.cancelable!="boolean"||t.cancelable)&&t.preventDefault(),e&&N(t)}function j(t,e){return t=Math.abs(t/e)/.003*(t<0?-1:1),t}function T(t,e=0,n,a=z){n==="end"?t.style.transition=`transform ${a}ms cubic-bezier(0.17, 0.89, 0.45, 1)`:t.style.transition="transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)",t.style.transform=`translate3d(${e}px, 0, 0)`}const y=new WeakMap;function k(t,e,n,a=1e3){const r={active:!0,startDistance:0,scrollDistance:0,scrollTime:0,moving:!1,transitionEndTrigger:null},p=t.previousSibling,m=L(),g=(h,d,v,u)=>{let c=d+r.startDistance;if(v==="end"){const _=S(h);let x=_.width/3;c<x?c=0:c=_.width,u&&u>0&&(r.transitionEndTrigger=()=>{r.moving=!1,n&&h.classList.remove(n)}),T(h,c,"end",u),p&&T(p,0,"",0),c>0&&typeof e=="function"&&e()}else c<0&&(c=0),T(h,c,"",0)},f=()=>{t.style.transform="",t.style.transition="",p&&(p.style.transform="",p.style.transition=""),r.transitionEndTrigger&&(r.transitionEndTrigger(),r.transitionEndTrigger=null)},l=h=>{if(m.start(h),r.moving){const d=t,{transform:v}=window.getComputedStyle(d);r.scrollDistance=+v.slice(7,v.length-1).split(", ")[5]}n&&t.classList.add(n),r.startDistance=r.scrollDistance,r.transitionEndTrigger=null,r.moving=!0},o=h=>{if(r.moving=!0,m.move(h),m.isVertical()){X(h,!0);return}g(t,m.deltaX.value,"",0)},i=()=>{const h=m.deltaX.value;if(h==0){n&&t.classList.remove(n);return}const d=m.duration.value;if(d<B&&Math.abs(h)>W){const u=j(h,d);g(t,u,"end",a)}else g(t,h,"end",a)};t.addEventListener("transitionend",f),t.addEventListener("touchstart",l),t.addEventListener("touchmove",o),t.addEventListener("touchend",i),t.addEventListener("touchcancel",i),y.set(t,{state:r,transitionend:f,touchstart:l,touchmove:o,touchend:i,touchcancel:i})}function A(t){const e=y.get(t);e&&(y.delete(t),t.addEventListener("transitionend",e.transitionend),t.addEventListener("touchstart",e.touchstart),t.addEventListener("touchmove",e.touchmove),t.addEventListener("touchend",e.touchend),t.addEventListener("touchcancel",e.touchcancel))}const U=s.defineComponent({__name:"index",props:{dragRemove:{type:Boolean,default:!0},removePage:null,routerViewName:null,viewTag:{default:"div"},transition:{type:[Object,Boolean],default:!0}},setup(t){const e=t;function n(l){return(l.params&&l.params.animationType)??"slide"}const a=(l,o,i,h)=>{if(i.opsType===3||o){const d=n(i);if(d==="pop"&&o)return;const v=o?"show":"enter",u=`fox-root-navigator__${d}-${v}-from`,c=`fox-root-navigator__${d}-${v}-active`;l.classList.add(u),l.classList.add(c)}},r=(l,o,i,h)=>{if(i.opsType===3||o){const d=n(i);if(d==="pop"&&o)return;const v=o?"show":"enter",u=`fox-root-navigator__${d}-${v}-from`,c=`fox-root-navigator__${d}-${v}-to`;l.classList.remove(u),l.classList.add(c)}},p=(l,o,i,h)=>{if(i.opsType===3||o){const d=n(i);if(d!=="pop"||!o){const v=o?"show":"enter",u=`fox-root-navigator__${d}-${v}-active`,c=`fox-root-navigator__${d}-${v}-to`;l.classList.remove(u),l.classList.remove(c)}}e.dragRemove&&!o&&i.opsType===3&&k(l,e.removePage,"fox-root-navigator__item-moving",1e3)},m=(l,o,i,h)=>{if(i.opsType===3||o){const d=n(i);if(d==="pop"&&o)return;const v=o?"hide":"leave",u=`fox-root-navigator__${d}-${v}-from`,c=`fox-root-navigator__${d}-${v}-active`;l.classList.add(u),l.classList.add(c)}},g=(l,o,i,h)=>{if(i.opsType===3||o){const d=n(i);if(d==="pop"&&o)return;const v=o?"hide":"leave",u=`fox-root-navigator__${d}-${v}-from`,c=`fox-root-navigator__${d}-${v}-to`;l.classList.remove(u),l.classList.add(c)}},f=(l,o,i,h)=>{if(i.opsType===3||o){const d=n(i);if(d!=="pop"||!o){const v=o?"hide":"leave",u=`fox-root-navigator__${d}-${v}-active`,c=`fox-root-navigator__${d}-${v}-to`;l.classList.remove(u),l.classList.remove(c)}}e.dragRemove&&!o&&A(l)};return(l,o)=>{const i=s.resolveComponent("fox-router-view");return s.openBlock(),s.createBlock(i,{class:"fox-root-navigator","view-class":"fox-root-navigator__item","before-enter":a,enter:r,"after-enter":p,"before-leave":m,leave:g,"after-leave":f,multi:!0,name:e.routerViewName,"view-tag":e.viewTag,transition:e.transition},null,8,["name","view-tag","transition"])}}});const V=Object.freeze(Object.defineProperty({__proto__:null,default:U},Symbol.toStringTag,{value:"Module"})),R={class:"fox-swiper-navigator"},Y=s.defineComponent({__name:"swiper",props:{width:null,scrollDistance:null,scrollTime:null},setup(t){const e=t,n=s.computed(()=>({transform:`translate3d(${e.scrollDistance}px, 0, 0)`,width:`${e.width}`}));return(a,r)=>(s.openBlock(),s.createElementBlock("div",R,[s.createElementVNode("div",{class:"fox-swiper-navigator__inner",style:s.normalizeStyle(s.unref(n))},[s.renderSlot(a.$slots,"default")],4)]))}});let q=0;function F(){return++q}const H=15,G=300,J=200;function K(t){t.stopPropagation()}function Q(t,e){(typeof t.cancelable!="boolean"||t.cancelable)&&t.preventDefault(),e&&K(t)}function Z(t,e){return t=Math.abs(t/e)/.003*(t<0?-1:1),t}function E(t,e=0,n,a=J){n==="end"?t.style.transition=`transform ${a}ms cubic-bezier(0.17, 0.89, 0.45, 1)`:t.style.transition="transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)",t.style.transform=`translate3d(${e}px, 0, 0)`}class tt{width=0;columnWidth=0;max=0;min=0;el=null;swipeDuration=360;transitionEndTrigger=null;moving=!1;startDistance=0;scrollDistance=0;getStartDistance;openPage;isPageOpened;pageOpened;transitionend=null;touchstart=null;touchmove=null;touchend=null;touchcancel=null;constructor(e,n,a,r){this.getStartDistance=e,this.openPage=n,this.isPageOpened=a,this.pageOpened=r}open(){const e=this.el,n=L(),a=(r,p,m,g)=>{let f=p+this.startDistance;const l=this.columnWidth/3;if(m==="end"){if(f==0){this.moving=!1;return}Math.abs(p)>l&&(p>0?f=this.startDistance+this.columnWidth:f=this.startDistance-this.columnWidth);let o=-f;o<0?o=0:o>this.width-this.columnWidth&&(o=this.width-this.columnWidth);const i=Math.floor(o/this.columnWidth);this.isPageOpened(i)||this.openPage(i),f=-i*this.columnWidth,g&&g>0&&(this.transitionEndTrigger=()=>{this.moving=!1,this.pageOpened(i)}),E(r,f,"end",g),this.scrollDistance=f}else{if(Math.abs(p)>l){let i=0;if(p>0?i=Math.abs(this.startDistance+this.columnWidth):i=Math.abs(this.startDistance-this.columnWidth),i>=0&&i<this.width){const h=Math.floor(i/this.columnWidth);this.isPageOpened(h)||this.openPage(h)}}let o=-f;o<this.min?o=this.min:o>this.max&&(o=this.max),E(r,-o,"",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=>{if(n.move(r),n.isVertical()){Q(r,!0);return}a(e,n.deltaX.value,"",0)},this.touchend=()=>{const r=n.deltaX.value;if(r==0)return;const p=n.duration.value;if(p<G&&Math.abs(r)>H){const g=Z(r,p);a(e,g,"end",this.swipeDuration)}else a(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 et(t,e,n,a){return new tt(t,e,n,a)}const nt=s.defineComponent({__name:"index",props:{activePath:null,routes:null,height:null,width:null,drag:{type:Boolean,default:!0},openPage:null,routerViewName:null,transition:{type:[Object,Boolean],default:!0},swipeDuration:{default:360},scrollTime:{default:0}},emits:["update:activePath"],setup(t,{emit:e}){const n=t,a=s.reactive({scrollDistance:0,index:-1,openedIndexList:[]}),f=et(()=>a.scrollDistance,u=>{if(a.openedIndexList.indexOf(u)===-1){a.openedIndexList.push(u);const c=n.routes[u];try{n.openPage(c,u)}catch(_){console.error(_)}}},u=>a.openedIndexList.indexOf(u)!==-1,u=>{a.index=u,a.scrollDistance=-a.index*n.width;const c=n.routes[u];e("update:activePath",c.path)});s.onMounted(()=>{const u=h();f.el=u,f.open()}),s.onUnmounted(()=>{f.close()}),s.watchEffect(()=>{const u=n.activePath;a.index=n.routes.findIndex(M=>M.path===u);const c=n.width;a.index!==-1&&(a.openedIndexList.push(a.index),a.scrollDistance=-c*a.index);const _=c*n.routes.length,x=-c/3,w=c*(n.routes.length-1)+c/3;f.columnWidth=c,f.width=_,f.min=x,f.max=w,f.swipeDuration=n.swipeDuration});const l=`fox-swiper-navigator-${F()}`,o=s.computed(()=>({width:`${n.width}px`,height:`${n.height}px`}));let i=null;function h(){return i||(i=document.querySelector(`.${l}>.fox-swiper-navigator__inner`),i)}const d=s.computed(()=>`${n.width*n.routes.length}px`),v=(u,c)=>({style:{left:`${n.routes.findIndex(x=>{const w=u.path??u.name??"";return x.path==w})*n.width}px`,width:`${n.width}px`}});return(u,c)=>{const _=s.resolveComponent("fox-router-view");return s.openBlock(),s.createBlock(_,{class:s.normalizeClass(l),style:s.normalizeStyle(s.unref(o)),"view-class":"fox-swiper-navigator__item",tag:Y,"view-tag-props":v,multi:!0,name:n.routerViewName,transition:n.transition,"scroll-distance":a.scrollDistance,"scroll-time":n.scrollTime,width:s.unref(d)},null,8,["style","name","transition","scroll-distance","scroll-time","width"])}}});const ot=Object.freeze(Object.defineProperty({__proto__:null,default:nt},Symbol.toStringTag,{value:"Module"}));let it="fox-";const st=[],$=Object.assign({"/src/components/card-navigator/index.vue":O,"/src/components/root-navigator/index.vue":V,"/src/components/swiper-navigator/index.vue":ot}),b=[];for(const t in $){let e=/src\/components\/(.*)\/index.vue/.exec(t)[1];st.indexOf(e)===-1&&b.push({name:e,component:$[t].default})}const at={install(t){b.forEach(e=>{t.component(`${it}${e.name}`,e.component)})}};module.exports=at;
@@ -0,0 +1,12 @@
1
+ import { App } from 'vue';
2
+
3
+ declare const _default: {
4
+ /**
5
+ * 安装
6
+ * @param app
7
+ */
8
+ install(app: App): void;
9
+ };
10
+ export default _default;
11
+
12
+ export { }
@@ -0,0 +1,468 @@
1
+ import { defineComponent as T, resolveComponent as b, openBlock as y, createBlock as M, ref as _, unref as w, computed as $, createElementBlock as z, createElementVNode as B, normalizeStyle as S, renderSlot as X, reactive as j, onMounted as A, onUnmounted as U, watchEffect as V, normalizeClass as R } from "vue";
2
+ /*!
3
+ * @fox-js/navigation v4.0.0 Mon Sep 26 2022 12:00:20 GMT+0800 (中国标准时间)
4
+ */
5
+ const Y = /* @__PURE__ */ T({
6
+ __name: "index",
7
+ props: {
8
+ routerViewName: null,
9
+ transition: { type: [Object, Boolean], default: !1 }
10
+ },
11
+ setup(t) {
12
+ const e = t;
13
+ return (n, s) => {
14
+ const a = b("fox-router-view");
15
+ return y(), M(a, {
16
+ class: "fox-card-navigator",
17
+ "view-class": "fox-card-navigator__item",
18
+ "view-active-class": "fox-card-navigator__item-active",
19
+ "view-inactive-class": "fox-card-navigator__item-inactive",
20
+ "transition-name": "fox-card-navigator__trans",
21
+ transition: e.transition,
22
+ multi: !0,
23
+ name: e.routerViewName
24
+ }, null, 8, ["transition", "name"]);
25
+ };
26
+ }
27
+ });
28
+ const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
29
+ __proto__: null,
30
+ default: Y
31
+ }, Symbol.toStringTag, { value: "Module" })), P = 10;
32
+ function q(t, e) {
33
+ return t > e && t > P ? "horizontal" : e > t && e > P ? "vertical" : "";
34
+ }
35
+ function W() {
36
+ const t = _(0), e = _(0), n = _(0), s = _(0), a = _(0), v = _(0), p = _(0), m = _(0), d = _(0), c = _(0), o = _(""), i = () => o.value === "vertical", h = () => o.value === "horizontal", u = () => {
37
+ p.value = 0, m.value = 0, d.value = 0, c.value = 0, o.value = "", n.value = 0;
38
+ };
39
+ return {
40
+ move: (r) => {
41
+ const g = r.touches[0];
42
+ p.value = g.clientX - t.value, m.value = g.clientY - e.value, a.value = g.clientX, v.value = g.clientY, d.value = Math.abs(p.value), c.value = Math.abs(m.value), s.value = Date.now() - n.value, o.value || (o.value = q(d.value, c.value));
43
+ },
44
+ start: (r) => {
45
+ u(), t.value = r.touches[0].clientX, e.value = r.touches[0].clientY, n.value = Date.now();
46
+ },
47
+ reset: u,
48
+ startX: t,
49
+ startY: e,
50
+ startTime: n,
51
+ duration: s,
52
+ moveX: a,
53
+ moveY: v,
54
+ deltaX: p,
55
+ deltaY: m,
56
+ offsetX: d,
57
+ offsetY: c,
58
+ direction: o,
59
+ isVertical: i,
60
+ isHorizontal: h
61
+ };
62
+ }
63
+ function F(t) {
64
+ return t === window;
65
+ }
66
+ const H = (t) => {
67
+ const e = w(t);
68
+ if (F(e)) {
69
+ const n = e.innerWidth, s = e.innerHeight;
70
+ return {
71
+ top: 0,
72
+ left: 0,
73
+ right: n,
74
+ bottom: s,
75
+ width: n,
76
+ height: s
77
+ };
78
+ }
79
+ return e && e.getBoundingClientRect ? e.getBoundingClientRect() : {
80
+ top: 0,
81
+ left: 0,
82
+ right: 0,
83
+ bottom: 0,
84
+ width: 0,
85
+ height: 0
86
+ };
87
+ }, G = 15, J = 300, K = 200;
88
+ function Q(t) {
89
+ t.stopPropagation();
90
+ }
91
+ function Z(t, e) {
92
+ (typeof t.cancelable != "boolean" || t.cancelable) && t.preventDefault(), e && Q(t);
93
+ }
94
+ function tt(t, e) {
95
+ return t = Math.abs(t / e) / 3e-3 * (t < 0 ? -1 : 1), t;
96
+ }
97
+ function E(t, e = 0, n, s = K) {
98
+ n === "end" ? t.style.transition = `transform ${s}ms cubic-bezier(0.17, 0.89, 0.45, 1)` : t.style.transition = "transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)", t.style.transform = `translate3d(${e}px, 0, 0)`;
99
+ }
100
+ const L = /* @__PURE__ */ new WeakMap();
101
+ function et(t, e, n, s = 1e3) {
102
+ const a = {
103
+ active: !0,
104
+ startDistance: 0,
105
+ scrollDistance: 0,
106
+ scrollTime: 0,
107
+ moving: !1,
108
+ transitionEndTrigger: null
109
+ }, v = t.previousSibling, p = W(), m = (h, u, f, l) => {
110
+ let r = u + a.startDistance;
111
+ if (f === "end") {
112
+ const g = H(h);
113
+ let x = g.width / 3;
114
+ r < x ? r = 0 : r = g.width, l && l > 0 && (a.transitionEndTrigger = () => {
115
+ a.moving = !1, n && h.classList.remove(n);
116
+ }), E(h, r, "end", l), v && E(v, 0, "", 0), r > 0 && typeof e == "function" && e();
117
+ } else
118
+ r < 0 && (r = 0), E(h, r, "", 0);
119
+ }, d = () => {
120
+ t.style.transform = "", t.style.transition = "", v && (v.style.transform = "", v.style.transition = ""), a.transitionEndTrigger && (a.transitionEndTrigger(), a.transitionEndTrigger = null);
121
+ }, c = (h) => {
122
+ if (p.start(h), a.moving) {
123
+ const u = t, { transform: f } = window.getComputedStyle(u);
124
+ a.scrollDistance = +f.slice(7, f.length - 1).split(", ")[5];
125
+ }
126
+ n && t.classList.add(n), a.startDistance = a.scrollDistance, a.transitionEndTrigger = null, a.moving = !0;
127
+ }, o = (h) => {
128
+ if (a.moving = !0, p.move(h), p.isVertical()) {
129
+ Z(h, !0);
130
+ return;
131
+ }
132
+ m(t, p.deltaX.value, "", 0);
133
+ }, i = () => {
134
+ const h = p.deltaX.value;
135
+ if (h == 0) {
136
+ n && t.classList.remove(n);
137
+ return;
138
+ }
139
+ const u = p.duration.value;
140
+ if (u < J && Math.abs(h) > G) {
141
+ const l = tt(h, u);
142
+ m(t, l, "end", s);
143
+ } else
144
+ m(t, h, "end", s);
145
+ };
146
+ t.addEventListener("transitionend", d), t.addEventListener("touchstart", c), t.addEventListener("touchmove", o), t.addEventListener("touchend", i), t.addEventListener("touchcancel", i), L.set(t, {
147
+ state: a,
148
+ transitionend: d,
149
+ touchstart: c,
150
+ touchmove: o,
151
+ touchend: i,
152
+ touchcancel: i
153
+ });
154
+ }
155
+ function nt(t) {
156
+ const e = L.get(t);
157
+ e && (L.delete(t), t.addEventListener("transitionend", e.transitionend), t.addEventListener("touchstart", e.touchstart), t.addEventListener("touchmove", e.touchmove), t.addEventListener("touchend", e.touchend), t.addEventListener("touchcancel", e.touchcancel));
158
+ }
159
+ const ot = /* @__PURE__ */ T({
160
+ __name: "index",
161
+ props: {
162
+ dragRemove: { type: Boolean, default: !0 },
163
+ removePage: null,
164
+ routerViewName: null,
165
+ viewTag: { default: "div" },
166
+ transition: { type: [Object, Boolean], default: !0 }
167
+ },
168
+ setup(t) {
169
+ const e = t;
170
+ function n(c) {
171
+ return (c.params && c.params.animationType) ?? "slide";
172
+ }
173
+ const s = (c, o, i, h) => {
174
+ if (i.opsType === 3 || o) {
175
+ const u = n(i);
176
+ if (u === "pop" && o)
177
+ return;
178
+ const f = o ? "show" : "enter", l = `fox-root-navigator__${u}-${f}-from`, r = `fox-root-navigator__${u}-${f}-active`;
179
+ c.classList.add(l), c.classList.add(r);
180
+ }
181
+ }, a = (c, o, i, h) => {
182
+ if (i.opsType === 3 || o) {
183
+ const u = n(i);
184
+ if (u === "pop" && o)
185
+ return;
186
+ const f = o ? "show" : "enter", l = `fox-root-navigator__${u}-${f}-from`, r = `fox-root-navigator__${u}-${f}-to`;
187
+ c.classList.remove(l), c.classList.add(r);
188
+ }
189
+ }, v = (c, o, i, h) => {
190
+ if (i.opsType === 3 || o) {
191
+ const u = n(i);
192
+ if (u !== "pop" || !o) {
193
+ const f = o ? "show" : "enter", l = `fox-root-navigator__${u}-${f}-active`, r = `fox-root-navigator__${u}-${f}-to`;
194
+ c.classList.remove(l), c.classList.remove(r);
195
+ }
196
+ }
197
+ e.dragRemove && !o && i.opsType === 3 && et(c, e.removePage, "fox-root-navigator__item-moving", 1e3);
198
+ }, p = (c, o, i, h) => {
199
+ if (i.opsType === 3 || o) {
200
+ const u = n(i);
201
+ if (u === "pop" && o)
202
+ return;
203
+ const f = o ? "hide" : "leave", l = `fox-root-navigator__${u}-${f}-from`, r = `fox-root-navigator__${u}-${f}-active`;
204
+ c.classList.add(l), c.classList.add(r);
205
+ }
206
+ }, m = (c, o, i, h) => {
207
+ if (i.opsType === 3 || o) {
208
+ const u = n(i);
209
+ if (u === "pop" && o)
210
+ return;
211
+ const f = o ? "hide" : "leave", l = `fox-root-navigator__${u}-${f}-from`, r = `fox-root-navigator__${u}-${f}-to`;
212
+ c.classList.remove(l), c.classList.add(r);
213
+ }
214
+ }, d = (c, o, i, h) => {
215
+ if (i.opsType === 3 || o) {
216
+ const u = n(i);
217
+ if (u !== "pop" || !o) {
218
+ const f = o ? "hide" : "leave", l = `fox-root-navigator__${u}-${f}-active`, r = `fox-root-navigator__${u}-${f}-to`;
219
+ c.classList.remove(l), c.classList.remove(r);
220
+ }
221
+ }
222
+ e.dragRemove && !o && nt(c);
223
+ };
224
+ return (c, o) => {
225
+ const i = b("fox-router-view");
226
+ return y(), M(i, {
227
+ class: "fox-root-navigator",
228
+ "view-class": "fox-root-navigator__item",
229
+ "before-enter": s,
230
+ enter: a,
231
+ "after-enter": v,
232
+ "before-leave": p,
233
+ leave: m,
234
+ "after-leave": d,
235
+ multi: !0,
236
+ name: e.routerViewName,
237
+ "view-tag": e.viewTag,
238
+ transition: e.transition
239
+ }, null, 8, ["name", "view-tag", "transition"]);
240
+ };
241
+ }
242
+ });
243
+ const it = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
244
+ __proto__: null,
245
+ default: ot
246
+ }, Symbol.toStringTag, { value: "Module" })), st = { class: "fox-swiper-navigator" }, at = /* @__PURE__ */ T({
247
+ __name: "swiper",
248
+ props: {
249
+ width: null,
250
+ scrollDistance: null,
251
+ scrollTime: null
252
+ },
253
+ setup(t) {
254
+ const e = t, n = $(() => ({
255
+ transform: `translate3d(${e.scrollDistance}px, 0, 0)`,
256
+ width: `${e.width}`
257
+ }));
258
+ return (s, a) => (y(), z("div", st, [
259
+ B("div", {
260
+ class: "fox-swiper-navigator__inner",
261
+ style: S(w(n))
262
+ }, [
263
+ X(s.$slots, "default")
264
+ ], 4)
265
+ ]));
266
+ }
267
+ });
268
+ let rt = 0;
269
+ function ct() {
270
+ return ++rt;
271
+ }
272
+ const lt = 15, ut = 300, dt = 200;
273
+ function ht(t) {
274
+ t.stopPropagation();
275
+ }
276
+ function ft(t, e) {
277
+ (typeof t.cancelable != "boolean" || t.cancelable) && t.preventDefault(), e && ht(t);
278
+ }
279
+ function vt(t, e) {
280
+ return t = Math.abs(t / e) / 3e-3 * (t < 0 ? -1 : 1), t;
281
+ }
282
+ function O(t, e = 0, n, s = dt) {
283
+ n === "end" ? t.style.transition = `transform ${s}ms cubic-bezier(0.17, 0.89, 0.45, 1)` : t.style.transition = "transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)", t.style.transform = `translate3d(${e}px, 0, 0)`;
284
+ }
285
+ class pt {
286
+ width = 0;
287
+ columnWidth = 0;
288
+ max = 0;
289
+ min = 0;
290
+ el = null;
291
+ swipeDuration = 360;
292
+ transitionEndTrigger = null;
293
+ moving = !1;
294
+ startDistance = 0;
295
+ scrollDistance = 0;
296
+ getStartDistance;
297
+ openPage;
298
+ isPageOpened;
299
+ pageOpened;
300
+ transitionend = null;
301
+ touchstart = null;
302
+ touchmove = null;
303
+ touchend = null;
304
+ touchcancel = null;
305
+ constructor(e, n, s, a) {
306
+ this.getStartDistance = e, this.openPage = n, this.isPageOpened = s, this.pageOpened = a;
307
+ }
308
+ open() {
309
+ const e = this.el, n = W(), s = (a, v, p, m) => {
310
+ let d = v + this.startDistance;
311
+ const c = this.columnWidth / 3;
312
+ if (p === "end") {
313
+ if (d == 0) {
314
+ this.moving = !1;
315
+ return;
316
+ }
317
+ Math.abs(v) > c && (v > 0 ? d = this.startDistance + this.columnWidth : d = this.startDistance - this.columnWidth);
318
+ let o = -d;
319
+ o < 0 ? o = 0 : o > this.width - this.columnWidth && (o = this.width - this.columnWidth);
320
+ const i = Math.floor(o / this.columnWidth);
321
+ this.isPageOpened(i) || this.openPage(i), d = -i * this.columnWidth, m && m > 0 && (this.transitionEndTrigger = () => {
322
+ this.moving = !1, this.pageOpened(i);
323
+ }), O(a, d, "end", m), this.scrollDistance = d;
324
+ } else {
325
+ if (Math.abs(v) > c) {
326
+ let i = 0;
327
+ if (v > 0 ? i = Math.abs(this.startDistance + this.columnWidth) : i = Math.abs(this.startDistance - this.columnWidth), i >= 0 && i < this.width) {
328
+ const h = Math.floor(i / this.columnWidth);
329
+ this.isPageOpened(h) || this.openPage(h);
330
+ }
331
+ }
332
+ let o = -d;
333
+ o < this.min ? o = this.min : o > this.max && (o = this.max), O(a, -o, "", 0);
334
+ }
335
+ };
336
+ this.transitionend = () => {
337
+ e.style.transition = "", this.transitionEndTrigger && (this.transitionEndTrigger(), this.transitionEndTrigger = null);
338
+ }, this.touchstart = (a) => {
339
+ this.moving || (n.start(a), this.startDistance = this.getStartDistance(), this.transitionEndTrigger = null, this.moving = !0);
340
+ }, this.touchmove = (a) => {
341
+ if (n.move(a), n.isVertical()) {
342
+ ft(a, !0);
343
+ return;
344
+ }
345
+ s(e, n.deltaX.value, "", 0);
346
+ }, this.touchend = () => {
347
+ const a = n.deltaX.value;
348
+ if (a == 0)
349
+ return;
350
+ const v = n.duration.value;
351
+ if (v < ut && Math.abs(a) > lt) {
352
+ const m = vt(a, v);
353
+ s(e, m, "end", this.swipeDuration);
354
+ } else
355
+ s(e, a, "end", this.swipeDuration);
356
+ }, 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);
357
+ }
358
+ close() {
359
+ const e = this.el;
360
+ 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;
361
+ }
362
+ }
363
+ function mt(t, e, n, s) {
364
+ return new pt(t, e, n, s);
365
+ }
366
+ const gt = /* @__PURE__ */ T({
367
+ __name: "index",
368
+ props: {
369
+ activePath: null,
370
+ routes: null,
371
+ height: null,
372
+ width: null,
373
+ drag: { type: Boolean, default: !0 },
374
+ openPage: null,
375
+ routerViewName: null,
376
+ transition: { type: [Object, Boolean], default: !0 },
377
+ swipeDuration: { default: 360 },
378
+ scrollTime: { default: 0 }
379
+ },
380
+ emits: ["update:activePath"],
381
+ setup(t, { emit: e }) {
382
+ const n = t, s = j({
383
+ scrollDistance: 0,
384
+ index: -1,
385
+ openedIndexList: []
386
+ }), d = mt(() => s.scrollDistance, (l) => {
387
+ if (s.openedIndexList.indexOf(l) === -1) {
388
+ s.openedIndexList.push(l);
389
+ const r = n.routes[l];
390
+ try {
391
+ n.openPage(r, l);
392
+ } catch (g) {
393
+ console.error(g);
394
+ }
395
+ }
396
+ }, (l) => s.openedIndexList.indexOf(l) !== -1, (l) => {
397
+ s.index = l, s.scrollDistance = -s.index * n.width;
398
+ const r = n.routes[l];
399
+ e("update:activePath", r.path);
400
+ });
401
+ A(() => {
402
+ const l = h();
403
+ d.el = l, d.open();
404
+ }), U(() => {
405
+ d.close();
406
+ }), V(() => {
407
+ const l = n.activePath;
408
+ s.index = n.routes.findIndex((N) => N.path === l);
409
+ const r = n.width;
410
+ s.index !== -1 && (s.openedIndexList.push(s.index), s.scrollDistance = -r * s.index);
411
+ const g = r * n.routes.length, x = -r / 3, D = r * (n.routes.length - 1) + r / 3;
412
+ d.columnWidth = r, d.width = g, d.min = x, d.max = D, d.swipeDuration = n.swipeDuration;
413
+ });
414
+ const c = `fox-swiper-navigator-${ct()}`, o = $(() => ({ width: `${n.width}px`, height: `${n.height}px` }));
415
+ let i = null;
416
+ function h() {
417
+ return i || (i = document.querySelector(`.${c}>.fox-swiper-navigator__inner`), i);
418
+ }
419
+ const u = $(() => `${n.width * n.routes.length}px`), f = (l, r) => ({
420
+ style: {
421
+ left: `${n.routes.findIndex((x) => {
422
+ const D = l.path ?? l.name ?? "";
423
+ return x.path == D;
424
+ }) * n.width}px`,
425
+ width: `${n.width}px`
426
+ }
427
+ });
428
+ return (l, r) => {
429
+ const g = b("fox-router-view");
430
+ return y(), M(g, {
431
+ class: R(c),
432
+ style: S(w(o)),
433
+ "view-class": "fox-swiper-navigator__item",
434
+ tag: at,
435
+ "view-tag-props": f,
436
+ multi: !0,
437
+ name: n.routerViewName,
438
+ transition: n.transition,
439
+ "scroll-distance": s.scrollDistance,
440
+ "scroll-time": n.scrollTime,
441
+ width: w(u)
442
+ }, null, 8, ["style", "name", "transition", "scroll-distance", "scroll-time", "width"]);
443
+ };
444
+ }
445
+ });
446
+ const _t = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
447
+ __proto__: null,
448
+ default: gt
449
+ }, Symbol.toStringTag, { value: "Module" }));
450
+ let xt = "fox-";
451
+ const wt = [], I = /* @__PURE__ */ Object.assign({ "/src/components/card-navigator/index.vue": k, "/src/components/root-navigator/index.vue": it, "/src/components/swiper-navigator/index.vue": _t }), C = [];
452
+ for (const t in I) {
453
+ let e = /src\/components\/(.*)\/index.vue/.exec(t)[1];
454
+ wt.indexOf(e) === -1 && C.push({
455
+ name: e,
456
+ component: I[t].default
457
+ });
458
+ }
459
+ const yt = {
460
+ install(t) {
461
+ C.forEach((e) => {
462
+ t.component(`${xt}${e.name}`, e.component);
463
+ });
464
+ }
465
+ };
466
+ export {
467
+ yt as default
468
+ };
@@ -0,0 +1,3 @@
1
+ (function(i,x){typeof exports=="object"&&typeof module<"u"?module.exports=x(require("vue")):typeof define=="function"&&define.amd?define(["vue"],x):(i=typeof globalThis<"u"?globalThis:i||self,i.navigation=x(i.Vue))})(this,function(i){"use strict";/*!
2
+ * @fox-js/navigation v4.0.0 Mon Sep 26 2022 12:00:20 GMT+0800 (中国标准时间)
3
+ */const x=i.defineComponent({__name:"index",props:{routerViewName:null,transition:{type:[Object,Boolean],default:!1}},setup(t){const e=t;return(n,a)=>{const r=i.resolveComponent("fox-router-view");return i.openBlock(),i.createBlock(r,{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:e.transition,multi:!0,name:e.routerViewName},null,8,["transition","name"])}}}),at="",P=Object.freeze(Object.defineProperty({__proto__:null,default:x},Symbol.toStringTag,{value:"Module"})),E=10;function O(t,e){return t>e&&t>E?"horizontal":e>t&&e>E?"vertical":""}function $(){const t=i.ref(0),e=i.ref(0),n=i.ref(0),a=i.ref(0),r=i.ref(0),m=i.ref(0),g=i.ref(0),v=i.ref(0),f=i.ref(0),l=i.ref(0),o=i.ref(""),s=()=>o.value==="vertical",h=()=>o.value==="horizontal",d=()=>{g.value=0,v.value=0,f.value=0,l.value=0,o.value="",n.value=0};return{move:c=>{const _=c.touches[0];g.value=_.clientX-t.value,v.value=_.clientY-e.value,r.value=_.clientX,m.value=_.clientY,f.value=Math.abs(g.value),l.value=Math.abs(v.value),a.value=Date.now()-n.value,o.value||(o.value=O(f.value,l.value))},start:c=>{d(),t.value=c.touches[0].clientX,e.value=c.touches[0].clientY,n.value=Date.now()},reset:d,startX:t,startY:e,startTime:n,duration:a,moveX:r,moveY:m,deltaX:g,deltaY:v,offsetX:f,offsetY:l,direction:o,isVertical:s,isHorizontal:h}}function I(t){return t===window}const C=t=>{const e=i.unref(t);if(I(e)){const n=e.innerWidth,a=e.innerHeight;return{top:0,left:0,right:n,bottom:a,width:n,height:a}}return e&&e.getBoundingClientRect?e.getBoundingClientRect():{top:0,left:0,right:0,bottom:0,width:0,height:0}},S=15,W=300,B=200;function z(t){t.stopPropagation()}function N(t,e){(typeof t.cancelable!="boolean"||t.cancelable)&&t.preventDefault(),e&&z(t)}function j(t,e){return t=Math.abs(t/e)/.003*(t<0?-1:1),t}function T(t,e=0,n,a=B){n==="end"?t.style.transition=`transform ${a}ms cubic-bezier(0.17, 0.89, 0.45, 1)`:t.style.transition="transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)",t.style.transform=`translate3d(${e}px, 0, 0)`}const y=new WeakMap;function V(t,e,n,a=1e3){const r={active:!0,startDistance:0,scrollDistance:0,scrollTime:0,moving:!1,transitionEndTrigger:null},m=t.previousSibling,g=$(),v=(h,d,p,u)=>{let c=d+r.startDistance;if(p==="end"){const _=C(h);let w=_.width/3;c<w?c=0:c=_.width,u&&u>0&&(r.transitionEndTrigger=()=>{r.moving=!1,n&&h.classList.remove(n)}),T(h,c,"end",u),m&&T(m,0,"",0),c>0&&typeof e=="function"&&e()}else c<0&&(c=0),T(h,c,"",0)},f=()=>{t.style.transform="",t.style.transition="",m&&(m.style.transform="",m.style.transition=""),r.transitionEndTrigger&&(r.transitionEndTrigger(),r.transitionEndTrigger=null)},l=h=>{if(g.start(h),r.moving){const d=t,{transform:p}=window.getComputedStyle(d);r.scrollDistance=+p.slice(7,p.length-1).split(", ")[5]}n&&t.classList.add(n),r.startDistance=r.scrollDistance,r.transitionEndTrigger=null,r.moving=!0},o=h=>{if(r.moving=!0,g.move(h),g.isVertical()){N(h,!0);return}v(t,g.deltaX.value,"",0)},s=()=>{const h=g.deltaX.value;if(h==0){n&&t.classList.remove(n);return}const d=g.duration.value;if(d<W&&Math.abs(h)>S){const u=j(h,d);v(t,u,"end",a)}else v(t,h,"end",a)};t.addEventListener("transitionend",f),t.addEventListener("touchstart",l),t.addEventListener("touchmove",o),t.addEventListener("touchend",s),t.addEventListener("touchcancel",s),y.set(t,{state:r,transitionend:f,touchstart:l,touchmove:o,touchend:s,touchcancel:s})}function X(t){const e=y.get(t);e&&(y.delete(t),t.addEventListener("transitionend",e.transitionend),t.addEventListener("touchstart",e.touchstart),t.addEventListener("touchmove",e.touchmove),t.addEventListener("touchend",e.touchend),t.addEventListener("touchcancel",e.touchcancel))}const k=i.defineComponent({__name:"index",props:{dragRemove:{type:Boolean,default:!0},removePage:null,routerViewName:null,viewTag:{default:"div"},transition:{type:[Object,Boolean],default:!0}},setup(t){const e=t;function n(l){return(l.params&&l.params.animationType)??"slide"}const a=(l,o,s,h)=>{if(s.opsType===3||o){const d=n(s);if(d==="pop"&&o)return;const p=o?"show":"enter",u=`fox-root-navigator__${d}-${p}-from`,c=`fox-root-navigator__${d}-${p}-active`;l.classList.add(u),l.classList.add(c)}},r=(l,o,s,h)=>{if(s.opsType===3||o){const d=n(s);if(d==="pop"&&o)return;const p=o?"show":"enter",u=`fox-root-navigator__${d}-${p}-from`,c=`fox-root-navigator__${d}-${p}-to`;l.classList.remove(u),l.classList.add(c)}},m=(l,o,s,h)=>{if(s.opsType===3||o){const d=n(s);if(d!=="pop"||!o){const p=o?"show":"enter",u=`fox-root-navigator__${d}-${p}-active`,c=`fox-root-navigator__${d}-${p}-to`;l.classList.remove(u),l.classList.remove(c)}}e.dragRemove&&!o&&s.opsType===3&&V(l,e.removePage,"fox-root-navigator__item-moving",1e3)},g=(l,o,s,h)=>{if(s.opsType===3||o){const d=n(s);if(d==="pop"&&o)return;const p=o?"hide":"leave",u=`fox-root-navigator__${d}-${p}-from`,c=`fox-root-navigator__${d}-${p}-active`;l.classList.add(u),l.classList.add(c)}},v=(l,o,s,h)=>{if(s.opsType===3||o){const d=n(s);if(d==="pop"&&o)return;const p=o?"hide":"leave",u=`fox-root-navigator__${d}-${p}-from`,c=`fox-root-navigator__${d}-${p}-to`;l.classList.remove(u),l.classList.add(c)}},f=(l,o,s,h)=>{if(s.opsType===3||o){const d=n(s);if(d!=="pop"||!o){const p=o?"hide":"leave",u=`fox-root-navigator__${d}-${p}-active`,c=`fox-root-navigator__${d}-${p}-to`;l.classList.remove(u),l.classList.remove(c)}}e.dragRemove&&!o&&X(l)};return(l,o)=>{const s=i.resolveComponent("fox-router-view");return i.openBlock(),i.createBlock(s,{class:"fox-root-navigator","view-class":"fox-root-navigator__item","before-enter":a,enter:r,"after-enter":m,"before-leave":g,leave:v,"after-leave":f,multi:!0,name:e.routerViewName,"view-tag":e.viewTag,transition:e.transition},null,8,["name","view-tag","transition"])}}}),rt="",A=Object.freeze(Object.defineProperty({__proto__:null,default:k},Symbol.toStringTag,{value:"Module"})),U={class:"fox-swiper-navigator"},R=i.defineComponent({__name:"swiper",props:{width:null,scrollDistance:null,scrollTime:null},setup(t){const e=t,n=i.computed(()=>({transform:`translate3d(${e.scrollDistance}px, 0, 0)`,width:`${e.width}`}));return(a,r)=>(i.openBlock(),i.createElementBlock("div",U,[i.createElementVNode("div",{class:"fox-swiper-navigator__inner",style:i.normalizeStyle(i.unref(n))},[i.renderSlot(a.$slots,"default")],4)]))}});let Y=0;function q(){return++Y}const F=15,H=300,G=200;function J(t){t.stopPropagation()}function K(t,e){(typeof t.cancelable!="boolean"||t.cancelable)&&t.preventDefault(),e&&J(t)}function Q(t,e){return t=Math.abs(t/e)/.003*(t<0?-1:1),t}function L(t,e=0,n,a=G){n==="end"?t.style.transition=`transform ${a}ms cubic-bezier(0.17, 0.89, 0.45, 1)`:t.style.transition="transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)",t.style.transform=`translate3d(${e}px, 0, 0)`}class Z{width=0;columnWidth=0;max=0;min=0;el=null;swipeDuration=360;transitionEndTrigger=null;moving=!1;startDistance=0;scrollDistance=0;getStartDistance;openPage;isPageOpened;pageOpened;transitionend=null;touchstart=null;touchmove=null;touchend=null;touchcancel=null;constructor(e,n,a,r){this.getStartDistance=e,this.openPage=n,this.isPageOpened=a,this.pageOpened=r}open(){const e=this.el,n=$(),a=(r,m,g,v)=>{let f=m+this.startDistance;const l=this.columnWidth/3;if(g==="end"){if(f==0){this.moving=!1;return}Math.abs(m)>l&&(m>0?f=this.startDistance+this.columnWidth:f=this.startDistance-this.columnWidth);let o=-f;o<0?o=0:o>this.width-this.columnWidth&&(o=this.width-this.columnWidth);const s=Math.floor(o/this.columnWidth);this.isPageOpened(s)||this.openPage(s),f=-s*this.columnWidth,v&&v>0&&(this.transitionEndTrigger=()=>{this.moving=!1,this.pageOpened(s)}),L(r,f,"end",v),this.scrollDistance=f}else{if(Math.abs(m)>l){let s=0;if(m>0?s=Math.abs(this.startDistance+this.columnWidth):s=Math.abs(this.startDistance-this.columnWidth),s>=0&&s<this.width){const h=Math.floor(s/this.columnWidth);this.isPageOpened(h)||this.openPage(h)}}let o=-f;o<this.min?o=this.min:o>this.max&&(o=this.max),L(r,-o,"",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=>{if(n.move(r),n.isVertical()){K(r,!0);return}a(e,n.deltaX.value,"",0)},this.touchend=()=>{const r=n.deltaX.value;if(r==0)return;const m=n.duration.value;if(m<H&&Math.abs(r)>F){const v=Q(r,m);a(e,v,"end",this.swipeDuration)}else a(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 tt(t,e,n,a){return new Z(t,e,n,a)}const et=i.defineComponent({__name:"index",props:{activePath:null,routes:null,height:null,width:null,drag:{type:Boolean,default:!0},openPage:null,routerViewName:null,transition:{type:[Object,Boolean],default:!0},swipeDuration:{default:360},scrollTime:{default:0}},emits:["update:activePath"],setup(t,{emit:e}){const n=t,a=i.reactive({scrollDistance:0,index:-1,openedIndexList:[]}),f=tt(()=>a.scrollDistance,u=>{if(a.openedIndexList.indexOf(u)===-1){a.openedIndexList.push(u);const c=n.routes[u];try{n.openPage(c,u)}catch(_){console.error(_)}}},u=>a.openedIndexList.indexOf(u)!==-1,u=>{a.index=u,a.scrollDistance=-a.index*n.width;const c=n.routes[u];e("update:activePath",c.path)});i.onMounted(()=>{const u=h();f.el=u,f.open()}),i.onUnmounted(()=>{f.close()}),i.watchEffect(()=>{const u=n.activePath;a.index=n.routes.findIndex(st=>st.path===u);const c=n.width;a.index!==-1&&(a.openedIndexList.push(a.index),a.scrollDistance=-c*a.index);const _=c*n.routes.length,w=-c/3,D=c*(n.routes.length-1)+c/3;f.columnWidth=c,f.width=_,f.min=w,f.max=D,f.swipeDuration=n.swipeDuration});const l=`fox-swiper-navigator-${q()}`,o=i.computed(()=>({width:`${n.width}px`,height:`${n.height}px`}));let s=null;function h(){return s||(s=document.querySelector(`.${l}>.fox-swiper-navigator__inner`),s)}const d=i.computed(()=>`${n.width*n.routes.length}px`),p=(u,c)=>({style:{left:`${n.routes.findIndex(w=>{const D=u.path??u.name??"";return w.path==D})*n.width}px`,width:`${n.width}px`}});return(u,c)=>{const _=i.resolveComponent("fox-router-view");return i.openBlock(),i.createBlock(_,{class:i.normalizeClass(l),style:i.normalizeStyle(i.unref(o)),"view-class":"fox-swiper-navigator__item",tag:R,"view-tag-props":p,multi:!0,name:n.routerViewName,transition:n.transition,"scroll-distance":a.scrollDistance,"scroll-time":n.scrollTime,width:i.unref(d)},null,8,["style","name","transition","scroll-distance","scroll-time","width"])}}}),ct="",nt=Object.freeze(Object.defineProperty({__proto__:null,default:et},Symbol.toStringTag,{value:"Module"}));let ot="fox-";const it=[],b=Object.assign({"/src/components/card-navigator/index.vue":P,"/src/components/root-navigator/index.vue":A,"/src/components/swiper-navigator/index.vue":nt}),M=[];for(const t in b){let e=/src\/components\/(.*)\/index.vue/.exec(t)[1];it.indexOf(e)===-1&&M.push({name:e,component:b[t].default})}return{install(t){M.forEach(e=>{t.component(`${ot}${e.name}`,e.component)})}}});
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ .fox-card-navigator{position:relative;overflow:hidden;width:100%}.fox-card-navigator__item{position:fixed;width:100%}.fox-card-navigator__item-active{z-index:1}.fox-card-navigator__item-inactive{display:none;z-index:0}.fox-card-navigator__trans-enter-from,.fox-card-navigator__trans-show-from{-webkit-transform:translate3d(50%,0%,0);transform:translate3d(50%,0,0)}.fox-card-navigator__trans-enter-to,.fox-card-navigator__trans-show-to{-webkit-transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1),-webkit-transform .36s cubic-bezier(.17,.89,.45,1);-webkit-transform:translate3d(0%,0,0);transform:translateZ(0)}.fox-card-navigator__trans-hide-active{position:absolute;display:block}.fox-card-navigator__trans-leave-to,.fox-card-navigator__trans-hide-to{-webkit-transition:opacity .36s cubic-bezier(.17,.89,.45,1);transition:opacity .36s cubic-bezier(.17,.89,.45,1);opacity:0}.fox-root-navigator{position:relative;overflow:hidden;width:100%}.fox-root-navigator__item{position:fixed;left:0;top:0;width:100%;z-index:120;-webkit-box-sizing:border-box;box-sizing:border-box}.fox-root-navigator__item-moving{-webkit-box-shadow:0 4px 8px 0 rgba(0,0,0,.2),0 6px 20px 0 rgba(0,0,0,.19);box-shadow:0 4px 8px #0003,0 6px 20px #00000030}.fox-root-navigator__slide-enter-from{-webkit-transform:translate3d(103%,0,0);transform:translate3d(103%,0,0)}.fox-root-navigator__slide-enter-active{-webkit-transition:-webkit-transform .3s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .3s cubic-bezier(.17,.89,.45,1);transition:transform .3s cubic-bezier(.17,.89,.45,1);transition:transform .3s cubic-bezier(.17,.89,.45,1),-webkit-transform .3s cubic-bezier(.17,.89,.45,1)}.fox-root-navigator__slide-enter-to{-webkit-transform:translate3d(0,0,0);transform:translateZ(0)}.fox-root-navigator__slide-leave-to{-webkit-transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1),-webkit-transform .36s cubic-bezier(.17,.89,.45,1);-webkit-transform:translate3d(103%,0,0);transform:translate3d(103%,0,0)}.fox-root-navigator__slide-show-from{-webkit-transform:translate3d(-50%,0%,0);transform:translate3d(-50%,0,0)}.fox-root-navigator__slide-show-to{-webkit-transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1),-webkit-transform .36s cubic-bezier(.17,.89,.45,1);-webkit-transform:translate3d(0%,0,0);transform:translateZ(0)}.fox-root-navigator__slide-hide-from{-webkit-transform:translate3d(0%,0%,0);transform:translateZ(0)}.fox-root-navigator__slide-hide-to{-webkit-transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1),-webkit-transform .36s cubic-bezier(.17,.89,.45,1);-webkit-transform:translate3d(-50%,0,0);transform:translate3d(-50%,0,0)}.fox-root-navigator__pop-enter-from{-webkit-transform:translate3d(0,103%,0);transform:translate3d(0,103%,0)}.fox-root-navigator__pop-enter-active{-webkit-transition:-webkit-transform .3s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .3s cubic-bezier(.17,.89,.45,1);transition:transform .3s cubic-bezier(.17,.89,.45,1);transition:transform .3s cubic-bezier(.17,.89,.45,1),-webkit-transform .3s cubic-bezier(.17,.89,.45,1)}.fox-root-navigator__pop-enter-to{-webkit-transform:translate3d(0,0,0);transform:translateZ(0)}.fox-root-navigator__pop-leave-to{-webkit-transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1),-webkit-transform .36s cubic-bezier(.17,.89,.45,1);-webkit-transform:translate3d(0,103%,0);transform:translate3d(0,103%,0)}.fox-swiper-navigator{position:relative;overflow:hidden;width:100%}.fox-swiper-navigator__item,.fox-swiper-navigator__inner{position:absolute;top:0;bottom:0}.fox-swiper-navigator__slide-enter-from{-webkit-transform:translate3d(103%,0,0);transform:translate3d(103%,0,0)}.fox-swiper-navigator__slide-enter-active{-webkit-transition:-webkit-transform .3s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .3s cubic-bezier(.17,.89,.45,1);transition:transform .3s cubic-bezier(.17,.89,.45,1);transition:transform .3s cubic-bezier(.17,.89,.45,1),-webkit-transform .3s cubic-bezier(.17,.89,.45,1)}.fox-swiper-navigator__slide-enter-to{-webkit-transform:translate3d(0,0,0);transform:translateZ(0)}.fox-swiper-navigator__slide-leave-to{-webkit-transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1),-webkit-transform .36s cubic-bezier(.17,.89,.45,1);-webkit-transform:translate3d(103%,0,0);transform:translate3d(103%,0,0)}.fox-swiper-navigator__slide-show-from{-webkit-transform:translate3d(-50%,0%,0);transform:translate3d(-50%,0,0)}.fox-swiper-navigator__slide-show-to{-webkit-transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1),-webkit-transform .36s cubic-bezier(.17,.89,.45,1);-webkit-transform:translate3d(0%,0,0);transform:translateZ(0)}.fox-swiper-navigator__slide-hide-from{-webkit-transform:translate3d(0%,0%,0);transform:translateZ(0)}.fox-swiper-navigator__slide-hide-to{-webkit-transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1),-webkit-transform .36s cubic-bezier(.17,.89,.45,1);-webkit-transform:translate3d(-50%,0,0);transform:translate3d(-50%,0,0)}.fox-swiper-navigator__pop-enter-from{-webkit-transform:translate3d(0,103%,0);transform:translate3d(0,103%,0)}.fox-swiper-navigator__pop-enter-active{-webkit-transition:-webkit-transform .3s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .3s cubic-bezier(.17,.89,.45,1);transition:transform .3s cubic-bezier(.17,.89,.45,1);transition:transform .3s cubic-bezier(.17,.89,.45,1),-webkit-transform .3s cubic-bezier(.17,.89,.45,1)}.fox-swiper-navigator__pop-enter-to{-webkit-transform:translate3d(0,0,0);transform:translateZ(0)}.fox-swiper-navigator__pop-leave-to{-webkit-transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:-webkit-transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1);transition:transform .36s cubic-bezier(.17,.89,.45,1),-webkit-transform .36s cubic-bezier(.17,.89,.45,1);-webkit-transform:translate3d(0,103%,0);transform:translate3d(0,103%,0)}.fox-swiper-navigator .fox-header{position:absolute}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@fox-js/navigation",
3
+ "version": "4.0.0",
4
+ "description": "fox navigation",
5
+ "author": "jiangcheng",
6
+ "keywords": [
7
+ "fox",
8
+ "navigation"
9
+ ],
10
+ "main": "dist/index.umd.js",
11
+ "module": "dist/index.esm.js",
12
+ "exports": {
13
+ ".": {
14
+ "import": {
15
+ "node": "./dist/index.cjs.js",
16
+ "default": "./dist/index.esm.js"
17
+ },
18
+ "require": {
19
+ "node": "./dist/index.cjs.js",
20
+ "default": "./dist/index.umd.js"
21
+ }
22
+ },
23
+ "./style.css": "./dist/style.css"
24
+ },
25
+ "style": "dist/style.css",
26
+ "typings": "dist/index.d.ts",
27
+ "license": "",
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "publish:next": "npm version prerelease & npm publish --tag next",
33
+ "build:dev": "vue-tsc --noEmit && vite build --config scripts/vite.config.ts --mode development",
34
+ "build:prod": "vue-tsc --noEmit && vite build --config scripts/vite.config.ts --mode production"
35
+ },
36
+ "dependencies": {
37
+ "@fox-js/fox": "workspace:^"
38
+ }
39
+ }