@vrembem/core
Advanced tools
Comparing version 1.14.8 to 1.15.0
@@ -7,2 +7,41 @@ (function (global, factory) { | ||
var setInert = function setInert(state, selector) { | ||
if (selector) { | ||
var els = document.querySelectorAll(selector); | ||
els.forEach(function (el) { | ||
if (state) { | ||
el.inert = true; | ||
el.setAttribute('aria-hidden', true); | ||
} else { | ||
el.inert = null; | ||
el.removeAttribute('aria-hidden'); | ||
} | ||
}); | ||
} | ||
}; | ||
var setOverflowHidden = function setOverflowHidden(state, selector) { | ||
if (selector) { | ||
var els = document.querySelectorAll(selector); | ||
els.forEach(function (el) { | ||
if (state) { | ||
el.style.overflow = 'hidden'; | ||
} else { | ||
el.style.removeProperty('overflow'); | ||
} | ||
}); | ||
} | ||
}; | ||
var setTabindex = function setTabindex(state, selector) { | ||
if (selector) { | ||
var els = document.querySelectorAll(selector); | ||
els.forEach(function (el) { | ||
if (state) { | ||
el.setAttribute('tabindex', '-1'); | ||
} else { | ||
el.removeAttribute('tabindex'); | ||
} | ||
}); | ||
} | ||
}; | ||
var addClass = function addClass(el) { | ||
@@ -27,2 +66,131 @@ for (var _len = arguments.length, cl = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
var classCallCheck = _classCallCheck; | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
var createClass = _createClass; | ||
var focusTarget = function focusTarget(target, settings) { | ||
var innerFocus = target.querySelector("[data-".concat(settings.dataFocus, "]")); | ||
if (innerFocus) { | ||
innerFocus.focus(); | ||
} else { | ||
var innerElement = target.querySelector('[tabindex="-1"]'); | ||
if (innerElement) innerElement.focus(); | ||
} | ||
}; | ||
var focusTrigger = function focusTrigger() { | ||
var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
if (!obj || !obj.memory || !obj.memory.trigger) return; | ||
obj.memory.trigger.focus(); | ||
obj.memory.trigger = null; | ||
}; | ||
var FocusTrap = function () { | ||
function FocusTrap() { | ||
classCallCheck(this, FocusTrap); | ||
this.target = null; | ||
this.__handlerFocusTrap = this.handlerFocusTrap.bind(this); | ||
} | ||
createClass(FocusTrap, [{ | ||
key: "init", | ||
value: function init(target) { | ||
this.target = target; | ||
this.inner = this.target.querySelector('[tabindex="-1"]'); | ||
this.focusable = this.getFocusable(); | ||
if (this.focusable.length) { | ||
this.focusableFirst = this.focusable[0]; | ||
this.focusableLast = this.focusable[this.focusable.length - 1]; | ||
this.target.addEventListener('keydown', this.__handlerFocusTrap); | ||
} else { | ||
this.target.addEventListener('keydown', this.handlerFocusLock); | ||
} | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy() { | ||
if (!this.target) return; | ||
this.inner = null; | ||
this.focusable = null; | ||
this.focusableFirst = null; | ||
this.focusableLast = null; | ||
this.target.removeEventListener('keydown', this.__handlerFocusTrap); | ||
this.target.removeEventListener('keydown', this.handlerFocusLock); | ||
this.target = null; | ||
} | ||
}, { | ||
key: "handlerFocusTrap", | ||
value: function handlerFocusTrap(event) { | ||
var isTab = event.key === 'Tab' || event.keyCode === 9; | ||
if (!isTab) return; | ||
if (event.shiftKey) { | ||
if (document.activeElement === this.focusableFirst || document.activeElement === this.inner) { | ||
this.focusableLast.focus(); | ||
event.preventDefault(); | ||
} | ||
} else { | ||
if (document.activeElement === this.focusableLast || document.activeElement === this.inner) { | ||
this.focusableFirst.focus(); | ||
event.preventDefault(); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "handlerFocusLock", | ||
value: function handlerFocusLock(event) { | ||
var isTab = event.key === 'Tab' || event.keyCode === 9; | ||
if (isTab) event.preventDefault(); | ||
} | ||
}, { | ||
key: "getFocusable", | ||
value: function getFocusable() { | ||
var focusable = []; | ||
var initFocus = document.activeElement; | ||
var initScrollTop = this.inner ? this.inner.scrollTop : 0; | ||
this.target.querySelectorAll("\n a[href]:not([disabled]),\n button:not([disabled]),\n textarea:not([disabled]),\n input[type=\"text\"]:not([disabled]),\n input[type=\"radio\"]:not([disabled]),\n input[type=\"checkbox\"]:not([disabled]),\n select:not([disabled]),\n [tabindex]:not([tabindex=\"-1\"])\n ").forEach(function (el) { | ||
el.focus(); | ||
if (el === document.activeElement) { | ||
focusable.push(el); | ||
} | ||
}); | ||
if (this.inner) this.inner.scrollTop = initScrollTop; | ||
initFocus.focus(); | ||
return focusable; | ||
} | ||
}]); | ||
return FocusTrap; | ||
}(); | ||
var getElement = function getElement(selector) { | ||
var single = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
if (typeof selector != 'string') return selector; | ||
return single ? document.querySelector(selector) : document.querySelectorAll(selector); | ||
}; | ||
var hasClass = function hasClass(el) { | ||
@@ -49,2 +217,53 @@ el = el.forEach ? el : [el]; | ||
function moveElement() { | ||
var reference = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
var type = arguments.length > 1 ? arguments[1] : undefined; | ||
var target = arguments.length > 2 ? arguments[2] : undefined; | ||
if (reference) { | ||
var ref = getElement(reference, 1); | ||
if (!ref) throw new Error("Move reference element \"".concat(reference, "\" not found!")); | ||
var els = getElement(target); | ||
if (!els.length) throw new Error("Move target element \"".concat(target, "\" not found!")); | ||
els.forEach(function (el) { | ||
switch (type) { | ||
case 'after': | ||
ref.after(el); | ||
return { | ||
ref: ref, | ||
el: el, | ||
type: type | ||
}; | ||
case 'before': | ||
ref.before(el); | ||
return { | ||
ref: ref, | ||
el: el, | ||
type: type | ||
}; | ||
case 'append': | ||
ref.append(el); | ||
return { | ||
ref: ref, | ||
el: el, | ||
type: type | ||
}; | ||
case 'prepend': | ||
ref.prepend(el); | ||
return { | ||
ref: ref, | ||
el: el, | ||
type: type | ||
}; | ||
default: | ||
throw new Error("Move type \"".concat(type, "\" does not exist!")); | ||
} | ||
}); | ||
} | ||
} | ||
var removeClass = function removeClass(el) { | ||
@@ -76,2 +295,39 @@ for (var _len = arguments.length, cl = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
var openTransition = function openTransition(el, settings) { | ||
return new Promise(function (resolve) { | ||
if (settings.transition) { | ||
el.classList.remove(settings.stateClosed); | ||
el.classList.add(settings.stateOpening); | ||
el.addEventListener('transitionend', function _f() { | ||
el.classList.add(settings.stateOpened); | ||
el.classList.remove(settings.stateOpening); | ||
resolve(el); | ||
this.removeEventListener('transitionend', _f); | ||
}); | ||
} else { | ||
el.classList.add(settings.stateOpened); | ||
el.classList.remove(settings.stateClosed); | ||
resolve(el); | ||
} | ||
}); | ||
}; | ||
var closeTransition = function closeTransition(el, settings) { | ||
return new Promise(function (resolve) { | ||
if (settings.transition) { | ||
el.classList.add(settings.stateClosing); | ||
el.classList.remove(settings.stateOpened); | ||
el.addEventListener('transitionend', function _f() { | ||
el.classList.remove(settings.stateClosing); | ||
el.classList.add(settings.stateClosed); | ||
resolve(el); | ||
this.removeEventListener('transitionend', _f); | ||
}); | ||
} else { | ||
el.classList.add(settings.stateClosed); | ||
el.classList.remove(settings.stateOpened); | ||
resolve(el); | ||
} | ||
}); | ||
}; | ||
var breakpoints = { | ||
@@ -85,8 +341,18 @@ xs: '480px', | ||
exports.FocusTrap = FocusTrap; | ||
exports.addClass = addClass; | ||
exports.breakpoints = breakpoints; | ||
exports.camelCase = camelCase; | ||
exports.closeTransition = closeTransition; | ||
exports.focusTarget = focusTarget; | ||
exports.focusTrigger = focusTrigger; | ||
exports.getElement = getElement; | ||
exports.hasClass = hasClass; | ||
exports.hyphenCase = hyphenCase; | ||
exports.moveElement = moveElement; | ||
exports.openTransition = openTransition; | ||
exports.removeClass = removeClass; | ||
exports.setInert = setInert; | ||
exports.setOverflowHidden = setOverflowHidden; | ||
exports.setTabindex = setTabindex; | ||
exports.toggleClass = toggleClass; | ||
@@ -93,0 +359,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(((e="undefined"!=typeof globalThis?globalThis:e||self).vrembem=e.vrembem||{},e.vrembem.core=e.vrembem.core||{}))}(this,(function(e){"use strict";e.addClass=function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];(e=e.forEach?e:[e]).forEach((function(e){var n;(n=e.classList).add.apply(n,r)}))},e.breakpoints={xs:"480px",sm:"620px",md:"760px",lg:"990px",xl:"1380px"},e.camelCase=function(e){return e.replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()}))},e.hasClass=function(e){e=e.forEach?e:[e],e=[].slice.call(e);for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return r.some((function(n){return e.some((function(e){if(e.classList.contains(n))return!0}))}))},e.hyphenCase=function(e){return e.replace(/([a-z][A-Z])/g,(function(e){return e[0]+"-"+e[1].toLowerCase()}))},e.removeClass=function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];(e=e.forEach?e:[e]).forEach((function(e){var n;(n=e.classList).remove.apply(n,r)}))},e.toggleClass=function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];(e=e.forEach?e:[e]).forEach((function(e){r.forEach((function(n){e.classList.toggle(n)}))}))},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).vrembem=e.vrembem||{},e.vrembem.core=e.vrembem.core||{}))}(this,(function(e){"use strict";var t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")};function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var r=function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e},o=function(){function e(){t(this,e),this.target=null,this.__handlerFocusTrap=this.handlerFocusTrap.bind(this)}return r(e,[{key:"init",value:function(e){this.target=e,this.inner=this.target.querySelector('[tabindex="-1"]'),this.focusable=this.getFocusable(),this.focusable.length?(this.focusableFirst=this.focusable[0],this.focusableLast=this.focusable[this.focusable.length-1],this.target.addEventListener("keydown",this.__handlerFocusTrap)):this.target.addEventListener("keydown",this.handlerFocusLock)}},{key:"destroy",value:function(){this.target&&(this.inner=null,this.focusable=null,this.focusableFirst=null,this.focusableLast=null,this.target.removeEventListener("keydown",this.__handlerFocusTrap),this.target.removeEventListener("keydown",this.handlerFocusLock),this.target=null)}},{key:"handlerFocusTrap",value:function(e){("Tab"===e.key||9===e.keyCode)&&(e.shiftKey?document.activeElement!==this.focusableFirst&&document.activeElement!==this.inner||(this.focusableLast.focus(),e.preventDefault()):document.activeElement!==this.focusableLast&&document.activeElement!==this.inner||(this.focusableFirst.focus(),e.preventDefault()))}},{key:"handlerFocusLock",value:function(e){("Tab"===e.key||9===e.keyCode)&&e.preventDefault()}},{key:"getFocusable",value:function(){var e=[],t=document.activeElement,n=this.inner?this.inner.scrollTop:0;return this.target.querySelectorAll('\n a[href]:not([disabled]),\n button:not([disabled]),\n textarea:not([disabled]),\n input[type="text"]:not([disabled]),\n input[type="radio"]:not([disabled]),\n input[type="checkbox"]:not([disabled]),\n select:not([disabled]),\n [tabindex]:not([tabindex="-1"])\n ').forEach((function(t){t.focus(),t===document.activeElement&&e.push(t)})),this.inner&&(this.inner.scrollTop=n),t.focus(),e}}]),e}(),s=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return"string"!=typeof e?e:t?document.querySelector(e):document.querySelectorAll(e)};e.FocusTrap=o,e.addClass=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];(e=e.forEach?e:[e]).forEach((function(e){var t;(t=e.classList).add.apply(t,n)}))},e.breakpoints={xs:"480px",sm:"620px",md:"760px",lg:"990px",xl:"1380px"},e.camelCase=function(e){return e.replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()}))},e.closeTransition=function(e,t){return new Promise((function(n){t.transition?(e.classList.add(t.stateClosing),e.classList.remove(t.stateOpened),e.addEventListener("transitionend",(function r(){e.classList.remove(t.stateClosing),e.classList.add(t.stateClosed),n(e),this.removeEventListener("transitionend",r)}))):(e.classList.add(t.stateClosed),e.classList.remove(t.stateOpened),n(e))}))},e.focusTarget=function(e,t){var n=e.querySelector("[data-".concat(t.dataFocus,"]"));if(n)n.focus();else{var r=e.querySelector('[tabindex="-1"]');r&&r.focus()}},e.focusTrigger=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e&&e.memory&&e.memory.trigger&&(e.memory.trigger.focus(),e.memory.trigger=null)},e.getElement=s,e.hasClass=function(e){e=e.forEach?e:[e],e=[].slice.call(e);for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return n.some((function(t){return e.some((function(e){if(e.classList.contains(t))return!0}))}))},e.hyphenCase=function(e){return e.replace(/([a-z][A-Z])/g,(function(e){return e[0]+"-"+e[1].toLowerCase()}))},e.moveElement=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0;if(e){var r=s(e,1);if(!r)throw new Error('Move reference element "'.concat(e,'" not found!'));var o=s(n);if(!o.length)throw new Error('Move target element "'.concat(n,'" not found!'));o.forEach((function(e){switch(t){case"after":return r.after(e),{ref:r,el:e,type:t};case"before":return r.before(e),{ref:r,el:e,type:t};case"append":return r.append(e),{ref:r,el:e,type:t};case"prepend":return r.prepend(e),{ref:r,el:e,type:t};default:throw new Error('Move type "'.concat(t,'" does not exist!'))}}))}},e.openTransition=function(e,t){return new Promise((function(n){t.transition?(e.classList.remove(t.stateClosed),e.classList.add(t.stateOpening),e.addEventListener("transitionend",(function r(){e.classList.add(t.stateOpened),e.classList.remove(t.stateOpening),n(e),this.removeEventListener("transitionend",r)}))):(e.classList.add(t.stateOpened),e.classList.remove(t.stateClosed),n(e))}))},e.removeClass=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];(e=e.forEach?e:[e]).forEach((function(e){var t;(t=e.classList).remove.apply(t,n)}))},e.setInert=function(e,t){t&&document.querySelectorAll(t).forEach((function(t){e?(t.inert=!0,t.setAttribute("aria-hidden",!0)):(t.inert=null,t.removeAttribute("aria-hidden"))}))},e.setOverflowHidden=function(e,t){t&&document.querySelectorAll(t).forEach((function(t){e?t.style.overflow="hidden":t.style.removeProperty("overflow")}))},e.setTabindex=function(e,t){t&&document.querySelectorAll(t).forEach((function(t){e?t.setAttribute("tabindex","-1"):t.removeAttribute("tabindex")}))},e.toggleClass=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];(e=e.forEach?e:[e]).forEach((function(e){n.forEach((function(t){e.classList.toggle(t)}))}))},Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -0,7 +1,12 @@ | ||
export * from './src/js/accessibility'; | ||
export * from './src/js/addClass'; | ||
export * from './src/js/camelCase'; | ||
export * from './src/js/focus'; | ||
export * from './src/js/getElement'; | ||
export * from './src/js/hasClass'; | ||
export * from './src/js/hyphenCase'; | ||
export * from './src/js/moveElement'; | ||
export * from './src/js/removeClass'; | ||
export * from './src/js/toggleClass'; | ||
export * from './src/js/transition'; | ||
export * from './src/js/variables'; |
{ | ||
"name": "@vrembem/core", | ||
"description": "The core variables, functions and mixins for Vrembem components.", | ||
"version": "1.14.8", | ||
"version": "1.15.0", | ||
"license": "MIT", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "a50ba9cc1e2316d74171701bbc4161f851e2bb63" | ||
"gitHead": "1fde52e053066cf019c34748ddd36aea7bdd5ae0" | ||
} |
@@ -1,2 +0,2 @@ | ||
const breakpoints = { | ||
export const breakpoints = { | ||
xs: '480px', | ||
@@ -8,5 +8,1 @@ sm: '620px', | ||
}; | ||
export { | ||
breakpoints | ||
}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
76889
36
1261
1