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.
- package/.editorconfig +30 -0
- package/.gitattributes +11 -0
- package/.github/FUNDING.yml +8 -0
- package/.github/copilot-instructions.md +103 -0
- package/.github/kimu-copilot-instructions.md +3779 -0
- package/.github/workflows/deploy-demo.yml +39 -0
- package/AUTHORS.md +20 -0
- package/CHANGELOG.md +20 -0
- package/CODE_GUIDELINES.md +165 -0
- package/CODE_OF_CONDUCT.md +47 -0
- package/CONTRIBUTING.md +62 -0
- package/FUNDING.md +31 -0
- package/ISSUE_GUIDELINES.md +74 -0
- package/LICENSE +17 -0
- package/LICENSE.it.md +17 -0
- package/MPL-2.0.txt +373 -0
- package/NOTICE +65 -0
- package/README-KIMU.md +40 -0
- package/README.it.md +208 -0
- package/README.md +266 -0
- package/SECURITY.md +64 -0
- package/docs/get-started-en.md +207 -0
- package/docs/images/icon.svg +64 -0
- package/docs/images/logo_kimu.png +0 -0
- package/docs/index.md +29 -0
- package/env/dev.config.json +6 -0
- package/env/local.config.json +6 -0
- package/env/prod.config.json +6 -0
- package/env/staging.config.json +6 -0
- package/env/test.config.json +4 -0
- package/icon.svg +10 -0
- package/logo_kimu.png +0 -0
- package/package.json +79 -0
- package/public/favicon.svg +64 -0
- package/public/logo_kimu.svg +1 -0
- package/scripts/build-all-config.js +59 -0
- package/scripts/build-all-core.js +65 -0
- package/scripts/build-all-extensions.js +64 -0
- package/scripts/build-all-modules.js +99 -0
- package/scripts/build-extension.js +60 -0
- package/scripts/clear-kimu-build.js +31 -0
- package/scripts/generate-kimu-build-config.js +79 -0
- package/scripts/install-module.js +162 -0
- package/scripts/list-modules.js +109 -0
- package/scripts/minify-css-assets.js +82 -0
- package/scripts/remove-module.js +122 -0
- package/scripts/utils/fix-imports.js +85 -0
- package/src/assets/index.css +43 -0
- package/src/assets/kimu-style.css +84 -0
- package/src/assets/style.css +116 -0
- package/src/config/kimu-base-config.json +5 -0
- package/src/core/index.ts +47 -0
- package/src/core/kimu-app.ts +76 -0
- package/src/core/kimu-asset-manager.ts +167 -0
- package/src/core/kimu-component-element.ts +325 -0
- package/src/core/kimu-component.ts +33 -0
- package/src/core/kimu-engine.ts +188 -0
- package/src/core/kimu-extension-manager.ts +281 -0
- package/src/core/kimu-global-styles.ts +136 -0
- package/src/core/kimu-module-manager.ts +69 -0
- package/src/core/kimu-module.ts +21 -0
- package/src/core/kimu-path-config.ts +127 -0
- package/src/core/kimu-reactive.ts +196 -0
- package/src/core/kimu-render.ts +91 -0
- package/src/core/kimu-store.ts +147 -0
- package/src/core/kimu-types.ts +65 -0
- package/src/extensions/.gitkeep +0 -0
- package/src/extensions/extensions-manifest.json +13 -0
- package/src/extensions/kimu-home/component.ts +80 -0
- package/src/extensions/kimu-home/lang/en.json +5 -0
- package/src/extensions/kimu-home/lang/it.json +5 -0
- package/src/extensions/kimu-home/style.css +61 -0
- package/src/extensions/kimu-home/view.html +51 -0
- package/src/index.html +26 -0
- package/src/main.ts +68 -0
- package/src/modules/.gitkeep +0 -0
- package/src/modules/README.md +79 -0
- package/src/modules/i18n/README.it.md +63 -0
- package/src/modules/i18n/README.md +63 -0
- package/src/modules/i18n/kimu-global-lang.ts +26 -0
- package/src/modules/i18n/kimu-i18n-service.ts +108 -0
- package/src/modules/i18n/manifest.json +22 -0
- package/src/modules/i18n/module.ts +39 -0
- package/src/modules/modules-manifest.json +12 -0
- package/src/modules-repository/README.md +108 -0
- package/src/modules-repository/api-axios/CHANGELOG.md +48 -0
- package/src/modules-repository/api-axios/QUICK-REFERENCE.md +178 -0
- package/src/modules-repository/api-axios/README.md +304 -0
- package/src/modules-repository/api-axios/api-axios-service.ts +355 -0
- package/src/modules-repository/api-axios/examples.ts +293 -0
- package/src/modules-repository/api-axios/index.ts +19 -0
- package/src/modules-repository/api-axios/interfaces.ts +71 -0
- package/src/modules-repository/api-axios/module.ts +41 -0
- package/src/modules-repository/api-core/CHANGELOG.md +42 -0
- package/src/modules-repository/api-core/QUICK-REFERENCE.md +192 -0
- package/src/modules-repository/api-core/README.md +435 -0
- package/src/modules-repository/api-core/api-core-service.ts +289 -0
- package/src/modules-repository/api-core/examples.ts +432 -0
- package/src/modules-repository/api-core/index.ts +8 -0
- package/src/modules-repository/api-core/interfaces.ts +83 -0
- package/src/modules-repository/api-core/module.ts +30 -0
- package/src/modules-repository/event-bus/README.md +273 -0
- package/src/modules-repository/event-bus/event-bus-service.ts +176 -0
- package/src/modules-repository/event-bus/module.ts +30 -0
- package/src/modules-repository/i18n/README.it.md +63 -0
- package/src/modules-repository/i18n/README.md +63 -0
- package/src/modules-repository/i18n/kimu-global-lang.ts +26 -0
- package/src/modules-repository/i18n/kimu-i18n-service.ts +108 -0
- package/src/modules-repository/i18n/manifest.json +22 -0
- package/src/modules-repository/i18n/module.ts +39 -0
- package/src/modules-repository/notification/README.md +423 -0
- package/src/modules-repository/notification/module.ts +30 -0
- package/src/modules-repository/notification/notification-service.ts +436 -0
- package/src/modules-repository/router/README.it.md +39 -0
- package/src/modules-repository/router/README.md +39 -0
- package/src/modules-repository/router/manifest.json +21 -0
- package/src/modules-repository/router/module.ts +23 -0
- package/src/modules-repository/router/router.ts +144 -0
- package/src/modules-repository/state/README.md +409 -0
- package/src/modules-repository/state/module.ts +30 -0
- package/src/modules-repository/state/state-service.ts +296 -0
- package/src/modules-repository/theme/README.md +267 -0
- package/src/modules-repository/theme/module.ts +30 -0
- package/src/modules-repository/theme/pre-build.js +40 -0
- package/src/modules-repository/theme/theme-service.ts +389 -0
- package/src/modules-repository/theme/themes/theme-cherry-blossom.css +78 -0
- package/src/modules-repository/theme/themes/theme-cozy.css +111 -0
- package/src/modules-repository/theme/themes/theme-cyberpunk.css +150 -0
- package/src/modules-repository/theme/themes/theme-dark.css +79 -0
- package/src/modules-repository/theme/themes/theme-forest.css +171 -0
- package/src/modules-repository/theme/themes/theme-gold.css +100 -0
- package/src/modules-repository/theme/themes/theme-high-contrast.css +126 -0
- package/src/modules-repository/theme/themes/theme-lava.css +101 -0
- package/src/modules-repository/theme/themes/theme-lavender.css +90 -0
- package/src/modules-repository/theme/themes/theme-light.css +79 -0
- package/src/modules-repository/theme/themes/theme-matrix.css +103 -0
- package/src/modules-repository/theme/themes/theme-midnight.css +81 -0
- package/src/modules-repository/theme/themes/theme-nord.css +94 -0
- package/src/modules-repository/theme/themes/theme-ocean.css +84 -0
- package/src/modules-repository/theme/themes/theme-retro80s.css +343 -0
- package/src/modules-repository/theme/themes/theme-sunset.css +62 -0
- package/src/modules-repository/theme/themes-config.d.ts +27 -0
- package/src/modules-repository/theme/themes-config.json +213 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +33 -0
- package/vite.config.ts +99 -0
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
/* Base styles with fallback values */
|
|
7
|
+
:root {
|
|
8
|
+
/* Default theme colors (overridden by theme module if installed) */
|
|
9
|
+
/* These provide basic styling when no theme module is active */
|
|
10
|
+
|
|
11
|
+
/* Primary colors */
|
|
12
|
+
--kimu-primary: #667eea;
|
|
13
|
+
--kimu-primary-light: #818cf8;
|
|
14
|
+
--kimu-primary-dark: #5a67d8;
|
|
15
|
+
--kimu-text-on-primary: #ffffff;
|
|
16
|
+
|
|
17
|
+
/* Accent colors */
|
|
18
|
+
--kimu-accent: #764ba2;
|
|
19
|
+
--kimu-accent-light: #9f7aea;
|
|
20
|
+
--kimu-accent-dark: #6b46c1;
|
|
21
|
+
--kimu-text-on-accent: #ffffff;
|
|
22
|
+
|
|
23
|
+
/* Background colors */
|
|
24
|
+
--kimu-background: #ffffff;
|
|
25
|
+
--kimu-background-alt: #f7fafc;
|
|
26
|
+
--kimu-surface: #ffffff;
|
|
27
|
+
|
|
28
|
+
/* Text colors */
|
|
29
|
+
--kimu-text-primary: #1a202c;
|
|
30
|
+
--kimu-text-secondary: #4a5568;
|
|
31
|
+
--kimu-text-disabled: #a0aec0;
|
|
32
|
+
|
|
33
|
+
/* Borders and dividers */
|
|
34
|
+
--kimu-border: #e2e8f0;
|
|
35
|
+
--kimu-divider: #cbd5e0;
|
|
36
|
+
|
|
37
|
+
/* Semantic colors */
|
|
38
|
+
--kimu-success: #22c55e;
|
|
39
|
+
--kimu-warning: #f59e0b;
|
|
40
|
+
--kimu-error: #ef4444;
|
|
41
|
+
--kimu-info: #3b82f6;
|
|
42
|
+
|
|
43
|
+
/* Font and dimensions */
|
|
44
|
+
--kimu-font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
45
|
+
--kimu-radius: 8px;
|
|
46
|
+
--kimu-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
47
|
+
--kimu-shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* Base styles - use theme variables */
|
|
51
|
+
html,
|
|
52
|
+
body {
|
|
53
|
+
margin: 0;
|
|
54
|
+
padding: 0;
|
|
55
|
+
height: 100%;
|
|
56
|
+
background-color: var(--kimu-background, #ffffff);
|
|
57
|
+
color: var(--kimu-text-primary, #1a202c);
|
|
58
|
+
font-family: var(--kimu-font);
|
|
59
|
+
font-optical-sizing: auto;
|
|
60
|
+
font-weight: 400;
|
|
61
|
+
font-style: normal;
|
|
62
|
+
line-height: 1.6;
|
|
63
|
+
-webkit-font-smoothing: antialiased;
|
|
64
|
+
-moz-osx-font-smoothing: grayscale;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* Reset styles */
|
|
68
|
+
:host {
|
|
69
|
+
all: initial;
|
|
70
|
+
display: block;
|
|
71
|
+
font-family: var(--kimu-font);
|
|
72
|
+
color: var(--kimu-text-primary, #1a202c);
|
|
73
|
+
background-color: transparent;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
* {
|
|
77
|
+
box-sizing: border-box;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* Layout base */
|
|
81
|
+
.container {
|
|
82
|
+
padding: 1rem;
|
|
83
|
+
display: flex;
|
|
84
|
+
flex-direction: column;
|
|
85
|
+
gap: 1rem;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* Tipografia - use theme colors */
|
|
89
|
+
h1,
|
|
90
|
+
h2,
|
|
91
|
+
h3,
|
|
92
|
+
h4 {
|
|
93
|
+
color: var(--kimu-text-primary);
|
|
94
|
+
margin: 0;
|
|
95
|
+
font-weight: 600;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
p {
|
|
99
|
+
margin: 0.5rem 0;
|
|
100
|
+
color: var(--kimu-text-secondary);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* headings */
|
|
104
|
+
h1,
|
|
105
|
+
h2,
|
|
106
|
+
h3,
|
|
107
|
+
h4,
|
|
108
|
+
h5 {
|
|
109
|
+
margin: 0.5em 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* links */
|
|
113
|
+
a {
|
|
114
|
+
color: var(--kimu-primary);
|
|
115
|
+
text-decoration: none;
|
|
116
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KIMU Core - Central Export File
|
|
3
|
+
*
|
|
4
|
+
* This file exports all core KIMU framework classes, decorators, and utilities
|
|
5
|
+
* for convenient importing in extensions and applications.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Core application classes
|
|
9
|
+
export { KimuApp } from './kimu-app';
|
|
10
|
+
export { KimuComponentElement } from './kimu-component-element';
|
|
11
|
+
export { KimuComponent } from './kimu-component';
|
|
12
|
+
export { KimuEngine } from './kimu-engine';
|
|
13
|
+
export { KimuRender } from './kimu-render';
|
|
14
|
+
|
|
15
|
+
// Extension and module management
|
|
16
|
+
export { KimuExtensionManager } from './kimu-extension-manager';
|
|
17
|
+
export { KimuModule } from './kimu-module';
|
|
18
|
+
export { KimuModuleManager } from './kimu-module-manager';
|
|
19
|
+
|
|
20
|
+
// Asset and style management
|
|
21
|
+
export { KimuAssetManager } from './kimu-asset-manager';
|
|
22
|
+
export { KimuGlobalStyles } from './kimu-global-styles';
|
|
23
|
+
|
|
24
|
+
// Configuration and storage
|
|
25
|
+
export { KimuPathConfig } from './kimu-path-config';
|
|
26
|
+
export { KimuStore } from './kimu-store';
|
|
27
|
+
|
|
28
|
+
// Reactive system - Optimized & Minimal
|
|
29
|
+
export {
|
|
30
|
+
property,
|
|
31
|
+
initReactiveProperties,
|
|
32
|
+
getObservedAttributes,
|
|
33
|
+
handleAttributeChange
|
|
34
|
+
} from './kimu-reactive';
|
|
35
|
+
|
|
36
|
+
// Type definitions
|
|
37
|
+
export type {
|
|
38
|
+
KimuAsset,
|
|
39
|
+
KimuGroupAsset,
|
|
40
|
+
KimuLang,
|
|
41
|
+
KimuExtensionLanguages,
|
|
42
|
+
KimuExtensionMeta,
|
|
43
|
+
KimuModuleOptions
|
|
44
|
+
} from './kimu-types';
|
|
45
|
+
|
|
46
|
+
// Reactive system types
|
|
47
|
+
export type { PropertyOptions } from './kimu-reactive';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { KimuBuildConfig } from "../config/kimu-build-config";
|
|
2
|
+
import { KimuModuleManager } from "./kimu-module-manager";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The `KimuApp` class represents the core application logic for the Kimu framework.
|
|
6
|
+
* It is implemented as a singleton to ensure a single global instance throughout the application.
|
|
7
|
+
*
|
|
8
|
+
* Key functionalities:
|
|
9
|
+
* - Manages the system configuration, including version and environment details.
|
|
10
|
+
* - Provides utility methods to check the current environment (local, dev, prod).
|
|
11
|
+
* - Initializes the application by loading the configuration from the default configuration file.
|
|
12
|
+
* - Ensures the application is properly initialized before usage.
|
|
13
|
+
* - Provides access to the global KimuModuleManager for dynamic module management.
|
|
14
|
+
*/
|
|
15
|
+
export class KimuApp {
|
|
16
|
+
|
|
17
|
+
private static _instance: KimuApp;
|
|
18
|
+
private _config: any = null; // KIMU system configuration
|
|
19
|
+
public readonly moduleManager: KimuModuleManager;
|
|
20
|
+
|
|
21
|
+
/** Private constructor for singleton design pattern */
|
|
22
|
+
private constructor() {
|
|
23
|
+
this.moduleManager = new KimuModuleManager();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Retrieves the global instance, initializing it if necessary */
|
|
27
|
+
static async getInstance(): Promise<KimuApp> {
|
|
28
|
+
if (!this._instance) {
|
|
29
|
+
console.log('[Kimu] Avvio Kimu Framework');
|
|
30
|
+
this._instance = new KimuApp();
|
|
31
|
+
await this._instance._init();
|
|
32
|
+
}
|
|
33
|
+
return this._instance;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Initializes KimuApp component by reading the configuration */
|
|
37
|
+
private async _init(): Promise<void> {
|
|
38
|
+
try {
|
|
39
|
+
// Initializes the configuration with the default configuration file
|
|
40
|
+
this._config = KimuBuildConfig;
|
|
41
|
+
//console.log("[KIMU] version: ", this.version);
|
|
42
|
+
//console.log("[KIMU] environment: ", this.environment);
|
|
43
|
+
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.warn('[KimuApp] ❌ Error: Configuration not found or invalid. Using fallback.', err);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get config(): any {
|
|
50
|
+
if (!this._config) {
|
|
51
|
+
throw new Error('[KimuApp] ❌ Error: System configuration not available!');
|
|
52
|
+
}
|
|
53
|
+
return this._config;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get version(): string {
|
|
57
|
+
return this.config.version;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get environment(): string {
|
|
61
|
+
return this.config.environment;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
isLocal(): boolean {
|
|
65
|
+
return this.environment === 'local';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
isDev(): boolean {
|
|
69
|
+
return this.environment === 'dev';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
isProd(): boolean {
|
|
73
|
+
return this.environment === 'prod';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { KimuGroupAsset, KimuExtensionMeta } from './kimu-types';
|
|
2
|
+
import { KimuPathConfig } from './kimu-path-config';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The `KimuAssetManager` class provides utility methods for managing assets such as stylesheets,
|
|
6
|
+
* scripts, and other external resources in the Kimu framework. It includes functionality to:
|
|
7
|
+
*
|
|
8
|
+
* - Fetch text files from the server.
|
|
9
|
+
* - Inject stylesheets and scripts into the DOM or Shadow DOM.
|
|
10
|
+
* - Manage external assets defined in metadata or configuration objects.
|
|
11
|
+
* - Ensure assets are loaded only once to avoid duplication.
|
|
12
|
+
*
|
|
13
|
+
* This class is designed to streamline asset management for extensions and components
|
|
14
|
+
* within the Kimu framework.
|
|
15
|
+
*/
|
|
16
|
+
export class KimuAssetManager {
|
|
17
|
+
|
|
18
|
+
/** Cache for fetched files to avoid repeated requests */
|
|
19
|
+
private static _fileCache = new Map<string, string | null>();
|
|
20
|
+
|
|
21
|
+
/** Loads a text file from the server root */
|
|
22
|
+
static async fetchFile(path: string, useCache: boolean = true): Promise<string | null> {
|
|
23
|
+
// Check cache first (if caching is enabled)
|
|
24
|
+
if (useCache && this._fileCache.has(path)) {
|
|
25
|
+
return this._fileCache.get(path)!;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// console.log(`[KimuAssetManager::fetchFile] 🧾 Fetching file: ${path}`);
|
|
29
|
+
const rawPath = path.includes('?raw') ? path : `${path}?raw`;
|
|
30
|
+
const finalPath = rawPath.startsWith('/') ?
|
|
31
|
+
KimuPathConfig.resolvePath(rawPath) :
|
|
32
|
+
KimuPathConfig.resolvePath(`/${rawPath}`);
|
|
33
|
+
// console.log(`[KimuAssetManager::fetchFile] 🧾 Fetching file: ${finalPath}`);
|
|
34
|
+
try {
|
|
35
|
+
const response = await fetch(finalPath);
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
console.warn(`[KimuAssetManager::fetchFile] ⚠️ File not found: ${path} (status: ${response.status})`);
|
|
38
|
+
if (useCache) this._fileCache.set(path, null);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const content = await response.text();
|
|
42
|
+
if (useCache) this._fileCache.set(path, content);
|
|
43
|
+
return content;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.warn(`[KimuAssetManager::fetchFile] ⚠️ Fetch File Error: ${path}`, err);
|
|
46
|
+
if (useCache) this._fileCache.set(path, null);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Injects an element if not already present in the target node */
|
|
52
|
+
private static injectElementIfAbsent(
|
|
53
|
+
root: Document | ShadowRoot | HTMLElement,
|
|
54
|
+
create: () => HTMLElement,
|
|
55
|
+
id?: string
|
|
56
|
+
): void {
|
|
57
|
+
if (!root || typeof root.appendChild !== 'function') {
|
|
58
|
+
console.warn('[KimuAssetManager] ⚠️ Invalid root node for injection: ', root);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (id && 'getElementById' in root && root.getElementById(id)) {
|
|
62
|
+
console.log(`[KimuAssetManager] ⚠️ Element already present: ${id}`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const el = create();
|
|
66
|
+
if (id) {
|
|
67
|
+
el.id = id;
|
|
68
|
+
}
|
|
69
|
+
root.appendChild(el);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static async injectStyle(component: HTMLElement, stylePath: string, styleId: string | null): Promise<void> {
|
|
73
|
+
// console.log(`[KimuAssetManager] Injecting style: ${stylePath}`);
|
|
74
|
+
if(!stylePath) {
|
|
75
|
+
console.warn('[KimuAssetManager] ⚠️ No style assigned: ', stylePath);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const root = component.shadowRoot;
|
|
79
|
+
if (!(root instanceof ShadowRoot)) {
|
|
80
|
+
console.warn('[KimuAssetManager] ⚠️ ShadowRoot not found, unable to inject styl');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (styleId && root.getElementById(styleId)) {
|
|
84
|
+
console.log(`[KimuAssetManager] ⚠️ Style already injected: ${styleId}`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
//const css = await fetch(stylePath).then(res => res.ok ? res.text() : null).catch(() => null);
|
|
88
|
+
const css = await this.fetchFile(stylePath);
|
|
89
|
+
if (!css) {
|
|
90
|
+
console.warn(`[KimuAssetManager] ⚠️ Style not found: ${stylePath}`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const style = document.createElement('style');
|
|
94
|
+
if (styleId) {
|
|
95
|
+
style.id = styleId;
|
|
96
|
+
}
|
|
97
|
+
style.textContent = css;
|
|
98
|
+
root.appendChild(style);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static injectExternalLink(component: HTMLElement, href: string, id: string): void {
|
|
102
|
+
const root = component.shadowRoot;
|
|
103
|
+
if (!root) return;
|
|
104
|
+
this.injectElementIfAbsent(root, () => {
|
|
105
|
+
const link = document.createElement('link');
|
|
106
|
+
link.rel = 'stylesheet';
|
|
107
|
+
link.href = href;
|
|
108
|
+
return link;
|
|
109
|
+
}, id);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static injectExternalScript(component: HTMLElement | Document, src: string, id: string): void {
|
|
113
|
+
const root = component instanceof HTMLElement ? component.shadowRoot : component;
|
|
114
|
+
if (!root) return;
|
|
115
|
+
this.injectElementIfAbsent(root, () => {
|
|
116
|
+
const script = document.createElement('script');
|
|
117
|
+
script.src = src;
|
|
118
|
+
script.defer = true;
|
|
119
|
+
return script;
|
|
120
|
+
}, id);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static injectGlobalScript(src: string, id: string): void {
|
|
124
|
+
this.injectElementIfAbsent(document.head, () => {
|
|
125
|
+
const script = document.createElement('script');
|
|
126
|
+
script.src = src;
|
|
127
|
+
script.defer = true;
|
|
128
|
+
return script;
|
|
129
|
+
}, id);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static injectFromMeta(component: HTMLElement, meta: KimuExtensionMeta): void {
|
|
133
|
+
meta.external?.css?.forEach((css, index) => {
|
|
134
|
+
const id = css.id ?? `ext-css-${meta.tag}-${index}`;
|
|
135
|
+
this.injectExternalLink(component, css.path, id);
|
|
136
|
+
});
|
|
137
|
+
meta.external?.js?.forEach((js, index) => {
|
|
138
|
+
const id = js.id ?? `ext-js-${meta.tag}-${index}`;
|
|
139
|
+
this.injectGlobalScript(js.path, id);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static async loadExternalAssets(assets?: KimuGroupAsset): Promise<void> {
|
|
144
|
+
if (!assets) return;
|
|
145
|
+
const promises: Promise<void>[] = [];
|
|
146
|
+
assets.css?.forEach(asset => {
|
|
147
|
+
if (!document.querySelector(`link[href="${asset.path}"]`)) {
|
|
148
|
+
const link = document.createElement('link');
|
|
149
|
+
link.rel = 'stylesheet';
|
|
150
|
+
link.href = asset.path;
|
|
151
|
+
document.head.appendChild(link);
|
|
152
|
+
promises.push(new Promise(resolve => link.onload = () => resolve()));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
assets.js?.forEach(asset => {
|
|
156
|
+
if (!document.querySelector(`script[src="${asset.path}"]`)) {
|
|
157
|
+
const script = document.createElement('script');
|
|
158
|
+
script.src = asset.path;
|
|
159
|
+
script.defer = true;
|
|
160
|
+
document.head.appendChild(script);
|
|
161
|
+
promises.push(new Promise(resolve => script.onload = () => resolve()));
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
await Promise.all(promises);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
}
|