-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathnode.js
More file actions
28 lines (22 loc) · 949 Bytes
/
Copy pathnode.js
File metadata and controls
28 lines (22 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*! (c) Andrea Giammarchi - MIT */
import { Hole } from './rabbit.js';
import { attr } from './handler.js';
/** @typedef {import("./literals.js").DOMValue} DOMValue */
/** @typedef {import("./literals.js").Target} Target */
const tag = svg => (template, ...values) => new Hole(svg, template, values).toDOM().valueOf();
/** @type {(template: TemplateStringsArray, ...values:DOMValue[]) => Target} A tag to render HTML content. */
const html = tag(false);
/** @type {(template: TemplateStringsArray, ...values:DOMValue[]) => Target} A tag to render SVG content. */
const svg = tag(true);
/**
* Render directly within a generic container.
* @template T
* @param {T} where the DOM node where to render content
* @param {(() => Target) | Target} what the node to render
* @returns
*/
const render = (where, what) => {
where.replaceChildren(typeof what === 'function' ? what() : what);
return where;
};
export { render, html, svg, attr };