@walkeros/web-source-browser 4.7.2-next-1791147139360 → 4.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{isString as e}from"@walkeros/core";import{throttle as t,tryCatch as n}from"@walkeros/core";import{Const as r}from"@walkeros/collector";import{getAttribute as o}from"@walkeros/web-core";import{assign as s,castValue as i,isArray as c,trim as l}from"@walkeros/core";import{Const as a}from"@walkeros/collector";import{getAttribute as u,splitAttribute as f,splitKeyVal as d}from"@walkeros/web-core";function m(e,t,n=!0){return e+(t=null!=t?(n?"-":"")+t:"")}function h(e,t,n,r=!0){const o=u(t,m(e,n,r))||"";return f(o).reduce((e,n)=>{let[r,o]=d(n);if(!r)return e;if(o.startsWith("#")){o=o.slice(1);try{let e=t[o];e||"selected"!==o||(e=t.options[t.selectedIndex].text),o=String(e)}catch(e){o=""}}return r.endsWith("[]")?(r=r.slice(0,-2),c(e[r])||(e[r]=[]),e[r].push(i(o))):e[r]=i(o),e},{})}function g(e,t=a.Commands.Prefix){var n;const r=e;if(!r)return[];let o=[];const s=a.Commands.Action,i=`[${m(t,s,!1)}]`,c=e=>{Object.keys(h(t,e,s,!1)).forEach(n=>{o=o.concat(p(e,n,t))})};return r!==(r.ownerDocument||r)&&(null==(n=r.matches)?void 0:n.call(r,i))&&c(r),j(r,i,c),o}function p(e,t,n=a.Commands.Prefix){const r=[],{actions:o,nearestOnly:s}=function(e,t,n){let r=t;for(;r;){const t=u(r,m(e,a.Commands.Actions,!1));if(t){const e=y(t);if(e[n])return{actions:e[n],nearestOnly:!1}}const o=u(r,m(e,a.Commands.Action,!1));if(o){const e=y(o);if(e[n]||"click"!==n)return{actions:e[n]||[],nearestOnly:!0}}r=O(e,r)}return{actions:[],nearestOnly:!1}}(n,e,t);return o.length?(o.forEach(o=>{const i=f(o.actionParams||"",",").reduce((e,t)=>(e[l(t)]=!0,e),{}),c=w(n,e,i,s);if(!c.length){const t="page",r=`[${m(n,t)}]`,[o,s]=S(e,r,n,t);c.push({entity:t,data:o,nested:[],context:s})}c.forEach(e=>{var n;r.push({entity:e.entity,action:o.action,data:e.data,trigger:t,context:e.context,nested:null!=(n=e.nested)?n:[]})})}),r):r}function b(e=a.Commands.Prefix,t){if(!t)return{};const n=m(e,a.Commands.Globals,!1);let r={};return $(t,`[${n}]`,t=>{r=s(r,h(e,t,a.Commands.Globals,!1))}),r}function v(e=a.Commands.Prefix,t){if(!t)return{};const n=m(e,a.Commands.User,!1);let r={};return $(t,`[${n}]`,t=>{r=s(r,h(e,t,a.Commands.User,!1))}),r}function y(e){const t={};return f(e).forEach(e=>{const[n,r]=d(e),[o,s]=x(n);if(!o)return;let[i,c]=x(r||"");i=i||o,t[o]||(t[o]=[]),t[o].push({trigger:o,triggerParams:s,action:i,actionParams:c})}),t}function w(e,t,n,r=!1){const o=[];let s=t;for(n=0!==Object.keys(n||{}).length?n:void 0;s;){const i=k(e,s,t,n);if(i&&(o.push(i),r))break;s=O(e,s)}return o}var E=/^[\w\u0080-\uffff-]+$/;function k(e,t,n,r){const o=u(t,m(e));if(!o||!E.test(o)||r&&!r[o])return null;const i=[t],c=`[${m(e,o)}],[${m(e,"")}]`,l=m(e,a.Commands.Link,!1);let f={};const d=[],[g,p]=S(n||t,c,e,o,!0);j(t,`[${l}]`,n=>{const[r,o]=L(n,l);"parent"===o&&j(t.ownerDocument.body,`[${l}]`,t=>{const[n,o]=L(t,l);if(n!==r||"child"!==o)return;i.push(t);const s=k(e,t);s&&d.push(s)})});const b=[];i.forEach(e=>{e.matches(c)&&b.push(e),j(e,c,e=>b.push(e))});let v={};return b.forEach(t=>{v=s(v,h(e,t,"")),f=s(f,h(e,t,o))}),f=s(s(v,f),g),i.forEach(t=>{j(t,`[${m(e)}]`,t=>{const n=k(e,t);n&&d.push(n)})}),{entity:o,data:f,context:p,nested:d}}function O(e,t){const n=m(e,a.Commands.Link,!1);if(t.matches(`[${n}]`)){const[e,r]=L(t,n);if("child"===r){const r=t.ownerDocument;let o=null;return $(r,`[${n}]`,t=>{const[r,s]=L(t,n);o||r!==e||"parent"!==s||(o=t)}),o}}const r=t.ownerDocument.defaultView;return!t.parentElement&&t.getRootNode&&t.getRootNode()instanceof r.ShadowRoot?t.getRootNode().host:t.parentElement}function S(e,t,n,r,o=!1){let i={};const c={};let l=e;const u=`[${m(n,a.Commands.Context,!1)}]`,f=a.Commands.Scoped,d=`[${m(n,f,!1)}]`;let g=0;for(;l;)o&&f&&l.matches(d)&&(i=s(h(n,l,f,!1),i)),l.matches(t)&&(i=s(h(n,l,""),i),i=s(h(n,l,r),i)),l.matches(u)&&(Object.entries(h(n,l,a.Commands.Context,!1)).forEach(([e,t])=>{t&&!c[e]&&(c[e]=[t,g])}),++g),l=O(n,l);return[i,c]}function $(e,t,n){e.querySelectorAll(t).forEach(n)}function j(e,t,n){e.querySelectorAll(t).forEach(n);e instanceof(e.ownerDocument||e).defaultView.Element&&e.shadowRoot&&j(e.shadowRoot,t,n),e.querySelectorAll("*").forEach(e=>{e.shadowRoot&&j(e.shadowRoot,t,n)})}function L(e,t){return d(u(e,t))}function x(e){const[t,n]=e.split("(",2);return[t,n?n.slice(0,-1):""]}import{tryCatch as C}from"@walkeros/core";import{isVisible as R}from"@walkeros/web-core";var A=Array.from({length:101},(e,t)=>t/100);function I(e){return e.ownerDocument||e}function P(e,t){const n=t.defaultView;if(n&&n.IntersectionObserver)return C(()=>new n.IntersectionObserver(n=>{n.forEach(n=>function(e,t,n){const r=n.target,o=e.visibility.get(t);if(!o)return;const s=r.ownerDocument.defaultView;if(!s)return;const i=o.configs.get(r);if(!i||!i.length)return;const c=o.timers.get(r);if(function(e,t){if(!e.isIntersecting)return!1;const n=e.boundingClientRect;if(n.width<=0||n.height<=0)return!1;const r=e.rootBounds?e.rootBounds.width:t.innerWidth,o=e.rootBounds?e.rootBounds.height:t.innerHeight;if(r<=0||o<=0)return!1;const s=e.intersectionRect,i=.5*Math.min(n.width,r),c=.5*Math.min(n.height,o);return s.width>=i&&s.height>=c}(n,s)){if(i.every(e=>e.blocked))return;if(!c){const n=s.setTimeout(()=>{T(e,t,r)},o.duration);o.timers.set(r,n)}return}c&&(clearTimeout(c),o.timers.delete(r));i.forEach(e=>{e.multiple&&(e.blocked=!1)})}(e,t,n))},{rootMargin:"0px",threshold:A}),()=>{})()}async function T(e,t,n,r=!1){const o=e.visibility.get(t);if(!o)return;o.timers.delete(n);const s=t.defaultView;if(!s)return;if("visible"!==t.visibilityState)return void o.timers.set(n,s.setTimeout(()=>{T(e,t,n,!0)},o.duration));if(r)return void o.timers.set(n,s.setTimeout(()=>{T(e,t,n)},o.duration));if(!R(n,s,t))return void o.timers.set(n,s.setTimeout(()=>{T(e,t,n)},o.duration));const i=o.configs.get(n);if(!i)return;const c=i.filter(e=>!e.blocked);if(!c.length)return;c.forEach(e=>{e.multiple&&(e.blocked=!0)});const l=i.filter(e=>e.multiple);l.length?o.configs.set(n,l):D(e,t,n),await Promise.all(c.map(e=>Z(e.context,n,e.trigger)))}function D(e,t,n){var r,o;const s=e.visibility.get(I(t));if(!s)return;null==(r=s.observer)||r.unobserve(n),null==(o=s.resizeObserver)||o.unobserve(n),s.configs.delete(n),s.zeroArea.delete(n);const i=s.timers.get(n);i&&(clearTimeout(i),s.timers.delete(n))}function V(e,t){const n=t.defaultView;if(n&&n.ResizeObserver)return C(()=>new n.ResizeObserver(n=>{const r=e.visibility.get(t);(null==r?void 0:r.observer)&&n.forEach(e=>{var t,n;const o=e.target,{width:s,height:i}=e.contentRect;s<=0||i<=0?r.zeroArea.add(o):r.zeroArea.has(o)&&(r.zeroArea.delete(o),null==(t=r.observer)||t.unobserve(o),null==(n=r.observer)||n.observe(o))})}),()=>{})()}function M(e,t,n={multiple:!1}){var r,o,s;const i=e.settings.scope;if(!i)return;const c=e.registry.visibility.get(I(i));if(!(null==c?void 0:c.observer)||!t)return;const l=null!=(r=n.multiple)&&r,a=null!=(o=c.configs.get(t))?o:[],u=a.length>0,f=l?K.Visible:K.Impression,d={multiple:l,blocked:!1,context:e,trigger:f},m=a.findIndex(e=>e.trigger===f);if(m>=0?a[m]=d:a.push(d),c.configs.set(t,a),u)return;const h=t.getBoundingClientRect();(h.width<=0||h.height<=0)&&c.zeroArea.add(t),c.observer.observe(t),null==(s=c.resizeObserver)||s.observe(t)}import{isString as H,isObject as W,isElementOrDocument as z}from"@walkeros/core";import{createPushResult as N}from"@walkeros/collector";function q(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof Element&&e instanceof Element)return!0;if("undefined"!=typeof Document&&e instanceof Document)return!0;if("undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot)return!0;if("nodeType"in e){const t=e.nodeType;return 1===t||9===t||11===t}return!1}function B(e,t,n,r,o,s,i){var c;const{elb:l,push:a,settings:u}=e,f=null!=(c=e.root)?c:u.scope;if(H(t)&&t.startsWith("walker ")){if("walker init"===t&&e.initScope){const t=function(e,t){if(q(e))return[e];if(Array.isArray(e)){const t=[];for(const n of e)q(n)&&t.push(n);return t}if(void 0===e){const e=t.scope;if(q(e))return[e];if(void 0!==globalThis.document)return[globalThis.document]}return[]}(n,u);for(const n of t)e.initScope({...e,settings:{...u,scope:n}});return Promise.resolve(N({ok:!0}))}return l(t,n)}if(W(t)){const n=t;if(!n.source&&u.scope){const t=u.scope.ownerDocument||u.scope,r=t.defaultView;n.source=U(r,t,e.href)}return!n.globals&&f&&(n.globals=G(f)?b(u.prefix,f):{}),a(n)}const[d]=String(W(t)?t.name:t).split(" ");let m,h=W(n)?n:{},g={},p=!1;if(z(n)&&(m=n,p=!0),z(o)?m=o:W(o)&&Object.keys(o).length&&(g=o),m){const e=w(u.prefix||"data-elb",m).find(e=>e.entity===d);e&&(p&&(h=e.data),e.context&&(g=e.context))}const v=u.scope?u.scope.ownerDocument||u.scope:void 0,y=null==v?void 0:v.defaultView;"page"===d&&y&&(h.id=h.id||(e.href?new URL(e.href):y.location).pathname);const E=f&&G(f)?b(u.prefix,f):{};return a({name:String(t||""),data:h,context:g,globals:E,nested:s,custom:i,trigger:H(r)?r:"",source:y&&v?U(y,v,e.href):void 0})}function U(e,t,n){return{type:"browser",platform:"web",url:n||e.location.href,referrer:t.referrer}}function G(e){return 11!==e.nodeType}function _(e){var t,n;return new(null!=(n=null==(t=(e.ownerDocument||e).defaultView)?void 0:t.AbortController)?n:AbortController)}function F(e,t){return e.elements.has(t)}function J(e,t){var n;const r=e.elements.get(t);if(!r)return;const o=e.scopes.get(r.scope);r.intervalIds.forEach(e=>{if(clearInterval(e),o){const t=o.intervalIds.indexOf(e);-1!==t&&o.intervalIds.splice(t,1)}}),r.timeoutIds.forEach(e=>{if(clearTimeout(e),o){const t=o.timeoutIds.indexOf(e);-1!==t&&o.timeoutIds.splice(t,1)}}),null==(n=r.hoverAbort)||n.abort(),r.observed&&(D(e,r.scope,t),null==o||o.observed.delete(t)),r.scroll&&o&&(o.scrollElements=o.scrollElements.filter(([e])=>e!==t)),null==o||o.registered.delete(t),e.elements.delete(t)}var K={Click:"click",Custom:"custom",Hover:"hover",Load:"load",Pulse:"pulse",Scroll:"scroll",Submit:"submit",Impression:"impression",Visible:"visible",Wait:"wait"};function Q(e,t){t.scope&&function(e){const{scope:t,capture:r}=e.settings;if(!t)return;if(e.registry.destroyed)return;const{registry:o}=e;o.root&&o.root.abort();o.root=_(t);const{signal:s}=o.root;t.addEventListener("click",n(function(t){oe.call(this,e,t)}),{signal:s,capture:r}),t.addEventListener("submit",n(function(t){se.call(this,e,t)}),{signal:s,capture:r})}(e)}function X(e){const{registry:t}=e;t.destroyed=!0,t.root&&(t.root.abort(),t.root=void 0),t.scopes.forEach((e,n)=>{e.abort.abort(),e.mutationObservers.forEach(e=>e.disconnect()),e.intervalIds.forEach(e=>clearInterval(e)),e.timeoutIds.forEach(e=>clearTimeout(e)),e.observed.forEach(e=>D(t,n,e)),[...e.registered].forEach(e=>J(t,e))}),t.scopes.forEach((e,n)=>{!function(e,t){var n,r;if(!t)return;const o=I(t),s=e.visibility.get(o);s&&(null==(n=s.observer)||n.disconnect(),null==(r=s.resizeObserver)||r.disconnect(),e.visibility.delete(o))}(t,n)}),t.scopes.clear()}function Y(e){const t=e.settings.scope;if(!t)return;if(e.registry.destroyed)return;const o=function(e,t){const n=e.scopes.get(t);n&&(n.abort.abort(),n.intervalIds.forEach(e=>clearInterval(e)),n.timeoutIds.forEach(e=>clearTimeout(e)),n.observed.forEach(n=>D(e,t,n)),[...n.registered].forEach(t=>J(e,t)),n.mutationObservers.forEach(e=>e.disconnect()));const r={abort:_(t),intervalIds:[],timeoutIds:[],scrollElements:[],observed:new Set,registered:new Set,mutationObservers:[]};return e.scopes.set(t,r),r}(e.registry,t);!function(e,t,n=1e3){const r=I(t);if(e.visibility.has(r))return;const o={observer:P(e,r),resizeObserver:V(e,r),timers:new WeakMap,duration:n,configs:new WeakMap,zeroArea:new WeakSet};e.visibility.set(r,o)}(e.registry,t,1e3);const s=m(e.settings.prefix,r.Commands.Action,!1),i=t.ownerDocument||t,c=i.defaultView;t!==i&&c&&t instanceof c.HTMLElement&&F(e.registry,t)&&J(e.registry,t),j(t,`[${s}]`,t=>{c&&t instanceof c.HTMLElement&&F(e.registry,t)&&J(e.registry,t)}),t!==i&&c&&t instanceof c.Element&&ee(e,t,s,o,t),j(t,`[${s}]`,n=>{ee(e,n,s,o,t)}),o.scrollElements.length&&ie(e,t,o),e.settings.history&&t===i?function(e,t,r,o){const s=t.defaultView;if(!s||!s.MutationObserver)return;let i=[],c=[],l=!1;const a=()=>{l=!1;const n=i,r=c;i=[],c=[];const s=e.registry.scopes.get(t);s&&(r.forEach(t=>{t.isConnected||te(e,t)}),n.forEach(n=>{n.isConnected&&ne(e,n,o,s,t)}),s.scrollElements.length&&ie(e,t,s))},u=new s.MutationObserver(n(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{1===e.nodeType&&i.push(e)}),e.removedNodes.forEach(e=>{1===e.nodeType&&c.push(e)})}),l||!i.length&&!c.length||(l=!0,setTimeout(n(a),0))}));u.observe(t,{childList:!0,subtree:!0}),r.mutationObservers.push(u)}(e,i,o,s):function(e,t,r,o){const s=t.ownerDocument||t,i=s.defaultView;if(!i||!i.MutationObserver)return;const c=m(e.settings.prefix,"observe",!1),l=[];t!==s&&t instanceof i.Element&&t.matches(`[${c}]`)&&l.push(t);j(t,`[${c}]`,e=>l.push(e)),l.forEach(s=>{if(l.some(e=>e!==s&&e.contains(s)))return;const c=new i.MutationObserver(n(n=>{const r=e.registry.scopes.get(t);r&&n.forEach(n=>{n.addedNodes.forEach(n=>ne(e,n,o,r,t)),r.scrollElements.length&&ie(e,t,r),n.removedNodes.forEach(t=>te(e,t))})}));c.observe(s,{childList:!0,subtree:!0}),r.mutationObservers.push(c)})}(e,t,o,s)}async function Z(e,t,n){const r=p(t,n,e.settings.prefix);return Promise.all(r.map(t=>B(e,{name:`${t.entity} ${t.action}`,...t,trigger:n})))}function ee(e,t,r,s,i){var c;if(1!==t.nodeType)return;const l=null==(c=t.ownerDocument)?void 0:c.defaultView;if(!(l&&t instanceof l.HTMLElement))return;if(F(e.registry,t))return;if(!o(t,r))return;const a={scope:i,intervalIds:[],timeoutIds:[],scroll:!1,observed:!1};return function(e,t,r,s,i){const c=o(t,r);if(!c)return;Object.values(y(c)).forEach(r=>r.forEach(r=>{switch(r.trigger){case K.Hover:!function(e,t,r){r.hoverAbort||(r.hoverAbort=_(t));t.addEventListener("mouseenter",n(function(t){const n=re(t);n&&Z(e,n,K.Hover)}),{signal:r.hoverAbort.signal})}(e,t,i);break;case K.Load:!function(e,t){Z(e,t,K.Load)}(e,t);break;case K.Pulse:!function(e,t,n,r,o=""){const s=t.ownerDocument,i=setInterval(()=>{s.hidden||Z(e,t,K.Pulse)},parseInt(o||"")||15e3);n.intervalIds.push(i),r.intervalIds.push(i)}(e,t,s,i,r.triggerParams);break;case K.Scroll:!function(e,t,n,r=""){const o=parseInt(r||"")||50;if(o<0||o>100)return;t.scrollElements.push([e,o]),n.scroll=!0}(t,s,i,r.triggerParams);break;case K.Impression:M(e,t),s.observed.add(t),i.observed=!0;break;case K.Visible:M(e,t,{multiple:!0}),s.observed.add(t),i.observed=!0;break;case K.Wait:!function(e,t,n,r,o=""){const s=setTimeout(()=>Z(e,t,K.Wait),parseInt(o||"")||15e3);n.timeoutIds.push(s),r.timeoutIds.push(s)}(e,t,s,i,r.triggerParams)}}))}(e,t,r,s,a),function(e,t,n,r){if(e.elements.has(n))return!1;const o=e.scopes.get(t);!!o&&(r.scope=t,o.registered.add(n),e.elements.set(n,r))}(e.registry,i,t,a),a}function te(e,t){var n;if(1!==t.nodeType)return;const o=null==(n=t.ownerDocument)?void 0:n.defaultView;if(!(o&&t instanceof o.HTMLElement))return;const{registry:s}=e,i=m(e.settings.prefix,r.Commands.Action,!1);F(s,t)&&J(s,t),j(t,`[${i}]`,e=>{e instanceof o.HTMLElement&&F(s,e)&&J(s,e)})}function ne(e,t,n,r,o){var s;const i=null==(s=t.ownerDocument)?void 0:s.defaultView;i&&t instanceof i.HTMLElement&&(ee(e,t,n,r,o),j(t,`[${n}]`,t=>{ee(e,t,n,r,o)}))}function re(e){var t;const n=null==(t=e.composedPath)?void 0:t.call(e),r=(null==n?void 0:n.length)?n[0]:e.target;if(r&&"object"==typeof r&&"tagName"in r)return r}function oe(e,t){const n=re(t);n&&Z(e,n,K.Click)}function se(e,t){const n=re(t);n&&Z(e,n,K.Submit)}function ie(e,n,r){const o=n.ownerDocument||n,s=o.defaultView,i=(e,t)=>e.filter(([e,n])=>{const r=e.getBoundingClientRect();if(s.innerHeight<r.top)return!0;const o=r.height||e.clientHeight;return!(100*(1-(r.top+o-s.innerHeight)/(o||1))>=n)||(Z(t,e,K.Scroll),!1)});if(!r.scrollListener){r.scrollListener=t(function(){r.scrollElements=i.call(n,r.scrollElements,e)});(n instanceof s.ShadowRoot?o:n).addEventListener("scroll",r.scrollListener,{signal:r.abort.signal})}}import{isString as ce,isObject as le,tryCatch as ae}from"@walkeros/core";import{createPushResult as ue}from"@walkeros/collector";import{isObject as fe,tryCatch as de}from"@walkeros/core";var me=Symbol.for("@walkeros/web-source-browser:owner"),he=e=>null!==e&&("object"==typeof e||"function"==typeof e),ge=e=>he(e)&&"function"==typeof Reflect.get(e,"get")&&"function"==typeof Reflect.get(e,"set")&&"function"==typeof Reflect.get(e,"has");function pe(e,t){return de(()=>{Object.defineProperty(e,me,{value:t,writable:!0,enumerable:!1,configurable:!0})})(),e}function be(e){if(!he(e))return;const t=Reflect.get(e,me);return(e=>fe(e)&&ge(e.scopes)&&ge(e.elements))(t)?t:void 0}function ve(e){Reflect.deleteProperty(e,me)}var ye=Symbol.for("@walkeros/web-source-browser:elbLayer-drained"),we=e=>{const t=Reflect.get(e,ye);if(le(n=t)&&"number"==typeof n.commands&&"number"==typeof n.events)return t;var n;const r={commands:0,events:0};return ae(()=>{Object.defineProperty(e,ye,{value:r,writable:!0,enumerable:!1,configurable:!0})})(),r};function Ee(e,t={}){const n=t.name||"elbLayer",r=t.window,o=t.logger,s=()=>ue({ok:!0}),i=()=>({intake:()=>Promise.resolve(s()),start:()=>{},enqueue:e=>Promise.resolve().then(()=>e()),destroy:()=>{}});if(!r)return i();const c=Reflect.get(r,n);let l;Array.isArray(c)?l=c:(l=[],Reflect.set(r,n,l));const{registry:a}=e,u=be(l);if(u&&u!==a)return null==o||o.error(`elbLayer "${n}" is already adopted by another source`),i();pe(l,a);const f=we(l);let d=!1,m=f.commands,h=f.events,g=Promise.resolve(s()),p=Promise.resolve();const b=()=>{f.commands=m,f.events=h},v=async t=>{try{return await(t=>{if(Array.isArray(t)){const[n,...r]=t;return B(e,n,...r)}return B(e,t)})(t)}catch(e){return null==o||o.warn("elbLayer entry failed",{error:e,item:t}),ue({ok:!1})}},y=e=>{const t=e[0];return ce(t)&&t.startsWith("walker ")},w=(e,t)=>{if(!d){if(y(e)){if(t<m)return Promise.resolve(s());const n=g.then(()=>v(e));return g=n,m=t+1,b(),n}return Promise.resolve(s())}const n=p.then(()=>v(e));return p=n,m=t+1,h=t+1,b(),n},E=[],k=e=>{const t=ke(e),n=l.length,r=ae(()=>(l[n]=e,!0))();return t?r?w(t,n):(e=>{if(!d){if(y(e)){const t=g.then(()=>v(e));return g=t,t}return E.push(e),Promise.resolve(s())}const t=p.then(()=>v(e));return p=t,t})(t):Promise.resolve(s())},O=(...e)=>{for(const t of e)k(t);return l.length};ae(()=>{l.push=O})();const S=l.length;for(let e=0;e<S;e++){const t=ke(l[e]);t&&w(t,e)}return{intake:e=>k(e),start:()=>{if(!d){d=!0,p=g;for(let e=h;e<l.length;e++){const t=ke(l[e]);if(!t)continue;if(y(t))continue;const n=t;p=p.then(()=>v(n))}E.splice(0,E.length).forEach(e=>{p=p.then(()=>v(e))}),h=l.length,m=l.length,b()}},enqueue:e=>{const t=p.then(()=>e());return p=t.then(()=>{},()=>{}),t},destroy:()=>{l.push===O&&Reflect.deleteProperty(l,"push"),ve(l),d=!1,E.length=0,m=0,h=0,g=Promise.resolve(s()),p=Promise.resolve()}}}function ke(e){const t=null!=(n=e)&&"object"==typeof n&&"[object Arguments]"===Object.prototype.toString.call(n)?[...Array.from(e)]:function(e){return null!=e&&"object"==typeof e&&"length"in e&&"number"==typeof e.length}(e)?Array.from(e):[e];var n;if(!Array.isArray(t)||0===t.length)return null;if(1===t.length&&!t[0])return null;const r=t[0];return le(r)&&0===Object.keys(r).length||!le(r)&&ce(r)&&""===r.trim()?null:t}import{isBoolean as Oe,isObject as Se,isString as $e}from"@walkeros/core";var je={};import{isString as Le,isDefined as xe}from"@walkeros/core";function Ce(e={}){const t=e.prefix||"data-elb";return function(e){let n,r=e;const o={},s={},i={},c={},l={},a={},u={};function f(e){return Object.entries(e).map(([e,t])=>`${function(e){return e.replace(/[\\;:']/g,"\\$&")}(e)}:${function(e){return xe(e)&&null!==e?String(e).replace(/[\\;']/g,"\\$&"):"undefined"}(t)}`).join(";")}const d={entity:e=>(n=e,r=e,d),data(e,t){const n=null!=r?r:"";return o[n]||(o[n]={}),Le(e)?o[n][e]=t:Object.assign(o[n],e),d},scoped:(e,t)=>(Le(e)?s[e]=t:Object.assign(s,e),d),action(e,t){if(Le(e))if(xe(t))i[e]=t;else if(e.includes(":")){const[t,n]=e.split(":",2);i[t]=n}else i[e]=e;else Object.assign(i,e);return d},actions(e,t){if(Le(e))if(xe(t))c[e]=t;else if(e.includes(":")){const[t,n]=e.split(":",2);c[t]=n}else c[e]=e;else Object.assign(c,e);return d},context:(e,t)=>(Le(e)?l[e]=t:Object.assign(l,e),d),globals:(e,t)=>(Le(e)?a[e]=t:Object.assign(a,e),d),link:(e,t)=>(Le(e)?u[e]=t:Object.assign(u,e),d),get(){const e={};return n&&(e[t]=n),Object.entries(o).forEach(([n,r])=>{if(Object.keys(r).length>0){e[n?`${t}-${n}`:`${t}-`]=f(r)}}),Object.keys(s).length>0&&(e[`${t}_`]=f(s)),Object.keys(i).length>0&&(e[`${t}action`]=f(i)),Object.keys(c).length>0&&(e[`${t}actions`]=f(c)),Object.keys(l).length>0&&(e[`${t}context`]=f(l)),Object.keys(a).length>0&&(e[`${t}globals`]=f(a)),Object.keys(u).length>0&&(e[`${t}link`]=f(u)),e}};return d}}function Re(){}function Ae(){}var Ie=async t=>{const{config:n,env:r,logger:o}=t,{elb:s,push:i,command:c,window:l,document:a}=r,u=(null==n?void 0:n.settings)||{},f=l||(void 0!==globalThis.window?globalThis.window:void 0),d=a||(void 0!==globalThis.document?globalThis.document:void 0),h=function(e={},t){return{prefix:"data-elb",pageview:!0,capture:!0,history:!1,elb:"elb",elbLayer:"elbLayer",scope:t||void 0,...e}}(u,d),g={settings:h},p={scopes:new Map,elements:new WeakMap,visibility:new WeakMap,destroyed:!1},b={elb:s,push:i,settings:h,root:h.scope,registry:p,logger:o,initScope:Y};let y,w,E,k=!1;const O=[];let $;const j=(e,t)=>{if(!e.pageview)return;const[n,r]=function(e,t,n){const r=t.ownerDocument||t,o=r.defaultView,s=n?new URL(n):o.location,i="page",c="body"in t?t.body:t,[l,a]=S(c,`[${m(e,i)}]`,e,i);return l.domain=s.hostname,l.title=r.title,l.referrer=r.referrer,s.search&&(l.search=s.search),s.hash&&(l.hash=s.hash),[l,a]}(e.prefix||"data-elb",e.scope,t);return $&&(n.referrer=$.split("#")[0]),$=t||(null==f?void 0:f.location.href),B({...b,href:t},"page view",n,"load",r)},L=e=>{const t=v(e.prefix||"data-elb",e.scope);if(Object.keys(t).length)return B(b,"walker user",t)},x=(...e)=>{const[t,n,r,o,s,i]=e;return B(b,t,n,r,o,s,i)};return{type:"browser",config:g,push:x,on:async e=>{if("run"===e)if(d&&f&&!p.destroyed){h.history&&!E&&(E=function(e,t){const n=e.history,r=n.pushState,o=n.replaceState;let s=e.location.pathname,i=e.location.search,c=!0;const l=n=>{if(!c)return;const{pathname:r,search:o,href:l}=e.location,a=r!==s||!n&&o!==i;s=r,i=o,a&&t(l)},a=function(...e){r.apply(n,e),l(!1)},u=function(...e){o.apply(n,e),l(!0)},f=()=>l(!1);return n.pushState=a,n.replaceState=u,e.addEventListener("popstate",f,{capture:!0}),()=>{c=!1,n.pushState===a&&(n.pushState=r),n.replaceState===u&&(n.replaceState=o),e.removeEventListener("popstate",f,{capture:!0})}}(f,e=>{O.push(e),s("walker run").catch(()=>{})}));const e=O.shift();e||function(e,t){t.scope&&Y(e)}(b,h),y?(y.start(),y.enqueue(()=>L(h)).catch(()=>{}),y.enqueue(()=>j(h,e)).catch(()=>{})):(await L(h),j(h,e))}},init:async()=>{if(!f||!d)return;if(k)return;k=!0;const t=e(h.elbLayer)?h.elbLayer:"elbLayer",n=!1!==h.elbLayer?Ee(b,{name:t,window:f,logger:o}):void 0,r=Reflect.get(f,t),s=n&&be(r)===p?n:void 0;if(y=s,await async function(e,t,n){const r=()=>{t.registry.destroyed||e(t,n)},o=n.scope;if(!o)return void r();const s=o.ownerDocument||o;if("loading"!==s.readyState)return void r();const{registry:i}=t;i.root||(i.root=_(o)),s.addEventListener("DOMContentLoaded",r,{signal:i.root.signal})}(Q,b,h),e(h.elb)&&h.elb){const e=be(Reflect.get(f,h.elb));if(e&&e!==p)null==o||o.error(`elb "${h.elb}" is already installed by another source`);else{const e=s?(...e)=>s.intake(e):x;w=pe(e,p),Reflect.set(f,h.elb,e)}}},destroy:async()=>{X(b),null==E||E(),E=void 0,O.length=0,null==y||y.destroy(),f&&e(h.elb)&&h.elb&&Reflect.get(f,h.elb)===w&&Reflect.deleteProperty(f,h.elb),w&&ve(w),y=void 0,w=void 0}}},Pe=Ie;export{je as SourceBrowser,Ae as __readInstanceGuardForTests,Re as __resetInstanceCountForTests,Ce as createTagger,Pe as default,g as getAllEvents,m as getElbAttributeName,h as getElbValues,p as getEvents,b as getGlobals,v as getUser,Ie as sourceBrowser};//# sourceMappingURL=index.mjs.map
1
+ import{isString as e}from"@walkeros/core";import{throttle as t,tryCatch as n}from"@walkeros/core";import{Const as r}from"@walkeros/collector";import{getAttribute as o}from"@walkeros/web-core";import{assign as s,castValue as i,isArray as c,trim as l}from"@walkeros/core";import{Const as a}from"@walkeros/collector";import{getAttribute as u,splitAttribute as f,splitKeyVal as d}from"@walkeros/web-core";function m(e,t,n=!0){return e+(t=null!=t?(n?"-":"")+t:"")}function h(e,t,n,r=!0){const o=u(t,m(e,n,r))||"";return f(o).reduce((e,n)=>{let[r,o]=d(n);if(!r)return e;if(o.startsWith("#")){o=o.slice(1);try{let e=t[o];e||"selected"!==o||(e=t.options[t.selectedIndex].text),o=String(e)}catch(e){o=""}}return r.endsWith("[]")?(r=r.slice(0,-2),c(e[r])||(e[r]=[]),e[r].push(i(o))):e[r]=i(o),e},{})}function g(e,t=a.Commands.Prefix){var n;const r=e;if(!r)return[];let o=[];const s=a.Commands.Action,i=`[${m(t,s,!1)}]`,c=e=>{Object.keys(h(t,e,s,!1)).forEach(n=>{o=o.concat(p(e,n,t))})};return r!==(r.ownerDocument||r)&&(null==(n=r.matches)?void 0:n.call(r,i))&&c(r),j(r,i,c),o}function p(e,t,n=a.Commands.Prefix){const r=[],{actions:o,nearestOnly:s}=function(e,t,n){let r=t;for(;r;){const t=u(r,m(e,a.Commands.Actions,!1));if(t){const e=y(t);if(e[n])return{actions:e[n],nearestOnly:!1}}const o=u(r,m(e,a.Commands.Action,!1));if(o){const e=y(o);if(e[n]||"click"!==n)return{actions:e[n]||[],nearestOnly:!0}}r=O(e,r)}return{actions:[],nearestOnly:!1}}(n,e,t);return o.length?(o.forEach(o=>{const i=f(o.actionParams||"",",").reduce((e,t)=>(e[l(t)]=!0,e),{}),c=w(n,e,i,s);if(!c.length){const t="page",r=`[${m(n,t)}]`,[o,s]=$(e,r,n,t);c.push({entity:t,data:o,nested:[],context:s})}c.forEach(e=>{var n;r.push({entity:e.entity,action:o.action,data:e.data,trigger:t,context:e.context,nested:null!=(n=e.nested)?n:[]})})}),r):r}function b(e=a.Commands.Prefix,t){if(!t)return{};const n=m(e,a.Commands.Globals,!1);let r={};return S(t,`[${n}]`,t=>{r=s(r,h(e,t,a.Commands.Globals,!1))}),r}function v(e=a.Commands.Prefix,t){if(!t)return{};const n=m(e,a.Commands.User,!1);let r={};return S(t,`[${n}]`,t=>{r=s(r,h(e,t,a.Commands.User,!1))}),r}function y(e){const t={};return f(e).forEach(e=>{const[n,r]=d(e),[o,s]=x(n);if(!o)return;let[i,c]=x(r||"");i=i||o,t[o]||(t[o]=[]),t[o].push({trigger:o,triggerParams:s,action:i,actionParams:c})}),t}function w(e,t,n,r=!1){const o=[];let s=t;for(n=0!==Object.keys(n||{}).length?n:void 0;s;){const i=k(e,s,t,n);if(i&&(o.push(i),r))break;s=O(e,s)}return o}var E=/^[\w\u0080-\uffff-]+$/;function k(e,t,n,r){const o=u(t,m(e));if(!o||!E.test(o)||r&&!r[o])return null;const i=[t],c=`[${m(e,o)}],[${m(e,"")}]`,l=m(e,a.Commands.Link,!1);let f={};const d=[],[g,p]=$(n||t,c,e,o,!0);j(t,`[${l}]`,n=>{const[r,o]=L(n,l);"parent"===o&&j(t.ownerDocument.body,`[${l}]`,t=>{const[n,o]=L(t,l);if(n!==r||"child"!==o)return;i.push(t);const s=k(e,t);s&&d.push(s)})});const b=[];i.forEach(e=>{e.matches(c)&&b.push(e),j(e,c,e=>b.push(e))});let v={};return b.forEach(t=>{v=s(v,h(e,t,"")),f=s(f,h(e,t,o))}),f=s(s(v,f),g),i.forEach(t=>{j(t,`[${m(e)}]`,t=>{const n=k(e,t);n&&d.push(n)})}),{entity:o,data:f,context:p,nested:d}}function O(e,t){const n=m(e,a.Commands.Link,!1);if(t.matches(`[${n}]`)){const[e,r]=L(t,n);if("child"===r){const r=t.ownerDocument;let o=null;return S(r,`[${n}]`,t=>{const[r,s]=L(t,n);o||r!==e||"parent"!==s||(o=t)}),o}}const r=t.ownerDocument.defaultView;return!t.parentElement&&t.getRootNode&&t.getRootNode()instanceof r.ShadowRoot?t.getRootNode().host:t.parentElement}function $(e,t,n,r,o=!1){let i={};const c={};let l=e;const u=`[${m(n,a.Commands.Context,!1)}]`,f=a.Commands.Scoped,d=`[${m(n,f,!1)}]`;let g=0;for(;l;)o&&f&&l.matches(d)&&(i=s(h(n,l,f,!1),i)),l.matches(t)&&(i=s(h(n,l,""),i),i=s(h(n,l,r),i)),l.matches(u)&&(Object.entries(h(n,l,a.Commands.Context,!1)).forEach(([e,t])=>{t&&!c[e]&&(c[e]=[t,g])}),++g),l=O(n,l);return[i,c]}function S(e,t,n){e.querySelectorAll(t).forEach(n)}function j(e,t,n){e.querySelectorAll(t).forEach(n);e instanceof(e.ownerDocument||e).defaultView.Element&&e.shadowRoot&&j(e.shadowRoot,t,n),e.querySelectorAll("*").forEach(e=>{e.shadowRoot&&j(e.shadowRoot,t,n)})}function L(e,t){return d(u(e,t))}function x(e){const[t,n]=e.split("(",2);return[t,n?n.slice(0,-1):""]}import{tryCatch as C}from"@walkeros/core";import{isVisible as R}from"@walkeros/web-core";var A=Array.from({length:101},(e,t)=>t/100);function I(e){return e.ownerDocument||e}function P(e,t){const n=t.defaultView;if(n&&n.IntersectionObserver)return C(()=>new n.IntersectionObserver(n=>{n.forEach(n=>function(e,t,n){const r=n.target,o=e.visibility.get(t);if(!o)return;const s=r.ownerDocument.defaultView;if(!s)return;const i=o.configs.get(r);if(!i||!i.length)return;const c=o.timers.get(r);if(function(e,t){if(!e.isIntersecting)return!1;const n=e.boundingClientRect;if(n.width<=0||n.height<=0)return!1;const r=e.rootBounds?e.rootBounds.width:t.innerWidth,o=e.rootBounds?e.rootBounds.height:t.innerHeight;if(r<=0||o<=0)return!1;const s=e.intersectionRect,i=.5*Math.min(n.width,r),c=.5*Math.min(n.height,o);return s.width>=i&&s.height>=c}(n,s)){if(i.every(e=>e.blocked))return;if(!c){const n=s.setTimeout(()=>{T(e,t,r)},o.duration);o.timers.set(r,n)}return}c&&(clearTimeout(c),o.timers.delete(r));i.forEach(e=>{e.multiple&&(e.blocked=!1)})}(e,t,n))},{rootMargin:"0px",threshold:A}),()=>{})()}async function T(e,t,n,r=!1){const o=e.visibility.get(t);if(!o)return;o.timers.delete(n);const s=t.defaultView;if(!s)return;if("visible"!==t.visibilityState)return void o.timers.set(n,s.setTimeout(()=>{T(e,t,n,!0)},o.duration));if(r)return void o.timers.set(n,s.setTimeout(()=>{T(e,t,n)},o.duration));if(!R(n,s,t))return void o.timers.set(n,s.setTimeout(()=>{T(e,t,n)},o.duration));const i=o.configs.get(n);if(!i)return;const c=i.filter(e=>!e.blocked);if(!c.length)return;c.forEach(e=>{e.multiple&&(e.blocked=!0)});const l=i.filter(e=>e.multiple);l.length?o.configs.set(n,l):D(e,t,n),await Promise.all(c.map(e=>Z(e.context,n,e.trigger)))}function D(e,t,n){var r,o;const s=e.visibility.get(I(t));if(!s)return;null==(r=s.observer)||r.unobserve(n),null==(o=s.resizeObserver)||o.unobserve(n),s.configs.delete(n),s.zeroArea.delete(n);const i=s.timers.get(n);i&&(clearTimeout(i),s.timers.delete(n))}function V(e,t){const n=t.defaultView;if(n&&n.ResizeObserver)return C(()=>new n.ResizeObserver(n=>{const r=e.visibility.get(t);(null==r?void 0:r.observer)&&n.forEach(e=>{var t,n;const o=e.target,{width:s,height:i}=e.contentRect;s<=0||i<=0?r.zeroArea.add(o):r.zeroArea.has(o)&&(r.zeroArea.delete(o),null==(t=r.observer)||t.unobserve(o),null==(n=r.observer)||n.observe(o))})}),()=>{})()}function M(e,t,n={multiple:!1}){var r,o,s;const i=e.settings.scope;if(!i)return;const c=e.registry.visibility.get(I(i));if(!(null==c?void 0:c.observer)||!t)return;const l=null!=(r=n.multiple)&&r,a=null!=(o=c.configs.get(t))?o:[],u=a.length>0,f=l?K.Visible:K.Impression,d={multiple:l,blocked:!1,context:e,trigger:f},m=a.findIndex(e=>e.trigger===f);if(m>=0?a[m]=d:a.push(d),c.configs.set(t,a),u)return;const h=t.getBoundingClientRect();(h.width<=0||h.height<=0)&&c.zeroArea.add(t),c.observer.observe(t),null==(s=c.resizeObserver)||s.observe(t)}import{isString as H,isObject as W,isElementOrDocument as z}from"@walkeros/core";import{createPushResult as N}from"@walkeros/collector";function q(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof Element&&e instanceof Element)return!0;if("undefined"!=typeof Document&&e instanceof Document)return!0;if("undefined"!=typeof ShadowRoot&&e instanceof ShadowRoot)return!0;if("nodeType"in e){const t=e.nodeType;return 1===t||9===t||11===t}return!1}function B(e,t,n,r,o,s,i){var c;const{elb:l,push:a,settings:u}=e,f=null!=(c=e.root)?c:u.scope;if(H(t)&&t.startsWith("walker ")){if("walker init"===t&&e.initScope){const t=function(e,t){if(q(e))return[e];if(Array.isArray(e)){const t=[];for(const n of e)q(n)&&t.push(n);return t}if(void 0===e){const e=t.scope;if(q(e))return[e];if(void 0!==globalThis.document)return[globalThis.document]}return[]}(n,u);for(const n of t)e.initScope({...e,settings:{...u,scope:n}});return Promise.resolve(N({ok:!0}))}return l(t,n)}if(W(t)){const n=t;if(!n.source&&u.scope){const t=u.scope.ownerDocument||u.scope,r=t.defaultView;n.source=U(r,t,e.href)}return!n.globals&&f&&(n.globals=G(f)?b(u.prefix,f):{}),a(n)}const[d]=String(W(t)?t.name:t).split(" ");let m,h=W(n)?n:{},g={},p=!1;if(z(n)&&(m=n,p=!0),z(o)?m=o:W(o)&&Object.keys(o).length&&(g=o),m){const e=w(u.prefix||"data-elb",m).find(e=>e.entity===d);e&&(p&&(h=e.data),e.context&&(g=e.context))}const v=u.scope?u.scope.ownerDocument||u.scope:void 0,y=null==v?void 0:v.defaultView;"page"===d&&y&&(h.id=h.id||(e.href?new URL(e.href):y.location).pathname);const E=f&&G(f)?b(u.prefix,f):{};return a({name:String(t||""),data:h,context:g,globals:E,nested:s,custom:i,trigger:H(r)?r:"",source:y&&v?U(y,v,e.href):void 0})}function U(e,t,n){return{type:"browser",platform:"web",url:n||e.location.href,referrer:t.referrer}}function G(e){return 11!==e.nodeType}function _(e){var t,n;return new(null!=(n=null==(t=(e.ownerDocument||e).defaultView)?void 0:t.AbortController)?n:AbortController)}function F(e,t){return e.elements.has(t)}function J(e,t){var n;const r=e.elements.get(t);if(!r)return;const o=e.scopes.get(r.scope);r.intervalIds.forEach(e=>{if(clearInterval(e),o){const t=o.intervalIds.indexOf(e);-1!==t&&o.intervalIds.splice(t,1)}}),r.timeoutIds.forEach(e=>{if(clearTimeout(e),o){const t=o.timeoutIds.indexOf(e);-1!==t&&o.timeoutIds.splice(t,1)}}),null==(n=r.hoverAbort)||n.abort(),r.observed&&(D(e,r.scope,t),null==o||o.observed.delete(t)),r.scroll&&o&&(o.scrollElements=o.scrollElements.filter(([e])=>e!==t)),null==o||o.registered.delete(t),e.elements.delete(t)}var K={Click:"click",Custom:"custom",Hover:"hover",Load:"load",Pulse:"pulse",Scroll:"scroll",Submit:"submit",Impression:"impression",Visible:"visible",Wait:"wait"};function Q(e,t){t.scope&&function(e){const{scope:t,capture:r}=e.settings;if(!t)return;if(e.registry.destroyed)return;const{registry:o}=e;o.root&&o.root.abort();o.root=_(t);const{signal:s}=o.root;t.addEventListener("click",n(function(t){oe.call(this,e,t)}),{signal:s,capture:r}),t.addEventListener("submit",n(function(t){se.call(this,e,t)}),{signal:s,capture:r})}(e)}function X(e){const{registry:t}=e;t.destroyed=!0,t.root&&(t.root.abort(),t.root=void 0),t.scopes.forEach((e,n)=>{e.abort.abort(),e.mutationObservers.forEach(e=>e.disconnect()),e.intervalIds.forEach(e=>clearInterval(e)),e.timeoutIds.forEach(e=>clearTimeout(e)),e.observed.forEach(e=>D(t,n,e)),[...e.registered].forEach(e=>J(t,e))}),t.scopes.forEach((e,n)=>{!function(e,t){var n,r;if(!t)return;const o=I(t),s=e.visibility.get(o);s&&(null==(n=s.observer)||n.disconnect(),null==(r=s.resizeObserver)||r.disconnect(),e.visibility.delete(o))}(t,n)}),t.scopes.clear()}function Y(e){const t=e.settings.scope;if(!t)return;if(e.registry.destroyed)return;const o=function(e,t){const n=e.scopes.get(t);n&&(n.abort.abort(),n.intervalIds.forEach(e=>clearInterval(e)),n.timeoutIds.forEach(e=>clearTimeout(e)),n.observed.forEach(n=>D(e,t,n)),[...n.registered].forEach(t=>J(e,t)),n.mutationObservers.forEach(e=>e.disconnect()));const r={abort:_(t),intervalIds:[],timeoutIds:[],scrollElements:[],observed:new Set,registered:new Set,mutationObservers:[]};return e.scopes.set(t,r),r}(e.registry,t);!function(e,t,n=1e3){const r=I(t);if(e.visibility.has(r))return;const o={observer:P(e,r),resizeObserver:V(e,r),timers:new WeakMap,duration:n,configs:new WeakMap,zeroArea:new WeakSet};e.visibility.set(r,o)}(e.registry,t,1e3);const s=m(e.settings.prefix,r.Commands.Action,!1),i=t.ownerDocument||t,c=i.defaultView;t!==i&&c&&t instanceof c.HTMLElement&&F(e.registry,t)&&J(e.registry,t),j(t,`[${s}]`,t=>{c&&t instanceof c.HTMLElement&&F(e.registry,t)&&J(e.registry,t)}),t!==i&&c&&t instanceof c.Element&&ee(e,t,s,o,t),j(t,`[${s}]`,n=>{ee(e,n,s,o,t)}),o.scrollElements.length&&ie(e,t,o),e.settings.history&&t===i?function(e,t,r,o){const s=t.defaultView;if(!s||!s.MutationObserver)return;let i=[],c=[],l=!1;const a=()=>{l=!1;const n=i,r=c;i=[],c=[];const s=e.registry.scopes.get(t);s&&(r.forEach(t=>{t.isConnected||te(e,t)}),n.forEach(n=>{n.isConnected&&ne(e,n,o,s,t)}),s.scrollElements.length&&ie(e,t,s))},u=new s.MutationObserver(n(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{1===e.nodeType&&i.push(e)}),e.removedNodes.forEach(e=>{1===e.nodeType&&c.push(e)})}),l||!i.length&&!c.length||(l=!0,setTimeout(n(a),0))}));u.observe(t,{childList:!0,subtree:!0}),r.mutationObservers.push(u)}(e,i,o,s):function(e,t,r,o){const s=t.ownerDocument||t,i=s.defaultView;if(!i||!i.MutationObserver)return;const c=m(e.settings.prefix,"observe",!1),l=[];t!==s&&t instanceof i.Element&&t.matches(`[${c}]`)&&l.push(t);j(t,`[${c}]`,e=>l.push(e)),l.forEach(s=>{if(l.some(e=>e!==s&&e.contains(s)))return;const c=new i.MutationObserver(n(n=>{const r=e.registry.scopes.get(t);r&&n.forEach(n=>{n.addedNodes.forEach(n=>ne(e,n,o,r,t)),r.scrollElements.length&&ie(e,t,r),n.removedNodes.forEach(t=>te(e,t))})}));c.observe(s,{childList:!0,subtree:!0}),r.mutationObservers.push(c)})}(e,t,o,s)}async function Z(e,t,n){const r=p(t,n,e.settings.prefix);return Promise.all(r.map(t=>B(e,{name:`${t.entity} ${t.action}`,...t,trigger:n})))}function ee(e,t,r,s,i){var c;if(1!==t.nodeType)return;const l=null==(c=t.ownerDocument)?void 0:c.defaultView;if(!(l&&t instanceof l.HTMLElement))return;if(F(e.registry,t))return;if(!o(t,r))return;const a={scope:i,intervalIds:[],timeoutIds:[],scroll:!1,observed:!1};return function(e,t,r,s,i){const c=o(t,r);if(!c)return;Object.values(y(c)).forEach(r=>r.forEach(r=>{switch(r.trigger){case K.Hover:!function(e,t,r){r.hoverAbort||(r.hoverAbort=_(t));t.addEventListener("mouseenter",n(function(t){const n=re(t);n&&Z(e,n,K.Hover)}),{signal:r.hoverAbort.signal})}(e,t,i);break;case K.Load:!function(e,t){Z(e,t,K.Load)}(e,t);break;case K.Pulse:!function(e,t,n,r,o=""){const s=t.ownerDocument,i=setInterval(()=>{s.hidden||Z(e,t,K.Pulse)},parseInt(o||"")||15e3);n.intervalIds.push(i),r.intervalIds.push(i)}(e,t,s,i,r.triggerParams);break;case K.Scroll:!function(e,t,n,r=""){const o=parseInt(r||"")||50;if(o<0||o>100)return;t.scrollElements.push([e,o]),n.scroll=!0}(t,s,i,r.triggerParams);break;case K.Impression:M(e,t),s.observed.add(t),i.observed=!0;break;case K.Visible:M(e,t,{multiple:!0}),s.observed.add(t),i.observed=!0;break;case K.Wait:!function(e,t,n,r,o=""){const s=setTimeout(()=>Z(e,t,K.Wait),parseInt(o||"")||15e3);n.timeoutIds.push(s),r.timeoutIds.push(s)}(e,t,s,i,r.triggerParams)}}))}(e,t,r,s,a),function(e,t,n,r){if(e.elements.has(n))return!1;const o=e.scopes.get(t);!!o&&(r.scope=t,o.registered.add(n),e.elements.set(n,r))}(e.registry,i,t,a),a}function te(e,t){var n;if(1!==t.nodeType)return;const o=null==(n=t.ownerDocument)?void 0:n.defaultView;if(!(o&&t instanceof o.HTMLElement))return;const{registry:s}=e,i=m(e.settings.prefix,r.Commands.Action,!1);F(s,t)&&J(s,t),j(t,`[${i}]`,e=>{e instanceof o.HTMLElement&&F(s,e)&&J(s,e)})}function ne(e,t,n,r,o){var s;const i=null==(s=t.ownerDocument)?void 0:s.defaultView;i&&t instanceof i.HTMLElement&&(ee(e,t,n,r,o),j(t,`[${n}]`,t=>{ee(e,t,n,r,o)}))}function re(e){var t;const n=null==(t=e.composedPath)?void 0:t.call(e),r=(null==n?void 0:n.length)?n[0]:e.target;if(r&&"object"==typeof r&&"tagName"in r)return r}function oe(e,t){const n=re(t);n&&Z(e,n,K.Click)}function se(e,t){const n=re(t);n&&Z(e,n,K.Submit)}function ie(e,n,r){const o=n.ownerDocument||n,s=o.defaultView,i=(e,t)=>e.filter(([e,n])=>{const r=e.getBoundingClientRect();if(s.innerHeight<r.top)return!0;const o=r.height||e.clientHeight;return!(100*(1-(r.top+o-s.innerHeight)/(o||1))>=n)||(Z(t,e,K.Scroll),!1)});if(!r.scrollListener){r.scrollListener=t(function(){r.scrollElements=i.call(n,r.scrollElements,e)});(n instanceof s.ShadowRoot?o:n).addEventListener("scroll",r.scrollListener,{signal:r.abort.signal})}}import{isString as ce,isObject as le,tryCatch as ae}from"@walkeros/core";import{createPushResult as ue}from"@walkeros/collector";import{isObject as fe,tryCatch as de}from"@walkeros/core";var me=Symbol.for("@walkeros/web-source-browser:owner"),he=e=>null!==e&&("object"==typeof e||"function"==typeof e),ge=e=>he(e)&&"function"==typeof Reflect.get(e,"get")&&"function"==typeof Reflect.get(e,"set")&&"function"==typeof Reflect.get(e,"has");function pe(e,t){return de(()=>{Object.defineProperty(e,me,{value:t,writable:!0,enumerable:!1,configurable:!0})})(),e}function be(e){if(!he(e))return;const t=Reflect.get(e,me);return(e=>fe(e)&&ge(e.scopes)&&ge(e.elements))(t)?t:void 0}function ve(e){Reflect.deleteProperty(e,me)}var ye=Symbol.for("@walkeros/web-source-browser:elbLayer-drained"),we=e=>{const t=Reflect.get(e,ye);if(le(n=t)&&"number"==typeof n.commands&&"number"==typeof n.events)return t;var n;const r={commands:0,events:0};return ae(()=>{Object.defineProperty(e,ye,{value:r,writable:!0,enumerable:!1,configurable:!0})})(),r};function Ee(e,t={}){const n=t.name||"elbLayer",r=t.window,o=t.logger,s=()=>ue({ok:!0}),i=()=>({intake:()=>Promise.resolve(s()),start:()=>{},enqueue:e=>Promise.resolve().then(()=>e()),destroy:()=>{}});if(!r)return i();const c=Reflect.get(r,n);let l;Array.isArray(c)?l=c:(l=[],Reflect.set(r,n,l));const{registry:a}=e,u=be(l);if(u&&u!==a)return null==o||o.error(`elbLayer "${n}" is already adopted by another source`),i();pe(l,a);const f=we(l);let d=!1,m=f.commands,h=f.events,g=Promise.resolve(s()),p=Promise.resolve();const b=()=>{f.commands=m,f.events=h},v=async t=>{try{return await(t=>{if(Array.isArray(t)){const[n,...r]=t;return B(e,n,...r)}return B(e,t)})(t)}catch(e){return null==o||o.warn("elbLayer entry failed",{error:e,item:t}),ue({ok:!1})}},y=e=>{const t=e[0];return ce(t)&&t.startsWith("walker ")},w=(e,t)=>{if(!d){if(y(e)){if(t<m)return Promise.resolve(s());const n=g.then(()=>v(e));return g=n,m=t+1,b(),n}return Promise.resolve(s())}const n=p.then(()=>v(e));return p=n,m=t+1,h=t+1,b(),n},E=[],k=e=>{const t=ke(e),n=l.length,r=ae(()=>(l[n]=e,!0))();return t?r?w(t,n):(e=>{if(!d){if(y(e)){const t=g.then(()=>v(e));return g=t,t}return E.push(e),Promise.resolve(s())}const t=p.then(()=>v(e));return p=t,t})(t):Promise.resolve(s())},O=(...e)=>{for(const t of e)k(t);return l.length};ae(()=>{l.push=O})();const $=l.length;for(let e=0;e<$;e++){const t=ke(l[e]);t&&w(t,e)}return{intake:e=>k(e),start:()=>{if(!d){d=!0,p=g;for(let e=h;e<l.length;e++){const t=ke(l[e]);if(!t)continue;if(y(t))continue;const n=t;p=p.then(()=>v(n))}E.splice(0,E.length).forEach(e=>{p=p.then(()=>v(e))}),h=l.length,m=l.length,b()}},enqueue:e=>{const t=p.then(()=>e());return p=t.then(()=>{},()=>{}),t},destroy:()=>{l.push===O&&Reflect.deleteProperty(l,"push"),ve(l),d=!1,E.length=0,m=0,h=0,g=Promise.resolve(s()),p=Promise.resolve()}}}function ke(e){const t=null!=(n=e)&&"object"==typeof n&&"[object Arguments]"===Object.prototype.toString.call(n)?[...Array.from(e)]:function(e){return null!=e&&"object"==typeof e&&"length"in e&&"number"==typeof e.length}(e)?Array.from(e):[e];var n;if(!Array.isArray(t)||0===t.length)return null;if(1===t.length&&!t[0])return null;const r=t[0];return le(r)&&0===Object.keys(r).length||!le(r)&&ce(r)&&""===r.trim()?null:t}import{isBoolean as Oe,isObject as $e,isString as Se}from"@walkeros/core";var je={};import{isString as Le,isDefined as xe}from"@walkeros/core";function Ce(e={}){const t=e.prefix||"data-elb";return function(e){let n,r=e;const o={},s={},i={},c={},l={},a={};let u;function f(e){return Object.entries(e).map(([e,t])=>`${function(e){return e.replace(/[\\;:']/g,"\\$&")}(e)}:${function(e){return xe(e)&&null!==e?String(e).replace(/[\\;']/g,"\\$&"):"undefined"}(t)}`).join(";")}const d={entity:e=>(n=e,r=e,d),data(e,t){const n=null!=r?r:"";return o[n]||(o[n]={}),Le(e)?o[n][e]=t:Object.assign(o[n],e),d},scoped:(e,t)=>(Le(e)?s[e]=t:Object.assign(s,e),d),action(e,t){if(Le(e))if(xe(t))i[e]=t;else if(e.includes(":")){const[t,n]=e.split(":",2);i[t]=n}else i[e]=e;else Object.assign(i,e);return d},actions(e,t){if(Le(e))if(xe(t))c[e]=t;else if(e.includes(":")){const[t,n]=e.split(":",2);c[t]=n}else c[e]=e;else Object.assign(c,e);return d},context:(e,t)=>(Le(e)?l[e]=t:Object.assign(l,e),d),globals:(e,t)=>(Le(e)?a[e]=t:Object.assign(a,e),d),link(e,n){const r=Le(e)?[[e,null!=n?n:""]]:Object.entries(e),o=`One link per element: ${t}link`;if(r.length>1)throw new Error(`${o} holds one id and type, got ${r.length} (${r.map(([e])=>e).join(", ")})`);const[s]=r;if(!s)return d;if(u&&(u[0]!==s[0]||u[1]!==s[1]))throw new Error(`${o} already holds "${u.join(":")}", got "${s.join(":")}"`);return u=s,d},get(){const e={};return n&&(e[t]=n),Object.entries(o).forEach(([n,r])=>{if(Object.keys(r).length>0){e[n?`${t}-${n}`:`${t}-`]=f(r)}}),Object.keys(s).length>0&&(e[`${t}_`]=f(s)),Object.keys(i).length>0&&(e[`${t}action`]=f(i)),Object.keys(c).length>0&&(e[`${t}actions`]=f(c)),Object.keys(l).length>0&&(e[`${t}context`]=f(l)),Object.keys(a).length>0&&(e[`${t}globals`]=f(a)),u&&(e[`${t}link`]=f({[u[0]]:u[1]})),e}};return d}}function Re(){}function Ae(){}var Ie=async t=>{const{config:n,env:r,logger:o}=t,{elb:s,push:i,command:c,window:l,document:a}=r,u=(null==n?void 0:n.settings)||{},f=l||(void 0!==globalThis.window?globalThis.window:void 0),d=a||(void 0!==globalThis.document?globalThis.document:void 0),h=function(e={},t){return{prefix:"data-elb",pageview:!0,capture:!0,history:!1,elb:"elb",elbLayer:"elbLayer",scope:t||void 0,...e}}(u,d),g={settings:h},p={scopes:new Map,elements:new WeakMap,visibility:new WeakMap,destroyed:!1},b={elb:s,push:i,settings:h,root:h.scope,registry:p,logger:o,initScope:Y};let y,w,E,k=!1;const O=[];let S;const j=(e,t)=>{if(!e.pageview)return;const[n,r]=function(e,t,n){const r=t.ownerDocument||t,o=r.defaultView,s=n?new URL(n):o.location,i="page",c="body"in t?t.body:t,[l,a]=$(c,`[${m(e,i)}]`,e,i);return l.domain=s.hostname,l.title=r.title,l.referrer=r.referrer,s.search&&(l.search=s.search),s.hash&&(l.hash=s.hash),[l,a]}(e.prefix||"data-elb",e.scope,t);return S&&(n.referrer=S.split("#")[0]),S=t||(null==f?void 0:f.location.href),B({...b,href:t},"page view",n,"load",r)},L=e=>{const t=v(e.prefix||"data-elb",e.scope);if(Object.keys(t).length)return B(b,"walker user",t)},x=(...e)=>{const[t,n,r,o,s,i]=e;return B(b,t,n,r,o,s,i)};return{type:"browser",config:g,push:x,on:async e=>{if("run"===e)if(d&&f&&!p.destroyed){h.history&&!E&&(E=function(e,t){const n=e.history,r=n.pushState,o=n.replaceState;let s=e.location.pathname,i=e.location.search,c=!0;const l=n=>{if(!c)return;const{pathname:r,search:o,href:l}=e.location,a=r!==s||!n&&o!==i;s=r,i=o,a&&t(l)},a=function(...e){r.apply(n,e),l(!1)},u=function(...e){o.apply(n,e),l(!0)},f=()=>l(!1);return n.pushState=a,n.replaceState=u,e.addEventListener("popstate",f,{capture:!0}),()=>{c=!1,n.pushState===a&&(n.pushState=r),n.replaceState===u&&(n.replaceState=o),e.removeEventListener("popstate",f,{capture:!0})}}(f,e=>{O.push(e),s("walker run").catch(()=>{})}));const e=O.shift();e||function(e,t){t.scope&&Y(e)}(b,h),y?(y.start(),y.enqueue(()=>L(h)).catch(()=>{}),y.enqueue(()=>j(h,e)).catch(()=>{})):(await L(h),j(h,e))}},init:async()=>{if(!f||!d)return;if(k)return;k=!0;const t=e(h.elbLayer)?h.elbLayer:"elbLayer",n=!1!==h.elbLayer?Ee(b,{name:t,window:f,logger:o}):void 0,r=Reflect.get(f,t),s=n&&be(r)===p?n:void 0;if(y=s,await async function(e,t,n){const r=()=>{t.registry.destroyed||e(t,n)},o=n.scope;if(!o)return void r();const s=o.ownerDocument||o;if("loading"!==s.readyState)return void r();const{registry:i}=t;i.root||(i.root=_(o)),s.addEventListener("DOMContentLoaded",r,{signal:i.root.signal})}(Q,b,h),e(h.elb)&&h.elb){const e=be(Reflect.get(f,h.elb));if(e&&e!==p)null==o||o.error(`elb "${h.elb}" is already installed by another source`);else{const e=s?(...e)=>s.intake(e):x;w=pe(e,p),Reflect.set(f,h.elb,e)}}},destroy:async()=>{X(b),null==E||E(),E=void 0,O.length=0,null==y||y.destroy(),f&&e(h.elb)&&h.elb&&Reflect.get(f,h.elb)===w&&Reflect.deleteProperty(f,h.elb),w&&ve(w),y=void 0,w=void 0}}},Pe=Ie;export{je as SourceBrowser,K as Triggers,Ae as __readInstanceGuardForTests,Re as __resetInstanceCountForTests,Ce as createTagger,Pe as default,g as getAllEvents,m as getElbAttributeName,h as getElbValues,p as getEvents,b as getGlobals,y as getTriggerActions,v as getUser,Ie as sourceBrowser};//# sourceMappingURL=index.mjs.map