@editora/performance
Advanced tools
@@ -1,1 +0,1 @@ | ||
| "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class o{constructor(e={}){this.batch=[],this.batchTimeout=null,this.config={maxBatchSize:10,maxBatchTime:16,enabled:!0,...e}}add(e){if(!this.config.enabled){this.flush([e]);return}this.batch.push(e),this.batch.length>=this.config.maxBatchSize?this.flushBatch():this.batch.length===1&&this.scheduleFlush()}flushBatch(){this.batch.length>0&&(this.flush([...this.batch]),this.batch=[],this.clearTimeout())}setOnFlush(e){this.onFlush=e}getBatchSize(){return this.batch.length}isEnabled(){return this.config.enabled}setEnabled(e){this.config.enabled=e,e||this.flushBatch()}flush(e){if(this.onFlush){const t=e[0]?.beforeState||{};this.onFlush(e,t)}}scheduleFlush(){this.clearTimeout(),this.batchTimeout=window.setTimeout(()=>{this.flushBatch()},this.config.maxBatchTime)}clearTimeout(){this.batchTimeout&&(window.clearTimeout(this.batchTimeout),this.batchTimeout=null)}destroy(){this.clearTimeout(),this.flushBatch()}}function l(r){return new o(r)}class c{constructor(e=250){this.timeoutId=null,this.delay=e}execute(e,...t){this.timeoutId!==null&&clearTimeout(this.timeoutId),this.timeoutId=window.setTimeout(()=>{e(...t)},this.delay)}cancel(){this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}}function u(r){return new c(r)}class h{constructor(e={}){this.cleanupInterval=null,this.eventListeners=new Map,this.timeouts=new Set,this.intervals=new Set,this.config={maxMemoryMB:100,cleanupIntervalMs:3e4,autoCleanup:!0,...e},this.config.autoCleanup&&this.startAutoCleanup()}registerEventListener(e,t,n,i){const s=`${t}_${Math.random()}`;e.addEventListener(t,n,i),this.eventListeners.set(s,n)}registerTimeout(e){this.timeouts.add(e)}registerInterval(e){this.intervals.add(e)}unregisterTimeout(e){this.timeouts.delete(e)}unregisterInterval(e){this.intervals.delete(e)}forceGC(){window.gc&&window.gc()}getMemoryUsage(){const e=performance.memory;return e?{used:Math.round(e.usedJSHeapSize/1024/1024),total:Math.round(e.totalJSHeapSize/1024/1024),limit:Math.round(e.jsHeapSizeLimit/1024/1024)}:null}isMemoryHigh(){const e=this.getMemoryUsage();return e?e.used>this.config.maxMemoryMB:!1}cleanup(){for(const e of this.timeouts)clearTimeout(e);this.timeouts.clear();for(const e of this.intervals)clearInterval(e);this.intervals.clear(),this.forceGC()}startAutoCleanup(){this.cleanupInterval=window.setInterval(()=>{this.isMemoryHigh()&&this.cleanup()},this.config.cleanupIntervalMs)}stopAutoCleanup(){this.cleanupInterval&&(clearInterval(this.cleanupInterval),this.cleanupInterval=null)}destroy(){this.stopAutoCleanup(),this.cleanup(),this.eventListeners.clear()}}function d(r){return new h(r)}class m{constructor(e={}){this.metrics=[],this.isMonitoring=!1,this.sampleInterval=null,this.currentOperation=null,this.config={enabled:!0,sampleInterval:5e3,maxSamples:100,logWarnings:!0,...e},this.config.enabled&&this.startMonitoring()}startMonitoring(){this.isMonitoring||(this.isMonitoring=!0,this.sampleInterval=window.setInterval(()=>{this.collectMetrics()},this.config.sampleInterval))}stopMonitoring(){this.isMonitoring&&(this.isMonitoring=!1,this.sampleInterval&&(clearInterval(this.sampleInterval),this.sampleInterval=null))}startOperation(e){if(!this.config.enabled)return;const t=performance.memory;this.currentOperation={type:e,startTime:performance.now(),memoryStart:t?t.usedJSHeapSize:0}}endOperation(){if(!this.config.enabled||!this.currentOperation)return null;const e=performance.now(),t=performance.memory,n=t?t.usedJSHeapSize:0,i={domTime:0,renderTime:e-this.currentOperation.startTime,transactionTime:e-this.currentOperation.startTime,memoryUsage:Math.round((n-this.currentOperation.memoryStart)/1024/1024),timestamp:Date.now()};switch(this.currentOperation.type){case"transaction":i.transactionTime=e-this.currentOperation.startTime;break;case"render":i.renderTime=e-this.currentOperation.startTime;break;case"dom":i.domTime=e-this.currentOperation.startTime;break}return this.addMetrics(i),this.currentOperation=null,this.config.logWarnings&&this.checkPerformanceWarnings(i),i}getMetrics(){return[...this.metrics]}getAverageMetrics(e=6e4){const t=Date.now()-e,n=this.metrics.filter(s=>s.timestamp>t);if(n.length===0)return{};const i=n.reduce((s,a)=>({domTime:s.domTime+a.domTime,renderTime:s.renderTime+a.renderTime,transactionTime:s.transactionTime+a.transactionTime,memoryUsage:s.memoryUsage+a.memoryUsage}),{domTime:0,renderTime:0,transactionTime:0,memoryUsage:0});return{domTime:Math.round(i.domTime/n.length),renderTime:Math.round(i.renderTime/n.length),transactionTime:Math.round(i.transactionTime/n.length),memoryUsage:Math.round(i.memoryUsage/n.length)}}clearMetrics(){this.metrics=[]}collectMetrics(){const e=performance.memory;if(!e)return;const t={domTime:0,renderTime:0,transactionTime:0,memoryUsage:Math.round(e.usedJSHeapSize/1024/1024),timestamp:Date.now()};this.addMetrics(t)}addMetrics(e){this.metrics.push(e),this.metrics.length>this.config.maxSamples&&(this.metrics=this.metrics.slice(-this.config.maxSamples))}checkPerformanceWarnings(e){const t=[];e.renderTime>16&&t.push(`Slow render: ${e.renderTime}ms`),e.transactionTime>100&&t.push(`Slow transaction: ${e.transactionTime}ms`),e.memoryUsage>50&&t.push(`High memory usage: ${e.memoryUsage}MB`),t.length>0&&console.warn("Performance warning:",t.join(", "))}destroy(){this.stopMonitoring(),this.clearMetrics()}}function f(r){return new m(r)}exports.Debouncer=c;exports.MemoryManager=h;exports.PerformanceMonitor=m;exports.TransactionBatcher=o;exports.createDebouncer=u;exports.createMemoryManager=d;exports.createPerformanceMonitor=f;exports.createTransactionBatcher=l; | ||
| "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class o{constructor(e={}){this.batch=[],this.batchTimeout=null,this.config={maxBatchSize:10,maxBatchTime:16,enabled:!0,...e}}add(e){if(!this.config.enabled){this.flush([e]);return}this.batch.push(e),this.batch.length>=this.config.maxBatchSize?this.flushBatch():this.batch.length===1&&this.scheduleFlush()}flushBatch(){this.batch.length>0&&(this.flush([...this.batch]),this.batch=[],this.clearTimeout())}setOnFlush(e){this.onFlush=e}getBatchSize(){return this.batch.length}isEnabled(){return this.config.enabled}setEnabled(e){this.config.enabled=e,e||this.flushBatch()}flush(e){var t;if(this.onFlush){const i=((t=e[0])==null?void 0:t.beforeState)||{};this.onFlush(e,i)}}scheduleFlush(){this.clearTimeout(),this.batchTimeout=window.setTimeout(()=>{this.flushBatch()},this.config.maxBatchTime)}clearTimeout(){this.batchTimeout&&(window.clearTimeout(this.batchTimeout),this.batchTimeout=null)}destroy(){this.clearTimeout(),this.flushBatch()}}function l(n){return new o(n)}class c{constructor(e=250){this.timeoutId=null,this.delay=e}execute(e,...t){this.timeoutId!==null&&clearTimeout(this.timeoutId),this.timeoutId=window.setTimeout(()=>{e(...t)},this.delay)}cancel(){this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}}function u(n){return new c(n)}class h{constructor(e={}){this.cleanupInterval=null,this.eventListeners=new Map,this.timeouts=new Set,this.intervals=new Set,this.config={maxMemoryMB:100,cleanupIntervalMs:3e4,autoCleanup:!0,...e},this.config.autoCleanup&&this.startAutoCleanup()}registerEventListener(e,t,i,r){const s=`${t}_${Math.random()}`;e.addEventListener(t,i,r),this.eventListeners.set(s,i)}registerTimeout(e){this.timeouts.add(e)}registerInterval(e){this.intervals.add(e)}unregisterTimeout(e){this.timeouts.delete(e)}unregisterInterval(e){this.intervals.delete(e)}forceGC(){window.gc&&window.gc()}getMemoryUsage(){const e=performance.memory;return e?{used:Math.round(e.usedJSHeapSize/1024/1024),total:Math.round(e.totalJSHeapSize/1024/1024),limit:Math.round(e.jsHeapSizeLimit/1024/1024)}:null}isMemoryHigh(){const e=this.getMemoryUsage();return e?e.used>this.config.maxMemoryMB:!1}cleanup(){for(const e of this.timeouts)clearTimeout(e);this.timeouts.clear();for(const e of this.intervals)clearInterval(e);this.intervals.clear(),this.forceGC()}startAutoCleanup(){this.cleanupInterval=window.setInterval(()=>{this.isMemoryHigh()&&this.cleanup()},this.config.cleanupIntervalMs)}stopAutoCleanup(){this.cleanupInterval&&(clearInterval(this.cleanupInterval),this.cleanupInterval=null)}destroy(){this.stopAutoCleanup(),this.cleanup(),this.eventListeners.clear()}}function d(n){return new h(n)}class m{constructor(e={}){this.metrics=[],this.isMonitoring=!1,this.sampleInterval=null,this.currentOperation=null,this.config={enabled:!0,sampleInterval:5e3,maxSamples:100,logWarnings:!0,...e},this.config.enabled&&this.startMonitoring()}startMonitoring(){this.isMonitoring||(this.isMonitoring=!0,this.sampleInterval=window.setInterval(()=>{this.collectMetrics()},this.config.sampleInterval))}stopMonitoring(){this.isMonitoring&&(this.isMonitoring=!1,this.sampleInterval&&(clearInterval(this.sampleInterval),this.sampleInterval=null))}startOperation(e){if(!this.config.enabled)return;const t=performance.memory;this.currentOperation={type:e,startTime:performance.now(),memoryStart:t?t.usedJSHeapSize:0}}endOperation(){if(!this.config.enabled||!this.currentOperation)return null;const e=performance.now(),t=performance.memory,i=t?t.usedJSHeapSize:0,r={domTime:0,renderTime:e-this.currentOperation.startTime,transactionTime:e-this.currentOperation.startTime,memoryUsage:Math.round((i-this.currentOperation.memoryStart)/1024/1024),timestamp:Date.now()};switch(this.currentOperation.type){case"transaction":r.transactionTime=e-this.currentOperation.startTime;break;case"render":r.renderTime=e-this.currentOperation.startTime;break;case"dom":r.domTime=e-this.currentOperation.startTime;break}return this.addMetrics(r),this.currentOperation=null,this.config.logWarnings&&this.checkPerformanceWarnings(r),r}getMetrics(){return[...this.metrics]}getAverageMetrics(e=6e4){const t=Date.now()-e,i=this.metrics.filter(s=>s.timestamp>t);if(i.length===0)return{};const r=i.reduce((s,a)=>({domTime:s.domTime+a.domTime,renderTime:s.renderTime+a.renderTime,transactionTime:s.transactionTime+a.transactionTime,memoryUsage:s.memoryUsage+a.memoryUsage}),{domTime:0,renderTime:0,transactionTime:0,memoryUsage:0});return{domTime:Math.round(r.domTime/i.length),renderTime:Math.round(r.renderTime/i.length),transactionTime:Math.round(r.transactionTime/i.length),memoryUsage:Math.round(r.memoryUsage/i.length)}}clearMetrics(){this.metrics=[]}collectMetrics(){const e=performance.memory;if(!e)return;const t={domTime:0,renderTime:0,transactionTime:0,memoryUsage:Math.round(e.usedJSHeapSize/1024/1024),timestamp:Date.now()};this.addMetrics(t)}addMetrics(e){this.metrics.push(e),this.metrics.length>this.config.maxSamples&&(this.metrics=this.metrics.slice(-this.config.maxSamples))}checkPerformanceWarnings(e){const t=[];e.renderTime>16&&t.push(`Slow render: ${e.renderTime}ms`),e.transactionTime>100&&t.push(`Slow transaction: ${e.transactionTime}ms`),e.memoryUsage>50&&t.push(`High memory usage: ${e.memoryUsage}MB`),t.length>0&&console.warn("Performance warning:",t.join(", "))}destroy(){this.stopMonitoring(),this.clearMetrics()}}function f(n){return new m(n)}exports.Debouncer=c;exports.MemoryManager=h;exports.PerformanceMonitor=m;exports.TransactionBatcher=o;exports.createDebouncer=u;exports.createMemoryManager=d;exports.createPerformanceMonitor=f;exports.createTransactionBatcher=l; |
+33
-28
@@ -55,5 +55,6 @@ class o { | ||
| flush(e) { | ||
| var t; | ||
| if (this.onFlush) { | ||
| const t = e[0]?.beforeState || {}; | ||
| this.onFlush(e, t); | ||
| const i = ((t = e[0]) == null ? void 0 : t.beforeState) || {}; | ||
| this.onFlush(e, i); | ||
| } | ||
@@ -82,4 +83,4 @@ } | ||
| } | ||
| function l(r) { | ||
| return new o(r); | ||
| function l(n) { | ||
| return new o(n); | ||
| } | ||
@@ -105,4 +106,4 @@ class h { | ||
| } | ||
| function u(r) { | ||
| return new h(r); | ||
| function u(n) { | ||
| return new h(n); | ||
| } | ||
@@ -122,5 +123,5 @@ class m { | ||
| */ | ||
| registerEventListener(e, t, n, i) { | ||
| registerEventListener(e, t, i, r) { | ||
| const s = `${t}_${Math.random()}`; | ||
| e.addEventListener(t, n, i), this.eventListeners.set(s, n); | ||
| e.addEventListener(t, i, r), this.eventListeners.set(s, i); | ||
| } | ||
@@ -207,4 +208,4 @@ /** | ||
| } | ||
| function d(r) { | ||
| return new m(r); | ||
| function d(n) { | ||
| return new m(n); | ||
| } | ||
@@ -240,3 +241,4 @@ class c { | ||
| startOperation(e) { | ||
| if (!this.config.enabled) return; | ||
| if (!this.config.enabled) | ||
| return; | ||
| const t = performance.memory; | ||
@@ -253,4 +255,5 @@ this.currentOperation = { | ||
| endOperation() { | ||
| if (!this.config.enabled || !this.currentOperation) return null; | ||
| const e = performance.now(), t = performance.memory, n = t ? t.usedJSHeapSize : 0, i = { | ||
| if (!this.config.enabled || !this.currentOperation) | ||
| return null; | ||
| const e = performance.now(), t = performance.memory, i = t ? t.usedJSHeapSize : 0, r = { | ||
| domTime: 0, | ||
@@ -260,3 +263,3 @@ // Would be calculated based on operation type | ||
| transactionTime: e - this.currentOperation.startTime, | ||
| memoryUsage: Math.round((n - this.currentOperation.memoryStart) / 1024 / 1024), | ||
| memoryUsage: Math.round((i - this.currentOperation.memoryStart) / 1024 / 1024), | ||
| timestamp: Date.now() | ||
@@ -266,12 +269,12 @@ }; | ||
| case "transaction": | ||
| i.transactionTime = e - this.currentOperation.startTime; | ||
| r.transactionTime = e - this.currentOperation.startTime; | ||
| break; | ||
| case "render": | ||
| i.renderTime = e - this.currentOperation.startTime; | ||
| r.renderTime = e - this.currentOperation.startTime; | ||
| break; | ||
| case "dom": | ||
| i.domTime = e - this.currentOperation.startTime; | ||
| r.domTime = e - this.currentOperation.startTime; | ||
| break; | ||
| } | ||
| return this.addMetrics(i), this.currentOperation = null, this.config.logWarnings && this.checkPerformanceWarnings(i), i; | ||
| return this.addMetrics(r), this.currentOperation = null, this.config.logWarnings && this.checkPerformanceWarnings(r), r; | ||
| } | ||
@@ -288,5 +291,6 @@ /** | ||
| getAverageMetrics(e = 6e4) { | ||
| const t = Date.now() - e, n = this.metrics.filter((s) => s.timestamp > t); | ||
| if (n.length === 0) return {}; | ||
| const i = n.reduce( | ||
| const t = Date.now() - e, i = this.metrics.filter((s) => s.timestamp > t); | ||
| if (i.length === 0) | ||
| return {}; | ||
| const r = i.reduce( | ||
| (s, a) => ({ | ||
@@ -301,6 +305,6 @@ domTime: s.domTime + a.domTime, | ||
| return { | ||
| domTime: Math.round(i.domTime / n.length), | ||
| renderTime: Math.round(i.renderTime / n.length), | ||
| transactionTime: Math.round(i.transactionTime / n.length), | ||
| memoryUsage: Math.round(i.memoryUsage / n.length) | ||
| domTime: Math.round(r.domTime / i.length), | ||
| renderTime: Math.round(r.renderTime / i.length), | ||
| transactionTime: Math.round(r.transactionTime / i.length), | ||
| memoryUsage: Math.round(r.memoryUsage / i.length) | ||
| }; | ||
@@ -319,3 +323,4 @@ } | ||
| const e = performance.memory; | ||
| if (!e) return; | ||
| if (!e) | ||
| return; | ||
| const t = { | ||
@@ -350,4 +355,4 @@ domTime: 0, | ||
| } | ||
| function f(r) { | ||
| return new c(r); | ||
| function f(n) { | ||
| return new c(n); | ||
| } | ||
@@ -354,0 +359,0 @@ export { |
+6
-6
| { | ||
| "name": "@editora/performance", | ||
| "version": "1.0.7", | ||
| "version": "1.0.8", | ||
| "description": "Performance optimization utilities for Editora Rich Text Editor", | ||
@@ -39,3 +39,3 @@ "homepage": "https://editora-free.netlify.app/", | ||
| "dependencies": { | ||
| "@editora/core": "^1.0.8" | ||
| "@editora/core": "^1.0.9" | ||
| }, | ||
@@ -54,3 +54,3 @@ "keywords": [ | ||
| "engines": { | ||
| "node": ">=18.0.0" | ||
| "node": ">=16.0.0" | ||
| }, | ||
@@ -63,5 +63,5 @@ "repository": { | ||
| "devDependencies": { | ||
| "@editora/core": "^1.0.6", | ||
| "@editora/core": "^1.0.9", | ||
| "typescript": "^5.0.0", | ||
| "vite": "^7.3.1" | ||
| "vite": "^4.5.14" | ||
| }, | ||
@@ -71,3 +71,3 @@ "publishConfig": { | ||
| }, | ||
| "gitHead": "80e0808ae4909de63b8e0f1dd915b06b33a8ed44" | ||
| "gitHead": "7883627e823aa99dd5ecb66a5201116df972f88b" | ||
| } |
+5
-0
| # @editora/performance | ||
| > [!IMPORTANT] | ||
| > **Live Website:** https://editora-ecosystem.netlify.app/ | ||
| > **Storybook:** https://editora-ecosystem-storybook.netlify.app/ | ||
| Performance and memory utilities for Editora editors. | ||
@@ -4,0 +9,0 @@ |
-21
| MIT License | ||
| Copyright (c) 2026 Ajay Kumar | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
1083
0.56%92
5.75%38204
-2.13%11
-8.33%Updated