@scalar/core 0.3.24 → 0.3.26

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,18 @@
1
1
  # @scalar/core
2
2
 
3
+ ## 0.3.26
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`72cd82f`](https://github.com/scalar/scalar/commit/72cd82fb8df63a9e5d0db1202978aebfefd0457a)]:
8
+ - @scalar/types@0.5.2
9
+
10
+ ## 0.3.25
11
+
12
+ ### Patch Changes
13
+
14
+ - [#7494](https://github.com/scalar/scalar/pull/7494) [`daa5df4`](https://github.com/scalar/scalar/commit/daa5df45386fa2305275fbf0a7bbcede6bcf9edc) Thanks [@marcalexiei](https://github.com/marcalexiei)! - fix: remove empty index file
15
+
3
16
  ## 0.3.24
4
17
 
5
18
  ### Patch Changes
@@ -1,59 +1,42 @@
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
1
  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');
2
+ const indent = " ".repeat(spaces);
3
+ const lines = str.split("\n");
4
+ return lines.map((line, index) => {
5
+ if (index === 0 && !initialIndent) {
6
+ return line;
7
+ }
8
+ return `${indent}${line}`;
9
+ }).join("\n");
18
10
  };
19
- /**
20
- * Generate the style tag with custom theme if needed
21
- */
22
11
  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 `
12
+ const styles = [];
13
+ if (configuration.customCss) {
14
+ styles.push("/* Custom CSS */");
15
+ styles.push(configuration.customCss);
16
+ }
17
+ if (!configuration.theme && customTheme) {
18
+ styles.push("/* Custom Theme */");
19
+ styles.push(customTheme);
20
+ }
21
+ if (styles.length === 0) {
22
+ return "";
23
+ }
24
+ return `
36
25
  <style type="text/css">
37
- ${addIndent(styles.join('\n\n'), 6)}
26
+ ${addIndent(styles.join("\n\n"), 6)}
38
27
  </style>`;
39
28
  };
40
- /**
41
- * The HTML document to render the Scalar API reference.
42
- *
43
- * We must check the passed in configuration and not the configuration for the theme as the configuration will have it
44
- * defaulted to 'default'
45
- */
46
- const getHtmlDocument = (givenConfiguration, customTheme = '') => {
47
- const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration;
48
- const configuration = getConfiguration({
49
- ...rest,
50
- ...(theme ? { theme } : {}),
51
- customCss,
52
- });
53
- const content = `<!doctype html>
29
+ const getHtmlDocument = (givenConfiguration, customTheme = "") => {
30
+ const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration;
31
+ const configuration = getConfiguration({
32
+ ...rest,
33
+ ...theme ? { theme } : {},
34
+ customCss
35
+ });
36
+ const content = `<!doctype html>
54
37
  <html>
55
38
  <head>
56
- <title>${pageTitle ?? 'Scalar API Reference'}</title>
39
+ <title>${pageTitle ?? "Scalar API Reference"}</title>
57
40
  <meta charset="utf-8" />
58
41
  <meta
59
42
  name="viewport"
@@ -63,65 +46,51 @@ const getHtmlDocument = (givenConfiguration, customTheme = '') => {
63
46
  <div id="app"></div>${getScriptTags(configuration, cdn)}
64
47
  </body>
65
48
  </html>`;
66
- return content;
49
+ return content;
67
50
  };
68
- /**
69
- * Helper function to serialize arrays that may contain functions
70
- */
71
51
  const serializeArrayWithFunctions = (arr) => {
72
- return `[${arr.map((item) => (typeof item === 'function' ? item.toString() : JSON.stringify(item))).join(', ')}]`;
52
+ return `[${arr.map((item) => typeof item === "function" ? item.toString() : JSON.stringify(item)).join(", ")}]`;
73
53
  };
74
- /**
75
- * The script tags to load the @scalar/api-reference package from the CDN.
76
- */
77
54
  function getScriptTags(configuration, cdn) {
78
- const restConfig = { ...configuration };
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
- }
55
+ const restConfig = { ...configuration };
56
+ const functionProps = [];
57
+ for (const [key, value] of Object.entries(configuration)) {
58
+ if (typeof value === "function") {
59
+ functionProps.push(`"${key}": ${value.toString()}`);
60
+ delete restConfig[key];
61
+ } else if (Array.isArray(value) && value.some((item) => typeof item === "function")) {
62
+ functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
63
+ delete restConfig[key];
90
64
  }
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 `
65
+ }
66
+ const configString = JSON.stringify(restConfig, null, 2).split("\n").map((line, index) => index === 0 ? line : " " + line).join("\n").replace(/\s*}$/, "");
67
+ const functionPropsString = functionProps.length ? `,
68
+ ${functionProps.join(",\n ")}
69
+ }` : "}";
70
+ return `
99
71
  <!-- Load the Script -->
100
- <script src="${cdn ?? 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'}"></script>
72
+ <script src="${cdn ?? "https://cdn.jsdelivr.net/npm/@scalar/api-reference"}"><\/script>
101
73
 
102
74
  <!-- Initialize the Scalar API Reference -->
103
75
  <script type="text/javascript">
104
76
  Scalar.createApiReference('#app', ${configString}${functionPropsString})
105
- </script>`;
77
+ <\/script>`;
106
78
  }
107
- /**
108
- * The configuration to pass to the @scalar/api-reference package.
109
- */
110
79
  const getConfiguration = (givenConfiguration) => {
111
- // Clone the given configuration
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;
80
+ const configuration = {
81
+ ...givenConfiguration
82
+ };
83
+ if (typeof configuration.content === "function") {
84
+ configuration.content = configuration.content();
85
+ }
86
+ if (configuration.content && configuration.url) {
87
+ delete configuration.content;
88
+ }
89
+ return configuration;
125
90
  };
126
-
127
- export { getConfiguration, getHtmlDocument, getScriptTags };
91
+ export {
92
+ getConfiguration,
93
+ getHtmlDocument,
94
+ getScriptTags
95
+ };
96
+ //# sourceMappingURL=html-rendering.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/libs/html-rendering/html-rendering.ts"],
4
+ "sourcesContent": ["import type { ApiReferenceConfigurationWithSource, HtmlRenderingConfiguration } from '@scalar/types/api-reference'\n\n// Re-export the type for convenience\nexport type { HtmlRenderingConfiguration }\n\n/**\n * Helper function to add consistent indentation to multiline strings\n * @param str The string to indent\n * @param spaces Number of spaces for each level\n * @param initialIndent Whether to indent the first line\n */\nconst addIndent = (str: string, spaces: number = 2, initialIndent: boolean = false): string => {\n const indent = ' '.repeat(spaces)\n const lines = str.split('\\n')\n return lines\n .map((line, index) => {\n if (index === 0 && !initialIndent) {\n return line\n }\n return `${indent}${line}`\n })\n .join('\\n')\n}\n\n/**\n * Generate the style tag with custom theme if needed\n */\nconst getStyles = (configuration: Partial<HtmlRenderingConfiguration>, customTheme: string): string => {\n const styles: string[] = []\n\n if (configuration.customCss) {\n styles.push('/* Custom CSS */')\n styles.push(configuration.customCss)\n }\n\n if (!configuration.theme && customTheme) {\n styles.push('/* Custom Theme */')\n styles.push(customTheme)\n }\n\n if (styles.length === 0) {\n return ''\n }\n\n return `\n <style type=\"text/css\">\n ${addIndent(styles.join('\\n\\n'), 6)}\n </style>`\n}\n\n/**\n * The HTML document to render the Scalar API reference.\n *\n * We must check the passed in configuration and not the configuration for the theme as the configuration will have it\n * defaulted to 'default'\n */\nexport const getHtmlDocument = (givenConfiguration: Partial<HtmlRenderingConfiguration>, customTheme = '') => {\n const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration\n\n const configuration = getConfiguration({\n ...rest,\n ...(theme ? { theme } : {}),\n customCss,\n })\n\n const content = `<!doctype html>\n<html>\n <head>\n <title>${pageTitle ?? 'Scalar API Reference'}</title>\n <meta charset=\"utf-8\" />\n <meta\n name=\"viewport\"\n content=\"width=device-width, initial-scale=1\" />${getStyles(configuration, customTheme)}\n </head>\n <body>\n <div id=\"app\"></div>${getScriptTags(configuration, cdn)}\n </body>\n</html>`\n\n return content\n}\n\n/**\n * Helper function to serialize arrays that may contain functions\n */\nconst serializeArrayWithFunctions = (arr: unknown[]): string => {\n return `[${arr.map((item) => (typeof item === 'function' ? item.toString() : JSON.stringify(item))).join(', ')}]`\n}\n\n/**\n * The script tags to load the @scalar/api-reference package from the CDN.\n */\nexport function getScriptTags(configuration: Partial<ApiReferenceConfigurationWithSource>, cdn?: string) {\n const restConfig = { ...configuration }\n\n const functionProps: string[] = []\n\n for (const [key, value] of Object.entries(configuration) as [keyof typeof configuration, unknown][]) {\n if (typeof value === 'function') {\n functionProps.push(`\"${key}\": ${value.toString()}`)\n delete restConfig[key]\n } else if (Array.isArray(value) && value.some((item) => typeof item === 'function')) {\n // Handle arrays that contain functions (like plugins)\n functionProps.push(`\"${key}\": ${serializeArrayWithFunctions(value)}`)\n delete restConfig[key]\n }\n }\n\n // Stringify the rest of the configuration\n const configString = JSON.stringify(restConfig, null, 2)\n .split('\\n')\n .map((line, index) => (index === 0 ? line : ' ' + line))\n .join('\\n')\n .replace(/\\s*}$/, '') // Remove the closing brace and any whitespace before it\n\n const functionPropsString = functionProps.length ? `,\\n ${functionProps.join(',\\n ')}\\n }` : '}'\n\n return `\n <!-- Load the Script -->\n <script src=\"${cdn ?? 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'}\"></script>\n\n <!-- Initialize the Scalar API Reference -->\n <script type=\"text/javascript\">\n Scalar.createApiReference('#app', ${configString}${functionPropsString})\n </script>`\n}\n\n/**\n * The configuration to pass to the @scalar/api-reference package.\n */\nexport const getConfiguration = (\n givenConfiguration: Partial<ApiReferenceConfigurationWithSource>,\n): Partial<ApiReferenceConfigurationWithSource> => {\n // Clone the given configuration\n const configuration = {\n ...givenConfiguration,\n }\n\n // Execute content if it's a function\n if (typeof configuration.content === 'function') {\n configuration.content = configuration.content()\n }\n\n // Only remove content if url is provided\n if (configuration.content && configuration.url) {\n delete configuration.content\n }\n\n // Just return regular JSON string, no HTML escaping needed\n return configuration\n}\n"],
5
+ "mappings": "AAWA,MAAM,YAAY,CAAC,KAAa,SAAiB,GAAG,gBAAyB,UAAkB;AAC7F,QAAM,SAAS,IAAI,OAAO,MAAM;AAChC,QAAM,QAAQ,IAAI,MAAM,IAAI;AAC5B,SAAO,MACJ,IAAI,CAAC,MAAM,UAAU;AACpB,QAAI,UAAU,KAAK,CAAC,eAAe;AACjC,aAAO;AAAA,IACT;AACA,WAAO,GAAG,MAAM,GAAG,IAAI;AAAA,EACzB,CAAC,EACA,KAAK,IAAI;AACd;AAKA,MAAM,YAAY,CAAC,eAAoD,gBAAgC;AACrG,QAAM,SAAmB,CAAC;AAE1B,MAAI,cAAc,WAAW;AAC3B,WAAO,KAAK,kBAAkB;AAC9B,WAAO,KAAK,cAAc,SAAS;AAAA,EACrC;AAEA,MAAI,CAAC,cAAc,SAAS,aAAa;AACvC,WAAO,KAAK,oBAAoB;AAChC,WAAO,KAAK,WAAW;AAAA,EACzB;AAEA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U,YAAY,MAAM,CAAC,EACpD,MAAM,IAAI,EACV,IAAI,CAAC,MAAM,UAAW,UAAU,IAAI,OAAO,WAAW,IAAK,EAC3D,KAAK,IAAI,EACT,QAAQ,SAAS,EAAE;AAEtB,QAAM,sBAAsB,cAAc,SAAS;AAAA,UAAc,cAAc,KAAK,aAAa,CAAC;AAAA,WAAc;AAEhH,SAAO;AAAA;AAAA,mBAEU,OAAO,oDAAoD;AAAA;AAAA;AAAA;AAAA,0CAIpC,YAAY,GAAG,mBAAmB;AAAA;AAE5E;AAKO,MAAM,mBAAmB,CAC9B,uBACiD;AAEjD,QAAM,gBAAgB;AAAA,IACpB,GAAG;AAAA,EACL;AAGA,MAAI,OAAO,cAAc,YAAY,YAAY;AAC/C,kBAAc,UAAU,cAAc,QAAQ;AAAA,EAChD;AAGA,MAAI,cAAc,WAAW,cAAc,KAAK;AAC9C,WAAO,cAAc;AAAA,EACvB;AAGA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,2 +1,2 @@
1
- export { type HtmlRenderingConfiguration, getHtmlDocument, getScriptTags, getConfiguration, } from './html-rendering.js';
1
+ export { type HtmlRenderingConfiguration, getConfiguration, getHtmlDocument, getScriptTags, } from './html-rendering.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/libs/html-rendering/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAC/B,eAAe,EACf,aAAa,EACb,gBAAgB,GACjB,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/libs/html-rendering/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAC/B,gBAAgB,EAChB,eAAe,EACf,aAAa,GACd,MAAM,kBAAkB,CAAA"}
@@ -1 +1,11 @@
1
- export { getConfiguration, getHtmlDocument, getScriptTags } from './html-rendering.js';
1
+ import {
2
+ getConfiguration,
3
+ getHtmlDocument,
4
+ getScriptTags
5
+ } from "./html-rendering.js";
6
+ export {
7
+ getConfiguration,
8
+ getHtmlDocument,
9
+ getScriptTags
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/libs/html-rendering/index.ts"],
4
+ "sourcesContent": ["export {\n type HtmlRenderingConfiguration,\n getConfiguration,\n getHtmlDocument,\n getScriptTags,\n} from './html-rendering'\n"],
5
+ "mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -11,19 +11,12 @@
11
11
  "directory": "packages/core"
12
12
  },
13
13
  "keywords": [],
14
- "version": "0.3.24",
14
+ "version": "0.3.26",
15
15
  "engines": {
16
16
  "node": ">=20"
17
17
  },
18
18
  "type": "module",
19
- "main": "dist/index.js",
20
- "module": "dist/index.js",
21
19
  "exports": {
22
- ".": {
23
- "import": "./dist/index.js",
24
- "types": "./dist/index.d.ts",
25
- "default": "./dist/index.js"
26
- },
27
20
  "./libs/html-rendering": {
28
21
  "import": "./dist/libs/html-rendering/index.js",
29
22
  "types": "./dist/libs/html-rendering/index.d.ts",
@@ -35,14 +28,14 @@
35
28
  "CHANGELOG.md"
36
29
  ],
37
30
  "dependencies": {
38
- "@scalar/types": "0.5.1"
31
+ "@scalar/types": "0.5.2"
39
32
  },
40
33
  "devDependencies": {
41
34
  "vite": "7.1.11",
42
35
  "@scalar/build-tooling": "0.3.1"
43
36
  },
44
37
  "scripts": {
45
- "build": "scalar-build-rollup",
38
+ "build": "scalar-build-esbuild",
46
39
  "lint:check": "scalar-lint-check",
47
40
  "lint:fix": "scalar-lint-fix",
48
41
  "test": "vitest",
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
-