valtech-components 2.0.495 → 2.0.497

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.
@@ -0,0 +1,29 @@
1
+ import { EnvironmentProviders } from '@angular/core';
2
+ import { I18nConfig } from './types';
3
+ /**
4
+ * Configura el sistema de internacionalización de Valtech Components.
5
+ *
6
+ * @param config Configuración de i18n
7
+ * @returns Providers para agregar en app.config.ts
8
+ *
9
+ * @example
10
+ * // app.config.ts
11
+ * import { provideValtechI18n } from 'valtech-components';
12
+ * import { GLOBAL_CONTENT } from './i18n/_global';
13
+ * import { LOGIN_CONTENT } from './i18n/login.i18n';
14
+ *
15
+ * export const appConfig: ApplicationConfig = {
16
+ * providers: [
17
+ * provideValtechI18n({
18
+ * defaultLanguage: 'es',
19
+ * supportedLanguages: ['es', 'en'],
20
+ * detectBrowserLanguage: true,
21
+ * content: {
22
+ * '_global': GLOBAL_CONTENT,
23
+ * 'Login': LOGIN_CONTENT,
24
+ * }
25
+ * }),
26
+ * ]
27
+ * };
28
+ */
29
+ export declare function provideValtechI18n(config?: I18nConfig): EnvironmentProviders;
@@ -0,0 +1,112 @@
1
+ import { I18nLang, LanguagesContent, ContentStore } from './types';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Servicio de internacionalización basado en Angular Signals.
5
+ *
6
+ * Características:
7
+ * - Sin RxJS: usa Signals para evitar memory leaks y congelamiento
8
+ * - Namespace-based: organiza traducciones por contexto
9
+ * - Fallback multi-nivel: namespace → _global → placeholder
10
+ * - Interpolación: soporta {variable} en textos
11
+ *
12
+ * @example
13
+ * // En un componente
14
+ * i18n = inject(I18nService);
15
+ *
16
+ * // Obtener texto
17
+ * const title = this.i18n.t('title', 'Login');
18
+ *
19
+ * // Con interpolación
20
+ * const welcome = this.i18n.t('welcome', 'Login', { name: 'Juan' });
21
+ *
22
+ * // Cambiar idioma
23
+ * this.i18n.setLanguage('en');
24
+ */
25
+ export declare class I18nService {
26
+ private readonly _lang;
27
+ private readonly _content;
28
+ private readonly _supportedLanguages;
29
+ readonly lang: import("@angular/core").Signal<I18nLang>;
30
+ readonly supportedLanguages: import("@angular/core").Signal<I18nLang[]>;
31
+ readonly isSpanish: import("@angular/core").Signal<boolean>;
32
+ readonly isEnglish: import("@angular/core").Signal<boolean>;
33
+ constructor();
34
+ /**
35
+ * Obtiene texto traducido (alias corto de getText)
36
+ *
37
+ * @param key Clave del texto
38
+ * @param namespace Namespace (default: '_global')
39
+ * @param data Variables para interpolación
40
+ * @returns Texto traducido o placeholder [namespace.key]
41
+ *
42
+ * @example
43
+ * i18n.t('submit'); // busca en _global
44
+ * i18n.t('title', 'Login'); // busca en Login
45
+ * i18n.t('welcome', 'Login', {name}); // con interpolación
46
+ */
47
+ t(key: string, namespace?: string, data?: Record<string, string>): string;
48
+ /**
49
+ * Obtiene texto traducido
50
+ *
51
+ * Fallback order:
52
+ * 1. content[namespace][lang][key]
53
+ * 2. content['_global'][lang][key]
54
+ * 3. "[namespace.key]" (placeholder)
55
+ */
56
+ getText(key: string, namespace?: string, data?: Record<string, string>): string;
57
+ /**
58
+ * Cambia el idioma de la aplicación
59
+ *
60
+ * @param lang Nuevo idioma
61
+ * @param forceReload Si true, recarga la página (fallback si reactividad falla)
62
+ */
63
+ setLanguage(lang: I18nLang, forceReload?: boolean): void;
64
+ /**
65
+ * Registra contenido de traducciones para un namespace
66
+ *
67
+ * @param namespace Nombre del namespace
68
+ * @param content Contenido de traducciones
69
+ *
70
+ * @example
71
+ * i18n.registerContent('Login', {
72
+ * es: { title: 'Iniciar sesión' },
73
+ * en: { title: 'Sign in' }
74
+ * });
75
+ */
76
+ registerContent(namespace: string, content: LanguagesContent): void;
77
+ /**
78
+ * Registra múltiples namespaces de una vez
79
+ *
80
+ * @param contentStore Objeto con namespaces como keys
81
+ */
82
+ registerContentBulk(contentStore: ContentStore): void;
83
+ /**
84
+ * Configura los idiomas soportados
85
+ */
86
+ setI18nLanguages(languages: I18nLang[]): void;
87
+ /**
88
+ * Obtiene todos los namespaces registrados
89
+ */
90
+ getNamespaces(): string[];
91
+ /**
92
+ * Verifica si un namespace tiene traducciones
93
+ */
94
+ hasNamespace(namespace: string): boolean;
95
+ /**
96
+ * Carga idioma guardado en localStorage o detecta del navegador
97
+ */
98
+ private loadStoredLanguage;
99
+ /**
100
+ * Valida si un idioma está soportado
101
+ */
102
+ private isValidLanguage;
103
+ /**
104
+ * Reemplaza {variable} en texto con valores de data
105
+ *
106
+ * @example
107
+ * interpolate('Hola {name}', { name: 'Juan' }) // 'Hola Juan'
108
+ */
109
+ private interpolate;
110
+ static ɵfac: i0.ɵɵFactoryDeclaration<I18nService, never>;
111
+ static ɵprov: i0.ɵɵInjectableDeclaration<I18nService>;
112
+ }
@@ -0,0 +1,4 @@
1
+ export { I18nLang, LanguagesContent, ContentStore, I18nConfig, LANG_STORAGE_KEY, } from './types';
2
+ export { I18nService } from './i18n.service';
3
+ export { TranslatePipe } from './translate.pipe';
4
+ export { provideValtechI18n } from './config';
@@ -0,0 +1,36 @@
1
+ import { PipeTransform } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Pipe de traducción para templates.
5
+ *
6
+ * NOTA: Es impure para detectar cambios de idioma.
7
+ * El costo es mínimo porque I18nService usa Signals internamente.
8
+ *
9
+ * @example
10
+ * <!-- Busca en _global -->
11
+ * {{ 'submit' | t }}
12
+ *
13
+ * <!-- Busca en namespace específico -->
14
+ * {{ 'title' | t:'Login' }}
15
+ *
16
+ * <!-- Con interpolación -->
17
+ * {{ 'welcome' | t:'Login':{ name: userName } }}
18
+ *
19
+ * <!-- En atributos -->
20
+ * <val-button [label]="'submit' | t"></val-button>
21
+ * <val-input [label]="'email' | t:'Login'"></val-input>
22
+ */
23
+ export declare class TranslatePipe implements PipeTransform {
24
+ private readonly i18n;
25
+ /**
26
+ * Transforma una key de traducción a su valor
27
+ *
28
+ * @param key Clave del texto
29
+ * @param namespace Namespace opcional (default: '_global')
30
+ * @param data Variables para interpolación opcional
31
+ * @returns Texto traducido
32
+ */
33
+ transform(key: string, namespace?: string, data?: Record<string, string>): string;
34
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslatePipe, never>;
35
+ static ɵpipe: i0.ɵɵPipeDeclaration<TranslatePipe, "t", true>;
36
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Idiomas soportados por el sistema i18n
3
+ */
4
+ export type I18nLang = 'es' | 'en' | 'pt' | 'fr' | 'de';
5
+ /**
6
+ * Contenido de traducciones para un namespace
7
+ *
8
+ * @example
9
+ * const loginContent: LanguagesContent = {
10
+ * es: { title: 'Iniciar sesión', submit: 'Entrar' },
11
+ * en: { title: 'Sign in', submit: 'Sign in' }
12
+ * };
13
+ */
14
+ export type LanguagesContent = {
15
+ [lang in I18nLang]?: Record<string, string>;
16
+ };
17
+ /**
18
+ * Almacén de contenido por namespace
19
+ *
20
+ * @example
21
+ * {
22
+ * '_global': { es: {...}, en: {...} },
23
+ * 'Login': { es: {...}, en: {...} },
24
+ * 'Profile': { es: {...}, en: {...} }
25
+ * }
26
+ */
27
+ export type ContentStore = Record<string, LanguagesContent>;
28
+ /**
29
+ * Configuración para provideValtechI18n()
30
+ */
31
+ export interface I18nConfig {
32
+ /**
33
+ * Idioma por defecto si no hay preferencia guardada
34
+ * @default 'es'
35
+ */
36
+ defaultLanguage?: I18nLang;
37
+ /**
38
+ * Lista de idiomas habilitados en la app
39
+ * @default ['es', 'en']
40
+ */
41
+ supportedLanguages?: I18nLang[];
42
+ /**
43
+ * Detectar idioma del navegador al iniciar
44
+ * @default true
45
+ */
46
+ detectBrowserLanguage?: boolean;
47
+ /**
48
+ * Contenido inicial de traducciones por namespace
49
+ */
50
+ content?: ContentStore;
51
+ }
52
+ /**
53
+ * Valores por defecto de configuración
54
+ */
55
+ export declare const DEFAULT_I18N_CONFIG: Required<I18nConfig>;
56
+ /**
57
+ * Clave para persistir idioma en localStorage
58
+ */
59
+ export declare const LANG_STORAGE_KEY = "app_lang";
@@ -0,0 +1,32 @@
1
+ import { EnvironmentProviders } from '@angular/core';
2
+ import { PresetConfig } from './types';
3
+ /**
4
+ * Configura el sistema de presets de Valtech Components.
5
+ *
6
+ * @param presets Configuración de presets por componente
7
+ * @returns Providers para agregar en app.config.ts
8
+ *
9
+ * @example
10
+ * // app.config.ts
11
+ * import { provideValtechPresets } from 'valtech-components';
12
+ *
13
+ * export const appConfig: ApplicationConfig = {
14
+ * providers: [
15
+ * provideValtechPresets({
16
+ * button: {
17
+ * 'primary-action': { size: 'large', color: 'primary', fill: 'solid' },
18
+ * 'secondary': { size: 'medium', color: 'secondary', fill: 'outline' },
19
+ * 'danger': { size: 'medium', color: 'danger', fill: 'solid' },
20
+ * },
21
+ * card: {
22
+ * 'feature': { variant: 'elevated', padding: 'large' },
23
+ * 'compact': { variant: 'flat', padding: 'small' },
24
+ * },
25
+ * input: {
26
+ * 'form-field': { size: 'medium', fill: 'outline', labelPosition: 'floating' },
27
+ * }
28
+ * }),
29
+ * ]
30
+ * };
31
+ */
32
+ export declare function provideValtechPresets(presets: PresetConfig): EnvironmentProviders;
@@ -0,0 +1,3 @@
1
+ export { PresetConfig, ComponentPresets, PresetsOptions } from './types';
2
+ export { PresetService } from './preset.service';
3
+ export { provideValtechPresets } from './config';
@@ -0,0 +1,69 @@
1
+ import { PresetConfig, ComponentPresets } from './types';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Servicio para gestionar presets de componentes.
5
+ *
6
+ * Los presets permiten definir configuraciones reutilizables
7
+ * de componentes (tamaño, color, variante, etc.) que se pueden
8
+ * aplicar con un nombre semántico.
9
+ *
10
+ * @example
11
+ * // En un componente
12
+ * presets = inject(PresetService);
13
+ *
14
+ * // Obtener preset
15
+ * const buttonProps = this.presets.get<ButtonMetadata>('button', 'primary-action');
16
+ * // { size: 'large', color: 'primary', fill: 'solid' }
17
+ */
18
+ export declare class PresetService {
19
+ private readonly _presets;
20
+ /**
21
+ * Obtiene un preset específico para un componente
22
+ *
23
+ * @param component Tipo de componente (ej: 'button', 'card', 'input')
24
+ * @param presetName Nombre del preset (ej: 'primary-action', 'compact')
25
+ * @returns Propiedades del preset o objeto vacío si no existe
26
+ *
27
+ * @example
28
+ * // Obtener preset de botón
29
+ * const props = presets.get<ButtonMetadata>('button', 'primary-action');
30
+ *
31
+ * // Usar en componente
32
+ * <val-button [props]="props"></val-button>
33
+ */
34
+ get<T extends Record<string, unknown>>(component: string, presetName: string): Partial<T>;
35
+ /**
36
+ * Verifica si existe un preset
37
+ */
38
+ has(component: string, presetName: string): boolean;
39
+ /**
40
+ * Registra presets de la aplicación
41
+ *
42
+ * @param presets Configuración de presets
43
+ *
44
+ * @example
45
+ * presets.registerPresets({
46
+ * button: {
47
+ * 'primary-action': { size: 'large', color: 'primary' },
48
+ * },
49
+ * card: {
50
+ * 'feature': { variant: 'elevated' },
51
+ * }
52
+ * });
53
+ */
54
+ registerPresets(presets: PresetConfig): void;
55
+ /**
56
+ * Agrega presets para un componente específico (merge con existentes)
57
+ */
58
+ registerComponentPresets(component: string, presets: ComponentPresets): void;
59
+ /**
60
+ * Obtiene todos los nombres de presets para un componente
61
+ */
62
+ getPresetNames(component: string): string[];
63
+ /**
64
+ * Obtiene todos los componentes con presets registrados
65
+ */
66
+ getRegisteredComponents(): string[];
67
+ static ɵfac: i0.ɵɵFactoryDeclaration<PresetService, never>;
68
+ static ɵprov: i0.ɵɵInjectableDeclaration<PresetService>;
69
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Presets para un tipo de componente
3
+ *
4
+ * @example
5
+ * const buttonPresets: ComponentPresets = {
6
+ * 'primary-action': { size: 'large', color: 'primary', fill: 'solid' },
7
+ * 'secondary': { size: 'medium', color: 'secondary', fill: 'outline' },
8
+ * 'danger': { size: 'medium', color: 'danger', fill: 'solid' },
9
+ * };
10
+ */
11
+ export type ComponentPresets = Record<string, Record<string, unknown>>;
12
+ /**
13
+ * Configuración completa de presets por componente
14
+ *
15
+ * @example
16
+ * const appPresets: PresetConfig = {
17
+ * button: {
18
+ * 'primary-action': { size: 'large', color: 'primary', fill: 'solid' },
19
+ * 'secondary': { size: 'medium', color: 'secondary', fill: 'outline' },
20
+ * },
21
+ * card: {
22
+ * 'feature': { variant: 'elevated', padding: 'large' },
23
+ * 'compact': { variant: 'flat', padding: 'small' },
24
+ * },
25
+ * input: {
26
+ * 'form-field': { size: 'medium', fill: 'outline', labelPosition: 'floating' },
27
+ * }
28
+ * };
29
+ */
30
+ export type PresetConfig = Record<string, ComponentPresets>;
31
+ /**
32
+ * Opciones para provideValtechPresets()
33
+ */
34
+ export interface PresetsOptions {
35
+ /**
36
+ * Presets iniciales de la aplicación
37
+ */
38
+ presets: PresetConfig;
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valtech-components",
3
- "version": "2.0.495",
3
+ "version": "2.0.497",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "valtech-firebase-config": "./src/lib/services/firebase/scripts/generate-sw-config.js"
package/public-api.d.ts CHANGED
@@ -219,6 +219,8 @@ export * from './lib/services/modal/modal.service';
219
219
  export * from './lib/services/modal/types';
220
220
  export * from './lib/services/firebase';
221
221
  export * from './lib/services/auth';
222
+ export * from './lib/services/i18n';
223
+ export * from './lib/services/presets';
222
224
  export * from './lib/components/types';
223
225
  export * from './lib/shared/pipes/process-links.pipe';
224
226
  export * from './lib/shared/utils/dom';