bearminion 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/astro.js +5 -5
- package/dist/cli.js +761 -25
- package/dist/content.js +2 -2
- package/dist/hash-BeBymBO1.js +59 -0
- package/dist/index.js +4 -4
- package/dist/marks-DPBilumg.js +174 -0
- package/dist/marks.js +1 -174
- package/dist/{page-NOFVEqn1.js → page-X-WnOu7-.js} +1 -1
- package/dist/{preview--S1QUrMM.js → preview-B_88I5Jm.js} +1 -1
- package/dist/{reload-BPkPoQ-P.js → reload-Dkp3xC0l.js} +1 -1
- package/dist/rich-text-70hddxMC.js +403 -0
- package/dist/rich-text.js +1 -403
- package/dist/{sections-manifest-CU-xBjMi.js → sections-manifest-CO9QfJPG.js} +1 -1
- package/dist/{theme-DFjHjgFO.js → theme-Dv7_7B56.js} +2 -2
- package/dist/ui/mount.js +20 -7
- package/package.json +4 -1
- package/registry/default/files/src/components/atoms/Button.astro +64 -0
- package/registry/default/files/src/components/atoms/Emphasis.astro +24 -0
- package/registry/default/files/src/components/atoms/Image.astro +78 -0
- package/registry/default/files/src/components/atoms/Typography.astro +53 -0
- package/registry/default/files/src/components/atoms/button.ts +31 -0
- package/registry/default/files/src/components/atoms/image.ts +34 -0
- package/registry/default/files/src/components/atoms/options.ts +39 -0
- package/registry/default/files/src/components/atoms/typography.ts +64 -0
- package/registry/default/files/src/components/molecules/CommandLine.astro +109 -0
- package/registry/default/files/src/components/molecules/MediaFrame.astro +71 -0
- package/registry/default/files/src/components/molecules/Pill.astro +24 -0
- package/registry/default/files/src/components/molecules/SectionHeader.astro +63 -0
- package/registry/default/files/src/components/molecules/SectionShell.astro +33 -0
- package/registry/default/files/src/components/sections/contact/Contact.astro +231 -0
- package/registry/default/files/src/components/sections/contact/definition.ts +52 -0
- package/registry/default/files/src/components/sections/contact/form.ts +313 -0
- package/registry/default/files/src/components/sections/contact/wireframe.ts +15 -0
- package/registry/default/files/src/components/sections/cta/Cta.astro +206 -0
- package/registry/default/files/src/components/sections/cta/definition.ts +49 -0
- package/registry/default/files/src/components/sections/cta/wireframe.ts +9 -0
- package/registry/default/files/src/components/sections/faq/Faq.astro +136 -0
- package/registry/default/files/src/components/sections/faq/definition.ts +54 -0
- package/registry/default/files/src/components/sections/faq/wireframe.ts +19 -0
- package/registry/default/files/src/components/sections/features/Features.astro +146 -0
- package/registry/default/files/src/components/sections/features/definition.ts +54 -0
- package/registry/default/files/src/components/sections/features/wireframe.ts +19 -0
- package/registry/default/files/src/components/sections/gallery/Gallery.astro +128 -0
- package/registry/default/files/src/components/sections/gallery/definition.ts +59 -0
- package/registry/default/files/src/components/sections/gallery/lightbox.ts +159 -0
- package/registry/default/files/src/components/sections/gallery/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/hero/Hero.astro +185 -0
- package/registry/default/files/src/components/sections/hero/HeroBadge.astro +26 -0
- package/registry/default/files/src/components/sections/hero/definition.ts +74 -0
- package/registry/default/files/src/components/sections/hero/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/logo-strip/LogoStrip.astro +107 -0
- package/registry/default/files/src/components/sections/logo-strip/definition.ts +30 -0
- package/registry/default/files/src/components/sections/logo-strip/wireframe.ts +11 -0
- package/registry/default/files/src/components/sections/media/Media.astro +118 -0
- package/registry/default/files/src/components/sections/media/MediaPlayer.astro +176 -0
- package/registry/default/files/src/components/sections/media/definition.ts +77 -0
- package/registry/default/files/src/components/sections/media/source.ts +3 -0
- package/registry/default/files/src/components/sections/media/wireframe.ts +9 -0
- package/registry/default/files/src/components/sections/pricing/Pricing.astro +210 -0
- package/registry/default/files/src/components/sections/pricing/definition.ts +62 -0
- package/registry/default/files/src/components/sections/pricing/wireframe.ts +18 -0
- package/registry/default/files/src/components/sections/shared.ts +13 -0
- package/registry/default/files/src/components/sections/stats/Stats.astro +110 -0
- package/registry/default/files/src/components/sections/stats/definition.ts +41 -0
- package/registry/default/files/src/components/sections/stats/wireframe.ts +15 -0
- package/registry/default/files/src/components/sections/steps/Steps.astro +139 -0
- package/registry/default/files/src/components/sections/steps/definition.ts +62 -0
- package/registry/default/files/src/components/sections/steps/icons.ts +27 -0
- package/registry/default/files/src/components/sections/steps/wireframe.ts +16 -0
- package/registry/default/files/src/components/sections/testimonials/Testimonials.astro +172 -0
- package/registry/default/files/src/components/sections/testimonials/definition.ts +42 -0
- package/registry/default/files/src/components/sections/testimonials/wireframe.ts +21 -0
- package/registry/default/files/src/components/sections/text/Text.astro +43 -0
- package/registry/default/files/src/components/sections/text/definition.ts +36 -0
- package/registry/default/files/src/components/sections/text/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/text-image/TextImage.astro +107 -0
- package/registry/default/files/src/components/sections/text-image/definition.ts +39 -0
- package/registry/default/files/src/components/sections/text-image/wireframe.ts +12 -0
- package/registry/default/files/src/lib/assets.ts +13 -0
- package/registry/default/files/src/lib/cn.ts +6 -0
- package/registry/default/files/src/lib/contact-form.ts +97 -0
- package/registry/default/files/src/lib/hidden-text.ts +32 -0
- package/registry/default/files/src/lib/image-url.ts +38 -0
- package/registry/default/files/src/lib/link-attrs.ts +74 -0
- package/registry/default/registry.json +670 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { FormResult, FormSubmission } from 'bearminion'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Contact form's rules, apart from the page: what is sent, how an answer is read, and which submissions a
|
|
5
|
+
* person could not have made. `components/sections/contact/form.ts` wires them to the DOM.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** The spam-trap field. People never see it; many bots fill every field they find. Formspree uses the same name. */
|
|
9
|
+
export const HONEYPOT_FIELD = '_gotcha'
|
|
10
|
+
|
|
11
|
+
/** The field Cloudflare Turnstile's token is sent in, which `defineForm` from `bearminion/forms` checks on the server. */
|
|
12
|
+
export const TURNSTILE_FIELD = 'cf-turnstile-response'
|
|
13
|
+
|
|
14
|
+
/** A person needs longer than this to type a message. A submit sooner than this after the form appeared is a script. */
|
|
15
|
+
export const MIN_FILL_MS = 1500
|
|
16
|
+
|
|
17
|
+
/** Why a submission is dropped without being sent, or `null` when it should go out. */
|
|
18
|
+
export function botVerdict(trap: string, openedAt: number, now: number): 'honeypot' | 'too-fast' | null {
|
|
19
|
+
if (trap.trim() !== '') return 'honeypot'
|
|
20
|
+
if (now - openedAt < MIN_FILL_MS) return 'too-fast'
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The fields of a form as strings, plus where they came from. The trap field and any file input are left out. */
|
|
25
|
+
export function collectSubmission(entries: Iterable<[string, unknown]>, formId: string, page: string): FormSubmission {
|
|
26
|
+
const submission: FormSubmission = { formId, page }
|
|
27
|
+
for (const [name, value] of entries) {
|
|
28
|
+
if (name === HONEYPOT_FIELD || name === 'formId' || name === 'page' || typeof value !== 'string') continue
|
|
29
|
+
submission[name] = value
|
|
30
|
+
}
|
|
31
|
+
return submission
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Where every Contact form posts. The site's own handler, `src/forms/contact.ts`, answers here. */
|
|
35
|
+
export const FORM_ENDPOINT = '/api/contact'
|
|
36
|
+
|
|
37
|
+
export interface FormRequest {
|
|
38
|
+
url: string
|
|
39
|
+
init: RequestInit
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The request: the submission as JSON. The handler (`defineForm`) reads it and answers with JSON. */
|
|
43
|
+
export function buildRequest(submission: FormSubmission): FormRequest {
|
|
44
|
+
return {
|
|
45
|
+
url: FORM_ENDPOINT,
|
|
46
|
+
init: {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
|
49
|
+
body: JSON.stringify(submission),
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
55
|
+
const text = (value: unknown): string | undefined => (typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined)
|
|
56
|
+
|
|
57
|
+
/** Field errors from `fieldErrors: { email: '…' }`. */
|
|
58
|
+
function readFieldErrors(body: Record<string, unknown>): Record<string, string> | undefined {
|
|
59
|
+
if (!isRecord(body.fieldErrors)) return undefined
|
|
60
|
+
const found: Record<string, string> = {}
|
|
61
|
+
for (const [name, message] of Object.entries(body.fieldErrors)) {
|
|
62
|
+
const line = text(message)
|
|
63
|
+
if (line) found[name] = line
|
|
64
|
+
}
|
|
65
|
+
return Object.keys(found).length > 0 ? found : undefined
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** What to tell a visitor when the endpoint gave no message of its own. */
|
|
69
|
+
function fallbackError(status: number): string {
|
|
70
|
+
if (status === 429) return 'Too many messages in a short time. Wait a minute and try again.'
|
|
71
|
+
if (status >= 500) return 'The server had a problem. Try again in a moment.'
|
|
72
|
+
return 'The message was not accepted. Check the form and try again.'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Reads the handler's answer. The HTTP status decides: a 2xx is a success unless the body says `ok: false`. `body` is
|
|
77
|
+
* the parsed JSON, or `undefined` when there was none, which a 2xx treats as success.
|
|
78
|
+
*/
|
|
79
|
+
export function readResponse(status: number, body: unknown): FormResult {
|
|
80
|
+
const record = isRecord(body) ? body : {}
|
|
81
|
+
if (status >= 200 && status < 300 && record.ok !== false) {
|
|
82
|
+
const note = record.ok === true ? text(record.message) : undefined
|
|
83
|
+
return note ? { ok: true, message: note } : { ok: true }
|
|
84
|
+
}
|
|
85
|
+
const fieldErrors = readFieldErrors(record)
|
|
86
|
+
const error = text(record.error) ?? text(record.message) ?? fallbackError(status >= 200 && status < 300 ? 400 : status)
|
|
87
|
+
return fieldErrors ? { ok: false, error, fieldErrors } : { ok: false, error }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Shown when the request never got an answer: offline or blocked. */
|
|
91
|
+
export const NETWORK_ERROR = 'The message could not be sent. Check your connection and try again.'
|
|
92
|
+
|
|
93
|
+
/** Shown when the visitor sends before Turnstile has given its token. */
|
|
94
|
+
export const TURNSTILE_PENDING = 'The spam check is still running. Try again in a moment.'
|
|
95
|
+
|
|
96
|
+
/** Shown when Turnstile could not run: its script is blocked, or it reported an error. */
|
|
97
|
+
export const TURNSTILE_FAILED = 'The spam check could not run. Reload the page, turn off any blocker for this site, and try again.'
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps a contact detail (an email address, a phone number) out of the page's HTML, so a crawler that only reads markup
|
|
3
|
+
* does not harvest it. `hide` runs at build time and `reveal` in the browser.
|
|
4
|
+
*
|
|
5
|
+
* This is obfuscation, not encryption: the page has to show the value, so a browser, and any crawler that runs the
|
|
6
|
+
* page's script, can recover it. It stops the scrapers that match `@` and digits in the HTML, which is most of them.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const KEY = 'bearminion'
|
|
10
|
+
|
|
11
|
+
function scramble(bytes: Uint8Array): Uint8Array {
|
|
12
|
+
return bytes.map((byte, index) => byte ^ (KEY.charCodeAt(index % KEY.length) & 0xff))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** `value` as a short ASCII string that contains none of its characters. */
|
|
16
|
+
export function hide(value: string): string {
|
|
17
|
+
const scrambled = scramble(new TextEncoder().encode(value))
|
|
18
|
+
let binary = ''
|
|
19
|
+
for (const byte of scrambled) binary += String.fromCharCode(byte)
|
|
20
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The value `hide` was given. */
|
|
24
|
+
export function reveal(hidden: string): string {
|
|
25
|
+
const base64 = hidden.replace(/-/g, '+').replace(/_/g, '/')
|
|
26
|
+
const binary = atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4))
|
|
27
|
+
const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0))
|
|
28
|
+
return new TextDecoder().decode(scramble(bytes))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What a visitor without JavaScript reads where the value would be. */
|
|
32
|
+
export const HIDDEN_FALLBACK = 'Turn on JavaScript to see this, or use the form.'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getImage } from 'astro:assets'
|
|
2
|
+
import type { Image } from 'bearminion'
|
|
3
|
+
import { isRemote, resolveLocalAsset } from './assets'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An image as a plain URL, for attributes that take no `<img>`, such as a video's `poster`. A file in `src/assets` is
|
|
7
|
+
* optimized to WebP; a file uploaded in this dev session is served by the editor's dev route; a remote URL is used as
|
|
8
|
+
* it is. A missing file in `src/assets` fails the build, like a missing `<Image>`.
|
|
9
|
+
*/
|
|
10
|
+
/** Widths for a responsive `srcset`; none wider than the file itself. */
|
|
11
|
+
const SRCSET_WIDTHS = [480, 768, 1080, 1440, 1920]
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An image as a WebP `srcset`, for a plain `<img>` that is not an Astro `<Image>`, such as a video's cover. Undefined
|
|
15
|
+
* when the image is not a file in `src/assets` (a remote URL or a dev upload): then `imageUrl` alone is used.
|
|
16
|
+
*/
|
|
17
|
+
export async function imageSrcset(image: Image | undefined): Promise<string | undefined> {
|
|
18
|
+
if (!image || image.hidden || !image.src || image.src === 'placeholder' || isRemote(image.src)) return undefined
|
|
19
|
+
const asset = resolveLocalAsset(image.src.replace(/^\//, ''))
|
|
20
|
+
if (!asset) return undefined
|
|
21
|
+
const widths = SRCSET_WIDTHS.filter((width) => width < asset.width)
|
|
22
|
+
widths.push(Math.min(asset.width, SRCSET_WIDTHS.at(-1) ?? asset.width))
|
|
23
|
+
const sources = await Promise.all(widths.map(async (width) => `${(await getImage({ src: asset, width, format: 'webp' })).src} ${width}w`))
|
|
24
|
+
return sources.join(', ')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function imageUrl(image: Image | undefined, maxWidth = 1920): Promise<string | undefined> {
|
|
28
|
+
if (!image || image.hidden || !image.src || image.src === 'placeholder') return undefined
|
|
29
|
+
if (isRemote(image.src)) return image.src
|
|
30
|
+
const path = image.src.replace(/^\//, '')
|
|
31
|
+
const asset = resolveLocalAsset(path)
|
|
32
|
+
if (asset) return (await getImage({ src: asset, width: Math.min(asset.width, maxWidth), format: 'webp' })).src
|
|
33
|
+
if (path.startsWith('src/assets/')) {
|
|
34
|
+
if (import.meta.env.DEV) return `/__bearminion/assets?src=${encodeURIComponent(path)}`
|
|
35
|
+
throw new Error(`No file in src/assets for the image "${image.src}". Restore the file, or choose another image in the editor and save.`)
|
|
36
|
+
}
|
|
37
|
+
return image.src
|
|
38
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Attributes shared by every link and button renderer. */
|
|
2
|
+
|
|
3
|
+
export type ButtonStyleChoice = 'primary' | 'secondary' | 'tertiary'
|
|
4
|
+
export type ButtonRole = 'primary' | 'secondary' | 'strong' | 'ghost' | 'text'
|
|
5
|
+
|
|
6
|
+
export interface LinkFields {
|
|
7
|
+
href: string
|
|
8
|
+
style?: ButtonStyleChoice
|
|
9
|
+
newTab?: boolean
|
|
10
|
+
id?: string
|
|
11
|
+
trackingId?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Button look for a link. The editor's `style` wins; without it the section keeps its own design (`fallback`).
|
|
16
|
+
* On an accent background `primary` would vanish, so it becomes the inverted `strong` button there.
|
|
17
|
+
*/
|
|
18
|
+
export function buttonVariant(link: LinkFields, fallback: ButtonRole, onAccent = false): ButtonRole {
|
|
19
|
+
switch (link.style) {
|
|
20
|
+
case 'primary':
|
|
21
|
+
return onAccent ? 'strong' : 'primary'
|
|
22
|
+
case 'secondary':
|
|
23
|
+
return 'secondary'
|
|
24
|
+
case 'tertiary':
|
|
25
|
+
return 'text'
|
|
26
|
+
default:
|
|
27
|
+
return fallback
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Extra classes for a button on an accent background, where the default colors would not read. */
|
|
32
|
+
export function onAccentClass(variant: ButtonRole): string | undefined {
|
|
33
|
+
if (variant === 'secondary') return 'text-on! shadow-[inset_0_0_0_1px_color-mix(in_oklch,var(--on)_35%,transparent)]'
|
|
34
|
+
if (variant === 'text') return 'text-on!'
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function opensNewTab(link: LinkFields): boolean {
|
|
39
|
+
const external = /^https?:\/\//i.test(link.href)
|
|
40
|
+
return link.newTab === true || (link.newTab !== false && external)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Spread onto `<Button>`. `newTab` is a component prop, not an HTML attribute. */
|
|
44
|
+
export function buttonLinkProps(link: LinkFields): {
|
|
45
|
+
href: string
|
|
46
|
+
newTab?: boolean
|
|
47
|
+
id?: string
|
|
48
|
+
'data-analytics'?: string
|
|
49
|
+
} {
|
|
50
|
+
return {
|
|
51
|
+
href: link.href,
|
|
52
|
+
newTab: link.newTab,
|
|
53
|
+
id: link.id,
|
|
54
|
+
'data-analytics': link.trackingId,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Spread onto a plain `<a>`. */
|
|
59
|
+
export function anchorAttrs(link: LinkFields): {
|
|
60
|
+
href: string
|
|
61
|
+
id?: string
|
|
62
|
+
target?: '_blank'
|
|
63
|
+
rel?: 'noopener noreferrer'
|
|
64
|
+
'data-analytics'?: string
|
|
65
|
+
} {
|
|
66
|
+
const blank = opensNewTab(link)
|
|
67
|
+
return {
|
|
68
|
+
href: link.href,
|
|
69
|
+
id: link.id,
|
|
70
|
+
target: blank ? '_blank' : undefined,
|
|
71
|
+
rel: blank ? 'noopener noreferrer' : undefined,
|
|
72
|
+
'data-analytics': link.trackingId,
|
|
73
|
+
}
|
|
74
|
+
}
|