transone 0.1.0
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/README.md +17 -0
- package/dist/core/app.d.ts +114 -0
- package/dist/core/component/base.d.ts +79 -0
- package/dist/core/component/index.d.ts +4 -0
- package/dist/core/component.d.ts +1 -0
- package/dist/core/document.d.ts +32 -0
- package/dist/core/form.d.ts +24 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/model.d.ts +18 -0
- package/dist/core/reactive/scheduler.d.ts +32 -0
- package/dist/core/reactive/types.d.ts +24 -0
- package/dist/core/reactive.d.ts +77 -0
- package/dist/core/renderer/element-strategy.d.ts +32 -0
- package/dist/core/renderer/props.d.ts +9 -0
- package/dist/core/renderer/types.d.ts +37 -0
- package/dist/core/renderer.d.ts +43 -0
- package/dist/core/template.d.ts +50 -0
- package/dist/core/vnode.d.ts +104 -0
- package/dist/dom/index.d.ts +612 -0
- package/dist/dom/index.js +4 -0
- package/dist/dom/index.js.map +10 -0
- package/dist/index-3t506ckz.js +12 -0
- package/dist/index-3t506ckz.js.map +25 -0
- package/dist/index-mbmajrpr.js +26 -0
- package/dist/index-mbmajrpr.js.map +11 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +11 -0
- package/dist/router/history.d.ts +5 -0
- package/dist/router/index.d.ts +112 -0
- package/dist/router/index.js +4 -0
- package/dist/router/index.js.map +9 -0
- package/dist/router/instance.d.ts +26 -0
- package/dist/router/matcher.d.ts +7 -0
- package/dist/style/StyleManager.d.ts +18 -0
- package/dist/style/class-style.d.ts +0 -0
- package/dist/style/id-style.d.ts +0 -0
- package/dist/style/index.d.ts +2 -0
- package/dist/style/index.js +4 -0
- package/dist/style/index.js.map +9 -0
- package/dist/style/sheet.d.ts +13 -0
- package/dist/style/style.d.ts +0 -0
- package/package.json +59 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { AnyComponentConstructor, Component } from '../core/component';
|
|
2
|
+
import { OneApp } from '../core/app';
|
|
3
|
+
import type { VNode } from '../core/vnode';
|
|
4
|
+
export { useRouter } from './instance';
|
|
5
|
+
export type RouteMeta = Record<string, unknown>;
|
|
6
|
+
export interface RouteRecord {
|
|
7
|
+
path: string;
|
|
8
|
+
component?: AnyComponentConstructor;
|
|
9
|
+
redirect?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
meta?: RouteMeta;
|
|
12
|
+
}
|
|
13
|
+
export interface RouterOptions {
|
|
14
|
+
routes: RouteRecord[];
|
|
15
|
+
mode?: 'history' | 'hash';
|
|
16
|
+
base?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface RouteLocation {
|
|
19
|
+
path: string;
|
|
20
|
+
query: Record<string, string>;
|
|
21
|
+
params: Record<string, string>;
|
|
22
|
+
fullPath: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
meta?: RouteMeta;
|
|
25
|
+
}
|
|
26
|
+
export type RouteChangeListener = (to: RouteLocation, from: RouteLocation | null) => void;
|
|
27
|
+
/**
|
|
28
|
+
* 导航守卫。返回 false 取消导航;返回字符串表示重定向到该路径;
|
|
29
|
+
* 返回 true 或 undefined 放行。
|
|
30
|
+
*/
|
|
31
|
+
export type NavigationGuard = (to: RouteLocation, from: RouteLocation | null) => boolean | void | string;
|
|
32
|
+
export declare class Router {
|
|
33
|
+
protected currentRoute: RouteRecord | null;
|
|
34
|
+
protected currentLocation: RouteLocation | null;
|
|
35
|
+
private readonly routes;
|
|
36
|
+
private app;
|
|
37
|
+
private readonly mode;
|
|
38
|
+
private readonly base;
|
|
39
|
+
private readonly routeChangeListeners;
|
|
40
|
+
private readonly beforeGuards;
|
|
41
|
+
private readonly afterHooks;
|
|
42
|
+
private removeWindowListener?;
|
|
43
|
+
constructor(options: RouterOptions | RouteRecord[]);
|
|
44
|
+
install(app: OneApp): void;
|
|
45
|
+
push(path: string): void;
|
|
46
|
+
replace(path: string): void;
|
|
47
|
+
forward(): void;
|
|
48
|
+
back(): void;
|
|
49
|
+
go(delta: number): void;
|
|
50
|
+
getCurrentRoute(): RouteLocation | null;
|
|
51
|
+
getCurrentRouteRecord(): RouteRecord | null;
|
|
52
|
+
onRouteChange(listener: RouteChangeListener): () => void;
|
|
53
|
+
/**
|
|
54
|
+
* 注册全局前置守卫;返回移除该守卫的函数。
|
|
55
|
+
*/
|
|
56
|
+
beforeEach(guard: NavigationGuard): () => void;
|
|
57
|
+
/**
|
|
58
|
+
* 注册导航完成后钩子;返回移除该钩子的函数。
|
|
59
|
+
*/
|
|
60
|
+
afterEach(hook: RouteChangeListener): () => void;
|
|
61
|
+
getRoutes(): RouteRecord[];
|
|
62
|
+
addRoute(route: RouteRecord): void;
|
|
63
|
+
createHref(path: string): string;
|
|
64
|
+
destroy(): void;
|
|
65
|
+
private navigate;
|
|
66
|
+
/**
|
|
67
|
+
* 解析导航目标:应用 redirect 链后返回最终路径、路由与 location。
|
|
68
|
+
*/
|
|
69
|
+
private resolveTarget;
|
|
70
|
+
/**
|
|
71
|
+
* 沿 redirect 链解析到最终路由(防循环)。
|
|
72
|
+
*/
|
|
73
|
+
private applyRedirect;
|
|
74
|
+
private validateRoutes;
|
|
75
|
+
private initEvents;
|
|
76
|
+
private handleRouteChange;
|
|
77
|
+
private resolveCurrentRoute;
|
|
78
|
+
private getCurrentLocation;
|
|
79
|
+
private isSameLocation;
|
|
80
|
+
private triggerRouteChangeListeners;
|
|
81
|
+
}
|
|
82
|
+
export interface RouterLinkProps {
|
|
83
|
+
to: string;
|
|
84
|
+
replace?: boolean;
|
|
85
|
+
className?: string;
|
|
86
|
+
activeClass?: string;
|
|
87
|
+
children?: Array<VNode | string>;
|
|
88
|
+
}
|
|
89
|
+
interface RouterLinkState {
|
|
90
|
+
currentPath: string;
|
|
91
|
+
}
|
|
92
|
+
export declare class RouterLink extends Component<RouterLinkProps, RouterLinkState> {
|
|
93
|
+
private unsubscribe?;
|
|
94
|
+
protected initState(): RouterLinkState;
|
|
95
|
+
protected initStyles(): void;
|
|
96
|
+
protected onMounted(): void;
|
|
97
|
+
protected onUnmounted(): void;
|
|
98
|
+
protected render(): VNode;
|
|
99
|
+
}
|
|
100
|
+
interface RouterViewState {
|
|
101
|
+
route: RouteLocation | null;
|
|
102
|
+
record: RouteRecord | null;
|
|
103
|
+
}
|
|
104
|
+
export declare class RouterView extends Component<object, RouterViewState> {
|
|
105
|
+
private unsubscribe?;
|
|
106
|
+
protected initState(): RouterViewState;
|
|
107
|
+
protected initStyles(): void;
|
|
108
|
+
protected onMounted(): void;
|
|
109
|
+
protected onUnmounted(): void;
|
|
110
|
+
protected render(): VNode;
|
|
111
|
+
}
|
|
112
|
+
export declare function createRouter(options: RouterOptions | RouteRecord[]): Router;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Router } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* 设置全局路由实例
|
|
4
|
+
* @param r 路由实例
|
|
5
|
+
*/
|
|
6
|
+
export declare function setRouter(r: Router): void;
|
|
7
|
+
/**
|
|
8
|
+
* 获取路由实例
|
|
9
|
+
* @returns 路由实例
|
|
10
|
+
* @throws 当路由未初始化时抛出错误
|
|
11
|
+
*/
|
|
12
|
+
export declare function useRouter(): Router;
|
|
13
|
+
/**
|
|
14
|
+
* 安全地获取路由实例,如果未初始化则返回null
|
|
15
|
+
* @returns 路由实例或null
|
|
16
|
+
*/
|
|
17
|
+
export declare function getRouter(): Router | null;
|
|
18
|
+
/**
|
|
19
|
+
* 检查路由是否已初始化
|
|
20
|
+
* @returns 是否已初始化
|
|
21
|
+
*/
|
|
22
|
+
export declare function hasRouter(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 重置路由实例(主要用于测试)
|
|
25
|
+
*/
|
|
26
|
+
export declare function resetRouter(): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RouteRecord } from './index';
|
|
2
|
+
export interface RouteMatch {
|
|
3
|
+
route: RouteRecord;
|
|
4
|
+
params: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export declare function normalizePath(path: string): string;
|
|
7
|
+
export declare function matchRoute(routes: RouteRecord[], path: string): RouteMatch | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface StyleOptions {
|
|
2
|
+
selector: string;
|
|
3
|
+
properties: Record<string, string | number>;
|
|
4
|
+
hover?: Record<string, string | number>;
|
|
5
|
+
media?: Record<string, Record<string, string | number>>;
|
|
6
|
+
}
|
|
7
|
+
export declare class StyleManager {
|
|
8
|
+
styleElement: HTMLStyleElement | null;
|
|
9
|
+
styles: Map<string, StyleOptions>;
|
|
10
|
+
constructor();
|
|
11
|
+
addStyle(name: string, options: StyleOptions): void;
|
|
12
|
+
removeStyle(name: string): void;
|
|
13
|
+
clearStyles(): void;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
private ensureStyleElement;
|
|
16
|
+
private convertToCSS;
|
|
17
|
+
private updateStyles;
|
|
18
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type StyleValue = string | number;
|
|
2
|
+
export type StyleProperties = Record<string, StyleValue>;
|
|
3
|
+
export interface StyleRule {
|
|
4
|
+
selector: string;
|
|
5
|
+
properties: StyleProperties;
|
|
6
|
+
}
|
|
7
|
+
export interface StyleAtRule {
|
|
8
|
+
atRule: string;
|
|
9
|
+
rules: StyleRule[];
|
|
10
|
+
}
|
|
11
|
+
export type StyleSheetEntry = StyleRule | StyleAtRule;
|
|
12
|
+
export type StyleSheet = StyleSheetEntry[];
|
|
13
|
+
export declare function renderStyleSheet(styles: StyleSheet): string;
|
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "transone",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TransOne 是跨端前端框架:一份 TypeScript 源码,编译期静态转换为 Web 与多端小程序原生产物,产物不携带框架运行时",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./router": {
|
|
15
|
+
"import": "./dist/router/index.js",
|
|
16
|
+
"types": "./dist/router/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./style": {
|
|
19
|
+
"import": "./dist/style/index.js",
|
|
20
|
+
"types": "./dist/style/index.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./dom": {
|
|
23
|
+
"import": "./dist/dom/index.js",
|
|
24
|
+
"types": "./dist/dom/index.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "bun scripts/build.ts",
|
|
29
|
+
"build:types": "bunx tsc --project tsconfig.build.json",
|
|
30
|
+
"lint": "eslint . --ext .ts",
|
|
31
|
+
"format": "prettier --write . --ignore-path .gitignore",
|
|
32
|
+
"test": "bun test"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"typescript",
|
|
36
|
+
"cross-platform",
|
|
37
|
+
"frontend",
|
|
38
|
+
"framework",
|
|
39
|
+
"reactive",
|
|
40
|
+
"component",
|
|
41
|
+
"router",
|
|
42
|
+
"miniprogram",
|
|
43
|
+
"transpile"
|
|
44
|
+
],
|
|
45
|
+
"author": "Jimmie Max(Qianyu)",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"engines": {
|
|
48
|
+
"bun": ">=1.3.0"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"README.md",
|
|
53
|
+
"LICENSE"
|
|
54
|
+
],
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"registry": "https://registry.npmjs.org/"
|
|
58
|
+
}
|
|
59
|
+
}
|