@growth-rail/core 2.0.1 → 2.1.1
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 +12 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +132 -4
- package/dist/index.mjs +132 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -33,15 +33,16 @@ type TriggerButtonPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top
|
|
|
33
33
|
type ReferrerTriggerButton = {
|
|
34
34
|
show: boolean;
|
|
35
35
|
position: TriggerButtonPosition;
|
|
36
|
-
|
|
36
|
+
displayMode: 'floating' | 'edge';
|
|
37
37
|
};
|
|
38
38
|
type ReferrerModalOptions = {
|
|
39
39
|
title: string;
|
|
40
40
|
description: string;
|
|
41
|
-
|
|
41
|
+
componentType: 'modal' | 'drawer';
|
|
42
42
|
theme: {
|
|
43
43
|
primaryColor: string;
|
|
44
44
|
tintColor: string;
|
|
45
|
+
tintAlpha: number;
|
|
45
46
|
backgroundColor: string;
|
|
46
47
|
};
|
|
47
48
|
};
|
|
@@ -54,6 +55,7 @@ interface NewUserExperience {
|
|
|
54
55
|
show: boolean;
|
|
55
56
|
position: 'center-top' | 'center-bottom' | 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom';
|
|
56
57
|
text: string;
|
|
58
|
+
themeColor: string;
|
|
57
59
|
};
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -84,7 +86,6 @@ declare class GrowthRail {
|
|
|
84
86
|
static isUserReady(): boolean;
|
|
85
87
|
static ensureUserReady(): Promise<AppUserType>;
|
|
86
88
|
static showReferralDashboard(options?: Partial<ReferrerModalOptions>): Promise<void>;
|
|
87
|
-
private static createPromotionalBanner;
|
|
88
89
|
static createTriggerButton(options: Partial<ReferrerTriggerButton>): void;
|
|
89
90
|
static destroyTriggerButton(): void;
|
|
90
91
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -33,15 +33,16 @@ type TriggerButtonPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top
|
|
|
33
33
|
type ReferrerTriggerButton = {
|
|
34
34
|
show: boolean;
|
|
35
35
|
position: TriggerButtonPosition;
|
|
36
|
-
|
|
36
|
+
displayMode: 'floating' | 'edge';
|
|
37
37
|
};
|
|
38
38
|
type ReferrerModalOptions = {
|
|
39
39
|
title: string;
|
|
40
40
|
description: string;
|
|
41
|
-
|
|
41
|
+
componentType: 'modal' | 'drawer';
|
|
42
42
|
theme: {
|
|
43
43
|
primaryColor: string;
|
|
44
44
|
tintColor: string;
|
|
45
|
+
tintAlpha: number;
|
|
45
46
|
backgroundColor: string;
|
|
46
47
|
};
|
|
47
48
|
};
|
|
@@ -54,6 +55,7 @@ interface NewUserExperience {
|
|
|
54
55
|
show: boolean;
|
|
55
56
|
position: 'center-top' | 'center-bottom' | 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom';
|
|
56
57
|
text: string;
|
|
58
|
+
themeColor: string;
|
|
57
59
|
};
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -84,7 +86,6 @@ declare class GrowthRail {
|
|
|
84
86
|
static isUserReady(): boolean;
|
|
85
87
|
static ensureUserReady(): Promise<AppUserType>;
|
|
86
88
|
static showReferralDashboard(options?: Partial<ReferrerModalOptions>): Promise<void>;
|
|
87
|
-
private static createPromotionalBanner;
|
|
88
89
|
static createTriggerButton(options: Partial<ReferrerTriggerButton>): void;
|
|
89
90
|
static destroyTriggerButton(): void;
|
|
90
91
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
|
-
"use strict";var y=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var E=(d,e,r)=>e in d?y(d,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):d[e]=r;var C=(d,e)=>{for(var r in e)y(d,r,{get:e[r],enumerable:!0})},T=(d,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of R(e))!k.call(d,n)&&n!==r&&y(d,n,{get:()=>e[n],enumerable:!(i=w(e,n))||i.enumerable});return d};var P=d=>T(y({},"__esModule",{value:!0}),d);var a=(d,e,r)=>E(d,typeof e!="symbol"?e+"":e,r);var U={};C(U,{GrowthRail:()=>m,ReferralModal:()=>u});module.exports=P(U);var b=class{constructor(e){a(this,"baseUrl");a(this,"apiKey");let r=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=r||"http://hw84ko0ok4ccws4sws8gos0o.193.31.30.10.sslip.io",this.apiKey=e.apiKey}async request(e,r,i){let n={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.apiKey};try{let o=await fetch(`${this.baseUrl}${e}`,{method:r,headers:n,body:i?JSON.stringify(i):void 0});if(!o.ok)throw new Error(`GrowthRail API Error: ${o.statusText}`);return o.json()}catch(o){throw console.error("GrowthRail SDK Error:",o),o}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(e){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:e})}async createReferralLink(e,r){return this.request("/api/v1/sdk/create-referral-link","POST",{referrerId:e,rewardEventName:r})}async trackReferral(e,r){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:r})}async trackRewardEvent(e,r,i){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:r,eventName:i})}};var f=class f{constructor(e){a(this,"options",{});e&&(this.options=e)}setCookie(e,r,i=30){if(typeof document>"u")return;let n="";if(i){let s=new Date;s.setTime(s.getTime()+i*24*60*60*1e3),n=`; expires=${s.toUTCString()}`}let o="";this.options.cookieDomain&&(o=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${r||""}${n}${o}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let r=`${e}=`,i=document.cookie.split(";");for(let n=0;n<i.length;n++){let o=i[n];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(r)===0)return o.substring(r.length,o.length)}return null}getReferralCode(){return this.getCookie(f.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(f.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(f.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(f.TRACKED_REFERRAL_KEY)}};a(f,"REFERRAL_CODE_KEY","gr_ref_code"),a(f,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var x=f;var u=class{constructor(e,r){a(this,"referrerExperience");a(this,"deps");a(this,"host",null);a(this,"shadow",null);a(this,"overlay",null);a(this,"content",null);this.deps=e,this.referrerExperience=r}show(e,r){this.host||(this.createDom(e,r),this.bindEvents(),r||(document.body.style.overflow="hidden"))}hide(){this.host&&(this.host&&this.host.parentNode&&this.host.parentNode.removeChild(this.host),this.host=null,this.overlay=null,this.content=null,this.shadow=null,document.body.style.overflow="")}createDom(e,r){let i={...this.referrerExperience,...e??{}},n=this.getTheme(),o={...n,colorPrimary:i.modal?.theme?.primaryColor||n.colorPrimary,colorBackground:i.modal?.theme?.backgroundColor||n.colorBackground,colorTint:i.modal?.theme?.tintColor||n.colorTint},s=!!r;this.host=document.createElement("div"),this.host.style.all="initial",s?(this.host.style.display="block",this.host.style.width="100%",this.host.style.height="100%"):(this.host.style.position="absolute",this.host.style.zIndex="2147483647"),this.host.id="growth-rail-modal-host",this.host.style.setProperty("--gr-primary",o.colorPrimary),this.host.style.setProperty("--gr-text",o.colorText),this.host.style.setProperty("--gr-text-secondary",o.colorTextSecondary),this.host.style.setProperty("--gr-bg",o.colorBackground),this.host.style.setProperty("--gr-tint",o.colorTint),this.host.style.setProperty("--gr-surface",o.colorSurface),this.host.style.setProperty("--gr-border",o.colorBorder),this.host.style.setProperty("--gr-error",o.colorError),this.host.style.setProperty("--gr-radius",o.borderRadius),this.host.style.setProperty("--gr-font",'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),this.shadow=this.host.attachShadow({mode:"open"});let c=document.createElement("style");c.textContent=":host{all:initial;display:block}*{box-sizing:border-box}@keyframes gr-fade-in{from{opacity:0}to{opacity:1}}@keyframes gr-slide-up{from{opacity:0;transform:translateY(20px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes gr-slide-in-right{from{opacity:0;transform:translateX(100%)}to{opacity:1;transform:translateX(0)}}@keyframes gr-slide-in-left{from{opacity:0;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}.gr-overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;display:flex;z-index:2147483647;font-family:var(--gr-font);animation:gr-fade-in .2s ease-out forwards;backdrop-filter:blur(4px)}.gr-overlay--modal{background-color:var(--gr-tint);align-items:center;justify-content:center}.gr-overlay--drawer{background-color:var(--gr-tint);align-items:flex-start;justify-content:flex-start}.gr-container{position:relative;background-color:var(--gr-bg);color:var(--gr-text);padding:32px;box-shadow:0 20px 25px -5px rgba(0,0,0,.1),0 10px 10px -5px rgba(0,0,0,.04)}.gr-container--embedded{width:100%;height:100%;box-shadow:none;border:1px solid var(--gr-border);border-radius:var(--gr-radius)}.gr-container--modal{width:90%;max-width:480px;border-radius:var(--gr-radius);animation:gr-slide-up .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--drawer{position:absolute;width:400px;max-width:calc(100vw - 20px);max-height:calc(100vh - 40px);overflow-y:auto}.gr-container--right{right:0;border-top-left-radius:var(--gr-radius);border-bottom-left-radius:var(--gr-radius);animation:gr-slide-in-right .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--left{left:0;border-top-right-radius:var(--gr-radius);border-bottom-right-radius:var(--gr-radius);animation:gr-slide-in-left .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--top{top:100px}.gr-container--bottom{bottom:100px}.gr-close-btn{position:absolute;top:20px;right:20px;background:0 0;border:none;cursor:pointer;color:#9ca3af;padding:4px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:all .2s}.gr-close-btn:hover{background-color:var(--gr-surface);color:var(--gr-text)}.gr-header{text-align:center;margin-bottom:28px}.gr-icon-lg{font-size:32px;margin-bottom:12px}.gr-title{margin:0 0 8px 0;font-size:22px;font-weight:700;letter-spacing:-.02em}.gr-subtitle{margin:0;font-size:14px;line-height:1.5;color:var(--gr-text-secondary)}.gr-loading{padding:16px;background-color:var(--gr-surface);border-radius:8px;text-align:center;color:var(--gr-text-secondary);font-size:14px}.gr-label{display:block;font-size:12px;font-weight:600;color:var(--gr-text-secondary);margin-bottom:8px;text-transform:uppercase;letter-spacing:.05em}.gr-share-label{text-align:center;margin-bottom:16px;font-size:13px;font-weight:500;color:var(--gr-text-secondary);display:flex;align-items:center;gap:12px}.gr-divider{flex:1;height:1px;background:var(--gr-border)}.gr-social-container{display:flex;gap:16px;justify-content:center;flex-wrap:wrap}.gr-btn{padding:14px;font-size:15px;font-weight:600;background-color:var(--gr-primary);color:#fff;border:none;border-radius:var(--gr-radius);cursor:pointer;transition:all .2s ease;text-align:center;width:100%;display:block}.gr-btn:hover{transform:translateY(-1px);filter:brightness(1.05)}.gr-btn:active{transform:translateY(0);filter:brightness(.95)}.gr-btn:disabled{opacity:.7;cursor:not-allowed}.gr-btn--sm{padding:8px 16px;font-size:13px;width:auto;border-radius:calc(var(--gr-radius) - 4px)}.gr-input-group{display:flex;align-items:center;background-color:var(--gr-surface);border:1px solid var(--gr-border);border-radius:var(--gr-radius);padding:4px;margin-bottom:24px}.gr-input-group:focus-within{border-color:var(--gr-primary);box-shadow:0 0 0 3px var(--gr-surface)}.gr-input{flex:1;padding:10px 12px;font-size:14px;border:none;background:0 0;color:var(--gr-text);outline:none;font-family:monospace}.gr-social-btn{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border-radius:50%;background-color:var(--gr-surface);color:var(--gr-text-secondary);border:1px solid var(--gr-border);transition:transform .2s cubic-bezier(.34,1.56,.64,1);cursor:pointer}.gr-social-btn:hover{transform:scale(1.15) rotate(3deg);color:#fff}.gr-powered-by{margin-top:24px;text-align:center;font-size:11px;color:#9ca3af;display:flex;align-items:center;justify-content:center;gap:4px;opacity:.8}.gr-powered-by a{color:inherit;text-decoration:none;font-weight:600;transition:opacity .2s}.gr-powered-by a:hover{opacity:1;text-decoration:underline}",this.shadow.appendChild(c),this.content=document.createElement("div");let p=i.modal.type==="drawer",l=i.trigger.position||"top-right",h=["gr-container"];s?(h.push("gr-container--embedded"),this.content.className=h.join(" "),this.renderInternalContent(o,e,s),this.shadow.appendChild(this.content),r&&r.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${p?"gr-overlay--drawer":"gr-overlay--modal"}`,p?(h.push("gr-container--drawer"),l.includes("right")?h.push("gr-container--right"):h.push("gr-container--left"),l.includes("bottom")?h.push("gr-container--bottom"):h.push("gr-container--top")):h.push("gr-container--modal"),this.content.className=h.join(" "),this.renderInternalContent(o,e,s),this.overlay.appendChild(this.content),this.shadow.appendChild(this.overlay),document.body.appendChild(this.host),this.overlay.onclick=g=>{g.target===this.overlay&&this.hide()})}getTheme(){return{colorPrimary:"#2563eb",colorText:"#111827",colorTextSecondary:"#6b7280",colorBackground:"#ffffff",colorTint:"#f9fafb",colorSurface:"#f9fafb",colorBorder:"#e5e7eb",colorError:"#ef4444",borderRadius:"16px"}}async renderInternalContent(e,r,i=!1){if(!this.content)return;if(this.content.innerHTML="",!i){let g=document.createElement("button");g.className="gr-close-btn",g.innerHTML=`
|
|
1
|
+
"use strict";var b=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var z=(p,e,r)=>e in p?b(p,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):p[e]=r;var U=(p,e)=>{for(var r in e)b(p,r,{get:e[r],enumerable:!0})},M=(p,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of T(e))!P.call(p,i)&&i!==r&&b(p,i,{get:()=>e[i],enumerable:!(n=C(e,i))||n.enumerable});return p};var L=p=>M(b({},"__esModule",{value:!0}),p);var a=(p,e,r)=>z(p,typeof e!="symbol"?e+"":e,r);var A={};U(A,{GrowthRail:()=>x,ReferralModal:()=>m});module.exports=L(A);var y=class{constructor(e){a(this,"baseUrl");a(this,"apiKey");let r=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=r||"https://api.growthrail.dev",this.apiKey=e.apiKey}async request(e,r,n){let i={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.apiKey};try{let o=await fetch(`${this.baseUrl}${e}`,{method:r,headers:i,body:n?JSON.stringify(n):void 0});if(!o.ok)throw new Error(`GrowthRail API Error: ${o.statusText}`);return o.json()}catch(o){throw console.error("GrowthRail SDK Error:",o),o}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(e){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:e})}async createReferralLink(e,r){return this.request("/api/v1/sdk/create-referral-link","POST",{referrerId:e,rewardEventName:r})}async trackReferral(e,r){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:r})}async trackRewardEvent(e,r,n){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:r,eventName:n})}};var u=class u{constructor(e){a(this,"options",{});e&&(this.options=e)}setCookie(e,r,n=30){if(typeof document>"u")return;let i="";if(n){let s=new Date;s.setTime(s.getTime()+n*24*60*60*1e3),i=`; expires=${s.toUTCString()}`}let o="";this.options.cookieDomain&&(o=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${r||""}${i}${o}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let r=`${e}=`,n=document.cookie.split(";");for(let i=0;i<n.length;i++){let o=n[i];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(r)===0)return o.substring(r.length,o.length)}return null}getReferralCode(){return this.getCookie(u.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(u.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(u.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(u.TRACKED_REFERRAL_KEY)}};a(u,"REFERRAL_CODE_KEY","gr_ref_code"),a(u,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var v=u;var m=class{constructor(e,r){a(this,"referrerExperience");a(this,"deps");a(this,"host",null);a(this,"shadow",null);a(this,"overlay",null);a(this,"content",null);this.deps=e,this.referrerExperience=r}show(e,r){this.host||(this.createDom(e,r),this.bindEvents(),r||(document.body.style.overflow="hidden"))}hide(){this.host&&(this.host&&this.host.parentNode&&this.host.parentNode.removeChild(this.host),this.host=null,this.overlay=null,this.content=null,this.shadow=null,document.body.style.overflow="")}createDom(e,r){let n={...this.referrerExperience,modal:{...this.referrerExperience.modal,...e??{},theme:{...this.referrerExperience.modal?.theme,...e?.theme??{}}}},i=this.getTheme(),o={...i,colorPrimary:n.modal?.theme?.primaryColor||i.colorPrimary,colorBackground:n.modal?.theme?.backgroundColor||i.colorBackground,colorTint:n.modal?.theme?.tintColor||i.colorTint,tintAlpha:n.modal?.theme?.tintAlpha??i.tintAlpha},s=!!r;this.host=document.createElement("div"),this.host.style.all="initial",s?(this.host.style.display="block",this.host.style.width="100%",this.host.style.height="100%"):(this.host.style.position="absolute",this.host.style.zIndex="2147483647"),this.host.id="growth-rail-modal-host",this.host.style.setProperty("--gr-primary",o.colorPrimary),this.host.style.setProperty("--gr-text",o.colorText),this.host.style.setProperty("--gr-text-secondary",o.colorTextSecondary),this.host.style.setProperty("--gr-bg",o.colorBackground),this.host.style.setProperty("--gr-tint",o.colorTint);let l=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o.colorTint),d=o.tintAlpha>1?o.tintAlpha/100:o.tintAlpha,c=l?`rgba(${parseInt(l[1],16)}, ${parseInt(l[2],16)}, ${parseInt(l[3],16)}, ${d})`:`rgba(0, 0, 0, ${d})`;this.host.style.setProperty("--gr-tint-rgba",c),this.host.style.setProperty("--gr-surface",o.colorSurface),this.host.style.setProperty("--gr-border",o.colorBorder),this.host.style.setProperty("--gr-error",o.colorError),this.host.style.setProperty("--gr-radius",o.borderRadius),this.host.style.setProperty("--gr-font",'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),this.shadow=this.host.attachShadow({mode:"open"});let g=document.createElement("style");g.textContent=":host{all:initial;display:block}*{box-sizing:border-box}@keyframes gr-fade-in{from{opacity:0}to{opacity:1}}@keyframes gr-slide-up{from{opacity:0;transform:translateY(20px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes gr-slide-in-right{from{opacity:0;transform:translateX(100%)}to{opacity:1;transform:translateX(0)}}@keyframes gr-slide-in-left{from{opacity:0;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}.gr-overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;display:flex;z-index:2147483647;font-family:var(--gr-font);animation:gr-fade-in .2s ease-out forwards;backdrop-filter:blur(4px);background-color:var(--gr-tint-rgba)}.gr-overlay--modal{align-items:center;justify-content:center}.gr-overlay--drawer{align-items:flex-start;justify-content:flex-start}.gr-container{position:relative;background-color:var(--gr-bg);color:var(--gr-text);padding:32px;box-shadow:0 0 50px -12px rgba(0,0,0,0.25), 0 0 30px -10px rgba(0,0,0,0.15)}.gr-container--embedded{width:100%;height:100%;box-shadow:none;border:1px solid var(--gr-border);border-radius:var(--gr-radius)}.gr-container--modal{width:90%;max-width:480px;border-radius:var(--gr-radius);animation:gr-slide-up .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--drawer{position:absolute;width:400px;max-width:calc(100vw - 20px);max-height:calc(100vh - 40px);overflow-y:auto}.gr-container--right{right:0;border-top-left-radius:var(--gr-radius);border-bottom-left-radius:var(--gr-radius);animation:gr-slide-in-right .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--left{left:0;border-top-right-radius:var(--gr-radius);border-bottom-right-radius:var(--gr-radius);animation:gr-slide-in-left .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--top{top:100px}.gr-container--bottom{bottom:100px}.gr-close-btn{position:absolute;top:20px;right:20px;background:0 0;border:none;cursor:pointer;color:#9ca3af;padding:4px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:all .2s}.gr-close-btn:hover{background-color:var(--gr-surface);color:var(--gr-text)}.gr-header{text-align:center;margin-bottom:28px}.gr-icon-lg{font-size:32px;margin-bottom:12px}.gr-title{margin:0 0 8px 0;font-size:22px;font-weight:700;letter-spacing:-.02em}.gr-subtitle{margin:0;font-size:14px;line-height:1.5;color:var(--gr-text-secondary)}.gr-loading{padding:16px;background-color:var(--gr-surface);border-radius:8px;text-align:center;color:var(--gr-text-secondary);font-size:14px}.gr-label{display:block;font-size:12px;font-weight:600;color:var(--gr-text-secondary);margin-bottom:8px;text-transform:uppercase;letter-spacing:.05em}.gr-share-label{text-align:center;margin-bottom:16px;font-size:13px;font-weight:500;color:var(--gr-text-secondary);display:flex;align-items:center;gap:12px}.gr-divider{flex:1;height:1px;background:var(--gr-border)}.gr-social-container{display:flex;gap:16px;justify-content:center;flex-wrap:wrap}.gr-btn{padding:14px;font-size:15px;font-weight:600;background-color:var(--gr-primary);color:#fff;border:none;border-radius:var(--gr-radius);cursor:pointer;transition:all .2s ease;text-align:center;width:100%;display:block}.gr-btn:hover{transform:translateY(-1px);filter:brightness(1.05)}.gr-btn:active{transform:translateY(0);filter:brightness(.95)}.gr-btn:disabled{opacity:.7;cursor:not-allowed}.gr-btn--sm{padding:8px 16px;font-size:13px;width:auto;border-radius:calc(var(--gr-radius) - 4px)}.gr-input-group{display:flex;align-items:center;background-color:var(--gr-surface);border:1px solid var(--gr-border);border-radius:var(--gr-radius);padding:4px;margin-bottom:24px}.gr-input-group:focus-within{border-color:var(--gr-primary);box-shadow:0 0 0 3px var(--gr-surface)}.gr-input{flex:1;padding:10px 12px;font-size:14px;border:none;background:0 0;color:var(--gr-text);outline:none;font-family:monospace}.gr-social-btn{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border-radius:50%;background-color:var(--gr-surface);color:var(--gr-text-secondary);border:1px solid var(--gr-border);transition:transform .2s cubic-bezier(.34,1.56,.64,1);cursor:pointer}.gr-social-btn:hover{transform:scale(1.15) rotate(3deg);color:#fff}.gr-powered-by{margin-top:24px;text-align:center;font-size:11px;color:#9ca3af;display:flex;align-items:center;justify-content:center;gap:4px;opacity:.8}.gr-powered-by a{color:inherit;text-decoration:none;font-weight:600;transition:opacity .2s}.gr-powered-by a:hover{opacity:1;text-decoration:underline}",this.shadow.appendChild(g),this.content=document.createElement("div");let h=n.modal.componentType==="drawer",R=n.trigger.position||"top-right",f=["gr-container"];s?(f.push("gr-container--embedded"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.shadow.appendChild(this.content),r&&r.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${h?"gr-overlay--drawer":"gr-overlay--modal"}`,h?(f.push("gr-container--drawer"),R.includes("right")?f.push("gr-container--right"):f.push("gr-container--left"),R.includes("bottom")?f.push("gr-container--bottom"):f.push("gr-container--top")):f.push("gr-container--modal"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.overlay.appendChild(this.content),this.shadow.appendChild(this.overlay),document.body.appendChild(this.host),this.overlay.onclick=E=>{E.target===this.overlay&&this.hide()})}getTheme(){return{colorPrimary:"#2563eb",colorText:"#111827",colorTextSecondary:"#6b7280",colorBackground:"#ffffff",colorTint:"#f9fafb",tintAlpha:.8,colorSurface:"#f9fafb",colorBorder:"#e5e7eb",colorError:"#ef4444",borderRadius:"16px"}}async renderInternalContent(e,r,n=!1){if(!this.content)return;if(this.content.innerHTML="",!n){let h=document.createElement("button");h.className="gr-close-btn",h.innerHTML=`
|
|
2
2
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
3
3
|
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
4
4
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
5
5
|
</svg>
|
|
6
|
-
`,
|
|
6
|
+
`,h.onclick=()=>this.hide(),this.content.appendChild(h)}let i=document.createElement("div");i.className="gr-header";let o=document.createElement("div");o.className="gr-icon-lg",o.innerHTML="\u{1F381}",i.appendChild(o);let s=document.createElement("h3");s.className="gr-title",s.textContent=r?.title??this.referrerExperience.modal.title??"Invite Friends & Earn",i.appendChild(s);let l=document.createElement("p");if(l.className="gr-subtitle",l.textContent="Share your unique link and earn rewards for every friend who signs up.",i.appendChild(l),this.content.appendChild(i),!this.deps.isUserReady()){let h=document.createElement("div");h.className="gr-loading",h.textContent="Please log in to view your referral dashboard.",this.content.appendChild(h);return}let d=this.deps.getReferralLink(),c=document.createElement("div");this.renderLinkView(c,d,e),this.content.appendChild(c),d&&this.renderSocialShare(this.content,d,e);let g=document.createElement("div");g.className="gr-powered-by",g.innerHTML=`
|
|
7
7
|
Powered by <a href="https://growthrail.com" target="_blank" rel="noopener noreferrer">Growth Rail</a>
|
|
8
|
-
`,this.content.appendChild(
|
|
8
|
+
`,this.content.appendChild(g)}renderLinkView(e,r,n){let i=document.createElement("label");i.className="gr-label",i.textContent="Your unique link",e.appendChild(i);let o=document.createElement("div");o.className="gr-input-group";let s=document.createElement("input");s.className="gr-input",s.type="text",s.value=r,s.readOnly=!0;let l=document.createElement("button");l.className="gr-btn gr-btn--sm",l.textContent="Copy",l.onclick=async()=>{try{await navigator.clipboard.writeText(r);let d=l.textContent;l.textContent="Copied!",l.style.backgroundColor="#10b981",setTimeout(()=>{l.textContent=d,l.style.backgroundColor=""},2e3)}catch(d){console.error("Failed to copy",d)}},o.appendChild(s),o.appendChild(l),e.appendChild(o)}renderSocialShare(e,r,n){let i=document.createElement("div"),o=document.createElement("div");o.className="gr-share-label",o.innerHTML='<span class="gr-divider"></span>Share via<span class="gr-divider"></span>',i.appendChild(o);let s=document.createElement("div");s.className="gr-social-container",[{name:"Twitter",color:"#000000",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>',url:`https://twitter.com/intent/tweet?url=${encodeURIComponent(r)}&text=Check+this+out!`},{name:"Facebook",color:"#1877F2",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036c-2.648 0-2.928 1.67-2.928 3.403v1.596h3.949l-.577 3.667h-3.372v7.98h-4.938z"/></svg>',url:`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(r)}`},{name:"LinkedIn",color:"#0A66C2",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>',url:`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(r)}`},{name:"WhatsApp",color:"#25D366",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/></svg>',url:`https://api.whatsapp.com/send?text=${encodeURIComponent(r)}`},{name:"Email",color:"#888888",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/></svg>',url:`mailto:?subject=Check this out&body=${encodeURIComponent(r)}`}].forEach(d=>{let c=document.createElement("a");c.href=d.url,c.target="_blank",c.rel="noopener noreferrer",c.className="gr-social-btn",c.innerHTML=d.icon,c.title=`Share on ${d.name}`,c.onmouseenter=()=>{c.style.backgroundColor=d.color,c.style.color="#ffffff",c.style.borderColor=d.color},c.onmouseleave=()=>{c.style.backgroundColor="",c.style.color="",c.style.borderColor=""},s.appendChild(c)}),i.appendChild(s),e.appendChild(i)}bindEvents(){this.overlay&&(this.overlay.onclick=e=>{e.target===this.overlay&&this.hide()})}};var w=class{constructor(e){a(this,"options");a(this,"host",null);a(this,"shadow",null);a(this,"element",null);this.options=e}mount(){this.host||this.createDom()}unmount(){this.host&&this.host.parentNode&&document.body.removeChild(this.host),this.host=null,this.shadow=null,this.element=null}createDom(){this.host=document.createElement("div"),this.host.style.all="initial",this.host.style.position="absolute",this.host.style.zIndex="2147483646";let e={x:0,y:100};this.host.style.setProperty("--gr-offset-y",`${e.y}px`),this.shadow=this.host.attachShadow({mode:"open"});let r=document.createElement("style"),n=this.options.trigger?.displayMode||"edge";r.textContent=`
|
|
9
|
+
:host { all: initial; display: block; }
|
|
10
|
+
@keyframes gr-shimmer {
|
|
11
|
+
0% { transform: translateX(-150%) skewX(-15deg); }
|
|
12
|
+
50% { transform: translateX(150%) skewX(-15deg); }
|
|
13
|
+
100% { transform: translateX(150%) skewX(-15deg); }
|
|
14
|
+
}
|
|
15
|
+
.gr-btn {
|
|
16
|
+
position: fixed;
|
|
17
|
+
width: 50px;
|
|
18
|
+
height: 50px;
|
|
19
|
+
background: ${this.options.modal?.theme?.primaryColor||"#000"};
|
|
20
|
+
box-shadow: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,0.06);
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
z-index: 2147483646;
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease, width .2s, border-radius .2s;
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
29
|
+
box-sizing: border-box;
|
|
30
|
+
}
|
|
31
|
+
.gr-btn * { box-sizing: border-box; }
|
|
32
|
+
.gr-btn:hover {
|
|
33
|
+
transform: scale(1.05);
|
|
34
|
+
box-shadow: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,0.05);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Edge Mode Radii */
|
|
38
|
+
.gr-btn--edge.gr-btn--right { border-radius: 8px 0 0 8px; padding-left: 4px; right: 0; }
|
|
39
|
+
.gr-btn--edge.gr-btn--left { border-radius: 0 8px 8px 0; padding-right: 4px; left: 0; }
|
|
40
|
+
|
|
41
|
+
/* Floating Mode Radii & Position */
|
|
42
|
+
.gr-btn--floating {
|
|
43
|
+
border-radius: 50%;
|
|
44
|
+
box-shadow: 0 8px 24px color-mix(in srgb, ${this.options.modal?.theme?.primaryColor||"#000"}, transparent 60%);
|
|
45
|
+
}
|
|
46
|
+
.gr-btn--floating:hover {
|
|
47
|
+
box-shadow: 0 12px 32px color-mix(in srgb, ${this.options.modal?.theme?.primaryColor||"#000"}, transparent 40%);
|
|
48
|
+
}
|
|
49
|
+
.gr-btn--floating.gr-btn--right { right: 20px; }
|
|
50
|
+
.gr-btn--floating.gr-btn--left { left: 20px; }
|
|
51
|
+
|
|
52
|
+
.gr-btn--bottom { bottom: var(--gr-offset-y); }
|
|
53
|
+
.gr-btn--top { top: var(--gr-offset-y); }
|
|
54
|
+
|
|
55
|
+
.gr-btn::after {
|
|
56
|
+
content: '';
|
|
57
|
+
position: absolute;
|
|
58
|
+
top: 0;
|
|
59
|
+
left: 0;
|
|
60
|
+
width: 100%;
|
|
61
|
+
height: 100%;
|
|
62
|
+
background: linear-gradient(to right, transparent 0%, rgba(255,255,255,0.4) 50%, transparent 100%);
|
|
63
|
+
transform: translateX(-150%) skewX(-15deg);
|
|
64
|
+
animation: gr-shimmer 3s infinite;
|
|
65
|
+
}
|
|
66
|
+
.gr-icon { color: #fff; width: 24px; height: 24px; position: relative; z-index: 10; }
|
|
67
|
+
`,this.shadow.appendChild(r),this.element=document.createElement("div");let i=this.options.trigger?.position||"bottom-right",o=["gr-btn",`gr-btn--${n}`];i.includes("right")?o.push("gr-btn--right"):o.push("gr-btn--left"),i.includes("bottom")?o.push("gr-btn--bottom"):o.push("gr-btn--top"),this.element.className=o.join(" "),this.element.innerHTML=`
|
|
9
68
|
<svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
10
69
|
<polyline points="20 12 20 22 4 22 4 12"></polyline>
|
|
11
70
|
<rect x="2" y="7" width="20" height="5"></rect>
|
|
@@ -13,4 +72,73 @@
|
|
|
13
72
|
<path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
|
|
14
73
|
<path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
|
|
15
74
|
</svg>
|
|
16
|
-
`,this.element.onclick=()=>{
|
|
75
|
+
`,this.element.onclick=()=>{x.showReferralDashboard()},this.shadow.appendChild(this.element),document.body.appendChild(this.host)}};var k=class{static show(e){if(typeof document>"u")return;let r=document.createElement("div");r.id="gr-banner-host",document.body.appendChild(r);let n=r.attachShadow({mode:"open"}),i=(e.banner.position||"center-top").toLowerCase(),o=i.includes("bottom")?"bottom":"top",s=i.includes("left")?"left":i.includes("right")?"right":"center",l="",d="";s==="center"?(l="left: 50%;",d="translateX(-50%)"):(l=`${s}: 20px;`,d="translateX(0)");let c=e.banner.themeColor||"#0070f3",g=document.createElement("style");g.textContent=`
|
|
76
|
+
.gr-banner {
|
|
77
|
+
position: fixed;
|
|
78
|
+
${o}: 20px;
|
|
79
|
+
${l}
|
|
80
|
+
z-index: 2147483647;
|
|
81
|
+
font-family: Inter, system-ui, -apple-system, sans-serif;
|
|
82
|
+
background: var(--gr-theme-color);
|
|
83
|
+
color: #ffffff;
|
|
84
|
+
padding: 12px 20px;
|
|
85
|
+
border-radius: 12px;
|
|
86
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
|
|
87
|
+
display: flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
gap: 12px;
|
|
90
|
+
width: max-content;
|
|
91
|
+
max-width: 500px;
|
|
92
|
+
animation: gr-slide-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
93
|
+
box-sizing: border-box;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@keyframes gr-slide-in {
|
|
97
|
+
from {
|
|
98
|
+
opacity: 0;
|
|
99
|
+
transform: ${d} translateY(${o==="top"?"-20px":"20px"});
|
|
100
|
+
}
|
|
101
|
+
to {
|
|
102
|
+
opacity: 1;
|
|
103
|
+
transform: ${d} translateY(0);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.gr-icon {
|
|
108
|
+
width: 20px;
|
|
109
|
+
height: 20px;
|
|
110
|
+
color: #ffffff;
|
|
111
|
+
flex-shrink: 0;
|
|
112
|
+
}
|
|
113
|
+
.gr-text { font-size: 14px; font-weight: 600; line-height: 1.4; margin: 0; color: #ffffff; flex: 1; }
|
|
114
|
+
.gr-close {
|
|
115
|
+
background: transparent;
|
|
116
|
+
border: none;
|
|
117
|
+
color: rgba(255, 255, 255, 0.8);
|
|
118
|
+
cursor: pointer;
|
|
119
|
+
padding: 4px;
|
|
120
|
+
margin-left: 8px;
|
|
121
|
+
border-radius: 6px;
|
|
122
|
+
display: flex;
|
|
123
|
+
align-items: center;
|
|
124
|
+
justify-content: center;
|
|
125
|
+
transition: all 0.2s;
|
|
126
|
+
flex-shrink: 0;
|
|
127
|
+
}
|
|
128
|
+
.gr-close:hover { background: rgba(255, 255, 255, 0.2); color: #ffffff; }
|
|
129
|
+
`;let h=document.createElement("div");h.className="gr-banner",h.style.setProperty("--gr-theme-color",c),h.innerHTML=`
|
|
130
|
+
<svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
131
|
+
<polyline points="20 12 20 22 4 22 4 12"></polyline>
|
|
132
|
+
<rect x="2" y="7" width="20" height="5"></rect>
|
|
133
|
+
<line x1="12" y1="22" x2="12" y2="7"></line>
|
|
134
|
+
<path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
|
|
135
|
+
<path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
|
|
136
|
+
</svg>
|
|
137
|
+
<p class="gr-text">${e.banner.text}</p>
|
|
138
|
+
<button class="gr-close" aria-label="Close banner">
|
|
139
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
140
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
141
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
142
|
+
</svg>
|
|
143
|
+
</button>
|
|
144
|
+
`,h.querySelector(".gr-close")?.addEventListener("click",()=>{r.remove()}),n.appendChild(g),n.appendChild(h)}};var t=class t{constructor(){}static init(e){t.initialized||(t.options=e,t.api=new y(e),t.storage=new v({cookieDomain:e.cookieDomain}),t.initialized=!0,t.autoTrackReferral())}static isInitialized(){return t.initialized}static ensureInitialized(){if(!t.initialized)throw new Error("GrowthRail.init() must be called before using the SDK")}static async loadReferrerExperience(e){try{t.createReferralModal(e),e.trigger.show&&t.createTriggerButton(e.trigger)}catch(r){throw console.error("GrowthRail: Failed to load referrer experience",r),r}}static createReferralModal(e){t.referralModal=new m({isUserReady:()=>t.isUserReady(),getReferralLink:()=>t.currentUser?.referralLink||""},e)}static async autoTrackReferral(){if(typeof window>"u")return;let e=new URLSearchParams(window.location.search),r=e.get("referralCode"),n=e.get("rewardEventName");if(r){let i=await t.api.getNewUserExperience(),o=await t.trackReferral(r,n??void 0);t.storage.setTrackedReferral(o.referralTrackingId),i.banner.show&&k.show(i)}}static async initAppUser(e){t.ensureInitialized();let r=await t.api.initAppUser(e);return t.currentUser={...r,id:e},t.experience=r.referrerExperience,t.loadReferrerExperience(r.referrerExperience),t.userReadyResolver?t.userReadyResolver(t.currentUser):t.userReadyPromise=Promise.resolve(t.currentUser),r}static async trackReferral(e,r){return t.ensureInitialized(),t.api.trackReferral(e,r)}static async trackRewardEvent(e){t.ensureInitialized();let r=t.currentUser?.id;if(!r)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let n=t.storage.getTrackedReferral();if(!n)throw new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");return t.api.trackRewardEvent(r,n,e)}static getReferralLink(){if(!t.currentUser?.referralLink)throw new Error("GrowthRail: Referral Link not loaded or user not initialized");return t.currentUser.referralLink}static getReferralCode(){return t.currentUser?.referralCode}static getUserId(){return t.currentUser?.id}static isUserReady(){return t.currentUser!==null}static ensureUserReady(){return t.currentUser?Promise.resolve(t.currentUser):(t.userReadyPromise||(t.userReadyPromise=new Promise(e=>{t.userReadyResolver=e})),t.userReadyPromise)}static async showReferralDashboard(e){if(t.ensureInitialized(),!t.experience)throw new Error("GrowthRail: Experience not loaded");t.referralModal&&t.referralModal.hide(),t.referralModal?.show(e)}static createTriggerButton(e){if(typeof window>"u")return;if(!t.experience)throw new Error("GrowthRail: Experience not loaded");t.floatingButton&&t.floatingButton.unmount();let r={...t.experience?.trigger,...e},n={modal:{...t.experience.modal},trigger:r};t.floatingButton=new w(n),t.floatingButton.mount()}static destroyTriggerButton(){t.floatingButton&&(t.floatingButton.unmount(),t.floatingButton=null)}};a(t,"api"),a(t,"storage"),a(t,"options"),a(t,"currentUser",null),a(t,"initialized",!1),a(t,"referralModal",null),a(t,"floatingButton",null),a(t,"experience",null),a(t,"userReadyPromise",null),a(t,"userReadyResolver",null);var x=t;0&&(module.exports={GrowthRail,ReferralModal});
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
|
-
var v=Object.defineProperty;var w=(g,e,t)=>e in g?v(g,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):g[e]=t;var a=(g,e,t)=>w(g,typeof e!="symbol"?e+"":e,t);var u=class{constructor(e){a(this,"baseUrl");a(this,"apiKey");let t=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=t||"http://hw84ko0ok4ccws4sws8gos0o.193.31.30.10.sslip.io",this.apiKey=e.apiKey}async request(e,t,i){let n={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.apiKey};try{let o=await fetch(`${this.baseUrl}${e}`,{method:t,headers:n,body:i?JSON.stringify(i):void 0});if(!o.ok)throw new Error(`GrowthRail API Error: ${o.statusText}`);return o.json()}catch(o){throw console.error("GrowthRail SDK Error:",o),o}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(e){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:e})}async createReferralLink(e,t){return this.request("/api/v1/sdk/create-referral-link","POST",{referrerId:e,rewardEventName:t})}async trackReferral(e,t){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:t})}async trackRewardEvent(e,t,i){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:t,eventName:i})}};var f=class f{constructor(e){a(this,"options",{});e&&(this.options=e)}setCookie(e,t,i=30){if(typeof document>"u")return;let n="";if(i){let s=new Date;s.setTime(s.getTime()+i*24*60*60*1e3),n=`; expires=${s.toUTCString()}`}let o="";this.options.cookieDomain&&(o=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${t||""}${n}${o}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let t=`${e}=`,i=document.cookie.split(";");for(let n=0;n<i.length;n++){let o=i[n];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(t)===0)return o.substring(t.length,o.length)}return null}getReferralCode(){return this.getCookie(f.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(f.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(f.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(f.TRACKED_REFERRAL_KEY)}};a(f,"REFERRAL_CODE_KEY","gr_ref_code"),a(f,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var m=f;var y=class{constructor(e,t){a(this,"referrerExperience");a(this,"deps");a(this,"host",null);a(this,"shadow",null);a(this,"overlay",null);a(this,"content",null);this.deps=e,this.referrerExperience=t}show(e,t){this.host||(this.createDom(e,t),this.bindEvents(),t||(document.body.style.overflow="hidden"))}hide(){this.host&&(this.host&&this.host.parentNode&&this.host.parentNode.removeChild(this.host),this.host=null,this.overlay=null,this.content=null,this.shadow=null,document.body.style.overflow="")}createDom(e,t){let i={...this.referrerExperience,...e??{}},n=this.getTheme(),o={...n,colorPrimary:i.modal?.theme?.primaryColor||n.colorPrimary,colorBackground:i.modal?.theme?.backgroundColor||n.colorBackground,colorTint:i.modal?.theme?.tintColor||n.colorTint},s=!!t;this.host=document.createElement("div"),this.host.style.all="initial",s?(this.host.style.display="block",this.host.style.width="100%",this.host.style.height="100%"):(this.host.style.position="absolute",this.host.style.zIndex="2147483647"),this.host.id="growth-rail-modal-host",this.host.style.setProperty("--gr-primary",o.colorPrimary),this.host.style.setProperty("--gr-text",o.colorText),this.host.style.setProperty("--gr-text-secondary",o.colorTextSecondary),this.host.style.setProperty("--gr-bg",o.colorBackground),this.host.style.setProperty("--gr-tint",o.colorTint),this.host.style.setProperty("--gr-surface",o.colorSurface),this.host.style.setProperty("--gr-border",o.colorBorder),this.host.style.setProperty("--gr-error",o.colorError),this.host.style.setProperty("--gr-radius",o.borderRadius),this.host.style.setProperty("--gr-font",'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),this.shadow=this.host.attachShadow({mode:"open"});let c=document.createElement("style");c.textContent=":host{all:initial;display:block}*{box-sizing:border-box}@keyframes gr-fade-in{from{opacity:0}to{opacity:1}}@keyframes gr-slide-up{from{opacity:0;transform:translateY(20px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes gr-slide-in-right{from{opacity:0;transform:translateX(100%)}to{opacity:1;transform:translateX(0)}}@keyframes gr-slide-in-left{from{opacity:0;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}.gr-overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;display:flex;z-index:2147483647;font-family:var(--gr-font);animation:gr-fade-in .2s ease-out forwards;backdrop-filter:blur(4px)}.gr-overlay--modal{background-color:var(--gr-tint);align-items:center;justify-content:center}.gr-overlay--drawer{background-color:var(--gr-tint);align-items:flex-start;justify-content:flex-start}.gr-container{position:relative;background-color:var(--gr-bg);color:var(--gr-text);padding:32px;box-shadow:0 20px 25px -5px rgba(0,0,0,.1),0 10px 10px -5px rgba(0,0,0,.04)}.gr-container--embedded{width:100%;height:100%;box-shadow:none;border:1px solid var(--gr-border);border-radius:var(--gr-radius)}.gr-container--modal{width:90%;max-width:480px;border-radius:var(--gr-radius);animation:gr-slide-up .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--drawer{position:absolute;width:400px;max-width:calc(100vw - 20px);max-height:calc(100vh - 40px);overflow-y:auto}.gr-container--right{right:0;border-top-left-radius:var(--gr-radius);border-bottom-left-radius:var(--gr-radius);animation:gr-slide-in-right .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--left{left:0;border-top-right-radius:var(--gr-radius);border-bottom-right-radius:var(--gr-radius);animation:gr-slide-in-left .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--top{top:100px}.gr-container--bottom{bottom:100px}.gr-close-btn{position:absolute;top:20px;right:20px;background:0 0;border:none;cursor:pointer;color:#9ca3af;padding:4px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:all .2s}.gr-close-btn:hover{background-color:var(--gr-surface);color:var(--gr-text)}.gr-header{text-align:center;margin-bottom:28px}.gr-icon-lg{font-size:32px;margin-bottom:12px}.gr-title{margin:0 0 8px 0;font-size:22px;font-weight:700;letter-spacing:-.02em}.gr-subtitle{margin:0;font-size:14px;line-height:1.5;color:var(--gr-text-secondary)}.gr-loading{padding:16px;background-color:var(--gr-surface);border-radius:8px;text-align:center;color:var(--gr-text-secondary);font-size:14px}.gr-label{display:block;font-size:12px;font-weight:600;color:var(--gr-text-secondary);margin-bottom:8px;text-transform:uppercase;letter-spacing:.05em}.gr-share-label{text-align:center;margin-bottom:16px;font-size:13px;font-weight:500;color:var(--gr-text-secondary);display:flex;align-items:center;gap:12px}.gr-divider{flex:1;height:1px;background:var(--gr-border)}.gr-social-container{display:flex;gap:16px;justify-content:center;flex-wrap:wrap}.gr-btn{padding:14px;font-size:15px;font-weight:600;background-color:var(--gr-primary);color:#fff;border:none;border-radius:var(--gr-radius);cursor:pointer;transition:all .2s ease;text-align:center;width:100%;display:block}.gr-btn:hover{transform:translateY(-1px);filter:brightness(1.05)}.gr-btn:active{transform:translateY(0);filter:brightness(.95)}.gr-btn:disabled{opacity:.7;cursor:not-allowed}.gr-btn--sm{padding:8px 16px;font-size:13px;width:auto;border-radius:calc(var(--gr-radius) - 4px)}.gr-input-group{display:flex;align-items:center;background-color:var(--gr-surface);border:1px solid var(--gr-border);border-radius:var(--gr-radius);padding:4px;margin-bottom:24px}.gr-input-group:focus-within{border-color:var(--gr-primary);box-shadow:0 0 0 3px var(--gr-surface)}.gr-input{flex:1;padding:10px 12px;font-size:14px;border:none;background:0 0;color:var(--gr-text);outline:none;font-family:monospace}.gr-social-btn{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border-radius:50%;background-color:var(--gr-surface);color:var(--gr-text-secondary);border:1px solid var(--gr-border);transition:transform .2s cubic-bezier(.34,1.56,.64,1);cursor:pointer}.gr-social-btn:hover{transform:scale(1.15) rotate(3deg);color:#fff}.gr-powered-by{margin-top:24px;text-align:center;font-size:11px;color:#9ca3af;display:flex;align-items:center;justify-content:center;gap:4px;opacity:.8}.gr-powered-by a{color:inherit;text-decoration:none;font-weight:600;transition:opacity .2s}.gr-powered-by a:hover{opacity:1;text-decoration:underline}",this.shadow.appendChild(c),this.content=document.createElement("div");let d=i.modal.type==="drawer",l=i.trigger.position||"top-right",p=["gr-container"];s?(p.push("gr-container--embedded"),this.content.className=p.join(" "),this.renderInternalContent(o,e,s),this.shadow.appendChild(this.content),t&&t.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${d?"gr-overlay--drawer":"gr-overlay--modal"}`,d?(p.push("gr-container--drawer"),l.includes("right")?p.push("gr-container--right"):p.push("gr-container--left"),l.includes("bottom")?p.push("gr-container--bottom"):p.push("gr-container--top")):p.push("gr-container--modal"),this.content.className=p.join(" "),this.renderInternalContent(o,e,s),this.overlay.appendChild(this.content),this.shadow.appendChild(this.overlay),document.body.appendChild(this.host),this.overlay.onclick=h=>{h.target===this.overlay&&this.hide()})}getTheme(){return{colorPrimary:"#2563eb",colorText:"#111827",colorTextSecondary:"#6b7280",colorBackground:"#ffffff",colorTint:"#f9fafb",colorSurface:"#f9fafb",colorBorder:"#e5e7eb",colorError:"#ef4444",borderRadius:"16px"}}async renderInternalContent(e,t,i=!1){if(!this.content)return;if(this.content.innerHTML="",!i){let h=document.createElement("button");h.className="gr-close-btn",h.innerHTML=`
|
|
1
|
+
var E=Object.defineProperty;var C=(h,e,t)=>e in h?E(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t;var a=(h,e,t)=>C(h,typeof e!="symbol"?e+"":e,t);var m=class{constructor(e){a(this,"baseUrl");a(this,"apiKey");let t=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=t||"https://api.growthrail.dev",this.apiKey=e.apiKey}async request(e,t,n){let i={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.apiKey};try{let o=await fetch(`${this.baseUrl}${e}`,{method:t,headers:i,body:n?JSON.stringify(n):void 0});if(!o.ok)throw new Error(`GrowthRail API Error: ${o.statusText}`);return o.json()}catch(o){throw console.error("GrowthRail SDK Error:",o),o}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(e){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:e})}async createReferralLink(e,t){return this.request("/api/v1/sdk/create-referral-link","POST",{referrerId:e,rewardEventName:t})}async trackReferral(e,t){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:t})}async trackRewardEvent(e,t,n){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:t,eventName:n})}};var u=class u{constructor(e){a(this,"options",{});e&&(this.options=e)}setCookie(e,t,n=30){if(typeof document>"u")return;let i="";if(n){let s=new Date;s.setTime(s.getTime()+n*24*60*60*1e3),i=`; expires=${s.toUTCString()}`}let o="";this.options.cookieDomain&&(o=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${t||""}${i}${o}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let t=`${e}=`,n=document.cookie.split(";");for(let i=0;i<n.length;i++){let o=n[i];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(t)===0)return o.substring(t.length,o.length)}return null}getReferralCode(){return this.getCookie(u.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(u.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(u.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(u.TRACKED_REFERRAL_KEY)}};a(u,"REFERRAL_CODE_KEY","gr_ref_code"),a(u,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var x=u;var b=class{constructor(e,t){a(this,"referrerExperience");a(this,"deps");a(this,"host",null);a(this,"shadow",null);a(this,"overlay",null);a(this,"content",null);this.deps=e,this.referrerExperience=t}show(e,t){this.host||(this.createDom(e,t),this.bindEvents(),t||(document.body.style.overflow="hidden"))}hide(){this.host&&(this.host&&this.host.parentNode&&this.host.parentNode.removeChild(this.host),this.host=null,this.overlay=null,this.content=null,this.shadow=null,document.body.style.overflow="")}createDom(e,t){let n={...this.referrerExperience,modal:{...this.referrerExperience.modal,...e??{},theme:{...this.referrerExperience.modal?.theme,...e?.theme??{}}}},i=this.getTheme(),o={...i,colorPrimary:n.modal?.theme?.primaryColor||i.colorPrimary,colorBackground:n.modal?.theme?.backgroundColor||i.colorBackground,colorTint:n.modal?.theme?.tintColor||i.colorTint,tintAlpha:n.modal?.theme?.tintAlpha??i.tintAlpha},s=!!t;this.host=document.createElement("div"),this.host.style.all="initial",s?(this.host.style.display="block",this.host.style.width="100%",this.host.style.height="100%"):(this.host.style.position="absolute",this.host.style.zIndex="2147483647"),this.host.id="growth-rail-modal-host",this.host.style.setProperty("--gr-primary",o.colorPrimary),this.host.style.setProperty("--gr-text",o.colorText),this.host.style.setProperty("--gr-text-secondary",o.colorTextSecondary),this.host.style.setProperty("--gr-bg",o.colorBackground),this.host.style.setProperty("--gr-tint",o.colorTint);let l=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o.colorTint),d=o.tintAlpha>1?o.tintAlpha/100:o.tintAlpha,c=l?`rgba(${parseInt(l[1],16)}, ${parseInt(l[2],16)}, ${parseInt(l[3],16)}, ${d})`:`rgba(0, 0, 0, ${d})`;this.host.style.setProperty("--gr-tint-rgba",c),this.host.style.setProperty("--gr-surface",o.colorSurface),this.host.style.setProperty("--gr-border",o.colorBorder),this.host.style.setProperty("--gr-error",o.colorError),this.host.style.setProperty("--gr-radius",o.borderRadius),this.host.style.setProperty("--gr-font",'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),this.shadow=this.host.attachShadow({mode:"open"});let g=document.createElement("style");g.textContent=":host{all:initial;display:block}*{box-sizing:border-box}@keyframes gr-fade-in{from{opacity:0}to{opacity:1}}@keyframes gr-slide-up{from{opacity:0;transform:translateY(20px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes gr-slide-in-right{from{opacity:0;transform:translateX(100%)}to{opacity:1;transform:translateX(0)}}@keyframes gr-slide-in-left{from{opacity:0;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}.gr-overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;display:flex;z-index:2147483647;font-family:var(--gr-font);animation:gr-fade-in .2s ease-out forwards;backdrop-filter:blur(4px);background-color:var(--gr-tint-rgba)}.gr-overlay--modal{align-items:center;justify-content:center}.gr-overlay--drawer{align-items:flex-start;justify-content:flex-start}.gr-container{position:relative;background-color:var(--gr-bg);color:var(--gr-text);padding:32px;box-shadow:0 0 50px -12px rgba(0,0,0,0.25), 0 0 30px -10px rgba(0,0,0,0.15)}.gr-container--embedded{width:100%;height:100%;box-shadow:none;border:1px solid var(--gr-border);border-radius:var(--gr-radius)}.gr-container--modal{width:90%;max-width:480px;border-radius:var(--gr-radius);animation:gr-slide-up .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--drawer{position:absolute;width:400px;max-width:calc(100vw - 20px);max-height:calc(100vh - 40px);overflow-y:auto}.gr-container--right{right:0;border-top-left-radius:var(--gr-radius);border-bottom-left-radius:var(--gr-radius);animation:gr-slide-in-right .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--left{left:0;border-top-right-radius:var(--gr-radius);border-bottom-right-radius:var(--gr-radius);animation:gr-slide-in-left .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--top{top:100px}.gr-container--bottom{bottom:100px}.gr-close-btn{position:absolute;top:20px;right:20px;background:0 0;border:none;cursor:pointer;color:#9ca3af;padding:4px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:all .2s}.gr-close-btn:hover{background-color:var(--gr-surface);color:var(--gr-text)}.gr-header{text-align:center;margin-bottom:28px}.gr-icon-lg{font-size:32px;margin-bottom:12px}.gr-title{margin:0 0 8px 0;font-size:22px;font-weight:700;letter-spacing:-.02em}.gr-subtitle{margin:0;font-size:14px;line-height:1.5;color:var(--gr-text-secondary)}.gr-loading{padding:16px;background-color:var(--gr-surface);border-radius:8px;text-align:center;color:var(--gr-text-secondary);font-size:14px}.gr-label{display:block;font-size:12px;font-weight:600;color:var(--gr-text-secondary);margin-bottom:8px;text-transform:uppercase;letter-spacing:.05em}.gr-share-label{text-align:center;margin-bottom:16px;font-size:13px;font-weight:500;color:var(--gr-text-secondary);display:flex;align-items:center;gap:12px}.gr-divider{flex:1;height:1px;background:var(--gr-border)}.gr-social-container{display:flex;gap:16px;justify-content:center;flex-wrap:wrap}.gr-btn{padding:14px;font-size:15px;font-weight:600;background-color:var(--gr-primary);color:#fff;border:none;border-radius:var(--gr-radius);cursor:pointer;transition:all .2s ease;text-align:center;width:100%;display:block}.gr-btn:hover{transform:translateY(-1px);filter:brightness(1.05)}.gr-btn:active{transform:translateY(0);filter:brightness(.95)}.gr-btn:disabled{opacity:.7;cursor:not-allowed}.gr-btn--sm{padding:8px 16px;font-size:13px;width:auto;border-radius:calc(var(--gr-radius) - 4px)}.gr-input-group{display:flex;align-items:center;background-color:var(--gr-surface);border:1px solid var(--gr-border);border-radius:var(--gr-radius);padding:4px;margin-bottom:24px}.gr-input-group:focus-within{border-color:var(--gr-primary);box-shadow:0 0 0 3px var(--gr-surface)}.gr-input{flex:1;padding:10px 12px;font-size:14px;border:none;background:0 0;color:var(--gr-text);outline:none;font-family:monospace}.gr-social-btn{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border-radius:50%;background-color:var(--gr-surface);color:var(--gr-text-secondary);border:1px solid var(--gr-border);transition:transform .2s cubic-bezier(.34,1.56,.64,1);cursor:pointer}.gr-social-btn:hover{transform:scale(1.15) rotate(3deg);color:#fff}.gr-powered-by{margin-top:24px;text-align:center;font-size:11px;color:#9ca3af;display:flex;align-items:center;justify-content:center;gap:4px;opacity:.8}.gr-powered-by a{color:inherit;text-decoration:none;font-weight:600;transition:opacity .2s}.gr-powered-by a:hover{opacity:1;text-decoration:underline}",this.shadow.appendChild(g),this.content=document.createElement("div");let p=n.modal.componentType==="drawer",k=n.trigger.position||"top-right",f=["gr-container"];s?(f.push("gr-container--embedded"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.shadow.appendChild(this.content),t&&t.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${p?"gr-overlay--drawer":"gr-overlay--modal"}`,p?(f.push("gr-container--drawer"),k.includes("right")?f.push("gr-container--right"):f.push("gr-container--left"),k.includes("bottom")?f.push("gr-container--bottom"):f.push("gr-container--top")):f.push("gr-container--modal"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.overlay.appendChild(this.content),this.shadow.appendChild(this.overlay),document.body.appendChild(this.host),this.overlay.onclick=R=>{R.target===this.overlay&&this.hide()})}getTheme(){return{colorPrimary:"#2563eb",colorText:"#111827",colorTextSecondary:"#6b7280",colorBackground:"#ffffff",colorTint:"#f9fafb",tintAlpha:.8,colorSurface:"#f9fafb",colorBorder:"#e5e7eb",colorError:"#ef4444",borderRadius:"16px"}}async renderInternalContent(e,t,n=!1){if(!this.content)return;if(this.content.innerHTML="",!n){let p=document.createElement("button");p.className="gr-close-btn",p.innerHTML=`
|
|
2
2
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
3
3
|
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
4
4
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
5
5
|
</svg>
|
|
6
|
-
`,
|
|
6
|
+
`,p.onclick=()=>this.hide(),this.content.appendChild(p)}let i=document.createElement("div");i.className="gr-header";let o=document.createElement("div");o.className="gr-icon-lg",o.innerHTML="\u{1F381}",i.appendChild(o);let s=document.createElement("h3");s.className="gr-title",s.textContent=t?.title??this.referrerExperience.modal.title??"Invite Friends & Earn",i.appendChild(s);let l=document.createElement("p");if(l.className="gr-subtitle",l.textContent="Share your unique link and earn rewards for every friend who signs up.",i.appendChild(l),this.content.appendChild(i),!this.deps.isUserReady()){let p=document.createElement("div");p.className="gr-loading",p.textContent="Please log in to view your referral dashboard.",this.content.appendChild(p);return}let d=this.deps.getReferralLink(),c=document.createElement("div");this.renderLinkView(c,d,e),this.content.appendChild(c),d&&this.renderSocialShare(this.content,d,e);let g=document.createElement("div");g.className="gr-powered-by",g.innerHTML=`
|
|
7
7
|
Powered by <a href="https://growthrail.com" target="_blank" rel="noopener noreferrer">Growth Rail</a>
|
|
8
|
-
`,this.content.appendChild(
|
|
8
|
+
`,this.content.appendChild(g)}renderLinkView(e,t,n){let i=document.createElement("label");i.className="gr-label",i.textContent="Your unique link",e.appendChild(i);let o=document.createElement("div");o.className="gr-input-group";let s=document.createElement("input");s.className="gr-input",s.type="text",s.value=t,s.readOnly=!0;let l=document.createElement("button");l.className="gr-btn gr-btn--sm",l.textContent="Copy",l.onclick=async()=>{try{await navigator.clipboard.writeText(t);let d=l.textContent;l.textContent="Copied!",l.style.backgroundColor="#10b981",setTimeout(()=>{l.textContent=d,l.style.backgroundColor=""},2e3)}catch(d){console.error("Failed to copy",d)}},o.appendChild(s),o.appendChild(l),e.appendChild(o)}renderSocialShare(e,t,n){let i=document.createElement("div"),o=document.createElement("div");o.className="gr-share-label",o.innerHTML='<span class="gr-divider"></span>Share via<span class="gr-divider"></span>',i.appendChild(o);let s=document.createElement("div");s.className="gr-social-container",[{name:"Twitter",color:"#000000",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>',url:`https://twitter.com/intent/tweet?url=${encodeURIComponent(t)}&text=Check+this+out!`},{name:"Facebook",color:"#1877F2",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036c-2.648 0-2.928 1.67-2.928 3.403v1.596h3.949l-.577 3.667h-3.372v7.98h-4.938z"/></svg>',url:`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(t)}`},{name:"LinkedIn",color:"#0A66C2",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>',url:`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(t)}`},{name:"WhatsApp",color:"#25D366",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/></svg>',url:`https://api.whatsapp.com/send?text=${encodeURIComponent(t)}`},{name:"Email",color:"#888888",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/></svg>',url:`mailto:?subject=Check this out&body=${encodeURIComponent(t)}`}].forEach(d=>{let c=document.createElement("a");c.href=d.url,c.target="_blank",c.rel="noopener noreferrer",c.className="gr-social-btn",c.innerHTML=d.icon,c.title=`Share on ${d.name}`,c.onmouseenter=()=>{c.style.backgroundColor=d.color,c.style.color="#ffffff",c.style.borderColor=d.color},c.onmouseleave=()=>{c.style.backgroundColor="",c.style.color="",c.style.borderColor=""},s.appendChild(c)}),i.appendChild(s),e.appendChild(i)}bindEvents(){this.overlay&&(this.overlay.onclick=e=>{e.target===this.overlay&&this.hide()})}};var y=class{constructor(e){a(this,"options");a(this,"host",null);a(this,"shadow",null);a(this,"element",null);this.options=e}mount(){this.host||this.createDom()}unmount(){this.host&&this.host.parentNode&&document.body.removeChild(this.host),this.host=null,this.shadow=null,this.element=null}createDom(){this.host=document.createElement("div"),this.host.style.all="initial",this.host.style.position="absolute",this.host.style.zIndex="2147483646";let e={x:0,y:100};this.host.style.setProperty("--gr-offset-y",`${e.y}px`),this.shadow=this.host.attachShadow({mode:"open"});let t=document.createElement("style"),n=this.options.trigger?.displayMode||"edge";t.textContent=`
|
|
9
|
+
:host { all: initial; display: block; }
|
|
10
|
+
@keyframes gr-shimmer {
|
|
11
|
+
0% { transform: translateX(-150%) skewX(-15deg); }
|
|
12
|
+
50% { transform: translateX(150%) skewX(-15deg); }
|
|
13
|
+
100% { transform: translateX(150%) skewX(-15deg); }
|
|
14
|
+
}
|
|
15
|
+
.gr-btn {
|
|
16
|
+
position: fixed;
|
|
17
|
+
width: 50px;
|
|
18
|
+
height: 50px;
|
|
19
|
+
background: ${this.options.modal?.theme?.primaryColor||"#000"};
|
|
20
|
+
box-shadow: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,0.06);
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
z-index: 2147483646;
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease, width .2s, border-radius .2s;
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
29
|
+
box-sizing: border-box;
|
|
30
|
+
}
|
|
31
|
+
.gr-btn * { box-sizing: border-box; }
|
|
32
|
+
.gr-btn:hover {
|
|
33
|
+
transform: scale(1.05);
|
|
34
|
+
box-shadow: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,0.05);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Edge Mode Radii */
|
|
38
|
+
.gr-btn--edge.gr-btn--right { border-radius: 8px 0 0 8px; padding-left: 4px; right: 0; }
|
|
39
|
+
.gr-btn--edge.gr-btn--left { border-radius: 0 8px 8px 0; padding-right: 4px; left: 0; }
|
|
40
|
+
|
|
41
|
+
/* Floating Mode Radii & Position */
|
|
42
|
+
.gr-btn--floating {
|
|
43
|
+
border-radius: 50%;
|
|
44
|
+
box-shadow: 0 8px 24px color-mix(in srgb, ${this.options.modal?.theme?.primaryColor||"#000"}, transparent 60%);
|
|
45
|
+
}
|
|
46
|
+
.gr-btn--floating:hover {
|
|
47
|
+
box-shadow: 0 12px 32px color-mix(in srgb, ${this.options.modal?.theme?.primaryColor||"#000"}, transparent 40%);
|
|
48
|
+
}
|
|
49
|
+
.gr-btn--floating.gr-btn--right { right: 20px; }
|
|
50
|
+
.gr-btn--floating.gr-btn--left { left: 20px; }
|
|
51
|
+
|
|
52
|
+
.gr-btn--bottom { bottom: var(--gr-offset-y); }
|
|
53
|
+
.gr-btn--top { top: var(--gr-offset-y); }
|
|
54
|
+
|
|
55
|
+
.gr-btn::after {
|
|
56
|
+
content: '';
|
|
57
|
+
position: absolute;
|
|
58
|
+
top: 0;
|
|
59
|
+
left: 0;
|
|
60
|
+
width: 100%;
|
|
61
|
+
height: 100%;
|
|
62
|
+
background: linear-gradient(to right, transparent 0%, rgba(255,255,255,0.4) 50%, transparent 100%);
|
|
63
|
+
transform: translateX(-150%) skewX(-15deg);
|
|
64
|
+
animation: gr-shimmer 3s infinite;
|
|
65
|
+
}
|
|
66
|
+
.gr-icon { color: #fff; width: 24px; height: 24px; position: relative; z-index: 10; }
|
|
67
|
+
`,this.shadow.appendChild(t),this.element=document.createElement("div");let i=this.options.trigger?.position||"bottom-right",o=["gr-btn",`gr-btn--${n}`];i.includes("right")?o.push("gr-btn--right"):o.push("gr-btn--left"),i.includes("bottom")?o.push("gr-btn--bottom"):o.push("gr-btn--top"),this.element.className=o.join(" "),this.element.innerHTML=`
|
|
9
68
|
<svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
10
69
|
<polyline points="20 12 20 22 4 22 4 12"></polyline>
|
|
11
70
|
<rect x="2" y="7" width="20" height="5"></rect>
|
|
@@ -13,4 +72,73 @@ var v=Object.defineProperty;var w=(g,e,t)=>e in g?v(g,e,{enumerable:!0,configura
|
|
|
13
72
|
<path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
|
|
14
73
|
<path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
|
|
15
74
|
</svg>
|
|
16
|
-
`,this.element.onclick=()=>{
|
|
75
|
+
`,this.element.onclick=()=>{v.showReferralDashboard()},this.shadow.appendChild(this.element),document.body.appendChild(this.host)}};var w=class{static show(e){if(typeof document>"u")return;let t=document.createElement("div");t.id="gr-banner-host",document.body.appendChild(t);let n=t.attachShadow({mode:"open"}),i=(e.banner.position||"center-top").toLowerCase(),o=i.includes("bottom")?"bottom":"top",s=i.includes("left")?"left":i.includes("right")?"right":"center",l="",d="";s==="center"?(l="left: 50%;",d="translateX(-50%)"):(l=`${s}: 20px;`,d="translateX(0)");let c=e.banner.themeColor||"#0070f3",g=document.createElement("style");g.textContent=`
|
|
76
|
+
.gr-banner {
|
|
77
|
+
position: fixed;
|
|
78
|
+
${o}: 20px;
|
|
79
|
+
${l}
|
|
80
|
+
z-index: 2147483647;
|
|
81
|
+
font-family: Inter, system-ui, -apple-system, sans-serif;
|
|
82
|
+
background: var(--gr-theme-color);
|
|
83
|
+
color: #ffffff;
|
|
84
|
+
padding: 12px 20px;
|
|
85
|
+
border-radius: 12px;
|
|
86
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
|
|
87
|
+
display: flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
gap: 12px;
|
|
90
|
+
width: max-content;
|
|
91
|
+
max-width: 500px;
|
|
92
|
+
animation: gr-slide-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
93
|
+
box-sizing: border-box;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@keyframes gr-slide-in {
|
|
97
|
+
from {
|
|
98
|
+
opacity: 0;
|
|
99
|
+
transform: ${d} translateY(${o==="top"?"-20px":"20px"});
|
|
100
|
+
}
|
|
101
|
+
to {
|
|
102
|
+
opacity: 1;
|
|
103
|
+
transform: ${d} translateY(0);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.gr-icon {
|
|
108
|
+
width: 20px;
|
|
109
|
+
height: 20px;
|
|
110
|
+
color: #ffffff;
|
|
111
|
+
flex-shrink: 0;
|
|
112
|
+
}
|
|
113
|
+
.gr-text { font-size: 14px; font-weight: 600; line-height: 1.4; margin: 0; color: #ffffff; flex: 1; }
|
|
114
|
+
.gr-close {
|
|
115
|
+
background: transparent;
|
|
116
|
+
border: none;
|
|
117
|
+
color: rgba(255, 255, 255, 0.8);
|
|
118
|
+
cursor: pointer;
|
|
119
|
+
padding: 4px;
|
|
120
|
+
margin-left: 8px;
|
|
121
|
+
border-radius: 6px;
|
|
122
|
+
display: flex;
|
|
123
|
+
align-items: center;
|
|
124
|
+
justify-content: center;
|
|
125
|
+
transition: all 0.2s;
|
|
126
|
+
flex-shrink: 0;
|
|
127
|
+
}
|
|
128
|
+
.gr-close:hover { background: rgba(255, 255, 255, 0.2); color: #ffffff; }
|
|
129
|
+
`;let p=document.createElement("div");p.className="gr-banner",p.style.setProperty("--gr-theme-color",c),p.innerHTML=`
|
|
130
|
+
<svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
131
|
+
<polyline points="20 12 20 22 4 22 4 12"></polyline>
|
|
132
|
+
<rect x="2" y="7" width="20" height="5"></rect>
|
|
133
|
+
<line x1="12" y1="22" x2="12" y2="7"></line>
|
|
134
|
+
<path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
|
|
135
|
+
<path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
|
|
136
|
+
</svg>
|
|
137
|
+
<p class="gr-text">${e.banner.text}</p>
|
|
138
|
+
<button class="gr-close" aria-label="Close banner">
|
|
139
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
140
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
141
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
142
|
+
</svg>
|
|
143
|
+
</button>
|
|
144
|
+
`,p.querySelector(".gr-close")?.addEventListener("click",()=>{t.remove()}),n.appendChild(g),n.appendChild(p)}};var r=class r{constructor(){}static init(e){r.initialized||(r.options=e,r.api=new m(e),r.storage=new x({cookieDomain:e.cookieDomain}),r.initialized=!0,r.autoTrackReferral())}static isInitialized(){return r.initialized}static ensureInitialized(){if(!r.initialized)throw new Error("GrowthRail.init() must be called before using the SDK")}static async loadReferrerExperience(e){try{r.createReferralModal(e),e.trigger.show&&r.createTriggerButton(e.trigger)}catch(t){throw console.error("GrowthRail: Failed to load referrer experience",t),t}}static createReferralModal(e){r.referralModal=new b({isUserReady:()=>r.isUserReady(),getReferralLink:()=>r.currentUser?.referralLink||""},e)}static async autoTrackReferral(){if(typeof window>"u")return;let e=new URLSearchParams(window.location.search),t=e.get("referralCode"),n=e.get("rewardEventName");if(t){let i=await r.api.getNewUserExperience(),o=await r.trackReferral(t,n??void 0);r.storage.setTrackedReferral(o.referralTrackingId),i.banner.show&&w.show(i)}}static async initAppUser(e){r.ensureInitialized();let t=await r.api.initAppUser(e);return r.currentUser={...t,id:e},r.experience=t.referrerExperience,r.loadReferrerExperience(t.referrerExperience),r.userReadyResolver?r.userReadyResolver(r.currentUser):r.userReadyPromise=Promise.resolve(r.currentUser),t}static async trackReferral(e,t){return r.ensureInitialized(),r.api.trackReferral(e,t)}static async trackRewardEvent(e){r.ensureInitialized();let t=r.currentUser?.id;if(!t)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let n=r.storage.getTrackedReferral();if(!n)throw new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");return r.api.trackRewardEvent(t,n,e)}static getReferralLink(){if(!r.currentUser?.referralLink)throw new Error("GrowthRail: Referral Link not loaded or user not initialized");return r.currentUser.referralLink}static getReferralCode(){return r.currentUser?.referralCode}static getUserId(){return r.currentUser?.id}static isUserReady(){return r.currentUser!==null}static ensureUserReady(){return r.currentUser?Promise.resolve(r.currentUser):(r.userReadyPromise||(r.userReadyPromise=new Promise(e=>{r.userReadyResolver=e})),r.userReadyPromise)}static async showReferralDashboard(e){if(r.ensureInitialized(),!r.experience)throw new Error("GrowthRail: Experience not loaded");r.referralModal&&r.referralModal.hide(),r.referralModal?.show(e)}static createTriggerButton(e){if(typeof window>"u")return;if(!r.experience)throw new Error("GrowthRail: Experience not loaded");r.floatingButton&&r.floatingButton.unmount();let t={...r.experience?.trigger,...e},n={modal:{...r.experience.modal},trigger:t};r.floatingButton=new y(n),r.floatingButton.mount()}static destroyTriggerButton(){r.floatingButton&&(r.floatingButton.unmount(),r.floatingButton=null)}};a(r,"api"),a(r,"storage"),a(r,"options"),a(r,"currentUser",null),a(r,"initialized",!1),a(r,"referralModal",null),a(r,"floatingButton",null),a(r,"experience",null),a(r,"userReadyPromise",null),a(r,"userReadyResolver",null);var v=r;export{v as GrowthRail,b as ReferralModal};
|