{"id":11002,"library":"hast-util-interactive","title":"HAST Interactive Content Utility","description":"hast-util-interactive is a focused utility within the unified ecosystem, specifically designed to determine if a given hast (Hypertext Abstract Syntax Tree) node constitutes \"interactive content\" according to the HTML specification. This package is particularly useful for tools that analyze or transform HTML content and need to identify elements like `<a>` with `href`, `<button>`, `<input>`, or `<video controls>` to enforce accessibility rules, validate content, or apply specific styling. The current stable version is 3.0.0. Maintained by the syntax-tree collective, it follows a release cadence tied to Node.js LTS cycles and hast ecosystem updates, providing TypeScript types for enhanced developer experience. Its primary differentiator is its precise implementation of the HTML interactive content algorithm for hast nodes, offering a reliable predicate function rather than a full parsing or transformation engine.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/hast-util-interactive","tags":["javascript","unist","hast","hast-util","util","utility","html","element","category","typescript"],"install":[{"cmd":"npm install hast-util-interactive","lang":"bash","label":"npm"},{"cmd":"yarn add hast-util-interactive","lang":"bash","label":"yarn"},{"cmd":"pnpm add hast-util-interactive","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since v2.0.0 and requires Node.js 16+ since v3.0.0. CommonJS `require()` is not supported.","wrong":"const interactive = require('hast-util-interactive')","symbol":"interactive","correct":"import { interactive } from 'hast-util-interactive'"},{"note":"While this package ships its own types, input nodes often come from the 'hast' package, requiring its types for full type safety.","symbol":"Element","correct":"import type { Element } from 'hast'"}],"quickstart":{"code":"import { interactive } from 'hast-util-interactive';\nimport type { Element, Text, Root } from 'hast';\n\n// Example 1: Non-interactive anchor (no href)\nconst nonInteractiveLink: Element = {\n  type: 'element',\n  tagName: 'a',\n  properties: {},\n  children: [{type: 'text', value: 'Non-clickable link'}]\n};\nconsole.log('Is nonInteractiveLink interactive?', interactive(nonInteractiveLink)); // => false\n\n// Example 2: Interactive anchor (with href)\nconst interactiveLink: Element = {\n  type: 'element',\n  tagName: 'a',\n  properties: {href: '#section'},\n  children: [{type: 'text', value: 'Clickable link'}]\n};\nconsole.log('Is interactiveLink interactive?', interactive(interactiveLink)); // => true\n\n// Example 3: Interactive button\nconst buttonElement: Element = {\n  type: 'element',\n  tagName: 'button',\n  properties: {},\n  children: [{type: 'text', value: 'Submit'}]\n};\nconsole.log('Is buttonElement interactive?', interactive(buttonElement)); // => true\n\n// Example 4: Video with controls\nconst videoElement: Element = {\n  type: 'element',\n  tagName: 'video',\n  properties: {controls: true, src: 'movie.mp4'},\n  children: []\n};\nconsole.log('Is videoElement interactive?', interactive(videoElement)); // => true\n\n// Example 5: Input field\nconst inputElement: Element = {\n  type: 'element',\n  tagName: 'input',\n  properties: {type: 'text', value: 'Hello'},\n  children: []\n};\nconsole.log('Is inputElement interactive?', interactive(inputElement)); // => true","lang":"typescript","description":"Demonstrates how to use the `interactive` function to check various hast nodes against the HTML specification for interactive content."},"warnings":[{"fix":"Upgrade your Node.js environment to version 16 or newer. For projects requiring older Node.js, use `hast-util-interactive@^2`.","message":"Version 3.0.0 changes to require Node.js 16 or higher. Older Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Ensure that the `node` argument passed to `interactive()` is always a valid `hast` Node object. Validate input before calling the utility.","message":"Version 3.0.0 removes support for passing non-Node values (e.g., `null`, `undefined`) to the `interactive` function. Input must be a valid `hast` Node.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always import symbols directly from the package's main entry point, e.g., `import { interactive } from 'hast-util-interactive'`. Do not try to access internal paths like `hast-util-interactive/lib/interactive.js`.","message":"Version 3.0.0 introduces `exports` in package.json, changing internal module resolution. Avoid relying on private, non-exported APIs as they may no longer be accessible.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update your import statements to use ES module syntax (e.g., `import { interactive } from 'hast-util-interactive'`). Ensure your project is configured for ESM, or use a tool like Babel/TypeScript to transpile.","message":"Version 2.0.0 converted the package to ESM (ECMAScript Modules) only. CommonJS `require()` is no longer supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Understand the HTML specification for interactive content before use. This utility serves a niche purpose within the unified ecosystem.","message":"This utility is highly specific, checking for 'interactive content' according to HTML. It is not a general-purpose HTML parser or validator. Its definition of 'interactive' is precise (e.g., `<a>` is only interactive with an `href`).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statement from `const { interactive } = require('hast-util-interactive')` to `import { interactive } from 'hast-util-interactive'` and ensure your Node.js environment or build setup supports ESM.","cause":"Attempting to use CommonJS `require()` syntax with an ESM-only package.","error":"TypeError [ERR_REQUIRE_ESM]: require() of ES module /path/to/node_modules/hast-util-interactive/index.js from /your/project/file.js not supported."},{"fix":"Upgrade your Node.js environment to version 16 or higher. Alternatively, ensure the `import` statement is correct and the module is resolving properly.","cause":"Using an outdated Node.js version (prior to 16) that does not meet the minimum requirement for `hast-util-interactive@^3`, or an incorrect import.","error":"ReferenceError: interactive is not defined"},{"fix":"Before calling `interactive(node)`, validate that `node` is indeed a `hast` Node object. For example, `if (node && typeof node === 'object' && node.type) { interactive(node) }`.","cause":"Passing `null`, `undefined`, or other non-Node JavaScript values to the `interactive` function, which now strictly requires a `hast` Node.","error":"TypeError: Cannot read properties of undefined (reading 'type') or similar error when passing non-node values."}],"ecosystem":"npm"}