@symbo.ls/brender 3.14.0 → 3.14.2
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 +12 -0
- package/dist/esm/env.js +1 -80
- package/dist/esm/hydrate.js +1 -535
- package/dist/esm/index.js +1 -53
- package/dist/esm/keys.js +1 -43
- package/dist/esm/load.js +1 -114
- package/dist/esm/metadata.js +1 -7
- package/dist/esm/prefetch.js +1 -235
- package/dist/esm/render.js +50 -1512
- package/dist/esm/scripts/liquidate.js +11 -0
- package/dist/esm/scripts/render.js +12 -0
- package/dist/esm/sitemap.js +10 -19
- package/package.json +27 -17
- package/dist/cjs/env.js +0 -99
- package/dist/cjs/hydrate.js +0 -554
- package/dist/cjs/index.js +0 -72
- package/dist/cjs/keys.js +0 -62
- package/dist/cjs/load.js +0 -143
- package/dist/cjs/metadata.js +0 -26
- package/dist/cjs/prefetch.js +0 -264
- package/dist/cjs/render.js +0 -1602
- package/dist/cjs/sitemap.js +0 -41
- package/env.js +0 -76
- package/hydrate.js +0 -462
- package/index.js +0 -54
- package/keys.js +0 -54
- package/load.js +0 -141
- package/metadata.js +0 -5
- package/prefetch.js +0 -363
- package/render.js +0 -1887
- package/sitemap.js +0 -28
package/dist/esm/render.js
CHANGED
|
@@ -1,805 +1,11 @@
|
|
|
1
|
-
import { resolve,
|
|
2
|
-
import { existsSync, writeFileSync, unlinkSync, readFileSync, realpathSync } from "fs";
|
|
3
|
-
import { tmpdir } from "os";
|
|
4
|
-
import { randomBytes } from "crypto";
|
|
5
|
-
import { createRequire } from "module";
|
|
6
|
-
import { createEnv } from "./env.js";
|
|
7
|
-
import { resetKeys, assignKeys, mapKeysToElements } from "./keys.js";
|
|
8
|
-
import { extractMetadata, generateHeadHtml } from "./metadata.js";
|
|
9
|
-
import { hydrate } from "./hydrate.js";
|
|
10
|
-
import { prefetchPageData, injectPrefetchedState, fetchSSRTranslations } from "./prefetch.js";
|
|
11
|
-
let _funcqlPlugin = null;
|
|
12
|
-
const getFuncqlPlugin = async () => {
|
|
13
|
-
if (_funcqlPlugin) return _funcqlPlugin;
|
|
14
|
-
try {
|
|
15
|
-
const mod = await import("@symbo.ls/funcql");
|
|
16
|
-
_funcqlPlugin = mod.funcqlPlugin;
|
|
17
|
-
return _funcqlPlugin;
|
|
18
|
-
} catch {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
import { parseHTML } from "linkedom";
|
|
23
|
-
import { css, injectGlobal, reset as resetCss } from "@symbo.ls/css";
|
|
24
|
-
const ssrResolve = (map, key) => {
|
|
25
|
-
if (!map || !key) return void 0;
|
|
26
|
-
if (map[key] !== void 0) return map[key];
|
|
27
|
-
const parts = key.split(".");
|
|
28
|
-
let v = map;
|
|
29
|
-
for (const p of parts) {
|
|
30
|
-
if (v == null || typeof v !== "object") return void 0;
|
|
31
|
-
v = v[p];
|
|
32
|
-
}
|
|
33
|
-
return v;
|
|
34
|
-
};
|
|
35
|
-
const ssrTranslate = function(key, lang) {
|
|
36
|
-
if (!key) return "";
|
|
37
|
-
const ctx = this?.context;
|
|
38
|
-
const poly = ctx?.polyglot;
|
|
39
|
-
const activeLang = lang || poly?.defaultLang || "ka";
|
|
40
|
-
if (poly?.translations) {
|
|
41
|
-
const langMap = poly.translations[activeLang];
|
|
42
|
-
if (langMap) {
|
|
43
|
-
const val = ssrResolve(langMap, key);
|
|
44
|
-
if (val !== void 0) return val;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const root = this?.state?.root || ctx?.state?.root;
|
|
48
|
-
if (root?.translations) {
|
|
49
|
-
const langMap = root.translations[activeLang];
|
|
50
|
-
if (langMap) {
|
|
51
|
-
const val = ssrResolve(langMap, key);
|
|
52
|
-
if (val !== void 0) return val;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const defaultLang = poly?.defaultLang || "en";
|
|
56
|
-
if (defaultLang !== activeLang && poly?.translations) {
|
|
57
|
-
const fallback = poly.translations[defaultLang];
|
|
58
|
-
if (fallback) {
|
|
59
|
-
const val = ssrResolve(fallback, key);
|
|
60
|
-
if (val !== void 0) return val;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return key;
|
|
64
|
-
};
|
|
65
|
-
const ssrGetActiveLang = function() {
|
|
66
|
-
const ctx = this?.context;
|
|
67
|
-
return this?.state?.root?.lang || ctx?.polyglot?.defaultLang || "ka";
|
|
68
|
-
};
|
|
69
|
-
const structuredCloneDeep = (obj, seen = /* @__PURE__ */ new WeakMap()) => {
|
|
70
|
-
if (obj === null || typeof obj !== "object") return obj;
|
|
71
|
-
if (seen.has(obj)) return seen.get(obj);
|
|
72
|
-
if (Array.isArray(obj)) {
|
|
73
|
-
const arr = [];
|
|
74
|
-
seen.set(obj, arr);
|
|
75
|
-
for (const v of obj) arr.push(typeof v === "object" && v !== null ? structuredCloneDeep(v, seen) : v);
|
|
76
|
-
return arr;
|
|
77
|
-
}
|
|
78
|
-
const clone = {};
|
|
79
|
-
seen.set(obj, clone);
|
|
80
|
-
for (const k of Object.keys(obj)) {
|
|
81
|
-
const v = obj[k];
|
|
82
|
-
clone[k] = typeof v === "object" && v !== null ? structuredCloneDeep(v, seen) : v;
|
|
83
|
-
}
|
|
84
|
-
return clone;
|
|
85
|
-
};
|
|
86
|
-
const safeJsonReplacer = () => {
|
|
87
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
88
|
-
return (key, value) => {
|
|
89
|
-
if (typeof value === "function") return void 0;
|
|
90
|
-
if (typeof value === "object" && value !== null) {
|
|
91
|
-
if (seen.has(value)) return void 0;
|
|
92
|
-
seen.add(value);
|
|
93
|
-
}
|
|
94
|
-
return value;
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
let _brenderRequire = null;
|
|
98
|
-
try {
|
|
99
|
-
if (import.meta.url) {
|
|
100
|
-
_brenderRequire = createRequire(import.meta.url);
|
|
101
|
-
}
|
|
102
|
-
} catch {
|
|
103
|
-
}
|
|
104
|
-
const detectWorkspace = () => {
|
|
105
|
-
if (!import.meta.url || !_brenderRequire) {
|
|
106
|
-
return { isMonorepo: false, monorepoRoot: null, resolvePackage: (pkg) => pkg };
|
|
107
|
-
}
|
|
108
|
-
const brenderDir = realpathSync(new URL(".", import.meta.url).pathname);
|
|
109
|
-
const monorepoRoot = resolve(brenderDir, "../..");
|
|
110
|
-
const isMonorepo = existsSync(resolve(monorepoRoot, "packages", "smbls", "src", "createDomql.js"));
|
|
111
|
-
if (isMonorepo) {
|
|
112
|
-
return { isMonorepo: true, monorepoRoot };
|
|
113
|
-
}
|
|
114
|
-
let smblsRoot;
|
|
115
|
-
try {
|
|
116
|
-
const smblsPkg = _brenderRequire.resolve("smbls/package.json");
|
|
117
|
-
smblsRoot = dirname(smblsPkg);
|
|
118
|
-
} catch {
|
|
119
|
-
let dir2 = brenderDir;
|
|
120
|
-
while (dir2 !== dirname(dir2)) {
|
|
121
|
-
const candidate = resolve(dir2, "node_modules", "smbls");
|
|
122
|
-
if (existsSync(resolve(candidate, "package.json"))) {
|
|
123
|
-
smblsRoot = candidate;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
dir2 = dirname(dir2);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
let _smblsRequire = _brenderRequire;
|
|
130
|
-
if (smblsRoot) {
|
|
131
|
-
try {
|
|
132
|
-
_smblsRequire = createRequire(resolve(smblsRoot, "package.json"));
|
|
133
|
-
} catch {
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
let projectRoot;
|
|
137
|
-
let dir = process.cwd();
|
|
138
|
-
while (dir !== dirname(dir)) {
|
|
139
|
-
if (existsSync(resolve(dir, "package.json"))) {
|
|
140
|
-
projectRoot = dir;
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
dir = dirname(dir);
|
|
144
|
-
}
|
|
145
|
-
let _projectRequire = _smblsRequire;
|
|
146
|
-
if (projectRoot) {
|
|
147
|
-
try {
|
|
148
|
-
_projectRequire = createRequire(resolve(projectRoot, "package.json"));
|
|
149
|
-
} catch {
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return { isMonorepo: false, smblsRoot, brenderDir, projectRoot, _smblsRequire, _projectRequire };
|
|
153
|
-
};
|
|
154
|
-
const tryRequireResolve = (ws, specifier) => {
|
|
155
|
-
const requireFns = ws.isMonorepo ? [_brenderRequire] : [ws._smblsRequire, ws._projectRequire, _brenderRequire].filter(Boolean);
|
|
156
|
-
for (const req of requireFns) {
|
|
157
|
-
try {
|
|
158
|
-
return req.resolve(specifier);
|
|
159
|
-
} catch {
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return null;
|
|
163
|
-
};
|
|
164
|
-
const resolvePackagePath = (ws, pkgName, ...subpath) => {
|
|
165
|
-
if (ws.isMonorepo) {
|
|
166
|
-
return resolve(ws.monorepoRoot, "packages", pkgName, ...subpath);
|
|
167
|
-
}
|
|
168
|
-
const pkgJson = tryRequireResolve(ws, `${pkgName}/package.json`);
|
|
169
|
-
if (pkgJson) return resolve(dirname(pkgJson), ...subpath);
|
|
170
|
-
return null;
|
|
171
|
-
};
|
|
172
|
-
const resolvePluginPath = (ws, pluginName, ...subpath) => {
|
|
173
|
-
if (ws.isMonorepo) {
|
|
174
|
-
return resolve(ws.monorepoRoot, "plugins", pluginName, ...subpath);
|
|
175
|
-
}
|
|
176
|
-
const pkgJson = tryRequireResolve(ws, `@symbo.ls/${pluginName}/package.json`);
|
|
177
|
-
if (pkgJson) return resolve(dirname(pkgJson), ...subpath);
|
|
178
|
-
return null;
|
|
179
|
-
};
|
|
180
|
-
const resolveSymbolsPackage = (ws, pkg, ...subpath) => {
|
|
181
|
-
if (ws.isMonorepo) {
|
|
182
|
-
for (const dir of ["packages", "plugins"]) {
|
|
183
|
-
const src = resolve(ws.monorepoRoot, dir, pkg, ...subpath);
|
|
184
|
-
if (existsSync(src)) return src;
|
|
185
|
-
}
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
const pkgJson = tryRequireResolve(ws, `@symbo.ls/${pkg}/package.json`);
|
|
189
|
-
if (pkgJson) return resolve(dirname(pkgJson), ...subpath);
|
|
190
|
-
return null;
|
|
191
|
-
};
|
|
192
|
-
const resolveDomqlPackage = (ws, pkg, ...subpath) => {
|
|
193
|
-
if (ws.isMonorepo) {
|
|
194
|
-
return resolve(ws.monorepoRoot, "packages", "domql", "packages", pkg, ...subpath);
|
|
195
|
-
}
|
|
196
|
-
const pkgJson = tryRequireResolve(ws, `@symbo.ls/${pkg}/package.json`);
|
|
197
|
-
if (pkgJson) return resolve(dirname(pkgJson), ...subpath);
|
|
198
|
-
return null;
|
|
199
|
-
};
|
|
200
|
-
let _cachedCreateDomql = null;
|
|
201
|
-
const bundleCreateDomql = async () => {
|
|
202
|
-
if (_cachedCreateDomql) return _cachedCreateDomql;
|
|
203
|
-
const ws = detectWorkspace();
|
|
204
|
-
if (!_brenderRequire) {
|
|
205
|
-
try {
|
|
206
|
-
const mod2 = await import("./dist/createDomql.bundled.mjs");
|
|
207
|
-
_cachedCreateDomql = mod2;
|
|
208
|
-
return mod2;
|
|
209
|
-
} catch (err) {
|
|
210
|
-
throw new Error(`brender: pre-bundled createDomql not available in bundled runtime: ${err.message}`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
let entry;
|
|
214
|
-
if (ws.isMonorepo) {
|
|
215
|
-
entry = resolve(ws.monorepoRoot, "packages", "smbls", "src", "createDomql.js");
|
|
216
|
-
} else if (ws.smblsRoot) {
|
|
217
|
-
const srcEntry = resolve(ws.smblsRoot, "src", "createDomql.js");
|
|
218
|
-
const distEntry = resolve(ws.smblsRoot, "dist", "esm", "src", "createDomql.js");
|
|
219
|
-
entry = existsSync(srcEntry) ? srcEntry : distEntry;
|
|
220
|
-
}
|
|
221
|
-
if (!entry || !existsSync(entry)) {
|
|
222
|
-
throw new Error(`brender: cannot find createDomql.js (isMonorepo=${ws.isMonorepo}, entry=${entry})`);
|
|
223
|
-
}
|
|
224
|
-
const esbuild = await import("esbuild");
|
|
225
|
-
const outFile = join(tmpdir(), `br_createDomql_${randomBytes(6).toString("hex")}.mjs`);
|
|
226
|
-
const tryResolve = (base) => {
|
|
227
|
-
if (!base) return null;
|
|
228
|
-
const src = resolve(base, "src", "index.js");
|
|
229
|
-
if (existsSync(src)) return src;
|
|
230
|
-
const idx = resolve(base, "index.js");
|
|
231
|
-
if (existsSync(idx)) return idx;
|
|
232
|
-
return null;
|
|
233
|
-
};
|
|
234
|
-
const workspacePlugin = {
|
|
235
|
-
name: "workspace-resolve",
|
|
236
|
-
setup(build) {
|
|
237
|
-
build.onResolve({ filter: /^smbls/ }, (args) => {
|
|
238
|
-
const subpath = args.path.replace(/^smbls\/?/, "");
|
|
239
|
-
const smblsBase = ws.isMonorepo ? resolve(ws.monorepoRoot, "packages", "smbls") : ws.smblsRoot;
|
|
240
|
-
if (!smblsBase) return;
|
|
241
|
-
if (!subpath) {
|
|
242
|
-
const r = tryResolve(smblsBase);
|
|
243
|
-
if (r) return { path: r };
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
const full = resolve(smblsBase, subpath);
|
|
247
|
-
if (existsSync(full)) return { path: full };
|
|
248
|
-
if (existsSync(full + ".js")) return { path: full + ".js" };
|
|
249
|
-
const idx = resolve(full, "index.js");
|
|
250
|
-
if (existsSync(idx)) return { path: idx };
|
|
251
|
-
});
|
|
252
|
-
build.onResolve({ filter: /^domql$/ }, (args) => {
|
|
253
|
-
if (ws.isMonorepo) {
|
|
254
|
-
const src = resolve(ws.monorepoRoot, "packages", "domql", "src", "index.js");
|
|
255
|
-
if (existsSync(src)) return { path: src };
|
|
256
|
-
const dist = resolve(ws.monorepoRoot, "packages", "domql", "index.js");
|
|
257
|
-
if (existsSync(dist)) return { path: dist };
|
|
258
|
-
} else {
|
|
259
|
-
try {
|
|
260
|
-
const pkgJson = _require.resolve("domql/package.json");
|
|
261
|
-
const r = tryResolve(dirname(pkgJson));
|
|
262
|
-
if (r) return { path: r };
|
|
263
|
-
} catch {
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
build.onResolve({ filter: /^@symbo\.ls\// }, (args) => {
|
|
268
|
-
const pkg = args.path.replace("@symbo.ls/", "");
|
|
269
|
-
if (pkg === "sync") return { path: "sync-stub", namespace: "brender-stub" };
|
|
270
|
-
if (ws.isMonorepo) {
|
|
271
|
-
for (const dir of ["packages", "plugins"]) {
|
|
272
|
-
const src = resolve(ws.monorepoRoot, dir, pkg, "src", "index.js");
|
|
273
|
-
if (existsSync(src)) return { path: src };
|
|
274
|
-
const dist = resolve(ws.monorepoRoot, dir, pkg, "index.js");
|
|
275
|
-
if (existsSync(dist)) return { path: dist };
|
|
276
|
-
}
|
|
277
|
-
const blank = resolve(ws.monorepoRoot, "packages", "default-config", "blank", "index.js");
|
|
278
|
-
if (pkg === "default-config" && existsSync(blank)) return { path: blank };
|
|
279
|
-
} else {
|
|
280
|
-
const resolved = resolveSymbolsPackage(ws, pkg, "src", "index.js");
|
|
281
|
-
if (resolved && existsSync(resolved)) return { path: resolved };
|
|
282
|
-
const resolvedIdx = resolveSymbolsPackage(ws, pkg, "index.js");
|
|
283
|
-
if (resolvedIdx && existsSync(resolvedIdx)) return { path: resolvedIdx };
|
|
284
|
-
if (pkg === "default-config") {
|
|
285
|
-
const blank = resolveSymbolsPackage(ws, "default-config", "blank", "index.js");
|
|
286
|
-
if (blank && existsSync(blank)) return { path: blank };
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
build.onResolve({ filter: /^@domql\// }, (args) => {
|
|
291
|
-
const pkg = args.path.replace("@symbo.ls/", "");
|
|
292
|
-
if (ws.isMonorepo) {
|
|
293
|
-
const src = resolve(ws.monorepoRoot, "packages", "domql", "packages", pkg, "src", "index.js");
|
|
294
|
-
if (existsSync(src)) return { path: src };
|
|
295
|
-
const dist = resolve(ws.monorepoRoot, "packages", "domql", "packages", pkg, "index.js");
|
|
296
|
-
if (existsSync(dist)) return { path: dist };
|
|
297
|
-
} else {
|
|
298
|
-
const resolved = resolveDomqlPackage(ws, pkg, "src", "index.js");
|
|
299
|
-
if (resolved && existsSync(resolved)) return { path: resolved };
|
|
300
|
-
const resolvedIdx = resolveDomqlPackage(ws, pkg, "index.js");
|
|
301
|
-
if (resolvedIdx && existsSync(resolvedIdx)) return { path: resolvedIdx };
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
build.onResolve({ filter: /^css-in-props/ }, (args) => {
|
|
305
|
-
let base;
|
|
306
|
-
if (ws.isMonorepo) {
|
|
307
|
-
base = resolve(ws.monorepoRoot, "packages", "css-in-props");
|
|
308
|
-
} else {
|
|
309
|
-
const pkgJson = tryRequireResolve(ws, "css-in-props/package.json");
|
|
310
|
-
if (pkgJson) base = dirname(pkgJson);
|
|
311
|
-
}
|
|
312
|
-
if (!base) return;
|
|
313
|
-
const subpath = args.path.replace(/^css-in-props\/?/, "");
|
|
314
|
-
if (subpath) {
|
|
315
|
-
const full = resolve(base, subpath);
|
|
316
|
-
const idx = resolve(full, "index.js");
|
|
317
|
-
if (existsSync(idx)) return { path: idx };
|
|
318
|
-
if (existsSync(full + ".js")) return { path: full + ".js" };
|
|
319
|
-
if (existsSync(full)) return { path: full };
|
|
320
|
-
}
|
|
321
|
-
const r = tryResolve(base);
|
|
322
|
-
if (r) return { path: r };
|
|
323
|
-
});
|
|
324
|
-
build.onResolve({ filter: /^@emotion\// }, (args) => {
|
|
325
|
-
let nm;
|
|
326
|
-
if (ws.isMonorepo) {
|
|
327
|
-
nm = resolve(ws.monorepoRoot, "node_modules", args.path);
|
|
328
|
-
} else {
|
|
329
|
-
const pkgJson = tryRequireResolve(ws, `${args.path}/package.json`);
|
|
330
|
-
if (!pkgJson) return;
|
|
331
|
-
nm = dirname(pkgJson);
|
|
332
|
-
}
|
|
333
|
-
if (existsSync(nm)) {
|
|
334
|
-
const pkg = resolve(nm, "package.json");
|
|
335
|
-
if (existsSync(pkg)) {
|
|
336
|
-
try {
|
|
337
|
-
const p = JSON.parse(readFileSync(pkg, "utf8"));
|
|
338
|
-
const main = p.module || p.main || "dist/emotion-css.esm.js";
|
|
339
|
-
return { path: resolve(nm, main) };
|
|
340
|
-
} catch {
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return { path: nm };
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
build.onResolve({ filter: /\.json$/ }, (args) => {
|
|
347
|
-
if (args.resolveDir) {
|
|
348
|
-
const full = resolve(args.resolveDir, args.path);
|
|
349
|
-
if (existsSync(full)) return { path: full };
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
build.onLoad({ filter: /smbls\/.*options\.js$/ }, async (args) => {
|
|
353
|
-
if (!args.path.includes("smbls/") || !args.path.endsWith("options.js")) return;
|
|
354
|
-
let contents = readFileSync(args.path, "utf8");
|
|
355
|
-
contents = contents.replace(
|
|
356
|
-
/import\s*\{[^}]*version[^}]*\}\s*from\s*['"][^'"]*package\.json['"][^;\n]*/,
|
|
357
|
-
"const version = '0.0.0'"
|
|
358
|
-
);
|
|
359
|
-
contents = contents.replace(
|
|
360
|
-
/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,
|
|
361
|
-
"// createRequire removed for brender build"
|
|
362
|
-
);
|
|
363
|
-
return { contents, loader: "js" };
|
|
364
|
-
});
|
|
365
|
-
build.onLoad({ filter: /smbls\/.*init\.js$/ }, async (args) => {
|
|
366
|
-
if (!args.path.includes("smbls/") || !args.path.endsWith("init.js")) return;
|
|
367
|
-
let contents = readFileSync(args.path, "utf8");
|
|
368
|
-
contents = contents.replace(
|
|
369
|
-
/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,
|
|
370
|
-
"// createRequire removed for brender build"
|
|
371
|
-
);
|
|
372
|
-
return { contents, loader: "js" };
|
|
373
|
-
});
|
|
374
|
-
build.onLoad({ filter: /fetch\/adapters\/supabase\.js$/ }, () => {
|
|
375
|
-
return {
|
|
376
|
-
contents: `export const setup = async () => null;
|
|
1
|
+
import{resolve as d,join as tt,dirname as P}from"path";import{existsSync as h,unlinkSync as _t,readFileSync as K,realpathSync as kt}from"fs";import{tmpdir as $t}from"os";import{randomBytes as Ct}from"crypto";import{createRequire as et}from"module";import{createEnv as nt}from"./env.js";import{resetKeys as st,assignKeys as rt,mapKeysToElements as it}from"./keys.js";import{extractMetadata as ct,generateHeadHtml as Tt}from"./metadata.js";import"./hydrate.js";import{prefetchPageData as Ot,injectPrefetchedState as Lt,fetchSSRTranslations as At}from"./prefetch.js";let z=null;const It=async()=>{if(z)return z;try{return z=(await import("@symbo.ls/funcql")).funcqlPlugin,z}catch{return null}};import"linkedom";import{reset as qt}from"@symbo.ls/css";const ot=(t,e)=>{if(!t||!e)return;if(t[e]!==void 0)return t[e];const o=e.split(".");let s=t;for(const r of o){if(s==null||typeof s!="object")return;s=s[r]}return s},Pt=function(t,e){if(!t)return"";const o=this?.context,s=o?.polyglot,r=e||s?.defaultLang||"en";if(s?.translations){const c=s.translations[r];if(c){const i=ot(c,t);if(i!==void 0)return i}}const p=this?.state?.root||o?.state?.root;if(p?.translations){const c=p.translations[r];if(c){const i=ot(c,t);if(i!==void 0)return i}}const f=s?.defaultLang||"en";if(f!==r&&s?.translations){const c=s.translations[f];if(c){const i=ot(c,t);if(i!==void 0)return i}}return t},lt=function(){const t=this?.context;return this?.state?.root?.lang||t?.polyglot?.defaultLang||"en"},D=(t,e=new WeakMap)=>{if(t===null||typeof t!="object")return t;if(e.has(t))return e.get(t);if(Array.isArray(t)){const s=[];e.set(t,s);for(const r of t)s.push(typeof r=="object"&&r!==null?D(r,e):r);return s}const o={};e.set(t,o);for(const s of Object.keys(t)){const r=t[s];o[s]=typeof r=="object"&&r!==null?D(r,e):r}return o},at=()=>{const t=new WeakSet;return(e,o)=>{if(typeof o!="function"){if(typeof o=="object"&&o!==null){if(t.has(o))return;t.add(o)}return o}}};let N=null;try{import.meta.url&&(N=et(import.meta.url))}catch{}const ft=()=>{if(!import.meta.url||!N)return{isMonorepo:!1,monorepoRoot:null,resolvePackage:i=>i};const t=kt(new URL(".",import.meta.url).pathname),e=d(t,"../..");if(h(d(e,"packages","smbls","src","createDomql.js")))return{isMonorepo:!0,monorepoRoot:e};let s;try{const i=N.resolve("smbls/package.json");s=P(i)}catch{let i=t;for(;i!==P(i);){const n=d(i,"node_modules","smbls");if(h(d(n,"package.json"))){s=n;break}i=P(i)}}let r=N;if(s)try{r=et(d(s,"package.json"))}catch{}let p,f=process.cwd();for(;f!==P(f);){if(h(d(f,"package.json"))){p=f;break}f=P(f)}let c=r;if(p)try{c=et(d(p,"package.json"))}catch{}return{isMonorepo:!1,smblsRoot:s,brenderDir:t,projectRoot:p,_smblsRequire:r,_projectRequire:c}},G=(t,e)=>{const o=t.isMonorepo?[N]:[t._smblsRequire,t._projectRequire,N].filter(Boolean);for(const s of o)try{return s.resolve(e)}catch{}return null},le=(t,e,...o)=>{if(t.isMonorepo)return d(t.monorepoRoot,"packages",e,...o);const s=G(t,`${e}/package.json`);return s?d(P(s),...o):null},ae=(t,e,...o)=>{if(t.isMonorepo)return d(t.monorepoRoot,"plugins",e,...o);const s=G(t,`@symbo.ls/${e}/package.json`);return s?d(P(s),...o):null},H=(t,e,...o)=>{if(t.isMonorepo){for(const r of["packages","plugins"]){const p=d(t.monorepoRoot,r,e,...o);if(h(p))return p}return null}const s=G(t,`@symbo.ls/${e}/package.json`);return s?d(P(s),...o):null},Y=(t,e,...o)=>{if(t.isMonorepo)return d(t.monorepoRoot,"packages","domql","packages",e,...o);const s=G(t,`@symbo.ls/${e}/package.json`);return s?d(P(s),...o):null};let Z=null;const vt=async()=>{if(Z)return Z;const t=ft();if(!N)try{const c=await import("./dist/createDomql.bundled.mjs");return Z=c,c}catch(c){throw new Error(`brender: pre-bundled createDomql not available in bundled runtime: ${c.message}`)}let e;if(t.isMonorepo)e=d(t.monorepoRoot,"packages","smbls","src","createDomql.js");else if(t.smblsRoot){const c=d(t.smblsRoot,"src","createDomql.js"),i=d(t.smblsRoot,"dist","esm","src","createDomql.js");e=h(c)?c:i}if(!e||!h(e))throw new Error(`brender: cannot find createDomql.js (isMonorepo=${t.isMonorepo}, entry=${e})`);const o=await import("esbuild"),s=tt($t(),`br_createDomql_${Ct(6).toString("hex")}.mjs`),r=c=>{if(!c)return null;const i=d(c,"src","index.js");if(h(i))return i;const n=d(c,"index.js");return h(n)?n:null},p={name:"workspace-resolve",setup(c){c.onResolve({filter:/^smbls/},i=>{const n=i.path.replace(/^smbls\/?/,""),l=t.isMonorepo?d(t.monorepoRoot,"packages","smbls"):t.smblsRoot;if(!l)return;if(!n){const m=r(l);return m?{path:m}:void 0}const u=d(l,n);if(h(u))return{path:u};if(h(u+".js"))return{path:u+".js"};const a=d(u,"index.js");if(h(a))return{path:a}}),c.onResolve({filter:/^domql$/},i=>{if(t.isMonorepo){const n=d(t.monorepoRoot,"packages","domql","src","index.js");if(h(n))return{path:n};const l=d(t.monorepoRoot,"packages","domql","index.js");if(h(l))return{path:l}}else try{const n=_require.resolve("domql/package.json"),l=r(P(n));if(l)return{path:l}}catch{}}),c.onResolve({filter:/^@symbo\.ls\//},i=>{const n=i.path.replace("@symbo.ls/","");if(n==="sync")return{path:"sync-stub",namespace:"brender-stub"};if(t.isMonorepo){for(const u of["packages","plugins"]){const a=d(t.monorepoRoot,u,n,"src","index.js");if(h(a))return{path:a};const m=d(t.monorepoRoot,u,n,"index.js");if(h(m))return{path:m}}const l=d(t.monorepoRoot,"packages","default-config","blank","index.js");if(n==="default-config"&&h(l))return{path:l}}else{const l=H(t,n,"src","index.js");if(l&&h(l))return{path:l};const u=H(t,n,"index.js");if(u&&h(u))return{path:u};if(n==="default-config"){const a=H(t,"default-config","blank","index.js");if(a&&h(a))return{path:a}}}}),c.onResolve({filter:/^@domql\//},i=>{const n=i.path.replace("@symbo.ls/","");if(t.isMonorepo){const l=d(t.monorepoRoot,"packages","domql","packages",n,"src","index.js");if(h(l))return{path:l};const u=d(t.monorepoRoot,"packages","domql","packages",n,"index.js");if(h(u))return{path:u}}else{const l=Y(t,n,"src","index.js");if(l&&h(l))return{path:l};const u=Y(t,n,"index.js");if(u&&h(u))return{path:u}}}),c.onResolve({filter:/^css-in-props/},i=>{let n;if(t.isMonorepo)n=d(t.monorepoRoot,"packages","css-in-props");else{const a=G(t,"css-in-props/package.json");a&&(n=P(a))}if(!n)return;const l=i.path.replace(/^css-in-props\/?/,"");if(l){const a=d(n,l),m=d(a,"index.js");if(h(m))return{path:m};if(h(a+".js"))return{path:a+".js"};if(h(a))return{path:a}}const u=r(n);if(u)return{path:u}}),c.onResolve({filter:/^@emotion\//},i=>{let n;if(t.isMonorepo)n=d(t.monorepoRoot,"node_modules",i.path);else{const l=G(t,`${i.path}/package.json`);if(!l)return;n=P(l)}if(h(n)){const l=d(n,"package.json");if(h(l))try{const u=JSON.parse(K(l,"utf8")),a=u.module||u.main||"dist/emotion-css.esm.js";return{path:d(n,a)}}catch{}return{path:n}}}),c.onResolve({filter:/\.json$/},i=>{if(i.resolveDir){const n=d(i.resolveDir,i.path);if(h(n))return{path:n}}}),c.onLoad({filter:/smbls\/.*options\.js$/},async i=>{if(!i.path.includes("smbls/")||!i.path.endsWith("options.js"))return;let n=K(i.path,"utf8");return n=n.replace(/import\s*\{[^}]*version[^}]*\}\s*from\s*['"][^'"]*package\.json['"][^;\n]*/,"const version = '0.0.0'"),n=n.replace(/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,"// createRequire removed for brender build"),{contents:n,loader:"js"}}),c.onLoad({filter:/smbls\/.*init\.js$/},async i=>{if(!i.path.includes("smbls/")||!i.path.endsWith("init.js"))return;let n=K(i.path,"utf8");return n=n.replace(/import\s*\{[^}]*createRequire[^}]*\}\s*from\s*['"]module['"][^;\n]*/g,"// createRequire removed for brender build"),{contents:n,loader:"js"}}),c.onLoad({filter:/fetch\/adapters\/supabase\.js$/},()=>({contents:`export const setup = async () => null;
|
|
377
2
|
export const supabaseAdapter = () => ({name:'supabase'});
|
|
378
|
-
`,
|
|
379
|
-
loader: "js"
|
|
380
|
-
};
|
|
381
|
-
});
|
|
382
|
-
build.onLoad({ filter: /.*/, namespace: "brender-stub" }, () => {
|
|
383
|
-
return { contents: "export const SyncComponent = {}; export const Inspect = {}; export const Notifications = {}; export default {}", loader: "js" };
|
|
384
|
-
});
|
|
385
|
-
build.onLoad({ filter: /smbls\/src\/router\.js$/ }, async (args) => {
|
|
386
|
-
let contents = readFileSync(args.path, "utf8");
|
|
387
|
-
contents = contents.replace(
|
|
388
|
-
/import\s*\{\s*Link\s*\}\s*from\s*['"]smbls['"]/,
|
|
389
|
-
`const Link = { tag: 'a', attr: { href: (el) => el.href } }`
|
|
390
|
-
);
|
|
391
|
-
return { contents, loader: "js" };
|
|
392
|
-
});
|
|
393
|
-
build.onLoad({ filter: /fetchOnCreate\.js$/ }, async (args) => {
|
|
394
|
-
if (!args.path.includes("smbls/")) return;
|
|
395
|
-
let contents = readFileSync(args.path, "utf8");
|
|
396
|
-
contents = contents.replace(
|
|
397
|
-
/window\s*&&\s*window\.location\s*\?\s*window\.location\.host\.includes/g,
|
|
398
|
-
"window && window.location && window.location.host ? window.location.host.includes"
|
|
399
|
-
);
|
|
400
|
-
return { contents, loader: "js" };
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
await esbuild.build({
|
|
405
|
-
entryPoints: [entry],
|
|
406
|
-
bundle: true,
|
|
407
|
-
format: "esm",
|
|
408
|
-
platform: "node",
|
|
409
|
-
outfile: outFile,
|
|
410
|
-
write: true,
|
|
411
|
-
logLevel: "warning",
|
|
412
|
-
plugins: [workspacePlugin],
|
|
413
|
-
nodePaths: ws.isMonorepo ? [resolve(ws.monorepoRoot, "node_modules")] : [
|
|
414
|
-
...ws.smblsRoot ? [resolve(ws.smblsRoot, "node_modules")] : [],
|
|
415
|
-
...ws.projectRoot ? [resolve(ws.projectRoot, "node_modules")] : [],
|
|
416
|
-
...ws.smblsRoot ? [resolve(ws.smblsRoot, "..", "..", "node_modules")] : []
|
|
417
|
-
].filter((p) => existsSync(p)),
|
|
418
|
-
supported: { "import-attributes": false },
|
|
419
|
-
external: [
|
|
420
|
-
"fs",
|
|
421
|
-
"path",
|
|
422
|
-
"os",
|
|
423
|
-
"crypto",
|
|
424
|
-
"url",
|
|
425
|
-
"http",
|
|
426
|
-
"https",
|
|
427
|
-
"stream",
|
|
428
|
-
"util",
|
|
429
|
-
"events",
|
|
430
|
-
"buffer",
|
|
431
|
-
"child_process",
|
|
432
|
-
"worker_threads",
|
|
433
|
-
"net",
|
|
434
|
-
"tls",
|
|
435
|
-
"dns",
|
|
436
|
-
"dgram",
|
|
437
|
-
"zlib",
|
|
438
|
-
"assert",
|
|
439
|
-
"querystring",
|
|
440
|
-
"string_decoder",
|
|
441
|
-
"readline",
|
|
442
|
-
"perf_hooks",
|
|
443
|
-
"async_hooks",
|
|
444
|
-
"v8",
|
|
445
|
-
"vm",
|
|
446
|
-
"cluster",
|
|
447
|
-
"inspector",
|
|
448
|
-
"module",
|
|
449
|
-
"process",
|
|
450
|
-
"tty",
|
|
451
|
-
"color-contrast-checker",
|
|
452
|
-
"linkedom"
|
|
453
|
-
]
|
|
454
|
-
});
|
|
455
|
-
const mod = await import(`file://${outFile}`);
|
|
456
|
-
if (!process.env.BRENDER_DEBUG) {
|
|
457
|
-
try {
|
|
458
|
-
unlinkSync(outFile);
|
|
459
|
-
} catch {
|
|
460
|
-
}
|
|
461
|
-
} else {
|
|
462
|
-
console.log("[brender] Bundle saved:", outFile);
|
|
463
|
-
}
|
|
464
|
-
_cachedCreateDomql = mod;
|
|
465
|
-
return mod;
|
|
466
|
-
};
|
|
467
|
-
const UIKIT_STUBS = {
|
|
468
|
-
Box: {},
|
|
469
|
-
Focusable: {},
|
|
470
|
-
Block: { display: "block" },
|
|
471
|
-
Inline: { display: "inline" },
|
|
472
|
-
Flex: { display: "flex" },
|
|
473
|
-
InlineFlex: { display: "inline-flex" },
|
|
474
|
-
Grid: { display: "grid" },
|
|
475
|
-
InlineGrid: { display: "inline-grid" },
|
|
476
|
-
Link: {
|
|
477
|
-
tag: "a",
|
|
478
|
-
attr: {
|
|
479
|
-
href: (el) => el.href,
|
|
480
|
-
target: (el) => el.target,
|
|
481
|
-
rel: (el) => el.rel
|
|
482
|
-
}
|
|
483
|
-
},
|
|
484
|
-
A: { extends: "Link" },
|
|
485
|
-
RouteLink: { extends: "Link" },
|
|
486
|
-
Img: {
|
|
487
|
-
tag: "img",
|
|
488
|
-
attr: {
|
|
489
|
-
src: (el) => {
|
|
490
|
-
let src = el.src;
|
|
491
|
-
if (typeof src === "string" && src.includes("{{")) {
|
|
492
|
-
src = el.call("replaceLiteralsWithObjectFields", src, el.state);
|
|
493
|
-
}
|
|
494
|
-
return src;
|
|
495
|
-
},
|
|
496
|
-
alt: (el) => el.alt,
|
|
497
|
-
loading: (el) => el.loading
|
|
498
|
-
}
|
|
499
|
-
},
|
|
500
|
-
Image: { extends: "Img" },
|
|
501
|
-
Button: { tag: "button" },
|
|
502
|
-
FocusableComponent: { tag: "button" },
|
|
503
|
-
Form: { tag: "form" },
|
|
504
|
-
Input: { tag: "input" },
|
|
505
|
-
TextArea: { tag: "textarea" },
|
|
506
|
-
Textarea: { tag: "textarea" },
|
|
507
|
-
Select: { tag: "select" },
|
|
508
|
-
Label: { tag: "label" },
|
|
509
|
-
Iframe: { tag: "iframe" },
|
|
510
|
-
Video: { tag: "video" },
|
|
511
|
-
Audio: { tag: "audio" },
|
|
512
|
-
Canvas: { tag: "canvas" },
|
|
513
|
-
Span: { tag: "span" },
|
|
514
|
-
P: { tag: "p" },
|
|
515
|
-
H1: { tag: "h1" },
|
|
516
|
-
H2: { tag: "h2" },
|
|
517
|
-
H3: { tag: "h3" },
|
|
518
|
-
H4: { tag: "h4" },
|
|
519
|
-
H5: { tag: "h5" },
|
|
520
|
-
H6: { tag: "h6" },
|
|
521
|
-
Svg: {
|
|
522
|
-
tag: "svg",
|
|
523
|
-
attr: {
|
|
524
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
525
|
-
"xmlns:xlink": "http://www.w3.org/1999/xlink"
|
|
526
|
-
}
|
|
527
|
-
},
|
|
528
|
-
Text: { tag: "span" }
|
|
529
|
-
};
|
|
530
|
-
const buildPathRegistry = (element, path = "") => {
|
|
531
|
-
if (!element || !element.__ref) return {};
|
|
532
|
-
const registry = {};
|
|
533
|
-
const brKey = element.__ref.__brKey;
|
|
534
|
-
if (brKey) registry[path === "" ? "__root" : path] = brKey;
|
|
535
|
-
if (element.__ref.__children) {
|
|
536
|
-
for (const childKey of element.__ref.__children) {
|
|
537
|
-
const child = element[childKey];
|
|
538
|
-
if (child && child.__ref) {
|
|
539
|
-
const childPath = path === "" ? childKey : `${path}.${childKey}`;
|
|
540
|
-
Object.assign(registry, buildPathRegistry(child, childPath));
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
return registry;
|
|
545
|
-
};
|
|
546
|
-
const render = async (data, options = {}) => {
|
|
547
|
-
const { route = "/", pathname, state: stateOverrides, context: contextOverrides, prefetch = false } = options;
|
|
548
|
-
const locationPath = pathname || route;
|
|
549
|
-
const _prevLocPrefetch = globalThis.location;
|
|
550
|
-
const _prevWinPrefetch = globalThis.window;
|
|
551
|
-
if (!globalThis.location || globalThis.location.pathname !== locationPath) {
|
|
552
|
-
globalThis.location = { pathname: locationPath, href: locationPath, search: "", hash: "", origin: "" };
|
|
553
|
-
}
|
|
554
|
-
if (!globalThis.window) {
|
|
555
|
-
globalThis.window = { location: globalThis.location };
|
|
556
|
-
}
|
|
557
|
-
let prefetchedPages;
|
|
558
|
-
if (prefetch) {
|
|
559
|
-
try {
|
|
560
|
-
const pages = data.pages || {};
|
|
561
|
-
prefetchedPages = { ...pages };
|
|
562
|
-
const stateUpdates = await prefetchPageData(data, route);
|
|
563
|
-
if (stateUpdates.size) {
|
|
564
|
-
const pageDef = JSON.parse(JSON.stringify(pages[route], (key, value) => {
|
|
565
|
-
if (typeof value === "function") return void 0;
|
|
566
|
-
return value;
|
|
567
|
-
}));
|
|
568
|
-
const copyFunctions = (src, dst) => {
|
|
569
|
-
if (!src || !dst) return;
|
|
570
|
-
for (const k in src) {
|
|
571
|
-
if (typeof src[k] === "function") {
|
|
572
|
-
dst[k] = src[k];
|
|
573
|
-
} else if (typeof src[k] === "object" && src[k] !== null && !Array.isArray(src[k]) && typeof dst[k] === "object" && dst[k] !== null) {
|
|
574
|
-
copyFunctions(src[k], dst[k]);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
copyFunctions(pages[route], pageDef);
|
|
579
|
-
injectPrefetchedState(pageDef, stateUpdates);
|
|
580
|
-
prefetchedPages[route] = pageDef;
|
|
581
|
-
}
|
|
582
|
-
} catch (prefetchErr) {
|
|
583
|
-
console.error("[brender] Prefetch error:", prefetchErr);
|
|
584
|
-
prefetchedPages = data.pages;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
let ssrTranslations;
|
|
588
|
-
if (prefetch) {
|
|
589
|
-
try {
|
|
590
|
-
ssrTranslations = await fetchSSRTranslations(data);
|
|
591
|
-
} catch (e) {
|
|
592
|
-
console.warn("[brender] SSR translation fetch failed:", e.message);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
if (_prevLocPrefetch !== void 0) globalThis.location = _prevLocPrefetch;
|
|
596
|
-
else delete globalThis.location;
|
|
597
|
-
if (_prevWinPrefetch !== void 0) globalThis.window = _prevWinPrefetch;
|
|
598
|
-
else delete globalThis.window;
|
|
599
|
-
const { window, document } = createEnv();
|
|
600
|
-
const body = document.body;
|
|
601
|
-
window.location.pathname = locationPath;
|
|
602
|
-
const _prevDoc = globalThis.document;
|
|
603
|
-
const _prevLoc = globalThis.location;
|
|
604
|
-
globalThis.document = document;
|
|
605
|
-
globalThis.location = window.location;
|
|
606
|
-
const { createDomqlElement } = await bundleCreateDomql();
|
|
607
|
-
const app = structuredCloneDeep(data.app || {});
|
|
608
|
-
const config = { ...data.config || {} };
|
|
609
|
-
if (data.polyglot && !config.polyglot) config.polyglot = data.polyglot;
|
|
610
|
-
if (data.fetch && !config.fetch) config.fetch = data.fetch;
|
|
611
|
-
if (data.router && !config.router) config.router = data.router;
|
|
612
|
-
for (const k of ["useReset", "useVariable", "useFontImport", "useIconSprite", "useSvgSprite", "useDefaultConfig", "useDocumentTheme"]) {
|
|
613
|
-
if (data[k] != null && config[k] == null) config[k] = data[k];
|
|
614
|
-
}
|
|
615
|
-
const polyglotConfig = config.polyglot ? { ...config.polyglot } : void 0;
|
|
616
|
-
if (ssrTranslations && polyglotConfig) {
|
|
617
|
-
polyglotConfig.translations = {
|
|
618
|
-
...polyglotConfig.translations || {},
|
|
619
|
-
...ssrTranslations
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
const baseState = structuredCloneDeep(data.state || {});
|
|
623
|
-
if (ssrTranslations || polyglotConfig) {
|
|
624
|
-
if (!baseState.root) baseState.root = {};
|
|
625
|
-
if (polyglotConfig) {
|
|
626
|
-
baseState.root.lang = baseState.root.lang || polyglotConfig.defaultLang || "en";
|
|
627
|
-
}
|
|
628
|
-
if (ssrTranslations) {
|
|
629
|
-
baseState.root.translations = {
|
|
630
|
-
...baseState.root.translations || {},
|
|
631
|
-
...ssrTranslations
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
resetCss();
|
|
636
|
-
const ctx = {
|
|
637
|
-
state: baseState,
|
|
638
|
-
...stateOverrides ? { state: { ...baseState, ...stateOverrides } } : {},
|
|
639
|
-
dependencies: structuredCloneDeep(data.dependencies || {}),
|
|
640
|
-
components: structuredCloneDeep(data.components || {}),
|
|
641
|
-
snippets: structuredCloneDeep(data.snippets || {}),
|
|
642
|
-
pages: structuredCloneDeep(prefetchedPages || data.pages || {}),
|
|
643
|
-
functions: {
|
|
644
|
-
...data.functions || {},
|
|
645
|
-
// SSR polyglot functions — enable {{ key | polyglot }} resolution during render
|
|
646
|
-
polyglot: ssrTranslate,
|
|
647
|
-
getActiveLang: ssrGetActiveLang,
|
|
648
|
-
getLang: ssrGetActiveLang
|
|
649
|
-
},
|
|
650
|
-
methods: data.methods || {},
|
|
651
|
-
designSystem: structuredCloneDeep(data.designSystem || {}),
|
|
652
|
-
files: data.files || {},
|
|
653
|
-
sharedLibraries: data.sharedLibraries || [],
|
|
654
|
-
...config,
|
|
655
|
-
// Override polyglot with SSR-enriched version
|
|
656
|
-
...polyglotConfig ? { polyglot: polyglotConfig } : {},
|
|
657
|
-
// Virtual DOM environment
|
|
658
|
-
document,
|
|
659
|
-
window,
|
|
660
|
-
parent: { node: body },
|
|
661
|
-
initOptions: {},
|
|
662
|
-
// Disable sourcemap tracking in SSR — it causes stack overflows
|
|
663
|
-
// when state contains large data arrays (articles, events, etc.)
|
|
664
|
-
domqlOptions: { sourcemap: false },
|
|
665
|
-
// Caller overrides
|
|
666
|
-
...contextOverrides || {}
|
|
667
|
-
};
|
|
668
|
-
const funcql = await getFuncqlPlugin();
|
|
669
|
-
if (funcql) {
|
|
670
|
-
ctx.plugins = ctx.plugins || [];
|
|
671
|
-
if (!ctx.plugins.some((p) => p.name === "funcql")) {
|
|
672
|
-
ctx.plugins.push(funcql);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
resetKeys();
|
|
676
|
-
const element = await createDomqlElement(app, ctx);
|
|
677
|
-
const flushDelay = prefetch ? 2e3 : 50;
|
|
678
|
-
await new Promise((r) => setTimeout(r, flushDelay));
|
|
679
|
-
assignKeys(body);
|
|
680
|
-
const registry = mapKeysToElements(element);
|
|
681
|
-
const brRegistry = buildPathRegistry(element);
|
|
682
|
-
const metadata = extractMetadata(data, route, element, element?.state);
|
|
683
|
-
const emotionCSS = [];
|
|
684
|
-
const head = document.head || document.querySelector("head");
|
|
685
|
-
if (head) {
|
|
686
|
-
for (const style of head.querySelectorAll("style")) {
|
|
687
|
-
if (style.sheet && style.sheet.cssRules) {
|
|
688
|
-
for (const rule of style.sheet.cssRules) {
|
|
689
|
-
if (rule.cssText) emotionCSS.push(rule.cssText);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
if (!emotionCSS.length) {
|
|
693
|
-
const content = style.textContent || "";
|
|
694
|
-
if (content) emotionCSS.push(content);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
let html = fixSvgContent(body.innerHTML);
|
|
699
|
-
if (ssrTranslations) {
|
|
700
|
-
const defaultLang = polyglotConfig?.defaultLang || "en";
|
|
701
|
-
const langMap = ssrTranslations[defaultLang] || Object.values(ssrTranslations)[0] || {};
|
|
702
|
-
html = html.replace(/\{\{\s*([^|{}]+?)\s*\|\s*polyglot\s*\}\}/g, (match, key) => {
|
|
703
|
-
const trimmed = key.trim();
|
|
704
|
-
return langMap[trimmed] ?? match;
|
|
705
|
-
});
|
|
706
|
-
}
|
|
707
|
-
if (_prevDoc !== void 0) globalThis.document = _prevDoc;
|
|
708
|
-
else delete globalThis.document;
|
|
709
|
-
if (_prevLoc !== void 0) globalThis.location = _prevLoc;
|
|
710
|
-
else delete globalThis.location;
|
|
711
|
-
return { html, metadata, registry, brRegistry, element, emotionCSS, document, window, ssrTranslations, prefetchedPages };
|
|
712
|
-
};
|
|
713
|
-
const renderElement = async (elementDef, options = {}) => {
|
|
714
|
-
const { context = {} } = options;
|
|
715
|
-
const { window, document } = createEnv();
|
|
716
|
-
const body = document.body;
|
|
717
|
-
const { create } = await import("@symbo.ls/element");
|
|
718
|
-
const domqlUtils = await import("@symbo.ls/utils");
|
|
719
|
-
const components = { ...UIKIT_STUBS, ...context.components || {} };
|
|
720
|
-
const utils = {
|
|
721
|
-
...domqlUtils,
|
|
722
|
-
...context.utils || {},
|
|
723
|
-
...context.functions || {}
|
|
724
|
-
};
|
|
725
|
-
resetKeys();
|
|
726
|
-
let element;
|
|
727
|
-
try {
|
|
728
|
-
element = create(elementDef, { node: body }, "root", {
|
|
729
|
-
context: { document, window, ...context, components, utils }
|
|
730
|
-
});
|
|
731
|
-
} catch (err) {
|
|
732
|
-
}
|
|
733
|
-
assignKeys(body);
|
|
734
|
-
const registry = element ? mapKeysToElements(element) : {};
|
|
735
|
-
const html = fixSvgContent(body.innerHTML);
|
|
736
|
-
return { html, registry, element };
|
|
737
|
-
};
|
|
738
|
-
const fixSvgContent = (html) => {
|
|
739
|
-
return html.replace(
|
|
740
|
-
/(<svg\b[^>]*>)([\s\S]*?)(<\/svg>)/gi,
|
|
741
|
-
(match, open, content, close) => {
|
|
742
|
-
if (content.includes("<")) {
|
|
743
|
-
const unescaped = content.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'");
|
|
744
|
-
return open + unescaped + close;
|
|
745
|
-
}
|
|
746
|
-
return match;
|
|
747
|
-
}
|
|
748
|
-
);
|
|
749
|
-
};
|
|
750
|
-
let _cachedGlobalCSS = null;
|
|
751
|
-
const SCRATCH_CONFIG_FLAGS = [
|
|
752
|
-
"globalTheme",
|
|
753
|
-
"themeStorageKey",
|
|
754
|
-
"themeRoot",
|
|
755
|
-
"useReset",
|
|
756
|
-
"useVariable",
|
|
757
|
-
"useFontImport",
|
|
758
|
-
"useIconSprite",
|
|
759
|
-
"useSvgSprite",
|
|
760
|
-
"useDocumentTheme",
|
|
761
|
-
"useDefaultConfig",
|
|
762
|
-
"useDefaultIcons",
|
|
763
|
-
"useThemeSuffixedVars",
|
|
764
|
-
"verbose",
|
|
765
|
-
"semanticIcons"
|
|
766
|
-
];
|
|
767
|
-
const pickProjectConfig = (data) => {
|
|
768
|
-
if (!data || typeof data !== "object") return null;
|
|
769
|
-
if (data.config && typeof data.config === "object") return data.config;
|
|
770
|
-
const out = {};
|
|
771
|
-
let any = false;
|
|
772
|
-
for (const flag of SCRATCH_CONFIG_FLAGS) {
|
|
773
|
-
if (Object.prototype.hasOwnProperty.call(data, flag)) {
|
|
774
|
-
out[flag] = data[flag];
|
|
775
|
-
any = true;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
if (any) return out;
|
|
779
|
-
return data.settings || null;
|
|
780
|
-
};
|
|
781
|
-
const generateGlobalCSS = async (ds, config) => {
|
|
782
|
-
if (_cachedGlobalCSS) return _cachedGlobalCSS;
|
|
783
|
-
try {
|
|
784
|
-
const { existsSync: existsSync2, writeFileSync: writeFileSync2, unlinkSync: unlinkSync2 } = await import("fs");
|
|
785
|
-
const { tmpdir: tmpdir2 } = await import("os");
|
|
786
|
-
const { randomBytes: randomBytes2 } = await import("crypto");
|
|
787
|
-
try {
|
|
788
|
-
tmpdir2();
|
|
789
|
-
} catch {
|
|
790
|
-
return {};
|
|
791
|
-
}
|
|
792
|
-
const esbuild = await import("esbuild");
|
|
793
|
-
const dsJson = JSON.stringify(ds || {}, safeJsonReplacer());
|
|
794
|
-
const cfgJson = JSON.stringify(config || {}, safeJsonReplacer());
|
|
795
|
-
const tmpEntry = join(tmpdir2(), `br_global_${randomBytes2(6).toString("hex")}.mjs`);
|
|
796
|
-
const tmpOut = join(tmpdir2(), `br_global_${randomBytes2(6).toString("hex")}_out.mjs`);
|
|
797
|
-
writeFileSync2(tmpEntry, `
|
|
3
|
+
`,loader:"js"})),c.onLoad({filter:/.*/,namespace:"brender-stub"},()=>({contents:"export const SyncComponent = {}; export const Inspect = {}; export const Notifications = {}; export default {}",loader:"js"})),c.onLoad({filter:/smbls\/src\/router\.js$/},async i=>{let n=K(i.path,"utf8");return n=n.replace(/import\s*\{\s*Link\s*\}\s*from\s*['"]smbls['"]/,"const Link = { tag: 'a', attr: { href: (el) => el.href } }"),{contents:n,loader:"js"}}),c.onLoad({filter:/fetchOnCreate\.js$/},async i=>{if(!i.path.includes("smbls/"))return;let n=K(i.path,"utf8");return n=n.replace(/window\s*&&\s*window\.location\s*\?\s*window\.location\.host\.includes/g,"window && window.location && window.location.host ? window.location.host.includes"),{contents:n,loader:"js"}})}};await o.build({entryPoints:[e],bundle:!0,format:"esm",platform:"node",outfile:s,write:!0,logLevel:"warning",plugins:[p],nodePaths:t.isMonorepo?[d(t.monorepoRoot,"node_modules")]:[...t.smblsRoot?[d(t.smblsRoot,"node_modules")]:[],...t.projectRoot?[d(t.projectRoot,"node_modules")]:[],...t.smblsRoot?[d(t.smblsRoot,"..","..","node_modules")]:[]].filter(c=>h(c)),supported:{"import-attributes":!1},external:["fs","path","os","crypto","url","http","https","stream","util","events","buffer","child_process","worker_threads","net","tls","dns","dgram","zlib","assert","querystring","string_decoder","readline","perf_hooks","async_hooks","v8","vm","cluster","inspector","module","process","tty","color-contrast-checker","linkedom"]});const f=await import(`file://${s}`);if(process.env.BRENDER_DEBUG)console.log("[brender] Bundle saved:",s);else try{_t(s)}catch{}return Z=f,f},Et={Box:{},Focusable:{},Block:{display:"block"},Inline:{display:"inline"},Flex:{display:"flex"},InlineFlex:{display:"inline-flex"},Grid:{display:"grid"},InlineGrid:{display:"inline-grid"},Link:{tag:"a",attr:{href:t=>t.href,target:t=>t.target,rel:t=>t.rel}},A:{extends:"Link"},RouteLink:{extends:"Link"},Img:{tag:"img",attr:{src:t=>{let e=t.src;return typeof e=="string"&&e.includes("{{")&&(e=t.call("replaceLiteralsWithObjectFields",e,t.state)),e},alt:t=>t.alt,loading:t=>t.loading}},Image:{extends:"Img"},Button:{tag:"button"},FocusableComponent:{tag:"button"},Form:{tag:"form"},Input:{tag:"input"},TextArea:{tag:"textarea"},Textarea:{tag:"textarea"},Select:{tag:"select"},Label:{tag:"label"},Iframe:{tag:"iframe"},Video:{tag:"video"},Audio:{tag:"audio"},Canvas:{tag:"canvas"},Span:{tag:"span"},P:{tag:"p"},H1:{tag:"h1"},H2:{tag:"h2"},H3:{tag:"h3"},H4:{tag:"h4"},H5:{tag:"h5"},H6:{tag:"h6"},Svg:{tag:"svg",attr:{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}},Text:{tag:"span"}},ut=(t,e="")=>{if(!t||!t.__ref)return{};const o={},s=t.__ref.__brKey;if(s&&(o[e===""?"__root":e]=s),t.__ref.__children)for(const r of t.__ref.__children){const p=t[r];if(p&&p.__ref){const f=e===""?r:`${e}.${r}`;Object.assign(o,ut(p,f))}}return o},pt=async(t,e={})=>{const{route:o="/",pathname:s,state:r,context:p,prefetch:f=!1}=e,c=s||o,i=globalThis.location,n=globalThis.window;(!globalThis.location||globalThis.location.pathname!==c)&&(globalThis.location={pathname:c,href:c,search:"",hash:"",origin:""}),globalThis.window||(globalThis.window={location:globalThis.location});let l;if(f)try{const b=t.pages||{};l={...b};const E=await Ot(t,o);if(E.size){const V=JSON.parse(JSON.stringify(b[o],(v,B)=>{if(typeof B!="function")return B})),U=(v,B)=>{if(!(!v||!B))for(const M in v)typeof v[M]=="function"?B[M]=v[M]:typeof v[M]=="object"&&v[M]!==null&&!Array.isArray(v[M])&&typeof B[M]=="object"&&B[M]!==null&&U(v[M],B[M])};U(b[o],V),Lt(V,E),l[o]=V}}catch(b){console.error("[brender] Prefetch error:",b),l=t.pages}let u;if(f)try{u=await At(t)}catch(b){console.warn("[brender] SSR translation fetch failed:",b.message)}i!==void 0?globalThis.location=i:delete globalThis.location,n!==void 0?globalThis.window=n:delete globalThis.window;const{window:a,document:m}=nt(),_=m.body;a.location.pathname=c;const y=globalThis.document,g=globalThis.location;globalThis.document=m,globalThis.location=a.location;const{createDomqlElement:q}=await vt(),L=D(t.app||{}),R={...t.config||{}};t.polyglot&&!R.polyglot&&(R.polyglot=t.polyglot),t.fetch&&!R.fetch&&(R.fetch=t.fetch),t.router&&!R.router&&(R.router=t.router);for(const b of["useReset","useVariable","useFontImport","useIconSprite","useSvgSprite","useDefaultConfig","useDocumentTheme"])t[b]!=null&&R[b]==null&&(R[b]=t[b]);const k=R.polyglot?{...R.polyglot}:void 0;u&&k&&(k.translations={...k.translations||{},...u});const O=D(t.state||{});(u||k)&&(O.root||(O.root={}),k&&(O.root.lang=O.root.lang||k.defaultLang||"en"),u&&(O.root.translations={...O.root.translations||{},...u})),qt();const C={state:O,...r?{state:{...O,...r}}:{},dependencies:D(t.dependencies||{}),components:D(t.components||{}),snippets:D(t.snippets||{}),pages:D(l||t.pages||{}),functions:{...t.functions||{},polyglot:Pt,getActiveLang:lt,getLang:lt},methods:t.methods||{},designSystem:D(t.designSystem||{}),files:t.files||{},sharedLibraries:t.sharedLibraries||[],...R,...k?{polyglot:k}:{},document:m,window:a,parent:{node:_},initOptions:{},domqlOptions:{sourcemap:!1},...p||{}},F=await It();F&&(C.plugins=C.plugins||[],C.plugins.some(b=>b.name==="funcql")||C.plugins.push(F)),st();const A=await q(L,C),x=f?2e3:50;await new Promise(b=>setTimeout(b,x)),rt(_);const $=it(A),S=ut(A),w=ct(t,o,A,A?.state),j=[],T=m.head||m.querySelector("head");if(T)for(const b of T.querySelectorAll("style")){if(b.sheet&&b.sheet.cssRules)for(const E of b.sheet.cssRules)E.cssText&&j.push(E.cssText);if(!j.length){const E=b.textContent||"";E&&j.push(E)}}let I=dt(_.innerHTML);if(u){const b=k?.defaultLang||"en",E=u[b]||Object.values(u)[0]||{};I=I.replace(/\{\{\s*([^|{}]+?)\s*\|\s*polyglot\s*\}\}/g,(V,U)=>{const v=U.trim();return E[v]??V})}return y!==void 0?globalThis.document=y:delete globalThis.document,g!==void 0?globalThis.location=g:delete globalThis.location,{html:I,metadata:w,registry:$,brRegistry:S,element:A,emotionCSS:j,document:m,window:a,ssrTranslations:u,prefetchedPages:l}},fe=async(t,e={})=>{const{context:o={}}=e,{window:s,document:r}=nt(),p=r.body,{create:f}=await import("@symbo.ls/element"),c=await import("@symbo.ls/utils"),i={...Et,...o.components||{}},n={...c,...o.utils||{},...o.functions||{}};st();let l;try{l=f(t,{node:p},"root",{context:{document:r,window:s,...o,components:i,utils:n}})}catch{}rt(p);const u=l?it(l):{};return{html:dt(p.innerHTML),registry:u,element:l}},dt=t=>t.replace(/(<svg\b[^>]*>)([\s\S]*?)(<\/svg>)/gi,(e,o,s,r)=>{if(s.includes("<")){const p=s.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'");return o+p+r}return e});let W=null;const Mt=["globalTheme","themeStorageKey","themeRoot","useReset","useVariable","useFontImport","useIconSprite","useSvgSprite","useDocumentTheme","useDefaultConfig","useDefaultIcons","useThemeSuffixedVars","verbose","semanticIcons"],mt=t=>{if(!t||typeof t!="object")return null;if(t.config&&typeof t.config=="object")return t.config;const e={};let o=!1;for(const s of Mt)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s],o=!0);return o?e:t.settings||null},gt=async(t,e)=>{if(W)return W;try{const{existsSync:o,writeFileSync:s,unlinkSync:r}=await import("fs"),{tmpdir:p}=await import("os"),{randomBytes:f}=await import("crypto");try{p()}catch{return{}}const c=await import("esbuild"),i=JSON.stringify(t||{},at()),n=JSON.stringify(e||{},at()),l=tt(p(),`br_global_${f(6).toString("hex")}.mjs`),u=tt(p(),`br_global_${f(6).toString("hex")}_out.mjs`);s(l,`
|
|
798
4
|
import { set, getActiveConfig, getFontFaceString } from '@symbo.ls/scratch'
|
|
799
5
|
import { DEFAULT_CONFIG } from '@symbo.ls/default-config'
|
|
800
6
|
|
|
801
|
-
const ds = ${
|
|
802
|
-
const cfg = ${
|
|
7
|
+
const ds = ${i}
|
|
8
|
+
const cfg = ${n}
|
|
803
9
|
|
|
804
10
|
// Merge with defaults (same as initEmotion)
|
|
805
11
|
const merged = {}
|
|
@@ -832,237 +38,33 @@ const generateGlobalCSS = async (ds, config) => {
|
|
|
832
38
|
// Export as globalThis so we can read it
|
|
833
39
|
globalThis.__BR_GLOBAL_CSS__ = result
|
|
834
40
|
export default result
|
|
835
|
-
`);
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
build.onResolve({ filter: /^@symbo\.ls\// }, (args) => {
|
|
841
|
-
const pkg = args.path.replace("@symbo.ls/", "");
|
|
842
|
-
if (ws.isMonorepo) {
|
|
843
|
-
for (const dir of ["packages", "plugins"]) {
|
|
844
|
-
const src = resolve(ws.monorepoRoot, dir, pkg, "src", "index.js");
|
|
845
|
-
if (existsSync2(src)) return { path: src };
|
|
846
|
-
const dist = resolve(ws.monorepoRoot, dir, pkg, "index.js");
|
|
847
|
-
if (existsSync2(dist)) return { path: dist };
|
|
848
|
-
}
|
|
849
|
-
const blank = resolve(ws.monorepoRoot, "packages", "default-config", "blank", "index.js");
|
|
850
|
-
if (pkg === "default-config" && existsSync2(blank)) return { path: blank };
|
|
851
|
-
} else {
|
|
852
|
-
const resolved = resolveSymbolsPackage(ws, pkg, "src", "index.js");
|
|
853
|
-
if (resolved && existsSync2(resolved)) return { path: resolved };
|
|
854
|
-
const resolvedIdx = resolveSymbolsPackage(ws, pkg, "index.js");
|
|
855
|
-
if (resolvedIdx && existsSync2(resolvedIdx)) return { path: resolvedIdx };
|
|
856
|
-
if (pkg === "default-config") {
|
|
857
|
-
const blank = resolveSymbolsPackage(ws, "default-config", "blank", "index.js");
|
|
858
|
-
if (blank && existsSync2(blank)) return { path: blank };
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
});
|
|
862
|
-
build.onResolve({ filter: /^@domql\// }, (args) => {
|
|
863
|
-
const pkg = args.path.replace("@symbo.ls/", "");
|
|
864
|
-
if (ws.isMonorepo) {
|
|
865
|
-
const src = resolve(ws.monorepoRoot, "packages", "domql", "packages", pkg, "src", "index.js");
|
|
866
|
-
if (existsSync2(src)) return { path: src };
|
|
867
|
-
} else {
|
|
868
|
-
const resolved = resolveDomqlPackage(ws, pkg, "src", "index.js");
|
|
869
|
-
if (resolved && existsSync2(resolved)) return { path: resolved };
|
|
870
|
-
const resolvedIdx = resolveDomqlPackage(ws, pkg, "index.js");
|
|
871
|
-
if (resolvedIdx && existsSync2(resolvedIdx)) return { path: resolvedIdx };
|
|
872
|
-
}
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
};
|
|
876
|
-
await esbuild.build({
|
|
877
|
-
entryPoints: [tmpEntry],
|
|
878
|
-
bundle: true,
|
|
879
|
-
format: "esm",
|
|
880
|
-
platform: "node",
|
|
881
|
-
outfile: tmpOut,
|
|
882
|
-
write: true,
|
|
883
|
-
logLevel: "silent",
|
|
884
|
-
plugins: [workspacePlugin],
|
|
885
|
-
nodePaths: ws.isMonorepo ? [resolve(ws.monorepoRoot, "node_modules")] : [
|
|
886
|
-
...ws.smblsRoot ? [resolve(ws.smblsRoot, "node_modules")] : [],
|
|
887
|
-
...ws.projectRoot ? [resolve(ws.projectRoot, "node_modules")] : [],
|
|
888
|
-
...ws.smblsRoot ? [resolve(ws.smblsRoot, "..", "..", "node_modules")] : []
|
|
889
|
-
].filter((p) => existsSync2(p)),
|
|
890
|
-
external: ["fs", "path", "os", "crypto", "url", "http", "https", "stream", "util", "events", "buffer", "child_process", "worker_threads", "net", "tls", "dns", "dgram", "zlib", "assert", "querystring", "string_decoder", "readline", "perf_hooks", "async_hooks", "v8", "vm", "cluster", "inspector", "module", "process", "tty", "color-contrast-checker"]
|
|
891
|
-
});
|
|
892
|
-
const mod = await import(`file://${tmpOut}`);
|
|
893
|
-
const data = mod.default || {};
|
|
894
|
-
try {
|
|
895
|
-
unlinkSync2(tmpEntry);
|
|
896
|
-
} catch {
|
|
897
|
-
}
|
|
898
|
-
try {
|
|
899
|
-
unlinkSync2(tmpOut);
|
|
900
|
-
} catch {
|
|
901
|
-
}
|
|
902
|
-
const cssVars = data.CSS_VARS || {};
|
|
903
|
-
const cssMediaVars = data.CSS_MEDIA_VARS || {};
|
|
904
|
-
const reset = data.RESET || {};
|
|
905
|
-
const animations = data.ANIMATION || {};
|
|
906
|
-
const varDecls = Object.entries(cssVars).map(([k, v]) => ` ${k}: ${v}`).join(";\n");
|
|
907
|
-
let rootRule = varDecls ? `:root {
|
|
908
|
-
${varDecls};
|
|
909
|
-
}` : "";
|
|
910
|
-
const themeVarRules = Object.entries(cssMediaVars).map(([key, vars]) => {
|
|
911
|
-
const decls = Object.entries(vars).map(([k, v]) => ` ${k}: ${v}`).join(";\n");
|
|
912
|
-
if (!decls) return "";
|
|
913
|
-
if (key.startsWith("@media")) {
|
|
914
|
-
return `${key} {
|
|
41
|
+
`);const a=ft(),m={name:"workspace-resolve",setup(x){x.onResolve({filter:/^@symbo\.ls\//},$=>{const S=$.path.replace("@symbo.ls/","");if(a.isMonorepo){for(const j of["packages","plugins"]){const T=d(a.monorepoRoot,j,S,"src","index.js");if(o(T))return{path:T};const I=d(a.monorepoRoot,j,S,"index.js");if(o(I))return{path:I}}const w=d(a.monorepoRoot,"packages","default-config","blank","index.js");if(S==="default-config"&&o(w))return{path:w}}else{const w=H(a,S,"src","index.js");if(w&&o(w))return{path:w};const j=H(a,S,"index.js");if(j&&o(j))return{path:j};if(S==="default-config"){const T=H(a,"default-config","blank","index.js");if(T&&o(T))return{path:T}}}}),x.onResolve({filter:/^@domql\//},$=>{const S=$.path.replace("@symbo.ls/","");if(a.isMonorepo){const w=d(a.monorepoRoot,"packages","domql","packages",S,"src","index.js");if(o(w))return{path:w}}else{const w=Y(a,S,"src","index.js");if(w&&o(w))return{path:w};const j=Y(a,S,"index.js");if(j&&o(j))return{path:j}}})}};await c.build({entryPoints:[l],bundle:!0,format:"esm",platform:"node",outfile:u,write:!0,logLevel:"silent",plugins:[m],nodePaths:a.isMonorepo?[d(a.monorepoRoot,"node_modules")]:[...a.smblsRoot?[d(a.smblsRoot,"node_modules")]:[],...a.projectRoot?[d(a.projectRoot,"node_modules")]:[],...a.smblsRoot?[d(a.smblsRoot,"..","..","node_modules")]:[]].filter(x=>o(x)),external:["fs","path","os","crypto","url","http","https","stream","util","events","buffer","child_process","worker_threads","net","tls","dns","dgram","zlib","assert","querystring","string_decoder","readline","perf_hooks","async_hooks","v8","vm","cluster","inspector","module","process","tty","color-contrast-checker"]});const y=(await import(`file://${u}`)).default||{};try{r(l)}catch{}try{r(u)}catch{}const g=y.CSS_VARS||{},q=y.CSS_MEDIA_VARS||{},L=y.RESET||{},R=y.ANIMATION||{},k=Object.entries(g).map(([x,$])=>` ${x}: ${$}`).join(`;
|
|
42
|
+
`);let O=k?`:root {
|
|
43
|
+
${k};
|
|
44
|
+
}`:"";const C=Object.entries(q).map(([x,$])=>{const S=Object.entries($).map(([w,j])=>` ${w}: ${j}`).join(`;
|
|
45
|
+
`);return S?x.startsWith("@media")?`${x} {
|
|
915
46
|
:root:not([data-theme]) {
|
|
916
|
-
${
|
|
917
|
-
}
|
|
918
|
-
}`;
|
|
919
|
-
}
|
|
920
|
-
return `${key} {
|
|
921
|
-
${decls};
|
|
922
|
-
}`;
|
|
923
|
-
}).filter(Boolean).join("\n\n");
|
|
924
|
-
if (themeVarRules) rootRule += "\n\n" + themeVarRules;
|
|
925
|
-
const resetRules = generateResetCSS(reset);
|
|
926
|
-
const keyframeRules = [];
|
|
927
|
-
for (const name in animations) {
|
|
928
|
-
const frames = animations[name];
|
|
929
|
-
if (!frames || typeof frames !== "object") continue;
|
|
930
|
-
const frameRules = Object.entries(frames).map(([step, p]) => {
|
|
931
|
-
if (typeof p !== "object") return "";
|
|
932
|
-
const decls = Object.entries(p).map(([k, v]) => `${camelToKebab(k)}: ${v}`).join("; ");
|
|
933
|
-
return ` ${step} { ${decls}; }`;
|
|
934
|
-
}).join("\n");
|
|
935
|
-
keyframeRules.push(`@keyframes ${name} {
|
|
936
|
-
${frameRules}
|
|
937
|
-
}`);
|
|
938
|
-
}
|
|
939
|
-
_cachedGlobalCSS = {
|
|
940
|
-
rootRule,
|
|
941
|
-
resetRules,
|
|
942
|
-
fontFaceCSS: "",
|
|
943
|
-
keyframeRules: keyframeRules.join("\n")
|
|
944
|
-
};
|
|
945
|
-
return _cachedGlobalCSS;
|
|
946
|
-
} catch (err) {
|
|
947
|
-
console.warn("generateGlobalCSS failed:", err.message, err.stack);
|
|
948
|
-
_cachedGlobalCSS = { rootRule: "", resetRules: "", fontFaceCSS: "", keyframeRules: "" };
|
|
949
|
-
return _cachedGlobalCSS;
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
let _accumulatedEmotionCSS = /* @__PURE__ */ new Set();
|
|
953
|
-
const resetGlobalCSSCache = () => {
|
|
954
|
-
_cachedGlobalCSS = null;
|
|
955
|
-
_accumulatedEmotionCSS = /* @__PURE__ */ new Set();
|
|
956
|
-
};
|
|
957
|
-
const getAccumulatedEmotionCSS = () => Array.from(_accumulatedEmotionCSS).join("\n");
|
|
958
|
-
const replaceEmotionCSS = (html, newCSS) => {
|
|
959
|
-
return html.replace(
|
|
960
|
-
/<style data-emotion="smbls">[\s\S]*?<\/style>/,
|
|
961
|
-
newCSS ? `<style data-emotion="smbls">
|
|
962
|
-
${newCSS}
|
|
963
|
-
</style>` : ""
|
|
964
|
-
);
|
|
965
|
-
};
|
|
966
|
-
const renderRoute = async (data, options = {}) => {
|
|
967
|
-
const { route = "/", pathname } = options;
|
|
968
|
-
const result = await render(data, { route, pathname, prefetch: true });
|
|
969
|
-
if (!result) return null;
|
|
970
|
-
const ds = data.designSystem || {};
|
|
971
|
-
const globalCSS = await generateGlobalCSS(ds, pickProjectConfig(data));
|
|
972
|
-
let prefetchedState = null;
|
|
973
|
-
let activeLang = null;
|
|
974
|
-
try {
|
|
975
|
-
const el = result.element;
|
|
976
|
-
const polyglot = el?.context?.polyglot || data.polyglot || data.config?.polyglot;
|
|
977
|
-
activeLang = el?.state?.root?.lang || polyglot?.defaultLang || "en";
|
|
978
|
-
if (result.prefetchedPages && result.prefetchedPages[route]) {
|
|
979
|
-
const pageDef = result.prefetchedPages[route];
|
|
980
|
-
const collectStates = (def, result2 = {}) => {
|
|
981
|
-
if (!def || typeof def !== "object") return result2;
|
|
982
|
-
if (def.state && typeof def.state === "object") {
|
|
983
|
-
for (const [k, v] of Object.entries(def.state)) {
|
|
984
|
-
if (v !== void 0 && v !== null && typeof v !== "function") {
|
|
985
|
-
result2[k] = v;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
for (const [key, child] of Object.entries(def)) {
|
|
990
|
-
if (key === "state" || key === "props" || key === "attr" || key === "on" || key === "define" || key === "__ref" || key.startsWith("__")) continue;
|
|
991
|
-
if (child && typeof child === "object" && !Array.isArray(child)) {
|
|
992
|
-
collectStates(child, result2);
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
return result2;
|
|
996
|
-
};
|
|
997
|
-
prefetchedState = collectStates(pageDef);
|
|
998
|
-
}
|
|
999
|
-
} catch (e) {
|
|
1000
|
-
}
|
|
1001
|
-
return {
|
|
1002
|
-
html: result.html,
|
|
1003
|
-
css: result.emotionCSS ? result.emotionCSS.join("\n") : "",
|
|
1004
|
-
globalCSS,
|
|
1005
|
-
resetCss: globalCSS.resetRules || generateResetCSS(ds.reset),
|
|
1006
|
-
fontLinks: generateFontLinks(ds),
|
|
1007
|
-
metadata: result.metadata || extractMetadata(data, route),
|
|
1008
|
-
brKeyCount: result.registry ? Object.keys(result.registry).length : 0,
|
|
1009
|
-
brRegistry: result.brRegistry || {},
|
|
1010
|
-
ssrTranslations: result.ssrTranslations,
|
|
1011
|
-
prefetchedState,
|
|
1012
|
-
activeLang
|
|
1013
|
-
};
|
|
1014
|
-
};
|
|
1015
|
-
const renderPage = async (data, route = "/", options = {}) => {
|
|
1016
|
-
const { lang, themeColor, isr, hydrate: hydrate2 = true, prefetch = true } = options;
|
|
1017
|
-
const htmlLang = lang || data.state?.lang || data.app?.metadata?.lang || "en";
|
|
1018
|
-
const result = await render(data, { route, prefetch });
|
|
1019
|
-
if (!result) return null;
|
|
1020
|
-
const metadata = { ...result.metadata };
|
|
1021
|
-
if (themeColor) metadata["theme-color"] = themeColor;
|
|
1022
|
-
const headTags = generateHeadHtml(metadata);
|
|
1023
|
-
if (result.emotionCSS && result.emotionCSS.length) {
|
|
1024
|
-
for (const rule of result.emotionCSS) {
|
|
1025
|
-
if (rule) _accumulatedEmotionCSS.add(rule);
|
|
1026
|
-
}
|
|
47
|
+
${S};
|
|
1027
48
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
seedEntries.push(`localStorage.setItem(${JSON.stringify(storagePrefix + lang2)},${JSON.stringify(JSON.stringify(map))})`);
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
if (storageLangKey) {
|
|
1051
|
-
const defaultLang = polyglotCfg2?.defaultLang || "en";
|
|
1052
|
-
seedEntries.push(`if(!localStorage.getItem(${JSON.stringify(storageLangKey)}))localStorage.setItem(${JSON.stringify(storageLangKey)},${JSON.stringify(defaultLang)})`);
|
|
1053
|
-
}
|
|
1054
|
-
if (seedEntries.length) {
|
|
1055
|
-
translationSeed = `<script>try{${seedEntries.join(";")}}catch(e){}<\/script>
|
|
1056
|
-
`;
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
const brRegistryJson = result.brRegistry && Object.keys(result.brRegistry).length ? JSON.stringify(result.brRegistry) : null;
|
|
1060
|
-
const brRegistryScript = brRegistryJson ? `<script>window.__BR_REGISTRY__=${brRegistryJson}<\/script>
|
|
1061
|
-
` : "";
|
|
1062
|
-
isrBody = `${translationSeed}${brRegistryScript}<script>window.__BRENDER__=true<\/script>
|
|
1063
|
-
<script type="module" src="${prefix}${isr.clientScript}"><\/script>`;
|
|
1064
|
-
} else {
|
|
1065
|
-
isrBody = `<script type="module">
|
|
49
|
+
}`:`${x} {
|
|
50
|
+
${S};
|
|
51
|
+
}`:""}).filter(Boolean).join(`
|
|
52
|
+
|
|
53
|
+
`);C&&(O+=`
|
|
54
|
+
|
|
55
|
+
`+C);const F=wt(L),A=[];for(const x in R){const $=R[x];if(!$||typeof $!="object")continue;const S=Object.entries($).map(([w,j])=>{if(typeof j!="object")return"";const T=Object.entries(j).map(([I,b])=>`${J(I)}: ${b}`).join("; ");return` ${w} { ${T}; }`}).join(`
|
|
56
|
+
`);A.push(`@keyframes ${x} {
|
|
57
|
+
${S}
|
|
58
|
+
}`)}return W={rootRule:O,resetRules:F,fontFaceCSS:"",keyframeRules:A.join(`
|
|
59
|
+
`)},W}catch(o){return console.warn("generateGlobalCSS failed:",o.message,o.stack),W={rootRule:"",resetRules:"",fontFaceCSS:"",keyframeRules:""},W}};let X=new Set;const ue=()=>{W=null,X=new Set},pe=()=>Array.from(X).join(`
|
|
60
|
+
`),de=(t,e)=>t.replace(/<style data-emotion="smbls">[\s\S]*?<\/style>/,e?`<style data-emotion="smbls">
|
|
61
|
+
${e}
|
|
62
|
+
</style>`:""),me=async(t,e={})=>{const{route:o="/",pathname:s}=e,r=await pt(t,{route:o,pathname:s,prefetch:!0});if(!r)return null;const p=t.designSystem||{},f=await gt(p,mt(t));let c=null,i=null;try{const n=r.element,l=n?.context?.polyglot||t.polyglot||t.config?.polyglot;if(i=n?.state?.root?.lang||l?.defaultLang||"en",r.prefetchedPages&&r.prefetchedPages[o]){const u=r.prefetchedPages[o],a=(m,_={})=>{if(!m||typeof m!="object")return _;if(m.state&&typeof m.state=="object")for(const[y,g]of Object.entries(m.state))g!=null&&typeof g!="function"&&(_[y]=g);for(const[y,g]of Object.entries(m))y==="state"||y==="props"||y==="attr"||y==="on"||y==="define"||y==="__ref"||y.startsWith("__")||g&&typeof g=="object"&&!Array.isArray(g)&&a(g,_);return _};c=a(u)}}catch{}return{html:r.html,css:r.emotionCSS?r.emotionCSS.join(`
|
|
63
|
+
`):"",globalCSS:f,resetCss:f.resetRules||wt(p.reset),fontLinks:xt(p),metadata:r.metadata||ct(t,o),brKeyCount:r.registry?Object.keys(r.registry).length:0,brRegistry:r.brRegistry||{},ssrTranslations:r.ssrTranslations,prefetchedState:c,activeLang:i}},ge=async(t,e="/",o={})=>{const{lang:s,themeColor:r,isr:p,hydrate:f=!0,prefetch:c=!0}=o,i=s||t.state?.lang||t.app?.metadata?.lang||"en",n=await pt(t,{route:e,prefetch:c});if(!n)return null;const l={...n.metadata};r&&(l["theme-color"]=r);const u=Tt(l);if(n.emotionCSS&&n.emotionCSS.length)for(const C of n.emotionCSS)C&&X.add(C);const a=Array.from(X).join(`
|
|
64
|
+
`),m=t.designSystem||{},_=await gt(m,mt(t)),y=xt(m),g=Object.keys(n.registry).length;let q="";if(p&&p.clientScript){const C=e==="/"?0:e.replace(/^\/|\/$/g,"").split("/").length,F=C>0?"../".repeat(C):"./";if(f){let A="";if(n.ssrTranslations){const S=t.polyglot||t.config?.polyglot,w=S?.storagePrefix||"",j=S?.storageLangKey||"",T=[];for(const I in n.ssrTranslations){const b=n.ssrTranslations[I];b&&typeof b=="object"&&T.push(`localStorage.setItem(${JSON.stringify(w+I)},${JSON.stringify(JSON.stringify(b))})`)}if(j){const I=S?.defaultLang||"en";T.push(`if(!localStorage.getItem(${JSON.stringify(j)}))localStorage.setItem(${JSON.stringify(j)},${JSON.stringify(I)})`)}T.length&&(A=`<script>try{${T.join(";")}}catch(e){}<\/script>
|
|
65
|
+
`)}const x=n.brRegistry&&Object.keys(n.brRegistry).length?JSON.stringify(n.brRegistry):null,$=x?`<script>window.__BR_REGISTRY__=${x}<\/script>
|
|
66
|
+
`:"";q=`${A}${$}<script>window.__BRENDER__=true<\/script>
|
|
67
|
+
<script type="module" src="${F}${p.clientScript}"><\/script>`}else q=`<script type="module">
|
|
1066
68
|
{
|
|
1067
69
|
const brEls = document.querySelectorAll('body > :not(script):not(style)')
|
|
1068
70
|
const observer = new MutationObserver((mutations) => {
|
|
@@ -1079,494 +81,30 @@ const renderPage = async (data, route = "/", options = {}) => {
|
|
|
1079
81
|
observer.observe(document.body, { childList: true })
|
|
1080
82
|
}
|
|
1081
83
|
<\/script>
|
|
1082
|
-
<script type="module" src="${
|
|
1083
|
-
|
|
1084
|
-
}
|
|
1085
|
-
const headConfig = { ...data.config || {} };
|
|
1086
|
-
if (data.polyglot && !headConfig.polyglot) headConfig.polyglot = data.polyglot;
|
|
1087
|
-
const polyglotCfg = headConfig.polyglot;
|
|
1088
|
-
let resolvedHeadTags = headTags;
|
|
1089
|
-
if (polyglotCfg) {
|
|
1090
|
-
const defaultLang = polyglotCfg.defaultLang || "en";
|
|
1091
|
-
const translations = {
|
|
1092
|
-
...polyglotCfg.translations || {},
|
|
1093
|
-
...result.ssrTranslations || {}
|
|
1094
|
-
};
|
|
1095
|
-
const langMap = translations[defaultLang] || {};
|
|
1096
|
-
resolvedHeadTags = headTags.replace(/\{\{\s*([^|{}]+?)\s*\|\s*polyglot\s*\}\}/g, (match, key) => {
|
|
1097
|
-
const trimmed = key.trim();
|
|
1098
|
-
return langMap[trimmed] ?? match;
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
const html = `<!DOCTYPE html>
|
|
1102
|
-
<html lang="${htmlLang}">
|
|
84
|
+
<script type="module" src="${F}${p.clientScript}"><\/script>`}const L={...t.config||{}};t.polyglot&&!L.polyglot&&(L.polyglot=t.polyglot);const R=L.polyglot;let k=u;if(R){const C=R.defaultLang||"en",A={...R.translations||{},...n.ssrTranslations||{}}[C]||{};k=u.replace(/\{\{\s*([^|{}]+?)\s*\|\s*polyglot\s*\}\}/g,(x,$)=>{const S=$.trim();return A[S]??x})}return{html:`<!DOCTYPE html>
|
|
85
|
+
<html lang="${i}">
|
|
1103
86
|
<head>
|
|
1104
|
-
${
|
|
1105
|
-
${
|
|
1106
|
-
${
|
|
87
|
+
${k}
|
|
88
|
+
${y}
|
|
89
|
+
${_.fontFaceCSS?`<style>${_.fontFaceCSS}</style>`:""}
|
|
1107
90
|
<style>
|
|
1108
|
-
${
|
|
1109
|
-
${
|
|
1110
|
-
${
|
|
91
|
+
${_.rootRule||""}
|
|
92
|
+
${_.resetRules||""}
|
|
93
|
+
${_.keyframeRules||""}
|
|
1111
94
|
</style>
|
|
1112
|
-
${
|
|
1113
|
-
${
|
|
1114
|
-
</style
|
|
95
|
+
${a?`<style data-emotion="smbls">
|
|
96
|
+
${a}
|
|
97
|
+
</style>`:""}
|
|
1115
98
|
</head>
|
|
1116
99
|
<body>
|
|
1117
|
-
${
|
|
1118
|
-
${
|
|
100
|
+
${n.html}
|
|
101
|
+
${q}
|
|
1119
102
|
</body>
|
|
1120
|
-
</html
|
|
1121
|
-
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
Y: -2,
|
|
1129
|
-
Z: -1,
|
|
1130
|
-
A: 0,
|
|
1131
|
-
B: 1,
|
|
1132
|
-
C: 2,
|
|
1133
|
-
D: 3,
|
|
1134
|
-
E: 4,
|
|
1135
|
-
F: 5,
|
|
1136
|
-
G: 6,
|
|
1137
|
-
H: 7,
|
|
1138
|
-
I: 8,
|
|
1139
|
-
J: 9,
|
|
1140
|
-
K: 10,
|
|
1141
|
-
L: 11,
|
|
1142
|
-
M: 12,
|
|
1143
|
-
N: 13,
|
|
1144
|
-
O: 14,
|
|
1145
|
-
P: 15
|
|
1146
|
-
};
|
|
1147
|
-
const SPACING_PROPS = /* @__PURE__ */ new Set([
|
|
1148
|
-
"padding",
|
|
1149
|
-
"paddingTop",
|
|
1150
|
-
"paddingRight",
|
|
1151
|
-
"paddingBottom",
|
|
1152
|
-
"paddingLeft",
|
|
1153
|
-
"paddingBlock",
|
|
1154
|
-
"paddingInline",
|
|
1155
|
-
"paddingBlockStart",
|
|
1156
|
-
"paddingBlockEnd",
|
|
1157
|
-
"paddingInlineStart",
|
|
1158
|
-
"paddingInlineEnd",
|
|
1159
|
-
"margin",
|
|
1160
|
-
"marginTop",
|
|
1161
|
-
"marginRight",
|
|
1162
|
-
"marginBottom",
|
|
1163
|
-
"marginLeft",
|
|
1164
|
-
"marginBlock",
|
|
1165
|
-
"marginInline",
|
|
1166
|
-
"marginBlockStart",
|
|
1167
|
-
"marginBlockEnd",
|
|
1168
|
-
"marginInlineStart",
|
|
1169
|
-
"marginInlineEnd",
|
|
1170
|
-
"gap",
|
|
1171
|
-
"rowGap",
|
|
1172
|
-
"columnGap",
|
|
1173
|
-
"top",
|
|
1174
|
-
"right",
|
|
1175
|
-
"bottom",
|
|
1176
|
-
"left",
|
|
1177
|
-
"width",
|
|
1178
|
-
"height",
|
|
1179
|
-
"minWidth",
|
|
1180
|
-
"maxWidth",
|
|
1181
|
-
"minHeight",
|
|
1182
|
-
"maxHeight",
|
|
1183
|
-
"flexBasis",
|
|
1184
|
-
"fontSize",
|
|
1185
|
-
"lineHeight",
|
|
1186
|
-
"letterSpacing",
|
|
1187
|
-
"borderWidth",
|
|
1188
|
-
"borderRadius",
|
|
1189
|
-
"outlineWidth",
|
|
1190
|
-
"outlineOffset",
|
|
1191
|
-
"inset",
|
|
1192
|
-
"insetBlock",
|
|
1193
|
-
"insetInline",
|
|
1194
|
-
"boxSize",
|
|
1195
|
-
"round"
|
|
1196
|
-
]);
|
|
1197
|
-
const resolveSpacingToken = (token, spacingConfig) => {
|
|
1198
|
-
if (!token || typeof token !== "string") return null;
|
|
1199
|
-
if (!spacingConfig) return null;
|
|
1200
|
-
const base = spacingConfig.base || 16;
|
|
1201
|
-
const ratio = spacingConfig.ratio || 1.618;
|
|
1202
|
-
const unit = spacingConfig.unit || "px";
|
|
1203
|
-
const hasSubSequence = spacingConfig.subSequence !== false;
|
|
1204
|
-
if (token.includes(" ")) {
|
|
1205
|
-
const parts = token.split(" ").map((part) => {
|
|
1206
|
-
if (part === "-" || part === "") return part;
|
|
1207
|
-
return resolveSpacingToken(part, spacingConfig) || part;
|
|
1208
|
-
});
|
|
1209
|
-
return parts.join(" ");
|
|
1210
|
-
}
|
|
1211
|
-
if (/^(none|auto|inherit|initial|unset|0)$/i.test(token)) return null;
|
|
1212
|
-
if (/\d+(px|em|rem|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|fr|s|ms)$/i.test(token)) return null;
|
|
1213
|
-
if (/^(#|rgb|hsl|var\()/i.test(token)) return null;
|
|
1214
|
-
const isNegative = token.startsWith("-");
|
|
1215
|
-
const abs = isNegative ? token.slice(1) : token;
|
|
1216
|
-
const m = abs.match(/^([A-Z])(\d)?$/i);
|
|
1217
|
-
if (!m) return null;
|
|
1218
|
-
const letter = m[1].toUpperCase();
|
|
1219
|
-
const subStep = m[2] ? parseInt(m[2]) : 0;
|
|
1220
|
-
const idx = LETTER_TO_INDEX[letter];
|
|
1221
|
-
if (idx === void 0) return null;
|
|
1222
|
-
let value = base * Math.pow(ratio, idx);
|
|
1223
|
-
if (subStep > 0 && hasSubSequence) {
|
|
1224
|
-
const next = base * Math.pow(ratio, idx + 1);
|
|
1225
|
-
const diff = next - value;
|
|
1226
|
-
const subRatio = diff / ratio;
|
|
1227
|
-
const first = next - subRatio;
|
|
1228
|
-
const second = value + subRatio;
|
|
1229
|
-
const middle = (first + second) / 2;
|
|
1230
|
-
const subs = ~~next - ~~value > 16 ? [first, middle, second] : [first, second];
|
|
1231
|
-
if (subStep <= subs.length) {
|
|
1232
|
-
value = subs[subStep - 1];
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
const rounded = Math.round(value * 100) / 100;
|
|
1236
|
-
const sign = isNegative ? "-" : "";
|
|
1237
|
-
return `${sign}${rounded}${unit}`;
|
|
1238
|
-
};
|
|
1239
|
-
const SPACING_PROPS_KEBAB = new Set(
|
|
1240
|
-
[...SPACING_PROPS].map((k) => k.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase()))
|
|
1241
|
-
);
|
|
1242
|
-
const resolveDSValue = (key, val, ds) => {
|
|
1243
|
-
if (typeof val !== "string") return val;
|
|
1244
|
-
if (CSS_COLOR_PROPS.has(key)) {
|
|
1245
|
-
const colorMap = ds?.color || {};
|
|
1246
|
-
if (colorMap[val]) return colorMap[val];
|
|
1247
|
-
}
|
|
1248
|
-
if (SPACING_PROPS.has(key) || SPACING_PROPS_KEBAB.has(key)) {
|
|
1249
|
-
const spacing = ds?.spacing || {};
|
|
1250
|
-
const resolved = resolveSpacingToken(val, spacing);
|
|
1251
|
-
if (resolved) return resolved;
|
|
1252
|
-
}
|
|
1253
|
-
return val;
|
|
1254
|
-
};
|
|
1255
|
-
const CSS_COLOR_PROPS = /* @__PURE__ */ new Set([
|
|
1256
|
-
"color",
|
|
1257
|
-
"background",
|
|
1258
|
-
"backgroundColor",
|
|
1259
|
-
"borderColor",
|
|
1260
|
-
"borderTopColor",
|
|
1261
|
-
"borderRightColor",
|
|
1262
|
-
"borderBottomColor",
|
|
1263
|
-
"borderLeftColor",
|
|
1264
|
-
"outlineColor",
|
|
1265
|
-
"fill",
|
|
1266
|
-
"stroke"
|
|
1267
|
-
]);
|
|
1268
|
-
const NON_CSS_PROPS = /* @__PURE__ */ new Set([
|
|
1269
|
-
"href",
|
|
1270
|
-
"src",
|
|
1271
|
-
"alt",
|
|
1272
|
-
"title",
|
|
1273
|
-
"id",
|
|
1274
|
-
"name",
|
|
1275
|
-
"type",
|
|
1276
|
-
"value",
|
|
1277
|
-
"placeholder",
|
|
1278
|
-
"target",
|
|
1279
|
-
"rel",
|
|
1280
|
-
"loading",
|
|
1281
|
-
"srcset",
|
|
1282
|
-
"sizes",
|
|
1283
|
-
"media",
|
|
1284
|
-
"role",
|
|
1285
|
-
"tabindex",
|
|
1286
|
-
"for",
|
|
1287
|
-
"action",
|
|
1288
|
-
"method",
|
|
1289
|
-
"enctype",
|
|
1290
|
-
"autocomplete",
|
|
1291
|
-
"autofocus",
|
|
1292
|
-
"theme",
|
|
1293
|
-
"__element",
|
|
1294
|
-
"update",
|
|
1295
|
-
"childrenAs",
|
|
1296
|
-
"childExtends",
|
|
1297
|
-
"childProps",
|
|
1298
|
-
"children"
|
|
1299
|
-
]);
|
|
1300
|
-
const camelToKebab = (str) => str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
1301
|
-
const resolveShorthand = (key, val) => {
|
|
1302
|
-
if (typeof val === "undefined" || val === null) return null;
|
|
1303
|
-
if (key === "flow" && typeof val === "string") {
|
|
1304
|
-
let [direction, wrap] = (val || "row").split(" ");
|
|
1305
|
-
if (val.startsWith("x") || val === "row") direction = "row";
|
|
1306
|
-
if (val.startsWith("y") || val === "column") direction = "column";
|
|
1307
|
-
return { display: "flex", "flex-flow": (direction || "") + " " + (wrap || "") };
|
|
1308
|
-
}
|
|
1309
|
-
if (key === "wrap") {
|
|
1310
|
-
return { display: "flex", "flex-wrap": val };
|
|
1311
|
-
}
|
|
1312
|
-
if ((key === "align" || key === "flexAlign") && typeof val === "string") {
|
|
1313
|
-
const [alignItems, justifyContent] = val.split(" ");
|
|
1314
|
-
const result = { display: "flex", "align-items": alignItems };
|
|
1315
|
-
if (justifyContent) result["justify-content"] = justifyContent;
|
|
1316
|
-
return result;
|
|
1317
|
-
}
|
|
1318
|
-
if (key === "gridAlign" && typeof val === "string") {
|
|
1319
|
-
const [alignItems, justifyContent] = val.split(" ");
|
|
1320
|
-
const result = { display: "grid", "align-items": alignItems };
|
|
1321
|
-
if (justifyContent) result["justify-content"] = justifyContent;
|
|
1322
|
-
return result;
|
|
1323
|
-
}
|
|
1324
|
-
if (key === "flexFlow" && typeof val === "string") {
|
|
1325
|
-
let [direction, wrap] = (val || "row").split(" ");
|
|
1326
|
-
if (val.startsWith("x") || val === "row") direction = "row";
|
|
1327
|
-
if (val.startsWith("y") || val === "column") direction = "column";
|
|
1328
|
-
return { display: "flex", "flex-flow": (direction || "") + " " + (wrap || "") };
|
|
1329
|
-
}
|
|
1330
|
-
if (key === "flexWrap") {
|
|
1331
|
-
return { display: "flex", "flex-wrap": val };
|
|
1332
|
-
}
|
|
1333
|
-
if (key === "backgroundImage" && typeof val === "string" && !val.startsWith("url(") && !val.startsWith("linear-gradient") && !val.startsWith("radial-gradient") && !val.startsWith("none")) {
|
|
1334
|
-
return { "background-image": `url(${val})` };
|
|
1335
|
-
}
|
|
1336
|
-
if (key === "round" || key === "borderRadius" && val) {
|
|
1337
|
-
return { "border-radius": typeof val === "number" ? val + "px" : val };
|
|
1338
|
-
}
|
|
1339
|
-
if (key === "boxSize" && typeof val === "string") {
|
|
1340
|
-
const [height, width] = val.split(" ");
|
|
1341
|
-
return { height, width: width || height };
|
|
1342
|
-
}
|
|
1343
|
-
if (key === "widthRange" && typeof val === "string") {
|
|
1344
|
-
const [minWidth, maxWidth] = val.split(" ");
|
|
1345
|
-
return { "min-width": minWidth, "max-width": maxWidth || minWidth };
|
|
1346
|
-
}
|
|
1347
|
-
if (key === "heightRange" && typeof val === "string") {
|
|
1348
|
-
const [minHeight, maxHeight] = val.split(" ");
|
|
1349
|
-
return { "min-height": minHeight, "max-height": maxHeight || minHeight };
|
|
1350
|
-
}
|
|
1351
|
-
if (key === "column") return { "grid-column": val };
|
|
1352
|
-
if (key === "columns") return { "grid-template-columns": val };
|
|
1353
|
-
if (key === "templateColumns") return { "grid-template-columns": val };
|
|
1354
|
-
if (key === "row") return { "grid-row": val };
|
|
1355
|
-
if (key === "rows") return { "grid-template-rows": val };
|
|
1356
|
-
if (key === "templateRows") return { "grid-template-rows": val };
|
|
1357
|
-
if (key === "area") return { "grid-area": val };
|
|
1358
|
-
if (key === "template") return { "grid-template": val };
|
|
1359
|
-
if (key === "templateAreas") return { "grid-template-areas": val };
|
|
1360
|
-
if (key === "autoColumns") return { "grid-auto-columns": val };
|
|
1361
|
-
if (key === "autoRows") return { "grid-auto-rows": val };
|
|
1362
|
-
if (key === "autoFlow") return { "grid-auto-flow": val };
|
|
1363
|
-
if (key === "columnStart") return { "grid-column-start": val };
|
|
1364
|
-
if (key === "rowStart") return { "grid-row-start": val };
|
|
1365
|
-
return null;
|
|
1366
|
-
};
|
|
1367
|
-
const resolveInnerProps = (obj, ds) => {
|
|
1368
|
-
const result = {};
|
|
1369
|
-
for (const k in obj) {
|
|
1370
|
-
const v = obj[k];
|
|
1371
|
-
const expanded = resolveShorthand(k, v);
|
|
1372
|
-
if (expanded) {
|
|
1373
|
-
for (const ek in expanded) {
|
|
1374
|
-
result[ek] = resolveDSValue(ek, expanded[ek], ds);
|
|
1375
|
-
}
|
|
1376
|
-
continue;
|
|
1377
|
-
}
|
|
1378
|
-
if (typeof v !== "string" && typeof v !== "number") continue;
|
|
1379
|
-
result[camelToKebab(k)] = resolveDSValue(k, v, ds);
|
|
1380
|
-
}
|
|
1381
|
-
return result;
|
|
1382
|
-
};
|
|
1383
|
-
const buildCSSFromProps = (props, ds, mediaMap) => {
|
|
1384
|
-
const base = {};
|
|
1385
|
-
const mediaRules = {};
|
|
1386
|
-
const pseudoRules = {};
|
|
1387
|
-
for (const key in props) {
|
|
1388
|
-
const val = props[key];
|
|
1389
|
-
if (key.charCodeAt(0) === 64 && typeof val === "object") {
|
|
1390
|
-
const bp = mediaMap?.[key.slice(1)];
|
|
1391
|
-
if (bp) {
|
|
1392
|
-
const inner = resolveInnerProps(val, ds);
|
|
1393
|
-
if (Object.keys(inner).length) mediaRules[bp] = inner;
|
|
1394
|
-
}
|
|
1395
|
-
continue;
|
|
1396
|
-
}
|
|
1397
|
-
if (key.charCodeAt(0) === 58 && typeof val === "object") {
|
|
1398
|
-
const inner = resolveInnerProps(val, ds);
|
|
1399
|
-
if (Object.keys(inner).length) pseudoRules[key] = inner;
|
|
1400
|
-
continue;
|
|
1401
|
-
}
|
|
1402
|
-
if (typeof val !== "string" && typeof val !== "number") continue;
|
|
1403
|
-
if (key.charCodeAt(0) >= 65 && key.charCodeAt(0) <= 90) continue;
|
|
1404
|
-
if (NON_CSS_PROPS.has(key)) continue;
|
|
1405
|
-
const expanded = resolveShorthand(key, val);
|
|
1406
|
-
if (expanded) {
|
|
1407
|
-
for (const ek in expanded) {
|
|
1408
|
-
base[ek] = resolveDSValue(ek, expanded[ek], ds);
|
|
1409
|
-
}
|
|
1410
|
-
continue;
|
|
1411
|
-
}
|
|
1412
|
-
base[camelToKebab(key)] = resolveDSValue(key, val, ds);
|
|
1413
|
-
}
|
|
1414
|
-
return { base, mediaRules, pseudoRules };
|
|
1415
|
-
};
|
|
1416
|
-
const renderCSSRule = (selector, { base, mediaRules, pseudoRules }) => {
|
|
1417
|
-
const lines = [];
|
|
1418
|
-
const baseDecls = Object.entries(base).map(([k, v]) => `${k}: ${v}`).join("; ");
|
|
1419
|
-
if (baseDecls) lines.push(`${selector} { ${baseDecls}; }`);
|
|
1420
|
-
for (const [pseudo, p] of Object.entries(pseudoRules)) {
|
|
1421
|
-
const decls = Object.entries(p).map(([k, v]) => `${k}: ${v}`).join("; ");
|
|
1422
|
-
if (decls) lines.push(`${selector}${pseudo} { ${decls}; }`);
|
|
1423
|
-
}
|
|
1424
|
-
for (const [query, p] of Object.entries(mediaRules)) {
|
|
1425
|
-
const decls = Object.entries(p).map(([k, v]) => `${k}: ${v}`).join("; ");
|
|
1426
|
-
const mq = query.startsWith("@") ? query : `@media ${query}`;
|
|
1427
|
-
if (decls) lines.push(`${mq} { ${selector} { ${decls}; } }`);
|
|
1428
|
-
}
|
|
1429
|
-
return lines.join("\n");
|
|
1430
|
-
};
|
|
1431
|
-
const EXTENDS_CSS = {
|
|
1432
|
-
Flex: { display: "flex" },
|
|
1433
|
-
InlineFlex: { display: "inline-flex" },
|
|
1434
|
-
Grid: { display: "grid" },
|
|
1435
|
-
InlineGrid: { display: "inline-grid" },
|
|
1436
|
-
Block: { display: "block" },
|
|
1437
|
-
Inline: { display: "inline" }
|
|
1438
|
-
};
|
|
1439
|
-
const getExtendsCSS = (el) => {
|
|
1440
|
-
const exts = el.__ref?.__extends;
|
|
1441
|
-
if (!exts || !Array.isArray(exts)) return null;
|
|
1442
|
-
for (const ext of exts) {
|
|
1443
|
-
if (EXTENDS_CSS[ext]) return EXTENDS_CSS[ext];
|
|
1444
|
-
}
|
|
1445
|
-
return null;
|
|
1446
|
-
};
|
|
1447
|
-
const resolveElementProps = (el) => {
|
|
1448
|
-
let resolved;
|
|
1449
|
-
for (const key in el) {
|
|
1450
|
-
if (typeof el[key] !== "function") continue;
|
|
1451
|
-
if (NON_CSS_PROPS.has(key)) continue;
|
|
1452
|
-
if (key.charCodeAt(0) >= 65 && key.charCodeAt(0) <= 90) continue;
|
|
1453
|
-
if (key.startsWith("on")) continue;
|
|
1454
|
-
if (key.startsWith("__")) continue;
|
|
1455
|
-
if (!resolved) resolved = {};
|
|
1456
|
-
let result;
|
|
1457
|
-
try {
|
|
1458
|
-
result = el[key](el, el.state || {});
|
|
1459
|
-
} catch {
|
|
1460
|
-
try {
|
|
1461
|
-
const mockState = { root: {}, ...el.state || {} };
|
|
1462
|
-
result = el[key](el, mockState);
|
|
1463
|
-
} catch {
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
if (result !== void 0 && result !== null && result !== false) {
|
|
1467
|
-
resolved[key] = result;
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
return resolved || el;
|
|
1471
|
-
};
|
|
1472
|
-
const extractCSS = (element, ds) => {
|
|
1473
|
-
const mediaMap = ds?.media || {};
|
|
1474
|
-
const animations = ds?.animation || {};
|
|
1475
|
-
const rules = [];
|
|
1476
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1477
|
-
const usedAnimations = /* @__PURE__ */ new Set();
|
|
1478
|
-
const walk = (el) => {
|
|
1479
|
-
if (!el || !el.__ref) return;
|
|
1480
|
-
const props = resolveElementProps(el);
|
|
1481
|
-
if (props && el.node) {
|
|
1482
|
-
const cls = el.node.getAttribute?.("class");
|
|
1483
|
-
if (cls && !seen.has(cls)) {
|
|
1484
|
-
seen.add(cls);
|
|
1485
|
-
const cssResult = buildCSSFromProps(props, ds, mediaMap);
|
|
1486
|
-
const extsCss = getExtendsCSS(el);
|
|
1487
|
-
if (extsCss) {
|
|
1488
|
-
for (const [k, v] of Object.entries(extsCss)) {
|
|
1489
|
-
const kebab = camelToKebab(k);
|
|
1490
|
-
if (!cssResult.base[kebab]) cssResult.base[kebab] = v;
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
const has = Object.keys(cssResult.base).length || Object.keys(cssResult.mediaRules).length || Object.keys(cssResult.pseudoRules).length;
|
|
1494
|
-
if (has) rules.push(renderCSSRule("." + cls.split(" ")[0], cssResult));
|
|
1495
|
-
const anim = props.animation || props.animationName;
|
|
1496
|
-
if (typeof anim === "string") {
|
|
1497
|
-
const name = anim.split(" ")[0];
|
|
1498
|
-
if (animations[name]) usedAnimations.add(name);
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
if (el.__ref?.__children) {
|
|
1503
|
-
for (const ck of el.__ref.__children) {
|
|
1504
|
-
if (el[ck]?.__ref) walk(el[ck]);
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
};
|
|
1508
|
-
walk(element);
|
|
1509
|
-
const keyframes = [];
|
|
1510
|
-
for (const name of usedAnimations) {
|
|
1511
|
-
const frames = animations[name];
|
|
1512
|
-
const frameRules = Object.entries(frames).map(([step, p]) => {
|
|
1513
|
-
const decls = Object.entries(p).map(([k, v]) => `${camelToKebab(k)}: ${v}`).join("; ");
|
|
1514
|
-
return ` ${step} { ${decls}; }`;
|
|
1515
|
-
}).join("\n");
|
|
1516
|
-
keyframes.push(`@keyframes ${name} {
|
|
1517
|
-
${frameRules}
|
|
1518
|
-
}`);
|
|
1519
|
-
}
|
|
1520
|
-
return [...keyframes, ...rules].join("\n");
|
|
1521
|
-
};
|
|
1522
|
-
const generateResetCSS = (reset) => {
|
|
1523
|
-
if (!reset) return "";
|
|
1524
|
-
const rules = [];
|
|
1525
|
-
for (const [selector, props] of Object.entries(reset)) {
|
|
1526
|
-
if (!props || typeof props !== "object") continue;
|
|
1527
|
-
const baseDecls = [];
|
|
1528
|
-
const mediaRules = [];
|
|
1529
|
-
for (const [k, v] of Object.entries(props)) {
|
|
1530
|
-
if (typeof v === "object" && v !== null) {
|
|
1531
|
-
if (k.startsWith("@media") || k.startsWith("@")) {
|
|
1532
|
-
const inner = Object.entries(v).filter(([, iv]) => typeof iv !== "object").map(([ik, iv]) => `${camelToKebab(ik)}: ${iv}`).join("; ");
|
|
1533
|
-
if (inner) mediaRules.push(`${k} { ${selector} { ${inner}; } }`);
|
|
1534
|
-
}
|
|
1535
|
-
continue;
|
|
1536
|
-
}
|
|
1537
|
-
baseDecls.push(`${camelToKebab(k)}: ${v}`);
|
|
1538
|
-
}
|
|
1539
|
-
if (baseDecls.length) rules.push(`${selector} { ${baseDecls.join("; ")}; }`);
|
|
1540
|
-
rules.push(...mediaRules);
|
|
1541
|
-
}
|
|
1542
|
-
return rules.join("\n");
|
|
1543
|
-
};
|
|
1544
|
-
const generateFontLinks = (ds) => {
|
|
1545
|
-
if (!ds) return "";
|
|
1546
|
-
const families = ds.font_family || ds.fontFamily || {};
|
|
1547
|
-
const fontNames = /* @__PURE__ */ new Set();
|
|
1548
|
-
for (const val of Object.values(families)) {
|
|
1549
|
-
if (typeof val !== "string") continue;
|
|
1550
|
-
const match = val.match(/'([^']+)'/);
|
|
1551
|
-
if (match) fontNames.add(match[1]);
|
|
1552
|
-
}
|
|
1553
|
-
if (!fontNames.size) return "";
|
|
1554
|
-
const params = [...fontNames].map((name) => {
|
|
1555
|
-
const slug = name.replace(/\s+/g, "+");
|
|
1556
|
-
return `family=${slug}:wght@300;400;500;600;700`;
|
|
1557
|
-
}).join("&");
|
|
1558
|
-
return [
|
|
1559
|
-
'<link rel="preconnect" href="https://fonts.googleapis.com">',
|
|
1560
|
-
'<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>',
|
|
1561
|
-
`<link href="https://fonts.googleapis.com/css2?${params}&display=swap" rel="stylesheet">`
|
|
1562
|
-
].join("\n");
|
|
1563
|
-
};
|
|
1564
|
-
export {
|
|
1565
|
-
getAccumulatedEmotionCSS,
|
|
1566
|
-
render,
|
|
1567
|
-
renderElement,
|
|
1568
|
-
renderPage,
|
|
1569
|
-
renderRoute,
|
|
1570
|
-
replaceEmotionCSS,
|
|
1571
|
-
resetGlobalCSSCache
|
|
1572
|
-
};
|
|
103
|
+
</html>`,route:e,brKeyCount:g}},Dt={U:-6,V:-5,W:-4,X:-3,Y:-2,Z:-1,A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9,K:10,L:11,M:12,N:13,O:14,P:15},ht=new Set(["padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingBlock","paddingInline","paddingBlockStart","paddingBlockEnd","paddingInlineStart","paddingInlineEnd","margin","marginTop","marginRight","marginBottom","marginLeft","marginBlock","marginInline","marginBlockStart","marginBlockEnd","marginInlineStart","marginInlineEnd","gap","rowGap","columnGap","top","right","bottom","left","width","height","minWidth","maxWidth","minHeight","maxHeight","flexBasis","fontSize","lineHeight","letterSpacing","borderWidth","borderRadius","outlineWidth","outlineOffset","inset","insetBlock","insetInline","boxSize","round"]),yt=(t,e)=>{if(!t||typeof t!="string"||!e)return null;const o=e.base||16,s=e.ratio||1.618,r=e.unit||"px",p=e.subSequence!==!1;if(t.includes(" "))return t.split(" ").map(g=>g==="-"||g===""?g:yt(g,e)||g).join(" ");if(/^(none|auto|inherit|initial|unset|0)$/i.test(t)||/\d+(px|em|rem|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|fr|s|ms)$/i.test(t)||/^(#|rgb|hsl|var\()/i.test(t))return null;const f=t.startsWith("-"),i=(f?t.slice(1):t).match(/^([A-Z])(\d)?$/i);if(!i)return null;const n=i[1].toUpperCase(),l=i[2]?parseInt(i[2]):0,u=Dt[n];if(u===void 0)return null;let a=o*Math.pow(s,u);if(l>0&&p){const y=o*Math.pow(s,u+1),q=(y-a)/s,L=y-q,R=a+q,k=(L+R)/2,O=~~y-~~a>16?[L,k,R]:[L,R];l<=O.length&&(a=O[l-1])}const m=Math.round(a*100)/100;return`${f?"-":""}${m}${r}`},Ft=new Set([...ht].map(t=>t.replace(/[A-Z]/g,e=>"-"+e.toLowerCase()))),Q=(t,e,o)=>{if(typeof e!="string")return e;if(Bt.has(t)){const s=o?.color||{};if(s[e])return s[e]}if(ht.has(t)||Ft.has(t)){const s=o?.spacing||{},r=yt(e,s);if(r)return r}return e},Bt=new Set(["color","background","backgroundColor","borderColor","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor","outlineColor","fill","stroke"]),bt=new Set(["href","src","alt","title","id","name","type","value","placeholder","target","rel","loading","srcset","sizes","media","role","tabindex","for","action","method","enctype","autocomplete","autofocus","theme","__element","update","childrenAs","childExtends","childProps","children"]),J=t=>t.replace(/[A-Z]/g,e=>"-"+e.toLowerCase()),St=(t,e)=>{if(typeof e>"u"||e===null)return null;if(t==="flow"&&typeof e=="string"){let[o,s]=(e||"row").split(" ");return(e.startsWith("x")||e==="row")&&(o="row"),(e.startsWith("y")||e==="column")&&(o="column"),{display:"flex","flex-flow":(o||"")+" "+(s||"")}}if(t==="wrap")return{display:"flex","flex-wrap":e};if((t==="align"||t==="flexAlign")&&typeof e=="string"){const[o,s]=e.split(" "),r={display:"flex","align-items":o};return s&&(r["justify-content"]=s),r}if(t==="gridAlign"&&typeof e=="string"){const[o,s]=e.split(" "),r={display:"grid","align-items":o};return s&&(r["justify-content"]=s),r}if(t==="flexFlow"&&typeof e=="string"){let[o,s]=(e||"row").split(" ");return(e.startsWith("x")||e==="row")&&(o="row"),(e.startsWith("y")||e==="column")&&(o="column"),{display:"flex","flex-flow":(o||"")+" "+(s||"")}}if(t==="flexWrap")return{display:"flex","flex-wrap":e};if(t==="backgroundImage"&&typeof e=="string"&&!e.startsWith("url(")&&!e.startsWith("linear-gradient")&&!e.startsWith("radial-gradient")&&!e.startsWith("none"))return{"background-image":`url(${e})`};if(t==="round"||t==="borderRadius"&&e)return{"border-radius":typeof e=="number"?e+"px":e};if(t==="boxSize"&&typeof e=="string"){const[o,s]=e.split(" ");return{height:o,width:s||o}}if(t==="widthRange"&&typeof e=="string"){const[o,s]=e.split(" ");return{"min-width":o,"max-width":s||o}}if(t==="heightRange"&&typeof e=="string"){const[o,s]=e.split(" ");return{"min-height":o,"max-height":s||o}}return t==="column"?{"grid-column":e}:t==="columns"?{"grid-template-columns":e}:t==="templateColumns"?{"grid-template-columns":e}:t==="row"?{"grid-row":e}:t==="rows"?{"grid-template-rows":e}:t==="templateRows"?{"grid-template-rows":e}:t==="area"?{"grid-area":e}:t==="template"?{"grid-template":e}:t==="templateAreas"?{"grid-template-areas":e}:t==="autoColumns"?{"grid-auto-columns":e}:t==="autoRows"?{"grid-auto-rows":e}:t==="autoFlow"?{"grid-auto-flow":e}:t==="columnStart"?{"grid-column-start":e}:t==="rowStart"?{"grid-row-start":e}:null},jt=(t,e)=>{const o={};for(const s in t){const r=t[s],p=St(s,r);if(p){for(const f in p)o[f]=Q(f,p[f],e);continue}typeof r!="string"&&typeof r!="number"||(o[J(s)]=Q(s,r,e))}return o},Nt=(t,e,o)=>{const s={},r={},p={};for(const f in t){const c=t[f];if(f.charCodeAt(0)===64&&typeof c=="object"){const n=o?.[f.slice(1)];if(n){const l=jt(c,e);Object.keys(l).length&&(r[n]=l)}continue}if(f.charCodeAt(0)===58&&typeof c=="object"){const n=jt(c,e);Object.keys(n).length&&(p[f]=n);continue}if(typeof c!="string"&&typeof c!="number"||f.charCodeAt(0)>=65&&f.charCodeAt(0)<=90||bt.has(f))continue;const i=St(f,c);if(i){for(const n in i)s[n]=Q(n,i[n],e);continue}s[J(f)]=Q(f,c,e)}return{base:s,mediaRules:r,pseudoRules:p}},Wt=(t,{base:e,mediaRules:o,pseudoRules:s})=>{const r=[],p=Object.entries(e).map(([f,c])=>`${f}: ${c}`).join("; ");p&&r.push(`${t} { ${p}; }`);for(const[f,c]of Object.entries(s)){const i=Object.entries(c).map(([n,l])=>`${n}: ${l}`).join("; ");i&&r.push(`${t}${f} { ${i}; }`)}for(const[f,c]of Object.entries(o)){const i=Object.entries(c).map(([l,u])=>`${l}: ${u}`).join("; "),n=f.startsWith("@")?f:`@media ${f}`;i&&r.push(`${n} { ${t} { ${i}; } }`)}return r.join(`
|
|
104
|
+
`)},Rt={Flex:{display:"flex"},InlineFlex:{display:"inline-flex"},Grid:{display:"grid"},InlineGrid:{display:"inline-grid"},Block:{display:"block"},Inline:{display:"inline"}},Jt=t=>{const e=t.__ref?.__extends;if(!e||!Array.isArray(e))return null;for(const o of e)if(Rt[o])return Rt[o];return null},Gt=t=>{let e;for(const o in t){if(typeof t[o]!="function"||bt.has(o)||o.charCodeAt(0)>=65&&o.charCodeAt(0)<=90||o.startsWith("on")||o.startsWith("__"))continue;e||(e={});let s;try{s=t[o](t,t.state||{})}catch{try{const r={root:{},...t.state||{}};s=t[o](t,r)}catch{}}s!=null&&s!==!1&&(e[o]=s)}return e||t},he=(t,e)=>{const o=e?.media||{},s=e?.animation||{},r=[],p=new Set,f=new Set,c=n=>{if(!n||!n.__ref)return;const l=Gt(n);if(l&&n.node){const u=n.node.getAttribute?.("class");if(u&&!p.has(u)){p.add(u);const a=Nt(l,e,o),m=Jt(n);if(m)for(const[g,q]of Object.entries(m)){const L=J(g);a.base[L]||(a.base[L]=q)}(Object.keys(a.base).length||Object.keys(a.mediaRules).length||Object.keys(a.pseudoRules).length)&&r.push(Wt("."+u.split(" ")[0],a));const y=l.animation||l.animationName;if(typeof y=="string"){const g=y.split(" ")[0];s[g]&&f.add(g)}}}if(n.__ref?.__children)for(const u of n.__ref.__children)n[u]?.__ref&&c(n[u])};c(t);const i=[];for(const n of f){const l=s[n],u=Object.entries(l).map(([a,m])=>{const _=Object.entries(m).map(([y,g])=>`${J(y)}: ${g}`).join("; ");return` ${a} { ${_}; }`}).join(`
|
|
105
|
+
`);i.push(`@keyframes ${n} {
|
|
106
|
+
${u}
|
|
107
|
+
}`)}return[...i,...r].join(`
|
|
108
|
+
`)},wt=t=>{if(!t)return"";const e=[];for(const[o,s]of Object.entries(t)){if(!s||typeof s!="object")continue;const r=[],p=[];for(const[f,c]of Object.entries(s)){if(typeof c=="object"&&c!==null){if(f.startsWith("@media")||f.startsWith("@")){const i=Object.entries(c).filter(([,n])=>typeof n!="object").map(([n,l])=>`${J(n)}: ${l}`).join("; ");i&&p.push(`${f} { ${o} { ${i}; } }`)}continue}r.push(`${J(f)}: ${c}`)}r.length&&e.push(`${o} { ${r.join("; ")}; }`),e.push(...p)}return e.join(`
|
|
109
|
+
`)},xt=t=>{if(!t)return"";const e=t.font_family||t.fontFamily||{},o=new Set;for(const r of Object.values(e)){if(typeof r!="string")continue;const p=r.match(/'([^']+)'/);p&&o.add(p[1])}return o.size?['<link rel="preconnect" href="https://fonts.googleapis.com">','<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>',`<link href="https://fonts.googleapis.com/css2?${[...o].map(r=>`family=${r.replace(/\s+/g,"+")}:wght@300;400;500;600;700`).join("&")}&display=swap" rel="stylesheet">`].join(`
|
|
110
|
+
`):""};export{pe as getAccumulatedEmotionCSS,pt as render,fe as renderElement,ge as renderPage,me as renderRoute,de as replaceEmotionCSS,ue as resetGlobalCSSCache};
|