canvasframework 0.5.1 → 0.5.2
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/core/CanvasFramework.js +89 -48
- package/package.json +1 -1
package/core/CanvasFramework.js
CHANGED
|
@@ -155,6 +155,15 @@ class CanvasFramework {
|
|
|
155
155
|
constructor(canvasId, options = {}) {
|
|
156
156
|
// ✅ AJOUTER: Démarrer le chronomètre
|
|
157
157
|
const startTime = performance.now();
|
|
158
|
+
|
|
159
|
+
this.metrics = {
|
|
160
|
+
initTime: 0,
|
|
161
|
+
firstRenderTime: null,
|
|
162
|
+
firstInteractionTime: null,
|
|
163
|
+
totalStartupTime: null
|
|
164
|
+
};
|
|
165
|
+
this._firstRenderDone = false;
|
|
166
|
+
this._startupStartTime = startTime;
|
|
158
167
|
|
|
159
168
|
// ✅ Créer automatiquement le canvas
|
|
160
169
|
this.canvas = document.createElement('canvas');
|
|
@@ -2649,54 +2658,86 @@ class CanvasFramework {
|
|
|
2649
2658
|
}
|
|
2650
2659
|
}
|
|
2651
2660
|
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2661
|
+
startRenderLoop() {
|
|
2662
|
+
let lastScrollOffset = this.scrollOffset;
|
|
2663
|
+
let lastRenderMode = 'full';
|
|
2664
|
+
|
|
2665
|
+
const render = () => {
|
|
2666
|
+
if (!this._splashFinished) {
|
|
2667
|
+
requestAnimationFrame(render);
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
// Vérifier le scroll
|
|
2672
|
+
const scrollChanged = Math.abs(this.scrollOffset - lastScrollOffset) > 0.1;
|
|
2673
|
+
lastScrollOffset = this.scrollOffset;
|
|
2674
|
+
|
|
2675
|
+
// Décider du mode de rendu
|
|
2676
|
+
let renderMode = 'full';
|
|
2677
|
+
|
|
2678
|
+
if (this.optimizationEnabled &&
|
|
2679
|
+
this.dirtyComponents.size > 0 &&
|
|
2680
|
+
!this.isDragging &&
|
|
2681
|
+
Math.abs(this.scrollVelocity) < 0.5 &&
|
|
2682
|
+
!scrollChanged &&
|
|
2683
|
+
this.dirtyComponents.size < 3) {
|
|
2684
|
+
renderMode = 'dirty';
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
if (renderMode === 'full' || lastRenderMode !== renderMode) {
|
|
2688
|
+
this.ctx.fillStyle = this.backgroundColor || '#ffffff';
|
|
2689
|
+
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
2690
|
+
this.renderFull();
|
|
2691
|
+
} else {
|
|
2692
|
+
this._renderDirtyComponents();
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
lastRenderMode = renderMode;
|
|
2696
|
+
|
|
2697
|
+
// ✅ AJOUTER : Calcul et affichage du FPS
|
|
2698
|
+
this._frames++;
|
|
2699
|
+
const now = performance.now();
|
|
2700
|
+
const elapsed = now - this._lastFpsTime;
|
|
2701
|
+
|
|
2702
|
+
if (elapsed >= 1000) {
|
|
2703
|
+
this.fps = Math.round((this._frames * 1000) / elapsed);
|
|
2704
|
+
this._frames = 0;
|
|
2705
|
+
this._lastFpsTime = now;
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
// ✅ AJOUTER : Afficher le FPS si activé
|
|
2709
|
+
if (this.showFps) {
|
|
2710
|
+
this.ctx.save();
|
|
2711
|
+
this.ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';
|
|
2712
|
+
this.ctx.fillRect(10, 10, 100, 40);
|
|
2713
|
+
this.ctx.fillStyle = '#00ff00';
|
|
2714
|
+
this.ctx.font = 'bold 20px monospace';
|
|
2715
|
+
this.ctx.textAlign = 'left';
|
|
2716
|
+
this.ctx.textBaseline = 'top';
|
|
2717
|
+
this.ctx.fillText(`FPS: ${this.fps}`, 20, 20);
|
|
2718
|
+
this.ctx.restore();
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2721
|
+
// ✅ AJOUTER : Indicateurs de débogage si activés
|
|
2722
|
+
if (this.debbug) {
|
|
2723
|
+
this.drawOverflowIndicators();
|
|
2724
|
+
}
|
|
2725
|
+
|
|
2726
|
+
// ✅ AJOUTER : Marquer le premier rendu
|
|
2727
|
+
if (!this._firstRenderDone) {
|
|
2728
|
+
this._markFirstRender();
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
// ✅ AJOUTER : Mettre à jour l'inertie si nécessaire
|
|
2732
|
+
if (Math.abs(this.scrollVelocity) > 0.1 && !this.isDragging) {
|
|
2733
|
+
this.scrollWorker.postMessage({ type: 'UPDATE_INERTIA' });
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
requestAnimationFrame(render);
|
|
2737
|
+
};
|
|
2738
|
+
|
|
2739
|
+
render();
|
|
2740
|
+
}
|
|
2700
2741
|
|
|
2701
2742
|
// 3. Ajoutez une méthode renderFull() optimisée
|
|
2702
2743
|
renderFull() {
|