"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../internal-state.cjs"),t=require("../utils/is-function.cjs"),s=require("../lifecycle/lifecycle-handler.cjs"),n=require("../lifecycle/event-delegation.cjs"),i=require("../sinks/error-sink.cjs"),r=require("../sinks/termination-sink.cjs");const a=/\s*<!--\s*SINK:\s*(\w+)\s*-->\s*$/;let l=0;const c=(t,s)=>{const n=(e.waitingElementHanlders.get(t)||[]).concat(s);e.waitingElementHanlders.set(t,n)};exports.default=function e(o,...u){let p="";for(let f=0;f<o.length;f++){const d=o[f],b=p+d,g=b.lastIndexOf("<"),E=u[f],y=E?.value,h=($=d,/\s+on(?<event>\w+)=['"]?$/.exec($)?.groups?.event),x=b.match(/<\w+\s+[^>]*RESOLVE="(?<existingRef>[^"]+)"\s*[^>]*(?:\s*>\s*)?$/),j=x&&x.groups?x.groups.existingRef:void 0,k=j||"#REF"+l++;if(E)if(h){const e=t.isFunction(E)?E:t.isFunction(E.next)?E.next.bind(E):null,i=s.nonBubblingAttributes.has(h);e&&(i||n.delegateEvent(h),c(k,{handler:e,type:"event",eventName:h})),p=b+("mount"==h||i?k:"")+(j?"":`" RESOLVE="${k}`)}else if(E.sink)c(k,{handler:E,type:E.sink}),p+=d.replace(/<(\w+)\s*([^>]*)/,`<$1 ${j?"":`RESOLVE="${k}" `}$2`);else if("function"==typeof(E.subscribe??E.then)&&f<o.length-1||"object"==typeof E||E.sink){const e=o[f+1],t=/(?<attribute>[a-z0-9\-_]+)\=(?<quote>['"]?)(?<otherValues>[^"]*)$/.exec(b);if(t&&new RegExp(`^(?:[^>${t.groups?.quote}]*)${t.groups?.quote}`).test(e)){let e=t.groups?.attribute??"";const s="class"==e||"style"==e||"value"==e?e:e.indexOf("data")?"attribute":"dataset";"dataset"==s&&(e=e.replace(/^data-/,""));const n="";c(k,{handler:E,type:s,attribute:e}),p=(b+n).replace(/<(\w+)\s+([^>]+)$/,`<$1 ${j?"":`RESOLVE="${k}" `}$2`)}else if(/<\s*\S+(?:\s+[^=>]+(?:=(?:'[^']*'|"[^"]*"|\S+|[^>]+)))*(?:\s+\.\.\.)?$/.test(b.substring(g))&&/^(?:[^<]*>|\s+\.\.\.)/.test(e))p+=d.replace(/\.\.\.$/,""),c(k,{handler:E,type:"attributeset",attribute:E}),p=p.replace(/<\s*(\w+)\s+([^<]*)$/,`<$1 ${j?"":`RESOLVE="${k}" `}$2`);else if(/>\s*$/.test(d)&&/^\s*<\s*/.test(e)){let e,t;t=d.replace(a,""),e=RegExp.$1||E.sink||"innerHTML",c(k,{handler:y&&E.skip?E.skip(1):E,type:e,error:i.errorSink,..."collection"==e&&{attribute:E}||{},termination:r.terminationSink}),p+=j?t:t.replace(/\s*>\s*$/,` RESOLVE="${k}">`)+(y||"")}else/>\s*[^<]+$/m.test(d)&&/^\s*[^<]*\s*</m.test(e)?(c(k,{handler:E,type:"textContent"}),p=j?b:p+d.replace(/\s*>/,` RESOLVE="${k}">`)+k):p=b}else if(/\.\.\.$/.test(d))p+=d.substr(0,d.length-3).replace(/\.\.\.$/,""),t.isFunction(E.next)||t.isFunction(E.then)?c(k,{handler:E,type:"attributeset",attribute:E}):p+="string"==typeof E?E:Object.entries(E||{}).map((([e,t])=>`${e}="${t}"`)).join(" ");else if(Array.isArray(E))p=b+E.join("");else if("object"==typeof E){const[t,s]=Object.entries(E).reduce((([e,t],[s,n])=>[e.concat(s),t.concat(n)]),[[],[]]);p+=d+e(t,...s)}else p=b+E;else p=b}var $;return p};
//# sourceMappingURL=parser.cjs.map
