kimu-core 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/.editorconfig +30 -0
  2. package/.gitattributes +11 -0
  3. package/.github/FUNDING.yml +8 -0
  4. package/.github/copilot-instructions.md +103 -0
  5. package/.github/kimu-copilot-instructions.md +3779 -0
  6. package/.github/workflows/deploy-demo.yml +39 -0
  7. package/AUTHORS.md +20 -0
  8. package/CHANGELOG.md +20 -0
  9. package/CODE_GUIDELINES.md +165 -0
  10. package/CODE_OF_CONDUCT.md +47 -0
  11. package/CONTRIBUTING.md +62 -0
  12. package/FUNDING.md +31 -0
  13. package/ISSUE_GUIDELINES.md +74 -0
  14. package/LICENSE +17 -0
  15. package/LICENSE.it.md +17 -0
  16. package/MPL-2.0.txt +373 -0
  17. package/NOTICE +65 -0
  18. package/README-KIMU.md +40 -0
  19. package/README.it.md +208 -0
  20. package/README.md +266 -0
  21. package/SECURITY.md +64 -0
  22. package/docs/get-started-en.md +207 -0
  23. package/docs/images/icon.svg +64 -0
  24. package/docs/images/logo_kimu.png +0 -0
  25. package/docs/index.md +29 -0
  26. package/env/dev.config.json +6 -0
  27. package/env/local.config.json +6 -0
  28. package/env/prod.config.json +6 -0
  29. package/env/staging.config.json +6 -0
  30. package/env/test.config.json +4 -0
  31. package/icon.svg +10 -0
  32. package/logo_kimu.png +0 -0
  33. package/package.json +79 -0
  34. package/public/favicon.svg +64 -0
  35. package/public/logo_kimu.svg +1 -0
  36. package/scripts/build-all-config.js +59 -0
  37. package/scripts/build-all-core.js +65 -0
  38. package/scripts/build-all-extensions.js +64 -0
  39. package/scripts/build-all-modules.js +99 -0
  40. package/scripts/build-extension.js +60 -0
  41. package/scripts/clear-kimu-build.js +31 -0
  42. package/scripts/generate-kimu-build-config.js +79 -0
  43. package/scripts/install-module.js +162 -0
  44. package/scripts/list-modules.js +109 -0
  45. package/scripts/minify-css-assets.js +82 -0
  46. package/scripts/remove-module.js +122 -0
  47. package/scripts/utils/fix-imports.js +85 -0
  48. package/src/assets/index.css +43 -0
  49. package/src/assets/kimu-style.css +84 -0
  50. package/src/assets/style.css +116 -0
  51. package/src/config/kimu-base-config.json +5 -0
  52. package/src/core/index.ts +47 -0
  53. package/src/core/kimu-app.ts +76 -0
  54. package/src/core/kimu-asset-manager.ts +167 -0
  55. package/src/core/kimu-component-element.ts +325 -0
  56. package/src/core/kimu-component.ts +33 -0
  57. package/src/core/kimu-engine.ts +188 -0
  58. package/src/core/kimu-extension-manager.ts +281 -0
  59. package/src/core/kimu-global-styles.ts +136 -0
  60. package/src/core/kimu-module-manager.ts +69 -0
  61. package/src/core/kimu-module.ts +21 -0
  62. package/src/core/kimu-path-config.ts +127 -0
  63. package/src/core/kimu-reactive.ts +196 -0
  64. package/src/core/kimu-render.ts +91 -0
  65. package/src/core/kimu-store.ts +147 -0
  66. package/src/core/kimu-types.ts +65 -0
  67. package/src/extensions/.gitkeep +0 -0
  68. package/src/extensions/extensions-manifest.json +13 -0
  69. package/src/extensions/kimu-home/component.ts +80 -0
  70. package/src/extensions/kimu-home/lang/en.json +5 -0
  71. package/src/extensions/kimu-home/lang/it.json +5 -0
  72. package/src/extensions/kimu-home/style.css +61 -0
  73. package/src/extensions/kimu-home/view.html +51 -0
  74. package/src/index.html +26 -0
  75. package/src/main.ts +68 -0
  76. package/src/modules/.gitkeep +0 -0
  77. package/src/modules/README.md +79 -0
  78. package/src/modules/i18n/README.it.md +63 -0
  79. package/src/modules/i18n/README.md +63 -0
  80. package/src/modules/i18n/kimu-global-lang.ts +26 -0
  81. package/src/modules/i18n/kimu-i18n-service.ts +108 -0
  82. package/src/modules/i18n/manifest.json +22 -0
  83. package/src/modules/i18n/module.ts +39 -0
  84. package/src/modules/modules-manifest.json +12 -0
  85. package/src/modules-repository/README.md +108 -0
  86. package/src/modules-repository/api-axios/CHANGELOG.md +48 -0
  87. package/src/modules-repository/api-axios/QUICK-REFERENCE.md +178 -0
  88. package/src/modules-repository/api-axios/README.md +304 -0
  89. package/src/modules-repository/api-axios/api-axios-service.ts +355 -0
  90. package/src/modules-repository/api-axios/examples.ts +293 -0
  91. package/src/modules-repository/api-axios/index.ts +19 -0
  92. package/src/modules-repository/api-axios/interfaces.ts +71 -0
  93. package/src/modules-repository/api-axios/module.ts +41 -0
  94. package/src/modules-repository/api-core/CHANGELOG.md +42 -0
  95. package/src/modules-repository/api-core/QUICK-REFERENCE.md +192 -0
  96. package/src/modules-repository/api-core/README.md +435 -0
  97. package/src/modules-repository/api-core/api-core-service.ts +289 -0
  98. package/src/modules-repository/api-core/examples.ts +432 -0
  99. package/src/modules-repository/api-core/index.ts +8 -0
  100. package/src/modules-repository/api-core/interfaces.ts +83 -0
  101. package/src/modules-repository/api-core/module.ts +30 -0
  102. package/src/modules-repository/event-bus/README.md +273 -0
  103. package/src/modules-repository/event-bus/event-bus-service.ts +176 -0
  104. package/src/modules-repository/event-bus/module.ts +30 -0
  105. package/src/modules-repository/i18n/README.it.md +63 -0
  106. package/src/modules-repository/i18n/README.md +63 -0
  107. package/src/modules-repository/i18n/kimu-global-lang.ts +26 -0
  108. package/src/modules-repository/i18n/kimu-i18n-service.ts +108 -0
  109. package/src/modules-repository/i18n/manifest.json +22 -0
  110. package/src/modules-repository/i18n/module.ts +39 -0
  111. package/src/modules-repository/notification/README.md +423 -0
  112. package/src/modules-repository/notification/module.ts +30 -0
  113. package/src/modules-repository/notification/notification-service.ts +436 -0
  114. package/src/modules-repository/router/README.it.md +39 -0
  115. package/src/modules-repository/router/README.md +39 -0
  116. package/src/modules-repository/router/manifest.json +21 -0
  117. package/src/modules-repository/router/module.ts +23 -0
  118. package/src/modules-repository/router/router.ts +144 -0
  119. package/src/modules-repository/state/README.md +409 -0
  120. package/src/modules-repository/state/module.ts +30 -0
  121. package/src/modules-repository/state/state-service.ts +296 -0
  122. package/src/modules-repository/theme/README.md +267 -0
  123. package/src/modules-repository/theme/module.ts +30 -0
  124. package/src/modules-repository/theme/pre-build.js +40 -0
  125. package/src/modules-repository/theme/theme-service.ts +389 -0
  126. package/src/modules-repository/theme/themes/theme-cherry-blossom.css +78 -0
  127. package/src/modules-repository/theme/themes/theme-cozy.css +111 -0
  128. package/src/modules-repository/theme/themes/theme-cyberpunk.css +150 -0
  129. package/src/modules-repository/theme/themes/theme-dark.css +79 -0
  130. package/src/modules-repository/theme/themes/theme-forest.css +171 -0
  131. package/src/modules-repository/theme/themes/theme-gold.css +100 -0
  132. package/src/modules-repository/theme/themes/theme-high-contrast.css +126 -0
  133. package/src/modules-repository/theme/themes/theme-lava.css +101 -0
  134. package/src/modules-repository/theme/themes/theme-lavender.css +90 -0
  135. package/src/modules-repository/theme/themes/theme-light.css +79 -0
  136. package/src/modules-repository/theme/themes/theme-matrix.css +103 -0
  137. package/src/modules-repository/theme/themes/theme-midnight.css +81 -0
  138. package/src/modules-repository/theme/themes/theme-nord.css +94 -0
  139. package/src/modules-repository/theme/themes/theme-ocean.css +84 -0
  140. package/src/modules-repository/theme/themes/theme-retro80s.css +343 -0
  141. package/src/modules-repository/theme/themes/theme-sunset.css +62 -0
  142. package/src/modules-repository/theme/themes-config.d.ts +27 -0
  143. package/src/modules-repository/theme/themes-config.json +213 -0
  144. package/src/vite-env.d.ts +1 -0
  145. package/tsconfig.json +33 -0
  146. package/vite.config.ts +99 -0
@@ -0,0 +1,51 @@
1
+ <!--
2
+ This file can be freely modified by developers.
3
+ Changes made to this page are not subject to the publication requirement of the MPL framework license.
4
+ -->
5
+
6
+ <div class="container">
7
+ <div class="logo" >
8
+ <img src="/logo_kimu.svg" alt="KIMU logo" style="width: 256px;" />
9
+ </div>
10
+
11
+ <h2 class="slogan">${slogan}</h2>
12
+
13
+ <h1>KIMU Home</h1>
14
+
15
+ <p class="welcome">${translate('welcome') || 'Hello World!'}</p>
16
+
17
+ <p class="lang">
18
+ <span>${translate('selectedLanguage')}</span> <strong>${selectedLang}</strong>
19
+ </p>
20
+
21
+ <div class="btn-lang">
22
+ <button @click=${onLangIt}>🇮🇹 Italiano</button>
23
+ <button @click=${onLangEn}>🇬🇧 English</button>
24
+ </div>
25
+ <footer class="kimu-footer">
26
+ <small>
27
+ Made with
28
+ <img src="/favicon.svg" alt="favicon KIMU" width="18" height="18" style="vertical-align: middle; margin: 0 2px; filter: grayscale(1) brightness(0.7);" />
29
+ <a href="https://github.com/UnicoVerso/kimu-core" target="_blank" rel="noopener">KIMU Framework</a>
30
+ v${version}
31
+ &middot;
32
+ by
33
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" style="vertical-align: middle; margin-right: 2px;">
34
+ <rect width="16" height="16" rx="3" fill="#fff"/>
35
+ <path d="M3 5.5V10.5C3 11.0523 3.44772 11.5 4 11.5H12C12.5523 11.5 13 11.0523 13 10.5V5.5C13 4.94772 12.5523 4.5 12 4.5H4C3.44772 4.5 3 4.94772 3 5.5ZM4 5.5L8 8.5L12 5.5"
36
+ stroke="#888" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
37
+ </svg>
38
+ <a href="mailto:info@unicoverso.com" title="Email">Marco Di Pasquale</a>
39
+ &middot;
40
+ <svg width="12" height="12" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" style="vertical-align: middle; margin-right: 4px;">
41
+ <rect width="16" height="16" rx="3" fill="#fff"/>
42
+ <circle cx="8" cy="8" r="7" fill="#f5f5f5" stroke="#888" stroke-width="1.2"/>
43
+ <ellipse cx="8" cy="8" rx="5.5" ry="7" stroke="#888" stroke-width="1" fill="none"/>
44
+ <ellipse cx="8" cy="8" rx="7" ry="3.5" stroke="#888" stroke-width="1" fill="none"/>
45
+ <path d="M8 1v14" stroke="#888" stroke-width="1" stroke-linecap="round"/>
46
+ <path d="M1 8h14" stroke="#888" stroke-width="1" stroke-linecap="round"/>
47
+ </svg>
48
+ <a href="https://unicoverso.com" target="_blank" rel="noopener">UnicòVerso</a>
49
+ </small>
50
+ </footer>
51
+ </div>
package/src/index.html ADDED
@@ -0,0 +1,26 @@
1
+ <!--
2
+ This file can be freely modified by developers.
3
+ Changes made to this page are not subject to the publication requirement of the MPL framework license.
4
+ -->
5
+ <!doctype html>
6
+ <html lang="en">
7
+ <head>
8
+ <meta charset="UTF-8" />
9
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
10
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
11
+ <link rel="stylesheet" href="/assets/style.css">
12
+ <link rel="stylesheet" href="/assets/kimu-style.css">
13
+ <script type="importmap">
14
+ {
15
+ "imports": {
16
+ "lit": "https://cdn.skypack.dev/lit@3.2.1"
17
+ }
18
+ }
19
+ </script>
20
+ <title>Kimu App</title>
21
+ </head>
22
+ <body>
23
+ <div id="app"></div>
24
+ <script type="module" src="/main.ts"></script>
25
+ </body>
26
+ </html>
package/src/main.ts ADDED
@@ -0,0 +1,68 @@
1
+ import { KimuExtensionManager } from './core/kimu-extension-manager';
2
+ import { KimuApp } from './core/kimu-app';
3
+ import { KimuPathConfig } from './core/kimu-path-config';
4
+
5
+ /**
6
+ * This code initializes the Kimu framework and mounts the main application interface.
7
+ * It handles the setup of the core system, loads extensions, and dynamically mounts the main app component.
8
+ *
9
+ * Key functionalities:
10
+ * - Initializes the Kimu system and retrieves the global configuration.
11
+ * - Loads the list of available extensions and initializes the extension manager.
12
+ * - Dynamically mounts the main application component (`kimu-app`) to the DOM.
13
+ * - Handles errors during initialization and ensures the application is properly set up.
14
+ */
15
+ async function main() {
16
+ try {
17
+ console.log('[MAIN] Starting KIMU-App interface');
18
+
19
+ // Initialize path configuration FIRST (before any resource loading)
20
+ KimuPathConfig.initialize();
21
+
22
+ // Make KimuPathConfig globally available for testing
23
+ (window as any).KimuPathConfig = KimuPathConfig;
24
+
25
+ // Initialize the Kimu system
26
+ let kimuApp = await KimuApp.getInstance();
27
+ console.log("[Kimu] version: ", kimuApp.version);
28
+ console.log("[Kimu] environment: ", kimuApp.environment);
29
+ console.log("[Kimu] base-path: ", KimuPathConfig.getBasePath());
30
+
31
+ // Initialize extension manager and the list of available extensions in /extensions
32
+ const kimuExtensionManager = KimuExtensionManager.getInstance();
33
+ await kimuExtensionManager.init();
34
+
35
+ // Mount the main app
36
+ const root = document.getElementById('app');
37
+ if (!root) {
38
+ console.error('[MAIN] ❌ Error initializing KIMU-App. Element #app not found in the DOM!');
39
+ return;
40
+ }
41
+
42
+ // Mount the extensions
43
+ // Load the main component of the Kimu application
44
+ // The main component is the one that has the tag name 'kimu-home'
45
+ console.log('[KIMU-MAIN] 🚀 Loading kimu-home extension...');
46
+ const mainAppExtensions = 'kimu-home';
47
+
48
+ try {
49
+ await kimuExtensionManager.load(mainAppExtensions);
50
+
51
+ // Create and mount the main component
52
+ const mainComponent = document.createElement(mainAppExtensions);
53
+ root.appendChild(mainComponent);
54
+
55
+ console.log('[KIMU-MAIN] ✅ Extension loaded and mounted successfully');
56
+ } catch (loadError) {
57
+ console.error('[KIMU-MAIN] ❌ Error loading extension:', loadError);
58
+ throw loadError;
59
+ }
60
+
61
+ console.log('[KIMU-MAIN] ✅ KIMU APP initialized successfully');
62
+ } catch (error) {
63
+ console.error('[KIMU-MAIN] ❌ Error during initialization:', error);
64
+ }
65
+ }
66
+
67
+ // Start the application
68
+ main();
File without changes
@@ -0,0 +1,79 @@
1
+ # KIMU Active Modules
2
+
3
+ This directory contains **installed modules** that are included in the build.
4
+
5
+ ## 📦 What's Here
6
+
7
+ Only modules that have been explicitly installed using:
8
+ ```bash
9
+ npm run install:module <module-name>
10
+ ```
11
+
12
+ ## Current Status
13
+
14
+ Check installed modules:
15
+ ```bash
16
+ npm run list:modules
17
+ ```
18
+
19
+ ## How It Works
20
+
21
+ ### Installation Process
22
+ 1. Module is **copied** from `src/modules-repository/<module-name>/`
23
+ 2. Files appear in this directory: `src/modules/<module-name>/`
24
+ 3. Module is registered in `modules-manifest.json`
25
+ 4. Module is included in next build
26
+
27
+ ### Removal Process
28
+ 1. Module directory is **deleted** from `src/modules/<module-name>/`
29
+ 2. Module is removed from `modules-manifest.json`
30
+ 3. Module is excluded from next build
31
+ 4. Module remains available in `modules-repository` for reinstallation
32
+
33
+ ## modules-manifest.json
34
+
35
+ This file tracks all installed modules:
36
+
37
+ ```json
38
+ {
39
+ "installedModules": [
40
+ {
41
+ "name": "i18n",
42
+ "version": "1.0.0",
43
+ "path": "i18n",
44
+ "installedAt": "2025-01-17T00:00:00.000Z"
45
+ }
46
+ ],
47
+ "availableModules": [],
48
+ "lastUpdate": "2025-01-17T00:00:00.000Z"
49
+ }
50
+ ```
51
+
52
+ ## Best Practices
53
+
54
+ - ✅ **Commit `modules-manifest.json`** to track which modules your project uses
55
+ - ✅ **Install only needed modules** to keep build size minimal
56
+ - ❌ **Don't manually edit module files** - changes will be lost on reinstall
57
+ - ❌ **Don't manually modify `modules-manifest.json`** - use provided scripts
58
+
59
+ ## Commands
60
+
61
+ ```bash
62
+ # List modules
63
+ npm run list:modules
64
+
65
+ # Install a module
66
+ npm run install:module router
67
+
68
+ # Remove a module
69
+ npm run remove:module router
70
+
71
+ # Build with current modules
72
+ npm run build
73
+ ```
74
+
75
+ ## See Also
76
+
77
+ - [Module Management Guide](../../docs/MODULE_MANAGEMENT.md)
78
+ - [Available Modules](../modules-repository/README.md)
79
+ - [Main Documentation](../../README.md)
@@ -0,0 +1,63 @@
1
+ # Kimu I18n Module
2
+
3
+ Il modulo `i18n` di kimu-core fornisce un sistema di internazionalizzazione (internationalization) per applicazioni ed estensioni basate su kimu-core. Permette di gestire facilmente interfacce multilingua, traduzioni di stringhe e cambio dinamico della lingua.
4
+
5
+ ## Scopo
6
+ - Abilitare la localizzazione di tutte le stringhe visibili all’utente.
7
+ - Gestire più lingue in modo centralizzato e modulare.
8
+ - Fornire API semplici per accedere alle traduzioni e cambiare lingua a runtime.
9
+
10
+ ## Struttura del modulo
11
+ ```
12
+ src/modules/i18n/
13
+ ├── kimu-i18n-service.ts # Servizio principale per traduzioni e gestione lingua
14
+ ├── kimu-global-lang.ts # Definizione delle lingue globali e risorse
15
+ ├── module.ts # Esportazione del modulo come KimuModule
16
+ └── README.md # Questa documentazione
17
+ ```
18
+
19
+ ## Come funziona
20
+ - Il servizio `KimuI18nService` gestisce la lingua corrente e fornisce il metodo `translate(key)` per ottenere la stringa tradotta.
21
+ - Le risorse delle lingue sono definite in oggetti o file separati (es. `en`, `it`, ecc.).
22
+ - È possibile cambiare lingua a runtime e aggiornare dinamicamente l’interfaccia.
23
+
24
+ ## Utilizzo base
25
+ ```typescript
26
+ import I18nModule from 'src/modules/i18n/module';
27
+
28
+ // Istanzia il modulo e imposta la lingua di default
29
+ const i18nModule = new I18nModule('i18n', '1.0.0', { lang: 'it' });
30
+ const i18n = i18nModule.getService();
31
+
32
+ // Traduci una chiave
33
+ console.log(i18n.translate('hello'));
34
+
35
+ // Cambia lingua
36
+ i18n.setLang('en');
37
+ ```
38
+
39
+ ## Integrazione in un’estensione
40
+ ```typescript
41
+ // Nel componente
42
+ getData() {
43
+ return {
44
+ translate: this.i18n.translate,
45
+ // ...altri dati
46
+ };
47
+ }
48
+ // Nel template HTML: <span>${translate('welcome')}</span>
49
+ ```
50
+
51
+ ## Best practice
52
+ - Definisci tutte le stringhe utente tramite chiavi, mai testo hardcoded.
53
+ - Mantieni le risorse delle lingue aggiornate e documentate.
54
+ - Fornisci sempre l’inglese come fallback.
55
+ - Documenta come aggiungere nuove lingue.
56
+
57
+ ## Vantaggi
58
+ - UI multilingua pronta all’uso.
59
+ - Cambi di lingua reattivi e centralizzati.
60
+ - Facilmente estendibile per nuove lingue o domini.
61
+
62
+ ---
63
+ Autore: UnicoVerso
@@ -0,0 +1,63 @@
1
+ # Kimu I18n Module
2
+
3
+ The `i18n` module in kimu-core provides an internationalization system for kimu-core-based applications and extensions. It allows you to easily manage multilingual interfaces, string translations, and dynamic language switching.
4
+
5
+ ## Purpose
6
+ - Enable localization of all user-visible strings.
7
+ - Manage multiple languages in a centralized and modular way.
8
+ - Provide simple APIs to access translations and change language at runtime.
9
+
10
+ ## Module Structure
11
+ ```
12
+ src/modules/i18n/
13
+ ├── kimu-i18n-service.ts # Main service for translations and language management
14
+ ├── kimu-global-lang.ts # Definition of global languages and resources
15
+ ├── module.ts # Module export as KimuModule
16
+ └── README.md # This documentation
17
+ ```
18
+
19
+ ## How it works
20
+ - The `KimuI18nService` manages the current language and provides the `translate(key)` method to get the translated string.
21
+ - Language resources are defined in separate objects or files (e.g., `en`, `it`, etc.).
22
+ - You can change language at runtime and dynamically update the interface.
23
+
24
+ ## Basic usage
25
+ ```typescript
26
+ import I18nModule from 'src/modules/i18n/module';
27
+
28
+ // Instantiate the module and set the default language
29
+ const i18nModule = new I18nModule('i18n', '1.0.0', { lang: 'it' });
30
+ const i18n = i18nModule.getService();
31
+
32
+ // Translate a key
33
+ console.log(i18n.translate('hello'));
34
+
35
+ // Change language
36
+ i18n.setLang('en');
37
+ ```
38
+
39
+ ## Integration in an extension
40
+ ```typescript
41
+ // In the component
42
+ getData() {
43
+ return {
44
+ translate: this.i18n.translate,
45
+ // ...other data
46
+ };
47
+ }
48
+ // In the HTML template: <span>${translate('welcome')}</span>
49
+ ```
50
+
51
+ ## Best practices
52
+ - Define all user strings using keys, never hardcoded text.
53
+ - Keep language resources updated and documented.
54
+ - Always provide English as a fallback.
55
+ - Document how to add new languages.
56
+
57
+ ## Advantages
58
+ - Ready-to-use multilingual UI.
59
+ - Reactive and centralized language changes.
60
+ - Easily extendable for new languages or domains.
61
+
62
+ ---
63
+ Author: UnicoVerso
@@ -0,0 +1,26 @@
1
+ export type LangChangeCallback = (lang: string) => void;
2
+
3
+ export class KimuGlobalLang {
4
+ private static currentLang: string = 'it';
5
+ private static listeners: LangChangeCallback[] = [];
6
+
7
+ static set(lang: string) {
8
+ //console.log(`[KimuGlobalLang] set language: ${lang}`);
9
+ if (lang !== this.currentLang) {
10
+ this.currentLang = lang;
11
+ this.listeners.forEach(fn => fn(lang));
12
+ }
13
+ }
14
+
15
+ static get(): string {
16
+ return this.currentLang;
17
+ }
18
+
19
+ static onChange(cb: LangChangeCallback) {
20
+ this.listeners.push(cb);
21
+ }
22
+
23
+ static off(cb: LangChangeCallback) {
24
+ this.listeners = this.listeners.filter(fn => fn !== cb);
25
+ }
26
+ }
@@ -0,0 +1,108 @@
1
+ import { KimuExtensionLanguages } from '../../core/kimu-types';
2
+
3
+ /**
4
+ * KimuI18nService provides internationalization support for Kimu extensions.
5
+ * It loads translation files, manages language switching, and supports parameterized translations.
6
+ */
7
+ export class KimuI18nService {
8
+ private lang: string;
9
+ private translations: Record<string, string> = {};
10
+ private basePath: string;
11
+ private languages: KimuExtensionLanguages;
12
+
13
+ /**
14
+ * Creates a new I18n service instance.
15
+ * @param defaultLang The default language code (e.g. 'it').
16
+ * @param basePath The base path for language files.
17
+ * @param languages Optional: supported languages metadata. If not provided, fallback to default only.
18
+ */
19
+ constructor(defaultLang: string = 'it', basePath: string = './lang', languages?: KimuExtensionLanguages | null) {
20
+ this.lang = defaultLang;
21
+ this.basePath = basePath;
22
+ // If languages is not defined, fallback to only the initial language
23
+ this.languages = languages ?? {
24
+ default: defaultLang,
25
+ supported: {
26
+ [defaultLang]: { code: defaultLang },
27
+ },
28
+ };
29
+ // Use requested language only if supported, otherwise fallback to default
30
+ this.lang = this.resolveLang(defaultLang);
31
+ // Always bind translate to this instance
32
+ this.translate = this.translate.bind(this);
33
+ }
34
+
35
+ /**
36
+ * Returns the effective language to use (fallbacks to default if not supported).
37
+ * @param lang Requested language code.
38
+ */
39
+ private resolveLang(lang: string): string {
40
+ if (this.languages.supported[lang]) return lang;
41
+ return this.languages.default;
42
+ }
43
+
44
+ /**
45
+ * Changes the current language and loads the corresponding translation file.
46
+ * Returns a promise that resolves when the file is loaded.
47
+ * @param lang Language code to set.
48
+ */
49
+ async setLang(lang: string) {
50
+ this.lang = this.resolveLang(lang);
51
+ return await this.loadLang();
52
+ }
53
+
54
+ /**
55
+ * Returns the current language code for the extension.
56
+ */
57
+ getLang(): string {
58
+ return this.lang;
59
+ }
60
+
61
+ /**
62
+ * Loads the translation file for the current language.
63
+ * Uses the language metadata if available, otherwise defaults to <lang>.json.
64
+ * Returns a promise that resolves when the file is loaded.
65
+ */
66
+ async loadLang(): Promise<void> {
67
+ const langMeta = this.languages.supported[this.lang];
68
+ // Use custom file name if provided, otherwise default to <lang>.json
69
+ const file = langMeta.file || `${this.lang}.json`;
70
+ const url = `${this.basePath}/${file}`;
71
+ return await this.loadFromUrl(url);
72
+ }
73
+
74
+ /**
75
+ * Loads translations from a given URL (internal or external).
76
+ * If the file is not found or invalid, falls back to an empty translation object.
77
+ * @param url The URL to fetch the translation file from.
78
+ */
79
+ async loadFromUrl(url: string): Promise<void> {
80
+ try {
81
+ const res = await fetch(url);
82
+ if (!res.ok) {
83
+ throw new Error(`Lang file not found: ${url}`);
84
+ }
85
+ this.translations = await res.json();
86
+ } catch (err) {
87
+ console.warn(`[KimuI18nService] ERROR: ${err}`);
88
+ this.translations = {}; // fallback to empty translations
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Translates a key using the loaded translations.
94
+ * Supports optional parameters identified by {{param}} in the translation string.
95
+ * If the key is not found, returns the key itself.
96
+ * @param key The translation key.
97
+ * @param params Optional: parameters to replace in the translation string.
98
+ */
99
+ translate(key: string, params?: Record<string, any>): string {
100
+ let value = this.translations[key] || key;
101
+ if (params) {
102
+ for (const [k, v] of Object.entries(params)) {
103
+ value = value.replace(new RegExp(`{{${k}}}`, 'g'), v);
104
+ }
105
+ }
106
+ return value;
107
+ }
108
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "i18n",
3
+ "version": "1.0.0",
4
+ "description": "Internationalization module for KIMU applications with multi-language support and dynamic translation system",
5
+ "author": "KIMU Team",
6
+ "license": "MPL-2.0",
7
+ "dependencies": [],
8
+ "kimuCoreVersion": "^0.3.0",
9
+ "keywords": [
10
+ "i18n",
11
+ "internationalization",
12
+ "localization",
13
+ "translation",
14
+ "multilingual",
15
+ "language"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/UnicoVerso/kimu-core",
20
+ "directory": "src/modules/i18n"
21
+ }
22
+ }
@@ -0,0 +1,39 @@
1
+ import { KimuModule } from '../../core/kimu-module';
2
+ import { KimuModuleOptions } from '../../core/kimu-types';
3
+ import { KimuGlobalLang } from './kimu-global-lang';
4
+ import { KimuI18nService } from './kimu-i18n-service';
5
+
6
+ export default class I18nModule extends KimuModule {
7
+ private static instance: I18nModule | null = null;
8
+ private globalLang: typeof KimuGlobalLang;
9
+ private service: KimuI18nService;
10
+
11
+ constructor(name: string, version: string, options?: KimuModuleOptions & { basePath?: string; languages?: any }) {
12
+ super(name, version, options);
13
+ this.singleton = true; // Marca come singleton
14
+ this.globalLang = KimuGlobalLang;
15
+ this.service = new KimuI18nService(
16
+ options?.lang || 'it',
17
+ options?.basePath || './lang',
18
+ options?.languages
19
+ );
20
+ }
21
+
22
+ static getInstance(options?: KimuModuleOptions & { basePath?: string; languages?: any }): I18nModule {
23
+ if (!I18nModule.instance) {
24
+ I18nModule.instance = new I18nModule('i18n', '1.0.0', options);
25
+ }
26
+ return I18nModule.instance;
27
+ }
28
+
29
+ getService(): KimuI18nService {
30
+ return this.service;
31
+ }
32
+
33
+ getGlobalLang(): typeof KimuGlobalLang {
34
+ return this.globalLang;
35
+ }
36
+ }
37
+
38
+ // Export direct access to services (for optimized extension usage)
39
+ export { KimuGlobalLang, KimuI18nService };
@@ -0,0 +1,12 @@
1
+ {
2
+ "installedModules": [
3
+ {
4
+ "name": "i18n",
5
+ "version": "1.0.0",
6
+ "path": "i18n",
7
+ "installedAt": "2025-01-17T00:00:00.000Z"
8
+ }
9
+ ],
10
+ "availableModules": [],
11
+ "lastUpdate": "2025-11-04T13:37:31.093Z"
12
+ }
@@ -0,0 +1,108 @@
1
+ # KIMU Modules Repository
2
+
3
+ This directory contains **available modules** that can be installed in KIMU applications.
4
+
5
+ ## ⚠️ Important Rules
6
+
7
+ 1. **DO NOT modify files in this directory** - This is the central repository
8
+ 2. **DO NOT import from this directory** - Use `src/modules/` instead
9
+ 3. **To use a module**, install it first: `npm run install:module <module-name>`
10
+
11
+ ## 📁 Location
12
+
13
+ This repository is located in `src/modules-repository/` to ensure:
14
+ - ✅ Correct TypeScript import paths
15
+ - ✅ IDE autocompletion and type checking
16
+ - ✅ No compilation errors during module development
17
+ - ✅ Automatic exclusion from build via tree-shaking
18
+
19
+ ## How it works
20
+
21
+ ### Installation
22
+ When you install a module (e.g., `npm run install:module router`):
23
+ 1. The module is **copied** from `src/modules-repository/router/` to `src/modules/router/`
24
+ 2. The module becomes part of the build
25
+ 3. You can import and use it in your application
26
+
27
+ ### Uninstallation
28
+ When you remove a module (e.g., `npm run remove:module router`):
29
+ 1. The module is **deleted** from `src/modules/router/`
30
+ 2. The module is excluded from the build
31
+ 3. It remains available in `src/modules-repository/` for future reinstallation
32
+
33
+ ### Repository Structure
34
+ ```
35
+ src/modules-repository/
36
+ ├── router/
37
+ │ ├── manifest.json # Module metadata and dependencies
38
+ │ ├── module.ts # Module class (entry point)
39
+ │ ├── router.ts # Service implementation
40
+ │ ├── README.md # English documentation
41
+ │ └── README.it.md # Italian documentation
42
+ └── i18n/
43
+ ├── manifest.json
44
+ ├── module.ts
45
+ ├── i18n-service.ts
46
+ ├── README.md
47
+ └── README.it.md
48
+ ```
49
+
50
+ ## Adding New Modules
51
+
52
+ 1. Create a folder with the module name in `src/modules-repository/`
53
+ 2. Add required files:
54
+ - `manifest.json` - Module metadata, dependencies, and compatibility
55
+ - `module.ts` - Main module class extending `KimuModule`
56
+ - Service implementation files
57
+ - `README.md` - English documentation
58
+ - `README.it.md` (optional) - Italian documentation
59
+ 3. Use standard import paths (they will work correctly from this location)
60
+
61
+ ## Available Modules
62
+
63
+ ### Router Module
64
+ **Location:** `router/`
65
+ **Version:** 1.0.0
66
+ **Description:** Client-side routing module for KIMU applications with History API support
67
+
68
+ **Install:**
69
+ ```bash
70
+ npm run install:module router
71
+ ```
72
+
73
+ **Usage after installation:**
74
+ ```typescript
75
+ import RouterModule from './modules/router/module';
76
+
77
+ const router = new RouterModule();
78
+ const routerService = router.getService();
79
+
80
+ routerService.addRoute('/', () => console.log('Home'));
81
+ routerService.navigate('/');
82
+ ```
83
+
84
+ ## Commands Reference
85
+
86
+ ```bash
87
+ # List all available and installed modules
88
+ npm run list:modules
89
+
90
+ # Install a module from repository
91
+ npm run install:module <module-name>
92
+
93
+ # Remove an installed module
94
+ npm run remove:module <module-name>
95
+ ```
96
+
97
+ ## Build Behavior
98
+
99
+ Modules in `src/modules-repository/` are **automatically excluded** from the build because:
100
+ - They are never imported by the main application
101
+ - Vite's tree-shaking removes unused code
102
+ - Only modules in `src/modules/` (installed) are included in the final bundle
103
+
104
+ ## See Also
105
+
106
+ - [Module Management Guide](../../docs/MODULE_MANAGEMENT.md)
107
+ - [Creating Extensions](../../docs/EXTENSIONS.md)
108
+ - [Main Documentation](../../README.md)