UNPKG

@forbespro/lead-agent

Version:
5 lines (4 loc) 2.29 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./index124.js"),C=require("./index98.js"),S=require("./index62.js"),k=require("./index74.js"),y={}.hasOwnProperty,M={};function N(t,n){const e=n||M,r=new Map,u=new Map,h=new Map,d={...C.handlers,...e.handlers},l={all:m,applyData:P,definitionById:r,footnoteById:u,footnoteCounts:h,footnoteOrder:[],handlers:d,one:v,options:e,patch:O,wrap:x};return S.visit(t,function(i){if(i.type==="definition"||i.type==="footnoteDefinition"){const o=i.type==="definition"?r:u,s=String(i.identifier).toUpperCase();o.has(s)||o.set(s,i)}}),l;function v(i,o){const s=i.type,c=l.handlers[s];if(y.call(l.handlers,s)&&c)return c(l,i,o);if(l.options.passThrough&&l.options.passThrough.includes(s)){if("children"in i){const{children:p,...A}=i,w=f.default(A);return w.children=l.all(i),w}return f.default(i)}return(l.options.unknownHandler||b)(l,i,o)}function m(i){const o=[];if("children"in i){const s=i.children;let c=-1;for(;++c<s.length;){const a=l.one(s[c],i);if(a){if(c&&s[c-1].type==="break"&&(!Array.isArray(a)&&a.type==="text"&&(a.value=g(a.value)),!Array.isArray(a)&&a.type==="element")){const p=a.children[0];p&&p.type==="text"&&(p.value=g(p.value))}Array.isArray(a)?o.push(...a):o.push(a)}}}return o}}function O(t,n){t.position&&(n.position=k.position(t))}function P(t,n){let e=n;if(t&&t.data){const r=t.data.hName,u=t.data.hChildren,h=t.data.hProperties;if(typeof r=="string")if(e.type==="element")e.tagName=r;else{const d="children"in e?e.children:[e];e={type:"element",tagName:r,properties:{},children:d}}e.type==="element"&&h&&Object.assign(e.properties,f.default(h)),"children"in e&&e.children&&u!==null&&u!==void 0&&(e.children=u)}return e}function b(t,n){const e=n.data||{},r="value"in n&&!(y.call(e,"hProperties")||y.call(e,"hChildren"))?{type:"text",value:n.value}:{type:"element",tagName:"div",properties:{},children:t.all(n)};return t.patch(n,r),t.applyData(n,r)}function x(t,n){const e=[];let r=-1;for(n&&e.push({type:"text",value:` `});++r<t.length;)r&&e.push({type:"text",value:` `}),e.push(t[r]);return n&&t.length>0&&e.push({type:"text",value:` `}),e}function g(t){let n=0,e=t.charCodeAt(n);for(;e===9||e===32;)n++,e=t.charCodeAt(n);return t.slice(n)}exports.createState=N;exports.wrap=x;