@b9g/crank 0.6.0 → 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
- import { Portal, Renderer } from './crank.js';
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,262 +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
- switch (name) {
58
- case "style": {
59
- const style = node.style;
60
- if (style == null) {
61
- node.setAttribute("style", value);
62
- }
63
- else if (value == null || value === false) {
64
- node.removeAttribute("style");
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;
65
103
  }
66
- else if (value === true) {
67
- node.setAttribute("style", "");
68
- }
69
- else if (typeof value === "string") {
70
- if (style.cssText !== value) {
71
- style.cssText = value;
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;
72
136
  }
73
137
  }
74
- else {
75
- if (typeof oldValue === "string") {
76
- style.cssText = "";
138
+ }
139
+ switch (name) {
140
+ // TODO: fix hydration warnings for the style prop
141
+ case "style": {
142
+ const style = element.style;
143
+ if (value == null || value === false) {
144
+ if (isHydrating && style.cssText !== "") {
145
+ emitHydrationWarning(name, quietProps, value, style.cssText, element);
146
+ }
147
+ element.removeAttribute("style");
77
148
  }
78
- for (const styleName in { ...oldValue, ...value }) {
79
- const styleValue = value && value[styleName];
80
- if (styleValue == null) {
81
- style.removeProperty(styleName);
149
+ else if (value === true) {
150
+ if (isHydrating && style.cssText !== "") {
151
+ emitHydrationWarning(name, quietProps, "", style.cssText, element);
82
152
  }
83
- else if (style.getPropertyValue(styleName) !== styleValue) {
84
- style.setProperty(styleName, styleValue);
153
+ element.setAttribute("style", "");
154
+ }
155
+ else if (typeof value === "string") {
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;
85
168
  }
86
169
  }
87
- }
88
- break;
89
- }
90
- case "class":
91
- case "className":
92
- if (value === true) {
93
- node.setAttribute("class", "");
94
- }
95
- else if (value == null) {
96
- node.removeAttribute("class");
97
- }
98
- else if (!isSVG) {
99
- if (node.className !== value) {
100
- node["className"] = value;
170
+ else {
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
+ }
101
199
  }
200
+ break;
102
201
  }
103
- else if (node.getAttribute("class") !== value) {
104
- node.setAttribute("class", value);
105
- }
106
- break;
107
- case "innerHTML":
108
- if (value !== oldValue) {
109
- node.innerHTML = value;
110
- }
111
- break;
112
- default: {
113
- if (name[0] === "o" &&
114
- name[1] === "n" &&
115
- name[2] === name[2].toUpperCase() &&
116
- typeof value === "function") {
117
- // Support React-style event names (onClick, onChange, etc.)
118
- name = name.toLowerCase();
119
- }
120
- if (name in node &&
121
- // boolean properties will coerce strings, but sometimes they map to
122
- // enumerated attributes, where truthy strings ("false", "no") map to
123
- // falsy properties, so we use attributes in this case.
124
- !(typeof value === "string" &&
125
- typeof node[name] === "boolean")) {
126
- // walk up the object's prototype chain to find the owner of the
127
- // named property
128
- let obj = node;
129
- do {
130
- if (Object.prototype.hasOwnProperty.call(obj, name)) {
131
- break;
202
+ case "class":
203
+ case "className":
204
+ if (value === true) {
205
+ if (isHydrating && element.getAttribute("class") !== "") {
206
+ emitHydrationWarning(name, quietProps, "", element.getAttribute("class"), element);
132
207
  }
133
- } while ((obj = Object.getPrototypeOf(obj)));
134
- // get the descriptor for the named property and check whether it
135
- // implies that the property is writable
136
- const descriptor = Object.getOwnPropertyDescriptor(obj, name);
137
- if (descriptor != null &&
138
- (descriptor.writable === true || descriptor.set !== undefined)) {
139
- if (node[name] !== value || oldValue === undefined) {
140
- node[name] = value;
208
+ element.setAttribute("class", "");
209
+ }
210
+ else if (value == null) {
211
+ if (isHydrating && element.hasAttribute("class")) {
212
+ emitHydrationWarning(name, quietProps, value, element.getAttribute("class"), element);
141
213
  }
142
- return;
214
+ element.removeAttribute("class");
143
215
  }
144
- // if the property wasn't writable, fall through to the code below
145
- // which uses setAttribute() instead of assigning directly.
146
- }
147
- if (value === true) {
148
- value = "";
149
- }
150
- else if (value == null || value === false) {
151
- node.removeAttribute(name);
152
- return;
153
- }
154
- if (node.getAttribute(name) !== value) {
155
- node.setAttribute(name, value);
156
- }
157
- }
158
- }
159
- },
160
- arrange(tag, node, props, children, _oldProps, oldChildren) {
161
- if (tag === Portal && (node == null || typeof node.nodeType !== "number")) {
162
- throw new TypeError(`Portal root is not a node. Received: ${JSON.stringify(node && node.toString())}`);
163
- }
164
- if (!("innerHTML" in props) &&
165
- // We don’t want to update elements without explicit children (<div/>),
166
- // because these elements sometimes have child nodes added via raw
167
- // DOM manipulations.
168
- // However, if an element has previously rendered children, we clear the
169
- // them because it would be surprising not to clear Crank managed
170
- // children, even if the new element does not have explicit children.
171
- ("children" in props || (oldChildren && oldChildren.length))) {
172
- if (children.length === 0) {
173
- node.textContent = "";
174
- }
175
- else {
176
- let oldChild = node.firstChild;
177
- let i = 0;
178
- while (oldChild !== null && i < children.length) {
179
- const newChild = children[i];
180
- if (oldChild === newChild) {
181
- oldChild = oldChild.nextSibling;
182
- i++;
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
+ }
243
+ }
244
+ if (shouldIssueWarning ||
245
+ (hydratingClasses && hydratingClasses.size > 0)) {
246
+ emitHydrationWarning(name, quietProps, Object.keys(value)
247
+ .filter((k) => value[k])
248
+ .join(" "), hydratingClassName || "", element);
249
+ }
183
250
  }
184
- else if (typeof newChild === "string") {
185
- if (oldChild.nodeType === Node.TEXT_NODE) {
186
- if (oldChild.data !== newChild) {
187
- oldChild.data = newChild;
251
+ else if (!isSVG) {
252
+ if (element.className !== value) {
253
+ if (isHydrating) {
254
+ emitHydrationWarning(name, quietProps, value, element.className, element);
188
255
  }
189
- oldChild = oldChild.nextSibling;
256
+ element.className = value;
190
257
  }
191
- else {
192
- node.insertBefore(document.createTextNode(newChild), oldChild);
258
+ }
259
+ else if (element.getAttribute("class") !== value) {
260
+ if (isHydrating) {
261
+ emitHydrationWarning(name, quietProps, value, element.getAttribute("class"), element);
193
262
  }
194
- i++;
263
+ element.setAttribute("class", value);
195
264
  }
196
- else if (oldChild.nodeType === Node.TEXT_NODE) {
197
- const nextSibling = oldChild.nextSibling;
198
- node.removeChild(oldChild);
199
- oldChild = nextSibling;
265
+ break;
266
+ case "innerHTML":
267
+ if (value !== oldValue) {
268
+ if (isHydrating) {
269
+ emitHydrationWarning(name, quietProps, value, element.innerHTML, element);
270
+ }
271
+ element.innerHTML = value;
200
272
  }
201
- else {
202
- node.insertBefore(newChild, oldChild);
203
- i++;
204
- // TODO: This is an optimization but we need to think a little more about other cases like prepending.
205
- if (oldChild !== children[i]) {
206
- const nextSibling = oldChild.nextSibling;
207
- node.removeChild(oldChild);
208
- oldChild = nextSibling;
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();
281
+ }
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);
295
+ }
296
+ // if the property is writable, assign it directly
297
+ element[name] = value;
298
+ }
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);
209
307
  }
308
+ element.removeAttribute(name);
309
+ continue;
310
+ }
311
+ else if (typeof value !== "string") {
312
+ value = String(value);
313
+ }
314
+ if (element.getAttribute(name) !== value) {
315
+ if (isHydrating) {
316
+ emitHydrationWarning(name, quietProps, value, element.getAttribute(name), element);
317
+ }
318
+ element.setAttribute(name, value);
210
319
  }
211
320
  }
212
- // remove excess DOM nodes
213
- while (oldChild !== null) {
214
- const nextSibling = oldChild.nextSibling;
215
- node.removeChild(oldChild);
216
- 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;
217
335
  }
218
- // append excess children
219
- for (; i < children.length; i++) {
220
- const newChild = children[i];
221
- node.appendChild(typeof newChild === "string"
222
- ? document.createTextNode(newChild)
223
- : 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
+ }
224
344
  }
225
345
  }
226
346
  }
227
347
  },
228
- text(text, _scope, hydrationData) {
229
- if (hydrationData != null) {
230
- let value = hydrationData.children.shift();
231
- if (typeof value !== "string" || !value.startsWith(text)) ;
232
- else if (text.length < value.length) {
233
- value = value.slice(text.length);
234
- 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);
235
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;
236
384
  }
237
- return text;
385
+ return document.createTextNode(value);
238
386
  },
239
- raw(value, xmlns, hydrationData) {
240
- let result;
387
+ raw({ value, scope: xmlns, hydrationNodes, }) {
388
+ let nodes;
241
389
  if (typeof value === "string") {
242
390
  const el = xmlns == null
243
391
  ? document.createElement("div")
244
392
  : document.createElementNS(xmlns, "svg");
245
393
  el.innerHTML = value;
246
- if (el.childNodes.length === 0) {
247
- result = undefined;
248
- }
249
- else if (el.childNodes.length === 1) {
250
- result = el.childNodes[0];
251
- }
252
- else {
253
- result = Array.from(el.childNodes);
254
- }
394
+ nodes = Array.from(el.childNodes);
255
395
  }
256
396
  else {
257
- result = value;
397
+ nodes = value == null ? [] : Array.isArray(value) ? [...value] : [value];
258
398
  }
259
- if (hydrationData != null) {
260
- // TODO: maybe we should warn on incorrect values
261
- if (Array.isArray(result)) {
262
- for (let i = 0; i < result.length; i++) {
263
- const node = result[i];
264
- if (typeof node !== "string" &&
265
- (node.nodeType === Node.ELEMENT_NODE ||
266
- node.nodeType === Node.TEXT_NODE)) {
267
- hydrationData.children.shift();
268
- }
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;
269
409
  }
270
- }
271
- else if (result != null && typeof result !== "string") {
272
- if (result.nodeType === Node.ELEMENT_NODE ||
273
- result.nodeType === Node.TEXT_NODE) {
274
- hydrationData.children.shift();
410
+ else {
411
+ console.warn(`Expected <Raw value="${String(value)}"> while hydrating but found:`, hydrationNode);
275
412
  }
276
413
  }
277
414
  }
278
- return result;
415
+ return nodes.length === 0
416
+ ? undefined
417
+ : nodes.length === 1
418
+ ? nodes[0]
419
+ : nodes;
279
420
  },
280
421
  };
281
422
  class DOMRenderer extends Renderer {
282
423
  constructor() {
283
- super(impl);
424
+ super(adapter);
284
425
  }
285
426
  render(children, root, ctx) {
286
427
  validateRoot(root);
@@ -292,12 +433,15 @@ class DOMRenderer extends Renderer {
292
433
  }
293
434
  }
294
435
  function validateRoot(root) {
295
- if (root === null ||
436
+ if (root == null ||
296
437
  (typeof root === "object" && typeof root.nodeType !== "number")) {
297
- 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)}`);
298
442
  }
299
443
  }
300
444
  const renderer = new DOMRenderer();
301
445
 
302
- export { DOMRenderer, impl, renderer };
446
+ export { DOMRenderer, adapter, renderer };
303
447
  //# sourceMappingURL=dom.js.map