@tstdl/base 0.92.166 → 0.92.168
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.
- package/api/server/middlewares/content-type.middleware.js +1 -1
- package/application/application.d.ts +12 -18
- package/application/application.js +48 -69
- package/application/index.d.ts +1 -5
- package/application/index.js +1 -5
- package/application/providers.d.ts +10 -0
- package/application/providers.js +54 -0
- package/authentication/client/authentication.service.d.ts +1 -3
- package/authentication/client/authentication.service.js +4 -5
- package/browser/browser-context-controller.d.ts +2 -4
- package/browser/browser-context-controller.js +5 -6
- package/browser/browser-controller.d.ts +2 -4
- package/browser/browser-controller.js +3 -4
- package/browser/browser.service.d.ts +1 -3
- package/browser/browser.service.js +1 -2
- package/browser/page-controller.d.ts +2 -4
- package/browser/page-controller.js +7 -8
- package/browser/utils.js +3 -3
- package/cancellation/token.d.ts +104 -41
- package/cancellation/token.js +125 -54
- package/core.d.ts +1 -13
- package/core.js +1 -46
- package/disposable/disposable.d.ts +0 -8
- package/disposable/disposable.js +1 -3
- package/disposable/index.d.ts +0 -6
- package/disposable/index.js +0 -6
- package/disposable/using.d.ts +0 -1
- package/disposable/using.js +2 -3
- package/distributed-loop/distributed-loop.js +2 -2
- package/errors/utils.js +4 -1
- package/examples/api/authentication.js +11 -5
- package/examples/api/basic-overview.js +17 -12
- package/examples/api/custom-authentication.js +13 -7
- package/examples/api/streaming.js +15 -12
- package/examples/browser/basic.js +6 -3
- package/examples/document-management/main.js +6 -3
- package/examples/http/client.js +7 -3
- package/examples/mail/basic.js +9 -7
- package/examples/pdf/basic.js +8 -6
- package/examples/template/basic.js +7 -5
- package/http/client/http-client-request.d.ts +1 -2
- package/http/client/http-client-request.js +1 -2
- package/http/server/http-server.d.ts +1 -3
- package/http/server/http-server.js +0 -1
- package/http/server/node/node-http-server.d.ts +1 -2
- package/http/server/node/node-http-server.js +1 -2
- package/import.js +1 -1
- package/injector/injector.d.ts +1 -1
- package/injector/types.d.ts +3 -4
- package/lock/lock.d.ts +40 -21
- package/lock/lock.js +74 -1
- package/lock/postgres/drizzle/0000_busy_tattoo.sql +7 -0
- package/lock/postgres/drizzle/meta/0000_snapshot.json +65 -0
- package/lock/postgres/drizzle/meta/_journal.json +13 -0
- package/lock/postgres/drizzle.config.js +11 -0
- package/lock/postgres/index.d.ts +2 -0
- package/lock/postgres/index.js +2 -0
- package/lock/postgres/lock.d.ts +14 -0
- package/lock/postgres/lock.js +127 -0
- package/lock/postgres/models/index.d.ts +2 -0
- package/lock/postgres/models/index.js +2 -0
- package/lock/postgres/models/lock.model.d.ts +7 -0
- package/{examples/orm/user.model.js → lock/postgres/models/lock.model.js} +22 -30
- package/lock/postgres/models/schemas.d.ts +3 -0
- package/lock/postgres/models/schemas.js +4 -0
- package/lock/postgres/module.d.ts +6 -0
- package/lock/postgres/module.js +26 -0
- package/lock/postgres/provider.d.ts +6 -0
- package/lock/postgres/provider.js +29 -0
- package/lock/provider.d.ts +12 -2
- package/lock/provider.js +24 -1
- package/lock/web/web-lock.d.ts +4 -3
- package/lock/web/web-lock.js +49 -42
- package/lock/web/web-lock.provider.d.ts +0 -3
- package/lock/web/web-lock.provider.js +5 -22
- package/logger/formatter.d.ts +13 -0
- package/logger/formatter.js +3 -0
- package/logger/formatters/index.d.ts +2 -0
- package/logger/formatters/index.js +2 -0
- package/logger/formatters/json.d.ts +5 -0
- package/logger/formatters/json.js +33 -0
- package/logger/formatters/pretty-print.d.ts +5 -0
- package/logger/formatters/pretty-print.js +55 -0
- package/logger/index.d.ts +5 -2
- package/logger/index.js +5 -2
- package/logger/level.d.ts +10 -8
- package/logger/level.js +9 -9
- package/logger/logger.d.ts +21 -30
- package/logger/logger.js +98 -26
- package/logger/manager.d.ts +20 -0
- package/logger/manager.js +77 -0
- package/logger/tokens.d.ts +1 -1
- package/logger/tokens.js +1 -1
- package/logger/transport.d.ts +14 -0
- package/logger/transport.js +16 -0
- package/logger/transports/console.d.ts +14 -0
- package/logger/transports/console.js +36 -0
- package/logger/transports/index.d.ts +1 -0
- package/logger/transports/index.js +1 -0
- package/mail/clients/nodemailer.mail-client.d.ts +0 -1
- package/mail/clients/nodemailer.mail-client.js +9 -7
- package/message-bus/local/local-message-bus.js +2 -2
- package/message-bus/message-bus-base.d.ts +2 -3
- package/message-bus/message-bus-base.js +5 -6
- package/message-bus/message-bus.d.ts +1 -2
- package/message-bus/message-bus.js +1 -2
- package/module/index.d.ts +0 -2
- package/module/index.js +0 -2
- package/module/module.d.ts +17 -18
- package/module/module.js +47 -12
- package/module/modules/function.module.d.ts +6 -6
- package/module/modules/function.module.js +25 -9
- package/module/modules/web-server.module.d.ts +2 -10
- package/module/modules/web-server.module.js +3 -11
- package/openid-connect/index.d.ts +0 -2
- package/openid-connect/index.js +0 -2
- package/openid-connect/oidc-state.model.d.ts +4 -5
- package/openid-connect/oidc-state.model.js +51 -1
- package/openid-connect/oidc.service-model.d.ts +1 -1
- package/openid-connect/oidc.service.d.ts +2 -6
- package/openid-connect/oidc.service.js +24 -37
- package/orm/decorators.d.ts +10 -1
- package/orm/decorators.js +8 -0
- package/orm/server/repository.d.ts +3 -1
- package/orm/server/repository.js +32 -3
- package/package.json +17 -28
- package/pdf/pdf.service.js +9 -9
- package/pool/pool.d.ts +1 -3
- package/pool/pool.js +3 -4
- package/queue/postgres/job.model.d.ts +1 -2
- package/queue/postgres/job.model.js +1 -2
- package/queue/postgres/module.js +1 -1
- package/threading/thread-pool.d.ts +1 -3
- package/threading/thread-pool.js +7 -8
- package/utils/format-error.d.ts +7 -0
- package/utils/format-error.js +59 -17
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/object/dereference.d.ts +51 -19
- package/utils/object/dereference.js +52 -43
- package/utils/timing.js +2 -2
- package/utils/try-chain.d.ts +22 -0
- package/utils/try-chain.js +46 -0
- package/database/entity-repository.d.ts +0 -50
- package/database/entity-repository.js +0 -3
- package/database/entity.d.ts +0 -7
- package/database/entity.js +0 -1
- package/database/id.d.ts +0 -1
- package/database/id.js +0 -9
- package/database/index.d.ts +0 -11
- package/database/index.js +0 -11
- package/database/module.d.ts +0 -8
- package/database/module.js +0 -11
- package/database/mongo/classes.d.ts +0 -21
- package/database/mongo/classes.js +0 -26
- package/database/mongo/index.d.ts +0 -15
- package/database/mongo/index.js +0 -15
- package/database/mongo/model/document.d.ts +0 -29
- package/database/mongo/model/document.js +0 -63
- package/database/mongo/model/index.d.ts +0 -1
- package/database/mongo/model/index.js +0 -1
- package/database/mongo/module.d.ts +0 -8
- package/database/mongo/module.js +0 -68
- package/database/mongo/mongo-base.repository.d.ts +0 -103
- package/database/mongo/mongo-base.repository.js +0 -263
- package/database/mongo/mongo-bulk.d.ts +0 -35
- package/database/mongo/mongo-bulk.js +0 -90
- package/database/mongo/mongo-entity-repository.d.ts +0 -98
- package/database/mongo/mongo-entity-repository.js +0 -278
- package/database/mongo/operations.d.ts +0 -10
- package/database/mongo/operations.js +0 -54
- package/database/mongo/query-converter.d.ts +0 -6
- package/database/mongo/query-converter.js +0 -83
- package/database/mongo/simple-entity-repository.d.ts +0 -7
- package/database/mongo/simple-entity-repository.js +0 -6
- package/database/mongo/types.d.ts +0 -50
- package/database/mongo/types.js +0 -3
- package/database/query.d.ts +0 -121
- package/database/query.js +0 -7
- package/database/utils.d.ts +0 -2
- package/database/utils.js +0 -3
- package/disposable/async-disposer.d.ts +0 -35
- package/disposable/async-disposer.js +0 -125
- package/examples/orm/drizzle.config.js +0 -6
- package/examples/orm/schemas.d.ts +0 -3
- package/examples/orm/schemas.js +0 -4
- package/examples/orm/test.d.ts +0 -1
- package/examples/orm/test.js +0 -11
- package/examples/orm/user.model.d.ts +0 -13
- package/key-value-store/mongo/index.d.ts +0 -6
- package/key-value-store/mongo/index.js +0 -6
- package/key-value-store/mongo/module.d.ts +0 -8
- package/key-value-store/mongo/module.js +0 -18
- package/key-value-store/mongo/mongo-key-value-store.provider.d.ts +0 -8
- package/key-value-store/mongo/mongo-key-value-store.provider.js +0 -26
- package/key-value-store/mongo/mongo-key-value.model.d.ts +0 -7
- package/key-value-store/mongo/mongo-key-value.model.js +0 -1
- package/key-value-store/mongo/mongo-key-value.repository.d.ts +0 -10
- package/key-value-store/mongo/mongo-key-value.repository.js +0 -31
- package/key-value-store/mongo/mongo-key-value.store.d.ts +0 -15
- package/key-value-store/mongo/mongo-key-value.store.js +0 -82
- package/key-value-store/mongo/tokens.d.ts +0 -3
- package/key-value-store/mongo/tokens.js +0 -2
- package/lock/mongo/index.d.ts +0 -5
- package/lock/mongo/index.js +0 -5
- package/lock/mongo/lock.d.ts +0 -14
- package/lock/mongo/lock.js +0 -125
- package/lock/mongo/model.d.ts +0 -6
- package/lock/mongo/model.js +0 -1
- package/lock/mongo/module.d.ts +0 -12
- package/lock/mongo/module.js +0 -20
- package/lock/mongo/mongo-lock-repository.d.ts +0 -14
- package/lock/mongo/mongo-lock-repository.js +0 -67
- package/lock/mongo/provider.d.ts +0 -8
- package/lock/mongo/provider.js +0 -36
- package/logger/console/index.d.ts +0 -1
- package/logger/console/index.js +0 -1
- package/logger/console/logger.d.ts +0 -11
- package/logger/console/logger.js +0 -64
- package/logger/noop/index.d.ts +0 -1
- package/logger/noop/index.js +0 -1
- package/logger/noop/logger.d.ts +0 -9
- package/logger/noop/logger.js +0 -21
- package/migration/index.d.ts +0 -9
- package/migration/index.js +0 -9
- package/migration/migration-state-repository.d.ts +0 -4
- package/migration/migration-state-repository.js +0 -3
- package/migration/migration-state.d.ts +0 -6
- package/migration/migration-state.js +0 -1
- package/migration/migrator.d.ts +0 -23
- package/migration/migrator.js +0 -76
- package/migration/mongo/index.d.ts +0 -2
- package/migration/mongo/index.js +0 -2
- package/migration/mongo/migration-state-repository.d.ts +0 -11
- package/migration/mongo/migration-state-repository.js +0 -32
- package/migration/mongo/module.d.ts +0 -12
- package/migration/mongo/module.js +0 -17
- package/module/module-base.d.ts +0 -18
- package/module/module-base.js +0 -40
- package/module/module-metric-reporter.d.ts +0 -29
- package/module/module-metric-reporter.js +0 -62
- package/openid-connect/mongo-oidc-state.repository.d.ts +0 -21
- package/openid-connect/mongo-oidc-state.repository.js +0 -52
- package/openid-connect/oidc-state.repository.d.ts +0 -4
- package/openid-connect/oidc-state.repository.js +0 -3
- package/process-shutdown.d.ts +0 -9
- package/process-shutdown.js +0 -65
- package/queue/mongo/index.d.ts +0 -4
- package/queue/mongo/index.js +0 -4
- package/queue/mongo/job.d.ts +0 -12
- package/queue/mongo/job.js +0 -1
- package/queue/mongo/mongo-job.repository.d.ts +0 -13
- package/queue/mongo/mongo-job.repository.js +0 -54
- package/queue/mongo/queue.d.ts +0 -38
- package/queue/mongo/queue.js +0 -266
- package/queue/mongo/queue.provider.d.ts +0 -18
- package/queue/mongo/queue.provider.js +0 -38
- package/search-index/elastic/config.d.ts +0 -8
- package/search-index/elastic/config.js +0 -26
- package/search-index/elastic/index.d.ts +0 -8
- package/search-index/elastic/index.js +0 -8
- package/search-index/elastic/keyword-rewriter.d.ts +0 -8
- package/search-index/elastic/keyword-rewriter.js +0 -18
- package/search-index/elastic/model/elastic-query.d.ts +0 -16
- package/search-index/elastic/model/elastic-query.js +0 -1
- package/search-index/elastic/model/index-mapping.d.ts +0 -26
- package/search-index/elastic/model/index-mapping.js +0 -4
- package/search-index/elastic/model/index.d.ts +0 -3
- package/search-index/elastic/model/index.js +0 -3
- package/search-index/elastic/model/sort.d.ts +0 -8
- package/search-index/elastic/model/sort.js +0 -1
- package/search-index/elastic/module.d.ts +0 -10
- package/search-index/elastic/module.js +0 -49
- package/search-index/elastic/query-builder/boolean-query-builder.d.ts +0 -11
- package/search-index/elastic/query-builder/boolean-query-builder.js +0 -52
- package/search-index/elastic/query-builder/index.d.ts +0 -1
- package/search-index/elastic/query-builder/index.js +0 -1
- package/search-index/elastic/query-converter.d.ts +0 -9
- package/search-index/elastic/query-converter.js +0 -183
- package/search-index/elastic/search-index.d.ts +0 -30
- package/search-index/elastic/search-index.js +0 -144
- package/search-index/elastic/sort-converter.d.ts +0 -4
- package/search-index/elastic/sort-converter.js +0 -14
- package/search-index/elastic/types.d.ts +0 -5
- package/search-index/elastic/types.js +0 -1
- package/search-index/error.d.ts +0 -10
- package/search-index/error.js +0 -14
- package/search-index/index.d.ts +0 -3
- package/search-index/index.js +0 -3
- package/search-index/memory/index.d.ts +0 -1
- package/search-index/memory/index.js +0 -1
- package/search-index/memory/memory-search-index.d.ts +0 -19
- package/search-index/memory/memory-search-index.js +0 -144
- package/search-index/search-index.d.ts +0 -46
- package/search-index/search-index.js +0 -31
- package/search-index/search-result.d.ts +0 -12
- package/search-index/search-result.js +0 -1
- package/theme/adapters/css-adapter.d.ts +0 -5
- package/theme/adapters/css-adapter.js +0 -29
- package/theme/adapters/index.d.ts +0 -2
- package/theme/adapters/index.js +0 -2
- package/theme/adapters/tailwind-adapter.d.ts +0 -18
- package/theme/adapters/tailwind-adapter.js +0 -32
- package/theme/index.d.ts +0 -1
- package/theme/index.js +0 -1
- package/theme/theme-service.d.ts +0 -43
- package/theme/theme-service.js +0 -128
- /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,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
|
-
}
|
package/theme/adapters/index.js
DELETED
|
@@ -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';
|
package/theme/theme-service.d.ts
DELETED
|
@@ -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
|
-
}
|
package/theme/theme-service.js
DELETED
|
@@ -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
|
-
}
|
|
File without changes
|