@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
package/utils/stores.js CHANGED
@@ -1,298 +1,163 @@
1
- import { asReadable, asWritable, batch, computed, derived, equal as tansuDefaultEqual, get, readable, writable } from '@amadeus-it-group/tansu';
2
- import { INVALID_VALUE } from '../types';
3
- import { identity } from './internal/func';
4
- /**
5
- *
6
- * Utility function designed to create a `patch` function related to the provided stores.
7
- * Any key given to the patch function which is not in the original object will be ignored.
8
- *
9
- * @example
10
- *
11
- * ```typescript
12
- * const storeA$ = writable(1);
13
- * const storeB$ = writable(1);
14
- * const patch = createPatch({a: storeA$, b: storeB$});
15
- *
16
- * patch({a: 2}) // will perform storeA$.set(2)
17
- * patch({a: 2, b: 2}) // will perform storeA$.set(2) and storeB$.set(2) in the same batch.
18
- * patch({a: 2, c: 2}) // will perform storeA$.set(2), c is ignored.
19
- *
20
- * ```
21
- * @param stores - object of stores
22
- * @returns the patch function
23
- */
24
- export function createPatch(stores) {
25
- return function (storesValues) {
26
- batch(() => {
27
- for (const [name, value] of Object.entries(storesValues ?? {})) {
28
- stores[`${name}$`]?.set(value);
29
- }
30
- });
31
- };
1
+ import { batch, computed, asWritable, readable, writable, asReadable, get, derived, equal } from "@amadeus-it-group/tansu";
2
+ import { INVALID_VALUE } from "../types.js";
3
+ import { i as identity } from "../func-DR0n-ShK.js";
4
+ function createPatch(stores) {
5
+ return function(storesValues) {
6
+ batch(() => {
7
+ var _a;
8
+ for (const [name, value] of Object.entries(storesValues ?? {})) {
9
+ (_a = stores[`${name}$`]) == null ? void 0 : _a.set(value);
10
+ }
11
+ });
12
+ };
32
13
  }
33
- /**
34
- * This utility function is designed to compare the first level of two objects.
35
- *
36
- * It returns a new object which has all the keys for which the values in `obj1`
37
- * and `obj2` are different, with the values from `obj2`, or null if objects
38
- * are identical.
39
- *
40
- * @param obj1 - First object
41
- * @param obj2 - Second object
42
- * @returns the object with changed properties
43
- */
44
- export function findChangedProperties(obj1, obj2) {
45
- if (obj1 === obj2) {
46
- return null;
47
- }
48
- let hasUpdate = false;
49
- const changedValues = {};
50
- const keys = new Set([...Object.keys(obj1), ...Object.keys(obj2)]);
51
- for (const key of keys) {
52
- const value = obj2[key];
53
- if (obj1[key] !== value) {
54
- changedValues[key] = value;
55
- hasUpdate = true;
56
- }
14
+ function findChangedProperties(obj1, obj2) {
15
+ if (obj1 === obj2) {
16
+ return null;
17
+ }
18
+ let hasUpdate = false;
19
+ const changedValues = {};
20
+ const keys = /* @__PURE__ */ new Set([...Object.keys(obj1), ...Object.keys(obj2)]);
21
+ for (const key of keys) {
22
+ const value = obj2[key];
23
+ if (obj1[key] !== value) {
24
+ changedValues[key] = value;
25
+ hasUpdate = true;
57
26
  }
58
- return hasUpdate ? changedValues : null;
27
+ }
28
+ return hasUpdate ? changedValues : null;
59
29
  }
60
- /**
61
- * Returns a writable store whose value is either its own value (when it is not undefined) or a default value
62
- * that comes either from the `config$` store (when it is not undefined) or from `defValue`.
63
- * If a normalizeValue function is passed in the options, it is called to normalize non-undefined values coming
64
- * either from the `config$` store or from the `set` or `update` functions. If a value is invalid (i.e. normalizeValue
65
- * returns the `invalidValue` symbol), an error is logged on the console and it is either not set (if it comes from the
66
- * `set` or `update` functions), or the `defValue` is used instead (if the invalid value comes from the `config$` store).
67
- *
68
- * @param defValue - Default value used when both the own value and the config$ value are undefined.
69
- * @param config$ - Store containing the default value used when the own value is undefined
70
- * @param options - Object which can contain the following optional functions: normalizeValue and equal
71
- * @param own$ - Store containing the own value
72
- * @returns a writable store with the extra default value and normalization logic described above
73
- */
74
- export function writableWithDefault(defValue, config$ = readable(undefined), options = {}, own$ = writable(undefined)) {
75
- const { normalizeValue = identity, equal = Object.is } = options;
76
- const getDefValue = () => defValue;
77
- const callNormalizeValue = (value, defValue = getDefValue) => {
78
- const normalizedValue = value === undefined ? undefined : normalizeValue(value);
79
- if (normalizedValue === INVALID_VALUE) {
80
- console.error('Not using invalid value', value);
81
- return defValue();
82
- }
83
- if (normalizedValue === undefined) {
84
- return defValue();
85
- }
86
- return normalizedValue;
87
- };
88
- const validatedDefConfig$ = computed(() => callNormalizeValue(config$()), { equal });
89
- const validatedOwnValue$ = computed(() => callNormalizeValue(own$(), validatedDefConfig$), { equal });
90
- return asWritable(validatedOwnValue$, (value) => {
91
- if (value !== undefined) {
92
- const normalizedValue = normalizeValue(value);
93
- if (normalizedValue === INVALID_VALUE) {
94
- console.error('Not setting invalid value', value);
95
- return;
96
- }
97
- value = normalizedValue;
98
- }
99
- own$.set(value);
100
- });
101
- }
102
- /**
103
- * Returns true if the provided argument is a store (ReadableSignal).
104
- * @param x - argument that is tested
105
- * @returns true if the argument is a store (ReadableSignal)
106
- */
107
- export const isStore = (x) => !!(x && typeof x === 'function' && 'subscribe' in x);
108
- /**
109
- * If the provided argument is already a store, it is returned as is, otherwise, a readable store is created with the provided argument as its initial value.
110
- * @param x - either a store or a simple value
111
- * @returns either x if x is already a store, or readable(x) otherwise
112
- */
113
- export const toReadableStore = (x) => (isStore(x) ? x : readable(x));
114
- /**
115
- * If the provided argument is already a store, it is returned as is, otherwise, a writable store is created with the provided argument as its initial value.
116
- * @param x - either a writable store or a simple value
117
- * @returns either x if x is already a store, or writable(x) otherwise
118
- */
119
- export const toWritableStore = (x) => (isStore(x) ? x : writable(x));
120
- /**
121
- * Extract and normalize config stores.
122
- *
123
- * @param keys - the keys of the stores to extract / normalize
124
- * @param config - the config stores
125
- * @returns the normalized config stores
126
- */
127
- export const normalizeConfigStores = (keys, config) => {
128
- const res = {};
129
- if (config) {
130
- const configIsStore = isStore(config);
131
- for (const key of keys) {
132
- res[key] = configIsStore
133
- ? computed(() => config()[key])
134
- : toReadableStore(config[key]);
135
- }
30
+ function writableWithDefault(defValue, config$ = readable(void 0), options = {}, own$ = writable(void 0)) {
31
+ const { normalizeValue = identity, equal: equal2 = Object.is } = options;
32
+ const getDefValue = () => defValue;
33
+ const callNormalizeValue = (value, defValue2 = getDefValue) => {
34
+ const normalizedValue = value === void 0 ? void 0 : normalizeValue(value);
35
+ if (normalizedValue === INVALID_VALUE) {
36
+ console.error("Not using invalid value", value);
37
+ return defValue2();
136
38
  }
137
- return res;
138
- };
139
- /**
140
- * Merge two stores configs into one
141
- *
142
- * @param keys - the keys of the stores to extract and merge from the two provided configs
143
- * @param config1 - the first config
144
- * @param config2 - the second config
145
- * @returns the merged config
146
- */
147
- export const mergeConfigStores = (keys, config1, config2) => {
148
- const res = {};
149
- for (const key of keys) {
150
- const config1Store = config1?.[key];
151
- const config2Store = config2?.[key];
152
- res[key] = config1Store && config2Store ? computed(() => config1Store() ?? config2Store()) : config1Store || config2Store;
39
+ if (normalizedValue === void 0) {
40
+ return defValue2();
153
41
  }
154
- return res;
155
- };
156
- /**
157
- * Returns an object containing, for each property of `defConfig`, a corresponding writable with the normalization and default value logic
158
- * described in {@link writableWithDefault}. Keys in the returned object are the same as the ones present in `defConfig`,
159
- * with the exta `$` suffix (showing that they are stores).
160
- *
161
- * @param defConfig - object containing, for each property, a default value to use in case `config$` does not provide the suitable default
162
- * value for that property
163
- * @param propsConfig - object defining the config and props
164
- * @param options - object containing, for each property of `defConfig`, an optional object with the following optional functions: normalizeValue and equal
165
- * @returns an object containing writables
166
- *
167
- * @example With a store
168
- * ```ts
169
- * const defConfig = {propA: 1};
170
- * const validation = {propA: {normalizeValue: value => +value}};
171
- * const config = writable({propA: 5});
172
- * const {propA$} = writablesWithDefault(defConfig, {config}, validation);
173
- * ```
174
- *
175
- * @example With an object containing a value and a store
176
- * ```ts
177
- * const defConfig = {propA: 1, propB: 2};
178
- * const validation = {propA: {normalizeValue: value => +value}};
179
- * const config = {propA: 5, propB: writable(3)};
180
- * const {propA$, propB$} = writablesWithDefault(defConfig, {config}, validation);
181
- * ```
182
- */
183
- export const writablesWithDefault = (defConfig, propsConfig, options) => {
184
- const res = {};
185
- const keys = Object.keys(defConfig);
186
- const configStores = normalizeConfigStores(keys, propsConfig?.config);
187
- const props = propsConfig?.props;
42
+ return normalizedValue;
43
+ };
44
+ const validatedDefConfig$ = computed(() => callNormalizeValue(config$()), { equal: equal2 });
45
+ const validatedOwnValue$ = computed(() => callNormalizeValue(own$(), validatedDefConfig$), { equal: equal2 });
46
+ return asWritable(validatedOwnValue$, (value) => {
47
+ if (value !== void 0) {
48
+ const normalizedValue = normalizeValue(value);
49
+ if (normalizedValue === INVALID_VALUE) {
50
+ console.error("Not setting invalid value", value);
51
+ return;
52
+ }
53
+ value = normalizedValue;
54
+ }
55
+ own$.set(value);
56
+ });
57
+ }
58
+ const isStore = (x) => !!(x && typeof x === "function" && "subscribe" in x);
59
+ const toReadableStore = (x) => isStore(x) ? x : readable(x);
60
+ const toWritableStore = (x) => isStore(x) ? x : writable(x);
61
+ const normalizeConfigStores = (keys, config) => {
62
+ const res = {};
63
+ if (config) {
64
+ const configIsStore = isStore(config);
188
65
  for (const key of keys) {
189
- const propValue = props?.[key];
190
- res[`${key}$`] = writableWithDefault(defConfig[key], configStores[key], options?.[key], toWritableStore(propValue));
66
+ res[key] = configIsStore ? computed(() => config()[key]) : toReadableStore(config[key]);
191
67
  }
192
- return res;
68
+ }
69
+ return res;
193
70
  };
194
- /**
195
- * Shortcut for calling both {@link writablesWithDefault} and {@link createPatch} in one call.
196
- * @param defConfig - object containing, for each property, a default value to use in case `config` does not provide the suitable default
197
- * value for that property
198
- * @param propsConfig - either a store of objects containing, for each property of `defConfig`, the default value or an object containing
199
- * for each property of `defConfig` either a store containing the default value or the default value itself
200
- * @param options - object containing, for each property of `defConfig`, an optional object with the following optional functions: normalizeValue and equal
201
- * @returns an array with two items: the first one containing the writables (returned by {@link writablesWithDefault}),
202
- * and the second one containing the patch function (returned by {@link createPatch})
203
- *
204
- * @example With a store
205
- * ```ts
206
- * const defConfig = {propA: 1};
207
- * const validation = {propA: {normalizeValue: value => +value}};
208
- * const config$ = writable({propA: 5});
209
- * const [{propA$}, patch] = writablesForProps(defConfig, config$, validation);
210
- * ```
211
- *
212
- * @example With an object containing a value and a store
213
- * ```ts
214
- * const defConfig = {propA: 1, propB: 2};
215
- * const validation = {propA: {normalizeValue: value => +value}};
216
- * const config = {propA: 5, propB: writable(3)};
217
- * const [{propA$, propB$}, patch] = writablesForProps(defConfig, config, validation);
218
- * ```
219
- */
220
- export const writablesForProps = (defConfig, propsConfig, options) => {
221
- const stores = writablesWithDefault(defConfig, propsConfig, options);
222
- return [stores, createPatch(stores)];
71
+ const mergeConfigStores = (keys, config1, config2) => {
72
+ const res = {};
73
+ for (const key of keys) {
74
+ const config1Store = config1 == null ? void 0 : config1[key];
75
+ const config2Store = config2 == null ? void 0 : config2[key];
76
+ res[key] = config1Store && config2Store ? computed(() => config1Store() ?? config2Store()) : config1Store || config2Store;
77
+ }
78
+ return res;
223
79
  };
224
- /**
225
- * Using input stores, this function builds an object containing the stores as readable and a global state.
226
- *
227
- * @param inputStores - the input stores
228
- * @returns the object containing the stores as readable and the global state
229
- */
230
- export const stateStores = (inputStores) => {
231
- const storesNames = [];
232
- const storesArray = [];
233
- const stores = {};
234
- for (const key of Object.keys(inputStores)) {
235
- if (key.endsWith('$')) {
236
- const store = inputStores[key];
237
- storesNames.push(key.substring(0, key.length - 1));
238
- storesArray.push(store);
239
- stores[key] = asReadable(store);
240
- }
80
+ const writablesWithDefault = (defConfig, propsConfig, options) => {
81
+ const res = {};
82
+ const keys = Object.keys(defConfig);
83
+ const configStores = normalizeConfigStores(keys, propsConfig == null ? void 0 : propsConfig.config);
84
+ const props = propsConfig == null ? void 0 : propsConfig.props;
85
+ for (const key of keys) {
86
+ const propValue = props == null ? void 0 : props[key];
87
+ res[`${key}$`] = writableWithDefault(defConfig[key], configStores[key], options == null ? void 0 : options[key], toWritableStore(propValue));
88
+ }
89
+ return res;
90
+ };
91
+ const writablesForProps = (defConfig, propsConfig, options) => {
92
+ const stores = writablesWithDefault(defConfig, propsConfig, options);
93
+ return [stores, createPatch(stores)];
94
+ };
95
+ const stateStores = (inputStores) => {
96
+ const storesNames = [];
97
+ const storesArray = [];
98
+ const stores = {};
99
+ for (const [key, store] of Object.entries(inputStores)) {
100
+ if (key.endsWith("$")) {
101
+ storesNames.push(key.substring(0, key.length - 1));
102
+ storesArray.push(store);
103
+ stores[key] = asReadable(store);
241
104
  }
242
- return {
243
- stores,
244
- state$: computed(() => {
245
- const values = storesArray.map(get);
246
- const res = {};
247
- storesNames.forEach((name, index) => {
248
- res[name] = values[index];
249
- });
250
- return res;
251
- }),
252
- };
105
+ }
106
+ return {
107
+ stores,
108
+ state$: computed(() => {
109
+ const values = storesArray.map(get);
110
+ const res = {};
111
+ storesNames.forEach((name, index) => {
112
+ res[name] = values[index];
113
+ });
114
+ return res;
115
+ })
116
+ };
253
117
  };
254
- /**
255
- * Creates a derived store that binds to multiple stores and triggers a callback when the value changes for any reason.
256
- * @param onChange$ - A readable signal containing a callback function to execute when the value changes.
257
- * @param stores - An array of Svelte stores, with the main store at index 0.
258
- * @param adjustValue - A function to adjust the value of the main store. By default, the value of the main store is returned.
259
- * @param equal - A function to determine if two values are equal. Used to compare the ajusted value with the current one.
260
- * @returns The derived store that reflects the combined state of the input stores.
261
- */
262
- export const bindableDerived = (onChange$, stores, adjustValue = (arg) => arg[0], equal = (currentValue, newValue) => newValue === currentValue) => {
263
- let currentValue = stores[0]();
264
- return asWritable(derived(stores, {
265
- derive(values) {
266
- const newValue = adjustValue(values);
267
- const rectifiedValue = !equal(values[0], newValue);
268
- if (rectifiedValue) {
269
- stores[0].set(newValue);
270
- }
271
- if (rectifiedValue || !equal(currentValue, newValue)) {
272
- currentValue = newValue;
273
- // TODO check if we should do this async to avoid issue
274
- // with angular and react only when rectifiedValue is true?
275
- onChange$()(newValue);
276
- }
277
- return newValue;
278
- },
279
- equal,
280
- }), stores[0].set.bind(stores[0]));
118
+ const bindableDerived = (onChange$, stores, adjustValue = (arg) => arg[0], equal2 = (currentValue, newValue) => newValue === currentValue) => {
119
+ let currentValue = stores[0]();
120
+ return asWritable(
121
+ derived(stores, {
122
+ derive(values) {
123
+ const newValue = adjustValue(values);
124
+ const rectifiedValue = !equal2(values[0], newValue);
125
+ if (rectifiedValue) {
126
+ stores[0].set(newValue);
127
+ }
128
+ if (rectifiedValue || !equal2(currentValue, newValue)) {
129
+ currentValue = newValue;
130
+ onChange$()(newValue);
131
+ }
132
+ return newValue;
133
+ },
134
+ equal: equal2
135
+ }),
136
+ stores[0].set.bind(stores[0])
137
+ );
281
138
  };
282
- /**
283
- * Creates a computed store that contains the adjusted value of the given store and that triggers a callback when the value changes from the set or update
284
- * method of the returned writable store.
285
- * @param store$ - store to be bound
286
- * @param onChange$ - A readable signal containing a callback function to execute when the value changes from the set or update method of the returned writable store.
287
- * @param adjustValue - A function to adjust the value of the store, called in a reactive context each time the value changes or any called dependency changes.
288
- * By default, the value of store$ is returned.
289
- * @param equal - A function to determine if two values are equal.
290
- * @returns A writable store that contains the adjusted value of the given store, with the set or update functions that trigger the onChange$ callback.
291
- */
292
- export const bindableProp = (store$, onChange$, adjustValue = identity, equal = tansuDefaultEqual) => asWritable(computed(() => adjustValue(store$()), { equal }), (newValue) => {
139
+ const bindableProp = (store$, onChange$, adjustValue = identity, equal$1 = equal) => asWritable(
140
+ computed(() => adjustValue(store$()), { equal: equal$1 }),
141
+ (newValue) => {
293
142
  const adjustedValue = adjustValue(newValue);
294
- if (!equal(store$(), adjustedValue)) {
295
- store$.set(adjustedValue);
296
- onChange$()(adjustedValue);
143
+ if (!equal$1(store$(), adjustedValue)) {
144
+ store$.set(adjustedValue);
145
+ onChange$()(adjustedValue);
297
146
  }
298
- });
147
+ }
148
+ );
149
+ export {
150
+ bindableDerived,
151
+ bindableProp,
152
+ createPatch,
153
+ findChangedProperties,
154
+ isStore,
155
+ mergeConfigStores,
156
+ normalizeConfigStores,
157
+ stateStores,
158
+ toReadableStore,
159
+ toWritableStore,
160
+ writableWithDefault,
161
+ writablesForProps,
162
+ writablesWithDefault
163
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils_writables = require("../writables-D46sFgGK.cjs");
4
+ require("../types.cjs");
5
+ exports.testToNormalizeValue = utils_writables.testToNormalizeValue;
6
+ exports.typeArray = utils_writables.typeArray;
7
+ exports.typeBoolean = utils_writables.typeBoolean;
8
+ exports.typeBooleanOrNull = utils_writables.typeBooleanOrNull;
9
+ exports.typeFunction = utils_writables.typeFunction;
10
+ exports.typeHTMLElementOrNull = utils_writables.typeHTMLElementOrNull;
11
+ exports.typeNumber = utils_writables.typeNumber;
12
+ exports.typeNumberInRangeFactory = utils_writables.typeNumberInRangeFactory;
13
+ exports.typeString = utils_writables.typeString;
@@ -1,72 +1,13 @@
1
- import { allowNull, clamp, isArray, isBoolean, isFunction, isHTMLElement, isNumber, isString } from './internal/checks';
2
- import { INVALID_VALUE } from '../types';
3
- /**
4
- * Check if a value respects a provided type guard.
5
- *
6
- * @param filter - the guard function
7
- * @returns a function that takes a value as input, checks if it respects the type guard and returns `INVALID_VALUE` otherwise
8
- */
9
- export const testToNormalizeValue = (filter) => (value) => filter(value) ? value : INVALID_VALUE;
10
- const numberNormalizeFn = testToNormalizeValue(isNumber);
11
- export const typeNumber = {
12
- normalizeValue: numberNormalizeFn,
13
- };
14
- /**
15
- * Factory function for creating a type constraint for numbers within a specified range.
16
- *
17
- * @param min - The minimum value.
18
- * @param max - The maximum value.
19
- * @param options - Additional options to customize the behavior.
20
- *
21
- * @returns A type guard function that returns the clamp value or INVALID_VALUE depending on the provided options.
22
- */
23
- export function typeNumberInRangeFactory(min, max, options = {}) {
24
- const { strict = false, useClamp = true } = options;
25
- return {
26
- normalizeValue: (value) => {
27
- let normalizedNumber = numberNormalizeFn(value);
28
- if (normalizedNumber !== INVALID_VALUE) {
29
- if (!strict && useClamp) {
30
- normalizedNumber = clamp(normalizedNumber, max, min);
31
- }
32
- if (normalizedNumber >= min && normalizedNumber <= max) {
33
- if (!strict || (normalizedNumber !== min && normalizedNumber !== max)) {
34
- return normalizedNumber;
35
- }
36
- }
37
- }
38
- return INVALID_VALUE;
39
- },
40
- };
41
- }
42
- export const typeBoolean = {
43
- normalizeValue: testToNormalizeValue(isBoolean),
44
- };
45
- export const typeBooleanOrNull = {
46
- normalizeValue: testToNormalizeValue(allowNull(isBoolean)),
47
- };
48
- export const typeString = {
49
- normalizeValue: testToNormalizeValue(isString),
50
- };
51
- export const typeFunction = {
52
- normalizeValue: testToNormalizeValue(isFunction),
53
- equal: Object.is,
54
- };
55
- export const typeHTMLElementOrNull = {
56
- normalizeValue: testToNormalizeValue(allowNull(isHTMLElement)),
57
- equal: Object.is,
58
- };
59
- export const typeArray = {
60
- normalizeValue: testToNormalizeValue(isArray),
61
- equal: (a, b) => {
62
- if (a === b) {
63
- return true;
64
- }
65
- else {
66
- if (a?.length !== b?.length) {
67
- return false;
68
- }
69
- return a.every((val, index) => val === b[index]);
70
- }
71
- },
1
+ import { t, h, c, d, f, g, a, b, e } from "../writables-DoU_XYTX.js";
2
+ import "../types.js";
3
+ export {
4
+ t as testToNormalizeValue,
5
+ h as typeArray,
6
+ c as typeBoolean,
7
+ d as typeBooleanOrNull,
8
+ f as typeFunction,
9
+ g as typeHTMLElementOrNull,
10
+ a as typeNumber,
11
+ b as typeNumberInRangeFactory,
12
+ e as typeString
72
13
  };
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ const types = require("./types.cjs");
3
+ function isNumber(value) {
4
+ return typeof value === "number" && !isNaN(value) && Number.isFinite(value);
5
+ }
6
+ function isBoolean(value) {
7
+ return value === true || value === false;
8
+ }
9
+ function isFunction(value) {
10
+ return typeof value === "function";
11
+ }
12
+ function isString(value) {
13
+ return typeof value === "string";
14
+ }
15
+ const isArray = Array.isArray;
16
+ function clamp(value, max, min = 0) {
17
+ return Math.max(Math.min(value, max), min);
18
+ }
19
+ const isHTMLElement = (value) => value instanceof HTMLElement;
20
+ const allowNull = (isType) => (value) => value === null || isType(value);
21
+ const testToNormalizeValue = (filter) => (value) => filter(value) ? value : types.INVALID_VALUE;
22
+ const numberNormalizeFn = testToNormalizeValue(isNumber);
23
+ const typeNumber = {
24
+ normalizeValue: numberNormalizeFn
25
+ };
26
+ function typeNumberInRangeFactory(min, max, options = {}) {
27
+ const { strict = false, useClamp = true } = options;
28
+ return {
29
+ normalizeValue: (value) => {
30
+ let normalizedNumber = numberNormalizeFn(value);
31
+ if (normalizedNumber !== types.INVALID_VALUE) {
32
+ if (!strict && useClamp) {
33
+ normalizedNumber = clamp(normalizedNumber, max, min);
34
+ }
35
+ if (normalizedNumber >= min && normalizedNumber <= max) {
36
+ if (!strict || normalizedNumber !== min && normalizedNumber !== max) {
37
+ return normalizedNumber;
38
+ }
39
+ }
40
+ }
41
+ return types.INVALID_VALUE;
42
+ }
43
+ };
44
+ }
45
+ const typeBoolean = {
46
+ normalizeValue: testToNormalizeValue(isBoolean)
47
+ };
48
+ const typeBooleanOrNull = {
49
+ normalizeValue: testToNormalizeValue(allowNull(isBoolean))
50
+ };
51
+ const typeString = {
52
+ normalizeValue: testToNormalizeValue(isString)
53
+ };
54
+ const typeFunction = {
55
+ normalizeValue: testToNormalizeValue(isFunction),
56
+ equal: Object.is
57
+ };
58
+ const typeHTMLElementOrNull = {
59
+ normalizeValue: testToNormalizeValue(allowNull(isHTMLElement)),
60
+ equal: Object.is
61
+ };
62
+ const typeArray = {
63
+ normalizeValue: testToNormalizeValue(isArray),
64
+ equal: (a, b) => {
65
+ if (a === b) {
66
+ return true;
67
+ } else {
68
+ if ((a == null ? void 0 : a.length) !== (b == null ? void 0 : b.length)) {
69
+ return false;
70
+ }
71
+ return a.every((val, index) => val === b[index]);
72
+ }
73
+ }
74
+ };
75
+ exports.clamp = clamp;
76
+ exports.isNumber = isNumber;
77
+ exports.testToNormalizeValue = testToNormalizeValue;
78
+ exports.typeArray = typeArray;
79
+ exports.typeBoolean = typeBoolean;
80
+ exports.typeBooleanOrNull = typeBooleanOrNull;
81
+ exports.typeFunction = typeFunction;
82
+ exports.typeHTMLElementOrNull = typeHTMLElementOrNull;
83
+ exports.typeNumber = typeNumber;
84
+ exports.typeNumberInRangeFactory = typeNumberInRangeFactory;
85
+ exports.typeString = typeString;