@vectoriox/iox-ui 5.136.0 → 5.138.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/assist-core/index.d.ts +22 -4
- package/composite-core/index.d.ts +10 -2
- package/design-core/index.d.ts +257 -21
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs +12 -2
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +29 -5
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs +18 -2
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +431 -61
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +999 -259
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs +5 -4
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs +197 -28
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +538 -11
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +1118 -732
- package/harness-core/index.d.ts +2 -2
- package/index.d.ts +150 -4
- package/package.json +1 -1
- package/scene-core/index.d.ts +69 -13
- package/src/actions-core/element-actions.ts +14 -4
- package/src/assist-core/assist-turn.ts +3 -1
- package/src/assist-core/route-schema.ts +20 -5
- package/src/assist-core/surfaces.ts +12 -0
- package/src/composite-core/header.ts +18 -1
- package/src/design-core/design-settings.ts +14 -3
- package/src/design-core/design-token.model.ts +3 -0
- package/src/design-core/flavor-spec.generated.ts +64 -25
- package/src/design-core/graphemes.ts +16 -0
- package/src/design-core/header-behaviour.ts +20 -2
- package/src/design-core/motion-language.ts +11 -7
- package/src/design-core/node-classes.ts +10 -4
- package/src/design-core/preloader-of.ts +26 -0
- package/src/design-core/preloader.ts +49 -5
- package/src/design-core/public-api.ts +4 -0
- package/src/design-core/scrub.ts +37 -0
- package/src/design-core/section-edge.ts +223 -0
- package/src/design-core/style-presets.ts +2 -0
- package/src/generation-core/body-mix.ts +443 -0
- package/src/generation-core/check-layout.ts +42 -4
- package/src/generation-core/compose-layout.ts +28 -6
- package/src/generation-core/compose-site.ts +26 -8
- package/src/generation-core/header-mix.ts +4 -0
- package/src/generation-core/layout-fingerprint.ts +19 -1
- package/src/generation-core/layout-language.ts +21 -1
- package/src/generation-core/layout-wire.ts +27 -2
- package/src/generation-core/node-baselines.generated.ts +7 -2
- package/src/generation-core/opening-mix.ts +32 -0
- package/src/generation-core/plan-wire.ts +1 -0
- package/src/generation-core/public-api.ts +2 -0
- package/src/generation-core/redesign-run.ts +69 -2
- package/src/generation-core/site-build-run.ts +29 -7
- package/src/generation-core/site-plan.model.ts +2 -0
- package/src/generation-core/site-spec.generated.ts +120 -86
- package/src/generation-core/text-scroll.ts +179 -0
- package/src/generation-core/validate-site-plan.ts +4 -2
- package/src/harness-core/starting-design.ts +6 -5
- package/src/scene-core/scroll-range.ts +4 -0
- package/src/scene-core/split-text.ts +216 -28
- package/styles/iox-design.css +87 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { actionOfferedUnder, ELEMENT_ACTION_DESCRIPTORS, SCROLL_PROGRESS_TRIGGER } from '@vectoriox/iox-ui/actions-core';
|
|
2
|
+
import { ScrubId } from '@vectoriox/iox-ui/design-core';
|
|
3
|
+
|
|
4
|
+
import { ENTRANCE_EASING, ENTRANCE_ORIGIN_LOOK, ENTRANCE_TRIGGER } from './entrances';
|
|
5
|
+
import { LayoutEnter, LayoutRole } from './layout-language';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TEXT BY THE SCROLL (award-ingredients-plan AW10; board `award-text-scroll`) — the pure stamps. The runtime is the ONE
|
|
9
|
+
* `scrollProgress` runtime (`attachScrollProgress`), which plays a text's pieces since AW10 (`scrubTextReveal`); nothing
|
|
10
|
+
* here moves anything, it only says what a node carries.
|
|
11
|
+
*
|
|
12
|
+
* - **scrubbed**: an entrance the look stamps on time (`viewportEnter`, once) becomes the SAME action played by the
|
|
13
|
+
* scroll — wholly played when its element reaches the middle of the screen, let go there (its hover and press apply
|
|
14
|
+
* again). The first screen never scrubs: it is wholly in view at load, so a scroll entrance would be let go unseen.
|
|
15
|
+
* - **copy-out**: the opening's words fade as the page leaves it, following the scroll (graya) — a `fadeOut` played by
|
|
16
|
+
* the opening's own exit, gone at 0.6 of it. Opacity only, so it is the same under reduced motion.
|
|
17
|
+
* - **letter**: `params.by = 'letter'` on a text reveal (`TextRevealBy.Letter`); the split is the browser's, never the
|
|
18
|
+
* page's.
|
|
19
|
+
*
|
|
20
|
+
* Board approved 2026-11-22 (AW10-D1…D12): `planEntrances` runs every look stamp through `scrubbedEntrance` (the look's
|
|
21
|
+
* `design.scrub`, the opening excluded), the layout composer through `layoutScrub` (a layer's `scrub`), and
|
|
22
|
+
* `composeOpening` stamps copy-out when the opening's mix names it. The look's word is design-core's `ScrubId`.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** The action a text reveal is. */
|
|
26
|
+
const TEXT_REVEAL = 'revealText';
|
|
27
|
+
|
|
28
|
+
/** Where a scrubbed entrance plays: from its element's first pixel on screen, wholly played at the middle of it. */
|
|
29
|
+
export const SCRUBBED_ENTRANCE = Object.freeze({ range: 'cover', until: 0.5 });
|
|
30
|
+
|
|
31
|
+
/** Interactions ▸ Follow the scroll ▸ Wholly in by (AW10-D6): the middle of the screen (the default), three quarters of
|
|
32
|
+
* the way, or the end of its pass — `params.until`. */
|
|
33
|
+
export enum ScrubUntil {
|
|
34
|
+
Middle = 'middle',
|
|
35
|
+
ThreeQuarters = 'three-quarters',
|
|
36
|
+
End = 'end',
|
|
37
|
+
}
|
|
38
|
+
export const SCRUB_UNTIL: Readonly<Record<ScrubUntil, number>> = Object.freeze({ [ScrubUntil.Middle]: 0.5, [ScrubUntil.ThreeQuarters]: 0.75, [ScrubUntil.End]: 1 });
|
|
39
|
+
|
|
40
|
+
/** The Wholly in by choice a stored `until` reads as (absent or 1 = the end). */
|
|
41
|
+
export function scrubUntilChoice(until: unknown): ScrubUntil {
|
|
42
|
+
const n = Number(until);
|
|
43
|
+
return (Object.entries(SCRUB_UNTIL).find(([, v]) => v === n)?.[0] as ScrubUntil | undefined) ?? ScrubUntil.End;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Where copy-out plays: the opening's own exit, the words gone at 0.6 of it. */
|
|
47
|
+
export const COPY_OUT = Object.freeze({ range: 'exit', until: 0.6 });
|
|
48
|
+
|
|
49
|
+
/** A stamped interaction, in the shape both interaction runtimes read. */
|
|
50
|
+
export interface StampedAction {
|
|
51
|
+
type: string;
|
|
52
|
+
target: string;
|
|
53
|
+
duration?: number;
|
|
54
|
+
delay?: number;
|
|
55
|
+
easing?: string;
|
|
56
|
+
once?: boolean;
|
|
57
|
+
params?: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface StampedInteraction {
|
|
61
|
+
id: string;
|
|
62
|
+
trigger: string;
|
|
63
|
+
range?: string;
|
|
64
|
+
actions: StampedAction[];
|
|
65
|
+
origin?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ScrubContext {
|
|
69
|
+
/** The node stands in the page's opening (its first screen): it plays on time whatever the scrub. */
|
|
70
|
+
opening?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Whether the look's `scrub` makes an entrance of `type` follow the scroll. */
|
|
74
|
+
export function scrubsEntrance(scrub: ScrubId | string | null | undefined, type: string, context: ScrubContext = {}): boolean {
|
|
75
|
+
if (context.opening) return false;
|
|
76
|
+
if (scrub === ScrubId.Entrances) return true;
|
|
77
|
+
return scrub === ScrubId.Words && type === TEXT_REVEAL;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* An entrance stamp under the look's `scrub` (AW10): the same action played by the scroll when the scrub takes it, else
|
|
82
|
+
* the stamp unchanged. A scroll-played action keeps its own params (distance, side, pieces) and its curve (the look's
|
|
83
|
+
* `ease-enter` — H7) and drops its clock (no duration, delay or row stagger: the scroll is the clock); under `words` a
|
|
84
|
+
* text lights rather than rises. Pure.
|
|
85
|
+
*/
|
|
86
|
+
export function scrubbedEntrance(ix: StampedInteraction, scrub: ScrubId | string | null | undefined, context: ScrubContext = {}): StampedInteraction {
|
|
87
|
+
const action = ix.actions[0];
|
|
88
|
+
if (ix.trigger !== ENTRANCE_TRIGGER || ix.actions.length !== 1 || !action || !scrubsEntrance(scrub, action.type, context)) return ix;
|
|
89
|
+
const params: Record<string, unknown> = { ...(action.params ?? {}), until: SCRUBBED_ENTRANCE.until };
|
|
90
|
+
delete params['stagger'];
|
|
91
|
+
delete params['cap'];
|
|
92
|
+
if (scrub === ScrubId.Words) params['look'] = 'light';
|
|
93
|
+
return {
|
|
94
|
+
id: ix.id,
|
|
95
|
+
trigger: SCROLL_PROGRESS_TRIGGER,
|
|
96
|
+
range: SCRUBBED_ENTRANCE.range,
|
|
97
|
+
actions: [{ type: action.type, target: action.target, ...(action.easing ? { easing: action.easing } : {}), params }],
|
|
98
|
+
...(ix.origin ? { origin: ix.origin } : {}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** How long an entrance plays once when Follow the scroll is turned off (AW10-D11): the Standard level's heading. */
|
|
103
|
+
export const ONCE_ENTRANCE_MS = 700;
|
|
104
|
+
|
|
105
|
+
/** Is `ix` a scrubbed entrance — one this module made, or an author's Follow the scroll: passing through the screen, one
|
|
106
|
+
* action the time trigger could play too (never a depth or a reading bar, which only the scroll plays)? */
|
|
107
|
+
export function isScrubbedEntrance(ix: StampedInteraction): boolean {
|
|
108
|
+
if (ix.trigger !== SCROLL_PROGRESS_TRIGGER || ix.range !== SCRUBBED_ENTRANCE.range || ix.actions.length !== 1) return false;
|
|
109
|
+
const d = ELEMENT_ACTION_DESCRIPTORS.find(x => x.type === ix.actions[0].type);
|
|
110
|
+
return !!d && actionOfferedUnder(d, ENTRANCE_TRIGGER);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Follow the scroll turned OFF (AW10-D11, "off, back to once"): a scrubbed entrance becomes the same action played once
|
|
115
|
+
* as it arrives (`viewportEnter`), `timing` its clock (its own curve, else the look's, and a Standard length when not
|
|
116
|
+
* given); its `until` goes, every other param (pieces, look, distance) stays. Anything else comes back as it was. Pure —
|
|
117
|
+
* the panel's one undo step, and the inverse of `scrubbedEntrance` but for the clock it dropped.
|
|
118
|
+
*/
|
|
119
|
+
export function onceEntrance(ix: StampedInteraction, timing: { duration?: number; delay?: number; easing?: string } = {}): StampedInteraction {
|
|
120
|
+
if (!isScrubbedEntrance(ix)) return ix;
|
|
121
|
+
const action = ix.actions[0];
|
|
122
|
+
const params: Record<string, unknown> = { ...(action.params ?? {}) };
|
|
123
|
+
delete params['until'];
|
|
124
|
+
const out: StampedAction = {
|
|
125
|
+
type: action.type, target: action.target,
|
|
126
|
+
duration: timing.duration ?? ONCE_ENTRANCE_MS, delay: timing.delay ?? 0, easing: timing.easing ?? action.easing ?? ENTRANCE_EASING, once: true,
|
|
127
|
+
...(Object.keys(params).length ? { params } : {}),
|
|
128
|
+
};
|
|
129
|
+
return { id: ix.id, trigger: ENTRANCE_TRIGGER, actions: [out], ...(ix.origin ? { origin: ix.origin } : {}) };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Copy-out (AW10, OPENING `motion.copy-out`, AW10-D9): stamped on the opening SECTION (its exit is what is measured),
|
|
134
|
+
* fading each node that holds the opening's words — opacity only, so reduced motion keeps it (AW10-D10). Pure.
|
|
135
|
+
*/
|
|
136
|
+
export function copyOutInteraction(sectionId: string, wordsIds: string | ReadonlyArray<string>): StampedInteraction {
|
|
137
|
+
const targets = typeof wordsIds === 'string' ? [wordsIds] : [...wordsIds];
|
|
138
|
+
return {
|
|
139
|
+
id: `${sectionId}-copy-out`,
|
|
140
|
+
trigger: SCROLL_PROGRESS_TRIGGER,
|
|
141
|
+
range: COPY_OUT.range,
|
|
142
|
+
actions: targets.map(target => ({ type: 'fadeOut', target, params: { until: COPY_OUT.until } })),
|
|
143
|
+
origin: ENTRANCE_ORIGIN_LOOK,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A look stamp on a node, as `planEntrances` gives it. */
|
|
148
|
+
export interface ScrubbableStamp {
|
|
149
|
+
nodeId: string;
|
|
150
|
+
interaction: StampedInteraction;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The look's entrance stamps of one composed section under the look's `scrub` (AW10-D5, D7, D8): each one the scrub
|
|
155
|
+
* takes becomes the same action played by the scroll (`scrubbedEntrance`); the opening keeps every stamp on time. The
|
|
156
|
+
* ONE rule the composer applies to `planEntrances`' stamps. Pure.
|
|
157
|
+
*/
|
|
158
|
+
export function scrubEntranceStamps(stamps: ReadonlyArray<ScrubbableStamp>, scrub: ScrubId | string | null | undefined, context: ScrubContext = {}): ScrubbableStamp[] {
|
|
159
|
+
if (!scrub || scrub === ScrubId.Never || context.opening) return [...stamps];
|
|
160
|
+
return stamps.map(s => {
|
|
161
|
+
const interaction = scrubbedEntrance(s.interaction, scrub, context);
|
|
162
|
+
return interaction === s.interaction ? s : { ...s, interaction };
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The layout language's entrances a line of words plays as a text reveal (word by word, letter by letter). */
|
|
167
|
+
const TEXT_REVEAL_ENTERS: ReadonlySet<string> = new Set([LayoutEnter.MaskRise, LayoutEnter.Letters]);
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether the look's `scrub` takes a layout layer's entrance (AW10-D12): `entrances` takes every entrance, `words` a
|
|
171
|
+
* line of words that reveals (mask rise, letters — never a decoration, which only fades), the opening none. The layout
|
|
172
|
+
* composer plays a layer that says `scrub` by the scroll only when this holds; `checkLayout` mends a `scrub` it does not
|
|
173
|
+
* (`scrub-look`). `textual`: the layer is a line of words (word, heading, text, label, number). Pure.
|
|
174
|
+
*/
|
|
175
|
+
export function layoutScrubTakes(layer: { enter?: string; role?: string }, textual: boolean, scrub: ScrubId | string | null | undefined, context: ScrubContext = {}): boolean {
|
|
176
|
+
if (!layer.enter || layer.enter === LayoutEnter.None) return false;
|
|
177
|
+
const reveals = textual && layer.role !== LayoutRole.Decoration && TEXT_REVEAL_ENTERS.has(layer.enter);
|
|
178
|
+
return scrubsEntrance(scrub, reveals ? TEXT_REVEAL : layer.enter, context);
|
|
179
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ARRIVE_IDS, flavorPackById, MOVE_IDS, parseHexColor, PRELOADER_IDS, SPEC_AXES } from '@vectoriox/iox-ui/design-core';
|
|
1
|
+
import { ARRIVE_IDS, flavorPackById, MOVE_IDS, parseHexColor, PRELOADER_IDS, SCRUB_IDS, SPEC_AXES } from '@vectoriox/iox-ui/design-core';
|
|
2
2
|
import { formPresetById } from '@vectoriox/iox-ui/forms-core';
|
|
3
3
|
import { filmScreensFor, normalizeFrameSequence } from '@vectoriox/iox-ui/media-core';
|
|
4
4
|
import { SEO_DESCRIPTION_MAX, SEO_TITLE_MAX } from '@vectoriox/iox-ui/seo-core';
|
|
@@ -18,6 +18,7 @@ import { artDirectionIssues } from './art-direction';
|
|
|
18
18
|
import { footerMixFromWords } from './footer-mix';
|
|
19
19
|
import { headerMixFromWords } from './header-mix';
|
|
20
20
|
import { openingMixFromWords } from './opening-mix';
|
|
21
|
+
import { bodyMixFromWords } from './body-mix';
|
|
21
22
|
import { patternListGap } from './recipe-fields';
|
|
22
23
|
import { SPEC_SITE_LAYOUT, SPEC_SITE_PLAN_SHAPE } from './site-spec.generated';
|
|
23
24
|
import {
|
|
@@ -256,6 +257,7 @@ function validateDesign(c: Collector, design: unknown): void {
|
|
|
256
257
|
word('feel', ARRIVE_IDS);
|
|
257
258
|
word('headings', MOVE_IDS);
|
|
258
259
|
word('preloader', PRELOADER_IDS);
|
|
260
|
+
word('scrub', SCRUB_IDS);
|
|
259
261
|
if (design['mode'] !== undefined && !(SPEC_AXES.modes as ReadonlyArray<unknown>).includes(design['mode'])) bad('mode', `must be one of ${SPEC_AXES.modes.join(', ')}`);
|
|
260
262
|
if (design['pillButtons'] !== undefined && typeof design['pillButtons'] !== 'boolean') bad('pillButtons', 'must be a boolean');
|
|
261
263
|
if (design['fonts'] !== undefined && !isObject(design['fonts'])) bad('fonts', 'must be an object');
|
|
@@ -739,7 +741,7 @@ function validateGlobals(c: Collector, globals: unknown): void {
|
|
|
739
741
|
}
|
|
740
742
|
|
|
741
743
|
/** The parts a plan may carry as a mix, and how each reads its words (only the footer until header ingredients HI1). */
|
|
742
|
-
const MIX_READERS: Readonly<Record<string, (words: ReadonlyArray<string>) => unknown>> = { header: headerMixFromWords, footer: footerMixFromWords, opening: openingMixFromWords };
|
|
744
|
+
const MIX_READERS: Readonly<Record<string, (words: ReadonlyArray<string>) => unknown>> = { header: headerMixFromWords, footer: footerMixFromWords, opening: openingMixFromWords, body: bodyMixFromWords };
|
|
743
745
|
|
|
744
746
|
/** `mixes`: each part's words parse in its table (list ingredients LI5); absent is fine. */
|
|
745
747
|
function validateMixes(c: Collector, mixes: unknown): void {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DesignChoices, presetChoices, PRELOADER_LEVELS } from '@vectoriox/iox-ui/design-core';
|
|
1
|
+
import { DesignChoices, presetChoices, PRELOADER_LEVELS, SCRUB_LEVELS } from '@vectoriox/iox-ui/design-core';
|
|
2
2
|
|
|
3
3
|
import { motionFor, MotionInput } from './motion';
|
|
4
4
|
import { RankInput, rankWithReferences, StyleRead } from './rank';
|
|
@@ -17,12 +17,12 @@ import { referenceSeed } from './reference-colour';
|
|
|
17
17
|
* when that colour passes AA in every mode the preset offers (`referenceSeed` — judged as used), and what the owner
|
|
18
18
|
* already set kept. The ONE rule for a Look pick and for Build with these. The style's first-visit preloader (AW5) is kept
|
|
19
19
|
* only while the start is Lively or Expressive (PL-D6) — a calm business (its ceiling below Standard) or "little
|
|
20
|
-
* movement" never opens with one.
|
|
20
|
+
* movement" never opens with one. Its By the scroll (AW10) likewise, only on a Lively or Expressive start (AW10-D7).
|
|
21
21
|
*/
|
|
22
22
|
export function presetDesign(
|
|
23
23
|
presetId: string,
|
|
24
24
|
input: MotionInput | string | null,
|
|
25
|
-
kept: Partial<Pick<DesignChoices, 'scroll' | 'animate' | 'between' | 'motion' | 'feel' | 'headings' | 'preloader'>> = {},
|
|
25
|
+
kept: Partial<Pick<DesignChoices, 'scroll' | 'animate' | 'between' | 'motion' | 'feel' | 'headings' | 'preloader' | 'scrub'>> = {},
|
|
26
26
|
read: StyleRead | null = null,
|
|
27
27
|
): DesignChoices | null {
|
|
28
28
|
const base = presetChoices(presetId);
|
|
@@ -30,9 +30,10 @@ export function presetDesign(
|
|
|
30
30
|
const motionInput: MotionInput = typeof input === 'object' && input !== null ? input : { businessType: input as string | null };
|
|
31
31
|
const start = motionFor(motionInput, presetId, read);
|
|
32
32
|
const seed = referenceSeed(read, presetId);
|
|
33
|
-
const { preloader, ...rest } = base;
|
|
33
|
+
const { preloader, scrub, ...rest } = base;
|
|
34
34
|
const opens = preloader && PRELOADER_LEVELS.includes(start.animate) ? { preloader } : {};
|
|
35
|
-
|
|
35
|
+
const scrubs = scrub && SCRUB_LEVELS.includes(start.animate) ? { scrub } : {};
|
|
36
|
+
return { ...rest, ...opens, ...scrubs, ...(seed?.used ? { seed: seed.seed } : {}), scroll: start.scroll, animate: start.animate, between: start.between, ...kept };
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export interface StartingDesign {
|
|
@@ -168,6 +168,8 @@ export enum ScrollActionKind {
|
|
|
168
168
|
Progress = 'progress',
|
|
169
169
|
/** Any entrance or exit, played by the scroll instead of the clock. */
|
|
170
170
|
Scrub = 'scrub',
|
|
171
|
+
/** AW10: a text whose pieces (lines, words, letters) the scroll plays. */
|
|
172
|
+
Text = 'text',
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
/** What a visitor gets of one scroll-driven action. */
|
|
@@ -193,6 +195,8 @@ const PLAY: Readonly<Record<ScrollActionKind, { reduced: ScrollPlay; light: Scro
|
|
|
193
195
|
[ScrollActionKind.Progress]: { reduced: ScrollPlay.Full, light: ScrollPlay.Full },
|
|
194
196
|
// A scrubbed fade keeps its fade under reduced motion; a light device sees the element as it rests.
|
|
195
197
|
[ScrollActionKind.Scrub]: { reduced: ScrollPlay.Gentle, light: ScrollPlay.Rest },
|
|
198
|
+
// AW10 (MOTION.reduced `scrubbedText: 'whole'`, `splitLetters: false`): a text the scroll would play stands whole.
|
|
199
|
+
[ScrollActionKind.Text]: { reduced: ScrollPlay.Rest, light: ScrollPlay.Rest },
|
|
196
200
|
};
|
|
197
201
|
|
|
198
202
|
/** THE degrade (motion-v2 §3d/§3e): one table, read by the canvas and both engine paths. */
|
|
@@ -5,14 +5,51 @@
|
|
|
5
5
|
* framework may hold that node, and a layer may hold live components.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { graphemes } from '@vectoriox/iox-ui/design-core';
|
|
9
|
+
|
|
10
|
+
import { SCENE_WORD_DIM } from './scene';
|
|
11
|
+
|
|
8
12
|
export enum TextRevealBy {
|
|
9
13
|
Line = 'line',
|
|
10
14
|
Word = 'word',
|
|
15
|
+
/** AW10: letter by letter. Display words only (`LETTER_PIECE_CAP`), never a script whose letters join. */
|
|
16
|
+
Letter = 'letter',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** How a reveal's pieces arrive (AW10): rising out of their masks, or lighting from dim (a Scene's words track's look). */
|
|
20
|
+
export enum TextRevealLook {
|
|
21
|
+
Rise = 'rise',
|
|
22
|
+
Light = 'light',
|
|
11
23
|
}
|
|
12
24
|
|
|
13
25
|
/** Past these a text is plainly no heading: it fades whole, and lights up whole. */
|
|
14
26
|
export const REVEAL_PIECE_CAP = 120;
|
|
15
27
|
export const LIGHT_UP_PIECE_CAP = 300;
|
|
28
|
+
/** AW10: past this many letters a text is no display line — it splits by word instead (the waiting word's stand-in). */
|
|
29
|
+
export const LETTER_PIECE_CAP = 80;
|
|
30
|
+
|
|
31
|
+
const REVEAL_BYS: ReadonlySet<string> = new Set(Object.values(TextRevealBy));
|
|
32
|
+
|
|
33
|
+
/** A saved `params.by`: a reveal's pieces, line by default (what `mask-rise` has always been). */
|
|
34
|
+
export function textRevealByOf(value: unknown): TextRevealBy {
|
|
35
|
+
return typeof value === 'string' && REVEAL_BYS.has(value) ? (value as TextRevealBy) : TextRevealBy.Line;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A saved `params.look`: rising by default. */
|
|
39
|
+
export function textRevealLookOf(value: unknown): TextRevealLook {
|
|
40
|
+
return value === TextRevealLook.Light ? TextRevealLook.Light : TextRevealLook.Rise;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Scripts whose letters change shape with their neighbours (Arabic joins, an Indic consonant takes its vowel): pulled
|
|
45
|
+
* apart, every letter would show its isolated form, so they never split by letter — they split by word.
|
|
46
|
+
*/
|
|
47
|
+
const JOINED_SCRIPTS = /[\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\p{Script=Mongolian}\p{Script=Devanagari}\p{Script=Bengali}\p{Script=Gurmukhi}\p{Script=Gujarati}\p{Script=Oriya}\p{Script=Tamil}\p{Script=Telugu}\p{Script=Kannada}\p{Script=Malayalam}\p{Script=Sinhala}\p{Script=Thai}\p{Script=Lao}\p{Script=Tibetan}\p{Script=Myanmar}\p{Script=Khmer}]/u;
|
|
48
|
+
|
|
49
|
+
/** True when `text` may come apart letter by letter without a letter changing its shape (Hebrew, Latin, Cyrillic…). */
|
|
50
|
+
export function lettersSplittable(text: string): boolean {
|
|
51
|
+
return !JOINED_SCRIPTS.test(text);
|
|
52
|
+
}
|
|
16
53
|
|
|
17
54
|
const SKIPPED_TAGS: ReadonlySet<string> = new Set(['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'SELECT', 'OPTION']);
|
|
18
55
|
const SHOW_TEXT = 4;
|
|
@@ -26,17 +63,21 @@ export interface TextPiece {
|
|
|
26
63
|
}
|
|
27
64
|
|
|
28
65
|
/**
|
|
29
|
-
* A string as words and the space between them. With `keepLtrRuns` a run of words holding no
|
|
30
|
-
*
|
|
66
|
+
* A string as words and the space between them. With `keepLtrRuns` (a right-to-left element) a run of words holding no
|
|
67
|
+
* RTL letter stays ONE word; with `keepRtlRuns` (a left-to-right element) a run of words holding an RTL letter does: an
|
|
68
|
+
* inline-block is neutral to the bidi algorithm, so "Studio Alma" inside a Hebrew heading, split, would read reversed —
|
|
69
|
+
* and so would a Hebrew name inside an English one.
|
|
31
70
|
*/
|
|
32
|
-
export function textPieces(text: string, keepLtrRuns = false): TextPiece[] {
|
|
71
|
+
export function textPieces(text: string, keepLtrRuns = false, keepRtlRuns = false): TextPiece[] {
|
|
33
72
|
const pieces: TextPiece[] = (text.match(/\s+|\S+/g) ?? []).map(part => ({ text: part, word: /\S/.test(part) }));
|
|
34
|
-
if (!keepLtrRuns) return pieces;
|
|
73
|
+
if (!keepLtrRuns && !keepRtlRuns) return pieces;
|
|
74
|
+
const against = (word: string): boolean => (RTL_LETTER.test(word) ? keepRtlRuns : keepLtrRuns);
|
|
35
75
|
const merged: TextPiece[] = [];
|
|
36
76
|
for (const piece of pieces) {
|
|
37
77
|
const space = merged[merged.length - 1];
|
|
38
78
|
const word = merged[merged.length - 2];
|
|
39
|
-
if (piece.word &&
|
|
79
|
+
if (piece.word && against(piece.text) && space && !space.word && word?.word && against(word.text)
|
|
80
|
+
&& RTL_LETTER.test(word.text) === RTL_LETTER.test(piece.text)) {
|
|
40
81
|
word.text += space.text + piece.text;
|
|
41
82
|
merged.pop();
|
|
42
83
|
} else {
|
|
@@ -46,12 +87,20 @@ export function textPieces(text: string, keepLtrRuns = false): TextPiece[] {
|
|
|
46
87
|
return merged;
|
|
47
88
|
}
|
|
48
89
|
|
|
90
|
+
/** The direction a word reads in: its first letter's. */
|
|
91
|
+
function wordDirection(text: string): 'rtl' | 'ltr' {
|
|
92
|
+
const first = text.match(/\p{L}/u)?.[0] ?? '';
|
|
93
|
+
return RTL_LETTER.test(first) ? 'rtl' : 'ltr';
|
|
94
|
+
}
|
|
95
|
+
|
|
49
96
|
export interface SplitTextOptions {
|
|
50
97
|
cap: number;
|
|
51
98
|
/** Each piece in a clipping mask, to rise out of (and so an inline-block). Without it a piece is a plain inline span. */
|
|
52
99
|
mask?: boolean;
|
|
53
|
-
/** The element reads right-to-left. Only a mask needs to know. */
|
|
100
|
+
/** The element reads right-to-left. Only an inline-block (a mask, a word of letters) needs to know. */
|
|
54
101
|
rtl?: boolean;
|
|
102
|
+
/** AW10: letters, not words. Null is returned for a script whose letters join (`lettersSplittable`). */
|
|
103
|
+
letters?: boolean;
|
|
55
104
|
}
|
|
56
105
|
|
|
57
106
|
export interface SplitText {
|
|
@@ -76,6 +125,9 @@ function textNodesOf(root: HTMLElement): Text[] {
|
|
|
76
125
|
return found;
|
|
77
126
|
}
|
|
78
127
|
|
|
128
|
+
/** A clip-path and not overflow, which would move the box's baseline. The negative sides leave descenders and italics. */
|
|
129
|
+
const MASK_CLIP = 'inset(-0.1em -0.1em -0.18em -0.1em)';
|
|
130
|
+
|
|
79
131
|
function pieceOf(doc: Document, text: string, mask: boolean): { outer: HTMLElement; moving: HTMLElement } {
|
|
80
132
|
const moving = doc.createElement('span');
|
|
81
133
|
moving.textContent = text;
|
|
@@ -83,8 +135,7 @@ function pieceOf(doc: Document, text: string, mask: boolean): { outer: HTMLEleme
|
|
|
83
135
|
moving.style.display = 'inline-block';
|
|
84
136
|
const outer = doc.createElement('span');
|
|
85
137
|
outer.style.display = 'inline-block';
|
|
86
|
-
|
|
87
|
-
outer.style.clipPath = 'inset(-0.1em -0.1em -0.18em -0.1em)';
|
|
138
|
+
outer.style.clipPath = MASK_CLIP;
|
|
88
139
|
outer.appendChild(moving);
|
|
89
140
|
return { outer, moving };
|
|
90
141
|
}
|
|
@@ -93,17 +144,26 @@ function pieceOf(doc: Document, text: string, mask: boolean): { outer: HTMLEleme
|
|
|
93
144
|
export function splitText(root: HTMLElement, options: SplitTextOptions): SplitText | null {
|
|
94
145
|
const doc = root.ownerDocument;
|
|
95
146
|
const mask = !!options.mask;
|
|
96
|
-
const
|
|
97
|
-
const
|
|
147
|
+
const letters = !!options.letters;
|
|
148
|
+
const texts = textNodesOf(root);
|
|
149
|
+
if (letters && texts.some(text => !lettersSplittable(text.nodeValue ?? ''))) return null;
|
|
150
|
+
// Words of letters in a mask are inline-blocks too: a run against the element's direction stays one.
|
|
151
|
+
const keepRuns = mask;
|
|
152
|
+
const planned = texts.map(original => ({
|
|
153
|
+
original, parts: textPieces(original.nodeValue ?? '', keepRuns && !!options.rtl, keepRuns && !options.rtl),
|
|
154
|
+
}));
|
|
155
|
+
const pieceCount = (part: TextPiece): number => (!part.word ? 0 : letters ? graphemes(part.text.replace(/\s+/g, '')).length : 1);
|
|
156
|
+
const count = planned.reduce((sum, { parts }) => sum + parts.reduce((n, part) => n + pieceCount(part), 0), 0);
|
|
98
157
|
if (!count || count > options.cap) return null;
|
|
99
158
|
|
|
100
159
|
const pieces: HTMLElement[] = [];
|
|
101
160
|
const replacements: Replacement[] = planned.map(({ original, parts }) => {
|
|
102
|
-
const nodes = parts.
|
|
103
|
-
if (!part.word) return doc.createTextNode(part.text);
|
|
161
|
+
const nodes = parts.flatMap((part): Node[] => {
|
|
162
|
+
if (!part.word) return [doc.createTextNode(part.text)];
|
|
163
|
+
if (letters) return lettersOf(doc, part.text, mask, pieces);
|
|
104
164
|
const { outer, moving } = pieceOf(doc, part.text, mask);
|
|
105
165
|
pieces.push(moving);
|
|
106
|
-
return outer;
|
|
166
|
+
return [outer];
|
|
107
167
|
});
|
|
108
168
|
const parent = original.parentNode as ParentNode & Node;
|
|
109
169
|
for (const node of nodes) parent.insertBefore(node, original);
|
|
@@ -124,6 +184,32 @@ export function splitText(root: HTMLElement, options: SplitTextOptions): SplitTe
|
|
|
124
184
|
};
|
|
125
185
|
}
|
|
126
186
|
|
|
187
|
+
/**
|
|
188
|
+
* A word as letters (AW10). Unmasked, each letter is a plain inline span: the line breaks, the bidi order and the
|
|
189
|
+
* shaping are the text's own. Masked, the WORD is the mask — an inline-block that never breaks inside, reading in its
|
|
190
|
+
* own direction (an inline-block's letters would otherwise take the element's) — and each letter an inline-block that
|
|
191
|
+
* rises inside it.
|
|
192
|
+
*/
|
|
193
|
+
function lettersOf(doc: Document, word: string, mask: boolean, pieces: HTMLElement[]): Node[] {
|
|
194
|
+
const letterOf = (letter: string): HTMLElement => {
|
|
195
|
+
const span = doc.createElement('span');
|
|
196
|
+
span.textContent = letter;
|
|
197
|
+
if (mask) span.style.display = 'inline-block';
|
|
198
|
+
pieces.push(span);
|
|
199
|
+
return span;
|
|
200
|
+
};
|
|
201
|
+
// A run of words held together (`textPieces`) keeps its spaces as bare text.
|
|
202
|
+
const parts: Node[] = (word.match(/\s+|\S+/g) ?? []).flatMap((part): Node[] => (/\S/.test(part) ? graphemes(part).map(letterOf) : [doc.createTextNode(part)]));
|
|
203
|
+
if (!mask) return parts;
|
|
204
|
+
const outer = doc.createElement('span');
|
|
205
|
+
outer.style.display = 'inline-block';
|
|
206
|
+
outer.style.whiteSpace = 'nowrap';
|
|
207
|
+
outer.style.clipPath = MASK_CLIP;
|
|
208
|
+
outer.dir = wordDirection(word);
|
|
209
|
+
for (const part of parts) outer.appendChild(part);
|
|
210
|
+
return [outer];
|
|
211
|
+
}
|
|
212
|
+
|
|
127
213
|
/** The line each piece stands on: 0, 0, 1, 1, 1, 2… Read once, as a reveal starts. */
|
|
128
214
|
export function lineIndexes(tops: ReadonlyArray<number>, heights: ReadonlyArray<number>): number[] {
|
|
129
215
|
let line = 0;
|
|
@@ -139,40 +225,75 @@ export function lineIndexes(tops: ReadonlyArray<number>, heights: ReadonlyArray<
|
|
|
139
225
|
|
|
140
226
|
const LINE_STAGGER_MS = 90;
|
|
141
227
|
const WORD_STAGGER_MS = 40;
|
|
228
|
+
/** AW10: letters follow one another closely — a word assembles, it is not spelled out. */
|
|
229
|
+
const LETTER_STAGGER_MS = 24;
|
|
142
230
|
/** However long the heading, the last piece starts within this. */
|
|
143
231
|
const STAGGER_BUDGET_MS = 1000;
|
|
144
232
|
|
|
233
|
+
const STAGGER_MS: Readonly<Record<TextRevealBy, number>> = {
|
|
234
|
+
[TextRevealBy.Line]: LINE_STAGGER_MS,
|
|
235
|
+
[TextRevealBy.Word]: WORD_STAGGER_MS,
|
|
236
|
+
[TextRevealBy.Letter]: LETTER_STAGGER_MS,
|
|
237
|
+
};
|
|
238
|
+
|
|
145
239
|
export function revealStagger(groups: number, by: TextRevealBy): number {
|
|
146
|
-
|
|
147
|
-
return groups > 1 ? Math.min(step, STAGGER_BUDGET_MS / (groups - 1)) : 0;
|
|
240
|
+
return groups > 1 ? Math.min(STAGGER_MS[by], STAGGER_BUDGET_MS / (groups - 1)) : 0;
|
|
148
241
|
}
|
|
149
242
|
|
|
150
243
|
/** Past the mask's negative inset, so nothing shows before a piece's turn. */
|
|
151
244
|
const PIECE_FRAMES: Keyframe[] = [{ transform: 'translateY(120%)' }, { transform: 'translateY(0)' }];
|
|
245
|
+
/** A lit piece goes from the Scene words track's dim to whole: it never moves. */
|
|
246
|
+
const LIGHT_FRAMES: Keyframe[] = [{ opacity: SCENE_WORD_DIM }, { opacity: 1 }];
|
|
152
247
|
const DEFAULT_PIECE_MS = 700;
|
|
153
248
|
|
|
154
|
-
|
|
249
|
+
/** A text split for a reveal: its pieces in reading order and the group (line, word, letter) each plays with. */
|
|
250
|
+
export interface RevealSplit {
|
|
251
|
+
split: SplitText;
|
|
252
|
+
/** What it really split by: a letter split a text refuses falls to words (`LETTER_PIECE_CAP`, a joined script). */
|
|
253
|
+
by: TextRevealBy;
|
|
254
|
+
order: number[];
|
|
255
|
+
groups: number;
|
|
256
|
+
}
|
|
155
257
|
|
|
156
258
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* is put back whole, which leaves nothing for a screen reader to stumble on and nothing to re-split on a resize. Null
|
|
160
|
-
* when there is nothing to split or it is being edited: the caller plays its plain fade.
|
|
259
|
+
* Split `el` for a reveal by `by` in `look`, or null when there is nothing to split or it is being edited (the caller
|
|
260
|
+
* plays its plain fade). Letters a text cannot give (too many, a joined script) are words instead.
|
|
161
261
|
*/
|
|
162
|
-
export function
|
|
163
|
-
playing.get(el)?.cancel();
|
|
262
|
+
export function splitForReveal(el: HTMLElement, by: TextRevealBy, look: TextRevealLook = TextRevealLook.Rise): RevealSplit | null {
|
|
164
263
|
if (el.isContentEditable) return null;
|
|
165
264
|
const rtl = el.ownerDocument.defaultView?.getComputedStyle(el).direction === 'rtl';
|
|
166
|
-
const
|
|
265
|
+
const mask = look === TextRevealLook.Rise;
|
|
266
|
+
let used = by;
|
|
267
|
+
let split = by === TextRevealBy.Letter ? splitText(el, { cap: LETTER_PIECE_CAP, mask, rtl, letters: true }) : null;
|
|
268
|
+
if (!split) {
|
|
269
|
+
if (used === TextRevealBy.Letter) used = TextRevealBy.Word;
|
|
270
|
+
split = splitText(el, { cap: REVEAL_PIECE_CAP, mask, rtl });
|
|
271
|
+
}
|
|
167
272
|
if (!split) return null;
|
|
273
|
+
const boxes = used === TextRevealBy.Line ? split.pieces.map(piece => ((mask ? piece.parentElement : piece) as HTMLElement).getBoundingClientRect()) : [];
|
|
274
|
+
const order = used === TextRevealBy.Line ? lineIndexes(boxes.map(box => box.top), boxes.map(box => box.height)) : split.pieces.map((_, i) => i);
|
|
275
|
+
return { split, by: used, order, groups: Math.max(...order) + 1 };
|
|
276
|
+
}
|
|
168
277
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
278
|
+
const playing = new WeakMap<HTMLElement, Animation>();
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Play a text reveal: each piece rises out of its mask (or lights from dim), line by line, word by word or letter by
|
|
282
|
+
* letter. Returns ONE animation for the whole, so a runtime treats it as any other: it finishes when the last piece
|
|
283
|
+
* lands, and on finish or cancel the text is put back whole, which leaves nothing for a screen reader to stumble on and
|
|
284
|
+
* nothing to re-split on a resize. Null when there is nothing to split or it is being edited: the caller plays its plain
|
|
285
|
+
* fade.
|
|
286
|
+
*/
|
|
287
|
+
export function playTextReveal(el: HTMLElement, by: TextRevealBy, timing: KeyframeAnimationOptions, look: TextRevealLook = TextRevealLook.Rise): Animation | null {
|
|
288
|
+
playing.get(el)?.cancel();
|
|
289
|
+
const planned = splitForReveal(el, by, look);
|
|
290
|
+
if (!planned) return null;
|
|
291
|
+
const { split, order, groups } = planned;
|
|
292
|
+
const step = revealStagger(groups, planned.by);
|
|
173
293
|
const duration = Number(timing.duration) || DEFAULT_PIECE_MS;
|
|
174
294
|
const delay = timing.delay ?? 0;
|
|
175
|
-
const
|
|
295
|
+
const frames = look === TextRevealLook.Light ? LIGHT_FRAMES : PIECE_FRAMES;
|
|
296
|
+
const pieces = split.pieces.map((piece, i) => piece.animate(frames, { duration, delay: delay + order[i] * step, easing: timing.easing, fill: 'both' }));
|
|
176
297
|
// The element itself just stands visible: its entrance's first frame had hidden it whole.
|
|
177
298
|
const whole = el.animate([{ opacity: 1 }, { opacity: 1 }], { duration: delay + duration + step * (groups - 1), fill: timing.fill ?? 'both' });
|
|
178
299
|
playing.set(el, whole);
|
|
@@ -185,3 +306,70 @@ export function playTextReveal(el: HTMLElement, by: TextRevealBy, timing: Keyfra
|
|
|
185
306
|
whole.addEventListener('cancel', finished, { once: true });
|
|
186
307
|
return whole;
|
|
187
308
|
}
|
|
309
|
+
|
|
310
|
+
/** AW10: how many pieces are on their way at once while the scroll plays a text — a wave, not one piece at a time. */
|
|
311
|
+
export const SCRUB_PIECES_IN_FLIGHT = 3;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Where piece group `group` of `groups` stands when the scroll has played `progress` (0–1) of its text: each group plays
|
|
315
|
+
* over its own window, `inFlight` groups overlapping, the first starting at 0 and the last ending at 1. Pure.
|
|
316
|
+
*/
|
|
317
|
+
export function scrubPieceProgress(progress: number, group: number, groups: number, inFlight = SCRUB_PIECES_IN_FLIGHT): number {
|
|
318
|
+
const n = Math.max(1, groups);
|
|
319
|
+
const k = Math.max(1, Math.min(inFlight, n));
|
|
320
|
+
const slots = n + k - 1;
|
|
321
|
+
const start = group / slots;
|
|
322
|
+
const local = (progress - start) / (k / slots);
|
|
323
|
+
return Math.min(1, Math.max(0, local));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** A paused timeline this long is moved to the progress. */
|
|
327
|
+
const SCRUB_TIMELINE_MS = 1000;
|
|
328
|
+
|
|
329
|
+
/** A text the scroll plays (AW10 `scrub`): moved to a progress, then let go — put back whole. */
|
|
330
|
+
export interface TextScrub {
|
|
331
|
+
/** What it really split by. */
|
|
332
|
+
readonly by: TextRevealBy;
|
|
333
|
+
seek(progress: number): void;
|
|
334
|
+
release(): void;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Split `el` once and let the scroll play its pieces (AW10, mode `scrubbed`): `seek` moves every piece to where the
|
|
339
|
+
* progress puts it — rising out of its mask or lighting from dim, `SCRUB_PIECES_IN_FLIGHT` at a time — and `release`
|
|
340
|
+
* puts the text back whole. Null when there is nothing to split or it is being edited: the caller scrubs its plain fade.
|
|
341
|
+
* Transform and opacity only; nothing changes a box.
|
|
342
|
+
*/
|
|
343
|
+
export function scrubTextReveal(el: HTMLElement, by: TextRevealBy, look: TextRevealLook = TextRevealLook.Rise, easing = 'linear'): TextScrub | null {
|
|
344
|
+
playing.get(el)?.cancel();
|
|
345
|
+
const planned = splitForReveal(el, by, look);
|
|
346
|
+
if (!planned) return null;
|
|
347
|
+
const { split, order, groups } = planned;
|
|
348
|
+
const frames = look === TextRevealLook.Light ? LIGHT_FRAMES : PIECE_FRAMES;
|
|
349
|
+
const anims = split.pieces.map(piece => {
|
|
350
|
+
const anim = piece.animate(frames, { duration: SCRUB_TIMELINE_MS, fill: 'both', easing });
|
|
351
|
+
anim.pause();
|
|
352
|
+
anim.currentTime = 0;
|
|
353
|
+
return anim;
|
|
354
|
+
});
|
|
355
|
+
const at = anims.map(() => 0);
|
|
356
|
+
let released = false;
|
|
357
|
+
return {
|
|
358
|
+
by: planned.by,
|
|
359
|
+
seek: (progress: number) => {
|
|
360
|
+
if (released) return;
|
|
361
|
+
anims.forEach((anim, i) => {
|
|
362
|
+
const time = scrubPieceProgress(progress, order[i], groups) * SCRUB_TIMELINE_MS;
|
|
363
|
+
if (time === at[i]) return;
|
|
364
|
+
anim.currentTime = time;
|
|
365
|
+
at[i] = time;
|
|
366
|
+
});
|
|
367
|
+
},
|
|
368
|
+
release: () => {
|
|
369
|
+
if (released) return;
|
|
370
|
+
released = true;
|
|
371
|
+
for (const anim of anims) anim.cancel();
|
|
372
|
+
split.restore();
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
}
|