@orieljs/framework 0.1.0-alpha.14 → 0.1.0-alpha.15

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.
@@ -9,8 +9,9 @@ import {
9
9
  currentContainer,
10
10
  facade,
11
11
  fileType_exports,
12
- inject
13
- } from "./chunk-4NCMY3ZS.js";
12
+ inject,
13
+ isPublicAsset
14
+ } from "./chunk-FVI6X3VJ.js";
14
15
  import {
15
16
  Application,
16
17
  AuthFactory,
@@ -184,12 +185,14 @@ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } fr
184
185
  var FIRST = "abcdefghijklmnopqrstuvwxyz";
185
186
  var REST = `${FIRST}0123456789`;
186
187
  var CLASS_ATTRIBUTE = /^(class|o:[^\s=]*-class[^\s=]*)$/i;
188
+ var ALPINE_EXPRESSION = /^(:|x-bind:)class$/i;
189
+ var ALPINE_CLASS_LIST = /^x-transition:(enter|leave)(-start|-end)?$/i;
187
190
  var RAW_TEXT = /* @__PURE__ */ new Set(["script", "style", "textarea", "title", "xmp", "noembed", "noframes"]);
188
191
  function rewriteHtml(html, map) {
189
192
  if (Object.keys(map).length === 0) return html;
190
- return replaceHtmlClasses(html, (token2) => map[decodeEntities(token2)] ?? token2);
193
+ return replaceHtmlClasses(html, (token2) => map[decodeEntities(token2)] ?? token2, { alpine: true });
191
194
  }
192
- function replaceHtmlClasses(html, replace) {
195
+ function replaceHtmlClasses(html, replace, options = {}) {
193
196
  let out = "";
194
197
  let last = 0;
195
198
  let i = 0;
@@ -222,13 +225,21 @@ function replaceHtmlClasses(html, replace) {
222
225
  const quote2 = html[j] === '"' || html[j] === "'" ? html[j] : "";
223
226
  const valueStart = quote2 === "" ? j : j + 1;
224
227
  const valueEnd = quote2 === "" ? unquotedEnd(html, valueStart) : indexOrEnd(html, quote2, valueStart);
225
- if (CLASS_ATTRIBUTE.test(name)) {
228
+ if (CLASS_ATTRIBUTE.test(name) || options.alpine && ALPINE_CLASS_LIST.test(name)) {
226
229
  const value = html.slice(valueStart, valueEnd);
227
230
  const renamed = value.replace(/\S+/g, replace);
228
231
  if (renamed !== value) {
229
232
  out += html.slice(last, valueStart) + renamed;
230
233
  last = valueEnd;
231
234
  }
235
+ } else if (options.alpine && ALPINE_EXPRESSION.test(name)) {
236
+ const raw = html.slice(valueStart, valueEnd);
237
+ const decoded = decodeEntities(raw);
238
+ const renamed = rewriteClassExpression(decoded, replace);
239
+ if (renamed !== decoded) {
240
+ out += html.slice(last, valueStart) + (raw === decoded ? renamed : encodeAttribute(renamed));
241
+ last = valueEnd;
242
+ }
232
243
  }
233
244
  j = quote2 === "" ? valueEnd : valueEnd + 1;
234
245
  }
@@ -242,6 +253,97 @@ function replaceHtmlClasses(html, replace) {
242
253
  }
243
254
  return out + html.slice(last);
244
255
  }
256
+ var ATTRIBUTE_ESCAPES = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#039;" };
257
+ var encodeAttribute = (value) => value.replace(/[&<>"']/g, (character) => ATTRIBUTE_ESCAPES[character]);
258
+ function rewriteClassExpression(expression, replace) {
259
+ let out = "";
260
+ let previous = "";
261
+ let i = 0;
262
+ while (i < expression.length) {
263
+ const character = expression[i];
264
+ if (character === "`") {
265
+ const end = templateEnd(expression, i);
266
+ out += `\`${rewriteTemplate(expression.slice(i + 1, end), replace)}${expression[end] ?? ""}`;
267
+ previous = character;
268
+ i = end + 1;
269
+ continue;
270
+ }
271
+ if (character === "'" || character === '"') {
272
+ let end = i + 1;
273
+ while (end < expression.length && expression[end] !== character) end += expression[end] === "\\" ? 2 : 1;
274
+ const body = expression.slice(i + 1, end);
275
+ const compared = /[=!]=$/.test(out.trimEnd()) || /^\s*[=!]=/.test(expression.slice(end + 1));
276
+ const untouched = compared || body.includes("\\");
277
+ out += character + (untouched ? body : body.replace(/\S+/g, replace)) + (expression[end] ?? "");
278
+ previous = character;
279
+ i = end + 1;
280
+ continue;
281
+ }
282
+ if (/[A-Za-z_$]/.test(character)) {
283
+ let end = i + 1;
284
+ while (end < expression.length && /[\w$-]/.test(expression[end]) && !(expression[end] === "-" && !/[\w$]/.test(expression[end + 1] ?? ""))) end++;
285
+ const word = expression.slice(i, end);
286
+ const isKey = (previous === "{" || previous === ",") && /^\s*:/.test(expression.slice(end));
287
+ const renamed = isKey ? replace(word) : word;
288
+ out += renamed === word || /^[A-Za-z_$][\w$]*$/.test(renamed) ? renamed : `'${renamed}'`;
289
+ previous = "word";
290
+ i = end;
291
+ continue;
292
+ }
293
+ if (!/\s/.test(character)) previous = character;
294
+ out += character;
295
+ i++;
296
+ }
297
+ return out;
298
+ }
299
+ function templateEnd(code, start) {
300
+ let i = start + 1;
301
+ while (i < code.length && code[i] !== "`") {
302
+ if (code[i] === "\\") i += 2;
303
+ else if (code.startsWith("${", i)) i = substitutionEnd(code, i + 2) + 1;
304
+ else i++;
305
+ }
306
+ return i;
307
+ }
308
+ function substitutionEnd(code, start) {
309
+ let depth = 0;
310
+ let i = start;
311
+ while (i < code.length) {
312
+ const character = code[i];
313
+ if (character === "'" || character === '"') {
314
+ i++;
315
+ while (i < code.length && code[i] !== character) i += code[i] === "\\" ? 2 : 1;
316
+ } else if (character === "`") {
317
+ i = templateEnd(code, i);
318
+ } else if (character === "{") {
319
+ depth++;
320
+ } else if (character === "}") {
321
+ if (depth === 0) return i;
322
+ depth--;
323
+ }
324
+ i++;
325
+ }
326
+ return i;
327
+ }
328
+ function rewriteTemplate(body, replace) {
329
+ if (body.includes("\\")) return body;
330
+ let out = "";
331
+ let i = 0;
332
+ while (i < body.length) {
333
+ const open = body.indexOf("${", i);
334
+ const text = body.slice(i, open === -1 ? body.length : open);
335
+ out += text.replace(/\S+/g, (word, offset) => {
336
+ const gluedBefore = offset === 0 && i > 0;
337
+ const gluedAfter = offset + word.length === text.length && open !== -1;
338
+ return gluedBefore || gluedAfter ? word : replace(word);
339
+ });
340
+ if (open === -1) break;
341
+ const close = substitutionEnd(body, open + 2);
342
+ out += `\${${rewriteClassExpression(body.slice(open + 2, close), replace)}}`;
343
+ i = close + 1;
344
+ }
345
+ return out;
346
+ }
245
347
  function attributeNameEnd(html, i) {
246
348
  let j = i + 1;
247
349
  while (j < html.length && !/[\s/>=]/.test(html[j])) j++;
@@ -700,7 +802,7 @@ var Application2 = class _Application extends Container2 {
700
802
  this.singleton(ClassNames, () => new ClassNameMap(this));
701
803
  }
702
804
  base;
703
- version = "0.1.0-alpha.14";
805
+ version = "0.1.0-alpha.15";
704
806
  providers = [];
705
807
  bootingCallbacks = [];
706
808
  bootedCallbacks = [];
@@ -880,7 +982,7 @@ import { readFile } from "fs/promises";
880
982
  import { fileURLToPath } from "url";
881
983
  import { existsSync as existsSync4, lstatSync, readdirSync as readdirSync2, statSync as statSync3 } from "fs";
882
984
  import { cp, mkdir, mkdtemp, rename, rm, writeFile } from "fs/promises";
883
- import { basename as basename2, dirname, join as join5, resolve as resolve2 } from "path";
985
+ import { basename as basename2, dirname, join as join5, relative as relative2, resolve as resolve2 } from "path";
884
986
  import { createReadStream as createReadStream2 } from "fs";
885
987
  import { stat as stat2 } from "fs/promises";
886
988
  import { Readable as Readable2 } from "stream";
@@ -2364,7 +2466,6 @@ function applyExceptionCallbacks(app, handler) {
2364
2466
  const configurator = new ExceptionsConfiguration(handler);
2365
2467
  for (const callback of app.make(ExceptionCallbacks)) callback(configurator);
2366
2468
  }
2367
- var HIDDEN_SEGMENT = /^\.|\.(ts|tsx|mts|cts)$|[. ]$/i;
2368
2469
  async function servePublicFile(publicPath, request2) {
2369
2470
  if (request2.method !== "GET" && request2.method !== "HEAD") return void 0;
2370
2471
  let pathname;
@@ -2377,7 +2478,7 @@ async function servePublicFile(publicPath, request2) {
2377
2478
  const root = resolve(publicPath);
2378
2479
  const file = resolve(root, `.${pathname}`);
2379
2480
  if (!file.startsWith(root + sep)) return void 0;
2380
- if (relative(root, file).split(/[\\/]/).some((segment) => HIDDEN_SEGMENT.test(segment))) return void 0;
2481
+ if (!isPublicAsset(relative(root, file))) return void 0;
2381
2482
  const info = await stat2(file).catch(() => void 0);
2382
2483
  if (info === void 0 || !info.isFile()) return void 0;
2383
2484
  const type = mimeFromExtension(file);
@@ -2482,7 +2583,7 @@ async function exportSite(app, options) {
2482
2583
  const staging = await mkdtemp(join5(dirname(output), `.${basename2(output)}-`));
2483
2584
  try {
2484
2585
  if (publicPath !== void 0 && existsSync4(publicPath)) {
2485
- await cp(publicPath, staging, { recursive: true, filter: (source) => basename2(source) !== "hot" && !lstatSync(source).isSymbolicLink() });
2586
+ await cp(publicPath, staging, { recursive: true, filter: (source) => basename2(source) !== "hot" && !lstatSync(source).isSymbolicLink() && isPublicAsset(relative2(publicPath, source)) });
2486
2587
  }
2487
2588
  const excluded = (path) => options.exclude.some((pattern) => wildcard(pattern).test(path));
2488
2589
  const isPublicFile = (path) => publicPath !== void 0 && path !== "/" && isFile(join5(publicPath, path));
@@ -2558,6 +2659,8 @@ async function serveBun(app, options) {
2558
2659
  const server = bun.serve({
2559
2660
  port: options.port,
2560
2661
  hostname: options.hostname,
2662
+ // Bun closes a connection idle for 10 seconds by default, a slow page included; 255 is the most it allows.
2663
+ idleTimeout: 255,
2561
2664
  async fetch(request2, current) {
2562
2665
  setClientAddress(request2, current.requestIP(request2)?.address);
2563
2666
  const response2 = await handleSafely(app, request2, options.publicPath);
@@ -3222,7 +3325,7 @@ import { createHmac, timingSafeEqual } from "crypto";
3222
3325
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
3223
3326
  import { randomBytes as randomBytes2 } from "crypto";
3224
3327
  import { existsSync as existsSync5, readdirSync as readdirSync3 } from "fs";
3225
- import { join as join6, relative as relative2, sep as sep2 } from "path";
3328
+ import { join as join6, relative as relative3, sep as sep2 } from "path";
3226
3329
  import { pathToFileURL as pathToFileURL2 } from "url";
3227
3330
  import { AsyncLocalStorage } from "async_hooks";
3228
3331
  import { existsSync as existsSync24 } from "fs";
@@ -4412,7 +4515,7 @@ async function discover(directory) {
4412
4515
  /* @vite-ignore */
4413
4516
  pathToFileURL2(join6(directory, file)).href
4414
4517
  );
4415
- found.push([componentName(relative2(directory, join6(directory, file))), module.default]);
4518
+ found.push([componentName(relative3(directory, join6(directory, file))), module.default]);
4416
4519
  }
4417
4520
  return found;
4418
4521
  }
@@ -4955,12 +5058,12 @@ var LiveComponentManager = class {
4955
5058
  }
4956
5059
  /** The absolute URL of the page a memo path belongs to, on the current request's origin ('/' + path without one). */
4957
5060
  pageUrl(path) {
4958
- const relative3 = `/${path.replace(/^\/+/, "")}`;
5061
+ const relative32 = `/${path.replace(/^\/+/, "")}`;
4959
5062
  const url2 = optional(this.container(), HttpRequest)?.url();
4960
5063
  try {
4961
- return url2 === void 0 ? relative3 : new URL(relative3, url2).href;
5064
+ return url2 === void 0 ? relative32 : new URL(relative32, url2).href;
4962
5065
  } catch {
4963
- return relative3;
5066
+ return relative32;
4964
5067
  }
4965
5068
  }
4966
5069
  /** Dispatches, redirects: the effects every response carries. */
@@ -8955,4 +9058,4 @@ export {
8955
9058
  StorageFake,
8956
9059
  FakeFile
8957
9060
  };
8958
- //# sourceMappingURL=chunk-UBSIBGXR.js.map
9061
+ //# sourceMappingURL=chunk-7GPMFMS7.js.map