@agnos-ui/core 0.2.0 → 0.3.1

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 (143) hide show
  1. package/README.md +3 -3
  2. package/accordion-BaWN0_n-.js +330 -0
  3. package/accordion-BuIgxZ0S.cjs +329 -0
  4. package/alert-C4jCg9Pl.cjs +8 -0
  5. package/alert-Dlf-BV98.js +9 -0
  6. package/common-DRdsw5m8.js +76 -0
  7. package/common-nJRMXbwj.cjs +75 -0
  8. package/components/accordion/accordion.d.ts +38 -49
  9. package/components/accordion/index.cjs +7 -0
  10. package/components/accordion/index.js +7 -1
  11. package/components/alert/alert.d.ts +3 -12
  12. package/components/alert/common.d.ts +4 -13
  13. package/components/alert/index.cjs +10 -0
  14. package/components/alert/index.js +10 -2
  15. package/components/modal/index.cjs +7 -0
  16. package/components/modal/index.js +7 -1
  17. package/components/modal/modal.d.ts +7 -49
  18. package/components/pagination/index.cjs +5 -0
  19. package/components/pagination/index.d.ts +0 -1
  20. package/components/pagination/index.js +5 -2
  21. package/components/pagination/pagination.d.ts +68 -139
  22. package/components/progressbar/index.cjs +5 -0
  23. package/components/progressbar/index.js +5 -1
  24. package/components/progressbar/progressbar.d.ts +6 -22
  25. package/components/rating/index.cjs +5 -0
  26. package/components/rating/index.js +5 -1
  27. package/components/rating/rating.d.ts +16 -11
  28. package/components/select/index.cjs +6 -0
  29. package/components/select/index.js +6 -1
  30. package/components/select/select.d.ts +15 -33
  31. package/components/slider/index.cjs +5 -0
  32. package/components/slider/index.js +5 -1
  33. package/components/slider/slider.d.ts +29 -35
  34. package/components/toast/index.cjs +5 -0
  35. package/components/toast/index.js +5 -1
  36. package/components/toast/toast.d.ts +11 -8
  37. package/config.cjs +38 -0
  38. package/config.d.ts +1 -1
  39. package/config.js +35 -50
  40. package/directive-BTSEYLF3.cjs +404 -0
  41. package/directive-DCYlDznf.js +405 -0
  42. package/func-DR0n-ShK.js +7 -0
  43. package/func-Qd3cD9a3.cjs +6 -0
  44. package/index.cjs +119 -0
  45. package/index.d.ts +1 -1
  46. package/index.js +119 -33
  47. package/modal-BI2qUu1M.js +251 -0
  48. package/modal-rzMpATf5.cjs +250 -0
  49. package/package.json +29 -19
  50. package/pagination--GkwduJn.js +263 -0
  51. package/pagination-EWSWQT1I.cjs +262 -0
  52. package/progressbar-DH7DHYMp.cjs +83 -0
  53. package/progressbar-DuRX7_my.js +84 -0
  54. package/promise-BMJ8qhA8.cjs +118 -0
  55. package/promise-CY2U8bTP.js +119 -0
  56. package/rating-BR5wD7y2.js +173 -0
  57. package/rating-CmuYUSxy.cjs +172 -0
  58. package/select-BCs6HQWn.js +358 -0
  59. package/select-CCIKn8WR.cjs +357 -0
  60. package/services/extendWidget.cjs +32 -0
  61. package/services/extendWidget.d.ts +2 -1
  62. package/services/extendWidget.js +31 -34
  63. package/services/floatingUI.cjs +131 -0
  64. package/services/floatingUI.d.ts +30 -14
  65. package/services/floatingUI.js +128 -102
  66. package/services/focustrack.cjs +47 -0
  67. package/services/focustrack.js +45 -44
  68. package/services/hash.cjs +15 -0
  69. package/services/hash.js +14 -12
  70. package/services/intersection.cjs +53 -0
  71. package/services/intersection.js +48 -50
  72. package/services/matchMedia.cjs +13 -0
  73. package/services/matchMedia.d.ts +7 -0
  74. package/services/matchMedia.js +13 -0
  75. package/services/navManager.cjs +196 -0
  76. package/services/navManager.d.ts +9 -9
  77. package/services/navManager.js +186 -168
  78. package/services/portal.cjs +43 -0
  79. package/services/portal.js +41 -42
  80. package/services/resizeObserver.cjs +32 -0
  81. package/services/resizeObserver.d.ts +1 -1
  82. package/services/resizeObserver.js +31 -28
  83. package/services/siblingsInert.cjs +40 -0
  84. package/services/siblingsInert.js +31 -31
  85. package/services/transitions/baseTransitions.cjs +171 -0
  86. package/services/transitions/baseTransitions.d.ts +16 -16
  87. package/services/transitions/baseTransitions.js +159 -170
  88. package/services/transitions/collapse.cjs +44 -0
  89. package/services/transitions/collapse.js +41 -49
  90. package/services/transitions/cssTransitions.cjs +32 -0
  91. package/services/transitions/cssTransitions.d.ts +2 -1
  92. package/services/transitions/cssTransitions.js +29 -39
  93. package/services/transitions/simpleClassTransition.cjs +31 -0
  94. package/services/transitions/simpleClassTransition.js +30 -41
  95. package/slider-CA_fszn7.js +536 -0
  96. package/slider-DsLvT87U.cjs +535 -0
  97. package/toast-8tWp6x89.js +63 -0
  98. package/toast-Aw8o0Iwe.cjs +62 -0
  99. package/types.cjs +12 -0
  100. package/types.d.ts +21 -1
  101. package/types.js +11 -13
  102. package/utils/directive.cjs +26 -0
  103. package/utils/directive.d.ts +148 -5
  104. package/utils/directive.js +25 -205
  105. package/utils/internal/dom.d.ts +43 -4
  106. package/utils/internal/promise.d.ts +2 -2
  107. package/utils/internal/ssrHTMLElement.d.ts +7 -0
  108. package/utils/stores.cjs +163 -0
  109. package/utils/stores.d.ts +9 -17
  110. package/utils/stores.js +149 -284
  111. package/utils/writables.cjs +13 -0
  112. package/utils/writables.js +12 -71
  113. package/writables-D46sFgGK.cjs +85 -0
  114. package/writables-DoU_XYTX.js +86 -0
  115. package/components/accordion/accordion.js +0 -264
  116. package/components/alert/alert.js +0 -22
  117. package/components/alert/common.js +0 -69
  118. package/components/commonProps.js +0 -1
  119. package/components/modal/modal.js +0 -186
  120. package/components/pagination/bootstrap.d.ts +0 -8
  121. package/components/pagination/bootstrap.js +0 -110
  122. package/components/pagination/pagination.js +0 -195
  123. package/components/progressbar/progressbar.js +0 -78
  124. package/components/rating/rating.js +0 -137
  125. package/components/select/select.js +0 -297
  126. package/components/slider/slider.js +0 -420
  127. package/components/toast/toast.js +0 -43
  128. package/services/transitions/bootstrap/collapse.d.ts +0 -2
  129. package/services/transitions/bootstrap/collapse.js +0 -15
  130. package/services/transitions/bootstrap/fade.d.ts +0 -1
  131. package/services/transitions/bootstrap/fade.js +0 -7
  132. package/services/transitions/bootstrap.d.ts +0 -2
  133. package/services/transitions/bootstrap.js +0 -2
  134. package/utils/internal/checks.js +0 -60
  135. package/utils/internal/dom.js +0 -82
  136. package/utils/internal/func.js +0 -11
  137. package/utils/internal/isFocusable.js +0 -37
  138. package/utils/internal/math.js +0 -13
  139. package/utils/internal/promise.js +0 -169
  140. package/utils/internal/scrollbars.js +0 -33
  141. package/utils/internal/sort.js +0 -28
  142. package/utils/internal/textDirection.js +0 -7
  143. package/utils/internal/traversal.js +0 -105
@@ -1,26 +1,29 @@
1
1
  import type { ExtendWidgetAdaptSlotWidgetProps, ExtendWidgetInterfaces } from '../../services/extendWidget';
2
- import type { Directive, PropsConfig, SlotContent, Widget, WidgetSlotContext } from '../../types';
2
+ import type { Directive, PropsConfig, Widget } from '../../types';
3
3
  import type { CommonAlertApi, CommonAlertDirectives, CommonAlertProps, CommonAlertState } from '../alert/common';
4
- export type ToastContext = WidgetSlotContext<ToastWidget>;
5
4
  export interface ToastExtraProps {
6
5
  /**
7
6
  * If `true` automatically hides the toast after the delay.
8
7
  */
9
- autohide: boolean;
8
+ autoHide: boolean;
10
9
  /**
11
10
  * Delay in milliseconds before hiding the toast.
12
11
  */
13
12
  delay: number;
14
- /**
15
- * Header template for the toast component
16
- */
17
- slotHeader: SlotContent<ToastContext>;
18
13
  }
19
14
  export interface ExtraDirectives {
20
15
  /**
21
16
  * Directive that handles the autohide of the toast component
22
17
  */
23
- autohideDirective: Directive;
18
+ autoHideDirective: Directive;
19
+ /**
20
+ * Directive that adds all the necessary attributes to the body
21
+ */
22
+ bodyDirective: Directive;
23
+ /**
24
+ * Directive that adds all the necessary attributes to the close button depending on the presence of the header
25
+ */
26
+ closeButtonDirective: Directive;
24
27
  }
25
28
  export interface ToastState extends ExtendWidgetAdaptSlotWidgetProps<CommonAlertState, ToastExtraProps, ExtraDirectives> {
26
29
  }
package/config.cjs ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tansu = require("@amadeus-it-group/tansu");
4
+ const func = require("./func-Qd3cD9a3.cjs");
5
+ const mergeInto = (destination, source, levels = Infinity) => {
6
+ if (source !== void 0) {
7
+ if (typeof source === "object" && source && levels >= 1) {
8
+ if (!destination) {
9
+ destination = {};
10
+ }
11
+ for (const key of Object.keys(source)) {
12
+ if (!Object.prototype.hasOwnProperty.call(source, key))
13
+ continue;
14
+ if (key === "__proto__" || key === "constructor")
15
+ continue;
16
+ destination[key] = mergeInto(destination[key], source[key], levels - 1);
17
+ }
18
+ } else {
19
+ return source;
20
+ }
21
+ }
22
+ return destination;
23
+ };
24
+ const createWidgetsConfig = (parent$, adaptParentConfig = func.identity) => {
25
+ const own$ = tansu.writable({});
26
+ const adaptedParent$ = adaptParentConfig === func.identity ? parent$ : tansu.computed(() => adaptParentConfig(mergeInto({}, parent$ == null ? void 0 : parent$(), 2)));
27
+ return tansu.asWritable(
28
+ tansu.computed(() => mergeInto(mergeInto({}, adaptedParent$ == null ? void 0 : adaptedParent$(), 2), own$(), 2)),
29
+ {
30
+ ...own$,
31
+ own$,
32
+ adaptedParent$,
33
+ parent$
34
+ }
35
+ );
36
+ };
37
+ exports.createWidgetsConfig = createWidgetsConfig;
38
+ exports.mergeInto = mergeInto;
package/config.d.ts CHANGED
@@ -45,7 +45,7 @@ export declare const mergeInto: <T>(destination: T, source: T | undefined, level
45
45
  * parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties).
46
46
  * The resulting store is writable, its set function is actually the set function of the own$ store.
47
47
  */
48
- export declare const createWidgetsConfig: <T>(parent$?: WidgetsConfigStore<T> | undefined, adaptParentConfig?: (config: Partial<{ [Level1 in keyof T]: Partial<T[Level1]>; }>) => Partial<{ [Level1 in keyof T]: Partial<T[Level1]>; }>) => WidgetsConfigStore<T>;
48
+ export declare const createWidgetsConfig: <T>(parent$?: WidgetsConfigStore<T> | undefined, adaptParentConfig?: (config: Partial2Levels<T>) => Partial2Levels<T>) => WidgetsConfigStore<T>;
49
49
  export interface WidgetsConfig {
50
50
  /**
51
51
  * the pagination widget config
package/config.js CHANGED
@@ -1,53 +1,38 @@
1
- import { asWritable, computed, writable } from '@amadeus-it-group/tansu';
2
- import { identity } from './utils/internal/func';
3
- /**
4
- * Merges source object into destination object, up to the provided number of levels.
5
- * @param destination - destination object
6
- * @param source - source object
7
- * @param levels - number of levels to merge
8
- * @returns the destination object in most cases, or the source in some cases (if the source is not undefined and either levels is smaller than 1
9
- * or the source is not an object)
10
- */
11
- export const mergeInto = (destination, source, levels = Infinity) => {
12
- if (source !== undefined) {
13
- if (typeof source === 'object' && source && levels >= 1) {
14
- for (const key of Object.keys(source)) {
15
- destination[key] = mergeInto(destination[key] ?? {}, source[key], levels - 1);
16
- }
17
- }
18
- else {
19
- return source;
20
- }
1
+ import { writable, computed, asWritable } from "@amadeus-it-group/tansu";
2
+ import { i as identity } from "./func-DR0n-ShK.js";
3
+ const mergeInto = (destination, source, levels = Infinity) => {
4
+ if (source !== void 0) {
5
+ if (typeof source === "object" && source && levels >= 1) {
6
+ if (!destination) {
7
+ destination = {};
8
+ }
9
+ for (const key of Object.keys(source)) {
10
+ if (!Object.prototype.hasOwnProperty.call(source, key))
11
+ continue;
12
+ if (key === "__proto__" || key === "constructor")
13
+ continue;
14
+ destination[key] = mergeInto(destination[key], source[key], levels - 1);
15
+ }
16
+ } else {
17
+ return source;
21
18
  }
22
- return destination;
19
+ }
20
+ return destination;
23
21
  };
24
- /**
25
- * Creates a new widgets default configuration store, optionally inheriting from a parent store, and containing
26
- * its own set of widgets configuration properties that override the same properties form the parent configuration.
27
- *
28
- * @remarks
29
- * The resulting store has a value computed from the parent store in two steps:
30
- * - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
31
- * If adaptParentConfig is not specified, this step is skipped.
32
- * - second step: the configuration from step 1 is merged (2-levels deep) with the own$ store. The own$ store initially contains
33
- * an empty object (i.e. no property from the parent is overridden). It can be changed by calling set on the store returned by this function.
34
- *
35
- * @param parent$ - optional parent widgets default configuration store.
36
- * @param adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
37
- * from parent$ (or an empty object if parent$ is not specified) and returns the widgets default configuration to be used.
38
- * It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
39
- * It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
40
- * @returns the resulting widgets default configuration store, which contains 3 additional properties that are stores:
41
- * parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties).
42
- * The resulting store is writable, its set function is actually the set function of the own$ store.
43
- */
44
- export const createWidgetsConfig = (parent$, adaptParentConfig = identity) => {
45
- const own$ = writable({});
46
- const adaptedParent$ = adaptParentConfig === identity ? parent$ : computed(() => adaptParentConfig(mergeInto({}, parent$?.(), 2)));
47
- return asWritable(computed(() => mergeInto(mergeInto({}, adaptedParent$?.(), 2), own$(), 2)), {
48
- ...own$,
49
- own$,
50
- adaptedParent$,
51
- parent$,
52
- });
22
+ const createWidgetsConfig = (parent$, adaptParentConfig = identity) => {
23
+ const own$ = writable({});
24
+ const adaptedParent$ = adaptParentConfig === identity ? parent$ : computed(() => adaptParentConfig(mergeInto({}, parent$ == null ? void 0 : parent$(), 2)));
25
+ return asWritable(
26
+ computed(() => mergeInto(mergeInto({}, adaptedParent$ == null ? void 0 : adaptedParent$(), 2), own$(), 2)),
27
+ {
28
+ ...own$,
29
+ own$,
30
+ adaptedParent$,
31
+ parent$
32
+ }
33
+ );
34
+ };
35
+ export {
36
+ createWidgetsConfig,
37
+ mergeInto
53
38
  };
@@ -0,0 +1,404 @@
1
+ "use strict";
2
+ const tansu = require("@amadeus-it-group/tansu");
3
+ const esmEnv = require("esm-env");
4
+ const func = require("./func-Qd3cD9a3.cjs");
5
+ const utils_stores = require("./utils/stores.cjs");
6
+ const computeCommonAncestor = (elements) => {
7
+ const length = elements.length;
8
+ if (length === 0)
9
+ return null;
10
+ let ancestor = elements[0];
11
+ for (let i = 1; i < length && ancestor; i++) {
12
+ const element = elements[i];
13
+ while (ancestor) {
14
+ if (ancestor === element) {
15
+ break;
16
+ }
17
+ const comparison = ancestor.compareDocumentPosition(element);
18
+ if (comparison & Node.DOCUMENT_POSITION_CONTAINED_BY) {
19
+ break;
20
+ } else if (comparison & Node.DOCUMENT_POSITION_CONTAINS) {
21
+ ancestor = element;
22
+ break;
23
+ } else if (comparison & Node.DOCUMENT_POSITION_DISCONNECTED) {
24
+ return null;
25
+ }
26
+ ancestor = ancestor.parentElement;
27
+ }
28
+ }
29
+ return ancestor;
30
+ };
31
+ const reflow = esmEnv.BROWSER ? (element = document.body) => {
32
+ if (isBrowserHTMLElement(element)) {
33
+ element.getBoundingClientRect();
34
+ }
35
+ } : func.noop;
36
+ const addClasses = (element, classes) => {
37
+ if (classes && classes.length > 0) {
38
+ element.classList.add(...classes);
39
+ }
40
+ };
41
+ const removeClasses = (element, classes) => {
42
+ if (classes && classes.length > 0) {
43
+ element.classList.remove(...classes);
44
+ }
45
+ };
46
+ function addEvent(element, type, fn, options) {
47
+ element.addEventListener(type, fn, options);
48
+ return function() {
49
+ element.removeEventListener(type, fn, options);
50
+ };
51
+ }
52
+ let idCount = 0;
53
+ const generateId = () => `auId-${idCount++}`;
54
+ const notEmpty = (value) => value != null && value !== false;
55
+ function classNamesSubscribe(node, classNames$) {
56
+ let currentClassNames = /* @__PURE__ */ new Set();
57
+ return classNames$.subscribe((newClassName) => {
58
+ const classNames = new Set(`${newClassName ?? ""}`.split(" "));
59
+ classNames.delete("");
60
+ const classList = node.classList;
61
+ for (const className of currentClassNames) {
62
+ if (!classNames.has(className)) {
63
+ classList.remove(className);
64
+ }
65
+ }
66
+ if (classNames.size > 0) {
67
+ classList.add(...classNames);
68
+ }
69
+ currentClassNames = classNames;
70
+ });
71
+ }
72
+ function attributeSubscribe(node, attributeName, value$) {
73
+ return value$.subscribe((value) => {
74
+ if (notEmpty(value)) {
75
+ node.setAttribute(attributeName, "" + (value === true ? attributeName : value));
76
+ } else {
77
+ node.removeAttribute(attributeName);
78
+ }
79
+ });
80
+ }
81
+ function bindAttribute(node, attributeName, value$) {
82
+ const isClass = attributeName === "class";
83
+ return isClass ? classNamesSubscribe(node, value$) : attributeSubscribe(node, attributeName, value$);
84
+ }
85
+ function bindStyle(node, styleName, value$) {
86
+ return value$.subscribe((value) => {
87
+ const style = node.style;
88
+ style[styleName] = "" + (notEmpty(value) ? value : "");
89
+ });
90
+ }
91
+ function bindClassName(node, className, value$) {
92
+ const unsubscribe = value$.subscribe((isPresent) => {
93
+ node.classList.toggle(className, isPresent);
94
+ });
95
+ return () => {
96
+ unsubscribe();
97
+ node.classList.remove(className);
98
+ };
99
+ }
100
+ const ssrHTMLElementAttributesAndStyle = Symbol("attributesAndStyle");
101
+ const spaceRegExp = /\s+/;
102
+ const ssrHTMLElement = () => {
103
+ const attributes = {};
104
+ const style = {};
105
+ let classNames = /* @__PURE__ */ new Set();
106
+ const toggleClass = (className, force = !classNames.has(className)) => {
107
+ if (force) {
108
+ classNames.add(className);
109
+ } else {
110
+ classNames.delete(className);
111
+ }
112
+ return !!force;
113
+ };
114
+ const toggleAll = (force) => (...classNames2) => classNames2.forEach((className) => toggleClass(className, force));
115
+ return {
116
+ style,
117
+ classList: {
118
+ add: toggleAll(true),
119
+ remove: toggleAll(false),
120
+ toggle: toggleClass
121
+ },
122
+ setAttribute(name, value) {
123
+ if (name === "class") {
124
+ classNames = new Set(value.trim().split(spaceRegExp));
125
+ } else if (name === "style") {
126
+ throw new Error('setAttribute("style",...) is not implemented in ssrHTMLElement. Use the style property instead.');
127
+ } else {
128
+ attributes[name] = value;
129
+ }
130
+ },
131
+ removeAttribute(name) {
132
+ if (name === "class") {
133
+ classNames = /* @__PURE__ */ new Set();
134
+ } else {
135
+ delete attributes[name];
136
+ }
137
+ },
138
+ [ssrHTMLElementAttributesAndStyle]() {
139
+ return { attributes: { ...attributes }, classNames: [...classNames], style: { ...style } };
140
+ }
141
+ };
142
+ };
143
+ const isBrowserHTMLElement = esmEnv.BROWSER ? (element) => {
144
+ var _a;
145
+ const contentWindow = ((_a = element == null ? void 0 : element.ownerDocument) == null ? void 0 : _a.defaultView) ?? window;
146
+ return element instanceof contentWindow.HTMLElement;
147
+ } : (element) => false;
148
+ const browserDirective = esmEnv.BROWSER ? (directive) => (node, args) => {
149
+ if (isBrowserHTMLElement(node)) {
150
+ return directive(node, args);
151
+ }
152
+ } : (directive) => () => {
153
+ };
154
+ const bindDirective = (directive, directiveArg$) => (element) => {
155
+ let firstTime = true;
156
+ let instance;
157
+ const unsubscribe = directiveArg$.subscribe((value) => {
158
+ var _a;
159
+ if (firstTime) {
160
+ firstTime = false;
161
+ instance = directive(element, value);
162
+ } else {
163
+ (_a = instance == null ? void 0 : instance.update) == null ? void 0 : _a.call(instance, value);
164
+ }
165
+ });
166
+ return {
167
+ destroy() {
168
+ var _a;
169
+ (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
170
+ unsubscribe();
171
+ }
172
+ };
173
+ };
174
+ const noArg = tansu.readable(void 0);
175
+ const bindDirectiveNoArg = (directive) => bindDirective(directive, noArg);
176
+ const mapDirectiveArg = (directive, fn) => (node, arg) => {
177
+ const instance = directive(node, fn(arg));
178
+ return {
179
+ update: (arg2) => {
180
+ var _a;
181
+ (_a = instance == null ? void 0 : instance.update) == null ? void 0 : _a.call(instance, fn(arg2));
182
+ },
183
+ destroy: () => {
184
+ var _a;
185
+ return (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
186
+ }
187
+ };
188
+ };
189
+ const directiveSubscribe = (store, asyncUnsubscribe = true) => () => {
190
+ const unsubscribe = store.subscribe(func.noop);
191
+ return {
192
+ destroy: async () => {
193
+ if (asyncUnsubscribe) {
194
+ await 0;
195
+ }
196
+ unsubscribe();
197
+ }
198
+ };
199
+ };
200
+ const directiveUpdate = (update) => (element, arg) => {
201
+ update(arg);
202
+ return {
203
+ update
204
+ };
205
+ };
206
+ const equalOption = { equal: Object.is };
207
+ const registrationArray = () => {
208
+ const elements$ = tansu.writable([], equalOption);
209
+ return tansu.asReadable(elements$, {
210
+ /**
211
+ * Add the given element to the array.
212
+ * @param element - Element to be added to the array.
213
+ * @returns A function to remove the element from the array.
214
+ */
215
+ register: (element) => {
216
+ let removed = false;
217
+ elements$.update((currentElements) => [...currentElements, element]);
218
+ return () => {
219
+ if (!removed) {
220
+ removed = true;
221
+ elements$.update((currentElements) => {
222
+ const index = currentElements.indexOf(element);
223
+ if (index > -1) {
224
+ const copy = [...currentElements];
225
+ copy.splice(index, 1);
226
+ return copy;
227
+ }
228
+ return currentElements;
229
+ });
230
+ }
231
+ };
232
+ }
233
+ });
234
+ };
235
+ const createStoreArrayDirective = () => {
236
+ const elements$ = registrationArray();
237
+ return {
238
+ elements$: tansu.asReadable(elements$),
239
+ directive: (element) => ({ destroy: elements$.register(element) })
240
+ };
241
+ };
242
+ const createBrowserStoreArrayDirective = () => {
243
+ const { directive, elements$ } = createStoreArrayDirective();
244
+ return { directive: browserDirective(directive), elements$ };
245
+ };
246
+ const createStoreDirective = () => {
247
+ const element$ = tansu.writable(null, equalOption);
248
+ return {
249
+ element$: tansu.asReadable(element$),
250
+ directive: (element) => {
251
+ let valid = false;
252
+ element$.update((currentElement) => {
253
+ if (currentElement) {
254
+ console.error("The directive cannot be used on multiple elements.", currentElement, element);
255
+ return currentElement;
256
+ }
257
+ valid = true;
258
+ return element;
259
+ });
260
+ return valid ? {
261
+ destroy() {
262
+ element$.update((currentElement) => element === currentElement ? null : currentElement);
263
+ }
264
+ } : void 0;
265
+ }
266
+ };
267
+ };
268
+ const createBrowserStoreDirective = () => {
269
+ const { directive, element$ } = createStoreDirective();
270
+ return { directive: browserDirective(directive), element$ };
271
+ };
272
+ const mergeDirectives = (...args) => (element, arg) => {
273
+ const instances = tansu.batch(() => args.map((directive) => directive(element, arg)));
274
+ return {
275
+ update(arg2) {
276
+ tansu.batch(() => instances.forEach((instance) => {
277
+ var _a;
278
+ return (_a = instance == null ? void 0 : instance.update) == null ? void 0 : _a.call(instance, arg2);
279
+ }));
280
+ },
281
+ destroy() {
282
+ tansu.batch(() => instances.reverse().forEach((instance) => {
283
+ var _a;
284
+ return (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
285
+ }));
286
+ }
287
+ };
288
+ };
289
+ const multiDirective = (element, directives) => {
290
+ const instances = [];
291
+ const update = (directives2) => tansu.batch(() => {
292
+ directives2.forEach((directiveWithArg, index) => {
293
+ var _a, _b, _c, _d;
294
+ const [directive, arg] = Array.isArray(directiveWithArg) ? directiveWithArg : [directiveWithArg, void 0];
295
+ const oldInstance = instances[index];
296
+ if (oldInstance) {
297
+ if (oldInstance.directive === directive) {
298
+ if (oldInstance.arg !== arg) {
299
+ (_b = (_a = oldInstance.instance) == null ? void 0 : _a.update) == null ? void 0 : _b.call(_a, arg);
300
+ oldInstance.arg = arg;
301
+ }
302
+ return;
303
+ }
304
+ (_d = (_c = oldInstance.instance) == null ? void 0 : _c.destroy) == null ? void 0 : _d.call(_c);
305
+ }
306
+ const instance = directive(element, arg);
307
+ instances[index] = { directive, instance, arg };
308
+ });
309
+ const extraInstances = instances.splice(directives2.length);
310
+ extraInstances.reverse().forEach(({ instance }) => {
311
+ var _a;
312
+ return (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
313
+ });
314
+ });
315
+ update(directives);
316
+ return {
317
+ update,
318
+ destroy: () => update([])
319
+ };
320
+ };
321
+ const createAttributesDirective = (propsFn) => (node, args) => {
322
+ const unsubscribers = [];
323
+ const args$ = tansu.writable(args);
324
+ const { events, attributes, styles, classNames } = propsFn(args$);
325
+ if (isBrowserHTMLElement(node)) {
326
+ for (const [type, event] of Object.entries(events ?? {})) {
327
+ if (typeof event === "function") {
328
+ unsubscribers.push(addEvent(node, type, event));
329
+ } else {
330
+ unsubscribers.push(addEvent(node, type, event.handler, event.options));
331
+ }
332
+ }
333
+ }
334
+ for (const [attributeName, value] of Object.entries(attributes ?? {})) {
335
+ if (value != null) {
336
+ unsubscribers.push(bindAttribute(node, attributeName, utils_stores.toReadableStore(value)));
337
+ }
338
+ }
339
+ for (const [styleName, value] of Object.entries(styles ?? {})) {
340
+ if (value) {
341
+ unsubscribers.push(bindStyle(node, styleName, utils_stores.toReadableStore(value)));
342
+ }
343
+ }
344
+ for (const [className, value] of Object.entries(classNames ?? {})) {
345
+ unsubscribers.push(bindClassName(node, className, utils_stores.toReadableStore(value)));
346
+ }
347
+ return {
348
+ update: (args2) => args$.set(args2),
349
+ destroy: () => unsubscribers.forEach((fn) => fn())
350
+ };
351
+ };
352
+ const attributesData = (...directives) => {
353
+ const instances = [];
354
+ try {
355
+ const element = ssrHTMLElement();
356
+ for (const directive of directives) {
357
+ instances.push(Array.isArray(directive) ? directive[0](element, directive[1]) : directive(element));
358
+ }
359
+ return element[ssrHTMLElementAttributesAndStyle]();
360
+ } finally {
361
+ instances.forEach((instance) => {
362
+ var _a;
363
+ return (_a = instance == null ? void 0 : instance.destroy) == null ? void 0 : _a.call(instance);
364
+ });
365
+ }
366
+ };
367
+ const classDirective = createAttributesDirective((className) => ({ attributes: { class: className } }));
368
+ function directiveAttributes(...directives) {
369
+ const { attributes, classNames, style } = attributesData(...directives);
370
+ if (classNames.length) {
371
+ attributes["class"] = classNames.join(" ");
372
+ }
373
+ const stringStyle = Object.entries(style).filter(([, value]) => !!value).map(([name, value]) => `${name}: ${value};`).join("");
374
+ if (stringStyle.length) {
375
+ attributes["style"] = stringStyle;
376
+ }
377
+ return attributes;
378
+ }
379
+ const ssrAttributes = esmEnv.BROWSER ? () => ({}) : directiveAttributes;
380
+ exports.addClasses = addClasses;
381
+ exports.addEvent = addEvent;
382
+ exports.attributesData = attributesData;
383
+ exports.bindDirective = bindDirective;
384
+ exports.bindDirectiveNoArg = bindDirectiveNoArg;
385
+ exports.browserDirective = browserDirective;
386
+ exports.classDirective = classDirective;
387
+ exports.computeCommonAncestor = computeCommonAncestor;
388
+ exports.createAttributesDirective = createAttributesDirective;
389
+ exports.createBrowserStoreArrayDirective = createBrowserStoreArrayDirective;
390
+ exports.createBrowserStoreDirective = createBrowserStoreDirective;
391
+ exports.createStoreArrayDirective = createStoreArrayDirective;
392
+ exports.createStoreDirective = createStoreDirective;
393
+ exports.directiveAttributes = directiveAttributes;
394
+ exports.directiveSubscribe = directiveSubscribe;
395
+ exports.directiveUpdate = directiveUpdate;
396
+ exports.generateId = generateId;
397
+ exports.isBrowserHTMLElement = isBrowserHTMLElement;
398
+ exports.mapDirectiveArg = mapDirectiveArg;
399
+ exports.mergeDirectives = mergeDirectives;
400
+ exports.multiDirective = multiDirective;
401
+ exports.reflow = reflow;
402
+ exports.registrationArray = registrationArray;
403
+ exports.removeClasses = removeClasses;
404
+ exports.ssrAttributes = ssrAttributes;