manual-data-masking
Version:
A super light javascript library for manual data masking
1 lines • 16.6 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.manualDataMasking=e():t.manualDataMasking=e()}(self,(function(){return function(){"use strict";var t={814:function(t){t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n=t(e);return e[2]?"@media ".concat(e[2]," {").concat(n,"}"):n})).join("")},e.i=function(t,n,a){"string"==typeof t&&(t=[[null,t,""]]);var r={};if(a)for(var o=0;o<this.length;o++){var i=this[o][0];null!=i&&(r[i]=!0)}for(var s=0;s<t.length;s++){var c=[].concat(t[s]);a&&r[c[0]]||(n&&(c[2]?c[2]="".concat(n," and ").concat(c[2]):c[2]=n),e.push(c))}},e}},539:function(t,e,n){var a=n(814),r=n.n(a)()((function(t){return t[1]}));r.push([t.id,".easy_data_masking{box-shadow:0 2px 3px rgba(10,10,10,.1),0 0 0 1px rgba(10,10,10,.1)}.easy_data_masking_head{padding:10px 10px 5px 10px;border-bottom:1px solid #dedede}.easy_data_masking_head .category{display:inline-block;margin-right:10px;margin-bottom:5px;border:2px solid;cursor:pointer}.easy_data_masking_head .category .category_value{padding:0px 2px 2px 2px}.easy_data_masking_head .category .category_keypress{padding:0px 2px 2px 2px;border-left:2px solid}.easy_data_masking_body{overflow:auto;word-break:break-word;line-height:2;padding:10px 10px 10px 7px}.easy_data_masking_body .text-indent{padding-left:2em}.easy_data_masking_body .masking{margin:0px 3px;line-height:1.3;border:2px solid;box-shadow:2px 4px 20px rgba(0,0,0,.1);display:inline-block;position:relative}.easy_data_masking_body .masking:hover .masking_delete{display:block}.easy_data_masking_body .masking .masking_content{cursor:pointer;float:left;height:20px;padding:0px 2px 0px;overflow:hidden}.easy_data_masking_body .masking .masking_content_top,.easy_data_masking_body .masking .masking_content_bottom{text-align:center;width:100%;height:100%;line-height:20px;transition:margin-top .3s}.easy_data_masking_body .masking .masking_content:hover .masking_content_top{margin-top:-20px}.easy_data_masking_body .masking .category{display:inline-block;height:1.3rem;padding-left:2px}.easy_data_masking_body .masking .masking_delete{font-size:16px;color:#fff;top:-9px;left:-9px;position:absolute;text-align:center;display:none;border-radius:50%;line-height:1;padding:0px;width:16px;height:16px;background-color:rgba(0,0,0,.54);border:none}.easy_data_masking_body .masking .masking_delete:hover{cursor:pointer}",""]),e.Z=r},379:function(t,e,n){var a,r=function(){var t={};return function(e){if(void 0===t[e]){var n=document.querySelector(e);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(t){n=null}t[e]=n}return t[e]}}(),o=[];function i(t){for(var e=-1,n=0;n<o.length;n++)if(o[n].identifier===t){e=n;break}return e}function s(t,e){for(var n={},a=[],r=0;r<t.length;r++){var s=t[r],c=e.base?s[0]+e.base:s[0],l=n[c]||0,u="".concat(c," ").concat(l);n[c]=l+1;var d=i(u),p={css:s[1],media:s[2],sourceMap:s[3]};-1!==d?(o[d].references++,o[d].updater(p)):o.push({identifier:u,updater:y(p,e),references:1}),a.push(u)}return a}function c(t){var e=document.createElement("style"),a=t.attributes||{};if(void 0===a.nonce){var o=n.nc;o&&(a.nonce=o)}if(Object.keys(a).forEach((function(t){e.setAttribute(t,a[t])})),"function"==typeof t.insert)t.insert(e);else{var i=r(t.insert||"head");if(!i)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");i.appendChild(e)}return e}var l,u=(l=[],function(t,e){return l[t]=e,l.filter(Boolean).join("\n")});function d(t,e,n,a){var r=n?"":a.media?"@media ".concat(a.media," {").concat(a.css,"}"):a.css;if(t.styleSheet)t.styleSheet.cssText=u(e,r);else{var o=document.createTextNode(r),i=t.childNodes;i[e]&&t.removeChild(i[e]),i.length?t.insertBefore(o,i[e]):t.appendChild(o)}}function p(t,e,n){var a=n.css,r=n.media,o=n.sourceMap;if(r?t.setAttribute("media",r):t.removeAttribute("media"),o&&"undefined"!=typeof btoa&&(a+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),t.styleSheet)t.styleSheet.cssText=a;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(a))}}var f=null,h=0;function y(t,e){var n,a,r;if(e.singleton){var o=h++;n=f||(f=c(e)),a=d.bind(null,n,o,!1),r=d.bind(null,n,o,!0)}else n=c(e),a=p.bind(null,n,e),r=function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(n)};return a(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;a(t=e)}else r()}}t.exports=function(t,e){(e=e||{}).singleton||"boolean"==typeof e.singleton||(e.singleton=(void 0===a&&(a=Boolean(window&&document&&document.all&&!window.atob)),a));var n=s(t=t||[],e);return function(t){if(t=t||[],"[object Array]"===Object.prototype.toString.call(t)){for(var a=0;a<n.length;a++){var r=i(n[a]);o[r].references--}for(var c=s(t,e),l=0;l<n.length;l++){var u=i(n[l]);0===o[u].references&&(o[u].updater(),o.splice(u,1))}n=c}}}}},e={};function n(a){if(e[a])return e[a].exports;var r=e[a]={id:a,exports:{}};return t[a](r,r.exports,n),r.exports}n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,{a:e}),e},n.d=function(t,e){for(var a in e)n.o(e,a)&&!n.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var a={};return function(){n.r(a),n.d(a,{create:function(){return F}});var t=n(379),e=n.n(t),r=n(539);function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);e&&(a=a.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,a)}return n}function s(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach((function(e){d(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function c(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=l(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var a=0,r=function(){};return{s:r,n:function(){return a>=t.length?{done:!0}:{done:!1,value:t[a++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,s=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return i=t.done,t},e:function(t){s=!0,o=t},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw o}}}}function l(t,e){if(t){if("string"==typeof t)return u(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,e):void 0}}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,a=new Array(e);n<e;n++)a[n]=t[n];return a}function d(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function p(t,e,n){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return n}function f(t,e,n){var a=e.get(t);if(!a)throw new TypeError("attempted to set private field on non-instance");if(a.set)a.set.call(t,n);else{if(!a.writable)throw new TypeError("attempted to set read only private field");a.value=n}return n}function h(t,e){var n=e.get(t);if(!n)throw new TypeError("attempted to get private field on non-instance");return n.get?n.get.call(t):n.value}e()(r.Z,{insert:"head",singleton:!1}),r.Z.locals;var y=new WeakMap,g=new WeakMap,v=new WeakMap,b=new WeakMap,m=new WeakMap,w=new WeakMap,k=new WeakMap,_=new WeakMap,x=new WeakMap,M=new WeakMap,j=new WeakMap,S=new WeakMap,O=new WeakMap,E=new WeakMap,T=new WeakMap,W=new WeakMap,A=new WeakMap,C=new WeakMap,P=new WeakSet,D=new WeakMap,I=new WeakMap,L=new WeakMap,N=new WeakMap,H=new WeakMap,B=new WeakMap,R=new WeakMap,U=function t(e){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),P.add(this),y.set(this,{writable:!0,value:void 0}),g.set(this,{writable:!0,value:void 0}),v.set(this,{writable:!0,value:void 0}),b.set(this,{writable:!0,value:void 0}),m.set(this,{writable:!0,value:void 0}),w.set(this,{writable:!0,value:void 0}),k.set(this,{writable:!0,value:void 0}),_.set(this,{writable:!0,value:void 0}),x.set(this,{writable:!0,value:void 0}),M.set(this,{writable:!0,value:void 0}),j.set(this,{writable:!0,value:{}}),S.set(this,{writable:!0,value:{maxHeight:null,dataMasked:[],replaceCharactor:"*",dataMaskingCharactor:"●"}}),O.set(this,{writable:!0,value:"#577eba"}),E.set(this,{writable:!0,value:function(t){t.forEach((function(t){t.color||(t.color=h(n,O))}))}}),T.set(this,{writable:!0,value:function(t){t=t.slice().sort((function(t,e){return t.start-e.start})),f(n,w,t);var e,a=[],r=c(t);try{for(r.s();!(e=r.n()).done;){var o=e.value,i=s(s({},o),{},{color:h(n,N).call(n,o.category)});a=a.concat(i)}}catch(t){r.e(t)}finally{r.f()}return a}}),W.set(this,{writable:!0,value:function(t){var e,n=[],a=t.split("\n"),r=c(a.slice(0,-1));try{for(r.s();!(e=r.n()).done;){var o=e.value;n.push({type:"text",content:o,category:null,color:null}),n.push({type:"wrap",content:"↵",category:null,color:null})}}catch(t){r.e(t)}finally{r.f()}return n.push({type:"text",category:null,color:null,content:a.slice(-1)[0]}),n}}),A.set(this,{writable:!0,value:function(t,e){var a,r=[],o=0,i=t.split(""),s=c(e);try{for(s.s();!(a=s.n()).done;){var l=a.value,u=i.slice(o,l.start).join("");r=r.concat(h(n,W).call(n,u)),o=l.end,u=i.slice(l.start,l.end).join(""),r.push({type:"masking",content:u,start:l.start,category:l.category,color:l.color})}}catch(t){s.e(t)}finally{s.f()}return r.concat(h(n,W).call(n,i.slice(o,i.length).join("")))}}),C.set(this,{writable:!0,value:function(t,e){var a,r="",o=c(e);try{for(o.s();!(a=o.n()).done;){var i=a.value,s="";s+='<span class="category_value" style="background-color: '.concat(i.color,"; color: ").concat(h(n,L).call(n,i.color),'">').concat(i.value,"</span>"),i.keypress&&(s+='<span class="category_keypress" style="border-color: '.concat(i.color,'">').concat(i.keypress,"</span>")),r+='<span data-category="'.concat(i.value,'" class="category" style="border-color: ').concat(i.color,'">').concat(s,"</span>")}}catch(t){o.e(t)}finally{o.f()}r='<div class="easy_data_masking_head">'.concat(r,"</div>");var u,d,f,y="",g=c(t.entries());try{for(g.s();!(u=g.n()).done;){var v=(d=u.value,f=2,function(t){if(Array.isArray(t))return t}(d)||function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var n=[],a=!0,r=!1,o=void 0;try{for(var i,s=t[Symbol.iterator]();!(a=(i=s.next()).done)&&(n.push(i.value),!e||n.length!==e);a=!0);}catch(t){r=!0,o=t}finally{try{a||null==s.return||s.return()}finally{if(r)throw o}}return n}}(d,f)||l(d,f)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),m=v[0],w=v[1];"text"==w.type&&(y+="".concat(p(n,P,Z).call(n,m,t)?'<span class="text-indent">':"<span>").concat(w.content,"</span>")),"wrap"==w.type&&(y+="<br/>"),"masking"==w.type&&(y+='<span class="masking" style="border-color: '.concat(w.color,';">\n <button class="masking_delete" data-maskingStart="').concat(w.start,'">x\n </button> \n <span class="masking_content">\n <div class="masking_content_top">\n ').concat(h(n,x).repeat(w.content.length),'\n </div>\n <div class="masking_content_bottom">\n ').concat(w.content,'\n </div>\n </span>\n <span class="category"\n style="background-color: ').concat(w.color,"; color: ").concat(h(n,L).call(n,w.color),';">\n ').concat(w.category,"\n </span>\n </span>"))}}catch(t){g.e(t)}finally{g.f()}return y='<div class="easy_data_masking_body"\n id="easy_data_masking_body"\n style="'.concat(h(n,b)?"max-height: ".concat(h(n,b),"px"):"",'">\n ').concat(y,"\n </div>"),'<div class="easy_data_masking">'.concat(r).concat(y,"</div>")}}),D.set(this,{writable:!0,value:function(t){h(n,v).innerHTML=t}}),I.set(this,{writable:!0,value:function(t,e,a){var r=h(n,T).call(n,t);f(n,g,h(n,A).call(n,a,r));var o=h(n,C).call(n,h(n,g),e);h(n,D).call(n,o);var i=h(n,j).afterDataMasking;"function"==typeof i&&i(n.getDataMasked(),n.getTextAfterDataMasking())}}),L.set(this,{writable:!0,value:function(t){return"#"===t.slice(0,1)&&(t=t.slice(1)),(299*parseInt(t.substr(0,2),16)+587*parseInt(t.substr(2,2),16)+114*parseInt(t.substr(4,2),16))/1e3>=128?"black":"white"}}),N.set(this,{writable:!0,value:function(t){return h(n,m).find((function(e){return e.value===t})).color}}),H.set(this,{writable:!0,value:function(t){for(var e=h(n,g).findIndex((function(e){return e.content===t})),a=0,r=0;r<e;r++)a+=h(n,g)[r].content.length;return a}}),B.set(this,{writable:!0,value:function(){h(n,v).addEventListener("click",(function(t){var e=(t=t||window.event).target||t.srcElement;if(e.classList.contains("masking_delete")){var a=e.getAttribute("data-maskingStart");f(n,w,h(n,w).filter((function(t){return t.start!=a}))),h(n,I).call(n,h(n,w),h(n,m),h(n,y))}})),h(n,v).addEventListener("mousedown",(function(t){var e=(t=t||window.event).target||t.srcElement;if(e.parentNode&&e.parentNode.classList.contains("category")){var a=e.parentNode.getAttribute("data-category");h(n,k)&&""!=h(n,k)&&a&&(h(n,w).push({content:h(n,k),category:a,start:h(n,M),end:h(n,M)+h(n,k).length}),h(n,I).call(n,h(n,w),h(n,m),h(n,y)))}})),document.addEventListener("mouseup",(function(){var t=window.getSelection?window.getSelection():document.selection.createRange().text,e=t.anchorOffset,a=t.focusOffset,r=t.anchorNode.data;t=(t+="").replace(/^\s+|\s+$/g,""),f(n,k,t.trim().length?t:null),f(n,M,h(n,H).call(n,r)+Math.min(e,a))})),document.addEventListener("keyup",(function(t){var e=t.key,a=h(n,m).find((function(t){return t.keypress===e}));h(n,k)&&""!=h(n,k)&&a&&(h(n,w).push({content:h(n,k),category:a.value,start:h(n,M),end:h(n,M)+h(n,k).length}),h(n,I).call(n,h(n,w),h(n,m),h(n,y)))}),!1)}}),R.set(this,{writable:!0,value:function(t,e,n){return t.substr(0,e)+n+t.substr(e+n.length)}}),d(this,"getDataMasked",(function(){return h(n,w)})),d(this,"getTextAfterDataMasking",(function(){var t=h(n,y);return h(n,w).forEach((function(e){t=h(n,R).call(n,t,e.start,h(n,_).repeat(e.content.length))})),t})),d(this,"on",(function(t,e){h(n,j)[t]=e}));var a=e=Object.assign({},h(this,S),e),r=a.container,i=a.text,u=a.categories,U=a.replaceCharactor,F=a.dataMaskingCharactor,$=a.dataMasked,q=a.maxHeight;if("string"!=typeof i||0===i.length)throw new Error("Type or value of the text option is wrong");if(!(u instanceof Array)||0===u.length)throw new Error("Type or value of the categories option is wrong");if(!($ instanceof Array))throw new Error("Type of the dataMasked option is wrong");if("object"!==o(r))throw new Error("Type of the container option is wrong");if("string"!=typeof U||0===U.length)throw new Error("Type or value of the replaceCharactor option is wrong");if("string"!=typeof F||0===F.length)throw new Error("Type or value of the dataMaskingCharactor option is wrong");if("number"!=typeof q&&null!==q)throw new Error("Type of the maxHeight option is wrong");f(this,v,r),f(this,y,i),f(this,m,u),f(this,w,$),f(this,b,q),f(this,k,null),f(this,_,U),f(this,x,F),h(this,E).call(this,h(this,m)),h(this,I).call(this,h(this,w),h(this,m),h(this,y)),h(this,B).call(this)},Z=function(t,e){return 0===t||"wrap"===e[t-1].type};function F(t){return new U(t)}}(),a}()}));