You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vue-scroll-picker

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-scroll-picker - npm Package Compare versions

Comparing version

to
1.0.0-rc.2

6

lib/index.d.ts
import { App, Plugin } from 'vue';
import ScrollPicker from './components/picker';
import VueScrollPicker from './components/picker';
export declare function install(app: App): void;
declare const plugin: Plugin;
export default plugin;
export interface ScrollPickerOption {
export interface VueScrollPickerOption {
name: string;
value: any;
}
export { ScrollPicker, };
export { VueScrollPicker, };

@@ -1,2 +0,2 @@

import{defineComponent as t,h as e,renderSlot as i}from"vue";function s(t){return t.map((t=>{switch(typeof t){case"string":return{value:t,name:t};case"number":case"boolean":return{value:t,name:`${t}`}}return t}))}function n(t){return t.changedTouches||t.touches}function l(t){return n(t)?t.changedTouches[0]||t.touches[0]:t}var o=t({props:{modelValue:null,options:{type:Array,default:()=>[]},dragSensitivity:{type:Number,default:1.7},touchSensitivity:{type:Number,default:1.7},scrollSensitivity:{type:Number,default:1},empty:{type:String,default:"No Items"},placeholder:{type:String,default:null}},data(){var t,e;const i=s(this.options);let n=i.findIndex((t=>t.value==this.modelValue));-1===n&&!this.placeholder&&!this.$slots.placeholder&&this.options.length>0&&(n=0);return{refItems:[],internalOptions:i,internalIndex:n,internalValue:null!=(e=null==(t=i[n])?void 0:t.value)?e:null,pivots:[],pivotsMin:0,pivotsMax:0,scroll:null,scrollOffsetTop:0,scrollMin:0,scrollMax:0,transitioning:!1,transitionTimer:null,start:null,isMouseDown:!1,isDragging:!1}},beforeUpdate(){this.refItems=[]},mounted(){this.calculatePivots(),this.scroll=this.findScrollByIndex(this.internalIndex),this.internalValue!==this.modelValue&&this.$emit("update:modelValue",this.internalValue);const t=this.$el;t.addEventListener("touchstart",this.onStart),t.addEventListener("touchmove",this.onMove),t.addEventListener("touchend",this.onEnd),t.addEventListener("touchcancel",this.onCancel),t.addEventListener("mousewheel",this.onWheel),t.addEventListener("DOMMouseScroll",this.onWheel),t.addEventListener("wheel",this.onWheel),t.addEventListener("mousedown",this.onStart),t.addEventListener("mousemove",this.onMove),t.addEventListener("mouseup",this.onEnd),t.addEventListener("mouseleave",this.onCancel)},beforeUnmount(){const t=this.$el;t.removeEventListener("touchstart",this.onStart),t.removeEventListener("touchmove",this.onMove),t.removeEventListener("touchend",this.onEnd),t.removeEventListener("touchcancel",this.onCancel),t.removeEventListener("mousewheel",this.onWheel),t.removeEventListener("DOMMouseScroll",this.onWheel),t.removeEventListener("wheel",this.onWheel),t.removeEventListener("mousedown",this.onStart),t.removeEventListener("mousemove",this.onMove),t.removeEventListener("mouseup",this.onEnd),t.removeEventListener("mouseleave",this.onCancel)},watch:{modelValue(t){if(null==t&&this.hasPlaceholder)return void this.correction(-1);const e=this.internalOptions.findIndex((e=>e.value==t));-1!==e?this.internalIndex!==e&&this.correction(e):this.$emit("update:modelValue",this.internalValue)},options:{handler(t){var e,i;const n=this.internalOptions=s(t);let l=n.findIndex((t=>t.value==this.modelValue));-1===l&&!this.hasPlaceholder&&this.options.length>0&&(l=0);const o=null!=(i=null==(e=n[l])?void 0:e.value)?i:null;this.$nextTick((()=>{this.calculatePivots(),this.scroll=this.findScrollByIndex(l),this.internalIndex=l,this.internalValue!==o&&this.$emit("update:modelValue",this.internalValue=o)}))},deep:!0}},computed:{hasPlaceholder(){return!(!this.placeholder&&!this.$slots.placeholder)}},methods:{setRefItem(t){this.refItems.push(t)},calculatePivots(){const t=this.$refs.rotator,e=this.$refs.layerSelection,i=t.getBoundingClientRect().top,s=this.pivots=this.refItems.map((t=>function(t){const{top:e,bottom:i}=t.getBoundingClientRect();return(e+i)/2}(t)-i)).sort(((t,e)=>t-e)),n=this.pivotsMin=Math.min(...s),l=this.pivotsMax=Math.max(...s),o=this.scrollOffsetTop=e.offsetTop+e.offsetHeight/2;this.scrollMin=o-n,this.scrollMax=o-l},sanitizeInternalIndex(t){return Math.min(Math.max(t,this.hasPlaceholder?-1:0),this.internalOptions.length-1)},findIndexFromScroll(t){let e=null,i=0;return this.pivots.forEach(((s,n)=>{const l=s+t-this.scrollOffsetTop;(null===e||Math.abs(e)>Math.abs(l))&&(i=n,e=l)})),this.hasPlaceholder||0===this.options.length?i-1:i},findScrollByIndex(t){let e=t;return(this.hasPlaceholder||0===this.options.length)&&e++,t>-1&&e in this.pivots?this.scrollOffsetTop-this.pivots[e]:this.scrollOffsetTop-this.pivotsMin},onWheel(t){var e,i;if(this.scroll>=this.scrollMin&&t.deltaY<0)return;if(this.scroll<=this.scrollMax&&t.deltaY>0)return;t.preventDefault(),this.scroll=Math.min(Math.max(this.scroll-t.deltaY*this.scrollSensitivity,this.scrollMax),this.scrollMin);const s=this.sanitizeInternalIndex(this.findIndexFromScroll(this.scroll)),n=null!=(i=null==(e=this.internalOptions[s])?void 0:e.value)?i:null;this.internalIndex=s,this.internalValue!==n&&this.$emit("update:modelValue",this.internalValue=n),this.onAfterWheel((()=>{this.correction(this.findIndexFromScroll(this.scroll))}))},onAfterWheel:function(t,e=83){let i=null;return function(){i&&(clearTimeout(i),i=null);const s=this,n=arguments;i=setTimeout((()=>t.apply(s,n)),e)}}((function(t){t()}),200),onStart(t){t.cancelable&&t.preventDefault();const{clientY:e}=l(t);this.start=[this.scroll,e],n(t)||(this.isMouseDown=!0),this.isDragging=!1},onMove(t){if(t.cancelable&&t.preventDefault(),!this.start)return;const{clientY:e}=l(t),i=e-this.start[1];Math.abs(i)>1.5&&(this.isDragging=!0),this.scroll=this.start[0]+i*(n(t)?this.touchSensitivity:this.dragSensitivity)},onEnd(t){t.cancelable&&t.preventDefault(),this.isDragging?this.correction(this.findIndexFromScroll(this.scroll)):this.onClick(t),this.start=null,this.isDragging=!1,this.isMouseDown=!1},onCancel(t){t.cancelable&&t.preventDefault(),this.correction(this.findIndexFromScroll(this.scroll)),this.start=null,this.isMouseDown=!1,this.isDragging=!1},onClick(t){const e=this.$refs.layerTop,i=this.$refs.layerBottom,s=l(t),n=s.clientX,o=s.clientY,r=e.getBoundingClientRect(),a=i.getBoundingClientRect();r.left<=n&&n<=r.right&&r.top<=o&&o<=r.bottom?this.correction(this.internalIndex-1):a.left<=n&&n<=a.right&&a.top<=o&&o<=a.bottom&&this.correction(this.internalIndex+1)},correction(t){var e,i;const s=this.sanitizeInternalIndex(t),n=null!=(i=null==(e=this.internalOptions[s])?void 0:e.value)?i:null;this.scroll=this.findScrollByIndex(s),this.transitioning=!0,this.transitionTimer&&(clearTimeout(this.transitionTimer),this.transitionTimer=null),this.transitionTimer=setTimeout((()=>{this.transitioning=!1,this.transitionTimer=null,this.internalIndex=s,this.internalValue!==n&&this.$emit("update:modelValue",this.internalValue=n)}),100)}},render(){let t=[];return this.hasPlaceholder?t.push(e("div",{class:["vue-scroll-picker-item","vue-scroll-picker-item-placeholder",{"vue-scroll-picker-item-selected":-1===this.internalIndex}],ref:t=>t&&this.setRefItem(t)},i(this.$slots,"placeholder",{text:this.placeholder},(()=>[this.placeholder])))):0===this.internalOptions.length&&t.push(e("div",{class:["vue-scroll-picker-item","vue-scroll-picker-item-empty","vue-scroll-picker-item-selected"],ref:t=>t&&this.setRefItem(t)},i(this.$slots,"empty",{text:this.empty},(()=>[this.empty])))),t=t.concat(this.internalOptions.map(((t,s)=>e("div",{class:["vue-scroll-picker-item",{"vue-scroll-picker-item-selected":this.internalIndex===s}],key:t.value,ref:t=>t&&this.setRefItem(t)},i(this.$slots,"default",{option:t},(()=>[t.name])))))),e("div",{class:["vue-scroll-picker"]},[e("div",{ref:"rotator",class:["vue-scroll-picker-rotator",{"vue-scroll-picker-rotator-transition":this.transitioning}],style:"number"==typeof this.scroll?{top:`${this.scroll}px`}:{}},t),e("div",{class:["vue-scroll-picker-layer"]},[e("div",{class:["vue-scroll-picker-layer-top"],ref:"layerTop"}),e("div",{class:["vue-scroll-picker-layer-selection"],ref:"layerSelection"}),e("div",{class:["vue-scroll-picker-layer-bottom"],ref:"layerBottom"})])])}});function r(t){t.component("ScrollPicker",o)}"undefined"!=typeof window&&window.Vue&&r(window.Vue);export{o as ScrollPicker,r as install};
import{defineComponent as t,h as e,renderSlot as i}from"vue";function s(t){return t.map((t=>{switch(typeof t){case"string":return{value:t,name:t};case"number":case"boolean":return{value:t,name:`${t}`}}return t}))}function n(t){return t.changedTouches||t.touches}function l(t){return n(t)?t.changedTouches[0]||t.touches[0]:t}var o=t({props:{modelValue:null,options:{type:Array,default:()=>[]},dragSensitivity:{type:Number,default:1.7},touchSensitivity:{type:Number,default:1.7},scrollSensitivity:{type:Number,default:1},empty:{type:String,default:"No Items"},placeholder:{type:String,default:null}},data(){var t,e;const i=s(this.options);let n=i.findIndex((t=>t.value==this.modelValue));-1===n&&!this.placeholder&&!this.$slots.placeholder&&this.options.length>0&&(n=0);return{refItems:[],internalOptions:i,internalIndex:n,internalValue:null!=(e=null==(t=i[n])?void 0:t.value)?e:null,pivots:[],pivotsMin:0,pivotsMax:0,scroll:null,scrollOffsetTop:0,scrollMin:0,scrollMax:0,transitioning:!1,transitionTimer:null,start:null,isMouseDown:!1,isDragging:!1}},beforeUpdate(){this.refItems=[]},mounted(){this.calculatePivots(),this.scroll=this.findScrollByIndex(this.internalIndex),this.internalValue!==this.modelValue&&this.$emit("update:modelValue",this.internalValue);const t=this.$el;t.addEventListener("touchstart",this.onStart),t.addEventListener("touchmove",this.onMove),t.addEventListener("touchend",this.onEnd),t.addEventListener("touchcancel",this.onCancel),t.addEventListener("mousewheel",this.onWheel),t.addEventListener("DOMMouseScroll",this.onWheel),t.addEventListener("wheel",this.onWheel),t.addEventListener("mousedown",this.onStart),t.addEventListener("mousemove",this.onMove),t.addEventListener("mouseup",this.onEnd),t.addEventListener("mouseleave",this.onCancel)},beforeUnmount(){const t=this.$el;t.removeEventListener("touchstart",this.onStart),t.removeEventListener("touchmove",this.onMove),t.removeEventListener("touchend",this.onEnd),t.removeEventListener("touchcancel",this.onCancel),t.removeEventListener("mousewheel",this.onWheel),t.removeEventListener("DOMMouseScroll",this.onWheel),t.removeEventListener("wheel",this.onWheel),t.removeEventListener("mousedown",this.onStart),t.removeEventListener("mousemove",this.onMove),t.removeEventListener("mouseup",this.onEnd),t.removeEventListener("mouseleave",this.onCancel)},watch:{modelValue(t){if(null==t&&this.hasPlaceholder)return void this.correction(-1);const e=this.internalOptions.findIndex((e=>e.value==t));-1!==e?this.internalIndex!==e&&this.correction(e):this.$emit("update:modelValue",this.internalValue)},options:{handler(t){var e,i;const n=this.internalOptions=s(t);let l=n.findIndex((t=>t.value==this.modelValue));-1===l&&!this.hasPlaceholder&&this.options.length>0&&(l=0);const o=null!=(i=null==(e=n[l])?void 0:e.value)?i:null;this.$nextTick((()=>{this.calculatePivots(),this.scroll=this.findScrollByIndex(l),this.internalIndex=l,this.internalValue!==o&&this.$emit("update:modelValue",this.internalValue=o)}))},deep:!0}},computed:{hasPlaceholder(){return!(!this.placeholder&&!this.$slots.placeholder)}},methods:{setRefItem(t){this.refItems.push(t)},calculatePivots(){const t=this.$refs.rotator,e=this.$refs.layerSelection,i=t.getBoundingClientRect().top,s=this.pivots=this.refItems.map((t=>function(t){const{top:e,bottom:i}=t.getBoundingClientRect();return(e+i)/2}(t)-i)).sort(((t,e)=>t-e)),n=this.pivotsMin=Math.min(...s),l=this.pivotsMax=Math.max(...s),o=this.scrollOffsetTop=e.offsetTop+e.offsetHeight/2;this.scrollMin=o-n,this.scrollMax=o-l},sanitizeInternalIndex(t){return Math.min(Math.max(t,this.hasPlaceholder?-1:0),this.internalOptions.length-1)},findIndexFromScroll(t){let e=null,i=0;return this.pivots.forEach(((s,n)=>{const l=s+t-this.scrollOffsetTop;(null===e||Math.abs(e)>Math.abs(l))&&(i=n,e=l)})),this.hasPlaceholder||0===this.options.length?i-1:i},findScrollByIndex(t){let e=t;return(this.hasPlaceholder||0===this.options.length)&&e++,t>-1&&e in this.pivots?this.scrollOffsetTop-this.pivots[e]:this.scrollOffsetTop-this.pivotsMin},onWheel(t){var e,i;if(this.scroll>=this.scrollMin&&t.deltaY<0)return;if(this.scroll<=this.scrollMax&&t.deltaY>0)return;t.preventDefault(),this.scroll=Math.min(Math.max(this.scroll-t.deltaY*this.scrollSensitivity,this.scrollMax),this.scrollMin);const s=this.sanitizeInternalIndex(this.findIndexFromScroll(this.scroll)),n=null!=(i=null==(e=this.internalOptions[s])?void 0:e.value)?i:null;this.internalIndex=s,this.internalValue!==n&&this.$emit("update:modelValue",this.internalValue=n),this.onAfterWheel((()=>{this.correction(this.findIndexFromScroll(this.scroll))}))},onAfterWheel:function(t,e=83){let i=null;return function(){i&&(clearTimeout(i),i=null);const s=this,n=arguments;i=setTimeout((()=>t.apply(s,n)),e)}}((function(t){t()}),200),onStart(t){t.cancelable&&t.preventDefault();const{clientY:e}=l(t);this.start=[this.scroll,e],n(t)||(this.isMouseDown=!0),this.isDragging=!1},onMove(t){if(t.cancelable&&t.preventDefault(),!this.start)return;const{clientY:e}=l(t),i=e-this.start[1];Math.abs(i)>1.5&&(this.isDragging=!0),this.scroll=this.start[0]+i*(n(t)?this.touchSensitivity:this.dragSensitivity)},onEnd(t){t.cancelable&&t.preventDefault(),this.isDragging?this.correction(this.findIndexFromScroll(this.scroll)):this.onClick(t),this.start=null,this.isDragging=!1,this.isMouseDown=!1},onCancel(t){t.cancelable&&t.preventDefault(),this.correction(this.findIndexFromScroll(this.scroll)),this.start=null,this.isMouseDown=!1,this.isDragging=!1},onClick(t){const e=this.$refs.layerTop,i=this.$refs.layerBottom,s=l(t),n=s.clientX,o=s.clientY,r=e.getBoundingClientRect(),a=i.getBoundingClientRect();r.left<=n&&n<=r.right&&r.top<=o&&o<=r.bottom?this.correction(this.internalIndex-1):a.left<=n&&n<=a.right&&a.top<=o&&o<=a.bottom&&this.correction(this.internalIndex+1)},correction(t){var e,i;const s=this.sanitizeInternalIndex(t),n=null!=(i=null==(e=this.internalOptions[s])?void 0:e.value)?i:null;this.scroll=this.findScrollByIndex(s),this.transitioning=!0,this.transitionTimer&&(clearTimeout(this.transitionTimer),this.transitionTimer=null),this.transitionTimer=setTimeout((()=>{this.transitioning=!1,this.transitionTimer=null,this.internalIndex=s,this.internalValue!==n&&this.$emit("update:modelValue",this.internalValue=n)}),100)}},render(){let t=[];return this.hasPlaceholder?t.push(e("div",{class:["vue-scroll-picker-item","vue-scroll-picker-item-placeholder",{"vue-scroll-picker-item-selected":-1===this.internalIndex}],ref:t=>t&&this.setRefItem(t)},i(this.$slots,"placeholder",{text:this.placeholder},(()=>[this.placeholder])))):0===this.internalOptions.length&&t.push(e("div",{class:["vue-scroll-picker-item","vue-scroll-picker-item-empty","vue-scroll-picker-item-selected"],ref:t=>t&&this.setRefItem(t)},i(this.$slots,"empty",{text:this.empty},(()=>[this.empty])))),t=t.concat(this.internalOptions.map(((t,s)=>e("div",{class:["vue-scroll-picker-item",{"vue-scroll-picker-item-selected":this.internalIndex===s}],key:t.value,ref:t=>t&&this.setRefItem(t)},i(this.$slots,"default",{option:t},(()=>[t.name])))))),e("div",{class:["vue-scroll-picker"]},[e("div",{ref:"rotator",class:["vue-scroll-picker-rotator",{"vue-scroll-picker-rotator-transition":this.transitioning}],style:"number"==typeof this.scroll?{top:`${this.scroll}px`}:{}},t),e("div",{class:["vue-scroll-picker-layer"]},[e("div",{class:["vue-scroll-picker-layer-top"],ref:"layerTop"}),e("div",{class:["vue-scroll-picker-layer-selection"],ref:"layerSelection"}),e("div",{class:["vue-scroll-picker-layer-bottom"],ref:"layerBottom"})])])}});function r(t){t.component("VueScrollPicker",o)}"undefined"!=typeof window&&window.Vue&&r(window.Vue);const a={install:r};export default a;export{o as VueScrollPicker,r as install};
//# sourceMappingURL=vue-scroll-picker.es.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VueScrollPicker={},e.Vue)}(this,(function(e,t){"use strict";function i(e){return e.map((e=>{switch(typeof e){case"string":return{value:e,name:e};case"number":case"boolean":return{value:e,name:`${e}`}}return e}))}function n(e){return e.changedTouches||e.touches}function s(e){return n(e)?e.changedTouches[0]||e.touches[0]:e}var l=t.defineComponent({props:{modelValue:null,options:{type:Array,default:()=>[]},dragSensitivity:{type:Number,default:1.7},touchSensitivity:{type:Number,default:1.7},scrollSensitivity:{type:Number,default:1},empty:{type:String,default:"No Items"},placeholder:{type:String,default:null}},data(){var e,t;const n=i(this.options);let s=n.findIndex((e=>e.value==this.modelValue));-1===s&&!this.placeholder&&!this.$slots.placeholder&&this.options.length>0&&(s=0);return{refItems:[],internalOptions:n,internalIndex:s,internalValue:null!=(t=null==(e=n[s])?void 0:e.value)?t:null,pivots:[],pivotsMin:0,pivotsMax:0,scroll:null,scrollOffsetTop:0,scrollMin:0,scrollMax:0,transitioning:!1,transitionTimer:null,start:null,isMouseDown:!1,isDragging:!1}},beforeUpdate(){this.refItems=[]},mounted(){this.calculatePivots(),this.scroll=this.findScrollByIndex(this.internalIndex),this.internalValue!==this.modelValue&&this.$emit("update:modelValue",this.internalValue);const e=this.$el;e.addEventListener("touchstart",this.onStart),e.addEventListener("touchmove",this.onMove),e.addEventListener("touchend",this.onEnd),e.addEventListener("touchcancel",this.onCancel),e.addEventListener("mousewheel",this.onWheel),e.addEventListener("DOMMouseScroll",this.onWheel),e.addEventListener("wheel",this.onWheel),e.addEventListener("mousedown",this.onStart),e.addEventListener("mousemove",this.onMove),e.addEventListener("mouseup",this.onEnd),e.addEventListener("mouseleave",this.onCancel)},beforeUnmount(){const e=this.$el;e.removeEventListener("touchstart",this.onStart),e.removeEventListener("touchmove",this.onMove),e.removeEventListener("touchend",this.onEnd),e.removeEventListener("touchcancel",this.onCancel),e.removeEventListener("mousewheel",this.onWheel),e.removeEventListener("DOMMouseScroll",this.onWheel),e.removeEventListener("wheel",this.onWheel),e.removeEventListener("mousedown",this.onStart),e.removeEventListener("mousemove",this.onMove),e.removeEventListener("mouseup",this.onEnd),e.removeEventListener("mouseleave",this.onCancel)},watch:{modelValue(e){if(null==e&&this.hasPlaceholder)return void this.correction(-1);const t=this.internalOptions.findIndex((t=>t.value==e));-1!==t?this.internalIndex!==t&&this.correction(t):this.$emit("update:modelValue",this.internalValue)},options:{handler(e){var t,n;const s=this.internalOptions=i(e);let l=s.findIndex((e=>e.value==this.modelValue));-1===l&&!this.hasPlaceholder&&this.options.length>0&&(l=0);const o=null!=(n=null==(t=s[l])?void 0:t.value)?n:null;this.$nextTick((()=>{this.calculatePivots(),this.scroll=this.findScrollByIndex(l),this.internalIndex=l,this.internalValue!==o&&this.$emit("update:modelValue",this.internalValue=o)}))},deep:!0}},computed:{hasPlaceholder(){return!(!this.placeholder&&!this.$slots.placeholder)}},methods:{setRefItem(e){this.refItems.push(e)},calculatePivots(){const e=this.$refs.rotator,t=this.$refs.layerSelection,i=e.getBoundingClientRect().top,n=this.pivots=this.refItems.map((e=>function(e){const{top:t,bottom:i}=e.getBoundingClientRect();return(t+i)/2}(e)-i)).sort(((e,t)=>e-t)),s=this.pivotsMin=Math.min(...n),l=this.pivotsMax=Math.max(...n),o=this.scrollOffsetTop=t.offsetTop+t.offsetHeight/2;this.scrollMin=o-s,this.scrollMax=o-l},sanitizeInternalIndex(e){return Math.min(Math.max(e,this.hasPlaceholder?-1:0),this.internalOptions.length-1)},findIndexFromScroll(e){let t=null,i=0;return this.pivots.forEach(((n,s)=>{const l=n+e-this.scrollOffsetTop;(null===t||Math.abs(t)>Math.abs(l))&&(i=s,t=l)})),this.hasPlaceholder||0===this.options.length?i-1:i},findScrollByIndex(e){let t=e;return(this.hasPlaceholder||0===this.options.length)&&t++,e>-1&&t in this.pivots?this.scrollOffsetTop-this.pivots[t]:this.scrollOffsetTop-this.pivotsMin},onWheel(e){var t,i;if(this.scroll>=this.scrollMin&&e.deltaY<0)return;if(this.scroll<=this.scrollMax&&e.deltaY>0)return;e.preventDefault(),this.scroll=Math.min(Math.max(this.scroll-e.deltaY*this.scrollSensitivity,this.scrollMax),this.scrollMin);const n=this.sanitizeInternalIndex(this.findIndexFromScroll(this.scroll)),s=null!=(i=null==(t=this.internalOptions[n])?void 0:t.value)?i:null;this.internalIndex=n,this.internalValue!==s&&this.$emit("update:modelValue",this.internalValue=s),this.onAfterWheel((()=>{this.correction(this.findIndexFromScroll(this.scroll))}))},onAfterWheel:function(e,t=83){let i=null;return function(){i&&(clearTimeout(i),i=null);const n=this,s=arguments;i=setTimeout((()=>e.apply(n,s)),t)}}((function(e){e()}),200),onStart(e){e.cancelable&&e.preventDefault();const{clientY:t}=s(e);this.start=[this.scroll,t],n(e)||(this.isMouseDown=!0),this.isDragging=!1},onMove(e){if(e.cancelable&&e.preventDefault(),!this.start)return;const{clientY:t}=s(e),i=t-this.start[1];Math.abs(i)>1.5&&(this.isDragging=!0),this.scroll=this.start[0]+i*(n(e)?this.touchSensitivity:this.dragSensitivity)},onEnd(e){e.cancelable&&e.preventDefault(),this.isDragging?this.correction(this.findIndexFromScroll(this.scroll)):this.onClick(e),this.start=null,this.isDragging=!1,this.isMouseDown=!1},onCancel(e){e.cancelable&&e.preventDefault(),this.correction(this.findIndexFromScroll(this.scroll)),this.start=null,this.isMouseDown=!1,this.isDragging=!1},onClick(e){const t=this.$refs.layerTop,i=this.$refs.layerBottom,n=s(e),l=n.clientX,o=n.clientY,r=t.getBoundingClientRect(),h=i.getBoundingClientRect();r.left<=l&&l<=r.right&&r.top<=o&&o<=r.bottom?this.correction(this.internalIndex-1):h.left<=l&&l<=h.right&&h.top<=o&&o<=h.bottom&&this.correction(this.internalIndex+1)},correction(e){var t,i;const n=this.sanitizeInternalIndex(e),s=null!=(i=null==(t=this.internalOptions[n])?void 0:t.value)?i:null;this.scroll=this.findScrollByIndex(n),this.transitioning=!0,this.transitionTimer&&(clearTimeout(this.transitionTimer),this.transitionTimer=null),this.transitionTimer=setTimeout((()=>{this.transitioning=!1,this.transitionTimer=null,this.internalIndex=n,this.internalValue!==s&&this.$emit("update:modelValue",this.internalValue=s)}),100)}},render(){let e=[];return this.hasPlaceholder?e.push(t.h("div",{class:["vue-scroll-picker-item","vue-scroll-picker-item-placeholder",{"vue-scroll-picker-item-selected":-1===this.internalIndex}],ref:e=>e&&this.setRefItem(e)},t.renderSlot(this.$slots,"placeholder",{text:this.placeholder},(()=>[this.placeholder])))):0===this.internalOptions.length&&e.push(t.h("div",{class:["vue-scroll-picker-item","vue-scroll-picker-item-empty","vue-scroll-picker-item-selected"],ref:e=>e&&this.setRefItem(e)},t.renderSlot(this.$slots,"empty",{text:this.empty},(()=>[this.empty])))),e=e.concat(this.internalOptions.map(((e,i)=>t.h("div",{class:["vue-scroll-picker-item",{"vue-scroll-picker-item-selected":this.internalIndex===i}],key:e.value,ref:e=>e&&this.setRefItem(e)},t.renderSlot(this.$slots,"default",{option:e},(()=>[e.name])))))),t.h("div",{class:["vue-scroll-picker"]},[t.h("div",{ref:"rotator",class:["vue-scroll-picker-rotator",{"vue-scroll-picker-rotator-transition":this.transitioning}],style:"number"==typeof this.scroll?{top:`${this.scroll}px`}:{}},e),t.h("div",{class:["vue-scroll-picker-layer"]},[t.h("div",{class:["vue-scroll-picker-layer-top"],ref:"layerTop"}),t.h("div",{class:["vue-scroll-picker-layer-selection"],ref:"layerSelection"}),t.h("div",{class:["vue-scroll-picker-layer-bottom"],ref:"layerBottom"})])])}});function o(e){e.component("ScrollPicker",l)}"undefined"!=typeof window&&window.Vue&&o(window.Vue),e.ScrollPicker=l,e.install=o,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VueScrollPicker={},e.Vue)}(this,(function(e,t){"use strict";function i(e){return e.map((e=>{switch(typeof e){case"string":return{value:e,name:e};case"number":case"boolean":return{value:e,name:`${e}`}}return e}))}function n(e){return e.changedTouches||e.touches}function s(e){return n(e)?e.changedTouches[0]||e.touches[0]:e}var l=t.defineComponent({props:{modelValue:null,options:{type:Array,default:()=>[]},dragSensitivity:{type:Number,default:1.7},touchSensitivity:{type:Number,default:1.7},scrollSensitivity:{type:Number,default:1},empty:{type:String,default:"No Items"},placeholder:{type:String,default:null}},data(){var e,t;const n=i(this.options);let s=n.findIndex((e=>e.value==this.modelValue));-1===s&&!this.placeholder&&!this.$slots.placeholder&&this.options.length>0&&(s=0);return{refItems:[],internalOptions:n,internalIndex:s,internalValue:null!=(t=null==(e=n[s])?void 0:e.value)?t:null,pivots:[],pivotsMin:0,pivotsMax:0,scroll:null,scrollOffsetTop:0,scrollMin:0,scrollMax:0,transitioning:!1,transitionTimer:null,start:null,isMouseDown:!1,isDragging:!1}},beforeUpdate(){this.refItems=[]},mounted(){this.calculatePivots(),this.scroll=this.findScrollByIndex(this.internalIndex),this.internalValue!==this.modelValue&&this.$emit("update:modelValue",this.internalValue);const e=this.$el;e.addEventListener("touchstart",this.onStart),e.addEventListener("touchmove",this.onMove),e.addEventListener("touchend",this.onEnd),e.addEventListener("touchcancel",this.onCancel),e.addEventListener("mousewheel",this.onWheel),e.addEventListener("DOMMouseScroll",this.onWheel),e.addEventListener("wheel",this.onWheel),e.addEventListener("mousedown",this.onStart),e.addEventListener("mousemove",this.onMove),e.addEventListener("mouseup",this.onEnd),e.addEventListener("mouseleave",this.onCancel)},beforeUnmount(){const e=this.$el;e.removeEventListener("touchstart",this.onStart),e.removeEventListener("touchmove",this.onMove),e.removeEventListener("touchend",this.onEnd),e.removeEventListener("touchcancel",this.onCancel),e.removeEventListener("mousewheel",this.onWheel),e.removeEventListener("DOMMouseScroll",this.onWheel),e.removeEventListener("wheel",this.onWheel),e.removeEventListener("mousedown",this.onStart),e.removeEventListener("mousemove",this.onMove),e.removeEventListener("mouseup",this.onEnd),e.removeEventListener("mouseleave",this.onCancel)},watch:{modelValue(e){if(null==e&&this.hasPlaceholder)return void this.correction(-1);const t=this.internalOptions.findIndex((t=>t.value==e));-1!==t?this.internalIndex!==t&&this.correction(t):this.$emit("update:modelValue",this.internalValue)},options:{handler(e){var t,n;const s=this.internalOptions=i(e);let l=s.findIndex((e=>e.value==this.modelValue));-1===l&&!this.hasPlaceholder&&this.options.length>0&&(l=0);const o=null!=(n=null==(t=s[l])?void 0:t.value)?n:null;this.$nextTick((()=>{this.calculatePivots(),this.scroll=this.findScrollByIndex(l),this.internalIndex=l,this.internalValue!==o&&this.$emit("update:modelValue",this.internalValue=o)}))},deep:!0}},computed:{hasPlaceholder(){return!(!this.placeholder&&!this.$slots.placeholder)}},methods:{setRefItem(e){this.refItems.push(e)},calculatePivots(){const e=this.$refs.rotator,t=this.$refs.layerSelection,i=e.getBoundingClientRect().top,n=this.pivots=this.refItems.map((e=>function(e){const{top:t,bottom:i}=e.getBoundingClientRect();return(t+i)/2}(e)-i)).sort(((e,t)=>e-t)),s=this.pivotsMin=Math.min(...n),l=this.pivotsMax=Math.max(...n),o=this.scrollOffsetTop=t.offsetTop+t.offsetHeight/2;this.scrollMin=o-s,this.scrollMax=o-l},sanitizeInternalIndex(e){return Math.min(Math.max(e,this.hasPlaceholder?-1:0),this.internalOptions.length-1)},findIndexFromScroll(e){let t=null,i=0;return this.pivots.forEach(((n,s)=>{const l=n+e-this.scrollOffsetTop;(null===t||Math.abs(t)>Math.abs(l))&&(i=s,t=l)})),this.hasPlaceholder||0===this.options.length?i-1:i},findScrollByIndex(e){let t=e;return(this.hasPlaceholder||0===this.options.length)&&t++,e>-1&&t in this.pivots?this.scrollOffsetTop-this.pivots[t]:this.scrollOffsetTop-this.pivotsMin},onWheel(e){var t,i;if(this.scroll>=this.scrollMin&&e.deltaY<0)return;if(this.scroll<=this.scrollMax&&e.deltaY>0)return;e.preventDefault(),this.scroll=Math.min(Math.max(this.scroll-e.deltaY*this.scrollSensitivity,this.scrollMax),this.scrollMin);const n=this.sanitizeInternalIndex(this.findIndexFromScroll(this.scroll)),s=null!=(i=null==(t=this.internalOptions[n])?void 0:t.value)?i:null;this.internalIndex=n,this.internalValue!==s&&this.$emit("update:modelValue",this.internalValue=s),this.onAfterWheel((()=>{this.correction(this.findIndexFromScroll(this.scroll))}))},onAfterWheel:function(e,t=83){let i=null;return function(){i&&(clearTimeout(i),i=null);const n=this,s=arguments;i=setTimeout((()=>e.apply(n,s)),t)}}((function(e){e()}),200),onStart(e){e.cancelable&&e.preventDefault();const{clientY:t}=s(e);this.start=[this.scroll,t],n(e)||(this.isMouseDown=!0),this.isDragging=!1},onMove(e){if(e.cancelable&&e.preventDefault(),!this.start)return;const{clientY:t}=s(e),i=t-this.start[1];Math.abs(i)>1.5&&(this.isDragging=!0),this.scroll=this.start[0]+i*(n(e)?this.touchSensitivity:this.dragSensitivity)},onEnd(e){e.cancelable&&e.preventDefault(),this.isDragging?this.correction(this.findIndexFromScroll(this.scroll)):this.onClick(e),this.start=null,this.isDragging=!1,this.isMouseDown=!1},onCancel(e){e.cancelable&&e.preventDefault(),this.correction(this.findIndexFromScroll(this.scroll)),this.start=null,this.isMouseDown=!1,this.isDragging=!1},onClick(e){const t=this.$refs.layerTop,i=this.$refs.layerBottom,n=s(e),l=n.clientX,o=n.clientY,r=t.getBoundingClientRect(),h=i.getBoundingClientRect();r.left<=l&&l<=r.right&&r.top<=o&&o<=r.bottom?this.correction(this.internalIndex-1):h.left<=l&&l<=h.right&&h.top<=o&&o<=h.bottom&&this.correction(this.internalIndex+1)},correction(e){var t,i;const n=this.sanitizeInternalIndex(e),s=null!=(i=null==(t=this.internalOptions[n])?void 0:t.value)?i:null;this.scroll=this.findScrollByIndex(n),this.transitioning=!0,this.transitionTimer&&(clearTimeout(this.transitionTimer),this.transitionTimer=null),this.transitionTimer=setTimeout((()=>{this.transitioning=!1,this.transitionTimer=null,this.internalIndex=n,this.internalValue!==s&&this.$emit("update:modelValue",this.internalValue=s)}),100)}},render(){let e=[];return this.hasPlaceholder?e.push(t.h("div",{class:["vue-scroll-picker-item","vue-scroll-picker-item-placeholder",{"vue-scroll-picker-item-selected":-1===this.internalIndex}],ref:e=>e&&this.setRefItem(e)},t.renderSlot(this.$slots,"placeholder",{text:this.placeholder},(()=>[this.placeholder])))):0===this.internalOptions.length&&e.push(t.h("div",{class:["vue-scroll-picker-item","vue-scroll-picker-item-empty","vue-scroll-picker-item-selected"],ref:e=>e&&this.setRefItem(e)},t.renderSlot(this.$slots,"empty",{text:this.empty},(()=>[this.empty])))),e=e.concat(this.internalOptions.map(((e,i)=>t.h("div",{class:["vue-scroll-picker-item",{"vue-scroll-picker-item-selected":this.internalIndex===i}],key:e.value,ref:e=>e&&this.setRefItem(e)},t.renderSlot(this.$slots,"default",{option:e},(()=>[e.name])))))),t.h("div",{class:["vue-scroll-picker"]},[t.h("div",{ref:"rotator",class:["vue-scroll-picker-rotator",{"vue-scroll-picker-rotator-transition":this.transitioning}],style:"number"==typeof this.scroll?{top:`${this.scroll}px`}:{}},e),t.h("div",{class:["vue-scroll-picker-layer"]},[t.h("div",{class:["vue-scroll-picker-layer-top"],ref:"layerTop"}),t.h("div",{class:["vue-scroll-picker-layer-selection"],ref:"layerSelection"}),t.h("div",{class:["vue-scroll-picker-layer-bottom"],ref:"layerBottom"})])])}});function o(e){e.component("VueScrollPicker",l)}"undefined"!=typeof window&&window.Vue&&o(window.Vue);const r={install:o};e.VueScrollPicker=l,e.default=r,e.install=o,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"}));
//# sourceMappingURL=vue-scroll-picker.umd.js.map
{
"name": "vue-scroll-picker",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"description": "iOS Style Scroll Picker Component for Vue 3. Support All Gestures of Mouse(also MouseWheel) and Touch.",

@@ -5,0 +5,0 @@ "author": "Changwan Jun",

@@ -40,3 +40,3 @@ # Vue Scroll Picker

app.use(VueScrollPicker)
app.use(VueScrollPicker) // export default is plugin

@@ -50,8 +50,11 @@ ```

```vue
<template>
<VueScrollPicker :options="options" />
</template>
<script>
import { ScrollPicker } from 'vue-scroll-picker'
import { VueScrollPicker } from 'vue-scroll-picker'
export default {
components: {
ScrollPicker,
VueScrollPicker, // export VueScrollPicker is component
},

@@ -58,0 +61,0 @@ }

import { App, Plugin } from 'vue'
import ScrollPicker from './components/picker'
import VueScrollPicker from './components/picker'
export function install(app: App) {
app.component('ScrollPicker', ScrollPicker)
app.component('VueScrollPicker', VueScrollPicker)
}

@@ -21,3 +21,3 @@

// re-define: https://github.com/vitejs/vite/issues/2117
export interface ScrollPickerOption {
export interface VueScrollPickerOption {
name: string

@@ -28,3 +28,3 @@ value: any

export {
ScrollPicker,
VueScrollPicker,
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet