@lynx-example/design-guide 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/README.md +10 -0
- package/dist/color_wheels.lynx.bundle +0 -0
- package/dist/color_wheels.web.bundle +1 -1
- package/dist/force_field.lynx.bundle +0 -0
- package/dist/force_field.web.bundle +1 -1
- package/dist/gooey_effect.lynx.bundle +0 -0
- package/dist/gooey_effect.web.bundle +1 -1
- package/dist/soft_glow.lynx.bundle +0 -0
- package/dist/soft_glow.web.bundle +1 -1
- package/package.json +23 -10
- package/src/shared/hooks/use-element-frame/index.ts +9 -4
- package/src/shared/hooks/use-pointer-axis/index.ts +11 -3
- package/src/shared/hooks/use-pointer-point/index.ts +63 -3
|
@@ -9,6 +9,7 @@ export type PointerPoint = { x: number; y: number };
|
|
|
9
9
|
export type UsePointerPointProps = {
|
|
10
10
|
x0?: number;
|
|
11
11
|
y0?: number;
|
|
12
|
+
debug?: boolean;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
export type PointerBindProps = {
|
|
@@ -26,6 +27,20 @@ export type PointerBindProps = {
|
|
|
26
27
|
bindlayoutchange?: (e: LayoutChangeEvent) => void;
|
|
27
28
|
};
|
|
28
29
|
|
|
30
|
+
export type PointerPointDebugInfo = {
|
|
31
|
+
/** Latest raw event coords from TouchEvent.detail */
|
|
32
|
+
lastEvent?: { x: number; y: number };
|
|
33
|
+
|
|
34
|
+
/** Latest frame snapshot used for mapping */
|
|
35
|
+
frame: { left: number | null; top: number | null; width: number; height: number };
|
|
36
|
+
|
|
37
|
+
/** Latest computed axis positions */
|
|
38
|
+
axis: {
|
|
39
|
+
x?: { offset: number; ratio: number; length: number };
|
|
40
|
+
y?: { offset: number; ratio: number; length: number };
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
29
44
|
export type UsePointerPointReturnValue = {
|
|
30
45
|
p: PointerPoint;
|
|
31
46
|
bind: PointerBindProps;
|
|
@@ -33,11 +48,14 @@ export type UsePointerPointReturnValue = {
|
|
|
33
48
|
handlePointerMove: (e: TouchEvent) => void;
|
|
34
49
|
handlePointerUp: (e: TouchEvent) => void;
|
|
35
50
|
handleElementLayoutChange: (e: LayoutChangeEvent) => void;
|
|
51
|
+
/** Debug-only: populated when `debug: true` */
|
|
52
|
+
debug?: PointerPointDebugInfo;
|
|
36
53
|
};
|
|
37
54
|
|
|
38
55
|
function usePointerPoint({
|
|
39
56
|
x0 = 0.5,
|
|
40
57
|
y0 = 0.5,
|
|
58
|
+
debug = false,
|
|
41
59
|
}: UsePointerPointProps = {}): UsePointerPointReturnValue {
|
|
42
60
|
const [p, setP] = useState<PointerPoint>({ x: x0, y: y0 });
|
|
43
61
|
|
|
@@ -46,11 +64,34 @@ function usePointerPoint({
|
|
|
46
64
|
|
|
47
65
|
const frameRef = useElementFrame();
|
|
48
66
|
|
|
67
|
+
const debugRef = useRef<PointerPointDebugInfo>({
|
|
68
|
+
frame: { left: null, top: null, width: 0, height: 0 },
|
|
69
|
+
axis: {},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const syncFrameDebug = () => {
|
|
73
|
+
if (!debug) return;
|
|
74
|
+
debugRef.current.frame = {
|
|
75
|
+
left: frameRef.leftRef.current,
|
|
76
|
+
top: frameRef.topRef.current,
|
|
77
|
+
width: frameRef.widthRef.current,
|
|
78
|
+
height: frameRef.heightRef.current,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
49
82
|
const axisX = usePointerAxis({
|
|
50
83
|
axis: "x",
|
|
51
84
|
frame: frameRef,
|
|
52
85
|
onUpdate(pos) {
|
|
53
86
|
lastXRef.current = pos.offsetRatio;
|
|
87
|
+
if (debug) {
|
|
88
|
+
syncFrameDebug();
|
|
89
|
+
debugRef.current.axis.x = {
|
|
90
|
+
offset: pos.offset,
|
|
91
|
+
ratio: pos.offsetRatio,
|
|
92
|
+
length: pos.elementLength,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
54
95
|
setP({ x: lastXRef.current, y: lastYRef.current });
|
|
55
96
|
},
|
|
56
97
|
});
|
|
@@ -60,22 +101,40 @@ function usePointerPoint({
|
|
|
60
101
|
frame: frameRef,
|
|
61
102
|
onUpdate(pos) {
|
|
62
103
|
lastYRef.current = pos.offsetRatio;
|
|
104
|
+
if (debug) {
|
|
105
|
+
syncFrameDebug();
|
|
106
|
+
debugRef.current.axis.y = {
|
|
107
|
+
offset: pos.offset,
|
|
108
|
+
ratio: pos.offsetRatio,
|
|
109
|
+
length: pos.elementLength,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
63
112
|
setP({ x: lastXRef.current, y: lastYRef.current });
|
|
64
113
|
},
|
|
65
114
|
});
|
|
66
115
|
|
|
67
116
|
const handlePointerDown = (e: TouchEvent) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
117
|
+
if (debug) {
|
|
118
|
+
debugRef.current.lastEvent = { x: e.detail.x, y: e.detail.y };
|
|
119
|
+
}
|
|
120
|
+
frameRef.refreshRect(() => {
|
|
121
|
+
axisY.handlePointerDown(e);
|
|
122
|
+
axisX.handlePointerDown(e);
|
|
123
|
+
});
|
|
71
124
|
};
|
|
72
125
|
|
|
73
126
|
const handlePointerMove = (e: TouchEvent) => {
|
|
127
|
+
if (debug) {
|
|
128
|
+
debugRef.current.lastEvent = { x: e.detail.x, y: e.detail.y };
|
|
129
|
+
}
|
|
74
130
|
axisY.handlePointerMove(e);
|
|
75
131
|
axisX.handlePointerMove(e);
|
|
76
132
|
};
|
|
77
133
|
|
|
78
134
|
const handlePointerUp = (e: TouchEvent) => {
|
|
135
|
+
if (debug) {
|
|
136
|
+
debugRef.current.lastEvent = { x: e.detail.x, y: e.detail.y };
|
|
137
|
+
}
|
|
79
138
|
axisY.handlePointerUp(e);
|
|
80
139
|
axisX.handlePointerUp(e);
|
|
81
140
|
};
|
|
@@ -107,6 +166,7 @@ function usePointerPoint({
|
|
|
107
166
|
bindmouseup: bindPointer.bindmouseup,
|
|
108
167
|
bindlayoutchange: handleElementLayoutChange,
|
|
109
168
|
},
|
|
169
|
+
debug: debug ? debugRef.current : undefined,
|
|
110
170
|
};
|
|
111
171
|
}
|
|
112
172
|
|