@sectile/dom 0.1.0 → 0.2.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/README.md +6 -0
- package/package.json +91 -3
- package/dist/accordion.d.ts +0 -36
- package/dist/accordion.d.ts.map +0 -1
- package/dist/accordion.js +0 -143
- package/dist/accordion.js.map +0 -1
- package/dist/alert-dialog.d.ts +0 -27
- package/dist/alert-dialog.d.ts.map +0 -1
- package/dist/alert-dialog.js +0 -14
- package/dist/alert-dialog.js.map +0 -1
- package/dist/calendar.d.ts +0 -92
- package/dist/calendar.d.ts.map +0 -1
- package/dist/calendar.js +0 -296
- package/dist/calendar.js.map +0 -1
- package/dist/carousel.d.ts +0 -54
- package/dist/carousel.d.ts.map +0 -1
- package/dist/carousel.js +0 -285
- package/dist/carousel.js.map +0 -1
- package/dist/checkbox-group.d.ts +0 -22
- package/dist/checkbox-group.d.ts.map +0 -1
- package/dist/checkbox-group.js +0 -32
- package/dist/checkbox-group.js.map +0 -1
- package/dist/checkbox.d.ts +0 -18
- package/dist/checkbox.d.ts.map +0 -1
- package/dist/checkbox.js +0 -12
- package/dist/checkbox.js.map +0 -1
- package/dist/combobox.d.ts +0 -120
- package/dist/combobox.d.ts.map +0 -1
- package/dist/combobox.js +0 -386
- package/dist/combobox.js.map +0 -1
- package/dist/date-field.d.ts +0 -36
- package/dist/date-field.d.ts.map +0 -1
- package/dist/date-field.js +0 -88
- package/dist/date-field.js.map +0 -1
- package/dist/date-picker.d.ts +0 -43
- package/dist/date-picker.d.ts.map +0 -1
- package/dist/date-picker.js +0 -118
- package/dist/date-picker.js.map +0 -1
- package/dist/date-range-picker.d.ts +0 -45
- package/dist/date-range-picker.d.ts.map +0 -1
- package/dist/date-range-picker.js +0 -64
- package/dist/date-range-picker.js.map +0 -1
- package/dist/date-time-field.d.ts +0 -36
- package/dist/date-time-field.d.ts.map +0 -1
- package/dist/date-time-field.js +0 -163
- package/dist/date-time-field.js.map +0 -1
- package/dist/date-time-picker.d.ts +0 -45
- package/dist/date-time-picker.d.ts.map +0 -1
- package/dist/date-time-picker.js +0 -259
- package/dist/date-time-picker.js.map +0 -1
- package/dist/date-time-range-picker.d.ts +0 -47
- package/dist/date-time-range-picker.d.ts.map +0 -1
- package/dist/date-time-range-picker.js +0 -269
- package/dist/date-time-range-picker.js.map +0 -1
- package/dist/dialog.d.ts +0 -27
- package/dist/dialog.d.ts.map +0 -1
- package/dist/dialog.js +0 -15
- package/dist/dialog.js.map +0 -1
- package/dist/disclosure.d.ts +0 -24
- package/dist/disclosure.d.ts.map +0 -1
- package/dist/disclosure.js +0 -74
- package/dist/disclosure.js.map +0 -1
- package/dist/feed.d.ts +0 -33
- package/dist/feed.d.ts.map +0 -1
- package/dist/feed.js +0 -68
- package/dist/feed.js.map +0 -1
- package/dist/grid.d.ts +0 -43
- package/dist/grid.d.ts.map +0 -1
- package/dist/grid.js +0 -165
- package/dist/grid.js.map +0 -1
- package/dist/index.d.ts +0 -45
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -44
- package/dist/index.js.map +0 -1
- package/dist/internal/checked-control.d.ts +0 -28
- package/dist/internal/checked-control.d.ts.map +0 -1
- package/dist/internal/checked-control.js +0 -45
- package/dist/internal/checked-control.js.map +0 -1
- package/dist/internal/controller.d.ts +0 -6
- package/dist/internal/controller.d.ts.map +0 -1
- package/dist/internal/controller.js +0 -35
- package/dist/internal/controller.js.map +0 -1
- package/dist/internal/delegated-event.d.ts +0 -2
- package/dist/internal/delegated-event.d.ts.map +0 -1
- package/dist/internal/delegated-event.js +0 -11
- package/dist/internal/delegated-event.js.map +0 -1
- package/dist/internal/disabled-items.d.ts +0 -6
- package/dist/internal/disabled-items.d.ts.map +0 -1
- package/dist/internal/disabled-items.js +0 -15
- package/dist/internal/disabled-items.js.map +0 -1
- package/dist/internal/facade.d.ts +0 -44
- package/dist/internal/facade.d.ts.map +0 -1
- package/dist/internal/facade.js +0 -58
- package/dist/internal/facade.js.map +0 -1
- package/dist/internal/interaction.d.ts +0 -14
- package/dist/internal/interaction.d.ts.map +0 -1
- package/dist/internal/interaction.js +0 -25
- package/dist/internal/interaction.js.map +0 -1
- package/dist/internal/menu-control.d.ts +0 -38
- package/dist/internal/menu-control.d.ts.map +0 -1
- package/dist/internal/menu-control.js +0 -251
- package/dist/internal/menu-control.js.map +0 -1
- package/dist/internal/popup-control.d.ts +0 -39
- package/dist/internal/popup-control.d.ts.map +0 -1
- package/dist/internal/popup-control.js +0 -140
- package/dist/internal/popup-control.js.map +0 -1
- package/dist/internal/semantic-controller.d.ts +0 -20
- package/dist/internal/semantic-controller.d.ts.map +0 -1
- package/dist/internal/semantic-controller.js +0 -42
- package/dist/internal/semantic-controller.js.map +0 -1
- package/dist/internal/text-element.d.ts +0 -16
- package/dist/internal/text-element.d.ts.map +0 -1
- package/dist/internal/text-element.js +0 -215
- package/dist/internal/text-element.js.map +0 -1
- package/dist/listbox.d.ts +0 -103
- package/dist/listbox.d.ts.map +0 -1
- package/dist/listbox.js +0 -416
- package/dist/listbox.js.map +0 -1
- package/dist/menu-button.d.ts +0 -10
- package/dist/menu-button.d.ts.map +0 -1
- package/dist/menu-button.js +0 -11
- package/dist/menu-button.js.map +0 -1
- package/dist/menu.d.ts +0 -8
- package/dist/menu.d.ts.map +0 -1
- package/dist/menu.js +0 -11
- package/dist/menu.js.map +0 -1
- package/dist/menubar.d.ts +0 -8
- package/dist/menubar.d.ts.map +0 -1
- package/dist/menubar.js +0 -11
- package/dist/menubar.js.map +0 -1
- package/dist/multi-thumb-slider.d.ts +0 -38
- package/dist/multi-thumb-slider.d.ts.map +0 -1
- package/dist/multi-thumb-slider.js +0 -190
- package/dist/multi-thumb-slider.js.map +0 -1
- package/dist/number-field.d.ts +0 -45
- package/dist/number-field.d.ts.map +0 -1
- package/dist/number-field.js +0 -136
- package/dist/number-field.js.map +0 -1
- package/dist/pagination.d.ts +0 -39
- package/dist/pagination.d.ts.map +0 -1
- package/dist/pagination.js +0 -169
- package/dist/pagination.js.map +0 -1
- package/dist/pin-input.d.ts +0 -27
- package/dist/pin-input.d.ts.map +0 -1
- package/dist/pin-input.js +0 -76
- package/dist/pin-input.js.map +0 -1
- package/dist/quantity-field.d.ts +0 -46
- package/dist/quantity-field.d.ts.map +0 -1
- package/dist/quantity-field.js +0 -172
- package/dist/quantity-field.js.map +0 -1
- package/dist/radio-group.d.ts +0 -40
- package/dist/radio-group.d.ts.map +0 -1
- package/dist/radio-group.js +0 -172
- package/dist/radio-group.js.map +0 -1
- package/dist/rating.d.ts +0 -22
- package/dist/rating.d.ts.map +0 -1
- package/dist/rating.js +0 -38
- package/dist/rating.js.map +0 -1
- package/dist/select.d.ts +0 -45
- package/dist/select.d.ts.map +0 -1
- package/dist/select.js +0 -87
- package/dist/select.js.map +0 -1
- package/dist/slider.d.ts +0 -73
- package/dist/slider.d.ts.map +0 -1
- package/dist/slider.js +0 -265
- package/dist/slider.js.map +0 -1
- package/dist/spin-button.d.ts +0 -41
- package/dist/spin-button.d.ts.map +0 -1
- package/dist/spin-button.js +0 -127
- package/dist/spin-button.js.map +0 -1
- package/dist/stepper.d.ts +0 -24
- package/dist/stepper.d.ts.map +0 -1
- package/dist/stepper.js +0 -32
- package/dist/stepper.js.map +0 -1
- package/dist/switch.d.ts +0 -16
- package/dist/switch.d.ts.map +0 -1
- package/dist/switch.js +0 -12
- package/dist/switch.js.map +0 -1
- package/dist/tabs.d.ts +0 -55
- package/dist/tabs.d.ts.map +0 -1
- package/dist/tabs.js +0 -193
- package/dist/tabs.js.map +0 -1
- package/dist/tags-input.d.ts +0 -32
- package/dist/tags-input.d.ts.map +0 -1
- package/dist/tags-input.js +0 -94
- package/dist/tags-input.js.map +0 -1
- package/dist/text.d.ts +0 -80
- package/dist/text.d.ts.map +0 -1
- package/dist/text.js +0 -203
- package/dist/text.js.map +0 -1
- package/dist/time-field.d.ts +0 -36
- package/dist/time-field.d.ts.map +0 -1
- package/dist/time-field.js +0 -57
- package/dist/time-field.js.map +0 -1
- package/dist/toggle-button.d.ts +0 -16
- package/dist/toggle-button.d.ts.map +0 -1
- package/dist/toggle-button.js +0 -12
- package/dist/toggle-button.js.map +0 -1
- package/dist/toolbar.d.ts +0 -37
- package/dist/toolbar.d.ts.map +0 -1
- package/dist/toolbar.js +0 -148
- package/dist/toolbar.js.map +0 -1
- package/dist/tooltip.d.ts +0 -18
- package/dist/tooltip.d.ts.map +0 -1
- package/dist/tooltip.js +0 -14
- package/dist/tooltip.js.map +0 -1
- package/dist/tree-grid.d.ts +0 -122
- package/dist/tree-grid.d.ts.map +0 -1
- package/dist/tree-grid.js +0 -449
- package/dist/tree-grid.js.map +0 -1
- package/dist/tree-view.d.ts +0 -92
- package/dist/tree-view.d.ts.map +0 -1
- package/dist/tree-view.js +0 -309
- package/dist/tree-view.js.map +0 -1
- package/dist/window-splitter.d.ts +0 -8
- package/dist/window-splitter.d.ts.map +0 -1
- package/dist/window-splitter.js +0 -13
- package/dist/window-splitter.js.map +0 -1
package/dist/calendar.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { createFacadeConnection } from './internal/facade.js';
|
|
2
|
-
import { unwrap } from '@sectile/core/result';
|
|
3
|
-
import { createInteractionState, requireInteraction, } from '@sectile/core/interaction';
|
|
4
|
-
import { applyCalendarEvent, createCalendarState, } from '@sectile/core/calendar';
|
|
5
|
-
import { createGrid } from '@sectile/core/grid';
|
|
6
|
-
import { createRevisionSnapshot, rejectRevisionInput, } from '@sectile/core/revision';
|
|
7
|
-
import { applyControllerEvent, synchronizeControllerState } from './internal/controller.js';
|
|
8
|
-
import { findDelegatedID } from './internal/delegated-event.js';
|
|
9
|
-
import { setInteractionAttributes } from './internal/interaction.js';
|
|
10
|
-
export function createCalendarController(options) {
|
|
11
|
-
const value = options.value !== undefined ? options.value : options.defaultValue ?? null;
|
|
12
|
-
const current = options.highlightedValue !== undefined
|
|
13
|
-
? options.highlightedValue
|
|
14
|
-
: options.defaultHighlightedValue ?? null;
|
|
15
|
-
const initial = createCalendarState(options.grid, {
|
|
16
|
-
selected: value === null ? [] : [value],
|
|
17
|
-
anchor: value,
|
|
18
|
-
current,
|
|
19
|
-
});
|
|
20
|
-
if (!initial.ok)
|
|
21
|
-
return initial;
|
|
22
|
-
const snapshot = createRevisionSnapshot(initial.value);
|
|
23
|
-
if (!snapshot.ok)
|
|
24
|
-
return snapshot;
|
|
25
|
-
const interaction = createInteractionState(options);
|
|
26
|
-
if (!interaction.ok)
|
|
27
|
-
return interaction;
|
|
28
|
-
return { ok: true, value: new DOMCalendarController(options, snapshot.value, interaction.value) };
|
|
29
|
-
}
|
|
30
|
-
export function createCalendar(options) {
|
|
31
|
-
return unwrap(tryCreateCalendar(options));
|
|
32
|
-
}
|
|
33
|
-
export function tryCreateCalendar(options) {
|
|
34
|
-
return createFacadeConnection(options, (options) => tryCreateCalendarConnection(options));
|
|
35
|
-
}
|
|
36
|
-
function tryCreateCalendarConnection(options) {
|
|
37
|
-
const grid = createGrid(options.rows);
|
|
38
|
-
if (!grid.ok)
|
|
39
|
-
return grid;
|
|
40
|
-
const controller = createCalendarController({ ...options, grid: grid.value });
|
|
41
|
-
if (!controller.ok)
|
|
42
|
-
return controller;
|
|
43
|
-
return { ok: true, value: connectCalendar({ ...options, controller: controller.value }) };
|
|
44
|
-
}
|
|
45
|
-
export function connectCalendar(options) {
|
|
46
|
-
return new DOMCalendarConnection(options);
|
|
47
|
-
}
|
|
48
|
-
export function toCalendarEvent(input) {
|
|
49
|
-
if (input.altKey === true || input.ctrlKey === true || input.metaKey === true)
|
|
50
|
-
return null;
|
|
51
|
-
if (input.key === 'ArrowLeft')
|
|
52
|
-
return 'left';
|
|
53
|
-
if (input.key === 'ArrowRight')
|
|
54
|
-
return 'right';
|
|
55
|
-
if (input.key === 'ArrowUp')
|
|
56
|
-
return 'up';
|
|
57
|
-
if (input.key === 'ArrowDown')
|
|
58
|
-
return 'down';
|
|
59
|
-
if (input.key === ' ' || input.key === 'Enter')
|
|
60
|
-
return 'select';
|
|
61
|
-
if (input.key === 'PageUp')
|
|
62
|
-
return 'previous-page';
|
|
63
|
-
if (input.key === 'PageDown')
|
|
64
|
-
return 'next-page';
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
export function toCalendarEffect(command) {
|
|
68
|
-
return Object.freeze(command.type === 'focus'
|
|
69
|
-
? { type: 'focus-element', id: command.id }
|
|
70
|
-
: { type: 'request-page', direction: command.direction, from: command.from });
|
|
71
|
-
}
|
|
72
|
-
class DOMCalendarConnection {
|
|
73
|
-
grid;
|
|
74
|
-
#controller;
|
|
75
|
-
#root;
|
|
76
|
-
#onPageRequest;
|
|
77
|
-
#onTransition;
|
|
78
|
-
#onUpdate;
|
|
79
|
-
#handleKeydown;
|
|
80
|
-
#handleClick;
|
|
81
|
-
constructor(options) {
|
|
82
|
-
this.#controller = options.controller;
|
|
83
|
-
this.grid = options.controller.grid;
|
|
84
|
-
this.#root = options.root;
|
|
85
|
-
this.#onPageRequest = options.onPageRequest;
|
|
86
|
-
this.#onTransition = options.onTransition;
|
|
87
|
-
this.#onUpdate = options.onUpdate;
|
|
88
|
-
setInteractionAttributes(this.#root, options);
|
|
89
|
-
this.#handleKeydown = (event) => {
|
|
90
|
-
if (this.handleKeyboardEvent(event))
|
|
91
|
-
event.preventDefault();
|
|
92
|
-
};
|
|
93
|
-
this.#handleClick = (event) => {
|
|
94
|
-
const id = findDelegatedID(event.target, this.#root, 'calendarId');
|
|
95
|
-
if (id !== null)
|
|
96
|
-
this.handleEvent({ type: 'select', id: id });
|
|
97
|
-
};
|
|
98
|
-
this.#root.addEventListener('keydown', this.#handleKeydown);
|
|
99
|
-
this.#root.addEventListener('click', this.#handleClick);
|
|
100
|
-
}
|
|
101
|
-
getSnapshot() {
|
|
102
|
-
return this.#controller.getSnapshot();
|
|
103
|
-
}
|
|
104
|
-
syncControlledValues(values) {
|
|
105
|
-
const result = this.#controller.syncControlledValues(values);
|
|
106
|
-
if (result.ok) {
|
|
107
|
-
this.#onUpdate?.();
|
|
108
|
-
this.focusCurrent();
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
setCalendarAttributes(label) {
|
|
113
|
-
this.#root.setAttribute('role', 'grid');
|
|
114
|
-
this.#root.setAttribute('aria-rowcount', String(this.grid.rowCount));
|
|
115
|
-
this.#root.setAttribute('aria-colcount', String(this.grid.columnCount));
|
|
116
|
-
if (label === undefined)
|
|
117
|
-
this.#root.removeAttribute('aria-label');
|
|
118
|
-
else
|
|
119
|
-
this.#root.setAttribute('aria-label', label);
|
|
120
|
-
}
|
|
121
|
-
setCellAttributes(element, attributes) {
|
|
122
|
-
const state = this.#controller.getSnapshot().state;
|
|
123
|
-
element.dataset['calendarId'] = String(attributes.id);
|
|
124
|
-
element.tabIndex = state.cursor.current === attributes.id ? 0 : -1;
|
|
125
|
-
element.setAttribute('role', 'gridcell');
|
|
126
|
-
element.setAttribute('aria-rowindex', String(attributes.rowIndex));
|
|
127
|
-
element.setAttribute('aria-colindex', String(attributes.columnIndex));
|
|
128
|
-
element.setAttribute('aria-selected', String(state.selection.has(attributes.id)));
|
|
129
|
-
if (attributes.disabled === true)
|
|
130
|
-
element.setAttribute('aria-disabled', 'true');
|
|
131
|
-
else
|
|
132
|
-
element.removeAttribute('aria-disabled');
|
|
133
|
-
}
|
|
134
|
-
handleKeyboardEvent(event) {
|
|
135
|
-
const input = {
|
|
136
|
-
key: event.key,
|
|
137
|
-
altKey: event.altKey,
|
|
138
|
-
ctrlKey: event.ctrlKey,
|
|
139
|
-
metaKey: event.metaKey,
|
|
140
|
-
};
|
|
141
|
-
const semanticEvent = toCalendarEvent(input);
|
|
142
|
-
if (semanticEvent === null)
|
|
143
|
-
return false;
|
|
144
|
-
return this.handleEvent(semanticEvent);
|
|
145
|
-
}
|
|
146
|
-
handleEvent(event) {
|
|
147
|
-
const result = this.#controller.handleEvent(event);
|
|
148
|
-
if (result.ok)
|
|
149
|
-
this.#applyEffects(result.commands);
|
|
150
|
-
this.#onTransition?.(Object.freeze({ event, result }));
|
|
151
|
-
if (result.ok) {
|
|
152
|
-
this.#onUpdate?.();
|
|
153
|
-
this.focusCurrent();
|
|
154
|
-
}
|
|
155
|
-
return result.ok;
|
|
156
|
-
}
|
|
157
|
-
focusCurrent() {
|
|
158
|
-
queueMicrotask(() => {
|
|
159
|
-
const current = this.#controller.getSnapshot().state.cursor.current;
|
|
160
|
-
if (current === null) {
|
|
161
|
-
this.#root.focus();
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
for (const element of this.#root.querySelectorAll('[data-calendar-id]')) {
|
|
165
|
-
if (element.dataset['calendarId'] !== String(current))
|
|
166
|
-
continue;
|
|
167
|
-
element.focus();
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
disconnect() {
|
|
173
|
-
this.#root.removeEventListener('keydown', this.#handleKeydown);
|
|
174
|
-
this.#root.removeEventListener('click', this.#handleClick);
|
|
175
|
-
}
|
|
176
|
-
#applyEffects(effects) {
|
|
177
|
-
for (const effect of effects) {
|
|
178
|
-
if (effect.type !== 'request-page')
|
|
179
|
-
continue;
|
|
180
|
-
this.#onPageRequest?.(Object.freeze({ direction: effect.direction, from: effect.from }));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
class DOMCalendarController {
|
|
185
|
-
grid;
|
|
186
|
-
#grid;
|
|
187
|
-
#policies;
|
|
188
|
-
#valueControlled;
|
|
189
|
-
#highlightControlled;
|
|
190
|
-
#onValueChange;
|
|
191
|
-
#onHighlightedValueChange;
|
|
192
|
-
#interaction;
|
|
193
|
-
#snapshot;
|
|
194
|
-
constructor(options, snapshot, interaction) {
|
|
195
|
-
this.grid = options.grid;
|
|
196
|
-
this.#grid = options.grid;
|
|
197
|
-
this.#policies = options.policies ?? {};
|
|
198
|
-
this.#valueControlled = options.value !== undefined;
|
|
199
|
-
this.#highlightControlled = options.highlightedValue !== undefined;
|
|
200
|
-
this.#onValueChange = options.onValueChange;
|
|
201
|
-
this.#onHighlightedValueChange = options.onHighlightedValueChange;
|
|
202
|
-
this.#interaction = interaction;
|
|
203
|
-
this.#snapshot = snapshot;
|
|
204
|
-
}
|
|
205
|
-
getSnapshot() {
|
|
206
|
-
return this.#snapshot;
|
|
207
|
-
}
|
|
208
|
-
syncControlledValues(values) {
|
|
209
|
-
const error = controlledInputError(this.#valueControlled, this.#highlightControlled, values);
|
|
210
|
-
if (error !== null)
|
|
211
|
-
return { ok: false, error };
|
|
212
|
-
const selected = this.#valueControlled
|
|
213
|
-
? values.value
|
|
214
|
-
: selectedValue(this.#snapshot.state);
|
|
215
|
-
const state = createCalendarState(this.#grid, {
|
|
216
|
-
selected: selected === null ? [] : [selected],
|
|
217
|
-
anchor: this.#valueControlled ? selected : this.#snapshot.state.selection.anchor,
|
|
218
|
-
current: this.#highlightControlled
|
|
219
|
-
? values.highlightedValue
|
|
220
|
-
: this.#snapshot.state.cursor.current,
|
|
221
|
-
});
|
|
222
|
-
const snapshot = synchronizeControllerState(this.#snapshot, state);
|
|
223
|
-
if (!snapshot.ok)
|
|
224
|
-
return snapshot;
|
|
225
|
-
this.#snapshot = snapshot.value;
|
|
226
|
-
return snapshot;
|
|
227
|
-
}
|
|
228
|
-
handleKeyboardInput(input, expectedRevision = this.#snapshot.revision) {
|
|
229
|
-
const event = toCalendarEvent(input);
|
|
230
|
-
if (event === null) {
|
|
231
|
-
return rejectRevisionInput(this.#snapshot, {
|
|
232
|
-
class: 'transition-rejection',
|
|
233
|
-
code: 'unsupported-dom-key',
|
|
234
|
-
message: 'DOM keyboard input does not map to a calendar semantic event.',
|
|
235
|
-
details: { key: input.key },
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
return this.handleEvent(event, expectedRevision);
|
|
239
|
-
}
|
|
240
|
-
handleEvent(event, expectedRevision = this.#snapshot.revision) {
|
|
241
|
-
const permitted = requireInteraction(this.#interaction, 'navigate');
|
|
242
|
-
if (!permitted.ok)
|
|
243
|
-
return rejectRevisionInput(this.#snapshot, permitted.error);
|
|
244
|
-
const result = applyControllerEvent(this.#snapshot, expectedRevision, event, (state, semanticEvent) => applyCalendarEvent(this.#grid, state, semanticEvent, this.#policies), (previous, proposed) => controlledState(this.#grid, previous, proposed, this.#valueControlled, this.#highlightControlled), (previous, proposed) => this.#notify(previous, proposed), toCalendarEffect);
|
|
245
|
-
if (result.ok)
|
|
246
|
-
this.#snapshot = result.snapshot;
|
|
247
|
-
return result;
|
|
248
|
-
}
|
|
249
|
-
#notify(previous, proposed) {
|
|
250
|
-
const previousValue = selectedValue(previous);
|
|
251
|
-
const value = selectedValue(proposed);
|
|
252
|
-
if (previousValue !== value) {
|
|
253
|
-
this.#onValueChange?.(Object.freeze({ value, previousValue }));
|
|
254
|
-
}
|
|
255
|
-
if (previous.cursor.current !== proposed.cursor.current) {
|
|
256
|
-
this.#onHighlightedValueChange?.(Object.freeze({
|
|
257
|
-
value: proposed.cursor.current,
|
|
258
|
-
previousValue: previous.cursor.current,
|
|
259
|
-
}));
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
function controlledState(grid, previous, proposed, valueControlled, highlightControlled) {
|
|
264
|
-
return createCalendarState(grid, {
|
|
265
|
-
selected: valueControlled ? previous.selection.selected : proposed.selection.selected,
|
|
266
|
-
anchor: valueControlled ? previous.selection.anchor : proposed.selection.anchor,
|
|
267
|
-
current: highlightControlled ? previous.cursor.current : proposed.cursor.current,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
function selectedValue(state) {
|
|
271
|
-
return state.selection.selected[0] ?? null;
|
|
272
|
-
}
|
|
273
|
-
function controlledInputError(valueControlled, highlightControlled, values) {
|
|
274
|
-
if (valueControlled !== (values.value !== undefined)) {
|
|
275
|
-
return {
|
|
276
|
-
class: 'construction',
|
|
277
|
-
code: valueControlled ? 'controlled-value-required' : 'uncontrolled-value-update',
|
|
278
|
-
message: valueControlled
|
|
279
|
-
? 'Controlled calendar selection sync requires value.'
|
|
280
|
-
: 'Uncontrolled calendar selection cannot be synchronized externally.',
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
if (highlightControlled !== (values.highlightedValue !== undefined)) {
|
|
284
|
-
return {
|
|
285
|
-
class: 'construction',
|
|
286
|
-
code: highlightControlled
|
|
287
|
-
? 'controlled-highlighted-value-required'
|
|
288
|
-
: 'uncontrolled-highlighted-value-update',
|
|
289
|
-
message: highlightControlled
|
|
290
|
-
? 'Controlled calendar highlight sync requires highlightedValue.'
|
|
291
|
-
: 'Uncontrolled calendar highlight cannot be synchronized externally.',
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
//# sourceMappingURL=calendar.js.map
|
package/dist/calendar.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../src/calendar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAyB,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EACL,sBAAsB,EACtB,kBAAkB,GAEnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,GAKpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAa,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EACL,sBAAsB,EACtB,mBAAmB,GAGpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAqGrE,MAAM,UAAU,wBAAwB,CACtC,OAAsC;IAEtC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,KAAK,SAAS,CAA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AC,IAAI,IAAI,CAAC;AAC7C,CAAC;AAED,SAAS,oBAAoB,CAC3B,eAAwB,EACxB,mBAA4B,EAC5B,MAAoC;IAEpC,IAAI,eAAe,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE,CAAC;QACrD,OAAO;YACL,KAAK,EAAE,cAAc;YACrB,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,2BAA2B;YACjF,OAAO,EAAE,eAAe;gBACtB,CAAC,CAAC,oDAAoD;gBACtD,CAAC,CAAC,oEAAoE;SACzE,CAAC;IACJ,CAAC;IACD,IAAI,mBAAmB,KAAK,CAAC,MAAM,CAAC,gBAAgB,KAAK,SAAS,CAAC,EAAE,CAAC;QACpE,OAAO;YACL,KAAK,EAAE,cAAc;YACrB,IAAI,EAAE,mBAAmB;gBACvB,CAAC,CAAC,uCAAuC;gBACzC,CAAC,CAAC,uCAAuC;YAC3C,OAAO,EAAE,mBAAmB;gBAC1B,CAAC,CAAC,+DAA+D;gBACjE,CAAC,CAAC,oEAAoE;SACzE,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/carousel.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { type FacadeConnection } from './internal/facade.js';
|
|
2
|
-
import type { Result, StableID } from '@sectile/core';
|
|
3
|
-
import { type CarouselEvent, type CarouselPolicies, type CarouselPosition, type CarouselState } from '@sectile/core/carousel';
|
|
4
|
-
import type { RevisionSnapshot } from '@sectile/core/revision';
|
|
5
|
-
export interface CarouselScheduler {
|
|
6
|
-
schedule(callback: () => void, delayMs: number): unknown;
|
|
7
|
-
cancel(token: unknown): void;
|
|
8
|
-
}
|
|
9
|
-
export interface CarouselAutoplayOptions {
|
|
10
|
-
readonly delayMs?: number;
|
|
11
|
-
readonly pauseOnHover?: boolean;
|
|
12
|
-
readonly pauseOnFocus?: boolean;
|
|
13
|
-
readonly stopOnInteraction?: boolean;
|
|
14
|
-
readonly scheduler?: CarouselScheduler;
|
|
15
|
-
}
|
|
16
|
-
export interface CarouselOptions<ID extends StableID = StableID> {
|
|
17
|
-
readonly root: HTMLElement;
|
|
18
|
-
readonly slides: readonly ID[];
|
|
19
|
-
readonly value?: ID | null;
|
|
20
|
-
readonly defaultValue?: ID | null;
|
|
21
|
-
readonly paused?: boolean;
|
|
22
|
-
readonly defaultPaused?: boolean;
|
|
23
|
-
readonly disabled?: boolean;
|
|
24
|
-
readonly policies?: CarouselPolicies;
|
|
25
|
-
readonly orientation?: 'horizontal' | 'vertical';
|
|
26
|
-
readonly autoplay?: boolean | CarouselAutoplayOptions;
|
|
27
|
-
readonly label?: string;
|
|
28
|
-
readonly previousButton?: HTMLElement;
|
|
29
|
-
readonly nextButton?: HTMLElement;
|
|
30
|
-
readonly pauseButton?: HTMLElement;
|
|
31
|
-
readonly indicatorGroup?: HTMLElement;
|
|
32
|
-
readonly getSlideLabel?: (id: ID, index: number, count: number) => string;
|
|
33
|
-
readonly getIndicatorLabel?: (id: ID, index: number, count: number) => string;
|
|
34
|
-
readonly onValueChange?: (value: ID | null) => void;
|
|
35
|
-
readonly onPausedChange?: (paused: boolean) => void;
|
|
36
|
-
readonly onAnnounce?: (id: ID) => void;
|
|
37
|
-
readonly onUpdate?: () => void;
|
|
38
|
-
}
|
|
39
|
-
export interface CarouselControlledValues<ID extends StableID = StableID> {
|
|
40
|
-
readonly value?: ID | null;
|
|
41
|
-
readonly paused?: boolean;
|
|
42
|
-
}
|
|
43
|
-
export interface CarouselConnection<ID extends StableID = StableID> {
|
|
44
|
-
getSnapshot(): RevisionSnapshot<CarouselState<ID>>;
|
|
45
|
-
getPosition(): CarouselPosition;
|
|
46
|
-
syncControlledValues(values: CarouselControlledValues<ID>): Result<RevisionSnapshot<CarouselState<ID>>>;
|
|
47
|
-
setSlideAttributes(element: HTMLElement, id: ID): void;
|
|
48
|
-
setIndicatorAttributes(element: HTMLElement, id: ID): void;
|
|
49
|
-
handleEvent(event: CarouselEvent<ID>): boolean;
|
|
50
|
-
disconnect(): void;
|
|
51
|
-
}
|
|
52
|
-
export declare function createCarousel<ID extends StableID>(options: CarouselOptions<ID>): FacadeConnection<CarouselConnection<ID>>;
|
|
53
|
-
export declare function tryCreateCarousel<ID extends StableID>(options: CarouselOptions<ID>): Result<FacadeConnection<CarouselConnection<ID>>>;
|
|
54
|
-
//# sourceMappingURL=carousel.d.ts.map
|
package/dist/carousel.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"carousel.d.ts","sourceRoot":"","sources":["../src/carousel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAErF,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI/D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IACzD,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;CACxC;AAED,MAAM,WAAW,eAAe,CAAC,EAAE,SAAS,QAAQ,GAAG,QAAQ;I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ED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import { createFacadeConnection } from './internal/facade.js';
|
|
2
|
-
import { unwrap } from '@sectile/core/result';
|
|
3
|
-
import { createSequence } from '@sectile/core/sequence';
|
|
4
|
-
import { applyCarouselEvent, createCarouselState, getCarouselPosition, isCarouselRotationPaused, } from '@sectile/core/carousel';
|
|
5
|
-
import { createSemanticController } from './internal/semantic-controller.js';
|
|
6
|
-
import { setInteractionAttributes } from './internal/interaction.js';
|
|
7
|
-
export function createCarousel(options) {
|
|
8
|
-
return unwrap(tryCreateCarousel(options));
|
|
9
|
-
}
|
|
10
|
-
export function tryCreateCarousel(options) {
|
|
11
|
-
return createFacadeConnection(options, (options) => tryCreateCarouselConnection(options));
|
|
12
|
-
}
|
|
13
|
-
function tryCreateCarouselConnection(options) {
|
|
14
|
-
const slides = createSequence(options.slides);
|
|
15
|
-
if (!slides.ok)
|
|
16
|
-
return slides;
|
|
17
|
-
const autoplay = normalizeAutoplay(options);
|
|
18
|
-
if (!autoplay.ok)
|
|
19
|
-
return autoplay;
|
|
20
|
-
const valueControlled = options.value !== undefined;
|
|
21
|
-
const pausedControlled = options.paused !== undefined;
|
|
22
|
-
const runtime = createSemanticController({
|
|
23
|
-
initial: createCarouselState(slides.value, options.value !== undefined ? options.value : options.defaultValue ?? options.slides[0] ?? null, options.paused ?? options.defaultPaused ?? false),
|
|
24
|
-
reducer: (state, event) => applyCarouselEvent(slides.value, state, event, options.policies),
|
|
25
|
-
reconcile: (previous, proposed) => createCarouselState(slides.value, valueControlled ? previous.cursor.current : proposed.cursor.current, pausedControlled ? previous.paused : proposed.paused, proposed.pauseReasons),
|
|
26
|
-
notify: (previous, proposed) => {
|
|
27
|
-
if (previous.cursor.current !== proposed.cursor.current)
|
|
28
|
-
options.onValueChange?.(proposed.cursor.current);
|
|
29
|
-
if (previous.paused !== proposed.paused)
|
|
30
|
-
options.onPausedChange?.(proposed.paused);
|
|
31
|
-
},
|
|
32
|
-
toEffect: (command) => command,
|
|
33
|
-
interaction: options,
|
|
34
|
-
});
|
|
35
|
-
return runtime.ok
|
|
36
|
-
? { ok: true, value: new DOMCarousel(options, slides.value, runtime.value, autoplay.value, valueControlled, pausedControlled) }
|
|
37
|
-
: runtime;
|
|
38
|
-
}
|
|
39
|
-
class DOMCarousel {
|
|
40
|
-
#options;
|
|
41
|
-
#slides;
|
|
42
|
-
#runtime;
|
|
43
|
-
#autoplay;
|
|
44
|
-
#valueControlled;
|
|
45
|
-
#pausedControlled;
|
|
46
|
-
#slideElements = new Map();
|
|
47
|
-
#indicatorElements = new Map();
|
|
48
|
-
#baseID;
|
|
49
|
-
#keydown;
|
|
50
|
-
#previous;
|
|
51
|
-
#next;
|
|
52
|
-
#pause;
|
|
53
|
-
#mouseenter;
|
|
54
|
-
#mouseleave;
|
|
55
|
-
#focusin;
|
|
56
|
-
#focusout;
|
|
57
|
-
#timer = noCarouselTimer;
|
|
58
|
-
constructor(options, slides, runtime, autoplay, valueControlled, pausedControlled) {
|
|
59
|
-
this.#options = options;
|
|
60
|
-
this.#slides = slides;
|
|
61
|
-
this.#runtime = runtime;
|
|
62
|
-
this.#autoplay = autoplay;
|
|
63
|
-
this.#valueControlled = valueControlled;
|
|
64
|
-
this.#pausedControlled = pausedControlled;
|
|
65
|
-
this.#baseID = options.root.id || `sectile-carousel-${nextCarouselID++}`;
|
|
66
|
-
if (!options.root.id)
|
|
67
|
-
options.root.id = this.#baseID;
|
|
68
|
-
this.#keydown = (event) => {
|
|
69
|
-
if (event.key === ' ' && event.target !== options.root)
|
|
70
|
-
return;
|
|
71
|
-
const vertical = options.orientation === 'vertical';
|
|
72
|
-
const semantic = event.key === (vertical ? 'ArrowDown' : 'ArrowRight') ? 'next'
|
|
73
|
-
: event.key === (vertical ? 'ArrowUp' : 'ArrowLeft') ? 'previous'
|
|
74
|
-
: event.key === 'Home' ? 'first'
|
|
75
|
-
: event.key === 'End' ? 'last'
|
|
76
|
-
: event.key === ' ' ? 'toggle-pause'
|
|
77
|
-
: null;
|
|
78
|
-
if (semantic !== null) {
|
|
79
|
-
this.#handleInteraction(semantic);
|
|
80
|
-
event.preventDefault();
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
this.#previous = () => { this.#handleInteraction('previous'); };
|
|
84
|
-
this.#next = () => { this.#handleInteraction('next'); };
|
|
85
|
-
this.#pause = () => {
|
|
86
|
-
this.handleEvent('toggle-pause');
|
|
87
|
-
const state = this.getSnapshot().state;
|
|
88
|
-
if (!state.paused && state.pauseReasons.includes('focus'))
|
|
89
|
-
this.handleEvent({ type: 'resume-for', reason: 'focus' });
|
|
90
|
-
};
|
|
91
|
-
this.#mouseenter = () => { if (this.#autoplay?.pauseOnHover)
|
|
92
|
-
this.handleEvent({ type: 'pause-for', reason: 'hover' }); };
|
|
93
|
-
this.#mouseleave = () => { if (this.#autoplay?.pauseOnHover)
|
|
94
|
-
this.handleEvent({ type: 'resume-for', reason: 'hover' }); };
|
|
95
|
-
this.#focusin = () => { if (this.#autoplay?.pauseOnFocus)
|
|
96
|
-
this.handleEvent({ type: 'pause-for', reason: 'focus' }); };
|
|
97
|
-
this.#focusout = (event) => {
|
|
98
|
-
if (this.#autoplay?.pauseOnFocus && !options.root.contains(event.relatedTarget)) {
|
|
99
|
-
this.handleEvent({ type: 'resume-for', reason: 'focus' });
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
options.root.addEventListener('keydown', this.#keydown);
|
|
103
|
-
setInteractionAttributes(options.root, options);
|
|
104
|
-
if (options.previousButton !== undefined)
|
|
105
|
-
setInteractionAttributes(options.previousButton, options, { native: true });
|
|
106
|
-
if (options.nextButton !== undefined)
|
|
107
|
-
setInteractionAttributes(options.nextButton, options, { native: true });
|
|
108
|
-
if (options.pauseButton !== undefined)
|
|
109
|
-
setInteractionAttributes(options.pauseButton, options, { native: true });
|
|
110
|
-
options.previousButton?.addEventListener('click', this.#previous);
|
|
111
|
-
options.nextButton?.addEventListener('click', this.#next);
|
|
112
|
-
options.pauseButton?.addEventListener('click', this.#pause);
|
|
113
|
-
if (autoplay?.pauseOnHover) {
|
|
114
|
-
options.root.addEventListener('mouseenter', this.#mouseenter);
|
|
115
|
-
options.root.addEventListener('mouseleave', this.#mouseleave);
|
|
116
|
-
}
|
|
117
|
-
if (autoplay?.pauseOnFocus) {
|
|
118
|
-
options.root.addEventListener('focusin', this.#focusin);
|
|
119
|
-
options.root.addEventListener('focusout', this.#focusout);
|
|
120
|
-
}
|
|
121
|
-
options.root.setAttribute('role', 'region');
|
|
122
|
-
options.root.setAttribute('aria-roledescription', 'carousel');
|
|
123
|
-
if (options.label !== undefined)
|
|
124
|
-
options.root.setAttribute('aria-label', options.label);
|
|
125
|
-
if (options.indicatorGroup !== undefined) {
|
|
126
|
-
options.indicatorGroup.setAttribute('role', 'tablist');
|
|
127
|
-
options.indicatorGroup.setAttribute('aria-label', 'Choose slide');
|
|
128
|
-
options.indicatorGroup.setAttribute('aria-orientation', options.orientation ?? 'horizontal');
|
|
129
|
-
}
|
|
130
|
-
this.#refresh();
|
|
131
|
-
this.#resetTimer();
|
|
132
|
-
}
|
|
133
|
-
getSnapshot() { return this.#runtime.getSnapshot(); }
|
|
134
|
-
getPosition() { return getCarouselPosition(this.#slides, this.getSnapshot().state); }
|
|
135
|
-
syncControlledValues(values) {
|
|
136
|
-
if (this.#valueControlled !== (values.value !== undefined) || this.#pausedControlled !== (values.paused !== undefined)) {
|
|
137
|
-
return { ok: false, error: { class: 'construction', code: 'controlled-shape-mismatch', message: 'Controlled carousel values must preserve their construction-time shape.' } };
|
|
138
|
-
}
|
|
139
|
-
const state = this.getSnapshot().state;
|
|
140
|
-
const result = this.#runtime.replace(createCarouselState(this.#slides, this.#valueControlled ? values.value : state.cursor.current, this.#pausedControlled ? values.paused : state.paused, state.pauseReasons));
|
|
141
|
-
if (result.ok) {
|
|
142
|
-
this.#refresh();
|
|
143
|
-
this.#resetTimer();
|
|
144
|
-
this.#options.onUpdate?.();
|
|
145
|
-
}
|
|
146
|
-
return result;
|
|
147
|
-
}
|
|
148
|
-
setSlideAttributes(element, id) {
|
|
149
|
-
if (!this.#slides.contains(id))
|
|
150
|
-
return;
|
|
151
|
-
this.#slideElements.set(id, element);
|
|
152
|
-
this.#refresh();
|
|
153
|
-
}
|
|
154
|
-
setIndicatorAttributes(element, id) {
|
|
155
|
-
if (!this.#slides.contains(id))
|
|
156
|
-
return;
|
|
157
|
-
const previous = this.#indicatorElements.get(id);
|
|
158
|
-
if (previous !== undefined)
|
|
159
|
-
previous.element.removeEventListener('click', previous.listener);
|
|
160
|
-
const listener = () => { this.#handleInteraction({ type: 'focus', id }); };
|
|
161
|
-
this.#indicatorElements.set(id, { element, listener });
|
|
162
|
-
element.addEventListener('click', listener);
|
|
163
|
-
this.#refresh();
|
|
164
|
-
}
|
|
165
|
-
handleEvent(event) {
|
|
166
|
-
const before = this.getSnapshot().state.cursor.current;
|
|
167
|
-
const result = this.#runtime.handle(event);
|
|
168
|
-
if (result.ok) {
|
|
169
|
-
for (const command of result.commands)
|
|
170
|
-
this.#options.onAnnounce?.(command.id);
|
|
171
|
-
this.#refresh();
|
|
172
|
-
this.#resetTimer();
|
|
173
|
-
if (this.#autoplay !== null && this.#options.policies?.wrap === false && event === 'next' && before === this.getSnapshot().state.cursor.current)
|
|
174
|
-
this.#clearTimer();
|
|
175
|
-
}
|
|
176
|
-
this.#options.onUpdate?.();
|
|
177
|
-
return result.ok;
|
|
178
|
-
}
|
|
179
|
-
disconnect() {
|
|
180
|
-
this.#clearTimer();
|
|
181
|
-
this.#options.root.removeEventListener('keydown', this.#keydown);
|
|
182
|
-
this.#options.previousButton?.removeEventListener('click', this.#previous);
|
|
183
|
-
this.#options.nextButton?.removeEventListener('click', this.#next);
|
|
184
|
-
this.#options.pauseButton?.removeEventListener('click', this.#pause);
|
|
185
|
-
this.#options.root.removeEventListener('mouseenter', this.#mouseenter);
|
|
186
|
-
this.#options.root.removeEventListener('mouseleave', this.#mouseleave);
|
|
187
|
-
this.#options.root.removeEventListener('focusin', this.#focusin);
|
|
188
|
-
this.#options.root.removeEventListener('focusout', this.#focusout);
|
|
189
|
-
for (const { element, listener } of this.#indicatorElements.values())
|
|
190
|
-
element.removeEventListener('click', listener);
|
|
191
|
-
this.#slideElements.clear();
|
|
192
|
-
this.#indicatorElements.clear();
|
|
193
|
-
}
|
|
194
|
-
#handleInteraction(event) {
|
|
195
|
-
this.handleEvent(event);
|
|
196
|
-
if (this.#autoplay?.stopOnInteraction && isMovementEvent(event))
|
|
197
|
-
this.handleEvent('pause');
|
|
198
|
-
}
|
|
199
|
-
#refresh() {
|
|
200
|
-
const state = this.getSnapshot().state;
|
|
201
|
-
const position = this.getPosition();
|
|
202
|
-
for (const [id, element] of this.#slideElements) {
|
|
203
|
-
const index = this.#slides.indexOf(id);
|
|
204
|
-
element.id = this.#slideID(id);
|
|
205
|
-
element.setAttribute('role', 'group');
|
|
206
|
-
element.setAttribute('aria-roledescription', 'slide');
|
|
207
|
-
if (index !== null)
|
|
208
|
-
element.setAttribute('aria-label', this.#options.getSlideLabel?.(id, index, this.#slides.size) ?? `${index + 1} of ${this.#slides.size}`);
|
|
209
|
-
element.hidden = id !== state.cursor.current;
|
|
210
|
-
}
|
|
211
|
-
for (const [id, binding] of this.#indicatorElements) {
|
|
212
|
-
const index = this.#slides.indexOf(id);
|
|
213
|
-
const selected = id === state.cursor.current;
|
|
214
|
-
binding.element.setAttribute('role', 'tab');
|
|
215
|
-
binding.element.setAttribute('aria-controls', this.#slideID(id));
|
|
216
|
-
binding.element.setAttribute('aria-selected', String(selected));
|
|
217
|
-
if (index !== null)
|
|
218
|
-
binding.element.setAttribute('aria-label', this.#options.getIndicatorLabel?.(id, index, this.#slides.size) ?? `Go to slide ${index + 1}`);
|
|
219
|
-
binding.element.tabIndex = selected ? 0 : -1;
|
|
220
|
-
}
|
|
221
|
-
const bounded = this.#options.policies?.wrap === false;
|
|
222
|
-
setDisabled(this.#options.previousButton, position.count < 2 || bounded && position.index === 0);
|
|
223
|
-
setDisabled(this.#options.nextButton, position.count < 2 || bounded && position.index === position.count - 1);
|
|
224
|
-
if (this.#options.pauseButton !== undefined) {
|
|
225
|
-
this.#options.pauseButton.setAttribute('aria-pressed', String(state.paused));
|
|
226
|
-
this.#options.pauseButton.setAttribute('aria-label', state.paused ? 'Resume automatic rotation' : 'Pause automatic rotation');
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
#slideID(id) {
|
|
230
|
-
const index = this.#slides.indexOf(id);
|
|
231
|
-
return `${this.#baseID}-slide-${index === null ? 'unknown' : index + 1}`;
|
|
232
|
-
}
|
|
233
|
-
#resetTimer() {
|
|
234
|
-
this.#clearTimer();
|
|
235
|
-
if (this.#autoplay === null || this.#slides.size < 2 || isCarouselRotationPaused(this.getSnapshot().state))
|
|
236
|
-
return;
|
|
237
|
-
this.#timer = this.#autoplay.scheduler.schedule(() => {
|
|
238
|
-
this.#timer = noCarouselTimer;
|
|
239
|
-
this.handleEvent('next');
|
|
240
|
-
}, this.#autoplay.delayMs);
|
|
241
|
-
}
|
|
242
|
-
#clearTimer() {
|
|
243
|
-
if (this.#timer === noCarouselTimer || this.#autoplay === null)
|
|
244
|
-
return;
|
|
245
|
-
this.#autoplay.scheduler.cancel(this.#timer);
|
|
246
|
-
this.#timer = noCarouselTimer;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
let nextCarouselID = 1;
|
|
250
|
-
const noCarouselTimer = Symbol('no-carousel-timer');
|
|
251
|
-
function normalizeAutoplay(options) {
|
|
252
|
-
if (options.autoplay === undefined || options.autoplay === false)
|
|
253
|
-
return { ok: true, value: null };
|
|
254
|
-
const config = options.autoplay === true ? {} : options.autoplay;
|
|
255
|
-
const delayMs = config.delayMs ?? 5000;
|
|
256
|
-
if (!Number.isFinite(delayMs) || delayMs <= 0) {
|
|
257
|
-
return { ok: false, error: { class: 'construction', code: 'carousel-autoplay-delay-invalid', message: 'Carousel autoplay delay must be a positive finite number.' } };
|
|
258
|
-
}
|
|
259
|
-
const timerHost = options.root.ownerDocument?.defaultView ?? globalThis;
|
|
260
|
-
const scheduler = config.scheduler ?? {
|
|
261
|
-
schedule: (callback, delay) => timerHost.setTimeout(callback, delay),
|
|
262
|
-
cancel: (token) => { timerHost.clearTimeout(token); },
|
|
263
|
-
};
|
|
264
|
-
return {
|
|
265
|
-
ok: true,
|
|
266
|
-
value: {
|
|
267
|
-
delayMs,
|
|
268
|
-
pauseOnHover: config.pauseOnHover ?? true,
|
|
269
|
-
pauseOnFocus: config.pauseOnFocus ?? true,
|
|
270
|
-
stopOnInteraction: config.stopOnInteraction ?? true,
|
|
271
|
-
scheduler,
|
|
272
|
-
},
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
function isMovementEvent(event) {
|
|
276
|
-
return event === 'next' || event === 'previous' || event === 'first' || event === 'last' || typeof event === 'object' && event.type === 'focus';
|
|
277
|
-
}
|
|
278
|
-
function setDisabled(element, disabled) {
|
|
279
|
-
if (element === undefined)
|
|
280
|
-
return;
|
|
281
|
-
element.setAttribute('aria-disabled', String(disabled));
|
|
282
|
-
if ('disabled' in element)
|
|
283
|
-
element.disabled = disabled;
|
|
284
|
-
}
|
|
285
|
-
//# sourceMappingURL=carousel.js.map
|