@elementor/editor-interactions 4.1.0-698 → 4.1.0-700

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-interactions",
3
- "version": "4.1.0-698",
3
+ "version": "4.1.0-700",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,19 +39,19 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor-controls": "4.1.0-698",
43
- "@elementor/editor-elements": "4.1.0-698",
44
- "@elementor/editor-mcp": "4.1.0-698",
45
- "@elementor/editor-props": "4.1.0-698",
46
- "@elementor/editor-responsive": "4.1.0-698",
47
- "@elementor/editor-ui": "4.1.0-698",
48
- "@elementor/editor-v1-adapters": "4.1.0-698",
42
+ "@elementor/editor-controls": "4.1.0-700",
43
+ "@elementor/editor-elements": "4.1.0-700",
44
+ "@elementor/editor-mcp": "4.1.0-700",
45
+ "@elementor/editor-props": "4.1.0-700",
46
+ "@elementor/editor-responsive": "4.1.0-700",
47
+ "@elementor/editor-ui": "4.1.0-700",
48
+ "@elementor/editor-v1-adapters": "4.1.0-700",
49
49
  "@elementor/icons": "^1.68.0",
50
- "@elementor/schema": "4.1.0-698",
51
- "@elementor/session": "4.1.0-698",
50
+ "@elementor/schema": "4.1.0-700",
51
+ "@elementor/session": "4.1.0-700",
52
52
  "@elementor/ui": "1.36.17",
53
- "@elementor/utils": "4.1.0-698",
54
- "@elementor/events": "4.1.0-698",
53
+ "@elementor/utils": "4.1.0-700",
54
+ "@elementor/events": "4.1.0-700",
55
55
  "@wordpress/i18n": "^5.13.0"
56
56
  },
57
57
  "peerDependencies": {
@@ -25,7 +25,7 @@ export const proSchema = {
25
25
  .optional()
26
26
  .describe( 'Event that triggers the animation' ),
27
27
  effect: z.enum( [ 'fade', 'slide', 'scale', 'custom' ] ).optional().describe( 'Animation effect type' ),
28
- customEffect: z
28
+ customEffects: z
29
29
  .object( {
30
30
  keyframes: z
31
31
  .array(
@@ -0,0 +1,145 @@
1
+ import { type PropValue } from '@elementor/editor-props';
2
+
3
+ const CUSTOM_EFFECT_TYPE = 'custom-effect';
4
+ const KEYFRAMES_TYPE = 'keyframes';
5
+ const KEYFRAME_STOP_TYPE = 'keyframe-stop';
6
+ const KEYFRAME_STOP_SETTINGS_TYPE = 'keyframe-stop-settings';
7
+ const SIZE_TYPE = 'size';
8
+ const NUMBER_TYPE = 'number';
9
+ const TRANSFORM_SCALE_TYPE = 'transform-scale';
10
+ const TRANSFORM_ROTATE_TYPE = 'transform-rotate';
11
+ const TRANSFORM_MOVE_TYPE = 'transform-move';
12
+ const TRANSFORM_SKEW_TYPE = 'transform-skew';
13
+ const UNIT_PERCENT = '%';
14
+ const UNIT_DEG = 'deg';
15
+ const UNIT_PX = 'px';
16
+
17
+ export type PlainKeyframeValue = {
18
+ opacity?: number;
19
+ scale?: { x: number; y: number };
20
+ rotate?: { x: number; y: number; z: number };
21
+ move?: { x: number; y: number; z: number };
22
+ skew?: { x: number; y: number };
23
+ };
24
+
25
+ export type PlainKeyframe = { stop: number; value: PlainKeyframeValue };
26
+
27
+ export type PlainCustomEffect = { keyframes: PlainKeyframe[] };
28
+
29
+ const isPlainCustomEffect = ( v: unknown ): v is PlainCustomEffect =>
30
+ typeof v === 'object' &&
31
+ v !== null &&
32
+ 'keyframes' in v &&
33
+ Array.isArray( ( v as PlainCustomEffect ).keyframes ) &&
34
+ ! ( '$$type' in v );
35
+
36
+ const toSizePropValue = ( size: number, unit: string = UNIT_PERCENT ): PropValue => ( {
37
+ $$type: SIZE_TYPE,
38
+ value: { size, unit },
39
+ } );
40
+
41
+ const toNumberPropValue = ( n: number ): PropValue => ( {
42
+ $$type: NUMBER_TYPE,
43
+ value: n,
44
+ } );
45
+
46
+ const toDimensionalNumberPropValue = (
47
+ type: string,
48
+ plain: { x?: number; y?: number; z?: number },
49
+ defaults: { x: number; y: number; z: number }
50
+ ): PropValue => ( {
51
+ $$type: type,
52
+ value: {
53
+ x: toNumberPropValue( plain.x ?? defaults.x ),
54
+ y: toNumberPropValue( plain.y ?? defaults.y ),
55
+ z: toNumberPropValue( plain.z ?? defaults.z ),
56
+ },
57
+ } );
58
+
59
+ const toDimensionalSizePropValue = (
60
+ type: string,
61
+ plain: { x?: number; y?: number; z?: number },
62
+ defaults: { x: number; y: number; z: number },
63
+ unit: string
64
+ ): PropValue => ( {
65
+ $$type: type,
66
+ value: {
67
+ x: toSizePropValue( plain.x ?? defaults.x, unit ),
68
+ y: toSizePropValue( plain.y ?? defaults.y, unit ),
69
+ z: toSizePropValue( plain.z ?? defaults.z, unit ),
70
+ },
71
+ } );
72
+
73
+ const toSkewPropValue = ( plain: { x?: number; y?: number } ): PropValue => ( {
74
+ $$type: TRANSFORM_SKEW_TYPE,
75
+ value: {
76
+ x: toSizePropValue( plain.x ?? 0, UNIT_DEG ),
77
+ y: toSizePropValue( plain.y ?? 0, UNIT_DEG ),
78
+ },
79
+ } );
80
+
81
+ const toKeyframeStopSettingsPropValue = ( plain: PlainKeyframeValue ): PropValue => {
82
+ const value: Record< string, PropValue > = {};
83
+ if ( plain.opacity !== undefined ) {
84
+ const percent = plain.opacity <= 1 ? Math.round( plain.opacity * 100 ) : plain.opacity;
85
+ value.opacity = toSizePropValue( percent );
86
+ }
87
+ if ( plain.scale !== undefined ) {
88
+ value.scale = toDimensionalNumberPropValue( TRANSFORM_SCALE_TYPE, plain.scale, { x: 1, y: 1, z: 1 } );
89
+ }
90
+ if ( plain.rotate !== undefined ) {
91
+ value.rotate = toDimensionalSizePropValue(
92
+ TRANSFORM_ROTATE_TYPE,
93
+ plain.rotate,
94
+ { x: 0, y: 0, z: 0 },
95
+ UNIT_DEG
96
+ );
97
+ }
98
+ if ( plain.move !== undefined ) {
99
+ value.move = toDimensionalSizePropValue( TRANSFORM_MOVE_TYPE, plain.move, { x: 0, y: 0, z: 0 }, UNIT_PX );
100
+ }
101
+ if ( plain.skew !== undefined ) {
102
+ value.skew = toSkewPropValue( plain.skew );
103
+ }
104
+ return { $$type: KEYFRAME_STOP_SETTINGS_TYPE, value };
105
+ };
106
+
107
+ const isPlainKeyframe = ( v: unknown ): v is PlainKeyframe =>
108
+ typeof v === 'object' && v !== null && 'stop' in v && 'value' in v && ! ( '$$type' in v );
109
+
110
+ const toKeyframeStopPropValue = ( item: PlainKeyframe | PropValue ): PropValue => {
111
+ if ( ! isPlainKeyframe( item ) ) {
112
+ return item as PropValue;
113
+ }
114
+ return {
115
+ $$type: KEYFRAME_STOP_TYPE,
116
+ value: {
117
+ stop: toSizePropValue( item.stop ),
118
+ settings: toKeyframeStopSettingsPropValue( item.value ),
119
+ },
120
+ };
121
+ };
122
+
123
+ const toKeyframesPropValue = ( keyframes: ( PlainKeyframe | PropValue )[] ): PropValue => ( {
124
+ $$type: KEYFRAMES_TYPE,
125
+ value: keyframes.map( toKeyframeStopPropValue ),
126
+ } );
127
+
128
+ const plainCustomEffectToPropValue = ( plain: PlainCustomEffect ): PropValue => ( {
129
+ $$type: CUSTOM_EFFECT_TYPE,
130
+ value: {
131
+ keyframes: toKeyframesPropValue( plain.keyframes as ( PlainKeyframe | PropValue )[] ),
132
+ },
133
+ } );
134
+
135
+ export const toCustomEffectPropValue = (
136
+ customEffects: PropValue | PlainCustomEffect | undefined
137
+ ): PropValue | undefined => {
138
+ if ( customEffects === undefined ) {
139
+ return undefined;
140
+ }
141
+ if ( isPlainCustomEffect( customEffects ) ) {
142
+ return plainCustomEffectToPropValue( customEffects );
143
+ }
144
+ return customEffects as PropValue;
145
+ };
@@ -17,6 +17,7 @@ import {
17
17
  type TimingConfigPropValue,
18
18
  } from '../types';
19
19
  import { formatSizeValue, parseSizeValue } from '../utils/size-transform-utils';
20
+ import { type PlainCustomEffect, toCustomEffectPropValue } from './custom-effect-to-prop-value';
20
21
  import { getInteractionsConfig } from './get-interactions-config';
21
22
  import { generateTempInteractionId } from './temp-id-utils';
22
23
 
@@ -46,7 +47,7 @@ export const createBoolean = ( value: boolean ): BooleanPropValue => ( {
46
47
  export const createConfig = ( {
47
48
  replay,
48
49
  easing = 'easeIn',
49
- relativeTo = '',
50
+ relativeTo = 'viewport',
50
51
  repeat = '',
51
52
  times = 1,
52
53
  start = 85,
@@ -128,26 +129,29 @@ export const createAnimationPreset = ( {
128
129
  times?: number;
129
130
  start?: SizeStringValue;
130
131
  end?: SizeStringValue;
131
- customEffects?: PropValue;
132
- } ): AnimationPresetPropValue => ( {
133
- $$type: 'animation-preset-props',
134
- value: {
135
- effect: createString( effect ),
136
- custom_effect: customEffects,
137
- type: createString( type ),
138
- direction: createString( direction ?? '' ),
139
- timing_config: createTimingConfig( duration, delay ),
140
- config: createConfig( {
141
- replay,
142
- easing,
143
- relativeTo,
144
- repeat,
145
- times,
146
- start,
147
- end,
148
- } ),
149
- },
150
- } );
132
+ customEffects?: PropValue | PlainCustomEffect;
133
+ } ): AnimationPresetPropValue => {
134
+ const customEffectProp = toCustomEffectPropValue( customEffects );
135
+ return {
136
+ $$type: 'animation-preset-props',
137
+ value: {
138
+ effect: createString( effect ),
139
+ ...( customEffectProp !== undefined && { custom_effect: customEffectProp } ),
140
+ type: createString( type ),
141
+ direction: createString( direction ?? '' ),
142
+ timing_config: createTimingConfig( duration, delay ),
143
+ config: createConfig( {
144
+ replay,
145
+ easing,
146
+ relativeTo,
147
+ repeat,
148
+ times,
149
+ start,
150
+ end,
151
+ } ),
152
+ },
153
+ };
154
+ };
151
155
 
152
156
  export const createInteractionItem = ( {
153
157
  trigger,
@@ -182,7 +186,7 @@ export const createInteractionItem = ( {
182
186
  start?: number;
183
187
  end?: number;
184
188
  excludedBreakpoints?: string[];
185
- customEffects?: PropValue;
189
+ customEffects?: PropValue | PlainCustomEffect;
186
190
  } ): InteractionItemPropValue => ( {
187
191
  $$type: 'interaction-item',
188
192
  value: {