{"version":3,"sources":["utils.ts"],"sourcesContent":["import type { SearchTheme, SearchLayoutType } from \"./SearchModal.tsx\"\n\nexport const localStorageDebugFlag = (() => {\n    try {\n        return (\n            typeof window !== \"undefined\" &&\n            window.localStorage.__framerDebugSearch === \"true\"\n        )\n    } catch (e) {\n        // localStorage not available\n    }\n})()\n\nconst groupsRegex = /[A-Z]{2,}|[A-Z][a-z]+|[a-z]+|[A-Z]\\d*|\\d+/gu\n\nfunction capitalizeFirstLetter(value: string) {\n    return value.charAt(0).toUpperCase() + value.slice(1)\n}\nexport function titleCase(value: string): string {\n    const groups = value.match(groupsRegex) || []\n\n    return groups.map(capitalizeFirstLetter).join(\" \")\n}\n\nexport function clampText(text: string, maxLength: number) {\n    const textLength = text.length\n\n    if (textLength <= maxLength) {\n        return text\n    }\n\n    const slicedText = text.slice(0, maxLength)\n\n    if (textLength > maxLength) {\n        return slicedText + \"…\"\n    }\n\n    return slicedText\n}\n\nexport function isEmptyObject(object: any) {\n    return Object.keys(object).length === 0\n}\n\nexport function createLogger(showOutput: boolean) {\n    function log(...data: any[]) {\n        console.log(Date.now(), ...data)\n    }\n\n    function time(label?: string) {\n        console.time(label)\n    }\n\n    function timeEnd(label?: string) {\n        console.timeEnd(label)\n    }\n\n    function noop() {}\n\n    if (!showOutput) {\n        return { log: noop, time: noop, timeEnd: noop }\n    }\n\n    return {\n        log,\n        time,\n        timeEnd,\n    }\n}\n\nexport const DEFAULT_FONT_FAMILY = `\"Inter\", system-ui, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"`\n\nexport function getFontFamily(theme: SearchTheme) {\n    if (theme.inputFont?.fontFamily) return theme.inputFont.fontFamily\n    if (theme.titleFont?.fontFamily) return theme.titleFont.fontFamily\n    if (theme.subtitleFont?.fontFamily) return theme.subtitleFont.fontFamily\n    return DEFAULT_FONT_FAMILY\n}\n\nexport function animationKeyFromLayout(layout: SearchLayoutType) {\n    return `${layout}Animation`\n}\n\nexport const safeDocument = typeof document !== \"undefined\" ? document : null\nexport const safeWindow = typeof window !== \"undefined\" ? window : null\n\nconst metaTagSelector = 'meta[name=\"framer-search-index\"]'\n\nexport function getMetaTagContent() {\n    const metaTag = safeDocument?.querySelector(metaTagSelector)\n    if (!metaTag) return undefined\n\n    const metaTagContent = metaTag.getAttribute(\"content\")\n    return metaTagContent\n}\n\nexport const checkIfOverLimit = () => {\n    return getMetaTagContent() === \"limit-reached\"\n}\n\nexport function stripLocaleSlugFromPath(\n    url: string,\n    localeSlug: string | undefined\n) {\n    if (!localeSlug) return url\n\n    const localeSlugWithSlash = `/${localeSlug}`\n    if (url.startsWith(localeSlugWithSlash)) {\n        return url.slice(localeSlugWithSlash.length)\n    }\n}\n\ndeclare const scheduler:\n    | {\n          yield(options?: {\n              priority?: string\n              signal?: AbortSignal\n          }): Promise<void>\n      }\n    | {\n          postTask(\n              task: () => void,\n              options?: { priority?: string; signal?: AbortSignal }\n          ): Promise<void>\n      }\n    | object\n\n/**\n * @param isHighPriority If true and `scheduler.yield` is not available, the function will either use `postTask` or if also not available, return a resolved promise.\n */\nexport function yieldToMain(isHighPriority?: boolean): Promise<void> {\n    if (\"scheduler\" in window) {\n        // see https://github.com/WICG/scheduling-apis/blob/main/explainers/yield-and-continuation.md\n        // \"user-blocking\" is the highest priority and creates a paint opportunity.\n        // \"user-visible\" is the default, creates a paint opportunity, but has more potential to be delayed (by \"user-blocking\" tasks).\n        const options = {\n            priority: isHighPriority ? \"user-blocking\" : \"user-visible\",\n        }\n        if (\"yield\" in scheduler) return scheduler.yield(options)\n        if (\"postTask\" in scheduler)\n            return scheduler.postTask(() => {}, options)\n    }\n    if (isHighPriority) {\n        // `setTimeout` could suffer from being delayed for longer: https://developer.chrome.com/blog/introducing-scheduler-yield-origin-trial#the_problem_with_current_yielding_strategies\n        // so for browsers not supporting yield, we guarantee execution for high priority actions, but do not guarantee a paint opportunity as trade-off.\n        return Promise.resolve()\n    }\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