@rootnative/web 0.0.0-alpha.5 → 0.0.0-alpha.6
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/CHANGELOG.md +11 -1
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/apis/Animated/AnimatedEvent.d.ts +19 -0
- package/dist/apis/Animated/AnimatedEvent.js +52 -0
- package/dist/apis/Animated/AnimatedEvent.js.map +1 -0
- package/dist/apis/Animated/AnimatedExports.d.ts +20 -0
- package/dist/apis/Animated/AnimatedExports.js +32 -0
- package/dist/apis/Animated/AnimatedExports.js.map +1 -0
- package/dist/apis/Animated/AnimatedImplementation.d.ts +18 -0
- package/dist/apis/Animated/AnimatedImplementation.js +79 -0
- package/dist/apis/Animated/AnimatedImplementation.js.map +1 -0
- package/dist/apis/Animated/animations/Animation.d.ts +29 -0
- package/dist/apis/Animated/animations/Animation.js +31 -0
- package/dist/apis/Animated/animations/Animation.js.map +1 -0
- package/dist/apis/Animated/animations/SpringAnimation.d.ts +17 -0
- package/dist/apis/Animated/animations/SpringAnimation.js +132 -0
- package/dist/apis/Animated/animations/SpringAnimation.js.map +1 -0
- package/dist/apis/Animated/animations/TimingAnimation.d.ts +8 -0
- package/dist/apis/Animated/animations/TimingAnimation.js +55 -0
- package/dist/apis/Animated/animations/TimingAnimation.js.map +1 -0
- package/dist/apis/Animated/animations/springConfig.js +37 -0
- package/dist/apis/Animated/animations/springConfig.js.map +1 -0
- package/dist/apis/Animated/createAnimatedComponent.d.ts +27 -0
- package/dist/apis/Animated/createAnimatedComponent.js +43 -0
- package/dist/apis/Animated/createAnimatedComponent.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedAddition.d.ts +14 -0
- package/dist/apis/Animated/nodes/AnimatedAddition.js +36 -0
- package/dist/apis/Animated/nodes/AnimatedAddition.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedInterpolation.d.ts +26 -0
- package/dist/apis/Animated/nodes/AnimatedInterpolation.js +171 -0
- package/dist/apis/Animated/nodes/AnimatedInterpolation.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedMultiplication.d.ts +14 -0
- package/dist/apis/Animated/nodes/AnimatedMultiplication.js +36 -0
- package/dist/apis/Animated/nodes/AnimatedMultiplication.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedNode.d.ts +29 -0
- package/dist/apis/Animated/nodes/AnimatedNode.js +47 -0
- package/dist/apis/Animated/nodes/AnimatedNode.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedObject.js +66 -0
- package/dist/apis/Animated/nodes/AnimatedObject.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedProps.js +88 -0
- package/dist/apis/Animated/nodes/AnimatedProps.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedStyle.js +65 -0
- package/dist/apis/Animated/nodes/AnimatedStyle.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedTransform.js +64 -0
- package/dist/apis/Animated/nodes/AnimatedTransform.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedValue.d.ts +26 -0
- package/dist/apis/Animated/nodes/AnimatedValue.js +81 -0
- package/dist/apis/Animated/nodes/AnimatedValue.js.map +1 -0
- package/dist/apis/Animated/nodes/AnimatedWithChildren.d.ts +9 -0
- package/dist/apis/Animated/nodes/AnimatedWithChildren.js +37 -0
- package/dist/apis/Animated/nodes/AnimatedWithChildren.js.map +1 -0
- package/dist/apis/Animated/useAnimatedProps.js +93 -0
- package/dist/apis/Animated/useAnimatedProps.js.map +1 -0
- package/dist/apis/Easing/bezier.js +69 -0
- package/dist/apis/Easing/bezier.js.map +1 -0
- package/dist/apis/Easing/index.d.ts +21 -0
- package/dist/apis/Easing/index.js +43 -0
- package/dist/apis/Easing/index.js.map +1 -0
- package/dist/index.d.ts +24 -22
- package/dist/index.js +4 -2
- package/llms.txt +39 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,15 @@ All notable changes to `@rootnative/web` are in this file. The format follows [K
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.0.0-alpha.6] - 2026-11-18
|
|
8
|
+
|
|
9
|
+
The first part of React Native's `Animated` API, and `Easing`. With them, Expo Router runs on this runtime, through `@rootnative/web-expo`.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **`Animated`**, on the JavaScript driver: `Animated.Value` with `interpolate`, `add`, `multiply`, `timing`, `spring`, `parallel`, `event`, `Animated.View`, `Animated.Text`, and `createAnimatedComponent`. A frame writes the new style to the element, with no React render. `useNativeDriver: true` runs the same driver. With reduced motion, `timing` and `spring` go to their end at once, after their `delay`. `toValue` takes only a number. `ValueXY`, `sequence`, `loop`, and the rest of the API come later. See [Animated](https://rootnative.github.io/web/animated).
|
|
14
|
+
- **`Easing`**, with every curve and helper of React Native and the same math: `linear`, `ease`, `quad`, `cubic`, `poly`, `sin`, `circle`, `exp`, `elastic`, `back`, `bounce`, `bezier`, `step0`, `step1`, `in`, `out`, and `inOut`. The type `EasingFunction` comes with it.
|
|
15
|
+
|
|
7
16
|
## [0.0.0-alpha.5] - 2026-11-15
|
|
8
17
|
|
|
9
18
|
Two changes make each render after the first one cheaper. On one app, the runtime's own script time while a menu or a dialog opens and closes is about half of what it was in `0.0.0-alpha.4`. The first load doesn't change.
|
|
@@ -141,7 +150,8 @@ The first alpha. It runs a React Native app in the browser with the components a
|
|
|
141
150
|
- There's no Vite plugin yet. Set the `react-native` alias by hand, as [Installation](https://rootnative.github.io/web/installation) shows.
|
|
142
151
|
- The tests run in Chromium. Firefox and Safari aren't in the test run yet.
|
|
143
152
|
|
|
144
|
-
[unreleased]: https://github.com/rootnative/web/compare/web@0.0.0-alpha.
|
|
153
|
+
[unreleased]: https://github.com/rootnative/web/compare/web@0.0.0-alpha.6...HEAD
|
|
154
|
+
[0.0.0-alpha.6]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.6
|
|
145
155
|
[0.0.0-alpha.5]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.5
|
|
146
156
|
[0.0.0-alpha.4]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.4
|
|
147
157
|
[0.0.0-alpha.3]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.3
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
export { __exportAll };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NativeSyntheticEvent } from "../../events/types.js";
|
|
2
|
+
import { PlatformConfig } from "./animations/Animation.js";
|
|
3
|
+
import { AnimatedValue } from "./nodes/AnimatedValue.js";
|
|
4
|
+
export type Mapping = {
|
|
5
|
+
[key: string]: Mapping;
|
|
6
|
+
} | AnimatedValue;
|
|
7
|
+
export type EventConfig<T> = {
|
|
8
|
+
listener?: ((event: NativeSyntheticEvent<T>) => unknown) | undefined;
|
|
9
|
+
useNativeDriver: boolean;
|
|
10
|
+
platformConfig?: PlatformConfig | undefined;
|
|
11
|
+
};
|
|
12
|
+
export declare class AnimatedEvent {
|
|
13
|
+
private readonly argMapping;
|
|
14
|
+
private readonly listeners;
|
|
15
|
+
constructor(argMapping: readonly (Mapping | null | undefined)[], config: EventConfig<unknown>);
|
|
16
|
+
__getHandler(): (...args: unknown[]) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare const event: <T>(argMapping: readonly (Mapping | null | undefined)[], config: EventConfig<T>) => ((...args: unknown[]) => void);
|
|
19
|
+
//# sourceMappingURL=AnimatedEvent.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { isProductionEnv } from "../../utils/env.js";
|
|
2
|
+
import { AnimatedValue } from "./nodes/AnimatedValue.js";
|
|
3
|
+
// src/apis/Animated/AnimatedEvent.ts
|
|
4
|
+
/**
|
|
5
|
+
* @license MIT
|
|
6
|
+
* A port of `Libraries/Animated/AnimatedEvent.js` of React Native, Copyright (c) Meta Platforms,
|
|
7
|
+
* Inc. and affiliates.
|
|
8
|
+
*/
|
|
9
|
+
const fail = (message) => {
|
|
10
|
+
throw new Error(message);
|
|
11
|
+
};
|
|
12
|
+
const validate = (mapping, event, key) => {
|
|
13
|
+
if (mapping instanceof AnimatedValue) {
|
|
14
|
+
if (typeof event !== "number") fail(`Bad mapping of event key ${key}, should be number but got ${typeof event}`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (typeof event === "number") fail(`Bad mapping of type ${typeof mapping} for key ${key}, event value must map to AnimatedValue`);
|
|
18
|
+
if (typeof mapping !== "object") fail(`Bad mapping of type ${typeof mapping} for key ${key}`);
|
|
19
|
+
if (typeof event !== "object") fail(`Bad event of type ${typeof event} for key ${key}`);
|
|
20
|
+
for (const name in mapping) validate(mapping?.[name], event?.[name], name);
|
|
21
|
+
};
|
|
22
|
+
const validateMapping = (argMapping, args) => {
|
|
23
|
+
if (args.length < argMapping.length) fail("Event has less arguments than mapping");
|
|
24
|
+
argMapping.forEach((mapping, index) => validate(mapping, args[index], `arg${index}`));
|
|
25
|
+
};
|
|
26
|
+
const setValues = (mapping, event) => {
|
|
27
|
+
if (mapping instanceof AnimatedValue) {
|
|
28
|
+
if (typeof event === "number") mapping.setValue(event);
|
|
29
|
+
} else if (typeof mapping === "object" && mapping !== null) for (const name in mapping) setValues(mapping[name], event?.[name]);
|
|
30
|
+
};
|
|
31
|
+
var AnimatedEvent = class {
|
|
32
|
+
constructor(argMapping, config) {
|
|
33
|
+
this.listeners = [];
|
|
34
|
+
this.argMapping = argMapping;
|
|
35
|
+
if (config.listener) this.listeners.push(config.listener);
|
|
36
|
+
}
|
|
37
|
+
__getHandler() {
|
|
38
|
+
let validated = isProductionEnv();
|
|
39
|
+
return (...args) => {
|
|
40
|
+
if (!validated) {
|
|
41
|
+
validateMapping(this.argMapping, args);
|
|
42
|
+
validated = true;
|
|
43
|
+
}
|
|
44
|
+
this.argMapping.forEach((mapping, index) => setValues(mapping, args[index]));
|
|
45
|
+
for (const listener of this.listeners) listener(...args);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const event = (argMapping, config) => new AnimatedEvent(argMapping, config).__getHandler();
|
|
50
|
+
export { AnimatedEvent, event };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=AnimatedEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimatedEvent.js","names":[],"sources":["../../../src/apis/Animated/AnimatedEvent.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/AnimatedEvent.js` of React Native, Copyright (c) Meta Platforms,\n * Inc. and affiliates.\n */\n\nimport type { NativeSyntheticEvent } from '../../events/types'\nimport { isProductionEnv } from '../../utils/env'\nimport type { PlatformConfig } from './animations/Animation'\nimport { AnimatedValue } from './nodes/AnimatedValue'\n\nexport type Mapping = { [key: string]: Mapping } | AnimatedValue\n\nexport type EventConfig<T> = {\n listener?: ((event: NativeSyntheticEvent<T>) => unknown) | undefined\n useNativeDriver: boolean\n platformConfig?: PlatformConfig | undefined\n}\n\ntype Listener = (...args: unknown[]) => unknown\n\nconst fail = (message: string): never => {\n throw new Error(message)\n}\n\nconst validate = (mapping: Mapping | null | undefined, event: unknown, key: string): void => {\n if (mapping instanceof AnimatedValue) {\n if (typeof event !== 'number') {\n fail(`Bad mapping of event key ${key}, should be number but got ${typeof event}`)\n }\n return\n }\n if (typeof event === 'number') {\n fail(\n `Bad mapping of type ${typeof mapping} for key ${key}, event value must map to AnimatedValue`,\n )\n }\n if (typeof mapping !== 'object') fail(`Bad mapping of type ${typeof mapping} for key ${key}`)\n if (typeof event !== 'object') fail(`Bad event of type ${typeof event} for key ${key}`)\n for (const name in mapping) {\n validate(mapping?.[name], (event as Record<string, unknown> | null)?.[name], name)\n }\n}\n\nconst validateMapping = (argMapping: readonly (Mapping | null | undefined)[], args: unknown[]) => {\n if (args.length < argMapping.length) fail('Event has less arguments than mapping')\n argMapping.forEach((mapping, index) => validate(mapping, args[index], `arg${index}`))\n}\n\nconst setValues = (mapping: Mapping | null | undefined, event: unknown): void => {\n if (mapping instanceof AnimatedValue) {\n if (typeof event === 'number') mapping.setValue(event)\n } else if (typeof mapping === 'object' && mapping !== null) {\n for (const name in mapping) {\n setValues(mapping[name], (event as Record<string, unknown> | null)?.[name])\n }\n }\n}\n\n// The web has no native driver, so each event runs the JavaScript handler, also with\n// `useNativeDriver: true`.\nexport class AnimatedEvent {\n private readonly argMapping: readonly (Mapping | null | undefined)[]\n private readonly listeners: Listener[] = []\n\n constructor(argMapping: readonly (Mapping | null | undefined)[], config: EventConfig<unknown>) {\n this.argMapping = argMapping\n if (config.listener) this.listeners.push(config.listener as Listener)\n }\n\n // A handler that sets each mapped value from the event, then calls the listener. In\n // development, it checks the mapping on the first event.\n __getHandler(): (...args: unknown[]) => void {\n let validated = isProductionEnv()\n return (...args) => {\n if (!validated) {\n validateMapping(this.argMapping, args)\n validated = true\n }\n this.argMapping.forEach((mapping, index) => setValues(mapping, args[index]))\n for (const listener of this.listeners) listener(...args)\n }\n }\n}\n\nexport const event = <T>(\n argMapping: readonly (Mapping | null | undefined)[],\n config: EventConfig<T>,\n): ((...args: unknown[]) => void) =>\n new AnimatedEvent(argMapping, config as EventConfig<unknown>).__getHandler()\n"],"mappings":";;;;;;;;AAqBA,MAAM,QAAQ,YAA2B;CACvC,MAAM,IAAI,MAAM,OAAO;AACzB;AAEA,MAAM,YAAY,SAAqC,OAAgB,QAAsB;CAC3F,IAAI,mBAAmB,eAAe;EACpC,IAAI,OAAO,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,CAAC,aAAa"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ViewInstance, ViewProps } from "../../components/View/types.js";
|
|
2
|
+
import { TextInstance, TextProps } from "../../components/Text/types.js";
|
|
3
|
+
import "../../components/Text/index.js";
|
|
4
|
+
import "../../components/View/index.js";
|
|
5
|
+
import { AnimatedComponentType, AnimatedProps, WithAnimatedValue, createAnimatedComponent } from "./createAnimatedComponent.js";
|
|
6
|
+
import { AnimatedInterpolation, InterpolationConfigType } from "./nodes/AnimatedInterpolation.js";
|
|
7
|
+
import { AnimatedValue, AnimatedValueConfig } from "./nodes/AnimatedValue.js";
|
|
8
|
+
import { AnimatedEvent, event } from "./AnimatedEvent.js";
|
|
9
|
+
import { CompositeAnimation, SpringAnimationConfig, TimingAnimationConfig, parallel, spring, timing } from "./AnimatedImplementation.js";
|
|
10
|
+
import { AnimatedAddition, add } from "./nodes/AnimatedAddition.js";
|
|
11
|
+
import { AnimatedMultiplication, multiply } from "./nodes/AnimatedMultiplication.js";
|
|
12
|
+
import { AnimatedNode } from "./nodes/AnimatedNode.js";
|
|
13
|
+
declare namespace AnimatedExports_d_exports {
|
|
14
|
+
export { AnimatedAddition, AnimatedComponentType as AnimatedComponent, AnimatedValueConfig as AnimatedConfig, AnimatedInterpolation, AnimatedMultiplication, AnimatedNode, AnimatedProps, CompositeAnimation, AnimatedEvent as Event, AnimatedInterpolation as Interpolation, InterpolationConfigType as InterpolationConfig, AnimatedNode as Node, Numeric, SpringAnimationConfig, Text, TimingAnimationConfig, AnimatedValue as Value, View, WithAnimatedValue, add, createAnimatedComponent, event, multiply, parallel, spring, timing };
|
|
15
|
+
}
|
|
16
|
+
export type Numeric = AnimatedInterpolation<number> | AnimatedValue;
|
|
17
|
+
export declare const View: AnimatedComponentType<ViewProps, ViewInstance>;
|
|
18
|
+
export declare const Text: AnimatedComponentType<TextProps, TextInstance>;
|
|
19
|
+
export { type AnimatedAddition, type AnimatedComponentType as AnimatedComponent, type AnimatedValueConfig as AnimatedConfig, AnimatedExports_d_exports, type AnimatedInterpolation, type AnimatedMultiplication, type AnimatedNode, type AnimatedProps, type CompositeAnimation, AnimatedEvent as Event, AnimatedInterpolation as Interpolation, type InterpolationConfigType as InterpolationConfig, AnimatedNode as Node, type SpringAnimationConfig, type TimingAnimationConfig, AnimatedValue as Value, type WithAnimatedValue, add, createAnimatedComponent, event, multiply, parallel, spring, timing };
|
|
20
|
+
//# sourceMappingURL=AnimatedExports.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { Text as Text$1 } from "../../components/Text/index.js";
|
|
3
|
+
import { View as View$1 } from "../../components/View/index.js";
|
|
4
|
+
import { createAnimatedComponent } from "./createAnimatedComponent.js";
|
|
5
|
+
import { AnimatedEvent, event } from "./AnimatedEvent.js";
|
|
6
|
+
import { parallel, spring, timing } from "./AnimatedImplementation.js";
|
|
7
|
+
import { add } from "./nodes/AnimatedAddition.js";
|
|
8
|
+
import { AnimatedInterpolation } from "./nodes/AnimatedInterpolation.js";
|
|
9
|
+
import { multiply } from "./nodes/AnimatedMultiplication.js";
|
|
10
|
+
import { AnimatedNode } from "./nodes/AnimatedNode.js";
|
|
11
|
+
import { AnimatedValue } from "./nodes/AnimatedValue.js";
|
|
12
|
+
// src/apis/Animated/AnimatedExports.ts
|
|
13
|
+
var AnimatedExports_exports = /* @__PURE__ */ __exportAll({
|
|
14
|
+
Event: () => AnimatedEvent,
|
|
15
|
+
Interpolation: () => AnimatedInterpolation,
|
|
16
|
+
Node: () => AnimatedNode,
|
|
17
|
+
Text: () => Text,
|
|
18
|
+
Value: () => AnimatedValue,
|
|
19
|
+
View: () => View,
|
|
20
|
+
add: () => add,
|
|
21
|
+
createAnimatedComponent: () => createAnimatedComponent,
|
|
22
|
+
event: () => event,
|
|
23
|
+
multiply: () => multiply,
|
|
24
|
+
parallel: () => parallel,
|
|
25
|
+
spring: () => spring,
|
|
26
|
+
timing: () => timing
|
|
27
|
+
});
|
|
28
|
+
const View = /* @__PURE__ */ createAnimatedComponent(View$1);
|
|
29
|
+
const Text = /* @__PURE__ */ createAnimatedComponent(Text$1);
|
|
30
|
+
export { AnimatedExports_exports, AnimatedEvent as Event, AnimatedInterpolation as Interpolation, AnimatedNode as Node, Text, AnimatedValue as Value, View, add, createAnimatedComponent, event, multiply, parallel, spring, timing };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=AnimatedExports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimatedExports.js","names":["BaseView","BaseText"],"sources":["../../../src/apis/Animated/AnimatedExports.ts"],"sourcesContent":["import { Text as BaseText } from '../../components/Text'\nimport type { TextInstance, TextProps } from '../../components/Text'\nimport { View as BaseView } from '../../components/View'\nimport type { ViewInstance, ViewProps } from '../../components/View'\nimport { createAnimatedComponent } from './createAnimatedComponent'\nimport type { AnimatedComponentType } from './createAnimatedComponent'\nimport type { AnimatedInterpolation } from './nodes/AnimatedInterpolation'\nimport type { AnimatedValue } from './nodes/AnimatedValue'\n\nexport { AnimatedEvent as Event, event } from './AnimatedEvent'\nexport { parallel, spring, timing } from './AnimatedImplementation'\nexport type {\n CompositeAnimation,\n SpringAnimationConfig,\n TimingAnimationConfig,\n} from './AnimatedImplementation'\nexport { createAnimatedComponent } from './createAnimatedComponent'\nexport type {\n AnimatedComponentType as AnimatedComponent,\n AnimatedProps,\n WithAnimatedValue,\n} from './createAnimatedComponent'\nexport { add } from './nodes/AnimatedAddition'\nexport type { AnimatedAddition } from './nodes/AnimatedAddition'\nexport { AnimatedInterpolation as Interpolation } from './nodes/AnimatedInterpolation'\nexport type {\n AnimatedInterpolation,\n InterpolationConfigType as InterpolationConfig,\n} from './nodes/AnimatedInterpolation'\nexport { multiply } from './nodes/AnimatedMultiplication'\nexport type { AnimatedMultiplication } from './nodes/AnimatedMultiplication'\nexport { AnimatedNode as Node } from './nodes/AnimatedNode'\nexport type { AnimatedNode } from './nodes/AnimatedNode'\nexport { AnimatedValue as Value } from './nodes/AnimatedValue'\nexport type { AnimatedValueConfig as AnimatedConfig } from './nodes/AnimatedValue'\n\nexport type Numeric = AnimatedInterpolation<number> | AnimatedValue\n\nexport const View: AnimatedComponentType<ViewProps, ViewInstance> =\n /* @__PURE__ */ createAnimatedComponent(BaseView)\n\nexport const Text: AnimatedComponentType<TextProps, TextInstance> =\n /* @__PURE__ */ createAnimatedComponent(BaseText)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,OACK,wCAAwBA,MAAQ;AAElD,MAAa,OACK,wCAAwBC,MAAQ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EndCallback } from "./animations/Animation.js";
|
|
2
|
+
import { SpringAnimationConfigSingle } from "./animations/SpringAnimation.js";
|
|
3
|
+
import { TimingAnimationConfigSingle } from "./animations/TimingAnimation.js";
|
|
4
|
+
import { AnimatedValue } from "./nodes/AnimatedValue.js";
|
|
5
|
+
export type CompositeAnimation = {
|
|
6
|
+
start: (callback?: EndCallback | undefined, isLooping?: boolean) => void;
|
|
7
|
+
stop: () => void;
|
|
8
|
+
reset: () => void;
|
|
9
|
+
};
|
|
10
|
+
export type TimingAnimationConfig = TimingAnimationConfigSingle;
|
|
11
|
+
export type SpringAnimationConfig = SpringAnimationConfigSingle;
|
|
12
|
+
export type ParallelConfig = {
|
|
13
|
+
stopTogether?: boolean | undefined;
|
|
14
|
+
};
|
|
15
|
+
export declare const timing: (value: AnimatedValue, config: TimingAnimationConfig) => CompositeAnimation;
|
|
16
|
+
export declare const spring: (value: AnimatedValue, config: SpringAnimationConfig) => CompositeAnimation;
|
|
17
|
+
export declare const parallel: (animations: CompositeAnimation[], config?: ParallelConfig | null) => CompositeAnimation;
|
|
18
|
+
//# sourceMappingURL=AnimatedImplementation.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { SpringAnimation } from "./animations/SpringAnimation.js";
|
|
2
|
+
import { TimingAnimation } from "./animations/TimingAnimation.js";
|
|
3
|
+
// src/apis/Animated/AnimatedImplementation.ts
|
|
4
|
+
/**
|
|
5
|
+
* @license MIT
|
|
6
|
+
* A port of `timing`, `spring`, and `parallel` from `Libraries/Animated/AnimatedImplementation.js`
|
|
7
|
+
* of React Native, Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
+
*/
|
|
9
|
+
const combineCallbacks = (callback, config) => {
|
|
10
|
+
const { onComplete } = config;
|
|
11
|
+
if (callback && onComplete) return (result) => {
|
|
12
|
+
onComplete(result);
|
|
13
|
+
callback(result);
|
|
14
|
+
};
|
|
15
|
+
return callback ?? onComplete;
|
|
16
|
+
};
|
|
17
|
+
const checkToValue = (config) => {
|
|
18
|
+
if (typeof config.toValue !== "number") throw new Error("Animated: a toValue that is not a number is not in @rootnative/web yet. See https://rootnative.github.io/web/status.");
|
|
19
|
+
};
|
|
20
|
+
const timing = (value, config) => ({
|
|
21
|
+
start: (callback) => {
|
|
22
|
+
checkToValue(config);
|
|
23
|
+
value.animate(new TimingAnimation(config), combineCallbacks(callback, config));
|
|
24
|
+
},
|
|
25
|
+
stop: () => value.stopAnimation(),
|
|
26
|
+
reset: () => value.resetAnimation()
|
|
27
|
+
});
|
|
28
|
+
const spring = (value, config) => ({
|
|
29
|
+
start: (callback) => {
|
|
30
|
+
checkToValue(config);
|
|
31
|
+
value.animate(new SpringAnimation(config), combineCallbacks(callback, config));
|
|
32
|
+
},
|
|
33
|
+
stop: () => value.stopAnimation(),
|
|
34
|
+
reset: () => value.resetAnimation()
|
|
35
|
+
});
|
|
36
|
+
const parallel = (animations, config) => {
|
|
37
|
+
let doneCount = 0;
|
|
38
|
+
const hasEnded = [];
|
|
39
|
+
const stopTogether = config?.stopTogether !== false;
|
|
40
|
+
const result = {
|
|
41
|
+
start: (callback, isLooping) => {
|
|
42
|
+
if (doneCount === animations.length) {
|
|
43
|
+
callback?.({ finished: true });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
animations.forEach((animation, index) => {
|
|
47
|
+
const onEnd = (endResult) => {
|
|
48
|
+
hasEnded[index] = true;
|
|
49
|
+
doneCount++;
|
|
50
|
+
if (doneCount === animations.length) {
|
|
51
|
+
doneCount = 0;
|
|
52
|
+
callback?.(endResult);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!endResult.finished && stopTogether) result.stop();
|
|
56
|
+
};
|
|
57
|
+
if (animation) animation.start(onEnd, isLooping);
|
|
58
|
+
else onEnd({ finished: true });
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
stop: () => {
|
|
62
|
+
animations.forEach((animation, index) => {
|
|
63
|
+
if (!hasEnded[index]) animation.stop();
|
|
64
|
+
hasEnded[index] = true;
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
reset: () => {
|
|
68
|
+
animations.forEach((animation, index) => {
|
|
69
|
+
animation.reset();
|
|
70
|
+
hasEnded[index] = false;
|
|
71
|
+
doneCount = 0;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
export { parallel, spring, timing };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=AnimatedImplementation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimatedImplementation.js","names":[],"sources":["../../../src/apis/Animated/AnimatedImplementation.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `timing`, `spring`, and `parallel` from `Libraries/Animated/AnimatedImplementation.js`\n * of React Native, Copyright (c) Meta Platforms, Inc. and affiliates.\n */\n\nimport type { AnimationConfig, EndCallback, EndResult } from './animations/Animation'\nimport { SpringAnimation } from './animations/SpringAnimation'\nimport type { SpringAnimationConfigSingle } from './animations/SpringAnimation'\nimport { TimingAnimation } from './animations/TimingAnimation'\nimport type { TimingAnimationConfigSingle } from './animations/TimingAnimation'\nimport type { AnimatedValue } from './nodes/AnimatedValue'\n\nexport type CompositeAnimation = {\n start: (callback?: EndCallback | undefined, isLooping?: boolean) => void\n stop: () => void\n reset: () => void\n}\n\n// Only a number for now. React Native also takes an `Animated` node, a `ValueXY`, and a color.\nexport type TimingAnimationConfig = TimingAnimationConfigSingle\nexport type SpringAnimationConfig = SpringAnimationConfigSingle\n\nexport type ParallelConfig = { stopTogether?: boolean | undefined }\n\nconst combineCallbacks = (\n callback: EndCallback | undefined,\n config: AnimationConfig,\n): EndCallback | undefined => {\n const { onComplete } = config\n if (callback && onComplete) {\n return (result) => {\n onComplete(result)\n callback(result)\n }\n }\n return callback ?? onComplete\n}\n\nconst checkToValue = (config: { toValue: unknown }): void => {\n if (typeof config.toValue !== 'number') {\n throw new Error(\n 'Animated: a toValue that is not a number is not in @rootnative/web yet. See https://rootnative.github.io/web/status.',\n )\n }\n}\n\nexport const timing = (\n value: AnimatedValue,\n config: TimingAnimationConfig,\n): CompositeAnimation => ({\n start: (callback) => {\n checkToValue(config)\n value.animate(new TimingAnimation(config), combineCallbacks(callback, config))\n },\n stop: () => value.stopAnimation(),\n reset: () => value.resetAnimation(),\n})\n\nexport const spring = (\n value: AnimatedValue,\n config: SpringAnimationConfig,\n): CompositeAnimation => ({\n start: (callback) => {\n checkToValue(config)\n value.animate(new SpringAnimation(config), combineCallbacks(callback, config))\n },\n stop: () => value.stopAnimation(),\n reset: () => value.resetAnimation(),\n})\n\n// Starts each animation at once. With `stopTogether` (the default), the first one that stops\n// early stops the rest. The callback runs once, when the last one ends, with its result.\nexport const parallel = (\n animations: CompositeAnimation[],\n config?: ParallelConfig | null,\n): CompositeAnimation => {\n let doneCount = 0\n const hasEnded: boolean[] = []\n const stopTogether = config?.stopTogether !== false\n\n const result: CompositeAnimation = {\n start: (callback, isLooping) => {\n if (doneCount === animations.length) {\n callback?.({ finished: true })\n return\n }\n animations.forEach((animation, index) => {\n const onEnd = (endResult: EndResult): void => {\n hasEnded[index] = true\n doneCount++\n if (doneCount === animations.length) {\n doneCount = 0\n callback?.(endResult)\n return\n }\n if (!endResult.finished && stopTogether) result.stop()\n }\n // React Native allows a hole in the list, so a `.map()` can return null for a route.\n if (animation) animation.start(onEnd, isLooping)\n else onEnd({ finished: true })\n })\n },\n stop: () => {\n animations.forEach((animation, index) => {\n if (!hasEnded[index]) animation.stop()\n hasEnded[index] = true\n })\n },\n reset: () => {\n animations.forEach((animation, index) => {\n animation.reset()\n hasEnded[index] = false\n doneCount = 0\n })\n },\n }\n return result\n}\n"],"mappings":";;;;;;;;AAyBA,MAAM,oBACJ,UACA,WAC4B;CAC5B,MAAM,EAAE,eAAe;CACvB,IAAI,YAAY,YACd,QAAQ,WAAW;EACjB,WAAW,MAAM;EACjB,SAAS,MAAM;CACjB;CAEF,OAAO,YAAY;AACrB;AAEA,MAAM,gBAAgB,WAAuC;CAC3D,IAAI,OAAO,OAAO,YAAY,UAC5B,MAAM,IAAI,MACR,sHACF;AAEJ;AAEA,MAAa,UACX,OACA,YACwB;CACxB,QAAQ,aAAa;EACnB,aAAa,MAAM;EACnB,MAAM,QAAQ,IAAI,gBAAgB,MAAM,GAAG,iBAAiB,UAAU,MAAM,CAAC;CAC/E;CACA,YAAY,MAAM,cAAc;CAChC,aAAa,MAAM,eAAe;AACpC;AAEA,MAAa,UACX,OACA,YACwB;CACxB,QAAQ,aAAa;EACnB,aAAa,MAAM;EACnB,MAAM,QAAQ,IAAI,gBAAgB,MAAM,GAAG,iBAAiB,UAAU,MAAM,CAAC;CAC/E;CACA,YAAY,MAAM,cAAc;CAChC,aAAa,MAAM,eAAe;AACpC;AAIA,MAAa,YACX,YACA,WACuB;CACvB,IAAI,YAAY;CAChB,MAAM,WAAsB,CAAC;CAC7B,MAAM,eAAe,QAAQ,iBAAiB;CAE9C,MAAM,SAA6B;EACjC,QAAQ,UAAU,cAAc;GAC9B,IAAI,cAAc,WAAW,QAAQ;IACnC,WAAW,EAAE,UAAU,KAAK,CAAC;IAC7B;GACF;GACA,WAAW,SAAS,WAAW,UAAU;IACvC,MAAM,SAAS,cAA+B;KAC5C,SAAS,SAAS;KAClB;KACA,IAAI,cAAc,WAAW,QAAQ;MACnC,YAAY;MACZ,WAAW,SAAS;MACpB;KACF;KACA,IAAI,CAAC,UAAU,YAAY,cAAc,OAAO,KAAK;IACvD;IAEA,IAAI,WAAW,UAAU,MAAM,OAAO,SAAS;SAC1C,MAAM,EAAE,UAAU,KAAK,CAAC;GAC/B,CAAC;EACH;EACA,YAAY;GACV,WAAW,SAAS,WAAW,UAAU;IACvC,IAAI,CAAC,SAAS,QAAQ,UAAU,KAAK;IACrC,SAAS,SAAS;GACpB,CAAC;EACH;EACA,aAAa;GACX,WAAW,SAAS,WAAW,UAAU;IACvC,UAAU,MAAM;IAChB,SAAS,SAAS;IAClB,YAAY;GACd,CAAC;EACH;CACF;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* A port of `Libraries/Animated/animations/Animation.js` of React Native, Copyright (c) Meta
|
|
4
|
+
* Platforms, Inc. and affiliates.
|
|
5
|
+
*/
|
|
6
|
+
export type EndResult = {
|
|
7
|
+
finished: boolean;
|
|
8
|
+
value?: number | undefined;
|
|
9
|
+
offset?: number | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type EndCallback = (result: EndResult) => void;
|
|
12
|
+
export type PlatformConfig = {};
|
|
13
|
+
export type AnimationConfig = Readonly<{
|
|
14
|
+
isInteraction?: boolean | undefined;
|
|
15
|
+
useNativeDriver: boolean;
|
|
16
|
+
platformConfig?: PlatformConfig | undefined;
|
|
17
|
+
onComplete?: EndCallback | undefined;
|
|
18
|
+
iterations?: number | undefined;
|
|
19
|
+
isLooping?: boolean | undefined;
|
|
20
|
+
debugID?: string | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export declare class Animation {
|
|
23
|
+
private onEnd;
|
|
24
|
+
protected active: boolean;
|
|
25
|
+
start(_fromValue: number, _onUpdate: (value: number) => void, onEnd: EndCallback | null | undefined, _previousAnimation: Animation | null | undefined): void;
|
|
26
|
+
stop(): void;
|
|
27
|
+
protected notifyAnimationEnd(result: EndResult): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=Animation.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Platform } from "../../Platform/index.js";
|
|
2
|
+
// src/apis/Animated/animations/Animation.ts
|
|
3
|
+
/**
|
|
4
|
+
* @license MIT
|
|
5
|
+
* A port of `Libraries/Animated/animations/Animation.js` of React Native, Copyright (c) Meta
|
|
6
|
+
* Platforms, Inc. and affiliates.
|
|
7
|
+
*/
|
|
8
|
+
const now = () => performance.now();
|
|
9
|
+
const isMotionReduced = () => Platform.isDisableAnimations;
|
|
10
|
+
var Animation = class {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.active = false;
|
|
13
|
+
}
|
|
14
|
+
start(_fromValue, _onUpdate, onEnd, _previousAnimation) {
|
|
15
|
+
this.onEnd = onEnd;
|
|
16
|
+
this.active = true;
|
|
17
|
+
}
|
|
18
|
+
stop() {
|
|
19
|
+
this.active = false;
|
|
20
|
+
}
|
|
21
|
+
notifyAnimationEnd(result) {
|
|
22
|
+
const callback = this.onEnd;
|
|
23
|
+
if (callback) {
|
|
24
|
+
this.onEnd = null;
|
|
25
|
+
callback(result);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export { Animation, isMotionReduced, now };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=Animation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Animation.js","names":[],"sources":["../../../../src/apis/Animated/animations/Animation.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/animations/Animation.js` of React Native, Copyright (c) Meta\n * Platforms, Inc. and affiliates.\n */\n\nimport { Platform } from '../../Platform'\n\nexport type EndResult = {\n finished: boolean\n value?: number | undefined\n offset?: number | undefined\n}\n\nexport type EndCallback = (result: EndResult) => void\n\n// React Native's `AnimatedPlatformConfig`, an empty type.\nexport type PlatformConfig = {}\n\nexport type AnimationConfig = Readonly<{\n isInteraction?: boolean | undefined\n useNativeDriver: boolean\n platformConfig?: PlatformConfig | undefined\n onComplete?: EndCallback | undefined\n iterations?: number | undefined\n isLooping?: boolean | undefined\n debugID?: string | undefined\n}>\n\n// The clock of the JavaScript driver. React Native reads `Date.now()`. `performance.now()` is\n// monotonic, so a change of the system clock can't make an animation jump.\nexport const now = (): number => performance.now()\n\n// As in the other components: with reduced motion, an animation goes to its end at once. A delay\n// still waits, so a sequence keeps its order and its pauses.\nexport const isMotionReduced = (): boolean => Platform.isDisableAnimations\n\n// The web has no native driver, so `useNativeDriver`, `isInteraction`, `iterations`, and\n// `platformConfig` have no effect here.\nexport class Animation {\n private onEnd: EndCallback | null | undefined\n protected active = false\n\n start(\n _fromValue: number,\n _onUpdate: (value: number) => void,\n onEnd: EndCallback | null | undefined,\n _previousAnimation: Animation | null | undefined,\n ): void {\n this.onEnd = onEnd\n this.active = true\n }\n\n stop(): void {\n this.active = false\n }\n\n // Calls the end callback once at most.\n protected notifyAnimationEnd(result: EndResult): void {\n const callback = this.onEnd\n if (callback) {\n this.onEnd = null\n callback(result)\n }\n }\n}\n"],"mappings":";;;;;;;AA+BA,MAAa,YAAoB,YAAY,IAAI;AAIjD,MAAa,wBAAiC,SAAS;AAIvD,IAAa,YAAb,MAAuB;;EAErB,KAAU,SAAS;;CAEnB,MACE,YACA,WACA,OACA,oBACM;EACN,KAAK,QAAQ;EACb,KAAK,SAAS;CAChB;CAEA,OAAa;EACX,KAAK,SAAS;CAChB;CAGA,mBAA6B,QAAyB;EACpD,MAAM,WAAW,KAAK;EACtB,IAAI,UAAU;GACZ,KAAK,QAAQ;GACb,SAAS,MAAM;EACjB;CACF;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AnimationConfig } from "./Animation.js";
|
|
2
|
+
export type SpringAnimationConfigSingle = Readonly<AnimationConfig & {
|
|
3
|
+
toValue: number;
|
|
4
|
+
overshootClamping?: boolean | undefined;
|
|
5
|
+
restDisplacementThreshold?: number | undefined;
|
|
6
|
+
restSpeedThreshold?: number | undefined;
|
|
7
|
+
velocity?: number | undefined;
|
|
8
|
+
bounciness?: number | undefined;
|
|
9
|
+
speed?: number | undefined;
|
|
10
|
+
tension?: number | undefined;
|
|
11
|
+
friction?: number | undefined;
|
|
12
|
+
stiffness?: number | undefined;
|
|
13
|
+
damping?: number | undefined;
|
|
14
|
+
mass?: number | undefined;
|
|
15
|
+
delay?: number | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=SpringAnimation.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Animation, isMotionReduced, now } from "./Animation.js";
|
|
2
|
+
import { fromBouncinessAndSpeed, fromOrigamiTensionAndFriction } from "./springConfig.js";
|
|
3
|
+
// src/apis/Animated/animations/SpringAnimation.ts
|
|
4
|
+
/**
|
|
5
|
+
* @license MIT
|
|
6
|
+
* A port of `Libraries/Animated/animations/SpringAnimation.js` of React Native, Copyright (c) Meta
|
|
7
|
+
* Platforms, Inc. and affiliates.
|
|
8
|
+
*/
|
|
9
|
+
const ONE_KIND = "You can define one of bounciness/speed, tension/friction, or stiffness/damping/mass, but not more than one";
|
|
10
|
+
const MAX_STEP_MS = 64;
|
|
11
|
+
const check = (condition, message) => {
|
|
12
|
+
if (!condition) throw new Error(message);
|
|
13
|
+
};
|
|
14
|
+
var SpringAnimation = class SpringAnimation extends Animation {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
super();
|
|
17
|
+
this.startPosition = 0;
|
|
18
|
+
this.lastPosition = 0;
|
|
19
|
+
this.lastTime = 0;
|
|
20
|
+
this.frameTime = 0;
|
|
21
|
+
this.setValue = () => {};
|
|
22
|
+
this.overshootClamping = config.overshootClamping ?? false;
|
|
23
|
+
this.restDisplacementThreshold = config.restDisplacementThreshold ?? .001;
|
|
24
|
+
this.restSpeedThreshold = config.restSpeedThreshold ?? .001;
|
|
25
|
+
this.initialVelocity = config.velocity ?? 0;
|
|
26
|
+
this.lastVelocity = config.velocity ?? 0;
|
|
27
|
+
this.toValue = config.toValue;
|
|
28
|
+
this.delay = config.delay ?? 0;
|
|
29
|
+
if (config.stiffness !== void 0 || config.damping !== void 0 || config.mass !== void 0) {
|
|
30
|
+
check(config.bounciness === void 0 && config.speed === void 0 && config.tension === void 0 && config.friction === void 0, ONE_KIND);
|
|
31
|
+
this.stiffness = config.stiffness ?? 100;
|
|
32
|
+
this.damping = config.damping ?? 10;
|
|
33
|
+
this.mass = config.mass ?? 1;
|
|
34
|
+
} else if (config.bounciness !== void 0 || config.speed !== void 0) {
|
|
35
|
+
check(config.tension === void 0 && config.friction === void 0, ONE_KIND);
|
|
36
|
+
const spring = fromBouncinessAndSpeed(config.bounciness ?? 8, config.speed ?? 12);
|
|
37
|
+
this.stiffness = spring.stiffness;
|
|
38
|
+
this.damping = spring.damping;
|
|
39
|
+
this.mass = 1;
|
|
40
|
+
} else {
|
|
41
|
+
const spring = fromOrigamiTensionAndFriction(config.tension ?? 40, config.friction ?? 7);
|
|
42
|
+
this.stiffness = spring.stiffness;
|
|
43
|
+
this.damping = spring.damping;
|
|
44
|
+
this.mass = 1;
|
|
45
|
+
}
|
|
46
|
+
check(this.stiffness > 0, "Stiffness value must be greater than 0");
|
|
47
|
+
check(this.damping > 0, "Damping value must be greater than 0");
|
|
48
|
+
check(this.mass > 0, "Mass value must be greater than 0");
|
|
49
|
+
}
|
|
50
|
+
start(fromValue, onUpdate, onEnd, previousAnimation) {
|
|
51
|
+
super.start(fromValue, onUpdate, onEnd, previousAnimation);
|
|
52
|
+
this.startPosition = fromValue;
|
|
53
|
+
this.lastPosition = fromValue;
|
|
54
|
+
this.setValue = onUpdate;
|
|
55
|
+
this.lastTime = now();
|
|
56
|
+
this.frameTime = 0;
|
|
57
|
+
if (previousAnimation instanceof SpringAnimation) {
|
|
58
|
+
const state = previousAnimation.getInternalState();
|
|
59
|
+
this.lastPosition = state.lastPosition;
|
|
60
|
+
this.lastVelocity = state.lastVelocity;
|
|
61
|
+
this.initialVelocity = state.lastVelocity;
|
|
62
|
+
this.lastTime = state.lastTime;
|
|
63
|
+
}
|
|
64
|
+
const start = () => {
|
|
65
|
+
if (isMotionReduced()) this.finish();
|
|
66
|
+
else this.onUpdate();
|
|
67
|
+
};
|
|
68
|
+
if (this.delay) this.timeout = setTimeout(start, this.delay);
|
|
69
|
+
else start();
|
|
70
|
+
}
|
|
71
|
+
getInternalState() {
|
|
72
|
+
return {
|
|
73
|
+
lastPosition: this.lastPosition,
|
|
74
|
+
lastVelocity: this.lastVelocity,
|
|
75
|
+
lastTime: this.lastTime
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
onUpdate() {
|
|
79
|
+
const time = Math.min(now(), this.lastTime + MAX_STEP_MS);
|
|
80
|
+
this.frameTime += (time - this.lastTime) / 1e3;
|
|
81
|
+
const c = this.damping;
|
|
82
|
+
const m = this.mass;
|
|
83
|
+
const k = this.stiffness;
|
|
84
|
+
const v0 = -this.initialVelocity;
|
|
85
|
+
const zeta = c / (2 * Math.sqrt(k * m));
|
|
86
|
+
const omega0 = Math.sqrt(k / m);
|
|
87
|
+
const omega1 = omega0 * Math.sqrt(1 - zeta * zeta);
|
|
88
|
+
const x0 = this.toValue - this.startPosition;
|
|
89
|
+
const t = this.frameTime;
|
|
90
|
+
let position;
|
|
91
|
+
let velocity;
|
|
92
|
+
if (zeta < 1) {
|
|
93
|
+
const envelope = Math.exp(-zeta * omega0 * t);
|
|
94
|
+
const sin = Math.sin(omega1 * t);
|
|
95
|
+
const cos = Math.cos(omega1 * t);
|
|
96
|
+
position = this.toValue - envelope * ((v0 + zeta * omega0 * x0) / omega1 * sin + x0 * cos);
|
|
97
|
+
velocity = zeta * omega0 * envelope * (sin * (v0 + zeta * omega0 * x0) / omega1 + x0 * cos) - envelope * (cos * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin);
|
|
98
|
+
} else {
|
|
99
|
+
const envelope = Math.exp(-omega0 * t);
|
|
100
|
+
position = this.toValue - envelope * (x0 + (v0 + omega0 * x0) * t);
|
|
101
|
+
velocity = envelope * (v0 * (t * omega0 - 1) + t * x0 * (omega0 * omega0));
|
|
102
|
+
}
|
|
103
|
+
this.lastTime = time;
|
|
104
|
+
this.lastPosition = position;
|
|
105
|
+
this.lastVelocity = velocity;
|
|
106
|
+
this.setValue(position);
|
|
107
|
+
if (!this.active) return;
|
|
108
|
+
let isOvershooting = false;
|
|
109
|
+
if (this.overshootClamping) isOvershooting = this.startPosition < this.toValue ? position > this.toValue : position < this.toValue;
|
|
110
|
+
const isResting = Math.abs(velocity) <= this.restSpeedThreshold && Math.abs(this.toValue - position) <= this.restDisplacementThreshold;
|
|
111
|
+
if (isOvershooting || isResting) {
|
|
112
|
+
this.finish();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.frame = requestAnimationFrame(() => this.onUpdate());
|
|
116
|
+
}
|
|
117
|
+
stop() {
|
|
118
|
+
super.stop();
|
|
119
|
+
clearTimeout(this.timeout);
|
|
120
|
+
if (this.frame !== void 0) cancelAnimationFrame(this.frame);
|
|
121
|
+
this.notifyAnimationEnd({ finished: false });
|
|
122
|
+
}
|
|
123
|
+
finish() {
|
|
124
|
+
this.lastPosition = this.toValue;
|
|
125
|
+
this.lastVelocity = 0;
|
|
126
|
+
this.setValue(this.toValue);
|
|
127
|
+
this.notifyAnimationEnd({ finished: true });
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export { SpringAnimation };
|
|
131
|
+
|
|
132
|
+
//# sourceMappingURL=SpringAnimation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpringAnimation.js","names":[],"sources":["../../../../src/apis/Animated/animations/SpringAnimation.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/animations/SpringAnimation.js` of React Native, Copyright (c) Meta\n * Platforms, Inc. and affiliates.\n */\n\nimport { Animation, isMotionReduced, now } from './Animation'\nimport type { AnimationConfig, EndCallback } from './Animation'\nimport { fromBouncinessAndSpeed, fromOrigamiTensionAndFriction } from './springConfig'\n\nexport type SpringAnimationConfigSingle = Readonly<\n AnimationConfig & {\n toValue: number\n overshootClamping?: boolean | undefined\n restDisplacementThreshold?: number | undefined\n restSpeedThreshold?: number | undefined\n velocity?: number | undefined\n bounciness?: number | undefined\n speed?: number | undefined\n tension?: number | undefined\n friction?: number | undefined\n stiffness?: number | undefined\n damping?: number | undefined\n mass?: number | undefined\n delay?: number | undefined\n }\n>\n\nexport type SpringAnimationInternalState = Readonly<{\n lastPosition: number\n lastVelocity: number\n lastTime: number\n}>\n\nconst ONE_KIND =\n 'You can define one of bounciness/speed, tension/friction, or stiffness/damping/mass, but not more than one'\n\n// A frame after a long pause, such as a hidden tab, moves the spring by 64 ms at most.\nconst MAX_STEP_MS = 64\n\nconst check = (condition: boolean, message: string): void => {\n if (!condition) throw new Error(message)\n}\n\nexport class SpringAnimation extends Animation {\n private readonly overshootClamping: boolean\n private readonly restDisplacementThreshold: number\n private readonly restSpeedThreshold: number\n private readonly toValue: number\n private readonly stiffness: number\n private readonly damping: number\n private readonly mass: number\n private readonly delay: number\n private initialVelocity: number\n private lastVelocity: number\n private startPosition = 0\n private lastPosition = 0\n private lastTime = 0\n private frameTime = 0\n private setValue: (value: number) => void = () => {}\n private frame: number | undefined\n private timeout: ReturnType<typeof setTimeout> | undefined\n\n constructor(config: SpringAnimationConfigSingle) {\n super()\n this.overshootClamping = config.overshootClamping ?? false\n this.restDisplacementThreshold = config.restDisplacementThreshold ?? 0.001\n this.restSpeedThreshold = config.restSpeedThreshold ?? 0.001\n this.initialVelocity = config.velocity ?? 0\n this.lastVelocity = config.velocity ?? 0\n this.toValue = config.toValue\n this.delay = config.delay ?? 0\n\n if (\n config.stiffness !== undefined ||\n config.damping !== undefined ||\n config.mass !== undefined\n ) {\n check(\n config.bounciness === undefined &&\n config.speed === undefined &&\n config.tension === undefined &&\n config.friction === undefined,\n ONE_KIND,\n )\n this.stiffness = config.stiffness ?? 100\n this.damping = config.damping ?? 10\n this.mass = config.mass ?? 1\n } else if (config.bounciness !== undefined || config.speed !== undefined) {\n check(config.tension === undefined && config.friction === undefined, ONE_KIND)\n const spring = fromBouncinessAndSpeed(config.bounciness ?? 8, config.speed ?? 12)\n this.stiffness = spring.stiffness\n this.damping = spring.damping\n this.mass = 1\n } else {\n const spring = fromOrigamiTensionAndFriction(config.tension ?? 40, config.friction ?? 7)\n this.stiffness = spring.stiffness\n this.damping = spring.damping\n this.mass = 1\n }\n\n check(this.stiffness > 0, 'Stiffness value must be greater than 0')\n check(this.damping > 0, 'Damping value must be greater than 0')\n check(this.mass > 0, 'Mass value must be greater than 0')\n }\n\n override start(\n fromValue: number,\n onUpdate: (value: number) => void,\n onEnd: EndCallback | null | undefined,\n previousAnimation: Animation | null | undefined,\n ): void {\n super.start(fromValue, onUpdate, onEnd, previousAnimation)\n this.startPosition = fromValue\n this.lastPosition = fromValue\n this.setValue = onUpdate\n this.lastTime = now()\n this.frameTime = 0\n\n // A spring that takes over from a spring keeps its position and its speed.\n if (previousAnimation instanceof SpringAnimation) {\n const state = previousAnimation.getInternalState()\n this.lastPosition = state.lastPosition\n this.lastVelocity = state.lastVelocity\n this.initialVelocity = state.lastVelocity\n this.lastTime = state.lastTime\n }\n\n const start = (): void => {\n if (isMotionReduced()) this.finish()\n else this.onUpdate()\n }\n if (this.delay) this.timeout = setTimeout(start, this.delay)\n else start()\n }\n\n getInternalState(): SpringAnimationInternalState {\n return {\n lastPosition: this.lastPosition,\n lastVelocity: this.lastVelocity,\n lastTime: this.lastTime,\n }\n }\n\n // The closed form of a damped harmonic oscillator, x'' + 2ζω₀x' + ω₀²x = 0, with ω₀ = √(k/m) and\n // ζ = c / 2√(mk). It is the model of CASpringAnimation on iOS.\n onUpdate(): void {\n const time = Math.min(now(), this.lastTime + MAX_STEP_MS)\n this.frameTime += (time - this.lastTime) / 1000\n\n const c = this.damping\n const m = this.mass\n const k = this.stiffness\n const v0 = -this.initialVelocity\n const zeta = c / (2 * Math.sqrt(k * m))\n const omega0 = Math.sqrt(k / m)\n const omega1 = omega0 * Math.sqrt(1 - zeta * zeta)\n const x0 = this.toValue - this.startPosition\n const t = this.frameTime\n\n let position: number\n let velocity: number\n if (zeta < 1) {\n const envelope = Math.exp(-zeta * omega0 * t)\n const sin = Math.sin(omega1 * t)\n const cos = Math.cos(omega1 * t)\n position = this.toValue - envelope * (((v0 + zeta * omega0 * x0) / omega1) * sin + x0 * cos)\n velocity =\n zeta * omega0 * envelope * ((sin * (v0 + zeta * omega0 * x0)) / omega1 + x0 * cos) -\n envelope * (cos * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin)\n } else {\n const envelope = Math.exp(-omega0 * t)\n position = this.toValue - envelope * (x0 + (v0 + omega0 * x0) * t)\n velocity = envelope * (v0 * (t * omega0 - 1) + t * x0 * (omega0 * omega0))\n }\n\n this.lastTime = time\n this.lastPosition = position\n this.lastVelocity = velocity\n this.setValue(position)\n if (!this.active) return\n\n let isOvershooting = false\n if (this.overshootClamping) {\n isOvershooting =\n this.startPosition < this.toValue ? position > this.toValue : position < this.toValue\n }\n const isResting =\n Math.abs(velocity) <= this.restSpeedThreshold &&\n Math.abs(this.toValue - position) <= this.restDisplacementThreshold\n\n if (isOvershooting || isResting) {\n this.finish()\n return\n }\n this.frame = requestAnimationFrame(() => this.onUpdate())\n }\n\n override stop(): void {\n super.stop()\n clearTimeout(this.timeout)\n if (this.frame !== undefined) cancelAnimationFrame(this.frame)\n this.notifyAnimationEnd({ finished: false })\n }\n\n private finish(): void {\n this.lastPosition = this.toValue\n this.lastVelocity = 0\n this.setValue(this.toValue)\n this.notifyAnimationEnd({ finished: true })\n }\n}\n"],"mappings":";;;;;;;;AAkCA,MAAM,WACJ;AAGF,MAAM,cAAc;AAEpB,MAAM,SAAS,WAAoB,YAA0B;CAC3D,IAAI,CAAC,WAAW,MAAM,IAAI,MAAM,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4
|
+
easing?: ((value: number) => number) | undefined;
|
|
5
|
+
duration?: number | undefined;
|
|
6
|
+
delay?: number | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=TimingAnimation.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Easing } from "../../Easing/index.js";
|
|
2
|
+
import { Animation, isMotionReduced, now } from "./Animation.js";
|
|
3
|
+
// src/apis/Animated/animations/TimingAnimation.ts
|
|
4
|
+
/**
|
|
5
|
+
* @license MIT
|
|
6
|
+
* A port of `Libraries/Animated/animations/TimingAnimation.js` of React Native, Copyright (c) Meta
|
|
7
|
+
* Platforms, Inc. and affiliates.
|
|
8
|
+
*/
|
|
9
|
+
let easeInOut;
|
|
10
|
+
var TimingAnimation = class extends Animation {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super();
|
|
13
|
+
this.startTime = 0;
|
|
14
|
+
this.fromValue = 0;
|
|
15
|
+
this.setValue = () => {};
|
|
16
|
+
this.toValue = config.toValue;
|
|
17
|
+
this.easing = config.easing ?? (easeInOut ??= Easing.inOut(Easing.ease));
|
|
18
|
+
this.duration = config.duration ?? 500;
|
|
19
|
+
this.delay = config.delay ?? 0;
|
|
20
|
+
}
|
|
21
|
+
start(fromValue, onUpdate, onEnd, previousAnimation) {
|
|
22
|
+
super.start(fromValue, onUpdate, onEnd, previousAnimation);
|
|
23
|
+
this.fromValue = fromValue;
|
|
24
|
+
this.setValue = onUpdate;
|
|
25
|
+
const start = () => {
|
|
26
|
+
this.startTime = now();
|
|
27
|
+
if (this.duration === 0 || isMotionReduced()) {
|
|
28
|
+
this.setValue(this.toValue);
|
|
29
|
+
this.notifyAnimationEnd({ finished: true });
|
|
30
|
+
} else this.frame = requestAnimationFrame(() => this.onUpdate());
|
|
31
|
+
};
|
|
32
|
+
if (this.delay) this.timeout = setTimeout(start, this.delay);
|
|
33
|
+
else start();
|
|
34
|
+
}
|
|
35
|
+
onUpdate() {
|
|
36
|
+
const time = now();
|
|
37
|
+
if (time >= this.startTime + this.duration) {
|
|
38
|
+
this.setValue(this.fromValue + this.easing(1) * (this.toValue - this.fromValue));
|
|
39
|
+
this.notifyAnimationEnd({ finished: true });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const progress = this.easing((time - this.startTime) / this.duration);
|
|
43
|
+
this.setValue(this.fromValue + progress * (this.toValue - this.fromValue));
|
|
44
|
+
if (this.active) this.frame = requestAnimationFrame(() => this.onUpdate());
|
|
45
|
+
}
|
|
46
|
+
stop() {
|
|
47
|
+
super.stop();
|
|
48
|
+
clearTimeout(this.timeout);
|
|
49
|
+
if (this.frame !== void 0) cancelAnimationFrame(this.frame);
|
|
50
|
+
this.notifyAnimationEnd({ finished: false });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export { TimingAnimation };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=TimingAnimation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimingAnimation.js","names":[],"sources":["../../../../src/apis/Animated/animations/TimingAnimation.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/animations/TimingAnimation.js` of React Native, Copyright (c) Meta\n * Platforms, Inc. and affiliates.\n */\n\nimport { Easing } from '../../Easing'\nimport type { EasingFunction } from '../../Easing'\nimport { Animation, isMotionReduced, now } from './Animation'\nimport type { AnimationConfig, EndCallback } from './Animation'\n\nexport type TimingAnimationConfigSingle = Readonly<\n AnimationConfig & {\n toValue: number\n easing?: ((value: number) => number) | undefined\n duration?: number | undefined\n delay?: number | undefined\n }\n>\n\nlet easeInOut: EasingFunction | undefined\n\nexport class TimingAnimation extends Animation {\n private startTime = 0\n private fromValue = 0\n private readonly toValue: number\n private readonly duration: number\n private readonly delay: number\n private readonly easing: EasingFunction\n private setValue: (value: number) => void = () => {}\n private frame: number | undefined\n private timeout: ReturnType<typeof setTimeout> | undefined\n\n constructor(config: TimingAnimationConfigSingle) {\n super()\n this.toValue = config.toValue\n this.easing = config.easing ?? (easeInOut ??= Easing.inOut(Easing.ease))\n this.duration = config.duration ?? 500\n this.delay = config.delay ?? 0\n }\n\n override start(\n fromValue: number,\n onUpdate: (value: number) => void,\n onEnd: EndCallback | null | undefined,\n previousAnimation: Animation | null | undefined,\n ): void {\n super.start(fromValue, onUpdate, onEnd, previousAnimation)\n this.fromValue = fromValue\n this.setValue = onUpdate\n\n const start = (): void => {\n this.startTime = now()\n if (this.duration === 0 || isMotionReduced()) {\n this.setValue(this.toValue)\n this.notifyAnimationEnd({ finished: true })\n } else {\n this.frame = requestAnimationFrame(() => this.onUpdate())\n }\n }\n if (this.delay) this.timeout = setTimeout(start, this.delay)\n else start()\n }\n\n onUpdate(): void {\n const time = now()\n if (time >= this.startTime + this.duration) {\n // As in React Native, the last value uses `easing(1)`. A custom curve that doesn't end at 1\n // ends short of `toValue`.\n this.setValue(this.fromValue + this.easing(1) * (this.toValue - this.fromValue))\n this.notifyAnimationEnd({ finished: true })\n return\n }\n const progress = this.easing((time - this.startTime) / this.duration)\n this.setValue(this.fromValue + progress * (this.toValue - this.fromValue))\n if (this.active) this.frame = requestAnimationFrame(() => this.onUpdate())\n }\n\n override stop(): void {\n super.stop()\n clearTimeout(this.timeout)\n if (this.frame !== undefined) cancelAnimationFrame(this.frame)\n this.notifyAnimationEnd({ finished: false })\n }\n}\n"],"mappings":";;;;;;;;AAoBA,IAAI;AAEJ,IAAa,kBAAb,cAAqC,UAAU;CAW7C,YAAY,QAAqC;EAC/C,MAAM;EAXR,KAAQ,YAAY;EACpB,KAAQ,YAAY;EAKpB,KAAQ,iBAA0C,CAAC;EAMjD,KAAK,UAAU,OAAO;EACtB,KAAK,SAAS,OAAO,WAAW,cAAc,OAAO,MAAM,OAAO,IAAI;EACtE,KAAK,WAAW,OAAO,YAAY;EACnC,KAAK,QAAQ,OAAO,SAAS;CAC/B;CAEA,MACE,WACA,UACA,OACA,mBACM;EACN,MAAM,MAAM,WAAW,UAAU,OAAO,iBAAiB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