@builder.io/sdk-solid 0.12.5 → 0.12.7

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.
@@ -107,7 +107,7 @@ import { createContext as createContext2 } from "solid-js";
107
107
  var components_context_default = createContext2({ registeredComponents: {} });
108
108
 
109
109
  // src/components/block/block.tsx
110
- import { Show as Show4, For as For2, createSignal as createSignal4 } from "solid-js";
110
+ import { Show as Show4, For as For2, onMount, createSignal as createSignal4 } from "solid-js";
111
111
 
112
112
  // src/functions/get-block-component-options.ts
113
113
  function getBlockComponentOptions(block) {
@@ -237,27 +237,43 @@ var runInBrowser = ({
237
237
  builder,
238
238
  context,
239
239
  event,
240
- state: flattenState(rootState, localState, rootSetState)
240
+ state: flattenState({
241
+ rootState,
242
+ localState,
243
+ rootSetState
244
+ })
241
245
  });
242
246
  return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
243
247
  };
244
- function flattenState(rootState, localState, rootSetState) {
245
- if (rootState === localState) {
246
- throw new Error("rootState === localState");
247
- }
248
+ function flattenState({
249
+ rootState,
250
+ localState,
251
+ rootSetState
252
+ }) {
248
253
  return new Proxy(rootState, {
249
- get: (_, prop) => {
254
+ get: (target, prop) => {
250
255
  if (localState && prop in localState) {
251
256
  return localState[prop];
252
257
  }
253
- return rootState[prop];
258
+ const val = target[prop];
259
+ if (typeof val === "object") {
260
+ return flattenState({
261
+ rootState: val,
262
+ localState: void 0,
263
+ rootSetState: rootSetState ? (subState) => {
264
+ target[prop] = subState;
265
+ rootSetState(target);
266
+ } : void 0
267
+ });
268
+ }
269
+ return val;
254
270
  },
255
- set: (_, prop, value) => {
271
+ set: (target, prop, value) => {
256
272
  if (localState && prop in localState) {
257
273
  throw new Error("Writing to local state is not allowed as it is read-only.");
258
274
  }
259
- rootState[prop] = value;
260
- rootSetState?.(rootState);
275
+ target[prop] = value;
276
+ rootSetState?.(target);
261
277
  return true;
262
278
  }
263
279
  });
@@ -3547,6 +3563,211 @@ function getProcessedBlock({
3547
3563
  }
3548
3564
  }
3549
3565
 
3566
+ // src/components/block/animator.ts
3567
+ function throttle(func, wait, options = {}) {
3568
+ let context;
3569
+ let args;
3570
+ let result;
3571
+ let timeout = null;
3572
+ let previous = 0;
3573
+ const later = function() {
3574
+ previous = options.leading === false ? 0 : Date.now();
3575
+ timeout = null;
3576
+ result = func.apply(context, args);
3577
+ if (!timeout)
3578
+ context = args = null;
3579
+ };
3580
+ return function() {
3581
+ const now = Date.now();
3582
+ if (!previous && options.leading === false)
3583
+ previous = now;
3584
+ const remaining = wait - (now - previous);
3585
+ context = this;
3586
+ args = arguments;
3587
+ if (remaining <= 0 || remaining > wait) {
3588
+ if (timeout) {
3589
+ clearTimeout(timeout);
3590
+ timeout = null;
3591
+ }
3592
+ previous = now;
3593
+ result = func.apply(context, args);
3594
+ if (!timeout)
3595
+ context = args = null;
3596
+ } else if (!timeout && options.trailing !== false) {
3597
+ timeout = setTimeout(later, remaining);
3598
+ }
3599
+ return result;
3600
+ };
3601
+ }
3602
+ function assign(target, ..._args) {
3603
+ const to = Object(target);
3604
+ for (let index = 1; index < arguments.length; index++) {
3605
+ const nextSource = arguments[index];
3606
+ if (nextSource != null) {
3607
+ for (const nextKey in nextSource) {
3608
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
3609
+ to[nextKey] = nextSource[nextKey];
3610
+ }
3611
+ }
3612
+ }
3613
+ }
3614
+ return to;
3615
+ }
3616
+ var camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) : "";
3617
+ function bindAnimations(animations) {
3618
+ for (const animation of animations) {
3619
+ switch (animation.trigger) {
3620
+ case "pageLoad":
3621
+ triggerAnimation(animation);
3622
+ break;
3623
+ case "hover":
3624
+ bindHoverAnimation(animation);
3625
+ break;
3626
+ case "scrollInView":
3627
+ bindScrollInViewAnimation(animation);
3628
+ break;
3629
+ }
3630
+ }
3631
+ }
3632
+ function warnElementNotPresent(id2) {
3633
+ }
3634
+ function augmentAnimation(animation, element) {
3635
+ const stylesUsed = getAllStylesUsed(animation);
3636
+ const computedStyle = getComputedStyle(element);
3637
+ const firstStyles = animation.steps[0].styles;
3638
+ const lastStyles = animation.steps[animation.steps.length - 1].styles;
3639
+ const bothStyles = [firstStyles, lastStyles];
3640
+ for (const styles of bothStyles) {
3641
+ for (const style of stylesUsed) {
3642
+ if (!(style in styles)) {
3643
+ styles[style] = computedStyle[style];
3644
+ }
3645
+ }
3646
+ }
3647
+ }
3648
+ function getAllStylesUsed(animation) {
3649
+ const properties = [];
3650
+ for (const step of animation.steps) {
3651
+ for (const key in step.styles) {
3652
+ if (properties.indexOf(key) === -1) {
3653
+ properties.push(key);
3654
+ }
3655
+ }
3656
+ }
3657
+ return properties;
3658
+ }
3659
+ function triggerAnimation(animation) {
3660
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
3661
+ if (!elements.length) {
3662
+ warnElementNotPresent(animation.elementId || animation.id || "");
3663
+ return;
3664
+ }
3665
+ Array.from(elements).forEach((element) => {
3666
+ augmentAnimation(animation, element);
3667
+ element.style.transition = "none";
3668
+ element.style.transitionDelay = "0";
3669
+ assign(element.style, animation.steps[0].styles);
3670
+ setTimeout(() => {
3671
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
3672
+ if (animation.delay) {
3673
+ element.style.transitionDelay = animation.delay + "s";
3674
+ }
3675
+ assign(element.style, animation.steps[1].styles);
3676
+ setTimeout(() => {
3677
+ element.style.transition = "";
3678
+ element.style.transitionDelay = "";
3679
+ }, (animation.delay || 0) * 1e3 + animation.duration * 1e3 + 100);
3680
+ });
3681
+ });
3682
+ }
3683
+ function bindHoverAnimation(animation) {
3684
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
3685
+ if (!elements.length) {
3686
+ warnElementNotPresent(animation.elementId || animation.id || "");
3687
+ return;
3688
+ }
3689
+ Array.from(elements).forEach((element) => {
3690
+ augmentAnimation(animation, element);
3691
+ const defaultState = animation.steps[0].styles;
3692
+ const hoverState = animation.steps[1].styles;
3693
+ function attachDefaultState() {
3694
+ assign(element.style, defaultState);
3695
+ }
3696
+ function attachHoverState() {
3697
+ assign(element.style, hoverState);
3698
+ }
3699
+ attachDefaultState();
3700
+ element.addEventListener("mouseenter", attachHoverState);
3701
+ element.addEventListener("mouseleave", attachDefaultState);
3702
+ setTimeout(() => {
3703
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
3704
+ if (animation.delay) {
3705
+ element.style.transitionDelay = animation.delay + "s";
3706
+ }
3707
+ });
3708
+ });
3709
+ }
3710
+ function bindScrollInViewAnimation(animation) {
3711
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
3712
+ if (!elements.length) {
3713
+ warnElementNotPresent(animation.elementId || animation.id || "");
3714
+ return;
3715
+ }
3716
+ Array.from(elements).forEach((element) => {
3717
+ augmentAnimation(animation, element);
3718
+ let triggered = false;
3719
+ let pendingAnimation = false;
3720
+ function immediateOnScroll() {
3721
+ if (!triggered && isScrolledIntoView(element)) {
3722
+ triggered = true;
3723
+ pendingAnimation = true;
3724
+ setTimeout(() => {
3725
+ assign(element.style, animation.steps[1].styles);
3726
+ if (!animation.repeat) {
3727
+ document.removeEventListener("scroll", onScroll);
3728
+ }
3729
+ setTimeout(() => {
3730
+ pendingAnimation = false;
3731
+ if (!animation.repeat) {
3732
+ element.style.transition = "";
3733
+ element.style.transitionDelay = "";
3734
+ }
3735
+ }, (animation.duration + (animation.delay || 0)) * 1e3 + 100);
3736
+ });
3737
+ } else if (animation.repeat && triggered && !pendingAnimation && !isScrolledIntoView(element)) {
3738
+ triggered = false;
3739
+ assign(element.style, animation.steps[0].styles);
3740
+ }
3741
+ }
3742
+ const onScroll = throttle(immediateOnScroll, 200, {
3743
+ leading: false
3744
+ });
3745
+ function isScrolledIntoView(elem) {
3746
+ const rect = elem.getBoundingClientRect();
3747
+ const windowHeight = window.innerHeight;
3748
+ const thresholdPercent = (animation.thresholdPercent || 0) / 100;
3749
+ const threshold = thresholdPercent * windowHeight;
3750
+ return rect.bottom > threshold && rect.top < windowHeight - threshold;
3751
+ }
3752
+ const defaultState = animation.steps[0].styles;
3753
+ function attachDefaultState() {
3754
+ assign(element.style, defaultState);
3755
+ }
3756
+ attachDefaultState();
3757
+ setTimeout(() => {
3758
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
3759
+ if (animation.delay) {
3760
+ element.style.transitionDelay = animation.delay + "s";
3761
+ }
3762
+ });
3763
+ document.addEventListener("scroll", onScroll, {
3764
+ capture: true,
3765
+ passive: true
3766
+ });
3767
+ immediateOnScroll();
3768
+ });
3769
+ }
3770
+
3550
3771
  // src/components/block/block.helpers.ts
3551
3772
  var getComponent = ({
3552
3773
  block,
@@ -4066,6 +4287,18 @@ function Block(props) {
4066
4287
  isInteractive: !blockComponent()?.isRSC
4067
4288
  };
4068
4289
  }
4290
+ onMount(() => {
4291
+ const blockId = processedBlock().id;
4292
+ const animations = processedBlock().animations;
4293
+ if (animations && blockId) {
4294
+ bindAnimations(
4295
+ animations.filter((item) => item.trigger !== "hover").map((animation) => ({
4296
+ ...animation,
4297
+ elementId: blockId
4298
+ }))
4299
+ );
4300
+ }
4301
+ });
4069
4302
  return <Show4 when={canShowBlock()}>
4070
4303
  <Block_styles_default block={props.block} context={props.context} />
4071
4304
  <Show4
@@ -4513,10 +4746,10 @@ function SectionComponent(props) {
4513
4746
  var section_default = SectionComponent;
4514
4747
 
4515
4748
  // src/blocks/symbol/symbol.tsx
4516
- import { onMount as onMount4, on as on3, createEffect as createEffect3, createSignal as createSignal14 } from "solid-js";
4749
+ import { onMount as onMount5, on as on3, createEffect as createEffect3, createSignal as createSignal14 } from "solid-js";
4517
4750
 
4518
4751
  // src/components/content-variants/content-variants.tsx
4519
- import { Show as Show11, For as For5, onMount as onMount3, createSignal as createSignal13 } from "solid-js";
4752
+ import { Show as Show11, For as For5, onMount as onMount4, createSignal as createSignal13 } from "solid-js";
4520
4753
 
4521
4754
  // src/helpers/url.ts
4522
4755
  var getTopLevelDomain = (host) => {
@@ -4994,12 +5227,12 @@ var componentInfo3 = {
4994
5227
  };
4995
5228
 
4996
5229
  // src/blocks/custom-code/custom-code.tsx
4997
- import { onMount, createSignal as createSignal7 } from "solid-js";
5230
+ import { onMount as onMount2, createSignal as createSignal7 } from "solid-js";
4998
5231
  function CustomCode(props) {
4999
5232
  const [scriptsInserted, setScriptsInserted] = createSignal7([]);
5000
5233
  const [scriptsRun, setScriptsRun] = createSignal7([]);
5001
5234
  let elementRef;
5002
- onMount(() => {
5235
+ onMount2(() => {
5003
5236
  if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
5004
5237
  return;
5005
5238
  }
@@ -5717,7 +5950,7 @@ function InlinedScript(props) {
5717
5950
  var Inlined_script_default = InlinedScript;
5718
5951
 
5719
5952
  // src/components/content/components/enable-editor.tsx
5720
- import { Show as Show9, onMount as onMount2, on as on2, createEffect as createEffect2, createSignal as createSignal10 } from "solid-js";
5953
+ import { Show as Show9, onMount as onMount3, on as on2, createEffect as createEffect2, createSignal as createSignal10 } from "solid-js";
5721
5954
  import { Dynamic as Dynamic5 } from "solid-js/web";
5722
5955
 
5723
5956
  // src/helpers/preview-lru-cache/get.ts
@@ -6207,7 +6440,7 @@ var getInteractionPropertiesForEvent = (event) => {
6207
6440
  };
6208
6441
 
6209
6442
  // src/constants/sdk-version.ts
6210
- var SDK_VERSION = "0.12.5";
6443
+ var SDK_VERSION = "0.12.7";
6211
6444
 
6212
6445
  // src/functions/register.ts
6213
6446
  var registry = {};
@@ -6410,6 +6643,10 @@ function EnableEditor(props) {
6410
6643
  setForceReRenderCount(forceReRenderCount() + 1);
6411
6644
  break;
6412
6645
  }
6646
+ case "builder.triggerAnimation": {
6647
+ triggerAnimation(data.data);
6648
+ break;
6649
+ }
6413
6650
  case "builder.contentUpdate": {
6414
6651
  const messageContent = data.data;
6415
6652
  const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
@@ -6506,7 +6743,7 @@ function EnableEditor(props) {
6506
6743
  }
6507
6744
  }
6508
6745
  let elementRef;
6509
- onMount2(() => {
6746
+ onMount3(() => {
6510
6747
  if (isBrowser()) {
6511
6748
  if (isEditing() && true) {
6512
6749
  setForceReRenderCount(forceReRenderCount() + 1);
@@ -6571,7 +6808,7 @@ function EnableEditor(props) {
6571
6808
  }
6572
6809
  }
6573
6810
  });
6574
- onMount2(() => {
6811
+ onMount3(() => {
6575
6812
  if (!props.apiKey) {
6576
6813
  logger.error(
6577
6814
  "No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
@@ -6594,13 +6831,7 @@ function EnableEditor(props) {
6594
6831
  evaluateJsCode();
6595
6832
  }
6596
6833
  createEffect2(
6597
- on2(
6598
- () => [
6599
- props.builderContextSignal.content?.data?.jsCode,
6600
- props.builderContextSignal.rootState
6601
- ],
6602
- onUpdateFn_2
6603
- )
6834
+ on2(() => [props.builderContextSignal.content?.data?.jsCode], onUpdateFn_2)
6604
6835
  );
6605
6836
  function onUpdateFn_3() {
6606
6837
  runHttpRequests();
@@ -6917,7 +7148,7 @@ function ContentVariants(props) {
6917
7148
  canTrack: getDefaultCanTrack(props.canTrack)
6918
7149
  });
6919
7150
  }
6920
- onMount3(() => {
7151
+ onMount4(() => {
6921
7152
  setShouldRenderVariants(false);
6922
7153
  });
6923
7154
  return <>
@@ -7029,7 +7260,7 @@ function Symbol2(props) {
7029
7260
  }
7030
7261
  });
7031
7262
  }
7032
- onMount4(() => {
7263
+ onMount5(() => {
7033
7264
  setContent();
7034
7265
  });
7035
7266
  function onUpdateFn_0() {
package/lib/node/dev.js CHANGED
@@ -245,27 +245,43 @@ var runInBrowser = ({
245
245
  builder,
246
246
  context,
247
247
  event,
248
- state: flattenState(rootState, localState, rootSetState)
248
+ state: flattenState({
249
+ rootState,
250
+ localState,
251
+ rootSetState
252
+ })
249
253
  });
250
254
  return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
251
255
  };
252
- function flattenState(rootState, localState, rootSetState) {
253
- if (rootState === localState) {
254
- throw new Error("rootState === localState");
255
- }
256
+ function flattenState({
257
+ rootState,
258
+ localState,
259
+ rootSetState
260
+ }) {
256
261
  return new Proxy(rootState, {
257
- get: (_, prop) => {
262
+ get: (target, prop) => {
258
263
  if (localState && prop in localState) {
259
264
  return localState[prop];
260
265
  }
261
- return rootState[prop];
266
+ const val = target[prop];
267
+ if (typeof val === "object") {
268
+ return flattenState({
269
+ rootState: val,
270
+ localState: void 0,
271
+ rootSetState: rootSetState ? (subState) => {
272
+ target[prop] = subState;
273
+ rootSetState(target);
274
+ } : void 0
275
+ });
276
+ }
277
+ return val;
262
278
  },
263
- set: (_, prop, value) => {
279
+ set: (target, prop, value) => {
264
280
  if (localState && prop in localState) {
265
281
  throw new Error("Writing to local state is not allowed as it is read-only.");
266
282
  }
267
- rootState[prop] = value;
268
- rootSetState?.(rootState);
283
+ target[prop] = value;
284
+ rootSetState?.(target);
269
285
  return true;
270
286
  }
271
287
  });
@@ -531,6 +547,212 @@ function getProcessedBlock({
531
547
  }
532
548
  }
533
549
 
550
+ // src/components/block/animator.ts
551
+ function throttle(func, wait, options = {}) {
552
+ let context;
553
+ let args;
554
+ let result;
555
+ let timeout = null;
556
+ let previous = 0;
557
+ const later = function() {
558
+ previous = options.leading === false ? 0 : Date.now();
559
+ timeout = null;
560
+ result = func.apply(context, args);
561
+ if (!timeout)
562
+ context = args = null;
563
+ };
564
+ return function() {
565
+ const now = Date.now();
566
+ if (!previous && options.leading === false)
567
+ previous = now;
568
+ const remaining = wait - (now - previous);
569
+ context = this;
570
+ args = arguments;
571
+ if (remaining <= 0 || remaining > wait) {
572
+ if (timeout) {
573
+ clearTimeout(timeout);
574
+ timeout = null;
575
+ }
576
+ previous = now;
577
+ result = func.apply(context, args);
578
+ if (!timeout)
579
+ context = args = null;
580
+ } else if (!timeout && options.trailing !== false) {
581
+ timeout = setTimeout(later, remaining);
582
+ }
583
+ return result;
584
+ };
585
+ }
586
+ function assign(target, ..._args) {
587
+ const to = Object(target);
588
+ for (let index = 1; index < arguments.length; index++) {
589
+ const nextSource = arguments[index];
590
+ if (nextSource != null) {
591
+ for (const nextKey in nextSource) {
592
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
593
+ to[nextKey] = nextSource[nextKey];
594
+ }
595
+ }
596
+ }
597
+ }
598
+ return to;
599
+ }
600
+ var camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) : "";
601
+ function bindAnimations(animations) {
602
+ for (const animation of animations) {
603
+ switch (animation.trigger) {
604
+ case "pageLoad":
605
+ triggerAnimation(animation);
606
+ break;
607
+ case "hover":
608
+ bindHoverAnimation(animation);
609
+ break;
610
+ case "scrollInView":
611
+ bindScrollInViewAnimation(animation);
612
+ break;
613
+ }
614
+ }
615
+ }
616
+ function warnElementNotPresent(id) {
617
+ console.warn(`Cannot animate element: element with ID ${id} not found!`);
618
+ }
619
+ function augmentAnimation(animation, element) {
620
+ const stylesUsed = getAllStylesUsed(animation);
621
+ const computedStyle = getComputedStyle(element);
622
+ const firstStyles = animation.steps[0].styles;
623
+ const lastStyles = animation.steps[animation.steps.length - 1].styles;
624
+ const bothStyles = [firstStyles, lastStyles];
625
+ for (const styles of bothStyles) {
626
+ for (const style of stylesUsed) {
627
+ if (!(style in styles)) {
628
+ styles[style] = computedStyle[style];
629
+ }
630
+ }
631
+ }
632
+ }
633
+ function getAllStylesUsed(animation) {
634
+ const properties = [];
635
+ for (const step of animation.steps) {
636
+ for (const key in step.styles) {
637
+ if (properties.indexOf(key) === -1) {
638
+ properties.push(key);
639
+ }
640
+ }
641
+ }
642
+ return properties;
643
+ }
644
+ function triggerAnimation(animation) {
645
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
646
+ if (!elements.length) {
647
+ warnElementNotPresent(animation.elementId || animation.id || "");
648
+ return;
649
+ }
650
+ Array.from(elements).forEach((element) => {
651
+ augmentAnimation(animation, element);
652
+ element.style.transition = "none";
653
+ element.style.transitionDelay = "0";
654
+ assign(element.style, animation.steps[0].styles);
655
+ setTimeout(() => {
656
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
657
+ if (animation.delay) {
658
+ element.style.transitionDelay = animation.delay + "s";
659
+ }
660
+ assign(element.style, animation.steps[1].styles);
661
+ setTimeout(() => {
662
+ element.style.transition = "";
663
+ element.style.transitionDelay = "";
664
+ }, (animation.delay || 0) * 1e3 + animation.duration * 1e3 + 100);
665
+ });
666
+ });
667
+ }
668
+ function bindHoverAnimation(animation) {
669
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
670
+ if (!elements.length) {
671
+ warnElementNotPresent(animation.elementId || animation.id || "");
672
+ return;
673
+ }
674
+ Array.from(elements).forEach((element) => {
675
+ augmentAnimation(animation, element);
676
+ const defaultState = animation.steps[0].styles;
677
+ const hoverState = animation.steps[1].styles;
678
+ function attachDefaultState() {
679
+ assign(element.style, defaultState);
680
+ }
681
+ function attachHoverState() {
682
+ assign(element.style, hoverState);
683
+ }
684
+ attachDefaultState();
685
+ element.addEventListener("mouseenter", attachHoverState);
686
+ element.addEventListener("mouseleave", attachDefaultState);
687
+ setTimeout(() => {
688
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
689
+ if (animation.delay) {
690
+ element.style.transitionDelay = animation.delay + "s";
691
+ }
692
+ });
693
+ });
694
+ }
695
+ function bindScrollInViewAnimation(animation) {
696
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
697
+ if (!elements.length) {
698
+ warnElementNotPresent(animation.elementId || animation.id || "");
699
+ return;
700
+ }
701
+ Array.from(elements).forEach((element) => {
702
+ augmentAnimation(animation, element);
703
+ let triggered = false;
704
+ let pendingAnimation = false;
705
+ function immediateOnScroll() {
706
+ if (!triggered && isScrolledIntoView(element)) {
707
+ triggered = true;
708
+ pendingAnimation = true;
709
+ setTimeout(() => {
710
+ assign(element.style, animation.steps[1].styles);
711
+ if (!animation.repeat) {
712
+ document.removeEventListener("scroll", onScroll);
713
+ }
714
+ setTimeout(() => {
715
+ pendingAnimation = false;
716
+ if (!animation.repeat) {
717
+ element.style.transition = "";
718
+ element.style.transitionDelay = "";
719
+ }
720
+ }, (animation.duration + (animation.delay || 0)) * 1e3 + 100);
721
+ });
722
+ } else if (animation.repeat && triggered && !pendingAnimation && !isScrolledIntoView(element)) {
723
+ triggered = false;
724
+ assign(element.style, animation.steps[0].styles);
725
+ }
726
+ }
727
+ const onScroll = throttle(immediateOnScroll, 200, {
728
+ leading: false
729
+ });
730
+ function isScrolledIntoView(elem) {
731
+ const rect = elem.getBoundingClientRect();
732
+ const windowHeight = window.innerHeight;
733
+ const thresholdPercent = (animation.thresholdPercent || 0) / 100;
734
+ const threshold = thresholdPercent * windowHeight;
735
+ return rect.bottom > threshold && rect.top < windowHeight - threshold;
736
+ }
737
+ const defaultState = animation.steps[0].styles;
738
+ function attachDefaultState() {
739
+ assign(element.style, defaultState);
740
+ }
741
+ attachDefaultState();
742
+ setTimeout(() => {
743
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
744
+ if (animation.delay) {
745
+ element.style.transitionDelay = animation.delay + "s";
746
+ }
747
+ });
748
+ document.addEventListener("scroll", onScroll, {
749
+ capture: true,
750
+ passive: true
751
+ });
752
+ immediateOnScroll();
753
+ });
754
+ }
755
+
534
756
  // src/components/block/block.helpers.ts
535
757
  var getComponent = ({
536
758
  block,
@@ -1106,6 +1328,16 @@ function Block(props) {
1106
1328
  isInteractive: !blockComponent()?.isRSC
1107
1329
  };
1108
1330
  }
1331
+ onMount(() => {
1332
+ const blockId = processedBlock().id;
1333
+ const animations = processedBlock().animations;
1334
+ if (animations && blockId) {
1335
+ bindAnimations(animations.filter((item) => item.trigger !== "hover").map((animation) => ({
1336
+ ...animation,
1337
+ elementId: blockId
1338
+ })));
1339
+ }
1340
+ });
1109
1341
  return createComponent(Show, {
1110
1342
  get when() {
1111
1343
  return canShowBlock();
@@ -3518,7 +3750,7 @@ var getInteractionPropertiesForEvent = (event) => {
3518
3750
  };
3519
3751
 
3520
3752
  // src/constants/sdk-version.ts
3521
- var SDK_VERSION = "0.12.5";
3753
+ var SDK_VERSION = "0.12.7";
3522
3754
 
3523
3755
  // src/functions/register.ts
3524
3756
  var registry = {};
@@ -3725,6 +3957,10 @@ function EnableEditor(props) {
3725
3957
  setForceReRenderCount(forceReRenderCount() + 1);
3726
3958
  break;
3727
3959
  }
3960
+ case "builder.triggerAnimation": {
3961
+ triggerAnimation(data.data);
3962
+ break;
3963
+ }
3728
3964
  case "builder.contentUpdate": {
3729
3965
  const messageContent = data.data;
3730
3966
  const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
@@ -3895,7 +4131,7 @@ function EnableEditor(props) {
3895
4131
  function onUpdateFn_2() {
3896
4132
  evaluateJsCode();
3897
4133
  }
3898
- createEffect(on(() => [props.builderContextSignal.content?.data?.jsCode, props.builderContextSignal.rootState], onUpdateFn_2));
4134
+ createEffect(on(() => [props.builderContextSignal.content?.data?.jsCode], onUpdateFn_2));
3899
4135
  function onUpdateFn_3() {
3900
4136
  runHttpRequests();
3901
4137
  }