@agnos-ui/core 0.9.2 → 0.10.0-next.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.
Files changed (110) hide show
  1. package/{accordion-CoM4efp-.js → accordion-CcirvrjR.js} +10 -15
  2. package/{accordion-cR5JqWJ8.cjs → accordion-yD-czBna.cjs} +10 -15
  3. package/{alert-DtDozJal.cjs → alert-B-jQDQcB.cjs} +1 -1
  4. package/{alert-YIlqdEPO.js → alert-gGz2CDS9.js} +1 -1
  5. package/collapse-BV4kD3j9.js +82 -0
  6. package/collapse-gLiT080Y.cjs +81 -0
  7. package/{common-BToNPUDq.cjs → common-D3QcdJ6S.cjs} +1 -1
  8. package/{common-BqUjUBPy.js → common-DK0ADNTX.js} +1 -1
  9. package/components/accordion/index.cjs +1 -1
  10. package/components/accordion/index.js +1 -1
  11. package/components/alert/index.cjs +1 -1
  12. package/components/alert/index.js +1 -1
  13. package/components/carousel/index.cjs +10 -23
  14. package/components/carousel/index.js +10 -23
  15. package/components/collapse/collapse.d.ts +132 -0
  16. package/components/collapse/index.cjs +5 -0
  17. package/components/collapse/index.d.ts +1 -0
  18. package/components/collapse/index.js +5 -0
  19. package/components/drawer/drawer.d.ts +222 -0
  20. package/components/drawer/index.cjs +5 -0
  21. package/components/drawer/index.d.ts +1 -0
  22. package/components/drawer/index.js +5 -0
  23. package/components/modal/index.cjs +2 -1
  24. package/components/modal/index.js +2 -1
  25. package/components/modal/modal.d.ts +5 -0
  26. package/components/pagination/index.cjs +1 -1
  27. package/components/pagination/index.js +1 -1
  28. package/components/progressbar/index.cjs +1 -1
  29. package/components/progressbar/index.js +1 -1
  30. package/components/rating/index.cjs +1 -1
  31. package/components/rating/index.js +1 -1
  32. package/components/select/index.cjs +1 -1
  33. package/components/select/index.js +1 -1
  34. package/components/slider/index.cjs +1 -1
  35. package/components/slider/index.js +1 -1
  36. package/components/toast/index.cjs +1 -1
  37. package/components/toast/index.js +1 -1
  38. package/components/tree/index.cjs +1 -1
  39. package/components/tree/index.js +1 -1
  40. package/config.cjs +2 -2
  41. package/config.d.ts +10 -0
  42. package/config.js +2 -2
  43. package/{dom-gfxqXJpK.js → dom-Bcg9ORcA.js} +64 -54
  44. package/{dom-CuBx1JPZ.cjs → dom-C2gi9OCP.cjs} +47 -37
  45. package/drawer-D5SO73ew.js +251 -0
  46. package/drawer-DP7UPojk.cjs +250 -0
  47. package/index.cjs +21 -12
  48. package/index.d.ts +2 -0
  49. package/index.js +54 -45
  50. package/isFocusable-Ckwus82R.js +32 -0
  51. package/isFocusable-DfzDLeAN.cjs +31 -0
  52. package/{modal-D3wGIDlj.js → modal-CAvQW-vo.js} +26 -32
  53. package/{modal-BEnQ6c5M.cjs → modal-DiXZXYjR.cjs} +27 -33
  54. package/package.json +1 -1
  55. package/{pagination-B97wBLok.js → pagination-BKbMROV6.js} +4 -4
  56. package/{pagination-C1TT-oea.cjs → pagination-DvZ2rLsz.cjs} +4 -4
  57. package/{progressbar-BWBlRk_Y.js → progressbar-D8zIcm9n.js} +2 -2
  58. package/{progressbar-CRvhNB5R.cjs → progressbar-i9xfAxb7.cjs} +2 -2
  59. package/{promise-XSP94FjG.js → promise-Y53vc4Ia.js} +5 -5
  60. package/{rating-BXvy9kXq.js → rating-DEXTGWCU.js} +2 -2
  61. package/{rating-DAb6nR67.cjs → rating-DmG4oUkr.cjs} +2 -2
  62. package/scrollbars-CT87iv_6.cjs +30 -0
  63. package/scrollbars-CcxSrnCx.js +31 -0
  64. package/{select-BdjpnE7_.js → select-Bw68Xdu5.js} +4 -5
  65. package/{select-C0rJJQfl.cjs → select-MFjAnIt7.cjs} +4 -5
  66. package/services/extendWidget.cjs +2 -2
  67. package/services/extendWidget.js +2 -2
  68. package/services/floatingUI.cjs +8 -29
  69. package/services/floatingUI.js +9 -30
  70. package/services/focusElement.cjs +46 -0
  71. package/services/focusElement.d.ts +9 -0
  72. package/services/focusElement.js +46 -0
  73. package/services/focustrack.cjs +1 -1
  74. package/services/focustrack.js +1 -1
  75. package/services/matchMedia.cjs +1 -1
  76. package/services/matchMedia.js +1 -1
  77. package/services/navManager.cjs +7 -37
  78. package/services/navManager.js +6 -36
  79. package/services/portal.cjs +7 -10
  80. package/services/portal.js +7 -10
  81. package/services/resizeObserver.cjs +2 -2
  82. package/services/resizeObserver.js +2 -2
  83. package/services/siblingsInert.cjs +9 -8
  84. package/services/siblingsInert.d.ts +13 -3
  85. package/services/siblingsInert.js +9 -8
  86. package/services/transitions/baseTransitions.cjs +9 -10
  87. package/services/transitions/baseTransitions.js +10 -11
  88. package/services/transitions/collapse.cjs +1 -1
  89. package/services/transitions/collapse.js +1 -1
  90. package/services/transitions/cssTransitions.cjs +1 -1
  91. package/services/transitions/cssTransitions.js +2 -2
  92. package/services/transitions/simpleClassTransition.cjs +1 -1
  93. package/services/transitions/simpleClassTransition.js +1 -1
  94. package/{slider-BmxQ3A_u.js → slider-Cx50Eghd.js} +14 -24
  95. package/{slider-DSx5CAce.cjs → slider-Dl4Trh32.cjs} +14 -24
  96. package/toaster-UDglac7x.cjs +187 -0
  97. package/toaster-_p1GTtHI.js +188 -0
  98. package/{tree-BFrXdJox.js → tree-DV0tfPlZ.js} +7 -11
  99. package/{tree-Pvr2rZ-D.cjs → tree-rGHtmCnS.cjs} +7 -11
  100. package/utils/directive.cjs +3 -1
  101. package/utils/directive.d.ts +47 -0
  102. package/utils/directive.js +14 -12
  103. package/utils/stores.cjs +8 -9
  104. package/utils/stores.js +8 -9
  105. package/utils/writables.cjs +1 -1
  106. package/utils/writables.js +1 -1
  107. package/{writables-Bn3uhKEG.cjs → writables-DcGT98a7.cjs} +1 -1
  108. package/{writables-CgpOQ4hA.js → writables-e0tyaQpe.js} +1 -1
  109. package/toaster-Cayg6Lbq.cjs +0 -209
  110. package/toaster-XfzHDqz_.js +0 -210
package/utils/stores.js CHANGED
@@ -1,13 +1,12 @@
1
1
  import { readable, writable, asWritable, equal, batch, computed, asReadable, get, derived } from "@amadeus-it-group/tansu";
2
2
  import { INVALID_VALUE } from "../types.js";
3
3
  import { identity } from "./func.js";
4
- import { t as generateId } from "../dom-gfxqXJpK.js";
4
+ import { v as generateId } from "../dom-Bcg9ORcA.js";
5
5
  function createPatch(stores) {
6
6
  return function(storesValues) {
7
7
  batch(() => {
8
- var _a;
9
8
  for (const [name, value] of Object.entries(storesValues)) {
10
- (_a = stores[`${name}$`]) == null ? void 0 : _a.set(value);
9
+ stores[`${name}$`]?.set(value);
11
10
  }
12
11
  });
13
12
  };
@@ -72,8 +71,8 @@ const normalizeConfigStores = (keys, config) => {
72
71
  const mergeConfigStores = (keys, config1, config2) => {
73
72
  const res = {};
74
73
  for (const key of keys) {
75
- const config1Store = config1 == null ? void 0 : config1[key];
76
- const config2Store = config2 == null ? void 0 : config2[key];
74
+ const config1Store = config1?.[key];
75
+ const config2Store = config2?.[key];
77
76
  res[key] = config1Store && config2Store ? computed(() => config1Store() ?? config2Store()) : config1Store || config2Store;
78
77
  }
79
78
  return res;
@@ -81,11 +80,11 @@ const mergeConfigStores = (keys, config1, config2) => {
81
80
  const writablesWithDefault = (defConfig, propsConfig, options) => {
82
81
  const res = {};
83
82
  const keys = Object.keys(defConfig);
84
- const configStores = normalizeConfigStores(keys, propsConfig == null ? void 0 : propsConfig.config);
85
- const props = propsConfig == null ? void 0 : propsConfig.props;
83
+ const configStores = normalizeConfigStores(keys, propsConfig?.config);
84
+ const props = propsConfig?.props;
86
85
  for (const key of keys) {
87
- const propValue = props == null ? void 0 : props[key];
88
- res[`${key}$`] = writableWithDefault(defConfig[key], configStores[key], options == null ? void 0 : options[key], toWritableStore(propValue));
86
+ const propValue = props?.[key];
87
+ res[`${key}$`] = writableWithDefault(defConfig[key], configStores[key], options?.[key], toWritableStore(propValue));
89
88
  }
90
89
  return res;
91
90
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const utils_writables = require("../writables-Bn3uhKEG.cjs");
3
+ const utils_writables = require("../writables-DcGT98a7.cjs");
4
4
  require("../types.cjs");
5
5
  exports.createTypeEnum = utils_writables.createTypeEnum;
6
6
  exports.testToNormalizeValue = utils_writables.testToNormalizeValue;
@@ -1,4 +1,4 @@
1
- import { j, t, i, c, d, g, h, a, b, e, f } from "../writables-CgpOQ4hA.js";
1
+ import { j, t, i, c, d, g, h, a, b, e, f } from "../writables-e0tyaQpe.js";
2
2
  import "../types.js";
3
3
  export {
4
4
  j as createTypeEnum,
@@ -71,7 +71,7 @@ const typeArray = {
71
71
  if (a === b) {
72
72
  return true;
73
73
  } else {
74
- if ((a == null ? void 0 : a.length) !== (b == null ? void 0 : b.length)) {
74
+ if (a?.length !== b?.length) {
75
75
  return false;
76
76
  }
77
77
  return a.every((val, index) => val === b[index]);
@@ -70,7 +70,7 @@ const typeArray = {
70
70
  if (a === b) {
71
71
  return true;
72
72
  } else {
73
- if ((a == null ? void 0 : a.length) !== (b == null ? void 0 : b.length)) {
73
+ if (a?.length !== b?.length) {
74
74
  return false;
75
75
  }
76
76
  return a.every((val, index) => val === b[index]);
@@ -1,209 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __typeError = (msg) => {
4
- throw TypeError(msg);
5
- };
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
9
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
10
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
11
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
12
- var __privateWrapper = (obj, member, setter, getter) => ({
13
- set _(value) {
14
- __privateSet(obj, member, value, setter);
15
- },
16
- get _() {
17
- return __privateGet(obj, member, getter);
18
- }
19
- });
20
- var _idCount, _toasts, _timers;
21
- const tansu = require("@amadeus-it-group/tansu");
22
- const services_extendWidget = require("./services/extendWidget.cjs");
23
- const utils_directive = require("./dom-CuBx1JPZ.cjs");
24
- const utils_stores = require("./utils/stores.cjs");
25
- const utils_writables = require("./writables-Bn3uhKEG.cjs");
26
- const common = require("./common-BToNPUDq.cjs");
27
- const utils_widget = require("./utils/widget.cjs");
28
- const toastDefaultConfig = {
29
- autoHide: true,
30
- delay: 5e3
31
- };
32
- const toastConfigValidator = {
33
- autoHide: utils_writables.typeBoolean,
34
- delay: utils_writables.typeNumberInRangeFactory(0, Infinity, { strict: true })
35
- };
36
- function getToastDefaultConfig() {
37
- return { ...common.getCommonAlertDefaultConfig(), ...toastDefaultConfig };
38
- }
39
- const createToast = utils_widget.createWidgetFactory("toast", (config) => {
40
- let _timeout;
41
- const extendedAlert = services_extendWidget.extendWidgetProps(
42
- common.createCommonAlert,
43
- toastDefaultConfig,
44
- toastConfigValidator
45
- )(config);
46
- const time$ = tansu.computed(() => {
47
- clearTimeout(_timeout);
48
- if (extendedAlert.stores.autoHide$()) {
49
- _timeout = setTimeout(() => extendedAlert.api.close(), extendedAlert.stores.delay$());
50
- }
51
- });
52
- const bodyDirective = utils_directive.createAttributesDirective(() => ({
53
- attributes: {
54
- role: tansu.readable("alert"),
55
- "aria-atomic": tansu.readable("true"),
56
- class: tansu.computed(() => extendedAlert.stores.className$())
57
- },
58
- classNames: {
59
- "au-toast": utils_stores.true$,
60
- toast: utils_stores.true$
61
- }
62
- }));
63
- const closeButtonDirective = utils_directive.createAttributesDirective(() => ({
64
- attributes: {
65
- type: tansu.readable("button"),
66
- "aria-label": tansu.computed(() => extendedAlert.stores.ariaCloseButtonLabel$())
67
- },
68
- events: {
69
- click: extendedAlert.api.close
70
- }
71
- }));
72
- return {
73
- ...extendedAlert,
74
- directives: {
75
- ...extendedAlert.directives,
76
- autoHideDirective: utils_directive.directiveSubscribe(time$),
77
- bodyDirective,
78
- closeButtonDirective
79
- }
80
- };
81
- });
82
- const defaultToasterProps = {
83
- duration: 5e3,
84
- position: "bottomRight",
85
- dismissible: false
86
- };
87
- class Toaster {
88
- constructor(props) {
89
- __privateAdd(this, _idCount, 0);
90
- __privateAdd(this, _toasts, tansu.writable([]));
91
- /**
92
- * Get the toasts value from the store
93
- * @returns The array of toasts.
94
- */
95
- __publicField(this, "toasts", tansu.computed(
96
- () => __privateGet(this, _toasts).call(this).sort((a, b) => b.id - a.id).slice(0, this.options().limit)
97
- ));
98
- __publicField(this, "options", tansu.writable(defaultToasterProps));
99
- __privateAdd(this, _timers, /* @__PURE__ */ new Map());
100
- /**
101
- * Add timer for a toast
102
- * @param id Id of the toast
103
- * @param duration Duration of the timer, by default taken from options
104
- */
105
- __publicField(this, "addTimer", (id, duration = this.options().duration) => {
106
- if (duration > 0) {
107
- __privateGet(this, _timers).set(id, {
108
- timeout: setTimeout(() => this.removeToast(id), duration),
109
- started: performance.now(),
110
- duration
111
- });
112
- }
113
- });
114
- /**
115
- * Pause a timer for a toast
116
- * @param id Id of the toast
117
- */
118
- __publicField(this, "pauseTimer", (id) => {
119
- if (__privateGet(this, _timers).has(id)) {
120
- const timer = __privateGet(this, _timers).get(id);
121
- if (timer && timer.timeout) {
122
- clearTimeout(timer.timeout);
123
- timer.timeout = null;
124
- timer.paused = performance.now();
125
- }
126
- }
127
- });
128
- /**
129
- * Resume a timer for a toast
130
- * @param id Id of the toast
131
- */
132
- __publicField(this, "resumeTimer", (id) => {
133
- if (__privateGet(this, _timers).has(id)) {
134
- const timer = __privateGet(this, _timers).get(id);
135
- if (timer) {
136
- const paused = timer.paused ?? timer.started;
137
- const elapsed = paused - timer.started;
138
- const remaining = (timer.duration ?? 0) - elapsed;
139
- this.addTimer(id, remaining);
140
- timer.duration = remaining;
141
- timer.paused = void 0;
142
- }
143
- }
144
- });
145
- /**
146
- * Events directive is used to set events on the Toast component, to keep track for example of pointer enter/leave,
147
- * used to pause / resume the timer in case of duration and pauseOnHover are specified.
148
- */
149
- __publicField(this, "eventsDirective", utils_directive.createAttributesDirective((id) => ({
150
- events: {
151
- pointerenter: () => this.options().pauseOnHover && this.pauseTimer(id()),
152
- pointerleave: () => this.options().pauseOnHover && this.resumeTimer(id())
153
- }
154
- })));
155
- /**
156
- * Helper to add a toast to the viewport.
157
- * @param props Options for the toast.
158
- * @returns The ID of the added toast.
159
- */
160
- __publicField(this, "addToast", (props) => {
161
- const autoHide = props.autoHide ?? this.options().duration > 0;
162
- __privateGet(this, _toasts).update((toasts) => [...toasts, { id: __privateWrapper(this, _idCount)._++, props }]);
163
- if (autoHide) {
164
- this.addTimer(__privateGet(this, _idCount) - 1, props.delay);
165
- }
166
- return __privateGet(this, _idCount) - 1;
167
- });
168
- /**
169
- * Helper to remove a toast to the viewport.
170
- * @param id Id of the toast to remove.
171
- */
172
- __publicField(this, "removeToast", (id) => {
173
- __privateGet(this, _timers).delete(id);
174
- __privateGet(this, _toasts).update((toasts) => toasts.filter((toast) => toast.id !== id));
175
- });
176
- /** Helper to update toasts when options change */
177
- __publicField(this, "updateToasts", () => {
178
- if (this.options().duration === 0) {
179
- this.options().dismissible = true;
180
- }
181
- });
182
- /** Helper to close all toasts at once */
183
- __publicField(this, "closeAll", () => {
184
- __privateGet(this, _toasts).set([]);
185
- __privateGet(this, _timers).clear();
186
- });
187
- this.options.set({
188
- ...defaultToasterProps,
189
- ...props
190
- });
191
- this.options.subscribe(() => {
192
- this.updateToasts();
193
- });
194
- }
195
- /**
196
- * Get the timers value from the store
197
- * @returns The map of timers.
198
- */
199
- get timers() {
200
- return new Map(__privateGet(this, _timers));
201
- }
202
- }
203
- _idCount = new WeakMap();
204
- _toasts = new WeakMap();
205
- _timers = new WeakMap();
206
- exports.Toaster = Toaster;
207
- exports.createToast = createToast;
208
- exports.defaultToasterProps = defaultToasterProps;
209
- exports.getToastDefaultConfig = getToastDefaultConfig;
@@ -1,210 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __typeError = (msg) => {
3
- throw TypeError(msg);
4
- };
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
8
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
- var __privateWrapper = (obj, member, setter, getter) => ({
12
- set _(value) {
13
- __privateSet(obj, member, value, setter);
14
- },
15
- get _() {
16
- return __privateGet(obj, member, getter);
17
- }
18
- });
19
- var _idCount, _toasts, _timers;
20
- import { computed, readable, writable } from "@amadeus-it-group/tansu";
21
- import { extendWidgetProps } from "./services/extendWidget.js";
22
- import { n as createAttributesDirective, d as directiveSubscribe } from "./dom-gfxqXJpK.js";
23
- import { true$ } from "./utils/stores.js";
24
- import { b as typeNumberInRangeFactory, c as typeBoolean } from "./writables-CgpOQ4hA.js";
25
- import { g as getCommonAlertDefaultConfig, c as createCommonAlert } from "./common-BqUjUBPy.js";
26
- import { createWidgetFactory } from "./utils/widget.js";
27
- const toastDefaultConfig = {
28
- autoHide: true,
29
- delay: 5e3
30
- };
31
- const toastConfigValidator = {
32
- autoHide: typeBoolean,
33
- delay: typeNumberInRangeFactory(0, Infinity, { strict: true })
34
- };
35
- function getToastDefaultConfig() {
36
- return { ...getCommonAlertDefaultConfig(), ...toastDefaultConfig };
37
- }
38
- const createToast = createWidgetFactory("toast", (config) => {
39
- let _timeout;
40
- const extendedAlert = extendWidgetProps(
41
- createCommonAlert,
42
- toastDefaultConfig,
43
- toastConfigValidator
44
- )(config);
45
- const time$ = computed(() => {
46
- clearTimeout(_timeout);
47
- if (extendedAlert.stores.autoHide$()) {
48
- _timeout = setTimeout(() => extendedAlert.api.close(), extendedAlert.stores.delay$());
49
- }
50
- });
51
- const bodyDirective = createAttributesDirective(() => ({
52
- attributes: {
53
- role: readable("alert"),
54
- "aria-atomic": readable("true"),
55
- class: computed(() => extendedAlert.stores.className$())
56
- },
57
- classNames: {
58
- "au-toast": true$,
59
- toast: true$
60
- }
61
- }));
62
- const closeButtonDirective = createAttributesDirective(() => ({
63
- attributes: {
64
- type: readable("button"),
65
- "aria-label": computed(() => extendedAlert.stores.ariaCloseButtonLabel$())
66
- },
67
- events: {
68
- click: extendedAlert.api.close
69
- }
70
- }));
71
- return {
72
- ...extendedAlert,
73
- directives: {
74
- ...extendedAlert.directives,
75
- autoHideDirective: directiveSubscribe(time$),
76
- bodyDirective,
77
- closeButtonDirective
78
- }
79
- };
80
- });
81
- const defaultToasterProps = {
82
- duration: 5e3,
83
- position: "bottomRight",
84
- dismissible: false
85
- };
86
- class Toaster {
87
- constructor(props) {
88
- __privateAdd(this, _idCount, 0);
89
- __privateAdd(this, _toasts, writable([]));
90
- /**
91
- * Get the toasts value from the store
92
- * @returns The array of toasts.
93
- */
94
- __publicField(this, "toasts", computed(
95
- () => __privateGet(this, _toasts).call(this).sort((a, b) => b.id - a.id).slice(0, this.options().limit)
96
- ));
97
- __publicField(this, "options", writable(defaultToasterProps));
98
- __privateAdd(this, _timers, /* @__PURE__ */ new Map());
99
- /**
100
- * Add timer for a toast
101
- * @param id Id of the toast
102
- * @param duration Duration of the timer, by default taken from options
103
- */
104
- __publicField(this, "addTimer", (id, duration = this.options().duration) => {
105
- if (duration > 0) {
106
- __privateGet(this, _timers).set(id, {
107
- timeout: setTimeout(() => this.removeToast(id), duration),
108
- started: performance.now(),
109
- duration
110
- });
111
- }
112
- });
113
- /**
114
- * Pause a timer for a toast
115
- * @param id Id of the toast
116
- */
117
- __publicField(this, "pauseTimer", (id) => {
118
- if (__privateGet(this, _timers).has(id)) {
119
- const timer = __privateGet(this, _timers).get(id);
120
- if (timer && timer.timeout) {
121
- clearTimeout(timer.timeout);
122
- timer.timeout = null;
123
- timer.paused = performance.now();
124
- }
125
- }
126
- });
127
- /**
128
- * Resume a timer for a toast
129
- * @param id Id of the toast
130
- */
131
- __publicField(this, "resumeTimer", (id) => {
132
- if (__privateGet(this, _timers).has(id)) {
133
- const timer = __privateGet(this, _timers).get(id);
134
- if (timer) {
135
- const paused = timer.paused ?? timer.started;
136
- const elapsed = paused - timer.started;
137
- const remaining = (timer.duration ?? 0) - elapsed;
138
- this.addTimer(id, remaining);
139
- timer.duration = remaining;
140
- timer.paused = void 0;
141
- }
142
- }
143
- });
144
- /**
145
- * Events directive is used to set events on the Toast component, to keep track for example of pointer enter/leave,
146
- * used to pause / resume the timer in case of duration and pauseOnHover are specified.
147
- */
148
- __publicField(this, "eventsDirective", createAttributesDirective((id) => ({
149
- events: {
150
- pointerenter: () => this.options().pauseOnHover && this.pauseTimer(id()),
151
- pointerleave: () => this.options().pauseOnHover && this.resumeTimer(id())
152
- }
153
- })));
154
- /**
155
- * Helper to add a toast to the viewport.
156
- * @param props Options for the toast.
157
- * @returns The ID of the added toast.
158
- */
159
- __publicField(this, "addToast", (props) => {
160
- const autoHide = props.autoHide ?? this.options().duration > 0;
161
- __privateGet(this, _toasts).update((toasts) => [...toasts, { id: __privateWrapper(this, _idCount)._++, props }]);
162
- if (autoHide) {
163
- this.addTimer(__privateGet(this, _idCount) - 1, props.delay);
164
- }
165
- return __privateGet(this, _idCount) - 1;
166
- });
167
- /**
168
- * Helper to remove a toast to the viewport.
169
- * @param id Id of the toast to remove.
170
- */
171
- __publicField(this, "removeToast", (id) => {
172
- __privateGet(this, _timers).delete(id);
173
- __privateGet(this, _toasts).update((toasts) => toasts.filter((toast) => toast.id !== id));
174
- });
175
- /** Helper to update toasts when options change */
176
- __publicField(this, "updateToasts", () => {
177
- if (this.options().duration === 0) {
178
- this.options().dismissible = true;
179
- }
180
- });
181
- /** Helper to close all toasts at once */
182
- __publicField(this, "closeAll", () => {
183
- __privateGet(this, _toasts).set([]);
184
- __privateGet(this, _timers).clear();
185
- });
186
- this.options.set({
187
- ...defaultToasterProps,
188
- ...props
189
- });
190
- this.options.subscribe(() => {
191
- this.updateToasts();
192
- });
193
- }
194
- /**
195
- * Get the timers value from the store
196
- * @returns The map of timers.
197
- */
198
- get timers() {
199
- return new Map(__privateGet(this, _timers));
200
- }
201
- }
202
- _idCount = new WeakMap();
203
- _toasts = new WeakMap();
204
- _timers = new WeakMap();
205
- export {
206
- Toaster as T,
207
- createToast as c,
208
- defaultToasterProps as d,
209
- getToastDefaultConfig as g
210
- };