UNPKG

wired-pattern-lock

Version:

A lightweight div-based gesture pattern lock library using SVG lines.

2 lines 15.8 kB
/*! For license information please see wired.js.LICENSE.txt */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.wired=e():t.wired=e()}(this,(()=>(()=>{var t={333:()=>{},569:(t,e,i)=>{var s;!function(){"use strict";var e="input is invalid type",n="object"==typeof window,r=n?window:{};r.JS_MD5_NO_WINDOW&&(n=!1);var o=!n&&"object"==typeof self,h=!r.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;h?r=i.g:o&&(r=self);var a,d=!r.JS_MD5_NO_COMMON_JS&&t.exports,c=i.amdO,u=!r.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,l="0123456789abcdef".split(""),f=[128,32768,8388608,-2147483648],p=[0,8,16,24],y=["hex","array","digest","buffer","arrayBuffer","base64"],v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),_=[];if(u){var w=new ArrayBuffer(68);a=new Uint8Array(w),_=new Uint32Array(w)}var m=Array.isArray;!r.JS_MD5_NO_NODE_JS&&m||(m=function(t){return"[object Array]"===Object.prototype.toString.call(t)});var b=ArrayBuffer.isView;!u||!r.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&b||(b=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});var g=function(t){var i=typeof t;if("string"===i)return[t,!0];if("object"!==i||null===t)throw new Error(e);if(u&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!m(t)&&!b(t))throw new Error(e);return[t,!1]},A=function(t){return function(e){return new x(!0).update(e)[t]()}},E=function(t){return function(e,i){return new H(e,!0).update(i)[t]()}};function x(t){if(t)_[0]=_[16]=_[1]=_[2]=_[3]=_[4]=_[5]=_[6]=_[7]=_[8]=_[9]=_[10]=_[11]=_[12]=_[13]=_[14]=_[15]=0,this.blocks=_,this.buffer8=a;else if(u){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function H(t,e){var i,s=g(t);if(t=s[0],s[1]){var n,r=[],o=t.length,h=0;for(i=0;i<o;++i)(n=t.charCodeAt(i))<128?r[h++]=n:n<2048?(r[h++]=192|n>>>6,r[h++]=128|63&n):n<55296||n>=57344?(r[h++]=224|n>>>12,r[h++]=128|n>>>6&63,r[h++]=128|63&n):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++i)),r[h++]=240|n>>>18,r[h++]=128|n>>>12&63,r[h++]=128|n>>>6&63,r[h++]=128|63&n);t=r}t.length>64&&(t=new x(!0).update(t).array());var a=[],d=[];for(i=0;i<64;++i){var c=t[i]||0;a[i]=92^c,d[i]=54^c}x.call(this,e),this.update(d),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}x.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=g(t);t=e[0];for(var i,s,n=e[1],r=0,o=t.length,h=this.blocks,a=this.buffer8;r<o;){if(this.hashed&&(this.hashed=!1,h[0]=h[16],h[16]=h[1]=h[2]=h[3]=h[4]=h[5]=h[6]=h[7]=h[8]=h[9]=h[10]=h[11]=h[12]=h[13]=h[14]=h[15]=0),n)if(u)for(s=this.start;r<o&&s<64;++r)(i=t.charCodeAt(r))<128?a[s++]=i:i<2048?(a[s++]=192|i>>>6,a[s++]=128|63&i):i<55296||i>=57344?(a[s++]=224|i>>>12,a[s++]=128|i>>>6&63,a[s++]=128|63&i):(i=65536+((1023&i)<<10|1023&t.charCodeAt(++r)),a[s++]=240|i>>>18,a[s++]=128|i>>>12&63,a[s++]=128|i>>>6&63,a[s++]=128|63&i);else for(s=this.start;r<o&&s<64;++r)(i=t.charCodeAt(r))<128?h[s>>>2]|=i<<p[3&s++]:i<2048?(h[s>>>2]|=(192|i>>>6)<<p[3&s++],h[s>>>2]|=(128|63&i)<<p[3&s++]):i<55296||i>=57344?(h[s>>>2]|=(224|i>>>12)<<p[3&s++],h[s>>>2]|=(128|i>>>6&63)<<p[3&s++],h[s>>>2]|=(128|63&i)<<p[3&s++]):(i=65536+((1023&i)<<10|1023&t.charCodeAt(++r)),h[s>>>2]|=(240|i>>>18)<<p[3&s++],h[s>>>2]|=(128|i>>>12&63)<<p[3&s++],h[s>>>2]|=(128|i>>>6&63)<<p[3&s++],h[s>>>2]|=(128|63&i)<<p[3&s++]);else if(u)for(s=this.start;r<o&&s<64;++r)a[s++]=t[r];else for(s=this.start;r<o&&s<64;++r)h[s>>>2]|=t[r]<<p[3&s++];this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},x.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex;t[e>>>2]|=f[3&e],e>=56&&(this.hashed||this.hash(),t[0]=t[16],t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.bytes<<3,t[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},x.prototype.hash=function(){var t,e,i,s,n,r,o=this.blocks;this.first?e=((e=((t=((t=o[0]-680876937)<<7|t>>>25)-271733879|0)^(i=((i=(-271733879^(s=((s=(-1732584194^2004318071&t)+o[1]-117830708)<<12|s>>>20)+t|0)&(-271733879^t))+o[2]-1126478375)<<17|i>>>15)+s|0)&(s^t))+o[3]-1316259209)<<22|e>>>10)+i|0:(t=this.h0,e=this.h1,i=this.h2,e=((e+=((t=((t+=((s=this.h3)^e&(i^s))+o[0]-680876936)<<7|t>>>25)+e|0)^(i=((i+=(e^(s=((s+=(i^t&(e^i))+o[1]-389564586)<<12|s>>>20)+t|0)&(t^e))+o[2]+606105819)<<17|i>>>15)+s|0)&(s^t))+o[3]-1044525330)<<22|e>>>10)+i|0),e=((e+=((t=((t+=(s^e&(i^s))+o[4]-176418897)<<7|t>>>25)+e|0)^(i=((i+=(e^(s=((s+=(i^t&(e^i))+o[5]+1200080426)<<12|s>>>20)+t|0)&(t^e))+o[6]-1473231341)<<17|i>>>15)+s|0)&(s^t))+o[7]-45705983)<<22|e>>>10)+i|0,e=((e+=((t=((t+=(s^e&(i^s))+o[8]+1770035416)<<7|t>>>25)+e|0)^(i=((i+=(e^(s=((s+=(i^t&(e^i))+o[9]-1958414417)<<12|s>>>20)+t|0)&(t^e))+o[10]-42063)<<17|i>>>15)+s|0)&(s^t))+o[11]-1990404162)<<22|e>>>10)+i|0,e=((e+=((t=((t+=(s^e&(i^s))+o[12]+1804603682)<<7|t>>>25)+e|0)^(i=((i+=(e^(s=((s+=(i^t&(e^i))+o[13]-40341101)<<12|s>>>20)+t|0)&(t^e))+o[14]-1502002290)<<17|i>>>15)+s|0)&(s^t))+o[15]+1236535329)<<22|e>>>10)+i|0,e=((e+=((s=((s+=(e^i&((t=((t+=(i^s&(e^i))+o[1]-165796510)<<5|t>>>27)+e|0)^e))+o[6]-1069501632)<<9|s>>>23)+t|0)^t&((i=((i+=(t^e&(s^t))+o[11]+643717713)<<14|i>>>18)+s|0)^s))+o[0]-373897302)<<20|e>>>12)+i|0,e=((e+=((s=((s+=(e^i&((t=((t+=(i^s&(e^i))+o[5]-701558691)<<5|t>>>27)+e|0)^e))+o[10]+38016083)<<9|s>>>23)+t|0)^t&((i=((i+=(t^e&(s^t))+o[15]-660478335)<<14|i>>>18)+s|0)^s))+o[4]-405537848)<<20|e>>>12)+i|0,e=((e+=((s=((s+=(e^i&((t=((t+=(i^s&(e^i))+o[9]+568446438)<<5|t>>>27)+e|0)^e))+o[14]-1019803690)<<9|s>>>23)+t|0)^t&((i=((i+=(t^e&(s^t))+o[3]-187363961)<<14|i>>>18)+s|0)^s))+o[8]+1163531501)<<20|e>>>12)+i|0,e=((e+=((s=((s+=(e^i&((t=((t+=(i^s&(e^i))+o[13]-1444681467)<<5|t>>>27)+e|0)^e))+o[2]-51403784)<<9|s>>>23)+t|0)^t&((i=((i+=(t^e&(s^t))+o[7]+1735328473)<<14|i>>>18)+s|0)^s))+o[12]-1926607734)<<20|e>>>12)+i|0,e=((e+=((r=(s=((s+=((n=e^i)^(t=((t+=(n^s)+o[5]-378558)<<4|t>>>28)+e|0))+o[8]-2022574463)<<11|s>>>21)+t|0)^t)^(i=((i+=(r^e)+o[11]+1839030562)<<16|i>>>16)+s|0))+o[14]-35309556)<<23|e>>>9)+i|0,e=((e+=((r=(s=((s+=((n=e^i)^(t=((t+=(n^s)+o[1]-1530992060)<<4|t>>>28)+e|0))+o[4]+1272893353)<<11|s>>>21)+t|0)^t)^(i=((i+=(r^e)+o[7]-155497632)<<16|i>>>16)+s|0))+o[10]-1094730640)<<23|e>>>9)+i|0,e=((e+=((r=(s=((s+=((n=e^i)^(t=((t+=(n^s)+o[13]+681279174)<<4|t>>>28)+e|0))+o[0]-358537222)<<11|s>>>21)+t|0)^t)^(i=((i+=(r^e)+o[3]-722521979)<<16|i>>>16)+s|0))+o[6]+76029189)<<23|e>>>9)+i|0,e=((e+=((r=(s=((s+=((n=e^i)^(t=((t+=(n^s)+o[9]-640364487)<<4|t>>>28)+e|0))+o[12]-421815835)<<11|s>>>21)+t|0)^t)^(i=((i+=(r^e)+o[15]+530742520)<<16|i>>>16)+s|0))+o[2]-995338651)<<23|e>>>9)+i|0,e=((e+=((s=((s+=(e^((t=((t+=(i^(e|~s))+o[0]-198630844)<<6|t>>>26)+e|0)|~i))+o[7]+1126891415)<<10|s>>>22)+t|0)^((i=((i+=(t^(s|~e))+o[14]-1416354905)<<15|i>>>17)+s|0)|~t))+o[5]-57434055)<<21|e>>>11)+i|0,e=((e+=((s=((s+=(e^((t=((t+=(i^(e|~s))+o[12]+1700485571)<<6|t>>>26)+e|0)|~i))+o[3]-1894986606)<<10|s>>>22)+t|0)^((i=((i+=(t^(s|~e))+o[10]-1051523)<<15|i>>>17)+s|0)|~t))+o[1]-2054922799)<<21|e>>>11)+i|0,e=((e+=((s=((s+=(e^((t=((t+=(i^(e|~s))+o[8]+1873313359)<<6|t>>>26)+e|0)|~i))+o[15]-30611744)<<10|s>>>22)+t|0)^((i=((i+=(t^(s|~e))+o[6]-1560198380)<<15|i>>>17)+s|0)|~t))+o[13]+1309151649)<<21|e>>>11)+i|0,e=((e+=((s=((s+=(e^((t=((t+=(i^(e|~s))+o[4]-145523070)<<6|t>>>26)+e|0)|~i))+o[11]-1120210379)<<10|s>>>22)+t|0)^((i=((i+=(t^(s|~e))+o[2]+718787259)<<15|i>>>17)+s|0)|~t))+o[9]-343485551)<<21|e>>>11)+i|0,this.first?(this.h0=t+1732584193|0,this.h1=e-271733879|0,this.h2=i-1732584194|0,this.h3=s+271733878|0,this.first=!1):(this.h0=this.h0+t|0,this.h1=this.h1+e|0,this.h2=this.h2+i|0,this.h3=this.h3+s|0)},x.prototype.hex=function(){this.finalize();var t=this.h0,e=this.h1,i=this.h2,s=this.h3;return l[t>>>4&15]+l[15&t]+l[t>>>12&15]+l[t>>>8&15]+l[t>>>20&15]+l[t>>>16&15]+l[t>>>28&15]+l[t>>>24&15]+l[e>>>4&15]+l[15&e]+l[e>>>12&15]+l[e>>>8&15]+l[e>>>20&15]+l[e>>>16&15]+l[e>>>28&15]+l[e>>>24&15]+l[i>>>4&15]+l[15&i]+l[i>>>12&15]+l[i>>>8&15]+l[i>>>20&15]+l[i>>>16&15]+l[i>>>28&15]+l[i>>>24&15]+l[s>>>4&15]+l[15&s]+l[s>>>12&15]+l[s>>>8&15]+l[s>>>20&15]+l[s>>>16&15]+l[s>>>28&15]+l[s>>>24&15]},x.prototype.toString=x.prototype.hex,x.prototype.digest=function(){this.finalize();var t=this.h0,e=this.h1,i=this.h2,s=this.h3;return[255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&i,i>>>8&255,i>>>16&255,i>>>24&255,255&s,s>>>8&255,s>>>16&255,s>>>24&255]},x.prototype.array=x.prototype.digest,x.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(16),e=new Uint32Array(t);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,t},x.prototype.buffer=x.prototype.arrayBuffer,x.prototype.base64=function(){for(var t,e,i,s="",n=this.array(),r=0;r<15;)t=n[r++],e=n[r++],i=n[r++],s+=v[t>>>2]+v[63&(t<<4|e>>>4)]+v[63&(e<<2|i>>>6)]+v[63&i];return t=n[r],s+(v[t>>>2]+v[t<<4&63]+"==")},H.prototype=new x,H.prototype.finalize=function(){if(x.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();x.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(t),x.prototype.finalize.call(this)}};var L=function(){var t=A("hex");h&&(t=function(t){var s,n=i(644),o=i(333).Buffer;return s=o.from&&!r.JS_MD5_NO_BUFFER_FROM?o.from:function(t){return new o(t)},function(i){if("string"==typeof i)return n.createHash("md5").update(i,"utf8").digest("hex");if(null==i)throw new Error(e);return i.constructor===ArrayBuffer&&(i=new Uint8Array(i)),m(i)||b(i)||i.constructor===o?n.createHash("md5").update(s(i)).digest("hex"):t(i)}}(t)),t.create=function(){return new x},t.update=function(e){return t.create().update(e)};for(var s=0;s<y.length;++s){var n=y[s];t[n]=A(n)}return t}();L.md5=L,L.md5.hmac=function(){var t=E("hex");t.create=function(t){return new H(t)},t.update=function(e,i){return t.create(e).update(i)};for(var e=0;e<y.length;++e){var i=y[e];t[i]=E(i)}return t}(),d?t.exports=L:(r.md5=L,c&&(void 0===(s=function(){return L}.call(L,i,L,t))||(t.exports=s)))}()},644:()=>{}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}i.amdO={},i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var s={};return(()=>{"use strict";i.d(s,{default:()=>n});var t=i(569);class e{constructor(t,e={}){this.container="string"==typeof t?document.querySelector(t):t;const i={};[...this.container.attributes].forEach((t=>{let e=t.value;"true"===e?e=!0:"false"===e&&(e=!1),i[t.name.toLowerCase()]=e})),this.options=Object.assign({rows:3,cols:3,size:300,pointRadius:20,lineColor:"#2196F3",lineWidth:4,lineDash:[],correctpassword:null,onsuccess:null,onfail:null},i,e);const s=this.container.getAttribute("md5");this.md5Enabled=""===s||"true"===s||!0===s,this.successHandler=this._getHandler(this.options.onsuccess),this.failHandler=this._getHandler(this.options.onfail),this.points=[],this.selected=[],this.mouseDown=!1,this._init()}static enable(t){const i="string"==typeof t?document.querySelector(t):t;i&&!i._wiredInstance&&(i._wiredInstance=new e(i))}static disable(t){const e="string"==typeof t?document.querySelector(t):t;e&&e._wiredInstance&&(e._wiredInstance._destroy(),delete e._wiredInstance)}static boot(){document.querySelectorAll("[wired]").forEach((t=>{e.enable(t)}))}_getHandler(t){return"function"==typeof t?t:"string"==typeof t&&"function"==typeof window[t]?window[t]:()=>{}}_init(){const{size:t,rows:e,cols:i,pointRadius:s}=this.options;this._unbindEvents(),this.container.innerHTML="",this.container.classList.add("wired-container"),this.container.style.width=t+"px",this.container.style.height=t+"px",this.container.style.position="relative";const n=t/(Math.max(e,i)+1);this.points=[];for(let t=0;t<e;t++)for(let e=0;e<i;e++){const s=(e+1)*n,r=(t+1)*n,o=document.createElement("div");o.classList.add("wired-dot"),o.style.left=`${s}px`,o.style.top=`${r}px`,o.dataset.index=t*i+e,this.container.appendChild(o),this.points.push({x:s,y:r,el:o,index:t*i+e})}this._svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._svg.setAttribute("width",t),this._svg.setAttribute("height",t),this._svg.classList.add("wired-svg"),this.container.appendChild(this._svg),this._startHandler=this._start.bind(this),this._moveHandler=this._move.bind(this),this._endHandler=this._end.bind(this),this.container.addEventListener("mousedown",this._startHandler),this.container.addEventListener("mousemove",this._moveHandler),this.container.addEventListener("mouseup",this._endHandler),this.container.addEventListener("touchstart",this._startHandler,{passive:!1}),this.container.addEventListener("touchmove",this._moveHandler,{passive:!1}),this.container.addEventListener("touchend",this._endHandler,{passive:!1})}_unbindEvents(){this._startHandler&&(this.container.removeEventListener("mousedown",this._startHandler),this.container.removeEventListener("mousemove",this._moveHandler),this.container.removeEventListener("mouseup",this._endHandler),this.container.removeEventListener("touchstart",this._startHandler),this.container.removeEventListener("touchmove",this._moveHandler),this.container.removeEventListener("touchend",this._endHandler))}_start(t){t.preventDefault(),this.mouseDown=!0,this.selected=[],this._handleInput(t)}_move(t){this.mouseDown&&this._handleInput(t)}_end(){this.mouseDown=!1,this._render();let e=this.selected.map((t=>t.index)).join("");this.md5Enabled&&(e=(0,t.md5)(e));const i=this.options.correctpassword,s={detail:e};null!==i&&(e===i?(this.successHandler(e),this.container.dispatchEvent(new CustomEvent("unlock-success",s))):(this.failHandler(e),this.container.dispatchEvent(new CustomEvent("unlock-fail",s)))),this._resetAfterDelay()}_handleInput(t){const e=this.container.getBoundingClientRect(),i=(t.touches?t.touches[0].clientX:t.clientX)-e.left,s=(t.touches?t.touches[0].clientY:t.clientY)-e.top,n=this.options.pointRadius;for(const t of this.points)if(!this.selected.includes(t)&&Math.hypot(t.x-i,t.y-s)<n){this.selected.push(t);break}this._render(i,s)}_render(t,e){if(this.points.forEach((t=>t.el.classList.toggle("wired-dot-selected",this.selected.includes(t)))),this._svg.innerHTML="",0===this.selected.length)return;const i=document.createElementNS("http://www.w3.org/2000/svg","polyline"),s=this.selected.map((t=>[t.x,t.y]));if(this.mouseDown&&void 0!==t&&void 0!==e&&this.selected.length>0){const i=this.selected[this.selected.length-1],n=t-i.x,r=e-i.y;Math.hypot(n,r)>this.options.pointRadius&&s.push([t,e])}const n=s.map((t=>`${t[0]},${t[1]}`)).join(" ");i.setAttribute("points",n),i.setAttribute("fill","none"),i.setAttribute("stroke",this.options.lineColor),i.setAttribute("stroke-width",this.options.lineWidth),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),this.options.lineDash.length>0&&i.setAttribute("stroke-dasharray",this.options.lineDash.join(",")),this._svg.appendChild(i)}_resetAfterDelay(){setTimeout((()=>{this.selected=[],this._render()}),500)}_destroy(){this._unbindEvents(),this.container.innerHTML="",this.container.classList.remove("wired-container")}}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>e.boot())):e.boot();const n=e})(),s.default})()));