@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/dist/index.mjs CHANGED
@@ -115,6 +115,110 @@ var createSizeValue = (size, unit) => {
115
115
  return { size, unit };
116
116
  };
117
117
 
118
+ // src/utils/custom-effect-to-prop-value.ts
119
+ var CUSTOM_EFFECT_TYPE = "custom-effect";
120
+ var KEYFRAMES_TYPE = "keyframes";
121
+ var KEYFRAME_STOP_TYPE = "keyframe-stop";
122
+ var KEYFRAME_STOP_SETTINGS_TYPE = "keyframe-stop-settings";
123
+ var SIZE_TYPE = "size";
124
+ var NUMBER_TYPE = "number";
125
+ var TRANSFORM_SCALE_TYPE = "transform-scale";
126
+ var TRANSFORM_ROTATE_TYPE = "transform-rotate";
127
+ var TRANSFORM_MOVE_TYPE = "transform-move";
128
+ var TRANSFORM_SKEW_TYPE = "transform-skew";
129
+ var UNIT_PERCENT = "%";
130
+ var UNIT_DEG = "deg";
131
+ var UNIT_PX = "px";
132
+ var isPlainCustomEffect = (v) => typeof v === "object" && v !== null && "keyframes" in v && Array.isArray(v.keyframes) && !("$$type" in v);
133
+ var toSizePropValue = (size, unit = UNIT_PERCENT) => ({
134
+ $$type: SIZE_TYPE,
135
+ value: { size, unit }
136
+ });
137
+ var toNumberPropValue = (n) => ({
138
+ $$type: NUMBER_TYPE,
139
+ value: n
140
+ });
141
+ var toDimensionalNumberPropValue = (type, plain, defaults) => ({
142
+ $$type: type,
143
+ value: {
144
+ x: toNumberPropValue(plain.x ?? defaults.x),
145
+ y: toNumberPropValue(plain.y ?? defaults.y),
146
+ z: toNumberPropValue(plain.z ?? defaults.z)
147
+ }
148
+ });
149
+ var toDimensionalSizePropValue = (type, plain, defaults, unit) => ({
150
+ $$type: type,
151
+ value: {
152
+ x: toSizePropValue(plain.x ?? defaults.x, unit),
153
+ y: toSizePropValue(plain.y ?? defaults.y, unit),
154
+ z: toSizePropValue(plain.z ?? defaults.z, unit)
155
+ }
156
+ });
157
+ var toSkewPropValue = (plain) => ({
158
+ $$type: TRANSFORM_SKEW_TYPE,
159
+ value: {
160
+ x: toSizePropValue(plain.x ?? 0, UNIT_DEG),
161
+ y: toSizePropValue(plain.y ?? 0, UNIT_DEG)
162
+ }
163
+ });
164
+ var toKeyframeStopSettingsPropValue = (plain) => {
165
+ const value = {};
166
+ if (plain.opacity !== void 0) {
167
+ const percent = plain.opacity <= 1 ? Math.round(plain.opacity * 100) : plain.opacity;
168
+ value.opacity = toSizePropValue(percent);
169
+ }
170
+ if (plain.scale !== void 0) {
171
+ value.scale = toDimensionalNumberPropValue(TRANSFORM_SCALE_TYPE, plain.scale, { x: 1, y: 1, z: 1 });
172
+ }
173
+ if (plain.rotate !== void 0) {
174
+ value.rotate = toDimensionalSizePropValue(
175
+ TRANSFORM_ROTATE_TYPE,
176
+ plain.rotate,
177
+ { x: 0, y: 0, z: 0 },
178
+ UNIT_DEG
179
+ );
180
+ }
181
+ if (plain.move !== void 0) {
182
+ value.move = toDimensionalSizePropValue(TRANSFORM_MOVE_TYPE, plain.move, { x: 0, y: 0, z: 0 }, UNIT_PX);
183
+ }
184
+ if (plain.skew !== void 0) {
185
+ value.skew = toSkewPropValue(plain.skew);
186
+ }
187
+ return { $$type: KEYFRAME_STOP_SETTINGS_TYPE, value };
188
+ };
189
+ var isPlainKeyframe = (v) => typeof v === "object" && v !== null && "stop" in v && "value" in v && !("$$type" in v);
190
+ var toKeyframeStopPropValue = (item) => {
191
+ if (!isPlainKeyframe(item)) {
192
+ return item;
193
+ }
194
+ return {
195
+ $$type: KEYFRAME_STOP_TYPE,
196
+ value: {
197
+ stop: toSizePropValue(item.stop),
198
+ settings: toKeyframeStopSettingsPropValue(item.value)
199
+ }
200
+ };
201
+ };
202
+ var toKeyframesPropValue = (keyframes) => ({
203
+ $$type: KEYFRAMES_TYPE,
204
+ value: keyframes.map(toKeyframeStopPropValue)
205
+ });
206
+ var plainCustomEffectToPropValue = (plain) => ({
207
+ $$type: CUSTOM_EFFECT_TYPE,
208
+ value: {
209
+ keyframes: toKeyframesPropValue(plain.keyframes)
210
+ }
211
+ });
212
+ var toCustomEffectPropValue = (customEffects) => {
213
+ if (customEffects === void 0) {
214
+ return void 0;
215
+ }
216
+ if (isPlainCustomEffect(customEffects)) {
217
+ return plainCustomEffectToPropValue(customEffects);
218
+ }
219
+ return customEffects;
220
+ };
221
+
118
222
  // src/utils/get-interactions-config.ts
119
223
  function getInteractionsConfig() {
120
224
  return window.ElementorInteractionsConfig ?? {};
@@ -153,7 +257,7 @@ var createBoolean = (value) => ({
153
257
  var createConfig = ({
154
258
  replay,
155
259
  easing = "easeIn",
156
- relativeTo = "",
260
+ relativeTo = "viewport",
157
261
  repeat = "",
158
262
  times = 1,
159
263
  start = 85,
@@ -206,25 +310,28 @@ var createAnimationPreset = ({
206
310
  start,
207
311
  end,
208
312
  customEffects
209
- }) => ({
210
- $$type: "animation-preset-props",
211
- value: {
212
- effect: createString(effect),
213
- custom_effect: customEffects,
214
- type: createString(type),
215
- direction: createString(direction ?? ""),
216
- timing_config: createTimingConfig(duration, delay),
217
- config: createConfig({
218
- replay,
219
- easing,
220
- relativeTo,
221
- repeat,
222
- times,
223
- start,
224
- end
225
- })
226
- }
227
- });
313
+ }) => {
314
+ const customEffectProp = toCustomEffectPropValue(customEffects);
315
+ return {
316
+ $$type: "animation-preset-props",
317
+ value: {
318
+ effect: createString(effect),
319
+ ...customEffectProp !== void 0 && { custom_effect: customEffectProp },
320
+ type: createString(type),
321
+ direction: createString(direction ?? ""),
322
+ timing_config: createTimingConfig(duration, delay),
323
+ config: createConfig({
324
+ replay,
325
+ easing,
326
+ relativeTo,
327
+ repeat,
328
+ times,
329
+ start,
330
+ end
331
+ })
332
+ }
333
+ };
334
+ };
228
335
  var createInteractionItem = ({
229
336
  trigger,
230
337
  effect,
@@ -1644,7 +1751,7 @@ var baseSchema = {
1644
1751
  var proSchema = {
1645
1752
  trigger: z.enum(["load", "scrollIn", "scrollOut", "scrollOn", "hover", "click"]).optional().describe("Event that triggers the animation"),
1646
1753
  effect: z.enum(["fade", "slide", "scale", "custom"]).optional().describe("Animation effect type"),
1647
- customEffect: z.object({
1754
+ customEffects: z.object({
1648
1755
  keyframes: z.array(
1649
1756
  z.object({
1650
1757
  stop: z.number().describe("The stop of the keyframe in percent, can be either 0 or 100"),