@nativemason/runtime 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +4 -2
- package/dist/capture.native.d.ts +3 -0
- package/dist/capture.native.js +57 -0
- package/dist/capture.web.d.ts +3 -0
- package/dist/capture.web.js +38 -0
- package/dist/components/index.d.ts +32 -0
- package/dist/components/index.js +258 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/nativewind.d.ts +2 -0
- package/dist/nativewind.js +11 -0
- package/dist/registry/index.d.ts +122 -0
- package/dist/registry/index.js +166 -0
- package/dist/scenario-hooks.d.ts +3 -0
- package/dist/scenario-hooks.js +18 -0
- package/dist/source-revisions.d.ts +5 -0
- package/dist/source-revisions.js +28 -0
- package/dist/trials.web.d.ts +3 -0
- package/dist/trials.web.js +18 -0
- package/package.json +54 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nativemason/runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Part of [NativeMason](https://github.com/gauravsaini/nativemason), a development toolkit for measured React Native layout trials and native verification.
|
|
4
|
+
|
|
5
|
+
See the repository README for setup, supported versions, instrumentation and MCP workflows. Licensed under Apache-2.0.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { captureSourceRevisions } from './source-revisions.js';
|
|
2
|
+
import { PixelRatio, Platform } from 'react-native';
|
|
3
|
+
import { BridgeFault } from '@nativemason/contracts';
|
|
4
|
+
import { nextFrame, toSpatialNodes, validateSnapshot } from './registry/index.js';
|
|
5
|
+
function measure(entry) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const timeout = setTimeout(() => reject(new BridgeFault('TIMEOUT', `Measurement timed out for ${entry.id}`)), 2000);
|
|
8
|
+
if (Platform.OS === 'ios' && entry.host.measureInWindow) {
|
|
9
|
+
entry.host.measureInWindow((x, y, width, height) => { clearTimeout(timeout); resolve({ x, y, width, height }); });
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (!entry.host.measure) {
|
|
13
|
+
clearTimeout(timeout);
|
|
14
|
+
reject(new BridgeFault('MISSING_ELEMENT', `Missing native measure ref for ${entry.id}`));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// RN0.88 measure().pageX/pageY omit the viewport offset. The legacy
|
|
18
|
+
// measureInWindow and DOM-like bounding rect include it on Android.
|
|
19
|
+
entry.host.measure((_x, _y, width, height, pageX, pageY) => { clearTimeout(timeout); resolve({ x: pageX, y: pageY, width, height }); });
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export async function captureNative(registry) {
|
|
23
|
+
if (Platform.OS !== 'android' && Platform.OS !== 'ios')
|
|
24
|
+
throw new BridgeFault('INVALID_INPUT', 'Native acceptance requires Android or iOS');
|
|
25
|
+
if (registry.autoRoot && [...registry.entries.values()].filter(entry => entry.parentId === null).length !== 1)
|
|
26
|
+
throw new BridgeFault('INVALID_INPUT', 'Automatic root requires exactly one instrumented root host');
|
|
27
|
+
if (!registry.entries.has(registry.rootId))
|
|
28
|
+
throw new BridgeFault('MISSING_ELEMENT', `Designated root ${registry.rootId} is not mounted`);
|
|
29
|
+
const generation = registry.generation;
|
|
30
|
+
let nodes = [];
|
|
31
|
+
let previous = '';
|
|
32
|
+
let stable = false;
|
|
33
|
+
let profile = registry.profile;
|
|
34
|
+
for (let frame = 0; frame < 12; frame++) {
|
|
35
|
+
await nextFrame();
|
|
36
|
+
const entries = [...registry.entries.values()];
|
|
37
|
+
const measured = await Promise.all(entries.map(async (entry) => [entry.id, await measure(entry)]));
|
|
38
|
+
const rectangles = new Map(measured);
|
|
39
|
+
const root = rectangles.get(registry.rootId);
|
|
40
|
+
if (!root)
|
|
41
|
+
throw new BridgeFault('MISSING_ELEMENT', `Designated root ${registry.rootId} disappeared`);
|
|
42
|
+
const canonicalRoot = { ...root, x: root.x - registry.windowOrigin.x, y: root.y - registry.windowOrigin.y };
|
|
43
|
+
const window = registry.profile.window;
|
|
44
|
+
profile = { ...registry.profile, root: canonicalRoot, window, pixelRatio: PixelRatio.get(), fontScale: PixelRatio.getFontScale(), orientation: window.width > window.height ? 'landscape' : 'portrait' };
|
|
45
|
+
const relative = new Map(measured.map(([id, rect]) => [id, { ...rect, x: rect.x - root.x, y: rect.y - root.y }]));
|
|
46
|
+
nodes = toSpatialNodes(registry, relative);
|
|
47
|
+
const key = JSON.stringify(nodes.map(node => ({ rect: node.rect, textFit: node.textFit })));
|
|
48
|
+
if (key === previous && generation === registry.generation) {
|
|
49
|
+
stable = true;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
previous = key;
|
|
53
|
+
}
|
|
54
|
+
const revisions = captureSourceRevisions(nodes);
|
|
55
|
+
return validateSnapshot({ schemaVersion: 1, sessionId: registry.sessionId, snapshotId: `${Platform.OS}-${Date.now()}-${++captureSequence}`, platform: Platform.OS, scenarioId: registry.scenarioId, profile, revisions, nodes, status: stable ? 'stable' : 'unstable', generation: registry.generation, ...(registry.nativeTarget ? { nativeTarget: registry.nativeTarget } : {}) });
|
|
56
|
+
}
|
|
57
|
+
let captureSequence = 0;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { captureSourceRevisions } from './source-revisions.js';
|
|
2
|
+
import { BridgeFault } from '@nativemason/contracts';
|
|
3
|
+
import { nextFrame, toSpatialNodes, validateSnapshot } from './registry/index.js';
|
|
4
|
+
export async function captureWeb(registry) {
|
|
5
|
+
if (registry.autoRoot && [...registry.entries.values()].filter(entry => entry.parentId === null).length !== 1)
|
|
6
|
+
throw new BridgeFault('INVALID_INPUT', 'Automatic root requires exactly one instrumented root host');
|
|
7
|
+
if (!registry.entries.has(registry.rootId))
|
|
8
|
+
throw new BridgeFault('MISSING_ELEMENT', `Designated root ${registry.rootId} is not mounted`);
|
|
9
|
+
let capturedProfile = registry.profile;
|
|
10
|
+
let previous = '';
|
|
11
|
+
let stable = false;
|
|
12
|
+
let nodes = [];
|
|
13
|
+
const generation = registry.generation;
|
|
14
|
+
for (let frame = 0; frame < 12; frame++) {
|
|
15
|
+
await nextFrame();
|
|
16
|
+
const root = registry.entries.get(registry.rootId)?.host.getBoundingClientRect?.();
|
|
17
|
+
if (!root)
|
|
18
|
+
throw new BridgeFault('MISSING_ELEMENT', `Designated root ${registry.rootId} has no web host`);
|
|
19
|
+
capturedProfile = { ...registry.profile, root: { x: root.x, y: root.y, width: root.width, height: root.height } };
|
|
20
|
+
const rectangles = new Map();
|
|
21
|
+
for (const entry of registry.entries.values()) {
|
|
22
|
+
const rect = entry.host.getBoundingClientRect?.();
|
|
23
|
+
if (!rect)
|
|
24
|
+
throw new BridgeFault('MISSING_ELEMENT', `No web host for ${entry.id}`);
|
|
25
|
+
rectangles.set(entry.id, { x: rect.x - root.x, y: rect.y - root.y, width: rect.width, height: rect.height });
|
|
26
|
+
}
|
|
27
|
+
nodes = toSpatialNodes(registry, rectangles);
|
|
28
|
+
const key = JSON.stringify(nodes.map(node => node.rect));
|
|
29
|
+
if (key === previous && generation === registry.generation) {
|
|
30
|
+
stable = true;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
previous = key;
|
|
34
|
+
}
|
|
35
|
+
const revisions = captureSourceRevisions(nodes);
|
|
36
|
+
return validateSnapshot({ schemaVersion: 1, sessionId: registry.sessionId, snapshotId: `web-${Date.now()}-${++captureSequence}`, platform: 'web', scenarioId: registry.scenarioId, profile: capturedProfile, revisions, nodes, status: stable ? 'stable' : 'unstable', generation: registry.generation });
|
|
37
|
+
}
|
|
38
|
+
let captureSequence = 0;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { type PropsWithChildren } from 'react';
|
|
2
|
+
import { type PressableProps, type TextProps, type ViewProps, type ImageProps, type ScrollViewProps, type TextInputProps } from 'react-native';
|
|
3
|
+
import { type DeviceProfile, type SourceRef, type NativeTarget } from '@nativemason/contracts';
|
|
4
|
+
import { type HostNode } from '../registry/index.js';
|
|
5
|
+
export interface LayoutProviderProps extends PropsWithChildren {
|
|
6
|
+
scenarioId: string;
|
|
7
|
+
rootId: string;
|
|
8
|
+
profile?: DeviceProfile;
|
|
9
|
+
nativeUrl?: string;
|
|
10
|
+
nativeToken?: string;
|
|
11
|
+
nativeTarget?: NativeTarget;
|
|
12
|
+
textProbes?: boolean;
|
|
13
|
+
/** @internal Existing root provider host supplied by withLayoutRoot. */
|
|
14
|
+
__bridgeRootHost?: HostNode | null;
|
|
15
|
+
}
|
|
16
|
+
export declare function LayoutProvider({ scenarioId, rootId, profile, nativeUrl, nativeToken, nativeTarget, textProbes, __bridgeRootHost, children }: LayoutProviderProps): React.JSX.Element;
|
|
17
|
+
export interface LayoutElementProps {
|
|
18
|
+
layoutId?: string;
|
|
19
|
+
__bridgeSource?: SourceRef;
|
|
20
|
+
__bridgeId?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const LayoutView: React.ForwardRefExoticComponent<ViewProps & LayoutElementProps & React.RefAttributes<import("node_modules/react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement.js").default>>;
|
|
23
|
+
export declare const LayoutText: React.ForwardRefExoticComponent<TextProps & LayoutElementProps & React.RefAttributes<import("node_modules/react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement.js").default>>;
|
|
24
|
+
export declare const LayoutPressable: React.ForwardRefExoticComponent<PressableProps & LayoutElementProps & React.RefAttributes<import("node_modules/react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement.js").default>>;
|
|
25
|
+
export declare const LayoutTextInput: React.ForwardRefExoticComponent<TextInputProps & LayoutElementProps & React.RefAttributes<import("node_modules/react-native/types_generated/Libraries/Components/TextInput/TextInput.flow.js")._TextInputInstance>>;
|
|
26
|
+
export declare const LayoutScrollView: React.ForwardRefExoticComponent<ScrollViewProps & LayoutElementProps & React.RefAttributes<import("react-native").ScrollViewInstance>>;
|
|
27
|
+
export declare const LayoutImage: React.ForwardRefExoticComponent<ImageProps & LayoutElementProps & React.RefAttributes<import("node_modules/react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement.js").default>>;
|
|
28
|
+
/** Development root transform with safe-area and bridge providers. */
|
|
29
|
+
export declare function withLayoutRoot<P extends object>(Component: React.ComponentType<P>, options?: Partial<LayoutProviderProps>): React.ComponentType<P> | {
|
|
30
|
+
(props: P): React.JSX.Element;
|
|
31
|
+
displayName: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { Platform, I18nManager, Image, ScrollView, TextInput, Pressable, StyleSheet, Text, View, useWindowDimensions } from 'react-native';
|
|
4
|
+
import { SafeAreaFrameContext, SafeAreaInsetsContext, SafeAreaProvider } from 'react-native-safe-area-context';
|
|
5
|
+
import { BridgeFault, NativeServerMessageSchema } from '@nativemason/contracts';
|
|
6
|
+
import { runScenarioHook } from '../scenario-hooks.js';
|
|
7
|
+
import { captureNative } from '../capture.native.js';
|
|
8
|
+
import { LayoutRegistry } from '../registry/index.js';
|
|
9
|
+
import { createBrowserRuntime } from '../trials.web.js';
|
|
10
|
+
const isDevelopment = () => typeof __DEV__ !== 'undefined' ? __DEV__ : process.env.NODE_ENV !== 'production';
|
|
11
|
+
const RegistryContext = createContext(null);
|
|
12
|
+
const ParentContext = createContext(null);
|
|
13
|
+
const TextNestingContext = createContext(false);
|
|
14
|
+
export function LayoutProvider({ scenarioId, rootId, profile, nativeUrl, nativeToken, nativeTarget, textProbes = false, __bridgeRootHost, children }) {
|
|
15
|
+
const dimensions = useWindowDimensions();
|
|
16
|
+
const safeFrame = useContext(SafeAreaFrameContext);
|
|
17
|
+
const safeInsets = useContext(SafeAreaInsetsContext) ?? { top: 0, right: 0, bottom: 0, left: 0 };
|
|
18
|
+
const width = Platform.OS === 'web' ? dimensions.width : safeFrame?.width ?? dimensions.width;
|
|
19
|
+
const height = Platform.OS === 'web' ? dimensions.height : safeFrame?.height ?? dimensions.height;
|
|
20
|
+
const fallback = { window: { width, height }, root: { x: 0, y: 0, width, height }, pixelRatio: dimensions.scale, fontScale: dimensions.fontScale, orientation: width > height ? 'landscape' : 'portrait', insets: safeInsets };
|
|
21
|
+
const registryRef = useRef(null);
|
|
22
|
+
if (!registryRef.current)
|
|
23
|
+
registryRef.current = new LayoutRegistry(scenarioId, profile ?? fallback, rootId);
|
|
24
|
+
const registry = registryRef.current;
|
|
25
|
+
const configuredTarget = nativeTarget ?? ((Platform.OS === 'android' || Platform.OS === 'ios') && process.env.EXPO_PUBLIC_LAYOUT_TARGET_ID ? { targetId: process.env.EXPO_PUBLIC_LAYOUT_TARGET_ID, platform: Platform.OS, kind: process.env.EXPO_PUBLIC_LAYOUT_TARGET_KIND === 'emulator' ? 'emulator' : process.env.EXPO_PUBLIC_LAYOUT_TARGET_KIND === 'simulator' ? 'simulator' : 'physical' } : undefined);
|
|
26
|
+
registry.nativeTarget = configuredTarget;
|
|
27
|
+
registry.textProbes = textProbes;
|
|
28
|
+
registry.autoRoot = rootId === "__nativemason_auto_root";
|
|
29
|
+
useSyncExternalStore(registry.subscribe, registry.getRevision, registry.getRevision);
|
|
30
|
+
useLayoutEffect(() => {
|
|
31
|
+
if (!isDevelopment())
|
|
32
|
+
return;
|
|
33
|
+
if (!registry.autoRoot && registry.rootId !== rootId) {
|
|
34
|
+
registry.rootId = rootId;
|
|
35
|
+
registry.generation++;
|
|
36
|
+
registry.resetTrial();
|
|
37
|
+
}
|
|
38
|
+
if (registry.scenarioId !== scenarioId) {
|
|
39
|
+
registry.scenarioId = scenarioId;
|
|
40
|
+
registry.generation++;
|
|
41
|
+
registry.resetTrial();
|
|
42
|
+
}
|
|
43
|
+
if (Platform.OS !== 'web') {
|
|
44
|
+
registry.windowOrigin = { x: safeFrame?.x ?? 0, y: safeFrame?.y ?? 0 };
|
|
45
|
+
const next = { ...fallback, insets: safeInsets };
|
|
46
|
+
if (JSON.stringify(next) !== JSON.stringify(registry.profile)) {
|
|
47
|
+
registry.profile = next;
|
|
48
|
+
registry.generation++;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
if (!isDevelopment() || !__bridgeRootHost)
|
|
54
|
+
return;
|
|
55
|
+
registry.register({ id: rootId, parentId: null, kind: 'View', role: null, styles: { flex: 1 }, source: null, dynamicStyle: false, trialable: false, host: __bridgeRootHost });
|
|
56
|
+
return () => registry.unregister(rootId, __bridgeRootHost);
|
|
57
|
+
}, [registry, rootId, __bridgeRootHost]);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!isDevelopment() || Platform.OS !== 'web')
|
|
60
|
+
return;
|
|
61
|
+
const runtime = createBrowserRuntime(registry);
|
|
62
|
+
registry.runtime = runtime;
|
|
63
|
+
const target = window;
|
|
64
|
+
if (target.__RN_LAYOUT_BRIDGE__)
|
|
65
|
+
throw new BridgeFault('INVALID_INPUT', 'Only one LayoutProvider is supported per page');
|
|
66
|
+
target.__RN_LAYOUT_BRIDGE__ = runtime;
|
|
67
|
+
return () => { if (target.__RN_LAYOUT_BRIDGE__ === runtime)
|
|
68
|
+
delete target.__RN_LAYOUT_BRIDGE__; };
|
|
69
|
+
}, [registry]);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!isDevelopment() || (Platform.OS !== 'android' && Platform.OS !== 'ios') || !nativeUrl || !nativeToken)
|
|
72
|
+
return;
|
|
73
|
+
let disposed = false;
|
|
74
|
+
let reconnect;
|
|
75
|
+
let socket;
|
|
76
|
+
const connect = () => {
|
|
77
|
+
if (disposed)
|
|
78
|
+
return;
|
|
79
|
+
socket = new WebSocket(nativeUrl);
|
|
80
|
+
socket.onopen = () => socket?.send(JSON.stringify({ type: 'hello', protocolVersion: 2, token: nativeToken, scenarioId, platform: Platform.OS, targetId: configuredTarget?.targetId ?? Platform.OS, capabilities: { textFits: textProbes, scenarioActions: true } }));
|
|
81
|
+
socket.onmessage = event => {
|
|
82
|
+
const currentSocket = socket;
|
|
83
|
+
void (async () => {
|
|
84
|
+
let requestId;
|
|
85
|
+
try {
|
|
86
|
+
const request = NativeServerMessageSchema.parse(JSON.parse(String(event.data)));
|
|
87
|
+
requestId = request.requestId;
|
|
88
|
+
registry.sessionId = request.sessionId;
|
|
89
|
+
if (request.type === 'action') {
|
|
90
|
+
await runScenarioHook(request.name, request.value);
|
|
91
|
+
currentSocket?.send(JSON.stringify({ type: 'action_result', requestId }));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const snapshot = await captureNative(registry);
|
|
95
|
+
for (const [path, hash] of Object.entries(request.expectedRevisions)) {
|
|
96
|
+
if (snapshot.revisions[path] !== hash)
|
|
97
|
+
throw new BridgeFault('STALE_SOURCE', `Native runtime has not loaded ${path}`);
|
|
98
|
+
}
|
|
99
|
+
currentSocket?.send(JSON.stringify({ type: 'snapshot', requestId, snapshot }));
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (requestId && currentSocket?.readyState === WebSocket.OPEN)
|
|
103
|
+
currentSocket.send(JSON.stringify({ type: 'error', requestId, error: { code: error instanceof BridgeFault ? error.code : 'INVALID_INPUT', message: error instanceof Error ? error.message : String(error) } }));
|
|
104
|
+
}
|
|
105
|
+
})();
|
|
106
|
+
};
|
|
107
|
+
socket.onerror = () => { };
|
|
108
|
+
socket.onclose = () => { if (!disposed)
|
|
109
|
+
reconnect = setTimeout(connect, 1000); };
|
|
110
|
+
};
|
|
111
|
+
connect();
|
|
112
|
+
return () => { disposed = true; clearTimeout(reconnect); socket?.close(); };
|
|
113
|
+
}, [nativeToken, nativeUrl, configuredTarget?.targetId, textProbes, registry, scenarioId]);
|
|
114
|
+
const insets = Platform.OS === 'web' && registry.configured ? registry.profile.insets : safeInsets;
|
|
115
|
+
return _jsx(RegistryContext.Provider, { value: isDevelopment() ? registry : null, children: _jsx(SafeAreaInsetsContext.Provider, { value: insets, children: __bridgeRootHost !== undefined ? _jsx(ParentContext.Provider, { value: rootId, children: children }) : children }) });
|
|
116
|
+
}
|
|
117
|
+
function assignRef(ref, value) {
|
|
118
|
+
if (typeof ref === 'function')
|
|
119
|
+
return ref(value);
|
|
120
|
+
if (ref)
|
|
121
|
+
ref.current = value;
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
function useRegistration(props, kind, forwarded, authoredTextProps, textSignature, resolveStyle) {
|
|
125
|
+
const registry = useContext(RegistryContext);
|
|
126
|
+
const parentId = useContext(ParentContext);
|
|
127
|
+
const instanceId = useId();
|
|
128
|
+
const sourceId = props.__bridgeId ?? (props.__bridgeSource ? `${props.__bridgeSource.path}:${props.__bridgeSource.start}` : "unmapped");
|
|
129
|
+
const baseId = parentId ? `${parentId}/${sourceId}` : sourceId;
|
|
130
|
+
const id = props.layoutId ?? props.testID ?? registry?.claimAutoId(baseId, instanceId) ?? `${baseId}#${instanceId}`;
|
|
131
|
+
useSyncExternalStore(registry?.subscribe ?? noSubscribe, registry?.getRevision ?? zeroRevision, registry?.getRevision ?? zeroRevision);
|
|
132
|
+
const hostRef = useRef(null);
|
|
133
|
+
const forwardedCleanup = useRef(undefined);
|
|
134
|
+
const registration = useRef({});
|
|
135
|
+
const dynamicStyle = typeof props.style === 'function';
|
|
136
|
+
const nativeDirection = Platform.OS === 'web' ? 'unknown' : I18nManager?.isRTL === undefined ? 'unknown' : I18nManager.isRTL ? 'rtl' : 'ltr';
|
|
137
|
+
const accessibility = { direction: nativeDirection, directionSource: Platform.OS === 'web' || nativeDirection === 'unknown' ? 'unknown' : 'native-global', ...(typeof props.accessibilityLabel === 'string' ? { authoredLabel: props.accessibilityLabel } : {}), ...(typeof props.accessibilityHint === 'string' ? { authoredHint: props.accessibilityHint } : {}), ...(typeof props.accessible === 'boolean' ? { accessible: props.accessible } : {}), ...(typeof props.focusable === 'boolean' ? { focusable: props.focusable } : {}), ...(props.accessibilityElementsHidden === true || props.importantForAccessibility === 'no-hide-descendants' ? { hidden: true } : {}), ...(typeof props.disabled === 'boolean' ? { disabled: props.disabled } : props.accessibilityState?.disabled !== undefined ? { disabled: props.accessibilityState.disabled } : {}) };
|
|
138
|
+
registration.current = { id, parentId, kind, accessibility, resolveStyle, ...(props.layoutId || props.testID ? {} : { autoIdBase: baseId, autoIdInstance: instanceId }), role: typeof props.accessibilityRole === 'string' ? props.accessibilityRole : kind === 'Pressable' ? 'button' : null, styles: dynamicStyle ? {} : StyleSheet.flatten(props.style) ?? {}, source: props.__bridgeSource ?? null, dynamicStyle, ...(textSignature ? { authoredSignature: textSignature, measurementSignature: textSignature + JSON.stringify(registry?.overrides.get(id)) } : {}), ...(authoredTextProps ? { authoredTextProps } : {}) };
|
|
139
|
+
const ref = useCallback((host) => {
|
|
140
|
+
if (hostRef.current && registry)
|
|
141
|
+
registry.unregister(id, hostRef.current);
|
|
142
|
+
hostRef.current = host;
|
|
143
|
+
if (host && registry)
|
|
144
|
+
registry.register({ ...registration.current, host });
|
|
145
|
+
if (forwardedCleanup.current) {
|
|
146
|
+
forwardedCleanup.current();
|
|
147
|
+
forwardedCleanup.current = undefined;
|
|
148
|
+
}
|
|
149
|
+
else if (!host)
|
|
150
|
+
assignRef(forwarded, null);
|
|
151
|
+
if (host) {
|
|
152
|
+
const cleanup = assignRef(forwarded, host);
|
|
153
|
+
if (typeof cleanup === 'function')
|
|
154
|
+
forwardedCleanup.current = cleanup;
|
|
155
|
+
}
|
|
156
|
+
}, [forwarded, id, registry]);
|
|
157
|
+
useLayoutEffect(() => { if (registry && hostRef.current)
|
|
158
|
+
registry.register({ ...registration.current, host: hostRef.current }); });
|
|
159
|
+
return { ref, id, override: registry?.overrides.get(id), registry };
|
|
160
|
+
}
|
|
161
|
+
const noSubscribe = () => () => { };
|
|
162
|
+
const zeroRevision = () => 0;
|
|
163
|
+
export const LayoutView = forwardRef(function LayoutView({ layoutId, __bridgeSource, __bridgeId, children, ...props }, forwarded) {
|
|
164
|
+
const { ref, id, override } = useRegistration({ ...props, layoutId, __bridgeSource, __bridgeId }, 'View', forwarded);
|
|
165
|
+
return _jsx(ParentContext.Provider, { value: id, children: _jsx(View, { ...props, collapsable: isDevelopment() ? false : props.collapsable, ref: ref, style: override ? [props.style, override] : props.style, children: children }) });
|
|
166
|
+
});
|
|
167
|
+
export const LayoutText = forwardRef(function LayoutText({ layoutId, __bridgeSource, __bridgeId, children, ...props }, forwarded) {
|
|
168
|
+
const nestedText = useContext(TextNestingContext);
|
|
169
|
+
const flattened = StyleSheet.flatten(props.style) ?? {};
|
|
170
|
+
const authoredTextProps = {
|
|
171
|
+
...(typeof flattened.fontSize === 'number' ? { fontSize: flattened.fontSize } : {}),
|
|
172
|
+
...(typeof flattened.lineHeight === 'number' ? { lineHeight: flattened.lineHeight } : {}),
|
|
173
|
+
...(typeof props.numberOfLines === 'number' && props.numberOfLines > 0 ? { numberOfLines: props.numberOfLines } : {}),
|
|
174
|
+
...(typeof props.allowFontScaling === 'boolean' ? { allowFontScaling: props.allowFontScaling } : {}),
|
|
175
|
+
...(props.ellipsizeMode ? { ellipsizeMode: props.ellipsizeMode } : {}),
|
|
176
|
+
};
|
|
177
|
+
const { ref, id, override, registry } = useRegistration({ ...props, layoutId, __bridgeSource, __bridgeId }, 'Text', forwarded, authoredTextProps, JSON.stringify([typeof children === 'string' || typeof children === 'number' ? children : 'unsupported', flattened, authoredTextProps]));
|
|
178
|
+
const effectiveTextStyle = StyleSheet.flatten([props.style, override]) ?? {};
|
|
179
|
+
const [box, setBox] = useState({ width: 0, height: 0 });
|
|
180
|
+
const [full, setFull] = useState(null);
|
|
181
|
+
const [limited, setLimited] = useState();
|
|
182
|
+
const plain = typeof children === 'string' || typeof children === 'number';
|
|
183
|
+
const comparableText = !props.adjustsFontSizeToFit && props.minimumFontScale === undefined;
|
|
184
|
+
const signature = JSON.stringify([plain ? children : null, flattened, box.width, props.numberOfLines, props.allowFontScaling, props.maxFontSizeMultiplier, props.textBreakStrategy, props.android_hyphenationFrequency, props.lineBreakStrategyIOS, props.dynamicTypeRamp, comparableText, override, registry?.profile.fontScale]);
|
|
185
|
+
const previousSignature = useRef(signature);
|
|
186
|
+
useLayoutEffect(() => {
|
|
187
|
+
if (previousSignature.current !== signature) {
|
|
188
|
+
previousSignature.current = signature;
|
|
189
|
+
setFull(null);
|
|
190
|
+
setLimited(undefined);
|
|
191
|
+
}
|
|
192
|
+
}, [signature]);
|
|
193
|
+
useLayoutEffect(() => {
|
|
194
|
+
if (!registry?.textProbes || Platform.OS === 'web' || nestedText || !plain || !comparableText || typeof effectiveTextStyle.fontSize !== 'number' || !box.width || !full || full.signature !== signature) {
|
|
195
|
+
registry?.updateTextFit(id, { status: 'unavailable', reason: 'Requires an enabled probe, plain non-nested text, explicit fontSize, supported sizing props, and settled native measurements' });
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
registry.updateTextFit(id, { status: 'supported', fullLineCount: full.lineCount, ...(limited === undefined ? {} : { limitedLineCount: limited }), fullHeight: full.height, availableHeight: Math.max(0, box.height - (typeof effectiveTextStyle.paddingBottom === "number" ? effectiveTextStyle.paddingBottom : typeof effectiveTextStyle.paddingVertical === "number" ? effectiveTextStyle.paddingVertical : typeof effectiveTextStyle.padding === "number" ? effectiveTextStyle.padding : 0)) });
|
|
199
|
+
}, [registry, id, plain, comparableText, nestedText, effectiveTextStyle.fontSize, box.width, box.height, full, limited, signature]);
|
|
200
|
+
const onTextLayout = event => {
|
|
201
|
+
registry?.updateTextMetrics(id, event.nativeEvent.lines.length);
|
|
202
|
+
setLimited(event.nativeEvent.lines.length);
|
|
203
|
+
props.onTextLayout?.(event);
|
|
204
|
+
};
|
|
205
|
+
const onLayout = event => {
|
|
206
|
+
const { width, height } = event.nativeEvent.layout;
|
|
207
|
+
setBox(current => current.width === width && current.height === height ? current : { width, height });
|
|
208
|
+
props.onLayout?.(event);
|
|
209
|
+
};
|
|
210
|
+
const probe = isDevelopment() && Platform.OS !== 'web' && registry?.textProbes && !nestedText && plain && comparableText && typeof effectiveTextStyle.fontSize === 'number' && box.width > 0;
|
|
211
|
+
return _jsx(ParentContext.Provider, { value: id, children: _jsxs(TextNestingContext.Provider, { value: true, children: [_jsx(Text, { ...props, onLayout: isDevelopment() ? onLayout : props.onLayout, onTextLayout: isDevelopment() ? onTextLayout : props.onTextLayout, ref: ref, style: override ? [props.style, override] : props.style, children: children }), probe ? _jsx(Text, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", pointerEvents: "none", allowFontScaling: props.allowFontScaling, maxFontSizeMultiplier: props.maxFontSizeMultiplier, textBreakStrategy: props.textBreakStrategy, android_hyphenationFrequency: props.android_hyphenationFrequency, lineBreakStrategyIOS: props.lineBreakStrategyIOS, dynamicTypeRamp: props.dynamicTypeRamp, style: [props.style, override, { position: 'absolute', opacity: 0, width: box.width, height: undefined, minHeight: undefined, maxHeight: undefined, flex: 0 }], onTextLayout: event => { const lines = event.nativeEvent.lines; const height = lines.reduce((max, line) => Math.max(max, line.y + line.height), 0); setFull({ signature, lineCount: lines.length, height }); }, children: children }, signature) : null] }) });
|
|
212
|
+
});
|
|
213
|
+
export const LayoutPressable = forwardRef(function LayoutPressable({ layoutId, __bridgeSource, __bridgeId, children, ...props }, forwarded) {
|
|
214
|
+
const currentStyle = useRef(undefined);
|
|
215
|
+
const readStyle = useCallback(() => currentStyle.current, []);
|
|
216
|
+
const { ref, id, override } = useRegistration({ ...props, layoutId, __bridgeSource, __bridgeId }, 'Pressable', forwarded, undefined, undefined, readStyle);
|
|
217
|
+
const originalStyle = props.style;
|
|
218
|
+
let style = originalStyle;
|
|
219
|
+
if (isDevelopment() && typeof originalStyle === 'function')
|
|
220
|
+
style = (state) => {
|
|
221
|
+
const resolved = originalStyle(state);
|
|
222
|
+
currentStyle.current = { pressed: state.pressed, styles: StyleSheet.flatten(resolved) ?? {} };
|
|
223
|
+
return override ? [resolved, override] : resolved;
|
|
224
|
+
};
|
|
225
|
+
else if (override)
|
|
226
|
+
style = typeof originalStyle === 'function' ? (state) => [originalStyle(state), override] : [originalStyle, override];
|
|
227
|
+
return _jsx(ParentContext.Provider, { value: id, children: _jsx(Pressable, { ...props, ref: ref, style: style, children: children }) });
|
|
228
|
+
});
|
|
229
|
+
export const LayoutTextInput = forwardRef(function LayoutTextInput({ layoutId, __bridgeSource, __bridgeId, ...props }, forwarded) {
|
|
230
|
+
const { ref, override } = useRegistration({ ...props, layoutId, __bridgeSource, __bridgeId }, 'TextInput', forwarded);
|
|
231
|
+
return _jsx(TextInput, { ...props, ref: ref, style: override ? [props.style, override] : props.style });
|
|
232
|
+
});
|
|
233
|
+
export const LayoutScrollView = forwardRef(function LayoutScrollView({ layoutId, __bridgeSource, __bridgeId, children, ...props }, forwarded) {
|
|
234
|
+
const { ref, id, override } = useRegistration({ ...props, layoutId, __bridgeSource, __bridgeId }, 'ScrollView', forwarded);
|
|
235
|
+
return _jsx(ParentContext.Provider, { value: id, children: _jsx(ScrollView, { ...props, ref: ref, style: override ? [props.style, override] : props.style, children: children }) });
|
|
236
|
+
});
|
|
237
|
+
export const LayoutImage = forwardRef(function LayoutImage({ layoutId, __bridgeSource, __bridgeId, ...props }, forwarded) {
|
|
238
|
+
const { ref, override } = useRegistration({ ...props, layoutId, __bridgeSource, __bridgeId }, 'Image', forwarded);
|
|
239
|
+
return _jsx(Image, { ...props, ref: ref, style: override ? [props.style, override] : props.style });
|
|
240
|
+
});
|
|
241
|
+
/** Development root transform with safe-area and bridge providers. */
|
|
242
|
+
export function withLayoutRoot(Component, options = {}) {
|
|
243
|
+
if (!isDevelopment())
|
|
244
|
+
return Component;
|
|
245
|
+
function InstrumentedRoot(props) {
|
|
246
|
+
const [host, setHost] = useState(null);
|
|
247
|
+
const rootRef = useCallback((value) => { if (value === null) {
|
|
248
|
+
setHost(null);
|
|
249
|
+
return;
|
|
250
|
+
} if (typeof value === 'object' && value !== null && (('measure' in value && typeof value.measure === 'function') || ('getBoundingClientRect' in value && typeof value.getBoundingClientRect === 'function'))) {
|
|
251
|
+
setHost(value);
|
|
252
|
+
return;
|
|
253
|
+
} throw new BridgeFault('MISSING_ELEMENT', 'Safe-area provider did not expose a measurable root host'); }, []);
|
|
254
|
+
return _jsx(SafeAreaProvider, { ref: rootRef, children: _jsx(LayoutProvider, { ...options, rootId: options.rootId ?? '__nativemason_app_root', __bridgeRootHost: options.rootId ? undefined : host, scenarioId: options.scenarioId ?? (typeof window !== 'undefined' && window.location ? new URLSearchParams(window.location.search).get('scenario') : null) ?? process.env.EXPO_PUBLIC_LAYOUT_SCENARIO ?? 'default', nativeUrl: options.nativeUrl ?? process.env.EXPO_PUBLIC_LAYOUT_NATIVE_URL, nativeToken: options.nativeToken ?? process.env.EXPO_PUBLIC_LAYOUT_NATIVE_TOKEN, children: _jsx(Component, { ...props }) }) });
|
|
255
|
+
}
|
|
256
|
+
InstrumentedRoot.displayName = 'NativeMasonRoot';
|
|
257
|
+
return InstrumentedRoot;
|
|
258
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { LayoutProvider, LayoutView, LayoutText, LayoutPressable, LayoutTextInput, LayoutScrollView, LayoutImage, withLayoutRoot } from './components/index.js';
|
|
2
|
+
export type { LayoutProviderProps, LayoutElementProps } from './components/index.js';
|
|
3
|
+
export { registerScenarioHook } from './scenario-hooks.js';
|
|
4
|
+
export { registerSourceRevision } from './source-revisions.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { LayoutProvider, LayoutView, LayoutText, LayoutPressable, LayoutTextInput, LayoutScrollView, LayoutImage, withLayoutRoot } from './components/index.js';
|
|
2
|
+
export { registerScenarioHook } from './scenario-hooks.js';
|
|
3
|
+
export { registerSourceRevision } from './source-revisions.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { cssInterop } from 'nativewind';
|
|
2
|
+
import { LayoutImage, LayoutPressable, LayoutScrollView, LayoutText, LayoutTextInput, LayoutView } from './components/index.js';
|
|
3
|
+
// Import this optional entry once after NativeWind configuration. It keeps
|
|
4
|
+
// className resolution active when development transforms replace RN hosts.
|
|
5
|
+
cssInterop(LayoutView, { className: 'style' });
|
|
6
|
+
cssInterop(LayoutText, { className: 'style' });
|
|
7
|
+
cssInterop(LayoutPressable, { className: 'style' });
|
|
8
|
+
cssInterop(LayoutTextInput, { className: 'style' });
|
|
9
|
+
cssInterop(LayoutImage, { className: 'style' });
|
|
10
|
+
cssInterop(LayoutScrollView, { className: 'style', contentContainerClassName: 'contentContainerStyle' });
|
|
11
|
+
export { LayoutImage, LayoutPressable, LayoutScrollView, LayoutText, LayoutTextInput, LayoutView };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { type SpatialSnapshot, type BrowserRuntime, type DeviceProfile, type RnStylePatch, type SourceRef, type SpatialNode, type TextFitEvidence, type LayoutMutation, type NativeTarget } from '@nativemason/contracts';
|
|
2
|
+
export interface HostNode {
|
|
3
|
+
getBoundingClientRect?: () => {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
measure?: (callback: (x: number, y: number, width: number, height: number, pageX: number, pageY: number) => void) => void;
|
|
10
|
+
measureInWindow?: (callback: (x: number, y: number, width: number, height: number) => void) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface Registration {
|
|
13
|
+
id: string;
|
|
14
|
+
parentId: string | null;
|
|
15
|
+
kind: SpatialNode['kind'];
|
|
16
|
+
role: string | null;
|
|
17
|
+
styles: Record<string, unknown>;
|
|
18
|
+
source: SourceRef | null;
|
|
19
|
+
dynamicStyle: boolean;
|
|
20
|
+
accessibility?: SpatialNode['accessibility'];
|
|
21
|
+
resolveStyle?: () => {
|
|
22
|
+
styles: Record<string, unknown>;
|
|
23
|
+
pressed: boolean;
|
|
24
|
+
} | undefined;
|
|
25
|
+
authoredTextProps?: SpatialNode['authoredTextProps'];
|
|
26
|
+
measuredLineCount?: number;
|
|
27
|
+
textFit?: TextFitEvidence;
|
|
28
|
+
measurementSignature?: string;
|
|
29
|
+
authoredSignature?: string;
|
|
30
|
+
trialable?: boolean;
|
|
31
|
+
autoIdBase?: string;
|
|
32
|
+
autoIdInstance?: string;
|
|
33
|
+
host: HostNode;
|
|
34
|
+
}
|
|
35
|
+
export declare class LayoutRegistry {
|
|
36
|
+
readonly entries: Map<string, Registration>;
|
|
37
|
+
readonly overrides: Map<string, {
|
|
38
|
+
flex?: number | undefined;
|
|
39
|
+
flexWrap?: "wrap" | "nowrap" | "wrap-reverse" | undefined;
|
|
40
|
+
alignContent?: "center" | "flex-start" | "flex-end" | "stretch" | "space-between" | "space-around" | undefined;
|
|
41
|
+
position?: "relative" | "absolute" | "static" | undefined;
|
|
42
|
+
top?: number | undefined;
|
|
43
|
+
bottom?: number | undefined;
|
|
44
|
+
left?: number | undefined;
|
|
45
|
+
right?: number | undefined;
|
|
46
|
+
start?: number | undefined;
|
|
47
|
+
end?: number | undefined;
|
|
48
|
+
aspectRatio?: number | undefined;
|
|
49
|
+
paddingStart?: number | undefined;
|
|
50
|
+
paddingEnd?: number | undefined;
|
|
51
|
+
marginStart?: number | undefined;
|
|
52
|
+
marginEnd?: number | undefined;
|
|
53
|
+
fontSize?: number | undefined;
|
|
54
|
+
lineHeight?: number | undefined;
|
|
55
|
+
fontFamily?: string | undefined;
|
|
56
|
+
fontWeight?: "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | undefined;
|
|
57
|
+
flexDirection?: "column" | "row" | "row-reverse" | "column-reverse" | undefined;
|
|
58
|
+
justifyContent?: "center" | "flex-start" | "flex-end" | "space-between" | "space-around" | "space-evenly" | undefined;
|
|
59
|
+
alignItems?: "center" | "flex-start" | "flex-end" | "stretch" | "baseline" | undefined;
|
|
60
|
+
alignSelf?: "center" | "flex-start" | "flex-end" | "stretch" | "baseline" | "auto" | undefined;
|
|
61
|
+
flexGrow?: number | undefined;
|
|
62
|
+
flexShrink?: number | undefined;
|
|
63
|
+
width?: string | number | undefined;
|
|
64
|
+
height?: string | number | undefined;
|
|
65
|
+
minWidth?: number | undefined;
|
|
66
|
+
maxWidth?: number | undefined;
|
|
67
|
+
minHeight?: number | undefined;
|
|
68
|
+
maxHeight?: number | undefined;
|
|
69
|
+
gap?: number | undefined;
|
|
70
|
+
rowGap?: number | undefined;
|
|
71
|
+
columnGap?: number | undefined;
|
|
72
|
+
padding?: number | undefined;
|
|
73
|
+
paddingHorizontal?: number | undefined;
|
|
74
|
+
paddingVertical?: number | undefined;
|
|
75
|
+
paddingTop?: number | undefined;
|
|
76
|
+
paddingBottom?: number | undefined;
|
|
77
|
+
paddingLeft?: number | undefined;
|
|
78
|
+
paddingRight?: number | undefined;
|
|
79
|
+
margin?: number | undefined;
|
|
80
|
+
marginHorizontal?: number | undefined;
|
|
81
|
+
marginVertical?: number | undefined;
|
|
82
|
+
marginTop?: number | undefined;
|
|
83
|
+
marginBottom?: number | undefined;
|
|
84
|
+
marginLeft?: number | undefined;
|
|
85
|
+
marginRight?: number | undefined;
|
|
86
|
+
}>;
|
|
87
|
+
readonly listeners: Set<() => void>;
|
|
88
|
+
generation: number;
|
|
89
|
+
revision: number;
|
|
90
|
+
sessionId: string;
|
|
91
|
+
scenarioId: string;
|
|
92
|
+
profile: DeviceProfile;
|
|
93
|
+
rootId: string;
|
|
94
|
+
windowOrigin: {
|
|
95
|
+
x: number;
|
|
96
|
+
y: number;
|
|
97
|
+
};
|
|
98
|
+
configured: boolean;
|
|
99
|
+
nativeTarget?: NativeTarget;
|
|
100
|
+
textProbes: boolean;
|
|
101
|
+
autoRoot: boolean;
|
|
102
|
+
private readonly autoIds;
|
|
103
|
+
claimAutoId(base: string, instance: string): string;
|
|
104
|
+
runtime?: BrowserRuntime;
|
|
105
|
+
constructor(scenarioId: string, profile: DeviceProfile, rootId: string);
|
|
106
|
+
subscribe: (listener: () => void) => () => void;
|
|
107
|
+
getRevision: () => number;
|
|
108
|
+
notify(): void;
|
|
109
|
+
register(entry: Registration): void;
|
|
110
|
+
unregister(id: string, host: HostNode): void;
|
|
111
|
+
updateTextMetrics(id: string, measuredLineCount: number): void;
|
|
112
|
+
updateTextFit(id: string, textFit: TextFitEvidence): void;
|
|
113
|
+
setTrialBatch(mutations: readonly LayoutMutation[]): void;
|
|
114
|
+
configure(input: Parameters<BrowserRuntime['configure']>[0]): void;
|
|
115
|
+
setTrial(id: string, patch: RnStylePatch): void;
|
|
116
|
+
resetTrial(): void;
|
|
117
|
+
}
|
|
118
|
+
export declare const nextFrame: () => Promise<void>;
|
|
119
|
+
export declare function settleReact(): Promise<void>;
|
|
120
|
+
export declare function toSpatialNodes(registry: LayoutRegistry, rectangles: Map<string, SpatialNode['rect']>): SpatialNode[];
|
|
121
|
+
/** Boundary validation preserves the frozen machine-readable failure contract. */
|
|
122
|
+
export declare function validateSnapshot(input: unknown): SpatialSnapshot;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { BridgeFault, SpatialSnapshotSchema } from '@nativemason/contracts';
|
|
2
|
+
export class LayoutRegistry {
|
|
3
|
+
entries = new Map();
|
|
4
|
+
overrides = new Map();
|
|
5
|
+
listeners = new Set();
|
|
6
|
+
generation = 0;
|
|
7
|
+
revision = 0;
|
|
8
|
+
sessionId = 'unconfigured';
|
|
9
|
+
scenarioId;
|
|
10
|
+
profile;
|
|
11
|
+
rootId;
|
|
12
|
+
windowOrigin = { x: 0, y: 0 };
|
|
13
|
+
configured = false;
|
|
14
|
+
nativeTarget;
|
|
15
|
+
textProbes = false;
|
|
16
|
+
autoRoot = false;
|
|
17
|
+
autoIds = new Map();
|
|
18
|
+
claimAutoId(base, instance) {
|
|
19
|
+
let claims = this.autoIds.get(base);
|
|
20
|
+
if (!claims) {
|
|
21
|
+
claims = new Map();
|
|
22
|
+
this.autoIds.set(base, claims);
|
|
23
|
+
}
|
|
24
|
+
const existing = claims.get(instance);
|
|
25
|
+
if (existing)
|
|
26
|
+
return existing;
|
|
27
|
+
const id = claims.size ? `${base}#${instance}` : base;
|
|
28
|
+
claims.set(instance, id);
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
runtime;
|
|
32
|
+
constructor(scenarioId, profile, rootId) {
|
|
33
|
+
this.scenarioId = scenarioId;
|
|
34
|
+
this.profile = profile;
|
|
35
|
+
this.rootId = rootId;
|
|
36
|
+
}
|
|
37
|
+
subscribe = (listener) => {
|
|
38
|
+
this.listeners.add(listener);
|
|
39
|
+
return () => { this.listeners.delete(listener); };
|
|
40
|
+
};
|
|
41
|
+
getRevision = () => this.revision;
|
|
42
|
+
notify() {
|
|
43
|
+
this.revision++;
|
|
44
|
+
this.listeners.forEach(listener => listener());
|
|
45
|
+
}
|
|
46
|
+
register(entry) {
|
|
47
|
+
if (entry.autoIdBase && entry.autoIdInstance) {
|
|
48
|
+
let claims = this.autoIds.get(entry.autoIdBase);
|
|
49
|
+
if (!claims) {
|
|
50
|
+
claims = new Map();
|
|
51
|
+
this.autoIds.set(entry.autoIdBase, claims);
|
|
52
|
+
}
|
|
53
|
+
claims.set(entry.autoIdInstance, entry.id);
|
|
54
|
+
}
|
|
55
|
+
const old = this.entries.get(entry.id);
|
|
56
|
+
if (this.autoRoot && entry.parentId === null && !this.entries.has(this.rootId))
|
|
57
|
+
this.rootId = entry.id;
|
|
58
|
+
if (old && old.host !== entry.host)
|
|
59
|
+
throw new BridgeFault('DUPLICATE_ELEMENT', `Duplicate layoutId: ${entry.id}`);
|
|
60
|
+
const comparable = (value) => ({ ...value, host: null, measuredLineCount: undefined, textFit: undefined, measurementSignature: undefined });
|
|
61
|
+
if (!old || JSON.stringify(comparable(old)) !== JSON.stringify(comparable(entry)))
|
|
62
|
+
this.generation++;
|
|
63
|
+
const preserve = old?.measurementSignature === entry.measurementSignature;
|
|
64
|
+
this.entries.set(entry.id, { ...entry, ...(preserve && old?.measuredLineCount !== undefined ? { measuredLineCount: old.measuredLineCount } : {}), ...(preserve && old?.textFit ? { textFit: old.textFit } : {}) });
|
|
65
|
+
}
|
|
66
|
+
unregister(id, host) {
|
|
67
|
+
if (this.entries.get(id)?.host === host) {
|
|
68
|
+
const entry = this.entries.get(id);
|
|
69
|
+
if (entry.autoIdBase && entry.autoIdInstance) {
|
|
70
|
+
const claims = this.autoIds.get(entry.autoIdBase);
|
|
71
|
+
claims?.delete(entry.autoIdInstance);
|
|
72
|
+
if (!claims?.size)
|
|
73
|
+
this.autoIds.delete(entry.autoIdBase);
|
|
74
|
+
}
|
|
75
|
+
this.entries.delete(id);
|
|
76
|
+
this.generation++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
updateTextMetrics(id, measuredLineCount) {
|
|
80
|
+
const entry = this.entries.get(id);
|
|
81
|
+
if (!entry || entry.measuredLineCount === measuredLineCount)
|
|
82
|
+
return;
|
|
83
|
+
this.entries.set(id, { ...entry, measuredLineCount });
|
|
84
|
+
this.notify();
|
|
85
|
+
}
|
|
86
|
+
updateTextFit(id, textFit) {
|
|
87
|
+
const entry = this.entries.get(id);
|
|
88
|
+
if (!entry || JSON.stringify(entry.textFit) === JSON.stringify(textFit))
|
|
89
|
+
return;
|
|
90
|
+
this.entries.set(id, { ...entry, textFit });
|
|
91
|
+
this.notify();
|
|
92
|
+
}
|
|
93
|
+
setTrialBatch(mutations) {
|
|
94
|
+
const ids = new Set();
|
|
95
|
+
for (const mutation of mutations) {
|
|
96
|
+
if (this.entries.get(mutation.elementId)?.trialable === false)
|
|
97
|
+
throw new BridgeFault('UNSUPPORTED_EDIT', 'The measurement-only root does not accept style trials');
|
|
98
|
+
if (!this.entries.has(mutation.elementId))
|
|
99
|
+
throw new BridgeFault('MISSING_ELEMENT', 'Unknown layoutId: ' + mutation.elementId);
|
|
100
|
+
if (ids.has(mutation.elementId))
|
|
101
|
+
throw new BridgeFault('INVALID_INPUT', 'Duplicate mutation target');
|
|
102
|
+
ids.add(mutation.elementId);
|
|
103
|
+
}
|
|
104
|
+
this.overrides.clear();
|
|
105
|
+
for (const mutation of mutations)
|
|
106
|
+
this.overrides.set(mutation.elementId, mutation.patch);
|
|
107
|
+
this.notify();
|
|
108
|
+
}
|
|
109
|
+
configure(input) {
|
|
110
|
+
if (input.scenarioId !== this.scenarioId)
|
|
111
|
+
throw new BridgeFault('INVALID_INPUT', `Scenario mismatch: expected ${this.scenarioId}`);
|
|
112
|
+
if (JSON.stringify(input.profile) !== JSON.stringify(this.profile))
|
|
113
|
+
this.generation++;
|
|
114
|
+
this.sessionId = input.sessionId;
|
|
115
|
+
this.profile = input.profile;
|
|
116
|
+
this.configured = true;
|
|
117
|
+
this.notify();
|
|
118
|
+
}
|
|
119
|
+
setTrial(id, patch) {
|
|
120
|
+
if (!this.entries.has(id))
|
|
121
|
+
throw new BridgeFault('MISSING_ELEMENT', `Unknown layoutId: ${id}`);
|
|
122
|
+
if (this.entries.get(id)?.trialable === false)
|
|
123
|
+
throw new BridgeFault('UNSUPPORTED_EDIT', 'The measurement-only root does not accept style trials');
|
|
124
|
+
this.overrides.clear();
|
|
125
|
+
this.overrides.set(id, patch);
|
|
126
|
+
this.notify();
|
|
127
|
+
}
|
|
128
|
+
resetTrial() {
|
|
129
|
+
this.overrides.clear();
|
|
130
|
+
this.notify();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export const nextFrame = () => new Promise(resolve => {
|
|
134
|
+
if (typeof requestAnimationFrame === 'function')
|
|
135
|
+
requestAnimationFrame(() => resolve());
|
|
136
|
+
else
|
|
137
|
+
setTimeout(resolve, 16);
|
|
138
|
+
});
|
|
139
|
+
export async function settleReact() { await nextFrame(); await nextFrame(); }
|
|
140
|
+
export function toSpatialNodes(registry, rectangles) {
|
|
141
|
+
const sites = new Map();
|
|
142
|
+
for (const entry of registry.entries.values()) {
|
|
143
|
+
if (entry.source) {
|
|
144
|
+
const key = `${entry.source.path}:${entry.source.start}`;
|
|
145
|
+
sites.set(key, (sites.get(key) ?? 0) + 1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return [...registry.entries.values()].map(entry => {
|
|
149
|
+
const repeated = entry.source && (sites.get(`${entry.source.path}:${entry.source.start}`) ?? 0) > 1;
|
|
150
|
+
const editReason = !entry.source ? 'Missing build-time source metadata' : entry.dynamicStyle && entry.source.styleForm !== 'pressable-state' ? 'Dynamic style expression' : repeated ? 'Source site has multiple mounted instances' : null;
|
|
151
|
+
const rect = rectangles.get(entry.id);
|
|
152
|
+
if (!rect)
|
|
153
|
+
throw new BridgeFault('MISSING_ELEMENT', `No measurement for ${entry.id}`);
|
|
154
|
+
const resolved = entry.resolveStyle?.(), styles = { ...(resolved?.styles ?? entry.styles), ...registry.overrides.get(entry.id) }, direction = styles.direction;
|
|
155
|
+
const accessibility = entry.accessibility && (direction === 'rtl' || direction === 'ltr' ? { ...entry.accessibility, direction: direction, directionSource: 'authored' } : entry.accessibility);
|
|
156
|
+
return { id: entry.id, parentId: entry.parentId, kind: entry.kind, role: entry.role, rect, styles, source: entry.source, editable: editReason === null, editReason, ...(resolved ? { pressableState: resolved.pressed ? 'pressed' : 'rest' } : {}), ...(accessibility ? { accessibility } : {}), ...(entry.textFit ? { textFit: entry.textFit } : {}), ...(entry.authoredTextProps ? { authoredTextProps: entry.authoredTextProps } : {}), ...(entry.measuredLineCount === undefined ? {} : { measuredLineCount: entry.measuredLineCount }) };
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/** Boundary validation preserves the frozen machine-readable failure contract. */
|
|
160
|
+
export function validateSnapshot(input) {
|
|
161
|
+
const result = SpatialSnapshotSchema.safeParse(input);
|
|
162
|
+
if (result.success)
|
|
163
|
+
return result.data;
|
|
164
|
+
const stale = result.error.issues.some(issue => issue.code === 'custom' && issue.params?.bridgeCode === 'STALE_SOURCE');
|
|
165
|
+
throw new BridgeFault(stale ? 'STALE_SOURCE' : 'INVALID_INPUT', stale ? 'Mounted elements contain inconsistent source revisions' : result.error.message);
|
|
166
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Register an explicitly named development action; returns an ownership-safe cleanup. */
|
|
2
|
+
export declare function registerScenarioHook(name: string, handler: (value?: unknown) => void | Promise<void>): () => void;
|
|
3
|
+
export declare function runScenarioHook(name: string, value?: unknown): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BridgeFault } from '@nativemason/contracts';
|
|
2
|
+
const handlers = new Map();
|
|
3
|
+
/** Register an explicitly named development action; returns an ownership-safe cleanup. */
|
|
4
|
+
export function registerScenarioHook(name, handler) {
|
|
5
|
+
if (typeof __DEV__ !== 'undefined' ? !__DEV__ : process.env.NODE_ENV === 'production')
|
|
6
|
+
return () => { };
|
|
7
|
+
if (!name || handlers.has(name))
|
|
8
|
+
throw new BridgeFault('INVALID_INPUT', `Duplicate or empty scenario hook: ${name}`);
|
|
9
|
+
handlers.set(name, handler);
|
|
10
|
+
return () => { if (handlers.get(name) === handler)
|
|
11
|
+
handlers.delete(name); };
|
|
12
|
+
}
|
|
13
|
+
export async function runScenarioHook(name, value) {
|
|
14
|
+
const handler = handlers.get(name);
|
|
15
|
+
if (!handler)
|
|
16
|
+
throw new BridgeFault('INVALID_INPUT', `Scenario hook is not registered: ${name}`);
|
|
17
|
+
await handler(value);
|
|
18
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type SpatialNode, type SourceRevisions } from '@nativemason/contracts';
|
|
2
|
+
/** Called at the end of successfully evaluated development application modules. */
|
|
3
|
+
export declare function registerSourceRevision(path: string, hash: string): void;
|
|
4
|
+
export declare function loadedSourceRevisions(): SourceRevisions;
|
|
5
|
+
export declare function captureSourceRevisions(nodes: readonly SpatialNode[]): SourceRevisions;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BridgeFault } from '@nativemason/contracts';
|
|
2
|
+
const revisions = new Map();
|
|
3
|
+
/** Called at the end of successfully evaluated development application modules. */
|
|
4
|
+
export function registerSourceRevision(path, hash) {
|
|
5
|
+
if (typeof __DEV__ !== 'undefined' ? !__DEV__ : process.env.NODE_ENV === 'production')
|
|
6
|
+
return;
|
|
7
|
+
if (!path || path.startsWith('/') || path.split('/').includes('..') || !/^[a-f0-9]{64}$/.test(hash))
|
|
8
|
+
return;
|
|
9
|
+
revisions.set(path, hash);
|
|
10
|
+
}
|
|
11
|
+
export function loadedSourceRevisions() { return Object.fromEntries(revisions); }
|
|
12
|
+
export function captureSourceRevisions(nodes) {
|
|
13
|
+
const loaded = loadedSourceRevisions();
|
|
14
|
+
const result = {};
|
|
15
|
+
for (const node of nodes) {
|
|
16
|
+
if (!node.source)
|
|
17
|
+
continue;
|
|
18
|
+
if (loaded[node.source.path] && loaded[node.source.path] !== node.source.hash)
|
|
19
|
+
throw new BridgeFault('STALE_SOURCE', 'Mounted source metadata is stale: ' + node.source.path);
|
|
20
|
+
result[node.source.path] = node.source.hash;
|
|
21
|
+
for (const dependency of node.source.dependencies ?? []) {
|
|
22
|
+
if (!loaded[dependency])
|
|
23
|
+
throw new BridgeFault('STALE_SOURCE', 'Required style module has not loaded: ' + dependency);
|
|
24
|
+
result[dependency] = loaded[dependency];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RnStylePatchSchema, LayoutMutationSchema } from '@nativemason/contracts';
|
|
2
|
+
import { runScenarioHook } from './scenario-hooks.js';
|
|
3
|
+
import { captureWeb } from './capture.web.js';
|
|
4
|
+
import { settleReact } from './registry/index.js';
|
|
5
|
+
export function createBrowserRuntime(registry) {
|
|
6
|
+
return {
|
|
7
|
+
runHook: async (name, value) => { await runScenarioHook(name, value); await settleReact(); },
|
|
8
|
+
configure: input => registry.configure(input),
|
|
9
|
+
capture: () => captureWeb(registry),
|
|
10
|
+
getDiagnosticTargets: () => [...registry.entries.values()].flatMap(entry => {
|
|
11
|
+
const element = entry.host;
|
|
12
|
+
return element && typeof element === 'object' && 'nodeType' in element ? [{ id: entry.id, element }] : [];
|
|
13
|
+
}),
|
|
14
|
+
applyTrialBatch: async (mutations) => { const parsed = mutations.map(mutation => LayoutMutationSchema.parse(mutation)); registry.setTrialBatch(parsed); await settleReact(); },
|
|
15
|
+
applyTrial: async (id, patch) => { registry.setTrial(id, RnStylePatchSchema.parse(patch)); await settleReact(); },
|
|
16
|
+
resetTrial: async () => { registry.resetTrial(); await settleReact(); },
|
|
17
|
+
};
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nativemason/runtime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./nativewind": {
|
|
12
|
+
"types": "./dist/nativewind.d.ts",
|
|
13
|
+
"default": "./dist/nativewind.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.build.json"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@nativemason/contracts": "0.3.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"nativewind": "^4.2.7",
|
|
24
|
+
"react": "19.3.0",
|
|
25
|
+
"react-native": "0.88.1",
|
|
26
|
+
"react-native-safe-area-context": "~5.10.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"nativewind": "4.2.7",
|
|
30
|
+
"react": "19.3.0",
|
|
31
|
+
"react-native": "0.88.1",
|
|
32
|
+
"react-native-safe-area-context": "~5.10.1",
|
|
33
|
+
"tailwindcss": "3.4.17",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
35
|
+
},
|
|
36
|
+
"license": "Apache-2.0",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"bin",
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"README.md"
|
|
42
|
+
],
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/gauravsaini/nativemason.git",
|
|
46
|
+
"directory": "packages/runtime"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"nativewind": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public",
|
|
55
|
+
"provenance": true
|
|
56
|
+
}
|
|
6
57
|
}
|