export function wrapStructural(raw, ctx) {
  const kids = ctx.nodeChildren(raw);
  if (!kids || kids.length === 0) {
    return { kind: "terminal", raw, key: ctx.nodeKey(raw) };
  }
  return {
    kind: "branch",
    raw,
    key: ctx.nodeKey(raw),
    children: kids.map((c) => wrapStructural(c, ctx))
  };
}
export function wrapStructuralAll(raws, ctx) {
  return raws.map((r) => wrapStructural(r, ctx));
}
export function getWrappedChildren(w) {
  return w.kind === "branch" ? w.children : void 0;
}
export function findWrappedPath(roots, key) {
  const trail = [];
  function walk(siblings) {
    for (const n of siblings) {
      trail.push(n);
      if (n.key === key) return true;
      if (n.kind === "branch" && n.children.length > 0 && walk(n.children)) return true;
      trail.pop();
    }
    return false;
  }
  return walk(roots) ? trail.slice() : null;
}
