UNPKG

vue-composable-helpers

Version:

Vue 3 composable api helpers

3 lines (2 loc) 2.62 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("json2mq"),require("vue")):"function"==typeof define&&define.amd?define(["exports","json2mq","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VueComposableHelpers={},e.toMq,e.vue)}(this,(function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,o=!1,u=void 0;try{for(var i,a=e[Symbol.iterator]();!(r=(i=a.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw u}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,t=n.ref(e),r=n.computed((function(){return t.value}));function o(e){t.value=e}return[r,o]}e.useComputedState=a,e.useMatchMedia=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=o.default(e),i=n.ref(),l=a(t),f=u(l,2),c=f[0],s=f[1],d=a(""),v=u(d,2),m=v[0],y=v[1],h=a(!1),p=u(h,2),b=p[0],g=p[1];function j(e){s(e.matches),y(e.media)}function S(){if(i.value=window.matchMedia(r),s(i.value.matches),y(i.value.media),!i.value)return g(!0);i.value.addEventListener?i.value.addEventListener("change",j):i.value.addListener(j)}function M(){i.value&&(i.value.removeEventListener?i.value.removeEventListener("change",j):i.value.removeListener(j))}return n.onMounted(S),n.onBeforeUnmount(M),{error:b,matches:c,media:m}},e.usePromise=function(e){var t=u(a(!1),2),n=t[0],r=t[1],o=u(a(!0),2),i=o[0],l=o[1],f=u(a(!1),2),c=f[0],s=f[1],d=u(a(null),2),v=d[0],m=d[1],y=u(a(null),2),h=y[0],p=y[1];return e.then((function(e){m(e),s(!0)})),e.catch((function(e){p(e),r(!0)})),e.finally((function(){l(!1)})),{data:v,error:h,isError:n,isPending:i,isSuccess:c}},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=vue-composable-helpers-umd.js.map