solid-js 1.9.3 → 2.0.0-experimental.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.
Files changed (76) hide show
  1. package/dist/dev.cjs +213 -1603
  2. package/dist/dev.js +159 -1749
  3. package/dist/server.cjs +88 -11
  4. package/dist/server.js +91 -11
  5. package/dist/solid.cjs +196 -1558
  6. package/dist/solid.js +139 -1682
  7. package/package.json +8 -154
  8. package/types/{render → client}/component.d.ts +0 -61
  9. package/types/client/core.d.ts +75 -0
  10. package/types/client/flow.d.ts +114 -0
  11. package/types/{render → client}/hydration.d.ts +0 -2
  12. package/types/{reactive → client}/observable.d.ts +1 -1
  13. package/types/index.d.ts +44 -55
  14. package/types/jsx.d.ts +1944 -174
  15. package/types/server/index.d.ts +1 -1
  16. package/types/server/reactive.d.ts +6 -1
  17. package/types/server/store.d.ts +6 -0
  18. package/h/dist/h.cjs +0 -115
  19. package/h/dist/h.js +0 -144
  20. package/h/jsx-dev-runtime/package.json +0 -8
  21. package/h/jsx-runtime/dist/jsx.cjs +0 -15
  22. package/h/jsx-runtime/dist/jsx.js +0 -10
  23. package/h/jsx-runtime/package.json +0 -8
  24. package/h/jsx-runtime/types/index.d.ts +0 -14
  25. package/h/jsx-runtime/types/jsx.d.ts +0 -2276
  26. package/h/package.json +0 -8
  27. package/h/types/hyperscript.d.ts +0 -20
  28. package/h/types/index.d.ts +0 -3
  29. package/html/dist/html.cjs +0 -583
  30. package/html/dist/html.js +0 -706
  31. package/html/package.json +0 -8
  32. package/html/types/index.d.ts +0 -3
  33. package/html/types/lit.d.ts +0 -60
  34. package/store/dist/dev.cjs +0 -454
  35. package/store/dist/dev.js +0 -525
  36. package/store/dist/server.cjs +0 -126
  37. package/store/dist/server.js +0 -126
  38. package/store/dist/store.cjs +0 -434
  39. package/store/dist/store.js +0 -499
  40. package/store/package.json +0 -46
  41. package/store/types/index.d.ts +0 -26
  42. package/store/types/modifiers.d.ts +0 -9
  43. package/store/types/mutable.d.ts +0 -8
  44. package/store/types/server.d.ts +0 -37
  45. package/store/types/store.d.ts +0 -263
  46. package/types/reactive/array.d.ts +0 -52
  47. package/types/reactive/scheduler.d.ts +0 -13
  48. package/types/reactive/signal.d.ts +0 -664
  49. package/types/render/Suspense.d.ts +0 -26
  50. package/types/render/flow.d.ts +0 -130
  51. package/types/render/index.d.ts +0 -4
  52. package/universal/dist/dev.cjs +0 -243
  53. package/universal/dist/dev.js +0 -257
  54. package/universal/dist/universal.cjs +0 -243
  55. package/universal/dist/universal.js +0 -257
  56. package/universal/package.json +0 -20
  57. package/universal/types/index.d.ts +0 -4
  58. package/universal/types/universal.d.ts +0 -29
  59. package/web/dist/dev.cjs +0 -804
  60. package/web/dist/dev.js +0 -1241
  61. package/web/dist/server.cjs +0 -793
  62. package/web/dist/server.js +0 -1214
  63. package/web/dist/web.cjs +0 -793
  64. package/web/dist/web.js +0 -1220
  65. package/web/package.json +0 -46
  66. package/web/storage/dist/storage.cjs +0 -12
  67. package/web/storage/dist/storage.js +0 -10
  68. package/web/storage/package.json +0 -15
  69. package/web/storage/types/index.d.ts +0 -2
  70. package/web/storage/types/index.js +0 -13
  71. package/web/types/client.d.ts +0 -79
  72. package/web/types/core.d.ts +0 -10
  73. package/web/types/index.d.ts +0 -54
  74. package/web/types/jsx.d.ts +0 -1
  75. package/web/types/server-mock.d.ts +0 -80
  76. package/web/types/server.d.ts +0 -177
package/html/dist/html.js DELETED
@@ -1,706 +0,0 @@
1
- import {
2
- effect,
3
- style,
4
- insert,
5
- untrack,
6
- spread,
7
- createComponent,
8
- delegateEvents,
9
- classList,
10
- mergeProps,
11
- dynamicProperty,
12
- setAttribute,
13
- setAttributeNS,
14
- addEventListener,
15
- Aliases,
16
- getPropAlias,
17
- Properties,
18
- ChildProperties,
19
- DelegatedEvents,
20
- SVGElements,
21
- SVGNamespace
22
- } from "solid-js/web";
23
-
24
- const tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
25
- const attrRE =
26
- /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g;
27
- const lookup = {
28
- area: true,
29
- base: true,
30
- br: true,
31
- col: true,
32
- embed: true,
33
- hr: true,
34
- img: true,
35
- input: true,
36
- keygen: true,
37
- link: true,
38
- menuitem: true,
39
- meta: true,
40
- param: true,
41
- source: true,
42
- track: true,
43
- wbr: true
44
- };
45
- function parseTag(tag) {
46
- const res = {
47
- type: "tag",
48
- name: "",
49
- voidElement: false,
50
- attrs: [],
51
- children: []
52
- };
53
- const tagMatch = tag.match(/<\/?([^\s]+?)[/\s>]/);
54
- if (tagMatch) {
55
- res.name = tagMatch[1];
56
- if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === "/") {
57
- res.voidElement = true;
58
- }
59
- if (res.name.startsWith("!--")) {
60
- const endIndex = tag.indexOf("-->");
61
- return {
62
- type: "comment",
63
- comment: endIndex !== -1 ? tag.slice(4, endIndex) : ""
64
- };
65
- }
66
- }
67
- const reg = new RegExp(attrRE);
68
- for (const match of tag.matchAll(reg)) {
69
- if ((match[1] || match[2]).startsWith("use:")) {
70
- res.attrs.push({
71
- type: "directive",
72
- name: match[1] || match[2],
73
- value: match[4] || match[5] || ""
74
- });
75
- } else {
76
- res.attrs.push({
77
- type: "attr",
78
- name: match[1] || match[2],
79
- value: match[4] || match[5] || ""
80
- });
81
- }
82
- }
83
- return res;
84
- }
85
- function pushTextNode(list, html, start) {
86
- const end = html.indexOf("<", start);
87
- const content = html.slice(start, end === -1 ? void 0 : end);
88
- if (!/^\s*$/.test(content)) {
89
- list.push({
90
- type: "text",
91
- content: content
92
- });
93
- }
94
- }
95
- function pushCommentNode(list, tag) {
96
- const content = tag.replace("<!--", "").replace("-->", "");
97
- if (!/^\s*$/.test(content)) {
98
- list.push({
99
- type: "comment",
100
- content: content
101
- });
102
- }
103
- }
104
- function parse(html) {
105
- const result = [];
106
- let current = void 0;
107
- let level = -1;
108
- const arr = [];
109
- const byTag = {};
110
- html.replace(tagRE, (tag, index) => {
111
- const isOpen = tag.charAt(1) !== "/";
112
- const isComment = tag.slice(0, 4) === "<!--";
113
- const start = index + tag.length;
114
- const nextChar = html.charAt(start);
115
- let parent = void 0;
116
- if (isOpen && !isComment) {
117
- level++;
118
- current = parseTag(tag);
119
- if (!current.voidElement && nextChar && nextChar !== "<") {
120
- pushTextNode(current.children, html, start);
121
- }
122
- byTag[current.tagName] = current;
123
- if (level === 0) {
124
- result.push(current);
125
- }
126
- parent = arr[level - 1];
127
- if (parent) {
128
- parent.children.push(current);
129
- }
130
- arr[level] = current;
131
- }
132
- if (isComment) {
133
- if (level < 0) {
134
- pushCommentNode(result, tag);
135
- } else {
136
- pushCommentNode(arr[level].children, tag);
137
- }
138
- }
139
- if (isComment || !isOpen || current.voidElement) {
140
- if (!isComment) {
141
- level--;
142
- }
143
- if (nextChar !== "<" && nextChar) {
144
- parent = level === -1 ? result : arr[level].children;
145
- pushTextNode(parent, html, start);
146
- }
147
- }
148
- });
149
- return result;
150
- }
151
- function attrString(attrs) {
152
- const buff = [];
153
- for (const attr of attrs) {
154
- buff.push(attr.name + '="' + attr.value.replace(/"/g, "&quot;") + '"');
155
- }
156
- if (!buff.length) {
157
- return "";
158
- }
159
- return " " + buff.join(" ");
160
- }
161
- function stringifier(buff, doc) {
162
- switch (doc.type) {
163
- case "text":
164
- return buff + doc.content;
165
- case "tag":
166
- buff +=
167
- "<" + doc.name + (doc.attrs ? attrString(doc.attrs) : "") + (doc.voidElement ? "/>" : ">");
168
- if (doc.voidElement) {
169
- return buff;
170
- }
171
- return buff + doc.children.reduce(stringifier, "") + "</" + doc.name + ">";
172
- case "comment":
173
- return (buff += "<!--" + doc.content + "-->");
174
- }
175
- }
176
- function stringify(doc) {
177
- return doc.reduce(function (token, rootEl) {
178
- return token + stringifier("", rootEl);
179
- }, "");
180
- }
181
- const cache = new Map();
182
- const VOID_ELEMENTS =
183
- /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
184
- const spaces = " \\f\\n\\r\\t";
185
- const almostEverything = "[^" + spaces + "\\/>\"'=]+";
186
- const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ")";
187
- const tagName = "<([A-Za-z$#]+[A-Za-z0-9:_-]*)((?:";
188
- const attrPartials =
189
- "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)";
190
- const attrSeeker = new RegExp(tagName + attrName + attrPartials + "+)([ " + spaces + "]*/?>)", "g");
191
- const findAttributes = new RegExp(
192
- "(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])",
193
- "gi"
194
- );
195
- const selfClosing = new RegExp(tagName + attrName + attrPartials + "*)([ " + spaces + "]*/>)", "g");
196
- const marker = "<!--#-->";
197
- const reservedNameSpaces = new Set(["class", "on", "oncapture", "style", "use", "prop", "attr"]);
198
- function attrReplacer($0, $1, $2, $3) {
199
- return "<" + $1 + $2.replace(findAttributes, replaceAttributes) + $3;
200
- }
201
- function replaceAttributes($0, $1, $2) {
202
- return (
203
- $1.replace(/<!--#-->/g, "###") +
204
- ($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"')
205
- );
206
- }
207
- function fullClosing($0, $1, $2) {
208
- return VOID_ELEMENTS.test($1) ? $0 : "<" + $1 + $2 + "></" + $1 + ">";
209
- }
210
- function toPropertyName(name) {
211
- return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
212
- }
213
- function parseDirective(name, value, tag, options) {
214
- if (name === "use:###" && value === "###") {
215
- const count = options.counter++;
216
- options.exprs.push(
217
- `typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()`
218
- );
219
- } else {
220
- throw new Error(`Not support syntax ${name} must be use:{function}`);
221
- }
222
- }
223
- function createHTML(
224
- r,
225
- { delegateEvents = true, functionBuilder = (...args) => new Function(...args) } = {}
226
- ) {
227
- let uuid = 1;
228
- r.wrapProps = props => {
229
- const d = Object.getOwnPropertyDescriptors(props);
230
- for (const k in d) {
231
- if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k);
232
- }
233
- return props;
234
- };
235
- function createTemplate(statics, opt) {
236
- let i = 0,
237
- markup = "";
238
- for (; i < statics.length - 1; i++) {
239
- markup = markup + statics[i] + "<!--#-->";
240
- }
241
- markup = markup + statics[i];
242
- const replaceList = [
243
- [selfClosing, fullClosing],
244
- [/<(<!--#-->)/g, "<###"],
245
- [/\.\.\.(<!--#-->)/g, "###"],
246
- [attrSeeker, attrReplacer],
247
- [/>\n+\s*/g, ">"],
248
- [/\n+\s*</g, "<"],
249
- [/\s+</g, " <"],
250
- [/>\s+/g, "> "]
251
- ];
252
- markup = replaceList.reduce((acc, x) => {
253
- return acc.replace(x[0], x[1]);
254
- }, markup);
255
- const pars = parse(markup);
256
- const [html, code] = parseTemplate(pars, opt.funcBuilder),
257
- templates = [];
258
- for (let i = 0; i < html.length; i++) {
259
- templates.push(document.createElement("template"));
260
- templates[i].innerHTML = html[i];
261
- const nomarkers = templates[i].content.querySelectorAll("script,style");
262
- for (let j = 0; j < nomarkers.length; j++) {
263
- const d = nomarkers[j].firstChild?.data || "";
264
- if (d.indexOf(marker) > -1) {
265
- const parts = d.split(marker).reduce((memo, p, i) => {
266
- i && memo.push("");
267
- memo.push(p);
268
- return memo;
269
- }, []);
270
- nomarkers[i].firstChild.replaceWith(...parts);
271
- }
272
- }
273
- }
274
- templates[0].create = code;
275
- cache.set(statics, templates);
276
- return templates;
277
- }
278
- function parseKeyValue(node, tag, name, value, isSVG, isCE, options) {
279
- let expr =
280
- value === "###"
281
- ? `!doNotWrap ? exprs[${options.counter}]() : exprs[${options.counter++}]`
282
- : value
283
- .split("###")
284
- .map((v, i) =>
285
- i
286
- ? ` + (typeof exprs[${options.counter}] === "function" ? exprs[${
287
- options.counter
288
- }]() : exprs[${options.counter++}]) + "${v}"`
289
- : `"${v}"`
290
- )
291
- .join(""),
292
- parts,
293
- namespace;
294
- if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
295
- name = parts[1];
296
- namespace = parts[0];
297
- }
298
- const isChildProp = r.ChildProperties.has(name);
299
- const isProp = r.Properties.has(name);
300
- if (name === "style") {
301
- const prev = `_$v${uuid++}`;
302
- options.decl.push(`${prev}={}`);
303
- options.exprs.push(`r.style(${tag},${expr},${prev})`);
304
- } else if (name === "classList") {
305
- const prev = `_$v${uuid++}`;
306
- options.decl.push(`${prev}={}`);
307
- options.exprs.push(`r.classList(${tag},${expr},${prev})`);
308
- } else if (
309
- namespace !== "attr" &&
310
- (isChildProp ||
311
- (!isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp)) ||
312
- isCE ||
313
- namespace === "prop")
314
- ) {
315
- if (isCE && !isChildProp && !isProp && namespace !== "prop") name = toPropertyName(name);
316
- options.exprs.push(
317
- `${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}`
318
- );
319
- } else {
320
- const ns = isSVG && name.indexOf(":") > -1 && r.SVGNamespace[name.split(":")[0]];
321
- if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`);
322
- else options.exprs.push(`r.setAttribute(${tag},"${r.Aliases[name] || name}",${expr})`);
323
- }
324
- }
325
- function parseAttribute(node, tag, name, value, isSVG, isCE, options) {
326
- if (name.slice(0, 2) === "on") {
327
- if (!name.includes(":")) {
328
- const lc = name.slice(2).toLowerCase();
329
- const delegate = delegateEvents && r.DelegatedEvents.has(lc);
330
- options.exprs.push(
331
- `r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})`
332
- );
333
- delegate && options.delegatedEvents.add(lc);
334
- } else {
335
- let capture = name.startsWith("oncapture:");
336
- options.exprs.push(
337
- `${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${
338
- capture ? ",true" : ""
339
- })`
340
- );
341
- }
342
- } else if (name === "ref") {
343
- options.exprs.push(`exprs[${options.counter++}](${tag})`);
344
- } else {
345
- const childOptions = Object.assign({}, options, {
346
- exprs: []
347
- }),
348
- count = options.counter;
349
- parseKeyValue(node, tag, name, value, isSVG, isCE, childOptions);
350
- options.decl.push(
351
- `_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join(
352
- ";\n"
353
- )};\n}`
354
- );
355
- if (value === "###") {
356
- options.exprs.push(
357
- `typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)`
358
- );
359
- } else {
360
- let check = "";
361
- for (let i = count; i < childOptions.counter; i++) {
362
- i !== count && (check += " || ");
363
- check += `typeof exprs[${i}] === "function"`;
364
- }
365
- options.exprs.push(check + ` ? r.effect(_fn${count}) : _fn${count}()`);
366
- }
367
- options.counter = childOptions.counter;
368
- options.wrap = false;
369
- }
370
- }
371
- function processChildren(node, options) {
372
- const childOptions = Object.assign({}, options, {
373
- first: true,
374
- multi: false,
375
- parent: options.path
376
- });
377
- if (node.children.length > 1) {
378
- for (let i = 0; i < node.children.length; i++) {
379
- const child = node.children[i];
380
- if (
381
- (child.type === "comment" && child.content === "#") ||
382
- (child.type === "tag" && child.name === "###")
383
- ) {
384
- childOptions.multi = true;
385
- break;
386
- }
387
- }
388
- }
389
- let i = 0;
390
- while (i < node.children.length) {
391
- const child = node.children[i];
392
- if (child.name === "###") {
393
- if (childOptions.multi) {
394
- node.children[i] = {
395
- type: "comment",
396
- content: "#"
397
- };
398
- i++;
399
- } else node.children.splice(i, 1);
400
- processComponent(child, childOptions);
401
- continue;
402
- }
403
- parseNode(child, childOptions);
404
- if (!childOptions.multi && child.type === "comment" && child.content === "#")
405
- node.children.splice(i, 1);
406
- else i++;
407
- }
408
- options.counter = childOptions.counter;
409
- options.templateId = childOptions.templateId;
410
- options.hasCustomElement = options.hasCustomElement || childOptions.hasCustomElement;
411
- options.isImportNode = options.isImportNode || childOptions.isImportNode;
412
- }
413
- function processComponentProps(propGroups) {
414
- let result = [];
415
- for (const props of propGroups) {
416
- if (Array.isArray(props)) {
417
- if (!props.length) continue;
418
- result.push(`r.wrapProps({${props.join(",") || ""}})`);
419
- } else result.push(props);
420
- }
421
- return result.length > 1 ? `r.mergeProps(${result.join(",")})` : result[0];
422
- }
423
- function processComponent(node, options) {
424
- let props = [];
425
- const keys = Object.keys(node.attrs),
426
- propGroups = [props],
427
- componentIdentifier = options.counter++;
428
- for (let i = 0; i < keys.length; i++) {
429
- const { type, name, value } = node.attrs[i];
430
- if (type === "attr") {
431
- if (name === "###") {
432
- propGroups.push(`exprs[${options.counter++}]`);
433
- propGroups.push((props = []));
434
- } else if (value === "###") {
435
- props.push(`${name}: exprs[${options.counter++}]`);
436
- } else props.push(`${name}: "${value}"`);
437
- } else if (type === "directive") {
438
- const tag = `_$el${uuid++}`;
439
- const topDecl = !options.decl.length;
440
- options.decl.push(
441
- topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
442
- );
443
- parseDirective(name, value, tag, options);
444
- }
445
- }
446
- if (
447
- node.children.length === 1 &&
448
- node.children[0].type === "comment" &&
449
- node.children[0].content === "#"
450
- ) {
451
- props.push(`children: () => exprs[${options.counter++}]`);
452
- } else if (node.children.length) {
453
- const children = {
454
- type: "fragment",
455
- children: node.children
456
- },
457
- childOptions = Object.assign({}, options, {
458
- first: true,
459
- decl: [],
460
- exprs: [],
461
- parent: false
462
- });
463
- parseNode(children, childOptions);
464
- props.push(`children: () => { ${childOptions.exprs.join(";\n")}}`);
465
- options.templateId = childOptions.templateId;
466
- options.counter = childOptions.counter;
467
- }
468
- let tag;
469
- if (options.multi) {
470
- tag = `_$el${uuid++}`;
471
- options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
472
- }
473
- if (options.parent)
474
- options.exprs.push(
475
- `r.insert(${
476
- options.parent
477
- }, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${
478
- tag ? `, ${tag}` : ""
479
- })`
480
- );
481
- else
482
- options.exprs.push(
483
- `${
484
- options.fragment ? "" : "return "
485
- }r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`
486
- );
487
- options.path = tag;
488
- options.first = false;
489
- }
490
- function parseNode(node, options) {
491
- if (node.type === "fragment") {
492
- const parts = [];
493
- node.children.forEach(child => {
494
- if (child.type === "tag") {
495
- if (child.name === "###") {
496
- const childOptions = Object.assign({}, options, {
497
- first: true,
498
- fragment: true,
499
- decl: [],
500
- exprs: []
501
- });
502
- processComponent(child, childOptions);
503
- parts.push(childOptions.exprs[0]);
504
- options.counter = childOptions.counter;
505
- options.templateId = childOptions.templateId;
506
- return;
507
- }
508
- options.templateId++;
509
- const id = uuid;
510
- const childOptions = Object.assign({}, options, {
511
- first: true,
512
- decl: [],
513
- exprs: []
514
- });
515
- options.templateNodes.push([child]);
516
- parseNode(child, childOptions);
517
- parts.push(
518
- `function() { ${
519
- childOptions.decl.join(",\n") +
520
- ";\n" +
521
- childOptions.exprs.join(";\n") +
522
- `;\nreturn _$el${id};\n`
523
- }}()`
524
- );
525
- options.counter = childOptions.counter;
526
- options.templateId = childOptions.templateId;
527
- } else if (child.type === "text") {
528
- parts.push(`"${child.content}"`);
529
- } else if (child.type === "comment") {
530
- if (child.content === "#") parts.push(`exprs[${options.counter++}]`);
531
- else if (child.content) {
532
- for (let i = 0; i < child.content.split("###").length - 1; i++) {
533
- parts.push(`exprs[${options.counter++}]`);
534
- }
535
- }
536
- }
537
- });
538
- options.exprs.push(`return [${parts.join(", \n")}]`);
539
- } else if (node.type === "tag") {
540
- const tag = `_$el${uuid++}`;
541
- const topDecl = !options.decl.length;
542
- const templateId = options.templateId;
543
- options.decl.push(
544
- topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
545
- );
546
- const isSVG = r.SVGElements.has(node.name);
547
- const isCE = node.name.includes("-") || node.attrs.some(e => e.name === "is");
548
- options.hasCustomElement = isCE;
549
- options.isImportNode =
550
- (node.name === "img" || node.name === "iframe") &&
551
- node.attrs.some(e => e.name === "loading" && e.value === "lazy");
552
- if (node.attrs.some(e => e.name === "###")) {
553
- const spreadArgs = [];
554
- let current = "";
555
- const newAttrs = [];
556
- for (let i = 0; i < node.attrs.length; i++) {
557
- const { type, name, value } = node.attrs[i];
558
- if (type === "attr") {
559
- if (value.includes("###")) {
560
- let count = options.counter++;
561
- current += `${name}: ${
562
- name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""
563
- }exprs[${count}],`;
564
- } else if (name === "###") {
565
- if (current.length) {
566
- spreadArgs.push(`()=>({${current}})`);
567
- current = "";
568
- }
569
- spreadArgs.push(`exprs[${options.counter++}]`);
570
- } else {
571
- newAttrs.push(node.attrs[i]);
572
- }
573
- } else if (type === "directive") {
574
- parseDirective(name, value, tag, options);
575
- }
576
- }
577
- node.attrs = newAttrs;
578
- if (current.length) {
579
- spreadArgs.push(`()=>({${current}})`);
580
- }
581
- options.exprs.push(
582
- `r.spread(${tag},${
583
- spreadArgs.length === 1
584
- ? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}`
585
- : `r.mergeProps(${spreadArgs.join(",")})`
586
- },${isSVG},${!!node.children.length})`
587
- );
588
- } else {
589
- for (let i = 0; i < node.attrs.length; i++) {
590
- const { type, name, value } = node.attrs[i];
591
- if (type === "directive") {
592
- parseDirective(name, value, tag, options);
593
- node.attrs.splice(i, 1);
594
- i--;
595
- } else if (type === "attr") {
596
- if (value.includes("###")) {
597
- node.attrs.splice(i, 1);
598
- i--;
599
- parseAttribute(node, tag, name, value, isSVG, isCE, options);
600
- }
601
- }
602
- }
603
- }
604
- options.path = tag;
605
- options.first = false;
606
- processChildren(node, options);
607
- if (topDecl) {
608
- options.decl[0] =
609
- options.hasCustomElement || options.isImportNode
610
- ? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))`
611
- : `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`;
612
- }
613
- } else if (node.type === "text") {
614
- const tag = `_$el${uuid++}`;
615
- options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
616
- options.path = tag;
617
- options.first = false;
618
- } else if (node.type === "comment") {
619
- const tag = `_$el${uuid++}`;
620
- options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
621
- if (node.content === "#") {
622
- if (options.multi) {
623
- options.exprs.push(`r.insert(${options.parent}, exprs[${options.counter++}], ${tag})`);
624
- } else options.exprs.push(`r.insert(${options.parent}, exprs[${options.counter++}])`);
625
- }
626
- options.path = tag;
627
- options.first = false;
628
- }
629
- }
630
- function parseTemplate(nodes, funcBuilder) {
631
- const options = {
632
- path: "",
633
- decl: [],
634
- exprs: [],
635
- delegatedEvents: new Set(),
636
- counter: 0,
637
- first: true,
638
- multi: false,
639
- templateId: 0,
640
- templateNodes: []
641
- },
642
- id = uuid,
643
- origNodes = nodes;
644
- let toplevel;
645
- if (nodes.length > 1) {
646
- nodes = [
647
- {
648
- type: "fragment",
649
- children: nodes
650
- }
651
- ];
652
- }
653
- if (nodes[0].name === "###") {
654
- toplevel = true;
655
- processComponent(nodes[0], options);
656
- } else parseNode(nodes[0], options);
657
- r.delegateEvents(Array.from(options.delegatedEvents));
658
- const templateNodes = [origNodes].concat(options.templateNodes);
659
- return [
660
- templateNodes.map(t => stringify(t)),
661
- funcBuilder(
662
- "tmpls",
663
- "exprs",
664
- "r",
665
- options.decl.join(",\n") +
666
- ";\n" +
667
- options.exprs.join(";\n") +
668
- (toplevel ? "" : `;\nreturn _$el${id};\n`)
669
- )
670
- ];
671
- }
672
- function html(statics, ...args) {
673
- const templates =
674
- cache.get(statics) ||
675
- createTemplate(statics, {
676
- funcBuilder: functionBuilder
677
- });
678
- return templates[0].create(templates, args, r);
679
- }
680
- return html;
681
- }
682
-
683
- const html = createHTML({
684
- effect,
685
- style,
686
- insert,
687
- untrack,
688
- spread,
689
- createComponent,
690
- delegateEvents,
691
- classList,
692
- mergeProps,
693
- dynamicProperty,
694
- setAttribute,
695
- setAttributeNS,
696
- addEventListener,
697
- Aliases,
698
- getPropAlias,
699
- Properties,
700
- ChildProperties,
701
- DelegatedEvents,
702
- SVGElements,
703
- SVGNamespace
704
- });
705
-
706
- export { html as default };
package/html/package.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "name": "solid-js/html",
3
- "main": "./dist/html.cjs",
4
- "module": "./dist/html.js",
5
- "types": "./types/index.d.ts",
6
- "type": "module",
7
- "sideEffects": false
8
- }