11import cookie from 'cookiejs'
2- import { computed , type Ref } from 'vue-demi'
2+ import { computed , type MaybeRefOrGetter , type Ref , toRef , toValue } from 'vue-demi'
33
4- import type { ViewportOptions , ViewportQuery } from '.. /types'
4+ import type { ViewportOptions , ViewportQuery } from './types'
55
66export const STATE_KEY = 'viewportState'
77
8- export function createViewportManager ( options : ViewportOptions , state : Ref < string > ) {
8+ export function createViewportManager ( options : MaybeRefOrGetter < ViewportOptions > , state : Ref < string > ) {
9+ options = toRef ( options )
10+
911 const breakpoint = computed < string > ( {
1012 get ( ) {
11- return state . value || options . fallbackBreakpoint
13+ return state . value || options . value . fallbackBreakpoint
1214 } ,
1315
1416 set ( newBreakpoint ) {
1517 state . value = newBreakpoint
1618
17- if ( typeof window !== 'undefined' && options . cookie . name ) {
18- cookie . set ( options . cookie . name , state . value , options . cookie )
19+ if ( typeof window !== 'undefined' && options . value . cookie . name ) {
20+ cookie . set ( options . value . cookie . name , state . value , options . value . cookie )
1921 }
2022 } ,
2123 } )
2224
2325 const queries = computed < Record < string , ViewportQuery > > ( ( ) => {
24- const breakpoints = options . breakpoints || { }
26+ const breakpoints = options . value . breakpoints || { }
2527 const breakpointsKeys = Object . keys ( breakpoints ) . sort ( ( a , b ) => breakpoints [ a ] - breakpoints [ b ] )
2628
2729 const output : Record < string , ViewportQuery > = { }
@@ -36,7 +38,7 @@ export function createViewportManager(options: ViewportOptions, state: Ref<strin
3638
3739 let mediaQuery = ''
3840
39- if ( options . feature === 'minWidth' ) {
41+ if ( options . value . feature === 'minWidth' ) {
4042 if ( i > 0 ) {
4143 mediaQuery = `(min-width: ${ size } px)`
4244 } else {
@@ -86,7 +88,7 @@ export function createViewportManager(options: ViewportOptions, state: Ref<strin
8688 * @param searchBreakpoint - Breakpoint to search.
8789 */
8890 function breakpointValue ( searchBreakpoint : string ) {
89- const breakpoints = options . breakpoints || { }
91+ const breakpoints = toValue ( options ) . breakpoints || { }
9092
9193 return breakpoints [ searchBreakpoint ]
9294 }
0 commit comments