@ezpg/app-ui 0.8.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 (52) hide show
  1. package/CHANGELOG.md +12 -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/module/templates/index.js +1 -0
  19. package/lib/module/templates/index.js.map +1 -1
  20. package/lib/module/templates/intro-template.js +136 -0
  21. package/lib/module/templates/intro-template.js.map +1 -0
  22. package/lib/typescript/src/adjust/adjust-template.d.ts +13 -0
  23. package/lib/typescript/src/adjust/adjust-template.d.ts.map +1 -0
  24. package/lib/typescript/src/adjust/color-adjust-note.d.ts +10 -0
  25. package/lib/typescript/src/adjust/color-adjust-note.d.ts.map +1 -0
  26. package/lib/typescript/src/adjust/color-track.d.ts +12 -0
  27. package/lib/typescript/src/adjust/color-track.d.ts.map +1 -0
  28. package/lib/typescript/src/adjust/dial-strip.d.ts +16 -0
  29. package/lib/typescript/src/adjust/dial-strip.d.ts.map +1 -0
  30. package/lib/typescript/src/adjust/hsl.d.ts +4 -0
  31. package/lib/typescript/src/adjust/hsl.d.ts.map +1 -0
  32. package/lib/typescript/src/adjust/index.d.ts +7 -0
  33. package/lib/typescript/src/adjust/index.d.ts.map +1 -0
  34. package/lib/typescript/src/adjust/scrub-ruler.d.ts +13 -0
  35. package/lib/typescript/src/adjust/scrub-ruler.d.ts.map +1 -0
  36. package/lib/typescript/src/adjust.d.ts +2 -0
  37. package/lib/typescript/src/adjust.d.ts.map +1 -0
  38. package/lib/typescript/src/templates/index.d.ts +2 -0
  39. package/lib/typescript/src/templates/index.d.ts.map +1 -1
  40. package/lib/typescript/src/templates/intro-template.d.ts +16 -0
  41. package/lib/typescript/src/templates/intro-template.d.ts.map +1 -0
  42. package/package.json +6 -1
  43. package/src/adjust/adjust-template.tsx +89 -0
  44. package/src/adjust/color-adjust-note.tsx +61 -0
  45. package/src/adjust/color-track.tsx +140 -0
  46. package/src/adjust/dial-strip.tsx +142 -0
  47. package/src/adjust/hsl.ts +37 -0
  48. package/src/adjust/index.ts +9 -0
  49. package/src/adjust/scrub-ruler.tsx +160 -0
  50. package/src/adjust.tsx +1 -0
  51. package/src/templates/index.ts +2 -0
  52. package/src/templates/intro-template.tsx +153 -0
@@ -0,0 +1,61 @@
1
+ import { View, type StyleProp, type ViewStyle } from 'react-native';
2
+ import { Text } from '../components/text/text';
3
+ import { makeStyles } from '../utils/styles';
4
+
5
+ export type ColorAdjustNoteProps = {
6
+ original: string;
7
+ applied: string;
8
+ title: string;
9
+ detail?: string;
10
+ style?: StyleProp<ViewStyle>;
11
+ };
12
+
13
+ const useStyles = makeStyles((t) => ({
14
+ root: {
15
+ flexDirection: 'row',
16
+ alignItems: 'center',
17
+ gap: t.space[2],
18
+ marginHorizontal: t.layout.screenX,
19
+ paddingHorizontal: t.space[3],
20
+ paddingVertical: t.space[2],
21
+ borderRadius: t.radius.lg,
22
+ borderWidth: 1,
23
+ borderColor: t.colors.border,
24
+ },
25
+ sw: { width: t.space[5], height: t.space[5], borderRadius: t.radius.sm },
26
+ text: { flex: 1 },
27
+ }));
28
+
29
+ export function ColorAdjustNote({
30
+ original,
31
+ applied,
32
+ title,
33
+ detail,
34
+ style,
35
+ }: ColorAdjustNoteProps) {
36
+ const s = useStyles();
37
+ const changed = original.toUpperCase() !== applied.toUpperCase();
38
+ return (
39
+ <View
40
+ style={[s.root, style]}
41
+ accessible
42
+ accessibilityLabel={[title, detail].filter(Boolean).join(', ')}
43
+ >
44
+ {changed ? (
45
+ <>
46
+ <View style={[s.sw, { backgroundColor: original }]} />
47
+ <Text variant="caption" tone="muted">
48
+ →
49
+ </Text>
50
+ </>
51
+ ) : null}
52
+ <View style={[s.sw, { backgroundColor: applied }]} />
53
+ <Text variant="caption" style={s.text} numberOfLines={2}>
54
+ <Text variant="caption" weight="semibold">
55
+ {title}
56
+ </Text>
57
+ {detail ? ` · ${detail}` : ''}
58
+ </Text>
59
+ </View>
60
+ );
61
+ }
@@ -0,0 +1,140 @@
1
+ import { useMemo, useRef, useState } from 'react';
2
+ import {
3
+ PanResponder,
4
+ View,
5
+ type LayoutChangeEvent,
6
+ type StyleProp,
7
+ type ViewStyle,
8
+ } from 'react-native';
9
+ import Svg, { Defs, LinearGradient, Rect, Stop } from 'react-native-svg';
10
+ import { Text } from '../components/text/text';
11
+ import { useTheme } from '../theme/theme-provider';
12
+ import { makeStyles } from '../utils/styles';
13
+ import { clamp, hslToHex } from './hsl';
14
+
15
+ export type ColorTrackProps = {
16
+ kind: 'hue' | 'saturation';
17
+ hue: number;
18
+ saturation: number;
19
+ lightness?: number;
20
+ onChange: (value: number) => void;
21
+ label: string;
22
+ style?: StyleProp<ViewStyle>;
23
+ };
24
+
25
+ const useStyles = makeStyles((t) => ({
26
+ root: { gap: t.space[2], paddingHorizontal: t.layout.screenX },
27
+ track: { height: t.space[8], justifyContent: 'center' },
28
+ knob: {
29
+ position: 'absolute',
30
+ width: t.space[8],
31
+ height: t.space[8],
32
+ borderRadius: t.radius.full,
33
+ borderWidth: 3,
34
+ borderColor: t.colors.background,
35
+ boxShadow: t.shadow.md,
36
+ },
37
+ }));
38
+
39
+ export function ColorTrack({
40
+ kind,
41
+ hue,
42
+ saturation,
43
+ lightness = 45,
44
+ onChange,
45
+ label,
46
+ style,
47
+ }: ColorTrackProps) {
48
+ const t = useTheme();
49
+ const s = useStyles();
50
+ const [width, setWidth] = useState(0);
51
+ const max = kind === 'hue' ? 360 : 100;
52
+ const value = kind === 'hue' ? hue : saturation;
53
+ const latest = useRef({ width, onChange, max });
54
+ latest.current = { width, onChange, max };
55
+ const pan = useMemo(
56
+ () =>
57
+ PanResponder.create({
58
+ onStartShouldSetPanResponder: () => true,
59
+ onMoveShouldSetPanResponder: () => true,
60
+ onPanResponderTerminationRequest: () => false,
61
+ onPanResponderGrant: (e) => pick(e.nativeEvent.locationX),
62
+ onPanResponderMove: (e) => pick(e.nativeEvent.locationX),
63
+ }),
64
+ []
65
+ );
66
+ function pick(x: number) {
67
+ const { width: w, onChange: change, max: m } = latest.current;
68
+ if (w > 0) change(Math.round(clamp(x / w, 0, 1) * m));
69
+ }
70
+ const stops =
71
+ kind === 'hue'
72
+ ? Array.from({ length: 13 }, (_, i) =>
73
+ hslToHex(i * 30, saturation, lightness)
74
+ )
75
+ : [hslToHex(hue, 0, lightness), hslToHex(hue, 100, lightness)];
76
+ const knob = t.space[8];
77
+ const step = kind === 'hue' ? 10 : 5;
78
+ return (
79
+ <View style={[s.root, style]}>
80
+ <Text variant="caption" tone="muted">
81
+ {label}
82
+ </Text>
83
+ <View
84
+ {...pan.panHandlers}
85
+ onLayout={(e: LayoutChangeEvent) =>
86
+ setWidth(e.nativeEvent.layout.width)
87
+ }
88
+ accessible
89
+ accessibilityRole="adjustable"
90
+ accessibilityLabel={label}
91
+ accessibilityValue={{ min: 0, max, now: value }}
92
+ accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]}
93
+ onAccessibilityAction={(e) =>
94
+ onChange(
95
+ clamp(
96
+ value + (e.nativeEvent.actionName === 'increment' ? step : -step),
97
+ 0,
98
+ max
99
+ )
100
+ )
101
+ }
102
+ style={s.track}
103
+ >
104
+ {width > 0 ? (
105
+ <Svg width={width} height={knob} pointerEvents="none">
106
+ <Defs>
107
+ <LinearGradient id={`g-${kind}`} x1="0" y1="0" x2="1" y2="0">
108
+ {stops.map((c, i) => (
109
+ <Stop key={i} offset={i / (stops.length - 1)} stopColor={c} />
110
+ ))}
111
+ </LinearGradient>
112
+ </Defs>
113
+ <Rect
114
+ x={0}
115
+ y={0}
116
+ width={width}
117
+ height={knob}
118
+ rx={knob / 2}
119
+ fill={`url(#g-${kind})`}
120
+ />
121
+ </Svg>
122
+ ) : null}
123
+ <View
124
+ pointerEvents="none"
125
+ style={[
126
+ s.knob,
127
+ {
128
+ left: clamp(
129
+ (value / max) * width - knob / 2,
130
+ 0,
131
+ Math.max(0, width - knob)
132
+ ),
133
+ backgroundColor: hslToHex(hue, saturation, lightness),
134
+ },
135
+ ]}
136
+ />
137
+ </View>
138
+ </View>
139
+ );
140
+ }
@@ -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';
@@ -18,6 +18,8 @@ export type {
18
18
  } from './editor-template';
19
19
  export { ListTemplate } from './list-template';
20
20
  export type { ListTemplateProps, ListTemplateStatus } from './list-template';
21
+ export { IntroTemplate } from './intro-template';
22
+ export type { IntroPage, IntroTemplateProps } from './intro-template';
21
23
  export { ResultTemplate } from './result-template';
22
24
  export type { ResultPreview, ResultTemplateProps } from './result-template';
23
25
  export { SystemTemplate } from './system-template';