@marko/run 0.10.0 → 0.11.0-rc.1

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.
@@ -0,0 +1,61 @@
1
+ // src/runtime/url-builder.ts
2
+ var encode = encodeURIComponent;
3
+ var pathParts = /* @__PURE__ */ new Map();
4
+ function parsePathParts(path) {
5
+ let parts = pathParts.get(path);
6
+ if (!parts) {
7
+ let lastEnd = 0;
8
+ let paramStart;
9
+ pathParts.set(path, parts = [[]]);
10
+ while (lastEnd >= 0 && (paramStart = path.indexOf("/$", lastEnd) + 1)) {
11
+ parts.push(path.slice(lastEnd, paramStart++));
12
+ if (path.charAt(paramStart) === "$") {
13
+ paramStart++;
14
+ lastEnd = -1;
15
+ } else {
16
+ lastEnd = path.indexOf("/", paramStart);
17
+ }
18
+ parts[0].push(path.slice(paramStart, lastEnd < 0 ? void 0 : lastEnd));
19
+ }
20
+ parts.push(lastEnd >= 0 ? path.slice(lastEnd) : "");
21
+ }
22
+ return parts;
23
+ }
24
+ function joinHref(path, options) {
25
+ let result = path;
26
+ if (options.search) {
27
+ const query = "" + new URLSearchParams(options.search);
28
+ if (query) result += "?" + query;
29
+ }
30
+ if (options.hash) result += "#" + encode(options.hash);
31
+ return result;
32
+ }
33
+ function href(path, ...[options]) {
34
+ return options ? "params" in options ? ((parts) => href_keys(parts, options, ...parts[0]))(
35
+ parsePathParts(path)
36
+ ) : joinHref(path, options) : path;
37
+ }
38
+ function href_path(strings, ...params) {
39
+ let i = 0;
40
+ let j = 0;
41
+ let result = strings[i++];
42
+ if (!result || Array.isArray(result)) result = strings[i++];
43
+ while (i < strings.length) {
44
+ const param = params[j++];
45
+ result += (Array.isArray(param) ? param.map(encode).join("/") : encode(param)) + strings[i++];
46
+ }
47
+ return result;
48
+ }
49
+ function href_values(strings, options, ...params) {
50
+ return joinHref(href_path(strings, ...params), options);
51
+ }
52
+ function href_keys(strings, options, ...keys) {
53
+ return href_values(strings, options, ...keys.map((k) => options.params[k]));
54
+ }
55
+ export {
56
+ href,
57
+ href_keys,
58
+ href_path,
59
+ href_values,
60
+ parsePathParts
61
+ };
@@ -1,5 +1,5 @@
1
1
  import type { Adapter, BuiltRoutes, RoutableFile, Route, RouterOptions } from "../types";
2
- export declare function renderRouteTemplate(route: Route, markoApi?: string): string;
2
+ export declare function renderRouteTemplate(route: Route, markoApi?: string, dev?: boolean): string;
3
3
  export declare function renderRouteEntry(route: Route, rootDir: string): string;
4
4
  export declare function renderRouter(routes: BuiltRoutes, rootDir: string, runtimeInclude?: string, options?: RouterOptions): string;
5
5
  export declare function renderMiddleware(middleware: RoutableFile[], rootDir: string): string;
@@ -3,10 +3,10 @@ export declare const markoRunFilePrefix = "__marko-run__";
3
3
  export declare const virtualFilePrefix = "virtual:marko-run";
4
4
  export declare const httpVerbs: readonly ["get", "head", "post", "put", "delete", "patch", "options"];
5
5
  export declare const RoutableFileTypes: {
6
- readonly Page: "page";
7
- readonly Layout: "layout";
8
- readonly Handler: "handler";
9
6
  readonly Middleware: "middleware";
7
+ readonly Handler: "handler";
8
+ readonly Layout: "layout";
9
+ readonly Page: "page";
10
10
  readonly Meta: "meta";
11
11
  readonly NotFound: "404";
12
12
  readonly Error: "500";