motion-plus-vue 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +2 -2
- package/dist/components/Carousel/Carousel.d.ts +31 -0
- package/dist/components/Carousel/CarouselView.d.ts +32 -0
- package/dist/components/Carousel/const.d.ts +3 -0
- package/dist/components/Carousel/context.d.ts +15 -0
- package/dist/components/Carousel/index.d.ts +3 -0
- package/dist/components/Carousel/utils/calc-current-page.d.ts +1 -0
- package/dist/components/Carousel/utils/calc-page-insets.d.ts +5 -0
- package/dist/components/Carousel/utils/find-current-index.d.ts +2 -0
- package/dist/components/Carousel/utils/find-next-page.d.ts +3 -0
- package/dist/components/Carousel/utils/find-prev-page.d.ts +3 -0
- package/dist/components/Ticker/TickerItem.d.ts +59 -13
- package/dist/components/Ticker/const.d.ts +3 -0
- package/dist/components/Ticker/context.d.ts +4259 -2
- package/dist/components/Ticker/index.d.ts +1 -1
- package/dist/components/Ticker/types.d.ts +16 -1
- package/dist/components/Ticker/utils/layout-strategy.d.ts +2 -0
- package/dist/es/components/Carousel/Carousel.vue.mjs +79 -0
- package/dist/es/components/Carousel/Carousel.vue2.mjs +4 -0
- package/dist/es/components/Carousel/CarouselView.vue.mjs +115 -0
- package/dist/es/components/Carousel/CarouselView.vue2.mjs +4 -0
- package/dist/es/components/Carousel/const.mjs +13 -0
- package/dist/es/components/Carousel/context.mjs +6 -0
- package/dist/es/components/Carousel/utils/calc-current-page.mjs +13 -0
- package/dist/es/components/Carousel/utils/calc-page-insets.mjs +42 -0
- package/dist/es/components/Carousel/utils/find-current-index.mjs +13 -0
- package/dist/es/components/Carousel/utils/find-next-page.mjs +26 -0
- package/dist/es/components/Carousel/utils/find-prev-page.mjs +31 -0
- package/dist/es/components/Ticker/Ticker.vue.mjs +270 -111
- package/dist/es/components/Ticker/TickerItem.vue.mjs +68 -36
- package/dist/es/components/Ticker/const.mjs +12 -3
- package/dist/es/components/Ticker/context.mjs +5 -3
- package/dist/es/components/Ticker/utils/layout-strategy.mjs +57 -0
- package/dist/es/index.mjs +21 -16
- package/dist/es/utils/flatten-slots.mjs +22 -16
- package/dist/index.d.ts +1 -0
- package/dist/size.animate-number.js +1 -0
- package/dist/size.carousel.js +1 -0
- package/dist/size.cursor.js +1 -0
- package/dist/size.ticker.js +1 -0
- package/dist/size.typewriter.js +1 -0
- package/package.json +31 -8
- package/dist/components/Ticker/Ticker.d.ts +0 -51
- package/dist/components/Ticker/use-item-offset.d.ts +0 -1
- package/dist/es/components/Ticker/use-item-offset.mjs +0 -12
- package/dist/es/components/Ticker/utils/get-cumulative-offset.mjs +0 -9
package/dist/es/index.mjs
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { AnimateNumber as o } from "./components/AnimateNumber/index.mjs";
|
|
2
|
-
import { Ticker as
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { default as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
2
|
+
import { Ticker as s } from "./components/Ticker/index.mjs";
|
|
3
|
+
import { default as f } from "./components/Cursor/Cursor.vue.mjs";
|
|
4
|
+
import { default as a } from "./components/Ticker/TickerItem.vue.mjs";
|
|
5
|
+
import { default as x } from "./components/Typewriter/Typewriter.vue.mjs";
|
|
6
|
+
import { default as l } from "./components/Carousel/Carousel.vue.mjs";
|
|
7
|
+
import { useCursorState as n } from "./components/Cursor/hooks/use-cursor-state/index.mjs";
|
|
8
|
+
import { useCursorIsInView as T } from "./components/Cursor/hooks/use-cursor-in-view.mjs";
|
|
9
|
+
import { usePointerPosition as k } from "./components/Cursor/hooks/use-pointer-position.mjs";
|
|
9
10
|
import { useMagneticPull as P } from "./components/Cursor/magnetic/use-magnetic-pull.mjs";
|
|
10
|
-
import {
|
|
11
|
+
import { useTicker as b, useTickerItem as g } from "./components/Ticker/context.mjs";
|
|
12
|
+
import { useCarousel as A } from "./components/Carousel/context.mjs";
|
|
11
13
|
export {
|
|
12
14
|
o as AnimateNumber,
|
|
13
|
-
|
|
14
|
-
f as
|
|
15
|
-
|
|
16
|
-
a as
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
l as Carousel,
|
|
16
|
+
f as Cursor,
|
|
17
|
+
s as Ticker,
|
|
18
|
+
a as TickerItem,
|
|
19
|
+
x as Typewriter,
|
|
20
|
+
A as useCarousel,
|
|
21
|
+
T as useCursorIsInView,
|
|
22
|
+
n as useCursorState,
|
|
20
23
|
P as useMagneticPull,
|
|
21
|
-
|
|
24
|
+
k as usePointerPosition,
|
|
25
|
+
b as useTicker,
|
|
26
|
+
g as useTickerItem
|
|
22
27
|
};
|
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
import { Comment as
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Comment as i, Fragment as c } from "vue";
|
|
2
|
+
function s(t = []) {
|
|
3
|
+
var n;
|
|
4
|
+
const r = [];
|
|
5
|
+
for (const e of t)
|
|
6
|
+
if (e.type !== i)
|
|
7
|
+
if (e.type === c) {
|
|
8
|
+
const o = Array.isArray(e.children) ? e.children : (n = e.children) == null ? void 0 : n.default();
|
|
9
|
+
r.push(...s(o));
|
|
10
|
+
} else
|
|
11
|
+
r.push(e);
|
|
12
|
+
return r;
|
|
7
13
|
}
|
|
8
|
-
function
|
|
14
|
+
function l(t) {
|
|
9
15
|
var n;
|
|
10
|
-
const
|
|
11
|
-
for (const
|
|
12
|
-
if (
|
|
13
|
-
const o = Array.isArray(
|
|
14
|
-
|
|
16
|
+
const r = [];
|
|
17
|
+
for (const e of t)
|
|
18
|
+
if (e.type === "Fragment" || e.type === c) {
|
|
19
|
+
const o = Array.isArray(e.children) ? e.children : (n = e.children) == null ? void 0 : n.default();
|
|
20
|
+
r.push(...l(o));
|
|
15
21
|
} else
|
|
16
|
-
|
|
17
|
-
return
|
|
22
|
+
r.push(e);
|
|
23
|
+
return r;
|
|
18
24
|
}
|
|
19
25
|
export {
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
s as flattenSlots,
|
|
27
|
+
l as renderVNode
|
|
22
28
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{onMounted as e,ref as t,watch as a,defineComponent as n,createBlock as l,openBlock as i,unref as o,normalizeStyle as r,withCtx as u,createVNode as s,createTextVNode as p,toDisplayString as y,nextTick as d,createElementVNode as c,createElementBlock as v,createCommentVNode as f,Fragment as m,renderList as g,resolveDynamicComponent as h,toRef as k,normalizeClass as x,renderSlot as $,computed as b,mergeProps as _}from"vue";import{createContext as w,addScaleCorrector as D,mountedStates as I,motion as P,AnimatePresence as j,useMotionConfig as C,animate as M,useDomRef as R,easeOut as S,LayoutGroup as N,MotionConfig as A}from"motion-v";const[B,L]=w("SectionContext");function E(){const t={current:!0};return e(()=>{t.current=!1}),t}function z(e){const{width:t,fontSize:a}=getComputedStyle(e);return parseFloat(t)/parseFloat(a)+"em"}const F="var(--mask-height, 0.15em)",K="var(--mask-width, 0.5em)",H=`calc(${K} / var(--invert-x, 1))`,T="#000 0, transparent 71%",V=`linear-gradient(to right, transparent 0, #000 ${H}, #000 calc(100% - ${H}), transparent),linear-gradient(to bottom, transparent 0, #000 ${F}, #000 calc(100% - ${F}), transparent 100%),radial-gradient(at bottom right, ${T}),radial-gradient(at bottom left, ${T}), radial-gradient(at top left, ${T}), radial-gradient(at top right, ${T})`,W=`100% calc(100% - ${F} * 2),calc(100% - ${H} * 2) 100%,${H} ${F},${H} ${F},${H} ${F},${H} ${F}`;D({"--invert-x":{correct:(e,{treeScale:t,projectionDelta:a})=>a.x.scale*t.x}});const q={display:"flex",flexDirection:"column",alignItems:"center",position:"absolute",width:"100%"};function G(e){const n=t();return a(()=>e.isPresent,e=>{var t;n.value&&(null==(t=I.get(n.value))||t.setActive("exit",!e))}),{root:n,getRoot:function(e){n.value=null==e?void 0:e.$el},handleComplete:function(t){var a;t.detail.isExit&&!e.isPresent&&(null==(a=e.onRemove)||a.call(e,e.partKey,t.target))}}}const J=n({__name:"NumberSymbol",props:{partKey:{},type:{},value:{},isPresent:{type:Boolean},onRemove:{type:Function},style:{},layoutDependency:{},preInitial:{type:Boolean}},setup(e){const t=e,{justify:a}=B(),{getRoot:n,handleComplete:d}=G(t);return(e,t)=>(i(),l(o(P).span,{ref:o(n),layout:"position","layout-dependency":e.layoutDependency,"data-state":e.isPresent?void 0:"exiting",style:r({display:"inline-flex",justifyContent:o(a),padding:`calc(${o(F)}/2) 0`,position:"relative",pointerEvents:e.isPresent?void 0:"none"}),"aria-hidden":!e.isPresent,onMotioncomplete:o(d)},{default:u(()=>[s(o(j),{mode:"popLayout","anchor-x":o(a),initial:e.preInitial},{default:u(()=>[(i(),l(o(P).span,{key:e.value,layout:"right"===o(a)&&"position","layout-dependency":e.layoutDependency,initial:{opacity:0,left:"right"===o(a)&&void 0===e.preInitial?"-100%":void 0},animate:{opacity:[null,1],left:0},exit:{opacity:[null,0],transition:{opacity:{duration:.4}}},style:{display:"inline-block",whiteSpace:"pre",position:"relative"}},{default:u(()=>[p(y(e.value),1)]),_:1},8,["layout","layout-dependency","initial"]))]),_:1},8,["anchor-x","initial"])]),_:1},8,["layout-dependency","data-state","style","aria-hidden","onMotioncomplete"]))}}),O=new WeakMap,Q=n({__name:"NumberDigit",props:{value:{},initialValue:{default:void 0},isPresent:{type:Boolean},partKey:{},onRemove:{},style:{},layoutDependency:{}},setup(e){const n=e,p=n.initialValue??n.value,y=E(),k=C(),x=t(),$=t(Array(10).fill(null)),b=t(),{getRoot:_,handleComplete:w,root:D}=G(n);let I=p;const j=t(p);function R(e){return()=>s("span",{key:e,style:{display:"inline-block",padding:`calc(${F}/2) 0`},ref:t=>{$.value[e]=t}},[e])}return a([()=>n.value,()=>n.isPresent],([e,t])=>t?y.current?d(()=>{j.value=e}):void(j.value=e):j.value=0,{immediate:!0}),a(j,e=>{!function(e){if(y.current&&p===e||!$.value[e])return;const t=z($.value[e]);D.value&&(O.set(D.value,t),D.value.style.width=t),b.value=t}(e)},{immediate:!0,flush:"sync"}),a(j,async(e,t,a)=>{await d(),function(e){var t;if(!x.value||e===I)return;const a=x.value.getBoundingClientRect(),n=null==(t=D.value)?void 0:t.getBoundingClientRect(),l=a.height*(e-I)+(a.top-(n?n.top||0:a.top));M(x.value,{y:[l,0]},k.value.transition)}(e),a(()=>{I=e})},{immediate:!0,flush:"sync"}),(e,t)=>(i(),l(o(P).span,{ref:o(_),layout:"position","layout-dependency":e.layoutDependency,"data-state":e.isPresent?void 0:"exiting","data-key":e.partKey,style:r({display:"inline-flex",justifyContent:"center",width:b.value,pointerEvents:e.isPresent?void 0:"none"}),"aria-hidden":!e.isPresent,onMotioncomplete:o(w)},{default:u(()=>[c("span",{ref_key:"scope",ref:x,style:{display:"inline-flex",justifyContent:"center",flexDirection:"column",alignItems:"center",position:"relative"}},[0!==j.value?(i(),v("span",{key:0,style:r({...o(q),bottom:"100%",left:0})},[(i(!0),v(m,null,g(j.value,e=>(i(),l(h(R(e-1)),{key:e-1}))),128))],4)):f("",!0),(i(),l(h(R(j.value)))),9!==j.value?(i(),v("span",{key:1,style:r({...o(q),top:"100%",left:0})},[(i(!0),v(m,null,g(9-j.value,e=>(i(),l(h(R(j.value+e)),{key:j.value+e}))),128))],4)):f("",!0)],512)]),_:1},8,["layout-dependency","data-state","data-key","style","aria-hidden","onMotioncomplete"]))}}),U=n({__name:"NumberSection",props:{parts:{},justify:{default:"left"},mode:{},name:{},style:{},layoutDependency:{}},setup(e){var n;const y=e,f=t(),h=R(),$=t(),b=E(),_=t(y.parts);let w=!("pre"!==y.name||null!=(n=y.parts)&&n.length)&&void 0;a(()=>y.parts,e=>{const t=new Map(e.map(e=>[e.key,{...e,isPresent:!0}])),a=_.value.filter(e=>!t.get(e.key)).map(e=>({...e,isPresent:!1})),n=e.sort((e,t)=>e.originalIndex-t.originalIndex);_.value=a.concat(n)},{flush:"pre"}),a(()=>{var e;return null==(e=y.parts)?void 0:e.map(e=>e.value).join("")},async(e,t)=>{if(await d(),w=!1,!$.value)return;if(b.current)return void(h.value&&(h.value.style.width=z($.value)));const a=Array.from($.value.children).map(e=>{if(e instanceof HTMLElement&&"exiting"===e.dataset.state){const t=e.nextSibling;return e.remove(),()=>{$.value&&$.value.insertBefore(e,t)}}}),n=z($.value);f.value=n;for(let e=a.length-1;e>=0;e--){const t=a[e];t&&t()}},{flush:"post"});const D=k(y,"justify");function I(e,t){var a;_.value=_.value.filter(t=>t.key!==e),null==(a=null==t?void 0:t.parentElement)||a.removeChild(t)}return L({justify:D}),(e,t)=>(i(),l(o(P).span,{ref:o(h),class:x(`number-section-${e.name}`),style:r({...e.style,display:"inline-flex",justifyContent:D.value,width:f.value}),layout:"position","layout-dependency":e.layoutDependency},{default:u(()=>[c("span",{ref_key:"measuredRef",ref:$,style:{display:"inline-flex",justifyContent:"inherit",position:"relative"}},[t[0]||(t[0]=p(" ")),s(o(j),{mode:e.mode,"anchor-x":D.value,initial:!1},{default:u(()=>[(i(!0),v(m,null,g(_.value,t=>(i(),v(m,{key:t.key},["integer"===t.type||"fraction"===t.type?(i(),l(Q,{key:t.key,"part-key":t.key,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},value:t.value,"is-present":t.isPresent??!0,"initial-value":o(b).current?void 0:0,"layout-dependency":e.layoutDependency,onRemove:I},null,8,["part-key","value","is-present","initial-value","layout-dependency"])):(i(),l(J,{key:"literal"===t.type?`${t.key}:${t.value}`:t.key,type:t.type,"part-key":t.key,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},value:t.value,"is-present":t.isPresent??!0,"pre-initial":o(w),"layout-dependency":e.layoutDependency,onRemove:I},null,8,["type","part-key","value","is-present","pre-initial","layout-dependency"]))],64))),128))]),_:1},8,["mode","anchor-x"])],512)]),_:1},8,["class","style","layout-dependency"]))}}),X=n({__name:"Mask",props:{layoutDependency:{}},setup:e=>(e,t)=>(i(),l(o(P).span,{layout:"","layout-dependency":e.layoutDependency,"aria-hidden":!0,style:r({display:"inline-flex","--invert-x":1,margin:`0 calc(-1*${o(K)})`,padding:`calc(${o(F)}/2) ${o(K)}`,position:"relative",zIndex:-1,overflow:"clip",webkitMaskImage:o(V),webkitMaskSize:o(W),webkitMaskPosition:"center, center, top left, top right, bottom right, bottom left",webkitMaskRepeat:"no-repeat"})},{default:u(()=>[$(e.$slots,"default")]),_:3},8,["layout-dependency","style"]))}),Y=n({name:"AnimateNumber",inheritAttrs:!1,__name:"AnimateNumber",props:{locales:{},format:{},transition:{},suffix:{},prefix:{},value:{},style:{},layoutDependency:{}},setup(e){const t={opacity:{duration:1,ease:S},layout:{type:"spring",duration:1,bounce:0},y:{type:"spring",duration:1,bounce:0}},a=e,n=b(()=>function(e,{locales:t,format:a},n,l){const i=new Intl.NumberFormat(t,a).formatToParts(Number(e));n&&i.unshift({type:"prefix",value:n}),l&&i.push({type:"suffix",value:l});const o=[],r=[],u=[],s=[],p={},y=e=>`${e}:${p[e]=(p[e]??-1)+1}`;let d="",c=!1,v=!1,f=0;for(const e of i){d+=e.value;const t="minusSign"===e.type||"plusSign"===e.type?"sign":e.type;switch(t){case"integer":c=!0,r.push(...e.value.split("").map(e=>({type:t,value:parseInt(e)})));break;case"group":r.push({type:t,value:e.value});break;case"decimal":v=!0,u.push({type:t,value:e.value,key:y(t),originalIndex:f++});break;case"fraction":u.push(...e.value.split("").map(e=>({type:t,value:parseInt(e),key:y(t),originalIndex:f++})));break;default:(c||v?s:o).push({type:t,value:e.value,key:y(t),originalIndex:f++})}}const m=[];for(let e=r.length-1;e>=0;e--){const t=y(r[e].type);m.unshift({...r[e],key:t,originalIndex:e})}return{pre:o,integer:m,fraction:u,post:s,formatted:d}}(a.value,{locales:a.locales,format:a.format},a.prefix,a.suffix)),p=C(),y=b(()=>a.transition??p.value.transition??t);function d(){const{format:e,prefix:t,suffix:n,locales:l,value:i,layoutDependency:o,...r}=a;return r}const c=b(()=>{if(void 0!==a.layoutDependency)return{layoutDependency:a.layoutDependency,value:a.value}});return(e,t)=>(i(),l(o(N),null,{default:u(()=>[s(o(A),{transition:y.value},{default:u(()=>[s(o(P).div,_({...e.$attrs,...d()},{layout:"","layout-dependency":c.value,style:{lineHeight:"1",...e.style,display:"inline-flex",isolation:"isolate",whiteSpace:"nowrap"}}),{default:u(()=>[s(o(P).div,{layout:"","layout-dependency":c.value,"aria-label":n.value.formatted,style:{display:"inline-flex",direction:"ltr",isolation:"isolate",position:"relative",zIndex:-1}},{default:u(()=>[s(U,{"layout-dependency":c.value,style:r({padding:`calc(${o(F)}/2) 0`}),"aria-hidden":!0,justify:"right",mode:"popLayout",parts:n.value.pre,name:"pre"},null,8,["layout-dependency","style","parts"]),s(X,{"layout-dependency":c.value},{default:u(()=>[s(U,{"layout-dependency":c.value,justify:"right",parts:n.value.integer,name:"integer",mode:"popLayout"},null,8,["layout-dependency","parts"]),s(U,{"layout-dependency":c.value,layout:"position",parts:n.value.fraction,name:"fraction",mode:"popLayout"},null,8,["layout-dependency","parts"])]),_:1},8,["layout-dependency"]),s(U,{"layout-dependency":c.value,style:r({padding:`calc(${o(F)}/2) 0`}),"aria-hidden":!0,layout:"position",mode:"popLayout",parts:n.value.post,name:"post"},null,8,["layout-dependency","style","parts"])]),_:1},8,["layout-dependency","aria-label"])]),_:1},16,["layout-dependency","style"])]),_:1},8,["transition"])]),_:1}))}}),Z=Y;export{Z as AnimateNumber};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defineComponent as e,computed as t,toRefs as n,renderSlot as a,createBlock as o,openBlock as i,unref as s,normalizeProps as r,mergeProps as l,withCtx as u,watch as f,nextTick as d,Comment as g,Fragment as c,reactive as v,ref as p,useSlots as m,createVNode as h,toRef as x,createElementBlock as y,normalizeStyle as I,renderList as b,resolveDynamicComponent as w,isVNode as L,onMounted as k}from"vue";import{createContext as M,useTransform as P,motion as E,isHTMLElement as _,wrap as T,useMotionValue as S,useDomRef as O,useInView as A,usePageInView as B,useReducedMotion as $,resize as C,useAnimationFrame as j,LayoutGroup as D,frame as z,animate as W,Motion as R,clamp as H,useMotionValueEvent as N,JSAnimation as X}from"motion-v";const[Y,G]=M("TickerItemContext"),[K,q]=M("TickerInfo");function F(e,t,n,a,o){return{sign:1,direction:o,lengthProp:t,viewportLengthProp:n,paddingStartProp:a,measureItem:n=>({start:n[e],end:n[e]+n[t]}),getCumulativeInset:t=>{let n=0,a=t;for(;a;)n+=a[e],a=a.offsetParent;return n}}}const U=F("offsetLeft","offsetWidth","innerWidth","paddingLeft","right"),V=F("offsetTop","offsetHeight","innerHeight","paddingTop","bottom");function J(e,t){return((null==t?void 0:t.offsetWidth)??window.innerWidth)-(e.offsetLeft+e.offsetWidth)}const Q={...U,sign:-1,direction:"left",paddingStartProp:"paddingRight",measureItem:(e,t)=>{const n=e.offsetWidth,a=J(e,t);return{start:a,end:a+n}},getCumulativeInset:e=>{let t=0,n=e;for(;n;)t+=J(n,n.offsetParent),n=n.offsetParent;return t}};function Z(e,t){return"y"===e?V:"ltr"===t?U:Q}const ee=e({__name:"TickerItem",props:{offset:{},axis:{},listSize:{default:0},bounds:{},numItems:{default:0},itemIndex:{},cloneIndex:{},alignItems:{},size:{default:"auto"},safeMargin:{},reproject:{type:Boolean,default:!0}},setup(e){const f=e,{state:d}=K(),g=t(()=>Z(f.axis,d.direction).sign),c=P(()=>{if(!f.reproject)return 0;const{offset:e,bounds:t,listSize:n,safeMargin:a}=f,{start:o,end:i}=t;if(!o&&!i||!n)return 0;const s=e.get();if(s*g.value+i<=-d.inset-a)return n*g.value;if(a>0){const e=d.visibleLength-a-d.inset;if(s*g.value+t.start>=e)return-n*g.value}return 0}),v=P(()=>{const e=f.offset.get(),t=c.get();return(f.bounds.start||f.bounds.end)&&f.listSize?e*g.value+f.bounds.start+t*g.value:0}),p=t(()=>void 0===f.cloneIndex?{"aria-hidden":!1,"aria-posinset":f.itemIndex+1,"aria-setsize":f.numItems}:{"aria-hidden":!0}),m=t(()=>{const e="fill"===f.size,t="stretch"===f.alignItems?"100%":"fit-content";return{class:void 0===f.cloneIndex?"ticker-item":"clone-item",style:{flexGrow:0,flexShrink:0,position:"relative",flexBasis:e?"100%":void 0,display:e?"grid":void 0,gridTemplateColumns:e?"1fr":void 0,gridTemplateRows:e?"1fr":void 0,minWidth:e?0:void 0,minHeight:e?0:void 0,height:"x"===f.axis?t:void 0,width:"y"===f.axis?t:void 0,x:"x"===f.axis?c:0,y:"y"===f.axis?c:0},...p.value}}),{bounds:h,itemIndex:x,cloneIndex:y}=n(f);return G({offset:v,bounds:h,projection:c,itemIndex:x,cloneIndex:y,props:m}),(e,t)=>"manual"===e.size?a(e.$slots,"default",{key:0}):(i(),o(s(E).li,r(l({key:1},m.value)),{default:u(()=>[a(e.$slots,"default")]),_:3},16))}});function te(e,t,n,a,o){let i=!1;f(e,(e,s,r)=>{if(!e)return;let l=!1;const u=new AbortController,f={signal:u.signal},g={...f,capture:!0},c="x"===t.value?"scrollLeft":"scrollTop",v="x"===t.value?"offsetLeft":"offsetTop",p="x"===t.value?"ArrowLeft":"ArrowUp",m="x"===t.value?"ArrowRight":"ArrowDown";let h=[],x=0;const y=async()=>{const t=h[x];t.focus(),await d(),n.set(-t[v]),e[c]=0},I=t=>{if("Tab"===t.key){t.preventDefault(),w();const n=Array.from(document.querySelectorAll('a, button, input, textarea, select, [tabindex]:not([tabindex="-1"]), [contenteditable="true"]')).filter(_);n.sort(ne);const a=n[t.shiftKey?0:n.length-1],o=t.shiftKey?n.length-1:0;if(e.contains(a))return void n[o].focus();{const a=n.indexOf(h[x]),o=t.shiftKey?-1:1;for(let t=a;t<n.length&&t>=0;t+=o){const a=n[t];if(!e.contains(a))return void a.focus()}}return}t.key===p?x--:t.key===m&&x++,x=T(0,h.length,x),y()},b=t=>{(!t.target||!(t.target instanceof HTMLElement)||!e.contains(t.target))&&w()},w=()=>{i&&(i=!1,o(!1),a.value.set(n.get()),window.removeEventListener("focus",b),window.removeEventListener("blur",b),e.removeEventListener("keydown",I))},L=t=>{const{target:n}=t;_(n)&&(i||i||(o(!0),i=!0,h=Array.from(e.querySelectorAll('.ticker-item a, .ticker-item button, .ticker-item input, .ticker-item textarea, .ticker-item select, .ticker-item [tabindex]:not([tabindex="-1"]), .ticker-item [contenteditable="true"]')).filter(_),x=0,y(),window.addEventListener("focus",b,g),window.addEventListener("blur",b,g),e.addEventListener("keydown",I,f)))},k=()=>{l&&(l=!1,e.removeEventListener("focus",L,!0),window.removeEventListener("pointermove",k,f))};window.addEventListener("keydown",()=>{l||(l=!0,e.addEventListener("focus",L,g),window.addEventListener("pointermove",k,f))},f),e.addEventListener("pointerdown",e=>{const t=e.target.closest('[aria-hidden="true"]');t&&t.removeAttribute("aria-hidden")},f),r(()=>{u.abort(),w()})},{flush:"post"})}function ne(e,t){return e.tabIndex>=1&&t.tabIndex>=1?e.tabIndex-t.tabIndex:e.tabIndex>=1&&t.tabIndex<=0?-1:t.tabIndex>=1&&e.tabIndex<=0?1:0}const ae={start:0,end:0},oe={start:"flex-start",end:"flex-end"},ie={duration:.2,ease:"linear"},se={type:"spring",stiffness:400,damping:40};function re(e){return e.end-e.start}function le(e){return e.length?e[e.length-1].end-e[0].start:0}function ue(e=[]){var t;const n=[];for(const a of e)if(a.type!==g)if(a.type===c){const e=Array.isArray(a.children)?a.children:null==(t=a.children)?void 0:t.default();n.push(...ue(e))}else n.push(a);return n}function fe(e){var t;const n=[];for(const a of e)if("Fragment"===a.type||a.type===c){const e=Array.isArray(a.children)?a.children:null==(t=a.children)?void 0:t.default();n.push(...fe(e))}else n.push(a);return n}function de(e,t,n){const a=Math.floor(e/n),o=a*n;let i=0;for(let n=0;n<t.length;n++){const{end:a}=t[n];if(i=n,a+o>e)break}return i+a*t.length}function ge(e,t,n,a){var o;if(0===t.length)return 0;const i=t[t.length-1].end+n,s=a??e+((null==(o=t[0])?void 0:o.end)??0);let r=de(e,t,i)+1,l=0,u=!1;for(;!u;){const{start:e,end:n}=t[T(0,t.length,r)],a=Math.floor(r/t.length)*i;l=e+a,n+a>s?u=!0:r++}return l}function ce(e,t,n,a){return ge(e,n,a,e+t)}function ve(e,t,n,a,o){if(0===t.length)return 0;const i=t[t.length-1].end+n,s=a??e-(o??0);let r=de(e,t,i),l=e,u=!1;for(;!u;){const{start:a,end:f}=t[T(0,t.length,r)],d=f-a,g=a+Math.floor(r/t.length)*i;s<=g+n||g>=e?(l=g,r--):s<=g?(l=g,u=!0):((o&&d>o||l===e&&s>=g)&&(l=g),u=!0)}return l}function pe(e,t,n,a){return ve(e,n,a,e-t,t)}function me(e){return"function"==typeof e||"[object Object]"===Object.prototype.toString.call(e)&&!L(e)}const he=e({__name:"Ticker",props:{axis:{default:"x"},velocity:{default:50},hoverFactor:{default:1},gap:{default:10},align:{default:"center"},offset:{},itemSize:{default:"auto"},overflow:{type:Boolean,default:!1},loop:{type:Boolean,default:!0},safeMargin:{default:0},fade:{default:0},fadeTransition:{default:()=>ie},pageTransition:{default:()=>se},_dragX:{type:[Object,Boolean]},_dragY:{type:[Object,Boolean]},snap:{type:[String,Boolean]},as:{default:"div"},style:{},onDragEnd:{},drag:{type:[Boolean,String]},dragConstraints:{type:[Boolean,Object]},dragMomentum:{type:Boolean}},setup(e){const n=e,r=v({direction:"ltr",visibleLength:0,inset:0,totalItemLength:0,containerLength:0,itemPositions:[],isMeasured:!1,maxInset:null}),d=t(()=>oe[n.align]||n.align),g=t(()=>Z(n.axis,r.direction).sign),L=p(!1),k=S(1),M=S(0),_=t(()=>n.offset??M),N=P(()=>"rtl"===r.direction?T(r.totalItemLength+n.gap+r.inset,r.inset,_.value.get()):T(-r.totalItemLength-n.gap-r.inset,-r.inset,_.value.get())),X=S(0),Y=t(()=>L.value?X:n.loop?N:_.value),G=O(),K=O(),F=A(G,{margin:"100px"}),U=B(),V=t(()=>F.value&&U.value),J=$(),Q=m(),ne=t(()=>{var e;return ue(null==(e=Q.default)?void 0:e.call(Q))});function ie(){if(!G.value||!K.value)return;const e=window.getComputedStyle(G.value).direction,{measureItem:t,lengthProp:a,viewportLengthProp:o,getCumulativeInset:i}=Z(n.axis,e),{safeMargin:s,overflow:l,loop:u}=n,f="x"===he.value?"paddingLeft":"paddingTop",d="x"===he.value?"paddingRight":"paddingBottom",g=G.value,c=K.value.querySelectorAll(".ticker-item");if(!c.length)return;let v=!1;const p=[];for(let e=0;e<c.length;e++){const n=t(c[e],g);p.push(n);const a=r.itemPositions[e];(!a||n.start!==a.start||n.end!==a.end)&&(v=!0)}const m=Math.min(g[a],window[o]);let h=n.overflow?window[o]:m;s>0&&(h+=2*s);const x=le(p),y=window.getComputedStyle(g),I=parseInt(y[f]??0),b=parseInt(y[d]??0),w=l?i(c[0]):I,L=!1===u?Math.max(0,x-m+I+b):null;(h!==r.visibleLength||x!==r.totalItemLength||w!==r.inset||r.itemPositions.length!==p.length||v)&&(r.direction=e,r.visibleLength=h,r.itemPositions=p,r.totalItemLength=x,r.inset=w,r.containerLength=m,r.maxInset=L,r.isMeasured=!0)}f([ne,V,()=>n.overflow],(e,t,a)=>{if(!V.value||!G.value)return;ie();const o=n.overflow?C(ie):void 0,i=C(G.value,ie);a(()=>{null==o||o(),i()})},{immediate:!0,flush:"post"});const se=t(()=>r.totalItemLength>0);j((e,t)=>{if(se.value&&V.value&&_.value===M&&!J.value){const e=t/1e3*(n.velocity*g.value*k.get());_.value.set(_.value.get()-e)}});const de=t(()=>se.value&&r.visibleLength?function(e,t,n){const a=le(t),o=Math.max(...t.map(re));let i=0,s=0;for(;s<e;)s=(a+n)*(i+1)-o,i++;return Math.max(i-1,0)}(r.visibleLength,r.itemPositions,n.gap):0),ce=t(()=>0===r.totalItemLength?0:(r.totalItemLength+n.gap)*(de.value+1)),pe=t(()=>{if(!n.loop)return[];const e=[];for(let t=0;t<de.value;t++){const a=[];ne.value.forEach((e,o)=>{let i;const s=r.itemPositions[o],l=(r.totalItemLength+n.gap)*(t+1),u=s?{start:s.start+l,end:s.end+l}:ae;a.push(h(ee,{key:`clone-${t}-${o}`,offset:Y.value,axis:n.axis,listSize:ce.value,itemIndex:o,cloneIndex:o,bounds:u,alignItems:d.value,size:n.itemSize,safeMargin:n.safeMargin,numItems:ne.value.length},me(i=fe([e]))?i:{default:()=>[i]}))});const o=`ticker-group-${t}`;e.push(h(D,{key:o,id:o},me(a)?a:{default:()=>[a]}))}return e}),he=x(n,"axis");te(G,he,X,_,e=>{L.value=e});const xe={display:"flex",position:"relative"},ye={display:"flex",position:"relative",willChange:"transform",listStyleType:"none",padding:0,margin:0,justifyContent:"flex-start"};function Ie(e){return null!==r.maxInset?H(-r.maxInset,0,e):e}q({state:r,gap:t(()=>n.gap),clampOffset:Ie,renderedOffset:Y});const be=t(()=>"x"===n.axis?null==n?void 0:n._dragX:null==n?void 0:n._dragY);let we=null;const Le=t(()=>null!==r.maxInset?"x"===he.value?g.value>0?{left:-1*r.maxInset,right:0}:{right:r.maxInset,left:0}:{top:-1*r.maxInset,bottom:0}:{});function ke(){we&&(we.stop(),we=null)}const Me=t(()=>!n.onDragEnd&&n.drag&&be?()=>{be.value.jump(_.value.get()),ke()}:n.onPointerDown),Pe=t(()=>!n.onDragEnd&&n.drag&&be.value?(e,{velocity:t})=>{const a=_.value.get();ke(),z.postRender(()=>{let e=a+t[he.value]*(n.snap?.3:.8);if(n.snap)if(t[he.value]<0)e=-ge(-a,r.itemPositions,n.gap,-e);else if(t[he.value]>0)e=-ve(-a,r.itemPositions,n.gap,-e,r.containerLength);else{const t=-ge(-a,r.itemPositions,n.gap,-a),o=-ve(-a,r.itemPositions,n.gap,-a,r.containerLength);e=Math.abs(a-t)<Math.abs(a-o)?t:o}const o=n.loop?{}:g.value>0?{max:0,min:Le.value["x"===he.value?"left":"top"]}:{min:0,max:Le.value.right};we=W(be,Ie(e*g.value)*g.value,n.snap?n.pageTransition:{type:"inertia",velocity:t[he.value],modifyTarget:()=>e,bounceDamping:40,bounceStiffness:400,...o})})}:n.onDragEnd),Ee=S(n.loop?0:1),_e=S(0),Te=t(()=>Z(he.value,r.direction)),Se=t(()=>"number"==typeof n.fade?"px":""),Oe=P(()=>`linear-gradient(to ${Te.value.direction}, rgba(0,0,0,${Ee.get()}) 0px, black ${n.fade}${Se.value}, black calc(100% - ${n.fade}${Se.value}), rgba(0,0,0,${_e.get()}) 100%)`),Ae=t(()=>n.fade?{maskImage:Oe,WebkitMaskImage:Oe}:{}),Be={start:!0,end:!1};return f(Y,(e,t,a)=>{let o=()=>{};e&&(o=e.on("change",e=>{if(null===r.maxInset)return;const t=-1*r.maxInset;(e*=g.value)<0?Be.start&&(W(Ee,0,n.fadeTransition),Be.start=!1):Be.start||(W(Ee,1,n.fadeTransition),Be.start=!0),e>t?Be.end&&(W(_e,0,n.fadeTransition),Be.end=!1):Be.end||(W(_e,1,n.fadeTransition),Be.end=!0)})),a(o)},{immediate:!0}),(e,t)=>(i(),y(c,null,[h(s(R),l(e.$attrs,{ref_key:"containerRef",ref:G,as:e.as,style:{overflowX:e.overflow||"x"!==he.value?void 0:"clip",overflowY:e.overflow||"y"!==he.value?void 0:"clip",...xe,...n.style,...Ae.value},drag:e.drag,_dragX:e._dragX,_dragY:e._dragY,"drag-constraints":Le.value,"drag-momentum":e.dragMomentum,onPointerenter:t[0]||(t[0]=()=>{s(W)(s(k),e.hoverFactor)}),onPointerleave:t[1]||(t[1]=()=>{s(W)(s(k),1)}),onPointerdown:Me.value,onDragEnd:Pe.value}),{default:u(()=>[h(s(E).ul,{ref_key:"listRef",ref:K,role:"group",style:I({...ye,flexDirection:"x"===he.value?"row":"column",gap:`${e.gap}px`,x:"x"===he.value?Y.value:0,y:"y"===he.value?Y.value:0,opacity:se.value?1:0,alignItems:d.value,willChange:se.value&&V.value?"transform":void 0,width:"100%",height:"100%",maxHeight:"100%",maxWidth:"100%"})},{default:u(()=>[(i(!0),y(c,null,b(ne.value,(t,n)=>(i(),o(ee,{key:`original-${n}`,axis:he.value,offset:Y.value,"list-size":ce.value,"item-index":n,bounds:r.itemPositions[n]??s(ae),"align-items":d.value,size:e.itemSize,reproject:e.loop,"safe-margin":e.safeMargin,"num-items":ne.value.length},{default:u(()=>[(i(!0),y(c,null,b(s(fe)([t]),(e,t)=>(i(),o(w(e),{key:t}))),128))]),_:2},1032,["axis","offset","list-size","item-index","bounds","align-items","size","reproject","safe-margin","num-items"]))),128)),(i(!0),y(c,null,b(pe.value,e=>(i(),o(w(e),{key:e.key}))),128))]),_:1},8,["style"])]),_:1},16,["as","style","drag","_dragX","_dragY","drag-constraints","drag-momentum","onPointerdown","onDragEnd"]),a(e.$slots,"after")],64))}}),xe=he,ye={type:"spring",stiffness:200,damping:40},Ie={type:"spring",stiffness:80,damping:10};function be(e){return-Math.sign(e)}function we(e,t,n,a=!0){const o={insets:[],visibleLength:t};if(0===e.length)return o;const i=[e[0].start];for(let a=1;a<e.length;a++){const{start:o,end:s}=e[a];if(i[i.length-1]+t<s)if(null!==n){if(!(o<=n)){i.push(n);break}i.push(o)}else i.push(o)}if(a&&null!==n&&i.length>1){const a=i[i.length-1],o=[];for(let e=0;e<i.length-1;e++)o.push(i[e+1]-i[e]);const s=o.reduce((e,t)=>e+t,0)/o.length;if(n-a<.5*s){const a=we(e,.75*t,n,!1);if(a.insets.length===i.length)return a}}return{insets:i,visibleLength:t}}const[Le,ke]=M("CarouselContext"),Me=e({__name:"CarouselView",props:{offset:{},targetOffset:{},tugOffset:{},loop:{type:Boolean},transition:{},axis:{default:"x"},snap:{type:[String,Boolean],default:"page"},tickerRef:{}},setup(e){const o=e;let i=!0;const{state:s,gap:r,clampOffset:l}=K(),u=t(()=>s.totalItemLength+r.value),d=t(()=>we(s.itemPositions,s.containerLength,s.maxInset)),g=t(()=>d.value.insets.length),c=t(()=>Z(o.axis,s.direction).sign);function v(e){const t=function(e,t,n,a){const o=-e,i=null===a?Math.floor(o/n):0,s=i*n;for(let e=t.length-1;e>=0;e--){const a=t[e]+s,r=(0===e?i-1:i)*n,l=t[T(0,t.length,e-1)]+r,u=(a-l)/2,f=T(0,t.length,e+1),d=(e===t.length-1?i+1:i)*n,g=t[f]+d;if(o<g-(g-a)/2&&o>=l+u)return e}return 0}(e*c.value,d.value.insets,u.value,s.maxInset);return{current:t,isNextActive:!!o.loop||e*-c.value<s.maxInset,isPrevActive:!!o.loop||e*-c.value>0}}const m=p(v(o.targetOffset.get()));function h(){const e=v(o.targetOffset.get());(e.current!==m.value.current||e.isNextActive!==m.value.isNextActive||e.isPrevActive!==m.value.isPrevActive)&&(m.value=e)}f([()=>s.containerLength,()=>s.totalItemLength],h,{immediate:!0,flush:"post"}),N(o.targetOffset,"change",e=>{o.offset.set(e),h()});let x=null;function y(){x&&(x.stop(),x=null)}function I(e){const t=l(e);o.targetOffset.stop(),i=!1,o.targetOffset.set(t*c.value)}function b(e,t){const n=-e(-o.targetOffset.get()*c.value,d.value.visibleLength,s.itemPositions,r.value),a=l(n);a*c.value===o.targetOffset.get()?W(o.tugOffset,0,{velocity:t*c.value*400,...Ie}):I(a)}k(()=>{o.offset.attach((e,t)=>{y(),i?t(e):x=new X({keyframes:[o.offset.get(),e],velocity:H(-2e3,2e3,o.offset.getVelocity()),...o.transition,onUpdate:t,onComplete:()=>{x=null}}),i=!0},y)});const w=()=>b(ce,-1),L=()=>b(pe,1);const{axis:M,snap:P,offset:E}=n(o);return f([M,P,E,c,()=>o.tickerRef],(e,t,n)=>{o.tickerRef&&n(function(e,{axis:t="y",onWheel:n,onSwipe:a,swipeThreshold:o=100,swipeTimeout:i=150,jitterThreshold:s=2,lineHeight:r=16}){let l="IDLE",u=0,f=0,d=0,g=!1,c=0,v=!1,p=null;const m=e=>{const m="x"!==t||e.shiftKey?e.deltaY:e.deltaX,h="x"!==t||e.shiftKey?e.deltaX:e.deltaY;if(Math.abs(m)<Math.abs(h))return;(n||a)&&e.preventDefault();let x=-(e.deltaMode===WheelEvent.DOM_DELTA_LINE?m*r:m);if(0===x)return;p&&clearTimeout(p),p=setTimeout(()=>{l="IDLE",v=!1,u=0},i),"IDLE"===l&&(l="WHEELING");const y=be(x);function I(e,t){l="SWIPING",v=!0,f=be(t),g=!1,c=0,d=Math.abs(e),a?.(f),u=Math.abs(t)%o*f}switch(l){case"WHEELING":{const e=u+x;a&&!v&&Math.abs(e)>=o?I(x,e):(u=e,n?.(x));break}case"SWIPING":{const e=Math.abs(x);let t=!1;if(d>0){const n=e-d;n<0&&(g=!0),g&&n>s?(c++,c>2&&(t=!0)):c=0}if(y!==f||t){v=!1;const e=x;a&&!v&&Math.abs(e)>=o?I(x,e):(l="WHEELING",u=e,n?.(x));break}d=e;break}}};return e.addEventListener("wheel",m,{passive:!1}),()=>{p&&clearTimeout(p),e.removeEventListener("wheel",m)}}(o.tickerRef,{axis:M.value,onSwipe:P.value?e=>{e*c.value===1?w():L()}:void 0,onWheel:e=>{const t=E.value.get()+e,n=c.value>0?l(t):H(0,s.maxInset,t);o.targetOffset.jump(s.maxInset?n:t)}}))},{immediate:!0,flush:"post"}),ke({paginationState:m,totalPages:g,nextPage:w,prevPage:L,gotoPage:function(e){const t=(o.loop?Math.floor(-o.targetOffset.get()*c.value/u.value):0)*-u.value;I(-d.value.insets[e]+t)},targetOffset:o.targetOffset}),(e,t)=>a(e.$slots,"default")}}),Pe=e({name:"Carousel",inheritAttrs:!1,__name:"Carousel",props:{snap:{type:[String,Boolean],default:"page"},transition:{default:()=>({...ye})},axis:{default:"x"},gap:{},align:{},itemSize:{},overflow:{type:Boolean},loop:{type:Boolean,default:!0},safeMargin:{},fade:{},fadeTransition:{},pageTransition:{},_dragX:{type:[Object,Boolean]},_dragY:{type:[Object,Boolean]},as:{},style:{},onDragEnd:{},drag:{type:[Boolean,String]},dragConstraints:{type:[Boolean,Object]},dragMomentum:{type:Boolean}},setup(e){const t=e,n=S(0),r=S(0),f=S(0),d=P(()=>f.get()+r.get()),g=O();return(e,c)=>(i(),o(s(xe),l({...t,...e.$attrs},{ref_key:"tickerRef",ref:g,role:"region","aria-roledescription":"carousel",offset:s(d),loop:e.loop,axis:e.axis,drag:e.axis,"_drag-x":"x"===e.axis&&s(n),"_drag-y":"y"===e.axis&&s(n),snap:e.snap,"page-transition":e.transition}),{after:u(()=>[h(Me,{"ticker-ref":s(g),loop:e.loop,offset:s(r),"tug-offset":s(f),"target-offset":s(n),transition:e.transition,snap:e.snap,axis:e.axis},{default:u(()=>[a(e.$slots,"after")]),_:3},8,["ticker-ref","loop","offset","tug-offset","target-offset","transition","snap","axis"])]),default:u(()=>[a(e.$slots,"default")]),_:3},16,["offset","loop","axis","drag","_drag-x","_drag-y","snap","page-transition"]))}});export{Pe as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{watch as t,ref as e,computed as n,defineComponent as o,toRefs as i,useSlots as r,createBlock as a,openBlock as u,Teleport as l,createCommentVNode as s,unref as d,withCtx as c,createVNode as f,mergeProps as p,renderSlot as g}from"vue";import{noop as m,motionValue as v,frame as h,useTransform as y,pipe as w,mix as x,useSpring as B,useMotionValue as z,animate as b,useReducedMotion as S,LayoutGroup as E,MotionConfig as C,motion as L,AnimatePresence as $}from"motion-v";function O(e){t(e,(t,e,n)=>{const o=t?function(){const t=document.createElement("style");return t.textContent='\n * {\n cursor: none !important;\n }\n \n [data-motion-cursor="pointer"] {\n background-color: #333;\n }\n ',document.head.appendChild(t),()=>{document.head.removeChild(t)}}():m;return n(()=>{o()})},{immediate:!0,flush:"post"})}function T(t){return e=>{"mouse"===e.pointerType&&t(e)}}function j(t){return T(e=>{0===e.button&&t(e)})}let P,_;function M(){return P||function(){P=v(0),_=v(0);let t=0,e=0;function n(){P.set(t),_.set(e)}typeof window<"u"&&window.addEventListener("pointermove",T(o=>{t=o.clientX,e=o.clientY,h.update(n)}))}(),{x:P,y:_}}function k(t){let e=function(t){return t.closest("[data-cursor]")}(t);return e?[e.dataset.cursor,e]:(e=function(t){return t.closest('a, button, input[type="button"]:not(:disabled)')}(t),e?["pointer",e]:(e=function(t){return"none"===window.getComputedStyle(t).userSelect?null:t.closest("p, textarea:not(:disabled), input[type='text']:not(:disabled), h1, h2, h3, h4, h5, h6")}(t),e?["text",e]:["default",null]))}let A=null,I={type:"default",isPressed:!1,fontSize:null,targetBoundingBox:null,target:null,zone:null};function R(t){let e=null;if("closest"in t){const n=t.closest("[data-cursor-zone]");n instanceof HTMLElement&&(e=n.dataset.cursorZone||null)}return e}function X(){if(typeof window>"u")return{onChange:()=>()=>{}};const t=new Set;function e(e){I={...I,...e},t.forEach(t=>t(I))}const n=j(()=>{I.isPressed||e({isPressed:!0})}),o=j(()=>{I.isPressed&&e({isPressed:!1})}),i=T(({target:t})=>{if(!t)return;const[n,o]=k(t);let i=!1;const r={target:o,zone:R(t)};n!==I.type&&(r.type=n,i=!0),r.zone!==I.zone&&(I.zone=r.zone,i=!0);const a="pointer"===n&&o?o.getBoundingClientRect():null;if(a!==I.targetBoundingBox&&(r.targetBoundingBox=a,i=!0),"text"===n){const{fontSize:e}=window.getComputedStyle(t),n=e?parseInt(e):null;n!==I.fontSize&&(r.fontSize=n,i=!0)}else I.fontSize&&(r.fontSize=null,i=!0);i&&e(r)});return{onChange:e=>(t.size||(typeof window>"u"||(window.addEventListener("pointerover",i),window.addEventListener("pointerdown",n),window.addEventListener("pointerup",o))),t.add(e),()=>{t.delete(e),t.size||(window.removeEventListener("pointerover",i),window.removeEventListener("pointerdown",n),window.removeEventListener("pointerup",o))})}}function Y(){const n=e({...I});return t(n,()=>(A||(A=X()),A).onChange(t=>{n.value=t}),{immediate:!0,flush:"post"}),n}let H=null;function Z(){const t=new Set;function e(){t.forEach(t=>t.show())}function n(){t.forEach(t=>t.hide())}return{on:o=>typeof window>"u"?m:(t.size||(document.body.addEventListener("mouseenter",e),document.body.addEventListener("mouseleave",n)),t.add(o),()=>{t.delete(o),0===t.size&&(document.body.removeEventListener("mouseenter",e),document.body.removeEventListener("mouseleave",n))})}}function q(n){const o=e(!0);return t(o,()=>(H||(H=Z()),H).on({show:()=>{o.value||(n(),o.value=!0)},hide:()=>o.value=!1}),{immediate:!0}),o}const D={x:0,y:0},F={x:.5,y:.5},G={duration:0},J={stiffness:1e3,damping:100},K={duration:.15,ease:[.38,.12,.29,1]},N={magneticOptions:{morph:!0,padding:5,snap:.8}};function Q(t,e,n){const o={width:(null==n?void 0:n.width)??t,height:(null==n?void 0:n.height)??e};return"number"==typeof o.width&&(o.width=`${o.width}px`),"number"==typeof o.height&&(o.height=`${o.height}px`),o}function U(e,n,o){const i=B(0,{stiffness:600,damping:50}),r=z(0),a=function(t,e,n){return y(()=>x(t.value.get(),e.get(),n.get()))}(e,i,r);return t(()=>null==o?void 0:o.value,(t,e)=>{t?(e||r.isAnimating()?i.set(t):i.jump(t),b(r,n.value||0)):b(r,0)},{immediate:!0,flush:"sync"}),a}function V(t,e,o,i){const r=U(n(()=>t.value.x),i,n(()=>o.value.targetBoundingBox?o.value.targetBoundingBox.left+o.value.targetBoundingBox.width/2:void 0)),a=U(n(()=>t.value.y),i,n(()=>o.value.targetBoundingBox?o.value.targetBoundingBox.top+o.value.targetBoundingBox.height/2:void 0));return n(()=>e.value?{x:r,y:a}:t.value)}const W=o({name:"Cursor",inheritAttrs:!1,__name:"Cursor",props:{follow:{type:Boolean,default:!1},center:{default:({follow:t})=>t?D:F},offset:{default:()=>D},spring:{type:[Boolean,Object],default:({follow:t})=>!!t&&J},matchTextSize:{type:Boolean,default:!0},magnetic:{type:[Boolean,Object],default:!1},transition:{},variants:{},style:{},show:{type:Boolean,default:!0}},setup(o){const m=o,{offset:v,magnetic:h}=i(m),x=S();O(()=>!x.value&&!m.follow);const z=M(),b=function(t,e){return{x:y(()=>t.x.get()+e.value.x),y:y(()=>t.y.get()+e.value.y)}}(z,v),T=B(b.x,m.spring||void 0),j=B(b.y,m.spring||void 0),P=n(()=>"object"==typeof m.magnetic?{...N.magneticOptions,...m.magnetic}:N.magneticOptions);function _(){const t=b.x.on("change",e=>{T.jump(e),t()}),e=b.y.on("change",t=>{j.jump(t),e()})}const k=Y(),A=q(_),I=V(n(()=>m.spring?{x:T,y:j}:z),n(()=>!!h.value),k,n(()=>P.value&&P.value.snap)),R=r(),X=n(()=>{var t,e;const n=null==(e=null==(t=R.default)?void 0:t.call(R))?void 0:e.filter(t=>t.type!==Symbol.for("v-cmt"));return function({type:t,state:e,hasChildren:n,style:o,isMagnetic:i,magneticOptions:r,matchTextSize:a}){const u=i&&e.targetBoundingBox;if(n&&!u)return Q("auto","auto",o);const{padding:l,morph:s}=r;switch(t){case"pointer":if(i&&s&&e.targetBoundingBox){const{width:t,height:n}=e.targetBoundingBox;return{width:`${t+2*l}px`,height:`${n+2*l}px`}}return Q(31,31,o);case"text":return a&&e.fontSize?{width:"4px",height:`${e.fontSize}px`}:Q(4,20,o);default:return Q(17,17,o)}}({type:k.value.type,state:k.value,hasChildren:!(null==n||!n.length),isMagnetic:!!m.magnetic,style:m.style,magneticOptions:P.value,matchTextSize:m.matchTextSize})}),H=function({x:n,y:o},i){const r=e(void 0!==n.prev||void 0!==o.prev);return t(r,()=>{if(r.value)return;const t=()=>{r.value=!0,i(),e()},e=w(n.on("change",t),o.on("change",t));return()=>e()},{immediate:!0}),r}(z,_);function Z(t){return(e,n)=>`translate(-${100*t.x}%, -${100*t.y}%) ${n}`}function D(){const{follow:t,center:e,offset:n,spring:o,matchTextSize:i,magnetic:r,...a}=m;return a}return(t,e)=>(u(),a(l,{to:"body"},[d(H)?(u(),a(d(E),{key:0},{default:c(()=>[f(d(C),{transition:d(x)?d(G):t.transition||d(K)},{default:c(()=>{var e,n;return[f(d(L).div,p({layout:"","data-motion-cursor":t.follow?"follow":"pointer","data-framer-portal-id":"motion-cursor",initial:"exit",exit:"exit"},{...t.$attrs,...D()},{variants:{pressed:t.follow?{}:{scale:.9},...t.variants,default:{opacity:1,scale:1,...null==(e=t.variants)?void 0:e.default},exit:{opacity:0,scale:0,...null==(n=t.variants)?void 0:n.exit}},animate:["default",d(k).type,d(h)&&d(k).targetBoundingBox?"magnetic":"",d(A)&&t.show?d(k).isPressed?"pressed":"":"exit"],"transform-template":Z(t.center),style:{borderRadius:t.follow?0:20,zIndex:t.follow?99998:99999,willChange:"transform",contain:"layout",originX:t.center.x,originY:t.center.y,...t.style,width:X.value.width,height:X.value.height,x:d(I).x,y:d(I).y,top:0,left:0,position:"fixed",pointerEvents:"none"}}),{default:c(()=>[f(d($),null,{default:c(()=>[g(t.$slots,"default")]),_:3})]),_:3},16,["data-motion-cursor","variants","animate","transform-template","style"])]}),_:3},8,["transition"])]),_:3})):s("",!0)]))}});export{W as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defineComponent as e,computed as t,toRefs as n,renderSlot as a,createBlock as i,openBlock as o,unref as r,normalizeProps as l,mergeProps as s,withCtx as u,watch as d,nextTick as f,Comment as c,Fragment as g,reactive as v,ref as m,useSlots as p,createVNode as h,toRef as x,createElementBlock as y,normalizeStyle as I,renderList as b,resolveDynamicComponent as w,isVNode as L}from"vue";import{createContext as k,useTransform as P,motion as T,isHTMLElement as M,wrap as E,useMotionValue as S,useDomRef as _,useInView as z,usePageInView as $,useReducedMotion as A,resize as j,useAnimationFrame as C,LayoutGroup as B,frame as D,animate as W,Motion as O,clamp as R}from"motion-v";const[X,Y]=k("TickerItemContext"),[H,q]=k("TickerInfo");function F(e,t,n,a,i){return{sign:1,direction:i,lengthProp:t,viewportLengthProp:n,paddingStartProp:a,measureItem:n=>({start:n[e],end:n[e]+n[t]}),getCumulativeInset:t=>{let n=0,a=t;for(;a;)n+=a[e],a=a.offsetParent;return n}}}const K=F("offsetLeft","offsetWidth","innerWidth","paddingLeft","right"),G=F("offsetTop","offsetHeight","innerHeight","paddingTop","bottom");function U(e,t){return((null==t?void 0:t.offsetWidth)??window.innerWidth)-(e.offsetLeft+e.offsetWidth)}const J={...K,sign:-1,direction:"left",paddingStartProp:"paddingRight",measureItem:(e,t)=>{const n=e.offsetWidth,a=U(e,t);return{start:a,end:a+n}},getCumulativeInset:e=>{let t=0,n=e;for(;n;)t+=U(n,n.offsetParent),n=n.offsetParent;return t}};function N(e,t){return"y"===e?G:"ltr"===t?K:J}const Q=e({__name:"TickerItem",props:{offset:{},axis:{},listSize:{default:0},bounds:{},numItems:{default:0},itemIndex:{},cloneIndex:{},alignItems:{},size:{default:"auto"},safeMargin:{},reproject:{type:Boolean,default:!0}},setup(e){const d=e,{state:f}=H(),c=t(()=>N(d.axis,f.direction).sign),g=P(()=>{if(!d.reproject)return 0;const{offset:e,bounds:t,listSize:n,safeMargin:a}=d,{start:i,end:o}=t;if(!i&&!o||!n)return 0;const r=e.get();if(r*c.value+o<=-f.inset-a)return n*c.value;if(a>0){const e=f.visibleLength-a-f.inset;if(r*c.value+t.start>=e)return-n*c.value}return 0}),v=P(()=>{const e=d.offset.get(),t=g.get();return(d.bounds.start||d.bounds.end)&&d.listSize?e*c.value+d.bounds.start+t*c.value:0}),m=t(()=>void 0===d.cloneIndex?{"aria-hidden":!1,"aria-posinset":d.itemIndex+1,"aria-setsize":d.numItems}:{"aria-hidden":!0}),p=t(()=>{const e="fill"===d.size,t="stretch"===d.alignItems?"100%":"fit-content";return{class:void 0===d.cloneIndex?"ticker-item":"clone-item",style:{flexGrow:0,flexShrink:0,position:"relative",flexBasis:e?"100%":void 0,display:e?"grid":void 0,gridTemplateColumns:e?"1fr":void 0,gridTemplateRows:e?"1fr":void 0,minWidth:e?0:void 0,minHeight:e?0:void 0,height:"x"===d.axis?t:void 0,width:"y"===d.axis?t:void 0,x:"x"===d.axis?g:0,y:"y"===d.axis?g:0},...m.value}}),{bounds:h,itemIndex:x,cloneIndex:y}=n(d);return Y({offset:v,bounds:h,projection:g,itemIndex:x,cloneIndex:y,props:p}),(e,t)=>"manual"===e.size?a(e.$slots,"default",{key:0}):(o(),i(r(T).li,l(s({key:1},p.value)),{default:u(()=>[a(e.$slots,"default")]),_:3},16))}});function V(e,t,n,a,i){let o=!1;d(e,(e,r,l)=>{if(!e)return;let s=!1;const u=new AbortController,d={signal:u.signal},c={...d,capture:!0},g="x"===t.value?"scrollLeft":"scrollTop",v="x"===t.value?"offsetLeft":"offsetTop",m="x"===t.value?"ArrowLeft":"ArrowUp",p="x"===t.value?"ArrowRight":"ArrowDown";let h=[],x=0;const y=async()=>{const t=h[x];t.focus(),await f(),n.set(-t[v]),e[g]=0},I=t=>{if("Tab"===t.key){t.preventDefault(),w();const n=Array.from(document.querySelectorAll('a, button, input, textarea, select, [tabindex]:not([tabindex="-1"]), [contenteditable="true"]')).filter(M);n.sort(Z);const a=n[t.shiftKey?0:n.length-1],i=t.shiftKey?n.length-1:0;if(e.contains(a))return void n[i].focus();{const a=n.indexOf(h[x]),i=t.shiftKey?-1:1;for(let t=a;t<n.length&&t>=0;t+=i){const a=n[t];if(!e.contains(a))return void a.focus()}}return}t.key===m?x--:t.key===p&&x++,x=E(0,h.length,x),y()},b=t=>{(!t.target||!(t.target instanceof HTMLElement)||!e.contains(t.target))&&w()},w=()=>{o&&(o=!1,i(!1),a.value.set(n.get()),window.removeEventListener("focus",b),window.removeEventListener("blur",b),e.removeEventListener("keydown",I))},L=t=>{const{target:n}=t;M(n)&&(o||o||(i(!0),o=!0,h=Array.from(e.querySelectorAll('.ticker-item a, .ticker-item button, .ticker-item input, .ticker-item textarea, .ticker-item select, .ticker-item [tabindex]:not([tabindex="-1"]), .ticker-item [contenteditable="true"]')).filter(M),x=0,y(),window.addEventListener("focus",b,c),window.addEventListener("blur",b,c),e.addEventListener("keydown",I,d)))},k=()=>{s&&(s=!1,e.removeEventListener("focus",L,!0),window.removeEventListener("pointermove",k,d))};window.addEventListener("keydown",()=>{s||(s=!0,e.addEventListener("focus",L,c),window.addEventListener("pointermove",k,d))},d),e.addEventListener("pointerdown",e=>{const t=e.target.closest('[aria-hidden="true"]');t&&t.removeAttribute("aria-hidden")},d),l(()=>{u.abort(),w()})},{flush:"post"})}function Z(e,t){return e.tabIndex>=1&&t.tabIndex>=1?e.tabIndex-t.tabIndex:e.tabIndex>=1&&t.tabIndex<=0?-1:t.tabIndex>=1&&e.tabIndex<=0?1:0}const ee={start:0,end:0},te={start:"flex-start",end:"flex-end"},ne={duration:.2,ease:"linear"},ae={type:"spring",stiffness:400,damping:40};function ie(e){return e.end-e.start}function oe(e){return e.length?e[e.length-1].end-e[0].start:0}function re(e,t,n){const a=oe(t),i=Math.max(...t.map(ie));let o=0,r=0;for(;r<e;)r=(a+n)*(o+1)-i,o++;return Math.max(o-1,0)}function le(e=[]){var t;const n=[];for(const a of e)if(a.type!==c)if(a.type===g){const e=Array.isArray(a.children)?a.children:null==(t=a.children)?void 0:t.default();n.push(...le(e))}else n.push(a);return n}function se(e){var t;const n=[];for(const a of e)if("Fragment"===a.type||a.type===g){const e=Array.isArray(a.children)?a.children:null==(t=a.children)?void 0:t.default();n.push(...se(e))}else n.push(a);return n}function ue(e,t,n){const a=Math.floor(e/n),i=a*n;let o=0;for(let n=0;n<t.length;n++){const{end:a}=t[n];if(o=n,a+i>e)break}return o+a*t.length}function de(e,t,n,a){var i;if(0===t.length)return 0;const o=t[t.length-1].end+n,r=a??e+((null==(i=t[0])?void 0:i.end)??0);let l=ue(e,t,o)+1,s=0,u=!1;for(;!u;){const{start:e,end:n}=t[E(0,t.length,l)],a=Math.floor(l/t.length)*o;s=e+a,n+a>r?u=!0:l++}return s}function fe(e,t,n,a,i){if(0===t.length)return 0;const o=t[t.length-1].end+n,r=a??e-(i??0);let l=ue(e,t,o),s=e,u=!1;for(;!u;){const{start:a,end:d}=t[E(0,t.length,l)],f=d-a,c=a+Math.floor(l/t.length)*o;r<=c+n||c>=e?(s=c,l--):r<=c?(s=c,u=!0):((i&&f>i||s===e&&r>=c)&&(s=c),u=!0)}return s}function ce(e){return"function"==typeof e||"[object Object]"===Object.prototype.toString.call(e)&&!L(e)}const ge=e({__name:"Ticker",props:{axis:{default:"x"},velocity:{default:50},hoverFactor:{default:1},gap:{default:10},align:{default:"center"},offset:{},itemSize:{default:"auto"},overflow:{type:Boolean,default:!1},loop:{type:Boolean,default:!0},safeMargin:{default:0},fade:{default:0},fadeTransition:{default:()=>ne},pageTransition:{default:()=>ae},_dragX:{type:[Object,Boolean]},_dragY:{type:[Object,Boolean]},snap:{type:[String,Boolean]},as:{default:"div"},style:{},onDragEnd:{},drag:{type:[Boolean,String]},dragConstraints:{type:[Boolean,Object]},dragMomentum:{type:Boolean}},setup(e){const n=e,l=v({direction:"ltr",visibleLength:0,inset:0,totalItemLength:0,containerLength:0,itemPositions:[],isMeasured:!1,maxInset:null}),f=t(()=>te[n.align]||n.align),c=t(()=>N(n.axis,l.direction).sign),L=m(!1),k=S(1),M=S(0),X=t(()=>n.offset??M),Y=P(()=>"rtl"===l.direction?E(l.totalItemLength+n.gap+l.inset,l.inset,X.value.get()):E(-l.totalItemLength-n.gap-l.inset,-l.inset,X.value.get())),H=S(0),F=t(()=>L.value?H:n.loop?Y:X.value),K=_(),G=_(),U=z(K,{margin:"100px"}),J=$(),Z=t(()=>U.value&&J.value),ne=A(),ae=p(),ie=t(()=>{var e;return le(null==(e=ae.default)?void 0:e.call(ae))});function ue(){if(!K.value||!G.value)return;const e=window.getComputedStyle(K.value).direction,{measureItem:t,lengthProp:a,viewportLengthProp:i,getCumulativeInset:o}=N(n.axis,e),{safeMargin:r,overflow:s,loop:u}=n,d="x"===he.value?"paddingLeft":"paddingTop",f="x"===he.value?"paddingRight":"paddingBottom",c=K.value,g=G.value.querySelectorAll(".ticker-item");if(!g.length)return;let v=!1;const m=[];for(let e=0;e<g.length;e++){const n=t(g[e],c);m.push(n);const a=l.itemPositions[e];(!a||n.start!==a.start||n.end!==a.end)&&(v=!0)}const p=Math.min(c[a],window[i]);let h=n.overflow?window[i]:p;r>0&&(h+=2*r);const x=oe(m),y=window.getComputedStyle(c),I=parseInt(y[d]??0),b=parseInt(y[f]??0),w=s?o(g[0]):I,L=!1===u?Math.max(0,x-p+I+b):null;(h!==l.visibleLength||x!==l.totalItemLength||w!==l.inset||l.itemPositions.length!==m.length||v)&&(l.direction=e,l.visibleLength=h,l.itemPositions=m,l.totalItemLength=x,l.inset=w,l.containerLength=p,l.maxInset=L,l.isMeasured=!0)}d([ie,Z,()=>n.overflow],(e,t,a)=>{if(!Z.value||!K.value)return;ue();const i=n.overflow?j(ue):void 0,o=j(K.value,ue);a(()=>{null==i||i(),o()})},{immediate:!0,flush:"post"});const ge=t(()=>l.totalItemLength>0);C((e,t)=>{if(ge.value&&Z.value&&X.value===M&&!ne.value){const e=t/1e3*(n.velocity*c.value*k.get());X.value.set(X.value.get()-e)}});const ve=t(()=>ge.value&&l.visibleLength?re(l.visibleLength,l.itemPositions,n.gap):0),me=t(()=>0===l.totalItemLength?0:(l.totalItemLength+n.gap)*(ve.value+1)),pe=t(()=>{if(!n.loop)return[];const e=[];for(let t=0;t<ve.value;t++){const a=[];ie.value.forEach((e,i)=>{let o;const r=l.itemPositions[i],s=(l.totalItemLength+n.gap)*(t+1),u=r?{start:r.start+s,end:r.end+s}:ee;a.push(h(Q,{key:`clone-${t}-${i}`,offset:F.value,axis:n.axis,listSize:me.value,itemIndex:i,cloneIndex:i,bounds:u,alignItems:f.value,size:n.itemSize,safeMargin:n.safeMargin,numItems:ie.value.length},ce(o=se([e]))?o:{default:()=>[o]}))});const i=`ticker-group-${t}`;e.push(h(B,{key:i,id:i},ce(a)?a:{default:()=>[a]}))}return e}),he=x(n,"axis");V(K,he,H,X,e=>{L.value=e});const xe={display:"flex",position:"relative"},ye={display:"flex",position:"relative",willChange:"transform",listStyleType:"none",padding:0,margin:0,justifyContent:"flex-start"};function Ie(e){return null!==l.maxInset?R(-l.maxInset,0,e):e}q({state:l,gap:t(()=>n.gap),clampOffset:Ie,renderedOffset:F});const be=t(()=>"x"===n.axis?null==n?void 0:n._dragX:null==n?void 0:n._dragY);let we=null;const Le=t(()=>null!==l.maxInset?"x"===he.value?c.value>0?{left:-1*l.maxInset,right:0}:{right:l.maxInset,left:0}:{top:-1*l.maxInset,bottom:0}:{});function ke(){we&&(we.stop(),we=null)}const Pe=t(()=>!n.onDragEnd&&n.drag&&be?()=>{be.value.jump(X.value.get()),ke()}:n.onPointerDown),Te=t(()=>!n.onDragEnd&&n.drag&&be.value?(e,{velocity:t})=>{const a=X.value.get();ke(),D.postRender(()=>{let e=a+t[he.value]*(n.snap?.3:.8);if(n.snap)if(t[he.value]<0)e=-de(-a,l.itemPositions,n.gap,-e);else if(t[he.value]>0)e=-fe(-a,l.itemPositions,n.gap,-e,l.containerLength);else{const t=-de(-a,l.itemPositions,n.gap,-a),i=-fe(-a,l.itemPositions,n.gap,-a,l.containerLength);e=Math.abs(a-t)<Math.abs(a-i)?t:i}const i=n.loop?{}:c.value>0?{max:0,min:Le.value["x"===he.value?"left":"top"]}:{min:0,max:Le.value.right};we=W(be,Ie(e*c.value)*c.value,n.snap?n.pageTransition:{type:"inertia",velocity:t[he.value],modifyTarget:()=>e,bounceDamping:40,bounceStiffness:400,...i})})}:n.onDragEnd),Me=S(n.loop?0:1),Ee=S(0),Se=t(()=>N(he.value,l.direction)),_e=t(()=>"number"==typeof n.fade?"px":""),ze=P(()=>`linear-gradient(to ${Se.value.direction}, rgba(0,0,0,${Me.get()}) 0px, black ${n.fade}${_e.value}, black calc(100% - ${n.fade}${_e.value}), rgba(0,0,0,${Ee.get()}) 100%)`),$e=t(()=>n.fade?{maskImage:ze,WebkitMaskImage:ze}:{}),Ae={start:!0,end:!1};return d(F,(e,t,a)=>{let i=()=>{};e&&(i=e.on("change",e=>{if(null===l.maxInset)return;const t=-1*l.maxInset;(e*=c.value)<0?Ae.start&&(W(Me,0,n.fadeTransition),Ae.start=!1):Ae.start||(W(Me,1,n.fadeTransition),Ae.start=!0),e>t?Ae.end&&(W(Ee,0,n.fadeTransition),Ae.end=!1):Ae.end||(W(Ee,1,n.fadeTransition),Ae.end=!0)})),a(i)},{immediate:!0}),(e,t)=>(o(),y(g,null,[h(r(O),s(e.$attrs,{ref_key:"containerRef",ref:K,as:e.as,style:{overflowX:e.overflow||"x"!==he.value?void 0:"clip",overflowY:e.overflow||"y"!==he.value?void 0:"clip",...xe,...n.style,...$e.value},drag:e.drag,_dragX:e._dragX,_dragY:e._dragY,"drag-constraints":Le.value,"drag-momentum":e.dragMomentum,onPointerenter:t[0]||(t[0]=()=>{r(W)(r(k),e.hoverFactor)}),onPointerleave:t[1]||(t[1]=()=>{r(W)(r(k),1)}),onPointerdown:Pe.value,onDragEnd:Te.value}),{default:u(()=>[h(r(T).ul,{ref_key:"listRef",ref:G,role:"group",style:I({...ye,flexDirection:"x"===he.value?"row":"column",gap:`${e.gap}px`,x:"x"===he.value?F.value:0,y:"y"===he.value?F.value:0,opacity:ge.value?1:0,alignItems:f.value,willChange:ge.value&&Z.value?"transform":void 0,width:"100%",height:"100%",maxHeight:"100%",maxWidth:"100%"})},{default:u(()=>[(o(!0),y(g,null,b(ie.value,(t,n)=>(o(),i(Q,{key:`original-${n}`,axis:he.value,offset:F.value,"list-size":me.value,"item-index":n,bounds:l.itemPositions[n]??r(ee),"align-items":f.value,size:e.itemSize,reproject:e.loop,"safe-margin":e.safeMargin,"num-items":ie.value.length},{default:u(()=>[(o(!0),y(g,null,b(r(se)([t]),(e,t)=>(o(),i(w(e),{key:t}))),128))]),_:2},1032,["axis","offset","list-size","item-index","bounds","align-items","size","reproject","safe-margin","num-items"]))),128)),(o(!0),y(g,null,b(pe.value,e=>(o(),i(w(e),{key:e.key}))),128))]),_:1},8,["style"])]),_:1},16,["as","style","drag","_dragX","_dragY","drag-constraints","drag-momentum","onPointerdown","onDragEnd"]),a(e.$slots,"after")],64))}}),ve=ge;export{ve as Ticker};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defineComponent as e,mergeDefaults as t,useSlots as n,watchEffect as r,ref as a,computed as l,createBlock as s,onMounted as o,openBlock as c,resolveDynamicComponent as i,unref as u,withCtx as p,createElementVNode as f,normalizeStyle as m,normalizeClass as h,createVNode as d}from"vue";import{useMotionValue as y,RowValue as v,animate as g,delayInMs as b}from"motion-v";function k(e,t){return e.length>t.length||e.length>0&&!t.startsWith(e)}function x(e,t,n){return e+(t-e)*n}function C(e,t,n,r,a){if(k(t,e))return n*a;if("natural"===r)return function(e,t,n){const r=t.length,a=e[r],l=e[r-1];if(!a)return n;const s=e.slice(0,r),o=s.lastIndexOf(" "),c=r-o-1,i=o+1,u=e.slice(r),p=u.indexOf(" "),f=-1===p?e.length:r+p,m=f-i;let h=1;l&&/[.!?]/.test(l)&&" "===a&&(h*=3);m<=3?h*=.7:(0===c&&" "!==a&&(h*=1.5),c===m-1&&(h*=1.4));if(c>0&&c<m-1&&m>3){h*=1-Math.min(c/m,.4)}w.has(a)&&(h*=1.5);M.has(a)&&(h*=1.5);/\d/.test(a)&&(h*=1.3);m>8&&(h*=1.3);a!==a.toLowerCase()&&(h*=1.25);const d=200;if(r>d){h*=1+Math.min((r-d)/1e3,.3)}const y=x(-.25,.25,Math.random());h*=1+y;const v=n*h;return Math.max(.2*n,v)}(e,t,n);if("number"==typeof r&&r>0){const e=n*(r/100);return n+x(-e,e,Math.random())}return n}const w=new Set([".",",","!","?",":",";","'",'"',"-","(",")"]),M=new Set(["!","@","#","$","%","^","&","*","(",")","_","+","{","}","|",":",'"',"<",">","?"]);function S(e,t,n,r){if("type"===n&&k(e,t)){if("all"===r)return t.slice(0,function(e,t){const n=Math.min(e.length,t.length);let r=0;for(let a=0;a<n&&e[a]===t[a];a++)r=a+1;return r}(e,t));if("word"===r){const t=function(e,t){let n=t-1;for(;n>=0&&/\s/.test(e[n]);)n--;for(;n>=0&&!/\s/.test(e[n]);)n--;return Math.max(0,n+1)}(e,e.length);return e.slice(0,t)}return e.slice(0,-1)}return t.slice(0,e.length+1)}const N={slow:130,normal:75,fast:30},_=e({__name:"Typewriter",props:t({as:{},speed:{},variance:{},play:{type:Boolean},cursorClassName:{},cursorStyle:{},textClassName:{},textStyle:{},cursorBlinkDuration:{},onComplete:{type:Function},replace:{},backspace:{},backspaceFactor:{}},{as:"span",speed:"normal",variance:"natural",cursorClassName:"motion-typewriter-cursor",play:!0,cursorBlinkDuration:.5,replace:"type",backspace:"character",backspaceFactor:.2}),setup(e){const t=e,k=n();function x(){var e;return((null==(e=null==k?void 0:k.default)?void 0:e.call(k))??[]).map(e=>"string"==typeof e.children?e.children:"").join("")}let w=x();const M=y("");r(()=>{const e=x();"all"===t.replace&&e!==w&&M.set(""),w=e});const _=a();let B=null;const F=l(()=>"number"==typeof t.speed?t.speed:N[t.speed]);function D(){_.value&&(B=g(_.value,{opacity:[1,1,0,0]},{duration:t.cursorBlinkDuration,times:[0,.5,.5,1],ease:"linear",repeat:1/0,repeatType:"reverse"}))}let O=null;function T(){null==O||O(),O=null}function j(){if(!t.play)return D(),void T();null==B||B.cancel();const e=x(),n=()=>{var n;const a=S(M.get(),e,t.replace,t.backspace);M.set(a),a!==e?r():(D(),null==(n=t.onComplete)||n.call(t))},r=()=>{O=b(n,C(e,M.get(),F.value,t.variance,t.backspaceFactor))};O||r()}return r(e=>{j(),e(T)}),o(()=>{j()}),(e,n)=>(c(),s(i(t.as),{"aria-label":u(w)},{default:p(()=>[f("span",{class:h(t.textClassName),style:m(t.textStyle)},[d(u(v),{value:u(M)},null,8,["value"])],6),f("span",{ref_key:"cursorRef",ref:_,class:h(t.cursorClassName),style:m({display:"inline-block",width:"2px",height:"1em",backgroundColor:"currentColor",position:"relative",top:"0.1em",left:"0.2em",...t.cursorStyle})},null,6)]),_:1},8,["aria-label"]))}});export{_ as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-plus-vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Motion Plus Vue",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -25,15 +25,21 @@
|
|
|
25
25
|
],
|
|
26
26
|
"typings": "./dist/index.d.ts",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"motion-v": "^1.
|
|
28
|
+
"motion-v": "^1.7.4",
|
|
29
29
|
"vue": ">=3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"motion-plus-dom": "^
|
|
32
|
+
"motion-plus-dom": "^2.0.2"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
36
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
37
|
+
"rollup": "^4.34.9",
|
|
38
|
+
"rollup-plugin-terser": "^7.0.2"
|
|
33
39
|
},
|
|
34
40
|
"size-limit": [
|
|
35
41
|
{
|
|
36
|
-
"path": "dist/
|
|
42
|
+
"path": "dist/size.animate-number.js",
|
|
37
43
|
"limit": "3.75 kb",
|
|
38
44
|
"ignore": [
|
|
39
45
|
"vue",
|
|
@@ -41,16 +47,32 @@
|
|
|
41
47
|
]
|
|
42
48
|
},
|
|
43
49
|
{
|
|
44
|
-
"path": "dist/
|
|
45
|
-
"limit": "3
|
|
50
|
+
"path": "dist/size.cursor.js",
|
|
51
|
+
"limit": "3 kb",
|
|
52
|
+
"ignore": [
|
|
53
|
+
"vue",
|
|
54
|
+
"motion-v"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"path": "dist/size.ticker.js",
|
|
59
|
+
"limit": "5.1 kb",
|
|
60
|
+
"ignore": [
|
|
61
|
+
"vue",
|
|
62
|
+
"motion-v"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "dist/size.typewriter.js",
|
|
67
|
+
"limit": "1.7 kb",
|
|
46
68
|
"ignore": [
|
|
47
69
|
"vue",
|
|
48
70
|
"motion-v"
|
|
49
71
|
]
|
|
50
72
|
},
|
|
51
73
|
{
|
|
52
|
-
"path": "dist/
|
|
53
|
-
"limit": "
|
|
74
|
+
"path": "dist/size.carousel.js",
|
|
75
|
+
"limit": "6.9 kb",
|
|
54
76
|
"ignore": [
|
|
55
77
|
"vue",
|
|
56
78
|
"motion-v"
|
|
@@ -60,6 +82,7 @@
|
|
|
60
82
|
"scripts": {
|
|
61
83
|
"clean": "rm -rf dist",
|
|
62
84
|
"build": "npm run clean && vite build",
|
|
85
|
+
"build:size": "rollup -c rollup.config.js",
|
|
63
86
|
"dev": "vite build --watch",
|
|
64
87
|
"test": "vitest",
|
|
65
88
|
"bumpp": "bumpp package.json",
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { CSSProperties } from 'vue';
|
|
2
|
-
import { MotionValue } from 'motion-v';
|
|
3
|
-
import { ItemSize } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Props for the Ticker component.
|
|
6
|
-
*/
|
|
7
|
-
export interface TickerProps {
|
|
8
|
-
/**
|
|
9
|
-
* The axis along which the ticker scrolls. Defaults to "x".
|
|
10
|
-
*/
|
|
11
|
-
axis?: 'x' | 'y';
|
|
12
|
-
style?: CSSProperties;
|
|
13
|
-
/**
|
|
14
|
-
* The velocity of the ticker scroll in pixels per second. Defaults to 50.
|
|
15
|
-
*/
|
|
16
|
-
velocity?: number;
|
|
17
|
-
/**
|
|
18
|
-
* Factor by which the velocity is multiplied when the ticker is hovered. Defaults to 1 (no change).
|
|
19
|
-
*/
|
|
20
|
-
hoverFactor?: number;
|
|
21
|
-
/**
|
|
22
|
-
* The gap between ticker items in pixels. Defaults to 10.
|
|
23
|
-
*/
|
|
24
|
-
gap?: number;
|
|
25
|
-
/**
|
|
26
|
-
* Alignment of items within the ticker. Defaults to "center".
|
|
27
|
-
*/
|
|
28
|
-
align?: 'start' | 'center' | 'end' | 'stretch';
|
|
29
|
-
/**
|
|
30
|
-
* An optional MotionValue to control the ticker's offset externally.
|
|
31
|
-
*/
|
|
32
|
-
offset?: MotionValue<number>;
|
|
33
|
-
/**
|
|
34
|
-
* The size of the ticker items. Defaults to "auto".
|
|
35
|
-
*/
|
|
36
|
-
itemSize?: ItemSize;
|
|
37
|
-
/**
|
|
38
|
-
* Show items that overflow the container.
|
|
39
|
-
*/
|
|
40
|
-
overflow?: boolean;
|
|
41
|
-
}
|
|
42
|
-
declare const _default: import('vue').DefineComponent<TickerProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<TickerProps> & Readonly<{}>, {
|
|
43
|
-
gap: number;
|
|
44
|
-
overflow: boolean;
|
|
45
|
-
velocity: number;
|
|
46
|
-
axis: "x" | "y";
|
|
47
|
-
itemSize: ItemSize;
|
|
48
|
-
hoverFactor: number;
|
|
49
|
-
align: "start" | "center" | "end" | "stretch";
|
|
50
|
-
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
51
|
-
export default _default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useItemOffset(): import('motion-v/es').MotionValue<number>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { invariant as t } from "motion-v";
|
|
2
|
-
import { useTickerItemContext as o } from "./context.mjs";
|
|
3
|
-
function n() {
|
|
4
|
-
const e = o(null);
|
|
5
|
-
return t(
|
|
6
|
-
!!e,
|
|
7
|
-
"useItemOffset must be used within a TickerItem"
|
|
8
|
-
), e == null ? void 0 : e.offset;
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
n as useItemOffset
|
|
12
|
-
};
|