@gamepark/react-game 7.3.0 → 7.4.0
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/dist/components/GameProvider/GameProvider.js +1 -3
- package/dist/components/GameProvider/GameProvider.js.map +1 -1
- package/dist/components/Header/HeaderText.d.ts +6 -1
- package/dist/components/Header/HeaderText.js +14 -5
- package/dist/components/Header/HeaderText.js.map +1 -1
- package/dist/components/JournalTabs/JournalTabs.js +1 -1
- package/dist/components/JournalTabs/JournalTabs.js.map +1 -1
- package/dist/components/LoadingScreen/LoadingScreen.js +5 -0
- package/dist/components/LoadingScreen/LoadingScreen.js.map +1 -1
- package/dist/components/material/DraggableMaterial.d.ts +12 -2
- package/dist/components/material/DraggableMaterial.js +50 -57
- package/dist/components/material/DraggableMaterial.js.map +1 -1
- package/dist/components/material/GameTable/DynamicItemsDisplay.js +52 -8
- package/dist/components/material/GameTable/DynamicItemsDisplay.js.map +1 -1
- package/dist/components/material/GameTable/GameMaterialDisplay.js +5 -2
- package/dist/components/material/GameTable/GameMaterialDisplay.js.map +1 -1
- package/dist/components/material/GameTable/GameTable.d.ts +1 -0
- package/dist/components/material/GameTable/GameTable.js +49 -18
- package/dist/components/material/GameTable/GameTable.js.map +1 -1
- package/dist/components/material/GameTable/GameTableNavigation.js +7 -0
- package/dist/components/material/GameTable/GameTableNavigation.js.map +1 -1
- package/dist/components/material/GameTable/ItemDisplay.js +4 -4
- package/dist/components/material/GameTable/ItemDisplay.js.map +1 -1
- package/dist/components/material/GameTable/StaticItemsDisplay.js +21 -6
- package/dist/components/material/GameTable/StaticItemsDisplay.js.map +1 -1
- package/dist/components/material/GameTable/focus/FocusProvider.js +11 -5
- package/dist/components/material/GameTable/focus/FocusProvider.js.map +1 -1
- package/dist/components/material/GameTable/focus/NoZoomFocusProvider.js +2 -2
- package/dist/components/material/GameTable/focus/NoZoomFocusProvider.js.map +1 -1
- package/dist/components/material/GameTable/focus/index.d.ts +1 -0
- package/dist/components/material/GameTable/focus/index.js +1 -0
- package/dist/components/material/GameTable/focus/index.js.map +1 -1
- package/dist/components/material/GameTable/index.d.ts +2 -0
- package/dist/components/material/GameTable/index.js +2 -0
- package/dist/components/material/GameTable/index.js.map +1 -1
- package/dist/components/material/MaterialDescription.d.ts +9 -1
- package/dist/components/material/MaterialDescription.js +20 -13
- package/dist/components/material/MaterialDescription.js.map +1 -1
- package/dist/components/material/animations/AnimationBuilder.d.ts +160 -0
- package/dist/components/material/animations/AnimationBuilder.js +287 -0
- package/dist/components/material/animations/AnimationBuilder.js.map +1 -0
- package/dist/components/material/animations/CreateItemAnimations.d.ts +4 -2
- package/dist/components/material/animations/CreateItemAnimations.js +80 -10
- package/dist/components/material/animations/CreateItemAnimations.js.map +1 -1
- package/dist/components/material/animations/DeleteItemAnimations.d.ts +3 -1
- package/dist/components/material/animations/DeleteItemAnimations.js +16 -4
- package/dist/components/material/animations/DeleteItemAnimations.js.map +1 -1
- package/dist/components/material/animations/DeleteItemAtOnceAnimations.d.ts +3 -1
- package/dist/components/material/animations/DeleteItemAtOnceAnimations.js +16 -4
- package/dist/components/material/animations/DeleteItemAtOnceAnimations.js.map +1 -1
- package/dist/components/material/animations/ItemAnimations.d.ts +35 -1
- package/dist/components/material/animations/ItemAnimations.js +143 -1
- package/dist/components/material/animations/ItemAnimations.js.map +1 -1
- package/dist/components/material/animations/MaterialAnimations.d.ts +2 -1
- package/dist/components/material/animations/MaterialAnimations.js +6 -6
- package/dist/components/material/animations/MaterialAnimations.js.map +1 -1
- package/dist/components/material/animations/MaterialGameAnimations.d.ts +94 -1
- package/dist/components/material/animations/MaterialGameAnimations.js +150 -2
- package/dist/components/material/animations/MaterialGameAnimations.js.map +1 -1
- package/dist/components/material/animations/MoveItemAnimations.d.ts +3 -1
- package/dist/components/material/animations/MoveItemAnimations.js +29 -5
- package/dist/components/material/animations/MoveItemAnimations.js.map +1 -1
- package/dist/components/material/animations/MoveItemAtOnceAnimations.d.ts +5 -2
- package/dist/components/material/animations/MoveItemAtOnceAnimations.js +45 -3
- package/dist/components/material/animations/MoveItemAtOnceAnimations.js.map +1 -1
- package/dist/components/material/animations/Trajectory.d.ts +132 -0
- package/dist/components/material/animations/Trajectory.js +87 -0
- package/dist/components/material/animations/Trajectory.js.map +1 -0
- package/dist/components/material/animations/index.d.ts +3 -0
- package/dist/components/material/animations/index.js +3 -0
- package/dist/components/material/animations/index.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useLegalMoves.js +2 -1
- package/dist/hooks/useLegalMoves.js.map +1 -1
- package/dist/hooks/useMaterialContextRef.d.ts +10 -0
- package/dist/hooks/useMaterialContextRef.js +12 -0
- package/dist/hooks/useMaterialContextRef.js.map +1 -0
- package/dist/hooks/usePlayerName.js +1 -1
- package/dist/hooks/usePlayerName.js.map +1 -1
- package/dist/hooks/useUndo.js +12 -3
- package/dist/hooks/useUndo.js.map +1 -1
- package/dist/locators/DeckLocator.d.ts +3 -1
- package/dist/locators/DeckLocator.js +6 -0
- package/dist/locators/DeckLocator.js.map +1 -1
- package/dist/locators/HandLocator.d.ts +1 -0
- package/dist/locators/HandLocator.js +3 -0
- package/dist/locators/HandLocator.js.map +1 -1
- package/dist/locators/ListLocator.d.ts +1 -0
- package/dist/locators/ListLocator.js +3 -0
- package/dist/locators/ListLocator.js.map +1 -1
- package/dist/locators/Locator.d.ts +39 -0
- package/dist/locators/Locator.js +74 -1
- package/dist/locators/Locator.js.map +1 -1
- package/dist/locators/PileLocator.d.ts +1 -0
- package/dist/locators/PileLocator.js +3 -0
- package/dist/locators/PileLocator.js.map +1 -1
- package/dist/utilities/translation.util.js +1 -1
- package/dist/utilities/translation.util.js.map +1 -1
- package/package.json +79 -77
|
@@ -2,16 +2,113 @@ import { Animations, AnimationStep } from '@gamepark/react-client';
|
|
|
2
2
|
import { isEndPlayerTurn, MoveKind } from '@gamepark/rules-api';
|
|
3
3
|
import { uniq } from 'es-toolkit';
|
|
4
4
|
import { ensureMaterialSoundConfig } from '../sound/sound.utils';
|
|
5
|
+
import { AnimationBuilder, isMaterial, isMoveType, isRule } from './AnimationBuilder';
|
|
5
6
|
import { ItemAnimations } from './ItemAnimations';
|
|
6
7
|
import { MaterialAnimations } from './MaterialAnimations';
|
|
7
8
|
export class MaterialGameAnimations extends Animations {
|
|
9
|
+
/** @internal Animation configurations from the legacy .when() API */
|
|
8
10
|
animationConfigs = [];
|
|
11
|
+
/** @internal Animation builders from the new .configure() API */
|
|
12
|
+
animationBuilders = [];
|
|
13
|
+
/** @internal Default animation configuration */
|
|
9
14
|
defaultAnimationConfig = new AnimationConfig();
|
|
15
|
+
/** @internal Default animation builder for new API */
|
|
16
|
+
_defaultBuilder = new AnimationBuilder();
|
|
17
|
+
// ==========================================
|
|
18
|
+
// Legacy API (backward compatible)
|
|
19
|
+
// ==========================================
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use configure() instead for the new trajectory API.
|
|
22
|
+
* Create a new animation configuration with filter chain.
|
|
23
|
+
*/
|
|
10
24
|
when() {
|
|
11
25
|
const animationConfig = new AnimationConfig();
|
|
12
26
|
this.animationConfigs.push(animationConfig);
|
|
13
27
|
return animationConfig;
|
|
14
28
|
}
|
|
29
|
+
// ==========================================
|
|
30
|
+
// New API
|
|
31
|
+
// ==========================================
|
|
32
|
+
/**
|
|
33
|
+
* Configure animations for moves matching a predicate.
|
|
34
|
+
* @param predicate Function to determine if this configuration applies
|
|
35
|
+
* @returns AnimationBuilder for fluent configuration
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* animations.configure(and(isRule(RuleId.PlayCard), isMyMove()))
|
|
40
|
+
* .duration(800)
|
|
41
|
+
* .arc(15)
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
configure(predicate) {
|
|
45
|
+
const builder = new AnimationBuilder();
|
|
46
|
+
builder.filter(predicate);
|
|
47
|
+
this.animationBuilders.push(builder);
|
|
48
|
+
return builder;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Configure animations for moves during a specific rule.
|
|
52
|
+
* @param ruleId The rule ID to match
|
|
53
|
+
* @returns AnimationBuilder for fluent configuration
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* animations.forRule(RuleId.PlayCard)
|
|
58
|
+
* .duration(600)
|
|
59
|
+
* .via(LocationType.TableCenter)
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
forRule(ruleId) {
|
|
63
|
+
return this.configure(isRule(ruleId));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Configure animations for a specific item move type.
|
|
67
|
+
* @param moveType The item move type to match (Create, Move, Delete, etc.)
|
|
68
|
+
* @returns AnimationBuilder for fluent configuration
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* animations.forMove(ItemMoveType.Move)
|
|
73
|
+
* .duration(500)
|
|
74
|
+
* .arc(12)
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
forMove(moveType) {
|
|
78
|
+
return this.configure(isMoveType(moveType));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Configure animations for a specific material type.
|
|
82
|
+
* @param materialType The material type to match
|
|
83
|
+
* @returns AnimationBuilder for fluent configuration
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* animations.forMaterial(MaterialType.Card)
|
|
88
|
+
* .duration(400)
|
|
89
|
+
* .flat() // No arc for cards
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
forMaterial(materialType) {
|
|
93
|
+
return this.configure(isMaterial(materialType));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Configure default animations (applies to all moves not matched by other configurations).
|
|
97
|
+
* @returns AnimationBuilder for fluent configuration
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* animations.defaults()
|
|
102
|
+
* .duration(600)
|
|
103
|
+
* .arc({ height: 8, peak: 0.4 })
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
defaults() {
|
|
107
|
+
return this._defaultBuilder;
|
|
108
|
+
}
|
|
109
|
+
// ==========================================
|
|
110
|
+
// Internal methods
|
|
111
|
+
// ==========================================
|
|
15
112
|
getDuration(move, context) {
|
|
16
113
|
const materialContext = {
|
|
17
114
|
rules: new context.Rules(context.game),
|
|
@@ -20,8 +117,34 @@ export class MaterialGameAnimations extends Animations {
|
|
|
20
117
|
player: context.playerId,
|
|
21
118
|
action: context.action
|
|
22
119
|
};
|
|
120
|
+
// Check new API builders first
|
|
121
|
+
const builder = this.getAnimationBuilder(move, materialContext);
|
|
122
|
+
if (builder) {
|
|
123
|
+
return builder.getDuration(move, context);
|
|
124
|
+
}
|
|
125
|
+
// Fall back to legacy API
|
|
23
126
|
return this.getAnimationConfig(move, materialContext).getDuration(move, context);
|
|
24
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Find matching animation builder from new API.
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
getAnimationBuilder(move, context) {
|
|
133
|
+
for (const builder of this.animationBuilders) {
|
|
134
|
+
if (builder.matches(move, context)) {
|
|
135
|
+
return builder;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Check if default builder has any configuration
|
|
139
|
+
if (this._defaultBuilder.durationSeconds !== undefined || typeof this._defaultBuilder.trajectoryConfig === 'function' || this._defaultBuilder.trajectoryConfig.elevation !== undefined) {
|
|
140
|
+
return this._defaultBuilder;
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Find matching animation config from legacy API.
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
25
148
|
getAnimationConfig(move, context) {
|
|
26
149
|
for (const animationConfig of this.animationConfigs) {
|
|
27
150
|
if (animationConfig.filters.every(filter => filter(move, context))) {
|
|
@@ -30,15 +153,40 @@ export class MaterialGameAnimations extends Animations {
|
|
|
30
153
|
}
|
|
31
154
|
return this.defaultAnimationConfig;
|
|
32
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Get item animation CSS, checking both new and legacy APIs.
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
getItemAnimation(context, animation, action, boundaries) {
|
|
161
|
+
const materialContext = {
|
|
162
|
+
...context,
|
|
163
|
+
action
|
|
164
|
+
};
|
|
165
|
+
// Check new API builders first
|
|
166
|
+
const builder = this.getAnimationBuilder(animation.move, materialContext);
|
|
167
|
+
if (builder) {
|
|
168
|
+
return builder.getItemAnimation(context, animation, boundaries);
|
|
169
|
+
}
|
|
170
|
+
// Fall back to legacy API
|
|
171
|
+
return this.getAnimationConfig(animation.move, materialContext).getItemAnimation(context, animation, boundaries);
|
|
172
|
+
}
|
|
33
173
|
getSounds() {
|
|
34
|
-
|
|
174
|
+
const legacySounds = this.animationConfigs
|
|
35
175
|
.filter(animationConfig => !!animationConfig.s)
|
|
36
|
-
.map(animationConfig => ensureMaterialSoundConfig(animationConfig.s).sound)
|
|
176
|
+
.map(animationConfig => ensureMaterialSoundConfig(animationConfig.s).sound);
|
|
177
|
+
const newSounds = this.animationBuilders
|
|
178
|
+
.filter(builder => builder.soundConfig !== undefined && builder.soundConfig !== false)
|
|
179
|
+
.map(builder => ensureMaterialSoundConfig(builder.soundConfig).sound);
|
|
180
|
+
return uniq([...legacySounds, ...newSounds]);
|
|
37
181
|
}
|
|
38
182
|
pauseNextConsequenceAnimation(move, _context) {
|
|
39
183
|
return isEndPlayerTurn(move);
|
|
40
184
|
}
|
|
41
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* @deprecated Use AnimationBuilder with the new configure() API instead.
|
|
188
|
+
* Legacy animation configuration class for backward compatibility.
|
|
189
|
+
*/
|
|
42
190
|
class AnimationConfig extends ItemAnimations {
|
|
43
191
|
filters = [];
|
|
44
192
|
d;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MaterialGameAnimations.js","sourceRoot":"","sources":["../../../../src/components/material/animations/MaterialGameAnimations.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,UAAU,EAAE,aAAa,EAAmB,MAAM,wBAAwB,CAAA;AAChH,OAAO,EAAkB,eAAe,
|
|
1
|
+
{"version":3,"file":"MaterialGameAnimations.js","sourceRoot":"","sources":["../../../../src/components/material/animations/MaterialGameAnimations.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,UAAU,EAAE,aAAa,EAAmB,MAAM,wBAAwB,CAAA;AAChH,OAAO,EAAkB,eAAe,EAAuD,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACpI,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAIjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAsB,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AACzG,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AASzD,MAAM,OAAO,sBACX,SAAQ,UAA2D;IAEnE,qEAAqE;IAC5D,gBAAgB,GAA+B,EAAE,CAAA;IAE1D,iEAAiE;IACxD,iBAAiB,GAAgC,EAAE,CAAA;IAE5D,gDAAgD;IAChD,sBAAsB,GAAG,IAAI,eAAe,EAAW,CAAA;IAEvD,sDAAsD;IAC9C,eAAe,GAAG,IAAI,gBAAgB,EAAW,CAAA;IAEzD,6CAA6C;IAC7C,mCAAmC;IACnC,6CAA6C;IAE7C;;;OAGG;IACH,IAAI;QACF,MAAM,eAAe,GAAG,IAAI,eAAe,EAAW,CAAA;QACtD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QAC3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IAC3E,CAAC;IAED,gBAAgB,CAAC,OAA6B,EAAE,SAA2C,EAAE,UAA0B;QACrH,OAAO,IAAI,kBAAkB,CAAU,IAAI,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;IACjG,CAAC;CACF"}
|
|
@@ -4,10 +4,12 @@ import { GridBoundaries, MaterialItem, MoveItem } from '@gamepark/rules-api';
|
|
|
4
4
|
import { ItemContext } from '../../../locators';
|
|
5
5
|
import { ItemAnimations } from './ItemAnimations';
|
|
6
6
|
import { MaterialGameAnimationContext } from './MaterialGameAnimations';
|
|
7
|
+
import { Trajectory } from './Trajectory';
|
|
7
8
|
export declare class MoveItemAnimations<P extends number = number, M extends number = number, L extends number = number> extends ItemAnimations<P, M, L> {
|
|
8
9
|
protected duration: number;
|
|
9
10
|
protected droppedItemDuration: number;
|
|
10
|
-
|
|
11
|
+
protected trajectory?: Trajectory<P, M, L> | undefined;
|
|
12
|
+
constructor(duration?: number, droppedItemDuration?: number, trajectory?: Trajectory<P, M, L> | undefined);
|
|
11
13
|
getPreDuration(move: MoveItem<P, M, L>, context: MaterialGameAnimationContext<P, M, L>): number;
|
|
12
14
|
getItemAnimation(context: ItemContext<P, M, L>, animation: Animation<MoveItem<P, M, L>>, boundaries: GridBoundaries): Interpolation<Theme>;
|
|
13
15
|
getMovedItemAnimation(context: ItemContext<P, M, L>, animation: Animation<MoveItem<P, M, L>>, boundaries: GridBoundaries): Interpolation<Theme>;
|
|
@@ -8,10 +8,12 @@ import { transformItem } from './transformItem.util';
|
|
|
8
8
|
export class MoveItemAnimations extends ItemAnimations {
|
|
9
9
|
duration;
|
|
10
10
|
droppedItemDuration;
|
|
11
|
-
|
|
11
|
+
trajectory;
|
|
12
|
+
constructor(duration = 1, droppedItemDuration = 0.2, trajectory) {
|
|
12
13
|
super();
|
|
13
14
|
this.duration = duration;
|
|
14
15
|
this.droppedItemDuration = droppedItemDuration;
|
|
16
|
+
this.trajectory = trajectory;
|
|
15
17
|
}
|
|
16
18
|
getPreDuration(move, context) {
|
|
17
19
|
const potentialDroppedItem = { type: move.itemType, index: move.itemIndex };
|
|
@@ -57,8 +59,20 @@ export class MoveItemAnimations extends ItemAnimations {
|
|
|
57
59
|
if (currentOrigin.y !== futureOrigin.y) {
|
|
58
60
|
targetTransforms.unshift(`translateY(${getOriginDeltaPosition(boundaries.yMin, boundaries.yMax, futureOrigin.y, currentOrigin.y)}em)`);
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
// Check if trajectory is configured (either in this instance or in context)
|
|
63
|
+
const contextWithTrajectory = context;
|
|
64
|
+
const trajectory = this.trajectory ?? contextWithTrajectory.trajectory;
|
|
65
|
+
if (trajectory) {
|
|
66
|
+
// Use new trajectory-based animation (single div, integrated elevation)
|
|
67
|
+
const trajectoryContext = { ...context, trajectory };
|
|
68
|
+
const animationKeyframes = this.getTrajectoryKeyframes(currentTransforms, targetTransforms, animation, trajectoryContext);
|
|
69
|
+
return this.getAnimationCssWithTrajectory(animationKeyframes, animation.duration, trajectory.easing, trajectory.elevation);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Use legacy two-div animation
|
|
73
|
+
const animationKeyframes = this.getTransformKeyframes(currentTransforms.join(' '), targetTransforms.join(' '), animation, context);
|
|
74
|
+
return description?.getAnimationCss(animationKeyframes, animation.duration);
|
|
75
|
+
}
|
|
62
76
|
}
|
|
63
77
|
getItemIndexAfterMove({ rules }, move) {
|
|
64
78
|
const items = rules.game.items[move.itemType];
|
|
@@ -86,8 +100,18 @@ export class MoveItemAnimations extends ItemAnimations {
|
|
|
86
100
|
const originTransforms = transformItem(context);
|
|
87
101
|
const targetTransforms = description?.getItemTransform(item, futureContext) ?? [];
|
|
88
102
|
toClosestRotations(originTransforms, targetTransforms);
|
|
89
|
-
|
|
90
|
-
|
|
103
|
+
// Check if trajectory is configured
|
|
104
|
+
const contextWithTrajectory = context;
|
|
105
|
+
const trajectory = this.trajectory ?? contextWithTrajectory.trajectory;
|
|
106
|
+
if (trajectory) {
|
|
107
|
+
const trajectoryContext = { ...context, trajectory };
|
|
108
|
+
const animationKeyframes = this.getTrajectoryKeyframes(originTransforms, targetTransforms, animation, trajectoryContext);
|
|
109
|
+
return this.getAnimationCssWithTrajectory(animationKeyframes, animation.duration, trajectory.easing, trajectory.elevation);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const animationKeyframes = this.getTransformKeyframes(originTransforms.join(' '), targetTransforms.join(' '), animation, context);
|
|
113
|
+
return description?.getAnimationCss(animationKeyframes, animation.duration);
|
|
114
|
+
}
|
|
91
115
|
}
|
|
92
116
|
}
|
|
93
117
|
//# sourceMappingURL=MoveItemAnimations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoveItemAnimations.js","sourceRoot":"","sources":["../../../../src/components/material/animations/MoveItemAnimations.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAe,MAAM,mBAAmB,CAAA;AAC1G,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"MoveItemAnimations.js","sourceRoot":"","sources":["../../../../src/components/material/animations/MoveItemAnimations.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAe,MAAM,mBAAmB,CAAA;AAC1G,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,cAAc,EAA6B,MAAM,kBAAkB,CAAA;AAE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,oCAAoC;QACpC,MAAM,qBAAqB,GAAG,OAA6C,CAAA;QAC3E,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,qBAAqB,CAAC,UAAU,CAAA;QAEtE,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,iBAAiB,GAAuC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAA;YACxF,MAAM,kBAAkB,GAAG,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAA;YACxH,OAAO,IAAI,CAAC,6BAA6B,CAAC,kBAAkB,EAAE,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;QAC5H,CAAC;aAAM,CAAC;YACN,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;YACjI,OAAO,WAAW,EAAE,eAAe,CAAC,kBAAkB,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAA;QAC7E,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { Interpolation, Theme } from '@emotion/react';
|
|
2
2
|
import { Animation } from '@gamepark/react-client';
|
|
3
|
-
import { GridBoundaries, MoveItemsAtOnce } from '@gamepark/rules-api';
|
|
3
|
+
import { GridBoundaries, MaterialItem, MoveItemsAtOnce } from '@gamepark/rules-api';
|
|
4
4
|
import { ItemContext } from '../../../locators';
|
|
5
5
|
import { ItemAnimations } from './ItemAnimations';
|
|
6
6
|
import { MaterialGameAnimationContext } from './MaterialGameAnimations';
|
|
7
|
+
import { Trajectory } from './Trajectory';
|
|
7
8
|
export declare class MoveItemAtOnceAnimations<P extends number = number, M extends number = number, L extends number = number> extends ItemAnimations<P, M, L> {
|
|
8
9
|
protected duration: number;
|
|
10
|
+
protected trajectory?: Trajectory<P, M, L> | undefined;
|
|
9
11
|
protected droppedItemDuration: number;
|
|
10
|
-
constructor(duration?: number, droppedItemDuration?: number);
|
|
12
|
+
constructor(duration?: number, trajectory?: Trajectory<P, M, L> | undefined, droppedItemDuration?: number);
|
|
11
13
|
getPreDuration(move: MoveItemsAtOnce<P, M, L>, context: MaterialGameAnimationContext<P, M, L>): number;
|
|
12
14
|
getItemAnimation(context: ItemContext<P, M, L>, animation: Animation<MoveItemsAtOnce<P, M, L>>, boundaries: GridBoundaries): Interpolation<Theme>;
|
|
13
15
|
getMovedItemAnimation(context: ItemContext<P, M, L>, animation: Animation<MoveItemsAtOnce<P, M, L>>, boundaries: GridBoundaries): Interpolation<Theme>;
|
|
16
|
+
getChildItemAnimation(item: MaterialItem<P, L>, context: ItemContext<P, M, L>, animation: Animation<MoveItemsAtOnce<P, M, L>>): Interpolation<Theme>;
|
|
14
17
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { defaultOrigin, getItemFromContext, getOriginDeltaPosition } from '../../../locators';
|
|
2
2
|
import { isDroppedItem } from '../utils/isDroppedItem';
|
|
3
|
+
import { isPlacedOnItem } from '../utils/isPlacedOnItem';
|
|
3
4
|
import { ItemAnimations } from './ItemAnimations';
|
|
4
5
|
import { toClosestRotations, toSingleRotation } from './rotations.utils';
|
|
5
6
|
import { transformItem } from './transformItem.util';
|
|
6
7
|
export class MoveItemAtOnceAnimations extends ItemAnimations {
|
|
7
8
|
duration;
|
|
9
|
+
trajectory;
|
|
8
10
|
droppedItemDuration;
|
|
9
|
-
constructor(duration = 1, droppedItemDuration = 0.2) {
|
|
11
|
+
constructor(duration = 1, trajectory, droppedItemDuration = 0.2) {
|
|
10
12
|
super();
|
|
11
13
|
this.duration = duration;
|
|
14
|
+
this.trajectory = trajectory;
|
|
12
15
|
this.droppedItemDuration = droppedItemDuration;
|
|
13
16
|
}
|
|
14
17
|
getPreDuration(move, context) {
|
|
@@ -22,6 +25,13 @@ export class MoveItemAtOnceAnimations extends ItemAnimations {
|
|
|
22
25
|
if (context.type === animation.move.itemType && animation.move.indexes.includes(context.index)) {
|
|
23
26
|
return this.getMovedItemAnimation(context, animation, boundaries);
|
|
24
27
|
}
|
|
28
|
+
const item = getItemFromContext(context);
|
|
29
|
+
for (const index of animation.move.indexes) {
|
|
30
|
+
const animatedItemContext = { ...context, type: animation.move.itemType, index };
|
|
31
|
+
if (isPlacedOnItem(item, animatedItemContext)) {
|
|
32
|
+
return this.getChildItemAnimation(item, context, animation);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
getMovedItemAnimation(context, animation, boundaries) {
|
|
27
37
|
const { type, rules, material, player } = context;
|
|
@@ -44,8 +54,40 @@ export class MoveItemAtOnceAnimations extends ItemAnimations {
|
|
|
44
54
|
if (currentOrigin.y !== futureOrigin.y) {
|
|
45
55
|
targetTransforms.unshift(`translateY(${getOriginDeltaPosition(boundaries.yMin, boundaries.yMax, futureOrigin.y, currentOrigin.y)}em)`);
|
|
46
56
|
}
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
// Check if trajectory is configured
|
|
58
|
+
const contextWithTrajectory = context;
|
|
59
|
+
const trajectory = this.trajectory ?? contextWithTrajectory.trajectory;
|
|
60
|
+
if (trajectory) {
|
|
61
|
+
const trajectoryContext = { ...context, trajectory };
|
|
62
|
+
const animationKeyframes = this.getTrajectoryKeyframes(originTransforms, targetTransforms, animation, trajectoryContext);
|
|
63
|
+
return this.getAnimationCssWithTrajectory(animationKeyframes, animation.duration, trajectory.easing, trajectory.elevation);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const animationKeyframes = this.getTransformKeyframes(originTransforms.join(' '), targetTransforms.join(' '), animation, context);
|
|
67
|
+
return description?.getAnimationCss(animationKeyframes, animation.duration);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
getChildItemAnimation(item, context, animation) {
|
|
71
|
+
const { type, rules, material, player } = context;
|
|
72
|
+
const description = material[type];
|
|
73
|
+
const Rules = rules.constructor;
|
|
74
|
+
const futureRules = new Rules(JSON.parse(JSON.stringify(rules.game)), { player });
|
|
75
|
+
futureRules.play(animation.move);
|
|
76
|
+
const futureContext = { ...context, rules: futureRules };
|
|
77
|
+
const originTransforms = transformItem(context);
|
|
78
|
+
const targetTransforms = description?.getItemTransform(item, futureContext) ?? [];
|
|
79
|
+
toClosestRotations(originTransforms, targetTransforms);
|
|
80
|
+
const contextWithTrajectory = context;
|
|
81
|
+
const trajectory = this.trajectory ?? contextWithTrajectory.trajectory;
|
|
82
|
+
if (trajectory) {
|
|
83
|
+
const trajectoryContext = { ...context, trajectory };
|
|
84
|
+
const animationKeyframes = this.getTrajectoryKeyframes(originTransforms, targetTransforms, animation, trajectoryContext);
|
|
85
|
+
return this.getAnimationCssWithTrajectory(animationKeyframes, animation.duration, trajectory.easing, trajectory.elevation);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const animationKeyframes = this.getTransformKeyframes(originTransforms.join(' '), targetTransforms.join(' '), animation, context);
|
|
89
|
+
return description?.getAnimationCss(animationKeyframes, animation.duration);
|
|
90
|
+
}
|
|
49
91
|
}
|
|
50
92
|
}
|
|
51
93
|
//# sourceMappingURL=MoveItemAtOnceAnimations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoveItemAtOnceAnimations.js","sourceRoot":"","sources":["../../../../src/components/material/animations/MoveItemAtOnceAnimations.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAe,MAAM,mBAAmB,CAAA;AAC1G,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"MoveItemAtOnceAnimations.js","sourceRoot":"","sources":["../../../../src/components/material/animations/MoveItemAtOnceA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ChC,MAAM,aAAa,GAAG,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAA;QACxD,MAAM,gBAAgB,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;QAC/C,MAAM,gBAAgB,GAAG,WAAW,EAAE,gBAAgB,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAA;QACjF,kBAAkB,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAA;QAEtD,MAAM,qBAAqB,GAAG,OAA6C,CAAA;QAC3E,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,qBAAqB,CAAC,UAAU,CAAA;QAEtE,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,iBAAiB,GAAuC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAA;YACxF,MAAM,kBAAkB,GAAG,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAA;YACxH,OAAO,IAAI,CAAC,6BAA6B,CAAC,kBAAkB,EAAE,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;QAC5H,CAAC;aAAM,CAAC;YACN,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;YACjI,OAAO,WAAW,EAAE,eAAe,CAAC,kBAAkB,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAA;QAC7E,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { keyframes } from '@emotion/react';
|
|
2
|
+
import { Coordinates, Location, MaterialItem } from '@gamepark/rules-api';
|
|
3
|
+
import type { Locator } from '../../../locators';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the elevation arc during animation.
|
|
6
|
+
* The elevation is applied in world coordinates (before rotation transforms).
|
|
7
|
+
*/
|
|
8
|
+
export interface ElevationConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Maximum height of the arc in em units.
|
|
11
|
+
* @default 10
|
|
12
|
+
*/
|
|
13
|
+
height: number;
|
|
14
|
+
/**
|
|
15
|
+
* Position of the peak in the animation (0-1).
|
|
16
|
+
* @default 0.5
|
|
17
|
+
*/
|
|
18
|
+
peak?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Shape of the elevation curve.
|
|
21
|
+
* - 'parabolic': smooth parabolic arc (default)
|
|
22
|
+
* - 'linear': triangular arc with linear segments
|
|
23
|
+
* - 'ease': uses CSS ease timing for smoother feel
|
|
24
|
+
*/
|
|
25
|
+
curve?: 'parabolic' | 'linear' | 'ease';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A waypoint defines an intermediate position during an animation.
|
|
29
|
+
* @typeParam P - Player ID type
|
|
30
|
+
* @typeParam M - Material type (unused but kept for type consistency)
|
|
31
|
+
* @typeParam L - Location type
|
|
32
|
+
*/
|
|
33
|
+
export interface Waypoint<P extends number = number, M extends number = number, L extends number = number> {
|
|
34
|
+
/**
|
|
35
|
+
* Position in the animation timeline (0-1).
|
|
36
|
+
* 0 = start, 1 = end, 0.5 = middle
|
|
37
|
+
*/
|
|
38
|
+
at: number;
|
|
39
|
+
/**
|
|
40
|
+
* Use a locator instance to determine the position.
|
|
41
|
+
* The locator will be used with the provided location to compute coordinates.
|
|
42
|
+
*/
|
|
43
|
+
locator?: Locator<P, M, L>;
|
|
44
|
+
/**
|
|
45
|
+
* Location parameters to pass to the locator.
|
|
46
|
+
* Can be a static partial location, or a function receiving the animated item
|
|
47
|
+
* to derive location dynamically (e.g., to preserve coordinates from origin).
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // Static location
|
|
51
|
+
* { locator: LocationType.Panel, location: { player: nextPlayer } }
|
|
52
|
+
*
|
|
53
|
+
* // Dynamic: preserve x from item's current location
|
|
54
|
+
* { locator: LocationType.FaceDown, location: (item) => ({ x: item.location.x }) }
|
|
55
|
+
*/
|
|
56
|
+
location?: Partial<Location<P, L>> | ((item: MaterialItem<P, L>) => Partial<Location<P, L>>);
|
|
57
|
+
/**
|
|
58
|
+
* Absolute coordinates for this waypoint.
|
|
59
|
+
* Use this instead of locator for fixed positions.
|
|
60
|
+
*/
|
|
61
|
+
coordinates?: Partial<Coordinates>;
|
|
62
|
+
/**
|
|
63
|
+
* Offset relative to the linear interpolation between origin and destination.
|
|
64
|
+
* Useful for creating arcs or detours without specifying absolute positions.
|
|
65
|
+
*/
|
|
66
|
+
offset?: Partial<Coordinates>;
|
|
67
|
+
/**
|
|
68
|
+
* Override the elevation at this specific waypoint.
|
|
69
|
+
* If not specified, uses the global elevation curve.
|
|
70
|
+
*/
|
|
71
|
+
elevation?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Z-axis rotation at this waypoint (in the locator's rotation unit).
|
|
74
|
+
* If not specified, rotation is interpolated linearly.
|
|
75
|
+
*/
|
|
76
|
+
rotation?: number;
|
|
77
|
+
/**
|
|
78
|
+
* CSS easing function to use when animating TOWARDS this waypoint.
|
|
79
|
+
* @example 'ease-in', 'ease-out', 'cubic-bezier(0.4, 0, 0.2, 1)'
|
|
80
|
+
*/
|
|
81
|
+
easing?: string;
|
|
82
|
+
/** @internal Type brand to ensure M is used */
|
|
83
|
+
_brand?: M;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Complete trajectory configuration for an animation.
|
|
87
|
+
* @typeParam P - Player ID type
|
|
88
|
+
* @typeParam M - Material type (unused but kept for type consistency)
|
|
89
|
+
* @typeParam L - Location type
|
|
90
|
+
*/
|
|
91
|
+
export interface Trajectory<P extends number = number, M extends number = number, L extends number = number> {
|
|
92
|
+
/**
|
|
93
|
+
* Elevation configuration for the arc effect.
|
|
94
|
+
* Set to false to disable elevation (flat movement).
|
|
95
|
+
*/
|
|
96
|
+
elevation?: ElevationConfig | false;
|
|
97
|
+
/**
|
|
98
|
+
* Intermediate waypoints for the trajectory.
|
|
99
|
+
* Waypoints are sorted by their 'at' value automatically.
|
|
100
|
+
*/
|
|
101
|
+
waypoints?: Waypoint<P, M, L>[];
|
|
102
|
+
/**
|
|
103
|
+
* Global CSS easing function for the animation.
|
|
104
|
+
* @default 'ease-in-out'
|
|
105
|
+
*/
|
|
106
|
+
easing?: string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Default elevation configuration (arc of 10em at 50%).
|
|
110
|
+
*/
|
|
111
|
+
export declare const defaultElevation: ElevationConfig;
|
|
112
|
+
/**
|
|
113
|
+
* Calculate the elevation value at a given point in time.
|
|
114
|
+
* @param t Progress in the animation (0-1)
|
|
115
|
+
* @param config Elevation configuration
|
|
116
|
+
* @returns Elevation in em units
|
|
117
|
+
*/
|
|
118
|
+
export declare function calculateElevation(t: number, config: ElevationConfig | false | undefined): number;
|
|
119
|
+
/**
|
|
120
|
+
* Parse a transform string and extract x, y, z translations.
|
|
121
|
+
* This is used to interpolate between waypoints.
|
|
122
|
+
*/
|
|
123
|
+
export declare function extractTranslation(transforms: string[]): Coordinates;
|
|
124
|
+
/**
|
|
125
|
+
* Generate simple elevation keyframes for the parent div.
|
|
126
|
+
* Creates a 3-keyframe arc: from (0) → peak (height) → to (0).
|
|
127
|
+
*/
|
|
128
|
+
export declare function getElevationKeyframes(config: ElevationConfig): ReturnType<typeof keyframes>;
|
|
129
|
+
/**
|
|
130
|
+
* Interpolate between two coordinate values.
|
|
131
|
+
*/
|
|
132
|
+
export declare function interpolateCoordinate(from: number, to: number, t: number): number;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { keyframes } from '@emotion/react';
|
|
2
|
+
/**
|
|
3
|
+
* Default elevation configuration (arc of 10em at 50%).
|
|
4
|
+
*/
|
|
5
|
+
export const defaultElevation = {
|
|
6
|
+
height: 10,
|
|
7
|
+
peak: 0.5,
|
|
8
|
+
curve: 'parabolic'
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Calculate the elevation value at a given point in time.
|
|
12
|
+
* @param t Progress in the animation (0-1)
|
|
13
|
+
* @param config Elevation configuration
|
|
14
|
+
* @returns Elevation in em units
|
|
15
|
+
*/
|
|
16
|
+
export function calculateElevation(t, config) {
|
|
17
|
+
if (config === false)
|
|
18
|
+
return 0;
|
|
19
|
+
const { height, peak = 0.5, curve = 'parabolic' } = config ?? defaultElevation;
|
|
20
|
+
if (curve === 'linear') {
|
|
21
|
+
// Triangular arc
|
|
22
|
+
if (t <= peak) {
|
|
23
|
+
return height * (t / peak);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return height * (1 - (t - peak) / (1 - peak));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Parabolic arc (default)
|
|
30
|
+
// Parabola passing through (0, 0), (peak, height), (1, 0)
|
|
31
|
+
if (t <= peak) {
|
|
32
|
+
const normalized = t / peak;
|
|
33
|
+
return height * (1 - (1 - normalized) * (1 - normalized));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const normalized = (t - peak) / (1 - peak);
|
|
37
|
+
return height * (1 - normalized * normalized);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parse a transform string and extract x, y, z translations.
|
|
42
|
+
* This is used to interpolate between waypoints.
|
|
43
|
+
*/
|
|
44
|
+
export function extractTranslation(transforms) {
|
|
45
|
+
let x = 0, y = 0, z = 0;
|
|
46
|
+
for (const transform of transforms) {
|
|
47
|
+
const translate3dMatch = transform.match(/translate3d\(\s*([-\d.]+)em\s*,\s*([-\d.]+)em\s*,\s*([-\d.]+)em\s*\)/);
|
|
48
|
+
if (translate3dMatch) {
|
|
49
|
+
x += parseFloat(translate3dMatch[1]);
|
|
50
|
+
y += parseFloat(translate3dMatch[2]);
|
|
51
|
+
z += parseFloat(translate3dMatch[3]);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const translateXMatch = transform.match(/translateX\(\s*([-\d.]+)em\s*\)/);
|
|
55
|
+
if (translateXMatch) {
|
|
56
|
+
x += parseFloat(translateXMatch[1]);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const translateYMatch = transform.match(/translateY\(\s*([-\d.]+)em\s*\)/);
|
|
60
|
+
if (translateYMatch) {
|
|
61
|
+
y += parseFloat(translateYMatch[1]);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const translateZMatch = transform.match(/translateZ\(\s*([-\d.]+)em\s*\)/);
|
|
65
|
+
if (translateZMatch) {
|
|
66
|
+
z += parseFloat(translateZMatch[1]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { x, y, z };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Generate simple elevation keyframes for the parent div.
|
|
73
|
+
* Creates a 3-keyframe arc: from (0) → peak (height) → to (0).
|
|
74
|
+
*/
|
|
75
|
+
export function getElevationKeyframes(config) {
|
|
76
|
+
const { height, peak = 0.5 } = config;
|
|
77
|
+
const peakPercent = Math.round(peak * 100);
|
|
78
|
+
const frames = `from, to { transform: translateZ(0); } ${peakPercent}% { transform: translateZ(${height}em); }`;
|
|
79
|
+
return keyframes `${frames}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Interpolate between two coordinate values.
|
|
83
|
+
*/
|
|
84
|
+
export function interpolateCoordinate(from, to, t) {
|
|
85
|
+
return from + (to - from) * t;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=Trajectory.js.map
|