stimulus-use
Advanced tools
Comparing version 0.21.4 to 0.22.0-0
@@ -14,2 +14,3 @@ export { useIntersection, IntersectionController } from './use-intersection/index'; | ||
export { useMeta } from './use-meta/index'; | ||
export { useTransition, TransitionOptions, TransitionController } from './use-transition/index'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -14,2 +14,3 @@ export { useIntersection, IntersectionController } from './use-intersection/index'; | ||
export { useMeta } from './use-meta/index'; | ||
export { useTransition, TransitionController } from './use-transition/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 l=Object.assign({},r,n),s=l.dispatchEvent,u=l.eventPrefix,a=(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),s){var r=i("appear",e,u),c=o(r,null,{controller:e,entry:n});a.dispatchEvent(c)}}(r):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),s){var r=i("disappear",e,u),c=o(r,null,{controller:e,entry:n});a.dispatchEvent(c)}}(r)},n),f=function(){v.observe(a)},b=function(){v.unobserve(a)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),d()}}),f(),[f,b]};function l(){return(l=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e}).apply(this,arguments)}function s(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function u(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(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),d=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=d(u(t),t.options),n=e[0],i=e[1];Object.assign(u(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},b=function(e,n){var r;void 0===n&&(n={});var c=Object.assign({},f,n),l=c.dispatchEvent,s=c.eventPrefix,u=(null==(r=n)?void 0:r.element)||e.element,a=e.disconnect.bind(e),d=new ResizeObserver(function(n){var r=n[0];if(e.resize&&t(e,"resize").call(e,r.contentRect),l){var c=i("resize",e,s),a=o(c,null,{controller:e,entry:r});u.dispatchEvent(a)}}),v=function(){d.observe(u)},b=function(){d.unobserve(u)};return Object.assign(e,{disconnect:function(){b(),a()}}),v(),[v,b]},h=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=b(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.resize=function(e){},n}(n.Controller),p={events:["click","touchend"],onlyVisible:!0,dispatchEvent:!0,eventPrefix:!0},m=function(e,n){void 0===n&&(n={});var r=Object.assign({},p,n),c=r.onlyVisible,l=r.dispatchEvent,s=r.events,u=r.eventPrefix,a=function(r){var s,a,d=(null==(s=n)?void 0:s.element)||e.element;if(!d.contains(r.target)&&((a=d.getBoundingClientRect()).top>=0&&a.left>=0&&a.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&a.right<=(window.innerWidth||document.documentElement.clientWidth)||!c)&&(e.clickOutside&&t(e,"clickOutside").call(e,r),l)){var v=i("click:outside",e,u),f=o(v,r,{controller:e});d.dispatchEvent(f)}},d=function(){null==s||s.forEach(function(e){window.addEventListener(e,a,!1)})},v=function(){null==s||s.forEach(function(e){window.removeEventListener(e,a,!1)})},f=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){v(),f()}}),d(),[d,v]},g=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=m(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),y={debug:!1,logger:console},w=function(e,n){var t,i,o=this;void 0===n&&(n={}),this.log=function(e,n){o.debug&&(o.logger.groupCollapsed("%c"+o.controller.identifier+"#%c"+e,"color: #3B82F6","color: unset"),o.logger.log(l({controllerId:o.controllerId},n)),o.logger.groupEnd())},this.debug=(null==(t=n)?void 0:t.debug)||e.application.stimulusUseDebug||y.debug,this.logger=(null==(i=n)?void 0:i.logger)||y.logger,this.controller=e,this.controllerId=e.element.id||e.element.dataset.id,this.controllerInitialize=e.initialize.bind(e),this.controllerConnect=e.connect.bind(e),this.controllerDisconnect=e.disconnect.bind(e)},E=function(e){function n(n,t){var o,r,c,l,s;return void 0===t&&(t={}),(s=e.call(this,n,t)||this).dispatch=function(e,n){void 0===n&&(n={});var t=u(s),o=t.targetElement,r=t.eventPrefix,c=t.bubbles,l=t.cancelable,a=t.log;Object.assign(n,{controller:t.controller});var d=i(e,s.controller,r),v=new CustomEvent(d,{detail:n,bubbles:c,cancelable:l});return o.dispatchEvent(v),a("dispatch",{eventName:d,detail:n,bubbles:c,cancelable:l}),v},s.targetElement=null!=(o=t.element)?o:n.element,s.eventPrefix=null==(r=t.eventPrefix)||r,s.bubbles=null==(c=t.bubbles)||c,s.cancelable=null==(l=t.cancelable)||l,s.enhanceController(),s}return s(n,e),n.prototype.enhanceController=function(){Object.assign(this.controller,{dispatch:this.dispatch})},n}(w),O=function(e,n){return void 0===n&&(n={}),new E(e,n)},j=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")}}),O(e,n),Object.assign(e,{metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})},C=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",j(u(t),t.options),t}return s(n,e),n}(n.Controller),V={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},P=function(e,n){void 0===n&&(n={});var r=Object.assign({},V,n),c=r.ms,l=r.events,s=r.dispatchEvent,u=r.eventPrefix,a=r.initialState,d=setTimeout(function(){a=!0,v()},c),v=function(n){var r=i("away",e,u);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),s){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},f=function(n){var r=i("back",e,u);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),s){var c=o(r,n||null,{controller:e});e.element.dispatchEvent(c)}},b=function(e){a&&f(e),a=!1,clearTimeout(d),d=setTimeout(function(){a=!0,v(e)},c)},h=function(e){document.hidden||b(e)};a?v():f();var p=e.disconnect.bind(e),m=function(){l.forEach(function(e){window.addEventListener(e,b)}),document.addEventListener("visibilitychange",h)},g=function(){l.forEach(function(e){window.removeEventListener(e,b)}),document.removeEventListener("visibilitychange",h)};return Object.assign(e,{disconnect:function(){g(),p()}}),m(),[m,g]},x=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){var e=P(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}s(n,e);var t=n.prototype;return t.away=function(){},t.back=function(){},n}(n.Controller),z={dispatchEvent:!0,eventPrefix:!0},L=function(e){function n(n,r){var c;void 0===r&&(r={}),(c=e.call(this,n,r)||this).observe=function(){c.controller.isVisible=!document.hidden,document.addEventListener("visibilitychange",c.handleVisibilityChange)},c.unobserve=function(){document.removeEventListener("visibilitychange",c.handleVisibilityChange)},c.becomesInvisible=function(e){var n=i("invisible",c.controller,c.eventPrefix);c.controller.isVisible=!1,c.controller.invisible&&t(c.controller,"invisible").call(c.controller,e),c.log("invisible",{isVisible:!1}),c.dispatch(n,e)},c.becomesVisible=function(e){var n=i("visible",c.controller,c.eventPrefix);c.controller.isVisible=!0,c.controller.visible&&t(c.controller,"visible").call(c.controller,e),c.log("visible",{isVisible:!0}),c.dispatch(n,e)},c.dispatch=function(e,n){if(c.dispatchEvent){var t={controller:c.controller,isVisible:c.controller.isVisible},i=o(e,n||null,t);c.controller.element.dispatchEvent(i),c.log("dispatchEvent",l({eventName:e},t))}},c.handleVisibilityChange=function(e){document.hidden?c.becomesInvisible(e):c.becomesVisible(e)};var s=Object.assign({},z,r),a=s.dispatchEvent,d=s.eventPrefix;return Object.assign(u(c),{dispatchEvent:a,eventPrefix:d}),c.controller=n,Object.assign(n,{disconnect:function(){c.unobserve(),c.controllerDisconnect()}}),c.handleVisibilityChange(),c.observe(),c}return s(n,e),n}(w),I=function(e,n){void 0===n&&(n={});var t=new L(e,n);return[t.observe,t.unobserve]},k=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=I(u(t),t.options),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return s(n,e),n}(n.Controller),A=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]},R=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=A(u(t)),n=e[0],i=e[1];Object.assign(u(t),{observe:n,unobserve:i})}),t}return s(n,e),n.prototype.windowResize=function(e){},n}(n.Controller),q=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 T(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 F(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}function S(e){try{return JSON.parse(e)}catch(n){return e}}function D(e){return e.replace(/(?:[_-])([a-z0-9])/g,function(e,n){return n.toUpperCase()})}e.ApplicationController=C,e.ClickOutsideController=g,e.IdleController=x,e.IntersectionController=a,e.LazyLoadController=v,e.ResizeController=h,e.UseVisibility=L,e.VisibilityController=k,e.WindowResizeController=R,e.useApplication=j,e.useClickOutside=m,e.useDebounce=function(e,n){var t;null==(t=e.constructor.debounces)||t.forEach(function(t){if("string"==typeof t&&(e[t]=q(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=q(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useDispatch=O,e.useIdle=P,e.useIntersection=c,e.useLazyLoad=d,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?D(n)+"Meta":D(n);Object.defineProperty(e,i,{get:function(){return S(F(n))}})}(e,n,i)}),Object.defineProperty(e,"metas",{get:function(){var e={};return null==t||t.forEach(function(n){var t=S(F(n));null!=t&&(e[D(n)]=t)}),e}})},e.useResize=b,e.useThrottle=function(e,n){var t;null==(t=e.constructor.throttles)||t.forEach(function(t){if("string"==typeof t&&(e[t]=T(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=T(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useVisibility=I,e.useWindowResize=A}); | ||
!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},r=function(e,n,t){var i=n||{bubbles:!0,cancelable:!0,composed:!0},r=i.bubbles,o=i.cancelable,s=i.composed;return n&&Object.assign(t,{originalEvent:n}),new CustomEvent(e,{bubbles:r,cancelable:o,composed:s,detail:t})},o={dispatchEvent:!0,eventPrefix:!0},s=function(e,n){var s;void 0===n&&(n={});var c=Object.assign({},o,n),l=c.dispatchEvent,a=c.eventPrefix,u=(null==(s=n)?void 0:s.element)||e.element,v=e.disconnect.bind(e),d=new IntersectionObserver(function(n){var o=n[0];o.isIntersecting?function(n){if(e.isVisible=!0,e.appear&&t(e,"appear").call(e,n),l){var o=i("appear",e,a),s=r(o,null,{controller:e,entry:n});u.dispatchEvent(s)}}(o):e.isVisible&&function(n){if(e.isVisible=!1,e.disappear&&t(e,"disappear").call(e,n),l){var o=i("disappear",e,a),s=r(o,null,{controller:e,entry:n});u.dispatchEvent(s)}}(o)},n),f=function(){d.observe(u)},b=function(){d.unobserve(u)};return Object.assign(e,{isVisible:!1,disconnect:function(){b(),v()}}),f(),[f,b]};function c(){return(c=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e}).apply(this,arguments)}function l(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=s(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(n.Controller),v=function(e,n){var i=e.disconnect.bind(e),r=new IntersectionObserver(function(n){n[0].isIntersecting&&!e.isLoaded&&function(n){var i=e.data.get("src");if(i){var r=e.element;e.isLoading=!0,e.loading&&t(e,"loading").call(e,i),r.onload=function(){!function(n){e.isLoading=!1,e.isLoaded=!0,e.loading&&t(e,"loaded").call(e,n)}(i)},r.src=i}}()},n),o=function(){r.observe(e.element)},s=function(){r.unobserve(e.element)};return Object.assign(e,{isVisible:!1,disconnect:function(){s(),i()}}),o(),[o,s]},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=v(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}l(n,e);var t=n.prototype;return t.loading=function(e){},t.loaded=function(e){},n}(n.Controller),f={dispatchEvent:!0,eventPrefix:!0},b=function(e,n){var o;void 0===n&&(n={});var s=Object.assign({},f,n),c=s.dispatchEvent,l=s.eventPrefix,a=(null==(o=n)?void 0:o.element)||e.element,u=e.disconnect.bind(e),v=new ResizeObserver(function(n){var o=n[0];if(e.resize&&t(e,"resize").call(e,o.contentRect),c){var s=i("resize",e,l),u=r(s,null,{controller:e,entry:o});a.dispatchEvent(u)}}),d=function(){v.observe(a)},b=function(){v.unobserve(a)};return Object.assign(e,{disconnect:function(){b(),u()}}),d(),[d,b]},h=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=b(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n.prototype.resize=function(e){},n}(n.Controller),m={events:["click","touchend"],onlyVisible:!0,dispatchEvent:!0,eventPrefix:!0},p=function(e,n){void 0===n&&(n={});var o=Object.assign({},m,n),s=o.onlyVisible,c=o.dispatchEvent,l=o.events,a=o.eventPrefix,u=function(o){var l,u,v=(null==(l=n)?void 0:l.element)||e.element;if(!v.contains(o.target)&&((u=v.getBoundingClientRect()).top>=0&&u.left>=0&&u.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&u.right<=(window.innerWidth||document.documentElement.clientWidth)||!s)&&(e.clickOutside&&t(e,"clickOutside").call(e,o),c)){var d=i("click:outside",e,a),f=r(d,o,{controller:e});v.dispatchEvent(f)}},v=function(){null==l||l.forEach(function(e){window.addEventListener(e,u,!1)})},d=function(){null==l||l.forEach(function(e){window.removeEventListener(e,u,!1)})},f=e.disconnect.bind(e);return Object.assign(e,{disconnect:function(){d(),f()}}),v(),[v,d]},g=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 l(n,e),n.prototype.clickOutside=function(e){},n}(n.Controller),y={debug:!1,logger:console},w=function(e,n){var t,i,r,o,s,l=this;void 0===n&&(n={}),this.log=function(e,n){l.debug&&(l.logger.groupCollapsed("%c"+l.controller.identifier+" %c#"+e,"color: #3B82F6","color: unset"),l.logger.log(c({controllerId:l.controllerId},n)),l.logger.groupEnd())},this.debug=null!=(t=null!=(i=null==(r=n)?void 0:r.debug)?i:e.application.stimulusUseDebug)?t:y.debug,this.logger=null!=(o=null==(s=n)?void 0:s.logger)?o:y.logger,this.controller=e,this.controllerId=e.element.id||e.element.dataset.id,this.controllerInitialize=e.initialize.bind(e),this.controllerConnect=e.connect.bind(e),this.controllerDisconnect=e.disconnect.bind(e)},E=function(e){function n(n,t){var r,o,s,c,l;return void 0===t&&(t={}),(l=e.call(this,n,t)||this).dispatch=function(e,n){void 0===n&&(n={});var t=a(l),r=t.targetElement,o=t.eventPrefix,s=t.bubbles,c=t.cancelable,u=t.log;Object.assign(n,{controller:t.controller});var v=i(e,l.controller,o),d=new CustomEvent(v,{detail:n,bubbles:s,cancelable:c});return r.dispatchEvent(d),u("dispatch",{eventName:v,detail:n,bubbles:s,cancelable:c}),d},l.targetElement=null!=(r=t.element)?r:n.element,l.eventPrefix=null==(o=t.eventPrefix)||o,l.bubbles=null==(s=t.bubbles)||s,l.cancelable=null==(c=t.cancelable)||c,l.enhanceController(),l}return l(n,e),n.prototype.enhanceController=function(){Object.assign(this.controller,{dispatch:this.dispatch})},n}(w),O=function(e,n){return void 0===n&&(n={}),new E(e,n)},j=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")}}),O(e,n),Object.assign(e,{metaValue:function(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}})},C=function(e){function n(n){var t;return(t=e.call(this,n)||this).isPreview=!1,t.csrfToken="",j(a(t),t.options),t}return l(n,e),n}(n.Controller),P={ms:6e4,initialState:!1,events:["mousemove","mousedown","resize","keydown","touchstart","wheel"],dispatchEvent:!0,eventPrefix:!0},L=function(e,n){void 0===n&&(n={});var o=Object.assign({},P,n),s=o.ms,c=o.events,l=o.dispatchEvent,a=o.eventPrefix,u=o.initialState,v=setTimeout(function(){u=!0,d()},s),d=function(n){var o=i("away",e,a);if(e.isIdle=!0,e.away&&t(e,"away").call(e,n),l){var s=r(o,n||null,{controller:e});e.element.dispatchEvent(s)}},f=function(n){var o=i("back",e,a);if(e.isIdle=!1,e.back&&t(e,"back").call(e,n),l){var s=r(o,n||null,{controller:e});e.element.dispatchEvent(s)}},b=function(e){u&&f(e),u=!1,clearTimeout(v),v=setTimeout(function(){u=!0,d(e)},s)},h=function(e){document.hidden||b(e)};u?d():f();var m=e.disconnect.bind(e),p=function(){c.forEach(function(e){window.addEventListener(e,b)}),document.addEventListener("visibilitychange",h)},g=function(){c.forEach(function(e){window.removeEventListener(e,b)}),document.removeEventListener("visibilitychange",h)};return Object.assign(e,{disconnect:function(){g(),m()}}),p(),[p,g]},V=function(e){function n(n){var t;return(t=e.call(this,n)||this).isIdle=!1,requestAnimationFrame(function(){var e=L(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}l(n,e);var t=n.prototype;return t.away=function(){},t.back=function(){},n}(n.Controller),x={dispatchEvent:!0,eventPrefix:!0},T=function(e){function n(n,o){var s;void 0===o&&(o={}),(s=e.call(this,n,o)||this).observe=function(){s.controller.isVisible=!document.hidden,document.addEventListener("visibilitychange",s.handleVisibilityChange)},s.unobserve=function(){document.removeEventListener("visibilitychange",s.handleVisibilityChange)},s.becomesInvisible=function(e){var n=i("invisible",s.controller,s.eventPrefix);s.controller.isVisible=!1,s.controller.invisible&&t(s.controller,"invisible").call(s.controller,e),s.log("invisible",{isVisible:!1}),s.dispatch(n,e)},s.becomesVisible=function(e){var n=i("visible",s.controller,s.eventPrefix);s.controller.isVisible=!0,s.controller.visible&&t(s.controller,"visible").call(s.controller,e),s.log("visible",{isVisible:!0}),s.dispatch(n,e)},s.dispatch=function(e,n){if(s.dispatchEvent){var t={controller:s.controller,isVisible:s.controller.isVisible},i=r(e,n||null,t);s.controller.element.dispatchEvent(i),s.log("dispatchEvent",c({eventName:e},t))}},s.handleVisibilityChange=function(e){document.hidden?s.becomesInvisible(e):s.becomesVisible(e)};var l=Object.assign({},x,o),u=l.dispatchEvent,v=l.eventPrefix;return Object.assign(a(s),{dispatchEvent:u,eventPrefix:v}),s.controller=n,Object.assign(n,{disconnect:function(){s.unobserve(),s.controllerDisconnect()}}),s.handleVisibilityChange(),s.observe(),s}return l(n,e),n}(w),z=function(e,n){void 0===n&&(n={});var t=new T(e,n);return[t.observe,t.unobserve]},A=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=z(a(t),t.options),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n}(n.Controller),I=function(e){var n=function(n){var i=window,r={height:i.innerHeight||Infinity,width:i.innerWidth||Infinity,event:n};e.windowResize&&t(e,"windowResize").call(e,r)},i=e.disconnect.bind(e),r=function(){window.addEventListener("resize",n),n()},o=function(){window.removeEventListener("resize",n)};return Object.assign(e,{disconnect:function(){o(),i()}}),r(),[r,o]},k=function(e){function n(n){var t;return t=e.call(this,n)||this,requestAnimationFrame(function(){var e=I(a(t)),n=e[0],i=e[1];Object.assign(a(t),{observe:n,unobserve:i})}),t}return l(n,e),n.prototype.windowResize=function(e){},n}(n.Controller),q=function(e,n){void 0===n&&(n=200);var t=null;return function(){var i=arguments,r=this,o=function(){return e.apply(r,i)};clearTimeout(t),t=setTimeout(o,n)}};function F(e,n){var t;return void 0===n&&(n=200),function(){var i=arguments,r=this;t||(t=!0,e.apply(r,i),setTimeout(function(){return t=!1},n))}}function R(e){var n=document.head.querySelector('meta[name="'+e+'"]');return n&&n.getAttribute("content")}function S(e){try{return JSON.parse(e)}catch(n){return e}}function D(e){return e.replace(/(?:[_-])([a-z0-9])/g,function(e,n){return n.toUpperCase()})}var M={enterClass:"enter",enterActiveClass:"enterStart",enterToClass:"enterEnd",leaveClass:"leave",leaveActiveClass:"leaveStart",leaveToClass:"leaveEnd"},N={dispatchEvent:!0,eventPrefix:!0,transitioned:!1,hiddenClass:"hidden"},U=function(e,n){var t,i,r,o,s=function(e,n,t,i){try{var r,o;return(r=e.classList).add.apply(r,n),(o=e.classList).add.apply(o,t),Promise.resolve(function(){try{return Promise.resolve(new Promise(function(e){requestAnimationFrame(function(){requestAnimationFrame(e)})}))}catch(e){return Promise.reject(e)}}()).then(function(){var r,o;return(r=e.classList).remove.apply(r,t),(o=e.classList).add.apply(o,i),Promise.resolve(function(e){try{return Promise.resolve(new Promise(function(n){var t=1e3*Number(getComputedStyle(e).transitionDuration.split(",")[0].replace("s",""));setTimeout(function(){n(t)},t)}))}catch(e){return Promise.reject(e)}}(e)).then(function(){var t;(t=e.classList).remove.apply(t,n)})})}catch(e){return Promise.reject(e)}},c=function(t){try{if(!e.transitioned)return Promise.resolve();e.transitioned=!1,p&&p(t);var i=W("leave",n,d),r=W("leaveActive",n,d),o=W("leaveTo",n,d);return Promise.resolve(s(v,i,r,o)).then(function(){h&&v.classList.add(h)})}catch(e){return Promise.reject(e)}},l=function(t){try{if(e.transitioned)return Promise.resolve();e.transitioned=!0,m&&m(t);var i=W("enter",n,d),r=W("enterActive",n,d),o=W("enterTo",n,d);return h&&v.classList.remove(h),Promise.resolve(s(v,i,r,o)).then(function(){})}catch(e){return Promise.reject(e)}};void 0===n&&(n={});var a,u=e.element.dataset.transitionTarget;u&&(a=e[u+"Target"]);var v=(null==(t=n)?void 0:t.element)||a||e.element;if(v instanceof HTMLElement||v instanceof SVGElement){var d=v.dataset,f=Object.assign(N,n),b=f.transitioned,h=f.hiddenClass,m=null==(i=e.enter)?void 0:i.bind(e),p=null==(r=e.leave)?void 0:r.bind(e),g=null==(o=e.toggleTransition)?void 0:o.bind(e);return e.transitioned=b,b?(h&&v.classList.remove(h),l()):(h&&v.classList.add(h),c()),Object.assign(e,{enter:l,leave:c,toggleTransition:y}),[l,c,y]}function y(n){g&&g(n),e.transitioned?c():l()}};function W(e,n,t){var i="transition"+e[0].toUpperCase()+e.substr(1);return(n[e]||t[i]||t[M[e]]||"").split(" ")}var _=function(e){function n(n){var t;return(t=e.call(this,n)||this).transitioned=!1,requestAnimationFrame(function(){U(a(t),t.options)}),t}return l(n,e),n}(n.Controller);e.ApplicationController=C,e.ClickOutsideController=g,e.IdleController=V,e.IntersectionController=u,e.LazyLoadController=d,e.ResizeController=h,e.TransitionController=_,e.UseVisibility=T,e.VisibilityController=A,e.WindowResizeController=k,e.useApplication=j,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]=q(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=q(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useDispatch=O,e.useIdle=L,e.useIntersection=s,e.useLazyLoad=v,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?D(n)+"Meta":D(n);Object.defineProperty(e,i,{get:function(){return S(R(n))}})}(e,n,i)}),Object.defineProperty(e,"metas",{get:function(){var e={};return null==t||t.forEach(function(n){var t=S(R(n));null!=t&&(e[D(n)]=t)}),e}})},e.useResize=b,e.useThrottle=function(e,n){var t;null==(t=e.constructor.throttles)||t.forEach(function(t){if("string"==typeof t&&(e[t]=F(e[t],null==n?void 0:n.wait)),"object"==typeof t){var i=t.name;if(!i)return;e[i]=F(e[i],t.wait||(null==n?void 0:n.wait))}})},e.useTransition=U,e.useVisibility=z,e.useWindowResize=I}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -7,11 +7,12 @@ const defaultOptions = { | ||
constructor(controller, options = {}) { | ||
var _a, _b, _c; | ||
this.log = (functionName, args) => { | ||
if (!this.debug) | ||
return; | ||
this.logger.groupCollapsed(`%c${this.controller.identifier}#%c${functionName}`, 'color: #3B82F6', 'color: unset'); | ||
this.logger.groupCollapsed(`%c${this.controller.identifier} %c#${functionName}`, 'color: #3B82F6', 'color: unset'); | ||
this.logger.log(Object.assign({ controllerId: this.controllerId }, args)); | ||
this.logger.groupEnd(); | ||
}; | ||
this.debug = (options === null || options === void 0 ? void 0 : options.debug) || controller.application.stimulusUseDebug || defaultOptions.debug; | ||
this.logger = (options === null || options === void 0 ? void 0 : options.logger) || defaultOptions.logger; | ||
this.debug = (_b = (_a = options === null || options === void 0 ? void 0 : options.debug) !== null && _a !== void 0 ? _a : controller.application.stimulusUseDebug) !== null && _b !== void 0 ? _b : defaultOptions.debug; | ||
this.logger = (_c = options === null || options === void 0 ? void 0 : options.logger) !== null && _c !== void 0 ? _c : defaultOptions.logger; | ||
this.controller = controller; | ||
@@ -18,0 +19,0 @@ this.controllerId = controller.element.id || controller.element.dataset.id; |
{ | ||
"name": "stimulus-use", | ||
"version": "0.21.4", | ||
"version": "0.22.0-0", | ||
"description": "A collection of standard controllers and utilities for Stimulus", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.umd.js", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181468
169
1200