@deneb-ui/core 2.0.24 → 2.0.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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DenebFontDefinition } from './types';
|
|
2
2
|
export declare const FONTS_MANIFEST_REL = ".deneb/fonts.json";
|
|
3
3
|
export declare const FONTS_CSS_REL = "src/fonts/deneb-fonts.css";
|
|
4
|
-
export declare const FONTS_CSS_IMPORT = "
|
|
4
|
+
export declare const FONTS_CSS_IMPORT = "../fonts/deneb-fonts.css";
|
|
5
5
|
export interface InstallProjectFontsOptions {
|
|
6
6
|
projectDir: string;
|
|
7
7
|
fontIds?: string[];
|
|
@@ -16,7 +16,7 @@ const registry_1 = require("./registry");
|
|
|
16
16
|
const resolve_1 = require("./resolve");
|
|
17
17
|
exports.FONTS_MANIFEST_REL = '.deneb/fonts.json';
|
|
18
18
|
exports.FONTS_CSS_REL = 'src/fonts/deneb-fonts.css';
|
|
19
|
-
exports.FONTS_CSS_IMPORT = '
|
|
19
|
+
exports.FONTS_CSS_IMPORT = '../fonts/deneb-fonts.css';
|
|
20
20
|
const SKIP_HOST_NAMES = new Set([
|
|
21
21
|
'@deneb-ui/ui',
|
|
22
22
|
'@deneb-ui/core',
|
|
@@ -109,21 +109,58 @@ function generateFontsCss(fonts) {
|
|
|
109
109
|
}
|
|
110
110
|
return `${lines.join('\n').trim()}\n`;
|
|
111
111
|
}
|
|
112
|
-
function
|
|
112
|
+
function findLayoutPath(projectDir) {
|
|
113
113
|
const layoutCandidates = [
|
|
114
114
|
node_path_1.default.join(projectDir, 'src', 'app', 'layout.tsx'),
|
|
115
115
|
node_path_1.default.join(projectDir, 'src', 'app', 'layout.jsx'),
|
|
116
116
|
node_path_1.default.join(projectDir, 'app', 'layout.tsx'),
|
|
117
117
|
node_path_1.default.join(projectDir, 'app', 'layout.jsx'),
|
|
118
118
|
];
|
|
119
|
-
|
|
119
|
+
return layoutCandidates.find((candidate) => node_fs_1.default.existsSync(candidate));
|
|
120
|
+
}
|
|
121
|
+
function ensureRootHydrationGuard(source) {
|
|
122
|
+
let next = source;
|
|
123
|
+
if (!/<html\b[^>]*suppressHydrationWarning/.test(next)) {
|
|
124
|
+
next = next.replace(/<html\b([^>]*)>/, '<html$1 suppressHydrationWarning>');
|
|
125
|
+
}
|
|
126
|
+
if (!/<body\b[^>]*suppressHydrationWarning/.test(next)) {
|
|
127
|
+
next = next.replace(/<body\b([^>]*)>/, '<body$1 suppressHydrationWarning>');
|
|
128
|
+
}
|
|
129
|
+
return next;
|
|
130
|
+
}
|
|
131
|
+
function fontsCssImportSpecifier(projectDir, layoutPath) {
|
|
132
|
+
const cssAbs = node_path_1.default.join(projectDir, exports.FONTS_CSS_REL);
|
|
133
|
+
let rel = node_path_1.default.relative(node_path_1.default.dirname(layoutPath), cssAbs).replace(/\\/g, '/');
|
|
134
|
+
if (!rel.startsWith('.'))
|
|
135
|
+
rel = `./${rel}`;
|
|
136
|
+
return rel;
|
|
137
|
+
}
|
|
138
|
+
function patchLayoutImport(projectDir) {
|
|
139
|
+
const layoutPath = findLayoutPath(projectDir);
|
|
120
140
|
if (!layoutPath)
|
|
121
141
|
return { patched: false, reason: 'layout.tsx not found' };
|
|
142
|
+
const specifier = fontsCssImportSpecifier(projectDir, layoutPath);
|
|
143
|
+
const importLine = `import '${specifier}';`;
|
|
122
144
|
let source = node_fs_1.default.readFileSync(layoutPath, 'utf8');
|
|
123
|
-
|
|
145
|
+
// Older installer wrote ./fonts/... next to layout.tsx; the CSS lives in src/fonts.
|
|
146
|
+
if (source.includes("import './fonts/deneb-fonts.css'")) {
|
|
147
|
+
source = ensureRootHydrationGuard(source.replace("import './fonts/deneb-fonts.css';", importLine));
|
|
148
|
+
node_fs_1.default.writeFileSync(layoutPath, source, 'utf8');
|
|
149
|
+
return { patched: true, reason: 'rewrote stale import', layoutPath };
|
|
150
|
+
}
|
|
151
|
+
if (source.includes('import "./fonts/deneb-fonts.css"')) {
|
|
152
|
+
source = ensureRootHydrationGuard(source.replace('import "./fonts/deneb-fonts.css";', importLine));
|
|
153
|
+
node_fs_1.default.writeFileSync(layoutPath, source, 'utf8');
|
|
154
|
+
return { patched: true, reason: 'rewrote stale import', layoutPath };
|
|
155
|
+
}
|
|
156
|
+
if (source.includes('deneb-fonts.css')) {
|
|
157
|
+
const guarded = ensureRootHydrationGuard(source);
|
|
158
|
+
if (guarded !== source) {
|
|
159
|
+
node_fs_1.default.writeFileSync(layoutPath, guarded, 'utf8');
|
|
160
|
+
return { patched: true, reason: 'hydration guard', layoutPath };
|
|
161
|
+
}
|
|
124
162
|
return { patched: false, reason: 'already imported', layoutPath };
|
|
125
163
|
}
|
|
126
|
-
const importLine = `import '${exports.FONTS_CSS_IMPORT}';`;
|
|
127
164
|
if (source.includes("import './globals.css'")) {
|
|
128
165
|
source = source.replace("import './globals.css';", `import './globals.css';\n${importLine}`);
|
|
129
166
|
}
|
|
@@ -133,6 +170,7 @@ function patchLayoutImport(projectDir) {
|
|
|
133
170
|
else {
|
|
134
171
|
source = `${importLine}\n${source}`;
|
|
135
172
|
}
|
|
173
|
+
source = ensureRootHydrationGuard(source);
|
|
136
174
|
node_fs_1.default.writeFileSync(layoutPath, source, 'utf8');
|
|
137
175
|
return { patched: true, reason: 'patched', layoutPath };
|
|
138
176
|
}
|
package/package.json
CHANGED