@revenuecat/purchases-ui-js 2.0.1 → 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 (138) hide show
  1. package/dist/components/button/ButtonNode.stories.svelte +66 -108
  2. package/dist/components/button/ButtonNode.svelte +3 -31
  3. package/dist/components/footer/Footer.stories.svelte +112 -106
  4. package/dist/components/footer/Footer.svelte +10 -6
  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 -199
  12. package/dist/components/image/Image.svelte +152 -137
  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 +12 -27
  17. package/dist/components/package/Package.svelte +10 -44
  18. package/dist/components/paywall/Node.svelte +45 -43
  19. package/dist/components/paywall/Node.svelte.d.ts +10 -12
  20. package/dist/components/paywall/Paywall.stories.svelte +36 -140
  21. package/dist/components/paywall/Paywall.svelte +38 -20
  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 -29
  30. package/dist/components/purchase-button/PurchaseButton.svelte +2 -34
  31. package/dist/components/stack/Stack.stories.svelte +2364 -1020
  32. package/dist/components/stack/Stack.svelte +108 -151
  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 -257
  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 -48
  39. package/dist/components/text/TextNode.svelte +25 -37
  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 -256
  44. package/dist/components/timeline/Timeline.svelte +42 -30
  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 -114
  50. package/dist/data/entities.d.ts +23 -169
  51. package/dist/index.d.ts +11 -10
  52. package/dist/index.js +11 -10
  53. package/dist/stores/color-mode.d.ts +1 -1
  54. package/dist/stores/localization.d.ts +1 -1
  55. package/dist/stores/localization.js +3 -2
  56. package/dist/stores/paywall.d.ts +7 -3
  57. package/dist/stores/selected.d.ts +5 -0
  58. package/dist/stores/selected.js +12 -0
  59. package/dist/stores/variables.d.ts +2 -3
  60. package/dist/stores/variables.js +0 -1
  61. package/dist/stories/component-decorator.d.ts +2 -0
  62. package/dist/stories/component-decorator.js +12 -0
  63. package/dist/stories/fixtures.d.ts +6 -4
  64. package/dist/stories/fixtures.js +6241 -5485
  65. package/dist/stories/localization-decorator.js +1 -1
  66. package/dist/stories/paywall-decorator.js +8 -1
  67. package/dist/stories/variables-decorator.d.ts +1 -1
  68. package/dist/stories/viewport-decorator.d.ts +2 -0
  69. package/dist/stories/viewport-decorator.js +8 -0
  70. package/dist/stories/viewport-wrapper.svelte +53 -0
  71. package/dist/stories/viewport-wrapper.svelte.d.ts +10 -0
  72. package/dist/stories/with-layout.d.ts +2 -10
  73. package/dist/stories/with-layout.js +3 -5
  74. package/dist/stories/with-layout.svelte +3 -3
  75. package/dist/types/alignment.d.ts +5 -3
  76. package/dist/types/background.d.ts +6 -5
  77. package/dist/types/base.d.ts +7 -0
  78. package/dist/types/colors.d.ts +4 -4
  79. package/dist/types/component.d.ts +10 -0
  80. package/dist/types/component.js +1 -0
  81. package/dist/types/components/button.d.ts +5 -2
  82. package/dist/types/components/footer.d.ts +3 -2
  83. package/dist/types/components/icon.d.ts +28 -0
  84. package/dist/types/components/icon.js +1 -0
  85. package/dist/types/components/image.d.ts +20 -0
  86. package/dist/types/components/image.js +1 -0
  87. package/dist/types/components/package.d.ts +3 -2
  88. package/dist/types/components/purchase-button.d.ts +3 -2
  89. package/dist/types/components/stack.d.ts +32 -0
  90. package/dist/types/components/stack.js +1 -0
  91. package/dist/types/components/text.d.ts +20 -0
  92. package/dist/types/components/text.js +1 -0
  93. package/dist/types/components/timeline.d.ts +35 -0
  94. package/dist/types/components/timeline.js +1 -0
  95. package/dist/types/localization.d.ts +2 -1
  96. package/dist/types/media.d.ts +4 -3
  97. package/dist/types/overrides.d.ts +48 -0
  98. package/dist/types/overrides.js +1 -0
  99. package/dist/types/variables.d.ts +13 -0
  100. package/dist/types/variables.js +10 -0
  101. package/dist/types.d.ts +17 -9
  102. package/dist/ui/atoms/typography.stories.svelte +3 -29
  103. package/dist/ui/atoms/typography.stories.svelte.d.ts +1 -1
  104. package/dist/ui/layout/main-block.svelte +2 -2
  105. package/dist/ui/molecules/button.stories.svelte +5 -10
  106. package/dist/ui/molecules/button.svelte +1 -1
  107. package/dist/ui/theme/colors.d.ts +0 -6
  108. package/dist/ui/theme/colors.js +1 -1
  109. package/dist/ui/theme/text.d.ts +3 -4
  110. package/dist/ui/theme/theme.d.ts +2 -2
  111. package/dist/ui/theme/theme.js +2 -2
  112. package/dist/ui/theme/utils.d.ts +2 -12
  113. package/dist/ui/theme/utils.js +5 -5
  114. package/dist/utils/background-utils.d.ts +4 -0
  115. package/dist/utils/background-utils.js +39 -0
  116. package/dist/utils/base-utils.d.ts +18 -0
  117. package/dist/utils/base-utils.js +124 -0
  118. package/dist/utils/constants.d.ts +2 -2
  119. package/dist/utils/constants.js +6 -1
  120. package/dist/utils/font-utils.d.ts +4 -0
  121. package/dist/utils/font-utils.js +47 -0
  122. package/dist/utils/style-utils.d.ts +7 -120
  123. package/dist/utils/style-utils.js +35 -314
  124. package/dist/utils/variable-utils.d.ts +1 -22
  125. package/dist/utils/variable-utils.js +28 -24
  126. package/dist/web-components/index.css +1 -1
  127. package/dist/web-components/index.js +1415 -987
  128. package/package.json +34 -24
  129. package/dist/components/button/button-utils.d.ts +0 -2
  130. package/dist/components/button/button-utils.js +0 -19
  131. package/dist/components/image/image-utils.d.ts +0 -19
  132. package/dist/components/image/image-utils.js +0 -33
  133. package/dist/components/purchase-button/purchase-button-utils.d.ts +0 -2
  134. package/dist/components/purchase-button/purchase-button-utils.js +0 -20
  135. package/dist/data/state.d.ts +0 -4
  136. package/dist/stories/meta-templates.d.ts +0 -12
  137. package/dist/stories/meta-templates.js +0 -155
  138. /package/dist/{data/state.js → types/base.js} +0 -0
@@ -1,177 +1,134 @@
1
1
  <script lang="ts">
2
2
  import Node from "../paywall/Node.svelte";
3
- import {
4
- getBadgeStyles,
5
- getStackBadgeTextStyles,
6
- getStackComponentStyles,
7
- getZStackChildStyles,
8
- } from "./stack-utils";
9
- import Text from "../text/Text.svelte";
10
- import type { StackProps } from "../../data/entities";
11
3
  import { getColorModeContext } from "../../stores/color-mode";
12
- import { getLocalizationContext } from "../../stores/localization";
13
- import { getVariablesContext } from "../../stores/variables";
14
- import { replaceVariables } from "../../utils/variable-utils";
4
+ import { getSelectedStateContext } from "../../stores/selected";
5
+ import type { StackProps } from "../../types/components/stack";
6
+ import { mapBackground } from "../../utils/background-utils";
7
+ import {
8
+ css,
9
+ mapBorder,
10
+ mapBorderRadius,
11
+ mapShadow,
12
+ mapSize,
13
+ mapSpacing,
14
+ px,
15
+ } from "../../utils/base-utils";
16
+ import { getActiveStateProps } from "../../utils/style-utils";
17
+ import { mapBadge, mapDimension, mapLayerAlignment } from "./stack-utils";
15
18
 
19
+ interface MiscProps {
20
+ onclick?: () => void;
21
+ }
22
+
23
+ const props: StackProps & MiscProps = $props();
24
+ const selectedState = getSelectedStateContext();
16
25
  const {
17
- id,
18
26
  components,
19
- labels,
20
- purchaseState,
27
+ size,
28
+ dimension,
29
+ spacing,
30
+ margin,
31
+ padding,
32
+ background_color,
33
+ background,
34
+ border,
35
+ shape,
36
+ shadow,
21
37
  badge,
22
- zStackChildStyles,
23
- ...restProps
24
- }: StackProps = $props();
38
+ onclick,
39
+ } = $derived.by(() => {
40
+ return {
41
+ ...props,
42
+ ...getActiveStateProps($selectedState, props.overrides),
43
+ };
44
+ });
25
45
 
26
46
  const getColorMode = getColorModeContext();
27
47
  const colorMode = $derived(getColorMode());
28
48
 
29
- const stackStyles = $derived(
30
- getStackComponentStyles(colorMode, {
31
- id,
32
- components,
33
- labels,
34
- purchaseState,
35
- zStackChildStyles,
36
- ...restProps,
37
- }),
38
- );
39
- const badgeStyles = $derived(
40
- getBadgeStyles(colorMode, {
41
- id,
42
- components,
43
- labels,
44
- purchaseState,
45
- badge,
46
- ...restProps,
49
+ const style = $derived(
50
+ css({
51
+ display: "flex",
52
+ position: "relative",
53
+ width: mapSize(size.width),
54
+ height: mapSize(size.height),
55
+ ...mapDimension(dimension),
56
+ gap: px(spacing),
57
+ margin: mapSpacing(margin),
58
+ padding: mapSpacing(padding),
59
+ ...mapBackground(colorMode, background_color, background),
60
+ border: mapBorder(colorMode, border),
61
+ "border-radius": mapBorderRadius(shape),
62
+ "box-shadow": mapShadow(colorMode, shadow),
47
63
  }),
48
64
  );
49
65
 
50
- const zStackChildrenStyles = $derived(
51
- getZStackChildStyles({
52
- id,
53
- components,
54
- labels,
55
- purchaseState,
56
- ...restProps,
57
- }),
58
- );
66
+ const getLayerStyle = (index: number): string => {
67
+ if (index === 0 || dimension.type !== "zlayer") {
68
+ return "";
69
+ }
59
70
 
60
- const variables = getVariablesContext();
61
- const { getLocalizedString } = getLocalizationContext();
62
- const label = $derived(
63
- replaceVariables(getLocalizedString(badge?.text_lid), $variables),
64
- );
71
+ const { justifyContent, alignItems } = mapLayerAlignment(
72
+ dimension.alignment,
73
+ );
74
+ return css({
75
+ position: "absolute",
76
+ inset: 0,
77
+ display: "flex",
78
+ "justify-content": justifyContent,
79
+ "align-items": alignItems,
80
+ "z-index": index + 1,
81
+ });
82
+ };
65
83
 
66
- const { tagToRender, textStyles } = $derived(
67
- getStackBadgeTextStyles(colorMode, {
68
- id,
69
- components,
70
- labels,
71
- purchaseState,
72
- badge,
73
- ...restProps,
74
- }),
75
- );
84
+ const badgeStyle = $derived(css(mapBadge(badge, border?.width)));
76
85
  </script>
77
86
 
78
- <div {id} class="rc-pw-stack-wrapper" style={stackStyles}>
87
+ <svelte:element
88
+ this={onclick !== undefined ? "button" : "div"}
89
+ role={onclick !== undefined ? "button" : undefined}
90
+ {onclick}
91
+ {style}
92
+ class="stack"
93
+ >
79
94
  {#if badge}
80
- <span class="rc-pw-badge" style={badgeStyles}>
81
- <Text styleVariables={textStyles} component={tagToRender}>
82
- {label}
83
- </Text>
84
- </span>
95
+ <div style={badgeStyle}>
96
+ <Node nodeData={badge.stack} />
97
+ </div>
85
98
  {/if}
86
- <div class="rc-pw-stack">
87
- {#each components as component, index}
88
- {#if zStackChildrenStyles}
89
- <Node
90
- nodeData={component}
91
- {purchaseState}
92
- componentState={restProps.componentState}
93
- zStackChildStyles={index > 0 ? zStackChildrenStyles : undefined}
94
- />
95
- {:else}
96
- <Node
97
- nodeData={component}
98
- {purchaseState}
99
- componentState={restProps.componentState}
100
- />
101
- {/if}
99
+
100
+ {#if dimension.type === "zlayer"}
101
+ <div style="position: relative; width: 100%; height: 100%;">
102
+ {#each components as component, index}
103
+ <div style={getLayerStyle(index)}>
104
+ <Node nodeData={component} />
105
+ </div>
106
+ {/each}
107
+ </div>
108
+ {:else}
109
+ {#each components as component}
110
+ <Node nodeData={component} />
102
111
  {/each}
103
- </div>
104
- </div>
112
+ {/if}
113
+ </svelte:element>
105
114
 
106
115
  <style>
107
- .rc-pw-stack-wrapper {
108
- display: block;
109
- box-sizing: border-box;
110
- width: var(--stack-width, unset);
111
- height: var(--stack-height, unset);
112
- box-shadow: var(--stack-shadow, none);
113
- background: var(--stack-background, unset);
114
- position: var(--stack-position, relative);
115
- transform: var(--stack-transform, initial);
116
- inset: var(--stack-inset, initial);
117
- margin-block-start: var(--stack-margin-block-start, 0);
118
- margin-inline-end: var(--stack-margin-inline-end, 0);
119
- margin-block-end: var(--stack-margin-block-end, 0);
120
- margin-inline-start: var(--stack-margin-inline-start, 0);
121
- border: var(--stack-border, none);
122
- border-end-start-radius: var(--stack-border-end-start-radius, 0px);
123
- border-end-end-radius: var(--stack-border-end-end-radius, 0px);
124
- border-start-start-radius: var(--stack-border-start-start-radius, 0px);
125
- border-start-end-radius: var(--stack-border-start-end-radius, 0px);
126
- }
116
+ .stack {
117
+ appearance: none;
118
+ position: relative;
127
119
 
128
- .rc-pw-stack {
129
- background: none;
130
- overflow: hidden;
131
- box-sizing: border-box;
132
- width: 100%;
133
- height: 100%;
134
- display: flex;
135
- gap: var(--stack-spacing, 0);
136
- flex: var(--stack-flex, 0 1 auto);
137
- flex-direction: var(--stack-direction, unset);
138
- justify-content: var(--stack-distribution, flex-start);
139
- align-items: var(--stack-alignment, flex-start);
140
- padding-block-start: var(--stack-padding-block-start, 0);
141
- padding-inline-end: var(--stack-padding-inline-end, 0);
142
- padding-block-end: var(--stack-padding-block-end, 0);
143
- padding-inline-start: var(--stack-padding-inline-start, 0);
144
- }
145
- .rc-pw-badge {
146
- box-sizing: border-box;
147
- font-family: var(--stack-badge-font-family, sans-serif);
148
- position: absolute;
149
- inset: var(--stack-badge-inset, unset);
150
- transform: var(--stack-badge-transform, initial);
151
- margin-block-start: var(--stack-badge-margin-block-start, 0px);
152
- margin-inline-end: var(--stack-badge-margin-inline-end, 0px);
153
- margin-block-end: var(--stack-badge-margin-block-end, 0px);
154
- margin-inline-start: var(--stack-badge-margin-inline-start, 0px);
155
- padding-block-start: var(--stack-badge-padding-block-start, 0px);
156
- padding-inline-end: var(--stack-badge-padding-inline-end, 0px);
157
- padding-block-end: var(--stack-badge-padding-block-end, 0px);
158
- padding-inline-start: var(--stack-badge-padding-inline-start, 0px);
159
- background: var(--stack-badge-background, initial);
160
- color: var(--stack-badge-text-color, inherit);
161
- border: var(--stack-badge-border, none);
162
- border-end-start-radius: var(--stack-badge-border-end-start-radius, 0px);
163
- border-end-end-radius: var(--stack-badge-border-end-end-radius, 0px);
164
- border-start-start-radius: var(
165
- --stack-badge-border-start-start-radius,
166
- 0px
167
- );
168
- border-start-end-radius: var(--stack-badge-border-start-end-radius, 0px);
169
- box-shadow: var(--stack-badge-shadow, none);
170
- display: flex;
171
- align-items: center;
172
- justify-content: center;
173
- width: var(--stack-badge-badge-width, max-content);
174
- height: var(--stack-badge-badge-height, max-content);
175
- z-index: var(--stack-badge-z-index, 1);
120
+ &[role="button"] {
121
+ cursor: pointer;
122
+ }
123
+
124
+ &::before {
125
+ content: "";
126
+ position: absolute;
127
+ top: 0;
128
+ left: 0;
129
+ width: 100%;
130
+ height: 100%;
131
+ background: var(--overlay);
132
+ }
176
133
  }
177
134
  </style>
@@ -1,4 +1,8 @@
1
- import type { StackProps } from "../../data/entities";
2
- declare const Stack: import("svelte").Component<StackProps, {}, "">;
1
+ import type { StackProps } from "../../types/components/stack";
2
+ interface MiscProps {
3
+ onclick?: () => void;
4
+ }
5
+ type $$ComponentProps = StackProps & MiscProps;
6
+ declare const Stack: import("svelte").Component<$$ComponentProps, {}, "">;
3
7
  type Stack = ReturnType<typeof Stack>;
4
8
  export default Stack;
@@ -1,31 +1,11 @@
1
- import type { StackProps } from "../../data/entities";
2
- import type { ColorMode } from "../../types";
3
- /**
4
- * Generates comprehensive styles for stack components by combining component, dimension and size styles
5
- * @param props - Stack component properties including background, spacing, size, border etc.
6
- * @returns CSS style variables object with all stack-specific styles
7
- */
8
- export declare const getStackComponentStyles: (colorMode: ColorMode, props: StackProps) => string;
9
- /**
10
- * Generates styles for badge component within a stack
11
- * @param props - Stack component properties containing badge configuration
12
- * @returns CSS style object with badge-specific styles including positioning, dimensions and appearance
13
- */
14
- export declare function getBadgeStyles(colorMode: ColorMode, props: StackProps): string;
15
- /**
16
- * Generates text styles and HTML tag for a stack's badge component
17
- * @param props - Stack component properties containing badge configuration
18
- * @returns Object containing:
19
- * - tagToRender: HTML tag to use for the badge text
20
- * - textStyles: CSS styles string for the badge text
21
- */
22
- export declare function getStackBadgeTextStyles(colorMode: ColorMode, props: StackProps): {
23
- tagToRender: string;
24
- textStyles: string;
25
- };
26
- export declare function getZStackChildStyles(props: StackProps): ZStackChildStyles | undefined;
27
- export type ZStackChildStyles = {
28
- "--inset": string;
29
- "--transform": string;
30
- "--position": string;
1
+ import type { Dimension, ZAlignment } from "../../types/alignment";
2
+ import type { Badge } from "../../types/components/stack";
3
+ import { type CSS } from "../../utils/base-utils";
4
+ export declare function mapDimension(dimension: Dimension): Record<string, string>;
5
+ type JustifyAlign = {
6
+ justifyContent: string;
7
+ alignItems: string;
31
8
  };
9
+ export declare function mapLayerAlignment(alignment: ZAlignment): JustifyAlign;
10
+ export declare function mapBadge(badge?: Badge | null, parentBorderWidth?: number): CSS;
11
+ export {};