{"version":3,"sources":["utils.ts"],"sourcesContent":["import { isBrowser } from \"framer-motion\"\nimport { useLayoutEffect } from \"react\"\n\nexport const DEFAULT_FONT_FAMILY = `\"Inter\", system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"`\n\nexport type FlexboxPosition =\n    | \"top-left\"\n    | \"top-center\"\n    | \"top-right\"\n    | \"center-center\"\n    | \"bottom-right\"\n    | \"bottom-center\"\n    | \"bottom-left\"\n\nexport function getFlexboxValues(position: FlexboxPosition) {\n    const positionParts = position.split(\"-\")\n\n    let justifyContent: \"flex-start\" | \"flex-end\" | \"center\" | \"initial\",\n        alignItems: \"flex-start\" | \"flex-end\" | \"center\" | \"initial\"\n\n    switch (positionParts[0]) {\n        case \"top\":\n            alignItems = \"flex-start\"\n            break\n        case \"bottom\":\n            alignItems = \"flex-end\"\n            break\n        case \"center\":\n            alignItems = \"center\"\n            break\n        default:\n            alignItems = \"initial\"\n            break\n    }\n\n    switch (positionParts[1]) {\n        case \"left\":\n            justifyContent = \"flex-start\"\n            break\n        case \"right\":\n            justifyContent = \"flex-end\"\n            break\n        case \"center\":\n            justifyContent = \"center\"\n            break\n        default:\n            justifyContent = \"initial\"\n            break\n    }\n\n    return {\n        justifyContent,\n        alignItems,\n    } as const\n}\n\nexport function getMultipleShadows(...shadows: string[]) {\n    const output = []\n    shadows.forEach((shadow) => {\n        return shadow && output.push(shadow)\n    })\n    return output.join(\", \")\n}\n\nexport function getShadow(shadow) {\n    if (shadow) {\n        return `${shadow.shadowX}px ${shadow.shadowY}px ${shadow.shadowBlur}px ${shadow.shadowColor}`\n    } else return null\n}\n\nexport function safeJSONParse(jsonString: string, onError?: () => void) {\n    try {\n        return JSON.parse(jsonString)\n    } catch {\n        if (onError) onError()\n    }\n}\n\nexport const getCookie = (name: string, cookies?: string) => {\n    cookies = cookies ? cookies : isBrowser ? document.cookie : \"\"\n    const [, , cookie] = cookies.match(`(^|;) ?${name}=([^;]*)(;|$)`) ?? [\n        null,\n        null,\n        null,\n    ]\n\n    return cookie\n}\n\ninterface SchedulerOptions {\n    /**\n     * @see https://www.notion.so/framer/Sites-fc2114454aca4262bef725a39e5060bb?pvs=4#58d5b1f4188d4b1297eb0f3ec4761e17\n     * @see Can implicitly inherit the priority, see https://github.com/WICG/scheduling-apis/blob/main/explainers/yield-and-continuation.md#:~:text=highest%20scheduler%20priority.-,scheduler.yield(),-If%20a%20priority\n     */\n    priority?: \"user-blocking\" | \"user-visible\" | \"background\"\n    signal?: AbortSignal\n}\n\ndeclare const scheduler:\n    | { yield(options?: SchedulerOptions): Promise<void> }\n    | { postTask(task: () => void, options?: SchedulerOptions): Promise<void> }\n    | object\n\n/**\n * Yields to main thread before continuing execution, which might allow the browser to paint.\n * If `options.priority` is 'user-blocking', it will asynchronously resolve in older browsers.\n * @param {object} options - see https://github.com/WICG/scheduling-apis/blob/main/explainers/yield-and-continuation.md\n * @see interactionResponse for guaranteeing execution after a paint\n */\nexport function yieldToMain(options?: SchedulerOptions): Promise<void> {\n    if (\"scheduler\" in window) {\n        if (\"yield\" in scheduler) return scheduler.yield(options)\n        if (\"postTask\" in scheduler)\n            return scheduler.postTask(() => {}, options)\n    }\n\n    if (options?.priority === \"user-blocking\") {\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 this does not create space for a paint opportunity as trade-off.\n        return Promise.resolve()\n    }\n\n    return new Promise((resolve) => {\n        setTimeout(resolve)\n    })\n}\n\n/**\n * Helper function for `yieldToMain`, which yields before calling `fn`.\n * @see yieldToMain\n */\nexport async function yieldBeforeCb(\n    fn: CallableFunction,\n    options?: SchedulerOptions\n) {\n    await yieldToMain(options)\n    return fn()\n}\n\n/**\n * Similar to `yieldToMain`, but also waits for the next animation frame before yielding (with a fallback of 100ms if the animation frame never fires).\n * Compared to `yieldToMain`, it guarantees improved INP, but might make processing a little slower. Use only if necessary.\n * @see yieldToMain\n */\nexport function interactionResponse(options?: SchedulerOptions) {\n    return new Promise((resolve) => {\n        setTimeout(resolve, 200) // Fallback for the case where the animation frame never fires.\n        requestAnimationFrame(() => {\n            void yieldBeforeCb(resolve, options)\n        })\n    })\n}\n\n/**\n * Runs `fn` after the next paint. Similar to `useEffect`, but *guarantees* that the function is run after the next paint.\n * @important Does not support a cleanup fn.\n * @see https://thoughtspile.github.io/2021/11/15/unintentional-layout-effect/\n */\nexport function useAfterPaintEffect(\n    fn: CallableFunction,\n    deps?: React.DependencyList,\n    options?: SchedulerOptions\n) {\n    useLayoutEffect(() => {\n        const runAfterPaint = async () => {\n            await interactionResponse(options)\n            fn()\n        }\n\n        void runAfterPaint()\n\n        // eslint-disable-next-line react-hooks/exhaustive-deps -- deps are passed in\n    }, deps)\n}\n"],"names":[],"mappings":"AAAA,OAAS,SAAS,KAAQ,gBAAe,AACzC,OAAS,eAAe,KAAQ,QAAO,AAEvC,OAAO,MAAM,oBAAsB,CAAC,iKAAiK,CAAC,CAAA,AAWtM,OAAO,SAAS,iBAAiB,QAAyB,EACtD,MAAM,cAAgB,SAAS,KAAK,CAAC,KAErC,IAAI,eACA,WAEJ,OAAQ,aAAa,CAAC,EAAE,EACpB,IAAK,MACD,WAAa,aACb,MACJ,IAAK,SACD,WAAa,WACb,MACJ,IAAK,SACD,WAAa,SACb,MACJ,QACI,WAAa,UACb,MACR,CAEA,OAAQ,aAAa,CAAC,EAAE,EACpB,IAAK,OACD,eAAiB,aACjB,MACJ,IAAK,QACD,eAAiB,WACjB,MACJ,IAAK,SACD,eAAiB,SACjB,MACJ,QACI,eAAiB,UACjB,MACR,CAEA,MAAO,CACH,eACA,UACJ,EACJ,CAEA,OAAO,SAAS,mBAAmB,GAAG,OAAiB,EACnD,MAAM,OAAS,EAAE,CACjB,QAAQ,OAAO,CAAC,AAAC,SACb,OAAO,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