ng-primitives 0.90.0 → 0.91.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 (95) hide show
  1. package/a11y/index.d.ts +38 -46
  2. package/accordion/index.d.ts +252 -104
  3. package/ai/index.d.ts +1 -1
  4. package/autofill/index.d.ts +49 -9
  5. package/avatar/index.d.ts +96 -61
  6. package/breadcrumbs/index.d.ts +156 -16
  7. package/button/index.d.ts +23 -28
  8. package/checkbox/index.d.ts +93 -14
  9. package/combobox/index.d.ts +1 -1
  10. package/date-picker/index.d.ts +12 -11
  11. package/fesm2022/ng-primitives-a11y.mjs +36 -52
  12. package/fesm2022/ng-primitives-a11y.mjs.map +1 -1
  13. package/fesm2022/ng-primitives-accordion.mjs +210 -189
  14. package/fesm2022/ng-primitives-accordion.mjs.map +1 -1
  15. package/fesm2022/ng-primitives-ai.mjs +4 -4
  16. package/fesm2022/ng-primitives-ai.mjs.map +1 -1
  17. package/fesm2022/ng-primitives-autofill.mjs +53 -36
  18. package/fesm2022/ng-primitives-autofill.mjs.map +1 -1
  19. package/fesm2022/ng-primitives-avatar.mjs +97 -138
  20. package/fesm2022/ng-primitives-avatar.mjs.map +1 -1
  21. package/fesm2022/ng-primitives-breadcrumbs.mjs +92 -35
  22. package/fesm2022/ng-primitives-breadcrumbs.mjs.map +1 -1
  23. package/fesm2022/ng-primitives-button.mjs +14 -36
  24. package/fesm2022/ng-primitives-button.mjs.map +1 -1
  25. package/fesm2022/ng-primitives-checkbox.mjs +87 -65
  26. package/fesm2022/ng-primitives-checkbox.mjs.map +1 -1
  27. package/fesm2022/ng-primitives-combobox.mjs +9 -9
  28. package/fesm2022/ng-primitives-combobox.mjs.map +1 -1
  29. package/fesm2022/ng-primitives-date-picker.mjs +5 -4
  30. package/fesm2022/ng-primitives-date-picker.mjs.map +1 -1
  31. package/fesm2022/ng-primitives-form-field.mjs +48 -16
  32. package/fesm2022/ng-primitives-form-field.mjs.map +1 -1
  33. package/fesm2022/ng-primitives-input.mjs +32 -48
  34. package/fesm2022/ng-primitives-input.mjs.map +1 -1
  35. package/fesm2022/ng-primitives-interactions.mjs +4 -4
  36. package/fesm2022/ng-primitives-interactions.mjs.map +1 -1
  37. package/fesm2022/ng-primitives-listbox.mjs.map +1 -1
  38. package/fesm2022/ng-primitives-menu.mjs +13 -6
  39. package/fesm2022/ng-primitives-menu.mjs.map +1 -1
  40. package/fesm2022/ng-primitives-pagination.mjs +6 -6
  41. package/fesm2022/ng-primitives-pagination.mjs.map +1 -1
  42. package/fesm2022/ng-primitives-progress.mjs +16 -4
  43. package/fesm2022/ng-primitives-progress.mjs.map +1 -1
  44. package/fesm2022/ng-primitives-radio.mjs +3 -3
  45. package/fesm2022/ng-primitives-radio.mjs.map +1 -1
  46. package/fesm2022/ng-primitives-roving-focus.mjs +259 -236
  47. package/fesm2022/ng-primitives-roving-focus.mjs.map +1 -1
  48. package/fesm2022/ng-primitives-search.mjs.map +1 -1
  49. package/fesm2022/ng-primitives-select.mjs +8 -8
  50. package/fesm2022/ng-primitives-select.mjs.map +1 -1
  51. package/fesm2022/ng-primitives-slider.mjs +195 -172
  52. package/fesm2022/ng-primitives-slider.mjs.map +1 -1
  53. package/fesm2022/ng-primitives-state.mjs +172 -2
  54. package/fesm2022/ng-primitives-state.mjs.map +1 -1
  55. package/fesm2022/ng-primitives-switch.mjs +90 -88
  56. package/fesm2022/ng-primitives-switch.mjs.map +1 -1
  57. package/fesm2022/ng-primitives-tabs.mjs +4 -1
  58. package/fesm2022/ng-primitives-tabs.mjs.map +1 -1
  59. package/fesm2022/ng-primitives-textarea.mjs +27 -35
  60. package/fesm2022/ng-primitives-textarea.mjs.map +1 -1
  61. package/fesm2022/ng-primitives-toggle-group.mjs +134 -136
  62. package/fesm2022/ng-primitives-toggle-group.mjs.map +1 -1
  63. package/fesm2022/ng-primitives-toggle.mjs +69 -58
  64. package/fesm2022/ng-primitives-toggle.mjs.map +1 -1
  65. package/fesm2022/ng-primitives-toolbar.mjs +26 -35
  66. package/fesm2022/ng-primitives-toolbar.mjs.map +1 -1
  67. package/fesm2022/ng-primitives-utils.mjs +48 -35
  68. package/fesm2022/ng-primitives-utils.mjs.map +1 -1
  69. package/form-field/index.d.ts +7 -3
  70. package/input/index.d.ts +61 -24
  71. package/interactions/index.d.ts +5 -5
  72. package/listbox/index.d.ts +1 -1
  73. package/menu/index.d.ts +3 -2
  74. package/package.json +1 -1
  75. package/pagination/index.d.ts +7 -7
  76. package/progress/index.d.ts +9 -1
  77. package/roving-focus/index.d.ts +77 -101
  78. package/schematics/ng-add/schema.d.ts +0 -1
  79. package/schematics/ng-generate/templates/checkbox/checkbox.__fileSuffix@dasherize__.ts.template +2 -2
  80. package/schematics/ng-generate/templates/progress/progress.__fileSuffix@dasherize__.ts.template +1 -1
  81. package/schematics/ng-generate/templates/slider/slider.__fileSuffix@dasherize__.ts.template +6 -3
  82. package/schematics/ng-generate/templates/switch/switch.__fileSuffix@dasherize__.ts.template +2 -2
  83. package/schematics/ng-generate/templates/toggle/toggle.__fileSuffix@dasherize__.ts.template +2 -2
  84. package/schematics/ng-generate/templates/toggle-group/toggle-group.__fileSuffix@dasherize__.ts.template +2 -2
  85. package/schematics/ng-generate/templates/toolbar/toolbar.__fileSuffix@dasherize__.ts.template +1 -1
  86. package/search/index.d.ts +1 -1
  87. package/select/index.d.ts +2 -2
  88. package/slider/index.d.ts +195 -56
  89. package/state/index.d.ts +57 -3
  90. package/switch/index.d.ts +103 -28
  91. package/textarea/index.d.ts +63 -8
  92. package/toggle/index.d.ts +65 -24
  93. package/toggle-group/index.d.ts +79 -54
  94. package/toolbar/index.d.ts +27 -17
  95. package/utils/index.d.ts +1 -0
@@ -1,237 +1,265 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, HostListener, input, numberAttribute, output, booleanAttribute, signal, computed } from '@angular/core';
3
- import { createStateToken, createStateProvider, createStateInjector, createState } from 'ng-primitives/state';
4
- import { ngpInteractions } from 'ng-primitives/interactions';
2
+ import { signal, computed, Directive, input, numberAttribute, output, booleanAttribute, HostListener } from '@angular/core';
5
3
  import { injectElementRef } from 'ng-primitives/internal';
6
- import { setupFormControl } from 'ng-primitives/form-field';
4
+ import { createPrimitive, controlled, attrBinding, dataBinding, deprecatedSetter, styleBinding, listener, createStateToken, createStateProvider, createStateInjector, createState } from 'ng-primitives/state';
5
+ import { ngpFormControl } from 'ng-primitives/form-field';
7
6
  import { uniqueId } from 'ng-primitives/utils';
7
+ import { Subject } from 'rxjs';
8
+ import { ngpInteractions } from 'ng-primitives/interactions';
8
9
 
9
- /**
10
- * The state token for the Slider primitive.
11
- */
12
- const NgpSliderStateToken = createStateToken('Slider');
13
- /**
14
- * Provides the Slider state.
15
- */
16
- const provideSliderState = createStateProvider(NgpSliderStateToken);
17
- /**
18
- * Injects the Slider state.
19
- */
20
- const injectSliderState = createStateInjector(NgpSliderStateToken);
21
- /**
22
- * The Slider state registration function.
23
- */
24
- const sliderState = createState(NgpSliderStateToken);
10
+ const [NgpSliderStateToken, ngpSlider, injectSliderState, provideSliderState] = createPrimitive('NgpSlider', ({ id = signal(uniqueId('ngp-slider')), value: _value = signal(0), min = signal(0), max = signal(100), step = signal(1), orientation: _orientation = signal('horizontal'), disabled: _disabled = signal(false), onValueChange, }) => {
11
+ const element = injectElementRef();
12
+ const value = controlled(_value);
13
+ const disabledInput = controlled(_disabled);
14
+ const orientation = controlled(_orientation);
15
+ const valueChange = new Subject();
16
+ const track = signal(undefined, ...(ngDevMode ? [{ debugName: "track" }] : []));
17
+ // Form control integration
18
+ const status = ngpFormControl({ id, disabled: disabledInput });
19
+ const percentage = computed(() => {
20
+ const range = max() - min();
21
+ if (range <= 0) {
22
+ return 0;
23
+ }
24
+ const pct = ((value() - min()) / range) * 100;
25
+ return Math.min(100, Math.max(0, pct));
26
+ }, ...(ngDevMode ? [{ debugName: "percentage" }] : []));
27
+ // Host bindings
28
+ attrBinding(element, 'id', id);
29
+ dataBinding(element, 'data-orientation', orientation);
30
+ dataBinding(element, 'data-disabled', () => status().disabled);
31
+ function setTrack(newTrack) {
32
+ track.set(newTrack);
33
+ }
34
+ function setValue(newValue) {
35
+ const clamped = Math.min(max(), Math.max(min(), newValue));
36
+ value.set(clamped);
37
+ onValueChange?.(clamped);
38
+ valueChange.next(clamped);
39
+ }
40
+ function setDisabled(isDisabled) {
41
+ disabledInput.set(isDisabled);
42
+ }
43
+ function setOrientation(newOrientation) {
44
+ orientation.set(newOrientation);
45
+ }
46
+ return {
47
+ id,
48
+ value,
49
+ min,
50
+ max,
51
+ step,
52
+ orientation: deprecatedSetter(orientation, 'setOrientation'),
53
+ disabled: deprecatedSetter(disabledInput, 'setDisabled'),
54
+ valueChange,
55
+ percentage,
56
+ track,
57
+ setValue,
58
+ setTrack,
59
+ setDisabled,
60
+ setOrientation,
61
+ };
62
+ });
63
+
64
+ const [NgpSliderRangeStateToken, ngpSliderRange, injectSliderRangeState, provideSliderRangeState,] = createPrimitive('NgpSliderRange', ({}) => {
65
+ const element = injectElementRef();
66
+ const slider = injectSliderState();
67
+ // Host bindings
68
+ dataBinding(element, 'data-orientation', () => slider().orientation());
69
+ dataBinding(element, 'data-disabled', () => slider().disabled());
70
+ styleBinding(element, 'width.%', () => slider().orientation() === 'horizontal' ? slider().percentage() : null);
71
+ styleBinding(element, 'height.%', () => slider().orientation() === 'vertical' ? slider().percentage() : null);
72
+ return {};
73
+ });
25
74
 
26
75
  /**
27
76
  * Apply the `ngpSliderRange` directive to an element that represents the range of the slider.
28
77
  */
29
78
  class NgpSliderRange {
30
79
  constructor() {
31
- /**
32
- * Access the slider state.
33
- */
34
- this.sliderState = injectSliderState();
80
+ ngpSliderRange({});
35
81
  }
36
82
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpSliderRange, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
37
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.9", type: NgpSliderRange, isStandalone: true, selector: "[ngpSliderRange]", host: { properties: { "attr.data-orientation": "sliderState().orientation()", "attr.data-disabled": "sliderState().disabled() ? \"\" : null", "style.width.%": "sliderState().orientation() === \"horizontal\" ? sliderState().percentage() : undefined", "style.height.%": "sliderState().orientation() === \"vertical\" ? sliderState().percentage() : undefined" } }, exportAs: ["ngpSliderRange"], ngImport: i0 }); }
83
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.9", type: NgpSliderRange, isStandalone: true, selector: "[ngpSliderRange]", providers: [provideSliderRangeState()], exportAs: ["ngpSliderRange"], ngImport: i0 }); }
38
84
  }
39
85
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpSliderRange, decorators: [{
40
86
  type: Directive,
41
87
  args: [{
42
88
  selector: '[ngpSliderRange]',
43
89
  exportAs: 'ngpSliderRange',
44
- host: {
45
- '[attr.data-orientation]': 'sliderState().orientation()',
46
- '[attr.data-disabled]': 'sliderState().disabled() ? "" : null',
47
- '[style.width.%]': 'sliderState().orientation() === "horizontal" ? sliderState().percentage() : undefined',
48
- '[style.height.%]': 'sliderState().orientation() === "vertical" ? sliderState().percentage() : undefined',
49
- },
90
+ providers: [provideSliderRangeState()],
50
91
  }]
51
- }] });
92
+ }], ctorParameters: () => [] });
52
93
 
53
- /**
54
- * Apply the `ngpSliderThumb` directive to an element that represents the thumb of the slider.
55
- */
56
- class NgpSliderThumb {
57
- constructor() {
58
- /**
59
- * Access the slider state.
60
- */
61
- this.state = injectSliderState();
62
- /**
63
- * Access the thumb element.
64
- */
65
- this.elementRef = injectElementRef();
66
- /**
67
- * Store the dragging state.
68
- */
69
- this.dragging = false;
70
- ngpInteractions({
71
- hover: true,
72
- focusVisible: true,
73
- press: true,
74
- disabled: this.state().disabled,
75
- });
76
- }
77
- handlePointerDown(event) {
94
+ const [NgpSliderThumbStateToken, ngpSliderThumb, injectSliderThumbState, provideSliderThumbState,] = createPrimitive('NgpSliderThumb', ({}) => {
95
+ const elementRef = injectElementRef();
96
+ const slider = injectSliderState();
97
+ let dragging = false;
98
+ const ariaValueNow = computed(() => slider().value(), ...(ngDevMode ? [{ debugName: "ariaValueNow" }] : []));
99
+ const tabindex = computed(() => (slider().disabled() ? -1 : 0), ...(ngDevMode ? [{ debugName: "tabindex" }] : []));
100
+ // Host bindings
101
+ attrBinding(elementRef, 'role', 'slider');
102
+ attrBinding(elementRef, 'aria-valuemin', () => slider().min().toString());
103
+ attrBinding(elementRef, 'aria-valuemax', () => slider().max().toString());
104
+ attrBinding(elementRef, 'aria-valuenow', () => ariaValueNow().toString());
105
+ attrBinding(elementRef, 'aria-orientation', () => slider().orientation());
106
+ attrBinding(elementRef, 'tabindex', () => tabindex().toString());
107
+ dataBinding(elementRef, 'data-orientation', () => slider().orientation());
108
+ dataBinding(elementRef, 'data-disabled', () => slider().disabled());
109
+ styleBinding(elementRef, 'inset-inline-start.%', () => slider().orientation() === 'horizontal' ? slider().percentage() : null);
110
+ styleBinding(elementRef, 'inset-block-start.%', () => slider().orientation() === 'vertical' ? slider().percentage() : null);
111
+ ngpInteractions({
112
+ hover: true,
113
+ focusVisible: true,
114
+ press: true,
115
+ disabled: slider().disabled,
116
+ });
117
+ // Pointer interactions
118
+ listener(elementRef, 'pointerdown', (event) => {
78
119
  event.preventDefault();
79
- if (this.state().disabled()) {
120
+ if (slider().disabled()) {
80
121
  return;
81
122
  }
82
- this.dragging = true;
83
- }
84
- handlePointerUp() {
85
- if (this.state().disabled()) {
123
+ dragging = true;
124
+ elementRef.nativeElement.setPointerCapture(event.pointerId);
125
+ });
126
+ listener(elementRef, 'pointerup', (event) => {
127
+ if (slider().disabled()) {
86
128
  return;
87
129
  }
88
- this.dragging = false;
89
- }
90
- handlePointerMove(event) {
91
- if (this.state().disabled() || !this.dragging) {
130
+ dragging = false;
131
+ if (elementRef.nativeElement.hasPointerCapture(event.pointerId)) {
132
+ elementRef.nativeElement.releasePointerCapture(event.pointerId);
133
+ }
134
+ });
135
+ listener(elementRef, 'pointermove', (event) => {
136
+ if (slider().disabled() || !dragging) {
92
137
  return;
93
138
  }
94
- const rect = this.state().track()?.element.nativeElement.getBoundingClientRect();
139
+ const track = slider().track();
140
+ const rect = track?.nativeElement.getBoundingClientRect();
95
141
  if (!rect) {
96
142
  return;
97
143
  }
98
- const percentage = this.state().orientation() === 'horizontal'
144
+ const percentage = slider().orientation() === 'horizontal'
99
145
  ? (event.clientX - rect.left) / rect.width
100
146
  : 1 - (event.clientY - rect.top) / rect.height;
101
- const value = this.state().min() +
102
- (this.state().max() - this.state().min()) * Math.max(0, Math.min(1, percentage));
103
- this.state().value.set(value);
104
- this.state().valueChange.emit(value);
105
- }
106
- /**
107
- * Handle keyboard events.
108
- * @param event
109
- */
110
- handleKeydown(event) {
147
+ const value = slider().min() + (slider().max() - slider().min()) * Math.max(0, Math.min(1, percentage));
148
+ slider().setValue(value);
149
+ });
150
+ // Keyboard interactions
151
+ listener(elementRef, 'keydown', (event) => {
111
152
  const multiplier = event.shiftKey ? 10 : 1;
112
- const step = this.state().step() * multiplier;
113
- const currentValue = this.state().value();
153
+ const step = slider().step() * multiplier;
154
+ const currentValue = slider().value();
114
155
  // determine the document direction
115
- const isRTL = getComputedStyle(this.elementRef.nativeElement).direction === 'rtl';
156
+ const isRTL = getComputedStyle(elementRef.nativeElement).direction === 'rtl';
116
157
  let newValue;
117
158
  switch (event.key) {
118
159
  case 'ArrowLeft':
119
160
  newValue = isRTL
120
- ? Math.min(currentValue + step, this.state().max())
121
- : Math.max(currentValue - step, this.state().min());
161
+ ? Math.min(currentValue + step, slider().max())
162
+ : Math.max(currentValue - step, slider().min());
122
163
  break;
123
164
  case 'ArrowDown':
124
- newValue = Math.max(currentValue - step, this.state().min());
165
+ newValue = Math.max(currentValue - step, slider().min());
125
166
  break;
126
167
  case 'ArrowRight':
127
168
  newValue = isRTL
128
- ? Math.max(currentValue - step, this.state().min())
129
- : Math.min(currentValue + step, this.state().max());
169
+ ? Math.max(currentValue - step, slider().min())
170
+ : Math.min(currentValue + step, slider().max());
130
171
  break;
131
172
  case 'ArrowUp':
132
- newValue = Math.min(currentValue + step, this.state().max());
173
+ newValue = Math.min(currentValue + step, slider().max());
133
174
  break;
134
175
  case 'Home':
135
- newValue = isRTL ? this.state().max() : this.state().min();
176
+ newValue = isRTL ? slider().max() : slider().min();
136
177
  break;
137
178
  case 'End':
138
- newValue = isRTL ? this.state().min() : this.state().max();
179
+ newValue = isRTL ? slider().min() : slider().max();
139
180
  break;
140
181
  default:
141
182
  return;
142
183
  }
143
- // if the value is the same, do not emit an event
144
184
  if (newValue === currentValue) {
145
185
  return;
146
186
  }
147
- this.state().value.set(newValue);
148
- this.state().valueChange.emit(newValue);
187
+ slider().setValue(newValue);
149
188
  event.preventDefault();
189
+ });
190
+ function focus() {
191
+ elementRef.nativeElement.focus({ preventScroll: true });
192
+ }
193
+ return {
194
+ dragging: computed(() => dragging),
195
+ focus,
196
+ };
197
+ });
198
+
199
+ /**
200
+ * Apply the `ngpSliderThumb` directive to an element that represents the thumb of the slider.
201
+ */
202
+ class NgpSliderThumb {
203
+ constructor() {
204
+ ngpSliderThumb({});
150
205
  }
151
206
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpSliderThumb, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
152
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.9", type: NgpSliderThumb, isStandalone: true, selector: "[ngpSliderThumb]", host: { attributes: { "role": "slider" }, listeners: { "pointerdown": "handlePointerDown($event)", "document:pointerup": "handlePointerUp()", "document:pointermove": "handlePointerMove($event)", "keydown": "handleKeydown($event)" }, properties: { "attr.aria-valuemin": "state().min()", "attr.aria-valuemax": "state().max()", "attr.aria-valuenow": "state().value()", "attr.aria-orientation": "state().orientation()", "tabindex": "state().disabled() ? -1 : 0", "attr.data-orientation": "state().orientation()", "attr.data-disabled": "state().disabled() ? \"\" : null", "style.inset-inline-start.%": "state().orientation() === \"horizontal\" ? state().percentage() : undefined", "style.inset-block-start.%": "state().orientation() === \"vertical\" ? state().percentage() : undefined" } }, exportAs: ["ngpSliderThumb"], ngImport: i0 }); }
207
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.9", type: NgpSliderThumb, isStandalone: true, selector: "[ngpSliderThumb]", providers: [provideSliderThumbState()], exportAs: ["ngpSliderThumb"], ngImport: i0 }); }
153
208
  }
154
209
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpSliderThumb, decorators: [{
155
210
  type: Directive,
156
211
  args: [{
157
212
  selector: '[ngpSliderThumb]',
158
213
  exportAs: 'ngpSliderThumb',
159
- host: {
160
- role: 'slider',
161
- '[attr.aria-valuemin]': 'state().min()',
162
- '[attr.aria-valuemax]': 'state().max()',
163
- '[attr.aria-valuenow]': 'state().value()',
164
- '[attr.aria-orientation]': 'state().orientation()',
165
- '[tabindex]': 'state().disabled() ? -1 : 0',
166
- '[attr.data-orientation]': 'state().orientation()',
167
- '[attr.data-disabled]': 'state().disabled() ? "" : null',
168
- '[style.inset-inline-start.%]': 'state().orientation() === "horizontal" ? state().percentage() : undefined',
169
- '[style.inset-block-start.%]': 'state().orientation() === "vertical" ? state().percentage() : undefined',
170
- },
214
+ providers: [provideSliderThumbState()],
171
215
  }]
172
- }], ctorParameters: () => [], propDecorators: { handlePointerDown: [{
173
- type: HostListener,
174
- args: ['pointerdown', ['$event']]
175
- }], handlePointerUp: [{
176
- type: HostListener,
177
- args: ['document:pointerup']
178
- }], handlePointerMove: [{
179
- type: HostListener,
180
- args: ['document:pointermove', ['$event']]
181
- }], handleKeydown: [{
182
- type: HostListener,
183
- args: ['keydown', ['$event']]
184
- }] } });
216
+ }], ctorParameters: () => [] });
217
+
218
+ const [NgpSliderTrackStateToken, ngpSliderTrack, injectSliderTrackState, provideSliderTrackState,] = createPrimitive('NgpSliderTrack', ({}) => {
219
+ const element = injectElementRef();
220
+ const slider = injectSliderState();
221
+ // Host bindings
222
+ dataBinding(element, 'data-orientation', () => slider().orientation());
223
+ dataBinding(element, 'data-disabled', () => slider().disabled());
224
+ // Register track for thumb measurements
225
+ slider().setTrack(element);
226
+ // Listener for pointer interactions to set value
227
+ listener(element, 'pointerdown', (event) => {
228
+ if (slider().disabled()) {
229
+ return;
230
+ }
231
+ // prevent text selection
232
+ event.preventDefault();
233
+ const rect = element.nativeElement.getBoundingClientRect();
234
+ const position = slider().orientation() === 'horizontal'
235
+ ? event.clientX - rect.left
236
+ : event.clientY - rect.top;
237
+ const size = slider().orientation() === 'horizontal' ? rect.width : rect.height;
238
+ const percentage = size === 0 ? 0 : position / size;
239
+ const value = slider().min() + (slider().max() - slider().min()) * Math.max(0, Math.min(1, percentage));
240
+ slider().setValue(value);
241
+ });
242
+ return {};
243
+ });
185
244
 
186
245
  /**
187
246
  * Apply the `ngpSliderTrack` directive to an element that represents the track of the slider.
188
247
  */
189
248
  class NgpSliderTrack {
190
249
  constructor() {
191
- /**
192
- * Access the slider state.
193
- */
194
- this.sliderState = injectSliderState();
195
- /**
196
- * The element that represents the slider track.
197
- */
198
- this.element = injectElementRef();
199
- this.sliderState().track.set(this);
200
- }
201
- /**
202
- * When the slider track is clicked, update the value.
203
- * @param event The click event.
204
- */
205
- handlePointerDown(event) {
206
- if (this.sliderState().disabled()) {
207
- return;
208
- }
209
- // get the position the click occurred within the slider track
210
- const position = this.sliderState().orientation() === 'horizontal' ? event.clientX : event.clientY;
211
- const rect = this.element.nativeElement.getBoundingClientRect();
212
- const percentage = (position - (this.sliderState().orientation() === 'horizontal' ? rect.left : rect.top)) /
213
- (this.sliderState().orientation() === 'horizontal' ? rect.width : rect.height);
214
- // update the value based on the position
215
- this.sliderState().value.set(this.sliderState().min() + (this.sliderState().max() - this.sliderState().min()) * percentage);
216
- this.sliderState().valueChange.emit(this.sliderState().value());
250
+ ngpSliderTrack({});
217
251
  }
218
252
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpSliderTrack, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
219
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.9", type: NgpSliderTrack, isStandalone: true, selector: "[ngpSliderTrack]", host: { listeners: { "pointerdown": "handlePointerDown($event)" }, properties: { "attr.data-orientation": "sliderState().orientation()", "attr.data-disabled": "sliderState().disabled() ? \"\" : null" } }, exportAs: ["ngpSliderTrack"], ngImport: i0 }); }
253
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.9", type: NgpSliderTrack, isStandalone: true, selector: "[ngpSliderTrack]", providers: [provideSliderTrackState()], exportAs: ["ngpSliderTrack"], ngImport: i0 }); }
220
254
  }
221
255
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpSliderTrack, decorators: [{
222
256
  type: Directive,
223
257
  args: [{
224
258
  selector: '[ngpSliderTrack]',
225
259
  exportAs: 'ngpSliderTrack',
226
- host: {
227
- '[attr.data-orientation]': 'sliderState().orientation()',
228
- '[attr.data-disabled]': 'sliderState().disabled() ? "" : null',
229
- },
260
+ providers: [provideSliderTrackState()],
230
261
  }]
231
- }], ctorParameters: () => [], propDecorators: { handlePointerDown: [{
232
- type: HostListener,
233
- args: ['pointerdown', ['$event']]
234
- }] } });
262
+ }], ctorParameters: () => [] });
235
263
 
236
264
  /**
237
265
  * Apply the `ngpSlider` directive to an element that represents the slider and contains the track, range, and thumb.
@@ -294,24 +322,23 @@ class NgpSlider {
294
322
  alias: 'ngpSliderDisabled',
295
323
  transform: booleanAttribute,
296
324
  }]));
297
- /**
298
- * Access the slider track.
299
- * @internal
300
- */
301
- this.track = signal(undefined, ...(ngDevMode ? [{ debugName: "track" }] : []));
302
- /**
303
- * The value as a percentage based on the min and max values.
304
- */
305
- this.percentage = computed(() => ((this.state.value() - this.state.min()) / (this.state.max() - this.state.min())) * 100, ...(ngDevMode ? [{ debugName: "percentage" }] : []));
306
325
  /**
307
326
  * The state of the slider. We use this for the slider state rather than relying on the inputs.
308
327
  * @internal
309
328
  */
310
- this.state = sliderState(this);
311
- setupFormControl({ id: this.state.id, disabled: this.state.disabled });
329
+ this.state = ngpSlider({
330
+ id: this.id,
331
+ value: this.value,
332
+ min: this.min,
333
+ max: this.max,
334
+ step: this.step,
335
+ orientation: this.orientation,
336
+ disabled: this.disabled,
337
+ onValueChange: value => this.valueChange.emit(value),
338
+ });
312
339
  }
313
340
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpSlider, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
314
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpSlider, isStandalone: true, selector: "[ngpSlider]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "ngpSliderValue", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "ngpSliderMin", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "ngpSliderMax", isSignal: true, isRequired: false, transformFunction: null }, step: { classPropertyName: "step", publicName: "ngpSliderStep", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "ngpSliderOrientation", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngpSliderDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueChange: "ngpSliderValueChange" }, host: { properties: { "id": "id()", "attr.data-orientation": "state.orientation()" } }, providers: [provideSliderState()], exportAs: ["ngpSlider"], ngImport: i0 }); }
341
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpSlider, isStandalone: true, selector: "[ngpSlider]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "ngpSliderValue", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "ngpSliderMin", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "ngpSliderMax", isSignal: true, isRequired: false, transformFunction: null }, step: { classPropertyName: "step", publicName: "ngpSliderStep", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "ngpSliderOrientation", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngpSliderDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueChange: "ngpSliderValueChange" }, providers: [provideSliderState()], exportAs: ["ngpSlider"], ngImport: i0 }); }
315
342
  }
316
343
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpSlider, decorators: [{
317
344
  type: Directive,
@@ -319,12 +346,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
319
346
  selector: '[ngpSlider]',
320
347
  exportAs: 'ngpSlider',
321
348
  providers: [provideSliderState()],
322
- host: {
323
- '[id]': 'id()',
324
- '[attr.data-orientation]': 'state.orientation()',
325
- },
326
349
  }]
327
- }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderValue", required: false }] }], valueChange: [{ type: i0.Output, args: ["ngpSliderValueChange"] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderMin", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderMax", required: false }] }], step: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderStep", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderOrientation", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderDisabled", required: false }] }] } });
350
+ }], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderValue", required: false }] }], valueChange: [{ type: i0.Output, args: ["ngpSliderValueChange"] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderMin", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderMax", required: false }] }], step: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderStep", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderOrientation", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpSliderDisabled", required: false }] }] } });
328
351
 
329
352
  /**
330
353
  * The state token for the Range Slider primitive.
@@ -692,7 +715,7 @@ class NgpRangeSlider {
692
715
  * @internal
693
716
  */
694
717
  this.state = rangeSliderState(this);
695
- setupFormControl({ id: this.state.id, disabled: this.state.disabled });
718
+ ngpFormControl({ id: this.state.id, disabled: this.state.disabled });
696
719
  }
697
720
  /**
698
721
  * Updates the low value, ensuring it doesn't exceed the high value.
@@ -763,5 +786,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
763
786
  * Generated bundle index. Do not edit.
764
787
  */
765
788
 
766
- export { NgpRangeSlider, NgpRangeSliderRange, NgpRangeSliderThumb, NgpRangeSliderTrack, NgpSlider, NgpSliderRange, NgpSliderThumb, NgpSliderTrack, injectRangeSliderState, injectSliderState, provideRangeSliderState, provideSliderState };
789
+ export { NgpRangeSlider, NgpRangeSliderRange, NgpRangeSliderThumb, NgpRangeSliderTrack, NgpSlider, NgpSliderRange, NgpSliderThumb, NgpSliderTrack, injectRangeSliderState, injectSliderRangeState, injectSliderState, injectSliderThumbState, injectSliderTrackState, ngpSlider, ngpSliderRange, ngpSliderThumb, ngpSliderTrack, provideRangeSliderState, provideSliderRangeState, provideSliderState, provideSliderThumbState, provideSliderTrackState };
767
790
  //# sourceMappingURL=ng-primitives-slider.mjs.map