@solidjs/html 2.0.0-beta.3 → 2.0.0-beta.30

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,565 +1,18 @@
1
- import { SVGNamespace, SVGElements, DelegatedEvents, ChildProperties, Properties, addEventListener, setAttributeNS, setAttribute, dynamicProperty, mergeProps, className, delegateEvents, createComponent, spread, untrack, insert, style, effect } from '@solidjs/web';
1
+ import { RawTextElements, VoidElements, MathMLElements, SVGElements, claimElement, 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, isSVG, 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 isProp = r.Properties.has(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},${isSVG},_$p)`);
246
- } else if (isChildProp || !isSVG && isProp || namespace === "prop") {
247
- options.exprs.push(`${tag}.${name} = ${expr}`);
248
- } else {
249
- const ns = isSVG && name.indexOf(":") > -1 && r.SVGNamespace[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, isSVG, 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, isSVG, 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.hasCustomElement = options.hasCustomElement || childOptions.hasCustomElement;
329
- options.isImportNode = options.isImportNode || childOptions.isImportNode;
330
- }
331
- function processComponentProps(propGroups) {
332
- let result = [];
333
- for (const props of propGroups) {
334
- if (Array.isArray(props)) {
335
- if (!props.length) continue;
336
- result.push(`r.wrapProps({${props.join(",") || ""}})`);
337
- } else result.push(props);
338
- }
339
- return result.length > 1 ? `r.mergeProps(${result.join(",")})` : result[0];
340
- }
341
- function processComponent(node, options) {
342
- let props = [];
343
- const keys = Object.keys(node.attrs),
344
- propGroups = [props],
345
- componentIdentifier = options.counter++;
346
- for (let i = 0; i < keys.length; i++) {
347
- const {
348
- type,
349
- name,
350
- value
351
- } = node.attrs[i];
352
- if (type === "attr") {
353
- if (name === "###") {
354
- propGroups.push(`exprs[${options.counter++}]`);
355
- propGroups.push(props = []);
356
- } else if (value === "###") {
357
- props.push(`"${name}": exprs[${options.counter++}]`);
358
- } else props.push(`"${name}": "${value}"`);
359
- }
360
- }
361
- if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
362
- props.push(`children: () => exprs[${options.counter++}]`);
363
- } else if (node.children.length) {
364
- const children = {
365
- type: "fragment",
366
- children: node.children
367
- },
368
- childOptions = Object.assign({}, options, {
369
- first: true,
370
- decl: [],
371
- exprs: [],
372
- parent: false
373
- });
374
- parseNode(children, childOptions);
375
- props.push(`children: () => { ${childOptions.exprs.join(";\n")}}`);
376
- options.templateId = childOptions.templateId;
377
- options.counter = childOptions.counter;
378
- }
379
- let tag;
380
- if (options.multi) {
381
- tag = `_$el${uuid++}`;
382
- options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
383
- }
384
- 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)})`);
385
- options.path = tag;
386
- options.first = false;
387
- }
388
- function parseNode(node, options) {
389
- if (node.type === "fragment") {
390
- const parts = [];
391
- node.children.forEach(child => {
392
- if (child.type === "tag") {
393
- if (child.name === "###") {
394
- const childOptions = Object.assign({}, options, {
395
- first: true,
396
- fragment: true,
397
- decl: [],
398
- exprs: []
399
- });
400
- processComponent(child, childOptions);
401
- parts.push(childOptions.exprs[0]);
402
- options.counter = childOptions.counter;
403
- options.templateId = childOptions.templateId;
404
- return;
405
- }
406
- options.templateId++;
407
- const id = uuid;
408
- const childOptions = Object.assign({}, options, {
409
- first: true,
410
- decl: [],
411
- exprs: []
412
- });
413
- options.templateNodes.push([child]);
414
- parseNode(child, childOptions);
415
- parts.push(`function() { ${childOptions.decl.join(",\n") + ";\n" + childOptions.exprs.join(";\n") + `;\nreturn _$el${id};\n`}}()`);
416
- options.counter = childOptions.counter;
417
- options.templateId = childOptions.templateId;
418
- } else if (child.type === "text") {
419
- parts.push(`"${child.content}"`);
420
- } else if (child.type === "comment") {
421
- if (child.content === "#") parts.push(`exprs[${options.counter++}]`);else if (child.content) {
422
- for (let i = 0; i < child.content.split("###").length - 1; i++) {
423
- parts.push(`exprs[${options.counter++}]`);
424
- }
425
- }
426
- }
427
- });
428
- options.exprs.push(`return [${parts.join(", \n")}]`);
429
- } else if (node.type === "tag") {
430
- const tag = `_$el${uuid++}`;
431
- const topDecl = !options.decl.length;
432
- const templateId = options.templateId;
433
- options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
434
- const isSVG = r.SVGElements.has(node.name);
435
- options.hasCustomElement = node.name.includes("-") || node.attrs.some(e => e.name === "is");
436
- options.isImportNode = (node.name === "img" || node.name === "iframe") && node.attrs.some(e => e.name === "loading" && e.value === "lazy");
437
- if (node.attrs.some(e => e.name === "###")) {
438
- const spreadArgs = [];
439
- let current = "";
440
- const newAttrs = [];
441
- for (let i = 0; i < node.attrs.length; i++) {
442
- const {
443
- type,
444
- name,
445
- value
446
- } = node.attrs[i];
447
- if (type === "attr") {
448
- if (value.includes("###")) {
449
- let count = options.counter++;
450
- current += `${name}: ${name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""}exprs[${count}],`;
451
- } else if (name === "###") {
452
- if (current.length) {
453
- spreadArgs.push(`()=>({${current}})`);
454
- current = "";
455
- }
456
- spreadArgs.push(`exprs[${options.counter++}]`);
457
- } else {
458
- newAttrs.push(node.attrs[i]);
459
- }
460
- }
461
- }
462
- node.attrs = newAttrs;
463
- if (current.length) {
464
- spreadArgs.push(`()=>({${current}})`);
465
- }
466
- options.exprs.push(`r.spread(${tag},${spreadArgs.length === 1 ? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}` : `r.mergeProps(${spreadArgs.join(",")})`},${isSVG},${!!node.children.length})`);
467
- } else {
468
- for (let i = 0; i < node.attrs.length; i++) {
469
- const {
470
- type,
471
- name,
472
- value
473
- } = node.attrs[i];
474
- if (type === "attr") {
475
- if (value.includes("###")) {
476
- node.attrs.splice(i, 1);
477
- i--;
478
- parseAttribute(node, tag, name, value, isSVG, options);
479
- }
480
- }
481
- }
482
- }
483
- options.path = tag;
484
- options.first = false;
485
- processChildren(node, options);
486
- if (topDecl) {
487
- options.decl[0] = options.hasCustomElement || options.isImportNode ? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))` : `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`;
488
- }
489
- } else if (node.type === "text") {
490
- const tag = `_$el${uuid++}`;
491
- options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
492
- options.path = tag;
493
- options.first = false;
494
- } else if (node.type === "comment") {
495
- const tag = `_$el${uuid++}`;
496
- options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
497
- if (node.content === "#") {
498
- if (options.multi) {
499
- options.exprs.push(`r.insert(${options.parent}, exprs[${options.counter++}], ${tag})`);
500
- } else options.exprs.push(`r.insert(${options.parent}, exprs[${options.counter++}])`);
501
- }
502
- options.path = tag;
503
- options.first = false;
504
- }
505
- }
506
- function parseTemplate(nodes, funcBuilder) {
507
- const options = {
508
- path: "",
509
- decl: [],
510
- exprs: [],
511
- delegatedEvents: new Set(),
512
- counter: 0,
513
- first: true,
514
- multi: false,
515
- templateId: 0,
516
- templateNodes: []
517
- },
518
- id = uuid,
519
- origNodes = nodes;
520
- let toplevel;
521
- if (nodes.length > 1) {
522
- nodes = [{
523
- type: "fragment",
524
- children: nodes
525
- }];
526
- }
527
- if (nodes[0].name === "###") {
528
- toplevel = true;
529
- processComponent(nodes[0], options);
530
- } else parseNode(nodes[0], options);
531
- r.delegateEvents(Array.from(options.delegatedEvents));
532
- const templateNodes = [origNodes].concat(options.templateNodes);
533
- return [templateNodes.map(t => stringify(t)), funcBuilder("tmpls", "exprs", "r", options.decl.join(",\n") + ";\n" + options.exprs.join(";\n") + (toplevel ? "" : `;\nreturn _$el${id};\n`))];
534
- }
535
- function html(statics, ...args) {
536
- const templates = cache.get(statics) || createTemplate(statics, {
537
- funcBuilder: functionBuilder
538
- });
539
- return templates[0].create(templates, args, r);
540
- }
541
- return html;
542
- }
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-2]?.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){let e=u.charCodeAt(c+1),t=u.slice(c+2).search(/\S/),n=e===47&&a[a.length-1]?.type===0&&t!==-1&&u[c+2+t]===`>`;e===47&&!n?o=4:e===42?o=5:(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 at ${l}:${c}`);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]} at ${l}:${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:case 4:case 5:{let e=o===4?`
4
+ `:o===5?`*/`:`-->`,t=u.indexOf(e,c);t===-1?c=d:(o=o===3?0:1,c=t+e.length);break}}l<r.length-1&&(o===0||o===1||o===2)&&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 for <${o.name}>`)}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 in <${c.name}> 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 for "${n}" in <${c.name}> must be an expression or a string`)}else c.props.push({type:0,name:n,value:true}),a++;}else throw Error(`Invalid attribute in <${c.name}>`)}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)} after <${r[r.length-1].name}>`)}}if(r.length>1)throw Error(`Unclosed tag for <${r[r.length-1].name}>`);return n},o=e=>e.length===1?e[0]:e;function s(e){let t=new WeakMap,n=new Set(e.RawTextElements);n.delete(`template`);let i=document.createTreeWalker(document,129),s=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),c=e=>{let t=(t,...n)=>m(l(t),n,e);return t.components=e,t.jsx=t,t.define=t=>c({...e,...t}),t},l=i=>{let o=t.get(i);return o||(o=a(r(i,n),e.VoidElements),u(o,false),t.set(i,o)),o},u=(e,t)=>{if(e.type===1){if(!t){let n=document.createElement(`template`);n.content.appendChild(f(e)),e.template=n,t=true;}e.children.forEach(e=>u(e,t));}else e.type===2||e.type===0?e.children.forEach(e=>u(e,false)):e.type===3&&!t&&(d.innerHTML=e.value,e.value=d.content.textContent??``);},d=document.createElement(`template`),f=e=>{switch(e.type){case 3:return d.innerHTML=e.value,document.createTextNode(d.content.textContent??``);case 4:return document.createComment(`+`);case 2:return document.createComment(e.name);case 1:let t=false,n=s(e.name),r=e.name===`a`?`href`:e.name===`form`?`action`:void 0;return e.props=e.props.filter(i=>i.type===1?i.name.startsWith(`prop:`)?true:(n.setAttribute(i.name,i.value),!t&&i.name===r&&(e.claim=true),t):i.type===0?(n.setAttribute(i.name,``),!t&&i.name===r&&(e.claim=true),t):i.type===3?(t=true,t):true),(e.name===`template`?n.content:n).append(...e.children.map(f)),n}},p=(t,n,r)=>{switch(t.type){case 3:return t.value;case 4:return n[t.value];case 2:let i=typeof t.name==`string`?r[t.name]:n[t.name];if(i&&typeof i==`function`)return e.createComponent(i,h(t,n,r));throw Error(`Component "${t.name}" not found in registry`);case 1:let a=m(t,n,r),o=h(t,n,r);return e.spread(a,o,true),t.claim&&e.claimElement(a),a}},m=(t,n,r)=>{if(t.type!==1||!t.template)return o(t.children.map(e=>p(e,n,r)));let a=t.template.content.firstChild.cloneNode(true);i.currentNode=a;let s=(t,i)=>{for(let a of t)if(a.type===1||a.type===4||a.type===2){let t=i.nextNode();if(a.type===4||a.type===2)e.insert(t.parentNode,p(a,n,r),t),i.currentNode=t;else {if(a.props.length){let i=h(a,n,r);e.spread(t,i,true);}a.claim&&e.claimElement(t),s(a.children,a.name===`template`?document.createTreeWalker(t.content,129):i);}}};return s(t.children,t.name===`template`?document.createTreeWalker(a.content,129):i),a},h=(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:g(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 m(t,n,r)}}),i},g=(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 c({})}
543
5
 
544
- const html = createHTML({
545
- effect,
546
- style,
6
+ const html = s({
547
7
  insert,
548
- untrack,
549
8
  spread,
550
9
  createComponent,
551
- delegateEvents,
552
- className,
553
10
  mergeProps,
554
- dynamicProperty,
555
- setAttribute,
556
- setAttributeNS,
557
- addEventListener,
558
- Properties,
559
- ChildProperties,
560
- DelegatedEvents,
11
+ claimElement,
561
12
  SVGElements,
562
- SVGNamespace
13
+ MathMLElements,
14
+ VoidElements,
15
+ RawTextElements
563
16
  });
564
17
 
565
18
  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.3",
3
+ "description": "Tagged-template-literal templating for Solid — write components with no build step.",
4
+ "version": "2.0.0-beta.30",
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"
@@ -20,28 +21,36 @@
20
21
  "files": [
21
22
  "dist",
22
23
  "types",
24
+ "types-cjs",
23
25
  "package.json"
24
26
  ],
25
27
  "exports": {
26
28
  ".": {
27
- "types": "./types/index.d.ts",
28
- "import": "./dist/html.js",
29
- "require": "./dist/html.cjs"
30
- },
31
- "./dist/*": "./dist/*"
29
+ "import": {
30
+ "types": "./types/index.d.ts",
31
+ "default": "./dist/html.js"
32
+ },
33
+ "require": {
34
+ "types": "./types-cjs/index.d.cts",
35
+ "default": "./dist/html.cjs"
36
+ }
37
+ }
32
38
  },
33
39
  "peerDependencies": {
34
- "@solidjs/web": "^2.0.0-beta.3"
40
+ "@solidjs/web": "^2.0.0-beta.30"
35
41
  },
36
42
  "devDependencies": {
37
- "@solidjs/web": "2.0.0-beta.3"
43
+ "@solidjs/web": "2.0.0-beta.30",
44
+ "solid-js": "2.0.0-beta.30"
38
45
  },
39
46
  "scripts": {
40
47
  "build": "npm-run-all -nl build:*",
41
48
  "build:clean": "rimraf dist/ coverage/",
42
49
  "build:js": "rollup -c",
43
- "types": "npm-run-all -nl types:*",
44
- "types:clean": "rimraf types/",
45
- "types:html": "tsc --project ./tsconfig.json && ncp ../../node_modules/lit-dom-expressions/types/index.d.ts ./types/lit.d.ts"
50
+ "types": "npm-run-all -nl types:clean types:html types:cjs",
51
+ "types:clean": "rimraf types/ types-cjs/",
52
+ "types:html": "tsc --project ./tsconfig.json && ncp ../../node_modules/@dom-expressions/tagged-jsx/dist/index.d.mts ./types/tagged-jsx.d.ts",
53
+ "types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs",
54
+ "test": "vitest run"
46
55
  }
47
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 { TaggedJSXInstance } from "./tagged-jsx.js";
2
+ declare const html: TaggedJSXInstance<{}>;
3
3
  export default html;