@revenuecat/purchases-ui-js 4.14.2 → 4.16.0

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 (39) hide show
  1. package/dist/components/button/ButtonNode.svelte +6 -0
  2. package/dist/components/package/Package.svelte +82 -10
  3. package/dist/components/paywall/Paywall.stories.svelte +335 -1
  4. package/dist/components/paywall/Paywall.svelte +95 -4
  5. package/dist/components/paywall/Paywall.svelte.d.ts +1 -0
  6. package/dist/components/paywall/Sheet.svelte +31 -1
  7. package/dist/components/paywall/fixtures/stack-scroll-paywall.d.ts +40 -0
  8. package/dist/components/paywall/fixtures/stack-scroll-paywall.js +280 -0
  9. package/dist/components/paywall/fixtures/window-rule-packages-paywall.d.ts +14 -0
  10. package/dist/components/paywall/fixtures/window-rule-packages-paywall.js +89 -0
  11. package/dist/components/paywall/fixtures/window-size-paywall.d.ts +2 -0
  12. package/dist/components/paywall/fixtures/window-size-paywall.js +48 -0
  13. package/dist/components/stack/Stack.svelte +87 -9
  14. package/dist/components/stack/Stack.svelte.d.ts +2 -0
  15. package/dist/components/stack/stack-scroll.d.ts +59 -0
  16. package/dist/components/stack/stack-scroll.js +162 -0
  17. package/dist/components/tabs/Tabs.svelte +11 -0
  18. package/dist/components/workflows/Screen.svelte +3 -0
  19. package/dist/components/workflows/Screen.svelte.d.ts +1 -0
  20. package/dist/components/workflows/Workflow.svelte +3 -0
  21. package/dist/components/workflows/Workflow.svelte.d.ts +1 -0
  22. package/dist/stores/condition-context.svelte.js +3 -0
  23. package/dist/stores/default-selection.d.ts +17 -0
  24. package/dist/stores/default-selection.js +21 -0
  25. package/dist/stores/rendered-packages.d.ts +10 -0
  26. package/dist/stores/rendered-packages.js +17 -0
  27. package/dist/stores/window-size.d.ts +10 -0
  28. package/dist/stores/window-size.js +10 -0
  29. package/dist/types/components/button.d.ts +1 -1
  30. package/dist/types/components/package.d.ts +1 -0
  31. package/dist/types/components/stack.d.ts +6 -0
  32. package/dist/types/overrides.d.ts +15 -1
  33. package/dist/types/overrides.js +3 -0
  34. package/dist/types/paywall-component-interaction.d.ts +1 -1
  35. package/dist/utils/package-selection.d.ts +26 -0
  36. package/dist/utils/package-selection.js +47 -0
  37. package/dist/utils/style-utils.d.ts +12 -0
  38. package/dist/utils/style-utils.js +59 -0
  39. package/package.json +2 -2
@@ -119,6 +119,26 @@ export function collectPackageIdsInDisplayOrder({ stack, sticky_footer, }) {
119
119
  ]),
120
120
  ];
121
121
  }
122
+ /**
123
+ * Each package component's place in display order (root stack, then sticky
124
+ * footer) and whether it sits inside tabs, by component id.
125
+ */
126
+ export function collectPackagePlacements({ stack, sticky_footer, }) {
127
+ const placements = new Map();
128
+ const walk = (node, inTabs) => {
129
+ if (node.type === "package" && !placements.has(node.id)) {
130
+ placements.set(node.id, { index: placements.size, inTabs });
131
+ }
132
+ for (const child of getPaywallComponentChildNodes(node)) {
133
+ walk(child, inTabs || node.type === "tabs");
134
+ }
135
+ };
136
+ walk(stack, false);
137
+ if (sticky_footer != null) {
138
+ walk(sticky_footer, false);
139
+ }
140
+ return placements;
141
+ }
122
142
  /**
123
143
  * Returns the overrides (in array order) whose conditions all match (AND) the
124
144
  * given context, without merging their properties.
@@ -206,6 +226,11 @@ const conditionMatches = (condition, context) => {
206
226
  if (condition.operator === "!=")
207
227
  return currentValue !== conditionValue;
208
228
  }
229
+ if (condition.type === RuleKey.WindowWidthCondition ||
230
+ condition.type === RuleKey.WindowHeightCondition ||
231
+ condition.type === RuleKey.WindowAspectRatioCondition) {
232
+ return windowSizeMatches(condition, context.windowSize);
233
+ }
209
234
  if (condition.type === RuleKey.StateCondition) {
210
235
  const stateValues = context.stateValues ?? {};
211
236
  const stateDefaults = context.stateDefaults ?? {};
@@ -233,6 +258,40 @@ const conditionMatches = (condition, context) => {
233
258
  }
234
259
  return false;
235
260
  };
261
+ // `=` compares an authored value against a fractional measurement, so it
262
+ // allows the same tolerances as Android.
263
+ const DIMENSION_EQUALITY_TOLERANCE_PX = 0.5;
264
+ const ASPECT_RATIO_EQUALITY_TOLERANCE = 1e-3;
265
+ function windowSizeMatches(condition, windowSize) {
266
+ if (!windowSize)
267
+ return false;
268
+ const { width, height } = windowSize;
269
+ if (condition.type === RuleKey.WindowWidthCondition) {
270
+ return compareNumbers(width, condition.operator, condition.value, DIMENSION_EQUALITY_TOLERANCE_PX);
271
+ }
272
+ if (condition.type === RuleKey.WindowHeightCondition) {
273
+ return compareNumbers(height, condition.operator, condition.value, DIMENSION_EQUALITY_TOLERANCE_PX);
274
+ }
275
+ if (height === 0)
276
+ return false;
277
+ return compareNumbers(width / height, condition.operator, condition.value, ASPECT_RATIO_EQUALITY_TOLERANCE);
278
+ }
279
+ function compareNumbers(actual, operator, expected, tolerance) {
280
+ switch (operator) {
281
+ case ">=":
282
+ return actual >= expected;
283
+ case ">":
284
+ return actual > expected;
285
+ case "<=":
286
+ return actual <= expected;
287
+ case "<":
288
+ return actual < expected;
289
+ case "=":
290
+ return Math.abs(actual - expected) < tolerance;
291
+ default:
292
+ return false;
293
+ }
294
+ }
236
295
  function stateValuesEqual(actual, expected) {
237
296
  if (typeof actual === "string" && typeof expected === "string") {
238
297
  return actual === expected;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@revenuecat/purchases-ui-js",
3
3
  "description": "Web components for Paywalls. Powered by RevenueCat",
4
4
  "private": false,
5
- "version": "4.14.2",
5
+ "version": "4.16.0",
6
6
  "author": {
7
7
  "name": "RevenueCat, Inc."
8
8
  },
@@ -99,7 +99,7 @@
99
99
  "@types/qrcode": "^1.5.6",
100
100
  "@types/react": "^19.2.14",
101
101
  "@typescript-eslint/parser": "8.57.2",
102
- "chromatic": "13.3.2",
102
+ "chromatic": "18.12.2",
103
103
  "eslint": "9.38.0",
104
104
  "eslint-plugin-storybook": "9.1.17",
105
105
  "eslint-plugin-svelte": "3.16.0",