@quietsapa/qsl 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/qsl.mjs CHANGED
@@ -2,7 +2,7 @@ const core = {
2
2
  /**
3
3
  * Constants
4
4
  */
5
- VERSION: "0.1.1",
5
+ VERSION: "0.1.3",
6
6
  PREFIX: "qsl-",
7
7
  FLOW_TYPE: {
8
8
  DEFAULT: "default",
@@ -108,6 +108,7 @@ const core = {
108
108
  */
109
109
  async init() {
110
110
  if (this.initialized) return this;
111
+ const loaderScript = document.currentScript;
111
112
  window.__QSL__ = window.__QSL__ || this;
112
113
  if (document.readyState === "interactive" || document.readyState === "complete") {
113
114
  this.LIFECYCLE.DOMREADY = true;
@@ -139,7 +140,7 @@ const core = {
139
140
  }
140
141
  }
141
142
  this.initialized = true;
142
- const url = document.currentScript ? new URL(document.currentScript.src, document.baseURI) : null;
143
+ const url = loaderScript && loaderScript.src ? new URL(loaderScript.src, document.baseURI) : null;
143
144
  if (!url || url.searchParams.get("async") !== "true") return this;
144
145
  const callback = url.searchParams.get("callback") || this.CALLBACK;
145
146
  if (typeof window[callback] === "function") window[callback]();
@@ -1624,21 +1625,13 @@ function events(QSL) {
1624
1625
  };
1625
1626
  document.addEventListener = (type, listener, opts) => {
1626
1627
  if (type === "DOMContentLoaded" && this.LIFECYCLE.DOMREADY) {
1627
- const trackedType = iterator.call(this, type, this.EVENTS.DOMREADY, true);
1628
- if (trackedType !== type) {
1629
- type = trackedType;
1630
- queueMicrotask(() => document.dispatchEvent(new Event(trackedType)));
1631
- }
1628
+ type = iterator.call(this, type, this.EVENTS.DOMREADY, true);
1632
1629
  }
1633
1630
  return documentListener.call(document, type, listener, opts);
1634
1631
  };
1635
1632
  window.addEventListener = (type, listener, opts) => {
1636
1633
  if (type === "load" && this.LIFECYCLE.LOADED) {
1637
- const trackedType = iterator.call(this, type, this.EVENTS.LOADED, true);
1638
- if (trackedType !== type) {
1639
- type = trackedType;
1640
- queueMicrotask(() => window.dispatchEvent(new Event(trackedType)));
1641
- }
1634
+ type = iterator.call(this, type, this.EVENTS.LOADED, true);
1642
1635
  }
1643
1636
  return windowListener.call(window, type, listener, opts);
1644
1637
  };