diff --git a/dist/angular-sidebarjs.css b/dist/angular-sidebarjs.css index d35aad8..3f71329 100644 --- a/dist/angular-sidebarjs.css +++ b/dist/angular-sidebarjs.css @@ -1,76 +1,130 @@ -[sidebarjs-backdrop], [sidebarjs] { - top: 0; - left: 0; - width: 100%; - height: 100%; } +[sidebarjs-backdrop], +[sidebarjs] { + top: 0; + left: 0; + width: 100%; + height: 100%; +} -[sidebarjs].sidebarjs--left, [sidebarjs].sidebarjs--left [sidebarjs-container] { - -webkit-transform: translate(-100%, 0); - transform: translate(-100%, 0); } +.sidebarjs--left[sidebarjs], +[sidebarjs].sidebarjs--left [sidebarjs-container] { + transform: translate(-100%, 0); +} -[sidebarjs].sidebarjs--right, [sidebarjs].sidebarjs--right [sidebarjs-container] { - -webkit-transform: translate(100%, 0); - transform: translate(100%, 0); } +.sidebarjs--right[sidebarjs], +[sidebarjs].sidebarjs--right [sidebarjs-container] { + transform: translate(100%, 0); +} [sidebarjs].sidebarjs--left [sidebarjs-container] { - -webkit-box-shadow: 2px 0 4px rgba(0, 0, 0, 0.2); - box-shadow: 2px 0 4px rgba(0, 0, 0, 0.2); } + box-shadow: 2px 0 4px rgba(0, 0, 0, 0.2); +} [sidebarjs].sidebarjs--right [sidebarjs-container] { - -webkit-box-shadow: -2px 0 4px rgba(0, 0, 0, 0.2); - box-shadow: -2px 0 4px rgba(0, 0, 0, 0.2); - margin-left: auto; } + box-shadow: -2px 0 4px rgba(0, 0, 0, 0.2); + margin-left: auto; +} [sidebarjs-backdrop] { - position: absolute; - background: #000; - opacity: 0; - -webkit-transition: opacity 0.3s ease; - transition: opacity 0.3s ease; - will-change: opacity; } + position: absolute; + background: #000; + opacity: 0; + transition: opacity 0.3s ease; + will-change: opacity; +} [sidebarjs-container] { - position: relative; - z-index: 1; - display: -webkit-box; - display: -ms-flexbox; - display: flex; - -webkit-box-orient: vertical; - -webkit-box-direction: normal; - -ms-flex-direction: column; - flex-direction: column; - width: 90%; - max-width: 300px; - height: 100%; - background: #fff; - -webkit-transition: -webkit-transform ease 0.3s; - transition: -webkit-transform ease 0.3s; - transition: transform ease 0.3s; - transition: transform ease 0.3s, -webkit-transform ease 0.3s; - will-change: transform; } + position: relative; + z-index: 1; + display: flex; + flex-direction: column; + width: 90%; + max-width: 300px; + height: 100%; + background: #fff; + transition: transform ease 0.3s; + will-change: transform; +} [sidebarjs] { - position: fixed; - z-index: 9999; - -webkit-transition: -webkit-transform 0s ease 0.3s; - transition: -webkit-transform 0s ease 0.3s; - transition: transform 0s ease 0.3s; - transition: transform 0s ease 0.3s, -webkit-transform 0s ease 0.3s; } - [sidebarjs].sidebarjs--is-visible { - -webkit-transform: translate(0, 0); - transform: translate(0, 0); - -webkit-transition: -webkit-transform 0s ease 0s; - transition: -webkit-transform 0s ease 0s; + position: fixed; + z-index: 9999; + transition: transform 0s ease 0.3s; +} + +[sidebarjs].sidebarjs--is-visible { + transform: translate(0, 0); transition: transform 0s ease 0s; - transition: transform 0s ease 0s, -webkit-transform 0s ease 0s; } - [sidebarjs].sidebarjs--is-visible [sidebarjs-container] { - -webkit-transform: translate(0, 0); - transform: translate(0, 0); } - [sidebarjs].sidebarjs--is-moving { - -webkit-transition: none; +} + +[sidebarjs].sidebarjs--is-visible [sidebarjs-container] { + transform: translate(0, 0); +} + +[sidebarjs].sidebarjs--is-moving { transition: none; - -webkit-transform: translate(0, 0); - transform: translate(0, 0); } - [sidebarjs].sidebarjs--is-moving [sidebarjs-container], [sidebarjs].sidebarjs--is-moving [sidebarjs-backdrop] { - -webkit-transition: none; - transition: none; } + transform: translate(0, 0); +} + +[sidebarjs].sidebarjs--is-moving [sidebarjs-container] { + transform: none !important; +} + +[sidebarjs].sidebarjs--is-moving [sidebarjs-container], +[sidebarjs].sidebarjs--is-moving [sidebarjs-backdrop] { + transition: none; +} + +[sidebarjs-content] { + position: relative; + width: 100%; + min-height: 100%; + transition: width 0.3s ease; +} + +[sidebarjs-content].sidebarjs-content--left { + margin-left: auto; + margin-right: 0; +} + +[sidebarjs-content].sidebarjs-content--right { + margin-left: 0; + margin-right: auto; +} + +@media (min-width: 1025px) { + [sidebarjs].sidebarjs--responsive { + transform: translate(0, 0) !important; + transition: transform 0s ease 0s; + width: 300px; + } + [sidebarjs].sidebarjs--responsive [sidebarjs-container] { + transform: translate(0, 0) !important; + } + [sidebarjs].sidebarjs--responsive.sidebarjs--left { + left: 0; + right: auto; + } + [sidebarjs].sidebarjs--responsive.sidebarjs--left [sidebarjs-container] { + box-shadow: 1px 0 0 rgba(0, 0, 0, 0.1); + } + [sidebarjs].sidebarjs--responsive.sidebarjs--right { + right: 0; + left: auto; + } + [sidebarjs].sidebarjs--responsive.sidebarjs--right [sidebarjs-container] { + box-shadow: -1px 0 0 rgba(0, 0, 0, 0.1); + } + [sidebarjs].sidebarjs--responsive [sidebarjs-container] { + max-width: none; + width: 100%; + box-shadow: none; + } + [sidebarjs-content] { + width: calc(100% - 300px); + } + [sidebarjs-content].sidebarjs-content--left.sidebarjs-content--right { + width: calc(100% - 600px); + margin: 0 auto; + } +} \ No newline at end of file diff --git a/dist/angular-sidebarjs.js b/dist/angular-sidebarjs.js index 837c0a7..059bcb1 100644 --- a/dist/angular-sidebarjs.js +++ b/dist/angular-sidebarjs.js @@ -174,7 +174,7 @@ module.exports = __webpack_require__(2); /* * SidebarJS - * Version 5.1.0 + * Version 5.4.0 * https://github.com/SidebarJS/sidebarjs#readme */ @@ -184,343 +184,405 @@ module.exports = __webpack_require__(2); (factory((global.SidebarJS = {}))); }(this, (function (exports) { 'use strict'; -function unwrapExports (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; -} - -function createCommonjsModule(fn, module) { - return module = { exports: {} }, fn(module, module.exports), module.exports; -} - -var sidebarElement = createCommonjsModule(function (module, exports) { -Object.defineProperty(exports, "__esModule", { value: true }); -var SIDEBARJS = 'sidebarjs'; -var IS_VISIBLE = SIDEBARJS + "--is-visible"; -var IS_MOVING = SIDEBARJS + "--is-moving"; -var LEFT_POSITION = 'left'; -var RIGHT_POSITION = 'right'; -var POSITIONS = [LEFT_POSITION, RIGHT_POSITION]; -var SidebarElement = /** @class */ (function () { - function SidebarElement(config) { - if (config === void 0) { config = {}; } - var _this = this; - this.toggle = function () { - _this.isVisible() ? _this.close() : _this.open(); - }; - this.open = function () { - _this.component.classList.add(IS_VISIBLE); - _this.setBackdropOpacity(_this.backdropOpacity); - }; - this.close = function () { - _this.component.classList.remove(IS_VISIBLE); - _this.backdrop.removeAttribute('style'); - }; - this.__onTouchStart = function (e) { - _this.initialTouch = e.touches[0].pageX; - }; - this.__onTouchMove = function (e) { - var documentSwiped = Math.abs(_this.initialTouch - e.touches[0].clientX); - var sidebarMovement = _this.container.clientWidth - documentSwiped; - if (sidebarMovement <= _this.container.clientWidth) { - _this.touchMoveSidebar = documentSwiped; - _this.moveSidebar(_this.hasLeftPosition() ? -documentSwiped : documentSwiped); - } - }; - this.__onTouchEnd = function () { - _this.component.classList.remove(IS_MOVING); - _this.container.removeAttribute('style'); - _this.backdrop.removeAttribute('style'); - _this.touchMoveSidebar > (_this.container.clientWidth / 3.5) ? _this.close() : _this.open(); - _this.initialTouch = null; - _this.touchMoveSidebar = null; - }; - this.__onSwipeOpenStart = function (e) { - if (_this.targetElementIsBackdrop(e)) { - return; - } - var touchPositionX = e.touches[0].clientX; - var documentTouch = _this.hasLeftPosition() ? touchPositionX : document.body.clientWidth - touchPositionX; - if (documentTouch < _this.documentSwipeRange) { - _this.__onTouchStart(e); - } - }; - this.__onSwipeOpenMove = function (e) { - if (!_this.targetElementIsBackdrop(e) && _this.initialTouch && !_this.isVisible()) { - var documentSwiped = e.touches[0].clientX - _this.initialTouch; - var hasLeftPosition = _this.hasLeftPosition(); - var swipeX = hasLeftPosition ? documentSwiped : -documentSwiped; - var sidebarMovement = _this.container.clientWidth - swipeX; - if (sidebarMovement > 0 && swipeX >= _this.documentMinSwipeX) { - _this.openMovement = hasLeftPosition ? -sidebarMovement : sidebarMovement; - _this.moveSidebar(_this.openMovement); - } - } - }; - this.__onSwipeOpenEnd = function () { - if (_this.openMovement) { - _this.openMovement = null; - _this.__onTouchEnd(); - } - }; - this.__onTransitionEnd = function () { - var isVisible = _this.isVisible(); - if (isVisible && !_this.__wasVisible) { - _this.__wasVisible = true; - if (_this.__emitOnOpen) { - _this.__emitOnOpen(); - } - } - else if (!isVisible && _this.__wasVisible) { - _this.__wasVisible = false; - if (_this.__emitOnClose) { - _this.__emitOnClose(); - } - } - if (_this.__emitOnChangeVisibility) { - _this.__emitOnChangeVisibility({ isVisible: isVisible }); - } - }; - var component = config.component, container = config.container, backdrop = config.backdrop, _a = config.documentMinSwipeX, documentMinSwipeX = _a === void 0 ? 10 : _a, _b = config.documentSwipeRange, documentSwipeRange = _b === void 0 ? 40 : _b, nativeSwipe = config.nativeSwipe, nativeSwipeOpen = config.nativeSwipeOpen, _c = config.position, position = _c === void 0 ? 'left' : _c, _d = config.backdropOpacity, backdropOpacity = _d === void 0 ? 0.3 : _d, onOpen = config.onOpen, onClose = config.onClose, onChangeVisibility = config.onChangeVisibility; - var hasCustomTransclude = container && backdrop; - this.component = component || document.querySelector("[" + SIDEBARJS + "]"); - this.container = hasCustomTransclude ? container : SidebarElement.create(SIDEBARJS + "-container"); - this.backdrop = hasCustomTransclude ? backdrop : SidebarElement.create(SIDEBARJS + "-backdrop"); - this.documentMinSwipeX = documentMinSwipeX; - this.documentSwipeRange = documentSwipeRange; - this.nativeSwipe = nativeSwipe !== false; - this.nativeSwipeOpen = nativeSwipeOpen !== false; - this.backdropOpacity = backdropOpacity; - this.backdropOpacityRatio = 1 / backdropOpacity; - this.__emitOnOpen = onOpen; - this.__emitOnClose = onClose; - this.__emitOnChangeVisibility = onChangeVisibility; - if (!hasCustomTransclude) { - try { - this.transcludeContent(); - } - catch (e) { - throw new Error('You must define an element with [sidebarjs] attribute'); - } - } - if (this.nativeSwipe) { - this.addNativeGestures(); - if (this.nativeSwipeOpen) { - this.addNativeOpenGestures(); - } - } - this.setPosition(position); - this.addAttrsEventsListeners(this.component.getAttribute(SIDEBARJS)); - this.addTransitionListener(); - this.backdrop.addEventListener('click', this.close, { passive: true }); - } - SidebarElement.prototype.isVisible = function () { - return this.component.classList.contains(IS_VISIBLE); - }; - SidebarElement.prototype.destroy = function () { - var _this = this; - this.component.removeEventListener('touchstart', this.__onTouchStart, { passive: true }); - this.component.removeEventListener('touchmove', this.__onTouchMove, { passive: true }); - this.component.removeEventListener('touchend', this.__onTouchEnd, { passive: true }); - this.container.removeEventListener('transitionend', this.__onTransitionEnd, { passive: true }); - this.backdrop.removeEventListener('click', this.close, { passive: true }); - document.removeEventListener('touchstart', this.__onSwipeOpenStart, { passive: true }); - document.removeEventListener('touchmove', this.__onSwipeOpenMove, { passive: true }); - document.removeEventListener('touchend', this.__onSwipeOpenEnd, { passive: true }); - this.removeAttrsEventsListeners(this.component.getAttribute(SIDEBARJS)); - this.removeComponentClassPosition(); - while (this.container.firstElementChild) { - this.component.appendChild(this.container.firstElementChild); - } - this.component.removeChild(this.container); - this.component.removeChild(this.backdrop); - Object.keys(this).forEach(function (key) { return _this[key] = null; }); - }; - SidebarElement.prototype.setPosition = function (position) { - var _this = this; - this.component.classList.add(IS_MOVING); - this.position = POSITIONS.indexOf(position) >= 0 ? position : LEFT_POSITION; - this.removeComponentClassPosition(); - this.component.classList.add(SIDEBARJS + "--" + (this.hasRightPosition() ? RIGHT_POSITION : LEFT_POSITION)); - setTimeout(function () { return _this.component && _this.component.classList.remove(IS_MOVING); }, 200); - }; - SidebarElement.prototype.addAttrsEventsListeners = function (sidebarName) { - var _this = this; - this.forEachActionElement(sidebarName, function (element, action) { - if (!SidebarElement.elemHasListener(element)) { - element.addEventListener('click', _this[action], { passive: true }); - SidebarElement.elemHasListener(element, true); - } - }); - }; - SidebarElement.prototype.removeAttrsEventsListeners = function (sidebarName) { - var _this = this; - this.forEachActionElement(sidebarName, function (element, action) { - if (SidebarElement.elemHasListener(element)) { - element.removeEventListener('click', _this[action]); - SidebarElement.elemHasListener(element, false); - } - }); - }; - SidebarElement.prototype.addTransitionListener = function () { - this.__wasVisible = this.isVisible(); - this.container.addEventListener('transitionend', this.__onTransitionEnd, { passive: true }); - }; - SidebarElement.prototype.forEachActionElement = function (sidebarName, func) { - var actions = ['toggle', 'open', 'close']; - for (var i = 0; i < actions.length; i++) { - var elements = document.querySelectorAll("[" + SIDEBARJS + "-" + actions[i] + "=\"" + sidebarName + "\"]"); - for (var j = 0; j < elements.length; j++) { - func(elements[j], actions[i]); - } - } - }; - SidebarElement.prototype.removeComponentClassPosition = function () { - for (var i = 0; i < POSITIONS.length; i++) { - this.component.classList.remove(SIDEBARJS + "--" + POSITIONS[i]); - } - }; - SidebarElement.prototype.hasLeftPosition = function () { - return this.position === LEFT_POSITION; - }; - SidebarElement.prototype.hasRightPosition = function () { - return this.position === RIGHT_POSITION; - }; - SidebarElement.prototype.transcludeContent = function () { - while (this.component.firstChild) { - this.container.appendChild(this.component.firstChild); - } - while (this.component.firstChild) { - this.component.removeChild(this.component.firstChild); - } - this.component.appendChild(this.container); - this.component.appendChild(this.backdrop); - }; - SidebarElement.prototype.addNativeGestures = function () { - this.component.addEventListener('touchstart', this.__onTouchStart, { passive: true }); - this.component.addEventListener('touchmove', this.__onTouchMove, { passive: true }); - this.component.addEventListener('touchend', this.__onTouchEnd, { passive: true }); - }; - SidebarElement.prototype.addNativeOpenGestures = function () { - document.addEventListener('touchstart', this.__onSwipeOpenStart, { passive: true }); - document.addEventListener('touchmove', this.__onSwipeOpenMove, { passive: true }); - document.addEventListener('touchend', this.__onSwipeOpenEnd, { passive: true }); - }; - SidebarElement.prototype.moveSidebar = function (movement) { - this.component.classList.add(IS_MOVING); - SidebarElement.vendorify(this.container, 'transform', "translate(" + movement + "px, 0)"); - this.updateBackdropOpacity(movement); - }; - SidebarElement.prototype.updateBackdropOpacity = function (movement) { - var swipeProgress = 1 - (Math.abs(movement) / this.container.clientWidth); - var opacity = swipeProgress / this.backdropOpacityRatio; - this.setBackdropOpacity(opacity); - }; - SidebarElement.prototype.setBackdropOpacity = function (opacity) { - this.backdrop.style.opacity = opacity.toString(); - }; - SidebarElement.prototype.targetElementIsBackdrop = function (e) { - return e.target.hasAttribute(SIDEBARJS + "-backdrop"); - }; - SidebarElement.create = function (element) { - var el = document.createElement('div'); - el.setAttribute(element, ''); - return el; - }; - SidebarElement.vendorify = function (el, prop, val) { - el.style['Webkit' + prop.charAt(0).toUpperCase() + prop.slice(1)] = val; - el.style[prop] = val; - }; - SidebarElement.elemHasListener = function (elem, value) { - return elem && typeof value === 'boolean' ? elem.sidebarjsListener = value : !!elem.sidebarjsListener; - }; - return SidebarElement; -}()); -exports.SidebarElement = SidebarElement; - -}); - -unwrapExports(sidebarElement); -var sidebarElement_1 = sidebarElement.SidebarElement; - -var sidebarService = createCommonjsModule(function (module, exports) { -Object.defineProperty(exports, "__esModule", { value: true }); - -var SidebarService = /** @class */ (function () { - function SidebarService() { - this.instances = {}; - } - SidebarService.prototype.create = function (options) { - if (options === void 0) { options = {}; } - var name = options.component && options.component.getAttribute('sidebarjs') || ''; - this.instances[name] = new sidebarElement.SidebarElement(options); - return this.instances[name]; - }; - SidebarService.prototype.open = function (sidebarName) { - if (sidebarName === void 0) { sidebarName = ''; } - if (this.instances[sidebarName]) { - this.instances[sidebarName].open(); - } - }; - SidebarService.prototype.close = function (sidebarName) { - if (sidebarName === void 0) { sidebarName = ''; } - if (this.instances[sidebarName]) { - this.instances[sidebarName].close(); - } - }; - SidebarService.prototype.toggle = function (sidebarName) { - if (sidebarName === void 0) { sidebarName = ''; } - if (this.instances[sidebarName]) { - this.instances[sidebarName].toggle(); - } - }; - SidebarService.prototype.isVisible = function (sidebarName) { - if (sidebarName === void 0) { sidebarName = ''; } - return !!this.instances[sidebarName] && this.instances[sidebarName].isVisible(); - }; - SidebarService.prototype.setPosition = function (position, sidebarName) { - if (sidebarName === void 0) { sidebarName = ''; } - if (this.instances[sidebarName]) { - this.instances[sidebarName].setPosition(position); - } - }; - SidebarService.prototype.elemHasListener = function (elem, value) { - return sidebarElement.SidebarElement.elemHasListener(elem, value); - }; - SidebarService.prototype.destroy = function (sidebarName) { - if (sidebarName === void 0) { sidebarName = ''; } - if (this.instances[sidebarName]) { - this.instances[sidebarName].destroy(); - this.instances[sidebarName] = null; - delete this.instances[sidebarName]; - } - }; - return SidebarService; -}()); -exports.SidebarService = SidebarService; - -}); - -unwrapExports(sidebarService); -var sidebarService_1 = sidebarService.SidebarService; - -var src = createCommonjsModule(function (module, exports) { -Object.defineProperty(exports, "__esModule", { value: true }); - -exports.SidebarElement = sidebarElement.SidebarElement; - -exports.SidebarService = sidebarService.SidebarService; - -}); - -var index = unwrapExports(src); -var src_1 = src.SidebarElement; -var src_2 = src.SidebarService; - -exports.default = index; -exports.SidebarElement = src_1; -exports.SidebarService = src_2; - -Object.defineProperty(exports, '__esModule', { value: true }); + function unwrapExports (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x; + } + + function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; + } + + var sidebarElement = createCommonjsModule(function (module, exports) { + Object.defineProperty(exports, "__esModule", { value: true }); + var SIDEBARJS = 'sidebarjs'; + var SIDEBARJS_CONTENT = 'sidebarjs-content'; + var IS_VISIBLE = SIDEBARJS + "--is-visible"; + var IS_MOVING = SIDEBARJS + "--is-moving"; + var LEFT_POSITION = 'left'; + var RIGHT_POSITION = 'right'; + var POSITIONS = [LEFT_POSITION, RIGHT_POSITION]; + var SidebarElement = /** @class */ (function () { + function SidebarElement(config) { + if (config === void 0) { config = {}; } + var _this = this; + this.toggle = function () { + _this.isVisible() ? _this.close() : _this.open(); + }; + this.open = function () { + _this.component.classList.add(IS_VISIBLE); + _this.setBackdropOpacity(_this.backdropOpacity); + }; + this.close = function () { + _this.component.classList.remove(IS_VISIBLE); + _this.clearStyle(_this.backdrop); + }; + this.__onTouchStart = function (e) { + _this.initialTouch = e.touches[0].pageX; + }; + this.__onTouchMove = function (e) { + var swipeDirection = -(_this.initialTouch - e.touches[0].clientX); + var sidebarMovement = _this.container.clientWidth + (_this.hasLeftPosition() ? swipeDirection : -swipeDirection); + if (sidebarMovement <= _this.container.clientWidth) { + _this.touchMoveSidebar = Math.abs(swipeDirection); + _this.moveSidebar(swipeDirection); + } + }; + this.__onTouchEnd = function () { + _this.component.classList.remove(IS_MOVING); + _this.clearStyle(_this.container); + _this.clearStyle(_this.backdrop); + _this.touchMoveSidebar > (_this.container.clientWidth / 3.5) ? _this.close() : _this.open(); + _this.initialTouch = null; + _this.touchMoveSidebar = null; + }; + this.__onSwipeOpenStart = function (e) { + if (_this.targetElementIsBackdrop(e)) { + return; + } + var touchPositionX = e.touches[0].clientX; + var documentTouch = _this.hasLeftPosition() ? touchPositionX : document.body.clientWidth - touchPositionX; + if (documentTouch < _this.documentSwipeRange) { + _this.__onTouchStart(e); + } + }; + this.__onSwipeOpenMove = function (e) { + if (!_this.targetElementIsBackdrop(e) && _this.initialTouch && !_this.isVisible()) { + var documentSwiped = e.touches[0].clientX - _this.initialTouch; + var hasLeftPosition = _this.hasLeftPosition(); + var swipeX = hasLeftPosition ? documentSwiped : -documentSwiped; + var sidebarMovement = _this.container.clientWidth - swipeX; + if (sidebarMovement > 0 && swipeX >= _this.documentMinSwipeX) { + _this.openMovement = hasLeftPosition ? -sidebarMovement : sidebarMovement; + _this.moveSidebar(_this.openMovement); + } + } + }; + this.__onSwipeOpenEnd = function () { + if (_this.openMovement) { + _this.openMovement = null; + _this.__onTouchEnd(); + } + }; + this.__onTransitionEnd = function () { + var isVisible = _this.isVisible(); + if (isVisible && !_this.__wasVisible) { + _this.__wasVisible = true; + if (_this.__emitOnOpen) { + _this.__emitOnOpen(); + } + } + else if (!isVisible && _this.__wasVisible) { + _this.__wasVisible = false; + if (_this.__emitOnClose) { + _this.__emitOnClose(); + } + } + if (_this.__emitOnChangeVisibility) { + _this.__emitOnChangeVisibility({ isVisible: isVisible }); + } + }; + var component = config.component, container = config.container, backdrop = config.backdrop, _a = config.documentMinSwipeX, documentMinSwipeX = _a === void 0 ? 10 : _a, _b = config.documentSwipeRange, documentSwipeRange = _b === void 0 ? 40 : _b, nativeSwipe = config.nativeSwipe, nativeSwipeOpen = config.nativeSwipeOpen, _c = config.responsive, responsive = _c === void 0 ? false : _c, mainContent = config.mainContent, _d = config.position, position = _d === void 0 ? 'left' : _d, _e = config.backdropOpacity, backdropOpacity = _e === void 0 ? 0.3 : _e, onOpen = config.onOpen, onClose = config.onClose, onChangeVisibility = config.onChangeVisibility; + var hasCustomTransclude = container && backdrop; + this.component = component || document.querySelector("[" + SIDEBARJS + "]"); + this.container = hasCustomTransclude ? container : SidebarElement.create(SIDEBARJS + "-container"); + this.backdrop = hasCustomTransclude ? backdrop : SidebarElement.create(SIDEBARJS + "-backdrop"); + this.documentMinSwipeX = documentMinSwipeX; + this.documentSwipeRange = documentSwipeRange; + this.nativeSwipe = nativeSwipe !== false; + this.nativeSwipeOpen = nativeSwipeOpen !== false; + this.isStyleMapSupported = SidebarElement.isStyleMapSupported(); + this.responsive = Boolean(responsive); + this.mainContent = this.shouldDefineMainContent(mainContent); + this.backdropOpacity = backdropOpacity; + this.backdropOpacityRatio = 1 / backdropOpacity; + this.__emitOnOpen = onOpen; + this.__emitOnClose = onClose; + this.__emitOnChangeVisibility = onChangeVisibility; + if (!hasCustomTransclude) { + try { + this.transcludeContent(); + } + catch (e) { + throw new Error('You must define an element with [sidebarjs] attribute'); + } + } + this.setSwipeGestures(true); + if (this.responsive || this.mainContent) { + this.setResponsive(); + } + this.setPosition(position); + this.addAttrsEventsListeners(this.component.getAttribute(SIDEBARJS)); + this.addTransitionListener(); + this.backdrop.addEventListener('click', this.close, { passive: true }); + } + SidebarElement.prototype.isVisible = function () { + return this.component.classList.contains(IS_VISIBLE); + }; + SidebarElement.prototype.destroy = function () { + var _this = this; + this.removeNativeGestures(); + this.container.removeEventListener('transitionend', this.__onTransitionEnd, { passive: true }); + this.backdrop.removeEventListener('click', this.close, { passive: true }); + this.removeNativeOpenGestures(); + this.removeAttrsEventsListeners(this.component.getAttribute(SIDEBARJS)); + this.removeComponentClassPosition(); + while (this.container.firstElementChild) { + this.component.appendChild(this.container.firstElementChild); + } + this.component.removeChild(this.container); + this.component.removeChild(this.backdrop); + Object.keys(this).forEach(function (key) { return _this[key] = null; }); + }; + SidebarElement.prototype.setPosition = function (position) { + var _this = this; + this.component.classList.add(IS_MOVING); + this.position = POSITIONS.indexOf(position) >= 0 ? position : LEFT_POSITION; + var resetMainContent = (document.querySelectorAll("[" + SIDEBARJS + "]") || []).length === 1; + this.removeComponentClassPosition(resetMainContent); + this.component.classList.add(SIDEBARJS + "--" + this.position); + if (this.responsive && this.mainContent) { + this.mainContent.classList.add(SIDEBARJS_CONTENT + "--" + this.position); + } + setTimeout(function () { return _this.component && _this.component.classList.remove(IS_MOVING); }, 200); + }; + SidebarElement.prototype.addAttrsEventsListeners = function (sidebarName) { + var _this = this; + this.forEachActionElement(sidebarName, function (element, action) { + if (!SidebarElement.elemHasListener(element)) { + element.addEventListener('click', _this[action], { passive: true }); + SidebarElement.elemHasListener(element, true); + } + }); + }; + SidebarElement.prototype.removeAttrsEventsListeners = function (sidebarName) { + var _this = this; + this.forEachActionElement(sidebarName, function (element, action) { + if (SidebarElement.elemHasListener(element)) { + element.removeEventListener('click', _this[action]); + SidebarElement.elemHasListener(element, false); + } + }); + }; + SidebarElement.prototype.setSwipeGestures = function (value) { + if (typeof value !== 'boolean') { + throw new Error("You provided a " + typeof value + " value but setSwipeGestures needs a boolean value."); + } + if (this.nativeSwipe) { + value ? this.addNativeGestures() : this.removeNativeGestures(); + if (this.nativeSwipeOpen) { + value ? this.addNativeOpenGestures() : this.removeNativeOpenGestures(); + } + } + }; + SidebarElement.prototype.addTransitionListener = function () { + this.__wasVisible = this.isVisible(); + this.container.addEventListener('transitionend', this.__onTransitionEnd, { passive: true }); + }; + SidebarElement.prototype.forEachActionElement = function (sidebarName, func) { + var actions = ['toggle', 'open', 'close']; + for (var i = 0; i < actions.length; i++) { + var elements = document.querySelectorAll("[" + SIDEBARJS + "-" + actions[i] + "=\"" + sidebarName + "\"]"); + for (var j = 0; j < elements.length; j++) { + func(elements[j], actions[i]); + } + } + }; + SidebarElement.prototype.removeComponentClassPosition = function (resetMainContent) { + for (var i = 0; i < POSITIONS.length; i++) { + this.component.classList.remove(SIDEBARJS + "--" + POSITIONS[i]); + if (resetMainContent && this.mainContent) { + this.mainContent.classList.remove(SIDEBARJS_CONTENT + "--" + POSITIONS[i]); + } + } + }; + SidebarElement.prototype.hasLeftPosition = function () { + return this.position === LEFT_POSITION; + }; + SidebarElement.prototype.hasRightPosition = function () { + return this.position === RIGHT_POSITION; + }; + SidebarElement.prototype.transcludeContent = function () { + while (this.component.firstChild) { + this.container.appendChild(this.component.firstChild); + } + while (this.component.firstChild) { + this.component.removeChild(this.component.firstChild); + } + this.component.appendChild(this.container); + this.component.appendChild(this.backdrop); + }; + SidebarElement.prototype.addNativeGestures = function () { + this.component.addEventListener('touchstart', this.__onTouchStart, { passive: true }); + this.component.addEventListener('touchmove', this.__onTouchMove, { passive: true }); + this.component.addEventListener('touchend', this.__onTouchEnd, { passive: true }); + }; + SidebarElement.prototype.removeNativeGestures = function () { + this.component.removeEventListener('touchstart', this.__onTouchStart, { passive: true }); + this.component.removeEventListener('touchmove', this.__onTouchMove, { passive: true }); + this.component.removeEventListener('touchend', this.__onTouchEnd, { passive: true }); + }; + SidebarElement.prototype.addNativeOpenGestures = function () { + document.addEventListener('touchstart', this.__onSwipeOpenStart, { passive: true }); + document.addEventListener('touchmove', this.__onSwipeOpenMove, { passive: true }); + document.addEventListener('touchend', this.__onSwipeOpenEnd, { passive: true }); + }; + SidebarElement.prototype.removeNativeOpenGestures = function () { + document.removeEventListener('touchstart', this.__onSwipeOpenStart, { passive: true }); + document.removeEventListener('touchmove', this.__onSwipeOpenMove, { passive: true }); + document.removeEventListener('touchend', this.__onSwipeOpenEnd, { passive: true }); + }; + SidebarElement.prototype.moveSidebar = function (movement) { + this.component.classList.add(IS_MOVING); + this.applyStyle(this.container, 'transform', "translate(" + movement + "px, 0)", true); + this.updateBackdropOpacity(movement); + }; + SidebarElement.prototype.updateBackdropOpacity = function (movement) { + var swipeProgress = 1 - (Math.abs(movement) / this.container.clientWidth); + var opacity = swipeProgress / this.backdropOpacityRatio; + this.setBackdropOpacity(opacity); + }; + SidebarElement.prototype.setBackdropOpacity = function (opacity) { + this.applyStyle(this.backdrop, 'opacity', opacity.toString()); + }; + SidebarElement.prototype.targetElementIsBackdrop = function (e) { + return e.target.hasAttribute(SIDEBARJS + "-backdrop"); + }; + SidebarElement.prototype.setResponsive = function () { + if (!this.responsive && this.mainContent) { + throw new Error("You provide a [" + SIDEBARJS_CONTENT + "] element without set {responsive: true}"); + } + if (this.responsive && !this.mainContent) { + throw new Error("You have set {responsive: true} without provide a [" + SIDEBARJS_CONTENT + "] element"); + } + this.component.classList.add('sidebarjs--responsive'); + }; + SidebarElement.prototype.shouldDefineMainContent = function (mainContent) { + if (mainContent) { + mainContent.setAttribute(SIDEBARJS_CONTENT, ''); + return mainContent; + } + else { + return document.querySelector("[" + SIDEBARJS_CONTENT + "]"); + } + }; + SidebarElement.prototype.applyStyle = function (el, prop, val, vendorify) { + if (this.isStyleMapSupported) { + el.attributeStyleMap.set(prop, val); + } + else { + el.style[prop] = val; + if (vendorify) { + el.style['Webkit' + prop.charAt(0).toUpperCase() + prop.slice(1)] = val; + } + } + }; + SidebarElement.prototype.clearStyle = function (el) { + if (this.isStyleMapSupported) { + el.attributeStyleMap.clear(); + } + else { + el.removeAttribute('style'); + } + }; + SidebarElement.isStyleMapSupported = function () { + return Boolean(window.CSS && CSS.number); + }; + SidebarElement.create = function (element) { + var el = document.createElement('div'); + el.setAttribute(element, ''); + return el; + }; + SidebarElement.elemHasListener = function (elem, value) { + return elem && typeof value === 'boolean' ? elem.sidebarjsListener = value : !!elem.sidebarjsListener; + }; + return SidebarElement; + }()); + exports.SidebarElement = SidebarElement; + + }); + + unwrapExports(sidebarElement); + var sidebarElement_1 = sidebarElement.SidebarElement; + + var sidebarService = createCommonjsModule(function (module, exports) { + Object.defineProperty(exports, "__esModule", { value: true }); + + var SidebarService = /** @class */ (function () { + function SidebarService() { + this.instances = {}; + } + SidebarService.prototype.create = function (options) { + if (options === void 0) { options = {}; } + var name = options.component && options.component.getAttribute('sidebarjs') || ''; + this.instances[name] = new sidebarElement.SidebarElement(options); + return this.instances[name]; + }; + SidebarService.prototype.open = function (sidebarName) { + if (sidebarName === void 0) { sidebarName = ''; } + if (this.instances[sidebarName]) { + this.instances[sidebarName].open(); + } + }; + SidebarService.prototype.close = function (sidebarName) { + if (sidebarName === void 0) { sidebarName = ''; } + if (this.instances[sidebarName]) { + this.instances[sidebarName].close(); + } + }; + SidebarService.prototype.toggle = function (sidebarName) { + if (sidebarName === void 0) { sidebarName = ''; } + if (this.instances[sidebarName]) { + this.instances[sidebarName].toggle(); + } + }; + SidebarService.prototype.isVisible = function (sidebarName) { + if (sidebarName === void 0) { sidebarName = ''; } + return !!this.instances[sidebarName] && this.instances[sidebarName].isVisible(); + }; + SidebarService.prototype.setPosition = function (position, sidebarName) { + if (sidebarName === void 0) { sidebarName = ''; } + if (this.instances[sidebarName]) { + this.instances[sidebarName].setPosition(position); + } + }; + SidebarService.prototype.elemHasListener = function (elem, value) { + return sidebarElement.SidebarElement.elemHasListener(elem, value); + }; + SidebarService.prototype.destroy = function (sidebarName) { + if (sidebarName === void 0) { sidebarName = ''; } + if (this.instances[sidebarName]) { + this.instances[sidebarName].destroy(); + this.instances[sidebarName] = null; + delete this.instances[sidebarName]; + } + }; + return SidebarService; + }()); + exports.SidebarService = SidebarService; + + }); + + unwrapExports(sidebarService); + var sidebarService_1 = sidebarService.SidebarService; + + var src = createCommonjsModule(function (module, exports) { + Object.defineProperty(exports, "__esModule", { value: true }); + + exports.SidebarElement = sidebarElement.SidebarElement; + + exports.SidebarService = sidebarService.SidebarService; + + }); + + var index = unwrapExports(src); + var src_1 = src.SidebarElement; + var src_2 = src.SidebarService; + + exports.default = index; + exports.SidebarElement = src_1; + exports.SidebarService = src_2; + + Object.defineProperty(exports, '__esModule', { value: true }); }))); diff --git a/dist/angular-sidebarjs.min.css b/dist/angular-sidebarjs.min.css index 43bf506..db73c34 100644 --- a/dist/angular-sidebarjs.min.css +++ b/dist/angular-sidebarjs.min.css @@ -1 +1 @@ -[sidebarjs-backdrop],[sidebarjs]{top:0;left:0;width:100%;height:100%}[sidebarjs].sidebarjs--left,[sidebarjs].sidebarjs--left [sidebarjs-container]{-webkit-transform:translate(-100%);transform:translate(-100%)}[sidebarjs].sidebarjs--right,[sidebarjs].sidebarjs--right [sidebarjs-container]{-webkit-transform:translate(100%);transform:translate(100%)}[sidebarjs].sidebarjs--left [sidebarjs-container]{box-shadow:2px 0 4px rgba(0,0,0,.2)}[sidebarjs].sidebarjs--right [sidebarjs-container]{box-shadow:-2px 0 4px rgba(0,0,0,.2);margin-left:auto}[sidebarjs-backdrop]{position:absolute;background:#000;opacity:0;transition:opacity .3s ease;will-change:opacity}[sidebarjs-container]{position:relative;z-index:1;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;width:90%;max-width:300px;height:100%;background:#fff;transition:-webkit-transform .3s ease;transition:transform .3s ease;transition:transform .3s ease,-webkit-transform .3s ease;will-change:transform}[sidebarjs]{position:fixed;z-index:2;transition:-webkit-transform 0s ease .3s;transition:transform 0s ease .3s;transition:transform 0s ease .3s,-webkit-transform 0s ease .3s}[sidebarjs].sidebarjs--is-visible{transition:-webkit-transform 0s ease 0s;transition:transform 0s ease 0s;transition:transform 0s ease 0s,-webkit-transform 0s ease 0s}[sidebarjs].sidebarjs--is-moving,[sidebarjs].sidebarjs--is-visible,[sidebarjs].sidebarjs--is-visible [sidebarjs-container]{-webkit-transform:translate(0);transform:translate(0)}[sidebarjs].sidebarjs--is-moving,[sidebarjs].sidebarjs--is-moving [sidebarjs-backdrop],[sidebarjs].sidebarjs--is-moving [sidebarjs-container]{transition:none} \ No newline at end of file +[sidebarjs-backdrop],[sidebarjs]{top:0;left:0;width:100%;height:100%}.sidebarjs--left[sidebarjs],[sidebarjs].sidebarjs--left [sidebarjs-container]{transform:translate(-100%)}.sidebarjs--right[sidebarjs],[sidebarjs].sidebarjs--right [sidebarjs-container]{transform:translate(100%)}[sidebarjs].sidebarjs--left [sidebarjs-container]{box-shadow:2px 0 4px rgba(0,0,0,.2)}[sidebarjs].sidebarjs--right [sidebarjs-container]{box-shadow:-2px 0 4px rgba(0,0,0,.2);margin-left:auto}[sidebarjs-backdrop]{position:absolute;background:#000;opacity:0;transition:opacity .3s ease;will-change:opacity}[sidebarjs-container]{position:relative;z-index:1;display:flex;flex-direction:column;width:90%;max-width:300px;height:100%;background:#fff;transition:transform .3s ease;will-change:transform}[sidebarjs]{position:fixed;z-index:2;transition:transform 0s ease .3s}[sidebarjs].sidebarjs--is-visible{transform:translate(0);transition:transform 0s ease 0s}[sidebarjs].sidebarjs--is-visible [sidebarjs-container]{transform:translate(0)}[sidebarjs].sidebarjs--is-moving{transition:none;transform:translate(0)}[sidebarjs].sidebarjs--is-moving [sidebarjs-container]{transform:none!important}[sidebarjs].sidebarjs--is-moving [sidebarjs-backdrop],[sidebarjs].sidebarjs--is-moving [sidebarjs-container]{transition:none}[sidebarjs-content]{position:relative;width:100%;min-height:100%;transition:width .3s ease}[sidebarjs-content].sidebarjs-content--left{margin-left:auto;margin-right:0}[sidebarjs-content].sidebarjs-content--right{margin-left:0;margin-right:auto}@media (min-width:1025px){[sidebarjs].sidebarjs--responsive{transform:translate(0)!important;transition:transform 0s ease 0s;width:300px}[sidebarjs].sidebarjs--responsive [sidebarjs-container]{transform:translate(0)!important}[sidebarjs].sidebarjs--responsive.sidebarjs--left{left:0;right:auto}[sidebarjs].sidebarjs--responsive.sidebarjs--left [sidebarjs-container]{box-shadow:1px 0 0 rgba(0,0,0,.1)}[sidebarjs].sidebarjs--responsive.sidebarjs--right{right:0;left:auto}[sidebarjs].sidebarjs--responsive.sidebarjs--right [sidebarjs-container]{box-shadow:-1px 0 0 rgba(0,0,0,.1)}[sidebarjs].sidebarjs--responsive [sidebarjs-container]{max-width:none;width:100%;box-shadow:none}[sidebarjs-content]{width:calc(100% - 300px)}[sidebarjs-content].sidebarjs-content--left.sidebarjs-content--right{width:calc(100% - 600px);margin:0 auto}} \ No newline at end of file diff --git a/dist/angular-sidebarjs.min.js b/dist/angular-sidebarjs.min.js index 8f5ab69..520648d 100644 --- a/dist/angular-sidebarjs.min.js +++ b/dist/angular-sidebarjs.min.js @@ -1 +1 @@ -!function(e){var t={};function i(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){"use strict";var n=Object.assign||function(e){for(var t=1;t
",transclude:!0,controller:r,bindings:{onOpen:"&?",onClose:"&?",onChangeVisibility:"&?",sidebarjsConfig:"s.container.clientWidth/3.5?s.close():s.open(),s.initialTouch=null,s.touchMoveSidebar=null},this.__onSwipeOpenStart=function(e){if(!s.targetElementIsBackdrop(e)){var t=e.touches[0].clientX;(s.hasLeftPosition()?t:document.body.clientWidth-t)0&&n>=s.documentMinSwipeX&&(s.openMovement=i?-o:o,s.moveSidebar(s.openMovement))}},this.__onSwipeOpenEnd=function(){s.openMovement&&(s.openMovement=null,s.__onTouchEnd())},this.__onTransitionEnd=function(){var e=s.isVisible();e&&!s.__wasVisible?(s.__wasVisible=!0,s.__emitOnOpen&&s.__emitOnOpen()):!e&&s.__wasVisible&&(s.__wasVisible=!1,s.__emitOnClose&&s.__emitOnClose()),s.__emitOnChangeVisibility&&s.__emitOnChangeVisibility({isVisible:e})};var r=t.component,a=t.container,c=t.backdrop,p=t.documentMinSwipeX,d=void 0===p?10:p,h=t.documentSwipeRange,u=void 0===h?40:h,l=t.nativeSwipe,v=t.nativeSwipeOpen,m=t.position,f=void 0===m?"left":m,b=t.backdropOpacity,_=void 0===b?.3:b,y=t.onOpen,S=t.onClose,O=t.onChangeVisibility,E=a&&c;if(this.component=r||document.querySelector("["+i+"]"),this.container=E?a:e.create(i+"-container"),this.backdrop=E?c:e.create(i+"-backdrop"),this.documentMinSwipeX=d,this.documentSwipeRange=u,this.nativeSwipe=!1!==l,this.nativeSwipeOpen=!1!==v,this.backdropOpacity=_,this.backdropOpacityRatio=1/_,this.__emitOnOpen=y,this.__emitOnClose=S,this.__emitOnChangeVisibility=O,!E)try{this.transcludeContent()}catch(e){throw new Error("You must define an element with [sidebarjs] attribute")}this.nativeSwipe&&(this.addNativeGestures(),this.nativeSwipeOpen&&this.addNativeOpenGestures()),this.setPosition(f),this.addAttrsEventsListeners(this.component.getAttribute(i)),this.addTransitionListener(),this.backdrop.addEventListener("click",this.close,{passive:!0})}return e.prototype.isVisible=function(){return this.component.classList.contains(n)},e.prototype.destroy=function(){var e=this;for(this.component.removeEventListener("touchstart",this.__onTouchStart,{passive:!0}),this.component.removeEventListener("touchmove",this.__onTouchMove,{passive:!0}),this.component.removeEventListener("touchend",this.__onTouchEnd,{passive:!0}),this.container.removeEventListener("transitionend",this.__onTransitionEnd,{passive:!0}),this.backdrop.removeEventListener("click",this.close,{passive:!0}),document.removeEventListener("touchstart",this.__onSwipeOpenStart,{passive:!0}),document.removeEventListener("touchmove",this.__onSwipeOpenMove,{passive:!0}),document.removeEventListener("touchend",this.__onSwipeOpenEnd,{passive:!0}),this.removeAttrsEventsListeners(this.component.getAttribute(i)),this.removeComponentClassPosition();this.container.firstElementChild;)this.component.appendChild(this.container.firstElementChild);this.component.removeChild(this.container),this.component.removeChild(this.backdrop),Object.keys(this).forEach(function(t){return e[t]=null})},e.prototype.setPosition=function(e){var t=this;this.component.classList.add(o),this.position=r.indexOf(e)>=0?e:s,this.removeComponentClassPosition(),this.component.classList.add(i+"--"+(this.hasRightPosition()?"right":s)),setTimeout(function(){return t.component&&t.component.classList.remove(o)},200)},e.prototype.addAttrsEventsListeners=function(t){var i=this;this.forEachActionElement(t,function(t,n){e.elemHasListener(t)||(t.addEventListener("click",i[n],{passive:!0}),e.elemHasListener(t,!0))})},e.prototype.removeAttrsEventsListeners=function(t){var i=this;this.forEachActionElement(t,function(t,n){e.elemHasListener(t)&&(t.removeEventListener("click",i[n]),e.elemHasListener(t,!1))})},e.prototype.addTransitionListener=function(){this.__wasVisible=this.isVisible(),this.container.addEventListener("transitionend",this.__onTransitionEnd,{passive:!0})},e.prototype.forEachActionElement=function(e,t){for(var n=["toggle","open","close"],o=0;o
",transclude:!0,controller:r,bindings:{onOpen:"&?",onClose:"&?",onChangeVisibility:"&?",sidebarjsConfig:"s.container.clientWidth/3.5?s.close():s.open(),s.initialTouch=null,s.touchMoveSidebar=null},this.__onSwipeOpenStart=function(e){if(!s.targetElementIsBackdrop(e)){var t=e.touches[0].clientX;(s.hasLeftPosition()?t:document.body.clientWidth-t)0&&n>=s.documentMinSwipeX&&(s.openMovement=i?-o:o,s.moveSidebar(s.openMovement))}},this.__onSwipeOpenEnd=function(){s.openMovement&&(s.openMovement=null,s.__onTouchEnd())},this.__onTransitionEnd=function(){var e=s.isVisible();e&&!s.__wasVisible?(s.__wasVisible=!0,s.__emitOnOpen&&s.__emitOnOpen()):!e&&s.__wasVisible&&(s.__wasVisible=!1,s.__emitOnClose&&s.__emitOnClose()),s.__emitOnChangeVisibility&&s.__emitOnChangeVisibility({isVisible:e})};var r=t.component,a=t.container,c=t.backdrop,p=t.documentMinSwipeX,h=void 0===p?10:p,d=t.documentSwipeRange,u=void 0===d?40:d,l=t.nativeSwipe,v=t.nativeSwipeOpen,m=t.responsive,f=void 0!==m&&m,b=t.mainContent,S=t.position,y=void 0===S?"left":S,_=t.backdropOpacity,O=void 0===_?.3:_,E=t.onOpen,C=t.onClose,L=t.onChangeVisibility,g=a&&c;if(this.component=r||document.querySelector("["+i+"]"),this.container=g?a:e.create(i+"-container"),this.backdrop=g?c:e.create(i+"-backdrop"),this.documentMinSwipeX=h,this.documentSwipeRange=u,this.nativeSwipe=!1!==l,this.nativeSwipeOpen=!1!==v,this.isStyleMapSupported=e.isStyleMapSupported(),this.responsive=Boolean(f),this.mainContent=this.shouldDefineMainContent(b),this.backdropOpacity=O,this.backdropOpacityRatio=1/O,this.__emitOnOpen=E,this.__emitOnClose=C,this.__emitOnChangeVisibility=L,!g)try{this.transcludeContent()}catch(e){throw new Error("You must define an element with [sidebarjs] attribute")}this.setSwipeGestures(!0),(this.responsive||this.mainContent)&&this.setResponsive(),this.setPosition(y),this.addAttrsEventsListeners(this.component.getAttribute(i)),this.addTransitionListener(),this.backdrop.addEventListener("click",this.close,{passive:!0})}return e.prototype.isVisible=function(){return this.component.classList.contains(n)},e.prototype.destroy=function(){var e=this;for(this.removeNativeGestures(),this.container.removeEventListener("transitionend",this.__onTransitionEnd,{passive:!0}),this.backdrop.removeEventListener("click",this.close,{passive:!0}),this.removeNativeOpenGestures(),this.removeAttrsEventsListeners(this.component.getAttribute(i)),this.removeComponentClassPosition();this.container.firstElementChild;)this.component.appendChild(this.container.firstElementChild);this.component.removeChild(this.container),this.component.removeChild(this.backdrop),Object.keys(this).forEach(function(t){return e[t]=null})},e.prototype.setPosition=function(e){var t=this;this.component.classList.add(o),this.position=s.indexOf(e)>=0?e:"left";var n=1===(document.querySelectorAll("["+i+"]")||[]).length;this.removeComponentClassPosition(n),this.component.classList.add(i+"--"+this.position),this.responsive&&this.mainContent&&this.mainContent.classList.add("sidebarjs-content--"+this.position),setTimeout(function(){return t.component&&t.component.classList.remove(o)},200)},e.prototype.addAttrsEventsListeners=function(t){var i=this;this.forEachActionElement(t,function(t,n){e.elemHasListener(t)||(t.addEventListener("click",i[n],{passive:!0}),e.elemHasListener(t,!0))})},e.prototype.removeAttrsEventsListeners=function(t){var i=this;this.forEachActionElement(t,function(t,n){e.elemHasListener(t)&&(t.removeEventListener("click",i[n]),e.elemHasListener(t,!1))})},e.prototype.setSwipeGestures=function(e){if("boolean"!=typeof e)throw new Error("You provided a "+typeof e+" value but setSwipeGestures needs a boolean value.");this.nativeSwipe&&(e?this.addNativeGestures():this.removeNativeGestures(),this.nativeSwipeOpen&&(e?this.addNativeOpenGestures():this.removeNativeOpenGestures()))},e.prototype.addTransitionListener=function(){this.__wasVisible=this.isVisible(),this.container.addEventListener("transitionend",this.__onTransitionEnd,{passive:!0})},e.prototype.forEachActionElement=function(e,t){for(var n=["toggle","open","close"],o=0;o