@wular/pnext 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/bin/pnext +9 -2
  2. package/dist/server/_chunks/aliases-j47a10ce.js +44 -0
  3. package/dist/server/_chunks/analyze-arswqe6s.js +445 -0
  4. package/dist/server/_chunks/boot-af0mv3dy.js +36 -0
  5. package/dist/server/_chunks/build-spy3dxp4.js +84 -0
  6. package/dist/server/_chunks/build-t9h0hec3.js +3550 -0
  7. package/dist/server/_chunks/build-tier-m7yvqz61.js +2472 -0
  8. package/dist/server/_chunks/compile-53j02j27.js +22 -0
  9. package/dist/server/_chunks/config-1yzwexq6.js +27 -0
  10. package/dist/server/_chunks/config-n2z7yxps.js +22 -0
  11. package/dist/server/_chunks/create-meec9hs6.js +134 -0
  12. package/dist/server/_chunks/dev-fjmqg6en.js +220 -0
  13. package/dist/server/_chunks/esbuild-yyktfrtt.js +15 -0
  14. package/dist/server/_chunks/generate-n9sh6hzt.js +21 -0
  15. package/dist/server/_chunks/index-0374j2b9.js +66 -0
  16. package/dist/server/_chunks/index-06nyqntx.js +213 -0
  17. package/dist/server/_chunks/index-1011cscr.js +5263 -0
  18. package/dist/server/_chunks/index-11sfk4hb.js +170 -0
  19. package/dist/server/_chunks/index-20ppawv7.js +297 -0
  20. package/dist/server/_chunks/index-2dv4y4wd.js +1065 -0
  21. package/dist/server/_chunks/index-2vz0wzdn.js +59 -0
  22. package/dist/server/_chunks/index-2wfv4kvx.js +182 -0
  23. package/dist/server/_chunks/index-357na4a8.js +109 -0
  24. package/dist/server/_chunks/index-3b3at80h.js +109 -0
  25. package/dist/server/_chunks/index-3tf1xjsp.js +6166 -0
  26. package/dist/server/_chunks/index-3xbr4eyv.js +105 -0
  27. package/dist/server/_chunks/index-4399bvd2.js +18 -0
  28. package/dist/server/_chunks/index-4hgjrqh7.js +851 -0
  29. package/dist/server/_chunks/index-4q2gbfwk.js +2530 -0
  30. package/dist/server/_chunks/index-4t92hdxd.js +172 -0
  31. package/dist/server/_chunks/index-4zzebszd.js +10 -0
  32. package/dist/server/_chunks/index-5gyr4emz.js +107 -0
  33. package/dist/server/_chunks/index-5hr4062s.js +70 -0
  34. package/dist/server/_chunks/index-68m3mwbd.js +84 -0
  35. package/dist/server/_chunks/index-6b009mt0.js +56 -0
  36. package/dist/server/_chunks/index-6e4fqv30.js +588 -0
  37. package/dist/server/_chunks/index-6gex3pfa.js +15 -0
  38. package/dist/server/_chunks/index-6kp9r0d9.js +11 -0
  39. package/dist/server/_chunks/index-6q7zvrap.js +134 -0
  40. package/dist/server/_chunks/index-73z4esab.js +38 -0
  41. package/dist/server/_chunks/index-79ngvam8.js +60 -0
  42. package/dist/server/_chunks/index-7wc9n8be.js +25 -0
  43. package/dist/server/_chunks/index-8k7pfejn.js +1599 -0
  44. package/dist/server/_chunks/index-8kcxdfya.js +206 -0
  45. package/dist/server/_chunks/index-91x12ykq.js +274 -0
  46. package/dist/server/_chunks/index-9ch50vtq.js +18 -0
  47. package/dist/server/_chunks/index-9hx2641q.js +28 -0
  48. package/dist/server/_chunks/index-9n2914ww.js +535 -0
  49. package/dist/server/_chunks/index-9ych9ma8.js +207 -0
  50. package/dist/server/_chunks/index-b6wtkdp4.js +24 -0
  51. package/dist/server/_chunks/index-bcws5eh2.js +35 -0
  52. package/dist/server/_chunks/index-c0g2wf3z.js +92 -0
  53. package/dist/server/_chunks/index-cf4rvxv6.js +95 -0
  54. package/dist/server/_chunks/index-cjgqs13g.js +65 -0
  55. package/dist/server/_chunks/index-ckkdpht5.js +41 -0
  56. package/dist/server/_chunks/index-cyfednwb.js +87 -0
  57. package/dist/server/_chunks/index-danncfhy.js +311 -0
  58. package/dist/server/_chunks/index-dg0f05zs.js +199 -0
  59. package/dist/server/_chunks/index-e3a6yx84.js +18 -0
  60. package/dist/server/_chunks/index-e88tyv35.js +45 -0
  61. package/dist/server/_chunks/index-eajaspjk.js +1253 -0
  62. package/dist/server/_chunks/index-eeaanp2e.js +483 -0
  63. package/dist/server/_chunks/index-egykcqg3.js +101 -0
  64. package/dist/server/_chunks/index-en7n9f7m.js +22 -0
  65. package/dist/server/_chunks/index-ezgj0tr1.js +88 -0
  66. package/dist/server/_chunks/index-fkp000p1.js +590 -0
  67. package/dist/server/_chunks/index-fn1chkkd.js +214 -0
  68. package/dist/server/_chunks/index-fp8r0sqs.js +64 -0
  69. package/dist/server/_chunks/index-ggk2j965.js +9432 -0
  70. package/dist/server/_chunks/index-grta8ap3.js +238 -0
  71. package/dist/server/_chunks/index-h2a70tg4.js +7 -0
  72. package/dist/server/_chunks/index-h4xy648y.js +51 -0
  73. package/dist/server/_chunks/index-hkdfj58q.js +92 -0
  74. package/dist/server/_chunks/index-j2zrcp1k.js +66 -0
  75. package/dist/server/_chunks/index-jcsjq3d1.js +20 -0
  76. package/dist/server/_chunks/index-jepjvcrf.js +198 -0
  77. package/dist/server/_chunks/index-jks0x0a1.js +14 -0
  78. package/dist/server/_chunks/index-jx7bqvw1.js +57 -0
  79. package/dist/server/_chunks/index-k1g3epw0.js +1299 -0
  80. package/dist/server/_chunks/index-knp0s912.js +7 -0
  81. package/dist/server/_chunks/index-kq8kpzye.js +472 -0
  82. package/dist/server/_chunks/index-kqyy1d4f.js +50 -0
  83. package/dist/server/_chunks/index-kresp2n8.js +445 -0
  84. package/dist/server/_chunks/index-ms9v9tnx.js +31 -0
  85. package/dist/server/_chunks/index-n4hxpng2.js +11 -0
  86. package/dist/server/_chunks/index-ncnes8c6.js +17 -0
  87. package/dist/server/_chunks/index-nqh3xhdc.js +57 -0
  88. package/dist/server/_chunks/index-nyrba2kr.js +4130 -0
  89. package/dist/server/_chunks/index-p77b4kcx.js +296 -0
  90. package/dist/server/_chunks/index-pym1cezq.js +39 -0
  91. package/dist/server/_chunks/index-q738kkhj.js +100 -0
  92. package/dist/server/_chunks/index-qjj6gddn.js +54 -0
  93. package/dist/server/_chunks/index-qm6kmhqs.js +110 -0
  94. package/dist/server/_chunks/index-qn4z5s3c.js +819 -0
  95. package/dist/server/_chunks/index-qpwsgt3a.js +158 -0
  96. package/dist/server/_chunks/index-r97ptz1q.js +97 -0
  97. package/dist/server/_chunks/index-ras0sdab.js +26 -0
  98. package/dist/server/_chunks/index-rcs322t1.js +19 -0
  99. package/dist/server/_chunks/index-rn8dyr1f.js +126 -0
  100. package/dist/server/_chunks/index-rt9qq1va.js +4 -0
  101. package/dist/server/_chunks/index-rthrsed5.js +356 -0
  102. package/dist/server/_chunks/index-sctcgyvv.js +185 -0
  103. package/dist/server/_chunks/index-sjpckxqn.js +213 -0
  104. package/dist/server/_chunks/index-sq3kvz3g.js +200 -0
  105. package/dist/server/_chunks/index-stbk3jhn.js +31 -0
  106. package/dist/server/_chunks/index-sv8m6789.js +266 -0
  107. package/dist/server/_chunks/index-tgcakdxc.js +125 -0
  108. package/dist/server/_chunks/index-tgsfjmep.js +74 -0
  109. package/dist/server/_chunks/index-tq0pc7eg.js +154 -0
  110. package/dist/server/_chunks/index-tq1f96v7.js +51 -0
  111. package/dist/server/_chunks/index-tqn2qnnn.js +241 -0
  112. package/dist/server/_chunks/index-tvqkq6e6.js +128 -0
  113. package/dist/server/_chunks/index-v1ags1na.js +132 -0
  114. package/dist/server/_chunks/index-vvmmknm1.js +1431 -0
  115. package/dist/server/_chunks/index-vvq7rqtn.js +329 -0
  116. package/dist/server/_chunks/index-vz0km5qk.js +33 -0
  117. package/dist/server/_chunks/index-w6h8m6vp.js +138 -0
  118. package/dist/server/_chunks/index-web361b8.js +138 -0
  119. package/dist/server/_chunks/index-wpfhfbs4.js +194 -0
  120. package/dist/server/_chunks/index-x0y005nh.js +283 -0
  121. package/dist/server/_chunks/index-x3yn4ywm.js +22 -0
  122. package/dist/server/_chunks/index-x93hv0sc.js +271 -0
  123. package/dist/server/_chunks/index-xvj80c3a.js +30 -0
  124. package/dist/server/_chunks/index-xywjg2vc.js +100 -0
  125. package/dist/server/_chunks/index-y2jr2n72.js +152 -0
  126. package/dist/server/_chunks/index-y36a0ybw.js +57 -0
  127. package/dist/server/_chunks/index-ye9hmsvf.js +47 -0
  128. package/dist/server/_chunks/index-yhxkxghe.js +56 -0
  129. package/dist/server/_chunks/index-ym67zqxp.js +130 -0
  130. package/dist/server/_chunks/index-ytjvpbm2.js +736 -0
  131. package/dist/server/_chunks/index-yz54pxrh.js +960 -0
  132. package/dist/server/_chunks/index-z4z9zv3b.js +733 -0
  133. package/dist/server/_chunks/index-z84ab1w0.js +1270 -0
  134. package/dist/server/_chunks/index-z88qv16t.js +11 -0
  135. package/dist/server/_chunks/index-zqpqyg8p.js +666 -0
  136. package/dist/server/_chunks/loader-7yw0j98z.js +78 -0
  137. package/dist/server/_chunks/modules-jn8bmbn8.js +74 -0
  138. package/dist/server/_chunks/pipeline-yy9jhydf.js +832 -0
  139. package/dist/server/_chunks/production-jar9ztm3.js +44 -0
  140. package/dist/server/_chunks/proxy-config-j84dgksn.js +21 -0
  141. package/dist/server/_chunks/proxy-w1d0wmsn.js +33 -0
  142. package/dist/server/_chunks/router-k1reahfn.js +498 -0
  143. package/dist/server/_chunks/routes-2s277fc6.js +64 -0
  144. package/dist/server/_chunks/run-pvd8bs1t.js +696 -0
  145. package/dist/server/_chunks/server-mt4a994c.js +1835 -0
  146. package/dist/server/_chunks/tsconfig-defaults-1nb3308g.js +20 -0
  147. package/dist/server/_chunks/typegen-0qr0459b.js +35 -0
  148. package/dist/server/api/client-cache.js +14 -0
  149. package/dist/server/cli/index.js +378 -0
  150. package/dist/server/cli/start.js +137 -0
  151. package/dist/server/client/reference.js +16 -0
  152. package/dist/server/compat/next/cache.js +56 -0
  153. package/dist/server/compat/next/canonical-url.js +13 -0
  154. package/dist/server/compat/next/client-cache.js +57 -0
  155. package/dist/server/compat/next/client-navigation.js +232 -0
  156. package/dist/server/compat/next/client-only.js +1 -0
  157. package/dist/server/compat/next/client-script.js +178 -0
  158. package/dist/server/compat/next/client-server.js +34 -0
  159. package/dist/server/compat/next/config-headers.js +32 -0
  160. package/dist/server/compat/next/config-loader.js +25 -0
  161. package/dist/server/compat/next/config.js +10 -0
  162. package/dist/server/compat/next/constants.js +18 -0
  163. package/dist/server/compat/next/custom-server.js +10 -0
  164. package/dist/server/compat/next/dist/client/components/app-router-headers.js +48 -0
  165. package/dist/server/compat/next/dist/server/web/spec-extension/revalidate.js +27 -0
  166. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-cache.js +25 -0
  167. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-no-store.js +25 -0
  168. package/dist/server/compat/next/dynamic.js +32 -0
  169. package/dist/server/compat/next/error.js +112 -0
  170. package/dist/server/compat/next/font/cache.js +14 -0
  171. package/dist/server/compat/next/font/google.js +3 -0
  172. package/dist/server/compat/next/font/index.js +1 -0
  173. package/dist/server/compat/next/font/local.js +22 -0
  174. package/dist/server/compat/next/font/runtime-client.js +33 -0
  175. package/dist/server/compat/next/font/runtime.js +41 -0
  176. package/dist/server/compat/next/font/shared.js +22 -0
  177. package/dist/server/compat/next/form.js +129 -0
  178. package/dist/server/compat/next/head.js +10 -0
  179. package/dist/server/compat/next/headers.js +30 -0
  180. package/dist/server/compat/next/image/client.js +11 -0
  181. package/dist/server/compat/next/image/config.js +18 -0
  182. package/dist/server/compat/next/image/optimizer.js +25 -0
  183. package/dist/server/compat/next/image/patterns.js +12 -0
  184. package/dist/server/compat/next/image/props.js +16 -0
  185. package/dist/server/compat/next/image/shared.js +86 -0
  186. package/dist/server/compat/next/image/static-metadata.js +32 -0
  187. package/dist/server/compat/next/image/validate.js +8 -0
  188. package/dist/server/compat/next/image.js +59 -0
  189. package/dist/server/compat/next/index.js +1 -0
  190. package/dist/server/compat/next/legacy-image.js +78 -0
  191. package/dist/server/compat/next/legacy-request-apis.js +24 -0
  192. package/dist/server/compat/next/link-transform.js +14 -0
  193. package/dist/server/compat/next/link.js +14 -0
  194. package/dist/server/compat/next/navigation.js +190 -0
  195. package/dist/server/compat/next/offline.js +45 -0
  196. package/dist/server/compat/next/og.js +8 -0
  197. package/dist/server/compat/next/preferred-region.js +8 -0
  198. package/dist/server/compat/next/redirects.js +30 -0
  199. package/dist/server/compat/next/resource-hints.js +30 -0
  200. package/dist/server/compat/next/rewrites.js +41 -0
  201. package/dist/server/compat/next/root-params.js +121 -0
  202. package/dist/server/compat/next/route-state.js +23 -0
  203. package/dist/server/compat/next/router.js +103 -0
  204. package/dist/server/compat/next/script.js +37 -0
  205. package/dist/server/compat/next/server-only.js +1 -0
  206. package/dist/server/compat/next/server.js +131 -0
  207. package/dist/server/compat/next/svgr.js +14 -0
  208. package/dist/server/compat/next/telemetry.js +10 -0
  209. package/dist/server/compat/next/usage.js +13 -0
  210. package/dist/server/compat/next/user-agent.js +12 -0
  211. package/dist/server/compat/next/web-vitals.js +35 -0
  212. package/dist/server/compat/react/action-state.js +11 -0
  213. package/dist/server/compat/react/client-lite.js +83 -0
  214. package/dist/server/compat/react/client.js +131 -0
  215. package/dist/server/compat/react/compiler-runtime.js +42 -0
  216. package/dist/server/compat/react/dom-client.js +106 -0
  217. package/dist/server/compat/react/dom-react-server.js +37 -0
  218. package/dist/server/compat/react/dom-server.js +40 -0
  219. package/dist/server/compat/react/dom.js +52 -0
  220. package/dist/server/compat/react/hooks-extra.js +12 -0
  221. package/dist/server/compat/react/internals.js +14 -0
  222. package/dist/server/compat/react/parity.js +11 -0
  223. package/dist/server/compat/react/preact.js +113 -0
  224. package/dist/server/compat/react/react-server.js +133 -0
  225. package/dist/server/compat/react/router-shim.js +8 -0
  226. package/dist/server/compat/react/server-component-use.js +14 -0
  227. package/dist/server/compat/react/server-inserted-html.js +14 -0
  228. package/dist/server/compat/react/server.js +194 -0
  229. package/dist/server/compat/react/style-values.js +10 -0
  230. package/dist/server/compat/react/use.js +10 -0
  231. package/dist/server/compat/react/view-transition.js +12 -0
  232. package/dist/server/generation.json +1 -0
  233. package/package.json +4 -1
  234. package/src/api/dynamic.tsx +2 -0
  235. package/src/api/server.ts +24 -6
  236. package/src/cli/adapters/vercel-warm.ts +315 -61
  237. package/src/cli/adapters/vercel.ts +348 -71
  238. package/src/cli/build.ts +58 -33
  239. package/src/cli/index.ts +23 -10
  240. package/src/cli/serve/entry.ts +21 -159
  241. package/src/cli/serve/immutable.ts +31 -0
  242. package/src/cli/serve/pipeline.ts +82 -84
  243. package/src/cli/start.ts +3 -1
  244. package/src/client/chunk-fold.ts +19 -6
  245. package/src/client/react-tier.ts +3 -2
  246. package/src/client/reference-stub.ts +21 -2
  247. package/src/compat/actions/client-plugin.ts +4 -2
  248. package/src/compat/actions/config.ts +6 -5
  249. package/src/compat/actions/extensions.ts +2 -3
  250. package/src/compat/aliases.ts +8 -1
  251. package/src/compat/bundler/config.ts +88 -0
  252. package/src/compat/bundler/optimize-package-imports.ts +86 -26
  253. package/src/compat/bundler/relay-transform.ts +15 -3
  254. package/src/compat/cache-control.ts +16 -8
  255. package/src/compat/css/modules.ts +18 -5
  256. package/src/compat/lifecycle/error-funnel.ts +1 -1
  257. package/src/compat/lifecycle/instrumentation.ts +117 -24
  258. package/src/compat/lifecycle/testmode.ts +3 -2
  259. package/src/compat/next/config-loader.ts +137 -13
  260. package/src/compat/next/font/runtime.ts +22 -2
  261. package/src/compat/next/og.ts +3 -3
  262. package/src/compat/next/usage.ts +3 -2
  263. package/src/compat/pages/api.ts +83 -14
  264. package/src/compat/pages/router.ts +30 -14
  265. package/src/compat/register/bundler.ts +3 -1
  266. package/src/compat/register/middleware.ts +1 -1
  267. package/src/compat/register/otel.ts +5 -9
  268. package/src/compat/register/render.ts +3 -1
  269. package/src/compat/register/use-cache.ts +3 -1
  270. package/src/compat/release.ts +46 -0
  271. package/src/compat/segment/serve.ts +1 -1
  272. package/src/compat/validation/validate.ts +10 -7
  273. package/src/config.ts +51 -7
  274. package/src/css/assets.ts +213 -0
  275. package/src/css/build.ts +174 -238
  276. package/src/dev/server.ts +27 -8
  277. package/src/extensions.ts +4 -0
  278. package/src/render/hooks.ts +13 -0
  279. package/src/render/renderer.ts +52 -32
  280. package/src/request/context.ts +9 -0
  281. package/src/resolve/dynamic.ts +3 -1
  282. package/src/resolve/imports.ts +12 -52
  283. package/src/resolve/package-json.ts +56 -0
  284. package/src/resolve/scan-facts.ts +65 -0
  285. package/src/routing/href.ts +10 -3
  286. package/src/routing/match.ts +287 -0
  287. package/src/routing/metadata-files.ts +19 -5
  288. package/src/routing/proxy-config.ts +137 -0
  289. package/src/routing/proxy.ts +35 -134
  290. package/src/routing/routes.ts +22 -281
  291. package/src/runtime/fingerprint.ts +23 -8
  292. package/src/runtime/load.ts +170 -0
  293. package/src/runtime/loader.ts +215 -43
  294. package/src/runtime/module-cache.ts +13 -0
  295. package/src/runtime/modules.ts +370 -81
  296. package/src/runtime/prebundle.ts +81 -0
  297. package/src/runtime/production.ts +391 -0
  298. package/src/runtime/release-graph.ts +334 -0
  299. package/src/runtime/vendor-build.ts +724 -13
  300. package/src/runtime/vendor.ts +16 -3
  301. package/src/types.ts +2 -0
  302. package/src/utils/fs.ts +89 -3
@@ -0,0 +1,736 @@
1
+ // @bun
2
+ import { join as __pnextJoin } from "node:path";
3
+ const __PNEXT_PACKAGE_ROOT__ = __pnextJoin(import.meta.dirname, "../../..");
4
+ import {
5
+ persistFont,
6
+ persistedFont
7
+ } from "./index-3b3at80h.js";
8
+ import {
9
+ familyStack,
10
+ fontStyle,
11
+ googleFontNaming,
12
+ localFontNaming,
13
+ singleQuoteFamily,
14
+ stableJson
15
+ } from "./index-fn1chkkd.js";
16
+ import {
17
+ servedRelease
18
+ } from "./index-tqn2qnnn.js";
19
+ import {
20
+ getWorkUnit
21
+ } from "./index-grta8ap3.js";
22
+ import {
23
+ onExtensionHostReset,
24
+ registerResponseFinalizers
25
+ } from "./index-zqpqyg8p.js";
26
+ import {
27
+ escapeRegex
28
+ } from "./index-qjj6gddn.js";
29
+
30
+ // src/compat/next/font/runtime.ts
31
+ import { AsyncLocalStorage } from "async_hooks";
32
+ import { createHash } from "crypto";
33
+ import { createRequire } from "module";
34
+ import { existsSync, readFileSync } from "fs";
35
+ import { copyFile, mkdir, readFile, writeFile } from "fs/promises";
36
+ import path from "path";
37
+ import { fileURLToPath } from "url";
38
+ var fontRuntimeGlobal = globalThis;
39
+ var sharedAcrossInstances = (key, create) => fontRuntimeGlobal[key] ??= create();
40
+ var fontStorage = sharedAcrossInstances(Symbol.for("pnext.compat.font.storage"), () => new AsyncLocalStorage);
41
+ var allowedDisplayValues = new Set(["auto", "block", "swap", "fallback", "optional"]);
42
+ var require2 = createRequire(Bun.pathToFileURL(__PNEXT_PACKAGE_ROOT__ + "/src/compat/next/font/runtime.ts").href);
43
+ var googleCssCache = new Map;
44
+ var googleFontFileCache = new Map;
45
+ var resolvedFontCache = sharedAcrossInstances(Symbol.for("pnext.compat.font.resolved"), () => new Map);
46
+ var googleMetadataCache;
47
+ var declaredFonts = sharedAcrossInstances(Symbol.for("pnext.compat.font.declared"), () => new Map);
48
+ async function prewarmFonts(config, options = {}) {
49
+ if (process.env.PNEXT_PREWARM_FONTS === "0" || declaredFonts.size === 0)
50
+ return;
51
+ await Promise.allSettled([...declaredFonts.values()].map((font) => resolveFont(font, { config, dev: options.dev })));
52
+ }
53
+ function runWithFontScope(callback) {
54
+ registerFontFinalizerOnce();
55
+ return fontStorage.run({ fonts: new Map }, callback);
56
+ }
57
+ var FONT_HEADER_PRELOADS = Symbol.for("pnext.compat.font.headerPreloads");
58
+ async function fontAssets(config, options = {}) {
59
+ const scope = fontStorage.getStore();
60
+ if (!scope || scope.fonts.size === 0)
61
+ return { css: "", preloads: [] };
62
+ const resolved = await Promise.all([...scope.fonts.values()].map((font) => resolveFont(font, { config, dev: options.dev })));
63
+ const preloads = dedupePreloads(resolved.flatMap((font) => font.preloads));
64
+ stashHeaderPreloads(preloads);
65
+ if (resolved.some((font) => font.sizeAdjust))
66
+ scope.sizeAdjust = true;
67
+ const usesFonts = resolved.some((font) => font.usesFonts);
68
+ return {
69
+ css: resolved.map((font) => font.css).filter(Boolean).join(`
70
+ `),
71
+ preloads: preloads.length > 0 ? options.dev ? preloads : [] : usesFonts ? [fontPreconnect()] : []
72
+ };
73
+ }
74
+ function fontPreloadDomScript() {
75
+ return `<script>(function(){try{function a(){var seen={},ls=document.querySelectorAll('link[as="font"]');` + "for(var i=0;i<ls.length;i++)seen[ls[i].href]=1;" + "for(var i=0;i<document.styleSheets.length;i++){var rules;try{rules=document.styleSheets[i].cssRules}catch(e){continue}if(!rules)continue;" + "for(var j=0;j<rules.length;j++){var r=rules[j];if(!(r.type===5))continue;" + `var m=/url\\((?:"|')?([^"')\\s]*\\.p\\.woff2)/.exec(r.cssText);if(!m)continue;` + "var u;try{u=new URL(m[1],location.href).href}catch(e){continue}if(seen[u])continue;seen[u]=1;" + 'var l=document.createElement("link");l.rel="preload";l.as="font";l.type="font/woff2";l.setAttribute("crossorigin","");l.href=u;document.head.appendChild(l)}}}' + 'document.readyState==="loading"?document.addEventListener("DOMContentLoaded",a):a()}catch(e){}})();</script>';
76
+ }
77
+ function fontSizeAdjustMeta() {
78
+ return fontStorage.getStore()?.sizeAdjust === true ? '<meta name="next-size-adjust" content=""/>' : "";
79
+ }
80
+ function stashHeaderPreloads(preloads) {
81
+ if (preloads.length === 0)
82
+ return;
83
+ const unit = getWorkUnit();
84
+ if (!unit)
85
+ return;
86
+ const compat = unit.compat ??= {};
87
+ const existing = compat[FONT_HEADER_PRELOADS] ?? [];
88
+ compat[FONT_HEADER_PRELOADS] = dedupePreloads([...existing, ...preloads]);
89
+ }
90
+ function takeFontHeaderPreloads() {
91
+ const unit = getWorkUnit();
92
+ const compat = unit?.compat;
93
+ if (!compat)
94
+ return [];
95
+ const preloads = compat[FONT_HEADER_PRELOADS] ?? [];
96
+ compat[FONT_HEADER_PRELOADS] = undefined;
97
+ return preloads;
98
+ }
99
+ var fontFinalizerRegistered = false;
100
+ onExtensionHostReset(() => fontFinalizerRegistered = false);
101
+ function registerFontFinalizerOnce() {
102
+ if (fontFinalizerRegistered)
103
+ return;
104
+ fontFinalizerRegistered = true;
105
+ registerResponseFinalizers((ctx) => {
106
+ const preloads = takeFontHeaderPreloads();
107
+ if (preloads.length === 0)
108
+ return;
109
+ const value = preloads.map(fontLinkHeaderValue).join(", ");
110
+ const existing = ctx.headers.get("link");
111
+ ctx.headers.set("link", existing ? `${existing}, ${value}` : value);
112
+ });
113
+ }
114
+ function fontLinkHeaderValue(link) {
115
+ const parts = [`<${link.url}>`, `rel=${link.rel}`];
116
+ if (link.as)
117
+ parts.push(`as=${link.as}`);
118
+ if (link.type)
119
+ parts.push(`type=${link.type}`);
120
+ parts.push('crossorigin=""');
121
+ return parts.join("; ");
122
+ }
123
+ function googleFont(family) {
124
+ return (options = {}) => {
125
+ const naming = googleFontNaming(family, options);
126
+ const { className, variable, fontFamily, hash, style, hasVariable } = naming;
127
+ const definition = {
128
+ className,
129
+ family: fontFamily,
130
+ key: `google:${stableJson({ family, options })}`,
131
+ style,
132
+ variable,
133
+ hasVariable,
134
+ resolve: (context) => resolveGoogleFont(context, {
135
+ className,
136
+ family,
137
+ fontFamily,
138
+ hash,
139
+ options,
140
+ variable
141
+ })
142
+ };
143
+ return fontObject(definition);
144
+ };
145
+ }
146
+ var localFont = Object.assign((options) => localFontWithFile(inferLocalFontCallerFile())(options), { withFile: localFontWithFile });
147
+ function localFontWithFile(callerFile, family) {
148
+ return (options) => {
149
+ const naming = localFontNaming(callerFile, options);
150
+ if (family) {
151
+ naming.fontFamily = family;
152
+ naming.style = fontStyle(family, options, options.fallback ?? []);
153
+ }
154
+ const { className, variable, fontFamily, hash, style, hasVariable } = naming;
155
+ const definition = {
156
+ className,
157
+ family: fontFamily,
158
+ key: `local:${stableJson({ callerFile, options })}`,
159
+ style,
160
+ variable,
161
+ hasVariable,
162
+ resolve: (context) => resolveLocalFont(context, {
163
+ callerFile,
164
+ className,
165
+ fontFamily,
166
+ hash,
167
+ options,
168
+ variable
169
+ })
170
+ };
171
+ return fontObject(definition);
172
+ };
173
+ }
174
+ function fontObject(definition) {
175
+ declaredFonts.set(definition.key, definition);
176
+ const descriptors = {
177
+ className: {
178
+ enumerable: true,
179
+ get() {
180
+ registerFont(definition);
181
+ return definition.className;
182
+ }
183
+ },
184
+ style: {
185
+ enumerable: true,
186
+ get() {
187
+ registerFont(definition);
188
+ return definition.style;
189
+ }
190
+ }
191
+ };
192
+ if (definition.hasVariable) {
193
+ descriptors.variable = {
194
+ enumerable: true,
195
+ get() {
196
+ registerFont(definition);
197
+ return definition.variable;
198
+ }
199
+ };
200
+ }
201
+ return Object.defineProperties({}, descriptors);
202
+ }
203
+ function registerFont(definition) {
204
+ fontStorage.getStore()?.fonts.set(definition.key, definition);
205
+ }
206
+ async function releaseFonts(config) {
207
+ const fonts = {};
208
+ for (const font of declaredFonts.values()) {
209
+ const { sources: _sources, ...resolved } = await resolveFont(font, { config });
210
+ fonts[font.key] = resolved;
211
+ }
212
+ return fonts;
213
+ }
214
+ async function resolveFont(definition, context) {
215
+ const released = servedRelease()?.fonts?.[definition.key];
216
+ if (released)
217
+ return released;
218
+ const key = `${context.config.outPath}:${context.dev ? "dev" : "build"}:${definition.key}`;
219
+ let resolved = resolvedFontCache.get(key);
220
+ if (!resolved) {
221
+ resolved = resolveThroughCache(definition, context, key);
222
+ resolvedFontCache.set(key, resolved);
223
+ }
224
+ const font = await resolved;
225
+ if (font.files.every((file) => existsSync(file)))
226
+ return font;
227
+ const fresh = resolveAndPersist(definition, context, key);
228
+ resolvedFontCache.set(key, fresh);
229
+ return fresh;
230
+ }
231
+ async function resolveThroughCache(definition, context, key) {
232
+ if (!context.dev)
233
+ return definition.resolve(context);
234
+ const persisted = await persistedFont(context.config, key);
235
+ if (persisted)
236
+ return persisted;
237
+ return resolveAndPersist(definition, context, key);
238
+ }
239
+ function resolveAndPersist(definition, context, key) {
240
+ const resolved = definition.resolve(context);
241
+ if (context.dev) {
242
+ resolved.then((font) => persistFont(context.config, key, font)).catch(() => {
243
+ return;
244
+ });
245
+ }
246
+ return resolved;
247
+ }
248
+ async function resolveGoogleFont(context, request) {
249
+ const metadata = googleMetadata()[request.family];
250
+ if (!metadata)
251
+ throw new Error(`Unknown font \`${request.family}\``);
252
+ const options = normalizeGoogleOptions(request.family, metadata, request.options);
253
+ const adjustFontFallback = options.adjustFontFallback;
254
+ const url = googleFontsUrl(request.family, googleFontAxes(metadata, options), options.display);
255
+ const css = (await googleCss(url, request.family, Boolean(context.dev))).split("body {", 1)[0] ?? "";
256
+ const fontFiles = findGoogleFontFiles(css, options.preload ? options.subsets : undefined);
257
+ const emitted = await Promise.all(fontFiles.map(async (fontFile) => ({
258
+ ...fontFile,
259
+ emitted: await emitRemoteFontFile(context, fontFile.googleFontFileUrl, {
260
+ preload: fontFile.preloadFontFile,
261
+ adjustFontFallback
262
+ })
263
+ })));
264
+ let rewrittenCss = css;
265
+ for (const item of emitted) {
266
+ rewrittenCss = rewrittenCss.replaceAll(item.googleFontFileUrl, item.emitted.url);
267
+ }
268
+ const stack = familyStack(request.fontFamily, options.fallback, adjustFontFallback);
269
+ const scopedCss = [
270
+ rewriteFontFamily(rewrittenCss, request.family, request.fontFamily),
271
+ adjustFontFallback ? fallbackFaceCss(request.fontFamily) : "",
272
+ classRule(request.className, stack, singleCssValue(options.weights), singleCssValue(options.styles)),
273
+ request.options.variable ? variableRule(request.variable, customProperty(request.options.variable), stack) : ""
274
+ ].filter(Boolean).join(`
275
+ `);
276
+ return {
277
+ usesFonts: emitted.length > 0,
278
+ sizeAdjust: adjustFontFallback,
279
+ css: scopedCss,
280
+ preloads: emitted.filter((item) => item.preloadFontFile).map((item) => fontPreload(item.emitted.url, item.emitted.type)),
281
+ files: emitted.map((item) => item.emitted.file)
282
+ };
283
+ }
284
+ async function resolveLocalFont(context, request) {
285
+ const display = validateDisplay(request.options.display ?? "swap");
286
+ const adjustFontFallback = request.options.declarations?.some((item) => item.prop === "font-family") ? false : true;
287
+ const preload = request.options.preload !== false;
288
+ const sources = normalizeLocalSources(request.options, request.callerFile && path.resolve(context.config.root, request.callerFile));
289
+ const emitted = await Promise.all(sources.map(async (source) => ({
290
+ ...source,
291
+ emitted: await emitLocalFontFile(context, source.file, { preload, adjustFontFallback })
292
+ })));
293
+ const stack = familyStack(request.fontFamily, request.options.fallback ?? [], adjustFontFallback);
294
+ const declarations = request.options.declarations ?? [];
295
+ const faceCss = emitted.map((source) => [
296
+ "@font-face{",
297
+ `font-family:${singleQuoteFamily(request.fontFamily)};`,
298
+ `src:url("${source.emitted.url}") format("${fontFormat(source.emitted.ext)}");`,
299
+ `font-display:${display};`,
300
+ source.weight ?? request.options.weight ? `font-weight:${cssIdentifier(source.weight ?? request.options.weight ?? "")};` : "",
301
+ source.style ?? request.options.style ? `font-style:${cssIdentifier(source.style ?? request.options.style ?? "")};` : "",
302
+ ...declarations.map((item) => `${cssProperty(item.prop)}:${cssDeclarationValue(item.value)};`),
303
+ "}"
304
+ ].filter(Boolean).join(""));
305
+ return {
306
+ usesFonts: emitted.length > 0,
307
+ sizeAdjust: adjustFontFallback,
308
+ css: [
309
+ ...faceCss,
310
+ adjustFontFallback ? fallbackFaceCss(request.fontFamily) : "",
311
+ classRule(request.className, stack, request.options.weight, request.options.style),
312
+ request.options.variable ? variableRule(request.variable, customProperty(request.options.variable), stack) : ""
313
+ ].filter(Boolean).join(`
314
+ `),
315
+ preloads: preload ? emitted.map((item) => fontPreload(item.emitted.url, item.emitted.type)) : [],
316
+ files: emitted.map((item) => item.emitted.file),
317
+ sources: emitted.map((source) => source.file)
318
+ };
319
+ }
320
+ function normalizeGoogleOptions(family, metadata, options) {
321
+ const display = validateDisplay(options.display ?? "swap");
322
+ const preload = options.preload ?? true;
323
+ const subsets = options.subsets;
324
+ if (metadata.subsets.length === 0) {} else if (preload) {
325
+ if (!subsets) {
326
+ throw new Error(`Preload is enabled but no subsets were specified for font \`${family}\`. ` + `Please specify subsets or disable preloading.`);
327
+ }
328
+ for (const subset of subsets) {
329
+ if (!metadata.subsets.includes(subset)) {
330
+ throw new Error(`Unknown subset \`${subset}\` for font \`${family}\`.`);
331
+ }
332
+ }
333
+ }
334
+ const weights = uniqueArray(options.weight ? arrayValue(options.weight) : []);
335
+ if (weights.length === 0) {
336
+ if (metadata.weights.includes("variable"))
337
+ weights.push("variable");
338
+ else
339
+ throw new Error(`Missing weight for font \`${family}\`.`);
340
+ }
341
+ if (weights.length > 1 && weights.includes("variable")) {
342
+ throw new Error(`Unexpected \`variable\` in weight array for font \`${family}\`.`);
343
+ }
344
+ for (const weight of weights) {
345
+ if (!metadata.weights.includes(weight))
346
+ throw new Error(`Unknown weight \`${weight}\` for font \`${family}\`.`);
347
+ }
348
+ const styles = uniqueArray(options.style ? arrayValue(options.style) : []);
349
+ if (styles.length === 0)
350
+ styles.push(metadata.styles.length === 1 ? metadata.styles[0] ?? "normal" : "normal");
351
+ for (const style of styles) {
352
+ if (!metadata.styles.includes(style))
353
+ throw new Error(`Unknown style \`${style}\` for font \`${family}\`.`);
354
+ }
355
+ if (options.axes) {
356
+ if (!metadata.weights.includes("variable") || weights[0] !== "variable") {
357
+ throw new Error("Axes can only be defined for variable fonts.");
358
+ }
359
+ const definableAxes = (metadata.axes ?? []).map((axis) => axis.tag).filter((tag) => tag !== "wght");
360
+ for (const axis of options.axes) {
361
+ if (!definableAxes.includes(axis))
362
+ throw new Error(`Invalid axes value \`${axis}\` for font \`${family}\`.`);
363
+ }
364
+ }
365
+ return {
366
+ axes: options.axes,
367
+ adjustFontFallback: options.adjustFontFallback ?? true,
368
+ display,
369
+ fallback: options.fallback ?? [],
370
+ preload: metadata.subsets.length === 0 ? false : preload,
371
+ styles,
372
+ subsets,
373
+ variable: options.variable,
374
+ weights
375
+ };
376
+ }
377
+ function googleFontAxes(metadata, options) {
378
+ const hasItalic = options.styles.includes("italic");
379
+ const hasNormal = options.styles.includes("normal");
380
+ const ital = hasItalic ? [...hasNormal ? ["0"] : [], "1"] : undefined;
381
+ if (options.weights[0] !== "variable") {
382
+ return {
383
+ ital,
384
+ wght: options.weights,
385
+ variableAxes: undefined
386
+ };
387
+ }
388
+ let weightAxis;
389
+ const variableAxes = [];
390
+ for (const axis of metadata.axes ?? []) {
391
+ if (axis.tag === "wght")
392
+ weightAxis = `${axis.min}..${axis.max}`;
393
+ else if (options.axes?.includes(axis.tag))
394
+ variableAxes.push([axis.tag, `${axis.min}..${axis.max}`]);
395
+ }
396
+ return {
397
+ ital,
398
+ wght: weightAxis ? [weightAxis] : undefined,
399
+ variableAxes: variableAxes.length > 0 ? variableAxes : undefined
400
+ };
401
+ }
402
+ function googleFontsUrl(family, axes, display) {
403
+ const variants = [];
404
+ if (axes.wght) {
405
+ for (const wght of axes.wght) {
406
+ if (!axes.ital) {
407
+ variants.push([["wght", wght], ...axes.variableAxes ?? []]);
408
+ } else {
409
+ for (const ital of axes.ital)
410
+ variants.push([["ital", ital], ["wght", wght], ...axes.variableAxes ?? []]);
411
+ }
412
+ }
413
+ } else if (axes.variableAxes) {
414
+ variants.push([...axes.variableAxes]);
415
+ }
416
+ if (axes.variableAxes) {
417
+ for (const variant of variants) {
418
+ variant.sort(([a], [b]) => {
419
+ const aLower = a.charCodeAt(0) > 96;
420
+ const bLower = b.charCodeAt(0) > 96;
421
+ if (aLower && !bLower)
422
+ return -1;
423
+ if (bLower && !aLower)
424
+ return 1;
425
+ return a > b ? 1 : -1;
426
+ });
427
+ }
428
+ }
429
+ let url = `https://fonts.googleapis.com/css2?family=${family.replace(/ /g, "+")}`;
430
+ const firstVariant = variants[0];
431
+ if (firstVariant) {
432
+ url += `:${firstVariant.map(([key]) => key).join(",")}@${variants.map((variant) => variant.map(([, value]) => value).join(",")).sort(sortFontVariantValues).join(";")}`;
433
+ }
434
+ return `${url}&display=${display}`;
435
+ }
436
+ async function googleCss(url, family, dev) {
437
+ let cached = googleCssCache.get(url);
438
+ if (!cached) {
439
+ cached = fetchGoogleCss(url, family, dev);
440
+ googleCssCache.set(url, cached);
441
+ }
442
+ return cached;
443
+ }
444
+ async function fetchGoogleCss(url, family, dev) {
445
+ const mocked = mockedGoogleResponse(url);
446
+ if (typeof mocked === "string")
447
+ return mocked;
448
+ const response = await fetch(url, {
449
+ headers: {
450
+ "user-agent": "Mozilla/5.0 AppleWebKit/537.36 Chrome/120 Safari/537.36"
451
+ }
452
+ });
453
+ if (!response.ok) {
454
+ const message = `Failed to fetch font \`${family}\` from Google Fonts: ${response.status} ${response.statusText}`;
455
+ throw new Error(dev ? `${message}. Use NEXT_FONT_GOOGLE_MOCKED_RESPONSES for offline tests.` : message);
456
+ }
457
+ return response.text();
458
+ }
459
+ function findGoogleFontFiles(css, subsetsToPreload) {
460
+ const fontFiles = [];
461
+ let currentSubset = "";
462
+ for (const line of css.split(`
463
+ `)) {
464
+ const subset = /\/\* (.+?) \*\//.exec(line)?.[1];
465
+ if (subset) {
466
+ currentSubset = subset;
467
+ continue;
468
+ }
469
+ const googleFontFileUrl = /src: url\((.+?)\)/.exec(line)?.[1];
470
+ if (!googleFontFileUrl || fontFiles.some((file) => file.googleFontFileUrl === googleFontFileUrl))
471
+ continue;
472
+ fontFiles.push({
473
+ googleFontFileUrl,
474
+ preloadFontFile: Boolean(subsetsToPreload?.includes(currentSubset))
475
+ });
476
+ }
477
+ return fontFiles;
478
+ }
479
+ async function emitRemoteFontFile(context, url, emit) {
480
+ let cached = googleFontFileCache.get(url);
481
+ if (!cached) {
482
+ cached = fetchFontFile(url);
483
+ googleFontFileCache.set(url, cached);
484
+ }
485
+ const bytes = await cached;
486
+ return emitFontBytes(context, bytes, fontExt(url), emit);
487
+ }
488
+ async function fetchFontFile(url) {
489
+ const mocked = mockedGoogleResponse(url);
490
+ if (mocked instanceof Uint8Array)
491
+ return mocked;
492
+ if (typeof mocked === "string")
493
+ return new TextEncoder().encode(mocked);
494
+ const response = await fetch(url);
495
+ if (!response.ok)
496
+ throw new Error(`Failed to fetch font file from \`${url}\`.`);
497
+ return new Uint8Array(await response.arrayBuffer());
498
+ }
499
+ async function emitLocalFontFile(context, file, emit) {
500
+ const bytes = await readFile(file);
501
+ return emitFontBytes(context, bytes, fontExt(file), emit, file);
502
+ }
503
+ async function emitFontBytes(context, bytes, ext, emit, sourceFile) {
504
+ const hash = createHash("sha256").update(bytes).digest("hex").slice(0, 16);
505
+ const filename = `${hash}${emit.adjustFontFallback ? "-s" : ""}${emit.preload ? ".p" : ""}.${ext}`;
506
+ const mediaSegments = ["_next", "static", "media"];
507
+ const outDir = path.join(context.config.outPath, "public", ...mediaSegments);
508
+ const file = path.join(outDir, filename);
509
+ const asset = {
510
+ ext,
511
+ file,
512
+ type: fontMimeType(ext),
513
+ url: `/${mediaSegments.join("/")}/${filename}`
514
+ };
515
+ if (existsSync(file))
516
+ return asset;
517
+ await mkdir(outDir, { recursive: true });
518
+ if (sourceFile)
519
+ await copyFile(sourceFile, file);
520
+ else
521
+ await writeFile(file, bytes);
522
+ return asset;
523
+ }
524
+ function normalizeLocalSources(options, callerFile) {
525
+ if (!callerFile)
526
+ throw new Error("next/font/local requires PNext server source transforms.");
527
+ const values = Array.isArray(options.src) ? options.src : [options.src];
528
+ return values.map((value) => {
529
+ const item = typeof value === "string" ? { path: value } : value;
530
+ if (!item.path)
531
+ throw new Error("next/font/local src entries require a path.");
532
+ const file = path.resolve(path.dirname(callerFile), item.path);
533
+ if (!existsSync(file))
534
+ throw new Error(`Font file not found: ${item.path}`);
535
+ return { file, style: item.style, weight: item.weight };
536
+ });
537
+ }
538
+ function inferLocalFontCallerFile() {
539
+ const stack = new Error().stack;
540
+ if (!stack)
541
+ return;
542
+ for (const line of stack.split(`
543
+ `)) {
544
+ const file = stackFrameFile(line);
545
+ if (!file)
546
+ continue;
547
+ if (file.replace(/\\/g, "/").includes("/src/compat/next/font/"))
548
+ continue;
549
+ return originalSourceFile(file);
550
+ }
551
+ return;
552
+ }
553
+ function stackFrameFile(line) {
554
+ const match = /\(?((?:file:\/\/)?\/[^():]+\.[cm]?[jt]sx?|(?:file:\/\/)?\/[^():]+\.mjs):\d+:\d+\)?/.exec(line);
555
+ const file = match?.[1];
556
+ if (!file)
557
+ return;
558
+ return file.startsWith("file://") ? fileURLToPath(file) : file;
559
+ }
560
+ function originalSourceFile(file) {
561
+ const source = sourceComment(file);
562
+ if (!source)
563
+ return file;
564
+ const normalized = source.replace(/\\/g, "/");
565
+ if (normalized.startsWith("file://"))
566
+ return fileURLToPath(normalized);
567
+ if (path.isAbsolute(normalized))
568
+ return existsSync(normalized) ? normalized : file;
569
+ const nodeModulesIndex = normalized.indexOf("node_modules/");
570
+ const relative = nodeModulesIndex === -1 ? normalized : normalized.slice(nodeModulesIndex);
571
+ const candidate = path.resolve(compiledProjectRoot(file), relative);
572
+ return existsSync(candidate) ? candidate : file;
573
+ }
574
+ function sourceComment(file) {
575
+ if (!existsSync(file))
576
+ return;
577
+ const firstLine = readFileSync(file, "utf8").split(/\r?\n/, 1)[0]?.trim();
578
+ return /^\/\/\s+(.+)$/.exec(firstLine ?? "")?.[1];
579
+ }
580
+ function compiledProjectRoot(file) {
581
+ const marker = `${path.sep}.pnext${path.sep}`;
582
+ const index = file.indexOf(marker);
583
+ return index === -1 ? process.cwd() : file.slice(0, index);
584
+ }
585
+ function googleMetadata() {
586
+ if (!googleMetadataCache) {
587
+ googleMetadataCache = loadGoogleMetadata();
588
+ }
589
+ return googleMetadataCache;
590
+ }
591
+ function loadGoogleMetadata() {
592
+ const override = process.env.PNEXT_FONT_GOOGLE_METADATA;
593
+ if (override) {
594
+ const metadata2 = readGoogleMetadataFile(override);
595
+ if (metadata2)
596
+ return metadata2;
597
+ throw new Error(`Invalid Google font metadata file: ${override}`);
598
+ }
599
+ const metadata = tryLoadGoogleMetadata("next-font/google/font-data.json") ?? tryLoadGoogleMetadata("next-font");
600
+ if (metadata)
601
+ return metadata;
602
+ throw new Error("next/font/google requires Google font metadata. Install `next-font`.");
603
+ }
604
+ function tryLoadGoogleMetadata(specifier) {
605
+ try {
606
+ const loaded = require2(specifier);
607
+ const metadata = "googleFontsMetadata" in loaded ? loaded.googleFontsMetadata : ("default" in loaded) ? loaded.default : loaded;
608
+ return isGoogleMetadata(metadata) ? metadata : undefined;
609
+ } catch {
610
+ return;
611
+ }
612
+ }
613
+ function readGoogleMetadataFile(file) {
614
+ const metadata = JSON.parse(readFileSync(file, "utf8"));
615
+ return isGoogleMetadata(metadata) ? metadata : undefined;
616
+ }
617
+ function isGoogleMetadata(value) {
618
+ if (!value || typeof value !== "object")
619
+ return false;
620
+ const inter = value.Inter;
621
+ return Boolean(inter && Array.isArray(inter.weights) && Array.isArray(inter.styles) && Array.isArray(inter.subsets));
622
+ }
623
+ function mockedGoogleResponse(url) {
624
+ const mockFile = process.env.NEXT_FONT_GOOGLE_MOCKED_RESPONSES;
625
+ if (!mockFile)
626
+ return;
627
+ const mocked = require2(mockFile);
628
+ const value = mocked[url];
629
+ if (value === undefined)
630
+ throw new Error(`Missing mocked response for URL: ${url}`);
631
+ if (typeof value === "string" && value.startsWith("/") && existsSync(value)) {
632
+ return new Uint8Array(readFileSync(value));
633
+ }
634
+ return value;
635
+ }
636
+ function rewriteFontFamily(css, originalFamily, scopedFamily) {
637
+ const familyPattern = escapeRegex(originalFamily);
638
+ return css.replace(new RegExp(`font-family:\\s*(["']?)${familyPattern}\\1`, "g"), `font-family:${singleQuoteFamily(scopedFamily)}`);
639
+ }
640
+ function fallbackFaceCss(family) {
641
+ return `@font-face{font-family:${singleQuoteFamily(`${family} Fallback`)};src:local("Arial");}`;
642
+ }
643
+ function classRule(className, familyStack2, weight, style) {
644
+ return [
645
+ `.${className}{font-family:${familyStack2};`,
646
+ weight && !isRangeValue(weight) ? `font-weight:${cssIdentifier(weight)};` : "",
647
+ style && !isRangeValue(style) ? `font-style:${cssIdentifier(style)};` : "",
648
+ "}"
649
+ ].join("");
650
+ }
651
+ function variableRule(className, variable, familyStack2) {
652
+ return `.${className}{${variable}:${familyStack2};}`;
653
+ }
654
+ function fontPreload(url, type) {
655
+ return { rel: "preload", url, as: "font", type, crossOrigin: "" };
656
+ }
657
+ function fontPreconnect() {
658
+ return { rel: "preconnect", url: "/", crossOrigin: "" };
659
+ }
660
+ function dedupePreloads(preloads) {
661
+ const seen = new Set;
662
+ return preloads.filter((preload) => {
663
+ if (seen.has(preload.url))
664
+ return false;
665
+ seen.add(preload.url);
666
+ return true;
667
+ });
668
+ }
669
+ function validateDisplay(value) {
670
+ if (!allowedDisplayValues.has(value))
671
+ throw new Error(`Invalid font display value \`${value}\`.`);
672
+ return value;
673
+ }
674
+ function fontExt(value) {
675
+ return /\.(woff2?|eot|ttf|otf)(?:[?#]|$)/.exec(value)?.[1] ?? "woff2";
676
+ }
677
+ function fontMimeType(ext) {
678
+ if (ext === "woff")
679
+ return "font/woff";
680
+ if (ext === "ttf")
681
+ return "font/ttf";
682
+ if (ext === "otf")
683
+ return "font/otf";
684
+ if (ext === "eot")
685
+ return "application/vnd.ms-fontobject";
686
+ return "font/woff2";
687
+ }
688
+ function fontFormat(ext) {
689
+ if (ext === "ttf")
690
+ return "truetype";
691
+ if (ext === "otf")
692
+ return "opentype";
693
+ return ext;
694
+ }
695
+ function singleCssValue(values) {
696
+ return values.length === 1 ? values[0] : undefined;
697
+ }
698
+ function isRangeValue(value) {
699
+ return value.trim().includes(" ");
700
+ }
701
+ function arrayValue(value) {
702
+ return Array.isArray(value) ? value : [value];
703
+ }
704
+ function uniqueArray(items) {
705
+ return [...new Set(items)];
706
+ }
707
+ function customProperty(value) {
708
+ if (!/^--[-_a-zA-Z0-9]+$/.test(value))
709
+ throw new Error(`Invalid font variable name: ${value}`);
710
+ return value;
711
+ }
712
+ function cssIdentifier(value) {
713
+ if (!/^[-_a-zA-Z0-9. ]+$/.test(value))
714
+ throw new Error(`Invalid font option value: ${value}`);
715
+ return value;
716
+ }
717
+ function cssProperty(value) {
718
+ if (!/^[-_a-zA-Z0-9]+$/.test(value))
719
+ throw new Error(`Invalid CSS property: ${value}`);
720
+ return value;
721
+ }
722
+ function cssDeclarationValue(value) {
723
+ if (/[;{}]/.test(value))
724
+ throw new Error(`Invalid CSS declaration value: ${value}`);
725
+ return value;
726
+ }
727
+ function sortFontVariantValues(a, b) {
728
+ if (a.includes(",") && b.includes(",")) {
729
+ const [aPrefix, aSuffix] = a.split(",", 2);
730
+ const [bPrefix, bSuffix] = b.split(",", 2);
731
+ return aPrefix === bPrefix ? parseInt(aSuffix ?? "0", 10) - parseInt(bSuffix ?? "0", 10) : parseInt(aPrefix ?? "0", 10) - parseInt(bPrefix ?? "0", 10);
732
+ }
733
+ return parseInt(a, 10) - parseInt(b, 10);
734
+ }
735
+
736
+ export { prewarmFonts, runWithFontScope, fontAssets, fontPreloadDomScript, fontSizeAdjustMeta, takeFontHeaderPreloads, registerFontFinalizerOnce, fontLinkHeaderValue, googleFont, localFont, localFontWithFile, releaseFonts };