@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
@@ -1,182 +1,171 @@
1
- import { batch, computed, derived, writable } from '@amadeus-it-group/tansu';
2
- import { typeBoolean, typeBooleanOrNull, typeFunction } from '../../utils/writables';
3
- import { promiseWithResolve } from '../../utils/internal/promise';
4
- import { noop } from '../../utils/internal/func';
5
- import { bindableDerived, stateStores, writablesForProps } from '../../utils/stores';
6
- import { createStoreDirective, directiveSubscribe, directiveUpdate, mergeDirectives } from '../../utils/directive';
1
+ import { computed, writable, derived, batch } from "@amadeus-it-group/tansu";
2
+ import { c as typeBoolean, f as typeFunction, d as typeBooleanOrNull } from "../../writables-DoU_XYTX.js";
3
+ import { c as promiseWithResolve } from "../../promise-CY2U8bTP.js";
4
+ import { n as noop } from "../../func-DR0n-ShK.js";
5
+ import { writablesForProps, bindableDerived, stateStores } from "../../utils/stores.js";
6
+ import { h as createStoreDirective, k as mergeDirectives, d as directiveSubscribe, e as directiveUpdate } from "../../directive-DCYlDznf.js";
7
7
  const neverEndingPromise = new Promise(noop);
8
- /**
9
- * A transition to show / hide an element without any animation. It uses the HTML `display` attribute.
10
- *
11
- * @param element - the element to animate
12
- * @param direction - the direction
13
- */
14
- export const noAnimation = async (element, direction) => {
15
- element.style.display = direction === 'show' ? '' : 'none';
8
+ const noAnimation = async (element, direction) => {
9
+ element.style.display = direction === "show" ? "" : "none";
16
10
  };
17
11
  const defaultValues = {
18
- animation: true,
19
- animationOnInit: false,
20
- initDone: null,
21
- visible: true,
22
- transition: noAnimation,
23
- onShown: noop,
24
- onHidden: noop,
25
- onVisibleChange: noop,
12
+ animated: true,
13
+ animatedOnInit: false,
14
+ initDone: null,
15
+ visible: true,
16
+ transition: noAnimation,
17
+ onShown: noop,
18
+ onHidden: noop,
19
+ onVisibleChange: noop
26
20
  };
27
21
  const configValidator = {
28
- animation: typeBoolean,
29
- animationOnInit: typeBoolean,
30
- visible: typeBoolean,
31
- transition: typeFunction,
32
- onShown: typeFunction,
33
- onHidden: typeFunction,
34
- onVisibleChange: typeFunction,
35
- initDone: typeBooleanOrNull,
22
+ animated: typeBoolean,
23
+ animatedOnInit: typeBoolean,
24
+ visible: typeBoolean,
25
+ transition: typeFunction,
26
+ onShown: typeFunction,
27
+ onHidden: typeFunction,
28
+ onVisibleChange: typeFunction,
29
+ initDone: typeBooleanOrNull
36
30
  };
37
- /**
38
- * Create a transition widget.
39
- *
40
- * The widget will include a patch function, stores to track the animation states and a directive to apply the animation to an element.
41
- *
42
- * @param config - the props config of the transition
43
- * @returns the transition widget
44
- */
45
- export const createTransition = (config) => {
46
- const [{ animation$, initDone$, visible$: requestedVisible$, transition$, onShown$, onHidden$, onVisibleChange$, animationOnInit$ }, patch] = writablesForProps(defaultValues, config, configValidator);
47
- const { element$, directive: storeDirective } = createStoreDirective();
48
- const elementPresent$ = computed(() => !!element$());
49
- const visible$ = bindableDerived(onVisibleChange$, [requestedVisible$], ([visible]) => visible);
50
- const currentTransition$ = writable(null);
51
- const transitioning$ = computed(() => !!currentTransition$());
52
- const stop = () => {
53
- let context;
54
- currentTransition$.update((currentTransition) => {
55
- currentTransition?.abort.abort();
56
- context = currentTransition?.context;
57
- return null;
58
- });
59
- return context;
60
- };
61
- const runTransition = (visible, animation, element, transitionFn) => batch(() => {
62
- const abort = new AbortController();
63
- const signal = abort.signal;
64
- const context = stop() ?? {};
65
- const { promise, resolve } = promiseWithResolve();
66
- const currentTransition = {
67
- abort,
68
- animation,
69
- visible,
70
- context,
71
- element,
72
- transitionFn,
73
- promise,
74
- };
75
- currentTransition$.set(currentTransition);
76
- resolve((async () => {
77
- try {
78
- await transitionFn(element, visible ? 'show' : 'hide', animation, signal, context);
79
- }
80
- finally {
81
- if (signal.aborted) {
82
- await neverEndingPromise;
83
- }
84
- else {
85
- currentTransition$.set(null);
86
- (visible ? onShown$ : onHidden$)()?.();
87
- }
88
- }
89
- })());
90
- return currentTransition;
31
+ const createTransition = (config) => {
32
+ const [{ animated$, initDone$, visible$: requestedVisible$, transition$, onShown$, onHidden$, onVisibleChange$, animatedOnInit$ }, patch] = writablesForProps(defaultValues, config, configValidator);
33
+ const { element$, directive: storeDirective } = createStoreDirective();
34
+ const elementPresent$ = computed(() => !!element$());
35
+ const visible$ = bindableDerived(onVisibleChange$, [requestedVisible$], ([visible]) => visible);
36
+ const currentTransition$ = writable(
37
+ null
38
+ );
39
+ const transitioning$ = computed(() => !!currentTransition$());
40
+ const stop = () => {
41
+ let context;
42
+ currentTransition$.update((currentTransition) => {
43
+ currentTransition == null ? void 0 : currentTransition.abort.abort();
44
+ context = currentTransition == null ? void 0 : currentTransition.context;
45
+ return null;
91
46
  });
92
- const shown$ = computed(() => !transitioning$() && visible$() && elementPresent$());
93
- const hidden$ = computed(() => !transitioning$() && !visible$());
94
- const effectiveAnimation$ = computed(() => (initDone$() ? animation$() : animationOnInit$()));
95
- const animationFromToggle$ = writable(null);
96
- let previousElement;
97
- let previousVisible = requestedVisible$();
98
- let pendingTransition = null;
99
- const visibleAction$ = derived([visible$, element$, effectiveAnimation$, animationFromToggle$, transition$, currentTransition$], ([visible, element, animation, animationFromToggle, transition, currentTransition]) => {
100
- const elementChanged = previousElement !== element;
101
- previousElement = element;
102
- const visibleChanged = previousVisible !== visible;
103
- previousVisible = visible;
104
- if (element) {
105
- if (initDone$() == null) {
106
- initDone$.set(true);
107
- }
108
- const interruptAnimation = animationFromToggle != null && currentTransition && currentTransition.animation != animationFromToggle;
109
- if (elementChanged || visibleChanged || interruptAnimation) {
110
- if (visibleChanged || animationFromToggle != null) {
111
- pendingTransition = null;
112
- }
113
- const animate = animationFromToggle ?? pendingTransition?.animation ?? (elementChanged && !visible ? false : animation);
114
- currentTransition = runTransition(visible, animate, element, transition);
115
- pendingTransition?.resolve(currentTransition.promise);
116
- pendingTransition = null;
117
- }
47
+ return context;
48
+ };
49
+ const runTransition = (visible, animated, element, transitionFn) => batch(() => {
50
+ const abort = new AbortController();
51
+ const signal = abort.signal;
52
+ const context = stop() ?? {};
53
+ const { promise, resolve } = promiseWithResolve();
54
+ const currentTransition = {
55
+ abort,
56
+ animated,
57
+ visible,
58
+ context,
59
+ element,
60
+ transitionFn,
61
+ promise
62
+ };
63
+ currentTransition$.set(currentTransition);
64
+ resolve(
65
+ (async () => {
66
+ var _a;
67
+ try {
68
+ await transitionFn(element, visible ? "show" : "hide", animated, signal, context);
69
+ } finally {
70
+ if (signal.aborted) {
71
+ await neverEndingPromise;
72
+ } else {
73
+ currentTransition$.set(null);
74
+ (_a = (visible ? onShown$ : onHidden$)()) == null ? void 0 : _a();
75
+ }
118
76
  }
119
- else {
120
- if (elementChanged) {
121
- // just removed from the DOM: stop animation if any
122
- stop();
123
- currentTransition = null;
124
- }
125
- if (visibleChanged || (visible && pendingTransition?.animation !== animationFromToggle)) {
126
- pendingTransition =
127
- visible && animationFromToggle != null
128
- ? {
129
- // toggle was called to display the element, but the element is not yet in the DOM
130
- // let's keep the animation setting from toggle and provide the promise for the end of toggle
131
- animation: animationFromToggle,
132
- ...promiseWithResolve(),
133
- }
134
- : null;
135
- }
77
+ })()
78
+ );
79
+ return currentTransition;
80
+ });
81
+ const shown$ = computed(() => !transitioning$() && visible$() && elementPresent$());
82
+ const hidden$ = computed(() => !transitioning$() && !visible$());
83
+ const effectiveAnimation$ = computed(() => initDone$() ? animated$() : animatedOnInit$());
84
+ const animationFromToggle$ = writable(null);
85
+ let previousElement;
86
+ let previousVisible = requestedVisible$();
87
+ let pendingTransition = null;
88
+ const visibleAction$ = derived(
89
+ [visible$, element$, effectiveAnimation$, animationFromToggle$, transition$, currentTransition$],
90
+ ([visible, element, animated, animationFromToggle, transition, currentTransition]) => {
91
+ const elementChanged = previousElement !== element;
92
+ previousElement = element;
93
+ const visibleChanged = previousVisible !== visible;
94
+ previousVisible = visible;
95
+ if (element) {
96
+ if (initDone$() == null) {
97
+ initDone$.set(true);
136
98
  }
137
- return pendingTransition?.promise ?? currentTransition?.promise;
138
- });
139
- let lastToggle = {};
140
- const toggle = async (visible = !requestedVisible$(), animation = effectiveAnimation$()) => {
141
- const currentToggle = {};
142
- lastToggle = currentToggle;
143
- try {
144
- await batch(() => {
145
- try {
146
- animationFromToggle$.set(animation);
147
- requestedVisible$.set(visible);
148
- return visibleAction$();
149
- }
150
- finally {
151
- animationFromToggle$.set(null);
152
- }
153
- });
99
+ const interruptAnimation = animationFromToggle != null && currentTransition && currentTransition.animated != animationFromToggle;
100
+ if (elementChanged || visibleChanged || interruptAnimation) {
101
+ if (visibleChanged || animationFromToggle != null) {
102
+ pendingTransition = null;
103
+ }
104
+ const animate = animationFromToggle ?? (pendingTransition == null ? void 0 : pendingTransition.animated) ?? (elementChanged && !visible ? false : animated);
105
+ currentTransition = runTransition(visible, animate, element, transition);
106
+ pendingTransition == null ? void 0 : pendingTransition.resolve(currentTransition.promise);
107
+ pendingTransition = null;
154
108
  }
155
- finally {
156
- if (lastToggle !== currentToggle) {
157
- await neverEndingPromise;
158
- }
109
+ } else {
110
+ if (elementChanged) {
111
+ stop();
112
+ currentTransition = null;
159
113
  }
160
- };
161
- const directive = mergeDirectives(storeDirective, directiveUpdate(patch), directiveSubscribe(visibleAction$));
162
- return {
163
- ...stateStores({
164
- visible$,
165
- element$,
166
- elementPresent$,
167
- transitioning$,
168
- shown$,
169
- hidden$,
170
- }),
171
- patch,
172
- directives: {
173
- directive,
174
- },
175
- actions: {},
176
- api: {
177
- show: toggle.bind(null, true),
178
- hide: toggle.bind(null, false),
179
- toggle,
180
- },
181
- };
114
+ if (visibleChanged || visible && (pendingTransition == null ? void 0 : pendingTransition.animated) !== animationFromToggle) {
115
+ pendingTransition = visible && animationFromToggle != null ? {
116
+ // toggle was called to display the element, but the element is not yet in the DOM
117
+ // let's keep the animation setting from toggle and provide the promise for the end of toggle
118
+ animated: animationFromToggle,
119
+ ...promiseWithResolve()
120
+ } : null;
121
+ }
122
+ }
123
+ return (pendingTransition == null ? void 0 : pendingTransition.promise) ?? (currentTransition == null ? void 0 : currentTransition.promise);
124
+ }
125
+ );
126
+ let lastToggle = {};
127
+ const toggle = async (visible = !requestedVisible$(), animated = effectiveAnimation$()) => {
128
+ const currentToggle = {};
129
+ lastToggle = currentToggle;
130
+ try {
131
+ await batch(() => {
132
+ try {
133
+ animationFromToggle$.set(animated);
134
+ requestedVisible$.set(visible);
135
+ return visibleAction$();
136
+ } finally {
137
+ animationFromToggle$.set(null);
138
+ }
139
+ });
140
+ } finally {
141
+ if (lastToggle !== currentToggle) {
142
+ await neverEndingPromise;
143
+ }
144
+ }
145
+ };
146
+ const directive = mergeDirectives(storeDirective, directiveUpdate(patch), directiveSubscribe(visibleAction$));
147
+ return {
148
+ ...stateStores({
149
+ visible$,
150
+ element$,
151
+ elementPresent$,
152
+ transitioning$,
153
+ shown$,
154
+ hidden$
155
+ }),
156
+ patch,
157
+ directives: {
158
+ directive
159
+ },
160
+ actions: {},
161
+ api: {
162
+ show: toggle.bind(null, true),
163
+ hide: toggle.bind(null, false),
164
+ toggle
165
+ }
166
+ };
167
+ };
168
+ export {
169
+ createTransition,
170
+ noAnimation
182
171
  };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils_directive = require("../../directive-BTSEYLF3.cjs");
4
+ const services_transitions_cssTransitions = require("./cssTransitions.cjs");
5
+ const createCollapseTransition = ({
6
+ dimension = "height",
7
+ showClasses,
8
+ hideClasses,
9
+ animationPendingClasses
10
+ } = {}) => services_transitions_cssTransitions.createCSSTransition((element, direction, animated, context) => {
11
+ if (animated && utils_directive.isBrowserHTMLElement(element)) {
12
+ let { maxSize, minSize } = context;
13
+ if (!maxSize) {
14
+ utils_directive.removeClasses(element, animationPendingClasses);
15
+ utils_directive.removeClasses(element, hideClasses);
16
+ utils_directive.addClasses(element, showClasses);
17
+ maxSize = element.getBoundingClientRect()[dimension] + "px";
18
+ context.maxSize = maxSize;
19
+ }
20
+ if (!minSize) {
21
+ utils_directive.removeClasses(element, animationPendingClasses);
22
+ utils_directive.removeClasses(element, showClasses);
23
+ utils_directive.addClasses(element, hideClasses);
24
+ minSize = element.getBoundingClientRect()[dimension] + "px";
25
+ context.minSize = minSize;
26
+ }
27
+ utils_directive.removeClasses(element, showClasses);
28
+ utils_directive.removeClasses(element, hideClasses);
29
+ const values = direction === "show" ? [minSize, maxSize] : [maxSize, minSize];
30
+ element.style[dimension] = values[0];
31
+ utils_directive.reflow(element);
32
+ utils_directive.addClasses(element, animationPendingClasses);
33
+ utils_directive.reflow(element);
34
+ element.style[dimension] = values[1];
35
+ } else {
36
+ utils_directive.removeClasses(element, direction === "show" ? hideClasses : showClasses);
37
+ }
38
+ return () => {
39
+ utils_directive.removeClasses(element, animationPendingClasses);
40
+ utils_directive.addClasses(element, direction === "show" ? showClasses : hideClasses);
41
+ element.style[dimension] = "";
42
+ };
43
+ });
44
+ exports.createCollapseTransition = createCollapseTransition;
@@ -1,52 +1,44 @@
1
- import { createCSSTransition } from './cssTransitions';
2
- import { addClasses, reflow, removeClasses } from '../../utils/internal/dom';
3
- /**
4
- * Create a collapse transition.
5
- *
6
- * The transition attaches / removes classes during the different states of the collapse transition.
7
- * It also updates the dimension value when reaching a non-pending state.
8
- *
9
- * @param config - the collapse config
10
- * @param config.dimension - the dimension, `height` or `width`, on which the collapse applies
11
- * @param config.showClasses - the classes to attach when the element is fully visible
12
- * @param config.hideClasses - the classes to attach when the element is fully collapsed
13
- * @param config.animationPendingClasses - the classes to attach when the transition is pending
14
- * @returns the collapse transition
15
- */
16
- export const createCollapseTransition = ({ dimension = 'height', showClasses, hideClasses, animationPendingClasses, } = {}) => createCSSTransition((element, direction, animation, context) => {
17
- if (animation) {
18
- let { maxSize, minSize } = context;
19
- if (!maxSize) {
20
- // measure the element in its show state
21
- removeClasses(element, animationPendingClasses);
22
- removeClasses(element, hideClasses);
23
- addClasses(element, showClasses);
24
- maxSize = element.getBoundingClientRect()[dimension] + 'px';
25
- context.maxSize = maxSize;
26
- }
27
- if (!minSize) {
28
- // measure the element in its hide state
29
- removeClasses(element, animationPendingClasses);
30
- removeClasses(element, showClasses);
31
- addClasses(element, hideClasses);
32
- minSize = element.getBoundingClientRect()[dimension] + 'px';
33
- context.minSize = minSize;
34
- }
35
- removeClasses(element, showClasses);
36
- removeClasses(element, hideClasses);
37
- const values = direction === 'show' ? [minSize, maxSize] : [maxSize, minSize];
38
- element.style[dimension] = values[0];
39
- reflow(element); // explicitly applies the initial state
40
- addClasses(element, animationPendingClasses);
41
- reflow(element);
42
- element.style[dimension] = values[1];
1
+ import { i as isBrowserHTMLElement, v as removeClasses, w as addClasses, x as reflow } from "../../directive-DCYlDznf.js";
2
+ import { createCSSTransition } from "./cssTransitions.js";
3
+ const createCollapseTransition = ({
4
+ dimension = "height",
5
+ showClasses,
6
+ hideClasses,
7
+ animationPendingClasses
8
+ } = {}) => createCSSTransition((element, direction, animated, context) => {
9
+ if (animated && isBrowserHTMLElement(element)) {
10
+ let { maxSize, minSize } = context;
11
+ if (!maxSize) {
12
+ removeClasses(element, animationPendingClasses);
13
+ removeClasses(element, hideClasses);
14
+ addClasses(element, showClasses);
15
+ maxSize = element.getBoundingClientRect()[dimension] + "px";
16
+ context.maxSize = maxSize;
43
17
  }
44
- else {
45
- removeClasses(element, direction === 'show' ? hideClasses : showClasses);
18
+ if (!minSize) {
19
+ removeClasses(element, animationPendingClasses);
20
+ removeClasses(element, showClasses);
21
+ addClasses(element, hideClasses);
22
+ minSize = element.getBoundingClientRect()[dimension] + "px";
23
+ context.minSize = minSize;
46
24
  }
47
- return () => {
48
- removeClasses(element, animationPendingClasses);
49
- addClasses(element, direction === 'show' ? showClasses : hideClasses);
50
- element.style[dimension] = '';
51
- };
25
+ removeClasses(element, showClasses);
26
+ removeClasses(element, hideClasses);
27
+ const values = direction === "show" ? [minSize, maxSize] : [maxSize, minSize];
28
+ element.style[dimension] = values[0];
29
+ reflow(element);
30
+ addClasses(element, animationPendingClasses);
31
+ reflow(element);
32
+ element.style[dimension] = values[1];
33
+ } else {
34
+ removeClasses(element, direction === "show" ? hideClasses : showClasses);
35
+ }
36
+ return () => {
37
+ removeClasses(element, animationPendingClasses);
38
+ addClasses(element, direction === "show" ? showClasses : hideClasses);
39
+ element.style[dimension] = "";
40
+ };
52
41
  });
42
+ export {
43
+ createCollapseTransition
44
+ };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils_directive = require("../../directive-BTSEYLF3.cjs");
4
+ const func = require("../../func-Qd3cD9a3.cjs");
5
+ const promise = require("../../promise-BMJ8qhA8.cjs");
6
+ function hasTransition(element) {
7
+ return window.getComputedStyle(element).transitionProperty !== "none";
8
+ }
9
+ function getTransitionDurationMs(element) {
10
+ const { transitionDelay, transitionDuration } = window.getComputedStyle(element);
11
+ const transitionDelaySec = parseFloat(transitionDelay);
12
+ const transitionDurationSec = parseFloat(transitionDuration);
13
+ return (transitionDelaySec + transitionDurationSec) * 1e3;
14
+ }
15
+ const createCSSTransition = (start) => async (element, direction, animated, signal, context) => {
16
+ const endFn = start(element, direction, animated, context) ?? func.noop;
17
+ if (utils_directive.isBrowserHTMLElement(element) && animated && hasTransition(element)) {
18
+ const abort = promise.promiseFromEvent(signal, "abort");
19
+ const transitionEnd = promise.promiseFromEvent(element, "transitionend");
20
+ const timer = promise.promiseFromTimeout(getTransitionDurationMs(element));
21
+ await Promise.race([abort.promise, transitionEnd.promise, timer.promise]);
22
+ abort.unsubscribe();
23
+ transitionEnd.unsubscribe();
24
+ timer.unsubscribe();
25
+ }
26
+ if (!signal.aborted) {
27
+ endFn();
28
+ }
29
+ };
30
+ exports.createCSSTransition = createCSSTransition;
31
+ exports.getTransitionDurationMs = getTransitionDurationMs;
32
+ exports.hasTransition = hasTransition;
@@ -1,3 +1,4 @@
1
+ import type { SSRHTMLElement } from '../../types';
1
2
  import type { TransitionFn } from './baseTransitions';
2
3
  /**
3
4
  * Check if the provided html element has a transition
@@ -11,7 +12,7 @@ export declare function hasTransition(element: HTMLElement): boolean;
11
12
  * @returns transition duration in milli seconds
12
13
  */
13
14
  export declare function getTransitionDurationMs(element: HTMLElement): number;
14
- export type CSSTransitionFn = (element: HTMLElement, direction: 'show' | 'hide', animation: boolean, context: object) => void | (() => void);
15
+ export type CSSTransitionFn = (element: SSRHTMLElement, direction: 'show' | 'hide', animated: boolean, context: object) => void | (() => void);
15
16
  /**
16
17
  * Create a simple css transition.
17
18
  *
@@ -1,42 +1,32 @@
1
- import { noop } from '../../utils/internal/func';
2
- import { promiseFromEvent, promiseFromTimeout } from '../../utils/internal/promise';
3
- /**
4
- * Check if the provided html element has a transition
5
- * @param element - the html element
6
- * @returns true if the element has a transition
7
- */
8
- export function hasTransition(element) {
9
- return window.getComputedStyle(element).transitionProperty !== 'none';
1
+ import { i as isBrowserHTMLElement } from "../../directive-DCYlDznf.js";
2
+ import { n as noop } from "../../func-DR0n-ShK.js";
3
+ import { a as promiseFromEvent, b as promiseFromTimeout } from "../../promise-CY2U8bTP.js";
4
+ function hasTransition(element) {
5
+ return window.getComputedStyle(element).transitionProperty !== "none";
10
6
  }
11
- /**
12
- * Retrieve the transition duration of the provided html element in milli seconds
13
- * @param element - the html element
14
- * @returns transition duration in milli seconds
15
- */
16
- export function getTransitionDurationMs(element) {
17
- const { transitionDelay, transitionDuration } = window.getComputedStyle(element);
18
- const transitionDelaySec = parseFloat(transitionDelay);
19
- const transitionDurationSec = parseFloat(transitionDuration);
20
- return (transitionDelaySec + transitionDurationSec) * 1000;
7
+ function getTransitionDurationMs(element) {
8
+ const { transitionDelay, transitionDuration } = window.getComputedStyle(element);
9
+ const transitionDelaySec = parseFloat(transitionDelay);
10
+ const transitionDurationSec = parseFloat(transitionDuration);
11
+ return (transitionDelaySec + transitionDurationSec) * 1e3;
21
12
  }
22
- /**
23
- * Create a simple css transition.
24
- *
25
- * @param start - a function that creates the css animation and returns a clean-up function
26
- * @returns the css transition
27
- */
28
- export const createCSSTransition = (start) => async (element, direction, animation, signal, context) => {
29
- const endFn = start(element, direction, animation, context) ?? noop;
30
- if (animation && hasTransition(element)) {
31
- const abort = promiseFromEvent(signal, 'abort');
32
- const transitionEnd = promiseFromEvent(element, 'transitionend');
33
- const timer = promiseFromTimeout(getTransitionDurationMs(element));
34
- await Promise.race([abort.promise, transitionEnd.promise, timer.promise]);
35
- abort.unsubscribe();
36
- transitionEnd.unsubscribe();
37
- timer.unsubscribe();
38
- }
39
- if (!signal.aborted) {
40
- endFn();
41
- }
13
+ const createCSSTransition = (start) => async (element, direction, animated, signal, context) => {
14
+ const endFn = start(element, direction, animated, context) ?? noop;
15
+ if (isBrowserHTMLElement(element) && animated && hasTransition(element)) {
16
+ const abort = promiseFromEvent(signal, "abort");
17
+ const transitionEnd = promiseFromEvent(element, "transitionend");
18
+ const timer = promiseFromTimeout(getTransitionDurationMs(element));
19
+ await Promise.race([abort.promise, transitionEnd.promise, timer.promise]);
20
+ abort.unsubscribe();
21
+ transitionEnd.unsubscribe();
22
+ timer.unsubscribe();
23
+ }
24
+ if (!signal.aborted) {
25
+ endFn();
26
+ }
27
+ };
28
+ export {
29
+ createCSSTransition,
30
+ getTransitionDurationMs,
31
+ hasTransition
42
32
  };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const services_transitions_cssTransitions = require("./cssTransitions.cjs");
4
+ const utils_directive = require("../../directive-BTSEYLF3.cjs");
5
+ const createSimpleClassTransition = (config) => {
6
+ const { animationPendingClasses, animationPendingShowClasses, animationPendingHideClasses, showClasses, hideClasses } = config;
7
+ return services_transitions_cssTransitions.createCSSTransition((element, direction, animated, context) => {
8
+ utils_directive.removeClasses(element, showClasses);
9
+ utils_directive.removeClasses(element, hideClasses);
10
+ if (animated) {
11
+ utils_directive.removeClasses(element, direction === "show" ? animationPendingHideClasses : animationPendingShowClasses);
12
+ if (!context.started) {
13
+ context.started = true;
14
+ const classes = direction === "show" ? hideClasses : showClasses;
15
+ utils_directive.addClasses(element, classes);
16
+ utils_directive.reflow(element);
17
+ utils_directive.removeClasses(element, classes);
18
+ }
19
+ utils_directive.addClasses(element, animationPendingClasses);
20
+ utils_directive.reflow(element);
21
+ utils_directive.addClasses(element, direction === "show" ? animationPendingShowClasses : animationPendingHideClasses);
22
+ }
23
+ return () => {
24
+ utils_directive.removeClasses(element, animationPendingClasses);
25
+ utils_directive.removeClasses(element, animationPendingShowClasses);
26
+ utils_directive.removeClasses(element, animationPendingHideClasses);
27
+ utils_directive.addClasses(element, direction === "show" ? showClasses : hideClasses);
28
+ };
29
+ });
30
+ };
31
+ exports.createSimpleClassTransition = createSimpleClassTransition;