@quietsapa/qsl 0.1.1 → 0.1.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/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ All notable changes to this project are documented here. The format follows
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.2] - 2026-09-20
10
+
11
+ ### Fixed
12
+
13
+ - `init()` now captures `document.currentScript` before its first `await`
14
+ rather than after. `currentScript` is only set while a script runs
15
+ synchronously, so any plugin init action that waits on something genuinely
16
+ asynchronous would have left it `null` and the `?async=true` ready callback
17
+ would have silently never fired. No shipped plugin awaits anything today, so
18
+ this fixes a latent fault rather than an observable one.
19
+
20
+ ### Added
21
+
22
+ - Runnable examples under `examples/`, and a README section on loading QSL with
23
+ `async` and the `QSLReady` callback.
24
+
9
25
  ## [0.1.1] - 2026-09-20
10
26
 
11
27
  ### Fixed
@@ -103,6 +119,7 @@ list of new features.
103
119
  the internal bundle-composition map. Those stay in the private repository;
104
120
  this one ships only the runtime.
105
121
 
106
- [Unreleased]: https://github.com/Quietsapa/qsl/compare/v0.1.1...HEAD
122
+ [Unreleased]: https://github.com/Quietsapa/qsl/compare/v0.1.2...HEAD
123
+ [0.1.2]: https://github.com/Quietsapa/qsl/compare/v0.1.1...v0.1.2
107
124
  [0.1.1]: https://github.com/Quietsapa/qsl/compare/v0.1.0...v0.1.1
108
125
  [0.1.0]: https://github.com/Quietsapa/qsl/releases/tag/v0.1.0
package/README.md CHANGED
@@ -51,6 +51,48 @@ Or load a prebuilt bundle straight from a CDN:
51
51
  Both browser bundles register their types and call `init()` for you, then
52
52
  expose the instance as `window.__QSL__`.
53
53
 
54
+ ### Loading QSL without blocking the parser
55
+
56
+ The tag above is a blocking one: the parser stops until QSL has downloaded.
57
+ That is the simplest thing that works, and for a small file served from a CDN
58
+ it is often fine.
59
+
60
+ To take it off the critical path, mark the tag `async` and add `?async=true` to
61
+ the URL. QSL then calls `window.QSLReady()` once it has finished initialising,
62
+ and you do your work there:
63
+
64
+ ```html
65
+ <script>
66
+ window.QSLReady = function () {
67
+ var qsl = window.__QSL__;
68
+ qsl.add({ id: 'gtm', type: 'script', src: 'https://example.com/gtm.js' });
69
+ qsl.load();
70
+ };
71
+ </script>
72
+ <script async src="https://cdn.jsdelivr.net/npm/@quietsapa/qsl/dist/qsl.min.js?async=true"></script>
73
+ ```
74
+
75
+ The callback exists because `async` removes any guarantee about ordering. An
76
+ inline script placed after the tag runs while QSL is still downloading, so
77
+ `window.__QSL__` is not there yet and reading it gives you `undefined`. The
78
+ callback fires when the instance is actually ready.
79
+
80
+ Three things to keep in mind:
81
+
82
+ - **Define the callback before the tag.** QSL calls it once, immediately after
83
+ `init()`. If the global is not a function at that moment nothing happens —
84
+ no error, no retry.
85
+ - **`?async=true` is required.** Without it QSL initialises normally and never
86
+ looks for a callback. The `async` attribute alone changes when the script
87
+ runs, not what it does.
88
+ - **Rename it if `QSLReady` collides**, with `?callback=myHandler`. The name is
89
+ read from the same query string.
90
+
91
+ The DOM is only guaranteed to be parsed up to the tag itself, so keep it at the
92
+ end of `<body>` if your setup code touches elements. Triggers like `domready`
93
+ and `load` handle the rest for you and fire correctly even when QSL arrives
94
+ after those events have passed.
95
+
54
96
  | Build | Entry | Size (gzip) | Contents |
55
97
  | --- | --- | --- | --- |
56
98
  | `dist/qsl.mjs` | `src/index.js` | — | ESM, nothing registered, nothing started |
@@ -88,6 +130,18 @@ With a CDN bundle the registration is already done:
88
130
  </script>
89
131
  ```
90
132
 
133
+ ## Examples
134
+
135
+ Runnable pages in [`examples/`](examples/) — open `index.html`, no build step.
136
+ Each one starts with a description of the problem it solves.
137
+
138
+ | Example | Problem |
139
+ | --- | --- |
140
+ | [consent-groups](examples/consent-groups/) | A cookie banner where the pixel fires on consent but the chat widget still waits for engagement |
141
+ | [embed-on-visible](examples/embed-on-visible/) | A YouTube embed that costs nothing until someone scrolls to it |
142
+ | [dependency-chain](examples/dependency-chain/) | Tags that quietly need each other, declared in the wrong order |
143
+ | [legacy-domcontentloaded](examples/legacy-domcontentloaded/) | Why deferring a vendor script silently breaks it |
144
+
91
145
  ## Concepts
92
146
 
93
147
  **Process** — one thing to load: a script, a stylesheet, a pixel, an element.
package/dist/qsl.min.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(){"use strict";const e={VERSION:"0.1.1",PREFIX:"qsl-",FLOW_TYPE:{DEFAULT:"default",ORDERED:"ordered"},FLOW_STATE:{READY:"READY",RUNNING:"RUNNING",COMPLETED:"COMPLETED"},FLOW_OPTIONS:{delay:0,priority:0,between:null,trigger:null,condition:null,beforeStart:null,onComplete:null,group:null,paused:!1,preload:!1,fireEvents:!0,depends:[]},EVENTS:{STARTED:"QSL:started",COMPLETED:"QSL:completed",ERROR:"QSL:error",FLOW_STARTED:"QSL:flow:started",FLOW_COMPLETED:"QSL:flow:completed",ALL_COMPLETED:"QSL:all:completed",SKIPPED:"QSL:skipped",DOMREADY:"QSL:domready",LOADED:"QSL:loaded"},LIFECYCLE:{DOMREADY:"interactive"===document.readyState||"complete"===document.readyState,LOADED:!1},CALLBACK:"QSLReady",types:new Map,flows:new Map,flowOptions:new Map,flowGroups:new Map,currentProcessPerFlow:new Map,pendingFlows:new Set,pendingProcesses:new Set,completedProcesses:new Set,loadActions:new Set,initActions:new Set,addProcessFilters:new Set,completedFlowsActions:new Set,flowIdFilters:new Set,conditionHandlers:new Set,triggerHandlers:new Set,processCompleteActions:new Set,allCompleteActions:new Set,resetActions:new Set,handlerCallbacksFilters:new Set,onAllComplete:null,globalResolve:null,logger:null,hasStarted:!1,eventsEnabled:!1,initialized:!1,completing:!1,autoReset:!0,globalBetween:0,async init(){if(this.initialized)return this;if(window.__QSL__=window.__QSL__||this,"interactive"===document.readyState||"complete"===document.readyState?this.LIFECYCLE.DOMREADY=!0:document.addEventListener("DOMContentLoaded",()=>this.LIFECYCLE.DOMREADY=!0,{once:!0}),"complete"===document.readyState?this.LIFECYCLE.LOADED=!0:window.addEventListener("load",()=>this.LIFECYCLE.LOADED=!0,{once:!0}),this.registerType("console",e=>new Promise(t=>{var s;null==(s=e.onBeforeStart)||s.call(e),setTimeout(()=>{var s;e.message&&this.log(e.message,{timestamp:Date.now()}),null==(s=e.onComplete)||s.call(e),t()},e.delay||0)})),window.addEventListener("QSL:log",e=>this.log(e.detail.type,e.detail.config.id)),window.addEventListener("QSL:error",e=>this.error(e.detail.type,e.detail.error,e.detail.config.id)),this.initActions.size)for(const s of this.initActions)"function"==typeof s&&await s.call(this);this.initialized=!0;const e=document.currentScript?new URL(document.currentScript.src,document.baseURI):null;if(!e||"true"!==e.searchParams.get("async"))return this;const t=e.searchParams.get("callback")||this.CALLBACK;return"function"==typeof window[t]&&window[t](),this},use(e,...t){return"function"==typeof e&&e(this,...t),this},add(e,t=null){if(!e||"object"!=typeof e)return this;if(e.id=e.id?this.PREFIX+e.id:this.PREFIX+Math.random().toString(36).slice(2),e.skipped=!1,e.type||(e.type="console"),Array.isArray(e.depends)&&(e.depends=[...new Set(e.depends)]),this.addProcessFilters.size)for(const n of this.addProcessFilters)"function"==typeof n&&([t,e]=n.call(this,t,e));const s=this.normalizeFlowId(t);return e.flowId=s,this.getOrCreateFlow(s).push(e),this},async load({between:e=!1}={}){if(!this.hasStarted){this.hasStarted=!0,this.globalBetween=e;for(const e of this.loadActions)"function"==typeof e&&e.call(this);return new Promise(e=>{if(!this.flows.size)return this.reset(),e();this.globalResolve=e,this.processFlows()})}},reset(){if(this.resetActions.size)for(const e of this.resetActions)"function"==typeof e&&e.call(this);return this.flows.clear(),this.flowOptions.clear(),this.flowGroups.clear(),this.pendingFlows.clear(),this.pendingProcesses.clear(),this.completedProcesses.clear(),this.currentProcessPerFlow.clear(),this.onAllComplete=null,this.globalResolve=null,this.hasStarted=!1,this.globalBetween=0,this.log("RESET"),this},destroy(){return this.reset(),this.types.clear(),this.initActions.clear(),this.loadActions.clear(),this.addProcessFilters.clear(),this.completedFlowsActions.clear(),this.flowIdFilters.clear(),this.conditionHandlers.clear(),this.triggerHandlers.clear(),this.processCompleteActions.clear(),this.allCompleteActions.clear(),this.resetActions.clear(),this.handlerCallbacksFilters.clear(),this.logger=null,this.eventsEnabled=!1,this.initialized=!1,this},setLogger(e){return!e||"function"!=typeof e&&"object"!=typeof e||(this.logger=e),this},setOnAllComplete(e){return this.onAllComplete="function"==typeof e?e:null,this},useEvents(){return this.eventsEnabled=!0,this},log(e,...t){this.logger&&"function"==typeof this.logger.log&&this.logger.log(e,...t)},error(e,...t){this.logger&&"function"==typeof this.logger.error&&this.logger.error(e,...t)},fire(e,t){this.eventsEnabled&&this.EVENTS[e]&&window.dispatchEvent(new CustomEvent(this.EVENTS[e],{detail:t}))},normalizeFlowId(e){return!0===e?e=this.FLOW_TYPE.ORDERED:"string"!=typeof e&&(e=this.FLOW_TYPE.DEFAULT),e},registerType(e,t){return"string"!=typeof e||"function"!=typeof t||this.types.set(e,t),this},registerTypes(e){if(!e||"object"!=typeof e)return this;const t=Array.isArray(e)?e:Object.entries(e).map(([e,t])=>"function"==typeof t?{type:e,handler:t}:t);for(const s of t)s&&this.registerType(s.type,s.handler);return this},pauseGroup(e){const t=this.flowGroups.get(e);if(!t)return this;for(const s of t)this.setFlowOptions({paused:!0},s);return this},runGroup(e){const t=this.flowGroups.get(e);if(!t)return this;for(const s of t)this.setFlowOptions({paused:!1},s),this.runFlow(s);return this},runFlow(e,t=!1){const s=this.flows.get(e),n=this.flowOptions.get(e);return s&&n&&n.status===this.FLOW_STATE.READY?(this.processFlows(e,t),this):this},getOrCreateFlow(e){return this.flows.has(e)||(this.flows.set(e,[]),this.flowOptions.set(e,{...this.FLOW_OPTIONS,ordered:e===this.FLOW_TYPE.ORDERED,status:this.FLOW_STATE.READY})),this.flows.get(e)},setFlowOptions(e={},t=null){if(t=this.normalizeFlowId(t),this.getOrCreateFlow(t),!e||"object"!=typeof e)return this;const s=this.flowOptions.get(t);return Array.isArray(e.depends)&&e.depends.length&&(e.depends=[...new Set(e.depends)],e.paused=!0,this.pendingFlows.add(t)),e.group&&(this.flowGroups.has(e.group)||this.flowGroups.set(e.group,new Set),this.flowGroups.get(e.group).add(t)),this.flowOptions.set(t,{...s,...e}),this},checkPendingFlows(){if(this.pendingFlows.size)for(const e of this.pendingFlows){const t=this.flowOptions.get(e);t&&t.depends&&t.depends.every(e=>{const t=this.flowOptions.get(this.normalizeFlowId(e));return t&&t.status===this.FLOW_STATE.COMPLETED})&&(this.setFlowOptions({paused:!1},e),this.pendingFlows.delete(e),this.runFlow(e))}},checkPendingProcesses(){if(this.pendingProcesses.size)for(const e of this.pendingProcesses){const t=e.depends.filter(e=>{const t=Array.from(this.flows.values()).some(t=>t.some(t=>t.id===this.PREFIX+e));return!this.completedProcesses.has(this.PREFIX+e)&&!t});if(t.length){this.pendingProcesses.delete(e),this.log("DEP_NOT_FOUND",e.id,`${t.join(", ")}`),e._depsResolved=!0,e._triggered=!0,e._waitResolve&&e._waitResolve();continue}e.depends.every(e=>this.completedProcesses.has(this.PREFIX+e))&&(this.pendingProcesses.delete(e),e._depsResolved=!0,e._triggered&&e._waitResolve&&e._waitResolve())}},async maybeComplete(){var e;if(!this.hasStarted)return;if(this.pendingFlows.size)for(const n of this.pendingFlows){const e=this.flowOptions.get(n);e&&e.depends&&e.depends.some(e=>!this.flowOptions.has(this.normalizeFlowId(e)))&&(this.setFlowOptions({status:this.FLOW_STATE.COMPLETED},n),this.pendingFlows.delete(n),this.log("FLOW_DEP_SKIPPED",{flow:n,depends:`${e.depends.filter(e=>!this.flowOptions.has(this.normalizeFlowId(e))).join(", ")}`}))}let t=!!this.flowOptions.size&&Array.from(this.flowOptions.values()).every(e=>e.status===this.FLOW_STATE.COMPLETED),s=t;if(this.flows.size&&this.completedFlowsActions.size)for(const n of this.completedFlowsActions)s=n.call(this,t,this.flows,this.flowOptions);if(s&&!this.completing){if(this.completing=!0,this.log("ALL_COMPLETED"),this.fire("ALL_COMPLETED"),null==(e=this.onAllComplete)||e.call(this),null!==this.globalResolve&&this.globalResolve(),this.allCompleteActions.size)for(const e of this.allCompleteActions)"function"==typeof e&&e.call(this);this.autoReset&&this.reset(),this.completing=!1}},processFlows(e=null,t=!1){if(!this.flows.size)return;let s=e?[e]:Array.from(this.flows.keys());if(s.length&&this.flowIdFilters.size)for(const n of this.flowIdFilters)"function"==typeof n&&(s=n.call(this,s));s.sort((e,t)=>{const s=this.flowOptions.get(e),n=this.flowOptions.get(t),i=null!=(null==s?void 0:s.trigger),o=null!=(null==n?void 0:n.trigger);if(i&&!o)return 1;if(!i&&o)return-1;const r=(null==s?void 0:s.priority)||0;return((null==n?void 0:n.priority)||0)-r});for(const n of s){const s=this.flowOptions.get(n);if(s&&s.status!==this.FLOW_STATE.COMPLETED)if(this.getConditionStatus(s.condition))this.setFlowOptions({status:this.FLOW_STATE.COMPLETED},n);else if(!s.paused){if((null===e||e&&!t)&&null!=s.trigger){const e=this.getTriggerFunction(s.trigger,s);if(e){this.setFlowOptions({paused:!0},n);let t=!1;e(()=>{t||(t=!0,this.setFlowOptions({paused:!1},n),this.runFlow(n,!0))});continue}}this.setFlowOptions({status:this.FLOW_STATE.RUNNING},n),(async()=>{var e,t;null==(e=s.beforeStart)||e.call(s),s.delay&&s.delay>0&&await new Promise(e=>setTimeout(e,s.delay));const i=(this.flows.get(n)||[]).slice();if(i.sort((e,t)=>(t.priority||0)-(e.priority||0)),(s.preload||s.prefetch)&&!s.trigger)for(const n of i)if(!n.trigger&&("script"===n.type&&n.src||"style"===n.type&&n.href))try{const e=document.createElement("link");e.rel=s.preload?"preload":"prefetch",e.href=n.src||n.href,e.as="script"===n.type?"script":"style",n.crossOrigin&&(e.crossOrigin=n.crossOrigin),document.head.appendChild(e)}catch(r){this.error("PRELOAD_ERROR",r,n.id)}const o=void 0!==s.between&&null!==s.between?s.between:this.globalBetween;if(s.ordered){let e=Promise.resolve();i.forEach((t,s)=>{e=e.then(async()=>{s>0&&o&&await new Promise(e=>setTimeout(e,o)),await this.run(t)})}),await e}else{const e=i.map(async(e,t)=>(t>0&&o&&await new Promise(e=>setTimeout(e,o)),this.run(e)));await Promise.all(e)}this.setFlowOptions({status:this.FLOW_STATE.COMPLETED},n),null==(t=s.onComplete)||t.call(s),this.checkPendingFlows(),this.maybeComplete()})()}}this.checkPendingFlows(),this.maybeComplete()},async run(e){if(!e._running&&!this.getConditionStatus(e.condition)){if(e._running=!0,e._waitPromise||(e._triggered=!1,e._depsResolved=!1,e._waitPromise=new Promise(t=>e._waitResolve=t)),null!=e.trigger){const t=this.getTriggerFunction(e.trigger,e);t?t(()=>{e._triggered=!0,e._depsResolved&&e._waitResolve()}):e._triggered=!0}else e._triggered=!0;if(Array.isArray(e.depends)&&e.depends.length){const t=e.depends.filter(e=>{const t=Array.from(this.flows.values()).some(t=>t.some(t=>t.id===this.PREFIX+e));return!this.completedProcesses.has(this.PREFIX+e)&&!t});if(t.length)this.log("DEP_NOT_FOUND",e.id,`${t.join(", ")}`),e._depsResolved=!0,e._triggered=!0,e._waitResolve&&e._waitResolve();else{e.depends.every(e=>this.completedProcesses.has(this.PREFIX+e))?(e._depsResolved=!0,e._triggered&&e._waitResolve()):this.pendingProcesses.add(e)}}else e._depsResolved=!0,e._triggered&&e._waitResolve();return await e._waitPromise,this.execute(e)}},getConditionStatus(e){if(null==e)return!1;if(Array.isArray(e))return e.some(e=>this.getConditionStatus(e));if("object"==typeof e&&e.operator){const{operator:t,conditions:s}=e;return!!Array.isArray(s)&&("or"===t?s.every(e=>this.getConditionStatus(e)):"and"===t&&s.some(e=>this.getConditionStatus(e)))}if("function"==typeof e&&!e())return!0;if("boolean"==typeof e&&!e)return!0;if(this.conditionHandlers.size)for(const t of this.conditionHandlers)if("function"==typeof t){const s=t.call(this,e);if(!0===s||!1===s)return s}return!1},getTriggerFunction(e,t){if(null==e)return null;if("function"==typeof e)return t=>e(t);if(Array.isArray(e))return s=>{const n=e.map(e=>this.getTriggerFunction(e,t)).filter(e=>e);if(0===n.length)return void s();let i=0;const o=()=>{++i===n.length&&s()};n.forEach(e=>e(o))};if("object"==typeof e&&e.operator){const{operator:s,triggers:n}=e;return Array.isArray(n)?"or"===s?e=>{const s=n.map(e=>this.getTriggerFunction(e,t)).filter(e=>e);if(0===s.length)return void e();let i=!1;const o=()=>{i||(i=!0,e())};s.forEach(e=>e(o))}:"and"===s?e=>{const s=n.map(e=>this.getTriggerFunction(e,t)).filter(e=>e);if(0===s.length)return void e();let i=0;const o=()=>{++i===s.length&&e()};s.forEach(e=>e(o))}:null:null}if(this.triggerHandlers.size)for(const s of this.triggerHandlers)if("function"==typeof s){const n=s.call(this,e,t);if(n&&"function"==typeof n)return n}return!0===e||"interaction"===e?e=>this.waitForInteraction(e):null},waitForInteraction(e){["click","keydown","wheel","mousedown","mousemove","touchstart"].forEach(t=>window.addEventListener(t,()=>e(),{once:!0,passive:!0}))},async execute(e){const t=async()=>{if(this.processCompleteActions.size)for(const t of this.processCompleteActions)"function"==typeof t&&t.call(this,e);this.completedProcesses.add(e.id),e._running=!1,this.checkPendingProcesses()};if(e.skipped)return this.fire("SKIPPED",{...e,id:e.id}),void t();const s=this.types.get(e.type);if(!s)return this.log("UNKNOWN_TYPE",e.type,e.id),void t();this.fire("STARTED",{...e,id:e.id});const n={};if(this.handlerCallbacksFilters.size)for(const i of this.handlerCallbacksFilters)if("function"==typeof i){const t=i.call(this,e);t&&"object"==typeof t&&Object.assign(n,t)}return s(e,n).then(()=>{this.fire("COMPLETED",{...e,id:e.id}),t()}).catch(()=>{this.fire("ERROR",{...e,id:e.id}),t()})}},t=(e,t)=>t?(e.includes("?")?"&":"?")+Date.now():"",s=e=>{window.dispatchEvent(new CustomEvent("QSL:log",{detail:e}))},n=e=>{window.dispatchEvent(new CustomEvent("QSL:error",{detail:e}))},i=(e,t={})=>new Promise(async i=>{var o;const{flowId:r,tag:l,id:a,delay:c,data:d,onBeforeStart:u,onComplete:h,onError:f,footer:p,dom:g,onElement:E,onCustomResolve:w}=e;if(r&&l&&a)try{u&&await u(e),s({tag:l,type:"PROCESS_STARTED",config:e}),c&&await new Promise(e=>setTimeout(e,c));let r=document.createElement(l);if(null==E||E(r,e),null==(o=t.registerProcessElement)||o.call(t,r,e),d&&"object"==typeof d)for(const[e,t]of Object.entries(d))r.setAttribute(`data-${e.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/[^a-z0-9_-]/g,"").replace(/^-/,"")}`,String(t));w||(r.onload=()=>{s({tag:l,type:"PROCESS_COMPLETED",config:e}),null==h||h(),i()}),r.onerror=t=>{n({tag:l,type:"PROCESS_FAILED",config:e}),null==f||f(t),i(t)},g&&(p?document.body:document.head).appendChild(r),null==w||w({el:r,config:e,resolve:i})}catch(m){n({tag:l,type:"PROCESS_FAILED",config:e,error:m}),null==f||f(m),i(m)}else i()}),o={type:"inline-script",handler:(e,t)=>{var n;let o=null,r=!1;const l=`QSL:inline-script:completed:${e.id}`,a=()=>{var t;s({tag:"inline-script",type:"INLINE_SCRIPT_SUCCESS",config:e}),s({tag:"inline-script",type:"PROCESS_COMPLETED",config:e}),null==(t=null==e?void 0:e.onComplete)||t.call(e),null==o||o()},c={...e,code:null==(n=e.code)?void 0:n.replace(/<script.*?>|<\/script>/gi,"")};return i({...c,tag:"script",dom:!0,onElement:(e,t)=>{const{code:s,module:n,id:i,flowId:c}=t;if(s&&(e.textContent=s),n){e.type="module";const t=e.textContent,s=JSON.stringify(String(c)),n=`(function(){window.__QSL__.currentProcessPerFlow.set(${s},${JSON.stringify(String(i))});try{${t}}finally{window.__QSL__.currentProcessPerFlow.delete(${s});window.dispatchEvent(new Event(${JSON.stringify(String(l))}));}})();`;e.textContent=n;const d=()=>{window.removeEventListener(l,d),o?a():r=!0};window.addEventListener(l,d)}},onCustomResolve:({el:e,config:t,resolve:s})=>{const{module:n}=t;o=s,n&&r?a():n||queueMicrotask(()=>{o===s&&a()})}},t)}},r={type:"script",handler:(e,s)=>i({...e,tag:"script",dom:!0,onElement:(e,{src:s,module:n,async:i,defer:o,crossOrigin:r,integrity:l,bypassCache:a})=>{n&&(e.type="module"),i&&(e.async=i),o&&(e.defer=o),r&&(e.crossOrigin=r),l&&(e.integrity=l),s&&(e.src=s+t(s,a))}},s)},l={type:"style",handler:(e,t)=>{var n;const o={...e,code:null==(n=e.code)?void 0:n.replace(/<style.*?>|<\/style>/gi,"")};return i({...o,tag:"style",dom:!0,onElement:(e,{code:t})=>{t&&(e.textContent=t)},onCustomResolve:({el:e,config:t,resolve:n})=>{const{tag:i,onComplete:o}=t;s({tag:i,type:"INLINE_STYLE_SUCCESS",config:t}),s({tag:i,type:"PROCESS_COMPLETED",config:t}),null==o||o(),n()}},t)}},a={type:"stylesheet",handler:(e,s)=>i({...e,tag:"link",dom:!0,onElement:(e,{href:s,crossOrigin:n,bypassCache:i})=>{e.rel="stylesheet",n&&(e.crossOrigin=n),e.href=s+t(s,i)}},s)},c={type:"pixel",handler:(e,n)=>i({...e,tag:"img",dom:!0,onElement:(e,{style:s={display:"none"},dom:n,src:i,bypassCache:o})=>{if(n||(e=new window.Image),e.src=i+t(i,o),e.width=1,e.height=1,s&&"object"==typeof s)for(const[t,r]of Object.entries(s))e.style.setProperty(t,r)},onCustomResolve:({el:e,config:t,resolve:n})=>{const{tag:i,dom:o,onComplete:r}=t,l=()=>{s({tag:i,type:"IMAGE_LOADED",config:t}),s({tag:i,type:"PROCESS_COMPLETED",config:t}),null==r||r(),n()};o?e.onload=()=>l():l()}},n)},d={type:"shadow",handler:(e,t)=>i({...e,onBeforeStart:async({tag:e})=>await window.customElements.whenDefined(e),onElement:(e,{shadowData:t})=>{e.data=t||{},(null==t?void 0:t.hidden)&&e.setAttribute("hidden","")},onCustomResolve:({el:e,config:t,resolve:i})=>{const{tag:o,shadowData:r,onComplete:l,onError:a}=t,c=()=>{const c=null==r?void 0:r.container;let d=null;if("body"===c)d=document.body;else if("string"==typeof c&&c)try{d=document.querySelector(c)}catch(u){d=null}if(!d){const e=new Error(`Container not found: ${c}`);return n({tag:o,type:"SHADOW_FAILED",config:t,error:e}),null==a||a(e),void i(e)}"top"===(null==r?void 0:r.position)?d.insertBefore(e,d.firstChild):d.appendChild(e),s({tag:o,type:"SHADOW_SUCCESS",config:t}),s({tag:o,type:"PROCESS_COMPLETED",config:t}),null==l||l(),i()};"interactive"===document.readyState||"complete"===document.readyState?c():document.addEventListener("DOMContentLoaded",c,{once:!0})}},t)},u={type:"html",handler:(e,t)=>i({...e,dom:!0,onElement:(e,{html:t="",id:s="",className:n="",style:i={}})=>{if(t&&(e.innerHTML=t),s&&(e.id=s),n&&(e.className=Array.isArray(n)?n.join(" "):n),i&&"object"==typeof i)for(const[o,r]of Object.entries(i))e.style.setProperty(o,r)},onCustomResolve:({el:e,config:t,resolve:n})=>{const{tag:i,onComplete:o}=t;s({tag:i,type:"HTML_SUCCESS",config:t}),s({tag:i,type:"PROCESS_COMPLETED",config:t}),null==o||o(),n()}},t)};const h=(e,t)=>e.slice(t.length),f=(e,t)=>"string"==typeof e&&e.startsWith(t),p=(e,t)=>{let s=null;try{s=document.querySelector(e)}catch(o){return void t(null)}if(s)return void t(s);if("function"!=typeof MutationObserver)return void t(null);const n=document.body||document.documentElement;if(!n)return void t(null);const i=new MutationObserver(()=>{const s=document.querySelector(e);s&&(i.disconnect(),t(s))});i.observe(n,{childList:!0,subtree:!0})};e.registerTypes([r,o,l,a,c,d,u]).use(function(e){e.initActions.add(function(){e.logger={VERSION:"qsl-logger",LOG:{LOGGER_LOADED:"[QSL] Logger loaded",LOGGER_LOAD_ERROR:"[QSL] Logger load error:",UNKNOWN_TYPE:"[QSL] Unknown type:",PROCESS_STARTED:"[QSL] Process started:",PROCESS_COMPLETED:"[QSL] Process completed:",PROCESS_FAILED:"[QSL] Process failed:",STYLESHEET_STARTED:"[QSL] Stylesheet loading:",STYLESHEET_LOADED:"[QSL] Stylesheet loaded:",STYLESHEET_FAILED:"[QSL] Stylesheet failed to load:",INLINE_SCRIPT_STARTED:"[QSL] Inline script loading:",INLINE_SCRIPT_SUCCESS:"[QSL] Inline script loaded:",INLINE_SCRIPT_ERROR:"[QSL] Inline script load error:",INLINE_STYLE_STARTED:"[QSL] Inline style loading:",INLINE_STYLE_SUCCESS:"[QSL] Inline style loaded:",INLINE_STYLE_ERROR:"[QSL] Inline style load error:",IMAGE_STARTED:"[QSL] Image pixel loading:",IMAGE_LOADED:"[QSL] Image pixel loaded:",IMAGE_FAILED:"[QSL] Image pixel failed:",SHADOW_STARTED:"[QSL] Shadow element loading:",SHADOW_SUCCESS:"[QSL] Shadow element loaded:",SHADOW_FAILED:"[QSL] Shadow element failed:",HTML_STARTED:"[QSL] HTML element loading:",HTML_SUCCESS:"[QSL] HTML element loaded:",HTML_FAILED:"[QSL] HTML element failed:",PRELOAD_ERROR:"[QSL] Preload error:",FLOW_DEP_SKIPPED:"[QSL] Flow dependency missed:",DEP_NOT_FOUND:"[QSL] Dependency not found:",RESET:"[QSL] Global reset",ALL_COMPLETED:"[QSL] Loading is completed"},log(e,...t){this.LOG[e]?console.log(this.LOG[e],...t,{timestamp:Date.now()}):console.log("[QSL] "+e,...t)},error(e,...t){this.LOG[e]?console.error(this.LOG[e],...t):console.error("[QSL] "+e,...t)}}})}).use(function(e){const t=new Map,s=new WeakMap;let n=null,i=null,o=!1;const r=e=>{if(!e)return"";try{return e.includes("://")?new URL(e).pathname:e.split("?")[0].split("#")[0]}catch(t){return e.split("?")[0].split("#")[0]}};e.loadActions.add(function(){if(o)return;n=document.addEventListener,i=window.addEventListener,o=!0;const e=(e,n,i)=>{var o;let l=null,a=null;if(document.currentScript){const e=s.get(document.currentScript);e&&(l=e.processId,a=e.flowId)}if(!l&&this.currentProcessPerFlow.size)for(const[t,s]of this.currentProcessPerFlow)if(s){l=s,a=t;break}if(!l){const e=(new Error).stack;if(e){const t=e.split("\n");for(let e=2;e<t.length;e++){const s=t[e].match(/([^()\s]+\.js(?:\?[^:)]*)?):\d+(?::\d+)?/);if(s){const e=s[1],t=e.indexOf("?"),n=-1===t?e.trim():e.slice(0,t).trim();if(n){const e=n.indexOf("?"),t=n.indexOf("#"),s=-1===e?-1===t?n.length:t:-1===t?e:Math.min(e,t);let i=n.slice(0,s);try{i.includes("://")&&(i=new URL(i).pathname)}catch(c){}const o=i.lastIndexOf("/"),d=-1===o?i:i.slice(o+1);for(const[n,c]of this.flows){for(const e of c)if(e.src&&"script"===e.type){const t=r(e.src),s=t.lastIndexOf("/"),o=-1===s?t:t.slice(s+1);if(i===t||d&&d===o){l=e.id,a=n;break}}if(l)break}if(l)break}}}}}if(l&&a){const s=this.flows.get(a),r=null==s?void 0:s.find(e=>e.id===l||e.id===this.PREFIX+l);if(r){if(!1!==r.fireEvents&&!1!==(null==(o=this.flowOptions.get(a))?void 0:o.fireEvents)){const s=`${e}:${r.id}`;t.has(r.id)||t.set(r.id,[]);const o=t.get(r.id);o.some(e=>e.name===s)||o.push({type:n,name:s}),i&&(e=s)}}}return e};document.addEventListener=(t,s,i)=>{if("DOMContentLoaded"===t&&this.LIFECYCLE.DOMREADY){const s=e.call(this,t,this.EVENTS.DOMREADY,!0);s!==t&&(t=s,queueMicrotask(()=>document.dispatchEvent(new Event(s))))}return n.call(document,t,s,i)},window.addEventListener=(t,s,n)=>{if("load"===t&&this.LIFECYCLE.LOADED){const s=e.call(this,t,this.EVENTS.LOADED,!0);s!==t&&(t=s,queueMicrotask(()=>window.dispatchEvent(new Event(s))))}return i.call(window,t,s,n)}}),e.handlerCallbacksFilters.add(function(e){return{registerProcessElement:(e,t)=>{s.set(e,{flowId:t.flowId,processId:t.id})}}}),e.processCompleteActions.add(function(e){const s=t.get(e.id);if(s&&Array.isArray(s))for(const t of s)t.type===this.EVENTS.DOMREADY?this.LIFECYCLE.DOMREADY?document.dispatchEvent(new Event(t.name)):document.addEventListener("DOMContentLoaded",()=>{document.dispatchEvent(new Event(t.name))},{once:!0}):t.type===this.EVENTS.LOADED&&(this.LIFECYCLE.LOADED?window.dispatchEvent(new Event(t.name)):window.addEventListener("load",()=>{window.dispatchEvent(new Event(t.name))},{once:!0}))}),e.resetActions.add(function(){o&&n&&i&&(document.addEventListener=n,window.addEventListener=i,o=!1)}),e.customEvents=t}).use(function(e){e.loadActions.add(function(){const e=(t,s,n=new Set)=>{if(n.has(t))return!0;n.add(t);const i=s(t)||[];for(const o of i)if(e(o,s,new Set(n)))return!0;return!1},t=e=>{var t;return(null==(t=this.flowOptions.get(this.normalizeFlowId(e)))?void 0:t.depends)||[]};for(const[n,i]of this.flowOptions.entries())Array.isArray(i.depends)&&i.depends.length&&e(n,t)&&(this.log("CIRC_FLOW_DEP_SKIPPED",n,i.depends),this.setFlowOptions({status:this.FLOW_STATE.COMPLETED},n));const s=e=>{for(const t of this.flows.values()){const s=t.find(t=>t.id===e);if(s&&Array.isArray(s.depends))return s.depends.map(e=>this.PREFIX+e)}return[]};for(const n of this.flows.values())for(const t of n)Array.isArray(t.depends)&&t.depends.length&&e(t.id,s)&&(this.log("CIRC_PROCESS_DEP_SKIPPED",t.id,t.depends),t.condition=!1)}),e.logger&&"qsl-logger"===e.logger.VERSION&&(e.logger.LOG.CIRC_FLOW_DEP_SKIPPED="[QSL] Circular flow dependency skipped:",e.logger.LOG.CIRC_PROCESS_DEP_SKIPPED="[QSL] Circular process dependency skipped:")}).use(function(e){e.conditionHandlers.add(function(e){return"string"==typeof e&&e.startsWith("media:")?!window.matchMedia(e.slice(6)).matches:null})}).use(function(e){e.conditionHandlers.add(function(e){var t;if("string"!=typeof e||!e.startsWith("lang:"))return null;const s=e.split(":"),n=s[1]||"equals",i=s.slice(2).join(":"),o=navigator.language||(null==(t=navigator.languages)?void 0:t[0])||"";switch(n){case"equals":case"is":return o!==i;case"contains":return!o.includes(i);case"startsWith":return!o.startsWith(i);case"in":return!i.split(",").map(e=>e.trim()).includes(o);default:return!0}})}).use(function(e){e.conditionHandlers.add(function(e){if("string"!=typeof e||!e.startsWith("tz:")&&!e.startsWith("timezone:"))return null;const t=e.split(":"),s=t[1]||"equals",n=t.slice(2).join(":");try{const e=Intl.DateTimeFormat().resolvedOptions().timeZone,t=-(new Date).getTimezoneOffset()/60;switch(s){case"equals":case"is":return e!==n;case"contains":return!e.includes(n);case"offset":return t!==parseInt(n);default:return!0}}catch(i){return!0}})}).use(function(e){e.conditionHandlers.add(function(e){if("string"!=typeof e||!e.startsWith("url:"))return null;const t=window.location,s=t.href,n=t.pathname,i=t.search,o=t.hostname,r=e.split(":"),l=r[1],a=r.slice(2).join(":");if(!l)return!0;switch(l){case"contains":return!s.includes(a);case"path":return!n.includes(a);case"pathStartsWith":return!n.startsWith(a);case"pathEndsWith":return!n.endsWith(a);case"query":if(i){const e=new URLSearchParams(i);if(a.includes("=")){const[t,s]=a.split("=");return e.get(t)!==s}return!e.has(a)}return!0;case"hostname":return!o.includes(a);case"matches":try{return!new RegExp(a).test(s)}catch(c){return!0}case"pathMatches":try{return!new RegExp(a).test(n)}catch(c){return!0}default:return!0}})}).use(function(e){e.conditionHandlers.add(function(e){if("string"!=typeof e||!e.startsWith("ua:")&&!e.startsWith("userAgent:"))return null;const t=e.split(":"),s=t[1]||"contains",n=t.slice(2).join(":"),i=navigator.userAgent||"",o=i.toLowerCase(),r=n.toLowerCase();switch(s){case"contains":if(!o.includes(r))return!0;break;case"equals":case"is":if(i!==n)return!0;break;case"matches":try{if(!new RegExp(n,"i").test(i))return!0}catch(l){return!0}break;case"browser":if(!{chrome:/chrome/i.test(i)&&!/edg|opr/i.test(i),firefox:/firefox/i.test(i),safari:/safari/i.test(i)&&!/chrome|chromium|edg|opr/i.test(i),edge:/edg/i.test(i),opera:/opr/i.test(i),ie:/msie|trident/i.test(i),chromium:/chromium/i.test(i)}[r])return!0;break;case"device":const e=/mobile|android|iphone|ipod|blackberry|iemobile|opera mini/i.test(i),t=/tablet|ipad|playbook|silk/i.test(i)||e&&/android/i.test(i)&&!/mobile/i.test(i),s=!e&&!t;switch(r){case"mobile":if(!e)return!0;break;case"tablet":if(!t)return!0;break;case"desktop":if(!s)return!0;break;default:return!0}break;case"os":case"platform":if(!{windows:/win/i.test(i),mac:/mac/i.test(i),ios:/iphone|ipad|ipod/i.test(i),android:/android/i.test(i),linux:/linux/i.test(i)&&!/android/i.test(i),unix:/unix/i.test(i),chromeos:/cros/i.test(i)}[r])return!0;break;default:return!0}return!1})}).use(function(e){e.triggerHandlers.add(function(e){return"load"!==e?null:e=>{"complete"===document.readyState?e():window.addEventListener("load",()=>e(),{once:!0})}})}).use(function(e){e.triggerHandlers.add(function(e){return"idle"!==e?null:e=>{"function"==typeof window.requestIdleCallback?window.requestIdleCallback(()=>e()):setTimeout(()=>e(),200)}})}).use(function(e){e.triggerHandlers.add(function(e){return"domready"!==e?null:e=>{"interactive"===document.readyState||"complete"===document.readyState?e():document.addEventListener("DOMContentLoaded",()=>e(),{once:!0})}})}).use(function(e){e.triggerHandlers.add(function(e){if(!f(e,"delay:"))return null;const t=parseInt(h(e,"delay:"),10);return e=>setTimeout(e,Number.isFinite(t)&&t>0?t:0)})}).use(function(e){e.triggerHandlers.add(function(e){if(!f(e,"hover:"))return null;const t=h(e,"hover:");return e=>{p(t,t=>{t?t.addEventListener("mouseover",()=>e(),{once:!0,passive:!0}):e()})}})}).use(function(e){e.triggerHandlers.add(function(e){if(!f(e,"visible:"))return null;const t=h(e,"visible:");return e=>{p(t,t=>{if(!t||"function"!=typeof IntersectionObserver)return void e();const s=new IntersectionObserver(t=>{for(const n of t)if(n.isIntersecting)return s.disconnect(),void e()});s.observe(t)})}})}).use(function(e){e.triggerHandlers.add(function(e){if(!f(e,"appears:"))return null;const t=h(e,"appears:");return e=>p(t,()=>e())})}).use(function(e){e.triggerHandlers.add(function(e,t){if(!f(e,"media:"))return null;const s=h(e,"media:");return e=>{if(!s.length||"function"!=typeof window.matchMedia)return t&&(t.skipped=!0),void e();const n=window.matchMedia(s);if(n.matches)return void e();const i=t=>{t.matches&&(n.removeEventListener("change",i),e())};n.addEventListener("change",i)}})}).init()}();
1
+ !function(){"use strict";const e={VERSION:"0.1.2",PREFIX:"qsl-",FLOW_TYPE:{DEFAULT:"default",ORDERED:"ordered"},FLOW_STATE:{READY:"READY",RUNNING:"RUNNING",COMPLETED:"COMPLETED"},FLOW_OPTIONS:{delay:0,priority:0,between:null,trigger:null,condition:null,beforeStart:null,onComplete:null,group:null,paused:!1,preload:!1,fireEvents:!0,depends:[]},EVENTS:{STARTED:"QSL:started",COMPLETED:"QSL:completed",ERROR:"QSL:error",FLOW_STARTED:"QSL:flow:started",FLOW_COMPLETED:"QSL:flow:completed",ALL_COMPLETED:"QSL:all:completed",SKIPPED:"QSL:skipped",DOMREADY:"QSL:domready",LOADED:"QSL:loaded"},LIFECYCLE:{DOMREADY:"interactive"===document.readyState||"complete"===document.readyState,LOADED:!1},CALLBACK:"QSLReady",types:new Map,flows:new Map,flowOptions:new Map,flowGroups:new Map,currentProcessPerFlow:new Map,pendingFlows:new Set,pendingProcesses:new Set,completedProcesses:new Set,loadActions:new Set,initActions:new Set,addProcessFilters:new Set,completedFlowsActions:new Set,flowIdFilters:new Set,conditionHandlers:new Set,triggerHandlers:new Set,processCompleteActions:new Set,allCompleteActions:new Set,resetActions:new Set,handlerCallbacksFilters:new Set,onAllComplete:null,globalResolve:null,logger:null,hasStarted:!1,eventsEnabled:!1,initialized:!1,completing:!1,autoReset:!0,globalBetween:0,async init(){if(this.initialized)return this;const e=document.currentScript;if(window.__QSL__=window.__QSL__||this,"interactive"===document.readyState||"complete"===document.readyState?this.LIFECYCLE.DOMREADY=!0:document.addEventListener("DOMContentLoaded",()=>this.LIFECYCLE.DOMREADY=!0,{once:!0}),"complete"===document.readyState?this.LIFECYCLE.LOADED=!0:window.addEventListener("load",()=>this.LIFECYCLE.LOADED=!0,{once:!0}),this.registerType("console",e=>new Promise(t=>{var s;null==(s=e.onBeforeStart)||s.call(e),setTimeout(()=>{var s;e.message&&this.log(e.message,{timestamp:Date.now()}),null==(s=e.onComplete)||s.call(e),t()},e.delay||0)})),window.addEventListener("QSL:log",e=>this.log(e.detail.type,e.detail.config.id)),window.addEventListener("QSL:error",e=>this.error(e.detail.type,e.detail.error,e.detail.config.id)),this.initActions.size)for(const n of this.initActions)"function"==typeof n&&await n.call(this);this.initialized=!0;const t=e&&e.src?new URL(e.src,document.baseURI):null;if(!t||"true"!==t.searchParams.get("async"))return this;const s=t.searchParams.get("callback")||this.CALLBACK;return"function"==typeof window[s]&&window[s](),this},use(e,...t){return"function"==typeof e&&e(this,...t),this},add(e,t=null){if(!e||"object"!=typeof e)return this;if(e.id=e.id?this.PREFIX+e.id:this.PREFIX+Math.random().toString(36).slice(2),e.skipped=!1,e.type||(e.type="console"),Array.isArray(e.depends)&&(e.depends=[...new Set(e.depends)]),this.addProcessFilters.size)for(const n of this.addProcessFilters)"function"==typeof n&&([t,e]=n.call(this,t,e));const s=this.normalizeFlowId(t);return e.flowId=s,this.getOrCreateFlow(s).push(e),this},async load({between:e=!1}={}){if(!this.hasStarted){this.hasStarted=!0,this.globalBetween=e;for(const e of this.loadActions)"function"==typeof e&&e.call(this);return new Promise(e=>{if(!this.flows.size)return this.reset(),e();this.globalResolve=e,this.processFlows()})}},reset(){if(this.resetActions.size)for(const e of this.resetActions)"function"==typeof e&&e.call(this);return this.flows.clear(),this.flowOptions.clear(),this.flowGroups.clear(),this.pendingFlows.clear(),this.pendingProcesses.clear(),this.completedProcesses.clear(),this.currentProcessPerFlow.clear(),this.onAllComplete=null,this.globalResolve=null,this.hasStarted=!1,this.globalBetween=0,this.log("RESET"),this},destroy(){return this.reset(),this.types.clear(),this.initActions.clear(),this.loadActions.clear(),this.addProcessFilters.clear(),this.completedFlowsActions.clear(),this.flowIdFilters.clear(),this.conditionHandlers.clear(),this.triggerHandlers.clear(),this.processCompleteActions.clear(),this.allCompleteActions.clear(),this.resetActions.clear(),this.handlerCallbacksFilters.clear(),this.logger=null,this.eventsEnabled=!1,this.initialized=!1,this},setLogger(e){return!e||"function"!=typeof e&&"object"!=typeof e||(this.logger=e),this},setOnAllComplete(e){return this.onAllComplete="function"==typeof e?e:null,this},useEvents(){return this.eventsEnabled=!0,this},log(e,...t){this.logger&&"function"==typeof this.logger.log&&this.logger.log(e,...t)},error(e,...t){this.logger&&"function"==typeof this.logger.error&&this.logger.error(e,...t)},fire(e,t){this.eventsEnabled&&this.EVENTS[e]&&window.dispatchEvent(new CustomEvent(this.EVENTS[e],{detail:t}))},normalizeFlowId(e){return!0===e?e=this.FLOW_TYPE.ORDERED:"string"!=typeof e&&(e=this.FLOW_TYPE.DEFAULT),e},registerType(e,t){return"string"!=typeof e||"function"!=typeof t||this.types.set(e,t),this},registerTypes(e){if(!e||"object"!=typeof e)return this;const t=Array.isArray(e)?e:Object.entries(e).map(([e,t])=>"function"==typeof t?{type:e,handler:t}:t);for(const s of t)s&&this.registerType(s.type,s.handler);return this},pauseGroup(e){const t=this.flowGroups.get(e);if(!t)return this;for(const s of t)this.setFlowOptions({paused:!0},s);return this},runGroup(e){const t=this.flowGroups.get(e);if(!t)return this;for(const s of t)this.setFlowOptions({paused:!1},s),this.runFlow(s);return this},runFlow(e,t=!1){const s=this.flows.get(e),n=this.flowOptions.get(e);return s&&n&&n.status===this.FLOW_STATE.READY?(this.processFlows(e,t),this):this},getOrCreateFlow(e){return this.flows.has(e)||(this.flows.set(e,[]),this.flowOptions.set(e,{...this.FLOW_OPTIONS,ordered:e===this.FLOW_TYPE.ORDERED,status:this.FLOW_STATE.READY})),this.flows.get(e)},setFlowOptions(e={},t=null){if(t=this.normalizeFlowId(t),this.getOrCreateFlow(t),!e||"object"!=typeof e)return this;const s=this.flowOptions.get(t);return Array.isArray(e.depends)&&e.depends.length&&(e.depends=[...new Set(e.depends)],e.paused=!0,this.pendingFlows.add(t)),e.group&&(this.flowGroups.has(e.group)||this.flowGroups.set(e.group,new Set),this.flowGroups.get(e.group).add(t)),this.flowOptions.set(t,{...s,...e}),this},checkPendingFlows(){if(this.pendingFlows.size)for(const e of this.pendingFlows){const t=this.flowOptions.get(e);t&&t.depends&&t.depends.every(e=>{const t=this.flowOptions.get(this.normalizeFlowId(e));return t&&t.status===this.FLOW_STATE.COMPLETED})&&(this.setFlowOptions({paused:!1},e),this.pendingFlows.delete(e),this.runFlow(e))}},checkPendingProcesses(){if(this.pendingProcesses.size)for(const e of this.pendingProcesses){const t=e.depends.filter(e=>{const t=Array.from(this.flows.values()).some(t=>t.some(t=>t.id===this.PREFIX+e));return!this.completedProcesses.has(this.PREFIX+e)&&!t});if(t.length){this.pendingProcesses.delete(e),this.log("DEP_NOT_FOUND",e.id,`${t.join(", ")}`),e._depsResolved=!0,e._triggered=!0,e._waitResolve&&e._waitResolve();continue}e.depends.every(e=>this.completedProcesses.has(this.PREFIX+e))&&(this.pendingProcesses.delete(e),e._depsResolved=!0,e._triggered&&e._waitResolve&&e._waitResolve())}},async maybeComplete(){var e;if(!this.hasStarted)return;if(this.pendingFlows.size)for(const n of this.pendingFlows){const e=this.flowOptions.get(n);e&&e.depends&&e.depends.some(e=>!this.flowOptions.has(this.normalizeFlowId(e)))&&(this.setFlowOptions({status:this.FLOW_STATE.COMPLETED},n),this.pendingFlows.delete(n),this.log("FLOW_DEP_SKIPPED",{flow:n,depends:`${e.depends.filter(e=>!this.flowOptions.has(this.normalizeFlowId(e))).join(", ")}`}))}let t=!!this.flowOptions.size&&Array.from(this.flowOptions.values()).every(e=>e.status===this.FLOW_STATE.COMPLETED),s=t;if(this.flows.size&&this.completedFlowsActions.size)for(const n of this.completedFlowsActions)s=n.call(this,t,this.flows,this.flowOptions);if(s&&!this.completing){if(this.completing=!0,this.log("ALL_COMPLETED"),this.fire("ALL_COMPLETED"),null==(e=this.onAllComplete)||e.call(this),null!==this.globalResolve&&this.globalResolve(),this.allCompleteActions.size)for(const e of this.allCompleteActions)"function"==typeof e&&e.call(this);this.autoReset&&this.reset(),this.completing=!1}},processFlows(e=null,t=!1){if(!this.flows.size)return;let s=e?[e]:Array.from(this.flows.keys());if(s.length&&this.flowIdFilters.size)for(const n of this.flowIdFilters)"function"==typeof n&&(s=n.call(this,s));s.sort((e,t)=>{const s=this.flowOptions.get(e),n=this.flowOptions.get(t),i=null!=(null==s?void 0:s.trigger),o=null!=(null==n?void 0:n.trigger);if(i&&!o)return 1;if(!i&&o)return-1;const r=(null==s?void 0:s.priority)||0;return((null==n?void 0:n.priority)||0)-r});for(const n of s){const s=this.flowOptions.get(n);if(s&&s.status!==this.FLOW_STATE.COMPLETED)if(this.getConditionStatus(s.condition))this.setFlowOptions({status:this.FLOW_STATE.COMPLETED},n);else if(!s.paused){if((null===e||e&&!t)&&null!=s.trigger){const e=this.getTriggerFunction(s.trigger,s);if(e){this.setFlowOptions({paused:!0},n);let t=!1;e(()=>{t||(t=!0,this.setFlowOptions({paused:!1},n),this.runFlow(n,!0))});continue}}this.setFlowOptions({status:this.FLOW_STATE.RUNNING},n),(async()=>{var e,t;null==(e=s.beforeStart)||e.call(s),s.delay&&s.delay>0&&await new Promise(e=>setTimeout(e,s.delay));const i=(this.flows.get(n)||[]).slice();if(i.sort((e,t)=>(t.priority||0)-(e.priority||0)),(s.preload||s.prefetch)&&!s.trigger)for(const n of i)if(!n.trigger&&("script"===n.type&&n.src||"style"===n.type&&n.href))try{const e=document.createElement("link");e.rel=s.preload?"preload":"prefetch",e.href=n.src||n.href,e.as="script"===n.type?"script":"style",n.crossOrigin&&(e.crossOrigin=n.crossOrigin),document.head.appendChild(e)}catch(r){this.error("PRELOAD_ERROR",r,n.id)}const o=void 0!==s.between&&null!==s.between?s.between:this.globalBetween;if(s.ordered){let e=Promise.resolve();i.forEach((t,s)=>{e=e.then(async()=>{s>0&&o&&await new Promise(e=>setTimeout(e,o)),await this.run(t)})}),await e}else{const e=i.map(async(e,t)=>(t>0&&o&&await new Promise(e=>setTimeout(e,o)),this.run(e)));await Promise.all(e)}this.setFlowOptions({status:this.FLOW_STATE.COMPLETED},n),null==(t=s.onComplete)||t.call(s),this.checkPendingFlows(),this.maybeComplete()})()}}this.checkPendingFlows(),this.maybeComplete()},async run(e){if(!e._running&&!this.getConditionStatus(e.condition)){if(e._running=!0,e._waitPromise||(e._triggered=!1,e._depsResolved=!1,e._waitPromise=new Promise(t=>e._waitResolve=t)),null!=e.trigger){const t=this.getTriggerFunction(e.trigger,e);t?t(()=>{e._triggered=!0,e._depsResolved&&e._waitResolve()}):e._triggered=!0}else e._triggered=!0;if(Array.isArray(e.depends)&&e.depends.length){const t=e.depends.filter(e=>{const t=Array.from(this.flows.values()).some(t=>t.some(t=>t.id===this.PREFIX+e));return!this.completedProcesses.has(this.PREFIX+e)&&!t});if(t.length)this.log("DEP_NOT_FOUND",e.id,`${t.join(", ")}`),e._depsResolved=!0,e._triggered=!0,e._waitResolve&&e._waitResolve();else{e.depends.every(e=>this.completedProcesses.has(this.PREFIX+e))?(e._depsResolved=!0,e._triggered&&e._waitResolve()):this.pendingProcesses.add(e)}}else e._depsResolved=!0,e._triggered&&e._waitResolve();return await e._waitPromise,this.execute(e)}},getConditionStatus(e){if(null==e)return!1;if(Array.isArray(e))return e.some(e=>this.getConditionStatus(e));if("object"==typeof e&&e.operator){const{operator:t,conditions:s}=e;return!!Array.isArray(s)&&("or"===t?s.every(e=>this.getConditionStatus(e)):"and"===t&&s.some(e=>this.getConditionStatus(e)))}if("function"==typeof e&&!e())return!0;if("boolean"==typeof e&&!e)return!0;if(this.conditionHandlers.size)for(const t of this.conditionHandlers)if("function"==typeof t){const s=t.call(this,e);if(!0===s||!1===s)return s}return!1},getTriggerFunction(e,t){if(null==e)return null;if("function"==typeof e)return t=>e(t);if(Array.isArray(e))return s=>{const n=e.map(e=>this.getTriggerFunction(e,t)).filter(e=>e);if(0===n.length)return void s();let i=0;const o=()=>{++i===n.length&&s()};n.forEach(e=>e(o))};if("object"==typeof e&&e.operator){const{operator:s,triggers:n}=e;return Array.isArray(n)?"or"===s?e=>{const s=n.map(e=>this.getTriggerFunction(e,t)).filter(e=>e);if(0===s.length)return void e();let i=!1;const o=()=>{i||(i=!0,e())};s.forEach(e=>e(o))}:"and"===s?e=>{const s=n.map(e=>this.getTriggerFunction(e,t)).filter(e=>e);if(0===s.length)return void e();let i=0;const o=()=>{++i===s.length&&e()};s.forEach(e=>e(o))}:null:null}if(this.triggerHandlers.size)for(const s of this.triggerHandlers)if("function"==typeof s){const n=s.call(this,e,t);if(n&&"function"==typeof n)return n}return!0===e||"interaction"===e?e=>this.waitForInteraction(e):null},waitForInteraction(e){["click","keydown","wheel","mousedown","mousemove","touchstart"].forEach(t=>window.addEventListener(t,()=>e(),{once:!0,passive:!0}))},async execute(e){const t=async()=>{if(this.processCompleteActions.size)for(const t of this.processCompleteActions)"function"==typeof t&&t.call(this,e);this.completedProcesses.add(e.id),e._running=!1,this.checkPendingProcesses()};if(e.skipped)return this.fire("SKIPPED",{...e,id:e.id}),void t();const s=this.types.get(e.type);if(!s)return this.log("UNKNOWN_TYPE",e.type,e.id),void t();this.fire("STARTED",{...e,id:e.id});const n={};if(this.handlerCallbacksFilters.size)for(const i of this.handlerCallbacksFilters)if("function"==typeof i){const t=i.call(this,e);t&&"object"==typeof t&&Object.assign(n,t)}return s(e,n).then(()=>{this.fire("COMPLETED",{...e,id:e.id}),t()}).catch(()=>{this.fire("ERROR",{...e,id:e.id}),t()})}},t=(e,t)=>t?(e.includes("?")?"&":"?")+Date.now():"",s=e=>{window.dispatchEvent(new CustomEvent("QSL:log",{detail:e}))},n=e=>{window.dispatchEvent(new CustomEvent("QSL:error",{detail:e}))},i=(e,t={})=>new Promise(async i=>{var o;const{flowId:r,tag:l,id:a,delay:c,data:d,onBeforeStart:u,onComplete:h,onError:f,footer:p,dom:g,onElement:E,onCustomResolve:w}=e;if(r&&l&&a)try{u&&await u(e),s({tag:l,type:"PROCESS_STARTED",config:e}),c&&await new Promise(e=>setTimeout(e,c));let r=document.createElement(l);if(null==E||E(r,e),null==(o=t.registerProcessElement)||o.call(t,r,e),d&&"object"==typeof d)for(const[e,t]of Object.entries(d))r.setAttribute(`data-${e.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/[^a-z0-9_-]/g,"").replace(/^-/,"")}`,String(t));w||(r.onload=()=>{s({tag:l,type:"PROCESS_COMPLETED",config:e}),null==h||h(),i()}),r.onerror=t=>{n({tag:l,type:"PROCESS_FAILED",config:e}),null==f||f(t),i(t)},g&&(p?document.body:document.head).appendChild(r),null==w||w({el:r,config:e,resolve:i})}catch(m){n({tag:l,type:"PROCESS_FAILED",config:e,error:m}),null==f||f(m),i(m)}else i()}),o={type:"inline-script",handler:(e,t)=>{var n;let o=null,r=!1;const l=`QSL:inline-script:completed:${e.id}`,a=()=>{var t;s({tag:"inline-script",type:"INLINE_SCRIPT_SUCCESS",config:e}),s({tag:"inline-script",type:"PROCESS_COMPLETED",config:e}),null==(t=null==e?void 0:e.onComplete)||t.call(e),null==o||o()},c={...e,code:null==(n=e.code)?void 0:n.replace(/<script.*?>|<\/script>/gi,"")};return i({...c,tag:"script",dom:!0,onElement:(e,t)=>{const{code:s,module:n,id:i,flowId:c}=t;if(s&&(e.textContent=s),n){e.type="module";const t=e.textContent,s=JSON.stringify(String(c)),n=`(function(){window.__QSL__.currentProcessPerFlow.set(${s},${JSON.stringify(String(i))});try{${t}}finally{window.__QSL__.currentProcessPerFlow.delete(${s});window.dispatchEvent(new Event(${JSON.stringify(String(l))}));}})();`;e.textContent=n;const d=()=>{window.removeEventListener(l,d),o?a():r=!0};window.addEventListener(l,d)}},onCustomResolve:({el:e,config:t,resolve:s})=>{const{module:n}=t;o=s,n&&r?a():n||queueMicrotask(()=>{o===s&&a()})}},t)}},r={type:"script",handler:(e,s)=>i({...e,tag:"script",dom:!0,onElement:(e,{src:s,module:n,async:i,defer:o,crossOrigin:r,integrity:l,bypassCache:a})=>{n&&(e.type="module"),i&&(e.async=i),o&&(e.defer=o),r&&(e.crossOrigin=r),l&&(e.integrity=l),s&&(e.src=s+t(s,a))}},s)},l={type:"style",handler:(e,t)=>{var n;const o={...e,code:null==(n=e.code)?void 0:n.replace(/<style.*?>|<\/style>/gi,"")};return i({...o,tag:"style",dom:!0,onElement:(e,{code:t})=>{t&&(e.textContent=t)},onCustomResolve:({el:e,config:t,resolve:n})=>{const{tag:i,onComplete:o}=t;s({tag:i,type:"INLINE_STYLE_SUCCESS",config:t}),s({tag:i,type:"PROCESS_COMPLETED",config:t}),null==o||o(),n()}},t)}},a={type:"stylesheet",handler:(e,s)=>i({...e,tag:"link",dom:!0,onElement:(e,{href:s,crossOrigin:n,bypassCache:i})=>{e.rel="stylesheet",n&&(e.crossOrigin=n),e.href=s+t(s,i)}},s)},c={type:"pixel",handler:(e,n)=>i({...e,tag:"img",dom:!0,onElement:(e,{style:s={display:"none"},dom:n,src:i,bypassCache:o})=>{if(n||(e=new window.Image),e.src=i+t(i,o),e.width=1,e.height=1,s&&"object"==typeof s)for(const[t,r]of Object.entries(s))e.style.setProperty(t,r)},onCustomResolve:({el:e,config:t,resolve:n})=>{const{tag:i,dom:o,onComplete:r}=t,l=()=>{s({tag:i,type:"IMAGE_LOADED",config:t}),s({tag:i,type:"PROCESS_COMPLETED",config:t}),null==r||r(),n()};o?e.onload=()=>l():l()}},n)},d={type:"shadow",handler:(e,t)=>i({...e,onBeforeStart:async({tag:e})=>await window.customElements.whenDefined(e),onElement:(e,{shadowData:t})=>{e.data=t||{},(null==t?void 0:t.hidden)&&e.setAttribute("hidden","")},onCustomResolve:({el:e,config:t,resolve:i})=>{const{tag:o,shadowData:r,onComplete:l,onError:a}=t,c=()=>{const c=null==r?void 0:r.container;let d=null;if("body"===c)d=document.body;else if("string"==typeof c&&c)try{d=document.querySelector(c)}catch(u){d=null}if(!d){const e=new Error(`Container not found: ${c}`);return n({tag:o,type:"SHADOW_FAILED",config:t,error:e}),null==a||a(e),void i(e)}"top"===(null==r?void 0:r.position)?d.insertBefore(e,d.firstChild):d.appendChild(e),s({tag:o,type:"SHADOW_SUCCESS",config:t}),s({tag:o,type:"PROCESS_COMPLETED",config:t}),null==l||l(),i()};"interactive"===document.readyState||"complete"===document.readyState?c():document.addEventListener("DOMContentLoaded",c,{once:!0})}},t)},u={type:"html",handler:(e,t)=>i({...e,dom:!0,onElement:(e,{html:t="",id:s="",className:n="",style:i={}})=>{if(t&&(e.innerHTML=t),s&&(e.id=s),n&&(e.className=Array.isArray(n)?n.join(" "):n),i&&"object"==typeof i)for(const[o,r]of Object.entries(i))e.style.setProperty(o,r)},onCustomResolve:({el:e,config:t,resolve:n})=>{const{tag:i,onComplete:o}=t;s({tag:i,type:"HTML_SUCCESS",config:t}),s({tag:i,type:"PROCESS_COMPLETED",config:t}),null==o||o(),n()}},t)};const h=(e,t)=>e.slice(t.length),f=(e,t)=>"string"==typeof e&&e.startsWith(t),p=(e,t)=>{let s=null;try{s=document.querySelector(e)}catch(o){return void t(null)}if(s)return void t(s);if("function"!=typeof MutationObserver)return void t(null);const n=document.body||document.documentElement;if(!n)return void t(null);const i=new MutationObserver(()=>{const s=document.querySelector(e);s&&(i.disconnect(),t(s))});i.observe(n,{childList:!0,subtree:!0})};e.registerTypes([r,o,l,a,c,d,u]).use(function(e){e.initActions.add(function(){e.logger={VERSION:"qsl-logger",LOG:{LOGGER_LOADED:"[QSL] Logger loaded",LOGGER_LOAD_ERROR:"[QSL] Logger load error:",UNKNOWN_TYPE:"[QSL] Unknown type:",PROCESS_STARTED:"[QSL] Process started:",PROCESS_COMPLETED:"[QSL] Process completed:",PROCESS_FAILED:"[QSL] Process failed:",STYLESHEET_STARTED:"[QSL] Stylesheet loading:",STYLESHEET_LOADED:"[QSL] Stylesheet loaded:",STYLESHEET_FAILED:"[QSL] Stylesheet failed to load:",INLINE_SCRIPT_STARTED:"[QSL] Inline script loading:",INLINE_SCRIPT_SUCCESS:"[QSL] Inline script loaded:",INLINE_SCRIPT_ERROR:"[QSL] Inline script load error:",INLINE_STYLE_STARTED:"[QSL] Inline style loading:",INLINE_STYLE_SUCCESS:"[QSL] Inline style loaded:",INLINE_STYLE_ERROR:"[QSL] Inline style load error:",IMAGE_STARTED:"[QSL] Image pixel loading:",IMAGE_LOADED:"[QSL] Image pixel loaded:",IMAGE_FAILED:"[QSL] Image pixel failed:",SHADOW_STARTED:"[QSL] Shadow element loading:",SHADOW_SUCCESS:"[QSL] Shadow element loaded:",SHADOW_FAILED:"[QSL] Shadow element failed:",HTML_STARTED:"[QSL] HTML element loading:",HTML_SUCCESS:"[QSL] HTML element loaded:",HTML_FAILED:"[QSL] HTML element failed:",PRELOAD_ERROR:"[QSL] Preload error:",FLOW_DEP_SKIPPED:"[QSL] Flow dependency missed:",DEP_NOT_FOUND:"[QSL] Dependency not found:",RESET:"[QSL] Global reset",ALL_COMPLETED:"[QSL] Loading is completed"},log(e,...t){this.LOG[e]?console.log(this.LOG[e],...t,{timestamp:Date.now()}):console.log("[QSL] "+e,...t)},error(e,...t){this.LOG[e]?console.error(this.LOG[e],...t):console.error("[QSL] "+e,...t)}}})}).use(function(e){const t=new Map,s=new WeakMap;let n=null,i=null,o=!1;const r=e=>{if(!e)return"";try{return e.includes("://")?new URL(e).pathname:e.split("?")[0].split("#")[0]}catch(t){return e.split("?")[0].split("#")[0]}};e.loadActions.add(function(){if(o)return;n=document.addEventListener,i=window.addEventListener,o=!0;const e=(e,n,i)=>{var o;let l=null,a=null;if(document.currentScript){const e=s.get(document.currentScript);e&&(l=e.processId,a=e.flowId)}if(!l&&this.currentProcessPerFlow.size)for(const[t,s]of this.currentProcessPerFlow)if(s){l=s,a=t;break}if(!l){const e=(new Error).stack;if(e){const t=e.split("\n");for(let e=2;e<t.length;e++){const s=t[e].match(/([^()\s]+\.js(?:\?[^:)]*)?):\d+(?::\d+)?/);if(s){const e=s[1],t=e.indexOf("?"),n=-1===t?e.trim():e.slice(0,t).trim();if(n){const e=n.indexOf("?"),t=n.indexOf("#"),s=-1===e?-1===t?n.length:t:-1===t?e:Math.min(e,t);let i=n.slice(0,s);try{i.includes("://")&&(i=new URL(i).pathname)}catch(c){}const o=i.lastIndexOf("/"),d=-1===o?i:i.slice(o+1);for(const[n,c]of this.flows){for(const e of c)if(e.src&&"script"===e.type){const t=r(e.src),s=t.lastIndexOf("/"),o=-1===s?t:t.slice(s+1);if(i===t||d&&d===o){l=e.id,a=n;break}}if(l)break}if(l)break}}}}}if(l&&a){const s=this.flows.get(a),r=null==s?void 0:s.find(e=>e.id===l||e.id===this.PREFIX+l);if(r){if(!1!==r.fireEvents&&!1!==(null==(o=this.flowOptions.get(a))?void 0:o.fireEvents)){const s=`${e}:${r.id}`;t.has(r.id)||t.set(r.id,[]);const o=t.get(r.id);o.some(e=>e.name===s)||o.push({type:n,name:s}),i&&(e=s)}}}return e};document.addEventListener=(t,s,i)=>{if("DOMContentLoaded"===t&&this.LIFECYCLE.DOMREADY){const s=e.call(this,t,this.EVENTS.DOMREADY,!0);s!==t&&(t=s,queueMicrotask(()=>document.dispatchEvent(new Event(s))))}return n.call(document,t,s,i)},window.addEventListener=(t,s,n)=>{if("load"===t&&this.LIFECYCLE.LOADED){const s=e.call(this,t,this.EVENTS.LOADED,!0);s!==t&&(t=s,queueMicrotask(()=>window.dispatchEvent(new Event(s))))}return i.call(window,t,s,n)}}),e.handlerCallbacksFilters.add(function(e){return{registerProcessElement:(e,t)=>{s.set(e,{flowId:t.flowId,processId:t.id})}}}),e.processCompleteActions.add(function(e){const s=t.get(e.id);if(s&&Array.isArray(s))for(const t of s)t.type===this.EVENTS.DOMREADY?this.LIFECYCLE.DOMREADY?document.dispatchEvent(new Event(t.name)):document.addEventListener("DOMContentLoaded",()=>{document.dispatchEvent(new Event(t.name))},{once:!0}):t.type===this.EVENTS.LOADED&&(this.LIFECYCLE.LOADED?window.dispatchEvent(new Event(t.name)):window.addEventListener("load",()=>{window.dispatchEvent(new Event(t.name))},{once:!0}))}),e.resetActions.add(function(){o&&n&&i&&(document.addEventListener=n,window.addEventListener=i,o=!1)}),e.customEvents=t}).use(function(e){e.loadActions.add(function(){const e=(t,s,n=new Set)=>{if(n.has(t))return!0;n.add(t);const i=s(t)||[];for(const o of i)if(e(o,s,new Set(n)))return!0;return!1},t=e=>{var t;return(null==(t=this.flowOptions.get(this.normalizeFlowId(e)))?void 0:t.depends)||[]};for(const[n,i]of this.flowOptions.entries())Array.isArray(i.depends)&&i.depends.length&&e(n,t)&&(this.log("CIRC_FLOW_DEP_SKIPPED",n,i.depends),this.setFlowOptions({status:this.FLOW_STATE.COMPLETED},n));const s=e=>{for(const t of this.flows.values()){const s=t.find(t=>t.id===e);if(s&&Array.isArray(s.depends))return s.depends.map(e=>this.PREFIX+e)}return[]};for(const n of this.flows.values())for(const t of n)Array.isArray(t.depends)&&t.depends.length&&e(t.id,s)&&(this.log("CIRC_PROCESS_DEP_SKIPPED",t.id,t.depends),t.condition=!1)}),e.logger&&"qsl-logger"===e.logger.VERSION&&(e.logger.LOG.CIRC_FLOW_DEP_SKIPPED="[QSL] Circular flow dependency skipped:",e.logger.LOG.CIRC_PROCESS_DEP_SKIPPED="[QSL] Circular process dependency skipped:")}).use(function(e){e.conditionHandlers.add(function(e){return"string"==typeof e&&e.startsWith("media:")?!window.matchMedia(e.slice(6)).matches:null})}).use(function(e){e.conditionHandlers.add(function(e){var t;if("string"!=typeof e||!e.startsWith("lang:"))return null;const s=e.split(":"),n=s[1]||"equals",i=s.slice(2).join(":"),o=navigator.language||(null==(t=navigator.languages)?void 0:t[0])||"";switch(n){case"equals":case"is":return o!==i;case"contains":return!o.includes(i);case"startsWith":return!o.startsWith(i);case"in":return!i.split(",").map(e=>e.trim()).includes(o);default:return!0}})}).use(function(e){e.conditionHandlers.add(function(e){if("string"!=typeof e||!e.startsWith("tz:")&&!e.startsWith("timezone:"))return null;const t=e.split(":"),s=t[1]||"equals",n=t.slice(2).join(":");try{const e=Intl.DateTimeFormat().resolvedOptions().timeZone,t=-(new Date).getTimezoneOffset()/60;switch(s){case"equals":case"is":return e!==n;case"contains":return!e.includes(n);case"offset":return t!==parseInt(n);default:return!0}}catch(i){return!0}})}).use(function(e){e.conditionHandlers.add(function(e){if("string"!=typeof e||!e.startsWith("url:"))return null;const t=window.location,s=t.href,n=t.pathname,i=t.search,o=t.hostname,r=e.split(":"),l=r[1],a=r.slice(2).join(":");if(!l)return!0;switch(l){case"contains":return!s.includes(a);case"path":return!n.includes(a);case"pathStartsWith":return!n.startsWith(a);case"pathEndsWith":return!n.endsWith(a);case"query":if(i){const e=new URLSearchParams(i);if(a.includes("=")){const[t,s]=a.split("=");return e.get(t)!==s}return!e.has(a)}return!0;case"hostname":return!o.includes(a);case"matches":try{return!new RegExp(a).test(s)}catch(c){return!0}case"pathMatches":try{return!new RegExp(a).test(n)}catch(c){return!0}default:return!0}})}).use(function(e){e.conditionHandlers.add(function(e){if("string"!=typeof e||!e.startsWith("ua:")&&!e.startsWith("userAgent:"))return null;const t=e.split(":"),s=t[1]||"contains",n=t.slice(2).join(":"),i=navigator.userAgent||"",o=i.toLowerCase(),r=n.toLowerCase();switch(s){case"contains":if(!o.includes(r))return!0;break;case"equals":case"is":if(i!==n)return!0;break;case"matches":try{if(!new RegExp(n,"i").test(i))return!0}catch(l){return!0}break;case"browser":if(!{chrome:/chrome/i.test(i)&&!/edg|opr/i.test(i),firefox:/firefox/i.test(i),safari:/safari/i.test(i)&&!/chrome|chromium|edg|opr/i.test(i),edge:/edg/i.test(i),opera:/opr/i.test(i),ie:/msie|trident/i.test(i),chromium:/chromium/i.test(i)}[r])return!0;break;case"device":const e=/mobile|android|iphone|ipod|blackberry|iemobile|opera mini/i.test(i),t=/tablet|ipad|playbook|silk/i.test(i)||e&&/android/i.test(i)&&!/mobile/i.test(i),s=!e&&!t;switch(r){case"mobile":if(!e)return!0;break;case"tablet":if(!t)return!0;break;case"desktop":if(!s)return!0;break;default:return!0}break;case"os":case"platform":if(!{windows:/win/i.test(i),mac:/mac/i.test(i),ios:/iphone|ipad|ipod/i.test(i),android:/android/i.test(i),linux:/linux/i.test(i)&&!/android/i.test(i),unix:/unix/i.test(i),chromeos:/cros/i.test(i)}[r])return!0;break;default:return!0}return!1})}).use(function(e){e.triggerHandlers.add(function(e){return"load"!==e?null:e=>{"complete"===document.readyState?e():window.addEventListener("load",()=>e(),{once:!0})}})}).use(function(e){e.triggerHandlers.add(function(e){return"idle"!==e?null:e=>{"function"==typeof window.requestIdleCallback?window.requestIdleCallback(()=>e()):setTimeout(()=>e(),200)}})}).use(function(e){e.triggerHandlers.add(function(e){return"domready"!==e?null:e=>{"interactive"===document.readyState||"complete"===document.readyState?e():document.addEventListener("DOMContentLoaded",()=>e(),{once:!0})}})}).use(function(e){e.triggerHandlers.add(function(e){if(!f(e,"delay:"))return null;const t=parseInt(h(e,"delay:"),10);return e=>setTimeout(e,Number.isFinite(t)&&t>0?t:0)})}).use(function(e){e.triggerHandlers.add(function(e){if(!f(e,"hover:"))return null;const t=h(e,"hover:");return e=>{p(t,t=>{t?t.addEventListener("mouseover",()=>e(),{once:!0,passive:!0}):e()})}})}).use(function(e){e.triggerHandlers.add(function(e){if(!f(e,"visible:"))return null;const t=h(e,"visible:");return e=>{p(t,t=>{if(!t||"function"!=typeof IntersectionObserver)return void e();const s=new IntersectionObserver(t=>{for(const n of t)if(n.isIntersecting)return s.disconnect(),void e()});s.observe(t)})}})}).use(function(e){e.triggerHandlers.add(function(e){if(!f(e,"appears:"))return null;const t=h(e,"appears:");return e=>p(t,()=>e())})}).use(function(e){e.triggerHandlers.add(function(e,t){if(!f(e,"media:"))return null;const s=h(e,"media:");return e=>{if(!s.length||"function"!=typeof window.matchMedia)return t&&(t.skipped=!0),void e();const n=window.matchMedia(s);if(n.matches)return void e();const i=t=>{t.matches&&(n.removeEventListener("change",i),e())};n.addEventListener("change",i)}})}).init()}();
2
2
  //# sourceMappingURL=qsl.min.js.map