UNPKG

15.2 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("@material/snackbar",[],e):"object"==typeof exports?exports.snackbar=e():(t.mdc=t.mdc||{},t.mdc.snackbar=e())}(this,function(){return o={},i.m=n={0:function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.MDCFoundation=void 0;var o=(Object.defineProperty(i,"cssClasses",{get:function(){return{}},enumerable:!1,configurable:!0}),Object.defineProperty(i,"strings",{get:function(){return{}},enumerable:!1,configurable:!0}),Object.defineProperty(i,"numbers",{get:function(){return{}},enumerable:!1,configurable:!0}),Object.defineProperty(i,"defaultAdapter",{get:function(){return{}},enumerable:!1,configurable:!0}),i.prototype.init=function(){},i.prototype.destroy=function(){},i);function i(t){void 0===t&&(t={}),this.adapter=t}e.MDCFoundation=o,e.default=o},1:function(t,e,n){"use strict";var i=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,i,r=n.call(t),s=[];try{for(;(void 0===e||0<e--)&&!(o=r.next()).done;)s.push(o.value)}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s},r=this&&this.__spreadArray||function(t,e){for(var n=0,o=e.length,i=t.length;n<o;n++,i++)t[i]=e[n];return t};Object.defineProperty(e,"__esModule",{value:!0}),e.MDCComponent=void 0;var o=n(0),s=(a.attachTo=function(t){return new a(t,new o.MDCFoundation({}))},a.prototype.initialize=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e]},a.prototype.getDefaultFoundation=function(){throw new Error("Subclasses must override getDefaultFoundation to return a properly configured foundation class")},a.prototype.initialSyncWithDOM=function(){},a.prototype.destroy=function(){this.foundation.destroy()},a.prototype.listen=function(t,e,n){this.root.addEventListener(t,e,n)},a.prototype.unlisten=function(t,e,n){this.root.removeEventListener(t,e,n)},a.prototype.emit=function(t,e,n){var o;void 0===n&&(n=!1),"function"==typeof CustomEvent?o=new CustomEvent(t,{bubbles:n,detail:e}):(o=document.createEvent("CustomEvent")).initCustomEvent(t,n,!1,e),this.root.dispatchEvent(o)},a);function a(t,e){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];this.root=t,this.initialize.apply(this,r([],i(n))),this.foundation=void 0===e?this.getDefaultFoundation():e,this.foundation.init(),this.initialSyncWithDOM()}e.MDCComponent=s,e.default=s},117:function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.announce=void 0;var o=n(48),i=o.numbers.ARIA_LIVE_DELAY_MS,r=o.strings.ARIA_LIVE_LABEL_TEXT_ATTR;e.announce=function(t,e){void 0===e&&(e=t);var n=t.getAttribute("aria-live"),o=e.textContent.trim();o&&n&&(t.setAttribute("aria-live","off"),e.textContent="",e.innerHTML='<span style="display: inline-block; width: 0; height: 1px;">&nbsp;</span>',e.setAttribute(r,o),setTimeout(function(){t.setAttribute("aria-live",n),e.removeAttribute(r),e.textContent=o},i))}},118:function(t,e,n){"use strict";var o,i=this&&this.__extends||(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),r=this&&this.__assign||function(){return(r=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.MDCSnackbarFoundation=void 0;var s,a=n(0),u=n(48),c=u.cssClasses.OPENING,l=u.cssClasses.OPEN,f=u.cssClasses.CLOSING,p=u.strings.REASON_ACTION,d=u.strings.REASON_DISMISS,m=(s=a.MDCFoundation,i(h,s),Object.defineProperty(h,"cssClasses",{get:function(){return u.cssClasses},enumerable:!1,configurable:!0}),Object.defineProperty(h,"strings",{get:function(){return u.strings},enumerable:!1,configurable:!0}),Object.defineProperty(h,"numbers",{get:function(){return u.numbers},enumerable:!1,configurable:!0}),Object.defineProperty(h,"defaultAdapter",{get:function(){return{addClass:function(){},announce:function(){},notifyClosed:function(){},notifyClosing:function(){},notifyOpened:function(){},notifyOpening:function(){},removeClass:function(){}}},enumerable:!1,configurable:!0}),h.prototype.destroy=function(){this.clearAutoDismissTimer(),cancelAnimationFrame(this.animationFrame),this.animationFrame=0,clearTimeout(this.animationTimer),this.animationTimer=0,this.adapter.removeClass(c),this.adapter.removeClass(l),this.adapter.removeClass(f)},h.prototype.open=function(){var e=this;this.clearAutoDismissTimer(),this.opened=!0,this.adapter.notifyOpening(),this.adapter.removeClass(f),this.adapter.addClass(c),this.adapter.announce(),this.runNextAnimationFrame(function(){e.adapter.addClass(l),e.animationTimer=setTimeout(function(){var t=e.getTimeoutMs();e.handleAnimationTimerEnd(),e.adapter.notifyOpened(),t!==u.numbers.INDETERMINATE&&(e.autoDismissTimer=setTimeout(function(){e.close(d)},t))},u.numbers.SNACKBAR_ANIMATION_OPEN_TIME_MS)})},h.prototype.close=function(t){var e=this;void 0===t&&(t=""),this.opened&&(cancelAnimationFrame(this.animationFrame),this.animationFrame=0,this.clearAutoDismissTimer(),this.opened=!1,this.adapter.notifyClosing(t),this.adapter.addClass(u.cssClasses.CLOSING),this.adapter.removeClass(u.cssClasses.OPEN),this.adapter.removeClass(u.cssClasses.OPENING),clearTimeout(this.animationTimer),this.animationTimer=setTimeout(function(){e.handleAnimationTimerEnd(),e.adapter.notifyClosed(t)},u.numbers.SNACKBAR_ANIMATION_CLOSE_TIME_MS))},h.prototype.isOpen=function(){return this.opened},h.prototype.getTimeoutMs=function(){return this.autoDismissTimeoutMs},h.prototype.setTimeoutMs=function(t){var e=u.numbers.MIN_AUTO_DISMISS_TIMEOUT_MS,n=u.numbers.MAX_AUTO_DISMISS_TIMEOUT_MS,o=u.numbers.INDETERMINATE;if(!(t===u.numbers.INDETERMINATE||t<=n&&e<=t))throw new Error("\n timeoutMs must be an integer in the range "+e+"–"+n+"\n (or "+o+" to disable), but got '"+t+"'");this.autoDismissTimeoutMs=t},h.prototype.getCloseOnEscape=function(){return this.closeOnEscape},h.prototype.setCloseOnEscape=function(t){this.closeOnEscape=t},h.prototype.handleKeyDown=function(t){"Escape"!==t.key&&27!==t.keyCode||!this.getCloseOnEscape()||this.close(d)},h.prototype.handleActionButtonClick=function(t){this.close(p)},h.prototype.handleActionIconClick=function(t){this.close(d)},h.prototype.clearAutoDismissTimer=function(){clearTimeout(this.autoDismissTimer),this.autoDismissTimer=0},h.prototype.handleAnimationTimerEnd=function(){this.animationTimer=0,this.adapter.removeClass(u.cssClasses.OPENING),this.adapter.removeClass(u.cssClasses.CLOSING)},h.prototype.runNextAnimationFrame=function(t){var e=this;cancelAnimationFrame(this.animationFrame),this.animationFrame=requestAnimationFrame(function(){e.animationFrame=0,clearTimeout(e.animationTimer),e.animationTimer=setTimeout(t,0)})},h);function h(t){var e=s.call(this,r(r({},h.defaultAdapter),t))||this;return e.opened=!1,e.animationFrame=0,e.animationTimer=0,e.autoDismissTimer=0,e.autoDismissTimeoutMs=u.numbers.DEFAULT_AUTO_DISMISS_TIMEOUT_MS,e.closeOnEscape=!0,e}e.MDCSnackbarFoundation=m,e.default=m},2:function(t,e,n){"use strict";function o(t,e){return(t.matches||t.webkitMatchesSelector||t.msMatchesSelector).call(t,e)}Object.defineProperty(e,"__esModule",{value:!0}),e.estimateScrollWidth=e.matches=e.closest=void 0,e.closest=function(t,e){if(t.closest)return t.closest(e);for(var n=t;n;){if(o(n,e))return n;n=n.parentElement}return null},e.matches=o,e.estimateScrollWidth=function(t){var e=t;if(null!==e.offsetParent)return e.scrollWidth;var n=e.cloneNode(!0);n.style.setProperty("position","absolute"),n.style.setProperty("transform","translate(-9999px, -9999px)"),document.documentElement.appendChild(n);var o=n.scrollWidth;return document.documentElement.removeChild(n),o}},232:function(t,e,n){"use strict";var o=this&&this.__createBinding||(Object.create?function(t,e,n,o){void 0===o&&(o=n),Object.defineProperty(t,o,{enumerable:!0,get:function(){return e[n]}})}:function(t,e,n,o){void 0===o&&(o=n),t[o]=e[n]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),r=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&o(e,t,n);return i(e,t),e},s=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||o(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.util=void 0;var a=r(n(117));e.util=a,s(n(233),e),s(n(234),e),s(n(48),e),s(n(118),e),s(n(235),e)},233:function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0})},234:function(t,e,n){"use strict";var o,i=this&&this.__extends||(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),r=this&&this.__createBinding||(Object.create?function(t,e,n,o){void 0===o&&(o=n),Object.defineProperty(t,o,{enumerable:!0,get:function(){return e[n]}})}:function(t,e,n,o){void 0===o&&(o=n),t[o]=e[n]}),s=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),a=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return s(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.MDCSnackbar=void 0;var u,c=n(1),l=n(2),f=n(48),p=n(118),d=a(n(117)),m=f.strings.SURFACE_SELECTOR,h=f.strings.LABEL_SELECTOR,y=f.strings.ACTION_SELECTOR,_=f.strings.DISMISS_SELECTOR,b=f.strings.OPENING_EVENT,E=f.strings.OPENED_EVENT,O=f.strings.CLOSING_EVENT,C=f.strings.CLOSED_EVENT,v=(u=c.MDCComponent,i(T,u),T.attachTo=function(t){return new T(t)},T.prototype.initialize=function(t){void 0===t&&(t=function(){return d.announce}),this.announce=t()},T.prototype.initialSyncWithDOM=function(){var n=this;this.surfaceEl=this.root.querySelector(m),this.labelEl=this.root.querySelector(h),this.actionEl=this.root.querySelector(y),this.handleKeyDown=function(t){n.foundation.handleKeyDown(t)},this.handleSurfaceClick=function(t){var e=t.target;n.isActionButton(e)?n.foundation.handleActionButtonClick(t):n.isActionIcon(e)&&n.foundation.handleActionIconClick(t)},this.registerKeyDownHandler(this.handleKeyDown),this.registerSurfaceClickHandler(this.handleSurfaceClick)},T.prototype.destroy=function(){u.prototype.destroy.call(this),this.deregisterKeyDownHandler(this.handleKeyDown),this.deregisterSurfaceClickHandler(this.handleSurfaceClick)},T.prototype.open=function(){this.foundation.open()},T.prototype.close=function(t){void 0===t&&(t=""),this.foundation.close(t)},T.prototype.getDefaultFoundation=function(){var e=this,t={addClass:function(t){e.root.classList.add(t)},announce:function(){e.announce(e.labelEl)},notifyClosed:function(t){return e.emit(C,t?{reason:t}:{})},notifyClosing:function(t){return e.emit(O,t?{reason:t}:{})},notifyOpened:function(){return e.emit(E,{})},notifyOpening:function(){return e.emit(b,{})},removeClass:function(t){return e.root.classList.remove(t)}};return new p.MDCSnackbarFoundation(t)},Object.defineProperty(T.prototype,"timeoutMs",{get:function(){return this.foundation.getTimeoutMs()},set:function(t){this.foundation.setTimeoutMs(t)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"closeOnEscape",{get:function(){return this.foundation.getCloseOnEscape()},set:function(t){this.foundation.setCloseOnEscape(t)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"isOpen",{get:function(){return this.foundation.isOpen()},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"labelText",{get:function(){return this.labelEl.textContent},set:function(t){this.labelEl.textContent=t},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"actionButtonText",{get:function(){return this.actionEl.textContent},set:function(t){this.actionEl.textContent=t},enumerable:!1,configurable:!0}),T.prototype.registerKeyDownHandler=function(t){this.listen("keydown",t)},T.prototype.deregisterKeyDownHandler=function(t){this.unlisten("keydown",t)},T.prototype.registerSurfaceClickHandler=function(t){this.surfaceEl.addEventListener("click",t)},T.prototype.deregisterSurfaceClickHandler=function(t){this.surfaceEl.removeEventListener("click",t)},T.prototype.isActionButton=function(t){return Boolean(l.closest(t,y))},T.prototype.isActionIcon=function(t){return Boolean(l.closest(t,_))},T);function T(){return null!==u&&u.apply(this,arguments)||this}e.MDCSnackbar=v},235:function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0})},48:function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.numbers=e.strings=e.cssClasses=void 0;e.cssClasses={CLOSING:"mdc-snackbar--closing",OPEN:"mdc-snackbar--open",OPENING:"mdc-snackbar--opening"};e.strings={ACTION_SELECTOR:".mdc-snackbar__action",ARIA_LIVE_LABEL_TEXT_ATTR:"data-mdc-snackbar-label-text",CLOSED_EVENT:"MDCSnackbar:closed",CLOSING_EVENT:"MDCSnackbar:closing",DISMISS_SELECTOR:".mdc-snackbar__dismiss",LABEL_SELECTOR:".mdc-snackbar__label",OPENED_EVENT:"MDCSnackbar:opened",OPENING_EVENT:"MDCSnackbar:opening",REASON_ACTION:"action",REASON_DISMISS:"dismiss",SURFACE_SELECTOR:".mdc-snackbar__surface"};e.numbers={DEFAULT_AUTO_DISMISS_TIMEOUT_MS:5e3,INDETERMINATE:-1,MAX_AUTO_DISMISS_TIMEOUT_MS:1e4,MIN_AUTO_DISMISS_TIMEOUT_MS:4e3,SNACKBAR_ANIMATION_CLOSE_TIME_MS:75,SNACKBAR_ANIMATION_OPEN_TIME_MS:150,ARIA_LIVE_DELAY_MS:1e3}}},i.c=o,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)i.d(n,o,function(t){return e[t]}.bind(null,o));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=232);function i(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,i),e.l=!0,e.exports}var n,o});
\No newline at end of file