@solidjs/html 2.0.0-beta.8 → 2.0.0-beta.9

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/dist/html.js CHANGED
@@ -1,563 +1,16 @@
1
- import { Namespaces, MathMLElements, SVGElements, DelegatedEvents, ChildProperties, DOMWithState, addEventListener, setAttributeNS, setAttribute, dynamicProperty, mergeProps, className, delegateEvents, createComponent, spread, untrack, insert, style, effect } from '@solidjs/web';
1
+ import { RawTextElements, VoidElements, MathMLElements, SVGElements, mergeProps, createComponent, spread, insert } from '@solidjs/web';
2
2
 
3
- const tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
4
- const attrRE = /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g;
5
- const lookup = {
6
- area: true,
7
- base: true,
8
- br: true,
9
- col: true,
10
- embed: true,
11
- hr: true,
12
- img: true,
13
- input: true,
14
- keygen: true,
15
- link: true,
16
- menuitem: true,
17
- meta: true,
18
- param: true,
19
- source: true,
20
- track: true,
21
- wbr: true
22
- };
23
- function parseTag(tag) {
24
- const res = {
25
- type: 'tag',
26
- name: '',
27
- voidElement: false,
28
- attrs: [],
29
- children: []
30
- };
31
- const tagMatch = tag.match(/<\/?([^\s]+?)[/\s>]/);
32
- if (tagMatch) {
33
- res.name = tagMatch[1];
34
- if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === '/') {
35
- res.voidElement = true;
36
- }
37
- if (res.name.startsWith('!--')) {
38
- const endIndex = tag.indexOf('-->');
39
- return {
40
- type: 'comment',
41
- comment: endIndex !== -1 ? tag.slice(4, endIndex) : ''
42
- };
43
- }
44
- }
45
- const reg = new RegExp(attrRE);
46
- for (const match of tag.matchAll(reg)) {
47
- if ((match[1] || match[2]).startsWith('use:')) {
48
- res.attrs.push({
49
- type: 'directive',
50
- name: match[1] || match[2],
51
- value: match[4] || match[5] || ''
52
- });
53
- } else {
54
- res.attrs.push({
55
- type: 'attr',
56
- name: match[1] || match[2],
57
- value: match[4] || match[5] || ''
58
- });
59
- }
60
- }
61
- return res;
62
- }
63
- function pushTextNode(list, html, start) {
64
- const end = html.indexOf('<', start);
65
- const content = html.slice(start, end === -1 ? void 0 : end);
66
- if (!/^\s*$/.test(content)) {
67
- list.push({
68
- type: 'text',
69
- content: content
70
- });
71
- }
72
- }
73
- function pushCommentNode(list, tag) {
74
- const content = tag.replace('<!--', '').replace('-->', '');
75
- if (!/^\s*$/.test(content)) {
76
- list.push({
77
- type: 'comment',
78
- content: content
79
- });
80
- }
81
- }
82
- function parse(html) {
83
- const result = [];
84
- let current = void 0;
85
- let level = -1;
86
- const arr = [];
87
- const byTag = {};
88
- html.replace(tagRE, (tag, index) => {
89
- const isOpen = tag.charAt(1) !== '/';
90
- const isComment = tag.slice(0, 4) === '<!--';
91
- const start = index + tag.length;
92
- const nextChar = html.charAt(start);
93
- let parent = void 0;
94
- if (isOpen && !isComment) {
95
- level++;
96
- current = parseTag(tag);
97
- if (!current.voidElement && nextChar && nextChar !== '<') {
98
- pushTextNode(current.children, html, start);
99
- }
100
- byTag[current.tagName] = current;
101
- if (level === 0) {
102
- result.push(current);
103
- }
104
- parent = arr[level - 1];
105
- if (parent) {
106
- parent.children.push(current);
107
- }
108
- arr[level] = current;
109
- }
110
- if (isComment) {
111
- if (level < 0) {
112
- pushCommentNode(result, tag);
113
- } else {
114
- pushCommentNode(arr[level].children, tag);
115
- }
116
- }
117
- if (isComment || !isOpen || current.voidElement) {
118
- if (!isComment) {
119
- level--;
120
- }
121
- if (nextChar !== '<' && nextChar) {
122
- parent = level === -1 ? result : arr[level].children;
123
- pushTextNode(parent, html, start);
124
- }
125
- }
126
- });
127
- return result;
128
- }
129
- function attrString(attrs) {
130
- const buff = [];
131
- for (const attr of attrs) {
132
- buff.push(attr.name + '="' + attr.value.replace(/"/g, '&quot;') + '"');
133
- }
134
- if (!buff.length) {
135
- return '';
136
- }
137
- return ' ' + buff.join(' ');
138
- }
139
- function stringifier(buff, doc) {
140
- switch (doc.type) {
141
- case 'text':
142
- return buff + doc.content;
143
- case 'tag':
144
- buff += '<' + doc.name + (doc.attrs ? attrString(doc.attrs) : '') + (doc.voidElement ? '/>' : '>');
145
- if (doc.voidElement) {
146
- return buff;
147
- }
148
- return buff + doc.children.reduce(stringifier, '') + '</' + doc.name + '>';
149
- case 'comment':
150
- return buff += '<!--' + doc.content + '-->';
151
- }
152
- }
153
- function stringify(doc) {
154
- return doc.reduce(function (token, rootEl) {
155
- return token + stringifier('', rootEl);
156
- }, '');
157
- }
158
- const cache = new Map();
159
- const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
160
- const spaces = " \\f\\n\\r\\t";
161
- const almostEverything = "[^" + spaces + "\\/>\"'=]+";
162
- const attrName = "[ " + spaces + "]+" + almostEverything;
163
- const tagName = "<([A-Za-z$#]+[A-Za-z0-9:_-]*)((?:";
164
- const attrPartials = "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)";
165
- const attrSeeker = new RegExp(tagName + attrName + attrPartials + "+)([ " + spaces + "]*/?>)", "g");
166
- const findAttributes = new RegExp("(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])", "gi");
167
- const selfClosing = new RegExp(tagName + attrName + attrPartials + "*)([ " + spaces + "]*/>)", "g");
168
- const marker = "<!--#-->";
169
- const reservedNameSpaces = new Set(["class", "on", "style", "prop"]);
170
- function attrReplacer($0, $1, $2, $3) {
171
- return "<" + $1 + $2.replace(findAttributes, replaceAttributes) + $3;
172
- }
173
- function replaceAttributes($0, $1, $2) {
174
- return $1.replace(/<!--#-->/g, "###") + ($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"');
175
- }
176
- function fullClosing($0, $1, $2) {
177
- return VOID_ELEMENTS.test($1) ? $0 : "<" + $1 + $2 + "></" + $1 + ">";
178
- }
179
- function createHTML(r, {
180
- delegateEvents = true,
181
- functionBuilder = (...args) => new Function(...args)
182
- } = {}) {
183
- let uuid = 1;
184
- r.wrapProps = props => {
185
- const d = Object.getOwnPropertyDescriptors(props);
186
- for (const k in d) {
187
- if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k);
188
- }
189
- return props;
190
- };
191
- r.resolveFn = fn => typeof fn === "function" ? fn() : fn;
192
- function createTemplate(statics, opt) {
193
- let i = 0,
194
- markup = "";
195
- for (; i < statics.length - 1; i++) {
196
- markup = markup + statics[i] + "<!--#-->";
197
- }
198
- markup = markup + statics[i];
199
- const replaceList = [[selfClosing, fullClosing], [/<(<!--#-->)/g, "<###"], [/\.\.\.(<!--#-->)/g, "###"], [attrSeeker, attrReplacer], [/>\n+\s*/g, ">"], [/\n+\s*</g, "<"], [/\s+</g, " <"], [/>\s+/g, "> "]];
200
- markup = replaceList.reduce((acc, x) => {
201
- return acc.replace(x[0], x[1]);
202
- }, markup);
203
- const pars = parse(markup);
204
- const [html, code] = parseTemplate(pars, opt.funcBuilder),
205
- templates = [];
206
- for (let i = 0; i < html.length; i++) {
207
- templates.push(document.createElement("template"));
208
- templates[i].innerHTML = html[i];
209
- const nomarkers = templates[i].content.querySelectorAll("script,style");
210
- for (let j = 0; j < nomarkers.length; j++) {
211
- const d = nomarkers[j].firstChild?.data || "";
212
- if (d.indexOf(marker) > -1) {
213
- const parts = d.split(marker).reduce((memo, p, i) => {
214
- i && memo.push("");
215
- memo.push(p);
216
- return memo;
217
- }, []);
218
- nomarkers[i].firstChild.replaceWith(...parts);
219
- }
220
- }
221
- }
222
- templates[0].create = code;
223
- cache.set(statics, templates);
224
- return templates;
225
- }
226
- function parseKeyValue(node, tag, name, value, options) {
227
- let expr, parts, namespace;
228
- if (value === "###") {
229
- expr = `_$v`;
230
- options.counter++;
231
- } else {
232
- const chunks = value.split("###");
233
- options.counter = chunks.length - 1 + options.counter;
234
- expr = chunks.map((v, i) => i ? ` + _$v[${i - 1}] + "${v}"` : `"${v}"`).join("");
235
- }
236
- if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
237
- name = parts[1];
238
- namespace = parts[0];
239
- }
240
- const isChildProp = r.ChildProperties.has(name);
241
- const isLockedDOMProperty = !!r.DOMWithState[node.name.toUpperCase()]?.[name];
242
- if (name === "style") {
243
- options.exprs.push(`r.style(${tag},${expr},_$p)`);
244
- } else if (name === "class") {
245
- options.exprs.push(`r.className(${tag},${expr},_$p)`);
246
- } else if (isChildProp || isLockedDOMProperty || namespace === "prop") {
247
- options.exprs.push(`${tag}.${name} = ${expr}`);
248
- } else {
249
- const ns = name.indexOf(":") > -1 && r.Namespaces[name.split(":")[0]];
250
- if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`);else options.exprs.push(`r.setAttribute(${tag},"${name}",${expr})`);
251
- }
252
- }
253
- function parseAttribute(node, tag, name, value, options) {
254
- if (name.slice(0, 2) === "on") {
255
- if (!name.includes(":")) {
256
- const lc = name.slice(2).toLowerCase();
257
- const delegate = delegateEvents && r.DelegatedEvents.has(lc);
258
- options.exprs.push(`r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})`);
259
- delegate && options.delegatedEvents.add(lc);
260
- } else {
261
- options.exprs.push(`${tag}.addEventListener("${name.slice(3)}",exprs[${options.counter++}])`);
262
- }
263
- } else if (name === "ref") {
264
- options.exprs.push(`r.ref(() => exprs[${options.counter++}], ${tag})`);
265
- } else {
266
- const childOptions = Object.assign({}, options, {
267
- exprs: []
268
- }),
269
- count = options.counter;
270
- parseKeyValue(node, tag, name, value, childOptions);
271
- options.decl.push(`_fn${count} = (_$v, _$p) => {\n${childOptions.exprs.join(";\n")};\n}`);
272
- if (value === "###") {
273
- options.exprs.push(`typeof exprs[${count}] === "function" ? r.effect(() => exprs[${count}](), _fn${count}) : _fn${count}(exprs[${count}])`);
274
- } else {
275
- let check = "";
276
- let list = "";
277
- let reactiveList = "";
278
- for (let i = count; i < childOptions.counter; i++) {
279
- if (i !== count) {
280
- check += " || ";
281
- list += ",";
282
- reactiveList += ",";
283
- }
284
- check += `typeof exprs[${i}] === "function"`;
285
- list += `exprs[${i}]`;
286
- reactiveList += `r.resolveFn(exprs[${i}])`;
287
- }
288
- options.exprs.push(check + ` ? r.effect(() => [${reactiveList}], _fn${count}) : _fn${count}([${list}])`);
289
- }
290
- options.counter = childOptions.counter;
291
- options.wrap = false;
292
- }
293
- }
294
- function processChildren(node, options) {
295
- const childOptions = Object.assign({}, options, {
296
- first: true,
297
- multi: false,
298
- parent: options.path
299
- });
300
- if (node.children.length > 1) {
301
- for (let i = 0; i < node.children.length; i++) {
302
- const child = node.children[i];
303
- if (child.type === "comment" && child.content === "#" || child.type === "tag" && child.name === "###") {
304
- childOptions.multi = true;
305
- break;
306
- }
307
- }
308
- }
309
- let i = 0;
310
- while (i < node.children.length) {
311
- const child = node.children[i];
312
- if (child.name === "###") {
313
- if (childOptions.multi) {
314
- node.children[i] = {
315
- type: "comment",
316
- content: "#"
317
- };
318
- i++;
319
- } else node.children.splice(i, 1);
320
- processComponent(child, childOptions);
321
- continue;
322
- }
323
- parseNode(child, childOptions);
324
- if (!childOptions.multi && child.type === "comment" && child.content === "#") node.children.splice(i, 1);else i++;
325
- }
326
- options.counter = childOptions.counter;
327
- options.templateId = childOptions.templateId;
328
- options.isImportNode = options.isImportNode || childOptions.isImportNode;
329
- }
330
- function processComponentProps(propGroups) {
331
- let result = [];
332
- for (const props of propGroups) {
333
- if (Array.isArray(props)) {
334
- if (!props.length) continue;
335
- result.push(`r.wrapProps({${props.join(",") || ""}})`);
336
- } else result.push(props);
337
- }
338
- return result.length > 1 ? `r.mergeProps(${result.join(",")})` : result[0];
339
- }
340
- function processComponent(node, options) {
341
- let props = [];
342
- const keys = Object.keys(node.attrs),
343
- propGroups = [props],
344
- componentIdentifier = options.counter++;
345
- for (let i = 0; i < keys.length; i++) {
346
- const {
347
- type,
348
- name,
349
- value
350
- } = node.attrs[i];
351
- if (type === "attr") {
352
- if (name === "###") {
353
- propGroups.push(`exprs[${options.counter++}]`);
354
- propGroups.push(props = []);
355
- } else if (value === "###") {
356
- props.push(`"${name}": exprs[${options.counter++}]`);
357
- } else props.push(`"${name}": "${value}"`);
358
- }
359
- }
360
- if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
361
- props.push(`children: () => exprs[${options.counter++}]`);
362
- } else if (node.children.length) {
363
- const children = {
364
- type: "fragment",
365
- children: node.children
366
- },
367
- childOptions = Object.assign({}, options, {
368
- first: true,
369
- decl: [],
370
- exprs: [],
371
- parent: false
372
- });
373
- parseNode(children, childOptions);
374
- props.push(`children: () => { ${childOptions.exprs.join(";\n")}}`);
375
- options.templateId = childOptions.templateId;
376
- options.counter = childOptions.counter;
377
- }
378
- let tag;
379
- if (options.multi) {
380
- tag = `_$el${uuid++}`;
381
- options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
382
- }
383
- if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${tag ? `, ${tag}` : ""})`);else options.exprs.push(`${options.fragment ? "" : "return "}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`);
384
- options.path = tag;
385
- options.first = false;
386
- }
387
- function parseNode(node, options) {
388
- if (node.type === "fragment") {
389
- const parts = [];
390
- node.children.forEach(child => {
391
- if (child.type === "tag") {
392
- if (child.name === "###") {
393
- const childOptions = Object.assign({}, options, {
394
- first: true,
395
- fragment: true,
396
- decl: [],
397
- exprs: []
398
- });
399
- processComponent(child, childOptions);
400
- parts.push(childOptions.exprs[0]);
401
- options.counter = childOptions.counter;
402
- options.templateId = childOptions.templateId;
403
- return;
404
- }
405
- options.templateId++;
406
- const id = uuid;
407
- const childOptions = Object.assign({}, options, {
408
- first: true,
409
- decl: [],
410
- exprs: []
411
- });
412
- options.templateNodes.push([child]);
413
- parseNode(child, childOptions);
414
- parts.push(`function() { ${childOptions.decl.join(",\n") + ";\n" + childOptions.exprs.join(";\n") + `;\nreturn _$el${id};\n`}}()`);
415
- options.counter = childOptions.counter;
416
- options.templateId = childOptions.templateId;
417
- } else if (child.type === "text") {
418
- parts.push(`"${child.content}"`);
419
- } else if (child.type === "comment") {
420
- if (child.content === "#") parts.push(`exprs[${options.counter++}]`);else if (child.content) {
421
- for (let i = 0; i < child.content.split("###").length - 1; i++) {
422
- parts.push(`exprs[${options.counter++}]`);
423
- }
424
- }
425
- }
426
- });
427
- options.exprs.push(`return [${parts.join(", \n")}]`);
428
- } else if (node.type === "tag") {
429
- const tag = `_$el${uuid++}`;
430
- const topDecl = !options.decl.length;
431
- const templateId = options.templateId;
432
- options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
433
- options.isImportNode = node.name.includes("-") || node.attrs.some(e => e.name === "is") || (node.name === "img" || node.name === "iframe") && node.attrs.some(e => e.name === "loading" && e.value === "lazy");
434
- if (node.attrs.some(e => e.name === "###")) {
435
- const spreadArgs = [];
436
- let current = "";
437
- const newAttrs = [];
438
- for (let i = 0; i < node.attrs.length; i++) {
439
- const {
440
- type,
441
- name,
442
- value
443
- } = node.attrs[i];
444
- if (type === "attr") {
445
- if (value.includes("###")) {
446
- let count = options.counter++;
447
- current += `${name}: ${name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""}exprs[${count}],`;
448
- } else if (name === "###") {
449
- if (current.length) {
450
- spreadArgs.push(`()=>({${current}})`);
451
- current = "";
452
- }
453
- spreadArgs.push(`exprs[${options.counter++}]`);
454
- } else {
455
- newAttrs.push(node.attrs[i]);
456
- }
457
- }
458
- }
459
- node.attrs = newAttrs;
460
- if (current.length) {
461
- spreadArgs.push(`()=>({${current}})`);
462
- }
463
- options.exprs.push(`r.spread(${tag},${spreadArgs.length === 1 ? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}` : `r.mergeProps(${spreadArgs.join(",")})`},${!!node.children.length})`);
464
- } else {
465
- for (let i = 0; i < node.attrs.length; i++) {
466
- const {
467
- type,
468
- name,
469
- value
470
- } = node.attrs[i];
471
- if (type === "attr") {
472
- if (value.includes("###")) {
473
- node.attrs.splice(i, 1);
474
- i--;
475
- parseAttribute(node, tag, name, value, options);
476
- }
477
- }
478
- }
479
- }
480
- options.path = tag;
481
- options.first = false;
482
- processChildren(node, options);
483
- if (topDecl) {
484
- options.decl[0] = options.isImportNode ? `const ${tag} = document.importNode(tmpls[${templateId}].content.firstChild, true)` : `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`;
485
- }
486
- } else if (node.type === "text") {
487
- const tag = `_$el${uuid++}`;
488
- options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
489
- options.path = tag;
490
- options.first = false;
491
- } else if (node.type === "comment") {
492
- const tag = `_$el${uuid++}`;
493
- options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
494
- if (node.content === "#") {
495
- if (options.multi) {
496
- options.exprs.push(`r.insert(${options.parent}, exprs[${options.counter++}], ${tag})`);
497
- } else options.exprs.push(`r.insert(${options.parent}, exprs[${options.counter++}])`);
498
- }
499
- options.path = tag;
500
- options.first = false;
501
- }
502
- }
503
- function parseTemplate(nodes, funcBuilder) {
504
- const options = {
505
- path: "",
506
- decl: [],
507
- exprs: [],
508
- delegatedEvents: new Set(),
509
- counter: 0,
510
- first: true,
511
- multi: false,
512
- templateId: 0,
513
- templateNodes: []
514
- },
515
- id = uuid,
516
- origNodes = nodes;
517
- let toplevel;
518
- if (nodes.length > 1) {
519
- nodes = [{
520
- type: "fragment",
521
- children: nodes
522
- }];
523
- }
524
- if (nodes[0].name === "###") {
525
- toplevel = true;
526
- processComponent(nodes[0], options);
527
- } else parseNode(nodes[0], options);
528
- r.delegateEvents(Array.from(options.delegatedEvents));
529
- const templateNodes = [origNodes].concat(options.templateNodes);
530
- return [templateNodes.map(t => stringify(t)), funcBuilder("tmpls", "exprs", "r", options.decl.join(",\n") + ";\n" + options.exprs.join(";\n") + (toplevel ? "" : `;\nreturn _$el${id};\n`))];
531
- }
532
- function html(statics, ...args) {
533
- const templates = cache.get(statics) || createTemplate(statics, {
534
- funcBuilder: functionBuilder
535
- });
536
- return templates[0].create(templates, args, r);
537
- }
538
- return html;
539
- }
3
+ const e=e=>t(e)||e>=48&&e<=58||e===46||e===45,t=e=>e>=65&&e<=90||e>=97&&e<=122||e===95||e===36,n=e=>e>=9&&e<=13||e===32,r=(r,i)=>{let a=[],o=0,s=``,c=0;for(let l=0;l<r.length;l++){let u=r[l],d=u.length;for(c=0;c<d;)switch(o){case 0:{s=``;let e=u.indexOf(`<`,c);e===-1?(c<d&&a.push({type:6,value:u.slice(c)}),c=d):(e>c&&a.push({type:6,value:u.slice(c,e)}),u[e+1]===`!`&&u[e+2]===`-`&&u[e+3]===`-`?(o=3,c=e+4):(a.push({type:0}),o=1,c=e+1));break}case 1:{let r=u.charCodeAt(c);if(n(r))c++;else if(r===62)i.has(s)&&a[a.length-1]?.type!==2?o=2:(o=0,s=``),a.push({type:1}),c++;else if(r===61)a.push({type:4}),c++;else if(r===47)a.push({type:2}),c++;else if(r===34||r===39){let e=u[c],t=u.indexOf(e,c+1);if(t===-1)throw Error(`Unterminated string`);a.push({type:5,value:u.slice(c+1,t),quote:e}),c=t+1;}else if(t(r)){let t=c;for(;c<d&&e(u.charCodeAt(c));)c++;let n=u.slice(t,c);s===``&&(s=n),a.push({type:3,value:n});}else if(r===46&&u[c+1]===`.`&&u[c+2]===`.`)a.push({type:8}),c+=3;else throw Error(`Unexpected Character: ${u[c]}`);break}case 2:{let e=RegExp(`<\\s*/\\s*${s}\\s*>`,`g`);e.lastIndex=c;let t=e.exec(u);if(t){let e=t.index;e>c&&a.push({type:6,value:u.slice(c,e)}),o=0,c=e,s=``;}else a.push({type:6,value:u.slice(c)}),c=d;break}case 3:{let e=u.indexOf(`-->`,c);e===-1?c=d:(o=0,c=e+3);break}}l<r.length-1&&o!==3&&a.push({type:7,value:l});}return a},i=e=>{let t=e.charCodeAt(0);return t>=65&&t<=90},a=(e,t)=>{let n={type:0,children:[]},r=[n],a=0,o=e.length;for(;a<o;){let n=e[a],s=r[r.length-1];switch(n.type){case 6:{let t=n.value;if(t.trim()===``){let t=e[a-1]?.type,n=e[a+1]?.type;if(t===1||n===0){a++;continue}}s.children.push({type:3,value:t}),a++;continue}case 7:s.children.push({type:4,value:n.value}),a++;continue;case 0:{let n=e[++a];if(n.type===2){let n=e[++a],i=e[++a],o=r[r.length-1];if(r.length>1&&i.type===1&&(n?.type===3&&o.name===n.value||(n?.type===7||n.type===2)&&typeof o.name==`number`)){let e=r.pop();e?.type===1&&t.has(e.name)&&(e.children=[]),a++;continue}throw Error(`Mismatched closing tag.`)}if(n.type===3||n.type===7){let t=n.value,c={type:typeof t==`number`||i(t)?2:1,name:t,props:[],children:[]};for(s.children.push(c),a++;a<o;){let t=e[a];if(t.type===1||t.type===2)break;if(t.type===8){let t=e[a+1];if(t?.type===7)c.props.push({type:3,value:t.value}),a+=2;else throw Error(`Spread operator must be followed by an expression.`)}else if(t.type===3){let n=t.value;if(e[a+1]?.type===4){a+=2;let t=e[a];if(t.type===7)c.props.push({name:n,type:2,value:t.value}),a++;else if(t.type===5){let e=t.quote;c.props.push({name:n,value:t.value,quote:e,type:1}),a++;}else throw Error(`Attribute value must be an expression or a string.`)}else c.props.push({type:0,name:n,value:true}),a++;}else throw Error(`Invalid attribute.`)}let l=e[a];l.type===2?a+=2:l.type===1&&(a++,r.push(c));continue}}default:throw Error(`Unexpected token: ${JSON.stringify(n)}`)}}if(r.length>1)throw Error(`Unclosed tag found.`);return n},o=e=>e.length===1?e[0]:e;function s(e){let t=new WeakMap,n=document.createTreeWalker(document,129),i=t=>e.SVGElements.has(t)?document.createElementNS(`http://www.w3.org/2000/svg`,t):e.MathMLElements.has(t)?document.createElementNS(`http://www.w3.org/1998/Math/MathML`,t):document.createElement(t),s=e=>{let t=(t,...n)=>p(c(t),n,e);return t.components=e,t.sld=t,t.define=t=>s({...e,...t}),t},c=n=>{let i=t.get(n);return i||(i=a(r(n,e.RawTextElements),e.VoidElements),l(i),t.set(n,i)),i},l=e=>{if(e.type===0||e.type===2){if(e.children.some(e=>e.type===1)){let t=document.createElement(`template`);t.content.append(...e.children.map(d)),e.template=t;}e.children.forEach(l);}else e.type===1&&e.children.forEach(l);},u=document.createElement(`template`),d=e=>{switch(e.type){case 3:return u.innerHTML=e.value,document.createTextNode(u.content.textContent??``);case 4:return document.createComment(`+`);case 2:return document.createComment(e.name);case 1:let t=false,n=i(e.name);return e.props=e.props.filter(e=>e.type===1?e.name.startsWith(`prop:`)?true:(n.setAttribute(e.name,e.value),t):e.type===0?(n.setAttribute(e.name,``),t):e.type===3?(t=true,t):true),n.append(...e.children.map(d)),n}},f=(t,n,r)=>{switch(t.type){case 3:return t.value;case 4:return n[t.value];case 2:let a=typeof t.name==`string`?r[t.name]:n[t.name];if(a&&typeof a==`function`)return e.createComponent(a,m(t,n,r));throw Error(`Component "${t.name}" not found in registry`);case 1:let o=t.name,s=i(o),c=m(t,n,r);return e.spread(s,c,true),s}},p=(t,r,i)=>{if(!t.template)return o(t.children.map(e=>f(e,r,i)));let a=t.template.content.cloneNode(true);n.currentNode=a;let s=t=>{for(let a of t)if(a.type===1||a.type===4||a.type===2){let t=n.nextNode();if(a.type===4||a.type===2)e.insert(t.parentNode,f(a,r,i),t),n.currentNode=t;else {if(a.props.length){let n=m(a,r,i);e.spread(t,n,true);}s(a.children);}}};return s(t.children),a.childNodes.length===1?a.firstChild:Array.from(a.childNodes)},m=(t,n,r,i={})=>{for(let r of t.props)switch(r.type){case 0:i[r.name]=true;break;case 1:i[r.name]=r.value;break;case 2:h(i,r.name,n[r.value]);break;case 3:let t=n[r.value];if(!t||typeof t!=`object`)throw Error(`Can only spread objects`);i=e.mergeProps(i,t);break}return t.type===2&&t.children.length&&Object.defineProperty(i,`children`,{get(){return p(t,n,r)}}),i},h=(e,t,n)=>{typeof n==`function`&&n.length===0&&t!==`ref`&&!t.startsWith(`on`)?Object.defineProperty(e,t,{get(){return n()},enumerable:true}):e[t]=n;};return s({})}
540
4
 
541
- const html = createHTML({
542
- effect,
543
- style,
5
+ const html = s({
544
6
  insert,
545
- untrack,
546
7
  spread,
547
8
  createComponent,
548
- delegateEvents,
549
- className,
550
9
  mergeProps,
551
- dynamicProperty,
552
- setAttribute,
553
- setAttributeNS,
554
- addEventListener,
555
- DOMWithState,
556
- ChildProperties,
557
- DelegatedEvents,
558
10
  SVGElements,
559
11
  MathMLElements,
560
- Namespaces
12
+ VoidElements,
13
+ RawTextElements
561
14
  });
562
15
 
563
16
  export { html as default };
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@solidjs/html",
3
- "description": "Build-less Tagged-Template-Literal Templating for Solid",
4
- "version": "2.0.0-beta.8",
3
+ "description": "Tagged-template-literal templating for Solid — write components with no build step.",
4
+ "version": "2.0.0-beta.9",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/solidjs/solid-html"
10
+ "url": "git+https://github.com/solidjs/solid.git",
11
+ "directory": "packages/solid-html"
11
12
  },
12
13
  "publishConfig": {
13
14
  "access": "public"
@@ -36,10 +37,11 @@
36
37
  }
37
38
  },
38
39
  "peerDependencies": {
39
- "@solidjs/web": "^2.0.0-beta.8"
40
+ "@solidjs/web": "^2.0.0-beta.9"
40
41
  },
41
42
  "devDependencies": {
42
- "@solidjs/web": "2.0.0-beta.8"
43
+ "@solidjs/web": "2.0.0-beta.9",
44
+ "solid-js": "2.0.0-beta.9"
43
45
  },
44
46
  "scripts": {
45
47
  "build": "npm-run-all -nl build:*",
@@ -47,7 +49,8 @@
47
49
  "build:js": "rollup -c",
48
50
  "types": "npm-run-all -nl types:clean types:html types:cjs",
49
51
  "types:clean": "rimraf types/ types-cjs/",
50
- "types:html": "tsc --project ./tsconfig.json && ncp ../../node_modules/lit-dom-expressions/types/index.d.ts ./types/lit.d.ts",
51
- "types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs"
52
+ "types:html": "tsc --project ./tsconfig.json && ncp ../../node_modules/sld-dom-expressions/dist/index.d.mts ./types/sld.d.ts",
53
+ "types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs",
54
+ "test": "vitest run"
52
55
  }
53
56
  }
package/types/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { HTMLTag } from "./lit.js";
2
- declare const html: HTMLTag;
1
+ import type { SLDInstance } from "./sld.js";
2
+ declare const html: SLDInstance<{}>;
3
3
  export default html;