@300codes/design-system 1.2.9 → 1.2.10
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/package.json
CHANGED
|
@@ -33,19 +33,29 @@ const isServer = typeof window === 'undefined';
|
|
|
33
33
|
const notFound =
|
|
34
34
|
'<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 256 256"><path d="M48,48V208H80a8,8,0,0,1,0,16H40a8,8,0,0,1-8-8V40a8,8,0,0,1,8-8H80a8,8,0,0,1,0,16ZM216,32H176a8,8,0,0,0,0,16h32V208H176a8,8,0,0,0,0,16h40a8,8,0,0,0,8-8V40A8,8,0,0,0,216,32Z"></path></svg>';
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const serverBase: string = (() => {
|
|
37
|
+
if (!isServer) return '';
|
|
38
|
+
if (!import.meta.env.PROD) return `${process.cwd()}/public`;
|
|
39
|
+
if (import.meta.env.DS_PUBLIC_PATH) {
|
|
40
|
+
const p: string = import.meta.env.DS_PUBLIC_PATH;
|
|
41
|
+
return p.startsWith('/') ? p : `${process.cwd()}/${p}`;
|
|
42
|
+
}
|
|
43
|
+
// In production SSR this module is bundled inside <dist>/server/ (or a subdir).
|
|
44
|
+
// Find that boundary and swap /server/... for /client.
|
|
45
|
+
const moduleDir = new URL('.', import.meta.url).pathname;
|
|
46
|
+
const sep = moduleDir.lastIndexOf('/server/');
|
|
47
|
+
return sep >= 0 ? `${moduleDir.slice(0, sep)}/client` : `${process.cwd()}/dist/client`;
|
|
48
|
+
})();
|
|
38
49
|
|
|
39
50
|
async function getSvgContent(name: string): Promise<string> {
|
|
40
51
|
const warnNotFound = () =>
|
|
41
52
|
console.warn(`[BaseIcon] Icon "${name}" not found at ${props.iconPath}/${name}.svg`);
|
|
42
53
|
|
|
43
54
|
if (isServer) {
|
|
44
|
-
const
|
|
55
|
+
const pathModule = await import('path');
|
|
45
56
|
const fs = await import('fs/promises');
|
|
46
|
-
|
|
47
57
|
try {
|
|
48
|
-
const filePath =
|
|
58
|
+
const filePath = pathModule.join(serverBase, props.iconPath, `${name}.svg`);
|
|
49
59
|
return await fs.readFile(filePath, 'utf8');
|
|
50
60
|
} catch {
|
|
51
61
|
warnNotFound();
|