@vectoriox/iox-ui 5.87.0 → 5.88.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.
Files changed (32) hide show
  1. package/actions-core/index.d.ts +17 -3
  2. package/composite-core/index.d.ts +208 -2
  3. package/design-core/index.d.ts +373 -1
  4. package/fesm2022/vectoriox-iox-ui-actions-core.mjs +30 -4
  5. package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
  6. package/fesm2022/vectoriox-iox-ui-composite-core.mjs +656 -116
  7. package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
  8. package/fesm2022/vectoriox-iox-ui-design-core.mjs +444 -3
  9. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  10. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +5 -1
  11. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  12. package/fesm2022/vectoriox-iox-ui-scene-core.mjs +231 -7
  13. package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
  14. package/fesm2022/vectoriox-iox-ui.mjs +603 -20
  15. package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
  16. package/index.d.ts +196 -2
  17. package/package.json +1 -1
  18. package/scene-core/index.d.ts +158 -2
  19. package/src/actions-core/action.model.ts +3 -0
  20. package/src/actions-core/element-actions.ts +32 -3
  21. package/src/composite-core/marquee-runtime.ts +255 -0
  22. package/src/composite-core/marquee.ts +267 -0
  23. package/src/composite-core/public-api.ts +3 -0
  24. package/src/composite-core/scroll-recipes.ts +74 -0
  25. package/src/composite-core/structure.ts +7 -0
  26. package/src/design-core/contrast-audit.ts +6 -1
  27. package/src/design-core/flavor-spec.generated.ts +435 -1
  28. package/src/generation-core/node-baselines.generated.ts +5 -1
  29. package/src/scene-core/public-api.ts +1 -0
  30. package/src/scene-core/scroll-driver.ts +98 -0
  31. package/src/scene-core/scroll-range.ts +195 -0
  32. package/styles/iox-design.css +49 -1
@@ -0,0 +1,255 @@
1
+ import {
2
+ lookMarqueeSpeed, MarqueeAttribute, marqueeCopyCount, marqueeLoopSeconds, marqueePauseAttributes, marqueePauseGlyph, MarqueeRole, MarqueeSpeed, MarqueeWords,
3
+ marqueeWords,
4
+ } from './marquee';
5
+
6
+ /**
7
+ * The Marquee's RUNTIME (premium components M6, N6) — DOM only, ONE copy for the live site (both paths) and the canvas's
8
+ * "Showing on canvas ▸ Moving". The motion itself is CSS (iox-design.css: one `translate` keyframe, linear, on the
9
+ * track and its copy, started together by `MarqueeAttribute.Running`); this:
10
+ * - copies the track right after it — as many times as the rail needs (`marqueeCopyCount`), again when a size changes —
11
+ * each copy `aria-hidden` and `inert` (ids dropped), so the loop is seamless and a screen reader and the Tab key meet
12
+ * each item once;
13
+ * - sets one loop's duration from the track's own width and the look's speed (`--iox-marquee-speed`, px a second, on the
14
+ * motion axis), again when the track's size changes;
15
+ * - runs the pause control: its name says what pressing it will do, its glyph swaps;
16
+ * - holds the motion while the band is off screen or the tab is hidden (one attribute);
17
+ * - keeps the band STILL under reduced motion or a look whose motion is Off: no copy, no motion, no control — and
18
+ * follows the visitor's setting live (switched on with the page open, the band stops and its copies go).
19
+ * Hover (hover devices) and focus inside the rail pause it in CSS.
20
+ */
21
+
22
+ const SPEED_TOKEN = '--iox-marquee-speed';
23
+ /** The loop's keyframes (iox-design.css): the band runs toward its reading start, so a right-to-left one runs the other way. */
24
+ export const MARQUEE_KEYFRAMES = { ltr: 'iox-marquee', rtl: 'iox-marquee-rtl' } as const;
25
+ const REDUCED_MOTION = '(prefers-reduced-motion: reduce)';
26
+ const RUNTIME_KEY = '__ioxMarquee';
27
+ const AUTHOR_NAME_KEY = '__ioxMarqueeName';
28
+
29
+ function roleClass(role: MarqueeRole): string {
30
+ return `iox-role-${role.replace(/\./g, '-')}`;
31
+ }
32
+
33
+ /** The part of `role` that belongs to THIS band (never one of a band nested inside it). */
34
+ export function marqueePartElement(root: Element, role: MarqueeRole): HTMLElement | null {
35
+ for (const el of Array.from(root.querySelectorAll<HTMLElement>(`.${roleClass(role)}`))) {
36
+ if (el.closest(`[${MarqueeAttribute.Root}]`) === root) return el;
37
+ }
38
+ return null;
39
+ }
40
+
41
+ /** The rail's own child that holds the track: the track itself, or a host a renderer drew around it. */
42
+ function trackHostOf(rail: HTMLElement, track: HTMLElement): HTMLElement | null {
43
+ let el: HTMLElement | null = track;
44
+ while (el && el.parentElement !== rail) el = el.parentElement;
45
+ return el;
46
+ }
47
+
48
+ export interface MarqueeRuntimeOptions {
49
+ words?: MarqueeWords;
50
+ /** The window, for a test. */
51
+ host?: Window;
52
+ }
53
+
54
+ export class MarqueeRuntime {
55
+ readonly root: HTMLElement;
56
+ private readonly host: Window;
57
+ private readonly words: MarqueeWords;
58
+ private readonly track: HTMLElement | null;
59
+ private readonly rail: HTMLElement | null;
60
+ private readonly pause: HTMLElement | null;
61
+ private copies: HTMLElement[] = [];
62
+ private still = false;
63
+ private pausedByVisitor = false;
64
+ private offscreen = false;
65
+ private tabHidden = false;
66
+ private readonly cleanups: Array<() => void> = [];
67
+
68
+ constructor(root: HTMLElement, options: MarqueeRuntimeOptions = {}) {
69
+ this.root = root;
70
+ this.host = options.host ?? root.ownerDocument.defaultView ?? window;
71
+ this.words = options.words ?? marqueeWords(root.ownerDocument?.documentElement?.getAttribute('lang'));
72
+ this.track = marqueePartElement(root, MarqueeRole.Track);
73
+ this.rail = marqueePartElement(root, MarqueeRole.Rail);
74
+ this.pause = marqueePartElement(root, MarqueeRole.Pause);
75
+ (root as unknown as Record<string, unknown>)[RUNTIME_KEY] = this;
76
+ this.start();
77
+ this.watchReducedMotion();
78
+ }
79
+
80
+ /** The runtime a band already runs, if any. */
81
+ static of(root: Element): MarqueeRuntime | null {
82
+ return ((root as unknown as Record<string, unknown>)[RUNTIME_KEY] as MarqueeRuntime | undefined) ?? null;
83
+ }
84
+
85
+ get isStill(): boolean {
86
+ return this.still;
87
+ }
88
+
89
+ get isPaused(): boolean {
90
+ return this.pausedByVisitor;
91
+ }
92
+
93
+ /** Press the pause control. */
94
+ togglePause(): void {
95
+ if (this.still) return;
96
+ this.pausedByVisitor = !this.pausedByVisitor;
97
+ this.sync();
98
+ }
99
+
100
+ destroy(): void {
101
+ this.unwatch?.();
102
+ this.unwatch = null;
103
+ this.stop();
104
+ if ((this.root as unknown as Record<string, unknown>)[RUNTIME_KEY] === this) delete (this.root as unknown as Record<string, unknown>)[RUNTIME_KEY];
105
+ }
106
+
107
+ private unwatch: (() => void) | null = null;
108
+
109
+ /** The visitor's reduced-motion setting, followed live: the band stops (or starts again) where it stands. */
110
+ private watchReducedMotion(): void {
111
+ const query = this.host.matchMedia?.(REDUCED_MOTION);
112
+ if (!query?.addEventListener) return;
113
+ const onChange = (): void => {
114
+ this.stop();
115
+ this.start();
116
+ };
117
+ query.addEventListener('change', onChange);
118
+ this.unwatch = () => query.removeEventListener('change', onChange);
119
+ }
120
+
121
+ private stop(): void {
122
+ for (const cleanup of this.cleanups.splice(0)) cleanup();
123
+ for (const copy of this.copies.splice(0)) copy.remove();
124
+ this.track?.style.removeProperty('animation-duration');
125
+ this.track?.style.removeProperty('animation-name');
126
+ this.still = false;
127
+ this.pausedByVisitor = false;
128
+ this.offscreen = false;
129
+ for (const name of [MarqueeAttribute.Running, MarqueeAttribute.Still, MarqueeAttribute.Paused]) this.root.removeAttribute(name);
130
+ }
131
+
132
+ private start(): void {
133
+ const lookSpeed = lookMarqueeSpeed(this.host.getComputedStyle?.(this.root).getPropertyValue(SPEED_TOKEN));
134
+ const reduced = !!this.host.matchMedia?.(REDUCED_MOTION).matches;
135
+ if (!this.track || !this.rail || reduced || lookSpeed <= 0) {
136
+ this.still = true;
137
+ this.root.setAttribute(MarqueeAttribute.Still, '');
138
+ return;
139
+ }
140
+ this.measure(lookSpeed);
141
+ this.listen(lookSpeed);
142
+ this.sync();
143
+ this.root.setAttribute(MarqueeAttribute.Running, '');
144
+ }
145
+
146
+ /** As many copies as the rail needs, right after the track (the last one last). */
147
+ private fillCopies(count: number): void {
148
+ const holder = trackHostOf(this.rail!, this.track!);
149
+ if (!holder) return;
150
+ while (this.copies.length > count) this.copies.pop()!.remove();
151
+ while (this.copies.length < count) {
152
+ const copy = holder.cloneNode(true) as HTMLElement;
153
+ copy.setAttribute(MarqueeAttribute.Copy, '');
154
+ copy.setAttribute('aria-hidden', 'true');
155
+ copy.setAttribute('inert', '');
156
+ copy.removeAttribute('id');
157
+ copy.querySelectorAll('[id]').forEach(el => el.removeAttribute('id'));
158
+ (this.copies[this.copies.length - 1] ?? holder).after(copy);
159
+ this.copies.push(copy);
160
+ }
161
+ }
162
+
163
+ /** The copies and the loop's duration on every track: written on each, never through a variable on the band (Emil 51).
164
+ * A new copy starts its loop where the others stand: every track's animation is restarted together. */
165
+ private measure(lookSpeed: number): void {
166
+ const before = this.copies.length;
167
+ this.fillCopies(marqueeCopyCount(this.track!.offsetWidth, this.rail!.clientWidth));
168
+ const speed = (this.root.getAttribute(MarqueeAttribute.Root) as MarqueeSpeed) || MarqueeSpeed.Normal;
169
+ const seconds = marqueeLoopSeconds(this.track!.offsetWidth, lookSpeed, speed);
170
+ const value = seconds ? `${seconds}s` : '';
171
+ // A live page's right-to-left is CSS `direction` (never a `dir` attribute `:dir()` could see): read it.
172
+ const rtl = this.host.getComputedStyle?.(this.rail!).direction === 'rtl';
173
+ const moving = this.moving();
174
+ for (const el of moving) {
175
+ if (value) el.style.setProperty('animation-duration', value);
176
+ else el.style.removeProperty('animation-duration');
177
+ if (rtl) el.style.setProperty('animation-name', MARQUEE_KEYFRAMES.rtl);
178
+ else el.style.removeProperty('animation-name');
179
+ }
180
+ if (this.copies.length !== before) for (const el of moving) el.getAnimations?.().forEach(a => { a.currentTime = 0; });
181
+ }
182
+
183
+ private moving(): HTMLElement[] {
184
+ const trackClass = roleClass(MarqueeRole.Track);
185
+ const copyTracks = this.copies.map(copy => (copy.classList.contains(trackClass) ? copy : copy.querySelector<HTMLElement>(`.${trackClass}`)))
186
+ .filter((el): el is HTMLElement => !!el);
187
+ return [this.track!, ...copyTracks];
188
+ }
189
+
190
+ private listen(lookSpeed: number): void {
191
+ const onPress = (e: Event): void => {
192
+ e.preventDefault();
193
+ this.togglePause();
194
+ };
195
+ this.pause?.addEventListener('click', onPress);
196
+ this.cleanups.push(() => this.pause?.removeEventListener('click', onPress));
197
+
198
+ const doc = this.root.ownerDocument;
199
+ const onVisibility = (): void => {
200
+ this.tabHidden = doc.visibilityState === 'hidden';
201
+ this.sync();
202
+ };
203
+ doc.addEventListener('visibilitychange', onVisibility);
204
+ this.cleanups.push(() => doc.removeEventListener('visibilitychange', onVisibility));
205
+
206
+ const IO = (this.host as Window & { IntersectionObserver?: typeof IntersectionObserver }).IntersectionObserver;
207
+ if (IO) {
208
+ const observer = new IO(entries => {
209
+ for (const entry of entries) this.offscreen = !entry.isIntersecting;
210
+ this.sync();
211
+ });
212
+ observer.observe(this.root);
213
+ this.cleanups.push(() => observer.disconnect());
214
+ }
215
+ const RO = (this.host as Window & { ResizeObserver?: typeof ResizeObserver }).ResizeObserver;
216
+ if (RO && this.track) {
217
+ const resize = new RO(() => this.measure(lookSpeed));
218
+ resize.observe(this.track);
219
+ if (this.rail) resize.observe(this.rail);
220
+ this.cleanups.push(() => resize.disconnect());
221
+ }
222
+ }
223
+
224
+ private sync(): void {
225
+ const held = this.pausedByVisitor || this.offscreen || this.tabHidden;
226
+ if (held) this.root.setAttribute(MarqueeAttribute.Paused, '');
227
+ else this.root.removeAttribute(MarqueeAttribute.Paused);
228
+ if (!this.pause) return;
229
+ const host = this.pause as unknown as Record<string, unknown>;
230
+ if (host[AUTHOR_NAME_KEY] === undefined) host[AUTHOR_NAME_KEY] = this.pause.getAttribute('aria-label') ?? '';
231
+ const attrs = marqueePauseAttributes(this.pausedByVisitor, this.words, host[AUTHOR_NAME_KEY] as string);
232
+ for (const [name, value] of Object.entries(attrs)) this.pause.setAttribute(name, value);
233
+ if (!('aria-pressed' in attrs)) this.pause.removeAttribute('aria-pressed');
234
+ const icon = this.pause.querySelector('i');
235
+ if (icon) {
236
+ const own = Array.from(icon.classList).filter(c => c !== 'ph' && !c.startsWith('ph-'));
237
+ icon.className = [marqueePauseGlyph(this.pausedByVisitor), ...own].join(' ');
238
+ }
239
+ }
240
+ }
241
+
242
+ /** Every band in `container` (and the container itself when it is one), each run once. */
243
+ export function attachMarquees(container: ParentNode & Node, options: MarqueeRuntimeOptions = {}): MarqueeRuntime[] {
244
+ const roots: HTMLElement[] = [];
245
+ if ((container as HTMLElement).hasAttribute?.(MarqueeAttribute.Root)) roots.push(container as HTMLElement);
246
+ container.querySelectorAll?.<HTMLElement>(`[${MarqueeAttribute.Root}]`).forEach(el => roots.push(el));
247
+ return roots.filter(root => !MarqueeRuntime.of(root) && !root.closest(`[${MarqueeAttribute.Copy}]`))
248
+ .map(root => new MarqueeRuntime(root, options));
249
+ }
250
+
251
+ /**
252
+ * For a visitor with no script: the band stands still in its one row and its pause control, which could do nothing, is
253
+ * not shown. Served by the engine inside `<noscript>`, beside the entrance and Scene rules.
254
+ */
255
+ export const MARQUEE_NOSCRIPT_CSS = `.${roleClass(MarqueeRole.Pause)}{display:none!important}`;
@@ -0,0 +1,267 @@
1
+ import { CompositeNode, CompositeNodeFactory, makeCompositePart, NO_ELEMENT_STYLE, readProp, writeProp } from './composite-node';
2
+
3
+ /**
4
+ * THE MARQUEE (premium components M6, N6 — complex-components CC5 §7e, D5, Emil 180). A linear band that moves on its
5
+ * own, built from ordinary nodes with roles, so every part is selectable, editable and styled on its own (R2), and both
6
+ * renderers draw it with no new type:
7
+ *
8
+ * Container `marquee` role marquee the band; its settings are its own traits (speed, direction…)
9
+ * ├─ ButtonBlock `marquee-control` role marquee.pause FIRST focus stop: a real pause control (WCAG 2.2.2), locked
10
+ * └─ Container role marquee.rail what the band is seen through: clips, fades its edges; locked
11
+ * └─ Container role marquee.track the author's items, in one row; locked
12
+ * ├─ Text …
13
+ * └─ …
14
+ *
15
+ * The motion is the browser's: ONE CSS animation on the track and its copy (`translate`, linear, compositor only). The
16
+ * runtime (`marquee-runtime.ts`) only copies the track once for a seamless loop — the copy `aria-hidden` and `inert`, so a
17
+ * screen reader reads each item once and Tab never lands in it — sets the duration from the look's speed, and pauses it:
18
+ * the pause control, hover (hover devices) and focus inside the band, off screen, a hidden tab. Reduced motion and a look
19
+ * whose motion is Off keep it STILL (D5): no copy, no motion, no control.
20
+ */
21
+
22
+ export enum MarqueeRole {
23
+ Marquee = 'marquee',
24
+ Pause = 'marquee.pause',
25
+ Rail = 'marquee.rail',
26
+ Track = 'marquee.track',
27
+ }
28
+
29
+ /** The band's own traits (a Container's, hidden from the generic rows; Bindings ▸ Marquee edits them). */
30
+ export enum MarqueeTrait {
31
+ Speed = 'marqueeSpeed',
32
+ Direction = 'marqueeDirection',
33
+ Fade = 'marqueeFade',
34
+ PauseOnHover = 'marqueePauseOnHover',
35
+ }
36
+
37
+ export enum MarqueeSpeed {
38
+ Slow = 'slow',
39
+ Normal = 'normal',
40
+ Fast = 'fast',
41
+ }
42
+
43
+ /** Which way the items travel: toward the reading start (the classic ticker) or the end. Logical, so it mirrors in RTL. */
44
+ export enum MarqueeDirection {
45
+ Start = 'start',
46
+ End = 'end',
47
+ }
48
+
49
+ export enum MarqueeAttribute {
50
+ /** On the band; its value is the speed. */
51
+ Root = 'data-iox-marquee',
52
+ Direction = 'data-iox-marquee-direction',
53
+ Fade = 'data-iox-marquee-fade',
54
+ HoverPause = 'data-iox-marquee-hover',
55
+ /** The runtime's: the band moves. */
56
+ Running = 'data-iox-marquee-running',
57
+ /** The runtime's: the band stands still for good (reduced motion, a look whose motion is Off). */
58
+ Still = 'data-iox-marquee-still',
59
+ /** The runtime's: the motion is held (the visitor paused it, it is off screen, the tab is hidden). */
60
+ Paused = 'data-iox-marquee-paused',
61
+ /** The runtime's copy of the track. */
62
+ Copy = 'data-iox-marquee-copy',
63
+ }
64
+
65
+ /** Each speed, as a share of the look's `marquee-speed` (px a second). */
66
+ export const MARQUEE_SPEED_FACTOR: Readonly<Record<MarqueeSpeed, number>> = {
67
+ [MarqueeSpeed.Slow]: 0.6,
68
+ [MarqueeSpeed.Normal]: 1,
69
+ [MarqueeSpeed.Fast]: 1.6,
70
+ };
71
+
72
+ /** The look's speed when a page carries no design tokens (a legacy page): the Standard motion's. */
73
+ export const MARQUEE_DEFAULT_SPEED_PX = 40;
74
+ /** A loop is never shorter than this, however short the band: a fast flicker reads as broken (Emil 161). */
75
+ export const MARQUEE_MIN_LOOP_S = 8;
76
+
77
+ export interface MarqueeSettings {
78
+ speed: MarqueeSpeed;
79
+ direction: MarqueeDirection;
80
+ fade: boolean;
81
+ pauseOnHover: boolean;
82
+ }
83
+
84
+ export const MARQUEE_DEFAULTS: Readonly<MarqueeSettings> = Object.freeze({
85
+ speed: MarqueeSpeed.Normal,
86
+ direction: MarqueeDirection.Start,
87
+ fade: true,
88
+ pauseOnHover: true,
89
+ });
90
+
91
+ const asBool = (value: unknown, fallback: boolean): boolean => value === undefined || value === null || value === '' ? fallback : value === true || value === 'true';
92
+ const oneOf = <T extends string>(values: Record<string, T>, value: unknown, fallback: T): T =>
93
+ (Object.values(values) as string[]).includes(String(value)) ? (value as T) : fallback;
94
+
95
+ /** A band's settings, from its own traits (either shape), each falling back to the default. */
96
+ export function marqueeSettings(node: CompositeNode | null | undefined): MarqueeSettings {
97
+ if (!node) return { ...MARQUEE_DEFAULTS };
98
+ return {
99
+ speed: oneOf(MarqueeSpeed, readProp(node, MarqueeTrait.Speed), MARQUEE_DEFAULTS.speed),
100
+ direction: oneOf(MarqueeDirection, readProp(node, MarqueeTrait.Direction), MARQUEE_DEFAULTS.direction),
101
+ fade: asBool(readProp(node, MarqueeTrait.Fade), MARQUEE_DEFAULTS.fade),
102
+ pauseOnHover: asBool(readProp(node, MarqueeTrait.PauseOnHover), MARQUEE_DEFAULTS.pauseOnHover),
103
+ };
104
+ }
105
+
106
+ /** Write settings onto a band. False when a builder node has no slot for one of them. */
107
+ export function setMarqueeSettings(node: CompositeNode, patch: Partial<MarqueeSettings>): boolean {
108
+ let ok = true;
109
+ if (patch.speed !== undefined) ok = writeProp(node, MarqueeTrait.Speed, patch.speed) && ok;
110
+ if (patch.direction !== undefined) ok = writeProp(node, MarqueeTrait.Direction, patch.direction) && ok;
111
+ if (patch.fade !== undefined) ok = writeProp(node, MarqueeTrait.Fade, patch.fade) && ok;
112
+ if (patch.pauseOnHover !== undefined) ok = writeProp(node, MarqueeTrait.PauseOnHover, patch.pauseOnHover) && ok;
113
+ return ok;
114
+ }
115
+
116
+ /** True for the band itself. */
117
+ export function isMarqueeRoot(node: { role?: string | null } | null | undefined): boolean {
118
+ return node?.role === MarqueeRole.Marquee;
119
+ }
120
+
121
+ /** The marquee a node belongs to (the band itself when it is one), from its ancestors (root first), or null. */
122
+ export function marqueeRootOf<T extends { role?: string | null }>(node: T, path: ReadonlyArray<T>): T | null {
123
+ if (isMarqueeRoot(node)) return node;
124
+ for (let i = path.length - 1; i >= 0; i--) if (isMarqueeRoot(path[i])) return path[i];
125
+ return null;
126
+ }
127
+
128
+ /** The attributes the band's element carries — the same decision in all three render paths. Empty for any other node. */
129
+ export function marqueeRootAttributes(node: CompositeNode | null | undefined): Record<string, string> {
130
+ if (!isMarqueeRoot(node)) return {};
131
+ const settings = marqueeSettings(node);
132
+ return {
133
+ [MarqueeAttribute.Root]: settings.speed,
134
+ [MarqueeAttribute.Direction]: settings.direction,
135
+ ...(settings.fade ? { [MarqueeAttribute.Fade]: '' } : {}),
136
+ ...(settings.pauseOnHover ? { [MarqueeAttribute.HoverPause]: '' } : {}),
137
+ };
138
+ }
139
+
140
+ /** Every attribute `marqueeRootAttributes` may write: what a live sync removes when it no longer applies. */
141
+ export const MARQUEE_NODE_ATTRIBUTES: ReadonlyArray<string> = [MarqueeAttribute.Root, MarqueeAttribute.Direction, MarqueeAttribute.Fade, MarqueeAttribute.HoverPause];
142
+
143
+ /**
144
+ * How long one loop takes: the track's width (its trailing gap included) at the look's speed and the band's share of it.
145
+ * Null when the band does not move (a speed of 0 — the look's motion is Off — or nothing to move).
146
+ */
147
+ export function marqueeLoopSeconds(trackWidthPx: number, lookSpeedPx: number, speed: MarqueeSpeed = MarqueeSpeed.Normal): number | null {
148
+ const pxPerSecond = lookSpeedPx * MARQUEE_SPEED_FACTOR[speed];
149
+ if (!(pxPerSecond > 0) || !(trackWidthPx > 0)) return null;
150
+ return Math.round(Math.max(MARQUEE_MIN_LOOP_S, trackWidthPx / pxPerSecond) * 100) / 100;
151
+ }
152
+
153
+ /** The most copies a band makes: a single short word on a very wide screen still loops, with a bounded DOM. */
154
+ export const MARQUEE_MAX_COPIES = 12;
155
+
156
+ /**
157
+ * How many copies of the track a seamless loop needs: when the track has run its own width out of the rail, the copies
158
+ * behind it must still cover the whole rail — so `copies × track ≥ rail`, and never fewer than one. A short band of words
159
+ * on a wide screen needs several (one copy left a blank stretch at the end of each loop).
160
+ */
161
+ export function marqueeCopyCount(trackWidthPx: number, railWidthPx: number): number {
162
+ if (!(trackWidthPx > 0)) return 1;
163
+ const needed = Math.ceil(Math.max(0, railWidthPx) / trackWidthPx);
164
+ return Math.min(MARQUEE_MAX_COPIES, Math.max(1, needed));
165
+ }
166
+
167
+ /** The look's speed as a number of px a second, from its token's computed value; the default when it has none. */
168
+ export function lookMarqueeSpeed(raw: string | null | undefined): number {
169
+ const value = parseFloat(String(raw ?? '').trim());
170
+ return Number.isFinite(value) && value >= 0 ? value : MARQUEE_DEFAULT_SPEED_PX;
171
+ }
172
+
173
+ // ── accessibility vocabulary ──────────────────────────────────────────────────────────────────────
174
+
175
+ export interface MarqueeWords {
176
+ pause: string;
177
+ play: string;
178
+ }
179
+
180
+ export const MARQUEE_WORDS: Readonly<Record<'en' | 'he', MarqueeWords>> = {
181
+ en: { pause: 'Pause the moving band', play: 'Play the moving band' },
182
+ he: { pause: 'עצירת הפס הנע', play: 'הפעלת הפס הנע' },
183
+ };
184
+
185
+ export function marqueeWords(lang?: string | null): MarqueeWords {
186
+ return (lang ?? '').toLowerCase().startsWith('he') ? MARQUEE_WORDS.he : MARQUEE_WORDS.en;
187
+ }
188
+
189
+ export const MARQUEE_PAUSE_GLYPH = 'ph ph-pause';
190
+ export const MARQUEE_PLAY_GLYPH = 'ph-fill ph-play';
191
+
192
+ /**
193
+ * The pause control's state (APG, like the carousel's): its NAME says what pressing it will do. An author who named it
194
+ * keeps the name, and the state is `aria-pressed` instead (pressed = paused).
195
+ */
196
+ export function marqueePauseAttributes(paused: boolean, words: MarqueeWords = MARQUEE_WORDS.en, authorName?: string | null): Record<string, string> {
197
+ const name = (authorName ?? '').trim();
198
+ return name ? { 'aria-label': name, 'aria-pressed': paused ? 'true' : 'false' } : { 'aria-label': paused ? words.play : words.pause };
199
+ }
200
+
201
+ export function marqueePauseGlyph(paused: boolean): string {
202
+ return paused ? MARQUEE_PLAY_GLYPH : MARQUEE_PAUSE_GLYPH;
203
+ }
204
+
205
+ // ── the recipe ──────────────────────────────────────────────────────────────────────────────────────
206
+
207
+ enum Type {
208
+ Container = 'Container',
209
+ ButtonBlock = 'ButtonBlock',
210
+ Icon = 'Icon',
211
+ Text = 'Text',
212
+ }
213
+
214
+ export enum MarqueeStyle {
215
+ Band = 'marquee',
216
+ Control = 'marquee-control',
217
+ Item = 'lead',
218
+ Icon = 'icon',
219
+ }
220
+
221
+ const ZERO = '0px 0px 0px 0px';
222
+ const GAP = 'var(--iox-marquee-gap, 24px)';
223
+ /** The band: the control at its reading start, the rail taking the rest. */
224
+ const BAND_BASE: Readonly<Record<string, string>> = {
225
+ display: 'flex', flexDirection: 'row', flexWrap: 'nowrap', alignItems: 'center', width: '100%', minHeight: 'auto', padding: ZERO,
226
+ };
227
+ /** What the band is seen through: it clips the moving row and holds the track and its copy side by side. */
228
+ const RAIL_BASE: Readonly<Record<string, string>> = {
229
+ display: 'flex', flexDirection: 'row', flexWrap: 'nowrap', alignItems: 'center', flexGrow: '1', flexShrink: '1', flexBasis: '0%',
230
+ minWidth: '0px', width: 'auto', minHeight: 'auto', overflow: 'hidden', padding: ZERO, margin: ZERO,
231
+ };
232
+ /** One row of items, as wide as they are; its trailing gap (inline-end padding) is part of its width, so the copy picks
233
+ * up exactly one gap after the last item and a loop of −100% is seamless. */
234
+ const TRACK_BASE: Readonly<Record<string, string>> = {
235
+ display: 'flex', flexDirection: 'row', flexWrap: 'nowrap', alignItems: 'center', gap: GAP, flexGrow: '0', flexShrink: '0',
236
+ width: 'max-content', minHeight: 'auto', margin: ZERO, padding: `0px ${GAP} 0px 0px`,
237
+ };
238
+ /** A 44px round control (the slider's), in the flow at the band's start. */
239
+ const CONTROL_BASE: Readonly<Record<string, string>> = {
240
+ display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: '0', width: '44px', height: '44px', minWidth: '44px',
241
+ padding: ZERO, margin: ZERO, borderRadius: '999px',
242
+ };
243
+ const ICON_BASE: Readonly<Record<string, string>> = { fontSize: '18px', color: 'inherit' };
244
+ const ITEM_BASE: Readonly<Record<string, string>> = { flexShrink: '0', margin: ZERO, width: 'auto' };
245
+
246
+ export const MARQUEE_SAMPLE_WORDS: ReadonlyArray<string> = ['Design', 'Branding', 'Photography', 'Websites', 'Motion'];
247
+
248
+ export interface MarqueeRecipeOptions {
249
+ words?: ReadonlyArray<string>;
250
+ }
251
+
252
+ /** A band of words (Components ▸ Interactive ▸ Marquee). The words are ordinary Text nodes: bind, restyle, replace. */
253
+ export function buildMarqueeRecipe(create: CompositeNodeFactory, options: MarqueeRecipeOptions = {}): CompositeNode {
254
+ const root = makeCompositePart(create, { key: 'marquee', type: Type.Container, props: {}, elementStyle: MarqueeStyle.Band }, MarqueeRole.Marquee, 'Marquee', BAND_BASE);
255
+ setMarqueeSettings(root, MARQUEE_DEFAULTS);
256
+ const pause = makeCompositePart(create, { key: 'marquee-pause', type: Type.ButtonBlock, props: { tag: 'button', type: 'button' }, elementStyle: MarqueeStyle.Control },
257
+ MarqueeRole.Pause, 'Pause', CONTROL_BASE);
258
+ const icon = makeCompositePart(create, { key: 'marquee-pause-icon', type: Type.Icon, props: { iconClass: MARQUEE_PAUSE_GLYPH }, elementStyle: MarqueeStyle.Icon }, null, 'Icon', ICON_BASE);
259
+ pause.children = [icon];
260
+ const rail = makeCompositePart(create, { key: 'marquee-rail', type: Type.Container, props: {}, elementStyle: NO_ELEMENT_STYLE }, MarqueeRole.Rail, 'Rail', RAIL_BASE);
261
+ const track = makeCompositePart(create, { key: 'marquee-track', type: Type.Container, props: {}, elementStyle: NO_ELEMENT_STYLE }, MarqueeRole.Track, 'Items', TRACK_BASE);
262
+ track.children = (options.words?.length ? options.words : MARQUEE_SAMPLE_WORDS).map((word, i) =>
263
+ makeCompositePart(create, { key: `marquee-item-${i + 1}`, type: Type.Text, props: { content: word }, elementStyle: MarqueeStyle.Item }, null, 'Item', ITEM_BASE));
264
+ rail.children = [track];
265
+ root.children = [pause, rail];
266
+ return root;
267
+ }
@@ -25,3 +25,6 @@ export * from './exclusive';
25
25
  export * from './exclusive-runtime';
26
26
  export * from './composite-runtime';
27
27
  export * from './header';
28
+ export * from './marquee';
29
+ export * from './marquee-runtime';
30
+ export * from './scroll-recipes';
@@ -0,0 +1,74 @@
1
+ import { CompositeNode, CompositeNodeFactory, makeCompositePart } from './composite-node';
2
+
3
+ /**
4
+ * Two recipes of premium components M6 that are ordinary nodes carrying interactions — so the builder's palette and
5
+ * generation-core's composer (M8) stamp the same thing:
6
+ * - the COUNTER (N5): a number that counts up once when it comes into view, with its few words under it. Its entrance
7
+ * hides it until it plays, so it counts in the first screen too (a number already read is never taken away).
8
+ * - the READING BAR (N7): a thin bar that fills as the page — or its section — is read, sticky at the top of what holds it.
9
+ */
10
+
11
+ enum Type {
12
+ Container = 'Container',
13
+ Text = 'Text',
14
+ }
15
+
16
+ enum Style {
17
+ Box = 'box',
18
+ Number = 'price',
19
+ Words = 'small',
20
+ Bar = 'progress-bar',
21
+ }
22
+
23
+ interface WithInteractions { interactions?: unknown[] }
24
+
25
+ const ZERO = '0px 0px 0px 0px';
26
+ const COUNTER_BASE: Readonly<Record<string, string>> = { display: 'flex', flexDirection: 'column', gap: '6px', minHeight: 'auto', width: 'auto', padding: ZERO };
27
+ const NUMBER_BASE: Readonly<Record<string, string>> = { margin: ZERO, width: 'auto' };
28
+ const WORDS_BASE: Readonly<Record<string, string>> = { margin: ZERO, width: 'auto' };
29
+ /** Sticky at the top of what holds it, over its neighbours (a low layer — never past the app's scale), full width. */
30
+ const BAR_BASE: Readonly<Record<string, string>> = {
31
+ display: 'block', position: 'sticky', top: '0px', zIndex: '2', width: '100%', minHeight: '0px', margin: ZERO, padding: ZERO,
32
+ };
33
+
34
+ /** The entrance that hides a counter's number until it plays: lead content rises a little as it fades (Emil 46). */
35
+ export const COUNTER_ENTRANCE = Object.freeze({ type: 'moveUp', duration: 500, distance: 12, easing: 'ease-enter' });
36
+ /** The count itself: well inside WCAG 2.2.2, decelerating into the value. */
37
+ export const COUNTER_COUNT = Object.freeze({ type: 'countUp', duration: 1200, easing: 'ease-out' });
38
+
39
+ export interface CounterWords {
40
+ number: string;
41
+ label: string;
42
+ }
43
+
44
+ export const COUNTER_SAMPLE_WORDS: Readonly<CounterWords> = Object.freeze({ number: '1,250+', label: 'projects delivered' });
45
+
46
+ /** A number that counts up once, and its words (Components ▸ Interactive ▸ Counter). */
47
+ export function buildCounterRecipe(create: CompositeNodeFactory, words: Partial<CounterWords> = {}): CompositeNode {
48
+ const text = { ...COUNTER_SAMPLE_WORDS, ...words };
49
+ const root = makeCompositePart(create, { key: 'counter', type: Type.Container, props: {}, elementStyle: Style.Box }, null, 'Counter', COUNTER_BASE);
50
+ const number = makeCompositePart(create, { key: 'counter-number', type: Type.Text, props: { content: text.number }, elementStyle: Style.Number }, null, 'Number', NUMBER_BASE);
51
+ const label = makeCompositePart(create, { key: 'counter-label', type: Type.Text, props: { content: text.label }, elementStyle: Style.Words }, null, 'Words', WORDS_BASE);
52
+ const { distance, ...entrance } = COUNTER_ENTRANCE;
53
+ (number as WithInteractions).interactions = [{
54
+ id: `${number.id ?? 'counter'}-count`, trigger: 'viewportEnter',
55
+ actions: [
56
+ { ...entrance, target: 'self', delay: 0, once: true, params: { distance } },
57
+ { ...COUNTER_COUNT, target: 'self', delay: 0, once: true },
58
+ ],
59
+ }];
60
+ root.children = [number, label];
61
+ return root;
62
+ }
63
+
64
+ /** A bar that fills as the page is read (Components ▸ Interactive ▸ Reading bar). Its range may be changed to "This
65
+ * section" in the Interactions panel. */
66
+ export function buildReadingBarRecipe(create: CompositeNodeFactory): CompositeNode {
67
+ const bar = makeCompositePart(create, { key: 'reading-bar', type: Type.Container, props: {}, elementStyle: Style.Bar }, null, 'Reading bar', BAR_BASE);
68
+ (bar as WithInteractions).interactions = [{
69
+ id: `${bar.id ?? 'bar'}-read`, trigger: 'scrollProgress', range: 'page',
70
+ actions: [{ type: 'progressBar', target: 'self', duration: 1000, delay: 0, easing: 'linear' }],
71
+ }];
72
+ bar.children = [];
73
+ return bar;
74
+ }
@@ -1,5 +1,6 @@
1
1
  import { AccordionRole, DisclosureRole, SceneRole, SegmentedRole, TabsRole } from './composite-kinds';
2
2
  import { CardPart, CardRole } from './card';
3
+ import { MarqueeRole } from './marquee';
3
4
  import { SLIDER_TYPE, SliderRole } from './slider';
4
5
 
5
6
  /**
@@ -71,6 +72,12 @@ export const COMPOSITE_ROLE_SPECS: Readonly<Record<string, CompositeRoleSpec>> =
71
72
  [SliderRole.Bar]: { parent: null, parentType: SLIDER_TYPE, pinned: true },
72
73
  [SliderRole.Caption]: { parent: SliderRole.Bar, pinned: true },
73
74
  [SliderRole.Count]: { parent: SliderRole.Bar, pinned: true },
75
+ // M6 — a Marquee always keeps its pause control (WCAG 2.2.2: the band moves on its own), its rail and its track; the
76
+ // items in the track are the author's.
77
+ [MarqueeRole.Marquee]: { parent: null },
78
+ [MarqueeRole.Pause]: { parent: MarqueeRole.Marquee, locked: true },
79
+ [MarqueeRole.Rail]: { parent: MarqueeRole.Marquee, locked: true },
80
+ [MarqueeRole.Track]: { parent: MarqueeRole.Rail, locked: true },
74
81
  };
75
82
 
76
83
  export enum StructureEdit {
@@ -63,6 +63,9 @@ const SCRIM_HELD_TOKENS: ReadonlyArray<string> = ['heading-color', 'eyebrow-colo
63
63
  const SCHEME_IDS: ReadonlyArray<string> = Object.keys(SPEC_SCHEMES);
64
64
  const CONTAINER_GROUPS: ReadonlySet<string> = new Set(['Layout', 'Overlays']);
65
65
  const NOT_CONTENT: ReadonlySet<string> = new Set(['rule', 'media']);
66
+ /** Styles whose fill IS their mark (premium M6: a reading bar): the fill is judged as a graphic (3:1, WCAG 1.4.11) against
67
+ * the ground it sits on, never its own ink on it — it holds no words. The contract's audit, 1:1. */
68
+ export const MARK_STYLES: ReadonlySet<string> = new Set(['progress-bar']);
66
69
  const SECTION_STYLE = 'section';
67
70
  const ICON_STYLE = 'icon';
68
71
  const GLYPH_GROUP = 'Media';
@@ -111,7 +114,8 @@ export function auditDesignContrast(rows: ReadonlyArray<DesignTokenLike>, mode:
111
114
  const isItem = (e: ElementStyle) => CONTAINER_GROUPS.has(e.group) && !ownStyle(e)['backgroundColor']
112
115
  && !!ownStyle(e)['color'] && ownStyle(e)['color'] !== 'inherit';
113
116
  const content = styles.filter(e => (!CONTAINER_GROUPS.has(e.group) || isItem(e)) && (ownStyle(e)['color'] || ownStyle(e)['backgroundColor'])
114
- && e.group !== FORMS_GROUP && !NOT_CONTENT.has(e.id) && !SCRIM_STYLES.has(e.id));
117
+ && e.group !== FORMS_GROUP && !NOT_CONTENT.has(e.id) && !SCRIM_STYLES.has(e.id) && !MARK_STYLES.has(e.id));
118
+ const marks = styles.filter(e => MARK_STYLES.has(e.id));
115
119
  const notices = styles.filter(e => e.group === FORMS_GROUP && ownStyle(e)['color']);
116
120
  const section = ownStyle(byId.get(SECTION_STYLE) as ElementStyle);
117
121
  const iconColour = ownStyle(byId.get(ICON_STYLE) as ElementStyle)['color'];
@@ -179,6 +183,7 @@ export function auditDesignContrast(rows: ReadonlyArray<DesignTokenLike>, mode:
179
183
  if (focus) check(e.id, 'focus ring', ringColour(resolveIn(values, focus), ink), bgs, WCAG_AA_UI);
180
184
  }
181
185
  }
186
+ for (const e of marks) for (const f of paintColours(resolveIn(values, ownStyle(e)['backgroundColor']), boxInk)) check(e.id, 'mark', f, bgs, WCAG_AA_UI);
182
187
  for (const part of FORM_PARTS) {
183
188
  const fieldBg = paintColours(resolveIn(values, part.on ?? 'transparent'), boxInk);
184
189
  const under = part.on && opaque(fieldBg) ? overAll(fieldBg, bgs) : bgs;