@nysds/nys-tooltip 1.21.0 → 1.21.1
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/dist/nys-tooltip.js +151 -125
- package/dist/nys-tooltip.js.map +1 -1
- package/package.json +2 -2
package/dist/nys-tooltip.js
CHANGED
|
@@ -1,53 +1,49 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { property as d, state as
|
|
1
|
+
import { LitElement as m, unsafeCSS as y, html as u } from "lit";
|
|
2
|
+
import { property as d, state as g } from "lit/decorators.js";
|
|
3
3
|
/*!
|
|
4
4
|
* █▄ █ █ █ █▀▀▀█ █▀▀▄ █▀▀▀█
|
|
5
5
|
* █ █ █ █▄▄▄█ ▀▀▀▄▄ █ █ ▀▀▀▄▄
|
|
6
6
|
* █ ▀█ █ █▄▄▄█ █▄▄▀ █▄▄▄█
|
|
7
7
|
*
|
|
8
|
-
* Tooltip Component v1.21.
|
|
8
|
+
* Tooltip Component v1.21.1
|
|
9
9
|
* Part of the New York State Design System
|
|
10
10
|
* Repository: https://github.com/its-hcd/nysds
|
|
11
11
|
* License: MIT
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
/*!
|
|
14
|
+
* New York State Design System v1.21.1
|
|
15
|
+
* Description: A design system for New York State's digital products.
|
|
16
|
+
* Repository: https://github.com/its-hcd/nysds
|
|
17
|
+
* License: MIT
|
|
18
|
+
*/
|
|
19
|
+
let v = 0;
|
|
20
|
+
function w(c) {
|
|
21
|
+
return `${c}-${Date.now()}-${v++}`;
|
|
16
22
|
}
|
|
17
|
-
|
|
18
|
-
class
|
|
23
|
+
const b = (c) => {
|
|
24
|
+
class t extends c {
|
|
19
25
|
get idPrefix() {
|
|
20
26
|
return this.localName || "nys-element";
|
|
21
27
|
}
|
|
22
28
|
ensureId() {
|
|
23
|
-
this.id || (this.id =
|
|
29
|
+
this.id || (this.id = w(this.idPrefix));
|
|
24
30
|
}
|
|
25
31
|
connectedCallback() {
|
|
26
32
|
super.connectedCallback(), this.ensureId();
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
|
-
return
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
static {
|
|
42
|
-
this.styles = m(x);
|
|
43
|
-
}
|
|
44
|
-
get position() {
|
|
45
|
-
return this._position;
|
|
46
|
-
}
|
|
47
|
-
set position(t) {
|
|
48
|
-
const e = this._position;
|
|
49
|
-
this._position = t, this.requestUpdate("position", e), this._internallyUpdatingPosition || (this._userHasSetPosition = t !== null, this._originalUserPosition = t);
|
|
50
|
-
}
|
|
35
|
+
return t;
|
|
36
|
+
}, x = /* @__PURE__ */ b(m), E = `:host{--_nys-tooltip-color: var(--nys-color-text-reverse, #ffffff);--_nys-tooltip-background-color: var(--nys-color-ink, #1b1b1b);--_nys-tooltip-border-radius: var(--nys-radius-md, 4px);--_nys-tooltip-font-family: var( --nys-font-family-ui, var( --nys-font-family-sans, "Proxima Nova", "Helvetica Neue", "Helvetica", "Arial", sans-serif ) );--_nys-tooltip-font-size: var(--nys-font-size-ui-sm, 14px);--_nys-tooltip-letter-spacing: var(--nys-font-letterspacing-ui-sm, .044px);--_nys-tooltip-line-height: var(--nys-font-lineheight-ui-sm, 24px)}.nys-tooltip__content{position:fixed;top:0;left:0;max-width:400px;width:max-content;max-height:120px;padding:var(--nys-space-50, 4px) var(--nys-space-100, 8px);background-color:var(--_nys-tooltip-background-color);border-radius:var(--_nys-tooltip-border-radius);cursor:auto;z-index:1}.nys-tooltip__inner{color:var(--_nys-tooltip-color);font-family:var(--_nys-tooltip-font-family);font-size:var(--_nys-tooltip-font-size);font-weight:400;line-height:var(--_nys-tooltip-line-height);letter-spacing:var(--_nys-tooltip-letter-spacing);white-space:normal;overflow-wrap:anywhere;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:4;line-clamp:4;-webkit-box-orient:vertical}.nys-tooltip__arrow{position:absolute;width:14px;height:6px;background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="15" height="6" viewBox="0 0 15 6" fill="none"><path d="M8.15079 5.44218C7.7763 5.76317 7.2237 5.76317 6.84921 5.44218L0.5 0H14.5L8.15079 5.44218Z" fill="%231B1B1B"/></svg>') no-repeat center}.nys-tooltip__content[active]{display:block}.fade-out{opacity:0;transition:opacity .2s ease-out}@media(prefers-reduced-motion:reduce){.fade-out{transition:none}}:host([position=top]) .nys-tooltip__arrow{top:100%;left:var(--arrow-offset-x, 50%);transform:translate(-50%)}:host([position=bottom]) .nys-tooltip__arrow{bottom:100%;left:var(--arrow-offset-x, 50%);transform:translate(-50%) rotate(180deg)}:host([position=left]) .nys-tooltip__arrow{left:100%;top:50%;transform:translateY(-50%) rotate(-90deg);margin-left:-4px}:host([position=right]) .nys-tooltip__arrow{right:100%;top:50%;transform:translateY(-50%) rotate(90deg);margin-right:-4px}:host([inverted]) .nys-tooltip__content{--_nys-tooltip-color: var(--nys-color-text, #1b1b1b);--_nys-tooltip-background-color: var(--nys-color-ink-reverse, #ffffff)}:host([inverted]) .nys-tooltip__arrow{background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="15" height="6" viewBox="0 0 15 6" fill="none"><path d="M8.15079 5.44218C7.7763 5.76317 7.2237 5.76317 6.84921 5.44218L0.5 0H14.5L8.15079 5.44218Z" fill="white"/></svg>') no-repeat center}@media(max-width:400px){.nys-tooltip__content{max-width:calc(100vw - 2rem)}}`;
|
|
37
|
+
var L = Object.defineProperty, P = Object.getOwnPropertyDescriptor, p = (c, t, e, i) => {
|
|
38
|
+
for (var o = i > 1 ? void 0 : i ? P(t, e) : t, s = c.length - 1, n; s >= 0; s--)
|
|
39
|
+
(n = c[s]) && (o = (i ? n(t, e, o) : n(o)) || o);
|
|
40
|
+
return i && o && L(t, e, o), o;
|
|
41
|
+
};
|
|
42
|
+
const f = class f extends x {
|
|
43
|
+
/**
|
|
44
|
+
* Lifecycle Methods
|
|
45
|
+
* --------------------------------------------------------------------------
|
|
46
|
+
*/
|
|
51
47
|
constructor() {
|
|
52
48
|
super(), this.id = "", this.text = "", this.inverted = !1, this.for = "", this._active = !1, this._userHasSetPosition = !1, this._originalUserPosition = null, this._internallyUpdatingPosition = !1, this._hideTimeout = null, this._position = null, this._resizeObserver = null, this._showTooltip = () => {
|
|
53
49
|
if (this._active = !0, this._addScrollListeners(), this._userHasSetPosition && this._originalUserPosition && this._doesPositionFit(this._originalUserPosition)) {
|
|
@@ -58,23 +54,36 @@ var c = class extends b {
|
|
|
58
54
|
}
|
|
59
55
|
this._autoPositionTooltip();
|
|
60
56
|
}, this._handleBlurOrMouseLeave = () => {
|
|
61
|
-
const t = this._getReferenceElement(), e = this.shadowRoot?.querySelector(
|
|
57
|
+
const t = this._getReferenceElement(), e = this.shadowRoot?.querySelector(
|
|
58
|
+
".nys-tooltip__content"
|
|
59
|
+
);
|
|
62
60
|
t !== document.activeElement && (!t || !e || this._triggerFadeOut(e));
|
|
63
61
|
}, this._cancelFadeOut = () => {
|
|
64
|
-
const t = this.shadowRoot?.querySelector(
|
|
62
|
+
const t = this.shadowRoot?.querySelector(
|
|
63
|
+
".nys-tooltip__content"
|
|
64
|
+
), e = this._getReferenceElement();
|
|
65
65
|
if (!t || !e) return;
|
|
66
|
-
const
|
|
67
|
-
!
|
|
66
|
+
const i = t.matches(":hover"), o = e.matches(":hover"), s = document.activeElement === e;
|
|
67
|
+
!i && !o && !s || (this._hideTimeout && (clearTimeout(this._hideTimeout), this._hideTimeout = null), t.classList.remove("fade-out"), this._active = !0);
|
|
68
68
|
}, this._handleScrollOrResize = () => {
|
|
69
69
|
!this._active || this._hideTimeout || this._showTooltip();
|
|
70
70
|
}, this._handleEscapeKey = (t) => {
|
|
71
71
|
if (t.key === "Escape" && this._active) {
|
|
72
72
|
this._active = !1, this._removeScrollListeners();
|
|
73
|
-
const e = this.shadowRoot?.querySelector(
|
|
73
|
+
const e = this.shadowRoot?.querySelector(
|
|
74
|
+
".nys-tooltip__content"
|
|
75
|
+
);
|
|
74
76
|
e && this._resetTooltipPositioningStyles(e);
|
|
75
77
|
}
|
|
76
78
|
};
|
|
77
79
|
}
|
|
80
|
+
get position() {
|
|
81
|
+
return this._position;
|
|
82
|
+
}
|
|
83
|
+
set position(t) {
|
|
84
|
+
const e = this._position;
|
|
85
|
+
this._position = t, this.requestUpdate("position", e), this._internallyUpdatingPosition || (this._userHasSetPosition = t !== null, this._originalUserPosition = t);
|
|
86
|
+
}
|
|
78
87
|
connectedCallback() {
|
|
79
88
|
super.connectedCallback(), window.addEventListener("keydown", this._handleEscapeKey);
|
|
80
89
|
}
|
|
@@ -98,6 +107,7 @@ var c = class extends b {
|
|
|
98
107
|
this._active = !1, this._removeScrollListeners(), this._positionStartingBase(), this._resetTooltipPositioningStyles(t), t.classList.remove("fade-out"), this._hideTimeout = null;
|
|
99
108
|
}, 200));
|
|
100
109
|
}
|
|
110
|
+
// Listen to window scroll so a focus tooltip can auto position even when user move across the page
|
|
101
111
|
_addScrollListeners() {
|
|
102
112
|
window.addEventListener("scroll", this._handleScrollOrResize, !0), this._resizeObserver = new ResizeObserver(() => {
|
|
103
113
|
this._handleScrollOrResize();
|
|
@@ -106,38 +116,55 @@ var c = class extends b {
|
|
|
106
116
|
_removeScrollListeners() {
|
|
107
117
|
window.removeEventListener("scroll", this._handleScrollOrResize, !0), this._resizeObserver?.disconnect(), this._resizeObserver = null;
|
|
108
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Functions
|
|
121
|
+
* --------------------------------------------------------------------------
|
|
122
|
+
*/
|
|
109
123
|
_getReferenceElement() {
|
|
110
124
|
const t = this.for;
|
|
111
125
|
if (!t) return null;
|
|
112
126
|
let e = document.getElementById(t);
|
|
113
127
|
if (e) return e;
|
|
114
|
-
const
|
|
128
|
+
const i = (o) => {
|
|
115
129
|
for (const s of Array.from(o.querySelectorAll("*"))) {
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
118
|
-
const r =
|
|
130
|
+
const n = s.shadowRoot;
|
|
131
|
+
if (n) {
|
|
132
|
+
const r = n.getElementById(t);
|
|
119
133
|
if (r) return r;
|
|
120
|
-
const l = n
|
|
134
|
+
const l = i(n);
|
|
121
135
|
if (l) return l;
|
|
122
136
|
}
|
|
123
137
|
}
|
|
124
138
|
return null;
|
|
125
139
|
};
|
|
126
|
-
return
|
|
140
|
+
return i(document);
|
|
127
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Programmatically associates the trigger with the tooltip via
|
|
144
|
+
* `aria-describedby`, per the WAI-ARIA Tooltip pattern. The tooltip bubble
|
|
145
|
+
* (`.nys-tooltip__content`) carries `role="tooltip"` and `id={this.id}`, so we
|
|
146
|
+
* point the trigger's `aria-describedby` at that id. Preserves any existing
|
|
147
|
+
* `aria-describedby` tokens the consumer already set, and avoids duplicates.
|
|
148
|
+
*/
|
|
128
149
|
_associateTrigger(t) {
|
|
129
150
|
if (!this.text?.trim()) return;
|
|
130
151
|
const e = (t.getAttribute("aria-describedby") || "").split(/\s+/).filter(Boolean);
|
|
131
152
|
e.includes(this.id) || (e.push(this.id), t.setAttribute("aria-describedby", e.join(" ")));
|
|
132
153
|
}
|
|
154
|
+
// We need to pass `ariaLabel` or `ariaDescription` to the nys-components so they can announce both their label and the tooltip's text
|
|
133
155
|
async _passAria(t) {
|
|
134
156
|
const e = t.tagName.toLowerCase();
|
|
135
|
-
if (e === "nys-icon")
|
|
157
|
+
if (e === "nys-icon")
|
|
158
|
+
t.setAttribute("ariaLabel", `Hint: ${this.text}`);
|
|
136
159
|
else if (e === "nys-button") {
|
|
137
|
-
const
|
|
138
|
-
o.includes(this.id) || (o.push(this.id),
|
|
160
|
+
const i = t, o = (i.ariaDescribedBy || "").split(/\s+/).filter(Boolean);
|
|
161
|
+
o.includes(this.id) || (o.push(this.id), i.ariaDescribedBy = o.join(" "));
|
|
139
162
|
}
|
|
140
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* In React, the reference element found is often the native HTML element within the nys-component.
|
|
166
|
+
* Therefore, this function accounts for the closest NYS component ancestor that supports a tooltip prop.
|
|
167
|
+
*/
|
|
141
168
|
_applyTooltipPropToFormComponent(t) {
|
|
142
169
|
const e = t.tagName.toLowerCase();
|
|
143
170
|
if (e.startsWith("nys-")) {
|
|
@@ -148,21 +175,26 @@ var c = class extends b {
|
|
|
148
175
|
"tooltip" in t && (t.tooltip = this.text);
|
|
149
176
|
}
|
|
150
177
|
}
|
|
178
|
+
// Applies focus behavior to an otherwise non focus element (i.e. nys-icon is non focusable by default)
|
|
151
179
|
async _applyFocusBehavior(t) {
|
|
152
180
|
if (t.style.cursor = "pointer", t.tagName.toLowerCase() === "nys-icon") {
|
|
153
181
|
"updateComplete" in t && await t.updateComplete;
|
|
154
|
-
const
|
|
155
|
-
|
|
182
|
+
const i = t.shadowRoot?.querySelector("svg");
|
|
183
|
+
i && i.setAttribute("tabindex", "0");
|
|
156
184
|
}
|
|
157
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Checks if the tooltip fits inside the viewport on the given side of the trigger.
|
|
188
|
+
* Used for auto-positioning. Ignores text overflow for now.
|
|
189
|
+
*/
|
|
158
190
|
_doesPositionFit(t) {
|
|
159
|
-
const e = this._getReferenceElement(),
|
|
160
|
-
if (!e || !
|
|
161
|
-
const o = e.getBoundingClientRect(), s =
|
|
162
|
-
top: o.top -
|
|
163
|
-
left: o.left -
|
|
164
|
-
bottom: window.innerHeight - o.bottom -
|
|
165
|
-
right: window.innerWidth - o.right -
|
|
191
|
+
const e = this._getReferenceElement(), i = this.shadowRoot?.querySelector(".nys-tooltip__content");
|
|
192
|
+
if (!e || !i || t == null) return;
|
|
193
|
+
const o = e.getBoundingClientRect(), s = i.getBoundingClientRect(), n = 8, r = {
|
|
194
|
+
top: o.top - n,
|
|
195
|
+
left: o.left - n,
|
|
196
|
+
bottom: window.innerHeight - o.bottom - n,
|
|
197
|
+
right: window.innerWidth - o.right - n
|
|
166
198
|
};
|
|
167
199
|
return {
|
|
168
200
|
top: r.top >= s.height,
|
|
@@ -172,19 +204,24 @@ var c = class extends b {
|
|
|
172
204
|
}[t];
|
|
173
205
|
}
|
|
174
206
|
_userPositionTooltip() {
|
|
175
|
-
const t = this.shadowRoot?.querySelector(
|
|
207
|
+
const t = this.shadowRoot?.querySelector(
|
|
208
|
+
".nys-tooltip__content"
|
|
209
|
+
), e = this._getReferenceElement();
|
|
176
210
|
t && e && (this._positionTooltipElement(e, t, this.position), this._shiftTooltipIntoViewport(t));
|
|
177
211
|
}
|
|
212
|
+
// Calculates the best placement based on available space (flips placement if it doesn't fit)
|
|
178
213
|
async _autoPositionTooltip() {
|
|
179
|
-
const t = this._getReferenceElement(), e = this.shadowRoot?.querySelector(
|
|
214
|
+
const t = this._getReferenceElement(), e = this.shadowRoot?.querySelector(
|
|
215
|
+
".nys-tooltip__content"
|
|
216
|
+
);
|
|
180
217
|
if (!t || !e) return;
|
|
181
|
-
const
|
|
182
|
-
top:
|
|
183
|
-
left:
|
|
184
|
-
bottom: window.innerHeight -
|
|
185
|
-
right: window.innerWidth -
|
|
218
|
+
const i = t.getBoundingClientRect(), o = 8, s = {
|
|
219
|
+
top: i.top - o,
|
|
220
|
+
left: i.left - o,
|
|
221
|
+
bottom: window.innerHeight - i.bottom - o,
|
|
222
|
+
right: window.innerWidth - i.right - o
|
|
186
223
|
};
|
|
187
|
-
let
|
|
224
|
+
let n = [
|
|
188
225
|
"top",
|
|
189
226
|
"bottom",
|
|
190
227
|
"right",
|
|
@@ -192,61 +229,48 @@ var c = class extends b {
|
|
|
192
229
|
];
|
|
193
230
|
if (this._userHasSetPosition && this._originalUserPosition) {
|
|
194
231
|
const a = this._originalUserPosition;
|
|
195
|
-
a === "left" ?
|
|
196
|
-
"left",
|
|
197
|
-
"right",
|
|
198
|
-
"top",
|
|
199
|
-
"bottom"
|
|
200
|
-
] : a === "right" ? i = [
|
|
201
|
-
"right",
|
|
202
|
-
"left",
|
|
203
|
-
"top",
|
|
204
|
-
"bottom"
|
|
205
|
-
] : a === "top" ? i = [
|
|
206
|
-
"top",
|
|
207
|
-
"bottom",
|
|
208
|
-
"right",
|
|
209
|
-
"left"
|
|
210
|
-
] : a === "bottom" && (i = [
|
|
211
|
-
"bottom",
|
|
212
|
-
"top",
|
|
213
|
-
"right",
|
|
214
|
-
"left"
|
|
215
|
-
]);
|
|
216
|
-
}
|
|
217
|
-
for (const a of i) if (this._doesPositionFit(a)) {
|
|
218
|
-
this._setInternalPosition(a), await this.updateComplete, this._positionTooltipElement(t, e, a), this._shiftTooltipIntoViewport(e);
|
|
219
|
-
return;
|
|
232
|
+
a === "left" ? n = ["left", "right", "top", "bottom"] : a === "right" ? n = ["right", "left", "top", "bottom"] : a === "top" ? n = ["top", "bottom", "right", "left"] : a === "bottom" && (n = ["bottom", "top", "right", "left"]);
|
|
220
233
|
}
|
|
234
|
+
for (const a of n)
|
|
235
|
+
if (this._doesPositionFit(a)) {
|
|
236
|
+
this._setInternalPosition(a), await this.updateComplete, this._positionTooltipElement(t, e, a), this._shiftTooltipIntoViewport(e);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
221
239
|
let r = "top", l = s.top;
|
|
222
|
-
for (const a of
|
|
240
|
+
for (const a of n)
|
|
241
|
+
s[a] > l && (l = s[a], r = a);
|
|
223
242
|
this._setInternalPosition(r), await this.updateComplete, this._positionTooltipElement(t, e, r), this._shiftTooltipIntoViewport(e);
|
|
224
243
|
}
|
|
225
244
|
_positionStartingBase() {
|
|
226
|
-
const t = this.shadowRoot?.querySelector(
|
|
245
|
+
const t = this.shadowRoot?.querySelector(
|
|
246
|
+
".nys-tooltip__content"
|
|
247
|
+
);
|
|
227
248
|
t && (t.style.top = "0px", t.style.left = "0px");
|
|
228
249
|
}
|
|
229
|
-
_positionTooltipElement(t, e,
|
|
230
|
-
const o = t.getBoundingClientRect(), s = e.getBoundingClientRect(),
|
|
250
|
+
_positionTooltipElement(t, e, i) {
|
|
251
|
+
const o = t.getBoundingClientRect(), s = e.getBoundingClientRect(), n = 8;
|
|
231
252
|
let r = 0, l = 0;
|
|
232
|
-
switch (
|
|
253
|
+
switch (i) {
|
|
233
254
|
case "top":
|
|
234
|
-
r = o.top - s.height -
|
|
255
|
+
r = o.top - s.height - n, l = o.left + o.width / 2 - s.width / 2;
|
|
235
256
|
break;
|
|
236
257
|
case "bottom":
|
|
237
|
-
r = o.bottom +
|
|
258
|
+
r = o.bottom + n, l = o.left + o.width / 2 - s.width / 2;
|
|
238
259
|
break;
|
|
239
260
|
case "left":
|
|
240
|
-
r = o.top + o.height / 2 - s.height / 2, l = o.left - s.width -
|
|
261
|
+
r = o.top + o.height / 2 - s.height / 2, l = o.left - s.width - n;
|
|
241
262
|
break;
|
|
242
263
|
case "right":
|
|
243
|
-
r = o.top + o.height / 2 - s.height / 2, l = o.right +
|
|
264
|
+
r = o.top + o.height / 2 - s.height / 2, l = o.right + n;
|
|
244
265
|
break;
|
|
245
266
|
default:
|
|
246
|
-
r = o.top - s.height -
|
|
267
|
+
r = o.top - s.height - n, l = o.left + o.width / 2 - s.width / 2;
|
|
268
|
+
break;
|
|
247
269
|
}
|
|
248
270
|
e.style.top = `${r}px`, e.style.left = `${l}px`;
|
|
249
271
|
}
|
|
272
|
+
// In some iframes (like Storybook's) or embedded containers , parent elements may have CSS transforms applied, creating a new coordinate context.
|
|
273
|
+
// This function removes such transforms to prevent them from affecting tooltip positioning calculations.
|
|
250
274
|
applyInverseTransform() {
|
|
251
275
|
document.querySelectorAll('div[scale="1"]').forEach((t) => {
|
|
252
276
|
t.style.transform = "none";
|
|
@@ -255,21 +279,23 @@ var c = class extends b {
|
|
|
255
279
|
_setInternalPosition(t) {
|
|
256
280
|
this._internallyUpdatingPosition = !0, this.position = t, this._internallyUpdatingPosition = !1;
|
|
257
281
|
}
|
|
282
|
+
// Determines if text of tooltip over-extends outside of viewport edge and adjust tooltip for horizontal overflow
|
|
258
283
|
_shiftTooltipIntoViewport(t) {
|
|
259
284
|
const e = this._getReferenceElement();
|
|
260
285
|
if (!e) return;
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
const l = t.getBoundingClientRect(), a = (s - l.left) / l.width,
|
|
264
|
-
t.style.setProperty("--arrow-offset-x", `${
|
|
286
|
+
const i = e.getBoundingClientRect(), o = t.getBoundingClientRect(), s = i.left + i.width / 2, n = o.left < 0, r = o.right > window.innerWidth;
|
|
287
|
+
n ? (t.style.left = "10px", t.style.transform = "none") : r && (t.style.right = "0px", t.style.left = "auto", t.style.transform = "none");
|
|
288
|
+
const l = t.getBoundingClientRect(), a = (s - l.left) / l.width, _ = Math.max(0, Math.min(1, a)) * 100;
|
|
289
|
+
t.style.setProperty("--arrow-offset-x", `${_}%`);
|
|
265
290
|
}
|
|
291
|
+
// Reposition tooltip back to original set position (e.g. top, left, bottom, right) to avoid positioning issue base on last position
|
|
266
292
|
_resetTooltipPositioningStyles(t) {
|
|
267
293
|
t.style.left = "", t.style.right = "", t.style.top = "", t.style.transform = "", t.style.removeProperty("--arrow-offset-x");
|
|
268
294
|
}
|
|
269
295
|
render() {
|
|
270
|
-
return
|
|
296
|
+
return u`
|
|
271
297
|
<div class="nys-tooltip__main">
|
|
272
|
-
${this.text?.trim() ?
|
|
298
|
+
${this.text?.trim() ? u`<div
|
|
273
299
|
id=${this.id}
|
|
274
300
|
class="nys-tooltip__content"
|
|
275
301
|
role="tooltip"
|
|
@@ -284,28 +310,28 @@ var c = class extends b {
|
|
|
284
310
|
`;
|
|
285
311
|
}
|
|
286
312
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
p([
|
|
293
|
-
type:
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
313
|
+
f.styles = y(E);
|
|
314
|
+
let h = f;
|
|
315
|
+
p([
|
|
316
|
+
d({ type: String, reflect: !0 })
|
|
317
|
+
], h.prototype, "id", 2);
|
|
318
|
+
p([
|
|
319
|
+
d({ type: String })
|
|
320
|
+
], h.prototype, "text", 2);
|
|
321
|
+
p([
|
|
322
|
+
d({ type: Boolean, reflect: !0 })
|
|
323
|
+
], h.prototype, "inverted", 2);
|
|
324
|
+
p([
|
|
325
|
+
d({ type: String })
|
|
326
|
+
], h.prototype, "for", 2);
|
|
327
|
+
p([
|
|
328
|
+
g()
|
|
329
|
+
], h.prototype, "_active", 2);
|
|
298
330
|
p([
|
|
299
|
-
d({
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}),
|
|
303
|
-
h("design:type", Object),
|
|
304
|
-
h("design:paramtypes", [])
|
|
305
|
-
], c.prototype, "position", null);
|
|
306
|
-
customElements.get("nys-tooltip") || customElements.define("nys-tooltip", c);
|
|
331
|
+
d({ type: String, reflect: !0 })
|
|
332
|
+
], h.prototype, "position", 1);
|
|
333
|
+
customElements.get("nys-tooltip") || customElements.define("nys-tooltip", h);
|
|
307
334
|
export {
|
|
308
|
-
|
|
335
|
+
h as NysTooltip
|
|
309
336
|
};
|
|
310
|
-
|
|
311
|
-
//# sourceMappingURL=nys-tooltip.js.map
|
|
337
|
+
//# sourceMappingURL=nys-tooltip.js.map
|
package/dist/nys-tooltip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nys-tooltip.js","names":["u"],"sources":["../../internals/dist/index.js","../src/nys-tooltip.scss?inline","../src/nys-tooltip.ts"],"sourcesContent":["import { LitElement as u } from \"lit\";\n/*!\n * New York State Design System v1.21.0\n * Description: A design system for New York State's digital products.\n * Repository: https://github.com/its-hcd/nysds\n * License: MIT\n */\nvar y = 0;\nfunction f(e) {\n return `${e}-${Date.now()}-${y++}`;\n}\nvar p = {\n labelledby: \"ariaLabelledByElements\",\n describedby: \"ariaDescribedByElements\"\n}, v = {\n labelledby: \"ariaLabel\",\n describedby: \"ariaDescription\"\n};\nfunction A(e) {\n return \"ariaDescribedByElements\" in e;\n}\nfunction R(e) {\n return e === \"errormessage\" ? \"aria-errormessage\" : `aria-${e}`;\n}\nfunction d(e) {\n return e.filter((r) => !!r);\n}\nfunction _(e) {\n return e.map((r) => (r.id || (r.id = f(\"nys-ref\")), r.id));\n}\nfunction V(e, r, a) {\n const t = d(a), n = R(r);\n t.length ? e.setAttribute(n, _(t).join(\" \")) : e.removeAttribute(n);\n}\nfunction x(e, r, a, t, n) {\n const i = d(t), s = p[a], l = r;\n if (s && A(r)) {\n l[s] = i.length ? i : null;\n return;\n }\n const o = v[a];\n if (!o) return;\n const c = n ?? (i.length ? i.map((m) => m.textContent?.trim() ?? \"\").filter(Boolean).join(\" \") : \"\");\n o in l ? l[o] = c || null : c ? e.setAttribute(a === \"labelledby\" ? \"aria-label\" : \"aria-description\", c) : e.removeAttribute(a === \"labelledby\" ? \"aria-label\" : \"aria-description\");\n}\nvar E = {\n labelledby: \"ariaLabelledByElements\",\n describedby: \"ariaDescribedByElements\"\n}, C = {\n labelledby: \"aria-label\",\n describedby: \"aria-description\"\n};\nfunction L(e, r, a) {\n const t = d(a), n = E[r], i = C[r], s = e;\n if (n && n in e && (s[n] = t.length ? t : null), !i) return;\n const l = t.map((o) => o.textContent?.trim() ?? \"\").filter(Boolean).join(\" \");\n l ? e.setAttribute(i, l) : e.removeAttribute(i);\n}\nvar b = (e) => {\n class r extends e {\n get idPrefix() {\n return this.localName || \"nys-element\";\n }\n ensureId() {\n this.id || (this.id = f(this.idPrefix));\n }\n connectedCallback() {\n super.connectedCallback(), this.ensureId();\n }\n }\n return r;\n}, P = /* @__PURE__ */ b(u), h = (e) => {\n class r extends b(e) {\n constructor(...t) {\n super(...t), this.__internals = null;\n }\n get internals() {\n if (this.__internals) return this.__internals;\n if (typeof this.attachInternals == \"function\") try {\n this.__internals = this.attachInternals();\n } catch {\n this.__internals = null;\n }\n return this.__internals;\n }\n get defaultRole() {\n return null;\n }\n setHostAria(t, n) {\n const i = this.internals;\n if (i && t in i) {\n i[t] = n;\n return;\n }\n const s = g(t);\n n === null ? this.removeAttribute(s) : this.setAttribute(s, n);\n }\n reflectDefaultSemantics() {\n const t = this.defaultRole;\n t && this.setHostAria(\"role\", t);\n }\n connectedCallback() {\n super.connectedCallback(), this.reflectDefaultSemantics();\n }\n }\n return r;\n};\nfunction g(e) {\n if (e === \"role\") return \"role\";\n const r = e.replace(/^aria/, \"\");\n return \"aria-\" + r.charAt(0).toLowerCase() + r.slice(1);\n}\nvar T = /* @__PURE__ */ h(u), I = (e) => {\n class r extends h(e) {\n static {\n this.formAssociated = !0;\n }\n setFormValue(t) {\n this.internals?.setFormValue(t ?? null);\n }\n setValidityFromState(t, n, i) {\n const s = this.internals;\n if (!s) return;\n const l = Object.values(t).some(Boolean);\n l ? s.setValidity(t, n ?? \"Invalid value\", i) : s.setValidity({}), this.setHostAria(\"ariaInvalid\", l ? \"true\" : \"false\");\n }\n clearValidity() {\n this.internals?.setValidity({}), this.setHostAria(\"ariaInvalid\", \"false\");\n }\n checkValidity() {\n return this.internals?.checkValidity() ?? !0;\n }\n reportValidity() {\n return this.internals?.reportValidity() ?? !0;\n }\n formResetCallback() {\n this.clearValidity();\n }\n }\n return r;\n}, w = /* @__PURE__ */ I(u);\nfunction O(e) {\n const r = e.tagName.toLowerCase(), a = /* @__PURE__ */ new Set(), t = (n) => {\n n.querySelectorAll(\"*\").forEach((i) => {\n const s = i.tagName.toLowerCase();\n s.startsWith(\"nys-\") && s !== r && !customElements.get(s) && a.add(s), i.shadowRoot && t(i.shadowRoot);\n });\n };\n return e.shadowRoot && t(e.shadowRoot), t(e), [...a].sort();\n}\nexport {\n I as FormControlMixin,\n b as IdentifiedMixin,\n P as NysElement,\n w as NysFormControlElement,\n T as NysReflectsAriaElement,\n h as ReflectsAriaMixin,\n V as associateControl,\n L as associateControlRefs,\n x as associateHost,\n O as findUnregisteredChildren,\n f as generateId,\n A as supportsElementRefs\n};\n\n//# sourceMappingURL=index.js.map",":host {\n /* Global Tooltip Styles */\n --_nys-tooltip-color: var(--nys-color-text-reverse, #ffffff);\n --_nys-tooltip-background-color: var(--nys-color-ink, #1b1b1b);\n --_nys-tooltip-border-radius: var(--nys-radius-md, 4px);\n --_nys-tooltip-font-family: var(\n --nys-font-family-ui,\n var(\n --nys-font-family-sans,\n \"Proxima Nova\",\n \"Helvetica Neue\",\n \"Helvetica\",\n \"Arial\",\n sans-serif\n )\n );\n --_nys-tooltip-font-size: var(--nys-font-size-ui-sm, 14px);\n --_nys-tooltip-letter-spacing: var(--nys-font-letterspacing-ui-sm, 0.044px);\n --_nys-tooltip-line-height: var(--nys-font-lineheight-ui-sm, 24px);\n}\n\n.nys-tooltip__content {\n position: fixed;\n top: 0;\n left: 0;\n max-width: 400px;\n width: max-content;\n max-height: 120px;\n padding: var(--nys-space-50, 4px) var(--nys-space-100, 8px);\n background-color: var(--_nys-tooltip-background-color);\n border-radius: var(--_nys-tooltip-border-radius);\n cursor: auto;\n z-index: 1;\n}\n\n.nys-tooltip__inner {\n color: var(--_nys-tooltip-color);\n font-family: var(--_nys-tooltip-font-family);\n font-size: var(--_nys-tooltip-font-size);\n font-weight: 400;\n line-height: var(--_nys-tooltip-line-height);\n letter-spacing: var(--_nys-tooltip-letter-spacing);\n white-space: normal;\n overflow-wrap: anywhere; // Used to be word-wrap: break-word, but that is deprecated\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 4;\n line-clamp: 4;\n -webkit-box-orient: vertical;\n}\n\n/* Tooltip Arrow (default) */\n.nys-tooltip__arrow {\n position: absolute;\n width: 14px;\n height: 6px;\n background: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"6\" viewBox=\"0 0 15 6\" fill=\"none\"><path d=\"M8.15079 5.44218C7.7763 5.76317 7.2237 5.76317 6.84921 5.44218L0.5 0H14.5L8.15079 5.44218Z\" fill=\"%231B1B1B\"/></svg>')\n no-repeat center;\n}\n\n.nys-tooltip__content[active] {\n display: block;\n}\n\n.fade-out {\n opacity: 0;\n transition: opacity 0.2s ease-out;\n}\n\n/* Respect users who prefer reduced motion: drop the fade transition. */\n@media (prefers-reduced-motion: reduce) {\n .fade-out {\n transition: none;\n }\n}\n\n/* ===================== POSITIONING ===================== */\n\n/* Top */\n:host([position=\"top\"]) .nys-tooltip__arrow {\n top: 100%;\n left: var(--arrow-offset-x, 50%);\n transform: translateX(-50%);\n}\n\n/* Bottom */\n:host([position=\"bottom\"]) .nys-tooltip__arrow {\n bottom: 100%;\n left: var(--arrow-offset-x, 50%);\n transform: translateX(-50%) rotate(180deg);\n}\n\n/* Left */\n:host([position=\"left\"]) .nys-tooltip__arrow {\n left: 100%;\n top: 50%;\n transform: translateY(-50%) rotate(-90deg);\n margin-left: -4px;\n}\n\n/* Right */\n:host([position=\"right\"]) .nys-tooltip__arrow {\n right: 100%;\n top: 50%;\n transform: translateY(-50%) rotate(90deg);\n margin-right: -4px;\n}\n\n:host([inverted]) .nys-tooltip__content {\n --_nys-tooltip-color: var(--nys-color-text, #1b1b1b);\n --_nys-tooltip-background-color: var(--nys-color-ink-reverse, #ffffff);\n}\n\n:host([inverted]) .nys-tooltip__arrow {\n background: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"6\" viewBox=\"0 0 15 6\" fill=\"none\"><path d=\"M8.15079 5.44218C7.7763 5.76317 7.2237 5.76317 6.84921 5.44218L0.5 0H14.5L8.15079 5.44218Z\" fill=\"white\"/></svg>')\n no-repeat center;\n}\n\n@media (width <= 400px) {\n .nys-tooltip__content {\n max-width: calc(100vw - 2rem); /* 2rem = 32px = 16px margin on each side */\n }\n}\n","import { html, unsafeCSS } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { NysElement } from \"@nysds/internals\";\n// @ts-ignore: SCSS module imported via bundler as inline\nimport styles from \"./nys-tooltip.scss?inline\";\n\n/**\n * Shows contextual help text on hover/focus. Auto-positions to stay within viewport and supports keyboard dismiss.\n *\n * Link to a trigger element via `for` attribute matching the trigger's `id`. Tooltip appears on hover or focus\n * and dismisses on blur, mouse leave, or Escape key. Use for supplementary info only—not critical content.\n *\n * @accessibility\n * - Linked to trigger element via `for` attribute (must match trigger's `id`).\n * - `role=\"tooltip\"` with dynamic `aria-hidden` based on visibility.\n * - Keyboard accessible: Tab to trigger, Enter/Space shows tooltip, Escape dismisses.\n * - Screen readers announce tooltip text when visible.\n * - Visual focus indicators on trigger elements meet WCAG 2.2 AA standards.\n * - Auto-positioning respects viewport bounds to prevent content loss.\n *\n * @summary Contextual tooltip with auto-positioning, keyboard support, and screen reader integration.\n * @element nys-tooltip\n *\n * @example Basic\n * ```html\n * <div style=\"display: flex; justify-content: center; gap: 5px; padding: 40px;\">\n * <nys-tooltip for=\"my-button\" text=\"I am a tooltip.\"></nys-tooltip>\n * <nys-button id=\"my-button\" label=\"Hover Me\"></nys-button>\n * </div>\n * ```\n *\n * @example Position\n * ```html\n * <div style=\"display: flex; justify-content: center; gap: 5px; padding: 40px;\">\n * <p>Hover over the icon</p>\n * <nys-tooltip\n * for=\"my-icon2\"\n * text=\"I am a tooltip.\"\n * position=\"right\"\n * >\n * </nys-tooltip>\n * <nys-icon id=\"my-icon2\" name=\"info\" size=\"3xl\"></nys-icon>\n * </div>\n * ```\n *\n * @example Inverted\n * ```html\n * <div style=\"background-color: #1b1b1b; color: #ffffff; padding: 40px; display: flex; gap: 5px\">\n * <p>Hover over the icon</p>\n * <nys-tooltip\n * for=\"my-tooltip3\"\n * text=\"I am a tooltip.\"\n * inverted\n * >\n * </nys-tooltip>\n * <nys-icon id=\"my-tooltip3\" name=\"info\" size=\"3xl\"></nys-icon>\n * </div>\n * ```\n */\n\nexport class NysTooltip extends NysElement {\n static styles = unsafeCSS(styles);\n\n /** Unique identifier. Auto-generated if not provided. */\n @property({ type: String, reflect: true }) id = \"\";\n\n /** Tooltip content text. Required. */\n @property({ type: String }) text = \"\";\n\n /** Adjusts colors for dark backgrounds. */\n @property({ type: Boolean, reflect: true }) inverted = false;\n\n /** ID of the trigger element to attach this tooltip to. Required. */\n @property({ type: String }) for = \"\";\n\n // Track if tooltip is active (hovered or focused)\n @state()\n private _active = false;\n\n // Track if user set position is set explicitly\n private _userHasSetPosition = false;\n private _originalUserPosition: typeof this._position | null = null;\n // Internal flag to prevent dynamic positioning when not needed\n private _internallyUpdatingPosition = false;\n // Flag for hiding the timeout\n private _hideTimeout: number | null = null;\n\n // Position Logic\n private _position: \"top\" | \"bottom\" | \"left\" | \"right\" | null = null;\n\n // Resize observer to manipulate tooltip position on page\n private _resizeObserver: ResizeObserver | null = null;\n\n /**\n * Preferred position relative to trigger. Auto-adjusts if space is insufficient.\n * @default null (auto-positioned based on available space)\n */\n @property({ type: String, reflect: true })\n get position() {\n return this._position;\n }\n\n set position(value) {\n const oldVal = this._position;\n this._position = value;\n this.requestUpdate(\"position\", oldVal);\n\n // The \"_internallyUpdatingPosition\" flag allows user's set position to take preference\n if (!this._internallyUpdatingPosition) {\n this._userHasSetPosition = value !== null;\n this._originalUserPosition = value;\n }\n }\n\n /**\n * Lifecycle Methods\n * --------------------------------------------------------------------------\n */\n\n constructor() {\n super();\n }\n\n connectedCallback() {\n // super.connectedCallback() (NysElement) assigns an id when one\n // is not provided, preserving the \"nys-tooltip-<ts>-<n>\" shape. The\n // role=\"tooltip\" intentionally stays on the inner .nys-tooltip__content\n // element (so the tooltip bubble — not the host — is the described-by\n // target), so this component keeps defaultRole = null.\n super.connectedCallback();\n\n window.addEventListener(\"keydown\", this._handleEscapeKey);\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\".nys-tooltip__content\");\n\n if (ref && tooltip) {\n ref.removeEventListener(\"mouseenter\", this._showTooltip);\n ref.removeEventListener(\"mouseenter\", this._cancelFadeOut);\n ref.removeEventListener(\"mouseleave\", this._handleBlurOrMouseLeave);\n ref.removeEventListener(\"focusin\", this._showTooltip);\n ref.removeEventListener(\"focusout\", this._handleBlurOrMouseLeave);\n tooltip.removeEventListener(\"mouseenter\", this._cancelFadeOut);\n tooltip.removeEventListener(\"mouseleave\", this._handleBlurOrMouseLeave);\n }\n window.removeEventListener(\"keydown\", this._handleEscapeKey);\n }\n\n async firstUpdated() {\n await this.updateComplete;\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\".nys-tooltip__content\");\n\n if (!ref || !tooltip) return;\n\n this.applyInverseTransform();\n this._associateTrigger(ref);\n this._applyTooltipPropToFormComponent(ref);\n\n if (\n ref.tagName.toLowerCase() === \"nys-button\" ||\n ref.tagName.toLowerCase() === \"nys-icon\"\n ) {\n this._applyFocusBehavior(ref);\n ref.addEventListener(\"mouseenter\", this._showTooltip);\n ref.addEventListener(\"mouseenter\", this._cancelFadeOut);\n ref.addEventListener(\"mouseleave\", this._handleBlurOrMouseLeave);\n ref.addEventListener(\"focusin\", this._showTooltip);\n ref.addEventListener(\"focusout\", this._handleBlurOrMouseLeave);\n tooltip.addEventListener(\"mouseenter\", this._cancelFadeOut);\n tooltip.addEventListener(\"mouseleave\", this._handleBlurOrMouseLeave);\n }\n }\n\n updated(changedProps: Map<string, unknown>) {\n super.updated(changedProps);\n\n const ref = this._getReferenceElement();\n if (!ref) return;\n\n this._positionStartingBase();\n\n // Accounts for tooltip's text change (for code editor changes & VO)\n if (changedProps.has(\"text\")) {\n this._applyTooltipPropToFormComponent(ref);\n if (this._active) {\n this.updateComplete.then(() => this._showTooltip());\n }\n }\n }\n\n /**\n * Event Handlers\n * --------------------------------------------------------------------------\n */\n\n // When toggling tooltip, check if user has set position to give it preference it space allows. Otherwise dynamically position tooltip.\n private _showTooltip = () => {\n this._active = true;\n this._addScrollListeners();\n\n // Try to honor user's original preference first\n if (this._userHasSetPosition && this._originalUserPosition) {\n if (this._doesPositionFit(this._originalUserPosition)) {\n this.position = this._originalUserPosition;\n // Check if current tooltip position overflows to edge of screen\n this.updateComplete.then(() => {\n this._userPositionTooltip();\n });\n return;\n }\n }\n\n // Otherwise fall back to auto logic\n this._autoPositionTooltip();\n };\n\n private _handleBlurOrMouseLeave = () => {\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n\n if (ref === document.activeElement) return;\n if (!ref || !tooltip) return;\n\n this._triggerFadeOut(tooltip);\n };\n\n private _triggerFadeOut(tooltip: HTMLElement) {\n if (!tooltip || this._hideTimeout) return;\n\n tooltip.classList.add(\"fade-out\");\n\n this._hideTimeout = window.setTimeout(() => {\n this._active = false;\n this._removeScrollListeners();\n this._positionStartingBase();\n this._resetTooltipPositioningStyles(tooltip);\n\n tooltip.classList.remove(\"fade-out\");\n this._hideTimeout = null;\n }, 200);\n }\n\n private _cancelFadeOut = () => {\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n const ref = this._getReferenceElement();\n\n if (!tooltip || !ref) return;\n\n const isPointerInsideTooltip = tooltip.matches(\":hover\");\n const isPointerInsideRef = ref.matches(\":hover\");\n\n const isTouched = document.activeElement === ref;\n\n if (!isPointerInsideTooltip && !isPointerInsideRef && !isTouched) {\n return;\n }\n\n if (this._hideTimeout) {\n clearTimeout(this._hideTimeout);\n this._hideTimeout = null;\n }\n\n tooltip.classList.remove(\"fade-out\");\n this._active = true;\n };\n\n // Listen to window scroll so a focus tooltip can auto position even when user move across the page\n private _addScrollListeners() {\n window.addEventListener(\"scroll\", this._handleScrollOrResize, true);\n this._resizeObserver = new ResizeObserver(() => {\n this._handleScrollOrResize();\n });\n this._resizeObserver.observe(document.documentElement);\n }\n\n private _removeScrollListeners() {\n window.removeEventListener(\"scroll\", this._handleScrollOrResize, true);\n this._resizeObserver?.disconnect();\n this._resizeObserver = null;\n }\n\n private _handleScrollOrResize = () => {\n if (!this._active || this._hideTimeout) return;\n\n this._showTooltip();\n };\n\n private _handleEscapeKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\" && this._active) {\n this._active = false;\n this._removeScrollListeners();\n\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n if (tooltip) {\n this._resetTooltipPositioningStyles(tooltip);\n }\n }\n };\n\n /**\n * Functions\n * --------------------------------------------------------------------------\n */\n\n private _getReferenceElement() {\n const targetId = this.for;\n if (!targetId) return null;\n\n // lightDOM search\n let htmlElement = document.getElementById(targetId);\n if (htmlElement) return htmlElement;\n\n // Search recursively through shadow DOMs (e.g. for nys-label within other component's shadowDOM)\n const findInShadows = (root: ParentNode): HTMLElement | null => {\n for (const el of Array.from(root.querySelectorAll(\"*\"))) {\n const shadowElement = el.shadowRoot;\n if (shadowElement) {\n const found = shadowElement.getElementById(targetId);\n if (found) return found;\n\n const deeper = findInShadows(shadowElement);\n if (deeper) return deeper;\n }\n }\n return null;\n };\n\n return findInShadows(document);\n }\n\n /**\n * Programmatically associates the trigger with the tooltip via\n * `aria-describedby`, per the WAI-ARIA Tooltip pattern. The tooltip bubble\n * (`.nys-tooltip__content`) carries `role=\"tooltip\"` and `id={this.id}`, so we\n * point the trigger's `aria-describedby` at that id. Preserves any existing\n * `aria-describedby` tokens the consumer already set, and avoids duplicates.\n */\n private _associateTrigger(el: HTMLElement) {\n if (!this.text?.trim()) return;\n const existing = (el.getAttribute(\"aria-describedby\") || \"\")\n .split(/\\s+/)\n .filter(Boolean);\n if (!existing.includes(this.id)) {\n existing.push(this.id);\n el.setAttribute(\"aria-describedby\", existing.join(\" \"));\n }\n }\n\n // We need to pass `ariaLabel` or `ariaDescription` to the nys-components so they can announce both their label and the tooltip's text\n private async _passAria(el: HTMLElement) {\n const tagName = el.tagName.toLowerCase();\n\n if (tagName === \"nys-icon\") {\n // nys-icon has a real `ariaLabel` property whose default Lit attribute\n // name (\"arialabel\") matches what setAttribute(\"ariaLabel\", ...)\n // actually writes, so this reaches the icon's rendered <svg>.\n el.setAttribute(\"ariaLabel\", `Hint: ${this.text}`);\n } else if (tagName === \"nys-button\") {\n // nys-button has no ariaLabel/ariaDescription prop, so setAttribute here\n // reached nothing — and setting the plain aria-describedby *attribute*\n // (what _associateTrigger does above) doesn't reach it either, since the\n // host has no role and never maps its own light-DOM ARIA into the\n // internal <button>. Route through the real `ariaDescribedBy` *property*\n // instead, pointing at this tooltip's own id — the same id\n // _associateTrigger already builds toward — so nys-button renders a\n // working aria-describedby on its real internal <button>.\n const button = el as unknown as { ariaDescribedBy?: string };\n const existing = (button.ariaDescribedBy || \"\")\n .split(/\\s+/)\n .filter(Boolean);\n if (!existing.includes(this.id)) {\n existing.push(this.id);\n button.ariaDescribedBy = existing.join(\" \");\n }\n }\n }\n\n /**\n * In React, the reference element found is often the native HTML element within the nys-component.\n * Therefore, this function accounts for the closest NYS component ancestor that supports a tooltip prop.\n */\n private _applyTooltipPropToFormComponent(ref: HTMLElement) {\n const tagName = ref.tagName.toLowerCase();\n if (!tagName.startsWith(\"nys-\")) return;\n\n if (tagName === \"nys-button\" || tagName === \"nys-icon\") {\n // Already handled elsewhere in this component; we just ensure we attach listeners\n this._applyFocusBehavior(ref);\n this._passAria(ref);\n return;\n }\n\n if (\"tooltip\" in ref) {\n ref.tooltip = this.text;\n }\n }\n\n // Applies focus behavior to an otherwise non focus element (i.e. nys-icon is non focusable by default)\n private async _applyFocusBehavior(el: HTMLElement) {\n el.style.cursor = \"pointer\";\n const tagName = el.tagName.toLowerCase();\n\n if (tagName === \"nys-icon\") {\n if (\"updateComplete\" in el) {\n await (el as any).updateComplete;\n }\n const svg = el.shadowRoot?.querySelector(\"svg\");\n if (svg) {\n svg.setAttribute(\"tabindex\", \"0\");\n }\n }\n }\n\n /**\n * Checks if the tooltip fits inside the viewport on the given side of the trigger.\n * Used for auto-positioning. Ignores text overflow for now.\n */\n private _doesPositionFit(position: typeof this._position) {\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\".nys-tooltip__content\");\n\n if (!ref || !tooltip || position == null) return;\n\n const refRect = ref.getBoundingClientRect();\n const tooltipRect = tooltip.getBoundingClientRect();\n\n // Define some margin buffer between tooltip and trigger (to avoid touching the edges too tightly)\n const margin = 8;\n\n // Available space on each side relative to trigger rect and viewport\n const spaceAvailable = {\n top: refRect.top - margin,\n left: refRect.left - margin,\n bottom: window.innerHeight - refRect.bottom - margin,\n right: window.innerWidth - refRect.right - margin,\n };\n\n // Check if tooltip fits on each side (compare available space vs tooltip size)\n const fits = {\n top: spaceAvailable.top >= tooltipRect.height,\n bottom: spaceAvailable.bottom >= tooltipRect.height,\n left: spaceAvailable.left >= tooltipRect.width,\n right: spaceAvailable.right >= tooltipRect.width,\n };\n\n return fits[position];\n }\n\n private _userPositionTooltip() {\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n const ref = this._getReferenceElement();\n if (tooltip && ref) {\n this._positionTooltipElement(ref, tooltip, this.position);\n this._shiftTooltipIntoViewport(tooltip);\n }\n }\n\n // Calculates the best placement based on available space (flips placement if it doesn't fit)\n private async _autoPositionTooltip() {\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n\n if (!ref || !tooltip) return;\n\n const refRect = ref.getBoundingClientRect();\n const margin = 8;\n\n const spaceAvailable = {\n top: refRect.top - margin,\n left: refRect.left - margin,\n bottom: window.innerHeight - refRect.bottom - margin,\n right: window.innerWidth - refRect.right - margin,\n };\n\n // Default tryOrder for auto mode\n let tryOrder: Array<keyof typeof spaceAvailable> = [\n \"top\",\n \"bottom\",\n \"right\",\n \"left\",\n ];\n\n // If user explicitly set a preferred position (even if it didn’t fit),\n // favor it first before trying others\n if (this._userHasSetPosition && this._originalUserPosition) {\n const userPosition = this._originalUserPosition;\n if (userPosition === \"left\") {\n tryOrder = [\"left\", \"right\", \"top\", \"bottom\"];\n } else if (userPosition === \"right\") {\n tryOrder = [\"right\", \"left\", \"top\", \"bottom\"];\n } else if (userPosition === \"top\") {\n tryOrder = [\"top\", \"bottom\", \"right\", \"left\"];\n } else if (userPosition === \"bottom\") {\n tryOrder = [\"bottom\", \"top\", \"right\", \"left\"];\n }\n }\n\n // 1) Try to find the first side that fits\n for (const pos of tryOrder) {\n if (this._doesPositionFit(pos)) {\n this._setInternalPosition(pos);\n await this.updateComplete;\n this._positionTooltipElement(ref, tooltip, pos);\n this._shiftTooltipIntoViewport(tooltip);\n return;\n }\n }\n\n // 2) Fallback: pick the side with the most space\n let bestPosition: keyof typeof spaceAvailable = \"top\";\n let maxSpace = spaceAvailable.top;\n\n for (const pos of tryOrder) {\n if (spaceAvailable[pos] > maxSpace) {\n maxSpace = spaceAvailable[pos];\n bestPosition = pos;\n }\n }\n this._setInternalPosition(bestPosition);\n await this.updateComplete;\n this._positionTooltipElement(ref, tooltip, bestPosition);\n this._shiftTooltipIntoViewport(tooltip);\n }\n\n private _positionStartingBase() {\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n\n if (!tooltip) return;\n\n tooltip.style.top = \"0px\";\n tooltip.style.left = \"0px\";\n }\n\n private _positionTooltipElement(\n ref: HTMLElement,\n tooltip: HTMLElement,\n bestPosition: typeof this._position,\n ) {\n const refRect = ref.getBoundingClientRect();\n const tooltipRect = tooltip.getBoundingClientRect();\n const margin = 8;\n\n let top = 0;\n let left = 0;\n\n switch (bestPosition) {\n case \"top\":\n top = refRect.top - tooltipRect.height - margin;\n left = refRect.left + refRect.width / 2 - tooltipRect.width / 2;\n break;\n case \"bottom\":\n top = refRect.bottom + margin;\n left = refRect.left + refRect.width / 2 - tooltipRect.width / 2;\n break;\n case \"left\":\n top = refRect.top + refRect.height / 2 - tooltipRect.height / 2;\n left = refRect.left - tooltipRect.width - margin;\n break;\n case \"right\":\n top = refRect.top + refRect.height / 2 - tooltipRect.height / 2;\n left = refRect.right + margin;\n break;\n default:\n // Default to top\n top = refRect.top - tooltipRect.height - margin;\n left = refRect.left + refRect.width / 2 - tooltipRect.width / 2;\n break;\n }\n\n tooltip.style.top = `${top}px`;\n tooltip.style.left = `${left}px`;\n }\n\n // In some iframes (like Storybook's) or embedded containers , parent elements may have CSS transforms applied, creating a new coordinate context.\n // This function removes such transforms to prevent them from affecting tooltip positioning calculations.\n private applyInverseTransform() {\n document.querySelectorAll('div[scale=\"1\"]').forEach((el) => {\n (el as HTMLElement).style.transform = \"none\";\n });\n }\n\n private _setInternalPosition(bestPosition: typeof this._position) {\n this._internallyUpdatingPosition = true;\n this.position = bestPosition;\n this._internallyUpdatingPosition = false;\n }\n\n // Determines if text of tooltip over-extends outside of viewport edge and adjust tooltip for horizontal overflow\n private _shiftTooltipIntoViewport(tooltip: HTMLElement) {\n const ref = this._getReferenceElement();\n if (!ref) return;\n\n const refRect = ref.getBoundingClientRect();\n const tooltipRect = tooltip.getBoundingClientRect();\n\n const refCenter = refRect.left + refRect.width / 2;\n\n const overflowLeft = tooltipRect.left < 0;\n const overflowRight = tooltipRect.right > window.innerWidth;\n\n // Tooltip is past the viewport edge, shift it inwards\n if (overflowLeft) {\n tooltip.style.left = \"10px\";\n tooltip.style.transform = \"none\";\n } else if (overflowRight) {\n tooltip.style.right = \"0px\";\n tooltip.style.left = \"auto\";\n tooltip.style.transform = \"none\";\n }\n\n // Recalculate tooltip rect after any shift\n const newTooltipRect = tooltip.getBoundingClientRect();\n\n // Arrow offset relative to tooltip width to maintain accuracy on zoom and out-of-bounds\n const arrowOffsetRatio =\n (refCenter - newTooltipRect.left) / newTooltipRect.width;\n const arrowOffsetPercent = Math.max(0, Math.min(1, arrowOffsetRatio)) * 100;\n\n tooltip.style.setProperty(\"--arrow-offset-x\", `${arrowOffsetPercent}%`);\n }\n\n // Reposition tooltip back to original set position (e.g. top, left, bottom, right) to avoid positioning issue base on last position\n private _resetTooltipPositioningStyles(tooltip: HTMLElement) {\n tooltip.style.left = \"\";\n tooltip.style.right = \"\";\n tooltip.style.top = \"\";\n tooltip.style.transform = \"\";\n tooltip.style.removeProperty(\"--arrow-offset-x\");\n }\n\n render() {\n return html`\n <div class=\"nys-tooltip__main\">\n ${this.text?.trim()\n ? html`<div\n id=${this.id}\n class=\"nys-tooltip__content\"\n role=\"tooltip\"\n aria-hidden=${this._active && !this._hideTimeout\n ? \"false\"\n : \"true\"}\n ?active=${this._active}\n style=\"visibility: ${this._active ? \"visible\" : \"hidden\"}; \"\n >\n <div class=\"nys-tooltip__inner\">${this.text}</div>\n <span class=\"nys-tooltip__arrow\"></span>\n </div>`\n : \"\"}\n </div>\n `;\n }\n}\n\nif (!customElements.get(\"nys-tooltip\")) {\n customElements.define(\"nys-tooltip\", NysTooltip);\n}\n"],"mappings":";;;;;;;;;;;;AAOA,IAAI,IAAI;AACR,SAAS,EAAE,GAAG;AACZ,SAAO,GAAG,CAAA,IAAK,KAAK,IAAI,CAAA,IAAK,GAAA;AAC/B;AAgDA,IAAI,IAAA,CAAK,MAAM;AAAA,EACb,MAAM,UAAU,EAAE;AAAA,IAChB,IAAI,WAAW;AACb,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IACA,WAAW;AACT,WAAK,OAAO,KAAK,KAAK,EAAE,KAAK,QAAQ;AAAA,IACvC;AAAA,IACA,oBAAoB;AAClB,YAAM,kBAAkB,GAAG,KAAK,SAAS;AAAA,IAC3C;AAAA,EACF;AACA,SAAO;AACT,GAAG,IAAoB,gBAAA,EAAEA,CAAC;;;;;;;;;;AEX1B,IAAa,IAAb,cAAgC,EAAW;AAAA;AACzB,SAAA,SAAA,EAAU,CAAM;AAAA;EAoChC,IACI,WAAW;AACb,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,SAAS,GAAO;AAClB,UAAM,IAAS,KAAK;AACpB,SAAK,YAAY,GACjB,KAAK,cAAc,YAAY,CAAM,GAGhC,KAAK,gCACR,KAAK,sBAAsB,MAAU,MACrC,KAAK,wBAAwB;AAAA,EAEjC;AAAA,EAOA,cAAc;AACZ,UAAM,GAxDwC,KAAA,KAAA,IAGb,KAAA,OAAA,IAGoB,KAA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AA;AAGzC,EAAA,CAAA,EAAS,EAAE,MAAM,OAAO,CAAC,GAAA,EAAA,eAAA,MAAA,CAAA,GAAA,EAAA,WAAA,OAAA,MAAA;AAGzB,EAAA,CAAA,EAAM,GAAA,EAAA,eAAA,MAAA,CAAA,GAAA,EAAA,WAAA,WAAA,MAAA;;EAqBN,EAAS;AAAA,IAAE,MAAM;AAAA,IAAQ,SAAS;AAAA,EAAK,CAAC;AAAA;;;AA4jBtC,eAAe,IAAI,aAAa,KACnC,eAAe,OAAO,eAAe,CAAU"}
|
|
1
|
+
{"version":3,"file":"nys-tooltip.js","sources":["../../internals/dist/index.js","../src/nys-tooltip.ts"],"sourcesContent":["import { LitElement as u } from \"lit\";\n/*!\n * New York State Design System v1.21.1\n * Description: A design system for New York State's digital products.\n * Repository: https://github.com/its-hcd/nysds\n * License: MIT\n */\nlet y = 0;\nfunction f(e) {\n return `${e}-${Date.now()}-${y++}`;\n}\nconst p = {\n labelledby: \"ariaLabelledByElements\",\n describedby: \"ariaDescribedByElements\"\n}, A = {\n labelledby: \"ariaLabel\",\n describedby: \"ariaDescription\"\n};\nfunction R(e) {\n return \"ariaDescribedByElements\" in e;\n}\nfunction _(e) {\n return e === \"errormessage\" ? \"aria-errormessage\" : `aria-${e}`;\n}\nfunction d(e) {\n return e.filter((t) => !!t);\n}\nfunction E(e) {\n return e.map((t) => (t.id || (t.id = f(\"nys-ref\")), t.id));\n}\nfunction V(e, t, n) {\n const i = d(n), r = _(t);\n i.length ? e.setAttribute(r, E(i).join(\" \")) : e.removeAttribute(r);\n}\nfunction x(e, t, n, i, r) {\n const s = d(i), a = p[n], l = t;\n if (a && R(t)) {\n l[a] = s.length ? s : null;\n return;\n }\n const o = A[n];\n if (!o) return;\n const c = r ?? (s.length ? s.map((m) => m.textContent?.trim() ?? \"\").filter(Boolean).join(\" \") : \"\");\n o in l ? l[o] = c || null : c ? e.setAttribute(\n n === \"labelledby\" ? \"aria-label\" : \"aria-description\",\n c\n ) : e.removeAttribute(\n n === \"labelledby\" ? \"aria-label\" : \"aria-description\"\n );\n}\nconst g = {\n labelledby: \"ariaLabelledByElements\",\n describedby: \"ariaDescribedByElements\"\n}, C = {\n labelledby: \"aria-label\",\n describedby: \"aria-description\"\n};\nfunction L(e, t, n) {\n const i = d(n), r = g[t], s = C[t], a = e;\n if (r && r in e && (a[r] = i.length ? i : null), !s) return;\n const l = i.map((o) => o.textContent?.trim() ?? \"\").filter(Boolean).join(\" \");\n l ? e.setAttribute(s, l) : e.removeAttribute(s);\n}\nconst b = (e) => {\n class t extends e {\n get idPrefix() {\n return this.localName || \"nys-element\";\n }\n ensureId() {\n this.id || (this.id = f(this.idPrefix));\n }\n connectedCallback() {\n super.connectedCallback(), this.ensureId();\n }\n }\n return t;\n}, P = /* @__PURE__ */ b(u), h = (e) => {\n class t extends b(e) {\n constructor() {\n super(...arguments), this.__internals = null;\n }\n get internals() {\n if (this.__internals) return this.__internals;\n if (typeof this.attachInternals == \"function\")\n try {\n this.__internals = this.attachInternals();\n } catch {\n this.__internals = null;\n }\n return this.__internals;\n }\n get defaultRole() {\n return null;\n }\n setHostAria(i, r) {\n const s = this.internals;\n if (s && i in s) {\n s[i] = r;\n return;\n }\n const a = v(i);\n r === null ? this.removeAttribute(a) : this.setAttribute(a, r);\n }\n reflectDefaultSemantics() {\n const i = this.defaultRole;\n i && this.setHostAria(\"role\", i);\n }\n connectedCallback() {\n super.connectedCallback(), this.reflectDefaultSemantics();\n }\n }\n return t;\n};\nfunction v(e) {\n if (e === \"role\") return \"role\";\n const t = e.replace(/^aria/, \"\");\n return \"aria-\" + t.charAt(0).toLowerCase() + t.slice(1);\n}\nconst T = /* @__PURE__ */ h(u), I = (e) => {\n const n = class n extends h(e) {\n setFormValue(r) {\n this.internals?.setFormValue(r ?? null);\n }\n setValidityFromState(r, s, a) {\n const l = this.internals;\n if (!l) return;\n const o = Object.values(r).some(Boolean);\n o ? l.setValidity(r, s ?? \"Invalid value\", a) : l.setValidity({}), this.setHostAria(\"ariaInvalid\", o ? \"true\" : \"false\");\n }\n clearValidity() {\n this.internals?.setValidity({}), this.setHostAria(\"ariaInvalid\", \"false\");\n }\n checkValidity() {\n return this.internals?.checkValidity() ?? !0;\n }\n reportValidity() {\n return this.internals?.reportValidity() ?? !0;\n }\n formResetCallback() {\n this.clearValidity();\n }\n };\n n.formAssociated = !0;\n let t = n;\n return t;\n}, w = /* @__PURE__ */ I(u);\nfunction O(e) {\n const t = e.tagName.toLowerCase(), n = /* @__PURE__ */ new Set(), i = (r) => {\n r.querySelectorAll(\"*\").forEach((s) => {\n const a = s.tagName.toLowerCase();\n a.startsWith(\"nys-\") && a !== t && !customElements.get(a) && n.add(a), s.shadowRoot && i(s.shadowRoot);\n });\n };\n return e.shadowRoot && i(e.shadowRoot), i(e), [...n].sort();\n}\nexport {\n I as FormControlMixin,\n b as IdentifiedMixin,\n P as NysElement,\n w as NysFormControlElement,\n T as NysReflectsAriaElement,\n h as ReflectsAriaMixin,\n V as associateControl,\n L as associateControlRefs,\n x as associateHost,\n O as findUnregisteredChildren,\n f as generateId,\n R as supportsElementRefs\n};\n//# sourceMappingURL=index.js.map\n","import { html, unsafeCSS } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { NysElement } from \"@nysds/internals\";\n// @ts-ignore: SCSS module imported via bundler as inline\nimport styles from \"./nys-tooltip.scss?inline\";\n\n/**\n * Shows contextual help text on hover/focus. Auto-positions to stay within viewport and supports keyboard dismiss.\n *\n * Link to a trigger element via `for` attribute matching the trigger's `id`. Tooltip appears on hover or focus\n * and dismisses on blur, mouse leave, or Escape key. Use for supplementary info only—not critical content.\n *\n * @accessibility\n * - Linked to trigger element via `for` attribute (must match trigger's `id`).\n * - `role=\"tooltip\"` with dynamic `aria-hidden` based on visibility.\n * - Keyboard accessible: Tab to trigger, Enter/Space shows tooltip, Escape dismisses.\n * - Screen readers announce tooltip text when visible.\n * - Visual focus indicators on trigger elements meet WCAG 2.2 AA standards.\n * - Auto-positioning respects viewport bounds to prevent content loss.\n *\n * @summary Contextual tooltip with auto-positioning, keyboard support, and screen reader integration.\n * @element nys-tooltip\n *\n * @example Basic\n * ```html\n * <div style=\"display: flex; justify-content: center; gap: 5px; padding: 40px;\">\n * <nys-tooltip for=\"my-button\" text=\"I am a tooltip.\"></nys-tooltip>\n * <nys-button id=\"my-button\" label=\"Hover Me\"></nys-button>\n * </div>\n * ```\n *\n * @example Position\n * ```html\n * <div style=\"display: flex; justify-content: center; gap: 5px; padding: 40px;\">\n * <p>Hover over the icon</p>\n * <nys-tooltip\n * for=\"my-icon2\"\n * text=\"I am a tooltip.\"\n * position=\"right\"\n * >\n * </nys-tooltip>\n * <nys-icon id=\"my-icon2\" name=\"info\" size=\"3xl\"></nys-icon>\n * </div>\n * ```\n *\n * @example Inverted\n * ```html\n * <div style=\"background-color: #1b1b1b; color: #ffffff; padding: 40px; display: flex; gap: 5px\">\n * <p>Hover over the icon</p>\n * <nys-tooltip\n * for=\"my-tooltip3\"\n * text=\"I am a tooltip.\"\n * inverted\n * >\n * </nys-tooltip>\n * <nys-icon id=\"my-tooltip3\" name=\"info\" size=\"3xl\"></nys-icon>\n * </div>\n * ```\n */\n\nexport class NysTooltip extends NysElement {\n static styles = unsafeCSS(styles);\n\n /** Unique identifier. Auto-generated if not provided. */\n @property({ type: String, reflect: true }) id = \"\";\n\n /** Tooltip content text. Required. */\n @property({ type: String }) text = \"\";\n\n /** Adjusts colors for dark backgrounds. */\n @property({ type: Boolean, reflect: true }) inverted = false;\n\n /** ID of the trigger element to attach this tooltip to. Required. */\n @property({ type: String }) for = \"\";\n\n // Track if tooltip is active (hovered or focused)\n @state()\n private _active = false;\n\n // Track if user set position is set explicitly\n private _userHasSetPosition = false;\n private _originalUserPosition: typeof this._position | null = null;\n // Internal flag to prevent dynamic positioning when not needed\n private _internallyUpdatingPosition = false;\n // Flag for hiding the timeout\n private _hideTimeout: number | null = null;\n\n // Position Logic\n private _position: \"top\" | \"bottom\" | \"left\" | \"right\" | null = null;\n\n // Resize observer to manipulate tooltip position on page\n private _resizeObserver: ResizeObserver | null = null;\n\n /**\n * Preferred position relative to trigger. Auto-adjusts if space is insufficient.\n * @default null (auto-positioned based on available space)\n */\n @property({ type: String, reflect: true })\n get position() {\n return this._position;\n }\n\n set position(value) {\n const oldVal = this._position;\n this._position = value;\n this.requestUpdate(\"position\", oldVal);\n\n // The \"_internallyUpdatingPosition\" flag allows user's set position to take preference\n if (!this._internallyUpdatingPosition) {\n this._userHasSetPosition = value !== null;\n this._originalUserPosition = value;\n }\n }\n\n /**\n * Lifecycle Methods\n * --------------------------------------------------------------------------\n */\n\n constructor() {\n super();\n }\n\n connectedCallback() {\n // super.connectedCallback() (NysElement) assigns an id when one\n // is not provided, preserving the \"nys-tooltip-<ts>-<n>\" shape. The\n // role=\"tooltip\" intentionally stays on the inner .nys-tooltip__content\n // element (so the tooltip bubble — not the host — is the described-by\n // target), so this component keeps defaultRole = null.\n super.connectedCallback();\n\n window.addEventListener(\"keydown\", this._handleEscapeKey);\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\".nys-tooltip__content\");\n\n if (ref && tooltip) {\n ref.removeEventListener(\"mouseenter\", this._showTooltip);\n ref.removeEventListener(\"mouseenter\", this._cancelFadeOut);\n ref.removeEventListener(\"mouseleave\", this._handleBlurOrMouseLeave);\n ref.removeEventListener(\"focusin\", this._showTooltip);\n ref.removeEventListener(\"focusout\", this._handleBlurOrMouseLeave);\n tooltip.removeEventListener(\"mouseenter\", this._cancelFadeOut);\n tooltip.removeEventListener(\"mouseleave\", this._handleBlurOrMouseLeave);\n }\n window.removeEventListener(\"keydown\", this._handleEscapeKey);\n }\n\n async firstUpdated() {\n await this.updateComplete;\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\".nys-tooltip__content\");\n\n if (!ref || !tooltip) return;\n\n this.applyInverseTransform();\n this._associateTrigger(ref);\n this._applyTooltipPropToFormComponent(ref);\n\n if (\n ref.tagName.toLowerCase() === \"nys-button\" ||\n ref.tagName.toLowerCase() === \"nys-icon\"\n ) {\n this._applyFocusBehavior(ref);\n ref.addEventListener(\"mouseenter\", this._showTooltip);\n ref.addEventListener(\"mouseenter\", this._cancelFadeOut);\n ref.addEventListener(\"mouseleave\", this._handleBlurOrMouseLeave);\n ref.addEventListener(\"focusin\", this._showTooltip);\n ref.addEventListener(\"focusout\", this._handleBlurOrMouseLeave);\n tooltip.addEventListener(\"mouseenter\", this._cancelFadeOut);\n tooltip.addEventListener(\"mouseleave\", this._handleBlurOrMouseLeave);\n }\n }\n\n updated(changedProps: Map<string, unknown>) {\n super.updated(changedProps);\n\n const ref = this._getReferenceElement();\n if (!ref) return;\n\n this._positionStartingBase();\n\n // Accounts for tooltip's text change (for code editor changes & VO)\n if (changedProps.has(\"text\")) {\n this._applyTooltipPropToFormComponent(ref);\n if (this._active) {\n this.updateComplete.then(() => this._showTooltip());\n }\n }\n }\n\n /**\n * Event Handlers\n * --------------------------------------------------------------------------\n */\n\n // When toggling tooltip, check if user has set position to give it preference it space allows. Otherwise dynamically position tooltip.\n private _showTooltip = () => {\n this._active = true;\n this._addScrollListeners();\n\n // Try to honor user's original preference first\n if (this._userHasSetPosition && this._originalUserPosition) {\n if (this._doesPositionFit(this._originalUserPosition)) {\n this.position = this._originalUserPosition;\n // Check if current tooltip position overflows to edge of screen\n this.updateComplete.then(() => {\n this._userPositionTooltip();\n });\n return;\n }\n }\n\n // Otherwise fall back to auto logic\n this._autoPositionTooltip();\n };\n\n private _handleBlurOrMouseLeave = () => {\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n\n if (ref === document.activeElement) return;\n if (!ref || !tooltip) return;\n\n this._triggerFadeOut(tooltip);\n };\n\n private _triggerFadeOut(tooltip: HTMLElement) {\n if (!tooltip || this._hideTimeout) return;\n\n tooltip.classList.add(\"fade-out\");\n\n this._hideTimeout = window.setTimeout(() => {\n this._active = false;\n this._removeScrollListeners();\n this._positionStartingBase();\n this._resetTooltipPositioningStyles(tooltip);\n\n tooltip.classList.remove(\"fade-out\");\n this._hideTimeout = null;\n }, 200);\n }\n\n private _cancelFadeOut = () => {\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n const ref = this._getReferenceElement();\n\n if (!tooltip || !ref) return;\n\n const isPointerInsideTooltip = tooltip.matches(\":hover\");\n const isPointerInsideRef = ref.matches(\":hover\");\n\n const isTouched = document.activeElement === ref;\n\n if (!isPointerInsideTooltip && !isPointerInsideRef && !isTouched) {\n return;\n }\n\n if (this._hideTimeout) {\n clearTimeout(this._hideTimeout);\n this._hideTimeout = null;\n }\n\n tooltip.classList.remove(\"fade-out\");\n this._active = true;\n };\n\n // Listen to window scroll so a focus tooltip can auto position even when user move across the page\n private _addScrollListeners() {\n window.addEventListener(\"scroll\", this._handleScrollOrResize, true);\n this._resizeObserver = new ResizeObserver(() => {\n this._handleScrollOrResize();\n });\n this._resizeObserver.observe(document.documentElement);\n }\n\n private _removeScrollListeners() {\n window.removeEventListener(\"scroll\", this._handleScrollOrResize, true);\n this._resizeObserver?.disconnect();\n this._resizeObserver = null;\n }\n\n private _handleScrollOrResize = () => {\n if (!this._active || this._hideTimeout) return;\n\n this._showTooltip();\n };\n\n private _handleEscapeKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\" && this._active) {\n this._active = false;\n this._removeScrollListeners();\n\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n if (tooltip) {\n this._resetTooltipPositioningStyles(tooltip);\n }\n }\n };\n\n /**\n * Functions\n * --------------------------------------------------------------------------\n */\n\n private _getReferenceElement() {\n const targetId = this.for;\n if (!targetId) return null;\n\n // lightDOM search\n let htmlElement = document.getElementById(targetId);\n if (htmlElement) return htmlElement;\n\n // Search recursively through shadow DOMs (e.g. for nys-label within other component's shadowDOM)\n const findInShadows = (root: ParentNode): HTMLElement | null => {\n for (const el of Array.from(root.querySelectorAll(\"*\"))) {\n const shadowElement = el.shadowRoot;\n if (shadowElement) {\n const found = shadowElement.getElementById(targetId);\n if (found) return found;\n\n const deeper = findInShadows(shadowElement);\n if (deeper) return deeper;\n }\n }\n return null;\n };\n\n return findInShadows(document);\n }\n\n /**\n * Programmatically associates the trigger with the tooltip via\n * `aria-describedby`, per the WAI-ARIA Tooltip pattern. The tooltip bubble\n * (`.nys-tooltip__content`) carries `role=\"tooltip\"` and `id={this.id}`, so we\n * point the trigger's `aria-describedby` at that id. Preserves any existing\n * `aria-describedby` tokens the consumer already set, and avoids duplicates.\n */\n private _associateTrigger(el: HTMLElement) {\n if (!this.text?.trim()) return;\n const existing = (el.getAttribute(\"aria-describedby\") || \"\")\n .split(/\\s+/)\n .filter(Boolean);\n if (!existing.includes(this.id)) {\n existing.push(this.id);\n el.setAttribute(\"aria-describedby\", existing.join(\" \"));\n }\n }\n\n // We need to pass `ariaLabel` or `ariaDescription` to the nys-components so they can announce both their label and the tooltip's text\n private async _passAria(el: HTMLElement) {\n const tagName = el.tagName.toLowerCase();\n\n if (tagName === \"nys-icon\") {\n // nys-icon has a real `ariaLabel` property whose default Lit attribute\n // name (\"arialabel\") matches what setAttribute(\"ariaLabel\", ...)\n // actually writes, so this reaches the icon's rendered <svg>.\n el.setAttribute(\"ariaLabel\", `Hint: ${this.text}`);\n } else if (tagName === \"nys-button\") {\n // nys-button has no ariaLabel/ariaDescription prop, so setAttribute here\n // reached nothing — and setting the plain aria-describedby *attribute*\n // (what _associateTrigger does above) doesn't reach it either, since the\n // host has no role and never maps its own light-DOM ARIA into the\n // internal <button>. Route through the real `ariaDescribedBy` *property*\n // instead, pointing at this tooltip's own id — the same id\n // _associateTrigger already builds toward — so nys-button renders a\n // working aria-describedby on its real internal <button>.\n const button = el as unknown as { ariaDescribedBy?: string };\n const existing = (button.ariaDescribedBy || \"\")\n .split(/\\s+/)\n .filter(Boolean);\n if (!existing.includes(this.id)) {\n existing.push(this.id);\n button.ariaDescribedBy = existing.join(\" \");\n }\n }\n }\n\n /**\n * In React, the reference element found is often the native HTML element within the nys-component.\n * Therefore, this function accounts for the closest NYS component ancestor that supports a tooltip prop.\n */\n private _applyTooltipPropToFormComponent(ref: HTMLElement) {\n const tagName = ref.tagName.toLowerCase();\n if (!tagName.startsWith(\"nys-\")) return;\n\n if (tagName === \"nys-button\" || tagName === \"nys-icon\") {\n // Already handled elsewhere in this component; we just ensure we attach listeners\n this._applyFocusBehavior(ref);\n this._passAria(ref);\n return;\n }\n\n if (\"tooltip\" in ref) {\n ref.tooltip = this.text;\n }\n }\n\n // Applies focus behavior to an otherwise non focus element (i.e. nys-icon is non focusable by default)\n private async _applyFocusBehavior(el: HTMLElement) {\n el.style.cursor = \"pointer\";\n const tagName = el.tagName.toLowerCase();\n\n if (tagName === \"nys-icon\") {\n if (\"updateComplete\" in el) {\n await (el as any).updateComplete;\n }\n const svg = el.shadowRoot?.querySelector(\"svg\");\n if (svg) {\n svg.setAttribute(\"tabindex\", \"0\");\n }\n }\n }\n\n /**\n * Checks if the tooltip fits inside the viewport on the given side of the trigger.\n * Used for auto-positioning. Ignores text overflow for now.\n */\n private _doesPositionFit(position: typeof this._position) {\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\".nys-tooltip__content\");\n\n if (!ref || !tooltip || position == null) return;\n\n const refRect = ref.getBoundingClientRect();\n const tooltipRect = tooltip.getBoundingClientRect();\n\n // Define some margin buffer between tooltip and trigger (to avoid touching the edges too tightly)\n const margin = 8;\n\n // Available space on each side relative to trigger rect and viewport\n const spaceAvailable = {\n top: refRect.top - margin,\n left: refRect.left - margin,\n bottom: window.innerHeight - refRect.bottom - margin,\n right: window.innerWidth - refRect.right - margin,\n };\n\n // Check if tooltip fits on each side (compare available space vs tooltip size)\n const fits = {\n top: spaceAvailable.top >= tooltipRect.height,\n bottom: spaceAvailable.bottom >= tooltipRect.height,\n left: spaceAvailable.left >= tooltipRect.width,\n right: spaceAvailable.right >= tooltipRect.width,\n };\n\n return fits[position];\n }\n\n private _userPositionTooltip() {\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n const ref = this._getReferenceElement();\n if (tooltip && ref) {\n this._positionTooltipElement(ref, tooltip, this.position);\n this._shiftTooltipIntoViewport(tooltip);\n }\n }\n\n // Calculates the best placement based on available space (flips placement if it doesn't fit)\n private async _autoPositionTooltip() {\n const ref = this._getReferenceElement();\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n\n if (!ref || !tooltip) return;\n\n const refRect = ref.getBoundingClientRect();\n const margin = 8;\n\n const spaceAvailable = {\n top: refRect.top - margin,\n left: refRect.left - margin,\n bottom: window.innerHeight - refRect.bottom - margin,\n right: window.innerWidth - refRect.right - margin,\n };\n\n // Default tryOrder for auto mode\n let tryOrder: Array<keyof typeof spaceAvailable> = [\n \"top\",\n \"bottom\",\n \"right\",\n \"left\",\n ];\n\n // If user explicitly set a preferred position (even if it didn’t fit),\n // favor it first before trying others\n if (this._userHasSetPosition && this._originalUserPosition) {\n const userPosition = this._originalUserPosition;\n if (userPosition === \"left\") {\n tryOrder = [\"left\", \"right\", \"top\", \"bottom\"];\n } else if (userPosition === \"right\") {\n tryOrder = [\"right\", \"left\", \"top\", \"bottom\"];\n } else if (userPosition === \"top\") {\n tryOrder = [\"top\", \"bottom\", \"right\", \"left\"];\n } else if (userPosition === \"bottom\") {\n tryOrder = [\"bottom\", \"top\", \"right\", \"left\"];\n }\n }\n\n // 1) Try to find the first side that fits\n for (const pos of tryOrder) {\n if (this._doesPositionFit(pos)) {\n this._setInternalPosition(pos);\n await this.updateComplete;\n this._positionTooltipElement(ref, tooltip, pos);\n this._shiftTooltipIntoViewport(tooltip);\n return;\n }\n }\n\n // 2) Fallback: pick the side with the most space\n let bestPosition: keyof typeof spaceAvailable = \"top\";\n let maxSpace = spaceAvailable.top;\n\n for (const pos of tryOrder) {\n if (spaceAvailable[pos] > maxSpace) {\n maxSpace = spaceAvailable[pos];\n bestPosition = pos;\n }\n }\n this._setInternalPosition(bestPosition);\n await this.updateComplete;\n this._positionTooltipElement(ref, tooltip, bestPosition);\n this._shiftTooltipIntoViewport(tooltip);\n }\n\n private _positionStartingBase() {\n const tooltip = this.shadowRoot?.querySelector(\n \".nys-tooltip__content\",\n ) as HTMLElement;\n\n if (!tooltip) return;\n\n tooltip.style.top = \"0px\";\n tooltip.style.left = \"0px\";\n }\n\n private _positionTooltipElement(\n ref: HTMLElement,\n tooltip: HTMLElement,\n bestPosition: typeof this._position,\n ) {\n const refRect = ref.getBoundingClientRect();\n const tooltipRect = tooltip.getBoundingClientRect();\n const margin = 8;\n\n let top = 0;\n let left = 0;\n\n switch (bestPosition) {\n case \"top\":\n top = refRect.top - tooltipRect.height - margin;\n left = refRect.left + refRect.width / 2 - tooltipRect.width / 2;\n break;\n case \"bottom\":\n top = refRect.bottom + margin;\n left = refRect.left + refRect.width / 2 - tooltipRect.width / 2;\n break;\n case \"left\":\n top = refRect.top + refRect.height / 2 - tooltipRect.height / 2;\n left = refRect.left - tooltipRect.width - margin;\n break;\n case \"right\":\n top = refRect.top + refRect.height / 2 - tooltipRect.height / 2;\n left = refRect.right + margin;\n break;\n default:\n // Default to top\n top = refRect.top - tooltipRect.height - margin;\n left = refRect.left + refRect.width / 2 - tooltipRect.width / 2;\n break;\n }\n\n tooltip.style.top = `${top}px`;\n tooltip.style.left = `${left}px`;\n }\n\n // In some iframes (like Storybook's) or embedded containers , parent elements may have CSS transforms applied, creating a new coordinate context.\n // This function removes such transforms to prevent them from affecting tooltip positioning calculations.\n private applyInverseTransform() {\n document.querySelectorAll('div[scale=\"1\"]').forEach((el) => {\n (el as HTMLElement).style.transform = \"none\";\n });\n }\n\n private _setInternalPosition(bestPosition: typeof this._position) {\n this._internallyUpdatingPosition = true;\n this.position = bestPosition;\n this._internallyUpdatingPosition = false;\n }\n\n // Determines if text of tooltip over-extends outside of viewport edge and adjust tooltip for horizontal overflow\n private _shiftTooltipIntoViewport(tooltip: HTMLElement) {\n const ref = this._getReferenceElement();\n if (!ref) return;\n\n const refRect = ref.getBoundingClientRect();\n const tooltipRect = tooltip.getBoundingClientRect();\n\n const refCenter = refRect.left + refRect.width / 2;\n\n const overflowLeft = tooltipRect.left < 0;\n const overflowRight = tooltipRect.right > window.innerWidth;\n\n // Tooltip is past the viewport edge, shift it inwards\n if (overflowLeft) {\n tooltip.style.left = \"10px\";\n tooltip.style.transform = \"none\";\n } else if (overflowRight) {\n tooltip.style.right = \"0px\";\n tooltip.style.left = \"auto\";\n tooltip.style.transform = \"none\";\n }\n\n // Recalculate tooltip rect after any shift\n const newTooltipRect = tooltip.getBoundingClientRect();\n\n // Arrow offset relative to tooltip width to maintain accuracy on zoom and out-of-bounds\n const arrowOffsetRatio =\n (refCenter - newTooltipRect.left) / newTooltipRect.width;\n const arrowOffsetPercent = Math.max(0, Math.min(1, arrowOffsetRatio)) * 100;\n\n tooltip.style.setProperty(\"--arrow-offset-x\", `${arrowOffsetPercent}%`);\n }\n\n // Reposition tooltip back to original set position (e.g. top, left, bottom, right) to avoid positioning issue base on last position\n private _resetTooltipPositioningStyles(tooltip: HTMLElement) {\n tooltip.style.left = \"\";\n tooltip.style.right = \"\";\n tooltip.style.top = \"\";\n tooltip.style.transform = \"\";\n tooltip.style.removeProperty(\"--arrow-offset-x\");\n }\n\n render() {\n return html`\n <div class=\"nys-tooltip__main\">\n ${this.text?.trim()\n ? html`<div\n id=${this.id}\n class=\"nys-tooltip__content\"\n role=\"tooltip\"\n aria-hidden=${this._active && !this._hideTimeout\n ? \"false\"\n : \"true\"}\n ?active=${this._active}\n style=\"visibility: ${this._active ? \"visible\" : \"hidden\"}; \"\n >\n <div class=\"nys-tooltip__inner\">${this.text}</div>\n <span class=\"nys-tooltip__arrow\"></span>\n </div>`\n : \"\"}\n </div>\n `;\n }\n}\n\nif (!customElements.get(\"nys-tooltip\")) {\n customElements.define(\"nys-tooltip\", NysTooltip);\n}\n"],"names":["LitElement","unsafeCSS","html","property","state","y","f","e","P","u","_NysTooltip","NysElement","ref","tooltip","isPointerInsideTooltip","isPointerInsideRef","isTouched","value","oldVal","changedProps","targetId","htmlElement","findInShadows","root","el","shadowElement","found","deeper","existing","tagName","button","svg","position","refRect","tooltipRect","margin","spaceAvailable","tryOrder","userPosition","pos","bestPosition","maxSpace","top","left","refCenter","overflowLeft","overflowRight","newTooltipRect","arrowOffsetRatio","arrowOffsetPercent","styles","NysTooltip","__decorateClass"],"mappings":"AACA,SAAA,cAAAA,GAAA,aAAAC,GAAA,QAAAC,SAAA;AAAA,SAAA,YAAAC,GAAA,SAAAC,SAAA;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,IAAIC,IAAI;AACR,SAASC,EAAEC,GAAG;AACZ,SAAO,GAAGA,CAAC,IAAI,KAAK,KAAK,IAAIF,GAAG;AAClC;AAqDK,MAAC,IAAI,CAACE,MAAM;AAAA,EACf,MAAM,UAAUA,EAAE;AAAA,IAChB,IAAI,WAAW;AACb,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IACA,WAAW;AACT,WAAK,OAAO,KAAK,KAAKD,EAAE,KAAK,QAAQ;AAAA,IACvC;AAAA,IACA,oBAAoB;AAClB,YAAM,kBAAiB,GAAI,KAAK,SAAQ;AAAA,IAC1C;AAAA,EACJ;AACE,SAAO;AACT,GAAGE,IAAoB,kBAAEC,CAAC;;;;;;AChBnB,MAAMC,IAAN,MAAMA,UAAmBC,EAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EA2DzC,cAAc;AACZ,UAAA,GAxDyC,KAAA,KAAK,IAGpB,KAAA,OAAO,IAGS,KAAA,WAAW,IAG3B,KAAA,MAAM,IAIlC,KAAQ,UAAU,IAGlB,KAAQ,sBAAsB,IAC9B,KAAQ,wBAAsD,MAE9D,KAAQ,8BAA8B,IAEtC,KAAQ,eAA8B,MAGtC,KAA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KAAK,WAAW,CAAC,KAAK,eAChC,UACA,MAAM;AAAA,wBACA,KAAK,OAAO;AAAA,mCACD,KAAK,UAAU,YAAY,QAAQ;AAAA;AAAA,gDAEtB,KAAK,IAAI;AAAA;AAAA,sBAG7C,EAAE;AAAA;AAAA;AAAA,EAGZ;AACF;AA9lBEQ,EAAO,SAAST,EAAUiD,CAAM;AAD3B,IAAMC,IAANzC;AAIsC0C,EAAA;AAAA,EAA1CjD,EAAS,EAAE,MAAM,QAAQ,SAAS,IAAM;AAAA,GAJ9BgD,EAIgC,WAAA,MAAA,CAAA;AAGfC,EAAA;AAAA,EAA3BjD,EAAS,EAAE,MAAM,OAAA,CAAQ;AAAA,GAPfgD,EAOiB,WAAA,QAAA,CAAA;AAGgBC,EAAA;AAAA,EAA3CjD,EAAS,EAAE,MAAM,SAAS,SAAS,IAAM;AAAA,GAV/BgD,EAUiC,WAAA,YAAA,CAAA;AAGhBC,EAAA;AAAA,EAA3BjD,EAAS,EAAE,MAAM,OAAA,CAAQ;AAAA,GAbfgD,EAaiB,WAAA,OAAA,CAAA;AAIpBC,EAAA;AAAA,EADPhD,EAAA;AAAM,GAhBI+C,EAiBH,WAAA,WAAA,CAAA;AAqBJC,EAAA;AAAA,EADHjD,EAAS,EAAE,MAAM,QAAQ,SAAS,IAAM;AAAA,GArC9BgD,EAsCP,WAAA,YAAA,CAAA;AA2jBD,eAAe,IAAI,aAAa,KACnC,eAAe,OAAO,eAAeA,CAAU;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nysds/nys-tooltip",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.1",
|
|
4
4
|
"description": "The Tooltip component from the NYS Design System.",
|
|
5
5
|
"module": "dist/nys-tooltip.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"lit-analyze": "lit-analyzer '**/*.ts'"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@nysds/internals": "^1.21.
|
|
26
|
+
"@nysds/internals": "^1.21.1",
|
|
27
27
|
"lit": "^3.3.1",
|
|
28
28
|
"typescript": "^5.9.3",
|
|
29
29
|
"vite": "^7.3.1"
|