@fusion.dev/helix-core 0.241.3 → 0.243.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.
@@ -0,0 +1,284 @@
1
+ import { reducedMotion } from '../../utils/page-motion/page-motion.js';
2
+ const ARRIVAL = 6;
3
+ const milliseconds = (value) => {
4
+ const amount = Number.parseFloat(value);
5
+ if (!Number.isFinite(amount)) {
6
+ return 0;
7
+ }
8
+ return value.trim().endsWith('ms') ? amount : amount * 1000;
9
+ };
10
+ const scaleOf = (host, box) => {
11
+ const along = (drawn, laid) => laid > 0 && Math.abs(drawn - laid) > 1 ? drawn / laid : 1;
12
+ return { x: along(box.width, host.offsetWidth), y: along(box.height, host.offsetHeight) };
13
+ };
14
+ const boxesOf = (element) => {
15
+ if (getComputedStyle(element).display !== 'contents') {
16
+ return element instanceof HTMLElement ? [element] : [];
17
+ }
18
+ const inside = element instanceof HTMLSlotElement
19
+ ? element.assignedElements({ flatten: true })
20
+ : [...(element.shadowRoot ?? element).children];
21
+ return inside.flatMap(boxesOf);
22
+ };
23
+ export class LayoutMotionController {
24
+ constructor(host, options) {
25
+ this.places = new Map();
26
+ this.sizes = new Map();
27
+ this.recorded = false;
28
+ this.order = [];
29
+ this.flights = new WeakMap();
30
+ this.host = host;
31
+ this.options = options;
32
+ host.addController(this);
33
+ }
34
+ hostConnected() {
35
+ if (this.options.watch !== 'updates' && typeof MutationObserver !== 'undefined') {
36
+ this.mutations ??= new MutationObserver((records) => this.heard(records));
37
+ this.mutations.observe(this.host, {
38
+ attributeFilter: ['hidden'],
39
+ childList: true,
40
+ subtree: true,
41
+ });
42
+ }
43
+ if (typeof ResizeObserver !== 'undefined') {
44
+ this.resizes ??= new ResizeObserver(() => this.record());
45
+ this.resizes.observe(this.host);
46
+ }
47
+ }
48
+ hostDisconnected() {
49
+ this.mutations?.disconnect();
50
+ this.resizes?.disconnect();
51
+ this.places = new Map();
52
+ this.order = [];
53
+ this.recorded = false;
54
+ }
55
+ hostUpdated() {
56
+ if (this.options.watch !== 'updates') {
57
+ return;
58
+ }
59
+ queueMicrotask(() => {
60
+ const items = this.options.items();
61
+ const same = items.length === this.order.length && items.every((item, at) => item === this.order[at]);
62
+ if (!same) {
63
+ this.move();
64
+ }
65
+ });
66
+ }
67
+ heard(records) {
68
+ const items = new Set(this.options.items());
69
+ const changed = records.some((one) => one.type === 'childList'
70
+ ? one.target === this.host ||
71
+ (items.has(one.target) &&
72
+ ([...one.addedNodes].some((node) => items.has(node)) ||
73
+ [...one.removedNodes].some((node) => this.places.has(node))))
74
+ : items.has(one.target) || one.target.parentNode === this.host);
75
+ if (!changed) {
76
+ return;
77
+ }
78
+ const pending = records
79
+ .flatMap((one) => [...one.addedNodes])
80
+ .filter((node) => node instanceof HTMLElement &&
81
+ 'updateComplete' in node &&
82
+ node.isUpdatePending === true);
83
+ if (pending.length > 0) {
84
+ void Promise.all(pending.map((node) => node.updateComplete)).then(() => this.move());
85
+ return;
86
+ }
87
+ this.move();
88
+ }
89
+ record() {
90
+ const { now, sizes } = this.measure();
91
+ this.places = now;
92
+ this.sizes = sizes;
93
+ this.order = this.options.items();
94
+ this.recorded = true;
95
+ }
96
+ measure() {
97
+ const items = this.options.items();
98
+ const all = new Set(items);
99
+ const within = new Map();
100
+ for (const item of items) {
101
+ for (let up = item.parentElement; up && up !== this.host; up = up.parentElement) {
102
+ if (all.has(up)) {
103
+ within.set(item, up);
104
+ break;
105
+ }
106
+ }
107
+ }
108
+ const showing = new Map();
109
+ const shown = (item) => {
110
+ const known = showing.get(item);
111
+ if (known) {
112
+ return known;
113
+ }
114
+ const own = this.offset(item);
115
+ const outer = within.get(item);
116
+ const around = outer ? shown(outer) : { x: 0, y: 0 };
117
+ const total = { x: own.x + around.x, y: own.y + around.y };
118
+ showing.set(item, total);
119
+ return total;
120
+ };
121
+ const now = new Map();
122
+ const sizes = new Map();
123
+ const frame = this.host.getBoundingClientRect();
124
+ const scale = scaleOf(this.host, frame);
125
+ const scroller = this.options.scroller?.();
126
+ const scrolled = { x: scroller?.scrollLeft ?? 0, y: scroller?.scrollTop ?? 0 };
127
+ for (const item of items) {
128
+ const first = this.boxes(item)[0];
129
+ if (!first || first.getClientRects().length === 0) {
130
+ continue;
131
+ }
132
+ const box = first.getBoundingClientRect();
133
+ const offset = shown(item);
134
+ now.set(item, {
135
+ x: (box.left - frame.left) / scale.x - offset.x + scrolled.x,
136
+ y: (box.top - frame.top) / scale.y - offset.y + scrolled.y,
137
+ });
138
+ sizes.set(item, { height: box.height / scale.y, width: box.width / scale.x });
139
+ }
140
+ return { now, showing, sizes, within };
141
+ }
142
+ boxes(item) {
143
+ return this.options.boxes ? this.options.boxes(item).flatMap(boxesOf) : boxesOf(item);
144
+ }
145
+ offset(item) {
146
+ const flight = this.flights.get(item);
147
+ const first = flight?.animations[0];
148
+ const progress = first?.effect?.getComputedTiming().progress;
149
+ if (!flight || typeof progress !== 'number' || first?.playState !== 'running') {
150
+ return { x: 0, y: 0 };
151
+ }
152
+ return { x: flight.from.x * (1 - progress), y: flight.from.y * (1 - progress) };
153
+ }
154
+ move() {
155
+ const before = this.places;
156
+ const sized = this.sizes;
157
+ const recorded = this.recorded;
158
+ const { now, showing, sizes, within } = this.measure();
159
+ this.places = now;
160
+ this.sizes = sizes;
161
+ this.order = this.options.items();
162
+ this.recorded = true;
163
+ const timing = this.options.timing();
164
+ const duration = milliseconds(timing.duration);
165
+ if (!recorded || duration < 1 || reducedMotion()) {
166
+ return;
167
+ }
168
+ const easing = timing.easing.trim() || 'ease';
169
+ const replaced = !(this.options.arriveIntoEmpty && before.size === 0) &&
170
+ [...now.keys()].every((item) => !before.has(item));
171
+ if (this.options.leaving && !replaced) {
172
+ this.leave(before, sized, now, duration);
173
+ }
174
+ const journeys = new Map();
175
+ for (const [item, place] of now) {
176
+ const was = before.get(item);
177
+ if (was) {
178
+ const drawn = showing.get(item) ?? { x: 0, y: 0 };
179
+ journeys.set(item, { x: was.x + drawn.x - place.x, y: was.y + drawn.y - place.y });
180
+ }
181
+ }
182
+ for (const item of now.keys()) {
183
+ const outer = within.get(item);
184
+ const journey = journeys.get(item);
185
+ if (!journey) {
186
+ const carried = outer !== undefined && now.has(outer) && !before.has(outer);
187
+ if (!replaced && !carried) {
188
+ this.arrive(item, duration, easing);
189
+ }
190
+ continue;
191
+ }
192
+ const around = (outer && journeys.get(outer)) ?? { x: 0, y: 0 };
193
+ const from = { x: journey.x - around.x, y: journey.y - around.y };
194
+ this.land(item);
195
+ if (Math.abs(from.x) < 0.5 && Math.abs(from.y) < 0.5) {
196
+ continue;
197
+ }
198
+ const animations = this.boxes(item).map((box) => box.animate([{ transform: `translate(${from.x}px, ${from.y}px)` }, { transform: 'translate(0, 0)' }], { composite: 'add', duration, easing }));
199
+ this.flights.set(item, { animations, from });
200
+ }
201
+ }
202
+ arrive(item, duration, easing) {
203
+ this.land(item);
204
+ for (const box of this.boxes(item)) {
205
+ box.animate([{ opacity: 0 }, { opacity: 1 }], { duration, easing });
206
+ box.animate([{ transform: `translate(0, ${-ARRIVAL}px)` }, { transform: 'translate(0, 0)' }], {
207
+ composite: 'add',
208
+ duration,
209
+ easing,
210
+ });
211
+ }
212
+ }
213
+ leave(before, sizes, now, duration) {
214
+ const holder = this.options.leaving?.();
215
+ if (!holder) {
216
+ return;
217
+ }
218
+ const gone = [...before.keys()].filter((item) => !now.has(item));
219
+ const outermost = gone.filter((item) => {
220
+ for (let up = item.parentElement; up && up !== this.host; up = up.parentElement) {
221
+ if (gone.includes(up)) {
222
+ return false;
223
+ }
224
+ }
225
+ return true;
226
+ });
227
+ if (outermost.length === 0) {
228
+ return;
229
+ }
230
+ const frame = this.host.getBoundingClientRect();
231
+ const scale = scaleOf(this.host, frame);
232
+ const box = holder instanceof ShadowRoot ? this.host : holder;
233
+ const corner = box === this.host
234
+ ? { x: this.host.clientLeft, y: this.host.clientTop }
235
+ : (() => {
236
+ const rect = box.getBoundingClientRect();
237
+ return {
238
+ x: (rect.left - frame.left) / scale.x + box.clientLeft - box.scrollLeft,
239
+ y: (rect.top - frame.top) / scale.y + box.clientTop - box.scrollTop,
240
+ };
241
+ })();
242
+ for (const item of outermost) {
243
+ const place = before.get(item);
244
+ const size = sizes.get(item);
245
+ if (!place || !size || (size.width === 0 && size.height === 0)) {
246
+ continue;
247
+ }
248
+ const copy = item.cloneNode(true);
249
+ copy.removeAttribute('id');
250
+ copy.removeAttribute('slot');
251
+ copy.removeAttribute('hidden');
252
+ copy.setAttribute('aria-hidden', 'true');
253
+ copy.setAttribute('data-leaving', '');
254
+ copy.inert = true;
255
+ Object.assign(copy.style, {
256
+ blockSize: `${size.height}px`,
257
+ boxSizing: 'border-box',
258
+ inlineSize: `${size.width}px`,
259
+ left: `${place.x - corner.x}px`,
260
+ margin: '0',
261
+ pointerEvents: 'none',
262
+ position: 'absolute',
263
+ top: `${place.y - corner.y}px`,
264
+ });
265
+ holder.appendChild(copy);
266
+ if (typeof copy.animate !== 'function') {
267
+ copy.remove();
268
+ continue;
269
+ }
270
+ const fade = copy.animate([
271
+ { opacity: 1, transform: 'scale(1)' },
272
+ { opacity: 0, transform: 'scale(0.9)' },
273
+ ], { duration: duration / 2, easing: 'cubic-bezier(0.3, 0, 1, 1)', fill: 'forwards' });
274
+ const done = () => copy.remove();
275
+ void fade.finished.then(done, done);
276
+ }
277
+ }
278
+ land(item) {
279
+ for (const animation of this.flights.get(item)?.animations ?? []) {
280
+ animation.cancel();
281
+ }
282
+ this.flights.delete(item);
283
+ }
284
+ }
@@ -0,0 +1,41 @@
1
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ /** What a `PointerFollowController` tells its host. */
3
+ export interface PointerFollowOptions {
4
+ /**
5
+ * Where the pointer is over the host, once a frame while it moves: `x` from
6
+ * -1 at the inline start edge to 1 at the inline end, and `y` from -1 at the
7
+ * top to 1 at the bottom, so the middle is 0 and 0. Mirrored on a
8
+ * right-to-left page.
9
+ */
10
+ moved: (x: number, y: number) => void;
11
+ /** The pointer has left the host, or stopped being followed. */
12
+ left: () => void;
13
+ }
14
+ /**
15
+ * Follows a mouse or pen across its host, for a component that leans or
16
+ * drifts toward the pointer, such as `Tilt` and `Magnetic`.
17
+ *
18
+ * **A touch is not followed.** A finger is on the element only while it
19
+ * presses, so a lean toward it reads as the element dodging the press. Nor is
20
+ * a pointer followed where the reader asked for less movement, read when the
21
+ * pointer arrives, so the host never moves at all there.
22
+ *
23
+ * Positions are read once a frame at most, from the host's box, and handed
24
+ * over as shares of its half-width and half-height.
25
+ */
26
+ export declare class PointerFollowController implements ReactiveController {
27
+ private readonly host;
28
+ private readonly options;
29
+ /** The last position heard and not yet handed over. */
30
+ private pending;
31
+ /** The frame that hands `pending` over. */
32
+ private frame;
33
+ /** Whether the host has been told of a position since it was last told the pointer left. */
34
+ private following;
35
+ constructor(host: ReactiveControllerHost & HTMLElement, options: PointerFollowOptions);
36
+ hostConnected(): void;
37
+ hostDisconnected(): void;
38
+ private readonly move;
39
+ private readonly hand;
40
+ private readonly leave;
41
+ }
@@ -0,0 +1,59 @@
1
+ import { reducedMotion } from '../../utils/page-motion/page-motion.js';
2
+ export class PointerFollowController {
3
+ constructor(host, options) {
4
+ this.frame = 0;
5
+ this.following = false;
6
+ this.move = (event) => {
7
+ if (event.pointerType === 'touch' || reducedMotion()) {
8
+ return;
9
+ }
10
+ this.pending = { x: event.clientX, y: event.clientY };
11
+ if (!this.frame) {
12
+ this.frame = requestAnimationFrame(this.hand);
13
+ }
14
+ };
15
+ this.hand = () => {
16
+ this.frame = 0;
17
+ const at = this.pending;
18
+ this.pending = undefined;
19
+ if (!at) {
20
+ return;
21
+ }
22
+ const box = this.host.getBoundingClientRect();
23
+ if (box.width <= 0 || box.height <= 0) {
24
+ return;
25
+ }
26
+ const across = ((at.x - box.left) / box.width) * 2 - 1;
27
+ const down = ((at.y - box.top) / box.height) * 2 - 1;
28
+ const clamp = (value) => Math.max(-1, Math.min(1, value));
29
+ const rtl = getComputedStyle(this.host).direction === 'rtl';
30
+ this.following = true;
31
+ this.options.moved(clamp(rtl ? -across : across), clamp(down));
32
+ };
33
+ this.leave = () => {
34
+ if (this.frame) {
35
+ cancelAnimationFrame(this.frame);
36
+ this.frame = 0;
37
+ }
38
+ this.pending = undefined;
39
+ if (this.following) {
40
+ this.following = false;
41
+ this.options.left();
42
+ }
43
+ };
44
+ this.host = host;
45
+ this.options = options;
46
+ host.addController(this);
47
+ }
48
+ hostConnected() {
49
+ this.host.addEventListener('pointermove', this.move);
50
+ this.host.addEventListener('pointerleave', this.leave);
51
+ this.host.addEventListener('pointercancel', this.leave);
52
+ }
53
+ hostDisconnected() {
54
+ this.host.removeEventListener('pointermove', this.move);
55
+ this.host.removeEventListener('pointerleave', this.leave);
56
+ this.host.removeEventListener('pointercancel', this.leave);
57
+ this.leave();
58
+ }
59
+ }
@@ -142,6 +142,25 @@ export declare const SPOKEN_RULE = "[data-spoken]{position:absolute;inline-size:
142
142
  * whatever the script, and so is a picture of a key.
143
143
  */
144
144
  export declare const MIRROR_RULE = ":host(:dir(rtl)) [data-mirror]{scale:-1 1}";
145
+ /**
146
+ * Turns a disclosure's caret, drawn pointing down, to point along the line
147
+ * while what it discloses is shut: right on a left-to-right page and left on a
148
+ * right-to-left one.
149
+ *
150
+ * **One glyph, turned, so a stylesheet can move it.** A caret drawn as a
151
+ * second glyph while shut pointed the right way on the headless tier and
152
+ * jumped between the two on the styled one, where Tree's, Accordion's and
153
+ * Log's turned on a transition. The mark keeps both: the component drawing the
154
+ * caret knows whether it is shut, so the headless tier points it the right way
155
+ * with no stylesheet, and a styled sheet adds a transition on `rotate`.
156
+ *
157
+ * `rotate` rather than `transform`, so a consumer's `transform` on the same
158
+ * part composes with it, and a consumer's `rotate` there wins, a shadow rule
159
+ * losing to a document one. Its own direction rather than `data-mirror`'s
160
+ * `scale`, which applies after `rotate` and would leave a turned caret
161
+ * pointing right on both pages. A component marks the caret `data-shut`.
162
+ */
163
+ export declare const SHUT_RULE = "[data-shut]{rotate:-90deg}:host(:dir(rtl)) [data-shut]{rotate:90deg}";
145
164
  /**
146
165
  * Hands every touch on an element to the component, which reads each one as
147
166
  * input of its own.
@@ -9,4 +9,5 @@ export const LAYERS_RULE = '[data-layers]{display:grid}' +
9
9
  ':where([data-layers])>textarea{caret-color:CanvasText}';
10
10
  export const SPOKEN_RULE = '[data-spoken]{position:absolute;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}';
11
11
  export const MIRROR_RULE = ':host(:dir(rtl)) [data-mirror]{scale:-1 1}';
12
+ export const SHUT_RULE = '[data-shut]{rotate:-90deg}:host(:dir(rtl)) [data-shut]{rotate:90deg}';
12
13
  export const TOUCHES_RULE = '[data-touches]{touch-action:none}';
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export { ChartPointerController, type ChartPointerHost, type ReadingHeard, } fro
10
10
  export { ChildrenController } from './controllers/children-controller/children-controller.js';
11
11
  export { CommandController, type CommandOptions, HelixFallbackCommandEvent, supportsInvokers, } from './controllers/command-controller/command-controller.js';
12
12
  export { CopyController, type CopyOptions, } from './controllers/copy-controller/copy-controller.js';
13
+ export { CountController, type CountOptions, } from './controllers/count-controller/count-controller.js';
13
14
  export { CountdownController, type CountdownOptions, } from './controllers/countdown-controller/countdown-controller.js';
14
15
  export { activeCue, adoptTrack, type Caption, CueController, captionsAmong, captionTracks, showCaption, } from './controllers/cue-controller/cue-controller.js';
15
16
  export { DelayController, type DelayOptions, } from './controllers/delay-controller/delay-controller.js';
@@ -20,9 +21,11 @@ export { FloatingController, type FloatingOptions, type Placement, type Side, }
20
21
  export { controlsIn, FocusScopeController, type FocusScopeOptions, } from './controllers/focus-scope-controller/focus-scope-controller.js';
21
22
  export { FullscreenController } from './controllers/fullscreen-controller/fullscreen-controller.js';
22
23
  export { HostClickController } from './controllers/host-click-controller/host-click-controller.js';
24
+ export { HoverMarkController, type HoverMarkOptions, } from './controllers/hover-mark-controller/hover-mark-controller.js';
23
25
  export { IdleController } from './controllers/idle-controller/idle-controller.js';
24
26
  export { IndicatorController, type IndicatorOptions, } from './controllers/indicator-controller/indicator-controller.js';
25
27
  export { type FocusItemOptions, focusItemOf, KeyboardNavigationController, type KeyboardNavigationOptions, type KeyboardOrigin, type NavigableItem, } from './controllers/keyboard-navigation-controller/keyboard-navigation-controller.js';
28
+ export { LayoutMotionController, type LayoutMotionOptions, } from './controllers/layout-motion-controller/layout-motion-controller.js';
26
29
  export { ListedController } from './controllers/listed-controller/listed-controller.js';
27
30
  export { MediaSessionController, type SessionHandlers, SKIP_SECONDS, } from './controllers/media-session-controller/media-session-controller.js';
28
31
  export { animationsFinished, animationsSettled, type OpenPhase, OpenPhaseController, type OpenPhaseOptions, } from './controllers/open-phase-controller/open-phase-controller.js';
@@ -30,6 +33,7 @@ export { OptionWindowController, type OptionWindowOptions, } from './controllers
30
33
  export { insideBox, OverflowController, type OverflowOptions, } from './controllers/overflow-controller/overflow-controller.js';
31
34
  export { MAX_FRAME_STEP, PaintGateController, type PaintGateOptions, } from './controllers/paint-gate-controller/paint-gate-controller.js';
32
35
  export { PlacementController } from './controllers/placement-controller/placement-controller.js';
36
+ export { PointerFollowController, type PointerFollowOptions, } from './controllers/pointer-follow-controller/pointer-follow-controller.js';
33
37
  export { hintInside, hintMayShow, onPanelOpen, PopoverController, type PopoverOptions, } from './controllers/popover-controller/popover-controller.js';
34
38
  export { RelativeClockController, type RelativeClockOptions, } from './controllers/relative-clock-controller/relative-clock-controller.js';
35
39
  export { RemotePlaybackController, type RemoteReport, } from './controllers/remote-playback-controller/remote-playback-controller.js';
@@ -46,7 +50,7 @@ export { eventsForTag, registerElementEvents } from './events/element-events.js'
46
50
  export { type ActivateDetail, type ChangeDetail, type CheckDetail, type CompleteDetail, type CopyDetail, type DismissDetail, type FilterDetail, type FoundDetail, HelixActivateEvent, HelixBeforeActivateEvent, HelixBeforeChangeEvent, HelixBeforeCheckEvent, HelixBeforeCloseEvent, HelixBeforeFilterEvent, HelixBeforeListenEvent, HelixBeforeNavigateEvent, HelixBeforeOpenEvent, HelixBeforePinEvent, HelixBeforeReorderEvent, HelixBeforeResizeEvent, HelixBeforeSelectEvent, HelixBeforeSortEvent, HelixCheckEvent, HelixClearEvent, HelixCompleteEvent, HelixCopyErrorEvent, HelixCopyEvent, HelixDismissEvent, HelixExpandEvent, HelixFilterEvent, HelixFoundEvent, HelixListenEvent, HelixLoadEvent, HelixLoadMoreEvent, HelixNavigateEvent, HelixPinEvent, HelixPlotChangeEvent, HelixPlotTurnEvent, HelixReadingChangeEvent, HelixReadingPressEvent, HelixReorderEvent, HelixResizedEvent, HelixResizeEvent, HelixSelectEvent, HelixSortEvent, type ListenDetail, type NavigateDetail, type OpenDetail, type PlotChangeDetail, type PlotTurnDetail, type PressPointerType, type ReadingDetail, type ReorderDetail, type ResizeDetail, type SelectDetail, type SortDetail, type ViewportPanDetail, type ViewportZoomDetail, } from './events/events.js';
47
51
  export { helixEventNames, registerEventNames } from './events/names.js';
48
52
  export { HelixElement, internalsOf, whenHydrated } from './helix-element/helix-element.js';
49
- export { LAYERS_RULE, MIRROR_RULE, SCROLLER_RULE, SPOKEN_RULE, TOUCHES_RULE, VIRTUAL_RULE, } from './helix-element/mark-rules.js';
53
+ export { LAYERS_RULE, MIRROR_RULE, SCROLLER_RULE, SHUT_RULE, SPOKEN_RULE, TOUCHES_RULE, VIRTUAL_RULE, } from './helix-element/mark-rules.js';
50
54
  export { untilReactHydrated } from './helix-element/react-bridge.js';
51
55
  export { HelixFormElement } from './helix-form-element/helix-form-element.js';
52
56
  export { HelixFormElementBase } from './helix-form-element/helix-form-element-base.js';
@@ -68,6 +72,7 @@ export { MixinTokens, type MixinTokensInterface } from './mixins/mixin-tokens/mi
68
72
  export { MixinViewport, type ViewportControlAxes, type ViewportControlsPlacement, type ViewportElement, type ViewportGestureLabels, type ViewportGestureMode, type ViewportGestures, type ViewportGlyphControl, type ViewportWay, } from './mixins/mixin-viewport/mixin-viewport.js';
69
73
  export { MixinVoice, type VoiceElement } from './mixins/mixin-voice/mixin-voice.js';
70
74
  export { anchorElement } from './utils/anchor-element/anchor-element.js';
75
+ export { type ArriveOptions, arrive } from './utils/arrive/arrive.js';
71
76
  export { arrowReach, sideOf } from './utils/arrow/arrow.js';
72
77
  export { assignSlot, assignSlots } from './utils/assign-slots/assign-slots.js';
73
78
  export { type DrawAutofillOptions, drawAutofill, } from './utils/autofill-select/autofill-select.js';
@@ -83,6 +88,7 @@ export { clamp } from './utils/clamp/clamp.js';
83
88
  export { clockLocale, dayPeriod, type HourCycle, isTwelveHour, nearestTime, offeredTimes, type TimeFault, type TimeRules, timeBarred, timeFault, wheelParts, wholeHour, } from './utils/clock/clock.js';
84
89
  export { closestInstance } from './utils/closest-instance/closest-instance.js';
85
90
  export { closestName } from './utils/closest-name/closest-name.js';
91
+ export { COLOR_MODE_ATTRIBUTE, COLOR_TRANSITION_ATTRIBUTE, type ColorMode, type ColorModeOptions, type ColorModeTransition, colorMode, onColorModeChange, setColorMode, } from './utils/color-mode/color-mode.js';
86
92
  export { type ColorWords, colorName, hueName } from './utils/color-name/color-name.js';
87
93
  export { columnStep } from './utils/column-step/column-step.js';
88
94
  export { contextBudget, type Holder, LIVE, pageBudget, } from './utils/context-budget/context-budget.js';
@@ -134,6 +140,7 @@ export { formatNumber, formatNumberParts, formatPercent, parseNumber, readingTex
134
140
  export { onUnlessFalse } from './utils/on-unless-false/on-unless-false.js';
135
141
  export { applyOwnRule, type OwnRule } from './utils/own-rule/own-rule.js';
136
142
  export { MOTION_ATTRIBUTE, motionPaused, onMotionChange, pauseMotion, reducedMotion, } from './utils/page-motion/page-motion.js';
143
+ export { changePage, PAGE_TRANSITION_ATTRIBUTE, type PageChangeOptions, type PageTransition, } from './utils/page-transition/page-transition.js';
137
144
  export { plainClick } from './utils/plain-click/plain-click.js';
138
145
  export { appleTouch, onAndroid, onApple, type Platform } from './utils/platform/platform.js';
139
146
  export { pressType, type RecentPress } from './utils/press-type/press-type.js';
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export { ChartPointerController, } from './controllers/chart-pointer-controller/
10
10
  export { ChildrenController } from './controllers/children-controller/children-controller.js';
11
11
  export { CommandController, HelixFallbackCommandEvent, supportsInvokers, } from './controllers/command-controller/command-controller.js';
12
12
  export { CopyController, } from './controllers/copy-controller/copy-controller.js';
13
+ export { CountController, } from './controllers/count-controller/count-controller.js';
13
14
  export { CountdownController, } from './controllers/countdown-controller/countdown-controller.js';
14
15
  export { activeCue, adoptTrack, CueController, captionsAmong, captionTracks, showCaption, } from './controllers/cue-controller/cue-controller.js';
15
16
  export { DelayController, } from './controllers/delay-controller/delay-controller.js';
@@ -20,9 +21,11 @@ export { FloatingController, } from './controllers/floating-controller/floating-
20
21
  export { controlsIn, FocusScopeController, } from './controllers/focus-scope-controller/focus-scope-controller.js';
21
22
  export { FullscreenController } from './controllers/fullscreen-controller/fullscreen-controller.js';
22
23
  export { HostClickController } from './controllers/host-click-controller/host-click-controller.js';
24
+ export { HoverMarkController, } from './controllers/hover-mark-controller/hover-mark-controller.js';
23
25
  export { IdleController } from './controllers/idle-controller/idle-controller.js';
24
26
  export { IndicatorController, } from './controllers/indicator-controller/indicator-controller.js';
25
27
  export { focusItemOf, KeyboardNavigationController, } from './controllers/keyboard-navigation-controller/keyboard-navigation-controller.js';
28
+ export { LayoutMotionController, } from './controllers/layout-motion-controller/layout-motion-controller.js';
26
29
  export { ListedController } from './controllers/listed-controller/listed-controller.js';
27
30
  export { MediaSessionController, SKIP_SECONDS, } from './controllers/media-session-controller/media-session-controller.js';
28
31
  export { animationsFinished, animationsSettled, OpenPhaseController, } from './controllers/open-phase-controller/open-phase-controller.js';
@@ -30,6 +33,7 @@ export { OptionWindowController, } from './controllers/option-window-controller/
30
33
  export { insideBox, OverflowController, } from './controllers/overflow-controller/overflow-controller.js';
31
34
  export { MAX_FRAME_STEP, PaintGateController, } from './controllers/paint-gate-controller/paint-gate-controller.js';
32
35
  export { PlacementController } from './controllers/placement-controller/placement-controller.js';
36
+ export { PointerFollowController, } from './controllers/pointer-follow-controller/pointer-follow-controller.js';
33
37
  export { hintInside, hintMayShow, onPanelOpen, PopoverController, } from './controllers/popover-controller/popover-controller.js';
34
38
  export { RelativeClockController, } from './controllers/relative-clock-controller/relative-clock-controller.js';
35
39
  export { RemotePlaybackController, } from './controllers/remote-playback-controller/remote-playback-controller.js';
@@ -46,7 +50,7 @@ export { eventsForTag, registerElementEvents } from './events/element-events.js'
46
50
  export { HelixActivateEvent, HelixBeforeActivateEvent, HelixBeforeChangeEvent, HelixBeforeCheckEvent, HelixBeforeCloseEvent, HelixBeforeFilterEvent, HelixBeforeListenEvent, HelixBeforeNavigateEvent, HelixBeforeOpenEvent, HelixBeforePinEvent, HelixBeforeReorderEvent, HelixBeforeResizeEvent, HelixBeforeSelectEvent, HelixBeforeSortEvent, HelixCheckEvent, HelixClearEvent, HelixCompleteEvent, HelixCopyErrorEvent, HelixCopyEvent, HelixDismissEvent, HelixExpandEvent, HelixFilterEvent, HelixFoundEvent, HelixListenEvent, HelixLoadEvent, HelixLoadMoreEvent, HelixNavigateEvent, HelixPinEvent, HelixPlotChangeEvent, HelixPlotTurnEvent, HelixReadingChangeEvent, HelixReadingPressEvent, HelixReorderEvent, HelixResizedEvent, HelixResizeEvent, HelixSelectEvent, HelixSortEvent, } from './events/events.js';
47
51
  export { helixEventNames, registerEventNames } from './events/names.js';
48
52
  export { HelixElement, internalsOf, whenHydrated } from './helix-element/helix-element.js';
49
- export { LAYERS_RULE, MIRROR_RULE, SCROLLER_RULE, SPOKEN_RULE, TOUCHES_RULE, VIRTUAL_RULE, } from './helix-element/mark-rules.js';
53
+ export { LAYERS_RULE, MIRROR_RULE, SCROLLER_RULE, SHUT_RULE, SPOKEN_RULE, TOUCHES_RULE, VIRTUAL_RULE, } from './helix-element/mark-rules.js';
50
54
  export { untilReactHydrated } from './helix-element/react-bridge.js';
51
55
  export { HelixFormElement } from './helix-form-element/helix-form-element.js';
52
56
  export { HelixFormElementBase } from './helix-form-element/helix-form-element-base.js';
@@ -68,6 +72,7 @@ export { MixinTokens } from './mixins/mixin-tokens/mixin-tokens.js';
68
72
  export { MixinViewport, } from './mixins/mixin-viewport/mixin-viewport.js';
69
73
  export { MixinVoice } from './mixins/mixin-voice/mixin-voice.js';
70
74
  export { anchorElement } from './utils/anchor-element/anchor-element.js';
75
+ export { arrive } from './utils/arrive/arrive.js';
71
76
  export { arrowReach, sideOf } from './utils/arrow/arrow.js';
72
77
  export { assignSlot, assignSlots } from './utils/assign-slots/assign-slots.js';
73
78
  export { drawAutofill, } from './utils/autofill-select/autofill-select.js';
@@ -83,6 +88,7 @@ export { clamp } from './utils/clamp/clamp.js';
83
88
  export { clockLocale, dayPeriod, isTwelveHour, nearestTime, offeredTimes, timeBarred, timeFault, wheelParts, wholeHour, } from './utils/clock/clock.js';
84
89
  export { closestInstance } from './utils/closest-instance/closest-instance.js';
85
90
  export { closestName } from './utils/closest-name/closest-name.js';
91
+ export { COLOR_MODE_ATTRIBUTE, COLOR_TRANSITION_ATTRIBUTE, colorMode, onColorModeChange, setColorMode, } from './utils/color-mode/color-mode.js';
86
92
  export { colorName, hueName } from './utils/color-name/color-name.js';
87
93
  export { columnStep } from './utils/column-step/column-step.js';
88
94
  export { contextBudget, LIVE, pageBudget, } from './utils/context-budget/context-budget.js';
@@ -134,6 +140,7 @@ export { formatNumber, formatNumberParts, formatPercent, parseNumber, readingTex
134
140
  export { onUnlessFalse } from './utils/on-unless-false/on-unless-false.js';
135
141
  export { applyOwnRule } from './utils/own-rule/own-rule.js';
136
142
  export { MOTION_ATTRIBUTE, motionPaused, onMotionChange, pauseMotion, reducedMotion, } from './utils/page-motion/page-motion.js';
143
+ export { changePage, PAGE_TRANSITION_ATTRIBUTE, } from './utils/page-transition/page-transition.js';
137
144
  export { plainClick } from './utils/plain-click/plain-click.js';
138
145
  export { appleTouch, onAndroid, onApple } from './utils/platform/platform.js';
139
146
  export { pressType } from './utils/press-type/press-type.js';
@@ -0,0 +1,21 @@
1
+ /** How `arrive` moves an element in. */
2
+ export interface ArriveOptions {
3
+ /** The duration token, such as `--helix-duration-normal`. */
4
+ duration: string;
5
+ /** The easing token, such as `--helix-easing-decelerate`. */
6
+ easing: string;
7
+ /** Where the element starts from; it ends where its stylesheet has it. */
8
+ from: Keyframe;
9
+ }
10
+ /**
11
+ * Brings an element in from `from` to where its stylesheet has it, **a frame
12
+ * after it joined the page**, for an element a stylesheet's `@starting-style`
13
+ * cannot reach: one a parent assigns to a slot by hand once it has arrived,
14
+ * which has no style at all until then, so its first style is its last.
15
+ *
16
+ * In that frame the element is styled and not yet painted, so it is never
17
+ * seen in its place before it moves. The time and the curve are the tokens
18
+ * named, read then, so a tier with no tokens, or a reader who asked for less
19
+ * motion, gets no move.
20
+ */
21
+ export declare const arrive: (element: HTMLElement, options: ArriveOptions) => void;
@@ -0,0 +1,22 @@
1
+ import { reducedMotion } from '../page-motion/page-motion.js';
2
+ export const arrive = (element, options) => {
3
+ if (typeof requestAnimationFrame !== 'function' || typeof element.animate !== 'function') {
4
+ return;
5
+ }
6
+ requestAnimationFrame(() => {
7
+ if (!element.isConnected || reducedMotion()) {
8
+ return;
9
+ }
10
+ const style = getComputedStyle(element);
11
+ const written = style.getPropertyValue(options.duration).trim();
12
+ const amount = Number.parseFloat(written);
13
+ const duration = written.endsWith('ms') ? amount : amount * 1000;
14
+ if (!(duration >= 1)) {
15
+ return;
16
+ }
17
+ element.animate([options.from, {}], {
18
+ duration,
19
+ easing: style.getPropertyValue(options.easing).trim() || 'ease-out',
20
+ });
21
+ });
22
+ };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The page's color mode, light or dark: read, set, and heard changing.
3
+ *
4
+ * **Kept on the document element**, as `data-color-mode`, which is the one
5
+ * thing `helix.css` decides the mode by. Absent, the mode is the reader's
6
+ * system setting. So a page can write it in its markup, set it from its own
7
+ * code with `setColorMode`, or leave it to `Theme Toggle`, and all of them
8
+ * agree.
9
+ */
10
+ /** A color mode. */
11
+ export type ColorMode = 'dark' | 'light';
12
+ /**
13
+ * How the page moves from one mode to the other: the new mode spreading in a
14
+ * circle from a point, wiping across from the inline start, fading over the
15
+ * old one, or taking its place at once.
16
+ */
17
+ export type ColorModeTransition = 'circle' | 'fade' | 'none' | 'wipe';
18
+ /** The attribute on the document element that holds the page's mode. */
19
+ export declare const COLOR_MODE_ATTRIBUTE = "data-color-mode";
20
+ /**
21
+ * The attribute on the document element that names the transition running,
22
+ * which `helix.css` draws the view transition by.
23
+ */
24
+ export declare const COLOR_TRANSITION_ATTRIBUTE = "data-helix-color-transition";
25
+ /** The page's mode: the one written on the document element, or the reader's system setting. Light on a server. */
26
+ export declare const colorMode: () => ColorMode;
27
+ /** What `setColorMode` is told about how to move. */
28
+ export interface ColorModeOptions {
29
+ /** How the page moves to the new mode. `circle` where this is not given. */
30
+ transition?: ColorModeTransition;
31
+ /**
32
+ * The point a `circle` spreads from, in viewport pixels, such as the middle
33
+ * of the button pressed. The middle of the viewport where this is not given.
34
+ */
35
+ from?: {
36
+ x: number;
37
+ y: number;
38
+ };
39
+ }
40
+ /**
41
+ * Sets the page's mode, moving to it as `transition` says.
42
+ *
43
+ * **The one view transition in Helix, and why it may be one.** A view
44
+ * transition draws the whole document twice and runs between the two, so a
45
+ * component cannot own one: two would cancel each other, and the page's own
46
+ * would be canceled by a component's. The color mode is the document's own
47
+ * state, which the page decides once, so changing it is the one move that is
48
+ * the document's to make. The page's code can call this as well as the button.
49
+ *
50
+ * The mode is set at once, with no transition, where the reader asked for
51
+ * reduced motion, where the browser has no view transitions, or for `none`.
52
+ * Resolves once the page shows the new mode.
53
+ */
54
+ export declare const setColorMode: (mode: ColorMode, options?: ColorModeOptions) => Promise<void>;
55
+ /**
56
+ * Calls `listener` with the page's mode whenever it changes: the attribute on
57
+ * the document element, or the reader's system setting while the attribute is
58
+ * absent. Returns what stops listening.
59
+ */
60
+ export declare const onColorModeChange: (listener: (mode: ColorMode) => void) => (() => void);