stimeo-ui 0.18.1 → 0.19.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -0
- data/dist/cable/index.js +6 -5
- data/dist/controllers/alert_dialog_controller.js +324 -76
- data/dist/controllers/announcer_controller.js +22 -9
- data/dist/controllers/auto_submit_controller.js +103 -16
- data/dist/controllers/avatar_controller.js +29 -9
- data/dist/controllers/breadcrumb_controller.js +205 -17
- data/dist/controllers/bulk_select_controller.js +31 -13
- data/dist/controllers/calendar_controller.js +242 -7
- data/dist/controllers/carousel_controller.js +70 -15
- data/dist/controllers/character_counter_controller.js +103 -16
- data/dist/controllers/clipboard_controller.js +6 -5
- data/dist/controllers/collapsible_controller.js +35 -8
- data/dist/controllers/combobox_controller.js +155 -26
- data/dist/controllers/command_palette_controller.js +445 -117
- data/dist/controllers/conditional_fields_controller.js +84 -44
- data/dist/controllers/confirm_controller.js +303 -68
- data/dist/controllers/context_menu_controller.js +59 -30
- data/dist/controllers/countdown_controller.js +6 -5
- data/dist/controllers/currency_input_controller.js +72 -7
- data/dist/controllers/data_grid_controller.js +273 -51
- data/dist/controllers/date_range_picker_controller.js +27 -5
- data/dist/controllers/dialog_controller.js +330 -79
- data/dist/controllers/direct_upload_controller.js +6 -5
- data/dist/controllers/dismissible_controller.js +68 -18
- data/dist/controllers/drawer_controller.js +362 -92
- data/dist/controllers/dropdown_controller.js +64 -52
- data/dist/controllers/editable_controller.js +140 -12
- data/dist/controllers/empty_state_controller.js +193 -9
- data/dist/controllers/file_dropzone_controller.js +313 -23
- data/dist/controllers/filter_controller.js +194 -5
- data/dist/controllers/flash_controller.js +205 -17
- data/dist/controllers/focus_controller.js +273 -57
- data/dist/controllers/form_field_controller.js +71 -14
- data/dist/controllers/form_validation_controller.js +11 -7
- data/dist/controllers/frame_loading_controller.js +75 -20
- data/dist/controllers/hover_card_controller.js +108 -39
- data/dist/controllers/input_mask_controller.js +95 -37
- data/dist/controllers/intersection_controller.js +61 -29
- data/dist/controllers/lazy_frame_controller.js +61 -29
- data/dist/controllers/listbox_controller.js +174 -83
- data/dist/controllers/local_time_controller.js +1 -7
- data/dist/controllers/menu_controller.js +45 -24
- data/dist/controllers/menubar_controller.js +232 -52
- data/dist/controllers/meter_controller.js +31 -9
- data/dist/controllers/multi_select_controller.js +195 -62
- data/dist/controllers/navigation_menu_controller.js +1 -1
- data/dist/controllers/nested_form_controller.js +275 -21
- data/dist/controllers/network_status_controller.js +31 -9
- data/dist/controllers/number_input_controller.js +180 -71
- data/dist/controllers/otp_controller.js +97 -11
- data/dist/controllers/overflow_menu_controller.js +190 -24
- data/dist/controllers/pagination_controller.js +186 -24
- data/dist/controllers/password_reveal_controller.js +25 -4
- data/dist/controllers/password_strength_controller.js +6 -5
- data/dist/controllers/popover_controller.js +466 -42
- data/dist/controllers/progress_controller.js +31 -9
- data/dist/controllers/radio_group_controller.js +279 -88
- data/dist/controllers/range_slider_controller.js +72 -54
- data/dist/controllers/rating_controller.js +58 -10
- data/dist/controllers/read_more_controller.js +191 -25
- data/dist/controllers/relative_time_controller.js +1 -7
- data/dist/controllers/roving_controller.js +204 -8
- data/dist/controllers/scroll_area_controller.js +61 -19
- data/dist/controllers/scroll_visibility_controller.js +25 -4
- data/dist/controllers/scrollspy_controller.js +240 -32
- data/dist/controllers/separator_controller.js +97 -58
- data/dist/controllers/sidebar_controller.js +368 -127
- data/dist/controllers/skeleton_controller.js +75 -20
- data/dist/controllers/slider_controller.js +72 -54
- data/dist/controllers/sortable_controller.js +6 -5
- data/dist/controllers/spinner_controller.js +75 -20
- data/dist/controllers/step_indicator_controller.js +181 -6
- data/dist/controllers/stepper_controller.js +188 -6
- data/dist/controllers/sticky_observer_controller.js +86 -33
- data/dist/controllers/submit_once_controller.js +31 -9
- data/dist/controllers/switch_controller.js +84 -44
- data/dist/controllers/tabs_controller.js +189 -3
- data/dist/controllers/tags_input_controller.js +293 -29
- data/dist/controllers/theme_controller.js +192 -5
- data/dist/controllers/time_picker_controller.js +77 -42
- data/dist/controllers/toast_controller.js +478 -16
- data/dist/controllers/toggle_group_controller.js +282 -79
- data/dist/controllers/toolbar_controller.js +276 -15
- data/dist/controllers/tooltip_controller.js +244 -46
- data/dist/controllers/tree_view_controller.js +287 -57
- data/dist/index.js +2258 -1016
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
|
@@ -7,18 +7,20 @@ function fillTemplate(template, values) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
10
11
|
function announce(message, options = {}) {
|
|
11
12
|
const text = message.trim();
|
|
12
13
|
if (text.length === 0) return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
15
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
16
|
+
});
|
|
17
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
18
|
+
window.dispatchEvent(event);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
21
22
|
if (element.getAttribute(name) === value) return false;
|
|
23
|
+
beforeWrite?.();
|
|
22
24
|
if (value === null) element.removeAttribute(name);
|
|
23
25
|
else element.setAttribute(name, value);
|
|
24
26
|
return true;
|
|
@@ -92,14 +94,34 @@ var AttributeLease = class {
|
|
|
92
94
|
const names = registry.names;
|
|
93
95
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
94
96
|
}
|
|
95
|
-
write(element, value) {
|
|
97
|
+
write(element, value, beforeWrite) {
|
|
96
98
|
const stack = attributeStack(element, this.#attribute);
|
|
97
99
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
98
100
|
this.#held.add(element);
|
|
99
101
|
const shows = !this.#covered(element, stack, hold);
|
|
100
102
|
hold.written = value;
|
|
101
103
|
this.#mark(element, stack);
|
|
102
|
-
if (shows) this.#reflect(element, value);
|
|
104
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
105
|
+
}
|
|
106
|
+
adopt(element, options = {}) {
|
|
107
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
108
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
109
|
+
const stack = attributeStack(element, this.#attribute);
|
|
110
|
+
const hold = this.#take(stack);
|
|
111
|
+
if (!hold) return false;
|
|
112
|
+
const current = element.getAttribute(this.#attribute);
|
|
113
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
this.#held.add(element);
|
|
117
|
+
hold.original = current;
|
|
118
|
+
hold.linked = false;
|
|
119
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
120
|
+
if (!above.linked) break;
|
|
121
|
+
above.original = current;
|
|
122
|
+
}
|
|
123
|
+
this.#mark(element, stack);
|
|
124
|
+
return true;
|
|
103
125
|
}
|
|
104
126
|
return(element) {
|
|
105
127
|
const held = this.#held.delete(element);
|
|
@@ -165,8 +187,8 @@ var AttributeLease = class {
|
|
|
165
187
|
setAttributeIfChanged(element, name, recorded);
|
|
166
188
|
}
|
|
167
189
|
}
|
|
168
|
-
#reflect(element, value) {
|
|
169
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
190
|
+
#reflect(element, value, beforeWrite) {
|
|
191
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
170
192
|
}
|
|
171
193
|
};
|
|
172
194
|
|
|
@@ -209,7 +231,7 @@ var DetachGate = class _DetachGate {
|
|
|
209
231
|
|
|
210
232
|
var MinDurationFloor = class {
|
|
211
233
|
#timers;
|
|
212
|
-
#
|
|
234
|
+
#task = null;
|
|
213
235
|
#since = 0;
|
|
214
236
|
constructor(timers) {
|
|
215
237
|
this.#timers = timers;
|
|
@@ -218,25 +240,19 @@ var MinDurationFloor = class {
|
|
|
218
240
|
this.#since = Date.now();
|
|
219
241
|
}
|
|
220
242
|
get pending() {
|
|
221
|
-
return this.#
|
|
243
|
+
return this.#task?.pending ?? false;
|
|
222
244
|
}
|
|
223
245
|
schedule(minDuration, finish) {
|
|
224
246
|
this.cancel();
|
|
225
247
|
const remaining = minDuration - (Date.now() - this.#since);
|
|
226
248
|
if (remaining > 0) {
|
|
227
|
-
this.#
|
|
228
|
-
this.#timerId = null;
|
|
229
|
-
finish();
|
|
230
|
-
}, remaining);
|
|
249
|
+
this.#task = this.#timers.setTask(finish, remaining);
|
|
231
250
|
} else {
|
|
232
251
|
finish();
|
|
233
252
|
}
|
|
234
253
|
}
|
|
235
254
|
cancel() {
|
|
236
|
-
|
|
237
|
-
this.#timers.clear(this.#timerId);
|
|
238
|
-
this.#timerId = null;
|
|
239
|
-
}
|
|
255
|
+
this.#task?.cancel();
|
|
240
256
|
}
|
|
241
257
|
};
|
|
242
258
|
|
|
@@ -303,6 +319,22 @@ var TimerRegistry = class {
|
|
|
303
319
|
return this.ids.size;
|
|
304
320
|
}
|
|
305
321
|
};
|
|
322
|
+
var TimeoutRegistration = class {
|
|
323
|
+
#registration;
|
|
324
|
+
constructor(owner, id) {
|
|
325
|
+
this.#registration = { owner, id };
|
|
326
|
+
}
|
|
327
|
+
get pending() {
|
|
328
|
+
return this.#registration !== null;
|
|
329
|
+
}
|
|
330
|
+
cancel() {
|
|
331
|
+
const registration = this.#registration;
|
|
332
|
+
if (registration) registration.owner.clear(registration.id);
|
|
333
|
+
}
|
|
334
|
+
expire() {
|
|
335
|
+
this.#registration = null;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
306
338
|
var SafeTimeout = class extends TimerRegistry {
|
|
307
339
|
set(callback, delay) {
|
|
308
340
|
const id = this.schedule(() => {
|
|
@@ -319,6 +351,29 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
319
351
|
window.clearTimeout(id);
|
|
320
352
|
}
|
|
321
353
|
};
|
|
354
|
+
var TaskTimeout = class extends SafeTimeout {
|
|
355
|
+
#tasks = /* @__PURE__ */ new Map();
|
|
356
|
+
setTask(callback, delay) {
|
|
357
|
+
const id = this.set(() => {
|
|
358
|
+
this.#tasks.delete(id);
|
|
359
|
+
registration.expire();
|
|
360
|
+
callback();
|
|
361
|
+
}, delay);
|
|
362
|
+
const registration = new TimeoutRegistration(this, id);
|
|
363
|
+
this.#tasks.set(id, registration);
|
|
364
|
+
return registration;
|
|
365
|
+
}
|
|
366
|
+
clear(id) {
|
|
367
|
+
this.#tasks.get(id)?.expire();
|
|
368
|
+
this.#tasks.delete(id);
|
|
369
|
+
super.clear(id);
|
|
370
|
+
}
|
|
371
|
+
clearAll() {
|
|
372
|
+
for (const registration of this.#tasks.values()) registration.expire();
|
|
373
|
+
this.#tasks.clear();
|
|
374
|
+
super.clearAll();
|
|
375
|
+
}
|
|
376
|
+
};
|
|
322
377
|
|
|
323
378
|
var SkeletonController = class _SkeletonController extends Controller {
|
|
324
379
|
#numbers = new NumberValueReader();
|
|
@@ -332,7 +387,7 @@ var SkeletonController = class _SkeletonController extends Controller {
|
|
|
332
387
|
};
|
|
333
388
|
static actions = ["ready", "reset"];
|
|
334
389
|
static events = ["ready"];
|
|
335
|
-
#timers = new
|
|
390
|
+
#timers = new TaskTimeout();
|
|
336
391
|
#floor = new MinDurationFloor(this.#timers);
|
|
337
392
|
#gate = new DetachGate();
|
|
338
393
|
#hidden = new AttributeLease("hidden", this.identifier);
|
|
@@ -227,25 +227,22 @@ function snapSteppedValue(raw, range) {
|
|
|
227
227
|
if (!(range.min <= range.max)) return finiteFallback(range.min, range.max);
|
|
228
228
|
const input = Number.isNaN(raw) ? finiteFallback(range.min, range.max) : raw;
|
|
229
229
|
const clamped = Math.min(range.max, Math.max(range.min, input));
|
|
230
|
-
const
|
|
231
|
-
const base = stepBase(range);
|
|
230
|
+
const grid = stepGrid(range);
|
|
232
231
|
const candidates = [];
|
|
233
232
|
if (Number.isFinite(range.min)) candidates.push(range.min);
|
|
234
233
|
if (Number.isFinite(range.max)) candidates.push(range.max);
|
|
235
|
-
const
|
|
236
|
-
if (Number.isFinite(
|
|
237
|
-
|
|
238
|
-
|
|
234
|
+
const position = gridPosition(clamped, grid);
|
|
235
|
+
if (Number.isFinite(position)) {
|
|
236
|
+
for (const index of [Math.floor(position), Math.ceil(position)]) {
|
|
237
|
+
const candidate = gridValue(index, grid);
|
|
238
|
+
if (inRange(candidate, range)) candidates.push(candidate);
|
|
239
|
+
}
|
|
239
240
|
}
|
|
240
241
|
if (candidates.length === 0) return clamped;
|
|
241
242
|
let nearest = candidates[0];
|
|
242
|
-
let nearestDistance = Math.abs(clamped - nearest);
|
|
243
243
|
for (const candidate of candidates.slice(1)) {
|
|
244
|
-
const
|
|
245
|
-
if (
|
|
246
|
-
nearest = candidate;
|
|
247
|
-
nearestDistance = distance;
|
|
248
|
-
}
|
|
244
|
+
const nearer = isMidpoint(clamped, candidate, nearest, range, grid) ? candidate > nearest : Math.abs(clamped - candidate) < Math.abs(clamped - nearest);
|
|
245
|
+
if (nearer) nearest = candidate;
|
|
249
246
|
}
|
|
250
247
|
return nearest;
|
|
251
248
|
}
|
|
@@ -254,46 +251,36 @@ function stepSteppedValue(current, count, range) {
|
|
|
254
251
|
const distance = Math.abs(Math.trunc(count));
|
|
255
252
|
if (!Number.isFinite(distance) || distance === 0) return value;
|
|
256
253
|
const direction = Math.sign(count);
|
|
257
|
-
const adjacent =
|
|
254
|
+
const adjacent = nextGridValue(value, direction, range);
|
|
255
|
+
if (adjacent === value) return value;
|
|
258
256
|
const raw = adjacent + direction * (distance - 1) * effectiveStep(range.step);
|
|
259
|
-
|
|
257
|
+
const endpoint = direction > 0 ? range.max : range.min;
|
|
258
|
+
return Number.isFinite(raw) || Number.isFinite(endpoint) ? snapSteppedValue(raw, range) : value;
|
|
260
259
|
}
|
|
261
|
-
function
|
|
260
|
+
function nextGridValue(current, direction, range) {
|
|
261
|
+
const grid = stepGrid(range);
|
|
262
|
+
const position = gridPosition(current, grid);
|
|
263
|
+
if (!Number.isFinite(position)) return current;
|
|
264
|
+
const index = direction > 0 ? Math.floor(position) + 1 : Math.ceil(position) - 1;
|
|
265
|
+
const first = gridValue(index, grid);
|
|
266
|
+
if (direction * (first - current) > 0 && !sameGridValue(first, current, grid.step)) {
|
|
267
|
+
return first;
|
|
268
|
+
}
|
|
269
|
+
const second = gridValue(index + direction, grid);
|
|
270
|
+
return direction * (second - current) > 0 ? second : current;
|
|
271
|
+
}
|
|
272
|
+
function stepGrid(range) {
|
|
262
273
|
const step = effectiveStep(range.step);
|
|
263
274
|
const base = stepBase(range);
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (candidate < current || nearlyEqual(candidate, current)) {
|
|
271
|
-
gridIndex += 1;
|
|
272
|
-
candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
273
|
-
}
|
|
274
|
-
if (candidate > current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
|
|
275
|
-
candidates.push(clamp(candidate, range));
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return clamp(Math.min(...candidates), range);
|
|
279
|
-
}
|
|
280
|
-
const position = (current - base) / step;
|
|
281
|
-
if (Number.isFinite(position)) {
|
|
282
|
-
let gridIndex = Math.ceil(position) - 1;
|
|
283
|
-
let candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
284
|
-
if (candidate > current || nearlyEqual(candidate, current)) {
|
|
285
|
-
gridIndex -= 1;
|
|
286
|
-
candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
287
|
-
}
|
|
288
|
-
if (candidate < current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
|
|
289
|
-
candidates.push(clamp(candidate, range));
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return clamp(Math.max(...candidates), range);
|
|
275
|
+
const near = base - Math.trunc(base / step) * step;
|
|
276
|
+
const origin = cleanGridValue(Number.isFinite(near) ? near % step : base % step, base, step);
|
|
277
|
+
return { step, base, origin };
|
|
278
|
+
}
|
|
279
|
+
function gridPosition(value, grid) {
|
|
280
|
+
return value / grid.step - grid.origin / grid.step;
|
|
293
281
|
}
|
|
294
|
-
function
|
|
295
|
-
|
|
296
|
-
if (within(candidate, range.min, range.max)) candidates.push(clamp(candidate, range));
|
|
282
|
+
function gridValue(index, grid) {
|
|
283
|
+
return cleanGridValue(grid.origin + index * grid.step, grid.base, grid.step);
|
|
297
284
|
}
|
|
298
285
|
function stepBase(range) {
|
|
299
286
|
if (range.base !== void 0 && Number.isFinite(range.base)) return range.base;
|
|
@@ -309,15 +296,46 @@ function decimalPlaces(value) {
|
|
|
309
296
|
const exponent = exponentText === void 0 ? 0 : Number(exponentText);
|
|
310
297
|
return Math.max(0, fractionLength - exponent);
|
|
311
298
|
}
|
|
312
|
-
function
|
|
313
|
-
return (value
|
|
299
|
+
function inRange(value, range) {
|
|
300
|
+
return Number.isFinite(value) && value >= range.min && value <= range.max;
|
|
301
|
+
}
|
|
302
|
+
function sameGridValue(left, right, step) {
|
|
303
|
+
const rounding = Number.EPSILON * Math.max(Math.abs(left), Math.abs(right));
|
|
304
|
+
return Math.abs(left - right) <= Math.min(rounding, step / 4);
|
|
305
|
+
}
|
|
306
|
+
function isMidpoint(value, left, right, range, grid) {
|
|
307
|
+
const imbalance = Math.abs(Math.abs(value - left) - Math.abs(value - right));
|
|
308
|
+
const rounding = 4 * Number.EPSILON * Math.max(Math.abs(value), Math.abs(left), Math.abs(right));
|
|
309
|
+
if (!(imbalance <= rounding)) return false;
|
|
310
|
+
if (imbalance <= Math.abs(left - right) / 4) return true;
|
|
311
|
+
const lower = Math.min(left, right);
|
|
312
|
+
const upper = Math.max(left, right);
|
|
313
|
+
return value > lower && value < upper && isDecimalMidpoint(value, lower, upper, range, grid);
|
|
314
314
|
}
|
|
315
|
-
function
|
|
316
|
-
|
|
315
|
+
function isDecimalMidpoint(value, lower, upper, range, grid) {
|
|
316
|
+
const raw = decimalParts(value);
|
|
317
|
+
const base = decimalParts(grid.base);
|
|
318
|
+
const step = decimalParts(grid.step);
|
|
319
|
+
const min = decimalParts(lower);
|
|
320
|
+
const max = decimalParts(upper);
|
|
321
|
+
const place = Math.min(raw.place, base.place, step.place, min.place, max.place);
|
|
322
|
+
const units = (part) => part.units * 10n ** BigInt(part.place - place);
|
|
323
|
+
const origin = units(base);
|
|
324
|
+
const stride = units(step);
|
|
325
|
+
const rawUnits = units(raw);
|
|
326
|
+
const remainder = (rawUnits - origin) % stride;
|
|
327
|
+
const below = rawUnits - (remainder < 0n ? remainder + stride : remainder);
|
|
328
|
+
const above = below + stride;
|
|
329
|
+
const minUnits = units(min);
|
|
330
|
+
const maxUnits = units(max);
|
|
331
|
+
const lowerUnits = lower === range.min && minUnits > below ? minUnits : below;
|
|
332
|
+
const upperUnits = upper === range.max && maxUnits < above ? maxUnits : above;
|
|
333
|
+
return Number(`${lowerUnits}e${place}`) === lower && Number(`${upperUnits}e${place}`) === upper && Number(`${(lowerUnits + upperUnits) * 5n}e${place - 1}`) === value;
|
|
317
334
|
}
|
|
318
|
-
function
|
|
319
|
-
const
|
|
320
|
-
|
|
335
|
+
function decimalParts(value) {
|
|
336
|
+
const [coefficient = "", exponent = "0"] = value.toString().split("e");
|
|
337
|
+
const [whole = "", fraction = ""] = coefficient.split(".");
|
|
338
|
+
return { units: BigInt(whole + fraction), place: Number(exponent) - fraction.length };
|
|
321
339
|
}
|
|
322
340
|
function finiteFallback(min, max) {
|
|
323
341
|
if (Number.isFinite(min)) return min;
|
|
@@ -7,14 +7,15 @@ function fillTemplate(template, values) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
10
11
|
function announce(message, options = {}) {
|
|
11
12
|
const text = message.trim();
|
|
12
13
|
if (text.length === 0) return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
15
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
16
|
+
});
|
|
17
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
18
|
+
window.dispatchEvent(event);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
var ListenerSet = class {
|
|
@@ -7,18 +7,20 @@ function fillTemplate(template, values) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
10
11
|
function announce(message, options = {}) {
|
|
11
12
|
const text = message.trim();
|
|
12
13
|
if (text.length === 0) return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
15
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
16
|
+
});
|
|
17
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
18
|
+
window.dispatchEvent(event);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
21
22
|
if (element.getAttribute(name) === value) return false;
|
|
23
|
+
beforeWrite?.();
|
|
22
24
|
if (value === null) element.removeAttribute(name);
|
|
23
25
|
else element.setAttribute(name, value);
|
|
24
26
|
return true;
|
|
@@ -92,14 +94,34 @@ var AttributeLease = class {
|
|
|
92
94
|
const names = registry.names;
|
|
93
95
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
94
96
|
}
|
|
95
|
-
write(element, value) {
|
|
97
|
+
write(element, value, beforeWrite) {
|
|
96
98
|
const stack = attributeStack(element, this.#attribute);
|
|
97
99
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
98
100
|
this.#held.add(element);
|
|
99
101
|
const shows = !this.#covered(element, stack, hold);
|
|
100
102
|
hold.written = value;
|
|
101
103
|
this.#mark(element, stack);
|
|
102
|
-
if (shows) this.#reflect(element, value);
|
|
104
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
105
|
+
}
|
|
106
|
+
adopt(element, options = {}) {
|
|
107
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
108
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
109
|
+
const stack = attributeStack(element, this.#attribute);
|
|
110
|
+
const hold = this.#take(stack);
|
|
111
|
+
if (!hold) return false;
|
|
112
|
+
const current = element.getAttribute(this.#attribute);
|
|
113
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
this.#held.add(element);
|
|
117
|
+
hold.original = current;
|
|
118
|
+
hold.linked = false;
|
|
119
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
120
|
+
if (!above.linked) break;
|
|
121
|
+
above.original = current;
|
|
122
|
+
}
|
|
123
|
+
this.#mark(element, stack);
|
|
124
|
+
return true;
|
|
103
125
|
}
|
|
104
126
|
return(element) {
|
|
105
127
|
const held = this.#held.delete(element);
|
|
@@ -165,8 +187,8 @@ var AttributeLease = class {
|
|
|
165
187
|
setAttributeIfChanged(element, name, recorded);
|
|
166
188
|
}
|
|
167
189
|
}
|
|
168
|
-
#reflect(element, value) {
|
|
169
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
190
|
+
#reflect(element, value, beforeWrite) {
|
|
191
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
170
192
|
}
|
|
171
193
|
};
|
|
172
194
|
|
|
@@ -215,7 +237,7 @@ var DetachGate = class _DetachGate {
|
|
|
215
237
|
|
|
216
238
|
var MinDurationFloor = class {
|
|
217
239
|
#timers;
|
|
218
|
-
#
|
|
240
|
+
#task = null;
|
|
219
241
|
#since = 0;
|
|
220
242
|
constructor(timers) {
|
|
221
243
|
this.#timers = timers;
|
|
@@ -224,25 +246,19 @@ var MinDurationFloor = class {
|
|
|
224
246
|
this.#since = Date.now();
|
|
225
247
|
}
|
|
226
248
|
get pending() {
|
|
227
|
-
return this.#
|
|
249
|
+
return this.#task?.pending ?? false;
|
|
228
250
|
}
|
|
229
251
|
schedule(minDuration, finish) {
|
|
230
252
|
this.cancel();
|
|
231
253
|
const remaining = minDuration - (Date.now() - this.#since);
|
|
232
254
|
if (remaining > 0) {
|
|
233
|
-
this.#
|
|
234
|
-
this.#timerId = null;
|
|
235
|
-
finish();
|
|
236
|
-
}, remaining);
|
|
255
|
+
this.#task = this.#timers.setTask(finish, remaining);
|
|
237
256
|
} else {
|
|
238
257
|
finish();
|
|
239
258
|
}
|
|
240
259
|
}
|
|
241
260
|
cancel() {
|
|
242
|
-
|
|
243
|
-
this.#timers.clear(this.#timerId);
|
|
244
|
-
this.#timerId = null;
|
|
245
|
-
}
|
|
261
|
+
this.#task?.cancel();
|
|
246
262
|
}
|
|
247
263
|
};
|
|
248
264
|
|
|
@@ -309,6 +325,22 @@ var TimerRegistry = class {
|
|
|
309
325
|
return this.ids.size;
|
|
310
326
|
}
|
|
311
327
|
};
|
|
328
|
+
var TimeoutRegistration = class {
|
|
329
|
+
#registration;
|
|
330
|
+
constructor(owner, id) {
|
|
331
|
+
this.#registration = { owner, id };
|
|
332
|
+
}
|
|
333
|
+
get pending() {
|
|
334
|
+
return this.#registration !== null;
|
|
335
|
+
}
|
|
336
|
+
cancel() {
|
|
337
|
+
const registration = this.#registration;
|
|
338
|
+
if (registration) registration.owner.clear(registration.id);
|
|
339
|
+
}
|
|
340
|
+
expire() {
|
|
341
|
+
this.#registration = null;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
312
344
|
var SafeTimeout = class extends TimerRegistry {
|
|
313
345
|
set(callback, delay) {
|
|
314
346
|
const id = this.schedule(() => {
|
|
@@ -325,6 +357,29 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
325
357
|
window.clearTimeout(id);
|
|
326
358
|
}
|
|
327
359
|
};
|
|
360
|
+
var TaskTimeout = class extends SafeTimeout {
|
|
361
|
+
#tasks = /* @__PURE__ */ new Map();
|
|
362
|
+
setTask(callback, delay) {
|
|
363
|
+
const id = this.set(() => {
|
|
364
|
+
this.#tasks.delete(id);
|
|
365
|
+
registration.expire();
|
|
366
|
+
callback();
|
|
367
|
+
}, delay);
|
|
368
|
+
const registration = new TimeoutRegistration(this, id);
|
|
369
|
+
this.#tasks.set(id, registration);
|
|
370
|
+
return registration;
|
|
371
|
+
}
|
|
372
|
+
clear(id) {
|
|
373
|
+
this.#tasks.get(id)?.expire();
|
|
374
|
+
this.#tasks.delete(id);
|
|
375
|
+
super.clear(id);
|
|
376
|
+
}
|
|
377
|
+
clearAll() {
|
|
378
|
+
for (const registration of this.#tasks.values()) registration.expire();
|
|
379
|
+
this.#tasks.clear();
|
|
380
|
+
super.clearAll();
|
|
381
|
+
}
|
|
382
|
+
};
|
|
328
383
|
|
|
329
384
|
var SpinnerController = class _SpinnerController extends Controller {
|
|
330
385
|
#numbers = new NumberValueReader();
|
|
@@ -343,7 +398,7 @@ var SpinnerController = class _SpinnerController extends Controller {
|
|
|
343
398
|
};
|
|
344
399
|
static actions = ["start", "stop"];
|
|
345
400
|
static events = ["hide", "show", "timeout", "reconcile"];
|
|
346
|
-
#timers = new
|
|
401
|
+
#timers = new TaskTimeout();
|
|
347
402
|
#floor = new MinDurationFloor(this.#timers);
|
|
348
403
|
#gate = new DetachGate();
|
|
349
404
|
#busyLease = new AttributeLease("aria-busy", this.identifier);
|