/* esm.sh - yaml@2.9.1/browser/dist/doc/anchors */
import{isScalar as i,isCollection as h}from"../nodes/identity.mjs";import{visit as u}from"../visit.mjs";function m(r){if(/[\x00-\x19\s,[\]{}]/.test(r)){let n=`Anchor must not contain whitespace or control characters: ${JSON.stringify(r)}`;throw new Error(n)}return!0}function f(r){let t=new Set;return u(r,{Value(n,e){e.anchor&&t.add(e.anchor)}}),t}function l(r,t){for(let n=1;;++n){let e=`${r}${n}`;if(!t.has(e))return e}}function w(r,t){let n=[],e=new Map,c=null;return{onAnchor:s=>{n.push(s),c??(c=f(r));let o=l(t,c);return c.add(o),o},setAnchors:()=>{for(let s of n){let o=e.get(s);if(typeof o=="object"&&o.anchor&&(i(o.node)||h(o.node)))o.node.anchor=o.anchor;else{let a=new Error("Failed to resolve repeated object (this should not happen)");throw a.source=s,a}}},sourceObjects:e}}export{m as anchorIsValid,f as anchorNames,w as createNodeAnchors,l as findNewAnchor};
//# sourceMappingURL=anchors.mjs.map