@thestarweb/star-framework-app-web 1.1.1 → 1.1.3
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/CHANGELOG.md +19 -0
- package/package.json +3 -3
- package/resource/base-style.css +27 -0
- package/src/cli/index.ts +14 -1
- package/src/index.ts +1 -1
- package/src/return-types/index.ts +1 -0
- package/src/return-types/location-to.ts +8 -0
- package/src/view/const.ts +1 -0
- package/src/view/utils/get-render/client.ts +14 -1
- package/src/view/utils/get-render/server.ts +4 -0
- package/src/view/utils/loading-progress.ts +58 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.1.3](https://github.com/star-ss-qaq/star-node-framework/compare/@thestarweb/star-framework-app-web@1.1.2...@thestarweb/star-framework-app-web@1.1.3) (2026-11-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* 增加加载进度 ([f90531d](https://github.com/star-ss-qaq/star-node-framework/commit/f90531da1725f8da50a6d9ae675c5216dc3e51ea))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [1.1.2](https://github.com/star-ss-qaq/star-node-framework/compare/@thestarweb/star-framework-app-web@1.1.0...@thestarweb/star-framework-app-web@1.1.2) (2026-11-01)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @thestarweb/star-framework-app-web
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [1.1.1](https://github.com/star-ss-qaq/star-node-framework/compare/@thestarweb/star-framework-app-web@1.1.0...@thestarweb/star-framework-app-web@1.1.1) (2026-11-01)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @thestarweb/star-framework-app-web
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thestarweb/star-framework-app-web",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Star Framework Web App",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@deepkit/type-compiler": "^1.0.0",
|
|
19
19
|
"@thestarweb/star-framework-cli": "^1.1.2",
|
|
20
20
|
"@thestarweb/star-framework-param-helper": "^1.0.1",
|
|
21
|
-
"@thestarweb/star-framework-route": "^1.0.
|
|
21
|
+
"@thestarweb/star-framework-route": "^1.0.3",
|
|
22
22
|
"@thestarweb/star-framework-utils": "^1.0.1",
|
|
23
23
|
"@thestarweb/star-framework-web-runtime-node": "^1.0.2",
|
|
24
24
|
"node-mocks-http": "^1.18.1",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"README.md"
|
|
45
45
|
],
|
|
46
46
|
"license": "ISC",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "2a9c61c68d5a58c269cb50474bf22290fe1c6a57"
|
|
48
48
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@layer sf-app-web {
|
|
2
|
+
sf-route {
|
|
3
|
+
display: contents;
|
|
4
|
+
}
|
|
5
|
+
.sf-page-loading-progress {
|
|
6
|
+
position: fixed;
|
|
7
|
+
top: 0;
|
|
8
|
+
left: 0;
|
|
9
|
+
width: 100vw;
|
|
10
|
+
height: 2px;
|
|
11
|
+
background-color: #f0f0f0;
|
|
12
|
+
display: none;
|
|
13
|
+
--progress: 0;
|
|
14
|
+
--transition-time: 0.2;
|
|
15
|
+
}
|
|
16
|
+
.sf-page-loading-progress span {
|
|
17
|
+
content: "";
|
|
18
|
+
display: inline-block;
|
|
19
|
+
position: absolute;
|
|
20
|
+
left: 0;
|
|
21
|
+
top: 0;
|
|
22
|
+
height: 100%;
|
|
23
|
+
background-color: #1890ff;
|
|
24
|
+
width: calc(var(--progress) * 100%);
|
|
25
|
+
transition: width calc(var(--transition-time) * 1s);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/cli/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { writeFile } from "fs/promises";
|
|
|
5
5
|
import { readFileSync } from "fs";
|
|
6
6
|
import { PackageInfo } from "@thestarweb/star-framework-web-runtime-node";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
|
+
import { parseHtmlToVDom, renderVDomToString } from "../view/html/index.js";
|
|
8
9
|
|
|
9
10
|
export * from "./types.js";
|
|
10
11
|
const __file = fileURLToPath(import.meta.url);
|
|
@@ -19,7 +20,19 @@ export function SFWebPlugin({
|
|
|
19
20
|
|
|
20
21
|
let html = "";
|
|
21
22
|
try {
|
|
22
|
-
|
|
23
|
+
const sysScript = `<script type="module">import "sf:main"</script>`;
|
|
24
|
+
const sysStyle = `<style>${readFileSync(join(__dir, "../../resource/base-style.css"), "utf-8")}</style>`;
|
|
25
|
+
// const sysStyle = `<link rel="stylesheet" href=${JSON.stringify(join(__dir, "../../resource/base-style.css"))}>`;
|
|
26
|
+
html = renderVDomToString(
|
|
27
|
+
parseHtmlToVDom(readFileSync(htmlPath, "utf-8")),
|
|
28
|
+
{
|
|
29
|
+
customizeChildrenRender(dom) {
|
|
30
|
+
if (dom.tagName === "head") {
|
|
31
|
+
return (dom, raw) => `${raw()}${sysScript}${sysStyle}`;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
);
|
|
23
36
|
} catch {
|
|
24
37
|
throw new Error("未能找到html文件");
|
|
25
38
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { Get, Post, Put, Delete, SubRoute } from "./route/index.js";
|
|
|
2
2
|
export { Body, Query, Header, Param } from "./params/index.js";
|
|
3
3
|
// @side-only server
|
|
4
4
|
export { SFWebPlugin } from "./cli/index.js";
|
|
5
|
-
export { ResponseWithMeta } from "./return-types/index.js";
|
|
5
|
+
export { ResponseWithMeta, LocationTo } from "./return-types/index.js";
|
|
6
6
|
export { AddInterceptor, type Interceptor } from "./interceptor/index.js";
|
|
7
7
|
export {
|
|
8
8
|
View,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { redirectStatusCode } from "../view/const.js";
|
|
2
|
+
import { ResponseWithMeta } from "./response-with-meta.js";
|
|
3
|
+
|
|
4
|
+
export class LocationTo extends ResponseWithMeta {
|
|
5
|
+
constructor(path: string, code: (typeof redirectStatusCode)[number] = 302) {
|
|
6
|
+
super(undefined, { code, header: { Location: path } });
|
|
7
|
+
}
|
|
8
|
+
}
|
package/src/view/const.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { parseRoute } from "../../../route/index.js";
|
|
2
|
+
import { redirectStatusCode } from "../../const.js";
|
|
2
3
|
import { RenderContext } from "../../render/index.js";
|
|
3
4
|
import { RenderConfig, ViewMeta } from "../../types.js";
|
|
4
5
|
import { findRouteDom } from "../find-route-dom.js";
|
|
6
|
+
import { LoadingProgress } from "../loading-progress.js";
|
|
5
7
|
import {
|
|
6
8
|
createRootRenderContext,
|
|
7
9
|
ssrToBrowserDataKey,
|
|
@@ -28,7 +30,16 @@ export const clientRender = async (routes: ReturnType<typeof parseRoute>) => {
|
|
|
28
30
|
delete (window as any)[ssrToBrowserDataKey];
|
|
29
31
|
const route = routes("GET", location.pathname);
|
|
30
32
|
const getData = async () => {
|
|
31
|
-
const res = await fetch(location.href);
|
|
33
|
+
const res = await fetch(location.href, { redirect: "manual" });
|
|
34
|
+
if (res.type === "opaqueredirect") {
|
|
35
|
+
console.log(
|
|
36
|
+
"this page is redirect, however, we can not get the redirect url, so we can only reload the page for redirect from server",
|
|
37
|
+
);
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
location.reload();
|
|
40
|
+
}, 3000);
|
|
41
|
+
return new Promise(() => {});
|
|
42
|
+
}
|
|
32
43
|
if (res.headers.get("content-type")?.includes("json")) {
|
|
33
44
|
return await res.json();
|
|
34
45
|
}
|
|
@@ -38,8 +49,10 @@ export const clientRender = async (routes: ReturnType<typeof parseRoute>) => {
|
|
|
38
49
|
handleMeta(context.meta);
|
|
39
50
|
listenerRoute(async () => {
|
|
40
51
|
const route = routes("GET", location.pathname);
|
|
52
|
+
LoadingProgress.instance.start();
|
|
41
53
|
const c = await updateRootRenderContext(context, route, getData);
|
|
42
54
|
handleMeta(c.meta);
|
|
55
|
+
LoadingProgress.instance.end();
|
|
43
56
|
});
|
|
44
57
|
const addedEl = new WeakSet<HTMLAnchorElement>();
|
|
45
58
|
function handleAClick(this: HTMLAnchorElement, ev: MouseEvent) {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ssrToBrowserDataKey,
|
|
9
9
|
} from "./common.js";
|
|
10
10
|
import { RenderConfig } from "../../types.js";
|
|
11
|
+
import { redirectStatusCode } from "../../const.js";
|
|
11
12
|
|
|
12
13
|
export const createServerRender: (
|
|
13
14
|
context: ServerRuntimeContext,
|
|
@@ -33,6 +34,9 @@ export const createServerRender: (
|
|
|
33
34
|
if (rootContext) {
|
|
34
35
|
const { render, meta } = rootContext;
|
|
35
36
|
const nextRet = await nextPromise;
|
|
37
|
+
if ((redirectStatusCode as readonly any[]).includes(nextRet.code)) {
|
|
38
|
+
return nextRet;
|
|
39
|
+
}
|
|
36
40
|
const res = await render.warpRenderToString({});
|
|
37
41
|
return new ResponseWithMeta(
|
|
38
42
|
renderVDomToString(htmlVDdom, {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export class LoadingProgress {
|
|
2
|
+
private div = document.createElement("div");
|
|
3
|
+
private span = document.createElement("span");
|
|
4
|
+
private constructor() {
|
|
5
|
+
this.div.className = "sf-page-loading-progress";
|
|
6
|
+
this.div.append(this.span);
|
|
7
|
+
document.body.append(this.div);
|
|
8
|
+
this.span.addEventListener("transitionend", () => {
|
|
9
|
+
if (this.progress >= 100) {
|
|
10
|
+
this.div.style.display = "none";
|
|
11
|
+
} else {
|
|
12
|
+
this.progress = 1 - (1 - this.progress) * 0.9;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
static _instance: LoadingProgress;
|
|
17
|
+
static get instance() {
|
|
18
|
+
if (!this._instance) {
|
|
19
|
+
this._instance = new LoadingProgress();
|
|
20
|
+
}
|
|
21
|
+
return this._instance;
|
|
22
|
+
}
|
|
23
|
+
private _progress = 0;
|
|
24
|
+
get progress() {
|
|
25
|
+
return this._progress;
|
|
26
|
+
}
|
|
27
|
+
set progress(value: number) {
|
|
28
|
+
this._progress = value;
|
|
29
|
+
this.div.style.setProperty("--progress", this._progress.toString());
|
|
30
|
+
}
|
|
31
|
+
set transitionTime(value: number) {
|
|
32
|
+
this.div.style.setProperty("--transition-time", value.toString());
|
|
33
|
+
}
|
|
34
|
+
timeout?: NodeJS.Timeout;
|
|
35
|
+
interval?: NodeJS.Timeout;
|
|
36
|
+
private stop() {
|
|
37
|
+
clearTimeout(this.timeout);
|
|
38
|
+
clearInterval(this.interval);
|
|
39
|
+
}
|
|
40
|
+
start() {
|
|
41
|
+
this.stop();
|
|
42
|
+
this.div.style.display = "block";
|
|
43
|
+
this.transitionTime = 0;
|
|
44
|
+
this.progress = 0;
|
|
45
|
+
this.timeout = setTimeout(() => {
|
|
46
|
+
this.transitionTime = 2;
|
|
47
|
+
this.progress = 0.2;
|
|
48
|
+
}, 100);
|
|
49
|
+
}
|
|
50
|
+
end() {
|
|
51
|
+
if (this.progress <= 0.2) {
|
|
52
|
+
this.div.style.display = "none";
|
|
53
|
+
}
|
|
54
|
+
this.stop();
|
|
55
|
+
this.transitionTime = 0.2;
|
|
56
|
+
this.progress = 100;
|
|
57
|
+
}
|
|
58
|
+
}
|