@elcrm/tooltip 0.1.1 → 0.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/README.md CHANGED
@@ -75,12 +75,14 @@ import {
75
75
  | ----------------------- | ----------------- |
76
76
  | `--tooltip-bg` | Фон |
77
77
  | `--tooltip-fg` | Цвет текста |
78
- | `--tooltip-radius` | Скругление |
79
- | `--tooltip-max-width` | Макс. ширина |
80
- | `--tooltip-font-size` | Размер шрифта |
81
- | `--tooltip-padding` | Внутренние отступы |
82
- | `--tooltip-shadow` | Тень |
83
- | `--tooltip-gap` | Зазор до якоря |
78
+ | `--tooltip-radius` | Скругление (по умолчанию `8px`) |
79
+ | `--tooltip-max-width` | Макс. ширина |
80
+ | `--tooltip-font-size` | Размер шрифта |
81
+ | `--tooltip-padding-block` | Вертикальный padding |
82
+ | `--tooltip-padding-inline` | Горизонтальный padding |
83
+ | `--tooltip-padding` | Shorthand padding |
84
+ | `--tooltip-shadow` | Тень |
85
+ | `--tooltip-gap` | Зазор до якоря |
84
86
 
85
87
  ## Поведение
86
88
 
package/dist/index.css CHANGED
@@ -1 +1 @@
1
- @layer elcrm-tooltip{.ttr{display:inline-flex;vertical-align:middle;max-width:100%}.ttt{position:fixed;box-sizing:border-box;max-width:var(--tooltip-max-width);padding:var(--tooltip-padding);border-radius:var(--tooltip-radius);background:var(--tooltip-bg);color:var(--tooltip-fg);font-size:var(--tooltip-font-size);line-height:1.35;font-weight:500;box-shadow:var(--tooltip-shadow);pointer-events:none;opacity:0;transition:opacity .12s ease;white-space:normal;word-break:break-word}.ttv{opacity:1}.ttl{text-align:left}.ttm{text-align:center}.ttx{text-align:right}.ttt:before{content:"";position:fixed;pointer-events:none;width:0;height:0;top:var(--tooltip-arrow-y);left:var(--tooltip-arrow-x);transform:var(--tooltip-arrow-r, none);margin-left:-6px;border-width:6px;border-style:solid;border-color:var(--tooltip-bg) transparent transparent transparent}}
1
+ @layer elcrm-tooltip{.ttr{display:inline-flex;vertical-align:middle;max-width:100%}.ttt{position:fixed;box-sizing:border-box;max-width:var(--tooltip-max-width, 280px);padding:var(--tooltip-padding-block, 6px) var(--tooltip-padding-inline, 12px);border-radius:var(--tooltip-radius, 8px);background:var(--tooltip-bg, #1e1f24);color:var(--tooltip-fg, #eaeaea);font-size:var(--tooltip-font-size, 13px);line-height:1.35;font-weight:500;box-shadow:var(--tooltip-shadow, 0 8px 24px rgba(0, 0, 0, .28));pointer-events:none;opacity:0;transition:opacity .12s ease;white-space:normal;word-break:break-word}.ttv{opacity:1}.ttl{text-align:left}.ttm{text-align:center}.ttx{text-align:right}.ttt:before{content:"";position:absolute;width:0;height:0;pointer-events:none;border-style:solid;border-width:6px}.tta:before{top:100%;left:var(--tooltip-arrow-offset);margin-left:-6px;border-color:var(--tooltip-bg, #1e1f24) transparent transparent transparent}.ttb:before{bottom:100%;left:var(--tooltip-arrow-offset);margin-left:-6px;border-color:transparent transparent var(--tooltip-bg, #1e1f24) transparent}.ttc:before{left:100%;top:var(--tooltip-arrow-offset);margin-top:-6px;border-color:transparent transparent transparent var(--tooltip-bg, #1e1f24)}.ttd:before{right:100%;top:var(--tooltip-arrow-offset);margin-top:-6px;border-color:transparent var(--tooltip-bg, #1e1f24) transparent transparent}}
package/dist/index.es.js CHANGED
@@ -1,163 +1,177 @@
1
- import B, { useId as V, useRef as p, useState as z, useCallback as P, useLayoutEffect as X, useEffect as F } from "react";
2
- import { createPortal as J } from "react-dom";
3
- import './index.css';const K = "0.1.1", Q = {
4
- version: K
5
- }, U = "ttr", _ = "ttt", tt = "ttv", et = "ttl", nt = "ttm", rt = "ttx", f = {
6
- r: U,
7
- t: _,
8
- v: tt,
9
- l: et,
10
- m: nt,
11
- x: rt
12
- }, j = 1e3, ot = 10;
13
- function R() {
1
+ import k, { useId as K, useRef as w, useState as T, useCallback as A, useLayoutEffect as G, useEffect as Q } from "react";
2
+ import { createPortal as U } from "react-dom";
3
+ import './index.css';const tt = "0.1.2", et = {
4
+ version: tt
5
+ }, nt = "ttr", rt = "ttt", ot = "ttv", it = "ttl", lt = "ttm", st = "ttx", ct = "tta", ut = "ttb", ft = "ttc", at = "ttd", i = {
6
+ r: nt,
7
+ t: rt,
8
+ v: ot,
9
+ l: it,
10
+ m: lt,
11
+ x: st,
12
+ a: ct,
13
+ b: ut,
14
+ c: ft,
15
+ d: at
16
+ }, s = 10, c = 8, W = 10;
17
+ function j(t, e) {
18
+ return Math.min(Math.max(c, t), window.innerWidth - e - c);
19
+ }
20
+ function D(t, e) {
21
+ return Math.min(Math.max(c, t), window.innerHeight - e - c);
22
+ }
23
+ function p(t, e) {
24
+ return Math.min(Math.max(W, t), e - W);
25
+ }
26
+ function dt(t, e, b) {
27
+ const f = t.left + t.width / 2, a = t.top + t.height / 2;
28
+ switch (b) {
29
+ case "top": {
30
+ let n = t.top - e.height - s, r = j(f - e.width / 2, e.width), o = "top";
31
+ return n < c && (n = t.bottom + s, o = "bottom"), { top: n, left: r, side: o, arrow: p(f - r, e.width) };
32
+ }
33
+ case "bottom": {
34
+ let n = t.bottom + s, r = j(f - e.width / 2, e.width), o = "bottom";
35
+ return n + e.height > window.innerHeight - c && (n = t.top - e.height - s, o = "top"), { top: n, left: r, side: o, arrow: p(f - r, e.width) };
36
+ }
37
+ case "left": {
38
+ let n = D(a - e.height / 2, e.height), r = t.left - e.width - s, o = "left";
39
+ return r < c && (r = t.right + s, o = "right"), { top: n, left: r, side: o, arrow: p(a - n, e.height) };
40
+ }
41
+ case "right": {
42
+ let n = D(a - e.height / 2, e.height), r = t.right + s, o = "right";
43
+ return r + e.width > window.innerWidth - c && (r = t.left - e.width - s, o = "left"), { top: n, left: r, side: o, arrow: p(a - n, e.height) };
44
+ }
45
+ }
46
+ }
47
+ const X = 1e3, mt = 10;
48
+ function z() {
14
49
  const t = globalThis;
15
50
  return t.elcrm || (t.elcrm = {}), t.elcrm.overlayZ || (t.elcrm.overlayZ = { seq: 0, active: /* @__PURE__ */ new Set() }), t.elcrm.overlayZ;
16
51
  }
17
- function it() {
18
- const t = R();
52
+ function ht() {
53
+ const t = z();
19
54
  t.seq += 1;
20
- const e = j + t.seq * ot;
55
+ const e = X + t.seq * mt;
21
56
  return t.active.add(e), e;
22
57
  }
23
- function Y(t) {
24
- const e = R();
58
+ function N(t) {
59
+ const e = z();
25
60
  e.active.delete(t), e.active.size === 0 && (e.seq = 0);
26
61
  }
27
- function at() {
28
- const t = R();
29
- return t.active.size === 0 ? j : Math.max(...t.active);
30
- }
31
- const n = 8, s = 8;
32
- function lt(t, e, y) {
33
- const w = t.left + t.width / 2, d = t.top + t.height / 2;
34
- let o = 0, i = 0, c = w, l = 0, r = "";
35
- const g = (b) => Math.min(
36
- Math.max(s, b),
37
- window.innerWidth - e.width - s
38
- );
39
- switch (y) {
40
- case "top":
41
- o = t.top - e.height - n, i = g(w - e.width / 2), l = t.top - n, r = "", o < s && (o = t.bottom + n, l = t.bottom + n - 2, r = "rotate(180deg)");
42
- break;
43
- case "bottom":
44
- o = t.bottom + n, i = g(w - e.width / 2), l = t.bottom + n - 2, r = "rotate(180deg)", o + e.height > window.innerHeight - s && (o = t.top - e.height - n, l = t.top - n, r = "");
45
- break;
46
- case "left":
47
- o = Math.min(
48
- Math.max(s, d - e.height / 2),
49
- window.innerHeight - e.height - s
50
- ), i = t.left - e.width - n, c = t.left - n + 2, l = d, r = "rotate(270deg)", i < s && (i = t.right + n, c = t.right + n - 2, r = "rotate(90deg)");
51
- break;
52
- case "right":
53
- o = Math.min(
54
- Math.max(s, d - e.height / 2),
55
- window.innerHeight - e.height - s
56
- ), i = t.right + n, c = t.right + n - 2, l = d, r = "rotate(90deg)", i + e.width > window.innerWidth - s && (i = t.left - e.width - n, c = t.left - n + 2, r = "rotate(270deg)");
57
- break;
58
- }
59
- return { top: o, left: i, arrowX: c, arrowY: l, arrowR: r };
62
+ function bt() {
63
+ const t = z();
64
+ return t.active.size === 0 ? X : Math.max(...t.active);
60
65
  }
61
- function st(t) {
62
- return t === "left" ? f.l : t === "right" ? f.x : f.m;
66
+ const wt = {
67
+ top: i.a,
68
+ bottom: i.b,
69
+ left: i.c,
70
+ right: i.d
71
+ };
72
+ function gt(t) {
73
+ return t === "left" ? i.l : t === "right" ? i.x : i.m;
63
74
  }
64
- function ft({
75
+ function xt({
65
76
  content: t,
66
77
  children: e,
67
- placement: y,
68
- orientation: w,
69
- textAlign: d = "center",
70
- delay: o = 180,
71
- delayHide: i = 60,
72
- className: c,
73
- disabled: l = !1,
74
- open: r
78
+ placement: b,
79
+ orientation: f,
80
+ textAlign: a = "center",
81
+ delay: n = 180,
82
+ delayHide: r = 60,
83
+ className: o,
84
+ disabled: I = !1,
85
+ open: x
75
86
  }) {
76
- const g = y ?? w ?? "top", b = V(), M = p(null), k = p(null), x = p(null), E = p(null), u = p(null), [G, L] = z(!1), [a, O] = z(null), [Z, S] = z(null), T = () => {
77
- x.current != null && (window.clearTimeout(x.current), x.current = null), E.current != null && (window.clearTimeout(E.current), E.current = null);
78
- }, q = P(() => {
79
- l || t == null || t === "" || (T(), x.current = window.setTimeout(() => {
80
- L(!0);
81
- }, o));
82
- }, [t, o, l]), C = P(() => {
83
- r || (T(), E.current = window.setTimeout(() => {
84
- L(!1), O(null);
85
- }, i));
86
- }, [i, r]), m = r || G;
87
- X(() => {
88
- if (m) {
89
- if (u.current == null) {
90
- const h = it();
91
- u.current = h, S(h);
87
+ const R = b ?? f ?? "top", M = K(), O = w(null), L = w(null), g = w(null), v = w(null), l = w(null), [Y, Z] = T(!1), [u, C] = T(null), [S, q] = T(null), E = () => {
88
+ g.current != null && (window.clearTimeout(g.current), g.current = null), v.current != null && (window.clearTimeout(v.current), v.current = null);
89
+ }, B = A(() => {
90
+ I || t == null || t === "" || (E(), g.current = window.setTimeout(() => {
91
+ Z(!0);
92
+ }, n));
93
+ }, [t, n, I]), P = A(() => {
94
+ x || (E(), v.current = window.setTimeout(() => {
95
+ Z(!1), C(null);
96
+ }, r));
97
+ }, [r, x]), d = x || Y;
98
+ G(() => {
99
+ if (d) {
100
+ if (l.current == null) {
101
+ const m = ht();
102
+ l.current = m, q(m);
92
103
  }
93
104
  return;
94
105
  }
95
- u.current != null && (Y(u.current), u.current = null, S(null));
96
- }, [m]), F(() => () => {
97
- T(), u.current != null && (Y(u.current), u.current = null);
98
- }, []), X(() => {
99
- if (!m) return;
100
- const h = M.current, $ = k.current;
101
- if (!h || !$) return;
102
- const v = () => {
103
- const A = h.getBoundingClientRect(), D = $.getBoundingClientRect();
104
- O(lt(A, D, g));
106
+ l.current != null && (N(l.current), l.current = null, q(null));
107
+ }, [d]), Q(() => () => {
108
+ E(), l.current != null && (N(l.current), l.current = null);
109
+ }, []), G(() => {
110
+ if (!d) return;
111
+ const m = O.current, $ = L.current;
112
+ if (!m || !$) return;
113
+ const h = () => {
114
+ const F = m.getBoundingClientRect(), J = $.getBoundingClientRect();
115
+ C(dt(F, J, R));
105
116
  };
106
- return v(), window.addEventListener("resize", v), window.addEventListener("scroll", v, !0), () => {
107
- window.removeEventListener("resize", v), window.removeEventListener("scroll", v, !0);
117
+ return h(), window.addEventListener("resize", h), window.addEventListener("scroll", h, !0), () => {
118
+ window.removeEventListener("resize", h), window.removeEventListener("scroll", h, !0);
108
119
  };
109
- }, [m, g, t]);
110
- const H = a ? {
111
- top: a.top,
112
- left: a.left,
113
- zIndex: Z ?? 1e3,
114
- "--tooltip-arrow-x": `${a.arrowX}px`,
115
- "--tooltip-arrow-y": `${a.arrowY}px`,
116
- "--tooltip-arrow-r": a.arrowR || "none"
120
+ }, [d, R, t]);
121
+ const H = u ? {
122
+ top: u.top,
123
+ left: u.left,
124
+ zIndex: S ?? 1e3,
125
+ "--tooltip-arrow-offset": `${u.arrow}px`
117
126
  } : {
118
127
  top: -9999,
119
128
  left: -9999,
120
- zIndex: Z ?? 1e3,
129
+ zIndex: S ?? 1e3,
121
130
  visibility: "hidden"
122
- }, N = [f.t, st(d), a ? f.v : ""].filter(Boolean).join(" "), W = m && typeof document < "u" ? J(
123
- /* @__PURE__ */ B.createElement(
131
+ }, V = [
132
+ i.t,
133
+ u ? wt[u.side] : "",
134
+ gt(a),
135
+ u ? i.v : ""
136
+ ].filter(Boolean).join(" "), _ = d && typeof document < "u" ? U(
137
+ /* @__PURE__ */ k.createElement(
124
138
  "div",
125
139
  {
126
- ref: k,
127
- id: b,
140
+ ref: L,
141
+ id: M,
128
142
  role: "tooltip",
129
- className: N,
143
+ className: V,
130
144
  style: H
131
145
  },
132
146
  t
133
147
  ),
134
148
  document.body
135
149
  ) : null;
136
- return /* @__PURE__ */ B.createElement(
150
+ return /* @__PURE__ */ k.createElement(
137
151
  "span",
138
152
  {
139
- ref: M,
140
- className: c ? `${f.r} ${c}` : f.r,
141
- onMouseEnter: q,
142
- onMouseLeave: C,
143
- onFocus: q,
144
- onBlur: C,
145
- "aria-describedby": m ? b : void 0
153
+ ref: O,
154
+ className: o ? `${i.r} ${o}` : i.r,
155
+ onMouseEnter: B,
156
+ onMouseLeave: P,
157
+ onFocus: B,
158
+ onBlur: P,
159
+ "aria-describedby": d ? M : void 0
146
160
  },
147
161
  e,
148
- W
162
+ _
149
163
  );
150
164
  }
151
- const dt = () => null;
152
- function I() {
165
+ const Et = () => null;
166
+ function y() {
153
167
  return typeof globalThis < "u" ? globalThis : {};
154
168
  }
155
- I().elcrm || (I().elcrm = {});
156
- Object.assign(I().elcrm, { tooltip: Q.version });
169
+ y().elcrm || (y().elcrm = {});
170
+ Object.assign(y().elcrm, { tooltip: et.version });
157
171
  export {
158
- dt as Item,
159
- ft as Tooltip,
160
- it as acquireOverlayZIndex,
161
- at as peekOverlayZIndex,
162
- Y as releaseOverlayZIndex
172
+ Et as Item,
173
+ xt as Tooltip,
174
+ ht as acquireOverlayZIndex,
175
+ bt as peekOverlayZIndex,
176
+ N as releaseOverlayZIndex
163
177
  };
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(o,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],n):(o=typeof globalThis<"u"?globalThis:o||self,n((o.elCRM=o.elCRM||{},o.elCRM.tooltip={}),o.React,o.ReactDOM))})(this,function(o,n,R){"use strict";var O=document.createElement("style");O.textContent=`@layer elcrm-tooltip{.ttr{display:inline-flex;vertical-align:middle;max-width:100%}.ttt{position:fixed;box-sizing:border-box;max-width:var(--tooltip-max-width);padding:var(--tooltip-padding);border-radius:var(--tooltip-radius);background:var(--tooltip-bg);color:var(--tooltip-fg);font-size:var(--tooltip-font-size);line-height:1.35;font-weight:500;box-shadow:var(--tooltip-shadow);pointer-events:none;opacity:0;transition:opacity .12s ease;white-space:normal;word-break:break-word}.ttv{opacity:1}.ttl{text-align:left}.ttm{text-align:center}.ttx{text-align:right}.ttt:before{content:"";position:fixed;pointer-events:none;width:0;height:0;top:var(--tooltip-arrow-y);left:var(--tooltip-arrow-x);transform:var(--tooltip-arrow-r, none);margin-left:-6px;border-width:6px;border-style:solid;border-color:var(--tooltip-bg) transparent transparent transparent}}
2
- /*$vite$:1*/`,document.head.appendChild(O);const Y={version:"0.1.1"},f={r:"ttr",t:"ttt",v:"ttv",l:"ttl",m:"ttm",x:"ttx"},C=1e3,D=10;function T(){const t=globalThis;return t.elcrm||(t.elcrm={}),t.elcrm.overlayZ||(t.elcrm.overlayZ={seq:0,active:new Set}),t.elcrm.overlayZ}function S(){const t=T();t.seq+=1;const e=C+t.seq*D;return t.active.add(e),e}function I(t){const e=T();e.active.delete(t),e.active.size===0&&(e.seq=0)}function G(){const t=T();return t.active.size===0?C:Math.max(...t.active)}const r=8,u=8;function H(t,e,z){const v=t.left+t.width/2,p=t.top+t.height/2;let l=0,s=0,d=v,a=0,i="";const h=b=>Math.min(Math.max(u,b),window.innerWidth-e.width-u);switch(z){case"top":l=t.top-e.height-r,s=h(v-e.width/2),a=t.top-r,i="",l<u&&(l=t.bottom+r,a=t.bottom+r-2,i="rotate(180deg)");break;case"bottom":l=t.bottom+r,s=h(v-e.width/2),a=t.bottom+r-2,i="rotate(180deg)",l+e.height>window.innerHeight-u&&(l=t.top-e.height-r,a=t.top-r,i="");break;case"left":l=Math.min(Math.max(u,p-e.height/2),window.innerHeight-e.height-u),s=t.left-e.width-r,d=t.left-r+2,a=p,i="rotate(270deg)",s<u&&(s=t.right+r,d=t.right+r-2,i="rotate(90deg)");break;case"right":l=Math.min(Math.max(u,p-e.height/2),window.innerHeight-e.height-u),s=t.right+r,d=t.right+r-2,a=p,i="rotate(90deg)",s+e.width>window.innerWidth-u&&(s=t.left-e.width-r,d=t.left-r+2,i="rotate(270deg)");break}return{top:l,left:s,arrowX:d,arrowY:a,arrowR:i}}function N(t){return t==="left"?f.l:t==="right"?f.x:f.m}function W({content:t,children:e,placement:z,orientation:v,textAlign:p="center",delay:l=180,delayHide:s=60,className:d,disabled:a=!1,open:i}){const h=z??v??"top",b=n.useId(),Z=n.useRef(null),q=n.useRef(null),y=n.useRef(null),E=n.useRef(null),c=n.useRef(null),[V,L]=n.useState(!1),[m,$]=n.useState(null),[P,_]=n.useState(null),k=()=>{y.current!=null&&(window.clearTimeout(y.current),y.current=null),E.current!=null&&(window.clearTimeout(E.current),E.current=null)},j=n.useCallback(()=>{a||t==null||t===""||(k(),y.current=window.setTimeout(()=>{L(!0)},l))},[t,l,a]),B=n.useCallback(()=>{i||(k(),E.current=window.setTimeout(()=>{L(!1),$(null)},s))},[s,i]),w=i||V;n.useLayoutEffect(()=>{if(w){if(c.current==null){const g=S();c.current=g,_(g)}return}c.current!=null&&(I(c.current),c.current=null,_(null))},[w]),n.useEffect(()=>()=>{k(),c.current!=null&&(I(c.current),c.current=null)},[]),n.useLayoutEffect(()=>{if(!w)return;const g=Z.current,X=q.current;if(!g||!X)return;const x=()=>{const Q=g.getBoundingClientRect(),U=X.getBoundingClientRect();$(H(Q,U,h))};return x(),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),()=>{window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},[w,h,t]);const F=m?{top:m.top,left:m.left,zIndex:P??1e3,"--tooltip-arrow-x":`${m.arrowX}px`,"--tooltip-arrow-y":`${m.arrowY}px`,"--tooltip-arrow-r":m.arrowR||"none"}:{top:-9999,left:-9999,zIndex:P??1e3,visibility:"hidden"},J=[f.t,N(p),m?f.v:""].filter(Boolean).join(" "),K=w&&typeof document<"u"?R.createPortal(n.createElement("div",{ref:q,id:b,role:"tooltip",className:J,style:F},t),document.body):null;return n.createElement("span",{ref:Z,className:d?`${f.r} ${d}`:f.r,onMouseEnter:j,onMouseLeave:B,onFocus:j,onBlur:B,"aria-describedby":w?b:void 0},e,K)}const A=()=>null;function M(){return typeof globalThis<"u"?globalThis:{}}M().elcrm||(M().elcrm={}),Object.assign(M().elcrm,{tooltip:Y.version}),o.Item=A,o.Tooltip=W,o.acquireOverlayZIndex=S,o.peekOverlayZIndex=G,o.releaseOverlayZIndex=I,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(i,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],n):(i=typeof globalThis<"u"?globalThis:i||self,n((i.elCRM=i.elCRM||{},i.elCRM.tooltip={}),i.React,i.ReactDOM))})(this,function(i,n,N){"use strict";var z=document.createElement("style");z.textContent=`@layer elcrm-tooltip{.ttr{display:inline-flex;vertical-align:middle;max-width:100%}.ttt{position:fixed;box-sizing:border-box;max-width:var(--tooltip-max-width, 280px);padding:var(--tooltip-padding-block, 6px) var(--tooltip-padding-inline, 12px);border-radius:var(--tooltip-radius, 8px);background:var(--tooltip-bg, #1e1f24);color:var(--tooltip-fg, #eaeaea);font-size:var(--tooltip-font-size, 13px);line-height:1.35;font-weight:500;box-shadow:var(--tooltip-shadow, 0 8px 24px rgba(0, 0, 0, .28));pointer-events:none;opacity:0;transition:opacity .12s ease;white-space:normal;word-break:break-word}.ttv{opacity:1}.ttl{text-align:left}.ttm{text-align:center}.ttx{text-align:right}.ttt:before{content:"";position:absolute;width:0;height:0;pointer-events:none;border-style:solid;border-width:6px}.tta:before{top:100%;left:var(--tooltip-arrow-offset);margin-left:-6px;border-color:var(--tooltip-bg, #1e1f24) transparent transparent transparent}.ttb:before{bottom:100%;left:var(--tooltip-arrow-offset);margin-left:-6px;border-color:transparent transparent var(--tooltip-bg, #1e1f24) transparent}.ttc:before{left:100%;top:var(--tooltip-arrow-offset);margin-top:-6px;border-color:transparent transparent transparent var(--tooltip-bg, #1e1f24)}.ttd:before{right:100%;top:var(--tooltip-arrow-offset);margin-top:-6px;border-color:transparent var(--tooltip-bg, #1e1f24) transparent transparent}}
2
+ /*$vite$:1*/`,document.head.appendChild(z);const X={version:"0.1.2"},s={r:"ttr",t:"ttt",v:"ttv",l:"ttl",m:"ttm",x:"ttx",a:"tta",b:"ttb",c:"ttc",d:"ttd"},a=10,c=8,O=10;function C(t,e){return Math.min(Math.max(c,t),window.innerWidth-e-c)}function S(t,e){return Math.min(Math.max(c,t),window.innerHeight-e-c)}function v(t,e){return Math.min(Math.max(O,t),e-O)}function Y(t,e,T){const f=t.left+t.width/2,p=t.top+t.height/2;switch(T){case"top":{let r=t.top-e.height-a,o=C(f-e.width/2,e.width),l="top";return r<c&&(r=t.bottom+a,l="bottom"),{top:r,left:o,side:l,arrow:v(f-o,e.width)}}case"bottom":{let r=t.bottom+a,o=C(f-e.width/2,e.width),l="bottom";return r+e.height>window.innerHeight-c&&(r=t.top-e.height-a,l="top"),{top:r,left:o,side:l,arrow:v(f-o,e.width)}}case"left":{let r=S(p-e.height/2,e.height),o=t.left-e.width-a,l="left";return o<c&&(o=t.right+a,l="right"),{top:r,left:o,side:l,arrow:v(p-r,e.height)}}case"right":{let r=S(p-e.height/2,e.height),o=t.right+a,l="right";return o+e.width>window.innerWidth-c&&(o=t.left-e.width-a,l="left"),{top:r,left:o,side:l,arrow:v(p-r,e.height)}}}}const Z=1e3,H=10;function x(){const t=globalThis;return t.elcrm||(t.elcrm={}),t.elcrm.overlayZ||(t.elcrm.overlayZ={seq:0,active:new Set}),t.elcrm.overlayZ}function k(){const t=x();t.seq+=1;const e=Z+t.seq*H;return t.active.add(e),e}function y(t){const e=x();e.active.delete(t),e.active.size===0&&(e.seq=0)}function V(){const t=x();return t.active.size===0?Z:Math.max(...t.active)}const F={top:s.a,bottom:s.b,left:s.c,right:s.d};function J(t){return t==="left"?s.l:t==="right"?s.x:s.m}function K({content:t,children:e,placement:T,orientation:f,textAlign:p="center",delay:r=180,delayHide:o=60,className:l,disabled:q=!1,open:I}){const L=T??f??"top",_=n.useId(),$=n.useRef(null),P=n.useRef(null),g=n.useRef(null),b=n.useRef(null),u=n.useRef(null),[U,j]=n.useState(!1),[d,B]=n.useState(null),[A,D]=n.useState(null),M=()=>{g.current!=null&&(window.clearTimeout(g.current),g.current=null),b.current!=null&&(window.clearTimeout(b.current),b.current=null)},G=n.useCallback(()=>{q||t==null||t===""||(M(),g.current=window.setTimeout(()=>{j(!0)},r))},[t,r,q]),R=n.useCallback(()=>{I||(M(),b.current=window.setTimeout(()=>{j(!1),B(null)},o))},[o,I]),h=I||U;n.useLayoutEffect(()=>{if(h){if(u.current==null){const m=k();u.current=m,D(m)}return}u.current!=null&&(y(u.current),u.current=null,D(null))},[h]),n.useEffect(()=>()=>{M(),u.current!=null&&(y(u.current),u.current=null)},[]),n.useLayoutEffect(()=>{if(!h)return;const m=$.current,W=P.current;if(!m||!W)return;const w=()=>{const rt=m.getBoundingClientRect(),ot=W.getBoundingClientRect();B(Y(rt,ot,L))};return w(),window.addEventListener("resize",w),window.addEventListener("scroll",w,!0),()=>{window.removeEventListener("resize",w),window.removeEventListener("scroll",w,!0)}},[h,L,t]);const tt=d?{top:d.top,left:d.left,zIndex:A??1e3,"--tooltip-arrow-offset":`${d.arrow}px`}:{top:-9999,left:-9999,zIndex:A??1e3,visibility:"hidden"},et=[s.t,d?F[d.side]:"",J(p),d?s.v:""].filter(Boolean).join(" "),nt=h&&typeof document<"u"?N.createPortal(n.createElement("div",{ref:P,id:_,role:"tooltip",className:et,style:tt},t),document.body):null;return n.createElement("span",{ref:$,className:l?`${s.r} ${l}`:s.r,onMouseEnter:G,onMouseLeave:R,onFocus:G,onBlur:R,"aria-describedby":h?_:void 0},e,nt)}const Q=()=>null;function E(){return typeof globalThis<"u"?globalThis:{}}E().elcrm||(E().elcrm={}),Object.assign(E().elcrm,{tooltip:X.version}),i.Item=Q,i.Tooltip=K,i.acquireOverlayZIndex=k,i.peekOverlayZIndex=V,i.releaseOverlayZIndex=y,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elcrm/tooltip",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "React-подсказки для elCRM: portal, общий overlayZ-стек, hover/focus, CSS-переменные.",
5
5
  "type": "module",
6
6
  "author": "MaSkal <dev@elcrm.online>",
@@ -55,7 +55,7 @@
55
55
  "./package.json": "./package.json"
56
56
  },
57
57
  "scripts": {
58
- "dev": "vite",
58
+ "dev": "vite --port 3001",
59
59
  "build": "vite build && node scripts/postbuild.mjs",
60
60
  "check:css": "bun scripts/check-css-scoped.mjs",
61
61
  "check:tokens": "bun scripts/check-tokens.mjs",