@hamster-note/components 0.3.0 → 0.4.0-beta.1

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 (74) hide show
  1. package/README.md +28 -0
  2. package/dist/Icon-BuZRZcjv.js +1143 -0
  3. package/dist/button-mmBNcoG1.js +45 -0
  4. package/dist/button.js +1 -1
  5. package/dist/components/button/Button.d.ts +3 -2
  6. package/dist/components/icon/icon-names.d.ts +1 -15
  7. package/dist/components/theme/theme.d.ts +1 -87
  8. package/dist/{confirm-Faavk_5T.js → confirm-DKgVMWkR.js} +2 -2
  9. package/dist/confirm.js +1 -1
  10. package/dist/{dialog-BYlEUJ_j.js → dialog-DI_yumUn.js} +1 -1
  11. package/dist/dialog.js +1 -1
  12. package/dist/{drawer-BV9RFSna.js → drawer-Cpe3Yf3K.js} +1 -1
  13. package/dist/drawer.js +1 -1
  14. package/dist/hamster-note-components.css +1 -1
  15. package/dist/{icon-BFAcjkFI.js → icon-u7jiIYal.js} +1 -1
  16. package/dist/icon.js +2 -2
  17. package/dist/index.js +7 -7
  18. package/dist/shared/icon-names.d.ts +15 -0
  19. package/dist/shared/icons.d.ts +1216 -0
  20. package/dist/shared/theme.d.ts +87 -0
  21. package/dist/shared/tokens.d.ts +67 -0
  22. package/dist/test/shared-data.test.d.ts +1 -0
  23. package/dist/{theme-CVNLJL1G.js → theme-DNK-xd31.js} +1 -1
  24. package/dist/theme.js +1 -1
  25. package/dist-native/badge.d.ts +10 -0
  26. package/dist-native/badge.js +7 -0
  27. package/dist-native/button.d.ts +16 -0
  28. package/dist-native/button.js +7 -0
  29. package/dist-native/chunk-6RD26X3W.js +78 -0
  30. package/dist-native/chunk-6SR5ZHDD.js +13 -0
  31. package/dist-native/chunk-6VYUVVCP.js +27 -0
  32. package/dist-native/chunk-7LN4VNRB.js +124 -0
  33. package/dist-native/chunk-CF76TWL4.js +85 -0
  34. package/dist-native/chunk-ENTYQ6M4.js +256 -0
  35. package/dist-native/chunk-GSG6CXIE.js +1688 -0
  36. package/dist-native/chunk-JHT74YG3.js +186 -0
  37. package/dist-native/chunk-KPDK62A5.js +106 -0
  38. package/dist-native/chunk-PLFX4RVR.js +134 -0
  39. package/dist-native/chunk-QUGLAOXA.js +49 -0
  40. package/dist-native/chunk-S2EUKEYI.js +35 -0
  41. package/dist-native/chunk-VTE5RPMO.js +38 -0
  42. package/dist-native/chunk-YJ4H3ZBQ.js +145 -0
  43. package/dist-native/chunk-ZTQATW6Y.js +127 -0
  44. package/dist-native/confirm.d.ts +24 -0
  45. package/dist-native/confirm.js +14 -0
  46. package/dist-native/dialog.d.ts +8 -0
  47. package/dist-native/dialog.js +10 -0
  48. package/dist-native/drawer.d.ts +13 -0
  49. package/dist-native/drawer.js +10 -0
  50. package/dist-native/focus-C0k0lLui.d.ts +9 -0
  51. package/dist-native/icon.d.ts +28 -0
  52. package/dist-native/icon.js +9 -0
  53. package/dist-native/index.d.ts +20 -0
  54. package/dist-native/index.js +84 -0
  55. package/dist-native/kbd.d.ts +9 -0
  56. package/dist-native/kbd.js +7 -0
  57. package/dist-native/loading.d.ts +19 -0
  58. package/dist-native/loading.js +11 -0
  59. package/dist-native/menu.d.ts +31 -0
  60. package/dist-native/menu.js +17 -0
  61. package/dist-native/modal-panel-BOpp1oRC.d.ts +23 -0
  62. package/dist-native/note-card.d.ts +13 -0
  63. package/dist-native/note-card.js +7 -0
  64. package/dist-native/popover.d.ts +34 -0
  65. package/dist-native/popover.js +8 -0
  66. package/dist-native/position-CkPoZ5AD.d.ts +3 -0
  67. package/dist-native/text-field.d.ts +13 -0
  68. package/dist-native/text-field.js +7 -0
  69. package/dist-native/theme.d.ts +120 -0
  70. package/dist-native/theme.js +16 -0
  71. package/dist-native/tokens-DHoNd-yT.d.ts +41 -0
  72. package/package.json +137 -5
  73. package/dist/Icon-BBSPOBTI.js +0 -531
  74. package/dist/button-DjMS8bKj.js +0 -20
@@ -0,0 +1,256 @@
1
+ import {
2
+ useModalLifecycle
3
+ } from "./chunk-7LN4VNRB.js";
4
+ import {
5
+ ThemeProvider,
6
+ useTheme
7
+ } from "./chunk-YJ4H3ZBQ.js";
8
+
9
+ // native/popover.tsx
10
+ import { useEffect, useState } from "react";
11
+ import {
12
+ Keyboard,
13
+ Modal,
14
+ Platform,
15
+ Pressable,
16
+ ScrollView,
17
+ StatusBar,
18
+ StyleSheet,
19
+ Text,
20
+ View,
21
+ useWindowDimensions
22
+ } from "react-native";
23
+
24
+ // native/position.ts
25
+ function placePanel(anchor, panel, bounds, placement, offset) {
26
+ let x = bounds.x + (bounds.width - panel.width) / 2;
27
+ let y = bounds.y + (bounds.height - panel.height) / 2;
28
+ if (anchor && [anchor.x, anchor.y, anchor.width, anchor.height].every(Number.isFinite) && anchor.width > 0 && anchor.height > 0) {
29
+ x = anchor.x + (anchor.width - panel.width) / 2;
30
+ y = anchor.y + (anchor.height - panel.height) / 2;
31
+ if (placement === "bottom" || placement === "top") {
32
+ const below = anchor.y + anchor.height + offset;
33
+ const above = anchor.y - panel.height - offset;
34
+ const fitsBelow = below + panel.height <= bounds.y + bounds.height;
35
+ const fitsAbove = above >= bounds.y;
36
+ y = placement === "bottom" ? fitsBelow || !fitsAbove ? below : above : fitsAbove || !fitsBelow ? above : below;
37
+ } else {
38
+ const right = anchor.x + anchor.width + offset;
39
+ const left = anchor.x - panel.width - offset;
40
+ const fitsRight = right + panel.width <= bounds.x + bounds.width;
41
+ const fitsLeft = left >= bounds.x;
42
+ x = placement === "right" ? fitsRight || !fitsLeft ? right : left : fitsLeft || !fitsRight ? left : right;
43
+ }
44
+ }
45
+ return {
46
+ left: Math.max(bounds.x, Math.min(x, bounds.x + bounds.width - panel.width)),
47
+ top: Math.max(bounds.y, Math.min(y, bounds.y + bounds.height - panel.height))
48
+ };
49
+ }
50
+
51
+ // native/popover.tsx
52
+ import { jsx, jsxs } from "react/jsx-runtime";
53
+ function Popover({
54
+ open,
55
+ onClose,
56
+ children,
57
+ accessibilityLabel,
58
+ anchorRef,
59
+ triggerRef,
60
+ fallbackFocusRef,
61
+ initialFocusRef,
62
+ placement = "bottom",
63
+ anchorOffset = 8,
64
+ viewportMargin = 12,
65
+ safeAreaInsets,
66
+ style,
67
+ onBack,
68
+ focusKey = "",
69
+ closeLabel = "\u5173\u95ED"
70
+ }) {
71
+ const theme = useTheme();
72
+ const dimensions = useWindowDimensions();
73
+ const modal = useModalLifecycle({
74
+ open,
75
+ onClose,
76
+ onBack,
77
+ focusKey,
78
+ initialFocusRef,
79
+ triggerRef,
80
+ fallbackFocusRef
81
+ });
82
+ const [anchor, setAnchor] = useState(null);
83
+ const [panel, setPanel] = useState({ width: 280, height: 100 });
84
+ const [keyboardTop, setKeyboardTop] = useState(null);
85
+ useEffect(() => {
86
+ if (!open) {
87
+ setKeyboardTop(null);
88
+ return;
89
+ }
90
+ setKeyboardTop(Keyboard.metrics?.()?.screenY ?? null);
91
+ const show = Keyboard.addListener(
92
+ "keyboardDidShow",
93
+ (e) => setKeyboardTop(e.endCoordinates.screenY)
94
+ );
95
+ const hide = Keyboard.addListener("keyboardDidHide", () => setKeyboardTop(null));
96
+ return () => {
97
+ show.remove();
98
+ hide.remove();
99
+ };
100
+ }, [open]);
101
+ const insets = safeAreaInsets ?? {
102
+ top: Platform.OS === "android" ? StatusBar.currentHeight ?? 0 : 0,
103
+ right: 0,
104
+ bottom: 0,
105
+ left: 0
106
+ };
107
+ const bounds = {
108
+ x: insets.left + viewportMargin,
109
+ y: insets.top + viewportMargin,
110
+ width: Math.max(1, dimensions.width - insets.left - insets.right - 2 * viewportMargin),
111
+ height: Math.max(
112
+ 1,
113
+ Math.min(dimensions.height - insets.bottom, keyboardTop ?? dimensions.height) - insets.top - 2 * viewportMargin
114
+ )
115
+ };
116
+ useEffect(() => {
117
+ if (!open) return;
118
+ let active = true;
119
+ const node = anchorRef?.current;
120
+ setAnchor(null);
121
+ node?.measureInWindow?.((x, y, width, height) => {
122
+ if (active && anchorRef?.current === node) setAnchor({ x, y, width, height });
123
+ });
124
+ return () => {
125
+ active = false;
126
+ };
127
+ }, [
128
+ open,
129
+ anchorRef,
130
+ dimensions.width,
131
+ dimensions.height,
132
+ keyboardTop,
133
+ insets.top,
134
+ insets.right,
135
+ insets.bottom,
136
+ insets.left,
137
+ focusKey
138
+ ]);
139
+ const position = placePanel(
140
+ anchorRef?.current ? anchor : null,
141
+ { width: Math.min(panel.width, bounds.width), height: Math.min(panel.height, bounds.height) },
142
+ bounds,
143
+ placement,
144
+ anchorOffset
145
+ );
146
+ return /* @__PURE__ */ jsx(
147
+ Modal,
148
+ {
149
+ visible: open,
150
+ transparent: true,
151
+ animationType: "none",
152
+ statusBarTranslucent: true,
153
+ onShow: modal.onShow,
154
+ onDismiss: modal.onDismiss,
155
+ onRequestClose: modal.requestClose,
156
+ children: /* @__PURE__ */ jsx(ThemeProvider, { theme, children: /* @__PURE__ */ jsxs(
157
+ View,
158
+ {
159
+ style: StyleSheet.absoluteFill,
160
+ accessibilityViewIsModal: true,
161
+ onAccessibilityEscape: modal.requestClose,
162
+ children: [
163
+ /* @__PURE__ */ jsx(
164
+ Pressable,
165
+ {
166
+ accessible: false,
167
+ importantForAccessibility: "no",
168
+ style: [StyleSheet.absoluteFill, { backgroundColor: "rgba(0,0,0,0.2)" }],
169
+ onPress: modal.requestClose
170
+ }
171
+ ),
172
+ /* @__PURE__ */ jsxs(
173
+ View,
174
+ {
175
+ onLayout: (e) => {
176
+ setPanel(e.nativeEvent.layout);
177
+ modal.onLayout();
178
+ },
179
+ style: [
180
+ {
181
+ position: "absolute",
182
+ width: Math.min(320, bounds.width),
183
+ maxWidth: bounds.width,
184
+ maxHeight: bounds.height,
185
+ backgroundColor: theme.colors.surface,
186
+ borderRadius: theme.radius.large,
187
+ borderWidth: 1,
188
+ borderColor: theme.colors.border,
189
+ zIndex: theme.layer.popover,
190
+ padding: theme.spacing.panelPadding
191
+ },
192
+ style,
193
+ { ...position, maxWidth: bounds.width, maxHeight: bounds.height }
194
+ ],
195
+ children: [
196
+ /* @__PURE__ */ jsxs(
197
+ View,
198
+ {
199
+ style: {
200
+ flexDirection: "row",
201
+ alignItems: "center",
202
+ justifyContent: "space-between"
203
+ },
204
+ children: [
205
+ /* @__PURE__ */ jsx(
206
+ Text,
207
+ {
208
+ ...Platform.OS === "web" ? { tabIndex: -1 } : {},
209
+ ref: modal.titleRef,
210
+ accessible: true,
211
+ accessibilityRole: "header",
212
+ style: { color: theme.colors.text, fontSize: theme.fontSize.large, flexShrink: 1 },
213
+ children: accessibilityLabel
214
+ }
215
+ ),
216
+ /* @__PURE__ */ jsx(
217
+ Pressable,
218
+ {
219
+ ref: modal.closeRef,
220
+ accessibilityRole: "button",
221
+ accessibilityLabel: closeLabel,
222
+ onPress: modal.requestClose,
223
+ style: {
224
+ minWidth: 44,
225
+ minHeight: 44,
226
+ alignItems: "center",
227
+ justifyContent: "center"
228
+ },
229
+ children: /* @__PURE__ */ jsx(Text, { style: { color: theme.colors.text }, children: "\xD7" })
230
+ }
231
+ )
232
+ ]
233
+ }
234
+ ),
235
+ /* @__PURE__ */ jsx(
236
+ ScrollView,
237
+ {
238
+ keyboardShouldPersistTaps: "handled",
239
+ style: { flexShrink: 1 },
240
+ contentContainerStyle: { gap: 4 },
241
+ children
242
+ }
243
+ )
244
+ ]
245
+ }
246
+ )
247
+ ]
248
+ }
249
+ ) })
250
+ }
251
+ );
252
+ }
253
+
254
+ export {
255
+ Popover
256
+ };