sonner-wc 0.2.0 → 0.3.0
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 +2 -0
- package/dist/constants.d.ts +0 -2
- package/dist/icons.d.ts +0 -1
- package/dist/sonner-toast.d.ts +1 -2
- package/dist/sonner-toaster.d.ts +1 -2
- package/dist/sonner-wc.bundle.js +33 -25
- package/dist/sonner-wc.bundle.js.map +8 -7
- package/dist/sonner-wc.js +137 -136
- package/dist/sonner-wc.js.map +8 -7
- package/dist/ssr.d.ts +1 -0
- package/package.json +1 -1
package/dist/sonner-wc.js
CHANGED
|
@@ -14,8 +14,6 @@ var WARNING_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
|
|
|
14
14
|
var INFO_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd"/></svg>';
|
|
15
15
|
var ERROR_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd"/></svg>';
|
|
16
16
|
var CLOSE_ICON = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>';
|
|
17
|
-
var SPINNER_BARS = Array.from({ length: 12 }, () => '<div class="sonner-loading-bar"></div>').join("");
|
|
18
|
-
var LOADING_SPINNER = '<div class="sonner-loading-wrapper" data-visible="true"><div class="sonner-spinner">' + SPINNER_BARS + "</div></div>";
|
|
19
17
|
function getTypeIcon(type) {
|
|
20
18
|
switch (type) {
|
|
21
19
|
case "success":
|
|
@@ -68,6 +66,10 @@ function dismissAllToasts() {
|
|
|
68
66
|
t.dismissAll();
|
|
69
67
|
}
|
|
70
68
|
|
|
69
|
+
// src/ssr.ts
|
|
70
|
+
var HTMLElementCtor = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
|
71
|
+
};
|
|
72
|
+
|
|
71
73
|
// src/styles/toaster.css
|
|
72
74
|
var toaster_default = `:host {
|
|
73
75
|
position: fixed;
|
|
@@ -119,15 +121,24 @@ var toaster_default = `:host {
|
|
|
119
121
|
--toast-close-button-start: 0;
|
|
120
122
|
--toast-close-button-end: unset;
|
|
121
123
|
--toast-close-button-transform: translate(-35%, -35%);
|
|
124
|
+
inset: unset;
|
|
125
|
+
border: none;
|
|
126
|
+
overflow: visible;
|
|
127
|
+
background: transparent;
|
|
122
128
|
box-sizing: border-box;
|
|
123
129
|
padding: 0;
|
|
124
130
|
margin: 0;
|
|
125
131
|
outline: none;
|
|
132
|
+
contain: layout style;
|
|
126
133
|
z-index: 999999999;
|
|
127
134
|
transition: transform 400ms ease;
|
|
128
135
|
display: block;
|
|
129
136
|
}
|
|
130
137
|
|
|
138
|
+
::backdrop {
|
|
139
|
+
display: none;
|
|
140
|
+
}
|
|
141
|
+
|
|
131
142
|
:host(:focus-visible) {
|
|
132
143
|
outline: 2px solid var(--gray9);
|
|
133
144
|
outline-offset: 4px;
|
|
@@ -251,6 +262,8 @@ var toast_default = `:host {
|
|
|
251
262
|
position: absolute;
|
|
252
263
|
opacity: 0;
|
|
253
264
|
transform: var(--y);
|
|
265
|
+
contain: layout style;
|
|
266
|
+
will-change: transform, opacity;
|
|
254
267
|
touch-action: none;
|
|
255
268
|
transition:
|
|
256
269
|
transform 400ms,
|
|
@@ -405,16 +418,14 @@ var toast_default = `:host {
|
|
|
405
418
|
animation: sonner-fade-in 300ms ease forwards;
|
|
406
419
|
}
|
|
407
420
|
|
|
408
|
-
[data-button]
|
|
409
|
-
::slotted(button[slot='action']),
|
|
410
|
-
::slotted(button[slot='cancel']) {
|
|
421
|
+
[data-button] {
|
|
411
422
|
border-radius: 4px;
|
|
412
423
|
padding-left: 8px;
|
|
413
424
|
padding-right: 8px;
|
|
414
425
|
height: 24px;
|
|
415
426
|
font-size: 12px;
|
|
416
427
|
background: var(--normal-text);
|
|
417
|
-
color:
|
|
428
|
+
color: var(--normal-bg);
|
|
418
429
|
margin-left: var(--toast-button-margin-start);
|
|
419
430
|
margin-right: var(--toast-button-margin-end);
|
|
420
431
|
border: none;
|
|
@@ -432,8 +443,7 @@ var toast_default = `:host {
|
|
|
432
443
|
[data-button]:focus-visible {
|
|
433
444
|
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4);
|
|
434
445
|
}
|
|
435
|
-
[data-cancel]
|
|
436
|
-
::slotted(button[slot='cancel']) {
|
|
446
|
+
[data-cancel] {
|
|
437
447
|
color: var(--normal-text);
|
|
438
448
|
background: var(--cancel-bg, rgba(0, 0, 0, 0.08));
|
|
439
449
|
}
|
|
@@ -820,16 +830,34 @@ function getToastSheet() {
|
|
|
820
830
|
}
|
|
821
831
|
|
|
822
832
|
// src/sonner-toast.ts
|
|
823
|
-
var HTMLElementCtor = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
|
824
|
-
};
|
|
825
833
|
function isUrgentType(type) {
|
|
826
834
|
return type === "error" || type === "warning";
|
|
827
835
|
}
|
|
828
|
-
function
|
|
836
|
+
function boolAttr(host, name) {
|
|
837
|
+
return host.hasAttribute(name) && host.getAttribute(name) !== "false";
|
|
838
|
+
}
|
|
839
|
+
function toggleAttr(host, name, on) {
|
|
840
|
+
if (on)
|
|
841
|
+
host.setAttribute(name, "");
|
|
842
|
+
else
|
|
843
|
+
host.removeAttribute(name);
|
|
844
|
+
}
|
|
845
|
+
function clearSlot(host, slotName) {
|
|
829
846
|
for (const child of Array.from(host.children)) {
|
|
830
847
|
if (child.getAttribute("slot") === slotName)
|
|
831
848
|
host.removeChild(child);
|
|
832
849
|
}
|
|
850
|
+
}
|
|
851
|
+
function slotElementFromHTML(html, slotName) {
|
|
852
|
+
const tpl = document.createElement("template");
|
|
853
|
+
tpl.innerHTML = html;
|
|
854
|
+
const el = tpl.content.firstElementChild;
|
|
855
|
+
if (el)
|
|
856
|
+
el.setAttribute("slot", slotName);
|
|
857
|
+
return el;
|
|
858
|
+
}
|
|
859
|
+
function setContent(host, slotName, value) {
|
|
860
|
+
clearSlot(host, slotName);
|
|
833
861
|
if (value == null || value === "")
|
|
834
862
|
return;
|
|
835
863
|
const resolved = typeof value === "function" ? value() : value;
|
|
@@ -844,10 +872,14 @@ function setContent(host, slotName, value) {
|
|
|
844
872
|
host.appendChild(span);
|
|
845
873
|
}
|
|
846
874
|
}
|
|
847
|
-
function setButtonSlot(host, slotName, value, defaultCloseHandler) {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
875
|
+
function setButtonSlot(host, shadow, slotName, value, defaultCloseHandler) {
|
|
876
|
+
clearSlot(host, slotName);
|
|
877
|
+
const container = shadow.querySelector(`[data-${slotName}-host]`);
|
|
878
|
+
if (container) {
|
|
879
|
+
for (const child of Array.from(container.children)) {
|
|
880
|
+
if (child.tagName === "BUTTON")
|
|
881
|
+
container.removeChild(child);
|
|
882
|
+
}
|
|
851
883
|
}
|
|
852
884
|
if (!value)
|
|
853
885
|
return;
|
|
@@ -856,13 +888,12 @@ function setButtonSlot(host, slotName, value, defaultCloseHandler) {
|
|
|
856
888
|
host.appendChild(value);
|
|
857
889
|
return;
|
|
858
890
|
}
|
|
891
|
+
if (!container)
|
|
892
|
+
return;
|
|
859
893
|
const btn = document.createElement("button");
|
|
860
|
-
btn.setAttribute("slot", slotName);
|
|
861
894
|
btn.setAttribute("type", "button");
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
else
|
|
865
|
-
btn.setAttribute("data-action", "");
|
|
895
|
+
btn.setAttribute("data-button", "");
|
|
896
|
+
btn.setAttribute(slotName === "cancel" ? "data-cancel" : "data-action", "");
|
|
866
897
|
btn.textContent = value.label;
|
|
867
898
|
btn.addEventListener("click", (e) => {
|
|
868
899
|
value.onClick?.(e);
|
|
@@ -870,27 +901,33 @@ function setButtonSlot(host, slotName, value, defaultCloseHandler) {
|
|
|
870
901
|
return;
|
|
871
902
|
defaultCloseHandler();
|
|
872
903
|
});
|
|
873
|
-
|
|
904
|
+
container.appendChild(btn);
|
|
874
905
|
}
|
|
875
906
|
var SPINNER_BARS_HTML = Array.from({ length: 12 }, () => '<div class="sonner-loading-bar"></div>').join("");
|
|
876
|
-
var SHADOW_TEMPLATE =
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
907
|
+
var SHADOW_TEMPLATE = (() => {
|
|
908
|
+
if (typeof document === "undefined")
|
|
909
|
+
return null;
|
|
910
|
+
const tpl = document.createElement("template");
|
|
911
|
+
tpl.innerHTML = `
|
|
912
|
+
<div data-frame part="frame">
|
|
913
|
+
<button type="button" data-close-button part="close-button" hidden aria-label="Close toast"></button>
|
|
914
|
+
<div data-icon part="icon">
|
|
915
|
+
<slot name="icon"></slot>
|
|
916
|
+
<div class="sonner-loading-wrapper" aria-hidden="true">
|
|
917
|
+
<div class="sonner-spinner">${SPINNER_BARS_HTML}</div>
|
|
918
|
+
</div>
|
|
883
919
|
</div>
|
|
920
|
+
<div data-content part="content">
|
|
921
|
+
<div data-title part="title"><slot name="title"></slot></div>
|
|
922
|
+
<div data-description part="description"><slot name="description"></slot></div>
|
|
923
|
+
</div>
|
|
924
|
+
<div data-cancel-host part="cancel"><slot name="cancel"></slot></div>
|
|
925
|
+
<div data-action-host part="action"><slot name="action"></slot></div>
|
|
926
|
+
<slot part="custom"></slot>
|
|
884
927
|
</div>
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
</div>
|
|
889
|
-
<slot name="cancel"></slot>
|
|
890
|
-
<slot name="action"></slot>
|
|
891
|
-
<slot part="custom"></slot>
|
|
892
|
-
</div>
|
|
893
|
-
`;
|
|
928
|
+
`;
|
|
929
|
+
return tpl;
|
|
930
|
+
})();
|
|
894
931
|
|
|
895
932
|
class SonnerToast extends HTMLElementCtor {
|
|
896
933
|
static get observedAttributes() {
|
|
@@ -922,9 +959,7 @@ class SonnerToast extends HTMLElementCtor {
|
|
|
922
959
|
super();
|
|
923
960
|
this.#shadow = this.attachShadow({ mode: "open" });
|
|
924
961
|
this.#shadow.adoptedStyleSheets = [getToastSheet()];
|
|
925
|
-
|
|
926
|
-
tpl.innerHTML = SHADOW_TEMPLATE;
|
|
927
|
-
this.#shadow.appendChild(tpl.content.cloneNode(true));
|
|
962
|
+
this.#shadow.appendChild(SHADOW_TEMPLATE.content.cloneNode(true));
|
|
928
963
|
this.#closeBtn = this.#shadow.querySelector("[data-close-button]");
|
|
929
964
|
this.#iconWrap = this.#shadow.querySelector("[data-icon]");
|
|
930
965
|
this.#titleWrap = this.#shadow.querySelector("[data-title]");
|
|
@@ -1067,32 +1102,16 @@ class SonnerToast extends HTMLElementCtor {
|
|
|
1067
1102
|
this.#remainingTime = 0;
|
|
1068
1103
|
timerNeedsReset = true;
|
|
1069
1104
|
}
|
|
1070
|
-
if (options.dismissible !== undefined)
|
|
1071
|
-
|
|
1072
|
-
this.setAttribute("dismissible", "");
|
|
1073
|
-
else
|
|
1074
|
-
this.removeAttribute("dismissible");
|
|
1075
|
-
}
|
|
1105
|
+
if (options.dismissible !== undefined)
|
|
1106
|
+
toggleAttr(this, "dismissible", options.dismissible);
|
|
1076
1107
|
if (options.position !== undefined)
|
|
1077
1108
|
this.setAttribute("position", options.position);
|
|
1078
|
-
if (options.closeButton !== undefined)
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
if (options.richColors !== undefined) {
|
|
1085
|
-
if (options.richColors)
|
|
1086
|
-
this.setAttribute("rich-colors", "");
|
|
1087
|
-
else
|
|
1088
|
-
this.removeAttribute("rich-colors");
|
|
1089
|
-
}
|
|
1090
|
-
if (options.invert !== undefined) {
|
|
1091
|
-
if (options.invert)
|
|
1092
|
-
this.setAttribute("invert", "");
|
|
1093
|
-
else
|
|
1094
|
-
this.removeAttribute("invert");
|
|
1095
|
-
}
|
|
1109
|
+
if (options.closeButton !== undefined)
|
|
1110
|
+
toggleAttr(this, "close-button", options.closeButton);
|
|
1111
|
+
if (options.richColors !== undefined)
|
|
1112
|
+
toggleAttr(this, "rich-colors", options.richColors);
|
|
1113
|
+
if (options.invert !== undefined)
|
|
1114
|
+
toggleAttr(this, "invert", options.invert);
|
|
1096
1115
|
if (options.icon !== undefined)
|
|
1097
1116
|
this.setIcon(options.icon);
|
|
1098
1117
|
if (options.title !== undefined)
|
|
@@ -1100,10 +1119,10 @@ class SonnerToast extends HTMLElementCtor {
|
|
|
1100
1119
|
if (options.description !== undefined)
|
|
1101
1120
|
this.setDescription(options.description);
|
|
1102
1121
|
if (options.action !== undefined) {
|
|
1103
|
-
setButtonSlot(this, "action", options.action, () => this.dismiss());
|
|
1122
|
+
setButtonSlot(this, this.#shadow, "action", options.action, () => this.dismiss());
|
|
1104
1123
|
}
|
|
1105
1124
|
if (options.cancel !== undefined) {
|
|
1106
|
-
setButtonSlot(this, "cancel", options.cancel, () => this.dismiss());
|
|
1125
|
+
setButtonSlot(this, this.#shadow, "cancel", options.cancel, () => this.dismiss());
|
|
1107
1126
|
}
|
|
1108
1127
|
if (options.className)
|
|
1109
1128
|
this.className = options.className;
|
|
@@ -1120,8 +1139,7 @@ class SonnerToast extends HTMLElementCtor {
|
|
|
1120
1139
|
if (timerNeedsReset)
|
|
1121
1140
|
this.#resetTimer();
|
|
1122
1141
|
if (this.#mounted && typeChanged && !wasUrgent && isUrgentType(this.toastType)) {
|
|
1123
|
-
const
|
|
1124
|
-
const text = titleEl?.textContent?.trim();
|
|
1142
|
+
const text = this.#getTitleText();
|
|
1125
1143
|
if (text) {
|
|
1126
1144
|
const toaster = this.closest("sonner-toaster");
|
|
1127
1145
|
toaster?.announceUrgent(text);
|
|
@@ -1133,23 +1151,23 @@ class SonnerToast extends HTMLElementCtor {
|
|
|
1133
1151
|
setContent(this, "title", value);
|
|
1134
1152
|
this.#applyCloseButtonAriaLabel();
|
|
1135
1153
|
}
|
|
1154
|
+
#getTitleText() {
|
|
1155
|
+
const titleEl = Array.from(this.children).find((c) => c.getAttribute("slot") === "title");
|
|
1156
|
+
return titleEl?.textContent?.trim() ?? "";
|
|
1157
|
+
}
|
|
1136
1158
|
#applyCloseButtonAriaLabel() {
|
|
1137
1159
|
if (this.#closeButtonAriaLabel) {
|
|
1138
1160
|
this.#closeBtn.setAttribute("aria-label", this.#closeButtonAriaLabel);
|
|
1139
1161
|
return;
|
|
1140
1162
|
}
|
|
1141
|
-
const
|
|
1142
|
-
const text = titleEl?.textContent?.trim();
|
|
1163
|
+
const text = this.#getTitleText();
|
|
1143
1164
|
this.#closeBtn.setAttribute("aria-label", text ? `Close: ${text}` : "Close toast");
|
|
1144
1165
|
}
|
|
1145
1166
|
setDescription(value) {
|
|
1146
1167
|
setContent(this, "description", value);
|
|
1147
1168
|
}
|
|
1148
1169
|
setIcon(value) {
|
|
1149
|
-
|
|
1150
|
-
if (child.getAttribute("slot") === "icon")
|
|
1151
|
-
this.removeChild(child);
|
|
1152
|
-
}
|
|
1170
|
+
clearSlot(this, "icon");
|
|
1153
1171
|
if (value == null)
|
|
1154
1172
|
return;
|
|
1155
1173
|
if (value instanceof Node) {
|
|
@@ -1157,13 +1175,9 @@ class SonnerToast extends HTMLElementCtor {
|
|
|
1157
1175
|
value.setAttribute("slot", "icon");
|
|
1158
1176
|
this.appendChild(value);
|
|
1159
1177
|
} else {
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1162
|
-
const el = tpl.content.firstElementChild;
|
|
1163
|
-
if (el) {
|
|
1164
|
-
el.setAttribute("slot", "icon");
|
|
1178
|
+
const el = slotElementFromHTML(value, "icon");
|
|
1179
|
+
if (el)
|
|
1165
1180
|
this.appendChild(el);
|
|
1166
|
-
}
|
|
1167
1181
|
}
|
|
1168
1182
|
}
|
|
1169
1183
|
setHandlers(handlers) {
|
|
@@ -1189,36 +1203,25 @@ class SonnerToast extends HTMLElementCtor {
|
|
|
1189
1203
|
const urgent = isUrgentType(type);
|
|
1190
1204
|
this.setAttribute("role", urgent ? "alert" : "status");
|
|
1191
1205
|
this.setAttribute("aria-live", urgent ? "assertive" : "polite");
|
|
1206
|
+
for (const c of Array.from(this.children)) {
|
|
1207
|
+
if (c.getAttribute("slot") === "icon" && c.hasAttribute("data-sonner-default-icon"))
|
|
1208
|
+
this.removeChild(c);
|
|
1209
|
+
}
|
|
1192
1210
|
if (type === "loading") {
|
|
1193
1211
|
this.setAttribute("data-promise", "true");
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
if (c.getAttribute("slot") === "icon" && c.hasAttribute("data-sonner-default-icon"))
|
|
1208
|
-
this.removeChild(c);
|
|
1209
|
-
}
|
|
1210
|
-
const builtin = getTypeIcon(type);
|
|
1211
|
-
if (builtin) {
|
|
1212
|
-
const tpl = document.createElement("template");
|
|
1213
|
-
tpl.innerHTML = builtin;
|
|
1214
|
-
const el = tpl.content.firstElementChild;
|
|
1215
|
-
if (el) {
|
|
1216
|
-
el.setAttribute("slot", "icon");
|
|
1217
|
-
el.setAttribute("data-sonner-default-icon", "");
|
|
1218
|
-
this.appendChild(el);
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
this.removeAttribute("data-promise");
|
|
1215
|
+
const hasUserIcon = Array.from(this.children).some((c) => c.getAttribute("slot") === "icon");
|
|
1216
|
+
if (hasUserIcon)
|
|
1217
|
+
return;
|
|
1218
|
+
const builtin = getTypeIcon(type);
|
|
1219
|
+
if (!builtin)
|
|
1220
|
+
return;
|
|
1221
|
+
const el = slotElementFromHTML(builtin, "icon");
|
|
1222
|
+
if (el) {
|
|
1223
|
+
el.setAttribute("data-sonner-default-icon", "");
|
|
1224
|
+
this.appendChild(el);
|
|
1222
1225
|
}
|
|
1223
1226
|
}
|
|
1224
1227
|
#applyDismissible() {
|
|
@@ -1236,16 +1239,13 @@ class SonnerToast extends HTMLElementCtor {
|
|
|
1236
1239
|
this.setAttribute("data-x-position", x);
|
|
1237
1240
|
}
|
|
1238
1241
|
#applyCloseButton() {
|
|
1239
|
-
|
|
1240
|
-
this.#closeBtn.hidden = !show;
|
|
1242
|
+
this.#closeBtn.hidden = !boolAttr(this, "close-button");
|
|
1241
1243
|
}
|
|
1242
1244
|
#applyRichColors() {
|
|
1243
|
-
|
|
1244
|
-
this.setAttribute("data-rich-colors", String(rich));
|
|
1245
|
+
this.setAttribute("data-rich-colors", String(boolAttr(this, "rich-colors")));
|
|
1245
1246
|
}
|
|
1246
1247
|
#applyInvert() {
|
|
1247
|
-
|
|
1248
|
-
this.setAttribute("data-invert", String(invert));
|
|
1248
|
+
this.setAttribute("data-invert", String(boolAttr(this, "invert")));
|
|
1249
1249
|
}
|
|
1250
1250
|
#readDuration() {
|
|
1251
1251
|
const raw = this.getAttribute("duration");
|
|
@@ -1254,7 +1254,7 @@ class SonnerToast extends HTMLElementCtor {
|
|
|
1254
1254
|
if (raw === "Infinity")
|
|
1255
1255
|
return Infinity;
|
|
1256
1256
|
const n = Number(raw);
|
|
1257
|
-
return Number.isFinite(n)
|
|
1257
|
+
return Number.isFinite(n) ? n : null;
|
|
1258
1258
|
}
|
|
1259
1259
|
#effectiveDuration() {
|
|
1260
1260
|
const explicit = this.#duration ?? this.#readDuration();
|
|
@@ -1416,8 +1416,6 @@ if (typeof customElements !== "undefined" && !customElements.get("sonner-toast")
|
|
|
1416
1416
|
customElements.define("sonner-toast", SonnerToast);
|
|
1417
1417
|
}
|
|
1418
1418
|
// src/sonner-toaster.ts
|
|
1419
|
-
var HTMLElementCtor2 = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
|
1420
|
-
};
|
|
1421
1419
|
function parseOffsetValue(v, fallback) {
|
|
1422
1420
|
if (v == null)
|
|
1423
1421
|
return fallback;
|
|
@@ -1438,7 +1436,7 @@ function applyOffsetVars(host, opts, prefix, fallback) {
|
|
|
1438
1436
|
}
|
|
1439
1437
|
}
|
|
1440
1438
|
|
|
1441
|
-
class SonnerToaster extends
|
|
1439
|
+
class SonnerToaster extends HTMLElementCtor {
|
|
1442
1440
|
static get observedAttributes() {
|
|
1443
1441
|
return [
|
|
1444
1442
|
"position",
|
|
@@ -1507,6 +1505,11 @@ class SonnerToaster extends HTMLElementCtor2 {
|
|
|
1507
1505
|
this.addEventListener("sonner-toast-mounted", () => this.#reflow({ remeasure: true }));
|
|
1508
1506
|
}
|
|
1509
1507
|
connectedCallback() {
|
|
1508
|
+
if (typeof this.showPopover === "function") {
|
|
1509
|
+
if (!this.hasAttribute("popover"))
|
|
1510
|
+
this.setAttribute("popover", "manual");
|
|
1511
|
+
this.showPopover();
|
|
1512
|
+
}
|
|
1510
1513
|
if (!this.hasAttribute("tabindex"))
|
|
1511
1514
|
this.tabIndex = -1;
|
|
1512
1515
|
if (!this.hasAttribute("role"))
|
|
@@ -1535,6 +1538,11 @@ class SonnerToaster extends HTMLElementCtor2 {
|
|
|
1535
1538
|
this.#reflow({ remeasure: true });
|
|
1536
1539
|
}
|
|
1537
1540
|
disconnectedCallback() {
|
|
1541
|
+
if (typeof this.hidePopover === "function") {
|
|
1542
|
+
try {
|
|
1543
|
+
this.hidePopover();
|
|
1544
|
+
} catch {}
|
|
1545
|
+
}
|
|
1538
1546
|
this.#childObserver.disconnect();
|
|
1539
1547
|
this.#resizeObserver.disconnect();
|
|
1540
1548
|
document.removeEventListener("keydown", this.#onKeyDown);
|
|
@@ -1608,12 +1616,15 @@ class SonnerToaster extends HTMLElementCtor2 {
|
|
|
1608
1616
|
#getPosition() {
|
|
1609
1617
|
return this.getAttribute("position") || "bottom-right";
|
|
1610
1618
|
}
|
|
1611
|
-
#
|
|
1619
|
+
#applyPositionTo(target) {
|
|
1612
1620
|
const [y, x] = this.#getPosition().split("-");
|
|
1613
1621
|
if (y)
|
|
1614
|
-
|
|
1622
|
+
target.setAttribute("data-y-position", y);
|
|
1615
1623
|
if (x)
|
|
1616
|
-
|
|
1624
|
+
target.setAttribute("data-x-position", x);
|
|
1625
|
+
}
|
|
1626
|
+
#applyPosition() {
|
|
1627
|
+
this.#applyPositionTo(this);
|
|
1617
1628
|
}
|
|
1618
1629
|
#applyTheme() {
|
|
1619
1630
|
if (this.#themeMql && this.#themeMqlHandler) {
|
|
@@ -1657,13 +1668,8 @@ class SonnerToaster extends HTMLElementCtor2 {
|
|
|
1657
1668
|
}
|
|
1658
1669
|
#applyToastPositions() {
|
|
1659
1670
|
for (const t of this.#toasts) {
|
|
1660
|
-
if (!t.hasAttribute("position"))
|
|
1661
|
-
|
|
1662
|
-
if (y)
|
|
1663
|
-
t.setAttribute("data-y-position", y);
|
|
1664
|
-
if (x)
|
|
1665
|
-
t.setAttribute("data-x-position", x);
|
|
1666
|
-
}
|
|
1671
|
+
if (!t.hasAttribute("position"))
|
|
1672
|
+
this.#applyPositionTo(t);
|
|
1667
1673
|
}
|
|
1668
1674
|
}
|
|
1669
1675
|
#propagateBoolean(attr) {
|
|
@@ -1678,13 +1684,8 @@ class SonnerToaster extends HTMLElementCtor2 {
|
|
|
1678
1684
|
}
|
|
1679
1685
|
}
|
|
1680
1686
|
#decorateToast(toast) {
|
|
1681
|
-
if (!toast.hasAttribute("position"))
|
|
1682
|
-
|
|
1683
|
-
if (y)
|
|
1684
|
-
toast.setAttribute("data-y-position", y);
|
|
1685
|
-
if (x)
|
|
1686
|
-
toast.setAttribute("data-x-position", x);
|
|
1687
|
-
}
|
|
1687
|
+
if (!toast.hasAttribute("position"))
|
|
1688
|
+
this.#applyPositionTo(toast);
|
|
1688
1689
|
if (!toast.hasAttribute("duration")) {
|
|
1689
1690
|
const inherit = this.getAttribute("duration");
|
|
1690
1691
|
if (inherit)
|
|
@@ -2017,5 +2018,5 @@ export {
|
|
|
2017
2018
|
SonnerToast
|
|
2018
2019
|
};
|
|
2019
2020
|
|
|
2020
|
-
//# debugId=
|
|
2021
|
+
//# debugId=6DA0059CEA8E1A6464756E2164756E21
|
|
2021
2022
|
//# sourceMappingURL=sonner-wc.js.map
|