@yamatozhen/design_system 1.1.0 → 1.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.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/template/app/themes/dark-mc 2.css +0 -51
  3. package/template/app/themes/light 2.css +0 -51
  4. package/template/app/themes/light-mc 2.css +0 -51
  5. package/template/app/themes/theme 2.css +0 -272
  6. package/template/components/tools/CustomScrollbar 2.tsx +0 -107
  7. package/template/components/tools/Divider 2.tsx +0 -11
  8. package/template/components/tools/ReduceMotionContext 2.tsx +0 -5
  9. package/template/components/tools/Sinewave 2.tsx +0 -206
  10. package/template/components/tools/SinewaveProgress 2.tsx +0 -140
  11. package/template/components/tools/badge/Badge 2.tsx +0 -28
  12. package/template/components/tools/flubber.d 2.ts +0 -7
  13. package/template/components/tools/input/Input 2.tsx +0 -99
  14. package/template/components/tools/input/Input.module 2.css +0 -45
  15. package/template/components/tools/label/Icon 2.tsx +0 -39
  16. package/template/components/tools/label/Label 2.tsx +0 -150
  17. package/template/components/tools/mobileViewProvider 2.tsx +0 -53
  18. package/template/components/tools/ripple/ripple 2.css +0 -38
  19. package/template/components/tools/ripple/ripple 2.tsx +0 -78
  20. package/template/components/tools/shape/Shape 2.tsx +0 -313
  21. package/template/components/tools/shape/Shape.module 2.css +0 -21
  22. package/template/components/tools/shape/ShapeLoader 2.tsx +0 -104
  23. package/template/components/tools/shape/ShapePaths 2.ts +0 -116
  24. package/template/components/tools/switch/Switch 2.tsx +0 -48
  25. package/template/components/tools/switch/Switch.module 2.css +0 -102
  26. package/template/components/tools/useBodyScrollLock 2.tsx +0 -27
  27. package/template/components/tools/useImageColor 2.ts +0 -47
  28. package/template/components/tools/useNavSheetDrag 2.tsx +0 -196
  29. package/template/public/fonts/material-symbols/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght 2.woff2 +0 -0
@@ -1,196 +0,0 @@
1
- "use client";
2
-
3
- import { useEffect, useRef, useState } from "react";
4
- import { animate, useMotionValue } from "framer-motion";
5
-
6
- type PullSheetOptions = {
7
- /** Controlled open state (menu button / programmatic). */
8
- open: boolean;
9
- setOpen: (open: boolean) => void;
10
- /** Wrapper that catches the touches (the whole bar container). */
11
- surfaceRef: React.RefObject<HTMLElement | null>;
12
- /** Inner scroller — touches starting here scroll natively, never drag. */
13
- scrollRef?: React.RefObject<HTMLElement | null>;
14
- /** Returns the panel's open height in px (e.g. 98dvh minus the button row). */
15
- getMaxHeight: () => number;
16
- /**
17
- * Gate + mount signal. Pass `!!isMobile`. The variant mounts late
18
- * (useMediaQuery resolves false→true on the client); flipping this re-runs
19
- * the effects so they bind once the elements exist, instead of running while
20
- * the refs are still null and bailing.
21
- */
22
- enabled?: boolean;
23
- };
24
-
25
- const TAP_THRESHOLD = 8; // px before a touch counts as a drag
26
- const AXIS_LOCK_RATIO = 1.2; // |dy| must beat |dx| by this to claim vertical
27
- const OPEN_FRACTION = 0.4; // released past this fraction of open → snap open
28
- const FLICK_VELOCITY = 0.5; // px/ms; a flick this fast forces open/close
29
- const RUBBER_BAND = 0.2; // resistance past the open limit
30
- // Bouncy spring tuned to feel like cubic-bezier(0.01, 1.25, 0.23, 1.01):
31
- // ~25% overshoot, ~500ms settle. Tune stiffness/damping to taste.
32
- const SNAP_SPRING = {
33
- type: "spring",
34
- stiffness: 720,
35
- damping: 64,
36
- mass: 2,
37
- } as const;
38
-
39
- export function useNavSheetDrag({
40
- open,
41
- setOpen,
42
- surfaceRef,
43
- scrollRef,
44
- getMaxHeight,
45
- enabled = true,
46
- }: PullSheetOptions) {
47
- // Height is a motion value → Framer writes it to the DOM off the React render
48
- // loop, so the per-frame drag never triggers a React re-render.
49
- const height = useMotionValue(0);
50
- const [isDragging, setIsDragging] = useState(false);
51
- const [direction, setDirection] = useState<1 | -1>(1); // 1 = down/open, -1 = up/close
52
-
53
- const dragging = useRef(false);
54
- const abandoned = useRef(false);
55
- const startX = useRef(0);
56
- const startY = useRef(0);
57
- const startH = useRef(0);
58
- const maxH = useRef(0);
59
- const lastY = useRef(0);
60
- const lastT = useRef(0);
61
- const velocity = useRef(0);
62
- const dirRef = useRef<1 | -1>(1);
63
- const animRef = useRef<ReturnType<typeof animate> | null>(null);
64
-
65
- const stopAnim = () => {
66
- animRef.current?.stop();
67
- animRef.current = null;
68
- };
69
-
70
- const springTo = (px: number) => {
71
- stopAnim();
72
- animRef.current = animate(height, px, SNAP_SPRING);
73
- };
74
-
75
- // Controlled open (menu button / route change) — skip while a drag owns it.
76
- useEffect(() => {
77
- if (!enabled || dragging.current) return;
78
- springTo(open ? getMaxHeight() : 0);
79
- // eslint-disable-next-line react-hooks/exhaustive-deps
80
- }, [open, enabled]);
81
-
82
- // Set the initial height once enabled, without animating.
83
- useEffect(() => {
84
- if (!enabled) return;
85
- height.set(open ? getMaxHeight() : 0);
86
- // eslint-disable-next-line react-hooks/exhaustive-deps
87
- }, [enabled]);
88
-
89
- useEffect(() => {
90
- if (!enabled) return;
91
- const surface = surfaceRef.current;
92
- if (!surface) return;
93
-
94
- const onStart = (e: TouchEvent) => {
95
- const t = e.touches[0];
96
- dragging.current = false;
97
- abandoned.current = false;
98
- velocity.current = 0;
99
- startX.current = t.clientX;
100
- startY.current = lastY.current = t.clientY;
101
- lastT.current = e.timeStamp;
102
- startH.current = height.get(); // interruptible mid-spring
103
- maxH.current = getMaxHeight();
104
-
105
- // Open + finger in the scroll list → native scroll owns it.
106
- // Only hand off to native scroll when the list is actually scrolled —
107
- // otherwise (items fit, scrollTop 0) the drag hook keeps the gesture so
108
- // an up-swipe can close the sheet.
109
- const list = scrollRef?.current;
110
- if (
111
- open &&
112
- list &&
113
- list.contains(t.target as Node) &&
114
- list.scrollTop > 0
115
- ) {
116
- abandoned.current = true;
117
- }
118
- };
119
-
120
- const onMove = (e: TouchEvent) => {
121
- if (abandoned.current) return;
122
- const t = e.touches[0];
123
- const dx = t.clientX - startX.current;
124
- const dy = t.clientY - startY.current;
125
-
126
- if (!dragging.current) {
127
- if (Math.abs(dx) < TAP_THRESHOLD && Math.abs(dy) < TAP_THRESHOLD)
128
- return;
129
- if (Math.abs(dy) <= Math.abs(dx) * AXIS_LOCK_RATIO) {
130
- abandoned.current = true;
131
- return;
132
- }
133
- dragging.current = true;
134
- setIsDragging(true);
135
- stopAnim();
136
- }
137
-
138
- e.preventDefault(); // we own it → kill page scroll / pull-to-refresh
139
-
140
- const now = e.timeStamp;
141
- const dt = now - lastT.current;
142
- const stepY = t.clientY - lastY.current;
143
- if (dt > 0) velocity.current = stepY / dt;
144
-
145
- // Arrow direction follows the finger; only re-render on a real flip.
146
- if (stepY > 0.5 && dirRef.current !== 1) {
147
- dirRef.current = 1;
148
- setDirection(1);
149
- } else if (stepY < -0.5 && dirRef.current !== -1) {
150
- dirRef.current = -1;
151
- setDirection(-1);
152
- }
153
-
154
- lastY.current = t.clientY;
155
- lastT.current = now;
156
-
157
- const M = maxH.current;
158
- let h = startH.current + dy;
159
- if (h < 0) h = 0;
160
- else if (h > M) h = M + (h - M) * RUBBER_BAND; // clamp → no infinite pull
161
- height.set(h);
162
- };
163
-
164
- const settle = () => {
165
- if (!dragging.current) return;
166
- dragging.current = false;
167
- setIsDragging(false);
168
- const M = maxH.current || getMaxHeight();
169
- const h = height.get();
170
- const v = velocity.current;
171
-
172
- let toOpen: boolean;
173
- if (v > FLICK_VELOCITY) toOpen = true;
174
- else if (v < -FLICK_VELOCITY) toOpen = false;
175
- else toOpen = h > M * OPEN_FRACTION;
176
-
177
- springTo(toOpen ? M : 0);
178
- setOpen(toOpen);
179
- };
180
-
181
- surface.addEventListener("touchstart", onStart, { passive: true });
182
- surface.addEventListener("touchmove", onMove, { passive: false });
183
- surface.addEventListener("touchend", settle, { passive: true });
184
- surface.addEventListener("touchcancel", settle, { passive: true });
185
-
186
- return () => {
187
- surface.removeEventListener("touchstart", onStart);
188
- surface.removeEventListener("touchmove", onMove);
189
- surface.removeEventListener("touchend", settle);
190
- surface.removeEventListener("touchcancel", settle);
191
- };
192
- // eslint-disable-next-line react-hooks/exhaustive-deps
193
- }, [enabled, open, setOpen, surfaceRef, scrollRef, getMaxHeight]);
194
-
195
- return { height, isDragging, direction };
196
- }