You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.0 KiB
69 lines
2.0 KiB
import type { DomApplier, DomAttrValue } from '$adom'
|
|
import type { SemanticSignal } from './signal'
|
|
|
|
/**
|
|
* Project a `SemanticSignal` onto its target as `data-event-*` attrs.
|
|
*
|
|
* These are the **semantic tokens** the cascade matches against
|
|
* (`[data-event-family="signal"]`, `[data-event-intent="threat"]`, …) and
|
|
* the same tokens that eidos CSS reads to tint borders / pulse focus
|
|
* during the hold. Same surface for sema's signal-time matching and
|
|
* eidos's CSS animation.
|
|
*
|
|
* Ownership: `VisualChannel.prepare()` projects these attrs BEFORE the
|
|
* cascade resolver, through a `SignalProjector`. The engine only invokes
|
|
* generic channel prepare hooks and cleans their handles AFTER the visual
|
|
* hold.
|
|
*
|
|
* Attrs written:
|
|
* - `data-event` — signal.name (always)
|
|
* - `data-event-id` — signal.id (always; the engine generates one
|
|
* if the caller didn't pass it)
|
|
* - `data-event-phase` — `'active'` (always)
|
|
* - `data-event-family` — signal.family (when present)
|
|
* - `data-event-intent` — signal.intent (when present)
|
|
*/
|
|
export function eventAttrs(signal: SemanticSignal): Record<string, DomAttrValue> {
|
|
const attrs: Record<string, DomAttrValue> = {
|
|
'data-event': signal.name,
|
|
'data-event-id': signal.id ?? '',
|
|
'data-event-phase': 'active',
|
|
'data-event-family': signal.family,
|
|
'data-event-intent': signal.intent
|
|
}
|
|
|
|
return attrs
|
|
}
|
|
|
|
export function clearEventAttrs(): Record<string, DomAttrValue> {
|
|
return {
|
|
'data-event': undefined,
|
|
'data-event-id': undefined,
|
|
'data-event-phase': undefined,
|
|
'data-event-family': undefined,
|
|
'data-event-intent': undefined
|
|
}
|
|
}
|
|
|
|
export function stampEventAttrs(
|
|
target: HTMLElement,
|
|
signal: SemanticSignal,
|
|
dom: DomApplier
|
|
): void {
|
|
dom.apply({
|
|
target,
|
|
attrs: eventAttrs(signal)
|
|
})
|
|
}
|
|
|
|
export function unstampEventAttrs(
|
|
target: HTMLElement,
|
|
_signal: SemanticSignal,
|
|
dom: DomApplier
|
|
): void {
|
|
dom.apply({
|
|
target,
|
|
attrs: clearEventAttrs()
|
|
})
|
|
}
|