|
1 | 1 | /*! (c) Andrea Giammarchi - MIT */ |
| 2 | +import { Hole, unroll } from './rabbit.js'; |
2 | 3 | import { attr } from './handler.js'; |
3 | | - |
4 | | -import create from './creator.js'; |
5 | | -import parser from './parser.js'; |
6 | | -import render from './render/node.js'; |
| 4 | +import { cache } from './literals.js'; |
| 5 | +import { empty } from './utils.js'; |
7 | 6 |
|
8 | 7 | /** @typedef {import("./literals.js").DOMValue} DOMValue */ |
9 | 8 | /** @typedef {import("./literals.js").Target} Target */ |
10 | 9 |
|
11 | | -const tag = svg => { |
12 | | - const parse = create(parser(svg)); |
13 | | - return (template, ...values) => parse(template, values).n; |
14 | | -}; |
| 10 | +const tag = svg => (template, ...values) => unroll( |
| 11 | + cache(empty), |
| 12 | + new Hole(svg, template, values) |
| 13 | +); |
15 | 14 |
|
16 | 15 | /** @type {(template: TemplateStringsArray, ...values:DOMValue[]) => Target} A tag to render HTML content. */ |
17 | 16 | const html = tag(false); |
18 | 17 |
|
19 | 18 | /** @type {(template: TemplateStringsArray, ...values:DOMValue[]) => Target} A tag to render SVG content. */ |
20 | 19 | const svg = tag(true); |
21 | 20 |
|
| 21 | +/** |
| 22 | + * Render directly within a generic container. |
| 23 | + * @template T |
| 24 | + * @param {T} where the DOM node where to render content |
| 25 | + * @param {(() => Target) | Target} what the node to render |
| 26 | + * @returns |
| 27 | + */ |
| 28 | +const render = (where, what) => { |
| 29 | + where.replaceChildren( |
| 30 | + (typeof what === 'function' ? what() : what).valueOf() |
| 31 | + ); |
| 32 | + return where; |
| 33 | +}; |
| 34 | + |
22 | 35 | export { render, html, svg, attr }; |
0 commit comments