nesquick 0.0.2
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/lib/For/For.js +204 -0
- package/lib/For/getMap.js +100 -0
- package/lib/Nesquick.js +16 -0
- package/lib/NesquickElement.js +185 -0
- package/lib/NesquickFragment.js +91 -0
- package/lib/State.js +148 -0
- package/lib/cli/transformer.js +74 -0
- package/lib/index.js +19 -0
- package/lib/jsx-runtime.js +20 -0
- package/lib/types/For/For.d.ts +18 -0
- package/lib/types/For/getMap.d.ts +23 -0
- package/lib/types/Nesquick.d.ts +6 -0
- package/lib/types/NesquickElement.d.ts +37 -0
- package/lib/types/NesquickFragment.d.ts +20 -0
- package/lib/types/State.d.ts +24 -0
- package/lib/types/cli/transformer.d.ts +2 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/jsx-runtime.d.ts +66 -0
- package/package.json +46 -0
package/lib/For/For.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.For = For;
|
|
4
|
+
const State_1 = require("../State");
|
|
5
|
+
const NesquickFragment_1 = require("../NesquickFragment");
|
|
6
|
+
const getMap_1 = require("./getMap");
|
|
7
|
+
function renderChild(child, item, render) {
|
|
8
|
+
let getI = () => {
|
|
9
|
+
const iState = (0, State_1.useState)(child.i);
|
|
10
|
+
getI = iState[0];
|
|
11
|
+
child.setI = iState[1];
|
|
12
|
+
return iState[0]();
|
|
13
|
+
};
|
|
14
|
+
child.element = render(item, () => getI());
|
|
15
|
+
return child;
|
|
16
|
+
}
|
|
17
|
+
;
|
|
18
|
+
function getCycleMap(props) {
|
|
19
|
+
const map = (0, getMap_1.getMap)(props);
|
|
20
|
+
let cycle = false;
|
|
21
|
+
return {
|
|
22
|
+
...map,
|
|
23
|
+
cycle() {
|
|
24
|
+
cycle = !cycle;
|
|
25
|
+
},
|
|
26
|
+
pushChild(id, child) {
|
|
27
|
+
const childs = map.getChild(id);
|
|
28
|
+
if (childs) {
|
|
29
|
+
child.childs = childs;
|
|
30
|
+
childs.list.push(child);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
map.setChild(id, child.childs = {
|
|
34
|
+
list: [child],
|
|
35
|
+
offset: 0,
|
|
36
|
+
cycle: cycle
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
getChild(id) {
|
|
41
|
+
const childs = map.getChild(id);
|
|
42
|
+
if (childs) {
|
|
43
|
+
if (childs.cycle === cycle) {
|
|
44
|
+
if (childs.offset < childs.list.length) {
|
|
45
|
+
return childs.list[childs.offset++];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
childs.cycle = cycle;
|
|
50
|
+
childs.offset = 1;
|
|
51
|
+
return childs.list[0];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
popChild(child) {
|
|
56
|
+
const childs = child.childs;
|
|
57
|
+
if (childs.list.length === 1) {
|
|
58
|
+
map.deleteChild(child.id);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (childs.offset === childs.list.length) {
|
|
62
|
+
childs.offset--;
|
|
63
|
+
}
|
|
64
|
+
childs.list.pop();
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
skipChild(child) {
|
|
68
|
+
const childs = child.childs;
|
|
69
|
+
if (childs.cycle === cycle) {
|
|
70
|
+
if (childs.offset < childs.list.length) {
|
|
71
|
+
childs.offset++;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
childs.offset = 1;
|
|
76
|
+
childs.cycle = cycle;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function For(props) {
|
|
82
|
+
const children = [];
|
|
83
|
+
const fragment = new NesquickFragment_1.NesquickFragment([]);
|
|
84
|
+
let cycle = false;
|
|
85
|
+
const map = getCycleMap(props);
|
|
86
|
+
(0, State_1.useRender)(() => {
|
|
87
|
+
cycle = !cycle;
|
|
88
|
+
const each = props.each().slice();
|
|
89
|
+
if (children.length === 0) {
|
|
90
|
+
for (let i = 0; i < each.length; i++) {
|
|
91
|
+
const item = each[i];
|
|
92
|
+
const id = map.getId(item, i);
|
|
93
|
+
const child = renderChild({
|
|
94
|
+
id: id,
|
|
95
|
+
i: i,
|
|
96
|
+
setI: null,
|
|
97
|
+
element: null,
|
|
98
|
+
cycle: cycle,
|
|
99
|
+
childs: null
|
|
100
|
+
}, item, props.children);
|
|
101
|
+
map.pushChild(id, child);
|
|
102
|
+
children.push(child);
|
|
103
|
+
fragment.appendElement(child.element);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (each.length === 0) {
|
|
107
|
+
for (let i = 0; i < children.length; i++) {
|
|
108
|
+
fragment.removeElement(i);
|
|
109
|
+
}
|
|
110
|
+
map.clearChilds();
|
|
111
|
+
children.splice(0);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
map.cycle();
|
|
115
|
+
for (let i = 0; i < each.length; i++) {
|
|
116
|
+
const item = each[i];
|
|
117
|
+
const id = map.getId(item, i);
|
|
118
|
+
const child = map.getChild(id);
|
|
119
|
+
if (child) {
|
|
120
|
+
child.cycle = cycle;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
map.cycle();
|
|
124
|
+
let min = Math.min(children.length, each.length);
|
|
125
|
+
let offset = 0;
|
|
126
|
+
for (let i = 0; i < min; i++) {
|
|
127
|
+
const item = each[i];
|
|
128
|
+
const id = map.getId(item, i);
|
|
129
|
+
const oldChild = children[i];
|
|
130
|
+
if (!map.equalsId(oldChild.id, id)) {
|
|
131
|
+
if (oldChild.cycle !== cycle) {
|
|
132
|
+
fragment.removeElement(i);
|
|
133
|
+
children.splice(i--, 1);
|
|
134
|
+
map.popChild(oldChild);
|
|
135
|
+
if (children.length < each.length) {
|
|
136
|
+
min = children.length;
|
|
137
|
+
}
|
|
138
|
+
offset--;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
let child = map.getChild(id);
|
|
143
|
+
if (!child) {
|
|
144
|
+
child = renderChild({
|
|
145
|
+
id: id,
|
|
146
|
+
i: i,
|
|
147
|
+
setI: null,
|
|
148
|
+
element: null,
|
|
149
|
+
cycle: cycle,
|
|
150
|
+
childs: null
|
|
151
|
+
}, item, props.children);
|
|
152
|
+
fragment.spliceElement(i, child.element);
|
|
153
|
+
map.pushChild(id, child);
|
|
154
|
+
children.splice(i, 0, child);
|
|
155
|
+
if (children.length <= each.length) {
|
|
156
|
+
min = children.length;
|
|
157
|
+
}
|
|
158
|
+
offset++;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
children[child.i + offset] = oldChild;
|
|
162
|
+
children[i] = child;
|
|
163
|
+
oldChild.i = child.i;
|
|
164
|
+
child.i = i;
|
|
165
|
+
child.setI?.(i);
|
|
166
|
+
fragment.swapElements(oldChild.i + offset, child.i);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
map.skipChild(oldChild);
|
|
172
|
+
if (oldChild.i !== i) {
|
|
173
|
+
oldChild.i = i;
|
|
174
|
+
oldChild.setI?.(i);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
for (let i = min; i < each.length; i++) {
|
|
179
|
+
const item = each[i];
|
|
180
|
+
const id = map.getId(item, i);
|
|
181
|
+
const child = renderChild({
|
|
182
|
+
id: id,
|
|
183
|
+
i: i,
|
|
184
|
+
setI: null,
|
|
185
|
+
element: null,
|
|
186
|
+
cycle: cycle,
|
|
187
|
+
childs: null
|
|
188
|
+
}, item, props.children);
|
|
189
|
+
map.pushChild(id, child);
|
|
190
|
+
children.push(child);
|
|
191
|
+
fragment.appendElement(child.element);
|
|
192
|
+
}
|
|
193
|
+
if (each.length < children.length) {
|
|
194
|
+
for (let i = children.length - 1; i >= each.length; i--) {
|
|
195
|
+
const oldChild = children[i];
|
|
196
|
+
fragment.removeElement(i);
|
|
197
|
+
map.popChild(oldChild);
|
|
198
|
+
}
|
|
199
|
+
children.splice(each.length);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
return fragment;
|
|
204
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMap = getMap;
|
|
4
|
+
function getMap(props) {
|
|
5
|
+
if ("ids" in props && props.ids) {
|
|
6
|
+
const childrenMap = new Map();
|
|
7
|
+
let idLength = 0;
|
|
8
|
+
return {
|
|
9
|
+
getId(item, i) {
|
|
10
|
+
const ids = props.ids(item, i);
|
|
11
|
+
if (!ids || ids.length === 0) {
|
|
12
|
+
throw new Error(`Invalid ids array length. ids() should not return an empty array`);
|
|
13
|
+
}
|
|
14
|
+
if (idLength === 0) {
|
|
15
|
+
idLength = ids.length;
|
|
16
|
+
}
|
|
17
|
+
else if (ids.length !== idLength) {
|
|
18
|
+
throw new Error(`Invalid ids array length. Expected: ${idLength}. Found: ${ids.length}. Make sure ids() always return the same length`);
|
|
19
|
+
}
|
|
20
|
+
return ids;
|
|
21
|
+
},
|
|
22
|
+
equalsId(a, b) {
|
|
23
|
+
for (let i = 0; i < a.length; i++) {
|
|
24
|
+
if (a[i] !== b[i]) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
getChild(ids) {
|
|
31
|
+
let map = childrenMap;
|
|
32
|
+
for (let i = 0; i < ids.length; i++) {
|
|
33
|
+
map = map.get(ids[i]);
|
|
34
|
+
if (!map) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return map;
|
|
39
|
+
},
|
|
40
|
+
setChild(ids, child) {
|
|
41
|
+
let map = childrenMap;
|
|
42
|
+
for (let i = 0; i < ids.length - 1; i++) {
|
|
43
|
+
const childMap = map.get(ids[i]);
|
|
44
|
+
if (!childMap) {
|
|
45
|
+
map.set(ids[i], map = new Map());
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
map = childMap;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
map.set(ids[ids.length - 1], child);
|
|
52
|
+
},
|
|
53
|
+
deleteChild(ids) {
|
|
54
|
+
let parentMap = null;
|
|
55
|
+
let map = childrenMap;
|
|
56
|
+
for (let i = 0; i < ids.length - 1; i++) {
|
|
57
|
+
parentMap = map;
|
|
58
|
+
map = parentMap.get(ids[i]);
|
|
59
|
+
if (!map) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (let i = ids.length - 1; i >= 0; i--) {
|
|
64
|
+
map.delete(ids[i]);
|
|
65
|
+
if (map.size === 0) {
|
|
66
|
+
map = parentMap;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
clearChilds() {
|
|
74
|
+
childrenMap.clear();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const childrenMap = new Map();
|
|
80
|
+
return {
|
|
81
|
+
getId: ("id" in props && props.id) || (item => item),
|
|
82
|
+
equalsId(a, b) {
|
|
83
|
+
return a === b;
|
|
84
|
+
},
|
|
85
|
+
getChild(id) {
|
|
86
|
+
return childrenMap.get(id);
|
|
87
|
+
},
|
|
88
|
+
setChild(id, child) {
|
|
89
|
+
childrenMap.set(id, child);
|
|
90
|
+
},
|
|
91
|
+
deleteChild(id) {
|
|
92
|
+
childrenMap.delete(id);
|
|
93
|
+
},
|
|
94
|
+
clearChilds() {
|
|
95
|
+
childrenMap.clear();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
;
|
package/lib/Nesquick.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Nesquick = void 0;
|
|
4
|
+
var Nesquick;
|
|
5
|
+
(function (Nesquick) {
|
|
6
|
+
function render(element, parent) {
|
|
7
|
+
if (parent != null) {
|
|
8
|
+
parent.appendChild(element.render(parent.ownerDocument));
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
document.body.appendChild(element.render(document));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
Nesquick.render = render;
|
|
15
|
+
})(Nesquick || (exports.Nesquick = Nesquick = {}));
|
|
16
|
+
exports.default = Nesquick;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NesquickElement = void 0;
|
|
4
|
+
const State_1 = require("./State");
|
|
5
|
+
function functionizeProps(props) {
|
|
6
|
+
for (const k in props) {
|
|
7
|
+
if (typeof props[k] !== "function") {
|
|
8
|
+
const v = props[k];
|
|
9
|
+
props[k] = () => v;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
class NesquickElement {
|
|
14
|
+
constructor(_render, props) {
|
|
15
|
+
this._render = _render;
|
|
16
|
+
this.props = props;
|
|
17
|
+
this._subscriptions = new State_1.Subscriptions();
|
|
18
|
+
this._children = [];
|
|
19
|
+
this.props = props;
|
|
20
|
+
}
|
|
21
|
+
render(document) {
|
|
22
|
+
State_1.subscriptions.set(this._subscriptions);
|
|
23
|
+
if (typeof this._render === "function") {
|
|
24
|
+
functionizeProps(this.props);
|
|
25
|
+
const res = this._render(this.props).render(document);
|
|
26
|
+
State_1.subscriptions.reset();
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
29
|
+
const element = document.createElement(this._render);
|
|
30
|
+
if (this.props != null) {
|
|
31
|
+
this._renderProps(element, this.props);
|
|
32
|
+
}
|
|
33
|
+
this._renderChildren(document, element, this.props.children);
|
|
34
|
+
this.props = {};
|
|
35
|
+
State_1.subscriptions.reset();
|
|
36
|
+
return element;
|
|
37
|
+
}
|
|
38
|
+
_renderProps(element, props) {
|
|
39
|
+
for (const k in props) {
|
|
40
|
+
if (k !== "children") {
|
|
41
|
+
if (typeof props[k] === "function") {
|
|
42
|
+
(0, State_1.useRender)(props[k], v => {
|
|
43
|
+
element.setAttribute(k, String(v));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
element.setAttribute(k, String(props[k]));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
_renderChildren(document, parent, children) {
|
|
53
|
+
if (children != null) {
|
|
54
|
+
if (!Array.isArray(children)) {
|
|
55
|
+
children = [children];
|
|
56
|
+
}
|
|
57
|
+
for (const child of children) {
|
|
58
|
+
if (child instanceof NesquickElement) {
|
|
59
|
+
this._renderChild(document, parent, this._pushChild(), child);
|
|
60
|
+
}
|
|
61
|
+
else if (typeof child === "function") {
|
|
62
|
+
const ch = this._pushChild();
|
|
63
|
+
(0, State_1.useRender)(child, children => {
|
|
64
|
+
this._renderChild(document, parent, ch, children);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this._renderChild(document, parent, this._pushChild(), child);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
_pushChild() {
|
|
74
|
+
const nesquickChild = {
|
|
75
|
+
node: null,
|
|
76
|
+
element: null,
|
|
77
|
+
fragment: null
|
|
78
|
+
};
|
|
79
|
+
this._children.push(nesquickChild);
|
|
80
|
+
return nesquickChild;
|
|
81
|
+
}
|
|
82
|
+
_spliceChild(i) {
|
|
83
|
+
const nesquickChild = {
|
|
84
|
+
node: null,
|
|
85
|
+
element: null,
|
|
86
|
+
fragment: null
|
|
87
|
+
};
|
|
88
|
+
this._children.splice(i, 0, nesquickChild);
|
|
89
|
+
return nesquickChild;
|
|
90
|
+
}
|
|
91
|
+
_swapChilds(parent, i1, i2) {
|
|
92
|
+
const ch1 = this._children[i1];
|
|
93
|
+
const ch2 = this._children[i2];
|
|
94
|
+
if (ch1 && ch2) {
|
|
95
|
+
this._children[i1] = ch2;
|
|
96
|
+
this._children[i2] = ch1;
|
|
97
|
+
if (ch1.node && ch2.node) {
|
|
98
|
+
const node2Sibling = ch2.node.nextSibling;
|
|
99
|
+
if (node2Sibling === ch1.node) {
|
|
100
|
+
parent.insertBefore(ch1.node, ch2.node);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
parent.insertBefore(ch2.node, ch1.node);
|
|
104
|
+
parent.insertBefore(ch1.node, node2Sibling);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
_removeChild(i) {
|
|
110
|
+
const ch = this._children[i];
|
|
111
|
+
if (ch) {
|
|
112
|
+
this._children.splice(i, 1);
|
|
113
|
+
if (ch.node) {
|
|
114
|
+
ch.node.parentNode?.removeChild(ch.node);
|
|
115
|
+
}
|
|
116
|
+
if (ch.element != null) {
|
|
117
|
+
ch.element.dispose();
|
|
118
|
+
}
|
|
119
|
+
else if (ch.fragment != null) {
|
|
120
|
+
ch.fragment.dispose();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
_renderChild(document, parent, nesquickChild, child) {
|
|
125
|
+
if (nesquickChild.element != null) {
|
|
126
|
+
nesquickChild.element.dispose();
|
|
127
|
+
}
|
|
128
|
+
else if (nesquickChild.fragment != null) {
|
|
129
|
+
nesquickChild.fragment.clear();
|
|
130
|
+
}
|
|
131
|
+
if (child instanceof NesquickFragment_1.NesquickFragment || Array.isArray(child)) {
|
|
132
|
+
nesquickChild.element = null;
|
|
133
|
+
nesquickChild.fragment = Array.isArray(child) ? new NesquickFragment_1.NesquickFragment(child) : child;
|
|
134
|
+
const node = nesquickChild.fragment.render(document);
|
|
135
|
+
const lastChild = node.lastChild;
|
|
136
|
+
if (nesquickChild.node) {
|
|
137
|
+
parent.replaceChild(node, nesquickChild.node);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
parent.appendChild(node);
|
|
141
|
+
}
|
|
142
|
+
nesquickChild.node = lastChild;
|
|
143
|
+
}
|
|
144
|
+
else if (child instanceof NesquickElement) {
|
|
145
|
+
nesquickChild.element = child;
|
|
146
|
+
nesquickChild.fragment = null;
|
|
147
|
+
const node = child.render(document);
|
|
148
|
+
if (nesquickChild.node) {
|
|
149
|
+
parent.replaceChild(node, nesquickChild.node);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
parent.appendChild(node);
|
|
153
|
+
}
|
|
154
|
+
nesquickChild.node = node;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const value = child == null ? "" : String(child);
|
|
158
|
+
if (nesquickChild.node == null || nesquickChild.element != null || nesquickChild.fragment != null) {
|
|
159
|
+
nesquickChild.element = null;
|
|
160
|
+
nesquickChild.fragment = null;
|
|
161
|
+
const node = document.createTextNode(value);
|
|
162
|
+
if (nesquickChild.node) {
|
|
163
|
+
parent.replaceChild(node, nesquickChild.node);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
parent.appendChild(node);
|
|
167
|
+
}
|
|
168
|
+
nesquickChild.node = node;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
nesquickChild.node.textContent = value;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
dispose() {
|
|
176
|
+
this._subscriptions.dispose();
|
|
177
|
+
for (const child of this._children) {
|
|
178
|
+
if (child.element) {
|
|
179
|
+
child.element.dispose();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.NesquickElement = NesquickElement;
|
|
185
|
+
const NesquickFragment_1 = require("./NesquickFragment");
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NesquickFragment = void 0;
|
|
4
|
+
const NesquickElement_1 = require("./NesquickElement");
|
|
5
|
+
class NesquickFragment extends NesquickElement_1.NesquickElement {
|
|
6
|
+
constructor(children) {
|
|
7
|
+
super("", { children });
|
|
8
|
+
this._lastNode = null;
|
|
9
|
+
this._fragment = null;
|
|
10
|
+
}
|
|
11
|
+
render(document) {
|
|
12
|
+
this._fragment = document.createDocumentFragment();
|
|
13
|
+
this._renderChildren(document, this, this.props.children);
|
|
14
|
+
this.props = {};
|
|
15
|
+
this._lastNode = document.createComment("Fragment");
|
|
16
|
+
this._fragment.appendChild(this._lastNode);
|
|
17
|
+
return this._fragment;
|
|
18
|
+
}
|
|
19
|
+
getDocument() {
|
|
20
|
+
return (this._lastNode?.ownerDocument || this._fragment?.ownerDocument) || null;
|
|
21
|
+
}
|
|
22
|
+
getParent() {
|
|
23
|
+
return this._lastNode?.parentNode || this._fragment;
|
|
24
|
+
}
|
|
25
|
+
appendChild(child) {
|
|
26
|
+
const parent = this.getParent();
|
|
27
|
+
if (parent) {
|
|
28
|
+
parent.insertBefore(child, this._lastNode);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
replaceChild(newChild, oldChild) {
|
|
32
|
+
const parent = this.getParent();
|
|
33
|
+
if (parent) {
|
|
34
|
+
parent.replaceChild(newChild, oldChild);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
insertBefore(node, child) {
|
|
38
|
+
const parent = this.getParent();
|
|
39
|
+
if (parent) {
|
|
40
|
+
parent.insertBefore(node, child || this._lastNode);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
appendElement(child) {
|
|
44
|
+
const document = this.getDocument();
|
|
45
|
+
const parent = this.getParent();
|
|
46
|
+
if (document && parent) {
|
|
47
|
+
const ch = this._pushChild();
|
|
48
|
+
this._renderChild(document, this, ch, child);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.props.children.push(child);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
swapElements(i1, i2) {
|
|
55
|
+
const parent = this.getParent();
|
|
56
|
+
if (parent) {
|
|
57
|
+
this._swapChilds(parent, i1, i2);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
removeElement(i) {
|
|
61
|
+
this._removeChild(i);
|
|
62
|
+
}
|
|
63
|
+
spliceElement(i, child) {
|
|
64
|
+
const document = this.getDocument();
|
|
65
|
+
const parent = this.getParent();
|
|
66
|
+
if (document && parent) {
|
|
67
|
+
const spliced = this._children[i];
|
|
68
|
+
const ch = this._spliceChild(i);
|
|
69
|
+
ch.node = document.createComment("");
|
|
70
|
+
if (spliced?.node) {
|
|
71
|
+
parent.insertBefore(ch.node, spliced.node);
|
|
72
|
+
}
|
|
73
|
+
this._renderChild(document, this, ch, child);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.props.children.splice(i, 0, child);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
clear() {
|
|
80
|
+
const parent = this._lastNode?.parentNode || this._fragment;
|
|
81
|
+
if (parent) {
|
|
82
|
+
for (const child of this._children) {
|
|
83
|
+
if (child.node) {
|
|
84
|
+
parent.removeChild(child.node);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
this.dispose();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.NesquickFragment = NesquickFragment;
|
package/lib/State.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscriptions = exports.Subscriptions = void 0;
|
|
4
|
+
exports.useState = useState;
|
|
5
|
+
exports.useEffect = useEffect;
|
|
6
|
+
exports.useRender = useRender;
|
|
7
|
+
exports.useDispose = useDispose;
|
|
8
|
+
let currentReactor = [];
|
|
9
|
+
var reactor;
|
|
10
|
+
(function (reactor_1) {
|
|
11
|
+
function set(reactor) {
|
|
12
|
+
currentReactor.push(reactor);
|
|
13
|
+
}
|
|
14
|
+
reactor_1.set = set;
|
|
15
|
+
function reset() {
|
|
16
|
+
currentReactor.pop();
|
|
17
|
+
}
|
|
18
|
+
reactor_1.reset = reset;
|
|
19
|
+
})(reactor || (reactor = {}));
|
|
20
|
+
let pendingReactor = null;
|
|
21
|
+
function renderReactor(reactor, instant) {
|
|
22
|
+
if (instant) {
|
|
23
|
+
runSubscription(reactor);
|
|
24
|
+
}
|
|
25
|
+
else if (!reactor.pending) {
|
|
26
|
+
reactor.pending = true;
|
|
27
|
+
if (pendingReactor == null) {
|
|
28
|
+
pendingReactor = {
|
|
29
|
+
first: reactor,
|
|
30
|
+
last: reactor
|
|
31
|
+
};
|
|
32
|
+
requestAnimationFrame(renderReactors);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
pendingReactor.last.next = reactor;
|
|
36
|
+
pendingReactor.last = reactor;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function renderReactors() {
|
|
41
|
+
let next = pendingReactor.first;
|
|
42
|
+
do {
|
|
43
|
+
if (!next.cancelled) {
|
|
44
|
+
runSubscription(next);
|
|
45
|
+
}
|
|
46
|
+
const n = next.next;
|
|
47
|
+
next.next = null;
|
|
48
|
+
next = n;
|
|
49
|
+
} while (next);
|
|
50
|
+
pendingReactor = null;
|
|
51
|
+
}
|
|
52
|
+
class Subscriptions {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.list = [];
|
|
55
|
+
this.onDispose = [];
|
|
56
|
+
}
|
|
57
|
+
dispose() {
|
|
58
|
+
for (const sub of this.list) {
|
|
59
|
+
cancelSubscription(sub);
|
|
60
|
+
}
|
|
61
|
+
for (const cb of this.onDispose) {
|
|
62
|
+
cb();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.Subscriptions = Subscriptions;
|
|
67
|
+
let currentSubscriptions = [];
|
|
68
|
+
var subscriptions;
|
|
69
|
+
(function (subscriptions) {
|
|
70
|
+
function set(container) {
|
|
71
|
+
currentSubscriptions.push(container);
|
|
72
|
+
}
|
|
73
|
+
subscriptions.set = set;
|
|
74
|
+
function reset() {
|
|
75
|
+
currentSubscriptions.pop();
|
|
76
|
+
}
|
|
77
|
+
subscriptions.reset = reset;
|
|
78
|
+
})(subscriptions || (exports.subscriptions = subscriptions = {}));
|
|
79
|
+
function useState(value) {
|
|
80
|
+
const reactors = new Set();
|
|
81
|
+
const getValue = () => {
|
|
82
|
+
const reactor = currentReactor[currentReactor.length - 1];
|
|
83
|
+
if (reactor) {
|
|
84
|
+
reactors.add(reactor);
|
|
85
|
+
reactor.states.set(reactors, reactor.iteration);
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
};
|
|
89
|
+
const setValue = (newValue) => {
|
|
90
|
+
value = newValue;
|
|
91
|
+
for (const reactor of reactors) {
|
|
92
|
+
renderReactor(reactor, reactor.effect);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return [getValue, setValue];
|
|
96
|
+
}
|
|
97
|
+
function useEffect(cb, reaction = null) {
|
|
98
|
+
newSubscription(cb, reaction, true);
|
|
99
|
+
}
|
|
100
|
+
function useRender(cb, reaction = null) {
|
|
101
|
+
newSubscription(cb, reaction, false);
|
|
102
|
+
}
|
|
103
|
+
function useDispose(cb) {
|
|
104
|
+
const container = currentSubscriptions[currentSubscriptions.length - 1];
|
|
105
|
+
if (container) {
|
|
106
|
+
container.onDispose.push(cb);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function newSubscription(cb, reaction, effect) {
|
|
110
|
+
const sub = {
|
|
111
|
+
cb: cb,
|
|
112
|
+
reaction: reaction,
|
|
113
|
+
iteration: 0,
|
|
114
|
+
states: new Map(),
|
|
115
|
+
next: null,
|
|
116
|
+
effect: effect,
|
|
117
|
+
cancelled: false,
|
|
118
|
+
pending: false
|
|
119
|
+
};
|
|
120
|
+
renderReactor(sub, true);
|
|
121
|
+
if (sub.states.size === 0) {
|
|
122
|
+
cancelSubscription(sub);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const container = currentSubscriptions[currentSubscriptions.length - 1];
|
|
126
|
+
if (container) {
|
|
127
|
+
container.list.push(sub);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function cancelSubscription(sub) {
|
|
132
|
+
sub.cancelled = true;
|
|
133
|
+
for (const reactors of sub.states.keys()) {
|
|
134
|
+
reactors.delete(sub);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function runSubscription(sub) {
|
|
138
|
+
sub.pending = false;
|
|
139
|
+
reactor.set(sub);
|
|
140
|
+
const res = sub.cb();
|
|
141
|
+
reactor.reset();
|
|
142
|
+
for (const [state, iteration] of sub.states) {
|
|
143
|
+
if (iteration !== sub.iteration) {
|
|
144
|
+
sub.states.delete(state);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
sub.reaction?.(res);
|
|
148
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformer = void 0;
|
|
4
|
+
const TS = require("typescript");
|
|
5
|
+
function getSingleIdentifier(node) {
|
|
6
|
+
const identifiers = [];
|
|
7
|
+
node.forEachChild(node => {
|
|
8
|
+
if (TS.isIdentifier(node)) {
|
|
9
|
+
identifiers.push(node);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
if (identifiers.length === 1) {
|
|
13
|
+
return identifiers[0];
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
function getSingleBody(node) {
|
|
18
|
+
const body = [];
|
|
19
|
+
node.forEachChild(node => {
|
|
20
|
+
body.push(node);
|
|
21
|
+
});
|
|
22
|
+
if (body.length === 1) {
|
|
23
|
+
return body[0];
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
function hasIdentifier(node) {
|
|
28
|
+
let found = false;
|
|
29
|
+
node.forEachChild(node => {
|
|
30
|
+
if (!found && (TS.isIdentifier(node) || hasIdentifier(node))) {
|
|
31
|
+
found = true;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return found;
|
|
35
|
+
}
|
|
36
|
+
const transformer = context => {
|
|
37
|
+
return sourceFile => {
|
|
38
|
+
const visitorGeneric = node => {
|
|
39
|
+
if (TS.isJsxAttribute(node)) {
|
|
40
|
+
return TS.visitEachChild(node, visitorAttribute, context);
|
|
41
|
+
}
|
|
42
|
+
return TS.visitEachChild(node, visitorGeneric, context);
|
|
43
|
+
};
|
|
44
|
+
const visitorAttribute = node => {
|
|
45
|
+
if (TS.isJsxExpression(node)) {
|
|
46
|
+
return TS.visitEachChild(node, visitorExpression, context);
|
|
47
|
+
}
|
|
48
|
+
return TS.visitEachChild(node, visitorGeneric, context);
|
|
49
|
+
};
|
|
50
|
+
const visitorExpression = node => {
|
|
51
|
+
if (TS.isParenthesizedExpression(node)) {
|
|
52
|
+
const body = getSingleBody(node);
|
|
53
|
+
if (body) {
|
|
54
|
+
return TS.visitNode(body, visitorExpression, TS.isSourceFile);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (TS.isCallExpression(node)) {
|
|
58
|
+
const identifier = getSingleIdentifier(node);
|
|
59
|
+
if (identifier) {
|
|
60
|
+
return identifier;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (TS.isExpression(node) && hasIdentifier(node)) {
|
|
67
|
+
return TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
|
|
68
|
+
}
|
|
69
|
+
return node;
|
|
70
|
+
};
|
|
71
|
+
return TS.visitNode(sourceFile, visitorGeneric, TS.isSourceFile);
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
exports.transformer = transformer;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Nesquick"), exports);
|
|
18
|
+
__exportStar(require("./For/For"), exports);
|
|
19
|
+
__exportStar(require("./cli/transformer"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JSX = exports.jsx = exports.Fragment = void 0;
|
|
4
|
+
exports.jsxs = jsxs;
|
|
5
|
+
const NesquickElement_1 = require("./NesquickElement");
|
|
6
|
+
const NesquickFragment_1 = require("./NesquickFragment");
|
|
7
|
+
exports.Fragment = Symbol();
|
|
8
|
+
function jsxs(type, props, key) {
|
|
9
|
+
if (type === exports.Fragment) {
|
|
10
|
+
return new NesquickFragment_1.NesquickFragment(props.children);
|
|
11
|
+
}
|
|
12
|
+
if (key !== undefined) {
|
|
13
|
+
props.key = key;
|
|
14
|
+
}
|
|
15
|
+
return new NesquickElement_1.NesquickElement(type, props);
|
|
16
|
+
}
|
|
17
|
+
exports.jsx = jsxs;
|
|
18
|
+
var JSX;
|
|
19
|
+
(function (JSX) {
|
|
20
|
+
})(JSX || (exports.JSX = JSX = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Props, JSX } from "../jsx-runtime";
|
|
2
|
+
import { NesquickFragment } from "../NesquickFragment";
|
|
3
|
+
type ChildRender<T> = (item: T, i: () => number) => JSX.Element;
|
|
4
|
+
export type ForProps<T> = {
|
|
5
|
+
each: T[];
|
|
6
|
+
children: ChildRender<T>;
|
|
7
|
+
} & ({
|
|
8
|
+
ids?: never;
|
|
9
|
+
id: (item: T, i: number) => unknown;
|
|
10
|
+
} | {
|
|
11
|
+
ids: (item: T, i: number) => unknown[];
|
|
12
|
+
id?: never;
|
|
13
|
+
} | {
|
|
14
|
+
ids?: never;
|
|
15
|
+
id?: never;
|
|
16
|
+
});
|
|
17
|
+
export declare function For<T>(props: Props<ForProps<T>>): NesquickFragment;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Props } from "../jsx-runtime";
|
|
2
|
+
import { ForProps } from "./For";
|
|
3
|
+
export type IdMap<T, ID, CHILD> = {
|
|
4
|
+
getId(item: T, i: number): ID;
|
|
5
|
+
equalsId(a: ID, b: ID): boolean;
|
|
6
|
+
getChild(id: ID): CHILD | undefined;
|
|
7
|
+
setChild(id: ID, child: CHILD): void;
|
|
8
|
+
deleteChild(id: ID): void;
|
|
9
|
+
clearChilds(): void;
|
|
10
|
+
};
|
|
11
|
+
type IdMapProps<T> = Props<Pick<Extract<ForProps<T>, {
|
|
12
|
+
id?: unknown;
|
|
13
|
+
}>, "id"> | Pick<Extract<ForProps<T>, {
|
|
14
|
+
ids?: unknown;
|
|
15
|
+
}>, "ids">>;
|
|
16
|
+
export declare function getMap<T, CHILD>(props: Required<Extract<IdMapProps<T>, {
|
|
17
|
+
id?: unknown;
|
|
18
|
+
}>>): IdMap<T, unknown, CHILD>;
|
|
19
|
+
export declare function getMap<T, CHILD>(props: Required<Extract<IdMapProps<T>, {
|
|
20
|
+
ids?: unknown;
|
|
21
|
+
}>>): IdMap<T, unknown[], CHILD>;
|
|
22
|
+
export declare function getMap<T, CHILD>(props: IdMapProps<T>): IdMap<T, T, CHILD>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type Child = NesquickElement<any> | NesquickFragment | string | boolean | number | null | undefined | ChildFunc;
|
|
2
|
+
export type Children = Child | Child[];
|
|
3
|
+
export type ChildFunc = () => Exclude<Child, ChildFunc> | Exclude<Child, ChildFunc>[];
|
|
4
|
+
export type Props = Record<string, any>;
|
|
5
|
+
export type FunctionComponent<P extends Props = {}> = (props: P) => NesquickElement<P>;
|
|
6
|
+
type NesquickChild = {
|
|
7
|
+
node: Node | null;
|
|
8
|
+
} & ({
|
|
9
|
+
element: NesquickElement | null;
|
|
10
|
+
fragment: null;
|
|
11
|
+
} | {
|
|
12
|
+
element: null;
|
|
13
|
+
fragment: NesquickFragment | null;
|
|
14
|
+
});
|
|
15
|
+
export type NesquickParent = {
|
|
16
|
+
appendChild(child: Node): void;
|
|
17
|
+
replaceChild(newChild: Node, oldChild: Node): void;
|
|
18
|
+
insertBefore(node: Node, child: Node | null): void;
|
|
19
|
+
};
|
|
20
|
+
export declare class NesquickElement<P extends Props = {}> {
|
|
21
|
+
private _render;
|
|
22
|
+
protected props: P;
|
|
23
|
+
private _subscriptions;
|
|
24
|
+
protected _children: NesquickChild[];
|
|
25
|
+
constructor(_render: string | FunctionComponent<P>, props: P);
|
|
26
|
+
render(document: Document): Node;
|
|
27
|
+
private _renderProps;
|
|
28
|
+
protected _renderChildren(document: Document, parent: NesquickParent, children?: Children): void;
|
|
29
|
+
protected _pushChild(): NesquickChild;
|
|
30
|
+
protected _spliceChild(i: number): NesquickChild;
|
|
31
|
+
protected _swapChilds(parent: NesquickParent, i1: number, i2: number): void;
|
|
32
|
+
protected _removeChild(i: number): void;
|
|
33
|
+
protected _renderChild(document: Document, parent: NesquickParent, nesquickChild: NesquickChild, child: Exclude<Child, ChildFunc> | Exclude<Child, ChildFunc>[]): void;
|
|
34
|
+
dispose(): void;
|
|
35
|
+
}
|
|
36
|
+
import { NesquickFragment } from "./NesquickFragment";
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { JSX } from "./jsx-runtime";
|
|
2
|
+
import { NesquickElement, NesquickParent } from "./NesquickElement";
|
|
3
|
+
export declare class NesquickFragment extends NesquickElement<{
|
|
4
|
+
children: any[];
|
|
5
|
+
}> implements NesquickParent {
|
|
6
|
+
private _lastNode;
|
|
7
|
+
private _fragment;
|
|
8
|
+
constructor(children: any[]);
|
|
9
|
+
render(document: Document): Node;
|
|
10
|
+
getDocument(): Document | null;
|
|
11
|
+
getParent(): Node | null;
|
|
12
|
+
appendChild(child: Node): void;
|
|
13
|
+
replaceChild(newChild: Node, oldChild: Node): void;
|
|
14
|
+
insertBefore(node: Node, child: Node | null): void;
|
|
15
|
+
appendElement(child: JSX.Element): void;
|
|
16
|
+
swapElements(i1: number, i2: number): void;
|
|
17
|
+
removeElement(i: number): void;
|
|
18
|
+
spliceElement(i: number, child: JSX.Element): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type State<T> = [get: () => T, set: (value: T) => void];
|
|
2
|
+
export type Subscription<T> = {
|
|
3
|
+
cb: () => T;
|
|
4
|
+
reaction: ((data: T) => void) | null;
|
|
5
|
+
iteration: number;
|
|
6
|
+
states: Map<Set<Subscription<any>>, number>;
|
|
7
|
+
next: Subscription<T> | null;
|
|
8
|
+
effect: boolean;
|
|
9
|
+
cancelled: boolean;
|
|
10
|
+
pending: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare class Subscriptions {
|
|
13
|
+
list: Subscription<any>[];
|
|
14
|
+
onDispose: (() => void)[];
|
|
15
|
+
dispose(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare namespace subscriptions {
|
|
18
|
+
function set(container: Subscriptions): void;
|
|
19
|
+
function reset(): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function useState<T>(value: T): State<T>;
|
|
22
|
+
export declare function useEffect<T>(cb: () => T, reaction?: ((data: T) => void) | null): void;
|
|
23
|
+
export declare function useRender<T>(cb: () => T, reaction?: ((data: T) => void) | null): void;
|
|
24
|
+
export declare function useDispose(cb: () => void): void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { FunctionComponent, Props, NesquickElement } from "./NesquickElement";
|
|
2
|
+
import { NesquickFragment } from "./NesquickFragment";
|
|
3
|
+
export declare const Fragment: unique symbol;
|
|
4
|
+
export declare function jsxs<P extends Props>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string): NesquickFragment | NesquickElement<P>;
|
|
5
|
+
export declare const jsx: typeof jsxs;
|
|
6
|
+
declare const WrappedFunctionType: unique symbol;
|
|
7
|
+
type WrappedFunction<T> = (() => T) & {
|
|
8
|
+
readonly [WrappedFunctionType]?: T;
|
|
9
|
+
};
|
|
10
|
+
type UserProp<T> = T extends (...args: infer A) => infer R ? (((...args: A) => R) | T) : WrappedFunction<T>;
|
|
11
|
+
type ComponentProp<T> = T extends {
|
|
12
|
+
readonly [WrappedFunctionType]?: infer R;
|
|
13
|
+
} ? (T | R) : T extends (...args: any[]) => any ? T : (T | (() => T));
|
|
14
|
+
type UnFunction<T> = T extends {
|
|
15
|
+
readonly [WrappedFunctionType]?: infer R;
|
|
16
|
+
} ? (T | R) : T;
|
|
17
|
+
type UserProps<T> = {
|
|
18
|
+
[K in keyof T]: K extends "children" ? T[K] : UserProp<T[K]>;
|
|
19
|
+
};
|
|
20
|
+
type ComponentProps<T> = keyof T extends never ? {} : {
|
|
21
|
+
[K in keyof T]: K extends "children" ? UnFunction<T[K]> : ComponentProp<T[K]>;
|
|
22
|
+
};
|
|
23
|
+
export type Generic<T> = T extends (...args: any) => infer R ? R : T;
|
|
24
|
+
export { UserProps as Props };
|
|
25
|
+
export type Component<P = {}> = (props: UserProps<P>) => JSX.Element;
|
|
26
|
+
export declare namespace JSX {
|
|
27
|
+
export type JSXEvent<T extends Event, T2 extends EventTarget> = T & {
|
|
28
|
+
currentTarget: T2;
|
|
29
|
+
};
|
|
30
|
+
export type JSXHTMLEvent<T extends EventTarget> = {
|
|
31
|
+
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<HTMLElementEventMap[K], T>) => void;
|
|
32
|
+
};
|
|
33
|
+
export type JSXSVGEvent<T extends EventTarget> = {
|
|
34
|
+
[K in keyof SVGElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<SVGElementEventMap[K], T>) => void;
|
|
35
|
+
};
|
|
36
|
+
export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T> {
|
|
37
|
+
[k: string]: any;
|
|
38
|
+
style?: StyleProps;
|
|
39
|
+
}
|
|
40
|
+
export type StyleProps = {
|
|
41
|
+
[K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] extends Function ? never : CSSStyleDeclaration[K] | (() => CSSStyleDeclaration[K]);
|
|
42
|
+
};
|
|
43
|
+
export type HTMLProps<T extends HTMLElement = HTMLElement> = Props<T>;
|
|
44
|
+
export type SVGProps<T extends SVGElement = SVGElement> = Props<T>;
|
|
45
|
+
export type JSXElements = {
|
|
46
|
+
[K in keyof HTMLElementTagNameMap]: HTMLProps<HTMLElementTagNameMap[K]>;
|
|
47
|
+
} & {
|
|
48
|
+
[K in keyof SVGElementTagNameMap]: SVGProps<SVGElementTagNameMap[K]>;
|
|
49
|
+
};
|
|
50
|
+
export type Element = NesquickElement<any>;
|
|
51
|
+
export interface IntrinsicElements extends JSXElements {
|
|
52
|
+
}
|
|
53
|
+
export type ElementType = keyof IntrinsicElements | Component<any> | typeof NesquickElement<any>;
|
|
54
|
+
const NotEmptyObject: unique symbol;
|
|
55
|
+
export type IntrinsicAttributes = {
|
|
56
|
+
[NotEmptyObject]?: typeof NotEmptyObject;
|
|
57
|
+
};
|
|
58
|
+
export interface ElementAttributesProperty {
|
|
59
|
+
props: {};
|
|
60
|
+
}
|
|
61
|
+
export interface ElementChildrenAttribute {
|
|
62
|
+
children: {};
|
|
63
|
+
}
|
|
64
|
+
export type LibraryManagedAttributes<_, P> = ComponentProps<P>;
|
|
65
|
+
export {};
|
|
66
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nesquick",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "React-like library with focus on drawing performance",
|
|
5
|
+
"types": "./lib/types",
|
|
6
|
+
"main": "./lib",
|
|
7
|
+
"typesVersions": {
|
|
8
|
+
"*": {
|
|
9
|
+
"jsx-runtime": ["./lib/types/jsx-runtime.d.ts"]
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"nesquick-tsc": "lib/cli/nesquick-tsc.js",
|
|
14
|
+
"ntsc": "lib/cli/nesquick-tsc.js"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"files": [
|
|
18
|
+
"lib/",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"private": false,
|
|
22
|
+
"scripts": {
|
|
23
|
+
"watch": "npm run clean && npx tsc -p tsconfig.json -watch",
|
|
24
|
+
"build": "npm run clean && npx tsc -p tsconfig.build.json",
|
|
25
|
+
"build-debug": "npm run clean && npx tsc -p tsconfig.json",
|
|
26
|
+
"test": "npx aaa",
|
|
27
|
+
"clean": "node -e \"require('fs').rm('lib', {recursive: true, force:true}, O_o => {})\""
|
|
28
|
+
},
|
|
29
|
+
"author": "Llorx",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/Llorx/nesquick.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/Llorx/nesquick/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/Llorx/nesquick#readme",
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/jsdom": "^21.1.7",
|
|
41
|
+
"@types/node": "^22.7.8",
|
|
42
|
+
"arrange-act-assert": "^2.9.3",
|
|
43
|
+
"jsdom": "^26.1.0",
|
|
44
|
+
"typescript": "^5.6.3"
|
|
45
|
+
}
|
|
46
|
+
}
|