@bison-lab/payload-core 4.32.2 → 4.35.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/README.md +65 -3
- package/dist/block-library.d.mts +1 -1
- package/dist/block-library.mjs +1 -1
- package/dist/{block-thumbnails--AJzSdzJ.mjs → block-thumbnails-VRxpSXw1.mjs} +1 -1
- package/dist/{block-thumbnails--AJzSdzJ.mjs.map → block-thumbnails-VRxpSXw1.mjs.map} +1 -1
- package/dist/block-thumbnails-cli.mjs +1 -1
- package/dist/block-thumbnails.mjs +1 -1
- package/dist/{catalogue-BC_A9eLc.d.mts → catalogue-CEfYwTSK.d.mts} +1 -1
- package/dist/{catalogue-BC_A9eLc.d.mts.map → catalogue-CEfYwTSK.d.mts.map} +1 -1
- package/dist/{facet-field-DKzRCYrh.d.mts → facet-field-BvQp8Hzh.d.mts} +1 -1
- package/dist/{facet-field-DKzRCYrh.d.mts.map → facet-field-BvQp8Hzh.d.mts.map} +1 -1
- package/dist/{facet-field-Di1kNyzH.mjs → facet-field-Uf8S4yL1.mjs} +1 -1
- package/dist/{facet-field-Di1kNyzH.mjs.map → facet-field-Uf8S4yL1.mjs.map} +1 -1
- package/dist/identity-CN6EOeDM.mjs +180 -0
- package/dist/identity-CN6EOeDM.mjs.map +1 -0
- package/dist/index.d.mts +41 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +145 -36
- package/dist/index.mjs.map +1 -1
- package/dist/metadata.d.mts +14 -2
- package/dist/metadata.d.mts.map +1 -1
- package/dist/metadata.mjs +29 -3
- package/dist/metadata.mjs.map +1 -1
- package/dist/navigation.d.mts +1 -1
- package/dist/navigation.mjs +1 -1
- package/dist/og.d.mts +155 -0
- package/dist/og.d.mts.map +1 -0
- package/dist/og.mjs +282 -0
- package/dist/og.mjs.map +1 -0
- package/dist/{identity-8doWYeRn.mjs → preview-Br1SQCKn.mjs} +4 -179
- package/dist/preview-Br1SQCKn.mjs.map +1 -0
- package/dist/preview-Cgbh9eAq.d.mts +113 -0
- package/dist/preview-Cgbh9eAq.d.mts.map +1 -0
- package/dist/published-BLXCep6Z.d.mts +26 -0
- package/dist/published-BLXCep6Z.d.mts.map +1 -0
- package/dist/{published-CcW9bqLJ.mjs → published-CEuK5ym6.mjs} +1 -1
- package/dist/{published-CcW9bqLJ.mjs.map → published-CEuK5ym6.mjs.map} +1 -1
- package/dist/published-DgAzpDSG.mjs +31 -0
- package/dist/published-DgAzpDSG.mjs.map +1 -0
- package/dist/{published-IX1-6JEa.d.mts → published-Dsg-HX-v.d.mts} +1 -1
- package/dist/{published-IX1-6JEa.d.mts.map → published-Dsg-HX-v.d.mts.map} +1 -1
- package/dist/{published-niJkPGjE.mjs → published-QyTcDznE.mjs} +1 -1
- package/dist/{published-niJkPGjE.mjs.map → published-QyTcDznE.mjs.map} +1 -1
- package/dist/root-page-key-B86JwL8Z.mjs +32 -0
- package/dist/root-page-key-B86JwL8Z.mjs.map +1 -0
- package/dist/seo.d.mts +216 -0
- package/dist/seo.d.mts.map +1 -0
- package/dist/seo.mjs +155 -0
- package/dist/seo.mjs.map +1 -0
- package/dist/share-image-C8ZtIcU8.mjs +19 -0
- package/dist/share-image-C8ZtIcU8.mjs.map +1 -0
- package/dist/taxonomy.d.mts +1 -1
- package/dist/taxonomy.mjs +1 -1
- package/dist/theme.d.mts +3 -22
- package/dist/theme.d.mts.map +1 -1
- package/dist/theme.mjs +3 -28
- package/dist/theme.mjs.map +1 -1
- package/dist/{title-BvjHeRo5.d.mts → title-C8ppEDlc.d.mts} +1 -1
- package/dist/{title-BvjHeRo5.d.mts.map → title-C8ppEDlc.d.mts.map} +1 -1
- package/dist/title-DJ7C48gq.mjs +21 -0
- package/dist/title-DJ7C48gq.mjs.map +1 -0
- package/dist/{preview-D-G8PEEB.d.mts → types-D6jQql5Z.d.mts} +3 -110
- package/dist/types-D6jQql5Z.d.mts.map +1 -0
- package/dist/wireframe-cli.mjs +1 -1
- package/dist/{wireframe-ApjwNWAN.mjs → wireframe-sJW8Q4NS.mjs} +1 -1
- package/dist/{wireframe-ApjwNWAN.mjs.map → wireframe-sJW8Q4NS.mjs.map} +1 -1
- package/dist/wireframe.mjs +1 -1
- package/package.json +23 -5
- package/dist/identity-8doWYeRn.mjs.map +0 -1
- package/dist/preview-D-G8PEEB.d.mts.map +0 -1
- package/dist/share-image-C4ILz4p2.mjs +0 -37
- package/dist/share-image-C4ILz4p2.mjs.map +0 -1
package/dist/metadata.d.mts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { a as SeoImageSize, i as SeoImageDoc, n as titleTemplate, o as SeoImageValue, r as MediaId, s as SeoMeta, t as documentTitle } from "./title-
|
|
1
|
+
import { a as SeoImageSize, i as SeoImageDoc, n as titleTemplate, o as SeoImageValue, r as MediaId, s as SeoMeta, t as documentTitle } from "./title-C8ppEDlc.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/seo/metadata.d.ts
|
|
4
4
|
/** A page as the reader needs it; a site's generated `Page` is assignable. */
|
|
5
5
|
interface SeoPage {
|
|
6
6
|
title: string;
|
|
7
7
|
meta?: SeoMeta | null;
|
|
8
|
+
/** Read only to fill `{slug}` in `ogImageRoute`. */
|
|
9
|
+
slug?: string | null;
|
|
10
|
+
/** Read only to fill `{id}` in `ogImageRoute`. */
|
|
11
|
+
id?: string | number | null;
|
|
8
12
|
}
|
|
9
13
|
interface PageMetadataOptions {
|
|
10
14
|
/** The suffix a page without a written meta title gets. */
|
|
@@ -15,6 +19,13 @@ interface PageMetadataOptions {
|
|
|
15
19
|
absoluteUrl: (path: string) => string;
|
|
16
20
|
/** The rendition to read off the meta image. Default `SHARE_IMAGE_SIZE.name`. */
|
|
17
21
|
shareSize?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Where the site mounts `ogImageHandler` from `@bison-lab/payload-core/og`,
|
|
24
|
+
* as a path pattern with `{slug}` or `{id}`: `"/og/{slug}"`. A page with
|
|
25
|
+
* no share image points `og:image` at it (BIS-183); an uploaded share
|
|
26
|
+
* image always wins. Omit it and a page without one has no image, as before.
|
|
27
|
+
*/
|
|
28
|
+
ogImageRoute?: string;
|
|
18
29
|
}
|
|
19
30
|
interface PageMetadataImage {
|
|
20
31
|
url: string;
|
|
@@ -58,7 +69,8 @@ interface PageMetadata {
|
|
|
58
69
|
/**
|
|
59
70
|
* Next metadata for a page with the SEO tab: `<title>`, description,
|
|
60
71
|
* canonical, Open Graph and Twitter with the share image, and
|
|
61
|
-
* `noindex, nofollow` when the page is hidden.
|
|
72
|
+
* `noindex, nofollow` when the page is hidden. With `ogImageRoute`, a page
|
|
73
|
+
* whose SEO tab has no share image gets the generated card instead. Fields the editor left empty
|
|
62
74
|
* are left out, so the layout's defaults (a site-wide description, a default
|
|
63
75
|
* share image) carry through Next's merge. The canonical is always this
|
|
64
76
|
* site's origin; a page that must canonicalise elsewhere is a redirect, not
|
package/dist/metadata.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.mts","names":[],"sources":["../src/seo/metadata.ts"],"mappings":";;;;UAKiB,OAAA;EACf,KAAA;EACA,IAAA,GAAO,OAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"metadata.d.mts","names":[],"sources":["../src/seo/metadata.ts"],"mappings":";;;;UAKiB,OAAA;EACf,KAAA;EACA,IAAA,GAAO,OAAA;;EAEP,IAAA;EAHA;EAKA,EAAA;AAAA;AAAA,UAGe,mBAAA;EAHf;EAKA,QAAA;EALE;EAOF,SAAA;EAJkC;EAMlC,WAAA,GAAc,IAAA;EANoB;EAQlC,SAAA;EAJA;;;;;;EAWA,YAAA;AAAA;AAAA,UAGe,iBAAA;EACf,GAAA;EACA,KAAA;EACA,MAAA;EACA,GAAA;AAAA;;;;AAWF;;;;;UAAiB,YAAA;EACf,KAAA;IAAkB,QAAA;EAAA;EAClB,WAAA;EACA,UAAA;IAAc,SAAA;EAAA;EACd,SAAA;IACE,KAAA;IACA,WAAA;IACA,GAAA;IACA,MAAA,GAAS,iBAAA;EAAA;EAEX,OAAA;IACE,IAAA;IACA,KAAA;IACA,WAAA;IACA,MAAA,GAAS,iBAAA;EAAA;EAEX,MAAA;IAAW,KAAA;IAAc,MAAA;EAAA;AAAA;;;;;;;;;;;iBAwDX,YAAA,CACd,IAAA,EAAM,OAAA,EACN,OAAA,EAAS,mBAAA,GACR,YAAA"}
|
package/dist/metadata.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as titleTemplate, t as documentTitle } from "./title-DJ7C48gq.mjs";
|
|
2
|
+
import { t as SHARE_IMAGE_SIZE } from "./share-image-C8ZtIcU8.mjs";
|
|
2
3
|
//#region src/seo/metadata.ts
|
|
3
4
|
/**
|
|
4
5
|
* The share image as a crawler wants it, or `undefined` when the page has
|
|
@@ -19,9 +20,34 @@ function shareImage(image, { absoluteUrl, shareSize = SHARE_IMAGE_SIZE.name }) {
|
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
23
|
+
* The generated card for a page, from `ogImageRoute`, or `undefined` when
|
|
24
|
+
* the pattern names a value the page does not carry.
|
|
25
|
+
*/
|
|
26
|
+
function generatedImage(page, options, alt) {
|
|
27
|
+
const route = options.ogImageRoute;
|
|
28
|
+
if (!route) return void 0;
|
|
29
|
+
let missing = false;
|
|
30
|
+
const path = route.replace(/\{(slug|id)\}/g, (_, key) => {
|
|
31
|
+
const value = page[key];
|
|
32
|
+
if (value === void 0 || value === null || value === "") {
|
|
33
|
+
missing = true;
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
return String(value).split("/").map(encodeURIComponent).join("/");
|
|
37
|
+
});
|
|
38
|
+
if (missing) return void 0;
|
|
39
|
+
return {
|
|
40
|
+
url: options.absoluteUrl(path),
|
|
41
|
+
width: SHARE_IMAGE_SIZE.width,
|
|
42
|
+
height: SHARE_IMAGE_SIZE.height,
|
|
43
|
+
alt
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
22
47
|
* Next metadata for a page with the SEO tab: `<title>`, description,
|
|
23
48
|
* canonical, Open Graph and Twitter with the share image, and
|
|
24
|
-
* `noindex, nofollow` when the page is hidden.
|
|
49
|
+
* `noindex, nofollow` when the page is hidden. With `ogImageRoute`, a page
|
|
50
|
+
* whose SEO tab has no share image gets the generated card instead. Fields the editor left empty
|
|
25
51
|
* are left out, so the layout's defaults (a site-wide description, a default
|
|
26
52
|
* share image) carry through Next's merge. The canonical is always this
|
|
27
53
|
* site's origin; a page that must canonicalise elsewhere is a redirect, not
|
|
@@ -31,7 +57,7 @@ function pageMetadata(page, options) {
|
|
|
31
57
|
const meta = page.meta ?? {};
|
|
32
58
|
const title = meta.title || documentTitle(options.siteName, page.title);
|
|
33
59
|
const description = meta.description ? { description: meta.description } : {};
|
|
34
|
-
const image = shareImage(meta.image, options);
|
|
60
|
+
const image = shareImage(meta.image, options) ?? generatedImage(page, options, page.title);
|
|
35
61
|
const images = image ? { images: [image] } : {};
|
|
36
62
|
return {
|
|
37
63
|
title: meta.title ? { absolute: meta.title } : page.title,
|
package/dist/metadata.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.mjs","names":[],"sources":["../src/seo/metadata.ts"],"sourcesContent":["import { SHARE_IMAGE_SIZE } from \"./share-image\";\nimport { documentTitle } from \"./title\";\nimport type { SeoImageValue, SeoMeta } from \"./types\";\n\n/** A page as the reader needs it; a site's generated `Page` is assignable. */\nexport interface SeoPage {\n title: string;\n meta?: SeoMeta | null;\n}\n\nexport interface PageMetadataOptions {\n /** The suffix a page without a written meta title gets. */\n siteName: string;\n /** This page's absolute URL at the site's own origin. */\n canonical: string;\n /** Turns a media file path into an absolute URL; crawlers take no other kind. */\n absoluteUrl: (path: string) => string;\n /** The rendition to read off the meta image. Default `SHARE_IMAGE_SIZE.name`. */\n shareSize?: string;\n}\n\nexport interface PageMetadataImage {\n url: string;\n width?: number;\n height?: number;\n alt?: string;\n}\n\n/**\n * The shape `pageMetadata` returns, assignable to Next's `Metadata` without\n * this package depending on `next`. A written meta title is `absolute` so\n * the layout's title template does not append the site name a second time;\n * an unwritten one is the bare page title, which the template completes.\n * Optional keys are absent rather than `undefined`: Next's merge lets an\n * `undefined` key override the layout's value instead of inheriting it.\n */\nexport interface PageMetadata {\n title: string | { absolute: string };\n description?: string;\n alternates: { canonical: string };\n openGraph: {\n title: string;\n description?: string;\n url: string;\n images?: PageMetadataImage[];\n };\n twitter: {\n card: \"summary_large_image\";\n title: string;\n description?: string;\n images?: PageMetadataImage[];\n };\n robots?: { index: false; follow: false };\n}\n\n/**\n * The share image as a crawler wants it, or `undefined` when the page has\n * none or the relation came back unpopulated (`depth: 0` upstream). The\n * named rendition is preferred; a file uploaded before that size existed, or\n * too small to cut, has only its original, which is used as is.\n */\nfunction shareImage(\n image: SeoImageValue,\n { absoluteUrl, shareSize = SHARE_IMAGE_SIZE.name }: PageMetadataOptions,\n): PageMetadataImage | undefined {\n if (!image || typeof image !== \"object\") return undefined;\n const rendition = image.sizes?.[shareSize];\n const file = rendition?.url ? rendition : image;\n if (!file.url) return undefined;\n return {\n url: absoluteUrl(file.url),\n ...(file.width ? { width: file.width } : {}),\n ...(file.height ? { height: file.height } : {}),\n ...(image.alt ? { alt: image.alt } : {}),\n };\n}\n\n/**\n * Next metadata for a page with the SEO tab: `<title>`, description,\n * canonical, Open Graph and Twitter with the share image, and\n * `noindex, nofollow` when the page is hidden. Fields the editor left empty\n * are left out, so the layout's defaults (a site-wide description, a default\n * share image) carry through Next's merge. The canonical is always this\n * site's origin; a page that must canonicalise elsewhere is a redirect, not\n * a field.\n */\nexport function pageMetadata(\n page: SeoPage,\n options: PageMetadataOptions,\n): PageMetadata {\n const meta = page.meta ?? {};\n const title = meta.title || documentTitle(options.siteName, page.title);\n const description = meta.description ? { description: meta.description } : {};\n const image = shareImage(meta.image, options);\n const images = image ? { images: [image] } : {};\n\n return {\n title: meta.title ? { absolute: meta.title } : page.title,\n ...description,\n alternates: { canonical: options.canonical },\n openGraph: { title, ...description, url: options.canonical, ...images },\n twitter: { card: \"summary_large_image\", title, ...description, ...images },\n // Both off: a page hidden from search should not lend its links weight either.\n ...(meta.noIndex ? { robots: { index: false, follow: false } } : {}),\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"metadata.mjs","names":[],"sources":["../src/seo/metadata.ts"],"sourcesContent":["import { SHARE_IMAGE_SIZE } from \"./share-image\";\nimport { documentTitle } from \"./title\";\nimport type { SeoImageValue, SeoMeta } from \"./types\";\n\n/** A page as the reader needs it; a site's generated `Page` is assignable. */\nexport interface SeoPage {\n title: string;\n meta?: SeoMeta | null;\n /** Read only to fill `{slug}` in `ogImageRoute`. */\n slug?: string | null;\n /** Read only to fill `{id}` in `ogImageRoute`. */\n id?: string | number | null;\n}\n\nexport interface PageMetadataOptions {\n /** The suffix a page without a written meta title gets. */\n siteName: string;\n /** This page's absolute URL at the site's own origin. */\n canonical: string;\n /** Turns a media file path into an absolute URL; crawlers take no other kind. */\n absoluteUrl: (path: string) => string;\n /** The rendition to read off the meta image. Default `SHARE_IMAGE_SIZE.name`. */\n shareSize?: string;\n /**\n * Where the site mounts `ogImageHandler` from `@bison-lab/payload-core/og`,\n * as a path pattern with `{slug}` or `{id}`: `\"/og/{slug}\"`. A page with\n * no share image points `og:image` at it (BIS-183); an uploaded share\n * image always wins. Omit it and a page without one has no image, as before.\n */\n ogImageRoute?: string;\n}\n\nexport interface PageMetadataImage {\n url: string;\n width?: number;\n height?: number;\n alt?: string;\n}\n\n/**\n * The shape `pageMetadata` returns, assignable to Next's `Metadata` without\n * this package depending on `next`. A written meta title is `absolute` so\n * the layout's title template does not append the site name a second time;\n * an unwritten one is the bare page title, which the template completes.\n * Optional keys are absent rather than `undefined`: Next's merge lets an\n * `undefined` key override the layout's value instead of inheriting it.\n */\nexport interface PageMetadata {\n title: string | { absolute: string };\n description?: string;\n alternates: { canonical: string };\n openGraph: {\n title: string;\n description?: string;\n url: string;\n images?: PageMetadataImage[];\n };\n twitter: {\n card: \"summary_large_image\";\n title: string;\n description?: string;\n images?: PageMetadataImage[];\n };\n robots?: { index: false; follow: false };\n}\n\n/**\n * The share image as a crawler wants it, or `undefined` when the page has\n * none or the relation came back unpopulated (`depth: 0` upstream). The\n * named rendition is preferred; a file uploaded before that size existed, or\n * too small to cut, has only its original, which is used as is.\n */\nfunction shareImage(\n image: SeoImageValue,\n { absoluteUrl, shareSize = SHARE_IMAGE_SIZE.name }: PageMetadataOptions,\n): PageMetadataImage | undefined {\n if (!image || typeof image !== \"object\") return undefined;\n const rendition = image.sizes?.[shareSize];\n const file = rendition?.url ? rendition : image;\n if (!file.url) return undefined;\n return {\n url: absoluteUrl(file.url),\n ...(file.width ? { width: file.width } : {}),\n ...(file.height ? { height: file.height } : {}),\n ...(image.alt ? { alt: image.alt } : {}),\n };\n}\n\n/**\n * The generated card for a page, from `ogImageRoute`, or `undefined` when\n * the pattern names a value the page does not carry.\n */\nfunction generatedImage(page: SeoPage, options: PageMetadataOptions, alt: string): PageMetadataImage | undefined {\n const route = options.ogImageRoute;\n if (!route) return undefined;\n let missing = false;\n const path = route.replace(/\\{(slug|id)\\}/g, (_, key: \"slug\" | \"id\") => {\n const value = page[key];\n if (value === undefined || value === null || value === \"\") {\n missing = true;\n return \"\";\n }\n // A nested slug keeps its slashes: each segment is encoded on its own.\n return String(value).split(\"/\").map(encodeURIComponent).join(\"/\");\n });\n if (missing) return undefined;\n return { url: options.absoluteUrl(path), width: SHARE_IMAGE_SIZE.width, height: SHARE_IMAGE_SIZE.height, alt };\n}\n\n/**\n * Next metadata for a page with the SEO tab: `<title>`, description,\n * canonical, Open Graph and Twitter with the share image, and\n * `noindex, nofollow` when the page is hidden. With `ogImageRoute`, a page\n * whose SEO tab has no share image gets the generated card instead. Fields the editor left empty\n * are left out, so the layout's defaults (a site-wide description, a default\n * share image) carry through Next's merge. The canonical is always this\n * site's origin; a page that must canonicalise elsewhere is a redirect, not\n * a field.\n */\nexport function pageMetadata(\n page: SeoPage,\n options: PageMetadataOptions,\n): PageMetadata {\n const meta = page.meta ?? {};\n const title = meta.title || documentTitle(options.siteName, page.title);\n const description = meta.description ? { description: meta.description } : {};\n const image = shareImage(meta.image, options) ?? generatedImage(page, options, page.title);\n const images = image ? { images: [image] } : {};\n\n return {\n title: meta.title ? { absolute: meta.title } : page.title,\n ...description,\n alternates: { canonical: options.canonical },\n openGraph: { title, ...description, url: options.canonical, ...images },\n twitter: { card: \"summary_large_image\", title, ...description, ...images },\n // Both off: a page hidden from search should not lend its links weight either.\n ...(meta.noIndex ? { robots: { index: false, follow: false } } : {}),\n };\n}\n"],"mappings":";;;;;;;;;AAwEA,SAAS,WACP,OACA,EAAE,aAAa,YAAY,iBAAiB,QACb;AAC/B,KAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO,KAAA;CAChD,MAAM,YAAY,MAAM,QAAQ;CAChC,MAAM,OAAO,WAAW,MAAM,YAAY;AAC1C,KAAI,CAAC,KAAK,IAAK,QAAO,KAAA;AACtB,QAAO;EACL,KAAK,YAAY,KAAK,IAAI;EAC1B,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,OAAO,GAAG,EAAE;EAC3C,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,QAAQ,GAAG,EAAE;EAC9C,GAAI,MAAM,MAAM,EAAE,KAAK,MAAM,KAAK,GAAG,EAAE;EACxC;;;;;;AAOH,SAAS,eAAe,MAAe,SAA8B,KAA4C;CAC/G,MAAM,QAAQ,QAAQ;AACtB,KAAI,CAAC,MAAO,QAAO,KAAA;CACnB,IAAI,UAAU;CACd,MAAM,OAAO,MAAM,QAAQ,mBAAmB,GAAG,QAAuB;EACtE,MAAM,QAAQ,KAAK;AACnB,MAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IAAI;AACzD,aAAU;AACV,UAAO;;AAGT,SAAO,OAAO,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,mBAAmB,CAAC,KAAK,IAAI;GACjE;AACF,KAAI,QAAS,QAAO,KAAA;AACpB,QAAO;EAAE,KAAK,QAAQ,YAAY,KAAK;EAAE,OAAO,iBAAiB;EAAO,QAAQ,iBAAiB;EAAQ;EAAK;;;;;;;;;;;;AAahH,SAAgB,aACd,MACA,SACc;CACd,MAAM,OAAO,KAAK,QAAQ,EAAE;CAC5B,MAAM,QAAQ,KAAK,SAAS,cAAc,QAAQ,UAAU,KAAK,MAAM;CACvE,MAAM,cAAc,KAAK,cAAc,EAAE,aAAa,KAAK,aAAa,GAAG,EAAE;CAC7E,MAAM,QAAQ,WAAW,KAAK,OAAO,QAAQ,IAAI,eAAe,MAAM,SAAS,KAAK,MAAM;CAC1F,MAAM,SAAS,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;AAE/C,QAAO;EACL,OAAO,KAAK,QAAQ,EAAE,UAAU,KAAK,OAAO,GAAG,KAAK;EACpD,GAAG;EACH,YAAY,EAAE,WAAW,QAAQ,WAAW;EAC5C,WAAW;GAAE;GAAO,GAAG;GAAa,KAAK,QAAQ;GAAW,GAAG;GAAQ;EACvE,SAAS;GAAE,MAAM;GAAuB;GAAO,GAAG;GAAa,GAAG;GAAQ;EAE1E,GAAI,KAAK,UAAU,EAAE,QAAQ;GAAE,OAAO;GAAO,QAAQ;GAAO,EAAE,GAAG,EAAE;EACpE"}
|
package/dist/navigation.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as NAVIGATION_FOOTER_SLUG, D as NavigationFooter, E as NavigationDoc, O as NavigationHeader, S as NAVIGATION_FOOTER_DB_NAME, T as NavigationBar, _ as validateExternalHref, a as FOOTER_MAX_LINK_COLUMNS, b as NAVIGATION_DB_NAME, c as FooterColumnWidth, d as normalizeFooterDesktop, g as isValidExternalHref, i as FOOTER_MAX_COLUMNS, l as FooterSocial, m as EXTERNAL_HREF_MESSAGE, o as FOOTER_SOCIALS, p as validateFooterSocialUrl, r as FOOTER_COLUMN_WIDTHS, s as FOOTER_TWELFTHS, t as getNavigation, u as footerDesktopTracks, v as validateHeaderCta, w as NAVIGATION_SLUG } from "./published-
|
|
1
|
+
import { C as NAVIGATION_FOOTER_SLUG, D as NavigationFooter, E as NavigationDoc, O as NavigationHeader, S as NAVIGATION_FOOTER_DB_NAME, T as NavigationBar, _ as validateExternalHref, a as FOOTER_MAX_LINK_COLUMNS, b as NAVIGATION_DB_NAME, c as FooterColumnWidth, d as normalizeFooterDesktop, g as isValidExternalHref, i as FOOTER_MAX_COLUMNS, l as FooterSocial, m as EXTERNAL_HREF_MESSAGE, o as FOOTER_SOCIALS, p as validateFooterSocialUrl, r as FOOTER_COLUMN_WIDTHS, s as FOOTER_TWELFTHS, t as getNavigation, u as footerDesktopTracks, v as validateHeaderCta, w as NAVIGATION_SLUG } from "./published-Dsg-HX-v.mjs";
|
|
2
2
|
export { EXTERNAL_HREF_MESSAGE, FOOTER_COLUMN_WIDTHS, FOOTER_MAX_COLUMNS, FOOTER_MAX_LINK_COLUMNS, FOOTER_SOCIALS, FOOTER_TWELFTHS, type FooterColumnWidth, type FooterSocial, NAVIGATION_DB_NAME, NAVIGATION_FOOTER_DB_NAME, NAVIGATION_FOOTER_SLUG, NAVIGATION_SLUG, type NavigationBar, type NavigationDoc, type NavigationFooter, type NavigationHeader, footerDesktopTracks, getNavigation, isValidExternalHref, normalizeFooterDesktop, validateExternalHref, validateFooterSocialUrl, validateHeaderCta };
|
package/dist/navigation.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as NAVIGATION_SLUG, S as NAVIGATION_FOOTER_SLUG, _ as validateExternalHref, a as FOOTER_MAX_LINK_COLUMNS, c as footerDesktopTracks, f as validateFooterSocialUrl, h as isValidExternalHref, i as FOOTER_MAX_COLUMNS, o as FOOTER_SOCIALS, p as EXTERNAL_HREF_MESSAGE, r as FOOTER_COLUMN_WIDTHS, s as FOOTER_TWELFTHS, t as getNavigation, u as normalizeFooterDesktop, v as validateHeaderCta, x as NAVIGATION_FOOTER_DB_NAME, y as NAVIGATION_DB_NAME } from "./published-
|
|
1
|
+
import { C as NAVIGATION_SLUG, S as NAVIGATION_FOOTER_SLUG, _ as validateExternalHref, a as FOOTER_MAX_LINK_COLUMNS, c as footerDesktopTracks, f as validateFooterSocialUrl, h as isValidExternalHref, i as FOOTER_MAX_COLUMNS, o as FOOTER_SOCIALS, p as EXTERNAL_HREF_MESSAGE, r as FOOTER_COLUMN_WIDTHS, s as FOOTER_TWELFTHS, t as getNavigation, u as normalizeFooterDesktop, v as validateHeaderCta, x as NAVIGATION_FOOTER_DB_NAME, y as NAVIGATION_DB_NAME } from "./published-CEuK5ym6.mjs";
|
|
2
2
|
export { EXTERNAL_HREF_MESSAGE, FOOTER_COLUMN_WIDTHS, FOOTER_MAX_COLUMNS, FOOTER_MAX_LINK_COLUMNS, FOOTER_SOCIALS, FOOTER_TWELFTHS, NAVIGATION_DB_NAME, NAVIGATION_FOOTER_DB_NAME, NAVIGATION_FOOTER_SLUG, NAVIGATION_SLUG, footerDesktopTracks, getNavigation, isValidExternalHref, normalizeFooterDesktop, validateExternalHref, validateFooterSocialUrl, validateHeaderCta };
|
package/dist/og.d.mts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { _ as ThemeIdentityFallback } from "./types-D6jQql5Z.mjs";
|
|
2
|
+
import { t as ThemePayload } from "./published-BLXCep6Z.mjs";
|
|
3
|
+
import { FontId } from "@bison-lab/fonts";
|
|
4
|
+
import { ThemeConfig } from "@bison-lab/tokens";
|
|
5
|
+
import { Payload } from "payload";
|
|
6
|
+
|
|
7
|
+
//#region src/og/card.d.ts
|
|
8
|
+
/** Open Graph's own size, the same as the uploaded share rendition: the card every network crops to. */
|
|
9
|
+
declare const OG_IMAGE_SIZE: {
|
|
10
|
+
readonly width: number;
|
|
11
|
+
readonly height: number;
|
|
12
|
+
};
|
|
13
|
+
/** The family the card draws in when the Theme names one outside the catalogue. */
|
|
14
|
+
declare const OG_FALLBACK_FONT: FontId;
|
|
15
|
+
interface OgCardColors {
|
|
16
|
+
/** The Theme's page background, in the mode the site opens in. */
|
|
17
|
+
background: string;
|
|
18
|
+
/** The primary fill: the band down the left edge. */
|
|
19
|
+
accent: string;
|
|
20
|
+
/** The title ink: primary when it passes the audit on this background, else the derived foreground. */
|
|
21
|
+
title: string;
|
|
22
|
+
/** Which token the title took, and why. */
|
|
23
|
+
titleToken: "primary" | "foreground";
|
|
24
|
+
/** `primary` on `background`, as `auditTheme` measured it. */
|
|
25
|
+
primaryRatio: number;
|
|
26
|
+
/** The target `primary` had to meet: the audit's body text target. */
|
|
27
|
+
target: number;
|
|
28
|
+
/** The site name's ink. */
|
|
29
|
+
muted: string;
|
|
30
|
+
}
|
|
31
|
+
/** `"h s% l%"` (the palette's token form) → `#rrggbb`, which every renderer reads. */
|
|
32
|
+
declare function tokenToHex(token: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* The card's colours, from the same derivation the site's stylesheet uses
|
|
35
|
+
* (`deriveLightPalette` / `deriveDarkPalette`): dark when the Theme opens
|
|
36
|
+
* dark, light otherwise. The title is primary only where `auditTheme`'s
|
|
37
|
+
* "primary as link text on the page background" check meets its target in
|
|
38
|
+
* that mode; a primary too pale (or too dark) for the background hands the
|
|
39
|
+
* title to the derived foreground, so the card never prints unreadable ink.
|
|
40
|
+
*/
|
|
41
|
+
declare function ogCardColors(theme: ThemeConfig): OgCardColors;
|
|
42
|
+
/** The catalogue family the card's heading uses: the Theme's heading face, else its body face, else Inter. */
|
|
43
|
+
declare function ogHeadingFont(theme: Pick<ThemeConfig, "fontBody" | "fontHeading">): FontId;
|
|
44
|
+
/** A satori node: the shape React elements take, without React. */
|
|
45
|
+
interface OgNode {
|
|
46
|
+
type: string;
|
|
47
|
+
props: {
|
|
48
|
+
style?: Record<string, string | number>;
|
|
49
|
+
children?: OgNode | string | (OgNode | string)[];
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
interface OgCardInput {
|
|
54
|
+
title: string;
|
|
55
|
+
siteName: string;
|
|
56
|
+
colors: OgCardColors;
|
|
57
|
+
/** The family name satori was given the font under. */
|
|
58
|
+
fontFamily: string;
|
|
59
|
+
/** The logo as a URL satori can read (a `data:` URI is safest), or none. */
|
|
60
|
+
logo?: {
|
|
61
|
+
src: string;
|
|
62
|
+
} | null;
|
|
63
|
+
}
|
|
64
|
+
/** The logo's height on the card, in px. */
|
|
65
|
+
declare const LOGO_HEIGHT = 72;
|
|
66
|
+
/**
|
|
67
|
+
* The card as a satori tree: a primary band down the left edge, the logo
|
|
68
|
+
* top left, the title large in the heading face, the site name below.
|
|
69
|
+
*/
|
|
70
|
+
declare function ogCardElement({
|
|
71
|
+
title,
|
|
72
|
+
siteName,
|
|
73
|
+
colors,
|
|
74
|
+
fontFamily,
|
|
75
|
+
logo
|
|
76
|
+
}: OgCardInput): OgNode;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/og/render.d.ts
|
|
79
|
+
interface RenderOgImageInput {
|
|
80
|
+
title: string;
|
|
81
|
+
siteName: string;
|
|
82
|
+
/** The published Theme (`getPublishedTheme`). */
|
|
83
|
+
theme: ThemeConfig;
|
|
84
|
+
/** The logo as a URL satori can read; `loadOgLogo` turns a site path into a `data:` URI. */
|
|
85
|
+
logo?: string | null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The card as a 1200×630 PNG: the Theme's colours, its heading face from
|
|
89
|
+
* `@bison-lab/fonts` (read off disk, never fetched from Google), and the
|
|
90
|
+
* logo. satori lays it out as SVG; resvg rasterises it.
|
|
91
|
+
*/
|
|
92
|
+
declare function renderOgImage(input: RenderOgImageInput): Promise<Uint8Array>;
|
|
93
|
+
/**
|
|
94
|
+
* Fetch the logo and return it as a `data:` URI, or `null` when it cannot be
|
|
95
|
+
* read: a card without a logo beats no card. `fetchImpl` is for tests.
|
|
96
|
+
*/
|
|
97
|
+
declare function loadOgLogo(url: string, fetchImpl?: typeof fetch): Promise<string | null>;
|
|
98
|
+
/** The page a card is drawn for. */
|
|
99
|
+
interface OgPage {
|
|
100
|
+
title: string;
|
|
101
|
+
}
|
|
102
|
+
/** The two reads the handler makes. A site's `Payload` has both; tests hand in fakes. */
|
|
103
|
+
interface OgPayload extends ThemePayload {
|
|
104
|
+
find(args: Record<string, unknown>): Promise<{
|
|
105
|
+
docs: unknown[];
|
|
106
|
+
}>;
|
|
107
|
+
}
|
|
108
|
+
interface FindOgPageArgs {
|
|
109
|
+
payload: OgPayload;
|
|
110
|
+
request: Request;
|
|
111
|
+
params: Record<string, string | string[] | undefined>;
|
|
112
|
+
}
|
|
113
|
+
interface OgImageHandlerOptions {
|
|
114
|
+
/** The Payload instance: `() => getPayload({ config })`. */
|
|
115
|
+
payload: () => Payload | Promise<Payload>;
|
|
116
|
+
/** The site's `bison.config.json`, the Theme seed `getPublishedTheme` falls back to. */
|
|
117
|
+
seed: ThemeConfig;
|
|
118
|
+
/** Printed under the title. */
|
|
119
|
+
siteName: string;
|
|
120
|
+
/** The same fallback passed to `createTheme({ identity: { fallback } })`, for an empty logo. */
|
|
121
|
+
identity?: ThemeIdentityFallback;
|
|
122
|
+
/** Turns a logo path (`/api/brand-assets/file/logo.svg`) into an absolute URL to fetch. */
|
|
123
|
+
absoluteUrl: (path: string) => string;
|
|
124
|
+
/** @default "pages" */
|
|
125
|
+
collection?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Find the page from the route's params. Default: the published page
|
|
128
|
+
* whose `slug` equals `params.slug` (segments joined with `/`), read as
|
|
129
|
+
* the visitor so a draft or hidden page draws nothing.
|
|
130
|
+
*/
|
|
131
|
+
findPage?: (args: FindOgPageArgs) => Promise<OgPage | null>;
|
|
132
|
+
/** @default "public, max-age=3600, s-maxage=86400, stale-while-revalidate=604800" */
|
|
133
|
+
cacheControl?: string;
|
|
134
|
+
/** For tests: how the logo is fetched. */
|
|
135
|
+
fetch?: typeof fetch;
|
|
136
|
+
}
|
|
137
|
+
type RouteContext = {
|
|
138
|
+
params?: Record<string, string | string[] | undefined> | Promise<Record<string, string | string[] | undefined>>;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* A route handler that answers with a page's Open Graph card (BIS-183).
|
|
142
|
+
* Framework-agnostic: a Fetch `Request` (and the route's params) in, a PNG
|
|
143
|
+
* `Response` out. In Next, `app/og/[...slug]/route.ts`:
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* export const GET = ogImageHandler({ payload: () => getPayload({ config }), seed, siteName, absoluteUrl });
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* Then pass the same pattern to `pageMetadata({ ogImageRoute: "/og/{slug}" })`.
|
|
150
|
+
* A page that is missing, a draft or hidden from the visitor is a `404`.
|
|
151
|
+
*/
|
|
152
|
+
declare function ogImageHandler(options: OgImageHandlerOptions): (request: Request, context?: RouteContext) => Promise<Response>;
|
|
153
|
+
//#endregion
|
|
154
|
+
export { type FindOgPageArgs, LOGO_HEIGHT, OG_FALLBACK_FONT, OG_IMAGE_SIZE, type OgCardColors, type OgCardInput, type OgImageHandlerOptions, type OgNode, type OgPage, type OgPayload, type RenderOgImageInput, loadOgLogo, ogCardColors, ogCardElement, ogHeadingFont, ogImageHandler, renderOgImage, tokenToHex };
|
|
155
|
+
//# sourceMappingURL=og.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"og.d.mts","names":[],"sources":["../src/og/card.ts","../src/og/render.ts"],"mappings":";;;;;;;;cAYa,aAAA;EAAA,SAA2F,KAAA;EAAA,SAAA,MAAA;AAAA;AAAxG;AAAA,cAGa,gBAAA,EAAkB,MAAA;AAAA,UAEd,YAAA;EALuF;EAOtG,UAAA;EAJW;EAMX,MAAA;;EAEA,KAAA;EAR6C;EAU7C,UAAA;EAR2B;EAU3B,YAAA;EAV2B;EAY3B,MAAA;EARA;EAUA,KAAA;AAAA;;iBAIc,UAAA,CAAW,KAAA;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dyF;;;;;ECoBzF,QAAA,IAAY,IAAA,EAAM,cAAA,KAAmB,OAAA,CAAQ,MAAA;EDpB4C;ECsBzF,YAAA;EDhBqB;ECkBrB,KAAA,UAAe,KAAA;AAAA;AAAA,KAqBZ,YAAA;EAAiB,MAAA,GAAS,MAAA,0CAAgD,OAAA,CAAQ,MAAA;AAAA;;;;;;;;;;;;ADlCvF;iBCgDgB,cAAA,CAAe,OAAA,EAAS,qBAAA,IAGxB,OAAA,EAAS,OAAA,EAAS,OAAA,GAAS,YAAA,KAAoB,OAAA,CAAQ,QAAA"}
|
package/dist/og.mjs
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { t as SHARE_IMAGE_SIZE } from "./share-image-C8ZtIcU8.mjs";
|
|
2
|
+
import "./identity-CN6EOeDM.mjs";
|
|
3
|
+
import { n as getPublishedTheme, t as getPublishedIdentity } from "./published-DgAzpDSG.mjs";
|
|
4
|
+
import { isFontId } from "@bison-lab/fonts";
|
|
5
|
+
import { auditTheme, brandColorsFromConfig, deriveDarkPalette, deriveLightPalette } from "@bison-lab/tokens";
|
|
6
|
+
import * as fontsServer from "@bison-lab/fonts/server";
|
|
7
|
+
import { Resvg } from "@resvg/resvg-js";
|
|
8
|
+
import satori from "satori";
|
|
9
|
+
//#region src/og/card.ts
|
|
10
|
+
/** Open Graph's own size, the same as the uploaded share rendition: the card every network crops to. */
|
|
11
|
+
const OG_IMAGE_SIZE = {
|
|
12
|
+
width: SHARE_IMAGE_SIZE.width,
|
|
13
|
+
height: SHARE_IMAGE_SIZE.height
|
|
14
|
+
};
|
|
15
|
+
/** The family the card draws in when the Theme names one outside the catalogue. */
|
|
16
|
+
const OG_FALLBACK_FONT = "inter";
|
|
17
|
+
/** `"h s% l%"` (the palette's token form) → `#rrggbb`, which every renderer reads. */
|
|
18
|
+
function tokenToHex(token) {
|
|
19
|
+
const match = /^(-?[\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/.exec(token.trim());
|
|
20
|
+
if (!match) return token;
|
|
21
|
+
const h = (Number(match[1]) % 360 + 360) % 360 / 360;
|
|
22
|
+
const s = Number(match[2]) / 100;
|
|
23
|
+
const l = Number(match[3]) / 100;
|
|
24
|
+
const channel = (t) => {
|
|
25
|
+
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
26
|
+
const p = 2 * l - q;
|
|
27
|
+
let x = t;
|
|
28
|
+
if (x < 0) x += 1;
|
|
29
|
+
if (x > 1) x -= 1;
|
|
30
|
+
if (x < 1 / 6) return p + (q - p) * 6 * x;
|
|
31
|
+
if (x < 1 / 2) return q;
|
|
32
|
+
if (x < 2 / 3) return p + (q - p) * (2 / 3 - x) * 6;
|
|
33
|
+
return p;
|
|
34
|
+
};
|
|
35
|
+
return `#${(s === 0 ? [
|
|
36
|
+
l,
|
|
37
|
+
l,
|
|
38
|
+
l
|
|
39
|
+
] : [
|
|
40
|
+
channel(h + 1 / 3),
|
|
41
|
+
channel(h),
|
|
42
|
+
channel(h - 1 / 3)
|
|
43
|
+
]).map((v) => Math.round(v * 255).toString(16).padStart(2, "0")).join("")}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The card's colours, from the same derivation the site's stylesheet uses
|
|
47
|
+
* (`deriveLightPalette` / `deriveDarkPalette`): dark when the Theme opens
|
|
48
|
+
* dark, light otherwise. The title is primary only where `auditTheme`'s
|
|
49
|
+
* "primary as link text on the page background" check meets its target in
|
|
50
|
+
* that mode; a primary too pale (or too dark) for the background hands the
|
|
51
|
+
* title to the derived foreground, so the card never prints unreadable ink.
|
|
52
|
+
*/
|
|
53
|
+
function ogCardColors(theme) {
|
|
54
|
+
const mode = theme.defaultTheme === "dark" ? "dark" : "light";
|
|
55
|
+
const brand = brandColorsFromConfig(theme);
|
|
56
|
+
const palette = mode === "dark" ? deriveDarkPalette(brand) : deriveLightPalette(brand);
|
|
57
|
+
const check = auditTheme(theme).find((c) => c.id === "primary-on-background");
|
|
58
|
+
if (!check) throw new Error("auditTheme no longer measures primary on the page background.");
|
|
59
|
+
const sample = check[mode];
|
|
60
|
+
const passes = sample.ratio >= check.target;
|
|
61
|
+
return {
|
|
62
|
+
background: tokenToHex(palette.background),
|
|
63
|
+
accent: tokenToHex(palette.primary),
|
|
64
|
+
title: tokenToHex(passes ? palette.primary : palette.foreground),
|
|
65
|
+
titleToken: passes ? "primary" : "foreground",
|
|
66
|
+
primaryRatio: sample.ratio,
|
|
67
|
+
target: check.target,
|
|
68
|
+
muted: tokenToHex(palette["muted-foreground"])
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** The catalogue family the card's heading uses: the Theme's heading face, else its body face, else Inter. */
|
|
72
|
+
function ogHeadingFont(theme) {
|
|
73
|
+
const wanted = theme.fontHeading ?? theme.fontBody;
|
|
74
|
+
return isFontId(wanted) ? wanted : OG_FALLBACK_FONT;
|
|
75
|
+
}
|
|
76
|
+
/** The logo's height on the card, in px. */
|
|
77
|
+
const LOGO_HEIGHT = 72;
|
|
78
|
+
/** Long titles step down so three lines fit. */
|
|
79
|
+
function titleSize(title) {
|
|
80
|
+
if (title.length > 90) return 52;
|
|
81
|
+
if (title.length > 55) return 60;
|
|
82
|
+
return 72;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The card as a satori tree: a primary band down the left edge, the logo
|
|
86
|
+
* top left, the title large in the heading face, the site name below.
|
|
87
|
+
*/
|
|
88
|
+
function ogCardElement({ title, siteName, colors, fontFamily, logo }) {
|
|
89
|
+
const header = logo ? {
|
|
90
|
+
type: "img",
|
|
91
|
+
props: {
|
|
92
|
+
src: logo.src,
|
|
93
|
+
style: {
|
|
94
|
+
height: 72,
|
|
95
|
+
maxWidth: 480,
|
|
96
|
+
objectFit: "contain"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} : {
|
|
100
|
+
type: "div",
|
|
101
|
+
props: { style: {
|
|
102
|
+
display: "flex",
|
|
103
|
+
height: 1
|
|
104
|
+
} }
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
type: "div",
|
|
108
|
+
props: {
|
|
109
|
+
style: {
|
|
110
|
+
width: OG_IMAGE_SIZE.width,
|
|
111
|
+
height: OG_IMAGE_SIZE.height,
|
|
112
|
+
display: "flex",
|
|
113
|
+
backgroundColor: colors.background,
|
|
114
|
+
fontFamily
|
|
115
|
+
},
|
|
116
|
+
children: [{
|
|
117
|
+
type: "div",
|
|
118
|
+
props: { style: {
|
|
119
|
+
width: 24,
|
|
120
|
+
flexShrink: 0,
|
|
121
|
+
height: "100%",
|
|
122
|
+
backgroundColor: colors.accent
|
|
123
|
+
} }
|
|
124
|
+
}, {
|
|
125
|
+
type: "div",
|
|
126
|
+
props: {
|
|
127
|
+
style: {
|
|
128
|
+
display: "flex",
|
|
129
|
+
flexDirection: "column",
|
|
130
|
+
justifyContent: "space-between",
|
|
131
|
+
flexGrow: 1,
|
|
132
|
+
padding: "72px 80px"
|
|
133
|
+
},
|
|
134
|
+
children: [
|
|
135
|
+
header,
|
|
136
|
+
{
|
|
137
|
+
type: "div",
|
|
138
|
+
props: {
|
|
139
|
+
style: {
|
|
140
|
+
display: "flex",
|
|
141
|
+
color: colors.title,
|
|
142
|
+
fontSize: titleSize(title),
|
|
143
|
+
fontWeight: 700,
|
|
144
|
+
lineHeight: 1.1,
|
|
145
|
+
letterSpacing: -1
|
|
146
|
+
},
|
|
147
|
+
children: title
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
type: "div",
|
|
152
|
+
props: {
|
|
153
|
+
style: {
|
|
154
|
+
display: "flex",
|
|
155
|
+
color: colors.muted,
|
|
156
|
+
fontSize: 32,
|
|
157
|
+
fontWeight: 700
|
|
158
|
+
},
|
|
159
|
+
children: siteName
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
}]
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/og/render.ts
|
|
170
|
+
/**
|
|
171
|
+
* The card as a 1200×630 PNG: the Theme's colours, its heading face from
|
|
172
|
+
* `@bison-lab/fonts` (read off disk, never fetched from Google), and the
|
|
173
|
+
* logo. satori lays it out as SVG; resvg rasterises it.
|
|
174
|
+
*/
|
|
175
|
+
async function renderOgImage(input) {
|
|
176
|
+
const readImageFont = "readImageFont" in fontsServer ? fontsServer.readImageFont : void 0;
|
|
177
|
+
if (typeof readImageFont !== "function") throw new Error("@bison-lab/payload-core/og needs a @bison-lab/fonts release with readImageFont (the one this payload-core shipped beside). Upgrade @bison-lab/fonts.");
|
|
178
|
+
const font = await readImageFont(ogHeadingFont(input.theme));
|
|
179
|
+
const png = new Resvg(await satori(ogCardElement({
|
|
180
|
+
title: input.title,
|
|
181
|
+
siteName: input.siteName,
|
|
182
|
+
colors: ogCardColors(input.theme),
|
|
183
|
+
fontFamily: font.family,
|
|
184
|
+
logo: input.logo ? { src: input.logo } : null
|
|
185
|
+
}), {
|
|
186
|
+
width: OG_IMAGE_SIZE.width,
|
|
187
|
+
height: OG_IMAGE_SIZE.height,
|
|
188
|
+
fonts: [{
|
|
189
|
+
name: font.family,
|
|
190
|
+
data: font.data,
|
|
191
|
+
weight: font.weight,
|
|
192
|
+
style: font.style
|
|
193
|
+
}]
|
|
194
|
+
}), { fitTo: {
|
|
195
|
+
mode: "width",
|
|
196
|
+
value: OG_IMAGE_SIZE.width
|
|
197
|
+
} }).render().asPng();
|
|
198
|
+
return new Uint8Array(png);
|
|
199
|
+
}
|
|
200
|
+
const IMAGE_TYPES = /^image\/(png|jpeg|gif|svg\+xml|webp)/;
|
|
201
|
+
/**
|
|
202
|
+
* Fetch the logo and return it as a `data:` URI, or `null` when it cannot be
|
|
203
|
+
* read: a card without a logo beats no card. `fetchImpl` is for tests.
|
|
204
|
+
*/
|
|
205
|
+
async function loadOgLogo(url, fetchImpl = fetch) {
|
|
206
|
+
if (url.startsWith("data:")) return url;
|
|
207
|
+
try {
|
|
208
|
+
const response = await fetchImpl(url, { signal: AbortSignal.timeout(5e3) });
|
|
209
|
+
if (!response.ok) return null;
|
|
210
|
+
const type = (response.headers.get("content-type") ?? "").split(";")[0].trim();
|
|
211
|
+
if (!IMAGE_TYPES.test(type)) return null;
|
|
212
|
+
return `data:${type};base64,${Buffer.from(await response.arrayBuffer()).toString("base64")}`;
|
|
213
|
+
} catch {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function defaultFindPage(collection) {
|
|
218
|
+
return async ({ payload, params }) => {
|
|
219
|
+
const raw = params.slug;
|
|
220
|
+
const slug = Array.isArray(raw) ? raw.join("/") : raw;
|
|
221
|
+
if (!slug) return null;
|
|
222
|
+
const { docs } = await payload.find({
|
|
223
|
+
collection,
|
|
224
|
+
where: { slug: { equals: slug } },
|
|
225
|
+
draft: false,
|
|
226
|
+
overrideAccess: false,
|
|
227
|
+
depth: 0,
|
|
228
|
+
limit: 1
|
|
229
|
+
});
|
|
230
|
+
const doc = docs[0];
|
|
231
|
+
return doc && typeof doc.title === "string" ? { title: doc.title } : null;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* A route handler that answers with a page's Open Graph card (BIS-183).
|
|
236
|
+
* Framework-agnostic: a Fetch `Request` (and the route's params) in, a PNG
|
|
237
|
+
* `Response` out. In Next, `app/og/[...slug]/route.ts`:
|
|
238
|
+
*
|
|
239
|
+
* ```ts
|
|
240
|
+
* export const GET = ogImageHandler({ payload: () => getPayload({ config }), seed, siteName, absoluteUrl });
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* Then pass the same pattern to `pageMetadata({ ogImageRoute: "/og/{slug}" })`.
|
|
244
|
+
* A page that is missing, a draft or hidden from the visitor is a `404`.
|
|
245
|
+
*/
|
|
246
|
+
function ogImageHandler(options) {
|
|
247
|
+
const findPage = options.findPage ?? defaultFindPage(options.collection ?? "pages");
|
|
248
|
+
const cacheControl = options.cacheControl ?? "public, max-age=3600, s-maxage=86400, stale-while-revalidate=604800";
|
|
249
|
+
return async (request, context = {}) => {
|
|
250
|
+
const payload = await options.payload();
|
|
251
|
+
const page = await findPage({
|
|
252
|
+
payload,
|
|
253
|
+
request,
|
|
254
|
+
params: await context.params ?? {}
|
|
255
|
+
});
|
|
256
|
+
if (!page) return new Response("Not found", {
|
|
257
|
+
status: 404,
|
|
258
|
+
headers: { "cache-control": "no-store" }
|
|
259
|
+
});
|
|
260
|
+
const [theme, identity] = await Promise.all([getPublishedTheme(payload, options.seed), getPublishedIdentity(payload, options.identity)]);
|
|
261
|
+
const logoUrl = identity.lockup?.url;
|
|
262
|
+
const logo = logoUrl ? await loadOgLogo(logoUrl.startsWith("data:") ? logoUrl : options.absoluteUrl(logoUrl), options.fetch) : null;
|
|
263
|
+
const png = await renderOgImage({
|
|
264
|
+
title: page.title,
|
|
265
|
+
siteName: options.siteName,
|
|
266
|
+
theme,
|
|
267
|
+
logo
|
|
268
|
+
});
|
|
269
|
+
return new Response(png, {
|
|
270
|
+
status: 200,
|
|
271
|
+
headers: {
|
|
272
|
+
"content-type": "image/png",
|
|
273
|
+
"content-length": String(png.byteLength),
|
|
274
|
+
"cache-control": cacheControl
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
export { LOGO_HEIGHT, OG_FALLBACK_FONT, OG_IMAGE_SIZE, loadOgLogo, ogCardColors, ogCardElement, ogHeadingFont, ogImageHandler, renderOgImage, tokenToHex };
|
|
281
|
+
|
|
282
|
+
//# sourceMappingURL=og.mjs.map
|
package/dist/og.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"og.mjs","names":[],"sources":["../src/og/card.ts","../src/og/render.ts"],"sourcesContent":["import { isFontId, type FontId } from \"@bison-lab/fonts\";\nimport {\n auditTheme,\n brandColorsFromConfig,\n deriveDarkPalette,\n deriveLightPalette,\n type ThemeConfig,\n} from \"@bison-lab/tokens\";\n\nimport { SHARE_IMAGE_SIZE } from \"../seo/share-image\";\n\n/** Open Graph's own size, the same as the uploaded share rendition: the card every network crops to. */\nexport const OG_IMAGE_SIZE = { width: SHARE_IMAGE_SIZE.width, height: SHARE_IMAGE_SIZE.height } as const;\n\n/** The family the card draws in when the Theme names one outside the catalogue. */\nexport const OG_FALLBACK_FONT: FontId = \"inter\";\n\nexport interface OgCardColors {\n /** The Theme's page background, in the mode the site opens in. */\n background: string;\n /** The primary fill: the band down the left edge. */\n accent: string;\n /** The title ink: primary when it passes the audit on this background, else the derived foreground. */\n title: string;\n /** Which token the title took, and why. */\n titleToken: \"primary\" | \"foreground\";\n /** `primary` on `background`, as `auditTheme` measured it. */\n primaryRatio: number;\n /** The target `primary` had to meet: the audit's body text target. */\n target: number;\n /** The site name's ink. */\n muted: string;\n}\n\n/** `\"h s% l%\"` (the palette's token form) → `#rrggbb`, which every renderer reads. */\nexport function tokenToHex(token: string): string {\n const match = /^(-?[\\d.]+)\\s+([\\d.]+)%\\s+([\\d.]+)%$/.exec(token.trim());\n if (!match) return token;\n const h = (((Number(match[1]) % 360) + 360) % 360) / 360;\n const s = Number(match[2]) / 100;\n const l = Number(match[3]) / 100;\n const channel = (t: number) => {\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n let x = t;\n if (x < 0) x += 1;\n if (x > 1) x -= 1;\n if (x < 1 / 6) return p + (q - p) * 6 * x;\n if (x < 1 / 2) return q;\n if (x < 2 / 3) return p + (q - p) * (2 / 3 - x) * 6;\n return p;\n };\n const rgb = s === 0 ? [l, l, l] : [channel(h + 1 / 3), channel(h), channel(h - 1 / 3)];\n return `#${rgb.map((v) => Math.round(v * 255).toString(16).padStart(2, \"0\")).join(\"\")}`;\n}\n\n/**\n * The card's colours, from the same derivation the site's stylesheet uses\n * (`deriveLightPalette` / `deriveDarkPalette`): dark when the Theme opens\n * dark, light otherwise. The title is primary only where `auditTheme`'s\n * \"primary as link text on the page background\" check meets its target in\n * that mode; a primary too pale (or too dark) for the background hands the\n * title to the derived foreground, so the card never prints unreadable ink.\n */\nexport function ogCardColors(theme: ThemeConfig): OgCardColors {\n const mode = theme.defaultTheme === \"dark\" ? \"dark\" : \"light\";\n const brand = brandColorsFromConfig(theme);\n const palette = mode === \"dark\" ? deriveDarkPalette(brand) : deriveLightPalette(brand);\n const check = auditTheme(theme).find((c) => c.id === \"primary-on-background\");\n if (!check) throw new Error(\"auditTheme no longer measures primary on the page background.\");\n const sample = check[mode];\n const passes = sample.ratio >= check.target;\n return {\n background: tokenToHex(palette.background),\n accent: tokenToHex(palette.primary),\n title: tokenToHex(passes ? palette.primary : palette.foreground),\n titleToken: passes ? \"primary\" : \"foreground\",\n primaryRatio: sample.ratio,\n target: check.target,\n muted: tokenToHex(palette[\"muted-foreground\"]),\n };\n}\n\n/** The catalogue family the card's heading uses: the Theme's heading face, else its body face, else Inter. */\nexport function ogHeadingFont(theme: Pick<ThemeConfig, \"fontBody\" | \"fontHeading\">): FontId {\n const wanted = theme.fontHeading ?? theme.fontBody;\n return isFontId(wanted) ? wanted : OG_FALLBACK_FONT;\n}\n\n/** A satori node: the shape React elements take, without React. */\nexport interface OgNode {\n type: string;\n props: { style?: Record<string, string | number>; children?: OgNode | string | (OgNode | string)[]; [key: string]: unknown };\n}\n\nexport interface OgCardInput {\n title: string;\n siteName: string;\n colors: OgCardColors;\n /** The family name satori was given the font under. */\n fontFamily: string;\n /** The logo as a URL satori can read (a `data:` URI is safest), or none. */\n logo?: { src: string } | null;\n}\n\n/** The logo's height on the card, in px. */\nexport const LOGO_HEIGHT = 72;\n\n/** Long titles step down so three lines fit. */\nfunction titleSize(title: string): number {\n if (title.length > 90) return 52;\n if (title.length > 55) return 60;\n return 72;\n}\n\n/**\n * The card as a satori tree: a primary band down the left edge, the logo\n * top left, the title large in the heading face, the site name below.\n */\nexport function ogCardElement({ title, siteName, colors, fontFamily, logo }: OgCardInput): OgNode {\n const header: OgNode = logo\n ? {\n type: \"img\",\n // Height only: satori reads the image's own size and keeps its ratio.\n props: { src: logo.src, style: { height: LOGO_HEIGHT, maxWidth: 480, objectFit: \"contain\" } },\n }\n : { type: \"div\", props: { style: { display: \"flex\", height: 1 } } };\n return {\n type: \"div\",\n props: {\n style: {\n width: OG_IMAGE_SIZE.width,\n height: OG_IMAGE_SIZE.height,\n display: \"flex\",\n backgroundColor: colors.background,\n fontFamily,\n },\n children: [\n { type: \"div\", props: { style: { width: 24, flexShrink: 0, height: \"100%\", backgroundColor: colors.accent } } },\n {\n type: \"div\",\n props: {\n style: {\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"space-between\",\n flexGrow: 1,\n padding: \"72px 80px\",\n },\n children: [\n header,\n {\n type: \"div\",\n props: {\n style: {\n display: \"flex\",\n color: colors.title,\n fontSize: titleSize(title),\n fontWeight: 700,\n lineHeight: 1.1,\n letterSpacing: -1,\n },\n children: title,\n },\n },\n {\n type: \"div\",\n props: { style: { display: \"flex\", color: colors.muted, fontSize: 32, fontWeight: 700 }, children: siteName },\n },\n ],\n },\n },\n ],\n },\n };\n}\n","// A namespace import, not a named one: a site still on a `@bison-lab/fonts` release without\n// `readImageFont` gets the named error below instead of a module-link failure.\nimport * as fontsServer from \"@bison-lab/fonts/server\";\nimport type { ThemeConfig } from \"@bison-lab/tokens\";\nimport { Resvg } from \"@resvg/resvg-js\";\nimport type { Payload } from \"payload\";\nimport satori from \"satori\";\n\nimport { getPublishedIdentity, getPublishedTheme, type ThemePayload } from \"../theme/published\";\nimport type { ThemeIdentityFallback } from \"../theme/identity\";\nimport { OG_IMAGE_SIZE, ogCardColors, ogCardElement, ogHeadingFont } from \"./card\";\n\nexport interface RenderOgImageInput {\n title: string;\n siteName: string;\n /** The published Theme (`getPublishedTheme`). */\n theme: ThemeConfig;\n /** The logo as a URL satori can read; `loadOgLogo` turns a site path into a `data:` URI. */\n logo?: string | null;\n}\n\n/**\n * The card as a 1200×630 PNG: the Theme's colours, its heading face from\n * `@bison-lab/fonts` (read off disk, never fetched from Google), and the\n * logo. satori lays it out as SVG; resvg rasterises it.\n */\nexport async function renderOgImage(input: RenderOgImageInput): Promise<Uint8Array> {\n const readImageFont = \"readImageFont\" in fontsServer ? fontsServer.readImageFont : undefined;\n if (typeof readImageFont !== \"function\") {\n throw new Error(\n \"@bison-lab/payload-core/og needs a @bison-lab/fonts release with readImageFont (the one this payload-core shipped beside). Upgrade @bison-lab/fonts.\",\n );\n }\n const font = await readImageFont(ogHeadingFont(input.theme));\n const element = ogCardElement({\n title: input.title,\n siteName: input.siteName,\n colors: ogCardColors(input.theme),\n fontFamily: font.family,\n logo: input.logo ? { src: input.logo } : null,\n });\n const svg = await satori(element as never, {\n width: OG_IMAGE_SIZE.width,\n height: OG_IMAGE_SIZE.height,\n fonts: [{ name: font.family, data: font.data, weight: font.weight, style: font.style }],\n });\n const png = new Resvg(svg, { fitTo: { mode: \"width\", value: OG_IMAGE_SIZE.width } }).render().asPng();\n return new Uint8Array(png);\n}\n\nconst IMAGE_TYPES = /^image\\/(png|jpeg|gif|svg\\+xml|webp)/;\n\n/**\n * Fetch the logo and return it as a `data:` URI, or `null` when it cannot be\n * read: a card without a logo beats no card. `fetchImpl` is for tests.\n */\nexport async function loadOgLogo(url: string, fetchImpl: typeof fetch = fetch): Promise<string | null> {\n if (url.startsWith(\"data:\")) return url;\n try {\n const response = await fetchImpl(url, { signal: AbortSignal.timeout(5_000) });\n if (!response.ok) return null;\n const type = (response.headers.get(\"content-type\") ?? \"\").split(\";\")[0]!.trim();\n if (!IMAGE_TYPES.test(type)) return null;\n const bytes = Buffer.from(await response.arrayBuffer());\n return `data:${type};base64,${bytes.toString(\"base64\")}`;\n } catch {\n return null;\n }\n}\n\n/** The page a card is drawn for. */\nexport interface OgPage {\n title: string;\n}\n\n/** The two reads the handler makes. A site's `Payload` has both; tests hand in fakes. */\nexport interface OgPayload extends ThemePayload {\n find(args: Record<string, unknown>): Promise<{ docs: unknown[] }>;\n}\n\nexport interface FindOgPageArgs {\n payload: OgPayload;\n request: Request;\n params: Record<string, string | string[] | undefined>;\n}\n\nexport interface OgImageHandlerOptions {\n /** The Payload instance: `() => getPayload({ config })`. */\n payload: () => Payload | Promise<Payload>;\n /** The site's `bison.config.json`, the Theme seed `getPublishedTheme` falls back to. */\n seed: ThemeConfig;\n /** Printed under the title. */\n siteName: string;\n /** The same fallback passed to `createTheme({ identity: { fallback } })`, for an empty logo. */\n identity?: ThemeIdentityFallback;\n /** Turns a logo path (`/api/brand-assets/file/logo.svg`) into an absolute URL to fetch. */\n absoluteUrl: (path: string) => string;\n /** @default \"pages\" */\n collection?: string;\n /**\n * Find the page from the route's params. Default: the published page\n * whose `slug` equals `params.slug` (segments joined with `/`), read as\n * the visitor so a draft or hidden page draws nothing.\n */\n findPage?: (args: FindOgPageArgs) => Promise<OgPage | null>;\n /** @default \"public, max-age=3600, s-maxage=86400, stale-while-revalidate=604800\" */\n cacheControl?: string;\n /** For tests: how the logo is fetched. */\n fetch?: typeof fetch;\n}\n\nfunction defaultFindPage(collection: string) {\n return async ({ payload, params }: FindOgPageArgs): Promise<OgPage | null> => {\n const raw = params.slug;\n const slug = Array.isArray(raw) ? raw.join(\"/\") : raw;\n if (!slug) return null;\n const { docs } = await payload.find({\n collection,\n where: { slug: { equals: slug } },\n draft: false,\n overrideAccess: false,\n depth: 0,\n limit: 1,\n });\n const doc = docs[0] as { title?: unknown } | undefined;\n return doc && typeof doc.title === \"string\" ? { title: doc.title } : null;\n };\n}\n\ntype RouteContext = { params?: Record<string, string | string[] | undefined> | Promise<Record<string, string | string[] | undefined>> };\n\n/**\n * A route handler that answers with a page's Open Graph card (BIS-183).\n * Framework-agnostic: a Fetch `Request` (and the route's params) in, a PNG\n * `Response` out. In Next, `app/og/[...slug]/route.ts`:\n *\n * ```ts\n * export const GET = ogImageHandler({ payload: () => getPayload({ config }), seed, siteName, absoluteUrl });\n * ```\n *\n * Then pass the same pattern to `pageMetadata({ ogImageRoute: \"/og/{slug}\" })`.\n * A page that is missing, a draft or hidden from the visitor is a `404`.\n */\nexport function ogImageHandler(options: OgImageHandlerOptions) {\n const findPage = options.findPage ?? defaultFindPage(options.collection ?? \"pages\");\n const cacheControl = options.cacheControl ?? \"public, max-age=3600, s-maxage=86400, stale-while-revalidate=604800\";\n return async (request: Request, context: RouteContext = {}): Promise<Response> => {\n const payload = (await options.payload()) as unknown as OgPayload;\n const params = (await context.params) ?? {};\n const page = await findPage({ payload, request, params });\n if (!page) return new Response(\"Not found\", { status: 404, headers: { \"cache-control\": \"no-store\" } });\n\n const [theme, identity] = await Promise.all([\n getPublishedTheme(payload, options.seed),\n getPublishedIdentity(payload, options.identity),\n ]);\n const logoUrl = identity.lockup?.url;\n const logo = logoUrl ? await loadOgLogo(logoUrl.startsWith(\"data:\") ? logoUrl : options.absoluteUrl(logoUrl), options.fetch) : null;\n\n const png = await renderOgImage({ title: page.title, siteName: options.siteName, theme, logo });\n return new Response(png as BodyInit, {\n status: 200,\n headers: { \"content-type\": \"image/png\", \"content-length\": String(png.byteLength), \"cache-control\": cacheControl },\n });\n };\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAa,gBAAgB;CAAE,OAAO,iBAAiB;CAAO,QAAQ,iBAAiB;CAAQ;;AAG/F,MAAa,mBAA2B;;AAoBxC,SAAgB,WAAW,OAAuB;CAChD,MAAM,QAAQ,uCAAuC,KAAK,MAAM,MAAM,CAAC;AACvE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,KAAO,OAAO,MAAM,GAAG,GAAG,MAAO,OAAO,MAAO;CACrD,MAAM,IAAI,OAAO,MAAM,GAAG,GAAG;CAC7B,MAAM,IAAI,OAAO,MAAM,GAAG,GAAG;CAC7B,MAAM,WAAW,MAAc;EAC7B,MAAM,IAAI,IAAI,KAAM,KAAK,IAAI,KAAK,IAAI,IAAI,IAAI;EAC9C,MAAM,IAAI,IAAI,IAAI;EAClB,IAAI,IAAI;AACR,MAAI,IAAI,EAAG,MAAK;AAChB,MAAI,IAAI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