@elcrm/tooltip 0.1.0 → 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
@@ -69,16 +69,20 @@ import {
69
69
 
70
70
  ## CSS-переменные
71
71
 
72
+ Стили — CSS Modules с короткими классами (`r` корень, `t` пузырь). Цвета задаёт тема приложения; fallback в пакете нет.
73
+
72
74
  | Переменная | Назначение |
73
75
  | ----------------------- | ----------------- |
74
- | `--tooltip-background` | Фон |
75
- | `--tooltip-color` | Цвет текста |
76
- | `--tooltip-radius` | Скругление |
77
- | `--tooltip-max-width` | Макс. ширина |
78
- | `--tooltip-font-size` | Размер шрифта |
79
- | `--tooltip-padding` | Внутренние отступы |
80
- | `--tooltip-shadow` | Тень |
81
- | `--tooltip-gap` | Зазор до якоря |
76
+ | `--tooltip-bg` | Фон |
77
+ | `--tooltip-fg` | Цвет текста |
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` | Зазор до якоря |
82
86
 
83
87
  ## Поведение
84
88
 
package/dist/index.css CHANGED
@@ -1 +1 @@
1
- @charset "UTF-8";:root{--tooltip-background: #1e1f24;--tooltip-color: rgba(255, 255, 255, .92);--tooltip-radius: 10px;--tooltip-max-width: 280px;--tooltip-font-size: 13px;--tooltip-padding: 8px 10px;--tooltip-shadow: 0 8px 24px rgba(0, 0, 0, .28);--tooltip-gap: 8px}._t_ai3lm_13{position:fixed;box-sizing:border-box;max-width:var(--tooltip-max-width);padding:var(--tooltip-padding);border-radius:var(--tooltip-radius);background:var(--tooltip-background);color:var(--tooltip-color);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}._t_ai3lm_13[data-visible=true]{opacity:1}._t_ai3lm_13[data-align=left]{text-align:left}._t_ai3lm_13[data-align=center]{text-align:center}._t_ai3lm_13[data-align=right]{text-align:right}._t_ai3lm_13: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-background) transparent transparent transparent}._root_ai3lm_64{display:inline-flex;vertical-align:middle;max-width:100%}
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,159 +1,177 @@
1
- import P, { useId as A, useRef as v, useState as T, useCallback as X, useLayoutEffect as B, useEffect as D } from "react";
2
- import { createPortal as V } from "react-dom";
3
- import './index.css';const F = "0.1.0", J = {
4
- version: F
5
- }, K = "_t_ai3lm_13", Q = "_root_ai3lm_64", z = {
6
- t: K,
7
- root: Q
8
- }, Y = 1e3, U = 10;
9
- function R() {
10
- const e = globalThis;
11
- return e.elcrm || (e.elcrm = {}), e.elcrm.overlayZ || (e.elcrm.overlayZ = { seq: 0, active: /* @__PURE__ */ new Set() }), e.elcrm.overlayZ;
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);
12
19
  }
13
- function ee() {
14
- const e = R();
15
- e.seq += 1;
16
- const t = Y + e.seq * U;
17
- return e.active.add(t), t;
20
+ function D(t, e) {
21
+ return Math.min(Math.max(c, t), window.innerHeight - e - c);
18
22
  }
19
- function C(e) {
20
- const t = R();
21
- t.active.delete(e), t.active.size === 0 && (t.seq = 0);
23
+ function p(t, e) {
24
+ return Math.min(Math.max(W, t), e - W);
22
25
  }
23
- function oe() {
24
- const e = R();
25
- return e.active.size === 0 ? Y : Math.max(...e.active);
26
- }
27
- const n = 8, s = 8;
28
- function te(e, t, y) {
29
- const w = e.left + e.width / 2, d = e.top + e.height / 2;
30
- let o = 0, i = 0, u = w, l = 0, r = "";
31
- const m = (p) => Math.min(
32
- Math.max(s, p),
33
- window.innerWidth - t.width - s
34
- );
35
- switch (y) {
36
- case "top":
37
- o = e.top - t.height - n, i = m(w - t.width / 2), l = e.top - n, r = "", o < s && (o = e.bottom + n, l = e.bottom + n - 2, r = "rotate(180deg)");
38
- break;
39
- case "bottom":
40
- o = e.bottom + n, i = m(w - t.width / 2), l = e.bottom + n - 2, r = "rotate(180deg)", o + t.height > window.innerHeight - s && (o = e.top - t.height - n, l = e.top - n, r = "");
41
- break;
42
- case "left":
43
- o = Math.min(
44
- Math.max(s, d - t.height / 2),
45
- window.innerHeight - t.height - s
46
- ), i = e.left - t.width - n, u = e.left - n + 2, l = d, r = "rotate(270deg)", i < s && (i = e.right + n, u = e.right + n - 2, r = "rotate(90deg)");
47
- break;
48
- case "right":
49
- o = Math.min(
50
- Math.max(s, d - t.height / 2),
51
- window.innerHeight - t.height - s
52
- ), i = e.right + n, u = e.right + n - 2, l = d, r = "rotate(90deg)", i + t.width > window.innerWidth - s && (i = e.left - t.width - n, u = e.left - n + 2, r = "rotate(270deg)");
53
- break;
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
+ }
54
45
  }
55
- return { top: o, left: i, arrowX: u, arrowY: l, arrowR: r };
56
46
  }
57
- function ie({
58
- content: e,
59
- children: t,
60
- placement: y,
61
- orientation: w,
62
- textAlign: d = "center",
63
- delay: o = 180,
64
- delayHide: i = 60,
65
- className: u,
66
- disabled: l = !1,
67
- open: r
47
+ const X = 1e3, mt = 10;
48
+ function z() {
49
+ const t = globalThis;
50
+ return t.elcrm || (t.elcrm = {}), t.elcrm.overlayZ || (t.elcrm.overlayZ = { seq: 0, active: /* @__PURE__ */ new Set() }), t.elcrm.overlayZ;
51
+ }
52
+ function ht() {
53
+ const t = z();
54
+ t.seq += 1;
55
+ const e = X + t.seq * mt;
56
+ return t.active.add(e), e;
57
+ }
58
+ function N(t) {
59
+ const e = z();
60
+ e.active.delete(t), e.active.size === 0 && (e.seq = 0);
61
+ }
62
+ function bt() {
63
+ const t = z();
64
+ return t.active.size === 0 ? X : Math.max(...t.active);
65
+ }
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;
74
+ }
75
+ function xt({
76
+ content: t,
77
+ children: e,
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
68
86
  }) {
69
- const m = y ?? w ?? "top", p = A(), M = v(null), k = v(null), b = v(null), x = v(null), c = v(null), [G, L] = T(!1), [a, O] = T(null), [Z, S] = T(null), E = () => {
70
- b.current != null && (window.clearTimeout(b.current), b.current = null), x.current != null && (window.clearTimeout(x.current), x.current = null);
71
- }, _ = X(() => {
72
- l || e == null || e === "" || (E(), b.current = window.setTimeout(() => {
73
- L(!0);
74
- }, o));
75
- }, [e, o, l]), q = X(() => {
76
- r || (E(), x.current = window.setTimeout(() => {
77
- L(!1), O(null);
78
- }, i));
79
- }, [i, r]), f = r || G;
80
- B(() => {
81
- if (f) {
82
- if (c.current == null) {
83
- const g = ee();
84
- c.current = g, S(g);
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);
85
103
  }
86
104
  return;
87
105
  }
88
- c.current != null && (C(c.current), c.current = null, S(null));
89
- }, [f]), D(() => () => {
90
- E(), c.current != null && (C(c.current), c.current = null);
91
- }, []), B(() => {
92
- if (!f) return;
93
- const g = M.current, $ = k.current;
94
- if (!g || !$) return;
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;
95
113
  const h = () => {
96
- const W = g.getBoundingClientRect(), j = $.getBoundingClientRect();
97
- O(te(W, j, m));
114
+ const F = m.getBoundingClientRect(), J = $.getBoundingClientRect();
115
+ C(dt(F, J, R));
98
116
  };
99
117
  return h(), window.addEventListener("resize", h), window.addEventListener("scroll", h, !0), () => {
100
118
  window.removeEventListener("resize", h), window.removeEventListener("scroll", h, !0);
101
119
  };
102
- }, [f, m, e]);
103
- const H = a ? {
104
- top: a.top,
105
- left: a.left,
106
- zIndex: Z ?? 1e3,
107
- "--tooltip-arrow-x": `${a.arrowX}px`,
108
- "--tooltip-arrow-y": `${a.arrowY}px`,
109
- "--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`
110
126
  } : {
111
- // скрытый замер до первой позиции
112
127
  top: -9999,
113
128
  left: -9999,
114
- zIndex: Z ?? 1e3,
129
+ zIndex: S ?? 1e3,
115
130
  visibility: "hidden"
116
- }, N = f && typeof document < "u" ? V(
117
- /* @__PURE__ */ P.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(
118
138
  "div",
119
139
  {
120
- ref: k,
121
- id: p,
140
+ ref: L,
141
+ id: M,
122
142
  role: "tooltip",
123
- className: z.t,
124
- "data-visible": a ? "true" : "false",
125
- "data-align": d,
143
+ className: V,
126
144
  style: H
127
145
  },
128
- e
146
+ t
129
147
  ),
130
148
  document.body
131
149
  ) : null;
132
- return /* @__PURE__ */ P.createElement(
150
+ return /* @__PURE__ */ k.createElement(
133
151
  "span",
134
152
  {
135
- ref: M,
136
- className: u ? `${z.root} ${u}` : z.root,
137
- onMouseEnter: _,
138
- onMouseLeave: q,
139
- onFocus: _,
140
- onBlur: q,
141
- "aria-describedby": f ? p : 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
142
160
  },
143
- t,
144
- N
161
+ e,
162
+ _
145
163
  );
146
164
  }
147
- const le = () => null;
148
- function I() {
165
+ const Et = () => null;
166
+ function y() {
149
167
  return typeof globalThis < "u" ? globalThis : {};
150
168
  }
151
- I().elcrm || (I().elcrm = {});
152
- Object.assign(I().elcrm, { tooltip: J.version });
169
+ y().elcrm || (y().elcrm = {});
170
+ Object.assign(y().elcrm, { tooltip: et.version });
153
171
  export {
154
- le as Item,
155
- ie as Tooltip,
156
- ee as acquireOverlayZIndex,
157
- oe as peekOverlayZIndex,
158
- C as releaseOverlayZIndex
172
+ Et as Item,
173
+ xt as Tooltip,
174
+ ht as acquireOverlayZIndex,
175
+ bt as peekOverlayZIndex,
176
+ N as releaseOverlayZIndex
159
177
  };
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(n,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],o):(n=typeof globalThis<"u"?globalThis:n||self,o((n.elCRM=n.elCRM||{},n.elCRM.tooltip={}),n.React,n.ReactDOM))})(this,function(n,o,R){"use strict";var M=document.createElement("style");M.textContent=`@charset "UTF-8";:root{--tooltip-background: #1e1f24;--tooltip-color: rgba(255, 255, 255, .92);--tooltip-radius: 10px;--tooltip-max-width: 280px;--tooltip-font-size: 13px;--tooltip-padding: 8px 10px;--tooltip-shadow: 0 8px 24px rgba(0, 0, 0, .28);--tooltip-gap: 8px}._t_ai3lm_13{position:fixed;box-sizing:border-box;max-width:var(--tooltip-max-width);padding:var(--tooltip-padding);border-radius:var(--tooltip-radius);background:var(--tooltip-background);color:var(--tooltip-color);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}._t_ai3lm_13[data-visible=true]{opacity:1}._t_ai3lm_13[data-align=left]{text-align:left}._t_ai3lm_13[data-align=center]{text-align:center}._t_ai3lm_13[data-align=right]{text-align:right}._t_ai3lm_13: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-background) transparent transparent transparent}._root_ai3lm_64{display:inline-flex;vertical-align:middle;max-width:100%}
2
- /*$vite$:1*/`,document.head.appendChild(M);const Y={version:"0.1.0"},y={t:"_t_ai3lm_13",root:"_root_ai3lm_64"},O=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=O+t.seq*D;return t.active.add(e),e}function E(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?O:Math.max(...t.active)}const i=8,a=8;function H(t,e,z){const w=t.left+t.width/2,p=t.top+t.height/2;let l=0,s=0,u=w,d=0,r="";const g=x=>Math.min(Math.max(a,x),window.innerWidth-e.width-a);switch(z){case"top":l=t.top-e.height-i,s=g(w-e.width/2),d=t.top-i,r="",l<a&&(l=t.bottom+i,d=t.bottom+i-2,r="rotate(180deg)");break;case"bottom":l=t.bottom+i,s=g(w-e.width/2),d=t.bottom+i-2,r="rotate(180deg)",l+e.height>window.innerHeight-a&&(l=t.top-e.height-i,d=t.top-i,r="");break;case"left":l=Math.min(Math.max(a,p-e.height/2),window.innerHeight-e.height-a),s=t.left-e.width-i,u=t.left-i+2,d=p,r="rotate(270deg)",s<a&&(s=t.right+i,u=t.right+i-2,r="rotate(90deg)");break;case"right":l=Math.min(Math.max(a,p-e.height/2),window.innerHeight-e.height-a),s=t.right+i,u=t.right+i-2,d=p,r="rotate(90deg)",s+e.width>window.innerWidth-a&&(s=t.left-e.width-i,u=t.left-i+2,r="rotate(270deg)");break}return{top:l,left:s,arrowX:u,arrowY:d,arrowR:r}}function N({content:t,children:e,placement:z,orientation:w,textAlign:p="center",delay:l=180,delayHide:s=60,className:u,disabled:d=!1,open:r}){const g=z??w??"top",x=o.useId(),Z=o.useRef(null),C=o.useRef(null),b=o.useRef(null),_=o.useRef(null),c=o.useRef(null),[A,q]=o.useState(!1),[f,L]=o.useState(null),[$,P]=o.useState(null),I=()=>{b.current!=null&&(window.clearTimeout(b.current),b.current=null),_.current!=null&&(window.clearTimeout(_.current),_.current=null)},X=o.useCallback(()=>{d||t==null||t===""||(I(),b.current=window.setTimeout(()=>{q(!0)},l))},[t,l,d]),j=o.useCallback(()=>{r||(I(),_.current=window.setTimeout(()=>{q(!1),L(null)},s))},[s,r]),m=r||A;o.useLayoutEffect(()=>{if(m){if(c.current==null){const h=S();c.current=h,P(h)}return}c.current!=null&&(E(c.current),c.current=null,P(null))},[m]),o.useEffect(()=>()=>{I(),c.current!=null&&(E(c.current),c.current=null)},[]),o.useLayoutEffect(()=>{if(!m)return;const h=Z.current,B=C.current;if(!h||!B)return;const v=()=>{const V=h.getBoundingClientRect(),J=B.getBoundingClientRect();L(H(V,J,g))};return v(),window.addEventListener("resize",v),window.addEventListener("scroll",v,!0),()=>{window.removeEventListener("resize",v),window.removeEventListener("scroll",v,!0)}},[m,g,t]);const F=f?{top:f.top,left:f.left,zIndex:$??1e3,"--tooltip-arrow-x":`${f.arrowX}px`,"--tooltip-arrow-y":`${f.arrowY}px`,"--tooltip-arrow-r":f.arrowR||"none"}:{top:-9999,left:-9999,zIndex:$??1e3,visibility:"hidden"},U=m&&typeof document<"u"?R.createPortal(o.createElement("div",{ref:C,id:x,role:"tooltip",className:y.t,"data-visible":f?"true":"false","data-align":p,style:F},t),document.body):null;return o.createElement("span",{ref:Z,className:u?`${y.root} ${u}`:y.root,onMouseEnter:X,onMouseLeave:j,onFocus:X,onBlur:j,"aria-describedby":m?x:void 0},e,U)}const W=()=>null;function k(){return typeof globalThis<"u"?globalThis:{}}k().elcrm||(k().elcrm={}),Object.assign(k().elcrm,{tooltip:Y.version}),n.Item=W,n.Tooltip=N,n.acquireOverlayZIndex=S,n.peekOverlayZIndex=G,n.releaseOverlayZIndex=E,Object.defineProperty(n,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,16 +1,16 @@
1
1
  {
2
2
  "name": "@elcrm/tooltip",
3
- "version": "0.1.0",
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>",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/elcrm-lib/elcrm.tooltip.git"
10
+ "url": "git+https://elgit.ru/lib/elCRM.tooltip.git"
11
11
  },
12
12
  "bugs": {
13
- "url": "https://github.com/elcrm-lib/elcrm.tooltip/issues"
13
+ "url": "https://elgit.ru/lib/elCRM.tooltip/issues"
14
14
  },
15
15
  "homepage": "https://www.npmjs.com/package/@elcrm/tooltip",
16
16
  "publishConfig": {
@@ -30,7 +30,8 @@
30
30
  "portal"
31
31
  ],
32
32
  "sideEffects": [
33
- "**/*.css"
33
+ "**/*.css",
34
+ "**/*.module.css"
34
35
  ],
35
36
  "main": "./dist/index.umd.js",
36
37
  "module": "./dist/index.es.js",
@@ -54,11 +55,13 @@
54
55
  "./package.json": "./package.json"
55
56
  },
56
57
  "scripts": {
57
- "dev": "vite",
58
- "build": "vite build",
58
+ "dev": "vite --port 3001",
59
+ "build": "vite build && node scripts/postbuild.mjs",
60
+ "check:css": "bun scripts/check-css-scoped.mjs",
61
+ "check:tokens": "bun scripts/check-tokens.mjs",
59
62
  "test": "vitest run",
60
63
  "test:watch": "vitest",
61
- "prepublishOnly": "vitest run && vite build",
64
+ "prepublishOnly": "bun run check:css && bun run check:tokens && bun run test && bun run build",
62
65
  "pack:check": "npm pack --dry-run"
63
66
  },
64
67
  "peerDependencies": {
@@ -80,10 +83,10 @@
80
83
  "@types/react": "^18.2.66",
81
84
  "@types/react-dom": "^18.2.22",
82
85
  "@vitejs/plugin-react": "^4.3.1",
86
+ "elcrm": "file:../elCRM.cli",
83
87
  "jsdom": "^26.0.0",
84
88
  "react": "^18.2.0",
85
89
  "react-dom": "^18.2.0",
86
- "sass-embedded": "^1.85.1",
87
90
  "typescript": "^5.8.2",
88
91
  "vite": "^5.4.2",
89
92
  "vite-plugin-dts": "^4.0.3",