@radix-ng/primitives 0.35.0 → 0.36.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.
package/core/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from './src/accessor/provide-value-accessor';
2
2
  export * from './src/auto-focus.directive';
3
+ export * from './src/clamp';
3
4
  export * from './src/document';
4
5
  export * from './src/focus-initial.directive';
6
+ export * from './src/getActiveElement';
5
7
  export * from './src/id-generator';
6
8
  export * from './src/inject-ng-control';
7
9
  export * from './src/is-client';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The `clamp` function restricts a number within a specified range by returning the value itself if it
3
+ * falls within the range, or the closest boundary value if it exceeds the range.
4
+ * @param {number} value - The `value` parameter represents the number that you want to clamp within
5
+ * the specified range defined by `min` and `max` values.
6
+ * @param {number} min - If the `value` parameter is less than the `min` value, the
7
+ * function will return the `min` value.
8
+ * @param {number} max - If the `value` parameter is greater than the `max` value,
9
+ * the function will return `max`.
10
+ * @returns The `clamp` function returns the value of `value` constrained within the range defined by
11
+ * `min` and `max`.
12
+ */
13
+ export declare function clamp(value: number, min?: number, max?: number): number;
14
+ /**
15
+ * The function `roundToStepPrecision` rounds a number to a specified precision step.
16
+ * @param {number} value - The `value` parameter is the number that you want to round to a specific
17
+ * precision based on the `step` parameter.
18
+ * @param {number} step - The `step` parameter in the `roundToStepPrecision` function represents the
19
+ * interval at which you want to round the `value`. For example, if `step` is 0.5, the `value` will be
20
+ * rounded to the nearest half.
21
+ * @returns the `roundedValue` after rounding it to the precision specified by the `step`.
22
+ */
23
+ export declare function roundToStepPrecision(value: number, step: number): number;
24
+ /**
25
+ * The function `snapValueToStep` snaps a given value to the nearest step within a specified range.
26
+ * @param {number} value - The `value` parameter represents the number that you want to snap to the
27
+ * nearest step value.
28
+ * @param {number | undefined} min - The `min` parameter represents the minimum value that the `value`
29
+ * should be snapped to. If `value` is less than `min`, it will be snapped to `min`. If `min` is not
30
+ * provided (undefined), then the snapping will not consider a minimum value.
31
+ * @param {number | undefined} max - The `max` parameter represents the maximum value that the `value`
32
+ * should be snapped to. It ensures that the snapped value does not exceed this maximum value.
33
+ * @param {number} step - The `step` parameter in the `snapValueToStep` function represents the
34
+ * interval at which the `value` should be snapped to. It determines the granularity of the snapping
35
+ * operation. For example, if `step` is 5, the `value` will be snapped to the nearest multiple of
36
+ * @returns a number that has been snapped to the nearest step value within the specified range of minimum and maximum values.
37
+ */
38
+ export declare function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number;
@@ -0,0 +1 @@
1
+ export declare function getActiveElement(): Element | null;
@@ -1,2 +1,11 @@
1
+ import * as i0 from "@angular/core";
2
+ import * as i1 from "./src/date-field-root.directive";
3
+ import * as i2 from "./src/date-field-input.directive";
4
+ export * from './src/date-field-context.token';
1
5
  export * from './src/date-field-input.directive';
2
6
  export * from './src/date-field-root.directive';
7
+ export declare class RdxDateFieldModule {
8
+ static ɵfac: i0.ɵɵFactoryDeclaration<RdxDateFieldModule, never>;
9
+ static ɵmod: i0.ɵɵNgModuleDeclaration<RdxDateFieldModule, never, [typeof i1.RdxDateFieldRootDirective, typeof i2.RdxDateFieldInputDirective], [typeof i1.RdxDateFieldRootDirective, typeof i2.RdxDateFieldInputDirective]>;
10
+ static ɵinj: i0.ɵɵInjectorDeclaration<RdxDateFieldModule>;
11
+ }
@@ -101,6 +101,76 @@ function getRequestAnimationFrame() {
101
101
  // Get the requestAnimationFrame function or its polyfill.
102
102
  const reqAnimationFrame = getRequestAnimationFrame();
103
103
 
104
+ /**
105
+ * The `clamp` function restricts a number within a specified range by returning the value itself if it
106
+ * falls within the range, or the closest boundary value if it exceeds the range.
107
+ * @param {number} value - The `value` parameter represents the number that you want to clamp within
108
+ * the specified range defined by `min` and `max` values.
109
+ * @param {number} min - If the `value` parameter is less than the `min` value, the
110
+ * function will return the `min` value.
111
+ * @param {number} max - If the `value` parameter is greater than the `max` value,
112
+ * the function will return `max`.
113
+ * @returns The `clamp` function returns the value of `value` constrained within the range defined by
114
+ * `min` and `max`.
115
+ */
116
+ function clamp(value, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY) {
117
+ return Math.min(max, Math.max(min, value));
118
+ }
119
+ /**
120
+ * The function `roundToStepPrecision` rounds a number to a specified precision step.
121
+ * @param {number} value - The `value` parameter is the number that you want to round to a specific
122
+ * precision based on the `step` parameter.
123
+ * @param {number} step - The `step` parameter in the `roundToStepPrecision` function represents the
124
+ * interval at which you want to round the `value`. For example, if `step` is 0.5, the `value` will be
125
+ * rounded to the nearest half.
126
+ * @returns the `roundedValue` after rounding it to the precision specified by the `step`.
127
+ */
128
+ function roundToStepPrecision(value, step) {
129
+ let roundedValue = value;
130
+ const stepString = step.toString();
131
+ const pointIndex = stepString.indexOf('.');
132
+ const precision = pointIndex >= 0 ? stepString.length - pointIndex : 0;
133
+ if (precision > 0) {
134
+ const pow = 10 ** precision;
135
+ roundedValue = Math.round(roundedValue * pow) / pow;
136
+ }
137
+ return roundedValue;
138
+ }
139
+ /**
140
+ * The function `snapValueToStep` snaps a given value to the nearest step within a specified range.
141
+ * @param {number} value - The `value` parameter represents the number that you want to snap to the
142
+ * nearest step value.
143
+ * @param {number | undefined} min - The `min` parameter represents the minimum value that the `value`
144
+ * should be snapped to. If `value` is less than `min`, it will be snapped to `min`. If `min` is not
145
+ * provided (undefined), then the snapping will not consider a minimum value.
146
+ * @param {number | undefined} max - The `max` parameter represents the maximum value that the `value`
147
+ * should be snapped to. It ensures that the snapped value does not exceed this maximum value.
148
+ * @param {number} step - The `step` parameter in the `snapValueToStep` function represents the
149
+ * interval at which the `value` should be snapped to. It determines the granularity of the snapping
150
+ * operation. For example, if `step` is 5, the `value` will be snapped to the nearest multiple of
151
+ * @returns a number that has been snapped to the nearest step value within the specified range of minimum and maximum values.
152
+ */
153
+ function snapValueToStep(value, min, max, step) {
154
+ min = Number(min);
155
+ max = Number(max);
156
+ const remainder = (value - (Number.isNaN(min) ? 0 : min)) % step;
157
+ let snappedValue = roundToStepPrecision(Math.abs(remainder) * 2 >= step
158
+ ? value + Math.sign(remainder) * (step - Math.abs(remainder))
159
+ : value - remainder, step);
160
+ if (!Number.isNaN(min)) {
161
+ if (snappedValue < min)
162
+ snappedValue = min;
163
+ else if (!Number.isNaN(max) && snappedValue > max)
164
+ snappedValue = min + Math.floor(roundToStepPrecision((max - min) / step, step)) * step;
165
+ }
166
+ else if (!Number.isNaN(max) && snappedValue > max) {
167
+ snappedValue = Math.floor(roundToStepPrecision(max / step, step)) * step;
168
+ }
169
+ // correct floating point behavior by rounding to step precision
170
+ snappedValue = roundToStepPrecision(snappedValue, step);
171
+ return snappedValue;
172
+ }
173
+
104
174
  function injectDocument() {
105
175
  return inject(DOCUMENT);
106
176
  }
@@ -124,6 +194,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImpor
124
194
  }]
125
195
  }] });
126
196
 
197
+ function getActiveElement() {
198
+ let activeElement = document.activeElement;
199
+ if (activeElement == null) {
200
+ return null;
201
+ }
202
+ while (activeElement != null &&
203
+ activeElement.shadowRoot != null &&
204
+ activeElement.shadowRoot.activeElement != null) {
205
+ activeElement = activeElement.shadowRoot.activeElement;
206
+ }
207
+ return activeElement;
208
+ }
209
+
127
210
  /**
128
211
  * @license
129
212
  * Copyright Google LLC All Rights Reserved.
@@ -2017,5 +2100,5 @@ function watch(deps, fn, options) {
2017
2100
  * Generated bundle index. Do not edit.
2018
2101
  */
2019
2102
 
2020
- export { A, ALT, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT, ARROW_UP, ASTERISK, BACKSPACE, CAPS_LOCK, CONTROL, CTRL, DELETE, END, ENTER, ESCAPE, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, HOME, META, P, PAGE_DOWN, PAGE_UP, RDX_POSITIONING_DEFAULTS, RDX_POSITIONS, RdxAutoFocusDirective, RdxFocusInitialDirective, RdxPositionAlign, RdxPositionSide, SHIFT, SPACE, SPACE_CODE, TAB, WINDOW, _IdGenerator, a, areAllDaysBetweenValid, createContent, createFormatter, createMonth, createMonths, getAllPossibleConnectedPositions, getArrowPositionParams, getContentPosition, getDaysBetween, getDaysInMonth, getDefaultDate, getLastFirstDayOfWeek, getNextLastDayOfWeek, getOptsByGranularity, getPlaceholder, getSegmentElements, getSideAndAlignFromAllPossibleConnectedPositions, handleCalendarInitialFocus, hasTime, initializeSegmentValues, injectDocument, injectIsClient, injectNgControl, injectWindow, isAcceptableSegmentKey, isAfter, isAfterOrSame, isBefore, isBeforeOrSame, isBetween, isBetweenInclusive, isCalendarDateTime, isInsideForm, isNullish, isNumber, isNumberString, isSegmentNavigationKey, isZonedDateTime, j, k, n, p, provideToken, provideValueAccessor, segmentBuilders, syncSegmentValues, syncTimeSegmentValues, toDate, useDateField, watch };
2103
+ export { A, ALT, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT, ARROW_UP, ASTERISK, BACKSPACE, CAPS_LOCK, CONTROL, CTRL, DELETE, END, ENTER, ESCAPE, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, HOME, META, P, PAGE_DOWN, PAGE_UP, RDX_POSITIONING_DEFAULTS, RDX_POSITIONS, RdxAutoFocusDirective, RdxFocusInitialDirective, RdxPositionAlign, RdxPositionSide, SHIFT, SPACE, SPACE_CODE, TAB, WINDOW, _IdGenerator, a, areAllDaysBetweenValid, clamp, createContent, createFormatter, createMonth, createMonths, getActiveElement, getAllPossibleConnectedPositions, getArrowPositionParams, getContentPosition, getDaysBetween, getDaysInMonth, getDefaultDate, getLastFirstDayOfWeek, getNextLastDayOfWeek, getOptsByGranularity, getPlaceholder, getSegmentElements, getSideAndAlignFromAllPossibleConnectedPositions, handleCalendarInitialFocus, hasTime, initializeSegmentValues, injectDocument, injectIsClient, injectNgControl, injectWindow, isAcceptableSegmentKey, isAfter, isAfterOrSame, isBefore, isBeforeOrSame, isBetween, isBetweenInclusive, isCalendarDateTime, isInsideForm, isNullish, isNumber, isNumberString, isSegmentNavigationKey, isZonedDateTime, j, k, n, p, provideToken, provideValueAccessor, roundToStepPrecision, segmentBuilders, snapValueToStep, syncSegmentValues, syncTimeSegmentValues, toDate, useDateField, watch };
2021
2104
  //# sourceMappingURL=radix-ng-primitives-core.mjs.map