@flamingo-stack/openframe-frontend-core 0.0.830 → 0.0.832

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 (121) hide show
  1. package/dist/build/export-map.json +1 -1
  2. package/dist/build/next-styles.cjs +93 -3
  3. package/dist/build/next-styles.d.ts +8 -0
  4. package/dist/build/route-styles-client.mjs +67 -0
  5. package/dist/build/route-styles-markers.cjs +18 -0
  6. package/dist/build/route-styles-server.mjs +102 -0
  7. package/dist/build/route-styles.cjs +415 -0
  8. package/dist/build/route-styles.d.ts +11 -0
  9. package/dist/build/style-sources.cjs +14 -1
  10. package/dist/build/style-sources.d.ts +3 -0
  11. package/dist/{case-study-card-QMFGPABF.cjs → case-study-card-TK7ZCNLM.cjs} +5 -5
  12. package/dist/{chunk-LKP5R3EQ.cjs → chunk-46LATWQR.cjs} +2 -2
  13. package/dist/{chunk-IBD2FPSX.cjs → chunk-4JHO2NVI.cjs} +2 -2
  14. package/dist/{chunk-QTLWU6FY.cjs → chunk-5L3UKDC6.cjs} +11 -11
  15. package/dist/{chunk-HYCMMECU.cjs → chunk-7COZUANC.cjs} +58 -67
  16. package/dist/{chunk-ULF4ZOUM.cjs → chunk-7WQD3R5J.cjs} +84 -84
  17. package/dist/{chunk-DAKGX2WF.cjs → chunk-APNONOHY.cjs} +2 -2
  18. package/dist/{chunk-KPGKTEEB.cjs → chunk-BUEEQD3G.cjs} +2 -2
  19. package/dist/{chunk-YMLRDVPO.cjs → chunk-C4OQIYGW.cjs} +11 -11
  20. package/dist/{chunk-WCCE4WF3.cjs → chunk-CP46CVUC.cjs} +91 -91
  21. package/dist/{chunk-5LED4QHZ.cjs → chunk-D6ZSRGH2.cjs} +237 -237
  22. package/dist/{chunk-HYGWRUEM.cjs → chunk-DAQMCWCK.cjs} +3 -3
  23. package/dist/{chunk-56EP4QM2.cjs → chunk-EYSIQORA.cjs} +94 -94
  24. package/dist/{chunk-2BGLALP5.cjs → chunk-FNNDGOR3.cjs} +19 -19
  25. package/dist/{chunk-OKTNRGM5.cjs → chunk-GPXKG34G.cjs} +54 -54
  26. package/dist/{chunk-FMSAN6SR.cjs → chunk-H3WTYAVR.cjs} +129 -129
  27. package/dist/{chunk-RRPID7Z7.cjs → chunk-HDLY6OMQ.cjs} +6 -6
  28. package/dist/{chunk-2VLPXUQK.cjs → chunk-HLJXCOMA.cjs} +4 -4
  29. package/dist/{chunk-PBHP3FHO.cjs → chunk-JBTH3O2C.cjs} +4 -4
  30. package/dist/{chunk-2HQNXX2K.cjs → chunk-JQCQCE6U.cjs} +2 -2
  31. package/dist/{chunk-AY6XJOIN.cjs → chunk-LWMWY3JO.cjs} +45 -45
  32. package/dist/{chunk-E6W4YDPS.cjs → chunk-OGPAVRNF.cjs} +17 -17
  33. package/dist/{chunk-D2LXFMZI.cjs → chunk-P5DWAVWK.cjs} +28 -28
  34. package/dist/{chunk-TUMSVFVS.cjs → chunk-QHBKZJ6A.cjs} +4 -4
  35. package/dist/{chunk-WZYBUJJG.cjs → chunk-R6QZHOJB.cjs} +46 -46
  36. package/dist/{chunk-F2J5WN6U.cjs → chunk-SOCCHWDK.cjs} +2 -2
  37. package/dist/{chunk-CAGQAMJ6.cjs → chunk-SRHHLDBP.cjs} +36 -36
  38. package/dist/{chunk-WWDNLMB7.cjs → chunk-SWMUW3RR.cjs} +11 -11
  39. package/dist/{chunk-6GPMVHJN.cjs → chunk-TD4CC4KV.cjs} +20 -20
  40. package/dist/{chunk-SAW7V7CU.cjs → chunk-UGM3YDCK.cjs} +25 -25
  41. package/dist/{chunk-FFFN4IY2.cjs → chunk-UQS2RI5Y.cjs} +12 -12
  42. package/dist/{chunk-5KSPG3TV.cjs → chunk-VBGBKRDO.cjs} +665 -642
  43. package/dist/{chunk-X425BGXS.cjs → chunk-VQG2A7GA.cjs} +2 -2
  44. package/dist/{chunk-S6UJEW4G.cjs → chunk-WCOSGDGA.cjs} +2 -2
  45. package/dist/{chunk-ENMPSEEQ.cjs → chunk-WVNUCKB7.cjs} +4 -4
  46. package/dist/{chunk-DUGOOTER.cjs → chunk-X76TZ5YR.cjs} +21 -21
  47. package/dist/{chunk-PUXYAHH3.cjs → chunk-X7VQM5TU.cjs} +6 -6
  48. package/dist/{chunk-W4VEDSAX.cjs → chunk-ZABZIM2Y.cjs} +6 -6
  49. package/dist/{chunk-M75723HD.cjs → chunk-ZJ5K6XHW.cjs} +21 -21
  50. package/dist/{cloud-tenants-4KQQPXPM.cjs → cloud-tenants-E2AC4WEJ.cjs} +19 -19
  51. package/dist/components/case-studies/index.cjs +35 -35
  52. package/dist/components/chat/index.cjs +14 -14
  53. package/dist/components/chat/utils/icon-registry.d.ts +2 -2
  54. package/dist/components/chat/utils/icon-registry.js +2 -2
  55. package/dist/components/contact/index.cjs +20 -20
  56. package/dist/components/docs/index.cjs +23 -23
  57. package/dist/components/embeds/index.cjs +20 -20
  58. package/dist/components/faq/index.cjs +21 -21
  59. package/dist/components/features/index.cjs +21 -19
  60. package/dist/components/features/notifications/index.d.ts +3 -1
  61. package/dist/components/features/notifications/index.d.ts.map +1 -1
  62. package/dist/components/features/notifications/index.js +2 -0
  63. package/dist/components/features/notifications/notification-category-icon.d.ts +7 -0
  64. package/dist/components/features/notifications/notification-category-icon.d.ts.map +1 -0
  65. package/dist/components/features/notifications/notification-category-icon.js +26 -0
  66. package/dist/components/features/notifications/notification-tile.d.ts.map +1 -1
  67. package/dist/components/features/notifications/types.d.ts +1 -1
  68. package/dist/components/features/notifications/types.d.ts.map +1 -1
  69. package/dist/components/help-center-pages/index.cjs +124 -124
  70. package/dist/components/index.cjs +85 -81
  71. package/dist/components/meeting-scheduler/index.cjs +68 -68
  72. package/dist/components/navigation/index.cjs +22 -22
  73. package/dist/components/navigation/site-footer.d.ts.map +1 -1
  74. package/dist/components/navigation/site-footer.js +2 -12
  75. package/dist/components/onboarding-guides/index.cjs +22 -22
  76. package/dist/components/product-demo/index.cjs +30 -30
  77. package/dist/components/related-content/index.cjs +9 -9
  78. package/dist/components/social-icon-row.d.ts +6 -2
  79. package/dist/components/social-icon-row.d.ts.map +1 -1
  80. package/dist/components/social-icon-row.js +5 -6
  81. package/dist/components/tickets/index.cjs +26 -26
  82. package/dist/components/ui/index.cjs +19 -19
  83. package/dist/{devices-H6C4NMIY.cjs → devices-CAYUGD2N.cjs} +20 -20
  84. package/dist/{embeddable-chat-KUESE7P6.cjs → embeddable-chat-FYHMR66R.cjs} +91 -91
  85. package/dist/hooks/index.cjs +7 -7
  86. package/dist/index.cjs +26 -24
  87. package/dist/{knowledge-O6IBO5Y5.cjs → knowledge-OI4OPEVL.cjs} +20 -20
  88. package/dist/{logs-Y2UCF24Z.cjs → logs-B3XV2NHV.cjs} +26 -26
  89. package/dist/platform-domains.cjs +4 -0
  90. package/dist/platform-domains.d.ts +2 -0
  91. package/dist/platform-domains.d.ts.map +1 -1
  92. package/dist/platform-domains.js +4 -0
  93. package/dist/{policies-J6O3RLJT.cjs → policies-ZB4Z42DV.cjs} +23 -23
  94. package/dist/{remote-session-RVTFWSU4.cjs → remote-session-CN3G7JNR.cjs} +6 -6
  95. package/dist/{scripts-N67MM4T2.cjs → scripts-I4DNUOQC.cjs} +26 -26
  96. package/dist/{software-update-HB7F6KNG.cjs → software-update-AWH4WXOH.cjs} +23 -23
  97. package/dist/{tickets-board-2K3PBCNW.cjs → tickets-board-PLYD2NSY.cjs} +10 -10
  98. package/dist/types/marketing.d.ts +61 -216
  99. package/dist/types/marketing.d.ts.map +1 -1
  100. package/dist/utils/index.cjs +2 -2
  101. package/dist/utils/notifications.cjs +55 -0
  102. package/dist/utils/notifications.d.ts +29 -0
  103. package/dist/utils/notifications.d.ts.map +1 -0
  104. package/dist/utils/notifications.js +53 -0
  105. package/dist/utils/social-platforms.d.ts +9 -9
  106. package/dist/utils/social-platforms.d.ts.map +1 -1
  107. package/package.json +12 -1
  108. package/src/components/chat/utils/icon-registry.ts +5 -5
  109. package/src/components/chat/utils/index.ts +1 -1
  110. package/src/components/features/notifications/index.ts +2 -1
  111. package/src/components/features/notifications/notification-category-icon.tsx +38 -0
  112. package/src/components/features/notifications/notification-tile.tsx +2 -1
  113. package/src/components/features/notifications/types.ts +1 -2
  114. package/src/components/navigation/site-footer.tsx +2 -11
  115. package/src/components/social-icon-row.tsx +11 -10
  116. package/src/platform-domains.ts +5 -0
  117. package/src/styles/index.css +2 -0
  118. package/src/types/marketing.ts +90 -268
  119. package/src/utils/index.ts +1 -1
  120. package/src/utils/notifications.ts +71 -0
  121. package/src/utils/social-platforms.ts +9 -9
@@ -32,12 +32,31 @@
32
32
  * page's sheet is mostly its layout's. Inlining removes the wait; a smaller sheet only makes it cheap.
33
33
  */
34
34
  const { execFile } = require('node:child_process');
35
+ const crypto = require('node:crypto');
35
36
  const { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } = require('node:fs');
36
37
  const { tmpdir } = require('node:os');
37
38
  const { dirname, isAbsolute, join, resolve } = require('node:path');
38
39
  const { promisify } = require('node:util');
39
40
  const { brotliCompressSync, constants } = require('node:zlib');
40
41
 
42
+ const { STYLES_DIR, BUILD_INFO } = require('./route-styles-markers.cjs');
43
+
44
+ /**
45
+ * The complete sheet's address for a build (`{ buildId, assetPrefix, basePath }`). Named by the build, so the browser
46
+ * bundle knows it too: a page Next draws only in the browser (a 404 is served as an empty error shell, then rendered
47
+ * from its data) has no route sheet from the server and loads this one itself.
48
+ */
49
+ const fullSheetUrl = ({ buildId, assetPrefix, basePath }) =>
50
+ `${(assetPrefix || basePath || '').replace(/\/$/, '')}/_next/static/next-styles/full-${buildId}.css`;
51
+
52
+ /**
53
+ * The route-sheet build (`./route-styles.cjs`), loaded only by the `build` command. The app's next.config imports
54
+ * this file and Turbopack traces what it imports (`join(__dirname, …)` included): reaching the build tool pulled
55
+ * Next's own server, sharp's native libraries and esbuild into the trace and failed the build (Next 16.3).
56
+ */
57
+ const loadRouteStyles = () =>
58
+ require(/* turbopackIgnore: true */ /* webpackIgnore: true */ join(__dirname, 'route-styles.cjs'));
59
+
41
60
  /** `nextConfig` with every route's stylesheets written into its HTML. Composes with a config function. */
42
61
  function withInlineStyles(nextConfig) {
43
62
  const apply = config => ({ ...config, experimental: { ...config.experimental, inlineCss: true } });
@@ -47,6 +66,39 @@ function withInlineStyles(nextConfig) {
47
66
  return apply(nextConfig);
48
67
  }
49
68
 
69
+ /**
70
+ * `withInlineStyles`, and per-route stylesheets when the build is `next-styles build` (`./route-styles.cjs`): the
71
+ * server bundle carries `.next-styles/` (filled after the build) and knows its build, and the build records the
72
+ * settings the route step reads. Any other build, and `next dev`, is `withInlineStyles` alone.
73
+ */
74
+ function withRouteStyles(nextConfig) {
75
+ return async (phase, ...rest) => {
76
+ const config = typeof nextConfig === 'function' ? await nextConfig(phase, ...rest) : nextConfig;
77
+ const inline = withInlineStyles(config);
78
+ if (process.env.NEXT_STYLES !== 'routes' || phase !== 'phase-production-build') return inline;
79
+ const root = process.cwd();
80
+ const infoFile = join(root, STYLES_DIR, BUILD_INFO);
81
+ // One id per build: the server checks the sheets it reads were written for it.
82
+ const buildId = existsSync(infoFile) ? JSON.parse(readFileSync(infoFile, 'utf8')).buildId : crypto.randomUUID();
83
+ const info = {
84
+ buildId,
85
+ distDir: inline.distDir ?? '.next',
86
+ output: inline.output ?? null,
87
+ assetPrefix: inline.assetPrefix ?? '',
88
+ basePath: inline.basePath ?? '',
89
+ };
90
+ writeFileSync(infoFile, `${JSON.stringify(info, null, 2)}\n`);
91
+ // Every route: the files are read at run time by `RouteStyles`, which no static trace can follow.
92
+ const includes = { ...inline.outputFileTracingIncludes };
93
+ for (const route of ['/', '/*', '/*/**']) includes[route] = [...(includes[route] ?? []), `./${STYLES_DIR}/**/*`];
94
+ return {
95
+ ...inline,
96
+ env: { ...inline.env, NEXT_STYLES_BUILD: buildId, NEXT_STYLES_FULL_URL: fullSheetUrl(info) },
97
+ outputFileTracingIncludes: includes,
98
+ };
99
+ };
100
+ }
101
+
50
102
  /**
51
103
  * The stylesheet `input` with each `@import` made an absolute path: the Tailwind CLI resolves an import
52
104
  * by path only, never through a package's `exports` (`@import '<package>/styles'`), which a bundler does.
@@ -158,8 +210,9 @@ if (require.main === module) {
158
210
  const [command, ...rest] = process.argv.slice(2);
159
211
  Promise.resolve()
160
212
  .then(() => {
161
- if (command !== 'budget') throw new Error(`next-styles: unknown command ${command ?? '(none)'}; try "budget"`);
162
- return budgetCommand(rest);
213
+ if (command === 'budget') return budgetCommand(rest);
214
+ if (command === 'build') return buildCommand(rest);
215
+ throw new Error(`next-styles: unknown command ${command ?? '(none)'}; try "build" or "budget"`);
163
216
  })
164
217
  .catch(error => {
165
218
  console.error(`[css-budget] ${error.message}`);
@@ -167,4 +220,41 @@ if (require.main === module) {
167
220
  });
168
221
  }
169
222
 
170
- module.exports = { withInlineStyles, measureStylesheet, resolveImports };
223
+ /**
224
+ * `build [--budget <brotli bytes>] [--input <css>] [--config <tailwind config>] [--full-config <tailwind config>]
225
+ * [-- <next build args>]`: `next build` with a stylesheet per route (`./route-styles.cjs`).
226
+ */
227
+ async function buildCommand(argv) {
228
+ const root = process.cwd();
229
+ const split = argv.indexOf('--');
230
+ const args = parseArgs(split < 0 ? argv : argv.slice(0, split));
231
+ const nextArgs = split < 0 ? [] : argv.slice(split + 1);
232
+ const config =
233
+ args.config ??
234
+ firstExisting(
235
+ root,
236
+ ['ts', 'js', 'cjs', 'mjs'].map(ext => `tailwind.config.${ext}`),
237
+ );
238
+ const input = args.input ?? firstExisting(root, ['src/app/globals.css', 'app/globals.css']);
239
+ if (!input || !config)
240
+ throw new Error('usage: next-styles build [--input <css>] [--config <tailwind config>] [-- <next build args>]');
241
+ const { buildWithRouteStyles, DEFAULT_BUDGET } = loadRouteStyles();
242
+ await buildWithRouteStyles({
243
+ root,
244
+ nextArgs,
245
+ input,
246
+ config,
247
+ fullConfig: args['full-config'] ?? config,
248
+ budget: args.budget ? Number(args.budget) : DEFAULT_BUDGET,
249
+ });
250
+ }
251
+
252
+ module.exports = {
253
+ STYLES_DIR,
254
+ BUILD_INFO,
255
+ fullSheetUrl,
256
+ withInlineStyles,
257
+ withRouteStyles,
258
+ measureStylesheet,
259
+ resolveImports,
260
+ };
@@ -19,3 +19,11 @@ export function measureStylesheet(
19
19
 
20
20
  /** The stylesheet at `input` with each `@import` resolved to an absolute path (packages through their `exports`). */
21
21
  export function resolveImports(input: string, root: string): string;
22
+
23
+ /**
24
+ * `withInlineStyles`, plus per-route stylesheets when the build runs as `next-styles build`: the server bundle
25
+ * carries `.next-styles/` and knows its build. Any other build and `next dev` get `withInlineStyles` alone.
26
+ */
27
+ export function withRouteStyles<T extends object>(
28
+ nextConfig: T | ((...args: unknown[]) => T | Promise<T>),
29
+ ): (phase: string, ...rest: unknown[]) => Promise<T & { experimental: { inlineCss: true } }>;
@@ -0,0 +1,67 @@
1
+ 'use client';
2
+ /**
3
+ * The client part of `RouteStyles` (`./route-styles-server.mjs`). In the server render it asks the resolver the
4
+ * server part put in the process for the rules of the page's path, and renders them. In the browser it renders the
5
+ * same `<style>` empty, under the same `href`: React finds the server's copy in the head by its `href` and keeps it,
6
+ * and after a client navigation the complete sheet holds every rule. The loader starts the complete sheet when the HTML reaches it,
7
+ * without blocking paint, and appends it after every other stylesheet so its rules are the last copy of each.
8
+ *
9
+ * A page the server did not render (Next answers a 404 with an empty error shell and draws it from its data in the
10
+ * browser) has neither the rules nor the loader: the effect then loads the complete sheet itself, from the address
11
+ * the build wrote into the bundle.
12
+ */
13
+ import { usePathname } from 'next/navigation';
14
+ import { createElement, Fragment, useEffect } from 'react';
15
+ import markers from './route-styles-markers.cjs';
16
+
17
+ const REGISTRY = Symbol.for(markers.REGISTRY_KEY);
18
+ const FULL_URL = process.env.NEXT_STYLES_FULL_URL || '';
19
+ /** Appends the complete sheet named by its own `<script data-next-styles-full>` once, at low priority. */
20
+ const LOADER =
21
+ "(function(s){var h=s&&s.getAttribute('data-next-styles-full');" +
22
+ "if(!h||document.querySelector('link[data-next-styles-full]'))return;" +
23
+ "var l=document.createElement('link');l.rel='stylesheet';l.href=h;l.fetchPriority='low';" +
24
+ "l.setAttribute('data-next-styles-full','');document.head.appendChild(l)})(document.currentScript)";
25
+
26
+ /** The complete sheet, once, unless the server wrote this page's rules (its loader then started the sheet already). */
27
+ function loadCompleteSheet(build) {
28
+ if (!FULL_URL || document.querySelector('link[data-next-styles-full]')) return;
29
+ if (document.querySelector(`style[data-href="next-styles:${build}"]`)?.textContent) return;
30
+ const link = document.createElement('link');
31
+ link.rel = 'stylesheet';
32
+ link.href = FULL_URL;
33
+ link.setAttribute('data-next-styles-full', '');
34
+ document.head.appendChild(link);
35
+ }
36
+
37
+ export function RouteStyle({ build, complete }) {
38
+ const pathname = usePathname();
39
+ useEffect(() => loadCompleteSheet(build), [build]);
40
+ let entry;
41
+ if (typeof window === 'undefined') {
42
+ const resolve = globalThis[REGISTRY]?.get(build);
43
+ if (!resolve) {
44
+ // The server part runs first in this process; without its resolver the page would have no utilities.
45
+ throw new Error('next-styles: RouteStyle rendered without RouteStyles in this process');
46
+ }
47
+ entry = resolve(pathname, complete);
48
+ }
49
+ return createElement(
50
+ Fragment,
51
+ null,
52
+ createElement(
53
+ 'style',
54
+ // One href for every page of the build: the browser keeps the first page's copy, and a client
55
+ // navigation inserts no other (the complete sheet already holds every rule by then).
56
+ { href: `next-styles:${build}`, precedence: 'next-styles' },
57
+ entry?.css ?? '',
58
+ ),
59
+ // The complete sheet's address is the server's to state; the browser renders the script without it and
60
+ // keeps the server's attribute (the script already ran when the HTML reached it).
61
+ createElement('script', {
62
+ 'data-next-styles-full': entry?.fullUrl ?? undefined,
63
+ suppressHydrationWarning: true,
64
+ dangerouslySetInnerHTML: { __html: LOADER },
65
+ }),
66
+ );
67
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The names `next-styles build` and `RouteStyles` agree on, stated once: the build writes them
3
+ * (`./route-styles.cjs`, `./next-styles.cjs`) and the server and client parts read them
4
+ * (`./route-styles-server.mjs`, `./route-styles-client.mjs`). A leaf with no imports, so the app's server and
5
+ * browser bundles can carry it without reaching the build tool.
6
+ */
7
+ module.exports = {
8
+ /** Where `next-styles build` keeps the build's route sheets (the app's directory), and its files there. */
9
+ STYLES_DIR: '.next-styles',
10
+ BUILD_INFO: 'build.json',
11
+ MANIFEST: 'manifest.json',
12
+ /** What a prerendered page's route `<style>` holds until the build fills it with the route's rules. */
13
+ PLACEHOLDER: '/*next-styles:route*/',
14
+ /** What a page that carries the complete sheet (`RouteStyles complete`) holds until the build fills it. */
15
+ COMPLETE_PLACEHOLDER: '/*next-styles:complete*/',
16
+ /** The process-wide key the server part registers its resolver under for the client part's server render. */
17
+ REGISTRY_KEY: 'flamingo.next-styles',
18
+ };
@@ -0,0 +1,102 @@
1
+ /**
2
+ * The page's stylesheet, for the root layout of an app built with `next-styles build` (`./route-styles.cjs`).
3
+ *
4
+ * import { RouteStyles } from '<package>/route-styles'
5
+ * <body><RouteStyles />…</body> // once, in the root layout
6
+ * <RouteStyles complete /> // pages that depend on who is signed in
7
+ *
8
+ * It writes the rules of the page's route into the HTML (a `<style precedence>`, which React puts in the head after
9
+ * the app's own stylesheets) and starts the complete sheet loading after paint. The route is the page's path
10
+ * (`usePathname` in the server render of the client part), matched against the routes the build sampled; a path no
11
+ * route matches gets the complete sheet. The rules reach the HTML only: the client part reads them from a resolver
12
+ * this module puts in the process, never from a prop, so they are not written again into the page's data (the RSC
13
+ * payload a client navigation reads). In `next dev`, and in a build not made by `next-styles build`, it renders
14
+ * nothing and the app's stylesheet holds every rule as before.
15
+ */
16
+ import { existsSync, readFileSync } from 'node:fs';
17
+ import { join } from 'node:path';
18
+ import { createElement } from 'react';
19
+ import { RouteStyle } from './route-styles-client.mjs';
20
+ import markers from './route-styles-markers.cjs';
21
+
22
+ const { STYLES_DIR, MANIFEST, PLACEHOLDER, COMPLETE_PLACEHOLDER, REGISTRY_KEY } = markers;
23
+ const REGISTRY = Symbol.for(REGISTRY_KEY);
24
+
25
+ /** The build these rules belong to, and its complete sheet: written by `withRouteStyles` into the bundles. */
26
+ const BUILD = process.env.NEXT_STYLES_BUILD || '';
27
+ const FULL_URL = process.env.NEXT_STYLES_FULL_URL || '';
28
+
29
+ /** `/blog/[slug]` → a RegExp for its paths; `[...x]` takes one or more segments, `[[...x]]` none or more. */
30
+ function routePattern(route) {
31
+ let source = '';
32
+ let dynamic = 0;
33
+ for (const part of route.split('/').filter(Boolean)) {
34
+ if (/^\[\[\.\.\.[^\]]+\]\]$/.test(part)) {
35
+ source += '(?:/.+)?';
36
+ dynamic += 3;
37
+ } else if (/^\[\.\.\.[^\]]+\]$/.test(part)) {
38
+ source += '/.+';
39
+ dynamic += 2;
40
+ } else if (/^\[[^\]]+\]$/.test(part)) {
41
+ source += '/[^/]+';
42
+ dynamic += 1;
43
+ } else {
44
+ source += `/${part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`;
45
+ }
46
+ }
47
+ return { route, dynamic, regex: new RegExp(`^${source || '/'}$`) };
48
+ }
49
+
50
+ function normalize(pathname) {
51
+ const path = `/${String(pathname || '').replace(/^\/+/, '')}`.replace(/\/+$/, '');
52
+ return path === '' ? '/' : path;
53
+ }
54
+
55
+ /**
56
+ * The build's resolver, `(pathname, complete) → { css, fullUrl }`, read once per process. While the build
57
+ * prerenders, it answers placeholders for the rules, which the build fills in afterwards.
58
+ */
59
+ function createResolver() {
60
+ // Read at run time from the server's own directory (traced in by `withRouteStyles`), never followed by the
61
+ // bundler's file tracing.
62
+ const dir = join(/* turbopackIgnore: true */ process.cwd(), STYLES_DIR);
63
+ const file = join(dir, MANIFEST);
64
+ if (!existsSync(file)) {
65
+ throw new Error(
66
+ `next-styles: ${file} is missing: this server was built by next-styles build and needs its ${STYLES_DIR}`,
67
+ );
68
+ }
69
+ const manifest = JSON.parse(readFileSync(file, 'utf8'));
70
+ if (manifest.pending) {
71
+ return (_pathname, complete) =>
72
+ complete ? { css: COMPLETE_PLACEHOLDER, fullUrl: null } : { css: PLACEHOLDER, fullUrl: FULL_URL };
73
+ }
74
+ if (manifest.buildId !== BUILD) {
75
+ throw new Error(`next-styles: ${file} belongs to build ${manifest.buildId}, this server to ${BUILD}`);
76
+ }
77
+ const patterns = Object.keys(manifest.routes)
78
+ .map(routePattern)
79
+ .sort((a, b) => a.dynamic - b.dynamic || b.route.length - a.route.length);
80
+ const sheets = new Map();
81
+ const sheet = name => {
82
+ if (!sheets.has(name)) sheets.set(name, readFileSync(join(dir, 'sheets', name), 'utf8'));
83
+ return sheets.get(name);
84
+ };
85
+ return (pathname, complete) => {
86
+ const path = normalize(pathname);
87
+ const match = complete ? undefined : patterns.find(pattern => pattern.regex.test(path));
88
+ if (!match) return { css: sheet(manifest.full), fullUrl: null };
89
+ return { css: sheet(manifest.routes[match.route].file), fullUrl: manifest.fullUrl };
90
+ };
91
+ }
92
+
93
+ /**
94
+ * The page's rules: its route's sheet, or the complete sheet where no route matches its path or where `complete`
95
+ * says the page's markup depends on who is looking (a signed-in hub), so no one page can sample its route.
96
+ */
97
+ export function RouteStyles({ complete = false } = {}) {
98
+ if (!BUILD) return null;
99
+ globalThis[REGISTRY] ??= new Map();
100
+ if (!globalThis[REGISTRY].has(BUILD)) globalThis[REGISTRY].set(BUILD, createResolver());
101
+ return createElement(RouteStyle, { build: BUILD, complete });
102
+ }