@ezpg/app-ui 0.16.0 → 0.18.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 (194) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/module/blocks/cover-photos/cover-photos.js +165 -0
  3. package/lib/module/blocks/cover-photos/cover-photos.js.map +1 -0
  4. package/lib/module/blocks/cover-photos/index.js +4 -0
  5. package/lib/module/blocks/cover-photos/index.js.map +1 -0
  6. package/lib/module/blocks/detail-editor/compare-slider.js +117 -0
  7. package/lib/module/blocks/detail-editor/compare-slider.js.map +1 -0
  8. package/lib/module/blocks/detail-editor/detail-canvas.js +339 -0
  9. package/lib/module/blocks/detail-editor/detail-canvas.js.map +1 -0
  10. package/lib/module/blocks/detail-editor/detail-composer.js +254 -0
  11. package/lib/module/blocks/detail-editor/detail-composer.js.map +1 -0
  12. package/lib/module/blocks/detail-editor/detail-editor-template.js +102 -0
  13. package/lib/module/blocks/detail-editor/detail-editor-template.js.map +1 -0
  14. package/lib/module/blocks/detail-editor/detail-types.js +64 -0
  15. package/lib/module/blocks/detail-editor/detail-types.js.map +1 -0
  16. package/lib/module/blocks/detail-editor/draft-preview.js +39 -0
  17. package/lib/module/blocks/detail-editor/draft-preview.js.map +1 -0
  18. package/lib/module/blocks/detail-editor/draft-strip.js +97 -0
  19. package/lib/module/blocks/detail-editor/draft-strip.js.map +1 -0
  20. package/lib/module/blocks/detail-editor/editor-bar.js +96 -0
  21. package/lib/module/blocks/detail-editor/editor-bar.js.map +1 -0
  22. package/lib/module/blocks/detail-editor/focus-context.js +5 -0
  23. package/lib/module/blocks/detail-editor/focus-context.js.map +1 -0
  24. package/lib/module/blocks/detail-editor/font-picker.js +74 -0
  25. package/lib/module/blocks/detail-editor/font-picker.js.map +1 -0
  26. package/lib/module/blocks/detail-editor/index.js +16 -0
  27. package/lib/module/blocks/detail-editor/index.js.map +1 -0
  28. package/lib/module/blocks/detail-editor/layout-picker.js +173 -0
  29. package/lib/module/blocks/detail-editor/layout-picker.js.map +1 -0
  30. package/lib/module/blocks/detail-editor/photo-tray.js +144 -0
  31. package/lib/module/blocks/detail-editor/photo-tray.js.map +1 -0
  32. package/lib/module/blocks/detail-editor/structure-picker.js +75 -0
  33. package/lib/module/blocks/detail-editor/structure-picker.js.map +1 -0
  34. package/lib/module/blocks/detail-editor/tool-row.js +63 -0
  35. package/lib/module/blocks/detail-editor/tool-row.js.map +1 -0
  36. package/lib/module/blocks/index.js +3 -0
  37. package/lib/module/blocks/index.js.map +1 -1
  38. package/lib/module/blocks/slider-list/index.js +4 -0
  39. package/lib/module/blocks/slider-list/index.js.map +1 -0
  40. package/lib/module/blocks/slider-list/slider-list.js +45 -0
  41. package/lib/module/blocks/slider-list/slider-list.js.map +1 -0
  42. package/lib/module/blocks/task-tiles/task-tiles.js +1 -1
  43. package/lib/module/blocks/task-tiles/task-tiles.js.map +1 -1
  44. package/lib/module/charts/mini-bars.js +1 -1
  45. package/lib/module/charts/mini-bars.js.map +1 -1
  46. package/lib/module/components/button/button.js +10 -3
  47. package/lib/module/components/button/button.js.map +1 -1
  48. package/lib/module/components/floating-tab-bar/floating-tab-bar.js +103 -0
  49. package/lib/module/components/floating-tab-bar/floating-tab-bar.js.map +1 -0
  50. package/lib/module/components/floating-tab-bar/index.js +4 -0
  51. package/lib/module/components/floating-tab-bar/index.js.map +1 -0
  52. package/lib/module/components/list-row/list-row.js +9 -3
  53. package/lib/module/components/list-row/list-row.js.map +1 -1
  54. package/lib/module/components/section-tabs/index.js +4 -0
  55. package/lib/module/components/section-tabs/index.js.map +1 -0
  56. package/lib/module/components/section-tabs/section-tabs.js +73 -0
  57. package/lib/module/components/section-tabs/section-tabs.js.map +1 -0
  58. package/lib/module/components/slider/index.js +4 -0
  59. package/lib/module/components/slider/index.js.map +1 -0
  60. package/lib/module/components/slider/slider.js +151 -0
  61. package/lib/module/components/slider/slider.js.map +1 -0
  62. package/lib/module/index.js +3 -0
  63. package/lib/module/index.js.map +1 -1
  64. package/lib/module/internal/flush-row.js +5 -0
  65. package/lib/module/internal/flush-row.js.map +1 -0
  66. package/lib/module/internal/pressable-base.js +3 -2
  67. package/lib/module/internal/pressable-base.js.map +1 -1
  68. package/lib/module/internal/tab-icon-pairs.js +25 -0
  69. package/lib/module/internal/tab-icon-pairs.js.map +1 -0
  70. package/lib/module/sortable/block-strip.js +151 -0
  71. package/lib/module/sortable/block-strip.js.map +1 -0
  72. package/lib/module/sortable/index.js +1 -0
  73. package/lib/module/sortable/index.js.map +1 -1
  74. package/lib/module/templates/index.js +1 -0
  75. package/lib/module/templates/index.js.map +1 -1
  76. package/lib/module/templates/parts.js +42 -2
  77. package/lib/module/templates/parts.js.map +1 -1
  78. package/lib/module/templates/sheet-form-template.js +174 -0
  79. package/lib/module/templates/sheet-form-template.js.map +1 -0
  80. package/lib/module/theme/base.js +4 -4
  81. package/lib/typescript/src/blocks/cover-photos/cover-photos.d.ts +16 -0
  82. package/lib/typescript/src/blocks/cover-photos/cover-photos.d.ts.map +1 -0
  83. package/lib/typescript/src/blocks/cover-photos/index.d.ts +2 -0
  84. package/lib/typescript/src/blocks/cover-photos/index.d.ts.map +1 -0
  85. package/lib/typescript/src/blocks/detail-editor/compare-slider.d.ts +8 -0
  86. package/lib/typescript/src/blocks/detail-editor/compare-slider.d.ts.map +1 -0
  87. package/lib/typescript/src/blocks/detail-editor/detail-canvas.d.ts +13 -0
  88. package/lib/typescript/src/blocks/detail-editor/detail-canvas.d.ts.map +1 -0
  89. package/lib/typescript/src/blocks/detail-editor/detail-composer.d.ts +25 -0
  90. package/lib/typescript/src/blocks/detail-editor/detail-composer.d.ts.map +1 -0
  91. package/lib/typescript/src/blocks/detail-editor/detail-editor-template.d.ts +13 -0
  92. package/lib/typescript/src/blocks/detail-editor/detail-editor-template.d.ts.map +1 -0
  93. package/lib/typescript/src/blocks/detail-editor/detail-types.d.ts +55 -0
  94. package/lib/typescript/src/blocks/detail-editor/detail-types.d.ts.map +1 -0
  95. package/lib/typescript/src/blocks/detail-editor/draft-preview.d.ts +8 -0
  96. package/lib/typescript/src/blocks/detail-editor/draft-preview.d.ts.map +1 -0
  97. package/lib/typescript/src/blocks/detail-editor/draft-strip.d.ts +16 -0
  98. package/lib/typescript/src/blocks/detail-editor/draft-strip.d.ts.map +1 -0
  99. package/lib/typescript/src/blocks/detail-editor/editor-bar.d.ts +18 -0
  100. package/lib/typescript/src/blocks/detail-editor/editor-bar.d.ts.map +1 -0
  101. package/lib/typescript/src/blocks/detail-editor/focus-context.d.ts +6 -0
  102. package/lib/typescript/src/blocks/detail-editor/focus-context.d.ts.map +1 -0
  103. package/lib/typescript/src/blocks/detail-editor/font-picker.d.ts +8 -0
  104. package/lib/typescript/src/blocks/detail-editor/font-picker.d.ts.map +1 -0
  105. package/lib/typescript/src/blocks/detail-editor/index.d.ts +14 -0
  106. package/lib/typescript/src/blocks/detail-editor/index.d.ts.map +1 -0
  107. package/lib/typescript/src/blocks/detail-editor/layout-picker.d.ts +11 -0
  108. package/lib/typescript/src/blocks/detail-editor/layout-picker.d.ts.map +1 -0
  109. package/lib/typescript/src/blocks/detail-editor/photo-tray.d.ts +15 -0
  110. package/lib/typescript/src/blocks/detail-editor/photo-tray.d.ts.map +1 -0
  111. package/lib/typescript/src/blocks/detail-editor/structure-picker.d.ts +13 -0
  112. package/lib/typescript/src/blocks/detail-editor/structure-picker.d.ts.map +1 -0
  113. package/lib/typescript/src/blocks/detail-editor/tool-row.d.ts +13 -0
  114. package/lib/typescript/src/blocks/detail-editor/tool-row.d.ts.map +1 -0
  115. package/lib/typescript/src/blocks/index.d.ts +3 -0
  116. package/lib/typescript/src/blocks/index.d.ts.map +1 -1
  117. package/lib/typescript/src/blocks/slider-list/index.d.ts +2 -0
  118. package/lib/typescript/src/blocks/slider-list/index.d.ts.map +1 -0
  119. package/lib/typescript/src/blocks/slider-list/slider-list.d.ts +17 -0
  120. package/lib/typescript/src/blocks/slider-list/slider-list.d.ts.map +1 -0
  121. package/lib/typescript/src/components/button/button.d.ts.map +1 -1
  122. package/lib/typescript/src/components/floating-tab-bar/floating-tab-bar.d.ts +20 -0
  123. package/lib/typescript/src/components/floating-tab-bar/floating-tab-bar.d.ts.map +1 -0
  124. package/lib/typescript/src/components/floating-tab-bar/index.d.ts +2 -0
  125. package/lib/typescript/src/components/floating-tab-bar/index.d.ts.map +1 -0
  126. package/lib/typescript/src/components/list-row/list-row.d.ts.map +1 -1
  127. package/lib/typescript/src/components/section-tabs/index.d.ts +2 -0
  128. package/lib/typescript/src/components/section-tabs/index.d.ts.map +1 -0
  129. package/lib/typescript/src/components/section-tabs/section-tabs.d.ts +14 -0
  130. package/lib/typescript/src/components/section-tabs/section-tabs.d.ts.map +1 -0
  131. package/lib/typescript/src/components/slider/index.d.ts +2 -0
  132. package/lib/typescript/src/components/slider/index.d.ts.map +1 -0
  133. package/lib/typescript/src/components/slider/slider.d.ts +14 -0
  134. package/lib/typescript/src/components/slider/slider.d.ts.map +1 -0
  135. package/lib/typescript/src/index.d.ts +3 -0
  136. package/lib/typescript/src/index.d.ts.map +1 -1
  137. package/lib/typescript/src/internal/flush-row.d.ts +2 -0
  138. package/lib/typescript/src/internal/flush-row.d.ts.map +1 -0
  139. package/lib/typescript/src/internal/pressable-base.d.ts +2 -1
  140. package/lib/typescript/src/internal/pressable-base.d.ts.map +1 -1
  141. package/lib/typescript/src/internal/tab-icon-pairs.d.ts +23 -0
  142. package/lib/typescript/src/internal/tab-icon-pairs.d.ts.map +1 -0
  143. package/lib/typescript/src/sortable/block-strip.d.ts +14 -0
  144. package/lib/typescript/src/sortable/block-strip.d.ts.map +1 -0
  145. package/lib/typescript/src/sortable/index.d.ts +1 -0
  146. package/lib/typescript/src/sortable/index.d.ts.map +1 -1
  147. package/lib/typescript/src/templates/index.d.ts +2 -0
  148. package/lib/typescript/src/templates/index.d.ts.map +1 -1
  149. package/lib/typescript/src/templates/parts.d.ts +2 -1
  150. package/lib/typescript/src/templates/parts.d.ts.map +1 -1
  151. package/lib/typescript/src/templates/sheet-form-template.d.ts +31 -0
  152. package/lib/typescript/src/templates/sheet-form-template.d.ts.map +1 -0
  153. package/lib/typescript/src/theme/base.d.ts +4 -4
  154. package/package.json +1 -1
  155. package/src/blocks/cover-photos/cover-photos.tsx +176 -0
  156. package/src/blocks/cover-photos/index.ts +5 -0
  157. package/src/blocks/detail-editor/compare-slider.tsx +112 -0
  158. package/src/blocks/detail-editor/detail-canvas.tsx +369 -0
  159. package/src/blocks/detail-editor/detail-composer.tsx +261 -0
  160. package/src/blocks/detail-editor/detail-editor-template.tsx +109 -0
  161. package/src/blocks/detail-editor/detail-types.ts +113 -0
  162. package/src/blocks/detail-editor/draft-preview.tsx +34 -0
  163. package/src/blocks/detail-editor/draft-strip.tsx +102 -0
  164. package/src/blocks/detail-editor/editor-bar.tsx +116 -0
  165. package/src/blocks/detail-editor/focus-context.ts +7 -0
  166. package/src/blocks/detail-editor/font-picker.tsx +75 -0
  167. package/src/blocks/detail-editor/index.ts +57 -0
  168. package/src/blocks/detail-editor/layout-picker.tsx +158 -0
  169. package/src/blocks/detail-editor/photo-tray.tsx +140 -0
  170. package/src/blocks/detail-editor/structure-picker.tsx +75 -0
  171. package/src/blocks/detail-editor/tool-row.tsx +66 -0
  172. package/src/blocks/index.tsx +3 -0
  173. package/src/blocks/slider-list/index.ts +5 -0
  174. package/src/blocks/slider-list/slider-list.tsx +57 -0
  175. package/src/blocks/task-tiles/task-tiles.tsx +1 -1
  176. package/src/charts/mini-bars.tsx +1 -1
  177. package/src/components/button/button.tsx +10 -3
  178. package/src/components/floating-tab-bar/floating-tab-bar.tsx +121 -0
  179. package/src/components/floating-tab-bar/index.ts +7 -0
  180. package/src/components/list-row/list-row.tsx +7 -1
  181. package/src/components/section-tabs/index.ts +5 -0
  182. package/src/components/section-tabs/section-tabs.tsx +87 -0
  183. package/src/components/slider/index.ts +1 -0
  184. package/src/components/slider/slider.tsx +142 -0
  185. package/src/index.tsx +3 -0
  186. package/src/internal/flush-row.ts +3 -0
  187. package/src/internal/pressable-base.tsx +3 -1
  188. package/src/internal/tab-icon-pairs.ts +22 -0
  189. package/src/sortable/block-strip.tsx +168 -0
  190. package/src/sortable/index.ts +5 -0
  191. package/src/templates/index.ts +5 -0
  192. package/src/templates/parts.tsx +46 -1
  193. package/src/templates/sheet-form-template.tsx +190 -0
  194. package/src/theme/base.ts +4 -4
@@ -0,0 +1,112 @@
1
+ import { useRef, useState } from 'react';
2
+ import {
3
+ Image,
4
+ PanResponder,
5
+ View,
6
+ type GestureResponderEvent,
7
+ type LayoutChangeEvent,
8
+ } from 'react-native';
9
+ import { makeStyles } from '../../utils/styles';
10
+
11
+ export type CompareSliderProps = {
12
+ before: string;
13
+ after: string;
14
+ aspectRatio?: number;
15
+ label?: string;
16
+ };
17
+
18
+ const KNOB = 32;
19
+
20
+ const useStyles = makeStyles((t) => ({
21
+ root: { width: '100%', overflow: 'hidden', backgroundColor: t.colors.muted },
22
+ fill: { position: 'absolute', left: 0, top: 0, bottom: 0 },
23
+ clip: {
24
+ position: 'absolute',
25
+ left: 0,
26
+ top: 0,
27
+ bottom: 0,
28
+ overflow: 'hidden',
29
+ },
30
+ line: {
31
+ position: 'absolute',
32
+ top: 0,
33
+ bottom: 0,
34
+ width: 2,
35
+ backgroundColor: t.colors.surface,
36
+ },
37
+ knob: {
38
+ position: 'absolute',
39
+ top: '50%',
40
+ marginTop: -KNOB / 2,
41
+ width: KNOB,
42
+ height: KNOB,
43
+ borderRadius: KNOB / 2,
44
+ backgroundColor: t.colors.surface,
45
+ boxShadow: t.shadow.md,
46
+ },
47
+ grip: {
48
+ flex: 1,
49
+ margin: t.space[2],
50
+ borderLeftWidth: 2,
51
+ borderRightWidth: 2,
52
+ borderColor: t.colors.input,
53
+ },
54
+ }));
55
+
56
+ export function CompareSlider({
57
+ before,
58
+ after,
59
+ aspectRatio = 4 / 5,
60
+ label = '원본과 비교',
61
+ }: CompareSliderProps) {
62
+ const s = useStyles();
63
+ const [width, setWidth] = useState(0);
64
+ const [split, setSplit] = useState(0.5);
65
+ const widthRef = useRef(0);
66
+ const follow = (e: GestureResponderEvent) =>
67
+ setSplit(
68
+ Math.min(
69
+ 1,
70
+ Math.max(0, e.nativeEvent.locationX / (widthRef.current || 1))
71
+ )
72
+ );
73
+ const pan = useRef(
74
+ PanResponder.create({
75
+ onStartShouldSetPanResponder: () => true,
76
+ onMoveShouldSetPanResponder: () => true,
77
+ onPanResponderGrant: follow,
78
+ onPanResponderMove: follow,
79
+ })
80
+ ).current;
81
+ const layout = (e: LayoutChangeEvent) => {
82
+ widthRef.current = e.nativeEvent.layout.width;
83
+ setWidth(e.nativeEvent.layout.width);
84
+ };
85
+ const x = width * split;
86
+ return (
87
+ <View
88
+ onLayout={layout}
89
+ accessibilityLabel={label}
90
+ accessibilityRole="adjustable"
91
+ style={[s.root, { aspectRatio }]}
92
+ {...pan.panHandlers}
93
+ >
94
+ <Image
95
+ source={{ uri: after }}
96
+ resizeMode="cover"
97
+ style={[s.fill, { width }]}
98
+ />
99
+ <View style={[s.clip, { width: x }]}>
100
+ <Image
101
+ source={{ uri: before }}
102
+ resizeMode="cover"
103
+ style={[s.fill, { width }]}
104
+ />
105
+ </View>
106
+ <View style={[s.line, { left: x - 1 }]} />
107
+ <View style={[s.knob, { left: x - KNOB / 2 }]}>
108
+ <View style={s.grip} />
109
+ </View>
110
+ </View>
111
+ );
112
+ }
@@ -0,0 +1,369 @@
1
+ import {
2
+ createContext,
3
+ useContext,
4
+ useEffect,
5
+ useMemo,
6
+ useRef,
7
+ type ComponentRef,
8
+ type ReactNode,
9
+ type RefObject,
10
+ } from 'react';
11
+ import {
12
+ Image,
13
+ Text as RNText,
14
+ View,
15
+ type StyleProp,
16
+ type TextStyle,
17
+ type ViewStyle,
18
+ } from 'react-native';
19
+ import { PressableBase } from '../../internal/pressable-base';
20
+ import { useTheme } from '../../theme/theme-provider';
21
+ import { makeStyles } from '../../utils/styles';
22
+ import { DetailFocusContext, type DetailFocusRect } from './focus-context';
23
+ import {
24
+ DETAIL_FONT_FAMILY,
25
+ detailBlockSpace,
26
+ detailFontSize,
27
+ detailLineHeight,
28
+ detailTracking,
29
+ type DetailBlock,
30
+ type DetailDocValue,
31
+ type DetailLayer,
32
+ type DetailSelection,
33
+ } from './detail-types';
34
+
35
+ export type DetailCanvasProps = {
36
+ doc: DetailDocValue;
37
+ selection?: DetailSelection;
38
+ onSelect?: (selection: DetailSelection) => void;
39
+ scale?: number;
40
+ ink?: string;
41
+ paper?: string;
42
+ };
43
+
44
+ const HANDLE = 10;
45
+
46
+ type TapProps = {
47
+ onPress?: () => void;
48
+ label: string;
49
+ style?: StyleProp<ViewStyle>;
50
+ children?: ReactNode;
51
+ };
52
+
53
+ function Tap({ onPress, label, style, children }: TapProps) {
54
+ if (!onPress) {
55
+ return <View style={style}>{children}</View>;
56
+ }
57
+ return (
58
+ <PressableBase
59
+ onPress={onPress}
60
+ accessibilityLabel={label}
61
+ pressedStyle={{}}
62
+ style={style}
63
+ >
64
+ {children}
65
+ </PressableBase>
66
+ );
67
+ }
68
+
69
+ const useStyles = makeStyles((t) => ({
70
+ page: { overflow: 'hidden' },
71
+ texts: { gap: t.space[2] },
72
+ row: { flexDirection: 'row', alignItems: 'center' },
73
+ half: { flex: 1 },
74
+ full: { width: '100%' },
75
+ fill: { position: 'absolute', left: 0, right: 0, top: 0, bottom: 0 },
76
+ pair: { flexDirection: 'row', gap: t.space[2] },
77
+ card: { overflow: 'hidden', borderRadius: t.radius.lg },
78
+ ring: {
79
+ position: 'absolute',
80
+ left: 0,
81
+ right: 0,
82
+ top: 0,
83
+ bottom: 0,
84
+ borderWidth: 2,
85
+ borderColor: t.colors.primary,
86
+ },
87
+ tagText: {
88
+ fontSize: t.typography.caption.fontSize,
89
+ fontWeight: '700',
90
+ },
91
+ tag: {
92
+ position: 'absolute',
93
+ left: t.space[1],
94
+ top: t.space[1],
95
+ minWidth: t.space[6],
96
+ height: t.space[6],
97
+ borderRadius: t.radius.full,
98
+ alignItems: 'center',
99
+ justifyContent: 'center',
100
+ backgroundColor: t.colors.primary,
101
+ },
102
+ handle: {
103
+ position: 'absolute',
104
+ width: HANDLE,
105
+ height: HANDLE,
106
+ borderRadius: HANDLE / 2,
107
+ borderWidth: 2,
108
+ borderColor: t.colors.primary,
109
+ backgroundColor: t.colors.surface,
110
+ },
111
+ }));
112
+
113
+ type FocusTarget = {
114
+ root: RefObject<ComponentRef<typeof View> | null>;
115
+ report: (rect: DetailFocusRect | null) => void;
116
+ };
117
+
118
+ const FocusTargetContext = createContext<FocusTarget | null>(null);
119
+
120
+ function Handles() {
121
+ const s = useStyles();
122
+ const edge = -HANDLE / 2;
123
+ const target = useContext(FocusTargetContext);
124
+ const ring = useRef<ComponentRef<typeof View>>(null);
125
+ useEffect(() => () => target?.report(null), [target]);
126
+ const measure = () => {
127
+ const root = target?.root.current;
128
+ if (!target || !root || !ring.current) return;
129
+ ring.current.measureLayout(
130
+ root,
131
+ (_x, y, _w, height) => target.report({ y, height }),
132
+ () => undefined
133
+ );
134
+ };
135
+ return (
136
+ <>
137
+ <View ref={ring} onLayout={measure} pointerEvents="none" style={s.ring} />
138
+ <View style={[s.handle, { left: edge, top: edge }]} />
139
+ <View style={[s.handle, { right: edge, top: edge }]} />
140
+ <View style={[s.handle, { left: edge, bottom: edge }]} />
141
+ <View style={[s.handle, { right: edge, bottom: edge }]} />
142
+ </>
143
+ );
144
+ }
145
+
146
+ export function textStyleOf(
147
+ layer: DetailLayer,
148
+ scale: number,
149
+ ink: string,
150
+ paper?: string
151
+ ): TextStyle {
152
+ const st = layer.style ?? {};
153
+ const size = detailFontSize(st.size) * scale;
154
+ const color = st.color ?? ink;
155
+ const base: TextStyle = {
156
+ fontFamily: DETAIL_FONT_FAMILY[st.font ?? 'gothic'][st.weight ?? 'regular'],
157
+ fontSize: size,
158
+ lineHeight: size * detailLineHeight(st.line),
159
+ letterSpacing: size * detailTracking(st.tracking),
160
+ color,
161
+ textAlign: st.align ?? 'left',
162
+ };
163
+ if (st.effect === 'shadow') {
164
+ return {
165
+ ...base,
166
+ textShadowColor: 'rgba(0, 0, 0, 0.35)',
167
+ textShadowOffset: { width: 0, height: 1 },
168
+ textShadowRadius: 3,
169
+ };
170
+ }
171
+ if (st.effect === 'outline') {
172
+ return {
173
+ ...base,
174
+ borderWidth: 1.5,
175
+ borderColor: color,
176
+ paddingHorizontal: 8 * scale,
177
+ alignSelf: alignSelfOf(st.align),
178
+ };
179
+ }
180
+ if (st.effect === 'band') {
181
+ return {
182
+ ...base,
183
+ color: paper ?? color,
184
+ backgroundColor: color,
185
+ paddingHorizontal: 8 * scale,
186
+ alignSelf: alignSelfOf(st.align),
187
+ };
188
+ }
189
+ return base;
190
+ }
191
+
192
+ function alignSelfOf(align?: 'left' | 'center' | 'right') {
193
+ return align === 'center'
194
+ ? 'center'
195
+ : align === 'right'
196
+ ? 'flex-end'
197
+ : 'flex-start';
198
+ }
199
+
200
+ export function DetailCanvas({
201
+ doc,
202
+ selection,
203
+ onSelect,
204
+ scale = 1,
205
+ ink,
206
+ paper,
207
+ }: DetailCanvasProps) {
208
+ const t = useTheme();
209
+ const s = useStyles();
210
+ const report = useContext(DetailFocusContext);
211
+ const root = useRef<ComponentRef<typeof View>>(null);
212
+ const target = useMemo(() => (report ? { root, report } : null), [report]);
213
+ const pad = t.space[5] * scale;
214
+ const fg = ink ?? t.colors.foreground;
215
+ const bandText = paper ?? t.colors.surface;
216
+
217
+ const picked = (block: DetailBlock, layer?: DetailLayer) =>
218
+ selection?.block === block.id &&
219
+ (layer ? selection.layer === layer.id : !selection.layer);
220
+
221
+ const press = (next: DetailSelection) =>
222
+ onSelect ? () => onSelect(next) : undefined;
223
+
224
+ const image = (
225
+ block: DetailBlock,
226
+ layer: DetailLayer,
227
+ flex = false,
228
+ ratio = 1
229
+ ) => (
230
+ <Tap
231
+ key={layer.id}
232
+ onPress={press({ block: block.id, layer: layer.id })}
233
+ label={'사진'}
234
+ style={flex ? s.half : undefined}
235
+ >
236
+ {layer.url ? (
237
+ <Image
238
+ source={{ uri: layer.url }}
239
+ resizeMode="cover"
240
+ style={[s.full, { aspectRatio: ratio }]}
241
+ />
242
+ ) : (
243
+ <View
244
+ style={[
245
+ s.full,
246
+ { aspectRatio: ratio, backgroundColor: t.colors.muted },
247
+ ]}
248
+ />
249
+ )}
250
+ {picked(block, layer) ? <Handles /> : null}
251
+ </Tap>
252
+ );
253
+
254
+ const texts = (block: DetailBlock, shown: DetailLayer[]) => {
255
+ const list = shown.filter((l) => l.type === 'text' && l.text);
256
+ if (!list.length) return null;
257
+ return (
258
+ <View style={[s.texts, { padding: pad }]}>
259
+ {list.map((l) => {
260
+ const style = textStyleOf(l, scale, fg, bandText);
261
+ return (
262
+ <Tap
263
+ key={l.id}
264
+ onPress={press({ block: block.id, layer: l.id })}
265
+ label={l.text ?? ''}
266
+ >
267
+ <RNText style={style}>{l.text}</RNText>
268
+ {picked(block, l) ? <Handles /> : null}
269
+ </Tap>
270
+ );
271
+ })}
272
+ </View>
273
+ );
274
+ };
275
+
276
+ const body = (block: DetailBlock): ReactNode => {
277
+ const shown = block.layers.filter((l) => !l.hidden);
278
+ const images = shown.filter((l) => l.type === 'image');
279
+ switch (block.layout) {
280
+ case 'text':
281
+ return texts(block, shown);
282
+ case 'image':
283
+ return images.map((l) => image(block, l, false, 4 / 5));
284
+ case 'text_top':
285
+ return (
286
+ <>
287
+ {texts(block, shown)}
288
+ {images.map((l) => image(block, l, false, 4 / 5))}
289
+ </>
290
+ );
291
+ case 'side':
292
+ return (
293
+ <View style={s.row}>
294
+ {images.slice(0, 1).map((l) => image(block, l, true))}
295
+ <View style={s.half}>{texts(block, shown)}</View>
296
+ </View>
297
+ );
298
+ case 'two_images':
299
+ return (
300
+ <>
301
+ <View style={[s.pair, { paddingHorizontal: pad, paddingTop: pad }]}>
302
+ {images.slice(0, 2).map((l) => image(block, l, true))}
303
+ </View>
304
+ {texts(block, shown)}
305
+ </>
306
+ );
307
+ case 'card':
308
+ return (
309
+ <View style={{ padding: pad }}>
310
+ <View style={[s.card, { backgroundColor: t.colors.surface }]}>
311
+ {images.slice(0, 1).map((l) => image(block, l))}
312
+ {texts(block, shown)}
313
+ </View>
314
+ </View>
315
+ );
316
+ default:
317
+ return (
318
+ <>
319
+ {images.map((l) => image(block, l, false, 4 / 5))}
320
+ {texts(block, shown)}
321
+ </>
322
+ );
323
+ }
324
+ };
325
+
326
+ return (
327
+ <FocusTargetContext.Provider value={target}>
328
+ <View
329
+ ref={root}
330
+ style={[
331
+ s.page,
332
+ { backgroundColor: doc.background ?? paper ?? t.colors.surface },
333
+ ]}
334
+ >
335
+ {doc.blocks.map((block, index) => (
336
+ <Tap
337
+ key={block.id}
338
+ onPress={press({ block: block.id })}
339
+ label={'블록'}
340
+ style={{
341
+ backgroundColor: block.background?.color ?? undefined,
342
+ paddingTop: detailBlockSpace(block.space_top) * scale,
343
+ paddingBottom: detailBlockSpace(block.space_bottom) * scale,
344
+ }}
345
+ >
346
+ {block.background?.url ? (
347
+ <Image
348
+ source={{ uri: block.background.url }}
349
+ resizeMode="cover"
350
+ style={s.fill}
351
+ />
352
+ ) : null}
353
+ {body(block)}
354
+ {picked(block) ? <Handles /> : null}
355
+ {selection?.block === block.id ? (
356
+ <View pointerEvents="none" style={s.tag}>
357
+ <RNText
358
+ style={[s.tagText, { color: t.colors.primaryForeground }]}
359
+ >
360
+ {String(index + 1)}
361
+ </RNText>
362
+ </View>
363
+ ) : null}
364
+ </Tap>
365
+ ))}
366
+ </View>
367
+ </FocusTargetContext.Provider>
368
+ );
369
+ }