@scalar/nextjs-api-reference 0.10.8 → 0.10.9

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,11 @@
1
1
  # @scalar/nextjs-api-reference
2
2
 
3
+ ## 0.10.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#8873](https://github.com/scalar/scalar/pull/8873): refactor: migrate integrations to client-side rendering package
8
+
3
9
  ## 0.10.8
4
10
 
5
11
  ## 0.10.7
package/dist/index.cjs CHANGED
@@ -1,133 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region ../../packages/client-side-rendering/dist/html-rendering.js
3
- var DEFAULT_CDN = "https://cdn.jsdelivr.net/npm/@scalar/api-reference";
4
- /**
5
- * Escape HTML special characters in user-provided strings.
6
- */
7
- var escapeHtml = (str) => {
8
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
9
- };
10
- /**
11
- * Helper function to add consistent indentation to multiline strings
12
- * @param str The string to indent
13
- * @param spaces Number of spaces for each level
14
- * @param initialIndent Whether to indent the first line
15
- */
16
- var addIndent = (str, spaces = 2, initialIndent = false) => {
17
- const indent = " ".repeat(spaces);
18
- return str.split("\n").map((line, index) => {
19
- if (index === 0 && !initialIndent) return line;
20
- return `${indent}${line}`;
21
- }).join("\n");
22
- };
23
- /**
24
- * Generate the style tag with custom theme if needed
25
- */
26
- var getStyles = (configuration, customTheme) => {
27
- const styles = [];
28
- if (configuration.customCss) {
29
- styles.push("/* Custom CSS */");
30
- styles.push(configuration.customCss);
31
- }
32
- if (!configuration.theme && customTheme) {
33
- styles.push("/* Custom Theme */");
34
- styles.push(customTheme);
35
- }
36
- if (styles.length === 0) return "";
37
- return `
38
- <style type="text/css">
39
- ${addIndent(styles.join("\n\n"), 6)}
40
- </style>`;
41
- };
42
- /**
43
- * Render the Scalar API Reference as a complete HTML document using the CDN.
44
- *
45
- * Generates static HTML that loads the @scalar/api-reference standalone bundle
46
- * from a CDN and renders client-side. No server-side dependencies required.
47
- *
48
- * For server-side rendering with hydration, use the server module instead.
49
- */
50
- function renderApiReference(options, customTheme = "") {
51
- const { config: givenConfig, pageTitle, cdn } = options;
52
- const title = escapeHtml(pageTitle ?? "Scalar API Reference");
53
- const { customCss, theme, ...rest } = (Array.isArray(givenConfig) ? givenConfig[0] : givenConfig) ?? {};
54
- const configuration = getConfiguration({
55
- ...rest,
56
- ...theme ? { theme } : {},
57
- ...customCss !== void 0 ? { customCss } : {}
58
- });
59
- return `<!doctype html>
60
- <html>
61
- <head>
62
- <title>${title}</title>
63
- <meta charset="utf-8" />
64
- <meta
65
- name="viewport"
66
- content="width=device-width, initial-scale=1" />${getStyles(configuration, customTheme)}
67
- </head>
68
- <body>
69
- <div id="app"></div>${getScriptTags(configuration, cdn)}
70
- </body>
71
- </html>`;
72
- }
73
- /**
74
- * Helper function to serialize arrays that may contain functions
75
- */
76
- var serializeArrayWithFunctions = (arr) => {
77
- return `[${arr.map((item) => typeof item === "function" ? item.toString() : JSON.stringify(item)).join(", ")}]`;
78
- };
79
- /**
80
- * The script tags to load the @scalar/api-reference package from the CDN.
81
- */
82
- function getScriptTags(configuration, cdn) {
83
- const restConfig = { ...configuration };
84
- const functionProps = [];
85
- for (const [key, value] of Object.entries(configuration)) if (typeof value === "function") {
86
- functionProps.push(`"${key}": ${value.toString()}`);
87
- delete restConfig[key];
88
- } else if (Array.isArray(value) && value.some((item) => typeof item === "function")) {
89
- functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
90
- delete restConfig[key];
91
- }
92
- const jsonString = JSON.stringify(restConfig, null, 2);
93
- const indentedJsonString = jsonString.split("\n").map((line, index) => index === 0 ? line : ` ${line}`).join("\n");
94
- let configString = indentedJsonString;
95
- if (functionProps.length > 0) if (jsonString === "{}") configString = `{\n ${functionProps.join(",\n ")}\n }`;
96
- else configString = `${indentedJsonString.split("\n").slice(0, -1).join("\n")},\n ${functionProps.join(",\n ")}\n }`;
97
- return `
98
- <!-- Load the Script -->
99
- <script src="${cdn ?? DEFAULT_CDN}"><\/script>
100
-
101
- <!-- Initialize the Scalar API Reference -->
102
- <script type="text/javascript">
103
- Scalar.createApiReference('#app', ${configString})
104
- <\/script>`;
105
- }
106
- /**
107
- * The configuration to pass to the @scalar/api-reference package.
108
- */
109
- var getConfiguration = (givenConfiguration) => {
110
- const configuration = { ...givenConfiguration };
111
- if (typeof configuration.content === "function") configuration.content = configuration.content();
112
- if (configuration.content && configuration.url) delete configuration.content;
113
- return configuration;
114
- };
115
- //#endregion
116
- //#region ../../packages/core/dist/libs/html-rendering/html-rendering.js
117
- /**
118
- * The HTML document to render the Scalar API reference.
119
- *
120
- * @deprecated Use `renderApiReference` from `@scalar/client-side-rendering` instead.
121
- */
122
- var getHtmlDocument = (givenConfiguration, customTheme = "") => {
123
- const { cdn, pageTitle, ...config } = givenConfiguration;
124
- return renderApiReference({
125
- config,
126
- pageTitle,
127
- cdn
128
- }, customTheme);
129
- };
130
- //#endregion
2
+ let _scalar_client_side_rendering = require("@scalar/client-side-rendering");
131
3
  //#region src/custom-theme.ts
132
4
  /**
133
5
  * The custom theme for Next.js
@@ -274,7 +146,12 @@ var ApiReference = (givenConfiguration) => {
274
146
  ...givenConfiguration
275
147
  };
276
148
  return () => {
277
- const referenceDocument = getHtmlDocument(configuration, customTheme);
149
+ const { cdn, pageTitle, ...config } = configuration;
150
+ const referenceDocument = (0, _scalar_client_side_rendering.renderApiReference)({
151
+ config,
152
+ pageTitle,
153
+ cdn
154
+ }, customTheme);
278
155
  return new Response(referenceDocument, {
279
156
  status: 200,
280
157
  headers: { "Content-Type": "text/html" }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { HtmlRenderingConfiguration } from '@scalar/core/libs/html-rendering';
1
+ import { HtmlRenderingConfiguration } from '@scalar/client-side-rendering';
2
2
 
3
3
  /**
4
4
  * Next.js adapter for an Api Reference
package/dist/index.js CHANGED
@@ -1,132 +1,4 @@
1
- //#region ../../packages/client-side-rendering/dist/html-rendering.js
2
- var DEFAULT_CDN = "https://cdn.jsdelivr.net/npm/@scalar/api-reference";
3
- /**
4
- * Escape HTML special characters in user-provided strings.
5
- */
6
- var escapeHtml = (str) => {
7
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
8
- };
9
- /**
10
- * Helper function to add consistent indentation to multiline strings
11
- * @param str The string to indent
12
- * @param spaces Number of spaces for each level
13
- * @param initialIndent Whether to indent the first line
14
- */
15
- var addIndent = (str, spaces = 2, initialIndent = false) => {
16
- const indent = " ".repeat(spaces);
17
- return str.split("\n").map((line, index) => {
18
- if (index === 0 && !initialIndent) return line;
19
- return `${indent}${line}`;
20
- }).join("\n");
21
- };
22
- /**
23
- * Generate the style tag with custom theme if needed
24
- */
25
- var getStyles = (configuration, customTheme) => {
26
- const styles = [];
27
- if (configuration.customCss) {
28
- styles.push("/* Custom CSS */");
29
- styles.push(configuration.customCss);
30
- }
31
- if (!configuration.theme && customTheme) {
32
- styles.push("/* Custom Theme */");
33
- styles.push(customTheme);
34
- }
35
- if (styles.length === 0) return "";
36
- return `
37
- <style type="text/css">
38
- ${addIndent(styles.join("\n\n"), 6)}
39
- </style>`;
40
- };
41
- /**
42
- * Render the Scalar API Reference as a complete HTML document using the CDN.
43
- *
44
- * Generates static HTML that loads the @scalar/api-reference standalone bundle
45
- * from a CDN and renders client-side. No server-side dependencies required.
46
- *
47
- * For server-side rendering with hydration, use the server module instead.
48
- */
49
- function renderApiReference(options, customTheme = "") {
50
- const { config: givenConfig, pageTitle, cdn } = options;
51
- const title = escapeHtml(pageTitle ?? "Scalar API Reference");
52
- const { customCss, theme, ...rest } = (Array.isArray(givenConfig) ? givenConfig[0] : givenConfig) ?? {};
53
- const configuration = getConfiguration({
54
- ...rest,
55
- ...theme ? { theme } : {},
56
- ...customCss !== void 0 ? { customCss } : {}
57
- });
58
- return `<!doctype html>
59
- <html>
60
- <head>
61
- <title>${title}</title>
62
- <meta charset="utf-8" />
63
- <meta
64
- name="viewport"
65
- content="width=device-width, initial-scale=1" />${getStyles(configuration, customTheme)}
66
- </head>
67
- <body>
68
- <div id="app"></div>${getScriptTags(configuration, cdn)}
69
- </body>
70
- </html>`;
71
- }
72
- /**
73
- * Helper function to serialize arrays that may contain functions
74
- */
75
- var serializeArrayWithFunctions = (arr) => {
76
- return `[${arr.map((item) => typeof item === "function" ? item.toString() : JSON.stringify(item)).join(", ")}]`;
77
- };
78
- /**
79
- * The script tags to load the @scalar/api-reference package from the CDN.
80
- */
81
- function getScriptTags(configuration, cdn) {
82
- const restConfig = { ...configuration };
83
- const functionProps = [];
84
- for (const [key, value] of Object.entries(configuration)) if (typeof value === "function") {
85
- functionProps.push(`"${key}": ${value.toString()}`);
86
- delete restConfig[key];
87
- } else if (Array.isArray(value) && value.some((item) => typeof item === "function")) {
88
- functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
89
- delete restConfig[key];
90
- }
91
- const jsonString = JSON.stringify(restConfig, null, 2);
92
- const indentedJsonString = jsonString.split("\n").map((line, index) => index === 0 ? line : ` ${line}`).join("\n");
93
- let configString = indentedJsonString;
94
- if (functionProps.length > 0) if (jsonString === "{}") configString = `{\n ${functionProps.join(",\n ")}\n }`;
95
- else configString = `${indentedJsonString.split("\n").slice(0, -1).join("\n")},\n ${functionProps.join(",\n ")}\n }`;
96
- return `
97
- <!-- Load the Script -->
98
- <script src="${cdn ?? DEFAULT_CDN}"><\/script>
99
-
100
- <!-- Initialize the Scalar API Reference -->
101
- <script type="text/javascript">
102
- Scalar.createApiReference('#app', ${configString})
103
- <\/script>`;
104
- }
105
- /**
106
- * The configuration to pass to the @scalar/api-reference package.
107
- */
108
- var getConfiguration = (givenConfiguration) => {
109
- const configuration = { ...givenConfiguration };
110
- if (typeof configuration.content === "function") configuration.content = configuration.content();
111
- if (configuration.content && configuration.url) delete configuration.content;
112
- return configuration;
113
- };
114
- //#endregion
115
- //#region ../../packages/core/dist/libs/html-rendering/html-rendering.js
116
- /**
117
- * The HTML document to render the Scalar API reference.
118
- *
119
- * @deprecated Use `renderApiReference` from `@scalar/client-side-rendering` instead.
120
- */
121
- var getHtmlDocument = (givenConfiguration, customTheme = "") => {
122
- const { cdn, pageTitle, ...config } = givenConfiguration;
123
- return renderApiReference({
124
- config,
125
- pageTitle,
126
- cdn
127
- }, customTheme);
128
- };
129
- //#endregion
1
+ import { renderApiReference } from "@scalar/client-side-rendering";
130
2
  //#region src/custom-theme.ts
131
3
  /**
132
4
  * The custom theme for Next.js
@@ -273,7 +145,12 @@ var ApiReference = (givenConfiguration) => {
273
145
  ...givenConfiguration
274
146
  };
275
147
  return () => {
276
- const referenceDocument = getHtmlDocument(configuration, customTheme);
148
+ const { cdn, pageTitle, ...config } = configuration;
149
+ const referenceDocument = renderApiReference({
150
+ config,
151
+ pageTitle,
152
+ cdn
153
+ }, customTheme);
277
154
  return new Response(referenceDocument, {
278
155
  status: 200,
279
156
  headers: { "Content-Type": "text/html" }
@@ -1,136 +1,7 @@
1
1
  (function(global, factory) {
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) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@scalar/client-side-rendering")) : typeof define === "function" && define.amd ? define(["exports", "@scalar/client-side-rendering"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@scalar/nextjs-api-reference"] = {}, global._scalar_client_side_rendering));
3
+ })(this, function(exports, _scalar_client_side_rendering) {
4
4
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
5
- //#region ../../packages/client-side-rendering/dist/html-rendering.js
6
- var DEFAULT_CDN = "https://cdn.jsdelivr.net/npm/@scalar/api-reference";
7
- /**
8
- * Escape HTML special characters in user-provided strings.
9
- */
10
- var escapeHtml = (str) => {
11
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
12
- };
13
- /**
14
- * Helper function to add consistent indentation to multiline strings
15
- * @param str The string to indent
16
- * @param spaces Number of spaces for each level
17
- * @param initialIndent Whether to indent the first line
18
- */
19
- var addIndent = (str, spaces = 2, initialIndent = false) => {
20
- const indent = " ".repeat(spaces);
21
- return str.split("\n").map((line, index) => {
22
- if (index === 0 && !initialIndent) return line;
23
- return `${indent}${line}`;
24
- }).join("\n");
25
- };
26
- /**
27
- * Generate the style tag with custom theme if needed
28
- */
29
- var getStyles = (configuration, customTheme) => {
30
- const styles = [];
31
- if (configuration.customCss) {
32
- styles.push("/* Custom CSS */");
33
- styles.push(configuration.customCss);
34
- }
35
- if (!configuration.theme && customTheme) {
36
- styles.push("/* Custom Theme */");
37
- styles.push(customTheme);
38
- }
39
- if (styles.length === 0) return "";
40
- return `
41
- <style type="text/css">
42
- ${addIndent(styles.join("\n\n"), 6)}
43
- </style>`;
44
- };
45
- /**
46
- * Render the Scalar API Reference as a complete HTML document using the CDN.
47
- *
48
- * Generates static HTML that loads the @scalar/api-reference standalone bundle
49
- * from a CDN and renders client-side. No server-side dependencies required.
50
- *
51
- * For server-side rendering with hydration, use the server module instead.
52
- */
53
- function renderApiReference(options, customTheme = "") {
54
- const { config: givenConfig, pageTitle, cdn } = options;
55
- const title = escapeHtml(pageTitle ?? "Scalar API Reference");
56
- const { customCss, theme, ...rest } = (Array.isArray(givenConfig) ? givenConfig[0] : givenConfig) ?? {};
57
- const configuration = getConfiguration({
58
- ...rest,
59
- ...theme ? { theme } : {},
60
- ...customCss !== void 0 ? { customCss } : {}
61
- });
62
- return `<!doctype html>
63
- <html>
64
- <head>
65
- <title>${title}</title>
66
- <meta charset="utf-8" />
67
- <meta
68
- name="viewport"
69
- content="width=device-width, initial-scale=1" />${getStyles(configuration, customTheme)}
70
- </head>
71
- <body>
72
- <div id="app"></div>${getScriptTags(configuration, cdn)}
73
- </body>
74
- </html>`;
75
- }
76
- /**
77
- * Helper function to serialize arrays that may contain functions
78
- */
79
- var serializeArrayWithFunctions = (arr) => {
80
- return `[${arr.map((item) => typeof item === "function" ? item.toString() : JSON.stringify(item)).join(", ")}]`;
81
- };
82
- /**
83
- * The script tags to load the @scalar/api-reference package from the CDN.
84
- */
85
- function getScriptTags(configuration, cdn) {
86
- const restConfig = { ...configuration };
87
- const functionProps = [];
88
- for (const [key, value] of Object.entries(configuration)) if (typeof value === "function") {
89
- functionProps.push(`"${key}": ${value.toString()}`);
90
- delete restConfig[key];
91
- } else if (Array.isArray(value) && value.some((item) => typeof item === "function")) {
92
- functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
93
- delete restConfig[key];
94
- }
95
- const jsonString = JSON.stringify(restConfig, null, 2);
96
- const indentedJsonString = jsonString.split("\n").map((line, index) => index === 0 ? line : ` ${line}`).join("\n");
97
- let configString = indentedJsonString;
98
- if (functionProps.length > 0) if (jsonString === "{}") configString = `{\n ${functionProps.join(",\n ")}\n }`;
99
- else configString = `${indentedJsonString.split("\n").slice(0, -1).join("\n")},\n ${functionProps.join(",\n ")}\n }`;
100
- return `
101
- <!-- Load the Script -->
102
- <script src="${cdn ?? DEFAULT_CDN}"><\/script>
103
-
104
- <!-- Initialize the Scalar API Reference -->
105
- <script type="text/javascript">
106
- Scalar.createApiReference('#app', ${configString})
107
- <\/script>`;
108
- }
109
- /**
110
- * The configuration to pass to the @scalar/api-reference package.
111
- */
112
- var getConfiguration = (givenConfiguration) => {
113
- const configuration = { ...givenConfiguration };
114
- if (typeof configuration.content === "function") configuration.content = configuration.content();
115
- if (configuration.content && configuration.url) delete configuration.content;
116
- return configuration;
117
- };
118
- //#endregion
119
- //#region ../../packages/core/dist/libs/html-rendering/html-rendering.js
120
- /**
121
- * The HTML document to render the Scalar API reference.
122
- *
123
- * @deprecated Use `renderApiReference` from `@scalar/client-side-rendering` instead.
124
- */
125
- var getHtmlDocument = (givenConfiguration, customTheme = "") => {
126
- const { cdn, pageTitle, ...config } = givenConfiguration;
127
- return renderApiReference({
128
- config,
129
- pageTitle,
130
- cdn
131
- }, customTheme);
132
- };
133
- //#endregion
134
5
  //#region src/custom-theme.ts
135
6
  /**
136
7
  * The custom theme for Next.js
@@ -277,7 +148,12 @@
277
148
  ...givenConfiguration
278
149
  };
279
150
  return () => {
280
- const referenceDocument = getHtmlDocument(configuration, customTheme);
151
+ const { cdn, pageTitle, ...config } = configuration;
152
+ const referenceDocument = (0, _scalar_client_side_rendering.renderApiReference)({
153
+ config,
154
+ pageTitle,
155
+ cdn
156
+ }, customTheme);
281
157
  return new Response(referenceDocument, {
282
158
  status: 200,
283
159
  headers: { "Content-Type": "text/html" }
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "openapi",
19
19
  "swagger"
20
20
  ],
21
- "version": "0.10.8",
21
+ "version": "0.10.9",
22
22
  "engines": {
23
23
  "node": ">=22"
24
24
  },
@@ -50,7 +50,7 @@
50
50
  "documentation": "https://scalar.com/products/api-references/integrations/nextjs"
51
51
  },
52
52
  "dependencies": {
53
- "@scalar/core": "0.5.1"
53
+ "@scalar/client-side-rendering": "0.1.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/node": "^24.1.0",