@esportsplus/template 0.28.1 → 0.29.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/.github/workflows/bump.yml +2 -2
- package/.github/workflows/dependabot.yml +1 -1
- package/.github/workflows/publish.yml +2 -2
- package/build/attributes.d.ts +7 -1
- package/build/attributes.js +86 -33
- package/build/constants.d.ts +3 -11
- package/build/constants.js +4 -32
- package/build/event/constants.d.ts +3 -0
- package/build/event/constants.js +13 -0
- package/build/event/index.d.ts +9 -1
- package/build/event/index.js +29 -35
- package/build/event/ontick.js +6 -9
- package/build/html.d.ts +9 -0
- package/build/html.js +7 -0
- package/build/index.d.ts +8 -2
- package/build/index.js +8 -1
- package/build/render.d.ts +2 -2
- package/build/render.js +2 -3
- package/build/runtime.d.ts +1 -0
- package/build/runtime.js +5 -0
- package/build/slot/array.d.ts +3 -3
- package/build/slot/array.js +11 -14
- package/build/slot/cleanup.d.ts +1 -1
- package/build/slot/cleanup.js +1 -2
- package/build/slot/effect.js +5 -7
- package/build/slot/index.js +1 -7
- package/build/slot/render.js +6 -8
- package/build/svg.d.ts +1 -1
- package/build/svg.js +1 -1
- package/build/transformer/codegen.d.ts +18 -0
- package/build/transformer/codegen.js +316 -0
- package/build/transformer/index.d.ts +12 -0
- package/build/transformer/index.js +62 -0
- package/build/transformer/parser.d.ts +18 -0
- package/build/transformer/parser.js +166 -0
- package/build/transformer/plugins/esbuild.d.ts +5 -0
- package/build/transformer/plugins/esbuild.js +35 -0
- package/build/transformer/plugins/tsc.d.ts +3 -0
- package/build/transformer/plugins/tsc.js +4 -0
- package/build/transformer/plugins/vite.d.ts +5 -0
- package/build/transformer/plugins/vite.js +37 -0
- package/build/transformer/ts-parser.d.ts +21 -0
- package/build/transformer/ts-parser.js +72 -0
- package/build/transformer/type-analyzer.d.ts +7 -0
- package/build/transformer/type-analyzer.js +230 -0
- package/build/types.d.ts +2 -3
- package/build/utilities.d.ts +7 -0
- package/build/utilities.js +31 -0
- package/package.json +11 -4
- package/src/attributes.ts +115 -51
- package/src/constants.ts +6 -53
- package/src/event/constants.ts +16 -0
- package/src/event/index.ts +36 -42
- package/src/event/onconnect.ts +1 -1
- package/src/event/onresize.ts +1 -1
- package/src/event/ontick.ts +7 -11
- package/src/html.ts +18 -0
- package/src/index.ts +8 -2
- package/src/render.ts +6 -7
- package/src/runtime.ts +8 -0
- package/src/slot/array.ts +18 -24
- package/src/slot/cleanup.ts +3 -4
- package/src/slot/effect.ts +6 -8
- package/src/slot/index.ts +2 -8
- package/src/slot/render.ts +7 -9
- package/src/svg.ts +1 -1
- package/src/transformer/codegen.ts +518 -0
- package/src/transformer/index.ts +98 -0
- package/src/transformer/parser.ts +239 -0
- package/src/transformer/plugins/esbuild.ts +46 -0
- package/src/transformer/plugins/tsc.ts +7 -0
- package/src/transformer/plugins/vite.ts +49 -0
- package/src/transformer/ts-parser.ts +123 -0
- package/src/transformer/type-analyzer.ts +334 -0
- package/src/types.ts +3 -4
- package/src/utilities.ts +52 -0
- package/storage/rewrite-analysis-2026-01-04.md +439 -0
- package/test/constants.ts +69 -0
- package/test/effects.ts +237 -0
- package/test/events.ts +318 -0
- package/test/imported-values.ts +253 -0
- package/test/nested.ts +298 -0
- package/test/slots.ts +259 -0
- package/test/spread.ts +290 -0
- package/test/static.ts +118 -0
- package/test/templates.ts +473 -0
- package/test/tsconfig.json +17 -0
- package/test/vite.config.ts +50 -0
- package/build/html/index.d.ts +0 -9
- package/build/html/index.js +0 -29
- package/build/html/parser.d.ts +0 -5
- package/build/html/parser.js +0 -165
- package/build/utilities/element.d.ts +0 -11
- package/build/utilities/element.js +0 -9
- package/build/utilities/fragment.d.ts +0 -3
- package/build/utilities/fragment.js +0 -10
- package/build/utilities/marker.d.ts +0 -2
- package/build/utilities/marker.js +0 -4
- package/build/utilities/node.d.ts +0 -9
- package/build/utilities/node.js +0 -10
- package/build/utilities/raf.d.ts +0 -2
- package/build/utilities/raf.js +0 -1
- package/build/utilities/text.d.ts +0 -2
- package/build/utilities/text.js +0 -9
- package/src/html/index.ts +0 -48
- package/src/html/parser.ts +0 -235
- package/src/utilities/element.ts +0 -28
- package/src/utilities/fragment.ts +0 -19
- package/src/utilities/marker.ts +0 -6
- package/src/utilities/node.ts +0 -29
- package/src/utilities/raf.ts +0 -1
- package/src/utilities/text.ts +0 -15
package/build/html/parser.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { NODE_CLOSING, NODE_ELEMENT, NODE_SLOT, NODE_VOID, NODE_WHITELIST, REGEX_EMPTY_TEXT_NODES, REGEX_EVENTS, REGEX_SLOT_ATTRIBUTES, REGEX_SLOT_NODES, SLOT_HTML, SLOT_MARKER } from '../constants.js';
|
|
2
|
-
import { firstElementChild, nextElementSibling } from '../utilities/element.js';
|
|
3
|
-
import { firstChild, nextSibling } from '../utilities/node.js';
|
|
4
|
-
import { fragment } from '../utilities/fragment.js';
|
|
5
|
-
import a from '../attributes.js';
|
|
6
|
-
import s from '../slot/index.js';
|
|
7
|
-
let cache = new WeakMap();
|
|
8
|
-
function build(literals) {
|
|
9
|
-
let n = literals.length - 1;
|
|
10
|
-
if (n === 0) {
|
|
11
|
-
return set(literals, literals[0]);
|
|
12
|
-
}
|
|
13
|
-
let attributes = {}, buffer = '', events = false, html = literals.join(SLOT_MARKER)
|
|
14
|
-
.replace(REGEX_EMPTY_TEXT_NODES, '$1$2')
|
|
15
|
-
.trim(), index = 0, level = 0, levels = [{
|
|
16
|
-
children: 0,
|
|
17
|
-
elements: 0,
|
|
18
|
-
path: []
|
|
19
|
-
}], parsed = html.split(SLOT_MARKER), slot = 0, slots = [];
|
|
20
|
-
{
|
|
21
|
-
let attribute = '', buffer = '', char = '', match, quote = '';
|
|
22
|
-
REGEX_SLOT_ATTRIBUTES.lastIndex = 0;
|
|
23
|
-
while (match = REGEX_SLOT_ATTRIBUTES.exec(html)) {
|
|
24
|
-
let found = match[1], metadata = attributes[found];
|
|
25
|
-
if (metadata) {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
metadata = attributes[found] = [];
|
|
29
|
-
for (let i = 0, n = found.length; i < n; i++) {
|
|
30
|
-
char = found[i];
|
|
31
|
-
if (char === ' ') {
|
|
32
|
-
buffer = '';
|
|
33
|
-
}
|
|
34
|
-
else if (char === '=') {
|
|
35
|
-
attribute = buffer;
|
|
36
|
-
buffer = '';
|
|
37
|
-
}
|
|
38
|
-
else if (char === '"' || char === "'") {
|
|
39
|
-
if (!attribute) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
else if (!quote) {
|
|
43
|
-
quote = char;
|
|
44
|
-
}
|
|
45
|
-
else if (quote === char) {
|
|
46
|
-
attribute = '';
|
|
47
|
-
buffer = '';
|
|
48
|
-
quote = '';
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else if (char === '{' && char !== buffer) {
|
|
52
|
-
buffer = char;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
buffer += char;
|
|
56
|
-
if (buffer === SLOT_MARKER) {
|
|
57
|
-
buffer = '';
|
|
58
|
-
if (attribute) {
|
|
59
|
-
metadata.push(attribute);
|
|
60
|
-
if (!quote) {
|
|
61
|
-
attribute = '';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
metadata.push(null);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else if (buffer === 'on') {
|
|
69
|
-
events = true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
REGEX_SLOT_NODES.lastIndex = 0;
|
|
76
|
-
{
|
|
77
|
-
let match;
|
|
78
|
-
while (match = REGEX_SLOT_NODES.exec(html)) {
|
|
79
|
-
let parent = levels[level], type = match[1] === undefined ? NODE_SLOT : (NODE_WHITELIST[match[1].toLowerCase()] || NODE_ELEMENT);
|
|
80
|
-
if ((match.index || 1) - 1 > index) {
|
|
81
|
-
parent.children++;
|
|
82
|
-
}
|
|
83
|
-
if (type === NODE_ELEMENT || type === NODE_VOID) {
|
|
84
|
-
let attr = match[2], path = parent.path.length
|
|
85
|
-
? methods(parent.elements, parent.path, firstElementChild, nextElementSibling)
|
|
86
|
-
: methods(parent.children, [], firstChild, nextSibling);
|
|
87
|
-
if (attr) {
|
|
88
|
-
let metadata = attributes[attr];
|
|
89
|
-
if (!metadata) {
|
|
90
|
-
throw new Error(`Template: attribute metadata could not be found for '${attr}'`);
|
|
91
|
-
}
|
|
92
|
-
for (let i = 0, n = metadata.length; i < n; i++) {
|
|
93
|
-
let name = metadata[i];
|
|
94
|
-
slots.push({
|
|
95
|
-
fn: name === null ? a.spread : a.set,
|
|
96
|
-
name,
|
|
97
|
-
path
|
|
98
|
-
});
|
|
99
|
-
buffer += parsed[slot++];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (type === NODE_ELEMENT) {
|
|
103
|
-
levels[++level] = {
|
|
104
|
-
children: 0,
|
|
105
|
-
elements: 0,
|
|
106
|
-
path
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
parent.elements++;
|
|
110
|
-
}
|
|
111
|
-
else if (type === NODE_SLOT) {
|
|
112
|
-
buffer += parsed[slot++] + SLOT_HTML;
|
|
113
|
-
slots.push({
|
|
114
|
-
fn: s,
|
|
115
|
-
name: null,
|
|
116
|
-
path: methods(parent.children, parent.path, firstChild, nextSibling)
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
if (n === slot) {
|
|
120
|
-
buffer += parsed[slot];
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
if (type === NODE_CLOSING) {
|
|
124
|
-
level--;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
parent.children++;
|
|
128
|
-
}
|
|
129
|
-
index = (match.index || 0) + match[0].length;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (events) {
|
|
133
|
-
buffer = buffer.replace(REGEX_EVENTS, '');
|
|
134
|
-
}
|
|
135
|
-
return set(literals, buffer, slots);
|
|
136
|
-
}
|
|
137
|
-
function methods(children, copy, first, next) {
|
|
138
|
-
let length = copy.length, methods = new Array(length + 1 + children);
|
|
139
|
-
for (let i = 0, n = length; i < n; i++) {
|
|
140
|
-
methods[i] = copy[i];
|
|
141
|
-
}
|
|
142
|
-
methods[length] = first;
|
|
143
|
-
for (let i = 0, n = children; i < n; i++) {
|
|
144
|
-
methods[length + 1 + i] = next;
|
|
145
|
-
}
|
|
146
|
-
return methods;
|
|
147
|
-
}
|
|
148
|
-
function set(literals, html, slots = null) {
|
|
149
|
-
let value = {
|
|
150
|
-
fragment: fragment(html),
|
|
151
|
-
html,
|
|
152
|
-
literals,
|
|
153
|
-
slots
|
|
154
|
-
};
|
|
155
|
-
cache.set(literals, value);
|
|
156
|
-
return value;
|
|
157
|
-
}
|
|
158
|
-
const parse = (literals) => {
|
|
159
|
-
let result = cache.get(literals);
|
|
160
|
-
if (result === undefined) {
|
|
161
|
-
result = build(literals);
|
|
162
|
-
}
|
|
163
|
-
return result;
|
|
164
|
-
};
|
|
165
|
-
export default { parse };
|
|
@@ -1,11 +0,0 @@
|
|
|
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 };
|
|
@@ -1,9 +0,0 @@
|
|
|
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 };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { innerHTML } from './element.js';
|
|
2
|
-
import { cloneNode } from './node.js';
|
|
3
|
-
let template = document.createElement('template');
|
|
4
|
-
const append = DocumentFragment.prototype.append;
|
|
5
|
-
const fragment = (html) => {
|
|
6
|
-
let element = cloneNode.call(template);
|
|
7
|
-
innerHTML.call(element, html);
|
|
8
|
-
return element.content;
|
|
9
|
-
};
|
|
10
|
-
export { append, fragment };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const appendChild: <T extends Node>(node: T) => T;
|
|
2
|
-
declare const cloneNode: (subtree?: boolean) => Node;
|
|
3
|
-
declare const firstChild: () => any;
|
|
4
|
-
declare const lastChild: () => any;
|
|
5
|
-
declare const nextSibling: () => any;
|
|
6
|
-
declare const nodeValue: (v: any) => void;
|
|
7
|
-
declare const parentElement: () => any;
|
|
8
|
-
declare const previousSibling: () => any;
|
|
9
|
-
export { appendChild, cloneNode, firstChild, lastChild, nextSibling, nodeValue, parentElement, previousSibling };
|
package/build/utilities/node.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, prototype = Node.prototype;
|
|
2
|
-
const appendChild = prototype.appendChild;
|
|
3
|
-
const cloneNode = prototype.cloneNode;
|
|
4
|
-
const firstChild = getOwnPropertyDescriptor(prototype, 'firstChild').get;
|
|
5
|
-
const lastChild = getOwnPropertyDescriptor(prototype, 'lastChild').get;
|
|
6
|
-
const nextSibling = getOwnPropertyDescriptor(prototype, 'nextSibling').get;
|
|
7
|
-
const nodeValue = getOwnPropertyDescriptor(prototype, 'nodeValue').set;
|
|
8
|
-
const parentElement = getOwnPropertyDescriptor(prototype, 'parentElement').get;
|
|
9
|
-
const previousSibling = getOwnPropertyDescriptor(prototype, 'previousSibling').get;
|
|
10
|
-
export { appendChild, cloneNode, firstChild, lastChild, nextSibling, nodeValue, parentElement, previousSibling };
|
package/build/utilities/raf.d.ts
DELETED
package/build/utilities/raf.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default globalThis?.requestAnimationFrame;
|
package/build/utilities/text.js
DELETED
package/src/html/index.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ReactiveArray } from '@esportsplus/reactivity';
|
|
2
|
-
import { Attribute, Attributes, Renderable } from '~/types';
|
|
3
|
-
import { cloneNode } from '~/utilities/node';
|
|
4
|
-
import { ArraySlot } from '~/slot/array';
|
|
5
|
-
import parser from './parser';
|
|
6
|
-
import attributes from '~/attributes';
|
|
7
|
-
import slot from '~/slot';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type Values<T> = Attribute | Attributes<any> | ArraySlot<T> | Renderable<T>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const html = <T>(literals: TemplateStringsArray, ...values: (Values<T> | Values<T>[])[]) => {
|
|
14
|
-
let { fragment, slots } = parser.parse(literals),
|
|
15
|
-
clone = cloneNode.call(fragment, true);
|
|
16
|
-
|
|
17
|
-
if (slots !== null) {
|
|
18
|
-
let e, p;
|
|
19
|
-
|
|
20
|
-
for (let i = slots.length - 1; i >= 0; i--) {
|
|
21
|
-
let { fn, name, path } = slots[i];
|
|
22
|
-
|
|
23
|
-
if (p !== path) {
|
|
24
|
-
e = clone;
|
|
25
|
-
|
|
26
|
-
for (let i = 0, n = path.length; i < n; i++) {
|
|
27
|
-
e = path[i].call(e);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (name === null) {
|
|
32
|
-
(fn as typeof attributes.spread | typeof slot)(e, values[i] as any);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
(fn as typeof attributes.set)(e, name, values[i]);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return clone;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
html.reactive = <T>(arr: ReactiveArray<T>, template: (value: T) => ReturnType<typeof html>) => {
|
|
44
|
-
return new ArraySlot(arr, template);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export default html;
|
package/src/html/parser.ts
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
NODE_CLOSING, NODE_ELEMENT, NODE_SLOT, NODE_VOID, NODE_WHITELIST,
|
|
3
|
-
REGEX_EMPTY_TEXT_NODES, REGEX_EVENTS, REGEX_SLOT_ATTRIBUTES, REGEX_SLOT_NODES,
|
|
4
|
-
SLOT_HTML, SLOT_MARKER
|
|
5
|
-
} from '~/constants';
|
|
6
|
-
import { Template } from '~/types';
|
|
7
|
-
import { firstElementChild, nextElementSibling } from '~/utilities/element';
|
|
8
|
-
import { firstChild, nextSibling } from '~/utilities/node';
|
|
9
|
-
import { fragment } from '~/utilities/fragment';
|
|
10
|
-
import a from '~/attributes';
|
|
11
|
-
import s from '~/slot';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let cache = new WeakMap<TemplateStringsArray, Template>();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function build(literals: TemplateStringsArray) {
|
|
18
|
-
let n = literals.length - 1;
|
|
19
|
-
|
|
20
|
-
if (n === 0) {
|
|
21
|
-
return set(literals, literals[0]);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let attributes: Record<string, (null | string)[]> = {},
|
|
25
|
-
buffer = '',
|
|
26
|
-
events = false,
|
|
27
|
-
html = literals.join(SLOT_MARKER)
|
|
28
|
-
.replace(REGEX_EMPTY_TEXT_NODES, '$1$2')
|
|
29
|
-
.trim(),
|
|
30
|
-
index = 0,
|
|
31
|
-
level = 0,
|
|
32
|
-
levels = [{
|
|
33
|
-
children: 0,
|
|
34
|
-
elements: 0,
|
|
35
|
-
path: [] as NonNullable<Template['slots']>[number]['path']
|
|
36
|
-
}],
|
|
37
|
-
parsed = html.split(SLOT_MARKER),
|
|
38
|
-
slot = 0,
|
|
39
|
-
slots: Template['slots'] = [];
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
let attribute = '',
|
|
43
|
-
buffer = '',
|
|
44
|
-
char = '',
|
|
45
|
-
match: RegExpExecArray | null,
|
|
46
|
-
quote = '';
|
|
47
|
-
|
|
48
|
-
REGEX_SLOT_ATTRIBUTES.lastIndex = 0;
|
|
49
|
-
|
|
50
|
-
while (match = REGEX_SLOT_ATTRIBUTES.exec(html)) {
|
|
51
|
-
let found = match[1],
|
|
52
|
-
metadata = attributes[found];
|
|
53
|
-
|
|
54
|
-
if (metadata) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
metadata = attributes[found] = [];
|
|
59
|
-
|
|
60
|
-
for (let i = 0, n = found.length; i < n; i++) {
|
|
61
|
-
char = found[i];
|
|
62
|
-
|
|
63
|
-
if (char === ' ') {
|
|
64
|
-
buffer = '';
|
|
65
|
-
}
|
|
66
|
-
else if (char === '=') {
|
|
67
|
-
attribute = buffer;
|
|
68
|
-
buffer = '';
|
|
69
|
-
}
|
|
70
|
-
else if (char === '"' || char === "'") {
|
|
71
|
-
if (!attribute) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
else if (!quote) {
|
|
75
|
-
quote = char;
|
|
76
|
-
}
|
|
77
|
-
else if (quote === char) {
|
|
78
|
-
attribute = '';
|
|
79
|
-
buffer = '';
|
|
80
|
-
quote = '';
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else if (char === '{' && char !== buffer) {
|
|
84
|
-
buffer = char;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
buffer += char;
|
|
88
|
-
|
|
89
|
-
if (buffer === SLOT_MARKER) {
|
|
90
|
-
buffer = '';
|
|
91
|
-
|
|
92
|
-
if (attribute) {
|
|
93
|
-
metadata.push(attribute);
|
|
94
|
-
|
|
95
|
-
if (!quote) {
|
|
96
|
-
attribute = '';
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
metadata.push(null);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else if (buffer === 'on') {
|
|
104
|
-
events = true;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
REGEX_SLOT_NODES.lastIndex = 0;
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
let match: RegExpExecArray | null;
|
|
115
|
-
|
|
116
|
-
while (match = REGEX_SLOT_NODES.exec(html)) {
|
|
117
|
-
let parent = levels[level],
|
|
118
|
-
type = match[1] === undefined ? NODE_SLOT : (NODE_WHITELIST[match[1].toLowerCase()] || NODE_ELEMENT);
|
|
119
|
-
|
|
120
|
-
// Text nodes
|
|
121
|
-
if ((match.index || 1) - 1 > index) {
|
|
122
|
-
parent.children++;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (type === NODE_ELEMENT || type === NODE_VOID) {
|
|
126
|
-
let attr = match[2],
|
|
127
|
-
path = parent.path.length
|
|
128
|
-
? methods(parent.elements, parent.path, firstElementChild, nextElementSibling)
|
|
129
|
-
: methods(parent.children, [], firstChild, nextSibling);
|
|
130
|
-
|
|
131
|
-
if (attr) {
|
|
132
|
-
let metadata = attributes[attr];
|
|
133
|
-
|
|
134
|
-
if (!metadata) {
|
|
135
|
-
throw new Error(`Template: attribute metadata could not be found for '${attr}'`);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
for (let i = 0, n = metadata.length; i < n; i++) {
|
|
139
|
-
let name = metadata[i];
|
|
140
|
-
|
|
141
|
-
slots.push({
|
|
142
|
-
fn: name === null ? a.spread : a.set,
|
|
143
|
-
name,
|
|
144
|
-
path
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
buffer += parsed[slot++];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (type === NODE_ELEMENT) {
|
|
152
|
-
levels[++level] = {
|
|
153
|
-
children: 0,
|
|
154
|
-
elements: 0,
|
|
155
|
-
path
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
parent.elements++;
|
|
160
|
-
}
|
|
161
|
-
else if (type === NODE_SLOT) {
|
|
162
|
-
buffer += parsed[slot++] + SLOT_HTML;
|
|
163
|
-
slots.push({
|
|
164
|
-
fn: s,
|
|
165
|
-
name: null,
|
|
166
|
-
path: methods(parent.children, parent.path, firstChild, nextSibling)
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (n === slot) {
|
|
171
|
-
buffer += parsed[slot];
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (type === NODE_CLOSING) {
|
|
176
|
-
level--;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
parent.children++;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
index = (match.index || 0) + match[0].length;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (events) {
|
|
187
|
-
buffer = buffer.replace(REGEX_EVENTS, '');
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return set(literals, buffer, slots);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function methods(children: number, copy: (typeof firstChild)[], first: (typeof firstChild), next: (typeof firstChild)) {
|
|
194
|
-
let length = copy.length,
|
|
195
|
-
methods: (typeof firstChild)[] = new Array(length + 1 + children);
|
|
196
|
-
|
|
197
|
-
for (let i = 0, n = length; i < n; i++) {
|
|
198
|
-
methods[i] = copy[i];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
methods[length] = first;
|
|
202
|
-
|
|
203
|
-
for (let i = 0, n = children; i < n; i++) {
|
|
204
|
-
methods[length + 1 + i] = next;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return methods;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function set(literals: TemplateStringsArray, html: string, slots: Template['slots'] = null) {
|
|
211
|
-
let value = {
|
|
212
|
-
fragment: fragment(html),
|
|
213
|
-
html,
|
|
214
|
-
literals,
|
|
215
|
-
slots
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
cache.set(literals, value);
|
|
219
|
-
|
|
220
|
-
return value;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const parse = (literals: TemplateStringsArray) => {
|
|
225
|
-
let result = cache.get(literals);
|
|
226
|
-
|
|
227
|
-
if (result === undefined) {
|
|
228
|
-
result = build(literals);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return result;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
export default { parse };
|
package/src/utilities/element.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor,
|
|
2
|
-
prototype = Element.prototype;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const addEventListener = prototype.addEventListener;
|
|
6
|
-
|
|
7
|
-
const className = getOwnPropertyDescriptor(prototype, 'className')!.set!;
|
|
8
|
-
|
|
9
|
-
const innerHTML = getOwnPropertyDescriptor(prototype, 'innerHTML')!.set!;
|
|
10
|
-
|
|
11
|
-
const firstElementChild = getOwnPropertyDescriptor(prototype, 'firstElementChild')!.get!;
|
|
12
|
-
|
|
13
|
-
const nextElementSibling = getOwnPropertyDescriptor(prototype, 'nextElementSibling')!.get!;
|
|
14
|
-
|
|
15
|
-
const removeAttribute = prototype.removeAttribute;
|
|
16
|
-
|
|
17
|
-
const setAttribute = prototype.setAttribute;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
addEventListener,
|
|
22
|
-
className,
|
|
23
|
-
innerHTML,
|
|
24
|
-
firstElementChild,
|
|
25
|
-
nextElementSibling,
|
|
26
|
-
removeAttribute,
|
|
27
|
-
setAttribute
|
|
28
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { innerHTML } from './element';
|
|
2
|
-
import { cloneNode } from './node';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let template = document.createElement('template');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const append = DocumentFragment.prototype.append;
|
|
9
|
-
|
|
10
|
-
const fragment = (html: string): DocumentFragment => {
|
|
11
|
-
let element = cloneNode.call(template) as HTMLTemplateElement;
|
|
12
|
-
|
|
13
|
-
innerHTML.call(element, html);
|
|
14
|
-
|
|
15
|
-
return element.content;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export { append, fragment };
|
package/src/utilities/marker.ts
DELETED
package/src/utilities/node.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor,
|
|
2
|
-
prototype = Node.prototype;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const appendChild = prototype.appendChild;
|
|
6
|
-
|
|
7
|
-
const cloneNode = prototype.cloneNode;
|
|
8
|
-
|
|
9
|
-
const firstChild = getOwnPropertyDescriptor(prototype, 'firstChild')!.get!;
|
|
10
|
-
|
|
11
|
-
const lastChild = getOwnPropertyDescriptor(prototype, 'lastChild')!.get!;
|
|
12
|
-
|
|
13
|
-
const nextSibling = getOwnPropertyDescriptor(prototype, 'nextSibling')!.get!;
|
|
14
|
-
|
|
15
|
-
const nodeValue = getOwnPropertyDescriptor(prototype, 'nodeValue')!.set!;
|
|
16
|
-
|
|
17
|
-
const parentElement = getOwnPropertyDescriptor(prototype, 'parentElement')!.get!;
|
|
18
|
-
|
|
19
|
-
const previousSibling = getOwnPropertyDescriptor(prototype, 'previousSibling')!.get!;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
appendChild,
|
|
24
|
-
cloneNode,
|
|
25
|
-
firstChild,
|
|
26
|
-
lastChild,
|
|
27
|
-
nextSibling, nodeValue,
|
|
28
|
-
parentElement, previousSibling
|
|
29
|
-
};
|
package/src/utilities/raf.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default globalThis?.requestAnimationFrame;
|
package/src/utilities/text.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { cloneNode, nodeValue } from './node';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let text = document.createTextNode('');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default (value: string) => {
|
|
8
|
-
let element = cloneNode.call(text);
|
|
9
|
-
|
|
10
|
-
if (value !== '') {
|
|
11
|
-
nodeValue.call(element, value);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return element;
|
|
15
|
-
};
|