@agnos-ui/core 0.2.0 → 0.3.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 (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
@@ -0,0 +1,84 @@
1
+ import { i as clamp, a as typeNumber, e as typeString, f as typeFunction } from "./writables-DoU_XYTX.js";
2
+ import { writablesForProps, stateStores } from "./utils/stores.js";
3
+ import { computed } from "@amadeus-it-group/tansu";
4
+ import { n as createAttributesDirective } from "./directive-DCYlDznf.js";
5
+ const defaultConfig = {
6
+ min: 0,
7
+ max: 100,
8
+ value: 0,
9
+ ariaLabel: "Progressbar",
10
+ className: "",
11
+ ariaValueTextFn: () => void 0
12
+ };
13
+ function getProgressbarDefaultConfig() {
14
+ return { ...defaultConfig };
15
+ }
16
+ const configValidator = {
17
+ min: typeNumber,
18
+ max: typeNumber,
19
+ value: typeNumber,
20
+ ariaLabel: typeString,
21
+ className: typeString,
22
+ ariaValueTextFn: typeFunction
23
+ };
24
+ function createProgressbar(config) {
25
+ const [
26
+ {
27
+ // dirty inputs that need adjustment:
28
+ max$: _dirtyMaximum$,
29
+ value$: _dirtyValue$,
30
+ // clean inputs
31
+ min$,
32
+ ariaValueTextFn$,
33
+ ariaLabel$,
34
+ ...stateProps
35
+ },
36
+ patch
37
+ ] = writablesForProps(defaultConfig, config, configValidator);
38
+ const max$ = computed(() => Math.max(min$(), _dirtyMaximum$()));
39
+ const value$ = computed(() => clamp(_dirtyValue$(), max$(), min$()));
40
+ const percentage$ = computed(() => {
41
+ const max = max$();
42
+ const min = min$();
43
+ if (max > min) {
44
+ return clamp((value$() - min) * 100 / (max - min), 100, 0);
45
+ } else {
46
+ return 0;
47
+ }
48
+ });
49
+ const started$ = computed(() => value$() > min$());
50
+ const finished$ = computed(() => value$() === max$());
51
+ const ariaValueText$ = computed(() => ariaValueTextFn$()(value$(), min$(), max$()));
52
+ return {
53
+ ...stateStores({
54
+ min$,
55
+ max$,
56
+ value$,
57
+ percentage$,
58
+ started$,
59
+ finished$,
60
+ ariaValueText$,
61
+ ariaLabel$,
62
+ ...stateProps
63
+ }),
64
+ patch,
65
+ api: {},
66
+ directives: {
67
+ ariaDirective: createAttributesDirective(() => ({
68
+ attributes: {
69
+ role: "progressbar",
70
+ "aria-label": ariaLabel$,
71
+ "aria-valuenow": value$,
72
+ "aria-valuemin": min$,
73
+ "aria-valuemax": max$,
74
+ "aria-valuetext": ariaValueText$
75
+ }
76
+ }))
77
+ },
78
+ actions: {}
79
+ };
80
+ }
81
+ export {
82
+ createProgressbar as c,
83
+ getProgressbarDefaultConfig as g
84
+ };
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ const tansu = require("@amadeus-it-group/tansu");
3
+ const func = require("./func-Qd3cD9a3.cjs");
4
+ const promisePending = { status: "pending" };
5
+ const isThenable = (value) => {
6
+ const type = typeof value;
7
+ return type === "object" && value !== null || type === "function" ? typeof value.then === "function" : false;
8
+ };
9
+ const createPromiseStateStore = (promise) => {
10
+ const store = tansu.writable(promisePending);
11
+ Promise.resolve(promise).then(
12
+ (value) => store.set({ status: "fulfilled", value }),
13
+ (reason) => store.set({ status: "rejected", reason })
14
+ );
15
+ return tansu.asReadable(store);
16
+ };
17
+ const promiseWeakMap = /* @__PURE__ */ new WeakMap();
18
+ const promiseStateStore = (value) => {
19
+ if (!isThenable(value)) {
20
+ return tansu.readable({ status: "fulfilled", value });
21
+ }
22
+ let response = promiseWeakMap.get(value);
23
+ if (!response) {
24
+ response = createPromiseStateStore(value);
25
+ promiseWeakMap.set(value, response);
26
+ }
27
+ return response;
28
+ };
29
+ const promiseStateStoreEqual = (a, b) => Object.is(a, b) || a.status === b.status && (a.status !== "fulfilled" || tansu.equal(a.value, b.value)) && (a.status !== "rejected" || tansu.equal(a.reason, b.reason));
30
+ const promiseStoreToPromiseStateStore = (promiseStore$) => tansu.computed(() => promiseStateStore(promiseStore$())(), { equal: promiseStateStoreEqual });
31
+ const promiseStateStoreToValueStore = (store$, initialValue, equal2) => tansu.derived(
32
+ store$,
33
+ {
34
+ derive: (state, set) => {
35
+ if (state.status === "fulfilled") {
36
+ set(state.value);
37
+ }
38
+ },
39
+ equal: equal2
40
+ },
41
+ initialValue
42
+ );
43
+ const promiseStoreToValueStore = (promiseStore$, initialValue, equal2) => promiseStateStoreToValueStore(promiseStoreToPromiseStateStore(promiseStore$), initialValue, equal2);
44
+ const truthyValue = (value) => !!value;
45
+ const promiseFromStore = (store, condition = truthyValue) => {
46
+ let resolve;
47
+ const promise = new Promise((r) => resolve = r);
48
+ let unsubscribe = () => {
49
+ storeUnsubscribe();
50
+ unsubscribe = func.noop;
51
+ };
52
+ let storeUnsubscribe = func.noop;
53
+ storeUnsubscribe = store.subscribe((value) => {
54
+ if (condition(value)) {
55
+ resolve(value);
56
+ unsubscribe();
57
+ }
58
+ });
59
+ if (unsubscribe === func.noop) {
60
+ storeUnsubscribe();
61
+ }
62
+ return {
63
+ promise,
64
+ unsubscribe() {
65
+ unsubscribe();
66
+ }
67
+ };
68
+ };
69
+ const promiseFromEvent = (element, event) => {
70
+ let resolve;
71
+ const promise = new Promise((r) => resolve = r);
72
+ let unsubscribe = () => {
73
+ element.removeEventListener(event, eventListener);
74
+ unsubscribe = func.noop;
75
+ };
76
+ const eventListener = (event2) => {
77
+ if (event2.target === element) {
78
+ resolve(event2);
79
+ unsubscribe();
80
+ }
81
+ };
82
+ element.addEventListener(event, eventListener);
83
+ return {
84
+ promise,
85
+ unsubscribe() {
86
+ unsubscribe();
87
+ }
88
+ };
89
+ };
90
+ const promiseFromTimeout = (delay) => {
91
+ let timeout;
92
+ return {
93
+ promise: new Promise((r) => {
94
+ timeout = setTimeout(() => {
95
+ timeout = void 0;
96
+ r();
97
+ }, delay);
98
+ }),
99
+ unsubscribe() {
100
+ if (timeout) {
101
+ clearTimeout(timeout);
102
+ timeout = void 0;
103
+ }
104
+ }
105
+ };
106
+ };
107
+ const promiseWithResolve = () => {
108
+ let resolve;
109
+ const promise = new Promise((r) => {
110
+ resolve = r;
111
+ });
112
+ return { promise, resolve };
113
+ };
114
+ exports.promiseFromEvent = promiseFromEvent;
115
+ exports.promiseFromStore = promiseFromStore;
116
+ exports.promiseFromTimeout = promiseFromTimeout;
117
+ exports.promiseStoreToValueStore = promiseStoreToValueStore;
118
+ exports.promiseWithResolve = promiseWithResolve;
@@ -0,0 +1,119 @@
1
+ import { computed, derived, readable, equal, writable, asReadable } from "@amadeus-it-group/tansu";
2
+ import { n as noop } from "./func-DR0n-ShK.js";
3
+ const promisePending = { status: "pending" };
4
+ const isThenable = (value) => {
5
+ const type = typeof value;
6
+ return type === "object" && value !== null || type === "function" ? typeof value.then === "function" : false;
7
+ };
8
+ const createPromiseStateStore = (promise) => {
9
+ const store = writable(promisePending);
10
+ Promise.resolve(promise).then(
11
+ (value) => store.set({ status: "fulfilled", value }),
12
+ (reason) => store.set({ status: "rejected", reason })
13
+ );
14
+ return asReadable(store);
15
+ };
16
+ const promiseWeakMap = /* @__PURE__ */ new WeakMap();
17
+ const promiseStateStore = (value) => {
18
+ if (!isThenable(value)) {
19
+ return readable({ status: "fulfilled", value });
20
+ }
21
+ let response = promiseWeakMap.get(value);
22
+ if (!response) {
23
+ response = createPromiseStateStore(value);
24
+ promiseWeakMap.set(value, response);
25
+ }
26
+ return response;
27
+ };
28
+ const promiseStateStoreEqual = (a, b) => Object.is(a, b) || a.status === b.status && (a.status !== "fulfilled" || equal(a.value, b.value)) && (a.status !== "rejected" || equal(a.reason, b.reason));
29
+ const promiseStoreToPromiseStateStore = (promiseStore$) => computed(() => promiseStateStore(promiseStore$())(), { equal: promiseStateStoreEqual });
30
+ const promiseStateStoreToValueStore = (store$, initialValue, equal2) => derived(
31
+ store$,
32
+ {
33
+ derive: (state, set) => {
34
+ if (state.status === "fulfilled") {
35
+ set(state.value);
36
+ }
37
+ },
38
+ equal: equal2
39
+ },
40
+ initialValue
41
+ );
42
+ const promiseStoreToValueStore = (promiseStore$, initialValue, equal2) => promiseStateStoreToValueStore(promiseStoreToPromiseStateStore(promiseStore$), initialValue, equal2);
43
+ const truthyValue = (value) => !!value;
44
+ const promiseFromStore = (store, condition = truthyValue) => {
45
+ let resolve;
46
+ const promise = new Promise((r) => resolve = r);
47
+ let unsubscribe = () => {
48
+ storeUnsubscribe();
49
+ unsubscribe = noop;
50
+ };
51
+ let storeUnsubscribe = noop;
52
+ storeUnsubscribe = store.subscribe((value) => {
53
+ if (condition(value)) {
54
+ resolve(value);
55
+ unsubscribe();
56
+ }
57
+ });
58
+ if (unsubscribe === noop) {
59
+ storeUnsubscribe();
60
+ }
61
+ return {
62
+ promise,
63
+ unsubscribe() {
64
+ unsubscribe();
65
+ }
66
+ };
67
+ };
68
+ const promiseFromEvent = (element, event) => {
69
+ let resolve;
70
+ const promise = new Promise((r) => resolve = r);
71
+ let unsubscribe = () => {
72
+ element.removeEventListener(event, eventListener);
73
+ unsubscribe = noop;
74
+ };
75
+ const eventListener = (event2) => {
76
+ if (event2.target === element) {
77
+ resolve(event2);
78
+ unsubscribe();
79
+ }
80
+ };
81
+ element.addEventListener(event, eventListener);
82
+ return {
83
+ promise,
84
+ unsubscribe() {
85
+ unsubscribe();
86
+ }
87
+ };
88
+ };
89
+ const promiseFromTimeout = (delay) => {
90
+ let timeout;
91
+ return {
92
+ promise: new Promise((r) => {
93
+ timeout = setTimeout(() => {
94
+ timeout = void 0;
95
+ r();
96
+ }, delay);
97
+ }),
98
+ unsubscribe() {
99
+ if (timeout) {
100
+ clearTimeout(timeout);
101
+ timeout = void 0;
102
+ }
103
+ }
104
+ };
105
+ };
106
+ const promiseWithResolve = () => {
107
+ let resolve;
108
+ const promise = new Promise((r) => {
109
+ resolve = r;
110
+ });
111
+ return { promise, resolve };
112
+ };
113
+ export {
114
+ promiseFromEvent as a,
115
+ promiseFromTimeout as b,
116
+ promiseWithResolve as c,
117
+ promiseFromStore as d,
118
+ promiseStoreToValueStore as p
119
+ };
@@ -0,0 +1,173 @@
1
+ import { computed, writable } from "@amadeus-it-group/tansu";
2
+ import { INVALID_VALUE } from "./types.js";
3
+ import { n as createAttributesDirective } from "./directive-DCYlDznf.js";
4
+ import { i as clamp, a as typeNumber, j as isNumber, c as typeBoolean, f as typeFunction, e as typeString } from "./writables-DoU_XYTX.js";
5
+ import { n as noop } from "./func-DR0n-ShK.js";
6
+ import { writablesForProps, bindableProp, stateStores } from "./utils/stores.js";
7
+ const defaultConfig = {
8
+ rating: 0,
9
+ tabindex: 0,
10
+ maxRating: 10,
11
+ disabled: false,
12
+ readonly: false,
13
+ resettable: true,
14
+ ariaValueTextFn: (rating, maxRating) => `${rating} out of ${maxRating}`,
15
+ onHover: noop,
16
+ onLeave: noop,
17
+ onRatingChange: noop,
18
+ className: "",
19
+ ariaLabel: "Rating",
20
+ ariaLabelledBy: ""
21
+ };
22
+ function getRatingDefaultConfig() {
23
+ return { ...defaultConfig };
24
+ }
25
+ const configValidator = {
26
+ rating: typeNumber,
27
+ tabindex: typeNumber,
28
+ maxRating: { normalizeValue: (value) => isNumber(value) ? Math.max(0, value) : INVALID_VALUE },
29
+ disabled: typeBoolean,
30
+ readonly: typeBoolean,
31
+ resettable: typeBoolean,
32
+ ariaValueTextFn: typeFunction,
33
+ onHover: typeFunction,
34
+ onLeave: typeFunction,
35
+ onRatingChange: typeFunction,
36
+ className: typeString,
37
+ ariaLabel: typeString,
38
+ ariaLabelledBy: typeString
39
+ };
40
+ function createRating(config) {
41
+ const [
42
+ {
43
+ // dirty inputs that need adjustment:
44
+ rating$: _dirtyRating$,
45
+ tabindex$: _dirtyTabindex$,
46
+ ariaValueTextFn$,
47
+ onHover$,
48
+ onLeave$,
49
+ onRatingChange$,
50
+ ...stateProps
51
+ },
52
+ patch
53
+ ] = writablesForProps(defaultConfig, config, configValidator);
54
+ const { ariaLabel$, ariaLabelledBy$, className$, disabled$, maxRating$, readonly$, resettable$ } = stateProps;
55
+ const tabindex$ = computed(() => disabled$() ? -1 : _dirtyTabindex$());
56
+ const rating$ = bindableProp(_dirtyRating$, onRatingChange$, (dirtyRating) => clamp(dirtyRating, maxRating$()));
57
+ const _hoveredRating$ = writable(0);
58
+ const interactive$ = computed(() => !disabled$() && !readonly$());
59
+ const visibleRating$ = computed(() => {
60
+ const hoveredRating = _hoveredRating$();
61
+ return hoveredRating !== 0 ? hoveredRating : rating$();
62
+ });
63
+ const ariaValueText$ = computed(() => ariaValueTextFn$()(visibleRating$(), maxRating$()));
64
+ const stars$ = computed(() => {
65
+ const visibleRating = visibleRating$();
66
+ return Array.from({ length: maxRating$() }, (_v, i) => ({
67
+ fill: Math.round(Math.max(Math.min(visibleRating - i, 1), 0) * 100),
68
+ index: i
69
+ }));
70
+ });
71
+ const widget = {
72
+ ...stateStores({
73
+ ariaValueText$,
74
+ interactive$,
75
+ rating$,
76
+ stars$,
77
+ tabindex$,
78
+ visibleRating$,
79
+ ...stateProps
80
+ }),
81
+ patch,
82
+ actions: {
83
+ click: (index) => {
84
+ if (interactive$() && index > 0 && index <= maxRating$()) {
85
+ rating$.update((rating) => rating === index && resettable$() ? 0 : index);
86
+ }
87
+ },
88
+ hover: (index) => {
89
+ if (interactive$() && index > 0 && index <= maxRating$()) {
90
+ _hoveredRating$.set(index);
91
+ onHover$()(index);
92
+ }
93
+ },
94
+ leave: () => {
95
+ if (interactive$()) {
96
+ onLeave$()(_hoveredRating$());
97
+ _hoveredRating$.set(0);
98
+ }
99
+ },
100
+ handleKey(event) {
101
+ if (interactive$()) {
102
+ const { key } = event;
103
+ switch (key) {
104
+ case "ArrowLeft":
105
+ case "ArrowDown":
106
+ rating$.update((rating) => rating - 1);
107
+ break;
108
+ case "ArrowRight":
109
+ case "ArrowUp":
110
+ rating$.update((rating) => rating + 1);
111
+ break;
112
+ case "Home":
113
+ case "PageDown":
114
+ rating$.set(0);
115
+ break;
116
+ case "End":
117
+ case "PageUp":
118
+ rating$.set(maxRating$());
119
+ break;
120
+ default:
121
+ return;
122
+ }
123
+ event.preventDefault();
124
+ event.stopPropagation();
125
+ }
126
+ }
127
+ },
128
+ directives: {
129
+ containerDirective: createAttributesDirective(() => ({
130
+ events: {
131
+ keydown: (e) => widget.actions.handleKey(e),
132
+ mouseleave: () => widget.actions.leave()
133
+ },
134
+ attributes: {
135
+ role: "slider",
136
+ class: className$,
137
+ "aria-valuemin": 0,
138
+ tabindex: tabindex$,
139
+ "aria-valuemax": maxRating$,
140
+ "aria-valuenow": visibleRating$,
141
+ "aria-valuetext": ariaValueText$,
142
+ "aria-readonly": computed(() => readonly$() ? "true" : void 0),
143
+ "aria-disabled": computed(() => disabled$() ? "true" : void 0),
144
+ "aria-label": ariaLabel$,
145
+ "aria-labelledby": computed(() => ariaLabelledBy$() || void 0)
146
+ },
147
+ classNames: {
148
+ "au-rating": true
149
+ }
150
+ })),
151
+ starDirective: createAttributesDirective((starContext$) => {
152
+ return {
153
+ events: {
154
+ mouseenter: () => widget.actions.hover(starContext$().index + 1),
155
+ click: () => widget.actions.click(starContext$().index + 1)
156
+ },
157
+ styles: {
158
+ cursor: computed(() => interactive$() ? "pointer" : "default")
159
+ },
160
+ classNames: {
161
+ "au-rating-star": true
162
+ }
163
+ };
164
+ })
165
+ },
166
+ api: {}
167
+ };
168
+ return widget;
169
+ }
170
+ export {
171
+ createRating as c,
172
+ getRatingDefaultConfig as g
173
+ };
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ const tansu = require("@amadeus-it-group/tansu");
3
+ const types = require("./types.cjs");
4
+ const utils_directive = require("./directive-BTSEYLF3.cjs");
5
+ const utils_writables = require("./writables-D46sFgGK.cjs");
6
+ const func = require("./func-Qd3cD9a3.cjs");
7
+ const utils_stores = require("./utils/stores.cjs");
8
+ const defaultConfig = {
9
+ rating: 0,
10
+ tabindex: 0,
11
+ maxRating: 10,
12
+ disabled: false,
13
+ readonly: false,
14
+ resettable: true,
15
+ ariaValueTextFn: (rating, maxRating) => `${rating} out of ${maxRating}`,
16
+ onHover: func.noop,
17
+ onLeave: func.noop,
18
+ onRatingChange: func.noop,
19
+ className: "",
20
+ ariaLabel: "Rating",
21
+ ariaLabelledBy: ""
22
+ };
23
+ function getRatingDefaultConfig() {
24
+ return { ...defaultConfig };
25
+ }
26
+ const configValidator = {
27
+ rating: utils_writables.typeNumber,
28
+ tabindex: utils_writables.typeNumber,
29
+ maxRating: { normalizeValue: (value) => utils_writables.isNumber(value) ? Math.max(0, value) : types.INVALID_VALUE },
30
+ disabled: utils_writables.typeBoolean,
31
+ readonly: utils_writables.typeBoolean,
32
+ resettable: utils_writables.typeBoolean,
33
+ ariaValueTextFn: utils_writables.typeFunction,
34
+ onHover: utils_writables.typeFunction,
35
+ onLeave: utils_writables.typeFunction,
36
+ onRatingChange: utils_writables.typeFunction,
37
+ className: utils_writables.typeString,
38
+ ariaLabel: utils_writables.typeString,
39
+ ariaLabelledBy: utils_writables.typeString
40
+ };
41
+ function createRating(config) {
42
+ const [
43
+ {
44
+ // dirty inputs that need adjustment:
45
+ rating$: _dirtyRating$,
46
+ tabindex$: _dirtyTabindex$,
47
+ ariaValueTextFn$,
48
+ onHover$,
49
+ onLeave$,
50
+ onRatingChange$,
51
+ ...stateProps
52
+ },
53
+ patch
54
+ ] = utils_stores.writablesForProps(defaultConfig, config, configValidator);
55
+ const { ariaLabel$, ariaLabelledBy$, className$, disabled$, maxRating$, readonly$, resettable$ } = stateProps;
56
+ const tabindex$ = tansu.computed(() => disabled$() ? -1 : _dirtyTabindex$());
57
+ const rating$ = utils_stores.bindableProp(_dirtyRating$, onRatingChange$, (dirtyRating) => utils_writables.clamp(dirtyRating, maxRating$()));
58
+ const _hoveredRating$ = tansu.writable(0);
59
+ const interactive$ = tansu.computed(() => !disabled$() && !readonly$());
60
+ const visibleRating$ = tansu.computed(() => {
61
+ const hoveredRating = _hoveredRating$();
62
+ return hoveredRating !== 0 ? hoveredRating : rating$();
63
+ });
64
+ const ariaValueText$ = tansu.computed(() => ariaValueTextFn$()(visibleRating$(), maxRating$()));
65
+ const stars$ = tansu.computed(() => {
66
+ const visibleRating = visibleRating$();
67
+ return Array.from({ length: maxRating$() }, (_v, i) => ({
68
+ fill: Math.round(Math.max(Math.min(visibleRating - i, 1), 0) * 100),
69
+ index: i
70
+ }));
71
+ });
72
+ const widget = {
73
+ ...utils_stores.stateStores({
74
+ ariaValueText$,
75
+ interactive$,
76
+ rating$,
77
+ stars$,
78
+ tabindex$,
79
+ visibleRating$,
80
+ ...stateProps
81
+ }),
82
+ patch,
83
+ actions: {
84
+ click: (index) => {
85
+ if (interactive$() && index > 0 && index <= maxRating$()) {
86
+ rating$.update((rating) => rating === index && resettable$() ? 0 : index);
87
+ }
88
+ },
89
+ hover: (index) => {
90
+ if (interactive$() && index > 0 && index <= maxRating$()) {
91
+ _hoveredRating$.set(index);
92
+ onHover$()(index);
93
+ }
94
+ },
95
+ leave: () => {
96
+ if (interactive$()) {
97
+ onLeave$()(_hoveredRating$());
98
+ _hoveredRating$.set(0);
99
+ }
100
+ },
101
+ handleKey(event) {
102
+ if (interactive$()) {
103
+ const { key } = event;
104
+ switch (key) {
105
+ case "ArrowLeft":
106
+ case "ArrowDown":
107
+ rating$.update((rating) => rating - 1);
108
+ break;
109
+ case "ArrowRight":
110
+ case "ArrowUp":
111
+ rating$.update((rating) => rating + 1);
112
+ break;
113
+ case "Home":
114
+ case "PageDown":
115
+ rating$.set(0);
116
+ break;
117
+ case "End":
118
+ case "PageUp":
119
+ rating$.set(maxRating$());
120
+ break;
121
+ default:
122
+ return;
123
+ }
124
+ event.preventDefault();
125
+ event.stopPropagation();
126
+ }
127
+ }
128
+ },
129
+ directives: {
130
+ containerDirective: utils_directive.createAttributesDirective(() => ({
131
+ events: {
132
+ keydown: (e) => widget.actions.handleKey(e),
133
+ mouseleave: () => widget.actions.leave()
134
+ },
135
+ attributes: {
136
+ role: "slider",
137
+ class: className$,
138
+ "aria-valuemin": 0,
139
+ tabindex: tabindex$,
140
+ "aria-valuemax": maxRating$,
141
+ "aria-valuenow": visibleRating$,
142
+ "aria-valuetext": ariaValueText$,
143
+ "aria-readonly": tansu.computed(() => readonly$() ? "true" : void 0),
144
+ "aria-disabled": tansu.computed(() => disabled$() ? "true" : void 0),
145
+ "aria-label": ariaLabel$,
146
+ "aria-labelledby": tansu.computed(() => ariaLabelledBy$() || void 0)
147
+ },
148
+ classNames: {
149
+ "au-rating": true
150
+ }
151
+ })),
152
+ starDirective: utils_directive.createAttributesDirective((starContext$) => {
153
+ return {
154
+ events: {
155
+ mouseenter: () => widget.actions.hover(starContext$().index + 1),
156
+ click: () => widget.actions.click(starContext$().index + 1)
157
+ },
158
+ styles: {
159
+ cursor: tansu.computed(() => interactive$() ? "pointer" : "default")
160
+ },
161
+ classNames: {
162
+ "au-rating-star": true
163
+ }
164
+ };
165
+ })
166
+ },
167
+ api: {}
168
+ };
169
+ return widget;
170
+ }
171
+ exports.createRating = createRating;
172
+ exports.getRatingDefaultConfig = getRatingDefaultConfig;