@brimsites/brimjs 0.0.0-stage → 1.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 (238) hide show
  1. package/LICENSE +110 -0
  2. package/README.md +22 -2
  3. package/bin/brim.js +5 -0
  4. package/dist/cli.js +3802 -0
  5. package/editor-dist/editor.css +1 -0
  6. package/editor-dist/editor.js +91 -0
  7. package/package.json +71 -3
  8. package/skills/brim-convert/SKILL.md +256 -0
  9. package/skills/brim-hosting/SKILL.md +221 -0
  10. package/src/astro-shim.d.ts +5 -0
  11. package/src/auth/accounts.ts +341 -0
  12. package/src/auth/password.ts +34 -0
  13. package/src/auth/permissions.ts +44 -0
  14. package/src/blocks/accordion/Accordion.astro +48 -0
  15. package/src/blocks/accordion/accordion.css +63 -0
  16. package/src/blocks/analytics/Analytics.astro +45 -0
  17. package/src/blocks/analytics/ConsentBanner.astro +41 -0
  18. package/src/blocks/analytics/analytics.client.ts +125 -0
  19. package/src/blocks/analytics/analytics.css +51 -0
  20. package/src/blocks/analytics/consent.ts +51 -0
  21. package/src/blocks/button/Button.astro +64 -0
  22. package/src/blocks/button/button.css +100 -0
  23. package/src/blocks/carousel/Carousel.astro +140 -0
  24. package/src/blocks/carousel/carousel.client.ts +153 -0
  25. package/src/blocks/carousel/carousel.css +181 -0
  26. package/src/blocks/data/icons.ts +285 -0
  27. package/src/blocks/data/image-shapes.ts +91 -0
  28. package/src/blocks/data/social-icons.ts +41 -0
  29. package/src/blocks/data/social-networks.ts +256 -0
  30. package/src/blocks/divider/Divider.astro +27 -0
  31. package/src/blocks/divider/divider.css +17 -0
  32. package/src/blocks/form/Captcha.astro +27 -0
  33. package/src/blocks/form/Form.astro +250 -0
  34. package/src/blocks/form/FormField.astro +138 -0
  35. package/src/blocks/form/Newsletter.astro +80 -0
  36. package/src/blocks/form/form.client.ts +339 -0
  37. package/src/blocks/form/form.css +271 -0
  38. package/src/blocks/gallery/ImageGallery.astro +126 -0
  39. package/src/blocks/gallery/gallery.css +43 -0
  40. package/src/blocks/gallery/lightbox.client.ts +178 -0
  41. package/src/blocks/gallery/lightbox.css +134 -0
  42. package/src/blocks/icon/Icon.astro +41 -0
  43. package/src/blocks/icon/icon.css +16 -0
  44. package/src/blocks/image/Image.astro +158 -0
  45. package/src/blocks/image/image.css +42 -0
  46. package/src/blocks/images.ts +64 -0
  47. package/src/blocks/in-editor.client.ts +8 -0
  48. package/src/blocks/listing/Listing.astro +288 -0
  49. package/src/blocks/listing/ListingCards.astro +48 -0
  50. package/src/blocks/listing/listing.css +136 -0
  51. package/src/blocks/listing/query.ts +363 -0
  52. package/src/blocks/map/Map.astro +75 -0
  53. package/src/blocks/map/map.css +32 -0
  54. package/src/blocks/schemas/accordion.ts +118 -0
  55. package/src/blocks/schemas/button.ts +78 -0
  56. package/src/blocks/schemas/carousel.ts +133 -0
  57. package/src/blocks/schemas/divider.ts +29 -0
  58. package/src/blocks/schemas/form-field-types.ts +29 -0
  59. package/src/blocks/schemas/form.ts +350 -0
  60. package/src/blocks/schemas/icon.ts +24 -0
  61. package/src/blocks/schemas/image-gallery.ts +54 -0
  62. package/src/blocks/schemas/image.ts +87 -0
  63. package/src/blocks/schemas/index.ts +33 -0
  64. package/src/blocks/schemas/listing.ts +14 -0
  65. package/src/blocks/schemas/map.ts +81 -0
  66. package/src/blocks/schemas/newsletter.ts +324 -0
  67. package/src/blocks/schemas/social-media.ts +348 -0
  68. package/src/blocks/schemas/text.ts +151 -0
  69. package/src/blocks/schemas/video.ts +57 -0
  70. package/src/blocks/search/Search.astro +147 -0
  71. package/src/blocks/search/search.css +69 -0
  72. package/src/blocks/search/state.ts +28 -0
  73. package/src/blocks/settings.ts +94 -0
  74. package/src/blocks/social/SocialMedia.astro +102 -0
  75. package/src/blocks/social/social-links.ts +16 -0
  76. package/src/blocks/social/social.css +31 -0
  77. package/src/blocks/theme.ts +35 -0
  78. package/src/blocks/types.ts +52 -0
  79. package/src/blocks/video/Video.astro +90 -0
  80. package/src/blocks/video/video-source.ts +77 -0
  81. package/src/blocks/video/video.client.ts +43 -0
  82. package/src/blocks/video/video.css +29 -0
  83. package/src/check.ts +1119 -0
  84. package/src/cli.ts +493 -0
  85. package/src/components/Blocks.astro +68 -0
  86. package/src/components/Field.astro +61 -0
  87. package/src/components/Footer.astro +36 -0
  88. package/src/components/Link.astro +18 -0
  89. package/src/components/MobileMenu.astro +77 -0
  90. package/src/components/Navbar.astro +42 -0
  91. package/src/components/RichText.astro +32 -0
  92. package/src/components/Seo.astro +202 -0
  93. package/src/components/Setting.astro +46 -0
  94. package/src/components/Shared.astro +17 -0
  95. package/src/components/Text.astro +91 -0
  96. package/src/components/blocks.css +86 -0
  97. package/src/components/index.ts +27 -0
  98. package/src/components/mobile-menu.client.ts +21 -0
  99. package/src/components/mobile-menu.css +52 -0
  100. package/src/components/text.css +48 -0
  101. package/src/config.ts +413 -0
  102. package/src/content/block-layout.ts +63 -0
  103. package/src/content/block-values.ts +48 -0
  104. package/src/content/content-check.ts +174 -0
  105. package/src/content/content-types.ts +408 -0
  106. package/src/content/drafts.ts +115 -0
  107. package/src/content/feed.ts +237 -0
  108. package/src/content/field-types.ts +107 -0
  109. package/src/content/history.ts +140 -0
  110. package/src/content/ids.ts +50 -0
  111. package/src/content/image-size.ts +212 -0
  112. package/src/content/image-sizes.ts +126 -0
  113. package/src/content/item-fields.ts +110 -0
  114. package/src/content/item-head.ts +126 -0
  115. package/src/content/item-image.ts +26 -0
  116. package/src/content/item-path.ts +122 -0
  117. package/src/content/items.ts +580 -0
  118. package/src/content/language-scopes.ts +40 -0
  119. package/src/content/media.ts +271 -0
  120. package/src/content/menus.ts +51 -0
  121. package/src/content/page-templates.ts +52 -0
  122. package/src/content/redirects.ts +112 -0
  123. package/src/content/references.ts +165 -0
  124. package/src/content/rich-text.ts +63 -0
  125. package/src/content/search.ts +167 -0
  126. package/src/content/seed.ts +229 -0
  127. package/src/content/site-settings.ts +111 -0
  128. package/src/content/sitemap.ts +143 -0
  129. package/src/content/store.ts +225 -0
  130. package/src/content/tags.ts +67 -0
  131. package/src/content/text-default.ts +139 -0
  132. package/src/content/types.ts +137 -0
  133. package/src/content/validate.ts +253 -0
  134. package/src/content/validation-error.ts +2 -0
  135. package/src/db/cached.ts +140 -0
  136. package/src/db/database.ts +15 -0
  137. package/src/db/libsql.ts +29 -0
  138. package/src/db/schema.ts +189 -0
  139. package/src/db/url.ts +44 -0
  140. package/src/editor/client/BlockSettings.tsx +1063 -0
  141. package/src/editor/client/Chrome.tsx +284 -0
  142. package/src/editor/client/ContentBrowser.tsx +1299 -0
  143. package/src/editor/client/Editor.tsx +1756 -0
  144. package/src/editor/client/HistoryPanel.tsx +114 -0
  145. package/src/editor/client/ImagesWidget.tsx +113 -0
  146. package/src/editor/client/Inspector.tsx +127 -0
  147. package/src/editor/client/ItemForm.tsx +535 -0
  148. package/src/editor/client/LinkWidget.tsx +440 -0
  149. package/src/editor/client/ListingPanel.tsx +99 -0
  150. package/src/editor/client/Login.tsx +338 -0
  151. package/src/editor/client/Menu.tsx +64 -0
  152. package/src/editor/client/PageSettings.tsx +270 -0
  153. package/src/editor/client/RedirectsSettings.tsx +130 -0
  154. package/src/editor/client/Resize.tsx +204 -0
  155. package/src/editor/client/Sidebar.tsx +51 -0
  156. package/src/editor/client/SiteMap.tsx +568 -0
  157. package/src/editor/client/SiteSettings.tsx +409 -0
  158. package/src/editor/client/TextTools.tsx +391 -0
  159. package/src/editor/client/Toolbar.tsx +449 -0
  160. package/src/editor/client/VideoUpload.tsx +251 -0
  161. package/src/editor/client/api.ts +417 -0
  162. package/src/editor/client/brand.ts +20 -0
  163. package/src/editor/client/connection.ts +98 -0
  164. package/src/editor/client/context.ts +19 -0
  165. package/src/editor/client/css.d.ts +2 -0
  166. package/src/editor/client/editor.css +4656 -0
  167. package/src/editor/client/fields.tsx +812 -0
  168. package/src/editor/client/icons.tsx +174 -0
  169. package/src/editor/client/keys.ts +15 -0
  170. package/src/editor/client/kinds.ts +289 -0
  171. package/src/editor/client/languages.ts +32 -0
  172. package/src/editor/client/main.tsx +100 -0
  173. package/src/editor/client/responses.ts +26 -0
  174. package/src/editor/client/rich-text.ts +326 -0
  175. package/src/editor/client/site-tree.ts +239 -0
  176. package/src/editor/client/theme.ts +55 -0
  177. package/src/editor/client/tsconfig.json +18 -0
  178. package/src/editor/client/tus.ts +137 -0
  179. package/src/editor/client/use-rect.ts +50 -0
  180. package/src/editor/client/widgets.tsx +1218 -0
  181. package/src/forms/captcha.ts +83 -0
  182. package/src/forms/define.ts +166 -0
  183. package/src/forms/fields.ts +197 -0
  184. package/src/forms/file-types.ts +108 -0
  185. package/src/forms/files.ts +216 -0
  186. package/src/forms/form-page.ts +9 -0
  187. package/src/forms/handler.ts +622 -0
  188. package/src/forms/spec.ts +89 -0
  189. package/src/forms/store.ts +96 -0
  190. package/src/forms/work.ts +50 -0
  191. package/src/icons/library.ts +144 -0
  192. package/src/icons/load.ts +63 -0
  193. package/src/index.ts +99 -0
  194. package/src/init.ts +257 -0
  195. package/src/integration.ts +469 -0
  196. package/src/mail/mailer.ts +197 -0
  197. package/src/mail/notify.ts +272 -0
  198. package/src/mail/settings.ts +173 -0
  199. package/src/mail/templates.ts +191 -0
  200. package/src/mcp/page-nodes.ts +209 -0
  201. package/src/mcp/server.ts +111 -0
  202. package/src/mcp/tools.ts +637 -0
  203. package/src/runtime/TemplatePage.astro +39 -0
  204. package/src/runtime/TemplatePageStatic.astro +13 -0
  205. package/src/runtime/admin-route.ts +80 -0
  206. package/src/runtime/connect.ts +53 -0
  207. package/src/runtime/content.ts +188 -0
  208. package/src/runtime/context.ts +131 -0
  209. package/src/runtime/form-files.ts +18 -0
  210. package/src/runtime/forms-route.ts +33 -0
  211. package/src/runtime/forms.ts +28 -0
  212. package/src/runtime/icons.ts +5 -0
  213. package/src/runtime/media.ts +175 -0
  214. package/src/runtime/middleware.ts +186 -0
  215. package/src/runtime/nav.ts +13 -0
  216. package/src/runtime/query-reads.ts +49 -0
  217. package/src/runtime/query-store.ts +16 -0
  218. package/src/runtime/request-state.ts +69 -0
  219. package/src/runtime/robots.ts +29 -0
  220. package/src/runtime/rss-static.ts +16 -0
  221. package/src/runtime/rss.ts +29 -0
  222. package/src/runtime/server.ts +29 -0
  223. package/src/runtime/sitemap.ts +34 -0
  224. package/src/runtime/template-paths.ts +34 -0
  225. package/src/runtime/uploads-route.ts +13 -0
  226. package/src/seed-cli.ts +253 -0
  227. package/src/server/auth.ts +31 -0
  228. package/src/server/fetch-image.ts +219 -0
  229. package/src/server/handler.ts +2106 -0
  230. package/src/server/http.ts +162 -0
  231. package/src/server/locales.ts +73 -0
  232. package/src/server/node.ts +57 -0
  233. package/src/server/query-params.ts +249 -0
  234. package/src/server/rate-limit.ts +72 -0
  235. package/src/server/video-host.ts +162 -0
  236. package/src/starter.ts +70 -0
  237. package/src/version.ts +4 -0
  238. package/src/virtual.d.ts +65 -0
@@ -0,0 +1,41 @@
1
+ export const SOCIAL_ICONS = {
2
+ facebook: `<path d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647Z"/>`,
3
+ x: `<path d="M14.234 10.162 22.977 0h-2.072l-7.591 8.824L7.251 0H.258l9.168 13.343L.258 24H2.33l8.016-9.318L16.749 24h6.993zm-2.837 3.299-.929-1.329L3.076 1.56h3.182l5.965 8.532.929 1.329 7.754 11.09h-3.182z"/>`,
4
+ linkedin: `<path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>`,
5
+ whatsapp: `<path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"/>`,
6
+ telegram: `<path d="M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"/>`,
7
+ pinterest: `<path d="M12.017 0C5.396 0 .029 5.367.029 11.987c0 5.079 3.158 9.417 7.618 11.162-.105-.949-.199-2.403.041-3.439.219-.937 1.406-5.957 1.406-5.957s-.359-.72-.359-1.781c0-1.663.967-2.911 2.168-2.911 1.024 0 1.518.769 1.518 1.688 0 1.029-.653 2.567-.992 3.992-.285 1.193.6 2.165 1.775 2.165 2.128 0 3.768-2.245 3.768-5.487 0-2.861-2.063-4.869-5.008-4.869-3.41 0-5.409 2.562-5.409 5.199 0 1.033.394 2.143.889 2.741.099.12.112.225.085.345-.09.375-.293 1.199-.334 1.363-.053.225-.172.271-.401.165-1.495-.69-2.433-2.878-2.433-4.646 0-3.776 2.748-7.252 7.92-7.252 4.158 0 7.392 2.967 7.392 6.923 0 4.135-2.607 7.462-6.233 7.462-1.214 0-2.354-.629-2.758-1.379l-.749 2.848c-.269 1.045-1.004 2.352-1.498 3.146 1.123.345 2.306.535 3.55.535 6.607 0 11.985-5.365 11.985-11.987C23.97 5.39 18.592.026 11.985.026L12.017 0z"/>`,
8
+ reddit: `<path d="M12 0C5.373 0 0 5.373 0 12c0 3.314 1.343 6.314 3.515 8.485l-2.286 2.286C.775 23.225 1.097 24 1.738 24H12c6.627 0 12-5.373 12-12S18.627 0 12 0Zm4.388 3.199c1.104 0 1.999.895 1.999 1.999 0 1.105-.895 2-1.999 2-.946 0-1.739-.657-1.947-1.539v.002c-1.147.162-2.032 1.15-2.032 2.341v.007c1.776.067 3.4.567 4.686 1.363.473-.363 1.064-.58 1.707-.58 1.547 0 2.802 1.254 2.802 2.802 0 1.117-.655 2.081-1.601 2.531-.088 3.256-3.637 5.876-7.997 5.876-4.361 0-7.905-2.617-7.998-5.87-.954-.447-1.614-1.415-1.614-2.538 0-1.548 1.255-2.802 2.803-2.802.645 0 1.239.218 1.712.585 1.275-.79 2.881-1.291 4.64-1.365v-.01c0-1.663 1.263-3.034 2.88-3.207.188-.911.993-1.595 1.959-1.595Zm-8.085 8.376c-.784 0-1.459.78-1.506 1.797-.047 1.016.64 1.429 1.426 1.429.786 0 1.371-.369 1.418-1.385.047-1.017-.553-1.841-1.338-1.841Zm7.406 0c-.786 0-1.385.824-1.338 1.841.047 1.017.634 1.385 1.418 1.385.785 0 1.473-.413 1.426-1.429-.046-1.017-.721-1.797-1.506-1.797Zm-3.703 4.013c-.974 0-1.907.048-2.77.135-.147.015-.241.168-.183.305.483 1.154 1.622 1.964 2.953 1.964 1.33 0 2.47-.81 2.953-1.964.057-.137-.037-.29-.184-.305-.863-.087-1.795-.135-2.769-.135Z"/>`,
9
+ instagram: `<g transform="scale(0.046875)"><path d="M256,49.471c67.266,0,75.233.257,101.8,1.469,24.562,1.121,37.9,5.224,46.778,8.674a78.052,78.052,0,0,1,28.966,18.845,78.052,78.052,0,0,1,18.845,28.966c3.45,8.877,7.554,22.216,8.674,46.778,1.212,26.565,1.469,34.532,1.469,101.8s-.257,75.233-1.469,101.8c-1.121,24.562-5.225,37.9-8.674,46.778a83.427,83.427,0,0,1-47.811,47.811c-8.877,3.45-22.216,7.554-46.778,8.674-26.56,1.212-34.527,1.469-101.8,1.469s-75.237-.257-101.8-1.469c-24.562-1.121-37.9-5.225-46.778-8.674a78.051,78.051,0,0,1-28.966-18.845,78.053,78.053,0,0,1-18.845-28.966c-3.45-8.877-7.554-22.216-8.674-46.778-1.212-26.564-1.469-34.532-1.469-101.8s.257-75.233,1.469-101.8c1.121-24.562,5.224-37.9,8.674-46.778A78.052,78.052,0,0,1,78.458,78.458a78.053,78.053,0,0,1,28.966-18.845c8.877-3.45,22.216-7.554,46.778-8.674,26.565-1.212,34.532-1.469,101.8-1.469m0-45.391c-68.418,0-77,.29-103.866,1.516-26.815,1.224-45.127,5.482-61.151,11.71a123.488,123.488,0,0,0-44.62,29.057A123.488,123.488,0,0,0,17.3,90.982C11.077,107.007,6.819,125.319,5.6,152.134,4.369,179,4.079,187.582,4.079,256S4.369,333,5.6,359.866c1.224,26.815,5.482,45.127,11.71,61.151a123.489,123.489,0,0,0,29.057,44.62,123.486,123.486,0,0,0,44.62,29.057c16.025,6.228,34.337,10.486,61.151,11.71,26.87,1.226,35.449,1.516,103.866,1.516s77-.29,103.866-1.516c26.815-1.224,45.127-5.482,61.151-11.71a128.817,128.817,0,0,0,73.677-73.677c6.228-16.025,10.486-34.337,11.71-61.151,1.226-26.87,1.516-35.449,1.516-103.866s-.29-77-1.516-103.866c-1.224-26.815-5.482-45.127-11.71-61.151a123.486,123.486,0,0,0-29.057-44.62A123.487,123.487,0,0,0,421.018,17.3C404.993,11.077,386.681,6.819,359.866,5.6,333,4.369,324.418,4.079,256,4.079Z"/><path d="M256,126.635A129.365,129.365,0,1,0,385.365,256,129.365,129.365,0,0,0,256,126.635Zm0,213.338A83.973,83.973,0,1,1,339.974,256,83.974,83.974,0,0,1,256,339.973Z"/><circle cx="390.476" cy="121.524" r="30.23"/></g>`,
10
+ youtube: `<path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/>`,
11
+ tiktok: `<path d="M12.525.02c1.31-.02 2.61-.01 3.91-.02.08 1.53.63 3.09 1.75 4.17 1.12 1.11 2.7 1.62 4.24 1.79v4.03c-1.44-.05-2.89-.35-4.2-.97-.57-.26-1.1-.59-1.62-.93-.01 2.92.01 5.84-.02 8.75-.08 1.4-.54 2.79-1.35 3.94-1.31 1.92-3.58 3.17-5.91 3.21-1.43.08-2.86-.31-4.08-1.03-2.02-1.19-3.44-3.37-3.65-5.71-.02-.5-.03-1-.01-1.49.18-1.9 1.12-3.72 2.58-4.96 1.66-1.44 3.98-2.13 6.15-1.72.02 1.48-.04 2.96-.04 4.44-.99-.32-2.15-.23-3.02.37-.63.41-1.11 1.04-1.36 1.75-.21.51-.15 1.07-.14 1.61.24 1.64 1.82 3.02 3.5 2.87 1.12-.01 2.19-.66 2.77-1.61.19-.33.4-.67.41-1.06.1-1.79.06-3.57.07-5.36.01-4.03-.01-8.05.02-12.07z"/>`,
12
+ github: `<path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/>`,
13
+ discord: `<path d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z"/>`,
14
+ twitch: `<path d="M11.571 4.714h1.715v5.143H11.57zm4.715 0H18v5.143h-1.714zM6 0L1.714 4.286v15.428h5.143V24l4.286-4.286h3.428L22.286 12V0zm14.571 11.143l-3.428 3.428h-3.429l-3 3v-3H6.857V1.714h13.714Z"/>`,
15
+ vimeo: `<path d="M23.9765 6.4168c-.105 2.338-1.739 5.5429-4.894 9.6088-3.2679 4.247-6.0258 6.3699-8.2898 6.3699-1.409 0-2.578-1.294-3.553-3.881l-1.9179-7.1138c-.719-2.584-1.488-3.878-2.312-3.878-.179 0-.806.378-1.8809 1.132l-1.129-1.457a315.06 315.06 0 003.501-3.1279c1.579-1.368 2.765-2.085 3.5539-2.159 1.867-.18 3.016 1.1 3.447 3.838.465 2.953.789 4.789.971 5.5069.5389 2.45 1.1309 3.674 1.7759 3.674.502 0 1.256-.796 2.265-2.385 1.004-1.589 1.54-2.797 1.612-3.628.144-1.371-.395-2.061-1.614-2.061-.574 0-1.167.121-1.777.391 1.186-3.8679 3.434-5.7568 6.7619-5.6368 2.4729.06 3.6279 1.664 3.4929 4.7969z"/>`,
16
+ dribbble: `<path d="M12 24C5.385 24 0 18.615 0 12S5.385 0 12 0s12 5.385 12 12-5.385 12-12 12zm10.12-10.358c-.35-.11-3.17-.953-6.384-.438 1.34 3.684 1.887 6.684 1.992 7.308 2.3-1.555 3.936-4.02 4.395-6.87zm-6.115 7.808c-.153-.9-.75-4.032-2.19-7.77l-.066.02c-5.79 2.015-7.86 6.025-8.04 6.4 1.73 1.358 3.92 2.166 6.29 2.166 1.42 0 2.77-.29 4-.814zm-11.62-2.58c.232-.4 3.045-5.055 8.332-6.765.135-.045.27-.084.405-.12-.26-.585-.54-1.167-.832-1.74C7.17 11.775 2.206 11.71 1.756 11.7l-.004.312c0 2.633.998 5.037 2.634 6.855zm-2.42-8.955c.46.008 4.683.026 9.477-1.248-1.698-3.018-3.53-5.558-3.8-5.928-2.868 1.35-5.01 3.99-5.676 7.17zM9.6 2.052c.282.38 2.145 2.914 3.822 6 3.645-1.365 5.19-3.44 5.373-3.702-1.81-1.61-4.19-2.586-6.795-2.586-.825 0-1.63.1-2.4.285zm10.335 3.483c-.218.29-1.935 2.493-5.724 4.04.24.49.47.985.68 1.486.08.18.15.36.22.53 3.41-.43 6.8.26 7.14.33-.02-2.42-.88-4.64-2.31-6.38z"/>`,
17
+ email: `<path d="M2 4h20v16H2z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="m22 6-10 7L2 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>`,
18
+ phone: `<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6A19.79 19.79 0 0 1 2.11 4.18 2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.12.91.33 1.79.62 2.64a2 2 0 0 1-.45 2.11L8.09 9.68a16 16 0 0 0 6.23 6.23l1.21-1.19a2 2 0 0 1 2.11-.45c.85.29 1.73.5 2.64.62A2 2 0 0 1 22 16.92Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>`,
19
+ } as const;
20
+
21
+ export type SocialIconName = keyof typeof SOCIAL_ICONS;
22
+
23
+ export const SOCIAL_ICON_COLORS: Record<SocialIconName, string> = {
24
+ facebook: "#0866ff",
25
+ x: "#000000",
26
+ linkedin: "#0a66c2",
27
+ whatsapp: "#25d366",
28
+ telegram: "#26a5e4",
29
+ pinterest: "#bd081c",
30
+ reddit: "#ff4500",
31
+ instagram: "#e4405f",
32
+ youtube: "#ff0000",
33
+ tiktok: "#000000",
34
+ github: "#181717",
35
+ discord: "#5865f2",
36
+ twitch: "#9146ff",
37
+ vimeo: "#1ab7ea",
38
+ dribbble: "#ea4c89",
39
+ email: "currentColor",
40
+ phone: "currentColor",
41
+ };
@@ -0,0 +1,256 @@
1
+ import type { SocialIconName } from "./social-icons.ts";
2
+
3
+ export type SharePayload = {
4
+ url: string;
5
+ title: string;
6
+ text: string;
7
+ };
8
+
9
+ export type SocialNetworkConfig = {
10
+ key: string;
11
+ label: string;
12
+ icon: SocialIconName;
13
+ profileField: string;
14
+ allowedHosts?: string[];
15
+ allowedProtocols?: string[];
16
+ share?: (payload: SharePayload) => string;
17
+ };
18
+
19
+ export type SocialActionItem = SocialNetworkConfig & {
20
+ actionUrl: string;
21
+ actionKind: "share" | "profile";
22
+ };
23
+
24
+ export const SOCIAL_NETWORKS: SocialNetworkConfig[] = [
25
+ {
26
+ key: "facebook",
27
+ label: "Facebook",
28
+ icon: "facebook",
29
+ profileField: "facebookUrl",
30
+ allowedHosts: ["facebook.com", "fb.com"],
31
+ share: ({ url }) => `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`,
32
+ },
33
+ {
34
+ key: "x",
35
+ label: "X",
36
+ icon: "x",
37
+ profileField: "xUrl",
38
+ allowedHosts: ["x.com", "twitter.com"],
39
+ share: ({ url, text }) =>
40
+ `https://twitter.com/intent/tweet?url=${encodeURIComponent(url)}&text=${encodeURIComponent(text)}`,
41
+ },
42
+ {
43
+ key: "linkedin",
44
+ label: "LinkedIn",
45
+ icon: "linkedin",
46
+ profileField: "linkedinUrl",
47
+ allowedHosts: ["linkedin.com"],
48
+ share: ({ url }) => `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`,
49
+ },
50
+ {
51
+ key: "whatsapp",
52
+ label: "WhatsApp",
53
+ icon: "whatsapp",
54
+ profileField: "whatsappUrl",
55
+ allowedHosts: ["wa.me", "whatsapp.com", "api.whatsapp.com"],
56
+ share: ({ url, text }) => `https://wa.me/?text=${encodeURIComponent(`${text} ${url}`)}`,
57
+ },
58
+ {
59
+ key: "telegram",
60
+ label: "Telegram",
61
+ icon: "telegram",
62
+ profileField: "telegramUrl",
63
+ allowedHosts: ["t.me", "telegram.me", "telegram.org"],
64
+ share: ({ url, text }) => `https://t.me/share/url?url=${encodeURIComponent(url)}&text=${encodeURIComponent(text)}`,
65
+ },
66
+ {
67
+ key: "pinterest",
68
+ label: "Pinterest",
69
+ icon: "pinterest",
70
+ profileField: "pinterestUrl",
71
+ allowedHosts: ["pinterest.com"],
72
+ share: ({ url, text }) =>
73
+ `https://pinterest.com/pin/create/button/?url=${encodeURIComponent(url)}&description=${encodeURIComponent(text)}`,
74
+ },
75
+ {
76
+ key: "reddit",
77
+ label: "Reddit",
78
+ icon: "reddit",
79
+ profileField: "redditUrl",
80
+ allowedHosts: ["reddit.com"],
81
+ share: ({ url, text }) =>
82
+ `https://www.reddit.com/submit?url=${encodeURIComponent(url)}&title=${encodeURIComponent(text)}`,
83
+ },
84
+ {
85
+ key: "instagram",
86
+ label: "Instagram",
87
+ icon: "instagram",
88
+ profileField: "instagramUrl",
89
+ allowedHosts: ["instagram.com"],
90
+ },
91
+ {
92
+ key: "youtube",
93
+ label: "YouTube",
94
+ icon: "youtube",
95
+ profileField: "youtubeUrl",
96
+ allowedHosts: ["youtube.com", "youtu.be"],
97
+ },
98
+ {
99
+ key: "tiktok",
100
+ label: "TikTok",
101
+ icon: "tiktok",
102
+ profileField: "tiktokUrl",
103
+ allowedHosts: ["tiktok.com"],
104
+ },
105
+ {
106
+ key: "github",
107
+ label: "GitHub",
108
+ icon: "github",
109
+ profileField: "githubUrl",
110
+ allowedHosts: ["github.com"],
111
+ },
112
+ {
113
+ key: "discord",
114
+ label: "Discord",
115
+ icon: "discord",
116
+ profileField: "discordUrl",
117
+ allowedHosts: ["discord.gg", "discord.com"],
118
+ },
119
+ {
120
+ key: "twitch",
121
+ label: "Twitch",
122
+ icon: "twitch",
123
+ profileField: "twitchUrl",
124
+ allowedHosts: ["twitch.tv"],
125
+ },
126
+ {
127
+ key: "vimeo",
128
+ label: "Vimeo",
129
+ icon: "vimeo",
130
+ profileField: "vimeoUrl",
131
+ allowedHosts: ["vimeo.com"],
132
+ },
133
+ {
134
+ key: "dribbble",
135
+ label: "Dribbble",
136
+ icon: "dribbble",
137
+ profileField: "dribbbleUrl",
138
+ allowedHosts: ["dribbble.com"],
139
+ },
140
+ {
141
+ key: "email",
142
+ label: "Email",
143
+ icon: "email",
144
+ profileField: "emailUrl",
145
+ allowedProtocols: ["mailto"],
146
+ },
147
+ {
148
+ key: "phone",
149
+ label: "Phone",
150
+ icon: "phone",
151
+ profileField: "phoneUrl",
152
+ allowedProtocols: ["tel"],
153
+ },
154
+ ];
155
+
156
+ export const DEFAULT_SOCIAL_NETWORK_ORDER = SOCIAL_NETWORKS.map((network) => network.key);
157
+
158
+ export function normalizeSocialNetworkOrder(value: unknown): string[] {
159
+ const seen = new Set<string>();
160
+ const validKeys = new Set(DEFAULT_SOCIAL_NETWORK_ORDER);
161
+ const ordered = Array.isArray(value)
162
+ ? value.filter((key): key is string => {
163
+ if (typeof key !== "string" || !validKeys.has(key) || seen.has(key)) {
164
+ return false;
165
+ }
166
+ seen.add(key);
167
+ return true;
168
+ })
169
+ : [];
170
+
171
+ return [...ordered, ...DEFAULT_SOCIAL_NETWORK_ORDER.filter((key) => !seen.has(key))];
172
+ }
173
+
174
+ export function orderSocialNetworks(networks: SocialNetworkConfig[], value: unknown): SocialNetworkConfig[] {
175
+ const order = normalizeSocialNetworkOrder(value);
176
+ const rank = new Map(order.map((key, index) => [key, index]));
177
+
178
+ return [...networks].sort(
179
+ (a, b) => (rank.get(a.key) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.key) ?? Number.MAX_SAFE_INTEGER),
180
+ );
181
+ }
182
+
183
+ function hasValidHttpHostname(url: URL): boolean {
184
+ const hostname = url.hostname.trim();
185
+ if (!hostname) return false;
186
+ if (hostname === "localhost") return true;
187
+ if (/^\d{1,3}(?:\.\d{1,3}){3}$/.test(hostname)) return true;
188
+ if (hostname.includes(":")) return true;
189
+ return hostname.includes(".") && !hostname.includes("_");
190
+ }
191
+
192
+ export function normalizeSocialProfileUrl(value: unknown): string {
193
+ if (typeof value !== "string") return "";
194
+ const trimmed = value.trim();
195
+ if (!trimmed) return "";
196
+
197
+ const protocolMatch = trimmed.match(/^([a-z][a-z0-9+.-]*):/i);
198
+ const protocol = protocolMatch?.[1]?.toLowerCase();
199
+ if (protocol && !["http", "https", "mailto", "tel"].includes(protocol)) {
200
+ return "";
201
+ }
202
+
203
+ if (protocol === "mailto") {
204
+ const address = trimmed.slice("mailto:".length);
205
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(address) ? trimmed : "";
206
+ }
207
+
208
+ if (protocol === "tel") {
209
+ const phone = trimmed.slice("tel:".length);
210
+ return /^[+()0-9.\-\s]{3,}$/.test(phone) ? trimmed : "";
211
+ }
212
+
213
+ if (/\s/.test(trimmed)) return "";
214
+
215
+ const candidate = trimmed.startsWith("//") ? `https:${trimmed}` : protocol ? trimmed : `https://${trimmed}`;
216
+
217
+ try {
218
+ const url = new URL(candidate);
219
+ if (url.protocol !== "http:" && url.protocol !== "https:") return "";
220
+ if (!hasValidHttpHostname(url)) return "";
221
+ return url.toString();
222
+ } catch {
223
+ return "";
224
+ }
225
+ }
226
+
227
+ function isAllowedNetworkHostname(url: URL, allowedHosts: string[]): boolean {
228
+ const hostname = url.hostname.toLowerCase().replace(/\.$/, "");
229
+ return allowedHosts.some((host) => {
230
+ const normalizedHost = host.toLowerCase();
231
+ return hostname === normalizedHost || hostname.endsWith(`.${normalizedHost}`);
232
+ });
233
+ }
234
+
235
+ export function normalizeSocialNetworkProfileUrl(networkKey: string, value: unknown): string {
236
+ const normalized = normalizeSocialProfileUrl(value);
237
+ if (!normalized) return "";
238
+
239
+ const network = SOCIAL_NETWORKS.find((item) => item.key === networkKey);
240
+ if (!network) return normalized;
241
+
242
+ const protocol = normalized.match(/^([a-z][a-z0-9+.-]*):/i)?.[1] || "";
243
+ if (network.allowedProtocols?.length) {
244
+ return network.allowedProtocols.includes(protocol.toLowerCase()) ? normalized : "";
245
+ }
246
+
247
+ if (!network.allowedHosts?.length) return normalized;
248
+
249
+ try {
250
+ const url = new URL(normalized);
251
+ if (url.protocol !== "http:" && url.protocol !== "https:") return "";
252
+ return isAllowedNetworkHostname(url, network.allowedHosts) ? normalized : "";
253
+ } catch {
254
+ return "";
255
+ }
256
+ }
@@ -0,0 +1,27 @@
1
+ ---
2
+ import { defaultScope } from "../../runtime/request-state.ts";
3
+ import "./divider.css";
4
+ import type { NodeScope } from "../../runtime/context.ts";
5
+ import { divider } from "../schemas/divider.ts";
6
+
7
+ /**
8
+ * A line between two parts of a page. Its line is the site's CSS on `.brim-divider` (`border-color`, thickness,
9
+ * style); the owner chooses which way it runs. `class` goes on it.
10
+ */
11
+ interface Props {
12
+ nodeId: string;
13
+ scope?: NodeScope;
14
+ orientation?: "horizontal" | "vertical";
15
+ class?: string;
16
+ }
17
+
18
+ const { nodeId, scope = defaultScope(), class: className, ...source } = Astro.props;
19
+ const settings = Astro.locals.brim.settings(divider, nodeId, scope, source);
20
+ ---
21
+
22
+ <div
23
+ class:list={["brim-divider", className]}
24
+ role="separator"
25
+ aria-orientation={settings.orientation === "vertical" ? "vertical" : "horizontal"}
26
+ {...Astro.locals.brim.marker("divider", nodeId, scope, settings)}
27
+ ></div>
@@ -0,0 +1,17 @@
1
+ /* A plain line in the text's colour, with room around it. The site restyles `.brim-divider` as it likes. */
2
+ /* In the `brim` layer: any CSS of the site wins over it, whatever its selectors. */
3
+ @layer brim {
4
+ .brim-divider {
5
+ margin-block: var(--brim-divider-space, 1.5rem);
6
+ border-top: 1px solid currentColor;
7
+ opacity: 0.25;
8
+ }
9
+
10
+ .brim-divider[aria-orientation="vertical"] {
11
+ align-self: stretch;
12
+ min-height: 2rem;
13
+ margin: 0 var(--brim-divider-space, 1.5rem);
14
+ border-top: 0;
15
+ border-left: 1px solid currentColor;
16
+ }
17
+ }
@@ -0,0 +1,27 @@
1
+ ---
2
+ import config from "virtual:brim/config";
3
+ import { CAPTCHA_PROVIDERS } from "../../forms/captcha.ts";
4
+
5
+ /**
6
+ * The challenge a form asks for, when the config sets one: the provider's widget, which fills a hidden field the
7
+ * form sends. Its script is added once, however many forms the page has. Nothing at all without `forms.captcha`.
8
+ */
9
+ const captcha = config.captcha;
10
+ const provider = captcha ? CAPTCHA_PROVIDERS[captcha.provider] : undefined;
11
+ ---
12
+
13
+ {captcha && provider && (
14
+ <>
15
+ <div class:list={["brim-form__captcha", provider.widgetClass]} data-sitekey={captcha.siteKey} data-last-step />
16
+ <script is:inline define:vars={{ src: provider.script }}>
17
+ if (!document.querySelector("script[data-brim-captcha]")) {
18
+ const script = document.createElement("script");
19
+ script.src = src;
20
+ script.async = true;
21
+ script.defer = true;
22
+ script.dataset.brimCaptcha = "";
23
+ document.head.append(script);
24
+ }
25
+ </script>
26
+ </>
27
+ )}
@@ -0,0 +1,250 @@
1
+ ---
2
+ import { defaultScope } from "../../runtime/request-state.ts";
3
+ import "../button/button.css";
4
+ import "./form.css";
5
+ import type { FormDefinition } from "../../forms/define.ts";
6
+ import { type FormValue, formFields, formSteps } from "../../forms/fields.ts";
7
+ import Captcha from "./Captcha.astro";
8
+ import Field from "./FormField.astro";
9
+ import type { NodeScope } from "../../runtime/context.ts";
10
+ import { signForm, takesFormFiles } from "../../runtime/forms.ts";
11
+ import { form } from "../schemas/form.ts";
12
+ import { plainText } from "../theme.ts";
13
+
14
+ /**
15
+ * A contact form. What visitors send is kept with the site's content and shown in the editor.
16
+ * `fields` is the starting list; the owner can change it. Its look is the site's CSS: `.brim-form`,
17
+ * `.brim-form__field[data-type]`, `.brim-form__actions`, `.brim-form__success` and the rest keep their names.
18
+ *
19
+ * A field `{ type: "step", label: "…", help: "…" }` starts a step: the form is then asked in steps, with tabs, a
20
+ * progress bar and Back / Continue buttons, each step checked before the next. A field's `width: "half"` puts it next
21
+ * to another half; its `help` is a line under it. `buttonClass` gives the buttons the site's own classes.
22
+ *
23
+ * Pass a function to draw the fields in the site's own markup; Brim still draws the form around them (its sending,
24
+ * consent, button and messages). It gets the steps and fields, each field with the `id` its input takes, and `Field`,
25
+ * which draws one question:
26
+ *
27
+ * <Form nodeId="quote" fields={…}>
28
+ * {({ fields, Field }) => <div class="quote-grid">{fields.map((field) => <Field field={field} />)}</div>}
29
+ * </Form>
30
+ *
31
+ * In a form asked in steps, an element with `data-step="0"`, `data-step="1"`… is a step; `data-go-step`, `data-next-step`
32
+ * and `data-back-step` buttons move between them.
33
+ *
34
+ * `form={contact}` places a form declared once with `defineForm`: the same form wherever it is, edited once, kept in
35
+ * the site's shared content as `form-<key>`. Props given next to it (`buttonText`) still win where it is placed.
36
+ */
37
+ interface Props {
38
+ /** A form declared with `defineForm`; then `nodeId` and `scope` are the form's own unless given. */
39
+ form?: FormDefinition;
40
+ /** Required unless `form` is given. */
41
+ nodeId?: string;
42
+ scope?: NodeScope;
43
+ formName?: string;
44
+ infoText?: string;
45
+ /** The questions, in order; `{ type: "step", label, help }` starts a step. */
46
+ fields?: (
47
+ | {
48
+ name: string;
49
+ label: string;
50
+ type: string;
51
+ required?: boolean;
52
+ placeholder?: string;
53
+ options?: (string | { label: string; icon?: string; description?: string })[];
54
+ display?: "list" | "cards";
55
+ showWhen?: { field: string; equals: string | string[] };
56
+ width?: "full" | "half";
57
+ help?: string;
58
+ /** Of a `file` field: the kinds it takes, `["pdf", "jpg", "png", "webp"]` unless given. */
59
+ accept?: string[] | string;
60
+ /** Of a `file` field: several files (five at most) instead of one. */
61
+ multiple?: boolean;
62
+ }
63
+ | { type: "step"; label: string; help?: string }
64
+ )[];
65
+ buttonText?: string;
66
+ showConsent?: boolean;
67
+ consentText?: string;
68
+ consentLinkText?: string;
69
+ consentLinkUrl?: string;
70
+ consentRequired?: boolean;
71
+ successMessage?: string;
72
+ /** Email the visitor that their message arrived. Off unless set here or turned on by the owner. */
73
+ confirmationEmail?: boolean;
74
+ /** The `name` of the email field the confirmation goes to; the form's first email field without it. */
75
+ confirmationField?: string;
76
+ confirmationSubject?: string;
77
+ confirmationMessage?: string;
78
+ /** The confirmation also lists what the visitor answered (text, shortened). Off by default: see the README. */
79
+ confirmationAnswers?: boolean;
80
+ nextText?: string;
81
+ backText?: string;
82
+ /** Classes of the send and Continue buttons, the site's own instead of Brim's. */
83
+ buttonClass?: string;
84
+ /** In a form asked in steps: a step asking one single choice moves on by itself once it is answered. */
85
+ autoAdvance?: boolean;
86
+ /** Classes of the Back button; by default `buttonClass`. */
87
+ backClass?: string;
88
+ /** Classes of the form element itself. */
89
+ class?: string;
90
+ }
91
+
92
+ const {
93
+ form: declared,
94
+ nodeId: givenId,
95
+ scope: givenScope,
96
+ buttonClass = "brim-btn brim-btn--block brim-btn--md",
97
+ autoAdvance = false,
98
+ backClass = buttonClass,
99
+ class: className,
100
+ ...given
101
+ } = Astro.props;
102
+ const nodeId = givenId ?? declared?.nodeId;
103
+ if (!nodeId) throw new Error("<Form> needs a nodeId, or a form declared with defineForm: <Form form={contact} />.");
104
+ // A declared form is one form for the whole site, wherever it is placed.
105
+ const scope = givenScope ?? (declared ? "site" : defaultScope());
106
+ const source = { ...declared?.settings, ...given };
107
+ const settings = Astro.locals.brim.settings(form, nodeId, scope, source);
108
+
109
+ const id = (name: string): string => `${nodeId}-${name}`;
110
+ // A site with no private place for visitors' files (a static build, a host without private storage) asks for none.
111
+ const asked = takesFormFiles()
112
+ ? settings.fields
113
+ : (Array.isArray(settings.fields) ? settings.fields : []).filter(
114
+ (field) => (field as { type?: unknown } | null)?.type !== "file",
115
+ );
116
+ const steps = formSteps(asked).map((step) => ({
117
+ ...step,
118
+ fields: step.fields.map((field) => ({ ...field, id: id(field.name) })),
119
+ }));
120
+ const shown = steps.flatMap((step) => step.fields);
121
+ // What the server checks each answer against: the questions, without how they are laid out.
122
+ const fields = formFields(asked).map(({ width: _width, help: _help, display: _display, ...field }) => field);
123
+ const stepped = steps.length > 1;
124
+ const drawn = Astro.slots.has("default");
125
+ const content = drawn
126
+ ? await Astro.slots.render("default", [{ steps, fields: shown, Field } satisfies FormValue<typeof Field>])
127
+ : undefined;
128
+ // Responses are listed under the declared form's name even when its heading is left out of the page.
129
+ const title = String(settings.formName || declared?.settings.responsesName || "Form");
130
+ const consentRequired = settings.showConsent === true && settings.consentRequired === true;
131
+ const notify = typeof settings.notificationEmail === "string" ? settings.notificationEmail.trim() : "";
132
+ // The confirmation goes to one of the form's own email fields: the one chosen, else the first. A form without an
133
+ // email field sends none.
134
+ const text = (value: unknown, max: number): string => (typeof value === "string" ? plainText(value).slice(0, max) : "");
135
+ const confirmTo =
136
+ settings.confirmationEmail === true
137
+ ? (fields.find((field) => field.type === "email" && field.name === settings.confirmationField) ??
138
+ fields.find((field) => field.type === "email"))
139
+ : undefined;
140
+ const confirm = confirmTo && {
141
+ field: confirmTo.name,
142
+ subject: text(settings.confirmationSubject, 150),
143
+ message: text(settings.confirmationMessage, 5000),
144
+ ...(settings.confirmationAnswers === true && { answers: true }),
145
+ };
146
+ const signed = await signForm(
147
+ {
148
+ form: `${Astro.url.pathname}#${nodeId}`,
149
+ title,
150
+ fields,
151
+ consentRequired,
152
+ ...(notify && { notify }),
153
+ ...(confirm && { confirm }),
154
+ },
155
+ Astro.locals.brim.preview,
156
+ );
157
+ const info = plainText(settings.infoText);
158
+ const consentLink =
159
+ typeof settings.consentLinkUrl === "string" && /^(https?:\/\/|\/(?!\/))/i.test(settings.consentLinkUrl)
160
+ ? settings.consentLinkUrl
161
+ : undefined;
162
+ ---
163
+
164
+ <brim-form
165
+ class:list={["brim-form", className]}
166
+ data-spec={signed.spec}
167
+ data-signature={signed.signature}
168
+ data-stepped={stepped ? "" : undefined}
169
+ data-auto-advance={stepped && autoAdvance ? "" : undefined}
170
+ {...Astro.locals.brim.marker("form", nodeId, scope, settings)}
171
+ >
172
+ <form novalidate>
173
+ {settings.formName && <h2 class="brim-form__title">{settings.formName}</h2>}
174
+ {info && <p class="brim-form__info">{info}</p>}
175
+ {drawn ? (
176
+ <Fragment set:html={content} />
177
+ ) : stepped ? (
178
+ <>
179
+ <div class="brim-form__tabs" role="tablist">
180
+ {steps.map((step, index) => (
181
+ <button type="button" class="brim-form__tab" role="tab" data-go-step={index}>
182
+ <span class="brim-form__tab-number">{index + 1}</span>
183
+ <span class="brim-form__tab-title">{step.title}</span>
184
+ </button>
185
+ ))}
186
+ </div>
187
+ <div class="brim-form__progress" aria-hidden="true">
188
+ <span />
189
+ </div>
190
+ {steps.map((step, index) => (
191
+ <fieldset class="brim-form__step" data-step={index}>
192
+ <legend class="brim-form__step-title">{step.title}</legend>
193
+ {step.intro && <p class="brim-form__step-intro">{step.intro}</p>}
194
+ <div class="brim-form__fields">
195
+ {step.fields.map((field) => (
196
+ <Field field={field} />
197
+ ))}
198
+ </div>
199
+ </fieldset>
200
+ ))}
201
+ </>
202
+ ) : (
203
+ <div class="brim-form__fields">
204
+ {shown.map((field) => (
205
+ <Field field={field} />
206
+ ))}
207
+ </div>
208
+ )}
209
+ {/* Hidden from people; a script that fills every field gives itself away here. */}
210
+ <div class="brim-form__trap" aria-hidden="true">
211
+ <label>
212
+ Leave this field empty <input type="text" name="website" tabindex="-1" autocomplete="off" />
213
+ </label>
214
+ </div>
215
+ {settings.showConsent && (
216
+ <label class="brim-form__check brim-form__consent" data-last-step>
217
+ <input type="checkbox" name="consent" required={consentRequired} />
218
+ <span>
219
+ {settings.consentText}{" "}
220
+ {consentLink ? <a href={consentLink}>{settings.consentLinkText}</a> : settings.consentLinkText}
221
+ </span>
222
+ </label>
223
+ )}
224
+ {/* The challenge, when the site's forms ask for one: in a form asked in steps, on the last step. */}
225
+ <Captcha />
226
+ <div class="brim-form__actions">
227
+ {stepped && (
228
+ <button type="button" class:list={[backClass, "brim-form__back"]} data-back-step>
229
+ {settings.backText || "Back"}
230
+ </button>
231
+ )}
232
+ {stepped && (
233
+ <button type="button" class:list={[buttonClass, "brim-form__next"]} data-next-step>
234
+ {settings.nextText || "Continue"}
235
+ </button>
236
+ )}
237
+ <button type="submit" class:list={[buttonClass, "brim-form__submit"]} data-last-step>
238
+ {settings.buttonText}
239
+ </button>
240
+ </div>
241
+ <p class="brim-form__error" role="alert" hidden></p>
242
+ </form>
243
+ <p class="brim-form__success" role="status" hidden>
244
+ {plainText(settings.successMessage)}
245
+ </p>
246
+ </brim-form>
247
+
248
+ <script>
249
+ import "./form.client.ts";
250
+ </script>