@rootnative/web 0.0.0-alpha.4 → 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.
Files changed (67) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/_virtual/_rolldown/runtime.js +12 -0
  3. package/dist/apis/Animated/AnimatedEvent.d.ts +19 -0
  4. package/dist/apis/Animated/AnimatedEvent.js +52 -0
  5. package/dist/apis/Animated/AnimatedEvent.js.map +1 -0
  6. package/dist/apis/Animated/AnimatedExports.d.ts +20 -0
  7. package/dist/apis/Animated/AnimatedExports.js +32 -0
  8. package/dist/apis/Animated/AnimatedExports.js.map +1 -0
  9. package/dist/apis/Animated/AnimatedImplementation.d.ts +18 -0
  10. package/dist/apis/Animated/AnimatedImplementation.js +79 -0
  11. package/dist/apis/Animated/AnimatedImplementation.js.map +1 -0
  12. package/dist/apis/Animated/animations/Animation.d.ts +29 -0
  13. package/dist/apis/Animated/animations/Animation.js +31 -0
  14. package/dist/apis/Animated/animations/Animation.js.map +1 -0
  15. package/dist/apis/Animated/animations/SpringAnimation.d.ts +17 -0
  16. package/dist/apis/Animated/animations/SpringAnimation.js +132 -0
  17. package/dist/apis/Animated/animations/SpringAnimation.js.map +1 -0
  18. package/dist/apis/Animated/animations/TimingAnimation.d.ts +8 -0
  19. package/dist/apis/Animated/animations/TimingAnimation.js +55 -0
  20. package/dist/apis/Animated/animations/TimingAnimation.js.map +1 -0
  21. package/dist/apis/Animated/animations/springConfig.js +37 -0
  22. package/dist/apis/Animated/animations/springConfig.js.map +1 -0
  23. package/dist/apis/Animated/createAnimatedComponent.d.ts +27 -0
  24. package/dist/apis/Animated/createAnimatedComponent.js +43 -0
  25. package/dist/apis/Animated/createAnimatedComponent.js.map +1 -0
  26. package/dist/apis/Animated/nodes/AnimatedAddition.d.ts +14 -0
  27. package/dist/apis/Animated/nodes/AnimatedAddition.js +36 -0
  28. package/dist/apis/Animated/nodes/AnimatedAddition.js.map +1 -0
  29. package/dist/apis/Animated/nodes/AnimatedInterpolation.d.ts +26 -0
  30. package/dist/apis/Animated/nodes/AnimatedInterpolation.js +171 -0
  31. package/dist/apis/Animated/nodes/AnimatedInterpolation.js.map +1 -0
  32. package/dist/apis/Animated/nodes/AnimatedMultiplication.d.ts +14 -0
  33. package/dist/apis/Animated/nodes/AnimatedMultiplication.js +36 -0
  34. package/dist/apis/Animated/nodes/AnimatedMultiplication.js.map +1 -0
  35. package/dist/apis/Animated/nodes/AnimatedNode.d.ts +29 -0
  36. package/dist/apis/Animated/nodes/AnimatedNode.js +47 -0
  37. package/dist/apis/Animated/nodes/AnimatedNode.js.map +1 -0
  38. package/dist/apis/Animated/nodes/AnimatedObject.js +66 -0
  39. package/dist/apis/Animated/nodes/AnimatedObject.js.map +1 -0
  40. package/dist/apis/Animated/nodes/AnimatedProps.js +88 -0
  41. package/dist/apis/Animated/nodes/AnimatedProps.js.map +1 -0
  42. package/dist/apis/Animated/nodes/AnimatedStyle.js +65 -0
  43. package/dist/apis/Animated/nodes/AnimatedStyle.js.map +1 -0
  44. package/dist/apis/Animated/nodes/AnimatedTransform.js +64 -0
  45. package/dist/apis/Animated/nodes/AnimatedTransform.js.map +1 -0
  46. package/dist/apis/Animated/nodes/AnimatedValue.d.ts +26 -0
  47. package/dist/apis/Animated/nodes/AnimatedValue.js +81 -0
  48. package/dist/apis/Animated/nodes/AnimatedValue.js.map +1 -0
  49. package/dist/apis/Animated/nodes/AnimatedWithChildren.d.ts +9 -0
  50. package/dist/apis/Animated/nodes/AnimatedWithChildren.js +37 -0
  51. package/dist/apis/Animated/nodes/AnimatedWithChildren.js.map +1 -0
  52. package/dist/apis/Animated/useAnimatedProps.js +93 -0
  53. package/dist/apis/Animated/useAnimatedProps.js.map +1 -0
  54. package/dist/apis/Easing/bezier.js +69 -0
  55. package/dist/apis/Easing/bezier.js.map +1 -0
  56. package/dist/apis/Easing/index.d.ts +21 -0
  57. package/dist/apis/Easing/index.js +43 -0
  58. package/dist/apis/Easing/index.js.map +1 -0
  59. package/dist/index.d.ts +24 -22
  60. package/dist/index.js +4 -2
  61. package/dist/style/compile.js +61 -31
  62. package/dist/style/compile.js.map +1 -1
  63. package/dist/style/registry.d.ts +1 -0
  64. package/dist/style/registry.js +3 -0
  65. package/dist/style/registry.js.map +1 -1
  66. package/llms.txt +39 -13
  67. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimatedObject.js","names":[],"sources":["../../../../src/apis/Animated/nodes/AnimatedObject.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/nodes/AnimatedObject.js` of React Native, Copyright (c) Meta\n * Platforms, Inc. and affiliates.\n */\n\nimport { isValidElement } from 'react'\n\nimport { AnimatedNode } from './AnimatedNode'\nimport { AnimatedWithChildren } from './AnimatedWithChildren'\n\n// The search for nodes stops at this depth, so a large prop such as list data stays cheap.\nconst MAX_DEPTH = 5\n\nexport const isPlainObject = (value: unknown): value is Readonly<Record<string, unknown>> => {\n if (value === null || typeof value !== 'object') return false\n const proto: unknown = Object.getPrototypeOf(value)\n return (proto === null || proto === Object.prototype) && !isValidElement(value)\n}\n\nconst flatAnimatedNodes = (\n value: unknown,\n nodes: AnimatedNode[] = [],\n depth = 0,\n): AnimatedNode[] => {\n if (depth >= MAX_DEPTH) return nodes\n if (value instanceof AnimatedNode) {\n nodes.push(value)\n } else if (Array.isArray(value)) {\n for (const element of value) flatAnimatedNodes(element, nodes, depth + 1)\n } else if (isPlainObject(value)) {\n for (const key of Object.keys(value)) flatAnimatedNodes(value[key], nodes, depth + 1)\n }\n return nodes\n}\n\nexport const animatedNodesIn = (value: unknown): AnimatedNode[] => flatAnimatedNodes(value)\n\nconst mapAnimatedNodes = (\n value: unknown,\n fn: (node: AnimatedNode) => unknown,\n depth = 0,\n): unknown => {\n if (depth >= MAX_DEPTH) return value\n if (value instanceof AnimatedNode) return fn(value)\n if (Array.isArray(value)) return value.map((element) => mapAnimatedNodes(element, fn, depth + 1))\n if (isPlainObject(value)) {\n const result: Record<string, unknown> = {}\n for (const key of Object.keys(value)) result[key] = mapAnimatedNodes(value[key], fn, depth + 1)\n return result\n }\n return value\n}\n\n// A plain object or an array with nodes inside, such as `shadowOffset: { width: node }`.\nexport class AnimatedObject extends AnimatedWithChildren {\n private readonly nodes: readonly AnimatedNode[]\n private readonly value: unknown\n\n // An `AnimatedObject` when `value` holds a node, else null.\n static from(value: unknown): AnimatedObject | null {\n const nodes = flatAnimatedNodes(value)\n return nodes.length === 0 ? null : new AnimatedObject(nodes, value)\n }\n\n constructor(nodes: readonly AnimatedNode[], value: unknown) {\n super()\n this.nodes = nodes\n this.value = value\n }\n\n override __getValue(): unknown {\n return mapAnimatedNodes(this.value, (node) => node.__getValue())\n }\n\n // The values of the nodes, in order, at the places of the nodes in `staticObject`.\n __getValueWithStaticObject(staticObject: unknown): unknown {\n let index = 0\n return mapAnimatedNodes(staticObject, () => this.nodes[index++]?.__getValue())\n }\n\n override __getAnimatedValue(): unknown {\n return mapAnimatedNodes(this.value, (node) => node.__getAnimatedValue())\n }\n\n override __attach(): void {\n for (const node of this.nodes) node.__addChild(this)\n super.__attach()\n }\n\n override __detach(): void {\n for (const node of this.nodes) node.__removeChild(this)\n super.__detach()\n }\n}\n"],"mappings":";;;;;;;;;AAYA,MAAM,YAAY;AAElB,MAAa,iBAAiB,UAA+D;CAC3F,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO;CACxD,MAAM,QAAiB,OAAO,eAAe,KAAK;CAClD,QAAQ,UAAU,QAAQ,UAAU,OAAO,cAAc,CAAC,eAAe,KAAK;AAChF;AAEA,MAAM,qBACJ,OACA,QAAwB,CAAC,GACzB,QAAQ,MACW;CACnB,IAAI,SAAS,WAAW,OAAO;CAC/B,IAAI,iBAAiB,cACnB,MAAM,KAAK,KAAK;MACX,IAAI,MAAM,QAAQ,KAAK,GAC5B,KAAK,MAAM,WAAW,OAAO,kBAAkB,SAAS,OAAO,QAAQ,CAAC;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,KAAK,OAAO,KAAK,cAAc,IAAI;EACtD,MAAM,SAAS;CACjB;AACF"}
@@ -0,0 +1,88 @@
1
+ import { flattenStyle } from "../../../style/compile.js";
2
+ import { AnimatedEvent } from "../AnimatedEvent.js";
3
+ import { AnimatedNode } from "./AnimatedNode.js";
4
+ import { AnimatedObject } from "./AnimatedObject.js";
5
+ import { AnimatedStyle } from "./AnimatedStyle.js";
6
+ // src/apis/Animated/nodes/AnimatedProps.ts
7
+ /**
8
+ * @license MIT
9
+ * A port of `Libraries/Animated/nodes/AnimatedProps.js` of React Native, Copyright (c) Meta
10
+ * Platforms, Inc. and affiliates.
11
+ */
12
+ const flatten = (style) => flattenStyle(style);
13
+ var AnimatedProps = class extends AnimatedNode {
14
+ constructor(inputProps) {
15
+ super();
16
+ this.callback = null;
17
+ const nodes = [];
18
+ const nodeKeys = [];
19
+ const props = {};
20
+ for (const [key, value] of Object.entries(inputProps)) {
21
+ let node;
22
+ if (key === "style") node = AnimatedStyle.from(flatten(value));
23
+ else if (value instanceof AnimatedNode) node = value;
24
+ else node = AnimatedObject.from(value);
25
+ if (node === null) props[key] = value;
26
+ else {
27
+ nodes.push(node);
28
+ nodeKeys.push(key);
29
+ props[key] = node;
30
+ }
31
+ }
32
+ this.nodes = nodes;
33
+ this.nodeKeys = nodeKeys;
34
+ this.props = props;
35
+ }
36
+ setUpdateCallback(callback) {
37
+ this.callback = callback;
38
+ }
39
+ animatesOnlyStyle() {
40
+ return this.nodeKeys.every((key) => key === "style");
41
+ }
42
+ __getValue() {
43
+ const props = {};
44
+ for (const [key, value] of Object.entries(this.props)) if (value instanceof AnimatedNode) props[key] = value.__getValue();
45
+ else if (value instanceof AnimatedEvent) props[key] = value.__getHandler();
46
+ else props[key] = value;
47
+ return props;
48
+ }
49
+ __getValueWithStaticProps(staticProps) {
50
+ const props = { ...staticProps };
51
+ for (const key of Object.keys(staticProps)) {
52
+ const node = this.props[key];
53
+ if (key === "style") props[key] = this.styleWithStaticStyle(staticProps[key]);
54
+ else if (node instanceof AnimatedNode) props[key] = node.__getValue();
55
+ else if (node instanceof AnimatedEvent) props[key] = node.__getHandler();
56
+ }
57
+ return props;
58
+ }
59
+ styleWithStaticStyle(staticStyle) {
60
+ const node = this.props["style"];
61
+ const flatStatic = flatten(staticStyle);
62
+ if (!(node instanceof AnimatedStyle)) return flatStatic;
63
+ const style = flatStatic === void 0 ? {} : flatStatic === staticStyle ? { ...flatStatic } : flatStatic;
64
+ node.__replaceAnimatedNodeWithValues(style);
65
+ return style;
66
+ }
67
+ __getAnimatedValue() {
68
+ const props = {};
69
+ this.nodes.forEach((node, index) => {
70
+ props[this.nodeKeys[index] ?? ""] = node.__getAnimatedValue();
71
+ });
72
+ return props;
73
+ }
74
+ __attach() {
75
+ for (const node of this.nodes) node.__addChild(this);
76
+ super.__attach();
77
+ }
78
+ __detach() {
79
+ for (const node of this.nodes) node.__removeChild(this);
80
+ super.__detach();
81
+ }
82
+ update() {
83
+ this.callback?.();
84
+ }
85
+ };
86
+ export { AnimatedProps };
87
+
88
+ //# sourceMappingURL=AnimatedProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimatedProps.js","names":[],"sources":["../../../../src/apis/Animated/nodes/AnimatedProps.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/nodes/AnimatedProps.js` of React Native, Copyright (c) Meta\n * Platforms, Inc. and affiliates.\n */\n\nimport { flattenStyle } from '../../../style/compile'\nimport type { FlatStyle, StyleProp } from '../../../style/types'\nimport { AnimatedEvent } from '../AnimatedEvent'\nimport { AnimatedNode } from './AnimatedNode'\nimport { AnimatedObject } from './AnimatedObject'\nimport { AnimatedStyle } from './AnimatedStyle'\n\ntype Props = Readonly<Record<string, unknown>>\n\nconst flatten = (style: unknown): FlatStyle | undefined =>\n flattenStyle(style as StyleProp<FlatStyle>)\n\n// The props of one animated component: a leaf of the graph. A change of a node calls `update()`,\n// and the component writes the new values to its element. React Native takes the callback in the\n// constructor. Here the component sets it when its element mounts.\nexport class AnimatedProps extends AnimatedNode {\n private readonly nodes: readonly AnimatedNode[]\n private readonly nodeKeys: readonly string[]\n private readonly props: Props\n private callback: (() => void) | null = null\n\n constructor(inputProps: Props) {\n super()\n const nodes: AnimatedNode[] = []\n const nodeKeys: string[] = []\n const props: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(inputProps)) {\n let node: AnimatedNode | null\n if (key === 'style') {\n node = AnimatedStyle.from(flatten(value))\n } else if (value instanceof AnimatedNode) {\n node = value\n } else {\n node = AnimatedObject.from(value)\n }\n if (node === null) {\n props[key] = value\n } else {\n nodes.push(node)\n nodeKeys.push(key)\n props[key] = node\n }\n }\n this.nodes = nodes\n this.nodeKeys = nodeKeys\n this.props = props\n }\n\n setUpdateCallback(callback: (() => void) | null): void {\n this.callback = callback\n }\n\n // True when a node drives `style` and no other prop. A frame can then write the style to the\n // element with no render.\n animatesOnlyStyle(): boolean {\n return this.nodeKeys.every((key) => key === 'style')\n }\n\n override __getValue(): Props {\n const props: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(this.props)) {\n if (value instanceof AnimatedNode) props[key] = value.__getValue()\n else if (value instanceof AnimatedEvent) props[key] = value.__getHandler()\n else props[key] = value\n }\n return props\n }\n\n // `staticProps` with the current value of each node of this object. `style` comes back flat.\n __getValueWithStaticProps(staticProps: Props): Record<string, unknown> {\n const props: Record<string, unknown> = { ...staticProps }\n for (const key of Object.keys(staticProps)) {\n const node = this.props[key]\n if (key === 'style') {\n props[key] = this.styleWithStaticStyle(staticProps[key])\n } else if (node instanceof AnimatedNode) {\n props[key] = node.__getValue()\n } else if (node instanceof AnimatedEvent) {\n props[key] = node.__getHandler()\n }\n }\n return props\n }\n\n // `staticStyle`, flat, with the current value of each node of the style.\n styleWithStaticStyle(staticStyle: unknown): FlatStyle | undefined {\n const node = this.props['style']\n const flatStatic = flatten(staticStyle)\n if (!(node instanceof AnimatedStyle)) return flatStatic\n // A copy, unless `flattenStyle` made a new object already.\n const style: Record<string, unknown> =\n flatStatic === undefined\n ? {}\n : flatStatic === staticStyle\n ? { ...flatStatic }\n : (flatStatic as Record<string, unknown>)\n node.__replaceAnimatedNodeWithValues(style)\n return style\n }\n\n // Only the animated props, with their values.\n override __getAnimatedValue(): Props {\n const props: Record<string, unknown> = {}\n this.nodes.forEach((node, index) => {\n props[this.nodeKeys[index] ?? ''] = node.__getAnimatedValue()\n })\n return props\n }\n\n override __attach(): void {\n for (const node of this.nodes) node.__addChild(this)\n super.__attach()\n }\n\n override __detach(): void {\n for (const node of this.nodes) node.__removeChild(this)\n super.__detach()\n }\n\n update(): void {\n this.callback?.()\n }\n}\n"],"mappings":";;;;;;;;;;;AAeA,MAAM,WAAW,UACf,aAAa,KAA6B;AAK5C,IAAa,gBAAb,cAAmC,aAAa;CAM9C,YAAY,YAAmB;EAC7B,MAAM;EAHR,KAAQ,WAAgC;EAItC,MAAM,QAAwB,CAAC;EAC/B,MAAM,WAAqB,CAAC;EAC5B,MAAM,QAAiC,CAAC;EACxC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GAAG;GACrD,IAAI;GACJ,IAAI,QAAQ,SACV,OAAO,cAAc,KAAK,QAAQ,KAAK,CAAC;QACnC,IAAI,iBAAiB,cAC1B,OAAO;QAEP,OAAO,eAAe,KAAK,KAAK;GAElC,IAAI,SAAS,MACX,MAAM,OAAO;QACR;IACL,MAAM,KAAK,IAAI;IACf,SAAS,KAAK,GAAG;IACjB,MAAM,OAAO;GACf;EACF;EACA,KAAK,QAAQ;EACb,KAAK,WAAW;EAChB,KAAK,QAAQ;CACf;CAEA,kBAAkB,UAAqC;EACrD,KAAK,WAAW;CAClB;CAIA,oBAA6B;EAC3B,OAAO,KAAK,SAAS,OAAO,QAAQ,QAAQ,OAAO;CACrD;CAEA,aAA6B;EAC3B,MAAM,QAAiC,CAAC;EACxC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,KAAK,GAClD,IAAI,iBAAiB,cAAc,MAAM,OAAO,MAAM,WAAW;OAC5D,IAAI,iBAAiB,eAAe,MAAM,OAAO,MAAM,aAAa;OACpE,MAAM,OAAO;EAEpB,OAAO;CACT;CAGA,0BAA0B,aAA6C;EACrE,MAAM,QAAiC,EAAE,GAAG,YAAY;EACxD,KAAK,MAAM,OAAO,OAAO,KAAK,WAAW,GAAG;GAC1C,MAAM,OAAO,KAAK,MAAM;GACxB,IAAI,QAAQ,SACV,MAAM,OAAO,KAAK,qBAAqB,YAAY,IAAI;QAClD,IAAI,gBAAgB,cACzB,MAAM,OAAO,KAAK,WAAW;QACxB,IAAI,gBAAgB,eACzB,MAAM,OAAO,KAAK,aAAa;EAEnC;EACA,OAAO;CACT;CAGA,qBAAqB,aAA6C;EAChE,MAAM,OAAO,KAAK,MAAM;EACxB,MAAM,aAAa,QAAQ,WAAW;EACtC,IAAI,EAAE,gBAAgB,gBAAgB,OAAO;EAE7C,MAAM,QACJ,eAAe,KAAA,IACX,CAAC,IACD,eAAe,cACb,EAAE,GAAG,WAAW,IACf;EACT,KAAK,gCAAgC,KAAK;EAC1C,OAAO;CACT;CAGA,qBAAqC;EACnC,MAAM,QAAiC,CAAC;EACxC,KAAK,MAAM,SAAS,MAAM,UAAU;GAClC,MAAM,KAAK,SAAS,UAAU,MAAM,KAAK,mBAAmB;EAC9D,CAAC;EACD,OAAO;CACT;CAEA,WAA0B;EACxB,KAAK,MAAM,QAAQ,KAAK,OAAO,KAAK,WAAW,IAAI;EACnD,MAAM,SAAS;CACjB;CAEA,WAA0B;EACxB,KAAK,MAAM,QAAQ,KAAK,OAAO,KAAK,cAAc,IAAI;EACtD,MAAM,SAAS;CACjB;CAEA,SAAe;EACb,KAAK,WAAW;CAClB;AACF"}
@@ -0,0 +1,65 @@
1
+ import { AnimatedNode } from "./AnimatedNode.js";
2
+ import { AnimatedObject } from "./AnimatedObject.js";
3
+ import { AnimatedTransform } from "./AnimatedTransform.js";
4
+ import { AnimatedWithChildren } from "./AnimatedWithChildren.js";
5
+ // src/apis/Animated/nodes/AnimatedStyle.ts
6
+ /**
7
+ * @license MIT
8
+ * A port of `Libraries/Animated/nodes/AnimatedStyle.js` of React Native, Copyright (c) Meta
9
+ * Platforms, Inc. and affiliates.
10
+ */
11
+ var AnimatedStyle = class AnimatedStyle extends AnimatedWithChildren {
12
+ static from(flatStyle) {
13
+ if (flatStyle === void 0) return null;
14
+ const nodes = [];
15
+ const style = {};
16
+ for (const [key, value] of Object.entries(flatStyle)) {
17
+ let node;
18
+ if (key === "transform" && value !== null && value !== void 0) node = AnimatedTransform.from(value);
19
+ else if (value instanceof AnimatedNode) node = value;
20
+ else node = AnimatedObject.from(value);
21
+ if (node === null) style[key] = value;
22
+ else {
23
+ nodes.push(node);
24
+ style[key] = node;
25
+ }
26
+ }
27
+ return nodes.length === 0 ? null : new AnimatedStyle(nodes, style);
28
+ }
29
+ constructor(nodes, style) {
30
+ super();
31
+ this.nodes = nodes;
32
+ this.style = style;
33
+ }
34
+ __getValue() {
35
+ const style = {};
36
+ for (const [key, value] of Object.entries(this.style)) style[key] = value instanceof AnimatedNode ? value.__getValue() : value;
37
+ return style;
38
+ }
39
+ __replaceAnimatedNodeWithValues(style) {
40
+ for (const key of Object.keys(style)) {
41
+ const node = this.style[key];
42
+ if (key === "transform" && node instanceof AnimatedTransform) {
43
+ const transforms = style[key];
44
+ style[key] = node.__getValueWithStaticTransforms(Array.isArray(transforms) ? transforms : []);
45
+ } else if (node instanceof AnimatedObject) style[key] = node.__getValueWithStaticObject(style[key]);
46
+ else if (node instanceof AnimatedNode) style[key] = node.__getValue();
47
+ }
48
+ }
49
+ __getAnimatedValue() {
50
+ const style = {};
51
+ for (const [key, value] of Object.entries(this.style)) if (value instanceof AnimatedNode) style[key] = value.__getAnimatedValue();
52
+ return style;
53
+ }
54
+ __attach() {
55
+ for (const node of this.nodes) node.__addChild(this);
56
+ super.__attach();
57
+ }
58
+ __detach() {
59
+ for (const node of this.nodes) node.__removeChild(this);
60
+ super.__detach();
61
+ }
62
+ };
63
+ export { AnimatedStyle };
64
+
65
+ //# sourceMappingURL=AnimatedStyle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimatedStyle.js","names":[],"sources":["../../../../src/apis/Animated/nodes/AnimatedStyle.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/nodes/AnimatedStyle.js` of React Native, Copyright (c) Meta\n * Platforms, Inc. and affiliates.\n */\n\nimport { AnimatedNode } from './AnimatedNode'\nimport { AnimatedObject } from './AnimatedObject'\nimport { AnimatedTransform } from './AnimatedTransform'\nimport { AnimatedWithChildren } from './AnimatedWithChildren'\n\ntype FlatStyle = Readonly<Record<string, unknown>>\n\n// React Native's web branch keeps only the animated keys and renders `[originalStyle, values]`,\n// for react-native-web. This package takes React Native's native branch: the style keeps every\n// key, so a render gives one flat object of plain values, and a frame resolves the whole style.\nexport class AnimatedStyle extends AnimatedWithChildren {\n private readonly nodes: readonly AnimatedNode[]\n private readonly style: FlatStyle\n\n // An `AnimatedStyle` when `flatStyle` holds a node, else null.\n static from(flatStyle: FlatStyle | undefined): AnimatedStyle | null {\n if (flatStyle === undefined) return null\n const nodes: AnimatedNode[] = []\n const style: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(flatStyle)) {\n let node: AnimatedNode | null\n if (key === 'transform' && value !== null && value !== undefined) {\n node = AnimatedTransform.from(value)\n } else if (value instanceof AnimatedNode) {\n node = value\n } else {\n node = AnimatedObject.from(value)\n }\n if (node === null) {\n style[key] = value\n } else {\n nodes.push(node)\n style[key] = node\n }\n }\n return nodes.length === 0 ? null : new AnimatedStyle(nodes, style)\n }\n\n constructor(nodes: readonly AnimatedNode[], style: FlatStyle) {\n super()\n this.nodes = nodes\n this.style = style\n }\n\n override __getValue(): FlatStyle {\n const style: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(this.style)) {\n style[key] = value instanceof AnimatedNode ? value.__getValue() : value\n }\n return style\n }\n\n // Puts the value of each node in `style`, at the key of that node.\n __replaceAnimatedNodeWithValues(style: Record<string, unknown>): void {\n for (const key of Object.keys(style)) {\n const node = this.style[key]\n if (key === 'transform' && node instanceof AnimatedTransform) {\n const transforms = style[key]\n style[key] = node.__getValueWithStaticTransforms(\n Array.isArray(transforms) ? transforms : [],\n )\n } else if (node instanceof AnimatedObject) {\n style[key] = node.__getValueWithStaticObject(style[key])\n } else if (node instanceof AnimatedNode) {\n style[key] = node.__getValue()\n }\n }\n }\n\n // Only the animated keys, with their values.\n override __getAnimatedValue(): FlatStyle {\n const style: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(this.style)) {\n if (value instanceof AnimatedNode) style[key] = value.__getAnimatedValue()\n }\n return style\n }\n\n override __attach(): void {\n for (const node of this.nodes) node.__addChild(this)\n super.__attach()\n }\n\n override __detach(): void {\n for (const node of this.nodes) node.__removeChild(this)\n super.__detach()\n }\n}\n"],"mappings":";;;;;;;;;;AAgBA,IAAa,gBAAb,MAAa,sBAAsB,qBAAqB;CAKtD,OAAO,KAAK,WAAwD;EAClE,IAAI,cAAc,KAAA,GAAW,OAAO;EACpC,MAAM,QAAwB,CAAC;EAC/B,MAAM,QAAiC,CAAC;EACxC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,GAAG;GACpD,IAAI;GACJ,IAAI,QAAQ,eAAe,UAAU,QAAQ,UAAU,KAAA,GACrD,OAAO,kBAAkB,KAAK,KAAK;QAC9B,IAAI,iBAAiB,cAC1B,OAAO;QAEP,OAAO,eAAe,KAAK,KAAK;GAElC,IAAI,SAAS,MACX,MAAM,OAAO;QACR;IACL,MAAM,KAAK,IAAI;IACf,MAAM,OAAO;GACf;EACF;EACA,OAAO,MAAM,WAAW,IAAI,OAAO,IAAI,cAAc,OAAO,KAAK;CACnE;CAEA,YAAY,OAAgC,OAAkB;EAC5D,MAAM;EACN,KAAK,QAAQ;EACb,KAAK,QAAQ;CACf;CAEA,aAAiC;EAC/B,MAAM,QAAiC,CAAC;EACxC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,KAAK,GAClD,MAAM,OAAO,iBAAiB,eAAe,MAAM,WAAW,IAAI;EAEpE,OAAO;CACT;CAGA,gCAAgC,OAAsC;EACpE,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GAAG;GACpC,MAAM,OAAO,KAAK,MAAM;GACxB,IAAI,QAAQ,eAAe,gBAAgB,mBAAmB;IAC5D,MAAM,aAAa,MAAM;IACzB,MAAM,OAAO,KAAK,+BAChB,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,CAC5C;GACF,OAAO,IAAI,gBAAgB,gBACzB,MAAM,OAAO,KAAK,2BAA2B,MAAM,IAAI;QAClD,IAAI,gBAAgB,cACzB,MAAM,OAAO,KAAK,WAAW;EAEjC;CACF;CAGA,qBAAyC;EACvC,MAAM,QAAiC,CAAC;EACxC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,KAAK,GAClD,IAAI,iBAAiB,cAAc,MAAM,OAAO,MAAM,mBAAmB;EAE3E,OAAO;CACT;CAEA,WAA0B;EACxB,KAAK,MAAM,QAAQ,KAAK,OAAO,KAAK,WAAW,IAAI;EACnD,MAAM,SAAS;CACjB;CAEA,WAA0B;EACxB,KAAK,MAAM,QAAQ,KAAK,OAAO,KAAK,cAAc,IAAI;EACtD,MAAM,SAAS;CACjB;AACF"}
@@ -0,0 +1,64 @@
1
+ import { AnimatedNode } from "./AnimatedNode.js";
2
+ import { AnimatedWithChildren } from "./AnimatedWithChildren.js";
3
+ // src/apis/Animated/nodes/AnimatedTransform.ts
4
+ /**
5
+ * @license MIT
6
+ * A port of `Libraries/Animated/nodes/AnimatedTransform.js` of React Native, Copyright (c) Meta
7
+ * Platforms, Inc. and affiliates.
8
+ */
9
+ const flatAnimatedNodes = (transforms) => {
10
+ const nodes = [];
11
+ for (const transform of transforms) for (const key in transform) {
12
+ const value = transform[key];
13
+ if (value instanceof AnimatedNode) nodes.push(value);
14
+ }
15
+ return nodes;
16
+ };
17
+ const mapTransforms = (transforms, fn) => transforms.map((transform) => {
18
+ const result = {};
19
+ for (const key in transform) {
20
+ const value = transform[key];
21
+ if (value instanceof AnimatedNode) result[key] = fn(value);
22
+ else if (Array.isArray(value)) result[key] = value.map((element) => element instanceof AnimatedNode ? fn(element) : element);
23
+ else if (typeof value === "object" && value !== null) {
24
+ const object = {};
25
+ for (const [name, entry] of Object.entries(value)) object[name] = entry instanceof AnimatedNode ? fn(entry) : entry;
26
+ result[key] = object;
27
+ } else result[key] = value;
28
+ }
29
+ return result;
30
+ });
31
+ var AnimatedTransform = class AnimatedTransform extends AnimatedWithChildren {
32
+ static from(transforms) {
33
+ const list = Array.isArray(transforms) ? transforms : [];
34
+ const nodes = flatAnimatedNodes(list);
35
+ return nodes.length === 0 ? null : new AnimatedTransform(nodes, list);
36
+ }
37
+ constructor(nodes, transforms) {
38
+ super();
39
+ this.nodes = nodes;
40
+ this.transforms = transforms;
41
+ }
42
+ __getValue() {
43
+ return mapTransforms(this.transforms, (node) => node.__getValue());
44
+ }
45
+ __getValueWithStaticTransforms(staticTransforms) {
46
+ const values = [];
47
+ mapTransforms(this.transforms, (node) => values.push(node.__getValue()));
48
+ return mapTransforms(staticTransforms, () => values.shift());
49
+ }
50
+ __getAnimatedValue() {
51
+ return mapTransforms(this.transforms, (node) => node.__getAnimatedValue());
52
+ }
53
+ __attach() {
54
+ for (const node of this.nodes) node.__addChild(this);
55
+ super.__attach();
56
+ }
57
+ __detach() {
58
+ for (const node of this.nodes) node.__removeChild(this);
59
+ super.__detach();
60
+ }
61
+ };
62
+ export { AnimatedTransform };
63
+
64
+ //# sourceMappingURL=AnimatedTransform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimatedTransform.js","names":[],"sources":["../../../../src/apis/Animated/nodes/AnimatedTransform.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/nodes/AnimatedTransform.js` of React Native, Copyright (c) Meta\n * Platforms, Inc. and affiliates.\n */\n\nimport { AnimatedNode } from './AnimatedNode'\nimport { AnimatedWithChildren } from './AnimatedWithChildren'\n\ntype Transform = Readonly<Record<string, unknown>>\n\nconst flatAnimatedNodes = (transforms: readonly Transform[]): AnimatedNode[] => {\n const nodes: AnimatedNode[] = []\n for (const transform of transforms) {\n for (const key in transform) {\n const value = transform[key]\n if (value instanceof AnimatedNode) nodes.push(value)\n }\n }\n return nodes\n}\n\nconst mapTransforms = (\n transforms: readonly Transform[],\n fn: (node: AnimatedNode) => unknown,\n): Transform[] =>\n transforms.map((transform) => {\n const result: Record<string, unknown> = {}\n for (const key in transform) {\n const value = transform[key]\n if (value instanceof AnimatedNode) {\n result[key] = fn(value)\n } else if (Array.isArray(value)) {\n result[key] = value.map((element: unknown) =>\n element instanceof AnimatedNode ? fn(element) : element,\n )\n } else if (typeof value === 'object' && value !== null) {\n const object: Record<string, unknown> = {}\n for (const [name, entry] of Object.entries(value)) {\n object[name] = entry instanceof AnimatedNode ? fn(entry) : entry\n }\n result[key] = object\n } else {\n result[key] = value\n }\n }\n return result\n })\n\n// A `transform` array with nodes, such as `[{ translateX: node }, { rotate: '45deg' }]`.\nexport class AnimatedTransform extends AnimatedWithChildren {\n private readonly nodes: readonly AnimatedNode[]\n private readonly transforms: readonly Transform[]\n\n // An `AnimatedTransform` when `transforms` holds a node, else null.\n static from(transforms: unknown): AnimatedTransform | null {\n const list = Array.isArray(transforms) ? (transforms as Transform[]) : []\n const nodes = flatAnimatedNodes(list)\n return nodes.length === 0 ? null : new AnimatedTransform(nodes, list)\n }\n\n constructor(nodes: readonly AnimatedNode[], transforms: readonly Transform[]) {\n super()\n this.nodes = nodes\n this.transforms = transforms\n }\n\n override __getValue(): Transform[] {\n return mapTransforms(this.transforms, (node) => node.__getValue())\n }\n\n // The values of the nodes, in order, at the places of the nodes in `staticTransforms`.\n __getValueWithStaticTransforms(staticTransforms: readonly Transform[]): Transform[] {\n const values: unknown[] = []\n mapTransforms(this.transforms, (node) => values.push(node.__getValue()))\n return mapTransforms(staticTransforms, () => values.shift())\n }\n\n override __getAnimatedValue(): Transform[] {\n return mapTransforms(this.transforms, (node) => node.__getAnimatedValue())\n }\n\n override __attach(): void {\n for (const node of this.nodes) node.__addChild(this)\n super.__attach()\n }\n\n override __detach(): void {\n for (const node of this.nodes) node.__removeChild(this)\n super.__detach()\n }\n}\n"],"mappings":";;;;;;;;AAWA,MAAM,qBAAqB,eAAqD;CAC9E,MAAM,QAAwB,CAAC;CAC/B,KAAK,MAAM,aAAa,YACtB,KAAK,MAAM,OAAO,WAAW;EAC3B,MAAM,QAAQ,UAAU;EACxB,IAAI,iBAAiB,cAAc,MAAM,KAAK,KAAK;CACrD;CAEF,OAAO;AACT;AAEA,MAAM,iBACJ,YACA,OAEA,WAAW,KAAK,cAAc;CAC5B,MAAM,SAAkC,CAAC;CACzC,KAAK,MAAM,OAAO,WAAW;EAC3B,MAAM,QAAQ,UAAU;EACxB,IAAI,iBAAiB,cACnB,OAAO,OAAO,GAAG,KAAK;OACjB,IAAI,MAAM,QAAQ,KAAK,GAC5B,OAAO,OAAO,MAAM,KAAK,YACvB,mBAAmB,eAAe,GAAG,OAAO,IAAI,OAClD;OACK,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM;GACtD,MAAM,SAAkC,CAAC;GACzC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,GAC9C,OAAO,QAAQ,iBAAiB,eAAe,GAAG,KAAK,IAAI;GAE7D,OAAO,OAAO;EAChB,OACE,OAAO,OAAO;CAElB;CACA,OAAO;AACT,CAAC;AAGH,IAAa,oBAAb,MAAa,0BAA0B,qBAAqB;CAK1D,OAAO,KAAK,YAA+C;EACzD,MAAM,OAAO,MAAM,QAAQ,UAAU,IAAK,aAA6B,CAAC;EACxE,MAAM,QAAQ,kBAAkB,IAAI;EACpC,OAAO,MAAM,WAAW,IAAI,OAAO,IAAI,kBAAkB,OAAO,IAAI;CACtE;CAEA,YAAY,OAAgC,YAAkC;EAC5E,MAAM;EACN,KAAK,QAAQ;EACb,KAAK,aAAa;CACpB;CAEA,aAAmC;EACjC,OAAO,cAAc,KAAK,aAAa,SAAS,KAAK,WAAW,CAAC;CACnE;CAGA,+BAA+B,kBAAqD;EAClF,MAAM,SAAoB,CAAC;EAC3B,cAAc,KAAK,aAAa,SAAS,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC;EACvE,OAAO,cAAc,wBAAwB,OAAO,MAAM,CAAC;CAC7D;CAEA,qBAA2C;EACzC,OAAO,cAAc,KAAK,aAAa,SAAS,KAAK,mBAAmB,CAAC;CAC3E;CAEA,WAA0B;EACxB,KAAK,MAAM,QAAQ,KAAK,OAAO,KAAK,WAAW,IAAI;EACnD,MAAM,SAAS;CACjB;CAEA,WAA0B;EACxB,KAAK,MAAM,QAAQ,KAAK,OAAO,KAAK,cAAc,IAAI;EACtD,MAAM,SAAS;CACjB;AACF"}
@@ -0,0 +1,26 @@
1
+ import { Animation, EndCallback } from "../animations/Animation.js";
2
+ import { AnimatedNodeConfig } from "./AnimatedNode.js";
3
+ import { AnimatedInterpolation, InterpolationConfigSupportedOutputType, InterpolationConfigType } from "./AnimatedInterpolation.js";
4
+ import { AnimatedWithChildren } from "./AnimatedWithChildren.js";
5
+ export type AnimatedValueConfig = Readonly<AnimatedNodeConfig & {
6
+ useNativeDriver: boolean;
7
+ }>;
8
+ export declare class AnimatedValue extends AnimatedWithChildren {
9
+ private value;
10
+ private offset;
11
+ private readonly startingValue;
12
+ private animation;
13
+ constructor(value: number, _config?: AnimatedValueConfig | null);
14
+ override __detach(): void;
15
+ override __getValue(): number;
16
+ setValue(value: number): void;
17
+ setOffset(offset: number): void;
18
+ flattenOffset(): void;
19
+ extractOffset(): void;
20
+ stopAnimation(callback?: ((value: number) => void) | null): void;
21
+ resetAnimation(callback?: ((value: number) => void) | null): void;
22
+ interpolate<OutputT extends InterpolationConfigSupportedOutputType>(config: InterpolationConfigType<OutputT>): AnimatedInterpolation<OutputT>;
23
+ animate(animation: Animation, callback: EndCallback | null | undefined): void;
24
+ private updateValue;
25
+ }
26
+ //# sourceMappingURL=AnimatedValue.d.ts.map
@@ -0,0 +1,81 @@
1
+ import { AnimatedInterpolation } from "./AnimatedInterpolation.js";
2
+ import { AnimatedWithChildren } from "./AnimatedWithChildren.js";
3
+ // src/apis/Animated/nodes/AnimatedValue.ts
4
+ /**
5
+ * @license MIT
6
+ * A port of `Libraries/Animated/nodes/AnimatedValue.js` of React Native, Copyright (c) Meta
7
+ * Platforms, Inc. and affiliates.
8
+ */
9
+ const isUpdatable = (node) => "update" in node && typeof node.update === "function";
10
+ const flushValue = (root) => {
11
+ const leaves = /* @__PURE__ */ new Set();
12
+ const findLeaves = (node) => {
13
+ if (isUpdatable(node)) leaves.add(node);
14
+ else for (const child of node.__getChildren()) findLeaves(child);
15
+ };
16
+ findLeaves(root);
17
+ for (const leaf of leaves) leaf.update();
18
+ };
19
+ var AnimatedValue = class extends AnimatedWithChildren {
20
+ constructor(value, _config) {
21
+ super();
22
+ this.offset = 0;
23
+ this.animation = null;
24
+ if (typeof value !== "number") throw new Error("AnimatedValue: Attempting to set value to undefined");
25
+ this.value = value;
26
+ this.startingValue = value;
27
+ }
28
+ __detach() {
29
+ this.stopAnimation();
30
+ super.__detach();
31
+ }
32
+ __getValue() {
33
+ return this.value + this.offset;
34
+ }
35
+ setValue(value) {
36
+ this.animation?.stop();
37
+ this.animation = null;
38
+ this.updateValue(value);
39
+ }
40
+ setOffset(offset) {
41
+ this.offset = offset;
42
+ }
43
+ flattenOffset() {
44
+ this.value += this.offset;
45
+ this.offset = 0;
46
+ }
47
+ extractOffset() {
48
+ this.offset += this.value;
49
+ this.value = 0;
50
+ }
51
+ stopAnimation(callback) {
52
+ this.animation?.stop();
53
+ this.animation = null;
54
+ callback?.(this.__getValue());
55
+ }
56
+ resetAnimation(callback) {
57
+ this.stopAnimation(callback);
58
+ this.value = this.startingValue;
59
+ }
60
+ interpolate(config) {
61
+ return new AnimatedInterpolation(this, config);
62
+ }
63
+ animate(animation, callback) {
64
+ const previous = this.animation;
65
+ previous?.stop();
66
+ this.animation = animation;
67
+ animation.start(this.value, (value) => this.updateValue(value), (result) => {
68
+ this.animation = null;
69
+ callback?.(result);
70
+ }, previous);
71
+ }
72
+ updateValue(value) {
73
+ if (value === void 0) throw new Error("AnimatedValue: Attempting to set value to undefined");
74
+ this.value = value;
75
+ flushValue(this);
76
+ this.__callListeners(this.__getValue());
77
+ }
78
+ };
79
+ export { AnimatedValue, flushValue };
80
+
81
+ //# sourceMappingURL=AnimatedValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimatedValue.js","names":[],"sources":["../../../../src/apis/Animated/nodes/AnimatedValue.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/nodes/AnimatedValue.js` of React Native, Copyright (c) Meta\n * Platforms, Inc. and affiliates.\n */\n\nimport type { Animation, EndCallback } from '../animations/Animation'\nimport type { AnimatedNode, AnimatedNodeConfig } from './AnimatedNode'\nimport { AnimatedInterpolation } from './AnimatedInterpolation'\nimport type {\n InterpolationConfigSupportedOutputType,\n InterpolationConfigType,\n} from './AnimatedInterpolation'\nimport { AnimatedWithChildren } from './AnimatedWithChildren'\n\nexport type AnimatedValueConfig = Readonly<AnimatedNodeConfig & { useNativeDriver: boolean }>\n\ntype UpdatableNode = AnimatedNode & { update: () => void }\n\nconst isUpdatable = (node: AnimatedNode): node is UpdatableNode =>\n 'update' in node && typeof node.update === 'function'\n\n// A change goes down the graph to the leaves, the nodes with `update()`: the props of an animated\n// component. Each leaf then reads its values back up the graph. A leaf under two paths updates once.\nexport const flushValue = (root: AnimatedNode): void => {\n const leaves = new Set<UpdatableNode>()\n const findLeaves = (node: AnimatedNode): void => {\n if (isUpdatable(node)) leaves.add(node)\n else for (const child of node.__getChildren()) findLeaves(child)\n }\n findLeaves(root)\n for (const leaf of leaves) leaf.update()\n}\n\nexport class AnimatedValue extends AnimatedWithChildren {\n private value: number\n private offset = 0\n private readonly startingValue: number\n private animation: Animation | null = null\n\n // `useNativeDriver` has no effect: the web runs each animation on the JavaScript driver.\n constructor(value: number, _config?: AnimatedValueConfig | null) {\n super()\n if (typeof value !== 'number') {\n throw new Error('AnimatedValue: Attempting to set value to undefined')\n }\n this.value = value\n this.startingValue = value\n }\n\n // A value that leaves the graph stops its animation.\n override __detach(): void {\n this.stopAnimation()\n super.__detach()\n }\n\n override __getValue(): number {\n return this.value + this.offset\n }\n\n setValue(value: number): void {\n this.animation?.stop()\n this.animation = null\n this.updateValue(value)\n }\n\n // As in React Native, a new offset doesn't update the graph. The next change shows it.\n setOffset(offset: number): void {\n this.offset = offset\n }\n\n flattenOffset(): void {\n this.value += this.offset\n this.offset = 0\n }\n\n extractOffset(): void {\n this.offset += this.value\n this.value = 0\n }\n\n stopAnimation(callback?: ((value: number) => void) | null): void {\n this.animation?.stop()\n this.animation = null\n callback?.(this.__getValue())\n }\n\n // As in React Native, the reset doesn't update the graph. The next change shows it.\n resetAnimation(callback?: ((value: number) => void) | null): void {\n this.stopAnimation(callback)\n this.value = this.startingValue\n }\n\n interpolate<OutputT extends InterpolationConfigSupportedOutputType>(\n config: InterpolationConfigType<OutputT>,\n ): AnimatedInterpolation<OutputT> {\n return new AnimatedInterpolation(this, config)\n }\n\n // A new animation stops the one that runs, and that one ends with `finished: false`.\n animate(animation: Animation, callback: EndCallback | null | undefined): void {\n const previous = this.animation\n previous?.stop()\n this.animation = animation\n animation.start(\n this.value,\n (value) => this.updateValue(value),\n (result) => {\n this.animation = null\n callback?.(result)\n },\n previous,\n )\n }\n\n // React Native skips the flush only for a value that the native driver moves.\n private updateValue(value: number): void {\n if (value === undefined) throw new Error('AnimatedValue: Attempting to set value to undefined')\n this.value = value\n flushValue(this)\n this.__callListeners(this.__getValue())\n }\n}\n"],"mappings":";;;;;;;;AAmBA,MAAM,eAAe,SACnB,YAAY,QAAQ,OAAO,KAAK,WAAW;AAI7C,MAAa,cAAc,SAA6B;CACtD,MAAM,yBAAS,IAAI,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A,QACF;CACF;CAGA,YAAoB,OAAqB;EACvC,IAAI,UAAU,KAAA,GAAW,MAAM,IAAI,MAAM,qDAAqD;EAC9F,KAAK,QAAQ;EACb,WAAW,IAAI;EACf,KAAK,gBAAgB,KAAK,WAAW,CAAC;CACxC;AACF"}
@@ -0,0 +1,9 @@
1
+ import { AnimatedNode } from "./AnimatedNode.js";
2
+ export declare class AnimatedWithChildren extends AnimatedNode {
3
+ private readonly children;
4
+ override __addChild(child: AnimatedNode): void;
5
+ override __removeChild(child: AnimatedNode): void;
6
+ override __getChildren(): readonly AnimatedNode[];
7
+ override __callListeners(value: unknown): void;
8
+ }
9
+ //# sourceMappingURL=AnimatedWithChildren.d.ts.map
@@ -0,0 +1,37 @@
1
+ import { warnOnce } from "../../../utils/warn.js";
2
+ import { AnimatedNode } from "./AnimatedNode.js";
3
+ // src/apis/Animated/nodes/AnimatedWithChildren.ts
4
+ /**
5
+ * @license MIT
6
+ * A port of `Libraries/Animated/nodes/AnimatedWithChildren.js` of React Native, Copyright (c) Meta
7
+ * Platforms, Inc. and affiliates.
8
+ */
9
+ var AnimatedWithChildren = class extends AnimatedNode {
10
+ constructor(..._args) {
11
+ super(..._args);
12
+ this.children = [];
13
+ }
14
+ __addChild(child) {
15
+ if (this.children.length === 0) this.__attach();
16
+ this.children.push(child);
17
+ }
18
+ __removeChild(child) {
19
+ const index = this.children.indexOf(child);
20
+ if (index === -1) {
21
+ warnOnce("animated-remove-child", "Animated: a node can't remove a child that it doesn't have.");
22
+ return;
23
+ }
24
+ this.children.splice(index, 1);
25
+ if (this.children.length === 0) this.__detach();
26
+ }
27
+ __getChildren() {
28
+ return this.children;
29
+ }
30
+ __callListeners(value) {
31
+ super.__callListeners(value);
32
+ for (const child of this.children) child.__callListeners(child.__getValue());
33
+ }
34
+ };
35
+ export { AnimatedWithChildren };
36
+
37
+ //# sourceMappingURL=AnimatedWithChildren.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimatedWithChildren.js","names":[],"sources":["../../../../src/apis/Animated/nodes/AnimatedWithChildren.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/nodes/AnimatedWithChildren.js` of React Native, Copyright (c) Meta\n * Platforms, Inc. and affiliates.\n */\n\nimport { warnOnce } from '../../../utils/warn'\nimport { AnimatedNode } from './AnimatedNode'\n\n// A node that other nodes read. A node attaches to its parents when it gets its first child, as in\n// React Native. So a node that nothing reads stays out of the graph, and its listeners don't fire\n// when its parent changes.\nexport class AnimatedWithChildren extends AnimatedNode {\n private readonly children: AnimatedNode[] = []\n\n override __addChild(child: AnimatedNode): void {\n if (this.children.length === 0) this.__attach()\n this.children.push(child)\n }\n\n override __removeChild(child: AnimatedNode): void {\n const index = this.children.indexOf(child)\n if (index === -1) {\n warnOnce(\n 'animated-remove-child',\n \"Animated: a node can't remove a child that it doesn't have.\",\n )\n return\n }\n this.children.splice(index, 1)\n if (this.children.length === 0) this.__detach()\n }\n\n override __getChildren(): readonly AnimatedNode[] {\n return this.children\n }\n\n override __callListeners(value: unknown): void {\n super.__callListeners(value)\n for (const child of this.children) child.__callListeners(child.__getValue())\n }\n}\n"],"mappings":";;;;;;;;AAYA,IAAa,uBAAb,cAA0C,aAAa;;;EACrD,KAAiB,WAA2B,CAAC;;CAE7C,WAAoB,OAA2B;EAC7C,IAAI,KAAK,SAAS,WAAW,GAAG,KAAK,SAAS;EAC9C,KAAK,SAAS,KAAK,KAAK;CAC1B;CAEA,cAAuB,OAA2B;EAChD,MAAM,QAAQ,KAAK,SAAS,QAAQ,KAAK;EACzC,IAAI,UAAU,IAAI;GAChB,SACE,yBACA,6DACF;GACA;EACF;EACA,KAAK,SAAS,OAAO,OAAO,CAAC;EAC7B,IAAI,KAAK,SAAS,WAAW,GAAG,KAAK,SAAS;CAChD;CAEA,gBAAkD;EAChD,OAAO,KAAK;CACd;CAEA,gBAAyB,OAAsB;EAC7C,MAAM,gBAAgB,KAAK;EAC3B,KAAK,MAAM,SAAS,KAAK,UAAU,MAAM,gBAAgB,MAAM,WAAW,CAAC;CAC7E;AACF"}
@@ -0,0 +1,93 @@
1
+ import { flattenStyle } from "../../style/compile.js";
2
+ import { resolveStyle } from "../../style/resolveStyle.js";
3
+ import { AnimatedEvent } from "./AnimatedEvent.js";
4
+ import { AnimatedNode } from "./nodes/AnimatedNode.js";
5
+ import { animatedNodesIn } from "./nodes/AnimatedObject.js";
6
+ import { AnimatedProps } from "./nodes/AnimatedProps.js";
7
+ import { useCallback, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
8
+ // src/apis/Animated/useAnimatedProps.ts
9
+ /**
10
+ * @license MIT
11
+ * A port of `src/private/animated/createAnimatedPropsHook.js` and
12
+ * `createAnimatedPropsMemoHook.js` of React Native, Copyright (c) Meta Platforms, Inc. and
13
+ * affiliates.
14
+ */
15
+ const ids = /* @__PURE__ */ new WeakMap();
16
+ let nextId = 1;
17
+ const idOf = (value) => {
18
+ let id = ids.get(value);
19
+ if (id === void 0) {
20
+ id = nextId++;
21
+ ids.set(value, id);
22
+ }
23
+ return id;
24
+ };
25
+ const animatedKeyOf = (props) => {
26
+ const parts = [];
27
+ for (const [name, value] of Object.entries(props)) if (name === "style") {
28
+ const flat = flattenStyle(value);
29
+ if (flat === void 0) continue;
30
+ for (const [styleName, styleValue] of Object.entries(flat)) {
31
+ const nodes = animatedNodesIn(styleValue);
32
+ if (nodes.length > 0) parts.push(`style.${styleName}:${nodes.map(idOf).join(",")}`);
33
+ }
34
+ } else if (value instanceof AnimatedNode || value instanceof AnimatedEvent) parts.push(`${name}:${idOf(value)}`);
35
+ else if (animatedNodesIn(value).length > 0) parts.push(`${name}#${idOf(value)}`);
36
+ return parts.join("|");
37
+ };
38
+ const writeStyle = (element, style, written) => {
39
+ const next = style === void 0 ? {} : resolveStyle(style);
40
+ const inline = element.style;
41
+ for (const name of written.keys()) if (next[name] === void 0) {
42
+ inline[name] = "";
43
+ written.delete(name);
44
+ }
45
+ for (const [name, value] of Object.entries(next)) if (written.get(name) !== value) {
46
+ inline[name] = value;
47
+ written.set(name, value);
48
+ }
49
+ };
50
+ const useAnimatedProps = (props) => {
51
+ const [, scheduleUpdate] = useReducer((count) => count + 1, 0);
52
+ const propsRef = useRef(props);
53
+ const elementRef = useRef(null);
54
+ const [written] = useState(() => /* @__PURE__ */ new Map());
55
+ const key = animatedKeyOf(props);
56
+ const node = useMemo(() => new AnimatedProps(props), [key]);
57
+ useInsertionEffect(() => {
58
+ propsRef.current = props;
59
+ });
60
+ useInsertionEffect(() => {
61
+ node.__attach();
62
+ return () => queueMicrotask(() => node.__detach());
63
+ }, [node]);
64
+ useLayoutEffect(() => {
65
+ const element = elementRef.current;
66
+ if (element !== null && written.size > 0) writeStyle(element, node.styleWithStaticStyle(propsRef.current["style"]), written);
67
+ });
68
+ useLayoutEffect(() => {
69
+ node.setUpdateCallback(() => {
70
+ const element = elementRef.current;
71
+ if (element !== null && node.animatesOnlyStyle()) writeStyle(element, node.styleWithStaticStyle(propsRef.current["style"]), written);
72
+ else scheduleUpdate();
73
+ });
74
+ return () => node.setUpdateCallback(null);
75
+ }, [
76
+ node,
77
+ written,
78
+ scheduleUpdate
79
+ ]);
80
+ const ref = useCallback((instance) => {
81
+ elementRef.current = instance instanceof HTMLElement ? instance : null;
82
+ return () => {
83
+ elementRef.current = null;
84
+ };
85
+ }, []);
86
+ return [{
87
+ ...node.__getValueWithStaticProps(props),
88
+ collapsable: false
89
+ }, ref];
90
+ };
91
+ export { useAnimatedProps };
92
+
93
+ //# sourceMappingURL=useAnimatedProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAnimatedProps.js","names":[],"sources":["../../../src/apis/Animated/useAnimatedProps.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `src/private/animated/createAnimatedPropsHook.js` and\n * `createAnimatedPropsMemoHook.js` of React Native, Copyright (c) Meta Platforms, Inc. and\n * affiliates.\n */\n\nimport {\n useCallback,\n useInsertionEffect,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n type RefCallback,\n} from 'react'\n\nimport { flattenStyle } from '../../style/compile'\nimport { resolveStyle } from '../../style/resolveStyle'\nimport type { FlatStyle, StyleProp } from '../../style/types'\nimport { AnimatedEvent } from './AnimatedEvent'\nimport { AnimatedNode } from './nodes/AnimatedNode'\nimport { animatedNodesIn } from './nodes/AnimatedObject'\nimport { AnimatedProps } from './nodes/AnimatedProps'\n\ntype Props = Readonly<Record<string, unknown>>\n\nconst ids = new WeakMap<object, number>()\nlet nextId = 1\n\nconst idOf = (value: object): number => {\n let id = ids.get(value)\n if (id === undefined) {\n id = nextId++\n ids.set(value, id)\n }\n return id\n}\n\n// The parts of `props` that decide the nodes of an `AnimatedProps`, as a string: each node and\n// event, with its place. Two renders with the same string share one `AnimatedProps`, so a render\n// doesn't detach and attach the graph. React Native compares the same parts.\nconst animatedKeyOf = (props: Props): string => {\n const parts: string[] = []\n for (const [name, value] of Object.entries(props)) {\n if (name === 'style') {\n const flat = flattenStyle(value as StyleProp<FlatStyle>)\n if (flat === undefined) continue\n for (const [styleName, styleValue] of Object.entries(flat)) {\n const nodes = animatedNodesIn(styleValue)\n if (nodes.length > 0) parts.push(`style.${styleName}:${nodes.map(idOf).join(',')}`)\n }\n } else if (value instanceof AnimatedNode || value instanceof AnimatedEvent) {\n parts.push(`${name}:${idOf(value)}`)\n } else if (animatedNodesIn(value).length > 0) {\n // The node of such a prop keeps the object that it came from, so a new object needs a new\n // node, as in React Native.\n parts.push(`${name}#${idOf(value as object)}`)\n }\n }\n return parts.join('|')\n}\n\n// Writes the resolved style to the inline style of the element, and only what changed since the\n// last write. The whole style resolves each time, because some keys give one CSS property\n// together: the `shadow*` keys give `boxShadow`, for example.\nconst writeStyle = (\n element: HTMLElement,\n style: FlatStyle | undefined,\n written: Map<string, string>,\n): void => {\n const next = style === undefined ? {} : resolveStyle(style)\n const inline = element.style as unknown as Record<string, string>\n for (const name of written.keys()) {\n if (next[name] === undefined) {\n inline[name] = ''\n written.delete(name)\n }\n }\n for (const [name, value] of Object.entries(next)) {\n if (written.get(name) !== value) {\n inline[name] = value\n written.set(name, value)\n }\n }\n}\n\n// A frame that changes only the style writes it to the element, with no render. A change of any\n// other prop renders the component again, as React Native does for a component with no\n// `setNativeProps`.\nexport const useAnimatedProps = <TInstance>(\n props: Props,\n): [Record<string, unknown>, RefCallback<TInstance>] => {\n const [, scheduleUpdate] = useReducer((count: number) => count + 1, 0)\n const propsRef = useRef(props)\n const elementRef = useRef<HTMLElement | null>(null)\n const [written] = useState(() => new Map<string, string>())\n\n const key = animatedKeyOf(props)\n // The node depends only on the animated parts of `props`, and `key` names each of them. With\n // `props` as a dependency, each render would make a new node.\n // oxlint-disable-next-line react/memo-dependencies, react-hooks/exhaustive-deps\n const node = useMemo(() => new AnimatedProps(props), [key])\n\n useInsertionEffect(() => {\n propsRef.current = props\n })\n\n // The detach waits for a microtask. A new node of the next render attaches first, so a value\n // that both nodes read keeps its animation. It also keeps the end callbacks of animations out\n // of the commit phase.\n useInsertionEffect(() => {\n node.__attach()\n return () => queueMicrotask(() => node.__detach())\n }, [node])\n\n // A render can bring a new static style, and `resetAnimation` changes a value with no update.\n // So an element that a frame wrote to gets the current style again after each render.\n useLayoutEffect(() => {\n const element = elementRef.current\n if (element !== null && written.size > 0) {\n writeStyle(element, node.styleWithStaticStyle(propsRef.current['style']), written)\n }\n })\n\n // React Native sets the callback when the ref attaches, so a component that ignores its `ref`\n // never updates. Here it updates with a render.\n useLayoutEffect(() => {\n node.setUpdateCallback(() => {\n const element = elementRef.current\n if (element !== null && node.animatesOnlyStyle()) {\n writeStyle(element, node.styleWithStaticStyle(propsRef.current['style']), written)\n } else {\n scheduleUpdate()\n }\n })\n return () => node.setUpdateCallback(null)\n }, [node, written, scheduleUpdate])\n\n const ref = useCallback((instance: TInstance | null) => {\n elementRef.current = instance instanceof HTMLElement ? instance : null\n return () => {\n elementRef.current = null\n }\n }, [])\n\n return [{ ...node.__getValueWithStaticProps(props), collapsable: false }, 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js` of React Native, Copyright (c) Meta Platforms, Inc. and
5
+ * affiliates. That file comes from bezier-easing (https://github.com/gre/bezier-easing), Copyright
6
+ * (c) 2014-2015 Gaëtan Renaudeau. Both are MIT.
7
+ */
8
+ const NEWTON_ITERATIONS = 4;
9
+ const NEWTON_MIN_SLOPE = .001;
10
+ const SUBDIVISION_PRECISION = 1e-7;
11
+ const SUBDIVISION_MAX_ITERATIONS = 10;
12
+ const SPLINE_TABLE_SIZE = 11;
13
+ const SAMPLE_STEP_SIZE = 1 / 10;
14
+ const a = (a1, a2) => 1 - 3 * a2 + 3 * a1;
15
+ const b = (a1, a2) => 3 * a2 - 6 * a1;
16
+ const c = (a1) => 3 * a1;
17
+ const calcBezier = (t, a1, a2) => ((a(a1, a2) * t + b(a1, a2)) * t + c(a1)) * t;
18
+ const getSlope = (t, a1, a2) => 3 * a(a1, a2) * t * t + 2 * b(a1, a2) * t + c(a1);
19
+ const binarySubdivide = (x, start, end, x1, x2) => {
20
+ let low = start;
21
+ let high = end;
22
+ let t = 0;
23
+ let currentX = 0;
24
+ let i = 0;
25
+ do {
26
+ t = low + (high - low) / 2;
27
+ currentX = calcBezier(t, x1, x2) - x;
28
+ if (currentX > 0) high = t;
29
+ else low = t;
30
+ } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
31
+ return t;
32
+ };
33
+ const newtonRaphsonIterate = (x, guess, x1, x2) => {
34
+ let t = guess;
35
+ for (let i = 0; i < NEWTON_ITERATIONS; i++) {
36
+ const slope = getSlope(t, x1, x2);
37
+ if (slope === 0) return t;
38
+ t -= (calcBezier(t, x1, x2) - x) / slope;
39
+ }
40
+ return t;
41
+ };
42
+ const bezier = (x1, y1, x2, y2) => {
43
+ if (!(x1 >= 0 && x1 <= 1 && x2 >= 0 && x2 <= 1)) throw new Error("bezier x values must be in [0, 1] range");
44
+ if (x1 === y1 && x2 === y2) return (x) => x;
45
+ const samples = new Float32Array(SPLINE_TABLE_SIZE);
46
+ for (let i = 0; i < SPLINE_TABLE_SIZE; i++) samples[i] = calcBezier(i * SAMPLE_STEP_SIZE, x1, x2);
47
+ const sample = (i) => samples[i] ?? 0;
48
+ const getTForX = (x) => {
49
+ let intervalStart = 0;
50
+ let current = 1;
51
+ const last = 10;
52
+ for (; current !== last && sample(current) <= x; current++) intervalStart += SAMPLE_STEP_SIZE;
53
+ current--;
54
+ const dist = (x - sample(current)) / (sample(current + 1) - sample(current));
55
+ const guess = intervalStart + dist * SAMPLE_STEP_SIZE;
56
+ const slope = getSlope(guess, x1, x2);
57
+ if (slope >= NEWTON_MIN_SLOPE) return newtonRaphsonIterate(x, guess, x1, x2);
58
+ if (slope === 0) return guess;
59
+ return binarySubdivide(x, intervalStart, intervalStart + SAMPLE_STEP_SIZE, x1, x2);
60
+ };
61
+ return (x) => {
62
+ if (x === 0) return 0;
63
+ if (x === 1) return 1;
64
+ return calcBezier(getTForX(x), y1, y2);
65
+ };
66
+ };
67
+ export { bezier };
68
+
69
+ //# sourceMappingURL=bezier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bezier.js","names":[],"sources":["../../../src/apis/Easing/bezier.ts"],"sourcesContent":["/**\n * @license MIT\n * A port of `Libraries/Animated/bezier.js` of React Native, Copyright (c) Meta Platforms, Inc. and\n * affiliates. That file comes from bezier-easing (https://github.com/gre/bezier-easing), Copyright\n * (c) 2014-2015 Gaëtan Renaudeau. Both are MIT.\n */\n\n// React Native's values, a trade-off between speed and precision.\nconst NEWTON_ITERATIONS = 4\nconst NEWTON_MIN_SLOPE = 0.001\nconst SUBDIVISION_PRECISION = 0.0000001\nconst SUBDIVISION_MAX_ITERATIONS = 10\n\nconst SPLINE_TABLE_SIZE = 11\nconst SAMPLE_STEP_SIZE = 1 / (SPLINE_TABLE_SIZE - 1)\n\nconst a = (a1: number, a2: number): number => 1 - 3 * a2 + 3 * a1\nconst b = (a1: number, a2: number): number => 3 * a2 - 6 * a1\nconst c = (a1: number): number => 3 * a1\n\n// x(t) from x1 and x2, or y(t) from y1 and y2.\nconst calcBezier = (t: number, a1: number, a2: number): number =>\n ((a(a1, a2) * t + b(a1, a2)) * t + c(a1)) * t\n\n// dx/dt from x1 and x2, or dy/dt from y1 and y2.\nconst getSlope = (t: number, a1: number, a2: number): number =>\n 3 * a(a1, a2) * t * t + 2 * b(a1, a2) * t + c(a1)\n\nconst binarySubdivide = (x: number, start: number, end: number, x1: number, x2: number): number => {\n let low = start\n let high = end\n let t = 0\n let currentX = 0\n let i = 0\n do {\n t = low + (high - low) / 2\n currentX = calcBezier(t, x1, x2) - x\n if (currentX > 0) high = t\n else low = t\n } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS)\n return t\n}\n\nconst newtonRaphsonIterate = (x: number, guess: number, x1: number, x2: number): number => {\n let t = guess\n for (let i = 0; i < NEWTON_ITERATIONS; i++) {\n const slope = getSlope(t, x1, x2)\n if (slope === 0) return t\n t -= (calcBezier(t, x1, x2) - x) / slope\n }\n return t\n}\n\nexport const bezier = (x1: number, y1: number, x2: number, y2: number): ((x: number) => number) => {\n if (!(x1 >= 0 && x1 <= 1 && x2 >= 0 && x2 <= 1)) {\n throw new Error('bezier x values must be in [0, 1] range')\n }\n if (x1 === y1 && x2 === y2) return (x) => x\n\n const samples = new Float32Array(SPLINE_TABLE_SIZE)\n for (let i = 0; i < SPLINE_TABLE_SIZE; i++) samples[i] = calcBezier(i * SAMPLE_STEP_SIZE, x1, x2)\n const sample = (i: number): number => samples[i] ?? 0\n\n const getTForX = (x: number): number => {\n let intervalStart = 0\n let current = 1\n const last = SPLINE_TABLE_SIZE - 1\n for (; current !== last && sample(current) <= x; current++) intervalStart += SAMPLE_STEP_SIZE\n current--\n\n const dist = (x - sample(current)) / (sample(current + 1) - sample(current))\n const guess = intervalStart + dist * SAMPLE_STEP_SIZE\n const slope = getSlope(guess, x1, x2)\n if (slope >= NEWTON_MIN_SLOPE) return newtonRaphsonIterate(x, guess, x1, x2)\n if (slope === 0) return guess\n return binarySubdivide(x, intervalStart, intervalStart + SAMPLE_STEP_SIZE, x1, x2)\n }\n\n return (x) => {\n // The solver isn't exact, so the two ends come back as they are.\n if (x === 0) return 0\n if (x === 1) return 1\n return calcBezier(getTForX(x), y1, y2)\n }\n}\n"],"mappings":";;;;;;;AAQA,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,wBAAwB;AAC9B,MAAM,6BAA6B;AAEnC,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB,IAAK;AAE9B,MAAM,KAAK,IAAY,OAAuB,IAAI,IAAI,KAAK,IAAI;AAC/D,MAAM,KAAK,IAAY,OAAuB,IAAI,KAAK,IAAI;AAC3D,MAAM,KAAK,OAAuB,IAAI;AAGtC,MAAM,cAAc,GAAW,IAAY,SACvC,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,EAAE,KAAK;AAG9C,MAAM,YAAY,GAAW,IAAY,OACvC,IAAI,EAAE,IAAI,EAAE,IAAI,IAAI,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE;AAElD,MAAM,mBAAmB,GAAW,OAAe,KAAa,IAAY,OAAuB;CACjG,IAAI,MAAM;CACV,IAAI,OAAO;CACX,IAAI,IAAI;CACR,IAAI,WAAW;CACf,IAAI,IAAI;CACR,GAAG;EACD,IAAI,OAAO,OAAO,OAAO;EACzB,WAAW,WAAW,GAAG,IAAI,EAAE,IAAI;EACnC,IAAI,WAAW,GAAG,OAAO;OACpB,MAAM;CACb,SAAS,KAAK,IAAI,QAAQ,IAAI,yBAAyB,EAAE,IAAI;CAC7D,OAAO;AACT;AAEA,MAAM,wBAAwB,GAAW,OAAe,IAAY,OAAuB;CACzF,IAAI,IAAI;CACR,KAAK,IAAI,IAAI,GAAG,IAAI,mBAAmB,KAAK;EAC1C,MAAM,QAAQ,SAAS,GAAG,IAAI,EAAE;EAChC,IAAI,UAAU,GAAG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