@kopynator/angular 1.0.3 → 1.0.5
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/ng-package.json +7 -0
- package/package.json +6 -17
- package/src/lib/kopy.directive.ts +32 -0
- package/src/lib/kopy.pipe.ts +23 -0
- package/src/lib/kopy.selector.component.ts +164 -0
- package/src/lib/kopy.service.ts +57 -0
- package/src/public-api.ts +25 -0
- package/tsconfig.json +21 -0
- package/dist/public-api.d.mts +0 -35
- package/dist/public-api.d.ts +0 -35
- package/dist/public-api.js +0 -134
- package/dist/public-api.mjs +0 -106
package/ng-package.json
ADDED
package/package.json
CHANGED
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kopynator/angular",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "./dist/public-api.js",
|
|
5
|
-
"module": "./dist/public-api.mjs",
|
|
6
|
-
"types": "./dist/public-api.d.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"types": "./dist/public-api.d.ts",
|
|
10
|
-
"import": "./dist/public-api.mjs",
|
|
11
|
-
"require": "./dist/public-api.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
],
|
|
3
|
+
"version": "1.0.5",
|
|
17
4
|
"publishConfig": {
|
|
18
5
|
"access": "public"
|
|
19
6
|
},
|
|
20
7
|
"peerDependencies": {
|
|
21
8
|
"@angular/common": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0",
|
|
22
|
-
"@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0"
|
|
9
|
+
"@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0",
|
|
10
|
+
"@kopynator/core": "^1.0.1"
|
|
23
11
|
},
|
|
24
12
|
"dependencies": {
|
|
25
|
-
"@kopynator/core": "1.0.0",
|
|
26
13
|
"tslib": "^2.3.0"
|
|
27
14
|
},
|
|
28
15
|
"devDependencies": {
|
|
29
16
|
"@angular/common": "^21.0.6",
|
|
30
17
|
"@angular/core": "^21.0.6",
|
|
31
18
|
"@angular/platform-browser": "^21.0.6",
|
|
19
|
+
"@swc/core": "^1.15.7",
|
|
20
|
+
"ng-packagr": "^21.0.1",
|
|
32
21
|
"tsup": "^8.0.0",
|
|
33
22
|
"typescript": "^5.0.0"
|
|
34
23
|
},
|
|
35
24
|
"scripts": {
|
|
36
|
-
"build": "
|
|
25
|
+
"build": "ng-packagr -p ng-package.json",
|
|
37
26
|
"release:patch": "npm version patch",
|
|
38
27
|
"release:minor": "npm version minor",
|
|
39
28
|
"release:major": "npm version major"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Directive, ElementRef, Input, OnChanges, SimpleChanges, effect } from '@angular/core';
|
|
2
|
+
import { KopyService } from './kopy.service';
|
|
3
|
+
|
|
4
|
+
@Directive({
|
|
5
|
+
selector: '[kopy]',
|
|
6
|
+
standalone: true
|
|
7
|
+
})
|
|
8
|
+
export class KopyDirective implements OnChanges {
|
|
9
|
+
@Input('kopy') key!: string;
|
|
10
|
+
@Input() kopyParams: Record<string, any> = {};
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
private el: ElementRef,
|
|
14
|
+
private kopyService: KopyService
|
|
15
|
+
) {
|
|
16
|
+
// React to signal changes in KopyService
|
|
17
|
+
effect(() => {
|
|
18
|
+
this.kopyService.currentLocale();
|
|
19
|
+
this.kopyService.isReady();
|
|
20
|
+
this.render();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
ngOnChanges(changes: SimpleChanges): void {
|
|
25
|
+
this.render();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private render() {
|
|
29
|
+
if (!this.key) return;
|
|
30
|
+
this.el.nativeElement.textContent = this.kopyService.translate(this.key, this.kopyParams);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
import { KopyService } from './kopy.service';
|
|
3
|
+
|
|
4
|
+
@Pipe({
|
|
5
|
+
name: 'kopy',
|
|
6
|
+
pure: false, // Must be false to react to signal changes inside transform
|
|
7
|
+
standalone: true
|
|
8
|
+
})
|
|
9
|
+
export class KopyPipe implements PipeTransform {
|
|
10
|
+
constructor(
|
|
11
|
+
private kopyService: KopyService
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
transform(key: string, params: Record<string, any> = {}): string {
|
|
15
|
+
// Establishing reactive dependencies on signals
|
|
16
|
+
const ready = this.kopyService.isReady();
|
|
17
|
+
const locale = this.kopyService.currentLocale();
|
|
18
|
+
|
|
19
|
+
if (!ready) return key;
|
|
20
|
+
|
|
21
|
+
return this.kopyService.translate(key, params);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Component, inject, signal } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { KopyService } from './kopy.service';
|
|
4
|
+
|
|
5
|
+
@Component({
|
|
6
|
+
selector: 'kopy-selector',
|
|
7
|
+
standalone: true,
|
|
8
|
+
imports: [CommonModule],
|
|
9
|
+
template: `
|
|
10
|
+
<div class="kopy-selector-container" [class.open]="isOpen()">
|
|
11
|
+
<button class="kopy-selected-btn" (click)="toggleDropdown()">
|
|
12
|
+
<span class="flag">{{ getFlag(currentLocale()) }}</span>
|
|
13
|
+
<span class="label uppercase">{{ currentLocale() }}</span>
|
|
14
|
+
<svg class="chevron" [class.rotate]="isOpen()" viewBox="0 0 20 20" fill="currentColor">
|
|
15
|
+
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
|
16
|
+
</svg>
|
|
17
|
+
</button>
|
|
18
|
+
|
|
19
|
+
<div class="kopy-dropdown" *ngIf="isOpen()">
|
|
20
|
+
<button
|
|
21
|
+
*ngFor="let lang of languages()"
|
|
22
|
+
class="kopy-dropdown-item"
|
|
23
|
+
[class.active]="lang === currentLocale()"
|
|
24
|
+
(click)="selectLanguage(lang)"
|
|
25
|
+
>
|
|
26
|
+
<span class="flag">{{ getFlag(lang) }}</span>
|
|
27
|
+
<span class="label">{{ getNativeName(lang) }}</span>
|
|
28
|
+
</button>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
`,
|
|
32
|
+
styles: [`
|
|
33
|
+
.kopy-selector-container {
|
|
34
|
+
position: relative;
|
|
35
|
+
display: inline-block;
|
|
36
|
+
font-family: inherit;
|
|
37
|
+
}
|
|
38
|
+
.kopy-selected-btn {
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
gap: 6px;
|
|
42
|
+
padding: 4px 10px;
|
|
43
|
+
background: rgba(255, 255, 255, 0.05);
|
|
44
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
45
|
+
border-radius: 99px;
|
|
46
|
+
color: white;
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
transition: all 0.2s;
|
|
49
|
+
font-size: 11px;
|
|
50
|
+
font-weight: 700;
|
|
51
|
+
min-width: 70px;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
}
|
|
54
|
+
.kopy-selected-btn:hover {
|
|
55
|
+
background: rgba(255, 255, 255, 0.1);
|
|
56
|
+
border-color: rgba(255, 255, 255, 0.2);
|
|
57
|
+
}
|
|
58
|
+
.chevron {
|
|
59
|
+
width: 10px;
|
|
60
|
+
height: 10px;
|
|
61
|
+
opacity: 0.5;
|
|
62
|
+
transition: transform 0.2s;
|
|
63
|
+
}
|
|
64
|
+
.chevron.rotate {
|
|
65
|
+
transform: rotate(180deg);
|
|
66
|
+
}
|
|
67
|
+
.kopy-dropdown {
|
|
68
|
+
position: absolute;
|
|
69
|
+
top: 100%;
|
|
70
|
+
right: 0;
|
|
71
|
+
margin-top: 8px;
|
|
72
|
+
background: #1e293b;
|
|
73
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
74
|
+
border-radius: 12px;
|
|
75
|
+
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
|
|
76
|
+
overflow: hidden;
|
|
77
|
+
min-width: 140px;
|
|
78
|
+
z-index: 100;
|
|
79
|
+
animation: slideIn 0.2s ease-out;
|
|
80
|
+
}
|
|
81
|
+
.kopy-dropdown-item {
|
|
82
|
+
width: 100%;
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
gap: 12px;
|
|
86
|
+
padding: 10px 16px;
|
|
87
|
+
background: transparent;
|
|
88
|
+
border: none;
|
|
89
|
+
color: #94a3b8;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
text-align: left;
|
|
92
|
+
transition: all 0.2s;
|
|
93
|
+
font-size: 14px;
|
|
94
|
+
}
|
|
95
|
+
.kopy-dropdown-item:hover {
|
|
96
|
+
background: rgba(255, 255, 255, 0.05);
|
|
97
|
+
color: white;
|
|
98
|
+
}
|
|
99
|
+
.kopy-dropdown-item.active {
|
|
100
|
+
color: #38bdf8;
|
|
101
|
+
background: rgba(56, 189, 248, 0.05);
|
|
102
|
+
}
|
|
103
|
+
.label {
|
|
104
|
+
flex: 1;
|
|
105
|
+
}
|
|
106
|
+
.flag {
|
|
107
|
+
font-size: 16px;
|
|
108
|
+
}
|
|
109
|
+
@keyframes slideIn {
|
|
110
|
+
from { opacity: 0; transform: translateY(-10px); }
|
|
111
|
+
to { opacity: 1; transform: translateY(0); }
|
|
112
|
+
}
|
|
113
|
+
`]
|
|
114
|
+
})
|
|
115
|
+
export class KopySelectorComponent {
|
|
116
|
+
private kopyService = inject(KopyService);
|
|
117
|
+
|
|
118
|
+
public isOpen = signal(false);
|
|
119
|
+
public languages = this.kopyService.availableLanguages;
|
|
120
|
+
public currentLocale = this.kopyService.currentLocale;
|
|
121
|
+
|
|
122
|
+
private flagMap: Record<string, string> = {
|
|
123
|
+
'en': '🇺🇸',
|
|
124
|
+
'es': '🇪🇸',
|
|
125
|
+
'fr': '🇫🇷',
|
|
126
|
+
'de': '🇩🇪',
|
|
127
|
+
'it': '🇮🇹',
|
|
128
|
+
'pt': '🇵🇹',
|
|
129
|
+
'ja': '🇯🇵',
|
|
130
|
+
'zh': '🇨🇳',
|
|
131
|
+
'ru': '🇷🇺'
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
private nameMap: Record<string, string> = {
|
|
135
|
+
'en': 'English',
|
|
136
|
+
'es': 'Español',
|
|
137
|
+
'fr': 'Français',
|
|
138
|
+
'de': 'Deutsch',
|
|
139
|
+
'it': 'Italiano',
|
|
140
|
+
'pt': 'Português',
|
|
141
|
+
'ja': '日本語',
|
|
142
|
+
'zh': '中文',
|
|
143
|
+
'ru': 'Русский',
|
|
144
|
+
'en-us': 'English (US)'
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
toggleDropdown() {
|
|
148
|
+
this.isOpen.set(!this.isOpen());
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
selectLanguage(lang: string) {
|
|
152
|
+
this.kopyService.setLocale(lang);
|
|
153
|
+
this.isOpen.set(false);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getFlag(lang: string): string {
|
|
157
|
+
const code = lang.split('-')[0].toLowerCase();
|
|
158
|
+
return this.flagMap[code] || '🌐';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
getNativeName(lang: string): string {
|
|
162
|
+
return this.nameMap[lang.toLowerCase()] || lang.toUpperCase();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Injectable, Inject, InjectionToken, signal, NgZone } from '@angular/core';
|
|
2
|
+
import { Kopynator, KopyConfig } from '@kopynator/core';
|
|
3
|
+
|
|
4
|
+
export const KOPY_CONFIG = new InjectionToken<KopyConfig>('KOPY_CONFIG');
|
|
5
|
+
|
|
6
|
+
@Injectable({
|
|
7
|
+
providedIn: 'root'
|
|
8
|
+
})
|
|
9
|
+
export class KopyService {
|
|
10
|
+
private kopy: Kopynator;
|
|
11
|
+
|
|
12
|
+
// Signals for reactivity
|
|
13
|
+
public isReady = signal(false);
|
|
14
|
+
public availableLanguages = signal<string[]>([]);
|
|
15
|
+
public currentLocale = signal<string>('en');
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
@Inject(KOPY_CONFIG) private config: KopyConfig,
|
|
19
|
+
private zone: NgZone
|
|
20
|
+
) {
|
|
21
|
+
const savedLocale = typeof localStorage !== 'undefined' ? localStorage.getItem('kopy_locale') : null;
|
|
22
|
+
const initialLocale = savedLocale || config.defaultLocale || 'en';
|
|
23
|
+
|
|
24
|
+
// Initialize core with the restored or default locale
|
|
25
|
+
this.kopy = new Kopynator({ ...config, defaultLocale: initialLocale });
|
|
26
|
+
this.currentLocale.set(initialLocale);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public async init(): Promise<void> {
|
|
30
|
+
await this.kopy.init();
|
|
31
|
+
|
|
32
|
+
this.zone.run(() => {
|
|
33
|
+
this.availableLanguages.set(this.kopy.getLanguages());
|
|
34
|
+
this.isReady.set(true);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async setLocale(locale: string) {
|
|
39
|
+
await this.kopy.setLocale(locale);
|
|
40
|
+
|
|
41
|
+
if (typeof localStorage !== 'undefined') {
|
|
42
|
+
localStorage.setItem('kopy_locale', locale);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.zone.run(() => {
|
|
46
|
+
this.currentLocale.set(locale);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
translate(key: string, params: Record<string, any> = {}): string {
|
|
51
|
+
return this.kopy.translate(key, params);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getKopynator(): Kopynator {
|
|
55
|
+
return this.kopy;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Provider, provideAppInitializer, inject, EnvironmentProviders } from '@angular/core';
|
|
2
|
+
import { KopyConfig } from '@kopynator/core';
|
|
3
|
+
import { KOPY_CONFIG, KopyService } from './lib/kopy.service';
|
|
4
|
+
|
|
5
|
+
export * from './lib/kopy.service';
|
|
6
|
+
export * from './lib/kopy.pipe';
|
|
7
|
+
export * from './lib/kopy.directive';
|
|
8
|
+
export * from './lib/kopy.selector.component';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Provides the Kopynator SDK configuration to the application.
|
|
12
|
+
*/
|
|
13
|
+
export function provideKopynator(config: KopyConfig): (Provider | EnvironmentProviders)[] {
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
provide: KOPY_CONFIG,
|
|
17
|
+
useValue: config
|
|
18
|
+
},
|
|
19
|
+
KopyService,
|
|
20
|
+
provideAppInitializer(() => {
|
|
21
|
+
const kopyService = inject(KopyService);
|
|
22
|
+
return kopyService.init();
|
|
23
|
+
})
|
|
24
|
+
];
|
|
25
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ES2022",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": ["ES2022", "DOM"],
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"experimentalDecorators": true,
|
|
16
|
+
"emitDecoratorMetadata": true,
|
|
17
|
+
"useDefineForClassFields": false
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*"],
|
|
20
|
+
"exclude": ["node_modules", "dist"]
|
|
21
|
+
}
|
package/dist/public-api.d.mts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as _angular_core from '@angular/core';
|
|
2
|
-
import { InjectionToken, EnvironmentProviders, PipeTransform, ChangeDetectorRef, OnChanges, ElementRef, SimpleChanges } from '@angular/core';
|
|
3
|
-
import { KopyConfig } from '@kopynator/core';
|
|
4
|
-
|
|
5
|
-
declare const KOPY_CONFIG: InjectionToken<KopyConfig>;
|
|
6
|
-
declare class KopyService {
|
|
7
|
-
private config;
|
|
8
|
-
private kopy;
|
|
9
|
-
isReady: _angular_core.WritableSignal<boolean>;
|
|
10
|
-
constructor(config: KopyConfig);
|
|
11
|
-
private init;
|
|
12
|
-
translate(key: string, params?: Record<string, any>): string;
|
|
13
|
-
setLocale(locale: string): Promise<void>;
|
|
14
|
-
t(key: string, params?: Record<string, any>): string;
|
|
15
|
-
}
|
|
16
|
-
declare function provideKopynator(config: KopyConfig): EnvironmentProviders;
|
|
17
|
-
|
|
18
|
-
declare class KopyPipe implements PipeTransform {
|
|
19
|
-
private kopyService;
|
|
20
|
-
private cdr;
|
|
21
|
-
constructor(kopyService: KopyService, cdr: ChangeDetectorRef);
|
|
22
|
-
transform(key: string, params?: Record<string, any>): string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
declare class KopyDirective implements OnChanges {
|
|
26
|
-
private el;
|
|
27
|
-
private kopyService;
|
|
28
|
-
key: string;
|
|
29
|
-
kopyParams: Record<string, any>;
|
|
30
|
-
constructor(el: ElementRef, kopyService: KopyService);
|
|
31
|
-
ngOnChanges(changes: SimpleChanges): void;
|
|
32
|
-
private render;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { KOPY_CONFIG, KopyDirective, KopyPipe, KopyService, provideKopynator };
|
package/dist/public-api.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as _angular_core from '@angular/core';
|
|
2
|
-
import { InjectionToken, EnvironmentProviders, PipeTransform, ChangeDetectorRef, OnChanges, ElementRef, SimpleChanges } from '@angular/core';
|
|
3
|
-
import { KopyConfig } from '@kopynator/core';
|
|
4
|
-
|
|
5
|
-
declare const KOPY_CONFIG: InjectionToken<KopyConfig>;
|
|
6
|
-
declare class KopyService {
|
|
7
|
-
private config;
|
|
8
|
-
private kopy;
|
|
9
|
-
isReady: _angular_core.WritableSignal<boolean>;
|
|
10
|
-
constructor(config: KopyConfig);
|
|
11
|
-
private init;
|
|
12
|
-
translate(key: string, params?: Record<string, any>): string;
|
|
13
|
-
setLocale(locale: string): Promise<void>;
|
|
14
|
-
t(key: string, params?: Record<string, any>): string;
|
|
15
|
-
}
|
|
16
|
-
declare function provideKopynator(config: KopyConfig): EnvironmentProviders;
|
|
17
|
-
|
|
18
|
-
declare class KopyPipe implements PipeTransform {
|
|
19
|
-
private kopyService;
|
|
20
|
-
private cdr;
|
|
21
|
-
constructor(kopyService: KopyService, cdr: ChangeDetectorRef);
|
|
22
|
-
transform(key: string, params?: Record<string, any>): string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
declare class KopyDirective implements OnChanges {
|
|
26
|
-
private el;
|
|
27
|
-
private kopyService;
|
|
28
|
-
key: string;
|
|
29
|
-
kopyParams: Record<string, any>;
|
|
30
|
-
constructor(el: ElementRef, kopyService: KopyService);
|
|
31
|
-
ngOnChanges(changes: SimpleChanges): void;
|
|
32
|
-
private render;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { KOPY_CONFIG, KopyDirective, KopyPipe, KopyService, provideKopynator };
|
package/dist/public-api.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
-
if (decorator = decorators[i])
|
|
23
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
-
if (kind && result) __defProp(target, key, result);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
|
|
29
|
-
// src/public-api.ts
|
|
30
|
-
var public_api_exports = {};
|
|
31
|
-
__export(public_api_exports, {
|
|
32
|
-
KOPY_CONFIG: () => KOPY_CONFIG,
|
|
33
|
-
KopyDirective: () => KopyDirective,
|
|
34
|
-
KopyPipe: () => KopyPipe,
|
|
35
|
-
KopyService: () => KopyService,
|
|
36
|
-
provideKopynator: () => provideKopynator
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(public_api_exports);
|
|
39
|
-
|
|
40
|
-
// src/lib/kopy.service.ts
|
|
41
|
-
var import_core = require("@angular/core");
|
|
42
|
-
var import_core2 = require("@kopynator/core");
|
|
43
|
-
var KOPY_CONFIG = new import_core.InjectionToken("KOPY_CONFIG");
|
|
44
|
-
var KopyService = class {
|
|
45
|
-
constructor(config) {
|
|
46
|
-
this.config = config;
|
|
47
|
-
this.isReady = (0, import_core.signal)(false);
|
|
48
|
-
this.kopy = new import_core2.Kopynator(config);
|
|
49
|
-
this.init();
|
|
50
|
-
}
|
|
51
|
-
async init() {
|
|
52
|
-
await this.kopy.init();
|
|
53
|
-
this.isReady.set(true);
|
|
54
|
-
}
|
|
55
|
-
translate(key, params = {}) {
|
|
56
|
-
return this.kopy.translate(key, params);
|
|
57
|
-
}
|
|
58
|
-
async setLocale(locale) {
|
|
59
|
-
this.isReady.set(false);
|
|
60
|
-
await this.kopy.setLocale(locale);
|
|
61
|
-
this.isReady.set(true);
|
|
62
|
-
}
|
|
63
|
-
t(key, params = {}) {
|
|
64
|
-
return this.translate(key, params);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
KopyService = __decorateClass([
|
|
68
|
-
(0, import_core.Injectable)({
|
|
69
|
-
providedIn: "root"
|
|
70
|
-
}),
|
|
71
|
-
__decorateParam(0, (0, import_core.Inject)(KOPY_CONFIG))
|
|
72
|
-
], KopyService);
|
|
73
|
-
function provideKopynator(config) {
|
|
74
|
-
return (0, import_core.makeEnvironmentProviders)([
|
|
75
|
-
{ provide: KOPY_CONFIG, useValue: config },
|
|
76
|
-
KopyService
|
|
77
|
-
]);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/lib/kopy.pipe.ts
|
|
81
|
-
var import_core3 = require("@angular/core");
|
|
82
|
-
var KopyPipe = class {
|
|
83
|
-
constructor(kopyService, cdr) {
|
|
84
|
-
this.kopyService = kopyService;
|
|
85
|
-
this.cdr = cdr;
|
|
86
|
-
}
|
|
87
|
-
transform(key, params = {}) {
|
|
88
|
-
return this.kopyService.translate(key, params);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
KopyPipe = __decorateClass([
|
|
92
|
-
(0, import_core3.Pipe)({
|
|
93
|
-
name: "kopy",
|
|
94
|
-
pure: false,
|
|
95
|
-
standalone: true
|
|
96
|
-
})
|
|
97
|
-
], KopyPipe);
|
|
98
|
-
|
|
99
|
-
// src/lib/kopy.directive.ts
|
|
100
|
-
var import_core4 = require("@angular/core");
|
|
101
|
-
var KopyDirective = class {
|
|
102
|
-
constructor(el, kopyService) {
|
|
103
|
-
this.el = el;
|
|
104
|
-
this.kopyService = kopyService;
|
|
105
|
-
this.kopyParams = {};
|
|
106
|
-
}
|
|
107
|
-
ngOnChanges(changes) {
|
|
108
|
-
this.render();
|
|
109
|
-
}
|
|
110
|
-
render() {
|
|
111
|
-
if (!this.key) return;
|
|
112
|
-
this.el.nativeElement.textContent = this.kopyService.translate(this.key, this.kopyParams);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
__decorateClass([
|
|
116
|
-
(0, import_core4.Input)("kopy")
|
|
117
|
-
], KopyDirective.prototype, "key", 2);
|
|
118
|
-
__decorateClass([
|
|
119
|
-
(0, import_core4.Input)()
|
|
120
|
-
], KopyDirective.prototype, "kopyParams", 2);
|
|
121
|
-
KopyDirective = __decorateClass([
|
|
122
|
-
(0, import_core4.Directive)({
|
|
123
|
-
selector: "[kopy]",
|
|
124
|
-
standalone: true
|
|
125
|
-
})
|
|
126
|
-
], KopyDirective);
|
|
127
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
128
|
-
0 && (module.exports = {
|
|
129
|
-
KOPY_CONFIG,
|
|
130
|
-
KopyDirective,
|
|
131
|
-
KopyPipe,
|
|
132
|
-
KopyService,
|
|
133
|
-
provideKopynator
|
|
134
|
-
});
|
package/dist/public-api.mjs
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
-
if (decorator = decorators[i])
|
|
7
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
-
if (kind && result) __defProp(target, key, result);
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
11
|
-
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
-
|
|
13
|
-
// src/lib/kopy.service.ts
|
|
14
|
-
import { Injectable, Inject, InjectionToken, signal, makeEnvironmentProviders } from "@angular/core";
|
|
15
|
-
import { Kopynator } from "@kopynator/core";
|
|
16
|
-
var KOPY_CONFIG = new InjectionToken("KOPY_CONFIG");
|
|
17
|
-
var KopyService = class {
|
|
18
|
-
constructor(config) {
|
|
19
|
-
this.config = config;
|
|
20
|
-
this.isReady = signal(false);
|
|
21
|
-
this.kopy = new Kopynator(config);
|
|
22
|
-
this.init();
|
|
23
|
-
}
|
|
24
|
-
async init() {
|
|
25
|
-
await this.kopy.init();
|
|
26
|
-
this.isReady.set(true);
|
|
27
|
-
}
|
|
28
|
-
translate(key, params = {}) {
|
|
29
|
-
return this.kopy.translate(key, params);
|
|
30
|
-
}
|
|
31
|
-
async setLocale(locale) {
|
|
32
|
-
this.isReady.set(false);
|
|
33
|
-
await this.kopy.setLocale(locale);
|
|
34
|
-
this.isReady.set(true);
|
|
35
|
-
}
|
|
36
|
-
t(key, params = {}) {
|
|
37
|
-
return this.translate(key, params);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
KopyService = __decorateClass([
|
|
41
|
-
Injectable({
|
|
42
|
-
providedIn: "root"
|
|
43
|
-
}),
|
|
44
|
-
__decorateParam(0, Inject(KOPY_CONFIG))
|
|
45
|
-
], KopyService);
|
|
46
|
-
function provideKopynator(config) {
|
|
47
|
-
return makeEnvironmentProviders([
|
|
48
|
-
{ provide: KOPY_CONFIG, useValue: config },
|
|
49
|
-
KopyService
|
|
50
|
-
]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// src/lib/kopy.pipe.ts
|
|
54
|
-
import { Pipe } from "@angular/core";
|
|
55
|
-
var KopyPipe = class {
|
|
56
|
-
constructor(kopyService, cdr) {
|
|
57
|
-
this.kopyService = kopyService;
|
|
58
|
-
this.cdr = cdr;
|
|
59
|
-
}
|
|
60
|
-
transform(key, params = {}) {
|
|
61
|
-
return this.kopyService.translate(key, params);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
KopyPipe = __decorateClass([
|
|
65
|
-
Pipe({
|
|
66
|
-
name: "kopy",
|
|
67
|
-
pure: false,
|
|
68
|
-
standalone: true
|
|
69
|
-
})
|
|
70
|
-
], KopyPipe);
|
|
71
|
-
|
|
72
|
-
// src/lib/kopy.directive.ts
|
|
73
|
-
import { Directive, Input } from "@angular/core";
|
|
74
|
-
var KopyDirective = class {
|
|
75
|
-
constructor(el, kopyService) {
|
|
76
|
-
this.el = el;
|
|
77
|
-
this.kopyService = kopyService;
|
|
78
|
-
this.kopyParams = {};
|
|
79
|
-
}
|
|
80
|
-
ngOnChanges(changes) {
|
|
81
|
-
this.render();
|
|
82
|
-
}
|
|
83
|
-
render() {
|
|
84
|
-
if (!this.key) return;
|
|
85
|
-
this.el.nativeElement.textContent = this.kopyService.translate(this.key, this.kopyParams);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
__decorateClass([
|
|
89
|
-
Input("kopy")
|
|
90
|
-
], KopyDirective.prototype, "key", 2);
|
|
91
|
-
__decorateClass([
|
|
92
|
-
Input()
|
|
93
|
-
], KopyDirective.prototype, "kopyParams", 2);
|
|
94
|
-
KopyDirective = __decorateClass([
|
|
95
|
-
Directive({
|
|
96
|
-
selector: "[kopy]",
|
|
97
|
-
standalone: true
|
|
98
|
-
})
|
|
99
|
-
], KopyDirective);
|
|
100
|
-
export {
|
|
101
|
-
KOPY_CONFIG,
|
|
102
|
-
KopyDirective,
|
|
103
|
-
KopyPipe,
|
|
104
|
-
KopyService,
|
|
105
|
-
provideKopynator
|
|
106
|
-
};
|