@builder.io/sdk-solid 0.12.6 → 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.
package/lib/node/index.js CHANGED
@@ -544,6 +544,211 @@ function getProcessedBlock({
544
544
  }
545
545
  }
546
546
 
547
+ // src/components/block/animator.ts
548
+ function throttle(func, wait, options = {}) {
549
+ let context;
550
+ let args;
551
+ let result;
552
+ let timeout = null;
553
+ let previous = 0;
554
+ const later = function() {
555
+ previous = options.leading === false ? 0 : Date.now();
556
+ timeout = null;
557
+ result = func.apply(context, args);
558
+ if (!timeout)
559
+ context = args = null;
560
+ };
561
+ return function() {
562
+ const now = Date.now();
563
+ if (!previous && options.leading === false)
564
+ previous = now;
565
+ const remaining = wait - (now - previous);
566
+ context = this;
567
+ args = arguments;
568
+ if (remaining <= 0 || remaining > wait) {
569
+ if (timeout) {
570
+ clearTimeout(timeout);
571
+ timeout = null;
572
+ }
573
+ previous = now;
574
+ result = func.apply(context, args);
575
+ if (!timeout)
576
+ context = args = null;
577
+ } else if (!timeout && options.trailing !== false) {
578
+ timeout = setTimeout(later, remaining);
579
+ }
580
+ return result;
581
+ };
582
+ }
583
+ function assign(target, ..._args) {
584
+ const to = Object(target);
585
+ for (let index = 1; index < arguments.length; index++) {
586
+ const nextSource = arguments[index];
587
+ if (nextSource != null) {
588
+ for (const nextKey in nextSource) {
589
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
590
+ to[nextKey] = nextSource[nextKey];
591
+ }
592
+ }
593
+ }
594
+ }
595
+ return to;
596
+ }
597
+ var camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) : "";
598
+ function bindAnimations(animations) {
599
+ for (const animation of animations) {
600
+ switch (animation.trigger) {
601
+ case "pageLoad":
602
+ triggerAnimation(animation);
603
+ break;
604
+ case "hover":
605
+ bindHoverAnimation(animation);
606
+ break;
607
+ case "scrollInView":
608
+ bindScrollInViewAnimation(animation);
609
+ break;
610
+ }
611
+ }
612
+ }
613
+ function warnElementNotPresent(id) {
614
+ }
615
+ function augmentAnimation(animation, element) {
616
+ const stylesUsed = getAllStylesUsed(animation);
617
+ const computedStyle = getComputedStyle(element);
618
+ const firstStyles = animation.steps[0].styles;
619
+ const lastStyles = animation.steps[animation.steps.length - 1].styles;
620
+ const bothStyles = [firstStyles, lastStyles];
621
+ for (const styles of bothStyles) {
622
+ for (const style of stylesUsed) {
623
+ if (!(style in styles)) {
624
+ styles[style] = computedStyle[style];
625
+ }
626
+ }
627
+ }
628
+ }
629
+ function getAllStylesUsed(animation) {
630
+ const properties = [];
631
+ for (const step of animation.steps) {
632
+ for (const key in step.styles) {
633
+ if (properties.indexOf(key) === -1) {
634
+ properties.push(key);
635
+ }
636
+ }
637
+ }
638
+ return properties;
639
+ }
640
+ function triggerAnimation(animation) {
641
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
642
+ if (!elements.length) {
643
+ warnElementNotPresent(animation.elementId || animation.id || "");
644
+ return;
645
+ }
646
+ Array.from(elements).forEach((element) => {
647
+ augmentAnimation(animation, element);
648
+ element.style.transition = "none";
649
+ element.style.transitionDelay = "0";
650
+ assign(element.style, animation.steps[0].styles);
651
+ setTimeout(() => {
652
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
653
+ if (animation.delay) {
654
+ element.style.transitionDelay = animation.delay + "s";
655
+ }
656
+ assign(element.style, animation.steps[1].styles);
657
+ setTimeout(() => {
658
+ element.style.transition = "";
659
+ element.style.transitionDelay = "";
660
+ }, (animation.delay || 0) * 1e3 + animation.duration * 1e3 + 100);
661
+ });
662
+ });
663
+ }
664
+ function bindHoverAnimation(animation) {
665
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
666
+ if (!elements.length) {
667
+ warnElementNotPresent(animation.elementId || animation.id || "");
668
+ return;
669
+ }
670
+ Array.from(elements).forEach((element) => {
671
+ augmentAnimation(animation, element);
672
+ const defaultState = animation.steps[0].styles;
673
+ const hoverState = animation.steps[1].styles;
674
+ function attachDefaultState() {
675
+ assign(element.style, defaultState);
676
+ }
677
+ function attachHoverState() {
678
+ assign(element.style, hoverState);
679
+ }
680
+ attachDefaultState();
681
+ element.addEventListener("mouseenter", attachHoverState);
682
+ element.addEventListener("mouseleave", attachDefaultState);
683
+ setTimeout(() => {
684
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
685
+ if (animation.delay) {
686
+ element.style.transitionDelay = animation.delay + "s";
687
+ }
688
+ });
689
+ });
690
+ }
691
+ function bindScrollInViewAnimation(animation) {
692
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
693
+ if (!elements.length) {
694
+ warnElementNotPresent(animation.elementId || animation.id || "");
695
+ return;
696
+ }
697
+ Array.from(elements).forEach((element) => {
698
+ augmentAnimation(animation, element);
699
+ let triggered = false;
700
+ let pendingAnimation = false;
701
+ function immediateOnScroll() {
702
+ if (!triggered && isScrolledIntoView(element)) {
703
+ triggered = true;
704
+ pendingAnimation = true;
705
+ setTimeout(() => {
706
+ assign(element.style, animation.steps[1].styles);
707
+ if (!animation.repeat) {
708
+ document.removeEventListener("scroll", onScroll);
709
+ }
710
+ setTimeout(() => {
711
+ pendingAnimation = false;
712
+ if (!animation.repeat) {
713
+ element.style.transition = "";
714
+ element.style.transitionDelay = "";
715
+ }
716
+ }, (animation.duration + (animation.delay || 0)) * 1e3 + 100);
717
+ });
718
+ } else if (animation.repeat && triggered && !pendingAnimation && !isScrolledIntoView(element)) {
719
+ triggered = false;
720
+ assign(element.style, animation.steps[0].styles);
721
+ }
722
+ }
723
+ const onScroll = throttle(immediateOnScroll, 200, {
724
+ leading: false
725
+ });
726
+ function isScrolledIntoView(elem) {
727
+ const rect = elem.getBoundingClientRect();
728
+ const windowHeight = window.innerHeight;
729
+ const thresholdPercent = (animation.thresholdPercent || 0) / 100;
730
+ const threshold = thresholdPercent * windowHeight;
731
+ return rect.bottom > threshold && rect.top < windowHeight - threshold;
732
+ }
733
+ const defaultState = animation.steps[0].styles;
734
+ function attachDefaultState() {
735
+ assign(element.style, defaultState);
736
+ }
737
+ attachDefaultState();
738
+ setTimeout(() => {
739
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
740
+ if (animation.delay) {
741
+ element.style.transitionDelay = animation.delay + "s";
742
+ }
743
+ });
744
+ document.addEventListener("scroll", onScroll, {
745
+ capture: true,
746
+ passive: true
747
+ });
748
+ immediateOnScroll();
749
+ });
750
+ }
751
+
547
752
  // src/components/block/block.helpers.ts
548
753
  var getComponent = ({
549
754
  block,
@@ -1116,6 +1321,16 @@ function Block(props) {
1116
1321
  isInteractive: !blockComponent()?.isRSC
1117
1322
  };
1118
1323
  }
1324
+ onMount(() => {
1325
+ const blockId = processedBlock().id;
1326
+ const animations = processedBlock().animations;
1327
+ if (animations && blockId) {
1328
+ bindAnimations(animations.filter((item) => item.trigger !== "hover").map((animation) => ({
1329
+ ...animation,
1330
+ elementId: blockId
1331
+ })));
1332
+ }
1333
+ });
1119
1334
  return createComponent(Show, {
1120
1335
  get when() {
1121
1336
  return canShowBlock();
@@ -3519,7 +3734,7 @@ var getInteractionPropertiesForEvent = (event) => {
3519
3734
  };
3520
3735
 
3521
3736
  // src/constants/sdk-version.ts
3522
- var SDK_VERSION = "0.12.6";
3737
+ var SDK_VERSION = "0.12.7";
3523
3738
 
3524
3739
  // src/functions/register.ts
3525
3740
  var registry = {};
@@ -3725,6 +3940,10 @@ function EnableEditor(props) {
3725
3940
  setForceReRenderCount(forceReRenderCount() + 1);
3726
3941
  break;
3727
3942
  }
3943
+ case "builder.triggerAnimation": {
3944
+ triggerAnimation(data.data);
3945
+ break;
3946
+ }
3728
3947
  case "builder.contentUpdate": {
3729
3948
  const messageContent = data.data;
3730
3949
  const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
@@ -99,7 +99,7 @@ import { createContext as createContext2 } from "solid-js";
99
99
  var components_context_default = createContext2({ registeredComponents: {} });
100
100
 
101
101
  // src/components/block/block.tsx
102
- import { Show as Show4, For as For2, createSignal as createSignal4 } from "solid-js";
102
+ import { Show as Show4, For as For2, onMount, createSignal as createSignal4 } from "solid-js";
103
103
 
104
104
  // src/functions/get-block-component-options.ts
105
105
  function getBlockComponentOptions(block) {
@@ -533,6 +533,211 @@ function getProcessedBlock({
533
533
  }
534
534
  }
535
535
 
536
+ // src/components/block/animator.ts
537
+ function throttle(func, wait, options = {}) {
538
+ let context;
539
+ let args;
540
+ let result;
541
+ let timeout = null;
542
+ let previous = 0;
543
+ const later = function() {
544
+ previous = options.leading === false ? 0 : Date.now();
545
+ timeout = null;
546
+ result = func.apply(context, args);
547
+ if (!timeout)
548
+ context = args = null;
549
+ };
550
+ return function() {
551
+ const now = Date.now();
552
+ if (!previous && options.leading === false)
553
+ previous = now;
554
+ const remaining = wait - (now - previous);
555
+ context = this;
556
+ args = arguments;
557
+ if (remaining <= 0 || remaining > wait) {
558
+ if (timeout) {
559
+ clearTimeout(timeout);
560
+ timeout = null;
561
+ }
562
+ previous = now;
563
+ result = func.apply(context, args);
564
+ if (!timeout)
565
+ context = args = null;
566
+ } else if (!timeout && options.trailing !== false) {
567
+ timeout = setTimeout(later, remaining);
568
+ }
569
+ return result;
570
+ };
571
+ }
572
+ function assign(target, ..._args) {
573
+ const to = Object(target);
574
+ for (let index = 1; index < arguments.length; index++) {
575
+ const nextSource = arguments[index];
576
+ if (nextSource != null) {
577
+ for (const nextKey in nextSource) {
578
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
579
+ to[nextKey] = nextSource[nextKey];
580
+ }
581
+ }
582
+ }
583
+ }
584
+ return to;
585
+ }
586
+ var camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) : "";
587
+ function bindAnimations(animations) {
588
+ for (const animation of animations) {
589
+ switch (animation.trigger) {
590
+ case "pageLoad":
591
+ triggerAnimation(animation);
592
+ break;
593
+ case "hover":
594
+ bindHoverAnimation(animation);
595
+ break;
596
+ case "scrollInView":
597
+ bindScrollInViewAnimation(animation);
598
+ break;
599
+ }
600
+ }
601
+ }
602
+ function warnElementNotPresent(id) {
603
+ }
604
+ function augmentAnimation(animation, element) {
605
+ const stylesUsed = getAllStylesUsed(animation);
606
+ const computedStyle = getComputedStyle(element);
607
+ const firstStyles = animation.steps[0].styles;
608
+ const lastStyles = animation.steps[animation.steps.length - 1].styles;
609
+ const bothStyles = [firstStyles, lastStyles];
610
+ for (const styles of bothStyles) {
611
+ for (const style of stylesUsed) {
612
+ if (!(style in styles)) {
613
+ styles[style] = computedStyle[style];
614
+ }
615
+ }
616
+ }
617
+ }
618
+ function getAllStylesUsed(animation) {
619
+ const properties = [];
620
+ for (const step of animation.steps) {
621
+ for (const key in step.styles) {
622
+ if (properties.indexOf(key) === -1) {
623
+ properties.push(key);
624
+ }
625
+ }
626
+ }
627
+ return properties;
628
+ }
629
+ function triggerAnimation(animation) {
630
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
631
+ if (!elements.length) {
632
+ warnElementNotPresent(animation.elementId || animation.id || "");
633
+ return;
634
+ }
635
+ Array.from(elements).forEach((element) => {
636
+ augmentAnimation(animation, element);
637
+ element.style.transition = "none";
638
+ element.style.transitionDelay = "0";
639
+ assign(element.style, animation.steps[0].styles);
640
+ setTimeout(() => {
641
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
642
+ if (animation.delay) {
643
+ element.style.transitionDelay = animation.delay + "s";
644
+ }
645
+ assign(element.style, animation.steps[1].styles);
646
+ setTimeout(() => {
647
+ element.style.transition = "";
648
+ element.style.transitionDelay = "";
649
+ }, (animation.delay || 0) * 1e3 + animation.duration * 1e3 + 100);
650
+ });
651
+ });
652
+ }
653
+ function bindHoverAnimation(animation) {
654
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
655
+ if (!elements.length) {
656
+ warnElementNotPresent(animation.elementId || animation.id || "");
657
+ return;
658
+ }
659
+ Array.from(elements).forEach((element) => {
660
+ augmentAnimation(animation, element);
661
+ const defaultState = animation.steps[0].styles;
662
+ const hoverState = animation.steps[1].styles;
663
+ function attachDefaultState() {
664
+ assign(element.style, defaultState);
665
+ }
666
+ function attachHoverState() {
667
+ assign(element.style, hoverState);
668
+ }
669
+ attachDefaultState();
670
+ element.addEventListener("mouseenter", attachHoverState);
671
+ element.addEventListener("mouseleave", attachDefaultState);
672
+ setTimeout(() => {
673
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
674
+ if (animation.delay) {
675
+ element.style.transitionDelay = animation.delay + "s";
676
+ }
677
+ });
678
+ });
679
+ }
680
+ function bindScrollInViewAnimation(animation) {
681
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
682
+ if (!elements.length) {
683
+ warnElementNotPresent(animation.elementId || animation.id || "");
684
+ return;
685
+ }
686
+ Array.from(elements).forEach((element) => {
687
+ augmentAnimation(animation, element);
688
+ let triggered = false;
689
+ let pendingAnimation = false;
690
+ function immediateOnScroll() {
691
+ if (!triggered && isScrolledIntoView(element)) {
692
+ triggered = true;
693
+ pendingAnimation = true;
694
+ setTimeout(() => {
695
+ assign(element.style, animation.steps[1].styles);
696
+ if (!animation.repeat) {
697
+ document.removeEventListener("scroll", onScroll);
698
+ }
699
+ setTimeout(() => {
700
+ pendingAnimation = false;
701
+ if (!animation.repeat) {
702
+ element.style.transition = "";
703
+ element.style.transitionDelay = "";
704
+ }
705
+ }, (animation.duration + (animation.delay || 0)) * 1e3 + 100);
706
+ });
707
+ } else if (animation.repeat && triggered && !pendingAnimation && !isScrolledIntoView(element)) {
708
+ triggered = false;
709
+ assign(element.style, animation.steps[0].styles);
710
+ }
711
+ }
712
+ const onScroll = throttle(immediateOnScroll, 200, {
713
+ leading: false
714
+ });
715
+ function isScrolledIntoView(elem) {
716
+ const rect = elem.getBoundingClientRect();
717
+ const windowHeight = window.innerHeight;
718
+ const thresholdPercent = (animation.thresholdPercent || 0) / 100;
719
+ const threshold = thresholdPercent * windowHeight;
720
+ return rect.bottom > threshold && rect.top < windowHeight - threshold;
721
+ }
722
+ const defaultState = animation.steps[0].styles;
723
+ function attachDefaultState() {
724
+ assign(element.style, defaultState);
725
+ }
726
+ attachDefaultState();
727
+ setTimeout(() => {
728
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
729
+ if (animation.delay) {
730
+ element.style.transitionDelay = animation.delay + "s";
731
+ }
732
+ });
733
+ document.addEventListener("scroll", onScroll, {
734
+ capture: true,
735
+ passive: true
736
+ });
737
+ immediateOnScroll();
738
+ });
739
+ }
740
+
536
741
  // src/components/block/block.helpers.ts
537
742
  var getComponent = ({
538
743
  block,
@@ -1052,6 +1257,18 @@ function Block(props) {
1052
1257
  isInteractive: !blockComponent()?.isRSC
1053
1258
  };
1054
1259
  }
1260
+ onMount(() => {
1261
+ const blockId = processedBlock().id;
1262
+ const animations = processedBlock().animations;
1263
+ if (animations && blockId) {
1264
+ bindAnimations(
1265
+ animations.filter((item) => item.trigger !== "hover").map((animation) => ({
1266
+ ...animation,
1267
+ elementId: blockId
1268
+ }))
1269
+ );
1270
+ }
1271
+ });
1055
1272
  return <Show4 when={canShowBlock()}>
1056
1273
  <Block_styles_default block={props.block} context={props.context} />
1057
1274
  <Show4
@@ -1499,10 +1716,10 @@ function SectionComponent(props) {
1499
1716
  var section_default = SectionComponent;
1500
1717
 
1501
1718
  // src/blocks/symbol/symbol.tsx
1502
- import { onMount as onMount4, on as on3, createEffect as createEffect3, createSignal as createSignal14 } from "solid-js";
1719
+ import { onMount as onMount5, on as on3, createEffect as createEffect3, createSignal as createSignal14 } from "solid-js";
1503
1720
 
1504
1721
  // src/components/content-variants/content-variants.tsx
1505
- import { Show as Show11, For as For5, onMount as onMount3, createSignal as createSignal13 } from "solid-js";
1722
+ import { Show as Show11, For as For5, onMount as onMount4, createSignal as createSignal13 } from "solid-js";
1506
1723
 
1507
1724
  // src/helpers/url.ts
1508
1725
  var getTopLevelDomain = (host) => {
@@ -1980,12 +2197,12 @@ var componentInfo3 = {
1980
2197
  };
1981
2198
 
1982
2199
  // src/blocks/custom-code/custom-code.tsx
1983
- import { onMount, createSignal as createSignal7 } from "solid-js";
2200
+ import { onMount as onMount2, createSignal as createSignal7 } from "solid-js";
1984
2201
  function CustomCode(props) {
1985
2202
  const [scriptsInserted, setScriptsInserted] = createSignal7([]);
1986
2203
  const [scriptsRun, setScriptsRun] = createSignal7([]);
1987
2204
  let elementRef;
1988
- onMount(() => {
2205
+ onMount2(() => {
1989
2206
  if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
1990
2207
  return;
1991
2208
  }
@@ -2703,7 +2920,7 @@ function InlinedScript(props) {
2703
2920
  var Inlined_script_default = InlinedScript;
2704
2921
 
2705
2922
  // src/components/content/components/enable-editor.tsx
2706
- import { Show as Show9, onMount as onMount2, on as on2, createEffect as createEffect2, createSignal as createSignal10 } from "solid-js";
2923
+ import { Show as Show9, onMount as onMount3, on as on2, createEffect as createEffect2, createSignal as createSignal10 } from "solid-js";
2707
2924
  import { Dynamic as Dynamic5 } from "solid-js/web";
2708
2925
 
2709
2926
  // src/helpers/preview-lru-cache/get.ts
@@ -3193,7 +3410,7 @@ var getInteractionPropertiesForEvent = (event) => {
3193
3410
  };
3194
3411
 
3195
3412
  // src/constants/sdk-version.ts
3196
- var SDK_VERSION = "0.12.6";
3413
+ var SDK_VERSION = "0.12.7";
3197
3414
 
3198
3415
  // src/functions/register.ts
3199
3416
  var registry = {};
@@ -3396,6 +3613,10 @@ function EnableEditor(props) {
3396
3613
  setForceReRenderCount(forceReRenderCount() + 1);
3397
3614
  break;
3398
3615
  }
3616
+ case "builder.triggerAnimation": {
3617
+ triggerAnimation(data.data);
3618
+ break;
3619
+ }
3399
3620
  case "builder.contentUpdate": {
3400
3621
  const messageContent = data.data;
3401
3622
  const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
@@ -3492,7 +3713,7 @@ function EnableEditor(props) {
3492
3713
  }
3493
3714
  }
3494
3715
  let elementRef;
3495
- onMount2(() => {
3716
+ onMount3(() => {
3496
3717
  if (isBrowser()) {
3497
3718
  if (isEditing() && true) {
3498
3719
  setForceReRenderCount(forceReRenderCount() + 1);
@@ -3557,7 +3778,7 @@ function EnableEditor(props) {
3557
3778
  }
3558
3779
  }
3559
3780
  });
3560
- onMount2(() => {
3781
+ onMount3(() => {
3561
3782
  if (!props.apiKey) {
3562
3783
  logger.error(
3563
3784
  "No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
@@ -3897,7 +4118,7 @@ function ContentVariants(props) {
3897
4118
  canTrack: getDefaultCanTrack(props.canTrack)
3898
4119
  });
3899
4120
  }
3900
- onMount3(() => {
4121
+ onMount4(() => {
3901
4122
  setShouldRenderVariants(false);
3902
4123
  });
3903
4124
  return <>
@@ -4009,7 +4230,7 @@ function Symbol(props) {
4009
4230
  }
4010
4231
  });
4011
4232
  }
4012
- onMount4(() => {
4233
+ onMount5(() => {
4013
4234
  setContent();
4014
4235
  });
4015
4236
  function onUpdateFn_0() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.12.6",
3
+ "version": "0.12.7",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist",