@revenuecat/purchases-ui-js 2.0.2 → 2.0.3

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.
Files changed (127) hide show
  1. package/dist/components/button/ButtonNode.stories.svelte +66 -102
  2. package/dist/components/button/ButtonNode.svelte +2 -27
  3. package/dist/components/footer/Footer.stories.svelte +112 -102
  4. package/dist/components/footer/Footer.svelte +8 -4
  5. package/dist/components/icon/Icon.stories.svelte +100 -0
  6. package/dist/components/icon/Icon.stories.svelte.d.ts +19 -0
  7. package/dist/components/icon/Icon.svelte +73 -0
  8. package/dist/components/icon/Icon.svelte.d.ts +4 -0
  9. package/dist/components/image/ClipPath.svelte +49 -0
  10. package/dist/components/image/ClipPath.svelte.d.ts +9 -0
  11. package/dist/components/image/Image.stories.svelte +83 -188
  12. package/dist/components/image/Image.svelte +152 -136
  13. package/dist/components/image/Image.svelte.d.ts +1 -1
  14. package/dist/components/image/Overlay.svelte +36 -0
  15. package/dist/components/image/Overlay.svelte.d.ts +8 -0
  16. package/dist/components/package/Package.stories.svelte +10 -21
  17. package/dist/components/package/Package.svelte +8 -35
  18. package/dist/components/paywall/Node.svelte +27 -28
  19. package/dist/components/paywall/Node.svelte.d.ts +3 -6
  20. package/dist/components/paywall/Paywall.stories.svelte +36 -140
  21. package/dist/components/paywall/Paywall.svelte +22 -6
  22. package/dist/components/paywall/Paywall.svelte.d.ts +3 -2
  23. package/dist/components/paywall/fixtures/override-paywall.d.ts +2 -0
  24. package/dist/components/paywall/fixtures/override-paywall.js +1310 -0
  25. package/dist/components/paywall/fixtures/stack-paywall.d.ts +2 -0
  26. package/dist/components/paywall/fixtures/stack-paywall.js +5223 -0
  27. package/dist/components/paywall/fixtures/variables.d.ts +261 -0
  28. package/dist/components/paywall/fixtures/variables.js +262 -0
  29. package/dist/components/purchase-button/PurchaseButton.stories.svelte +10 -21
  30. package/dist/components/purchase-button/PurchaseButton.svelte +2 -27
  31. package/dist/components/stack/Stack.stories.svelte +2354 -978
  32. package/dist/components/stack/Stack.svelte +111 -134
  33. package/dist/components/stack/Stack.svelte.d.ts +6 -2
  34. package/dist/components/stack/stack-utils.d.ts +10 -30
  35. package/dist/components/stack/stack-utils.js +77 -255
  36. package/dist/components/text/Text.svelte +3 -37
  37. package/dist/components/text/Text.svelte.d.ts +1 -2
  38. package/dist/components/text/TextNode.stories.svelte +10 -36
  39. package/dist/components/text/TextNode.svelte +25 -28
  40. package/dist/components/text/TextNode.svelte.d.ts +1 -1
  41. package/dist/components/text/text-utils.d.ts +4 -9
  42. package/dist/components/text/text-utils.js +32 -117
  43. package/dist/components/timeline/Timeline.stories.svelte +640 -251
  44. package/dist/components/timeline/Timeline.svelte +42 -28
  45. package/dist/components/timeline/Timeline.svelte.d.ts +1 -1
  46. package/dist/components/timeline/TimelineItem.svelte +80 -112
  47. package/dist/components/timeline/TimelineItem.svelte.d.ts +6 -2
  48. package/dist/components/timeline/timeline-utils.d.ts +24 -6
  49. package/dist/components/timeline/timeline-utils.js +21 -113
  50. package/dist/data/entities.d.ts +19 -135
  51. package/dist/index.d.ts +2 -1
  52. package/dist/index.js +2 -1
  53. package/dist/stores/color-mode.d.ts +1 -1
  54. package/dist/stores/paywall.d.ts +5 -2
  55. package/dist/stores/selected.d.ts +5 -0
  56. package/dist/stores/selected.js +12 -0
  57. package/dist/stores/variables.d.ts +1 -1
  58. package/dist/stores/variables.js +0 -1
  59. package/dist/stories/component-decorator.d.ts +2 -0
  60. package/dist/stories/component-decorator.js +12 -0
  61. package/dist/stories/fixtures.d.ts +5 -3
  62. package/dist/stories/fixtures.js +5214 -4422
  63. package/dist/stories/paywall-decorator.js +6 -0
  64. package/dist/stories/variables-decorator.d.ts +1 -1
  65. package/dist/stories/viewport-decorator.d.ts +2 -0
  66. package/dist/stories/viewport-decorator.js +8 -0
  67. package/dist/stories/viewport-wrapper.svelte +53 -0
  68. package/dist/stories/viewport-wrapper.svelte.d.ts +10 -0
  69. package/dist/stories/with-layout.d.ts +2 -10
  70. package/dist/stories/with-layout.js +3 -5
  71. package/dist/types/alignment.d.ts +5 -3
  72. package/dist/types/background.d.ts +6 -5
  73. package/dist/types/base.d.ts +7 -0
  74. package/dist/types/base.js +1 -0
  75. package/dist/types/colors.d.ts +4 -4
  76. package/dist/types/component.d.ts +6 -2
  77. package/dist/types/components/button.d.ts +4 -1
  78. package/dist/types/components/footer.d.ts +2 -1
  79. package/dist/types/components/icon.d.ts +28 -0
  80. package/dist/types/components/icon.js +1 -0
  81. package/dist/types/components/image.d.ts +20 -0
  82. package/dist/types/components/image.js +1 -0
  83. package/dist/types/components/package.d.ts +2 -1
  84. package/dist/types/components/purchase-button.d.ts +2 -1
  85. package/dist/types/components/stack.d.ts +32 -0
  86. package/dist/types/components/stack.js +1 -0
  87. package/dist/types/components/text.d.ts +20 -0
  88. package/dist/types/components/text.js +1 -0
  89. package/dist/types/components/timeline.d.ts +35 -0
  90. package/dist/types/components/timeline.js +1 -0
  91. package/dist/types/localization.d.ts +2 -1
  92. package/dist/types/media.d.ts +4 -3
  93. package/dist/types/overrides.d.ts +48 -0
  94. package/dist/types/overrides.js +1 -0
  95. package/dist/types/variables.d.ts +13 -0
  96. package/dist/types/variables.js +10 -0
  97. package/dist/types.d.ts +17 -9
  98. package/dist/ui/atoms/typography.stories.svelte +1 -27
  99. package/dist/ui/molecules/button.stories.svelte +3 -8
  100. package/dist/ui/theme/colors.d.ts +0 -6
  101. package/dist/ui/theme/colors.js +1 -1
  102. package/dist/ui/theme/text.d.ts +3 -4
  103. package/dist/ui/theme/utils.d.ts +0 -10
  104. package/dist/ui/theme/utils.js +5 -5
  105. package/dist/utils/background-utils.d.ts +4 -0
  106. package/dist/utils/background-utils.js +39 -0
  107. package/dist/utils/base-utils.d.ts +18 -0
  108. package/dist/utils/base-utils.js +124 -0
  109. package/dist/utils/constants.d.ts +2 -2
  110. package/dist/utils/constants.js +6 -1
  111. package/dist/utils/font-utils.d.ts +4 -0
  112. package/dist/utils/font-utils.js +47 -0
  113. package/dist/utils/style-utils.d.ts +7 -120
  114. package/dist/utils/style-utils.js +22 -302
  115. package/dist/utils/variable-utils.d.ts +1 -22
  116. package/dist/utils/variable-utils.js +28 -24
  117. package/dist/web-components/index.css +1 -1
  118. package/dist/web-components/index.js +1323 -895
  119. package/package.json +34 -24
  120. package/dist/components/button/button-utils.d.ts +0 -2
  121. package/dist/components/button/button-utils.js +0 -19
  122. package/dist/components/image/image-utils.d.ts +0 -19
  123. package/dist/components/image/image-utils.js +0 -33
  124. package/dist/components/purchase-button/purchase-button-utils.d.ts +0 -2
  125. package/dist/components/purchase-button/purchase-button-utils.js +0 -20
  126. package/dist/stories/meta-templates.d.ts +0 -12
  127. package/dist/stories/meta-templates.js +0 -155
@@ -1,163 +1,179 @@
1
1
  <script lang="ts">
2
- import { getImageComponentStyles } from "./image-utils";
3
- import type { ImageProps } from "../../data/entities";
4
2
  import { getColorModeContext } from "../../stores/color-mode";
5
- import { DEFAULT_COLOR_MODE } from "../../utils/constants";
3
+ import { getSelectedStateContext } from "../../stores/selected";
4
+ import type { ImageProps } from "../../types/components/image";
5
+ import {
6
+ css,
7
+ mapColor,
8
+ mapColorMode,
9
+ mapFitMode,
10
+ mapSize,
11
+ mapSpacing,
12
+ } from "../../utils/base-utils";
13
+ import { getActiveStateProps } from "../../utils/style-utils";
14
+ import ClipPath from "./ClipPath.svelte";
15
+ import Overlay from "./Overlay.svelte";
6
16
 
7
- const { id, source, ...restProps }: ImageProps = $props();
17
+ const props: ImageProps = $props();
18
+
19
+ const selectedState = getSelectedStateContext();
20
+ const {
21
+ id,
22
+ source,
23
+ size,
24
+ mask_shape,
25
+ fit_mode,
26
+ padding,
27
+ margin,
28
+ color_overlay,
29
+ border,
30
+ shadow,
31
+ } = $derived.by(() => {
32
+ return {
33
+ ...props,
34
+ ...getActiveStateProps($selectedState, props.overrides),
35
+ };
36
+ });
8
37
 
9
38
  const getColorMode = getColorModeContext();
10
39
  const colorMode = $derived(getColorMode());
40
+ const image = $derived(mapColorMode(colorMode, source));
11
41
 
12
- let imageAspectRatio = $state(0);
13
- let imageElement: HTMLImageElement | null;
42
+ let wrapperWidth = $state(0);
43
+ let imageSize = $state({
44
+ height: 0,
45
+ width: 0,
46
+ });
14
47
 
15
- // Calculate aspect ratio once image loads
16
- function onImageLoad() {
17
- if (imageElement) {
18
- imageAspectRatio = imageElement.naturalHeight / imageElement.naturalWidth;
48
+ // TODO: Not needed if width/height are set. Remove once paywall stories are fixed or removed.
49
+ $effect(() => {
50
+ if (image.width || image.height) {
51
+ imageSize = {
52
+ height: image.height,
53
+ width: image.width,
54
+ };
55
+ return;
19
56
  }
20
- }
21
57
 
22
- const { imageStyles, maskPath, linearGradientAngle } = $derived(
23
- getImageComponentStyles(colorMode, {
24
- id,
25
- source,
26
- ...restProps,
27
- imageAspectRatio,
58
+ const img = new window.Image();
59
+ img.src = image.original;
60
+
61
+ const onImageLoad = () => {
62
+ imageSize = {
63
+ height: img.height,
64
+ width: img.width,
65
+ };
66
+ };
67
+
68
+ img.addEventListener("load", onImageLoad);
69
+ return () => {
70
+ img.removeEventListener("load", onImageLoad);
71
+ };
72
+ });
73
+
74
+ const height = $derived.by(() => {
75
+ if (size.height.type === "fixed") {
76
+ return size.height.value;
77
+ }
78
+ return Math.round(wrapperWidth * (imageSize.height / imageSize.width));
79
+ });
80
+
81
+ const style = $derived(
82
+ css({
83
+ width: mapSize(size.width),
84
+ height: `${height}px`,
85
+ margin: mapSpacing(margin),
86
+ padding: mapSpacing(padding),
87
+ "line-height": 0,
88
+ "flex-shrink": size.width.type === "fixed" ? 0 : 1,
28
89
  }),
29
90
  );
30
91
 
31
- const imageSource = $derived.by(() => {
32
- if (source[colorMode]?.original) {
33
- return source[colorMode].original;
34
- } else {
35
- return source[DEFAULT_COLOR_MODE]?.original as string;
92
+ let svgRect = $state<DOMRect | null>(null);
93
+
94
+ const [svgWidth, svgHeight] = $derived.by(() => {
95
+ return [svgRect?.width ?? 0, svgRect?.height ?? 0];
96
+ });
97
+
98
+ const viewBox = $derived.by(() => {
99
+ return `0 0 ${svgWidth} ${svgHeight}`;
100
+ });
101
+
102
+ const svgStyle = $derived.by(() => {
103
+ if (!shadow?.color) {
104
+ return "";
36
105
  }
106
+
107
+ const { x, y, radius, color } = shadow;
108
+ const shadowColor = mapColor(colorMode, color);
109
+ return `filter: drop-shadow(${x}px ${y}px ${radius}px ${shadowColor})`;
37
110
  });
38
111
 
39
- const colorOverlay = $derived(restProps.color_overlay);
40
- const colorInfo = $derived(
41
- colorOverlay?.[colorMode] ?? colorOverlay?.[DEFAULT_COLOR_MODE],
112
+ const overlay = $derived(
113
+ color_overlay && mapColorMode(colorMode, color_overlay),
42
114
  );
43
115
  </script>
44
116
 
45
- <img
46
- src={imageSource}
47
- bind:this={imageElement}
48
- onload={onImageLoad}
49
- style="display: none;"
50
- alt=""
51
- />
52
-
53
- <svg
54
- class="rc-pw-image-container"
55
- id={`rc-pw-image-container-${id}`}
56
- style={imageStyles}
57
- preserveAspectRatio="xMidYMid slice"
58
- viewBox={`0 0 100 ${imageAspectRatio * 100}`}
59
- >
60
- <defs>
61
- <clipPath id={`clip-path-${id}`}>
62
- {#if restProps.mask_shape?.type === "circle"}
63
- <ellipse
64
- cx="50"
65
- cy={imageAspectRatio * 50}
66
- rx="50"
67
- ry={imageAspectRatio * 50}
117
+ <div {style} bind:clientWidth={wrapperWidth}>
118
+ <svg
119
+ bind:contentRect={svgRect}
120
+ width="100%"
121
+ height="100%"
122
+ {viewBox}
123
+ style={svgStyle}
124
+ >
125
+ <defs>
126
+ <clipPath id={`${id}-path`}>
127
+ <ClipPath shape={mask_shape} width={svgWidth} height={svgHeight} />
128
+ </clipPath>
129
+
130
+ <g id={`${id}-border`}>
131
+ <ClipPath shape={mask_shape} width={svgWidth} height={svgHeight} />
132
+ </g>
133
+
134
+ <Overlay id={`${id}-overlay`} {overlay} />
135
+ </defs>
136
+
137
+ {#if border && border.width > 0}
138
+ <use href={`#${id}-border`} fill="transparent" />
139
+ {/if}
140
+
141
+ <g clip-path={`url(#${id}-path)`}>
142
+ <foreignObject x="0" y="0" width="100%" height="100%">
143
+ <img
144
+ src={image.original}
145
+ style="object-fit:{mapFitMode(fit_mode)}"
146
+ alt=""
147
+ />
148
+ </foreignObject>
149
+
150
+ {#if overlay}
151
+ <rect
152
+ x="0"
153
+ y="0"
154
+ height="100%"
155
+ width="100%"
156
+ fill={`url(#${id}-overlay)`}
68
157
  />
69
- {:else}
70
- <path d={maskPath} />
71
158
  {/if}
72
- </clipPath>
73
-
74
- {#if colorInfo?.type === "linear"}
75
- <linearGradient
76
- id={`gradient-${id}`}
77
- x1={linearGradientAngle.x1}
78
- y1={linearGradientAngle.y1}
79
- x2={linearGradientAngle.x2}
80
- y2={linearGradientAngle.y2}
81
- >
82
- {#each colorInfo?.points || [] as stop}
83
- <stop
84
- offset={`${stop.percent}%`}
85
- style={`stop-color: ${stop.color}`}
86
- />
87
- {/each}
88
- </linearGradient>
89
- {:else if colorInfo?.type === "radial"}
90
- <radialGradient
91
- id={`gradient-${id}`}
92
- cx="50%"
93
- cy="50%"
94
- r="50%"
95
- fx="50%"
96
- fy="50%"
97
- >
98
- {#each colorInfo?.points || [] as stop}
99
- <stop
100
- offset={`${stop.percent}%`}
101
- style={`stop-color: ${stop.color}`}
102
- />
103
- {/each}
104
- </radialGradient>
105
- {:else if colorInfo?.type === "hex"}
106
- <linearGradient id={`gradient-${id}`}>
107
- <stop offset="0%" style={`stop-color: ${colorInfo?.value}`} />
108
- </linearGradient>
109
- {/if}
110
- </defs>
111
-
112
- <image
113
- class="rc-pw-image"
114
- href={imageSource}
115
- x="0"
116
- y="0"
117
- width="100"
118
- height={imageAspectRatio * 100}
119
- clip-path={`url(#clip-path-${id})`}
120
- preserveAspectRatio="xMidYMid slice"
121
- {id}
122
- />
123
-
124
- <rect
125
- class="rc-pw-image-overlay"
126
- x="0"
127
- y="0"
128
- width="100"
129
- height={imageAspectRatio * 100}
130
- clip-path={`url(#clip-path-${id})`}
131
- fill={`url(#gradient-${id})`}
132
- />
133
- </svg>
134
159
 
135
- <style>
136
- .rc-pw-image-container {
137
- border-end-start-radius: var(--image-border-end-start-radius, 0px);
138
- border-end-end-radius: var(--image-border-end-end-radius, 0px);
139
- border-start-start-radius: var(--image-border-start-start-radius, 0px);
140
- border-start-end-radius: var(--image-border-start-end-radius, 0px);
141
- position: relative;
142
- overflow: hidden;
143
- display: flex;
144
- flex: var(--image-flex, 1 1 auto);
145
- position: var(--image-position, relative);
146
- inset: var(--image-inset, 0);
147
- transform: var(--image-transform, initial);
148
- height: var(--image-height, initial);
149
- width: var(--image-width, initial);
150
- }
160
+ {#if border && border.width > 0}
161
+ <use
162
+ href={`#${id}-border`}
163
+ fill="none"
164
+ stroke={mapColor(colorMode, border.color)}
165
+ stroke-width={border.width}
166
+ />
167
+ {/if}
168
+ </g>
169
+ </svg>
170
+ </div>
151
171
 
152
- .rc-pw-image {
172
+ <style>
173
+ img {
153
174
  width: 100%;
154
175
  height: 100%;
155
- object-fit: cover;
156
- display: block;
157
- }
158
-
159
- .rc-pw-image-overlay {
160
- position: absolute;
161
- inset: 0;
176
+ object-fit: contain;
177
+ object-position: center;
162
178
  }
163
179
  </style>
@@ -1,4 +1,4 @@
1
- import type { ImageProps } from "../../data/entities";
1
+ import type { ImageProps } from "../../types/components/image";
2
2
  declare const Image: import("svelte").Component<ImageProps, {}, "">;
3
3
  type Image = ReturnType<typeof Image>;
4
4
  export default Image;
@@ -0,0 +1,36 @@
1
+ <script lang="ts">
2
+ import type { ColorGradientInfo } from "../../types/colors";
3
+
4
+ interface OverlayProps {
5
+ id: string;
6
+ overlay: ColorGradientInfo | null | undefined;
7
+ }
8
+
9
+ const { id, overlay }: OverlayProps = $props();
10
+ </script>
11
+
12
+ {#if overlay?.type === "hex"}
13
+ <linearGradient {id} x1="0" y1="0" x2="100%" y2="100%">
14
+ <stop offset="0%" stop-color={overlay.value} />
15
+ <stop offset="100%" stop-color={overlay.value} />
16
+ </linearGradient>
17
+ {/if}
18
+
19
+ {#if overlay?.type === "linear"}
20
+ <linearGradient
21
+ {id}
22
+ gradientTransform={`rotate(${overlay.degrees - 90}, 0.5, 0.5)`}
23
+ >
24
+ {#each overlay.points as point}
25
+ <stop offset={`${point.percent}%`} stop-color={point.color} />
26
+ {/each}
27
+ </linearGradient>
28
+ {/if}
29
+
30
+ {#if overlay?.type === "radial"}
31
+ <radialGradient {id}>
32
+ {#each overlay.points as point}
33
+ <stop offset={`${point.percent}%`} stop-color={point.color} />
34
+ {/each}
35
+ </radialGradient>
36
+ {/if}
@@ -0,0 +1,8 @@
1
+ import type { ColorGradientInfo } from "../../types/colors";
2
+ interface OverlayProps {
3
+ id: string;
4
+ overlay: ColorGradientInfo | null | undefined;
5
+ }
6
+ declare const Overlay: import("svelte").Component<OverlayProps, {}, "">;
7
+ type Overlay = ReturnType<typeof Overlay>;
8
+ export default Overlay;
@@ -1,6 +1,8 @@
1
1
  <script module lang="ts">
2
2
  import Package from "./Package.svelte";
3
+ import { componentDecorator } from "../../stories/component-decorator";
3
4
  import { localizationDecorator } from "../../stories/localization-decorator";
5
+ import type { PackageProps } from "../../types/components/package";
4
6
  import { defineMeta } from "@storybook/addon-svelte-csf";
5
7
 
6
8
  const defaultLocale = "en_US";
@@ -10,8 +12,8 @@
10
12
  const { Story } = defineMeta({
11
13
  title: "Components/Package",
12
14
  component: Package,
13
- tags: ["autodocs"],
14
15
  decorators: [
16
+ componentDecorator(),
15
17
  localizationDecorator({
16
18
  defaultLocale,
17
19
  localizations: {
@@ -22,30 +24,21 @@
22
24
  },
23
25
  }),
24
26
  ],
25
- argTypes: {
26
- stack: {
27
- control: { type: "object" },
28
- description: "Stack configuration for package content",
29
- table: {
30
- type: {
31
- summary: "object",
32
- detail: "StackProps",
33
- },
34
- },
35
- },
36
- },
37
27
  });
38
28
  </script>
39
29
 
40
- <!-- Default -->
41
30
  <Story
42
31
  name="Default Package"
43
32
  args={{
44
- id: "6rQSD5e2Kz",
45
- is_selected_by_default: false,
33
+ type: "package",
34
+ id: "package",
46
35
  name: "Package - Monthly",
47
36
  package_id: "$rc_monthly",
37
+ is_selected_by_default: true,
48
38
  stack: {
39
+ type: "stack",
40
+ id: "stack",
41
+ name: "Stack",
49
42
  background_color: {
50
43
  light: {
51
44
  type: "hex",
@@ -208,14 +201,12 @@
208
201
  distribution: "space_between",
209
202
  type: "horizontal",
210
203
  },
211
- id: "u0KZLUZTQT",
212
204
  margin: {
213
205
  bottom: 0,
214
206
  leading: 16,
215
207
  top: 16,
216
208
  trailing: 16,
217
209
  },
218
- name: "Stack",
219
210
  padding: {
220
211
  bottom: 16,
221
212
  leading: 16,
@@ -241,9 +232,7 @@
241
232
  },
242
233
  },
243
234
  spacing: 8,
244
- type: "stack",
245
235
  shadow: null,
246
236
  },
247
- type: "package",
248
- }}
237
+ } satisfies PackageProps}
249
238
  />
@@ -1,19 +1,23 @@
1
1
  <script lang="ts">
2
2
  import Stack from "../stack/Stack.svelte";
3
3
  import { getPaywallContext } from "../../stores/paywall";
4
+ import { setSelectedStateContext } from "../../stores/selected";
4
5
  import {
5
6
  getVariablesContext,
6
7
  setVariablesContext,
7
8
  } from "../../stores/variables";
8
9
  import type { PackageProps } from "../../types/components/package";
9
- import { prefixObject, stringifyStyles } from "../../utils/style-utils";
10
10
  import { derived } from "svelte/store";
11
11
 
12
- const { stack, package_id, id, zStackChildStyles }: PackageProps = $props();
12
+ const { stack, package_id }: PackageProps = $props();
13
13
 
14
14
  const { selectedPackageId, variablesPerPackage } = getPaywallContext();
15
15
 
16
- const onPackageClick = () => ($selectedPackageId = package_id);
16
+ setSelectedStateContext(package_id);
17
+
18
+ const onPackageClick = () => {
19
+ $selectedPackageId = package_id;
20
+ };
17
21
 
18
22
  const fallbackVariables = getVariablesContext();
19
23
  const variables = derived(
@@ -21,37 +25,6 @@
21
25
  (fallback) => $variablesPerPackage?.[package_id] ?? fallback,
22
26
  );
23
27
  setVariablesContext(variables);
24
-
25
- const componentState = $derived({
26
- selected: $selectedPackageId === package_id,
27
- });
28
-
29
- const styles = $derived(
30
- stringifyStyles(prefixObject(zStackChildStyles, "package")),
31
- );
32
28
  </script>
33
29
 
34
- <button
35
- class="rc-pw-package"
36
- class:selected={componentState.selected}
37
- {id}
38
- onclick={onPackageClick}
39
- style={styles}
40
- >
41
- <Stack {...stack} {componentState} />
42
- </button>
43
-
44
- <style>
45
- .rc-pw-package {
46
- width: 100%;
47
- display: flex;
48
- margin: 0;
49
- padding: 0;
50
- background: initial;
51
- border: initial;
52
- text-align: initial;
53
- position: var(--package-position, relative);
54
- inset: var(--package-inset, 0);
55
- transform: var(--package-transform, initial);
56
- }
57
- </style>
30
+ <Stack {...stack} onclick={onPackageClick} />
@@ -8,37 +8,36 @@
8
8
  Timeline,
9
9
  } from "../..";
10
10
  import ButtonNode from "../button/ButtonNode.svelte";
11
- import type { ZStackChildStyles } from "../stack/stack-utils";
12
11
  import TextNode from "../text/TextNode.svelte";
13
- import type { ComponentState } from "../../data/entities";
14
12
  import type { Component } from "../../types/component";
15
13
  import type { Component as SvelteComponent } from "svelte";
14
+ import Icon from "../icon/Icon.svelte";
16
15
  import Self from "./Node.svelte";
17
16
 
18
17
  type SupportedComponents =
19
- | TextNode
20
- | Stack
21
- | Image
22
18
  | ButtonNode
23
- | PurchaseButton
24
- | Package
25
19
  | Footer
20
+ | Icon
21
+ | Image
22
+ | Package
23
+ | PurchaseButton
24
+ | Stack
25
+ | TextNode
26
26
  | Timeline;
27
27
 
28
28
  interface Props {
29
29
  nodeData: Component;
30
- zStackChildStyles?: ZStackChildStyles;
31
- componentState?: ComponentState;
32
30
  }
33
31
 
34
32
  const ComponentTypes = {
35
- stack: Stack,
36
- text: TextNode,
37
- image: Image,
38
33
  button: ButtonNode,
39
- purchase_button: PurchaseButton,
40
- package: Package,
41
34
  footer: Footer,
35
+ icon: Icon,
36
+ image: Image,
37
+ package: Package,
38
+ purchase_button: PurchaseButton,
39
+ stack: Stack,
40
+ text: TextNode,
42
41
  timeline: Timeline,
43
42
  } satisfies {
44
43
  [key in Component["type"]]: SvelteComponent<
@@ -57,7 +56,7 @@
57
56
  */
58
57
  export const getComponentClass: (
59
58
  nodeData: Component,
60
- ) => [SvelteComponent<SupportedComponents>, Component] = (
59
+ ) => [SvelteComponent<SupportedComponents>, Component] | undefined = (
61
60
  nodeData: Component,
62
61
  ) => {
63
62
  if (ComponentTypes[nodeData.type]) {
@@ -75,26 +74,26 @@
75
74
  ];
76
75
  }
77
76
 
78
- // manually throwing error for this specific case until
77
+ // Manually throwing error for this specific case until
79
78
  // it's handled with fallback components
80
- throw new Error(`Invalid component type: ${nodeData.type}`);
79
+ // throw new Error(`Invalid component type: ${nodeData.type}`);
81
80
  };
82
81
 
83
- const { nodeData, zStackChildStyles, ...restProps }: Props = $props();
82
+ const { nodeData, ...restProps }: Props = $props();
84
83
 
85
- const [ComponentToRender, dataToUse] = $derived(getComponentClass(nodeData));
84
+ const [ComponentToRender, dataToUse] = $derived(
85
+ getComponentClass(nodeData) ?? [],
86
+ );
86
87
 
87
88
  const components = $derived(
88
89
  ("components" in nodeData ? nodeData.components : undefined) ?? [],
89
90
  );
90
91
  </script>
91
92
 
92
- <ComponentToRender
93
- {...(dataToUse as any) || {}}
94
- {zStackChildStyles}
95
- {...restProps}
96
- >
97
- {#each components as childData}
98
- <Self nodeData={childData} {...restProps} />
99
- {/each}
100
- </ComponentToRender>
93
+ {#if ComponentToRender}
94
+ <ComponentToRender {...(dataToUse as any) || {}} {...restProps}>
95
+ {#each components as childData}
96
+ <Self nodeData={childData} {...restProps} />
97
+ {/each}
98
+ </ComponentToRender>
99
+ {/if}
@@ -1,15 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import { Footer, Image, Package, PurchaseButton, Stack, Timeline } from "../..";
3
3
  import ButtonNode from "../button/ButtonNode.svelte";
4
- import type { ZStackChildStyles } from "../stack/stack-utils";
5
4
  import TextNode from "../text/TextNode.svelte";
6
- import type { ComponentState } from "../../data/entities";
7
5
  import type { Component } from "../../types/component";
8
- type SupportedComponents = TextNode | Stack | Image | ButtonNode | PurchaseButton | Package | Footer | Timeline;
6
+ import Icon from "../icon/Icon.svelte";
7
+ type SupportedComponents = ButtonNode | Footer | Icon | Image | Package | PurchaseButton | Stack | TextNode | Timeline;
9
8
  interface Props {
10
9
  nodeData: Component;
11
- zStackChildStyles?: ZStackChildStyles;
12
- componentState?: ComponentState;
13
10
  }
14
11
  declare const Node: import("svelte").Component<Props, {
15
12
  /**
@@ -20,7 +17,7 @@ declare const Node: import("svelte").Component<Props, {
20
17
  * @param nodeData:Component - the Component object representing a Node in the paywall
21
18
  * @returns [Component<SupportedComponents>, Component] - a tuple containing the component class and the node data
22
19
  * @throws Error - if the component type and the fallback component type are not supported
23
- */ getComponentClass: (nodeData: Component) => [SvelteComponent<SupportedComponents>, Component];
20
+ */ getComponentClass: (nodeData: Component) => [SvelteComponent<SupportedComponents>, Component] | undefined;
24
21
  }, "">;
25
22
  type Node = ReturnType<typeof Node>;
26
23
  export default Node;