Add fonts, autotable, autotable examples

This commit is contained in:
2026-07-13 13:01:26 -04:00
parent ea3d2a6d03
commit cf8342f8d4
71 changed files with 16084 additions and 1443 deletions

View File

@@ -13,17 +13,57 @@
const { execSync } = require("child_process");
class CSSStyle {
constructor() { this.props = {}; }
setProperty(k, v) { this.props[k] = String(v); }
removeProperty(k) { delete this.props[k]; }
getPropertyValue(k) { return this.props[k] ?? ""; }
get cssText() {
return Object.keys(this.props).sort().map((k) => `${k}: ${this.props[k]}`).join("; ");
}
}
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const SVG_NS = "http://www.w3.org/2000/svg";
class DNode {
constructor(tag) {
constructor(tag, ns = XHTML_NS) {
this.tag = tag;
// An element's namespace is fixed at creation. createElement() always yields
// HTML — which is why an <svg> built that way is inert; see the reconciler.
this.namespaceURI = ns;
this.childNodes = [];
this.attrs = {};
this.parentNode = null;
this.listeners = {};
this.nodeValue = null;
this.rawHTML = null;
this.style = new CSSStyle();
// Tests set .rect to control what getBoundingClientRect reports; there is no
// layout engine here, so geometry is whatever the test declares.
this.rect = { left: 0, top: 0, width: 0, height: 0 };
}
get nodeType() { return this.tag === "#text" ? 3 : 1; }
get firstChild() { return this.childNodes[0] ?? null; }
get parentElement() { return this.parentNode; }
getAttribute(k) { return k in this.attrs ? this.attrs[k] : null; }
hasAttribute(k) { return k in this.attrs; }
getBoundingClientRect() {
const r = this.rect;
return { left: r.left, top: r.top, width: r.width, height: r.height, right: r.left + r.width, bottom: r.top + r.height };
}
contains(other) {
for (let n = other; n; n = n.parentNode) if (n === this) return true;
return false;
}
// Only the attribute-presence selectors the runtime actually uses, e.g.
// "[data-floating-id]".
closest(selector) {
const m = /^\[([a-zA-Z0-9-]+)\]$/.exec(selector);
if (!m) throw new Error(`domexec shim: unsupported selector ${selector}`);
for (let n = this; n; n = n.parentNode) if (n.nodeType === 1 && n.hasAttribute(m[1])) return n;
return null;
}
appendChild(c) { c.parentNode = this; this.childNodes.push(c); return c; }
removeChild(c) {
const i = this.childNodes.indexOf(c);
@@ -66,15 +106,37 @@ function serialize(n) {
if (n.tag === "#text") return n.nodeValue ?? "";
if (n.tag === "#raw") return n.rawHTML ?? "";
const attrs = Object.keys(n.attrs).sort().map((k) => ` ${k}="${n.attrs[k]}"`).join("");
return `<${n.tag}${attrs}>${n.childNodes.map(serialize).join("")}</${n.tag}>`;
const style = n.style.cssText ? ` style="${n.style.cssText}"` : "";
return `<${n.tag}${attrs}${style}>${n.childNodes.map(serialize).join("")}</${n.tag}>`;
}
const body = new DNode("body");
const documentElement = new DNode("html");
globalThis.document = {
createElement: (tag) => new DNode(tag),
body,
documentElement,
createElement: (tag) => new DNode(tag, XHTML_NS),
createElementNS: (ns, tag) => new DNode(tag, ns),
createTextNode: (text) => { const n = new DNode("#text"); n.nodeValue = text; return n; },
getElementById: () => null,
querySelector: () => null,
addEventListener: () => {},
removeEventListener: () => {},
};
// Viewport size the floating engine collides against. Tests override these.
globalThis.innerWidth = 1024;
globalThis.innerHeight = 768;
globalThis.addEventListener ??= () => {};
globalThis.removeEventListener ??= () => {};
globalThis.requestAnimationFrame = (fn) => setTimeout(() => fn(0), 0);
globalThis.cancelAnimationFrame = (id) => clearTimeout(id);
globalThis.getComputedStyle = (el) => ({
getPropertyValue: (k) => el.style.getPropertyValue(k),
fontSize: "16px",
});
// ---- go_js_wasm_exec boilerplate ----
globalThis.require = require;
globalThis.fs = require("fs");