@preline/toggle-password 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -1
- package/index.js +6 -6
- package/index.mjs +24 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare class HSBasePlugin<O, E = HTMLElement> implements IBasePlugin<O, E> {
|
|
|
17
17
|
options: O;
|
|
18
18
|
events?: any;
|
|
19
19
|
constructor(el: E, options: O, events?: any);
|
|
20
|
-
createCollection(collection: any[], element: any): void;
|
|
20
|
+
createCollection(collection: any[] | undefined, element: any): void;
|
|
21
21
|
fireEvent(evt: string, payload?: any): any;
|
|
22
22
|
on(evt: string, cb: Function): void;
|
|
23
23
|
}
|
package/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var o in s)("object"==typeof exports?exports:t)[o]=s[o]}}(self,(()=>(()=>{"use strict";var t={292:function(t,e){
|
|
2
2
|
/*
|
|
3
|
-
* @version: 4.1.
|
|
3
|
+
* @version: 4.1.2
|
|
4
4
|
* @author: Preline Labs Ltd.
|
|
5
5
|
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
6
6
|
* Copyright 2024 Preline Labs Ltd.
|
|
7
7
|
*/
|
|
8
|
-
Object.defineProperty(e,"__esModule",{value:!0}),e.stringToBoolean=e.menuSearchHistory=e.isScrollable=e.isParentOrElementHidden=e.isJson=e.isIpadOS=e.isIOS=e.isFormElement=e.isFocused=e.isEnoughSpace=e.isDirectChild=e.htmlToElement=e.getZIndex=e.getHighestZIndex=e.getClassPropertyAlt=e.getClassProperty=e.dispatch=e.debounce=e.classToClassList=e.afterTransition=void 0;e.stringToBoolean=t=>"true"===t;e.getClassProperty=(t,e,s="")=>(window.getComputedStyle(t).getPropertyValue(e)||s).replace(" ","");e.getClassPropertyAlt=(t,e,s="")=>{let o="";return t.classList.forEach((t=>{t.includes(e)&&(o=t)})),o.match(/:(.*)]/)?o.match(/:(.*)]/)[1]:s};const s=t=>window.getComputedStyle(t).getPropertyValue("z-index");e.getZIndex=s;e.getHighestZIndex=t=>{let e=Number.NEGATIVE_INFINITY;return t.forEach((t=>{let o=s(t);"auto"!==o&&(o=parseInt(o,10),o>e&&(e=o))})),e};e.isDirectChild=(t,e)=>{const s=t.children;for(let t=0;t<s.length;t++)if(s[t]===e)return!0;return!1};e.isEnoughSpace=(t,e,s="auto",o=10,i=null)=>{const n=e.getBoundingClientRect(),
|
|
8
|
+
Object.defineProperty(e,"__esModule",{value:!0}),e.stringToBoolean=e.menuSearchHistory=e.isScrollable=e.isParentOrElementHidden=e.isJson=e.isIpadOS=e.isIOS=e.isFormElement=e.isFocused=e.isEnoughSpace=e.isDirectChild=e.htmlToElement=e.getZIndex=e.getHighestZIndex=e.getClassPropertyAlt=e.getClassProperty=e.dispatch=e.debounce=e.classToClassList=e.afterTransition=void 0;e.stringToBoolean=t=>"true"===t;e.getClassProperty=(t,e,s="")=>(window.getComputedStyle(t).getPropertyValue(e)||s).replace(" ","");e.getClassPropertyAlt=(t,e,s="")=>{let o="";return t.classList.forEach((t=>{t.includes(e)&&(o=t)})),o.match(/:(.*)]/)?o.match(/:(.*)]/)[1]:s};const s=t=>window.getComputedStyle(t).getPropertyValue("z-index");e.getZIndex=s;e.getHighestZIndex=t=>{let e=Number.NEGATIVE_INFINITY;return t.forEach((t=>{let o=s(t);"auto"!==o&&(o=parseInt(o,10),o>e&&(e=o))})),e};e.isDirectChild=(t,e)=>{const s=t.children;for(let t=0;t<s.length;t++)if(s[t]===e)return!0;return!1};e.isEnoughSpace=(t,e,s="auto",o=10,i=null)=>{const n=e.getBoundingClientRect(),r=i?i.getBoundingClientRect():null,l=window.innerHeight,a=r?n.top-r.top:n.top,c=(i?r.bottom:l)-n.bottom,d=t.clientHeight+o;return"bottom"===s?c>=d:"top"===s?a>=d:a>=d||c>=d};e.isFocused=t=>document.activeElement===t;e.isFormElement=t=>t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement;e.isIOS=()=>!!/iPad|iPhone|iPod/.test(navigator.platform)||navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform);e.isIpadOS=()=>navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform);e.isJson=t=>{if("string"!=typeof t)return!1;const e=t.trim()[0],s=t.trim().slice(-1);if("{"===e&&"}"===s||"["===e&&"]"===s)try{return JSON.parse(t),!0}catch(t){return!1}return!1};const o=t=>{if(!t)return!1;return"none"===window.getComputedStyle(t).display||o(t.parentElement)};e.isParentOrElementHidden=o;e.isScrollable=t=>{const e=window.getComputedStyle(t),s=e.overflowY,o=e.overflowX,i=("scroll"===s||"auto"===s)&&t.scrollHeight>t.clientHeight,n=("scroll"===o||"auto"===o)&&t.scrollWidth>t.clientWidth;return i||n};e.debounce=(t,e=200)=>{let s;return(...o)=>{clearTimeout(s),s=setTimeout((()=>{t.apply(this,o)}),e)}};e.dispatch=(t,e,s=null)=>{const o=new CustomEvent(t,{detail:{payload:s},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(o)};e.afterTransition=(t,e)=>{const s=()=>{e(),t.removeEventListener("transitionend",s,!0)},o=window.getComputedStyle(t),i=o.getPropertyValue("transition-duration");"none"!==o.getPropertyValue("transition-property")&&parseFloat(i)>0?t.addEventListener("transitionend",s,!0):e()};e.htmlToElement=t=>{const e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild};e.classToClassList=(t,e,s=" ",o="add")=>{t.split(s).forEach((t=>{t.trim()&&("add"===o?e.classList.add(t):e.classList.remove(t))}))};const i={historyIndex:-1,addHistory(t){this.historyIndex=t},existsInHistory(t){return t>this.historyIndex},clearHistory(){this.historyIndex=-1}};e.menuSearchHistory=i},2961:(t,e)=>{
|
|
9
9
|
/*
|
|
10
10
|
* HSBasePlugin
|
|
11
|
-
* @version: 4.1.
|
|
11
|
+
* @version: 4.1.2
|
|
12
12
|
* @author: Preline Labs Ltd.
|
|
13
13
|
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
14
14
|
* Copyright 2024 Preline Labs Ltd.
|
|
15
15
|
*/
|
|
16
|
-
Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t,e,s){this.el=t,this.options=e,this.events=s,this.el=t,this.options=e,this.events={}}createCollection(t,e){var s;t.push({id:(null===(
|
|
16
|
+
Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t,e,s){this.el=t,this.options=e,this.events=s,this.el=t,this.options=e,this.events={}}createCollection(t,e){var s,o;let i=t;if(!Array.isArray(i)&&"undefined"!=typeof window){const t=null===(s=this.constructor)||void 0===s?void 0:s.name,e="string"==typeof t&&t.startsWith("HS")?`$hs${t.slice(2)}Collection`:null;e&&(Array.isArray(window[e])||(window[e]=[]),i=window[e])}Array.isArray(i)&&i.push({id:(null===(o=null==e?void 0:e.el)||void 0===o?void 0:o.id)||i.length+1,element:e})}fireEvent(t,e=null){if(this.events.hasOwnProperty(t))return this.events[t](e)}on(t,e){this.events[t]=e}}},8549:function(t,e,s){
|
|
17
17
|
/*
|
|
18
18
|
* HSTogglePassword
|
|
19
|
-
* @version: 4.1.
|
|
19
|
+
* @version: 4.1.2
|
|
20
20
|
* @author: Preline Labs Ltd.
|
|
21
21
|
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
22
22
|
* Copyright 2024 Preline Labs Ltd.
|
|
23
23
|
*/
|
|
24
|
-
var o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=s(292),n=o(s(2961));class
|
|
24
|
+
var o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=s(292),n=o(s(2961));class r extends n.default{constructor(t,e){super(t,e);const s=t.getAttribute("data-hs-toggle-password"),o=s?JSON.parse(s):{},n=Object.assign(Object.assign({},o),e),r=[];if((null==n?void 0:n.target)&&"string"==typeof(null==n?void 0:n.target)){(null==n?void 0:n.target.split(",")).forEach((t=>{r.push(document.querySelector(t))}))}else(null==n?void 0:n.target)&&"object"==typeof(null==n?void 0:n.target)?n.target.forEach((t=>r.push(document.querySelector(t)))):n.target.forEach((t=>r.push(t)));this.target=r,this.isShown=!!this.el.hasAttribute("type")&&this.el.checked,this.eventType=(0,i.isFormElement)(this.el)?"change":"click",this.isMultiple=this.target.length>1&&!!this.el.closest("[data-hs-toggle-password-group]"),this.target&&this.init()}elementAction(){this.isShown?this.hide():this.show(),this.fireEvent("toggle",this.target),(0,i.dispatch)("toggle.hs.toggle-select",this.el,this.target)}init(){this.createCollection(window.$hsTogglePasswordCollection,this),this.isShown?this.show():this.hide(),this.onElementActionListener=()=>this.elementAction(),this.el.addEventListener(this.eventType,this.onElementActionListener)}getMultipleToggles(){const t=this.el.closest("[data-hs-toggle-password-group]").querySelectorAll("[data-hs-toggle-password]"),e=[];return t.forEach((t=>{e.push(r.getInstance(t))})),e}show(){if(this.isMultiple){this.getMultipleToggles().forEach((t=>!!t&&(t.isShown=!0))),this.el.closest("[data-hs-toggle-password-group]").classList.add("active")}else this.isShown=!0,this.el.classList.add("active");this.target.forEach((t=>{t.type="text"}))}hide(){if(this.isMultiple){this.getMultipleToggles().forEach((t=>!!t&&(t.isShown=!1))),this.el.closest("[data-hs-toggle-password-group]").classList.remove("active")}else this.isShown=!1,this.el.classList.remove("active");this.target.forEach((t=>{t.type="password"}))}destroy(){this.isMultiple?this.el.closest("[data-hs-toggle-password-group]").classList.remove("active"):this.el.classList.remove("active"),this.target.forEach((t=>{t.type="password"})),this.el.removeEventListener(this.eventType,this.onElementActionListener),this.isShown=!1,window.$hsTogglePasswordCollection=window.$hsTogglePasswordCollection.filter((({element:t})=>t.el!==this.el))}static getInstance(t,e){const s=window.$hsTogglePasswordCollection.find((e=>e.element.el===("string"==typeof t?document.querySelector(t):t)));return s?e?s:s.element:null}static autoInit(){window.$hsTogglePasswordCollection||(window.$hsTogglePasswordCollection=[]),window.$hsTogglePasswordCollection&&(window.$hsTogglePasswordCollection=window.$hsTogglePasswordCollection.filter((({element:t})=>document.contains(t.el)))),document.querySelectorAll("[data-hs-toggle-password]:not(.--prevent-on-load-init)").forEach((t=>{window.$hsTogglePasswordCollection.find((e=>{var s;return(null===(s=null==e?void 0:e.element)||void 0===s?void 0:s.el)===t}))||new r(t)}))}}e.default=r}},e={};var s=function s(o){var i=e[o];if(void 0!==i)return i.exports;var n=e[o]={exports:{}};return t[o].call(n.exports,n,n.exports,s),n.exports}(8549);return s})()));
|
package/index.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var t={615:(t,e,s)=>{s.d(e,{A:()=>o});
|
|
2
|
+
/*
|
|
3
|
+
* HSBasePlugin
|
|
4
|
+
* @version: 4.1.2
|
|
5
|
+
* @author: Preline Labs Ltd.
|
|
6
|
+
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
7
|
+
* Copyright 2024 Preline Labs Ltd.
|
|
8
|
+
*/
|
|
9
|
+
class o{constructor(t,e,s){this.el=t,this.options=e,this.events=s,this.el=t,this.options=e,this.events={}}createCollection(t,e){var s,o;let i=t;if(!Array.isArray(i)&&"undefined"!=typeof window){const t=null===(s=this.constructor)||void 0===s?void 0:s.name,e="string"==typeof t&&t.startsWith("HS")?`$hs${t.slice(2)}Collection`:null;e&&(Array.isArray(window[e])||(window[e]=[]),i=window[e])}Array.isArray(i)&&i.push({id:(null===(o=null==e?void 0:e.el)||void 0===o?void 0:o.id)||i.length+1,element:e})}fireEvent(t,e=null){if(this.events.hasOwnProperty(t))return this.events[t](e)}on(t,e){this.events[t]=e}}},926:(t,e,s)=>{s.d(e,{JD:()=>i,V6:()=>o});
|
|
10
|
+
/*
|
|
11
|
+
* @version: 4.1.2
|
|
12
|
+
* @author: Preline Labs Ltd.
|
|
13
|
+
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
14
|
+
* Copyright 2024 Preline Labs Ltd.
|
|
15
|
+
*/
|
|
16
|
+
const o=t=>t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement,i=(t,e,s=null)=>{const o=new CustomEvent(t,{detail:{payload:s},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(o)}}},e={};function s(o){var i=e[o];if(void 0!==i)return i.exports;var l=e[o]={exports:{}};return t[o](l,l.exports,s),l.exports}s.d=(t,e)=>{for(var o in e)s.o(e,o)&&!s.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var o={};s.d(o,{A:()=>r});var i=s(926),l=s(615);
|
|
17
|
+
/*
|
|
18
|
+
* HSTogglePassword
|
|
19
|
+
* @version: 4.1.2
|
|
20
|
+
* @author: Preline Labs Ltd.
|
|
21
|
+
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
22
|
+
* Copyright 2024 Preline Labs Ltd.
|
|
23
|
+
*/
|
|
24
|
+
class n extends l.A{constructor(t,e){super(t,e);const s=t.getAttribute("data-hs-toggle-password"),o=s?JSON.parse(s):{},l=Object.assign(Object.assign({},o),e),n=[];if((null==l?void 0:l.target)&&"string"==typeof(null==l?void 0:l.target)){(null==l?void 0:l.target.split(",")).forEach((t=>{n.push(document.querySelector(t))}))}else(null==l?void 0:l.target)&&"object"==typeof(null==l?void 0:l.target)?l.target.forEach((t=>n.push(document.querySelector(t)))):l.target.forEach((t=>n.push(t)));this.target=n,this.isShown=!!this.el.hasAttribute("type")&&this.el.checked,this.eventType=(0,i.V6)(this.el)?"change":"click",this.isMultiple=this.target.length>1&&!!this.el.closest("[data-hs-toggle-password-group]"),this.target&&this.init()}elementAction(){this.isShown?this.hide():this.show(),this.fireEvent("toggle",this.target),(0,i.JD)("toggle.hs.toggle-select",this.el,this.target)}init(){this.createCollection(window.$hsTogglePasswordCollection,this),this.isShown?this.show():this.hide(),this.onElementActionListener=()=>this.elementAction(),this.el.addEventListener(this.eventType,this.onElementActionListener)}getMultipleToggles(){const t=this.el.closest("[data-hs-toggle-password-group]").querySelectorAll("[data-hs-toggle-password]"),e=[];return t.forEach((t=>{e.push(n.getInstance(t))})),e}show(){if(this.isMultiple){this.getMultipleToggles().forEach((t=>!!t&&(t.isShown=!0))),this.el.closest("[data-hs-toggle-password-group]").classList.add("active")}else this.isShown=!0,this.el.classList.add("active");this.target.forEach((t=>{t.type="text"}))}hide(){if(this.isMultiple){this.getMultipleToggles().forEach((t=>!!t&&(t.isShown=!1))),this.el.closest("[data-hs-toggle-password-group]").classList.remove("active")}else this.isShown=!1,this.el.classList.remove("active");this.target.forEach((t=>{t.type="password"}))}destroy(){this.isMultiple?this.el.closest("[data-hs-toggle-password-group]").classList.remove("active"):this.el.classList.remove("active"),this.target.forEach((t=>{t.type="password"})),this.el.removeEventListener(this.eventType,this.onElementActionListener),this.isShown=!1,window.$hsTogglePasswordCollection=window.$hsTogglePasswordCollection.filter((({element:t})=>t.el!==this.el))}static getInstance(t,e){const s=window.$hsTogglePasswordCollection.find((e=>e.element.el===("string"==typeof t?document.querySelector(t):t)));return s?e?s:s.element:null}static autoInit(){window.$hsTogglePasswordCollection||(window.$hsTogglePasswordCollection=[]),window.$hsTogglePasswordCollection&&(window.$hsTogglePasswordCollection=window.$hsTogglePasswordCollection.filter((({element:t})=>document.contains(t.el)))),document.querySelectorAll("[data-hs-toggle-password]:not(.--prevent-on-load-init)").forEach((t=>{window.$hsTogglePasswordCollection.find((e=>{var s;return(null===(s=null==e?void 0:e.element)||void 0===s?void 0:s.el)===t}))||new n(t)}))}}const r=n;var a=o.A;export{a as default};
|
package/package.json
CHANGED