canvasframework 0.5.34 → 0.5.36

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 +146 -106
  2. package/package.json +1 -1
@@ -39,34 +39,52 @@ class Card extends Component {
39
39
  this.borderRadius = options.borderRadius || 0;
40
40
  this.elevation = options.elevation || 0;
41
41
  this.autoLayout = options.autoLayout !== undefined ? options.autoLayout : true;
42
- // 🔴 AJOUTER CETTE LIGNE
42
+
43
+ // 🔴 IMPORTANT : Activer la gestion des clics pour les enfants
43
44
  this.clickableChildren = true;
45
+
46
+ // 🔴 Détecter la plateforme
47
+ this.isCapacitor = typeof window !== 'undefined' && (window.Capacitor || window.cordova);
48
+
44
49
  // Stocker les positions relatives des enfants
45
50
  this.childPositions = new Map();
46
51
  }
47
52
 
48
53
  /**
49
- * Ajoute un enfant (position relative convertie en absolue)
54
+ * Ajoute un enfant
50
55
  * @param {Component} child - Composant enfant
51
56
  * @returns {Component} L'enfant ajouté
52
57
  */
53
- add(child) {
58
+ add(child) {
54
59
  this.children.push(child);
55
60
 
56
- // NE PAS CONVERTIR - garder relatif
57
- this.childPositions.set(child, {
61
+ if (this.isCapacitor) {
62
+ // CAPACITOR : Convertir en positions absolues
63
+ const relativeX = child.x;
64
+ const relativeY = child.y;
65
+
66
+ child.x = this.x + relativeX;
67
+ child.y = this.y + relativeY;
68
+
69
+ this.childPositions.set(child, {
70
+ x: relativeX,
71
+ y: relativeY
72
+ });
73
+ } else {
74
+ // WEB : Garder les positions relatives
75
+ this.childPositions.set(child, {
58
76
  x: child.x,
59
77
  y: child.y
60
- });
78
+ });
79
+ }
61
80
 
81
+ // Si autoLayout est activé, organiser automatiquement
62
82
  if (this.autoLayout) {
63
- this.layout();
83
+ this.layout();
64
84
  }
65
85
 
66
- // PAS de conversion child.x = this.x + relativeX !
67
-
68
86
  return child;
69
- }
87
+ }
70
88
 
71
89
  /**
72
90
  * Supprime un enfant
@@ -100,56 +118,84 @@ add(child) {
100
118
  if (this.children.length === 0 || !this.autoLayout) return;
101
119
 
102
120
  if (this.direction === 'column') {
103
- let currentY = this.padding;
121
+ let currentY = this.padding;
122
+
123
+ for (let i = 0; i < this.children.length; i++) {
124
+ const child = this.children[i];
104
125
 
105
- for (let i = 0; i < this.children.length; i++) {
106
- const child = this.children[i];
107
-
108
- let childX = this.padding;
109
- if (this.align === 'center') {
110
- childX = (this.width - child.width) / 2;
111
- } else if (this.align === 'end') {
112
- childX = this.width - child.width - this.padding;
113
- }
114
-
115
- // GARDER RELATIF (ne pas ajouter this.x et this.y)
116
- child.x = childX;
117
- child.y = currentY;
118
-
119
- this.childPositions.set(child, { x: childX, y: currentY });
120
-
121
- currentY += child.height;
122
- if (i < this.children.length - 1) {
123
- currentY += this.gap;
124
- }
126
+ // Calculer la position X selon l'alignement
127
+ let childX = this.padding;
128
+ if (this.align === 'center') {
129
+ childX = (this.width - child.width) / 2;
130
+ } else if (this.align === 'end') {
131
+ childX = this.width - child.width - this.padding;
132
+ } else if (this.align === 'stretch') {
133
+ childX = this.padding;
134
+ child.width = this.width - (this.padding * 2);
125
135
  }
136
+
137
+ if (this.isCapacitor) {
138
+ // CAPACITOR : Positions absolues
139
+ child.x = this.x + childX;
140
+ child.y = this.y + currentY;
141
+ } else {
142
+ // WEB : Positions relatives
143
+ child.x = childX;
144
+ child.y = currentY;
145
+ }
146
+
147
+ // Stocker la position relative
148
+ this.childPositions.set(child, { x: childX, y: currentY });
149
+
150
+ // Mettre à jour la position Y pour l'enfant suivant
151
+ currentY += child.height;
152
+
153
+ // Ajouter le gap seulement si ce n'est pas le dernier enfant
154
+ if (i < this.children.length - 1) {
155
+ currentY += this.gap;
156
+ }
157
+ }
126
158
  } else {
127
- // Direction 'row' - même logique
128
- let currentX = this.padding;
159
+ // Direction 'row'
160
+ let currentX = this.padding;
161
+
162
+ for (let i = 0; i < this.children.length; i++) {
163
+ const child = this.children[i];
164
+
165
+ // Calculer la position Y selon l'alignement
166
+ let childY = this.padding;
167
+ if (this.align === 'center') {
168
+ childY = (this.height - child.height) / 2;
169
+ } else if (this.align === 'end') {
170
+ childY = this.height - child.height - this.padding;
171
+ } else if (this.align === 'stretch') {
172
+ childY = this.padding;
173
+ child.height = this.height - (this.padding * 2);
174
+ }
175
+
176
+ if (this.isCapacitor) {
177
+ // CAPACITOR : Positions absolues
178
+ child.x = this.x + currentX;
179
+ child.y = this.y + childY;
180
+ } else {
181
+ // WEB : Positions relatives
182
+ child.x = currentX;
183
+ child.y = childY;
184
+ }
185
+
186
+ // Stocker la position relative
187
+ this.childPositions.set(child, { x: currentX, y: childY });
129
188
 
130
- for (let i = 0; i < this.children.length; i++) {
131
- const child = this.children[i];
132
-
133
- let childY = this.padding;
134
- if (this.align === 'center') {
135
- childY = (this.height - child.height) / 2;
136
- } else if (this.align === 'end') {
137
- childY = this.height - child.height - this.padding;
138
- }
139
-
140
- // GARDER RELATIF
141
- child.x = currentX;
142
- child.y = childY;
143
-
144
- this.childPositions.set(child, { x: currentX, y: childY });
145
-
146
- currentX += child.width;
147
- if (i < this.children.length - 1) {
148
- currentX += this.gap;
149
- }
189
+ // Mettre à jour la position X pour l'enfant suivant
190
+ currentX += child.width;
191
+
192
+ // Ajouter le gap seulement si ce n'est pas le dernier enfant
193
+ if (i < this.children.length - 1) {
194
+ currentX += this.gap;
150
195
  }
196
+ }
151
197
  }
152
- }
198
+ }
153
199
 
154
200
  /**
155
201
  * Met à jour la position de la carte et ajuste les enfants
@@ -157,15 +203,20 @@ add(child) {
157
203
  * @param {number} y - Nouvelle position Y
158
204
  */
159
205
  setPosition(x, y) {
160
- const deltaX = x - this.x;
161
- const deltaY = y - this.y;
162
-
163
- super.setPosition(x, y);
164
-
165
- // Déplacer tous les enfants avec la carte
166
- for (let child of this.children) {
167
- child.x += deltaX;
168
- child.y += deltaY;
206
+ if (this.isCapacitor) {
207
+ // CAPACITOR : Déplacer les enfants avec la carte
208
+ const deltaX = x - this.x;
209
+ const deltaY = y - this.y;
210
+
211
+ super.setPosition(x, y);
212
+
213
+ for (let child of this.children) {
214
+ child.x += deltaX;
215
+ child.y += deltaY;
216
+ }
217
+ } else {
218
+ // WEB : Les enfants sont en relatif, pas besoin de les déplacer
219
+ super.setPosition(x, y);
169
220
  }
170
221
  }
171
222
 
@@ -177,8 +228,13 @@ add(child) {
177
228
  */
178
229
  setChildPosition(child, relativeX, relativeY) {
179
230
  if (this.children.includes(child)) {
180
- child.x = this.x + relativeX;
181
- child.y = this.y + relativeY;
231
+ if (this.isCapacitor) {
232
+ child.x = this.x + relativeX;
233
+ child.y = this.y + relativeY;
234
+ } else {
235
+ child.x = relativeX;
236
+ child.y = relativeY;
237
+ }
182
238
  this.childPositions.set(child, { x: relativeX, y: relativeY });
183
239
  }
184
240
  }
@@ -257,57 +313,41 @@ add(child) {
257
313
 
258
314
  // Dessiner l'ombre si elevation > 0
259
315
  if (this.elevation > 0) {
260
- this.drawShadow(ctx);
316
+ this.drawShadow(ctx);
261
317
  }
262
318
 
263
319
  // Dessiner le fond de la carte
264
320
  if (this.bgColor !== 'transparent') {
265
- ctx.fillStyle = this.bgColor;
266
- if (this.borderRadius > 0) {
267
- ctx.beginPath();
268
- this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
269
- ctx.fill();
270
- } else {
271
- ctx.fillRect(this.x, this.y, this.width, this.height);
272
- }
321
+ ctx.fillStyle = this.bgColor;
322
+ if (this.borderRadius > 0) {
323
+ ctx.beginPath();
324
+ this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
325
+ ctx.fill();
326
+ } else {
327
+ ctx.fillRect(this.x, this.y, this.width, this.height);
328
+ }
273
329
  }
274
330
 
275
- // 🔴 DESSINER avec translate POUR LE WEB, sans translate POUR CAPACITOR
276
- const isCapacitor = typeof window !== 'undefined' && window.Capacitor;
277
-
278
- if (isCapacitor) {
279
- // Capacitor : positions absolues directes
280
- for (let child of this.children) {
281
- if (child.visible) {
282
- // Sauvegarder position relative
283
- const relX = child.x;
284
- const relY = child.y;
285
-
286
- // Convertir temporairement en absolu pour le dessin
287
- child.x = this.x + relX;
288
- child.y = this.y + relY;
289
-
290
- child.draw(ctx);
291
-
292
- // Restaurer position relative
293
- child.x = relX;
294
- child.y = relY;
295
- }
296
- }
331
+ // Dessiner les enfants
332
+ if (this.isCapacitor) {
333
+ // CAPACITOR : Dessiner directement (positions absolues)
334
+ for (let child of this.children) {
335
+ if (child.visible) child.draw(ctx);
336
+ }
297
337
  } else {
298
- // Web : translate
299
- ctx.save();
300
- ctx.translate(this.x, this.y);
301
-
302
- for (let child of this.children) {
303
- if (child.visible) child.draw(ctx);
304
- }
305
-
306
- ctx.restore();
338
+ // WEB : Dessiner avec translate (positions relatives)
339
+ ctx.save();
340
+ ctx.translate(this.x, this.y);
341
+
342
+ for (let child of this.children) {
343
+ if (child.visible) child.draw(ctx);
344
+ }
345
+
346
+ ctx.restore();
307
347
  }
308
348
 
309
349
  ctx.restore();
310
- }
350
+ }
311
351
 
312
352
  /**
313
353
  * Dessine un rectangle avec coins arrondis
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasframework",
3
- "version": "0.5.34",
3
+ "version": "0.5.36",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/beyons/CanvasFramework.git"