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.16.0-0 to 0.16.1-0

22

dist/index.d.ts

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

export { useIntersection, IntersectionController } from './use-intersection';
export { useLazyLoad, LazyLoadController } from './use-lazy-load';
export { useResize, ResizeController } from './use-resize';
export { useClickOutside, ClickOutsideController } from './use-click-outside';
export { useApplication, ApplicationController } from './use-application';
export { useIdle, IdleController } from './use-idle';
export { useVisibility, UseVisibility, VisibilityController } from './use-visibility';
export { useWindowResize, WindowResizeController } from './use-window-resize';
export { useMemo } from './use-memo';
export { useDebounce } from './use-debounce';
export { useThrottle } from './use-throttle';
export { useIntersection, IntersectionController } from './use-intersection/index';
export { useLazyLoad, LazyLoadController } from './use-lazy-load/index';
export { useResize, ResizeController } from './use-resize/index';
export { useClickOutside, ClickOutsideController } from './use-click-outside/index';
export { useApplication, ApplicationController } from './use-application/index';
export { useIdle, IdleController } from './use-idle/index';
export { useVisibility, UseVisibility, VisibilityController } from './use-visibility/index';
export { useWindowResize, WindowResizeController } from './use-window-resize/index';
export { useMemo } from './use-memo/index';
export { useDebounce } from './use-debounce/index';
export { useThrottle } from './use-throttle/index';
//# sourceMappingURL=index.d.ts.map

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

export { useIntersection, IntersectionController } from './use-intersection';
export { useLazyLoad, LazyLoadController } from './use-lazy-load';
export { useResize, ResizeController } from './use-resize';
export { useClickOutside, ClickOutsideController } from './use-click-outside';
export { useApplication, ApplicationController } from './use-application';
export { useIdle, IdleController } from './use-idle';
export { useVisibility, UseVisibility, VisibilityController } from './use-visibility';
export { useWindowResize, WindowResizeController } from './use-window-resize';
export { useMemo } from './use-memo';
export { useDebounce } from './use-debounce';
export { useThrottle } from './use-throttle';
export { useIntersection, IntersectionController } from './use-intersection/index';
export { useLazyLoad, LazyLoadController } from './use-lazy-load/index';
export { useResize, ResizeController } from './use-resize/index';
export { useClickOutside, ClickOutsideController } from './use-click-outside/index';
export { useApplication, ApplicationController } from './use-application/index';
export { useIdle, IdleController } from './use-idle/index';
export { useVisibility, UseVisibility, VisibilityController } from './use-visibility/index';
export { useWindowResize, WindowResizeController } from './use-window-resize/index';
export { useMemo } from './use-memo/index';
export { useDebounce } from './use-debounce/index';
export { useThrottle } from './use-throttle/index';
//# sourceMappingURL=index.js.map

@@ -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),l=s.dispatchEvent,a=s.eventPrefix,u=(null==(c=n)?void 0:c.element)||e.element,d=e.disconnect.bind(e),v=new IntersectionObserver(function(n){var r=n[0];r.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),l){var r=i("appear",e,a),c=o(r,null,{controller:e,entry:n});u.dispatchEvent(c)}}(r):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),l){var r=i("disappear",e,a),c=o(r,null,{controller:e,entry:n});u.dispatchEvent(c)}}(r)},n),f=function(){v.observe(u)},b=function(){v.unobserve(u)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),d()}}),f(),[f,b]};function s(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var a=function(e){function n(n){var t;return(t=e.call(this,n)||this).isVisible=!1,requestAnimationFrame(function(){var e=c(l(t),t.options),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),u=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]},d=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=u(l(t),t.options),n=e[0],i=e[1];Object.assign(l(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),v={dispatchEvent:!0,eventPrefix:!0},f=function(e,n){var r;void 0===n&&(n={});var c=Object.assign(v,n),s=c.dispatchEvent,l=c.eventPrefix,a=(null==(r=n)?void 0:r.element)||e.element,u=e.disconnect.bind(e),d=new ResizeObserver(function(n){var r=n[0];if(e.resize&&t(e,"resize").call(e,r.contentRect),s){var c=i("resize",e,l),u=o(c,null,{controller:e,entry:r});a.dispatchEvent(u)}}),f=function(){d.observe(a)},b=function(){d.unobserve(a)};return Object.assign(e,{disconnect:function(){b(),u()}}),f(),[f,b]},b=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=f(l(t),t.options),n=e[0],i=e[1];Object.assign(l(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,l=r.events,a=r.eventPrefix,u=function(r){var l,u,d=(null==(l=n)?void 0:l.element)||e.element;if(!d.contains(r.target)&&((u=d.getBoundingClientRect()).top>=0&&u.left>=0&&u.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&u.right<=(window.innerWidth||document.documentElement.clientWidth)||!c)&&(e.clickOutside&&t(e,"clickOutside").call(e,r),s)){var v=i("click:outside",e,a),f=o(v,r,{controller:e});d.dispatchEvent(f)}},d=function(){null==l||l.forEach(function(e){window.addEventListener(e,u,!1)})},v=function(){null==l||l.forEach(function(e){window.removeEventListener(e,u,!1)})},f=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){v(),f()}}),d(),[d,v]},m=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=p(l(t),t.options),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),g=function(e){Object.defineProperty(e,"isPreview",{get:function(){return document.documentElement.hasAttribute("data-turbolinks-preview")}}),Object.defineProperty(e,"csrfToken",{get:function(){return this.metaValue("csrf-token")}}),Object.assign(e,{dispatch:function(n,t){var i=void 0===t?{}:t,o=i.target,r=void 0===o?e.element:o,c=i.detail,s=void 0===c?{}:c,l=i.bubbles,a=void 0===l||l,u=i.cancelable,d=void 0===u||u;Object.assign(s,{controller:e});var v=new CustomEvent(e.identifier+":"+n,{detail:s,bubbles:a,cancelable:d});return r.dispatchEvent(v),v},metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})},w=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",g(l(t)),t}s(n,e);var t=n.prototype;return t.dispatch=function(e,n){},t.metaValue=function(e){return""},n}(n.Controller),y={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},E=function(e,n){void 0===n&&(n={});var r=Object.assign(y,n),c=r.ms,s=r.events,l=r.dispatchEvent,a=r.eventPrefix,u=r.initialState,d=setTimeout(function(){u=!0,v()},c),v=function(n){var r=i("away",e,a);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),l){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},f=function(n){var r=i("back",e,a);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),l){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},b=function(e){u&&f(e),u=!1,clearTimeout(d),d=setTimeout(function(){u=!0,v(e)},c)},h=function(e){document.hidden||b(e)};u?v():f();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]},O=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){var e=E(l(t),t.options),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}s(n,e);var t=n.prototype;return t.away=function(){},t.back=function(){},n}(n.Controller),j={dispatchEvent:!0,eventPrefix:!0},C=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(j,n);Object.assign(this,{dispatchEvent:c.dispatchEvent,eventPrefix:c.eventPrefix}),this.controller=e;var s=this.unobserve,l=e.disconnect.bind(e);Object.assign(e,{disconnect:function(){s(),l()}}),this.handleVisibilityChange(),this.observe()},V=function(e,n){void 0===n&&(n={});var t=new C(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=V(l(t),t.options),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),P=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]},z=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=P(l(t)),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.windowResize=function(e){},n}(n.Controller);e.ApplicationController=w,e.ClickOutsideController=m,e.IdleController=O,e.IntersectionController=a,e.LazyLoadController=d,e.ResizeController=b,e.UseVisibility=C,e.VisibilityController=L,e.WindowResizeController=z,e.useApplication=g,e.useClickOutside=p,e.useDebounce=function(e,n){var t;null==(t=e.constructor.debounces)||t.forEach(function(t){e[t]=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)}}(e[t],null==n?void 0:n.wait)})},e.useIdle=E,e.useIntersection=c,e.useLazyLoad=u,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.useResize=f,e.useThrottle=function(e,n){var t;null==(t=e.constructor.throttles)||t.forEach(function(t){var i,o,r;e[t]=(i=e[t],void 0===(o=null==n?void 0:n.wait)&&(o=200),function(){var e=arguments,n=this;r||(r=!0,i.apply(n,e),setTimeout(function(){return r=!1},o))})})},e.useVisibility=V,e.useWindowResize=P});
!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),l=s.dispatchEvent,a=s.eventPrefix,u=(null==(c=n)?void 0:c.element)||e.element,d=e.disconnect.bind(e),v=new IntersectionObserver(function(n){var r=n[0];r.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),l){var r=i("appear",e,a),c=o(r,null,{controller:e,entry:n});u.dispatchEvent(c)}}(r):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),l){var r=i("disappear",e,a),c=o(r,null,{controller:e,entry:n});u.dispatchEvent(c)}}(r)},n),f=function(){v.observe(u)},b=function(){v.unobserve(u)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),d()}}),f(),[f,b]};function s(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var a=function(e){function n(n){var t;return(t=e.call(this,n)||this).isVisible=!1,requestAnimationFrame(function(){var e=c(l(t),t.options),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),u=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]},d=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=u(l(t),t.options),n=e[0],i=e[1];Object.assign(l(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),v={dispatchEvent:!0,eventPrefix:!0},f=function(e,n){var r;void 0===n&&(n={});var c=Object.assign(v,n),s=c.dispatchEvent,l=c.eventPrefix,a=(null==(r=n)?void 0:r.element)||e.element,u=e.disconnect.bind(e),d=new ResizeObserver(function(n){var r=n[0];if(e.resize&&t(e,"resize").call(e,r.contentRect),s){var c=i("resize",e,l),u=o(c,null,{controller:e,entry:r});a.dispatchEvent(u)}}),f=function(){d.observe(a)},b=function(){d.unobserve(a)};return Object.assign(e,{disconnect:function(){b(),u()}}),f(),[f,b]},b=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=f(l(t),t.options),n=e[0],i=e[1];Object.assign(l(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,l=r.events,a=r.eventPrefix,u=function(r){var l,u,d=(null==(l=n)?void 0:l.element)||e.element;if(!d.contains(r.target)&&((u=d.getBoundingClientRect()).top>=0&&u.left>=0&&u.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&u.right<=(window.innerWidth||document.documentElement.clientWidth)||!c)&&(e.clickOutside&&t(e,"clickOutside").call(e,r),s)){var v=i("click:outside",e,a),f=o(v,r,{controller:e});d.dispatchEvent(f)}},d=function(){null==l||l.forEach(function(e){window.addEventListener(e,u,!1)})},v=function(){null==l||l.forEach(function(e){window.removeEventListener(e,u,!1)})},f=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){v(),f()}}),d(),[d,v]},m=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=p(l(t),t.options),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),g=function(e){Object.defineProperty(e,"isPreview",{get:function(){return document.documentElement.hasAttribute("data-turbolinks-preview")}}),Object.defineProperty(e,"csrfToken",{get:function(){return this.metaValue("csrf-token")}}),Object.assign(e,{dispatch:function(n,t){var i=void 0===t?{}:t,o=i.target,r=void 0===o?e.element:o,c=i.detail,s=void 0===c?{}:c,l=i.bubbles,a=void 0===l||l,u=i.cancelable,d=void 0===u||u;Object.assign(s,{controller:e});var v=new CustomEvent(e.identifier+":"+n,{detail:s,bubbles:a,cancelable:d});return r.dispatchEvent(v),v},metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})},w=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",g(l(t)),t}s(n,e);var t=n.prototype;return t.dispatch=function(e,n){},t.metaValue=function(e){return""},n}(n.Controller),y={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},E=function(e,n){void 0===n&&(n={});var r=Object.assign(y,n),c=r.ms,s=r.events,l=r.dispatchEvent,a=r.eventPrefix,u=r.initialState,d=setTimeout(function(){u=!0,v()},c),v=function(n){var r=i("away",e,a);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),l){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},f=function(n){var r=i("back",e,a);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),l){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},b=function(e){u&&f(e),u=!1,clearTimeout(d),d=setTimeout(function(){u=!0,v(e)},c)},h=function(e){document.hidden||b(e)};u?v():f();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]},O=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){var e=E(l(t),t.options),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}s(n,e);var t=n.prototype;return t.away=function(){},t.back=function(){},n}(n.Controller),j={dispatchEvent:!0,eventPrefix:!0},C=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(j,n);Object.assign(this,{dispatchEvent:c.dispatchEvent,eventPrefix:c.eventPrefix}),this.controller=e;var s=this.unobserve,l=e.disconnect.bind(e);Object.assign(e,{disconnect:function(){s(),l()}}),this.handleVisibilityChange(),this.observe()},V=function(e,n){void 0===n&&(n={});var t=new C(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=V(l(t),t.options),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),P=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]},z=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=P(l(t)),n=e[0],i=e[1];Object.assign(l(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.windowResize=function(e){},n}(n.Controller),k=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 x(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))}}e.ApplicationController=w,e.ClickOutsideController=m,e.IdleController=O,e.IntersectionController=a,e.LazyLoadController=d,e.ResizeController=b,e.UseVisibility=C,e.VisibilityController=L,e.WindowResizeController=z,e.useApplication=g,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]=k(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=k(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useIdle=E,e.useIntersection=c,e.useLazyLoad=u,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.useResize=f,e.useThrottle=function(e,n){var t;null==(t=e.constructor.throttles)||t.forEach(function(t){if("string"==typeof t&&(e[t]=x(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=x(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useVisibility=V,e.useWindowResize=P});
//# sourceMappingURL=index.umd.js.map

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

export var method = function (controller, methodName) {
var method = controller[methodName];
export const method = (controller, methodName) => {
const method = controller[methodName];
if (typeof method == 'function') {
return method;
}
throw new Error("undefined method \"" + methodName + "\"");
throw new Error(`undefined method "${methodName}"`);
};
export var composeEventName = function (name, controller, eventPrefix) {
var composedName = name;
export const composeEventName = (name, controller, eventPrefix) => {
let composedName = name;
if (eventPrefix === true) {
composedName = controller.identifier + ":" + name;
composedName = `${controller.identifier}:${name}`;
}
else if (typeof eventPrefix === 'string') {
composedName = eventPrefix + ":" + name;
composedName = `${eventPrefix}:${name}`;
}
return composedName;
};
export var extendedEvent = function (type, event, detail) {
var _a = event || { bubbles: true, cancelable: true, composed: true }, bubbles = _a.bubbles, cancelable = _a.cancelable, composed = _a.composed;
export const extendedEvent = (type, event, detail) => {
const { bubbles, cancelable, composed } = event || { bubbles: true, cancelable: true, composed: true };
if (event) {
Object.assign(detail, { originalEvent: event });
}
var customEvent = new CustomEvent(type, {
bubbles: bubbles,
cancelable: cancelable,
composed: composed,
detail: detail,
const customEvent = new CustomEvent(type, {
bubbles,
cancelable,
composed,
detail,
});
return customEvent;
};
export var isElementInViewport = function (el) {
var rect = el.getBoundingClientRect();
export const isElementInViewport = (el) => {
const rect = el.getBoundingClientRect();
return (rect.top >= 0 &&

@@ -34,0 +34,0 @@ rect.left >= 0 &&

@@ -1,33 +0,16 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Controller } from 'stimulus';
import { useApplication } from './use-application';
var ApplicationController = /** @class */ (function (_super) {
__extends(ApplicationController, _super);
function ApplicationController(context) {
var _this = _super.call(this, context) || this;
_this.isPreview = false;
_this.csrfToken = '';
useApplication(_this);
return _this;
export class ApplicationController extends Controller {
constructor(context) {
super(context);
this.isPreview = false;
this.csrfToken = '';
useApplication(this);
}
// define function for Typescript but they are overwitten by useApplication
ApplicationController.prototype.dispatch = function (eventName, eventArgs) { };
ApplicationController.prototype.metaValue = function (name) {
dispatch(eventName, eventArgs) { }
metaValue(name) {
return '';
};
return ApplicationController;
}(Controller));
export { ApplicationController };
}
}
//# sourceMappingURL=application-controller.js.map

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

export var useApplication = function (controller) {
export const useApplication = (controller) => {
// getter to detect Turbolink preview
Object.defineProperty(controller, 'isPreview', {
get: function () {
get() {
return document.documentElement.hasAttribute('data-turbolinks-preview');

@@ -10,3 +10,3 @@ },

Object.defineProperty(controller, 'csrfToken', {
get: function () {
get() {
return this.metaValue('csrf-token');

@@ -16,11 +16,10 @@ },

Object.assign(controller, {
dispatch: function (eventName, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.target, target = _c === void 0 ? controller.element : _c, _d = _b.detail, detail = _d === void 0 ? {} : _d, _e = _b.bubbles, bubbles = _e === void 0 ? true : _e, _f = _b.cancelable, cancelable = _f === void 0 ? true : _f;
dispatch(eventName, { target = controller.element, detail = {}, bubbles = true, cancelable = true } = {}) {
// include the emitting controller in the event detail
Object.assign(detail, { controller: controller });
var type = controller.identifier + ":" + eventName;
var event = new CustomEvent(type, {
detail: detail,
bubbles: bubbles,
cancelable: cancelable,
Object.assign(detail, { controller });
const type = `${controller.identifier}:${eventName}`;
const event = new CustomEvent(type, {
detail,
bubbles,
cancelable,
});

@@ -30,4 +29,4 @@ target.dispatchEvent(event);

},
metaValue: function (name) {
var element = document.head.querySelector("meta[name=\"" + name + "\"]");
metaValue(name) {
const element = document.head.querySelector(`meta[name="${name}"]`);
return element && element.getAttribute('content');

@@ -34,0 +33,0 @@ },

@@ -1,30 +0,13 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Controller } from 'stimulus';
import { useClickOutside } from './use-click-outside';
var ClickOutsideController = /** @class */ (function (_super) {
__extends(ClickOutsideController, _super);
function ClickOutsideController(context) {
var _this = _super.call(this, context) || this;
requestAnimationFrame(function () {
var _a = useClickOutside(_this, _this.options), observe = _a[0], unobserve = _a[1];
Object.assign(_this, { observe: observe, unobserve: unobserve });
export class ClickOutsideController extends Controller {
constructor(context) {
super(context);
requestAnimationFrame(() => {
const [observe, unobserve] = useClickOutside(this, this.options);
Object.assign(this, { observe, unobserve });
});
return _this;
}
ClickOutsideController.prototype.clickOutside = function (event) { };
return ClickOutsideController;
}(Controller));
export { ClickOutsideController };
clickOutside(event) { }
}
//# sourceMappingURL=click-outside-controller.js.map

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

import { method, extendedEvent, isElementInViewport, composeEventName } from '../support';
var defaultOptions = {
import { method, extendedEvent, isElementInViewport, composeEventName } from '../support/index';
const defaultOptions = {
events: ['click', 'touchend'],

@@ -8,7 +8,6 @@ onlyVisible: true,

};
export var useClickOutside = function (controller, options) {
if (options === void 0) { options = {}; }
var _a = Object.assign(defaultOptions, options), onlyVisible = _a.onlyVisible, dispatchEvent = _a.dispatchEvent, events = _a.events, eventPrefix = _a.eventPrefix;
var onEvent = function (event) {
var targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element;
export const useClickOutside = (controller, options = {}) => {
const { onlyVisible, dispatchEvent, events, eventPrefix } = Object.assign(defaultOptions, options);
const onEvent = (event) => {
const targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element;
if (targetElement.contains(event.target) || (!isElementInViewport(targetElement) && onlyVisible)) {

@@ -21,14 +20,14 @@ return;

if (dispatchEvent) {
var eventName = composeEventName('click:outside', controller, eventPrefix);
var clickOutsideEvent = extendedEvent(eventName, event, { controller: controller });
const eventName = composeEventName('click:outside', controller, eventPrefix);
const clickOutsideEvent = extendedEvent(eventName, event, { controller });
targetElement.dispatchEvent(clickOutsideEvent);
}
};
var observe = function () {
events === null || events === void 0 ? void 0 : events.forEach(function (event) {
const observe = () => {
events === null || events === void 0 ? void 0 : events.forEach(event => {
window.addEventListener(event, onEvent, false);
});
};
var unobserve = function () {
events === null || events === void 0 ? void 0 : events.forEach(function (event) {
const unobserve = () => {
events === null || events === void 0 ? void 0 : events.forEach(event => {
window.removeEventListener(event, onEvent, false);

@@ -39,5 +38,5 @@ });

// to support composing several behaviors
var controllerDisconnect = controller.disconnect.bind(controller);
const controllerDisconnect = controller.disconnect.bind(controller);
Object.assign(controller, {
disconnect: function () {
disconnect() {
unobserve();

@@ -44,0 +43,0 @@ controllerDisconnect();

import { Controller } from 'stimulus';
export interface DebounceOptions {
wait?: number;
name?: string;
}
export declare const useDebounce: (controller: Controller, options: DebounceOptions) => void;
declare class DebounceController extends Controller {
static debounces: string[] | DebounceOptions[];
}
export declare const useDebounce: (controller: DebounceController, options: DebounceOptions) => void;
export {};
//# sourceMappingURL=use-debounce.d.ts.map

@@ -1,9 +0,12 @@

var defaultWait = 200;
var debounce = function (fn, wait) {
if (wait === void 0) { wait = defaultWait; }
var timeoutId = null;
import { Controller } from 'stimulus';
class DebounceController extends Controller {
}
DebounceController.debounces = [];
const defaultWait = 200;
const debounce = (fn, wait = defaultWait) => {
let timeoutId = null;
return function () {
var args = arguments;
var context = this;
var callback = function () { return fn.apply(context, args); };
const args = arguments;
const context = this;
const callback = () => fn.apply(context, args);
clearTimeout(timeoutId);

@@ -13,9 +16,17 @@ timeoutId = setTimeout(callback, wait);

};
export var useDebounce = function (controller, options) {
export const useDebounce = (controller, options) => {
var _a;
var constructor = controller.constructor;
(_a = constructor.debounces) === null || _a === void 0 ? void 0 : _a.forEach(function (funcName) {
controller[funcName] = debounce(controller[funcName], options === null || options === void 0 ? void 0 : options.wait);
const constructor = controller.constructor;
(_a = constructor.debounces) === null || _a === void 0 ? void 0 : _a.forEach((func) => {
if (typeof func === "string") {
controller[func] = debounce(controller[func], options === null || options === void 0 ? void 0 : options.wait);
}
if (typeof func === "object") {
const { name, wait } = func;
if (!name)
return;
controller[name] = debounce(controller[name], wait || (options === null || options === void 0 ? void 0 : options.wait));
}
});
};
//# sourceMappingURL=use-debounce.js.map

@@ -1,32 +0,15 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Controller } from 'stimulus';
import { useIdle } from './use-idle';
var IdleController = /** @class */ (function (_super) {
__extends(IdleController, _super);
function IdleController(context) {
var _this = _super.call(this, context) || this;
_this.isIdle = false;
requestAnimationFrame(function () {
var _a = useIdle(_this, _this.options), observe = _a[0], unobserve = _a[1];
Object.assign(_this, { observe: observe, unobserve: unobserve });
export class IdleController extends Controller {
constructor(context) {
super(context);
this.isIdle = false;
requestAnimationFrame(() => {
const [observe, unobserve] = useIdle(this, this.options);
Object.assign(this, { observe, unobserve });
});
return _this;
}
IdleController.prototype.away = function () { };
IdleController.prototype.back = function () { };
return IdleController;
}(Controller));
export { IdleController };
away() { }
back() { }
}
//# sourceMappingURL=idle-controller.js.map

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

import { extendedEvent, method, composeEventName } from '../support';
var defaultEvents = ['mousemove', 'mousedown', 'resize', 'keydown', 'touchstart', 'wheel'];
var oneMinute = 60e3;
var defaultOptions = {
import { extendedEvent, method, composeEventName } from '../support/index';
const defaultEvents = ['mousemove', 'mousedown', 'resize', 'keydown', 'touchstart', 'wheel'];
const oneMinute = 60e3;
const defaultOptions = {
ms: oneMinute,

@@ -11,29 +11,28 @@ initialState: false,

};
export var useIdle = function (controller, options) {
if (options === void 0) { options = {}; }
var _a = Object.assign(defaultOptions, options), ms = _a.ms, initialState = _a.initialState, events = _a.events, dispatchEvent = _a.dispatchEvent, eventPrefix = _a.eventPrefix;
var isIdle = initialState;
var timeout = setTimeout(function () {
export const useIdle = (controller, options = {}) => {
const { ms, initialState, events, dispatchEvent, eventPrefix } = Object.assign(defaultOptions, options);
let isIdle = initialState;
let timeout = setTimeout(() => {
isIdle = true;
dispatchAway();
}, ms);
var dispatchAway = function (event) {
var eventName = composeEventName('away', controller, eventPrefix);
const dispatchAway = (event) => {
const eventName = composeEventName('away', controller, eventPrefix);
controller.isIdle = true;
controller.away && method(controller, 'away').call(controller, event);
if (dispatchEvent) {
var clickOutsideEvent = extendedEvent(eventName, event || null, { controller: controller });
const clickOutsideEvent = extendedEvent(eventName, event || null, { controller });
controller.element.dispatchEvent(clickOutsideEvent);
}
};
var dispatchBack = function (event) {
var eventName = composeEventName('back', controller, eventPrefix);
const dispatchBack = (event) => {
const eventName = composeEventName('back', controller, eventPrefix);
controller.isIdle = false;
controller.back && method(controller, 'back').call(controller, event);
if (dispatchEvent) {
var clickOutsideEvent = extendedEvent(eventName, event || null, { controller: controller });
const clickOutsideEvent = extendedEvent(eventName, event || null, { controller });
controller.element.dispatchEvent(clickOutsideEvent);
}
};
var onEvent = function (event) {
const onEvent = (event) => {
if (isIdle)

@@ -43,3 +42,3 @@ dispatchBack(event);

clearTimeout(timeout);
timeout = setTimeout(function () {
timeout = setTimeout(() => {
isIdle = true;

@@ -49,3 +48,3 @@ dispatchAway(event);

};
var onVisibility = function (event) {
const onVisibility = (event) => {
if (!document.hidden)

@@ -60,5 +59,5 @@ onEvent(event);

}
var controllerDisconnect = controller.disconnect.bind(controller);
var observe = function () {
events.forEach(function (event) {
const controllerDisconnect = controller.disconnect.bind(controller);
const observe = () => {
events.forEach(event => {
window.addEventListener(event, onEvent);

@@ -68,4 +67,4 @@ });

};
var unobserve = function () {
events.forEach(function (event) {
const unobserve = () => {
events.forEach(event => {
window.removeEventListener(event, onEvent);

@@ -76,3 +75,3 @@ });

Object.assign(controller, {
disconnect: function () {
disconnect() {
unobserve();

@@ -79,0 +78,0 @@ controllerDisconnect();

@@ -1,30 +0,13 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Controller } from 'stimulus';
import { useIntersection } from './use-intersection';
var IntersectionController = /** @class */ (function (_super) {
__extends(IntersectionController, _super);
function IntersectionController(context) {
var _this = _super.call(this, context) || this;
_this.isVisible = false;
requestAnimationFrame(function () {
var _a = useIntersection(_this, _this.options), observe = _a[0], unobserve = _a[1];
Object.assign(_this, { observe: observe, unobserve: unobserve });
export class IntersectionController extends Controller {
constructor(context) {
super(context);
this.isVisible = false;
requestAnimationFrame(() => {
const [observe, unobserve] = useIntersection(this, this.options);
Object.assign(this, { observe, unobserve });
});
return _this;
}
return IntersectionController;
}(Controller));
export { IntersectionController };
}
//# sourceMappingURL=intersection-controller.js.map

@@ -1,12 +0,11 @@

import { method, extendedEvent, composeEventName } from '../support';
var defaultOptions = {
import { method, extendedEvent, composeEventName } from '../support/index';
const defaultOptions = {
dispatchEvent: true,
eventPrefix: true,
};
export var useIntersection = function (controller, options) {
if (options === void 0) { options = {}; }
var _a = Object.assign(defaultOptions, options), dispatchEvent = _a.dispatchEvent, eventPrefix = _a.eventPrefix;
var targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element;
var callback = function (entries) {
var entry = entries[0];
export const useIntersection = (controller, options = {}) => {
const { dispatchEvent, eventPrefix } = Object.assign(defaultOptions, options);
const targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element;
const callback = (entries) => {
const [entry] = entries;
if (entry.isIntersecting) {

@@ -19,3 +18,3 @@ dispatchAppear(entry);

};
var dispatchAppear = function (entry) {
const dispatchAppear = (entry) => {
controller.isVisible = true;

@@ -25,8 +24,8 @@ controller.appear && method(controller, 'appear').call(controller, entry);

if (dispatchEvent) {
var eventName = composeEventName('appear', controller, eventPrefix);
var appearEvent = extendedEvent(eventName, null, { controller: controller, entry: entry });
const eventName = composeEventName('appear', controller, eventPrefix);
const appearEvent = extendedEvent(eventName, null, { controller, entry });
targetElement.dispatchEvent(appearEvent);
}
};
var dispatchDisappear = function (entry) {
const dispatchDisappear = (entry) => {
controller.isVisible = false;

@@ -36,4 +35,4 @@ controller.disappear && method(controller, 'disappear').call(controller, entry);

if (dispatchEvent) {
var eventName = composeEventName('disappear', controller, eventPrefix);
var disappearEvent = extendedEvent(eventName, null, { controller: controller, entry: entry });
const eventName = composeEventName('disappear', controller, eventPrefix);
const disappearEvent = extendedEvent(eventName, null, { controller, entry });
targetElement.dispatchEvent(disappearEvent);

@@ -44,8 +43,8 @@ }

// to support composing several behaviors
var controllerDisconnect = controller.disconnect.bind(controller);
var observer = new IntersectionObserver(callback, options);
var observe = function () {
const controllerDisconnect = controller.disconnect.bind(controller);
const observer = new IntersectionObserver(callback, options);
const observe = () => {
observer.observe(targetElement);
};
var unobserve = function () {
const unobserve = () => {
observer.unobserve(targetElement);

@@ -55,3 +54,3 @@ };

isVisible: false,
disconnect: function () {
disconnect() {
unobserve();

@@ -58,0 +57,0 @@ controllerDisconnect();

@@ -1,34 +0,17 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Controller } from 'stimulus';
import { useLazyLoad } from './useLazyLoad';
var LazyLoadController = /** @class */ (function (_super) {
__extends(LazyLoadController, _super);
function LazyLoadController(context) {
var _this = _super.call(this, context) || this;
_this.isLoading = false;
_this.isLoaded = false;
_this.options = { rootMargin: '10%' };
requestAnimationFrame(function () {
var _a = useLazyLoad(_this, _this.options), observe = _a[0], unobserve = _a[1];
Object.assign(_this, { observe: observe, unobserve: unobserve });
export class LazyLoadController extends Controller {
constructor(context) {
super(context);
this.isLoading = false;
this.isLoaded = false;
this.options = { rootMargin: '10%' };
requestAnimationFrame(() => {
const [observe, unobserve] = useLazyLoad(this, this.options);
Object.assign(this, { observe, unobserve });
});
return _this;
}
LazyLoadController.prototype.loading = function (src) { };
LazyLoadController.prototype.loaded = function (src) { };
return LazyLoadController;
}(Controller));
export { LazyLoadController };
loading(src) { }
loaded(src) { }
}
//# sourceMappingURL=lazy-load-controller.js.map

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

import { method } from '../support';
export var useLazyLoad = function (controller, options) {
var callback = function (entries) {
var entry = entries[0];
import { method } from '../support/index';
export const useLazyLoad = (controller, options) => {
const callback = (entries) => {
const [entry] = entries;
if (entry.isIntersecting && !controller.isLoaded) {

@@ -9,10 +9,10 @@ handleAppear(entry);

};
var handleAppear = function (entry) {
var src = controller.data.get('src');
const handleAppear = (entry) => {
const src = controller.data.get('src');
if (!src)
return;
var imageElement = controller.element;
const imageElement = controller.element;
controller.isLoading = true;
controller.loading && method(controller, 'loading').call(controller, src);
imageElement.onload = function () {
imageElement.onload = () => {
handleLoaded(src);

@@ -22,3 +22,3 @@ };

};
var handleLoaded = function (src) {
const handleLoaded = (src) => {
controller.isLoading = false;

@@ -29,8 +29,8 @@ controller.isLoaded = true;

// keep a copy of the current disconnect() function of the controller to not override it
var controllerDisconnect = controller.disconnect.bind(controller);
var observer = new IntersectionObserver(callback, options);
var observe = function () {
const controllerDisconnect = controller.disconnect.bind(controller);
const observer = new IntersectionObserver(callback, options);
const observe = () => {
observer.observe(controller.element);
};
var unobserve = function () {
const unobserve = () => {
observer.unobserve(controller.element);

@@ -40,3 +40,3 @@ };

isVisible: false,
disconnect: function () {
disconnect() {
unobserve();

@@ -43,0 +43,0 @@ controllerDisconnect();

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

var memoize = function (controller, name, value) {
Object.defineProperty(controller, name, { value: value });
const memoize = (controller, name, value) => {
Object.defineProperty(controller, name, { value });
return value;
};
export var useMemo = function (controller) {
export const useMemo = (controller) => {
var _a;
(_a = controller.constructor.memos) === null || _a === void 0 ? void 0 : _a.forEach(function (getter) {
(_a = controller.constructor.memos) === null || _a === void 0 ? void 0 : _a.forEach((getter) => {
memoize(controller, getter, controller[getter]);

@@ -9,0 +9,0 @@ });

@@ -1,30 +0,13 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Controller } from 'stimulus';
import { useResize } from './use-resize';
var ResizeController = /** @class */ (function (_super) {
__extends(ResizeController, _super);
function ResizeController(context) {
var _this = _super.call(this, context) || this;
requestAnimationFrame(function () {
var _a = useResize(_this, _this.options), observe = _a[0], unobserve = _a[1];
Object.assign(_this, { observe: observe, unobserve: unobserve });
export class ResizeController extends Controller {
constructor(context) {
super(context);
requestAnimationFrame(() => {
const [observe, unobserve] = useResize(this, this.options);
Object.assign(this, { observe, unobserve });
});
return _this;
}
ResizeController.prototype.resize = function (contentRect) { };
return ResizeController;
}(Controller));
export { ResizeController };
resize(contentRect) { }
}
//# sourceMappingURL=resize-controller.js.map

@@ -1,19 +0,18 @@

import { method, extendedEvent, composeEventName } from '../support';
var defaultOptions = {
import { method, extendedEvent, composeEventName } from '../support/index';
const defaultOptions = {
dispatchEvent: true,
eventPrefix: true,
};
export var useResize = function (controller, options) {
if (options === void 0) { options = {}; }
var _a = Object.assign(defaultOptions, options), dispatchEvent = _a.dispatchEvent, eventPrefix = _a.eventPrefix;
var targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element;
var callback = function (entries) {
var entry = entries[0];
export const useResize = (controller, options = {}) => {
const { dispatchEvent, eventPrefix } = Object.assign(defaultOptions, options);
const targetElement = (options === null || options === void 0 ? void 0 : options.element) || controller.element;
const callback = (entries) => {
const [entry] = entries;
controller.resize && method(controller, 'resize').call(controller, entry.contentRect);
// emit a custom "controllerIdentifier:resize" event
if (dispatchEvent) {
var eventName = composeEventName('resize', controller, eventPrefix);
var appearEvent = extendedEvent(eventName, null, {
controller: controller,
entry: entry,
const eventName = composeEventName('resize', controller, eventPrefix);
const appearEvent = extendedEvent(eventName, null, {
controller,
entry,
});

@@ -23,12 +22,12 @@ targetElement.dispatchEvent(appearEvent);

};
var controllerDisconnect = controller.disconnect.bind(controller);
var observer = new ResizeObserver(callback);
var observe = function () {
const controllerDisconnect = controller.disconnect.bind(controller);
const observer = new ResizeObserver(callback);
const observe = () => {
observer.observe(targetElement);
};
var unobserve = function () {
const unobserve = () => {
observer.unobserve(targetElement);
};
Object.assign(controller, {
disconnect: function () {
disconnect() {
unobserve();

@@ -35,0 +34,0 @@ controllerDisconnect();

import { Controller } from 'stimulus';
export interface ThrottleOptions {
wait?: number;
name?: string;
}
declare class ThrottleController extends Controller {
static trottles: string[] | ThrottleOptions[];
}
export declare function throttle(func: Function, wait?: number): Function;
export declare const useThrottle: (controller: Controller, options: ThrottleOptions) => void;
export declare const useThrottle: (controller: ThrottleController, options: ThrottleOptions) => void;
export {};
//# sourceMappingURL=use-throttle.d.ts.map

@@ -1,21 +0,33 @@

var defaultWait = 200;
export function throttle(func, wait) {
if (wait === void 0) { wait = defaultWait; }
var inThrottle;
import { Controller } from 'stimulus';
class ThrottleController extends Controller {
}
ThrottleController.trottles = [];
const defaultWait = 200;
export function throttle(func, wait = defaultWait) {
let inThrottle;
return function () {
var args = arguments;
var context = this;
const args = arguments;
const context = this;
if (!inThrottle) {
inThrottle = true;
func.apply(context, args);
setTimeout(function () { return (inThrottle = false); }, wait);
setTimeout(() => (inThrottle = false), wait);
}
};
}
export var useThrottle = function (controller, options) {
export const useThrottle = (controller, options) => {
var _a;
(_a = controller.constructor.throttles) === null || _a === void 0 ? void 0 : _a.forEach(function (funcName) {
controller[funcName] = throttle(controller[funcName], options === null || options === void 0 ? void 0 : options.wait);
const constructor = controller.constructor;
(_a = constructor.throttles) === null || _a === void 0 ? void 0 : _a.forEach((func) => {
if (typeof func === "string") {
controller[func] = throttle(controller[func], options === null || options === void 0 ? void 0 : options.wait);
}
if (typeof func === "object") {
const { name, wait } = func;
if (!name)
return;
controller[name] = throttle(controller[name], wait || (options === null || options === void 0 ? void 0 : options.wait));
}
});
};
//# sourceMappingURL=use-throttle.js.map

@@ -1,52 +0,50 @@

import { extendedEvent, method, composeEventName } from '../support';
var defaultOptions = {
import { extendedEvent, method, composeEventName } from '../support/index';
const defaultOptions = {
dispatchEvent: true,
eventPrefix: true
};
var UseVisibility = /** @class */ (function () {
function UseVisibility(controller, options) {
var _this = this;
if (options === void 0) { options = {}; }
this.observe = function () {
_this.controller.isVisible = !document.hidden;
document.addEventListener('visibilitychange', _this.handleVisibilityChange);
export class UseVisibility {
constructor(controller, options = {}) {
this.observe = () => {
this.controller.isVisible = !document.hidden;
document.addEventListener('visibilitychange', this.handleVisibilityChange);
};
this.unobserve = function () {
document.removeEventListener('visibilitychange', _this.handleVisibilityChange);
this.unobserve = () => {
document.removeEventListener('visibilitychange', this.handleVisibilityChange);
};
// private
this.dispatchInvisible = function (event) {
var eventName = composeEventName('invisible', _this.controller, _this.eventPrefix);
_this.controller.isVisible = false;
_this.controller.invisible && method(_this.controller, 'invisible').call(_this.controller, event);
_this.dispatch(eventName, event);
this.dispatchInvisible = (event) => {
const eventName = composeEventName('invisible', this.controller, this.eventPrefix);
this.controller.isVisible = false;
this.controller.invisible && method(this.controller, 'invisible').call(this.controller, event);
this.dispatch(eventName, event);
};
this.dispatchVisible = function (event) {
var eventName = composeEventName('visible', _this.controller, _this.eventPrefix);
_this.controller.isVisible = true;
_this.controller.visible && method(_this.controller, 'visible').call(_this.controller, event);
_this.dispatch(eventName, event);
this.dispatchVisible = (event) => {
const eventName = composeEventName('visible', this.controller, this.eventPrefix);
this.controller.isVisible = true;
this.controller.visible && method(this.controller, 'visible').call(this.controller, event);
this.dispatch(eventName, event);
};
this.dispatch = function (eventName, event) {
if (_this.dispatchEvent) {
var visibilityEvent = extendedEvent(eventName, event || null, { controller: _this.controller });
_this.controller.element.dispatchEvent(visibilityEvent);
this.dispatch = (eventName, event) => {
if (this.dispatchEvent) {
const visibilityEvent = extendedEvent(eventName, event || null, { controller: this.controller });
this.controller.element.dispatchEvent(visibilityEvent);
}
};
this.handleVisibilityChange = function (event) {
this.handleVisibilityChange = (event) => {
if (document.hidden) {
_this.dispatchInvisible(event);
this.dispatchInvisible(event);
}
else {
_this.dispatchVisible(event);
this.dispatchVisible(event);
}
};
var _a = Object.assign(defaultOptions, options), dispatchEvent = _a.dispatchEvent, eventPrefix = _a.eventPrefix;
Object.assign(this, { dispatchEvent: dispatchEvent, eventPrefix: eventPrefix });
const { dispatchEvent, eventPrefix } = Object.assign(defaultOptions, options);
Object.assign(this, { dispatchEvent, eventPrefix });
this.controller = controller;
// make a copy as tthis.unobserve is not available within Object.assign ??
var unobserve = this.unobserve;
var controllerDisconnect = controller.disconnect.bind(controller);
const unobserve = this.unobserve;
const controllerDisconnect = controller.disconnect.bind(controller);
Object.assign(controller, {
disconnect: function () {
disconnect() {
unobserve();

@@ -60,10 +58,7 @@ controllerDisconnect();

}
return UseVisibility;
}());
export { UseVisibility };
export var useVisibility = function (controller, options) {
if (options === void 0) { options = {}; }
var observer = new UseVisibility(controller, options);
}
export const useVisibility = (controller, options = {}) => {
const observer = new UseVisibility(controller, options);
return [observer.observe, observer.unobserve];
};
//# sourceMappingURL=use-visibility.js.map

@@ -1,29 +0,12 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Controller } from 'stimulus';
import { useVisibility } from './use-visibility';
var VisibilityController = /** @class */ (function (_super) {
__extends(VisibilityController, _super);
function VisibilityController(context) {
var _this = _super.call(this, context) || this;
requestAnimationFrame(function () {
var _a = useVisibility(_this, _this.options), observe = _a[0], unobserve = _a[1];
Object.assign(_this, { observe: observe, unobserve: unobserve });
export class VisibilityController extends Controller {
constructor(context) {
super(context);
requestAnimationFrame(() => {
const [observe, unobserve] = useVisibility(this, this.options);
Object.assign(this, { observe, unobserve });
});
return _this;
}
return VisibilityController;
}(Controller));
export { VisibilityController };
}
//# sourceMappingURL=visibility-controller.js.map
export { useWindowResize } from './use-window-resize';
export { WindowResizeController } from './window-resize-controller';
//# sourceMappingURL=index.d.ts.map

@@ -0,0 +0,0 @@ import { WindowResizeController } from './window-resize-controller';

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

import { method } from '../support';
export var useWindowResize = function (controller) {
var callback = function (event) {
var innerWidth = window.innerWidth, innerHeight = window.innerHeight;
var payload = {
import { method } from '../support/index';
export const useWindowResize = (controller) => {
const callback = (event) => {
const { innerWidth, innerHeight } = window;
const payload = {
height: innerHeight || Infinity,
width: innerWidth || Infinity,
event: event
event
};
controller.windowResize && method(controller, 'windowResize').call(controller, payload);
};
var controllerDisconnect = controller.disconnect.bind(controller);
var observe = function () {
const controllerDisconnect = controller.disconnect.bind(controller);
const observe = () => {
window.addEventListener('resize', callback);
callback();
};
var unobserve = function () {
const unobserve = () => {
window.removeEventListener('resize', callback);
};
Object.assign(controller, {
disconnect: function () {
disconnect() {
unobserve();

@@ -23,0 +23,0 @@ controllerDisconnect();

@@ -0,0 +0,0 @@ import { Controller, Context } from 'stimulus';

@@ -1,30 +0,13 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Controller } from 'stimulus';
import { useWindowResize } from './use-window-resize';
var WindowResizeController = /** @class */ (function (_super) {
__extends(WindowResizeController, _super);
function WindowResizeController(context) {
var _this = _super.call(this, context) || this;
requestAnimationFrame(function () {
var _a = useWindowResize(_this), observe = _a[0], unobserve = _a[1];
Object.assign(_this, { observe: observe, unobserve: unobserve });
export class WindowResizeController extends Controller {
constructor(context) {
super(context);
requestAnimationFrame(() => {
const [observe, unobserve] = useWindowResize(this);
Object.assign(this, { observe, unobserve });
});
return _this;
}
WindowResizeController.prototype.windowResize = function (payload) { };
return WindowResizeController;
}(Controller));
export { WindowResizeController };
windowResize(payload) { }
}
//# sourceMappingURL=window-resize-controller.js.map
{
"name": "stimulus-use",
"version": "0.16.0-0",
"version": "0.16.1-0",
"description": "A collection of standard controllers and utilities for Stimulus",

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

"test:watch": "NODE_ENV=test karma start --auto-watch --no-single-run",
"test:treeshake": "$npm_execpath run agadoo",
"dev": "tsc -b -w",
"clean": "rimraf dist *.tsbuildinfo coverage",
"doc": "docsify serve ./docs",
"prerelease": "$npm_execpath run build && $npm_execpath run test:treeshake",
"release": "np",

@@ -32,2 +34,3 @@ "cypress:open": "cypress open",

"@babel/preset-modules": "^0.1.4",
"agadoo": "^2.0.0",
"babel-loader": "^8.1.0",

@@ -34,0 +37,0 @@ "chai": "^4.2.0",

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

export { useIntersection, IntersectionController } from './use-intersection'
export { useLazyLoad, LazyLoadController } from './use-lazy-load'
export { useResize, ResizeController } from './use-resize'
export { useClickOutside, ClickOutsideController } from './use-click-outside'
export { useApplication, ApplicationController } from './use-application'
export { useIdle, IdleController } from './use-idle'
export { useVisibility, UseVisibility, VisibilityController } from './use-visibility'
export { useWindowResize, WindowResizeController } from './use-window-resize'
export { useMemo } from './use-memo'
export { useDebounce } from './use-debounce'
export { useThrottle } from './use-throttle'
export { useIntersection, IntersectionController } from './use-intersection/index'
export { useLazyLoad, LazyLoadController } from './use-lazy-load/index'
export { useResize, ResizeController } from './use-resize/index'
export { useClickOutside, ClickOutsideController } from './use-click-outside/index'
export { useApplication, ApplicationController } from './use-application/index'
export { useIdle, IdleController } from './use-idle/index'
export { useVisibility, UseVisibility, VisibilityController } from './use-visibility/index'
export { useWindowResize, WindowResizeController } from './use-window-resize/index'
export { useMemo } from './use-memo/index'
export { useDebounce } from './use-debounce/index'
export { useThrottle } from './use-throttle/index'
import { Controller } from 'stimulus'
import { method, extendedEvent, isElementInViewport, composeEventName } from '../support'
import { method, extendedEvent, isElementInViewport, composeEventName } from '../support/index'

@@ -4,0 +4,0 @@ interface ClickOutsideController extends Controller {

@@ -5,4 +5,9 @@ import { Controller } from 'stimulus'

wait?: number
name?: string
}
class DebounceController extends Controller {
static debounces: string[] | DebounceOptions[] = []
}
const defaultWait = 200

@@ -23,7 +28,16 @@

export const useDebounce = (controller: Controller, options: DebounceOptions) => {
export const useDebounce = (controller: DebounceController, options: DebounceOptions) => {
const constructor = controller.constructor as any
constructor.debounces?.forEach((funcName: string) => {
(controller as any)[funcName] = debounce((controller as any)[funcName] as Function, options?.wait)
constructor.debounces?.forEach((func: string | DebounceOptions) => {
if (typeof func === "string") {
(controller as any)[func] = debounce((controller as any)[func] as Function, options?.wait)
}
if (typeof func === "object") {
const { name, wait } = func as DebounceOptions
if (!name) return
(controller as any)[name] = debounce((controller as any)[name] as Function, wait || options?.wait)
}
})
}
import { IdleController } from './idle-controller'
import { extendedEvent, method, composeEventName } from '../support'
import { extendedEvent, method, composeEventName } from '../support/index'

@@ -4,0 +4,0 @@ const defaultEvents = ['mousemove', 'mousedown', 'resize', 'keydown', 'touchstart', 'wheel']

import { IntersectionController } from './intersection-controller'
import { method, extendedEvent, composeEventName } from '../support'
import { method, extendedEvent, composeEventName } from '../support/index'

@@ -4,0 +4,0 @@ export interface IntersectionOptions extends IntersectionObserverInit {

import { LazyLoadController } from './lazy-load-controller'
import { method } from '../support'
import { method } from '../support/index'

@@ -4,0 +4,0 @@ export const useLazyLoad = (controller: LazyLoadController, options?: IntersectionObserverInit) => {

import { ResizeController } from './resize-controller'
import { method, extendedEvent, composeEventName } from '../support'
import { method, extendedEvent, composeEventName } from '../support/index'

@@ -4,0 +4,0 @@ export interface ResizeOptions {

@@ -5,4 +5,9 @@ import { Controller } from 'stimulus'

wait?: number
name?: string
}
class ThrottleController extends Controller {
static trottles: string[] | ThrottleOptions[] = []
}
const defaultWait = 200

@@ -25,6 +30,16 @@

export const useThrottle = (controller: Controller, options: ThrottleOptions) => {
(controller.constructor as any).throttles?.forEach((funcName: string) => {
(controller as any)[funcName] = throttle((controller as any)[funcName] as Function, options?.wait)
export const useThrottle = (controller: ThrottleController, options: ThrottleOptions) => {
const constructor = controller.constructor as any
constructor.throttles?.forEach((func: string | ThrottleOptions) => {
if (typeof func === "string") {
(controller as any)[func] = throttle((controller as any)[func] as Function, options?.wait)
}
if (typeof func === "object") {
const { name, wait } = func as ThrottleOptions
if (!name) return
(controller as any)[name] = throttle((controller as any)[name] as Function, wait || options?.wait)
}
})
}
import { VisibilityController } from './visibility-controller'
import { extendedEvent, method, composeEventName } from '../support'
import { extendedEvent, method, composeEventName } from '../support/index'

@@ -4,0 +4,0 @@ export interface VisibilityOptions {

import { WindowResizeController } from './window-resize-controller'
import { method } from '../support'
import { method } from '../support/index'

@@ -4,0 +4,0 @@ export interface WindowResizePayload {

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

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

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

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

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

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

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

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

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