solid-js 1.9.2 → 1.9.3

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 (46) hide show
  1. package/dist/dev.js +559 -318
  2. package/dist/server.js +168 -74
  3. package/dist/solid.js +486 -276
  4. package/h/dist/h.js +40 -9
  5. package/h/jsx-runtime/dist/jsx.js +1 -1
  6. package/h/jsx-runtime/types/index.d.ts +11 -8
  7. package/h/jsx-runtime/types/jsx.d.ts +93 -91
  8. package/h/types/hyperscript.d.ts +11 -11
  9. package/html/dist/html.js +219 -94
  10. package/html/types/lit.d.ts +52 -33
  11. package/package.json +1 -1
  12. package/store/dist/dev.js +123 -43
  13. package/store/dist/server.js +20 -8
  14. package/store/dist/store.js +114 -40
  15. package/store/types/index.d.ts +21 -7
  16. package/store/types/modifiers.d.ts +6 -3
  17. package/store/types/mutable.d.ts +5 -2
  18. package/store/types/server.d.ts +25 -5
  19. package/store/types/store.d.ts +218 -61
  20. package/types/index.d.ts +75 -10
  21. package/types/jsx.d.ts +143 -157
  22. package/types/reactive/array.d.ts +12 -4
  23. package/types/reactive/observable.d.ts +25 -17
  24. package/types/reactive/scheduler.d.ts +9 -6
  25. package/types/reactive/signal.d.ts +233 -142
  26. package/types/render/Suspense.d.ts +5 -5
  27. package/types/render/component.d.ts +71 -35
  28. package/types/render/flow.d.ts +43 -31
  29. package/types/render/hydration.d.ts +15 -15
  30. package/types/server/index.d.ts +57 -2
  31. package/types/server/reactive.d.ts +73 -42
  32. package/types/server/rendering.d.ts +169 -98
  33. package/universal/dist/dev.js +28 -12
  34. package/universal/dist/universal.js +28 -12
  35. package/universal/types/index.d.ts +3 -1
  36. package/universal/types/universal.d.ts +0 -1
  37. package/web/dist/dev.js +639 -89
  38. package/web/dist/server.cjs +13 -10
  39. package/web/dist/server.js +653 -118
  40. package/web/dist/web.js +627 -87
  41. package/web/storage/dist/storage.js +3 -3
  42. package/web/types/client.d.ts +1 -1
  43. package/web/types/core.d.ts +10 -1
  44. package/web/types/index.d.ts +27 -10
  45. package/web/types/server-mock.d.ts +47 -32
  46. package/web/types/server.d.ts +1 -1
package/html/dist/html.js CHANGED
@@ -1,7 +1,29 @@
1
- import { effect, style, insert, untrack, spread, createComponent, delegateEvents, classList, mergeProps, dynamicProperty, setAttribute, setAttributeNS, addEventListener, Aliases, getPropAlias, Properties, ChildProperties, DelegatedEvents, SVGElements, SVGNamespace } from 'solid-js/web';
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";
2
23
 
3
24
  const tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
4
- const attrRE = /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g;
25
+ const attrRE =
26
+ /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g;
5
27
  const lookup = {
6
28
  area: true,
7
29
  base: true,
@@ -22,8 +44,8 @@ const lookup = {
22
44
  };
23
45
  function parseTag(tag) {
24
46
  const res = {
25
- type: 'tag',
26
- name: '',
47
+ type: "tag",
48
+ name: "",
27
49
  voidElement: false,
28
50
  attrs: [],
29
51
  children: []
@@ -31,50 +53,50 @@ function parseTag(tag) {
31
53
  const tagMatch = tag.match(/<\/?([^\s]+?)[/\s>]/);
32
54
  if (tagMatch) {
33
55
  res.name = tagMatch[1];
34
- if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === '/') {
56
+ if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === "/") {
35
57
  res.voidElement = true;
36
58
  }
37
- if (res.name.startsWith('!--')) {
38
- const endIndex = tag.indexOf('-->');
59
+ if (res.name.startsWith("!--")) {
60
+ const endIndex = tag.indexOf("-->");
39
61
  return {
40
- type: 'comment',
41
- comment: endIndex !== -1 ? tag.slice(4, endIndex) : ''
62
+ type: "comment",
63
+ comment: endIndex !== -1 ? tag.slice(4, endIndex) : ""
42
64
  };
43
65
  }
44
66
  }
45
67
  const reg = new RegExp(attrRE);
46
68
  for (const match of tag.matchAll(reg)) {
47
- if ((match[1] || match[2]).startsWith('use:')) {
69
+ if ((match[1] || match[2]).startsWith("use:")) {
48
70
  res.attrs.push({
49
- type: 'directive',
71
+ type: "directive",
50
72
  name: match[1] || match[2],
51
- value: match[4] || match[5] || ''
73
+ value: match[4] || match[5] || ""
52
74
  });
53
75
  } else {
54
76
  res.attrs.push({
55
- type: 'attr',
77
+ type: "attr",
56
78
  name: match[1] || match[2],
57
- value: match[4] || match[5] || ''
79
+ value: match[4] || match[5] || ""
58
80
  });
59
81
  }
60
82
  }
61
83
  return res;
62
84
  }
63
85
  function pushTextNode(list, html, start) {
64
- const end = html.indexOf('<', start);
86
+ const end = html.indexOf("<", start);
65
87
  const content = html.slice(start, end === -1 ? void 0 : end);
66
88
  if (!/^\s*$/.test(content)) {
67
89
  list.push({
68
- type: 'text',
90
+ type: "text",
69
91
  content: content
70
92
  });
71
93
  }
72
94
  }
73
95
  function pushCommentNode(list, tag) {
74
- const content = tag.replace('<!--', '').replace('-->', '');
96
+ const content = tag.replace("<!--", "").replace("-->", "");
75
97
  if (!/^\s*$/.test(content)) {
76
98
  list.push({
77
- type: 'comment',
99
+ type: "comment",
78
100
  content: content
79
101
  });
80
102
  }
@@ -86,15 +108,15 @@ function parse(html) {
86
108
  const arr = [];
87
109
  const byTag = {};
88
110
  html.replace(tagRE, (tag, index) => {
89
- const isOpen = tag.charAt(1) !== '/';
90
- const isComment = tag.slice(0, 4) === '<!--';
111
+ const isOpen = tag.charAt(1) !== "/";
112
+ const isComment = tag.slice(0, 4) === "<!--";
91
113
  const start = index + tag.length;
92
114
  const nextChar = html.charAt(start);
93
115
  let parent = void 0;
94
116
  if (isOpen && !isComment) {
95
117
  level++;
96
118
  current = parseTag(tag);
97
- if (!current.voidElement && nextChar && nextChar !== '<') {
119
+ if (!current.voidElement && nextChar && nextChar !== "<") {
98
120
  pushTextNode(current.children, html, start);
99
121
  }
100
122
  byTag[current.tagName] = current;
@@ -118,7 +140,7 @@ function parse(html) {
118
140
  if (!isComment) {
119
141
  level--;
120
142
  }
121
- if (nextChar !== '<' && nextChar) {
143
+ if (nextChar !== "<" && nextChar) {
122
144
  parent = level === -1 ? result : arr[level].children;
123
145
  pushTextNode(parent, html, start);
124
146
  }
@@ -129,41 +151,47 @@ function parse(html) {
129
151
  function attrString(attrs) {
130
152
  const buff = [];
131
153
  for (const attr of attrs) {
132
- buff.push(attr.name + '="' + attr.value.replace(/"/g, '&quot;') + '"');
154
+ buff.push(attr.name + '="' + attr.value.replace(/"/g, "&quot;") + '"');
133
155
  }
134
156
  if (!buff.length) {
135
- return '';
157
+ return "";
136
158
  }
137
- return ' ' + buff.join(' ');
159
+ return " " + buff.join(" ");
138
160
  }
139
161
  function stringifier(buff, doc) {
140
162
  switch (doc.type) {
141
- case 'text':
163
+ case "text":
142
164
  return buff + doc.content;
143
- case 'tag':
144
- buff += '<' + doc.name + (doc.attrs ? attrString(doc.attrs) : '') + (doc.voidElement ? '/>' : '>');
165
+ case "tag":
166
+ buff +=
167
+ "<" + doc.name + (doc.attrs ? attrString(doc.attrs) : "") + (doc.voidElement ? "/>" : ">");
145
168
  if (doc.voidElement) {
146
169
  return buff;
147
170
  }
148
- return buff + doc.children.reduce(stringifier, '') + '</' + doc.name + '>';
149
- case 'comment':
150
- return buff += '<!--' + doc.content + '-->';
171
+ return buff + doc.children.reduce(stringifier, "") + "</" + doc.name + ">";
172
+ case "comment":
173
+ return (buff += "<!--" + doc.content + "-->");
151
174
  }
152
175
  }
153
176
  function stringify(doc) {
154
177
  return doc.reduce(function (token, rootEl) {
155
- return token + stringifier('', rootEl);
156
- }, '');
178
+ return token + stringifier("", rootEl);
179
+ }, "");
157
180
  }
158
181
  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;
182
+ const VOID_ELEMENTS =
183
+ /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
160
184
  const spaces = " \\f\\n\\r\\t";
161
185
  const almostEverything = "[^" + spaces + "\\/>\"'=]+";
162
- const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ')';
186
+ const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ")";
163
187
  const tagName = "<([A-Za-z$#]+[A-Za-z0-9:_-]*)((?:";
164
- const attrPartials = "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)";
188
+ const attrPartials =
189
+ "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)";
165
190
  const attrSeeker = new RegExp(tagName + attrName + attrPartials + "+)([ " + spaces + "]*/?>)", "g");
166
- const findAttributes = new RegExp("(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])", "gi");
191
+ const findAttributes = new RegExp(
192
+ "(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])",
193
+ "gi"
194
+ );
167
195
  const selfClosing = new RegExp(tagName + attrName + attrPartials + "*)([ " + spaces + "]*/>)", "g");
168
196
  const marker = "<!--#-->";
169
197
  const reservedNameSpaces = new Set(["class", "on", "oncapture", "style", "use", "prop", "attr"]);
@@ -171,7 +199,10 @@ function attrReplacer($0, $1, $2, $3) {
171
199
  return "<" + $1 + $2.replace(findAttributes, replaceAttributes) + $3;
172
200
  }
173
201
  function replaceAttributes($0, $1, $2) {
174
- return $1.replace(/<!--#-->/g, "###") + ($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"');
202
+ return (
203
+ $1.replace(/<!--#-->/g, "###") +
204
+ ($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"')
205
+ );
175
206
  }
176
207
  function fullClosing($0, $1, $2) {
177
208
  return VOID_ELEMENTS.test($1) ? $0 : "<" + $1 + $2 + "></" + $1 + ">";
@@ -180,17 +211,19 @@ function toPropertyName(name) {
180
211
  return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
181
212
  }
182
213
  function parseDirective(name, value, tag, options) {
183
- if (name === 'use:###' && value === '###') {
214
+ if (name === "use:###" && value === "###") {
184
215
  const count = options.counter++;
185
- options.exprs.push(`typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()`);
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
+ );
186
219
  } else {
187
220
  throw new Error(`Not support syntax ${name} must be use:{function}`);
188
221
  }
189
222
  }
190
- function createHTML(r, {
191
- delegateEvents = true,
192
- functionBuilder = (...args) => new Function(...args)
193
- } = {}) {
223
+ function createHTML(
224
+ r,
225
+ { delegateEvents = true, functionBuilder = (...args) => new Function(...args) } = {}
226
+ ) {
194
227
  let uuid = 1;
195
228
  r.wrapProps = props => {
196
229
  const d = Object.getOwnPropertyDescriptors(props);
@@ -206,7 +239,16 @@ function createHTML(r, {
206
239
  markup = markup + statics[i] + "<!--#-->";
207
240
  }
208
241
  markup = markup + statics[i];
209
- const replaceList = [[selfClosing, fullClosing], [/<(<!--#-->)/g, "<###"], [/\.\.\.(<!--#-->)/g, "###"], [attrSeeker, attrReplacer], [/>\n+\s*/g, ">"], [/\n+\s*</g, "<"], [/\s+</g, " <"], [/>\s+/g, "> "]];
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
+ ];
210
252
  markup = replaceList.reduce((acc, x) => {
211
253
  return acc.replace(x[0], x[1]);
212
254
  }, markup);
@@ -234,7 +276,19 @@ function createHTML(r, {
234
276
  return templates;
235
277
  }
236
278
  function parseKeyValue(node, tag, name, value, isSVG, isCE, options) {
237
- let expr = value === "###" ? `!doNotWrap ? exprs[${options.counter}]() : exprs[${options.counter++}]` : value.split("###").map((v, i) => i ? ` + (typeof exprs[${options.counter}] === "function" ? exprs[${options.counter}]() : exprs[${options.counter++}]) + "${v}"` : `"${v}"`).join(""),
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(""),
238
292
  parts,
239
293
  namespace;
240
294
  if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
@@ -251,12 +305,21 @@ function createHTML(r, {
251
305
  const prev = `_$v${uuid++}`;
252
306
  options.decl.push(`${prev}={}`);
253
307
  options.exprs.push(`r.classList(${tag},${expr},${prev})`);
254
- } else if (namespace !== "attr" && (isChildProp || !isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp) || isCE || namespace === "prop")) {
308
+ } else if (
309
+ namespace !== "attr" &&
310
+ (isChildProp ||
311
+ (!isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp)) ||
312
+ isCE ||
313
+ namespace === "prop")
314
+ ) {
255
315
  if (isCE && !isChildProp && !isProp && namespace !== "prop") name = toPropertyName(name);
256
- options.exprs.push(`${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}`);
316
+ options.exprs.push(
317
+ `${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}`
318
+ );
257
319
  } else {
258
320
  const ns = isSVG && name.indexOf(":") > -1 && r.SVGNamespace[name.split(":")[0]];
259
- if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`);else options.exprs.push(`r.setAttribute(${tag},"${r.Aliases[name] || name}",${expr})`);
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})`);
260
323
  }
261
324
  }
262
325
  function parseAttribute(node, tag, name, value, isSVG, isCE, options) {
@@ -264,11 +327,17 @@ function createHTML(r, {
264
327
  if (!name.includes(":")) {
265
328
  const lc = name.slice(2).toLowerCase();
266
329
  const delegate = delegateEvents && r.DelegatedEvents.has(lc);
267
- options.exprs.push(`r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})`);
330
+ options.exprs.push(
331
+ `r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})`
332
+ );
268
333
  delegate && options.delegatedEvents.add(lc);
269
334
  } else {
270
335
  let capture = name.startsWith("oncapture:");
271
- options.exprs.push(`${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${capture ? ",true" : ""})`);
336
+ options.exprs.push(
337
+ `${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${
338
+ capture ? ",true" : ""
339
+ })`
340
+ );
272
341
  }
273
342
  } else if (name === "ref") {
274
343
  options.exprs.push(`exprs[${options.counter++}](${tag})`);
@@ -278,9 +347,15 @@ function createHTML(r, {
278
347
  }),
279
348
  count = options.counter;
280
349
  parseKeyValue(node, tag, name, value, isSVG, isCE, childOptions);
281
- options.decl.push(`_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join(";\n")};\n}`);
350
+ options.decl.push(
351
+ `_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join(
352
+ ";\n"
353
+ )};\n}`
354
+ );
282
355
  if (value === "###") {
283
- options.exprs.push(`typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)`);
356
+ options.exprs.push(
357
+ `typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)`
358
+ );
284
359
  } else {
285
360
  let check = "";
286
361
  for (let i = count; i < childOptions.counter; i++) {
@@ -302,7 +377,10 @@ function createHTML(r, {
302
377
  if (node.children.length > 1) {
303
378
  for (let i = 0; i < node.children.length; i++) {
304
379
  const child = node.children[i];
305
- if (child.type === "comment" && child.content === "#" || child.type === "tag" && child.name === "###") {
380
+ if (
381
+ (child.type === "comment" && child.content === "#") ||
382
+ (child.type === "tag" && child.name === "###")
383
+ ) {
306
384
  childOptions.multi = true;
307
385
  break;
308
386
  }
@@ -323,7 +401,9 @@ function createHTML(r, {
323
401
  continue;
324
402
  }
325
403
  parseNode(child, childOptions);
326
- if (!childOptions.multi && child.type === "comment" && child.content === "#") node.children.splice(i, 1);else i++;
404
+ if (!childOptions.multi && child.type === "comment" && child.content === "#")
405
+ node.children.splice(i, 1);
406
+ else i++;
327
407
  }
328
408
  options.counter = childOptions.counter;
329
409
  options.templateId = childOptions.templateId;
@@ -346,26 +426,28 @@ function createHTML(r, {
346
426
  propGroups = [props],
347
427
  componentIdentifier = options.counter++;
348
428
  for (let i = 0; i < keys.length; i++) {
349
- const {
350
- type,
351
- name,
352
- value
353
- } = node.attrs[i];
354
- if (type === 'attr') {
429
+ const { type, name, value } = node.attrs[i];
430
+ if (type === "attr") {
355
431
  if (name === "###") {
356
432
  propGroups.push(`exprs[${options.counter++}]`);
357
- propGroups.push(props = []);
433
+ propGroups.push((props = []));
358
434
  } else if (value === "###") {
359
435
  props.push(`${name}: exprs[${options.counter++}]`);
360
436
  } else props.push(`${name}: "${value}"`);
361
- } else if (type === 'directive') {
437
+ } else if (type === "directive") {
362
438
  const tag = `_$el${uuid++}`;
363
439
  const topDecl = !options.decl.length;
364
- options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
440
+ options.decl.push(
441
+ topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
442
+ );
365
443
  parseDirective(name, value, tag, options);
366
444
  }
367
445
  }
368
- if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
446
+ if (
447
+ node.children.length === 1 &&
448
+ node.children[0].type === "comment" &&
449
+ node.children[0].content === "#"
450
+ ) {
369
451
  props.push(`children: () => exprs[${options.counter++}]`);
370
452
  } else if (node.children.length) {
371
453
  const children = {
@@ -388,7 +470,20 @@ function createHTML(r, {
388
470
  tag = `_$el${uuid++}`;
389
471
  options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
390
472
  }
391
- 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)})`);
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
+ );
392
487
  options.path = tag;
393
488
  options.first = false;
394
489
  }
@@ -419,13 +514,21 @@ function createHTML(r, {
419
514
  });
420
515
  options.templateNodes.push([child]);
421
516
  parseNode(child, childOptions);
422
- parts.push(`function() { ${childOptions.decl.join(",\n") + ";\n" + childOptions.exprs.join(";\n") + `;\nreturn _$el${id};\n`}}()`);
517
+ parts.push(
518
+ `function() { ${
519
+ childOptions.decl.join(",\n") +
520
+ ";\n" +
521
+ childOptions.exprs.join(";\n") +
522
+ `;\nreturn _$el${id};\n`
523
+ }}()`
524
+ );
423
525
  options.counter = childOptions.counter;
424
526
  options.templateId = childOptions.templateId;
425
527
  } else if (child.type === "text") {
426
528
  parts.push(`"${child.content}"`);
427
529
  } else if (child.type === "comment") {
428
- if (child.content === "#") parts.push(`exprs[${options.counter++}]`);else if (child.content) {
530
+ if (child.content === "#") parts.push(`exprs[${options.counter++}]`);
531
+ else if (child.content) {
429
532
  for (let i = 0; i < child.content.split("###").length - 1; i++) {
430
533
  parts.push(`exprs[${options.counter++}]`);
431
534
  }
@@ -437,25 +540,27 @@ function createHTML(r, {
437
540
  const tag = `_$el${uuid++}`;
438
541
  const topDecl = !options.decl.length;
439
542
  const templateId = options.templateId;
440
- options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
543
+ options.decl.push(
544
+ topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
545
+ );
441
546
  const isSVG = r.SVGElements.has(node.name);
442
547
  const isCE = node.name.includes("-") || node.attrs.some(e => e.name === "is");
443
548
  options.hasCustomElement = isCE;
444
- options.isImportNode = (node.name === 'img' || node.name === 'iframe') && node.attrs.some(e => e.name === "loading" && e.value === 'lazy');
549
+ options.isImportNode =
550
+ (node.name === "img" || node.name === "iframe") &&
551
+ node.attrs.some(e => e.name === "loading" && e.value === "lazy");
445
552
  if (node.attrs.some(e => e.name === "###")) {
446
553
  const spreadArgs = [];
447
554
  let current = "";
448
555
  const newAttrs = [];
449
556
  for (let i = 0; i < node.attrs.length; i++) {
450
- const {
451
- type,
452
- name,
453
- value
454
- } = node.attrs[i];
455
- if (type === 'attr') {
557
+ const { type, name, value } = node.attrs[i];
558
+ if (type === "attr") {
456
559
  if (value.includes("###")) {
457
560
  let count = options.counter++;
458
- current += `${name}: ${name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""}exprs[${count}],`;
561
+ current += `${name}: ${
562
+ name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""
563
+ }exprs[${count}],`;
459
564
  } else if (name === "###") {
460
565
  if (current.length) {
461
566
  spreadArgs.push(`()=>({${current}})`);
@@ -465,7 +570,7 @@ function createHTML(r, {
465
570
  } else {
466
571
  newAttrs.push(node.attrs[i]);
467
572
  }
468
- } else if (type === 'directive') {
573
+ } else if (type === "directive") {
469
574
  parseDirective(name, value, tag, options);
470
575
  }
471
576
  }
@@ -473,15 +578,17 @@ function createHTML(r, {
473
578
  if (current.length) {
474
579
  spreadArgs.push(`()=>({${current}})`);
475
580
  }
476
- 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})`);
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
+ );
477
588
  } else {
478
589
  for (let i = 0; i < node.attrs.length; i++) {
479
- const {
480
- type,
481
- name,
482
- value
483
- } = node.attrs[i];
484
- if (type === 'directive') {
590
+ const { type, name, value } = node.attrs[i];
591
+ if (type === "directive") {
485
592
  parseDirective(name, value, tag, options);
486
593
  node.attrs.splice(i, 1);
487
594
  i--;
@@ -498,7 +605,10 @@ function createHTML(r, {
498
605
  options.first = false;
499
606
  processChildren(node, options);
500
607
  if (topDecl) {
501
- 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)`;
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)`;
502
612
  }
503
613
  } else if (node.type === "text") {
504
614
  const tag = `_$el${uuid++}`;
@@ -533,10 +643,12 @@ function createHTML(r, {
533
643
  origNodes = nodes;
534
644
  let toplevel;
535
645
  if (nodes.length > 1) {
536
- nodes = [{
537
- type: "fragment",
538
- children: nodes
539
- }];
646
+ nodes = [
647
+ {
648
+ type: "fragment",
649
+ children: nodes
650
+ }
651
+ ];
540
652
  }
541
653
  if (nodes[0].name === "###") {
542
654
  toplevel = true;
@@ -544,12 +656,25 @@ function createHTML(r, {
544
656
  } else parseNode(nodes[0], options);
545
657
  r.delegateEvents(Array.from(options.delegatedEvents));
546
658
  const templateNodes = [origNodes].concat(options.templateNodes);
547
- return [templateNodes.map(t => stringify(t)), funcBuilder("tmpls", "exprs", "r", options.decl.join(",\n") + ";\n" + options.exprs.join(";\n") + (toplevel ? "" : `;\nreturn _$el${id};\n`))];
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
+ ];
548
671
  }
549
672
  function html(statics, ...args) {
550
- const templates = cache.get(statics) || createTemplate(statics, {
551
- funcBuilder: functionBuilder
552
- });
673
+ const templates =
674
+ cache.get(statics) ||
675
+ createTemplate(statics, {
676
+ funcBuilder: functionBuilder
677
+ });
553
678
  return templates[0].create(templates, args, r);
554
679
  }
555
680
  return html;
@@ -1,41 +1,60 @@
1
1
  type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
2
2
  interface Runtime {
3
- effect<T>(fn: (prev?: T) => T, init?: T): any;
4
- untrack<T>(fn: () => T): T;
5
- insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any;
6
- spread<T>(node: Element, accessor: (() => T) | T, isSVG?: Boolean, skipChildren?: Boolean): void;
7
- createComponent(Comp: (props: any) => any, props: any): any;
8
- addEventListener(node: Element, name: string, handler: EventListener | EventListenerObject | (EventListenerObject & AddEventListenerOptions), delegate: boolean): void;
9
- delegateEvents(eventNames: string[]): void;
10
- classList(node: Element, value: {
11
- [k: string]: boolean;
12
- }, prev?: {
13
- [k: string]: boolean;
14
- }): {
15
- [k: string]: boolean;
16
- };
17
- style(node: Element, value: {
18
- [k: string]: string;
19
- }, prev?: {
20
- [k: string]: string;
21
- }): void;
22
- mergeProps(...sources: unknown[]): unknown;
23
- dynamicProperty(props: any, key: string): any;
24
- setAttribute(node: Element, name: string, value: any): void;
25
- setAttributeNS(node: Element, namespace: string, name: string, value: any): void;
26
- Aliases: Record<string, string>;
27
- getPropAlias(prop: string, tagName: string): string | undefined;
28
- Properties: Set<string>;
29
- ChildProperties: Set<string>;
30
- DelegatedEvents: Set<string>;
31
- SVGElements: Set<string>;
32
- SVGNamespace: Record<string, string>;
3
+ effect<T>(fn: (prev?: T) => T, init?: T): any;
4
+ untrack<T>(fn: () => T): T;
5
+ insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any;
6
+ spread<T>(node: Element, accessor: (() => T) | T, isSVG?: Boolean, skipChildren?: Boolean): void;
7
+ createComponent(Comp: (props: any) => any, props: any): any;
8
+ addEventListener(
9
+ node: Element,
10
+ name: string,
11
+ handler: EventListener | EventListenerObject | (EventListenerObject & AddEventListenerOptions),
12
+ delegate: boolean
13
+ ): void;
14
+ delegateEvents(eventNames: string[]): void;
15
+ classList(
16
+ node: Element,
17
+ value: {
18
+ [k: string]: boolean;
19
+ },
20
+ prev?: {
21
+ [k: string]: boolean;
22
+ }
23
+ ): {
24
+ [k: string]: boolean;
25
+ };
26
+ style(
27
+ node: Element,
28
+ value: {
29
+ [k: string]: string;
30
+ },
31
+ prev?: {
32
+ [k: string]: string;
33
+ }
34
+ ): void;
35
+ mergeProps(...sources: unknown[]): unknown;
36
+ dynamicProperty(props: any, key: string): any;
37
+ setAttribute(node: Element, name: string, value: any): void;
38
+ setAttributeNS(node: Element, namespace: string, name: string, value: any): void;
39
+ Aliases: Record<string, string>;
40
+ getPropAlias(prop: string, tagName: string): string | undefined;
41
+ Properties: Set<string>;
42
+ ChildProperties: Set<string>;
43
+ DelegatedEvents: Set<string>;
44
+ SVGElements: Set<string>;
45
+ SVGNamespace: Record<string, string>;
33
46
  }
34
47
  export type HTMLTag = {
35
- (statics: TemplateStringsArray, ...args: unknown[]): Node | Node[];
48
+ (statics: TemplateStringsArray, ...args: unknown[]): Node | Node[];
36
49
  };
37
- export declare function createHTML(r: Runtime, { delegateEvents, functionBuilder }?: {
50
+ export declare function createHTML(
51
+ r: Runtime,
52
+ {
53
+ delegateEvents,
54
+ functionBuilder
55
+ }?: {
38
56
  delegateEvents?: boolean;
39
57
  functionBuilder?: (...args: string[]) => Function;
40
- }): HTMLTag;
58
+ }
59
+ ): HTMLTag;
41
60
  export {};