UNPKG

@restnfeel/agentc-starter-kit

Version:

한국어 기업용 CMS 모듈 - Task Master AI와 함께 빠르게 웹사이트를 구현할 수 있는 재사용 가능한 컴포넌트 시스템

103 lines (83 loc) 2.44 kB
import require$$0 from '../../../../_virtual/index-all.js'; import { __require as requireAst } from './ast.js'; var simplify_1; var hasRequiredSimplify; function requireSimplify () { if (hasRequiredSimplify) return simplify_1; hasRequiredSimplify = 1; var _ = require$$0; var ast = /*@__PURE__*/ requireAst(); function simplify(nodes) { return collapse(removeEmpty(nodes)); } function collapse(nodes) { var children = []; nodes.map(collapseNode).forEach(function(child) { appendChild(children, child); }); return children; } function collapseNode(node) { return collapsers[node.type](node); } var collapsers = { element: collapseElement, text: identity, forceWrite: identity }; function collapseElement(node) { return ast.elementWithTag(node.tag, collapse(node.children)); } function identity(value) { return value; } function appendChild(children, child) { var lastChild = children[children.length - 1]; if (child.type === "element" && !child.tag.fresh && lastChild && lastChild.type === "element" && child.tag.matchesElement(lastChild.tag)) { if (child.tag.separator) { appendChild(lastChild.children, ast.text(child.tag.separator)); } child.children.forEach(function(grandChild) { // Mutation is fine since simplifying elements create a copy of the children. appendChild(lastChild.children, grandChild); }); } else { children.push(child); } } function removeEmpty(nodes) { return flatMap(nodes, function(node) { return emptiers[node.type](node); }); } function flatMap(values, func) { return _.flatten(_.map(values, func), true); } var emptiers = { element: elementEmptier, text: textEmptier, forceWrite: neverEmpty }; function neverEmpty(node) { return [node]; } function elementEmptier(element) { var children = removeEmpty(element.children); if (children.length === 0 && !ast.isVoidElement(element)) { return []; } else { return [ast.elementWithTag(element.tag, children)]; } } function textEmptier(node) { if (node.value.length === 0) { return []; } else { return [node]; } } simplify_1 = simplify; return simplify_1; } export { requireSimplify as __require }; //# sourceMappingURL=simplify.js.map