fontdue-js 3.11.0 → 3.12.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 (31) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/__generated__/CustomerLoginFormLoginMutation.graphql.d.ts +2 -1
  3. package/dist/__generated__/CustomerLoginFormLoginMutation.graphql.js +1 -1
  4. package/dist/__generated__/CustomerLoginFormRecaptchaQuery.graphql.d.ts +21 -0
  5. package/dist/__generated__/CustomerLoginFormRecaptchaQuery.graphql.js +86 -0
  6. package/dist/__generated__/CustomerSignInElementQuery.graphql.d.ts +22 -0
  7. package/dist/__generated__/CustomerSignInElementQuery.graphql.js +87 -0
  8. package/dist/__tests__/customerLoginRecaptcha.test.js +113 -0
  9. package/dist/__tests__/customerSignInElement.test.js +155 -0
  10. package/dist/__tests__/customerSignInRequest.test.js +85 -0
  11. package/dist/__tests__/stripeCheckoutError.test.js +110 -0
  12. package/dist/__tests__/typeTesterHeightAnimation.test.js +124 -0
  13. package/dist/__tests__/typeTesterPrefetchStyles.test.js +108 -0
  14. package/dist/__tests__/typeTesterShyFeaturesClose.test.js +133 -0
  15. package/dist/components/CustomerLoginForm/index.js +106 -11
  16. package/dist/components/CustomerSignIn/CustomerSignInElement.d.ts +22 -0
  17. package/dist/components/CustomerSignIn/CustomerSignInElement.js +132 -0
  18. package/dist/components/CustomerSignIn/index.js +4 -2
  19. package/dist/components/Root/index.js +2 -0
  20. package/dist/components/StripeProvider/index.js +19 -2
  21. package/dist/components/TypeTester/TypeTesterFeatures.js +27 -44
  22. package/dist/components/TypeTester/TypeTesterStyleSelect.js +6 -1
  23. package/dist/components/TypeTester/useCloseWhenToolbarHides.d.ts +17 -0
  24. package/dist/components/TypeTester/useCloseWhenToolbarHides.js +79 -0
  25. package/dist/components/TypeTester/useHeightAnimation.d.ts +27 -0
  26. package/dist/components/TypeTester/useHeightAnimation.js +85 -0
  27. package/dist/components/TypeTester/usePrefetchWhenNear.d.ts +14 -0
  28. package/dist/components/TypeTester/usePrefetchWhenNear.js +69 -0
  29. package/dist/fontdue.css +2 -1
  30. package/dist/version.js +1 -1
  31. package/package.json +1 -1
@@ -0,0 +1,69 @@
1
+ import { useEffect, useRef } from 'react';
2
+
3
+ // How far outside the viewport a tester counts as "near".
4
+ export const PREFETCH_ROOT_MARGIN = '300px';
5
+ // Upper bound on waiting for the browser to go idle.
6
+ export const PREFETCH_IDLE_TIMEOUT = 2000;
7
+ function onIdle(cb) {
8
+ if (typeof window.requestIdleCallback === 'function') {
9
+ const id = window.requestIdleCallback(cb, {
10
+ timeout: PREFETCH_IDLE_TIMEOUT
11
+ });
12
+ return {
13
+ cancel: () => window.cancelIdleCallback(id)
14
+ };
15
+ }
16
+ // Safari has no requestIdleCallback.
17
+ const id = window.setTimeout(cb, 200);
18
+ return {
19
+ cancel: () => window.clearTimeout(id)
20
+ };
21
+ }
22
+
23
+ /**
24
+ * Calls `prefetch` once, at idle time, after the element first comes near the
25
+ * viewport. Native `<select>` menus snapshot their options when they open (in
26
+ * Safari the open menu never updates), so data a dropdown needs has to be
27
+ * there before the first click – fetching on mousedown is too late. Waiting
28
+ * for idle keeps the request off the initial render, and waiting for the
29
+ * viewport keeps a long page of testers from fetching for every one at once.
30
+ *
31
+ * const ref = useRef<HTMLDivElement>(null);
32
+ * usePrefetchWhenNear(ref, loadOptions);
33
+ */
34
+ export default function usePrefetchWhenNear(ref, prefetch) {
35
+ const prefetchRef = useRef(prefetch);
36
+ prefetchRef.current = prefetch;
37
+ useEffect(() => {
38
+ const el = ref.current;
39
+ if (!el) return;
40
+ let idle = null;
41
+ const schedule = () => {
42
+ idle ??= onIdle(() => {
43
+ var _prefetchRef$current;
44
+ return (_prefetchRef$current = prefetchRef.current) === null || _prefetchRef$current === void 0 ? void 0 : _prefetchRef$current.call(prefetchRef);
45
+ });
46
+ };
47
+ if (typeof IntersectionObserver !== 'function') {
48
+ schedule();
49
+ return () => {
50
+ var _idle;
51
+ return (_idle = idle) === null || _idle === void 0 ? void 0 : _idle.cancel();
52
+ };
53
+ }
54
+ const observer = new IntersectionObserver(entries => {
55
+ if (entries.some(entry => entry.isIntersecting)) {
56
+ observer.disconnect();
57
+ schedule();
58
+ }
59
+ }, {
60
+ rootMargin: PREFETCH_ROOT_MARGIN
61
+ });
62
+ observer.observe(el);
63
+ return () => {
64
+ var _idle2;
65
+ observer.disconnect();
66
+ (_idle2 = idle) === null || _idle2 === void 0 ? void 0 : _idle2.cancel();
67
+ };
68
+ }, [ref]);
69
+ }
package/dist/fontdue.css CHANGED
@@ -4007,6 +4007,7 @@ input:disabled + .fontdue-admin-toolbar__switch {
4007
4007
 
4008
4008
  fontdue-test-fonts-form,
4009
4009
  fontdue-newsletter-signup,
4010
- fontdue-customer-login-form {
4010
+ fontdue-customer-login-form,
4011
+ fontdue-customer-sign-in {
4011
4012
  font-size: 1rem;
4012
4013
  }
package/dist/version.js CHANGED
@@ -8,4 +8,4 @@
8
8
  // (Fontage.ClientVersions) to spot sites that need to upgrade before a
9
9
  // feature that depends on a newer client can work for them.
10
10
  export const CLIENT_VERSION_HEADER = 'fontdue-client-version';
11
- export const version = "3.11.0";
11
+ export const version = "3.12.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fontdue-js",
3
- "version": "3.11.0",
3
+ "version": "3.12.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npm run relay && run-p build-js build-css build-ts",