ranuts 0.1.0-alpha → 0.1.0-alpha.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.
- package/assets/img/sort/bubble.gif +0 -0
- package/assets/img/sort/complexity.png +0 -0
- package/assets/img/sort/select.gif +0 -0
- package/assets/img/sort/sort.png +0 -0
- package/assets/img/tree/balanceTree.png +0 -0
- package/dist/index.d.ts +15 -8
- package/dist/index.js +1078 -44
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/dist/src/file/fileInfo.d.ts +7 -0
- package/dist/src/file/fs.d.ts +2 -0
- package/dist/src/file/readDir.d.ts +6 -0
- package/dist/src/file/readFile.d.ts +8 -0
- package/dist/src/file/watchFile.d.ts +8 -0
- package/dist/src/file/writeFile.d.ts +8 -0
- package/dist/src/mode/subscribe.d.ts +16 -0
- package/dist/src/ranlog/behavior.d.ts +1 -0
- package/dist/src/ranlog/env.d.ts +5 -0
- package/dist/src/ranlog/error.d.ts +2 -0
- package/dist/src/ranlog/index.d.ts +26 -0
- package/dist/src/ranlog/performance.d.ts +21 -0
- package/dist/src/ranlog/report.d.ts +7 -0
- package/dist/src/ranlog/request.d.ts +18 -0
- package/dist/src/ranlog/utils.d.ts +19 -0
- package/dist/src/utils/filterObj.d.ts +8 -0
- package/dist/src/utils/str2Xml.d.ts +8 -0
- package/dist/src/vnode/h.d.ts +6 -0
- package/dist/src/vnode/hooks.d.ts +23 -0
- package/dist/src/vnode/htmlDomApi.d.ts +33 -0
- package/dist/src/vnode/init.d.ts +2 -0
- package/dist/src/vnode/is.d.ts +5 -0
- package/dist/src/vnode/modules/attributes.d.ts +8 -0
- package/dist/src/vnode/modules/class.d.ts +8 -0
- package/dist/src/vnode/modules/index.d.ts +7 -0
- package/dist/src/vnode/modules/listeners.d.ts +14 -0
- package/dist/src/vnode/modules/props.d.ts +8 -0
- package/dist/src/vnode/modules/style.d.ts +14 -0
- package/dist/src/vnode/vnode.d.ts +31 -0
- package/package.json +32 -9
- package/readme.md +1 -0
- package/src/astParser/Parser.ts +654 -0
- package/src/astParser/Tokenizer.ts +447 -0
- package/src/astParser/nodeTypes.ts +194 -0
- package/src/astParser/utils.ts +27 -0
- package/src/babel/parser.ts +10 -0
- package/src/colors/fmt.ts +29 -0
- package/src/colors/isColorSupported.ts +13 -0
- package/src/file/appendFile.ts +29 -0
- package/src/file/fileInfo.ts +22 -0
- package/src/file/fs.ts +9 -0
- package/src/file/readDir.ts +18 -0
- package/src/file/readFile.ts +26 -0
- package/src/file/watchFile.ts +31 -0
- package/src/file/writeFile.ts +38 -0
- package/src/mode/subscribe.ts +89 -0
- package/src/ran/commit.ts +0 -0
- package/src/ran/dom.ts +0 -0
- package/src/ran/hooks.ts +0 -0
- package/src/ran/reconcile.ts +0 -0
- package/src/ran/schedule.ts +0 -0
- package/src/ranlog/behavior.ts +5 -0
- package/src/ranlog/console.ts +16 -0
- package/src/ranlog/env.ts +29 -0
- package/src/ranlog/error.ts +11 -0
- package/src/ranlog/performance.ts +65 -0
- package/src/ranlog/report.ts +33 -0
- package/src/ranlog/request.ts +60 -0
- package/src/ranlog/utils.ts +92 -0
- package/src/ranpack/ast/Declaration.ts +120 -0
- package/src/ranpack/ast/Node.ts +7 -0
- package/src/ranpack/ast/Reference.ts +32 -0
- package/src/ranpack/ast/Scope.ts +80 -0
- package/src/ranpack/bundle.ts +50 -0
- package/src/ranpack/graph.ts +143 -0
- package/src/ranpack/module.ts +431 -0
- package/src/ranpack/moduleLoader.ts +73 -0
- package/src/ranpack/plugins.ts +70 -0
- package/src/ranpack/statement.ts +66 -0
- package/src/ranpack/utils/buildScope.ts +77 -0
- package/src/ranpack/utils/findReference.ts +36 -0
- package/src/ranpack/utils/isFunctionDeclaration.ts +41 -0
- package/src/ranpack/utils/makeLegalIdentifier.ts +18 -0
- package/src/ranpack/utils/object.ts +8 -0
- package/src/ranpack/utils/resolve.ts +32 -0
- package/src/ranpack/utils/walk.ts +66 -0
- package/src/ranpack/ws.ts +269 -0
- package/src/server/connectType.ts +9 -0
- package/src/server/encodeUrl.ts +46 -0
- package/src/server/escapeHtml.ts +46 -0
- package/src/server/get.ts +36 -0
- package/src/server/jitter.ts +77 -0
- package/src/server/mimeType.ts +858 -0
- package/src/server/paresUrl.ts +40 -0
- package/src/server/send.ts +89 -0
- package/src/server/server.ts +67 -0
- package/src/server/status.ts +191 -0
- package/src/server/traverse.ts +54 -0
- package/src/server/websocket.ts +200 -0
- package/src/sort/bubble.ts +21 -0
- package/src/sort/bucket.ts +11 -0
- package/src/sort/count.ts +10 -0
- package/src/sort/heap.ts +10 -0
- package/src/sort/insert.ts +20 -0
- package/src/sort/merge.ts +35 -0
- package/src/sort/quick.ts +50 -0
- package/src/sort/radix.ts +11 -0
- package/src/sort/randomArray.ts +21 -0
- package/src/sort/select.ts +23 -0
- package/src/sort/shell.ts +22 -0
- package/src/utils/compose.ts +37 -0
- package/src/utils/filterObj.ts +21 -0
- package/src/utils/mergeObj.ts +12 -0
- package/src/utils/startTask.ts +15 -0
- package/src/utils/str2Xml.ts +26 -0
- package/src/utils/taskEnd.ts +14 -0
- package/src/vnode/h.ts +108 -0
- package/src/vnode/hooks.ts +25 -0
- package/src/vnode/htmlDomApi.ts +199 -0
- package/src/vnode/init.ts +429 -0
- package/src/vnode/is.ts +17 -0
- package/src/vnode/modules/attributes.ts +70 -0
- package/src/vnode/modules/class.ts +46 -0
- package/src/vnode/modules/listeners.ts +123 -0
- package/src/vnode/modules/props.ts +41 -0
- package/src/vnode/modules/style.ts +118 -0
- package/src/vnode/vnode.ts +65 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { VNode, VNodeData } from '../vnode'
|
|
2
|
+
|
|
3
|
+
export type Props = Record<string, any>
|
|
4
|
+
|
|
5
|
+
function updateProps(oldVnode: VNode, vnode: VNode): void {
|
|
6
|
+
// 用于缓存props的name
|
|
7
|
+
let key: string
|
|
8
|
+
// 缓存遍历中当前props的值
|
|
9
|
+
let cur: any
|
|
10
|
+
// 缓存遍历中旧props的值
|
|
11
|
+
let old: any
|
|
12
|
+
// 缓存VNode的dom元素
|
|
13
|
+
const elm = vnode.elm
|
|
14
|
+
// 获取旧VNode的props属性
|
|
15
|
+
let oldProps = oldVnode.data ? oldVnode.data.props : undefined
|
|
16
|
+
// 获取新VNode的props属性
|
|
17
|
+
let props = vnode.data ? vnode.data.props : undefined
|
|
18
|
+
|
|
19
|
+
// 如果新旧VNode都没有props属性,直接返回
|
|
20
|
+
if (!oldProps && !props) return
|
|
21
|
+
// 如果新旧VNode的props属性完全一样,直接返回
|
|
22
|
+
if (oldProps === props) return
|
|
23
|
+
// 如果旧VNode没有props,将其设置为空对象
|
|
24
|
+
oldProps = oldProps || {}
|
|
25
|
+
// 如果新VNode没有props,将其设置为空对象
|
|
26
|
+
props = props || {}
|
|
27
|
+
|
|
28
|
+
// 遍历新VNode的props
|
|
29
|
+
for (key in props) {
|
|
30
|
+
// 缓存当前prop属性的值
|
|
31
|
+
cur = props[key]
|
|
32
|
+
// 缓存旧VNode中同名prop的值
|
|
33
|
+
old = oldProps[key]
|
|
34
|
+
// 如果新旧prop值不同,同时当dom是含有value属性的元素(如:input),当前value值和当前prop值不同时,将值设置为当前prop的值
|
|
35
|
+
if (old !== cur && (key !== 'value' || (elm as any)[key] !== cur)) {
|
|
36
|
+
(elm as any)[key] = cur
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const propsModule = { create: updateProps, update: updateProps }
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { VNode, VNodeData } from '../vnode'
|
|
2
|
+
|
|
3
|
+
export type VNodeStyle = Record<string, any>
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 在snabbdom中style有三个额外的生命周期delayed, remove和destroy,主要是方便我们css动画的使用,而我们terdom是为了学习虚拟dom
|
|
7
|
+
* 的原理,所以这里我删除这两个生命周期,方便源码的阅读。
|
|
8
|
+
* */
|
|
9
|
+
|
|
10
|
+
let reflowForced = false
|
|
11
|
+
|
|
12
|
+
function updateStyle(oldVnode: VNode, vnode: VNode): void {
|
|
13
|
+
// 缓存遍历中当前新VNode中的style
|
|
14
|
+
let cur: any
|
|
15
|
+
// 缓存遍历中当前style的name
|
|
16
|
+
let name: string
|
|
17
|
+
// 获取dom节点
|
|
18
|
+
const elm = vnode.elm
|
|
19
|
+
// 获取旧VNode的style
|
|
20
|
+
let oldStyle = (oldVnode.data as VNodeData).style
|
|
21
|
+
// 获取新VNode的style
|
|
22
|
+
let style = (vnode.data as VNodeData).style
|
|
23
|
+
|
|
24
|
+
// 如果新旧VNode都没有设置style,直接返回
|
|
25
|
+
if (!oldStyle && !style) return
|
|
26
|
+
// 如果新旧VNode的style完全相同,直接返回
|
|
27
|
+
if (oldStyle === style) return
|
|
28
|
+
// 如果没有旧VNode的style,设置为空对象
|
|
29
|
+
oldStyle = oldStyle || {}
|
|
30
|
+
// 如果没有新VNode的style,设置为空对象
|
|
31
|
+
style = style || {}
|
|
32
|
+
|
|
33
|
+
// 遍历旧VNode的style
|
|
34
|
+
for (name in oldStyle) {
|
|
35
|
+
// 如果新VNode中没有相同name的style
|
|
36
|
+
if (!style[name]) {
|
|
37
|
+
if (name[0] === '-' && name[1] === '-') {
|
|
38
|
+
// 如果是以 -- 开头,代表是css变量,使用removeProperty删除
|
|
39
|
+
;(elm as any).style.removeProperty(name)
|
|
40
|
+
} else {
|
|
41
|
+
// 否则直接设为空
|
|
42
|
+
;(elm as any).style[name] = ''
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 遍历新VNode中的style
|
|
48
|
+
for (name in style) {
|
|
49
|
+
// 缓存当前style的值
|
|
50
|
+
cur = style[name]
|
|
51
|
+
if (cur !== oldStyle[name]) {
|
|
52
|
+
if (name[0] === '-' && name[1] === '-') {
|
|
53
|
+
// 如果是以 -- 开头,代表是css变量,使用setProperty设置
|
|
54
|
+
;(elm as any).style.setProperty(name, cur)
|
|
55
|
+
} else {
|
|
56
|
+
// 否则直接设置
|
|
57
|
+
;(elm as any).style[name] = cur
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function forceReflow(): void {
|
|
64
|
+
reflowForced = false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function applyDestroyStyle(vnode: VNode): void {
|
|
68
|
+
let style: any
|
|
69
|
+
let name: string
|
|
70
|
+
const elm = vnode.elm
|
|
71
|
+
const s = (vnode.data as VNodeData).style
|
|
72
|
+
if (!s || !(style = s.destroy)) return
|
|
73
|
+
for (name in style) {
|
|
74
|
+
;(elm as any).style[name] = style[name]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function applyRemoveStyle(vnode: VNode, rm: () => void): void {
|
|
79
|
+
const s = (vnode.data as VNodeData).style
|
|
80
|
+
if (!s || !s.remove) {
|
|
81
|
+
rm()
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
if (!reflowForced) {
|
|
85
|
+
;(vnode.elm as any).offsetLeft
|
|
86
|
+
reflowForced = true
|
|
87
|
+
}
|
|
88
|
+
let name: string
|
|
89
|
+
const elm = vnode.elm
|
|
90
|
+
let i = 0
|
|
91
|
+
const style = s.remove
|
|
92
|
+
let amount = 0
|
|
93
|
+
const applied: string[] = []
|
|
94
|
+
for (name in style) {
|
|
95
|
+
applied.push(name)
|
|
96
|
+
;(elm as any).style[name] = style[name]
|
|
97
|
+
}
|
|
98
|
+
const compStyle = getComputedStyle(elm as Element)
|
|
99
|
+
const props = (compStyle as any)['transition-property'].split(', ')
|
|
100
|
+
for (; i < props.length; ++i) {
|
|
101
|
+
if (applied.indexOf(props[i]) !== -1) amount++
|
|
102
|
+
}
|
|
103
|
+
;(elm as any).addEventListener(
|
|
104
|
+
'transitionend',
|
|
105
|
+
function (ev: TransitionEvent) {
|
|
106
|
+
if (ev.target === elm) --amount
|
|
107
|
+
if (amount === 0) rm()
|
|
108
|
+
},
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const styleModule = {
|
|
113
|
+
pre: forceReflow,
|
|
114
|
+
create: updateStyle,
|
|
115
|
+
update: updateStyle,
|
|
116
|
+
destroy: applyDestroyStyle,
|
|
117
|
+
remove: applyRemoveStyle,
|
|
118
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { On } from './modules/listeners'
|
|
2
|
+
import type { Attrs } from './modules/attributes'
|
|
3
|
+
import type { Classes } from './modules/class'
|
|
4
|
+
import type { Props } from './modules/props'
|
|
5
|
+
import type { VNodeStyle } from './modules/style'
|
|
6
|
+
import type { Hooks } from "./hooks";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export type VNodes = VNode[]
|
|
10
|
+
export type VNodeChildElement = VNode | string | number
|
|
11
|
+
export type ArrayOrElement<T> = T | T[]
|
|
12
|
+
export type VNodeChildren = ArrayOrElement<VNodeChildElement>
|
|
13
|
+
|
|
14
|
+
// key属性类型
|
|
15
|
+
export type Key = string | number
|
|
16
|
+
|
|
17
|
+
type Listener<T> = (this: VNode, ev: T, vnode: VNode) => void
|
|
18
|
+
|
|
19
|
+
// VNode接口
|
|
20
|
+
export interface VNode {
|
|
21
|
+
// dom节点的选择器,
|
|
22
|
+
// 虚拟节点的 .sel 属性通过对 h() 传入一个 CSS 选择器生成,
|
|
23
|
+
// 比如: h('div#container', {}, [...]) 将会创建一个虚拟节点并以 div#container 作为其 .sel 属性的值。
|
|
24
|
+
sel: string | undefined
|
|
25
|
+
// 节点数据
|
|
26
|
+
data: VNodeData | undefined
|
|
27
|
+
// 子节点,和text互斥
|
|
28
|
+
children: Array<VNode | string | number> | undefined
|
|
29
|
+
// 存储VNode转化成的真实dom
|
|
30
|
+
elm: Node | undefined
|
|
31
|
+
// 节点的文本内容,和children互斥
|
|
32
|
+
text: string | number | undefined
|
|
33
|
+
// key,用于优化diff算法
|
|
34
|
+
key: Key | undefined
|
|
35
|
+
listener?: EventListenerOrEventListenerObject | undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface VNodeData {
|
|
39
|
+
// 设置VNode对应的DOM元素的属性,通过 对象.属性 的方式来设置,它内部不会去处理布尔类型的属性
|
|
40
|
+
props?: Props
|
|
41
|
+
// 设置VNode对应的DOM元素的属性,通过 setAttributes 来设置,它内部不会去处理布尔类型的属性
|
|
42
|
+
attrs?: Attrs
|
|
43
|
+
// 设置VNode对应的DOM元素的class
|
|
44
|
+
class?: Classes
|
|
45
|
+
// 设置VNode对应的DOM元素的css style
|
|
46
|
+
style?: VNodeStyle
|
|
47
|
+
// 设置VNode对应的DOM元素的监听事件
|
|
48
|
+
on?: On
|
|
49
|
+
// 设置VNode对应的key
|
|
50
|
+
key?: Key
|
|
51
|
+
// svg元素
|
|
52
|
+
ns?: string
|
|
53
|
+
hook?: Hooks
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function vnode(
|
|
57
|
+
sel: string | undefined,
|
|
58
|
+
data: any | undefined,
|
|
59
|
+
children: Array<VNode | string | number> | undefined,
|
|
60
|
+
text: string | number | undefined,
|
|
61
|
+
elm: Element | Text | undefined,
|
|
62
|
+
): VNode {
|
|
63
|
+
const key = data === undefined ? undefined : data.key
|
|
64
|
+
return { sel, data, children, text, elm, key }
|
|
65
|
+
}
|