@webtypen/webframez-react 0.0.49 → 0.0.51

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/index.js CHANGED
@@ -1,3 +1,9 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1
7
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
8
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
9
  }) : x)(function(x) {
@@ -5,6 +11,79 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
5
11
  return require.apply(this, arguments);
6
12
  throw Error('Dynamic require of "' + x + '" is not supported');
7
13
  });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // node_modules/@webtypen/webframez-core/dist/routing.js
35
+ var require_routing = __commonJS({
36
+ "node_modules/@webtypen/webframez-core/dist/routing.js"(exports) {
37
+ "use strict";
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.appRelativePath = exports.appPath = exports.getBasename = exports.normalizeBasename = void 0;
40
+ function normalizeBasename2(value) {
41
+ if (value == null || value === "" || value === "/")
42
+ return "";
43
+ if (typeof value !== "string")
44
+ throw new Error("Router basename must be a string.");
45
+ const base = value.trim().replace(/\/+$/, "");
46
+ if (!base && value.trim().length <= 1)
47
+ return "";
48
+ if (!/^\/(?:[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)(?:\/[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)*$/.test(base)) {
49
+ throw new Error("Router basename must be empty or an absolute path such as /my-app.");
50
+ }
51
+ return base;
52
+ }
53
+ exports.normalizeBasename = normalizeBasename2;
54
+ function getBasename2() {
55
+ var _a, _b, _c, _d;
56
+ const runtime = globalThis;
57
+ return (_d = (_c = (_b = (_a = runtime.__WEBFRAMEZ_ROUTING_CONTEXT__) === null || _a === void 0 ? void 0 : _a.getStore()) !== null && _b !== void 0 ? _b : runtime.__RSC_BASENAME) !== null && _c !== void 0 ? _c : runtime.__WEBFRAMEZ_ROUTER_BASENAME__) !== null && _d !== void 0 ? _d : "";
58
+ }
59
+ exports.getBasename = getBasename2;
60
+ function appPath2(value, basename = getBasename2()) {
61
+ const base = normalizeBasename2(basename);
62
+ if (!base || !value.startsWith("/") || value.startsWith("//") || hasBasename(value, base))
63
+ return value;
64
+ return base + value;
65
+ }
66
+ exports.appPath = appPath2;
67
+ function appRelativePath2(value, basename = getBasename2()) {
68
+ const base = normalizeBasename2(basename);
69
+ if (!base || !hasBasename(value, base))
70
+ return value;
71
+ const relative = value.slice(base.length);
72
+ return !relative || relative.startsWith("?") || relative.startsWith("#") ? "/" + relative : relative;
73
+ }
74
+ exports.appRelativePath = appRelativePath2;
75
+ function hasBasename(value, base) {
76
+ return value === base || value.startsWith(base + "/") || value.startsWith(base + "?") || value.startsWith(base + "#");
77
+ }
78
+ }
79
+ });
80
+
81
+ // node_modules/@webtypen/webframez-core/routing.js
82
+ var require_routing2 = __commonJS({
83
+ "node_modules/@webtypen/webframez-core/routing.js"(exports, module) {
84
+ module.exports = require_routing();
85
+ }
86
+ });
8
87
 
9
88
  // src/server.ts
10
89
  import path from "node:path";
@@ -337,8 +416,7 @@ var FORCED_PACKAGE_REQUESTS = [
337
416
  "react-server-dom-webpack",
338
417
  "react-server-dom-webpack/server",
339
418
  "react-server-dom-webpack/client",
340
- "react-server-dom-webpack/client.node",
341
- "scheduler"
419
+ "react-server-dom-webpack/client.node"
342
420
  ];
343
421
  var forcedPackageResolutionInstalled = false;
344
422
  function normalizePathname(pathname) {
@@ -862,6 +940,7 @@ function parseSearchParams(query) {
862
940
  }
863
941
 
864
942
  // src/http.ts
943
+ import { AsyncLocalStorage } from "node:async_hooks";
865
944
  import fs2 from "node:fs";
866
945
  import path3 from "node:path";
867
946
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -999,6 +1078,7 @@ const rootParent = {
999
1078
  path: process.cwd(),
1000
1079
  paths: Module._nodeModulePaths(process.cwd()),
1001
1080
  };
1081
+ // Transitive dependencies (e.g. scheduler) must resolve from their importer.
1002
1082
  const forcedPackageRequests = [
1003
1083
  "@webtypen/webframez-core",
1004
1084
  "@webtypen/webframez-react",
@@ -1013,7 +1093,6 @@ const forcedPackageRequests = [
1013
1093
  "react-server-dom-webpack/server",
1014
1094
  "react-server-dom-webpack/client",
1015
1095
  "react-server-dom-webpack/client.node",
1016
- "scheduler"
1017
1096
  ];
1018
1097
 
1019
1098
  function shouldForcePackageResolution(request) {
@@ -1205,13 +1284,17 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
1205
1284
  ? payload.head.basename
1206
1285
  : "";
1207
1286
 
1208
- const previousBasename = globalThis.__RSC_BASENAME;
1209
- globalThis.__RSC_BASENAME = basename;
1210
- try {
1211
- return await renderHtml(model);
1212
- } finally {
1213
- globalThis.__RSC_BASENAME = previousBasename;
1214
- }
1287
+ const routingContext = globalThis.__WEBFRAMEZ_ROUTING_CONTEXT__ ??=
1288
+ new (require("node:async_hooks").AsyncLocalStorage)();
1289
+ return routingContext.run(basename, async () => {
1290
+ const previousBasename = globalThis.__RSC_BASENAME;
1291
+ globalThis.__RSC_BASENAME = basename;
1292
+ try {
1293
+ return await renderHtml(model);
1294
+ } finally {
1295
+ globalThis.__RSC_BASENAME = previousBasename;
1296
+ }
1297
+ });
1215
1298
  }
1216
1299
 
1217
1300
  process.on("message", async (message) => {
@@ -1447,24 +1530,10 @@ ${stderrBuffer.trim()}` : "";
1447
1530
  }
1448
1531
  };
1449
1532
  }
1533
+ var routingRuntime = globalThis;
1534
+ var basenameContext = routingRuntime.__WEBFRAMEZ_ROUTING_CONTEXT__ ??= new AsyncLocalStorage();
1450
1535
  function withRequestBasename(basename, fn) {
1451
- const target = globalThis;
1452
- const previous = target.__RSC_BASENAME;
1453
- target.__RSC_BASENAME = basename;
1454
- const finish = () => {
1455
- target.__RSC_BASENAME = previous;
1456
- };
1457
- try {
1458
- const result = fn();
1459
- if (result && typeof result.then === "function") {
1460
- return result.finally(finish);
1461
- }
1462
- finish();
1463
- return result;
1464
- } catch (error) {
1465
- finish();
1466
- throw error;
1467
- }
1536
+ return basenameContext.run(basename, fn);
1468
1537
  }
1469
1538
  function parseCookies(rawCookieHeader) {
1470
1539
  const raw = Array.isArray(rawCookieHeader) ? rawCookieHeader.join("; ") : rawCookieHeader ?? "";
@@ -1499,12 +1568,27 @@ function normalizeClientManifest(manifest, options) {
1499
1568
  }
1500
1569
  };
1501
1570
  for (const [key, value] of Object.entries(manifest)) {
1571
+ const hashIndex = key.indexOf("#");
1572
+ const moduleKey = hashIndex < 0 ? key : key.slice(0, hashIndex);
1573
+ const exportSuffix = hashIndex < 0 ? "" : key.slice(hashIndex);
1574
+ if (!path3.isAbsolute(moduleKey) && !moduleKey.includes(":") && !moduleKey.startsWith("file://")) {
1575
+ const runtimePath = path3.resolve(options.cwd, moduleKey);
1576
+ const allowedRoots = [options.distRootDir, ...candidateNodeModulesDirs];
1577
+ const insideArtifact = allowedRoots.some((root) => {
1578
+ const relative = path3.relative(path3.resolve(root), runtimePath);
1579
+ return relative !== "" && relative !== ".." && !relative.startsWith(`..${path3.sep}`) && !path3.isAbsolute(relative);
1580
+ });
1581
+ if (insideArtifact) {
1582
+ addAlias(`${runtimePath}${exportSuffix}`, value);
1583
+ addAlias(`${pathToFileURL(runtimePath).href}${exportSuffix}`, value);
1584
+ }
1585
+ }
1502
1586
  if (!key.startsWith("file://")) {
1503
1587
  continue;
1504
1588
  }
1505
1589
  let absolutePath = "";
1506
1590
  try {
1507
- absolutePath = fileURLToPath(key);
1591
+ absolutePath = fileURLToPath(moduleKey);
1508
1592
  } catch {
1509
1593
  continue;
1510
1594
  }
@@ -1515,13 +1599,13 @@ function normalizeClientManifest(manifest, options) {
1515
1599
  }
1516
1600
  const relativeModulePath = absolutePath.slice(markerIndex + marker.length);
1517
1601
  const relativeModulePathPosix = relativeModulePath.split(path3.sep).join("/");
1518
- addAlias(`./node_modules/${relativeModulePathPosix}`, value);
1519
- addAlias(`node_modules/${relativeModulePathPosix}`, value);
1520
- addAlias(absolutePath, value);
1602
+ addAlias(`./node_modules/${relativeModulePathPosix}${exportSuffix}`, value);
1603
+ addAlias(`node_modules/${relativeModulePathPosix}${exportSuffix}`, value);
1604
+ addAlias(`${absolutePath}${exportSuffix}`, value);
1521
1605
  for (const nodeModulesDir of candidateNodeModulesDirs) {
1522
1606
  const aliasPath = path3.join(nodeModulesDir, relativeModulePath);
1523
- addAlias(aliasPath, value);
1524
- addAlias(pathToFileURL(aliasPath).href, value);
1607
+ addAlias(`${aliasPath}${exportSuffix}`, value);
1608
+ addAlias(`${pathToFileURL(aliasPath).href}${exportSuffix}`, value);
1525
1609
  }
1526
1610
  }
1527
1611
  return normalized;
@@ -1666,10 +1750,10 @@ function createNodeRequestHandler(options) {
1666
1750
  const manifestPath = path3.resolve(
1667
1751
  options.manifestPath ?? path3.join(distRootDir, "react-client-manifest.json")
1668
1752
  );
1669
- const assetsPrefix = options.assetsPrefix ?? "/assets/";
1670
- const rscPath = options.rscPath ?? "/rsc";
1671
- const clientScriptUrl = options.clientScriptUrl ?? "/assets/client.js";
1672
1753
  const basePath = normalizeBasePath(options.basePath);
1754
+ const assetsPrefix = options.assetsPrefix ?? `${basePath}/assets/`;
1755
+ const rscPath = options.rscPath ?? `${basePath}/rsc`;
1756
+ const clientScriptUrl = options.clientScriptUrl ?? `${basePath}/assets/client.js`;
1673
1757
  const nodeEnv = process.env.NODE_ENV || "";
1674
1758
  const runningInWatchMode = Array.isArray(process.execArgv) && process.execArgv.includes("--watch");
1675
1759
  const liveReloadEnabled = options.liveReloadPath !== false && (nodeEnv === "development" || runningInWatchMode);
@@ -1688,7 +1772,7 @@ function createNodeRequestHandler(options) {
1688
1772
  process.once("exit", disposeInitialHtmlWorker);
1689
1773
  process.once("SIGINT", disposeInitialHtmlWorker);
1690
1774
  process.once("SIGTERM", disposeInitialHtmlWorker);
1691
- return async function handleRequest(req, res) {
1775
+ const handleRequest = async (req, res) => {
1692
1776
  if (!req.url) {
1693
1777
  res.statusCode = 400;
1694
1778
  res.end("Bad request");
@@ -1752,6 +1836,7 @@ function createNodeRequestHandler(options) {
1752
1836
  request: requestContext
1753
1837
  })
1754
1838
  );
1839
+ resolved2.head = { ...resolved2.head, basename: resolved2.head.basename ?? basePath };
1755
1840
  attachResolvedContextToCoreRequest(req, resolved2.context);
1756
1841
  const payload = {
1757
1842
  model: resolved2.model,
@@ -1827,6 +1912,7 @@ function createNodeRequestHandler(options) {
1827
1912
  )
1828
1913
  })
1829
1914
  );
1915
+ resolved.head = { ...resolved.head, basename: resolved.head.basename ?? basePath };
1830
1916
  attachResolvedContextToCoreRequest(req, resolved.context);
1831
1917
  const initialPayload = {
1832
1918
  model: resolved.model,
@@ -1912,8 +1998,31 @@ function createNodeRequestHandler(options) {
1912
1998
  }
1913
1999
  );
1914
2000
  };
2001
+ return (req, res) => withRequestBasename(basePath, () => handleRequest(req, res));
2002
+ }
2003
+ var standaloneHtmlWorker;
2004
+ async function renderReactToHtml(element) {
2005
+ if (!standaloneHtmlWorker) {
2006
+ standaloneHtmlWorker = createInitialHtmlWorker(process.cwd());
2007
+ process.once("exit", disposeReactHtmlRenderer);
2008
+ }
2009
+ const flightData = await renderRSCToString({ model: element }, {
2010
+ moduleMap: {},
2011
+ onError: (error) => {
2012
+ console.error("[webframez-react] HTML render failed", error);
2013
+ }
2014
+ });
2015
+ return standaloneHtmlWorker.renderFromFlightData({ flightData, moduleMap: {} });
2016
+ }
2017
+ function disposeReactHtmlRenderer() {
2018
+ process.removeListener("exit", disposeReactHtmlRenderer);
2019
+ standaloneHtmlWorker?.dispose();
2020
+ standaloneHtmlWorker = void 0;
1915
2021
  }
1916
2022
 
2023
+ // src/paths.ts
2024
+ var import_routing = __toESM(require_routing2(), 1);
2025
+
1917
2026
  // src/webframez-core.ts
1918
2027
  import path4 from "node:path";
1919
2028
  function normalizeMountPath(path5) {
@@ -2001,6 +2110,17 @@ function buildRenderDefaults(routePathValue) {
2001
2110
  clientScriptUrl: `${mountPath}/assets/client.js`
2002
2111
  };
2003
2112
  }
2113
+ function runtimeRoutePaths(routePath, options, basename = (0, import_routing.getBasename)(), groupPrefix = "") {
2114
+ const localMount = normalizeMountPath(options.basePath ?? `${groupPrefix}${normalizeMountPath(routePath)}`);
2115
+ const basePath = normalizeMountPath((0, import_routing.appPath)(localMount, basename)).replace(/\/$/, "");
2116
+ return {
2117
+ basePath,
2118
+ assetsPrefix: options.assetsPrefix !== void 0 ? (0, import_routing.appPath)(options.assetsPrefix, basename) : `${basePath}/assets/`,
2119
+ rscPath: options.rscPath !== void 0 ? (0, import_routing.appPath)(options.rscPath, basename) : `${basePath}/rsc`,
2120
+ clientScriptUrl: options.clientScriptUrl !== void 0 ? (0, import_routing.appPath)(options.clientScriptUrl, basename) : `${basePath}/assets/client.js`,
2121
+ ...typeof options.liveReloadPath === "string" ? { liveReloadPath: (0, import_routing.appPath)(options.liveReloadPath, basename) } : {}
2122
+ };
2123
+ }
2004
2124
  async function waitForResponseFinish(res) {
2005
2125
  if (res.writableEnded || res.destroyed) {
2006
2126
  return;
@@ -2094,10 +2214,7 @@ function registerRouteRenderer(route, methodName) {
2094
2214
  distRootDir: resolvedTarget.distRootDir,
2095
2215
  pagesDir: resolvedTarget.pagesDir,
2096
2216
  manifestPath: resolvedTarget.manifestPath,
2097
- basePath: basePath ?? defaults.basePath,
2098
- assetsPrefix: assetsPrefix ?? defaults.assetsPrefix,
2099
- rscPath: rscPath ?? defaults.rscPath,
2100
- clientScriptUrl: clientScriptUrl ?? defaults.clientScriptUrl
2217
+ ...runtimeRoutePaths(routePathValue, options, route.basename ?? (0, import_routing.getBasename)(), route.tempGroupPrefix ?? "")
2101
2218
  });
2102
2219
  const methods = normalizeMethods(method);
2103
2220
  for (const currentMethod of methods) {
@@ -2139,13 +2256,10 @@ function resolveWebframezReactRouteOptions(routePathValue, options = {}) {
2139
2256
  distRootDir,
2140
2257
  pagesDir,
2141
2258
  manifestPath,
2142
- assetsPrefix: options.assetsPrefix ?? defaults.assetsPrefix,
2143
- rscPath: options.rscPath ?? defaults.rscPath,
2144
- clientScriptUrl: options.clientScriptUrl ?? defaults.clientScriptUrl,
2259
+ ...runtimeRoutePaths(routePathValue, options),
2145
2260
  clientEntryPath: options.clientEntryPath ? resolveFromProjectRoot(options.clientEntryPath) : void 0,
2146
2261
  styleSrcPath: options.styleSrcPath ? resolveFromProjectRoot(options.styleSrcPath) : defaults.styleSrcPath,
2147
- basePath: options.basePath ?? defaults.basePath,
2148
- liveReloadPath: options.liveReloadPath,
2262
+ liveReloadPath: typeof options.liveReloadPath === "string" ? (0, import_routing.appPath)(options.liveReloadPath) : options.liveReloadPath,
2149
2263
  onData: options.onData
2150
2264
  };
2151
2265
  }
@@ -2177,10 +2291,12 @@ export {
2177
2291
  createHTMLShell,
2178
2292
  createNodeRequestHandler,
2179
2293
  createRSCHandler,
2294
+ disposeReactHtmlRenderer,
2180
2295
  getRegisteredReactBuildTargets,
2181
2296
  initWebframezReact,
2182
2297
  parseSearchParams,
2183
2298
  renderHeadToString,
2299
+ renderReactToHtml,
2184
2300
  resolveWebframezReactRouteOptions,
2185
2301
  sendRSC,
2186
2302
  setupWebframezCoreReactRoute
@@ -1,8 +1,13 @@
1
1
  "use client";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
6
11
  var __export = (target, all) => {
7
12
  for (var name in all)
8
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,8 +20,70 @@ var __copyProps = (to, from, except, desc) => {
15
20
  }
16
21
  return to;
17
22
  };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
18
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
32
 
33
+ // node_modules/@webtypen/webframez-core/dist/routing.js
34
+ var require_routing = __commonJS({
35
+ "node_modules/@webtypen/webframez-core/dist/routing.js"(exports2) {
36
+ "use strict";
37
+ Object.defineProperty(exports2, "__esModule", { value: true });
38
+ exports2.appRelativePath = exports2.appPath = exports2.getBasename = exports2.normalizeBasename = void 0;
39
+ function normalizeBasename2(value) {
40
+ if (value == null || value === "" || value === "/")
41
+ return "";
42
+ if (typeof value !== "string")
43
+ throw new Error("Router basename must be a string.");
44
+ const base = value.trim().replace(/\/+$/, "");
45
+ if (!base && value.trim().length <= 1)
46
+ return "";
47
+ if (!/^\/(?:[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)(?:\/[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)*$/.test(base)) {
48
+ throw new Error("Router basename must be empty or an absolute path such as /my-app.");
49
+ }
50
+ return base;
51
+ }
52
+ exports2.normalizeBasename = normalizeBasename2;
53
+ function getBasename2() {
54
+ var _a, _b, _c, _d;
55
+ const runtime = globalThis;
56
+ return (_d = (_c = (_b = (_a = runtime.__WEBFRAMEZ_ROUTING_CONTEXT__) === null || _a === void 0 ? void 0 : _a.getStore()) !== null && _b !== void 0 ? _b : runtime.__RSC_BASENAME) !== null && _c !== void 0 ? _c : runtime.__WEBFRAMEZ_ROUTER_BASENAME__) !== null && _d !== void 0 ? _d : "";
57
+ }
58
+ exports2.getBasename = getBasename2;
59
+ function appPath2(value, basename = getBasename2()) {
60
+ const base = normalizeBasename2(basename);
61
+ if (!base || !value.startsWith("/") || value.startsWith("//") || hasBasename(value, base))
62
+ return value;
63
+ return base + value;
64
+ }
65
+ exports2.appPath = appPath2;
66
+ function appRelativePath2(value, basename = getBasename2()) {
67
+ const base = normalizeBasename2(basename);
68
+ if (!base || !hasBasename(value, base))
69
+ return value;
70
+ const relative = value.slice(base.length);
71
+ return !relative || relative.startsWith("?") || relative.startsWith("#") ? "/" + relative : relative;
72
+ }
73
+ exports2.appRelativePath = appRelativePath2;
74
+ function hasBasename(value, base) {
75
+ return value === base || value.startsWith(base + "/") || value.startsWith(base + "?") || value.startsWith(base + "#");
76
+ }
77
+ }
78
+ });
79
+
80
+ // node_modules/@webtypen/webframez-core/routing.js
81
+ var require_routing2 = __commonJS({
82
+ "node_modules/@webtypen/webframez-core/routing.js"(exports2, module2) {
83
+ module2.exports = require_routing();
84
+ }
85
+ });
86
+
20
87
  // src/navigation.tsx
21
88
  var navigation_exports = {};
22
89
  __export(navigation_exports, {
@@ -24,18 +91,13 @@ __export(navigation_exports, {
24
91
  Redirect: () => Redirect
25
92
  });
26
93
  module.exports = __toCommonJS(navigation_exports);
94
+ var import_react = __toESM(require("react"), 1);
95
+
96
+ // src/paths.ts
97
+ var import_routing = __toESM(require_routing2(), 1);
98
+
99
+ // src/navigation.tsx
27
100
  var import_jsx_runtime = require("react/jsx-runtime");
28
- function getDefaultBasename() {
29
- const globalValue = globalThis.__RSC_BASENAME;
30
- if (globalValue && globalValue !== "/") {
31
- return globalValue;
32
- }
33
- if (typeof window === "undefined") {
34
- return "";
35
- }
36
- const value = window.__RSC_BASENAME;
37
- return value && value !== "/" ? value : "";
38
- }
39
101
  function getClientRouter() {
40
102
  if (typeof window === "undefined") {
41
103
  return null;
@@ -97,13 +159,14 @@ function resolveHref(to, basename) {
97
159
  const hash = hashPart ? `#${hashPart}` : "";
98
160
  return `${resolvedPath}${query}${hash}`;
99
161
  }
100
- function Link({ to, basename, onClick, ...rest }) {
101
- const resolvedHref = resolveHref(to, basename ?? getDefaultBasename());
162
+ var Link = import_react.default.forwardRef(function Link2({ to, basename, onClick, ...rest }, ref) {
163
+ const resolvedHref = resolveHref(to, basename ?? (0, import_routing.getBasename)());
102
164
  const isServerRender = typeof window === "undefined";
103
165
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
104
166
  "a",
105
167
  {
106
168
  ...rest,
169
+ ref,
107
170
  href: resolvedHref,
108
171
  onClick: isServerRender ? void 0 : (event) => {
109
172
  onClick?.(event);
@@ -113,6 +176,8 @@ function Link({ to, basename, onClick, ...rest }) {
113
176
  if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
114
177
  return;
115
178
  }
179
+ if (rest.download != null && rest.download !== false)
180
+ return;
116
181
  if (rest.target && rest.target !== "_self") {
117
182
  return;
118
183
  }
@@ -124,9 +189,9 @@ function Link({ to, basename, onClick, ...rest }) {
124
189
  }
125
190
  }
126
191
  );
127
- }
192
+ });
128
193
  function Redirect({ to, basename, replace = true }) {
129
- const resolvedHref = resolveHref(to, basename ?? getDefaultBasename());
194
+ const resolvedHref = resolveHref(to, basename ?? (0, import_routing.getBasename)());
130
195
  if (typeof window !== "undefined") {
131
196
  const currentHref = `${window.location.pathname}${window.location.search}${window.location.hash}`;
132
197
  if (resolvedHref !== currentHref) {
@@ -5,7 +5,7 @@ export type LinkProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "hre
5
5
  basename?: string;
6
6
  };
7
7
 
8
- export function Link(props: LinkProps): React.ReactElement;
8
+ export const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
9
9
 
10
10
  export type RedirectProps = {
11
11
  to: string;
@@ -1,18 +1,92 @@
1
1
  "use client";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
2
27
 
3
- // src/navigation.tsx
4
- import { jsx } from "react/jsx-runtime";
5
- function getDefaultBasename() {
6
- const globalValue = globalThis.__RSC_BASENAME;
7
- if (globalValue && globalValue !== "/") {
8
- return globalValue;
28
+ // node_modules/@webtypen/webframez-core/dist/routing.js
29
+ var require_routing = __commonJS({
30
+ "node_modules/@webtypen/webframez-core/dist/routing.js"(exports) {
31
+ "use strict";
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.appRelativePath = exports.appPath = exports.getBasename = exports.normalizeBasename = void 0;
34
+ function normalizeBasename2(value) {
35
+ if (value == null || value === "" || value === "/")
36
+ return "";
37
+ if (typeof value !== "string")
38
+ throw new Error("Router basename must be a string.");
39
+ const base = value.trim().replace(/\/+$/, "");
40
+ if (!base && value.trim().length <= 1)
41
+ return "";
42
+ if (!/^\/(?:[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)(?:\/[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)*$/.test(base)) {
43
+ throw new Error("Router basename must be empty or an absolute path such as /my-app.");
44
+ }
45
+ return base;
46
+ }
47
+ exports.normalizeBasename = normalizeBasename2;
48
+ function getBasename2() {
49
+ var _a, _b, _c, _d;
50
+ const runtime = globalThis;
51
+ return (_d = (_c = (_b = (_a = runtime.__WEBFRAMEZ_ROUTING_CONTEXT__) === null || _a === void 0 ? void 0 : _a.getStore()) !== null && _b !== void 0 ? _b : runtime.__RSC_BASENAME) !== null && _c !== void 0 ? _c : runtime.__WEBFRAMEZ_ROUTER_BASENAME__) !== null && _d !== void 0 ? _d : "";
52
+ }
53
+ exports.getBasename = getBasename2;
54
+ function appPath2(value, basename = getBasename2()) {
55
+ const base = normalizeBasename2(basename);
56
+ if (!base || !value.startsWith("/") || value.startsWith("//") || hasBasename(value, base))
57
+ return value;
58
+ return base + value;
59
+ }
60
+ exports.appPath = appPath2;
61
+ function appRelativePath2(value, basename = getBasename2()) {
62
+ const base = normalizeBasename2(basename);
63
+ if (!base || !hasBasename(value, base))
64
+ return value;
65
+ const relative = value.slice(base.length);
66
+ return !relative || relative.startsWith("?") || relative.startsWith("#") ? "/" + relative : relative;
67
+ }
68
+ exports.appRelativePath = appRelativePath2;
69
+ function hasBasename(value, base) {
70
+ return value === base || value.startsWith(base + "/") || value.startsWith(base + "?") || value.startsWith(base + "#");
71
+ }
9
72
  }
10
- if (typeof window === "undefined") {
11
- return "";
73
+ });
74
+
75
+ // node_modules/@webtypen/webframez-core/routing.js
76
+ var require_routing2 = __commonJS({
77
+ "node_modules/@webtypen/webframez-core/routing.js"(exports, module) {
78
+ module.exports = require_routing();
12
79
  }
13
- const value = window.__RSC_BASENAME;
14
- return value && value !== "/" ? value : "";
15
- }
80
+ });
81
+
82
+ // src/navigation.tsx
83
+ import React from "react";
84
+
85
+ // src/paths.ts
86
+ var import_routing = __toESM(require_routing2(), 1);
87
+
88
+ // src/navigation.tsx
89
+ import { jsx } from "react/jsx-runtime";
16
90
  function getClientRouter() {
17
91
  if (typeof window === "undefined") {
18
92
  return null;
@@ -74,13 +148,14 @@ function resolveHref(to, basename) {
74
148
  const hash = hashPart ? `#${hashPart}` : "";
75
149
  return `${resolvedPath}${query}${hash}`;
76
150
  }
77
- function Link({ to, basename, onClick, ...rest }) {
78
- const resolvedHref = resolveHref(to, basename ?? getDefaultBasename());
151
+ var Link = React.forwardRef(function Link2({ to, basename, onClick, ...rest }, ref) {
152
+ const resolvedHref = resolveHref(to, basename ?? (0, import_routing.getBasename)());
79
153
  const isServerRender = typeof window === "undefined";
80
154
  return /* @__PURE__ */ jsx(
81
155
  "a",
82
156
  {
83
157
  ...rest,
158
+ ref,
84
159
  href: resolvedHref,
85
160
  onClick: isServerRender ? void 0 : (event) => {
86
161
  onClick?.(event);
@@ -90,6 +165,8 @@ function Link({ to, basename, onClick, ...rest }) {
90
165
  if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
91
166
  return;
92
167
  }
168
+ if (rest.download != null && rest.download !== false)
169
+ return;
93
170
  if (rest.target && rest.target !== "_self") {
94
171
  return;
95
172
  }
@@ -101,9 +178,9 @@ function Link({ to, basename, onClick, ...rest }) {
101
178
  }
102
179
  }
103
180
  );
104
- }
181
+ });
105
182
  function Redirect({ to, basename, replace = true }) {
106
- const resolvedHref = resolveHref(to, basename ?? getDefaultBasename());
183
+ const resolvedHref = resolveHref(to, basename ?? (0, import_routing.getBasename)());
107
184
  if (typeof window !== "undefined") {
108
185
  const currentHref = `${window.location.pathname}${window.location.search}${window.location.hash}`;
109
186
  if (resolvedHref !== currentHref) {