revojs 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/app/index.d.ts +6 -6
- package/dist/http/index.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +19 -102
- package/dist/runtime/index.d.ts +5 -1
- package/package.json +1 -1
- package/dist/markdown/index.d.ts +0 -2
package/dist/app/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Middleware } from "../http";
|
|
1
|
+
import type { Middleware } from "../runtime";
|
|
3
2
|
export type NestedPartial<T> = T extends any[] ? T : T extends Record<string, any> ? {
|
|
4
3
|
[P in keyof T]?: NestedPartial<T[P]>;
|
|
5
4
|
} : T;
|
|
6
5
|
export type Environment = typeof CLIENT | typeof SERVER;
|
|
6
|
+
export type Virtual = (environment: Environment) => void | string;
|
|
7
|
+
export type ClientEntry = "index.html" | (string & {});
|
|
7
8
|
export type ServerEntry = "revojs/presets/node" | "revojs/presets/deno" | "revojs/presets/bun" | "revojs/presets/cloudflare" | (string & {});
|
|
8
9
|
export type ClientConfig = {
|
|
9
|
-
entry:
|
|
10
|
+
entry: ClientEntry;
|
|
10
11
|
};
|
|
11
12
|
export type ServerConfig = {
|
|
12
13
|
entry: ServerEntry;
|
|
@@ -15,14 +16,13 @@ export type DevelopmentConfig = {
|
|
|
15
16
|
middleware: Array<Middleware>;
|
|
16
17
|
};
|
|
17
18
|
export type Config = {
|
|
18
|
-
client: ClientConfig;
|
|
19
|
+
client: false | ClientConfig;
|
|
19
20
|
server: false | ServerConfig;
|
|
20
|
-
markdown: Record<string, Template>;
|
|
21
21
|
dev: DevelopmentConfig;
|
|
22
22
|
};
|
|
23
23
|
export type App = {
|
|
24
24
|
config: Config;
|
|
25
|
-
virtuals: Record<string,
|
|
25
|
+
virtuals: Record<string, Virtual>;
|
|
26
26
|
};
|
|
27
27
|
export declare const createApp: (config?: NestedPartial<Config>) => App;
|
|
28
28
|
export declare const SERVER = "ssr";
|
package/dist/http/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type ResponseOptions = {
|
|
|
19
19
|
headers: Headers;
|
|
20
20
|
};
|
|
21
21
|
export type Handle = (scope: Scope) => void | Response | Promise<void | Response>;
|
|
22
|
-
export type
|
|
22
|
+
export type Chain = (scope: Scope, next: Handle) => void | Response | Promise<void | Response>;
|
|
23
23
|
export declare const sendText: (scope: Scope, text: string) => Response;
|
|
24
24
|
export declare const sendHtml: (scope: Scope, text: string) => Response;
|
|
25
25
|
export declare const sendJson: <T>(scope: Scope, value: T) => Response;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ const createApp = (config) => {
|
|
|
7
7
|
config: defu(config, {
|
|
8
8
|
client: { entry: "./index.html" },
|
|
9
9
|
server: { entry: "revojs/presets/node" },
|
|
10
|
-
markdown: {},
|
|
11
10
|
dev: { middleware: [] }
|
|
12
11
|
}),
|
|
13
12
|
virtuals: {}
|
|
@@ -412,7 +411,7 @@ const toCustomElement = (Component) => {
|
|
|
412
411
|
internals: this.internals
|
|
413
412
|
});
|
|
414
413
|
await hydrate(this.component.scope, rootNode, await this.component.setup(), 0);
|
|
415
|
-
this.dispatchEvent(new MountedEvent());
|
|
414
|
+
requestAnimationFrame(() => this.dispatchEvent(new MountedEvent()));
|
|
416
415
|
}
|
|
417
416
|
attributeChangedCallback(name, oldValue, value) {
|
|
418
417
|
if (value === oldValue) return;
|
|
@@ -521,6 +520,9 @@ const useRoute = (scope) => {
|
|
|
521
520
|
const defineRoute = (route) => {
|
|
522
521
|
return route;
|
|
523
522
|
};
|
|
523
|
+
const defineMiddleware = (middleware) => {
|
|
524
|
+
return middleware;
|
|
525
|
+
};
|
|
524
526
|
const fileName = (path) => {
|
|
525
527
|
return path.split("/").pop()?.split(".").slice(0, -1).join(".");
|
|
526
528
|
};
|
|
@@ -567,11 +569,18 @@ const createRuntime = async () => {
|
|
|
567
569
|
const assets = await import("#virtual/assets").then((module) => module.assets);
|
|
568
570
|
for (const path in assets) radix.insert("GET/" + path, defineRoute({ fetch: async (scope) => {
|
|
569
571
|
const { response } = useRuntime(scope);
|
|
572
|
+
let content = await assets[path]?.();
|
|
573
|
+
if (content) {
|
|
574
|
+
if (path.endsWith(".png")) {
|
|
575
|
+
const [_, base64] = content.split(",");
|
|
576
|
+
content = Buffer.from(base64, "base64url");
|
|
577
|
+
}
|
|
578
|
+
}
|
|
570
579
|
response.headers.set("Content-Type", mimeType(path));
|
|
571
|
-
return new Response(
|
|
580
|
+
return new Response(content, response);
|
|
572
581
|
} }));
|
|
573
|
-
const invoke = (scope,
|
|
574
|
-
return middlewares.at(index)?.(scope, () => invoke(scope,
|
|
582
|
+
const invoke = (scope, route, index) => {
|
|
583
|
+
return middlewares.at(index)?.fetch(scope, () => invoke(scope, route, index + 1)) ?? route.fetch(scope);
|
|
575
584
|
};
|
|
576
585
|
return {
|
|
577
586
|
radix,
|
|
@@ -583,7 +592,7 @@ const createRuntime = async () => {
|
|
|
583
592
|
try {
|
|
584
593
|
scope.setContext(ROUTE_CONTEXT, { inputs: createState(inputs) });
|
|
585
594
|
if (route) {
|
|
586
|
-
const response = await invoke(scope, route
|
|
595
|
+
const response = await invoke(scope, route, 0);
|
|
587
596
|
if (response) return response;
|
|
588
597
|
}
|
|
589
598
|
return sendText(scope, "NOT_FOUND");
|
|
@@ -636,7 +645,7 @@ const useRequestUrl = (scope, base) => {
|
|
|
636
645
|
};
|
|
637
646
|
const useCookies = (scope) => {
|
|
638
647
|
const { request } = useRuntime(scope);
|
|
639
|
-
return (request.headers.get("Cookie")
|
|
648
|
+
return (isClient() ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
|
|
640
649
|
const [name, value] = cookie.split("=");
|
|
641
650
|
if (name && value) result[name] = decodeURIComponent(value);
|
|
642
651
|
return result;
|
|
@@ -661,7 +670,8 @@ const setCookie = (scope, name, value, options) => {
|
|
|
661
670
|
if (options?.priority) cookie += `; Priority=${options.priority}`;
|
|
662
671
|
if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
|
|
663
672
|
if (options?.secure) cookie += `; Secure`;
|
|
664
|
-
|
|
673
|
+
if (isClient()) document.cookie = cookie;
|
|
674
|
+
else response.headers.append("Set-Cookie", cookie);
|
|
665
675
|
};
|
|
666
676
|
const mimeType = (file) => {
|
|
667
677
|
const extension = /\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1);
|
|
@@ -835,97 +845,4 @@ const useLocale = (scope, context) => {
|
|
|
835
845
|
};
|
|
836
846
|
|
|
837
847
|
//#endregion
|
|
838
|
-
|
|
839
|
-
const charWhile = (buffer, start, ...chars) => {
|
|
840
|
-
let depth = 0;
|
|
841
|
-
let current = buffer.at(start + depth);
|
|
842
|
-
while (current && chars.includes(current)) {
|
|
843
|
-
depth += 1;
|
|
844
|
-
current = buffer.at(start + depth);
|
|
845
|
-
}
|
|
846
|
-
return depth;
|
|
847
|
-
};
|
|
848
|
-
const charUntil = (buffer, start, ...chars) => {
|
|
849
|
-
let depth = 0;
|
|
850
|
-
let current = buffer.at(start + depth);
|
|
851
|
-
while (current && !chars.includes(current)) {
|
|
852
|
-
depth += 1;
|
|
853
|
-
current = buffer.at(start + depth);
|
|
854
|
-
}
|
|
855
|
-
return depth;
|
|
856
|
-
};
|
|
857
|
-
const inlineText = (buffer, options) => {
|
|
858
|
-
const nodes = new Array();
|
|
859
|
-
let index = 0;
|
|
860
|
-
while (index < buffer.length) {
|
|
861
|
-
const char = buffer.charAt(index);
|
|
862
|
-
const text = charUntil(buffer, index, "*", "_", "\n");
|
|
863
|
-
if (text > 0) {
|
|
864
|
-
nodes.push(buffer.slice(index, index + text));
|
|
865
|
-
index += text;
|
|
866
|
-
continue;
|
|
867
|
-
}
|
|
868
|
-
if (char === "*" || char === "_") {
|
|
869
|
-
const start = charWhile(buffer, index, char);
|
|
870
|
-
const between = charUntil(buffer, index + start, char);
|
|
871
|
-
const end = charWhile(buffer, index + start + between, char);
|
|
872
|
-
const min = Math.min(start, end, 2);
|
|
873
|
-
const leading = start - min;
|
|
874
|
-
const trailing = end - min;
|
|
875
|
-
const slice = buffer.slice(index + leading + min, index + start + between + end - trailing - min);
|
|
876
|
-
if (slice.length > 0) {
|
|
877
|
-
const inline = inlineText(char.repeat(leading) + slice + char.repeat(trailing), options);
|
|
878
|
-
const tag = min === 2 ? "strong" : "em";
|
|
879
|
-
nodes.push(defu(options?.[tag], {
|
|
880
|
-
tag,
|
|
881
|
-
attributes: {},
|
|
882
|
-
children: inline
|
|
883
|
-
}));
|
|
884
|
-
}
|
|
885
|
-
index += start + between + end;
|
|
886
|
-
continue;
|
|
887
|
-
}
|
|
888
|
-
if (char === "\n") {
|
|
889
|
-
nodes.push(defu(options?.["br"], {
|
|
890
|
-
tag: "br",
|
|
891
|
-
attributes: {},
|
|
892
|
-
children: []
|
|
893
|
-
}));
|
|
894
|
-
index += 1;
|
|
895
|
-
continue;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
return nodes;
|
|
899
|
-
};
|
|
900
|
-
const markdownToSlot = (input, options) => {
|
|
901
|
-
const nodes = new Array();
|
|
902
|
-
const buffer = input.replace(/[\r]+/g, "").trim();
|
|
903
|
-
let index = 0;
|
|
904
|
-
while (index < buffer.length) {
|
|
905
|
-
const start = index;
|
|
906
|
-
let lines = charWhile(buffer, index, "\n");
|
|
907
|
-
while (lines < 2 && index < buffer.length) {
|
|
908
|
-
index += lines + charUntil(buffer, index + lines, "\n");
|
|
909
|
-
lines = charWhile(buffer, index, "\n");
|
|
910
|
-
}
|
|
911
|
-
const block = buffer.slice(start, index);
|
|
912
|
-
if (block.startsWith("#")) {
|
|
913
|
-
const depth = charWhile(block, 0, "#");
|
|
914
|
-
const tag = "h" + depth;
|
|
915
|
-
nodes.push(defu(options?.[tag], {
|
|
916
|
-
tag,
|
|
917
|
-
attributes: {},
|
|
918
|
-
children: inlineText(block.slice(depth))
|
|
919
|
-
}));
|
|
920
|
-
} else nodes.push(defu(options?.["p"], {
|
|
921
|
-
tag: "p",
|
|
922
|
-
attributes: {},
|
|
923
|
-
children: inlineText(block)
|
|
924
|
-
}));
|
|
925
|
-
index += lines;
|
|
926
|
-
}
|
|
927
|
-
return nodes;
|
|
928
|
-
};
|
|
929
|
-
|
|
930
|
-
//#endregion
|
|
931
|
-
export { $fetch, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, hydrate, isClient, isServer, isTemplate, markdownToSlot, mimeType, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useCookies, useEvent, useHost, useLocale, useRequestUrl, useRoute, useRouter, useRuntime, useSetCookies };
|
|
848
|
+
export { $fetch, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isServer, isTemplate, mimeType, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useCookies, useEvent, useHost, useLocale, useRequestUrl, useRoute, useRouter, useRuntime, useSetCookies };
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Chain, type Handle, type ResponseOptions } from "../http";
|
|
2
2
|
import { Radix } from "../radix";
|
|
3
3
|
import { Scope, type State } from "../signals";
|
|
4
4
|
export type Route = {
|
|
5
5
|
fetch: Handle;
|
|
6
6
|
};
|
|
7
|
+
export type Middleware = {
|
|
8
|
+
fetch: Chain;
|
|
9
|
+
};
|
|
7
10
|
export type Runtime = {
|
|
8
11
|
radix: Radix<Route>;
|
|
9
12
|
middlewares: Array<Middleware>;
|
|
@@ -20,6 +23,7 @@ export type RouteContext = {
|
|
|
20
23
|
export declare const useRuntime: <T = Record<string, unknown>>(scope: Scope) => RuntimeContext<T>;
|
|
21
24
|
export declare const useRoute: (scope: Scope) => RouteContext;
|
|
22
25
|
export declare const defineRoute: (route: Route) => Route;
|
|
26
|
+
export declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
23
27
|
export declare const fileName: (path: string) => string | undefined;
|
|
24
28
|
export declare const toPath: (value: string) => (string | undefined)[];
|
|
25
29
|
export declare const $fetch: <T>(scope: Scope, input: string | URL, options?: RequestInit) => Promise<T>;
|
package/package.json
CHANGED
package/dist/markdown/index.d.ts
DELETED