UNPKG

@striven-erp/striven-tooltip

Version:
1 lines 11.1 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.striventooltip=e():t.striventooltip=e()}(window,(function(){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,o),i.l=!0,i.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)o.d(n,i,function(e){return t[e]}.bind(null,i));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e,o){var n=o(2),i=o(3);"string"==typeof(i=i.__esModule?i.default:i)&&(i=[[t.i,i,""]]);var r={insert:"head",singleton:!1},s=(n(t.i,i,r),i.locals?i.locals:{});t.exports=s},function(t,e,o){var n,i,r;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self&&self,i=[e,o(0)],void 0===(r="function"==typeof(n=function(t,e){"use strict";function o(t,e){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),o.push.apply(o,n)}return o}function n(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?o(Object(n),!0).forEach((function(e){i(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function i(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var c={viewBox:"0 0 1792 1792",d:"M1152 1376v-160q0-14-9-23t-23-9h-96v-512q0-14-9-23t-23-9h-320q-14 0-23 9t-9 23v160q0 14 9 23t23 9h96v320h-96q-14 0-23 9t-9 23v160q0 14 9 23t23 9h448q14 0 23-9t9-23zm-128-896v-160q0-14-9-23t-23-9h-192q-14 0-23 9t-9 23v160q0 14 9 23t23 9h192q14 0 23-9t9-23zm640 416q0 209-103 385.5t-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103 385.5 103 279.5 279.5 103 385.5z"},a=function(){function t(e,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};r(this,t);var s={direction:"South"};this.el=o,this.tip=e,this.config=n({},s,{},i),this.config.icon&&this.initIcon(),this.initTooltip();var c=this;this.el.StrivenTooltip=function(){return c}}var e,o,i;return e=t,(o=[{key:"initTooltip",value:function(){var t=this,e=document.createElement("div");e.classList.add("s-tooltip");var o=document.createElement("div");o.classList.add("s-tooltip-stem"),this.stem=o;var n=document.createElement("p");n.classList.add("s-tooltip-content"),n.textContent=this.tip,this.content=n,e.append(o),e.append(n),this.tooltip=e,this.el.style.position="relative",this.el.onmouseenter=function(){t.el.append(e),setTimeout((function(){t.inView(t.tooltip)?t.setDirection(t.config.direction):t.correctPosition(),t.showTooltip(),t.config.onShow&&t.config.onShow()}),0)},this.el.onmouseleave=function(){t.hideTooltip(),t.tooltip.setAttribute("style",null),t.stem.setAttribute("style",null),e.remove(),setTimeout((function(){return t.config.onHide&&t.config.onHide()}),0)},this.config.onInit&&this.config.onInit(this.el)}},{key:"initIcon",value:function(){var t=this.constructSVG(c);t.setAttribute("style","cursor: pointer"),t.onmouseenter=function(){return t.getElementsByTagName("path")[0].setAttribute("fill","#2a6496")},t.onmouseleave=function(){return t.getElementsByTagName("path")[0].setAttribute("fill","#428bca")},this.el.style.height="16px",this.el.style.width="16px",this.el.append(t)}},{key:"constructSVG",value:function(t){var e=t.viewBox,o=t.d,n=document.createElement("span"),i='<svg width="'.concat("16",'" height="').concat("16",'" viewBox="').concat(e,'" xmlns="').concat("http://www.w3.org/2000/svg",'">'),r='<path fill="'.concat("#428bca",'" d="').concat(o,'"/>');return n.innerHTML="".concat(i).concat(r,"</svg>"),n}},{key:"inView",value:function(t){var e=t.getBoundingClientRect(),o=e.left,n=e.right;return!(o-t.offsetWidth/2<0||n>window.innerWidth)}},{key:"setTip",value:function(t){this.tip=t,this.content.textContent=t}},{key:"showTooltip",value:function(){this.tooltip.classList.add("s-tooltip-show")}},{key:"hideTooltip",value:function(){this.tooltip.classList.remove("s-tooltip-show")}},{key:"correctPosition",value:function(){var t=this.tooltip.getBoundingClientRect(),e=t.left,o=t.right;return e-this.tooltip.offsetWidth/2<0?(this.setDirection("East"),!0):o>window.innerWidth?(this.setDirection("West"),!0):void 0}},{key:"setDirection",value:function(t){switch(t){case"East":this.tooltip.style.left="".concat(this.el.offsetWidth+5,"px"),this.tooltip.style.top="50%",this.tooltip.style.marginTop="-".concat(this.tooltip.offsetHeight/2,"px"),this.stem.style.left="-5px",this.stem.style.transform="translateY(".concat(this.tooltip.offsetHeight/2-15,"px) rotate(45deg)"),this.stem.style.borderBottom="1px solid #acacac",this.stem.style.borderLeft="1px solid #acacac";break;case"West":this.tooltip.style.right="".concat(this.el.offsetWidth+5,"px"),this.tooltip.style.top="50%",this.tooltip.style.marginTop="-".concat(this.tooltip.offsetHeight/2,"px"),this.stem.style.right="-5px",this.stem.style.transform="translateY(".concat(this.tooltip.offsetHeight/2-15,"px) rotate(45deg)"),this.stem.style.borderTop="1px solid #acacac",this.stem.style.borderRight="1px solid #acacac";break;case"North":this.tooltip.style.right="50%",this.tooltip.style.marginRight="-".concat(this.tooltip.offsetWidth/2,"px"),this.tooltip.style.top="-".concat(this.tooltip.offsetHeight,"px"),this.stem.style.transform="translateY(".concat(this.tooltip.offsetHeight-this.stem.offsetHeight-5,"px) rotate(45deg)"),this.stem.style.right="50%",this.stem.style.marginRight="-5px",this.stem.style.borderBottom="1px solid #acacac",this.stem.style.borderRight="1px solid #acacac";break;case"South":default:this.tooltip.style.top="".concat(this.el.offsetHeight+5,"px"),this.tooltip.style.left="50%",this.tooltip.style.bottom="0px",this.tooltip.style.marginLeft="-".concat(this.tooltip.offsetWidth/2,"px"),this.stem.style.transform="translateY(-145%) rotate(45deg)",this.stem.style.left="50%",this.stem.style.marginLeft="-5px",this.stem.style.borderTop="1px solid #acacac",this.stem.style.borderLeft="1px solid #acacac"}}}])&&s(e.prototype,o),i&&s(e,i),t}();t.default=a})?n.apply(e,i):n)||(t.exports=r)},function(t,e,o){"use strict";var n,i=function(){return void 0===n&&(n=Boolean(window&&document&&document.all&&!window.atob)),n},r=function(){var t={};return function(e){if(void 0===t[e]){var o=document.querySelector(e);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(t){o=null}t[e]=o}return t[e]}}(),s={};function c(t,e,o){for(var n=0;n<e.length;n++){var i={css:e[n][1],media:e[n][2],sourceMap:e[n][3]};s[t][n]?s[t][n](i):s[t].push(y(i,o))}}function a(t){var e=document.createElement("style"),n=t.attributes||{};if(void 0===n.nonce){var i=o.nc;i&&(n.nonce=i)}if(Object.keys(n).forEach((function(t){e.setAttribute(t,n[t])})),"function"==typeof t.insert)t.insert(e);else{var s=r(t.insert||"head");if(!s)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");s.appendChild(e)}return e}var l,u=(l=[],function(t,e){return l[t]=e,l.filter(Boolean).join("\n")});function f(t,e,o,n){var i=o?"":n.css;if(t.styleSheet)t.styleSheet.cssText=u(e,i);else{var r=document.createTextNode(i),s=t.childNodes;s[e]&&t.removeChild(s[e]),s.length?t.insertBefore(r,s[e]):t.appendChild(r)}}function p(t,e,o){var n=o.css,i=o.media,r=o.sourceMap;if(i?t.setAttribute("media",i):t.removeAttribute("media"),r&&btoa&&(n+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}var h=null,d=0;function y(t,e){var o,n,i;if(e.singleton){var r=d++;o=h||(h=a(e)),n=f.bind(null,o,r,!1),i=f.bind(null,o,r,!0)}else o=a(e),n=p.bind(null,o,e),i=function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(o)};return n(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;n(t=e)}else i()}}t.exports=function(t,e,o){return(o=o||{}).singleton||"boolean"==typeof o.singleton||(o.singleton=i()),t=o.base?t+o.base:t,e=e||[],s[t]||(s[t]=[]),c(t,e,o),function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){s[t]||(s[t]=[]),c(t,e,o);for(var n=e.length;n<s[t].length;n++)s[t][n]();s[t].length=e.length,0===s[t].length&&delete s[t]}}}},function(t,e,o){(e=o(4)(!1)).push([t.i,".s-tooltip {\n font-family: 'Segoe UI';\n background-color: #fff;\n color: #000;\n line-height: 1.4;\n font-size: 14px;\n border: 1px solid rgba(0, 0, 0, 0.2);\n position: absolute;\n box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);\n opacity: 0;\n transition: opacity 500ms;\n height: fit-content;\n width: fit-content;\n padding: 10px;\n z-index: 1;\n text-align: center;\n}\n\n.s-tooltip-show {\n opacity: 1;\n}\n\n.s-tooltip-stem {\n position: absolute;\n background-color: #fff;\n height: 11px;\n width: 10px;\n}\n\n.s-tooltip-content {\n min-width: 250px;\n user-select: none;\n text-decoration: center;\n font-weight: normal;\n}\n",""]),t.exports=e},function(t,e,o){"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var o=function(t,e){var o=t[1]||"",n=t[3];if(!n)return o;if(e&&"function"==typeof btoa){var i=(s=n,c=btoa(unescape(encodeURIComponent(JSON.stringify(s)))),a="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(c),"/*# ".concat(a," */")),r=n.sources.map((function(t){return"/*# sourceURL=".concat(n.sourceRoot||"").concat(t," */")}));return[o].concat(r).concat([i]).join("\n")}var s,c,a;return[o].join("\n")}(e,t);return e[2]?"@media ".concat(e[2]," {").concat(o,"}"):o})).join("")},e.i=function(t,o){"string"==typeof t&&(t=[[null,t,""]]);for(var n=0;n<t.length;n++){var i=[].concat(t[n]);o&&(i[2]?i[2]="".concat(o," and ").concat(i[2]):i[2]=o),e.push(i)}},e}}])}));