@walkeros/web-source-browser 4.4.0-next-1785285516008 → 4.4.0
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/CHANGELOG.md +16 -4
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/index.browser.js +1 -1
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.es5.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/walkerOS.json +2 -2
- package/package.json +4 -4
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}from"@walkeros/web-core";function f(e,t,n=!0){return e+(t=null!=t?(n?"-":"")+t:"")}function d(e,t,n,r=!0){return $(u(t,f(e,n,r))||"").reduce((e,n)=>{let[r,o]=x(n);if(!r)return e;if(o||(r.endsWith(":")&&(r=r.slice(0,-1)),o=""),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 m(e,t=a.Commands.Prefix){var n;const r=e;if(!r)return[];let o=[];const s=a.Commands.Action,i=`[${f(t,s,!1)}]`,c=e=>{Object.keys(d(t,e,s,!1)).forEach(n=>{o=o.concat(g(e,n,t))})};return r!==(r.ownerDocument||r)&&(null==(n=r.matches)?void 0:n.call(r,i))&&c(r),O(r,i,c),o}function g(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,f(e,a.Commands.Actions,!1));if(t){const e=p(t);if(e[n])return{actions:e[n],nearestOnly:!1}}const o=u(r,f(e,a.Commands.Action,!1));if(o){const e=p(o);if(e[n]||"click"!==n)return{actions:e[n]||[],nearestOnly:!0}}r=w(e,r)}return{actions:[],nearestOnly:!1}}(n,e,t);return o.length?(o.forEach(o=>{const i=$(o.actionParams||"",",").reduce((e,t)=>(e[l(t)]=!0,e),{}),c=v(n,e,i,s);if(!c.length){const t="page",r=`[${f(n,t)}]`,[o,s]=k(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 h(e=a.Commands.Prefix,t){if(!t)return{};const n=f(e,a.Commands.Globals,!1);let r={};return E(t,`[${n}]`,t=>{r=s(r,d(e,t,a.Commands.Globals,!1))}),r}function b(e=a.Commands.Prefix,t){if(!t)return{};const n=f(e,a.Commands.User,!1);let r={};return E(t,`[${n}]`,t=>{r=s(r,d(e,t,a.Commands.User,!1))}),r}function p(e){const t={};return $(e).forEach(e=>{const[n,r]=x(e),[o,s]=j(n);if(!o)return;let[i,c]=j(r||"");i=i||o,t[o]||(t[o]=[]),t[o].push({trigger:o,triggerParams:s,action:i,actionParams:c})}),t}function v(e,t,n,r=!1){const o=[];let s=t;for(n=0!==Object.keys(n||{}).length?n:void 0;s;){const i=y(e,s,t,n);if(i&&(o.push(i),r))break;s=w(e,s)}return o}function y(e,t,n,r){const o=u(t,f(e));if(!o||r&&!r[o])return null;const i=[t],c=`[${f(e,o)}],[${f(e,"")}]`,l=f(e,a.Commands.Link,!1);let m={};const g=[],[h,b]=k(n||t,c,e,o,!0);O(t,`[${l}]`,n=>{const[r,o]=x(u(n,l));"parent"===o&&O(t.ownerDocument.body,`[${l}="${r}:child"]`,t=>{i.push(t);const n=y(e,t);n&&g.push(n)})});const p=[];i.forEach(e=>{e.matches(c)&&p.push(e),O(e,c,e=>p.push(e))});let v={};return p.forEach(t=>{v=s(v,d(e,t,"")),m=s(m,d(e,t,o))}),m=s(s(v,m),h),i.forEach(t=>{O(t,`[${f(e)}]`,t=>{const n=y(e,t);n&&g.push(n)})}),{entity:o,data:m,context:b,nested:g}}function w(e,t){const n=f(e,a.Commands.Link,!1);if(t.matches(`[${n}]`)){const[e,r]=x(u(t,n));if("child"===r){const r=t.ownerDocument;let o=null;return E(r,`[${n}="${e}:parent"]`,e=>{o||(o=e)}),o}}const r=t.ownerDocument.defaultView;return!t.parentElement&&t.getRootNode&&t.getRootNode()instanceof r.ShadowRoot?t.getRootNode().host:t.parentElement}function k(e,t,n,r,o=!1){let i={};const c={};let l=e;const u=`[${f(n,a.Commands.Context,!1)}]`,m=a.Commands.Scoped,g=`[${f(n,m,!1)}]`;let h=0;for(;l;)o&&m&&l.matches(g)&&(i=s(d(n,l,m,!1),i)),l.matches(t)&&(i=s(d(n,l,""),i),i=s(d(n,l,r),i)),l.matches(u)&&(Object.entries(d(n,l,a.Commands.Context,!1)).forEach(([e,t])=>{t&&!c[e]&&(c[e]=[t,h])}),++h),l=w(n,l);return[i,c]}function E(e,t,n){e.querySelectorAll(t).forEach(n)}function O(e,t,n){e.querySelectorAll(t).forEach(n);e instanceof(e.ownerDocument||e).defaultView.Element&&e.shadowRoot&&O(e.shadowRoot,t,n),e.querySelectorAll("*").forEach(e=>{e.shadowRoot&&O(e.shadowRoot,t,n)})}function $(e,t=";"){if(!e)return[];const n=new RegExp(`(?:[^${t}']+|'[^']*')+`,"ig");return e.match(n)||[]}function x(e){const[t,n]=e.split(/:(.+)/,2);return[l(t),l(n)]}function j(e){const[t,n]=e.split("(",2);return[t,n?n.slice(0,-1):""]}import{tryCatch as R}from"@walkeros/core";import{isVisible as A}from"@walkeros/web-core";var C=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 R(()=>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(()=>{S(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:C}),()=>{})()}async function S(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(()=>{S(e,t,n,!0)},o.duration));if(r)return void o.timers.set(n,s.setTimeout(()=>{S(e,t,n)},o.duration));if(!A(n,s,t))return void o.timers.set(n,s.setTimeout(()=>{S(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):L(e,t,n),await Promise.all(c.map(e=>X(e.context,n,e.trigger)))}function L(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 T(e,t){const n=t.defaultView;if(n&&n.ResizeObserver)return R(()=>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 D(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?F.Visible:F.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 g=t.getBoundingClientRect();(g.width<=0||g.height<=0)&&c.zeroArea.add(t),c.observer.observe(t),null==(s=c.resizeObserver)||s.observe(t)}import{isString as V,isObject as M,isElementOrDocument as W}from"@walkeros/core";import{createPushResult as z}from"@walkeros/collector";function H(e,t,n,r,o,s,i){var c;const{elb:l,settings:a}=e,u=null!=(c=e.root)?c:a.scope;if(V(t)&&t.startsWith("walker ")){if("walker init"===t&&e.initScope){const t=function(e,t){if(B(e))return[e];if(Array.isArray(e)){const t=[];for(const n of e)B(n)&&t.push(n);return t}if(void 0===e){const e=t.scope;if(B(e))return[e];if(void 0!==globalThis.document)return[globalThis.document]}return[]}(n,a);for(const n of t)e.initScope({...e,settings:{...a,scope:n}});return Promise.resolve(z({ok:!0}))}return l(t,n)}if(M(t)){const e=t;if(!e.source&&a.scope){const t=a.scope.ownerDocument||a.scope,n=t.defaultView;e.source=q(n,t)}return!e.globals&&u&&(e.globals=N(u)?h(a.prefix,u):{}),l(e)}const[f]=String(M(t)?t.name:t).split(" ");let d,m=M(n)?n:{},g={},b=!1;if(W(n)&&(d=n,b=!0),W(o)?d=o:M(o)&&Object.keys(o).length&&(g=o),d){const e=v(a.prefix||"data-elb",d).find(e=>e.entity===f);e&&(b&&(m=e.data),e.context&&(g=e.context))}const p=a.scope?a.scope.ownerDocument||a.scope:void 0,y=null==p?void 0:p.defaultView;"page"===f&&y&&(m.id=m.id||y.location.pathname);const w=u&&N(u)?h(a.prefix,u):{};return l({name:String(t||""),data:m,context:g,globals:w,nested:s,custom:i,trigger:V(r)?r:"",source:y&&p?q(y,p):void 0})}function q(e,t){return{type:"browser",platform:"web",url:e.location.href,referrer:t.referrer}}function B(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 N(e){return 11!==e.nodeType}function G(e){var t,n;return new(null!=(n=null==(t=(e.ownerDocument||e).defaultView)?void 0:t.AbortController)?n:AbortController)}function U(e,t){return e.elements.has(t)}function _(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&&(L(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 F={Click:"click",Custom:"custom",Hover:"hover",Load:"load",Pulse:"pulse",Scroll:"scroll",Submit:"submit",Impression:"impression",Visible:"visible",Wait:"wait"};function J(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=G(t);const{signal:s}=o.root;t.addEventListener("click",n(function(t){ee.call(this,e,t)}),{signal:s,capture:r}),t.addEventListener("submit",n(function(t){te.call(this,e,t)}),{signal:s,capture:r})}(e)}function K(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=>L(t,n,e)),[...e.registered].forEach(e=>_(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 Q(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=>L(e,t,n)),[...n.registered].forEach(t=>_(e,t)),n.mutationObservers.forEach(e=>e.disconnect()));const r={abort:G(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:T(e,r),timers:new WeakMap,duration:n,configs:new WeakMap,zeroArea:new WeakSet};e.visibility.set(r,o)}(e.registry,t,1e3);const s=f(e.settings.prefix,r.Commands.Action,!1),i=t.ownerDocument||t,c=i.defaultView;t!==i&&c&&t instanceof c.Element&&Y(e,t,s,o,t),O(t,`[${s}]`,n=>{Y(e,n,s,o,t)}),o.scrollElements.length&&ne(e,t,o),function(e,t,o,s){const i=t.ownerDocument||t,c=i.defaultView;if(!c||!c.MutationObserver)return;const l=f(e.settings.prefix,"observe",!1),a=[];t!==i&&t instanceof c.Element&&t.matches(`[${l}]`)&&a.push(t);O(t,`[${l}]`,e=>a.push(e)),a.forEach(i=>{if(a.some(e=>e!==i&&e.contains(i)))return;const l=new c.MutationObserver(n(n=>{const o=e.registry.scopes.get(t);o&&n.forEach(n=>{n.addedNodes.forEach(n=>function(e,t,n,r,o){var s;const i=null==(s=t.ownerDocument)?void 0:s.defaultView;if(!(i&&t instanceof i.HTMLElement))return;Y(e,t,n,r,o),O(t,`[${n}]`,t=>{Y(e,t,n,r,o)})}(e,n,s,o,t)),o.scrollElements.length&&ne(e,t,o),n.removedNodes.forEach(t=>function(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=f(e.settings.prefix,r.Commands.Action,!1);U(s,t)&&_(s,t);O(t,`[${i}]`,e=>{e instanceof o.HTMLElement&&U(s,e)&&_(s,e)})}(e,t))})}));l.observe(i,{childList:!0,subtree:!0}),o.mutationObservers.push(l)})}(e,t,o,s)}async function X(e,t,n){const r=g(t,n,e.settings.prefix);return Promise.all(r.map(t=>H(e,{name:`${t.entity} ${t.action}`,...t,trigger:n})))}function Y(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(U(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(p(c)).forEach(r=>r.forEach(r=>{switch(r.trigger){case F.Hover:!function(e,t,r){r.hoverAbort||(r.hoverAbort=G(t));t.addEventListener("mouseenter",n(function(t){const n=Z(t);n&&X(e,n,F.Hover)}),{signal:r.hoverAbort.signal})}(e,t,i);break;case F.Load:!function(e,t){X(e,t,F.Load)}(e,t);break;case F.Pulse:!function(e,t,n,r,o=""){const s=t.ownerDocument,i=setInterval(()=>{s.hidden||X(e,t,F.Pulse)},parseInt(o||"")||15e3);n.intervalIds.push(i),r.intervalIds.push(i)}(e,t,s,i,r.triggerParams);break;case F.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 F.Impression:D(e,t),s.observed.add(t),i.observed=!0;break;case F.Visible:D(e,t,{multiple:!0}),s.observed.add(t),i.observed=!0;break;case F.Wait:!function(e,t,n,r,o=""){const s=setTimeout(()=>X(e,t,F.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 Z(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 ee(e,t){const n=Z(t);n&&X(e,n,F.Click)}function te(e,t){const n=Z(t);n&&X(e,n,F.Submit)}function ne(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)||(X(t,e,F.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 re,isObject as oe,tryCatch as se}from"@walkeros/core";import{createPushResult as ie}from"@walkeros/collector";import{isObject as ce,tryCatch as le}from"@walkeros/core";var ae=Symbol.for("@walkeros/web-source-browser:owner"),ue=e=>null!==e&&("object"==typeof e||"function"==typeof e),fe=e=>ue(e)&&"function"==typeof Reflect.get(e,"get")&&"function"==typeof Reflect.get(e,"set")&&"function"==typeof Reflect.get(e,"has");function de(e,t){return le(()=>{Object.defineProperty(e,ae,{value:t,writable:!0,enumerable:!1,configurable:!0})})(),e}function me(e){if(!ue(e))return;const t=Reflect.get(e,ae);return(e=>ce(e)&&fe(e.scopes)&&fe(e.elements))(t)?t:void 0}function ge(e){Reflect.deleteProperty(e,ae)}var he=Symbol.for("@walkeros/web-source-browser:elbLayer-drained"),be=e=>{const t=Reflect.get(e,he);if(oe(n=t)&&"number"==typeof n.commands&&"number"==typeof n.events)return t;var n;const r={commands:0,events:0};return se(()=>{Object.defineProperty(e,he,{value:r,writable:!0,enumerable:!1,configurable:!0})})(),r};function pe(e,t={}){const n=t.name||"elbLayer",r=t.window,o=t.logger,s=()=>ie({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=me(l);if(u&&u!==a)return null==o||o.error(`elbLayer "${n}" is already adopted by another source`),i();de(l,a);const f=be(l);let d=!1,m=f.commands,g=f.events,h=Promise.resolve(s()),b=Promise.resolve();const p=()=>{f.commands=m,f.events=g},v=async t=>{try{return await(t=>{if(Array.isArray(t)){const[n,...r]=t;return H(e,n,...r)}return H(e,t)})(t)}catch(e){return null==o||o.warn("elbLayer entry failed",{error:e,item:t}),ie({ok:!1})}},y=e=>{const t=e[0];return re(t)&&t.startsWith("walker ")},w=(e,t)=>{if(!d){if(y(e)){if(t<m)return Promise.resolve(s());const n=h.then(()=>v(e));return h=n,m=t+1,p(),n}return Promise.resolve(s())}const n=b.then(()=>v(e));return b=n,m=t+1,g=t+1,p(),n},k=[],E=e=>{const t=ve(e),n=l.length,r=se(()=>(l[n]=e,!0))();return t?r?w(t,n):(e=>{if(!d){if(y(e)){const t=h.then(()=>v(e));return h=t,t}return k.push(e),Promise.resolve(s())}const t=b.then(()=>v(e));return b=t,t})(t):Promise.resolve(s())},O=(...e)=>{for(const t of e)E(t);return l.length};se(()=>{l.push=O})();const $=l.length;for(let e=0;e<$;e++){const t=ve(l[e]);t&&w(t,e)}return{intake:e=>E(e),start:()=>{if(!d){d=!0,b=h;for(let e=g;e<l.length;e++){const t=ve(l[e]);if(!t)continue;if(y(t))continue;const n=t;b=b.then(()=>v(n))}k.splice(0,k.length).forEach(e=>{b=b.then(()=>v(e))}),g=l.length,m=l.length,p()}},enqueue:e=>{const t=b.then(()=>e());return b=t.then(()=>{},()=>{}),t},destroy:()=>{l.push===O&&Reflect.deleteProperty(l,"push"),ge(l),d=!1,k.length=0,m=0,g=0,h=Promise.resolve(s()),b=Promise.resolve()}}}function ve(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 oe(r)&&0===Object.keys(r).length||!oe(r)&&re(r)&&""===r.trim()?null:t}var ye={};import{isString as we,isDefined as ke}from"@walkeros/core";function Ee(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])=>`${e}:${function(e){if(!ke(e)||null===e)return"undefined";let t=String(e);return t=t.replace(/\\/g,"\\\\"),t=t.replace(/;/g,"\\;"),t=t.replace(/:/g,"\\:"),t=t.replace(/'/g,"\\'"),t}(t)}`).join(";")}const d={entity:e=>(n=e,r=e,d),data(e,t){const n=null!=r?r:"";return o[n]||(o[n]={}),we(e)?o[n][e]=t:Object.assign(o[n],e),d},scoped:(e,t)=>(we(e)?s[e]=t:Object.assign(s,e),d),action(e,t){if(we(e))if(ke(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(we(e))if(ke(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)=>(we(e)?l[e]=t:Object.assign(l,e),d),globals:(e,t)=>(we(e)?a[e]=t:Object.assign(a,e),d),link:(e,t)=>(we(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 Oe(){}function $e(){}var xe=async t=>{const{config:n,env:r,logger:o}=t,{elb:s,command:i,window:c,document:l}=r,a=(null==n?void 0:n.settings)||{},u=c||(void 0!==globalThis.window?globalThis.window:void 0),d=l||(void 0!==globalThis.document?globalThis.document:void 0),m=function(e={},t){return{prefix:"data-elb",pageview:!0,capture:!0,elb:"elb",elbLayer:"elbLayer",scope:t||void 0,...e}}(a,d),g={settings:m},h={scopes:new Map,elements:new WeakMap,visibility:new WeakMap,destroyed:!1},p={elb:s,settings:m,root:m.scope,registry:h,logger:o,initScope:Q};let v,y,w=!1;const E=e=>{if(!e.pageview)return;const[t,n]=function(e,t){const n=t.ownerDocument||t,r=n.defaultView.location,o="page",s="body"in t?t.body:t,[i,c]=k(s,`[${f(e,o)}]`,e,o);return i.domain=r.hostname,i.title=n.title,i.referrer=n.referrer,r.search&&(i.search=r.search),r.hash&&(i.hash=r.hash),[i,c]}(e.prefix||"data-elb",e.scope);return H(p,"page view",t,"load",n)},O=e=>{const t=b(e.prefix||"data-elb",e.scope);if(Object.keys(t).length)return H(p,"walker user",t)},$=(...e)=>{const[t,n,r,o,s,i]=e;return H(p,t,n,r,o,s,i)};return{type:"browser",config:g,push:$,on:async e=>{if("run"===e)d&&u&&!h.destroyed&&(!function(e,t){t.scope&&Q(e)}(p,m),v?(v.start(),v.enqueue(()=>O(m)).catch(()=>{}),v.enqueue(()=>E(m)).catch(()=>{})):(await O(m),E(m)))},init:async()=>{if(!u||!d)return;if(w)return;w=!0;const t=e(m.elbLayer)?m.elbLayer:"elbLayer",n=!1!==m.elbLayer?pe(p,{name:t,window:u,logger:o}):void 0,r=Reflect.get(u,t),s=n&&me(r)===h?n:void 0;if(v=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=G(o)),s.addEventListener("DOMContentLoaded",r,{signal:i.root.signal})}(J,p,m),e(m.elb)&&m.elb){const e=me(Reflect.get(u,m.elb));if(e&&e!==h)null==o||o.error(`elb "${m.elb}" is already installed by another source`);else{const e=s?(...e)=>s.intake(e):$;y=de(e,h),Reflect.set(u,m.elb,e)}}},destroy:async()=>{K(p),null==v||v.destroy(),u&&e(m.elb)&&m.elb&&Reflect.get(u,m.elb)===y&&Reflect.deleteProperty(u,m.elb),y&&ge(y),v=void 0,y=void 0}}},je=xe;export{ye as SourceBrowser,$e as __readInstanceGuardForTests,Oe as __resetInstanceCountForTests,Ee as createTagger,je as default,m as getAllEvents,f as getElbAttributeName,d as getElbValues,g as getEvents,h as getGlobals,b as getUser,xe 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}from"@walkeros/web-core";function f(e,t,n=!0){return e+(t=null!=t?(n?"-":"")+t:"")}function d(e,t,n,r=!0){return $(u(t,f(e,n,r))||"").reduce((e,n)=>{let[r,o]=x(n);if(!r)return e;if(o||(r.endsWith(":")&&(r=r.slice(0,-1)),o=""),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 m(e,t=a.Commands.Prefix){var n;const r=e;if(!r)return[];let o=[];const s=a.Commands.Action,i=`[${f(t,s,!1)}]`,c=e=>{Object.keys(d(t,e,s,!1)).forEach(n=>{o=o.concat(g(e,n,t))})};return r!==(r.ownerDocument||r)&&(null==(n=r.matches)?void 0:n.call(r,i))&&c(r),O(r,i,c),o}function g(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,f(e,a.Commands.Actions,!1));if(t){const e=p(t);if(e[n])return{actions:e[n],nearestOnly:!1}}const o=u(r,f(e,a.Commands.Action,!1));if(o){const e=p(o);if(e[n]||"click"!==n)return{actions:e[n]||[],nearestOnly:!0}}r=w(e,r)}return{actions:[],nearestOnly:!1}}(n,e,t);return o.length?(o.forEach(o=>{const i=$(o.actionParams||"",",").reduce((e,t)=>(e[l(t)]=!0,e),{}),c=v(n,e,i,s);if(!c.length){const t="page",r=`[${f(n,t)}]`,[o,s]=k(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 h(e=a.Commands.Prefix,t){if(!t)return{};const n=f(e,a.Commands.Globals,!1);let r={};return E(t,`[${n}]`,t=>{r=s(r,d(e,t,a.Commands.Globals,!1))}),r}function b(e=a.Commands.Prefix,t){if(!t)return{};const n=f(e,a.Commands.User,!1);let r={};return E(t,`[${n}]`,t=>{r=s(r,d(e,t,a.Commands.User,!1))}),r}function p(e){const t={};return $(e).forEach(e=>{const[n,r]=x(e),[o,s]=j(n);if(!o)return;let[i,c]=j(r||"");i=i||o,t[o]||(t[o]=[]),t[o].push({trigger:o,triggerParams:s,action:i,actionParams:c})}),t}function v(e,t,n,r=!1){const o=[];let s=t;for(n=0!==Object.keys(n||{}).length?n:void 0;s;){const i=y(e,s,t,n);if(i&&(o.push(i),r))break;s=w(e,s)}return o}function y(e,t,n,r){const o=u(t,f(e));if(!o||r&&!r[o])return null;const i=[t],c=`[${f(e,o)}],[${f(e,"")}]`,l=f(e,a.Commands.Link,!1);let m={};const g=[],[h,b]=k(n||t,c,e,o,!0);O(t,`[${l}]`,n=>{const[r,o]=x(u(n,l));"parent"===o&&O(t.ownerDocument.body,`[${l}="${r}:child"]`,t=>{i.push(t);const n=y(e,t);n&&g.push(n)})});const p=[];i.forEach(e=>{e.matches(c)&&p.push(e),O(e,c,e=>p.push(e))});let v={};return p.forEach(t=>{v=s(v,d(e,t,"")),m=s(m,d(e,t,o))}),m=s(s(v,m),h),i.forEach(t=>{O(t,`[${f(e)}]`,t=>{const n=y(e,t);n&&g.push(n)})}),{entity:o,data:m,context:b,nested:g}}function w(e,t){const n=f(e,a.Commands.Link,!1);if(t.matches(`[${n}]`)){const[e,r]=x(u(t,n));if("child"===r){const r=t.ownerDocument;let o=null;return E(r,`[${n}="${e}:parent"]`,e=>{o||(o=e)}),o}}const r=t.ownerDocument.defaultView;return!t.parentElement&&t.getRootNode&&t.getRootNode()instanceof r.ShadowRoot?t.getRootNode().host:t.parentElement}function k(e,t,n,r,o=!1){let i={};const c={};let l=e;const u=`[${f(n,a.Commands.Context,!1)}]`,m=a.Commands.Scoped,g=`[${f(n,m,!1)}]`;let h=0;for(;l;)o&&m&&l.matches(g)&&(i=s(d(n,l,m,!1),i)),l.matches(t)&&(i=s(d(n,l,""),i),i=s(d(n,l,r),i)),l.matches(u)&&(Object.entries(d(n,l,a.Commands.Context,!1)).forEach(([e,t])=>{t&&!c[e]&&(c[e]=[t,h])}),++h),l=w(n,l);return[i,c]}function E(e,t,n){e.querySelectorAll(t).forEach(n)}function O(e,t,n){e.querySelectorAll(t).forEach(n);e instanceof(e.ownerDocument||e).defaultView.Element&&e.shadowRoot&&O(e.shadowRoot,t,n),e.querySelectorAll("*").forEach(e=>{e.shadowRoot&&O(e.shadowRoot,t,n)})}function $(e,t=";"){if(!e)return[];const n=new RegExp(`(?:[^${t}']+|'[^']*')+`,"ig");return e.match(n)||[]}function x(e){const[t,n]=e.split(/:(.+)/,2);return[l(t),l(n)]}function j(e){const[t,n]=e.split("(",2);return[t,n?n.slice(0,-1):""]}import{tryCatch as R}from"@walkeros/core";import{isVisible as A}from"@walkeros/web-core";var C=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 R(()=>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(()=>{S(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:C}),()=>{})()}async function S(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(()=>{S(e,t,n,!0)},o.duration));if(r)return void o.timers.set(n,s.setTimeout(()=>{S(e,t,n)},o.duration));if(!A(n,s,t))return void o.timers.set(n,s.setTimeout(()=>{S(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):L(e,t,n),await Promise.all(c.map(e=>X(e.context,n,e.trigger)))}function L(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 T(e,t){const n=t.defaultView;if(n&&n.ResizeObserver)return R(()=>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 D(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?F.Visible:F.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 g=t.getBoundingClientRect();(g.width<=0||g.height<=0)&&c.zeroArea.add(t),c.observer.observe(t),null==(s=c.resizeObserver)||s.observe(t)}import{isString as V,isObject as M,isElementOrDocument as W}from"@walkeros/core";import{createPushResult as H}from"@walkeros/collector";function z(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(V(t)&&t.startsWith("walker ")){if("walker init"===t&&e.initScope){const t=function(e,t){if(B(e))return[e];if(Array.isArray(e)){const t=[];for(const n of e)B(n)&&t.push(n);return t}if(void 0===e){const e=t.scope;if(B(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(H({ok:!0}))}return l(t,n)}if(M(t)){const e=t;if(!e.source&&u.scope){const t=u.scope.ownerDocument||u.scope,n=t.defaultView;e.source=q(n,t)}return!e.globals&&f&&(e.globals=N(f)?h(u.prefix,f):{}),a(e)}const[d]=String(M(t)?t.name:t).split(" ");let m,g=M(n)?n:{},b={},p=!1;if(W(n)&&(m=n,p=!0),W(o)?m=o:M(o)&&Object.keys(o).length&&(b=o),m){const e=v(u.prefix||"data-elb",m).find(e=>e.entity===d);e&&(p&&(g=e.data),e.context&&(b=e.context))}const y=u.scope?u.scope.ownerDocument||u.scope:void 0,w=null==y?void 0:y.defaultView;"page"===d&&w&&(g.id=g.id||w.location.pathname);const k=f&&N(f)?h(u.prefix,f):{};return a({name:String(t||""),data:g,context:b,globals:k,nested:s,custom:i,trigger:V(r)?r:"",source:w&&y?q(w,y):void 0})}function q(e,t){return{type:"browser",platform:"web",url:e.location.href,referrer:t.referrer}}function B(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 N(e){return 11!==e.nodeType}function G(e){var t,n;return new(null!=(n=null==(t=(e.ownerDocument||e).defaultView)?void 0:t.AbortController)?n:AbortController)}function U(e,t){return e.elements.has(t)}function _(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&&(L(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 F={Click:"click",Custom:"custom",Hover:"hover",Load:"load",Pulse:"pulse",Scroll:"scroll",Submit:"submit",Impression:"impression",Visible:"visible",Wait:"wait"};function J(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=G(t);const{signal:s}=o.root;t.addEventListener("click",n(function(t){ee.call(this,e,t)}),{signal:s,capture:r}),t.addEventListener("submit",n(function(t){te.call(this,e,t)}),{signal:s,capture:r})}(e)}function K(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=>L(t,n,e)),[...e.registered].forEach(e=>_(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 Q(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=>L(e,t,n)),[...n.registered].forEach(t=>_(e,t)),n.mutationObservers.forEach(e=>e.disconnect()));const r={abort:G(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:T(e,r),timers:new WeakMap,duration:n,configs:new WeakMap,zeroArea:new WeakSet};e.visibility.set(r,o)}(e.registry,t,1e3);const s=f(e.settings.prefix,r.Commands.Action,!1),i=t.ownerDocument||t,c=i.defaultView;t!==i&&c&&t instanceof c.HTMLElement&&U(e.registry,t)&&_(e.registry,t),O(t,`[${s}]`,t=>{c&&t instanceof c.HTMLElement&&U(e.registry,t)&&_(e.registry,t)}),t!==i&&c&&t instanceof c.Element&&Y(e,t,s,o,t),O(t,`[${s}]`,n=>{Y(e,n,s,o,t)}),o.scrollElements.length&&ne(e,t,o),function(e,t,o,s){const i=t.ownerDocument||t,c=i.defaultView;if(!c||!c.MutationObserver)return;const l=f(e.settings.prefix,"observe",!1),a=[];t!==i&&t instanceof c.Element&&t.matches(`[${l}]`)&&a.push(t);O(t,`[${l}]`,e=>a.push(e)),a.forEach(i=>{if(a.some(e=>e!==i&&e.contains(i)))return;const l=new c.MutationObserver(n(n=>{const o=e.registry.scopes.get(t);o&&n.forEach(n=>{n.addedNodes.forEach(n=>function(e,t,n,r,o){var s;const i=null==(s=t.ownerDocument)?void 0:s.defaultView;if(!(i&&t instanceof i.HTMLElement))return;Y(e,t,n,r,o),O(t,`[${n}]`,t=>{Y(e,t,n,r,o)})}(e,n,s,o,t)),o.scrollElements.length&&ne(e,t,o),n.removedNodes.forEach(t=>function(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=f(e.settings.prefix,r.Commands.Action,!1);U(s,t)&&_(s,t);O(t,`[${i}]`,e=>{e instanceof o.HTMLElement&&U(s,e)&&_(s,e)})}(e,t))})}));l.observe(i,{childList:!0,subtree:!0}),o.mutationObservers.push(l)})}(e,t,o,s)}async function X(e,t,n){const r=g(t,n,e.settings.prefix);return Promise.all(r.map(t=>z(e,{name:`${t.entity} ${t.action}`,...t,trigger:n})))}function Y(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(U(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(p(c)).forEach(r=>r.forEach(r=>{switch(r.trigger){case F.Hover:!function(e,t,r){r.hoverAbort||(r.hoverAbort=G(t));t.addEventListener("mouseenter",n(function(t){const n=Z(t);n&&X(e,n,F.Hover)}),{signal:r.hoverAbort.signal})}(e,t,i);break;case F.Load:!function(e,t){X(e,t,F.Load)}(e,t);break;case F.Pulse:!function(e,t,n,r,o=""){const s=t.ownerDocument,i=setInterval(()=>{s.hidden||X(e,t,F.Pulse)},parseInt(o||"")||15e3);n.intervalIds.push(i),r.intervalIds.push(i)}(e,t,s,i,r.triggerParams);break;case F.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 F.Impression:D(e,t),s.observed.add(t),i.observed=!0;break;case F.Visible:D(e,t,{multiple:!0}),s.observed.add(t),i.observed=!0;break;case F.Wait:!function(e,t,n,r,o=""){const s=setTimeout(()=>X(e,t,F.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 Z(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 ee(e,t){const n=Z(t);n&&X(e,n,F.Click)}function te(e,t){const n=Z(t);n&&X(e,n,F.Submit)}function ne(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)||(X(t,e,F.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 re,isObject as oe,tryCatch as se}from"@walkeros/core";import{createPushResult as ie}from"@walkeros/collector";import{isObject as ce,tryCatch as le}from"@walkeros/core";var ae=Symbol.for("@walkeros/web-source-browser:owner"),ue=e=>null!==e&&("object"==typeof e||"function"==typeof e),fe=e=>ue(e)&&"function"==typeof Reflect.get(e,"get")&&"function"==typeof Reflect.get(e,"set")&&"function"==typeof Reflect.get(e,"has");function de(e,t){return le(()=>{Object.defineProperty(e,ae,{value:t,writable:!0,enumerable:!1,configurable:!0})})(),e}function me(e){if(!ue(e))return;const t=Reflect.get(e,ae);return(e=>ce(e)&&fe(e.scopes)&&fe(e.elements))(t)?t:void 0}function ge(e){Reflect.deleteProperty(e,ae)}var he=Symbol.for("@walkeros/web-source-browser:elbLayer-drained"),be=e=>{const t=Reflect.get(e,he);if(oe(n=t)&&"number"==typeof n.commands&&"number"==typeof n.events)return t;var n;const r={commands:0,events:0};return se(()=>{Object.defineProperty(e,he,{value:r,writable:!0,enumerable:!1,configurable:!0})})(),r};function pe(e,t={}){const n=t.name||"elbLayer",r=t.window,o=t.logger,s=()=>ie({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=me(l);if(u&&u!==a)return null==o||o.error(`elbLayer "${n}" is already adopted by another source`),i();de(l,a);const f=be(l);let d=!1,m=f.commands,g=f.events,h=Promise.resolve(s()),b=Promise.resolve();const p=()=>{f.commands=m,f.events=g},v=async t=>{try{return await(t=>{if(Array.isArray(t)){const[n,...r]=t;return z(e,n,...r)}return z(e,t)})(t)}catch(e){return null==o||o.warn("elbLayer entry failed",{error:e,item:t}),ie({ok:!1})}},y=e=>{const t=e[0];return re(t)&&t.startsWith("walker ")},w=(e,t)=>{if(!d){if(y(e)){if(t<m)return Promise.resolve(s());const n=h.then(()=>v(e));return h=n,m=t+1,p(),n}return Promise.resolve(s())}const n=b.then(()=>v(e));return b=n,m=t+1,g=t+1,p(),n},k=[],E=e=>{const t=ve(e),n=l.length,r=se(()=>(l[n]=e,!0))();return t?r?w(t,n):(e=>{if(!d){if(y(e)){const t=h.then(()=>v(e));return h=t,t}return k.push(e),Promise.resolve(s())}const t=b.then(()=>v(e));return b=t,t})(t):Promise.resolve(s())},O=(...e)=>{for(const t of e)E(t);return l.length};se(()=>{l.push=O})();const $=l.length;for(let e=0;e<$;e++){const t=ve(l[e]);t&&w(t,e)}return{intake:e=>E(e),start:()=>{if(!d){d=!0,b=h;for(let e=g;e<l.length;e++){const t=ve(l[e]);if(!t)continue;if(y(t))continue;const n=t;b=b.then(()=>v(n))}k.splice(0,k.length).forEach(e=>{b=b.then(()=>v(e))}),g=l.length,m=l.length,p()}},enqueue:e=>{const t=b.then(()=>e());return b=t.then(()=>{},()=>{}),t},destroy:()=>{l.push===O&&Reflect.deleteProperty(l,"push"),ge(l),d=!1,k.length=0,m=0,g=0,h=Promise.resolve(s()),b=Promise.resolve()}}}function ve(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 oe(r)&&0===Object.keys(r).length||!oe(r)&&re(r)&&""===r.trim()?null:t}var ye={};import{isString as we,isDefined as ke}from"@walkeros/core";function Ee(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])=>`${e}:${function(e){if(!ke(e)||null===e)return"undefined";let t=String(e);return t=t.replace(/\\/g,"\\\\"),t=t.replace(/;/g,"\\;"),t=t.replace(/:/g,"\\:"),t=t.replace(/'/g,"\\'"),t}(t)}`).join(";")}const d={entity:e=>(n=e,r=e,d),data(e,t){const n=null!=r?r:"";return o[n]||(o[n]={}),we(e)?o[n][e]=t:Object.assign(o[n],e),d},scoped:(e,t)=>(we(e)?s[e]=t:Object.assign(s,e),d),action(e,t){if(we(e))if(ke(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(we(e))if(ke(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)=>(we(e)?l[e]=t:Object.assign(l,e),d),globals:(e,t)=>(we(e)?a[e]=t:Object.assign(a,e),d),link:(e,t)=>(we(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 Oe(){}function $e(){}var xe=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)||{},d=l||(void 0!==globalThis.window?globalThis.window:void 0),m=a||(void 0!==globalThis.document?globalThis.document:void 0),g=function(e={},t){return{prefix:"data-elb",pageview:!0,capture:!0,elb:"elb",elbLayer:"elbLayer",scope:t||void 0,...e}}(u,m),h={settings:g},p={scopes:new Map,elements:new WeakMap,visibility:new WeakMap,destroyed:!1},v={elb:s,push:i,settings:g,root:g.scope,registry:p,logger:o,initScope:Q};let y,w,E=!1;const O=e=>{if(!e.pageview)return;const[t,n]=function(e,t){const n=t.ownerDocument||t,r=n.defaultView.location,o="page",s="body"in t?t.body:t,[i,c]=k(s,`[${f(e,o)}]`,e,o);return i.domain=r.hostname,i.title=n.title,i.referrer=n.referrer,r.search&&(i.search=r.search),r.hash&&(i.hash=r.hash),[i,c]}(e.prefix||"data-elb",e.scope);return z(v,"page view",t,"load",n)},$=e=>{const t=b(e.prefix||"data-elb",e.scope);if(Object.keys(t).length)return z(v,"walker user",t)},x=(...e)=>{const[t,n,r,o,s,i]=e;return z(v,t,n,r,o,s,i)};return{type:"browser",config:h,push:x,on:async e=>{if("run"===e)m&&d&&!p.destroyed&&(!function(e,t){t.scope&&Q(e)}(v,g),y?(y.start(),y.enqueue(()=>$(g)).catch(()=>{}),y.enqueue(()=>O(g)).catch(()=>{})):(await $(g),O(g)))},init:async()=>{if(!d||!m)return;if(E)return;E=!0;const t=e(g.elbLayer)?g.elbLayer:"elbLayer",n=!1!==g.elbLayer?pe(v,{name:t,window:d,logger:o}):void 0,r=Reflect.get(d,t),s=n&&me(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=G(o)),s.addEventListener("DOMContentLoaded",r,{signal:i.root.signal})}(J,v,g),e(g.elb)&&g.elb){const e=me(Reflect.get(d,g.elb));if(e&&e!==p)null==o||o.error(`elb "${g.elb}" is already installed by another source`);else{const e=s?(...e)=>s.intake(e):x;w=de(e,p),Reflect.set(d,g.elb,e)}}},destroy:async()=>{K(v),null==y||y.destroy(),d&&e(g.elb)&&g.elb&&Reflect.get(d,g.elb)===w&&Reflect.deleteProperty(d,g.elb),w&&ge(w),y=void 0,w=void 0}}},je=xe;export{ye as SourceBrowser,$e as __readInstanceGuardForTests,Oe as __resetInstanceCountForTests,Ee as createTagger,je as default,m as getAllEvents,f as getElbAttributeName,d as getElbValues,g as getEvents,h as getGlobals,b as getUser,xe as sourceBrowser};//# sourceMappingURL=index.mjs.map
|