Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(ui): animate package (#3530)
Fake-Userf2af95e7c9f8
diff --git a/js/app/biome.jsonc b/js/app/biome.jsoncindex 55f0135e2b..9b59b15bec 100644--- a/js/app/biome.jsonc+++ b/js/app/biome.jsonc@@ -142,6 +142,7 @@{"includes": ["packages/app/component/settings/**",+ "packages/animate/**","packages/theme/**","packages/ui/**"],diff --git a/js/app/packages/animate/easings/back.ts b/js/app/packages/animate/easings/back.tsnew file mode 100644index 0000000000..1e3b17a5cc--- /dev/null+++ b/js/app/packages/animate/easings/back.ts@@ -0,0 +1,19 @@+import type { EasingFn, BackOptions } from '../types/types';++export function backIn(opts: BackOptions = {}): EasingFn {+ const { overshoot = 1.70158 } = opts;+ return (t) => (overshoot + 1) * t * t * t - overshoot * t * t;+}++export function backOut(opts: BackOptions = {}): EasingFn {+ const { overshoot = 1.70158 } = opts;+ return (t) => 1 + (overshoot + 1) * Math.pow(t - 1, 3) + overshoot * Math.pow(t - 1, 2);+}++export function backInOut(opts: BackOptions = {}): EasingFn {+ const { overshoot = 1.70158 } = opts;+ const c2 = overshoot * 1.525;+ return (t) => t < 0.5+ ? (Math.pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2+ : (Math.pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;+}diff --git a/js/app/packages/animate/easings/bounce.ts b/js/app/packages/animate/easings/bounce.tsnew file mode 100644index 0000000000..6e1cce0e97--- /dev/null+++ b/js/app/packages/animate/easings/bounce.ts@@ -0,0 +1,21 @@+import type { EasingFn } from '../types/types';++export const bounceIn: EasingFn = (t) => 1 - bounceOut(1 - t);++export const bounceOut: EasingFn = (t) => {+ if (t < 1 / 2.75) return 7.5625 * t * t;+ if (t < 2 / 2.75) {+ const t2 = t - 1.5 / 2.75;+ return 7.5625 * t2 * t2 + 0.75;+ }+ if (t < 2.5 / 2.75) {+ const t2 = t - 2.25 / 2.75;+ return 7.5625 * t2 * t2 + 0.9375;+ }+ const t2 = t - 2.625 / 2.75;+ return 7.5625 * t2 * t2 + 0.984375;+};++export const bounceInOut: EasingFn = (t) => t < 0.5+ ? (1 - bounceOut(1 - 2 * t)) / 2+ : (1 + bounceOut(2 * t - 1)) / 2;diff --git a/js/app/packages/animate/easings/cubic.ts b/js/app/packages/animate/easings/cubic.tsnew file mode 100644index 0000000000..06d403d8f7--- /dev/null+++ b/js/app/packages/animate/easings/cubic.ts@@ -0,0 +1,7 @@+import type { EasingFn } from '../types/types';++export const cubicIn: EasingFn = (t) => t * t * t;++export const cubicOut: EasingFn = (t) => 1 - Math.pow(1 - t, 3);++export const cubicInOut: EasingFn = (t) => t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;diff --git a/js/app/packages/animate/easings/elastic.ts b/js/app/packages/animate/easings/elastic.tsnew file mode 100644index 0000000000..ca97c21957--- /dev/null+++ b/js/app/packages/animate/easings/elastic.ts@@ -0,0 +1,29 @@+import type { EasingFn, ElasticOptions } from '../types/types';++export function elasticIn(opts: ElasticOptions = {}): EasingFn {+ const { amplitude: _amp = 1, period = 0.3 } = opts;+ const amplitude = Math.max(1, _amp);+ return (t) => {+ if (t === 0 || t === 1) return t;+ return -(amplitude * Math.pow(2, 10 * (t - 1)) * Math.sin(((t - 1 - (period / (2 * Math.PI)) * Math.asin(1 / amplitude)) * (2 * Math.PI)) / period));+ };+}++export function elasticOut(opts: ElasticOptions = {}): EasingFn {+ const { amplitude: _amp = 1, period = 0.3 } = opts;+ const amplitude = Math.max(1, _amp);+ return (t) => {+ if (t === 0 || t === 1) return t;+ return amplitude * Math.pow(2, -10 * t) * Math.sin(((t - (period / (2 * Math.PI)) * Math.asin(1 / amplitude)) * (2 * Math.PI)) / period) + 1;+ };+}++export function elasticInOut(opts: ElasticOptions = {}): EasingFn {+ const { amplitude: _amp = 1, period = 0.45 } = opts;+ const amplitude = Math.max(1, _amp);+ return (t) => {+ if (t === 0 || t === 1) return t;+ if (t < 0.5) return -(amplitude * Math.pow(2, 20 * t - 10) * Math.sin(((20 * t - 10 - (period / (2 * Math.PI)) * Math.asin(1 / amplitude)) * (2 * Math.PI)) / period)) / 2;+ return (amplitude * Math.pow(2, -20 * t + 10) * Math.sin(((20 * t - 10 - (period / (2 * Math.PI)) * Math.asin(1 / amplitude)) * (2 * Math.PI)) / period)) / 2 + 1;+ };+}diff --git a/js/app/packages/animate/easings/linear.ts b/js/app/packages/animate/easings/linear.tsnew file mode 100644index 0000000000..4e063b2954--- /dev/null+++ b/js/app/packages/animate/easings/linear.ts@@ -0,0 +1,3 @@+import type { EasingFn } from '../types/types';++export const linear: EasingFn = (t) => t;diff --git a/js/app/packages/animate/easings/quad.ts b/js/app/packages/animate/easings/quad.tsnew file mode 100644index 0000000000..f030f9005e--- /dev/null+++ b/js/app/packages/animate/easings/quad.ts@@ -0,0 +1,7 @@+import type { EasingFn } from '../types/types';++export const quadIn: EasingFn = (t) => t * t;++export const quadOut: EasingFn = (t) => 1 - (1 - t) * (1 - t);++export const quadInOut: EasingFn = (t) => t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;diff --git a/js/app/packages/animate/easings/sine.ts b/js/app/packages/animate/easings/sine.tsnew file mode 100644index 0000000000..b22f4d554c--- /dev/null+++ b/js/app/packages/animate/easings/sine.ts@@ -0,0 +1,7 @@+import type { EasingFn } from '../types/types';++export const sineIn: EasingFn = (t) => 1 - Math.cos((t * Math.PI) / 2);++export const sineOut: EasingFn = (t) => Math.sin((t * Math.PI) / 2);++export const sineInOut: EasingFn = (t) => -(Math.cos(Math.PI * t) - 1) / 2;diff --git a/js/app/packages/animate/index.ts b/js/app/packages/animate/index.tsnew file mode 100644index 0000000000..be022518cd--- /dev/null+++ b/js/app/packages/animate/index.ts@@ -0,0 +1,26 @@+export type {+ ProgressKeyframeProperty,+ PropertyKeyframeEntry,+ AnimationController,+ ProgressKeyframes,+ ProgressKeyframe,+ PropertySegment,+ ElasticOptions,+ PropertyTrack,+ BackOptions,+ PlayOptions,+ EasingFn,+ Timeline,+} from './types/types';++export { elasticIn, elasticOut, elasticInOut} from './easings/elastic';+export { bounceIn, bounceOut, bounceInOut } from './easings/bounce';+export { progressKeyframes } from './keyframes/progressKeyframes';+export { cubicIn, cubicOut, cubicInOut } from './easings/cubic';+export { targetKeyframes } from './keyframes/targetKeyframes';+export { backIn, backOut, backInOut } from './easings/back';+export { sineIn, sineOut, sineInOut } from './easings/sine';+export { quadIn, quadOut, quadInOut} from './easings/quad';+export { createTimeline } from './utils/timeline';+export { controller } from './utils/controller';+export { linear } from './easings/linear';diff --git a/js/app/packages/animate/keyframes/progressKeyframes.ts b/js/app/packages/animate/keyframes/progressKeyframes.tsnew file mode 100644index 0000000000..c48be56823--- /dev/null+++ b/js/app/packages/animate/keyframes/progressKeyframes.ts@@ -0,0 +1,86 @@+import type { PropertyTrack, PropertySegment, ProgressKeyframes, ProgressKeyframe, Timeline } from '../types/types';+import { createTimeline } from '../utils/timeline';+import { linear } from '../easings/linear';++/*+ Progress-first keyframe format.++ Example:++ progressKeyframes({+ 0: [{ target: setScale, value: 1.0, easing: backOut }, { target: setX, value: 0, easing: elasticOut }],+ 0.25: [{ target: setScale, value: 0.6, easing: cubicOut }],+ 0.5: [{ target: setScale, value: 0.6, easing: backOut }, { target: setX, value: 100, easing: bounceOut }],+ 0.75: [{ target: setScale, value: 1.2, easing: cubicInOut }],+ 1: [{ target: setScale, value: 1.0 }, { target: setX, value: 0 }],+ })++ Compiles to PropertyTrack[]:++ [+ {+ target: setScale,+ segments: [+ { fromProgress: 0, toProgress: 0.25, fromValue: 1.0, toValue: 0.6, easing: backOut },+ { fromProgress: 0.25, toProgress: 0.5, fromValue: 0.6, toValue: 0.6, easing: cubicOut },+ { fromProgress: 0.5, toProgress: 0.75, fromValue: 0.6, toValue: 1.2, easing: backOut },+ { fromProgress: 0.75, toProgress: 1.0, fromValue: 1.2, toValue: 1.0, easing: cubicInOut },+ ]+ },+ {+ target: setX,+ segments: [+ { fromProgress: 0, toProgress: 0.5, fromValue: 0, toValue: 100, easing: elasticOut },+ { fromProgress: 0.5, toProgress: 1.0, fromValue: 100, toValue: 0, easing: bounceOut },+ ]+ },+ ]+*/++export function progressKeyframes(timeline: ProgressKeyframes): Timeline {+ const keyframesByProperty = new Map<(value: number) => void, ProgressKeyframe[]>();++ for (const [progressStr, frame] of Object.entries(timeline)) {+ const progress = Number(progressStr);+ for (const { target, value, easing } of frame) {+ let list = keyframesByProperty.get(target);+ if (!list) {+ list = [];+ keyframesByProperty.set(target, list);+ }+ list.push({ progress, value, easing });+ }+ }++ const tracks: PropertyTrack[] = [];++ for (const [target, keyframes] of keyframesByProperty) {+ keyframes.sort((a, b) => a.progress - b.progress);++ const first = keyframes[0];+ const last = keyframes[keyframes.length - 1];+ if (first.progress > 0) { keyframes.unshift({ progress: 0, value: first.value, easing: first.easing }); }+ if (last.progress < 1) { keyframes.push({ progress: 1, value: last.value }); }++ const segments: PropertySegment[] = [];+ for (let i = 0; i < keyframes.length - 1; i++) {+ const from = keyframes[i];+ const to = keyframes[i + 1];+ const range = to.progress - from.progress;+ segments.push({+ rangeInverse: range > 0 ? 1 / range : 0,+ valueDelta: to.value - from.value,+ easing: from.easing ?? linear,+ fromProgress: from.progress,+ toProgress: to.progress,+ fromValue: from.value,+ toValue: to.value,+ });+ }++ if (segments.length > 0) { tracks.push({ target, segments }); }+ }++ if (tracks.length === 0) { throw new Error('progressKeyframes: no valid keyframes provided'); }+ return createTimeline(tracks);+}diff --git a/js/app/packages/animate/keyframes/targetKeyframes.ts b/js/app/packages/animate/keyframes/targetKeyframes.tsnew file mode 100644index 0000000000..fabccbee01--- /dev/null+++ b/js/app/packages/animate/keyframes/targetKeyframes.ts@@ -0,0 +1,90 @@+import type { PropertySegment, PropertyKeyframeEntry, Timeline } from '../types/types';+import { createTimeline } from '../utils/timeline';+import { linear } from '../easings/linear';++/*+ Property-first keyframe format.++ Example:++ propertyKeyframes([+ { target: setScale, offset: [0, 0.25, 0.5, 0.75, 1.0], value: [1.0, 0.6, 0.6, 1.2, 1.0], easing: [backOut, cubicOut, backOut, cubicInOut] },+ { target: setX, offset: [0, 0.5, 1.0], value: [0, 100, 0], easing: [elasticOut, bounceOut] },+ ])++ Compiles to PropertyTrack[]:++ [+ {+ target: setScale,+ segments: [+ { fromProgress: 0, toProgress: 0.25, fromValue: 1.0, toValue: 0.6, easing: backOut },+ { fromProgress: 0.25, toProgress: 0.5, fromValue: 0.6, toValue: 0.6, easing: cubicOut },+ { fromProgress: 0.5, toProgress: 0.75, fromValue: 0.6, toValue: 1.2, easing: backOut },+ { fromProgress: 0.75, toProgress: 1.0, fromValue: 1.2, toValue: 1.0, easing: cubicInOut },+ ]+ },+ {+ target: setX,+ segments: [+ { fromProgress: 0, toProgress: 0.5, fromValue: 0, toValue: 100, easing: elasticOut },+ { fromProgress: 0.5, toProgress: 1.0, fromValue: 100, toValue: 0, easing: bounceOut },+ ]+ },+ ]+*/++export function targetKeyframes(entries: PropertyKeyframeEntry[]): Timeline {+ if (entries.length === 0) { throw new Error('propertyKeyframes: entries array cannot be empty'); }++ const tracks = [];++ for (const entry of entries) {+ const { target, offset, value, easing } = entry;++ if (offset.length === 0) { continue; }++ const easings = easing ? easing.slice() : undefined;+ const times = offset.slice();+ const vals = value.slice();+++ const firstValue = vals[0];+ const lastValue = vals[vals.length - 1];+ const firstEasing = easings?.[0];+ const lastEasing = easings?.[easings.length - 1];++ if (times[0] > 0) {+ times.unshift(0);+ vals.unshift(firstValue);+ easings?.unshift(firstEasing);+ }+ if (times[times.length - 1] < 1) {+ times.push(1);+ vals.push(lastValue);+ easings?.push(lastEasing);+ }++ const segments: PropertySegment[] = [];+ for (let i = 0; i < times.length - 1; i++) {+ const fromProgress = times[i];+ const toProgress = times[i + 1];+ const fromValue = vals[i] ?? lastValue;+ const toValue = vals[i + 1] ?? lastValue;+ const r = toProgress - fromProgress;+ segments.push({+ easing: easings?.[i] ?? lastEasing ?? linear,+ rangeInverse: r > 0 ? 1 / r : 0,+ valueDelta: toValue - fromValue,+ fromProgress,+ toProgress,+ fromValue,+ toValue,+ });+ }++ tracks.push({ target, segments });+ }++ return createTimeline(tracks);+}diff --git a/js/app/packages/animate/types/types.ts b/js/app/packages/animate/types/types.tsnew file mode 100644index 0000000000..294d0db12b--- /dev/null+++ b/js/app/packages/animate/types/types.ts@@ -0,0 +1,76 @@+export type AnimationController = {+ onProgress(callback: (p: number) => void): AnimationController;+ onLoop(callback: (count: number) => void): AnimationController;+ onComplete(callback: () => void): AnimationController;+ onResume(callback: () => void): AnimationController;+ onPause(callback: () => void): AnimationController;+ duration(seconds: number): AnimationController;+ setSpeed(s: number): AnimationController;+ seek(p: number): AnimationController;+ pause(): AnimationController;+ loop(): AnimationController;+ play(): AnimationController;+ readonly isPlaying: boolean;+ readonly progress: number;+ readonly speed: number;+ destroy(): void;+};++export type EasingFn = (t: number) => number;++export type ProgressKeyframes = {+ [at: number]: ProgressKeyframeProperty[];+};++export type ProgressKeyframeProperty = {+ target: (val: number) => void;+ easing?: EasingFn;+ value: number;+};++export type PropertyKeyframeEntry = {+ easing?: (EasingFn | undefined)[];+ target: (val: number) => void;+ offset: number[];+ value: number[];+};++export type ProgressKeyframe = {+ easing?: EasingFn;+ progress: number;+ value: number;+};++export type PropertyTrack = {+ target: (val: number) => void;+ segments: PropertySegment[];+};++export type PropertySegment = {+ rangeInverse: number;+ fromProgress: number;+ toProgress: number;+ valueDelta: number;+ fromValue: number;+ easing: EasingFn;+ toValue: number;+};++export type ElasticOptions = {+ amplitude?: number;+ period?: number;+};++export type PlayOptions = {+ duration: number;+ speed?: number;+ loop?: boolean;+};++export type BackOptions = {+ overshoot?: number;+};++export type Timeline = {+ render(p: number): void;+};diff --git a/js/app/packages/animate/utils/controller.ts b/js/app/packages/animate/utils/controller.tsnew file mode 100644index 0000000000..6912cf8c64--- /dev/null+++ b/js/app/packages/animate/utils/controller.ts@@ -0,0 +1,169 @@+import type { AnimationController, Timeline } from '../types/types';++export function controller(input: Timeline | Timeline[]): AnimationController {+ const timelines = Array.isArray(input) ? input : [input];+ let _onProgress: ((p: number) => void) | null = null;+ let _onLoop: ((count: number) => void) | null = null;+ let _onComplete: (() => void) | null = null;+ let _onResume: (() => void) | null = null;+ let _onPause: (() => void) | null = null;+ let lastTimestamp: number | null = null;+ let rafId: number | null = null;+ let _isPlaying = false;+ let _loopCount = 0;+ let _duration = 1;+ let _progress = 0;+ let _loop = false;+ let _speed = 1;++ function onLoop(callback: (count: number) => void): AnimationController {+ _onLoop = callback;+ return ctrl;+ }++ function onProgress(callback: (p: number) => void): AnimationController {+ _onProgress = callback;+ return ctrl;+ }++ function onComplete(callback: () => void): AnimationController {+ _onComplete = callback;+ return ctrl;+ }++ function tick(timestamp: number) {+ if (!_isPlaying) {+ lastTimestamp = null;+ return;+ }++ if (lastTimestamp === null) {+ lastTimestamp = timestamp;+ rafId = requestAnimationFrame(tick);+ return;+ }++ const deltaMs = timestamp - lastTimestamp;+ lastTimestamp = timestamp;+ const deltaProgress = (deltaMs / 1000 / _duration) * _speed;+ let newProgress = _progress + deltaProgress;++ if (_loop) {+ if (newProgress > 1) {+ newProgress = newProgress % 1;+ _loopCount++;+ _onLoop?.(_loopCount);+ }+ if (newProgress < 0) {+ newProgress = 1 + (newProgress % 1);+ _loopCount++;+ _onLoop?.(_loopCount);+ }+ }+ else {+ if (newProgress >= 1) {+ renderAll(1);+ _isPlaying = false;+ lastTimestamp = null;+ _onComplete?.();+ return;+ }+ if (newProgress <= 0) {+ renderAll(0);+ _isPlaying = false;+ lastTimestamp = null;+ _onComplete?.();+ return;+ }+ }++ renderAll(newProgress);+ rafId = requestAnimationFrame(tick);+ }++ function onResume(callback: () => void): AnimationController {+ _onResume = callback;+ return ctrl;+ }++ function onPause(callback: () => void): AnimationController {+ _onPause = callback;+ return ctrl;+ }++ function renderAll(p: number) {+ _progress = p;+ for (const timeline of timelines) { timeline.render(p); }+ _onProgress?.(p);+ }++ function duration(seconds: number): AnimationController {+ _duration = seconds;+ return ctrl;+ }++ function setSpeed(s: number): AnimationController {+ _speed = s;+ return ctrl;+ }++ function seek(p: number): AnimationController {+ renderAll(p < 0 ? 0 : p > 1 ? 1 : p);+ return ctrl;+ }++ function pause(): AnimationController {+ _isPlaying = false;+ lastTimestamp = null;+ if (rafId !== null) {+ cancelAnimationFrame(rafId);+ rafId = null;+ }+ _onPause?.();+ return ctrl;+ }++ function play(): AnimationController {+ if (_isPlaying) return ctrl;+ _isPlaying = true;+ rafId = requestAnimationFrame(tick);+ _onResume?.();+ return ctrl;+ }++ function loop(): AnimationController {+ _loop = true;+ return ctrl;+ }++ function destroy(): void {+ pause();+ _onProgress = null;+ _onComplete = null;+ _onResume = null;+ _onPause = null;+ _onLoop = null;+ }++ renderAll(0);++ const ctrl: AnimationController = {+ get isPlaying() { return _isPlaying; },+ get progress() { return _progress; },+ get speed() { return _speed; },+ onProgress,+ onComplete,+ setSpeed,+ duration,+ onResume,+ destroy,+ onPause,+ onLoop,+ pause,+ loop,+ play,+ seek,+ };++ return ctrl;+}diff --git a/js/app/packages/animate/utils/timeline.ts b/js/app/packages/animate/utils/timeline.tsnew file mode 100644index 0000000000..0527ade561--- /dev/null+++ b/js/app/packages/animate/utils/timeline.ts@@ -0,0 +1,146 @@+import type { PropertyTrack, Timeline, EasingFn } from '../types/types';++/*+ Given the example PropertyTrack[] produced by `progressKeyframes`:++ [+ {+ target: setScale,+ segments: [+ { fromProgress: 0, toProgress: 0.25, fromValue: 1.0, toValue: 0.6, valueDelta: -0.4, rangeInverse: 4, easing: backOut },+ { fromProgress: 0.25, toProgress: 0.5, fromValue: 0.6, toValue: 0.6, valueDelta: 0.0, rangeInverse: 4, easing: cubicOut },+ { fromProgress: 0.5, toProgress: 0.75, fromValue: 0.6, toValue: 1.2, valueDelta: 0.6, rangeInverse: 4, easing: backOut },+ { fromProgress: 0.75, toProgress: 1.0, fromValue: 1.2, toValue: 1.0, valueDelta: -0.2, rangeInverse: 4, easing: cubicInOut },+ ],+ },+ {+ target: setX,+ segments: [+ { fromProgress: 0, toProgress: 0.5, fromValue: 0, toValue: 100, valueDelta: 100, rangeInverse: 2, easing: elasticOut },+ { fromProgress: 0.5, toProgress: 1.0, fromValue: 100, toValue: 0, valueDelta: -100, rangeInverse: 2, easing: bounceOut },+ ],+ },+ ]++ ...createTimeline compiles into a struct-of-arrays layout, indexed by track:++ trackCount = 2++ setters = [ setScale, setX ]+ segmentLengths = [ 4, 2 ]+ lastIndices = [ 3, 1 ]+ cachedIndices = Uint32Array [ 0, 0 ] // mutated per render++ fromProgressArrays = [ Float32Array [0, 0.25, 0.5, 0.75], Float32Array [0, 0.5 ] ]+ toProgressArrays = [ Float32Array [0.25, 0.5, 0.75, 1.0 ], Float32Array [0.5, 1.0 ] ]+ fromValueArrays = [ Float32Array [1.0, 0.6, 0.6, 1.2 ], Float32Array [0, 100 ] ]+ valueDeltaArrays = [ Float32Array [-0.4, 0.0, 0.6, -0.2 ], Float32Array [100, -100 ] ]+ rangeInverseArrays = [ Float32Array [4, 4, 4, 4 ], Float32Array [2, 2 ] ]+ easingArrays = [ [backOut, cubicOut, backOut, cubicInOut], [elasticOut, bounceOut] ]++ Why: hot-path render() reads parallel typed arrays by index, avoiding object+ property lookups and pointer chasing. Segments per track are tiny (here 4 and 2),+ so the linear-scan branch (len <= 4) skips the binary search, and cachedIndices+ short-circuits the lookup entirely while progress stays inside the same segment.++ Example: render(0.6) on the setScale track+ cachedIndices[0] = 0 (stale) -> fromP=0, toP=0.25, not in cached+ linear scan from j=3 down: fromProgressArr[2]=0.5 <= 0.6 -> idx = 2+ cachedIndices[0] = 2+ localProgress = (0.6 - 0.5) * 4 = 0.4+ mappedProgress = backOut(0.4) ~ 0.9+ setScale(0.6 + 0.6 * 0.9) ~ setScale(1.14)+*/++export function createTimeline(tracks: PropertyTrack[]): Timeline {+ const trackCount = tracks.length;++ const rangeInverseArrays: Float32Array[] = new Array(trackCount);+ const fromProgressArrays: Float32Array[] = new Array(trackCount);+ const setters: ((v: number) => void)[] = new Array(trackCount);+ const toProgressArrays: Float32Array[] = new Array(trackCount);+ const valueDeltaArrays: Float32Array[] = new Array(trackCount);+ const fromValueArrays: Float32Array[] = new Array(trackCount);+ const easingArrays: EasingFn[][] = new Array(trackCount);+ const segmentLengths: number[] = new Array(trackCount);+ const lastIndices: number[] = new Array(trackCount);+ const cachedIndices = new Uint32Array(trackCount);++ for (let i = 0; i < trackCount; i++) {+ const { target, segments } = tracks[i];+ const len = segments.length;+ const fromProgress = new Float32Array(len);+ const toProgress = new Float32Array(len);+ const fromValue = new Float32Array(len);+ const rangeInverse = new Float32Array(len);+ const valueDelta = new Float32Array(len);+ const easings: EasingFn[] = new Array(len);++ for (let j = 0; j < len; j++) {+ const seg = segments[j];+ fromProgress[j] = seg.fromProgress;+ toProgress[j] = seg.toProgress;+ fromValue[j] = seg.fromValue;+ rangeInverse[j] = seg.rangeInverse;+ valueDelta[j] = seg.valueDelta;+ easings[j] = seg.easing;+ }++ fromProgressArrays[i] = fromProgress;+ toProgressArrays[i] = toProgress;+ rangeInverseArrays[i] = rangeInverse;+ valueDeltaArrays[i] = valueDelta;+ fromValueArrays[i] = fromValue;+ easingArrays[i] = easings;+ lastIndices[i] = len - 1;+ segmentLengths[i] = len;+ setters[i] = target;+ }++ function render(progress: number) {+ const p = progress < 0 ? 0 : progress > 1 ? 1 : progress;++ for (let i = 0; i < trackCount; i++) {+ const fromProgressArr = fromProgressArrays[i];+ const toProgressArr = toProgressArrays[i];+ const lastIdx = lastIndices[i];++ let idx = cachedIndices[i];+ let fromP = fromProgressArr[idx];+ let toP = toProgressArr[idx];+ const inCached = p >= fromP && (p < toP || (p === 1 && idx === lastIdx));++ if (!inCached) {+ const len = segmentLengths[i];+ if (len <= 4) {+ idx = 0;+ for (let j = lastIdx; j >= 0; j--) {+ if (fromProgressArr[j] <= p) {+ idx = j;+ break;+ }+ }+ }+ else {+ let hi = lastIdx;+ let lo = 0;+ while (lo < hi) {+ const mid = (lo + hi + 1) >>> 1;+ if (fromProgressArr[mid] <= p) lo = mid;+ else hi = mid - 1;+ }+ idx = lo;+ }+ cachedIndices[i] = idx;+ fromP = fromProgressArr[idx];+ }++ const localProgress = (p - fromP) * rangeInverseArrays[i][idx];+ const mappedProgress = easingArrays[i][idx](localProgress);++ setters[i](fromValueArrays[i][idx] + valueDeltaArrays[i][idx] * mappedProgress);+ }+ }++ return { render };+}diff --git a/js/app/tsconfig.json b/js/app/tsconfig.jsonindex 8b2d7a0cfc..62c4ae63b9 100644--- a/js/app/tsconfig.json+++ b/js/app/tsconfig.json@@ -209,6 +209,12 @@"@notifications/*": ["./packages/notifications/*"],+ "@animate": [+ "./packages/animate/index.ts"+ ],+ "@animate/*": [+ "./packages/animate/*"+ ],"@app/*": ["./packages/app/*"],