// Minimal, untyped-tolerant input model for the raw scoped Figma node subtree (Epic #750, Issue #752).
//
// The cleaner consumes the raw Figma `document` node tree returned by the server-side connector
// (#751). That JSON is provider-shaped and only partially typed, so this module models the few
// fields the IR needs and exposes narrowing readers over `unknown` — never `any`. Direction is
// clean: this package depends on nothing from keiko-server; the readers tolerate absent/malformed
// fields so a single bad node never aborts the transform.
export const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
export const asNode = (value) => isRecord(value) ? value : undefined;
export const readString = (value) => typeof value === "string" ? value : undefined;
export const readNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
export const readArray = (value) => Array.isArray(value) ? value : [];
/** Figma omits `visible` when a node is shown; only an explicit `false` hides it. */
export const isHidden = (node) => node.visible === false;
export const nodeId = (node) => readString(node.id) ?? "";
export const nodeName = (node) => readString(node.name) ?? "";
export const nodeType = (node) => readString(node.type) ?? "";
export const childNodes = (node) => {
    const out = [];
    for (const child of readArray(node.children)) {
        const record = asNode(child);
        if (record !== undefined)
            out.push(record);
    }
    return out;
};
