@hellboy/ds 0.1.3 → 0.2.7

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 (298) hide show
  1. package/README.md +512 -162
  2. package/{src/style/components/badge → dist/components}/badge.css +9 -25
  3. package/dist/components/badge.d.mts +12 -0
  4. package/dist/components/badge.d.ts +12 -0
  5. package/dist/components/badge.js +42 -0
  6. package/dist/components/badge.mjs +15 -0
  7. package/dist/components/banner.css +280 -0
  8. package/dist/components/banner.d.mts +12 -0
  9. package/dist/components/banner.d.ts +12 -0
  10. package/dist/components/banner.js +184 -0
  11. package/dist/components/banner.mjs +147 -0
  12. package/dist/components/button-group.css +289 -0
  13. package/dist/components/button-group.d.mts +81 -0
  14. package/dist/components/button-group.d.ts +81 -0
  15. package/dist/components/button-group.js +180 -0
  16. package/dist/components/button-group.mjs +143 -0
  17. package/{src/style/components/button → dist/components}/button.css +59 -62
  18. package/dist/components/button.d.mts +57 -0
  19. package/dist/components/button.d.ts +57 -0
  20. package/dist/components/button.js +129 -0
  21. package/dist/components/button.mjs +92 -0
  22. package/{src/style/components/card → dist/components}/card.css +9 -30
  23. package/dist/components/card.d.mts +31 -0
  24. package/dist/components/card.d.ts +31 -0
  25. package/dist/components/card.js +59 -0
  26. package/dist/components/card.mjs +32 -0
  27. package/{src/style → dist}/components/checkbox.css +51 -43
  28. package/dist/components/checkbox.d.mts +31 -0
  29. package/dist/components/checkbox.d.ts +31 -0
  30. package/dist/components/checkbox.js +130 -0
  31. package/dist/components/checkbox.mjs +93 -0
  32. package/{src/style/components/code-block → dist/components}/code-block.css +3 -7
  33. package/dist/components/code-block.d.mts +24 -0
  34. package/dist/components/code-block.d.ts +24 -0
  35. package/dist/components/code-block.js +43 -0
  36. package/dist/components/code-block.mjs +16 -0
  37. package/dist/components/color-control.css +285 -0
  38. package/dist/components/color-control.d.mts +5 -0
  39. package/dist/components/color-control.d.ts +5 -0
  40. package/dist/components/color-control.js +534 -0
  41. package/dist/components/color-control.mjs +497 -0
  42. package/dist/components/dialog.css +930 -0
  43. package/dist/components/dialog.d.mts +32 -0
  44. package/dist/components/dialog.d.ts +32 -0
  45. package/dist/components/dialog.js +1111 -0
  46. package/dist/components/dialog.mjs +1074 -0
  47. package/dist/components/divider.css +356 -0
  48. package/dist/components/divider.d.mts +32 -0
  49. package/dist/components/divider.d.ts +32 -0
  50. package/dist/components/divider.js +344 -0
  51. package/dist/components/divider.mjs +307 -0
  52. package/{src/style/components/drag-handle → dist/components}/drag-handle.css +3 -18
  53. package/dist/components/drag-handle.d.mts +11 -0
  54. package/dist/components/drag-handle.d.ts +11 -0
  55. package/dist/components/drag-handle.js +103 -0
  56. package/dist/components/drag-handle.mjs +66 -0
  57. package/dist/components/drawer.css +1027 -0
  58. package/dist/components/drawer.d.mts +14 -0
  59. package/dist/components/drawer.d.ts +14 -0
  60. package/dist/components/drawer.js +1072 -0
  61. package/dist/components/drawer.mjs +1035 -0
  62. package/dist/components/floating-bar.css +17 -0
  63. package/dist/components/floating-bar.d.mts +25 -0
  64. package/dist/components/floating-bar.d.ts +25 -0
  65. package/dist/components/floating-bar.js +52 -0
  66. package/dist/components/floating-bar.mjs +25 -0
  67. package/dist/components/footer.css +40 -0
  68. package/dist/components/footer.d.mts +8 -0
  69. package/dist/components/footer.d.ts +8 -0
  70. package/dist/components/footer.js +44 -0
  71. package/dist/components/footer.mjs +17 -0
  72. package/dist/components/grid.css +47 -0
  73. package/dist/components/grid.d.mts +27 -0
  74. package/dist/components/grid.d.ts +27 -0
  75. package/dist/components/grid.js +52 -0
  76. package/dist/components/grid.mjs +25 -0
  77. package/dist/components/header.css +1075 -0
  78. package/dist/components/header.d.mts +35 -0
  79. package/dist/components/header.d.ts +35 -0
  80. package/dist/components/header.js +1402 -0
  81. package/dist/components/header.mjs +1365 -0
  82. package/dist/components/hero.css +121 -0
  83. package/dist/components/hero.d.mts +111 -0
  84. package/dist/components/hero.d.ts +111 -0
  85. package/dist/components/hero.js +285 -0
  86. package/dist/components/hero.mjs +248 -0
  87. package/{src/style/components/icons → dist/components}/icons.css +14 -15
  88. package/dist/components/icons.d.mts +104 -0
  89. package/dist/components/icons.d.ts +104 -0
  90. package/dist/components/icons.js +239 -0
  91. package/dist/components/icons.mjs +203 -0
  92. package/{src/style/components/input → dist/components}/input.css +189 -102
  93. package/dist/components/input.d.mts +114 -0
  94. package/dist/components/input.d.ts +114 -0
  95. package/dist/components/input.js +926 -0
  96. package/dist/components/input.mjs +879 -0
  97. package/dist/components/layout.css +551 -0
  98. package/dist/components/layout.d.mts +16 -0
  99. package/dist/components/layout.d.ts +16 -0
  100. package/dist/components/layout.js +387 -0
  101. package/dist/components/layout.mjs +352 -0
  102. package/{src/style/components/list → dist/components}/list.css +47 -41
  103. package/dist/components/list.d.mts +46 -0
  104. package/dist/components/list.d.ts +46 -0
  105. package/dist/components/list.js +124 -0
  106. package/dist/components/list.mjs +96 -0
  107. package/dist/components/navbar.css +706 -0
  108. package/dist/components/navbar.d.mts +56 -0
  109. package/dist/components/navbar.d.ts +56 -0
  110. package/dist/components/navbar.js +994 -0
  111. package/dist/components/navbar.mjs +952 -0
  112. package/{src/style/components/page-index → dist/components}/page-index.css +2 -47
  113. package/dist/components/page-index.d.mts +25 -0
  114. package/dist/components/page-index.d.ts +25 -0
  115. package/dist/components/page-index.js +239 -0
  116. package/dist/components/page-index.mjs +202 -0
  117. package/{src/style/components/page → dist/components}/page.css +4 -15
  118. package/dist/components/page.d.mts +30 -0
  119. package/dist/components/page.d.ts +30 -0
  120. package/dist/components/page.js +40 -0
  121. package/dist/components/page.mjs +13 -0
  122. package/dist/components/popover.css +87 -0
  123. package/dist/components/popover.d.mts +22 -0
  124. package/dist/components/popover.d.ts +22 -0
  125. package/dist/components/popover.js +243 -0
  126. package/dist/components/popover.mjs +206 -0
  127. package/{src/style → dist}/components/radio.css +8 -51
  128. package/dist/components/radio.d.mts +59 -0
  129. package/dist/components/radio.d.ts +59 -0
  130. package/dist/components/radio.js +133 -0
  131. package/dist/components/radio.mjs +95 -0
  132. package/dist/components/section.css +993 -0
  133. package/dist/components/section.d.mts +33 -0
  134. package/dist/components/section.d.ts +33 -0
  135. package/dist/components/section.js +1401 -0
  136. package/dist/components/section.mjs +1364 -0
  137. package/dist/components/select.css +391 -0
  138. package/dist/components/select.d.mts +63 -0
  139. package/dist/components/select.d.ts +63 -0
  140. package/dist/components/select.js +452 -0
  141. package/dist/components/select.mjs +415 -0
  142. package/{src/style/components/slider → dist/components}/slider.css +55 -33
  143. package/dist/components/slider.d.mts +69 -0
  144. package/dist/components/slider.d.ts +69 -0
  145. package/dist/components/slider.js +254 -0
  146. package/dist/components/slider.mjs +217 -0
  147. package/dist/components/switch.css +1081 -0
  148. package/dist/components/switch.d.mts +33 -0
  149. package/dist/components/switch.d.ts +33 -0
  150. package/dist/components/switch.js +1092 -0
  151. package/dist/components/switch.mjs +1055 -0
  152. package/{src/style/components/table → dist/components}/table.css +3 -28
  153. package/dist/components/table.d.mts +42 -0
  154. package/dist/components/table.d.ts +42 -0
  155. package/dist/components/table.js +108 -0
  156. package/dist/components/table.mjs +76 -0
  157. package/dist/components/tag.css +97 -0
  158. package/dist/components/tag.d.mts +12 -0
  159. package/dist/components/tag.d.ts +12 -0
  160. package/dist/components/tag.js +42 -0
  161. package/dist/components/tag.mjs +15 -0
  162. package/dist/components/textarea.css +1359 -0
  163. package/dist/components/textarea.d.mts +84 -0
  164. package/dist/components/textarea.d.ts +84 -0
  165. package/dist/components/textarea.js +1962 -0
  166. package/dist/components/textarea.mjs +1924 -0
  167. package/{src/style/components/theme-control → dist/components}/theme-control.css +3 -7
  168. package/dist/components/theme-control.d.mts +9 -0
  169. package/dist/components/theme-control.d.ts +9 -0
  170. package/dist/components/theme-control.js +235 -0
  171. package/dist/components/theme-control.mjs +200 -0
  172. package/{src/style/components/tooltip → dist/components}/tooltip.css +5 -13
  173. package/dist/components/tooltip.d.mts +12 -0
  174. package/dist/components/tooltip.d.ts +12 -0
  175. package/dist/components/tooltip.js +200 -0
  176. package/dist/components/tooltip.mjs +163 -0
  177. package/dist/icons-Czahnf-r.d.mts +15 -0
  178. package/dist/icons-Czahnf-r.d.ts +15 -0
  179. package/dist/index.css +2914 -2067
  180. package/dist/index.d.mts +144 -721
  181. package/dist/index.d.ts +144 -721
  182. package/dist/index.js +4076 -2282
  183. package/dist/index.mjs +4132 -2366
  184. package/dist/theme.css +34 -34
  185. package/package.json +27 -8
  186. package/dist/index.css.map +0 -1
  187. package/dist/index.js.map +0 -1
  188. package/dist/index.mjs.map +0 -1
  189. package/hellboy-ds-0.1.2.tgz +0 -0
  190. package/src/components/badge/Badge.tsx +0 -29
  191. package/src/components/badge/index.ts +0 -1
  192. package/src/components/banner/Banner.tsx +0 -48
  193. package/src/components/banner/banner.css +0 -44
  194. package/src/components/banner/index.ts +0 -1
  195. package/src/components/button/button.tsx +0 -127
  196. package/src/components/button/index.ts +0 -1
  197. package/src/components/card/card.tsx +0 -57
  198. package/src/components/card/index.ts +0 -1
  199. package/src/components/checkbox/Checkbox.tsx +0 -98
  200. package/src/components/checkbox/index.ts +0 -1
  201. package/src/components/code-block/code-block.tsx +0 -44
  202. package/src/components/code-block/index.ts +0 -1
  203. package/src/components/color-control/color-control.tsx +0 -322
  204. package/src/components/color-control/index.ts +0 -1
  205. package/src/components/drag-handle/DragHandle.tsx +0 -78
  206. package/src/components/drag-handle/index.ts +0 -1
  207. package/src/components/drawer/drawer.tsx +0 -82
  208. package/src/components/drawer/index.ts +0 -1
  209. package/src/components/floating-bar/floating-bar.tsx +0 -52
  210. package/src/components/floating-bar/index.ts +0 -2
  211. package/src/components/footer/footer.tsx +0 -28
  212. package/src/components/footer/index.ts +0 -1
  213. package/src/components/grid/Grid.tsx +0 -53
  214. package/src/components/grid/index.ts +0 -1
  215. package/src/components/header/header.tsx +0 -57
  216. package/src/components/header/index.ts +0 -1
  217. package/src/components/icons/icons.tsx +0 -44
  218. package/src/components/icons/index.ts +0 -1
  219. package/src/components/index.ts +0 -29
  220. package/src/components/input/DatePicker.tsx +0 -133
  221. package/src/components/input/Input.tsx +0 -220
  222. package/src/components/input/InputDate.tsx +0 -10
  223. package/src/components/input/InputDateTime.tsx +0 -10
  224. package/src/components/input/InputEmail.tsx +0 -10
  225. package/src/components/input/InputField.tsx +0 -137
  226. package/src/components/input/InputNumber.tsx +0 -10
  227. package/src/components/input/InputPassword.tsx +0 -10
  228. package/src/components/input/InputSearch.tsx +0 -10
  229. package/src/components/input/InputTel.tsx +0 -10
  230. package/src/components/input/InputText.tsx +0 -10
  231. package/src/components/input/InputTime.tsx +0 -10
  232. package/src/components/input/InputUrl.tsx +0 -10
  233. package/src/components/input/TimePicker.tsx +0 -151
  234. package/src/components/input/index.ts +0 -11
  235. package/src/components/layout/Layout.tsx +0 -244
  236. package/src/components/layout/index.ts +0 -1
  237. package/src/components/list/List.tsx +0 -159
  238. package/src/components/list/index.ts +0 -1
  239. package/src/components/navbar/MenuCategory.tsx +0 -20
  240. package/src/components/navbar/MenuGroup.tsx +0 -288
  241. package/src/components/navbar/MenuItem.tsx +0 -65
  242. package/src/components/navbar/Navbar.tsx +0 -23
  243. package/src/components/navbar/index.ts +0 -4
  244. package/src/components/page/index.ts +0 -1
  245. package/src/components/page/page.tsx +0 -46
  246. package/src/components/page-index/PageIndex.tsx +0 -275
  247. package/src/components/page-index/index.ts +0 -1
  248. package/src/components/popover/index.ts +0 -1
  249. package/src/components/popover/popover.tsx +0 -199
  250. package/src/components/radio/Radio.tsx +0 -176
  251. package/src/components/radio/index.ts +0 -1
  252. package/src/components/section/index.ts +0 -1
  253. package/src/components/section/section.tsx +0 -66
  254. package/src/components/select/Select.tsx +0 -212
  255. package/src/components/select/index.ts +0 -1
  256. package/src/components/slider/Slider.tsx +0 -267
  257. package/src/components/slider/index.ts +0 -1
  258. package/src/components/switch/index.ts +0 -1
  259. package/src/components/switch/switch.tsx +0 -99
  260. package/src/components/table/Table.tsx +0 -147
  261. package/src/components/table/index.ts +0 -1
  262. package/src/components/theme-control/index.ts +0 -1
  263. package/src/components/theme-control/theme-control.tsx +0 -78
  264. package/src/components/tooltip/index.ts +0 -1
  265. package/src/components/tooltip/tooltip.tsx +0 -207
  266. package/src/contexts/NavbarTooltipContext.tsx +0 -48
  267. package/src/contexts/index.ts +0 -1
  268. package/src/foundations/motion.md +0 -136
  269. package/src/index.ts +0 -40
  270. package/src/style/_shared/field.css +0 -69
  271. package/src/style/components/color-control/color-control.css +0 -126
  272. package/src/style/components/drawer/drawer.css +0 -210
  273. package/src/style/components/floating-bar/floating-bar.css +0 -39
  274. package/src/style/components/footer/footer.css +0 -108
  275. package/src/style/components/grid/grid.css +0 -33
  276. package/src/style/components/header/header.css +0 -44
  277. package/src/style/components/layout/layout.css +0 -205
  278. package/src/style/components/navbar/navbar.css +0 -342
  279. package/src/style/components/popover/popover.css +0 -44
  280. package/src/style/components/section/section.css +0 -67
  281. package/src/style/components/select/select.css +0 -143
  282. package/src/style/components/switch/switch.css +0 -267
  283. package/src/style/foundations/global.css +0 -316
  284. package/src/style/foundations/motion.css +0 -164
  285. package/src/style/foundations/spacing.css +0 -51
  286. package/src/style/foundations/typography.css +0 -39
  287. package/src/style/foundations/z-index.css +0 -81
  288. package/src/style/modes/dark.css +0 -146
  289. package/src/style/modes/light.css +0 -147
  290. package/src/style/semantic.css +0 -52
  291. package/src/style/styles.css +0 -51
  292. package/src/style/themes/theme.json +0 -37
  293. package/src/utils/README.md +0 -305
  294. package/src/utils/USER_PREFERENCES.md +0 -558
  295. package/src/utils/theme.ts +0 -127
  296. package/src/utils/user-preferences.ts +0 -577
  297. package/tsconfig.json +0 -25
  298. package/tsup.config.ts +0 -52
@@ -1,577 +0,0 @@
1
- /**
2
- * User Preferences Utility
3
- *
4
- * A comprehensive user preference management system for the Hellboy Design System.
5
- * This utility provides a practical, opinionated solution for storing and retrieving
6
- * user preferences using localStorage with optional IndexedDB fallback.
7
- *
8
- * Philosophy:
9
- * The Hellboy Design System aims to maximize development velocity by providing
10
- * complete, practical solutions rather than staying purely agnostic. While many
11
- * design systems focus solely on visual components, we believe in delivering
12
- * utilities that solve common real-world problems developers face.
13
- *
14
- * This preference system is designed to be:
15
- * - Easy to use with minimal configuration
16
- * - Type-safe with TypeScript
17
- * - Persistent across sessions
18
- * - Extensible for custom preferences
19
- * - Framework-agnostic (works with React, Vue, vanilla JS, etc.)
20
- *
21
- * Supported preference categories:
22
- * - Theme preferences (light/dark mode, custom colors)
23
- * - Layout preferences (sidebar widths, panel sizes)
24
- * - Component states (drawer positions, table column widths)
25
- * - User-specific settings (language, timezone, etc.)
26
- */
27
-
28
- /**
29
- * Storage backend types
30
- */
31
- type StorageBackend = 'localStorage' | 'indexedDB';
32
-
33
- /**
34
- * Base preference key type for type safety
35
- */
36
- type PreferenceKey = string;
37
-
38
- /**
39
- * User preferences interface
40
- * Extend this interface to add custom preference types
41
- */
42
- export interface UserPreferences {
43
- // Theme preferences
44
- theme?: 'light' | 'dark';
45
- colorConfig?: {
46
- primaryHue?: number;
47
- primarySaturation?: number;
48
- primaryLightness?: number;
49
- secondaryHue?: number;
50
- secondarySaturation?: number;
51
- secondaryLightness?: number;
52
- accentHue?: number;
53
- accentSaturation?: number;
54
- accentLightness?: number;
55
- successHue?: number;
56
- successSaturation?: number;
57
- successLightness?: number;
58
- warningHue?: number;
59
- warningSaturation?: number;
60
- warningLightness?: number;
61
- errorHue?: number;
62
- errorSaturation?: number;
63
- errorLightness?: number;
64
- infoHue?: number;
65
- infoSaturation?: number;
66
- infoLightness?: number;
67
- };
68
-
69
- // Layout preferences
70
- layout?: {
71
- leftSidebarWidth?: number;
72
- rightSidebarWidth?: number;
73
- bottomBarHeight?: number;
74
- navbarCollapsed?: boolean;
75
- };
76
-
77
- // Component-specific preferences
78
- components?: {
79
- [componentName: string]: {
80
- [key: string]: any;
81
- };
82
- };
83
-
84
- // Custom user settings
85
- custom?: {
86
- [key: string]: any;
87
- };
88
- }
89
-
90
- /**
91
- * Storage configuration
92
- */
93
- interface StorageConfig {
94
- backend: StorageBackend;
95
- prefix: string;
96
- dbName?: string;
97
- storeName?: string;
98
- }
99
-
100
- /**
101
- * Default storage configuration
102
- */
103
- const DEFAULT_CONFIG: StorageConfig = {
104
- backend: 'localStorage',
105
- prefix: 'hellboy-ds',
106
- dbName: 'hellboy-ds-prefs',
107
- storeName: 'preferences',
108
- };
109
-
110
- /**
111
- * Current storage configuration
112
- */
113
- let config: StorageConfig = { ...DEFAULT_CONFIG };
114
-
115
- /**
116
- * Configure the preference storage system
117
- * Call this once at app initialization if you need custom configuration
118
- *
119
- * @param userConfig - Custom storage configuration
120
- *
121
- * @example
122
- * ```ts
123
- * import { configurePreferences } from '@hellboy/ds';
124
- *
125
- * configurePreferences({
126
- * backend: 'localStorage',
127
- * prefix: 'my-app'
128
- * });
129
- * ```
130
- */
131
- export const configurePreferences = (userConfig: Partial<StorageConfig>): void => {
132
- config = { ...config, ...userConfig };
133
- };
134
-
135
- /**
136
- * Get full storage key with prefix
137
- */
138
- const getStorageKey = (key: PreferenceKey): string => {
139
- return `${config.prefix}:${key}`;
140
- };
141
-
142
- /**
143
- * Check if localStorage is available
144
- */
145
- const isLocalStorageAvailable = (): boolean => {
146
- try {
147
- const test = '__storage_test__';
148
- localStorage.setItem(test, test);
149
- localStorage.removeItem(test);
150
- return true;
151
- } catch {
152
- return false;
153
- }
154
- };
155
-
156
- /**
157
- * IndexedDB helper (for future expansion)
158
- * Currently a placeholder - localStorage is the primary backend
159
- */
160
- class IndexedDBStore {
161
- private db: IDBDatabase | null = null;
162
-
163
- async init(): Promise<void> {
164
- if (typeof window === 'undefined' || !window.indexedDB) {
165
- throw new Error('IndexedDB not available');
166
- }
167
-
168
- return new Promise((resolve, reject) => {
169
- const request = indexedDB.open(config.dbName!, 1);
170
-
171
- request.onerror = () => reject(request.error);
172
- request.onsuccess = () => {
173
- this.db = request.result;
174
- resolve();
175
- };
176
-
177
- request.onupgradeneeded = (event) => {
178
- const db = (event.target as IDBOpenDBRequest).result;
179
- if (!db.objectStoreNames.contains(config.storeName!)) {
180
- db.createObjectStore(config.storeName!, { keyPath: 'key' });
181
- }
182
- };
183
- });
184
- }
185
-
186
- async get(key: string): Promise<any> {
187
- if (!this.db) await this.init();
188
- return new Promise((resolve, reject) => {
189
- const transaction = this.db!.transaction([config.storeName!], 'readonly');
190
- const store = transaction.objectStore(config.storeName!);
191
- const request = store.get(key);
192
-
193
- request.onsuccess = () => resolve(request.result?.value);
194
- request.onerror = () => reject(request.error);
195
- });
196
- }
197
-
198
- async set(key: string, value: any): Promise<void> {
199
- if (!this.db) await this.init();
200
- return new Promise((resolve, reject) => {
201
- const transaction = this.db!.transaction([config.storeName!], 'readwrite');
202
- const store = transaction.objectStore(config.storeName!);
203
- const request = store.put({ key, value });
204
-
205
- request.onsuccess = () => resolve();
206
- request.onerror = () => reject(request.error);
207
- });
208
- }
209
-
210
- async remove(key: string): Promise<void> {
211
- if (!this.db) await this.init();
212
- return new Promise((resolve, reject) => {
213
- const transaction = this.db!.transaction([config.storeName!], 'readwrite');
214
- const store = transaction.objectStore(config.storeName!);
215
- const request = store.delete(key);
216
-
217
- request.onsuccess = () => resolve();
218
- request.onerror = () => reject(request.error);
219
- });
220
- }
221
-
222
- async clear(): Promise<void> {
223
- if (!this.db) await this.init();
224
- return new Promise((resolve, reject) => {
225
- const transaction = this.db!.transaction([config.storeName!], 'readwrite');
226
- const store = transaction.objectStore(config.storeName!);
227
- const request = store.clear();
228
-
229
- request.onsuccess = () => resolve();
230
- request.onerror = () => reject(request.error);
231
- });
232
- }
233
- }
234
-
235
- /**
236
- * Singleton IndexedDB instance
237
- */
238
- const indexedDBStore = new IndexedDBStore();
239
-
240
- /**
241
- * Get a preference value
242
- *
243
- * @param key - Preference key
244
- * @param defaultValue - Default value if preference doesn't exist
245
- * @returns The preference value or default value
246
- *
247
- * @example
248
- * ```ts
249
- * import { getPreference } from '@hellboy/ds';
250
- *
251
- * const theme = getPreference('theme', 'light');
252
- * const sidebarWidth = getPreference('layout.leftSidebarWidth', 280);
253
- * ```
254
- */
255
- export const getPreference = <T = any>(
256
- key: PreferenceKey,
257
- defaultValue?: T
258
- ): T | undefined => {
259
- try {
260
- if (config.backend === 'localStorage' && isLocalStorageAvailable()) {
261
- const stored = localStorage.getItem(getStorageKey(key));
262
- if (stored !== null) {
263
- return JSON.parse(stored) as T;
264
- }
265
- }
266
- return defaultValue;
267
- } catch (error) {
268
- console.warn(`Failed to get preference "${key}":`, error);
269
- return defaultValue;
270
- }
271
- };
272
-
273
- /**
274
- * Async version for IndexedDB (future use)
275
- */
276
- export const getPreferenceAsync = async <T = any>(
277
- key: PreferenceKey,
278
- defaultValue?: T
279
- ): Promise<T | undefined> => {
280
- try {
281
- if (config.backend === 'indexedDB') {
282
- const value = await indexedDBStore.get(getStorageKey(key));
283
- return value !== undefined ? value : defaultValue;
284
- }
285
- return getPreference(key, defaultValue);
286
- } catch (error) {
287
- console.warn(`Failed to get preference "${key}":`, error);
288
- return defaultValue;
289
- }
290
- };
291
-
292
- /**
293
- * Set a preference value
294
- *
295
- * @param key - Preference key
296
- * @param value - Preference value to store
297
- *
298
- * @example
299
- * ```ts
300
- * import { setPreference } from '@hellboy/ds';
301
- *
302
- * setPreference('theme', 'dark');
303
- * setPreference('layout.leftSidebarWidth', 320);
304
- * ```
305
- */
306
- export const setPreference = <T = any>(key: PreferenceKey, value: T): void => {
307
- try {
308
- if (config.backend === 'localStorage' && isLocalStorageAvailable()) {
309
- localStorage.setItem(getStorageKey(key), JSON.stringify(value));
310
- }
311
- } catch (error) {
312
- console.warn(`Failed to set preference "${key}":`, error);
313
- }
314
- };
315
-
316
- /**
317
- * Async version for IndexedDB (future use)
318
- */
319
- export const setPreferenceAsync = async <T = any>(
320
- key: PreferenceKey,
321
- value: T
322
- ): Promise<void> => {
323
- try {
324
- if (config.backend === 'indexedDB') {
325
- await indexedDBStore.set(getStorageKey(key), value);
326
- } else {
327
- setPreference(key, value);
328
- }
329
- } catch (error) {
330
- console.warn(`Failed to set preference "${key}":`, error);
331
- }
332
- };
333
-
334
- /**
335
- * Remove a preference
336
- *
337
- * @param key - Preference key to remove
338
- *
339
- * @example
340
- * ```ts
341
- * import { removePreference } from '@hellboy/ds';
342
- *
343
- * removePreference('layout.leftSidebarWidth');
344
- * ```
345
- */
346
- export const removePreference = (key: PreferenceKey): void => {
347
- try {
348
- if (config.backend === 'localStorage' && isLocalStorageAvailable()) {
349
- localStorage.removeItem(getStorageKey(key));
350
- }
351
- } catch (error) {
352
- console.warn(`Failed to remove preference "${key}":`, error);
353
- }
354
- };
355
-
356
- /**
357
- * Async version for IndexedDB (future use)
358
- */
359
- export const removePreferenceAsync = async (key: PreferenceKey): Promise<void> => {
360
- try {
361
- if (config.backend === 'indexedDB') {
362
- await indexedDBStore.remove(getStorageKey(key));
363
- } else {
364
- removePreference(key);
365
- }
366
- } catch (error) {
367
- console.warn(`Failed to remove preference "${key}":`, error);
368
- }
369
- };
370
-
371
- /**
372
- * Clear all preferences
373
- *
374
- * @example
375
- * ```ts
376
- * import { clearPreferences } from '@hellboy/ds';
377
- *
378
- * clearPreferences(); // Removes all hellboy-ds preferences
379
- * ```
380
- */
381
- export const clearPreferences = (): void => {
382
- try {
383
- if (config.backend === 'localStorage' && isLocalStorageAvailable()) {
384
- const prefix = `${config.prefix}:`;
385
- const keysToRemove: string[] = [];
386
-
387
- for (let i = 0; i < localStorage.length; i++) {
388
- const key = localStorage.key(i);
389
- if (key?.startsWith(prefix)) {
390
- keysToRemove.push(key);
391
- }
392
- }
393
-
394
- keysToRemove.forEach(key => localStorage.removeItem(key));
395
- }
396
- } catch (error) {
397
- console.warn('Failed to clear preferences:', error);
398
- }
399
- };
400
-
401
- /**
402
- * Async version for IndexedDB (future use)
403
- */
404
- export const clearPreferencesAsync = async (): Promise<void> => {
405
- try {
406
- if (config.backend === 'indexedDB') {
407
- await indexedDBStore.clear();
408
- } else {
409
- clearPreferences();
410
- }
411
- } catch (error) {
412
- console.warn('Failed to clear preferences:', error);
413
- }
414
- };
415
-
416
- /**
417
- * Get all preferences as an object
418
- *
419
- * @returns Object containing all stored preferences
420
- *
421
- * @example
422
- * ```ts
423
- * import { getAllPreferences } from '@hellboy/ds';
424
- *
425
- * const allPrefs = getAllPreferences();
426
- * console.log(allPrefs);
427
- * // { 'theme': 'dark', 'layout.leftSidebarWidth': 320, ... }
428
- * ```
429
- */
430
- export const getAllPreferences = (): Record<string, any> => {
431
- const preferences: Record<string, any> = {};
432
-
433
- try {
434
- if (config.backend === 'localStorage' && isLocalStorageAvailable()) {
435
- const prefix = `${config.prefix}:`;
436
-
437
- for (let i = 0; i < localStorage.length; i++) {
438
- const key = localStorage.key(i);
439
- if (key?.startsWith(prefix)) {
440
- const prefKey = key.substring(prefix.length);
441
- const value = localStorage.getItem(key);
442
- if (value !== null) {
443
- try {
444
- preferences[prefKey] = JSON.parse(value);
445
- } catch {
446
- preferences[prefKey] = value;
447
- }
448
- }
449
- }
450
- }
451
- }
452
- } catch (error) {
453
- console.warn('Failed to get all preferences:', error);
454
- }
455
-
456
- return preferences;
457
- };
458
-
459
- /**
460
- * Export preferences as JSON
461
- * Useful for backup or migration
462
- *
463
- * @returns JSON string of all preferences
464
- *
465
- * @example
466
- * ```ts
467
- * import { exportPreferences } from '@hellboy/ds';
468
- *
469
- * const json = exportPreferences();
470
- * // Download or save to file
471
- * const blob = new Blob([json], { type: 'application/json' });
472
- * const url = URL.createObjectURL(blob);
473
- * ```
474
- */
475
- export const exportPreferences = (): string => {
476
- const prefs = getAllPreferences();
477
- return JSON.stringify(prefs, null, 2);
478
- };
479
-
480
- /**
481
- * Import preferences from JSON
482
- * Useful for restoring from backup
483
- *
484
- * @param json - JSON string of preferences to import
485
- * @param merge - Whether to merge with existing preferences (default: false)
486
- *
487
- * @example
488
- * ```ts
489
- * import { importPreferences } from '@hellboy/ds';
490
- *
491
- * const json = '{"theme":"dark","layout.leftSidebarWidth":320}';
492
- * importPreferences(json, true); // Merge with existing
493
- * ```
494
- */
495
- export const importPreferences = (json: string, merge: boolean = false): void => {
496
- try {
497
- const prefs = JSON.parse(json);
498
-
499
- if (!merge) {
500
- clearPreferences();
501
- }
502
-
503
- Object.entries(prefs).forEach(([key, value]) => {
504
- setPreference(key, value);
505
- });
506
- } catch (error) {
507
- console.warn('Failed to import preferences:', error);
508
- }
509
- };
510
-
511
- /**
512
- * Create a preference namespace for better organization
513
- * Returns scoped get/set functions
514
- *
515
- * @param namespace - Namespace prefix
516
- *
517
- * @example
518
- * ```ts
519
- * import { createPreferenceNamespace } from '@hellboy/ds';
520
- *
521
- * const layoutPrefs = createPreferenceNamespace('layout');
522
- * layoutPrefs.set('sidebarWidth', 300);
523
- * const width = layoutPrefs.get('sidebarWidth', 280);
524
- * ```
525
- */
526
- export const createPreferenceNamespace = (namespace: string) => {
527
- const getKey = (key: string) => `${namespace}.${key}`;
528
-
529
- return {
530
- get: <T = any>(key: string, defaultValue?: T) =>
531
- getPreference<T>(getKey(key), defaultValue),
532
- set: <T = any>(key: string, value: T) =>
533
- setPreference(getKey(key), value),
534
- remove: (key: string) => removePreference(getKey(key)),
535
- clear: () => {
536
- const prefs = getAllPreferences();
537
- const prefix = `${namespace}.`;
538
- Object.keys(prefs)
539
- .filter(key => key.startsWith(prefix))
540
- .forEach(key => removePreference(key));
541
- },
542
- };
543
- };
544
-
545
- /**
546
- * React hook for preference management (optional, for React users)
547
- * Import this separately to avoid bundling React in non-React projects
548
- *
549
- * Note: This is a reference implementation. For production use in React,
550
- * consider creating a dedicated hook file with proper React imports.
551
- *
552
- * @example
553
- * ```tsx
554
- * // In a React component
555
- * import { useState, useEffect } from 'react';
556
- * import { getPreference, setPreference } from '@hellboy/ds';
557
- *
558
- * function usePreference<T>(key: string, defaultValue: T) {
559
- * const [value, setValue] = useState<T>(() =>
560
- * getPreference(key, defaultValue) ?? defaultValue
561
- * );
562
- *
563
- * const updateValue = (newValue: T) => {
564
- * setValue(newValue);
565
- * setPreference(key, newValue);
566
- * };
567
- *
568
- * return [value, updateValue] as const;
569
- * }
570
- *
571
- * // Usage
572
- * function MyComponent() {
573
- * const [theme, setTheme] = usePreference('theme', 'light');
574
- * return <button onClick={() => setTheme('dark')}>Switch to Dark</button>;
575
- * }
576
- * ```
577
- */
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "useDefineForClassFields": true,
5
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
- "module": "ESNext",
7
- "skipLibCheck": true,
8
- "esModuleInterop": true,
9
- "allowSyntheticDefaultImports": true,
10
- "strict": true,
11
- "noUnusedLocals": true,
12
- "noUnusedParameters": true,
13
- "noImplicitReturns": true,
14
- "declaration": true,
15
- "declarationMap": true,
16
- "sourceMap": true,
17
- "outDir": "./dist",
18
- "rootDir": "./src",
19
- "moduleResolution": "bundler",
20
- "jsx": "react-jsx",
21
- "resolveJsonModule": true,
22
- "isolatedModules": true
23
- },
24
- "include": ["src"]
25
- }
package/tsup.config.ts DELETED
@@ -1,52 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts'],
5
- format: ['esm', 'cjs'],
6
- dts: true,
7
- sourcemap: true,
8
- clean: true,
9
- external: ['react', 'react-dom', '@ariakit/react'],
10
- // Copiar arquivos CSS e outros assets
11
- // Copiar `theme.css` para `dist/theme.css` para que consumidores
12
- // possam carregá-lo diretamente no browser como fonte da verdade.
13
- asset: [],
14
- onSuccess: async () => {
15
- const fs = await import('fs');
16
- const path = await import('path');
17
- // Generate theme.css from theme.json (source of truth)
18
- try {
19
- const jsonPath = path.resolve(__dirname, 'src/style/themes/theme.json');
20
- const dest = path.resolve(__dirname, 'dist/theme.css');
21
-
22
- let themeObj: any = null;
23
- if (fs.existsSync && fs.existsSync(jsonPath)) {
24
- const raw = await fs.promises.readFile(jsonPath, 'utf8');
25
- themeObj = JSON.parse(raw);
26
- }
27
-
28
- if (themeObj) {
29
- const css = `/**\n * Theme Configuration (generated from theme.json)\n * Generated during build from src/style/themes/theme.json\n */\n\n:root {\n /* Primary Color */\n --primary-hue: ${themeObj.primary.hue};\n --primary-saturation: ${themeObj.primary.saturation}%;\n --primary-lightness: ${themeObj.primary.lightness}%;\n --primary-lightness-hover: ${themeObj.primary.hover}%;\n --primary-lightness-active: ${themeObj.primary.active}%;\n --primary-lightness-disabled: ${themeObj.primary.disabled}%;\n\n /* Secondary Color */\n --secondary-hue: ${themeObj.secondary.hue};\n --secondary-saturation: ${themeObj.secondary.saturation}%;\n --secondary-lightness: ${themeObj.secondary.lightness}%;\n --secondary-lightness-hover: ${themeObj.secondary.hover}%;\n --secondary-lightness-active: ${themeObj.secondary.active}%;\n --secondary-lightness-disabled: ${themeObj.secondary.disabled}%;\n\n /* Accent Color */\n --accent-hue: ${themeObj.accent.hue};\n --accent-saturation: ${themeObj.accent.saturation}%;\n --accent-lightness: ${themeObj.accent.lightness}%;\n --accent-lightness-hover: ${themeObj.accent.hover}%;\n --accent-lightness-active: ${themeObj.accent.active}%;\n --accent-lightness-disabled: ${themeObj.accent.disabled}%;\n\n /* Status Colors */\n --success-hue: ${themeObj.success.hue};\n --success-saturation: ${themeObj.success.saturation}%;\n --success-lightness: ${themeObj.success.lightness}%;\n --success-lightness-hover: ${themeObj.success.hover}%;\n --success-lightness-active: ${themeObj.success.active}%;\n\n --warning-hue: ${themeObj.warning.hue};\n --warning-saturation: ${themeObj.warning.saturation}%;\n --warning-lightness: ${themeObj.warning.lightness}%;\n --warning-lightness-hover: ${themeObj.warning.hover}%;\n --warning-lightness-active: ${themeObj.warning.active}%;\n\n --error-hue: ${themeObj.error.hue};\n --error-saturation: ${themeObj.error.saturation}%;\n --error-lightness: ${themeObj.error.lightness}%;\n --error-lightness-hover: ${themeObj.error.hover}%;\n --error-lightness-active: ${themeObj.error.active}%;\n\n --info-hue: ${themeObj.info.hue};\n --info-saturation: ${themeObj.info.saturation}%;\n --info-lightness: ${themeObj.info.lightness}%;\n --info-lightness-hover: ${themeObj.info.hover}%;\n --info-lightness-active: ${themeObj.info.active}%;\n}\n`;
30
-
31
- await fs.promises.writeFile(dest, css, 'utf8');
32
- console.log('✓ Generated dist/theme.css from theme.json');
33
-
34
- // Also copy into web/public if exists
35
- const webPublicDest = path.resolve(__dirname, '..', 'web', 'public', 'theme.css');
36
- const webPublicDir = path.dirname(webPublicDest);
37
- if (fs.existsSync && fs.existsSync(webPublicDir)) {
38
- await fs.promises.writeFile(webPublicDest, css, 'utf8');
39
- console.log('✓ Wrote theme.css to ../web/public/theme.css');
40
- } else {
41
- console.log('→ ../web/public not found — skipped writing theme.css to web public');
42
- }
43
- } else {
44
- console.warn('! theme.json not found; skipping theme generation');
45
- }
46
- } catch (err) {
47
- console.warn('! Could not generate theme.css from theme.json:', err);
48
- }
49
-
50
- console.log('✓ Build completo!');
51
- },
52
- });