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AAgD;QAChD,IAAI,UAAU,SAAS,CAAA,GAAA,cAAW,GAAG,MAAM,IAAI;YAC7C,WAAW,MAAM,IAAI,CAAC,SAAS,OAAO,EAAE,IAAI,CAAC,CAAA,IAAK,EAAE,GAAG,KAAK,WAAW;YACvE,IAAI,CAAC,UAAU;gBACb,WAAW,SAAS,aAAa,CAAC;gBAClC,SAAS,KAAK,GAAG;gBACjB,SAAS,GAAG,GAAG;gBACf,SAAS,IAAI,CAAC,WAAW,CAAC;YAC5B;QACF;QAEA,IAAI,UACF,SAAS,MAAM,GAAG;YAChB,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,eAAe,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,KAAK,YAChF,MAAM,CAAC,UAAU,CAAC,IAAI;QAE1B;IAEJ,GAAG;QAAC;QAAW;KAAO;IAEtB,4FAA4F;IAC5F,8BAA8B;IAC9B,IAAI,UAAU,SAAS,CAAA,GAAA,cAAW,GAAG,OAAO,IAC1C,qBAAO,gBAAC;QAAO,KAAK;QAAC,KAAK;QAAqB,KAAK;OAAb;IAGzC,+FAA+F;IAC/F,iGAAiG;IACjG,yCAAyC;IACzC,IAAI,cAAc,8BAAQ,CAAC,OAAO,QAAQ,CAAC,IAAI,+BAAS,EAAE;IAC1D,IAAI,eAAe,OAAO,CAAA,GAAA,eAAO,CAAC,CAAC,UAAU,KAAK,YAChD,KAAK,IAAI,OAAO,YACd,CAAA,GAAA,eAAO,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI;QACJ,MAAM;QACN,aAAa;IACf;IAIJ,OAAO;AACT","sources":["packages/@react-spectrum/s2/src/Fonts.tsx"],"sourcesContent":["import ReactDOM from 'react-dom';\nimport {ReactNode, version as ReactVersion, useEffect, useMemo, useRef} from 'react';\nimport {useLocale} from 'react-aria';\nimport './font-faces.css';\n\n// Typekit ids for each CJK locale. These use dynamic subsetting, so cannot be loaded as CSS.\n// Because of the large size of the JS, we only download the script for the locale that is used.\n// Each of these kits includes regular, bold, extra bold, and black weights. Spectrum 2 does not use any lighter weights.\nlet scripts = {\n ja: 'pyb4hbv',\n ko: 'pux4zom',\n 'zh-Hans': 'qwy0qqd',\n 'zh-CN': 'qwy0qqd',\n 'zh-SG': 'qwy0qqd',\n 'zh-HK': 'wrf0dsa',\n 'zh-Hant': 'twr1oiz',\n zh: 'twr1oiz'\n};\n\n// Font URLs from fonts.css to preload for each locale.\nlet preloads = {\n // Currently no preloads for arabic and hebrew, because we don't know which weights will be used ahead of time.\n // Browsers will emit warnings for unused preloads.\n // ar: [\n // 'https://use.typekit.net/af/dfb464/00000000000000007735a2f9/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n7&v=3',\n // 'https://use.typekit.net/af/560a53/00000000000000007735a300/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n4&v=3',\n // 'https://use.typekit.net/af/0f9162/00000000000000007735a307/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n6&v=3',\n // 'https://use.typekit.net/af/ab2792/00000000000000007735a309/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n9&v=3'\n // 'https://use.typekit.net/af/560a53/00000000000000007735a300/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n4&v=3'\n // ],\n // he: [\n // 'https://use.typekit.net/af/ffca46/00000000000000007735a30a/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n7&v=3',\n // 'https://use.typekit.net/af/e90860/00000000000000007735a313/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n4&v=3',\n // 'https://use.typekit.net/af/619974/00000000000000007735a31f/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n6&v=3'\n // 'https://use.typekit.net/af/e90860/00000000000000007735a313/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n4&v=3'\n // ],\n en: [\n // Preload Adobe Clean Spectrum VF.\n 'https://use.typekit.net/af/ca4cba/0000000000000000775c55a1/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n1&v=3'\n ]\n};\n\nexport function Fonts(): ReactNode {\n let {locale: localeString} = useLocale();\n let locale = useMemo(() => new Intl.Locale(localeString), [localeString]);\n let languageAndRegion = locale.language + (locale.region ? '-' + locale.region : '');\n let languageAndScript = locale.language + (locale.script ? '-' + locale.script : '');\n\n // Load script tag for CJK font\n let typekitId = scripts[locale.baseName] || scripts[languageAndRegion] || scripts[languageAndScript] || scripts[locale.language];\n let script = typekitId ? `https://use.typekit.net/${typekitId}.js` : null;\n\n let scriptRef = useRef<HTMLScriptElement | null>(null);\n useEffect(() => {\n let scriptEl = scriptRef.current;\n\n // In older React versions, we must manually insert scripts into the <head>.\n // Scripts rendered by React are never executed.\n if (script && parseInt(ReactVersion, 10) < 19) {\n scriptEl = Array.from(document.scripts).find(s => s.src === script) || null;\n if (!scriptEl) {\n scriptEl = document.createElement('script');\n scriptEl.async = true;\n scriptEl.src = script;\n document.head.appendChild(scriptEl);\n }\n }\n\n if (scriptEl) {\n scriptEl.onload = () => {\n if (typeof window['Typekit'] !== 'undefined' && typeof window['Typekit'].load === 'function') {\n window['Typekit'].load();\n }\n };\n }\n }, [scriptRef, script]);\n\n // When using React 19, async scripts are automatically deduped and hoisted into the <head>.\n // This also works during SSR.\n if (script && parseInt(ReactVersion, 10) >= 19) {\n return <script async src={script} key={script} ref={scriptRef} />;\n }\n\n // Preload fonts referenced by CSS file using React 19's preloading mechanism (when available).\n // This will insert a <link rel=\"preload\"> tag in the <head>, which is useful during SSR to start\n // font loading before the CSS downloads.\n let preloadUrls = preloads[locale.language] || preloads.en;\n if (preloadUrls && typeof ReactDOM['preload'] === 'function') {\n for (let url of preloadUrls) {\n ReactDOM.preload(url, {\n as: 'font',\n type: 'font/woff2',\n crossOrigin: ''\n });\n }\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"Fonts.mjs.map"}