@hsfx/attr 2.0.4 → 2.0.5

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/README.md CHANGED
@@ -10,14 +10,14 @@ Auto-initializing JavaScript library for Webflow sites with animations, accessib
10
10
 
11
11
  ```html
12
12
  <script type="module" src="https://cdn.jsdelivr.net/npm/@hsfx/attr@2/dist/main.js"></script>
13
- <script>!function t(){window.hsfx?.ready?window.hsfx.ready(()=>{window.hsfxReady=!0,dispatchEvent(new Event('hsfx:ready'))}):setTimeout(t,50)}()</script>
13
+ <script>!function(){let e=[];window.hsfx||(window.hsfx={ready:t=>e.push(t)});!function t(){window.hsfx.loaded?e.forEach(e=>{try{e()}catch{}}):window.hsfx.ready&&Array.isArray(window.hsfx)?e.forEach(e=>window.hsfx.ready(e)):setTimeout(t,50)}()}()</script>
14
14
  ```
15
15
 
16
16
  ### Next.js Installation
17
17
 
18
18
  ```tsx
19
19
  <Script src="https://cdn.jsdelivr.net/npm/@hsfx/attr@2/dist/main.js" strategy="afterInteractive" data-hs-wf-off />
20
- <Script id="hsfx-helper" strategy="afterInteractive">{`!function t(){window.hsfx?.ready?window.hsfx.ready(()=>{window.hsfxReady=!0,dispatchEvent(new Event('hsfx:ready'))}):setTimeout(t,50)}()`}</Script>
20
+ <Script id="hsfx-helper" strategy="afterInteractive">{`!function(){let e=[];window.hsfx||(window.hsfx={ready:t=>e.push(t)});!function t(){window.hsfx.loaded?e.forEach(e=>{try{e()}catch{}}):window.hsfx.ready&&Array.isArray(window.hsfx)?e.forEach(e=>window.hsfx.ready(e)):setTimeout(t,50)}()}()`}</Script>
21
21
  ```
22
22
 
23
23
  ### Local Development
@@ -25,7 +25,7 @@ Auto-initializing JavaScript library for Webflow sites with animations, accessib
25
25
  ```html
26
26
  <!-- Local testing (run: npm run dev) -->
27
27
  <script type="module" src="http://localhost:5173/index.ts"></script>
28
- <script>!function t(){window.hsfx?.ready?window.hsfx.ready(()=>{window.hsfxReady=!0,dispatchEvent(new Event('hsfx:ready'))}):setTimeout(t,50)}()</script>
28
+ <script>!function(){let e=[];window.hsfx||(window.hsfx={ready:t=>e.push(t)});!function t(){window.hsfx.loaded?e.forEach(e=>{try{e()}catch{}}):window.hsfx.ready&&Array.isArray(window.hsfx)?e.forEach(e=>window.hsfx.ready(e)):setTimeout(t,50)}()}()</script>
29
29
  ```
30
30
 
31
31
  ### Inline Helper Script
@@ -33,14 +33,15 @@ Auto-initializing JavaScript library for Webflow sites with animations, accessib
33
33
  The inline script ensures `window.hsfx` is available for external scripts:
34
34
 
35
35
  ```html
36
- <script>!function t(){window.hsfx?.ready?window.hsfx.ready(()=>{window.hsfxReady=!0,dispatchEvent(new Event('hsfx:ready'))}):setTimeout(t,50)}()</script>
36
+ <script>!function(){let e=[];window.hsfx||(window.hsfx={ready:t=>e.push(t)});!function t(){window.hsfx.loaded?e.forEach(e=>{try{e()}catch{}}):window.hsfx.ready&&Array.isArray(window.hsfx)?e.forEach(e=>window.hsfx.ready(e)):setTimeout(t,50)}()}()</script>
37
37
  ```
38
38
 
39
39
  **What it does:**
40
- - Polls for `window.hsfx` to exist
41
- - Calls `ready()` when initialization completes
42
- - Sets `window.hsfxReady = true` and dispatches `hsfx:ready` event
43
- - Guarantees external scripts can use `window.hsfx.ready()`
40
+ - Creates a temporary `window.hsfx.ready()` shim immediately
41
+ - Queues callbacks from external scripts before hsfx loads
42
+ - Polls for real hsfx to load
43
+ - Flushes queued callbacks to real hsfx when ready
44
+ - Guarantees external scripts can use `window.hsfx.ready()` safely
44
45
 
45
46
  ### SPA Mode
46
47
 
@@ -48,7 +49,7 @@ The inline script ensures `window.hsfx` is available for external scripts:
48
49
 
49
50
  ```html
50
51
  <script type="module" src="https://cdn.jsdelivr.net/npm/@hsfx/attr@2/dist/main.js" data-hs-spa="true"></script>
51
- <script>!function t(){window.hsfx?.ready?window.hsfx.ready(()=>{window.hsfxReady=!0,dispatchEvent(new Event('hsfx:ready'))}):setTimeout(t,50)}()</script>
52
+ <script>!function(){let e=[];window.hsfx||(window.hsfx={ready:t=>e.push(t)});!function t(){window.hsfx.loaded?e.forEach(e=>{try{e()}catch{}}):window.hsfx.ready&&Array.isArray(window.hsfx)?e.forEach(e=>window.hsfx.ready(e)):setTimeout(t,50)}()}()</script>
52
53
  ```
53
54
 
54
55
  ## Configuration
@@ -76,18 +77,15 @@ When using external scripts & libraries (Barba.js, GSAP ScrollTrigger, etc.) tha
76
77
 
77
78
  ```html
78
79
  <script>
79
- window.hsfx?.ready(() => {
80
- // Your code here
80
+ window.hsfx.ready(() => {
81
+ // Your code here - guaranteed to run when hsfx is fully loaded
81
82
  });
82
83
  </script>
83
84
  ```
84
85
 
85
- </script>
86
- ```
87
-
88
86
  **Why this works:**
89
87
 
90
- The inline helper script (included in standard installation) polls for `window.hsfx` to exist and calls `ready()` once initialization completes. This guarantees that by the time your external script runs, `window.hsfx` exists and `ready()` will fire either immediately (if already ready) or when initialization completes.
88
+ The inline helper script creates a temporary `window.hsfx.ready()` shim immediately, so external scripts can safely call it even before the real hsfx library loads. Callbacks are queued and then flushed to the real hsfx when initialization completes.
91
89
 
92
90
  ### Cleanup
93
91
 
package/dist/main.js CHANGED
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/hsfxnormalizeCgvVd0bo.js","assets/hsfxutilsCYt-q_3u.js","assets/hsfxdefaultUK8R1YLa.js","assets/hsfxanimationsCw1kkPqK.js"])))=>i.map(i=>d[i]);
2
- import{c as e}from"./assets/hsfxutilsCYt-q_3u.js";const t={},s=function(e,s,o){let a=Promise.resolve();if(s&&s.length>0){let e=function(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:"fulfilled",value:e}),e=>({status:"rejected",reason:e}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),r=o?.nonce||o?.getAttribute("nonce");a=e(s.map(e=>{if((e=function(e){return"https://cdn.jsdelivr.net/npm/@hsfx/attr@2.0.3/dist/"+e}(e))in t)return;t[e]=!0;const s=e.endsWith(".css"),o=s?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${e}"]${o}`))return;const a=document.createElement("link");return a.rel=s?"stylesheet":"modulepreload",s||(a.as="script"),a.crossOrigin="",a.href=e,r&&a.setAttribute("nonce",r),document.head.appendChild(a),s?new Promise((t,s)=>{a.addEventListener("load",t),a.addEventListener("error",()=>s(new Error(`Unable to preload CSS for ${e}`)))}):void 0}))}function r(e){const t=new Event("vite:preloadError",{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return a.then(t=>{for(const e of t||[])"rejected"===e.status&&r(e.reason);return e().catch(r)})},o=e._global.apiName;(async()=>{if(window[o]&&!Array.isArray(window[o])&&window[o].loaded)return;const t=Array.isArray(window[o])?window[o]:[],a={normalize:()=>s(()=>import("./assets/hsfxnormalizeCgvVd0bo.js"),__vite__mapDeps([0,1])),default:()=>s(()=>import("./assets/hsfxdefaultUK8R1YLa.js"),__vite__mapDeps([2,1])),animations:()=>s(()=>import("./assets/hsfxanimationsCw1kkPqK.js"),__vite__mapDeps([3,1]))};let r=[...document.querySelectorAll(`script[type="module"][src="${import.meta.url}"]`)];0===r.length&&(r=[...document.querySelectorAll('script[type="module"][src*="@hsfx/attr"]')].filter(e=>{const t=e.src,s=import.meta.url,o=t.match(/@hsfx\/attr(@[\d.]+)?/)?.[0],a=s.match(/@hsfx\/attr(@[\d.]+)?/)?.[0];return o&&a&&o.split("@")[0]===a.split("@")[0]}));const n={isSPA:r.some(e=>"true"===e.getAttribute("data-hs-spa"))},i={normalize:{modules:["normalize"],parallel:!1},default:{modules:["default","animations"],parallel:!0}},l=async e=>{const t=window[o];if(t.process.has(e))return t.modules[e]?.loading;t.process.add(e);const s=t.modules[e]||{};let r;t.modules[e]=s,s.loading=new Promise((e,t)=>{s.resolve=e,s.reject=t});try{const{init:o}=await a[e](),n=await o()||{};r=n.destroy;const i=n.result;return s.destroy=()=>{r?.(),t.process.delete(e)},s.restart=()=>{s.destroy?.(),t.load(e)},s.resolve?.(i),delete s.resolve,delete s.reject,i}catch(n){throw r?.(),s.reject?.(n),t.process.delete(e),n}},d=async e=>{const t=i[e];if(t.parallel){const e=t.modules.map(e=>l(e));await Promise.allSettled(e)}else for(const s of t.modules)await l(s)},c=async()=>{await Promise.allSettled([a.normalize(),a.default(),a.animations()]),await d("normalize"),await d("default"),(()=>{const e=new CustomEvent(`${o}:dom-ready`);window.dispatchEvent(e)})();const{initScrollAnimations:e}=await s(async()=>{const{initScrollAnimations:e}=await import("./assets/hsfxutilsCYt-q_3u.js").then(e=>e.r);return{initScrollAnimations:e}},[]);e().catch(e=>{console.error(`[${o}] Scroll animations failed to initialize:`,e)})},u=[];window[o]={scripts:r,settings:n,modules:{},process:new Set,load:l,loaded:!1,push(...e){for(const[t,s]of e)"function"==typeof s?this.modules[t]?.loading?.then(s):this.load(t)},destroy(){for(const e in this.modules)this.modules[e]?.destroy?.()},async reinitialize(){this.loaded=!1,this.destroy(),this.modules={},this.process=new Set,await this.scanForEmbedModules(),await c(),this.loaded=!0},async scanForEmbedModules(){document.querySelectorAll(".w-embed").forEach(e=>{e.querySelectorAll("script[data-hs-module]").forEach(e=>{const t=e.getAttribute("data-hs-module-type"),s=e.getAttribute("data-hs-module");if(t&&s){const e=`data-hs-${t}-${s}`;a[e]&&this.load(e)}})})},ready(e){"function"==typeof e&&(this.loaded?e():u.push(e))},status(e){return e?{loaded:!!this.modules[e],loading:this.process.has(e)}:{loaded:Object.keys(this.modules),loading:[...this.process],phases:i}}};(async()=>{window[o].push(...t),await c(),window[o].loaded=!0,document.documentElement.classList.add(e._global.classes.ready),u.forEach(e=>{try{e()}catch{}}),u.length=0})().catch(()=>{})})();export{s as _};
2
+ import{c as e}from"./assets/hsfxutilsCYt-q_3u.js";const t={},s=function(e,s,o){let r=Promise.resolve();if(s&&s.length>0){let e=function(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:"fulfilled",value:e}),e=>({status:"rejected",reason:e}))))};document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),a=o?.nonce||o?.getAttribute("nonce");r=e(s.map(e=>{if((e=function(e){return"https://cdn.jsdelivr.net/npm/@hsfx/attr@2.0.4/dist/"+e}(e))in t)return;t[e]=!0;const s=e.endsWith(".css"),o=s?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${e}"]${o}`))return;const r=document.createElement("link");return r.rel=s?"stylesheet":"modulepreload",s||(r.as="script"),r.crossOrigin="",r.href=e,a&&r.setAttribute("nonce",a),document.head.appendChild(r),s?new Promise((t,s)=>{r.addEventListener("load",t),r.addEventListener("error",()=>s(new Error(`Unable to preload CSS for ${e}`)))}):void 0}))}function a(e){const t=new Event("vite:preloadError",{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(const e of t||[])"rejected"===e.status&&a(e.reason);return e().catch(a)})},o=e._global.apiName;(async()=>{if(window[o]&&!Array.isArray(window[o])&&window[o].loaded)return;const t=Array.isArray(window[o])?window[o]:[],r={normalize:()=>s(()=>import("./assets/hsfxnormalizeCgvVd0bo.js"),__vite__mapDeps([0,1])),default:()=>s(()=>import("./assets/hsfxdefaultUK8R1YLa.js"),__vite__mapDeps([2,1])),animations:()=>s(()=>import("./assets/hsfxanimationsCw1kkPqK.js"),__vite__mapDeps([3,1]))};let a=[...document.querySelectorAll(`script[type="module"][src="${import.meta.url}"]`)];0===a.length&&(a=[...document.querySelectorAll('script[type="module"][src*="@hsfx/attr"]')].filter(e=>{const t=e.src,s=import.meta.url,o=t.match(/@hsfx\/attr(@[\d.]+)?/)?.[0],r=s.match(/@hsfx\/attr(@[\d.]+)?/)?.[0];return o&&r&&o.split("@")[0]===r.split("@")[0]}));const n={isSPA:a.some(e=>"true"===e.getAttribute("data-hs-spa"))},l={normalize:{modules:["normalize"],parallel:!1},default:{modules:["default"],parallel:!0}},i=async e=>{const t=window[o];if(t.process.has(e))return t.modules[e]?.loading;t.process.add(e);const s=t.modules[e]||{};let a;t.modules[e]=s,s.loading=new Promise((e,t)=>{s.resolve=e,s.reject=t});try{const{init:o}=await r[e](),n=await o()||{};a=n.destroy;const l=n.result;return s.destroy=()=>{a?.(),t.process.delete(e)},s.restart=()=>{s.destroy?.(),t.load(e)},s.resolve?.(l),delete s.resolve,delete s.reject,l}catch(n){throw a?.(),s.reject?.(n),t.process.delete(e),n}},d=async e=>{const t=l[e];if(t.parallel){const e=t.modules.map(e=>i(e));await Promise.allSettled(e)}else for(const s of t.modules)await i(s)},c=async()=>{await Promise.allSettled([r.normalize(),r.default(),r.animations()]),await d("normalize");const e=d("default"),t=i("animations");await e,(()=>{const e=new CustomEvent(`${o}:dom-ready`);window.dispatchEvent(e)})();const{initScrollAnimations:a}=await s(async()=>{const{initScrollAnimations:e}=await import("./assets/hsfxutilsCYt-q_3u.js").then(e=>e.r);return{initScrollAnimations:e}},[]);Promise.all([t,a()]).catch(e=>{console.error(`[${o}] Phase 3 (animations + scroll trigger) failed:`,e)})},u=[];window[o]={scripts:a,settings:n,modules:{},process:new Set,load:i,loaded:!1,push(...e){for(const[t,s]of e)"function"==typeof s?this.modules[t]?.loading?.then(s):this.load(t)},destroy(){for(const e in this.modules)this.modules[e]?.destroy?.()},async reinitialize(){this.loaded=!1,this.destroy(),this.modules={},this.process=new Set,await this.scanForEmbedModules(),await c(),this.loaded=!0},async scanForEmbedModules(){document.querySelectorAll(".w-embed").forEach(e=>{e.querySelectorAll("script[data-hs-module]").forEach(e=>{const t=e.getAttribute("data-hs-module-type"),s=e.getAttribute("data-hs-module");if(t&&s){const e=`data-hs-${t}-${s}`;r[e]&&this.load(e)}})})},ready(e){"function"==typeof e&&(this.loaded?e():u.push(e))},status(e){return e?{loaded:!!this.modules[e],loading:this.process.has(e)}:{loaded:Object.keys(this.modules),loading:[...this.process],phases:l}}};(async()=>{window[o].push(...t),await c(),window[o].loaded=!0,document.documentElement.classList.add(e._global.classes.ready),u.forEach(e=>{try{e()}catch{}}),u.length=0})().catch(()=>{})})();export{s as _};
package/dist/main.js.br CHANGED
Binary file
package/dist/main.js.gz CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hsfx/attr",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "license": "UNLICENSED",