feat: Implement enhanced card physics with rotational dynamics, mass scaling, stacking behavior, and drag torque.
This commit is contained in:
@@ -11,6 +11,7 @@ export interface LayoutCardState {
|
||||
rotation: number;
|
||||
width: number;
|
||||
height: number;
|
||||
pageCount: number;
|
||||
}
|
||||
|
||||
export class LayoutCard implements LayoutCardState {
|
||||
@@ -21,6 +22,7 @@ export class LayoutCard implements LayoutCardState {
|
||||
rotation: number = 0;
|
||||
width: number = 0;
|
||||
height: number = 0;
|
||||
pageCount: number = 1;
|
||||
ref: HTMLElement | null = null;
|
||||
|
||||
private _innerRadius: number = 0;
|
||||
@@ -50,8 +52,6 @@ export class LayoutCard implements LayoutCardState {
|
||||
this.applyTransform();
|
||||
}
|
||||
|
||||
|
||||
|
||||
getConstrainedPosition(x: number, y: number): { x: number, y: number } {
|
||||
const rad = (this.rotation * Math.PI) / 180;
|
||||
const sin = Math.abs(Math.sin(rad));
|
||||
@@ -90,6 +90,10 @@ export class LayoutCard implements LayoutCardState {
|
||||
this.recalculateCenters();
|
||||
}
|
||||
|
||||
if (changes.pageCount !== undefined) {
|
||||
this.physics.updateMass(changes.pageCount);
|
||||
}
|
||||
|
||||
if (options.markDirty) {
|
||||
this.isDirty = true;
|
||||
}
|
||||
@@ -240,7 +244,8 @@ export class LayoutCard implements LayoutCardState {
|
||||
z: this.z,
|
||||
rotation: this.rotation,
|
||||
width: this.width,
|
||||
height: this.height
|
||||
height: this.height,
|
||||
pageCount: this.pageCount
|
||||
};
|
||||
}
|
||||
|
||||
@@ -278,6 +283,7 @@ export class LayoutStore {
|
||||
initialize(id: string, ref: HTMLElement | null, config: {
|
||||
width: number;
|
||||
height: number;
|
||||
pageCount: number;
|
||||
}) {
|
||||
let card = this.items.get(id);
|
||||
|
||||
@@ -309,14 +315,16 @@ export class LayoutStore {
|
||||
rotation,
|
||||
width,
|
||||
height,
|
||||
z
|
||||
z,
|
||||
pageCount: config.pageCount
|
||||
}, ref);
|
||||
} else {
|
||||
// Create card with temporary position
|
||||
card = new LayoutCard(id, this, {
|
||||
width,
|
||||
height,
|
||||
z: this.zCounter++
|
||||
z: this.zCounter++,
|
||||
pageCount: config.pageCount
|
||||
}, ref);
|
||||
|
||||
// Calculate initial position using the card instance
|
||||
@@ -333,7 +341,7 @@ export class LayoutStore {
|
||||
|
||||
this.items.set(id, card);
|
||||
} else {
|
||||
card.update({ width, height }, { markDirty: false });
|
||||
card.update({ width, height, pageCount: config.pageCount }, { markDirty: false });
|
||||
}
|
||||
|
||||
// Always update ref and ensure transform is applied
|
||||
|
||||
Reference in New Issue
Block a user