embedded-react 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,91 +1,91 @@
1
- /*
2
- * Copyright 2026 Cory Lamming
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- // Pure LayoutAnimation config helpers — no NativeUI dependency, so they're unit-testable in plain
18
- // Node (see __tests__/layout-animation.unit.test.js). LayoutAnimation.js wires configureNext to the
19
- // bridge using these.
20
-
21
- /** RN-compatible animation type tokens. */
22
- export const Types = {
23
- spring: 'spring',
24
- linear: 'linear',
25
- easeInEaseOut: 'easeInEaseOut',
26
- easeIn: 'easeIn',
27
- easeOut: 'easeOut',
28
- keyboard: 'keyboard',
29
- };
30
-
31
- /** RN-compatible animated-property tokens (accepted for API parity; the engine tweens position). */
32
- export const Properties = {
33
- opacity: 'opacity',
34
- scaleX: 'scaleX',
35
- scaleY: 'scaleY',
36
- scaleXY: 'scaleXY',
37
- };
38
-
39
- /** Maps an RN animation-type token to an engine easing token. */
40
- function easingForType(type) {
41
- switch (type) {
42
- case Types.linear:
43
- return 'linear';
44
- case Types.easeIn:
45
- return 'easeIn';
46
- case Types.easeOut:
47
- return 'easeOut';
48
- case Types.easeInEaseOut:
49
- case Types.keyboard:
50
- default:
51
- return 'easeInOut';
52
- }
53
- }
54
-
55
- /**
56
- * Reduces an RN LayoutAnimation config ({ duration, create, update, delete }) to the engine's flat
57
- * config. The engine tweens the *position transition*, which is RN's `update`; create/delete opacity
58
- * are accepted for parity but not separately animated.
59
- */
60
- export function toEngineConfig(config) {
61
- const c = config || {};
62
- const duration = typeof c.duration === 'number' ? c.duration : 300;
63
- const update = c.update || {};
64
- const type = update.type || c.type || Types.easeInEaseOut;
65
- if (type === Types.spring) {
66
- return { type: 'spring', duration };
67
- }
68
- return { type: 'timing', duration, easing: easingForType(type) };
69
- }
70
-
71
- /** Builds an RN-shaped config (duration + create/update/delete) from a type + creation property. */
72
- export function create(duration, type = Types.easeInEaseOut, creationProp = Properties.opacity) {
73
- return {
74
- duration,
75
- create: { type, property: creationProp },
76
- update: { type },
77
- delete: { type, property: creationProp },
78
- };
79
- }
80
-
81
- /** RN-compatible preset configs. */
82
- export const Presets = {
83
- easeInEaseOut: create(300, Types.easeInEaseOut, Properties.opacity),
84
- linear: create(500, Types.linear, Properties.opacity),
85
- spring: {
86
- duration: 700,
87
- create: { type: Types.linear, property: Properties.opacity },
88
- update: { type: Types.spring, springDamping: 0.4 },
89
- delete: { type: Types.linear, property: Properties.opacity },
90
- },
91
- };
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // Pure LayoutAnimation config helpers — no NativeUI dependency, so they're unit-testable in plain
18
+ // Node (see __tests__/layout-animation.unit.test.js). LayoutAnimation.js wires configureNext to the
19
+ // bridge using these.
20
+
21
+ /** RN-compatible animation type tokens. */
22
+ export const Types = {
23
+ spring: 'spring',
24
+ linear: 'linear',
25
+ easeInEaseOut: 'easeInEaseOut',
26
+ easeIn: 'easeIn',
27
+ easeOut: 'easeOut',
28
+ keyboard: 'keyboard',
29
+ };
30
+
31
+ /** RN-compatible animated-property tokens (accepted for API parity; the engine tweens position). */
32
+ export const Properties = {
33
+ opacity: 'opacity',
34
+ scaleX: 'scaleX',
35
+ scaleY: 'scaleY',
36
+ scaleXY: 'scaleXY',
37
+ };
38
+
39
+ /** Maps an RN animation-type token to an engine easing token. */
40
+ function easingForType(type) {
41
+ switch (type) {
42
+ case Types.linear:
43
+ return 'linear';
44
+ case Types.easeIn:
45
+ return 'easeIn';
46
+ case Types.easeOut:
47
+ return 'easeOut';
48
+ case Types.easeInEaseOut:
49
+ case Types.keyboard:
50
+ default:
51
+ return 'easeInOut';
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Reduces an RN LayoutAnimation config ({ duration, create, update, delete }) to the engine's flat
57
+ * config. The engine tweens the *position transition*, which is RN's `update`; create/delete opacity
58
+ * are accepted for parity but not separately animated.
59
+ */
60
+ export function toEngineConfig(config) {
61
+ const c = config || {};
62
+ const duration = typeof c.duration === 'number' ? c.duration : 300;
63
+ const update = c.update || {};
64
+ const type = update.type || c.type || Types.easeInEaseOut;
65
+ if (type === Types.spring) {
66
+ return { type: 'spring', duration };
67
+ }
68
+ return { type: 'timing', duration, easing: easingForType(type) };
69
+ }
70
+
71
+ /** Builds an RN-shaped config (duration + create/update/delete) from a type + creation property. */
72
+ export function create(duration, type = Types.easeInEaseOut, creationProp = Properties.opacity) {
73
+ return {
74
+ duration,
75
+ create: { type, property: creationProp },
76
+ update: { type },
77
+ delete: { type, property: creationProp },
78
+ };
79
+ }
80
+
81
+ /** RN-compatible preset configs. */
82
+ export const Presets = {
83
+ easeInEaseOut: create(300, Types.easeInEaseOut, Properties.opacity),
84
+ linear: create(500, Types.linear, Properties.opacity),
85
+ spring: {
86
+ duration: 700,
87
+ create: { type: Types.linear, property: Properties.opacity },
88
+ update: { type: Types.spring, springDamping: 0.4 },
89
+ delete: { type: Types.linear, property: Properties.opacity },
90
+ },
91
+ };
@@ -1,58 +1,58 @@
1
- /*
2
- * Copyright 2026 Cory Lamming
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- // Separates a style object into the static props (passed straight to the node) and the animated
18
- // bindings (Animated.Value / interpolation, bound to the node's prop so the engine drives them).
19
- // Pure (no NativeUI), so it's unit-testable. An animated entry is anything with an `__animated`
20
- // marker — `transform: [{ translateX: value }]` entries are handled too (scale binds both axes).
21
- import { flattenStyle } from '../props.js';
22
-
23
- export function splitAnimatedStyle(style) {
24
- const staticStyle = {};
25
- const bindings = [];
26
-
27
- const flat = {};
28
- flattenStyle(style, flat);
29
-
30
- for (const key in flat) {
31
- const val = flat[key];
32
-
33
- if (key === 'transform' && Array.isArray(val)) {
34
- const staticTransform = [];
35
- for (const entry of val) {
36
- const axis = Object.keys(entry)[0];
37
- const v = entry[axis];
38
- if (v && v.__animated) {
39
- if (axis === 'scale') {
40
- bindings.push({ prop: 'scaleX', value: v });
41
- bindings.push({ prop: 'scaleY', value: v });
42
- } else {
43
- bindings.push({ prop: axis, value: v });
44
- }
45
- } else {
46
- staticTransform.push(entry);
47
- }
48
- }
49
- if (staticTransform.length > 0) staticStyle.transform = staticTransform;
50
- } else if (val && val.__animated) {
51
- bindings.push({ prop: key, value: val });
52
- } else {
53
- staticStyle[key] = val;
54
- }
55
- }
56
-
57
- return { staticStyle, bindings };
58
- }
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // Separates a style object into the static props (passed straight to the node) and the animated
18
+ // bindings (Animated.Value / interpolation, bound to the node's prop so the engine drives them).
19
+ // Pure (no NativeUI), so it's unit-testable. An animated entry is anything with an `__animated`
20
+ // marker — `transform: [{ translateX: value }]` entries are handled too (scale binds both axes).
21
+ import { flattenStyle } from '../props.js';
22
+
23
+ export function splitAnimatedStyle(style) {
24
+ const staticStyle = {};
25
+ const bindings = [];
26
+
27
+ const flat = {};
28
+ flattenStyle(style, flat);
29
+
30
+ for (const key in flat) {
31
+ const val = flat[key];
32
+
33
+ if (key === 'transform' && Array.isArray(val)) {
34
+ const staticTransform = [];
35
+ for (const entry of val) {
36
+ const axis = Object.keys(entry)[0];
37
+ const v = entry[axis];
38
+ if (v && v.__animated) {
39
+ if (axis === 'scale') {
40
+ bindings.push({ prop: 'scaleX', value: v });
41
+ bindings.push({ prop: 'scaleY', value: v });
42
+ } else {
43
+ bindings.push({ prop: axis, value: v });
44
+ }
45
+ } else {
46
+ staticTransform.push(entry);
47
+ }
48
+ }
49
+ if (staticTransform.length > 0) staticStyle.transform = staticTransform;
50
+ } else if (val && val.__animated) {
51
+ bindings.push({ prop: key, value: val });
52
+ } else {
53
+ staticStyle[key] = val;
54
+ }
55
+ }
56
+
57
+ return { staticStyle, bindings };
58
+ }
@@ -14,8 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- // usePersistentState — a useState that survives the simulator's hot reload (see /SIMULATOR.md, Phase
18
- // 3). The simulator's build transform (persist-transform.mjs) rewrites the app's plain `useState`
17
+ // usePersistentState — a useState that survives the simulator's hot reload (see
18
+ // tools/simulator/README.md). The simulator's build transform (persist-transform.mjs) rewrites the app's plain `useState`
19
19
  // into this helper, so persistence is transparent — you normally never call this directly; it's also
20
20
  // exported for explicit use. Outside the simulator (e.g., on a device, where the host doesn't install
21
21
  // `__erPersist`) it is exactly useState, so the same app code runs everywhere.