@bison-lab/payload-core 4.39.0 → 5.0.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.
Files changed (75) hide show
  1. package/README.md +63 -33
  2. package/dist/admin.d.mts +19 -7
  3. package/dist/admin.d.mts.map +1 -1
  4. package/dist/admin.mjs +229 -16
  5. package/dist/admin.mjs.map +1 -1
  6. package/dist/block-library.d.mts +1 -1
  7. package/dist/block-library.mjs +1 -1
  8. package/dist/{block-thumbnails-DXOUzGjY.mjs → block-thumbnails-DC34uFtE.mjs} +1 -1
  9. package/dist/{block-thumbnails-DXOUzGjY.mjs.map → block-thumbnails-DC34uFtE.mjs.map} +1 -1
  10. package/dist/block-thumbnails-cli.mjs +1 -1
  11. package/dist/block-thumbnails.mjs +1 -1
  12. package/dist/capability-CqdYCzG1.d.mts +434 -0
  13. package/dist/capability-CqdYCzG1.d.mts.map +1 -0
  14. package/dist/capability-DHPE2kon.mjs +2685 -0
  15. package/dist/capability-DHPE2kon.mjs.map +1 -0
  16. package/dist/{catalogue-FxH10X3v.d.mts → catalogue-DWqHWVE5.d.mts} +1 -1
  17. package/dist/{catalogue-FxH10X3v.d.mts.map → catalogue-DWqHWVE5.d.mts.map} +1 -1
  18. package/dist/{facet-field-DjaZ0C7D.d.mts → facet-field-2K22iuWA.d.mts} +1 -1
  19. package/dist/{facet-field-DjaZ0C7D.d.mts.map → facet-field-2K22iuWA.d.mts.map} +1 -1
  20. package/dist/{facet-field-Uf8S4yL1.mjs → facet-field-DO3VT_Cz.mjs} +1 -1
  21. package/dist/{facet-field-Uf8S4yL1.mjs.map → facet-field-DO3VT_Cz.mjs.map} +1 -1
  22. package/dist/index.d.mts +13 -7
  23. package/dist/index.d.mts.map +1 -1
  24. package/dist/index.mjs +25 -667
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/{locale-CFWfB4wP.mjs → locale-B6rUVwpg.mjs} +1 -1
  27. package/dist/locale-B6rUVwpg.mjs.map +1 -0
  28. package/dist/{locale-CWiIcGuU.d.mts → locale-CTT3nn6T.d.mts} +5 -4
  29. package/dist/locale-CTT3nn6T.d.mts.map +1 -0
  30. package/dist/messages-dZV_aAnR.mjs +93 -0
  31. package/dist/messages-dZV_aAnR.mjs.map +1 -0
  32. package/dist/metadata.d.mts +1 -1
  33. package/dist/navigation.d.mts +2 -2
  34. package/dist/navigation.mjs +1 -1
  35. package/dist/og.d.mts +2 -2
  36. package/dist/og.mjs +1 -1
  37. package/dist/{preview-CNBVfmM7.d.mts → preview-1vwxBgm5.d.mts} +2 -2
  38. package/dist/{preview-CNBVfmM7.d.mts.map → preview-1vwxBgm5.d.mts.map} +1 -1
  39. package/dist/{published-_1rrTj_B.d.mts → published-B3etM6X5.d.mts} +3 -3
  40. package/dist/{published-_1rrTj_B.d.mts.map → published-B3etM6X5.d.mts.map} +1 -1
  41. package/dist/{published-D3yVnbxs.mjs → published-BMt7Z5CF.mjs} +2 -2
  42. package/dist/{published-D3yVnbxs.mjs.map → published-BMt7Z5CF.mjs.map} +1 -1
  43. package/dist/{published-DefZv9na.mjs → published-CkqqY08H.mjs} +2 -2
  44. package/dist/{published-DefZv9na.mjs.map → published-CkqqY08H.mjs.map} +1 -1
  45. package/dist/{published-DXjnElZn.d.mts → published-QDNmDi02.d.mts} +2 -2
  46. package/dist/{published-DXjnElZn.d.mts.map → published-QDNmDi02.d.mts.map} +1 -1
  47. package/dist/{published-QyTcDznE.mjs → published-hqtvmVUD.mjs} +1 -1
  48. package/dist/{published-QyTcDznE.mjs.map → published-hqtvmVUD.mjs.map} +1 -1
  49. package/dist/{root-page-key-B86JwL8Z.mjs → root-page-key-kx3C1eyp.mjs} +1 -1
  50. package/dist/{root-page-key-B86JwL8Z.mjs.map → root-page-key-kx3C1eyp.mjs.map} +1 -1
  51. package/dist/seo.mjs +1 -1
  52. package/dist/{messages-Fl1spIwN.mjs → strings-Fd7kUCT7.mjs} +156 -118
  53. package/dist/strings-Fd7kUCT7.mjs.map +1 -0
  54. package/dist/taxonomy.d.mts +1 -1
  55. package/dist/taxonomy.mjs +1 -1
  56. package/dist/theme.d.mts +4 -4
  57. package/dist/theme.mjs +1 -1
  58. package/dist/{title-D_jixG36.d.mts → title-trhUexxM.d.mts} +1 -1
  59. package/dist/{title-D_jixG36.d.mts.map → title-trhUexxM.d.mts.map} +1 -1
  60. package/dist/translate-messages-cli.mjs +3 -2
  61. package/dist/translate-messages-cli.mjs.map +1 -1
  62. package/dist/translate.d.mts +300 -206
  63. package/dist/translate.d.mts.map +1 -1
  64. package/dist/translate.mjs +225 -1027
  65. package/dist/translate.mjs.map +1 -1
  66. package/dist/{types-Db6Iy3hJ.d.mts → types-DLBlHZUd.d.mts} +1 -1
  67. package/dist/{types-Db6Iy3hJ.d.mts.map → types-DLBlHZUd.d.mts.map} +1 -1
  68. package/dist/{wireframe-xcJNJzBf.mjs → wireframe-CXorKFU_.mjs} +1 -1
  69. package/dist/{wireframe-xcJNJzBf.mjs.map → wireframe-CXorKFU_.mjs.map} +1 -1
  70. package/dist/wireframe-cli.mjs +1 -1
  71. package/dist/wireframe.mjs +1 -1
  72. package/package.json +6 -8
  73. package/dist/locale-CFWfB4wP.mjs.map +0 -1
  74. package/dist/locale-CWiIcGuU.d.mts.map +0 -1
  75. package/dist/messages-Fl1spIwN.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { A as PACKAGE_BLOCK_SLUGS, C as BlockLibraryDoc, D as BlockLibraryKind, O as BlockLibraryRow, T as BlockLibraryEntry, _ as SectionControls, a as sectionControlsFromLibrary, c as BlockLibraryReader, d as DEFAULT_SECTION_CONTROLS, f as HERO_SECTION_CONTROLS, g as SectionControlKey, h as SECTION_CONTROL_LABELS, i as defaultBlockLibraryValue, j as PackageBlockSlug, l as blockLibraryEntriesFromConfig, m as SECTION_CONTROL_KEYS, n as BlockLibraryOptions, o as stampBlockLibrary, p as NO_SECTION_CONTROLS, r as blockLibraryCatalogue, s as validateBlockLibrary, t as BlockLibraryCheck, u as getSectionControls, v as defaultSectionControls, x as BLOCK_LIBRARY_SLUG, y as sectionControlsOf } from "./catalogue-FxH10X3v.mjs";
1
+ import { A as PACKAGE_BLOCK_SLUGS, C as BlockLibraryDoc, D as BlockLibraryKind, O as BlockLibraryRow, T as BlockLibraryEntry, _ as SectionControls, a as sectionControlsFromLibrary, c as BlockLibraryReader, d as DEFAULT_SECTION_CONTROLS, f as HERO_SECTION_CONTROLS, g as SectionControlKey, h as SECTION_CONTROL_LABELS, i as defaultBlockLibraryValue, j as PackageBlockSlug, l as blockLibraryEntriesFromConfig, m as SECTION_CONTROL_KEYS, n as BlockLibraryOptions, o as stampBlockLibrary, p as NO_SECTION_CONTROLS, r as blockLibraryCatalogue, s as validateBlockLibrary, t as BlockLibraryCheck, u as getSectionControls, v as defaultSectionControls, x as BLOCK_LIBRARY_SLUG, y as sectionControlsOf } from "./catalogue-DWqHWVE5.mjs";
2
2
 
3
3
  //#region src/block-library/island.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { _ as sectionControlsOf, a as sectionControlsFromLibrary, d as DEFAULT_SECTION_CONTROLS, f as HERO_SECTION_CONTROLS, g as defaultSectionControls, h as SECTION_CONTROL_LABELS, i as defaultBlockLibraryValue, l as BLOCK_LIBRARY_SLUG, m as SECTION_CONTROL_KEYS, n as getSectionControls, o as stampBlockLibrary, p as NO_SECTION_CONTROLS, r as blockLibraryCatalogue, s as validateBlockLibrary, t as blockLibraryEntriesFromConfig, u as PACKAGE_BLOCK_SLUGS } from "./published-QyTcDznE.mjs";
1
+ import { _ as sectionControlsOf, a as sectionControlsFromLibrary, d as DEFAULT_SECTION_CONTROLS, f as HERO_SECTION_CONTROLS, g as defaultSectionControls, h as SECTION_CONTROL_LABELS, i as defaultBlockLibraryValue, l as BLOCK_LIBRARY_SLUG, m as SECTION_CONTROL_KEYS, n as getSectionControls, o as stampBlockLibrary, p as NO_SECTION_CONTROLS, r as blockLibraryCatalogue, s as validateBlockLibrary, t as blockLibraryEntriesFromConfig, u as PACKAGE_BLOCK_SLUGS } from "./published-hqtvmVUD.mjs";
2
2
  //#region src/block-library/island.ts
3
3
  /**
4
4
  * How a Block library island tells its card how tall it is (BIS-147).
@@ -127,4 +127,4 @@ function thumbnailVersion(data) {
127
127
  //#endregion
128
128
  export { THUMBNAIL_VIEWPORT as a, thumbnailCss as c, THUMBNAIL_SCALE as i, thumbnailVersion as l, THUMBNAIL_HEIGHT as n, THUMBNAIL_WIDTH as o, THUMBNAIL_ROOT as r, captureThumbnails as s, NEUTRAL_THEME as t };
129
129
 
130
- //# sourceMappingURL=block-thumbnails-DXOUzGjY.mjs.map
130
+ //# sourceMappingURL=block-thumbnails-DC34uFtE.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"block-thumbnails-DXOUzGjY.mjs","names":[],"sources":["../src/block-thumbnails.ts"],"sourcesContent":["/**\n * Screenshots of Block library samples for Payload's Add Block drawer\n * (`admin.images.thumbnail`). React-free and Payload-free: a script drives\n * a browser to each block's preview (`previewPath(slug)`), lays a neutral\n * theme over the site's, and captures the block as a 3:2 JPEG. The samples\n * carry generic copy and photos (`@bison-lab/payload-blocks`), so the card\n * reads as no particular site or industry. Rerun it when a block's layout\n * or sample changes.\n */\nimport { buildThemeCss, type ThemeConfig } from \"@bison-lab/tokens\";\n\n/** Payload's drawer card is 3:2. */\nexport const THUMBNAIL_WIDTH = 960;\nexport const THUMBNAIL_HEIGHT = 640;\n\n/** Desktop width, so the picture is the layout most visitors see; scaled down to 960. */\nexport const THUMBNAIL_VIEWPORT = { width: 1280, height: 900 } as const;\nexport const THUMBNAIL_SCALE = THUMBNAIL_WIDTH / THUMBNAIL_VIEWPORT.width;\n\n/** The element the Block library preview wraps each sample in (`BlockLibraryIsland`). */\nexport const THUMBNAIL_ROOT = \"[data-block-library-island]\";\n\n/**\n * Slate greys with a slate primary: no site's brand, and a contrast every\n * block was designed to read in. Fonts are the system stack (below), so no\n * font file has to be served for the capture.\n */\nexport const NEUTRAL_THEME: ThemeConfig = {\n brandPrimary: \"#334155\",\n brandSecondary: \"#64748b\",\n brandAccent: \"#475569\",\n brandHighlight: \"#94a3b8\",\n brandSuccess: \"#3f6212\",\n greyScale: \"slate\",\n defaultTheme: \"light\",\n radius: \"subtle\",\n shadow: \"subtle\",\n motion: \"minimal\",\n density: \"default\",\n fontBody: \"Inter\",\n fontHeading: null,\n fontWeights: { normal: 400, medium: 500, semibold: 600, bold: 700 },\n};\n\nconst SYSTEM_FONTS = 'ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif';\n\n/**\n * The stylesheet a capture adds to the preview: the neutral theme's tokens\n * (light, whatever the viewer's setting), the system font stack, no motion,\n * and the island as a column that centers its block, so a short band sits in\n * the middle of the card (`islandClip` sets the 3:2 height).\n */\nexport function thumbnailCss(selector = THUMBNAIL_ROOT): string {\n return [\n buildThemeCss(NEUTRAL_THEME, { attribute: \"data-theme\" }),\n `:root,[data-theme]{--font-body:${SYSTEM_FONTS};--font-heading:${SYSTEM_FONTS};color-scheme:light}`,\n `*,*::before,*::after{transition:none!important;animation:none!important;caret-color:transparent!important}`,\n // Dev-server chrome (Next's dev tools badge) is not part of the block.\n `nextjs-portal,[data-nextjs-toast],[data-next-badge-root]{display:none!important}`,\n `${selector}{box-sizing:border-box;display:flex!important;flex-direction:column;justify-content:center}`,\n ].join(\"\\n\");\n}\n\n/** The slice of Playwright's `Page` this needs; a site passes its own. */\nexport interface ThumbnailPage {\n goto(\n url: string,\n options?: { waitUntil?: \"load\" | \"domcontentloaded\" | \"networkidle\" },\n ): Promise<{ status(): number } | null | void>;\n evaluate<R, A>(fn: (arg: A) => R | Promise<R>, arg: A): Promise<R>;\n addStyleTag(options: { content: string }): Promise<unknown>;\n waitForTimeout(ms: number): Promise<void>;\n screenshot(options: {\n clip: { x: number; y: number; width: number; height: number };\n type: \"jpeg\";\n quality: number;\n scale: \"device\";\n }): Promise<Buffer | Uint8Array>;\n}\n\n/**\n * The box a capture takes: the island's top, its full width, 3:2. The\n * island is held at least that tall first, so a short block is centered in\n * the card and a tall one keeps its top. Runs in the page, so it closes over\n * nothing.\n */\nfunction islandClip(selector: string): { x: number; y: number; width: number; height: number } | null {\n const island = document.querySelector<HTMLElement>(selector);\n if (!island) return null;\n const width = Math.round(island.getBoundingClientRect().width);\n const height = Math.round((width * 2) / 3);\n island.style.minHeight = `${height}px`;\n const rect = island.getBoundingClientRect();\n return { x: Math.round(rect.left + window.scrollX), y: Math.round(rect.top + window.scrollY), width, height };\n}\n\n/**\n * Opens each preview, forces the light neutral theme, waits for its fonts\n * and images, and returns one JPEG per slug. The page's context should use\n * `THUMBNAIL_VIEWPORT` and `deviceScaleFactor: THUMBNAIL_SCALE`, so the\n * file comes out at 960 × 640. A preview that answers 400 or more, or\n * renders nothing `selector` matches, throws: nothing is written for a page\n * that did not draw its sample.\n */\nexport async function captureThumbnails(\n page: ThumbnailPage,\n previews: readonly { slug: string; url: string }[],\n { selector = THUMBNAIL_ROOT, quality = 68 }: { selector?: string; quality?: number } = {},\n): Promise<Record<string, Uint8Array>> {\n const out: Record<string, Uint8Array> = {};\n for (const { slug, url } of previews) {\n const response = await page.goto(url, { waitUntil: \"networkidle\" });\n const status = response ? response.status() : 200;\n if (status >= 400) throw new Error(`${slug}: ${url} answered ${status}; is the server up, the slug right, and the login one the route accepts?`);\n await page.evaluate(() => {\n document.documentElement.setAttribute(\"data-theme\", \"light\");\n document.documentElement.classList.remove(\"dark\");\n }, undefined);\n await page.addStyleTag({ content: thumbnailCss(selector) });\n await page.evaluate(\n () =>\n Promise.all([\n document.fonts.ready,\n ...Array.from(document.images).map((image) => (image.complete ? null : image.decode().catch(() => null))),\n ]).then(() => undefined),\n undefined,\n );\n await page.waitForTimeout(400);\n const clip = await page.evaluate(islandClip, selector);\n if (!clip) throw new Error(`${slug}: ${url} has no ${selector}; it did not render the sample`);\n out[slug] = new Uint8Array(await page.screenshot({ clip, type: \"jpeg\", quality, scale: \"device\" }));\n }\n return out;\n}\n\n/** A short, stable hash for a thumbnail's cache-busting `?v=`. */\nexport function thumbnailVersion(data: string | Uint8Array): string {\n let hash = 0x811c9dc5;\n const bytes = typeof data === \"string\" ? new TextEncoder().encode(data) : data;\n for (const byte of bytes) {\n hash ^= byte;\n hash = Math.imul(hash, 0x01000193) >>> 0;\n }\n return hash.toString(36);\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,kBAAkB;AAC/B,MAAa,mBAAmB;;AAGhC,MAAa,qBAAqB;CAAE,OAAO;CAAM,QAAQ;CAAK;AAC9D,MAAa,kBAAA,MAAoC,mBAAmB;;AAGpE,MAAa,iBAAiB;;;;;;AAO9B,MAAa,gBAA6B;CACxC,cAAc;CACd,gBAAgB;CAChB,aAAa;CACb,gBAAgB;CAChB,cAAc;CACd,WAAW;CACX,cAAc;CACd,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,UAAU;CACV,aAAa;CACb,aAAa;EAAE,QAAQ;EAAK,QAAQ;EAAK,UAAU;EAAK,MAAM;EAAK;CACpE;AAED,MAAM,eAAe;;;;;;;AAQrB,SAAgB,aAAa,WAAW,gBAAwB;AAC9D,QAAO;EACL,cAAc,eAAe,EAAE,WAAW,cAAc,CAAC;EACzD,kCAAkC,aAAa,kBAAkB,aAAa;EAC9E;EAEA;EACA,GAAG,SAAS;EACb,CAAC,KAAK,KAAK;;;;;;;;AA0Bd,SAAS,WAAW,UAAkF;CACpG,MAAM,SAAS,SAAS,cAA2B,SAAS;AAC5D,KAAI,CAAC,OAAQ,QAAO;CACpB,MAAM,QAAQ,KAAK,MAAM,OAAO,uBAAuB,CAAC,MAAM;CAC9D,MAAM,SAAS,KAAK,MAAO,QAAQ,IAAK,EAAE;AAC1C,QAAO,MAAM,YAAY,GAAG,OAAO;CACnC,MAAM,OAAO,OAAO,uBAAuB;AAC3C,QAAO;EAAE,GAAG,KAAK,MAAM,KAAK,OAAO,OAAO,QAAQ;EAAE,GAAG,KAAK,MAAM,KAAK,MA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B,UAAQ;AACR,SAAO,KAAK,KAAK,MAAM,SAAW,KAAK;;AAEzC,QAAO,KAAK,SAAS,GAAG"}
1
+ {"version":3,"file":"block-thumbnails-DC34uFtE.mjs","names":[],"sources":["../src/block-thumbnails.ts"],"sourcesContent":["/**\n * Screenshots of Block library samples for Payload's Add Block drawer\n * (`admin.images.thumbnail`). React-free and Payload-free: a script drives\n * a browser to each block's preview (`previewPath(slug)`), lays a neutral\n * theme over the site's, and captures the block as a 3:2 JPEG. The samples\n * carry generic copy and photos (`@bison-lab/payload-blocks`), so the card\n * reads as no particular site or industry. Rerun it when a block's layout\n * or sample changes.\n */\nimport { buildThemeCss, type ThemeConfig } from \"@bison-lab/tokens\";\n\n/** Payload's drawer card is 3:2. */\nexport const THUMBNAIL_WIDTH = 960;\nexport const THUMBNAIL_HEIGHT = 640;\n\n/** Desktop width, so the picture is the layout most visitors see; scaled down to 960. */\nexport const THUMBNAIL_VIEWPORT = { width: 1280, height: 900 } as const;\nexport const THUMBNAIL_SCALE = THUMBNAIL_WIDTH / THUMBNAIL_VIEWPORT.width;\n\n/** The element the Block library preview wraps each sample in (`BlockLibraryIsland`). */\nexport const THUMBNAIL_ROOT = \"[data-block-library-island]\";\n\n/**\n * Slate greys with a slate primary: no site's brand, and a contrast every\n * block was designed to read in. Fonts are the system stack (below), so no\n * font file has to be served for the capture.\n */\nexport const NEUTRAL_THEME: ThemeConfig = {\n brandPrimary: \"#334155\",\n brandSecondary: \"#64748b\",\n brandAccent: \"#475569\",\n brandHighlight: \"#94a3b8\",\n brandSuccess: \"#3f6212\",\n greyScale: \"slate\",\n defaultTheme: \"light\",\n radius: \"subtle\",\n shadow: \"subtle\",\n motion: \"minimal\",\n density: \"default\",\n fontBody: \"Inter\",\n fontHeading: null,\n fontWeights: { normal: 400, medium: 500, semibold: 600, bold: 700 },\n};\n\nconst SYSTEM_FONTS = 'ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif';\n\n/**\n * The stylesheet a capture adds to the preview: the neutral theme's tokens\n * (light, whatever the viewer's setting), the system font stack, no motion,\n * and the island as a column that centers its block, so a short band sits in\n * the middle of the card (`islandClip` sets the 3:2 height).\n */\nexport function thumbnailCss(selector = THUMBNAIL_ROOT): string {\n return [\n buildThemeCss(NEUTRAL_THEME, { attribute: \"data-theme\" }),\n `:root,[data-theme]{--font-body:${SYSTEM_FONTS};--font-heading:${SYSTEM_FONTS};color-scheme:light}`,\n `*,*::before,*::after{transition:none!important;animation:none!important;caret-color:transparent!important}`,\n // Dev-server chrome (Next's dev tools badge) is not part of the block.\n `nextjs-portal,[data-nextjs-toast],[data-next-badge-root]{display:none!important}`,\n `${selector}{box-sizing:border-box;display:flex!important;flex-direction:column;justify-content:center}`,\n ].join(\"\\n\");\n}\n\n/** The slice of Playwright's `Page` this needs; a site passes its own. */\nexport interface ThumbnailPage {\n goto(\n url: string,\n options?: { waitUntil?: \"load\" | \"domcontentloaded\" | \"networkidle\" },\n ): Promise<{ status(): number } | null | void>;\n evaluate<R, A>(fn: (arg: A) => R | Promise<R>, arg: A): Promise<R>;\n addStyleTag(options: { content: string }): Promise<unknown>;\n waitForTimeout(ms: number): Promise<void>;\n screenshot(options: {\n clip: { x: number; y: number; width: number; height: number };\n type: \"jpeg\";\n quality: number;\n scale: \"device\";\n }): Promise<Buffer | Uint8Array>;\n}\n\n/**\n * The box a capture takes: the island's top, its full width, 3:2. The\n * island is held at least that tall first, so a short block is centered in\n * the card and a tall one keeps its top. Runs in the page, so it closes over\n * nothing.\n */\nfunction islandClip(selector: string): { x: number; y: number; width: number; height: number } | null {\n const island = document.querySelector<HTMLElement>(selector);\n if (!island) return null;\n const width = Math.round(island.getBoundingClientRect().width);\n const height = Math.round((width * 2) / 3);\n island.style.minHeight = `${height}px`;\n const rect = island.getBoundingClientRect();\n return { x: Math.round(rect.left + window.scrollX), y: Math.round(rect.top + window.scrollY), width, height };\n}\n\n/**\n * Opens each preview, forces the light neutral theme, waits for its fonts\n * and images, and returns one JPEG per slug. The page's context should use\n * `THUMBNAIL_VIEWPORT` and `deviceScaleFactor: THUMBNAIL_SCALE`, so the\n * file comes out at 960 × 640. A preview that answers 400 or more, or\n * renders nothing `selector` matches, throws: nothing is written for a page\n * that did not draw its sample.\n */\nexport async function captureThumbnails(\n page: ThumbnailPage,\n previews: readonly { slug: string; url: string }[],\n { selector = THUMBNAIL_ROOT, quality = 68 }: { selector?: string; quality?: number } = {},\n): Promise<Record<string, Uint8Array>> {\n const out: Record<string, Uint8Array> = {};\n for (const { slug, url } of previews) {\n const response = await page.goto(url, { waitUntil: \"networkidle\" });\n const status = response ? response.status() : 200;\n if (status >= 400) throw new Error(`${slug}: ${url} answered ${status}; is the server up, the slug right, and the login one the route accepts?`);\n await page.evaluate(() => {\n document.documentElement.setAttribute(\"data-theme\", \"light\");\n document.documentElement.classList.remove(\"dark\");\n }, undefined);\n await page.addStyleTag({ content: thumbnailCss(selector) });\n await page.evaluate(\n () =>\n Promise.all([\n document.fonts.ready,\n ...Array.from(document.images).map((image) => (image.complete ? null : image.decode().catch(() => null))),\n ]).then(() => undefined),\n undefined,\n );\n await page.waitForTimeout(400);\n const clip = await page.evaluate(islandClip, selector);\n if (!clip) throw new Error(`${slug}: ${url} has no ${selector}; it did not render the sample`);\n out[slug] = new Uint8Array(await page.screenshot({ clip, type: \"jpeg\", quality, scale: \"device\" }));\n }\n return out;\n}\n\n/** A short, stable hash for a thumbnail's cache-busting `?v=`. */\nexport function thumbnailVersion(data: string | Uint8Array): string {\n let hash = 0x811c9dc5;\n const bytes = typeof data === \"string\" ? new TextEncoder().encode(data) : data;\n for (const byte of bytes) {\n hash ^= byte;\n hash = Math.imul(hash, 0x01000193) >>> 0;\n }\n return hash.toString(36);\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,kBAAkB;AAC/B,MAAa,mBAAmB;;AAGhC,MAAa,qBAAqB;CAAE,OAAO;CAAM,QAAQ;CAAK;AAC9D,MAAa,kBAAA,M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I,IAAI,YAAY,OAAO,0EAA0E;AAChJ,QAAM,KAAK,eAAe;AACxB,YAAS,gBAAgB,aAAa,cAAc,QAAQ;AAC5D,YAAS,gBAAgB,UAAU,OAAO,OAAO;KAChD,KAAA,EAAU;AACb,QAAM,KAAK,YAAY,EAAE,SAAS,aAAa,SAAS,EAAE,CAAC;AAC3D,QAAM,KAAK,eAEP,QAAQ,IAAI,CACV,SAAS,MAAM,OACf,GAAG,MAAM,KAAK,SAAS,OAAO,CAAC,KAAK,UAAW,MAAM,WAAW,OAAO,MAAM,QAAQ,CAAC,YAAY,KAAK,CAAE,CAC1G,CAAC,CAAC,WAAW,KAAA,EAAU,EAC1B,KAAA,EACD;AACD,QAAM,KAAK,eAAe,IAAI;EAC9B,MAAM,OAAO,MAAM,KAAK,SAAS,YAAY,SAAS;AACtD,MAAI,CAAC,KAAM,OAAM,IAAI,MAAM,GAAG,KAAK,IAAI,IAAI,UAAU,SAAS,gCAAgC;AAC9F,MAAI,QAAQ,IAAI,WAAW,MAAM,KAAK,WAAW;GAAE;GAAM,MAAM;GAAQ;GAAS,OAAO;GAAU,CAAC,CAAC;;AAErG,QAAO;;;AAIT,SAAgB,iBAAiB,MAAmC;CAClE,IAAI,OAAO;CACX,MAAM,QAAQ,OAAO,SAAS,WAAW,IAAI,aAAa,CAAC,OAAO,KAAK,GAAG;AAC1E,MAAK,MAAM,QAAQ,OAAO;AACxB,UAAQ;AACR,SAAO,KAAK,KAAK,MAAM,SAAW,KAAK;;AAEzC,QAAO,KAAK,SAAS,GAAG"}
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as THUMBNAIL_VIEWPORT, i as THUMBNAIL_SCALE, s as captureThumbnails } from "./block-thumbnails-DXOUzGjY.mjs";
2
+ import { a as THUMBNAIL_VIEWPORT, i as THUMBNAIL_SCALE, s as captureThumbnails } from "./block-thumbnails-DC34uFtE.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { mkdirSync, writeFileSync } from "node:fs";
5
5
  import { dirname, join, resolve } from "node:path";
@@ -1,2 +1,2 @@
1
- import { a as THUMBNAIL_VIEWPORT, c as thumbnailCss, i as THUMBNAIL_SCALE, l as thumbnailVersion, n as THUMBNAIL_HEIGHT, o as THUMBNAIL_WIDTH, r as THUMBNAIL_ROOT, s as captureThumbnails, t as NEUTRAL_THEME } from "./block-thumbnails-DXOUzGjY.mjs";
1
+ import { a as THUMBNAIL_VIEWPORT, c as thumbnailCss, i as THUMBNAIL_SCALE, l as thumbnailVersion, n as THUMBNAIL_HEIGHT, o as THUMBNAIL_WIDTH, r as THUMBNAIL_ROOT, s as captureThumbnails, t as NEUTRAL_THEME } from "./block-thumbnails-DC34uFtE.mjs";
2
2
  export { NEUTRAL_THEME, THUMBNAIL_HEIGHT, THUMBNAIL_ROOT, THUMBNAIL_SCALE, THUMBNAIL_VIEWPORT, THUMBNAIL_WIDTH, captureThumbnails, thumbnailCss, thumbnailVersion };
@@ -0,0 +1,434 @@
1
+ import { Block, Config, Endpoint, Field, GlobalConfig, Payload } from "payload";
2
+
3
+ //#region src/translate/errors.d.ts
4
+ /**
5
+ * Why a translation call failed, in the terms an Admin can act on.
6
+ *
7
+ * - `out-of-credit`: the Anthropic account has no credit or a billing
8
+ * problem (402 `billing_error`, or the older 400 "credit balance is too
9
+ * low").
10
+ * - `key-rejected`: the key is wrong, revoked or lacks permission (401, 403).
11
+ * - `rate-limited`: 429, after the SDK's own retry.
12
+ * - `unreachable`: no answer, a timeout, or a 5xx / 529 from Anthropic.
13
+ * - `other`: anything else (a malformed reply, a refusal).
14
+ */
15
+ type TranslationFailureKind = "out-of-credit" | "key-rejected" | "rate-limited" | "unreachable" | "other";
16
+ /** Sorts an error thrown by the Anthropic SDK (or a network failure) into a `TranslationFailureKind`. */
17
+ declare function classifyAnthropicError(error: unknown): TranslationFailureKind;
18
+ //#endregion
19
+ //#region src/translate/types.d.ts
20
+ /** A document as one locale's depth-0 read returns it. */
21
+ type Doc = Record<string, unknown>;
22
+ /** Why a translation write happened. */
23
+ type BisonTranslationKind = "auto" | "backfill" | "frozen-fix" | "manual";
24
+ /**
25
+ * Set as `context.bisonTranslation` (so `req.context.bisonTranslation` in
26
+ * every hook) on each write the library makes to land a translation, and on
27
+ * no other write. `locale` is the target locale, the write's own `locale`,
28
+ * never the default locale. A site's hooks read it to let a translation
29
+ * through a rule meant for people (a publish gate), and nothing else should
30
+ * set it.
31
+ *
32
+ * - `auto`: a save or publish filled or re-translated copy.
33
+ * - `backfill`: a background job filling blank copy.
34
+ * - `frozen-fix`: a background job re-translating strings that dropped a frozen word.
35
+ * - `manual`: "Translate now", or a script calling `translateDocument`.
36
+ */
37
+ interface BisonTranslationMarker {
38
+ locale: string;
39
+ kind: BisonTranslationKind;
40
+ }
41
+ /** The `context` key that carries a `BisonTranslationMarker`. */
42
+ declare const BISON_TRANSLATION_CONTEXT = "bisonTranslation";
43
+ /**
44
+ * What a site tells the model about itself. The library owns the generic
45
+ * rules (JSON in and out, placeholders, tags, URLs, literal legal copy);
46
+ * these are the facts only a site has.
47
+ */
48
+ interface TranslateSite {
49
+ /** The brand name, kept verbatim. Optional: a site may give only frozen words or a voice. */
50
+ name?: string;
51
+ /** One line on what the site is, for word choice ("a gigabit fiber provider in Kansas"). */
52
+ about?: string;
53
+ /** The voice to keep ("confident, friendly, speed-first"). */
54
+ voice?: string;
55
+ /** Brand, product and place names the model must never translate. */
56
+ keepVerbatim?: string[];
57
+ /**
58
+ * How to name a locale's language in the prompt, per locale code
59
+ * (`{ es: "Latin American Spanish" }`). A code left out is named by
60
+ * `Intl.DisplayNames`.
61
+ */
62
+ languages?: Record<string, string>;
63
+ }
64
+ /** One translation call: from which locale, into which, and where the strings appear. */
65
+ interface TranslateRequest {
66
+ from: string;
67
+ to: string;
68
+ /** A short hint about where the strings appear, to improve word choice. */
69
+ context?: string;
70
+ /** The plugin's `site`, when it was given one. */
71
+ site?: TranslateSite;
72
+ }
73
+ /**
74
+ * Translates a batch of strings, returning them in the same order and the
75
+ * same length, or `null` on any failure. It never throws on purpose; a
76
+ * throw is caught and read as `null`.
77
+ *
78
+ * `configured: false` says the translator cannot run (no API key): the
79
+ * plugin then logs a warning on publish instead of deferring work, and
80
+ * hides "Translate now". Leave it unset on a translator that always runs.
81
+ */
82
+ type Translator = ((strings: string[], request: TranslateRequest) => Promise<string[] | null>) & {
83
+ configured?: boolean;
84
+ };
85
+ /** A collection or global the plugin translates, by slug or with a prompt hint. */
86
+ type TranslatedEntity = string | {
87
+ slug: string; /** The prompt hint for one document, from its source-locale read (`Internet plan: Fiber 1000`). */
88
+ context?: (doc: Doc) => string;
89
+ };
90
+ interface AutoTranslateOptions {
91
+ /**
92
+ * The per-site switch. `false` registers nothing at all: no hooks,
93
+ * endpoints, admin components or config, the same config as leaving the
94
+ * plugin out.
95
+ */
96
+ enabled: boolean;
97
+ /** Collections whose source-locale publishes fill every other locale. */
98
+ collections?: TranslatedEntity[];
99
+ /** Globals whose source-locale publishes fill every other locale. */
100
+ globals?: TranslatedEntity[];
101
+ /**
102
+ * Replaces the translator Settings → Translation describes (its key and
103
+ * model). Leave it out to use the screen's; pass a fake in tests.
104
+ */
105
+ translator?: Translator;
106
+ /**
107
+ * Keeps the deferred translation alive after the response is sent, e.g.
108
+ * `waitUntil` from `@vercel/functions`. Off a serverless host leave it
109
+ * out; the work runs in the same process either way.
110
+ */
111
+ waitUntil?: (promise: Promise<unknown>) => void;
112
+ /** Site facts passed to the translator on every call (see `TranslateSite`). */
113
+ site?: TranslateSite;
114
+ }
115
+ /** What happened in one target locale. */
116
+ interface TranslateLocaleResult {
117
+ locale: string;
118
+ /** `nothing`: every string already in step; `failed`: the translator gave no usable result. */
119
+ status: "translated" | "nothing" | "failed";
120
+ /** Strings written. */
121
+ count: number;
122
+ }
123
+ //#endregion
124
+ //#region src/translate/anthropic.d.ts
125
+ /**
126
+ * The library's default model. Translating marketing copy does not need the
127
+ * most capable model; a current Sonnet handles it well at a fraction of the
128
+ * price. A site overrides it per environment (`ANTHROPIC_TRANSLATE_MODEL`).
129
+ */
130
+ declare const DEFAULT_TRANSLATE_MODEL = "claude-sonnet-5-5";
131
+ /** "Economy (Haiku)" on Settings → Translation: a fraction of Sonnet's price for plainer copy. */
132
+ declare const ECONOMY_TRANSLATE_MODEL = "claude-haiku-5-5";
133
+ /** USD per million tokens, for the cost estimates on Settings → Translation. */
134
+ interface ModelPrice {
135
+ input: number;
136
+ output: number;
137
+ }
138
+ /**
139
+ * Anthropic's list prices for the two models the screen offers. A model
140
+ * not listed (an `ANTHROPIC_TRANSLATE_MODEL` override) is estimated at
141
+ * Sonnet's price, so an estimate errs high rather than reading as free.
142
+ */
143
+ declare const TRANSLATE_MODEL_PRICES: Record<string, ModelPrice>;
144
+ declare function modelPrice(model: string): ModelPrice;
145
+ /** Estimated USD for one call's tokens on `model`. */
146
+ declare function estimateCost(model: string, inputTokens: number, outputTokens: number): number;
147
+ /** What one translator call did, for usage, cost and failure reporting. */
148
+ type TranslatorCallEvent = {
149
+ ok: true;
150
+ model: string;
151
+ strings: number;
152
+ inputTokens: number;
153
+ outputTokens: number;
154
+ } | {
155
+ ok: false;
156
+ model: string;
157
+ strings: number;
158
+ failure: TranslationFailureKind;
159
+ status?: number;
160
+ message: string;
161
+ };
162
+ /**
163
+ * True when `text` contains `word` as a whole word, case-sensitively: "ProtectIQ"
164
+ * is in "Get ProtectIQ today" but not in "protectiq" or "ProtectIQs". A
165
+ * frozen word is only kept where it appears this way.
166
+ */
167
+ declare function containsWord(text: string, word: string): boolean;
168
+ /** The slice of the Anthropic client this translator calls. */
169
+ interface AnthropicMessagesClient {
170
+ messages: {
171
+ create(body: Record<string, unknown>, options?: {
172
+ timeout?: number;
173
+ maxRetries?: number;
174
+ }): Promise<{
175
+ content: Array<{
176
+ type: string;
177
+ text?: string;
178
+ }>;
179
+ usage?: {
180
+ input_tokens?: number | null;
181
+ output_tokens?: number | null;
182
+ } | null;
183
+ }>;
184
+ };
185
+ }
186
+ interface AnthropicTranslatorOptions {
187
+ /**
188
+ * The API key, usually `process.env.ANTHROPIC_API_KEY`. Without one the
189
+ * translator reports `configured: false`: publishes still work, a
190
+ * warning is logged, and "Translate now" is hidden.
191
+ */
192
+ apiKey?: string | null;
193
+ /** The model id; omitted or blank uses `DEFAULT_TRANSLATE_MODEL`. */
194
+ model?: string | null;
195
+ /** The site facts the prompt carries. The plugin's own `site`, when given, wins. */
196
+ site?: TranslateSite;
197
+ /** A client to use instead of constructing one (tests, a proxied client). */
198
+ client?: AnthropicMessagesClient;
199
+ /**
200
+ * Called once per API call with its token usage, or with why it failed.
201
+ * Settings → Translation records usage and failures through it. A throw
202
+ * here is ignored.
203
+ */
204
+ onCall?: (event: TranslatorCallEvent) => void | Promise<void>;
205
+ }
206
+ /**
207
+ * The system prompt: the library's generic rules plus the site's own facts.
208
+ * Exported so a site can read exactly what the model is told.
209
+ */
210
+ declare function translationSystemPrompt(request: Pick<TranslateRequest, "from" | "to" | "site">): string;
211
+ /** Tolerant JSON-array parse: strips accidental ``` fences and prose around the array, and checks the shape. */
212
+ declare function parseJsonArray(text: string): string[] | null;
213
+ /**
214
+ * The provided `Translator`: one Anthropic Messages call per batch, the
215
+ * strings as a JSON array in and out. `@anthropic-ai/sdk` is a peer,
216
+ * imported on the first call, so a site that never translates never loads
217
+ * it. Every failure (no key, the SDK missing, a network error, a
218
+ * refusal, a malformed or wrong-length reply) returns `null` and is logged
219
+ * by the caller; it never throws.
220
+ */
221
+ declare function anthropicTranslator(options: AnthropicTranslatorOptions): Translator;
222
+ /** What a key check found. */
223
+ type KeyCheck = "valid" | "rejected" | "out-of-credit" | "unreachable";
224
+ /**
225
+ * Checks a key with the smallest call that proves both the key and the
226
+ * account's credit: one Haiku message with a few output tokens (a fraction
227
+ * of a cent). A 401 is `rejected`; a billing error `out-of-credit`; no
228
+ * answer, a 5xx or a rate limit `unreachable`, meaning "check again on
229
+ * first use". Never throws.
230
+ */
231
+ declare function verifyAnthropicKey(apiKey: string, options?: {
232
+ client?: AnthropicMessagesClient;
233
+ }): Promise<KeyCheck>;
234
+ //#endregion
235
+ //#region src/translate/key.d.ts
236
+ /** `v1:<iv>:<tag>:<ciphertext>`, base64 parts. */
237
+ declare function encryptApiKey(apiKey: string, secret: string): string;
238
+ /** The key, or `null` when the value is malformed or `secret` is not the one it was sealed with. */
239
+ declare function decryptApiKey(sealed: string, secret: string): string | null;
240
+ /** Where the key a translation would use comes from. */
241
+ type KeySource = "admin" | "environment";
242
+ interface ResolvedKey {
243
+ /** The key to call Anthropic with, or `undefined` when translation cannot run here. */
244
+ apiKey?: string;
245
+ source?: KeySource;
246
+ /** Last 4 characters of the key in use. */
247
+ last4?: string;
248
+ /** Why the stored key is not in use, in words for the screen. */
249
+ note?: string;
250
+ }
251
+ /**
252
+ * Which key a translation uses. Only on production (`VERCEL_ENV=production`)
253
+ * is the stored key considered, and there it wins over the environment's
254
+ * `ANTHROPIC_API_KEY`. Everywhere else (local, previews, a cloned database)
255
+ * only the environment key is used, so a copy of production's data never
256
+ * spends production's money. A stored key that cannot be decrypted reads
257
+ * as no key, with a note.
258
+ */
259
+ declare function resolveApiKey(input: {
260
+ sealed?: string | null;
261
+ secret: string;
262
+ env?: string | null;
263
+ production?: boolean;
264
+ }): ResolvedKey;
265
+ //#endregion
266
+ //#region src/translate/settings.d.ts
267
+ /** Settings → Translation: the switch, model, instructions and the key's public record. Versioned. */
268
+ declare const TRANSLATION_SETTINGS_SLUG = "translation-settings";
269
+ /**
270
+ * Server-only state beside it: the encrypted key and what the last check
271
+ * found. Unversioned and unreadable through the API, so the key is in no
272
+ * version row and no response.
273
+ */
274
+ declare const TRANSLATION_STATE_SLUG = "translation-state";
275
+ /** The Roles grant that opens Settings → Translation. Developer and Admin always hold it. */
276
+ declare const TRANSLATION_GRANT = "translation";
277
+ /** The admin component for the key panel on Settings → Translation. */
278
+ declare const TRANSLATION_KEY_PANEL = "@bison-lab/payload-core/admin#TranslationKeyPanel";
279
+ /** The model choice on the screen. */
280
+ type TranslationModelChoice = "quality" | "economy";
281
+ /** What the last key check found. `unchecked`: Anthropic did not answer; checked again on first use. */
282
+ type KeyStatus = "valid" | "out-of-credit" | "rejected" | "unchecked";
283
+ /** The saved Settings → Translation document, as this package reads it. Optional and nullable. */
284
+ interface TranslationSettingsDoc {
285
+ enabled?: boolean | null;
286
+ /** Ticked target languages. */
287
+ languages?: string[] | null;
288
+ /** Set by the server once someone has saved the ticks; until then the defaults apply. */
289
+ languagesChosen?: boolean | null;
290
+ model?: TranslationModelChoice | null;
291
+ keyLast4?: string | null;
292
+ keySetAt?: string | null;
293
+ keySetBy?: string | null;
294
+ keyChange?: string | null;
295
+ changedBy?: string | null;
296
+ instructions?: {
297
+ businessName?: string | null;
298
+ about?: string | null;
299
+ voice?: string | null;
300
+ dialects?: Array<{
301
+ locale?: string | null;
302
+ name?: string | null;
303
+ }> | null;
304
+ frozenWords?: Array<{
305
+ word?: string | null;
306
+ }> | null;
307
+ } | null;
308
+ updatedAt?: string | null;
309
+ }
310
+ interface TranslationStateDoc {
311
+ keyCipher?: string | null;
312
+ keyStatus?: KeyStatus | null;
313
+ keyCheckedAt?: string | null;
314
+ }
315
+ /** Settings → Translation, resolved for a translation run. */
316
+ interface ResolvedTranslationSettings {
317
+ enabled: boolean;
318
+ model: TranslationModelChoice;
319
+ /** The instructions the model gets: the saved ones once the screen was saved, else the site's code `site`. */
320
+ site?: TranslateSite;
321
+ /** True once the document has been saved. */
322
+ saved: boolean;
323
+ /** The ticked target languages, the only ones translated into. */
324
+ languages: string[];
325
+ doc: TranslationSettingsDoc;
326
+ state: TranslationStateDoc;
327
+ }
328
+ /**
329
+ * The model id for a choice. `ANTHROPIC_TRANSLATE_MODEL` overrides the
330
+ * screen off production, so a developer can try a model locally without
331
+ * touching the setting.
332
+ */
333
+ declare function resolveModel(choice: TranslationModelChoice | null | undefined, production: boolean): string;
334
+ /**
335
+ * The saved instructions as a `TranslateSite`, or `undefined` when every
336
+ * field is blank. A blank business name drops only the name: frozen words,
337
+ * voice and dialects still reach the model.
338
+ */
339
+ declare function siteFromInstructions(instructions: TranslationSettingsDoc["instructions"]): TranslateSite | undefined;
340
+ /** Drops the cached read, so the next one sees a save at once. */
341
+ declare function invalidateTranslationSettings(payload: object): void;
342
+ type ReadPayload = Pick<Payload, "findGlobal"> & {
343
+ config?: Pick<Payload["config"], "localization" | "custom">;
344
+ };
345
+ /**
346
+ * Settings → Translation and its server state, read once per
347
+ * `SETTINGS_CACHE_MS` per process. A missing Global (a site that has not
348
+ * migrated yet) reads as "off".
349
+ */
350
+ declare function readTranslationSettings(payload: ReadPayload, codeSite?: TranslateSite): Promise<ResolvedTranslationSettings>;
351
+ //#endregion
352
+ //#region src/translate/settings-endpoints.d.ts
353
+ /** What `GET /api/translation/status` answers: everything the key panel shows, never the key. */
354
+ interface TranslationStatus {
355
+ enabled: boolean;
356
+ production: boolean;
357
+ /** The stored key's public record. */
358
+ stored: {
359
+ last4: string;
360
+ setAt?: string | null;
361
+ setBy?: string | null;
362
+ status?: KeyStatus | null;
363
+ } | null;
364
+ /** The key a translation would use here, by source and last 4. */
365
+ inUse: {
366
+ source: "admin" | "environment";
367
+ last4: string;
368
+ } | null;
369
+ /** Why the stored key is not in use, when it is not. */
370
+ note?: string;
371
+ }
372
+ /** A test seam: replaces the Anthropic client the key check uses. */
373
+ interface TranslationEndpointOptions {
374
+ verifyClient?: AnthropicMessagesClient;
375
+ }
376
+ /**
377
+ * The key endpoints of Settings → Translation, all behind the `translation`
378
+ * grant:
379
+ *
380
+ * - `GET /api/translation/status`: what the key panel shows.
381
+ * - `POST /api/translation/key` `{ key }`: checks the key with one tiny call.
382
+ * A 401 refuses it and keeps the previous key. Out of credit saves it
383
+ * (switching on is then refused). No answer saves it as unchecked.
384
+ * - `POST /api/translation/key/check`: checks the stored key again.
385
+ * - `DELETE /api/translation/key`: removes the stored key.
386
+ */
387
+ declare function translationSettingsEndpoints(options?: TranslationEndpointOptions): Endpoint[];
388
+ //#endregion
389
+ //#region src/translate/capability.d.ts
390
+ /**
391
+ * A collection's or global's own hint for the model, set in its config:
392
+ * `custom: { bisonTranslation: { context: (doc) => "Internet plan: " + doc.name } }`.
393
+ * `doc` is its source-locale read at depth 0.
394
+ */
395
+ interface TranslationEntityHint {
396
+ context?: (doc: Doc) => string;
397
+ }
398
+ /** What a site may pass; every option is optional. */
399
+ interface TranslationOptions {
400
+ /** The site's facts: the instructions on Settings → Translation until an Admin saves the screen. */
401
+ site?: TranslateSite;
402
+ /** Keeps deferred work alive past the response. Defaults to Vercel's request context when there is one. */
403
+ waitUntil?: (promise: Promise<unknown>) => void;
404
+ /** Replaces the screen's translator (tests). The switch still governs it. */
405
+ translator?: Translator;
406
+ /** Prompt hints by collection or global slug, beside each entity's own `custom.bisonTranslation`. */
407
+ hints?: Record<string, TranslationEntityHint>;
408
+ /** Test seam for the key check's Anthropic client. */
409
+ endpoints?: TranslationEndpointOptions;
410
+ }
411
+ /** True when any field, at any depth, is localized: the entity has copy to translate. */
412
+ declare function hasLocalizedFields(fields: readonly Field[], blocks?: readonly Block[]): boolean;
413
+ /**
414
+ * Gives a config the translation capability: Settings → Translation (and
415
+ * its hidden state Global), the key endpoints, and on every collection and
416
+ * global with localized fields the save hook, plus "Translate now" on each
417
+ * collection. `adminNav()` applies it, so a site gets it with no line of
418
+ * its own; `translation()` is the same for a site without `adminNav()`.
419
+ *
420
+ * Safe to apply more than once: options merge (later wins), the Globals
421
+ * and endpoints are added once, and each entity is hooked once, so a second
422
+ * pass only picks up entities a later plugin registered.
423
+ *
424
+ * It also puts every library language (`LIBRARY_LOCALES`) into the
425
+ * config's `localization`, adding it when the site has none, so every site
426
+ * carries every language in its schema. A target language is translated
427
+ * and served only once it is ticked on the screen (`activeLocales`).
428
+ */
429
+ declare function applyTranslation(config: Config, options?: TranslationOptions): Config;
430
+ /** `applyTranslation` as a plugin, for a site that does not use `adminNav()`. */
431
+ declare function translation(options?: TranslationOptions): (config: Config) => Config;
432
+ //#endregion
433
+ export { ModelPrice as A, AutoTranslateOptions as B, encryptApiKey as C, DEFAULT_TRANSLATE_MODEL as D, AnthropicTranslatorOptions as E, estimateCost as F, TranslateLocaleResult as G, BisonTranslationKind as H, modelPrice as I, TranslatedEntity as J, TranslateRequest as K, parseJsonArray as L, TranslatorCallEvent as M, anthropicTranslator as N, ECONOMY_TRANSLATE_MODEL as O, containsWord as P, translationSystemPrompt as R, decryptApiKey as S, AnthropicMessagesClient as T, BisonTranslationMarker as U, BISON_TRANSLATION_CONTEXT as V, Doc as W, TranslationFailureKind as X, Translator as Y, classifyAnthropicError as Z, readTranslationSettings as _, translation as a, KeySource as b, KeyStatus as c, TRANSLATION_KEY_PANEL as d, TRANSLATION_SETTINGS_SLUG as f, invalidateTranslationSettings as g, TranslationSettingsDoc as h, hasLocalizedFields as i, TRANSLATE_MODEL_PRICES as j, KeyCheck as k, ResolvedTranslationSettings as l, TranslationModelChoice as m, TranslationOptions as n, TranslationStatus as o, TRANSLATION_STATE_SLUG as p, TranslateSite as q, applyTranslation as r, translationSettingsEndpoints as s, TranslationEntityHint as t, TRANSLATION_GRANT as u, resolveModel as v, resolveApiKey as w, ResolvedKey as x, siteFromInstructions as y, verifyAnthropicKey as z };
434
+ //# sourceMappingURL=capability-CqdYCzG1.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability-CqdYCzG1.d.mts","names":[],"sources":["../src/translate/errors.ts","../src/translate/types.ts","../src/translate/anthropic.ts","../src/translate/key.ts","../src/translate/settings.ts","../src/translate/settings-endpoints.ts","../src/translate/capability.ts"],"mappings":";;;;;;AAWA;;;;;AAWA;;;KAXY,sBAAA;;iBAWI,sBAAA,CAAuB,KAAA,YAAiB,sBAAA;;;;KCrB5C,GAAA,GAAM,MAAA;;KAGN,oBAAA;;;;;ADkBZ;;;;;;;;ACrBA;UAkBiB,sBAAA;EACf,MAAA;EACA,IAAA,EAAM,oBAAA;AAAA;AAjBR;AAAA,cAqBa,yBAAA;;;;AANb;;UAaiB,aAAA;EAXW;EAa1B,IAAA;E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