canvasframework 0.5.38 → 0.5.40

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 (2) hide show
  1. package/components/Card.js +117 -65
  2. package/package.json +1 -1
@@ -42,6 +42,9 @@ class Card extends Component {
42
42
 
43
43
  // Stocker les positions relatives des enfants
44
44
  this.childPositions = new Map();
45
+
46
+ // NOUVEAU: Flag pour forcer les positions absolues
47
+ this._positionsCorrected = false;
45
48
  }
46
49
 
47
50
  /**
@@ -52,49 +55,29 @@ class Card extends Component {
52
55
  add(child) {
53
56
  this.children.push(child);
54
57
 
55
- // CONVERTIR les positions relatives en positions absolues
56
- // Les x, y passés sont relatifs à la Card
57
- child.x = this.x + child.x;
58
- child.y = this.y + child.y;
58
+ // SOLUTION: Stocker les coordonnées relatives AVANT conversion
59
+ const relativeX = child.x || 0;
60
+ const relativeY = child.y || 0;
59
61
 
60
62
  // Stocker la position relative originale
61
63
  this.childPositions.set(child, {
62
- x: child.x - this.x,
63
- y: child.y - this.y
64
+ x: relativeX,
65
+ y: relativeY
64
66
  });
65
67
 
68
+ // CONVERTIR IMMÉDIATEMENT en positions absolues
69
+ child.x = this.x + relativeX;
70
+ child.y = this.y + relativeY;
71
+
66
72
  // Si autoLayout est activé, organiser automatiquement
67
73
  if (this.autoLayout) {
68
- this.layout();
74
+ // Utiliser setTimeout pour éviter les conflits avec Vite Hot Reload
75
+ setTimeout(() => this.layout(), 0);
69
76
  }
70
77
 
71
78
  return child;
72
79
  }
73
80
 
74
- /**
75
- * Supprime un enfant
76
- * @param {Component} child - Composant enfant à supprimer
77
- * @returns {boolean} True si l'enfant a été supprimé
78
- */
79
- remove(child) {
80
- const index = this.children.indexOf(child);
81
- if (index > -1) {
82
- this.children.splice(index, 1);
83
- this.childPositions.delete(child);
84
- if (this.autoLayout) this.layout();
85
- return true;
86
- }
87
- return false;
88
- }
89
-
90
- /**
91
- * Supprime tous les enfants
92
- */
93
- clear() {
94
- this.children = [];
95
- this.childPositions.clear();
96
- }
97
-
98
81
  /**
99
82
  * Organise les enfants selon le layout
100
83
  * @private
@@ -119,7 +102,7 @@ class Card extends Component {
119
102
  child.width = this.width - (this.padding * 2);
120
103
  }
121
104
 
122
- // Positionner l'enfant RELATIVEMENT à la Card
105
+ // Positionner l'enfant en COORDONNÉES ABSOLUES
123
106
  child.x = this.x + childX;
124
107
  child.y = this.y + currentY;
125
108
 
@@ -152,7 +135,7 @@ class Card extends Component {
152
135
  child.height = this.height - (this.padding * 2);
153
136
  }
154
137
 
155
- // Positionner l'enfant RELATIVEMENT à la Card
138
+ // Positionner l'enfant en COORDONNÉES ABSOLUES
156
139
  child.x = this.x + currentX;
157
140
  child.y = this.y + childY;
158
141
 
@@ -168,6 +151,68 @@ class Card extends Component {
168
151
  }
169
152
  }
170
153
  }
154
+
155
+ // Marquer que les positions sont corrigées
156
+ this._positionsCorrected = true;
157
+ }
158
+
159
+ /**
160
+ * Dessine la carte et ses enfants
161
+ * @param {CanvasRenderingContext2D} ctx - Contexte de dessin
162
+ */
163
+ draw(ctx) {
164
+ ctx.save();
165
+
166
+ // SOLUTION: Vérifier et corriger les positions AVANT de dessiner
167
+ // Ceci garantit que les enfants sont en coordonnées absolues
168
+ if (this._positionsCorrected) {
169
+ this._ensureAbsolutePositions();
170
+ }
171
+
172
+ // Dessiner l'ombre si elevation > 0
173
+ if (this.elevation > 0) {
174
+ this.drawShadow(ctx);
175
+ }
176
+
177
+ // Dessiner le fond de la carte
178
+ if (this.bgColor !== 'transparent') {
179
+ ctx.fillStyle = this.bgColor;
180
+ if (this.borderRadius > 0) {
181
+ ctx.beginPath();
182
+ this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
183
+ ctx.fill();
184
+ } else {
185
+ ctx.fillRect(this.x, this.y, this.width, this.height);
186
+ }
187
+ }
188
+
189
+ // Dessiner les enfants
190
+ for (let child of this.children) {
191
+ if (child.visible) child.draw(ctx);
192
+ }
193
+
194
+ ctx.restore();
195
+ }
196
+
197
+ /**
198
+ * S'assure que tous les enfants ont des coordonnées absolues
199
+ * @private
200
+ */
201
+ _ensureAbsolutePositions() {
202
+ for (let child of this.children) {
203
+ const relativePos = this.childPositions.get(child);
204
+ if (relativePos) {
205
+ // Recalculer la position absolue basée sur la position de la carte
206
+ const expectedX = this.x + relativePos.x;
207
+ const expectedY = this.y + relativePos.y;
208
+
209
+ // Corriger si nécessaire (important pour Vite Hot Reload)
210
+ if (Math.abs(child.x - expectedX) > 1 || Math.abs(child.y - expectedY) > 1) {
211
+ child.x = expectedX;
212
+ child.y = expectedY;
213
+ }
214
+ }
215
+ }
171
216
  }
172
217
 
173
218
  /**
@@ -186,6 +231,44 @@ class Card extends Component {
186
231
  child.x += deltaX;
187
232
  child.y += deltaY;
188
233
  }
234
+
235
+ // Mettre à jour les positions relatives stockées
236
+ this._updateRelativePositions();
237
+ }
238
+
239
+ /**
240
+ * Met à jour les positions relatives stockées
241
+ * @private
242
+ */
243
+ _updateRelativePositions() {
244
+ for (let [child, pos] of this.childPositions.entries()) {
245
+ // Les positions relatives ne changent pas quand la carte bouge
246
+ // On garde juste la référence
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Supprime un enfant
252
+ * @param {Component} child - Composant enfant à supprimer
253
+ * @returns {boolean} True si l'enfant a été supprimé
254
+ */
255
+ remove(child) {
256
+ const index = this.children.indexOf(child);
257
+ if (index > -1) {
258
+ this.children.splice(index, 1);
259
+ this.childPositions.delete(child);
260
+ if (this.autoLayout) this.layout();
261
+ return true;
262
+ }
263
+ return false;
264
+ }
265
+
266
+ /**
267
+ * Supprime tous les enfants
268
+ */
269
+ clear() {
270
+ this.children = [];
271
+ this.childPositions.clear();
189
272
  }
190
273
 
191
274
  /**
@@ -196,6 +279,7 @@ class Card extends Component {
196
279
  */
197
280
  setChildPosition(child, relativeX, relativeY) {
198
281
  if (this.children.includes(child)) {
282
+ // Définir en coordonnées absolues
199
283
  child.x = this.x + relativeX;
200
284
  child.y = this.y + relativeY;
201
285
  this.childPositions.set(child, { x: relativeX, y: relativeY });
@@ -267,38 +351,6 @@ class Card extends Component {
267
351
  ctx.restore();
268
352
  }
269
353
 
270
- /**
271
- * Dessine la carte et ses enfants
272
- * @param {CanvasRenderingContext2D} ctx - Contexte de dessin
273
- */
274
- draw(ctx) {
275
- ctx.save();
276
-
277
- // Dessiner l'ombre si elevation > 0
278
- if (this.elevation > 0) {
279
- this.drawShadow(ctx);
280
- }
281
-
282
- // Dessiner le fond de la carte
283
- if (this.bgColor !== 'transparent') {
284
- ctx.fillStyle = this.bgColor;
285
- if (this.borderRadius > 0) {
286
- ctx.beginPath();
287
- this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
288
- ctx.fill();
289
- } else {
290
- ctx.fillRect(this.x, this.y, this.width, this.height);
291
- }
292
- }
293
-
294
- // Dessiner les enfants
295
- for (let child of this.children) {
296
- if (child.visible) child.draw(ctx);
297
- }
298
-
299
- ctx.restore();
300
- }
301
-
302
354
  /**
303
355
  * Dessine un rectangle avec coins arrondis
304
356
  * @param {CanvasRenderingContext2D} ctx - Contexte de dessin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasframework",
3
- "version": "0.5.38",
3
+ "version": "0.5.40",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/beyons/CanvasFramework.git"