@recapi/client 0.33.0 → 0.33.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.
package/README.md CHANGED
@@ -27,6 +27,25 @@ Playwright's Linux build, not Safari on an iPhone: the engine is the same,
27
27
  but Safari's own storage rules (data deleted after seven days without a
28
28
  visit, private browsing) are not part of it.
29
29
 
30
+ ### A still page in each engine
31
+
32
+ A row's place is held while it loads (WooCommerce and Magento print blank
33
+ cards, Shopify's box and the quick start's element hold it by style). In
34
+ each engine, the most the content under the rows moved from the first paint
35
+ (recapi's page-shift test, before and after 0.33.1, in px):
36
+
37
+ | Page | Chromium 390 / 1440 | Firefox 390 / 1440 | WebKit 390 / 1440 |
38
+ |---|---|---|---|
39
+ | Shopify box | 76 / 186 → 0.2 / 0.2 | 76 / 186 → 0.1 / 0.1 | 76 / 186 → 0.2 / 0.2 |
40
+ | WooCommerce | 27 / 27 → 0 / 0 | 27 / 27 → 0 / 0 | 27 / 27 → 0 / 0 |
41
+ | Magento | 27 / 27 → 0 / 0 | 27 / 27 → 0 / 0 | 27 / 27 → 0 / 0 |
42
+ | Plain row | 26 / 1.2 → 1.2 / 1.2 | 26 / 1.1 → 1.1 / 1.1 | 26 / 1.2 → 1.2 / 1.2 |
43
+
44
+ Without the script, every hold stays put, then closes after 4 s. Safari
45
+ 15.4 to 16.3 lacks the `lh` unit, and 15.4 container queries: there
46
+ Shopify's box and the quick start's element hold nothing until the script
47
+ comes, and blank cards are a line short. Nothing is hidden.
48
+
30
49
  ## Install
31
50
 
32
51
  On a site without a build step (a theme, plain HTML), load the SDK from
@@ -35,7 +54,7 @@ are, gzipped, and browsers cache them:
35
54
 
36
55
  ```html
37
56
  <script type="module">
38
- import { createClient } from 'https://api.example.com/sdk/0.33.0/index.js';
57
+ import { createClient } from 'https://api.example.com/sdk/0.33.1/index.js';
39
58
 
40
59
  const recapi = createClient({ apiKey: 'rk_pub_…', baseUrl: 'https://api.example.com', consent: false });
41
60
  // From your cookie banner, once the visitor agrees: recapi.setConsent(true).
@@ -139,7 +158,7 @@ nothing to paste again. A file of its own rather than more exports of
139
158
  a page of 250 per product view while recapi's answer asks for one (once the
140
159
  browser is idle and after the row; recapi keeps the progress, so nothing is
141
160
  stored), and fills the
142
- `<div id="recapi-recommendations"><style>#recapi-recommendations{container-type:inline-size}#recapi-recommendations::before{content:"";display:block;--c:4;--l:2;height:calc(var(--l)*((100cqw + 1rem)/var(--c) + .5rem + 3lh) + 2rem + 2lh);animation:recapi-gone 0s 4s forwards}@container (width<630px){#recapi-recommendations::before{--c:3;--l:4}}@container (width<470px){#recapi-recommendations::before{--c:2}}@keyframes recapi-gone{to{height:0}}</style></div>`
161
+ `<div id="recapi-recommendations"><style>#recapi-recommendations{container-type:inline-size}#recapi-recommendations:not(:is(.page-width,.section--page-width) *){box-sizing:border-box;max-width:var(--page-width,1200px);margin-inline:auto;padding-inline:clamp(1.5rem,(100vw - 749px)*999,5rem)}#recapi-recommendations::before{content:"";display:block;--c:4;--l:2;height:calc(var(--l)*((100cqw + 1rem)/var(--c) + .5rem + 3lh) + .4rem + 2lh);animation:recapi-gone 0s 4s forwards}@container (width<630px){#recapi-recommendations::before{--c:3;--l:4}}@container (width<470px){#recapi-recommendations::before{--c:2}}@keyframes recapi-gone{to{height:0}}</style></div>`
143
162
  the shop pastes where the row goes with 4 product
144
163
  cards it loads from Shopify's `/products/<handle>.js`. The box's style
145
164
  holds a blank card's place in the row's own proportions from the first
@@ -894,7 +913,7 @@ row, with nothing to set in the dashboard (`BOUGHT_TOGETHER` is the product
894
913
  page's second row).
895
914
 
896
915
  ```js
897
- import { RECENTLY_VIEWED } from 'https://api.example.com/sdk/0.33.0/index.js';
916
+ import { RECENTLY_VIEWED } from 'https://api.example.com/sdk/0.33.1/index.js';
898
917
 
899
918
  const [home, recent] = await recapi.recommendLists({
900
919
  lists: [{ placement: 'home', count: 4 }, { placement: RECENTLY_VIEWED, count: 4 }]
@@ -1278,16 +1297,16 @@ key on a format change makes old data invisible.
1278
1297
  ## Size budget
1279
1298
 
1280
1299
  What a first visit downloads before the library runs: each entry is one
1281
- file, joined and gzipped as the API serves it (library 0.33.0). A test fails
1300
+ file, joined and gzipped as the API serves it (library 0.33.1). A test fails
1282
1301
  when an entry passes its budget (`go test ./internal/jssdk -run SizeBudget -v`
1283
1302
  in `server/` prints these):
1284
1303
 
1285
1304
  | Entry | Bytes | Gzipped | Budget | Its files as they are |
1286
1305
  |---|--:|--:|--:|--:|
1287
- | `index.js` (the pasted tag) | 41,723 | 16,802 | 18,000 | 6 files, 38,197 |
1288
- | `woocommerce.js` | 51,394 | 20,274 | 20,500 | 9 files, 54,138 |
1289
- | `shopify.js` | 54,119 | 21,323 | 21,500 | 9 files, 57,043 |
1290
- | `magento.js` | 50,693 | 20,033 | 20,250 | 9 files, 53,770 |
1306
+ | `index.js` (the pasted tag) | 41,811 | 16,843 | 18,000 | 6 files, 38,228 |
1307
+ | `woocommerce.js` | 51,482 | 20,315 | 20,500 | 9 files, 54,242 |
1308
+ | `shopify.js` | 54,207 | 21,363 | 21,500 | 9 files, 57,147 |
1309
+ | `magento.js` | 50,781 | 20,074 | 20,250 | 9 files, 53,874 |
1291
1310
 
1292
1311
  `index.js` holds the row too, which it used to fetch at the first `row()`.
1293
1312
 
@@ -1305,6 +1324,12 @@ in `server/` writes the files as served, for `scripts/e2e/chain.mjs /tmp/served`
1305
1324
 
1306
1325
  ## Changes
1307
1326
 
1327
+ - 2026-12-02: version 0.33.1. A product name too long for two lines ends
1328
+ with an ellipsis, so a card never grows past its held place. The Shopify
1329
+ box to paste holds the page's width from the first paint: paste it again
1330
+ to get it. On Wix, a product widget not laid out yet no
1331
+ longer lets an off-centre column set the row's margins.
1332
+
1308
1333
  - 2026-12-02: version 0.33.0. Rows on a product page's first screen
1309
1334
  hold their place in the printed page, before the script comes: the
1310
1335
  WooCommerce plugin prints its blank cards and bought together's, the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@recapi/client",
3
- "version": "0.33.0",
3
+ "version": "0.33.1",
4
4
  "description": "Browser and Node client for the recapi recommendation API: local decayed history, event batching, attribution.",
5
5
  "homepage": "https://recapi.io/docs",
6
6
  "bugs": {
package/src/cards.js CHANGED
@@ -20,12 +20,13 @@ export const wasStyle = (scope) => `:where(${scope} .recapi-was){font-weight:400
20
20
  `:where(${scope} .recapi-unseen){position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}`;
21
21
 
22
22
  /**
23
- * A name takes two lines at least, a short one too: a row's cards are as
24
- * tall whatever their names, their prices line up, and the blank cards held
25
- * while the list loads are as tall as the real ones (most names wrap on a
26
- * phone). A browser without the `lh` unit draws names at their own height.
23
+ * A name takes two lines, a short one too, a long one cut with an ellipsis:
24
+ * a row's cards are as tall whatever their names, their prices line up, and
25
+ * the blank cards held while the list loads are as tall as the real ones
26
+ * (most names wrap on a phone; a third line moved the page 27 px as the row
27
+ * came). A browser without the `lh` unit draws short names at their height.
27
28
  */
28
- export const nameStyle = (scope) => `:where(${scope} a>span:first-of-type){min-height:2lh}`;
29
+ export const nameStyle = (scope) => `:where(${scope} a>span:first-of-type){min-height:2lh;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden}`;
29
30
 
30
31
  export const cardStyle = (scope) => `:where(${scope} a){display:flex;flex-direction:column;gap:.25rem;color:inherit;text-decoration:none}${nameStyle(scope)}` +
31
32
  `:where(${scope} img){display:block;width:100%;height:auto;aspect-ratio:1;object-fit:cover}` +
package/src/client.js CHANGED
@@ -1201,6 +1201,7 @@ function fitSlot(doc, el) {
1201
1201
  // Wix may lay its whole product off-centre in the section (one shop's phone
1202
1202
  // page: 20 px left, 60 right): a block as wide as the product's widget is
1203
1203
  // the product, not one of its columns, so its own margins count.
1204
+ // A hidden widget (width 0) proves nothing: every block would pass as it.
1204
1205
  const whole = doc.querySelector('[data-hook="product-page"]')?.getBoundingClientRect().width;
1205
1206
  let side = [0, 0];
1206
1207
  for (let up = name; up && !up.contains(el); up = up.parentElement) {
@@ -1208,7 +1209,7 @@ function fitSlot(doc, el) {
1208
1209
  const s = style(up);
1209
1210
  if (!r.width || !s) continue;
1210
1211
  const pair = [r.left + (parseFloat(s.borderLeftWidth) || 0) + (parseFloat(s.paddingLeft) || 0) - left, right - r.right + (parseFloat(s.borderRightWidth) || 0) + (parseFloat(s.paddingRight) || 0)];
1211
- if (pair.some((m) => m < 0) || pair[0] + pair[1] >= width / 2 || (Math.abs(pair[0] - pair[1]) > width / 10 && !(r.width >= whole))) continue;
1212
+ if (pair.some((m) => m < 0) || pair[0] + pair[1] >= width / 2 || (Math.abs(pair[0] - pair[1]) > width / 10 && !(whole && r.width >= whole))) continue;
1212
1213
  if (pair[0] + pair[1] > side[0] + side[1]) side = pair;
1213
1214
  }
1214
1215
  ['margin-left', 'margin-right'].forEach((key, k) => {