Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue3-mq

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue3-mq - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

dist/vue3-mq.js

2

dist/vue3-mq.iife.js

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

var ge=Object.defineProperty;var z=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable;var K=(u,a,d)=>a in u?ge(u,a,{enumerable:!0,configurable:!0,writable:!0,value:d}):u[a]=d,Q=(u,a)=>{for(var d in a||(a={}))ye.call(a,d)&&K(u,d,a[d]);if(z)for(var d of z(a))ve.call(a,d)&&K(u,d,a[d]);return u};var Vue3Mq=function(u,a){"use strict";const d=a.ref([]),b=a.ref(null),V=a.ref(null),B=a.ref(null),S=a.ref(null),i=a.reactive({current:""}),k=[],N=a.ref(!1),p=a.readonly(d),C=a.readonly(b),Y=a.readonly(V),Z=a.readonly(B),F=a.readonly(S),f=a.readonly(i),G=e=>{d.value=e},J=e=>{b.value=e},H=e=>{V.value=e},U=e=>{B.value=e},W=e=>{S.value=e},$=(e=C.value)=>{i.current=e;const n=p.value.findIndex(t=>t.name===e),o=p.value.map(t=>t.name);for(let t=0;t<o.length;t++){if(t>0&&t<o.length-1){const r=o[t]+"Minus",s=o[t]+"Plus";i[r]=n<=t,i[s]=n>=t}i[o[t]]=o[t]===e}},X=()=>{const e=Object.keys(i);for(let n of e)delete i[n];$(),x(),R(),O()},x=(e=Y.value)=>{i.orientation=e,i.isLandscape=e==="landscape",i.isPortrait=e==="portrait"},R=(e=Z.value||"light")=>{i.theme=e,i.isDark=e==="dark",i.isLight=e==="light"},O=(e=F.value||"no-preference")=>{i.motionPreference=e,i.isMotion=e==="no-preference",i.isInert=e==="reduce"};function ee(){for(;k.length>0;){const e=k.shift();if(e&&typeof e=="object"){const{mql:n,cb:o}=e;n.addEventListener&&typeof n.addEventListener=="function"?n.removeEventListener("change",o):n.removeListener(o)}}}function te(){return p.value.reduce((n,o,t,r)=>{const s=`(min-width: ${o.min}px)`,l=t<r.length-1?`(max-width: ${r[t+1].min-1}px)`:null,c=s+(l?" and "+l:"");return Object.assign(n,{[o.name]:c})},{})}function y(e,n){if(typeof window=="undefined"||!window.matchMedia)return!1;if(typeof window!="undefined"&&!window.matchMedia)return console.error("Vue3 Mq: No MatchMedia support detected in this browser. Responsive breakpoints not available."),!1;{N.value=!0;const o=window.matchMedia(e),t=({matches:s})=>{s&&n()};k.push({mql:o,cb:t}),o.addEventListener&&typeof o.addEventListener=="function"?o.addEventListener("change",t):o.addListener(t),t(o)}}const m=e=>p.value.some(n=>n.name===e),I=(e,n)=>{const o=n.value.map(t=>t.name);if(e){if(Array.isArray(e))return e.filter(t=>m(t));if(typeof e=="string"&&/\w+\+$/.test(e)){if(e=e.replace(/\+$/,""),m(e)===!1)return console.error(`Vue3 Mq: ${e} is not a valid breakpoint key. Invalid range.`),o;const t=n.value.findIndex(r=>r.name===e);return n.value.slice(t).map(r=>r.name)}else if(typeof e=="string"&&/\w+-$/.test(e)){if(e=e.replace(/-$/,""),m(e)===!1)return console.error(`Vue3 Mq: ${e} is not a valid breakpoint key. Invalid range.`),o;const t=n.value.findIndex(r=>r.name===e);return n.value.slice(0,t+1).map(r=>r.name)}else if(typeof e=="string"&&/^\w+-\w+$/.test(e)){const[t,r]=e.split("-");if(m(t)===!1)return console.error(`Vue3 Mq: ${t} is not a valid breakpoint key. Invalid range.`),o;if(m(r)===!1)return console.error(`Vue3 Mq: ${r} is not a valid breakpoint key. Invalid range.`),o;const s=n.value.findIndex(c=>c.name===t),l=n.value.findIndex(c=>c.name===r);return n.value.slice(s,l+1).map(c=>c.name)}else return typeof e=="string"&&m(e)===!0?[e]:o}else return o},E=(e,n)=>{const o=[];return!e&&!n?["landscape","portrait"]:(e&&o.push("landscape"),n&&o.push("portrait"),o)},L=(e,n)=>{const o=[];return!n&&!e?["light","dark"]:(n&&o.push("light"),e&&o.push("dark"),o)},_=(e,n)=>{const o=[];return!e&&!n?["reduce","no-preference"]:(e&&o.push("reduce"),n&&o.push("no-preference"),o)};var M=Object.freeze(Object.defineProperty({__proto__:null,bootstrap5:{xs:0,sm:576,md:768,lg:992,xl:1200,xxl:1400},bootstrap4:{xs:0,sm:576,md:768,lg:992,xl:1200},bootstrap3:{xs:0,sm:768,md:992,lg:1200},vuetify:{xs:0,sm:600,md:960,lg:1264,xl:1904},tailwind:{xs:0,sm:640,md:768,lg:1024,xl:1280,xxl:1536},devices:{phone:0,tablet:768,laptop:1370,desktop:1906},wordpress:{mobile:0,small:600,medium:782,large:960,xlarge:1080,wide:1280,huge:1440}},Symbol.toStringTag,{value:"Module"}));const ne=e=>{if(typeof e=="string"&&M[e])return M[e];{const n=Object.keys(M);return console.error(`Vue3 Mq: "${e}" is not a valid preset. Available options are: ${n.join(", ")}`),!1}},oe=e=>["landscape","portrait"].includes(e)===!1?(console.error(`Vue3 Mq: "${e}" is not a valid default orientation. Reverting to unset value.`),null):e,re=(e=null)=>["dark","light"].includes(e)===!1&&e!==null?(console.error(`Vue3 Mq: "${e}" is not a valid default theme. Reverting to unset value.`),null):e,ae=(e=null)=>["no-preference","reduce"].includes(e)===!1&&e!==null?(console.error(`Vue3 Mq: "${e}" is not a valid default motion preference. Reverting to unset value.`),null):e,j=e=>{if(!e||typeof e!="object")return!1;const n=[];for(let r in e){const s=parseFloat(e[r]);if(!r||typeof r!="string"){console.warn(`Vue3 Mq: Invalid or missing breakpoint key (${JSON.stringify(r)}). Skipping.`);continue}else if(/^[^a-z]/i.test(r)||/[^a-zA-Z0-9_]/.test(r)){console.warn(`Vue3 Mq: "${r}" is an invalid breakpoint key. Breakpoint keys must start with a letter and contain only alphanumeric characters and underscores. Skipping.`);continue}else if(!s&&s!==0||isNaN(s)||s<0){console.warn(`Vue3 Mq: "${r}: ${e[r]}" is not a valid breakpoint. Breakpoints should be a number of zero or above. Skipping.`);continue}n.push({name:r,min:s})}return n.some(r=>r.min===0)||console.warn("Vue3 Mq: You have not declared a breakpoint with a minimum value of 0. There may be screen sizes to which Vue3Mq does not respond."),new Set(n.map(r=>r.min)).size<n.length&&console.warn("Vue3 Mq: Your breakpoint configuration contains duplicate values. Behaviour may be unpredictable."),n.length===0?!1:n.sort((r,s)=>r.min-s.min)},se=e=>{const n=e.split(":"),o={};for(let t of n)/\D/.test(t)!==!1&&(["landscape","portrait"].includes(t)?o.slotOrientation=t:["light","dark"].includes(t)?o.slotTheme=t:["inert","motion"].includes(t)?o.slotMotion=t:o.slotBp=t);return o},ie={name:"fade",mode:"out-in"};var le={name:"MqResponsive",props:{target:[String,Array],landscape:{type:Boolean,default:!1},portrait:{type:Boolean,default:!1},dark:{type:Boolean,default:!1},light:{type:Boolean,default:!1},inert:{type:Boolean,default:!1},motion:{type:Boolean,default:!1},tag:{type:String,default:"div"},listTag:{type:String,default:"div"},group:{type:Boolean,default:!1}},setup(e,{attrs:n,emit:o,slots:t}){const r=a.computed(()=>I(e.target,p)),s=a.computed(()=>E(e.landscape,e.portrait)),l=a.computed(()=>L(e.dark,e.light)),c=a.computed(()=>_(e.inert,e.motion)),q=a.computed(()=>r.value.includes(f.current)&&s.value.includes(f.orientation)&&l.value.includes(f.theme)&&c.value.includes(f.motionPreference)),T=h=>{if(!e.group&&t.length>0)return t;const g=[];for(let v in t){const{slotBp:de,slotOrientation:P,slotTheme:A,slotMotion:D}=se(v),fe=a.computed(()=>I(de,p)),pe=a.computed(()=>E(P==="landscape",P==="portrait")),me=a.computed(()=>L(A==="dark",A==="light")),he=a.computed(()=>_(D==="inert",D==="motion"));a.computed(()=>fe.value.includes(f.current)&&pe.value.includes(f.orientation)&&me.value.includes(f.theme)&&he.value.includes(f.motionPreference)).value===!0&&g.push(a.h(h||t[v],{key:v},h?t[v]():void 0))}return g.length>0?g:void 0};return t.default?()=>q.value?a.h(e.tag,Q({},n),t.default()):void 0:()=>{const h=Object.assign({},ie,n,{tag:e.tag}),g=e.group?a.TransitionGroup:a.Transition;return a.h(g,h,()=>T(e.listTag))}}};function w({breakpoints:e,preset:n}){const o=ne(n),t=j(e);if(o===!1&&!t)throw new TypeError("Vue3 Mq: You must provide a valid preset, or valid breakpoint settings.");G(t||j(o)),ee(),X();const r=te();for(const s in r){const l=r[s];y(l,()=>{$(s)})}["portrait","landscape"].forEach(s=>{const l=()=>{x(s)};y(`(orientation: ${s})`,l)}),["light","dark"].forEach(s=>{const l=()=>{R(s)};y(`(prefers-color-scheme: ${s})`,l)}),["reduce","no-preference"].forEach(s=>{const l=()=>{O(s)};y(`(prefers-reduced-motion: ${s})`,l)})}function ue(){const e=a.inject("mq");if(e)return e;throw new Error("Vue3Mq is not installed in this app. Please follow the installation instructions and try again.")}var ce={install:(e,{preset:n="bootstrap5",breakpoints:o,defaultBreakpoint:t,defaultOrientation:r="landscape",defaultMotion:s="no-preference",defaultTheme:l}={})=>{try{const c=oe(r),q=re(l),T=ae(s);J(t),H(c),U(q),W(T),e.provide("mq",f),e.provide("updateBreakpoints",w),w({breakpoints:o,preset:n})}catch(c){console.error(c)}}};return u.MqResponsive=le,u.Vue3Mq=ce,u.availableBreakpoints=p,u.updateBreakpoints=w,u.useMq=ue,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),u}({},Vue);
var Vue3Mq=function(d,s){"use strict";const T=s.ref([]),V=s.ref(null),B=s.ref(null),S=s.ref(null),b=s.ref(null),i=s.reactive({current:""}),v=[],z=s.ref(!1),f=s.readonly(T),K=s.readonly(V),Q=s.readonly(B),N=s.readonly(S),C=s.readonly(b),c=s.readonly(i),Y=e=>{T.value=e},Z=e=>{V.value=e},F=e=>{B.value=e},G=e=>{S.value=e},J=e=>{b.value=e},$=(e=K.value)=>{i.current=e;const n=f.value.findIndex(t=>t.name===e),o=f.value.map(t=>t.name);for(let t=0;t<o.length;t++){if(t>0&&t<o.length-1){const r=o[t]+"Minus",a=o[t]+"Plus";i[r]=n<=t,i[a]=n>=t}i[o[t]]=o[t]===e}},H=()=>{const e=Object.keys(i);for(let n of e)delete i[n];$(),x(),R(),O()},x=(e=Q.value)=>{i.orientation=e,i.isLandscape=e==="landscape",i.isPortrait=e==="portrait"},R=(e=N.value||"light")=>{i.theme=e,i.isDark=e==="dark",i.isLight=e==="light"},O=(e=C.value||"no-preference")=>{i.motionPreference=e,i.isMotion=e==="no-preference",i.isInert=e==="reduce"};function U(){for(;v.length>0;){const e=v.shift();if(e&&typeof e=="object"){const{mql:n,cb:o}=e;n.addEventListener&&typeof n.addEventListener=="function"?n.removeEventListener("change",o):n.removeListener(o)}}}function W(){return f.value.reduce((n,o,t,r)=>{const a=`(min-width: ${o.min}px)`,l=t<r.length-1?`(max-width: ${r[t+1].min-1}px)`:null,u=a+(l?" and "+l:"");return Object.assign(n,{[o.name]:u})},{})}function g(e,n){if(typeof window>"u"||!window.matchMedia)return!1;if(typeof window<"u"&&!window.matchMedia)return console.error("Vue3 Mq: No MatchMedia support detected in this browser. Responsive breakpoints not available."),!1;{z.value=!0;const o=window.matchMedia(e),t=({matches:a})=>{a&&n()};v.push({mql:o,cb:t}),o.addEventListener&&typeof o.addEventListener=="function"?o.addEventListener("change",t):o.addListener(t),t(o)}}const p=e=>f.value.some(n=>n.name===e),I=(e,n)=>{const o=n.value.map(t=>t.name);if(e){if(Array.isArray(e))return e.filter(t=>p(t));if(typeof e=="string"&&/\w+\+$/.test(e)){if(e=e.replace(/\+$/,""),p(e)===!1)return console.error(`Vue3 Mq: ${e} is not a valid breakpoint key. Invalid range.`),o;const t=n.value.findIndex(r=>r.name===e);return n.value.slice(t).map(r=>r.name)}else if(typeof e=="string"&&/\w+-$/.test(e)){if(e=e.replace(/-$/,""),p(e)===!1)return console.error(`Vue3 Mq: ${e} is not a valid breakpoint key. Invalid range.`),o;const t=n.value.findIndex(r=>r.name===e);return n.value.slice(0,t+1).map(r=>r.name)}else if(typeof e=="string"&&/^\w+-\w+$/.test(e)){const[t,r]=e.split("-");if(p(t)===!1)return console.error(`Vue3 Mq: ${t} is not a valid breakpoint key. Invalid range.`),o;if(p(r)===!1)return console.error(`Vue3 Mq: ${r} is not a valid breakpoint key. Invalid range.`),o;const a=n.value.findIndex(u=>u.name===t),l=n.value.findIndex(u=>u.name===r);return n.value.slice(a,l+1).map(u=>u.name)}else return typeof e=="string"&&p(e)===!0?[e]:o}else return o},E=(e,n)=>{const o=[];return!e&&!n?["landscape","portrait"]:(e&&o.push("landscape"),n&&o.push("portrait"),o)},L=(e,n)=>{const o=[];return!n&&!e?["light","dark"]:(n&&o.push("light"),e&&o.push("dark"),o)},_=(e,n)=>{const o=[];return!e&&!n?["reduce","no-preference"]:(e&&o.push("reduce"),n&&o.push("no-preference"),o)},k=Object.freeze(Object.defineProperty({__proto__:null,bootstrap5:{xs:0,sm:576,md:768,lg:992,xl:1200,xxl:1400},bootstrap4:{xs:0,sm:576,md:768,lg:992,xl:1200},bootstrap3:{xs:0,sm:768,md:992,lg:1200},vuetify:{xs:0,sm:600,md:960,lg:1264,xl:1904},tailwind:{xs:0,sm:640,md:768,lg:1024,xl:1280,xxl:1536},devices:{phone:0,tablet:768,laptop:1370,desktop:1906},wordpress:{mobile:0,small:600,medium:782,large:960,xlarge:1080,wide:1280,huge:1440}},Symbol.toStringTag,{value:"Module"})),X=e=>{if(typeof e=="string"&&k[e])return k[e];{const n=Object.keys(k);return console.error(`Vue3 Mq: "${e}" is not a valid preset. Available options are: ${n.join(", ")}`),!1}},ee=e=>["landscape","portrait"].includes(e)===!1?(console.error(`Vue3 Mq: "${e}" is not a valid default orientation. Reverting to unset value.`),null):e,te=(e=null)=>["dark","light"].includes(e)===!1&&e!==null?(console.error(`Vue3 Mq: "${e}" is not a valid default theme. Reverting to unset value.`),null):e,ne=(e=null)=>["no-preference","reduce"].includes(e)===!1&&e!==null?(console.error(`Vue3 Mq: "${e}" is not a valid default motion preference. Reverting to unset value.`),null):e,j=e=>{if(!e||typeof e!="object")return!1;const n=[];for(let r in e){const a=parseFloat(e[r]);if(!r||typeof r!="string"){console.warn(`Vue3 Mq: Invalid or missing breakpoint key (${JSON.stringify(r)}). Skipping.`);continue}else if(/^[^a-z]/i.test(r)||/[^a-zA-Z0-9_]/.test(r)){console.warn(`Vue3 Mq: "${r}" is an invalid breakpoint key. Breakpoint keys must start with a letter and contain only alphanumeric characters and underscores. Skipping.`);continue}else if(!a&&a!==0||isNaN(a)||a<0){console.warn(`Vue3 Mq: "${r}: ${e[r]}" is not a valid breakpoint. Breakpoints should be a number of zero or above. Skipping.`);continue}n.push({name:r,min:a})}return n.some(r=>r.min===0)||console.warn("Vue3 Mq: You have not declared a breakpoint with a minimum value of 0. There may be screen sizes to which Vue3Mq does not respond."),new Set(n.map(r=>r.min)).size<n.length&&console.warn("Vue3 Mq: Your breakpoint configuration contains duplicate values. Behaviour may be unpredictable."),n.length===0?!1:n.sort((r,a)=>r.min-a.min)},oe=e=>{const n=e.split(":"),o={};for(let t of n)/\D/.test(t)!==!1&&(["landscape","portrait"].includes(t)?o.slotOrientation=t:["light","dark"].includes(t)?o.slotTheme=t:["inert","motion"].includes(t)?o.slotMotion=t:o.slotBp=t);return o},re={name:"fade",mode:"out-in"},ae={name:"MqResponsive",props:{target:[String,Array],landscape:{type:Boolean,default:!1},portrait:{type:Boolean,default:!1},dark:{type:Boolean,default:!1},light:{type:Boolean,default:!1},inert:{type:Boolean,default:!1},motion:{type:Boolean,default:!1},tag:{type:String,default:"div"},listTag:{type:String,default:"div"},group:{type:Boolean,default:!1}},setup(e,{attrs:n,emit:o,slots:t}){const r=s.computed(()=>I(e.target,f)),a=s.computed(()=>E(e.landscape,e.portrait)),l=s.computed(()=>L(e.dark,e.light)),u=s.computed(()=>_(e.inert,e.motion)),w=s.computed(()=>r.value.includes(c.current)&&a.value.includes(c.orientation)&&l.value.includes(c.theme)&&u.value.includes(c.motionPreference)),q=m=>{if(!e.group&&t.length>0)return t;const h=[];for(let y in t){const{slotBp:le,slotOrientation:P,slotTheme:A,slotMotion:D}=oe(y),ue=s.computed(()=>I(le,f)),ce=s.computed(()=>E(P==="landscape",P==="portrait")),de=s.computed(()=>L(A==="dark",A==="light")),fe=s.computed(()=>_(D==="inert",D==="motion"));s.computed(()=>ue.value.includes(c.current)&&ce.value.includes(c.orientation)&&de.value.includes(c.theme)&&fe.value.includes(c.motionPreference)).value===!0&&h.push(s.h(m||t[y],{key:y},m?t[y]():void 0))}return h.length>0?h:void 0};return t.default?()=>w.value?s.h(e.tag,{...n},t.default()):void 0:()=>{const m=Object.assign({},re,n,{tag:e.tag}),h=e.group?s.TransitionGroup:s.Transition;return s.h(h,m,()=>q(e.listTag))}}};function M({breakpoints:e,preset:n}){const o=n?X(n):!1,t=e?j(e):!1;if(o===!1&&!t)throw new TypeError("Vue3 Mq: You must provide a valid preset, or valid breakpoint settings.");Y(t||j(o)),U(),H();const r=W();for(const a in r){const l=r[a];g(l,()=>{$(a)})}["portrait","landscape"].forEach(a=>{const l=()=>{x(a)};g(`(orientation: ${a})`,l)}),["light","dark"].forEach(a=>{const l=()=>{R(a)};g(`(prefers-color-scheme: ${a})`,l)}),["reduce","no-preference"].forEach(a=>{const l=()=>{O(a)};g(`(prefers-reduced-motion: ${a})`,l)})}function se(){const e=s.inject("mq");if(e)return e;throw new Error("Vue3Mq is not installed in this app. Please follow the installation instructions and try again.")}const ie={install:(e,{preset:n="bootstrap5",breakpoints:o,defaultBreakpoint:t,defaultOrientation:r="landscape",defaultMotion:a="no-preference",defaultTheme:l}={})=>{try{const u=ee(r),w=te(l),q=ne(a);Z(t),F(u),G(w),J(q),e.provide("mq",c),e.provide("updateBreakpoints",M),M({breakpoints:o,preset:n})}catch(u){console.error(u)}}};return d.MqResponsive=ae,d.Vue3Mq=ie,d.availableBreakpoints=f,d.updateBreakpoints=M,d.useMq=se,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),d}({},Vue);

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

var ye=Object.defineProperty;var z=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable;var K=(i,r,d)=>r in i?ye(i,r,{enumerable:!0,configurable:!0,writable:!0,value:d}):i[r]=d,Q=(i,r)=>{for(var d in r||(r={}))ge.call(r,d)&&K(i,d,r[d]);if(z)for(var d of z(r))ve.call(r,d)&&K(i,d,r[d]);return i};(function(i,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],r):(i=typeof globalThis!="undefined"?globalThis:i||self,r(i.Vue3Mq={},i.Vue))})(this,function(i,r){"use strict";const d=r.ref([]),b=r.ref(null),V=r.ref(null),B=r.ref(null),S=r.ref(null),l=r.reactive({current:""}),k=[],N=r.ref(!1),p=r.readonly(d),C=r.readonly(b),Y=r.readonly(V),Z=r.readonly(B),F=r.readonly(S),f=r.readonly(l),G=e=>{d.value=e},J=e=>{b.value=e},H=e=>{V.value=e},U=e=>{B.value=e},W=e=>{S.value=e},x=(e=C.value)=>{l.current=e;const n=p.value.findIndex(t=>t.name===e),o=p.value.map(t=>t.name);for(let t=0;t<o.length;t++){if(t>0&&t<o.length-1){const a=o[t]+"Minus",s=o[t]+"Plus";l[a]=n<=t,l[s]=n>=t}l[o[t]]=o[t]===e}},X=()=>{const e=Object.keys(l);for(let n of e)delete l[n];x(),$(),R(),O()},$=(e=Y.value)=>{l.orientation=e,l.isLandscape=e==="landscape",l.isPortrait=e==="portrait"},R=(e=Z.value||"light")=>{l.theme=e,l.isDark=e==="dark",l.isLight=e==="light"},O=(e=F.value||"no-preference")=>{l.motionPreference=e,l.isMotion=e==="no-preference",l.isInert=e==="reduce"};function ee(){for(;k.length>0;){const e=k.shift();if(e&&typeof e=="object"){const{mql:n,cb:o}=e;n.addEventListener&&typeof n.addEventListener=="function"?n.removeEventListener("change",o):n.removeListener(o)}}}function te(){return p.value.reduce((n,o,t,a)=>{const s=`(min-width: ${o.min}px)`,u=t<a.length-1?`(max-width: ${a[t+1].min-1}px)`:null,c=s+(u?" and "+u:"");return Object.assign(n,{[o.name]:c})},{})}function g(e,n){if(typeof window=="undefined"||!window.matchMedia)return!1;if(typeof window!="undefined"&&!window.matchMedia)return console.error("Vue3 Mq: No MatchMedia support detected in this browser. Responsive breakpoints not available."),!1;{N.value=!0;const o=window.matchMedia(e),t=({matches:s})=>{s&&n()};k.push({mql:o,cb:t}),o.addEventListener&&typeof o.addEventListener=="function"?o.addEventListener("change",t):o.addListener(t),t(o)}}const m=e=>p.value.some(n=>n.name===e),I=(e,n)=>{const o=n.value.map(t=>t.name);if(e){if(Array.isArray(e))return e.filter(t=>m(t));if(typeof e=="string"&&/\w+\+$/.test(e)){if(e=e.replace(/\+$/,""),m(e)===!1)return console.error(`Vue3 Mq: ${e} is not a valid breakpoint key. Invalid range.`),o;const t=n.value.findIndex(a=>a.name===e);return n.value.slice(t).map(a=>a.name)}else if(typeof e=="string"&&/\w+-$/.test(e)){if(e=e.replace(/-$/,""),m(e)===!1)return console.error(`Vue3 Mq: ${e} is not a valid breakpoint key. Invalid range.`),o;const t=n.value.findIndex(a=>a.name===e);return n.value.slice(0,t+1).map(a=>a.name)}else if(typeof e=="string"&&/^\w+-\w+$/.test(e)){const[t,a]=e.split("-");if(m(t)===!1)return console.error(`Vue3 Mq: ${t} is not a valid breakpoint key. Invalid range.`),o;if(m(a)===!1)return console.error(`Vue3 Mq: ${a} is not a valid breakpoint key. Invalid range.`),o;const s=n.value.findIndex(c=>c.name===t),u=n.value.findIndex(c=>c.name===a);return n.value.slice(s,u+1).map(c=>c.name)}else return typeof e=="string"&&m(e)===!0?[e]:o}else return o},E=(e,n)=>{const o=[];return!e&&!n?["landscape","portrait"]:(e&&o.push("landscape"),n&&o.push("portrait"),o)},L=(e,n)=>{const o=[];return!n&&!e?["light","dark"]:(n&&o.push("light"),e&&o.push("dark"),o)},_=(e,n)=>{const o=[];return!e&&!n?["reduce","no-preference"]:(e&&o.push("reduce"),n&&o.push("no-preference"),o)};var M=Object.freeze(Object.defineProperty({__proto__:null,bootstrap5:{xs:0,sm:576,md:768,lg:992,xl:1200,xxl:1400},bootstrap4:{xs:0,sm:576,md:768,lg:992,xl:1200},bootstrap3:{xs:0,sm:768,md:992,lg:1200},vuetify:{xs:0,sm:600,md:960,lg:1264,xl:1904},tailwind:{xs:0,sm:640,md:768,lg:1024,xl:1280,xxl:1536},devices:{phone:0,tablet:768,laptop:1370,desktop:1906},wordpress:{mobile:0,small:600,medium:782,large:960,xlarge:1080,wide:1280,huge:1440}},Symbol.toStringTag,{value:"Module"}));const ne=e=>{if(typeof e=="string"&&M[e])return M[e];{const n=Object.keys(M);return console.error(`Vue3 Mq: "${e}" is not a valid preset. Available options are: ${n.join(", ")}`),!1}},oe=e=>["landscape","portrait"].includes(e)===!1?(console.error(`Vue3 Mq: "${e}" is not a valid default orientation. Reverting to unset value.`),null):e,re=(e=null)=>["dark","light"].includes(e)===!1&&e!==null?(console.error(`Vue3 Mq: "${e}" is not a valid default theme. Reverting to unset value.`),null):e,ae=(e=null)=>["no-preference","reduce"].includes(e)===!1&&e!==null?(console.error(`Vue3 Mq: "${e}" is not a valid default motion preference. Reverting to unset value.`),null):e,j=e=>{if(!e||typeof e!="object")return!1;const n=[];for(let a in e){const s=parseFloat(e[a]);if(!a||typeof a!="string"){console.warn(`Vue3 Mq: Invalid or missing breakpoint key (${JSON.stringify(a)}). Skipping.`);continue}else if(/^[^a-z]/i.test(a)||/[^a-zA-Z0-9_]/.test(a)){console.warn(`Vue3 Mq: "${a}" is an invalid breakpoint key. Breakpoint keys must start with a letter and contain only alphanumeric characters and underscores. Skipping.`);continue}else if(!s&&s!==0||isNaN(s)||s<0){console.warn(`Vue3 Mq: "${a}: ${e[a]}" is not a valid breakpoint. Breakpoints should be a number of zero or above. Skipping.`);continue}n.push({name:a,min:s})}return n.some(a=>a.min===0)||console.warn("Vue3 Mq: You have not declared a breakpoint with a minimum value of 0. There may be screen sizes to which Vue3Mq does not respond."),new Set(n.map(a=>a.min)).size<n.length&&console.warn("Vue3 Mq: Your breakpoint configuration contains duplicate values. Behaviour may be unpredictable."),n.length===0?!1:n.sort((a,s)=>a.min-s.min)},se=e=>{const n=e.split(":"),o={};for(let t of n)/\D/.test(t)!==!1&&(["landscape","portrait"].includes(t)?o.slotOrientation=t:["light","dark"].includes(t)?o.slotTheme=t:["inert","motion"].includes(t)?o.slotMotion=t:o.slotBp=t);return o},ie={name:"fade",mode:"out-in"};var le={name:"MqResponsive",props:{target:[String,Array],landscape:{type:Boolean,default:!1},portrait:{type:Boolean,default:!1},dark:{type:Boolean,default:!1},light:{type:Boolean,default:!1},inert:{type:Boolean,default:!1},motion:{type:Boolean,default:!1},tag:{type:String,default:"div"},listTag:{type:String,default:"div"},group:{type:Boolean,default:!1}},setup(e,{attrs:n,emit:o,slots:t}){const a=r.computed(()=>I(e.target,p)),s=r.computed(()=>E(e.landscape,e.portrait)),u=r.computed(()=>L(e.dark,e.light)),c=r.computed(()=>_(e.inert,e.motion)),q=r.computed(()=>a.value.includes(f.current)&&s.value.includes(f.orientation)&&u.value.includes(f.theme)&&c.value.includes(f.motionPreference)),T=h=>{if(!e.group&&t.length>0)return t;const y=[];for(let v in t){const{slotBp:de,slotOrientation:P,slotTheme:A,slotMotion:D}=se(v),fe=r.computed(()=>I(de,p)),pe=r.computed(()=>E(P==="landscape",P==="portrait")),me=r.computed(()=>L(A==="dark",A==="light")),he=r.computed(()=>_(D==="inert",D==="motion"));r.computed(()=>fe.value.includes(f.current)&&pe.value.includes(f.orientation)&&me.value.includes(f.theme)&&he.value.includes(f.motionPreference)).value===!0&&y.push(r.h(h||t[v],{key:v},h?t[v]():void 0))}return y.length>0?y:void 0};return t.default?()=>q.value?r.h(e.tag,Q({},n),t.default()):void 0:()=>{const h=Object.assign({},ie,n,{tag:e.tag}),y=e.group?r.TransitionGroup:r.Transition;return r.h(y,h,()=>T(e.listTag))}}};function w({breakpoints:e,preset:n}){const o=ne(n),t=j(e);if(o===!1&&!t)throw new TypeError("Vue3 Mq: You must provide a valid preset, or valid breakpoint settings.");G(t||j(o)),ee(),X();const a=te();for(const s in a){const u=a[s];g(u,()=>{x(s)})}["portrait","landscape"].forEach(s=>{const u=()=>{$(s)};g(`(orientation: ${s})`,u)}),["light","dark"].forEach(s=>{const u=()=>{R(s)};g(`(prefers-color-scheme: ${s})`,u)}),["reduce","no-preference"].forEach(s=>{const u=()=>{O(s)};g(`(prefers-reduced-motion: ${s})`,u)})}function ue(){const e=r.inject("mq");if(e)return e;throw new Error("Vue3Mq is not installed in this app. Please follow the installation instructions and try again.")}var ce={install:(e,{preset:n="bootstrap5",breakpoints:o,defaultBreakpoint:t,defaultOrientation:a="landscape",defaultMotion:s="no-preference",defaultTheme:u}={})=>{try{const c=oe(a),q=re(u),T=ae(s);J(t),H(c),U(q),W(T),e.provide("mq",f),e.provide("updateBreakpoints",w),w({breakpoints:o,preset:n})}catch(c){console.error(c)}}};i.MqResponsive=le,i.Vue3Mq=ce,i.availableBreakpoints=p,i.updateBreakpoints=w,i.useMq=ue,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
(function(c,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(c=typeof globalThis<"u"?globalThis:c||self,a(c.Vue3Mq={},c.Vue))})(this,function(c,a){"use strict";const T=a.ref([]),V=a.ref(null),B=a.ref(null),S=a.ref(null),x=a.ref(null),i=a.reactive({current:""}),v=[],z=a.ref(!1),f=a.readonly(T),K=a.readonly(V),Q=a.readonly(B),N=a.readonly(S),C=a.readonly(x),d=a.readonly(i),Y=e=>{T.value=e},Z=e=>{V.value=e},F=e=>{B.value=e},G=e=>{S.value=e},J=e=>{x.value=e},b=(e=K.value)=>{i.current=e;const n=f.value.findIndex(t=>t.name===e),o=f.value.map(t=>t.name);for(let t=0;t<o.length;t++){if(t>0&&t<o.length-1){const r=o[t]+"Minus",s=o[t]+"Plus";i[r]=n<=t,i[s]=n>=t}i[o[t]]=o[t]===e}},H=()=>{const e=Object.keys(i);for(let n of e)delete i[n];b(),$(),R(),O()},$=(e=Q.value)=>{i.orientation=e,i.isLandscape=e==="landscape",i.isPortrait=e==="portrait"},R=(e=N.value||"light")=>{i.theme=e,i.isDark=e==="dark",i.isLight=e==="light"},O=(e=C.value||"no-preference")=>{i.motionPreference=e,i.isMotion=e==="no-preference",i.isInert=e==="reduce"};function U(){for(;v.length>0;){const e=v.shift();if(e&&typeof e=="object"){const{mql:n,cb:o}=e;n.addEventListener&&typeof n.addEventListener=="function"?n.removeEventListener("change",o):n.removeListener(o)}}}function W(){return f.value.reduce((n,o,t,r)=>{const s=`(min-width: ${o.min}px)`,l=t<r.length-1?`(max-width: ${r[t+1].min-1}px)`:null,u=s+(l?" and "+l:"");return Object.assign(n,{[o.name]:u})},{})}function g(e,n){if(typeof window>"u"||!window.matchMedia)return!1;if(typeof window<"u"&&!window.matchMedia)return console.error("Vue3 Mq: No MatchMedia support detected in this browser. Responsive breakpoints not available."),!1;{z.value=!0;const o=window.matchMedia(e),t=({matches:s})=>{s&&n()};v.push({mql:o,cb:t}),o.addEventListener&&typeof o.addEventListener=="function"?o.addEventListener("change",t):o.addListener(t),t(o)}}const p=e=>f.value.some(n=>n.name===e),I=(e,n)=>{const o=n.value.map(t=>t.name);if(e){if(Array.isArray(e))return e.filter(t=>p(t));if(typeof e=="string"&&/\w+\+$/.test(e)){if(e=e.replace(/\+$/,""),p(e)===!1)return console.error(`Vue3 Mq: ${e} is not a valid breakpoint key. Invalid range.`),o;const t=n.value.findIndex(r=>r.name===e);return n.value.slice(t).map(r=>r.name)}else if(typeof e=="string"&&/\w+-$/.test(e)){if(e=e.replace(/-$/,""),p(e)===!1)return console.error(`Vue3 Mq: ${e} is not a valid breakpoint key. Invalid range.`),o;const t=n.value.findIndex(r=>r.name===e);return n.value.slice(0,t+1).map(r=>r.name)}else if(typeof e=="string"&&/^\w+-\w+$/.test(e)){const[t,r]=e.split("-");if(p(t)===!1)return console.error(`Vue3 Mq: ${t} is not a valid breakpoint key. Invalid range.`),o;if(p(r)===!1)return console.error(`Vue3 Mq: ${r} is not a valid breakpoint key. Invalid range.`),o;const s=n.value.findIndex(u=>u.name===t),l=n.value.findIndex(u=>u.name===r);return n.value.slice(s,l+1).map(u=>u.name)}else return typeof e=="string"&&p(e)===!0?[e]:o}else return o},E=(e,n)=>{const o=[];return!e&&!n?["landscape","portrait"]:(e&&o.push("landscape"),n&&o.push("portrait"),o)},L=(e,n)=>{const o=[];return!n&&!e?["light","dark"]:(n&&o.push("light"),e&&o.push("dark"),o)},_=(e,n)=>{const o=[];return!e&&!n?["reduce","no-preference"]:(e&&o.push("reduce"),n&&o.push("no-preference"),o)},k=Object.freeze(Object.defineProperty({__proto__:null,bootstrap5:{xs:0,sm:576,md:768,lg:992,xl:1200,xxl:1400},bootstrap4:{xs:0,sm:576,md:768,lg:992,xl:1200},bootstrap3:{xs:0,sm:768,md:992,lg:1200},vuetify:{xs:0,sm:600,md:960,lg:1264,xl:1904},tailwind:{xs:0,sm:640,md:768,lg:1024,xl:1280,xxl:1536},devices:{phone:0,tablet:768,laptop:1370,desktop:1906},wordpress:{mobile:0,small:600,medium:782,large:960,xlarge:1080,wide:1280,huge:1440}},Symbol.toStringTag,{value:"Module"})),X=e=>{if(typeof e=="string"&&k[e])return k[e];{const n=Object.keys(k);return console.error(`Vue3 Mq: "${e}" is not a valid preset. Available options are: ${n.join(", ")}`),!1}},ee=e=>["landscape","portrait"].includes(e)===!1?(console.error(`Vue3 Mq: "${e}" is not a valid default orientation. Reverting to unset value.`),null):e,te=(e=null)=>["dark","light"].includes(e)===!1&&e!==null?(console.error(`Vue3 Mq: "${e}" is not a valid default theme. Reverting to unset value.`),null):e,ne=(e=null)=>["no-preference","reduce"].includes(e)===!1&&e!==null?(console.error(`Vue3 Mq: "${e}" is not a valid default motion preference. Reverting to unset value.`),null):e,j=e=>{if(!e||typeof e!="object")return!1;const n=[];for(let r in e){const s=parseFloat(e[r]);if(!r||typeof r!="string"){console.warn(`Vue3 Mq: Invalid or missing breakpoint key (${JSON.stringify(r)}). Skipping.`);continue}else if(/^[^a-z]/i.test(r)||/[^a-zA-Z0-9_]/.test(r)){console.warn(`Vue3 Mq: "${r}" is an invalid breakpoint key. Breakpoint keys must start with a letter and contain only alphanumeric characters and underscores. Skipping.`);continue}else if(!s&&s!==0||isNaN(s)||s<0){console.warn(`Vue3 Mq: "${r}: ${e[r]}" is not a valid breakpoint. Breakpoints should be a number of zero or above. Skipping.`);continue}n.push({name:r,min:s})}return n.some(r=>r.min===0)||console.warn("Vue3 Mq: You have not declared a breakpoint with a minimum value of 0. There may be screen sizes to which Vue3Mq does not respond."),new Set(n.map(r=>r.min)).size<n.length&&console.warn("Vue3 Mq: Your breakpoint configuration contains duplicate values. Behaviour may be unpredictable."),n.length===0?!1:n.sort((r,s)=>r.min-s.min)},oe=e=>{const n=e.split(":"),o={};for(let t of n)/\D/.test(t)!==!1&&(["landscape","portrait"].includes(t)?o.slotOrientation=t:["light","dark"].includes(t)?o.slotTheme=t:["inert","motion"].includes(t)?o.slotMotion=t:o.slotBp=t);return o},re={name:"fade",mode:"out-in"},ae={name:"MqResponsive",props:{target:[String,Array],landscape:{type:Boolean,default:!1},portrait:{type:Boolean,default:!1},dark:{type:Boolean,default:!1},light:{type:Boolean,default:!1},inert:{type:Boolean,default:!1},motion:{type:Boolean,default:!1},tag:{type:String,default:"div"},listTag:{type:String,default:"div"},group:{type:Boolean,default:!1}},setup(e,{attrs:n,emit:o,slots:t}){const r=a.computed(()=>I(e.target,f)),s=a.computed(()=>E(e.landscape,e.portrait)),l=a.computed(()=>L(e.dark,e.light)),u=a.computed(()=>_(e.inert,e.motion)),w=a.computed(()=>r.value.includes(d.current)&&s.value.includes(d.orientation)&&l.value.includes(d.theme)&&u.value.includes(d.motionPreference)),q=m=>{if(!e.group&&t.length>0)return t;const h=[];for(let y in t){const{slotBp:le,slotOrientation:P,slotTheme:A,slotMotion:D}=oe(y),ue=a.computed(()=>I(le,f)),ce=a.computed(()=>E(P==="landscape",P==="portrait")),de=a.computed(()=>L(A==="dark",A==="light")),fe=a.computed(()=>_(D==="inert",D==="motion"));a.computed(()=>ue.value.includes(d.current)&&ce.value.includes(d.orientation)&&de.value.includes(d.theme)&&fe.value.includes(d.motionPreference)).value===!0&&h.push(a.h(m||t[y],{key:y},m?t[y]():void 0))}return h.length>0?h:void 0};return t.default?()=>w.value?a.h(e.tag,{...n},t.default()):void 0:()=>{const m=Object.assign({},re,n,{tag:e.tag}),h=e.group?a.TransitionGroup:a.Transition;return a.h(h,m,()=>q(e.listTag))}}};function M({breakpoints:e,preset:n}){const o=n?X(n):!1,t=e?j(e):!1;if(o===!1&&!t)throw new TypeError("Vue3 Mq: You must provide a valid preset, or valid breakpoint settings.");Y(t||j(o)),U(),H();const r=W();for(const s in r){const l=r[s];g(l,()=>{b(s)})}["portrait","landscape"].forEach(s=>{const l=()=>{$(s)};g(`(orientation: ${s})`,l)}),["light","dark"].forEach(s=>{const l=()=>{R(s)};g(`(prefers-color-scheme: ${s})`,l)}),["reduce","no-preference"].forEach(s=>{const l=()=>{O(s)};g(`(prefers-reduced-motion: ${s})`,l)})}function se(){const e=a.inject("mq");if(e)return e;throw new Error("Vue3Mq is not installed in this app. Please follow the installation instructions and try again.")}const ie={install:(e,{preset:n="bootstrap5",breakpoints:o,defaultBreakpoint:t,defaultOrientation:r="landscape",defaultMotion:s="no-preference",defaultTheme:l}={})=>{try{const u=ee(r),w=te(l),q=ne(s);Z(t),F(u),G(w),J(q),e.provide("mq",d),e.provide("updateBreakpoints",M),M({breakpoints:o,preset:n})}catch(u){console.error(u)}}};c.MqResponsive=ae,c.Vue3Mq=ie,c.availableBreakpoints=f,c.updateBreakpoints=M,c.useMq=se,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
{
"name": "vue3-mq",
"version": "3.1.0",
"version": "3.1.1",
"description": "Build responsive design into your Vue3 app",

@@ -41,4 +41,4 @@ "files": [

"@babel/preset-env": "^7.14.8",
"@mdi/js": "^6.5.95",
"@vitejs/plugin-vue": "^2.2.0",
"@mdi/js": "^7.0.96",
"@vitejs/plugin-vue": "^3.1.0",
"@vue/compiler-sfc": "^3.0.5",

@@ -55,5 +55,5 @@ "@vue/test-utils": "^2.0.0-rc.10",

"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jsdoc": "^38.0.6",
"eslint-plugin-vue": "^8.4.1",
"gh-pages": "^3.2.3",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-vue": "^9.4.0",
"gh-pages": "^4.0.0",
"match-media-mock": "^0.1.1",

@@ -63,3 +63,3 @@ "postcss": "^8.4.12",

"tailwindcss": "^3.0.23",
"vite": "^2.4.2",
"vite": "^3.1.0",
"vue-jest": "^5.0.0-alpha.10",

@@ -66,0 +66,0 @@ "vue3-icon": "^2.0.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc