@neetechs/ui 0.0.3 → 0.1.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 (377) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/CONTRIBUTING.md +60 -0
  3. package/LICENSE +21 -21
  4. package/README.md +861 -650
  5. package/dist/ai/ai-action-button/ai-action-button.css +271 -270
  6. package/dist/ai/ai-approval-card/ai-approval-card.css +323 -320
  7. package/dist/ai/ai-conversation-panel/ai-conversation-panel.css +447 -403
  8. package/dist/ai/ai-prompt-input/ai-prompt-input.css +380 -377
  9. package/dist/ai/ai-proposal-card/ai-proposal-card.css +358 -358
  10. package/dist/ai/ai-suggestion-card/ai-suggestion-card.css +295 -293
  11. package/dist/ai/ai-tool-call/ai-tool-call.css +256 -255
  12. package/dist/ai/index.css +7 -7
  13. package/dist/appearance/cache.d.ts +6 -1
  14. package/dist/appearance/cache.d.ts.map +1 -1
  15. package/dist/appearance/cache.js +57 -1
  16. package/dist/appearance/cache.js.map +1 -1
  17. package/dist/appearance/cookie.d.ts +16 -1
  18. package/dist/appearance/cookie.d.ts.map +1 -1
  19. package/dist/appearance/cookie.js +73 -4
  20. package/dist/appearance/cookie.js.map +1 -1
  21. package/dist/appearance/index.d.ts +9 -6
  22. package/dist/appearance/index.d.ts.map +1 -1
  23. package/dist/appearance/index.js +5 -4
  24. package/dist/appearance/index.js.map +1 -1
  25. package/dist/appearance/inline-bootstrap.d.ts +29 -0
  26. package/dist/appearance/inline-bootstrap.d.ts.map +1 -0
  27. package/dist/appearance/inline-bootstrap.js +154 -0
  28. package/dist/appearance/inline-bootstrap.js.map +1 -0
  29. package/dist/appearance/preference.d.ts +9 -1
  30. package/dist/appearance/preference.d.ts.map +1 -1
  31. package/dist/appearance/preference.js +54 -0
  32. package/dist/appearance/preference.js.map +1 -1
  33. package/dist/appearance/theme-controller.d.ts +37 -49
  34. package/dist/appearance/theme-controller.d.ts.map +1 -1
  35. package/dist/appearance/theme-controller.js +153 -143
  36. package/dist/appearance/theme-controller.js.map +1 -1
  37. package/dist/appearance/types.d.ts +29 -2
  38. package/dist/appearance/types.d.ts.map +1 -1
  39. package/dist/behaviors/announcer.d.ts +34 -0
  40. package/dist/behaviors/announcer.d.ts.map +1 -0
  41. package/dist/behaviors/announcer.js +150 -0
  42. package/dist/behaviors/announcer.js.map +1 -0
  43. package/dist/behaviors/calendar.d.ts +15 -0
  44. package/dist/behaviors/calendar.d.ts.map +1 -0
  45. package/dist/behaviors/calendar.js +77 -0
  46. package/dist/behaviors/calendar.js.map +1 -0
  47. package/dist/behaviors/data-grid.d.ts +18 -0
  48. package/dist/behaviors/data-grid.d.ts.map +1 -0
  49. package/dist/behaviors/data-grid.js +114 -0
  50. package/dist/behaviors/data-grid.js.map +1 -0
  51. package/dist/behaviors/dialog.d.ts +14 -0
  52. package/dist/behaviors/dialog.d.ts.map +1 -1
  53. package/dist/behaviors/dialog.js +24 -6
  54. package/dist/behaviors/dialog.js.map +1 -1
  55. package/dist/behaviors/direction.d.ts +10 -0
  56. package/dist/behaviors/direction.d.ts.map +1 -0
  57. package/dist/behaviors/direction.js +24 -0
  58. package/dist/behaviors/direction.js.map +1 -0
  59. package/dist/behaviors/drawer.d.ts +15 -3
  60. package/dist/behaviors/drawer.d.ts.map +1 -1
  61. package/dist/behaviors/drawer.js +25 -10
  62. package/dist/behaviors/drawer.js.map +1 -1
  63. package/dist/behaviors/dropdown.d.ts +11 -0
  64. package/dist/behaviors/dropdown.d.ts.map +1 -1
  65. package/dist/behaviors/dropdown.js +53 -11
  66. package/dist/behaviors/dropdown.js.map +1 -1
  67. package/dist/behaviors/focus-trap.d.ts.map +1 -1
  68. package/dist/behaviors/focus-trap.js +45 -5
  69. package/dist/behaviors/focus-trap.js.map +1 -1
  70. package/dist/behaviors/forms.d.ts +32 -0
  71. package/dist/behaviors/forms.d.ts.map +1 -0
  72. package/dist/behaviors/forms.js +147 -0
  73. package/dist/behaviors/forms.js.map +1 -0
  74. package/dist/behaviors/index.d.ts +11 -0
  75. package/dist/behaviors/index.d.ts.map +1 -1
  76. package/dist/behaviors/index.js +11 -0
  77. package/dist/behaviors/index.js.map +1 -1
  78. package/dist/behaviors/keyboard.d.ts.map +1 -1
  79. package/dist/behaviors/keyboard.js +4 -2
  80. package/dist/behaviors/keyboard.js.map +1 -1
  81. package/dist/behaviors/navigation.d.ts +98 -0
  82. package/dist/behaviors/navigation.d.ts.map +1 -0
  83. package/dist/behaviors/navigation.js +295 -0
  84. package/dist/behaviors/navigation.js.map +1 -0
  85. package/dist/behaviors/overlay.d.ts +6 -0
  86. package/dist/behaviors/overlay.d.ts.map +1 -1
  87. package/dist/behaviors/overlay.js +93 -3
  88. package/dist/behaviors/overlay.js.map +1 -1
  89. package/dist/behaviors/popover.d.ts +22 -0
  90. package/dist/behaviors/popover.d.ts.map +1 -0
  91. package/dist/behaviors/popover.js +126 -0
  92. package/dist/behaviors/popover.js.map +1 -0
  93. package/dist/behaviors/sidebar.d.ts +78 -0
  94. package/dist/behaviors/sidebar.d.ts.map +1 -0
  95. package/dist/behaviors/sidebar.js +263 -0
  96. package/dist/behaviors/sidebar.js.map +1 -0
  97. package/dist/behaviors/state.d.ts +49 -0
  98. package/dist/behaviors/state.d.ts.map +1 -0
  99. package/dist/behaviors/state.js +220 -0
  100. package/dist/behaviors/state.js.map +1 -0
  101. package/dist/behaviors/tabs.d.ts +18 -0
  102. package/dist/behaviors/tabs.d.ts.map +1 -0
  103. package/dist/behaviors/tabs.js +103 -0
  104. package/dist/behaviors/tabs.js.map +1 -0
  105. package/dist/behaviors/viewport.d.ts +40 -0
  106. package/dist/behaviors/viewport.d.ts.map +1 -0
  107. package/dist/behaviors/viewport.js +47 -0
  108. package/dist/behaviors/viewport.js.map +1 -0
  109. package/dist/components/alert/alert.css +220 -217
  110. package/dist/components/avatar/avatar.css +220 -219
  111. package/dist/components/badge/badge.css +174 -174
  112. package/dist/components/breadcrumb/breadcrumb.css +207 -205
  113. package/dist/components/button/button.css +238 -167
  114. package/dist/components/button-group/button-group.css +111 -0
  115. package/dist/components/card/card.css +265 -220
  116. package/dist/components/checkbox/checkbox.css +189 -187
  117. package/dist/components/chip/chip.css +269 -267
  118. package/dist/components/data-grid/data-grid.css +520 -369
  119. package/dist/components/description-list/description-list.css +187 -0
  120. package/dist/components/dialog/dialog.css +339 -275
  121. package/dist/components/drawer/drawer.css +484 -403
  122. package/dist/components/dropdown/dropdown.css +316 -298
  123. package/dist/components/icon-button/icon-button.css +162 -158
  124. package/dist/components/index.css +5 -2
  125. package/dist/components/input/input.css +163 -163
  126. package/dist/components/menu/menu.css +315 -314
  127. package/dist/components/pagination/pagination.css +250 -249
  128. package/dist/components/panel/panel.css +284 -283
  129. package/dist/components/popover/popover.css +153 -0
  130. package/dist/components/progress/progress.css +256 -248
  131. package/dist/components/radio/radio.css +166 -164
  132. package/dist/components/segmented-control/segmented-control.css +205 -205
  133. package/dist/components/select/select.css +117 -103
  134. package/dist/components/skeleton/skeleton.css +267 -262
  135. package/dist/components/split-button/split-button.css +292 -285
  136. package/dist/components/stat/stat.css +403 -0
  137. package/dist/components/switch/switch.css +195 -181
  138. package/dist/components/table/table.css +220 -0
  139. package/dist/components/tabs/tabs.css +293 -289
  140. package/dist/components/textarea/textarea.css +86 -86
  141. package/dist/components/toast/toast.css +345 -323
  142. package/dist/components/tooltip/tooltip.css +258 -255
  143. package/dist/domain/billing/index.css +629 -498
  144. package/dist/domain/calendar/agenda-list/agenda-list.css +224 -0
  145. package/dist/domain/calendar/day-slice/day-slice.css +384 -383
  146. package/dist/domain/calendar/day-timeline/day-timeline.css +332 -324
  147. package/dist/domain/calendar/event-card/event-card.css +338 -336
  148. package/dist/domain/calendar/index.css +5 -4
  149. package/dist/domain/calendar/month-grid/month-grid.css +426 -420
  150. package/dist/domain/calendar/week-grid/week-grid.css +480 -470
  151. package/dist/domain/companies/index.css +526 -525
  152. package/dist/domain/index.css +3 -3
  153. package/dist/index.css +5 -5
  154. package/dist/index.d.ts +2 -1
  155. package/dist/index.d.ts.map +1 -1
  156. package/dist/index.js +2 -1
  157. package/dist/index.js.map +1 -1
  158. package/dist/localization/index.d.ts +8 -0
  159. package/dist/localization/index.d.ts.map +1 -0
  160. package/dist/localization/index.js +22 -0
  161. package/dist/localization/index.js.map +1 -0
  162. package/dist/patterns/command-palette/command-palette.css +447 -439
  163. package/dist/patterns/company-switcher/company-switcher.css +390 -363
  164. package/dist/patterns/content-state/content-state.css +236 -0
  165. package/dist/patterns/empty-state/empty-state.css +260 -259
  166. package/dist/patterns/error-state/error-state.css +272 -271
  167. package/dist/patterns/form-layout/form-layout.css +106 -0
  168. package/dist/patterns/index.css +9 -3
  169. package/dist/patterns/loading-state/loading-state.css +287 -287
  170. package/dist/patterns/master-detail/master-detail.css +103 -0
  171. package/dist/patterns/notification-center/notification-center.css +443 -438
  172. package/dist/patterns/page/page.css +303 -0
  173. package/dist/patterns/profile-menu/profile-menu.css +298 -297
  174. package/dist/patterns/record-list/record-list.css +302 -0
  175. package/dist/patterns/search-bar/search-bar.css +457 -444
  176. package/dist/patterns/settings-layout/settings-layout.css +150 -0
  177. package/dist/patterns/workflow/workflow.css +168 -0
  178. package/dist/shell/app-shell/app-shell.css +211 -68
  179. package/dist/shell/content-frame/content-frame.css +93 -93
  180. package/dist/shell/footer/footer.css +256 -0
  181. package/dist/shell/header/header.css +328 -178
  182. package/dist/shell/index.css +8 -6
  183. package/dist/shell/mobile-nav/mobile-nav.css +254 -171
  184. package/dist/shell/navbar/navbar.css +255 -0
  185. package/dist/shell/sidebar/sidebar.css +314 -146
  186. package/dist/styles/accessibility.css +150 -0
  187. package/dist/styles/animations/motion.css +162 -162
  188. package/dist/styles/appearance/accent.css +215 -0
  189. package/dist/styles/appearance/density.css +61 -0
  190. package/dist/styles/appearance/motion.css +40 -0
  191. package/dist/styles/base.css +83 -82
  192. package/dist/styles/index.css +28 -21
  193. package/dist/styles/localization.css +56 -0
  194. package/dist/styles/reset.css +51 -50
  195. package/dist/styles/responsive.css +101 -0
  196. package/dist/styles/themes/dark.css +202 -120
  197. package/dist/styles/themes/high-contrast.css +290 -119
  198. package/dist/styles/themes/light.css +201 -119
  199. package/dist/styles/tokens/breakpoints.css +37 -15
  200. package/dist/styles/tokens/color.css +102 -96
  201. package/dist/styles/tokens/compatibility.css +33 -0
  202. package/dist/styles/tokens/elevation.css +26 -32
  203. package/dist/styles/tokens/index.css +9 -8
  204. package/dist/styles/tokens/motion.css +35 -35
  205. package/dist/styles/tokens/radius.css +26 -21
  206. package/dist/styles/tokens/spacing.css +56 -50
  207. package/dist/styles/tokens/typography.css +85 -84
  208. package/dist/styles/tokens/z-index.css +14 -14
  209. package/dist/styles/utilities/layout.css +153 -135
  210. package/dist/styles/utilities/text.css +152 -152
  211. package/dist/styles/utilities/visibility.css +47 -47
  212. package/dist/types/index.d.ts +1 -0
  213. package/dist/types/index.d.ts.map +1 -1
  214. package/dist/version.d.ts +2 -0
  215. package/dist/version.d.ts.map +1 -0
  216. package/dist/version.js +3 -0
  217. package/dist/version.js.map +1 -0
  218. package/docs/NEETECHS_UI_UPGRADE_PLAN.md +192 -0
  219. package/docs/accessibility.md +218 -0
  220. package/docs/appearance-and-theming.md +150 -0
  221. package/docs/brand-palette.md +36 -0
  222. package/docs/component-architecture.md +137 -0
  223. package/docs/component-guidelines.md +64 -0
  224. package/docs/components.md +173 -0
  225. package/docs/content-and-terminology.md +207 -0
  226. package/docs/design-system-audit.md +120 -0
  227. package/docs/design-system-baseline-audit.md +226 -0
  228. package/docs/design-token-contract.md +279 -0
  229. package/docs/layering.md +53 -0
  230. package/docs/localization-and-rtl.md +147 -0
  231. package/docs/migration.md +193 -0
  232. package/docs/page-patterns-and-workflows.md +275 -0
  233. package/docs/responsive-and-adaptive-design.md +351 -0
  234. package/docs/semantic-role-migration-audit.md +77 -0
  235. package/docs/site-chrome.md +313 -0
  236. package/docs/states-feedback-and-recovery.md +206 -0
  237. package/docs/theming.md +5 -227
  238. package/package.json +48 -6
  239. package/src/ai/ai-action-button/ai-action-button.css +271 -270
  240. package/src/ai/ai-approval-card/ai-approval-card.css +323 -320
  241. package/src/ai/ai-conversation-panel/ai-conversation-panel.css +447 -403
  242. package/src/ai/ai-prompt-input/ai-prompt-input.css +380 -377
  243. package/src/ai/ai-proposal-card/ai-proposal-card.css +358 -358
  244. package/src/ai/ai-suggestion-card/ai-suggestion-card.css +295 -293
  245. package/src/ai/ai-tool-call/ai-tool-call.css +256 -255
  246. package/src/ai/index.css +7 -7
  247. package/src/appearance/cache.ts +236 -160
  248. package/src/appearance/cookie.ts +184 -68
  249. package/src/appearance/index.ts +86 -38
  250. package/src/appearance/inline-bootstrap.ts +163 -0
  251. package/src/appearance/preference.ts +121 -35
  252. package/src/appearance/theme-controller.ts +384 -383
  253. package/src/appearance/types.ts +61 -23
  254. package/src/behaviors/announcer.ts +222 -0
  255. package/src/behaviors/calendar.ts +92 -0
  256. package/src/behaviors/data-grid.ts +133 -0
  257. package/src/behaviors/dialog.ts +203 -168
  258. package/src/behaviors/direction.ts +34 -0
  259. package/src/behaviors/drawer.ts +210 -177
  260. package/src/behaviors/dropdown.ts +344 -281
  261. package/src/behaviors/focus-trap.ts +304 -261
  262. package/src/behaviors/forms.ts +205 -0
  263. package/src/behaviors/ids.ts +47 -47
  264. package/src/behaviors/index.ts +12 -1
  265. package/src/behaviors/keyboard.ts +305 -303
  266. package/src/behaviors/navigation.ts +417 -0
  267. package/src/behaviors/overlay.ts +344 -231
  268. package/src/behaviors/popover.ts +157 -0
  269. package/src/behaviors/sidebar.ts +342 -0
  270. package/src/behaviors/state.ts +282 -0
  271. package/src/behaviors/tabs.ts +137 -0
  272. package/src/behaviors/viewport.ts +61 -0
  273. package/src/components/alert/alert.css +220 -217
  274. package/src/components/avatar/avatar.css +220 -219
  275. package/src/components/badge/badge.css +174 -174
  276. package/src/components/breadcrumb/breadcrumb.css +207 -205
  277. package/src/components/button/button.css +238 -167
  278. package/src/components/button-group/button-group.css +111 -0
  279. package/src/components/card/card.css +265 -220
  280. package/src/components/checkbox/checkbox.css +189 -187
  281. package/src/components/chip/chip.css +269 -267
  282. package/src/components/data-grid/data-grid.css +520 -369
  283. package/src/components/description-list/description-list.css +187 -0
  284. package/src/components/dialog/dialog.css +339 -275
  285. package/src/components/drawer/drawer.css +484 -403
  286. package/src/components/dropdown/dropdown.css +316 -298
  287. package/src/components/icon-button/icon-button.css +162 -158
  288. package/src/components/index.css +5 -2
  289. package/src/components/input/input.css +163 -163
  290. package/src/components/menu/menu.css +315 -314
  291. package/src/components/pagination/pagination.css +250 -249
  292. package/src/components/panel/panel.css +284 -283
  293. package/src/components/popover/popover.css +153 -0
  294. package/src/components/progress/progress.css +256 -248
  295. package/src/components/radio/radio.css +166 -164
  296. package/src/components/segmented-control/segmented-control.css +205 -205
  297. package/src/components/select/select.css +117 -103
  298. package/src/components/skeleton/skeleton.css +267 -262
  299. package/src/components/split-button/split-button.css +292 -285
  300. package/src/components/stat/stat.css +403 -0
  301. package/src/components/switch/switch.css +195 -181
  302. package/src/components/table/table.css +220 -0
  303. package/src/components/tabs/tabs.css +293 -289
  304. package/src/components/textarea/textarea.css +86 -86
  305. package/src/components/toast/toast.css +345 -323
  306. package/src/components/tooltip/tooltip.css +258 -255
  307. package/src/domain/billing/index.css +629 -498
  308. package/src/domain/calendar/agenda-list/agenda-list.css +224 -0
  309. package/src/domain/calendar/day-slice/day-slice.css +384 -383
  310. package/src/domain/calendar/day-timeline/day-timeline.css +332 -324
  311. package/src/domain/calendar/event-card/event-card.css +338 -336
  312. package/src/domain/calendar/index.css +5 -4
  313. package/src/domain/calendar/month-grid/month-grid.css +426 -420
  314. package/src/domain/calendar/week-grid/week-grid.css +480 -470
  315. package/src/domain/companies/index.css +526 -525
  316. package/src/domain/index.css +3 -3
  317. package/src/index.css +5 -5
  318. package/src/index.ts +7 -6
  319. package/src/localization/index.ts +56 -0
  320. package/src/patterns/command-palette/command-palette.css +447 -439
  321. package/src/patterns/company-switcher/company-switcher.css +390 -363
  322. package/src/patterns/content-state/content-state.css +236 -0
  323. package/src/patterns/empty-state/empty-state.css +260 -259
  324. package/src/patterns/error-state/error-state.css +272 -271
  325. package/src/patterns/form-layout/form-layout.css +106 -0
  326. package/src/patterns/index.css +9 -3
  327. package/src/patterns/loading-state/loading-state.css +287 -287
  328. package/src/patterns/master-detail/master-detail.css +103 -0
  329. package/src/patterns/notification-center/notification-center.css +443 -438
  330. package/src/patterns/page/page.css +303 -0
  331. package/src/patterns/profile-menu/profile-menu.css +298 -297
  332. package/src/patterns/record-list/record-list.css +302 -0
  333. package/src/patterns/search-bar/search-bar.css +457 -444
  334. package/src/patterns/settings-layout/settings-layout.css +150 -0
  335. package/src/patterns/workflow/workflow.css +168 -0
  336. package/src/shell/app-shell/app-shell.css +211 -68
  337. package/src/shell/content-frame/content-frame.css +93 -93
  338. package/src/shell/footer/footer.css +256 -0
  339. package/src/shell/header/header.css +328 -178
  340. package/src/shell/index.css +8 -6
  341. package/src/shell/mobile-nav/mobile-nav.css +254 -171
  342. package/src/shell/navbar/navbar.css +255 -0
  343. package/src/shell/sidebar/sidebar.css +314 -146
  344. package/src/styles/accessibility.css +150 -0
  345. package/src/styles/animations/motion.css +162 -162
  346. package/src/styles/appearance/accent.css +215 -0
  347. package/src/styles/appearance/density.css +61 -0
  348. package/src/styles/appearance/motion.css +40 -0
  349. package/src/styles/base.css +83 -82
  350. package/src/styles/index.css +28 -21
  351. package/src/styles/localization.css +56 -0
  352. package/src/styles/reset.css +51 -50
  353. package/src/styles/responsive.css +101 -0
  354. package/src/styles/themes/dark.css +202 -120
  355. package/src/styles/themes/high-contrast.css +290 -119
  356. package/src/styles/themes/light.css +201 -119
  357. package/src/styles/tokens/breakpoints.css +37 -15
  358. package/src/styles/tokens/color.css +102 -96
  359. package/src/styles/tokens/compatibility.css +33 -0
  360. package/src/styles/tokens/elevation.css +26 -32
  361. package/src/styles/tokens/index.css +9 -8
  362. package/src/styles/tokens/motion.css +35 -35
  363. package/src/styles/tokens/radius.css +26 -21
  364. package/src/styles/tokens/spacing.css +56 -50
  365. package/src/styles/tokens/typography.css +85 -84
  366. package/src/styles/tokens/z-index.css +14 -14
  367. package/src/styles/utilities/layout.css +153 -135
  368. package/src/styles/utilities/text.css +152 -152
  369. package/src/styles/utilities/visibility.css +47 -47
  370. package/src/types/index.ts +126 -125
  371. package/src/version.ts +2 -0
  372. package/dist/components/modal/modal.css +0 -318
  373. package/dist/patterns/workspace-switcher/workspace-switcher.css +0 -380
  374. package/dist/shell/right-drawer/right-drawer.css +0 -108
  375. package/src/components/modal/modal.css +0 -318
  376. package/src/patterns/workspace-switcher/workspace-switcher.css +0 -380
  377. package/src/shell/right-drawer/right-drawer.css +0 -108
@@ -1,160 +1,236 @@
1
- import { normalizeThemePreference } from './preference.js';
2
- import type { ThemePreference } from './types.js';
3
-
4
- /**
5
- * Canonical local-storage cache key. The cache is a bootstrap fallback
6
- * only — the backend account setting and the `nt_theme` cookie always
7
- * override it.
8
- */
9
- export const NT_THEME_CACHE_KEY = 'nt_theme_preference';
10
-
11
- /**
12
- * Legacy app-specific keys replaced by NT_THEME_CACHE_KEY. Read once by
13
- * migrateLegacyThemeCache and then deleted.
14
- */
15
- export const NT_LEGACY_THEME_CACHE_KEYS: readonly string[] = [
16
- 'themeMode',
17
- 'selectedTheme',
18
- 'aiTheme',
19
- 'billingTheme',
20
- ];
21
-
22
- export type ThemeStorage = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
23
-
24
- /**
25
- * Returns `window.localStorage` when it is available and accessible,
26
- * otherwise `null`. Never throws (storage access can throw under blocked
27
- * third-party storage or strict privacy settings).
28
- */
29
- export function getDefaultThemeStorage(): ThemeStorage | null {
30
- try {
31
- if (typeof window === 'undefined' || !window.localStorage) {
32
- return null;
33
- }
34
-
35
- return window.localStorage;
36
- } catch {
37
- return null;
38
- }
39
- }
40
-
41
- /**
42
- * Reads the cached preference. Invalid cached values are removed and
43
- * reported as `null`. Storage errors never throw.
44
- */
45
- export function readThemeCache(
46
- storage: ThemeStorage | null = getDefaultThemeStorage(),
47
- ): ThemePreference | null {
48
- if (!storage) {
49
- return null;
50
- }
51
-
52
- try {
53
- const raw = storage.getItem(NT_THEME_CACHE_KEY);
54
-
55
- if (raw === null) {
56
- return null;
57
- }
58
-
59
- const preference = normalizeThemePreference(raw);
60
-
61
- if (preference === null) {
62
- storage.removeItem(NT_THEME_CACHE_KEY);
63
- }
64
-
65
- return preference;
66
- } catch {
67
- return null;
68
- }
69
- }
70
-
71
- /**
72
- * Caches a preference for the next bootstrap. Storage errors never throw.
73
- */
74
- export function writeThemeCache(
75
- preference: ThemePreference,
76
- storage: ThemeStorage | null = getDefaultThemeStorage(),
77
- ): void {
78
- if (!storage) {
79
- return;
80
- }
81
-
82
- try {
83
- storage.setItem(NT_THEME_CACHE_KEY, preference);
84
- } catch {
85
- /* Cache is best-effort only. */
86
- }
87
- }
88
-
89
- /**
90
- * Removes the cached preference. Storage errors never throw.
91
- */
92
- export function clearThemeCache(
93
- storage: ThemeStorage | null = getDefaultThemeStorage(),
94
- ): void {
95
- if (!storage) {
96
- return;
97
- }
98
-
99
- try {
100
- storage.removeItem(NT_THEME_CACHE_KEY);
101
- } catch {
102
- /* Cache is best-effort only. */
103
- }
104
- }
105
-
106
- export interface MigrateLegacyThemeCacheOptions {
107
- storage?: ThemeStorage | null;
108
- legacyKeys?: readonly string[];
109
- }
110
-
111
- /**
112
- * One-time migration from legacy app-specific storage keys to
113
- * NT_THEME_CACHE_KEY.
114
- *
115
- * - A legacy value is adopted only when no valid canonical value exists.
116
- * - All legacy keys are deleted either way.
117
- * - Only touches the local cache — it never overwrites a backend or
118
- * cookie preference, because the cache sits below both in the
119
- * source-of-truth order.
120
- *
121
- * Returns the canonical cached preference after migration, or `null`.
122
- */
123
- export function migrateLegacyThemeCache(
124
- options: MigrateLegacyThemeCacheOptions = {},
125
- ): ThemePreference | null {
126
- const storage =
127
- options.storage !== undefined ? options.storage : getDefaultThemeStorage();
128
- const legacyKeys = options.legacyKeys ?? NT_LEGACY_THEME_CACHE_KEYS;
129
-
130
- if (!storage) {
131
- return null;
132
- }
133
-
134
- try {
135
- const existing = readThemeCache(storage);
136
- let migrated: ThemePreference | null = null;
137
-
138
- if (existing === null) {
139
- for (const key of legacyKeys) {
140
- migrated = normalizeThemePreference(storage.getItem(key));
141
-
142
- if (migrated !== null) {
143
- break;
144
- }
145
- }
146
-
147
- if (migrated !== null) {
148
- storage.setItem(NT_THEME_CACHE_KEY, migrated);
149
- }
150
- }
151
-
152
- for (const key of legacyKeys) {
153
- storage.removeItem(key);
154
- }
155
-
156
- return existing ?? migrated;
157
- } catch {
158
- return null;
159
- }
160
- }
1
+ import {
2
+ appearanceFromTheme,
3
+ normalizeAppearancePreference,
4
+ normalizeThemePreference,
5
+ } from './preference.js';
6
+ import type { NtAppearancePreference, ThemePreference } from './types.js';
7
+
8
+ /** Complete appearance cache. This remains a startup optimization, never account truth. */
9
+ export const NT_APPEARANCE_CACHE_KEY = 'nt_appearance_preference';
10
+
11
+ /**
12
+ * Canonical local-storage cache key. The cache is a bootstrap fallback
13
+ * only — the backend account setting and the `nt_theme` cookie always
14
+ * override it.
15
+ */
16
+ export const NT_THEME_CACHE_KEY = 'nt_theme_preference';
17
+
18
+ /**
19
+ * Legacy app-specific keys replaced by NT_THEME_CACHE_KEY. Read once by
20
+ * migrateLegacyThemeCache and then deleted.
21
+ */
22
+ export const NT_LEGACY_THEME_CACHE_KEYS: readonly string[] = [
23
+ 'themeMode',
24
+ 'selectedTheme',
25
+ 'aiTheme',
26
+ 'billingTheme',
27
+ ];
28
+
29
+ export type ThemeStorage = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
30
+
31
+ /**
32
+ * Returns `window.localStorage` when it is available and accessible,
33
+ * otherwise `null`. Never throws (storage access can throw under blocked
34
+ * third-party storage or strict privacy settings).
35
+ */
36
+ export function getDefaultThemeStorage(): ThemeStorage | null {
37
+ try {
38
+ if (typeof window === 'undefined' || !window.localStorage) {
39
+ return null;
40
+ }
41
+
42
+ return window.localStorage;
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Reads the cached preference. Invalid cached values are removed and
50
+ * reported as `null`. Storage errors never throw.
51
+ */
52
+ export function readThemeCache(
53
+ storage: ThemeStorage | null = getDefaultThemeStorage(),
54
+ ): ThemePreference | null {
55
+ if (!storage) {
56
+ return null;
57
+ }
58
+
59
+ try {
60
+ const raw = storage.getItem(NT_THEME_CACHE_KEY);
61
+
62
+ if (raw === null) {
63
+ return null;
64
+ }
65
+
66
+ const preference = normalizeThemePreference(raw);
67
+
68
+ if (preference === null) {
69
+ storage.removeItem(NT_THEME_CACHE_KEY);
70
+ }
71
+
72
+ return preference;
73
+ } catch {
74
+ return null;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Caches a preference for the next bootstrap. Storage errors never throw.
80
+ */
81
+ export function writeThemeCache(
82
+ preference: ThemePreference,
83
+ storage: ThemeStorage | null = getDefaultThemeStorage(),
84
+ ): void {
85
+ if (!storage) {
86
+ return;
87
+ }
88
+
89
+ try {
90
+ storage.setItem(NT_THEME_CACHE_KEY, preference);
91
+ } catch {
92
+ /* Cache is best-effort only. */
93
+ }
94
+ }
95
+
96
+ export function readAppearanceCache(
97
+ storage: ThemeStorage | null = getDefaultThemeStorage(),
98
+ ): NtAppearancePreference | null {
99
+ if (!storage) {
100
+ return null;
101
+ }
102
+
103
+ try {
104
+ const raw = storage.getItem(NT_APPEARANCE_CACHE_KEY);
105
+
106
+ if (raw !== null) {
107
+ try {
108
+ const preference = normalizeAppearancePreference(JSON.parse(raw));
109
+
110
+ if (preference !== null) {
111
+ return preference;
112
+ }
113
+ } catch {
114
+ /* Removed below. */
115
+ }
116
+
117
+ storage.removeItem(NT_APPEARANCE_CACHE_KEY);
118
+ }
119
+
120
+ const legacyTheme = readThemeCache(storage);
121
+ return legacyTheme === null ? null : appearanceFromTheme(legacyTheme);
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
126
+
127
+ export function writeAppearanceCache(
128
+ preference: NtAppearancePreference,
129
+ storage: ThemeStorage | null = getDefaultThemeStorage(),
130
+ ): void {
131
+ if (!storage) {
132
+ return;
133
+ }
134
+
135
+ const normalized = normalizeAppearancePreference(preference);
136
+
137
+ if (normalized === null) {
138
+ return;
139
+ }
140
+
141
+ try {
142
+ storage.setItem(NT_APPEARANCE_CACHE_KEY, JSON.stringify(normalized));
143
+ // Keep the frozen theme-only key synchronized for older applications.
144
+ storage.setItem(NT_THEME_CACHE_KEY, normalized.theme);
145
+ } catch {
146
+ /* Cache is best-effort only. */
147
+ }
148
+ }
149
+
150
+ export function clearAppearanceCache(
151
+ storage: ThemeStorage | null = getDefaultThemeStorage(),
152
+ ): void {
153
+ if (!storage) {
154
+ return;
155
+ }
156
+
157
+ try {
158
+ storage.removeItem(NT_APPEARANCE_CACHE_KEY);
159
+ storage.removeItem(NT_THEME_CACHE_KEY);
160
+ } catch {
161
+ /* Cache is best-effort only. */
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Removes the cached preference. Storage errors never throw.
167
+ */
168
+ export function clearThemeCache(
169
+ storage: ThemeStorage | null = getDefaultThemeStorage(),
170
+ ): void {
171
+ if (!storage) {
172
+ return;
173
+ }
174
+
175
+ try {
176
+ storage.removeItem(NT_THEME_CACHE_KEY);
177
+ } catch {
178
+ /* Cache is best-effort only. */
179
+ }
180
+ }
181
+
182
+ export interface MigrateLegacyThemeCacheOptions {
183
+ storage?: ThemeStorage | null;
184
+ legacyKeys?: readonly string[];
185
+ }
186
+
187
+ /**
188
+ * One-time migration from legacy app-specific storage keys to
189
+ * NT_THEME_CACHE_KEY.
190
+ *
191
+ * - A legacy value is adopted only when no valid canonical value exists.
192
+ * - All legacy keys are deleted either way.
193
+ * - Only touches the local cache — it never overwrites a backend or
194
+ * cookie preference, because the cache sits below both in the
195
+ * source-of-truth order.
196
+ *
197
+ * Returns the canonical cached preference after migration, or `null`.
198
+ */
199
+ export function migrateLegacyThemeCache(
200
+ options: MigrateLegacyThemeCacheOptions = {},
201
+ ): ThemePreference | null {
202
+ const storage =
203
+ options.storage !== undefined ? options.storage : getDefaultThemeStorage();
204
+ const legacyKeys = options.legacyKeys ?? NT_LEGACY_THEME_CACHE_KEYS;
205
+
206
+ if (!storage) {
207
+ return null;
208
+ }
209
+
210
+ try {
211
+ const existing = readThemeCache(storage);
212
+ let migrated: ThemePreference | null = null;
213
+
214
+ if (existing === null) {
215
+ for (const key of legacyKeys) {
216
+ migrated = normalizeThemePreference(storage.getItem(key));
217
+
218
+ if (migrated !== null) {
219
+ break;
220
+ }
221
+ }
222
+
223
+ if (migrated !== null) {
224
+ storage.setItem(NT_THEME_CACHE_KEY, migrated);
225
+ }
226
+ }
227
+
228
+ for (const key of legacyKeys) {
229
+ storage.removeItem(key);
230
+ }
231
+
232
+ return existing ?? migrated;
233
+ } catch {
234
+ return null;
235
+ }
236
+ }
@@ -1,68 +1,184 @@
1
- import { normalizeThemePreference } from './preference.js';
2
- import type { ThemePreference } from './types.js';
3
-
4
- /**
5
- * Shared-domain bootstrap cookie set by the backend
6
- * (`Domain=.neetechs.com; Secure; SameSite=Lax` in production).
7
- * It only reduces theme flashing; the backend account setting is the
8
- * source of truth.
9
- */
10
- export const NT_THEME_COOKIE_NAME = 'nt_theme';
11
-
12
- /**
13
- * Reads the `nt_theme` bootstrap cookie. Only reads this single cookie —
14
- * never authentication or other sensitive cookies.
15
- *
16
- * Pass `cookieString` explicitly during SSR (e.g. the request `Cookie`
17
- * header). When omitted, `document.cookie` is used if a document exists;
18
- * otherwise `null` is returned.
19
- */
20
- export function readThemeCookie(cookieString?: string): ThemePreference | null {
21
- const source = cookieString ?? readDocumentCookieString();
22
-
23
- if (!source) {
24
- return null;
25
- }
26
-
27
- for (const pair of source.split(';')) {
28
- const separatorIndex = pair.indexOf('=');
29
-
30
- if (separatorIndex === -1) {
31
- continue;
32
- }
33
-
34
- if (pair.slice(0, separatorIndex).trim() !== NT_THEME_COOKIE_NAME) {
35
- continue;
36
- }
37
-
38
- const preference = normalizeThemePreference(
39
- decodeCookieValue(pair.slice(separatorIndex + 1).trim()),
40
- );
41
-
42
- if (preference !== null) {
43
- return preference;
44
- }
45
- }
46
-
47
- return null;
48
- }
49
-
50
- function decodeCookieValue(value: string): string {
51
- try {
52
- return decodeURIComponent(value);
53
- } catch {
54
- return value;
55
- }
56
- }
57
-
58
- function readDocumentCookieString(): string | null {
59
- if (typeof document === 'undefined') {
60
- return null;
61
- }
62
-
63
- try {
64
- return document.cookie;
65
- } catch {
66
- return null;
67
- }
68
- }
1
+ import {
2
+ appearanceFromTheme,
3
+ normalizeAppearancePreference,
4
+ normalizeThemePreference,
5
+ } from './preference.js';
6
+ import type {
7
+ NtAppearancePreference,
8
+ NtSystemPreference,
9
+ ThemePreference,
10
+ } from './types.js';
11
+
12
+ /**
13
+ * Shared-domain bootstrap cookie set by the backend
14
+ * (`Domain=.neetechs.com; Secure; SameSite=Lax` in production).
15
+ * It only reduces theme flashing; the backend account setting is the
16
+ * source of truth.
17
+ */
18
+ export const NT_THEME_COOKIE_NAME = 'nt_theme';
19
+ const COOKIE_VERSION = 'v1';
20
+
21
+ export interface NtAppearanceCookieOptions {
22
+ domain?: string;
23
+ path?: string;
24
+ sameSite?: 'Strict' | 'Lax' | 'None';
25
+ secure?: boolean;
26
+ maxAge?: number;
27
+ }
28
+
29
+ /**
30
+ * Reads the `nt_theme` bootstrap cookie. Only reads this single cookie —
31
+ * never authentication or other sensitive cookies.
32
+ *
33
+ * Pass `cookieString` explicitly during SSR (e.g. the request `Cookie`
34
+ * header). When omitted, `document.cookie` is used if a document exists;
35
+ * otherwise `null` is returned.
36
+ */
37
+ export function readThemeCookie(cookieString?: string): ThemePreference | null {
38
+ return readAppearanceCookie(cookieString)?.theme ?? null;
39
+ }
40
+
41
+ /** Reads either the versioned appearance payload or the legacy raw theme value. */
42
+ export function readAppearanceCookie(
43
+ cookieString?: string,
44
+ ): NtAppearancePreference | null {
45
+ const source = cookieString ?? readDocumentCookieString();
46
+
47
+ if (!source) {
48
+ return null;
49
+ }
50
+
51
+ for (const pair of source.split(';')) {
52
+ const separatorIndex = pair.indexOf('=');
53
+
54
+ if (separatorIndex === -1) {
55
+ continue;
56
+ }
57
+
58
+ if (pair.slice(0, separatorIndex).trim() !== NT_THEME_COOKIE_NAME) {
59
+ continue;
60
+ }
61
+
62
+ const value = decodeCookieValue(pair.slice(separatorIndex + 1).trim());
63
+ const legacyTheme = normalizeThemePreference(value);
64
+
65
+ if (legacyTheme !== null) {
66
+ return appearanceFromTheme(legacyTheme);
67
+ }
68
+
69
+ const parsed = parseVersionedAppearance(value);
70
+
71
+ if (parsed !== null) {
72
+ return parsed;
73
+ }
74
+ }
75
+
76
+ return null;
77
+ }
78
+
79
+ function encodeSystemPreference(value: NtSystemPreference | undefined): string {
80
+ return value === true ? '1' : value === false ? '0' : 's';
81
+ }
82
+
83
+ function decodeSystemPreference(value: string): NtSystemPreference | null {
84
+ return value === '1' ? true : value === '0' ? false : value === 's' ? 'system' : null;
85
+ }
86
+
87
+ function parseVersionedAppearance(value: string): NtAppearancePreference | null {
88
+ const parts = value.split('|');
89
+
90
+ if (parts.length !== 6 || parts[0] !== COOKIE_VERSION) {
91
+ return null;
92
+ }
93
+
94
+ const [, theme, accent, density, motion, contrast] = parts as [
95
+ string,
96
+ string,
97
+ string,
98
+ string,
99
+ string,
100
+ string,
101
+ ];
102
+
103
+ return normalizeAppearancePreference({
104
+ theme,
105
+ accent,
106
+ density,
107
+ reduceMotion: decodeSystemPreference(motion),
108
+ highContrast: decodeSystemPreference(contrast),
109
+ });
110
+ }
111
+
112
+ export function serializeAppearanceCookieValue(
113
+ preference: NtAppearancePreference,
114
+ ): string | null {
115
+ const normalized = normalizeAppearancePreference(preference);
116
+
117
+ if (normalized === null) {
118
+ return null;
119
+ }
120
+
121
+ return [
122
+ COOKIE_VERSION,
123
+ normalized.theme,
124
+ normalized.accent,
125
+ normalized.density,
126
+ encodeSystemPreference(normalized.reduceMotion),
127
+ encodeSystemPreference(normalized.highContrast),
128
+ ].join('|');
129
+ }
130
+
131
+ /**
132
+ * Produces a browser cookie assignment / Set-Cookie value. Domain is optional
133
+ * so local development works; production may pass `.neetechs.com`.
134
+ */
135
+ export function createAppearanceCookie(
136
+ preference: NtAppearancePreference,
137
+ options: NtAppearanceCookieOptions = {},
138
+ ): string | null {
139
+ const value = serializeAppearanceCookieValue(preference);
140
+
141
+ if (value === null) {
142
+ return null;
143
+ }
144
+
145
+ const parts = [
146
+ `${NT_THEME_COOKIE_NAME}=${encodeURIComponent(value)}`,
147
+ `Path=${options.path ?? '/'}`,
148
+ `SameSite=${options.sameSite ?? 'Lax'}`,
149
+ ];
150
+
151
+ if (options.domain) {
152
+ parts.push(`Domain=${options.domain}`);
153
+ }
154
+
155
+ if (options.secure) {
156
+ parts.push('Secure');
157
+ }
158
+
159
+ if (Number.isFinite(options.maxAge)) {
160
+ parts.push(`Max-Age=${Math.max(0, Math.trunc(options.maxAge ?? 0))}`);
161
+ }
162
+
163
+ return parts.join('; ');
164
+ }
165
+
166
+ function decodeCookieValue(value: string): string {
167
+ try {
168
+ return decodeURIComponent(value);
169
+ } catch {
170
+ return value;
171
+ }
172
+ }
173
+
174
+ function readDocumentCookieString(): string | null {
175
+ if (typeof document === 'undefined') {
176
+ return null;
177
+ }
178
+
179
+ try {
180
+ return document.cookie;
181
+ } catch {
182
+ return null;
183
+ }
184
+ }