@nuralyui/tooltips 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. package/bundle.js +123 -1
  2. package/package.json +1 -1
package/bundle.js CHANGED
@@ -1 +1,123 @@
1
- import{css as t,LitElement as i,html as o,nothing as s}from"lit";import{property as n,state as e,customElement as h}from"lit/decorators.js";const r=[t`:host([show]){background-color:var(--nuraly-tooltip-background-color);color:var(--nuraly-tooltip-text-color);position:fixed;padding:5px;text-align:center;opacity:0;font-size:14px;z-index:9999;border-radius:4px;animation-name:show-animation;animation-duration:.4s;animation-fill-mode:forwards}.popconfirm-container{display:flex;flex-direction:column}.btn-block{display:flex;justify-content:end;gap:10px;margin:10px}.popconfirm-description,.popconfirm-title{margin:5px;text-align:left}.popconfirm-title{font-weight:700}@keyframes show-animation{from{opacity:0}to{opacity:1}}:host::after{content:'';height:0;width:0;position:absolute;border:5px solid transparent}:host(.top-position)::after{border-top-color:var(--nuraly-tooltip-background-color);top:100%}:host(.left-position)::after{border-left-color:var(--nuraly-tooltip-background-color);left:100%}:host(.right-position)::after{border-right-color:var(--nuraly-tooltip-background-color);right:100%}:host(.bottom-position)::after{border-bottom-color:var(--nuraly-tooltip-background-color);bottom:100%}:host(.alignement-center.bottom-position)::after,:host(.alignement-center.top-position)::after{right:50%;transform:translate(50%)}:host(.alignement-start.bottom-position)::after,:host(.alignement-start.top-position)::after{left:4%}:host(.alignement-end.bottom-position)::after,:host(.top-position.alignement-end)::after{right:4%}:host(.alignement-center.left-position)::after,:host(.alignement-center.right-position)::after{top:50%;transform:translate(0,-50%)}:host(.alignement-start.left-position)::after,:host(.alignement-start.right-position)::after{top:5px}:host(.alignement-end.left-position)::after,:host(.alignement-end.right-position)::after{bottom:5px}`,t`:host{--nuraly-tooltip-background-color:#393939;--nuraly-tooltip-text-color:#ffffff}@media (prefers-color-scheme:dark){:host{--nuraly-tooltip-background-color:#f4f4f4;--nuraly-tooltip-text-color:#161616}}`];var a,l;!function(t){t.Top="top",t.Bottom="bottom",t.Right="right",t.Left="left"}(a||(a={})),function(t){t.Start="start",t.Center="center",t.End="end"}(l||(l={}));var p=function(t,i,o,s){for(var n,e=arguments.length,h=e<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,o):s,r=t.length-1;r>=0;r--)(n=t[r])&&(h=(e<3?n(h):e>3?n(i,o,h):n(i,o))||h);return e>3&&h&&Object.defineProperty(i,o,h),h};let c=class extends i{constructor(){super(...arguments),this.position=a.Bottom,this.alignement=l.Center,this.show=!1,this.isPopConfirm=!1,this.popConfirmTitle="",this.popConfirmDescription="",this.okText="Yes",this.cancelText="No",this.horizontalOffset=10,this.verticalOffset=10,this.onMouseOver=()=>{this.show=!0},this.onMouseLeave=()=>{this.show=!1,this.initStyles()},this.onClick=()=>{this.show=!this.show},this.calculatePosition=()=>{this.initStyles(),this.style.width=`${this.clientWidth}px`,this.position==a.Bottom||this.position==a.Top?(this.calculateYposition(),this.calculateYalignement()):(this.calculateXposition(),this.calculateXalignement())},this.calculateYposition=()=>{const t=this.target.getBoundingClientRect(),i=t.bottom,o=t.top,s=window.visualViewport.height,n=this.clientHeight,e=n+this.verticalOffset<s-i,h=n+this.verticalOffset<o;this.position==a.Bottom?e||!h?(this.classList.add("bottom-position"),this.style.top=`${i+this.verticalOffset}px`):(this.classList.add("top-position"),this.style.top=o-n-this.verticalOffset+"px"):h||!e?(this.classList.add("top-position"),this.style.top=o-n-this.verticalOffset+"px"):(this.classList.add("bottom-position"),this.style.top=`${i+this.verticalOffset}px`)},this.calculateYalignement=()=>{const t=this.target.getBoundingClientRect(),i=t.right,o=t.width,s=t.left,n=this.clientWidth,e=s+o/2,h=window.visualViewport.width,r=h-i+o/2;if(this.alignement==l.Start){n+s<h?(this.classList.add("alignement-start"),this.style.left=s-this.horizontalOffset+"px"):(this.classList.add("alignement-end"),this.style.left=`${s-n+this.horizontalOffset}px`)}else if(this.alignement==l.End){n<s?(this.classList.add("alignement-end"),this.style.left=`${s-n+this.horizontalOffset}px`):(this.classList.add("alignement-start"),this.style.left=s-this.horizontalOffset+"px")}else{const t=n<e;n/2<e&&n/2<r||n>e&&n>r?(this.classList.add("alignement-center"),this.style.left=s-n/2+o/2+"px"):t?(this.classList.add("alignement-end"),this.style.left=`${s-n+this.horizontalOffset}px`):(this.classList.add("alignement-start"),this.style.left=s-this.horizontalOffset+"px")}},this.calculateXposition=()=>{const t=this.target.getBoundingClientRect(),i=t.left,o=t.right,s=window.visualViewport.width,n=this.clientWidth,e=n+this.horizontalOffset<s-o,h=n+this.horizontalOffset<i;this.position==a.Right?e||!h?(this.classList.add("right-position"),this.style.left=`${o+this.horizontalOffset}px`):(this.classList.add("left-position"),this.style.left=i-n-this.horizontalOffset+"px"):h||!e?(this.classList.add("left-position"),this.style.left=i-n-this.horizontalOffset+"px"):(this.classList.add("right-position"),this.style.left=`${o+this.horizontalOffset}px`)},this.calculateXalignement=()=>{const t=this.target.getBoundingClientRect(),i=t.top,o=t.height,s=t.bottom,n=this.clientHeight,e=window.visualViewport.height,h=e-s;if(this.alignement==l.End){n<i?(this.classList.add("alignement-end"),this.style.top=s-n+"px"):(this.classList.add("alignement-start"),this.style.top=i-o/4+"px")}else if(this.alignement==l.Start){n<e-s?(this.classList.add("alignement-start"),this.style.top=i-o/4+"px"):(this.classList.add("alignement-end"),this.style.top=s-n+"px")}else{const t=n<i;n/2<i&&n/2<h||n>i&&n>h?(this.classList.add("alignement-center"),this.style.top=i+o/2-n/2+"px"):t?(this.classList.add("alignement-end"),this.style.top=s-n+"px"):(this.classList.add("alignement-start"),this.style.top=i-o/4+"px")}},this.onClickOutside=t=>{const i=t.composedPath();!i.includes(this.target)&&!i.includes(this)&&(this.show=!1)}}connectedCallback(){super.connectedCallback(),this.target=this.target||this.previousElementSibling,this.target?this.isPopConfirm?(document.addEventListener("scroll",this.calculatePosition),this.target.addEventListener("click",this.onClick),document.addEventListener("click",this.onClickOutside)):(this.target.addEventListener("mouseover",this.onMouseOver),this.target.addEventListener("mouseleave",this.onMouseLeave)):console.error("Tooltip target is not defined or found. Ensure target is explicitly set or precedes the tooltip.")}initStyles(){this.style.top="",this.style.left="",this.style.width="",this.classList.remove(...this.classList.values())}updated(t){this.show&&this.calculatePosition()}onPopConfirmCancel(){this.dispatchEvent(new CustomEvent("onCancel")),this.show=!1,this.initStyles()}onPopConfirmConfirm(){this.dispatchEvent(new CustomEvent("onConfirm")),this.show=!1,this.initStyles()}disconnectedCallback(){super.disconnectedCallback(),this.isPopConfirm?(this.target.removeEventListener("click",this.onClick),document.removeEventListener("scroll",this.calculatePosition)):(this.target.removeEventListener("mouseover",this.onMouseOver),this.target.removeEventListener("mouseleave",this.onMouseLeave))}render(){return this.isPopConfirm?this.show?o`<div class="popconfirm-container"><p class="popconfirm-title">${this.popConfirmTitle}</p><p class="popconfirm-description">${this.popConfirmDescription}</p><div class="btn-block"><nr-button .size="${"small"}" type="${"primary"}" @click="${this.onPopConfirmConfirm}">${this.okText}</nr-button><nr-button .size="${"small"}" type="${"danger"}" @click="${this.onPopConfirmCancel}">${this.cancelText}</nr-button></div></div>`:s:this.show?o`<slot></slot>`:s}};c.styles=r,p([n({reflect:!0})],c.prototype,"position",void 0),p([n({reflect:!0})],c.prototype,"alignement",void 0),p([e()],c.prototype,"target",void 0),p([n({reflect:!0,type:Boolean})],c.prototype,"show",void 0),p([n()],c.prototype,"isPopConfirm",void 0),p([n()],c.prototype,"popConfirmTitle",void 0),p([n()],c.prototype,"popConfirmDescription",void 0),p([n()],c.prototype,"okText",void 0),p([n()],c.prototype,"cancelText",void 0),c=p([h("hy-tooltip")],c);export{c as TooltipElement};
1
+ import{css as t,LitElement as i,html as o,nothing as s}from"lit";import{property as n,state as e,customElement as h}from"lit/decorators.js";const r=[t`
2
+ :host([show]) {
3
+ background-color: var(--nuraly-tooltip-background-color);
4
+ color: var(--nuraly-tooltip-text-color);
5
+ position: fixed;
6
+ padding: 5px;
7
+ text-align: center;
8
+ opacity: 0;
9
+ font-size: 14px;
10
+ z-index: 9999;
11
+ border-radius: 4px;
12
+ animation-name: show-animation;
13
+ animation-duration: 0.4s;
14
+ animation-fill-mode: forwards;
15
+ }
16
+
17
+ .popconfirm-container {
18
+ display: flex;
19
+ flex-direction: column;
20
+ }
21
+ .btn-block {
22
+ display: flex;
23
+ justify-content: end;
24
+ gap: 10px;
25
+ margin: 10px;
26
+ }
27
+
28
+ .popconfirm-description,
29
+ .popconfirm-title {
30
+ margin: 5px;
31
+ text-align: left;
32
+ }
33
+ .popconfirm-title {
34
+ font-weight: bold;
35
+ }
36
+
37
+ @keyframes show-animation {
38
+ from {
39
+ opacity: 0;
40
+ }
41
+ to {
42
+ opacity: 1;
43
+ }
44
+ }
45
+
46
+ :host::after {
47
+ content: '';
48
+ height: 0;
49
+ width: 0;
50
+ position: absolute;
51
+ border: 5px solid transparent;
52
+ }
53
+ :host(.top-position)::after {
54
+ border-top-color: var(--nuraly-tooltip-background-color);
55
+ top: 100%;
56
+ }
57
+ :host(.left-position)::after {
58
+ border-left-color: var(--nuraly-tooltip-background-color);
59
+ left: 100%;
60
+ }
61
+
62
+ :host(.right-position)::after {
63
+ border-right-color: var(--nuraly-tooltip-background-color);
64
+ right: 100%;
65
+ }
66
+ :host(.bottom-position)::after {
67
+ border-bottom-color: var(--nuraly-tooltip-background-color);
68
+ bottom: 100%;
69
+ }
70
+ :host(.alignement-center.top-position)::after,
71
+ :host(.alignement-center.bottom-position)::after {
72
+ right: 50%;
73
+ transform: translate(50%);
74
+ }
75
+
76
+ :host(.alignement-start.top-position)::after,
77
+ :host(.alignement-start.bottom-position)::after {
78
+ left: 4%;
79
+ }
80
+ :host(.top-position.alignement-end)::after,
81
+ :host(.alignement-end.bottom-position)::after {
82
+ right: 4%;
83
+ }
84
+
85
+ :host(.alignement-center.left-position)::after,
86
+ :host(.alignement-center.right-position)::after {
87
+ top: 50%;
88
+ transform: translate(0%, -50%);
89
+ }
90
+
91
+ :host(.alignement-start.left-position)::after,
92
+ :host(.alignement-start.right-position)::after {
93
+ top: 5px;
94
+ }
95
+ :host(.alignement-end.left-position)::after,
96
+ :host(.alignement-end.right-position)::after {
97
+ bottom: 5px;
98
+ }
99
+ `,t`
100
+ :host {
101
+ --nuraly-tooltip-background-color: #393939;
102
+ --nuraly-tooltip-text-color: #ffffff;
103
+ }
104
+ @media (prefers-color-scheme: dark) {
105
+ :host {
106
+ --nuraly-tooltip-background-color: #f4f4f4;
107
+ --nuraly-tooltip-text-color: #161616;
108
+ }
109
+ }
110
+ `];var a,l;!function(t){t.Top="top",t.Bottom="bottom",t.Right="right",t.Left="left"}(a||(a={})),function(t){t.Start="start",t.Center="center",t.End="end"}(l||(l={}));var p=function(t,i,o,s){for(var n,e=arguments.length,h=e<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,o):s,r=t.length-1;r>=0;r--)(n=t[r])&&(h=(e<3?n(h):e>3?n(i,o,h):n(i,o))||h);return e>3&&h&&Object.defineProperty(i,o,h),h};let c=class extends i{constructor(){super(...arguments),this.position=a.Bottom,this.alignement=l.Center,this.show=!1,this.isPopConfirm=!1,this.popConfirmTitle="",this.popConfirmDescription="",this.okText="Yes",this.cancelText="No",this.horizontalOffset=10,this.verticalOffset=10,this.onMouseOver=()=>{this.show=!0},this.onMouseLeave=()=>{this.show=!1,this.initStyles()},this.onClick=()=>{this.show=!this.show},this.calculatePosition=()=>{this.initStyles(),this.style.width=`${this.clientWidth}px`,this.position==a.Bottom||this.position==a.Top?(this.calculateYposition(),this.calculateYalignement()):(this.calculateXposition(),this.calculateXalignement())},this.calculateYposition=()=>{const t=this.target.getBoundingClientRect(),i=t.bottom,o=t.top,s=window.visualViewport.height,n=this.clientHeight,e=n+this.verticalOffset<s-i,h=n+this.verticalOffset<o;this.position==a.Bottom?e||!h?(this.classList.add("bottom-position"),this.style.top=`${i+this.verticalOffset}px`):(this.classList.add("top-position"),this.style.top=o-n-this.verticalOffset+"px"):h||!e?(this.classList.add("top-position"),this.style.top=o-n-this.verticalOffset+"px"):(this.classList.add("bottom-position"),this.style.top=`${i+this.verticalOffset}px`)},this.calculateYalignement=()=>{const t=this.target.getBoundingClientRect(),i=t.right,o=t.width,s=t.left,n=this.clientWidth,e=s+o/2,h=window.visualViewport.width,r=h-i+o/2;if(this.alignement==l.Start){n+s<h?(this.classList.add("alignement-start"),this.style.left=s-this.horizontalOffset+"px"):(this.classList.add("alignement-end"),this.style.left=`${s-n+this.horizontalOffset}px`)}else if(this.alignement==l.End){n<s?(this.classList.add("alignement-end"),this.style.left=`${s-n+this.horizontalOffset}px`):(this.classList.add("alignement-start"),this.style.left=s-this.horizontalOffset+"px")}else{const t=n<e;n/2<e&&n/2<r||n>e&&n>r?(this.classList.add("alignement-center"),this.style.left=s-n/2+o/2+"px"):t?(this.classList.add("alignement-end"),this.style.left=`${s-n+this.horizontalOffset}px`):(this.classList.add("alignement-start"),this.style.left=s-this.horizontalOffset+"px")}},this.calculateXposition=()=>{const t=this.target.getBoundingClientRect(),i=t.left,o=t.right,s=window.visualViewport.width,n=this.clientWidth,e=n+this.horizontalOffset<s-o,h=n+this.horizontalOffset<i;this.position==a.Right?e||!h?(this.classList.add("right-position"),this.style.left=`${o+this.horizontalOffset}px`):(this.classList.add("left-position"),this.style.left=i-n-this.horizontalOffset+"px"):h||!e?(this.classList.add("left-position"),this.style.left=i-n-this.horizontalOffset+"px"):(this.classList.add("right-position"),this.style.left=`${o+this.horizontalOffset}px`)},this.calculateXalignement=()=>{const t=this.target.getBoundingClientRect(),i=t.top,o=t.height,s=t.bottom,n=this.clientHeight,e=window.visualViewport.height,h=e-s;if(this.alignement==l.End){n<i?(this.classList.add("alignement-end"),this.style.top=s-n+"px"):(this.classList.add("alignement-start"),this.style.top=i-o/4+"px")}else if(this.alignement==l.Start){n<e-s?(this.classList.add("alignement-start"),this.style.top=i-o/4+"px"):(this.classList.add("alignement-end"),this.style.top=s-n+"px")}else{const t=n<i;n/2<i&&n/2<h||n>i&&n>h?(this.classList.add("alignement-center"),this.style.top=i+o/2-n/2+"px"):t?(this.classList.add("alignement-end"),this.style.top=s-n+"px"):(this.classList.add("alignement-start"),this.style.top=i-o/4+"px")}},this.onClickOutside=t=>{const i=t.composedPath();!i.includes(this.target)&&!i.includes(this)&&(this.show=!1)}}connectedCallback(){super.connectedCallback(),this.target=this.target||this.previousElementSibling,this.target?this.isPopConfirm?(document.addEventListener("scroll",this.calculatePosition),this.target.addEventListener("click",this.onClick),document.addEventListener("click",this.onClickOutside)):(this.target.addEventListener("mouseover",this.onMouseOver),this.target.addEventListener("mouseleave",this.onMouseLeave)):console.error("Tooltip target is not defined or found. Ensure target is explicitly set or precedes the tooltip.")}initStyles(){this.style.top="",this.style.left="",this.style.width="",this.classList.remove(...this.classList.values())}updated(t){this.show&&this.calculatePosition()}onPopConfirmCancel(){this.dispatchEvent(new CustomEvent("onCancel")),this.show=!1,this.initStyles()}onPopConfirmConfirm(){this.dispatchEvent(new CustomEvent("onConfirm")),this.show=!1,this.initStyles()}disconnectedCallback(){super.disconnectedCallback(),this.isPopConfirm?(this.target.removeEventListener("click",this.onClick),document.removeEventListener("scroll",this.calculatePosition)):(this.target.removeEventListener("mouseover",this.onMouseOver),this.target.removeEventListener("mouseleave",this.onMouseLeave))}render(){return this.isPopConfirm?this.show?o`
111
+ <div class="popconfirm-container">
112
+ <p class="popconfirm-title">${this.popConfirmTitle}</p>
113
+ <p class="popconfirm-description">${this.popConfirmDescription}</p>
114
+ <div class="btn-block">
115
+ <nr-button .size=${"small"} type=${"primary"} @click=${this.onPopConfirmConfirm}
116
+ >${this.okText}</nr-button
117
+ >
118
+ <nr-button .size=${"small"} type=${"danger"} @click=${this.onPopConfirmCancel}
119
+ >${this.cancelText}</nr-button
120
+ >
121
+ </div>
122
+ </div>
123
+ `:s:this.show?o`<slot></slot>`:s}};c.styles=r,p([n({reflect:!0})],c.prototype,"position",void 0),p([n({reflect:!0})],c.prototype,"alignement",void 0),p([e()],c.prototype,"target",void 0),p([n({reflect:!0,type:Boolean})],c.prototype,"show",void 0),p([n()],c.prototype,"isPopConfirm",void 0),p([n()],c.prototype,"popConfirmTitle",void 0),p([n()],c.prototype,"popConfirmDescription",void 0),p([n()],c.prototype,"okText",void 0),p([n()],c.prototype,"cancelText",void 0),c=p([h("hy-tooltip")],c);export{c as TooltipElement};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuralyui/tooltips",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",