Skip to content

Commit

Permalink
uhtml/ssr - Added both easy SSR and worker.js target
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Apr 13, 2024
1 parent a6f032c commit 4023a0a
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 106 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ types/
cjs/*
!cjs/package.json
dom.js
esm/init.js
init.js
esm/init*.js
init*.js
worker.js
keyed.js
!esm/keyed.js
!esm/dom/keyed.js
Expand All @@ -24,4 +25,4 @@ signal.js
!esm/signal.js
!esm/render/signal.js
preactive.js
!test/preactive.js
!test/preactive.js
10 changes: 1 addition & 9 deletions esm/creator.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { PersistentFragment } from './persistent-fragment.js';
import { bc, detail } from './literals.js';
import { array, hole } from './handler.js';
import { empty } from './utils.js';
import { empty, find } from './utils.js';
import { cache } from './literals.js';

/**
* @param {DocumentFragment} content
* @param {number[]} path
* @returns {Element}
*/
const find = (content, path) => path.reduceRight(childNodesIndex, content);
const childNodesIndex = (node, i) => node.childNodes[i];

/** @param {(template: TemplateStringsArray, values: any[]) => import("./parser.js").Resolved} parse */
export default parse => (
/**
Expand Down
3 changes: 2 additions & 1 deletion esm/persistent-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class PersistentFragment extends custom(DocumentFragment) {
remove(this, true).replaceWith(node);
}
valueOf() {
let { firstChild, lastChild, parentNode } = this;
const { parentNode } = this;
if (parentNode === this) {
if (this.#nodes === empty)
this.#nodes = [...this.childNodes];
Expand All @@ -65,6 +65,7 @@ export class PersistentFragment extends custom(DocumentFragment) {
// This is a render-only specific issue but it's tested and
// it's worth fixing to me to have more consistent fragments.
if (parentNode) {
let { firstChild, lastChild } = this;
this.#nodes = [firstChild];
while (firstChild !== lastChild)
this.#nodes.push((firstChild = firstChild.nextSibling));
Expand Down
6 changes: 3 additions & 3 deletions esm/rabbit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { cache } from './literals.js';
import create from './creator.js';
import parser from './parser.js';

const parseHTML = create(parser(false));
const parseSVG = create(parser(true));
const createHTML = create(parser(false));
const createSVG = create(parser(true));

/**
* @param {import("./literals.js").Cache} info
Expand All @@ -13,7 +13,7 @@ const parseSVG = create(parser(true));
*/
const unroll = (info, { s, t, v }) => {
if (info.a !== t) {
const { b, c } = (s ? parseSVG : parseHTML)(t, v);
const { b, c } = (s ? createSVG : createHTML)(t, v);
info.a = t;
info.b = b;
info.c = c;
Expand Down
6 changes: 6 additions & 0 deletions esm/ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Hole, render, html, svg, attr } from './index.js';

const htmlFor = () => html;
const svgFor = () => svg;

export { Hole, render, html, svg, htmlFor, svgFor, attr };
10 changes: 10 additions & 0 deletions esm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ export const gPD = (ref, prop) => {
while(!desc && (ref = getPrototypeOf(ref)));
return desc;
};

/* c8 ignore start */
/**
* @param {DocumentFragment} content
* @param {number[]} path
* @returns {Element}
*/
export const find = (content, path) => path.reduceRight(childNodesIndex, content);
const childNodesIndex = (node, i) => node.childNodes[i];
/* c8 ignore stop */
138 changes: 69 additions & 69 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4023a0a

Please sign in to comment.