@scalar/server-side-rendering 0.1.13 → 0.1.16

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @scalar/server-side-rendering
2
2
 
3
+ ## 0.1.16
4
+
5
+ ## 0.1.15
6
+
7
+ ### Patch Changes
8
+
9
+ - [#9211](https://github.com/scalar/scalar/pull/9211): Integrate Unhead server-side head rendering in SSR output so `metaData` and title tags are included in the server-rendered HTML document.
10
+
11
+ ## 0.1.14
12
+
13
+ ### Patch Changes
14
+
15
+ - [#8967](https://github.com/scalar/scalar/pull/8967): Integrate Unhead server-side head rendering in SSR output so `metaData` and title tags are included in the server-rendered HTML document.
16
+
3
17
  ## 0.1.13
4
18
 
5
19
  ## 0.1.12
@@ -0,0 +1,2 @@
1
+ export { generateBodyScript, getJsAsset, renderApiReference, renderApiReferenceToString } from './ssr';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- import { generateBodyScript, getJsAsset, renderApiReference, renderApiReferenceToString } from "./ssr.js";
2
- export { generateBodyScript, getJsAsset, renderApiReference, renderApiReferenceToString };
1
+ export { generateBodyScript, getJsAsset, renderApiReference, renderApiReferenceToString } from './ssr';
package/dist/ssr.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ import type { AnyApiReferenceConfiguration } from '@scalar/types/api-reference';
2
+ /**
3
+ * Generate an inline script that detects the user's color mode preference
4
+ * and applies the correct class to <body> before content paints.
5
+ *
6
+ * Place this script before the app container in your HTML so it runs before
7
+ * the first paint without interfering with Vue hydration.
8
+ *
9
+ * Priority:
10
+ * 1. forceDarkModeState → always wins (no runtime detection)
11
+ * 2. localStorage 'colorMode' → user's saved preference
12
+ * 3. matchMedia system preference
13
+ * 4. darkMode config → explicit default
14
+ * 5. Fallback → light-mode
15
+ */
16
+ export declare function generateBodyScript(configuration: AnyApiReferenceConfiguration): string;
17
+ /**
18
+ * Render the Scalar API Reference to an HTML string for server-side rendering.
19
+ * Use createApiReference on the client to hydrate the server-rendered output.
20
+ *
21
+ * Returns only the Vue-rendered HTML. Use generateBodyScript separately to get
22
+ * the dark/light mode script — place it outside the app container so it does not
23
+ * interfere with Vue hydration.
24
+ */
25
+ export declare function renderApiReferenceToString(configuration: AnyApiReferenceConfiguration): Promise<string>;
26
+ /**
27
+ * Get the standalone JavaScript bundle as a string.
28
+ *
29
+ * Serve this at a route (e.g. `/scalar/scalar.js`) and pass the same path
30
+ * as the `cdn` option to `renderApiReference`. The bundle handles client-side
31
+ * hydration of the server-rendered HTML.
32
+ */
33
+ export declare function getJsAsset(): string;
34
+ /**
35
+ * Serialize a configuration object to a JavaScript object literal for hydration.
36
+ * Top-level function props and top-level arrays containing functions are preserved
37
+ * to match the client-side renderer behavior.
38
+ */
39
+ export declare function serializeConfigToJs(config: Record<string, unknown>): string;
40
+ /**
41
+ * Render the Scalar API Reference as a complete HTML document with client-side
42
+ * hydration.
43
+ *
44
+ * Returns a full `<!doctype html>` page with:
45
+ * - Inline CSS in `<head>` (prevents flash of unstyled content)
46
+ * - Color-mode detection script (runs before first paint)
47
+ * - Pre-rendered Vue HTML (immediate content, no blank page)
48
+ * - Script tags to load the standalone bundle and hydrate
49
+ *
50
+ * Serve the standalone JS bundle via `getJsAsset()` at the route matching
51
+ * the `cdn` option (defaults to `/scalar/scalar.js`).
52
+ */
53
+ export declare function renderApiReference(options: {
54
+ /** The API reference configuration. */
55
+ config: AnyApiReferenceConfiguration;
56
+ /** Page title. Defaults to "Scalar API Reference". */
57
+ pageTitle?: string;
58
+ /** Override the built-in CSS. */
59
+ css?: string;
60
+ /** URL path to the standalone JS bundle. Defaults to "/scalar/scalar.js". */
61
+ cdn?: string;
62
+ }): Promise<string>;
63
+ //# sourceMappingURL=ssr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../src/ssr.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAA;AA+B/E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,4BAA4B,GAAG,MAAM,CAkBtF;AAqFD;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAAC,aAAa,EAAE,4BAA4B,GAAG,OAAO,CAAC,MAAM,CAAC,CAG7G;AAcD;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,MAAM,CA2BnC;AAwHD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CA4B3E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,uCAAuC;IACvC,MAAM,EAAE,4BAA4B,CAAA;IACpC,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,iCAAiC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BlB"}
package/dist/ssr.js CHANGED
@@ -1,232 +1,329 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { createRequire } from "node:module";
3
- import { dirname, resolve } from "node:path";
4
- import { ApiReference } from "@scalar/api-reference";
5
- import { createSSRApp, h } from "vue";
6
- import { renderToString } from "vue/server-renderer";
7
- //#region src/ssr.ts
8
- var require = createRequire(import.meta.url);
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { dirname, resolve } from 'node:path';
4
+ import { ApiReference } from '@scalar/api-reference';
5
+ import { useServerSeoMeta } from '@unhead/vue';
6
+ import { createHead, renderSSRHead } from '@unhead/vue/server';
7
+ import { createSSRApp, h } from 'vue';
8
+ import { renderToString } from 'vue/server-renderer';
9
+ const require = createRequire(import.meta.url);
9
10
  /**
10
- * Unwrap the configuration from an array if needed, since AnyApiReferenceConfiguration
11
- * can be a single config or an array of configs.
12
- */
11
+ * Unwrap the configuration from an array if needed, since AnyApiReferenceConfiguration
12
+ * can be a single config or an array of configs.
13
+ */
13
14
  function unwrapConfig(configuration) {
14
- return (Array.isArray(configuration) ? configuration[0] : configuration) ?? {};
15
+ const config = Array.isArray(configuration) ? configuration[0] : configuration;
16
+ return (config ?? {});
15
17
  }
16
18
  function parseForceDarkModeState(config) {
17
- const forced = config.forceDarkModeState;
18
- if (forced === "dark" || forced === "light") return forced;
19
- return null;
19
+ const forced = config.forceDarkModeState;
20
+ if (forced === 'dark' || forced === 'light') {
21
+ return forced;
22
+ }
23
+ return null;
20
24
  }
21
25
  function parseDarkMode(config) {
22
- return typeof config.darkMode === "boolean" ? config.darkMode : null;
26
+ return typeof config.darkMode === 'boolean' ? config.darkMode : null;
23
27
  }
24
28
  /**
25
- * Generate an inline script that detects the user's color mode preference
26
- * and applies the correct class to <body> before content paints.
27
- *
28
- * Place this script before the app container in your HTML so it runs before
29
- * the first paint without interfering with Vue hydration.
30
- *
31
- * Priority:
32
- * 1. forceDarkModeState → always wins (no runtime detection)
33
- * 2. localStorage 'colorMode' → user's saved preference
34
- * 3. matchMedia system preference
35
- * 4. darkMode config → explicit default
36
- * 5. Fallback → light-mode
37
- */
38
- function generateBodyScript(configuration) {
39
- const config = unwrapConfig(configuration);
40
- const forced = parseForceDarkModeState(config);
41
- const darkMode = parseDarkMode(config);
42
- /** When forceDarkModeState is set, we do not need runtime detection at all. */
43
- if (forced) return `<script>(function(){var cl=document.body.classList;cl.remove('dark-mode','light-mode');cl.add('${forced === "dark" ? "dark-mode" : "light-mode"}')})()<\/script>`;
44
- return `<script>(function(){var cl=document.body.classList;function set(d){cl.remove('dark-mode','light-mode');cl.add(d?'dark-mode':'light-mode')}try{var s=localStorage.getItem('colorMode');if(s==='dark'||s==='light'){set(s==='dark');return}}catch(e){}${darkMode === null ? `set(window.matchMedia('(prefers-color-scheme:dark)').matches)` : `set(${darkMode})`}})()<\/script>`;
29
+ * Generate an inline script that detects the user's color mode preference
30
+ * and applies the correct class to <body> before content paints.
31
+ *
32
+ * Place this script before the app container in your HTML so it runs before
33
+ * the first paint without interfering with Vue hydration.
34
+ *
35
+ * Priority:
36
+ * 1. forceDarkModeState → always wins (no runtime detection)
37
+ * 2. localStorage 'colorMode' → user's saved preference
38
+ * 3. matchMedia system preference
39
+ * 4. darkMode config → explicit default
40
+ * 5. Fallback → light-mode
41
+ */
42
+ export function generateBodyScript(configuration) {
43
+ const config = unwrapConfig(configuration);
44
+ const forced = parseForceDarkModeState(config);
45
+ const darkMode = parseDarkMode(config);
46
+ /** When forceDarkModeState is set, we do not need runtime detection at all. */
47
+ if (forced) {
48
+ return `<script>(function(){var cl=document.body.classList;cl.remove('dark-mode','light-mode');cl.add('${forced === 'dark' ? 'dark-mode' : 'light-mode'}')})()</script>`;
49
+ }
50
+ /**
51
+ * Runtime detection script: checks localStorage first, then system preference,
52
+ * then falls back to the darkMode config value.
53
+ */
54
+ const fallback = darkMode === null ? `set(window.matchMedia('(prefers-color-scheme:dark)').matches)` : `set(${darkMode})`;
55
+ return `<script>(function(){var cl=document.body.classList;function set(d){cl.remove('dark-mode','light-mode');cl.add(d?'dark-mode':'light-mode')}try{var s=localStorage.getItem('colorMode');if(s==='dark'||s==='light'){set(s==='dark');return}}catch(e){}${fallback}})()</script>`;
45
56
  }
46
57
  /**
47
- * Derive the initial SSR class for <body> from config.
48
- *
49
- * Priority:
50
- * 1. forceDarkModeState
51
- * 2. darkMode
52
- * 3. fallback to dark-mode (then runtime script can refine from localStorage/matchMedia)
53
- */
58
+ * Derive the initial SSR class for <body> from config.
59
+ *
60
+ * Priority:
61
+ * 1. forceDarkModeState
62
+ * 2. darkMode
63
+ * 3. fallback to dark-mode (then runtime script can refine from localStorage/matchMedia)
64
+ */
54
65
  function getInitialBodyClass(configuration) {
55
- const config = unwrapConfig(configuration);
56
- const forced = parseForceDarkModeState(config);
57
- const darkMode = parseDarkMode(config);
58
- if (forced) return forced === "dark" ? "dark-mode" : "light-mode";
59
- if (darkMode !== null) return darkMode ? "dark-mode" : "light-mode";
60
- return "dark-mode";
66
+ const config = unwrapConfig(configuration);
67
+ const forced = parseForceDarkModeState(config);
68
+ const darkMode = parseDarkMode(config);
69
+ if (forced) {
70
+ return forced === 'dark' ? 'dark-mode' : 'light-mode';
71
+ }
72
+ if (darkMode !== null) {
73
+ return darkMode ? 'dark-mode' : 'light-mode';
74
+ }
75
+ return 'dark-mode';
61
76
  }
77
+ const createHeadInstance = (pageTitle) => createHead({
78
+ init: [
79
+ {
80
+ htmlAttrs: { lang: 'en' },
81
+ ...(pageTitle ? { title: pageTitle } : {}),
82
+ },
83
+ ],
84
+ });
62
85
  /**
63
- * Render the Scalar API Reference to an HTML string for server-side rendering.
64
- * Use createApiReference on the client to hydrate the server-rendered output.
65
- *
66
- * Returns only the Vue-rendered HTML. Use generateBodyScript separately to get
67
- * the dark/light mode script — place it outside the app container so it does not
68
- * interfere with Vue hydration.
69
- */
70
- async function renderApiReferenceToString(configuration) {
71
- const normalizedConfiguration = unwrapConfig(configuration);
72
- const app = createSSRApp(() => h(ApiReference, { configuration: normalizedConfiguration }));
73
- app.config.idPrefix = "scalar-refs";
74
- return await renderToString(app);
75
- }
76
- var _cachedCss;
77
- var _cachedJs;
86
+ * Ensure the initial body class from Scalar config always exists.
87
+ * If Unhead provides body classes, merge them rather than overriding.
88
+ */
89
+ function mergeBodyAttrsWithInitialClass(bodyAttrs, initialBodyClass) {
90
+ const classAttributePattern = /\sclass=(['"])(.*?)\1/i;
91
+ const classMatch = bodyAttrs.match(classAttributePattern);
92
+ if (!classMatch) {
93
+ return `${bodyAttrs} class="${initialBodyClass}"`;
94
+ }
95
+ const existingClassValue = classMatch[2] ?? '';
96
+ const existingClasses = existingClassValue.split(/\s+/).filter(Boolean);
97
+ const mergedClasses = Array.from(new Set([...existingClasses, initialBodyClass])).join(' ');
98
+ return bodyAttrs.replace(classAttributePattern, ` class="${mergedClasses}"`);
99
+ }
100
+ async function renderApiReferenceApp(options) {
101
+ const normalizedConfiguration = unwrapConfig(options.configuration);
102
+ const app = createSSRApp({
103
+ setup: () => {
104
+ const metaData = normalizedConfiguration.metaData;
105
+ if (metaData && typeof metaData === 'object') {
106
+ useServerSeoMeta(metaData);
107
+ }
108
+ return () => h(ApiReference, { configuration: normalizedConfiguration });
109
+ },
110
+ });
111
+ const head = createHeadInstance(options.pageTitle);
112
+ app.use(head);
113
+ app.config.idPrefix = 'scalar-refs';
114
+ const html = await renderToString(app);
115
+ const headTags = await renderSSRHead(head);
116
+ return {
117
+ html,
118
+ head: headTags,
119
+ };
120
+ }
121
+ /**
122
+ * Render the Scalar API Reference to an HTML string for server-side rendering.
123
+ * Use createApiReference on the client to hydrate the server-rendered output.
124
+ *
125
+ * Returns only the Vue-rendered HTML. Use generateBodyScript separately to get
126
+ * the dark/light mode script — place it outside the app container so it does not
127
+ * interfere with Vue hydration.
128
+ */
129
+ export async function renderApiReferenceToString(configuration) {
130
+ const { html } = await renderApiReferenceApp({ configuration });
131
+ return html;
132
+ }
133
+ let _cachedCss;
134
+ let _cachedJs;
78
135
  /** Read the built style.css from the @scalar/api-reference package. */
79
136
  function getDefaultCss() {
80
- if (_cachedCss === void 0) _cachedCss = readFileSync(require.resolve("@scalar/api-reference/style.css"), "utf-8");
81
- return _cachedCss;
137
+ if (_cachedCss === undefined) {
138
+ const cssPath = require.resolve('@scalar/api-reference/style.css');
139
+ _cachedCss = readFileSync(cssPath, 'utf-8');
140
+ }
141
+ return _cachedCss;
82
142
  }
83
143
  /**
84
- * Get the standalone JavaScript bundle as a string.
85
- *
86
- * Serve this at a route (e.g. `/scalar/scalar.js`) and pass the same path
87
- * as the `cdn` option to `renderApiReference`. The bundle handles client-side
88
- * hydration of the server-rendered HTML.
89
- */
90
- function getJsAsset() {
91
- if (_cachedJs === void 0) {
92
- const apiReferencePackageRoot = resolve(dirname(require.resolve("@scalar/api-reference")), "..");
93
- const apiReferencePackageJsonPath = resolve(apiReferencePackageRoot, "package.json");
94
- const apiReferencePackageJson = JSON.parse(readFileSync(apiReferencePackageJsonPath, "utf-8"));
95
- if (typeof apiReferencePackageJson.browser !== "string" || apiReferencePackageJson.browser.length === 0) throw new Error(`Could not resolve @scalar/api-reference browser entry from "${apiReferencePackageJsonPath}". Expected a string "browser" field in package.json.`);
96
- const jsPath = resolve(apiReferencePackageRoot, apiReferencePackageJson.browser);
97
- if (!existsSync(jsPath)) throw new Error(`Could not locate @scalar/api-reference standalone bundle at "${jsPath}". Run the package build before reading SSR assets.`);
98
- _cachedJs = readFileSync(jsPath, "utf-8");
99
- }
100
- return _cachedJs;
144
+ * Get the standalone JavaScript bundle as a string.
145
+ *
146
+ * Serve this at a route (e.g. `/scalar/scalar.js`) and pass the same path
147
+ * as the `cdn` option to `renderApiReference`. The bundle handles client-side
148
+ * hydration of the server-rendered HTML.
149
+ */
150
+ export function getJsAsset() {
151
+ if (_cachedJs === undefined) {
152
+ const apiReferenceEntryPath = require.resolve('@scalar/api-reference');
153
+ const apiReferencePackageRoot = resolve(dirname(apiReferenceEntryPath), '..');
154
+ const apiReferencePackageJsonPath = resolve(apiReferencePackageRoot, 'package.json');
155
+ const apiReferencePackageJson = JSON.parse(readFileSync(apiReferencePackageJsonPath, 'utf-8'));
156
+ if (typeof apiReferencePackageJson.browser !== 'string' || apiReferencePackageJson.browser.length === 0) {
157
+ throw new Error(`Could not resolve @scalar/api-reference browser entry from "${apiReferencePackageJsonPath}". ` +
158
+ 'Expected a string "browser" field in package.json.');
159
+ }
160
+ const jsPath = resolve(apiReferencePackageRoot, apiReferencePackageJson.browser);
161
+ if (!existsSync(jsPath)) {
162
+ throw new Error(`Could not locate @scalar/api-reference standalone bundle at "${jsPath}". Run the package build before reading SSR assets.`);
163
+ }
164
+ _cachedJs = readFileSync(jsPath, 'utf-8');
165
+ }
166
+ return _cachedJs;
101
167
  }
102
168
  /** Escape HTML special characters in user-provided strings. */
103
169
  function escapeHtml(str) {
104
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
170
+ return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
105
171
  }
106
172
  /** Escape user-provided strings before inserting into HTML attributes. */
107
173
  function escapeHtmlAttribute(str) {
108
- return escapeHtml(str).replace(/"/g, "&quot;").replace(/'/g, "&#39;");
174
+ return escapeHtml(str).replace(/"/g, '&quot;').replace(/'/g, '&#39;');
109
175
  }
110
176
  /**
111
- * Escape a JSON string so it is safe to embed inside an inline script tag.
112
- * This prevents user content from closing the script tag.
113
- */
177
+ * Escape a JSON string so it is safe to embed inside an inline script tag.
178
+ * This prevents user content from closing the script tag.
179
+ */
114
180
  function escapeJsonForInlineScript(json) {
115
- return json.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
181
+ return json
182
+ .replace(/</g, '\\u003c')
183
+ .replace(/>/g, '\\u003e')
184
+ .replace(/&/g, '\\u0026')
185
+ .replace(/\u2028/g, '\\u2028')
186
+ .replace(/\u2029/g, '\\u2029');
116
187
  }
117
188
  /**
118
- * Escape a function's source code so it is safe to embed inside an inline script tag.
119
- *
120
- * Unlike escapeJsonForInlineScript (which escapes all `<` and `>`), this only neutralizes
121
- * sequences that could break out of a `<script>` block or open an HTML comment:
122
- * - `</` (case-insensitive closing tags, e.g. `<\/script>`)
123
- * - `<!--` (HTML comment open)
124
- * - U+2028 / U+2029 (line/paragraph separators, invalid in JS source outside strings)
125
- *
126
- * This preserves JS syntax like `=>`, `<`, `>`, and `>=`.
127
- */
189
+ * Escape a function's source code so it is safe to embed inside an inline script tag.
190
+ *
191
+ * Unlike escapeJsonForInlineScript (which escapes all `<` and `>`), this only neutralizes
192
+ * sequences that could break out of a `<script>` block or open an HTML comment:
193
+ * - `</` (case-insensitive closing tags, e.g. `</script>`)
194
+ * - `<!--` (HTML comment open)
195
+ * - U+2028 / U+2029 (line/paragraph separators, invalid in JS source outside strings)
196
+ *
197
+ * This preserves JS syntax like `=>`, `<`, `>`, and `>=`.
198
+ */
128
199
  function escapeFunctionSourceForInlineScript(source) {
129
- return source.replace(/<\//g, "<\\/").replace(/<!--/g, "<\\!--").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
200
+ return source
201
+ .replace(/<\//g, '<\\/')
202
+ .replace(/<!--/g, '<\\!--')
203
+ .replace(/\u2028/g, '\\u2028')
204
+ .replace(/\u2029/g, '\\u2029');
130
205
  }
131
206
  /** Add consistent indentation to multiline strings embedded in HTML output. */
132
- var addIndent = (str, spaces = 2, initialIndent = false) => {
133
- const indent = " ".repeat(spaces);
134
- return str.split("\n").map((line, index) => {
135
- if (index === 0 && !initialIndent) return line;
136
- return `${indent}${line}`;
137
- }).join("\n");
207
+ const addIndent = (str, spaces = 2, initialIndent = false) => {
208
+ const indent = ' '.repeat(spaces);
209
+ const lines = str.split('\n');
210
+ return lines
211
+ .map((line, index) => {
212
+ if (index === 0 && !initialIndent) {
213
+ return line;
214
+ }
215
+ return `${indent}${line}`;
216
+ })
217
+ .join('\n');
138
218
  };
139
219
  /**
140
- * Reject function values that would otherwise be silently dropped by JSON.stringify.
141
- * SSR only supports top-level function props and top-level arrays containing functions,
142
- * matching the client-side renderer behavior.
143
- */
144
- var assertNoNestedFunctions = (value, path) => {
145
- if (typeof value === "function") throw new Error(`Cannot serialize function at "${path}" for SSR hydration. Only top-level function properties and top-level arrays containing functions are supported.`);
146
- if (Array.isArray(value)) {
147
- value.forEach((item, index) => assertNoNestedFunctions(item, `${path}[${index}]`));
148
- return;
149
- }
150
- if (value && typeof value === "object") Object.entries(value).forEach(([key, nestedValue]) => assertNoNestedFunctions(nestedValue, `${path}.${key}`));
220
+ * Reject function values that would otherwise be silently dropped by JSON.stringify.
221
+ * SSR only supports top-level function props and top-level arrays containing functions,
222
+ * matching the client-side renderer behavior.
223
+ */
224
+ const assertNoNestedFunctions = (value, path) => {
225
+ if (typeof value === 'function') {
226
+ throw new Error(`Cannot serialize function at "${path}" for SSR hydration. ` +
227
+ 'Only top-level function properties and top-level arrays containing functions are supported.');
228
+ }
229
+ if (Array.isArray(value)) {
230
+ value.forEach((item, index) => assertNoNestedFunctions(item, `${path}[${index}]`));
231
+ return;
232
+ }
233
+ if (value && typeof value === 'object') {
234
+ Object.entries(value).forEach(([key, nestedValue]) => assertNoNestedFunctions(nestedValue, `${path}.${key}`));
235
+ }
151
236
  };
152
- var serializeJsonValue = (value) => escapeJsonForInlineScript(JSON.stringify(value));
153
- var serializeJsonObject = (value) => escapeJsonForInlineScript(JSON.stringify(value, null, 2));
154
- var serializePropertyKey = (key) => escapeJsonForInlineScript(JSON.stringify(key));
155
- var serializeArrayWithFunctions = (value, path) => {
156
- return `[${value.map((item, index) => {
157
- if (typeof item === "function") return escapeFunctionSourceForInlineScript(item.toString());
158
- assertNoNestedFunctions(item, `${path}[${index}]`);
159
- return serializeJsonValue(item);
160
- }).join(", ")}]`;
237
+ const serializeJsonValue = (value) => escapeJsonForInlineScript(JSON.stringify(value));
238
+ const serializeJsonObject = (value) => escapeJsonForInlineScript(JSON.stringify(value, null, 2));
239
+ const serializePropertyKey = (key) => escapeJsonForInlineScript(JSON.stringify(key));
240
+ const serializeArrayWithFunctions = (value, path) => {
241
+ return `[${value
242
+ .map((item, index) => {
243
+ if (typeof item === 'function') {
244
+ return escapeFunctionSourceForInlineScript(item.toString());
245
+ }
246
+ assertNoNestedFunctions(item, `${path}[${index}]`);
247
+ return serializeJsonValue(item);
248
+ })
249
+ .join(', ')}]`;
161
250
  };
162
- var serializeFunctionProperty = (key, value) => `${serializePropertyKey(key)}: ${escapeFunctionSourceForInlineScript(value.toString())}`;
163
- var serializeArrayProperty = (key, value) => `${serializePropertyKey(key)}: ${serializeArrayWithFunctions(value, key)}`;
164
- var mergeSerializedProperties = (jsonObjectLiteral, dynamicProperties) => {
165
- const formattedDynamicProperties = addIndent(dynamicProperties.join(",\n"), 8, true);
166
- if (jsonObjectLiteral === "{}") return `{\n${formattedDynamicProperties}\n }`;
167
- return `${jsonObjectLiteral.split("\n").slice(0, -1).join("\n")},\n${formattedDynamicProperties}\n }`;
251
+ const serializeFunctionProperty = (key, value) => `${serializePropertyKey(key)}: ${escapeFunctionSourceForInlineScript(value.toString())}`;
252
+ const serializeArrayProperty = (key, value) => `${serializePropertyKey(key)}: ${serializeArrayWithFunctions(value, key)}`;
253
+ const mergeSerializedProperties = (jsonObjectLiteral, dynamicProperties) => {
254
+ const formattedDynamicProperties = addIndent(dynamicProperties.join(',\n'), 8, true);
255
+ if (jsonObjectLiteral === '{}') {
256
+ return `{\n${formattedDynamicProperties}\n }`;
257
+ }
258
+ const jsonWithoutClosingBrace = jsonObjectLiteral.split('\n').slice(0, -1).join('\n');
259
+ return `${jsonWithoutClosingBrace},\n${formattedDynamicProperties}\n }`;
168
260
  };
169
261
  /**
170
- * Serialize a configuration object to a JavaScript object literal for hydration.
171
- * Top-level function props and top-level arrays containing functions are preserved
172
- * to match the client-side renderer behavior.
173
- */
174
- function serializeConfigToJs(config) {
175
- const restConfig = { ...config };
176
- const dynamicProperties = [];
177
- Object.entries(config).forEach(([key, value]) => {
178
- if (typeof value === "function") {
179
- dynamicProperties.push(serializeFunctionProperty(key, value));
180
- delete restConfig[key];
181
- return;
182
- }
183
- if (Array.isArray(value) && value.some((item) => typeof item === "function")) {
184
- dynamicProperties.push(serializeArrayProperty(key, value));
185
- delete restConfig[key];
186
- return;
187
- }
188
- assertNoNestedFunctions(value, key);
189
- });
190
- const indentedJsonString = addIndent(serializeJsonObject(restConfig), 6);
191
- if (dynamicProperties.length === 0) return indentedJsonString;
192
- return mergeSerializedProperties(indentedJsonString, dynamicProperties);
262
+ * Serialize a configuration object to a JavaScript object literal for hydration.
263
+ * Top-level function props and top-level arrays containing functions are preserved
264
+ * to match the client-side renderer behavior.
265
+ */
266
+ export function serializeConfigToJs(config) {
267
+ const restConfig = { ...config };
268
+ const dynamicProperties = [];
269
+ Object.entries(config).forEach(([key, value]) => {
270
+ if (typeof value === 'function') {
271
+ dynamicProperties.push(serializeFunctionProperty(key, value));
272
+ delete restConfig[key];
273
+ return;
274
+ }
275
+ if (Array.isArray(value) && value.some((item) => typeof item === 'function')) {
276
+ dynamicProperties.push(serializeArrayProperty(key, value));
277
+ delete restConfig[key];
278
+ return;
279
+ }
280
+ assertNoNestedFunctions(value, key);
281
+ });
282
+ const jsonString = serializeJsonObject(restConfig);
283
+ const indentedJsonString = addIndent(jsonString, 6);
284
+ if (dynamicProperties.length === 0) {
285
+ return indentedJsonString;
286
+ }
287
+ return mergeSerializedProperties(indentedJsonString, dynamicProperties);
193
288
  }
194
289
  /**
195
- * Render the Scalar API Reference as a complete HTML document with client-side
196
- * hydration.
197
- *
198
- * Returns a full `<!doctype html>` page with:
199
- * - Inline CSS in `<head>` (prevents flash of unstyled content)
200
- * - Color-mode detection script (runs before first paint)
201
- * - Pre-rendered Vue HTML (immediate content, no blank page)
202
- * - Script tags to load the standalone bundle and hydrate
203
- *
204
- * Serve the standalone JS bundle via `getJsAsset()` at the route matching
205
- * the `cdn` option (defaults to `/scalar/scalar.js`).
206
- */
207
- async function renderApiReference(options) {
208
- const title = escapeHtml(options.pageTitle ?? "Scalar API Reference");
209
- const css = options.css ?? getDefaultCss();
210
- const cdn = escapeHtmlAttribute(options.cdn ?? "/scalar/scalar.js");
211
- const html = await renderApiReferenceToString(options.config);
212
- const bodyScript = generateBodyScript(options.config);
213
- return `<!doctype html>
214
- <html lang="en">
290
+ * Render the Scalar API Reference as a complete HTML document with client-side
291
+ * hydration.
292
+ *
293
+ * Returns a full `<!doctype html>` page with:
294
+ * - Inline CSS in `<head>` (prevents flash of unstyled content)
295
+ * - Color-mode detection script (runs before first paint)
296
+ * - Pre-rendered Vue HTML (immediate content, no blank page)
297
+ * - Script tags to load the standalone bundle and hydrate
298
+ *
299
+ * Serve the standalone JS bundle via `getJsAsset()` at the route matching
300
+ * the `cdn` option (defaults to `/scalar/scalar.js`).
301
+ */
302
+ export async function renderApiReference(options) {
303
+ const title = options.pageTitle ?? 'Scalar API Reference';
304
+ const css = options.css ?? getDefaultCss();
305
+ const cdn = escapeHtmlAttribute(options.cdn ?? '/scalar/scalar.js');
306
+ const { html, head } = await renderApiReferenceApp({
307
+ configuration: options.config,
308
+ pageTitle: title,
309
+ });
310
+ const bodyScript = generateBodyScript(options.config);
311
+ const initialBodyClass = getInitialBodyClass(options.config);
312
+ const bodyAttrs = mergeBodyAttrsWithInitialClass(head.bodyAttrs, initialBodyClass);
313
+ const configJs = serializeConfigToJs(unwrapConfig(options.config));
314
+ return `<!doctype html>
315
+ <html${head.htmlAttrs}>
215
316
  <head>
216
- <meta charset="UTF-8" />
217
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
218
- <title>${title}</title>
317
+ ${head.headTags}
219
318
  <style>${css}</style>
220
319
  </head>
221
- <body class="${getInitialBodyClass(options.config)}">
320
+ <body${bodyAttrs}>
321
+ ${head.bodyTagsOpen}
222
322
  ${bodyScript}
223
323
  <div id="app">${html}</div>
224
- <script src="${cdn}"><\/script>
225
- <script>Scalar.createApiReference('#app', ${serializeConfigToJs(unwrapConfig(options.config))})<\/script>
324
+ <script src="${cdn}"></script>
325
+ <script>Scalar.createApiReference('#app', ${configJs})</script>
326
+ ${head.bodyTags}
226
327
  </body>
227
328
  </html>`;
228
329
  }
229
- //#endregion
230
- export { generateBodyScript, getJsAsset, renderApiReference, renderApiReferenceToString };
231
-
232
- //# sourceMappingURL=ssr.js.map
package/dist/ssr.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ssr.js","names":[],"sources":["../src/ssr.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, resolve } from 'node:path'\n\nimport { ApiReference } from '@scalar/api-reference'\nimport type { AnyApiReferenceConfiguration } from '@scalar/types/api-reference'\nimport { createSSRApp, h } from 'vue'\nimport { renderToString } from 'vue/server-renderer'\n\nconst require = createRequire(import.meta.url)\n\n/**\n * Unwrap the configuration from an array if needed, since AnyApiReferenceConfiguration\n * can be a single config or an array of configs.\n */\nfunction unwrapConfig(configuration: AnyApiReferenceConfiguration): Record<string, unknown> {\n const config = Array.isArray(configuration) ? configuration[0] : configuration\n return (config ?? {}) as Record<string, unknown>\n}\n\nfunction parseForceDarkModeState(config: Record<string, unknown>): 'dark' | 'light' | null {\n const forced = config.forceDarkModeState\n\n if (forced === 'dark' || forced === 'light') {\n return forced\n }\n\n return null\n}\n\nfunction parseDarkMode(config: Record<string, unknown>): boolean | null {\n return typeof config.darkMode === 'boolean' ? config.darkMode : null\n}\n\n/**\n * Generate an inline script that detects the user's color mode preference\n * and applies the correct class to <body> before content paints.\n *\n * Place this script before the app container in your HTML so it runs before\n * the first paint without interfering with Vue hydration.\n *\n * Priority:\n * 1. forceDarkModeState → always wins (no runtime detection)\n * 2. localStorage 'colorMode' → user's saved preference\n * 3. matchMedia system preference\n * 4. darkMode config → explicit default\n * 5. Fallback → light-mode\n */\nexport function generateBodyScript(configuration: AnyApiReferenceConfiguration): string {\n const config = unwrapConfig(configuration)\n const forced = parseForceDarkModeState(config)\n const darkMode = parseDarkMode(config)\n\n /** When forceDarkModeState is set, we do not need runtime detection at all. */\n if (forced) {\n return `<script>(function(){var cl=document.body.classList;cl.remove('dark-mode','light-mode');cl.add('${forced === 'dark' ? 'dark-mode' : 'light-mode'}')})()</script>`\n }\n\n /**\n * Runtime detection script: checks localStorage first, then system preference,\n * then falls back to the darkMode config value.\n */\n const fallback =\n darkMode === null ? `set(window.matchMedia('(prefers-color-scheme:dark)').matches)` : `set(${darkMode})`\n\n return `<script>(function(){var cl=document.body.classList;function set(d){cl.remove('dark-mode','light-mode');cl.add(d?'dark-mode':'light-mode')}try{var s=localStorage.getItem('colorMode');if(s==='dark'||s==='light'){set(s==='dark');return}}catch(e){}${fallback}})()</script>`\n}\n\n/**\n * Derive the initial SSR class for <body> from config.\n *\n * Priority:\n * 1. forceDarkModeState\n * 2. darkMode\n * 3. fallback to dark-mode (then runtime script can refine from localStorage/matchMedia)\n */\nfunction getInitialBodyClass(configuration: AnyApiReferenceConfiguration): 'dark-mode' | 'light-mode' {\n const config = unwrapConfig(configuration)\n const forced = parseForceDarkModeState(config)\n const darkMode = parseDarkMode(config)\n\n if (forced) {\n return forced === 'dark' ? 'dark-mode' : 'light-mode'\n }\n\n if (darkMode !== null) {\n return darkMode ? 'dark-mode' : 'light-mode'\n }\n\n return 'dark-mode'\n}\n\n/**\n * Render the Scalar API Reference to an HTML string for server-side rendering.\n * Use createApiReference on the client to hydrate the server-rendered output.\n *\n * Returns only the Vue-rendered HTML. Use generateBodyScript separately to get\n * the dark/light mode script — place it outside the app container so it does not\n * interfere with Vue hydration.\n */\nexport async function renderApiReferenceToString(configuration: AnyApiReferenceConfiguration): Promise<string> {\n const normalizedConfiguration = unwrapConfig(configuration)\n const app = createSSRApp(() => h(ApiReference, { configuration: normalizedConfiguration }))\n app.config.idPrefix = 'scalar-refs'\n\n return await renderToString(app)\n}\n\nlet _cachedCss: string | undefined\nlet _cachedJs: string | undefined\n\n/** Read the built style.css from the @scalar/api-reference package. */\nfunction getDefaultCss(): string {\n if (_cachedCss === undefined) {\n const cssPath = require.resolve('@scalar/api-reference/style.css')\n _cachedCss = readFileSync(cssPath, 'utf-8')\n }\n return _cachedCss\n}\n\n/**\n * Get the standalone JavaScript bundle as a string.\n *\n * Serve this at a route (e.g. `/scalar/scalar.js`) and pass the same path\n * as the `cdn` option to `renderApiReference`. The bundle handles client-side\n * hydration of the server-rendered HTML.\n */\nexport function getJsAsset(): string {\n if (_cachedJs === undefined) {\n const apiReferenceEntryPath = require.resolve('@scalar/api-reference')\n const apiReferencePackageRoot = resolve(dirname(apiReferenceEntryPath), '..')\n const apiReferencePackageJsonPath = resolve(apiReferencePackageRoot, 'package.json')\n const apiReferencePackageJson = JSON.parse(readFileSync(apiReferencePackageJsonPath, 'utf-8')) as {\n browser?: unknown\n }\n\n if (typeof apiReferencePackageJson.browser !== 'string' || apiReferencePackageJson.browser.length === 0) {\n throw new Error(\n `Could not resolve @scalar/api-reference browser entry from \"${apiReferencePackageJsonPath}\". ` +\n 'Expected a string \"browser\" field in package.json.',\n )\n }\n\n const jsPath = resolve(apiReferencePackageRoot, apiReferencePackageJson.browser)\n\n if (!existsSync(jsPath)) {\n throw new Error(\n `Could not locate @scalar/api-reference standalone bundle at \"${jsPath}\". Run the package build before reading SSR assets.`,\n )\n }\n\n _cachedJs = readFileSync(jsPath, 'utf-8')\n }\n return _cachedJs\n}\n\n/** Escape HTML special characters in user-provided strings. */\nfunction escapeHtml(str: string): string {\n return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n}\n\n/** Escape user-provided strings before inserting into HTML attributes. */\nfunction escapeHtmlAttribute(str: string): string {\n return escapeHtml(str).replace(/\"/g, '&quot;').replace(/'/g, '&#39;')\n}\n\n/**\n * Escape a JSON string so it is safe to embed inside an inline script tag.\n * This prevents user content from closing the script tag.\n */\nfunction escapeJsonForInlineScript(json: string): string {\n return json\n .replace(/</g, '\\\\u003c')\n .replace(/>/g, '\\\\u003e')\n .replace(/&/g, '\\\\u0026')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029')\n}\n\n/**\n * Escape a function's source code so it is safe to embed inside an inline script tag.\n *\n * Unlike escapeJsonForInlineScript (which escapes all `<` and `>`), this only neutralizes\n * sequences that could break out of a `<script>` block or open an HTML comment:\n * - `</` (case-insensitive closing tags, e.g. `</script>`)\n * - `<!--` (HTML comment open)\n * - U+2028 / U+2029 (line/paragraph separators, invalid in JS source outside strings)\n *\n * This preserves JS syntax like `=>`, `<`, `>`, and `>=`.\n */\nfunction escapeFunctionSourceForInlineScript(source: string): string {\n return source\n .replace(/<\\//g, '<\\\\/')\n .replace(/<!--/g, '<\\\\!--')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029')\n}\n\n/** Add consistent indentation to multiline strings embedded in HTML output. */\nconst addIndent = (str: string, spaces: number = 2, initialIndent: boolean = false): string => {\n const indent = ' '.repeat(spaces)\n const lines = str.split('\\n')\n\n return lines\n .map((line, index) => {\n if (index === 0 && !initialIndent) {\n return line\n }\n\n return `${indent}${line}`\n })\n .join('\\n')\n}\n\n/**\n * Reject function values that would otherwise be silently dropped by JSON.stringify.\n * SSR only supports top-level function props and top-level arrays containing functions,\n * matching the client-side renderer behavior.\n */\nconst assertNoNestedFunctions = (value: unknown, path: string): void => {\n if (typeof value === 'function') {\n throw new Error(\n `Cannot serialize function at \"${path}\" for SSR hydration. ` +\n 'Only top-level function properties and top-level arrays containing functions are supported.',\n )\n }\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => assertNoNestedFunctions(item, `${path}[${index}]`))\n return\n }\n\n if (value && typeof value === 'object') {\n Object.entries(value).forEach(([key, nestedValue]) => assertNoNestedFunctions(nestedValue, `${path}.${key}`))\n }\n}\n\nconst serializeJsonValue = (value: unknown): string => escapeJsonForInlineScript(JSON.stringify(value))\n\nconst serializeJsonObject = (value: Record<string, unknown>): string =>\n escapeJsonForInlineScript(JSON.stringify(value, null, 2))\n\nconst serializePropertyKey = (key: string): string => escapeJsonForInlineScript(JSON.stringify(key))\n\nconst serializeArrayWithFunctions = (value: unknown[], path: string): string => {\n return `[${value\n .map((item, index) => {\n if (typeof item === 'function') {\n return escapeFunctionSourceForInlineScript(item.toString())\n }\n\n assertNoNestedFunctions(item, `${path}[${index}]`)\n return serializeJsonValue(item)\n })\n .join(', ')}]`\n}\n\nconst serializeFunctionProperty = (key: string, value: Function): string =>\n `${serializePropertyKey(key)}: ${escapeFunctionSourceForInlineScript(value.toString())}`\n\nconst serializeArrayProperty = (key: string, value: unknown[]): string =>\n `${serializePropertyKey(key)}: ${serializeArrayWithFunctions(value, key)}`\n\nconst mergeSerializedProperties = (jsonObjectLiteral: string, dynamicProperties: string[]): string => {\n const formattedDynamicProperties = addIndent(dynamicProperties.join(',\\n'), 8, true)\n\n if (jsonObjectLiteral === '{}') {\n return `{\\n${formattedDynamicProperties}\\n }`\n }\n\n const jsonWithoutClosingBrace = jsonObjectLiteral.split('\\n').slice(0, -1).join('\\n')\n return `${jsonWithoutClosingBrace},\\n${formattedDynamicProperties}\\n }`\n}\n\n/**\n * Serialize a configuration object to a JavaScript object literal for hydration.\n * Top-level function props and top-level arrays containing functions are preserved\n * to match the client-side renderer behavior.\n */\nexport function serializeConfigToJs(config: Record<string, unknown>): string {\n const restConfig = { ...config }\n const dynamicProperties: string[] = []\n\n Object.entries(config).forEach(([key, value]) => {\n if (typeof value === 'function') {\n dynamicProperties.push(serializeFunctionProperty(key, value))\n delete restConfig[key]\n return\n }\n\n if (Array.isArray(value) && value.some((item) => typeof item === 'function')) {\n dynamicProperties.push(serializeArrayProperty(key, value))\n delete restConfig[key]\n return\n }\n\n assertNoNestedFunctions(value, key)\n })\n\n const jsonString = serializeJsonObject(restConfig)\n const indentedJsonString = addIndent(jsonString, 6)\n\n if (dynamicProperties.length === 0) {\n return indentedJsonString\n }\n\n return mergeSerializedProperties(indentedJsonString, dynamicProperties)\n}\n\n/**\n * Render the Scalar API Reference as a complete HTML document with client-side\n * hydration.\n *\n * Returns a full `<!doctype html>` page with:\n * - Inline CSS in `<head>` (prevents flash of unstyled content)\n * - Color-mode detection script (runs before first paint)\n * - Pre-rendered Vue HTML (immediate content, no blank page)\n * - Script tags to load the standalone bundle and hydrate\n *\n * Serve the standalone JS bundle via `getJsAsset()` at the route matching\n * the `cdn` option (defaults to `/scalar/scalar.js`).\n */\nexport async function renderApiReference(options: {\n /** The API reference configuration. */\n config: AnyApiReferenceConfiguration\n /** Page title. Defaults to \"Scalar API Reference\". */\n pageTitle?: string\n /** Override the built-in CSS. */\n css?: string\n /** URL path to the standalone JS bundle. Defaults to \"/scalar/scalar.js\". */\n cdn?: string\n}): Promise<string> {\n const title = escapeHtml(options.pageTitle ?? 'Scalar API Reference')\n const css = options.css ?? getDefaultCss()\n const cdn = escapeHtmlAttribute(options.cdn ?? '/scalar/scalar.js')\n const html = await renderApiReferenceToString(options.config)\n const bodyScript = generateBodyScript(options.config)\n const initialBodyClass = getInitialBodyClass(options.config)\n const configJs = serializeConfigToJs(unwrapConfig(options.config))\n\n return `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>${title}</title>\n <style>${css}</style>\n </head>\n <body class=\"${initialBodyClass}\">\n ${bodyScript}\n <div id=\"app\">${html}</div>\n <script src=\"${cdn}\"></script>\n <script>Scalar.createApiReference('#app', ${configJs})</script>\n </body>\n</html>`\n}\n"],"mappings":";;;;;;;AASA,IAAM,UAAU,cAAc,OAAO,KAAK,IAAI;;;;;AAM9C,SAAS,aAAa,eAAsE;AAE1F,SADe,MAAM,QAAQ,cAAc,GAAG,cAAc,KAAK,kBAC/C,EAAE;;AAGtB,SAAS,wBAAwB,QAA0D;CACzF,MAAM,SAAS,OAAO;AAEtB,KAAI,WAAW,UAAU,WAAW,QAClC,QAAO;AAGT,QAAO;;AAGT,SAAS,cAAc,QAAiD;AACtE,QAAO,OAAO,OAAO,aAAa,YAAY,OAAO,WAAW;;;;;;;;;;;;;;;;AAiBlE,SAAgB,mBAAmB,eAAqD;CACtF,MAAM,SAAS,aAAa,cAAc;CAC1C,MAAM,SAAS,wBAAwB,OAAO;CAC9C,MAAM,WAAW,cAAc,OAAO;;AAGtC,KAAI,OACF,QAAO,kGAAkG,WAAW,SAAS,cAAc,aAAa;AAU1J,QAAO,uPAFL,aAAa,OAAO,kEAAkE,OAAO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,QAAO;AAGT,QAAO,0BAA0B,oBAAoB,kBAAkB;;;;;;;;;;;;;;;AAgBzE,eAAsB,mBAAmB,SASrB;CAClB,MAAM,QAAQ,WAAW,QAAQ,aAAa,uBAAuB;CACrE,MAAM,MAAM,QAAQ,OAAO,eAAe;CAC1C,MAAM,MAAM,oBAAoB,QAAQ,OAAO,oBAAoB;CACnE,MAAM,OAAO,MAAM,2BAA2B,QAAQ,OAAO;CAC7D,MAAM,aAAa,mBAAmB,QAAQ,OAAO;AAIrD,QAAO;;;;;aAKI,MAAM;aACN,IAAI;;iBATU,oBAAoB,QAAQ,OAAO,CAW5B;MAC5B,WAAW;oBACG,KAAK;mBACN,IAAI;gDAbJ,oBAAoB,aAAa,QAAQ,OAAO,CAAC,CAcX"}
1
+ {"version":3,"file":"ssr.js","names":[],"sources":["../src/ssr.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, resolve } from 'node:path'\n\nimport { ApiReference } from '@scalar/api-reference'\nimport type { AnyApiReferenceConfiguration } from '@scalar/types/api-reference'\nimport { useServerSeoMeta } from '@unhead/vue'\nimport { createHead, renderSSRHead } from '@unhead/vue/server'\nimport { createSSRApp, h } from 'vue'\nimport { renderToString } from 'vue/server-renderer'\n\nconst require = createRequire(import.meta.url)\n\n/**\n * Unwrap the configuration from an array if needed, since AnyApiReferenceConfiguration\n * can be a single config or an array of configs.\n */\nfunction unwrapConfig(configuration: AnyApiReferenceConfiguration): Record<string, unknown> {\n const config = Array.isArray(configuration) ? configuration[0] : configuration\n return (config ?? {}) as Record<string, unknown>\n}\n\nfunction parseForceDarkModeState(config: Record<string, unknown>): 'dark' | 'light' | null {\n const forced = config.forceDarkModeState\n\n if (forced === 'dark' || forced === 'light') {\n return forced\n }\n\n return null\n}\n\nfunction parseDarkMode(config: Record<string, unknown>): boolean | null {\n return typeof config.darkMode === 'boolean' ? config.darkMode : null\n}\n\n/**\n * Generate an inline script that detects the user's color mode preference\n * and applies the correct class to <body> before content paints.\n *\n * Place this script before the app container in your HTML so it runs before\n * the first paint without interfering with Vue hydration.\n *\n * Priority:\n * 1. forceDarkModeState → always wins (no runtime detection)\n * 2. localStorage 'colorMode' → user's saved preference\n * 3. matchMedia system preference\n * 4. darkMode config → explicit default\n * 5. Fallback → light-mode\n */\nexport function generateBodyScript(configuration: AnyApiReferenceConfiguration): string {\n const config = unwrapConfig(configuration)\n const forced = parseForceDarkModeState(config)\n const darkMode = parseDarkMode(config)\n\n /** When forceDarkModeState is set, we do not need runtime detection at all. */\n if (forced) {\n return `<script>(function(){var cl=document.body.classList;cl.remove('dark-mode','light-mode');cl.add('${forced === 'dark' ? 'dark-mode' : 'light-mode'}')})()</script>`\n }\n\n /**\n * Runtime detection script: checks localStorage first, then system preference,\n * then falls back to the darkMode config value.\n */\n const fallback =\n darkMode === null ? `set(window.matchMedia('(prefers-color-scheme:dark)').matches)` : `set(${darkMode})`\n\n return `<script>(function(){var cl=document.body.classList;function set(d){cl.remove('dark-mode','light-mode');cl.add(d?'dark-mode':'light-mode')}try{var s=localStorage.getItem('colorMode');if(s==='dark'||s==='light'){set(s==='dark');return}}catch(e){}${fallback}})()</script>`\n}\n\n/**\n * Derive the initial SSR class for <body> from config.\n *\n * Priority:\n * 1. forceDarkModeState\n * 2. darkMode\n * 3. fallback to dark-mode (then runtime script can refine from localStorage/matchMedia)\n */\nfunction getInitialBodyClass(configuration: AnyApiReferenceConfiguration): 'dark-mode' | 'light-mode' {\n const config = unwrapConfig(configuration)\n const forced = parseForceDarkModeState(config)\n const darkMode = parseDarkMode(config)\n\n if (forced) {\n return forced === 'dark' ? 'dark-mode' : 'light-mode'\n }\n\n if (darkMode !== null) {\n return darkMode ? 'dark-mode' : 'light-mode'\n }\n\n return 'dark-mode'\n}\n\ntype RenderedSsrHead = Awaited<ReturnType<typeof renderSSRHead>>\n\nconst createHeadInstance = (pageTitle?: string) =>\n createHead({\n init: [\n {\n htmlAttrs: { lang: 'en' },\n ...(pageTitle ? { title: pageTitle } : {}),\n },\n ],\n })\n\n/**\n * Ensure the initial body class from Scalar config always exists.\n * If Unhead provides body classes, merge them rather than overriding.\n */\nfunction mergeBodyAttrsWithInitialClass(bodyAttrs: string, initialBodyClass: 'dark-mode' | 'light-mode'): string {\n const classAttributePattern = /\\sclass=(['\"])(.*?)\\1/i\n const classMatch = bodyAttrs.match(classAttributePattern)\n\n if (!classMatch) {\n return `${bodyAttrs} class=\"${initialBodyClass}\"`\n }\n\n const existingClassValue = classMatch[2] ?? ''\n const existingClasses = existingClassValue.split(/\\s+/).filter(Boolean)\n const mergedClasses = Array.from(new Set([...existingClasses, initialBodyClass])).join(' ')\n\n return bodyAttrs.replace(classAttributePattern, ` class=\"${mergedClasses}\"`)\n}\n\nasync function renderApiReferenceApp(options: {\n configuration: AnyApiReferenceConfiguration\n pageTitle?: string\n}): Promise<{ html: string; head: RenderedSsrHead }> {\n const normalizedConfiguration = unwrapConfig(options.configuration)\n const app = createSSRApp({\n setup: () => {\n const metaData = normalizedConfiguration.metaData\n if (metaData && typeof metaData === 'object') {\n useServerSeoMeta(metaData as Parameters<typeof useServerSeoMeta>[0])\n }\n\n return () => h(ApiReference, { configuration: normalizedConfiguration })\n },\n })\n const head = createHeadInstance(options.pageTitle)\n app.use(head)\n app.config.idPrefix = 'scalar-refs'\n\n const html = await renderToString(app)\n const headTags = await renderSSRHead(head)\n\n return {\n html,\n head: headTags,\n }\n}\n\n/**\n * Render the Scalar API Reference to an HTML string for server-side rendering.\n * Use createApiReference on the client to hydrate the server-rendered output.\n *\n * Returns only the Vue-rendered HTML. Use generateBodyScript separately to get\n * the dark/light mode script — place it outside the app container so it does not\n * interfere with Vue hydration.\n */\nexport async function renderApiReferenceToString(configuration: AnyApiReferenceConfiguration): Promise<string> {\n const { html } = await renderApiReferenceApp({ configuration })\n return html\n}\n\nlet _cachedCss: string | undefined\nlet _cachedJs: string | undefined\n\n/** Read the built style.css from the @scalar/api-reference package. */\nfunction getDefaultCss(): string {\n if (_cachedCss === undefined) {\n const cssPath = require.resolve('@scalar/api-reference/style.css')\n _cachedCss = readFileSync(cssPath, 'utf-8')\n }\n return _cachedCss\n}\n\n/**\n * Get the standalone JavaScript bundle as a string.\n *\n * Serve this at a route (e.g. `/scalar/scalar.js`) and pass the same path\n * as the `cdn` option to `renderApiReference`. The bundle handles client-side\n * hydration of the server-rendered HTML.\n */\nexport function getJsAsset(): string {\n if (_cachedJs === undefined) {\n const apiReferenceEntryPath = require.resolve('@scalar/api-reference')\n const apiReferencePackageRoot = resolve(dirname(apiReferenceEntryPath), '..')\n const apiReferencePackageJsonPath = resolve(apiReferencePackageRoot, 'package.json')\n const apiReferencePackageJson = JSON.parse(readFileSync(apiReferencePackageJsonPath, 'utf-8')) as {\n browser?: unknown\n }\n\n if (typeof apiReferencePackageJson.browser !== 'string' || apiReferencePackageJson.browser.length === 0) {\n throw new Error(\n `Could not resolve @scalar/api-reference browser entry from \"${apiReferencePackageJsonPath}\". ` +\n 'Expected a string \"browser\" field in package.json.',\n )\n }\n\n const jsPath = resolve(apiReferencePackageRoot, apiReferencePackageJson.browser)\n\n if (!existsSync(jsPath)) {\n throw new Error(\n `Could not locate @scalar/api-reference standalone bundle at \"${jsPath}\". Run the package build before reading SSR assets.`,\n )\n }\n\n _cachedJs = readFileSync(jsPath, 'utf-8')\n }\n return _cachedJs\n}\n\n/** Escape HTML special characters in user-provided strings. */\nfunction escapeHtml(str: string): string {\n return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n}\n\n/** Escape user-provided strings before inserting into HTML attributes. */\nfunction escapeHtmlAttribute(str: string): string {\n return escapeHtml(str).replace(/\"/g, '&quot;').replace(/'/g, '&#39;')\n}\n\n/**\n * Escape a JSON string so it is safe to embed inside an inline script tag.\n * This prevents user content from closing the script tag.\n */\nfunction escapeJsonForInlineScript(json: string): string {\n return json\n .replace(/</g, '\\\\u003c')\n .replace(/>/g, '\\\\u003e')\n .replace(/&/g, '\\\\u0026')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029')\n}\n\n/**\n * Escape a function's source code so it is safe to embed inside an inline script tag.\n *\n * Unlike escapeJsonForInlineScript (which escapes all `<` and `>`), this only neutralizes\n * sequences that could break out of a `<script>` block or open an HTML comment:\n * - `</` (case-insensitive closing tags, e.g. `</script>`)\n * - `<!--` (HTML comment open)\n * - U+2028 / U+2029 (line/paragraph separators, invalid in JS source outside strings)\n *\n * This preserves JS syntax like `=>`, `<`, `>`, and `>=`.\n */\nfunction escapeFunctionSourceForInlineScript(source: string): string {\n return source\n .replace(/<\\//g, '<\\\\/')\n .replace(/<!--/g, '<\\\\!--')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029')\n}\n\n/** Add consistent indentation to multiline strings embedded in HTML output. */\nconst addIndent = (str: string, spaces: number = 2, initialIndent: boolean = false): string => {\n const indent = ' '.repeat(spaces)\n const lines = str.split('\\n')\n\n return lines\n .map((line, index) => {\n if (index === 0 && !initialIndent) {\n return line\n }\n\n return `${indent}${line}`\n })\n .join('\\n')\n}\n\n/**\n * Reject function values that would otherwise be silently dropped by JSON.stringify.\n * SSR only supports top-level function props and top-level arrays containing functions,\n * matching the client-side renderer behavior.\n */\nconst assertNoNestedFunctions = (value: unknown, path: string): void => {\n if (typeof value === 'function') {\n throw new Error(\n `Cannot serialize function at \"${path}\" for SSR hydration. ` +\n 'Only top-level function properties and top-level arrays containing functions are supported.',\n )\n }\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => assertNoNestedFunctions(item, `${path}[${index}]`))\n return\n }\n\n if (value && typeof value === 'object') {\n Object.entries(value).forEach(([key, nestedValue]) => assertNoNestedFunctions(nestedValue, `${path}.${key}`))\n }\n}\n\nconst serializeJsonValue = (value: unknown): string => escapeJsonForInlineScript(JSON.stringify(value))\n\nconst serializeJsonObject = (value: Record<string, unknown>): string =>\n escapeJsonForInlineScript(JSON.stringify(value, null, 2))\n\nconst serializePropertyKey = (key: string): string => escapeJsonForInlineScript(JSON.stringify(key))\n\nconst serializeArrayWithFunctions = (value: unknown[], path: string): string => {\n return `[${value\n .map((item, index) => {\n if (typeof item === 'function') {\n return escapeFunctionSourceForInlineScript(item.toString())\n }\n\n assertNoNestedFunctions(item, `${path}[${index}]`)\n return serializeJsonValue(item)\n })\n .join(', ')}]`\n}\n\nconst serializeFunctionProperty = (key: string, value: Function): string =>\n `${serializePropertyKey(key)}: ${escapeFunctionSourceForInlineScript(value.toString())}`\n\nconst serializeArrayProperty = (key: string, value: unknown[]): string =>\n `${serializePropertyKey(key)}: ${serializeArrayWithFunctions(value, key)}`\n\nconst mergeSerializedProperties = (jsonObjectLiteral: string, dynamicProperties: string[]): string => {\n const formattedDynamicProperties = addIndent(dynamicProperties.join(',\\n'), 8, true)\n\n if (jsonObjectLiteral === '{}') {\n return `{\\n${formattedDynamicProperties}\\n }`\n }\n\n const jsonWithoutClosingBrace = jsonObjectLiteral.split('\\n').slice(0, -1).join('\\n')\n return `${jsonWithoutClosingBrace},\\n${formattedDynamicProperties}\\n }`\n}\n\n/**\n * Serialize a configuration object to a JavaScript object literal for hydration.\n * Top-level function props and top-level arrays containing functions are preserved\n * to match the client-side renderer behavior.\n */\nexport function serializeConfigToJs(config: Record<string, unknown>): string {\n const restConfig = { ...config }\n const dynamicProperties: string[] = []\n\n Object.entries(config).forEach(([key, value]) => {\n if (typeof value === 'function') {\n dynamicProperties.push(serializeFunctionProperty(key, value))\n delete restConfig[key]\n return\n }\n\n if (Array.isArray(value) && value.some((item) => typeof item === 'function')) {\n dynamicProperties.push(serializeArrayProperty(key, value))\n delete restConfig[key]\n return\n }\n\n assertNoNestedFunctions(value, key)\n })\n\n const jsonString = serializeJsonObject(restConfig)\n const indentedJsonString = addIndent(jsonString, 6)\n\n if (dynamicProperties.length === 0) {\n return indentedJsonString\n }\n\n return mergeSerializedProperties(indentedJsonString, dynamicProperties)\n}\n\n/**\n * Render the Scalar API Reference as a complete HTML document with client-side\n * hydration.\n *\n * Returns a full `<!doctype html>` page with:\n * - Inline CSS in `<head>` (prevents flash of unstyled content)\n * - Color-mode detection script (runs before first paint)\n * - Pre-rendered Vue HTML (immediate content, no blank page)\n * - Script tags to load the standalone bundle and hydrate\n *\n * Serve the standalone JS bundle via `getJsAsset()` at the route matching\n * the `cdn` option (defaults to `/scalar/scalar.js`).\n */\nexport async function renderApiReference(options: {\n /** The API reference configuration. */\n config: AnyApiReferenceConfiguration\n /** Page title. Defaults to \"Scalar API Reference\". */\n pageTitle?: string\n /** Override the built-in CSS. */\n css?: string\n /** URL path to the standalone JS bundle. Defaults to \"/scalar/scalar.js\". */\n cdn?: string\n}): Promise<string> {\n const title = options.pageTitle ?? 'Scalar API Reference'\n const css = options.css ?? getDefaultCss()\n const cdn = escapeHtmlAttribute(options.cdn ?? '/scalar/scalar.js')\n const { html, head } = await renderApiReferenceApp({\n configuration: options.config,\n pageTitle: title,\n })\n const bodyScript = generateBodyScript(options.config)\n const initialBodyClass = getInitialBodyClass(options.config)\n const bodyAttrs = mergeBodyAttrsWithInitialClass(head.bodyAttrs, initialBodyClass)\n const configJs = serializeConfigToJs(unwrapConfig(options.config))\n\n return `<!doctype html>\n<html${head.htmlAttrs}>\n <head>\n ${head.headTags}\n <style>${css}</style>\n </head>\n <body${bodyAttrs}>\n ${head.bodyTagsOpen}\n ${bodyScript}\n <div id=\"app\">${html}</div>\n <script src=\"${cdn}\"></script>\n <script>Scalar.createApiReference('#app', ${configJs})</script>\n ${head.bodyTags}\n </body>\n</html>`\n}\n"],"mappings":";;;;;;;;;AAWA,IAAM,UAAU,cAAc,OAAO,KAAK,IAAI;;;;;AAM9C,SAAS,aAAa,eAAsE;AAE1F,SADe,MAAM,QAAQ,cAAc,GAAG,cAAc,KAAK,kBAC/C,EAAE;;AAGtB,SAAS,wBAAwB,QAA0D;CACzF,MAAM,SAAS,OAAO;AAEtB,KAAI,WAAW,UAAU,WAAW,QAClC,QAAO;AAGT,QAAO;;A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;;;;;;AAgBzE,eAAsB,mBAAmB,SASrB;CAClB,MAAM,QAAQ,QAAQ,aAAa;CACnC,MAAM,MAAM,QAAQ,OAAO,eAAe;CAC1C,MAAM,MAAM,oBAAoB,QAAQ,OAAO,oBAAoB;CACnE,MAAM,EAAE,MAAM,SAAS,MAAM,sBAAsB;EACjD,eAAe,QAAQ;EACvB,WAAW;EACZ,CAAC;CACF,MAAM,aAAa,mBAAmB,QAAQ,OAAO;CACrD,MAAM,mBAAmB,oBAAoB,QAAQ,OAAO;CAC5D,MAAM,YAAY,+BAA+B,KAAK,WAAW,iBAAiB;CAClF,MAAM,WAAW,oBAAoB,aAAa,QAAQ,OAAO,CAAC;AAElE,QAAO;OACF,KAAK,UAAU;;MAEhB,KAAK,SAAS;aACP,IAAI;;SAER,UAAU;MACb,KAAK,aAAa;MAClB,WAAW;oBACG,KAAK;mBACN,IAAI;gDACyB,SAAS;MACnD,KAAK,SAAS"}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "directory": "packages/server-side-rendering"
12
12
  },
13
13
  "keywords": [],
14
- "version": "0.1.13",
14
+ "version": "0.1.16",
15
15
  "engines": {
16
16
  "node": ">=22"
17
17
  },
@@ -28,19 +28,21 @@
28
28
  "CHANGELOG.md"
29
29
  ],
30
30
  "dependencies": {
31
+ "@unhead/vue": "^2.1.12",
31
32
  "vue": "^3.5.30",
32
- "@scalar/api-reference": "1.55.3",
33
- "@scalar/types": "0.9.6"
33
+ "@scalar/api-reference": "1.57.1",
34
+ "@scalar/types": "0.11.0"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@hono/node-server": "^1.19.10",
37
38
  "@vitejs/plugin-vue": "^6.0.3",
38
39
  "hono": "^4.12.7",
39
40
  "tsx": "4.19.4",
40
- "vite": "8.0.0"
41
+ "vite": "8.0.0",
42
+ "vue-tsc": "^3.2.4"
41
43
  },
42
44
  "scripts": {
43
- "build": "vite build",
45
+ "build": "vite build && vue-tsc -p tsconfig.build.json",
44
46
  "dev": "tsx playground/server.ts",
45
47
  "test": "vitest --run",
46
48
  "types:check": "tsc --noEmit"