@withl5e/l5e 0.3.2 → 0.3.3-alpha.0

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/dist/server.js CHANGED
@@ -1,21 +1,21 @@
1
- import { existsSync as Q } from "fs";
2
- import H from "node:fs/promises";
1
+ import { existsSync as tt } from "fs";
2
+ import N from "node:fs/promises";
3
3
  import d from "node:path";
4
- import { pathToFileURL as I } from "node:url";
4
+ import { pathToFileURL as H } from "node:url";
5
5
  import V from "request-ip";
6
- import { a as ot, s as J } from "./render-BaTAJ4Ha.js";
7
- import { c as G, p as tt, a as it } from "./index-CybB8Tdk.js";
8
- import { createHash as at } from "node:crypto";
9
- import { createRequire as ct } from "node:module";
10
- let B = null;
11
- function lt() {
12
- return B || (B = (async () => {
13
- const t = ct(import.meta.url), e = t.resolve("vite"), n = t.resolve("rollup", { paths: [d.dirname(e)] });
14
- return await import(I(n).href);
15
- })()), B;
6
+ import { a as it, s as B } from "./render-CRag-5V7.js";
7
+ import { c as Y, p as et, a as at } from "./index-CybB8Tdk.js";
8
+ import { createHash as ct } from "node:crypto";
9
+ import { createRequire as lt } from "node:module";
10
+ let J = null;
11
+ function ut() {
12
+ return J || (J = (async () => {
13
+ const t = lt(import.meta.url), e = t.resolve("vite"), n = t.resolve("rollup", { paths: [d.dirname(e)] });
14
+ return await import(H(n).href);
15
+ })()), J;
16
16
  }
17
- const W = { hash: "", filename: "", content: "" }, z = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map();
18
- function et(t, e) {
17
+ const z = { hash: "", filename: "", content: "" }, G = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map();
18
+ function nt(t, e) {
19
19
  const n = K.get(t);
20
20
  if (n)
21
21
  return n;
@@ -25,21 +25,21 @@ function et(t, e) {
25
25
  return K.set(t, s), s;
26
26
  }
27
27
  function q(t) {
28
- return at("sha256").update(t).digest("hex").substring(0, 16);
28
+ return ct("sha256").update(t).digest("hex").substring(0, 16);
29
29
  }
30
- const F = "\0l5e:bundle-entry";
31
- function ut(t) {
30
+ const U = "\0l5e:bundle-entry";
31
+ function dt(t) {
32
32
  return {
33
33
  name: "l5e-virtual-entry",
34
34
  resolveId(e) {
35
- return e === F ? F : null;
35
+ return e === U ? U : null;
36
36
  },
37
37
  load(e) {
38
- return e === F ? t : null;
38
+ return e === U ? t : null;
39
39
  }
40
40
  };
41
41
  }
42
- function dt(t) {
42
+ function ft(t) {
43
43
  const e = (n) => "/" + d.relative(t, n).replace(/\\/g, "/");
44
44
  return {
45
45
  name: "vendor-path-rewriter",
@@ -48,130 +48,130 @@ function dt(t) {
48
48
  }
49
49
  };
50
50
  }
51
- async function ft(t, e) {
52
- const n = t.map((u) => {
53
- const k = u.startsWith("/") ? d.join(e, u.substring(1)) : d.join(e, u);
54
- return `import ${JSON.stringify(k)};`;
51
+ async function pt(t, e) {
52
+ const n = t.map((l) => {
53
+ const L = l.startsWith("/") ? d.join(e, l.substring(1)) : d.join(e, l);
54
+ return `import ${JSON.stringify(L)};`;
55
55
  }).join(`
56
56
  `), s = {
57
- input: F,
58
- plugins: [ut(n), dt(e)],
59
- external: (u) => !u.startsWith(".") && !d.isAbsolute(u) && u !== F
57
+ input: U,
58
+ plugins: [dt(n), ft(e)],
59
+ external: (l) => !l.startsWith(".") && !d.isAbsolute(l) && l !== U
60
60
  }, i = {
61
61
  format: "es",
62
62
  inlineDynamicImports: !1,
63
63
  entryFileNames: "bundle-[hash].js",
64
64
  chunkFileNames: "bundle-[hash].js"
65
- }, { rollup: l } = await lt(), c = await l(s);
66
- let a;
65
+ }, { rollup: f } = await ut(), p = await f(s);
66
+ let c;
67
67
  try {
68
- ({ output: a } = await c.generate(i));
68
+ ({ output: c } = await p.generate(i));
69
69
  } finally {
70
- await c.close();
70
+ await p.close();
71
71
  }
72
- for (const u of a)
73
- u.type === "chunk" && z.set(u.fileName, {
74
- content: u.code || "",
75
- hash: q(u.code || ""),
76
- filename: u.fileName,
72
+ for (const l of c)
73
+ l.type === "chunk" && G.set(l.fileName, {
74
+ content: l.code || "",
75
+ hash: q(l.code || ""),
76
+ filename: l.fileName,
77
77
  mimeType: "application/javascript"
78
78
  });
79
- const f = a[0];
80
- if (f?.type !== "chunk")
79
+ const o = c[0];
80
+ if (o?.type !== "chunk")
81
81
  throw new Error("[bundler] rollup produced no entry chunk");
82
82
  return {
83
- hash: q(f.code || ""),
84
- filename: f.fileName,
85
- content: f.code || ""
83
+ hash: q(o.code || ""),
84
+ filename: o.fileName,
85
+ content: o.code || ""
86
86
  };
87
87
  }
88
- async function pt(t, e) {
88
+ async function ht(t, e) {
89
89
  if (t.length === 0)
90
- return W;
90
+ return z;
91
91
  const n = [...new Set(t)].sort(), s = `scripts:${n.join(",")}`;
92
92
  try {
93
- return await et(s, () => ft(n, e));
93
+ return await nt(s, () => pt(n, e));
94
94
  } catch (i) {
95
- return console.error("[bundler] Error bundling scripts:", i), W;
95
+ return console.error("[bundler] Error bundling scripts:", i), z;
96
96
  }
97
97
  }
98
- async function ht(t, e) {
98
+ async function mt(t, e) {
99
99
  const n = [];
100
- for (const c of t) {
101
- const a = c.startsWith("/") ? d.join(e, c.substring(1)) : d.join(e, c);
100
+ for (const p of t) {
101
+ const c = p.startsWith("/") ? d.join(e, p.substring(1)) : d.join(e, p);
102
102
  try {
103
- const f = await H.readFile(a, "utf-8");
104
- n.push(`/* ${c} */
105
- ${f}
103
+ const o = await N.readFile(c, "utf-8");
104
+ n.push(`/* ${p} */
105
+ ${o}
106
106
  `);
107
- } catch (f) {
108
- console.warn(`[bundler] Failed to read CSS file: ${c}`, f);
107
+ } catch (o) {
108
+ console.warn(`[bundler] Failed to read CSS file: ${p}`, o);
109
109
  }
110
110
  }
111
111
  const s = n.join(`
112
112
 
113
- `), i = q(s), l = `bundle-${i}.css`;
114
- return z.set(l, {
113
+ `), i = q(s), f = `bundle-${i}.css`;
114
+ return G.set(f, {
115
115
  content: s,
116
116
  hash: i,
117
- filename: l,
117
+ filename: f,
118
118
  mimeType: "text/css"
119
- }), { hash: i, filename: l, content: s };
119
+ }), { hash: i, filename: f, content: s };
120
120
  }
121
- async function mt(t, e) {
121
+ async function wt(t, e) {
122
122
  if (t.length === 0)
123
- return W;
123
+ return z;
124
124
  const n = [...new Set(t)].sort(), s = `css:${n.join(",")}`;
125
125
  try {
126
- return await et(s, () => ht(n, e));
126
+ return await nt(s, () => mt(n, e));
127
127
  } catch (i) {
128
- return console.error("[bundler] Error bundling CSS:", i), W;
128
+ return console.error("[bundler] Error bundling CSS:", i), z;
129
129
  }
130
130
  }
131
- function wt(t) {
132
- return z.get(t);
131
+ function gt(t) {
132
+ return G.get(t);
133
133
  }
134
- function gt(t, e) {
135
- const n = ot(e);
134
+ function yt(t, e) {
135
+ const n = it(e);
136
136
  return t.replace(/<html\b([^>]*)>/i, (s, i) => /\blang\s*=/i.test(i) ? s.replace(/lang\s*=\s*"[^"]*"/i, () => `lang="${n}"`) : `<html lang="${n}"${i}>`);
137
137
  }
138
- function yt(t) {
138
+ function bt(t) {
139
139
  return new URL(`${t.protocol}://${t.get("host")}${t.originalUrl}`);
140
140
  }
141
- function nt(t, e) {
141
+ function st(t, e) {
142
142
  return `${t.pathname}${t.search}`.replace(e, "") || "/";
143
143
  }
144
- function Y(t) {
144
+ function X(t) {
145
145
  const e = {
146
146
  method: t.method,
147
- headers: it(t)
147
+ headers: at(t)
148
148
  };
149
- return t.method !== "GET" && t.method !== "HEAD" && (e.body = t, e.duplex = "half"), new globalThis.Request(yt(t).href, e);
149
+ return t.method !== "GET" && t.method !== "HEAD" && (e.body = t, e.duplex = "half"), new globalThis.Request(bt(t).href, e);
150
150
  }
151
- function D(t, e, n, s) {
152
- const i = new URL(e.url), l = nt(i, n), c = l.startsWith("/") ? l : `/${l}`, a = {};
153
- return e.headers.forEach((f, u) => {
154
- a[u] = f;
151
+ function W(t, e, n, s) {
152
+ const i = new URL(e.url), f = st(i, n), p = f.startsWith("/") ? f : `/${f}`, c = {};
153
+ return e.headers.forEach((o, l) => {
154
+ c[l] = o;
155
155
  }), {
156
156
  url: i,
157
- path: c,
157
+ path: p,
158
158
  pathname: i.pathname,
159
159
  method: e.method,
160
- headers: a,
161
- cookies: tt(e.headers.get("cookie") ?? void 0),
160
+ headers: c,
161
+ cookies: et(e.headers.get("cookie") ?? void 0),
162
162
  query: Object.fromEntries(i.searchParams.entries()),
163
163
  ip: V.getClientIp(t) ?? void 0,
164
164
  locals: s
165
165
  };
166
166
  }
167
- function X(t, e, n) {
167
+ function Z(t, e, n) {
168
168
  return t ? t instanceof globalThis.Request ? t : t instanceof URL ? new globalThis.Request(t.href, e.clone()) : new globalThis.Request(new URL(t, n).href, e.clone()) : e;
169
169
  }
170
- async function Z(t, e, n) {
170
+ async function Q(t, e, n) {
171
171
  e.status(n.status);
172
- const s = bt(n.headers);
173
- if (n.headers.forEach((l, c) => {
174
- c.toLowerCase() !== "set-cookie" && e.setHeader(c, l);
172
+ const s = vt(n.headers);
173
+ if (n.headers.forEach((f, p) => {
174
+ p.toLowerCase() !== "set-cookie" && e.setHeader(p, f);
175
175
  }), s.length > 0 && e.setHeader("Set-Cookie", s), t.method === "HEAD") {
176
176
  e.end();
177
177
  return;
@@ -179,7 +179,7 @@ async function Z(t, e, n) {
179
179
  const i = Buffer.from(await n.arrayBuffer());
180
180
  e.send(i);
181
181
  }
182
- function bt(t) {
182
+ function vt(t) {
183
183
  const e = t.getSetCookie;
184
184
  if (typeof e == "function")
185
185
  return e.call(t);
@@ -187,9 +187,9 @@ function bt(t) {
187
187
  if (n?.["set-cookie"])
188
188
  return n["set-cookie"];
189
189
  const s = t.get("set-cookie");
190
- return s ? vt(s) : [];
190
+ return s ? St(s) : [];
191
191
  }
192
- function vt(t) {
192
+ function St(t) {
193
193
  const e = [];
194
194
  let n = 0;
195
195
  for (let s = 0; s < t.length; s++) {
@@ -199,26 +199,26 @@ function vt(t) {
199
199
  }
200
200
  return e.push(t.slice(n).trim()), e.filter(Boolean);
201
201
  }
202
- function St(t) {
202
+ function xt(t) {
203
203
  if (!t.rawResponse)
204
204
  return null;
205
- const { body: e, contentType: n, statusCode: s, headers: i } = t.rawResponse, l = new Headers(i);
206
- return l.set("Content-Type", n), new globalThis.Response(e, {
205
+ const { body: e, contentType: n, statusCode: s, headers: i } = t.rawResponse, f = new Headers(i);
206
+ return f.set("Content-Type", n), new globalThis.Response(e, {
207
207
  status: s || 200,
208
- headers: l
208
+ headers: f
209
209
  });
210
210
  }
211
- async function xt({
211
+ async function $t({
212
212
  rendered: t,
213
213
  template: e,
214
214
  manifest: n,
215
215
  root: s,
216
216
  distClientDir: i,
217
- isProduction: l
217
+ isProduction: f
218
218
  }) {
219
- const c = St(t);
220
- if (c)
221
- return c;
219
+ const p = xt(t);
220
+ if (p)
221
+ return p;
222
222
  if (t.redirect)
223
223
  return new globalThis.Response(null, {
224
224
  status: t.redirect.statusCode,
@@ -226,89 +226,92 @@ async function xt({
226
226
  Location: t.redirect.url
227
227
  }
228
228
  });
229
- let a = t.scripts || [], f = t.styles || [];
230
- const u = t.islands || [];
231
- let k = t.cacheTags || [];
232
- const _ = t.maxAge, N = t.sMaxAge, U = t.swr;
233
- let o = "", p = [], w = "";
234
- if (l && n) {
229
+ let c = t.scripts || [], o = t.styles || [];
230
+ const l = t.islands || [];
231
+ let L = t.cacheTags || [];
232
+ const P = t.maxAge, I = t.sMaxAge, D = t.swr;
233
+ let F = "", a = [], u = "", g = "";
234
+ if (t.islandData && t.islandData.length > 0 && (g = `<script type="application/json" id="_l5e_data_">${B(
235
+ t.islandData,
236
+ { isJSON: !0 }
237
+ )}<\/script>`), f && n) {
235
238
  let x = function(r) {
236
239
  const m = n[r];
237
- return m ? (m.css && m.css.forEach((v) => g.add(v)), m.imports && m.imports.forEach((v) => {
238
- const P = n[v];
239
- P?.file && T.add(P.file), P?.css && P.css.forEach((A) => g.add(A)), P?.imports && P.imports.forEach((A) => {
240
+ return m ? (m.css && m.css.forEach((v) => w.add(v)), m.imports && m.imports.forEach((v) => {
241
+ const _ = n[v];
242
+ _?.file && E.add(_.file), _?.css && _.css.forEach((A) => w.add(A)), _?.imports && _.imports.forEach((A) => {
240
243
  const j = n[A];
241
- j?.file && T.add(j.file), j?.css && j.css.forEach((O) => g.add(O));
244
+ j?.file && E.add(j.file), j?.css && j.css.forEach((O) => w.add(O));
242
245
  });
243
246
  }), { file: m.file }) : { file: null };
244
247
  };
245
- a = a.filter((r) => !r.includes(".global.")), f = f.filter((r) => !r.includes(".global."));
246
- const g = /* @__PURE__ */ new Set(), T = /* @__PURE__ */ new Set(), M = [];
247
- for (const r of a) {
248
+ c = c.filter((r) => !r.includes(".global.")), o = o.filter((r) => !r.includes(".global."));
249
+ const w = /* @__PURE__ */ new Set(), E = /* @__PURE__ */ new Set(), T = [];
250
+ for (const r of c) {
248
251
  const m = r.replace(/^\//, ""), { file: v } = x(m);
249
- v && M.push(`/${v}`);
252
+ v && T.push(`/${v}`);
250
253
  }
251
- const L = [];
252
- for (const r of f) {
254
+ const M = [];
255
+ for (const r of o) {
253
256
  const m = r.replace(/^\//, ""), { file: v } = x(m);
254
- v && (L.push(`/${v}`), g.add(v));
257
+ v && (M.push(`/${v}`), w.add(v));
255
258
  }
256
- if (M.length > 0) {
257
- const r = await pt(M, i);
258
- a = r.filename ? [`/${r.filename}`] : M;
259
+ if (T.length > 0) {
260
+ const r = await ht(T, i);
261
+ c = r.filename ? [`/${r.filename}`] : T;
259
262
  }
260
- if (L.length > 0) {
261
- const r = await mt(L, i);
262
- r.filename && (f = [`/${r.filename}`]);
263
+ if (M.length > 0) {
264
+ const r = await wt(M, i);
265
+ r.filename && (o = [`/${r.filename}`]);
263
266
  }
264
267
  const h = n["src/client.global.ts"];
265
268
  if (h && (h.css && h.css.length > 0 && h.css.forEach((r) => {
266
- o += `<link rel="stylesheet" crossorigin href="/${r}">`;
267
- }), h.file && p.push(`/${h.file}`)), u.length > 0) {
269
+ F += `<link rel="stylesheet" crossorigin href="/${r}">`;
270
+ }), h.file && a.push(`/${h.file}`)), l.length > 0) {
268
271
  const r = {};
269
- for (const m of u) {
272
+ for (const m of l) {
270
273
  const v = n[m.src];
271
274
  v?.file && (r[m.key] = `/${v.file}`);
272
275
  }
273
- Object.keys(r).length > 0 && (w = `<script>window.__L5E_ISLANDS__=${J(r)}<\/script>`);
276
+ Object.keys(r).length > 0 && (u = `<script>window.__L5E_ISLANDS__=${B(r)}<\/script>`);
274
277
  }
275
- f.length > 0 && (o += f.map((r) => `<link rel="stylesheet" crossorigin href="${r}">`).join(""));
278
+ o.length > 0 && (F += o.map((r) => `<link rel="stylesheet" crossorigin href="${r}">`).join(""));
276
279
  }
277
280
  let y = "";
278
- l || (y = [...new Set(f)].map((x) => `<link rel="stylesheet" href="${x}">`).join(""));
279
- let b = [...p, ...a];
280
- if (!l) {
281
+ f || (y = [...new Set(o)].map((x) => `<link rel="stylesheet" href="${x}">`).join(""));
282
+ let b = [...a, ...c];
283
+ if (!f) {
281
284
  const x = d.join(s, "src", "client.global.ts");
282
- if (Q(x) && (b = ["/src/client.global.ts", ...b]), b = [...new Set(b)], u.length > 0) {
283
- const g = {};
284
- for (const T of u)
285
- g[T.key] = `/${T.src}`;
286
- w = `<script>window.__L5E_ISLANDS__=${J(g)}<\/script>`;
285
+ if (tt(x) && (b = ["/src/client.global.ts", ...b]), b = [...new Set(b)], l.length > 0) {
286
+ const w = {};
287
+ for (const E of l)
288
+ w[E.key] = `/${E.src}`;
289
+ u = `<script>window.__L5E_ISLANDS__=${B(w)}<\/script>`;
287
290
  }
288
291
  }
289
- const S = w + b.map((x) => `<script type="module" src="${x}"><\/script>`).join(""), E = t.lang ? gt(e, t.lang) : e, $ = t.rawHtml ? t.html || "" : E.replace("<!--app-head-->", () => (t.head ?? "") + o + y).replace("<!--app-html-->", () => t.html ?? "").replace("<!--app-scripts-->", () => S), C = new Headers({
292
+ const S = g + u + b.map((x) => `<script type="module" src="${x}"><\/script>`).join(""), k = t.lang ? yt(e, t.lang) : e, $ = t.rawHtml ? t.html || "" : k.replace("<!--app-head-->", () => (t.head ?? "") + F + y).replace("<!--app-html-->", () => t.html ?? "").replace("<!--app-scripts-->", () => S), C = new Headers({
290
293
  "Content-Type": "text/html"
291
294
  }), R = ["public"];
292
- return _ !== void 0 && R.push(`max-age=${_}`), N !== void 0 && R.push(`s-maxage=${N}`), U !== void 0 && R.push(`stale-while-revalidate=${U}`), R.length > 1 && l && C.set("Cache-Control", R.join(", ")), process.env.NODE_ENV === "production" && (k = Ct(k)), C.set("Cache-Tag", ["global", ...k].join(",")), new globalThis.Response($, {
295
+ return P !== void 0 && R.push(`max-age=${P}`), I !== void 0 && R.push(`s-maxage=${I}`), D !== void 0 && R.push(`stale-while-revalidate=${D}`), R.length > 1 && f && C.set("Cache-Control", R.join(", ")), process.env.NODE_ENV === "production" && (L = At(L)), C.set("Cache-Tag", ["global", ...L].join(",")), new globalThis.Response($, {
293
296
  status: t.statusCode || 200,
294
297
  headers: C
295
298
  });
296
299
  }
297
- async function $t(t = {}) {
298
- const e = t.root || process.cwd(), n = t.base || "/", s = process.env.NODE_ENV === "production", i = s ? await H.readFile(d.join(e, "./index.html"), "utf-8") : "", l = (await import("express")).default, c = t.app || l();
300
+ async function Rt(t = {}) {
301
+ const e = t.root || process.cwd(), n = t.base || "/", s = process.env.NODE_ENV === "production", i = t.externalizeIslandProps ?? !0, f = s ? await N.readFile(d.join(e, "./index.html"), "utf-8") : "", p = (await import("express")).default, c = t.app || p();
299
302
  if (t.publicDir) {
300
- const o = d.isAbsolute(t.publicDir) ? t.publicDir : d.join(e, t.publicDir);
301
- Q(o) && c.use(l.static(o));
303
+ const a = d.isAbsolute(t.publicDir) ? t.publicDir : d.join(e, t.publicDir);
304
+ tt(a) && c.use(p.static(a));
302
305
  }
303
- let a;
304
- const f = d.join(e, "./dist/client");
306
+ let o;
307
+ const l = d.join(e, "./dist/client");
305
308
  if (s) {
306
- const o = (await import("compression")).default, p = (await import("sirv")).default;
307
- c.use(o()), c.use(n, p(f, { extensions: [] })), c.get(
309
+ const a = (await import("compression")).default, u = (await import("sirv")).default;
310
+ c.use(a()), c.use(n, u(l, { extensions: [] })), c.get(
308
311
  `${n === "/" ? "" : n}/bundle-:hash.:ext`,
309
- async (w, y) => {
312
+ async (g, y) => {
310
313
  try {
311
- const { hash: b, ext: S } = w.params, E = `bundle-${b}.${S}`, $ = wt(E);
314
+ const { hash: b, ext: S } = g.params, k = `bundle-${b}.${S}`, $ = gt(k);
312
315
  if (!$)
313
316
  return y.status(404).send("Bundled file not found");
314
317
  y.set({
@@ -321,10 +324,10 @@ async function $t(t = {}) {
321
324
  }
322
325
  );
323
326
  } else {
324
- const { createServer: o } = await import("vite"), p = d.join(e, "vite.config.js");
325
- a = await o({
327
+ const { createServer: a } = await import("vite"), u = d.join(e, "vite.config.js");
328
+ o = await a({
326
329
  root: e,
327
- configFile: p,
330
+ configFile: u,
328
331
  server: { middlewareMode: !0 },
329
332
  appType: "custom",
330
333
  base: n,
@@ -339,141 +342,143 @@ async function $t(t = {}) {
339
342
  resolve: {
340
343
  conditions: ["development", "default"]
341
344
  }
342
- }), c.use(a.middlewares);
345
+ }), c.use(o.middlewares);
343
346
  }
344
- c.use("/_l5e/action", l.json({ limit: "100kb" }));
345
- const u = /^[a-zA-Z]\w+_[0-9a-f]{1,4}$/;
346
- let k = null, _ = null;
347
- async function N() {
347
+ c.use("/_l5e/action", p.json({ limit: "100kb" }));
348
+ const L = /^[a-zA-Z]\w+_[0-9a-f]{1,4}$/;
349
+ let P = null, I = null;
350
+ async function D() {
348
351
  if (!s)
349
- return (await a.ssrLoadModule("virtual:l5e-actions")).actionRegistry || {};
350
- if (!k) {
351
- const o = d.join(e, "./dist/server/action-registry.json"), p = await H.readFile(o, "utf-8");
352
- k = JSON.parse(p);
352
+ return (await o.ssrLoadModule("virtual:l5e-actions")).actionRegistry || {};
353
+ if (!P) {
354
+ const a = d.join(e, "./dist/server/action-registry.json"), u = await N.readFile(a, "utf-8");
355
+ P = JSON.parse(u);
353
356
  }
354
- return k;
357
+ return P;
355
358
  }
356
- async function U() {
359
+ async function F() {
357
360
  if (!s)
358
- return (await a.ssrLoadModule("virtual:l5e-actions")).viewActions || {};
359
- if (!_) {
360
- const o = d.join(e, "./dist/server/entry-server.js");
361
- _ = (await import(I(o).href)).viewActions || {};
361
+ return (await o.ssrLoadModule("virtual:l5e-actions")).viewActions || {};
362
+ if (!I) {
363
+ const a = d.join(e, "./dist/server/entry-server.js");
364
+ I = (await import(H(a).href)).viewActions || {};
362
365
  }
363
- return _;
366
+ return I;
364
367
  }
365
- return c.all("/_l5e/action/:actionKey", async (o, p) => {
368
+ return c.all("/_l5e/action/:actionKey", async (a, u) => {
366
369
  try {
367
- const { actionKey: w } = o.params;
368
- if (!u.test(w))
369
- return p.status(400).send("Invalid action key");
370
- const b = (await N())[w];
370
+ const { actionKey: g } = a.params;
371
+ if (!L.test(g))
372
+ return u.status(400).send("Invalid action key");
373
+ const b = (await D())[g];
371
374
  if (!b)
372
- return p.status(404).send("Action not found");
373
- const { modulePath: S, actionName: E } = b;
375
+ return u.status(404).send("Action not found");
376
+ const { modulePath: S, actionName: k } = b;
374
377
  let $;
375
378
  if (s) {
376
- const A = await U(), j = A[`/src/${S}/actions.tsx`] ? `/src/${S}/actions.tsx` : A[`/src/${S}/actions.ts`] ? `/src/${S}/actions.ts` : null;
379
+ const A = await F(), j = A[`/src/${S}/actions.tsx`] ? `/src/${S}/actions.tsx` : A[`/src/${S}/actions.ts`] ? `/src/${S}/actions.ts` : null;
377
380
  if (!j)
378
- return p.status(404).send("Action module not found");
381
+ return u.status(404).send("Action module not found");
379
382
  $ = await A[j]();
380
383
  } else
381
384
  try {
382
- $ = await a.ssrLoadModule(`/src/${S}/actions.tsx`);
385
+ $ = await o.ssrLoadModule(`/src/${S}/actions.tsx`);
383
386
  } catch {
384
- $ = await a.ssrLoadModule(`/src/${S}/actions.ts`);
387
+ $ = await o.ssrLoadModule(`/src/${S}/actions.ts`);
385
388
  }
386
- if (!Object.prototype.hasOwnProperty.call($, E))
387
- return p.status(404).send("Action not found");
388
- const C = $[E];
389
+ if (!Object.prototype.hasOwnProperty.call($, k))
390
+ return u.status(404).send("Action not found");
391
+ const C = $[k];
389
392
  if (!C || !C.handler)
390
- return p.status(404).send("Action not found");
393
+ return u.status(404).send("Action not found");
391
394
  const R = (C.method || "GET").toUpperCase();
392
- if (o.method.toUpperCase() !== R)
393
- return p.status(405).set("Allow", R).send("Method Not Allowed");
394
- const x = d.join(e, "./dist/server/entry-server.js"), g = s ? await import(I(x).href) : await a.ssrLoadModule("@withl5e/l5e/entry-server"), { runInRenderContext: T } = await (s ? import(I(x).href) : a.ssrLoadModule("@withl5e/l5e/jsx-runtime")), { renderJsxToHtmlString: M } = await (s ? import(I(x).href) : a.ssrLoadModule("@withl5e/l5e")), L = {}, h = Y(o), r = G({
395
+ if (a.method.toUpperCase() !== R)
396
+ return u.status(405).set("Allow", R).send("Method Not Allowed");
397
+ const x = d.join(e, "./dist/server/entry-server.js"), w = s ? await import(H(x).href) : await o.ssrLoadModule("@withl5e/l5e/entry-server"), { runInRenderContext: E } = await (s ? import(H(x).href) : o.ssrLoadModule("@withl5e/l5e/jsx-runtime")), { renderJsxToHtmlString: T } = await (s ? import(H(x).href) : o.ssrLoadModule("@withl5e/l5e")), M = {}, h = X(a), r = Y({
395
398
  request: h,
396
- locals: L,
397
- clientAddress: V.getClientIp(o) ?? void 0
398
- }), m = await g.loadMiddleware?.(), P = await (typeof m == "function" ? m : (A, j) => j())(r, async (A) => {
399
- const j = X(A, r.request, r.url), O = {
400
- ...D(o, j, n, L),
401
- path: o.originalUrl,
402
- body: o.body
403
- }, st = await T(
399
+ locals: M,
400
+ clientAddress: V.getClientIp(a) ?? void 0
401
+ }), m = await w.loadMiddleware?.(), _ = await (typeof m == "function" ? m : (A, j) => j())(r, async (A) => {
402
+ const j = Z(A, r.request, r.url), O = {
403
+ ...W(a, j, n, M),
404
+ path: a.originalUrl,
405
+ body: a.body
406
+ }, rt = await E(
404
407
  async () => {
405
- const rt = await C.handler(O);
406
- return M(rt);
408
+ const ot = await C.handler(O);
409
+ return T(ot);
407
410
  },
408
411
  O,
409
412
  S
410
413
  );
411
- return new Response(st, { headers: { "Content-Type": "text/html" } });
414
+ return new Response(rt, { headers: { "Content-Type": "text/html" } });
412
415
  });
413
- await Z(o, p, P);
414
- } catch (w) {
415
- a?.ssrFixStacktrace?.(w), console.error("[l5e] Action error:", w.stack || w), p.status(500).send("Internal server error");
416
+ await Q(a, u, _);
417
+ } catch (g) {
418
+ o?.ssrFixStacktrace?.(g), console.error("[l5e] Action error:", g.stack || g), u.status(500).send("Internal server error");
416
419
  }
417
- }), c.use(async (o, p) => {
420
+ }), c.use(async (a, u) => {
418
421
  try {
419
- const w = o.originalUrl.replace(n, "");
420
- let y, b, S, E;
422
+ const g = a.originalUrl.replace(n, "");
423
+ let y, b, S, k;
421
424
  if (s) {
422
- y = i;
423
- const h = d.join(e, "./dist/server/entry-server.js"), r = await import(I(h).href);
425
+ y = f;
426
+ const h = d.join(e, "./dist/server/entry-server.js"), r = await import(H(h).href);
424
427
  b = r.render, S = r.loadMiddleware;
425
- const m = await H.readFile(
428
+ const m = await N.readFile(
426
429
  d.join(e, "./dist/client/.vite/manifest.json"),
427
430
  "utf-8"
428
431
  );
429
- E = JSON.parse(m);
432
+ k = JSON.parse(m);
430
433
  } else {
431
- y = await H.readFile(d.join(e, "./index.html"), "utf-8"), y = await a.transformIndexHtml(w, y), y.includes("@vite/client") || (y = y.replace(
434
+ y = await N.readFile(d.join(e, "./index.html"), "utf-8"), y = await o.transformIndexHtml(g, y), y.includes("@vite/client") || (y = y.replace(
432
435
  "</head>",
433
436
  '<script type="module" src="/@vite/client"><\/script></head>'
434
437
  ));
435
- const h = await a.ssrLoadModule(
438
+ const h = await o.ssrLoadModule(
436
439
  "@withl5e/l5e/entry-server"
437
440
  );
438
441
  b = h.render, S = h.loadMiddleware;
439
442
  }
440
- const $ = await S?.(), C = typeof $ == "function" ? $ : (h, r) => r(), R = {}, x = Y(o), g = G({
443
+ const $ = await S?.(), C = typeof $ == "function" ? $ : (h, r) => r(), R = {}, x = X(a), w = Y({
441
444
  request: x,
442
- requestInfo: D(o, x, n, R),
445
+ requestInfo: W(a, x, n, R),
443
446
  locals: R,
444
- clientAddress: V.getClientIp(o)
445
- }), T = async (h) => {
446
- const r = D(o, h, n, R), m = nt(r.url, n), v = await b(m, r);
447
- return xt({
447
+ clientAddress: V.getClientIp(a)
448
+ }), E = async (h) => {
449
+ const r = W(a, h, n, R), m = st(r.url, n), v = await b(m, r, {
450
+ externalizeIslandProps: i
451
+ });
452
+ return $t({
448
453
  rendered: v,
449
454
  template: y,
450
- manifest: E,
455
+ manifest: k,
451
456
  root: e,
452
- distClientDir: f,
457
+ distClientDir: l,
453
458
  isProduction: s
454
459
  });
455
- }, M = async (h) => {
456
- const r = X(h, g.request, g.url);
457
- return g.request = r, g.url = new URL(r.url), g.cookies = tt(r.headers.get("cookie") ?? void 0), g.requestInfo = D(o, r, n, R), T(r);
460
+ }, T = async (h) => {
461
+ const r = Z(h, w.request, w.url);
462
+ return w.request = r, w.url = new URL(r.url), w.cookies = et(r.headers.get("cookie") ?? void 0), w.requestInfo = W(a, r, n, R), E(r);
458
463
  };
459
- g.rewrite = (h) => M(h);
460
- const L = await C(g, M);
461
- await Z(o, p, L);
462
- } catch (w) {
463
- a?.ssrFixStacktrace?.(w), console.error(w.stack), p.status(500).end(s ? "Internal Server Error" : w.stack);
464
+ w.rewrite = (h) => T(h);
465
+ const M = await C(w, T);
466
+ await Q(a, u, M);
467
+ } catch (g) {
468
+ o?.ssrFixStacktrace?.(g), console.error(g.stack), u.status(500).end(s ? "Internal Server Error" : g.stack);
464
469
  }
465
- }), { app: c, vite: a };
470
+ }), { app: c, vite: o };
466
471
  }
467
- async function Ht(t = {}) {
472
+ async function Ft(t = {}) {
468
473
  const e = t.port || 5173, n = (await import("express")).default, s = n();
469
474
  t.setupApp && (console.log("setupApp"), await t.setupApp(s));
470
- const { app: i } = await $t({ ...t, app: s });
475
+ const { app: i } = await Rt({ ...t, app: s });
471
476
  i.listen(e, () => {
472
477
  console.log(`Server started at http://localhost:${e}`);
473
478
  });
474
479
  }
475
- const Rt = 1e3;
476
- function jt(t) {
480
+ const jt = 1e3;
481
+ function Ct(t) {
477
482
  if (t === "global")
478
483
  return "global";
479
484
  let e = 0;
@@ -483,14 +488,14 @@ function jt(t) {
483
488
  }
484
489
  return Math.abs(e).toString(36).substring(0, 8);
485
490
  }
486
- function Ct(t) {
487
- return (Array.isArray(t) ? t : [...t]).slice(0, Rt).map(jt);
491
+ function At(t) {
492
+ return (Array.isArray(t) ? t : [...t]).slice(0, jt).map(Ct);
488
493
  }
489
494
  export {
490
- gt as applyHtmlLang,
491
- $t as createServer,
492
- jt as hashTag,
493
- Ct as optimizeCacheTags,
494
- Ht as startServer
495
+ yt as applyHtmlLang,
496
+ Rt as createServer,
497
+ Ct as hashTag,
498
+ At as optimizeCacheTags,
499
+ Ft as startServer
495
500
  };
496
501
  //# sourceMappingURL=server.js.map