@esportsplus/template 0.16.1 → 0.18.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/build/attributes.js +29 -24
- package/build/constants.d.ts +13 -3
- package/build/constants.js +14 -4
- package/build/event.js +48 -46
- package/build/html/hydrate.d.ts +2 -8
- package/build/html/hydrate.js +28 -79
- package/build/html/index.d.ts +2106 -5
- package/build/html/index.js +12 -4
- package/build/html/{cache.d.ts → parser.d.ts} +1 -1
- package/build/html/{cache.js → parser.js} +6 -4
- package/build/render.d.ts +1 -2
- package/build/render.js +7 -10
- package/build/slot/cleanup.d.ts +4 -0
- package/build/slot/cleanup.js +52 -0
- package/build/slot/effect.d.ts +3 -0
- package/build/slot/effect.js +56 -0
- package/build/slot/index.d.ts +3 -0
- package/build/slot/index.js +8 -0
- package/build/slot/reactive.d.ts +3 -0
- package/build/slot/reactive.js +125 -0
- package/build/slot/render.d.ts +2 -0
- package/build/slot/render.js +81 -0
- package/build/svg.d.ts +1 -2
- package/build/types.d.ts +21 -17
- package/build/utilities/element.d.ts +11 -0
- package/build/utilities/element.js +9 -0
- package/build/utilities/fragment.d.ts +3 -0
- package/build/utilities/fragment.js +11 -0
- package/build/utilities/node.d.ts +8 -0
- package/build/utilities/node.js +9 -0
- package/build/utilities/queue.d.ts +3 -0
- package/build/utilities/queue.js +4 -0
- package/build/utilities/text.d.ts +3 -0
- package/build/utilities/text.js +9 -0
- package/package.json +2 -2
- package/src/attributes.ts +32 -29
- package/src/constants.ts +32 -5
- package/src/event.ts +55 -52
- package/src/html/hydrate.ts +36 -108
- package/src/html/index.ts +16 -8
- package/src/html/{cache.ts → parser.ts} +5 -3
- package/src/render.ts +8 -12
- package/src/slot/cleanup.ts +74 -0
- package/src/slot/effect.ts +74 -0
- package/src/slot/index.ts +12 -0
- package/src/slot/reactive.ts +177 -0
- package/src/slot/render.ts +117 -0
- package/src/svg.ts +1 -2
- package/src/types.ts +25 -18
- package/src/utilities/element.ts +28 -0
- package/src/utilities/fragment.ts +22 -0
- package/src/utilities/node.ts +26 -0
- package/src/utilities/queue.ts +9 -0
- package/src/utilities/text.ts +16 -0
- package/build/slot.d.ts +0 -21
- package/build/slot.js +0 -204
- package/build/utilities.d.ts +0 -28
- package/build/utilities.js +0 -37
- package/src/slot.ts +0 -277
- package/src/utilities.ts +0 -87
package/build/html/index.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { RENDERABLE,
|
|
1
|
+
import { RENDERABLE, RENDERABLE_HTML_FRAGMENT, RENDERABLE_HTML_REACTIVE_ARRAY } from '../constants.js';
|
|
2
2
|
import hydrate from './hydrate.js';
|
|
3
|
+
import parser from './parser.js';
|
|
3
4
|
const html = (literals, ...values) => {
|
|
4
|
-
return {
|
|
5
|
+
return {
|
|
6
|
+
[RENDERABLE]: RENDERABLE_HTML_FRAGMENT,
|
|
7
|
+
fragment: hydrate(parser.parse(literals), values),
|
|
8
|
+
literals
|
|
9
|
+
};
|
|
5
10
|
};
|
|
6
11
|
html.reactive = (array, template) => {
|
|
7
|
-
return {
|
|
12
|
+
return {
|
|
13
|
+
[RENDERABLE]: RENDERABLE_HTML_REACTIVE_ARRAY,
|
|
14
|
+
array,
|
|
15
|
+
template
|
|
16
|
+
};
|
|
8
17
|
};
|
|
9
18
|
export default html;
|
|
10
|
-
export { hydrate };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { NODE_CLOSING, NODE_ELEMENT, NODE_SLOT, NODE_VOID, NODE_WHITELIST, REGEX_EMPTY_TEXT_NODES, REGEX_SLOT_NODES, SLOT_HTML, SLOT_MARKER, SLOT_MARKER_LENGTH } from '../constants.js';
|
|
2
|
-
import {
|
|
2
|
+
import { firstElementChild, nextElementSibling } from '../utilities/element.js';
|
|
3
|
+
import { fragment } from '../utilities/fragment.js';
|
|
4
|
+
import { firstChild, nextSibling } from '../utilities/node.js';
|
|
3
5
|
import { spread } from '../attributes.js';
|
|
4
|
-
import s from '../slot.js';
|
|
6
|
+
import s from '../slot/index.js';
|
|
5
7
|
let cache = new WeakMap();
|
|
6
8
|
function build(literals) {
|
|
7
9
|
let n = literals.length - 1;
|
|
@@ -94,7 +96,7 @@ function set(literals, html, slots = null) {
|
|
|
94
96
|
cache.set(literals, template);
|
|
95
97
|
return template;
|
|
96
98
|
}
|
|
97
|
-
const
|
|
99
|
+
const parse = (literals) => {
|
|
98
100
|
return cache.get(literals) || build(literals);
|
|
99
101
|
};
|
|
100
|
-
export default {
|
|
102
|
+
export default { parse };
|
package/build/render.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Slot } from './slot.js';
|
|
2
1
|
import { Renderable } from './types.js';
|
|
3
|
-
declare const _default: (
|
|
2
|
+
declare const _default: (parent: HTMLElement, renderable: Renderable) => void;
|
|
4
3
|
export default _default;
|
package/build/render.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { isInstanceOf } from '@esportsplus/utilities';
|
|
2
1
|
import { SLOT_HTML } from './constants.js';
|
|
3
|
-
import
|
|
4
|
-
import { firstChild,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return parent.render(renderable);
|
|
9
|
-
}
|
|
2
|
+
import { fragment } from './utilities/fragment.js';
|
|
3
|
+
import { firstChild, nodeValue } from './utilities/node.js';
|
|
4
|
+
import slot from './slot/index.js';
|
|
5
|
+
let anchor, marker = firstChild.call(fragment(SLOT_HTML));
|
|
6
|
+
export default (parent, renderable) => {
|
|
10
7
|
nodeValue.call(parent, '');
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
parent.append(anchor = marker.cloneNode());
|
|
9
|
+
slot(anchor, renderable);
|
|
13
10
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import queue from '@esportsplus/queue';
|
|
2
|
+
import { CLEANUP } from '../constants.js';
|
|
3
|
+
import { microtask } from '../utilities/queue.js';
|
|
4
|
+
import { previousSibling } from '../utilities/node.js';
|
|
5
|
+
let cleanup = queue(64), scheduled = false;
|
|
6
|
+
function schedule() {
|
|
7
|
+
if (!cleanup.length || scheduled) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
scheduled = true;
|
|
11
|
+
microtask.add(task);
|
|
12
|
+
}
|
|
13
|
+
function task() {
|
|
14
|
+
try {
|
|
15
|
+
let fns, fn, n = cleanup.length;
|
|
16
|
+
while ((fns = cleanup.next()) && n--) {
|
|
17
|
+
while (fn = fns.pop()) {
|
|
18
|
+
fn();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
if (cleanup.length) {
|
|
24
|
+
microtask.add(task);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
scheduled = false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const ondisconnect = (element, fn) => {
|
|
31
|
+
(element[CLEANUP] ??= []).push(fn);
|
|
32
|
+
};
|
|
33
|
+
const remove = (groups) => {
|
|
34
|
+
let group, head, tail;
|
|
35
|
+
while (group = groups.pop()) {
|
|
36
|
+
head = group.head;
|
|
37
|
+
tail = group.tail || head;
|
|
38
|
+
for (let node = tail; node; node = previousSibling.call(node)) {
|
|
39
|
+
if (CLEANUP in node) {
|
|
40
|
+
cleanup.add(node[CLEANUP]);
|
|
41
|
+
}
|
|
42
|
+
node.remove();
|
|
43
|
+
if (head === node) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!scheduled && cleanup.length) {
|
|
49
|
+
schedule();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export { ondisconnect, remove };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { effect } from '@esportsplus/reactivity';
|
|
2
|
+
import { STATE_HYDRATING, STATE_NONE } from '../constants.js';
|
|
3
|
+
import { firstChild, lastChild, nodeValue } from '../utilities/node.js';
|
|
4
|
+
import { raf } from '../utilities/queue.js';
|
|
5
|
+
import { ondisconnect } from '../slot/cleanup.js';
|
|
6
|
+
import { remove } from './cleanup.js';
|
|
7
|
+
import text from '../utilities/text.js';
|
|
8
|
+
import render from './render.js';
|
|
9
|
+
function update(anchor, value) {
|
|
10
|
+
let type = typeof value;
|
|
11
|
+
if (this.group) {
|
|
12
|
+
remove([this.group]);
|
|
13
|
+
this.group = undefined;
|
|
14
|
+
}
|
|
15
|
+
if (value == null || type !== 'object') {
|
|
16
|
+
let textnode = this.textnode;
|
|
17
|
+
if (textnode) {
|
|
18
|
+
nodeValue.call(textnode, String(value));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
textnode = this.textnode = text(String(value));
|
|
22
|
+
}
|
|
23
|
+
if (!textnode.isConnected) {
|
|
24
|
+
anchor.after(textnode);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
let fragment = render(anchor, value);
|
|
29
|
+
if (!fragment) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.group = {
|
|
33
|
+
head: firstChild.call(fragment),
|
|
34
|
+
tail: lastChild.call(fragment)
|
|
35
|
+
};
|
|
36
|
+
anchor.after(fragment);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export default (anchor, fn) => {
|
|
40
|
+
let context = {
|
|
41
|
+
group: undefined,
|
|
42
|
+
textnode: undefined
|
|
43
|
+
}, state = STATE_HYDRATING;
|
|
44
|
+
ondisconnect(anchor, effect(() => {
|
|
45
|
+
let value = fn();
|
|
46
|
+
if (state === STATE_HYDRATING) {
|
|
47
|
+
update.call(context, anchor, value);
|
|
48
|
+
state = STATE_NONE;
|
|
49
|
+
}
|
|
50
|
+
else if (state === STATE_NONE) {
|
|
51
|
+
raf.add(() => {
|
|
52
|
+
update.call(context, anchor, value);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { root } from '@esportsplus/reactivity';
|
|
2
|
+
import { EMPTY_FRAGMENT } from '../constants.js';
|
|
3
|
+
import { append } from '../utilities/fragment.js';
|
|
4
|
+
import { cloneNode, firstChild, lastChild } from '../utilities/node.js';
|
|
5
|
+
import { remove } from './cleanup.js';
|
|
6
|
+
class ReactiveArraySlot {
|
|
7
|
+
array;
|
|
8
|
+
fragment = cloneNode.call(EMPTY_FRAGMENT);
|
|
9
|
+
marker;
|
|
10
|
+
nodes = [];
|
|
11
|
+
template;
|
|
12
|
+
constructor(anchor, array, template) {
|
|
13
|
+
let fragment = this.fragment;
|
|
14
|
+
this.array = array;
|
|
15
|
+
this.marker = anchor;
|
|
16
|
+
this.template = function (data, i) {
|
|
17
|
+
let frag = template.call(this, data, i).fragment, group = {
|
|
18
|
+
head: firstChild.call(frag),
|
|
19
|
+
tail: lastChild.call(frag)
|
|
20
|
+
};
|
|
21
|
+
append.call(fragment, frag);
|
|
22
|
+
return group;
|
|
23
|
+
};
|
|
24
|
+
let render = () => {
|
|
25
|
+
root(() => this.render());
|
|
26
|
+
};
|
|
27
|
+
array.on('clear', () => this.clear());
|
|
28
|
+
array.on('reverse', render);
|
|
29
|
+
array.on('pop', () => this.pop());
|
|
30
|
+
array.on('push', ({ items }) => {
|
|
31
|
+
root(() => this.push(items));
|
|
32
|
+
});
|
|
33
|
+
array.on('shift', () => this.shift());
|
|
34
|
+
array.on('sort', render);
|
|
35
|
+
array.on('splice', ({ deleteCount, items, start }) => {
|
|
36
|
+
root(() => this.splice(start, deleteCount, ...items));
|
|
37
|
+
});
|
|
38
|
+
array.on('unshift', ({ items }) => {
|
|
39
|
+
root(() => this.unshift(items));
|
|
40
|
+
});
|
|
41
|
+
if (array.length) {
|
|
42
|
+
render();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
get length() {
|
|
46
|
+
return this.nodes.length;
|
|
47
|
+
}
|
|
48
|
+
set length(n) {
|
|
49
|
+
if (n >= this.nodes.length) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
else if (n === 0) {
|
|
53
|
+
this.clear();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.splice(n);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
anchor(index = this.nodes.length - 1) {
|
|
60
|
+
let node = this.nodes[index];
|
|
61
|
+
if (node) {
|
|
62
|
+
return node.tail || node.head;
|
|
63
|
+
}
|
|
64
|
+
return this.marker;
|
|
65
|
+
}
|
|
66
|
+
clear() {
|
|
67
|
+
remove(this.nodes);
|
|
68
|
+
}
|
|
69
|
+
pop() {
|
|
70
|
+
let group = this.nodes.pop();
|
|
71
|
+
if (group) {
|
|
72
|
+
remove([group]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
push(items) {
|
|
76
|
+
let anchor = this.anchor(), array = this.array, length = this.nodes.length;
|
|
77
|
+
this.nodes.length = length + items.length;
|
|
78
|
+
for (let i = 0, n = items.length; i < n; i++) {
|
|
79
|
+
this.nodes[i + length] = this.template.call(array, items[i], i);
|
|
80
|
+
}
|
|
81
|
+
anchor.after(this.fragment);
|
|
82
|
+
}
|
|
83
|
+
render() {
|
|
84
|
+
let nodes = this.nodes;
|
|
85
|
+
if (nodes.length) {
|
|
86
|
+
remove(nodes);
|
|
87
|
+
}
|
|
88
|
+
nodes = this.array.map(this.template);
|
|
89
|
+
this.marker.after(this.fragment);
|
|
90
|
+
}
|
|
91
|
+
shift() {
|
|
92
|
+
let group = this.nodes.shift();
|
|
93
|
+
if (group) {
|
|
94
|
+
remove([group]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
splice(start, stop = this.nodes.length, ...items) {
|
|
98
|
+
if (!items.length) {
|
|
99
|
+
return remove(this.nodes.splice(start, stop));
|
|
100
|
+
}
|
|
101
|
+
let array = this.array, n = items.length, nodes = new Array(n);
|
|
102
|
+
for (let i = 0; i < n; i++) {
|
|
103
|
+
nodes[i] = this.template.call(array, items[i], i);
|
|
104
|
+
}
|
|
105
|
+
remove(this.nodes.splice(start, stop, ...nodes));
|
|
106
|
+
this.anchor(start - 1).after(this.fragment);
|
|
107
|
+
}
|
|
108
|
+
unshift(items) {
|
|
109
|
+
let array = this.array, n = items.length, nodes = new Array(n);
|
|
110
|
+
for (let i = 0; i < n; i++) {
|
|
111
|
+
nodes[i] = this.template.call(array, items[i], i);
|
|
112
|
+
}
|
|
113
|
+
this.nodes.unshift(...nodes);
|
|
114
|
+
this.marker.after(this.fragment);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export default (anchor, renderable) => {
|
|
118
|
+
let { array, template } = renderable, slot = new ReactiveArraySlot(anchor, array, template);
|
|
119
|
+
if (array.length) {
|
|
120
|
+
root(() => {
|
|
121
|
+
slot.nodes = array.map(slot.template);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return slot.fragment;
|
|
125
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isArray } from '@esportsplus/utilities';
|
|
2
|
+
import { EMPTY_FRAGMENT, RENDERABLE, RENDERABLE_ARRAY, RENDERABLE_FRAGMENT, RENDERABLE_HTML_FRAGMENT, RENDERABLE_HTML_REACTIVE_ARRAY, RENDERABLE_NODE, RENDERABLE_NODE_LIST, RENDERABLE_TEXT, RENDERABLE_VOID } from '../constants.js';
|
|
3
|
+
import { cloneNode } from '../utilities/node.js';
|
|
4
|
+
import { append } from '../utilities/fragment.js';
|
|
5
|
+
import text from '../utilities/text.js';
|
|
6
|
+
import reactive from './reactive.js';
|
|
7
|
+
function type(input) {
|
|
8
|
+
if (input === false || input == null || input === '') {
|
|
9
|
+
return RENDERABLE_VOID;
|
|
10
|
+
}
|
|
11
|
+
if (typeof input !== 'object') {
|
|
12
|
+
return RENDERABLE_TEXT;
|
|
13
|
+
}
|
|
14
|
+
if (RENDERABLE in input) {
|
|
15
|
+
return input[RENDERABLE];
|
|
16
|
+
}
|
|
17
|
+
if (isArray(input)) {
|
|
18
|
+
return RENDERABLE_ARRAY;
|
|
19
|
+
}
|
|
20
|
+
let nodeType = input.nodeType;
|
|
21
|
+
if (nodeType === 11) {
|
|
22
|
+
return RENDERABLE_FRAGMENT;
|
|
23
|
+
}
|
|
24
|
+
if (nodeType !== undefined) {
|
|
25
|
+
return RENDERABLE_NODE;
|
|
26
|
+
}
|
|
27
|
+
if (input instanceof NodeList) {
|
|
28
|
+
return RENDERABLE_NODE_LIST;
|
|
29
|
+
}
|
|
30
|
+
return RENDERABLE_TEXT;
|
|
31
|
+
}
|
|
32
|
+
function loop(fragment, input) {
|
|
33
|
+
let t = type(input);
|
|
34
|
+
switch (t) {
|
|
35
|
+
case RENDERABLE_HTML_REACTIVE_ARRAY:
|
|
36
|
+
throw new Error('@esportsplus/template: reactive arrays cannot be defined within an slot array value');
|
|
37
|
+
case RENDERABLE_VOID:
|
|
38
|
+
return;
|
|
39
|
+
case RENDERABLE_ARRAY:
|
|
40
|
+
for (let i = 0, n = input.length; i < n; i++) {
|
|
41
|
+
loop(fragment, input[i]);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
case RENDERABLE_NODE_LIST:
|
|
45
|
+
append.call(fragment, ...input);
|
|
46
|
+
return;
|
|
47
|
+
default:
|
|
48
|
+
append.call(fragment, input);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
let scratchpad = cloneNode.call(EMPTY_FRAGMENT);
|
|
53
|
+
export default function render(anchor, input) {
|
|
54
|
+
let fragment = scratchpad, t = type(input);
|
|
55
|
+
switch (t) {
|
|
56
|
+
case RENDERABLE_VOID:
|
|
57
|
+
break;
|
|
58
|
+
case RENDERABLE_TEXT:
|
|
59
|
+
append.call(fragment, text(input));
|
|
60
|
+
break;
|
|
61
|
+
case RENDERABLE_HTML_FRAGMENT:
|
|
62
|
+
return input.fragment;
|
|
63
|
+
case RENDERABLE_HTML_REACTIVE_ARRAY:
|
|
64
|
+
return reactive(anchor, input);
|
|
65
|
+
case RENDERABLE_ARRAY:
|
|
66
|
+
for (let i = 0, n = input.length; i < n; i++) {
|
|
67
|
+
loop(fragment, input[i]);
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case RENDERABLE_FRAGMENT:
|
|
71
|
+
return input;
|
|
72
|
+
case RENDERABLE_NODE:
|
|
73
|
+
append.call(fragment, input);
|
|
74
|
+
break;
|
|
75
|
+
case RENDERABLE_NODE_LIST:
|
|
76
|
+
append.call(fragment, ...input);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
return fragment;
|
|
80
|
+
}
|
|
81
|
+
;
|
package/build/svg.d.ts
CHANGED
package/build/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ReactiveArray } from '@esportsplus/reactivity';
|
|
2
|
-
import { RENDERABLE,
|
|
3
|
-
import { firstChild } from './utilities.js';
|
|
2
|
+
import { RENDERABLE, RENDERABLE_HTML_FRAGMENT, RENDERABLE_HTML_REACTIVE_ARRAY } from './constants.js';
|
|
3
|
+
import { firstChild } from './utilities/node.js';
|
|
4
4
|
import attributes from './attributes.js';
|
|
5
|
-
import slot from './slot.js';
|
|
5
|
+
import slot from './slot/index.js';
|
|
6
|
+
import html from './html/index.js';
|
|
6
7
|
type Attribute = Primitive | Effect<Primitive | Primitive[]>;
|
|
7
8
|
type Attributes = {
|
|
8
9
|
class?: Attribute | Attribute[];
|
|
@@ -17,25 +18,28 @@ type Attributes = {
|
|
|
17
18
|
onrender?: (element: Element) => void;
|
|
18
19
|
} & Record<PropertyKey, unknown>;
|
|
19
20
|
type Effect<T> = () => EffectResponse<T>;
|
|
20
|
-
type EffectResponse<T> = T extends [] ?
|
|
21
|
+
type EffectResponse<T> = T extends [] ? (Primitive | Renderable)[] : Primitive | Renderable;
|
|
21
22
|
type Element = HTMLElement & Attributes & Record<PropertyKey, unknown>;
|
|
22
23
|
type Elements = Element[];
|
|
23
|
-
type Fragment = DocumentFragment | Node
|
|
24
|
+
type Fragment = (DocumentFragment | Node) & Record<PropertyKey, unknown>;
|
|
24
25
|
type Primitive = bigint | boolean | null | number | string | undefined;
|
|
25
|
-
type Renderable
|
|
26
|
-
type RenderableReactive
|
|
27
|
-
[RENDERABLE]: typeof
|
|
28
|
-
|
|
29
|
-
template: (this:
|
|
30
|
-
values: ReactiveArray<T>;
|
|
26
|
+
type Renderable = Fragment | Primitive | RenderableReactive | RenderableTemplate;
|
|
27
|
+
type RenderableReactive = Readonly<{
|
|
28
|
+
[RENDERABLE]: typeof RENDERABLE_HTML_REACTIVE_ARRAY;
|
|
29
|
+
array: ReactiveArray<unknown[]>;
|
|
30
|
+
template: (this: ReactiveArray<unknown[]>, ...args: Parameters<Parameters<ReactiveArray<unknown[]>['map']>[0]>) => ReturnType<typeof html>;
|
|
31
31
|
}>;
|
|
32
|
-
type RenderableTemplate
|
|
33
|
-
[RENDERABLE]: typeof
|
|
32
|
+
type RenderableTemplate = {
|
|
33
|
+
[RENDERABLE]: typeof RENDERABLE_HTML_FRAGMENT;
|
|
34
|
+
fragment: Fragment;
|
|
34
35
|
literals: TemplateStringsArray;
|
|
35
|
-
template: Template | null;
|
|
36
|
-
values: (RenderableValue<T> | RenderableValue<T>[])[];
|
|
37
36
|
};
|
|
38
|
-
type RenderableValue<T = unknown> = Attributes | Readonly<Attributes> | Readonly<Attributes[]> | Effect<T> | Primitive |
|
|
37
|
+
type RenderableValue<T = unknown> = Attributes | Readonly<Attributes> | Readonly<Attributes[]> | Effect<T> | Fragment | Primitive | RenderableReactive;
|
|
38
|
+
type RenderableValues = RenderableValue | RenderableValue[];
|
|
39
|
+
type SlotGroup = {
|
|
40
|
+
head: Element;
|
|
41
|
+
tail: Element;
|
|
42
|
+
};
|
|
39
43
|
type Template = {
|
|
40
44
|
fragment: DocumentFragment;
|
|
41
45
|
html: string;
|
|
@@ -50,4 +54,4 @@ type Template = {
|
|
|
50
54
|
slot: number;
|
|
51
55
|
}[] | null;
|
|
52
56
|
};
|
|
53
|
-
export type { Attributes, Effect, Element, Elements, Fragment, Renderable, RenderableReactive, RenderableTemplate, RenderableValue, Template };
|
|
57
|
+
export type { Attributes, Effect, Element, Elements, Fragment, Renderable, RenderableReactive, RenderableTemplate, RenderableValue, RenderableValues, SlotGroup, Template };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const addEventListener: {
|
|
2
|
+
<K extends keyof ElementEventMap>(type: K, listener: (this: Element, ev: ElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
3
|
+
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
4
|
+
};
|
|
5
|
+
declare const className: (v: any) => void;
|
|
6
|
+
declare const innerHTML: (v: any) => void;
|
|
7
|
+
declare const firstElementChild: () => any;
|
|
8
|
+
declare const nextElementSibling: () => any;
|
|
9
|
+
declare const removeAttribute: (qualifiedName: string) => void;
|
|
10
|
+
declare const setAttribute: (qualifiedName: string, value: string) => void;
|
|
11
|
+
export { addEventListener, className, innerHTML, firstElementChild, nextElementSibling, removeAttribute, setAttribute };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, prototype = Element.prototype;
|
|
2
|
+
const addEventListener = prototype.addEventListener;
|
|
3
|
+
const className = getOwnPropertyDescriptor(prototype, 'className').set;
|
|
4
|
+
const innerHTML = getOwnPropertyDescriptor(prototype, 'innerHTML').set;
|
|
5
|
+
const firstElementChild = getOwnPropertyDescriptor(prototype, 'firstElementChild').get;
|
|
6
|
+
const nextElementSibling = getOwnPropertyDescriptor(prototype, 'nextElementSibling').get;
|
|
7
|
+
const removeAttribute = prototype.removeAttribute;
|
|
8
|
+
const setAttribute = prototype.setAttribute;
|
|
9
|
+
export { addEventListener, className, innerHTML, firstElementChild, nextElementSibling, removeAttribute, setAttribute };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { innerHTML } from './element.js';
|
|
2
|
+
import { cloneNode } from './node.js';
|
|
3
|
+
let prototype = DocumentFragment.prototype, template = document.createElement('template');
|
|
4
|
+
const append = prototype.append;
|
|
5
|
+
const fragment = (html) => {
|
|
6
|
+
innerHTML.call(template, html);
|
|
7
|
+
let content = template.content;
|
|
8
|
+
template = cloneNode.call(template);
|
|
9
|
+
return content;
|
|
10
|
+
};
|
|
11
|
+
export { append, fragment };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const cloneNode: (subtree?: boolean) => Node;
|
|
2
|
+
declare const firstChild: () => any;
|
|
3
|
+
declare const lastChild: () => any;
|
|
4
|
+
declare const nextSibling: () => any;
|
|
5
|
+
declare const nodeValue: (v: any) => void;
|
|
6
|
+
declare const parentElement: () => any;
|
|
7
|
+
declare const previousSibling: () => any;
|
|
8
|
+
export { cloneNode, firstChild, lastChild, nextSibling, nodeValue, parentElement, previousSibling };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, prototype = Node.prototype;
|
|
2
|
+
const cloneNode = prototype.cloneNode;
|
|
3
|
+
const firstChild = getOwnPropertyDescriptor(prototype, 'firstChild').get;
|
|
4
|
+
const lastChild = getOwnPropertyDescriptor(prototype, 'lastChild').get;
|
|
5
|
+
const nextSibling = getOwnPropertyDescriptor(prototype, 'nextSibling').get;
|
|
6
|
+
const nodeValue = getOwnPropertyDescriptor(prototype, 'nodeValue').set;
|
|
7
|
+
const parentElement = getOwnPropertyDescriptor(prototype, 'parentElement').get;
|
|
8
|
+
const previousSibling = getOwnPropertyDescriptor(prototype, 'previousSibling').get;
|
|
9
|
+
export { cloneNode, firstChild, lastChild, nextSibling, nodeValue, parentElement, previousSibling };
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "ICJR",
|
|
3
3
|
"dependencies": {
|
|
4
4
|
"@esportsplus/queue": "^0.1.0",
|
|
5
|
-
"@esportsplus/reactivity": "^0.
|
|
5
|
+
"@esportsplus/reactivity": "^0.15.0",
|
|
6
6
|
"@esportsplus/tasks": "^0.2.1",
|
|
7
7
|
"@esportsplus/utilities": "^0.22.1"
|
|
8
8
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"private": false,
|
|
15
15
|
"type": "module",
|
|
16
16
|
"types": "./build/index.d.ts",
|
|
17
|
-
"version": "0.
|
|
17
|
+
"version": "0.18.0",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc && tsc-alias",
|
|
20
20
|
"-": "-"
|