@neetechs/ui 0.0.2 → 0.0.3

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 (203) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/dist/ai/ai-action-button/ai-action-button.css +269 -269
  4. package/dist/ai/ai-approval-card/ai-approval-card.css +320 -320
  5. package/dist/ai/ai-conversation-panel/ai-conversation-panel.css +403 -403
  6. package/dist/ai/ai-prompt-input/ai-prompt-input.css +377 -377
  7. package/dist/ai/ai-proposal-card/ai-proposal-card.css +358 -358
  8. package/dist/ai/ai-suggestion-card/ai-suggestion-card.css +293 -293
  9. package/dist/ai/ai-tool-call/ai-tool-call.css +255 -255
  10. package/dist/ai/index.css +1 -1
  11. package/dist/appearance/cache.d.ts +50 -0
  12. package/dist/appearance/cache.d.ts.map +1 -0
  13. package/dist/appearance/cache.js +126 -0
  14. package/dist/appearance/cache.js.map +1 -0
  15. package/dist/appearance/cookie.d.ts +18 -0
  16. package/dist/appearance/cookie.d.ts.map +1 -0
  17. package/dist/appearance/cookie.js +56 -0
  18. package/dist/appearance/cookie.js.map +1 -0
  19. package/dist/appearance/index.d.ts +8 -0
  20. package/dist/appearance/index.d.ts.map +1 -0
  21. package/dist/appearance/index.js +5 -0
  22. package/dist/appearance/index.js.map +1 -0
  23. package/dist/appearance/preference.d.ts +13 -0
  24. package/dist/appearance/preference.d.ts.map +1 -0
  25. package/dist/appearance/preference.js +26 -0
  26. package/dist/appearance/preference.js.map +1 -0
  27. package/dist/appearance/theme-controller.d.ts +80 -0
  28. package/dist/appearance/theme-controller.d.ts.map +1 -0
  29. package/dist/appearance/theme-controller.js +235 -0
  30. package/dist/appearance/theme-controller.js.map +1 -0
  31. package/dist/appearance/types.d.ts +21 -0
  32. package/dist/appearance/types.d.ts.map +1 -0
  33. package/dist/appearance/types.js +2 -0
  34. package/dist/appearance/types.js.map +1 -0
  35. package/dist/components/alert/alert.css +216 -216
  36. package/dist/components/avatar/avatar.css +218 -218
  37. package/dist/components/badge/badge.css +174 -174
  38. package/dist/components/breadcrumb/breadcrumb.css +204 -204
  39. package/dist/components/button/button.css +166 -166
  40. package/dist/components/card/card.css +219 -219
  41. package/dist/components/checkbox/checkbox.css +186 -186
  42. package/dist/components/chip/chip.css +267 -267
  43. package/dist/components/data-grid/data-grid.css +368 -368
  44. package/dist/components/dialog/dialog.css +274 -274
  45. package/dist/components/drawer/drawer.css +402 -402
  46. package/dist/components/dropdown/dropdown.css +297 -297
  47. package/dist/components/icon-button/icon-button.css +157 -157
  48. package/dist/components/input/input.css +162 -162
  49. package/dist/components/menu/menu.css +313 -313
  50. package/dist/components/modal/modal.css +317 -317
  51. package/dist/components/pagination/pagination.css +249 -249
  52. package/dist/components/panel/panel.css +282 -282
  53. package/dist/components/progress/progress.css +247 -247
  54. package/dist/components/radio/radio.css +163 -163
  55. package/dist/components/segmented-control/segmented-control.css +204 -204
  56. package/dist/components/select/select.css +102 -102
  57. package/dist/components/skeleton/skeleton.css +262 -262
  58. package/dist/components/split-button/split-button.css +284 -284
  59. package/dist/components/switch/switch.css +180 -180
  60. package/dist/components/tabs/tabs.css +288 -288
  61. package/dist/components/textarea/textarea.css +85 -85
  62. package/dist/components/toast/toast.css +322 -322
  63. package/dist/components/tooltip/tooltip.css +254 -254
  64. package/dist/domain/billing/index.css +497 -497
  65. package/dist/domain/calendar/day-slice/day-slice.css +382 -382
  66. package/dist/domain/calendar/day-timeline/day-timeline.css +323 -323
  67. package/dist/domain/calendar/event-card/event-card.css +336 -336
  68. package/dist/domain/calendar/month-grid/month-grid.css +419 -419
  69. package/dist/domain/calendar/week-grid/week-grid.css +469 -469
  70. package/dist/domain/companies/index.css +525 -525
  71. package/dist/index.css +5 -5
  72. package/dist/index.d.ts +1 -0
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +1 -0
  75. package/dist/index.js.map +1 -1
  76. package/dist/patterns/command-palette/command-palette.css +438 -438
  77. package/dist/patterns/company-switcher/company-switcher.css +362 -362
  78. package/dist/patterns/empty-state/empty-state.css +258 -258
  79. package/dist/patterns/error-state/error-state.css +271 -271
  80. package/dist/patterns/loading-state/loading-state.css +287 -287
  81. package/dist/patterns/notification-center/notification-center.css +437 -437
  82. package/dist/patterns/profile-menu/profile-menu.css +296 -296
  83. package/dist/patterns/search-bar/search-bar.css +443 -443
  84. package/dist/patterns/workspace-switcher/workspace-switcher.css +379 -379
  85. package/dist/shell/app-shell/app-shell.css +67 -67
  86. package/dist/shell/content-frame/content-frame.css +93 -93
  87. package/dist/shell/header/header.css +177 -177
  88. package/dist/shell/index.css +5 -5
  89. package/dist/shell/mobile-nav/mobile-nav.css +170 -170
  90. package/dist/shell/right-drawer/right-drawer.css +107 -107
  91. package/dist/shell/sidebar/sidebar.css +145 -145
  92. package/dist/styles/animations/motion.css +161 -161
  93. package/dist/styles/base.css +81 -81
  94. package/dist/styles/reset.css +50 -50
  95. package/dist/styles/themes/dark.css +119 -119
  96. package/dist/styles/themes/high-contrast.css +118 -118
  97. package/dist/styles/themes/light.css +118 -118
  98. package/dist/styles/tokens/breakpoints.css +14 -14
  99. package/dist/styles/tokens/color.css +96 -96
  100. package/dist/styles/tokens/elevation.css +31 -31
  101. package/dist/styles/tokens/motion.css +35 -35
  102. package/dist/styles/tokens/radius.css +20 -20
  103. package/dist/styles/tokens/spacing.css +49 -49
  104. package/dist/styles/tokens/typography.css +83 -83
  105. package/dist/styles/tokens/z-index.css +14 -14
  106. package/dist/styles/utilities/layout.css +134 -134
  107. package/dist/styles/utilities/text.css +151 -151
  108. package/dist/styles/utilities/visibility.css +47 -47
  109. package/docs/theming.md +227 -0
  110. package/package.json +23 -16
  111. package/src/ai/ai-action-button/ai-action-button.css +269 -269
  112. package/src/ai/ai-approval-card/ai-approval-card.css +320 -320
  113. package/src/ai/ai-conversation-panel/ai-conversation-panel.css +403 -403
  114. package/src/ai/ai-prompt-input/ai-prompt-input.css +377 -377
  115. package/src/ai/ai-proposal-card/ai-proposal-card.css +358 -358
  116. package/src/ai/ai-suggestion-card/ai-suggestion-card.css +293 -293
  117. package/src/ai/ai-tool-call/ai-tool-call.css +255 -255
  118. package/src/ai/index.css +1 -1
  119. package/src/appearance/cache.ts +160 -0
  120. package/src/appearance/cookie.ts +68 -0
  121. package/src/appearance/index.ts +38 -0
  122. package/src/appearance/preference.ts +35 -0
  123. package/src/appearance/theme-controller.ts +383 -0
  124. package/src/appearance/types.ts +23 -0
  125. package/src/behaviors/dialog.ts +167 -167
  126. package/src/behaviors/drawer.ts +176 -176
  127. package/src/behaviors/dropdown.ts +280 -280
  128. package/src/behaviors/focus-trap.ts +260 -260
  129. package/src/behaviors/ids.ts +47 -47
  130. package/src/behaviors/index.ts +6 -6
  131. package/src/behaviors/keyboard.ts +302 -302
  132. package/src/behaviors/overlay.ts +230 -230
  133. package/src/components/alert/alert.css +216 -216
  134. package/src/components/avatar/avatar.css +218 -218
  135. package/src/components/badge/badge.css +174 -174
  136. package/src/components/breadcrumb/breadcrumb.css +204 -204
  137. package/src/components/button/button.css +166 -166
  138. package/src/components/card/card.css +219 -219
  139. package/src/components/checkbox/checkbox.css +186 -186
  140. package/src/components/chip/chip.css +267 -267
  141. package/src/components/data-grid/data-grid.css +368 -368
  142. package/src/components/dialog/dialog.css +274 -274
  143. package/src/components/drawer/drawer.css +402 -402
  144. package/src/components/dropdown/dropdown.css +297 -297
  145. package/src/components/icon-button/icon-button.css +157 -157
  146. package/src/components/input/input.css +162 -162
  147. package/src/components/menu/menu.css +313 -313
  148. package/src/components/modal/modal.css +317 -317
  149. package/src/components/pagination/pagination.css +249 -249
  150. package/src/components/panel/panel.css +282 -282
  151. package/src/components/progress/progress.css +247 -247
  152. package/src/components/radio/radio.css +163 -163
  153. package/src/components/segmented-control/segmented-control.css +204 -204
  154. package/src/components/select/select.css +102 -102
  155. package/src/components/skeleton/skeleton.css +262 -262
  156. package/src/components/split-button/split-button.css +284 -284
  157. package/src/components/switch/switch.css +180 -180
  158. package/src/components/tabs/tabs.css +288 -288
  159. package/src/components/textarea/textarea.css +85 -85
  160. package/src/components/toast/toast.css +322 -322
  161. package/src/components/tooltip/tooltip.css +254 -254
  162. package/src/domain/billing/index.css +497 -497
  163. package/src/domain/calendar/day-slice/day-slice.css +382 -382
  164. package/src/domain/calendar/day-timeline/day-timeline.css +323 -323
  165. package/src/domain/calendar/event-card/event-card.css +336 -336
  166. package/src/domain/calendar/month-grid/month-grid.css +419 -419
  167. package/src/domain/calendar/week-grid/week-grid.css +469 -469
  168. package/src/domain/companies/index.css +525 -525
  169. package/src/index.css +5 -5
  170. package/src/index.ts +6 -5
  171. package/src/patterns/command-palette/command-palette.css +438 -438
  172. package/src/patterns/company-switcher/company-switcher.css +362 -362
  173. package/src/patterns/empty-state/empty-state.css +258 -258
  174. package/src/patterns/error-state/error-state.css +271 -271
  175. package/src/patterns/loading-state/loading-state.css +287 -287
  176. package/src/patterns/notification-center/notification-center.css +437 -437
  177. package/src/patterns/profile-menu/profile-menu.css +296 -296
  178. package/src/patterns/search-bar/search-bar.css +443 -443
  179. package/src/patterns/workspace-switcher/workspace-switcher.css +379 -379
  180. package/src/shell/app-shell/app-shell.css +67 -67
  181. package/src/shell/content-frame/content-frame.css +93 -93
  182. package/src/shell/header/header.css +177 -177
  183. package/src/shell/index.css +5 -5
  184. package/src/shell/mobile-nav/mobile-nav.css +170 -170
  185. package/src/shell/right-drawer/right-drawer.css +107 -107
  186. package/src/shell/sidebar/sidebar.css +145 -145
  187. package/src/styles/animations/motion.css +161 -161
  188. package/src/styles/base.css +81 -81
  189. package/src/styles/reset.css +50 -50
  190. package/src/styles/themes/dark.css +119 -119
  191. package/src/styles/themes/high-contrast.css +118 -118
  192. package/src/styles/themes/light.css +118 -118
  193. package/src/styles/tokens/breakpoints.css +14 -14
  194. package/src/styles/tokens/color.css +96 -96
  195. package/src/styles/tokens/elevation.css +31 -31
  196. package/src/styles/tokens/motion.css +35 -35
  197. package/src/styles/tokens/radius.css +20 -20
  198. package/src/styles/tokens/spacing.css +49 -49
  199. package/src/styles/tokens/typography.css +83 -83
  200. package/src/styles/tokens/z-index.css +14 -14
  201. package/src/styles/utilities/layout.css +134 -134
  202. package/src/styles/utilities/text.css +151 -151
  203. package/src/styles/utilities/visibility.css +47 -47
@@ -0,0 +1,126 @@
1
+ import { normalizeThemePreference } from './preference.js';
2
+ /**
3
+ * Canonical local-storage cache key. The cache is a bootstrap fallback
4
+ * only — the backend account setting and the `nt_theme` cookie always
5
+ * override it.
6
+ */
7
+ export const NT_THEME_CACHE_KEY = 'nt_theme_preference';
8
+ /**
9
+ * Legacy app-specific keys replaced by NT_THEME_CACHE_KEY. Read once by
10
+ * migrateLegacyThemeCache and then deleted.
11
+ */
12
+ export const NT_LEGACY_THEME_CACHE_KEYS = [
13
+ 'themeMode',
14
+ 'selectedTheme',
15
+ 'aiTheme',
16
+ 'billingTheme',
17
+ ];
18
+ /**
19
+ * Returns `window.localStorage` when it is available and accessible,
20
+ * otherwise `null`. Never throws (storage access can throw under blocked
21
+ * third-party storage or strict privacy settings).
22
+ */
23
+ export function getDefaultThemeStorage() {
24
+ try {
25
+ if (typeof window === 'undefined' || !window.localStorage) {
26
+ return null;
27
+ }
28
+ return window.localStorage;
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ /**
35
+ * Reads the cached preference. Invalid cached values are removed and
36
+ * reported as `null`. Storage errors never throw.
37
+ */
38
+ export function readThemeCache(storage = getDefaultThemeStorage()) {
39
+ if (!storage) {
40
+ return null;
41
+ }
42
+ try {
43
+ const raw = storage.getItem(NT_THEME_CACHE_KEY);
44
+ if (raw === null) {
45
+ return null;
46
+ }
47
+ const preference = normalizeThemePreference(raw);
48
+ if (preference === null) {
49
+ storage.removeItem(NT_THEME_CACHE_KEY);
50
+ }
51
+ return preference;
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ }
57
+ /**
58
+ * Caches a preference for the next bootstrap. Storage errors never throw.
59
+ */
60
+ export function writeThemeCache(preference, storage = getDefaultThemeStorage()) {
61
+ if (!storage) {
62
+ return;
63
+ }
64
+ try {
65
+ storage.setItem(NT_THEME_CACHE_KEY, preference);
66
+ }
67
+ catch {
68
+ /* Cache is best-effort only. */
69
+ }
70
+ }
71
+ /**
72
+ * Removes the cached preference. Storage errors never throw.
73
+ */
74
+ export function clearThemeCache(storage = getDefaultThemeStorage()) {
75
+ if (!storage) {
76
+ return;
77
+ }
78
+ try {
79
+ storage.removeItem(NT_THEME_CACHE_KEY);
80
+ }
81
+ catch {
82
+ /* Cache is best-effort only. */
83
+ }
84
+ }
85
+ /**
86
+ * One-time migration from legacy app-specific storage keys to
87
+ * NT_THEME_CACHE_KEY.
88
+ *
89
+ * - A legacy value is adopted only when no valid canonical value exists.
90
+ * - All legacy keys are deleted either way.
91
+ * - Only touches the local cache — it never overwrites a backend or
92
+ * cookie preference, because the cache sits below both in the
93
+ * source-of-truth order.
94
+ *
95
+ * Returns the canonical cached preference after migration, or `null`.
96
+ */
97
+ export function migrateLegacyThemeCache(options = {}) {
98
+ const storage = options.storage !== undefined ? options.storage : getDefaultThemeStorage();
99
+ const legacyKeys = options.legacyKeys ?? NT_LEGACY_THEME_CACHE_KEYS;
100
+ if (!storage) {
101
+ return null;
102
+ }
103
+ try {
104
+ const existing = readThemeCache(storage);
105
+ let migrated = null;
106
+ if (existing === null) {
107
+ for (const key of legacyKeys) {
108
+ migrated = normalizeThemePreference(storage.getItem(key));
109
+ if (migrated !== null) {
110
+ break;
111
+ }
112
+ }
113
+ if (migrated !== null) {
114
+ storage.setItem(NT_THEME_CACHE_KEY, migrated);
115
+ }
116
+ }
117
+ for (const key of legacyKeys) {
118
+ storage.removeItem(key);
119
+ }
120
+ return existing ?? migrated;
121
+ }
122
+ catch {
123
+ return null;
124
+ }
125
+ }
126
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/appearance/cache.ts"],"names":[],"mappings":"AAAA,OAAO,E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,CAAC;YAC7B,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;QAED,OAAO,QAAQ,IAAI,QAAQ,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { ThemePreference } from './types.js';
2
+ /**
3
+ * Shared-domain bootstrap cookie set by the backend
4
+ * (`Domain=.neetechs.com; Secure; SameSite=Lax` in production).
5
+ * It only reduces theme flashing; the backend account setting is the
6
+ * source of truth.
7
+ */
8
+ export declare const NT_THEME_COOKIE_NAME = "nt_theme";
9
+ /**
10
+ * Reads the `nt_theme` bootstrap cookie. Only reads this single cookie —
11
+ * never authentication or other sensitive cookies.
12
+ *
13
+ * Pass `cookieString` explicitly during SSR (e.g. the request `Cookie`
14
+ * header). When omitted, `document.cookie` is used if a document exists;
15
+ * otherwise `null` is returned.
16
+ */
17
+ export declare function readThemeCookie(cookieString?: string): ThemePreference | null;
18
+ //# sourceMappingURL=cookie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/appearance/cookie.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAa,CAAC;AAE/C;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA4B7E"}
@@ -0,0 +1,56 @@
1
+ import { normalizeThemePreference } from './preference.js';
2
+ /**
3
+ * Shared-domain bootstrap cookie set by the backend
4
+ * (`Domain=.neetechs.com; Secure; SameSite=Lax` in production).
5
+ * It only reduces theme flashing; the backend account setting is the
6
+ * source of truth.
7
+ */
8
+ export const NT_THEME_COOKIE_NAME = 'nt_theme';
9
+ /**
10
+ * Reads the `nt_theme` bootstrap cookie. Only reads this single cookie —
11
+ * never authentication or other sensitive cookies.
12
+ *
13
+ * Pass `cookieString` explicitly during SSR (e.g. the request `Cookie`
14
+ * header). When omitted, `document.cookie` is used if a document exists;
15
+ * otherwise `null` is returned.
16
+ */
17
+ export function readThemeCookie(cookieString) {
18
+ const source = cookieString ?? readDocumentCookieString();
19
+ if (!source) {
20
+ return null;
21
+ }
22
+ for (const pair of source.split(';')) {
23
+ const separatorIndex = pair.indexOf('=');
24
+ if (separatorIndex === -1) {
25
+ continue;
26
+ }
27
+ if (pair.slice(0, separatorIndex).trim() !== NT_THEME_COOKIE_NAME) {
28
+ continue;
29
+ }
30
+ const preference = normalizeThemePreference(decodeCookieValue(pair.slice(separatorIndex + 1).trim()));
31
+ if (preference !== null) {
32
+ return preference;
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+ function decodeCookieValue(value) {
38
+ try {
39
+ return decodeURIComponent(value);
40
+ }
41
+ catch {
42
+ return value;
43
+ }
44
+ }
45
+ function readDocumentCookieString() {
46
+ if (typeof document === 'undefined') {
47
+ return null;
48
+ }
49
+ try {
50
+ return document.cookie;
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ }
56
+ //# sourceMappingURL=cookie.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/appearance/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAG3D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,YAAqB;IACnD,MAAM,MAAM,GAAG,YAAY,IAAI,wBAAwB,EAAE,CAAC;IAE1D,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAEzC,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;YAC1B,SAAS;QACX,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,IAAI,EAAE,KAAK,oBAAoB,EAAE,CAAC;YAClE,SAAS;QACX,CAAC;QAED,MAAM,UAAU,GAAG,wBAAwB,CACzC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CACzD,CAAC;QAEF,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACxB,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa;IACtC,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,wBAAwB;IAC/B,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,MAAM,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type { ResolvedTheme, ResolvedThemeState, ThemePreference, ThemeSource, } from './types.js';
2
+ export { normalizeThemePreference, resolveTheme } from './preference.js';
3
+ export { NT_THEME_COOKIE_NAME, readThemeCookie } from './cookie.js';
4
+ export { NT_LEGACY_THEME_CACHE_KEYS, NT_THEME_CACHE_KEY, clearThemeCache, getDefaultThemeStorage, migrateLegacyThemeCache, readThemeCache, writeThemeCache, } from './cache.js';
5
+ export type { MigrateLegacyThemeCacheOptions, ThemeStorage } from './cache.js';
6
+ export { NT_THEME_ATTRIBUTE, NT_THEME_DEFAULT_RESOLVED, NT_THEME_PREFERENCE_ATTRIBUTE, applyThemeToDocument, bootstrapNeetechsTheme, createThemeController, } from './theme-controller.js';
7
+ export type { BootstrapThemeOptions, MatchMediaRef, SetPreferenceOptions, ThemeChangeListener, ThemeController, ThemeControllerOptions, } from './theme-controller.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/appearance/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,8BAA8B,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/E,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,6BAA6B,EAC7B,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,sBAAsB,GACvB,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { normalizeThemePreference, resolveTheme } from './preference.js';
2
+ export { NT_THEME_COOKIE_NAME, readThemeCookie } from './cookie.js';
3
+ export { NT_LEGACY_THEME_CACHE_KEYS, NT_THEME_CACHE_KEY, clearThemeCache, getDefaultThemeStorage, migrateLegacyThemeCache, readThemeCache, writeThemeCache, } from './cache.js';
4
+ export { NT_THEME_ATTRIBUTE, NT_THEME_DEFAULT_RESOLVED, NT_THEME_PREFERENCE_ATTRIBUTE, applyThemeToDocument, bootstrapNeetechsTheme, createThemeController, } from './theme-controller.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/appearance/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,6BAA6B,EAC7B,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { ResolvedTheme, ThemePreference } from './types.js';
2
+ /**
3
+ * Validates an untrusted value (cookie, cache, backend payload) into a
4
+ * ThemePreference. Anything other than `system`, `light` or `dark` is
5
+ * rejected with `null`.
6
+ */
7
+ export declare function normalizeThemePreference(value: unknown): ThemePreference | null;
8
+ /**
9
+ * Resolves a stored preference to the theme rendered on the document.
10
+ * `systemDark` is the current `(prefers-color-scheme: dark)` match state.
11
+ */
12
+ export declare function resolveTheme(preference: ThemePreference, systemDark: boolean): ResolvedTheme;
13
+ //# sourceMappingURL=preference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preference.d.ts","sourceRoot":"","sources":["../../src/appearance/preference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEjE;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAY/E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,eAAe,EAC3B,UAAU,EAAE,OAAO,GAClB,aAAa,CAMf"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Validates an untrusted value (cookie, cache, backend payload) into a
3
+ * ThemePreference. Anything other than `system`, `light` or `dark` is
4
+ * rejected with `null`.
5
+ */
6
+ export function normalizeThemePreference(value) {
7
+ if (typeof value !== 'string') {
8
+ return null;
9
+ }
10
+ const normalized = value.trim().toLowerCase();
11
+ if (normalized === 'system' || normalized === 'light' || normalized === 'dark') {
12
+ return normalized;
13
+ }
14
+ return null;
15
+ }
16
+ /**
17
+ * Resolves a stored preference to the theme rendered on the document.
18
+ * `systemDark` is the current `(prefers-color-scheme: dark)` match state.
19
+ */
20
+ export function resolveTheme(preference, systemDark) {
21
+ if (preference === 'system') {
22
+ return systemDark ? 'dark' : 'light';
23
+ }
24
+ return preference;
25
+ }
26
+ //# sourceMappingURL=preference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preference.js","sourceRoot":"","sources":["../../src/appearance/preference.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAE9C,IAAI,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;QAC/E,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,UAA2B,EAC3B,UAAmB;IAEnB,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IACvC,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { type ThemeStorage } from './cache.js';
2
+ import type { ResolvedTheme, ResolvedThemeState, ThemePreference, ThemeSource } from './types.js';
3
+ /** Canonical rendering attribute consumed by the theme CSS. */
4
+ export declare const NT_THEME_ATTRIBUTE = "data-nt-theme";
5
+ /** Informational attribute exposing the stored preference. */
6
+ export declare const NT_THEME_PREFERENCE_ATTRIBUTE = "data-nt-theme-preference";
7
+ /**
8
+ * Fallback resolved theme when the system preference cannot be detected
9
+ * (SSR, no matchMedia). Matches the package `:root` default token set.
10
+ */
11
+ export declare const NT_THEME_DEFAULT_RESOLVED: ResolvedTheme;
12
+ export type MatchMediaRef = (query: string) => MediaQueryList;
13
+ export interface ThemeEnvironmentOptions {
14
+ /** Explicit document (or `null` to force SSR behavior). Defaults to the global `document` when one exists. */
15
+ documentRef?: Document | null;
16
+ /** Explicit matchMedia (or `null` to disable system detection). Defaults to `window.matchMedia` when available. */
17
+ matchMediaRef?: MatchMediaRef | null;
18
+ /** Explicit storage (or `null` to disable the cache). Defaults to `window.localStorage` when accessible. */
19
+ storage?: ThemeStorage | null;
20
+ /** Explicit cookie string for SSR (e.g. the request `Cookie` header). Defaults to `document.cookie`. */
21
+ cookieString?: string;
22
+ /** Set to false to skip reading and writing the local cache. Default true. */
23
+ useCache?: boolean;
24
+ /** Resolved theme used when the system preference is unknown. Default `'dark'`. */
25
+ fallbackResolved?: ResolvedTheme;
26
+ }
27
+ export type ThemeControllerOptions = ThemeEnvironmentOptions;
28
+ export type BootstrapThemeOptions = ThemeEnvironmentOptions;
29
+ export interface SetPreferenceOptions {
30
+ /** Where the preference came from. Default `'backend'`. */
31
+ source?: ThemeSource;
32
+ /** Set to false to skip updating the local cache. Default true. */
33
+ updateCache?: boolean;
34
+ }
35
+ export type ThemeChangeListener = (state: ResolvedThemeState) => void;
36
+ export interface ThemeController {
37
+ /** Current state without side effects. */
38
+ getState(): ResolvedThemeState;
39
+ /**
40
+ * Reads bootstrap sources (cookie, then cache, then system), applies the
41
+ * theme to the document and attaches the system-theme listener. Calling
42
+ * it again while initialized is a no-op returning the current state.
43
+ */
44
+ initialize(): ResolvedThemeState;
45
+ /**
46
+ * Applies a preference, typically the backend account setting after it
47
+ * loads. Overrides whatever bootstrap source is active. Invalid values
48
+ * are ignored.
49
+ */
50
+ setPreference(preference: ThemePreference, options?: SetPreferenceOptions): ResolvedThemeState;
51
+ /** Notifies on every applied state change. Returns an unsubscribe function. */
52
+ subscribe(listener: ThemeChangeListener): () => void;
53
+ /** Removes listeners and subscribers. The controller can be initialized again. */
54
+ destroy(): void;
55
+ }
56
+ /**
57
+ * Applies the resolved theme to the document root:
58
+ *
59
+ * <html data-nt-theme="dark" data-nt-theme-preference="system">
60
+ *
61
+ * The document root is the canonical target — applications must not set
62
+ * theme attributes on `body` or app roots independently.
63
+ */
64
+ export declare function applyThemeToDocument(documentRef: Document, state: ResolvedThemeState): void;
65
+ /**
66
+ * Minimal early bootstrap, safe to run before framework rendering (from
67
+ * `main.ts`, `main.tsx`, an inline script or an Angular initializer).
68
+ * Reads the `nt_theme` cookie, then the local cache, then the system
69
+ * preference; applies `data-nt-theme` to the document root and returns
70
+ * the resolved state. No network requests, no listeners, SSR-safe no-op
71
+ * on the DOM when no document exists.
72
+ */
73
+ export declare function bootstrapNeetechsTheme(options?: BootstrapThemeOptions): ResolvedThemeState;
74
+ /**
75
+ * Creates the single per-application theme controller. Framework-neutral:
76
+ * no browser globals are touched until `initialize`, `setPreference` or
77
+ * `getState` run, and every global can be injected for SSR and tests.
78
+ */
79
+ export declare function createThemeController(options?: ThemeControllerOptions): ThemeController;
80
+ //# sourceMappingURL=theme-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-controller.d.ts","sourceRoot":"","sources":["../../src/appearance/theme-controller.ts"],"names":[],"mappings":"AAAA,OAAO,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AAE,eAAe,EAC3B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,kBAAkB,CAAC;IACtB,+EAA+E;IAC/E,SAAS,CAAC,QAAQ,EAAE,mBAAmB,GAAG,MAAM,IAAI,CAAC;IACrD,kFAAkF;IAClF,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,QAAQ,EACrB,KAAK,EAAE,kBAAkB,GACxB,IAAI,CASN;AA0HD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,qBAA0B,GAClC,kBAAkB,CAUpB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,sBAA2B,GACnC,eAAe,CAgIjB"}
@@ -0,0 +1,235 @@
1
+ import { getDefaultThemeStorage, readThemeCache, writeThemeCache, } from './cache.js';
2
+ import { readThemeCookie } from './cookie.js';
3
+ import { normalizeThemePreference, resolveTheme } from './preference.js';
4
+ /** Canonical rendering attribute consumed by the theme CSS. */
5
+ export const NT_THEME_ATTRIBUTE = 'data-nt-theme';
6
+ /** Informational attribute exposing the stored preference. */
7
+ export const NT_THEME_PREFERENCE_ATTRIBUTE = 'data-nt-theme-preference';
8
+ const PREFERS_DARK_QUERY = '(prefers-color-scheme: dark)';
9
+ /**
10
+ * Fallback resolved theme when the system preference cannot be detected
11
+ * (SSR, no matchMedia). Matches the package `:root` default token set.
12
+ */
13
+ export const NT_THEME_DEFAULT_RESOLVED = 'dark';
14
+ /**
15
+ * Applies the resolved theme to the document root:
16
+ *
17
+ * <html data-nt-theme="dark" data-nt-theme-preference="system">
18
+ *
19
+ * The document root is the canonical target — applications must not set
20
+ * theme attributes on `body` or app roots independently.
21
+ */
22
+ export function applyThemeToDocument(documentRef, state) {
23
+ const root = documentRef?.documentElement;
24
+ if (!root) {
25
+ return;
26
+ }
27
+ root.setAttribute(NT_THEME_ATTRIBUTE, state.resolved);
28
+ root.setAttribute(NT_THEME_PREFERENCE_ATTRIBUTE, state.preference);
29
+ }
30
+ function createEnvironment(options) {
31
+ const getDocument = () => {
32
+ if (options.documentRef !== undefined) {
33
+ return options.documentRef;
34
+ }
35
+ return typeof document === 'undefined' ? null : document;
36
+ };
37
+ const getMatchMedia = () => {
38
+ if (options.matchMediaRef !== undefined) {
39
+ return options.matchMediaRef;
40
+ }
41
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
42
+ return null;
43
+ }
44
+ return window.matchMedia.bind(window);
45
+ };
46
+ const getStorage = () => {
47
+ if (options.storage !== undefined) {
48
+ return options.storage;
49
+ }
50
+ return getDefaultThemeStorage();
51
+ };
52
+ const readCookie = () => {
53
+ if (options.cookieString !== undefined) {
54
+ return readThemeCookie(options.cookieString);
55
+ }
56
+ const doc = getDocument();
57
+ if (!doc) {
58
+ return null;
59
+ }
60
+ try {
61
+ return readThemeCookie(doc.cookie);
62
+ }
63
+ catch {
64
+ return null;
65
+ }
66
+ };
67
+ return {
68
+ getDocument,
69
+ getMatchMedia,
70
+ getStorage,
71
+ readCookie,
72
+ useCache: options.useCache !== false,
73
+ fallbackResolved: options.fallbackResolved ?? NT_THEME_DEFAULT_RESOLVED,
74
+ };
75
+ }
76
+ function readSystemDark(environment) {
77
+ const matchMedia = environment.getMatchMedia();
78
+ if (!matchMedia) {
79
+ return null;
80
+ }
81
+ try {
82
+ return matchMedia(PREFERS_DARK_QUERY).matches;
83
+ }
84
+ catch {
85
+ return null;
86
+ }
87
+ }
88
+ function computeState(environment, preference, source) {
89
+ if (preference !== 'system') {
90
+ return { preference, resolved: preference, source };
91
+ }
92
+ const systemDark = readSystemDark(environment);
93
+ if (systemDark === null) {
94
+ return {
95
+ preference,
96
+ resolved: environment.fallbackResolved,
97
+ source: source === 'system' ? 'default' : source,
98
+ };
99
+ }
100
+ return { preference, resolved: resolveTheme('system', systemDark), source };
101
+ }
102
+ function resolveBootstrapState(environment) {
103
+ const cookiePreference = environment.readCookie();
104
+ if (cookiePreference !== null) {
105
+ return computeState(environment, cookiePreference, 'cookie');
106
+ }
107
+ if (environment.useCache) {
108
+ const cachedPreference = readThemeCache(environment.getStorage());
109
+ if (cachedPreference !== null) {
110
+ return computeState(environment, cachedPreference, 'cache');
111
+ }
112
+ }
113
+ return computeState(environment, 'system', 'system');
114
+ }
115
+ /**
116
+ * Minimal early bootstrap, safe to run before framework rendering (from
117
+ * `main.ts`, `main.tsx`, an inline script or an Angular initializer).
118
+ * Reads the `nt_theme` cookie, then the local cache, then the system
119
+ * preference; applies `data-nt-theme` to the document root and returns
120
+ * the resolved state. No network requests, no listeners, SSR-safe no-op
121
+ * on the DOM when no document exists.
122
+ */
123
+ export function bootstrapNeetechsTheme(options = {}) {
124
+ const environment = createEnvironment(options);
125
+ const state = resolveBootstrapState(environment);
126
+ const doc = environment.getDocument();
127
+ if (doc) {
128
+ applyThemeToDocument(doc, state);
129
+ }
130
+ return state;
131
+ }
132
+ /**
133
+ * Creates the single per-application theme controller. Framework-neutral:
134
+ * no browser globals are touched until `initialize`, `setPreference` or
135
+ * `getState` run, and every global can be injected for SSR and tests.
136
+ */
137
+ export function createThemeController(options = {}) {
138
+ const environment = createEnvironment(options);
139
+ const listeners = new Set();
140
+ let state = {
141
+ preference: 'system',
142
+ resolved: environment.fallbackResolved,
143
+ source: 'default',
144
+ };
145
+ let initialized = false;
146
+ let detachSystemListener = null;
147
+ function commit(next) {
148
+ state = next;
149
+ const doc = environment.getDocument();
150
+ if (doc) {
151
+ applyThemeToDocument(doc, state);
152
+ }
153
+ for (const listener of [...listeners]) {
154
+ listener(state);
155
+ }
156
+ return state;
157
+ }
158
+ function handleSystemChange(event) {
159
+ if (state.preference !== 'system') {
160
+ return;
161
+ }
162
+ const resolved = event.matches ? 'dark' : 'light';
163
+ if (resolved === state.resolved) {
164
+ return;
165
+ }
166
+ // The stored preference stays `system`; only the resolved theme moves.
167
+ commit({ ...state, resolved });
168
+ }
169
+ function attachSystemListener() {
170
+ if (detachSystemListener) {
171
+ return;
172
+ }
173
+ const matchMedia = environment.getMatchMedia();
174
+ if (!matchMedia) {
175
+ return;
176
+ }
177
+ let mediaQueryList;
178
+ try {
179
+ mediaQueryList = matchMedia(PREFERS_DARK_QUERY);
180
+ }
181
+ catch {
182
+ return;
183
+ }
184
+ if (typeof mediaQueryList.addEventListener === 'function') {
185
+ mediaQueryList.addEventListener('change', handleSystemChange);
186
+ detachSystemListener = () => {
187
+ mediaQueryList.removeEventListener('change', handleSystemChange);
188
+ };
189
+ }
190
+ else if (typeof mediaQueryList.addListener === 'function') {
191
+ // Fallback for engines without MediaQueryList EventTarget support.
192
+ mediaQueryList.addListener(handleSystemChange);
193
+ detachSystemListener = () => {
194
+ mediaQueryList.removeListener(handleSystemChange);
195
+ };
196
+ }
197
+ }
198
+ return {
199
+ getState() {
200
+ return state;
201
+ },
202
+ initialize() {
203
+ if (initialized) {
204
+ return state;
205
+ }
206
+ initialized = true;
207
+ attachSystemListener();
208
+ return commit(resolveBootstrapState(environment));
209
+ },
210
+ setPreference(preference, setOptions = {}) {
211
+ const normalized = normalizeThemePreference(preference);
212
+ if (normalized === null) {
213
+ return state;
214
+ }
215
+ if (environment.useCache && setOptions.updateCache !== false) {
216
+ writeThemeCache(normalized, environment.getStorage());
217
+ }
218
+ attachSystemListener();
219
+ return commit(computeState(environment, normalized, setOptions.source ?? 'backend'));
220
+ },
221
+ subscribe(listener) {
222
+ listeners.add(listener);
223
+ return () => {
224
+ listeners.delete(listener);
225
+ };
226
+ },
227
+ destroy() {
228
+ detachSystemListener?.();
229
+ detachSystemListener = null;
230
+ listeners.clear();
231
+ initialized = false;
232
+ },
233
+ };
234
+ }
235
+ //# sourceMappingURL=theme-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-controller.js","sourceRoot":"","sources":["../../src/appearance/theme-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,GAEhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE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C,EAAE;YAErC,MAAM,UAAU,GAAG,wBAAwB,CAAC,UAAU,CAAC,CAAC;YAExD,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;gBACxB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,IAAI,WAAW,CAAC,QAAQ,IAAI,UAAU,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;gBAC7D,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC;YACxD,CAAC;YAED,oBAAoB,EAAE,CAAC;YAEvB,OAAO,MAAM,CACX,YAAY,CAAC,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,MAAM,IAAI,SAAS,CAAC,CACtE,CAAC;QACJ,CAAC;QAED,SAAS,CAAC,QAA6B;YACrC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAExB,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7B,CAAC,CAAC;QACJ,CAAC;QAED,OAAO;YACL,oBAAoB,EAAE,EAAE,CAAC;YACzB,oBAAoB,GAAG,IAAI,CAAC;YAC5B,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,WAAW,GAAG,KAAK,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Stored appearance preference. Persisted by the Django backend and edited
3
+ * in MyAccount. The shared package only bootstraps, resolves and applies it.
4
+ */
5
+ export type ThemePreference = 'system' | 'light' | 'dark';
6
+ /**
7
+ * Theme actually rendered on the document. `system` always resolves to one
8
+ * of these before touching the DOM.
9
+ */
10
+ export type ResolvedTheme = 'light' | 'dark';
11
+ /**
12
+ * Where the currently applied preference came from, in source-of-truth
13
+ * order: backend > cookie > cache > system > default.
14
+ */
15
+ export type ThemeSource = 'backend' | 'cookie' | 'cache' | 'system' | 'default';
16
+ export interface ResolvedThemeState {
17
+ preference: ThemePreference;
18
+ resolved: ResolvedTheme;
19
+ source: ThemeSource;
20
+ }
21
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/appearance/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEhF,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,eAAe,CAAC;IAC5B,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/appearance/types.ts"],"names":[],"mappings":""}