@b9g/crank 0.6.1 → 0.7.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.
package/dom.js CHANGED
@@ -1,11 +1,52 @@
1
1
  /// <reference types="dom.d.ts" />
2
2
  import { Renderer, Portal } from './crank.js';
3
+ import './event-target.js';
3
4
 
4
5
  const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
5
- const impl = {
6
- scope(xmlns, tag, props) {
6
+ function isWritableProperty(element, name) {
7
+ // walk up the object's prototype chain to find the owner
8
+ let propOwner = element;
9
+ do {
10
+ if (Object.prototype.hasOwnProperty.call(propOwner, name)) {
11
+ break;
12
+ }
13
+ } while ((propOwner = Object.getPrototypeOf(propOwner)));
14
+ if (propOwner === null) {
15
+ return false;
16
+ }
17
+ // get the descriptor for the named property and check whether it implies
18
+ // that the property is writable
19
+ const descriptor = Object.getOwnPropertyDescriptor(propOwner, name);
20
+ if (descriptor != null &&
21
+ (descriptor.writable === true || descriptor.set !== undefined)) {
22
+ return true;
23
+ }
24
+ return false;
25
+ }
26
+ function emitHydrationWarning(propName, quietProps, expectedValue, actualValue, element, displayName) {
27
+ const checkName = propName;
28
+ const showName = displayName || propName;
29
+ if (!quietProps || !quietProps.has(checkName)) {
30
+ if (expectedValue === null || expectedValue === false) {
31
+ console.warn(`Expected "${showName}" to be missing but found ${String(actualValue)} while hydrating:`, element);
32
+ }
33
+ else if (expectedValue === true || expectedValue === "") {
34
+ console.warn(`Expected "${showName}" to be ${expectedValue === true ? "present" : '""'} but found ${String(actualValue)} while hydrating:`, element);
35
+ }
36
+ else if (typeof window !== "undefined" &&
37
+ window.location &&
38
+ new URL(expectedValue, window.location.origin).href ===
39
+ new URL(actualValue, window.location.origin).href) ;
40
+ else {
41
+ console.warn(`Expected "${showName}" to be "${String(expectedValue)}" but found ${String(actualValue)} while hydrating:`, element);
42
+ }
43
+ }
44
+ }
45
+ const adapter = {
46
+ scope({ scope: xmlns, tag, props, }) {
7
47
  switch (tag) {
8
48
  case Portal:
49
+ // TODO: read the namespace from the portal root element
9
50
  xmlns = undefined;
10
51
  break;
11
52
  case "svg":
@@ -14,9 +55,9 @@ const impl = {
14
55
  }
15
56
  return props.xmlns || xmlns;
16
57
  },
17
- create(tag, _props, xmlns) {
58
+ create({ tag, tagName, scope: xmlns, }) {
18
59
  if (typeof tag !== "string") {
19
- throw new Error(`Unknown tag: ${tag.toString()}`);
60
+ throw new Error(`Unknown tag: ${tagName}`);
20
61
  }
21
62
  else if (tag.toLowerCase() === "svg") {
22
63
  xmlns = SVG_NAMESPACE;
@@ -25,286 +66,362 @@ const impl = {
25
66
  ? document.createElementNS(xmlns, tag)
26
67
  : document.createElement(tag);
27
68
  },
28
- hydrate(tag, node, props) {
69
+ adopt({ tag, tagName, node, }) {
29
70
  if (typeof tag !== "string" && tag !== Portal) {
30
- throw new Error(`Unknown tag: ${tag.toString()}`);
71
+ throw new Error(`Unknown tag: ${tagName}`);
31
72
  }
32
- if (typeof tag === "string" &&
33
- tag.toUpperCase() !== node.tagName) {
34
- // TODO: consider pros and cons of hydration warnings
35
- //console.error(`Expected <${tag}> while hydrating but found:`, node);
36
- return undefined;
73
+ if (node === document.body ||
74
+ node === document.head ||
75
+ node === document.documentElement ||
76
+ node === document) {
77
+ console.warn(`Hydrating ${node.nodeName.toLowerCase()} is discouraged as it is destructive and may remove unknown nodes.`);
37
78
  }
38
- const children = [];
39
- for (let i = 0; i < node.childNodes.length; i++) {
40
- const child = node.childNodes[i];
41
- if (child.nodeType === Node.TEXT_NODE) {
42
- children.push(child.data);
43
- }
44
- else if (child.nodeType === Node.ELEMENT_NODE) {
45
- children.push(child);
46
- }
79
+ if (node == null ||
80
+ (typeof tag === "string" &&
81
+ (node.nodeType !== Node.ELEMENT_NODE ||
82
+ tag.toLowerCase() !== node.tagName.toLowerCase()))) {
83
+ console.warn(`Expected <${tagName}> while hydrating but found: `, node);
84
+ return;
47
85
  }
48
- // TODO: extract props from nodes
49
- return { props, children };
86
+ return Array.from(node.childNodes);
50
87
  },
51
- patch(_tag,
52
- // TODO: Why does this assignment work?
53
- node, name,
54
- // TODO: Stricter typings?
55
- value, oldValue, xmlns) {
88
+ patch({ tagName, node, props, oldProps, scope: xmlns, copyProps, quietProps, isHydrating, }) {
89
+ if (node.nodeType !== Node.ELEMENT_NODE) {
90
+ throw new TypeError(`Cannot patch node: ${String(node)}`);
91
+ }
92
+ else if (props.class && props.className) {
93
+ console.error(`Both "class" and "className" set in props for <${tagName}>. Use one or the other.`);
94
+ }
95
+ const element = node;
56
96
  const isSVG = xmlns === SVG_NAMESPACE;
57
- const colonIndex = name.indexOf(":");
58
- if (colonIndex !== -1) {
59
- const ns = name.slice(0, colonIndex);
60
- const name1 = name.slice(colonIndex + 1);
61
- switch (ns) {
62
- case "prop":
63
- node[name1] = value;
64
- return;
65
- case "attr":
97
+ for (let name in { ...oldProps, ...props }) {
98
+ let value = props[name];
99
+ const oldValue = oldProps ? oldProps[name] : undefined;
100
+ {
101
+ if (copyProps != null && copyProps.has(name)) {
102
+ continue;
103
+ }
104
+ // handle prop:name or attr:name properties
105
+ const colonIndex = name.indexOf(":");
106
+ if (colonIndex !== -1) {
107
+ const [ns, name1] = [
108
+ name.slice(0, colonIndex),
109
+ name.slice(colonIndex + 1),
110
+ ];
111
+ switch (ns) {
112
+ case "prop":
113
+ node[name1] = value;
114
+ continue;
115
+ case "attr":
116
+ if (value == null || value === false) {
117
+ if (isHydrating && element.hasAttribute(name1)) {
118
+ emitHydrationWarning(name, quietProps, value, element.getAttribute(name1), element);
119
+ }
120
+ element.removeAttribute(name1);
121
+ }
122
+ else if (value === true) {
123
+ if (isHydrating && !element.hasAttribute(name1)) {
124
+ emitHydrationWarning(name, quietProps, value, null, element);
125
+ }
126
+ element.setAttribute(name1, "");
127
+ }
128
+ else if (typeof value !== "string") {
129
+ value = String(value);
130
+ }
131
+ if (isHydrating && element.getAttribute(name1) !== value) {
132
+ emitHydrationWarning(name, quietProps, value, element.getAttribute(name1), element);
133
+ }
134
+ element.setAttribute(name1, String(value));
135
+ continue;
136
+ }
137
+ }
138
+ }
139
+ switch (name) {
140
+ // TODO: fix hydration warnings for the style prop
141
+ case "style": {
142
+ const style = element.style;
66
143
  if (value == null || value === false) {
67
- node.removeAttribute(name1);
144
+ if (isHydrating && style.cssText !== "") {
145
+ emitHydrationWarning(name, quietProps, value, style.cssText, element);
146
+ }
147
+ element.removeAttribute("style");
68
148
  }
69
149
  else if (value === true) {
70
- node.setAttribute(name1, "");
150
+ if (isHydrating && style.cssText !== "") {
151
+ emitHydrationWarning(name, quietProps, "", style.cssText, element);
152
+ }
153
+ element.setAttribute("style", "");
71
154
  }
72
155
  else if (typeof value === "string") {
73
- node.setAttribute(name1, value);
156
+ if (style.cssText !== value) {
157
+ // TODO: Fix hydration warnings for styles
158
+ //if (isHydrating) {
159
+ // emitHydrationWarning(
160
+ // name,
161
+ // quietProps,
162
+ // value,
163
+ // style.cssText,
164
+ // element,
165
+ // );
166
+ //}
167
+ style.cssText = value;
168
+ }
74
169
  }
75
170
  else {
76
- node.setAttribute(name, String(value));
171
+ if (typeof oldValue === "string") {
172
+ // if the old value was a string, we need to clear the style
173
+ // TODO: only clear the styles enumerated in the old value
174
+ style.cssText = "";
175
+ }
176
+ for (const styleName in { ...oldValue, ...value }) {
177
+ const styleValue = value && value[styleName];
178
+ if (styleValue == null) {
179
+ if (isHydrating && style.getPropertyValue(styleName) !== "") {
180
+ emitHydrationWarning(name, quietProps, null, style.getPropertyValue(styleName), element, `style.${styleName}`);
181
+ }
182
+ style.removeProperty(styleName);
183
+ }
184
+ else if (style.getPropertyValue(styleName) !== styleValue) {
185
+ // TODO: hydration warnings for style props
186
+ //if (isHydrating) {
187
+ // emitHydrationWarning(
188
+ // name,
189
+ // quietProps,
190
+ // styleValue,
191
+ // style.getPropertyValue(styleName),
192
+ // element,
193
+ // `style.${styleName}`,
194
+ // );
195
+ //}
196
+ style.setProperty(styleName, styleValue);
197
+ }
198
+ }
77
199
  }
78
- return;
79
- }
80
- }
81
- switch (name) {
82
- case "style": {
83
- const style = node.style;
84
- if (style == null) {
85
- node.setAttribute("style", value);
86
- }
87
- else if (value == null || value === false) {
88
- node.removeAttribute("style");
89
- }
90
- else if (value === true) {
91
- node.setAttribute("style", "");
200
+ break;
92
201
  }
93
- else if (typeof value === "string") {
94
- if (style.cssText !== value) {
95
- style.cssText = value;
202
+ case "class":
203
+ case "className":
204
+ if (value === true) {
205
+ if (isHydrating && element.getAttribute("class") !== "") {
206
+ emitHydrationWarning(name, quietProps, "", element.getAttribute("class"), element);
207
+ }
208
+ element.setAttribute("class", "");
96
209
  }
97
- }
98
- else {
99
- if (typeof oldValue === "string") {
100
- style.cssText = "";
210
+ else if (value == null) {
211
+ if (isHydrating && element.hasAttribute("class")) {
212
+ emitHydrationWarning(name, quietProps, value, element.getAttribute("class"), element);
213
+ }
214
+ element.removeAttribute("class");
101
215
  }
102
- for (const styleName in { ...oldValue, ...value }) {
103
- const styleValue = value && value[styleName];
104
- if (styleValue == null) {
105
- style.removeProperty(styleName);
216
+ else if (typeof value === "object") {
217
+ // class={{"included-class": true, "excluded-class": false}} syntax
218
+ if (typeof oldValue === "string") {
219
+ // if the old value was a string, we need to clear all classes
220
+ element.setAttribute("class", "");
221
+ }
222
+ let shouldIssueWarning = false;
223
+ const hydratingClasses = isHydrating
224
+ ? new Set(Array.from(element.classList))
225
+ : undefined;
226
+ const hydratingClassName = isHydrating
227
+ ? element.getAttribute("class")
228
+ : undefined;
229
+ for (const className in { ...oldValue, ...value }) {
230
+ const classValue = value && value[className];
231
+ if (classValue) {
232
+ element.classList.add(className);
233
+ if (hydratingClasses && hydratingClasses.has(className)) {
234
+ hydratingClasses.delete(className);
235
+ }
236
+ else if (isHydrating) {
237
+ shouldIssueWarning = true;
238
+ }
239
+ }
240
+ else {
241
+ element.classList.remove(className);
242
+ }
106
243
  }
107
- else if (style.getPropertyValue(styleName) !== styleValue) {
108
- style.setProperty(styleName, styleValue);
244
+ if (shouldIssueWarning ||
245
+ (hydratingClasses && hydratingClasses.size > 0)) {
246
+ emitHydrationWarning(name, quietProps, Object.keys(value)
247
+ .filter((k) => value[k])
248
+ .join(" "), hydratingClassName || "", element);
109
249
  }
110
250
  }
111
- }
112
- break;
113
- }
114
- case "class":
115
- case "className":
116
- if (value === true) {
117
- node.setAttribute("class", "");
118
- }
119
- else if (value == null) {
120
- node.removeAttribute("class");
121
- }
122
- else if (!isSVG) {
123
- if (node.className !== value) {
124
- node["className"] = value;
251
+ else if (!isSVG) {
252
+ if (element.className !== value) {
253
+ if (isHydrating) {
254
+ emitHydrationWarning(name, quietProps, value, element.className, element);
255
+ }
256
+ element.className = value;
257
+ }
125
258
  }
126
- }
127
- else if (node.getAttribute("class") !== value) {
128
- node.setAttribute("class", value);
129
- }
130
- break;
131
- case "innerHTML":
132
- if (value !== oldValue) {
133
- node.innerHTML = value;
134
- }
135
- break;
136
- default: {
137
- if (name[0] === "o" &&
138
- name[1] === "n" &&
139
- name[2] === name[2].toUpperCase() &&
140
- typeof value === "function") {
141
- // Support React-style event names (onClick, onChange, etc.)
142
- name = name.toLowerCase();
143
- }
144
- if (name in node &&
145
- // boolean properties will coerce strings, but sometimes they map to
146
- // enumerated attributes, where truthy strings ("false", "no") map to
147
- // falsy properties, so we use attributes in this case.
148
- !(typeof value === "string" &&
149
- typeof node[name] === "boolean")) {
150
- // walk up the object's prototype chain to find the owner of the
151
- // named property
152
- let obj = node;
153
- do {
154
- if (Object.prototype.hasOwnProperty.call(obj, name)) {
155
- break;
259
+ else if (element.getAttribute("class") !== value) {
260
+ if (isHydrating) {
261
+ emitHydrationWarning(name, quietProps, value, element.getAttribute("class"), element);
156
262
  }
157
- } while ((obj = Object.getPrototypeOf(obj)));
158
- // get the descriptor for the named property and check whether it
159
- // implies that the property is writable
160
- const descriptor = Object.getOwnPropertyDescriptor(obj, name);
161
- if (descriptor != null &&
162
- (descriptor.writable === true || descriptor.set !== undefined)) {
163
- if (node[name] !== value || oldValue === undefined) {
164
- node[name] = value;
263
+ element.setAttribute("class", value);
264
+ }
265
+ break;
266
+ case "innerHTML":
267
+ if (value !== oldValue) {
268
+ if (isHydrating) {
269
+ emitHydrationWarning(name, quietProps, value, element.innerHTML, element);
165
270
  }
166
- return;
271
+ element.innerHTML = value;
167
272
  }
168
- // if the property wasn't writable, fall through to the code below
169
- // which uses setAttribute() instead of assigning directly.
170
- }
171
- if (value === true) {
172
- value = "";
173
- }
174
- else if (value == null || value === false) {
175
- node.removeAttribute(name);
176
- return;
177
- }
178
- if (node.getAttribute(name) !== value) {
179
- node.setAttribute(name, value);
180
- }
181
- }
182
- }
183
- },
184
- arrange(tag, node, props, children, _oldProps, oldChildren) {
185
- if (tag === Portal && (node == null || typeof node.nodeType !== "number")) {
186
- throw new TypeError(`Portal root is not a node. Received: ${JSON.stringify(node && node.toString())}`);
187
- }
188
- if (!("innerHTML" in props) &&
189
- // We don’t want to update elements without explicit children (<div/>),
190
- // because these elements sometimes have child nodes added via raw
191
- // DOM manipulations.
192
- // However, if an element has previously rendered children, we clear the
193
- // them because it would be surprising not to clear Crank managed
194
- // children, even if the new element does not have explicit children.
195
- ("children" in props || (oldChildren && oldChildren.length))) {
196
- if (children.length === 0) {
197
- node.textContent = "";
198
- }
199
- else {
200
- let oldChild = node.firstChild;
201
- let i = 0;
202
- while (oldChild !== null && i < children.length) {
203
- const newChild = children[i];
204
- if (oldChild === newChild) {
205
- oldChild = oldChild.nextSibling;
206
- i++;
273
+ break;
274
+ default: {
275
+ if (name[0] === "o" &&
276
+ name[1] === "n" &&
277
+ name[2] === name[2].toUpperCase() &&
278
+ typeof value === "function") {
279
+ // Support React-style event names (onClick, onChange, etc.)
280
+ name = name.toLowerCase();
207
281
  }
208
- else if (typeof newChild === "string") {
209
- if (oldChild.nodeType === Node.TEXT_NODE) {
210
- if (oldChild.data !== newChild) {
211
- oldChild.data = newChild;
282
+ // try to set the property directly
283
+ if (name in element &&
284
+ // boolean properties will coerce strings, but sometimes they map to
285
+ // enumerated attributes, where truthy strings ("false", "no") map to
286
+ // falsy properties, so we force using setAttribute.
287
+ !(typeof value === "string" &&
288
+ typeof element[name] === "boolean") &&
289
+ isWritableProperty(element, name)) {
290
+ if (element[name] !== value || oldValue === undefined) {
291
+ if (isHydrating &&
292
+ typeof element[name] === "string" &&
293
+ element[name] !== value) {
294
+ emitHydrationWarning(name, quietProps, value, element[name], element);
212
295
  }
213
- oldChild = oldChild.nextSibling;
296
+ // if the property is writable, assign it directly
297
+ element[name] = value;
214
298
  }
215
- else {
216
- node.insertBefore(document.createTextNode(newChild), oldChild);
299
+ continue;
300
+ }
301
+ if (value === true) {
302
+ value = "";
303
+ }
304
+ else if (value == null || value === false) {
305
+ if (isHydrating && element.hasAttribute(name)) {
306
+ emitHydrationWarning(name, quietProps, value, element.getAttribute(name), element);
217
307
  }
218
- i++;
308
+ element.removeAttribute(name);
309
+ continue;
219
310
  }
220
- else if (oldChild.nodeType === Node.TEXT_NODE) {
221
- const nextSibling = oldChild.nextSibling;
222
- node.removeChild(oldChild);
223
- oldChild = nextSibling;
311
+ else if (typeof value !== "string") {
312
+ value = String(value);
224
313
  }
225
- else {
226
- node.insertBefore(newChild, oldChild);
227
- i++;
228
- // TODO: This is an optimization but we need to think a little more about other cases like prepending.
229
- if (oldChild !== children[i]) {
230
- const nextSibling = oldChild.nextSibling;
231
- node.removeChild(oldChild);
232
- oldChild = nextSibling;
314
+ if (element.getAttribute(name) !== value) {
315
+ if (isHydrating) {
316
+ emitHydrationWarning(name, quietProps, value, element.getAttribute(name), element);
233
317
  }
318
+ element.setAttribute(name, value);
234
319
  }
235
320
  }
236
- // remove excess DOM nodes
237
- while (oldChild !== null) {
238
- const nextSibling = oldChild.nextSibling;
239
- node.removeChild(oldChild);
240
- oldChild = nextSibling;
321
+ }
322
+ }
323
+ },
324
+ arrange({ tag, node, props, children, }) {
325
+ if (tag === Portal && (node == null || typeof node.nodeType !== "number")) {
326
+ throw new TypeError(`<Portal> root is not a node. Received: ${String(node)}`);
327
+ }
328
+ if (!("innerHTML" in props)) {
329
+ let oldChild = node.firstChild;
330
+ for (let i = 0; i < children.length; i++) {
331
+ const newChild = children[i];
332
+ if (oldChild === newChild) {
333
+ // the child is already in the right place, so we can skip it
334
+ oldChild = oldChild.nextSibling;
241
335
  }
242
- // append excess children
243
- for (; i < children.length; i++) {
244
- const newChild = children[i];
245
- node.appendChild(typeof newChild === "string"
246
- ? document.createTextNode(newChild)
247
- : newChild);
336
+ else {
337
+ node.insertBefore(newChild, oldChild);
338
+ if (tag !== Portal &&
339
+ oldChild &&
340
+ i + 1 < children.length &&
341
+ oldChild !== children[i + 1]) {
342
+ oldChild = oldChild.nextSibling;
343
+ }
248
344
  }
249
345
  }
250
346
  }
251
347
  },
252
- text(text, _scope, hydrationData) {
253
- if (hydrationData != null) {
254
- let value = hydrationData.children.shift();
255
- if (typeof value !== "string" || !value.startsWith(text)) ;
256
- else if (text.length < value.length) {
257
- value = value.slice(text.length);
258
- hydrationData.children.unshift(value);
348
+ remove({ node, parentNode, isNested, }) {
349
+ if (!isNested && node.parentNode === parentNode) {
350
+ parentNode.removeChild(node);
351
+ }
352
+ },
353
+ text({ value, oldNode, hydrationNodes, }) {
354
+ if (hydrationNodes != null) {
355
+ let node = hydrationNodes.shift();
356
+ if (!node || node.nodeType !== Node.TEXT_NODE) {
357
+ console.warn(`Expected "${value}" while hydrating but found:`, node);
259
358
  }
359
+ else {
360
+ // value is a text node, check if it matches the expected text
361
+ const textData = node.data;
362
+ if (textData.length > value.length) {
363
+ if (textData.startsWith(value)) {
364
+ // the text node is longer than the expected text, so we
365
+ // reuse the existing text node, but truncate it and unshift the rest
366
+ node.data = value;
367
+ hydrationNodes.unshift(document.createTextNode(textData.slice(value.length)));
368
+ return node;
369
+ }
370
+ }
371
+ else if (textData === value) {
372
+ return node;
373
+ }
374
+ // We log textData and not node because node will be mutated
375
+ console.warn(`Expected "${value}" while hydrating but found:`, textData);
376
+ oldNode = node;
377
+ }
378
+ }
379
+ if (oldNode != null) {
380
+ if (oldNode.data !== value) {
381
+ oldNode.data = value;
382
+ }
383
+ return oldNode;
260
384
  }
261
- return text;
385
+ return document.createTextNode(value);
262
386
  },
263
- raw(value, xmlns, hydrationData) {
264
- let result;
387
+ raw({ value, scope: xmlns, hydrationNodes, }) {
388
+ let nodes;
265
389
  if (typeof value === "string") {
266
390
  const el = xmlns == null
267
391
  ? document.createElement("div")
268
392
  : document.createElementNS(xmlns, "svg");
269
393
  el.innerHTML = value;
270
- if (el.childNodes.length === 0) {
271
- result = undefined;
272
- }
273
- else if (el.childNodes.length === 1) {
274
- result = el.childNodes[0];
275
- }
276
- else {
277
- result = Array.from(el.childNodes);
278
- }
394
+ nodes = Array.from(el.childNodes);
279
395
  }
280
396
  else {
281
- result = value;
397
+ nodes = value == null ? [] : Array.isArray(value) ? [...value] : [value];
282
398
  }
283
- if (hydrationData != null) {
284
- // TODO: maybe we should warn on incorrect values
285
- if (Array.isArray(result)) {
286
- for (let i = 0; i < result.length; i++) {
287
- const node = result[i];
288
- if (typeof node !== "string" &&
289
- (node.nodeType === Node.ELEMENT_NODE ||
290
- node.nodeType === Node.TEXT_NODE)) {
291
- hydrationData.children.shift();
292
- }
399
+ if (hydrationNodes != null) {
400
+ for (let i = 0; i < nodes.length; i++) {
401
+ const node = nodes[i];
402
+ // check if node is equal to the next node in the hydration array
403
+ const hydrationNode = hydrationNodes.shift();
404
+ if (hydrationNode &&
405
+ typeof hydrationNode === "object" &&
406
+ typeof hydrationNode.nodeType === "number" &&
407
+ node.isEqualNode(hydrationNode)) {
408
+ nodes[i] = hydrationNode;
293
409
  }
294
- }
295
- else if (result != null && typeof result !== "string") {
296
- if (result.nodeType === Node.ELEMENT_NODE ||
297
- result.nodeType === Node.TEXT_NODE) {
298
- hydrationData.children.shift();
410
+ else {
411
+ console.warn(`Expected <Raw value="${String(value)}"> while hydrating but found:`, hydrationNode);
299
412
  }
300
413
  }
301
414
  }
302
- return result;
415
+ return nodes.length === 0
416
+ ? undefined
417
+ : nodes.length === 1
418
+ ? nodes[0]
419
+ : nodes;
303
420
  },
304
421
  };
305
422
  class DOMRenderer extends Renderer {
306
423
  constructor() {
307
- super(impl);
424
+ super(adapter);
308
425
  }
309
426
  render(children, root, ctx) {
310
427
  validateRoot(root);
@@ -316,12 +433,15 @@ class DOMRenderer extends Renderer {
316
433
  }
317
434
  }
318
435
  function validateRoot(root) {
319
- if (root === null ||
436
+ if (root == null ||
320
437
  (typeof root === "object" && typeof root.nodeType !== "number")) {
321
- throw new TypeError(`Render root is not a node. Received: ${JSON.stringify(root && root.toString())}`);
438
+ throw new TypeError(`Render root is not a node. Received: ${String(root)}`);
439
+ }
440
+ else if (root.nodeType !== Node.ELEMENT_NODE) {
441
+ throw new TypeError(`Render root must be an element node. Received: ${String(root)}`);
322
442
  }
323
443
  }
324
444
  const renderer = new DOMRenderer();
325
445
 
326
- export { DOMRenderer, impl, renderer };
446
+ export { DOMRenderer, adapter, renderer };
327
447
  //# sourceMappingURL=dom.js.map