@revenuecat/purchases-ui-js 2.0.0 → 2.0.1

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 (93) hide show
  1. package/dist/components/button/Button.svelte +1 -5
  2. package/dist/components/button/ButtonNode.stories.svelte +62 -70
  3. package/dist/components/button/ButtonNode.stories.svelte.d.ts +0 -8
  4. package/dist/components/button/ButtonNode.svelte +11 -19
  5. package/dist/components/button/ButtonNode.svelte.d.ts +2 -2
  6. package/dist/components/button/button-utils.d.ts +2 -2
  7. package/dist/components/footer/Footer.stories.svelte +30 -22
  8. package/dist/components/footer/Footer.stories.svelte.d.ts +0 -5
  9. package/dist/components/footer/Footer.svelte +3 -10
  10. package/dist/components/footer/Footer.svelte.d.ts +1 -1
  11. package/dist/components/image/Image.stories.svelte +26 -7
  12. package/dist/components/image/Image.svelte +17 -15
  13. package/dist/components/image/image-utils.d.ts +2 -1
  14. package/dist/components/image/image-utils.js +2 -2
  15. package/dist/components/package/Package.stories.svelte +31 -27
  16. package/dist/components/package/Package.stories.svelte.d.ts +0 -6
  17. package/dist/components/package/Package.svelte +18 -22
  18. package/dist/components/package/Package.svelte.d.ts +1 -1
  19. package/dist/components/paywall/Node.svelte +12 -39
  20. package/dist/components/paywall/Node.svelte.d.ts +4 -8
  21. package/dist/components/paywall/Paywall.stories.svelte +21 -78
  22. package/dist/components/paywall/Paywall.svelte +71 -98
  23. package/dist/components/paywall/Paywall.svelte.d.ts +4 -4
  24. package/dist/components/paywall/paywall-utils.d.ts +3 -2
  25. package/dist/components/paywall/paywall-utils.js +5 -5
  26. package/dist/components/purchase-button/PurchaseButton.stories.svelte +32 -26
  27. package/dist/components/purchase-button/PurchaseButton.stories.svelte.d.ts +0 -5
  28. package/dist/components/purchase-button/PurchaseButton.svelte +7 -11
  29. package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +1 -1
  30. package/dist/components/purchase-button/purchase-button-utils.d.ts +1 -1
  31. package/dist/components/stack/Stack.stories.svelte +34 -79
  32. package/dist/components/stack/Stack.svelte +15 -25
  33. package/dist/components/stack/stack-utils.d.ts +4 -3
  34. package/dist/components/stack/stack-utils.js +7 -8
  35. package/dist/components/text/TextNode.stories.svelte +46 -141
  36. package/dist/components/text/TextNode.svelte +13 -12
  37. package/dist/components/text/text-utils.d.ts +7 -6
  38. package/dist/components/text/text-utils.js +7 -7
  39. package/dist/components/timeline/Timeline.stories.svelte +41 -47
  40. package/dist/components/timeline/TimelineItem.svelte +28 -11
  41. package/dist/components/timeline/timeline-utils.d.ts +3 -3
  42. package/dist/components/timeline/timeline-utils.js +7 -16
  43. package/dist/data/entities.d.ts +59 -120
  44. package/dist/data/state.d.ts +0 -5
  45. package/dist/stores/color-mode.d.ts +6 -0
  46. package/dist/stores/color-mode.js +15 -0
  47. package/dist/stores/localization.d.ts +13 -0
  48. package/dist/stores/localization.js +25 -0
  49. package/dist/stores/paywall.d.ts +10 -0
  50. package/dist/stores/paywall.js +13 -0
  51. package/dist/stores/variables.d.ts +6 -0
  52. package/dist/stores/variables.js +14 -0
  53. package/dist/stories/fixtures.js +7 -76
  54. package/dist/stories/localization-decorator.d.ts +3 -0
  55. package/dist/stories/localization-decorator.js +7 -0
  56. package/dist/stories/paywall-decorator.d.ts +2 -0
  57. package/dist/stories/paywall-decorator.js +18 -0
  58. package/dist/stories/variables-decorator.d.ts +3 -0
  59. package/dist/stories/variables-decorator.js +9 -0
  60. package/dist/stories/with-layout.svelte +1 -1
  61. package/dist/types/alignment.d.ts +19 -0
  62. package/dist/types/alignment.js +1 -0
  63. package/dist/types/background.d.ts +18 -0
  64. package/dist/types/background.js +1 -0
  65. package/dist/types/colors.d.ts +34 -0
  66. package/dist/types/colors.js +1 -0
  67. package/dist/types/components/button.d.ts +36 -0
  68. package/dist/types/components/button.js +1 -0
  69. package/dist/types/components/footer.d.ts +5 -0
  70. package/dist/types/components/footer.js +1 -0
  71. package/dist/types/components/package.d.ts +8 -0
  72. package/dist/types/components/package.js +1 -0
  73. package/dist/types/components/purchase-button.d.ts +5 -0
  74. package/dist/types/components/purchase-button.js +1 -0
  75. package/dist/types/localization.d.ts +4 -0
  76. package/dist/types/localization.js +1 -0
  77. package/dist/types/media.d.ts +18 -0
  78. package/dist/types/media.js +1 -0
  79. package/dist/types.d.ts +5 -35
  80. package/dist/ui/atoms/typography.stories.svelte +8 -14
  81. package/dist/ui/atoms/typography.svelte +1 -1
  82. package/dist/ui/molecules/button.stories.svelte +8 -15
  83. package/dist/ui/molecules/button.svelte +2 -1
  84. package/dist/ui/molecules/button.svelte.d.ts +2 -26
  85. package/dist/ui/molecules/types.d.ts +2 -1
  86. package/dist/utils/style-utils.d.ts +13 -11
  87. package/dist/utils/style-utils.js +8 -15
  88. package/dist/utils/variable-utils.d.ts +1 -38
  89. package/dist/utils/variable-utils.js +6 -48
  90. package/dist/web-components/index.js +519 -566
  91. package/package.json +33 -36
  92. package/dist/stores/theme.d.ts +0 -1
  93. package/dist/stores/theme.js +0 -17
@@ -18,54 +18,12 @@ export const VARIABLE_NAMES = [
18
18
  "sub_offer_price_2",
19
19
  "sub_relative_discount",
20
20
  ];
21
- /**
22
- * Returns a string with the variables replaced by values from the dictionary
23
- * @param value A string like "Try {{ product_name }} for only {{ total_price_and_per_month }}"
24
- * @param dictionary Dictionary containing the values for the variables
25
- * @returns The string with values: "Try CatGPT Annual for only $59.99/yr ($4.99/mo)"
26
- */
27
- export const replaceVariables = ({ value = "", variableDictionary: dictionary, }) => {
28
- if (!dictionary)
29
- return value;
21
+ export function replaceVariables(input = "", variables) {
22
+ if (variables === undefined) {
23
+ return input;
24
+ }
30
25
  return VARIABLE_NAMES.reduce((result, variableName) => {
31
- const currentVariableReplaced = result.replaceAll(`{{ ${variableName} }}`, dictionary[variableName]?.toString() || "N/A");
26
+ const currentVariableReplaced = result.replaceAll(`{{ ${variableName} }}`, variables[variableName]?.toString() || "N/A");
32
27
  return currentVariableReplaced;
33
- }, value);
34
- };
35
- /**
36
- * Given a ComponentLocalizations object and a locale returns the label with label_id in the chosen locale, if any. Falls
37
- * back to the label with the same label_id in the fallbackLocale, if any. Finally returns undefined if no label can be
38
- * found for the requested label_id.
39
- * @param label_id - The id of the label to be returned
40
- * @param locale - The preferred locale to return the label
41
- * @param fallbackLocale - The locale to fall back to in case no label is found in the preferred one
42
- * @param labels - A ComponentLocalizations instance
43
- * @returns The label in the preferred or fallback locale, or undefined.
44
- */
45
- export function getLabelById(label_id, locale, fallbackLocale, labels) {
46
- if (!label_id)
47
- return "";
48
- const fallback = labels[fallbackLocale]?.[label_id];
49
- if (!(labels[locale] || {})[label_id]) {
50
- return fallback;
51
- }
52
- return labels[locale][label_id];
53
- }
54
- /**
55
- * Gets a label by ID and replaces any variables in it with values from the dictionary
56
- * @param text_lid - The ID of the text label to retrieve
57
- * @param purchaseState - Object containing locale and defaultLocale
58
- * @param labels - ComponentLocalizations containing the labels
59
- * @param variableDictionary - Dictionary of variables to replace in the label text
60
- * @returns The label with variables replaced, or undefined if label not found
61
- */
62
- export function getLabelAndReplaceVariables({ text_lid, locale, defaultLocale, labels, variableDictionary, }) {
63
- if (!text_lid)
64
- return "";
65
- const label = getLabelById(text_lid, locale, defaultLocale, labels);
66
- const parsedLabel = replaceVariables({
67
- value: label,
68
- variableDictionary,
69
- });
70
- return parsedLabel;
28
+ }, input);
71
29
  }