@scalar/core 0.4.5 → 0.5.0
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,18 +1,22 @@
|
|
|
1
1
|
import type { ApiReferenceConfigurationWithSource, HtmlRenderingConfiguration } from '@scalar/types/api-reference';
|
|
2
|
+
/** @deprecated Use `@scalar/client-side-rendering` instead. */
|
|
2
3
|
export type { HtmlRenderingConfiguration };
|
|
3
4
|
/**
|
|
4
5
|
* The HTML document to render the Scalar API reference.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
* defaulted to 'default'
|
|
7
|
+
* @deprecated Use `renderApiReference` from `@scalar/client-side-rendering` instead.
|
|
8
8
|
*/
|
|
9
9
|
export declare const getHtmlDocument: (givenConfiguration: Partial<HtmlRenderingConfiguration>, customTheme?: string) => string;
|
|
10
10
|
/**
|
|
11
11
|
* The script tags to load the @scalar/api-reference package from the CDN.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated Use `getScriptTags` from `@scalar/client-side-rendering` instead.
|
|
12
14
|
*/
|
|
13
15
|
export declare function getScriptTags(configuration: Partial<ApiReferenceConfigurationWithSource>, cdn?: string): string;
|
|
14
16
|
/**
|
|
15
17
|
* The configuration to pass to the @scalar/api-reference package.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated Use `getConfiguration` from `@scalar/client-side-rendering` instead.
|
|
16
20
|
*/
|
|
17
21
|
export declare const getConfiguration: (givenConfiguration: Partial<ApiReferenceConfigurationWithSource>) => Partial<ApiReferenceConfigurationWithSource>;
|
|
18
22
|
//# sourceMappingURL=html-rendering.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-rendering.d.ts","sourceRoot":"","sources":["../../../src/libs/html-rendering/html-rendering.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"html-rendering.d.ts","sourceRoot":"","sources":["../../../src/libs/html-rendering/html-rendering.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mCAAmC,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAA;AAElH,+DAA+D;AAC/D,YAAY,EAAE,0BAA0B,EAAE,CAAA;AAE1C;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,oBAAoB,OAAO,CAAC,0BAA0B,CAAC,EAAE,oBAAgB,KAAG,MAI3G,CAAA;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,aAAa,EAAE,OAAO,CAAC,mCAAmC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/G;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,oBAAoB,OAAO,CAAC,mCAAmC,CAAC,KAC/D,OAAO,CAAC,mCAAmC,CAI7C,CAAA"}
|
|
@@ -1,125 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
* Helper function to add consistent indentation to multiline strings
|
|
3
|
-
* @param str The string to indent
|
|
4
|
-
* @param spaces Number of spaces for each level
|
|
5
|
-
* @param initialIndent Whether to indent the first line
|
|
6
|
-
*/
|
|
7
|
-
const addIndent = (str, spaces = 2, initialIndent = false) => {
|
|
8
|
-
const indent = ' '.repeat(spaces);
|
|
9
|
-
const lines = str.split('\n');
|
|
10
|
-
return lines
|
|
11
|
-
.map((line, index) => {
|
|
12
|
-
if (index === 0 && !initialIndent) {
|
|
13
|
-
return line;
|
|
14
|
-
}
|
|
15
|
-
return `${indent}${line}`;
|
|
16
|
-
})
|
|
17
|
-
.join('\n');
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Generate the style tag with custom theme if needed
|
|
21
|
-
*/
|
|
22
|
-
const 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) {
|
|
33
|
-
return '';
|
|
34
|
-
}
|
|
35
|
-
return `
|
|
36
|
-
<style type="text/css">
|
|
37
|
-
${addIndent(styles.join('\n\n'), 6)}
|
|
38
|
-
</style>`;
|
|
39
|
-
};
|
|
1
|
+
import { getConfiguration as _getConfiguration, getScriptTags as _getScriptTags, renderApiReference, } from '@scalar/client-side-rendering';
|
|
40
2
|
/**
|
|
41
3
|
* The HTML document to render the Scalar API reference.
|
|
42
4
|
*
|
|
43
|
-
*
|
|
44
|
-
* defaulted to 'default'
|
|
5
|
+
* @deprecated Use `renderApiReference` from `@scalar/client-side-rendering` instead.
|
|
45
6
|
*/
|
|
46
7
|
export const getHtmlDocument = (givenConfiguration, customTheme = '') => {
|
|
47
|
-
const { cdn, pageTitle,
|
|
48
|
-
|
|
49
|
-
...rest,
|
|
50
|
-
...(theme ? { theme } : {}),
|
|
51
|
-
customCss,
|
|
52
|
-
});
|
|
53
|
-
const content = `<!doctype html>
|
|
54
|
-
<html>
|
|
55
|
-
<head>
|
|
56
|
-
<title>${pageTitle ?? 'Scalar API Reference'}</title>
|
|
57
|
-
<meta charset="utf-8" />
|
|
58
|
-
<meta
|
|
59
|
-
name="viewport"
|
|
60
|
-
content="width=device-width, initial-scale=1" />${getStyles(configuration, customTheme)}
|
|
61
|
-
</head>
|
|
62
|
-
<body>
|
|
63
|
-
<div id="app"></div>${getScriptTags(configuration, cdn)}
|
|
64
|
-
</body>
|
|
65
|
-
</html>`;
|
|
66
|
-
return content;
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Helper function to serialize arrays that may contain functions
|
|
70
|
-
*/
|
|
71
|
-
const serializeArrayWithFunctions = (arr) => {
|
|
72
|
-
return `[${arr.map((item) => (typeof item === 'function' ? item.toString() : JSON.stringify(item))).join(', ')}]`;
|
|
8
|
+
const { cdn, pageTitle, ...config } = givenConfiguration;
|
|
9
|
+
return renderApiReference({ config, pageTitle, cdn }, customTheme);
|
|
73
10
|
};
|
|
74
11
|
/**
|
|
75
12
|
* The script tags to load the @scalar/api-reference package from the CDN.
|
|
13
|
+
*
|
|
14
|
+
* @deprecated Use `getScriptTags` from `@scalar/client-side-rendering` instead.
|
|
76
15
|
*/
|
|
77
16
|
export function getScriptTags(configuration, cdn) {
|
|
78
|
-
|
|
79
|
-
const functionProps = [];
|
|
80
|
-
for (const [key, value] of Object.entries(configuration)) {
|
|
81
|
-
if (typeof value === 'function') {
|
|
82
|
-
functionProps.push(`"${key}": ${value.toString()}`);
|
|
83
|
-
delete restConfig[key];
|
|
84
|
-
}
|
|
85
|
-
else if (Array.isArray(value) && value.some((item) => typeof item === 'function')) {
|
|
86
|
-
// Handle arrays that contain functions (like plugins)
|
|
87
|
-
functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
|
|
88
|
-
delete restConfig[key];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// Stringify the rest of the configuration
|
|
92
|
-
const configString = JSON.stringify(restConfig, null, 2)
|
|
93
|
-
.split('\n')
|
|
94
|
-
.map((line, index) => (index === 0 ? line : ' ' + line))
|
|
95
|
-
.join('\n')
|
|
96
|
-
.replace(/\s*}$/, ''); // Remove the closing brace and any whitespace before it
|
|
97
|
-
const functionPropsString = functionProps.length ? `,\n ${functionProps.join(',\n ')}\n }` : '}';
|
|
98
|
-
return `
|
|
99
|
-
<!-- Load the Script -->
|
|
100
|
-
<script src="${cdn ?? 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'}"></script>
|
|
101
|
-
|
|
102
|
-
<!-- Initialize the Scalar API Reference -->
|
|
103
|
-
<script type="text/javascript">
|
|
104
|
-
Scalar.createApiReference('#app', ${configString}${functionPropsString})
|
|
105
|
-
</script>`;
|
|
17
|
+
return _getScriptTags(configuration, cdn);
|
|
106
18
|
}
|
|
107
19
|
/**
|
|
108
20
|
* The configuration to pass to the @scalar/api-reference package.
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Use `getConfiguration` from `@scalar/client-side-rendering` instead.
|
|
109
23
|
*/
|
|
110
24
|
export const getConfiguration = (givenConfiguration) => {
|
|
111
|
-
|
|
112
|
-
const configuration = {
|
|
113
|
-
...givenConfiguration,
|
|
114
|
-
};
|
|
115
|
-
// Execute content if it's a function
|
|
116
|
-
if (typeof configuration.content === 'function') {
|
|
117
|
-
configuration.content = configuration.content();
|
|
118
|
-
}
|
|
119
|
-
// Only remove content if url is provided
|
|
120
|
-
if (configuration.content && configuration.url) {
|
|
121
|
-
delete configuration.content;
|
|
122
|
-
}
|
|
123
|
-
// Just return regular JSON string, no HTML escaping needed
|
|
124
|
-
return configuration;
|
|
25
|
+
return _getConfiguration(givenConfiguration);
|
|
125
26
|
};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/core"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [],
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.5.0",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=22"
|
|
17
17
|
},
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"CHANGELOG.md"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@scalar/
|
|
31
|
+
"@scalar/client-side-rendering": "0.1.0",
|
|
32
|
+
"@scalar/types": "0.8.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"vite": "8.0.0"
|