{"version":3,"file":"Ticker.CUehBTdH.mjs","names":["useState","useRef","startTransition"],"sources":["https:/framerusercontent.com/modules/hPrJV8L2kmwIO5t82MoV/MqDdqfDqKJu9cthNjlSN/Ticker.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{motion,useMotionValue,useAnimationFrame}from\"framer-motion\";import{useRef,useState,useLayoutEffect,startTransition}from\"react\";/**\n * Ticker component that scrolls children horizontally\n *\n * @framerIntrinsicWidth 800\n * @framerIntrinsicHeight 100\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */function Ticker(props){const{children,speed=50,direction=\"left\",gap=40,pauseOnHover=true,fadeWidth=100,fadeLeft=true,fadeRight=true,fadeLeftColor=\"#FFFFFF\",fadeRightColor=\"#FFFFFF\",animationEnabled=true,showDots=false,dotSize=8,dotColor=\"#CCCCCC\",dotActiveColor=\"#000000\"}=props;const x=useMotionValue(0);const[isDragging,setIsDragging]=useState(false);const[isPaused,setIsPaused]=useState(false);const[activeDot,setActiveDot]=useState(0);const[itemCount,setItemCount]=useState(0);const itemOffsetsRef=useRef([]);const containerRef=useRef(null);const contentRef=useRef(null);// 內容區塊共用樣式：pointerEvents none 讓拖曳不會抓到圖片\nconst contentStyle={display:\"flex\",gap:`${gap}px`,minHeight:\"5px\",userSelect:\"none\",WebkitUserSelect:\"none\",// @ts-ignore - 非標準屬性，停用圖片原生拖曳\nWebkitUserDrag:\"none\",pointerEvents:\"none\"};// 量測 slot 裡真正的「物件」節點數量與各自位置\nconst measureItems=()=>{const content=contentRef.current;if(!content)return;let nodes=Array.from(content.children);// 若 slot 只連了一個外層容器(例如一個 Stack)，往內取它的子層當物件\nif(nodes.length===1&&nodes[0].children.length>1){nodes=Array.from(nodes[0].children);}const baseLeft=content.getBoundingClientRect().left;itemOffsetsRef.current=nodes.map(n=>n.getBoundingClientRect().left-baseLeft);setItemCount(nodes.length);};useLayoutEffect(()=>{measureItems();// 圖片/字體載入後再量一次，避免寬度抓不準\nconst id=requestAnimationFrame(measureItems);return()=>cancelAnimationFrame(id);},[children,gap]);// 依目前捲動位置算出落在第幾個物件\nconst updateActiveDot=currentX=>{if(!showDots||!contentRef.current)return;const width=contentRef.current.offsetWidth;const offsets=itemOffsetsRef.current;if(width<=0||offsets.length===0)return;const scrollPos=(-currentX%width+width)%width;let active=0;for(let i=0;i<offsets.length;i++){if(scrollPos>=offsets[i])active=i;else break;}if(active!==activeDot)startTransition(()=>setActiveDot(active));};useAnimationFrame((t,delta)=>{// 動畫關閉、拖曳中、或 hover 暫停時，不自動捲動（但拖曳仍可運作）\nif(!animationEnabled||isDragging||isPaused)return;if(!contentRef.current)return;const velocity=direction===\"left\"?-speed:speed;const movement=velocity*delta/1e3;let currentX=x.get();currentX+=movement;// 依單一內容寬度重設位置，達成無縫循環\nconst singleContentWidth=contentRef.current.offsetWidth;if(direction===\"left\"&&currentX<=-singleContentWidth){currentX+=singleContentWidth;}else if(direction===\"right\"&&currentX>=0){currentX-=singleContentWidth;}x.set(currentX);// 更新 dot 位置\nupdateActiveDot(currentX);});return /*#__PURE__*/_jsxs(\"div\",{style:{width:\"100%\",height:\"100%\",minHeight:\"5px\",overflow:\"hidden\",position:\"relative\",display:\"flex\",alignItems:\"center\",cursor:isDragging?\"grabbing\":\"grab\"},children:[/*#__PURE__*/_jsxs(motion.div,{ref:containerRef,style:{display:\"flex\",gap:`${gap}px`,position:\"absolute\",whiteSpace:\"nowrap\",minHeight:\"5px\",x},drag:\"x\",dragConstraints:{left:-1e4,right:1e4},dragElastic:0,dragTransition:{power:.2,timeConstant:200},onDragStart:()=>startTransition(()=>setIsDragging(true)),onDragEnd:()=>{startTransition(()=>setIsDragging(false));// 不貼齊回邊界，改為收進可無縫循環的範圍，保留拖曳後的位置\nif(contentRef.current){const singleContentWidth=contentRef.current.offsetWidth;if(singleContentWidth>0){let wrappedX=x.get()%singleContentWidth;if(wrappedX>0)wrappedX-=singleContentWidth;x.set(wrappedX);// 更新 dot 位置\nupdateActiveDot(wrappedX);}}},onHoverStart:()=>pauseOnHover&&startTransition(()=>setIsPaused(true)),onHoverEnd:()=>pauseOnHover&&startTransition(()=>setIsPaused(false)),children:[/*#__PURE__*/_jsx(\"div\",{ref:contentRef,style:contentStyle,children:children||/*#__PURE__*/_jsx(\"div\",{style:{minWidth:\"5px\",minHeight:\"5px\"}})}),/*#__PURE__*/_jsx(\"div\",{style:contentStyle,children:children||/*#__PURE__*/_jsx(\"div\",{style:{minWidth:\"5px\",minHeight:\"5px\"}})}),/*#__PURE__*/_jsx(\"div\",{style:contentStyle,children:children||/*#__PURE__*/_jsx(\"div\",{style:{minWidth:\"5px\",minHeight:\"5px\"}})}),/*#__PURE__*/_jsx(\"div\",{style:contentStyle,children:children||/*#__PURE__*/_jsx(\"div\",{style:{minWidth:\"5px\",minHeight:\"5px\"}})})]}),fadeLeft&&/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",left:0,top:0,bottom:0,width:`${fadeWidth}px`,background:`linear-gradient(to right, ${fadeLeftColor} 0%, transparent 100%)`,pointerEvents:\"none\",zIndex:1}}),fadeRight&&/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",right:0,top:0,bottom:0,width:`${fadeWidth}px`,background:`linear-gradient(to left, ${fadeRightColor} 0%, transparent 100%)`,pointerEvents:\"none\",zIndex:1}}),showDots&&itemCount>0&&/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",bottom:\"16px\",left:\"50%\",transform:\"translateX(-50%)\",display:\"flex\",gap:`${dotSize}px`,pointerEvents:\"none\",zIndex:2},children:Array.from({length:itemCount}).map((_,index)=>/*#__PURE__*/_jsx(\"div\",{style:{width:`${dotSize}px`,height:`${dotSize}px`,borderRadius:\"50%\",backgroundColor:index===activeDot?dotActiveColor:dotColor,transition:\"background-color 0.3s ease\"}},index))})]});}export default Ticker;addPropertyControls(Ticker,{children:{type:ControlType.Slot,title:\"Content\"},animationEnabled:{type:ControlType.Boolean,title:\"Animation\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},speed:{type:ControlType.Number,title:\"Speed\",defaultValue:50,min:1,max:200,step:1},direction:{type:ControlType.Enum,title:\"Direction\",options:[\"left\",\"right\"],optionTitles:[\"Left\",\"Right\"],defaultValue:\"left\",displaySegmentedControl:true},gap:{type:ControlType.Number,title:\"Gap\",defaultValue:40,min:0,max:200,step:1,unit:\"px\"},pauseOnHover:{type:ControlType.Boolean,title:\"Pause on Hover\",defaultValue:true,enabledTitle:\"Yes\",disabledTitle:\"No\"},fadeLeft:{type:ControlType.Boolean,title:\"Fade Left\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},fadeRight:{type:ControlType.Boolean,title:\"Fade Right\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},fadeWidth:{type:ControlType.Number,title:\"Fade Width\",defaultValue:100,min:0,max:300,step:10,unit:\"px\"},fadeLeftColor:{type:ControlType.Color,title:\"Left Gradient\",defaultValue:\"#FFFFFF\",hidden:({fadeLeft})=>!fadeLeft},fadeRightColor:{type:ControlType.Color,title:\"Right Gradient\",defaultValue:\"#FFFFFF\",hidden:({fadeRight})=>!fadeRight},showDots:{type:ControlType.Boolean,title:\"Show Dots\",defaultValue:false,enabledTitle:\"Show\",disabledTitle:\"Hide\"},dotSize:{type:ControlType.Number,title:\"Dot Size\",defaultValue:8,min:4,max:20,step:1,unit:\"px\",hidden:({showDots})=>!showDots},dotColor:{type:ControlType.Color,title:\"Dot Color\",defaultValue:\"#CCCCCC\",hidden:({showDots})=>!showDots},dotActiveColor:{type:ControlType.Color,title:\"Active Dot\",defaultValue:\"#000000\",hidden:({showDots})=>!showDots}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Ticker\",\"slots\":[\"children\"],\"annotations\":{\"framerIntrinsicHeight\":\"100\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"fixed\",\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