stimeo-ui 0.8.0 → 0.9.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/CHANGELOG.md +89 -0
- package/dist/controllers/bulk_select_controller.d.ts +62 -15
- package/dist/controllers/bulk_select_controller.js +139 -28
- package/dist/controllers/bulk_select_controller.js.map +1 -1
- package/dist/controllers/clipboard_controller.d.ts +48 -15
- package/dist/controllers/clipboard_controller.js +102 -20
- package/dist/controllers/clipboard_controller.js.map +1 -1
- package/dist/controllers/color_picker_controller.d.ts +37 -6
- package/dist/controllers/color_picker_controller.js +180 -43
- package/dist/controllers/color_picker_controller.js.map +1 -1
- package/dist/controllers/data_grid_controller.d.ts +25 -9
- package/dist/controllers/data_grid_controller.js +150 -24
- package/dist/controllers/data_grid_controller.js.map +1 -1
- package/dist/controllers/editable_controller.d.ts +34 -9
- package/dist/controllers/editable_controller.js +83 -30
- package/dist/controllers/editable_controller.js.map +1 -1
- package/dist/controllers/filter_controller.d.ts +15 -3
- package/dist/controllers/filter_controller.js +32 -1
- package/dist/controllers/filter_controller.js.map +1 -1
- package/dist/controllers/masonry_controller.d.ts +34 -5
- package/dist/controllers/masonry_controller.js +129 -17
- package/dist/controllers/masonry_controller.js.map +1 -1
- package/dist/controllers/otp_controller.d.ts +4 -1
- package/dist/controllers/otp_controller.js +29 -16
- package/dist/controllers/otp_controller.js.map +1 -1
- package/dist/controllers/reset_before_cache_controller.d.ts +25 -2
- package/dist/controllers/reset_before_cache_controller.js +51 -5
- package/dist/controllers/reset_before_cache_controller.js.map +1 -1
- package/dist/controllers/resizable_controller.d.ts +23 -7
- package/dist/controllers/resizable_controller.js +128 -55
- package/dist/controllers/resizable_controller.js.map +1 -1
- package/dist/index.js +860 -339
- package/dist/index.js.map +1 -1
- package/dist/inspector/cli.js +2 -0
- package/dist/inspector/cli.js.map +1 -1
- package/dist/inspector/cli_bin.js +2 -0
- package/dist/inspector/cli_bin.js.map +1 -1
- package/dist/inspector/examples.json +22 -22
- package/dist/inspector/manifest.json +12 -8
- package/package.json +1 -1
|
@@ -58,8 +58,62 @@ var MicrotaskCoalescer = class {
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
// src/utils/owned_pointer_session.ts
|
|
62
|
+
var OwnedPointerSession = class {
|
|
63
|
+
pointerId;
|
|
64
|
+
#owner;
|
|
65
|
+
#handlers;
|
|
66
|
+
#abort = new AbortController();
|
|
67
|
+
#active = true;
|
|
68
|
+
constructor(start, owner, handlers) {
|
|
69
|
+
this.pointerId = start.pointerId;
|
|
70
|
+
this.#owner = owner;
|
|
71
|
+
this.#handlers = handlers;
|
|
72
|
+
const { signal } = this.#abort;
|
|
73
|
+
owner.ownerDocument.addEventListener("pointermove", this.#onMove, { signal });
|
|
74
|
+
owner.ownerDocument.addEventListener("pointerup", this.#onEndEvent, { signal });
|
|
75
|
+
owner.ownerDocument.addEventListener("pointercancel", this.#onEndEvent, { signal });
|
|
76
|
+
owner.addEventListener("lostpointercapture", this.#onLostCapture, { signal });
|
|
77
|
+
try {
|
|
78
|
+
owner.setPointerCapture?.(this.pointerId);
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Whether this session still owns its pointer and listeners. */
|
|
83
|
+
get active() {
|
|
84
|
+
return this.#active;
|
|
85
|
+
}
|
|
86
|
+
/** Whether `event` belongs to the initiating pointer of the live session. */
|
|
87
|
+
owns(event) {
|
|
88
|
+
return this.#active && event.pointerId === this.pointerId;
|
|
89
|
+
}
|
|
90
|
+
/** Releases capture/listeners and invokes the end callback exactly once. */
|
|
91
|
+
end() {
|
|
92
|
+
if (!this.#active) return;
|
|
93
|
+
this.#active = false;
|
|
94
|
+
this.#abort.abort();
|
|
95
|
+
try {
|
|
96
|
+
this.#owner.releasePointerCapture?.(this.pointerId);
|
|
97
|
+
} catch {
|
|
98
|
+
}
|
|
99
|
+
this.#handlers.end?.();
|
|
100
|
+
}
|
|
101
|
+
#onMove = (event) => {
|
|
102
|
+
if (this.owns(event)) this.#handlers.move(event);
|
|
103
|
+
};
|
|
104
|
+
#onEndEvent = (event) => {
|
|
105
|
+
if (this.owns(event)) this.end();
|
|
106
|
+
};
|
|
107
|
+
#onLostCapture = (event) => {
|
|
108
|
+
const pointerId = event.pointerId;
|
|
109
|
+
if (typeof pointerId === "number" && pointerId !== this.pointerId) return;
|
|
110
|
+
this.end();
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
61
114
|
// src/controllers/color_picker_controller.ts
|
|
62
115
|
var COLOR_PROPERTY = "--stimeo--color";
|
|
116
|
+
var VALUE_TEXT_ATTRIBUTE = "data-value-text";
|
|
63
117
|
var CHANNEL_RANGE = {
|
|
64
118
|
hue: [0, 360],
|
|
65
119
|
saturation: [0, 100],
|
|
@@ -79,10 +133,10 @@ var ColorPickerController = class extends Controller {
|
|
|
79
133
|
get #mirrored() {
|
|
80
134
|
return this.logicalTrackValue && isRtl(this.element);
|
|
81
135
|
}
|
|
82
|
-
/** The current color in the editing model. */
|
|
136
|
+
/** The current color in the editing model; its alpha is 100 while `alpha` is off. */
|
|
83
137
|
#color = { hue: 0, saturation: 0, lightness: 0, alpha: 100 };
|
|
84
|
-
/**
|
|
85
|
-
#
|
|
138
|
+
/** The pointer that owns the live drag, with the slider whose geometry maps it. */
|
|
139
|
+
#drag = null;
|
|
86
140
|
/** Color the last repaint settled on, so a configuration-driven move is reported once. */
|
|
87
141
|
#committedHex = null;
|
|
88
142
|
/**
|
|
@@ -93,25 +147,48 @@ var ColorPickerController = class extends Controller {
|
|
|
93
147
|
/** Seeds the model from the initial hex value and renders every surface. */
|
|
94
148
|
connect() {
|
|
95
149
|
this.#repaint.activate();
|
|
96
|
-
|
|
97
|
-
if (parsed) this.#color = this.alphaValue ? parsed : { ...parsed, alpha: 100 };
|
|
150
|
+
this.#adoptValue();
|
|
98
151
|
this.#render();
|
|
99
152
|
}
|
|
100
153
|
/** Cancels any active pointer drag so document listeners never leak. */
|
|
101
154
|
disconnect() {
|
|
102
155
|
this.#repaint.cancel();
|
|
103
|
-
this.#
|
|
104
|
-
this.#dragAbort = null;
|
|
156
|
+
this.#endDrag();
|
|
105
157
|
}
|
|
106
158
|
/** Repaints when application code (or a Turbo morph) changes `alpha` at runtime. */
|
|
107
159
|
alphaValueChanged() {
|
|
108
160
|
this.#repaint.schedule();
|
|
109
161
|
}
|
|
162
|
+
/** Adopts a color application code (or a Turbo morph) put in `value` at runtime. */
|
|
163
|
+
valueValueChanged() {
|
|
164
|
+
if (this.valueValue === this.#committedHex) return;
|
|
165
|
+
this.#repaint.schedule();
|
|
166
|
+
}
|
|
167
|
+
/** Hydrates a channel slider inserted or replaced at runtime. */
|
|
168
|
+
sliderTargetConnected(slider) {
|
|
169
|
+
this.#renderSlider(slider);
|
|
170
|
+
}
|
|
171
|
+
/** Ends a gesture whose geometry target disappeared or ceased being a target. */
|
|
172
|
+
sliderTargetDisconnected(slider) {
|
|
173
|
+
if (this.#drag?.slider === slider) this.#endDrag();
|
|
174
|
+
}
|
|
175
|
+
/** Fills a hex input inserted or replaced at runtime with the current color. */
|
|
176
|
+
hexTargetConnected(hex) {
|
|
177
|
+
this.#mirrorColor(hex, this.#hexString());
|
|
178
|
+
}
|
|
179
|
+
/** Fills a form field inserted or replaced at runtime with the current color. */
|
|
180
|
+
fieldTargetConnected(field) {
|
|
181
|
+
this.#mirrorColor(field, this.#hexString());
|
|
182
|
+
}
|
|
183
|
+
/** Publishes the current color on a preview inserted or replaced at runtime. */
|
|
184
|
+
previewTargetConnected(preview) {
|
|
185
|
+
this.#publishColor(preview, this.#hexString());
|
|
186
|
+
}
|
|
110
187
|
/** Keyboard stepping on the focused channel slider (APG Slider model). */
|
|
111
188
|
onKeydown(event) {
|
|
112
189
|
if (isReservedArrowChord(event)) return;
|
|
113
190
|
const slider = event.currentTarget;
|
|
114
|
-
const channel = this.#
|
|
191
|
+
const channel = this.#editableChannel(slider);
|
|
115
192
|
if (!channel) return;
|
|
116
193
|
const [min, max] = this.#rangeOf(slider, channel);
|
|
117
194
|
const value = this.#color[channel];
|
|
@@ -143,34 +220,36 @@ var ColorPickerController = class extends Controller {
|
|
|
143
220
|
event.preventDefault();
|
|
144
221
|
this.#setChannel(channel, next, min, max);
|
|
145
222
|
}
|
|
146
|
-
/** Begins a
|
|
223
|
+
/** Begins a primary-button drag on a channel slider, owned by its own pointer. */
|
|
147
224
|
onPointerDown(event) {
|
|
225
|
+
if (event.button !== 0 || this.#drag) return;
|
|
148
226
|
const slider = event.currentTarget;
|
|
149
|
-
const channel = this.#
|
|
227
|
+
const channel = this.#editableChannel(slider);
|
|
150
228
|
if (!channel) return;
|
|
151
|
-
event.preventDefault();
|
|
152
|
-
slider.focus();
|
|
153
229
|
const [min, max] = this.#rangeOf(slider, channel);
|
|
154
230
|
const mirrored = this.#mirrored;
|
|
155
231
|
const update = (clientX) => {
|
|
156
232
|
const rect = slider.getBoundingClientRect();
|
|
157
|
-
if (rect.width === 0) return;
|
|
233
|
+
if (rect.width === 0) return false;
|
|
158
234
|
const offset = Math.min(1, Math.max(0, (clientX - rect.left) / rect.width));
|
|
159
235
|
const fraction = mirrored ? 1 - offset : offset;
|
|
160
236
|
this.#setChannel(channel, min + fraction * (max - min), min, max);
|
|
237
|
+
return true;
|
|
161
238
|
};
|
|
162
|
-
update(event.clientX);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
239
|
+
if (!update(event.clientX)) return;
|
|
240
|
+
event.preventDefault();
|
|
241
|
+
slider.focus();
|
|
242
|
+
const drag = { pointer: null, slider };
|
|
243
|
+
drag.pointer = new OwnedPointerSession(event, slider, {
|
|
244
|
+
move: (move) => {
|
|
245
|
+
if (slider.isConnected) update(move.clientX);
|
|
246
|
+
else this.#endDrag();
|
|
247
|
+
},
|
|
248
|
+
end: () => {
|
|
249
|
+
if (this.#drag === drag) this.#drag = null;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
this.#drag = drag;
|
|
174
253
|
}
|
|
175
254
|
/** Parses the hex input on confirm and syncs every channel + surface. */
|
|
176
255
|
onHexInput() {
|
|
@@ -180,9 +259,22 @@ var ColorPickerController = class extends Controller {
|
|
|
180
259
|
this.hexTarget.value = this.#hexString();
|
|
181
260
|
return;
|
|
182
261
|
}
|
|
183
|
-
this.#color = this
|
|
262
|
+
this.#color = this.#opaqueUnlessEnabled(parsed);
|
|
184
263
|
this.#commitColor();
|
|
185
264
|
}
|
|
265
|
+
/** Replaces the model with the color `value` names, leaving an unparsable one alone. */
|
|
266
|
+
#adoptValue() {
|
|
267
|
+
const parsed = hexToHsla(this.valueValue);
|
|
268
|
+
if (parsed) this.#color = this.#opaqueUnlessEnabled(parsed);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* The model a parsed color implies: alpha only survives while its channel is
|
|
272
|
+
* enabled, because `hexString()` would otherwise emit `#RRGGBB` while `change`
|
|
273
|
+
* reported `rgba.a < 1`.
|
|
274
|
+
*/
|
|
275
|
+
#opaqueUnlessEnabled(parsed) {
|
|
276
|
+
return this.alphaValue ? parsed : { ...parsed, alpha: 100 };
|
|
277
|
+
}
|
|
186
278
|
/** Clamps and snaps one channel to an integer, then re-renders + emits change. */
|
|
187
279
|
#setChannel(channel, raw, min, max) {
|
|
188
280
|
this.#color[channel] = Math.round(Math.min(max, Math.max(min, raw)));
|
|
@@ -201,32 +293,57 @@ var ColorPickerController = class extends Controller {
|
|
|
201
293
|
}
|
|
202
294
|
}
|
|
203
295
|
/**
|
|
204
|
-
* Reflects the model onto sliders, the hex input, preview,
|
|
296
|
+
* Reflects the model onto sliders, the hex input, preview, form field, and the
|
|
297
|
+
* `value` Value it serializes into.
|
|
205
298
|
*
|
|
206
299
|
* @stimeoRenderRoot
|
|
207
300
|
*/
|
|
208
301
|
#render() {
|
|
209
|
-
for (const slider of this.sliderTargets)
|
|
210
|
-
const channel = this.#channelOf(slider);
|
|
211
|
-
if (!channel) continue;
|
|
212
|
-
const value = this.#color[channel];
|
|
213
|
-
slider.setAttribute("aria-valuenow", String(value));
|
|
214
|
-
slider.setAttribute("aria-valuetext", valueText(channel, value));
|
|
215
|
-
}
|
|
302
|
+
for (const slider of this.sliderTargets) this.#renderSlider(slider);
|
|
216
303
|
const hex = this.#hexString();
|
|
217
304
|
this.#committedHex = hex;
|
|
218
|
-
if (this.
|
|
219
|
-
|
|
220
|
-
for (const
|
|
221
|
-
this.
|
|
305
|
+
if (this.valueValue !== hex) this.valueValue = hex;
|
|
306
|
+
if (this.hasHexTarget) this.#mirrorColor(this.hexTarget, hex);
|
|
307
|
+
for (const field of this.fieldTargets) this.#mirrorColor(field, hex);
|
|
308
|
+
for (const preview of this.previewTargets) this.#publishColor(preview, hex);
|
|
309
|
+
this.#publishColor(this.element, hex);
|
|
310
|
+
}
|
|
311
|
+
/** Writes one slider's announced range, value, and value text, skipping equal ones. */
|
|
312
|
+
#renderSlider(slider) {
|
|
313
|
+
const channel = this.#channelOf(slider);
|
|
314
|
+
if (!channel) return;
|
|
315
|
+
const [min, max] = this.#rangeOf(slider, channel);
|
|
316
|
+
const value = this.#color[channel];
|
|
317
|
+
const attributes = {
|
|
318
|
+
"aria-valuemin": String(min),
|
|
319
|
+
"aria-valuemax": String(max),
|
|
320
|
+
"aria-valuenow": String(value),
|
|
321
|
+
"aria-valuetext": this.#valueText(slider, channel, value)
|
|
322
|
+
};
|
|
323
|
+
for (const [name, next] of Object.entries(attributes)) {
|
|
324
|
+
if (slider.getAttribute(name) !== next) slider.setAttribute(name, next);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/** Mirrors the color into an input, leaving an already-equal value untouched. */
|
|
328
|
+
#mirrorColor(input, hex) {
|
|
329
|
+
if (input.value !== hex) input.value = hex;
|
|
330
|
+
}
|
|
331
|
+
/** Publishes the color as the consumer's CSS hook, skipping an equal value. */
|
|
332
|
+
#publishColor(element, hex) {
|
|
333
|
+
if (element.style.getPropertyValue(COLOR_PROPERTY) !== hex) {
|
|
334
|
+
element.style.setProperty(COLOR_PROPERTY, hex);
|
|
335
|
+
}
|
|
222
336
|
}
|
|
223
337
|
/**
|
|
224
|
-
* Repaints after
|
|
225
|
-
* settled on. Disabling alpha drops it from the model
|
|
226
|
-
*
|
|
338
|
+
* Repaints after a declarative input changed at runtime and reports a color this
|
|
339
|
+
* controller settled on. Disabling alpha drops it from the model and an outside
|
|
340
|
+
* `value` names another color, so the committed color can move without a user
|
|
341
|
+
* edit; `change` stays reserved for the picker's own actions.
|
|
227
342
|
*/
|
|
228
343
|
#reconcileColor() {
|
|
229
344
|
const previous = this.#committedHex;
|
|
345
|
+
if (previous !== null && this.valueValue !== previous) this.#adoptValue();
|
|
346
|
+
if (!this.alphaValue) this.#color.alpha = 100;
|
|
230
347
|
this.#render();
|
|
231
348
|
if (previous !== null && this.#committedHex !== previous) {
|
|
232
349
|
this.dispatch("reconcile", { detail: this.#settledDetail() });
|
|
@@ -247,7 +364,27 @@ var ColorPickerController = class extends Controller {
|
|
|
247
364
|
/** Reads a slider's `data-channel`, if it is a known channel. */
|
|
248
365
|
#channelOf(slider) {
|
|
249
366
|
const channel = slider.getAttribute("data-channel");
|
|
250
|
-
return channel && channel
|
|
367
|
+
return channel && Object.hasOwn(CHANNEL_RANGE, channel) ? channel : null;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* The channel a slider edits, or null when this picker edits none through it. An
|
|
371
|
+
* alpha slider authored while `alpha` is off edits nothing: moving it would leave
|
|
372
|
+
* the model translucent behind an opaque `#RRGGBB`.
|
|
373
|
+
*/
|
|
374
|
+
#editableChannel(slider) {
|
|
375
|
+
const channel = this.#channelOf(slider);
|
|
376
|
+
return channel === "alpha" && !this.alphaValue ? null : channel;
|
|
377
|
+
}
|
|
378
|
+
/** The channel's announced text: the slider's template, or the built-in English. */
|
|
379
|
+
#valueText(slider, channel, value) {
|
|
380
|
+
const template = slider.getAttribute(VALUE_TEXT_ATTRIBUTE);
|
|
381
|
+
return template ? template.replaceAll("{value}", String(value)) : defaultValueText(channel, value);
|
|
382
|
+
}
|
|
383
|
+
/** Ends the live drag so no further movement of that pointer reaches the model. */
|
|
384
|
+
#endDrag() {
|
|
385
|
+
const drag = this.#drag;
|
|
386
|
+
this.#drag = null;
|
|
387
|
+
drag?.pointer?.end();
|
|
251
388
|
}
|
|
252
389
|
/**
|
|
253
390
|
* A slider's `[min, max]` from aria-valuemin/max, falling back per channel.
|
|
@@ -263,7 +400,7 @@ var ColorPickerController = class extends Controller {
|
|
|
263
400
|
];
|
|
264
401
|
}
|
|
265
402
|
};
|
|
266
|
-
function
|
|
403
|
+
function defaultValueText(channel, value) {
|
|
267
404
|
const label = channel.charAt(0).toUpperCase() + channel.slice(1);
|
|
268
405
|
const unit = channel === "hue" ? "degrees" : "percent";
|
|
269
406
|
return `${label} ${value} ${unit}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/utils/coerce.ts","../../src/utils/microtask_coalescer.ts","../../src/controllers/color_picker_controller.ts"],"names":[],"mappings":";;;;;AAiBO,SAAS,MAAM,OAAA,EAA2B;AAC/C,EAAA,OAAO,MAAA,CAAO,gBAAA,CAAiB,OAAO,CAAA,CAAE,SAAA,KAAc,KAAA;AACxD;;;AC6CO,SAAS,eAAA,CAAgB,KAAa,OAAA,EAA0B;AACrE,EAAA,IAAI,GAAA,KAAQ,YAAA,IAAgB,GAAA,KAAQ,WAAA,EAAa,OAAO,GAAA;AACxD,EAAA,IAAI,CAAC,KAAA,CAAM,OAAO,CAAA,EAAG,OAAO,GAAA;AAC5B,EAAA,OAAO,GAAA,KAAQ,eAAe,WAAA,GAAc,YAAA;AAC9C;AA2BO,SAAS,oBAAA,CACd,KAAA,EACA,KAAA,GAAkC,EAAC,EAC1B;AACT,EAAA,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AA;AACzC,EAAA,IAAI,CAAC,sDAAA,CAAuD,IAAA,CAAK,GAAG,GAAG,OAAO,IAAA;AAG9E,EAAA,MAAM,OACJ,GAAA,CAAI,MAAA,IAAU,CAAA,GACV,GAAA,CACG,MAAM,EAAE,CAAA,CACR,GAAA,CAAI,CAAC,SAAS,IAAA,GAAO,IAAI,CAAA,CACzB,IAAA,CAAK,EAAE,CAAA,GACV,GAAA;AAEN,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,IAAA,CAAK,MAAM,CAAA,EAAG,CAAC,GAAG,EAAE,CAAA;AAC9C,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,IAAA,CAAK,MAAM,CAAA,EAAG,CAAC,GAAG,EAAE,CAAA;AAC9C,EAAA,MAAM,CAAA,GAAI,OAAO,QAAA,CAAS,IAAA,CAAK,MAAM,CAAA,EAAG,CAAC,GAAG,EAAE,CAAA;AAC9C,EAAA,MAAM,CAAA,GAAI,IAAA,CAAK,MAAA,KAAW,CAAA,GAAI,MAAA,CAAO,QAAA,CAAS,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,EAAG,EAAE,CAAA,GAAI,GAAA;AAEtE,EAAA,MAAM,EAAE,GAAG,CAAA,EAAG,CAAA,KAAM,QAAA,CAAS,CAAA,EAAG,GAAG,CAAC,CAAA;AACpC,EAAA,OAAO,EAAE,GAAA,EAAK,CAAA,EAAG,UAAA,EAAY,CAAA,EAAG,SAAA,EAAW,CAAA,EAAG,KAAA,EAAO,IAAA,CAAK,KAAA,CAAO,CAAA,GAAI,GAAA,GAAO,GAAG,CAAA,EAAE;AACnF","file":"color_picker_controller.js","sourcesContent":["/** Normalized scroll position and maximum distance on one logical axis. */\nexport interface LogicalScrollMetrics {\n position: number;\n max: number;\n}\n\n/**\n * Whether horizontal scrolling on `element` follows right-to-left inline flow.\n *\n * Resolved from the **computed** `direction`, so the authoring contract is the\n * usual `dir=\"rtl\"` (or a stylesheet) on the element or any ancestor.\n *\n * Scope: horizontal writing modes. A vertical writing mode (`writing-mode:\n * vertical-rl`) also inverts the horizontal axis, which this check does not\n * model — vertical writing modes are out of scope for the scroll utilities\n * (their consumers describe axes as horizontal/vertical, not inline/block).\n */\nexport function isRtl(element: Element): boolean {\n return window.getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * Returns scroll distance from the logical start edge.\n *\n * CSSOM View exposes standards-mode RTL horizontal offsets as `0` at the inline\n * start (right) and increasingly negative values toward the inline end (left).\n * The normalized position is always clamped to `[0, max]`, which also absorbs\n * Safari's elastic overscroll values.\n */\nexport function logicalScrollMetrics(\n element: HTMLElement,\n horizontal: boolean,\n): LogicalScrollMetrics {\n const max = Math.max(\n 0,\n horizontal\n ? element.scrollWidth - element.clientWidth\n : element.scrollHeight - element.clientHeight,\n );\n const raw = horizontal ? element.scrollLeft : element.scrollTop;\n const position = horizontal && isRtl(element) ? -raw : raw;\n return { position: Math.min(max, Math.max(0, position)), max };\n}\n\n/**\n * Converts a logical start/end delta to the physical value accepted by\n * `Element.scrollBy`.\n */\nexport function physicalScrollDelta(\n element: HTMLElement,\n horizontal: boolean,\n logicalDelta: number,\n): number {\n return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;\n}\n","import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n","/**\n * Numeric coercion shared by the value-bearing controllers (progress, meter,\n * color-picker).\n *\n * Stimulus already coerces numeric action params to numbers, but a value can also\n * arrive as a string — via a `*:set` CustomEvent `detail`, or an action param\n * whose attribute does not look numeric. Centralizing the parse keeps `setValue`\n * tolerant of either form while rejecting anything that is not a finite number.\n */\n\n/**\n * Coerces `raw` to a finite number, or returns `null` when it is absent, empty,\n * or not parseable. Empty strings are treated as \"no value\" rather than `0`, so a\n * stray blank param cannot silently reset the value.\n */\nexport function toFiniteNumber(raw: number | string | null | undefined): number | null {\n if (raw === null || raw === undefined || raw === \"\") return null;\n const value = typeof raw === \"number\" ? raw : Number(raw);\n return Number.isFinite(value) ? value : null;\n}\n","/**\n * Collapses many Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord, logicalArrowKey } from \"../utils/arrow_step\";\nimport { toFiniteNumber } from \"../utils/coerce\";\nimport { isRtl } from \"../utils/logical_scroll\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\n\n/** CSS custom property exposing the current color to consumer CSS. */\nconst COLOR_PROPERTY = \"--stimeo--color\";\n\n/** A color channel slider, identified by its `data-channel` attribute. */\ntype Channel = \"hue\" | \"saturation\" | \"lightness\" | \"alpha\";\n\n/** Default `[min, max]` per channel when the slider omits aria-valuemin/max. */\nconst CHANNEL_RANGE: Record<Channel, [number, number]> = {\n hue: [0, 360],\n saturation: [0, 100],\n lightness: [0, 100],\n alpha: [0, 100],\n};\n\n/** Internal color model: HSL plus an alpha percentage (0–100). */\ninterface Hsla {\n hue: number;\n saturation: number;\n lightness: number;\n alpha: number;\n}\n\n/**\n * Headless, accessible **Color Picker** behavior.\n *\n * Markup contract (identifier: `stimeo--color-picker`):\n * <div data-controller=\"stimeo--color-picker\"\n * data-stimeo--color-picker-value-value=\"#3366cc\">\n * <div role=\"slider\" aria-label=\"Hue\" data-channel=\"hue\" tabindex=\"0\"\n * aria-valuemin=\"0\" aria-valuemax=\"360\" aria-valuenow=\"210\"\n * data-stimeo--color-picker-target=\"slider\"\n * data-action=\"keydown->stimeo--color-picker#onKeydown\n * pointerdown->stimeo--color-picker#onPointerDown\"></div>\n * <!-- saturation / lightness / alpha sliders share the same contract -->\n * <input type=\"text\" aria-label=\"Hex color\"\n * data-stimeo--color-picker-target=\"hex\"\n * data-action=\"change->stimeo--color-picker#onHexInput\" />\n * <div data-stimeo--color-picker-target=\"preview\" aria-hidden=\"true\"></div>\n * <input type=\"hidden\" data-stimeo--color-picker-target=\"field\" />\n * </div>\n *\n * Decomposes color selection into independent APG **Slider** channels (hue,\n * saturation, lightness, optional alpha) instead of a 2-D palette, so every\n * adjustment is keyboard- and screen-reader-operable. Each slider exposes\n * `aria-valuenow` and a human-readable `aria-valuetext` (e.g. \"Hue 210 degrees\");\n * the hex input stays two-way synced; the current color is published on the\n * preview and root as the `--stimeo--color` custom property and mirrored into a\n * hidden form field.\n *\n * `change` and `reconcile` dispatch\n * `{ value: string, rgba: { r: number, g: number, b: number, a: number } }`.\n *\n * @remarks\n * Behavior only — the swatch/gradient visuals are the consumer's CSS/canvas, fed\n * by `--stimeo--color`. Only the consumer knows whether a channel track mirrors\n * under RTL: set `logicalTrack` to declare that it does, and the pointer mapping\n * and horizontal arrow pair follow the writing direction. Left unset, nothing\n * here reads `direction`. A gradient has no logical `to` keyword, so mirroring\n * one means swapping `to right`/`to left` under a `:dir(rtl)` selector.\n *\n * Pointer-drag listeners on `document` are bound to an\n * {@link AbortController} and released on drag end and on `disconnect()` (Turbo\n * navigation included). Color is fully reconstructable from the `value` (hex), so\n * there is no transient state to restore after a Turbo cache/morph.\n *\n * The internal model is integer HSL(A), so a hex → HSL → hex round-trip is not\n * exactly bijective: a typed hex can normalize to a near (not identical) value\n * once the HSL sliders are touched. This keeps the model small and zero-dep; use a\n * dedicated color library on the consumer side if exact hex preservation matters.\n *\n * A color the user set through a slider or the hex input is reported as\n * `stimeo--color-picker:change`. Toggling `alpha` at runtime can move the\n * committed color without a user edit, and that arrives as\n * `stimeo--color-picker:reconcile` with the same detail. Neither fires on connect.\n */\nexport class ColorPickerController extends Controller<HTMLElement> {\n static override targets = [\"slider\", \"hex\", \"preview\", \"field\"];\n static override values = {\n value: { type: String, default: \"#000000\" },\n alpha: { type: Boolean, default: false },\n logicalTrack: { type: Boolean, default: false },\n };\n static actions = [\"onHexInput\", \"onKeydown\", \"onPointerDown\"] as const;\n static events = [\"change\", \"reconcile\"] as const;\n\n declare readonly sliderTargets: HTMLElement[];\n declare readonly hexTarget: HTMLInputElement;\n declare readonly hasHexTarget: boolean;\n declare readonly previewTargets: HTMLElement[];\n declare readonly fieldTargets: HTMLInputElement[];\n declare valueValue: string;\n declare alphaValue: boolean;\n declare logicalTrackValue: boolean;\n\n /** Whether the consumer declared a mirroring track and the direction mirrors it. */\n get #mirrored(): boolean {\n return this.logicalTrackValue && isRtl(this.element);\n }\n\n /** The current color in the editing model. */\n #color: Hsla = { hue: 0, saturation: 0, lightness: 0, alpha: 100 };\n /** Aborts in-progress pointer-drag listeners on drag end / teardown. */\n #dragAbort: AbortController | null = null;\n /** Color the last repaint settled on, so a configuration-driven move is reported once. */\n #committedHex: string | null = null;\n\n /**\n * Collapses a morph that swaps render inputs into one repaint, and refuses the\n * pass Stimulus delivers before `connect()`.\n */\n readonly #repaint = new MicrotaskCoalescer(() => this.#reconcileColor());\n\n /** Seeds the model from the initial hex value and renders every surface. */\n override connect(): void {\n this.#repaint.activate();\n const parsed = hexToHsla(this.valueValue);\n // When alpha is disabled, drop any alpha carried by an `#RRGGBBAA` value so\n // the model stays opaque — otherwise `hexString()` would emit `#RRGGBB`\n // while `change` reported `rgba.a < 1`. Mirrors `onHexInput()`.\n if (parsed) this.#color = this.alphaValue ? parsed : { ...parsed, alpha: 100 };\n this.#render();\n }\n\n /** Cancels any active pointer drag so document listeners never leak. */\n override disconnect(): void {\n this.#repaint.cancel();\n this.#dragAbort?.abort();\n this.#dragAbort = null;\n }\n\n /** Repaints when application code (or a Turbo morph) changes `alpha` at runtime. */\n alphaValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Keyboard stepping on the focused channel slider (APG Slider model). */\n onKeydown(event: KeyboardEvent): void {\n if (isReservedArrowChord(event)) return;\n const slider = event.currentTarget as HTMLElement;\n const channel = this.#channelOf(slider);\n if (!channel) return;\n\n const [min, max] = this.#rangeOf(slider, channel);\n const value = this.#color[channel];\n let next: number | null = null;\n // On a mirrored track the greater value sits at the visual left, so the\n // horizontal pair trades places; the vertical pair passes through.\n switch (this.#mirrored ? logicalArrowKey(event.key, this.element) : event.key) {\n case \"ArrowRight\":\n case \"ArrowUp\":\n next = value + 1;\n break;\n case \"ArrowLeft\":\n case \"ArrowDown\":\n next = value - 1;\n break;\n case \"PageUp\":\n next = value + 10;\n break;\n case \"PageDown\":\n next = value - 10;\n break;\n case \"Home\":\n next = min;\n break;\n case \"End\":\n next = max;\n break;\n default:\n return;\n }\n event.preventDefault();\n this.#setChannel(channel, next, min, max);\n }\n\n /** Begins a pointer drag on a channel slider and tracks movement. */\n onPointerDown(event: PointerEvent): void {\n const slider = event.currentTarget as HTMLElement;\n const channel = this.#channelOf(slider);\n if (!channel) return;\n event.preventDefault();\n slider.focus();\n\n const [min, max] = this.#rangeOf(slider, channel);\n // Resolve the direction once for the whole gesture: reading it per move\n // would query computed style on every frame, and a drag that flipped\n // mid-gesture would be incoherent anyway.\n const mirrored = this.#mirrored;\n const update = (clientX: number): void => {\n const rect = slider.getBoundingClientRect();\n if (rect.width === 0) return;\n const offset = Math.min(1, Math.max(0, (clientX - rect.left) / rect.width));\n const fraction = mirrored ? 1 - offset : offset;\n this.#setChannel(channel, min + fraction * (max - min), min, max);\n };\n update(event.clientX);\n\n this.#dragAbort?.abort();\n const abort = new AbortController();\n this.#dragAbort = abort;\n const onMove = (move: PointerEvent): void => update(move.clientX);\n const onUp = (): void => {\n abort.abort();\n this.#dragAbort = null;\n };\n document.addEventListener(\"pointermove\", onMove, { signal: abort.signal });\n document.addEventListener(\"pointerup\", onUp, { signal: abort.signal });\n document.addEventListener(\"pointercancel\", onUp, { signal: abort.signal });\n }\n\n /** Parses the hex input on confirm and syncs every channel + surface. */\n onHexInput(): void {\n if (!this.hasHexTarget) return;\n const parsed = hexToHsla(this.hexTarget.value);\n if (!parsed) {\n // Reject invalid input by restoring the last valid hex.\n this.hexTarget.value = this.#hexString();\n return;\n }\n this.#color = this.alphaValue ? parsed : { ...parsed, alpha: 100 };\n this.#commitColor();\n }\n\n /** Clamps and snaps one channel to an integer, then re-renders + emits change. */\n #setChannel(channel: Channel, raw: number, min: number, max: number): void {\n this.#color[channel] = Math.round(Math.min(max, Math.max(min, raw)));\n this.#commitColor();\n }\n\n /**\n * Renders the model and reports a color the user actually moved. A key pressed\n * at a bound, a pointer that lands on the step already showing, and a re-confirmed\n * hex all leave the committed color where it was, so no `change` describes them.\n */\n #commitColor(): void {\n const previous = this.#committedHex;\n this.#render();\n if (this.#committedHex !== previous) {\n this.dispatch(\"change\", { detail: this.#settledDetail() });\n }\n }\n\n /**\n * Reflects the model onto sliders, the hex input, preview, and form field.\n *\n * @stimeoRenderRoot\n */\n #render(): void {\n for (const slider of this.sliderTargets) {\n const channel = this.#channelOf(slider);\n if (!channel) continue;\n const value = this.#color[channel];\n slider.setAttribute(\"aria-valuenow\", String(value));\n slider.setAttribute(\"aria-valuetext\", valueText(channel, value));\n }\n\n const hex = this.#hexString();\n this.#committedHex = hex;\n if (this.hasHexTarget) this.hexTarget.value = hex;\n for (const field of this.fieldTargets) field.value = hex;\n for (const preview of this.previewTargets) preview.style.setProperty(COLOR_PROPERTY, hex);\n this.element.style.setProperty(COLOR_PROPERTY, hex);\n }\n\n /**\n * Repaints after `alpha` changed at runtime and reports a color this controller\n * settled on. Disabling alpha drops it from the model, so the committed color can\n * move without a user edit; `change` stays reserved for the picker's own actions.\n */\n #reconcileColor(): void {\n // Compared against the last rendered color, not against the model: the Value\n // callback that scheduled this pass has already moved `alphaValue`, so\n // re-deriving the \"before\" state here would always match the \"after\" one.\n const previous = this.#committedHex;\n this.#render();\n if (previous !== null && this.#committedHex !== previous) {\n this.dispatch(\"reconcile\", { detail: this.#settledDetail() });\n }\n }\n\n /** The settled color as event detail, shared by both report paths. */\n #settledDetail(): { value: string; rgba: { r: number; g: number; b: number; a: number } } {\n const rgb = hslToRgb(this.#color.hue, this.#color.saturation, this.#color.lightness);\n return { value: this.#hexString(), rgba: { ...rgb, a: this.#color.alpha / 100 } };\n }\n\n /** The current color as `#RRGGBB`, or `#RRGGBBAA` when alpha is enabled. */\n #hexString(): string {\n const rgb = hslToRgb(this.#color.hue, this.#color.saturation, this.#color.lightness);\n const base = `#${hex2(rgb.r)}${hex2(rgb.g)}${hex2(rgb.b)}`;\n if (!this.alphaValue) return base;\n return `${base}${hex2(Math.round((this.#color.alpha / 100) * 255))}`;\n }\n\n /** Reads a slider's `data-channel`, if it is a known channel. */\n #channelOf(slider: HTMLElement): Channel | null {\n const channel = slider.getAttribute(\"data-channel\");\n return channel && channel in CHANNEL_RANGE ? (channel as Channel) : null;\n }\n\n /**\n * A slider's `[min, max]` from aria-valuemin/max, falling back per channel.\n * An absent or blank attribute means \"not authored\", not zero — coercing it to\n * a number would pin the channel at `0` and make the per-channel default\n * unreachable.\n */\n #rangeOf(slider: HTMLElement, channel: Channel): [number, number] {\n const [defMin, defMax] = CHANNEL_RANGE[channel];\n return [\n toFiniteNumber(slider.getAttribute(\"aria-valuemin\")) ?? defMin,\n toFiniteNumber(slider.getAttribute(\"aria-valuemax\")) ?? defMax,\n ];\n }\n}\n\n/** Capitalizes a channel name for `aria-valuetext` (e.g. \"Hue\"). */\nfunction valueText(channel: Channel, value: number): string {\n const label = channel.charAt(0).toUpperCase() + channel.slice(1);\n const unit = channel === \"hue\" ? \"degrees\" : \"percent\";\n return `${label} ${value} ${unit}`;\n}\n\n/** Formats a 0–255 byte as a 2-digit lowercase hex pair. */\nfunction hex2(value: number): string {\n return Math.round(Math.min(255, Math.max(0, value)))\n .toString(16)\n .padStart(2, \"0\");\n}\n\n/** Converts HSL (h:0–360, s/l:0–100) to RGB bytes (0–255). */\nfunction hslToRgb(h: number, s: number, l: number): { r: number; g: number; b: number } {\n const sat = s / 100;\n const light = l / 100;\n const c = (1 - Math.abs(2 * light - 1)) * sat;\n const hp = (((h % 360) + 360) % 360) / 60;\n const x = c * (1 - Math.abs((hp % 2) - 1));\n let r = 0;\n let g = 0;\n let b = 0;\n if (hp >= 0 && hp < 1) [r, g, b] = [c, x, 0];\n else if (hp < 2) [r, g, b] = [x, c, 0];\n else if (hp < 3) [r, g, b] = [0, c, x];\n else if (hp < 4) [r, g, b] = [0, x, c];\n else if (hp < 5) [r, g, b] = [x, 0, c];\n else [r, g, b] = [c, 0, x];\n const m = light - c / 2;\n return {\n r: Math.round((r + m) * 255),\n g: Math.round((g + m) * 255),\n b: Math.round((b + m) * 255),\n };\n}\n\n/** Converts RGB bytes (0–255) to HSL (h:0–360, s/l:0–100). */\nfunction rgbToHsl(r: number, g: number, b: number): { h: number; s: number; l: number } {\n const rn = r / 255;\n const gn = g / 255;\n const bn = b / 255;\n const max = Math.max(rn, gn, bn);\n const min = Math.min(rn, gn, bn);\n const delta = max - min;\n const l = (max + min) / 2;\n\n let h = 0;\n if (delta !== 0) {\n if (max === rn) h = ((gn - bn) / delta) % 6;\n else if (max === gn) h = (bn - rn) / delta + 2;\n else h = (rn - gn) / delta + 4;\n h = (h * 60 + 360) % 360;\n }\n const s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));\n return { h: Math.round(h), s: Math.round(s * 100), l: Math.round(l * 100) };\n}\n\n/**\n * Parses `#RGB`, `#RGBA`, `#RRGGBB`, or `#RRGGBBAA` into the HSLA model, or\n * returns null when the string is not a valid hex color.\n */\nfunction hexToHsla(input: string): Hsla | null {\n const hex = input.trim().replace(/^#/, \"\");\n if (!/^(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(hex)) return null;\n\n // Expand shorthand (#RGB / #RGBA) so every channel is a full byte pair.\n const full =\n hex.length <= 4\n ? hex\n .split(\"\")\n .map((char) => char + char)\n .join(\"\")\n : hex;\n\n const r = Number.parseInt(full.slice(0, 2), 16);\n const g = Number.parseInt(full.slice(2, 4), 16);\n const b = Number.parseInt(full.slice(4, 6), 16);\n const a = full.length === 8 ? Number.parseInt(full.slice(6, 8), 16) : 255;\n\n const { h, s, l } = rgbToHsl(r, g, b);\n return { hue: h, saturation: s, lightness: l, alpha: Math.round((a / 255) * 100) };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/utils/coerce.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/owned_pointer_session.ts","../../src/controllers/color_picker_controller.ts"],"names":[],"mappings":";;;;;AAiBO,SAAS,MAAM,OAAA,EAA2B;AAC/C,EAAA,OAAO,MAAA,CAAO,gBAAA,CAAiB,OAAO,CAAA,CAAE,SAAA,KAAc,KAAA;AACxD;;;AC6CO,SAAS,eAAA,CAAgB,KAAa,OAAA,EAA0B;AACrE,EAAA,IAAI,GAAA,KAAQ,YAAA,IAAgB,GAAA,KAAQ,WAAA,EAAa,OAAO,GAAA;AACxD,EAAA,IAAI,CAAC,KAAA,CAAM,OAAO,CAAA,EAAG,OAAO,GAAA;AAC5B,EAAA,OAAO,GAAA,KAAQ,eAAe,WAAA,GAAc,YAAA;AAC9C;AA2BO,SAAS,oBAAA,CACd,KAAA,EACA,KAAA,GAAkC,EAAC,EAC1B;AACT,EAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,UAAA,CAAW,OAAO,GAAG,OAAO,KAAA;AAC3C,EAAA,OACG,KAAA,CAAM,MAAA,IAAU,CAAC,KAAA,CAAM,QAAA,CAAS,KAAK,CAAA,IACrC,KAAA,CAAM,OAAA,IAAW,CAAC,KAAA,CAAM,QAAA,CAAS,MAAM,KACvC,KAAA,CAAM,OAAA,IAAW,CAAC,KAAA,CAAM,QAAA,CAAS,MAAM,CAAA,IACvC,KAAA,CAAM,QAAA,IAAY,CAAC,KAAA,CAAM,QAAA,CAAS,OAAO,CAAA;AAE9C;;;AC3FO,SAA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AAM,CAAA,GAAI,IAAA,CAAK,MAAA,KAAW,CAAA,GAAI,MAAA,CAAO,QAAA,CAAS,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,EAAG,EAAE,CAAA,GAAI,GAAA;AAEtE,EAAA,MAAM,EAAE,GAAG,CAAA,EAAG,CAAA,KAAM,QAAA,CAAS,CAAA,EAAG,GAAG,CAAC,CAAA;AACpC,EAAA,OAAO,EAAE,GAAA,EAAK,CAAA,EAAG,UAAA,EAAY,CAAA,EAAG,SAAA,EAAW,CAAA,EAAG,KAAA,EAAO,IAAA,CAAK,KAAA,CAAO,CAAA,GAAI,GAAA,GAAO,GAAG,CAAA,EAAE;AACnF","file":"color_picker_controller.js","sourcesContent":["/** Normalized scroll position and maximum distance on one logical axis. */\nexport interface LogicalScrollMetrics {\n position: number;\n max: number;\n}\n\n/**\n * Whether horizontal scrolling on `element` follows right-to-left inline flow.\n *\n * Resolved from the **computed** `direction`, so the authoring contract is the\n * usual `dir=\"rtl\"` (or a stylesheet) on the element or any ancestor.\n *\n * Scope: horizontal writing modes. A vertical writing mode (`writing-mode:\n * vertical-rl`) also inverts the horizontal axis, which this check does not\n * model — vertical writing modes are out of scope for the scroll utilities\n * (their consumers describe axes as horizontal/vertical, not inline/block).\n */\nexport function isRtl(element: Element): boolean {\n return window.getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * Returns scroll distance from the logical start edge.\n *\n * CSSOM View exposes standards-mode RTL horizontal offsets as `0` at the inline\n * start (right) and increasingly negative values toward the inline end (left).\n * The normalized position is always clamped to `[0, max]`, which also absorbs\n * Safari's elastic overscroll values.\n */\nexport function logicalScrollMetrics(\n element: HTMLElement,\n horizontal: boolean,\n): LogicalScrollMetrics {\n const max = Math.max(\n 0,\n horizontal\n ? element.scrollWidth - element.clientWidth\n : element.scrollHeight - element.clientHeight,\n );\n const raw = horizontal ? element.scrollLeft : element.scrollTop;\n const position = horizontal && isRtl(element) ? -raw : raw;\n return { position: Math.min(max, Math.max(0, position)), max };\n}\n\n/**\n * Converts a logical start/end delta to the physical value accepted by\n * `Element.scrollBy`.\n */\nexport function physicalScrollDelta(\n element: HTMLElement,\n horizontal: boolean,\n logicalDelta: number,\n): number {\n return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;\n}\n","import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n","/**\n * Numeric coercion shared by the value-bearing controllers (progress, meter,\n * color-picker).\n *\n * Stimulus already coerces numeric action params to numbers, but a value can also\n * arrive as a string — via a `*:set` CustomEvent `detail`, or an action param\n * whose attribute does not look numeric. Centralizing the parse keeps `setValue`\n * tolerant of either form while rejecting anything that is not a finite number.\n */\n\n/**\n * Coerces `raw` to a finite number, or returns `null` when it is absent, empty,\n * or not parseable. Empty strings are treated as \"no value\" rather than `0`, so a\n * stray blank param cannot silently reset the value.\n */\nexport function toFiniteNumber(raw: number | string | null | undefined): number | null {\n if (raw === null || raw === undefined || raw === \"\") return null;\n const value = typeof raw === \"number\" ? raw : Number(raw);\n return Number.isFinite(value) ? value : null;\n}\n","/**\n * Collapses many Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","/** Callbacks driven by one owned pointer until it ends or is cancelled. */\nexport interface OwnedPointerSessionHandlers {\n /** Receives movement from the initiating pointer only. */\n readonly move: (event: PointerEvent) => void;\n /** Runs once after every listener and pointer capture have been released. */\n readonly end?: () => void;\n}\n\n/**\n * Owns one pointer across document-level movement and termination events.\n *\n * A controller may have at most one instance at a time. The session filters\n * every event by the initiating `pointerId`, captures the pointer when the DOM\n * implementation supports it, and binds all fallback document listeners to one\n * abort signal. Calling {@link OwnedPointerSession.end} is idempotent.\n */\nexport class OwnedPointerSession {\n readonly pointerId: number;\n readonly #owner: HTMLElement;\n readonly #handlers: OwnedPointerSessionHandlers;\n readonly #abort = new AbortController();\n #active = true;\n\n constructor(start: PointerEvent, owner: HTMLElement, handlers: OwnedPointerSessionHandlers) {\n this.pointerId = start.pointerId;\n this.#owner = owner;\n this.#handlers = handlers;\n\n const { signal } = this.#abort;\n owner.ownerDocument.addEventListener(\"pointermove\", this.#onMove, { signal });\n owner.ownerDocument.addEventListener(\"pointerup\", this.#onEndEvent, { signal });\n owner.ownerDocument.addEventListener(\"pointercancel\", this.#onEndEvent, { signal });\n owner.addEventListener(\"lostpointercapture\", this.#onLostCapture, { signal });\n\n // Pointer capture is progressive here: happy-dom and older DOM shims may not\n // implement it, while the document listeners still preserve ownership.\n try {\n owner.setPointerCapture?.(this.pointerId);\n } catch {\n // A synthetic or already-ended pointer cannot be captured; filtering and\n // AbortController teardown remain sufficient for that environment.\n }\n }\n\n /** Whether this session still owns its pointer and listeners. */\n get active(): boolean {\n return this.#active;\n }\n\n /** Whether `event` belongs to the initiating pointer of the live session. */\n owns(event: PointerEvent): boolean {\n return this.#active && event.pointerId === this.pointerId;\n }\n\n /** Releases capture/listeners and invokes the end callback exactly once. */\n end(): void {\n if (!this.#active) return;\n this.#active = false;\n this.#abort.abort();\n try {\n this.#owner.releasePointerCapture?.(this.pointerId);\n } catch {\n // Losing capture because the owner detached is already an ended session.\n }\n this.#handlers.end?.();\n }\n\n readonly #onMove = (event: PointerEvent): void => {\n if (this.owns(event)) this.#handlers.move(event);\n };\n\n readonly #onEndEvent = (event: PointerEvent): void => {\n if (this.owns(event)) this.end();\n };\n\n readonly #onLostCapture = (event: Event): void => {\n const pointerId = (event as PointerEvent).pointerId;\n if (typeof pointerId === \"number\" && pointerId !== this.pointerId) return;\n this.end();\n };\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord, logicalArrowKey } from \"../utils/arrow_step\";\nimport { toFiniteNumber } from \"../utils/coerce\";\nimport { isRtl } from \"../utils/logical_scroll\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { OwnedPointerSession } from \"../utils/owned_pointer_session\";\n\n/** CSS custom property exposing the current color to consumer CSS. */\nconst COLOR_PROPERTY = \"--stimeo--color\";\n\n/** A slider's `aria-valuetext` template, where `{value}` is the channel value. */\nconst VALUE_TEXT_ATTRIBUTE = \"data-value-text\";\n\n/** A color channel slider, identified by its `data-channel` attribute. */\ntype Channel = \"hue\" | \"saturation\" | \"lightness\" | \"alpha\";\n\n/** Default `[min, max]` per channel when the slider omits aria-valuemin/max. */\nconst CHANNEL_RANGE: Record<Channel, [number, number]> = {\n hue: [0, 360],\n saturation: [0, 100],\n lightness: [0, 100],\n alpha: [0, 100],\n};\n\n/** Internal color model: HSL plus an alpha percentage (0–100). */\ninterface Hsla {\n hue: number;\n saturation: number;\n lightness: number;\n alpha: number;\n}\n\n/**\n * Headless, accessible **Color Picker** behavior.\n *\n * Markup contract (identifier: `stimeo--color-picker`):\n * <div data-controller=\"stimeo--color-picker\"\n * data-stimeo--color-picker-value-value=\"#3366cc\">\n * <div role=\"slider\" aria-label=\"Hue\" data-channel=\"hue\" tabindex=\"0\"\n * aria-valuemin=\"0\" aria-valuemax=\"360\" aria-valuenow=\"210\"\n * data-value-text=\"Hue {value} degrees\"\n * data-stimeo--color-picker-target=\"slider\"\n * data-action=\"keydown->stimeo--color-picker#onKeydown\n * pointerdown->stimeo--color-picker#onPointerDown\"></div>\n * <!-- saturation / lightness / alpha sliders share the same contract -->\n * <input type=\"text\" aria-label=\"Hex color\"\n * data-stimeo--color-picker-target=\"hex\"\n * data-action=\"change->stimeo--color-picker#onHexInput\" />\n * <div data-stimeo--color-picker-target=\"preview\" aria-hidden=\"true\"></div>\n * <input type=\"hidden\" data-stimeo--color-picker-target=\"field\" />\n * </div>\n *\n * Decomposes color selection into independent APG **Slider** channels (hue,\n * saturation, lightness, optional alpha) instead of a 2-D palette, so every\n * adjustment is keyboard- and screen-reader-operable. Each slider exposes\n * `aria-valuenow` and a human-readable `aria-valuetext` (e.g. \"Hue 210 degrees\");\n * the hex input stays two-way synced; the current color is published on the\n * preview and root as the `--stimeo--color` custom property and mirrored into a\n * hidden form field.\n *\n * `change` and `reconcile` dispatch\n * `{ value: string, rgba: { r: number, g: number, b: number, a: number } }`.\n *\n * @remarks\n * Behavior only — the swatch/gradient visuals are the consumer's CSS/canvas, fed\n * by `--stimeo--color`. Only the consumer knows whether a channel track mirrors\n * under RTL: set `logicalTrack` to declare that it does, and the pointer mapping\n * and horizontal arrow pair follow the writing direction. Left unset, nothing\n * here reads `direction`. A gradient has no logical `to` keyword, so mirroring\n * one means swapping `to right`/`to left` under a `:dir(rtl)` selector.\n *\n * A channel slider announces its bounds from its own `aria-valuemin`/`aria-valuemax`,\n * falling back per channel when they are absent or blank; the resolved pair is\n * written back, so assistive tech never hears the `slider` role's 0–100 default\n * over a hue that reaches 360. `aria-valuetext` is filled from the slider's\n * `{@link VALUE_TEXT_ATTRIBUTE}` template — `{value}` is the channel value — which\n * keeps the announced wording i18n-neutral; without a template the text is English.\n *\n * A drag belongs to the pointer that started it: only a primary button opens one,\n * and {@link OwnedPointerSession} filters movement and termination by that\n * `pointerId`, so a second finger neither steers nor cuts the gesture. Its\n * listeners are released on drag end, when the slider leaves, and on `disconnect()`\n * (Turbo navigation included).\n *\n * The `value` Value carries the color in both directions: every settled color is\n * written back, so a Turbo cache restore and a form submission both carry the color\n * the user picked. An outside write — application code or a morph — re-seeds the\n * model and reports `reconcile`. The ARIA attributes, `--stimeo--color`, and the\n * mirrored input values are this controller's own output and stay in the DOM as\n * written, which is what makes the restored snapshot show the current color.\n *\n * The internal model is integer HSL(A), so a hex → HSL → hex round-trip is not\n * exactly bijective: a typed hex can normalize to a near (not identical) value\n * once the HSL sliders are touched. This keeps the model small and zero-dep; use a\n * dedicated color library on the consumer side if exact hex preservation matters.\n *\n * While `alpha` is disabled the model stays opaque and an alpha slider authored\n * anyway edits nothing, so the hex and `change`'s `rgba.a` never disagree.\n *\n * A color the user set through a slider or the hex input is reported as\n * `stimeo--color-picker:change`. Changing `alpha` or `value` at runtime can move the\n * committed color without a user edit, and that arrives as\n * `stimeo--color-picker:reconcile` with the same detail. Neither fires on connect.\n */\nexport class ColorPickerController extends Controller<HTMLElement> {\n static override targets = [\"slider\", \"hex\", \"preview\", \"field\"];\n static override values = {\n value: { type: String, default: \"#000000\" },\n alpha: { type: Boolean, default: false },\n logicalTrack: { type: Boolean, default: false },\n };\n static actions = [\"onHexInput\", \"onKeydown\", \"onPointerDown\"] as const;\n static events = [\"change\", \"reconcile\"] as const;\n\n declare readonly sliderTargets: HTMLElement[];\n declare readonly hexTarget: HTMLInputElement;\n declare readonly hasHexTarget: boolean;\n declare readonly previewTargets: HTMLElement[];\n declare readonly fieldTargets: HTMLInputElement[];\n declare valueValue: string;\n declare alphaValue: boolean;\n declare logicalTrackValue: boolean;\n\n /** Whether the consumer declared a mirroring track and the direction mirrors it. */\n get #mirrored(): boolean {\n return this.logicalTrackValue && isRtl(this.element);\n }\n\n /** The current color in the editing model; its alpha is 100 while `alpha` is off. */\n #color: Hsla = { hue: 0, saturation: 0, lightness: 0, alpha: 100 };\n /** The pointer that owns the live drag, with the slider whose geometry maps it. */\n #drag: ColorDrag | null = null;\n /** Color the last repaint settled on, so a configuration-driven move is reported once. */\n #committedHex: string | null = null;\n\n /**\n * Collapses a morph that swaps render inputs into one repaint, and refuses the\n * pass Stimulus delivers before `connect()`.\n */\n readonly #repaint = new MicrotaskCoalescer(() => this.#reconcileColor());\n\n /** Seeds the model from the initial hex value and renders every surface. */\n override connect(): void {\n this.#repaint.activate();\n this.#adoptValue();\n this.#render();\n }\n\n /** Cancels any active pointer drag so document listeners never leak. */\n override disconnect(): void {\n this.#repaint.cancel();\n this.#endDrag();\n }\n\n /** Repaints when application code (or a Turbo morph) changes `alpha` at runtime. */\n alphaValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Adopts a color application code (or a Turbo morph) put in `value` at runtime. */\n valueValueChanged(): void {\n // The write-back from a render lands here too, and it already matches the DOM.\n if (this.valueValue === this.#committedHex) return;\n this.#repaint.schedule();\n }\n\n /** Hydrates a channel slider inserted or replaced at runtime. */\n sliderTargetConnected(slider: HTMLElement): void {\n this.#renderSlider(slider);\n }\n\n /** Ends a gesture whose geometry target disappeared or ceased being a target. */\n sliderTargetDisconnected(slider: HTMLElement): void {\n if (this.#drag?.slider === slider) this.#endDrag();\n }\n\n /** Fills a hex input inserted or replaced at runtime with the current color. */\n hexTargetConnected(hex: HTMLInputElement): void {\n this.#mirrorColor(hex, this.#hexString());\n }\n\n /** Fills a form field inserted or replaced at runtime with the current color. */\n fieldTargetConnected(field: HTMLInputElement): void {\n this.#mirrorColor(field, this.#hexString());\n }\n\n /** Publishes the current color on a preview inserted or replaced at runtime. */\n previewTargetConnected(preview: HTMLElement): void {\n this.#publishColor(preview, this.#hexString());\n }\n\n /** Keyboard stepping on the focused channel slider (APG Slider model). */\n onKeydown(event: KeyboardEvent): void {\n if (isReservedArrowChord(event)) return;\n const slider = event.currentTarget as HTMLElement;\n const channel = this.#editableChannel(slider);\n if (!channel) return;\n\n const [min, max] = this.#rangeOf(slider, channel);\n const value = this.#color[channel];\n let next: number | null = null;\n // On a mirrored track the greater value sits at the visual left, so the\n // horizontal pair trades places; the vertical pair passes through.\n switch (this.#mirrored ? logicalArrowKey(event.key, this.element) : event.key) {\n case \"ArrowRight\":\n case \"ArrowUp\":\n next = value + 1;\n break;\n case \"ArrowLeft\":\n case \"ArrowDown\":\n next = value - 1;\n break;\n case \"PageUp\":\n next = value + 10;\n break;\n case \"PageDown\":\n next = value - 10;\n break;\n case \"Home\":\n next = min;\n break;\n case \"End\":\n next = max;\n break;\n default:\n return;\n }\n event.preventDefault();\n this.#setChannel(channel, next, min, max);\n }\n\n /** Begins a primary-button drag on a channel slider, owned by its own pointer. */\n onPointerDown(event: PointerEvent): void {\n // A secondary button opens the context menu instead, and a live drag keeps its\n // slider: another press must not silently take the gesture over.\n if (event.button !== 0 || this.#drag) return;\n const slider = event.currentTarget as HTMLElement;\n const channel = this.#editableChannel(slider);\n if (!channel) return;\n\n const [min, max] = this.#rangeOf(slider, channel);\n // Resolve the direction once for the whole gesture: reading it per move\n // would query computed style on every frame, and a drag that flipped\n // mid-gesture would be incoherent anyway.\n const mirrored = this.#mirrored;\n const update = (clientX: number): boolean => {\n const rect = slider.getBoundingClientRect();\n if (rect.width === 0) return false;\n const offset = Math.min(1, Math.max(0, (clientX - rect.left) / rect.width));\n const fraction = mirrored ? 1 - offset : offset;\n this.#setChannel(channel, min + fraction * (max - min), min, max);\n return true;\n };\n // A track with no width maps no coordinate, so the press is left to the page.\n if (!update(event.clientX)) return;\n event.preventDefault();\n slider.focus();\n\n const drag: ColorDrag = { pointer: null, slider };\n drag.pointer = new OwnedPointerSession(event, slider, {\n move: (move) => {\n // A slider detached mid-drag would map against a stale rectangle.\n if (slider.isConnected) update(move.clientX);\n else this.#endDrag();\n },\n end: () => {\n if (this.#drag === drag) this.#drag = null;\n },\n });\n this.#drag = drag;\n }\n\n /** Parses the hex input on confirm and syncs every channel + surface. */\n onHexInput(): void {\n if (!this.hasHexTarget) return;\n const parsed = hexToHsla(this.hexTarget.value);\n if (!parsed) {\n // Reject invalid input by restoring the last valid hex.\n this.hexTarget.value = this.#hexString();\n return;\n }\n this.#color = this.#opaqueUnlessEnabled(parsed);\n this.#commitColor();\n }\n\n /** Replaces the model with the color `value` names, leaving an unparsable one alone. */\n #adoptValue(): void {\n const parsed = hexToHsla(this.valueValue);\n if (parsed) this.#color = this.#opaqueUnlessEnabled(parsed);\n }\n\n /**\n * The model a parsed color implies: alpha only survives while its channel is\n * enabled, because `hexString()` would otherwise emit `#RRGGBB` while `change`\n * reported `rgba.a < 1`.\n */\n #opaqueUnlessEnabled(parsed: Hsla): Hsla {\n return this.alphaValue ? parsed : { ...parsed, alpha: 100 };\n }\n\n /** Clamps and snaps one channel to an integer, then re-renders + emits change. */\n #setChannel(channel: Channel, raw: number, min: number, max: number): void {\n this.#color[channel] = Math.round(Math.min(max, Math.max(min, raw)));\n this.#commitColor();\n }\n\n /**\n * Renders the model and reports a color the user actually moved. A key pressed\n * at a bound, a pointer that lands on the step already showing, and a re-confirmed\n * hex all leave the committed color where it was, so no `change` describes them.\n */\n #commitColor(): void {\n const previous = this.#committedHex;\n this.#render();\n if (this.#committedHex !== previous) {\n this.dispatch(\"change\", { detail: this.#settledDetail() });\n }\n }\n\n /**\n * Reflects the model onto sliders, the hex input, preview, form field, and the\n * `value` Value it serializes into.\n *\n * @stimeoRenderRoot\n */\n #render(): void {\n for (const slider of this.sliderTargets) this.#renderSlider(slider);\n\n const hex = this.#hexString();\n this.#committedHex = hex;\n // The Value carries the color, so a Turbo snapshot and a morph read the same\n // truth the surfaces show.\n if (this.valueValue !== hex) this.valueValue = hex;\n if (this.hasHexTarget) this.#mirrorColor(this.hexTarget, hex);\n for (const field of this.fieldTargets) this.#mirrorColor(field, hex);\n for (const preview of this.previewTargets) this.#publishColor(preview, hex);\n this.#publishColor(this.element, hex);\n }\n\n /** Writes one slider's announced range, value, and value text, skipping equal ones. */\n #renderSlider(slider: HTMLElement): void {\n const channel = this.#channelOf(slider);\n if (!channel) return;\n const [min, max] = this.#rangeOf(slider, channel);\n const value = this.#color[channel];\n const attributes = {\n \"aria-valuemin\": String(min),\n \"aria-valuemax\": String(max),\n \"aria-valuenow\": String(value),\n \"aria-valuetext\": this.#valueText(slider, channel, value),\n };\n for (const [name, next] of Object.entries(attributes)) {\n if (slider.getAttribute(name) !== next) slider.setAttribute(name, next);\n }\n }\n\n /** Mirrors the color into an input, leaving an already-equal value untouched. */\n #mirrorColor(input: HTMLInputElement, hex: string): void {\n if (input.value !== hex) input.value = hex;\n }\n\n /** Publishes the color as the consumer's CSS hook, skipping an equal value. */\n #publishColor(element: HTMLElement, hex: string): void {\n if (element.style.getPropertyValue(COLOR_PROPERTY) !== hex) {\n element.style.setProperty(COLOR_PROPERTY, hex);\n }\n }\n\n /**\n * Repaints after a declarative input changed at runtime and reports a color this\n * controller settled on. Disabling alpha drops it from the model and an outside\n * `value` names another color, so the committed color can move without a user\n * edit; `change` stays reserved for the picker's own actions.\n */\n #reconcileColor(): void {\n // Compared against the last rendered color, not against the model: the Value\n // callback that scheduled this pass has already moved the Values, so\n // re-deriving the \"before\" state here would always match the \"after\" one.\n const previous = this.#committedHex;\n // Only a `value` that differs from the rendered color comes from outside.\n // Re-seeding from the controller's own write-back would round-trip the model\n // through hex and drop the hue and saturation a gray cannot carry.\n if (previous !== null && this.valueValue !== previous) this.#adoptValue();\n if (!this.alphaValue) this.#color.alpha = 100;\n this.#render();\n if (previous !== null && this.#committedHex !== previous) {\n this.dispatch(\"reconcile\", { detail: this.#settledDetail() });\n }\n }\n\n /** The settled color as event detail, shared by both report paths. */\n #settledDetail(): { value: string; rgba: { r: number; g: number; b: number; a: number } } {\n const rgb = hslToRgb(this.#color.hue, this.#color.saturation, this.#color.lightness);\n return { value: this.#hexString(), rgba: { ...rgb, a: this.#color.alpha / 100 } };\n }\n\n /** The current color as `#RRGGBB`, or `#RRGGBBAA` when alpha is enabled. */\n #hexString(): string {\n const rgb = hslToRgb(this.#color.hue, this.#color.saturation, this.#color.lightness);\n const base = `#${hex2(rgb.r)}${hex2(rgb.g)}${hex2(rgb.b)}`;\n if (!this.alphaValue) return base;\n return `${base}${hex2(Math.round((this.#color.alpha / 100) * 255))}`;\n }\n\n /** Reads a slider's `data-channel`, if it is a known channel. */\n #channelOf(slider: HTMLElement): Channel | null {\n const channel = slider.getAttribute(\"data-channel\");\n // Own keys only: an inherited name such as `toString` would otherwise index the\n // model with a function and be announced as one.\n return channel && Object.hasOwn(CHANNEL_RANGE, channel) ? (channel as Channel) : null;\n }\n\n /**\n * The channel a slider edits, or null when this picker edits none through it. An\n * alpha slider authored while `alpha` is off edits nothing: moving it would leave\n * the model translucent behind an opaque `#RRGGBB`.\n */\n #editableChannel(slider: HTMLElement): Channel | null {\n const channel = this.#channelOf(slider);\n return channel === \"alpha\" && !this.alphaValue ? null : channel;\n }\n\n /** The channel's announced text: the slider's template, or the built-in English. */\n #valueText(slider: HTMLElement, channel: Channel, value: number): string {\n const template = slider.getAttribute(VALUE_TEXT_ATTRIBUTE);\n // A placeholder with no substitution stays as authored, so a typo is visible\n // instead of being read as a blank.\n return template\n ? template.replaceAll(\"{value}\", String(value))\n : defaultValueText(channel, value);\n }\n\n /** Ends the live drag so no further movement of that pointer reaches the model. */\n #endDrag(): void {\n const drag = this.#drag;\n this.#drag = null;\n drag?.pointer?.end();\n }\n\n /**\n * A slider's `[min, max]` from aria-valuemin/max, falling back per channel.\n * An absent or blank attribute means \"not authored\", not zero — coercing it to\n * a number would pin the channel at `0` and make the per-channel default\n * unreachable.\n */\n #rangeOf(slider: HTMLElement, channel: Channel): [number, number] {\n const [defMin, defMax] = CHANNEL_RANGE[channel];\n return [\n toFiniteNumber(slider.getAttribute(\"aria-valuemin\")) ?? defMin,\n toFiniteNumber(slider.getAttribute(\"aria-valuemax\")) ?? defMax,\n ];\n }\n}\n\n/** Stable gesture state owned for the duration of one pointer drag. */\ninterface ColorDrag {\n pointer: OwnedPointerSession | null;\n readonly slider: HTMLElement;\n}\n\n/** Capitalizes a channel name for `aria-valuetext` (e.g. \"Hue\"). */\nfunction defaultValueText(channel: Channel, value: number): string {\n const label = channel.charAt(0).toUpperCase() + channel.slice(1);\n const unit = channel === \"hue\" ? \"degrees\" : \"percent\";\n return `${label} ${value} ${unit}`;\n}\n\n/** Formats a 0–255 byte as a 2-digit lowercase hex pair. */\nfunction hex2(value: number): string {\n return Math.round(Math.min(255, Math.max(0, value)))\n .toString(16)\n .padStart(2, \"0\");\n}\n\n/** Converts HSL (h:0–360, s/l:0–100) to RGB bytes (0–255). */\nfunction hslToRgb(h: number, s: number, l: number): { r: number; g: number; b: number } {\n const sat = s / 100;\n const light = l / 100;\n const c = (1 - Math.abs(2 * light - 1)) * sat;\n const hp = (((h % 360) + 360) % 360) / 60;\n const x = c * (1 - Math.abs((hp % 2) - 1));\n let r = 0;\n let g = 0;\n let b = 0;\n if (hp >= 0 && hp < 1) [r, g, b] = [c, x, 0];\n else if (hp < 2) [r, g, b] = [x, c, 0];\n else if (hp < 3) [r, g, b] = [0, c, x];\n else if (hp < 4) [r, g, b] = [0, x, c];\n else if (hp < 5) [r, g, b] = [x, 0, c];\n else [r, g, b] = [c, 0, x];\n const m = light - c / 2;\n return {\n r: Math.round((r + m) * 255),\n g: Math.round((g + m) * 255),\n b: Math.round((b + m) * 255),\n };\n}\n\n/** Converts RGB bytes (0–255) to HSL (h:0–360, s/l:0–100). */\nfunction rgbToHsl(r: number, g: number, b: number): { h: number; s: number; l: number } {\n const rn = r / 255;\n const gn = g / 255;\n const bn = b / 255;\n const max = Math.max(rn, gn, bn);\n const min = Math.min(rn, gn, bn);\n const delta = max - min;\n const l = (max + min) / 2;\n\n let h = 0;\n if (delta !== 0) {\n if (max === rn) h = ((gn - bn) / delta) % 6;\n else if (max === gn) h = (bn - rn) / delta + 2;\n else h = (rn - gn) / delta + 4;\n h = (h * 60 + 360) % 360;\n }\n const s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));\n return { h: Math.round(h), s: Math.round(s * 100), l: Math.round(l * 100) };\n}\n\n/**\n * Parses `#RGB`, `#RGBA`, `#RRGGBB`, or `#RRGGBBAA` into the HSLA model, or\n * returns null when the string is not a valid hex color.\n */\nfunction hexToHsla(input: string): Hsla | null {\n const hex = input.trim().replace(/^#/, \"\");\n if (!/^(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(hex)) return null;\n\n // Expand shorthand (#RGB / #RGBA) so every channel is a full byte pair.\n const full =\n hex.length <= 4\n ? hex\n .split(\"\")\n .map((char) => char + char)\n .join(\"\")\n : hex;\n\n const r = Number.parseInt(full.slice(0, 2), 16);\n const g = Number.parseInt(full.slice(2, 4), 16);\n const b = Number.parseInt(full.slice(4, 6), 16);\n const a = full.length === 8 ? Number.parseInt(full.slice(6, 8), 16) : 255;\n\n const { h, s, l } = rgbToHsl(r, g, b);\n return { hue: h, saturation: s, lightness: l, alpha: Math.round((a / 255) * 100) };\n}\n"]}
|
|
@@ -32,13 +32,27 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
32
32
|
* Behavior only — the consumer performs the actual data sort/render in response to
|
|
33
33
|
* the `sort` event and owns all styling. No timers or observers are held, so there
|
|
34
34
|
* is nothing to leak across Turbo navigations; `connect()` rebuilds the single tab
|
|
35
|
-
* stop idempotently from the DOM
|
|
35
|
+
* stop idempotently from the DOM, and the target callbacks rebuild it again after
|
|
36
|
+
* rows or cells are added or removed at runtime.
|
|
36
37
|
*
|
|
37
38
|
* Behavior provided:
|
|
38
39
|
* - `Arrow*` move between cells (clamped at edges); `Home`/`End` to the row's
|
|
39
40
|
* first/last cell; `Ctrl+Home`/`Ctrl+End` to the grid's first/last cell.
|
|
40
41
|
* - `Enter`/`Space` cycles a header's sort (`none→ascending→descending`) or toggles
|
|
41
42
|
* the focused row's selection when selection is enabled.
|
|
43
|
+
*
|
|
44
|
+
* Consumer contract — controls nested inside a cell or header:
|
|
45
|
+
* - APG's grid hosts working controls in its cells, so a keystroke or click that
|
|
46
|
+
* reached one — {@link INTERACTIVE_HOST_SELECTOR}, an editable host, or any
|
|
47
|
+
* widget that already called `preventDefault()` — is left to it entirely: no
|
|
48
|
+
* move, no sort, no selection. The one control that hands the event on is a
|
|
49
|
+
* sortable header's own `<button>`, whose activation is what the click carries.
|
|
50
|
+
* - A control keeps its own Tab behavior, so give it `tabindex="-1"` to preserve
|
|
51
|
+
* the grid's single Tab stop. A sortable `columnheader` hosting a `<button>` is
|
|
52
|
+
* the common case: the roving position stays on the header, and the button's
|
|
53
|
+
* own activation reaches `sort` through the click that bubbles to it.
|
|
54
|
+
* - Host `role="gridcell"` / `role="columnheader"` on a non-interactive element
|
|
55
|
+
* (`td`, `th`); an interactive host makes the grid stand down on that cell.
|
|
42
56
|
*/
|
|
43
57
|
declare class DataGridController extends Controller<HTMLElement> {
|
|
44
58
|
#private;
|
|
@@ -65,7 +79,7 @@ declare class DataGridController extends Controller<HTMLElement> {
|
|
|
65
79
|
* attribute, so the Value callback does not fire a second time.
|
|
66
80
|
*/
|
|
67
81
|
connect(): void;
|
|
68
|
-
/**
|
|
82
|
+
/** Closes the reconcile window so a queued pass cannot run against a detached tree. */
|
|
69
83
|
disconnect(): void;
|
|
70
84
|
/**
|
|
71
85
|
* Keeps `aria-multiselectable` in step with the `selection` Value. Fires on connect
|
|
@@ -73,14 +87,16 @@ declare class DataGridController extends Controller<HTMLElement> {
|
|
|
73
87
|
* never drifts from the selection logic, which reads `selectionValue` live.
|
|
74
88
|
*/
|
|
75
89
|
selectionValueChanged(): void;
|
|
76
|
-
/**
|
|
77
|
-
* Re-establishes the row baseline for a row added after connect.
|
|
78
|
-
*
|
|
79
|
-
* Each pass walks every row, and Stimulus reports the authored rows one by one
|
|
80
|
-
* before `connect()`, so the mount is gated to keep it linear in the row count
|
|
81
|
-
* rather than quadratic; `connect()` runs the single baseline pass instead.
|
|
82
|
-
*/
|
|
90
|
+
/** Re-establishes the baselines for a row added after connect. */
|
|
83
91
|
rowTargetConnected(): void;
|
|
92
|
+
/** Re-establishes the tab stop when a cell joins the grid after connect. */
|
|
93
|
+
cellTargetConnected(): void;
|
|
94
|
+
/** Re-establishes the tab stop when a cell leaves the grid. */
|
|
95
|
+
cellTargetDisconnected(): void;
|
|
96
|
+
/** Re-establishes the tab stop when a header joins the grid after connect. */
|
|
97
|
+
columnHeaderTargetConnected(): void;
|
|
98
|
+
/** Re-establishes the tab stop when a header leaves the grid. */
|
|
99
|
+
columnHeaderTargetDisconnected(): void;
|
|
84
100
|
/** Cycles the activated column header's sort and emits `sort`. */
|
|
85
101
|
sort(event: Event): void;
|
|
86
102
|
/** Toggles selection of the row owning the event target. Bound optionally. */
|