- gitgram-web (4): per-image alt-text accessibility, "New posts" load-latest pill - gitgram-backend (1): per-user muted words/tags moderation (MutedWord model + matcher) - gitgram-mobile (4): swipe-to-action list rows, soft-reset event bus (tap tab scroll-top) - aitm-api (7): gitnexus api_impact blast-radius/risk endpoints (reuse vendored gitnexus) - aitm-mcp (3): MCP handshake instructions, context-efficient beads output projections Note: gitgram-backend adds MutedWord Prisma model — run prisma migrate at deploy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
/**
|
|
* Alt-text preferences, ported from Bluesky's `alt-text-required` preference to
|
|
* the product's stack. The "require alt text" flag is stored alongside the
|
|
* existing accessibility settings (localStorage key
|
|
* `gitgram:accessibility-settings`) so it survives reloads without a dedicated
|
|
* backend endpoint, and is read by the composer to optionally block posting
|
|
* media that has no description.
|
|
*/
|
|
|
|
const ACCESSIBILITY_STORAGE_KEY = 'gitgram:accessibility-settings'
|
|
|
|
/** Max length for a single image description (mirrors Bluesky's 2000 cap). */
|
|
export const MAX_ALT_TEXT_LENGTH = 2000
|
|
|
|
interface AltTextPreferenceShape {
|
|
requireAltText?: boolean
|
|
}
|
|
|
|
/**
|
|
* Whether the user has opted into being required to add alt text before posting
|
|
* media. Defaults to `false` when unset or unavailable (SSR / private mode).
|
|
*/
|
|
export function isAltTextRequired(): boolean {
|
|
if (typeof window === 'undefined') return false
|
|
try {
|
|
const raw = window.localStorage.getItem(ACCESSIBILITY_STORAGE_KEY)
|
|
if (!raw) return false
|
|
const parsed = JSON.parse(raw) as AltTextPreferenceShape
|
|
return parsed.requireAltText === true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
/** Normalizes a raw alt-text input: trims and clamps to the max length. */
|
|
export function normalizeAltText(value: string): string {
|
|
return value.trim().slice(0, MAX_ALT_TEXT_LENGTH)
|
|
}
|