@kispace-io/extension-memory-usage 0.8.0
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/package.json +18 -0
- package/src/i18n.json +11 -0
- package/src/index.ts +16 -0
- package/src/k-memory-usage.ts +59 -0
- package/src/memory-usage-extension.ts +10 -0
- package/tsconfig.json +12 -0
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kispace-io/extension-memory-usage",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./src/index.ts",
|
|
9
|
+
"types": "./src/index.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@kispace-io/core": "*"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"typescript": "^5.9.3"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/i18n.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"namespace": "extensions",
|
|
3
|
+
"en": {
|
|
4
|
+
"EXT_MEMORYUSAGE_NAME": "Memory Usage Monitor",
|
|
5
|
+
"EXT_MEMORYUSAGE_DESC": "Displays JavaScript heap memory usage in the bottom toolbar"
|
|
6
|
+
},
|
|
7
|
+
"de": {
|
|
8
|
+
"EXT_MEMORYUSAGE_NAME": "Speicherverbrauch-Monitor",
|
|
9
|
+
"EXT_MEMORYUSAGE_DESC": "Zeigt die JavaScript-Heap-Speichernutzung in der unteren Symbolleiste an"
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { extensionRegistry, i18nLazy, contributionRegistry, SYSTEM_LANGUAGE_BUNDLES } from '@kispace-io/core';
|
|
2
|
+
import bundle from './i18n.json';
|
|
3
|
+
|
|
4
|
+
contributionRegistry.registerContribution(SYSTEM_LANGUAGE_BUNDLES, bundle as any);
|
|
5
|
+
|
|
6
|
+
const t = i18nLazy('extensions');
|
|
7
|
+
|
|
8
|
+
extensionRegistry.registerExtension({
|
|
9
|
+
id: "system.memoryusage",
|
|
10
|
+
name: t('EXT_MEMORYUSAGE_NAME'),
|
|
11
|
+
description: t('EXT_MEMORYUSAGE_DESC'),
|
|
12
|
+
loader: () => import("./memory-usage-extension"),
|
|
13
|
+
icon: "microchip",
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {customElement} from "lit/decorators.js";
|
|
2
|
+
import {KElement} from "@kispace-io/core";
|
|
3
|
+
import {html} from "lit";
|
|
4
|
+
|
|
5
|
+
@customElement('k-memory-usage')
|
|
6
|
+
export class KMemoryUsage extends KElement {
|
|
7
|
+
|
|
8
|
+
private updateInterval: number | null = null;
|
|
9
|
+
|
|
10
|
+
connectedCallback() {
|
|
11
|
+
super.connectedCallback();
|
|
12
|
+
this.updateInterval = window.setInterval(() => {
|
|
13
|
+
this.requestUpdate();
|
|
14
|
+
}, 2000);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
disconnectedCallback() {
|
|
18
|
+
super.disconnectedCallback();
|
|
19
|
+
if (this.updateInterval !== null) {
|
|
20
|
+
clearInterval(this.updateInterval);
|
|
21
|
+
this.updateInterval = null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected render() {
|
|
26
|
+
const memory = (performance as any).memory;
|
|
27
|
+
if (!memory) {
|
|
28
|
+
return html``;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const usedMB = (memory.usedJSHeapSize / 1048576).toFixed(1);
|
|
32
|
+
const limitMB = (memory.jsHeapSizeLimit / 1048576).toFixed(0);
|
|
33
|
+
const percentageNum = (memory.usedJSHeapSize / memory.jsHeapSizeLimit) * 100;
|
|
34
|
+
const percentage = percentageNum.toFixed(0);
|
|
35
|
+
|
|
36
|
+
const barColor = percentageNum > 80 ? '#ff4444' : percentageNum > 60 ? '#ffaa00' : '#44aa44';
|
|
37
|
+
|
|
38
|
+
return html`
|
|
39
|
+
<span style="display: inline-flex; align-items: center; justify-content: center; height: 100%; padding-left: 0.5rem; gap: 0.25rem; font-size: 0.85em; color: var(--wa-color-neutral-text);" title="Main thread memory consumption only (excludes web workers)">
|
|
40
|
+
<wa-icon name="microchip" label="Memory usage"></wa-icon>
|
|
41
|
+
<span style="display: flex; align-items: center; gap: 0.25rem;">
|
|
42
|
+
<span>${usedMB} / ${limitMB} MB</span>
|
|
43
|
+
<span style="position: relative; display: inline-block; width: 60px; height: 14px; vertical-align: middle;">
|
|
44
|
+
<span style="display: block; position: absolute; width: 100%; height: 100%; background: rgba(255,255,255,0.1); border-radius: 4px;"></span>
|
|
45
|
+
<span style="display: block; position: absolute; width: ${percentage}%; height: 100%; background: ${barColor}; border-radius: 4px; transition: width 0.3s ease;"></span>
|
|
46
|
+
<span style="position: absolute; width: 100%; text-align: center; font-size: 0.7em; line-height: 14px; font-weight: 600; color: white; text-shadow: 0 0 2px rgba(0,0,0,0.8);">${percentage}%</span>
|
|
47
|
+
</span>
|
|
48
|
+
</span>
|
|
49
|
+
</span>
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare global {
|
|
55
|
+
interface HTMLElementTagNameMap {
|
|
56
|
+
'k-memory-usage': KMemoryUsage
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {contributionRegistry, HTMLContribution} from "@kispace-io/core";
|
|
2
|
+
import {TOOLBAR_BOTTOM} from "@kispace-io/core";
|
|
3
|
+
import "./k-memory-usage";
|
|
4
|
+
|
|
5
|
+
contributionRegistry.registerContribution(TOOLBAR_BOTTOM, {
|
|
6
|
+
target: TOOLBAR_BOTTOM,
|
|
7
|
+
label: "Memory",
|
|
8
|
+
html: `<k-memory-usage></k-memory-usage>`
|
|
9
|
+
} as HTMLContribution)
|
|
10
|
+
|