From c70ec1ce1aff6072934add1f543576d5200c1b02 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 30 Aug 2024 18:45:49 +0100 Subject: [Video] Captions and alt text (#5009) * video settings modal in composer * show done button on web * rm download options * fix logic for showing settings button * add language picker (wip) * subtitle list with language select * send captions & alt text with video when posting * style "ensure you have selected a language" text * include aspect ratio with video * filter out captions where the lang is not set * rm log * fix label and add hint * minor scrubber fix --- src/lib/strings/helpers.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/lib/strings/helpers.ts') diff --git a/src/lib/strings/helpers.ts b/src/lib/strings/helpers.ts index b4ce64fa5..acd55da2d 100644 --- a/src/lib/strings/helpers.ts +++ b/src/lib/strings/helpers.ts @@ -1,3 +1,6 @@ +import {useCallback, useMemo} from 'react' +import Graphemer from 'graphemer' + export function enforceLen( str: string, len: number, @@ -23,6 +26,21 @@ export function enforceLen( return str } +export function useEnforceMaxGraphemeCount() { + const splitter = useMemo(() => new Graphemer(), []) + + return useCallback( + (text: string, maxCount: number) => { + if (splitter.countGraphemes(text) > maxCount) { + return splitter.splitGraphemes(text).slice(0, maxCount).join('') + } else { + return text + } + }, + [splitter], + ) +} + // https://stackoverflow.com/a/52171480 export function toHashCode(str: string, seed = 0): number { let h1 = 0xdeadbeef ^ seed, -- cgit 1.4.1