shared-lib-web 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 (186) hide show
  1. package/README.md +381 -127
  2. package/dist/components/app-brand.d.ts.map +1 -1
  3. package/dist/components/app-brand.js +9 -5
  4. package/dist/components/app-brand.js.map +1 -1
  5. package/dist/components/coming-soon.d.ts.map +1 -1
  6. package/dist/components/coming-soon.js +3 -2
  7. package/dist/components/coming-soon.js.map +1 -1
  8. package/dist/components/language-switcher.d.ts +5 -1
  9. package/dist/components/language-switcher.d.ts.map +1 -1
  10. package/dist/components/language-switcher.js +20 -7
  11. package/dist/components/language-switcher.js.map +1 -1
  12. package/dist/components/settings-menu.d.ts +4 -0
  13. package/dist/components/settings-menu.d.ts.map +1 -1
  14. package/dist/components/settings-menu.js +15 -2
  15. package/dist/components/settings-menu.js.map +1 -1
  16. package/dist/context/use-ui.d.ts.map +1 -1
  17. package/dist/context/use-ui.js +4 -3
  18. package/dist/context/use-ui.js.map +1 -1
  19. package/dist/i18n/browser-language.d.ts +9 -0
  20. package/dist/i18n/browser-language.d.ts.map +1 -0
  21. package/dist/i18n/browser-language.js +89 -0
  22. package/dist/i18n/browser-language.js.map +1 -0
  23. package/dist/i18n/default-messages.d.ts.map +1 -1
  24. package/dist/i18n/default-messages.js +3 -0
  25. package/dist/i18n/default-messages.js.map +1 -1
  26. package/dist/i18n/locale-groups.d.ts +18 -0
  27. package/dist/i18n/locale-groups.d.ts.map +1 -0
  28. package/dist/i18n/locale-groups.js +74 -0
  29. package/dist/i18n/locale-groups.js.map +1 -0
  30. package/dist/i18n/locale-service.d.ts +22 -4
  31. package/dist/i18n/locale-service.d.ts.map +1 -1
  32. package/dist/i18n/locale-service.js +95 -27
  33. package/dist/i18n/locale-service.js.map +1 -1
  34. package/dist/i18n/locale-signal.d.ts +18 -0
  35. package/dist/i18n/locale-signal.d.ts.map +1 -0
  36. package/dist/i18n/locale-signal.js +142 -0
  37. package/dist/i18n/locale-signal.js.map +1 -0
  38. package/dist/i18n/translator.d.ts +8 -1
  39. package/dist/i18n/translator.d.ts.map +1 -1
  40. package/dist/i18n/translator.js +36 -12
  41. package/dist/i18n/translator.js.map +1 -1
  42. package/dist/index.d.ts +21 -10
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +19 -8
  45. package/dist/index.js.map +1 -1
  46. package/dist/interfaces/app-types.d.ts +6 -0
  47. package/dist/interfaces/app-types.d.ts.map +1 -1
  48. package/dist/interfaces/ui-config.d.ts +162 -15
  49. package/dist/interfaces/ui-config.d.ts.map +1 -1
  50. package/dist/interfaces/ui-context.d.ts +1 -1
  51. package/dist/interfaces/ui-context.d.ts.map +1 -1
  52. package/dist/layouts/auth-layout.js +1 -1
  53. package/dist/layouts/auth-layout.js.map +1 -1
  54. package/dist/providers/provider-effects.d.ts +2 -2
  55. package/dist/providers/provider-effects.d.ts.map +1 -1
  56. package/dist/providers/provider-effects.js +4 -1
  57. package/dist/providers/provider-effects.js.map +1 -1
  58. package/dist/providers/register-config.d.ts.map +1 -1
  59. package/dist/providers/register-config.js +2 -0
  60. package/dist/providers/register-config.js.map +1 -1
  61. package/dist/providers/shared-web-ui-provider.d.ts +7 -19
  62. package/dist/providers/shared-web-ui-provider.d.ts.map +1 -1
  63. package/dist/providers/shared-web-ui-provider.js +21 -22
  64. package/dist/providers/shared-web-ui-provider.js.map +1 -1
  65. package/dist/query/query-param.d.ts +4 -1
  66. package/dist/query/query-param.d.ts.map +1 -1
  67. package/dist/query/query-param.js +6 -3
  68. package/dist/query/query-param.js.map +1 -1
  69. package/dist/state/api-loader.d.ts +19 -0
  70. package/dist/state/api-loader.d.ts.map +1 -0
  71. package/dist/state/api-loader.js +187 -0
  72. package/dist/state/api-loader.js.map +1 -0
  73. package/dist/state/auth-service.d.ts +4 -0
  74. package/dist/state/auth-service.d.ts.map +1 -1
  75. package/dist/state/auth-service.js +47 -3
  76. package/dist/state/auth-service.js.map +1 -1
  77. package/dist/state/branch-service.d.ts +1 -1
  78. package/dist/state/branch-service.js +3 -3
  79. package/dist/state/branch-service.js.map +1 -1
  80. package/dist/state/company-service.d.ts +16 -0
  81. package/dist/state/company-service.d.ts.map +1 -0
  82. package/dist/state/company-service.js +97 -0
  83. package/dist/state/company-service.js.map +1 -0
  84. package/dist/state/language-service.d.ts +5 -2
  85. package/dist/state/language-service.d.ts.map +1 -1
  86. package/dist/state/language-service.js +12 -7
  87. package/dist/state/language-service.js.map +1 -1
  88. package/dist/state/layout-choice-service.d.ts +10 -0
  89. package/dist/state/layout-choice-service.d.ts.map +1 -0
  90. package/dist/state/layout-choice-service.js +34 -0
  91. package/dist/state/layout-choice-service.js.map +1 -0
  92. package/dist/state/menu-service.d.ts +1 -1
  93. package/dist/state/menu-service.js +2 -2
  94. package/dist/state/menu-service.js.map +1 -1
  95. package/dist/state/preference-sync.d.ts +1 -1
  96. package/dist/state/preference-sync.d.ts.map +1 -1
  97. package/dist/state/preference-sync.js +11 -3
  98. package/dist/state/preference-sync.js.map +1 -1
  99. package/dist/state/signals.d.ts +9 -1
  100. package/dist/state/signals.d.ts.map +1 -1
  101. package/dist/state/signals.js +28 -4
  102. package/dist/state/signals.js.map +1 -1
  103. package/dist/theme/custom-themes.d.ts +28 -0
  104. package/dist/theme/custom-themes.d.ts.map +1 -0
  105. package/dist/theme/custom-themes.js +218 -0
  106. package/dist/theme/custom-themes.js.map +1 -0
  107. package/dist/theme/dark-themes.d.ts +9 -1
  108. package/dist/theme/dark-themes.d.ts.map +1 -1
  109. package/dist/theme/dark-themes.js +74 -2
  110. package/dist/theme/dark-themes.js.map +1 -1
  111. package/dist/theme/logo.d.ts +6 -3
  112. package/dist/theme/logo.d.ts.map +1 -1
  113. package/dist/theme/logo.js +17 -3
  114. package/dist/theme/logo.js.map +1 -1
  115. package/dist/theme/theme-service.d.ts +14 -3
  116. package/dist/theme/theme-service.d.ts.map +1 -1
  117. package/dist/theme/theme-service.js +64 -10
  118. package/dist/theme/theme-service.js.map +1 -1
  119. package/dist/utils/app-http.d.ts +29 -1
  120. package/dist/utils/app-http.d.ts.map +1 -1
  121. package/dist/utils/app-http.js +113 -11
  122. package/dist/utils/app-http.js.map +1 -1
  123. package/dist/utils/content-util.d.ts +6 -0
  124. package/dist/utils/content-util.d.ts.map +1 -0
  125. package/dist/utils/content-util.js +45 -0
  126. package/dist/utils/content-util.js.map +1 -0
  127. package/dist/utils/error-util.d.ts +3 -0
  128. package/dist/utils/error-util.d.ts.map +1 -0
  129. package/dist/utils/error-util.js +58 -0
  130. package/dist/utils/error-util.js.map +1 -0
  131. package/dist/utils/language-util.d.ts +3 -3
  132. package/dist/utils/language-util.d.ts.map +1 -1
  133. package/dist/utils/language-util.js +7 -7
  134. package/dist/utils/language-util.js.map +1 -1
  135. package/dist/utils/menu-util.js +1 -1
  136. package/dist/utils/menu-util.js.map +1 -1
  137. package/dist/utils/signal-source.d.ts +4 -0
  138. package/dist/utils/signal-source.d.ts.map +1 -0
  139. package/dist/utils/signal-source.js +13 -0
  140. package/dist/utils/signal-source.js.map +1 -0
  141. package/dist/utils/storage-keys.d.ts +5 -0
  142. package/dist/utils/storage-keys.d.ts.map +1 -1
  143. package/dist/utils/storage-keys.js +5 -0
  144. package/dist/utils/storage-keys.js.map +1 -1
  145. package/package.json +3 -3
  146. package/src/components/app-brand.tsx +9 -5
  147. package/src/components/coming-soon.tsx +3 -2
  148. package/src/components/language-switcher.tsx +26 -7
  149. package/src/components/settings-menu.tsx +28 -2
  150. package/src/context/use-ui.ts +4 -3
  151. package/src/i18n/browser-language.ts +98 -0
  152. package/src/i18n/default-messages.ts +3 -0
  153. package/src/i18n/locale-groups.ts +87 -0
  154. package/src/i18n/locale-service.ts +99 -27
  155. package/src/i18n/locale-signal.ts +173 -0
  156. package/src/i18n/translator.ts +38 -12
  157. package/src/index.ts +71 -3
  158. package/src/interfaces/app-types.ts +6 -0
  159. package/src/interfaces/ui-config.ts +168 -15
  160. package/src/interfaces/ui-context.ts +1 -1
  161. package/src/layouts/auth-layout.tsx +1 -1
  162. package/src/providers/provider-effects.ts +5 -2
  163. package/src/providers/register-config.ts +2 -0
  164. package/src/providers/shared-web-ui-provider.tsx +26 -43
  165. package/src/query/query-param.ts +6 -2
  166. package/src/state/api-loader.ts +205 -0
  167. package/src/state/auth-service.ts +58 -3
  168. package/src/state/branch-service.ts +3 -3
  169. package/src/state/company-service.ts +107 -0
  170. package/src/state/language-service.ts +12 -7
  171. package/src/state/layout-choice-service.ts +40 -0
  172. package/src/state/menu-service.ts +2 -2
  173. package/src/state/preference-sync.ts +11 -3
  174. package/src/state/signals.ts +36 -4
  175. package/src/theme/custom-themes.ts +236 -0
  176. package/src/theme/dark-themes.ts +80 -3
  177. package/src/theme/logo.ts +19 -4
  178. package/src/theme/org-themes.json +70 -0
  179. package/src/theme/theme-service.ts +70 -10
  180. package/src/utils/app-http.ts +125 -11
  181. package/src/utils/content-util.ts +49 -0
  182. package/src/utils/error-util.ts +64 -0
  183. package/src/utils/language-util.ts +7 -7
  184. package/src/utils/menu-util.ts +1 -1
  185. package/src/utils/signal-source.ts +15 -0
  186. package/src/utils/storage-keys.ts +6 -0
@@ -0,0 +1,218 @@
1
+ // custom-themes.ts
2
+ // Custom DaisyUI themes from plain data (a JSON file or an API reply) — no CSS file, no rebuild.
3
+ // The themes are an object keyed by theme name ("name" inside is optional, the key is the name):
4
+ //
5
+ // { "org-light": { "isDark": false, "name": "org-light", "variables": { "color-primary": "oklch(55.8% 0.154 249.1)", ... } },
6
+ // "org-dark": { "isDark": true, "name": "org-dark", "variables": { ... } } }
7
+ //
8
+ // A plain list [{ "name": "org-light", ... }] is accepted too.
9
+ //
10
+ // setCustomThemes(list) writes ONE <style> element:
11
+ // [data-theme="org-light"] { color-scheme: light; --color-primary: oklch(55.8% 0.154 249.1); ... }
12
+ // DaisyUI components read these CSS variables, so a custom theme works like a built-in one, and the theme switcher
13
+ // lists it first. Pass them in config.customThemes, load them lazily with config.loadThemes (like loadLocale),
14
+ // or set them any time later with setCustomThemes(json).
15
+ // The built-in DaisyUI themes still come from your CSS: @plugin "daisyui" { themes: all; }.
16
+ import { customThemesSignal, uiConfigSignal } from "../state/signals.js";
17
+ import { isSignalSource } from "../utils/signal-source.js";
18
+ import { applySavedThemeWhenKnown, leaveUnknownTheme } from "./theme-service.js";
19
+ const STYLE_ELEMENT_ID = "shared-lib-web-custom-themes";
20
+ /** Theme names: lowercase letters, digits and "-" (they go into a CSS selector). */
21
+ const SAFE_NAME = /^[a-z0-9][a-z0-9-]*$/;
22
+ /** Variable names, with or without the leading "--". */
23
+ const SAFE_VARIABLE = /^(--)?[a-z0-9][a-z0-9-]*$/i;
24
+ /** Characters that could end the CSS rule (values come from JSON, maybe from a server). */
25
+ const UNSAFE_VALUE = /[;{}<>"\\]/;
26
+ const VARIABLE_PREFIX = "--";
27
+ /** "color-primary" -> "--color-primary" ("--color-primary" stays). */
28
+ function toVariableName(key) {
29
+ const hasPrefix = key.startsWith(VARIABLE_PREFIX);
30
+ return hasPrefix ? key : `${VARIABLE_PREFIX}${key}`;
31
+ }
32
+ /** The CSS lines of the variables; unsafe names or values are skipped. */
33
+ function buildVariableLines(variables) {
34
+ const lines = [];
35
+ const entries = Object.entries(variables);
36
+ for (const [key, value] of entries) {
37
+ const valueText = String(value);
38
+ const isSafeKey = SAFE_VARIABLE.test(key);
39
+ const isUnsafeValue = UNSAFE_VALUE.test(valueText);
40
+ if (!isSafeKey || isUnsafeValue) {
41
+ continue;
42
+ }
43
+ const variableName = toVariableName(key);
44
+ lines.push(` ${variableName}: ${valueText};`);
45
+ }
46
+ return lines;
47
+ }
48
+ /** true when the theme has a usable name. */
49
+ export function isValidCustomTheme(theme) {
50
+ const hasName = typeof theme?.name === "string";
51
+ return hasName && SAFE_NAME.test(theme.name);
52
+ }
53
+ /** The CSS rule of one custom theme: [data-theme="name"] { color-scheme: ...; --color-primary: ...; } */
54
+ export function buildCustomThemeCss(theme) {
55
+ const isValid = isValidCustomTheme(theme);
56
+ if (!isValid) {
57
+ return "";
58
+ }
59
+ const colorScheme = theme.isDark ? "dark" : "light";
60
+ const variableLines = buildVariableLines(theme.variables ?? {});
61
+ const bodyLines = [` color-scheme: ${colorScheme};`, ...variableLines];
62
+ const bodyText = bodyLines.join("\n");
63
+ return `[data-theme="${theme.name}"] {\n${bodyText}\n}`;
64
+ }
65
+ /** Writes the CSS into the one <style> element of the custom themes (created on first use). */
66
+ function writeThemeStyle(cssText) {
67
+ if (typeof document === "undefined") {
68
+ return;
69
+ }
70
+ let styleElement = document.getElementById(STYLE_ELEMENT_ID);
71
+ if (!styleElement) {
72
+ styleElement = document.createElement("style");
73
+ styleElement.id = STYLE_ELEMENT_ID;
74
+ document.head.append(styleElement);
75
+ }
76
+ styleElement.textContent = cssText;
77
+ }
78
+ /** true for a plain object (not null, not a list). */
79
+ function isPlainObject(value) {
80
+ const isObject = typeof value === "object" && value !== null;
81
+ return isObject && !Array.isArray(value);
82
+ }
83
+ /** The themes of an object keyed by theme name; an entry without "name" gets its key as name. */
84
+ function readThemeMapEntries(themeMap) {
85
+ const themeList = [];
86
+ const entries = Object.entries(themeMap);
87
+ for (const [key, entry] of entries) {
88
+ if (!isPlainObject(entry)) {
89
+ continue;
90
+ }
91
+ const hasName = typeof entry.name === "string";
92
+ const name = hasName ? entry.name : key;
93
+ themeList.push({ ...entry, name });
94
+ }
95
+ return themeList;
96
+ }
97
+ /**
98
+ * The custom themes as a list: an object keyed by theme name ({ "org-light": {...}, "org-dark": {...} }) is turned
99
+ * into a list (in key order); a list stays as it is; anything else is an empty list.
100
+ */
101
+ export function toCustomThemeList(themes) {
102
+ if (Array.isArray(themes)) {
103
+ return themes;
104
+ }
105
+ if (isPlainObject(themes)) {
106
+ return readThemeMapEntries(themes);
107
+ }
108
+ return [];
109
+ }
110
+ /**
111
+ * Sets the custom themes (replaces the earlier ones): writes their CSS, adds them to the theme switcher and,
112
+ * when the saved theme is one of them, switches to it. Accepts the parsed JSON as it is — the object keyed by theme
113
+ * name, or a list; invalid entries are skipped.
114
+ */
115
+ export function setCustomThemes(themes) {
116
+ const validThemes = [];
117
+ const givenThemes = toCustomThemeList(themes);
118
+ for (const theme of givenThemes) {
119
+ const isValid = isValidCustomTheme(theme);
120
+ if (isValid) {
121
+ validThemes.push(theme);
122
+ }
123
+ }
124
+ const cssParts = validThemes.map(buildCustomThemeCss);
125
+ const cssText = cssParts.join("\n\n");
126
+ writeThemeStyle(cssText);
127
+ customThemesSignal.value = validThemes;
128
+ applySavedThemeWhenKnown();
129
+ }
130
+ /** true when the value is a JSON module ({ default: themes }), not a theme map with a theme called "default". */
131
+ function isThemesJsonModule(themesModule) {
132
+ if (!isPlainObject(themesModule)) {
133
+ return false;
134
+ }
135
+ const defaultValue = themesModule.default;
136
+ if (Array.isArray(defaultValue)) {
137
+ return true;
138
+ }
139
+ return isPlainObject(defaultValue) && !("variables" in defaultValue);
140
+ }
141
+ /** The themes inside a themes module as a list: the object keyed by name or the list, or the default export of a JSON module. */
142
+ export function unwrapThemesModule(themesModule) {
143
+ const isJsonModule = isThemesJsonModule(themesModule);
144
+ if (isJsonModule) {
145
+ return toCustomThemeList(themesModule.default);
146
+ }
147
+ return toCustomThemeList(themesModule);
148
+ }
149
+ /** baseThemes + extraThemes; a theme with the same name in extraThemes replaces the one in baseThemes. */
150
+ export function mergeCustomThemes(baseThemes, extraThemes) {
151
+ const mergedThemes = [];
152
+ const extraNames = [];
153
+ for (const extraTheme of extraThemes) {
154
+ extraNames.push(extraTheme?.name);
155
+ }
156
+ for (const baseTheme of baseThemes) {
157
+ const isReplaced = extraNames.includes(baseTheme.name);
158
+ if (!isReplaced) {
159
+ mergedThemes.push(baseTheme);
160
+ }
161
+ }
162
+ mergedThemes.push(...extraThemes);
163
+ return mergedThemes;
164
+ }
165
+ /** Configs whose loadThemes already ran (StrictMode mounts twice). */
166
+ const loadedConfigs = new WeakSet();
167
+ /**
168
+ * Runs config.loadThemes once per config and adds the result to config.customThemes.
169
+ * When it fails, or the saved theme is not in the result, the default theme is used.
170
+ */
171
+ export async function loadConfigThemes(config) {
172
+ const loadThemes = config.loadThemes;
173
+ const isLoaded = loadedConfigs.has(config);
174
+ if (typeof loadThemes !== "function" || isLoaded) {
175
+ return;
176
+ }
177
+ loadedConfigs.add(config);
178
+ try {
179
+ const themesModule = await loadThemes();
180
+ const loadedThemes = unwrapThemesModule(themesModule);
181
+ const isConfigStillActive = uiConfigSignal.peek() === config;
182
+ if (isConfigStillActive) {
183
+ const baseThemes = toCustomThemeList(config.customThemes);
184
+ const mergedThemes = mergeCustomThemes(baseThemes, loadedThemes);
185
+ setCustomThemes(mergedThemes);
186
+ }
187
+ }
188
+ catch (error) {
189
+ console.error("shared-lib-web: could not load the custom themes (config.loadThemes).", error);
190
+ }
191
+ leaveUnknownTheme();
192
+ }
193
+ /** One value of a loadThemes signal: null = not here yet; a list (or JSON module) replaces the loaded themes. */
194
+ function applyThemesFromSignal(config, themesModule) {
195
+ const isConfigActive = uiConfigSignal.peek() === config;
196
+ if (!themesModule || !isConfigActive) {
197
+ return;
198
+ }
199
+ const loadedThemes = unwrapThemesModule(themesModule);
200
+ const baseThemes = toCustomThemeList(config.customThemes);
201
+ const mergedThemes = mergeCustomThemes(baseThemes, loadedThemes);
202
+ setCustomThemes(mergedThemes);
203
+ leaveUnknownTheme();
204
+ }
205
+ /** Follows config.loadThemes when it is a signal. Returns the stop function (nothing to stop otherwise). */
206
+ export function followConfigThemes(config) {
207
+ const themesSource = config.loadThemes;
208
+ if (!isSignalSource(themesSource)) {
209
+ return stopNothing;
210
+ }
211
+ const applyThemes = applyThemesFromSignal.bind(null, config);
212
+ return themesSource.subscribe(applyThemes);
213
+ }
214
+ /** Nothing to clean up. */
215
+ function stopNothing() {
216
+ return;
217
+ }
218
+ //# sourceMappingURL=custom-themes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-themes.js","sourceRoot":"","sources":["../../src/theme/custom-themes.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB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uC,CAAC,CAAC;AACzE,CAAC;AAED,2BAA2B;AAC3B,SAAS,WAAW;IAClB,OAAO;AACT,CAAC"}
@@ -1,2 +1,10 @@
1
- export declare const DEFAULT_DARK_THEMES: string[];
1
+ import type { CustomTheme, Theme } from "../interfaces/ui-config.js";
2
+ /** All 35 DaisyUI 5 themes (enable them in CSS with @plugin "daisyui" { themes: all; }). */
3
+ export declare const DAISYUI_THEMES: Theme[];
4
+ /** The dark DaisyUI 5 themes. */
5
+ export declare const DEFAULT_DARK_THEMES: Theme[];
6
+ /** The dark theme names: the dark custom themes + (darkThemes, else the DaisyUI dark themes). */
7
+ export declare function buildDarkThemeNames(darkThemes: Theme[] | undefined, customThemes: CustomTheme[]): Theme[];
8
+ /** The theme names of the switcher: the custom themes first, then (themes, else all DaisyUI themes). */
9
+ export declare function buildThemeNames(themes: Theme[] | undefined, customThemes: CustomTheme[]): Theme[];
2
10
  //# sourceMappingURL=dark-themes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dark-themes.d.ts","sourceRoot":"","sources":["../../src/theme/dark-themes.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,UAe/B,CAAC"}
1
+ {"version":3,"file":"dark-themes.d.ts","sourceRoot":"","sources":["../../src/theme/dark-themes.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAErE,4FAA4F;AAC5F,eAAO,MAAM,cAAc,EAAE,KAAK,EAoCjC,CAAC;AAEF,iCAAiC;AACjC,eAAO,MAAM,mBAAmB,EAAE,KAAK,EAetC,CAAC;AAEF,iGAAiG;AACjG,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,CAezG;AAED,wGAAwG;AACxG,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,CAajG"}
@@ -1,6 +1,46 @@
1
1
  // dark-themes.ts
2
- // DaisyUI 5 themes with "color-scheme: dark". Used for dark logos and the markdown editor colours.
3
- // An app can replace this list with config.darkThemes.
2
+ // The DaisyUI 5 theme names, and which of them are dark ("color-scheme: dark": dark logos, dark markdown editor).
3
+ // config.themes defaults to DAISYUI_THEMES; config.darkThemes replaces DEFAULT_DARK_THEMES.
4
+ // Custom themes (config.customThemes / setCustomThemes) are added to both lists by their own isDark flag.
5
+ /** All 35 DaisyUI 5 themes (enable them in CSS with @plugin "daisyui" { themes: all; }). */
6
+ export const DAISYUI_THEMES = [
7
+ "light",
8
+ "dark",
9
+ "cupcake",
10
+ "bumblebee",
11
+ "emerald",
12
+ "corporate",
13
+ "synthwave",
14
+ "retro",
15
+ "cyberpunk",
16
+ "valentine",
17
+ "halloween",
18
+ "garden",
19
+ "forest",
20
+ "aqua",
21
+ "lofi",
22
+ "pastel",
23
+ "fantasy",
24
+ "wireframe",
25
+ "black",
26
+ "luxury",
27
+ "dracula",
28
+ "cmyk",
29
+ "autumn",
30
+ "business",
31
+ "acid",
32
+ "lemonade",
33
+ "night",
34
+ "coffee",
35
+ "winter",
36
+ "dim",
37
+ "nord",
38
+ "sunset",
39
+ "caramellatte",
40
+ "abyss",
41
+ "silk",
42
+ ];
43
+ /** The dark DaisyUI 5 themes. */
4
44
  export const DEFAULT_DARK_THEMES = [
5
45
  "dark",
6
46
  "aqua",
@@ -17,4 +57,36 @@ export const DEFAULT_DARK_THEMES = [
17
57
  "sunset",
18
58
  "abyss",
19
59
  ];
60
+ /** The dark theme names: the dark custom themes + (darkThemes, else the DaisyUI dark themes). */
61
+ export function buildDarkThemeNames(darkThemes, customThemes) {
62
+ const names = [];
63
+ for (const customTheme of customThemes) {
64
+ if (customTheme.isDark) {
65
+ names.push(customTheme.name);
66
+ }
67
+ }
68
+ const baseNames = darkThemes ?? DEFAULT_DARK_THEMES;
69
+ for (const name of baseNames) {
70
+ const isAdded = names.includes(name);
71
+ if (!isAdded) {
72
+ names.push(name);
73
+ }
74
+ }
75
+ return names;
76
+ }
77
+ /** The theme names of the switcher: the custom themes first, then (themes, else all DaisyUI themes). */
78
+ export function buildThemeNames(themes, customThemes) {
79
+ const names = [];
80
+ for (const customTheme of customThemes) {
81
+ names.push(customTheme.name);
82
+ }
83
+ const baseNames = themes ?? DAISYUI_THEMES;
84
+ for (const name of baseNames) {
85
+ const isAdded = names.includes(name);
86
+ if (!isAdded) {
87
+ names.push(name);
88
+ }
89
+ }
90
+ return names;
91
+ }
20
92
  //# sourceMappingURL=dark-themes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dark-themes.js","sourceRoot":"","sources":["../../src/theme/dark-themes.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,mGAAmG;AACnG,uDAAuD;AAEvD,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM;IACN,MAAM;IACN,WAAW;IACX,WAAW;IACX,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,SAAS;IACT,UAAU;IACV,OAAO;IACP,QAAQ;IACR,KAAK;IACL,QAAQ;IACR,OAAO;CACR,CAAC"}
1
+ {"version":3,"file":"dark-themes.js","sourceRoot":"","sources":["../../src/theme/dark-themes.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,kHAAkH;AAClH,4FAA4F;AAC5F,0GAA0G;AAI1G,4FAA4F;AAC5F,MAAM,CAAC,MAAM,cAAc,GAAY;IACrC,OAAO;IACP,MAAM;IACN,SAAS;IACT,WAAW;IACX,SAAS;IACT,WAAW;IACX,WAAW;IACX,OAAO;IACP,WAAW;IACX,WAAW;IACX,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,WAAW;IACX,OAAO;IACP,QAAQ;IACR,SAAS;IACT,MAAM;IACN,QAAQ;IACR,UAAU;IACV,MAAM;IACN,UAAU;IACV,OAAO;IAC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,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,4 +1,7 @@
1
- import type { UiConfig } from "../interfaces/ui-config.js";
2
- /** Returns logoDarkUrl on dark themes (when set), else logoUrl. */
3
- export declare function readLogoUrl(config: UiConfig, isDarkTheme: boolean): string | undefined;
1
+ import type { CompanyDetails, UiConfig } from "../interfaces/ui-config.js";
2
+ /**
3
+ * The logo URL. Dark themes: company logoDarkUrl, company logoUrl, config.logoDarkUrl, config.logoUrl.
4
+ * Light themes: company logoUrl, config.logoUrl.
5
+ */
6
+ export declare function readLogoUrl(config: UiConfig, isDarkTheme: boolean, details?: CompanyDetails | null): string | undefined;
4
7
  //# sourceMappingURL=logo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logo.d.ts","sourceRoot":"","sources":["../../src/theme/logo.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,mEAAmE;AACnE,wBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKtF"}
1
+ {"version":3,"file":"logo.d.ts","sourceRoot":"","sources":["../../src/theme/logo.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAU3E;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,GAAG,MAAM,GAAG,SAAS,CASvH"}
@@ -1,7 +1,21 @@
1
1
  // logo.ts
2
- // Picks the logo for the current theme.
3
- /** Returns logoDarkUrl on dark themes (when set), else logoUrl. */
4
- export function readLogoUrl(config, isDarkTheme) {
2
+ // Picks the logo for the current theme. Company details (loadCompanyDetails / setCompanyDetails) win over the config.
3
+ /** The company logo for the theme: logoDarkUrl on dark themes (when set), else logoUrl. */
4
+ function readCompanyLogoUrl(details, isDarkTheme) {
5
+ if (isDarkTheme && details?.logoDarkUrl) {
6
+ return details.logoDarkUrl;
7
+ }
8
+ return details?.logoUrl;
9
+ }
10
+ /**
11
+ * The logo URL. Dark themes: company logoDarkUrl, company logoUrl, config.logoDarkUrl, config.logoUrl.
12
+ * Light themes: company logoUrl, config.logoUrl.
13
+ */
14
+ export function readLogoUrl(config, isDarkTheme, details) {
15
+ const companyLogoUrl = readCompanyLogoUrl(details, isDarkTheme);
16
+ if (companyLogoUrl) {
17
+ return companyLogoUrl;
18
+ }
5
19
  if (isDarkTheme && config.logoDarkUrl) {
6
20
  return config.logoDarkUrl;
7
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"logo.js","sourceRoot":"","sources":["../../src/theme/logo.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,wCAAwC;AAIxC,mEAAmE;AACnE,MAAM,UAAU,WAAW,CAAC,MAAgB,EAAE,WAAoB;IAChE,IAAI,WAAW,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACtC,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC;AACxB,CAAC"}
1
+ {"version":3,"file":"logo.js","sourceRoot":"","sources":["../../src/theme/logo.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,sHAAsH;AAItH,2FAA2F;AAC3F,SAAS,kBAAkB,CAAC,OAA0C,EAAE,WAAoB;IAC1F,IAAI,WAAW,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;QACxC,OAAO,OAAO,CAAC,WAAW,CAAC;IAC7B,CAAC;IACD,OAAO,OAAO,EAAE,OAAO,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,MAAgB,EAAE,WAAoB,EAAE,OAA+B;IACjG,MAAM,cAAc,GAAG,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAChE,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,IAAI,WAAW,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACtC,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC;AACxB,CAAC"}
@@ -1,8 +1,19 @@
1
1
  import type { Theme, UiConfig } from "../interfaces/ui-config.js";
2
- /** true when the theme is listed in the config. */
2
+ /** The theme names of the switcher: the custom themes first, then config.themes (default: all DaisyUI themes). */
3
+ export declare function readThemeNames(config: UiConfig): Theme[];
4
+ /** true when the theme is offered (config.themes or a custom theme). */
3
5
  export declare function isKnownTheme(config: UiConfig, theme: string): boolean;
4
- /** Picks the theme to start with: the saved one if it is in the config, else the default. */
6
+ /** The first-visit theme: config.defaultTheme, else "dark" or "light" from the browser preference. */
7
+ export declare function readDefaultTheme(config: UiConfig): Theme;
8
+ /**
9
+ * Picks the theme to start with: the saved one if it is in the config, else the default.
10
+ * With config.loadThemes the saved theme is kept while the custom themes load (no flash of the default theme).
11
+ */
5
12
  export declare function readInitialTheme(config: UiConfig): Theme;
13
+ /** After config.loadThemes: a theme that is still unknown (not in the loaded list) falls back to the default. */
14
+ export declare function leaveUnknownTheme(): void;
15
+ /** Custom themes can arrive after the start (fetched JSON): switch to the saved theme once it is known. */
16
+ export declare function applySavedThemeWhenKnown(): void;
6
17
  /** Switches the theme. Themes not listed in the config are ignored. */
7
18
  export declare function changeTheme(theme: Theme): void;
8
19
  /** Themes grouped for the switchers: light ones and dark ones (config order kept). */
@@ -10,7 +21,7 @@ export interface ThemeGroups {
10
21
  lightThemes: Theme[];
11
22
  darkThemes: Theme[];
12
23
  }
13
- /** The dark theme names: config.darkThemes, else the DaisyUI dark themes. */
24
+ /** The dark theme names: the dark custom themes + (config.darkThemes, else the DaisyUI dark themes). */
14
25
  export declare function readDarkThemeNames(): Theme[];
15
26
  /** true when the theme has a dark background. */
16
27
  export declare function isDarkThemeName(theme: Theme): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"theme-service.d.ts","sourceRoot":"","sources":["../../src/theme/theme-service.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAMlE,mDAAmD;AACnD,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAGrE;AAED,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,GAAG,KAAK,CASxD;AAED,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAU9C;AAED,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,KAAK,EAAE,CAAC;IACrB,UAAU,EAAE,KAAK,EAAE,CAAC;CACrB;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,IAAI,KAAK,EAAE,CAG5C;AAED,iDAAiD;AACjD,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAGrD;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,CAY9D;AAED,iEAAiE;AACjE,wBAAgB,eAAe,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,CAGtD"}
1
+ {"version":3,"file":"theme-service.d.ts","sourceRoot":"","sources":["../../src/theme/theme-service.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAMlE,kHAAkH;AAClH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,GAAG,KAAK,EAAE,CAGxD;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAGrE;AAaD,sGAAsG;AACtG,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,GAAG,KAAK,CAMxD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,GAAG,KAAK,CAUxD;AAED,iHAAiH;AACjH,wBAAgB,iBAAiB,IAAI,IAAI,CAUxC;AAED,2GAA2G;AAC3G,wBAAgB,wBAAwB,IAAI,IAAI,CAU/C;AAED,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAU9C;AAED,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,KAAK,EAAE,CAAC;IACrB,UAAU,EAAE,KAAK,EAAE,CAAC;CACrB;AAED,wGAAwG;AACxG,wBAAgB,kBAAkB,IAAI,KAAK,EAAE,CAI5C;AAED,iDAAiD;AACjD,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAGrD;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,CAY9D;AAED,iEAAiE;AACjE,wBAAgB,eAAe,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,CAGtD"}
@@ -3,26 +3,79 @@
3
3
  //
4
4
  // changeTheme("dark"); -> <html data-theme="dark">, saved to localStorage
5
5
  //
6
+ // First visit (nothing saved): config.defaultTheme, or without it the browser preference
7
+ // (prefers-color-scheme: dark -> "dark", otherwise "light").
8
+ //
6
9
  // The <html> attribute is written by state/document-sync.ts.
7
- import { themeSignal, uiConfigSignal } from "../state/signals.js";
10
+ import { customThemesSignal, themeSignal, uiConfigSignal } from "../state/signals.js";
8
11
  import { AppStorage } from "../utils/app-storage.js";
9
12
  import { THEME } from "../utils/storage-keys.js";
10
- import { DEFAULT_DARK_THEMES } from "./dark-themes.js";
11
- /** true when the theme is listed in the config. */
13
+ import { buildDarkThemeNames, buildThemeNames } from "./dark-themes.js";
14
+ /** The theme names of the switcher: the custom themes first, then config.themes (default: all DaisyUI themes). */
15
+ export function readThemeNames(config) {
16
+ const customThemes = customThemesSignal.value;
17
+ return buildThemeNames(config.themes, customThemes);
18
+ }
19
+ /** true when the theme is offered (config.themes or a custom theme). */
12
20
  export function isKnownTheme(config, theme) {
13
- const isListed = config.themes.includes(theme);
14
- return isListed;
21
+ const themeNames = readThemeNames(config);
22
+ return themeNames.includes(theme);
23
+ }
24
+ const DARK_SCHEME_QUERY = "(prefers-color-scheme: dark)";
25
+ /** true when the browser / OS asks for a dark colour scheme. */
26
+ function isBrowserDarkPreferred() {
27
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
28
+ return false;
29
+ }
30
+ const darkQuery = window.matchMedia(DARK_SCHEME_QUERY);
31
+ return darkQuery.matches;
15
32
  }
16
- /** Picks the theme to start with: the saved one if it is in the config, else the default. */
33
+ /** The first-visit theme: config.defaultTheme, else "dark" or "light" from the browser preference. */
34
+ export function readDefaultTheme(config) {
35
+ if (config.defaultTheme) {
36
+ return config.defaultTheme;
37
+ }
38
+ const isDarkPreferred = isBrowserDarkPreferred();
39
+ return isDarkPreferred ? "dark" : "light";
40
+ }
41
+ /**
42
+ * Picks the theme to start with: the saved one if it is in the config, else the default.
43
+ * With config.loadThemes the saved theme is kept while the custom themes load (no flash of the default theme).
44
+ */
17
45
  export function readInitialTheme(config) {
18
46
  const storedTheme = AppStorage.getText(THEME);
19
47
  if (storedTheme) {
20
48
  const isStoredThemeKnown = isKnownTheme(config, storedTheme);
21
- if (isStoredThemeKnown) {
49
+ const isThemeLoading = Boolean(config.loadThemes);
50
+ if (isStoredThemeKnown || isThemeLoading) {
22
51
  return storedTheme;
23
52
  }
24
53
  }
25
- return config.defaultTheme;
54
+ return readDefaultTheme(config);
55
+ }
56
+ /** After config.loadThemes: a theme that is still unknown (not in the loaded list) falls back to the default. */
57
+ export function leaveUnknownTheme() {
58
+ const config = uiConfigSignal.peek();
59
+ if (!config) {
60
+ return;
61
+ }
62
+ const currentTheme = themeSignal.peek();
63
+ const isCurrentThemeKnown = isKnownTheme(config, currentTheme);
64
+ if (!isCurrentThemeKnown) {
65
+ themeSignal.value = readDefaultTheme(config);
66
+ }
67
+ }
68
+ /** Custom themes can arrive after the start (fetched JSON): switch to the saved theme once it is known. */
69
+ export function applySavedThemeWhenKnown() {
70
+ const config = uiConfigSignal.peek();
71
+ const storedTheme = AppStorage.getText(THEME);
72
+ if (!config || !storedTheme || storedTheme === themeSignal.peek()) {
73
+ return;
74
+ }
75
+ const isStoredThemeKnown = isKnownTheme(config, storedTheme);
76
+ if (isStoredThemeKnown) {
77
+ themeSignal.value = storedTheme;
78
+ }
26
79
  }
27
80
  /** Switches the theme. Themes not listed in the config are ignored. */
28
81
  export function changeTheme(theme) {
@@ -36,10 +89,11 @@ export function changeTheme(theme) {
36
89
  themeSignal.value = theme;
37
90
  AppStorage.setData(THEME, theme);
38
91
  }
39
- /** The dark theme names: config.darkThemes, else the DaisyUI dark themes. */
92
+ /** The dark theme names: the dark custom themes + (config.darkThemes, else the DaisyUI dark themes). */
40
93
  export function readDarkThemeNames() {
41
94
  const config = uiConfigSignal.value;
42
- return config?.darkThemes ?? DEFAULT_DARK_THEMES;
95
+ const customThemes = customThemesSignal.value;
96
+ return buildDarkThemeNames(config?.darkThemes, customThemes);
43
97
  }
44
98
  /** true when the theme has a dark background. */
45
99
  export function isDarkThemeName(theme) {
@@ -1 +1 @@
1
- {"version":3,"file":"theme-service.js","sourceRoot":"","sources":["../../src/theme/theme-service.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,+CAA+C;AAC/C,EAAE;AACF,6EAA6E;AAC7E,EAAE;AACF,6DAA6D;AAG7D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE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olean | null | undef
3
3
  export type HttpHeaders = Record<string, string>;
4
4
  /** window.env name (without prefix) of the API base URL. */
5
5
  export declare const API_BASE_URL_ENV = "API_BASE_URL";
6
- /** JWT from AppStorage (config.http.tokenKey, default TOKEN, sessionStorage). "" when missing. */
6
+ /** Cache key of a request: the full URL + the params sorted by name. */
7
+ export declare function buildSharedGetKey(fullUrl: string, params: HttpParams): string;
8
+ /** Empties the shared request cache (for example after the texts or themes changed on the server, or in tests). */
9
+ export declare function clearSharedGetCache(): void;
7
10
  export declare function readJwtToken(): string;
8
11
  /** "/api" -> "https://this-site/api". Absolute URLs stay as they are. A trailing "/" is removed. */
9
12
  export declare function toAbsoluteUrl(url: string): string;
13
+ /** true for "http://..." and "https://..." (any case). */
14
+ export declare function isHttpUrl(url: string): boolean;
15
+ /** Joins a base URL and a path with exactly one "/" between them. */
16
+ export declare function joinUrl(baseUrl: string, path: string): string;
10
17
  export declare class AppHttp {
11
18
  /**
12
19
  * API base URL: window.env REACT_APP_<APPNAMEKEY>_API_BASE_URL first, then config.http.baseUrl.
@@ -14,6 +21,11 @@ export declare class AppHttp {
14
21
  * so AppHttp.Get("/profile/search") works with a path only.
15
22
  */
16
23
  static BaseUrl(): string;
24
+ /**
25
+ * The URL a request goes to: a URL starting with http:// or https:// stays as it is,
26
+ * anything else is appended to BaseUrl() ("/profile/search" or "profile/search" -> "<baseUrl>/profile/search").
27
+ */
28
+ static FullUrl(url: string): string;
17
29
  /** Adds (or with "" removes) a header sent with every request, for example the selected branch. */
18
30
  static setHeader(headerName: string, value: string): void;
19
31
  /** JSON headers: content type, bearer token, session id, branch, config and runtime headers. */
@@ -22,6 +34,13 @@ export declare class AppHttp {
22
34
  static RawHeaders(): HttpHeaders;
23
35
  /** GET with query params. */
24
36
  static Get(url: string, params?: HttpParams, customHeaders?: HttpHeaders): Promise<unknown>;
37
+ /**
38
+ * GET once per page, shared by every copy of the library (shell + microfrontends): the same URL + params while a
39
+ * request is running or after it answered gives the same promise — no second call. For data that is the same for
40
+ * everyone on the page (languages, themes, texts, company details), not for user data. A failed request is not kept.
41
+ * const reply = await AppHttp.GetShared(`${MsUrl.sor}/load/LANG`, { active: true });
42
+ */
43
+ static GetShared(url: string, params?: HttpParams): Promise<unknown>;
25
44
  /** POST a JSON body. */
26
45
  static Post(url: string, body: unknown, customHeaders?: HttpHeaders): Promise<unknown>;
27
46
  /** PUT a JSON body to url/id. */
@@ -36,6 +55,15 @@ export declare class AppHttp {
36
55
  static CloudUpload(uploadUrl: string, file: File): Promise<Response>;
37
56
  /** Same as CloudUpload (the name the apps used). */
38
57
  static uploadFile(uploadUrl: string, file: File): Promise<Response>;
58
+ /**
59
+ * GET that returns the raw body as a Blob (images, video, audio, any binary file).
60
+ * The URL rule of every method applies (a path gets the base URL), and the same headers are sent (token,
61
+ * x-session-id, x-branch-id, http.headers, setHeader values; no Content-Type). No progress bar: pages often load
62
+ * many media files at once.
63
+ * const blob = await AppHttp.Media(`${MsUrl.utils}/files/${id}`);
64
+ * const objectUrl = URL.createObjectURL(blob); // <img src={objectUrl}>; URL.revokeObjectURL(objectUrl) later
65
+ */
66
+ static Media(url: string, params?: HttpParams): Promise<Blob>;
39
67
  /** Downloads a file and saves it in the browser. */
40
68
  static DownloadFile(url: string, params?: HttpParams, fileName?: string): Promise<void>;
41
69
  /** Shows the progress bar while the request runs. */
@@ -1 +1 @@
1
- {"version":3,"file":"app-http.d.ts","sourceRoot":"","sources":["../../src/utils/app-http.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAQ,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAS/C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AACtF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAKjD,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AA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