kitzo 2.1.29 → 2.1.30

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,676 @@
1
+ import React, { useRef, useLayoutEffect, useState, useEffect } from 'react';
2
+
3
+ function _arrayLikeToArray(r, a) {
4
+ (null == a || a > r.length) && (a = r.length);
5
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
6
+ return n;
7
+ }
8
+ function _arrayWithHoles(r) {
9
+ if (Array.isArray(r)) return r;
10
+ }
11
+ function _arrayWithoutHoles(r) {
12
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
13
+ }
14
+ function _defineProperty(e, r, t) {
15
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
16
+ value: t,
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true
20
+ }) : e[r] = t, e;
21
+ }
22
+ function _iterableToArray(r) {
23
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
24
+ }
25
+ function _iterableToArrayLimit(r, l) {
26
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
27
+ if (null != t) {
28
+ var e,
29
+ n,
30
+ i,
31
+ u,
32
+ a = [],
33
+ f = true,
34
+ o = false;
35
+ try {
36
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
37
+ } catch (r) {
38
+ o = true, n = r;
39
+ } finally {
40
+ try {
41
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
42
+ } finally {
43
+ if (o) throw n;
44
+ }
45
+ }
46
+ return a;
47
+ }
48
+ }
49
+ function _nonIterableRest() {
50
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
51
+ }
52
+ function _nonIterableSpread() {
53
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
54
+ }
55
+ function ownKeys(e, r) {
56
+ var t = Object.keys(e);
57
+ if (Object.getOwnPropertySymbols) {
58
+ var o = Object.getOwnPropertySymbols(e);
59
+ r && (o = o.filter(function (r) {
60
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
61
+ })), t.push.apply(t, o);
62
+ }
63
+ return t;
64
+ }
65
+ function _objectSpread2(e) {
66
+ for (var r = 1; r < arguments.length; r++) {
67
+ var t = null != arguments[r] ? arguments[r] : {};
68
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
69
+ _defineProperty(e, r, t[r]);
70
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
71
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
72
+ });
73
+ }
74
+ return e;
75
+ }
76
+ function _slicedToArray(r, e) {
77
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
78
+ }
79
+ function _toConsumableArray(r) {
80
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
81
+ }
82
+ function _toPrimitive(t, r) {
83
+ if ("object" != typeof t || !t) return t;
84
+ var e = t[Symbol.toPrimitive];
85
+ if (void 0 !== e) {
86
+ var i = e.call(t, r);
87
+ if ("object" != typeof i) return i;
88
+ throw new TypeError("@@toPrimitive must return a primitive value.");
89
+ }
90
+ return ("string" === r ? String : Number)(t);
91
+ }
92
+ function _toPropertyKey(t) {
93
+ var i = _toPrimitive(t, "string");
94
+ return "symbol" == typeof i ? i : i + "";
95
+ }
96
+ function _unsupportedIterableToArray(r, a) {
97
+ if (r) {
98
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
99
+ var t = {}.toString.call(r).slice(8, -1);
100
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
101
+ }
102
+ }
103
+
104
+ var toastStyles = ".toast-content,\n.toast-content-bottom {\n font-size: 0.925rem;\n}\n.toast-content,\n.toast-content-bottom {\n pointer-events: all;\n}\n \n.pre-styled {\n padding-inline: 0.825rem;\n padding-block: 0.625rem;\n display: flex;\n align-items: center;\n gap: 0.5rem;\n background-color: white;\n border-radius: 0.5525rem;\n box-shadow: 0 2px 8px -3px rgba(0, 0, 0, 0.3);\n}\n\n.toast-content {\n animation: slide-in 230ms forwards;\n}\n.toast-content.exit {\n animation: slide-out 110ms forwards;\n}\n\n.toast-content-bottom {\n animation: bottom-slide-in 230ms forwards;\n}\n.toast-content-bottom.exit {\n animation: bottom-slide-out 110ms forwards;\n}\n\n@keyframes slide-in {\n from {\n opacity: 0;\n translate: 0 -100%;\n scale: 0.7;\n }\n to {\n opacity: 1;\n translate: 0 0;\n scale: 1;\n }\n}\n\n@keyframes slide-out {\n from {\n opacity: 1;\n translate: 0 0;\n scale: 1;\n }\n to {\n opacity: 0;\n translate: 0 -100%;\n scale: 0.7;\n }\n}\n\n@keyframes bottom-slide-in {\n from {\n opacity: 0;\n translate: 0 100%;\n scale: 0.7;\n }\n to {\n opacity: 1;\n translate: 0 0;\n scale: 1;\n }\n}\n\n@keyframes bottom-slide-out {\n from {\n opacity: 1;\n translate: 0 0;\n scale: 1;\n }\n to {\n opacity: 0;\n translate: 0 100%;\n scale: 0.7;\n }\n}\n\n.svg-container {\n display: grid;\n place-items: center;\n border-radius: 10rem;\n background-color: #61d345;\n color: white;\n height: 20px;\n width: 20px;\n position: relative;\n overflow: hidden;\n\n scale: 1.1;\n animation: svg-container-animation 400ms ease-in-out forwards;\n\n svg {\n width: 14px;\n height: 14px;\n stroke-width: 4px;\n display: inline-block;\n }\n}\n\n.svg-container.success {\n background-color: #61d345;\n}\n.svg-container.error {\n background-color: #ff4b4b;\n\n svg {\n scale: 0;\n animation: error-svg-zoom-in 170ms 130ms forwards;\n }\n}\n\n.svg-container.success::before {\n content: '';\n position: absolute;\n inset: 0;\n z-index: 5;\n border-radius: 10rem;\n background-color: #61d345;\n animation: success-container-before-animation 250ms 150ms forwards;\n}\n\n@keyframes svg-container-animation {\n 0% {\n scale: 1;\n }\n 50% {\n scale: 1.15;\n }\n 100% {\n scale: 1;\n }\n}\n\n@keyframes success-container-before-animation {\n from {\n translate: 0 0;\n }\n to {\n translate: 100% -50%;\n }\n}\n\n@keyframes error-svg-zoom-in {\n from {\n scale: 0;\n }\n to {\n scale: 1;\n }\n}\n\n.promise-svg-container {\n width: 20px;\n height: 20px;\n display: grid;\n place-items: center;\n color: #474747;\n\n svg {\n width: 14px;\n height: 14px;\n stroke-width: 3px;\n display: inline-block;\n animation: rotate-infinity 1000ms infinite linear;\n }\n}\n\n@keyframes rotate-infinity {\n to {\n rotate: 360deg;\n }\n}\n";
105
+ var listeners = new Set();
106
+ function addToast(toast) {
107
+ listeners.forEach(function (callback) {
108
+ callback(toast);
109
+ });
110
+ }
111
+ function subscribe(callback) {
112
+ if (!document.getElementById('kitzo-react-toast-styles')) {
113
+ var styleTag = document.createElement('style');
114
+ styleTag.id = 'kitzo-react-toast-styles';
115
+ styleTag.textContent = toastStyles;
116
+ document.head.appendChild(styleTag);
117
+ }
118
+ listeners.add(callback);
119
+ return function () {
120
+ return listeners["delete"](callback);
121
+ };
122
+ }
123
+ function toast() {
124
+ var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Toast message';
125
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
126
+ var id = Date.now();
127
+ options = Object.assign({
128
+ duration: 2800,
129
+ id: id,
130
+ style: {},
131
+ showIcon: false
132
+ }, options);
133
+ addToast({
134
+ type: 'success',
135
+ text: text,
136
+ options: options
137
+ });
138
+ }
139
+ toast.success = function () {
140
+ var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Toast success';
141
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
142
+ var id = Date.now();
143
+ options = Object.assign({
144
+ duration: 2800,
145
+ id: id,
146
+ style: {},
147
+ showIcon: true
148
+ }, options);
149
+ addToast({
150
+ type: 'success',
151
+ text: text,
152
+ options: options
153
+ });
154
+ };
155
+ toast.error = function () {
156
+ var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Toast denied';
157
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
158
+ var id = Date.now();
159
+ options = Object.assign({
160
+ duration: 2800,
161
+ id: id,
162
+ style: {},
163
+ showIcon: true
164
+ }, options);
165
+ addToast({
166
+ type: 'error',
167
+ text: text,
168
+ options: options
169
+ });
170
+ };
171
+ toast.promise = function (callback) {
172
+ var msgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
173
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
174
+ var id = Date.now();
175
+ options = Object.assign({
176
+ duration: 2800,
177
+ id: id,
178
+ style: {},
179
+ showIcon: true
180
+ }, options);
181
+ msgs = Object.assign({
182
+ loading: 'Saving...',
183
+ success: 'Success',
184
+ error: 'Something went wrong'
185
+ }, msgs);
186
+ addToast({
187
+ type: 'loading',
188
+ text: msgs.loading,
189
+ options: _objectSpread2(_objectSpread2({}, options), {}, {
190
+ duration: Infinity,
191
+ id: id
192
+ })
193
+ });
194
+ callback.then(function (res) {
195
+ var successMsg = typeof msgs.success === 'function' ? msgs.success(res) : msgs.success;
196
+ addToast({
197
+ type: 'success',
198
+ text: successMsg,
199
+ options: options
200
+ });
201
+ return res;
202
+ })["catch"](function (err) {
203
+ var normalizedError = err instanceof Error ? err : new Error(String(err));
204
+ var errorMsg = typeof msgs.error === 'function' ? msgs.error(normalizedError) : msgs.error;
205
+ addToast({
206
+ type: 'error',
207
+ text: errorMsg,
208
+ options: options
209
+ });
210
+ return Promise.reject(normalizedError);
211
+ });
212
+ };
213
+ toast.custom = function (render) {
214
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
215
+ var id = Date.now();
216
+ options = Object.assign({
217
+ duration: 3000,
218
+ id: id,
219
+ exitDelay: 50
220
+ }, options);
221
+ addToast({
222
+ type: 'custom',
223
+ render: render,
224
+ options: options
225
+ });
226
+ return id;
227
+ };
228
+ function dismiss(id, exitDelay) {
229
+ addToast({
230
+ type: 'dismiss',
231
+ id: id,
232
+ exitDelay: exitDelay
233
+ });
234
+ }
235
+
236
+ function SuccessSvg() {
237
+ return /*#__PURE__*/React.createElement("div", {
238
+ className: "svg-container success"
239
+ }, /*#__PURE__*/React.createElement("svg", {
240
+ xmlns: "http://www.w3.org/2000/svg",
241
+ width: "24",
242
+ height: "24",
243
+ viewBox: "0 0 24 24",
244
+ fill: "none",
245
+ stroke: "currentColor",
246
+ strokeWidth: "2",
247
+ strokeLinecap: "round",
248
+ strokeLinejoin: "round"
249
+ }, /*#__PURE__*/React.createElement("path", {
250
+ d: "M20 6 9 17l-5-5"
251
+ })));
252
+ }
253
+ function ErrorSvg() {
254
+ return /*#__PURE__*/React.createElement("div", {
255
+ className: "svg-container error"
256
+ }, /*#__PURE__*/React.createElement("svg", {
257
+ xmlns: "http://www.w3.org/2000/svg",
258
+ width: "24",
259
+ height: "24",
260
+ viewBox: "0 0 24 24",
261
+ fill: "none",
262
+ stroke: "currentColor",
263
+ strokeWidth: "2",
264
+ strokeLinecap: "round",
265
+ strokeLinejoin: "round"
266
+ }, /*#__PURE__*/React.createElement("path", {
267
+ d: "M18 6 6 18"
268
+ }), /*#__PURE__*/React.createElement("path", {
269
+ d: "m6 6 12 12"
270
+ })));
271
+ }
272
+ function LoadingSvg() {
273
+ return /*#__PURE__*/React.createElement("div", {
274
+ className: "promise-svg-container"
275
+ }, /*#__PURE__*/React.createElement("svg", {
276
+ xmlns: "http://www.w3.org/2000/svg",
277
+ width: "24",
278
+ height: "24",
279
+ viewBox: "0 0 24 24",
280
+ fill: "none",
281
+ stroke: "currentColor",
282
+ strokeWidth: "2",
283
+ strokeLinecap: "round",
284
+ strokeLinejoin: "round"
285
+ }, /*#__PURE__*/React.createElement("path", {
286
+ d: "M21 12a9 9 0 1 1-6.219-8.56"
287
+ })));
288
+ }
289
+
290
+ function Toast(_ref) {
291
+ var toast = _ref.toast,
292
+ setToasts = _ref.setToasts,
293
+ position = _ref.position,
294
+ gap = _ref.gap;
295
+ var id = toast.id,
296
+ leaving = toast.leaving,
297
+ offset = toast.offset,
298
+ text = toast.text,
299
+ type = toast.type,
300
+ options = toast.options;
301
+ var style = options.style,
302
+ showIcon = options.showIcon;
303
+ var ref = useRef(null);
304
+ useLayoutEffect(function () {
305
+ if (!ref.current) return;
306
+ var height = ref.current.getBoundingClientRect().height;
307
+ var totalHeight = height + gap;
308
+ setToasts(function (prev) {
309
+ return prev.map(function (t) {
310
+ return t.id === id ? _objectSpread2(_objectSpread2({}, t), {}, {
311
+ height: totalHeight
312
+ }) : t;
313
+ });
314
+ });
315
+ }, []);
316
+ var transformY = position.includes('bottom') ? "translateY(-".concat(offset || 0, "px)") : "translateY(".concat(offset || 0, "px)");
317
+ function renderCustomContent() {
318
+ var render = toast.render;
319
+ if (typeof render === 'function') {
320
+ return render(function () {
321
+ return dismiss(toast.id, toast.options.exitDelay);
322
+ });
323
+ }
324
+ if (typeof render === 'string') {
325
+ return /*#__PURE__*/React.createElement("span", null, render);
326
+ }
327
+ return render;
328
+ }
329
+ return /*#__PURE__*/React.createElement("div", {
330
+ ref: ref,
331
+ style: _objectSpread2({
332
+ maxHeight: 'fit-content',
333
+ transform: transformY
334
+ }, getToastPosition(position))
335
+ }, /*#__PURE__*/React.createElement("div", {
336
+ className: "toast-content".concat(position.includes('bottom') ? '-bottom' : '', " ").concat(leaving ? 'exit' : '')
337
+ }, type === 'custom' ? renderCustomContent() : /*#__PURE__*/React.createElement("div", {
338
+ style: _objectSpread2({}, style),
339
+ className: "pre-styled"
340
+ }, showIcon && /*#__PURE__*/React.createElement(React.Fragment, null, type === 'loading' && /*#__PURE__*/React.createElement(LoadingSvg, null), type === 'success' && /*#__PURE__*/React.createElement(SuccessSvg, null), type === 'error' && /*#__PURE__*/React.createElement(ErrorSvg, null)), /*#__PURE__*/React.createElement("span", null, text))));
341
+ }
342
+ function getToastPosition(position) {
343
+ var isLeft = position.includes('left');
344
+ var isRight = position.includes('right');
345
+ var styles = {
346
+ position: 'absolute',
347
+ width: '100%',
348
+ pointerEvents: 'none',
349
+ transition: 'transform 230ms',
350
+ display: 'flex'
351
+ };
352
+ if (position.includes('top')) {
353
+ styles.top = '0';
354
+ styles.justifyContent = isLeft ? 'flex-start' : isRight ? 'flex-end' : 'center';
355
+ }
356
+ if (position.includes('bottom')) {
357
+ styles.bottom = '0';
358
+ styles.justifyContent = isLeft ? 'flex-start' : isRight ? 'flex-end' : 'center';
359
+ }
360
+ return styles;
361
+ }
362
+
363
+ function ToastContainer(props) {
364
+ props = Object.assign({
365
+ position: 'top-center',
366
+ gap: 8
367
+ }, props);
368
+ var _props = props,
369
+ gap = _props.gap;
370
+ var position = props.position;
371
+ var _useState = useState([]),
372
+ _useState2 = _slicedToArray(_useState, 2),
373
+ toasts = _useState2[0],
374
+ setToasts = _useState2[1];
375
+
376
+ // event listener
377
+ useEffect(function () {
378
+ var unsub = subscribe(function (toast) {
379
+ if (toast.type === 'dismiss') {
380
+ setTimeout(function () {
381
+ setToasts(function (prev) {
382
+ return prev.map(function (t) {
383
+ return t.options.id === toast.id ? _objectSpread2(_objectSpread2({}, t), {}, {
384
+ leaving: true
385
+ }) : t;
386
+ });
387
+ });
388
+ }, Math.max(0, Number(toast.exitDelay)));
389
+ setTimeout(function () {
390
+ setToasts(function (prev) {
391
+ return prev.filter(function (t) {
392
+ return t.options.id !== toast.id;
393
+ });
394
+ });
395
+ }, Math.max(0, Number(toast.exitDelay) + 300));
396
+ return;
397
+ }
398
+ var duration = toast.options.duration;
399
+ var id = toast.options.id;
400
+ setToasts(function (prev) {
401
+ var exists = prev.some(function (t) {
402
+ return t.options.id === id;
403
+ });
404
+ if (exists) {
405
+ return prev.map(function (t) {
406
+ return t.options.id === id ? _objectSpread2(_objectSpread2({}, t), toast) : t;
407
+ });
408
+ }
409
+ return [_objectSpread2(_objectSpread2({
410
+ id: id
411
+ }, toast), {}, {
412
+ offset: 0,
413
+ height: 0,
414
+ leaving: false
415
+ })].concat(_toConsumableArray(prev));
416
+ });
417
+ if (toast.type !== 'loading' && isFinite(duration)) {
418
+ setTimeout(function () {
419
+ setToasts(function (prev) {
420
+ return prev.map(function (t) {
421
+ return t.options.id === id ? _objectSpread2(_objectSpread2({}, t), {}, {
422
+ leaving: true
423
+ }) : t;
424
+ });
425
+ });
426
+ }, Math.max(0, duration - 300));
427
+ setTimeout(function () {
428
+ setToasts(function (prev) {
429
+ return prev.filter(function (t) {
430
+ return t.options.id !== id;
431
+ });
432
+ });
433
+ }, duration);
434
+ }
435
+ });
436
+ return function () {
437
+ return unsub();
438
+ };
439
+ }, []);
440
+
441
+ // measue height and offset for each toast
442
+ useLayoutEffect(function () {
443
+ var grouped = toasts.reduce(function (acc, t) {
444
+ var pos = t.options.position || position || 'top-center';
445
+ (acc[pos] || (acc[pos] = [])).push(t);
446
+ return acc;
447
+ }, {});
448
+ var hasChanged = false;
449
+ var updated = toasts.map(function (toast) {
450
+ var pos = toast.options.position || position || 'top-center';
451
+ var group = grouped[pos];
452
+ var index = group.findIndex(function (t) {
453
+ return t.id === toast.id;
454
+ });
455
+ var offset = group.slice(0, index).reduce(function (acc, t) {
456
+ return acc + (t.height || 0);
457
+ }, 0);
458
+ if (offset !== toast.offset) {
459
+ hasChanged = true;
460
+ }
461
+ return _objectSpread2(_objectSpread2({}, toast), {}, {
462
+ offset: offset
463
+ });
464
+ });
465
+ if (hasChanged) {
466
+ setToasts(updated);
467
+ }
468
+ }, [toasts]);
469
+ var positions = ['top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right'];
470
+ return /*#__PURE__*/React.createElement("div", {
471
+ style: {
472
+ position: 'fixed',
473
+ inset: 0,
474
+ zIndex: 100000000,
475
+ pointerEvents: 'none',
476
+ fontFamily: 'inherit',
477
+ boxSizing: 'border-box'
478
+ }
479
+ }, positions.map(function (pos) {
480
+ var group = toasts.filter(function (t) {
481
+ return (t.options.position || position || 'top-center') === pos;
482
+ });
483
+ if (!group.length) return null;
484
+ return /*#__PURE__*/React.createElement("div", {
485
+ key: pos,
486
+ style: {
487
+ position: 'absolute',
488
+ inset: 0,
489
+ display: 'grid',
490
+ padding: '1rem'
491
+ }
492
+ }, /*#__PURE__*/React.createElement("div", {
493
+ style: {
494
+ position: 'relative'
495
+ }
496
+ }, group.map(function (toast) {
497
+ return /*#__PURE__*/React.createElement(Toast, {
498
+ key: toast.options.id,
499
+ toast: toast,
500
+ setToasts: setToasts,
501
+ position: pos,
502
+ gap: typeof gap === 'string' ? isNaN(+gap) ? 8 : +gap : gap
503
+ });
504
+ })));
505
+ }));
506
+ }
507
+
508
+ // import './style.css';
509
+ var tooltipStyles = "/* Default styling */\n.kitzo-react-tooltip-root {\n --bg-clr: hsl(0, 0%, 15%);\n --text-clr: hsl(0, 0%, 95%);\n\n @media (prefers-color-scheme: dark) {\n --bg-clr: hsl(0, 0%, 95%);\n --text-clr: hsl(0, 0%, 15%);\n }\n}\n\n.kitzo-react-tooltip-content-default-style {\n font-family:\n inherit,\n system-ui,\n -apple-system,\n BlinkMacSystemFont,\n 'Segoe UI',\n Roboto,\n Oxygen,\n Ubuntu,\n Cantarell,\n 'Open Sans',\n 'Helvetica Neue',\n sans-serif;\n font-size: 0.875rem;\n background-color: var(--bg-clr);\n color: var(--text-clr);\n padding-block: 0.25rem;\n padding-inline: 0.5rem;\n border-radius: 0.325rem;\n}\n\n/* Tooltip positioning */\n.kitzo-react-tooltip-wrapper {\n --tooltip-offset: calc(var(--offset) * 1px + 1px);\n}\n/* Top */\n.kitzo-react-tooltip-wrapper.top {\n bottom: 100%;\n padding-block-end: var(--tooltip-offset);\n}\n.kitzo-react-tooltip-wrapper.top {\n left: 50%;\n translate: -50% 0;\n}\n.kitzo-react-tooltip-wrapper.top.start {\n left: 0;\n translate: 0 0;\n}\n.kitzo-react-tooltip-wrapper.top.end {\n right: 0;\n translate: 0 0;\n}\n\n/* Right */\n.kitzo-react-tooltip-wrapper.right {\n left: 100%;\n padding-inline-start: var(--tooltip-offset);\n}\n.kitzo-react-tooltip-wrapper.right {\n top: 50%;\n translate: 0 -50%;\n}\n.kitzo-react-tooltip-wrapper.right.start {\n top: 0;\n translate: 0 0;\n}\n.kitzo-react-tooltip-wrapper.right.end {\n top: 100%;\n translate: 0 -100%;\n}\n\n/* Bottom */\n.kitzo-react-tooltip-wrapper.bottom {\n top: 100%;\n padding-block-start: var(--tooltip-offset);\n}\n.kitzo-react-tooltip-wrapper.bottom {\n left: 50%;\n translate: -50% 0;\n}\n.kitzo-react-tooltip-wrapper.bottom.start {\n left: 0;\n translate: 0 0;\n}\n.kitzo-react-tooltip-wrapper.bottom.end {\n left: 100%;\n translate: -100% 0;\n}\n\n/* Left */\n.kitzo-react-tooltip-wrapper.left {\n right: 100%;\n padding-inline-end: var(--tooltip-offset);\n}\n.kitzo-react-tooltip-wrapper.left {\n top: 50%;\n translate: 0 -50%;\n}\n.kitzo-react-tooltip-wrapper.left.start {\n top: 0;\n translate: 0 0;\n}\n.kitzo-react-tooltip-wrapper.left.end {\n top: 100%;\n translate: 0 -100%;\n}\n\n/* Tooltip transitions */\n.kitzo-react-tooltip-root.animate-tooltip {\n --transition-startDuration: calc(var(--startDuration) * 1ms);\n --transition-endDuration: calc(var(--endDuration) * 1ms);\n --transition-startDelay: calc(var(--startDelay) * 1ms);\n --transition-endDelay: calc(var(--endDelay) * 1ms);\n\n .kitzo-react-tooltip-content {\n transition:\n transform var(--transition-endDuration) var(--transition-endDelay),\n opacity var(--transition-endDuration) var(--transition-endDelay);\n }\n}\n\n.kitzo-react-tooltip-content {\n transform: scale(0.8);\n opacity: 0;\n}\n\n.kitzo-react-tooltip-content.top {\n transform-origin: bottom;\n}\n.kitzo-react-tooltip-content.right {\n transform-origin: left;\n}\n.kitzo-react-tooltip-content.bottom {\n transform-origin: top;\n}\n.kitzo-react-tooltip-content.left {\n transform-origin: right;\n}\n\n.kitzo-react-tooltip-root.animate-tooltip:hover {\n .kitzo-react-tooltip-content {\n transition:\n transform var(--transition-startDuration) var(--transition-startDelay),\n opacity var(--transition-startDuration) var(--transition-startDelay);\n }\n}\n.kitzo-react-tooltip-root:hover {\n .kitzo-react-tooltip-content {\n transform: scale(1);\n opacity: 1;\n }\n}\n\n/* smart hover persistence feature */\n.kitzo-react-tooltip-root {\n .kitzo-react-tooltip-wrapper {\n pointer-events: none;\n }\n}\n.kitzo-react-tooltip-root.smart-hover:hover {\n .kitzo-react-tooltip-wrapper {\n pointer-events: all;\n }\n}\n\n/* Arrow */\n.kitzo-react-tooltip-content.tooltip-arrow {\n --effective-size: calc(var(--arrow-size, 6) * 1px);\n --effective-color: var(--arrow-color, var(--bg-clr));\n\n position: relative;\n}\n.kitzo-react-tooltip-content.tooltip-arrow::before {\n content: '';\n position: absolute;\n z-index: -1;\n border: var(--effective-size) solid transparent;\n}\n.kitzo-react-tooltip-content.tooltip-arrow.top::before {\n left: 50%;\n translate: -50% 0;\n top: calc(100% - 1px);\n border-top: var(--effective-size) solid var(--effective-color);\n}\n.kitzo-react-tooltip-content.tooltip-arrow.right::before {\n top: 50%;\n translate: 0 -50%;\n right: calc(100% - 1px);\n border-right: var(--effective-size) solid var(--effective-color);\n}\n.kitzo-react-tooltip-content.tooltip-arrow.bottom::before {\n left: 50%;\n translate: -50% 0;\n bottom: calc(100% - 1px);\n border-bottom: var(--effective-size) solid var(--effective-color);\n}\n.kitzo-react-tooltip-content.tooltip-arrow.left::before {\n top: 50%;\n translate: 0 -50%;\n left: calc(100% - 1px);\n border-left: var(--effective-size) solid var(--effective-color);\n}";
510
+ (function () {
511
+ if (!document.getElementById('kitzo-react-tooltip-styles')) {
512
+ var styleTag = document.createElement('style');
513
+ styleTag.id = 'kitzo-react-tooltip-styles';
514
+ styleTag.textContent = tooltipStyles;
515
+ document.head.appendChild(styleTag);
516
+ }
517
+ })();
518
+ var allowedPositions = ['top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-start', 'bottom', 'bottom-end', 'left-start', 'left', 'left-end'];
519
+ function getPositionClass() {
520
+ var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
521
+ var allowedPos = allowedPositions.find(function (p) {
522
+ return p === position;
523
+ });
524
+ if (!allowedPos) return 'top';
525
+ if (allowedPos.includes('-')) {
526
+ var _allowedPos$split = allowedPos.split('-'),
527
+ _allowedPos$split2 = _slicedToArray(_allowedPos$split, 2),
528
+ dir = _allowedPos$split2[0],
529
+ state = _allowedPos$split2[1];
530
+ return "".concat(dir, " ").concat(state);
531
+ } else {
532
+ return allowedPos;
533
+ }
534
+ }
535
+ function getAnimationProperties(animation) {
536
+ var _animation$delay, _animation$duration;
537
+ var effectiveStartDelay = animation === null || animation === void 0 ? void 0 : animation.startDelay;
538
+ var effectiveEndDelay = animation === null || animation === void 0 ? void 0 : animation.endDelay;
539
+ var effectiveDelay = (_animation$delay = animation === null || animation === void 0 ? void 0 : animation.delay) !== null && _animation$delay !== void 0 ? _animation$delay : 0;
540
+ var effectiveStartDuration = animation === null || animation === void 0 ? void 0 : animation.startDuration;
541
+ var effectiveEndDuration = animation === null || animation === void 0 ? void 0 : animation.endDuration;
542
+ var effectiveDuration = (_animation$duration = animation === null || animation === void 0 ? void 0 : animation.duration) !== null && _animation$duration !== void 0 ? _animation$duration : 110;
543
+ return {
544
+ startDelay: effectiveStartDelay !== null && effectiveStartDelay !== void 0 ? effectiveStartDelay : effectiveDelay,
545
+ endDelay: effectiveEndDelay !== null && effectiveEndDelay !== void 0 ? effectiveEndDelay : effectiveDelay,
546
+ startDuration: effectiveStartDuration !== null && effectiveStartDuration !== void 0 ? effectiveStartDuration : effectiveDuration,
547
+ endDuration: effectiveEndDuration !== null && effectiveEndDuration !== void 0 ? effectiveEndDuration : effectiveDuration
548
+ };
549
+ }
550
+ function Tooltip(_ref) {
551
+ var content = _ref.content,
552
+ _ref$tooltipOptions = _ref.tooltipOptions,
553
+ tooltipOptions = _ref$tooltipOptions === void 0 ? {} : _ref$tooltipOptions,
554
+ _ref$animation = _ref.animation,
555
+ animation = _ref$animation === void 0 ? true : _ref$animation,
556
+ _ref$style = _ref.style,
557
+ style = _ref$style === void 0 ? {} : _ref$style,
558
+ _ref$isHidden = _ref.isHidden,
559
+ isHidden = _ref$isHidden === void 0 ? false : _ref$isHidden,
560
+ children = _ref.children;
561
+ if (typeof isHidden === 'boolean' && isHidden) return children;
562
+ if (typeof content === 'string') {
563
+ if (!content.trim()) throw new Error('kitzo/react: tooltip content is required');
564
+ } else if (!content) {
565
+ throw new Error('kitzo/react: tooltip content is required');
566
+ }
567
+ // Define options
568
+ var _ref2 = tooltipOptions !== null && tooltipOptions !== void 0 ? tooltipOptions : {},
569
+ _ref2$position = _ref2.position,
570
+ position = _ref2$position === void 0 ? 'top' : _ref2$position,
571
+ _ref2$offset = _ref2.offset,
572
+ offset = _ref2$offset === void 0 ? 8 : _ref2$offset,
573
+ _ref2$hideOnTouch = _ref2.hideOnTouch,
574
+ hideOnTouch = _ref2$hideOnTouch === void 0 ? true : _ref2$hideOnTouch,
575
+ _ref2$arrow = _ref2.arrow,
576
+ arrow = _ref2$arrow === void 0 ? false : _ref2$arrow,
577
+ _ref2$smartHover = _ref2.smartHover,
578
+ smartHover = _ref2$smartHover === void 0 ? true : _ref2$smartHover;
579
+ var finalOptions = {
580
+ position: typeof position === 'string' ? position.trim().toLowerCase() : 'top',
581
+ offset: !isNaN(Number(offset)) ? Number(offset) : 8,
582
+ arrow: typeof arrow === 'boolean' ? arrow : false,
583
+ smartHover: typeof smartHover === 'boolean' ? smartHover : true,
584
+ hideOnTouch: typeof hideOnTouch === 'boolean' ? hideOnTouch : true
585
+ };
586
+
587
+ // Hide on touch device
588
+ var isTouch = window.matchMedia('(pointer: coarse)').matches;
589
+ if (isTouch && finalOptions.hideOnTouch) return children;
590
+ var positionClass = getPositionClass(finalOptions.position);
591
+
592
+ // Define animations
593
+ var animationEnabled = animation ? true : false;
594
+ var animationObj = animation === true ? {} : animation;
595
+ var finalAnimationProperties = getAnimationProperties(animationObj);
596
+ return /*#__PURE__*/React.createElement("div", {
597
+ style: {
598
+ position: 'relative',
599
+ width: 'fit-content',
600
+ '--offset': Math.max(0, finalOptions.offset),
601
+ '--startDuration': Math.max(0, finalAnimationProperties.startDuration),
602
+ '--endDuration': Math.max(0, finalAnimationProperties.endDuration),
603
+ '--startDelay': Math.max(0, finalAnimationProperties.startDelay),
604
+ '--endDelay': Math.max(0, finalAnimationProperties.endDelay),
605
+ '--arrow-color': style === null || style === void 0 ? void 0 : style['--arrow-color'],
606
+ '--arrow-size': style === null || style === void 0 ? void 0 : style['--arrow-size']
607
+ },
608
+ className: "kitzo-react-tooltip-root ".concat(finalOptions.smartHover ? 'smart-hover' : '', " ").concat(animationEnabled ? 'animate-tooltip' : '')
609
+ }, children, /*#__PURE__*/React.createElement("div", {
610
+ style: {
611
+ position: 'absolute',
612
+ whiteSpace: typeof content === 'string' ? 'nowrap' : 'normal'
613
+ },
614
+ tabIndex: -1,
615
+ className: "kitzo-react-tooltip-wrapper ".concat(positionClass)
616
+ }, /*#__PURE__*/React.createElement("div", {
617
+ className: "kitzo-react-tooltip-content ".concat(positionClass, " ").concat(finalOptions.arrow ? 'tooltip-arrow' : '')
618
+ }, typeof content === 'string' || typeof content === 'number' ? /*#__PURE__*/React.createElement("div", {
619
+ className: "kitzo-react-tooltip-content-default-style"
620
+ }, content) : /*#__PURE__*/React.createElement(React.Fragment, null, content))));
621
+ }
622
+
623
+ function useDebounce(value, delay) {
624
+ var _useState = useState(value),
625
+ _useState2 = _slicedToArray(_useState, 2),
626
+ debouncedValue = _useState2[0],
627
+ setDebouncedValue = _useState2[1];
628
+ useEffect(function () {
629
+ var handler = setTimeout(function () {
630
+ setDebouncedValue(value);
631
+ }, delay);
632
+ return function () {
633
+ clearTimeout(handler);
634
+ };
635
+ }, [value, delay]);
636
+ return debouncedValue;
637
+ }
638
+
639
+ function useWindowSize() {
640
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
641
+ var _options$delay = options.delay,
642
+ delay = _options$delay === void 0 ? 50 : _options$delay;
643
+ if (typeof delay !== 'number') throw new Error("Only number is accepted 'useWindowSize' hook configuration: delay");
644
+ var _useState = useState({
645
+ screenWidth: window.innerWidth,
646
+ screenHeight: window.innerHeight
647
+ }),
648
+ _useState2 = _slicedToArray(_useState, 2),
649
+ screenSize = _useState2[0],
650
+ setScreenSize = _useState2[1];
651
+ var timeoutRef = useRef(null);
652
+ useEffect(function () {
653
+ function updateScreenSize() {
654
+ if (timeoutRef.current) {
655
+ clearTimeout(timeoutRef.current);
656
+ }
657
+ timeoutRef.current = setTimeout(function () {
658
+ setScreenSize({
659
+ screenWidth: window.innerWidth,
660
+ screenHeight: window.innerHeight
661
+ });
662
+ }, Math.max(0, Number(delay)));
663
+ }
664
+ if (typeof window !== 'undefined') {
665
+ window.addEventListener('resize', updateScreenSize);
666
+ }
667
+ return function () {
668
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
669
+ window.removeEventListener('resize', updateScreenSize);
670
+ };
671
+ }, [delay]);
672
+ return screenSize;
673
+ }
674
+
675
+ export { ToastContainer, Tooltip, toast, useDebounce, useWindowSize };
676
+ //# sourceMappingURL=index.js.map