@cossackframework/cms 0.0.0-stage → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (427) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -2
  3. package/agent-docs.json +259 -0
  4. package/app/README.md +78 -0
  5. package/app/cossack-recipe.json +43 -0
  6. package/app/src/auth-bot-check.ts +32 -0
  7. package/app/src/auth-bot-token.ts +11 -0
  8. package/app/src/auth-input.ts +35 -0
  9. package/app/src/auth-options.ts +18 -0
  10. package/app/src/auth-providers.ts +16 -0
  11. package/app/src/auth.ts +1082 -0
  12. package/app/src/brand.ts +68 -0
  13. package/app/src/cms/ai.ts +54 -0
  14. package/app/src/cms/analytics.ts +33 -0
  15. package/app/src/cms/block-errors.ts +55 -0
  16. package/app/src/cms/block-inserter.ts +111 -0
  17. package/app/src/cms/block-panel.ts +68 -0
  18. package/app/src/cms/block-rows.ts +44 -0
  19. package/app/src/cms/block-tree.ts +585 -0
  20. package/app/src/cms/blocks.css +708 -0
  21. package/app/src/cms/builder.ts +126 -0
  22. package/app/src/cms/cache.ts +44 -0
  23. package/app/src/cms/carousel.client.ts +52 -0
  24. package/app/src/cms/collab/presence.ts +69 -0
  25. package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
  26. package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
  27. package/app/src/cms/collab/room.ts +881 -0
  28. package/app/src/cms/compare.client.ts +47 -0
  29. package/app/src/cms/condition-control.ts +109 -0
  30. package/app/src/cms/content-api.ts +143 -0
  31. package/app/src/cms/content.ts +524 -0
  32. package/app/src/cms/countdown.client.ts +37 -0
  33. package/app/src/cms/editor-layout-editor.ts +260 -0
  34. package/app/src/cms/editor-layout-view.ts +37 -0
  35. package/app/src/cms/editor.ts +381 -0
  36. package/app/src/cms/entry.ts +26 -0
  37. package/app/src/cms/feeds.ts +145 -0
  38. package/app/src/cms/field-controls.ts +222 -0
  39. package/app/src/cms/field-group-editor.ts +105 -0
  40. package/app/src/cms/field-group-view.ts +211 -0
  41. package/app/src/cms/form-view.ts +203 -0
  42. package/app/src/cms/form.client.ts +203 -0
  43. package/app/src/cms/guards.ts +27 -0
  44. package/app/src/cms/handoff.ts +202 -0
  45. package/app/src/cms/headings.ts +51 -0
  46. package/app/src/cms/icons.ts +80 -0
  47. package/app/src/cms/import.client.ts +16 -0
  48. package/app/src/cms/index.ts +191 -0
  49. package/app/src/cms/lightbox.client.ts +109 -0
  50. package/app/src/cms/machine.ts +118 -0
  51. package/app/src/cms/maintenance.ts +97 -0
  52. package/app/src/cms/manage.ts +1236 -0
  53. package/app/src/cms/mcp-tools.ts +388 -0
  54. package/app/src/cms/mcp.ts +242 -0
  55. package/app/src/cms/media-chooser.ts +123 -0
  56. package/app/src/cms/media-usage.ts +57 -0
  57. package/app/src/cms/middleware.ts +199 -0
  58. package/app/src/cms/middlewares.ts +13 -0
  59. package/app/src/cms/network-ui.ts +36 -0
  60. package/app/src/cms/network-view.ts +38 -0
  61. package/app/src/cms/notes-announce.ts +65 -0
  62. package/app/src/cms/notes-rail.ts +207 -0
  63. package/app/src/cms/notification-rules.ts +66 -0
  64. package/app/src/cms/recovery.ts +82 -0
  65. package/app/src/cms/replace.ts +63 -0
  66. package/app/src/cms/reserved-paths.ts +19 -0
  67. package/app/src/cms/rich-text-field.ts +325 -0
  68. package/app/src/cms/rich-text-schema.ts +91 -0
  69. package/app/src/cms/rich-text.client.ts +255 -0
  70. package/app/src/cms/search.client.ts +116 -0
  71. package/app/src/cms/seo-head.ts +78 -0
  72. package/app/src/cms/seo.ts +241 -0
  73. package/app/src/cms/settings-draft.ts +218 -0
  74. package/app/src/cms/settings-file.ts +127 -0
  75. package/app/src/cms/settings-form.ts +180 -0
  76. package/app/src/cms/settings-languages.ts +125 -0
  77. package/app/src/cms/settings-nav.ts +102 -0
  78. package/app/src/cms/settings-network.ts +151 -0
  79. package/app/src/cms/settings-permalinks.ts +114 -0
  80. package/app/src/cms/settings-scroll.ts +10 -0
  81. package/app/src/cms/settings-search.ts +77 -0
  82. package/app/src/cms/settings-section.ts +38 -0
  83. package/app/src/cms/share.client.ts +27 -0
  84. package/app/src/cms/site-editing.ts +219 -0
  85. package/app/src/cms/site-editor.client.ts +1008 -0
  86. package/app/src/cms/site-editor.ts +99 -0
  87. package/app/src/cms/site-export.ts +60 -0
  88. package/app/src/cms/site-forms.ts +143 -0
  89. package/app/src/cms/site-import.ts +28 -0
  90. package/app/src/cms/site-session.ts +36 -0
  91. package/app/src/cms/site-taskbar.ts +77 -0
  92. package/app/src/cms/site-view.ts +1014 -0
  93. package/app/src/cms/site.ts +1322 -0
  94. package/app/src/cms/sitemaps.ts +131 -0
  95. package/app/src/cms/stat.client.ts +56 -0
  96. package/app/src/cms/style-controls.ts +252 -0
  97. package/app/src/cms/tabs.client.ts +36 -0
  98. package/app/src/cms/taskbar.ts +134 -0
  99. package/app/src/cms/term-icons.ts +10 -0
  100. package/app/src/cms/traffic.ts +26 -0
  101. package/app/src/cms/ui.ts +170 -0
  102. package/app/src/cms/updates.ts +124 -0
  103. package/app/src/cms/uploads.ts +26 -0
  104. package/app/src/cms/worker.ts +13 -0
  105. package/app/src/config/auth.ts +30 -0
  106. package/app/src/config/cms.ts +18 -0
  107. package/app/src/dashboard/access.ts +344 -0
  108. package/app/src/dashboard/agent-icons.ts +44 -0
  109. package/app/src/dashboard/app-passwords.ts +74 -0
  110. package/app/src/dashboard/avatar-field.ts +58 -0
  111. package/app/src/dashboard/bulk.ts +53 -0
  112. package/app/src/dashboard/head.ts +29 -0
  113. package/app/src/dashboard/icons.ts +15 -0
  114. package/app/src/dashboard/list-table.ts +120 -0
  115. package/app/src/dashboard/modules/roles.ts +15 -0
  116. package/app/src/dashboard/modules/sessions.ts +15 -0
  117. package/app/src/dashboard/modules/settings.ts +15 -0
  118. package/app/src/dashboard/modules/users.ts +18 -0
  119. package/app/src/dashboard/page.ts +67 -0
  120. package/app/src/dashboard/registry.ts +13 -0
  121. package/app/src/dashboard/session-list.ts +98 -0
  122. package/app/src/dashboard/tabs.ts +26 -0
  123. package/app/src/dashboard/time-ago.ts +16 -0
  124. package/app/src/dashboard/types.ts +40 -0
  125. package/app/src/dashboard/user-sections.ts +172 -0
  126. package/app/src/lib/permissions.ts +84 -0
  127. package/app/src/middlewares/auth.ts +117 -0
  128. package/app/src/pages/(site)/[...path]/index.ts +609 -0
  129. package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
  130. package/app/src/pages/(site)/feed/index.ts +12 -0
  131. package/app/src/pages/(site)/index.ts +11 -0
  132. package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
  133. package/app/src/pages/(site)/layout.ts +219 -0
  134. package/app/src/pages/(site)/llms.txt/index.ts +23 -0
  135. package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
  136. package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
  137. package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
  138. package/app/src/pages/(site)/robots.txt/index.ts +29 -0
  139. package/app/src/pages/(site)/search/index.ts +36 -0
  140. package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
  141. package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
  142. package/app/src/pages/api/auth/session.ts +48 -0
  143. package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
  144. package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
  145. package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
  146. package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
  147. package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
  148. package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
  149. package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
  150. package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
  151. package/app/src/pages/api/cms/cache/purge.ts +6 -0
  152. package/app/src/pages/api/cms/collections/index.ts +6 -0
  153. package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
  154. package/app/src/pages/api/cms/comments/[id].ts +9 -0
  155. package/app/src/pages/api/cms/comments/index.ts +126 -0
  156. package/app/src/pages/api/cms/comments/queue.ts +6 -0
  157. package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
  158. package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
  159. package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
  160. package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
  161. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
  162. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
  163. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
  164. package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
  165. package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
  166. package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
  167. package/app/src/pages/api/cms/export/[collection].ts +37 -0
  168. package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
  169. package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
  170. package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
  171. package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
  172. package/app/src/pages/api/cms/import/[collection].ts +23 -0
  173. package/app/src/pages/api/cms/mcp.ts +29 -0
  174. package/app/src/pages/api/cms/me/index.ts +6 -0
  175. package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
  176. package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
  177. package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
  178. package/app/src/pages/api/cms/media/[id].ts +6 -0
  179. package/app/src/pages/api/cms/media.ts +26 -0
  180. package/app/src/pages/api/cms/menus/[location].ts +14 -0
  181. package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
  182. package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
  183. package/app/src/pages/api/cms/network/sites/index.ts +14 -0
  184. package/app/src/pages/api/cms/notes/[id].ts +13 -0
  185. package/app/src/pages/api/cms/notes/index.ts +6 -0
  186. package/app/src/pages/api/cms/payments/webhook.ts +28 -0
  187. package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
  188. package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
  189. package/app/src/pages/api/cms/plugins/index.ts +6 -0
  190. package/app/src/pages/api/cms/recovery.ts +29 -0
  191. package/app/src/pages/api/cms/redirects/index.ts +9 -0
  192. package/app/src/pages/api/cms/roles/index.ts +6 -0
  193. package/app/src/pages/api/cms/schema/[collection].ts +13 -0
  194. package/app/src/pages/api/cms/search.ts +16 -0
  195. package/app/src/pages/api/cms/settings/[group].ts +9 -0
  196. package/app/src/pages/api/cms/settings/index.ts +9 -0
  197. package/app/src/pages/api/cms/site-export.ts +34 -0
  198. package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
  199. package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
  200. package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
  201. package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
  202. package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
  203. package/app/src/pages/api/cms/uploads/index.ts +26 -0
  204. package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
  205. package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
  206. package/app/src/pages/api/cms/users/index.ts +12 -0
  207. package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
  208. package/app/src/pages/api/cms/webhooks/index.ts +9 -0
  209. package/app/src/pages/auth/[provider]/callback.ts +11 -0
  210. package/app/src/pages/auth/[provider]/redirect.ts +9 -0
  211. package/app/src/pages/auth/forgot-password/index.ts +75 -0
  212. package/app/src/pages/auth/layout.ts +32 -0
  213. package/app/src/pages/auth/login/index.ts +198 -0
  214. package/app/src/pages/auth/magic/index.ts +68 -0
  215. package/app/src/pages/auth/register/index.ts +117 -0
  216. package/app/src/pages/auth/reset-password/index.ts +65 -0
  217. package/app/src/pages/auth/setup/index.ts +194 -0
  218. package/app/src/pages/auth/two-factor/index.ts +67 -0
  219. package/app/src/pages/auth/verify/index.ts +62 -0
  220. package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
  221. package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
  222. package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
  223. package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
  224. package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
  225. package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
  226. package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
  227. package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
  228. package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
  229. package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
  230. package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
  231. package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
  232. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
  233. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
  234. package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
  235. package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
  236. package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
  237. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
  238. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
  239. package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
  240. package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
  241. package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
  242. package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
  243. package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
  244. package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
  245. package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
  246. package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
  247. package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
  248. package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
  249. package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
  250. package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
  251. package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
  252. package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
  253. package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
  254. package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
  255. package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
  256. package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
  257. package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
  258. package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
  259. package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
  260. package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
  261. package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
  262. package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
  263. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
  264. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
  265. package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
  266. package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
  267. package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
  268. package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
  269. package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
  270. package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
  271. package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
  272. package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
  273. package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
  274. package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
  275. package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
  276. package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
  277. package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
  278. package/app/src/pages/dashboard/index.ts +214 -0
  279. package/app/src/pages/dashboard/layout.ts +320 -0
  280. package/app/src/pages/dashboard/profile/index.ts +211 -0
  281. package/app/src/pages/dashboard/profile/security/index.ts +255 -0
  282. package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
  283. package/app/src/pages/dashboard/roles/index.ts +134 -0
  284. package/app/src/pages/dashboard/roles/new/index.ts +95 -0
  285. package/app/src/pages/dashboard/sessions/index.ts +105 -0
  286. package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
  287. package/app/src/pages/dashboard/users/index.ts +299 -0
  288. package/app/src/pages/dashboard/users/new/index.ts +123 -0
  289. package/app/src/passkeys.client.ts +18 -0
  290. package/app/src/plugins/default-theme/assets/cover.svg +31 -0
  291. package/app/src/plugins/default-theme/assets/logo.svg +8 -0
  292. package/app/src/plugins/default-theme/parts/comments.ts +66 -0
  293. package/app/src/plugins/default-theme/parts/list.ts +38 -0
  294. package/app/src/plugins/default-theme/parts/media.ts +15 -0
  295. package/app/src/plugins/default-theme/parts/options.ts +45 -0
  296. package/app/src/plugins/default-theme/plugin.json +275 -0
  297. package/app/src/plugins/default-theme/templates/archive.ts +14 -0
  298. package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
  299. package/app/src/plugins/default-theme/templates/entry.ts +27 -0
  300. package/app/src/plugins/default-theme/templates/home.ts +8 -0
  301. package/app/src/plugins/default-theme/templates/layout.ts +40 -0
  302. package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
  303. package/app/src/plugins/default-theme/templates/search.ts +32 -0
  304. package/app/src/services/rbac.ts +65 -0
  305. package/app/src/services/roles.ts +89 -0
  306. package/app/src/services/users.ts +173 -0
  307. package/package.json +123 -3
  308. package/src/automations.ts +95 -0
  309. package/src/bindings.ts +138 -0
  310. package/src/block-references.ts +239 -0
  311. package/src/block-shape.ts +155 -0
  312. package/src/blocks.ts +1157 -0
  313. package/src/cache.ts +54 -0
  314. package/src/checks.ts +198 -0
  315. package/src/cloudflare-workers.d.ts +13 -0
  316. package/src/cloudflare.ts +61 -0
  317. package/src/collab.ts +372 -0
  318. package/src/collections.ts +421 -0
  319. package/src/comments.ts +46 -0
  320. package/src/cron.ts +95 -0
  321. package/src/dashboard-menu.ts +105 -0
  322. package/src/diff.ts +113 -0
  323. package/src/editor-layout.ts +316 -0
  324. package/src/errors.ts +50 -0
  325. package/src/field-groups.ts +498 -0
  326. package/src/fields.ts +411 -0
  327. package/src/form-builder.ts +1053 -0
  328. package/src/forms.ts +109 -0
  329. package/src/highlight.ts +134 -0
  330. package/src/hooks.ts +510 -0
  331. package/src/icon-catalog.ts +55 -0
  332. package/src/icons.ts +128 -0
  333. package/src/images.ts +149 -0
  334. package/src/index.ts +100 -0
  335. package/src/isolate-core.ts +245 -0
  336. package/src/isolate.ts +19 -0
  337. package/src/isolation.ts +69 -0
  338. package/src/mail.ts +182 -0
  339. package/src/manifest.ts +476 -0
  340. package/src/media.ts +193 -0
  341. package/src/menus.ts +287 -0
  342. package/src/module.ts +32 -0
  343. package/src/modules/content.ts +64 -0
  344. package/src/modules/forms.ts +35 -0
  345. package/src/node.ts +66 -0
  346. package/src/notes.ts +237 -0
  347. package/src/permissions.ts +139 -0
  348. package/src/plugin-settings.ts +114 -0
  349. package/src/records.ts +56 -0
  350. package/src/redirects.ts +59 -0
  351. package/src/resource.ts +245 -0
  352. package/src/richtext.ts +402 -0
  353. package/src/schema-json.ts +112 -0
  354. package/src/search.ts +89 -0
  355. package/src/seo.ts +477 -0
  356. package/src/server/accounts.ts +418 -0
  357. package/src/server/ai.ts +33 -0
  358. package/src/server/api-tokens.ts +91 -0
  359. package/src/server/areas.ts +116 -0
  360. package/src/server/audit.ts +94 -0
  361. package/src/server/auth.ts +89 -0
  362. package/src/server/automations.ts +190 -0
  363. package/src/server/autosaves.ts +69 -0
  364. package/src/server/brand-icons.ts +50 -0
  365. package/src/server/brands.ts +86 -0
  366. package/src/server/budget.ts +97 -0
  367. package/src/server/cache.ts +104 -0
  368. package/src/server/capabilities.ts +333 -0
  369. package/src/server/cloudflare.ts +92 -0
  370. package/src/server/comments.ts +237 -0
  371. package/src/server/drafts.ts +176 -0
  372. package/src/server/field-groups.ts +88 -0
  373. package/src/server/files.ts +780 -0
  374. package/src/server/forms.ts +726 -0
  375. package/src/server/handoffs.ts +107 -0
  376. package/src/server/host-schema.ts +312 -0
  377. package/src/server/host.ts +2892 -0
  378. package/src/server/images.ts +34 -0
  379. package/src/server/index.ts +59 -0
  380. package/src/server/indexnow.ts +91 -0
  381. package/src/server/isolation.ts +183 -0
  382. package/src/server/locked.ts +45 -0
  383. package/src/server/mail.ts +93 -0
  384. package/src/server/markdown.ts +24 -0
  385. package/src/server/menus.ts +286 -0
  386. package/src/server/network-policy.ts +60 -0
  387. package/src/server/network.ts +665 -0
  388. package/src/server/notes.ts +275 -0
  389. package/src/server/outbox.ts +213 -0
  390. package/src/server/path-moves.ts +33 -0
  391. package/src/server/payments.ts +59 -0
  392. package/src/server/previews.ts +62 -0
  393. package/src/server/purge.ts +140 -0
  394. package/src/server/reconcile.ts +38 -0
  395. package/src/server/redirects.ts +183 -0
  396. package/src/server/repository.ts +1107 -0
  397. package/src/server/schedules.ts +105 -0
  398. package/src/server/schema.ts +562 -0
  399. package/src/server/security.ts +391 -0
  400. package/src/server/seed.ts +52 -0
  401. package/src/server/shared-fields.ts +34 -0
  402. package/src/server/site-export.ts +151 -0
  403. package/src/server/site-import.ts +482 -0
  404. package/src/server/site-search.ts +289 -0
  405. package/src/server/site-settings.ts +286 -0
  406. package/src/server/sites.ts +243 -0
  407. package/src/server/stores.ts +314 -0
  408. package/src/server/stripe.ts +173 -0
  409. package/src/server/taxonomies.ts +415 -0
  410. package/src/server/tokens.ts +25 -0
  411. package/src/server/traffic.ts +118 -0
  412. package/src/server/users.ts +653 -0
  413. package/src/server/webhooks.ts +245 -0
  414. package/src/settings-controls.ts +54 -0
  415. package/src/settings-document.ts +111 -0
  416. package/src/settings.ts +426 -0
  417. package/src/storage/cloudflare.ts +94 -0
  418. package/src/storage/index.ts +30 -0
  419. package/src/storage/node.ts +114 -0
  420. package/src/taxonomy.ts +51 -0
  421. package/src/theme.ts +1135 -0
  422. package/src/to-markdown.ts +179 -0
  423. package/src/updates.ts +126 -0
  424. package/src/version.ts +2 -0
  425. package/src/vite.d.ts +25 -0
  426. package/src/vite.js +199 -0
  427. package/src/webhooks.ts +107 -0
package/src/theme.ts ADDED
@@ -0,0 +1,1135 @@
1
+ /**
2
+ * Themes. As in VS Code, a theme is an extension: a plugin whose manifest has a `theme` field
3
+ * and that ships the site templates, as files under `templates/` or as the `theme` export of
4
+ * its `ui.ts`. One theme is active at a time and switching is a settings write. Templates
5
+ * receive plain view data and helpers; they never read the database. Themes own templates,
6
+ * never routes: the site's URLs come from its content.
7
+ */
8
+ import type { SnippetPart } from './search';
9
+ import type { HeadValue } from '@cossackframework/core';
10
+ import type { TemplateResult } from '@cossackframework/renderer';
11
+ import { fieldProblems } from './fields';
12
+ import { MENU_LOCATION, type MenuItemView } from './menus';
13
+ import type { SettingDeclaration } from './settings';
14
+ import { settingControlProblems } from './settings-controls';
15
+ import { BACKGROUND_SIZES, CUSTOM_COLOR, PRESET_SLUG, STYLE_PROPERTIES, TEXT_ALIGNMENTS, type StyleProperty } from './block-shape';
16
+ import type { Block, BlockCondition, BlockLayout, BlockStyle, InputKind } from './blocks';
17
+ import { blocksShapeProblem } from './block-shape';
18
+ import type { ChoiceOption, FormValue } from './form-builder';
19
+
20
+ /** A named value blocks pick by slug: a color, a gradient, a font size or a spacing step. */
21
+ export interface Preset {
22
+ readonly slug: string;
23
+ readonly name: string;
24
+ /** A CSS color, a CSS gradient, or a CSS length for sizes and spacing. */
25
+ readonly value: string;
26
+ }
27
+
28
+ /** The presets a theme offers the Style tab. Absent kinds take `DEFAULT_PRESETS`. */
29
+ export interface ThemePresets {
30
+ readonly colors?: readonly Preset[];
31
+ /** CSS gradients (`linear-gradient(...)`, radial or conic), for container backgrounds. */
32
+ readonly gradients?: readonly Preset[];
33
+ readonly fontSizes?: readonly Preset[];
34
+ readonly spacing?: readonly Preset[];
35
+ }
36
+ export type PresetKind = keyof ThemePresets;
37
+ export const PRESET_KINDS = Object.freeze(['colors', 'gradients', 'fontSizes', 'spacing'] as const);
38
+
39
+ /** A widget area with the blocks the theme shows until the site saves its own. */
40
+ export interface ThemeAreaManifest {
41
+ readonly label: string;
42
+ readonly blocks?: readonly Block[];
43
+ }
44
+
45
+ /** An area as a theme declares it, label and defaults apart: `name: label` has no defaults. */
46
+ export function themeArea(name: string, entry: string | ThemeAreaManifest): { name: string; label: string; defaults: readonly Block[] } {
47
+ return typeof entry === 'string' ? { name, label: entry, defaults: [] } : { name, label: entry.label, defaults: entry.blocks ?? [] };
48
+ }
49
+
50
+ /** The `theme` field of a plugin manifest. */
51
+ export interface ThemeManifest {
52
+ readonly label: string;
53
+ readonly description?: string;
54
+ /** Menu locations the theme renders, such as `{ "primary": "Primary menu" }`. */
55
+ readonly locations?: { readonly [name: string]: string };
56
+ /** Options shown under Appearance → Customize, stored as settings `<plugin>.<option>`. */
57
+ readonly options?: { readonly [name: string]: SettingDeclaration };
58
+ /**
59
+ * A parent theme, by plugin name. The child's templates, loaders, assets, options, menu
60
+ * locations and widget areas are layered over the parent's, slot by slot. Its option
61
+ * values are its own.
62
+ */
63
+ readonly extends?: string;
64
+ /**
65
+ * Widget areas: block lists edited under Appearance → Widgets and in Live Edit, such as
66
+ * `{ "sidebar": "Sidebar" }`. An area may carry default blocks, shown until the site saves
67
+ * its own: `{ "header": { "label": "Header", "blocks": [...] } }`.
68
+ */
69
+ readonly areas?: { readonly [name: string]: string | ThemeAreaManifest };
70
+ /** The palette, font sizes and spacing steps blocks pick from; the site adjusts colors under Customize. */
71
+ readonly presets?: ThemePresets;
72
+ }
73
+
74
+ const OPTION_KINDS = new Set(['string', 'text', 'enum', 'boolean', 'integer', 'number']);
75
+
76
+ /** Problems with a manifest's `theme` field; empty when valid. */
77
+ export function themeProblems(theme: unknown): string[] {
78
+ if (!theme || typeof theme !== 'object' || Array.isArray(theme)) return ['theme must be an object.'];
79
+ const value = theme as ThemeManifest;
80
+ const problems: string[] = [];
81
+ if (typeof value.label !== 'string' || !value.label.trim() || value.label.length > 60) problems.push('theme.label must be 1-60 characters.');
82
+ if (value.description !== undefined && (typeof value.description !== 'string' || value.description.length > 300)) problems.push('theme.description can be at most 300 characters.');
83
+ const locations = Object.entries(value.locations ?? {});
84
+ if (locations.length > 8) problems.push('theme.locations: declare at most 8 menu locations.');
85
+ for (const [name, label] of locations) {
86
+ if (!MENU_LOCATION.test(name)) problems.push(`theme.locations: ${name} must be lowercase letters, digits and hyphens.`);
87
+ if (typeof label !== 'string' || !label.trim() || label.length > 60) problems.push(`theme.locations.${name} needs a label of at most 60 characters.`);
88
+ }
89
+ if (value.extends !== undefined && (typeof value.extends !== 'string' || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(value.extends))) problems.push('theme.extends must name a theme plugin.');
90
+ const areas = Object.entries(value.areas ?? {});
91
+ if (areas.length > 8) problems.push('theme.areas: declare at most 8 widget areas.');
92
+ for (const [name, entry] of areas) {
93
+ if (!MENU_LOCATION.test(name)) problems.push(`theme.areas: ${name} must be lowercase letters, digits and hyphens.`);
94
+ const label = typeof entry === 'string' ? entry : entry && typeof entry === 'object' && !Array.isArray(entry) ? entry.label : undefined;
95
+ if (typeof label !== 'string' || !label.trim() || label.length > 60) problems.push(`theme.areas.${name} needs a label of at most 60 characters.`);
96
+ if (entry && typeof entry === 'object' && entry.blocks !== undefined) {
97
+ const shape = blocksShapeProblem(entry.blocks);
98
+ if (shape) problems.push(`theme.areas.${name}.blocks ${shape}`);
99
+ }
100
+ }
101
+ const options = Object.entries(value.options ?? {});
102
+ if (options.length > 16) problems.push('theme.options: declare at most 16 options.');
103
+ for (const [name, option] of options) {
104
+ if (['__proto__', 'constructor', 'prototype'].includes(name)) { problems.push(`theme.options.${name} is not a safe option name.`); continue; }
105
+ if (!option || typeof option !== 'object' || !OPTION_KINDS.has(option.kind)) { problems.push(`theme.options.${name} must be a string, text, enum, boolean, integer or number field.`); continue; }
106
+ if (option.unique || option.index || option.search || option.slugFrom || option.taxonomy || option.media) problems.push(`theme.options.${name} cannot be indexed, searched or derived.`);
107
+ problems.push(...fieldProblems(name, option).map(problem => `theme.options: ${problem}`));
108
+ problems.push(...settingControlProblems(name, option).map(problem => `theme.options: ${problem}`));
109
+ }
110
+ if (value.presets !== undefined) problems.push(...presetProblems(value.presets).map(problem => `theme.presets: ${problem}`));
111
+ return problems;
112
+ }
113
+
114
+
115
+ /** A CSS color: hex, a named color, or a color function without nested parentheses. */
116
+ const COLOR_VALUE = /^(?:#[0-9a-f]{3,8}|[a-z]{3,30}|(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color)\([^()]{1,60}\))$/i;
117
+ /** A CSS length, or `clamp()`, `min()`, `max()` and `calc()` of lengths. */
118
+ const LENGTH_VALUE = /^(?:-?\d*\.?\d+(?:px|rem|em|%|vw|vh|ch|cqi|cqw)?|(?:clamp|min|max|calc)\([-+*/\d.\s,%a-z]{1,60}\))$/i;
119
+ /** A CSS gradient: one gradient function over colors, stops and angles; it may read the palette's variables, never a `url()`. */
120
+ export const GRADIENT_VALUE = /^(?:repeating-)?(?:linear|radial|conic)-gradient\((?:[^()]|\([^()]*\))*\)$/i;
121
+ const PRESET_LIMITS: Readonly<Record<PresetKind, number>> = { colors: 24, gradients: 12, fontSizes: 8, spacing: 8 };
122
+ const PRESET_VALUE_NAMES: Readonly<Record<PresetKind, string>> = { colors: 'color', gradients: 'gradient', fontSizes: 'length', spacing: 'length' };
123
+
124
+ /** Whether a preset's value fits its kind: a color, a gradient or a length. */
125
+ function presetValueOk(kind: PresetKind, value: string): boolean {
126
+ const text = value.trim();
127
+ if (kind === 'colors') return COLOR_VALUE.test(text);
128
+ if (kind === 'gradients') return text.length <= 400 && GRADIENT_VALUE.test(text) && !/url\s*\(/i.test(text);
129
+ return LENGTH_VALUE.test(text);
130
+ }
131
+
132
+ /** Problems with presets, as a manifest declares them or as the site's custom colors and gradients; empty when valid. */
133
+ export function presetProblems(presets: unknown): string[] {
134
+ if (!presets || typeof presets !== 'object' || Array.isArray(presets)) return ['presets is an object of colors, gradients, fontSizes and spacing.'];
135
+ const problems: string[] = [];
136
+ for (const [kind, list] of Object.entries(presets)) {
137
+ if (!(PRESET_KINDS as readonly string[]).includes(kind)) { problems.push(`${kind} is not a preset kind; use ${PRESET_KINDS.join(', ')}.`); continue; }
138
+ if (!Array.isArray(list)) { problems.push(`${kind} is a list.`); continue; }
139
+ if (list.length > PRESET_LIMITS[kind as PresetKind]) problems.push(`${kind} lists at most ${PRESET_LIMITS[kind as PresetKind]} presets.`);
140
+ const slugs = new Set<string>();
141
+ for (const entry of list as Preset[]) {
142
+ const at = `${kind}.${String(entry?.slug)}`;
143
+ if (typeof entry?.slug !== 'string' || !PRESET_SLUG.test(entry.slug) || entry.slug.length > 40) { problems.push(`${kind}: slugs are lowercase letters, digits and hyphens.`); continue; }
144
+ if (slugs.has(entry.slug)) problems.push(`${at} is listed twice.`);
145
+ slugs.add(entry.slug);
146
+ if (typeof entry.name !== 'string' || !entry.name.trim() || entry.name.length > 40) problems.push(`${at} needs a name of at most 40 characters.`);
147
+ if (typeof entry.value !== 'string' || !presetValueOk(kind as PresetKind, entry.value)) problems.push(`${at} needs a CSS ${PRESET_VALUE_NAMES[kind as PresetKind]}.`);
148
+ }
149
+ }
150
+ return problems;
151
+ }
152
+
153
+ /** What a theme without its own gets: no palette, six gradients, five font sizes and five spacing steps. */
154
+ export const DEFAULT_PRESETS: ThemePresets = Object.freeze({
155
+ colors: Object.freeze([]),
156
+ gradients: Object.freeze([
157
+ { slug: 'dusk', name: 'Dusk', value: 'linear-gradient(135deg, #1e3a8a 0%, #7c3aed 100%)' }, { slug: 'sunrise', name: 'Sunrise', value: 'linear-gradient(135deg, #f97316 0%, #ec4899 100%)' },
158
+ { slug: 'meadow', name: 'Meadow', value: 'linear-gradient(135deg, #059669 0%, #84cc16 100%)' }, { slug: 'ocean', name: 'Ocean', value: 'linear-gradient(180deg, #0ea5e9 0%, #1e40af 100%)' },
159
+ { slug: 'graphite', name: 'Graphite', value: 'linear-gradient(135deg, #111827 0%, #4b5563 100%)' }, { slug: 'fog', name: 'Fog', value: 'linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%)' },
160
+ ]),
161
+ fontSizes: Object.freeze([
162
+ { slug: 'small', name: 'Small', value: '0.875rem' }, { slug: 'medium', name: 'Medium', value: '1rem' }, { slug: 'large', name: 'Large', value: '1.25rem' },
163
+ { slug: 'x-large', name: 'Extra large', value: '1.5rem' }, { slug: 'xx-large', name: 'Huge', value: '2.25rem' },
164
+ ]),
165
+ spacing: Object.freeze([
166
+ { slug: 'none', name: 'None', value: '0' }, { slug: 'small', name: 'Small', value: '0.75rem' }, { slug: 'medium', name: 'Medium', value: '1.5rem' },
167
+ { slug: 'large', name: 'Large', value: '3rem' }, { slug: 'x-large', name: 'Extra large', value: '5rem' },
168
+ ]),
169
+ });
170
+
171
+ /** `top`'s presets over `base`'s, slug by slug, kind by kind; a kind `top` lists at all is its own list plus the base's extra slugs. */
172
+ export function layerPresets(base: ThemePresets | undefined, top: ThemePresets | undefined): ThemePresets {
173
+ const result: { -readonly [K in PresetKind]?: Preset[] } = {};
174
+ for (const kind of PRESET_KINDS) {
175
+ const lower = base?.[kind];
176
+ const upper = top?.[kind];
177
+ if (!lower && !upper) continue;
178
+ const merged = new Map<string, Preset>();
179
+ for (const preset of upper ?? []) merged.set(preset.slug, preset);
180
+ for (const preset of lower ?? []) if (!merged.has(preset.slug)) merged.set(preset.slug, preset);
181
+ result[kind] = [...merged.values()];
182
+ }
183
+ return result;
184
+ }
185
+
186
+ /** The site's changes to the active theme's palette and gradients: new values by slug, and colors and gradients it added. */
187
+ export interface PresetOverrides {
188
+ readonly colors?: { readonly [slug: string]: string };
189
+ readonly custom?: readonly Preset[];
190
+ readonly gradients?: { readonly [slug: string]: string };
191
+ readonly customGradients?: readonly Preset[];
192
+ }
193
+
194
+ /** A problem with `appearance.presets` entries, which are overrides keyed by theme; undefined when valid. */
195
+ export function presetOverridesProblem(value: unknown): string | undefined {
196
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return 'Preset overrides are an object.';
197
+ const { colors, custom, gradients, customGradients } = value as PresetOverrides;
198
+ for (const [kind, map] of [['colors', colors], ['gradients', gradients]] as const) {
199
+ if (map === undefined) continue;
200
+ if (!map || typeof map !== 'object' || Array.isArray(map)) return `${kind} maps slugs to ${kind}.`;
201
+ for (const [slug, entry] of Object.entries(map)) {
202
+ if (!PRESET_SLUG.test(slug) || typeof entry !== 'string' || !presetValueOk(kind, entry)) return `${slug} needs a CSS ${PRESET_VALUE_NAMES[kind]}.`;
203
+ }
204
+ }
205
+ for (const [kind, list] of [['colors', custom], ['gradients', customGradients]] as const) {
206
+ if (list === undefined) continue;
207
+ const problems = presetProblems({ [kind]: list });
208
+ if (problems.length) return problems[0]!.replace(new RegExp(`^${kind}[.:]?\\s?`), '');
209
+ }
210
+ return undefined;
211
+ }
212
+
213
+ /** The presets blocks pick from: the theme's over the defaults, with the site's changes to colors and gradients and its additions. */
214
+ export function resolvePresets(theme: ThemePresets | undefined, overrides?: PresetOverrides | null): Required<ThemePresets> {
215
+ const layered = layerPresets(DEFAULT_PRESETS, theme);
216
+ const adjusted = (kind: 'colors' | 'gradients', changes: { readonly [slug: string]: string } | undefined, added: readonly Preset[] | undefined) => {
217
+ const own = (layered[kind] ?? []).map(preset => changes?.[preset.slug] ? { ...preset, value: changes[preset.slug]! } : preset);
218
+ return [...own, ...(added ?? []).filter(preset => !own.some(entry => entry.slug === preset.slug))];
219
+ };
220
+ return { colors: adjusted('colors', overrides?.colors, overrides?.custom), gradients: adjusted('gradients', overrides?.gradients, overrides?.customGradients), fontSizes: layered.fontSizes ?? [], spacing: layered.spacing ?? [] };
221
+ }
222
+
223
+ const PRESET_VARIABLES: Readonly<Record<PresetKind, string>> = { colors: '--cms-color', gradients: '--cms-gradient', fontSizes: '--cms-size', spacing: '--cms-space' };
224
+
225
+ /** The presets as custom properties for an inline `style`, such as `--cms-color-brand: #0f172a;`. */
226
+ export function presetStyle(presets: ThemePresets | undefined): string {
227
+ if (!presets) return '';
228
+ return PRESET_KINDS.flatMap(kind => (presets[kind] ?? []).map(preset => `${PRESET_VARIABLES[kind]}-${preset.slug}: ${preset.value.trim()};`)).join(' ');
229
+ }
230
+
231
+ /** What a styled block's wrapper carries; see `blockStyleAttributes`. */
232
+ export interface BlockStyleAttributes {
233
+ className: string;
234
+ style: string;
235
+ id: string;
236
+ nosnippet: boolean;
237
+ /** The video behind the block, when its style names one the block's media resolved; the renderer places the element. */
238
+ video?: MediaView;
239
+ /**
240
+ * The image behind the block as an element, with where it is anchored (`object-position`):
241
+ * an image that covers the block and has resized variants. The renderer places an `<img>`,
242
+ * so the browser picks a variant for the screen, finds it early and loads it when it nears
243
+ * the screen. Other images (tiled, fixed, contained, or over a gradient) stay in `style`.
244
+ */
245
+ image?: { media: MediaView; position: string };
246
+ }
247
+
248
+ /**
249
+ * The URL a background image loads from: the largest resized variant up to 2560 pixels, or the
250
+ * file as uploaded when it has none. Quotes and parentheses are escaped for `url("...")`.
251
+ */
252
+ export function backgroundImageUrl(media: Pick<MediaView, 'url' | 'srcset'>): string {
253
+ let best: { url: string; width: number } | null = null;
254
+ for (const candidate of media.srcset.split(',')) {
255
+ const [url, size] = candidate.trim().split(/\s+/);
256
+ const width = Number.parseInt(size ?? '', 10);
257
+ if (!url || !Number.isFinite(width) || width > 2560) continue;
258
+ if (!best || width > best.width) best = { url, width };
259
+ }
260
+ return (best?.url ?? media.url).replace(/["'()\\\s]/g, character => encodeURIComponent(character));
261
+ }
262
+
263
+ /**
264
+ * What a styled block's wrapper carries: classes per property, the `id`, and inline properties
265
+ * through the presets' variables. A container's advanced background renders as layers (a
266
+ * gradient over an image from the block's resolved media, positioned at its focal point), an
267
+ * overlay as the `--cms-overlay` color the stylesheet paints over them, and a video as a
268
+ * `MediaView` for the renderer. An image that covers the block is an element for the renderer
269
+ * too (`image`), not a layer. Null for an unstyled block.
270
+ */
271
+ export function blockStyleAttributes(block: { readonly style?: BlockStyle; readonly layout?: BlockLayout; readonly media?: { readonly [id: string]: MediaView } }): BlockStyleAttributes | null {
272
+ const classes: string[] = [];
273
+ const rules: string[] = [];
274
+ const slug = (property: StyleProperty) => {
275
+ const value = block.style?.[property];
276
+ return typeof value === 'string' && PRESET_SLUG.test(value) && value.length <= 40 ? value : '';
277
+ };
278
+ // A color is a preset's slug, rendered through its variable, or a hex color of the block's own, rendered as it is.
279
+ const custom = (property: 'background' | 'text' | 'overlay') => {
280
+ const value = block.style?.[property];
281
+ return typeof value === 'string' && CUSTOM_COLOR.test(value) ? value.toLowerCase() : '';
282
+ };
283
+ const background = slug('background');
284
+ if (background) { classes.push(`cms-bg-${background}`); rules.push(`background-color: var(--cms-color-${background})`); }
285
+ else if (custom('background')) { classes.push('cms-bg-custom'); rules.push(`background-color: ${custom('background')}`); }
286
+ const text = slug('text');
287
+ if (text) { classes.push(`cms-text-${text}`); rules.push(`color: var(--cms-color-${text})`); }
288
+ else if (custom('text')) { classes.push('cms-text-custom'); rules.push(`color: ${custom('text')}`); }
289
+ const padding = slug('padding');
290
+ // A padded block holds its own gutter: `cms-padded` pads by `--cms-pad` and zeroes `--cms-gutter` for its content. A band
291
+ // across the page pads top and bottom alone and keeps the page's gutter at its sides (cms/blocks.css).
292
+ if (padding) { classes.push(`cms-p-${padding}`, 'cms-padded'); rules.push(`--cms-pad: var(--cms-space-${padding})`); }
293
+ const margin = slug('margin');
294
+ if (margin) { classes.push(`cms-m-${margin}`); rules.push(`margin-block: var(--cms-space-${margin})`); }
295
+ const fontSize = slug('fontSize');
296
+ if (fontSize) { classes.push(`cms-size-${fontSize}`); rules.push(`font-size: var(--cms-size-${fontSize})`); }
297
+ const align = block.style?.align;
298
+ if (align && (TEXT_ALIGNMENTS as readonly string[]).includes(align)) { classes.push(`cms-align-${align}`); rules.push(`text-align: ${align}`); }
299
+ // The advanced background: layers from the top down, a gradient over an image.
300
+ const layers: string[] = [];
301
+ const gradient = slug('gradient');
302
+ if (gradient) { classes.push(`cms-gradient-${gradient}`); layers.push(`var(--cms-gradient-${gradient})`); }
303
+ const image = typeof block.style?.image === 'string' ? block.media?.[block.style.image] : undefined;
304
+ let element: BlockStyleAttributes['image'];
305
+ if (image && image.contentType.startsWith('image/')) {
306
+ classes.push('cms-has-image');
307
+ const size = block.style?.imageSize && (BACKGROUND_SIZES as readonly string[]).includes(block.style.imageSize) ? block.style.imageSize : 'cover';
308
+ const focus = image.focus;
309
+ const position = focus ? `${Math.round(focus.x * 100)}% ${Math.round(focus.y * 100)}%` : '50% 50%';
310
+ // An element where one does the same as the layer: it covers, once, scrolls with the page, and nothing is painted over it but the overlay.
311
+ if (size === 'cover' && image.srcset && !gradient && block.style?.imageRepeat !== true && block.style?.imageFixed !== true) {
312
+ classes.push('cms-has-image-element');
313
+ element = { media: image, position };
314
+ } else {
315
+ layers.push(`url("${backgroundImageUrl(image)}")`);
316
+ rules.push(`background-size: ${size}`);
317
+ rules.push(`background-position: ${position}`);
318
+ rules.push(`background-repeat: ${block.style?.imageRepeat === true ? 'repeat' : 'no-repeat'}`);
319
+ if (block.style?.imageFixed === true) rules.push('background-attachment: fixed');
320
+ }
321
+ }
322
+ if (layers.length) rules.push(`background-image: ${layers.join(', ')}`);
323
+ const overlay = slug('overlay') ? `var(--cms-color-${slug('overlay')})` : custom('overlay');
324
+ if (overlay) {
325
+ const opacity = typeof block.style?.overlayOpacity === 'number' ? Math.min(Math.max(Math.round(block.style.overlayOpacity), 0), 100) : 50;
326
+ classes.push('cms-has-overlay');
327
+ rules.push(`--cms-overlay: color-mix(in srgb, ${overlay} ${opacity}%, transparent)`);
328
+ }
329
+ const video = typeof block.style?.video === 'string' ? block.media?.[block.style.video] : undefined;
330
+ if (video && video.contentType.startsWith('video/')) classes.push('cms-has-video');
331
+ const extra = (block.layout?.className ?? '').trim().split(/\s+/).filter(name => /^-?[_A-Za-z][\w-]*$/.test(name));
332
+ const id = /^[A-Za-z][\w-]{0,59}$/.test(block.layout?.anchor ?? '') ? block.layout!.anchor! : '';
333
+ const nosnippet = block.layout?.nosnippet === true;
334
+ if (!classes.length && !extra.length && !id && !nosnippet) return null;
335
+ // A box: a wrapper you can see, whose padding or background holds its content, so its first and last blocks drop their outer margins (cms/blocks.css).
336
+ // A wrapper that only names, colors or sizes a block leaves the block's spacing as it would be unwrapped.
337
+ const box = Boolean(padding || background || custom('background') || gradient || overlay) || classes.includes('cms-has-image') || classes.includes('cms-has-video');
338
+ return { className: ['cms-block', ...(box ? ['cms-box'] : []), ...classes, ...extra].join(' '), style: rules.join('; '), id, nosnippet, ...(video && video.contentType.startsWith('video/') ? { video } : {}), ...(element ? { image: element } : {}) };
339
+ }
340
+
341
+ /**
342
+ * The CSS as the browser reads it, for matching: comments removed and escapes decoded, so
343
+ * `u\72l(` and `@\69mport` are seen as `url(` and `@import`.
344
+ */
345
+ function cssTokens(css: string): string {
346
+ return css.replace(/\/\*[\s\S]*?(?:\*\/|$)/g, '')
347
+ .replace(/\\(?:([0-9a-f]{1,6})[ \t\n\r\f]?|\r\n|([\s\S]))/gi, (match, hex: string | undefined, char: string | undefined) => {
348
+ if (hex !== undefined) { const point = parseInt(hex, 16); return point > 0 && point <= 0x10ffff && (point < 0xd800 || point > 0xdfff) ? String.fromCodePoint(point) : '\ufffd'; }
349
+ return char === undefined || /[\n\r\f]/.test(char) ? '' : char;
350
+ });
351
+ }
352
+
353
+ /** Why a site's Additional CSS is refused: it may not load other resources or run scripts. Undefined when fine. */
354
+ export function customCssProblem(css: string): string | undefined {
355
+ if (css.length > 20_000) return 'Additional CSS is at most 20,000 characters.';
356
+ for (const text of [css, cssTokens(css)]) {
357
+ if (/@import\b/i.test(text)) return 'Additional CSS cannot use @import.';
358
+ if (/\burl\s*\(/i.test(text)) return 'Additional CSS cannot use url().';
359
+ if (/(?:^|[^\w-])(?:-webkit-)?(?:image-set|image|cross-fade|element)\s*\(/i.test(text)) return 'Additional CSS cannot load images.';
360
+ if (/\bexpression\s*\(|\bbehavior\s*:|-moz-binding|javascript:/i.test(text)) return 'Additional CSS cannot run scripts.';
361
+ if (/<\/?\s*(?:style|script)\b/i.test(text)) return 'Additional CSS cannot contain HTML tags.';
362
+ }
363
+ return undefined;
364
+ }
365
+
366
+ export interface MediaView {
367
+ readonly url: string;
368
+ readonly alt: string;
369
+ /** Size after the image's crop. */
370
+ readonly width: number | null;
371
+ readonly height: number | null;
372
+ readonly contentType: string;
373
+ /** The file's name as uploaded, and its size in bytes. */
374
+ readonly name: string;
375
+ readonly size: number;
376
+ readonly caption: string;
377
+ /** Resized variants for `<img srcset>`; empty when the image is served as uploaded. `wideSrcset(media.srcset)` gives them in a 16:9 shape around the focal point, for cards and headers. */
378
+ readonly srcset: string;
379
+ /** A tiny stand-in as a `data:` URL, shown blurred while the image loads (`placeholderStyle`); null for other files or when Settings → Files says none. */
380
+ readonly placeholder: string | null;
381
+ /** How wide content images show, from Settings → Files, for `<img sizes>`. */
382
+ readonly sizes: string;
383
+ /** The page's first image: load it at once, with high priority (`loading="eager" fetchpriority="high"`). */
384
+ readonly priority?: boolean;
385
+ /** The point to keep in view when the image fills a shape, 0 to 1 each way, from the library's focal point edit; null when none is set. */
386
+ readonly focus?: { readonly x: number; readonly y: number } | null;
387
+ }
388
+
389
+ export interface TermLink {
390
+ readonly name: string;
391
+ readonly url: string | null;
392
+ /** The term's icon name, or empty. Themes may show it before the name. */
393
+ readonly icon?: string;
394
+ }
395
+
396
+ /** A block with its Markdown fields rendered and its media resolved. */
397
+ /** A brand's icon, as Simple Icons draws it: a 24×24 path and the brand's color. */
398
+ export interface BrandIcon {
399
+ readonly title: string;
400
+ readonly path: string;
401
+ readonly hex: string;
402
+ }
403
+
404
+ export interface RenderedBlock {
405
+ readonly _id: string;
406
+ readonly type: string;
407
+ readonly data: { readonly [field: string]: unknown };
408
+ /** Markdown fields rendered to escaped HTML. */
409
+ readonly html: { readonly [field: string]: string };
410
+ /** Media the block uses, by file ID. */
411
+ readonly media: { readonly [id: string]: MediaView };
412
+ /** The icons of the networks the block's `brand` fields link to, by URL; absent for URLs of no known network. */
413
+ readonly icons?: { readonly [url: string]: BrandIcon };
414
+ /** How the block shows: `hide` lists the container widths it is hidden at; `anchor` and `className` go on its wrapper. */
415
+ readonly layout?: BlockLayout;
416
+ /** Preset slugs the block's wrapper renders as classes and custom properties; see `blockStyleAttributes`. */
417
+ readonly style?: BlockStyle;
418
+ /** In a form: when the block shows, from the form's values. */
419
+ readonly when?: BlockCondition;
420
+ /** In a form: false while its condition hides it. The block still renders, marked `data-hidden`. */
421
+ readonly shown?: boolean;
422
+ /** An input block in a form: its name, value and error. */
423
+ readonly input?: InputView;
424
+ /** `form/repeater`: its rows, each with the row's blocks rendered, and the blocks of a new row. */
425
+ readonly repeater?: RepeaterView;
426
+ /** `core/form`: the form it places; absent when the form is gone. */
427
+ readonly form?: FormView;
428
+ /** Rich text fields rendered: HTML runs and embedded blocks, for `helpers.content`. */
429
+ readonly content?: { readonly [field: string]: readonly BodyPart[] };
430
+ /** `core/latest-entries`: the entries it lists. */
431
+ readonly entries?: readonly EntryView[];
432
+ /** `core/toc`: the headings of the entry's content, anchored. */
433
+ readonly headings?: readonly HeadingView[];
434
+ /** A data block: it holds values for themes and the API and renders nothing. */
435
+ readonly dataOnly?: boolean;
436
+ /** The synced pattern the block was expanded from, and its ID there: Live Edit addresses the pattern's own document through them. */
437
+ readonly pattern?: string;
438
+ readonly sourceId?: string;
439
+ /** In edit mode: the document the block belongs to (`area:<name>`, `pattern:<id>`); the entry's own blocks carry none. */
440
+ readonly document?: string;
441
+ /** In edit mode: the signed-in user may not change the block's document; it is marked but nothing in it selects. */
442
+ readonly locked?: boolean;
443
+ /** The rendered blocks a container holds. */
444
+ readonly children?: readonly RenderedBlock[];
445
+ /**
446
+ * Rendered from one of the entry's fields (rich text or Markdown as a `core/richtext`
447
+ * block), not stored among its blocks: the field's name. The site editor opens that field.
448
+ */
449
+ readonly field?: string;
450
+ }
451
+
452
+ /** An input block's state in a rendered form. */
453
+ export interface InputView {
454
+ /** The control's HTML name: the input's name, or `repeater[row id][name]` in a repeater's row. */
455
+ readonly name: string;
456
+ /** The input's key in errors and values: its name, or `repeater.<row id>.<name>` in a row. */
457
+ readonly key: string;
458
+ readonly kind: InputKind;
459
+ /** The control's HTML id, unique on the page. */
460
+ readonly id: string;
461
+ /** What the form starts with, or what the sender typed when the post came back with errors. */
462
+ readonly value: FormValue | null;
463
+ readonly error: string;
464
+ readonly options: readonly ChoiceOption[];
465
+ /** A multiple input: its items as controls, one per value, with the Add and Remove buttons' bounds. */
466
+ readonly items?: ItemsView;
467
+ }
468
+
469
+ /** The controls of a multiple input: one per posted value, or the fewest it needs. Errors are by position. */
470
+ export interface ItemsView {
471
+ readonly values: readonly string[];
472
+ readonly errors: readonly string[];
473
+ readonly min: number;
474
+ readonly max: number;
475
+ readonly addLabel: string;
476
+ }
477
+
478
+ /**
479
+ * A form as themes render it: its blocks with their inputs' state, and what the post needs.
480
+ * The default renderer posts it as HTML and lets `cms/form.client.ts` apply conditions and
481
+ * check values in the browser.
482
+ */
483
+ export interface FormView {
484
+ readonly id: string;
485
+ readonly slug: string;
486
+ readonly title: string;
487
+ /** POST target: `/api/cms/forms/<slug>`. */
488
+ readonly action: string;
489
+ /** The page the form is on, where a post returns. */
490
+ readonly page: string;
491
+ readonly blocks: readonly RenderedBlock[];
492
+ readonly submitLabel: string;
493
+ /** After a post came back: the confirmation, or what went wrong, as escaped HTML. */
494
+ readonly notice: { readonly kind: 'success' | 'error'; readonly html: string } | null;
495
+ /** The closed message as escaped HTML when the form takes no submissions; its fields are not shown. */
496
+ readonly closed: string | null;
497
+ /** Visitors must sign in first: where to. */
498
+ readonly signInUrl: string | null;
499
+ /** When the page was rendered, for the hidden `_started` field. */
500
+ readonly startedAt: number;
501
+ readonly turnstileSiteKey: string | null;
502
+ /** Input kinds by block type, for the browser's checks. */
503
+ readonly kinds: { readonly [type: string]: InputKind };
504
+ }
505
+
506
+ /**
507
+ * A repeater in a rendered form. Each row's blocks carry ids `<row id>:<block id>` and inputs
508
+ * named `repeater[row id][name]`; `template` is a row with the id `__row__`, which the page's
509
+ * script copies for a new row, its inputs disabled until then.
510
+ */
511
+ export interface RepeaterView {
512
+ readonly rows: readonly { readonly id: string; readonly blocks: readonly RenderedBlock[] }[];
513
+ readonly template: readonly RenderedBlock[];
514
+ readonly min: number;
515
+ readonly max: number;
516
+ readonly addLabel: string;
517
+ readonly rowLabel: string;
518
+ /** The repeater's own message: too few or too many rows. */
519
+ readonly error: string;
520
+ }
521
+
522
+ /** A run of escaped HTML from the body, or a block embedded in it. */
523
+ export type BodyPart = { readonly kind: 'html'; readonly html: string } | { readonly kind: 'block'; readonly block: RenderedBlock };
524
+
525
+ /** An entry's author as themes show them. */
526
+ export interface EntryAuthor {
527
+ readonly name: string;
528
+ /** Their author page, such as `/author/ada`; null when author pages are off. */
529
+ readonly url: string | null;
530
+ readonly avatar: string | null;
531
+ }
532
+
533
+ /** A comment as themes show it, with its replies. */
534
+ export interface CommentView {
535
+ readonly id: string;
536
+ readonly author: string;
537
+ /** The author's website, when given. */
538
+ readonly authorUrl: string | null;
539
+ readonly avatar: string | null;
540
+ readonly date: string;
541
+ /** The text as escaped paragraphs. */
542
+ readonly html: string;
543
+ readonly replies: readonly CommentView[];
544
+ /** Replies may nest below this comment. */
545
+ readonly replyable: boolean;
546
+ }
547
+
548
+ /** What the comment form posts and asks for. */
549
+ export interface CommentFormView {
550
+ /** POST target: `/api/cms/comments`, with `collection`, `entry`, `parent`, `content`, `authorName`, `authorEmail`, `authorUrl`. */
551
+ readonly action: string;
552
+ readonly collection: string;
553
+ readonly entry: string;
554
+ /** The signed-in commenter's name; empty for visitors. */
555
+ readonly userName: string;
556
+ readonly requireNameEmail: boolean;
557
+ /** Visitors must sign in first, at `signInUrl`. */
558
+ readonly requireSignIn: boolean;
559
+ readonly signInUrl: string;
560
+ /** Turnstile's site key when the site checks for bots, else null. */
561
+ readonly turnstileSiteKey: string | null;
562
+ }
563
+
564
+ export interface CommentsView {
565
+ readonly open: boolean;
566
+ /** Approved comments. */
567
+ readonly count: number;
568
+ readonly items: readonly CommentView[];
569
+ /** Null when comments are closed. */
570
+ readonly form: CommentFormView | null;
571
+ /** After posting: `held` when the comment awaits moderation, `posted` when it shows. */
572
+ readonly notice: '' | 'held' | 'posted';
573
+ /** Why the last post failed: comments `closed`, `sign-in` needed, posting `too-fast`, an `invalid` form, or a failed `bot` check. */
574
+ readonly error: '' | 'closed' | 'sign-in' | 'too-fast' | 'invalid' | 'bot';
575
+ }
576
+
577
+ /** The current page in another of the site's languages. */
578
+ export interface LanguageLink {
579
+ readonly code: string;
580
+ /** The language's own name, such as `Français`. */
581
+ readonly label: string;
582
+ /** A flag emoji for the language (`languageFlag`), or empty when it has none. */
583
+ readonly flag: string;
584
+ readonly url: string;
585
+ readonly current: boolean;
586
+ }
587
+
588
+ /** How a language switcher names each language: by name, flag, both, or code. */
589
+ export const LANGUAGE_SWITCHER_STYLES = Object.freeze(['names', 'flags', 'flags-names', 'codes'] as const);
590
+ export type LanguageSwitcherStyle = (typeof LANGUAGE_SWITCHER_STYLES)[number];
591
+
592
+ /** What `helpers.languages()` renders: the page's other languages as links, in one of the styles. */
593
+ export interface LanguageSwitcherOptions {
594
+ /** `names` by default. */
595
+ readonly style?: LanguageSwitcherStyle | string;
596
+ /** A row of links (`inline`, the default) or a column (`list`). */
597
+ readonly layout?: 'inline' | 'list' | string;
598
+ /** Class names for the `nav` element. */
599
+ readonly class?: string;
600
+ }
601
+
602
+ /** How `helpers.menu()` lays a menu out. */
603
+ export type MenuStyle = 'dropdowns' | 'inline' | 'list';
604
+
605
+ /** How a header menu's dropdowns and mega panels open: fade in and lift, fade, grow from the top edge, or switch. */
606
+ export type MenuMotion = 'rise' | 'fade' | 'scale' | 'none';
607
+
608
+ /** What `helpers.menu()` renders: a menu's items in one of the styles. */
609
+ export interface MenuOptions {
610
+ /**
611
+ * `dropdowns` (the default): a header menu, one row with dropdowns under items that have
612
+ * children, a mega panel under items with a panel or heading children, and a disclosure on
613
+ * small screens. `inline`: one row of links, for footers, children flattened. `list`: a
614
+ * column with the whole tree, for sidebars.
615
+ */
616
+ readonly style?: MenuStyle | string;
617
+ /**
618
+ * How dropdowns and mega panels open, as `data-motion` on the `nav`: `rise` (the default)
619
+ * fades in and lifts, `fade` only fades, `scale` grows from the top edge, `none` switches.
620
+ * Another name is passed through for the theme's own stylesheet to style; the
621
+ * `--cms-nav-duration`, `--cms-nav-ease` and `--cms-nav-offset` variables tune every preset.
622
+ */
623
+ readonly motion?: MenuMotion | string;
624
+ /**
625
+ * The menu shown in the hamburger drawer on small screens, as another location's name or
626
+ * as items, so phones get a shorter tree than the desktop row. Left out, or a location
627
+ * without a menu, the drawer shows this menu's own tree (headings become group labels;
628
+ * panels are not shown).
629
+ */
630
+ readonly mobile?: string | readonly MenuItemView[];
631
+ /** Below which width the row folds into the hamburger menu: `md` (768px, the default) or `lg` (1024px). */
632
+ readonly collapse?: 'md' | 'lg' | string;
633
+ /** The `nav` element's accessible name; the location's label by default. */
634
+ readonly label?: string;
635
+ /** Class names for the `nav` element. */
636
+ readonly class?: string;
637
+ }
638
+
639
+ /** What `helpers.search()` renders. */
640
+ export interface SearchOptions {
641
+ /** The box's placeholder and accessible name; “Search” by default. */
642
+ readonly placeholder?: string;
643
+ /** `box` (the default), or `icon`: a button that opens the box. */
644
+ readonly style?: 'box' | 'icon' | string;
645
+ /** Class names for the form. */
646
+ readonly class?: string;
647
+ /** Entries under the box while someone types, from the site's search; on by default. */
648
+ readonly suggest?: boolean;
649
+ }
650
+
651
+ /** A reference field's target: an entry with its title and URL, or a record of another resource. */
652
+ export interface EntryReference {
653
+ readonly id: string;
654
+ readonly title: string;
655
+ /** The entry's public URL; null for records that are not on the site. */
656
+ readonly url: string | null;
657
+ }
658
+
659
+ /**
660
+ * A field's value on an entry view, by the field's kind: text, enums and slugs as strings,
661
+ * numbers and datetimes (Unix milliseconds) as numbers, booleans, media as `MediaView`,
662
+ * references as `EntryReference`, taxonomy terms as `TermLink[]`, groups as objects, and in
663
+ * full views blocks, rich text and Markdown as `RenderedBlock[]` (rich text and Markdown as
664
+ * one `core/richtext` block; render with `helpers.block`). A multiple field is the list of
665
+ * its kind's views; multiple rich text or Markdown is one `core/richtext` block per item.
666
+ * Absent and empty values are null.
667
+ */
668
+ export type FieldView =
669
+ | string | number | boolean | null
670
+ | readonly (string | number | boolean)[]
671
+ | MediaView | readonly MediaView[]
672
+ | EntryReference | readonly EntryReference[]
673
+ | readonly TermLink[]
674
+ | readonly RenderedBlock[]
675
+ | { readonly [name: string]: unknown };
676
+
677
+ export interface EntryView {
678
+ readonly id: string;
679
+ readonly title: string;
680
+ readonly url: string | null;
681
+ /** The collection's name, such as `posts`. */
682
+ readonly collection: string;
683
+ /** The collection's singular label, such as `Post`. */
684
+ readonly kind: string;
685
+ /** The publication date in the site's format; empty for unpublishable collections. */
686
+ readonly date: string;
687
+ /** Who wrote the entry, the main author first, for article collections; empty otherwise. */
688
+ readonly authors: readonly EntryAuthor[];
689
+ /** When the entry was last changed, in the site's format; empty for unpublishable collections. */
690
+ readonly updated: string;
691
+ /** Minutes to read the content at 200 words a minute, at least 1; 0 when there is no content. */
692
+ readonly readingTime: number;
693
+ readonly excerpt: string;
694
+ /** The answer up front, from the entry's summary field; empty when none. Themes show it before the content. */
695
+ readonly summary: string;
696
+ /**
697
+ * The entry's content as rendered blocks, empty in lists: its blocks fields (the `content`
698
+ * feature first of all) and its rich text and Markdown fields, each of those one
699
+ * `core/richtext` block, in the collection's field order. Render it with
700
+ * `helpers.block(entry.content)`; `fields` has each field's blocks apart.
701
+ */
702
+ readonly content: readonly RenderedBlock[];
703
+ /**
704
+ * The fields `content` is made of, in its order, each with the number of blocks it gave.
705
+ * These fields are not carried a second time: `fields.<name>` reads them from `content`
706
+ * (`withContentFields`), and a loop over `fields` skips them.
707
+ */
708
+ readonly contentFields: readonly (readonly [name: string, blocks: number])[];
709
+ readonly image: MediaView | null;
710
+ readonly terms: readonly { readonly label: string; readonly terms: readonly TermLink[] }[];
711
+ /**
712
+ * Every field by name with its typed value (see `FieldView`), so a theme can lay out a
713
+ * collection's own fields. Rich text, Markdown and blocks are present in full views only,
714
+ * and the ones in `contentFields` are not listed by `Object.keys`.
715
+ */
716
+ readonly fields: { readonly [name: string]: FieldView };
717
+ /** Scalar fields with values as labelled text, derived from `fields`, for a details list. */
718
+ readonly details: readonly { readonly label: string; readonly value: string }[];
719
+ /** The template an editor chose for this entry, such as `entry-wide`; null for the default. */
720
+ readonly template: string | null;
721
+ /** The entry's language code. */
722
+ readonly locale: string;
723
+ /** Comments, when the collection takes them and the view is full; else null. */
724
+ readonly comments: CommentsView | null;
725
+ /**
726
+ * Why the excerpt, content and fields are withheld from this visitor: `password` for a
727
+ * protected entry they have not unlocked, `members` for a members-only entry and a visitor
728
+ * who is not signed in or has none of its member roles. Null when the entry shows in full.
729
+ */
730
+ readonly locked: 'password' | 'members' | null;
731
+ /**
732
+ * Search results only: the text around the words that matched, as plain parts with the
733
+ * matched words flagged (`match`), for a theme to mark up, for example with `<mark>`.
734
+ */
735
+ readonly snippet?: readonly SnippetPart[];
736
+ }
737
+
738
+ /** What a members-only entry shows a reader who may not read it: not signed in, or without one of its roles. */
739
+ export interface MembersView {
740
+ readonly entry: EntryView;
741
+ /** The reader is signed in, without one of the entry's member roles: signing in again does not help. */
742
+ readonly signedIn: boolean;
743
+ /** The sign-in page, returning to the entry. */
744
+ readonly signIn: string;
745
+ /** The registration page, returning to the entry; null when the site does not take registrations. */
746
+ readonly register: string | null;
747
+ }
748
+
749
+ /** What the password form of a protected entry shows. */
750
+ export interface LockedView {
751
+ readonly entry: EntryView;
752
+ /** Where the form posts: the entry's own URL. */
753
+ readonly action: string;
754
+ /** Set after a wrong password. */
755
+ readonly error: boolean;
756
+ }
757
+
758
+ export interface Paging {
759
+ readonly page: number;
760
+ /** The last page. Search knows no total: there it is one past the current page while more follow. */
761
+ readonly pages: number;
762
+ /** The first page's URL; others add `page=N` to its query (`?page=N`, or `&page=N` after search's `?q=`). */
763
+ readonly base: string;
764
+ }
765
+
766
+ /** An author as their page shows them. */
767
+ export interface AuthorView {
768
+ readonly name: string;
769
+ readonly slug: string;
770
+ /** The author page. */
771
+ readonly url: string;
772
+ readonly avatar: string | null;
773
+ readonly bio: string;
774
+ readonly jobTitle: string;
775
+ readonly website: string | null;
776
+ /** Profiles elsewhere. */
777
+ readonly profiles: readonly string[];
778
+ }
779
+
780
+ export interface ArchiveView {
781
+ /** `home` is the latest posts on the front page; `author` an author's entries. */
782
+ readonly kind: 'home' | 'archive' | 'term' | 'search' | 'author';
783
+ /** author: who is shown. */
784
+ readonly author?: AuthorView;
785
+ /** The collection listed, such as `posts`; null for a search across collections. */
786
+ readonly collection: string | null;
787
+ /** term: the taxonomy, such as `category`. */
788
+ readonly taxonomy: string | null;
789
+ readonly title: string;
790
+ readonly description: string;
791
+ readonly entries: readonly EntryView[];
792
+ readonly paging: Paging;
793
+ /** search: the query. */
794
+ readonly query: string;
795
+ /** search: nothing had every word, so these entries have some of them. */
796
+ readonly loose?: boolean;
797
+ }
798
+
799
+ export interface SiteView {
800
+ readonly title: string;
801
+ readonly tagline: string;
802
+ /** The logo's URL from Settings → General, or null; `helpers.logo()` renders it. */
803
+ readonly logo: string | null;
804
+ /** The blog's URL, when posts are on the site. */
805
+ readonly blog: string | null;
806
+ /** Resolved menus by location; an unassigned primary location lists top-level pages. */
807
+ readonly menus: { readonly [location: string]: readonly MenuItemView[] };
808
+ /** The page's language. */
809
+ readonly locale: string;
810
+ /** The page in each of the site's languages; empty for a site with one language. */
811
+ readonly languages: readonly LanguageLink[];
812
+ /** Where the search form posts in this language, such as `/search` or `/fr/search`. */
813
+ readonly searchUrl: string;
814
+ /** The home page in this language, such as `/` or `/fr`. */
815
+ readonly homeUrl: string;
816
+ /** The blocks of the theme's widget areas, by area; render them with `helpers.block`. */
817
+ readonly areas: { readonly [area: string]: readonly RenderedBlock[] };
818
+ /** The template of the entry shown, such as `entry-blank`, so a layout can leave out its frame; null elsewhere. */
819
+ readonly template: string | null;
820
+ /** The page's own absolute URL, for sharing. */
821
+ readonly url: string;
822
+ /** The way to the page: home, the section, the parents, then the page itself without a URL. */
823
+ readonly breadcrumbs: readonly BreadcrumbView[];
824
+ }
825
+
826
+ /**
827
+ * A plugin's `ui.ts` `head` export: tags for the document head of every site page while the
828
+ * plugin is active, merged under the theme's and the page's own. `plugin.asset(path)` is the
829
+ * URL of a file in the plugin's `assets/`, for a stylesheet its blocks need.
830
+ */
831
+ export type PluginHead = (context: PluginHeadContext) => HeadValue;
832
+
833
+ /** What a plugin's `head` receives: the theme's context and the plugin's own `asset()`. */
834
+ export interface PluginHeadContext extends HeadContext {
835
+ readonly plugin: { readonly asset: (path: string) => string };
836
+ }
837
+
838
+ /** One step of a page's breadcrumbs; the current page has no `url`. */
839
+ export interface BreadcrumbView {
840
+ readonly label: string;
841
+ readonly url: string | null;
842
+ }
843
+
844
+ /** A heading of an entry's content, for `core/toc`: its anchor, text and level (2, 3 or 4). */
845
+ export interface HeadingView {
846
+ readonly id: string;
847
+ readonly text: string;
848
+ readonly level: number;
849
+ }
850
+
851
+ /** Plain JSON a theme's loaders return. */
852
+ export type ThemeData = { readonly [key: string]: unknown };
853
+
854
+ /** What the host gives every template. */
855
+ export interface ThemeHelpers {
856
+ /** The active theme's option values, defaults applied. */
857
+ readonly options: { readonly [name: string]: unknown };
858
+ /** The presets blocks pick from, the site's changes applied; `presetStyle(helpers.presets)` renders them as custom properties. */
859
+ readonly presets: Required<ThemePresets>;
860
+ /**
861
+ * What the theme's loaders returned: `layout` in the layout and head templates, `page` in
862
+ * the page's template. Empty when the theme has no loader for the page, or it failed.
863
+ */
864
+ readonly data: { readonly layout: ThemeData; readonly page: ThemeData };
865
+ /** The URL of a file in the theme's `assets/`, such as `asset('assets/theme.css')`; empty when it has none. */
866
+ asset(path: string): string;
867
+ /**
868
+ * Any icon of the catalog (`ICON_CATEGORIES`) in the site's icon style, as an SVG drawn from
869
+ * a cached sprite, sized by `class` (default `size-5`) and decorative unless `label` names it.
870
+ * Null for a name outside the catalog.
871
+ */
872
+ icon(name: string, options?: { readonly class?: string; readonly label?: string }): TemplateResult | null;
873
+ /**
874
+ * The page's breadcrumbs (`site.breadcrumbs`) as a `nav` of links, the current page last
875
+ * without one; null on the home page. `separator` is `chevron` (the default), `slash` or
876
+ * `arrow`; `home: false` leaves Home out. The `core/breadcrumbs` block renders the same.
877
+ */
878
+ breadcrumbs(options?: { readonly class?: string; readonly separator?: string; readonly home?: boolean }): TemplateResult | null;
879
+ /**
880
+ * A search form posting to the site's search page in the page's language: a box, or a
881
+ * button that opens one (`style: 'icon'`). The `core/search` block renders the same.
882
+ */
883
+ search(options?: SearchOptions): TemplateResult;
884
+ /** Rich text inside a block (`block.content.<field>`): HTML runs and embedded blocks. For block renderers; entry content is blocks. */
885
+ content(parts: readonly BodyPart[]): TemplateResult;
886
+ /** A block, or a list of them, through the theme's renderer, a plugin's component or the core one. */
887
+ block(block: RenderedBlock | readonly RenderedBlock[]): TemplateResult | null;
888
+ /**
889
+ * A list of blocks as the page's constrained layout (`div.cms-layout`): each block in an
890
+ * item at the content measure, or the wide, full or narrow one its Width field asks for, so
891
+ * a full-width group makes a band across the page while the text keeps the column. For the
892
+ * blocks root of a template and for widget areas that span the page; `block` renders a list
893
+ * that has its own width, such as a footer cell.
894
+ */
895
+ layout(blocks: readonly RenderedBlock[], options?: { readonly class?: string }): TemplateResult;
896
+ /** Whether a URL is the current page or one of its ancestors. */
897
+ isActive(url: string): boolean;
898
+ /** The site's logo as an image named after the site, or null when none is set; `class` sizes it (default `h-10 w-auto`). */
899
+ logo(options?: { readonly class?: string }): TemplateResult | null;
900
+ /**
901
+ * The page in the site's other languages (`site.languages`) as a `nav` of links, named by
902
+ * language name, flag, both or code; null on a site with one language. The `core/languages`
903
+ * block renders the same, so editors place a switcher in widget areas and content.
904
+ */
905
+ languages(options?: LanguageSwitcherOptions): TemplateResult | null;
906
+ /**
907
+ * A menu as a `nav`: the one assigned to a location (`site.menus[location]`), or items given
908
+ * directly. Dropdowns, mega panels and the small-screen disclosure come from the core
909
+ * renderer, so a theme writes one line; the `core/navigation` block renders the same, so
910
+ * editors place a menu in widget areas and content. Null for an empty menu.
911
+ */
912
+ menu(source: string | readonly MenuItemView[], options?: MenuOptions): TemplateResult | null;
913
+ }
914
+
915
+ /**
916
+ * What a page's templates know of the site: its title, logo, URLs, language, breadcrumbs,
917
+ * menus and languages. The layout and the head get all of `SiteView`, widget areas included.
918
+ */
919
+ export type SiteBasics = Pick<SiteView, 'title' | 'tagline' | 'logo' | 'locale' | 'homeUrl' | 'searchUrl' | 'url' | 'breadcrumbs' | 'menus' | 'languages'>;
920
+
921
+ /**
922
+ * What every template receives, as one object a template destructures for what it uses:
923
+ * `({ entry, helpers }) => ...`. Each kind of template adds its own keys, so a new value is a
924
+ * new key and never moves an argument.
925
+ */
926
+ export interface ThemeContext {
927
+ readonly site: SiteBasics;
928
+ readonly helpers: ThemeHelpers;
929
+ }
930
+ /** The frame around every page: the page's content inside it. */
931
+ export interface LayoutContext extends ThemeContext {
932
+ readonly site: SiteView;
933
+ readonly content: TemplateResult;
934
+ }
935
+ /** The document head of every page. */
936
+ export interface HeadContext extends ThemeContext {
937
+ readonly site: SiteView;
938
+ }
939
+ export interface EntryContext extends ThemeContext {
940
+ readonly entry: EntryView;
941
+ }
942
+ export interface ArchiveContext extends ThemeContext {
943
+ readonly view: ArchiveView;
944
+ }
945
+ export interface LockedContext extends ThemeContext {
946
+ readonly view: LockedView;
947
+ }
948
+ export interface MembersContext extends ThemeContext {
949
+ readonly view: MembersView;
950
+ }
951
+ /** A theme's renderer of one block type. */
952
+ export interface BlockContext extends ThemeContext {
953
+ readonly block: RenderedBlock;
954
+ }
955
+
956
+ /** An entry template, from `templates/entry.ts` or `templates/entry-<collection>.ts`. */
957
+ export type EntryTemplate = (context: EntryContext) => TemplateResult;
958
+ /** A list template: an archive, a term, the home page or search results. */
959
+ export type ArchiveTemplate = (context: ArchiveContext) => TemplateResult;
960
+ /** A block renderer that replaces the core one; null renders nothing. */
961
+ export type BlockRenderer = (context: BlockContext) => TemplateResult | null;
962
+
963
+ /**
964
+ * A theme's templates: the `theme` export of its `ui.ts`, or the default exports of its
965
+ * `templates/` files, assembled by `assembleSiteTheme`. The site picks the most specific one
966
+ * for each page (`entryTemplate`, `archiveTemplate`).
967
+ */
968
+ export interface SiteTheme {
969
+ /** The frame around every page. */
970
+ layout(context: LayoutContext): TemplateResult;
971
+ /** One entry: a post, a page or an entry of another collection. */
972
+ entry(context: EntryContext): TemplateResult;
973
+ /** A collection or term archive. Also the front page and search results when those are absent. */
974
+ archive(context: ArchiveContext): TemplateResult;
975
+ home?(context: ArchiveContext): TemplateResult;
976
+ search?(context: ArchiveContext): TemplateResult;
977
+ notFound?(context: ThemeContext): TemplateResult;
978
+ /** The form asking for a protected entry's password; the host draws a plain one otherwise. */
979
+ password?(context: LockedContext): TemplateResult;
980
+ /** What a members-only entry shows visitors who are not signed in; the host draws a plain sign-in prompt otherwise. */
981
+ members?(context: MembersContext): TemplateResult;
982
+ /** Tags for the document head: stylesheets, fonts, meta. The page's own title and meta win. */
983
+ head?(context: HeadContext): HeadValue;
984
+ /**
985
+ * More specific templates by name: `entry-<collection>`, `archive-<collection>`, `term` and
986
+ * `term-<taxonomy>`. A file `templates/entry-posts.ts` lands here as `entry-posts`.
987
+ */
988
+ readonly templates?: { readonly [name: string]: EntryTemplate | ArchiveTemplate };
989
+ /** Block renderers that replace the core ones, by block type. */
990
+ readonly blocks?: { readonly [type: string]: BlockRenderer };
991
+ }
992
+
993
+ /** Template files that fill the theme's named slots; every other file is a specific template. */
994
+ const TEMPLATE_FILES: { readonly [stem: string]: keyof SiteTheme } = { layout: 'layout', entry: 'entry', archive: 'archive', home: 'home', search: 'search', 'not-found': 'notFound', head: 'head', password: 'password' };
995
+ /** Names a specific template can have. */
996
+ export const SPECIFIC_TEMPLATE = /^(?:entry-[a-z][a-z0-9_-]*|archive-[a-z][a-z0-9_-]*|term(?:-[a-z][a-z0-9_-]*)?|author)$/;
997
+
998
+ /** The parts of a plugin registration a theme is assembled from. */
999
+ export interface ThemeSource {
1000
+ /** The `ui.ts` exports. */
1001
+ readonly ui?: { readonly [name: string]: unknown } | null;
1002
+ /** The `templates/*.ts` modules by file stem, such as `entry-posts`. */
1003
+ readonly templates?: { readonly [stem: string]: { readonly [name: string]: unknown } };
1004
+ }
1005
+
1006
+ /**
1007
+ * A plugin's theme: its `templates/` files, with the `ui.ts` `theme` export on top, slot by slot.
1008
+ * `templates/layout.ts`, `entry.ts`, `archive.ts`, `home.ts`, `search.ts`, `not-found.ts` and
1009
+ * `head.ts` fill the named slots; any other file is a specific template under its stem. A child
1010
+ * theme passes its parent, whose theme it is layered over. Undefined when neither ships
1011
+ * templates; the result still needs `siteThemeProblems` before use.
1012
+ */
1013
+ export function assembleSiteTheme(source: ThemeSource, parent?: ThemeSource): unknown {
1014
+ return parent ? layerSiteThemes(assembleOwnTheme(parent), assembleOwnTheme(source)) : assembleOwnTheme(source);
1015
+ }
1016
+
1017
+ /** A theme layered over another, slot by slot: the top's named templates, specific templates and blocks win. */
1018
+ export function layerSiteThemes(base: unknown, top: unknown): unknown {
1019
+ if (!base || typeof base !== 'object') return top;
1020
+ if (!top || typeof top !== 'object') return base;
1021
+ const under = base as { [name: string]: unknown };
1022
+ const over = top as { [name: string]: unknown };
1023
+ const merged: { [name: string]: unknown } = { ...under };
1024
+ for (const [name, value] of Object.entries(over)) if (value !== undefined && name !== 'templates' && name !== 'blocks') merged[name] = value;
1025
+ for (const name of ['templates', 'blocks']) {
1026
+ const both = { ...(under[name] as object | undefined), ...(over[name] as object | undefined) };
1027
+ if (Object.keys(both).length) merged[name] = both;
1028
+ }
1029
+ return merged;
1030
+ }
1031
+
1032
+ function assembleOwnTheme(source: ThemeSource): unknown {
1033
+ const theme: { [name: string]: unknown } = {};
1034
+ const specific: { [name: string]: unknown } = {};
1035
+ for (const [stem, module] of Object.entries(source.templates ?? {})) {
1036
+ const template = module && typeof module === 'object' ? module.default : undefined;
1037
+ const slot = TEMPLATE_FILES[stem];
1038
+ if (slot) theme[slot] = template;
1039
+ else specific[stem] = template;
1040
+ }
1041
+ const exported = source.ui?.theme;
1042
+ if (exported && typeof exported === 'object') {
1043
+ const { templates, ...rest } = exported as { [name: string]: unknown };
1044
+ Object.assign(theme, rest);
1045
+ if (templates && typeof templates === 'object') Object.assign(specific, templates);
1046
+ } else if (exported !== undefined) {
1047
+ return exported;
1048
+ }
1049
+ if (Object.keys(specific).length) theme.templates = specific;
1050
+ return Object.keys(theme).length ? theme : undefined;
1051
+ }
1052
+
1053
+ /** Problems with a theme's templates; empty when it can render the site. */
1054
+ export function siteThemeProblems(theme: unknown): string[] {
1055
+ if (!theme || typeof theme !== 'object') return ['The theme has no templates: add templates/layout.ts, entry.ts and archive.ts, or export theme from ui.ts.'];
1056
+ const value = theme as { [name: string]: unknown };
1057
+ const problems: string[] = [];
1058
+ for (const name of ['layout', 'entry', 'archive']) if (typeof value[name] !== 'function') problems.push(`theme.${name} must be a function.`);
1059
+ for (const name of ['home', 'search', 'notFound', 'head']) if (value[name] !== undefined && typeof value[name] !== 'function') problems.push(`theme.${name} must be a function.`);
1060
+ if (value.templates !== undefined) {
1061
+ if (typeof value.templates !== 'object' || value.templates === null) problems.push('theme.templates must map template names to functions.');
1062
+ else for (const [name, template] of Object.entries(value.templates)) {
1063
+ if (!SPECIFIC_TEMPLATE.test(name)) problems.push(`theme.templates.${name}: name it entry-<collection>, archive-<collection>, term, term-<taxonomy> or author.`);
1064
+ else if (typeof template !== 'function') problems.push(`theme.templates.${name} must be a function.`);
1065
+ }
1066
+ }
1067
+ if (value.blocks !== undefined && (typeof value.blocks !== 'object' || value.blocks === null || Object.values(value.blocks).some(entry => typeof entry !== 'function'))) problems.push('theme.blocks must map block types to functions.');
1068
+ return problems;
1069
+ }
1070
+
1071
+ /** What a site page shows, for choosing its template and loader. */
1072
+ export type TemplatePage =
1073
+ | { readonly kind: 'entry'; readonly collection: string; readonly template?: string | null }
1074
+ | Pick<ArchiveView, 'kind' | 'collection' | 'taxonomy'>
1075
+ | { readonly kind: 'not-found' };
1076
+
1077
+ /**
1078
+ * Template names for a page, most specific first. An entry: the template an editor chose,
1079
+ * `entry-<collection>`, `entry`. A term: `term-<taxonomy>`, `term`, `archive-<collection>`,
1080
+ * `archive`. The home page: `home`, `archive-<collection>`, `archive`. Search: `search`,
1081
+ * `archive`. An archive: `archive-<collection>`, `archive`. Loaders are picked from the same list.
1082
+ */
1083
+ export function templateCandidates(page: TemplatePage): string[] {
1084
+ if (page.kind === 'not-found') return ['not-found'];
1085
+ if (page.kind === 'entry') return [...new Set([...(page.template && SPECIFIC_TEMPLATE.test(page.template) && page.template.startsWith('entry-') ? [page.template] : []), `entry-${page.collection}`, 'entry'])];
1086
+ const archive = [...(page.collection ? [`archive-${page.collection}`] : []), 'archive'];
1087
+ if (page.kind === 'home') return ['home', ...archive];
1088
+ if (page.kind === 'search') return ['search', 'archive'];
1089
+ if (page.kind === 'term') return [...(page.taxonomy ? [`term-${page.taxonomy}`] : []), 'term', ...archive];
1090
+ if (page.kind === 'author') return ['author', ...archive];
1091
+ return archive;
1092
+ }
1093
+
1094
+ /** The theme's template of that name: a named slot (`entry`, `not-found`, ...) or a specific one. */
1095
+ function namedTemplate(theme: SiteTheme, name: string): unknown {
1096
+ const slot = TEMPLATE_FILES[name];
1097
+ return slot ? theme[slot] : theme.templates?.[name];
1098
+ }
1099
+
1100
+ /** The first of the candidates the theme has, or null. */
1101
+ export function pickTemplate(theme: SiteTheme, candidates: readonly string[]): string | null {
1102
+ return candidates.find(name => typeof namedTemplate(theme, name) === 'function') ?? null;
1103
+ }
1104
+
1105
+ /**
1106
+ * Give `entry.fields` the content fields, each the part of `entry.content` it gave. They are
1107
+ * defined as hidden properties, so a view sent to the browser carries its blocks once; the
1108
+ * browser's copy gets them back here. Returns the same entry.
1109
+ */
1110
+ export function withContentFields<Entry extends Pick<EntryView, 'content' | 'contentFields' | 'fields'>>(entry: Entry): Entry {
1111
+ let start = 0;
1112
+ for (const [name, count] of entry.contentFields ?? []) {
1113
+ const blocks = entry.content.slice(start, start + count);
1114
+ start += count;
1115
+ if (Object.isExtensible(entry.fields)) Object.defineProperty(entry.fields, name, { value: blocks, enumerable: false, configurable: true, writable: true });
1116
+ }
1117
+ return entry;
1118
+ }
1119
+
1120
+ /** The template for an entry: the one an editor chose, `entry-<collection>`, else `entry`. Give it the entry through `withContentFields`. */
1121
+ export function entryTemplate(theme: SiteTheme, collection: string, template?: string | null): EntryTemplate {
1122
+ const name = pickTemplate(theme, templateCandidates({ kind: 'entry', collection, template }));
1123
+ return name ? namedTemplate(theme, name) as EntryTemplate : theme.entry;
1124
+ }
1125
+
1126
+ /** The template for a list, most specific first (see `templateCandidates`). Everything falls back to `archive`. */
1127
+ export function archiveTemplate(theme: SiteTheme, view: Pick<ArchiveView, 'kind' | 'collection' | 'taxonomy'>): ArchiveTemplate {
1128
+ const name = pickTemplate(theme, templateCandidates(view));
1129
+ return name ? namedTemplate(theme, name) as ArchiveTemplate : theme.archive;
1130
+ }
1131
+
1132
+ /** Templates an editor can choose for one entry: the theme's `entry-*` templates, by name. */
1133
+ export function entryTemplateChoices(theme: SiteTheme | undefined): string[] {
1134
+ return Object.keys(theme?.templates ?? {}).filter(name => name.startsWith('entry-')).sort();
1135
+ }