fontdue-js 3.0.6 → 3.1.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.
- package/CHANGELOG.md +10 -0
- package/dist/__generated__/FeatureTesterCard_fontStyle.graphql.d.ts +23 -0
- package/dist/__generated__/FeatureTesterCard_fontStyle.graphql.js +62 -0
- package/dist/__generated__/FeatureTesterStandaloneQuery.graphql.d.ts +25 -0
- package/dist/__generated__/FeatureTesterStandaloneQuery.graphql.js +240 -0
- package/dist/__generated__/FeatureTestersIdQuery.graphql.d.ts +21 -0
- package/dist/__generated__/FeatureTestersIdQuery.graphql.js +344 -0
- package/dist/__generated__/FeatureTestersSlugQuery.graphql.d.ts +25 -0
- package/dist/__generated__/FeatureTestersSlugQuery.graphql.js +364 -0
- package/dist/__generated__/FeatureTesters_collection.graphql.d.ts +39 -0
- package/dist/__generated__/FeatureTesters_collection.graphql.js +145 -0
- package/dist/__generated__/NodePasswordFormAccessNodeMutation.graphql.d.ts +2 -1
- package/dist/__generated__/NodePasswordFormAccessNodeMutation.graphql.js +10 -4
- package/dist/__generated__/NodePasswordFormElementIDQuery.graphql.d.ts +21 -0
- package/dist/__generated__/NodePasswordFormElementIDQuery.graphql.js +86 -0
- package/dist/__generated__/NodePasswordFormElementSlugQuery.graphql.d.ts +25 -0
- package/dist/__generated__/NodePasswordFormElementSlugQuery.graphql.js +108 -0
- package/dist/__tests__/createFontdueFetch.test.js +128 -4
- package/dist/__tests__/highlight.test.js +141 -0
- package/dist/__tests__/middleware.test.js +132 -0
- package/dist/components/FeatureTester/FeatureTesterCard.d.ts +30 -0
- package/dist/components/FeatureTester/FeatureTesterCard.js +167 -0
- package/dist/components/FeatureTester/FeatureTesterElement.d.ts +19 -0
- package/dist/components/FeatureTester/FeatureTesterElement.js +42 -0
- package/dist/components/FeatureTester/FeatureTesters.d.ts +43 -0
- package/dist/components/FeatureTester/FeatureTesters.js +156 -0
- package/dist/components/FeatureTester/FeatureTesters.server.d.ts +9 -0
- package/dist/components/FeatureTester/FeatureTesters.server.js +40 -0
- package/dist/components/FeatureTester/FeatureTestersElement.d.ts +10 -0
- package/dist/components/FeatureTester/FeatureTestersElement.js +27 -0
- package/dist/components/FeatureTester/highlight.d.ts +19 -0
- package/dist/components/FeatureTester/highlight.js +71 -0
- package/dist/components/FeatureTester/index.d.ts +26 -0
- package/dist/components/FeatureTester/index.js +66 -0
- package/dist/components/FeatureTester/index.server.d.ts +7 -0
- package/dist/components/FeatureTester/index.server.js +30 -0
- package/dist/components/NodePasswordForm/NodePasswordFormElement.d.ts +3 -0
- package/dist/components/NodePasswordForm/NodePasswordFormElement.js +65 -0
- package/dist/components/NodePasswordForm/index.d.ts +16 -1
- package/dist/components/NodePasswordForm/index.js +30 -59
- package/dist/components/Root/index.js +2 -1
- package/dist/fontdue.css +145 -0
- package/dist/hooks/useFeatureTesterAutofit.d.ts +17 -0
- package/dist/hooks/useFeatureTesterAutofit.js +106 -0
- package/dist/next/index.d.ts +2 -0
- package/dist/next/index.js +16 -1
- package/dist/next/registerSingleTenantResolver.js +13 -1
- package/dist/next/tenant.d.ts +1 -0
- package/dist/next/tenant.js +27 -2
- package/dist/nodeAccess.d.ts +18 -0
- package/dist/nodeAccess.js +84 -0
- package/dist/preview/server.d.ts +1 -20
- package/dist/preview/server.js +16 -85
- package/dist/relay/environment.js +8 -2
- package/dist/relay/serverConfig.d.ts +3 -0
- package/dist/relay/serverConfig.js +22 -1
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +90 -7
- package/dist/server/middleware.d.ts +37 -0
- package/dist/server/middleware.js +144 -0
- package/package.json +8 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
4
|
+
import _FeatureTesterStandaloneQuery from "../../__generated__/FeatureTesterStandaloneQuery.graphql.js";
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { graphql, useLazyLoadQuery, usePreloadedQuery } from 'react-relay';
|
|
7
|
+
import FeatureTesterCard from './FeatureTesterCard.js';
|
|
8
|
+
import { EnsureFontdueContext } from '../FontdueContextProvider/index.js';
|
|
9
|
+
import loadSerializableQuery from '../../relay/loadSerializableQuery.js';
|
|
10
|
+
import useSerializablePreloadedQuery from '../../relay/useSerializablePreloadedQuery.js';
|
|
11
|
+
import FeatureTesterStandaloneQueryNode from '../../__generated__/FeatureTesterStandaloneQuery.graphql.js';
|
|
12
|
+
const query = (_FeatureTesterStandaloneQuery.hash && _FeatureTesterStandaloneQuery.hash !== "eddba300b2fd5e283ab1f8f787edc518" && console.error("The definition of 'FeatureTesterStandaloneQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _FeatureTesterStandaloneQuery);
|
|
13
|
+
function FeatureTesterRender(_ref) {
|
|
14
|
+
var _data$viewer;
|
|
15
|
+
let {
|
|
16
|
+
data,
|
|
17
|
+
...rest
|
|
18
|
+
} = _ref;
|
|
19
|
+
const fontStyle = (_data$viewer = data.viewer) === null || _data$viewer === void 0 ? void 0 : _data$viewer.fontStyle;
|
|
20
|
+
if (!fontStyle) {
|
|
21
|
+
console.log('[FeatureTester]: No FontStyle found');
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return /*#__PURE__*/React.createElement(FeatureTesterCard, _extends({
|
|
25
|
+
fontStyle: fontStyle
|
|
26
|
+
}, rest));
|
|
27
|
+
}
|
|
28
|
+
export async function loadFeatureTesterQuery(variables, options) {
|
|
29
|
+
return loadSerializableQuery(FeatureTesterStandaloneQueryNode, {
|
|
30
|
+
familyName: variables.familyName,
|
|
31
|
+
styleName: variables.styleName
|
|
32
|
+
}, options);
|
|
33
|
+
}
|
|
34
|
+
export function FeatureTesterPreloadedRenderer(_ref2) {
|
|
35
|
+
let {
|
|
36
|
+
preloadedQuery,
|
|
37
|
+
...rest
|
|
38
|
+
} = _ref2;
|
|
39
|
+
const queryRef = useSerializablePreloadedQuery(preloadedQuery, 'store-or-network', query);
|
|
40
|
+
const data = usePreloadedQuery(query, queryRef);
|
|
41
|
+
return /*#__PURE__*/React.createElement(FeatureTesterRender, _extends({
|
|
42
|
+
data: data
|
|
43
|
+
}, rest));
|
|
44
|
+
}
|
|
45
|
+
function FeatureTesterLazyRenderer(_ref3) {
|
|
46
|
+
let {
|
|
47
|
+
familyName,
|
|
48
|
+
styleName,
|
|
49
|
+
...rest
|
|
50
|
+
} = _ref3;
|
|
51
|
+
const data = useLazyLoadQuery(query, {
|
|
52
|
+
familyName,
|
|
53
|
+
styleName
|
|
54
|
+
});
|
|
55
|
+
return /*#__PURE__*/React.createElement(FeatureTesterRender, _extends({
|
|
56
|
+
data: data
|
|
57
|
+
}, rest));
|
|
58
|
+
}
|
|
59
|
+
// Unified FeatureTester entry point. Accepts either a preloaded query
|
|
60
|
+
// (server-side preload path) or `{familyName, styleName}` (lazy path, used by
|
|
61
|
+
// the CDN custom element and inside an existing `<FontdueProvider>` tree).
|
|
62
|
+
export default function FeatureTester(props) {
|
|
63
|
+
return /*#__PURE__*/React.createElement(EnsureFontdueContext, {
|
|
64
|
+
config: props.config
|
|
65
|
+
}, 'preloadedQuery' in props && props.preloadedQuery ? /*#__PURE__*/React.createElement(FeatureTesterPreloadedRenderer, props) : /*#__PURE__*/React.createElement(FeatureTesterLazyRenderer, props));
|
|
66
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { FeatureTesterProps } from './index.js';
|
|
3
|
+
export type { FeatureTesterPreloadedQuery } from './index.js';
|
|
4
|
+
export declare function loadFeatureTesterQuery(): never;
|
|
5
|
+
export default function FeatureTester(props: Extract<FeatureTesterProps, {
|
|
6
|
+
familyName: string;
|
|
7
|
+
}>): Promise<React.JSX.Element>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import loadSerializableQuery from '../../relay/loadSerializableQuery.js';
|
|
4
|
+
import { FeatureTesterPreloadedRenderer } from './index.js';
|
|
5
|
+
import FeatureTesterStandaloneQueryNode from '../../__generated__/FeatureTesterStandaloneQuery.graphql.js';
|
|
6
|
+
// Stub for the RSC export condition. See FontdueProvider/index.server.tsx
|
|
7
|
+
// for the rationale.
|
|
8
|
+
export function loadFeatureTesterQuery() {
|
|
9
|
+
throw new Error("loadFeatureTesterQuery isn't needed in React Server Components — " + 'the <FeatureTester> server entrypoint awaits its query automatically. ' + 'Drop the manual call.');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Next RSC variant: awaits the query on the server and hands the response to
|
|
13
|
+
// the client `FeatureTesterPreloadedRenderer`. Lets pages just write
|
|
14
|
+
// `<FeatureTester familyName="..." styleName="..." feature="..." content="..." />`
|
|
15
|
+
// in an RSC without manually invoking `loadFeatureTesterQuery` + threading
|
|
16
|
+
// `preloadedQuery` through props.
|
|
17
|
+
export default async function FeatureTester(props) {
|
|
18
|
+
const {
|
|
19
|
+
familyName,
|
|
20
|
+
styleName,
|
|
21
|
+
...rest
|
|
22
|
+
} = props;
|
|
23
|
+
const preloadedQuery = await loadSerializableQuery(FeatureTesterStandaloneQueryNode, {
|
|
24
|
+
familyName,
|
|
25
|
+
styleName
|
|
26
|
+
});
|
|
27
|
+
return /*#__PURE__*/React.createElement(FeatureTesterPreloadedRenderer, _extends({
|
|
28
|
+
preloadedQuery: preloadedQuery
|
|
29
|
+
}, rest));
|
|
30
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
4
|
+
import _NodePasswordFormElementSlugQuery from "../../__generated__/NodePasswordFormElementSlugQuery.graphql.js";
|
|
5
|
+
import _NodePasswordFormElementIDQuery from "../../__generated__/NodePasswordFormElementIDQuery.graphql.js";
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { graphql, useLazyLoadQuery } from 'react-relay';
|
|
8
|
+
import NodePasswordForm from './index.js';
|
|
9
|
+
// Auto-detecting wrapper behind the <fontdue-node-password-form> custom element.
|
|
10
|
+
// Unlike the presentational React component (the default export of ./index, used
|
|
11
|
+
// when the server has already detected the lock), this queries the collection
|
|
12
|
+
// itself and renders the form only when access is denied — so it works dropped
|
|
13
|
+
// onto any page, hiding itself for a visitor who already has access.
|
|
14
|
+
|
|
15
|
+
const idQuery = (_NodePasswordFormElementIDQuery.hash && _NodePasswordFormElementIDQuery.hash !== "213a61ae079e4f57b7b197b0d2f5256a" && console.error("The definition of 'NodePasswordFormElementIDQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _NodePasswordFormElementIDQuery);
|
|
16
|
+
function NodePasswordFormIDQueryRenderer(_ref) {
|
|
17
|
+
let {
|
|
18
|
+
collectionId,
|
|
19
|
+
...rest
|
|
20
|
+
} = _ref;
|
|
21
|
+
const data = useLazyLoadQuery(idQuery, {
|
|
22
|
+
collectionId
|
|
23
|
+
});
|
|
24
|
+
// The @catch directive surfaces the password-protection error as ok:false; the
|
|
25
|
+
// node is only locked then, so only then do we render the form (we don't want
|
|
26
|
+
// to show it to a visitor who already has access).
|
|
27
|
+
if (data.collection.ok === false) return /*#__PURE__*/React.createElement(NodePasswordForm, _extends({}, rest, {
|
|
28
|
+
collectionId: collectionId
|
|
29
|
+
}));
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const slugQuery = (_NodePasswordFormElementSlugQuery.hash && _NodePasswordFormElementSlugQuery.hash !== "200a33ca6a1f9e4e7e95b7100bbdd261" && console.error("The definition of 'NodePasswordFormElementSlugQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _NodePasswordFormElementSlugQuery);
|
|
33
|
+
function NodePasswordFormSlugQueryRenderer(_ref2) {
|
|
34
|
+
var _data$viewer$slug;
|
|
35
|
+
let {
|
|
36
|
+
collectionSlug,
|
|
37
|
+
...rest
|
|
38
|
+
} = _ref2;
|
|
39
|
+
const data = useLazyLoadQuery(slugQuery, {
|
|
40
|
+
collectionSlug
|
|
41
|
+
});
|
|
42
|
+
// see note in NodePasswordFormIDQueryRenderer
|
|
43
|
+
if (((_data$viewer$slug = data.viewer.slug) === null || _data$viewer$slug === void 0 ? void 0 : _data$viewer$slug.collection.ok) === false) return /*#__PURE__*/React.createElement(NodePasswordForm, _extends({}, rest, {
|
|
44
|
+
collectionSlug: collectionSlug
|
|
45
|
+
}));
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
export default function NodePasswordFormElement(_ref3) {
|
|
49
|
+
let {
|
|
50
|
+
collectionId,
|
|
51
|
+
collectionSlug,
|
|
52
|
+
...rest
|
|
53
|
+
} = _ref3;
|
|
54
|
+
if (collectionId) {
|
|
55
|
+
return /*#__PURE__*/React.createElement(NodePasswordFormIDQueryRenderer, _extends({
|
|
56
|
+
collectionId: collectionId
|
|
57
|
+
}, rest));
|
|
58
|
+
}
|
|
59
|
+
if (collectionSlug) {
|
|
60
|
+
return /*#__PURE__*/React.createElement(NodePasswordFormSlugQueryRenderer, _extends({
|
|
61
|
+
collectionSlug: collectionSlug
|
|
62
|
+
}, rest));
|
|
63
|
+
}
|
|
64
|
+
throw new Error('NodePasswordForm expected either a collectionId or collectionSlug prop');
|
|
65
|
+
}
|
|
@@ -3,4 +3,19 @@ export interface NodePasswordForm_props {
|
|
|
3
3
|
collectionId?: string | null;
|
|
4
4
|
collectionSlug?: string | null;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Password form for a collection you already know is locked. Render it when a
|
|
8
|
+
* collection comes back password-protected (see the per-framework guides): it
|
|
9
|
+
* commits the `accessNode` mutation, remembers the returned access token, and
|
|
10
|
+
* reloads so the now-unlocked collection renders.
|
|
11
|
+
*
|
|
12
|
+
* Unlike the `<fontdue-node-password-form>` custom element (which detects the
|
|
13
|
+
* locked state itself), this does no data fetching of its own, so it renders
|
|
14
|
+
* immediately on the server with no Suspense flash — the server already detected
|
|
15
|
+
* the lock.
|
|
16
|
+
*
|
|
17
|
+
* Self-wraps in `EnsureFontdueContext` so it works as a standalone island (e.g.
|
|
18
|
+
* an Astro `client:load`) without its own provider, and no-ops inside an outer
|
|
19
|
+
* `<FontdueProvider>` (Next/RR7/TanStack).
|
|
20
|
+
*/
|
|
21
|
+
export default function NodePasswordForm(props: NodePasswordForm_props): React.JSX.Element;
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
4
|
-
import _NodePasswordFormSlugQuery from "../../__generated__/NodePasswordFormSlugQuery.graphql.js";
|
|
5
|
-
import _NodePasswordFormIDQuery from "../../__generated__/NodePasswordFormIDQuery.graphql.js";
|
|
6
3
|
import _NodePasswordFormAccessNodeMutation from "../../__generated__/NodePasswordFormAccessNodeMutation.graphql.js";
|
|
7
4
|
import React, { useState } from 'react';
|
|
8
|
-
import { graphql,
|
|
5
|
+
import { graphql, useMutation } from 'react-relay';
|
|
9
6
|
import TextField from '../TextField/index.js';
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import { EnsureFontdueContext } from '../FontdueContextProvider/index.js';
|
|
8
|
+
import { rememberNodeAccessToken } from '../../nodeAccess.js';
|
|
9
|
+
const accessNodeMutation = (_NodePasswordFormAccessNodeMutation.hash && _NodePasswordFormAccessNodeMutation.hash !== "eb0d3828d65a52c727ef60caa67709a1" && console.error("The definition of 'NodePasswordFormAccessNodeMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _NodePasswordFormAccessNodeMutation);
|
|
10
|
+
/**
|
|
11
|
+
* Password form for a collection you already know is locked. Render it when a
|
|
12
|
+
* collection comes back password-protected (see the per-framework guides): it
|
|
13
|
+
* commits the `accessNode` mutation, remembers the returned access token, and
|
|
14
|
+
* reloads so the now-unlocked collection renders.
|
|
15
|
+
*
|
|
16
|
+
* Unlike the `<fontdue-node-password-form>` custom element (which detects the
|
|
17
|
+
* locked state itself), this does no data fetching of its own, so it renders
|
|
18
|
+
* immediately on the server with no Suspense flash — the server already detected
|
|
19
|
+
* the lock.
|
|
20
|
+
*
|
|
21
|
+
* Self-wraps in `EnsureFontdueContext` so it works as a standalone island (e.g.
|
|
22
|
+
* an Astro `client:load`) without its own provider, and no-ops inside an outer
|
|
23
|
+
* `<FontdueProvider>` (Next/RR7/TanStack).
|
|
24
|
+
*/
|
|
25
|
+
export default function NodePasswordForm(props) {
|
|
26
|
+
return /*#__PURE__*/React.createElement(EnsureFontdueContext, null, /*#__PURE__*/React.createElement(NodePasswordFormFields, props));
|
|
27
|
+
}
|
|
28
|
+
function NodePasswordFormFields(props) {
|
|
12
29
|
const [password, setPassword] = useState('');
|
|
13
30
|
const [error, setError] = useState(null);
|
|
14
31
|
const [commitMutation, submitting] = useMutation(accessNodeMutation);
|
|
@@ -27,7 +44,14 @@ function NodePasswordFormComponent(props) {
|
|
|
27
44
|
onCompleted: res => {
|
|
28
45
|
var _res$accessNode;
|
|
29
46
|
if ((_res$accessNode = res.accessNode) !== null && _res$accessNode !== void 0 && _res$accessNode.success) {
|
|
47
|
+
// Persist the token so the next server render unlocks the collection:
|
|
48
|
+
// the Fontdue session cookie that does this for script-tag sites can't
|
|
49
|
+
// ride a proxied or cross-origin server fetch, so we forward this
|
|
50
|
+
// token as a header instead (see fontdue-js nodeAccess).
|
|
51
|
+
rememberNodeAccessToken(res.accessNode.token);
|
|
30
52
|
location.reload();
|
|
53
|
+
} else {
|
|
54
|
+
setError('Incorrect password');
|
|
31
55
|
}
|
|
32
56
|
},
|
|
33
57
|
onError: error => {
|
|
@@ -55,57 +79,4 @@ function NodePasswordFormComponent(props) {
|
|
|
55
79
|
disabled: disabled,
|
|
56
80
|
className: "submit-button"
|
|
57
81
|
}, "Submit")));
|
|
58
|
-
}
|
|
59
|
-
const idQuery = (_NodePasswordFormIDQuery.hash && _NodePasswordFormIDQuery.hash !== "2af86f8f6df3d2e6061ea1c9dd777a26" && console.error("The definition of 'NodePasswordFormIDQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _NodePasswordFormIDQuery);
|
|
60
|
-
function NodePasswordFormIDQueryRenderer(_ref) {
|
|
61
|
-
let {
|
|
62
|
-
collectionId,
|
|
63
|
-
...rest
|
|
64
|
-
} = _ref;
|
|
65
|
-
const data = useLazyLoadQuery(idQuery, {
|
|
66
|
-
collectionId
|
|
67
|
-
});
|
|
68
|
-
// this is counterintuitive, but we've added the @catch directive on the collection,
|
|
69
|
-
// and we're expecting it to respond with an error if the node is inaccessible due to being
|
|
70
|
-
// password-protected. so, when we encounter the error we're safe to render the password form.
|
|
71
|
-
// (we don't want to show the form if the user has already gained access)
|
|
72
|
-
if (data.collection.ok === false) return /*#__PURE__*/React.createElement(NodePasswordFormComponent, _extends({}, rest, {
|
|
73
|
-
collectionId: collectionId
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
const slugQuery = (_NodePasswordFormSlugQuery.hash && _NodePasswordFormSlugQuery.hash !== "c40faf067007027fa9ba6673350c7202" && console.error("The definition of 'NodePasswordFormSlugQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _NodePasswordFormSlugQuery);
|
|
77
|
-
function NodePasswordFormSlugQueryRenderer(_ref2) {
|
|
78
|
-
var _data$viewer$slug;
|
|
79
|
-
let {
|
|
80
|
-
collectionSlug,
|
|
81
|
-
...rest
|
|
82
|
-
} = _ref2;
|
|
83
|
-
const data = useLazyLoadQuery(slugQuery, {
|
|
84
|
-
collectionSlug
|
|
85
|
-
});
|
|
86
|
-
// see note in NodePasswordFormIDQueryRenderer
|
|
87
|
-
if (((_data$viewer$slug = data.viewer.slug) === null || _data$viewer$slug === void 0 ? void 0 : _data$viewer$slug.collection.ok) === false) return /*#__PURE__*/React.createElement(NodePasswordFormComponent, _extends({}, rest, {
|
|
88
|
-
collectionSlug: collectionSlug
|
|
89
|
-
}));
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// default client export
|
|
94
|
-
export default function NodePasswordForm(_ref3) {
|
|
95
|
-
let {
|
|
96
|
-
collectionId,
|
|
97
|
-
collectionSlug,
|
|
98
|
-
...rest
|
|
99
|
-
} = _ref3;
|
|
100
|
-
if (collectionId) {
|
|
101
|
-
return /*#__PURE__*/React.createElement(NodePasswordFormIDQueryRenderer, _extends({
|
|
102
|
-
collectionId: collectionId
|
|
103
|
-
}, rest));
|
|
104
|
-
}
|
|
105
|
-
if (collectionSlug) {
|
|
106
|
-
return /*#__PURE__*/React.createElement(NodePasswordFormSlugQueryRenderer, _extends({
|
|
107
|
-
collectionSlug: collectionSlug
|
|
108
|
-
}, rest));
|
|
109
|
-
}
|
|
110
|
-
throw new Error('NodePasswordForm expected either a collectionId or collectionSlug prop');
|
|
111
82
|
}
|
|
@@ -16,6 +16,7 @@ const customElementMap = {
|
|
|
16
16
|
'fontdue-cart': /*#__PURE__*/lazy(() => retryImport(() => import('../Cart/index.js'))),
|
|
17
17
|
'fontdue-cart-button': /*#__PURE__*/lazy(() => retryImport(() => import('../CartButton/index.js'))),
|
|
18
18
|
'fontdue-character-viewer': /*#__PURE__*/lazy(() => retryImport(() => import('../CharacterViewer/index.js'))),
|
|
19
|
+
'fontdue-feature-testers': /*#__PURE__*/lazy(() => retryImport(() => import('../FeatureTester/FeatureTestersElement.js'))),
|
|
19
20
|
// @ts-ignore
|
|
20
21
|
'fontdue-collection-aa': /*#__PURE__*/lazy(() => retryImport(() => import('../CollectionAa/index.js'))),
|
|
21
22
|
// @ts-ignore
|
|
@@ -23,7 +24,7 @@ const customElementMap = {
|
|
|
23
24
|
'fontdue-font-families': /*#__PURE__*/lazy(() => retryImport(() => import('../FontFamilies/index.js'))),
|
|
24
25
|
'fontdue-customer-login-form': /*#__PURE__*/lazy(() => retryImport(() => import('../CustomerLoginForm/index.js'))),
|
|
25
26
|
'fontdue-newsletter-signup': /*#__PURE__*/lazy(() => retryImport(() => import('../NewsletterSignup/NewsletterSignupElement.js'))),
|
|
26
|
-
'fontdue-node-password-form': /*#__PURE__*/lazy(() => retryImport(() => import('../NodePasswordForm/
|
|
27
|
+
'fontdue-node-password-form': /*#__PURE__*/lazy(() => retryImport(() => import('../NodePasswordForm/NodePasswordFormElement.js'))),
|
|
27
28
|
// @ts-ignore
|
|
28
29
|
'fontdue-precart': /*#__PURE__*/lazy(() => retryImport(() => import('../Precart/index.js'))),
|
|
29
30
|
// @ts-ignore
|
package/dist/fontdue.css
CHANGED
|
@@ -807,6 +807,151 @@ fontdue-type-tester {
|
|
|
807
807
|
font-weight: inherit;
|
|
808
808
|
}
|
|
809
809
|
|
|
810
|
+
fontdue-feature-tester,
|
|
811
|
+
fontdue-feature-testers {
|
|
812
|
+
display: block;
|
|
813
|
+
max-width: 100%;
|
|
814
|
+
min-width: 0;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
.fontdue-feature-tester {
|
|
818
|
+
--_ft-text: var(--fontdue-feature-tester-text, var(--primary_text_color, currentColor));
|
|
819
|
+
--_ft-muted: var(
|
|
820
|
+
--fontdue-feature-tester-muted,
|
|
821
|
+
color-mix(in srgb, var(--_ft-text) 50%, transparent)
|
|
822
|
+
);
|
|
823
|
+
--_ft-highlight: var(--fontdue-feature-tester-highlight, var(--_ft-text));
|
|
824
|
+
--_ft-bg: var(--fontdue-feature-tester-bg, transparent);
|
|
825
|
+
--_ft-border: var(
|
|
826
|
+
--fontdue-feature-tester-border,
|
|
827
|
+
1px solid var(--horizontal_rule_color, color-mix(in srgb, currentColor 15%, transparent))
|
|
828
|
+
);
|
|
829
|
+
--_ft-radius: var(--fontdue-feature-tester-radius, 0);
|
|
830
|
+
--_ft-padding: var(--fontdue-feature-tester-padding, 18px 0 30px);
|
|
831
|
+
--_ft-align: var(--fontdue-feature-tester-align, left);
|
|
832
|
+
font-size: 1rem;
|
|
833
|
+
color: var(--_ft-text);
|
|
834
|
+
background: var(--_ft-bg);
|
|
835
|
+
border-top: var(--_ft-border);
|
|
836
|
+
border-radius: var(--_ft-radius);
|
|
837
|
+
padding: var(--_ft-padding);
|
|
838
|
+
min-width: 0;
|
|
839
|
+
max-width: 100%;
|
|
840
|
+
}
|
|
841
|
+
.fontdue-feature-tester__bar {
|
|
842
|
+
display: flex;
|
|
843
|
+
align-items: center;
|
|
844
|
+
gap: 14px;
|
|
845
|
+
margin-bottom: 16px;
|
|
846
|
+
}
|
|
847
|
+
.fontdue-feature-tester__toggle {
|
|
848
|
+
background: none;
|
|
849
|
+
color: inherit;
|
|
850
|
+
font: inherit;
|
|
851
|
+
text-decoration: inherit;
|
|
852
|
+
text-align: inherit;
|
|
853
|
+
border: 0;
|
|
854
|
+
border-radius: 0;
|
|
855
|
+
padding: 0;
|
|
856
|
+
margin: 0;
|
|
857
|
+
appearance: none;
|
|
858
|
+
text-transform: inherit;
|
|
859
|
+
}
|
|
860
|
+
.fontdue-feature-tester__toggle:active, .fontdue-feature-tester__toggle:focus {
|
|
861
|
+
outline: none;
|
|
862
|
+
}
|
|
863
|
+
.fontdue-feature-tester__toggle:not(:disabled) {
|
|
864
|
+
cursor: pointer;
|
|
865
|
+
}
|
|
866
|
+
.fontdue-feature-tester__toggle {
|
|
867
|
+
display: inline-flex;
|
|
868
|
+
align-items: center;
|
|
869
|
+
flex: none;
|
|
870
|
+
color: inherit;
|
|
871
|
+
font: inherit;
|
|
872
|
+
}
|
|
873
|
+
.fontdue-feature-tester__toggle:focus-visible .fontdue-feature-tester__switch {
|
|
874
|
+
outline: 1px solid currentcolor;
|
|
875
|
+
outline-offset: 2px;
|
|
876
|
+
}
|
|
877
|
+
.fontdue-feature-tester__switch {
|
|
878
|
+
--_sw-w: var(--fontdue-feature-tester-switch-width, 40px);
|
|
879
|
+
--_sw-h: var(--fontdue-feature-tester-switch-height, 20px);
|
|
880
|
+
--_sw-r: var(--fontdue-feature-tester-switch-radius, 0);
|
|
881
|
+
--_sw-p: var(--fontdue-feature-tester-switch-padding, 2px);
|
|
882
|
+
--_sw-b: var(--fontdue-feature-tester-switch-border-width, 1px);
|
|
883
|
+
--_sw-color: var(--fontdue-feature-tester-switch-color, currentColor);
|
|
884
|
+
--_sw-knob: var(--fontdue-feature-tester-switch-knob, var(--primary_background_color, canvas));
|
|
885
|
+
--_sw-track: var(--fontdue-feature-tester-switch-track, transparent);
|
|
886
|
+
--_sw-travel: calc(var(--_sw-w) - var(--_sw-h));
|
|
887
|
+
position: relative;
|
|
888
|
+
box-sizing: border-box;
|
|
889
|
+
width: var(--_sw-w);
|
|
890
|
+
height: var(--_sw-h);
|
|
891
|
+
flex: none;
|
|
892
|
+
border: var(--_sw-b) solid var(--_sw-color);
|
|
893
|
+
border-radius: var(--_sw-r);
|
|
894
|
+
background: var(--_sw-track);
|
|
895
|
+
transition: background 120ms ease-out;
|
|
896
|
+
}
|
|
897
|
+
.fontdue-feature-tester__switch::after {
|
|
898
|
+
content: "";
|
|
899
|
+
position: absolute;
|
|
900
|
+
box-sizing: border-box;
|
|
901
|
+
top: var(--_sw-p);
|
|
902
|
+
left: var(--_sw-p);
|
|
903
|
+
bottom: var(--_sw-p);
|
|
904
|
+
aspect-ratio: 1;
|
|
905
|
+
border: var(--_sw-b) solid var(--_sw-color);
|
|
906
|
+
border-radius: var(--_sw-r);
|
|
907
|
+
background: transparent;
|
|
908
|
+
transition: transform 120ms ease-out, background 120ms ease-out;
|
|
909
|
+
}
|
|
910
|
+
@media (hover: hover) {
|
|
911
|
+
.fontdue-feature-tester[data-on=false] .fontdue-feature-tester__toggle:hover .fontdue-feature-tester__switch::after {
|
|
912
|
+
background: var(--_sw-color);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
.fontdue-feature-tester__label {
|
|
916
|
+
white-space: nowrap;
|
|
917
|
+
}
|
|
918
|
+
.fontdue-feature-tester[data-toggle=button] .fontdue-feature-tester__label {
|
|
919
|
+
cursor: pointer;
|
|
920
|
+
}
|
|
921
|
+
.fontdue-feature-tester__tag {
|
|
922
|
+
margin-left: auto;
|
|
923
|
+
color: inherit;
|
|
924
|
+
}
|
|
925
|
+
.fontdue-feature-tester[data-on=true] .fontdue-feature-tester__switch {
|
|
926
|
+
background: var(--_sw-color);
|
|
927
|
+
}
|
|
928
|
+
.fontdue-feature-tester[data-on=true] .fontdue-feature-tester__switch::after {
|
|
929
|
+
transform: translateX(var(--_sw-travel));
|
|
930
|
+
border-color: transparent;
|
|
931
|
+
background: var(--_sw-knob);
|
|
932
|
+
}
|
|
933
|
+
.fontdue-feature-tester[data-toggle=hover] .fontdue-feature-tester__switch,
|
|
934
|
+
.fontdue-feature-tester[data-toggle=hover] .fontdue-feature-tester__toggle {
|
|
935
|
+
display: none;
|
|
936
|
+
}
|
|
937
|
+
@media (hover: none) {
|
|
938
|
+
.fontdue-feature-tester[data-toggle=hover] .fontdue-feature-tester__switch,
|
|
939
|
+
.fontdue-feature-tester[data-toggle=hover] .fontdue-feature-tester__toggle {
|
|
940
|
+
display: inline-flex;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
.fontdue-feature-tester__sample {
|
|
944
|
+
white-space: pre-wrap;
|
|
945
|
+
text-align: var(--_ft-align);
|
|
946
|
+
color: var(--_ft-text);
|
|
947
|
+
}
|
|
948
|
+
.fontdue-feature-tester[data-highlighted=true] .fontdue-feature-tester__sample {
|
|
949
|
+
color: var(--_ft-muted);
|
|
950
|
+
}
|
|
951
|
+
.fontdue-feature-tester__hit {
|
|
952
|
+
color: var(--_ft-highlight);
|
|
953
|
+
}
|
|
954
|
+
|
|
810
955
|
.select-button {
|
|
811
956
|
background: none;
|
|
812
957
|
color: inherit;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface UseFeatureTesterAutofitProps {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
text: string;
|
|
4
|
+
fontFamily: string | null;
|
|
5
|
+
feature: string;
|
|
6
|
+
fontSize: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
letterSpacing?: number;
|
|
10
|
+
fontVariationSettings?: string;
|
|
11
|
+
padding?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface UseFeatureTesterAutofitResult {
|
|
14
|
+
ref: React.RefObject<HTMLDivElement | null>;
|
|
15
|
+
fontSize: number;
|
|
16
|
+
}
|
|
17
|
+
export default function useFeatureTesterAutofit({ enabled, text, fontFamily, feature, fontSize, min, max, letterSpacing, fontVariationSettings, padding, }: UseFeatureTesterAutofitProps): UseFeatureTesterAutofitResult;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useRef, useState, useLayoutEffect } from 'react';
|
|
2
|
+
import useResizeObserver from './useResizeObserver.js';
|
|
3
|
+
|
|
4
|
+
// Autofit for the Feature Tester. Unlike the plain type-tester autofit, the
|
|
5
|
+
// rendered width depends on the toggle state — an alternate glyph is wider or
|
|
6
|
+
// narrower, a ligature collapses, a fraction shrinks. So we measure the sample
|
|
7
|
+
// in BOTH states (feature off and on) and size to fit the WIDER one. The size
|
|
8
|
+
// is then fixed across toggles, so the tester never reflows or overflows when
|
|
9
|
+
// the feature is switched.
|
|
10
|
+
//
|
|
11
|
+
// Measurement must use the DOM (not canvas): canvas `measureText` can't apply
|
|
12
|
+
// `font-feature-settings`, which is exactly the thing that changes the width.
|
|
13
|
+
// Measuring the whole string with the feature applied is exact here, not an
|
|
14
|
+
// over-estimate: a character the feature doesn't touch renders identically
|
|
15
|
+
// whether the feature is on or off, so the two measurements are precisely the
|
|
16
|
+
// tester's two real states.
|
|
17
|
+
|
|
18
|
+
const REF_SIZE = 100;
|
|
19
|
+
let measureEl = null;
|
|
20
|
+
function getMeasureElement() {
|
|
21
|
+
if (!measureEl) {
|
|
22
|
+
measureEl = document.createElement('span');
|
|
23
|
+
measureEl.style.position = 'absolute';
|
|
24
|
+
measureEl.style.top = '-9999px';
|
|
25
|
+
measureEl.style.left = '-9999px';
|
|
26
|
+
measureEl.style.whiteSpace = 'pre';
|
|
27
|
+
measureEl.style.visibility = 'hidden';
|
|
28
|
+
document.body.appendChild(measureEl);
|
|
29
|
+
}
|
|
30
|
+
return measureEl;
|
|
31
|
+
}
|
|
32
|
+
function measure(text, fontFamily, letterSpacing, fontFeatureSettings, fontVariationSettings) {
|
|
33
|
+
const el = getMeasureElement();
|
|
34
|
+
el.style.fontFamily = fontFamily;
|
|
35
|
+
el.style.fontSize = `${REF_SIZE}px`;
|
|
36
|
+
el.style.letterSpacing = `${letterSpacing}em`;
|
|
37
|
+
el.style.fontFeatureSettings = fontFeatureSettings;
|
|
38
|
+
el.style.fontVariationSettings = fontVariationSettings;
|
|
39
|
+
el.textContent = text;
|
|
40
|
+
return el.getBoundingClientRect().width;
|
|
41
|
+
}
|
|
42
|
+
export default function useFeatureTesterAutofit(_ref) {
|
|
43
|
+
let {
|
|
44
|
+
enabled,
|
|
45
|
+
text,
|
|
46
|
+
fontFamily,
|
|
47
|
+
feature,
|
|
48
|
+
fontSize,
|
|
49
|
+
min = 8,
|
|
50
|
+
max = 999,
|
|
51
|
+
letterSpacing = 0,
|
|
52
|
+
fontVariationSettings = '',
|
|
53
|
+
padding = 0
|
|
54
|
+
} = _ref;
|
|
55
|
+
const ref = useRef(null);
|
|
56
|
+
const [size, setSize] = useState(fontSize);
|
|
57
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
58
|
+
const [fontVersion, setFontVersion] = useState(0);
|
|
59
|
+
useResizeObserver(ref, entry => setContainerWidth(entry.contentRect.width));
|
|
60
|
+
|
|
61
|
+
// Re-measure once the webfont is available (measuring the fallback would size
|
|
62
|
+
// to the wrong metrics). The font is often already cached — other cards on the
|
|
63
|
+
// page load the same family — so `document.fonts.load` can resolve in a
|
|
64
|
+
// microtask *before* a freshly-measured element reflects the loaded font in
|
|
65
|
+
// layout. Re-measuring on the next animation frame, when layout is font-ready,
|
|
66
|
+
// avoids sizing to a stale fallback measurement that then never gets corrected.
|
|
67
|
+
// Re-measure until the sizing lands on the real webfont metrics. A fresh DOM
|
|
68
|
+
// measurement can lag the font becoming available — the family is often
|
|
69
|
+
// already cached (other cards on the page load it), so `fonts.load`/
|
|
70
|
+
// `fonts.ready` can settle a frame or two before a measured element actually
|
|
71
|
+
// reflects it. Sizing to that stale fallback measurement would then stick.
|
|
72
|
+
// Re-measuring across a short schedule lets the size settle onto the real
|
|
73
|
+
// metrics whenever they land; the extra `fonts.ready` bump covers slow loads
|
|
74
|
+
// beyond the schedule.
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
if (!enabled || !fontFamily) return;
|
|
77
|
+
let cancelled = false;
|
|
78
|
+
const bump = () => {
|
|
79
|
+
if (!cancelled) setFontVersion(v => v + 1);
|
|
80
|
+
};
|
|
81
|
+
const timers = [0, 80, 200, 500, 1000].map(ms => window.setTimeout(bump, ms));
|
|
82
|
+
document.fonts.ready.then(bump);
|
|
83
|
+
return () => {
|
|
84
|
+
cancelled = true;
|
|
85
|
+
timers.forEach(clearTimeout);
|
|
86
|
+
};
|
|
87
|
+
}, [enabled, fontFamily]);
|
|
88
|
+
useLayoutEffect(() => {
|
|
89
|
+
if (!enabled || !fontFamily) return;
|
|
90
|
+
const available = containerWidth - padding;
|
|
91
|
+
if (available <= 0 || !text) return;
|
|
92
|
+
const off = `"${feature}" 0`;
|
|
93
|
+
const on = `"${feature}" 1`;
|
|
94
|
+
// Widest line across both states — samples can carry authored newlines.
|
|
95
|
+
const refWidth = Math.max(...text.split('\n').flatMap(line => [measure(line, fontFamily, letterSpacing, off, fontVariationSettings), measure(line, fontFamily, letterSpacing, on, fontVariationSettings)]));
|
|
96
|
+
if (refWidth <= 0) return;
|
|
97
|
+
|
|
98
|
+
// Width scales linearly with font-size; floor to avoid a sub-pixel wrap.
|
|
99
|
+
const next = Math.min(Math.max(min, Math.floor(available / (refWidth / REF_SIZE))), max);
|
|
100
|
+
setSize(next);
|
|
101
|
+
}, [enabled, text, fontFamily, feature, letterSpacing, fontVariationSettings, containerWidth, min, max, padding, fontVersion]);
|
|
102
|
+
return {
|
|
103
|
+
ref,
|
|
104
|
+
fontSize: enabled ? size : fontSize
|
|
105
|
+
};
|
|
106
|
+
}
|
package/dist/next/index.d.ts
CHANGED
package/dist/next/index.js
CHANGED
|
@@ -15,4 +15,19 @@
|
|
|
15
15
|
// configureFontdueRender, setFontdueServerConfig) are deliberately not
|
|
16
16
|
// re-exported here; the modules that need them import them directly from
|
|
17
17
|
// './tenant.js' / '../relay/serverConfig.js'.
|
|
18
|
-
export { __prepareFontdueRender } from './tenant.js';
|
|
18
|
+
export { __prepareFontdueRender } from './tenant.js';
|
|
19
|
+
import { registerNodeAccessRecovery } from '../relay/serverConfig.js';
|
|
20
|
+
import { nodeAccessHeaders } from './tenant.js';
|
|
21
|
+
|
|
22
|
+
// Wire up automatic node-access recovery: when a server fetch comes back
|
|
23
|
+
// `password_protected`, createFontdueFetch calls this to read the visitor's
|
|
24
|
+
// node-access cookie and (if they've unlocked the collection) fold the token
|
|
25
|
+
// into the per-render config + retry — so the page fetch and the embedded server
|
|
26
|
+
// components' preloads resolve, with no per-fetch plumbing in the app. Importing
|
|
27
|
+
// this entry (the next-template does, via __prepareFontdueRender) registers it.
|
|
28
|
+
registerNodeAccessRecovery(() => nodeAccessHeaders());
|
|
29
|
+
|
|
30
|
+
// Escape hatch (rarely needed now recovery is automatic): the visitor's
|
|
31
|
+
// per-collection node-access header for this request, or {} when none. See the
|
|
32
|
+
// password-protected-collections guide.
|
|
33
|
+
export { nodeAccessHeaders };
|
|
@@ -15,7 +15,19 @@
|
|
|
15
15
|
// stays safe for any non-Next RSC consumer. (Today only Next resolves the
|
|
16
16
|
// react-server export condition, but the decoupling makes that a structural
|
|
17
17
|
// invariant rather than an incidental one.)
|
|
18
|
-
import { registerAmbientConfigResolver } from '../relay/serverConfig.js';
|
|
18
|
+
import { registerAmbientConfigResolver, registerNodeAccessRecovery } from '../relay/serverConfig.js';
|
|
19
|
+
|
|
20
|
+
// Automatic node-access recovery for single-tenant Next apps (the same hook the
|
|
21
|
+
// multi-tenant entry registers). createFontdueFetch calls this when a fetch
|
|
22
|
+
// comes back `password_protected`; it reads the visitor's node-access cookie via
|
|
23
|
+
// Next's request APIs. Lazy-imported, for the same reason as the resolver below:
|
|
24
|
+
// keep next/headers off this module's static graph.
|
|
25
|
+
registerNodeAccessRecovery(async () => {
|
|
26
|
+
const {
|
|
27
|
+
nodeAccessHeaders
|
|
28
|
+
} = await import('./tenant.js');
|
|
29
|
+
return nodeAccessHeaders();
|
|
30
|
+
});
|
|
19
31
|
registerAmbientConfigResolver(async () => {
|
|
20
32
|
// Loaded lazily so next/headers + next/navigation never enter the
|
|
21
33
|
// provider's static graph; config is read per fetch from Next's request
|
package/dist/next/tenant.d.ts
CHANGED
|
@@ -23,4 +23,5 @@ interface RenderProps {
|
|
|
23
23
|
}
|
|
24
24
|
export declare function buildRenderConfig(domain: string): Promise<FontdueServerConfig>;
|
|
25
25
|
export declare function __prepareFontdueRender(props: RenderProps): Promise<FontdueEndpoint>;
|
|
26
|
+
export declare function nodeAccessHeaders(): Promise<Record<string, string>>;
|
|
26
27
|
export {};
|