@scalar/nextjs-api-reference 0.10.3 → 0.10.4
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 +6 -0
- package/dist/index.cjs +104 -79
- package/dist/index.js +105 -81
- package/dist/index.umd.cjs +117 -92
- package/package.json +5 -10
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,75 +1,86 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
//#region ../../packages/core/dist/libs/html-rendering/html-rendering.js
|
|
3
|
+
/**
|
|
4
|
+
* Helper function to add consistent indentation to multiline strings
|
|
5
|
+
* @param str The string to indent
|
|
6
|
+
* @param spaces Number of spaces for each level
|
|
7
|
+
* @param initialIndent Whether to indent the first line
|
|
8
|
+
*/
|
|
9
|
+
var addIndent = (str, spaces = 2, initialIndent = false) => {
|
|
10
|
+
const indent = " ".repeat(spaces);
|
|
11
|
+
return str.split("\n").map((line, index) => {
|
|
12
|
+
if (index === 0 && !initialIndent) return line;
|
|
13
|
+
return `${indent}${line}`;
|
|
14
|
+
}).join("\n");
|
|
12
15
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Generate the style tag with custom theme if needed
|
|
18
|
+
*/
|
|
19
|
+
var getStyles = (configuration, customTheme) => {
|
|
20
|
+
const styles = [];
|
|
21
|
+
if (configuration.customCss) {
|
|
22
|
+
styles.push("/* Custom CSS */");
|
|
23
|
+
styles.push(configuration.customCss);
|
|
24
|
+
}
|
|
25
|
+
if (!configuration.theme && customTheme) {
|
|
26
|
+
styles.push("/* Custom Theme */");
|
|
27
|
+
styles.push(customTheme);
|
|
28
|
+
}
|
|
29
|
+
if (styles.length === 0) return "";
|
|
30
|
+
return `
|
|
27
31
|
<style type="text/css">
|
|
28
32
|
${addIndent(styles.join("\n\n"), 6)}
|
|
29
33
|
</style>`;
|
|
30
34
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The HTML document to render the Scalar API reference.
|
|
37
|
+
*
|
|
38
|
+
* We must check the passed in configuration and not the configuration for the theme as the configuration will have it
|
|
39
|
+
* defaulted to 'default'
|
|
40
|
+
*/
|
|
41
|
+
var getHtmlDocument = (givenConfiguration, customTheme = "") => {
|
|
42
|
+
const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration;
|
|
43
|
+
const configuration = getConfiguration({
|
|
44
|
+
...rest,
|
|
45
|
+
...theme ? { theme } : {},
|
|
46
|
+
customCss
|
|
47
|
+
});
|
|
48
|
+
return `<!doctype html>
|
|
39
49
|
<html>
|
|
40
50
|
<head>
|
|
41
51
|
<title>${pageTitle ?? "Scalar API Reference"}</title>
|
|
42
52
|
<meta charset="utf-8" />
|
|
43
53
|
<meta
|
|
44
54
|
name="viewport"
|
|
45
|
-
content="width=device-width, initial-scale=1" />${getStyles(configuration,
|
|
55
|
+
content="width=device-width, initial-scale=1" />${getStyles(configuration, customTheme)}
|
|
46
56
|
</head>
|
|
47
57
|
<body>
|
|
48
58
|
<div id="app"></div>${getScriptTags(configuration, cdn)}
|
|
49
59
|
</body>
|
|
50
60
|
</html>`;
|
|
51
|
-
return content;
|
|
52
61
|
};
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to serialize arrays that may contain functions
|
|
64
|
+
*/
|
|
65
|
+
var serializeArrayWithFunctions = (arr) => {
|
|
66
|
+
return `[${arr.map((item) => typeof item === "function" ? item.toString() : JSON.stringify(item)).join(", ")}]`;
|
|
55
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* The script tags to load the @scalar/api-reference package from the CDN.
|
|
70
|
+
*/
|
|
56
71
|
function getScriptTags(configuration, cdn) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const functionPropsString = functionProps.length ? `,
|
|
70
|
-
${functionProps.join(",\n ")}
|
|
71
|
-
}` : "}";
|
|
72
|
-
return `
|
|
72
|
+
const restConfig = { ...configuration };
|
|
73
|
+
const functionProps = [];
|
|
74
|
+
for (const [key, value] of Object.entries(configuration)) if (typeof value === "function") {
|
|
75
|
+
functionProps.push(`"${key}": ${value.toString()}`);
|
|
76
|
+
delete restConfig[key];
|
|
77
|
+
} else if (Array.isArray(value) && value.some((item) => typeof item === "function")) {
|
|
78
|
+
functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
|
|
79
|
+
delete restConfig[key];
|
|
80
|
+
}
|
|
81
|
+
const configString = JSON.stringify(restConfig, null, 2).split("\n").map((line, index) => index === 0 ? line : " " + line).join("\n").replace(/\s*}$/, "");
|
|
82
|
+
const functionPropsString = functionProps.length ? `,\n ${functionProps.join(",\n ")}\n }` : "}";
|
|
83
|
+
return `
|
|
73
84
|
<!-- Load the Script -->
|
|
74
85
|
<script src="${cdn ?? "https://cdn.jsdelivr.net/npm/@scalar/api-reference"}"><\/script>
|
|
75
86
|
|
|
@@ -78,19 +89,21 @@ function getScriptTags(configuration, cdn) {
|
|
|
78
89
|
Scalar.createApiReference('#app', ${configString}${functionPropsString})
|
|
79
90
|
<\/script>`;
|
|
80
91
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
delete configuration.content;
|
|
90
|
-
}
|
|
91
|
-
return configuration;
|
|
92
|
+
/**
|
|
93
|
+
* The configuration to pass to the @scalar/api-reference package.
|
|
94
|
+
*/
|
|
95
|
+
var getConfiguration = (givenConfiguration) => {
|
|
96
|
+
const configuration = { ...givenConfiguration };
|
|
97
|
+
if (typeof configuration.content === "function") configuration.content = configuration.content();
|
|
98
|
+
if (configuration.content && configuration.url) delete configuration.content;
|
|
99
|
+
return configuration;
|
|
92
100
|
};
|
|
93
|
-
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/custom-theme.ts
|
|
103
|
+
/**
|
|
104
|
+
* The custom theme for Next.js
|
|
105
|
+
*/
|
|
106
|
+
var customTheme = `
|
|
94
107
|
/* basic theme */
|
|
95
108
|
.dark-mode {
|
|
96
109
|
--scalar-color-1: rgba(255, 255, 255, 0.9);
|
|
@@ -212,20 +225,32 @@ const customTheme = `
|
|
|
212
225
|
border: 1px solid var(--scalar-border-color);
|
|
213
226
|
}
|
|
214
227
|
`;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/ApiReference.ts
|
|
230
|
+
/**
|
|
231
|
+
* The default configuration for the API Reference.
|
|
232
|
+
*/
|
|
233
|
+
var DEFAULT_CONFIGURATION = { _integration: "nextjs" };
|
|
234
|
+
/**
|
|
235
|
+
* Next.js adapter for an Api Reference
|
|
236
|
+
*
|
|
237
|
+
* {@link https://github.com/scalar/scalar/tree/main/documentation/configuration.md Configuration}
|
|
238
|
+
*
|
|
239
|
+
* @params config - the Api Reference config object
|
|
240
|
+
* @params options - reserved for future use to add customization to the response
|
|
241
|
+
*/
|
|
242
|
+
var ApiReference = (givenConfiguration) => {
|
|
243
|
+
const configuration = {
|
|
244
|
+
...DEFAULT_CONFIGURATION,
|
|
245
|
+
...givenConfiguration
|
|
246
|
+
};
|
|
247
|
+
return () => {
|
|
248
|
+
const referenceDocument = getHtmlDocument(configuration, customTheme);
|
|
249
|
+
return new Response(referenceDocument, {
|
|
250
|
+
status: 200,
|
|
251
|
+
headers: { "Content-Type": "text/html" }
|
|
252
|
+
});
|
|
253
|
+
};
|
|
230
254
|
};
|
|
255
|
+
//#endregion
|
|
231
256
|
exports.ApiReference = ApiReference;
|
package/dist/index.js
CHANGED
|
@@ -1,73 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//#region ../../packages/core/dist/libs/html-rendering/html-rendering.js
|
|
2
|
+
/**
|
|
3
|
+
* Helper function to add consistent indentation to multiline strings
|
|
4
|
+
* @param str The string to indent
|
|
5
|
+
* @param spaces Number of spaces for each level
|
|
6
|
+
* @param initialIndent Whether to indent the first line
|
|
7
|
+
*/
|
|
8
|
+
var addIndent = (str, spaces = 2, initialIndent = false) => {
|
|
9
|
+
const indent = " ".repeat(spaces);
|
|
10
|
+
return str.split("\n").map((line, index) => {
|
|
11
|
+
if (index === 0 && !initialIndent) return line;
|
|
12
|
+
return `${indent}${line}`;
|
|
13
|
+
}).join("\n");
|
|
10
14
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Generate the style tag with custom theme if needed
|
|
17
|
+
*/
|
|
18
|
+
var getStyles = (configuration, customTheme) => {
|
|
19
|
+
const styles = [];
|
|
20
|
+
if (configuration.customCss) {
|
|
21
|
+
styles.push("/* Custom CSS */");
|
|
22
|
+
styles.push(configuration.customCss);
|
|
23
|
+
}
|
|
24
|
+
if (!configuration.theme && customTheme) {
|
|
25
|
+
styles.push("/* Custom Theme */");
|
|
26
|
+
styles.push(customTheme);
|
|
27
|
+
}
|
|
28
|
+
if (styles.length === 0) return "";
|
|
29
|
+
return `
|
|
25
30
|
<style type="text/css">
|
|
26
31
|
${addIndent(styles.join("\n\n"), 6)}
|
|
27
32
|
</style>`;
|
|
28
33
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The HTML document to render the Scalar API reference.
|
|
36
|
+
*
|
|
37
|
+
* We must check the passed in configuration and not the configuration for the theme as the configuration will have it
|
|
38
|
+
* defaulted to 'default'
|
|
39
|
+
*/
|
|
40
|
+
var getHtmlDocument = (givenConfiguration, customTheme = "") => {
|
|
41
|
+
const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration;
|
|
42
|
+
const configuration = getConfiguration({
|
|
43
|
+
...rest,
|
|
44
|
+
...theme ? { theme } : {},
|
|
45
|
+
customCss
|
|
46
|
+
});
|
|
47
|
+
return `<!doctype html>
|
|
37
48
|
<html>
|
|
38
49
|
<head>
|
|
39
50
|
<title>${pageTitle ?? "Scalar API Reference"}</title>
|
|
40
51
|
<meta charset="utf-8" />
|
|
41
52
|
<meta
|
|
42
53
|
name="viewport"
|
|
43
|
-
content="width=device-width, initial-scale=1" />${getStyles(configuration,
|
|
54
|
+
content="width=device-width, initial-scale=1" />${getStyles(configuration, customTheme)}
|
|
44
55
|
</head>
|
|
45
56
|
<body>
|
|
46
57
|
<div id="app"></div>${getScriptTags(configuration, cdn)}
|
|
47
58
|
</body>
|
|
48
59
|
</html>`;
|
|
49
|
-
return content;
|
|
50
60
|
};
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Helper function to serialize arrays that may contain functions
|
|
63
|
+
*/
|
|
64
|
+
var serializeArrayWithFunctions = (arr) => {
|
|
65
|
+
return `[${arr.map((item) => typeof item === "function" ? item.toString() : JSON.stringify(item)).join(", ")}]`;
|
|
53
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* The script tags to load the @scalar/api-reference package from the CDN.
|
|
69
|
+
*/
|
|
54
70
|
function getScriptTags(configuration, cdn) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const functionPropsString = functionProps.length ? `,
|
|
68
|
-
${functionProps.join(",\n ")}
|
|
69
|
-
}` : "}";
|
|
70
|
-
return `
|
|
71
|
+
const restConfig = { ...configuration };
|
|
72
|
+
const functionProps = [];
|
|
73
|
+
for (const [key, value] of Object.entries(configuration)) if (typeof value === "function") {
|
|
74
|
+
functionProps.push(`"${key}": ${value.toString()}`);
|
|
75
|
+
delete restConfig[key];
|
|
76
|
+
} else if (Array.isArray(value) && value.some((item) => typeof item === "function")) {
|
|
77
|
+
functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
|
|
78
|
+
delete restConfig[key];
|
|
79
|
+
}
|
|
80
|
+
const configString = JSON.stringify(restConfig, null, 2).split("\n").map((line, index) => index === 0 ? line : " " + line).join("\n").replace(/\s*}$/, "");
|
|
81
|
+
const functionPropsString = functionProps.length ? `,\n ${functionProps.join(",\n ")}\n }` : "}";
|
|
82
|
+
return `
|
|
71
83
|
<!-- Load the Script -->
|
|
72
84
|
<script src="${cdn ?? "https://cdn.jsdelivr.net/npm/@scalar/api-reference"}"><\/script>
|
|
73
85
|
|
|
@@ -76,19 +88,21 @@ function getScriptTags(configuration, cdn) {
|
|
|
76
88
|
Scalar.createApiReference('#app', ${configString}${functionPropsString})
|
|
77
89
|
<\/script>`;
|
|
78
90
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
delete configuration.content;
|
|
88
|
-
}
|
|
89
|
-
return configuration;
|
|
91
|
+
/**
|
|
92
|
+
* The configuration to pass to the @scalar/api-reference package.
|
|
93
|
+
*/
|
|
94
|
+
var getConfiguration = (givenConfiguration) => {
|
|
95
|
+
const configuration = { ...givenConfiguration };
|
|
96
|
+
if (typeof configuration.content === "function") configuration.content = configuration.content();
|
|
97
|
+
if (configuration.content && configuration.url) delete configuration.content;
|
|
98
|
+
return configuration;
|
|
90
99
|
};
|
|
91
|
-
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/custom-theme.ts
|
|
102
|
+
/**
|
|
103
|
+
* The custom theme for Next.js
|
|
104
|
+
*/
|
|
105
|
+
var customTheme = `
|
|
92
106
|
/* basic theme */
|
|
93
107
|
.dark-mode {
|
|
94
108
|
--scalar-color-1: rgba(255, 255, 255, 0.9);
|
|
@@ -210,22 +224,32 @@ const customTheme = `
|
|
|
210
224
|
border: 1px solid var(--scalar-border-color);
|
|
211
225
|
}
|
|
212
226
|
`;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/ApiReference.ts
|
|
229
|
+
/**
|
|
230
|
+
* The default configuration for the API Reference.
|
|
231
|
+
*/
|
|
232
|
+
var DEFAULT_CONFIGURATION = { _integration: "nextjs" };
|
|
233
|
+
/**
|
|
234
|
+
* Next.js adapter for an Api Reference
|
|
235
|
+
*
|
|
236
|
+
* {@link https://github.com/scalar/scalar/tree/main/documentation/configuration.md Configuration}
|
|
237
|
+
*
|
|
238
|
+
* @params config - the Api Reference config object
|
|
239
|
+
* @params options - reserved for future use to add customization to the response
|
|
240
|
+
*/
|
|
241
|
+
var ApiReference = (givenConfiguration) => {
|
|
242
|
+
const configuration = {
|
|
243
|
+
...DEFAULT_CONFIGURATION,
|
|
244
|
+
...givenConfiguration
|
|
245
|
+
};
|
|
246
|
+
return () => {
|
|
247
|
+
const referenceDocument = getHtmlDocument(configuration, customTheme);
|
|
248
|
+
return new Response(referenceDocument, {
|
|
249
|
+
status: 200,
|
|
250
|
+
headers: { "Content-Type": "text/html" }
|
|
251
|
+
});
|
|
252
|
+
};
|
|
231
253
|
};
|
|
254
|
+
//#endregion
|
|
255
|
+
export { ApiReference };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,77 +1,89 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
|
|
3
|
-
})(this,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@scalar/nextjs-api-reference"] = {}));
|
|
3
|
+
})(this, function(exports) {
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
5
|
+
//#region ../../packages/core/dist/libs/html-rendering/html-rendering.js
|
|
6
|
+
/**
|
|
7
|
+
* Helper function to add consistent indentation to multiline strings
|
|
8
|
+
* @param str The string to indent
|
|
9
|
+
* @param spaces Number of spaces for each level
|
|
10
|
+
* @param initialIndent Whether to indent the first line
|
|
11
|
+
*/
|
|
12
|
+
var addIndent = (str, spaces = 2, initialIndent = false) => {
|
|
13
|
+
const indent = " ".repeat(spaces);
|
|
14
|
+
return str.split("\n").map((line, index) => {
|
|
15
|
+
if (index === 0 && !initialIndent) return line;
|
|
16
|
+
return `${indent}${line}`;
|
|
17
|
+
}).join("\n");
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Generate the style tag with custom theme if needed
|
|
21
|
+
*/
|
|
22
|
+
var getStyles = (configuration, customTheme) => {
|
|
23
|
+
const styles = [];
|
|
24
|
+
if (configuration.customCss) {
|
|
25
|
+
styles.push("/* Custom CSS */");
|
|
26
|
+
styles.push(configuration.customCss);
|
|
27
|
+
}
|
|
28
|
+
if (!configuration.theme && customTheme) {
|
|
29
|
+
styles.push("/* Custom Theme */");
|
|
30
|
+
styles.push(customTheme);
|
|
31
|
+
}
|
|
32
|
+
if (styles.length === 0) return "";
|
|
33
|
+
return `
|
|
29
34
|
<style type="text/css">
|
|
30
35
|
${addIndent(styles.join("\n\n"), 6)}
|
|
31
36
|
</style>`;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The HTML document to render the Scalar API reference.
|
|
40
|
+
*
|
|
41
|
+
* We must check the passed in configuration and not the configuration for the theme as the configuration will have it
|
|
42
|
+
* defaulted to 'default'
|
|
43
|
+
*/
|
|
44
|
+
var getHtmlDocument = (givenConfiguration, customTheme = "") => {
|
|
45
|
+
const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration;
|
|
46
|
+
const configuration = getConfiguration({
|
|
47
|
+
...rest,
|
|
48
|
+
...theme ? { theme } : {},
|
|
49
|
+
customCss
|
|
50
|
+
});
|
|
51
|
+
return `<!doctype html>
|
|
41
52
|
<html>
|
|
42
53
|
<head>
|
|
43
54
|
<title>${pageTitle ?? "Scalar API Reference"}</title>
|
|
44
55
|
<meta charset="utf-8" />
|
|
45
56
|
<meta
|
|
46
57
|
name="viewport"
|
|
47
|
-
content="width=device-width, initial-scale=1" />${getStyles(configuration,
|
|
58
|
+
content="width=device-width, initial-scale=1" />${getStyles(configuration, customTheme)}
|
|
48
59
|
</head>
|
|
49
60
|
<body>
|
|
50
61
|
<div id="app"></div>${getScriptTags(configuration, cdn)}
|
|
51
62
|
</body>
|
|
52
63
|
</html>`;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Helper function to serialize arrays that may contain functions
|
|
67
|
+
*/
|
|
68
|
+
var serializeArrayWithFunctions = (arr) => {
|
|
69
|
+
return `[${arr.map((item) => typeof item === "function" ? item.toString() : JSON.stringify(item)).join(", ")}]`;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The script tags to load the @scalar/api-reference package from the CDN.
|
|
73
|
+
*/
|
|
74
|
+
function getScriptTags(configuration, cdn) {
|
|
75
|
+
const restConfig = { ...configuration };
|
|
76
|
+
const functionProps = [];
|
|
77
|
+
for (const [key, value] of Object.entries(configuration)) if (typeof value === "function") {
|
|
78
|
+
functionProps.push(`"${key}": ${value.toString()}`);
|
|
79
|
+
delete restConfig[key];
|
|
80
|
+
} else if (Array.isArray(value) && value.some((item) => typeof item === "function")) {
|
|
81
|
+
functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
|
|
82
|
+
delete restConfig[key];
|
|
83
|
+
}
|
|
84
|
+
const configString = JSON.stringify(restConfig, null, 2).split("\n").map((line, index) => index === 0 ? line : " " + line).join("\n").replace(/\s*}$/, "");
|
|
85
|
+
const functionPropsString = functionProps.length ? `,\n ${functionProps.join(",\n ")}\n }` : "}";
|
|
86
|
+
return `
|
|
75
87
|
<!-- Load the Script -->
|
|
76
88
|
<script src="${cdn ?? "https://cdn.jsdelivr.net/npm/@scalar/api-reference"}"><\/script>
|
|
77
89
|
|
|
@@ -79,20 +91,22 @@
|
|
|
79
91
|
<script type="text/javascript">
|
|
80
92
|
Scalar.createApiReference('#app', ${configString}${functionPropsString})
|
|
81
93
|
<\/script>`;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The configuration to pass to the @scalar/api-reference package.
|
|
97
|
+
*/
|
|
98
|
+
var getConfiguration = (givenConfiguration) => {
|
|
99
|
+
const configuration = { ...givenConfiguration };
|
|
100
|
+
if (typeof configuration.content === "function") configuration.content = configuration.content();
|
|
101
|
+
if (configuration.content && configuration.url) delete configuration.content;
|
|
102
|
+
return configuration;
|
|
103
|
+
};
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/custom-theme.ts
|
|
106
|
+
/**
|
|
107
|
+
* The custom theme for Next.js
|
|
108
|
+
*/
|
|
109
|
+
var customTheme = `
|
|
96
110
|
/* basic theme */
|
|
97
111
|
.dark-mode {
|
|
98
112
|
--scalar-color-1: rgba(255, 255, 255, 0.9);
|
|
@@ -214,22 +228,33 @@
|
|
|
214
228
|
border: 1px solid var(--scalar-border-color);
|
|
215
229
|
}
|
|
216
230
|
`;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/ApiReference.ts
|
|
233
|
+
/**
|
|
234
|
+
* The default configuration for the API Reference.
|
|
235
|
+
*/
|
|
236
|
+
var DEFAULT_CONFIGURATION = { _integration: "nextjs" };
|
|
237
|
+
/**
|
|
238
|
+
* Next.js adapter for an Api Reference
|
|
239
|
+
*
|
|
240
|
+
* {@link https://github.com/scalar/scalar/tree/main/documentation/configuration.md Configuration}
|
|
241
|
+
*
|
|
242
|
+
* @params config - the Api Reference config object
|
|
243
|
+
* @params options - reserved for future use to add customization to the response
|
|
244
|
+
*/
|
|
245
|
+
var ApiReference = (givenConfiguration) => {
|
|
246
|
+
const configuration = {
|
|
247
|
+
...DEFAULT_CONFIGURATION,
|
|
248
|
+
...givenConfiguration
|
|
249
|
+
};
|
|
250
|
+
return () => {
|
|
251
|
+
const referenceDocument = getHtmlDocument(configuration, customTheme);
|
|
252
|
+
return new Response(referenceDocument, {
|
|
253
|
+
status: 200,
|
|
254
|
+
headers: { "Content-Type": "text/html" }
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
//#endregion
|
|
259
|
+
exports.ApiReference = ApiReference;
|
|
260
|
+
});
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"openapi",
|
|
19
19
|
"swagger"
|
|
20
20
|
],
|
|
21
|
-
"version": "0.10.
|
|
21
|
+
"version": "0.10.4",
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=22"
|
|
24
24
|
},
|
|
@@ -50,20 +50,19 @@
|
|
|
50
50
|
"documentation": "https://scalar.com/products/api-references/integrations/nextjs"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@scalar/core": "0.4.
|
|
53
|
+
"@scalar/core": "0.4.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/node": "^24.1.0",
|
|
57
57
|
"@types/react": "^19.2.7",
|
|
58
58
|
"@types/react-dom": "^19.2.3",
|
|
59
|
-
"@vitejs/plugin-react": "
|
|
59
|
+
"@vitejs/plugin-react": "6.0.1",
|
|
60
60
|
"next": "^15.5.10",
|
|
61
61
|
"react": "^19.2.3",
|
|
62
62
|
"react-dom": "^19.2.3",
|
|
63
|
-
"vite": "
|
|
63
|
+
"vite": "8.0.0",
|
|
64
64
|
"vite-plugin-dts": "^4.3.0",
|
|
65
|
-
"vitest": "4.0
|
|
66
|
-
"@scalar/build-tooling": "0.5.0"
|
|
65
|
+
"vitest": "4.1.0"
|
|
67
66
|
},
|
|
68
67
|
"peerDependencies": {
|
|
69
68
|
"next": "^15.0.0 || ^16.0.0",
|
|
@@ -72,10 +71,6 @@
|
|
|
72
71
|
"scripts": {
|
|
73
72
|
"build": "pnpm types:check && pnpm build-only",
|
|
74
73
|
"build-only": "vite build",
|
|
75
|
-
"format": "scalar-format",
|
|
76
|
-
"format:check": "scalar-format-check",
|
|
77
|
-
"lint:check": "scalar-lint-check",
|
|
78
|
-
"lint:fix": "scalar-lint-fix",
|
|
79
74
|
"test": "vitest",
|
|
80
75
|
"types:check": "tsc --noEmit --skipLibCheck"
|
|
81
76
|
}
|