@ezpg/app-ui 0.9.0 → 0.10.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 (42) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/lib/module/adjust/adjust-template.js +92 -0
  3. package/lib/module/adjust/adjust-template.js.map +1 -0
  4. package/lib/module/adjust/color-adjust-note.js +67 -0
  5. package/lib/module/adjust/color-adjust-note.js.map +1 -0
  6. package/lib/module/adjust/color-track.js +132 -0
  7. package/lib/module/adjust/color-track.js.map +1 -0
  8. package/lib/module/adjust/dial-strip.js +126 -0
  9. package/lib/module/adjust/dial-strip.js.map +1 -0
  10. package/lib/module/adjust/hsl.js +29 -0
  11. package/lib/module/adjust/hsl.js.map +1 -0
  12. package/lib/module/adjust/index.js +9 -0
  13. package/lib/module/adjust/index.js.map +1 -0
  14. package/lib/module/adjust/scrub-ruler.js +159 -0
  15. package/lib/module/adjust/scrub-ruler.js.map +1 -0
  16. package/lib/module/adjust.js +4 -0
  17. package/lib/module/adjust.js.map +1 -0
  18. package/lib/typescript/src/adjust/adjust-template.d.ts +13 -0
  19. package/lib/typescript/src/adjust/adjust-template.d.ts.map +1 -0
  20. package/lib/typescript/src/adjust/color-adjust-note.d.ts +10 -0
  21. package/lib/typescript/src/adjust/color-adjust-note.d.ts.map +1 -0
  22. package/lib/typescript/src/adjust/color-track.d.ts +12 -0
  23. package/lib/typescript/src/adjust/color-track.d.ts.map +1 -0
  24. package/lib/typescript/src/adjust/dial-strip.d.ts +16 -0
  25. package/lib/typescript/src/adjust/dial-strip.d.ts.map +1 -0
  26. package/lib/typescript/src/adjust/hsl.d.ts +4 -0
  27. package/lib/typescript/src/adjust/hsl.d.ts.map +1 -0
  28. package/lib/typescript/src/adjust/index.d.ts +7 -0
  29. package/lib/typescript/src/adjust/index.d.ts.map +1 -0
  30. package/lib/typescript/src/adjust/scrub-ruler.d.ts +13 -0
  31. package/lib/typescript/src/adjust/scrub-ruler.d.ts.map +1 -0
  32. package/lib/typescript/src/adjust.d.ts +2 -0
  33. package/lib/typescript/src/adjust.d.ts.map +1 -0
  34. package/package.json +6 -1
  35. package/src/adjust/adjust-template.tsx +89 -0
  36. package/src/adjust/color-adjust-note.tsx +61 -0
  37. package/src/adjust/color-track.tsx +140 -0
  38. package/src/adjust/dial-strip.tsx +142 -0
  39. package/src/adjust/hsl.ts +37 -0
  40. package/src/adjust/index.ts +9 -0
  41. package/src/adjust/scrub-ruler.tsx +160 -0
  42. package/src/adjust.tsx +1 -0
@@ -0,0 +1,142 @@
1
+ import { ScrollView, View, type StyleProp, type ViewStyle } from 'react-native';
2
+ import Svg, { Circle } from 'react-native-svg';
3
+ import { Text } from '../components/text/text';
4
+ import { PressableBase } from '../internal/pressable-base';
5
+ import { useTheme } from '../theme/theme-provider';
6
+ import { makeStyles } from '../utils/styles';
7
+
8
+ export type DialItem = {
9
+ key: string;
10
+ label: string;
11
+ value?: number;
12
+ max?: number;
13
+ color?: string;
14
+ };
15
+
16
+ export type DialStripProps = {
17
+ items: readonly DialItem[];
18
+ selected: string;
19
+ onSelect: (key: string) => void;
20
+ style?: StyleProp<ViewStyle>;
21
+ };
22
+
23
+ const SIZE = 48;
24
+ const STROKE = 3;
25
+
26
+ const useStyles = makeStyles((t) => ({
27
+ row: { gap: t.space[3], paddingHorizontal: t.layout.screenX },
28
+ item: { alignItems: 'center', gap: t.space[1] },
29
+ ring: {
30
+ width: SIZE,
31
+ height: SIZE,
32
+ alignItems: 'center',
33
+ justifyContent: 'center',
34
+ },
35
+ value: { position: 'absolute' },
36
+ }));
37
+
38
+ const signed = (v: number) => (v > 0 ? `+${v}` : String(v));
39
+
40
+ function Ring({ item, on }: { item: DialItem; on: boolean }) {
41
+ const t = useTheme();
42
+ const s = useStyles();
43
+ const r = (SIZE - STROKE) / 2;
44
+ const c = 2 * Math.PI * r;
45
+ if (item.color) {
46
+ return (
47
+ <View style={s.ring}>
48
+ <Svg width={SIZE} height={SIZE}>
49
+ <Circle
50
+ cx={SIZE / 2}
51
+ cy={SIZE / 2}
52
+ r={r}
53
+ fill={item.color}
54
+ stroke={on ? t.colors.primary : t.colors.border}
55
+ strokeWidth={STROKE}
56
+ />
57
+ </Svg>
58
+ </View>
59
+ );
60
+ }
61
+ const v = item.value ?? 0;
62
+ const frac = Math.min(1, Math.abs(v) / (item.max ?? 2));
63
+ return (
64
+ <View style={s.ring}>
65
+ <Svg width={SIZE} height={SIZE}>
66
+ <Circle
67
+ cx={SIZE / 2}
68
+ cy={SIZE / 2}
69
+ r={r}
70
+ fill={on ? t.colors.primaryTint : t.colors.muted}
71
+ stroke={t.colors.border}
72
+ strokeWidth={STROKE}
73
+ />
74
+ {v ? (
75
+ <Circle
76
+ cx={SIZE / 2}
77
+ cy={SIZE / 2}
78
+ r={r}
79
+ fill="none"
80
+ stroke={on ? t.colors.primary : t.colors.primaryEdge}
81
+ strokeWidth={STROKE}
82
+ strokeLinecap="round"
83
+ strokeDasharray={`${c * frac} ${c}`}
84
+ transform={`${v < 0 ? `translate(${SIZE},0) scale(-1,1) ` : ''}rotate(-90 ${SIZE / 2} ${SIZE / 2})`}
85
+ />
86
+ ) : null}
87
+ </Svg>
88
+ <Text
89
+ variant="caption"
90
+ weight={on ? 'bold' : 'medium'}
91
+ tone={on ? 'primary' : 'muted'}
92
+ style={s.value}
93
+ >
94
+ {v ? signed(v) : '0'}
95
+ </Text>
96
+ </View>
97
+ );
98
+ }
99
+
100
+ export function DialStrip({
101
+ items,
102
+ selected,
103
+ onSelect,
104
+ style,
105
+ }: DialStripProps) {
106
+ const s = useStyles();
107
+ return (
108
+ <ScrollView
109
+ horizontal
110
+ showsHorizontalScrollIndicator={false}
111
+ contentContainerStyle={s.row}
112
+ style={style}
113
+ >
114
+ {items.map((item) => {
115
+ const on = item.key === selected;
116
+ return (
117
+ <PressableBase
118
+ key={item.key}
119
+ onPress={() => onSelect(item.key)}
120
+ accessibilityRole="button"
121
+ accessibilityLabel={
122
+ item.color
123
+ ? item.label
124
+ : `${item.label} ${signed(item.value ?? 0)}`
125
+ }
126
+ accessibilityState={{ selected: on }}
127
+ style={s.item}
128
+ >
129
+ <Ring item={item} on={on} />
130
+ <Text
131
+ variant="caption"
132
+ weight={on ? 'bold' : 'regular'}
133
+ tone={on ? 'primary' : 'muted'}
134
+ >
135
+ {item.label}
136
+ </Text>
137
+ </PressableBase>
138
+ );
139
+ })}
140
+ </ScrollView>
141
+ );
142
+ }
@@ -0,0 +1,37 @@
1
+ export function hslToHex(h: number, s: number, l: number): string {
2
+ const sat = s / 100;
3
+ const light = l / 100;
4
+ const a = sat * Math.min(light, 1 - light);
5
+ const channel = (n: number) => {
6
+ const k = (n + h / 30) % 12;
7
+ const v = light - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
8
+ return Math.round(v * 255)
9
+ .toString(16)
10
+ .padStart(2, '0');
11
+ };
12
+ return `#${channel(0)}${channel(8)}${channel(4)}`.toUpperCase();
13
+ }
14
+
15
+ export function hexToHsl(hex: string): [number, number, number] {
16
+ const v = hex.replace('#', '');
17
+ const [r, g, b] = [0, 2, 4].map(
18
+ (i) => parseInt(v.slice(i, i + 2), 16) / 255
19
+ ) as [number, number, number];
20
+ const mx = Math.max(r, g, b);
21
+ const mn = Math.min(r, g, b);
22
+ const l = (mx + mn) / 2;
23
+ if (mx === mn) return [0, 0, l * 100];
24
+ const d = mx - mn;
25
+ const s = l > 0.5 ? d / (2 - mx - mn) : d / (mx + mn);
26
+ const h =
27
+ mx === r
28
+ ? (g - b) / d + (g < b ? 6 : 0)
29
+ : mx === g
30
+ ? (b - r) / d + 2
31
+ : (r - g) / d + 4;
32
+ return [h * 60, s * 100, l * 100];
33
+ }
34
+
35
+ export function clamp(value: number, min: number, max: number): number {
36
+ return Math.max(min, Math.min(max, value));
37
+ }
@@ -0,0 +1,9 @@
1
+ export { AdjustTemplate, type AdjustTemplateProps } from './adjust-template';
2
+ export {
3
+ ColorAdjustNote,
4
+ type ColorAdjustNoteProps,
5
+ } from './color-adjust-note';
6
+ export { ColorTrack, type ColorTrackProps } from './color-track';
7
+ export { DialStrip, type DialItem, type DialStripProps } from './dial-strip';
8
+ export { ScrubRuler, type ScrubRulerProps } from './scrub-ruler';
9
+ export { hexToHsl, hslToHex } from './hsl';
@@ -0,0 +1,160 @@
1
+ import { useMemo, useRef } from 'react';
2
+ import {
3
+ PanResponder,
4
+ View,
5
+ type StyleProp,
6
+ type ViewStyle,
7
+ } from 'react-native';
8
+ import { Text } from '../components/text/text';
9
+ import { useTheme } from '../theme/theme-provider';
10
+ import { makeStyles } from '../utils/styles';
11
+ import { clamp } from './hsl';
12
+
13
+ export type ScrubRulerProps = {
14
+ value: number;
15
+ min?: number;
16
+ max?: number;
17
+ onChange: (value: number) => void;
18
+ startLabel?: string;
19
+ endLabel?: string;
20
+ accessibilityLabel: string;
21
+ style?: StyleProp<ViewStyle>;
22
+ };
23
+
24
+ const MINOR = 3;
25
+ const TICK = 2;
26
+
27
+ const useStyles = makeStyles((t) => ({
28
+ root: {
29
+ height: t.controlSize.lg,
30
+ marginHorizontal: t.layout.screenX,
31
+ overflow: 'hidden',
32
+ },
33
+ ticks: {
34
+ position: 'absolute',
35
+ top: t.space[2],
36
+ left: '50%',
37
+ flexDirection: 'row',
38
+ alignItems: 'flex-end',
39
+ },
40
+ tick: { width: TICK, height: t.space[2], backgroundColor: t.colors.input },
41
+ major: { height: t.space[4], backgroundColor: t.colors.mutedForeground },
42
+ zero: { height: t.space[5], backgroundColor: t.colors.foreground },
43
+ needle: {
44
+ position: 'absolute',
45
+ left: '50%',
46
+ top: t.space[1],
47
+ width: TICK,
48
+ marginLeft: -TICK / 2,
49
+ height: t.space[6] + t.space[1],
50
+ borderRadius: t.radius.sm,
51
+ backgroundColor: t.colors.primary,
52
+ },
53
+ ends: {
54
+ position: 'absolute',
55
+ left: 0,
56
+ right: 0,
57
+ bottom: 0,
58
+ flexDirection: 'row',
59
+ justifyContent: 'space-between',
60
+ },
61
+ }));
62
+
63
+ export function ScrubRuler({
64
+ value,
65
+ min = -2,
66
+ max = 2,
67
+ onChange,
68
+ startLabel,
69
+ endLabel,
70
+ accessibilityLabel,
71
+ style,
72
+ }: ScrubRulerProps) {
73
+ const t = useTheme();
74
+ const s = useStyles();
75
+ const step = t.space[8];
76
+ const gap = (step - TICK * (MINOR + 1)) / (MINOR + 1);
77
+ const latest = useRef({ value, onChange, min, max });
78
+ latest.current = { value, onChange, min, max };
79
+ const start = useRef(value);
80
+ const pan = useMemo(
81
+ () =>
82
+ PanResponder.create({
83
+ onStartShouldSetPanResponder: () => true,
84
+ onMoveShouldSetPanResponder: (_, g) => Math.abs(g.dx) > Math.abs(g.dy),
85
+ onPanResponderTerminationRequest: () => false,
86
+ onPanResponderGrant: () => {
87
+ start.current = latest.current.value;
88
+ },
89
+ onPanResponderMove: (_, g) => {
90
+ const {
91
+ onChange: change,
92
+ min: lo,
93
+ max: hi,
94
+ value: now,
95
+ } = latest.current;
96
+ const next = clamp(start.current - Math.round(g.dx / step), lo, hi);
97
+ if (next !== now) change(next);
98
+ },
99
+ }),
100
+ [step]
101
+ );
102
+ const ticks = [];
103
+ for (let v = min; v <= max; v += 1) {
104
+ ticks.push(
105
+ <View
106
+ key={`m${v}`}
107
+ style={[
108
+ s.tick,
109
+ v === 0 ? s.zero : s.major,
110
+ v < max && { marginRight: gap },
111
+ ]}
112
+ />
113
+ );
114
+ if (v < max) {
115
+ for (let j = 0; j < MINOR; j += 1) {
116
+ ticks.push(
117
+ <View key={`${v}-${j}`} style={[s.tick, { marginRight: gap }]} />
118
+ );
119
+ }
120
+ }
121
+ }
122
+ return (
123
+ <View
124
+ {...pan.panHandlers}
125
+ accessible
126
+ accessibilityRole="adjustable"
127
+ accessibilityLabel={accessibilityLabel}
128
+ accessibilityValue={{ min, max, now: value }}
129
+ accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]}
130
+ onAccessibilityAction={(e) =>
131
+ onChange(
132
+ clamp(
133
+ value + (e.nativeEvent.actionName === 'increment' ? 1 : -1),
134
+ min,
135
+ max
136
+ )
137
+ )
138
+ }
139
+ style={[s.root, style]}
140
+ >
141
+ <View
142
+ style={[
143
+ s.ticks,
144
+ { transform: [{ translateX: -(value - min) * step - TICK / 2 }] },
145
+ ]}
146
+ >
147
+ {ticks}
148
+ </View>
149
+ <View style={s.needle} />
150
+ <View style={s.ends}>
151
+ <Text variant="caption" tone="muted">
152
+ {startLabel ?? ''}
153
+ </Text>
154
+ <Text variant="caption" tone="muted">
155
+ {endLabel ?? ''}
156
+ </Text>
157
+ </View>
158
+ </View>
159
+ );
160
+ }
package/src/adjust.tsx ADDED
@@ -0,0 +1 @@
1
+ export * from './adjust/index';