@samline/notify 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ var jsxRuntime = require('react/jsx-runtime');
13
13
  var react = require('react');
14
14
  var react$1 = require('motion/react');
15
15
 
16
- __insertCSS(":root{--notify-spring-easing:linear(\n\t\t0,\n\t\t0.002 0.6%,\n\t\t0.007 1.2%,\n\t\t0.015 1.8%,\n\t\t0.026 2.4%,\n\t\t0.041 3.1%,\n\t\t0.06 3.8%,\n\t\t0.108 5.3%,\n\t\t0.157 6.6%,\n\t\t0.214 8%,\n\t\t0.467 13.7%,\n\t\t0.577 16.3%,\n\t\t0.631 17.7%,\n\t\t0.682 19.1%,\n\t\t0.73 20.5%,\n\t\t0.771 21.8%,\n\t\t0.808 23.1%,\n\t\t0.844 24.5%,\n\t\t0.874 25.8%,\n\t\t0.903 27.2%,\n\t\t0.928 28.6%,\n\t\t0.952 30.1%,\n\t\t0.972 31.6%,\n\t\t0.988 33.1%,\n\t\t1.01 35.7%,\n\t\t1.025 38.5%,\n\t\t1.034 41.6%,\n\t\t1.038 45%,\n\t\t1.035 50.1%,\n\t\t1.012 64.2%,\n\t\t1.003 73%,\n\t\t0.999 83.7%,\n\t\t1\n\t);--notify-duration:600ms;--notify-height:40px;--notify-width:350px;--notify-state-success:oklch(0.723 0.219 142.136);--notify-state-loading:oklch(0.556 0 0);--notify-state-error:oklch(0.637 0.237 25.331);--notify-state-warning:oklch(0.795 0.184 86.047);--notify-state-info:oklch(0.685 0.169 237.323);--notify-state-action:oklch(0.623 0.214 259.815)}[data-notify-toast]{position:relative;cursor:pointer;pointer-events:auto;touch-action:none;border:0;background:0 0;padding:0;width:var(--notify-width);height:var(--_h,var(--notify-height));opacity:0;transform:translateZ(0) scale(.95);transform-origin:center;contain:layout style;overflow:visible}[data-notify-toast][data-state=loading]{cursor:default}[data-notify-toast][data-ready=true]{opacity:1;transform:translateZ(0) scale(1);transition:transform calc(var(--notify-duration) * .66) var(--notify-spring-easing),opacity calc(var(--notify-duration) * .66) var(--notify-spring-easing),margin-bottom calc(var(--notify-duration) * .66) var(--notify-spring-easing),margin-top calc(var(--notify-duration) * .66) var(--notify-spring-easing),height var(--notify-duration) var(--notify-spring-easing)}[data-notify-viewport][data-position^=top] [data-notify-toast]:not([data-ready=true]){transform:translateY(-6px) scale(.95)}[data-notify-viewport][data-position^=bottom] [data-notify-toast]:not([data-ready=true]){transform:translateY(6px) scale(.95)}[data-notify-toast][data-ready=true][data-exiting=true]{opacity:0;pointer-events:none}[data-notify-viewport][data-position^=top] [data-notify-toast][data-ready=true][data-exiting=true]{transform:translateY(-6px) scale(.95)}[data-notify-viewport][data-position^=bottom] [data-notify-toast][data-ready=true][data-exiting=true]{transform:translateY(6px) scale(.95)}[data-notify-canvas]{position:absolute;left:0;right:0;pointer-events:none;transform:translateZ(0);contain:layout style;overflow:visible}[data-sileo-canvas][data-edge=top]{bottom:0;transform:scaleY(-1) translateZ(0)}[data-sileo-canvas][data-edge=bottom]{top:0}[data-notify-svg]{overflow:visible}[data-notify-header]{position:absolute;z-index:20;display:flex;align-items:center;padding:.5rem;height:var(--sileo-height);overflow:hidden;left:var(--_px,0);transform:var(--_ht);max-width:var(--_pw)}[data-notify-toast][data-ready=true] [data-notify-header]{transition:transform var(--sileo-duration) var(--sileo-spring-easing),left var(--sileo-duration) var(--sileo-spring-easing),max-width var(--sileo-duration) var(--sileo-spring-easing)}[data-notify-header][data-edge=top]{bottom:0}[data-notify-header][data-edge=bottom]{top:0}[data-notify-header-stack]{position:relative;display:inline-flex;align-items:center;height:100%}[data-notify-header-inner]{display:flex;align-items:center;gap:.5rem;white-space:nowrap;opacity:1;filter:blur(0px);transform:translateZ(0)}[data-notify-header-inner][data-layer=current]{position:relative;z-index:1;animation:sileo-header-enter var(--sileo-duration) var(--sileo-spring-easing) both}[data-notify-header-inner][data-exiting=true],[data-notify-header-inner][data-layer=current]:not(:only-child){will-change:opacity,filter}[data-notify-header-inner][data-layer=prev]{position:absolute;left:0;top:0;z-index:0;pointer-events:none}[data-notify-header-inner][data-exiting=true]{animation:notify-header-exit calc(var(--notify-duration) * .7) ease forwards}[data-notify-badge]{display:flex;height:24px;width:24px;flex-shrink:0;align-items:center;justify-content:center;padding:2px;box-sizing:border-box;border-radius:9999px;color:var(--sileo-tone,currentColor);background-color:var(--sileo-tone-bg,transparent)}[data-notify-title]{font-size:.825rem;line-height:1rem;font-weight:500;text-transform:capitalize;color:var(--sileo-tone,currentColor)}:is([data-notify-badge],[data-notify-title],[data-notify-button])[data-state]{--_c:var(--notify-state-success)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=loading]{--_c:var(--notify-state-loading)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=error]{--_c:var(--notify-state-error)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=warning]{--_c:var(--notify-state-warning)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=info]{--_c:var(--notify-state-info)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=action]{--_c:var(--notify-state-action)}:is([data-notify-badge],[data-notify-title])[data-state]{--notify-tone:var(--_c);--notify-tone-bg:color-mix(in oklch, var(--_c) 20%, transparent)}[data-notify-content]{position:absolute;left:0;z-index:10;width:100%;pointer-events:none;opacity:var(--_co, 0)}[data-notify-content]:not([data-visible=true]){content-visibility:hidden}[data-notify-toast][data-ready=true] [data-notify-content]{transition:opacity calc(var(--notify-duration) * .08) ease calc(var(--notify-duration) * .04)}[data-notify-content][data-edge=top]{top:0}[data-notify-content][data-edge=bottom]{top:var(--sileo-height)}[data-notify-content][data-visible=true]{pointer-events:auto}[data-notify-toast][data-ready=true] [data-notify-content][data-visible=true]{transition:opacity calc(var(--notify-duration) * .6) ease calc(var(--notify-duration) * .3)}[data-notify-description]{width:100%;text-align:left;padding:1rem;font-size:.875rem;line-height:1.25rem;contain:layout style paint;content-visibility:auto}[data-notify-button]{display:flex;align-items:center;justify-content:center;height:1.75rem;padding:0 .625rem;margin-top:.75rem;border-radius:9999px;border:0;font-size:.75rem;font-weight:500;cursor:pointer;color:var(--sileo-btn-color,currentColor);background-color:var(--sileo-btn-bg,transparent);transition:background-color 150ms ease}[data-notify-button]:hover{background-color:var(--sileo-btn-bg-hover,transparent)}[data-notify-button][data-state]{--notify-btn-color:var(--_c);--notify-btn-bg:color-mix(in oklch, var(--_c) 15%, transparent);--notify-btn-bg-hover:color-mix(in oklch, var(--_c) 25%, transparent)}[data-notify-icon=spin]{animation:notify-spin 1s linear infinite}@keyframes notify-spin{to{transform:rotate(360deg)}}@keyframes notify-header-enter{from{opacity:0;filter:blur(6px)}to{opacity:1;filter:blur(0px)}}@keyframes notify-header-exit{from{opacity:1;filter:blur(0px)}to{opacity:0;filter:blur(6px)}}[data-notify-viewport]{position:fixed;z-index:50;display:flex;gap:.75rem;padding:.75rem;pointer-events:none;max-width:calc(100vw - 1.5rem);contain:layout style}[data-notify-viewport][data-position^=top] [data-notify-toast]:not([data-ready=true]){margin-bottom:calc(-1 * (var(--notify-height) + .75rem))}[data-notify-viewport][data-position^=bottom] [data-notify-toast]:not([data-ready=true]){margin-top:calc(-1 * (var(--notify-height) + .75rem))}[data-notify-viewport][data-position^=top]{top:0;flex-direction:column-reverse}[data-notify-viewport][data-position^=bottom]{bottom:0;flex-direction:column}[data-notify-viewport][data-position$=left]{left:0;align-items:flex-start}[data-notify-viewport][data-position$=right]{right:0;align-items:flex-end}[data-notify-viewport][data-position$=center]{left:50%;transform:translateX(-50%);align-items:center}@media (prefers-reduced-motion:no-preference){[data-notify-toast][data-ready=true]:hover,[data-notify-toast][data-ready=true][data-exiting=true]{will-change:transform,opacity,height}}@media (prefers-reduced-motion:reduce){[data-notify-viewport],[data-notify-viewport] *,[data-notify-viewport] ::after,[data-notify-viewport] ::before{animation-duration:0s;animation-iteration-count:1;transition-duration:0s}}[data-notify-viewport][data-theme=dark] [data-notify-description]{color:rgba(0,0,0,.5)}[data-notify-viewport][data-theme=light] [data-notify-description]{color:rgba(255,255,255,.5)}");
16
+ __insertCSS(":root{--notify-spring-easing:linear(\n\t\t0,\n\t\t0.002 0.6%,\n\t\t0.007 1.2%,\n\t\t0.015 1.8%,\n\t\t0.026 2.4%,\n\t\t0.041 3.1%,\n\t\t0.06 3.8%,\n\t\t0.108 5.3%,\n\t\t0.157 6.6%,\n\t\t0.214 8%,\n\t\t0.467 13.7%,\n\t\t0.577 16.3%,\n\t\t0.631 17.7%,\n\t\t0.682 19.1%,\n\t\t0.73 20.5%,\n\t\t0.771 21.8%,\n\t\t0.808 23.1%,\n\t\t0.844 24.5%,\n\t\t0.874 25.8%,\n\t\t0.903 27.2%,\n\t\t0.928 28.6%,\n\t\t0.952 30.1%,\n\t\t0.972 31.6%,\n\t\t0.988 33.1%,\n\t\t1.01 35.7%,\n\t\t1.025 38.5%,\n\t\t1.034 41.6%,\n\t\t1.038 45%,\n\t\t1.035 50.1%,\n\t\t1.012 64.2%,\n\t\t1.003 73%,\n\t\t0.999 83.7%,\n\t\t1\n\t);--notify-duration:600ms;--notify-height:40px;--notify-width:350px;--notify-state-success:oklch(0.723 0.219 142.136);--notify-state-loading:oklch(0.556 0 0);--notify-state-error:oklch(0.637 0.237 25.331);--notify-state-warning:oklch(0.795 0.184 86.047);--notify-state-info:oklch(0.685 0.169 237.323);--notify-state-action:oklch(0.623 0.214 259.815)}[data-notify-toast]{position:relative;cursor:pointer;pointer-events:auto;touch-action:none;border:0;background:0 0;padding:0;width:var(--notify-width);height:var(--_h,var(--notify-height));opacity:0;transform:translateZ(0) scale(.95);transform-origin:center;contain:layout style;overflow:visible}[data-notify-toast][data-state=loading]{cursor:default}[data-notify-toast][data-ready=true]{opacity:1;transform:translateZ(0) scale(1);transition:transform calc(var(--notify-duration) * .66) var(--notify-spring-easing),opacity calc(var(--notify-duration) * .66) var(--notify-spring-easing),margin-bottom calc(var(--notify-duration) * .66) var(--notify-spring-easing),margin-top calc(var(--notify-duration) * .66) var(--notify-spring-easing),height var(--notify-duration) var(--notify-spring-easing)}[data-notify-viewport][data-position^=top] [data-notify-toast]:not([data-ready=true]){transform:translateY(-6px) scale(.95)}[data-notify-viewport][data-position^=bottom] [data-notify-toast]:not([data-ready=true]){transform:translateY(6px) scale(.95)}[data-notify-toast][data-ready=true][data-exiting=true]{opacity:0;pointer-events:none}[data-notify-viewport][data-position^=top] [data-notify-toast][data-ready=true][data-exiting=true]{transform:translateY(-6px) scale(.95)}[data-notify-viewport][data-position^=bottom] [data-notify-toast][data-ready=true][data-exiting=true]{transform:translateY(6px) scale(.95)}[data-notify-canvas]{position:absolute;left:0;right:0;pointer-events:none;transform:translateZ(0);contain:layout style;overflow:visible}[data-sileo-canvas][data-edge=top]{bottom:0;transform:scaleY(-1) translateZ(0)}[data-sileo-canvas][data-edge=bottom]{top:0}[data-notify-svg]{overflow:visible}[data-notify-header]{position:absolute;z-index:20;display:flex;align-items:center;padding:.5rem;height:var(--sileo-height);overflow:hidden;left:var(--_px,0);transform:var(--_ht);max-width:var(--_pw)}[data-notify-toast][data-ready=true] [data-notify-header]{transition:transform var(--sileo-duration) var(--sileo-spring-easing),left var(--sileo-duration) var(--sileo-spring-easing),max-width var(--sileo-duration) var(--sileo-spring-easing)}[data-notify-header][data-edge=top]{bottom:0}[data-notify-header][data-edge=bottom]{top:0}[data-notify-header-stack]{position:relative;display:inline-flex;align-items:center;height:100%}[data-notify-header-inner]{display:flex;align-items:center;gap:.5rem;white-space:nowrap;opacity:1;filter:blur(0px);transform:translateZ(0)}[data-notify-header-inner][data-layer=current]{position:relative;z-index:1;animation:sileo-header-enter var(--sileo-duration) var(--sileo-spring-easing) both}[data-notify-header-inner][data-exiting=true],[data-notify-header-inner][data-layer=current]:not(:only-child){will-change:opacity,filter}[data-notify-header-inner][data-layer=prev]{position:absolute;left:0;top:0;z-index:0;pointer-events:none}[data-notify-header-inner][data-exiting=true]{animation:notify-header-exit calc(var(--notify-duration) * .7) ease forwards}[data-notify-badge]{display:flex;height:24px;width:24px;flex-shrink:0;align-items:center;justify-content:center;padding:2px;box-sizing:border-box;border-radius:9999px;color:var(--sileo-tone,currentColor);background-color:var(--sileo-tone-bg,transparent)}[data-notify-title]{font-size:.825rem;line-height:1rem;font-weight:500;text-transform:capitalize;color:var(--sileo-tone,currentColor)}:is([data-notify-badge],[data-notify-title],[data-notify-button])[data-state]{--_c:var(--notify-state-success)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=loading]{--_c:var(--notify-state-loading)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=error]{--_c:var(--notify-state-error)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=warning]{--_c:var(--notify-state-warning)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=info]{--_c:var(--notify-state-info)}:is(\n[data-notify-badge],[data-notify-title],[data-notify-button]\n)[data-state=action]{--_c:var(--notify-state-action)}:is([data-notify-badge],[data-notify-title])[data-state]{--notify-tone:var(--_c);--notify-tone-bg:color-mix(in oklch, var(--_c) 20%, transparent)}[data-notify-content]{position:absolute;left:0;z-index:10;width:100%;pointer-events:none;opacity:var(--_co, 0)}[data-notify-content]:not([data-visible=true]){content-visibility:hidden}[data-notify-toast][data-ready=true] [data-notify-content]{transition:opacity calc(var(--notify-duration) * .08) ease calc(var(--notify-duration) * .04)}[data-notify-content][data-edge=top]{top:0}[data-notify-content][data-edge=bottom]{top:var(--sileo-height)}[data-notify-content][data-visible=true]{pointer-events:auto}[data-notify-toast][data-ready=true] [data-notify-content][data-visible=true]{transition:opacity calc(var(--notify-duration) * .6) ease calc(var(--notify-duration) * .3)}[data-notify-description]{width:100%;text-align:left;padding:1rem;font-size:.875rem;line-height:1.25rem;contain:layout style paint;content-visibility:auto}[data-notify-button]{display:flex;align-items:center;justify-content:center;height:1.75rem;padding:0 .625rem;margin-top:.75rem;border-radius:9999px;border:0;font-size:.75rem;font-weight:500;cursor:pointer;color:var(--sileo-btn-color,currentColor);background-color:var(--sileo-btn-bg,transparent);transition:background-color 150ms ease}[data-notify-button]:hover{background-color:var(--sileo-btn-bg-hover,transparent)}[data-notify-button][data-state]{--notify-btn-color:var(--_c);--notify-btn-bg:color-mix(in oklch, var(--_c) 15%, transparent);--notify-btn-bg-hover:color-mix(in oklch, var(--_c) 25%, transparent)}[data-notify-icon=spin]{animation:notify-spin 1s linear infinite}@keyframes notify-spin{to{transform:rotate(360deg)}}@keyframes notify-header-enter{from{opacity:0;filter:blur(6px)}to{opacity:1;filter:blur(0px)}}@keyframes notify-header-exit{from{opacity:1;filter:blur(0px)}to{opacity:0;filter:blur(6px)}}[data-notify-viewport]{position:fixed;z-index:50;display:flex;gap:.75rem;padding:.75rem;pointer-events:none;max-width:calc(100vw - 1.5rem);contain:layout style}[data-notify-viewport][data-position^=top] [data-notify-toast]:not([data-ready=true]){margin-bottom:calc(-1 * (var(--notify-height) + .75rem))}[data-notify-viewport][data-position^=bottom] [data-notify-toast]:not([data-ready=true]){margin-top:calc(-1 * (var(--notify-height) + .75rem))}[data-notify-viewport][data-position^=top]{top:0;flex-direction:column-reverse}[data-notify-viewport][data-position^=bottom]{bottom:0;flex-direction:column}[data-notify-viewport][data-position$=left]{left:0;align-items:flex-start}[data-notify-viewport][data-position$=right]{right:0;align-items:flex-end}[data-notify-viewport][data-position$=center]{left:50%;transform:translateX(-50%);align-items:center}@media (prefers-reduced-motion:no-preference){[data-notify-toast][data-ready=true]:hover,[data-notify-toast][data-ready=true][data-exiting=true]{will-change:transform,opacity,height}}@media (prefers-reduced-motion:reduce){[data-notify-viewport],[data-notify-viewport] *,[data-notify-viewport] ::after,[data-notify-viewport] ::before{animation-duration:0s;animation-iteration-count:1;transition-duration:0s}}[data-notify-viewport][data-theme=dark] [data-notify-description]{color:rgba(0,0,0,.5)}[data-notify-viewport][data-theme=light] [data-notify-description]{color:rgba(255,255,255,.5)}[data-notify-toast]:has([data-notify-card]){width:auto;height:auto;background:0 0}[data-notify-card]{background:#fff;border-radius:20px;box-shadow:0 4px 24px rgba(0,0,0,.1),0 1px 4px rgba(0,0,0,.06);width:var(--notify-width);overflow:hidden}[data-notify-card] [data-notify-header]{position:relative;display:flex;align-items:center;gap:.5rem;padding:.5rem .75rem;height:auto;left:auto;max-width:none;transform:none;overflow:visible}[data-notify-card] [data-notify-content]{position:relative;opacity:1;pointer-events:auto;content-visibility:visible;border-top:1px solid rgba(0,0,0,.06)}[data-notify-card] :is([data-notify-badge],[data-notify-title])[data-state]{color:var(--notify-state-success)}[data-notify-card] :is([data-notify-badge],[data-notify-title])[data-state=error]{color:var(--notify-state-error)}[data-notify-card] :is([data-notify-badge],[data-notify-title])[data-state=warning]{color:var(--notify-state-warning)}[data-notify-card] :is([data-notify-badge],[data-notify-title])[data-state=info]{color:var(--notify-state-info)}[data-notify-card] :is([data-notify-badge],[data-notify-title])[data-state=loading]{color:var(--notify-state-loading)}[data-notify-card] :is([data-notify-badge],[data-notify-title])[data-state=action]{color:var(--notify-state-action)}[data-notify-card] [data-notify-description]{color:rgba(0,0,0,.6)}");
17
17
 
18
18
  /* --------------------------------- Layout --------------------------------- */ const HEIGHT = 40;
19
19
  const WIDTH = 350;
@@ -1063,6 +1063,185 @@ function Toaster({ children, position = "top-right", offset, options, theme }) {
1063
1063
  });
1064
1064
  }
1065
1065
 
1066
+ // Notify logic (no React dependencies)
1067
+ // Provides toast management and utilities for VanillaJS, Vue, Svelte, etc.
1068
+ class NotifyCore {
1069
+ generateId() {
1070
+ return `${++this.idCounter}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
1071
+ }
1072
+ subscribe(fn) {
1073
+ this.listeners.add(fn);
1074
+ fn(this.toasts);
1075
+ return ()=>this.listeners.delete(fn);
1076
+ }
1077
+ emit() {
1078
+ for (const fn of this.listeners)fn(this.toasts);
1079
+ }
1080
+ update(fn) {
1081
+ this.toasts = fn(this.toasts);
1082
+ this.emit();
1083
+ }
1084
+ dismiss(id) {
1085
+ const item = this.toasts.find((t)=>t.id === id);
1086
+ if (!item || item.exiting) return;
1087
+ this.update((prev)=>prev.map((t)=>t.id === id ? cc._extends({}, t, {
1088
+ exiting: true
1089
+ }) : t));
1090
+ setTimeout(()=>this.update((prev)=>prev.filter((t)=>t.id !== id)), 600);
1091
+ }
1092
+ show(opts) {
1093
+ var _ref, _ref1, _opts_type;
1094
+ // Use a unique identifier based on options (e.g., the title or a generated key)
1095
+ // If not provided, use a default one
1096
+ const id = opts.title ? `notify-${opts.title}` : "notify-default";
1097
+ const prevItem = this.toasts.find((t)=>t.id === id);
1098
+ const instanceId = (_ref = prevItem == null ? void 0 : prevItem.instanceId) != null ? _ref : this.generateId();
1099
+ // Set the state correctly
1100
+ const state = (_ref1 = (_opts_type = opts.type) != null ? _opts_type : prevItem == null ? void 0 : prevItem.type) != null ? _ref1 : "success";
1101
+ const item = cc._extends({}, prevItem, opts, {
1102
+ id,
1103
+ instanceId,
1104
+ type: state
1105
+ });
1106
+ this.update((prev)=>{
1107
+ const filtered = prev.filter((t)=>t.id !== id);
1108
+ return [
1109
+ ...filtered,
1110
+ item
1111
+ ];
1112
+ });
1113
+ return id;
1114
+ }
1115
+ getToasts() {
1116
+ return this.toasts;
1117
+ }
1118
+ constructor(){
1119
+ this.toasts = [];
1120
+ this.listeners = new Set();
1121
+ this.position = "top-right";
1122
+ this.options = undefined;
1123
+ this.idCounter = 0;
1124
+ }
1125
+ }
1126
+ // Global instance for multiplatform usage
1127
+ const notifyCore = new NotifyCore();
1128
+
1129
+ const ICONS = {
1130
+ success: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="20 6 9 17 4 12"/></svg>',
1131
+ error: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',
1132
+ warning: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',
1133
+ info: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="m4.93 4.93 4.24 4.24"/><path d="m14.83 9.17 4.24-4.24"/><path d="m14.83 14.83 4.24 4.24"/><path d="m9.17 14.83-4.24 4.24"/><circle cx="12" cy="12" r="4"/></svg>',
1134
+ loading: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" data-notify-icon="spin" aria-hidden="true"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',
1135
+ action: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>'
1136
+ };
1137
+ const EXIT_MS = 600;
1138
+ function capitalize(s) {
1139
+ return s ? s.charAt(0).toUpperCase() + s.slice(1) : "";
1140
+ }
1141
+ let viewport = null;
1142
+ const toastEls = new Map();
1143
+ function getOrCreateViewport(position) {
1144
+ if (!viewport) {
1145
+ viewport = document.createElement("div");
1146
+ viewport.setAttribute("data-notify-viewport", "");
1147
+ viewport.setAttribute("data-position", position);
1148
+ viewport.setAttribute("data-theme", "light");
1149
+ document.body.appendChild(viewport);
1150
+ }
1151
+ return viewport;
1152
+ }
1153
+ function buildToastEl(toast) {
1154
+ const state = toast.type || "success";
1155
+ const btn = document.createElement("button");
1156
+ btn.type = "button";
1157
+ btn.setAttribute("data-notify-toast", "");
1158
+ btn.setAttribute("data-state", state);
1159
+ btn.setAttribute("data-ready", "false");
1160
+ btn.setAttribute("data-exiting", "false");
1161
+ const card = document.createElement("div");
1162
+ card.setAttribute("data-notify-card", "");
1163
+ const header = document.createElement("div");
1164
+ header.setAttribute("data-notify-header", "");
1165
+ const badge = document.createElement("div");
1166
+ badge.setAttribute("data-notify-badge", "");
1167
+ badge.setAttribute("data-state", state);
1168
+ badge.innerHTML = ICONS[state] || ICONS.success;
1169
+ const titleEl = document.createElement("span");
1170
+ titleEl.setAttribute("data-notify-title", "");
1171
+ titleEl.setAttribute("data-state", state);
1172
+ titleEl.textContent = toast.title || capitalize(state);
1173
+ header.appendChild(badge);
1174
+ header.appendChild(titleEl);
1175
+ card.appendChild(header);
1176
+ if (toast.description || toast.button) {
1177
+ const content = document.createElement("div");
1178
+ content.setAttribute("data-notify-content", "");
1179
+ content.setAttribute("data-visible", "true");
1180
+ if (toast.description) {
1181
+ const desc = document.createElement("div");
1182
+ desc.setAttribute("data-notify-description", "");
1183
+ desc.textContent = toast.description;
1184
+ content.appendChild(desc);
1185
+ }
1186
+ if (toast.button) {
1187
+ const actionBtn = document.createElement("button");
1188
+ actionBtn.setAttribute("data-notify-button", "");
1189
+ actionBtn.setAttribute("data-state", state);
1190
+ actionBtn.textContent = toast.button.title;
1191
+ actionBtn.addEventListener("click", (e)=>{
1192
+ var _toast_button;
1193
+ e.stopPropagation();
1194
+ (_toast_button = toast.button) == null ? void 0 : _toast_button.onClick();
1195
+ notifyCore.dismiss(toast.id);
1196
+ });
1197
+ content.appendChild(actionBtn);
1198
+ }
1199
+ card.appendChild(content);
1200
+ }
1201
+ btn.appendChild(card);
1202
+ btn.addEventListener("click", ()=>notifyCore.dismiss(toast.id));
1203
+ requestAnimationFrame(()=>{
1204
+ requestAnimationFrame(()=>{
1205
+ btn.setAttribute("data-ready", "true");
1206
+ });
1207
+ });
1208
+ return btn;
1209
+ }
1210
+ function updateToastEl(el, toast) {
1211
+ const state = toast.type || "success";
1212
+ el.setAttribute("data-state", state);
1213
+ if (toast.exiting) {
1214
+ el.setAttribute("data-exiting", "true");
1215
+ }
1216
+ }
1217
+ function renderNotifyToasts(options = {}) {
1218
+ var _options_position;
1219
+ const position = (_options_position = options.position) != null ? _options_position : "top-right";
1220
+ const vp = getOrCreateViewport(position);
1221
+ return notifyCore.subscribe((toasts)=>{
1222
+ const liveIds = new Set(toasts.map((t)=>t.id));
1223
+ for (const [id, el] of toastEls){
1224
+ if (!liveIds.has(id)) {
1225
+ el.setAttribute("data-exiting", "true");
1226
+ setTimeout(()=>{
1227
+ el.remove();
1228
+ toastEls.delete(id);
1229
+ }, EXIT_MS);
1230
+ }
1231
+ }
1232
+ for (const toast of toasts){
1233
+ if (toastEls.has(toast.id)) {
1234
+ updateToastEl(toastEls.get(toast.id), toast);
1235
+ } else {
1236
+ const el = buildToastEl(toast);
1237
+ toastEls.set(toast.id, el);
1238
+ vp.appendChild(el);
1239
+ }
1240
+ }
1241
+ });
1242
+ }
1243
+
1066
1244
  exports.Toaster = Toaster;
1067
1245
  exports.notify = notify;
1246
+ exports.renderNotifyToasts = renderNotifyToasts;
1068
1247
  exports.showNotifyToast = showNotifyToast;
package/dist/react.d.mts CHANGED
@@ -61,6 +61,10 @@ declare const notify: {
61
61
  declare function showNotifyToast(options: NotifyOptions): string;
62
62
  declare function Toaster({ children, position, offset, options, theme, }: NotifyToasterProps): react_jsx_runtime.JSX.Element;
63
63
 
64
- export { Toaster, notify, showNotifyToast };
64
+ declare function renderNotifyToasts(options?: {
65
+ position?: NotifyPosition;
66
+ }): () => boolean;
67
+
68
+ export { Toaster, notify, renderNotifyToasts, showNotifyToast };
65
69
  export type { NotifyButton, NotifyOptions, NotifyPosition, NotifyState, NotifyStyles };
66
70
  //# sourceMappingURL=react.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.mts","sources":["../src/types.ts","../src/toast.tsx"],"mappings":";;;AAAA,KAAK,WAAW;AAChB,UAAU,YAAY;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU,YAAY;AACtB;AACA;AACA;AACA,cAAc,gBAAgB;AAC9B,KAAK,cAAc,WAAW,gBAAgB;AAC9C,UAAU,aAAa;AACvB;AACA;AACA,WAAW,WAAW;AACtB,eAAe,cAAc;AAC7B;AACA;AACA,aAAa,YAAY;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,YAAY;AACzB;;ACzBA,KAAK,iBAAiB;AACtB,KAAK,kBAAkB,GAAG,OAAO,CAAC,MAAM,sCAAsC,iBAAiB;AAC/F,UAAU,kBAAkB;AAC5B,eAAe,SAAS;AACxB,eAAe,cAAc;AAC7B,aAAa,iBAAiB,GAAG,kBAAkB;AACnD,cAAc,OAAO,CAAC,aAAa;AACnC;AACA;AACA,UAAU,oBAAoB;AAC9B,aAAa,aAAa;AAC1B,aAAa,aAAa,iBAAiB,aAAa;AACxD,WAAW,aAAa,sBAAsB,aAAa;AAC3D,aAAa,aAAa,iBAAiB,aAAa;AACxD,eAAe,cAAc;AAC7B;AACA,cAAc,MAAM;AACpB,iBAAiB,aAAa;AAC9B,oBAAoB,aAAa;AACjC,kBAAkB,aAAa;AAC/B,oBAAoB,aAAa;AACjC,iBAAiB,aAAa;AAC9B,mBAAmB,aAAa;AAChC,0BAA0B,OAAO,aAAa,OAAO,YAAY,oBAAoB,QAAQ,OAAO;AACpG;AACA,uBAAuB,cAAc;AACrC;AACA,iBAAiB,eAAe,UAAU,aAAa;AACvD,iBAAiB,OAAO,kDAAkD,kBAAkB,GAAG,iBAAiB,CAAC,GAAG,CAAC,OAAO;;;;","names":[]}
1
+ {"version":3,"file":"react.d.mts","sources":["../src/types.ts","../src/toast.tsx","../src/render-notify-toasts.ts"],"mappings":";;;AAAA,KAAK,WAAW;AAChB,UAAU,YAAY;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU,YAAY;AACtB;AACA;AACA;AACA,cAAc,gBAAgB;AAC9B,KAAK,cAAc,WAAW,gBAAgB;AAC9C,UAAU,aAAa;AACvB;AACA;AACA,WAAW,WAAW;AACtB,eAAe,cAAc;AAC7B;AACA;AACA,aAAa,YAAY;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,YAAY;AACzB;;ACzBA,KAAK,iBAAiB;AACtB,KAAK,kBAAkB,GAAG,OAAO,CAAC,MAAM,sCAAsC,iBAAiB;AAC/F,UAAU,kBAAkB;AAC5B,eAAe,SAAS;AACxB,eAAe,cAAc;AAC7B,aAAa,iBAAiB,GAAG,kBAAkB;AACnD,cAAc,OAAO,CAAC,aAAa;AACnC;AACA;AACA,UAAU,oBAAoB;AAC9B,aAAa,aAAa;AAC1B,aAAa,aAAa,iBAAiB,aAAa;AACxD,WAAW,aAAa,sBAAsB,aAAa;AAC3D,aAAa,aAAa,iBAAiB,aAAa;AACxD,eAAe,cAAc;AAC7B;AACA,cAAc,MAAM;AACpB,iBAAiB,aAAa;AAC9B,oBAAoB,aAAa;AACjC,kBAAkB,aAAa;AAC/B,oBAAoB,aAAa;AACjC,iBAAiB,aAAa;AAC9B,mBAAmB,aAAa;AAChC,0BAA0B,OAAO,aAAa,OAAO,YAAY,oBAAoB,QAAQ,OAAO;AACpG;AACA,uBAAuB,cAAc;AACrC;AACA,iBAAiB,eAAe,UAAU,aAAa;AACvD,iBAAiB,OAAO,kDAAkD,kBAAkB,GAAG,iBAAiB,CAAC,GAAG,CAAC,OAAO;;AC9B5H,iBAAiB,kBAAkB;AACnC,eAAe,cAAc;AAC7B;;;;","names":[]}
package/dist/react.d.ts CHANGED
@@ -61,6 +61,10 @@ declare const notify: {
61
61
  declare function showNotifyToast(options: NotifyOptions): string;
62
62
  declare function Toaster({ children, position, offset, options, theme, }: NotifyToasterProps): react_jsx_runtime.JSX.Element;
63
63
 
64
- export { Toaster, notify, showNotifyToast };
64
+ declare function renderNotifyToasts(options?: {
65
+ position?: NotifyPosition;
66
+ }): () => boolean;
67
+
68
+ export { Toaster, notify, renderNotifyToasts, showNotifyToast };
65
69
  export type { NotifyButton, NotifyOptions, NotifyPosition, NotifyState, NotifyStyles };
66
70
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sources":["../src/types.ts","../src/toast.tsx"],"mappings":";;;AAAA,KAAK,WAAW;AAChB,UAAU,YAAY;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU,YAAY;AACtB;AACA;AACA;AACA,cAAc,gBAAgB;AAC9B,KAAK,cAAc,WAAW,gBAAgB;AAC9C,UAAU,aAAa;AACvB;AACA;AACA,WAAW,WAAW;AACtB,eAAe,cAAc;AAC7B;AACA;AACA,aAAa,YAAY;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,YAAY;AACzB;;ACzBA,KAAK,iBAAiB;AACtB,KAAK,kBAAkB,GAAG,OAAO,CAAC,MAAM,sCAAsC,iBAAiB;AAC/F,UAAU,kBAAkB;AAC5B,eAAe,SAAS;AACxB,eAAe,cAAc;AAC7B,aAAa,iBAAiB,GAAG,kBAAkB;AACnD,cAAc,OAAO,CAAC,aAAa;AACnC;AACA;AACA,UAAU,oBAAoB;AAC9B,aAAa,aAAa;AAC1B,aAAa,aAAa,iBAAiB,aAAa;AACxD,WAAW,aAAa,sBAAsB,aAAa;AAC3D,aAAa,aAAa,iBAAiB,aAAa;AACxD,eAAe,cAAc;AAC7B;AACA,cAAc,MAAM;AACpB,iBAAiB,aAAa;AAC9B,oBAAoB,aAAa;AACjC,kBAAkB,aAAa;AAC/B,oBAAoB,aAAa;AACjC,iBAAiB,aAAa;AAC9B,mBAAmB,aAAa;AAChC,0BAA0B,OAAO,aAAa,OAAO,YAAY,oBAAoB,QAAQ,OAAO;AACpG;AACA,uBAAuB,cAAc;AACrC;AACA,iBAAiB,eAAe,UAAU,aAAa;AACvD,iBAAiB,OAAO,kDAAkD,kBAAkB,GAAG,iBAAiB,CAAC,GAAG,CAAC,OAAO;;;;","names":[]}
1
+ {"version":3,"file":"react.d.ts","sources":["../src/types.ts","../src/toast.tsx","../src/render-notify-toasts.ts"],"mappings":";;;AAAA,KAAK,WAAW;AAChB,UAAU,YAAY;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU,YAAY;AACtB;AACA;AACA;AACA,cAAc,gBAAgB;AAC9B,KAAK,cAAc,WAAW,gBAAgB;AAC9C,UAAU,aAAa;AACvB;AACA;AACA,WAAW,WAAW;AACtB,eAAe,cAAc;AAC7B;AACA;AACA,aAAa,YAAY;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,YAAY;AACzB;;ACzBA,KAAK,iBAAiB;AACtB,KAAK,kBAAkB,GAAG,OAAO,CAAC,MAAM,sCAAsC,iBAAiB;AAC/F,UAAU,kBAAkB;AAC5B,eAAe,SAAS;AACxB,eAAe,cAAc;AAC7B,aAAa,iBAAiB,GAAG,kBAAkB;AACnD,cAAc,OAAO,CAAC,aAAa;AACnC;AACA;AACA,UAAU,oBAAoB;AAC9B,aAAa,aAAa;AAC1B,aAAa,aAAa,iBAAiB,aAAa;AACxD,WAAW,aAAa,sBAAsB,aAAa;AAC3D,aAAa,aAAa,iBAAiB,aAAa;AACxD,eAAe,cAAc;AAC7B;AACA,cAAc,MAAM;AACpB,iBAAiB,aAAa;AAC9B,oBAAoB,aAAa;AACjC,kBAAkB,aAAa;AAC/B,oBAAoB,aAAa;AACjC,iBAAiB,aAAa;AAC9B,mBAAmB,aAAa;AAChC,0BAA0B,OAAO,aAAa,OAAO,YAAY,oBAAoB,QAAQ,OAAO;AACpG;AACA,uBAAuB,cAAc;AACrC;AACA,iBAAiB,eAAe,UAAU,aAAa;AACvD,iBAAiB,OAAO,kDAAkD,kBAAkB,GAAG,iBAAiB,CAAC,GAAG,CAAC,OAAO;;AC9B5H,iBAAiB,kBAAkB;AACnC,eAAe,cAAc;AAC7B;;;;","names":[]}
package/dist/react.js CHANGED
@@ -9,10 +9,11 @@ function __insertCSS(code) {
9
9
 
10
10
  Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
- var reactNotify12s = require('./react-notify-12s-7LOZlSBi.js');
12
+ var reactNotify12s = require('./react-notify-12s-Kv2M6zlv.js');
13
13
 
14
14
 
15
15
 
16
16
  exports.Toaster = reactNotify12s.Toaster;
17
17
  exports.notify = reactNotify12s.notify;
18
+ exports.renderNotifyToasts = reactNotify12s.renderNotifyToasts;
18
19
  exports.showNotifyToast = reactNotify12s.showNotifyToast;
package/dist/react.mjs CHANGED
@@ -7,4 +7,4 @@ function __insertCSS(code) {
7
7
  ;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
8
8
  }
9
9
 
10
- export { T as Toaster, n as notify, s as showNotifyToast } from './react-notify-12s-BjWbwTu8.mjs';
10
+ export { T as Toaster, n as notify, r as renderNotifyToasts, s as showNotifyToast } from './react-notify-12s--2JK5UjB.mjs';
@@ -0,0 +1,213 @@
1
+ (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+
40
+ // src/render-notify-toasts.ts
41
+ var exports_render_notify_toasts = {};
42
+ __export(exports_render_notify_toasts, {
43
+ renderNotifyToasts: () => renderNotifyToasts
44
+ });
45
+
46
+ // src/core/notify-core.ts
47
+ class NotifyCore {
48
+ toasts = [];
49
+ listeners = new Set;
50
+ position = "top-right";
51
+ options = undefined;
52
+ idCounter = 0;
53
+ generateId() {
54
+ return `${++this.idCounter}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
55
+ }
56
+ subscribe(fn) {
57
+ this.listeners.add(fn);
58
+ fn(this.toasts);
59
+ return () => this.listeners.delete(fn);
60
+ }
61
+ emit() {
62
+ for (const fn of this.listeners)
63
+ fn(this.toasts);
64
+ }
65
+ update(fn) {
66
+ this.toasts = fn(this.toasts);
67
+ this.emit();
68
+ }
69
+ dismiss(id) {
70
+ const item = this.toasts.find((t) => t.id === id);
71
+ if (!item || item.exiting)
72
+ return;
73
+ this.update((prev) => prev.map((t) => t.id === id ? { ...t, exiting: true } : t));
74
+ setTimeout(() => this.update((prev) => prev.filter((t) => t.id !== id)), 600);
75
+ }
76
+ show(opts) {
77
+ const id = opts.title ? `notify-${opts.title}` : "notify-default";
78
+ const prevItem = this.toasts.find((t) => t.id === id);
79
+ const instanceId = prevItem?.instanceId ?? this.generateId();
80
+ const state = opts.type ?? prevItem?.type ?? "success";
81
+ const item = {
82
+ ...prevItem,
83
+ ...opts,
84
+ id,
85
+ instanceId,
86
+ type: state
87
+ };
88
+ this.update((prev) => {
89
+ const filtered = prev.filter((t) => t.id !== id);
90
+ return [...filtered, item];
91
+ });
92
+ return id;
93
+ }
94
+ getToasts() {
95
+ return this.toasts;
96
+ }
97
+ }
98
+ var notifyCore = new NotifyCore;
99
+
100
+ // src/render-notify-toasts.ts
101
+ var ICONS = {
102
+ success: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="20 6 9 17 4 12"/></svg>',
103
+ error: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',
104
+ warning: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',
105
+ info: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="m4.93 4.93 4.24 4.24"/><path d="m14.83 9.17 4.24-4.24"/><path d="m14.83 14.83 4.24 4.24"/><path d="m9.17 14.83-4.24 4.24"/><circle cx="12" cy="12" r="4"/></svg>',
106
+ loading: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" data-notify-icon="spin" aria-hidden="true"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',
107
+ action: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>'
108
+ };
109
+ var EXIT_MS = 600;
110
+ function capitalize(s) {
111
+ return s ? s.charAt(0).toUpperCase() + s.slice(1) : "";
112
+ }
113
+ var viewport = null;
114
+ var toastEls = new Map;
115
+ function getOrCreateViewport(position) {
116
+ if (!viewport) {
117
+ viewport = document.createElement("div");
118
+ viewport.setAttribute("data-notify-viewport", "");
119
+ viewport.setAttribute("data-position", position);
120
+ viewport.setAttribute("data-theme", "light");
121
+ document.body.appendChild(viewport);
122
+ }
123
+ return viewport;
124
+ }
125
+ function buildToastEl(toast) {
126
+ const state = toast.type || "success";
127
+ const btn = document.createElement("button");
128
+ btn.type = "button";
129
+ btn.setAttribute("data-notify-toast", "");
130
+ btn.setAttribute("data-state", state);
131
+ btn.setAttribute("data-ready", "false");
132
+ btn.setAttribute("data-exiting", "false");
133
+ const card = document.createElement("div");
134
+ card.setAttribute("data-notify-card", "");
135
+ const header = document.createElement("div");
136
+ header.setAttribute("data-notify-header", "");
137
+ const badge = document.createElement("div");
138
+ badge.setAttribute("data-notify-badge", "");
139
+ badge.setAttribute("data-state", state);
140
+ badge.innerHTML = ICONS[state] || ICONS.success;
141
+ const titleEl = document.createElement("span");
142
+ titleEl.setAttribute("data-notify-title", "");
143
+ titleEl.setAttribute("data-state", state);
144
+ titleEl.textContent = toast.title || capitalize(state);
145
+ header.appendChild(badge);
146
+ header.appendChild(titleEl);
147
+ card.appendChild(header);
148
+ if (toast.description || toast.button) {
149
+ const content = document.createElement("div");
150
+ content.setAttribute("data-notify-content", "");
151
+ content.setAttribute("data-visible", "true");
152
+ if (toast.description) {
153
+ const desc = document.createElement("div");
154
+ desc.setAttribute("data-notify-description", "");
155
+ desc.textContent = toast.description;
156
+ content.appendChild(desc);
157
+ }
158
+ if (toast.button) {
159
+ const actionBtn = document.createElement("button");
160
+ actionBtn.setAttribute("data-notify-button", "");
161
+ actionBtn.setAttribute("data-state", state);
162
+ actionBtn.textContent = toast.button.title;
163
+ actionBtn.addEventListener("click", (e) => {
164
+ e.stopPropagation();
165
+ toast.button?.onClick();
166
+ notifyCore.dismiss(toast.id);
167
+ });
168
+ content.appendChild(actionBtn);
169
+ }
170
+ card.appendChild(content);
171
+ }
172
+ btn.appendChild(card);
173
+ btn.addEventListener("click", () => notifyCore.dismiss(toast.id));
174
+ requestAnimationFrame(() => {
175
+ requestAnimationFrame(() => {
176
+ btn.setAttribute("data-ready", "true");
177
+ });
178
+ });
179
+ return btn;
180
+ }
181
+ function updateToastEl(el, toast) {
182
+ const state = toast.type || "success";
183
+ el.setAttribute("data-state", state);
184
+ if (toast.exiting) {
185
+ el.setAttribute("data-exiting", "true");
186
+ }
187
+ }
188
+ function renderNotifyToasts(options = {}) {
189
+ const position = options.position ?? "top-right";
190
+ const vp = getOrCreateViewport(position);
191
+ return notifyCore.subscribe((toasts) => {
192
+ const liveIds = new Set(toasts.map((t) => t.id));
193
+ for (const [id, el] of toastEls) {
194
+ if (!liveIds.has(id)) {
195
+ el.setAttribute("data-exiting", "true");
196
+ setTimeout(() => {
197
+ el.remove();
198
+ toastEls.delete(id);
199
+ }, EXIT_MS);
200
+ }
201
+ }
202
+ for (const toast of toasts) {
203
+ if (toastEls.has(toast.id)) {
204
+ updateToastEl(toastEls.get(toast.id), toast);
205
+ } else {
206
+ const el = buildToastEl(toast);
207
+ toastEls.set(toast.id, el);
208
+ vp.appendChild(el);
209
+ }
210
+ }
211
+ });
212
+ }
213
+ })();
package/dist/styles.css CHANGED
@@ -475,3 +475,84 @@
475
475
  [data-notify-viewport][data-theme="light"] [data-notify-description] {
476
476
  color: rgba(255, 255, 255, 0.5);
477
477
  }
478
+
479
+ /* -------- Browser / CDN card renderer (render-notify-toasts.js) ---------- */
480
+ /*
481
+ * When a [data-notify-card] is present (VanillaJS renderer), we override the
482
+ * SVG-based layout from the React component and use a plain HTML card instead.
483
+ */
484
+
485
+ [data-notify-toast]:has([data-notify-card]) {
486
+ width: auto;
487
+ height: auto;
488
+ background: transparent;
489
+ }
490
+
491
+ [data-notify-card] {
492
+ background: #ffffff;
493
+ border-radius: 20px;
494
+ box-shadow:
495
+ 0 4px 24px rgba(0, 0, 0, 0.1),
496
+ 0 1px 4px rgba(0, 0, 0, 0.06);
497
+ width: var(--notify-width);
498
+ overflow: hidden;
499
+ }
500
+
501
+ /* Header row: icon badge + title */
502
+ [data-notify-card] [data-notify-header] {
503
+ position: relative;
504
+ display: flex;
505
+ align-items: center;
506
+ gap: 0.5rem;
507
+ padding: 0.5rem 0.75rem;
508
+ height: auto;
509
+ left: auto;
510
+ max-width: none;
511
+ transform: none;
512
+ overflow: visible;
513
+ }
514
+
515
+ /* Content area: description + optional button */
516
+ [data-notify-card] [data-notify-content] {
517
+ position: relative;
518
+ opacity: 1;
519
+ pointer-events: auto;
520
+ content-visibility: visible;
521
+ border-top: 1px solid rgba(0, 0, 0, 0.06);
522
+ }
523
+
524
+ /* State colors for the badge icon and title inside the card */
525
+ [data-notify-card]
526
+ :is([data-notify-badge], [data-notify-title])[data-state] {
527
+ color: var(--notify-state-success);
528
+ }
529
+
530
+ [data-notify-card]
531
+ :is([data-notify-badge], [data-notify-title])[data-state="error"] {
532
+ color: var(--notify-state-error);
533
+ }
534
+
535
+ [data-notify-card]
536
+ :is([data-notify-badge], [data-notify-title])[data-state="warning"] {
537
+ color: var(--notify-state-warning);
538
+ }
539
+
540
+ [data-notify-card]
541
+ :is([data-notify-badge], [data-notify-title])[data-state="info"] {
542
+ color: var(--notify-state-info);
543
+ }
544
+
545
+ [data-notify-card]
546
+ :is([data-notify-badge], [data-notify-title])[data-state="loading"] {
547
+ color: var(--notify-state-loading);
548
+ }
549
+
550
+ [data-notify-card]
551
+ :is([data-notify-badge], [data-notify-title])[data-state="action"] {
552
+ color: var(--notify-state-action);
553
+ }
554
+
555
+ /* Description text */
556
+ [data-notify-card] [data-notify-description] {
557
+ color: rgba(0, 0, 0, 0.6);
558
+ }
package/dist/svelte.d.mts CHANGED
@@ -41,5 +41,9 @@ interface NotifyItem extends NotifyOptions {
41
41
  declare const notifyToasts: svelte_store.Writable<NotifyItem[]>;
42
42
  declare function showNotifyToast(options: NotifyOptions): string;
43
43
 
44
- export { notifyToasts, showNotifyToast };
44
+ declare function renderNotifyToasts(options?: {
45
+ position?: NotifyPosition;
46
+ }): () => boolean;
47
+
48
+ export { notifyToasts, renderNotifyToasts, showNotifyToast };
45
49
  //# sourceMappingURL=svelte.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"svelte.d.mts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/svelte-notify.ts"],"mappings":";;AAAA,KAAK,WAAW;AAChB,UAAU,YAAY;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU,YAAY;AACtB;AACA;AACA;AACA,cAAc,gBAAgB;AAC9B,KAAK,cAAc,WAAW,gBAAgB;AAC9C,UAAU,aAAa;AACvB;AACA;AACA,WAAW,WAAW;AACtB,eAAe,cAAc;AAC7B;AACA;AACA,aAAa,YAAY;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,YAAY;AACzB;;AC1BA,UAAU,UAAU,SAAS,aAAa;AAC1C;AACA;AACA;AACA;AACA;AACA;;ACLA,cAAc,YAAY,EAAE,YAAY,CAAC,QAAQ,CAACA,UAA6B;AAC/E,iBAAiB,eAAe,UAAU,aAAa;;;;","names":["__core_notify_core.NotifyItem"]}
1
+ {"version":3,"file":"svelte.d.mts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/svelte-notify.ts","../src/render-notify-toasts.ts"],"mappings":";;AAAA,KAAK,WAAW;AAChB,UAAU,YAAY;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU,YAAY;AACtB;AACA;AACA;AACA,cAAc,gBAAgB;AAC9B,KAAK,cAAc,WAAW,gBAAgB;AAC9C,UAAU,aAAa;AACvB;AACA;AACA,WAAW,WAAW;AACtB,eAAe,cAAc;AAC7B;AACA;AACA,aAAa,YAAY;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,YAAY;AACzB;;AC1BA,UAAU,UAAU,SAAS,aAAa;AAC1C;AACA;AACA;AACA;AACA;AACA;;ACLA,cAAc,YAAY,EAAE,YAAY,CAAC,QAAQ,CAACA,UAA6B;AAC/E,iBAAiB,eAAe,UAAU,aAAa;;ACHvD,iBAAiB,kBAAkB;AACnC,eAAe,cAAc;AAC7B;;;;","names":["__core_notify_core.NotifyItem"]}
package/dist/svelte.d.ts CHANGED
@@ -41,5 +41,9 @@ interface NotifyItem extends NotifyOptions {
41
41
  declare const notifyToasts: svelte_store.Writable<NotifyItem[]>;
42
42
  declare function showNotifyToast(options: NotifyOptions): string;
43
43
 
44
- export { notifyToasts, showNotifyToast };
44
+ declare function renderNotifyToasts(options?: {
45
+ position?: NotifyPosition;
46
+ }): () => boolean;
47
+
48
+ export { notifyToasts, renderNotifyToasts, showNotifyToast };
45
49
  //# sourceMappingURL=svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"svelte.d.ts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/svelte-notify.ts"],"mappings":";;AAAA,KAAK,WAAW;AAChB,UAAU,YAAY;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU,YAAY;AACtB;AACA;AACA;AACA,cAAc,gBAAgB;AAC9B,KAAK,cAAc,WAAW,gBAAgB;AAC9C,UAAU,aAAa;AACvB;AACA;AACA,WAAW,WAAW;AACtB,eAAe,cAAc;AAC7B;AACA;AACA,aAAa,YAAY;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,YAAY;AACzB;;AC1BA,UAAU,UAAU,SAAS,aAAa;AAC1C;AACA;AACA;AACA;AACA;AACA;;ACLA,cAAc,YAAY,EAAE,YAAY,CAAC,QAAQ,CAACA,UAA6B;AAC/E,iBAAiB,eAAe,UAAU,aAAa;;;;","names":["__core_notify_core.NotifyItem"]}
1
+ {"version":3,"file":"svelte.d.ts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/svelte-notify.ts","../src/render-notify-toasts.ts"],"mappings":";;AAAA,KAAK,WAAW;AAChB,UAAU,YAAY;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU,YAAY;AACtB;AACA;AACA;AACA,cAAc,gBAAgB;AAC9B,KAAK,cAAc,WAAW,gBAAgB;AAC9C,UAAU,aAAa;AACvB;AACA;AACA,WAAW,WAAW;AACtB,eAAe,cAAc;AAC7B;AACA;AACA,aAAa,YAAY;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,YAAY;AACzB;;AC1BA,UAAU,UAAU,SAAS,aAAa;AAC1C;AACA;AACA;AACA;AACA;AACA;;ACLA,cAAc,YAAY,EAAE,YAAY,CAAC,QAAQ,CAACA,UAA6B;AAC/E,iBAAiB,eAAe,UAAU,aAAa;;ACHvD,iBAAiB,kBAAkB;AACnC,eAAe,cAAc;AAC7B;;;;","names":["__core_notify_core.NotifyItem"]}