@economist/web-apple-pay 1.10.0 → 1.10.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/dist/index.js CHANGED
@@ -2211,18 +2211,32 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2211
2211
  if (await this.#fetchAndCacheOptions()) return;
2212
2212
  this.#finishLoading();
2213
2213
  } catch {
2214
- this.style.display = "none";
2215
- this.querySelector(SEL_CONTAINER)?.remove();
2214
+ this.#hide();
2216
2215
  } finally {
2217
2216
  this.#rendering = false;
2218
2217
  }
2219
2218
  }
2219
+ /**
2220
+ * Stop the loading spinner before tear-down so Safari does not leave a GPU
2221
+ * ghost of `.apple-pay-btn.wap-loading::before` after the container is removed.
2222
+ */
2223
+ #hide() {
2224
+ const button = this.querySelector(SEL_BUTTON);
2225
+ if (button) {
2226
+ button.classList.remove("wap-loading");
2227
+ button.removeAttribute("aria-busy");
2228
+ button.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2229
+ }
2230
+ this.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2231
+ void this.offsetHeight;
2232
+ this.style.display = "none";
2233
+ this.querySelector(SEL_CONTAINER)?.remove();
2234
+ }
2220
2235
  /** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
2221
2236
  async #checkAvailability() {
2222
2237
  const available = await isApplePayAvailable();
2223
2238
  if (!available) {
2224
- this.style.display = "none";
2225
- this.querySelector(SEL_CONTAINER)?.remove();
2239
+ this.#hide();
2226
2240
  return true;
2227
2241
  }
2228
2242
  return false;
@@ -2234,8 +2248,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2234
2248
  async #checkSession() {
2235
2249
  this.#sessionData = await this.#fetchSession();
2236
2250
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2237
- this.style.display = "none";
2238
- this.querySelector(SEL_CONTAINER)?.remove();
2251
+ this.#hide();
2239
2252
  return true;
2240
2253
  }
2241
2254
  return false;
@@ -2243,8 +2256,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2243
2256
  /** Returns `true` (hide) when no offer has been set before mount. */
2244
2257
  #checkOffer() {
2245
2258
  if (!this.#offer) {
2246
- this.style.display = "none";
2247
- this.querySelector(SEL_CONTAINER)?.remove();
2259
+ this.#hide();
2248
2260
  return true;
2249
2261
  }
2250
2262
  return false;
@@ -2271,8 +2283,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2271
2283
  async #fetchAndCacheOptions() {
2272
2284
  this.#paymentOptions = await this.#fetchPaymentOptions();
2273
2285
  if (!this.#paymentOptions?.options?.apple_pay) {
2274
- this.style.display = "none";
2275
- this.querySelector(SEL_CONTAINER)?.remove();
2286
+ this.#hide();
2276
2287
  return true;
2277
2288
  }
2278
2289
  return false;
@@ -2200,18 +2200,32 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2200
2200
  if (await this.#fetchAndCacheOptions()) return;
2201
2201
  this.#finishLoading();
2202
2202
  } catch {
2203
- this.style.display = "none";
2204
- this.querySelector(SEL_CONTAINER)?.remove();
2203
+ this.#hide();
2205
2204
  } finally {
2206
2205
  this.#rendering = false;
2207
2206
  }
2208
2207
  }
2208
+ /**
2209
+ * Stop the loading spinner before tear-down so Safari does not leave a GPU
2210
+ * ghost of `.apple-pay-btn.wap-loading::before` after the container is removed.
2211
+ */
2212
+ #hide() {
2213
+ const button = this.querySelector(SEL_BUTTON);
2214
+ if (button) {
2215
+ button.classList.remove("wap-loading");
2216
+ button.removeAttribute("aria-busy");
2217
+ button.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2218
+ }
2219
+ this.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2220
+ void this.offsetHeight;
2221
+ this.style.display = "none";
2222
+ this.querySelector(SEL_CONTAINER)?.remove();
2223
+ }
2209
2224
  /** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
2210
2225
  async #checkAvailability() {
2211
2226
  const available = await isApplePayAvailable();
2212
2227
  if (!available) {
2213
- this.style.display = "none";
2214
- this.querySelector(SEL_CONTAINER)?.remove();
2228
+ this.#hide();
2215
2229
  return true;
2216
2230
  }
2217
2231
  return false;
@@ -2223,8 +2237,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2223
2237
  async #checkSession() {
2224
2238
  this.#sessionData = await this.#fetchSession();
2225
2239
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2226
- this.style.display = "none";
2227
- this.querySelector(SEL_CONTAINER)?.remove();
2240
+ this.#hide();
2228
2241
  return true;
2229
2242
  }
2230
2243
  return false;
@@ -2232,8 +2245,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2232
2245
  /** Returns `true` (hide) when no offer has been set before mount. */
2233
2246
  #checkOffer() {
2234
2247
  if (!this.#offer) {
2235
- this.style.display = "none";
2236
- this.querySelector(SEL_CONTAINER)?.remove();
2248
+ this.#hide();
2237
2249
  return true;
2238
2250
  }
2239
2251
  return false;
@@ -2260,8 +2272,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2260
2272
  async #fetchAndCacheOptions() {
2261
2273
  this.#paymentOptions = await this.#fetchPaymentOptions();
2262
2274
  if (!this.#paymentOptions?.options?.apple_pay) {
2263
- this.style.display = "none";
2264
- this.querySelector(SEL_CONTAINER)?.remove();
2275
+ this.#hide();
2265
2276
  return true;
2266
2277
  }
2267
2278
  return false;
@@ -2208,18 +2208,32 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2208
2208
  if (await this.#fetchAndCacheOptions()) return;
2209
2209
  this.#finishLoading();
2210
2210
  } catch {
2211
- this.style.display = "none";
2212
- this.querySelector(SEL_CONTAINER)?.remove();
2211
+ this.#hide();
2213
2212
  } finally {
2214
2213
  this.#rendering = false;
2215
2214
  }
2216
2215
  }
2216
+ /**
2217
+ * Stop the loading spinner before tear-down so Safari does not leave a GPU
2218
+ * ghost of `.apple-pay-btn.wap-loading::before` after the container is removed.
2219
+ */
2220
+ #hide() {
2221
+ const button = this.querySelector(SEL_BUTTON);
2222
+ if (button) {
2223
+ button.classList.remove("wap-loading");
2224
+ button.removeAttribute("aria-busy");
2225
+ button.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2226
+ }
2227
+ this.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2228
+ void this.offsetHeight;
2229
+ this.style.display = "none";
2230
+ this.querySelector(SEL_CONTAINER)?.remove();
2231
+ }
2217
2232
  /** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
2218
2233
  async #checkAvailability() {
2219
2234
  const available = await isApplePayAvailable();
2220
2235
  if (!available) {
2221
- this.style.display = "none";
2222
- this.querySelector(SEL_CONTAINER)?.remove();
2236
+ this.#hide();
2223
2237
  return true;
2224
2238
  }
2225
2239
  return false;
@@ -2231,8 +2245,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2231
2245
  async #checkSession() {
2232
2246
  this.#sessionData = await this.#fetchSession();
2233
2247
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2234
- this.style.display = "none";
2235
- this.querySelector(SEL_CONTAINER)?.remove();
2248
+ this.#hide();
2236
2249
  return true;
2237
2250
  }
2238
2251
  return false;
@@ -2240,8 +2253,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2240
2253
  /** Returns `true` (hide) when no offer has been set before mount. */
2241
2254
  #checkOffer() {
2242
2255
  if (!this.#offer) {
2243
- this.style.display = "none";
2244
- this.querySelector(SEL_CONTAINER)?.remove();
2256
+ this.#hide();
2245
2257
  return true;
2246
2258
  }
2247
2259
  return false;
@@ -2268,8 +2280,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2268
2280
  async #fetchAndCacheOptions() {
2269
2281
  this.#paymentOptions = await this.#fetchPaymentOptions();
2270
2282
  if (!this.#paymentOptions?.options?.apple_pay) {
2271
- this.style.display = "none";
2272
- this.querySelector(SEL_CONTAINER)?.remove();
2283
+ this.#hide();
2273
2284
  return true;
2274
2285
  }
2275
2286
  return false;
@@ -2200,18 +2200,32 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2200
2200
  if (await this.#fetchAndCacheOptions()) return;
2201
2201
  this.#finishLoading();
2202
2202
  } catch {
2203
- this.style.display = "none";
2204
- this.querySelector(SEL_CONTAINER)?.remove();
2203
+ this.#hide();
2205
2204
  } finally {
2206
2205
  this.#rendering = false;
2207
2206
  }
2208
2207
  }
2208
+ /**
2209
+ * Stop the loading spinner before tear-down so Safari does not leave a GPU
2210
+ * ghost of `.apple-pay-btn.wap-loading::before` after the container is removed.
2211
+ */
2212
+ #hide() {
2213
+ const button = this.querySelector(SEL_BUTTON);
2214
+ if (button) {
2215
+ button.classList.remove("wap-loading");
2216
+ button.removeAttribute("aria-busy");
2217
+ button.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2218
+ }
2219
+ this.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2220
+ void this.offsetHeight;
2221
+ this.style.display = "none";
2222
+ this.querySelector(SEL_CONTAINER)?.remove();
2223
+ }
2209
2224
  /** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
2210
2225
  async #checkAvailability() {
2211
2226
  const available = await isApplePayAvailable();
2212
2227
  if (!available) {
2213
- this.style.display = "none";
2214
- this.querySelector(SEL_CONTAINER)?.remove();
2228
+ this.#hide();
2215
2229
  return true;
2216
2230
  }
2217
2231
  return false;
@@ -2223,8 +2237,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2223
2237
  async #checkSession() {
2224
2238
  this.#sessionData = await this.#fetchSession();
2225
2239
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2226
- this.style.display = "none";
2227
- this.querySelector(SEL_CONTAINER)?.remove();
2240
+ this.#hide();
2228
2241
  return true;
2229
2242
  }
2230
2243
  return false;
@@ -2232,8 +2245,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2232
2245
  /** Returns `true` (hide) when no offer has been set before mount. */
2233
2246
  #checkOffer() {
2234
2247
  if (!this.#offer) {
2235
- this.style.display = "none";
2236
- this.querySelector(SEL_CONTAINER)?.remove();
2248
+ this.#hide();
2237
2249
  return true;
2238
2250
  }
2239
2251
  return false;
@@ -2260,8 +2272,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2260
2272
  async #fetchAndCacheOptions() {
2261
2273
  this.#paymentOptions = await this.#fetchPaymentOptions();
2262
2274
  if (!this.#paymentOptions?.options?.apple_pay) {
2263
- this.style.display = "none";
2264
- this.querySelector(SEL_CONTAINER)?.remove();
2275
+ this.#hide();
2265
2276
  return true;
2266
2277
  }
2267
2278
  return false;
package/dist/src/index.js CHANGED
@@ -2211,18 +2211,32 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2211
2211
  if (await this.#fetchAndCacheOptions()) return;
2212
2212
  this.#finishLoading();
2213
2213
  } catch {
2214
- this.style.display = "none";
2215
- this.querySelector(SEL_CONTAINER)?.remove();
2214
+ this.#hide();
2216
2215
  } finally {
2217
2216
  this.#rendering = false;
2218
2217
  }
2219
2218
  }
2219
+ /**
2220
+ * Stop the loading spinner before tear-down so Safari does not leave a GPU
2221
+ * ghost of `.apple-pay-btn.wap-loading::before` after the container is removed.
2222
+ */
2223
+ #hide() {
2224
+ const button = this.querySelector(SEL_BUTTON);
2225
+ if (button) {
2226
+ button.classList.remove("wap-loading");
2227
+ button.removeAttribute("aria-busy");
2228
+ button.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2229
+ }
2230
+ this.getAnimations?.({ subtree: true }).forEach((animation) => animation.cancel());
2231
+ void this.offsetHeight;
2232
+ this.style.display = "none";
2233
+ this.querySelector(SEL_CONTAINER)?.remove();
2234
+ }
2220
2235
  /** Returns `true` (hide) when Apple Pay is unavailable on this device/browser. */
2221
2236
  async #checkAvailability() {
2222
2237
  const available = await isApplePayAvailable();
2223
2238
  if (!available) {
2224
- this.style.display = "none";
2225
- this.querySelector(SEL_CONTAINER)?.remove();
2239
+ this.#hide();
2226
2240
  return true;
2227
2241
  }
2228
2242
  return false;
@@ -2234,8 +2248,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2234
2248
  async #checkSession() {
2235
2249
  this.#sessionData = await this.#fetchSession();
2236
2250
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2237
- this.style.display = "none";
2238
- this.querySelector(SEL_CONTAINER)?.remove();
2251
+ this.#hide();
2239
2252
  return true;
2240
2253
  }
2241
2254
  return false;
@@ -2243,8 +2256,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2243
2256
  /** Returns `true` (hide) when no offer has been set before mount. */
2244
2257
  #checkOffer() {
2245
2258
  if (!this.#offer) {
2246
- this.style.display = "none";
2247
- this.querySelector(SEL_CONTAINER)?.remove();
2259
+ this.#hide();
2248
2260
  return true;
2249
2261
  }
2250
2262
  return false;
@@ -2271,8 +2283,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2271
2283
  async #fetchAndCacheOptions() {
2272
2284
  this.#paymentOptions = await this.#fetchPaymentOptions();
2273
2285
  if (!this.#paymentOptions?.options?.apple_pay) {
2274
- this.style.display = "none";
2275
- this.querySelector(SEL_CONTAINER)?.remove();
2286
+ this.#hide();
2276
2287
  return true;
2277
2288
  }
2278
2289
  return false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@economist/web-apple-pay",
3
3
  "description": "Web component package for Apple Pay checkout UI",
4
- "version": "1.10.0",
4
+ "version": "1.10.1",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",