@kopynator/angular 1.0.3 → 1.0.4

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.
@@ -1,24 +1,25 @@
1
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';
2
+ import { InjectionToken, NgZone, PipeTransform, OnChanges, ElementRef, SimpleChanges, Provider, EnvironmentProviders } from '@angular/core';
3
+ import { KopyConfig, Kopynator } from '@kopynator/core';
4
4
 
5
5
  declare const KOPY_CONFIG: InjectionToken<KopyConfig>;
6
6
  declare class KopyService {
7
7
  private config;
8
+ private zone;
8
9
  private kopy;
9
10
  isReady: _angular_core.WritableSignal<boolean>;
10
- constructor(config: KopyConfig);
11
- private init;
12
- translate(key: string, params?: Record<string, any>): string;
11
+ availableLanguages: _angular_core.WritableSignal<string[]>;
12
+ currentLocale: _angular_core.WritableSignal<string>;
13
+ constructor(config: KopyConfig, zone: NgZone);
14
+ init(): Promise<void>;
13
15
  setLocale(locale: string): Promise<void>;
14
- t(key: string, params?: Record<string, any>): string;
16
+ translate(key: string, params?: Record<string, any>): string;
17
+ getKopynator(): Kopynator;
15
18
  }
16
- declare function provideKopynator(config: KopyConfig): EnvironmentProviders;
17
19
 
18
20
  declare class KopyPipe implements PipeTransform {
19
21
  private kopyService;
20
- private cdr;
21
- constructor(kopyService: KopyService, cdr: ChangeDetectorRef);
22
+ constructor(kopyService: KopyService);
22
23
  transform(key: string, params?: Record<string, any>): string;
23
24
  }
24
25
 
@@ -32,4 +33,22 @@ declare class KopyDirective implements OnChanges {
32
33
  private render;
33
34
  }
34
35
 
35
- export { KOPY_CONFIG, KopyDirective, KopyPipe, KopyService, provideKopynator };
36
+ declare class KopySelectorComponent {
37
+ private kopyService;
38
+ isOpen: _angular_core.WritableSignal<boolean>;
39
+ languages: _angular_core.WritableSignal<string[]>;
40
+ currentLocale: _angular_core.WritableSignal<string>;
41
+ private flagMap;
42
+ private nameMap;
43
+ toggleDropdown(): void;
44
+ selectLanguage(lang: string): void;
45
+ getFlag(lang: string): string;
46
+ getNativeName(lang: string): string;
47
+ }
48
+
49
+ /**
50
+ * Provides the Kopynator SDK configuration to the application.
51
+ */
52
+ declare function provideKopynator(config: KopyConfig): (Provider | EnvironmentProviders)[];
53
+
54
+ export { KOPY_CONFIG, KopyDirective, KopyPipe, KopySelectorComponent, KopyService, provideKopynator };
@@ -1,24 +1,25 @@
1
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';
2
+ import { InjectionToken, NgZone, PipeTransform, OnChanges, ElementRef, SimpleChanges, Provider, EnvironmentProviders } from '@angular/core';
3
+ import { KopyConfig, Kopynator } from '@kopynator/core';
4
4
 
5
5
  declare const KOPY_CONFIG: InjectionToken<KopyConfig>;
6
6
  declare class KopyService {
7
7
  private config;
8
+ private zone;
8
9
  private kopy;
9
10
  isReady: _angular_core.WritableSignal<boolean>;
10
- constructor(config: KopyConfig);
11
- private init;
12
- translate(key: string, params?: Record<string, any>): string;
11
+ availableLanguages: _angular_core.WritableSignal<string[]>;
12
+ currentLocale: _angular_core.WritableSignal<string>;
13
+ constructor(config: KopyConfig, zone: NgZone);
14
+ init(): Promise<void>;
13
15
  setLocale(locale: string): Promise<void>;
14
- t(key: string, params?: Record<string, any>): string;
16
+ translate(key: string, params?: Record<string, any>): string;
17
+ getKopynator(): Kopynator;
15
18
  }
16
- declare function provideKopynator(config: KopyConfig): EnvironmentProviders;
17
19
 
18
20
  declare class KopyPipe implements PipeTransform {
19
21
  private kopyService;
20
- private cdr;
21
- constructor(kopyService: KopyService, cdr: ChangeDetectorRef);
22
+ constructor(kopyService: KopyService);
22
23
  transform(key: string, params?: Record<string, any>): string;
23
24
  }
24
25
 
@@ -32,4 +33,22 @@ declare class KopyDirective implements OnChanges {
32
33
  private render;
33
34
  }
34
35
 
35
- export { KOPY_CONFIG, KopyDirective, KopyPipe, KopyService, provideKopynator };
36
+ declare class KopySelectorComponent {
37
+ private kopyService;
38
+ isOpen: _angular_core.WritableSignal<boolean>;
39
+ languages: _angular_core.WritableSignal<string[]>;
40
+ currentLocale: _angular_core.WritableSignal<string>;
41
+ private flagMap;
42
+ private nameMap;
43
+ toggleDropdown(): void;
44
+ selectLanguage(lang: string): void;
45
+ getFlag(lang: string): string;
46
+ getNativeName(lang: string): string;
47
+ }
48
+
49
+ /**
50
+ * Provides the Kopynator SDK configuration to the application.
51
+ */
52
+ declare function provideKopynator(config: KopyConfig): (Provider | EnvironmentProviders)[];
53
+
54
+ export { KOPY_CONFIG, KopyDirective, KopyPipe, KopySelectorComponent, KopyService, provideKopynator };
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,15 +17,6 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  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
20
 
29
21
  // src/public-api.ts
30
22
  var public_api_exports = {};
@@ -32,77 +24,160 @@ __export(public_api_exports, {
32
24
  KOPY_CONFIG: () => KOPY_CONFIG,
33
25
  KopyDirective: () => KopyDirective,
34
26
  KopyPipe: () => KopyPipe,
27
+ KopySelectorComponent: () => KopySelectorComponent,
35
28
  KopyService: () => KopyService,
36
29
  provideKopynator: () => provideKopynator
37
30
  });
38
31
  module.exports = __toCommonJS(public_api_exports);
32
+ var import_core6 = require("@angular/core");
39
33
 
40
34
  // src/lib/kopy.service.ts
41
35
  var import_core = require("@angular/core");
42
36
  var import_core2 = require("@kopynator/core");
37
+ function _ts_decorate(decorators, target, key, desc) {
38
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
39
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
40
+ 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;
41
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
42
+ }
43
+ __name(_ts_decorate, "_ts_decorate");
44
+ function _ts_metadata(k, v) {
45
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
46
+ }
47
+ __name(_ts_metadata, "_ts_metadata");
48
+ function _ts_param(paramIndex, decorator) {
49
+ return function(target, key) {
50
+ decorator(target, key, paramIndex);
51
+ };
52
+ }
53
+ __name(_ts_param, "_ts_param");
43
54
  var KOPY_CONFIG = new import_core.InjectionToken("KOPY_CONFIG");
44
55
  var KopyService = class {
45
- constructor(config) {
56
+ static {
57
+ __name(this, "KopyService");
58
+ }
59
+ config;
60
+ zone;
61
+ kopy;
62
+ // Signals for reactivity
63
+ isReady = (0, import_core.signal)(false);
64
+ availableLanguages = (0, import_core.signal)([]);
65
+ currentLocale = (0, import_core.signal)("en");
66
+ constructor(config, zone) {
46
67
  this.config = config;
47
- this.isReady = (0, import_core.signal)(false);
48
- this.kopy = new import_core2.Kopynator(config);
49
- this.init();
68
+ this.zone = zone;
69
+ const savedLocale = typeof localStorage !== "undefined" ? localStorage.getItem("kopy_locale") : null;
70
+ const initialLocale = savedLocale || config.defaultLocale || "en";
71
+ this.kopy = new import_core2.Kopynator({
72
+ ...config,
73
+ defaultLocale: initialLocale
74
+ });
75
+ this.currentLocale.set(initialLocale);
50
76
  }
51
77
  async init() {
52
78
  await this.kopy.init();
53
- this.isReady.set(true);
54
- }
55
- translate(key, params = {}) {
56
- return this.kopy.translate(key, params);
79
+ this.zone.run(() => {
80
+ this.availableLanguages.set(this.kopy.getLanguages());
81
+ this.isReady.set(true);
82
+ });
57
83
  }
58
84
  async setLocale(locale) {
59
- this.isReady.set(false);
60
85
  await this.kopy.setLocale(locale);
61
- this.isReady.set(true);
86
+ if (typeof localStorage !== "undefined") {
87
+ localStorage.setItem("kopy_locale", locale);
88
+ }
89
+ this.zone.run(() => {
90
+ this.currentLocale.set(locale);
91
+ });
62
92
  }
63
- t(key, params = {}) {
64
- return this.translate(key, params);
93
+ translate(key, params = {}) {
94
+ return this.kopy.translate(key, params);
95
+ }
96
+ getKopynator() {
97
+ return this.kopy;
65
98
  }
66
99
  };
67
- KopyService = __decorateClass([
100
+ KopyService = _ts_decorate([
68
101
  (0, import_core.Injectable)({
69
102
  providedIn: "root"
70
103
  }),
71
- __decorateParam(0, (0, import_core.Inject)(KOPY_CONFIG))
104
+ _ts_param(0, (0, import_core.Inject)(KOPY_CONFIG)),
105
+ _ts_metadata("design:type", Function),
106
+ _ts_metadata("design:paramtypes", [
107
+ typeof import_core2.KopyConfig === "undefined" ? Object : import_core2.KopyConfig,
108
+ typeof import_core.NgZone === "undefined" ? Object : import_core.NgZone
109
+ ])
72
110
  ], KopyService);
73
- function provideKopynator(config) {
74
- return (0, import_core.makeEnvironmentProviders)([
75
- { provide: KOPY_CONFIG, useValue: config },
76
- KopyService
77
- ]);
78
- }
79
111
 
80
112
  // src/lib/kopy.pipe.ts
81
113
  var import_core3 = require("@angular/core");
114
+ function _ts_decorate2(decorators, target, key, desc) {
115
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
116
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
117
+ 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;
118
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
119
+ }
120
+ __name(_ts_decorate2, "_ts_decorate");
121
+ function _ts_metadata2(k, v) {
122
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
123
+ }
124
+ __name(_ts_metadata2, "_ts_metadata");
82
125
  var KopyPipe = class {
83
- constructor(kopyService, cdr) {
126
+ static {
127
+ __name(this, "KopyPipe");
128
+ }
129
+ kopyService;
130
+ constructor(kopyService) {
84
131
  this.kopyService = kopyService;
85
- this.cdr = cdr;
86
132
  }
87
133
  transform(key, params = {}) {
134
+ const ready = this.kopyService.isReady();
135
+ const locale = this.kopyService.currentLocale();
136
+ if (!ready) return key;
88
137
  return this.kopyService.translate(key, params);
89
138
  }
90
139
  };
91
- KopyPipe = __decorateClass([
140
+ KopyPipe = _ts_decorate2([
92
141
  (0, import_core3.Pipe)({
93
142
  name: "kopy",
94
143
  pure: false,
95
144
  standalone: true
96
- })
145
+ }),
146
+ _ts_metadata2("design:type", Function),
147
+ _ts_metadata2("design:paramtypes", [
148
+ typeof KopyService === "undefined" ? Object : KopyService
149
+ ])
97
150
  ], KopyPipe);
98
151
 
99
152
  // src/lib/kopy.directive.ts
100
153
  var import_core4 = require("@angular/core");
154
+ function _ts_decorate3(decorators, target, key, desc) {
155
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
156
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
157
+ 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;
158
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
159
+ }
160
+ __name(_ts_decorate3, "_ts_decorate");
161
+ function _ts_metadata3(k, v) {
162
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
163
+ }
164
+ __name(_ts_metadata3, "_ts_metadata");
101
165
  var KopyDirective = class {
166
+ static {
167
+ __name(this, "KopyDirective");
168
+ }
169
+ el;
170
+ kopyService;
171
+ key;
172
+ kopyParams = {};
102
173
  constructor(el, kopyService) {
103
174
  this.el = el;
104
175
  this.kopyService = kopyService;
105
- this.kopyParams = {};
176
+ (0, import_core4.effect)(() => {
177
+ this.kopyService.currentLocale();
178
+ this.kopyService.isReady();
179
+ this.render();
180
+ });
106
181
  }
107
182
  ngOnChanges(changes) {
108
183
  this.render();
@@ -112,23 +187,220 @@ var KopyDirective = class {
112
187
  this.el.nativeElement.textContent = this.kopyService.translate(this.key, this.kopyParams);
113
188
  }
114
189
  };
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([
190
+ _ts_decorate3([
191
+ (0, import_core4.Input)("kopy"),
192
+ _ts_metadata3("design:type", String)
193
+ ], KopyDirective.prototype, "key", void 0);
194
+ _ts_decorate3([
195
+ (0, import_core4.Input)(),
196
+ _ts_metadata3("design:type", typeof Record === "undefined" ? Object : Record)
197
+ ], KopyDirective.prototype, "kopyParams", void 0);
198
+ KopyDirective = _ts_decorate3([
122
199
  (0, import_core4.Directive)({
123
200
  selector: "[kopy]",
124
201
  standalone: true
125
- })
202
+ }),
203
+ _ts_metadata3("design:type", Function),
204
+ _ts_metadata3("design:paramtypes", [
205
+ typeof import_core4.ElementRef === "undefined" ? Object : import_core4.ElementRef,
206
+ typeof KopyService === "undefined" ? Object : KopyService
207
+ ])
126
208
  ], KopyDirective);
209
+
210
+ // src/lib/kopy.selector.component.ts
211
+ var import_core5 = require("@angular/core");
212
+ var import_common = require("@angular/common");
213
+ function _ts_decorate4(decorators, target, key, desc) {
214
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
215
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
216
+ 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;
217
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
218
+ }
219
+ __name(_ts_decorate4, "_ts_decorate");
220
+ var KopySelectorComponent = class {
221
+ static {
222
+ __name(this, "KopySelectorComponent");
223
+ }
224
+ kopyService = (0, import_core5.inject)(KopyService);
225
+ isOpen = (0, import_core5.signal)(false);
226
+ languages = this.kopyService.availableLanguages;
227
+ currentLocale = this.kopyService.currentLocale;
228
+ flagMap = {
229
+ "en": "\u{1F1FA}\u{1F1F8}",
230
+ "es": "\u{1F1EA}\u{1F1F8}",
231
+ "fr": "\u{1F1EB}\u{1F1F7}",
232
+ "de": "\u{1F1E9}\u{1F1EA}",
233
+ "it": "\u{1F1EE}\u{1F1F9}",
234
+ "pt": "\u{1F1F5}\u{1F1F9}",
235
+ "ja": "\u{1F1EF}\u{1F1F5}",
236
+ "zh": "\u{1F1E8}\u{1F1F3}",
237
+ "ru": "\u{1F1F7}\u{1F1FA}"
238
+ };
239
+ nameMap = {
240
+ "en": "English",
241
+ "es": "Espa\xF1ol",
242
+ "fr": "Fran\xE7ais",
243
+ "de": "Deutsch",
244
+ "it": "Italiano",
245
+ "pt": "Portugu\xEAs",
246
+ "ja": "\u65E5\u672C\u8A9E",
247
+ "zh": "\u4E2D\u6587",
248
+ "ru": "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
249
+ "en-us": "English (US)"
250
+ };
251
+ toggleDropdown() {
252
+ this.isOpen.set(!this.isOpen());
253
+ }
254
+ selectLanguage(lang) {
255
+ this.kopyService.setLocale(lang);
256
+ this.isOpen.set(false);
257
+ }
258
+ getFlag(lang) {
259
+ const code = lang.split("-")[0].toLowerCase();
260
+ return this.flagMap[code] || "\u{1F310}";
261
+ }
262
+ getNativeName(lang) {
263
+ return this.nameMap[lang.toLowerCase()] || lang.toUpperCase();
264
+ }
265
+ };
266
+ KopySelectorComponent = _ts_decorate4([
267
+ (0, import_core5.Component)({
268
+ selector: "kopy-selector",
269
+ standalone: true,
270
+ imports: [
271
+ import_common.CommonModule
272
+ ],
273
+ template: `
274
+ <div class="kopy-selector-container" [class.open]="isOpen()">
275
+ <button class="kopy-selected-btn" (click)="toggleDropdown()">
276
+ <span class="flag">{{ getFlag(currentLocale()) }}</span>
277
+ <span class="label uppercase">{{ currentLocale() }}</span>
278
+ <svg class="chevron" [class.rotate]="isOpen()" viewBox="0 0 20 20" fill="currentColor">
279
+ <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" />
280
+ </svg>
281
+ </button>
282
+
283
+ <div class="kopy-dropdown" *ngIf="isOpen()">
284
+ <button
285
+ *ngFor="let lang of languages()"
286
+ class="kopy-dropdown-item"
287
+ [class.active]="lang === currentLocale()"
288
+ (click)="selectLanguage(lang)"
289
+ >
290
+ <span class="flag">{{ getFlag(lang) }}</span>
291
+ <span class="label">{{ getNativeName(lang) }}</span>
292
+ </button>
293
+ </div>
294
+ </div>
295
+ `,
296
+ styles: [
297
+ `
298
+ .kopy-selector-container {
299
+ position: relative;
300
+ display: inline-block;
301
+ font-family: inherit;
302
+ }
303
+ .kopy-selected-btn {
304
+ display: flex;
305
+ align-items: center;
306
+ gap: 6px;
307
+ padding: 4px 10px;
308
+ background: rgba(255, 255, 255, 0.05);
309
+ border: 1px solid rgba(255, 255, 255, 0.1);
310
+ border-radius: 99px;
311
+ color: white;
312
+ cursor: pointer;
313
+ transition: all 0.2s;
314
+ font-size: 11px;
315
+ font-weight: 700;
316
+ min-width: 70px;
317
+ justify-content: center;
318
+ }
319
+ .kopy-selected-btn:hover {
320
+ background: rgba(255, 255, 255, 0.1);
321
+ border-color: rgba(255, 255, 255, 0.2);
322
+ }
323
+ .chevron {
324
+ width: 10px;
325
+ height: 10px;
326
+ opacity: 0.5;
327
+ transition: transform 0.2s;
328
+ }
329
+ .chevron.rotate {
330
+ transform: rotate(180deg);
331
+ }
332
+ .kopy-dropdown {
333
+ position: absolute;
334
+ top: 100%;
335
+ right: 0;
336
+ margin-top: 8px;
337
+ background: #1e293b;
338
+ border: 1px solid rgba(255, 255, 255, 0.1);
339
+ border-radius: 12px;
340
+ box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
341
+ overflow: hidden;
342
+ min-width: 140px;
343
+ z-index: 100;
344
+ animation: slideIn 0.2s ease-out;
345
+ }
346
+ .kopy-dropdown-item {
347
+ width: 100%;
348
+ display: flex;
349
+ align-items: center;
350
+ gap: 12px;
351
+ padding: 10px 16px;
352
+ background: transparent;
353
+ border: none;
354
+ color: #94a3b8;
355
+ cursor: pointer;
356
+ text-align: left;
357
+ transition: all 0.2s;
358
+ font-size: 14px;
359
+ }
360
+ .kopy-dropdown-item:hover {
361
+ background: rgba(255, 255, 255, 0.05);
362
+ color: white;
363
+ }
364
+ .kopy-dropdown-item.active {
365
+ color: #38bdf8;
366
+ background: rgba(56, 189, 248, 0.05);
367
+ }
368
+ .label {
369
+ flex: 1;
370
+ }
371
+ .flag {
372
+ font-size: 16px;
373
+ }
374
+ @keyframes slideIn {
375
+ from { opacity: 0; transform: translateY(-10px); }
376
+ to { opacity: 1; transform: translateY(0); }
377
+ }
378
+ `
379
+ ]
380
+ })
381
+ ], KopySelectorComponent);
382
+
383
+ // src/public-api.ts
384
+ function provideKopynator(config) {
385
+ return [
386
+ {
387
+ provide: KOPY_CONFIG,
388
+ useValue: config
389
+ },
390
+ KopyService,
391
+ (0, import_core6.provideAppInitializer)(() => {
392
+ const kopyService = (0, import_core6.inject)(KopyService);
393
+ return kopyService.init();
394
+ })
395
+ ];
396
+ }
397
+ __name(provideKopynator, "provideKopynator");
127
398
  // Annotate the CommonJS export names for ESM import in node:
128
399
  0 && (module.exports = {
129
400
  KOPY_CONFIG,
130
401
  KopyDirective,
131
402
  KopyPipe,
403
+ KopySelectorComponent,
132
404
  KopyService,
133
405
  provideKopynator
134
406
  });
@@ -1,81 +1,156 @@
1
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);
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/public-api.ts
5
+ import { provideAppInitializer, inject as inject2 } from "@angular/core";
12
6
 
13
7
  // src/lib/kopy.service.ts
14
- import { Injectable, Inject, InjectionToken, signal, makeEnvironmentProviders } from "@angular/core";
15
- import { Kopynator } from "@kopynator/core";
8
+ import { Injectable, Inject, InjectionToken, signal, NgZone } from "@angular/core";
9
+ import { Kopynator, KopyConfig } from "@kopynator/core";
10
+ function _ts_decorate(decorators, target, key, desc) {
11
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13
+ 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;
14
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
15
+ }
16
+ __name(_ts_decorate, "_ts_decorate");
17
+ function _ts_metadata(k, v) {
18
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
19
+ }
20
+ __name(_ts_metadata, "_ts_metadata");
21
+ function _ts_param(paramIndex, decorator) {
22
+ return function(target, key) {
23
+ decorator(target, key, paramIndex);
24
+ };
25
+ }
26
+ __name(_ts_param, "_ts_param");
16
27
  var KOPY_CONFIG = new InjectionToken("KOPY_CONFIG");
17
28
  var KopyService = class {
18
- constructor(config) {
29
+ static {
30
+ __name(this, "KopyService");
31
+ }
32
+ config;
33
+ zone;
34
+ kopy;
35
+ // Signals for reactivity
36
+ isReady = signal(false);
37
+ availableLanguages = signal([]);
38
+ currentLocale = signal("en");
39
+ constructor(config, zone) {
19
40
  this.config = config;
20
- this.isReady = signal(false);
21
- this.kopy = new Kopynator(config);
22
- this.init();
41
+ this.zone = zone;
42
+ const savedLocale = typeof localStorage !== "undefined" ? localStorage.getItem("kopy_locale") : null;
43
+ const initialLocale = savedLocale || config.defaultLocale || "en";
44
+ this.kopy = new Kopynator({
45
+ ...config,
46
+ defaultLocale: initialLocale
47
+ });
48
+ this.currentLocale.set(initialLocale);
23
49
  }
24
50
  async init() {
25
51
  await this.kopy.init();
26
- this.isReady.set(true);
27
- }
28
- translate(key, params = {}) {
29
- return this.kopy.translate(key, params);
52
+ this.zone.run(() => {
53
+ this.availableLanguages.set(this.kopy.getLanguages());
54
+ this.isReady.set(true);
55
+ });
30
56
  }
31
57
  async setLocale(locale) {
32
- this.isReady.set(false);
33
58
  await this.kopy.setLocale(locale);
34
- this.isReady.set(true);
59
+ if (typeof localStorage !== "undefined") {
60
+ localStorage.setItem("kopy_locale", locale);
61
+ }
62
+ this.zone.run(() => {
63
+ this.currentLocale.set(locale);
64
+ });
35
65
  }
36
- t(key, params = {}) {
37
- return this.translate(key, params);
66
+ translate(key, params = {}) {
67
+ return this.kopy.translate(key, params);
68
+ }
69
+ getKopynator() {
70
+ return this.kopy;
38
71
  }
39
72
  };
40
- KopyService = __decorateClass([
73
+ KopyService = _ts_decorate([
41
74
  Injectable({
42
75
  providedIn: "root"
43
76
  }),
44
- __decorateParam(0, Inject(KOPY_CONFIG))
77
+ _ts_param(0, Inject(KOPY_CONFIG)),
78
+ _ts_metadata("design:type", Function),
79
+ _ts_metadata("design:paramtypes", [
80
+ typeof KopyConfig === "undefined" ? Object : KopyConfig,
81
+ typeof NgZone === "undefined" ? Object : NgZone
82
+ ])
45
83
  ], KopyService);
46
- function provideKopynator(config) {
47
- return makeEnvironmentProviders([
48
- { provide: KOPY_CONFIG, useValue: config },
49
- KopyService
50
- ]);
51
- }
52
84
 
53
85
  // src/lib/kopy.pipe.ts
54
86
  import { Pipe } from "@angular/core";
87
+ function _ts_decorate2(decorators, target, key, desc) {
88
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
89
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
90
+ 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;
91
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
92
+ }
93
+ __name(_ts_decorate2, "_ts_decorate");
94
+ function _ts_metadata2(k, v) {
95
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
96
+ }
97
+ __name(_ts_metadata2, "_ts_metadata");
55
98
  var KopyPipe = class {
56
- constructor(kopyService, cdr) {
99
+ static {
100
+ __name(this, "KopyPipe");
101
+ }
102
+ kopyService;
103
+ constructor(kopyService) {
57
104
  this.kopyService = kopyService;
58
- this.cdr = cdr;
59
105
  }
60
106
  transform(key, params = {}) {
107
+ const ready = this.kopyService.isReady();
108
+ const locale = this.kopyService.currentLocale();
109
+ if (!ready) return key;
61
110
  return this.kopyService.translate(key, params);
62
111
  }
63
112
  };
64
- KopyPipe = __decorateClass([
113
+ KopyPipe = _ts_decorate2([
65
114
  Pipe({
66
115
  name: "kopy",
67
116
  pure: false,
68
117
  standalone: true
69
- })
118
+ }),
119
+ _ts_metadata2("design:type", Function),
120
+ _ts_metadata2("design:paramtypes", [
121
+ typeof KopyService === "undefined" ? Object : KopyService
122
+ ])
70
123
  ], KopyPipe);
71
124
 
72
125
  // src/lib/kopy.directive.ts
73
- import { Directive, Input } from "@angular/core";
126
+ import { Directive, ElementRef, Input, effect } from "@angular/core";
127
+ function _ts_decorate3(decorators, target, key, desc) {
128
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
129
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
130
+ 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;
131
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
132
+ }
133
+ __name(_ts_decorate3, "_ts_decorate");
134
+ function _ts_metadata3(k, v) {
135
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
136
+ }
137
+ __name(_ts_metadata3, "_ts_metadata");
74
138
  var KopyDirective = class {
139
+ static {
140
+ __name(this, "KopyDirective");
141
+ }
142
+ el;
143
+ kopyService;
144
+ key;
145
+ kopyParams = {};
75
146
  constructor(el, kopyService) {
76
147
  this.el = el;
77
148
  this.kopyService = kopyService;
78
- this.kopyParams = {};
149
+ effect(() => {
150
+ this.kopyService.currentLocale();
151
+ this.kopyService.isReady();
152
+ this.render();
153
+ });
79
154
  }
80
155
  ngOnChanges(changes) {
81
156
  this.render();
@@ -85,22 +160,219 @@ var KopyDirective = class {
85
160
  this.el.nativeElement.textContent = this.kopyService.translate(this.key, this.kopyParams);
86
161
  }
87
162
  };
88
- __decorateClass([
89
- Input("kopy")
90
- ], KopyDirective.prototype, "key", 2);
91
- __decorateClass([
92
- Input()
93
- ], KopyDirective.prototype, "kopyParams", 2);
94
- KopyDirective = __decorateClass([
163
+ _ts_decorate3([
164
+ Input("kopy"),
165
+ _ts_metadata3("design:type", String)
166
+ ], KopyDirective.prototype, "key", void 0);
167
+ _ts_decorate3([
168
+ Input(),
169
+ _ts_metadata3("design:type", typeof Record === "undefined" ? Object : Record)
170
+ ], KopyDirective.prototype, "kopyParams", void 0);
171
+ KopyDirective = _ts_decorate3([
95
172
  Directive({
96
173
  selector: "[kopy]",
97
174
  standalone: true
98
- })
175
+ }),
176
+ _ts_metadata3("design:type", Function),
177
+ _ts_metadata3("design:paramtypes", [
178
+ typeof ElementRef === "undefined" ? Object : ElementRef,
179
+ typeof KopyService === "undefined" ? Object : KopyService
180
+ ])
99
181
  ], KopyDirective);
182
+
183
+ // src/lib/kopy.selector.component.ts
184
+ import { Component, inject, signal as signal2 } from "@angular/core";
185
+ import { CommonModule } from "@angular/common";
186
+ function _ts_decorate4(decorators, target, key, desc) {
187
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
188
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
189
+ 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;
190
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
191
+ }
192
+ __name(_ts_decorate4, "_ts_decorate");
193
+ var KopySelectorComponent = class {
194
+ static {
195
+ __name(this, "KopySelectorComponent");
196
+ }
197
+ kopyService = inject(KopyService);
198
+ isOpen = signal2(false);
199
+ languages = this.kopyService.availableLanguages;
200
+ currentLocale = this.kopyService.currentLocale;
201
+ flagMap = {
202
+ "en": "\u{1F1FA}\u{1F1F8}",
203
+ "es": "\u{1F1EA}\u{1F1F8}",
204
+ "fr": "\u{1F1EB}\u{1F1F7}",
205
+ "de": "\u{1F1E9}\u{1F1EA}",
206
+ "it": "\u{1F1EE}\u{1F1F9}",
207
+ "pt": "\u{1F1F5}\u{1F1F9}",
208
+ "ja": "\u{1F1EF}\u{1F1F5}",
209
+ "zh": "\u{1F1E8}\u{1F1F3}",
210
+ "ru": "\u{1F1F7}\u{1F1FA}"
211
+ };
212
+ nameMap = {
213
+ "en": "English",
214
+ "es": "Espa\xF1ol",
215
+ "fr": "Fran\xE7ais",
216
+ "de": "Deutsch",
217
+ "it": "Italiano",
218
+ "pt": "Portugu\xEAs",
219
+ "ja": "\u65E5\u672C\u8A9E",
220
+ "zh": "\u4E2D\u6587",
221
+ "ru": "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
222
+ "en-us": "English (US)"
223
+ };
224
+ toggleDropdown() {
225
+ this.isOpen.set(!this.isOpen());
226
+ }
227
+ selectLanguage(lang) {
228
+ this.kopyService.setLocale(lang);
229
+ this.isOpen.set(false);
230
+ }
231
+ getFlag(lang) {
232
+ const code = lang.split("-")[0].toLowerCase();
233
+ return this.flagMap[code] || "\u{1F310}";
234
+ }
235
+ getNativeName(lang) {
236
+ return this.nameMap[lang.toLowerCase()] || lang.toUpperCase();
237
+ }
238
+ };
239
+ KopySelectorComponent = _ts_decorate4([
240
+ Component({
241
+ selector: "kopy-selector",
242
+ standalone: true,
243
+ imports: [
244
+ CommonModule
245
+ ],
246
+ template: `
247
+ <div class="kopy-selector-container" [class.open]="isOpen()">
248
+ <button class="kopy-selected-btn" (click)="toggleDropdown()">
249
+ <span class="flag">{{ getFlag(currentLocale()) }}</span>
250
+ <span class="label uppercase">{{ currentLocale() }}</span>
251
+ <svg class="chevron" [class.rotate]="isOpen()" viewBox="0 0 20 20" fill="currentColor">
252
+ <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" />
253
+ </svg>
254
+ </button>
255
+
256
+ <div class="kopy-dropdown" *ngIf="isOpen()">
257
+ <button
258
+ *ngFor="let lang of languages()"
259
+ class="kopy-dropdown-item"
260
+ [class.active]="lang === currentLocale()"
261
+ (click)="selectLanguage(lang)"
262
+ >
263
+ <span class="flag">{{ getFlag(lang) }}</span>
264
+ <span class="label">{{ getNativeName(lang) }}</span>
265
+ </button>
266
+ </div>
267
+ </div>
268
+ `,
269
+ styles: [
270
+ `
271
+ .kopy-selector-container {
272
+ position: relative;
273
+ display: inline-block;
274
+ font-family: inherit;
275
+ }
276
+ .kopy-selected-btn {
277
+ display: flex;
278
+ align-items: center;
279
+ gap: 6px;
280
+ padding: 4px 10px;
281
+ background: rgba(255, 255, 255, 0.05);
282
+ border: 1px solid rgba(255, 255, 255, 0.1);
283
+ border-radius: 99px;
284
+ color: white;
285
+ cursor: pointer;
286
+ transition: all 0.2s;
287
+ font-size: 11px;
288
+ font-weight: 700;
289
+ min-width: 70px;
290
+ justify-content: center;
291
+ }
292
+ .kopy-selected-btn:hover {
293
+ background: rgba(255, 255, 255, 0.1);
294
+ border-color: rgba(255, 255, 255, 0.2);
295
+ }
296
+ .chevron {
297
+ width: 10px;
298
+ height: 10px;
299
+ opacity: 0.5;
300
+ transition: transform 0.2s;
301
+ }
302
+ .chevron.rotate {
303
+ transform: rotate(180deg);
304
+ }
305
+ .kopy-dropdown {
306
+ position: absolute;
307
+ top: 100%;
308
+ right: 0;
309
+ margin-top: 8px;
310
+ background: #1e293b;
311
+ border: 1px solid rgba(255, 255, 255, 0.1);
312
+ border-radius: 12px;
313
+ box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
314
+ overflow: hidden;
315
+ min-width: 140px;
316
+ z-index: 100;
317
+ animation: slideIn 0.2s ease-out;
318
+ }
319
+ .kopy-dropdown-item {
320
+ width: 100%;
321
+ display: flex;
322
+ align-items: center;
323
+ gap: 12px;
324
+ padding: 10px 16px;
325
+ background: transparent;
326
+ border: none;
327
+ color: #94a3b8;
328
+ cursor: pointer;
329
+ text-align: left;
330
+ transition: all 0.2s;
331
+ font-size: 14px;
332
+ }
333
+ .kopy-dropdown-item:hover {
334
+ background: rgba(255, 255, 255, 0.05);
335
+ color: white;
336
+ }
337
+ .kopy-dropdown-item.active {
338
+ color: #38bdf8;
339
+ background: rgba(56, 189, 248, 0.05);
340
+ }
341
+ .label {
342
+ flex: 1;
343
+ }
344
+ .flag {
345
+ font-size: 16px;
346
+ }
347
+ @keyframes slideIn {
348
+ from { opacity: 0; transform: translateY(-10px); }
349
+ to { opacity: 1; transform: translateY(0); }
350
+ }
351
+ `
352
+ ]
353
+ })
354
+ ], KopySelectorComponent);
355
+
356
+ // src/public-api.ts
357
+ function provideKopynator(config) {
358
+ return [
359
+ {
360
+ provide: KOPY_CONFIG,
361
+ useValue: config
362
+ },
363
+ KopyService,
364
+ provideAppInitializer(() => {
365
+ const kopyService = inject2(KopyService);
366
+ return kopyService.init();
367
+ })
368
+ ];
369
+ }
370
+ __name(provideKopynator, "provideKopynator");
100
371
  export {
101
372
  KOPY_CONFIG,
102
373
  KopyDirective,
103
374
  KopyPipe,
375
+ KopySelectorComponent,
104
376
  KopyService,
105
377
  provideKopynator
106
378
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopynator/angular",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "./dist/public-api.js",
5
5
  "module": "./dist/public-api.mjs",
6
6
  "types": "./dist/public-api.d.ts",
@@ -22,13 +22,14 @@
22
22
  "@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0"
23
23
  },
24
24
  "dependencies": {
25
- "@kopynator/core": "1.0.0",
25
+ "@kopynator/core": "^1.0.1",
26
26
  "tslib": "^2.3.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@angular/common": "^21.0.6",
30
30
  "@angular/core": "^21.0.6",
31
31
  "@angular/platform-browser": "^21.0.6",
32
+ "@swc/core": "^1.15.7",
32
33
  "tsup": "^8.0.0",
33
34
  "typescript": "^5.0.0"
34
35
  },