@tstdl/base 0.92.167 → 0.93.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 (317) hide show
  1. package/application/application.d.ts +12 -18
  2. package/application/application.js +48 -69
  3. package/application/index.d.ts +1 -5
  4. package/application/index.js +1 -5
  5. package/application/providers.d.ts +10 -0
  6. package/application/providers.js +54 -0
  7. package/audit/audit.model.d.ts +15 -0
  8. package/audit/audit.model.js +73 -0
  9. package/audit/auditor.d.ts +42 -0
  10. package/audit/auditor.js +111 -0
  11. package/audit/index.d.ts +3 -0
  12. package/audit/index.js +3 -0
  13. package/audit/types.d.ts +22 -0
  14. package/audit/types.js +19 -0
  15. package/authentication/client/authentication.service.d.ts +1 -3
  16. package/authentication/client/authentication.service.js +4 -5
  17. package/browser/browser-context-controller.d.ts +2 -4
  18. package/browser/browser-context-controller.js +5 -6
  19. package/browser/browser-controller.d.ts +2 -4
  20. package/browser/browser-controller.js +3 -4
  21. package/browser/browser.service.d.ts +1 -3
  22. package/browser/browser.service.js +1 -2
  23. package/browser/page-controller.d.ts +2 -4
  24. package/browser/page-controller.js +7 -8
  25. package/browser/utils.js +3 -3
  26. package/cancellation/token.d.ts +104 -41
  27. package/cancellation/token.js +125 -54
  28. package/core.d.ts +1 -13
  29. package/core.js +1 -46
  30. package/disposable/disposable.d.ts +0 -8
  31. package/disposable/disposable.js +1 -3
  32. package/disposable/index.d.ts +0 -6
  33. package/disposable/index.js +0 -6
  34. package/disposable/using.d.ts +0 -1
  35. package/disposable/using.js +2 -3
  36. package/distributed-loop/distributed-loop.js +2 -2
  37. package/errors/utils.js +4 -1
  38. package/examples/api/authentication.js +11 -5
  39. package/examples/api/basic-overview.js +17 -12
  40. package/examples/api/custom-authentication.js +13 -7
  41. package/examples/api/streaming.js +15 -12
  42. package/examples/browser/basic.js +6 -3
  43. package/examples/document-management/main.js +6 -3
  44. package/examples/http/client.js +7 -3
  45. package/examples/mail/basic.js +9 -7
  46. package/examples/pdf/basic.js +8 -6
  47. package/examples/template/basic.js +7 -5
  48. package/http/client/http-client-request.d.ts +1 -2
  49. package/http/client/http-client-request.js +1 -2
  50. package/http/server/http-server.d.ts +1 -3
  51. package/http/server/http-server.js +0 -1
  52. package/http/server/node/node-http-server.d.ts +1 -2
  53. package/http/server/node/node-http-server.js +1 -2
  54. package/import.js +1 -1
  55. package/injector/injector.d.ts +1 -1
  56. package/injector/types.d.ts +3 -4
  57. package/lock/lock.d.ts +40 -21
  58. package/lock/lock.js +74 -1
  59. package/lock/postgres/drizzle/0000_busy_tattoo.sql +7 -0
  60. package/lock/postgres/drizzle/meta/0000_snapshot.json +65 -0
  61. package/lock/postgres/drizzle/meta/_journal.json +13 -0
  62. package/lock/postgres/drizzle.config.js +11 -0
  63. package/lock/postgres/index.d.ts +2 -0
  64. package/lock/postgres/index.js +2 -0
  65. package/lock/postgres/lock.d.ts +14 -0
  66. package/lock/postgres/lock.js +127 -0
  67. package/lock/postgres/models/index.d.ts +2 -0
  68. package/lock/postgres/models/index.js +2 -0
  69. package/lock/postgres/models/lock.model.d.ts +7 -0
  70. package/{examples/orm/user.model.js → lock/postgres/models/lock.model.js} +22 -30
  71. package/lock/postgres/models/schemas.d.ts +3 -0
  72. package/lock/postgres/models/schemas.js +4 -0
  73. package/lock/postgres/module.d.ts +6 -0
  74. package/lock/postgres/module.js +26 -0
  75. package/lock/postgres/provider.d.ts +6 -0
  76. package/lock/postgres/provider.js +29 -0
  77. package/lock/provider.d.ts +12 -2
  78. package/lock/provider.js +24 -1
  79. package/lock/web/web-lock.d.ts +4 -3
  80. package/lock/web/web-lock.js +49 -42
  81. package/lock/web/web-lock.provider.d.ts +0 -3
  82. package/lock/web/web-lock.provider.js +5 -22
  83. package/logger/formatter.d.ts +13 -0
  84. package/logger/formatter.js +3 -0
  85. package/logger/formatters/index.d.ts +2 -0
  86. package/logger/formatters/index.js +2 -0
  87. package/logger/formatters/json.d.ts +5 -0
  88. package/logger/formatters/json.js +33 -0
  89. package/logger/formatters/pretty-print.d.ts +5 -0
  90. package/logger/formatters/pretty-print.js +55 -0
  91. package/logger/index.d.ts +5 -2
  92. package/logger/index.js +5 -2
  93. package/logger/level.d.ts +10 -8
  94. package/logger/level.js +9 -9
  95. package/logger/logger.d.ts +21 -30
  96. package/logger/logger.js +98 -26
  97. package/logger/manager.d.ts +20 -0
  98. package/logger/manager.js +86 -0
  99. package/logger/tokens.d.ts +1 -1
  100. package/logger/tokens.js +1 -1
  101. package/logger/transport.d.ts +14 -0
  102. package/logger/transport.js +16 -0
  103. package/logger/transports/console.d.ts +14 -0
  104. package/logger/transports/console.js +36 -0
  105. package/logger/transports/index.d.ts +1 -0
  106. package/logger/transports/index.js +1 -0
  107. package/mail/clients/nodemailer.mail-client.d.ts +0 -1
  108. package/mail/clients/nodemailer.mail-client.js +9 -7
  109. package/message-bus/local/local-message-bus.js +2 -2
  110. package/message-bus/message-bus-base.d.ts +2 -3
  111. package/message-bus/message-bus-base.js +5 -6
  112. package/message-bus/message-bus.d.ts +1 -2
  113. package/message-bus/message-bus.js +1 -2
  114. package/module/index.d.ts +0 -2
  115. package/module/index.js +0 -2
  116. package/module/module.d.ts +17 -18
  117. package/module/module.js +47 -12
  118. package/module/modules/function.module.d.ts +6 -6
  119. package/module/modules/function.module.js +25 -9
  120. package/module/modules/web-server.module.d.ts +2 -10
  121. package/module/modules/web-server.module.js +3 -11
  122. package/openid-connect/index.d.ts +0 -2
  123. package/openid-connect/index.js +0 -2
  124. package/openid-connect/oidc-state.model.d.ts +4 -5
  125. package/openid-connect/oidc-state.model.js +51 -1
  126. package/openid-connect/oidc.service-model.d.ts +1 -1
  127. package/openid-connect/oidc.service.d.ts +2 -6
  128. package/openid-connect/oidc.service.js +24 -37
  129. package/orm/decorators.d.ts +10 -1
  130. package/orm/decorators.js +8 -0
  131. package/orm/server/repository.d.ts +3 -1
  132. package/orm/server/repository.js +32 -3
  133. package/package.json +19 -29
  134. package/pdf/pdf.service.js +9 -9
  135. package/pool/pool.d.ts +1 -3
  136. package/pool/pool.js +3 -4
  137. package/queue/postgres/job.model.d.ts +1 -2
  138. package/queue/postgres/job.model.js +1 -2
  139. package/queue/postgres/module.js +1 -1
  140. package/threading/thread-pool.d.ts +1 -3
  141. package/threading/thread-pool.js +7 -8
  142. package/utils/format-error.d.ts +7 -0
  143. package/utils/format-error.js +59 -17
  144. package/utils/function/memoize.d.ts +22 -7
  145. package/utils/function/memoize.js +82 -23
  146. package/utils/index.d.ts +1 -0
  147. package/utils/index.js +1 -0
  148. package/utils/object/dereference.d.ts +51 -19
  149. package/utils/object/dereference.js +52 -43
  150. package/utils/timing.js +2 -2
  151. package/utils/try-chain.d.ts +22 -0
  152. package/utils/try-chain.js +46 -0
  153. package/database/entity-repository.d.ts +0 -50
  154. package/database/entity-repository.js +0 -3
  155. package/database/entity.d.ts +0 -7
  156. package/database/entity.js +0 -1
  157. package/database/id.d.ts +0 -1
  158. package/database/id.js +0 -9
  159. package/database/index.d.ts +0 -11
  160. package/database/index.js +0 -11
  161. package/database/module.d.ts +0 -8
  162. package/database/module.js +0 -11
  163. package/database/mongo/classes.d.ts +0 -21
  164. package/database/mongo/classes.js +0 -26
  165. package/database/mongo/index.d.ts +0 -15
  166. package/database/mongo/index.js +0 -15
  167. package/database/mongo/model/document.d.ts +0 -29
  168. package/database/mongo/model/document.js +0 -63
  169. package/database/mongo/model/index.d.ts +0 -1
  170. package/database/mongo/model/index.js +0 -1
  171. package/database/mongo/module.d.ts +0 -8
  172. package/database/mongo/module.js +0 -68
  173. package/database/mongo/mongo-base.repository.d.ts +0 -103
  174. package/database/mongo/mongo-base.repository.js +0 -263
  175. package/database/mongo/mongo-bulk.d.ts +0 -35
  176. package/database/mongo/mongo-bulk.js +0 -90
  177. package/database/mongo/mongo-entity-repository.d.ts +0 -98
  178. package/database/mongo/mongo-entity-repository.js +0 -278
  179. package/database/mongo/operations.d.ts +0 -10
  180. package/database/mongo/operations.js +0 -54
  181. package/database/mongo/query-converter.d.ts +0 -6
  182. package/database/mongo/query-converter.js +0 -83
  183. package/database/mongo/simple-entity-repository.d.ts +0 -7
  184. package/database/mongo/simple-entity-repository.js +0 -6
  185. package/database/mongo/types.d.ts +0 -50
  186. package/database/mongo/types.js +0 -3
  187. package/database/query.d.ts +0 -121
  188. package/database/query.js +0 -7
  189. package/database/utils.d.ts +0 -2
  190. package/database/utils.js +0 -3
  191. package/disposable/async-disposer.d.ts +0 -35
  192. package/disposable/async-disposer.js +0 -125
  193. package/examples/orm/drizzle.config.js +0 -6
  194. package/examples/orm/schemas.d.ts +0 -3
  195. package/examples/orm/schemas.js +0 -4
  196. package/examples/orm/test.d.ts +0 -1
  197. package/examples/orm/test.js +0 -11
  198. package/examples/orm/user.model.d.ts +0 -13
  199. package/key-value-store/mongo/index.d.ts +0 -6
  200. package/key-value-store/mongo/index.js +0 -6
  201. package/key-value-store/mongo/module.d.ts +0 -8
  202. package/key-value-store/mongo/module.js +0 -18
  203. package/key-value-store/mongo/mongo-key-value-store.provider.d.ts +0 -8
  204. package/key-value-store/mongo/mongo-key-value-store.provider.js +0 -26
  205. package/key-value-store/mongo/mongo-key-value.model.d.ts +0 -7
  206. package/key-value-store/mongo/mongo-key-value.model.js +0 -1
  207. package/key-value-store/mongo/mongo-key-value.repository.d.ts +0 -10
  208. package/key-value-store/mongo/mongo-key-value.repository.js +0 -31
  209. package/key-value-store/mongo/mongo-key-value.store.d.ts +0 -15
  210. package/key-value-store/mongo/mongo-key-value.store.js +0 -82
  211. package/key-value-store/mongo/tokens.d.ts +0 -3
  212. package/key-value-store/mongo/tokens.js +0 -2
  213. package/lock/mongo/index.d.ts +0 -5
  214. package/lock/mongo/index.js +0 -5
  215. package/lock/mongo/lock.d.ts +0 -14
  216. package/lock/mongo/lock.js +0 -125
  217. package/lock/mongo/model.d.ts +0 -6
  218. package/lock/mongo/model.js +0 -1
  219. package/lock/mongo/module.d.ts +0 -12
  220. package/lock/mongo/module.js +0 -20
  221. package/lock/mongo/mongo-lock-repository.d.ts +0 -14
  222. package/lock/mongo/mongo-lock-repository.js +0 -67
  223. package/lock/mongo/provider.d.ts +0 -8
  224. package/lock/mongo/provider.js +0 -36
  225. package/logger/console/index.d.ts +0 -1
  226. package/logger/console/index.js +0 -1
  227. package/logger/console/logger.d.ts +0 -11
  228. package/logger/console/logger.js +0 -64
  229. package/logger/noop/index.d.ts +0 -1
  230. package/logger/noop/index.js +0 -1
  231. package/logger/noop/logger.d.ts +0 -9
  232. package/logger/noop/logger.js +0 -21
  233. package/migration/index.d.ts +0 -9
  234. package/migration/index.js +0 -9
  235. package/migration/migration-state-repository.d.ts +0 -4
  236. package/migration/migration-state-repository.js +0 -3
  237. package/migration/migration-state.d.ts +0 -6
  238. package/migration/migration-state.js +0 -1
  239. package/migration/migrator.d.ts +0 -23
  240. package/migration/migrator.js +0 -76
  241. package/migration/mongo/index.d.ts +0 -2
  242. package/migration/mongo/index.js +0 -2
  243. package/migration/mongo/migration-state-repository.d.ts +0 -11
  244. package/migration/mongo/migration-state-repository.js +0 -32
  245. package/migration/mongo/module.d.ts +0 -12
  246. package/migration/mongo/module.js +0 -17
  247. package/module/module-base.d.ts +0 -18
  248. package/module/module-base.js +0 -40
  249. package/module/module-metric-reporter.d.ts +0 -29
  250. package/module/module-metric-reporter.js +0 -62
  251. package/openid-connect/mongo-oidc-state.repository.d.ts +0 -21
  252. package/openid-connect/mongo-oidc-state.repository.js +0 -52
  253. package/openid-connect/oidc-state.repository.d.ts +0 -4
  254. package/openid-connect/oidc-state.repository.js +0 -3
  255. package/process-shutdown.d.ts +0 -9
  256. package/process-shutdown.js +0 -65
  257. package/queue/mongo/index.d.ts +0 -4
  258. package/queue/mongo/index.js +0 -4
  259. package/queue/mongo/job.d.ts +0 -12
  260. package/queue/mongo/job.js +0 -1
  261. package/queue/mongo/mongo-job.repository.d.ts +0 -13
  262. package/queue/mongo/mongo-job.repository.js +0 -54
  263. package/queue/mongo/queue.d.ts +0 -38
  264. package/queue/mongo/queue.js +0 -266
  265. package/queue/mongo/queue.provider.d.ts +0 -18
  266. package/queue/mongo/queue.provider.js +0 -38
  267. package/search-index/elastic/config.d.ts +0 -8
  268. package/search-index/elastic/config.js +0 -26
  269. package/search-index/elastic/index.d.ts +0 -8
  270. package/search-index/elastic/index.js +0 -8
  271. package/search-index/elastic/keyword-rewriter.d.ts +0 -8
  272. package/search-index/elastic/keyword-rewriter.js +0 -18
  273. package/search-index/elastic/model/elastic-query.d.ts +0 -16
  274. package/search-index/elastic/model/elastic-query.js +0 -1
  275. package/search-index/elastic/model/index-mapping.d.ts +0 -26
  276. package/search-index/elastic/model/index-mapping.js +0 -4
  277. package/search-index/elastic/model/index.d.ts +0 -3
  278. package/search-index/elastic/model/index.js +0 -3
  279. package/search-index/elastic/model/sort.d.ts +0 -8
  280. package/search-index/elastic/model/sort.js +0 -1
  281. package/search-index/elastic/module.d.ts +0 -10
  282. package/search-index/elastic/module.js +0 -49
  283. package/search-index/elastic/query-builder/boolean-query-builder.d.ts +0 -11
  284. package/search-index/elastic/query-builder/boolean-query-builder.js +0 -52
  285. package/search-index/elastic/query-builder/index.d.ts +0 -1
  286. package/search-index/elastic/query-builder/index.js +0 -1
  287. package/search-index/elastic/query-converter.d.ts +0 -9
  288. package/search-index/elastic/query-converter.js +0 -183
  289. package/search-index/elastic/search-index.d.ts +0 -30
  290. package/search-index/elastic/search-index.js +0 -144
  291. package/search-index/elastic/sort-converter.d.ts +0 -4
  292. package/search-index/elastic/sort-converter.js +0 -14
  293. package/search-index/elastic/types.d.ts +0 -5
  294. package/search-index/elastic/types.js +0 -1
  295. package/search-index/error.d.ts +0 -10
  296. package/search-index/error.js +0 -14
  297. package/search-index/index.d.ts +0 -3
  298. package/search-index/index.js +0 -3
  299. package/search-index/memory/index.d.ts +0 -1
  300. package/search-index/memory/index.js +0 -1
  301. package/search-index/memory/memory-search-index.d.ts +0 -19
  302. package/search-index/memory/memory-search-index.js +0 -144
  303. package/search-index/search-index.d.ts +0 -46
  304. package/search-index/search-index.js +0 -31
  305. package/search-index/search-result.d.ts +0 -12
  306. package/search-index/search-result.js +0 -1
  307. package/theme/adapters/css-adapter.d.ts +0 -5
  308. package/theme/adapters/css-adapter.js +0 -29
  309. package/theme/adapters/index.d.ts +0 -2
  310. package/theme/adapters/index.js +0 -2
  311. package/theme/adapters/tailwind-adapter.d.ts +0 -18
  312. package/theme/adapters/tailwind-adapter.js +0 -32
  313. package/theme/index.d.ts +0 -1
  314. package/theme/index.js +0 -1
  315. package/theme/theme-service.d.ts +0 -43
  316. package/theme/theme-service.js +0 -128
  317. /package/{examples/orm → lock/postgres}/drizzle.config.d.ts +0 -0
@@ -1,31 +0,0 @@
1
- import { isDefined } from '../utils/type-guards.js';
2
- export class SearchIndex {
3
- /**
4
- * search all entities using an automatic cursor
5
- * @param query search query
6
- * @param options search options
7
- */
8
- async *searchCursor(query, options) {
9
- let cursor;
10
- do {
11
- const result = await this.search(cursor ?? query, options);
12
- cursor = result.cursor;
13
- yield* result.items;
14
- } while (isDefined(cursor));
15
- }
16
- /**
17
- * search all entities instead of just a chunk
18
- * @param query search query
19
- * @param options search option
20
- */
21
- async searchAll(query, options) {
22
- const batches = [];
23
- let cursor;
24
- do {
25
- const result = await this.search(cursor ?? query, options);
26
- cursor = result.cursor;
27
- batches.push(result.items);
28
- } while (isDefined(cursor));
29
- return [].concat(...batches);
30
- }
31
- }
@@ -1,12 +0,0 @@
1
- import type { Entity } from '../database/index.js';
2
- export type SearchResultItem<T extends Entity> = {
3
- entity: T;
4
- score: number;
5
- };
6
- export type SearchResult<T extends Entity> = {
7
- total?: number;
8
- totalIsLowerBound: boolean;
9
- milliseconds: number;
10
- items: SearchResultItem<T>[];
11
- cursor?: string;
12
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import type { ThemeService } from '../theme-service.js';
2
- export interface CssThemeAdapter {
3
- destroy(): void;
4
- }
5
- export declare function cssThemeAdapter(themeService: ThemeService<any>): CssThemeAdapter;
@@ -1,29 +0,0 @@
1
- import { objectEntries } from '../../utils/object/object.js';
2
- import { hyphenate } from '../../utils/string/hypenate.js';
3
- import { themeColorTones } from '../theme-service.js';
4
- export function cssThemeAdapter(themeService) {
5
- const styleSheet = new CSSStyleSheet();
6
- document.adoptedStyleSheets.push(styleSheet);
7
- const rootRule = createCssRule(styleSheet, ':root {}');
8
- const subscription = themeService.calculatedTheme$.subscribe((theme) => setVariables(rootRule, theme.palette));
9
- return {
10
- destroy() {
11
- subscription.unsubscribe();
12
- }
13
- };
14
- }
15
- function setVariables(cssRule, palette) {
16
- for (const [color, tones] of objectEntries(palette)) {
17
- const colorVariable = hyphenate(color);
18
- for (const tone of themeColorTones) {
19
- cssRule.style.setProperty(`--theme-${colorVariable}`, tones.base);
20
- cssRule.style.setProperty(`--theme-${colorVariable}-rgb`, tones.baseRgb);
21
- cssRule.style.setProperty(`--theme-${colorVariable}-${tone}`, tones[tone]);
22
- cssRule.style.setProperty(`--theme-${colorVariable}-${tone}-rgb`, tones[`${tone}Rgb`]);
23
- }
24
- }
25
- }
26
- function createCssRule(styleSheet, rule) {
27
- const index = styleSheet.insertRule(rule);
28
- return styleSheet.cssRules[index];
29
- }
@@ -1,2 +0,0 @@
1
- export * from './css-adapter.js';
2
- export * from './tailwind-adapter.js';
@@ -1,2 +0,0 @@
1
- export * from './css-adapter.js';
2
- export * from './tailwind-adapter.js';
@@ -1,18 +0,0 @@
1
- import type { Theme } from '../../theme/theme-service.js';
2
- export type TailwindPalette = {
3
- DEFAULT: string;
4
- 50: string;
5
- 100: string;
6
- 200: string;
7
- 300: string;
8
- 400: string;
9
- 500: string;
10
- 600: string;
11
- 700: string;
12
- 800: string;
13
- 900: string;
14
- 950: string;
15
- };
16
- export declare function generateTailwindColorsFromTheme(theme: Theme, tailwindNamePrefix?: string): Record<string, TailwindPalette>;
17
- export declare function generateTailwindColorsFromThemeColors(colors: readonly string[], tailwindNamePrefix?: string): Record<string, TailwindPalette>;
18
- export declare function generateTailwindPalette(color: string): TailwindPalette;
@@ -1,32 +0,0 @@
1
- import { fromEntries, objectKeys } from '../../utils/object/object.js';
2
- import { hyphenate } from '../../utils/string/hypenate.js';
3
- import { isDefined } from '../../utils/type-guards.js';
4
- export function generateTailwindColorsFromTheme(theme, tailwindNamePrefix) {
5
- const colors = objectKeys(theme.palette);
6
- return generateTailwindColorsFromThemeColors(colors, tailwindNamePrefix);
7
- }
8
- export function generateTailwindColorsFromThemeColors(colors, tailwindNamePrefix) {
9
- const prefix = isDefined(tailwindNamePrefix) ? `${tailwindNamePrefix}-` : '';
10
- const entries = colors
11
- .map(hyphenate)
12
- .map((color) => [`${prefix}${color}`, generateTailwindPalette(color)]);
13
- return fromEntries(entries);
14
- }
15
- export function generateTailwindPalette(color) {
16
- return {
17
- /* eslint-disable @typescript-eslint/naming-convention */
18
- DEFAULT: `rgb(var(--theme-${color}-rgb) / <alpha-value>)`,
19
- 50: `rgb(var(--theme-${color}-50-rgb) / <alpha-value>)`,
20
- 100: `rgb(var(--theme-${color}-100-rgb) / <alpha-value>)`,
21
- 200: `rgb(var(--theme-${color}-200-rgb) / <alpha-value>)`,
22
- 300: `rgb(var(--theme-${color}-300-rgb) / <alpha-value>)`,
23
- 400: `rgb(var(--theme-${color}-400-rgb) / <alpha-value>)`,
24
- 500: `rgb(var(--theme-${color}-500-rgb) / <alpha-value>)`,
25
- 600: `rgb(var(--theme-${color}-600-rgb) / <alpha-value>)`,
26
- 700: `rgb(var(--theme-${color}-700-rgb) / <alpha-value>)`,
27
- 800: `rgb(var(--theme-${color}-800-rgb) / <alpha-value>)`,
28
- 900: `rgb(var(--theme-${color}-900-rgb) / <alpha-value>)`,
29
- 950: `rgb(var(--theme-${color}-950-rgb) / <alpha-value>)`
30
- /* eslint-enable @typescript-eslint/naming-convention */
31
- };
32
- }
package/theme/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './theme-service.js';
package/theme/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './theme-service.js';
@@ -1,43 +0,0 @@
1
- import { type Observable } from 'rxjs';
2
- export type CalculatedPalette<Colors extends string = string> = {
3
- [Color in Colors]: ColorTonesWithRgb;
4
- };
5
- export type CalculatedTheme<Colors extends string = string> = {
6
- palette: CalculatedPalette<Colors>;
7
- };
8
- export type Theme<Colors extends string = string> = {
9
- palette: Palette<Colors>;
10
- };
11
- export type Palette<Colors extends string = string> = {
12
- [Color in Colors]: string | ColorTones;
13
- };
14
- export type ColorTones = {
15
- base: string;
16
- 50: string;
17
- 100: string;
18
- 200: string;
19
- 300: string;
20
- 400: string;
21
- 500: string;
22
- 600: string;
23
- 700: string;
24
- 800: string;
25
- 900: string;
26
- };
27
- export type ColorTonesWithRgb = ColorTones & {
28
- [Tone in keyof ColorTones as `${Tone}Rgb`]: string;
29
- };
30
- export declare const themeColorTones: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
31
- export declare const DEFAULT_THEME: import("../injector/token.js").InjectionToken<Theme<string>, never>;
32
- export declare class ThemeService<Colors extends string = string> {
33
- private readonly themeSubject;
34
- private readonly calculatedThemeSubject;
35
- private readonly defaultTheme;
36
- readonly colors: Colors[];
37
- readonly theme$: Observable<Theme<Colors>>;
38
- readonly calculatedTheme$: Observable<CalculatedTheme<Colors>>;
39
- get theme(): Theme<Colors>;
40
- get calculatedTheme(): CalculatedTheme<Colors>;
41
- constructor(defaultTheme: Theme<Colors>);
42
- setTheme(theme?: Theme<Colors> | undefined): void;
43
- }
@@ -1,128 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-magic-numbers */
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- import chroma from 'chroma-js';
15
- import { BehaviorSubject } from 'rxjs';
16
- import { Inject, Singleton } from '../injector/decorators.js';
17
- import { injectionToken } from '../injector/token.js';
18
- import { createArray } from '../utils/array/array.js';
19
- import { memoize } from '../utils/function/memoize.js';
20
- import { fromEntries, objectEntries, objectKeys } from '../utils/object/object.js';
21
- import { isString } from '../utils/type-guards.js';
22
- export const themeColorTones = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
23
- export const DEFAULT_THEME = injectionToken('default theme');
24
- const calculateTheme = memoize(_calculateTheme, { weak: true });
25
- const generateColorTones = memoize(_generateColorTones);
26
- let ThemeService = class ThemeService {
27
- themeSubject;
28
- calculatedThemeSubject;
29
- defaultTheme;
30
- colors;
31
- theme$;
32
- calculatedTheme$;
33
- get theme() {
34
- return this.themeSubject.value;
35
- }
36
- get calculatedTheme() {
37
- return this.calculatedThemeSubject.value;
38
- }
39
- constructor(defaultTheme) {
40
- this.defaultTheme = defaultTheme;
41
- this.colors = objectKeys(defaultTheme.palette);
42
- this.themeSubject = new BehaviorSubject(undefined);
43
- this.calculatedThemeSubject = new BehaviorSubject(undefined);
44
- this.theme$ = this.themeSubject.asObservable();
45
- this.calculatedTheme$ = this.calculatedThemeSubject.asObservable();
46
- this.setTheme(undefined);
47
- }
48
- setTheme(theme = this.defaultTheme) {
49
- const calculatedTheme = calculateTheme(theme);
50
- this.themeSubject.next(theme);
51
- this.calculatedThemeSubject.next(calculatedTheme);
52
- }
53
- };
54
- ThemeService = __decorate([
55
- Singleton(),
56
- __param(0, Inject(DEFAULT_THEME)),
57
- __metadata("design:paramtypes", [Object])
58
- ], ThemeService);
59
- export { ThemeService };
60
- function _calculateTheme(theme) {
61
- const paletteEntries = objectEntries(theme.palette)
62
- .map(([color, palette]) => [color, toColorTonesWithRgb(isString(palette) ? generateColorTones(palette) : palette)]);
63
- const palette = fromEntries(paletteEntries);
64
- return { palette };
65
- }
66
- function _generateColorTones(base) {
67
- const colors = generateColors(base, 10);
68
- return {
69
- base,
70
- 50: colors[0],
71
- 100: colors[1],
72
- 200: colors[2],
73
- 300: colors[3],
74
- 400: colors[4],
75
- 500: colors[5],
76
- 600: colors[6],
77
- 700: colors[7],
78
- 800: colors[8],
79
- 900: colors[9]
80
- };
81
- }
82
- function toColorTonesWithRgb(tones) {
83
- return {
84
- /* eslint-disable @typescript-eslint/naming-convention, quote-props */
85
- 'base': tones.base,
86
- 'baseRgb': getRgbString(tones.base),
87
- '50': tones['50'],
88
- '50Rgb': getRgbString(tones['50']),
89
- '100': tones['100'],
90
- '100Rgb': getRgbString(tones['100']),
91
- '200': tones['200'],
92
- '200Rgb': getRgbString(tones['200']),
93
- '300': tones['300'],
94
- '300Rgb': getRgbString(tones['300']),
95
- '400': tones['400'],
96
- '400Rgb': getRgbString(tones['400']),
97
- '500': tones['500'],
98
- '500Rgb': getRgbString(tones['500']),
99
- '600': tones['600'],
100
- '600Rgb': getRgbString(tones['600']),
101
- '700': tones['700'],
102
- '700Rgb': getRgbString(tones['700']),
103
- '800': tones['800'],
104
- '800Rgb': getRgbString(tones['800']),
105
- '900': tones['900'],
106
- '900Rgb': getRgbString(tones['900'])
107
- /* eslint-enable @typescript-eslint/naming-convention, quote-props */
108
- };
109
- }
110
- function getRgbString(color) {
111
- return chroma(color).rgb(true).join(' ');
112
- }
113
- function generateColors(baseColor, colorCount, { bezier = true, correctLightness = true } = {}) {
114
- const generatedColors = autoGradient(baseColor, colorCount);
115
- if (!bezier && !correctLightness) {
116
- return generatedColors.map((color) => color.hex());
117
- }
118
- const scale = (bezier ? chroma.bezier(generatedColors).scale() : chroma.scale(generatedColors));
119
- const colors = scale
120
- .correctLightness(correctLightness)
121
- .colors(colorCount);
122
- return colors;
123
- }
124
- function autoGradient(color, numColors) {
125
- const [, a, b] = chroma(color).lab();
126
- const step = 100 / (numColors + 1);
127
- return createArray(numColors, (i) => chroma.lab(100 - ((i + 1) * step), a, b));
128
- }