@symbo.ls/brender 3.6.4 → 3.6.7
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/README.md +76 -6
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/prefetch.js +199 -0
- package/dist/cjs/render.js +335 -36
- package/dist/esm/index.js +9 -2
- package/dist/esm/prefetch.js +170 -0
- package/dist/esm/render.js +335 -36
- package/index.js +10 -3
- package/package.json +3 -3
- package/prefetch.js +256 -0
- package/render.js +374 -29
package/dist/cjs/render.js
CHANGED
|
@@ -35,12 +35,227 @@ __export(render_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(render_exports);
|
|
37
37
|
var import_path = require("path");
|
|
38
|
+
var import_fs = require("fs");
|
|
39
|
+
var import_os = require("os");
|
|
40
|
+
var import_crypto = require("crypto");
|
|
38
41
|
var import_env = require("./env.js");
|
|
39
42
|
var import_keys = require("./keys.js");
|
|
40
43
|
var import_metadata = require("./metadata.js");
|
|
41
44
|
var import_hydrate = require("./hydrate.js");
|
|
45
|
+
var import_prefetch = require("./prefetch.js");
|
|
42
46
|
var import_linkedom = require("linkedom");
|
|
43
47
|
const import_meta = {};
|
|
48
|
+
const structuredCloneDeep = (obj, seen = /* @__PURE__ */ new WeakMap()) => {
|
|
49
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
50
|
+
if (seen.has(obj)) return seen.get(obj);
|
|
51
|
+
if (Array.isArray(obj)) {
|
|
52
|
+
const arr = [];
|
|
53
|
+
seen.set(obj, arr);
|
|
54
|
+
for (const v of obj) arr.push(typeof v === "object" && v !== null ? structuredCloneDeep(v, seen) : v);
|
|
55
|
+
return arr;
|
|
56
|
+
}
|
|
57
|
+
const clone = {};
|
|
58
|
+
seen.set(obj, clone);
|
|
59
|
+
for (const k of Object.keys(obj)) {
|
|
60
|
+
const v = obj[k];
|
|
61
|
+
clone[k] = typeof v === "object" && v !== null ? structuredCloneDeep(v, seen) : v;
|
|
62
|
+
}
|
|
63
|
+
return clone;
|
|
64
|
+
};
|
|
65
|
+
const safeJsonReplacer = () => {
|
|
66
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
67
|
+
return (key, value) => {
|
|
68
|
+
if (typeof value === "function") return void 0;
|
|
69
|
+
if (typeof value === "object" && value !== null) {
|
|
70
|
+
if (seen.has(value)) return void 0;
|
|
71
|
+
seen.add(value);
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
let _cachedCreateDomql = null;
|
|
77
|
+
const bundleCreateDomql = async () => {
|
|
78
|
+
if (_cachedCreateDomql) return _cachedCreateDomql;
|
|
79
|
+
const brenderDir = new URL(".", import_meta.url).pathname;
|
|
80
|
+
const monorepoRoot = (0, import_path.resolve)(brenderDir, "../..");
|
|
81
|
+
const entry = (0, import_path.resolve)(monorepoRoot, "packages", "smbls", "src", "createDomql.js");
|
|
82
|
+
const esbuild = await import("esbuild");
|
|
83
|
+
const outFile = (0, import_path.join)((0, import_os.tmpdir)(), `br_createDomql_${(0, import_crypto.randomBytes)(6).toString("hex")}.mjs`);
|
|
84
|
+
const workspacePlugin = {
|
|
85
|
+
name: "workspace-resolve",
|
|
86
|
+
setup(build) {
|
|
87
|
+
build.onResolve({ filter: /^smbls/ }, (args) => {
|
|
88
|
+
const subpath = args.path.replace(/^smbls\/?/, "");
|
|
89
|
+
if (!subpath) {
|
|
90
|
+
const src = (0, import_path.resolve)(monorepoRoot, "packages", "smbls", "src", "index.js");
|
|
91
|
+
if ((0, import_fs.existsSync)(src)) return { path: src };
|
|
92
|
+
}
|
|
93
|
+
const full = (0, import_path.resolve)(monorepoRoot, "packages", "smbls", subpath);
|
|
94
|
+
if ((0, import_fs.existsSync)(full)) return { path: full };
|
|
95
|
+
if ((0, import_fs.existsSync)(full + ".js")) return { path: full + ".js" };
|
|
96
|
+
const idx = (0, import_path.resolve)(full, "index.js");
|
|
97
|
+
if ((0, import_fs.existsSync)(idx)) return { path: idx };
|
|
98
|
+
});
|
|
99
|
+
build.onResolve({ filter: /^domql$/ }, (args) => {
|
|
100
|
+
const src = (0, import_path.resolve)(monorepoRoot, "packages", "domql", "src", "index.js");
|
|
101
|
+
if ((0, import_fs.existsSync)(src)) return { path: src };
|
|
102
|
+
const dist = (0, import_path.resolve)(monorepoRoot, "packages", "domql", "index.js");
|
|
103
|
+
if ((0, import_fs.existsSync)(dist)) return { path: dist };
|
|
104
|
+
});
|
|
105
|
+
build.onResolve({ filter: /^@symbo\.ls\// }, (args) => {
|
|
106
|
+
const pkg = args.path.replace("@symbo.ls/", "");
|
|
107
|
+
if (pkg === "sync") return { path: "sync-stub", namespace: "brender-stub" };
|
|
108
|
+
for (const dir of ["packages", "plugins"]) {
|
|
109
|
+
const src = (0, import_path.resolve)(monorepoRoot, dir, pkg, "src", "index.js");
|
|
110
|
+
if ((0, import_fs.existsSync)(src)) return { path: src };
|
|
111
|
+
const dist = (0, import_path.resolve)(monorepoRoot, dir, pkg, "index.js");
|
|
112
|
+
if ((0, import_fs.existsSync)(dist)) return { path: dist };
|
|
113
|
+
}
|
|
114
|
+
const blank = (0, import_path.resolve)(monorepoRoot, "packages", "default-config", "blank", "index.js");
|
|
115
|
+
if (pkg === "default-config" && (0, import_fs.existsSync)(blank)) return { path: blank };
|
|
116
|
+
});
|
|
117
|
+
build.onResolve({ filter: /^@domql\// }, (args) => {
|
|
118
|
+
const pkg = args.path.replace("@domql/", "");
|
|
119
|
+
const src = (0, import_path.resolve)(monorepoRoot, "packages", "domql", "packages", pkg, "src", "index.js");
|
|
120
|
+
if ((0, import_fs.existsSync)(src)) return { path: src };
|
|
121
|
+
const dist = (0, import_path.resolve)(monorepoRoot, "packages", "domql", "packages", pkg, "index.js");
|
|
122
|
+
if ((0, import_fs.existsSync)(dist)) return { path: dist };
|
|
123
|
+
});
|
|
124
|
+
build.onResolve({ filter: /^css-in-props/ }, (args) => {
|
|
125
|
+
const base = (0, import_path.resolve)(monorepoRoot, "packages", "css-in-props");
|
|
126
|
+
const subpath = args.path.replace(/^css-in-props\/?/, "");
|
|
127
|
+
if (subpath) {
|
|
128
|
+
const full = (0, import_path.resolve)(base, subpath);
|
|
129
|
+
const idx2 = (0, import_path.resolve)(full, "index.js");
|
|
130
|
+
if ((0, import_fs.existsSync)(idx2)) return { path: idx2 };
|
|
131
|
+
if ((0, import_fs.existsSync)(full + ".js")) return { path: full + ".js" };
|
|
132
|
+
if ((0, import_fs.existsSync)(full)) return { path: full };
|
|
133
|
+
}
|
|
134
|
+
const src = (0, import_path.resolve)(base, "src", "index.js");
|
|
135
|
+
if ((0, import_fs.existsSync)(src)) return { path: src };
|
|
136
|
+
const idx = (0, import_path.resolve)(base, "index.js");
|
|
137
|
+
if ((0, import_fs.existsSync)(idx)) return { path: idx };
|
|
138
|
+
});
|
|
139
|
+
build.onResolve({ filter: /^@emotion\// }, (args) => {
|
|
140
|
+
const nm = (0, import_path.resolve)(monorepoRoot, "node_modules", args.path);
|
|
141
|
+
if ((0, import_fs.existsSync)(nm)) {
|
|
142
|
+
const pkg = (0, import_path.resolve)(nm, "package.json");
|
|
143
|
+
if ((0, import_fs.existsSync)(pkg)) {
|
|
144
|
+
try {
|
|
145
|
+
const p = JSON.parse((0, import_fs.readFileSync)(pkg, "utf8"));
|
|
146
|
+
const main = p.module || p.main || "dist/emotion-css.esm.js";
|
|
147
|
+
return { path: (0, import_path.resolve)(nm, main) };
|
|
148
|
+
} catch {
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { path: nm };
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
build.onResolve({ filter: /\.json$/ }, (args) => {
|
|
155
|
+
if (args.resolveDir) {
|
|
156
|
+
const full = (0, import_path.resolve)(args.resolveDir, args.path);
|
|
157
|
+
if ((0, import_fs.existsSync)(full)) return { path: full };
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
build.onLoad({ filter: /smbls\/.*options\.js$/ }, async (args) => {
|
|
161
|
+
if (!args.path.includes("smbls/") || !args.path.endsWith("options.js")) return;
|
|
162
|
+
let contents = (0, import_fs.readFileSync)(args.path, "utf8");
|
|
163
|
+
contents = contents.replace(
|
|
164
|
+
/import\s*\{[^}]*version[^}]*\}\s*from\s*['"][^'"]*package\.json['"][^;\n]*/,
|
|
165
|
+
"const version = '0.0.0'"
|
|
166
|
+
);
|
|
167
|
+
contents = contents.replace(
|
|
168
|
+
/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,
|
|
169
|
+
"// createRequire removed for brender build"
|
|
170
|
+
);
|
|
171
|
+
return { contents, loader: "js" };
|
|
172
|
+
});
|
|
173
|
+
build.onLoad({ filter: /smbls\/.*init\.js$/ }, async (args) => {
|
|
174
|
+
if (!args.path.includes("smbls/") || !args.path.endsWith("init.js")) return;
|
|
175
|
+
let contents = (0, import_fs.readFileSync)(args.path, "utf8");
|
|
176
|
+
contents = contents.replace(
|
|
177
|
+
/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,
|
|
178
|
+
"// createRequire removed for brender build"
|
|
179
|
+
);
|
|
180
|
+
return { contents, loader: "js" };
|
|
181
|
+
});
|
|
182
|
+
build.onLoad({ filter: /.*/, namespace: "brender-stub" }, () => {
|
|
183
|
+
return { contents: "export const SyncComponent = {}; export const Inspect = {}; export const Notifications = {}; export default {}", loader: "js" };
|
|
184
|
+
});
|
|
185
|
+
build.onLoad({ filter: /smbls\/src\/router\.js$/ }, async (args) => {
|
|
186
|
+
let contents = (0, import_fs.readFileSync)(args.path, "utf8");
|
|
187
|
+
contents = contents.replace(
|
|
188
|
+
/import\s*\{\s*Link\s*\}\s*from\s*['"]smbls['"]/,
|
|
189
|
+
`const Link = { tag: 'a', attr: { href: (el) => el.props?.href } }`
|
|
190
|
+
);
|
|
191
|
+
return { contents, loader: "js" };
|
|
192
|
+
});
|
|
193
|
+
build.onLoad({ filter: /fetchOnCreate\.js$/ }, async (args) => {
|
|
194
|
+
if (!args.path.includes("smbls/")) return;
|
|
195
|
+
let contents = (0, import_fs.readFileSync)(args.path, "utf8");
|
|
196
|
+
contents = contents.replace(
|
|
197
|
+
/window\s*&&\s*window\.location\s*\?\s*window\.location\.host\.includes/g,
|
|
198
|
+
"window && window.location && window.location.host ? window.location.host.includes"
|
|
199
|
+
);
|
|
200
|
+
return { contents, loader: "js" };
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
await esbuild.build({
|
|
205
|
+
entryPoints: [entry],
|
|
206
|
+
bundle: true,
|
|
207
|
+
format: "esm",
|
|
208
|
+
platform: "node",
|
|
209
|
+
outfile: outFile,
|
|
210
|
+
write: true,
|
|
211
|
+
logLevel: "warning",
|
|
212
|
+
plugins: [workspacePlugin],
|
|
213
|
+
nodePaths: [(0, import_path.resolve)(monorepoRoot, "node_modules")],
|
|
214
|
+
supported: { "import-attributes": false },
|
|
215
|
+
external: [
|
|
216
|
+
"fs",
|
|
217
|
+
"path",
|
|
218
|
+
"os",
|
|
219
|
+
"crypto",
|
|
220
|
+
"url",
|
|
221
|
+
"http",
|
|
222
|
+
"https",
|
|
223
|
+
"stream",
|
|
224
|
+
"util",
|
|
225
|
+
"events",
|
|
226
|
+
"buffer",
|
|
227
|
+
"child_process",
|
|
228
|
+
"worker_threads",
|
|
229
|
+
"net",
|
|
230
|
+
"tls",
|
|
231
|
+
"dns",
|
|
232
|
+
"dgram",
|
|
233
|
+
"zlib",
|
|
234
|
+
"assert",
|
|
235
|
+
"querystring",
|
|
236
|
+
"string_decoder",
|
|
237
|
+
"readline",
|
|
238
|
+
"perf_hooks",
|
|
239
|
+
"async_hooks",
|
|
240
|
+
"v8",
|
|
241
|
+
"vm",
|
|
242
|
+
"cluster",
|
|
243
|
+
"inspector",
|
|
244
|
+
"module",
|
|
245
|
+
"process",
|
|
246
|
+
"tty",
|
|
247
|
+
"color-contrast-checker",
|
|
248
|
+
"linkedom"
|
|
249
|
+
]
|
|
250
|
+
});
|
|
251
|
+
const mod = await import(`file://${outFile}`);
|
|
252
|
+
try {
|
|
253
|
+
(0, import_fs.unlinkSync)(outFile);
|
|
254
|
+
} catch {
|
|
255
|
+
}
|
|
256
|
+
_cachedCreateDomql = mod;
|
|
257
|
+
return mod;
|
|
258
|
+
};
|
|
44
259
|
const UIKIT_STUBS = {
|
|
45
260
|
Box: {},
|
|
46
261
|
Focusable: {},
|
|
@@ -105,22 +320,55 @@ const UIKIT_STUBS = {
|
|
|
105
320
|
Text: { tag: "span" }
|
|
106
321
|
};
|
|
107
322
|
const render = async (data, options = {}) => {
|
|
108
|
-
const { route = "/", state: stateOverrides, context: contextOverrides } = options;
|
|
323
|
+
const { route = "/", state: stateOverrides, context: contextOverrides, prefetch = false } = options;
|
|
324
|
+
let prefetchedPages;
|
|
325
|
+
if (prefetch) {
|
|
326
|
+
try {
|
|
327
|
+
const pages = data.pages || {};
|
|
328
|
+
prefetchedPages = { ...pages };
|
|
329
|
+
const stateUpdates = await (0, import_prefetch.prefetchPageData)(data, route);
|
|
330
|
+
if (stateUpdates.size) {
|
|
331
|
+
const pageDef = JSON.parse(JSON.stringify(pages[route], (key, value) => {
|
|
332
|
+
if (typeof value === "function") return void 0;
|
|
333
|
+
return value;
|
|
334
|
+
}));
|
|
335
|
+
const copyFunctions = (src, dst) => {
|
|
336
|
+
if (!src || !dst) return;
|
|
337
|
+
for (const k in src) {
|
|
338
|
+
if (typeof src[k] === "function") {
|
|
339
|
+
dst[k] = src[k];
|
|
340
|
+
} else if (typeof src[k] === "object" && src[k] !== null && !Array.isArray(src[k]) && typeof dst[k] === "object" && dst[k] !== null) {
|
|
341
|
+
copyFunctions(src[k], dst[k]);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
copyFunctions(pages[route], pageDef);
|
|
346
|
+
(0, import_prefetch.injectPrefetchedState)(pageDef, stateUpdates);
|
|
347
|
+
prefetchedPages[route] = pageDef;
|
|
348
|
+
}
|
|
349
|
+
} catch {
|
|
350
|
+
prefetchedPages = data.pages;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
109
353
|
const { window, document } = (0, import_env.createEnv)();
|
|
110
354
|
const body = document.body;
|
|
111
355
|
window.location.pathname = route;
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
356
|
+
const _prevDoc = globalThis.document;
|
|
357
|
+
const _prevLoc = globalThis.location;
|
|
358
|
+
globalThis.document = document;
|
|
359
|
+
globalThis.location = window.location;
|
|
360
|
+
const { createDomqlElement } = await bundleCreateDomql();
|
|
361
|
+
const app = structuredCloneDeep(data.app || {});
|
|
115
362
|
const ctx = {
|
|
116
|
-
state:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
363
|
+
state: structuredCloneDeep(data.state || {}),
|
|
364
|
+
...stateOverrides ? { state: { ...structuredCloneDeep(data.state || {}), ...stateOverrides } } : {},
|
|
365
|
+
dependencies: structuredCloneDeep(data.dependencies || {}),
|
|
366
|
+
components: structuredCloneDeep(data.components || {}),
|
|
367
|
+
snippets: structuredCloneDeep(data.snippets || {}),
|
|
368
|
+
pages: structuredCloneDeep(prefetchedPages || data.pages || {}),
|
|
121
369
|
functions: data.functions || {},
|
|
122
370
|
methods: data.methods || {},
|
|
123
|
-
designSystem: data.designSystem || {},
|
|
371
|
+
designSystem: structuredCloneDeep(data.designSystem || {}),
|
|
124
372
|
files: data.files || {},
|
|
125
373
|
...data.config || data.settings || {},
|
|
126
374
|
// Virtual DOM environment
|
|
@@ -132,11 +380,52 @@ const render = async (data, options = {}) => {
|
|
|
132
380
|
};
|
|
133
381
|
(0, import_keys.resetKeys)();
|
|
134
382
|
const element = await createDomqlElement(app, ctx);
|
|
383
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
135
384
|
(0, import_keys.assignKeys)(body);
|
|
136
385
|
const registry = (0, import_keys.mapKeysToElements)(element);
|
|
137
386
|
const metadata = (0, import_metadata.extractMetadata)(data, route);
|
|
138
|
-
const
|
|
139
|
-
|
|
387
|
+
const emotionCSS = [];
|
|
388
|
+
const emotionInstance = ctx.emotion || element && element.context && element.context.emotion;
|
|
389
|
+
if (emotionInstance && emotionInstance.cache) {
|
|
390
|
+
const cache = emotionInstance.cache;
|
|
391
|
+
if (cache.inserted) {
|
|
392
|
+
for (const key in cache.inserted) {
|
|
393
|
+
const rule = cache.inserted[key];
|
|
394
|
+
if (typeof rule === "string" && rule) emotionCSS.push(rule);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (cache.sheet && cache.sheet.tags) {
|
|
398
|
+
for (const tag of cache.sheet.tags) {
|
|
399
|
+
if (tag.sheet && tag.sheet.cssRules) {
|
|
400
|
+
for (const rule of tag.sheet.cssRules) {
|
|
401
|
+
if (rule.cssText) emotionCSS.push(rule.cssText);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (!emotionCSS.length) {
|
|
408
|
+
const head = document.head || document.querySelector("head");
|
|
409
|
+
if (head) {
|
|
410
|
+
for (const style of head.querySelectorAll("style")) {
|
|
411
|
+
if (style.sheet && style.sheet.cssRules) {
|
|
412
|
+
for (const rule of style.sheet.cssRules) {
|
|
413
|
+
if (rule.cssText) emotionCSS.push(rule.cssText);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (!emotionCSS.length) {
|
|
417
|
+
const content = style.textContent || "";
|
|
418
|
+
if (content) emotionCSS.push(content);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const html = fixSvgContent(body.innerHTML);
|
|
424
|
+
if (_prevDoc !== void 0) globalThis.document = _prevDoc;
|
|
425
|
+
else delete globalThis.document;
|
|
426
|
+
if (_prevLoc !== void 0) globalThis.location = _prevLoc;
|
|
427
|
+
else delete globalThis.location;
|
|
428
|
+
return { html, metadata, registry, element, emotionCSS, document, window };
|
|
140
429
|
};
|
|
141
430
|
const renderElement = async (elementDef, options = {}) => {
|
|
142
431
|
const { context = {} } = options;
|
|
@@ -179,15 +468,15 @@ let _cachedGlobalCSS = null;
|
|
|
179
468
|
const generateGlobalCSS = async (ds, config) => {
|
|
180
469
|
if (_cachedGlobalCSS) return _cachedGlobalCSS;
|
|
181
470
|
try {
|
|
182
|
-
const { existsSync, writeFileSync, unlinkSync } = await import("fs");
|
|
183
|
-
const { tmpdir } = await import("os");
|
|
184
|
-
const { randomBytes } = await import("crypto");
|
|
471
|
+
const { existsSync: existsSync2, writeFileSync: writeFileSync2, unlinkSync: unlinkSync2 } = await import("fs");
|
|
472
|
+
const { tmpdir: tmpdir2 } = await import("os");
|
|
473
|
+
const { randomBytes: randomBytes2 } = await import("crypto");
|
|
185
474
|
const esbuild = await import("esbuild");
|
|
186
|
-
const dsJson = JSON.stringify(ds || {});
|
|
187
|
-
const cfgJson = JSON.stringify(config || {});
|
|
188
|
-
const tmpEntry = (0, import_path.join)(
|
|
189
|
-
const tmpOut = (0, import_path.join)(
|
|
190
|
-
|
|
475
|
+
const dsJson = JSON.stringify(ds || {}, safeJsonReplacer());
|
|
476
|
+
const cfgJson = JSON.stringify(config || {}, safeJsonReplacer());
|
|
477
|
+
const tmpEntry = (0, import_path.join)(tmpdir2(), `br_global_${randomBytes2(6).toString("hex")}.mjs`);
|
|
478
|
+
const tmpOut = (0, import_path.join)(tmpdir2(), `br_global_${randomBytes2(6).toString("hex")}_out.mjs`);
|
|
479
|
+
writeFileSync2(tmpEntry, `
|
|
191
480
|
import { set, getActiveConfig, getFontFaceString } from '@symbo.ls/scratch'
|
|
192
481
|
import { DEFAULT_CONFIG } from '@symbo.ls/default-config'
|
|
193
482
|
|
|
@@ -235,17 +524,17 @@ const generateGlobalCSS = async (ds, config) => {
|
|
|
235
524
|
const pkg = args.path.replace("@symbo.ls/", "");
|
|
236
525
|
for (const dir of ["packages", "plugins"]) {
|
|
237
526
|
const src = (0, import_path.resolve)(monorepoRoot, dir, pkg, "src", "index.js");
|
|
238
|
-
if (
|
|
527
|
+
if (existsSync2(src)) return { path: src };
|
|
239
528
|
const dist = (0, import_path.resolve)(monorepoRoot, dir, pkg, "index.js");
|
|
240
|
-
if (
|
|
529
|
+
if (existsSync2(dist)) return { path: dist };
|
|
241
530
|
}
|
|
242
531
|
const blank = (0, import_path.resolve)(monorepoRoot, "packages", "default-config", "blank", "index.js");
|
|
243
|
-
if (pkg === "default-config" &&
|
|
532
|
+
if (pkg === "default-config" && existsSync2(blank)) return { path: blank };
|
|
244
533
|
});
|
|
245
534
|
build.onResolve({ filter: /^@domql\// }, (args) => {
|
|
246
535
|
const pkg = args.path.replace("@domql/", "");
|
|
247
536
|
const src = (0, import_path.resolve)(monorepoRoot, "packages", "domql", "packages", pkg, "src", "index.js");
|
|
248
|
-
if (
|
|
537
|
+
if (existsSync2(src)) return { path: src };
|
|
249
538
|
});
|
|
250
539
|
}
|
|
251
540
|
};
|
|
@@ -263,11 +552,11 @@ const generateGlobalCSS = async (ds, config) => {
|
|
|
263
552
|
const mod = await import(`file://${tmpOut}`);
|
|
264
553
|
const data = mod.default || {};
|
|
265
554
|
try {
|
|
266
|
-
|
|
555
|
+
unlinkSync2(tmpEntry);
|
|
267
556
|
} catch {
|
|
268
557
|
}
|
|
269
558
|
try {
|
|
270
|
-
|
|
559
|
+
unlinkSync2(tmpOut);
|
|
271
560
|
} catch {
|
|
272
561
|
}
|
|
273
562
|
const cssVars = data.CSS_VARS || {};
|
|
@@ -320,8 +609,10 @@ ${frameRules}
|
|
|
320
609
|
return _cachedGlobalCSS;
|
|
321
610
|
}
|
|
322
611
|
};
|
|
612
|
+
let _cachedEmotionCSS = null;
|
|
323
613
|
const resetGlobalCSSCache = () => {
|
|
324
614
|
_cachedGlobalCSS = null;
|
|
615
|
+
_cachedEmotionCSS = null;
|
|
325
616
|
};
|
|
326
617
|
const renderRoute = async (data, options = {}) => {
|
|
327
618
|
const { route = "/" } = options;
|
|
@@ -364,13 +655,21 @@ const renderRoute = async (data, options = {}) => {
|
|
|
364
655
|
};
|
|
365
656
|
};
|
|
366
657
|
const renderPage = async (data, route = "/", options = {}) => {
|
|
367
|
-
const { lang
|
|
368
|
-
const
|
|
658
|
+
const { lang, themeColor, isr, prefetch = true } = options;
|
|
659
|
+
const htmlLang = lang || data.state?.lang || data.app?.metadata?.lang || "en";
|
|
660
|
+
const result = await render(data, { route, prefetch });
|
|
369
661
|
if (!result) return null;
|
|
370
662
|
const metadata = { ...result.metadata };
|
|
371
663
|
if (themeColor) metadata["theme-color"] = themeColor;
|
|
372
664
|
const headTags = (0, import_metadata.generateHeadHtml)(metadata);
|
|
373
|
-
|
|
665
|
+
if (!_cachedEmotionCSS && result.emotionCSS && result.emotionCSS.length) {
|
|
666
|
+
_cachedEmotionCSS = result.emotionCSS.join("\n");
|
|
667
|
+
}
|
|
668
|
+
const emotionCSS = _cachedEmotionCSS || (result.emotionCSS || []).join("\n");
|
|
669
|
+
const ds = data.designSystem || {};
|
|
670
|
+
const globalCSS = await generateGlobalCSS(ds, data.config || data.settings);
|
|
671
|
+
const fontLinks = generateFontLinks(ds);
|
|
672
|
+
const brKeyCount = Object.keys(result.registry).length;
|
|
374
673
|
let isrBody = "";
|
|
375
674
|
if (isr && isr.clientScript) {
|
|
376
675
|
const depth = route === "/" ? 0 : route.replace(/^\/|\/$/g, "").split("/").length;
|
|
@@ -395,26 +694,26 @@ const renderPage = async (data, route = "/", options = {}) => {
|
|
|
395
694
|
<script type="module" src="${prefix}${isr.clientScript}"><\/script>`;
|
|
396
695
|
}
|
|
397
696
|
const html = `<!DOCTYPE html>
|
|
398
|
-
<html lang="${
|
|
697
|
+
<html lang="${htmlLang}">
|
|
399
698
|
<head>
|
|
400
699
|
${headTags}
|
|
401
|
-
${
|
|
700
|
+
${fontLinks}
|
|
402
701
|
${globalCSS.fontFaceCSS ? `<style>${globalCSS.fontFaceCSS}</style>` : ""}
|
|
403
702
|
<style>
|
|
404
703
|
${globalCSS.rootRule || ""}
|
|
405
|
-
${
|
|
704
|
+
${globalCSS.resetRules || ""}
|
|
406
705
|
${globalCSS.keyframeRules || ""}
|
|
407
706
|
</style>
|
|
408
|
-
|
|
409
|
-
${
|
|
410
|
-
</style
|
|
707
|
+
${emotionCSS ? `<style data-emotion="smbls">
|
|
708
|
+
${emotionCSS}
|
|
709
|
+
</style>` : ""}
|
|
411
710
|
</head>
|
|
412
711
|
<body>
|
|
413
712
|
${result.html}
|
|
414
713
|
${isrBody}
|
|
415
714
|
</body>
|
|
416
715
|
</html>`;
|
|
417
|
-
return { html, route, brKeyCount
|
|
716
|
+
return { html, route, brKeyCount };
|
|
418
717
|
};
|
|
419
718
|
const LETTER_TO_INDEX = {
|
|
420
719
|
U: -6,
|
package/dist/esm/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createEnv } from "./env.js";
|
|
2
2
|
import { resetKeys, assignKeys, mapKeysToElements } from "./keys.js";
|
|
3
3
|
import { loadProject, loadAndRenderAll } from "./load.js";
|
|
4
|
-
import { render, renderElement, renderRoute, renderPage } from "./render.js";
|
|
4
|
+
import { render, renderElement, renderRoute, renderPage, resetGlobalCSSCache } from "./render.js";
|
|
5
5
|
import { extractMetadata, generateHeadHtml } from "./metadata.js";
|
|
6
6
|
import { collectBrNodes, hydrate } from "./hydrate.js";
|
|
7
7
|
import { generateSitemap } from "./sitemap.js";
|
|
8
|
+
import { prefetchPageData, injectPrefetchedState } from "./prefetch.js";
|
|
8
9
|
var index_default = {
|
|
9
10
|
createEnv,
|
|
10
11
|
resetKeys,
|
|
@@ -16,11 +17,14 @@ var index_default = {
|
|
|
16
17
|
renderElement,
|
|
17
18
|
renderRoute,
|
|
18
19
|
renderPage,
|
|
20
|
+
resetGlobalCSSCache,
|
|
19
21
|
extractMetadata,
|
|
20
22
|
generateHeadHtml,
|
|
21
23
|
collectBrNodes,
|
|
22
24
|
hydrate,
|
|
23
|
-
generateSitemap
|
|
25
|
+
generateSitemap,
|
|
26
|
+
prefetchPageData,
|
|
27
|
+
injectPrefetchedState
|
|
24
28
|
};
|
|
25
29
|
export {
|
|
26
30
|
assignKeys,
|
|
@@ -31,12 +35,15 @@ export {
|
|
|
31
35
|
generateHeadHtml,
|
|
32
36
|
generateSitemap,
|
|
33
37
|
hydrate,
|
|
38
|
+
injectPrefetchedState,
|
|
34
39
|
loadAndRenderAll,
|
|
35
40
|
loadProject,
|
|
36
41
|
mapKeysToElements,
|
|
42
|
+
prefetchPageData,
|
|
37
43
|
render,
|
|
38
44
|
renderElement,
|
|
39
45
|
renderPage,
|
|
40
46
|
renderRoute,
|
|
47
|
+
resetGlobalCSSCache,
|
|
41
48
|
resetKeys
|
|
42
49
|
};
|