aark-react-modalify 1.0.5 → 1.2.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.
@@ -0,0 +1,898 @@
1
+ import { useState, useCallback, useEffect, memo, useMemo, createElement } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { createPortal } from "react-dom";
5
+ function useModal() {
6
+ const [isOpen2, setIsOpen] = useState(false);
7
+ const [config, setConfig] = useState(null);
8
+ const close2 = useCallback(() => {
9
+ modalManager.close();
10
+ }, []);
11
+ useEffect(() => {
12
+ const handleModalEvent = (event) => {
13
+ switch (event.type) {
14
+ case "open":
15
+ setIsOpen(true);
16
+ setConfig(event.config || null);
17
+ break;
18
+ case "close":
19
+ setIsOpen(false);
20
+ setConfig(null);
21
+ break;
22
+ }
23
+ };
24
+ const unsubscribe = modalManager.subscribe(handleModalEvent);
25
+ setIsOpen(modalManager.isOpen());
26
+ setConfig(modalManager.getCurrentConfig());
27
+ return unsubscribe;
28
+ }, []);
29
+ return {
30
+ isOpen: isOpen2,
31
+ config,
32
+ close: close2
33
+ };
34
+ }
35
+ const colors = {
36
+ white: "#FFFFFF",
37
+ black: "#0B071A"
38
+ };
39
+ const Icon = memo(
40
+ ({
41
+ name,
42
+ color = "black",
43
+ style,
44
+ className = "",
45
+ noHoverEffect = false,
46
+ onClick,
47
+ size = 24,
48
+ "aria-label": ariaLabel,
49
+ title
50
+ }) => {
51
+ const resolvedSize = useMemo(() => {
52
+ return String(size);
53
+ }, [size]);
54
+ const resolvedColor = useMemo(() => {
55
+ if (colors[color]) {
56
+ return colors[color];
57
+ }
58
+ if (color.startsWith("#")) {
59
+ return color;
60
+ }
61
+ return color;
62
+ }, [color]);
63
+ const iconElement = useMemo(() => {
64
+ const fill = resolvedColor;
65
+ switch (name) {
66
+ case "close":
67
+ return /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: resolvedSize, height: resolvedSize, viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M15.281 14.2198C15.3507 14.2895 15.406 14.3722 15.4437 14.4632C15.4814 14.5543 15.5008 14.6519 15.5008 14.7504C15.5008 14.849 15.4814 14.9465 15.4437 15.0376C15.406 15.1286 15.3507 15.2114 15.281 15.281C15.2114 15.3507 15.1286 15.406 15.0376 15.4437C14.9465 15.4814 14.849 15.5008 14.7504 15.5008C14.6519 15.5008 14.5543 15.4814 14.4632 15.4437C14.3722 15.406 14.2895 15.3507 14.2198 15.281L8.00042 9.06073L1.78104 15.281C1.64031 15.4218 1.44944 15.5008 1.25042 15.5008C1.05139 15.5008 0.860523 15.4218 0.719792 15.281C0.579062 15.1403 0.5 14.9494 0.5 14.7504C0.5 14.5514 0.579062 14.3605 0.719792 14.2198L6.9401 8.00042L0.719792 1.78104C0.579062 1.64031 0.5 1.44944 0.5 1.25042C0.5 1.05139 0.579062 0.860523 0.719792 0.719792C0.860523 0.579062 1.05139 0.5 1.25042 0.5C1.44944 0.5 1.64031 0.579062 1.78104 0.719792L8.00042 6.9401L14.2198 0.719792C14.3605 0.579062 14.5514 0.5 14.7504 0.5C14.9494 0.5 15.1403 0.579062 15.281 0.719792C15.4218 0.860523 15.5008 1.05139 15.5008 1.25042C15.5008 1.44944 15.4218 1.64031 15.281 1.78104L9.06073 8.00042L15.281 14.2198Z", fill }) });
68
+ default:
69
+ return null;
70
+ }
71
+ }, [name, resolvedColor, resolvedSize]);
72
+ const accessibilityProps = useMemo(() => {
73
+ const props = {};
74
+ if (ariaLabel) {
75
+ props["aria-label"] = ariaLabel;
76
+ } else {
77
+ props["aria-label"] = `${name} icon`;
78
+ }
79
+ if (title) {
80
+ props.title = title;
81
+ }
82
+ props.role = onClick ? "button" : "img";
83
+ return props;
84
+ }, [ariaLabel, title, name, onClick]);
85
+ const handleKeyDown = useMemo(() => {
86
+ if (!onClick) return void 0;
87
+ return (event) => {
88
+ if (event.key === "Enter" || event.key === " ") {
89
+ event.preventDefault();
90
+ onClick();
91
+ }
92
+ };
93
+ }, [onClick]);
94
+ return /* @__PURE__ */ jsx(
95
+ "i",
96
+ {
97
+ className: `
98
+ inline-flex items-center justify-center bg-transparent outline-none border-none
99
+ ${!noHoverEffect && onClick && "hover:opacity-80 cursor-pointer transition-opacity duration-200"}
100
+ ${onClick && "focus:outline-2 focus:outline-blue-500 focus:outline-offset-2"}
101
+ ${className}
102
+ `.trim(),
103
+ style,
104
+ onClick,
105
+ onKeyDown: handleKeyDown,
106
+ tabIndex: onClick ? 0 : void 0,
107
+ ...accessibilityProps,
108
+ children: iconElement
109
+ }
110
+ );
111
+ }
112
+ );
113
+ Icon.displayName = "Icon";
114
+ const typeIcons$1 = {
115
+ success: "✓",
116
+ error: "✕",
117
+ warning: "⚠",
118
+ info: "ⓘ",
119
+ question: "?"
120
+ };
121
+ const typeColors$1 = {
122
+ success: "#4ade80",
123
+ error: "#ef4444",
124
+ warning: "#f59e0b",
125
+ info: "#3b82f6",
126
+ question: "#8b5cf6"
127
+ };
128
+ const StandardModal = ({ props, onClose }) => {
129
+ const {
130
+ title,
131
+ text,
132
+ type = "info",
133
+ cancelText = "Cancel",
134
+ confirmText = "OK",
135
+ onCancel,
136
+ onConfirm,
137
+ icon,
138
+ html,
139
+ showCancelButton = false,
140
+ showConfirmButton = true,
141
+ reverseButtons = false,
142
+ width = "auto",
143
+ fullWidth = false,
144
+ customClass = {}
145
+ } = props;
146
+ const handleCancel = () => {
147
+ onCancel?.();
148
+ onClose();
149
+ };
150
+ const handleConfirm = () => {
151
+ onConfirm?.();
152
+ onClose();
153
+ };
154
+ const iconElement = useMemo(() => {
155
+ if (icon) {
156
+ return typeof icon === "string" ? /* @__PURE__ */ jsx("span", { children: icon }) : icon;
157
+ }
158
+ return /* @__PURE__ */ jsx("span", { style: { color: typeColors$1[type] }, children: typeIcons$1[type] });
159
+ }, [icon, type]);
160
+ const buttonOrder = reverseButtons ? ["confirm", "cancel"] : ["cancel", "confirm"];
161
+ const modalStyle = useMemo(() => {
162
+ const baseStyle = {};
163
+ if (fullWidth) {
164
+ baseStyle.width = "calc(100vw - 20px)";
165
+ baseStyle.maxWidth = "calc(100vw - 20px)";
166
+ } else {
167
+ if (typeof width === "number") {
168
+ baseStyle.width = `${width}px`;
169
+ } else {
170
+ baseStyle.width = width;
171
+ }
172
+ }
173
+ return baseStyle;
174
+ }, [width, fullWidth]);
175
+ return /* @__PURE__ */ jsxs("div", { className: `aark-standard-modal ${customClass.popup || ""}`, style: modalStyle, children: [
176
+ /* @__PURE__ */ jsxs("div", { className: `aark-modal-content ${customClass.content || ""}`, children: [
177
+ iconElement && /* @__PURE__ */ jsx("div", { className: `aark-modal-icon ${customClass.icon || ""}`, children: iconElement }),
178
+ title && /* @__PURE__ */ jsx("div", { className: `aark-modal-header ${customClass.header || ""}`, children: /* @__PURE__ */ jsx("h2", { className: `aark-modal-title ${customClass.title || ""}`, children: title }) }),
179
+ html ? /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: typeof html === "string" ? html : "" } }) : text ? /* @__PURE__ */ jsx("p", { children: text }) : null
180
+ ] }),
181
+ (showCancelButton || showConfirmButton) && /* @__PURE__ */ jsx("div", { className: `aark-modal-footer ${customClass.actions || ""}`, children: buttonOrder.map((buttonType) => {
182
+ if (buttonType === "cancel" && showCancelButton) {
183
+ return /* @__PURE__ */ jsx(
184
+ "button",
185
+ {
186
+ onClick: handleCancel,
187
+ className: `aark-modal-cancel-button ${customClass.cancelButton || ""}`,
188
+ children: cancelText
189
+ },
190
+ "cancel"
191
+ );
192
+ }
193
+ if (buttonType === "confirm" && showConfirmButton) {
194
+ return /* @__PURE__ */ jsx(
195
+ "button",
196
+ {
197
+ onClick: handleConfirm,
198
+ className: `aark-modal-confirm-button ${customClass.confirmButton || ""}`,
199
+ style: {
200
+ background: typeColors$1[type]
201
+ },
202
+ children: confirmText
203
+ },
204
+ "confirm"
205
+ );
206
+ }
207
+ return null;
208
+ }) })
209
+ ] });
210
+ };
211
+ let modalRoot = null;
212
+ const getModalRoot = () => {
213
+ if (!modalRoot) {
214
+ modalRoot = document.getElementById("aark-react-modalify-root");
215
+ if (!modalRoot) {
216
+ modalRoot = document.createElement("div");
217
+ modalRoot.id = "aark-react-modalify-root";
218
+ modalRoot.style.cssText = `
219
+ position: fixed;
220
+ top: 0;
221
+ left: 0;
222
+ width: 100%;
223
+ height: 100%;
224
+ pointer-events: none;
225
+ z-index: 9998;
226
+ `;
227
+ document.body.appendChild(modalRoot);
228
+ }
229
+ }
230
+ return modalRoot;
231
+ };
232
+ const cleanupModalRoot = () => {
233
+ if (modalRoot && modalRoot.children.length === 0) {
234
+ modalRoot.remove();
235
+ modalRoot = null;
236
+ }
237
+ };
238
+ const Modal = ({ config, onClose }) => {
239
+ const { content, props, options = {} } = config;
240
+ const {
241
+ position = "center",
242
+ showCloseIcon = true,
243
+ className = "",
244
+ overlayClassName = "",
245
+ preventEscClose = false,
246
+ preventOverlayClose = false
247
+ } = options;
248
+ useEffect(() => {
249
+ const handleKeyDown = (event) => {
250
+ if (event.key === "Escape" && !preventEscClose) {
251
+ onClose();
252
+ }
253
+ };
254
+ if (!preventEscClose) {
255
+ document.addEventListener("keydown", handleKeyDown);
256
+ return () => document.removeEventListener("keydown", handleKeyDown);
257
+ }
258
+ }, [onClose, preventEscClose]);
259
+ const handleOverlayClick = useCallback(
260
+ (event) => {
261
+ if (event.target === event.currentTarget && !preventOverlayClose) {
262
+ onClose();
263
+ }
264
+ },
265
+ [onClose, preventOverlayClose]
266
+ );
267
+ const handleCloseClick = useCallback(
268
+ (event) => {
269
+ event.stopPropagation();
270
+ onClose();
271
+ },
272
+ [onClose]
273
+ );
274
+ const contentClasses = `aark-modal-container ${position} ${className}`.trim();
275
+ const modalContainer = getModalRoot();
276
+ const renderContent = () => {
277
+ if (props) {
278
+ return /* @__PURE__ */ jsxs(
279
+ "div",
280
+ {
281
+ className: contentClasses,
282
+ role: "dialog",
283
+ "aria-modal": "true",
284
+ onClick: (e) => e.stopPropagation(),
285
+ children: [
286
+ showCloseIcon && /* @__PURE__ */ jsx(
287
+ "button",
288
+ {
289
+ onClick: handleCloseClick,
290
+ className: "aark-modal-close",
291
+ "aria-label": "Close Modal",
292
+ type: "button",
293
+ children: /* @__PURE__ */ jsx(Icon, { name: "close", size: 12 })
294
+ }
295
+ ),
296
+ /* @__PURE__ */ jsx("div", { className: "aark-modal-wrapper", children: /* @__PURE__ */ jsx(StandardModal, { props, onClose }) })
297
+ ]
298
+ }
299
+ );
300
+ } else if (content) {
301
+ return /* @__PURE__ */ jsxs(
302
+ "div",
303
+ {
304
+ className: contentClasses,
305
+ role: "dialog",
306
+ "aria-modal": "true",
307
+ onClick: (e) => e.stopPropagation(),
308
+ children: [
309
+ showCloseIcon && /* @__PURE__ */ jsx(
310
+ "button",
311
+ {
312
+ onClick: handleCloseClick,
313
+ className: "aark-modal-close",
314
+ "aria-label": "Close Modal",
315
+ type: "button",
316
+ children: /* @__PURE__ */ jsx(Icon, { name: "close", size: 12 })
317
+ }
318
+ ),
319
+ /* @__PURE__ */ jsx("div", { className: "aark-modal-body", children: content })
320
+ ]
321
+ }
322
+ );
323
+ }
324
+ return null;
325
+ };
326
+ return createPortal(
327
+ /* @__PURE__ */ jsx(
328
+ "div",
329
+ {
330
+ className: `aark-modal-overlay ${overlayClassName}`.trim(),
331
+ onClick: handleOverlayClick,
332
+ "aria-hidden": "true",
333
+ style: {
334
+ position: "fixed",
335
+ inset: 0,
336
+ zIndex: 9999,
337
+ background: "var(--aark-modal-overlay-bg)",
338
+ backdropFilter: "blur(2px)",
339
+ animation: "fade-in var(--aark-anim)",
340
+ display: "flex",
341
+ alignItems: position.includes("center") ? "center" : position.includes("top") ? "flex-start" : "flex-end",
342
+ justifyContent: position.includes("center") ? "center" : position.includes("right") ? "flex-end" : "flex-start",
343
+ padding: "1rem"
344
+ },
345
+ children: renderContent()
346
+ }
347
+ ),
348
+ modalContainer
349
+ );
350
+ };
351
+ const typeIcons = {
352
+ success: "✓",
353
+ error: "✕",
354
+ warning: "⚠",
355
+ info: "ⓘ",
356
+ question: "?"
357
+ };
358
+ const typeColors = {
359
+ success: "#4ade80",
360
+ error: "#ef4444",
361
+ warning: "#f59e0b",
362
+ info: "#3b82f6",
363
+ question: "#8b5cf6"
364
+ };
365
+ const StandardNotification = ({ props, onClose }) => {
366
+ const {
367
+ title,
368
+ text,
369
+ type = "info",
370
+ icon,
371
+ html,
372
+ timer = 5e3,
373
+ showCloseButton = true,
374
+ clickToClose = true,
375
+ width = "300px",
376
+ fullWidth = false,
377
+ padding = "1rem",
378
+ background = "#ffffff",
379
+ customClass = {}
380
+ } = props;
381
+ useEffect(() => {
382
+ if (timer && timer > 0) {
383
+ const timeoutId = setTimeout(onClose, timer);
384
+ return () => clearTimeout(timeoutId);
385
+ }
386
+ }, [timer, onClose]);
387
+ const handleClick = () => {
388
+ if (clickToClose) {
389
+ onClose();
390
+ }
391
+ };
392
+ const iconElement = useMemo(() => {
393
+ if (icon) {
394
+ return typeof icon === "string" ? /* @__PURE__ */ jsx("span", { children: icon }) : icon;
395
+ }
396
+ return /* @__PURE__ */ jsx("span", { style: { color: typeColors[type] }, children: typeIcons[type] });
397
+ }, [icon, type]);
398
+ const notificationStyle = useMemo(() => {
399
+ const baseStyle = {
400
+ padding,
401
+ background,
402
+ borderRadius: "8px",
403
+ boxShadow: "0 4px 12px rgba(0, 0, 0, 0.1)",
404
+ border: `1px solid ${typeColors[type]}`,
405
+ cursor: clickToClose ? "pointer" : "default",
406
+ position: "relative",
407
+ overflow: "hidden"
408
+ };
409
+ if (fullWidth) {
410
+ baseStyle.width = "calc(100vw - 40px)";
411
+ baseStyle.maxWidth = "calc(100vw - 40px)";
412
+ } else {
413
+ baseStyle.width = typeof width === "number" ? `${width}px` : width;
414
+ }
415
+ return baseStyle;
416
+ }, [width, fullWidth, padding, background, type, clickToClose]);
417
+ return /* @__PURE__ */ jsxs(
418
+ "div",
419
+ {
420
+ className: `aark-standard-notification ${customClass.popup || ""}`,
421
+ style: notificationStyle,
422
+ onClick: handleClick,
423
+ children: [
424
+ timer && timer > 0 && /* @__PURE__ */ jsx(
425
+ "div",
426
+ {
427
+ style: {
428
+ position: "absolute",
429
+ bottom: 0,
430
+ left: 0,
431
+ height: "3px",
432
+ background: typeColors[type],
433
+ animation: `aark-notification-progress ${timer}ms linear forwards`,
434
+ transformOrigin: "left"
435
+ }
436
+ }
437
+ ),
438
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "flex-start", gap: "0.75rem" }, children: [
439
+ iconElement && /* @__PURE__ */ jsx("div", { className: `aark-notification-icon ${customClass.icon || ""}`, style: { fontSize: "1.25rem", flexShrink: 0, marginTop: "0.125rem" }, children: iconElement }),
440
+ /* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
441
+ title && /* @__PURE__ */ jsx("div", { className: `aark-notification-header ${customClass.header || ""}`, children: /* @__PURE__ */ jsx("h4", { className: `aark-notification-title ${customClass.title || ""}`, style: { margin: 0, fontSize: "0.875rem", fontWeight: "600", color: "#1f2937" }, children: title }) }),
442
+ /* @__PURE__ */ jsx("div", { className: `aark-notification-content ${customClass.content || ""}`, style: { marginTop: title ? "0.25rem" : 0 }, children: html ? /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: typeof html === "string" ? html : "" } }) : text ? /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "0.75rem", color: "#6b7280", lineHeight: "1.4" }, children: text }) : null })
443
+ ] }),
444
+ showCloseButton && /* @__PURE__ */ jsx(
445
+ "button",
446
+ {
447
+ onClick: (e) => {
448
+ e.stopPropagation();
449
+ onClose();
450
+ },
451
+ className: `aark-notification-close ${customClass.closeButton || ""}`,
452
+ style: {
453
+ background: "none",
454
+ border: "none",
455
+ fontSize: "1rem",
456
+ color: "#9ca3af",
457
+ cursor: "pointer",
458
+ padding: 0,
459
+ lineHeight: 1,
460
+ flexShrink: 0
461
+ },
462
+ "aria-label": "Close notification",
463
+ children: "×"
464
+ }
465
+ )
466
+ ] }),
467
+ /* @__PURE__ */ jsx("style", { children: `
468
+ @keyframes aark-notification-progress {
469
+ from {
470
+ transform: scaleX(1);
471
+ }
472
+ to {
473
+ transform: scaleX(0);
474
+ }
475
+ }
476
+ ` })
477
+ ]
478
+ }
479
+ );
480
+ };
481
+ const Notification = ({ config, onClose }) => {
482
+ const { content, props, options = {} } = config;
483
+ const {
484
+ position = "top-right",
485
+ showCloseIcon = true,
486
+ autoCloseTime = 5e3,
487
+ className = "",
488
+ preventEscClose = false
489
+ } = options;
490
+ useEffect(() => {
491
+ if (autoCloseTime && !props) {
492
+ const timer = setTimeout(onClose, autoCloseTime);
493
+ return () => clearTimeout(timer);
494
+ }
495
+ }, [autoCloseTime, onClose, props]);
496
+ useEffect(() => {
497
+ const handleKeyDown = (event) => {
498
+ if (event.key === "Escape" && !preventEscClose) {
499
+ onClose();
500
+ }
501
+ };
502
+ if (!preventEscClose) {
503
+ document.addEventListener("keydown", handleKeyDown);
504
+ return () => document.removeEventListener("keydown", handleKeyDown);
505
+ }
506
+ }, [onClose, preventEscClose]);
507
+ const handleCloseClick = useCallback(
508
+ (event) => {
509
+ event.stopPropagation();
510
+ onClose();
511
+ },
512
+ [onClose]
513
+ );
514
+ const contentClasses = `aark-notification-container ${position} ${className}`.trim();
515
+ const modalContainer = getModalRoot();
516
+ const getPositionStyles = () => {
517
+ const baseStyles = {
518
+ position: "fixed",
519
+ zIndex: 1e4,
520
+ margin: "1rem"
521
+ };
522
+ switch (position) {
523
+ case "top-left":
524
+ return { ...baseStyles, top: 0, left: 0 };
525
+ case "top-center":
526
+ return { ...baseStyles, top: 0, left: "50%", transform: "translateX(-50%)" };
527
+ case "top-right":
528
+ return { ...baseStyles, top: 0, right: 0 };
529
+ case "bottom-left":
530
+ return { ...baseStyles, bottom: 0, left: 0 };
531
+ case "bottom-center":
532
+ return { ...baseStyles, bottom: 0, left: "50%", transform: "translateX(-50%)" };
533
+ case "bottom-right":
534
+ return { ...baseStyles, bottom: 0, right: 0 };
535
+ default:
536
+ return { ...baseStyles, top: 0, right: 0 };
537
+ }
538
+ };
539
+ const renderContent = () => {
540
+ if (props) {
541
+ return /* @__PURE__ */ jsx("div", { className: "aark-notification-wrapper", children: /* @__PURE__ */ jsx(StandardNotification, { props, onClose }) });
542
+ } else if (content) {
543
+ return /* @__PURE__ */ jsxs(
544
+ "div",
545
+ {
546
+ className: contentClasses,
547
+ role: "alert",
548
+ "aria-live": "polite",
549
+ "aria-labelledby": "aark-notification-content",
550
+ children: [
551
+ showCloseIcon && /* @__PURE__ */ jsx(
552
+ "button",
553
+ {
554
+ onClick: handleCloseClick,
555
+ className: "aark-notification-close",
556
+ "aria-label": "Close notification",
557
+ type: "button",
558
+ children: "×"
559
+ }
560
+ ),
561
+ /* @__PURE__ */ jsx("div", { id: "aark-notification-body", className: "aark-notification-body", children: content })
562
+ ]
563
+ }
564
+ );
565
+ }
566
+ return null;
567
+ };
568
+ return createPortal(
569
+ /* @__PURE__ */ jsx("div", { style: getPositionStyles(), children: renderContent() }),
570
+ modalContainer
571
+ );
572
+ };
573
+ const ModalProvider = () => {
574
+ const { isOpen: isOpen2, config, close: close2 } = useModal();
575
+ if (!isOpen2 || !config) {
576
+ return null;
577
+ }
578
+ if (config.mode === "modal") {
579
+ return /* @__PURE__ */ jsx(Modal, { config, onClose: close2 });
580
+ }
581
+ if (config.mode === "notification") {
582
+ return /* @__PURE__ */ jsx(Notification, { config, onClose: close2 });
583
+ }
584
+ return null;
585
+ };
586
+ const listeners = /* @__PURE__ */ new Set();
587
+ let currentConfig = null;
588
+ let root = null;
589
+ function init() {
590
+ if (root) return;
591
+ const container = getModalRoot();
592
+ root = createRoot(container);
593
+ root.render(createElement(ModalProvider));
594
+ }
595
+ function subscribe(listener) {
596
+ listeners.add(listener);
597
+ return () => listeners.delete(listener);
598
+ }
599
+ function emit(type, config) {
600
+ const event = { type, config };
601
+ listeners.forEach((listener) => listener(event));
602
+ }
603
+ function fireModal(contentOrProps, options) {
604
+ init();
605
+ let content;
606
+ let props;
607
+ if (contentOrProps && typeof contentOrProps === "object" && !("$$typeof" in contentOrProps) && !Array.isArray(contentOrProps)) {
608
+ props = contentOrProps;
609
+ content = void 0;
610
+ } else {
611
+ content = contentOrProps;
612
+ props = void 0;
613
+ }
614
+ const config = {
615
+ content,
616
+ props,
617
+ mode: "modal",
618
+ options: Object.assign(
619
+ {
620
+ position: "center",
621
+ showCloseIcon: true,
622
+ preventEscClose: false,
623
+ preventOverlayClose: false
624
+ },
625
+ options
626
+ )
627
+ };
628
+ currentConfig = config;
629
+ emit("open", config);
630
+ }
631
+ function fireNotification(contentOrProps, options) {
632
+ init();
633
+ let content;
634
+ let props;
635
+ if (contentOrProps && typeof contentOrProps === "object" && !("$$typeof" in contentOrProps) && !Array.isArray(contentOrProps)) {
636
+ props = contentOrProps;
637
+ content = void 0;
638
+ } else {
639
+ content = contentOrProps;
640
+ props = void 0;
641
+ }
642
+ const config = {
643
+ content,
644
+ props,
645
+ mode: "notification",
646
+ options: Object.assign(
647
+ {
648
+ position: "top-right",
649
+ showCloseIcon: true,
650
+ autoCloseTime: 5e3,
651
+ preventEscClose: false
652
+ },
653
+ options
654
+ )
655
+ };
656
+ currentConfig = config;
657
+ emit("open", config);
658
+ }
659
+ function fire(contentOrProps, options) {
660
+ fireModal(contentOrProps, options);
661
+ }
662
+ function close() {
663
+ if (currentConfig) {
664
+ emit("beforeClose", currentConfig);
665
+ currentConfig = null;
666
+ emit("close");
667
+ }
668
+ }
669
+ function isOpen() {
670
+ return currentConfig !== null;
671
+ }
672
+ function getCurrentConfig() {
673
+ return currentConfig;
674
+ }
675
+ function closeAll() {
676
+ close();
677
+ }
678
+ function cleanup() {
679
+ if (root) {
680
+ root.unmount();
681
+ root = null;
682
+ }
683
+ cleanupModalRoot();
684
+ }
685
+ const modalManager = {
686
+ subscribe,
687
+ fire,
688
+ fireModal,
689
+ fireNotification,
690
+ close,
691
+ isOpen,
692
+ getCurrentConfig,
693
+ closeAll,
694
+ cleanup
695
+ };
696
+ function setAarkModalTheme(theme) {
697
+ const root2 = document.documentElement;
698
+ if (theme.overlayBackground) {
699
+ root2.style.setProperty("--aark-modal-overlay-bg", theme.overlayBackground);
700
+ }
701
+ if (theme.overlayBlur) {
702
+ root2.style.setProperty("--aark-modal-overlay-blur", theme.overlayBlur);
703
+ }
704
+ if (theme.modalBackground) {
705
+ root2.style.setProperty("--aark-modal-bg", theme.modalBackground);
706
+ }
707
+ if (theme.modalBorderRadius) {
708
+ root2.style.setProperty(
709
+ "--aark-modal-border-radius",
710
+ theme.modalBorderRadius
711
+ );
712
+ }
713
+ if (theme.modalShadow) {
714
+ root2.style.setProperty("--aark-modal-shadow", theme.modalShadow);
715
+ }
716
+ if (theme.modalPadding) {
717
+ root2.style.setProperty("--aark-modal-padding", theme.modalPadding);
718
+ }
719
+ if (theme.modalZIndex) {
720
+ root2.style.setProperty(
721
+ "--aark-modal-z-index",
722
+ theme.modalZIndex.toString()
723
+ );
724
+ }
725
+ if (theme.modalContentZIndex) {
726
+ root2.style.setProperty(
727
+ "--aark-modal-content-z-index",
728
+ theme.modalContentZIndex.toString()
729
+ );
730
+ }
731
+ if (theme.closeButtonColor) {
732
+ root2.style.setProperty("--aark-modal-close-color", theme.closeButtonColor);
733
+ }
734
+ if (theme.closeButtonHoverBackground) {
735
+ root2.style.setProperty(
736
+ "--aark-modal-close-hover-bg",
737
+ theme.closeButtonHoverBackground
738
+ );
739
+ }
740
+ if (theme.closeButtonHoverColor) {
741
+ root2.style.setProperty(
742
+ "--aark-modal-close-hover-color",
743
+ theme.closeButtonHoverColor
744
+ );
745
+ }
746
+ if (theme.closeButtonFocusOutline) {
747
+ root2.style.setProperty(
748
+ "--aark-modal-close-focus-outline",
749
+ theme.closeButtonFocusOutline
750
+ );
751
+ }
752
+ if (theme.animationDuration) {
753
+ root2.style.setProperty(
754
+ "--aark-modal-animation-duration",
755
+ theme.animationDuration
756
+ );
757
+ }
758
+ if (theme.fadeDuration) {
759
+ root2.style.setProperty("--aark-modal-fade-duration", theme.fadeDuration);
760
+ }
761
+ if (theme.customOverlayBackground) {
762
+ root2.style.setProperty(
763
+ "--aark-custom-overlay-bg",
764
+ theme.customOverlayBackground
765
+ );
766
+ }
767
+ if (theme.customOverlayBlur) {
768
+ root2.style.setProperty(
769
+ "--aark-custom-overlay-blur",
770
+ theme.customOverlayBlur
771
+ );
772
+ }
773
+ if (theme.customModalGradientStart) {
774
+ root2.style.setProperty(
775
+ "--aark-custom-modal-gradient-start",
776
+ theme.customModalGradientStart
777
+ );
778
+ }
779
+ if (theme.customModalGradientEnd) {
780
+ root2.style.setProperty(
781
+ "--aark-custom-modal-gradient-end",
782
+ theme.customModalGradientEnd
783
+ );
784
+ }
785
+ if (theme.customModalTextColor) {
786
+ root2.style.setProperty(
787
+ "--aark-custom-modal-text-color",
788
+ theme.customModalTextColor
789
+ );
790
+ }
791
+ if (theme.customModalShadow) {
792
+ root2.style.setProperty(
793
+ "--aark-custom-modal-shadow",
794
+ theme.customModalShadow
795
+ );
796
+ }
797
+ if (theme.customModalCloseColor) {
798
+ root2.style.setProperty(
799
+ "--aark-custom-modal-close-color",
800
+ theme.customModalCloseColor
801
+ );
802
+ }
803
+ if (theme.customModalCloseHoverBackground) {
804
+ root2.style.setProperty(
805
+ "--aark-custom-modal-close-hover-bg",
806
+ theme.customModalCloseHoverBackground
807
+ );
808
+ }
809
+ if (theme.customModalCloseHoverColor) {
810
+ root2.style.setProperty(
811
+ "--aark-custom-modal-close-hover-color",
812
+ theme.customModalCloseHoverColor
813
+ );
814
+ }
815
+ }
816
+ function resetAarkModalTheme() {
817
+ const root2 = document.documentElement;
818
+ const properties = [
819
+ "--aark-modal-overlay-bg",
820
+ "--aark-modal-overlay-blur",
821
+ "--aark-modal-bg",
822
+ "--aark-modal-border-radius",
823
+ "--aark-modal-shadow",
824
+ "--aark-modal-padding",
825
+ "--aark-modal-z-index",
826
+ "--aark-modal-content-z-index",
827
+ "--aark-modal-close-color",
828
+ "--aark-modal-close-hover-bg",
829
+ "--aark-modal-close-hover-color",
830
+ "--aark-modal-close-focus-outline",
831
+ "--aark-modal-animation-duration",
832
+ "--aark-modal-fade-duration",
833
+ "--aark-custom-overlay-bg",
834
+ "--aark-custom-overlay-blur",
835
+ "--aark-custom-modal-gradient-start",
836
+ "--aark-custom-modal-gradient-end",
837
+ "--aark-custom-modal-text-color",
838
+ "--aark-custom-modal-shadow",
839
+ "--aark-custom-modal-close-color",
840
+ "--aark-custom-modal-close-hover-bg",
841
+ "--aark-custom-modal-close-hover-color"
842
+ ];
843
+ properties.forEach((property) => {
844
+ root2.style.removeProperty(property);
845
+ });
846
+ }
847
+ function getAarkModalTheme() {
848
+ const root2 = document.documentElement;
849
+ const computedStyle = getComputedStyle(root2);
850
+ return {
851
+ overlayBackground: computedStyle.getPropertyValue("--aark-modal-overlay-bg").trim(),
852
+ overlayBlur: computedStyle.getPropertyValue("--aark-modal-overlay-blur").trim(),
853
+ modalBackground: computedStyle.getPropertyValue("--aark-modal-bg").trim(),
854
+ modalBorderRadius: computedStyle.getPropertyValue("--aark-modal-border-radius").trim(),
855
+ modalShadow: computedStyle.getPropertyValue("--aark-modal-shadow").trim(),
856
+ modalPadding: computedStyle.getPropertyValue("--aark-modal-padding").trim(),
857
+ modalZIndex: parseInt(computedStyle.getPropertyValue("--aark-modal-z-index").trim()) || void 0,
858
+ modalContentZIndex: parseInt(
859
+ computedStyle.getPropertyValue("--aark-modal-content-z-index").trim()
860
+ ) || void 0,
861
+ closeButtonColor: computedStyle.getPropertyValue("--aark-modal-close-color").trim(),
862
+ closeButtonHoverBackground: computedStyle.getPropertyValue("--aark-modal-close-hover-bg").trim(),
863
+ closeButtonHoverColor: computedStyle.getPropertyValue("--aark-modal-close-hover-color").trim(),
864
+ closeButtonFocusOutline: computedStyle.getPropertyValue("--aark-modal-close-focus-outline").trim(),
865
+ animationDuration: computedStyle.getPropertyValue("--aark-modal-animation-duration").trim(),
866
+ fadeDuration: computedStyle.getPropertyValue("--aark-modal-fade-duration").trim(),
867
+ customOverlayBackground: computedStyle.getPropertyValue("--aark-custom-overlay-bg").trim(),
868
+ customOverlayBlur: computedStyle.getPropertyValue("--aark-custom-overlay-blur").trim(),
869
+ customModalGradientStart: computedStyle.getPropertyValue("--aark-custom-modal-gradient-start").trim(),
870
+ customModalGradientEnd: computedStyle.getPropertyValue("--aark-custom-modal-gradient-end").trim(),
871
+ customModalTextColor: computedStyle.getPropertyValue("--aark-custom-modal-text-color").trim(),
872
+ customModalShadow: computedStyle.getPropertyValue("--aark-custom-modal-shadow").trim(),
873
+ customModalCloseColor: computedStyle.getPropertyValue("--aark-custom-modal-close-color").trim(),
874
+ customModalCloseHoverBackground: computedStyle.getPropertyValue("--aark-custom-modal-close-hover-bg").trim(),
875
+ customModalCloseHoverColor: computedStyle.getPropertyValue("--aark-custom-modal-close-hover-color").trim()
876
+ };
877
+ }
878
+ const aark = {
879
+ fire: (contentOrProps, options) => modalManager.fire(contentOrProps, options),
880
+ modal: (contentOrProps, options) => modalManager.fireModal(contentOrProps, options),
881
+ notification: (contentOrProps, options) => modalManager.fireNotification(contentOrProps, options),
882
+ close: () => modalManager.close(),
883
+ isOpen: () => modalManager.isOpen(),
884
+ closeAll: () => modalManager.closeAll(),
885
+ setTheme: (theme) => setAarkModalTheme(theme),
886
+ resetTheme: () => resetAarkModalTheme(),
887
+ getTheme: () => getAarkModalTheme()
888
+ };
889
+ export {
890
+ Modal,
891
+ ModalProvider,
892
+ Notification,
893
+ aark,
894
+ getAarkModalTheme,
895
+ resetAarkModalTheme,
896
+ setAarkModalTheme,
897
+ useModal
898
+ };