@hozo/primitives 0.1.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 +21 -0
- package/README.md +54 -0
- package/dist/flat-list.native.d.ts +17 -0
- package/dist/flat-list.native.d.ts.map +1 -0
- package/dist/flat-list.native.js +89 -0
- package/dist/flat-list.native.js.map +1 -0
- package/dist/foundation.d.ts +104 -0
- package/dist/foundation.d.ts.map +1 -0
- package/dist/foundation.js +115 -0
- package/dist/foundation.js.map +1 -0
- package/dist/foundation.native.d.ts +59 -0
- package/dist/foundation.native.d.ts.map +1 -0
- package/dist/foundation.native.js +40 -0
- package/dist/foundation.native.js.map +1 -0
- package/dist/generated/animated.d.ts +2 -0
- package/dist/generated/animated.d.ts.map +1 -0
- package/dist/generated/animated.js +3 -0
- package/dist/generated/animated.js.map +1 -0
- package/dist/generated/backdrop-filter.d.ts +2 -0
- package/dist/generated/backdrop-filter.d.ts.map +1 -0
- package/dist/generated/backdrop-filter.js +3 -0
- package/dist/generated/backdrop-filter.js.map +1 -0
- package/dist/generated/container.d.ts +2 -0
- package/dist/generated/container.d.ts.map +1 -0
- package/dist/generated/container.js +3 -0
- package/dist/generated/container.js.map +1 -0
- package/dist/generated/flat-list.d.ts +2 -0
- package/dist/generated/flat-list.d.ts.map +1 -0
- package/dist/generated/flat-list.js +2 -0
- package/dist/generated/flat-list.js.map +1 -0
- package/dist/generated/flat-list.native.d.ts +3 -0
- package/dist/generated/flat-list.native.d.ts.map +1 -0
- package/dist/generated/flat-list.native.js +2 -0
- package/dist/generated/flat-list.native.js.map +1 -0
- package/dist/generated/grid.d.ts +3 -0
- package/dist/generated/grid.d.ts.map +1 -0
- package/dist/generated/grid.js +4 -0
- package/dist/generated/grid.js.map +1 -0
- package/dist/generated/link.d.ts +2 -0
- package/dist/generated/link.d.ts.map +1 -0
- package/dist/generated/link.js +2 -0
- package/dist/generated/link.js.map +1 -0
- package/dist/generated/link.native.d.ts +2 -0
- package/dist/generated/link.native.d.ts.map +1 -0
- package/dist/generated/link.native.js +2 -0
- package/dist/generated/link.native.js.map +1 -0
- package/dist/generated/pressable.d.ts +2 -0
- package/dist/generated/pressable.d.ts.map +1 -0
- package/dist/generated/pressable.js +2 -0
- package/dist/generated/pressable.js.map +1 -0
- package/dist/generated/pressable.native.d.ts +2 -0
- package/dist/generated/pressable.native.d.ts.map +1 -0
- package/dist/generated/pressable.native.js +2 -0
- package/dist/generated/pressable.native.js.map +1 -0
- package/dist/generated/refresh-control.d.ts +2 -0
- package/dist/generated/refresh-control.d.ts.map +1 -0
- package/dist/generated/refresh-control.js +2 -0
- package/dist/generated/refresh-control.js.map +1 -0
- package/dist/generated/refresh-control.native.d.ts +2 -0
- package/dist/generated/refresh-control.native.d.ts.map +1 -0
- package/dist/generated/refresh-control.native.js +2 -0
- package/dist/generated/refresh-control.native.js.map +1 -0
- package/dist/generated/scroll-view.d.ts +2 -0
- package/dist/generated/scroll-view.d.ts.map +1 -0
- package/dist/generated/scroll-view.js +2 -0
- package/dist/generated/scroll-view.js.map +1 -0
- package/dist/generated/scroll-view.native.d.ts +2 -0
- package/dist/generated/scroll-view.native.d.ts.map +1 -0
- package/dist/generated/scroll-view.native.js +2 -0
- package/dist/generated/scroll-view.native.js.map +1 -0
- package/dist/generated/spaced.d.ts +2 -0
- package/dist/generated/spaced.d.ts.map +1 -0
- package/dist/generated/spaced.js +3 -0
- package/dist/generated/spaced.js.map +1 -0
- package/dist/generated/text-input.d.ts +2 -0
- package/dist/generated/text-input.d.ts.map +1 -0
- package/dist/generated/text-input.js +2 -0
- package/dist/generated/text-input.js.map +1 -0
- package/dist/generated/text-input.native.d.ts +2 -0
- package/dist/generated/text-input.native.d.ts.map +1 -0
- package/dist/generated/text-input.native.js +2 -0
- package/dist/generated/text-input.native.js.map +1 -0
- package/dist/generated/text-size.d.ts +2 -0
- package/dist/generated/text-size.d.ts.map +1 -0
- package/dist/generated/text-size.js +3 -0
- package/dist/generated/text-size.js.map +1 -0
- package/dist/generated/text.d.ts +2 -0
- package/dist/generated/text.d.ts.map +1 -0
- package/dist/generated/text.js +5 -0
- package/dist/generated/text.js.map +1 -0
- package/dist/generated/view.d.ts +2 -0
- package/dist/generated/view.d.ts.map +1 -0
- package/dist/generated/view.js +2 -0
- package/dist/generated/view.js.map +1 -0
- package/dist/generated/view.native.d.ts +2 -0
- package/dist/generated/view.native.d.ts.map +1 -0
- package/dist/generated/view.native.js +2 -0
- package/dist/generated/view.native.js.map +1 -0
- package/dist/index.d.ts +188 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +718 -0
- package/dist/index.js.map +1 -0
- package/dist/index.native.d.ts +22 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/index.native.js +8 -0
- package/dist/index.native.js.map +1 -0
- package/dist/link.d.ts +320 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +69 -0
- package/dist/link.js.map +1 -0
- package/dist/link.native.d.ts +33 -0
- package/dist/link.native.d.ts.map +1 -0
- package/dist/link.native.js +44 -0
- package/dist/link.native.js.map +1 -0
- package/dist/pressable.d.ts +65 -0
- package/dist/pressable.d.ts.map +1 -0
- package/dist/pressable.js +202 -0
- package/dist/pressable.js.map +1 -0
- package/dist/pressable.native.d.ts +55 -0
- package/dist/pressable.native.d.ts.map +1 -0
- package/dist/pressable.native.js +405 -0
- package/dist/pressable.native.js.map +1 -0
- package/dist/runtime-backdrop.native.d.ts +8 -0
- package/dist/runtime-backdrop.native.d.ts.map +1 -0
- package/dist/runtime-backdrop.native.js +12 -0
- package/dist/runtime-backdrop.native.js.map +1 -0
- package/dist/runtime-container.native.d.ts +41 -0
- package/dist/runtime-container.native.d.ts.map +1 -0
- package/dist/runtime-container.native.js +61 -0
- package/dist/runtime-container.native.js.map +1 -0
- package/dist/runtime-grid.d.ts +37 -0
- package/dist/runtime-grid.d.ts.map +1 -0
- package/dist/runtime-grid.js +139 -0
- package/dist/runtime-grid.js.map +1 -0
- package/dist/runtime-grid.native.d.ts +26 -0
- package/dist/runtime-grid.native.d.ts.map +1 -0
- package/dist/runtime-grid.native.js +76 -0
- package/dist/runtime-grid.native.js.map +1 -0
- package/dist/runtime-measured.d.ts +20 -0
- package/dist/runtime-measured.d.ts.map +1 -0
- package/dist/runtime-measured.js +42 -0
- package/dist/runtime-measured.js.map +1 -0
- package/dist/runtime-spacing.d.ts +9 -0
- package/dist/runtime-spacing.d.ts.map +1 -0
- package/dist/runtime-spacing.js +35 -0
- package/dist/runtime-spacing.js.map +1 -0
- package/dist/runtime-spacing.native.d.ts +12 -0
- package/dist/runtime-spacing.native.d.ts.map +1 -0
- package/dist/runtime-spacing.native.js +64 -0
- package/dist/runtime-spacing.native.js.map +1 -0
- package/dist/runtime-text-size.native.d.ts +29 -0
- package/dist/runtime-text-size.native.d.ts.map +1 -0
- package/dist/runtime-text-size.native.js +51 -0
- package/dist/runtime-text-size.native.js.map +1 -0
- package/dist/runtime-transition.native.d.ts +15 -0
- package/dist/runtime-transition.native.d.ts.map +1 -0
- package/dist/runtime-transition.native.js +156 -0
- package/dist/runtime-transition.native.js.map +1 -0
- package/dist/text-input.d.ts +40 -0
- package/dist/text-input.d.ts.map +1 -0
- package/dist/text-input.js +54 -0
- package/dist/text-input.js.map +1 -0
- package/dist/view.d.ts +42 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +84 -0
- package/dist/view.js.map +1 -0
- package/dist/view.native.d.ts +8 -0
- package/dist/view.native.d.ts.map +1 -0
- package/dist/view.native.js +5 -0
- package/dist/view.native.js.map +1 -0
- package/dist/windowing.d.ts +149 -0
- package/dist/windowing.d.ts.map +1 -0
- package/dist/windowing.js +336 -0
- package/dist/windowing.js.map +1 -0
- package/package.json +160 -0
- package/src/flat-list.native.tsx +158 -0
- package/src/foundation.native.tsx +179 -0
- package/src/foundation.tsx +323 -0
- package/src/generated/animated.ts +6 -0
- package/src/generated/backdrop-filter.ts +5 -0
- package/src/generated/container.ts +7 -0
- package/src/generated/flat-list.native.ts +6 -0
- package/src/generated/flat-list.ts +7 -0
- package/src/generated/grid.ts +4 -0
- package/src/generated/link.native.ts +1 -0
- package/src/generated/link.ts +1 -0
- package/src/generated/pressable.native.ts +5 -0
- package/src/generated/pressable.ts +5 -0
- package/src/generated/refresh-control.native.ts +4 -0
- package/src/generated/refresh-control.ts +1 -0
- package/src/generated/scroll-view.native.ts +4 -0
- package/src/generated/scroll-view.ts +1 -0
- package/src/generated/spaced.ts +2 -0
- package/src/generated/text-input.native.ts +4 -0
- package/src/generated/text-input.ts +1 -0
- package/src/generated/text-size.ts +7 -0
- package/src/generated/text.ts +8 -0
- package/src/generated/view.native.ts +1 -0
- package/src/generated/view.ts +1 -0
- package/src/index.native.ts +24 -0
- package/src/index.ts +1111 -0
- package/src/link.native.tsx +77 -0
- package/src/link.ts +125 -0
- package/src/pressable.native.tsx +538 -0
- package/src/pressable.ts +358 -0
- package/src/runtime-backdrop.native.tsx +22 -0
- package/src/runtime-container.native.tsx +105 -0
- package/src/runtime-grid.native.tsx +143 -0
- package/src/runtime-grid.ts +198 -0
- package/src/runtime-measured.ts +42 -0
- package/src/runtime-spacing.native.tsx +75 -0
- package/src/runtime-spacing.ts +37 -0
- package/src/runtime-text-size.native.tsx +79 -0
- package/src/runtime-transition.native.tsx +183 -0
- package/src/text-input.ts +129 -0
- package/src/view.native.ts +7 -0
- package/src/view.ts +165 -0
- package/src/windowing.ts +415 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// A transition driven by the style changing, rather than by an
|
|
3
|
+
// interaction.
|
|
4
|
+
//
|
|
5
|
+
// `./pressable.native.tsx` already animates, and it is built the other way
|
|
6
|
+
// round: it knows the four interaction booleans, calls the author's `style`
|
|
7
|
+
// function for each combination, and animates between the results. That
|
|
8
|
+
// shape is right there and wrong here, because the conditions this has to
|
|
9
|
+
// serve are ambient -- `dark:`, `md:`, `motion-reduce:` -- and the
|
|
10
|
+
// compiler expresses those as a guarded array, `[base, __hozoDark &&
|
|
11
|
+
// dark]`, which is already resolved by the time it arrives.
|
|
12
|
+
//
|
|
13
|
+
// So this one asks a simpler question: what did the style just become, and
|
|
14
|
+
// what was it before? Everything that differs and can be interpolated is
|
|
15
|
+
// animated to its new value; everything else is passed straight through.
|
|
16
|
+
// That covers the interaction case too, in principle, which is why this is
|
|
17
|
+
// not named after the conditions that prompted it.
|
|
18
|
+
//
|
|
19
|
+
// Colours run on the JavaScript driver and opacity and transforms do not.
|
|
20
|
+
// React Native cannot interpolate a colour natively, so mixing the two in
|
|
21
|
+
// one `Animated.timing` would drag the fast ones onto the slow driver.
|
|
22
|
+
// They are separate animations for that reason and not for tidiness.
|
|
23
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
24
|
+
import { Animated, Easing, StyleSheet } from 'react-native';
|
|
25
|
+
/** The colour properties worth animating, in the order they are read. */
|
|
26
|
+
const COLOR_KEYS = ['backgroundColor', 'borderColor', 'color'];
|
|
27
|
+
/**
|
|
28
|
+
* The transform entries, flattened to `{ key: value }`.
|
|
29
|
+
*
|
|
30
|
+
* React Native's `transform` is an array of one-key objects, which is a
|
|
31
|
+
* shape nothing can be diffed against directly -- two arrays with the same
|
|
32
|
+
* entries in a different order are the same transform and not equal.
|
|
33
|
+
*/
|
|
34
|
+
function transformMap(style) {
|
|
35
|
+
const out = new Map();
|
|
36
|
+
const transform = style?.transform;
|
|
37
|
+
if (!Array.isArray(transform))
|
|
38
|
+
return out;
|
|
39
|
+
for (const entry of transform) {
|
|
40
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
41
|
+
if (typeof value === 'number')
|
|
42
|
+
out.set(key, value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** What a transform key means when nothing sets it. */
|
|
48
|
+
function identity(key) {
|
|
49
|
+
return key.startsWith('scale') ? 1 : 0;
|
|
50
|
+
}
|
|
51
|
+
export function HozoAnimated({ style, hozoTransition, children, ...props }) {
|
|
52
|
+
const flat = useMemo(() => StyleSheet.flatten(style) ?? {}, [style]);
|
|
53
|
+
// One progress value per animation rather than one per property. The
|
|
54
|
+
// properties change together -- they are the same rule flipping -- so
|
|
55
|
+
// animating a single 0 → 1 and interpolating each property from its old
|
|
56
|
+
// value to its new one is both cheaper and impossible to get out of
|
|
57
|
+
// step with itself.
|
|
58
|
+
const progress = useRef(new Animated.Value(1)).current;
|
|
59
|
+
const from = useRef(flat);
|
|
60
|
+
const to = useRef(flat);
|
|
61
|
+
// What changed, computed during render so the effect below has nothing
|
|
62
|
+
// to work out. `JSON.stringify` on the two style objects is enough: they
|
|
63
|
+
// are flat, their values are primitives, and the compiler emits the keys
|
|
64
|
+
// in a stable order.
|
|
65
|
+
const signature = JSON.stringify(flat);
|
|
66
|
+
const previous = useRef(signature);
|
|
67
|
+
if (previous.current !== signature) {
|
|
68
|
+
// The *visible* style becomes the new starting point, not the
|
|
69
|
+
// previous target. Interrupting a half-finished fade and restarting
|
|
70
|
+
// from where it was going would make it jump backwards first.
|
|
71
|
+
from.current = to.current;
|
|
72
|
+
to.current = flat;
|
|
73
|
+
previous.current = signature;
|
|
74
|
+
}
|
|
75
|
+
// `signature` is read above rather than inside, and it is what says the
|
|
76
|
+
// style moved -- `hozoTransition` does not change when only the values
|
|
77
|
+
// do. Without it a style change starts no transition at all, which is
|
|
78
|
+
// the whole feature. `biome check --unsafe` offers to remove it.
|
|
79
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: it is what says the style changed
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!hozoTransition)
|
|
82
|
+
return;
|
|
83
|
+
progress.setValue(0);
|
|
84
|
+
const animation = Animated.timing(progress, {
|
|
85
|
+
toValue: 1,
|
|
86
|
+
duration: hozoTransition.duration,
|
|
87
|
+
delay: hozoTransition.delay ?? 0,
|
|
88
|
+
easing: easingFor(hozoTransition.easing),
|
|
89
|
+
// Colours are in here too, and React Native cannot interpolate one
|
|
90
|
+
// on the native driver. One animation on the JavaScript driver is
|
|
91
|
+
// the honest choice: two drivers running the same rule would drift
|
|
92
|
+
// against each other on a busy frame, and a background that arrives
|
|
93
|
+
// before the text that sits on it is worse than both arriving late.
|
|
94
|
+
useNativeDriver: false,
|
|
95
|
+
});
|
|
96
|
+
animation.start();
|
|
97
|
+
return () => animation.stop();
|
|
98
|
+
}, [progress, signature, hozoTransition]);
|
|
99
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: as above -- `signature` is what changed
|
|
100
|
+
const animated = useMemo(() => {
|
|
101
|
+
if (!hozoTransition)
|
|
102
|
+
return flat;
|
|
103
|
+
const overrides = {};
|
|
104
|
+
if (typeof from.current.opacity === 'number' || typeof flat.opacity === 'number') {
|
|
105
|
+
const start = typeof from.current.opacity === 'number' ? from.current.opacity : 1;
|
|
106
|
+
const end = typeof flat.opacity === 'number' ? flat.opacity : 1;
|
|
107
|
+
if (start !== end) {
|
|
108
|
+
overrides.opacity = progress.interpolate({ inputRange: [0, 1], outputRange: [start, end] });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const key of COLOR_KEYS) {
|
|
112
|
+
// Read through a record: `color` lives on `TextStyle` and the rest
|
|
113
|
+
// on `ViewStyle`, and a component that may be either has to look at
|
|
114
|
+
// both. The runtime check below is what makes it safe.
|
|
115
|
+
const start = from.current[key];
|
|
116
|
+
const end = flat[key];
|
|
117
|
+
if (typeof start !== 'string' || typeof end !== 'string' || start === end)
|
|
118
|
+
continue;
|
|
119
|
+
overrides[key] = progress.interpolate({ inputRange: [0, 1], outputRange: [start, end] });
|
|
120
|
+
}
|
|
121
|
+
const before = transformMap(from.current);
|
|
122
|
+
const after = transformMap(flat);
|
|
123
|
+
const keys = [...new Set([...before.keys(), ...after.keys()])];
|
|
124
|
+
const moved = keys.filter((key) => (before.get(key) ?? identity(key)) !== (after.get(key) ?? identity(key)));
|
|
125
|
+
if (moved.length > 0) {
|
|
126
|
+
// Every key, not only the moved ones: `transform` is replaced
|
|
127
|
+
// wholesale, so leaving one out would reset it to identity halfway
|
|
128
|
+
// through the animation of its neighbour.
|
|
129
|
+
overrides.transform = keys.map((key) => ({
|
|
130
|
+
[key]: progress.interpolate({
|
|
131
|
+
inputRange: [0, 1],
|
|
132
|
+
outputRange: [before.get(key) ?? identity(key), after.get(key) ?? identity(key)],
|
|
133
|
+
}),
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
return [flat, overrides];
|
|
137
|
+
}, [flat, hozoTransition, progress, signature]);
|
|
138
|
+
return (_jsx(Animated.View, { style: animated, ...props, children: children }));
|
|
139
|
+
}
|
|
140
|
+
function easingFor(name) {
|
|
141
|
+
// Built here rather than in a module-level table, for the reason
|
|
142
|
+
// `hooks.native.ts` does the same: a table calls `Easing.bezier` on
|
|
143
|
+
// import, for every project that loads the package and never
|
|
144
|
+
// transitions. The import itself is free; the call is not.
|
|
145
|
+
switch (name) {
|
|
146
|
+
case 'linear':
|
|
147
|
+
return Easing.linear;
|
|
148
|
+
case 'ease-in':
|
|
149
|
+
return Easing.bezier(0.4, 0, 1, 1);
|
|
150
|
+
case 'ease-out':
|
|
151
|
+
return Easing.bezier(0, 0, 0.2, 1);
|
|
152
|
+
default:
|
|
153
|
+
return Easing.bezier(0.4, 0, 0.2, 1);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=runtime-transition.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-transition.native.js","sourceRoot":"","sources":["../src/runtime-transition.native.tsx"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,eAAe;AACf,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,wEAAwE;AACxE,0EAA0E;AAC1E,mEAAmE;AACnE,qEAAqE;AACrE,4DAA4D;AAC5D,EAAE;AACF,2EAA2E;AAC3E,yEAAyE;AACzE,yEAAyE;AACzE,2EAA2E;AAC3E,mDAAmD;AACnD,EAAE;AACF,0EAA0E;AAC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CAAC;aACH,CAAC,CAAC,CAAA;QACL,CAAC;QAED,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IAC1B,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAA;IAE/C,OAAO,CACL,KAAC,QAAQ,CAAC,IAAI,IAAC,KAAK,EAAE,QAAgC,KAAM,KAAK,YAC9D,QAAQ,GACK,CACjB,CAAA;AACH,CAAC;AAED,SAAS,SAAS,CAAC,IAAkC;IACnD,iEAAiE;IACjE,oEAAoE;IACpE,6DAA6D;IAC7D,2DAA2D;IAC3D,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,MAAM,CAAA;QACtB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QACpC,KAAK,UAAU;YACb,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;QACpC;YACE,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;IACxC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type HozoDomStyle } from '@hozo/engine';
|
|
2
|
+
import { type ChangeEventHandler, type InputHTMLAttributes, type KeyboardEvent, type ReactNode } from 'react';
|
|
3
|
+
type InputMode = 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url';
|
|
4
|
+
type DomInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'children' | 'onChange' | 'onKeyDown' | 'readOnly' | 'size' | 'style' | 'value'>;
|
|
5
|
+
export interface HozoTextInputProps extends DomInputProps {
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
value?: string;
|
|
8
|
+
style?: HozoDomStyle;
|
|
9
|
+
accessibilityLabel?: string;
|
|
10
|
+
accessibilityHint?: string;
|
|
11
|
+
accessibilityLabelledBy?: string;
|
|
12
|
+
testID?: string;
|
|
13
|
+
nativeID?: string;
|
|
14
|
+
onChange?: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
15
|
+
onChangeText?: (text: string) => void;
|
|
16
|
+
onKeyPress?: (event: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
17
|
+
onSubmitEditing?: (event: {
|
|
18
|
+
nativeEvent: {
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
}) => void;
|
|
22
|
+
editable?: boolean;
|
|
23
|
+
readOnly?: boolean;
|
|
24
|
+
multiline?: boolean;
|
|
25
|
+
numberOfLines?: number;
|
|
26
|
+
secureTextEntry?: boolean;
|
|
27
|
+
keyboardType?: string;
|
|
28
|
+
inputMode?: InputMode;
|
|
29
|
+
returnKeyType?: string;
|
|
30
|
+
blurOnSubmit?: boolean;
|
|
31
|
+
placeholderTextColor?: string;
|
|
32
|
+
selectionColor?: string;
|
|
33
|
+
cursorColor?: string;
|
|
34
|
+
keyboardAppearance?: string;
|
|
35
|
+
hitSlop?: unknown;
|
|
36
|
+
}
|
|
37
|
+
/** A value-level TextInput for factories and other code the JSX compiler cannot rewrite. */
|
|
38
|
+
export declare const HozoTextInput: import("react").ForwardRefExoticComponent<HozoTextInputProps & import("react").RefAttributes<HTMLInputElement | HTMLTextAreaElement>>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=text-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-input.d.ts","sourceRoot":"","sources":["../src/text-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAEL,KAAK,kBAAkB,EAGvB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAA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S,CAAC,EAAE,SAAS,CAAA;IACrB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,4FAA4F;AAC5F,eAAO,MAAM,aAAa,uIAsEzB,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { hozoDomStyle } from '@hozo/engine';
|
|
2
|
+
import { createElement, forwardRef, } from 'react';
|
|
3
|
+
const INPUT_MODES = {
|
|
4
|
+
'number-pad': 'numeric',
|
|
5
|
+
numeric: 'numeric',
|
|
6
|
+
'decimal-pad': 'decimal',
|
|
7
|
+
'email-address': 'email',
|
|
8
|
+
'phone-pad': 'tel',
|
|
9
|
+
url: 'url',
|
|
10
|
+
'web-search': 'search',
|
|
11
|
+
};
|
|
12
|
+
/** A value-level TextInput for factories and other code the JSX compiler cannot rewrite. */
|
|
13
|
+
export const HozoTextInput = forwardRef(function HozoTextInput({ accessibilityHint, accessibilityLabel, accessibilityLabelledBy, blurOnSubmit, cursorColor, editable, hitSlop: _hitSlop, inputMode, keyboardAppearance: _keyboardAppearance, keyboardType, multiline, nativeID, numberOfLines, onChange, onChangeText, onKeyPress, onSubmitEditing, placeholderTextColor: _placeholderTextColor, readOnly, returnKeyType, secureTextEntry, selectionColor, style, testID, value, ...props }, ref) {
|
|
14
|
+
const change = (event) => {
|
|
15
|
+
onChange?.(event);
|
|
16
|
+
onChangeText?.(event.currentTarget.value);
|
|
17
|
+
};
|
|
18
|
+
const keyDown = (event) => {
|
|
19
|
+
onKeyPress?.(event);
|
|
20
|
+
if (event.key !== 'Enter' || !onSubmitEditing)
|
|
21
|
+
return;
|
|
22
|
+
if (!multiline || blurOnSubmit) {
|
|
23
|
+
onSubmitEditing({ nativeEvent: { text: event.currentTarget.value } });
|
|
24
|
+
if (blurOnSubmit)
|
|
25
|
+
event.currentTarget.blur();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const resolvedStyle = hozoDomStyle([
|
|
29
|
+
style,
|
|
30
|
+
cursorColor || selectionColor ? { caretColor: cursorColor ?? selectionColor } : undefined,
|
|
31
|
+
]);
|
|
32
|
+
const shared = {
|
|
33
|
+
...props,
|
|
34
|
+
id: nativeID,
|
|
35
|
+
value,
|
|
36
|
+
readOnly: readOnly ?? (editable === undefined ? undefined : !editable),
|
|
37
|
+
inputMode: inputMode ?? (keyboardType ? INPUT_MODES[keyboardType] : undefined),
|
|
38
|
+
enterKeyHint: returnKeyType,
|
|
39
|
+
style: resolvedStyle,
|
|
40
|
+
'aria-label': accessibilityLabel,
|
|
41
|
+
'aria-description': accessibilityHint,
|
|
42
|
+
'aria-labelledby': accessibilityLabelledBy,
|
|
43
|
+
'data-testid': testID,
|
|
44
|
+
onChange: change,
|
|
45
|
+
onKeyDown: keyDown,
|
|
46
|
+
};
|
|
47
|
+
return createElement(multiline ? 'textarea' : 'input', {
|
|
48
|
+
...shared,
|
|
49
|
+
ref,
|
|
50
|
+
rows: multiline ? numberOfLines : undefined,
|
|
51
|
+
type: multiline ? undefined : secureTextEntry ? 'password' : props.type,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=text-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-input.js","sourceRoot":"","sources":["../src/text-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,YAAY,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAGL,aAAa,EACb,UAAU,GAIX,MAAM,OAAO,CAAA;AAId,MAAM,WAAW,GAA8B;IAC7C,YAAY,EAAE,SAAS;IACvB,OAAO,EAAE,SAAS;IAClB,aAAa,EAAE,SAAS;IACxB,eAAe,EAAE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C,EAAE,UAAU,EAAE,WAAW,IAAI,cAAc,EAAE,CAAC,CAAC,CAAC,SAAS;KAC1F,CAAC,CAAA;IACF,MAAM,MAAM,GAAG;QACb,GAAG,KAAK;QACR,EAAE,EAAE,QAAQ;QACZ,KAAK;QACL,QAAQ,EAAE,QAAQ,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACtE,SAAS,EAAE,SAAS,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9E,YAAY,EAAE,aAAsE;QACpF,KAAK,EAAE,aAAa;QACpB,YAAY,EAAE,kBAAkB;QAChC,kBAAkB,EAAE,iBAAiB;QACrC,iBAAiB,EAAE,uBAAuB;QAC1C,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,MAAM;QAChB,SAAS,EAAE,OAAO;KACnB,CAAA;IACD,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE;QACrD,GAAG,MAAM;QACT,GAAG;QACH,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;QAC3C,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI;KACxE,CAAC,CAAA;AACJ,CAAC,CACF,CAAA"}
|
package/dist/view.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type HozoDomStyle, type ResponderProps } from '@hozo/engine';
|
|
2
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
3
|
+
export interface HozoLayoutEvent {
|
|
4
|
+
nativeEvent: {
|
|
5
|
+
layout: {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface HozoViewProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'style'>, ResponderProps {
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
style?: HozoDomStyle;
|
|
16
|
+
testID?: string;
|
|
17
|
+
nativeID?: string;
|
|
18
|
+
pointerEvents?: 'auto' | 'none' | 'box-none' | 'box-only';
|
|
19
|
+
accessibilityLabel?: string;
|
|
20
|
+
accessibilityHint?: string;
|
|
21
|
+
accessibilityRole?: string;
|
|
22
|
+
accessibilityState?: {
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
selected?: boolean;
|
|
25
|
+
checked?: boolean | 'mixed';
|
|
26
|
+
busy?: boolean;
|
|
27
|
+
expanded?: boolean;
|
|
28
|
+
};
|
|
29
|
+
accessibilityValue?: {
|
|
30
|
+
min?: number;
|
|
31
|
+
max?: number;
|
|
32
|
+
now?: number;
|
|
33
|
+
text?: string;
|
|
34
|
+
};
|
|
35
|
+
accessibilityLiveRegion?: 'none' | 'polite' | 'assertive';
|
|
36
|
+
onLayout?: (event: HozoLayoutEvent) => void;
|
|
37
|
+
collapsable?: boolean;
|
|
38
|
+
'data-hozo-disabled'?: string;
|
|
39
|
+
}
|
|
40
|
+
/** A measured/responder-aware View for the Web paths that cannot be a plain div. */
|
|
41
|
+
export declare const HozoView: import("react").ForwardRefExoticComponent<HozoViewProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
42
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,cAAc,EAEpB,MAAM,cAAc,CAAA;AACrB,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,SAAS,EAKf,MAAM,OAAO,CAAA;AAEd,MAAM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rB,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAOD,oFAAoF;AACpF,eAAO,MAAM,QAAQ,0GAgHnB,CAAA"}
|
package/dist/view.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { hozoDomStyle, useResponderDomProps, } from '@hozo/engine';
|
|
2
|
+
import { createElement, forwardRef, useCallback, useEffect, useRef, } from 'react';
|
|
3
|
+
function assignRef(ref, value) {
|
|
4
|
+
if (typeof ref === 'function')
|
|
5
|
+
ref(value);
|
|
6
|
+
else if (ref)
|
|
7
|
+
ref.current = value;
|
|
8
|
+
}
|
|
9
|
+
/** A measured/responder-aware View for the Web paths that cannot be a plain div. */
|
|
10
|
+
export const HozoView = forwardRef(function HozoView({ children, style, testID, nativeID, pointerEvents, accessibilityLabel, accessibilityHint, accessibilityRole, accessibilityState, accessibilityValue, accessibilityLiveRegion, onLayout, collapsable: _collapsable, role, 'aria-disabled': ariaDisabled, 'data-hozo-disabled': dataHozoDisabled, onStartShouldSetResponder, onStartShouldSetResponderCapture, onMoveShouldSetResponder, onMoveShouldSetResponderCapture, onResponderGrant, onResponderStart, onResponderMove, onResponderEnd, onResponderRelease, onResponderReject, onResponderTerminate, onResponderTerminationRequest, ...props }, forwardedRef) {
|
|
11
|
+
const elementRef = useRef(null);
|
|
12
|
+
const layoutCallback = useRef(onLayout);
|
|
13
|
+
layoutCallback.current = onLayout;
|
|
14
|
+
const setRef = useCallback((element) => {
|
|
15
|
+
elementRef.current = element;
|
|
16
|
+
assignRef(forwardedRef, element);
|
|
17
|
+
}, [forwardedRef]);
|
|
18
|
+
const responder = useResponderDomProps(elementRef, {
|
|
19
|
+
onStartShouldSetResponder,
|
|
20
|
+
onStartShouldSetResponderCapture,
|
|
21
|
+
onMoveShouldSetResponder,
|
|
22
|
+
onMoveShouldSetResponderCapture,
|
|
23
|
+
onResponderGrant,
|
|
24
|
+
onResponderStart,
|
|
25
|
+
onResponderMove,
|
|
26
|
+
onResponderEnd,
|
|
27
|
+
onResponderRelease,
|
|
28
|
+
onResponderReject,
|
|
29
|
+
onResponderTerminate,
|
|
30
|
+
onResponderTerminationRequest,
|
|
31
|
+
});
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const element = elementRef.current;
|
|
34
|
+
if (!element || !layoutCallback.current)
|
|
35
|
+
return;
|
|
36
|
+
let previous = '';
|
|
37
|
+
const emit = () => {
|
|
38
|
+
const rect = element.getBoundingClientRect();
|
|
39
|
+
const layout = {
|
|
40
|
+
x: element.offsetLeft,
|
|
41
|
+
y: element.offsetTop,
|
|
42
|
+
width: rect.width,
|
|
43
|
+
height: rect.height,
|
|
44
|
+
};
|
|
45
|
+
const key = `${layout.x}:${layout.y}:${layout.width}:${layout.height}`;
|
|
46
|
+
if (key === previous)
|
|
47
|
+
return;
|
|
48
|
+
previous = key;
|
|
49
|
+
layoutCallback.current?.({ nativeEvent: { layout } });
|
|
50
|
+
};
|
|
51
|
+
emit();
|
|
52
|
+
if (typeof ResizeObserver === 'undefined')
|
|
53
|
+
return;
|
|
54
|
+
const observer = new ResizeObserver(emit);
|
|
55
|
+
observer.observe(element);
|
|
56
|
+
return () => observer.disconnect();
|
|
57
|
+
}, []);
|
|
58
|
+
const state = accessibilityState;
|
|
59
|
+
const value = accessibilityValue;
|
|
60
|
+
return createElement('div', {
|
|
61
|
+
...props,
|
|
62
|
+
...responder,
|
|
63
|
+
ref: setRef,
|
|
64
|
+
role: accessibilityRole ?? role,
|
|
65
|
+
style: hozoDomStyle(style),
|
|
66
|
+
'data-testid': testID,
|
|
67
|
+
id: nativeID,
|
|
68
|
+
'data-hozo-pointer-events': pointerEvents,
|
|
69
|
+
'data-hozo-disabled': state?.disabled ? '' : dataHozoDisabled,
|
|
70
|
+
'aria-disabled': state?.disabled ? true : ariaDisabled,
|
|
71
|
+
'aria-selected': state?.selected,
|
|
72
|
+
'aria-checked': state?.checked,
|
|
73
|
+
'aria-busy': state?.busy,
|
|
74
|
+
'aria-expanded': state?.expanded,
|
|
75
|
+
'aria-valuemin': value?.min,
|
|
76
|
+
'aria-valuemax': value?.max,
|
|
77
|
+
'aria-valuenow': value?.now,
|
|
78
|
+
'aria-valuetext': value?.text,
|
|
79
|
+
'aria-live': accessibilityLiveRegion === 'none' ? undefined : accessibilityLiveRegion,
|
|
80
|
+
'aria-label': accessibilityLabel,
|
|
81
|
+
'aria-description': accessibilityHint,
|
|
82
|
+
}, children);
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=view.js.map
|
package/dist/view.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAEZ,oBAAoB,GACrB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,aAAa,EACb,UAAU,EAIV,WAAW,EACX,SAAS,EACT,MAAM,GACP,MAAM,OAAO,CAAA;AA+Bd,SAAS,SAAS,CAAI,GAAuB,EAAE,KAAe;IAC5D,IAAI,OAAO,GAAG,KAAK,UAAU;QAAE,GAAG,CAAC,KAAK,CAAC,CAAA;SACpC,IAAI,GAAG;QAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAA;AACnC,CAAC;AAED,oFAAoF;AACpF,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAgC,SAAS,QAAQ,CACjF,EACE,QAAQ,EACR,KAAK,EACL,MAAM,EACN,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,QAAQ,EACR,WAAW,EAAE,YAAY,EACzB,IAAI,EACJ,eAAe,EAAE,YAAY,EAC7B,oBAAoB,EAAE,gBAAgB,EACtC,yBAAyB,EACzB,gCAAgC,EAChC,wBAAwB,EACxB,+BAA+B,EAC/B,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,o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AC3B,gBAAgB,EAAE,KAAK,EAAE,IAAI;QAC7B,WAAW,EAAE,uBAAuB,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,uBAAuB;QACrF,YAAY,EAAE,kBAAkB;QAChC,kBAAkB,EAAE,iBAAiB;KACtC,EACD,QAAQ,CACT,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as ReactNative from 'react-native';
|
|
2
|
+
export type HozoViewProps = ReactNative.ViewProps;
|
|
3
|
+
export declare const HozoView: (props: Omit<ReactNative.ViewProps, keyof {
|
|
4
|
+
ref?: React.Ref<ReactNative.ViewInstance> | undefined;
|
|
5
|
+
}> & {
|
|
6
|
+
ref?: React.Ref<ReactNative.ViewInstance> | undefined;
|
|
7
|
+
}) => React.ReactNode;
|
|
8
|
+
//# sourceMappingURL=view.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.native.d.ts","sourceRoot":"","sources":["../src/view.native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,cAAc,CAAA;AAE3C,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,SAAS,CAAA;AAIjD,eAAO,MAAM,QAAQ;;;;qBAAmB,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as ReactNative from 'react-native';
|
|
2
|
+
// Native lowering normally imports View directly. The paired export keeps
|
|
3
|
+
// platform resolution safe for source that explicitly uses the fallback.
|
|
4
|
+
export const HozoView = ReactNative.View;
|
|
5
|
+
//# sourceMappingURL=view.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.native.js","sourceRoot":"","sources":["../src/view.native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,cAAc,CAAA;AAI3C,0EAA0E;AAC1E,yEAAyE;AACzE,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAA"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/** What one row's geometry is, in the scrolling axis. */
|
|
2
|
+
export interface RowMetrics {
|
|
3
|
+
offset: number;
|
|
4
|
+
length: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Row lengths, measured where they have been and estimated where they have
|
|
8
|
+
* not.
|
|
9
|
+
*
|
|
10
|
+
* Keyed by the caller's own key rather than by index, which is the whole
|
|
11
|
+
* point: a feed that prepends ten rows moves every index by ten, and a
|
|
12
|
+
* store keyed by index would report ten rows of wrong heights and jump the
|
|
13
|
+
* scroll position. Compose makes the same argument for `key` on
|
|
14
|
+
* `LazyColumn`, and it is the one thing SwiftUI and Compose *do* ask of a
|
|
15
|
+
* caller.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ListMetrics {
|
|
18
|
+
/** Measured lengths, by key, surviving reorder and window movement. */
|
|
19
|
+
private readonly measured;
|
|
20
|
+
/** Prefix sums for the current key order; rebuilt when something changes. */
|
|
21
|
+
private offsets;
|
|
22
|
+
private keys;
|
|
23
|
+
private dirty;
|
|
24
|
+
private estimate;
|
|
25
|
+
constructor(estimate: number);
|
|
26
|
+
/** The key order to measure against. Cheap to call every render. */
|
|
27
|
+
setKeys(keys: readonly string[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Records what a row actually measured.
|
|
30
|
+
*
|
|
31
|
+
* Returns whether this changed anything, so a caller can avoid a re-render
|
|
32
|
+
* for a `ResizeObserver` callback that reports the size it already knew --
|
|
33
|
+
* which is most of them, since the observer fires on mount for every row.
|
|
34
|
+
*/
|
|
35
|
+
measure(key: string, length: number): boolean;
|
|
36
|
+
/** Forgets a measurement. For a row whose content changed identity under one key. */
|
|
37
|
+
forget(key: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* The estimate used for rows nothing has measured.
|
|
40
|
+
*
|
|
41
|
+
* The mean of what *has* been measured, once anything has, rather than
|
|
42
|
+
* the constructor's number. A list of 60px rows told to estimate 100
|
|
43
|
+
* would otherwise keep a scrollbar half again too long for as long as it
|
|
44
|
+
* was scrolled, and every `scrollToIndex` past the window would land in
|
|
45
|
+
* the wrong place. React Native keeps the same running average for the
|
|
46
|
+
* same reason.
|
|
47
|
+
*/
|
|
48
|
+
get averageLength(): number;
|
|
49
|
+
/** Replaces the starting estimate. For a caller that learns a better one. */
|
|
50
|
+
setEstimate(estimate: number): void;
|
|
51
|
+
lengthAt(index: number): number;
|
|
52
|
+
offsetAt(index: number): number;
|
|
53
|
+
metricsAt(index: number): RowMetrics;
|
|
54
|
+
get totalLength(): number;
|
|
55
|
+
/** How many of the current rows have a real measurement. */
|
|
56
|
+
get measuredCount(): number;
|
|
57
|
+
private rebuild;
|
|
58
|
+
}
|
|
59
|
+
/** The rows to mount, inclusive at both ends. `last < first` means none. */
|
|
60
|
+
export interface WindowRange {
|
|
61
|
+
first: number;
|
|
62
|
+
last: number;
|
|
63
|
+
}
|
|
64
|
+
export interface WindowRangeInput {
|
|
65
|
+
count: number;
|
|
66
|
+
/** Scroll offset along the axis, in list space. */
|
|
67
|
+
offset: number;
|
|
68
|
+
/** The viewport's length along the axis. */
|
|
69
|
+
visibleLength: number;
|
|
70
|
+
/** React Native's units: `(windowSize - 1)` viewports of overscan. */
|
|
71
|
+
windowSize: number;
|
|
72
|
+
maxToRenderPerBatch: number;
|
|
73
|
+
/** Signed, for the fill bias. Zero is the honest answer when unknown. */
|
|
74
|
+
velocity?: number;
|
|
75
|
+
previous: WindowRange;
|
|
76
|
+
metrics: Pick<ListMetrics, 'offsetAt' | 'lengthAt'>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The first and last row indices to mount.
|
|
80
|
+
*
|
|
81
|
+
* A port of `computeWindowedRenderLimits`; see this file's header for why
|
|
82
|
+
* it is a port rather than an invention.
|
|
83
|
+
*/
|
|
84
|
+
export declare function windowRange(input: WindowRangeInput): WindowRange;
|
|
85
|
+
/**
|
|
86
|
+
* The first `count` rows, for the render before anything has been measured.
|
|
87
|
+
*
|
|
88
|
+
* `initialNumToRender` is not an overscan window and is not derived from
|
|
89
|
+
* one: it is what to put on the screen when the viewport's own size is not
|
|
90
|
+
* known yet, which on the Web is every server render and the first client
|
|
91
|
+
* commit. Rendering nothing there would hand a crawler and a
|
|
92
|
+
* `renderToStaticMarkup` caller an empty list.
|
|
93
|
+
*/
|
|
94
|
+
export declare function initialRange(count: number, initialNumToRender: number): WindowRange;
|
|
95
|
+
/** A row to hold still across a data change, and where it was. */
|
|
96
|
+
export interface Anchor {
|
|
97
|
+
key: string;
|
|
98
|
+
offset: number;
|
|
99
|
+
}
|
|
100
|
+
export interface MaintainVisibleContentPosition {
|
|
101
|
+
/**
|
|
102
|
+
* The first row allowed to be the anchor.
|
|
103
|
+
*
|
|
104
|
+
* `1` is the usual value for a feed with a header row: the header is
|
|
105
|
+
* index 0 and is always at offset 0, so anchoring on it would hold
|
|
106
|
+
* nothing still.
|
|
107
|
+
*/
|
|
108
|
+
minIndexForVisible: number;
|
|
109
|
+
/**
|
|
110
|
+
* Scroll to the top instead of holding position, when already within this
|
|
111
|
+
* many pixels of it. Absent means never.
|
|
112
|
+
*/
|
|
113
|
+
autoscrollToTopThreshold?: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The row to hold still when the data changes under a scrolled list.
|
|
117
|
+
*
|
|
118
|
+
* The first row at or after `minIndexForVisible` whose end is below the
|
|
119
|
+
* current offset -- that is, the first one the reader can see. Holding a
|
|
120
|
+
* row by *key* rather than by index is what makes this work at all: a feed
|
|
121
|
+
* that prepends ten rows renumbers every index, and there is no arithmetic
|
|
122
|
+
* on indices that survives it.
|
|
123
|
+
*/
|
|
124
|
+
export declare function anchorRow(keys: readonly string[], metrics: Pick<ListMetrics, 'offsetAt' | 'lengthAt'>, scrollOffset: number, minIndexForVisible: number): Anchor | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* How far the scroll offset has to move for `anchor` to stay where it was.
|
|
127
|
+
*
|
|
128
|
+
* Zero when the anchor is gone -- deleted, or scrolled out of a list that
|
|
129
|
+
* was replaced wholesale -- because the honest answer there is that there
|
|
130
|
+
* is nothing left to hold still, and inventing a correction would move a
|
|
131
|
+
* list the reader was looking at.
|
|
132
|
+
*/
|
|
133
|
+
export declare function anchorCorrection(anchor: Anchor, keys: readonly string[], metrics: Pick<ListMetrics, 'offsetAt'>): number;
|
|
134
|
+
/**
|
|
135
|
+
* Rows kept mounted around the focused one, however the scroll window moved.
|
|
136
|
+
*
|
|
137
|
+
* Focus is not the viewport. A row can hold focus and be scrolled well out
|
|
138
|
+
* of sight, and unmounting it drops focus to `<body>` -- which is not a
|
|
139
|
+
* degraded experience but a lost place. Tabbing forward has the mirror
|
|
140
|
+
* problem: the last mounted row is the last row in the document, so there
|
|
141
|
+
* is nothing after it to move to.
|
|
142
|
+
*
|
|
143
|
+
* `FOCUS_MARGIN` is small on purpose. It is a landing strip either side of
|
|
144
|
+
* focus so a step past the edge has somewhere to go before the next
|
|
145
|
+
* recompute catches up -- not a second overscan window.
|
|
146
|
+
*/
|
|
147
|
+
export declare const FOCUS_MARGIN = 3;
|
|
148
|
+
export declare function withFocus(window: WindowRange, focusRow: number | null, count: number): WindowRange;
|
|
149
|
+
//# sourceMappingURL=windowing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"windowing.d.ts","sourceRoot":"","sources":["../src/windowing.ts"],"names":[],"mappings":"AA4CA,yDAAyD;AACzD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;;GAUG;AACH,qBAAa,WAAW;IACtB,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IACrD,6EAA6E;IAC7E,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,KAAK,CAAO;IAIpB,OAAO,CAAC,QAAQ,CAAQ;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