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

stimulus-use

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stimulus-use - npm Package Compare versions

Comparing version 0.19.0 to 0.20.0

2

dist/index.umd.js

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("stimulus")):"function"==typeof define&&define.amd?define(["exports","stimulus"],n):n((e=e||self).StimulusUse={},e.Stimulus)}(this,function(e,n){var t=function(e,n){var t=e[n];if("function"==typeof t)return t;throw new Error('undefined method "'+n+'"')},i=function(e,n,t){var i=e;return!0===t?i=n.identifier+":"+e:"string"==typeof t&&(i=t+":"+e),i},o=function(e,n,t){var i=n||{bubbles:!0,cancelable:!0,composed:!0},o=i.bubbles,r=i.cancelable,c=i.composed;return n&&Object.assign(t,{originalEvent:n}),new CustomEvent(e,{bubbles:o,cancelable:r,composed:c,detail:t})},r={dispatchEvent:!0,eventPrefix:!0},c=function(e,n){var c;void 0===n&&(n={});var s=Object.assign(r,n),a=s.dispatchEvent,u=s.eventPrefix,l=(null==(c=n)?void 0:c.element)||e.element,v=e.disconnect.bind(e),f=new IntersectionObserver(function(n){var r=n[0];r.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),a){var r=i("appear",e,u),c=o(r,null,{controller:e,entry:n});l.dispatchEvent(c)}}(r):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),a){var r=i("disappear",e,u),c=o(r,null,{controller:e,entry:n});l.dispatchEvent(c)}}(r)},n),d=function(){f.observe(l)},b=function(){f.unobserve(l)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),v()}}),d(),[d,b]};function s(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var u=function(e){function n(n){var t;return(t=e.call(this,n)||this).isVisible=!1,requestAnimationFrame(function(){var e=c(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),l=function(e,n){var i=e.disconnect.bind(e),o=new IntersectionObserver(function(n){n[0].isIntersecting&&!e.isLoaded&&function(n){var i=e.data.get("src");if(i){var o=e.element;e.isLoading=!0,e.loading&&t(e,"loading").call(e,i),o.onload=function(){!function(n){e.isLoading=!1,e.isLoaded=!0,e.loading&&t(e,"loaded").call(e,n)}(i)},o.src=i}}()},n),r=function(){o.observe(e.element)},c=function(){o.unobserve(e.element)};return Object.assign(e,{isVisible:!1,disconnect:function(){c(),i()}}),r(),[r,c]},v=function(e){function n(n){var t;return(t=e.call(this,n)||this).isLoading=!1,t.isLoaded=!1,t.options={rootMargin:"10%"},requestAnimationFrame(function(){var e=l(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}s(n,e);var t=n.prototype;return t.loading=function(e){},t.loaded=function(e){},n}(n.Controller),f={dispatchEvent:!0,eventPrefix:!0},d=function(e,n){var r;void 0===n&&(n={});var c=Object.assign(f,n),s=c.dispatchEvent,a=c.eventPrefix,u=(null==(r=n)?void 0:r.element)||e.element,l=e.disconnect.bind(e),v=new ResizeObserver(function(n){var r=n[0];if(e.resize&&t(e,"resize").call(e,r.contentRect),s){var c=i("resize",e,a),l=o(c,null,{controller:e,entry:r});u.dispatchEvent(l)}}),d=function(){v.observe(u)},b=function(){v.unobserve(u)};return Object.assign(e,{disconnect:function(){b(),l()}}),d(),[d,b]},b=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=d(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.resize=function(e){},n}(n.Controller),h={events:["click","touchend"],onlyVisible:!0,dispatchEvent:!0,eventPrefix:!0},p=function(e,n){void 0===n&&(n={});var r=Object.assign(h,n),c=r.onlyVisible,s=r.dispatchEvent,a=r.events,u=r.eventPrefix,l=function(r){var a,l,v=(null==(a=n)?void 0:a.element)||e.element;if(!v.contains(r.target)&&((l=v.getBoundingClientRect()).top>=0&&l.left>=0&&l.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&l.right<=(window.innerWidth||document.documentElement.clientWidth)||!c)&&(e.clickOutside&&t(e,"clickOutside").call(e,r),s)){var f=i("click:outside",e,u),d=o(f,r,{controller:e});v.dispatchEvent(d)}},v=function(){null==a||a.forEach(function(e){window.addEventListener(e,l,!1)})},f=function(){null==a||a.forEach(function(e){window.removeEventListener(e,l,!1)})},d=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){f(),d()}}),v(),[v,f]},m=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=p(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),g={eventPrefix:!0,bubbles:!0,cancelable:!0},w=function(e,n){var t=(null==n?void 0:n.element)||e.element,o=Object.assign(g,n),r=o.eventPrefix,c=o.bubbles,s=o.cancelable;Object.assign(e,{dispatch:function(n,o){void 0===o&&(o={}),Object.assign(o,{controller:e});var a=i(n,e,r),u=new CustomEvent(a,{detail:o,bubbles:c,cancelable:s});return t.dispatchEvent(u),u}})},y=function(e,n){Object.defineProperty(e,"isPreview",{get:function(){return document.documentElement.hasAttribute("data-turbolinks-preview")}}),Object.defineProperty(e,"csrfToken",{get:function(){return this.metaValue("csrf-token")}}),w(e,n),Object.assign(e,{metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})},E=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",y(a(t),t.options),t}return s(n,e),n}(n.Controller),O={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},j=function(e,n){void 0===n&&(n={});var r=Object.assign(O,n),c=r.ms,s=r.events,a=r.dispatchEvent,u=r.eventPrefix,l=r.initialState,v=setTimeout(function(){l=!0,f()},c),f=function(n){var r=i("away",e,u);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),a){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},d=function(n){var r=i("back",e,u);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),a){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},b=function(e){l&&d(e),l=!1,clearTimeout(v),v=setTimeout(function(){l=!0,f(e)},c)},h=function(e){document.hidden||b(e)};l?f():d();var p=e.disconnect.bind(e),m=function(){s.forEach(function(e){window.addEventListener(e,b)}),document.addEventListener("visibilitychange",h)},g=function(){s.forEach(function(e){window.removeEventListener(e,b)}),document.removeEventListener("visibilitychange",h)};return Object.assign(e,{disconnect:function(){g(),p()}}),m(),[m,g]},C=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){var e=j(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}s(n,e);var t=n.prototype;return t.away=function(){},t.back=function(){},n}(n.Controller),P={dispatchEvent:!0,eventPrefix:!0},V=function(e,n){var r=this;void 0===n&&(n={}),this.observe=function(){r.controller.isVisible=!document.hidden,document.addEventListener("visibilitychange",r.handleVisibilityChange)},this.unobserve=function(){document.removeEventListener("visibilitychange",r.handleVisibilityChange)},this.dispatchInvisible=function(e){var n=i("invisible",r.controller,r.eventPrefix);r.controller.isVisible=!1,r.controller.invisible&&t(r.controller,"invisible").call(r.controller,e),r.dispatch(n,e)},this.dispatchVisible=function(e){var n=i("visible",r.controller,r.eventPrefix);r.controller.isVisible=!0,r.controller.visible&&t(r.controller,"visible").call(r.controller,e),r.dispatch(n,e)},this.dispatch=function(e,n){if(r.dispatchEvent){var t=o(e,n||null,{controller:r.controller});r.controller.element.dispatchEvent(t)}},this.handleVisibilityChange=function(e){document.hidden?r.dispatchInvisible(e):r.dispatchVisible(e)};var c=Object.assign(P,n);Object.assign(this,{dispatchEvent:c.dispatchEvent,eventPrefix:c.eventPrefix}),this.controller=e;var s=this.unobserve,a=e.disconnect.bind(e);Object.assign(e,{disconnect:function(){s(),a()}}),this.handleVisibilityChange(),this.observe()},L=function(e,n){void 0===n&&(n={});var t=new V(e,n);return[t.observe,t.unobserve]},x=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=L(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),z=function(e){var n=function(n){var i=window,o={height:i.innerHeight||Infinity,width:i.innerWidth||Infinity,event:n};e.windowResize&&t(e,"windowResize").call(e,o)},i=e.disconnect.bind(e),o=function(){window.addEventListener("resize",n),n()},r=function(){window.removeEventListener("resize",n)};return Object.assign(e,{disconnect:function(){r(),i()}}),o(),[o,r]},k=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=z(a(t)),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.windowResize=function(e){},n}(n.Controller),I=function(e,n){void 0===n&&(n=200);var t=null;return function(){var i=arguments,o=this,r=function(){return e.apply(o,i)};clearTimeout(t),t=setTimeout(r,n)}};function A(e,n){var t;return void 0===n&&(n=200),function(){var i=arguments,o=this;t||(t=!0,e.apply(o,i),setTimeout(function(){return t=!1},n))}}function R(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}function q(e){try{return JSON.parse(e)}catch(n){return e}}function T(e){return e.replace(/(?:[_-])([a-z0-9])/g,function(e,n){return n.toUpperCase()})}e.ApplicationController=E,e.ClickOutsideController=m,e.IdleController=C,e.IntersectionController=u,e.LazyLoadController=v,e.ResizeController=b,e.UseVisibility=V,e.VisibilityController=x,e.WindowResizeController=k,e.useApplication=y,e.useClickOutside=p,e.useDebounce=function(e,n){var t;null==(t=e.constructor.debounces)||t.forEach(function(t){if("string"==typeof t&&(e[t]=I(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=I(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useDispatch=w,e.useIdle=j,e.useIntersection=c,e.useLazyLoad=l,e.useMemo=function(e){var n;null==(n=e.constructor.memos)||n.forEach(function(n){!function(e,n,t){Object.defineProperty(e,n,{value:t})}(e,n,e[n])})},e.useMeta=function(e){var n=e.constructor.metaNames;null==n||n.forEach(function(n){!function(e,n){Object.defineProperty(e,T(n),{get:function(){return q(R(n))}})}(e,n)}),Object.defineProperty(e,"metas",{get:function(){var e={};return null==n||n.forEach(function(n){var t=q(R(n));null!=t&&(e[T(n)]=t)}),e}})},e.useResize=d,e.useThrottle=function(e,n){var t;null==(t=e.constructor.throttles)||t.forEach(function(t){if("string"==typeof t&&(e[t]=A(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=A(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useVisibility=L,e.useWindowResize=z});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("stimulus")):"function"==typeof define&&define.amd?define(["exports","stimulus"],n):n((e=e||self).StimulusUse={},e.Stimulus)}(this,function(e,n){var t=function(e,n){var t=e[n];if("function"==typeof t)return t;throw new Error('undefined method "'+n+'"')},i=function(e,n,t){var i=e;return!0===t?i=n.identifier+":"+e:"string"==typeof t&&(i=t+":"+e),i},o=function(e,n,t){var i=n||{bubbles:!0,cancelable:!0,composed:!0},o=i.bubbles,r=i.cancelable,c=i.composed;return n&&Object.assign(t,{originalEvent:n}),new CustomEvent(e,{bubbles:o,cancelable:r,composed:c,detail:t})},r={dispatchEvent:!0,eventPrefix:!0},c=function(e,n){var c;void 0===n&&(n={});var s=Object.assign(r,n),a=s.dispatchEvent,u=s.eventPrefix,l=(null==(c=n)?void 0:c.element)||e.element,v=e.disconnect.bind(e),f=new IntersectionObserver(function(n){var r=n[0];r.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),a){var r=i("appear",e,u),c=o(r,null,{controller:e,entry:n});l.dispatchEvent(c)}}(r):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),a){var r=i("disappear",e,u),c=o(r,null,{controller:e,entry:n});l.dispatchEvent(c)}}(r)},n),d=function(){f.observe(l)},b=function(){f.unobserve(l)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),v()}}),d(),[d,b]};function s(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var u=function(e){function n(n){var t;return(t=e.call(this,n)||this).isVisible=!1,requestAnimationFrame(function(){var e=c(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),l=function(e,n){var i=e.disconnect.bind(e),o=new IntersectionObserver(function(n){n[0].isIntersecting&&!e.isLoaded&&function(n){var i=e.data.get("src");if(i){var o=e.element;e.isLoading=!0,e.loading&&t(e,"loading").call(e,i),o.onload=function(){!function(n){e.isLoading=!1,e.isLoaded=!0,e.loading&&t(e,"loaded").call(e,n)}(i)},o.src=i}}()},n),r=function(){o.observe(e.element)},c=function(){o.unobserve(e.element)};return Object.assign(e,{isVisible:!1,disconnect:function(){c(),i()}}),r(),[r,c]},v=function(e){function n(n){var t;return(t=e.call(this,n)||this).isLoading=!1,t.isLoaded=!1,t.options={rootMargin:"10%"},requestAnimationFrame(function(){var e=l(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}s(n,e);var t=n.prototype;return t.loading=function(e){},t.loaded=function(e){},n}(n.Controller),f={dispatchEvent:!0,eventPrefix:!0},d=function(e,n){var r;void 0===n&&(n={});var c=Object.assign(f,n),s=c.dispatchEvent,a=c.eventPrefix,u=(null==(r=n)?void 0:r.element)||e.element,l=e.disconnect.bind(e),v=new ResizeObserver(function(n){var r=n[0];if(e.resize&&t(e,"resize").call(e,r.contentRect),s){var c=i("resize",e,a),l=o(c,null,{controller:e,entry:r});u.dispatchEvent(l)}}),d=function(){v.observe(u)},b=function(){v.unobserve(u)};return Object.assign(e,{disconnect:function(){b(),l()}}),d(),[d,b]},b=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=d(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.resize=function(e){},n}(n.Controller),h={events:["click","touchend"],onlyVisible:!0,dispatchEvent:!0,eventPrefix:!0},p=function(e,n){void 0===n&&(n={});var r=Object.assign(h,n),c=r.onlyVisible,s=r.dispatchEvent,a=r.events,u=r.eventPrefix,l=function(r){var a,l,v=(null==(a=n)?void 0:a.element)||e.element;if(!v.contains(r.target)&&((l=v.getBoundingClientRect()).top>=0&&l.left>=0&&l.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&l.right<=(window.innerWidth||document.documentElement.clientWidth)||!c)&&(e.clickOutside&&t(e,"clickOutside").call(e,r),s)){var f=i("click:outside",e,u),d=o(f,r,{controller:e});v.dispatchEvent(d)}},v=function(){null==a||a.forEach(function(e){window.addEventListener(e,l,!1)})},f=function(){null==a||a.forEach(function(e){window.removeEventListener(e,l,!1)})},d=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){f(),d()}}),v(),[v,f]},m=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=p(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),g={eventPrefix:!0,bubbles:!0,cancelable:!0},w=function(e,n){var t=(null==n?void 0:n.element)||e.element,o=Object.assign(g,n),r=o.eventPrefix,c=o.bubbles,s=o.cancelable;Object.assign(e,{dispatch:function(n,o){void 0===o&&(o={}),Object.assign(o,{controller:e});var a=i(n,e,r),u=new CustomEvent(a,{detail:o,bubbles:c,cancelable:s});return t.dispatchEvent(u),u}})},y=function(e,n){Object.defineProperty(e,"isPreview",{get:function(){return document.documentElement.hasAttribute("data-turbolinks-preview")}}),Object.defineProperty(e,"csrfToken",{get:function(){return this.metaValue("csrf-token")}}),w(e,n),Object.assign(e,{metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})},E=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",y(a(t),t.options),t}return s(n,e),n}(n.Controller),O={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},j=function(e,n){void 0===n&&(n={});var r=Object.assign(O,n),c=r.ms,s=r.events,a=r.dispatchEvent,u=r.eventPrefix,l=r.initialState,v=setTimeout(function(){l=!0,f()},c),f=function(n){var r=i("away",e,u);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),a){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},d=function(n){var r=i("back",e,u);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),a){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},b=function(e){l&&d(e),l=!1,clearTimeout(v),v=setTimeout(function(){l=!0,f(e)},c)},h=function(e){document.hidden||b(e)};l?f():d();var p=e.disconnect.bind(e),m=function(){s.forEach(function(e){window.addEventListener(e,b)}),document.addEventListener("visibilitychange",h)},g=function(){s.forEach(function(e){window.removeEventListener(e,b)}),document.removeEventListener("visibilitychange",h)};return Object.assign(e,{disconnect:function(){g(),p()}}),m(),[m,g]},C=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){var e=j(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}s(n,e);var t=n.prototype;return t.away=function(){},t.back=function(){},n}(n.Controller),P={dispatchEvent:!0,eventPrefix:!0},V=function(e,n){var r=this;void 0===n&&(n={}),this.observe=function(){r.controller.isVisible=!document.hidden,document.addEventListener("visibilitychange",r.handleVisibilityChange)},this.unobserve=function(){document.removeEventListener("visibilitychange",r.handleVisibilityChange)},this.dispatchInvisible=function(e){var n=i("invisible",r.controller,r.eventPrefix);r.controller.isVisible=!1,r.controller.invisible&&t(r.controller,"invisible").call(r.controller,e),r.dispatch(n,e)},this.dispatchVisible=function(e){var n=i("visible",r.controller,r.eventPrefix);r.controller.isVisible=!0,r.controller.visible&&t(r.controller,"visible").call(r.controller,e),r.dispatch(n,e)},this.dispatch=function(e,n){if(r.dispatchEvent){var t=o(e,n||null,{controller:r.controller});r.controller.element.dispatchEvent(t)}},this.handleVisibilityChange=function(e){document.hidden?r.dispatchInvisible(e):r.dispatchVisible(e)};var c=Object.assign(P,n);Object.assign(this,{dispatchEvent:c.dispatchEvent,eventPrefix:c.eventPrefix}),this.controller=e;var s=this.unobserve,a=e.disconnect.bind(e);Object.assign(e,{disconnect:function(){s(),a()}}),this.handleVisibilityChange(),this.observe()},x=function(e,n){void 0===n&&(n={});var t=new V(e,n);return[t.observe,t.unobserve]},L=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=x(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),z=function(e){var n=function(n){var i=window,o={height:i.innerHeight||Infinity,width:i.innerWidth||Infinity,event:n};e.windowResize&&t(e,"windowResize").call(e,o)},i=e.disconnect.bind(e),o=function(){window.addEventListener("resize",n),n()},r=function(){window.removeEventListener("resize",n)};return Object.assign(e,{disconnect:function(){r(),i()}}),o(),[o,r]},k=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=z(a(t)),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.windowResize=function(e){},n}(n.Controller),I=function(e,n){void 0===n&&(n=200);var t=null;return function(){var i=arguments,o=this,r=function(){return e.apply(o,i)};clearTimeout(t),t=setTimeout(r,n)}};function A(e,n){var t;return void 0===n&&(n=200),function(){var i=arguments,o=this;t||(t=!0,e.apply(o,i),setTimeout(function(){return t=!1},n))}}function R(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}function q(e){try{return JSON.parse(e)}catch(n){return e}}function T(e){return e.replace(/(?:[_-])([a-z0-9])/g,function(e,n){return n.toUpperCase()})}e.ApplicationController=E,e.ClickOutsideController=m,e.IdleController=C,e.IntersectionController=u,e.LazyLoadController=v,e.ResizeController=b,e.UseVisibility=V,e.VisibilityController=L,e.WindowResizeController=k,e.useApplication=y,e.useClickOutside=p,e.useDebounce=function(e,n){var t;null==(t=e.constructor.debounces)||t.forEach(function(t){if("string"==typeof t&&(e[t]=I(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=I(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useDispatch=w,e.useIdle=j,e.useIntersection=c,e.useLazyLoad=l,e.useMemo=function(e){var n;null==(n=e.constructor.memos)||n.forEach(function(n){!function(e,n,t){Object.defineProperty(e,n,{value:t})}(e,n,e[n])})},e.useMeta=function(e,n){void 0===n&&(n={suffix:!0});var t=e.constructor.metaNames,i=n.suffix;null==t||t.forEach(function(n){!function(e,n,t){var i=t?T(n)+"Meta":T(n);Object.defineProperty(e,i,{get:function(){return q(R(n))}})}(e,n,i)}),Object.defineProperty(e,"metas",{get:function(){var e={};return null==t||t.forEach(function(n){var t=q(R(n));null!=t&&(e[T(n)]=t)}),e}})},e.useResize=d,e.useThrottle=function(e,n){var t;null==(t=e.constructor.throttles)||t.forEach(function(t){if("string"==typeof t&&(e[t]=A(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=A(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useVisibility=x,e.useWindowResize=z});
//# sourceMappingURL=index.umd.js.map
import { Controller } from 'stimulus';
export declare const useMeta: (controller: Controller) => void;
export interface MetaOptions {
suffix: boolean;
}
export declare const useMeta: (controller: Controller, options?: MetaOptions) => void;
//# sourceMappingURL=use-meta.d.ts.map

@@ -1,3 +0,4 @@

const defineMetaGetter = (controller, metaName) => {
Object.defineProperty(controller, camelize(metaName), {
const defineMetaGetter = (controller, metaName, suffix) => {
const getterName = suffix ? `${camelize(metaName)}Meta` : camelize(metaName);
Object.defineProperty(controller, getterName, {
get() {

@@ -23,7 +24,8 @@ return typeCast(metaValue(metaName));

}
export const useMeta = (controller) => {
export const useMeta = (controller, options = { suffix: true }) => {
const metaNames = controller.constructor.metaNames;
const suffix = options.suffix;
// defines the individual meta getters
metaNames === null || metaNames === void 0 ? void 0 : metaNames.forEach((metaName) => {
defineMetaGetter(controller, metaName);
defineMetaGetter(controller, metaName, suffix);
});

@@ -30,0 +32,0 @@ // define the metas getter to retreive an object with all metas

{
"name": "stimulus-use",
"version": "0.19.0",
"version": "0.20.0",
"description": "A collection of standard controllers and utilities for Stimulus",

@@ -5,0 +5,0 @@ "main": "dist/index.umd.js",

import { Controller } from 'stimulus'
const defineMetaGetter = (controller: Controller, metaName: string) => {
Object.defineProperty(controller, camelize(metaName), {
export interface MetaOptions {
suffix: boolean
}
const defineMetaGetter = (controller: Controller, metaName: string, suffix: boolean) => {
const getterName = suffix ? `${camelize(metaName)}Meta` : camelize(metaName)
Object.defineProperty(controller, getterName, {
get(): any {

@@ -28,8 +34,9 @@ return typeCast(metaValue(metaName))

export const useMeta = (controller: Controller) => {
export const useMeta = (controller: Controller, options: MetaOptions = { suffix: true }) => {
const metaNames = (controller.constructor as any).metaNames
const suffix = options.suffix
// defines the individual meta getters
metaNames?.forEach((metaName: string) => {
defineMetaGetter(controller, metaName)
defineMetaGetter(controller, metaName, suffix)
})

@@ -36,0 +43,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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