@appstorys/react-web 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +711 -0
- package/dist/index.d.ts +711 -0
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +100 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
var si=Object.defineProperty;var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ai=(t,e)=>{for(var o in e)si(t,o,{get:e[o],enumerable:!0})};var tt,Ot=Et(()=>{"use strict";tt=class{static async getItem(e){try{return localStorage.getItem(e)}catch{return null}}static async setItem(e,o){try{localStorage.setItem(e,o)}catch{}}static async removeItem(e){try{localStorage.removeItem(e)}catch{}}}});import{create as li}from"zustand";function ht(){return Ie.getState().userId}async function it(){return tt.getItem("access_token")}function Ro(t){if(!t)return;let e=String(t||"").trim();if(e)return Ie.getState().variantMappings?.[e]}var Ie,z,K=Et(()=>{"use strict";Ot();Ie=li(t=>({userId:"",appId:"",accountId:"",currentScreen:"",campaigns:[],allCampaigns:[],campaignVersion:2,trackedEvents:[],trackedEventMetadata:{},isVisible:!0,isAnonymousUser:!1,variantMappings:{},personalizationData:{},screenCaptureEnabled:!1,baseUrl:void 0,trackingUrl:void 0,saveCampaigns:e=>t({campaigns:e}),saveAllCampaigns:e=>t({allCampaigns:e}),setCampaignVersion:e=>t({campaignVersion:e}),setUserId:e=>t({userId:e}),setAppId:e=>t({appId:e}),setAccountId:e=>t({accountId:e}),setCurrentScreen:e=>t({currentScreen:e}),setAttributes:e=>t({attributes:e}),setTrackedEvents:e=>t({trackedEvents:e}),setTrackedEventMetadata:e=>t({trackedEventMetadata:e}),setVisibility:e=>t({isVisible:e}),setIsAnonymousUser:e=>t({isAnonymousUser:e}),setVariantMappings:e=>t({variantMappings:e}),setPersonalizationData:e=>t({personalizationData:e}),setScreenCaptureEnabled:e=>t({screenCaptureEnabled:e}),setBaseUrl:e=>t({baseUrl:e}),setTrackingUrl:e=>t({trackingUrl:e})}));z=Ie});async function Lt(){try{return{browser:navigator.userAgent,language:navigator.language,platform:"web",screen_width_px:window.innerWidth,screen_height_px:window.innerHeight,screen_density:window.devicePixelRatio,orientation:window.innerWidth<window.innerHeight?"portrait":"landscape",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}catch(t){return console.error("Error fetching device info:",t),{}}}var de=Et(()=>{"use strict"});async function Rt(t,e,o){try{let i={account_id:t,app_id:e,user_id:o};if(await tt.getItem(zo))console.log("Device info already sent previously - skipping");else{let g=await Lt();i.attributes={...g},console.log("First time verification - including device info in attributes")}let a=z.getState().baseUrl||"https://users.appstorys.co",l=await fetch(`${a}/${t}/validate-account`,{method:"POST",body:JSON.stringify(i),headers:{Accept:"application/json","Content-Type":"application/json"}});if(console.log("Verify account body",i),console.log("Verifying account",l.status,l.statusText),l.ok){let g=await l.json();console.log("Account verified",g);let{access_token:p,refresh_token:x}=g;if(p&&x)return await tt.setItem("access_token",p),await tt.setItem("refresh_token",x),i.attributes&&(await tt.setItem(zo,"true"),console.log("Device info sent flag set")),!0}return!1}catch(i){return console.error("Error when verifying AppStorys account",i),!1}}var zo,ce=Et(()=>{"use strict";Ot();de();K();zo="device_info_sent"});async function Te(t,e){if(!e||e.length===0){console.info("AppStorys: identifyWidgetPositions called with empty positionList; skipping");return}let o=await it();if(!o){console.error("AppStorys: identifyWidgetPositions - access token not found");return}try{let i="https://backend.appstorys.co/api/v2/appinfo/identify-positions/";console.info("AppStorys: identifyWidgetPositions payload",{screen_name:t,position_list:e});let n=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`,Accept:"application/json"},body:JSON.stringify({screen_name:t,position_list:e})});n.ok?console.info("AppStorys: identifyWidgetPositions OK"):console.error("AppStorys: identifyWidgetPositions failed",n.status,await n.text())}catch(i){console.error("AppStorys: identifyWidgetPositions error",i)}}var qn=Et(()=>{"use strict";K()});function ze(t){return t&&(t.startsWith("widget_")?t:`widget_${t}`)}function Hn(){try{let t=z.getState().allCampaigns||[],e=[];return t.forEach(o=>{o&&o.position&&typeof o.position=="string"&&e.push(String(o.position));try{if(o&&o.campaign_type==="WID"&&o.details){let i=o.details;typeof i=="object"&&(i.id&&typeof i.id=="string"&&e.push(String(i.id)),i.variants&&typeof i.variants=="object"&&Object.values(i.variants).forEach(n=>{n&&n.id&&typeof n.id=="string"&&e.push(String(n.id))}))}}catch{}}),e.filter(o=>!!o).map(o=>ze(String(o))).filter(o=>!!o)}catch{return[]}}function Ur(t){try{let e=Hn();if(!e||e.length===0)return[];let o=[];return e.forEach(i=>{let n=i.replace(/^widget_/,""),r=[`[data-as-id="${n}"]`,`#${n}`,`.${n}`,`[data-widget="${n}"]`],a=null;for(let l of r)if(a=document.querySelector(l),a)break;if(a){let l=a.getBoundingClientRect(),g={x:Math.round(l.left),y:Math.round(l.top),width:Math.round(l.width),height:Math.round(l.height),screenWidth:window.innerWidth,screenHeight:window.innerHeight};Mt.addLayoutInfo(t,n,g),o.push(n)}}),console.info("AppStorys: mapServerPositionsToDOM mapped",o.length,"server positions to DOM elements",o),o}catch(e){return console.warn("AppStorys: mapServerPositionsToDOM error",e),[]}}function Hr(t){return se[t]||(se[t]=[]),se[t]}function Un(t,e,o,i){let n=new FormData,r=t.replace(/[^a-z0-9]/gi,"_"),a=`screenshot_${e}_${r}_${Date.now()}.png`,l=new File([i],a,{type:"image/png"});n.append("screenName",t),n.append("user_id",e),n.append("children",o),n.append("screenshot",l);try{console.groupCollapsed("AppStorys: FormData Payload Diagnostic"),console.info(" screenName:",t),console.info(" user_id:",e),console.info(" children:",JSON.parse(o)),console.info(" screenshot:",l.name,`(${l.size} bytes)`),console.groupEnd()}catch(g){console.warn("AppStorys: Could not run FormData diagnostics",g)}return n}var se,Mt,Vn=Et(()=>{"use strict";K();ce();qn();K();se={};Mt=class{static setup(e,o){let i=z.getState();i.setScreenCaptureEnabled(o),i.setCurrentScreen(e)}static addLayoutInfo(e,o,i){let n=Hr(e),r=n.findIndex(g=>g.id===o),a={...i,screenWidth:i.screenWidth||window.innerWidth,screenHeight:i.screenHeight||window.innerHeight},l={id:o,frame:a};r>=0?n[r]=l:n.push(l)}static collectElements(e){this.clearLayoutData(e);let o=document.querySelectorAll("[data-as-id]"),i=window.innerWidth,n=window.innerHeight,r=[];o.forEach(a=>{let l=a.getAttribute("data-as-id");if(l){r.push(l);let g=a.getBoundingClientRect();this.addLayoutInfo(e,l,{x:Math.round(g.left),y:Math.round(g.top),width:Math.round(g.width),height:Math.round(g.height),screenWidth:i,screenHeight:n})}}),console.info(`AppStorys: Identified ${o.length} elements:`,r)}static clearLayoutData(e){se[e]=[]}static getLayoutData(e){return se[e]||[]}static async takeScreenshot(e,o){try{if(!e)return console.error("AppStorys: Screen name is required"),!1;console.info("AppStorys: Starting takeScreenshot for",e),z.getState().setCurrentScreen(e),this.collectElements(e);try{let u=Ur(e);u&&u.length>0&&console.info("AppStorys: mapServerPositionsToDOM added",u.length,"elements")}catch{}await new Promise(u=>setTimeout(u,100));let n=window,r=null;if(typeof n.html2canvas!="function")try{await new Promise((u,v)=>{let f=document.createElement("script");f.src="https://html2canvas.hertzen.com/dist/html2canvas.min.js",f.onload=()=>u(),f.onerror=()=>v(new Error("Failed to load html2canvas")),document.head.appendChild(f)})}catch(u){console.warn("AppStorys: html2canvas load error",u)}if(typeof n.html2canvas=="function")try{let u=await n.html2canvas(document.documentElement,{useCORS:!0,allowTaint:!0,logging:!1,scale:window.devicePixelRatio||1});r=await new Promise(v=>u.toBlob(f=>v(f),"image/png"))}catch(u){console.warn("AppStorys: html2canvas capture failed (falling back to getDisplayMedia)",u),r=null}if(!r&&navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia)try{let u=await navigator.mediaDevices.getDisplayMedia({video:!0}),v=document.createElement("video");v.srcObject=u,await v.play();let f=document.createElement("canvas");f.width=v.videoWidth||window.innerWidth,f.height=v.videoHeight||window.innerHeight;let b=f.getContext("2d");b&&b.drawImage(v,0,0,f.width,f.height),r=await new Promise(h=>f.toBlob(y=>h(y),"image/png")),v.pause(),u.getTracks().forEach(h=>h.stop())}catch(u){console.warn("AppStorys: getDisplayMedia capture failed",u)}if(!r)return console.warn("AppStorys: Capture failed \u2014 no blob generated"),!1;let a=await it(),l=ht();if(!l)return console.warn("AppStorys: No userId"),!1;if(!a){let u=z.getState();u.accountId&&u.appId&&u.userId&&await Rt(u.accountId,u.appId,u.userId)&&(a=await it())}if(!a)return console.warn("AppStorys: No token available"),!1;let g="https://backend.appstorys.co/api/v1/appinfo/identify-elements/",p=JSON.stringify(this.getLayoutData(e)||[]),x=Un(e,l,p,r);console.info("AppStorys: Sending identify-elements with payload size:",p.length);let m=await fetch(g,{method:"POST",headers:{Authorization:`Bearer ${a}`,Accept:"application/json"},body:x});if(m.status===401){console.warn("AppStorys: 401 response \u2014 retrying once");let u=z.getState();if(u.accountId&&u.appId&&u.userId&&await Rt(u.accountId,u.appId,u.userId)){let f=await it();f&&(m=await fetch(g,{method:"POST",headers:{Authorization:`Bearer ${f}`,Accept:"application/json"},body:Un(e,l,p,r)}))}}if(!m.ok){let u=await m.text();return console.error("AppStorys: identify-elements failed",m.status,u),!1}console.info("AppStorys: identify-elements success \u2713");try{let u=o,v=[];!u||u.length===0?v=(this.getLayoutData(e)||[]).map(y=>ze(y.id)).filter(y=>!!y):v=u.map(h=>ze(h)).filter(h=>!!h);let f=Hn(),b=Array.from(new Set([...v,...f]));console.info("AppStorys: identifyWidgetPositions will send",b.length,"positions (collected + server)",b),await Te(e,b)}catch(u){console.warn("AppStorys: identifyWidgetPositions failed",u)}return!0}catch(i){return console.error("AppStorys: takeScreenshot error",i),!1}}};(function(){try{let e=window;e.AppStorysForceIdentifyPositions=async o=>{let i=z.getState(),n=o||i.currentScreen;if(!n){console.warn("AppStorys: AppStorysForceIdentifyPositions - no screen name available");return}let a=(Mt.getLayoutData(n)||[]).map(l=>ze(l.id)).filter(l=>!!l);console.info("AppStorys: AppStorysForceIdentifyPositions sending",a.length,"positions for",n,a);try{await Te(n,a),console.info("AppStorys: AppStorysForceIdentifyPositions completed")}catch(l){console.error("AppStorys: AppStorysForceIdentifyPositions error",l)}}}catch{}})()});var Qn={};ai(Qn,{mountScreenCaptureButton:()=>Yn});function Vr(){if(document.getElementById("appstorys-capture-styles"))return;let t=document.createElement("style");t.id="appstorys-capture-styles",t.innerHTML=`
|
|
2
|
+
@keyframes appstorys-spin {
|
|
3
|
+
0% { transform: rotate(0deg); }
|
|
4
|
+
100% { transform: rotate(360deg); }
|
|
5
|
+
}
|
|
6
|
+
.appstorys-spinner {
|
|
7
|
+
width: 20px;
|
|
8
|
+
height: 20px;
|
|
9
|
+
border: 3px solid rgba(255,255,255,0.3);
|
|
10
|
+
border-top: 3px solid #fff;
|
|
11
|
+
border-radius: 50%;
|
|
12
|
+
animation: appstorys-spin 0.8s linear infinite;
|
|
13
|
+
}
|
|
14
|
+
`,document.head.appendChild(t)}function Yr(){Vr();let t=document.createElement("button");return t.id="appstorys-screen-capture-btn",t.title="Capture screen",Object.assign(t.style,{position:"fixed",left:"16px",bottom:"16px",width:"100px",height:"56px",borderRadius:"28px",background:"#ff6a00",color:"#fff",border:"none",boxShadow:"0 6px 18px rgba(0,0,0,0.2)",zIndex:"2147483647",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"14px",fontWeight:"600",fontFamily:"sans-serif",transition:"all 0.2s ease"}),t.innerText="Capture",t}function Yn(){try{let t=z.getState(),o=!!window.__APPSTORYS_DEBUG_CAPTURE;if(console.info("AppStorys: mountScreenCaptureButton called, screenCaptureEnabled=",t.screenCaptureEnabled,"debugForce=",o),!t.screenCaptureEnabled&&!o||document.getElementById("appstorys-screen-capture-btn"))return null;let i=Yr();return i.addEventListener("click",async()=>{i.disabled=!0;let n=i.innerText;i.innerHTML='<div class="appstorys-spinner"></div>';let a=z.getState().currentScreen||(typeof window<"u"?window.location.pathname:"");try{await Mt.takeScreenshot(a)}catch(l){console.error("CaptureService error",l)}i.disabled=!1,i.innerText=n,i.animate([{transform:"scale(1.0)"},{transform:"scale(1.05)"},{transform:"scale(1.0)"}],{duration:300})}),document.body.appendChild(i),console.info("AppStorys: screen capture button mounted"),i}catch(t){return console.error("mountScreenCaptureButton error",t),null}}var Gn=Et(()=>{"use strict";K();Vn();try{window.AppStorysMountCapture=function(){try{return Yn()}catch(t){return console.error("AppStorysMountCapture failed",t),null}}}catch{}try{window.AppStorysDebugState=function(){try{let t=z.getState();return console.info("AppStorys store state:",t),t}catch(t){return console.error("AppStorysDebugState failed",t),null}}}catch{}try{window.AppStorysDebugToken=function(){try{let t=localStorage.getItem("access_token")||"",e=t.length,o=t?t.slice(0,20)+"..."+t.slice(-10):"(none)";if(console.info("Token length:",e,"masked:",o),t&&t.includes("."))try{let i=t.split(".");if(i.length===3){let n=JSON.parse(atob(i[1]));if(console.info("Token payload:",n),n.exp){let r=new Date(n.exp*1e3),a=new Date;console.info("Token expires:",r.toISOString(),"Expired:",a>r)}}}catch(i){console.warn("Could not decode JWT:",i)}return t?"Token present":"No token"}catch(t){return console.error("AppStorysDebugToken failed",t),null}}}catch{}});var wo=(n=>(n.uninitialized="uninitialized",n.initializing="initializing",n.initialized="initialized",n.error="error",n))(wo||{});K();import{useState as fe,useEffect as Po,useRef as xi}from"react";import*as jt from"lottie-react";K();import{useMemo as ci}from"react";K();var di=t=>z.getState().variantMappings[t];function Be(t){return!!(t.details&&typeof t.details=="object"&&"variants"in t.details)}function ut(t){if(!Be(t))return t;let e=di(t.id||"");if(!e)return t;let o=t.details?.variants;if(!o||typeof o!="object")return t;let i=o[e];if(!i)return t;let n=typeof t.details=="object"?Object.fromEntries(Object.entries(t.details).filter(([a])=>a!=="variants")):{};return{...t,details:{...n,...i},_variantId:e}}var le="__back_press_triggered__";function To(t){return(t||"").trim().toLowerCase()}function pi(t,e){let o=To(t),i=To(e);return!o||o===i}function ui(t,e,o){let i=Number(t),n=Number(o),r=!isNaN(i)&&!isNaN(n);switch(e){case"eq":return r?i===n:t===o;case"neq":return r?i!==n:t!==o;case"gt":return r?i>n:t>o;case"gte":return r?i>=n:t>=o;case"lt":return r?i<n:t<o;case"lte":return r?i<=n:t<=o;default:return!1}}function gi(t,e){let o=t.filter(i=>i.back_press==null);return o.length===0?!0:e.some(i=>o.every(n=>{let r=i[n.key];return r==null?!1:ui(String(r),n.operator,n.value)}))}function fi(t,e,o){let i=t,n=i.trigger_event??i.trigger,r=t.id;return!n}function Ae(){let{campaigns:t,trackedEvents:e,trackedEventMetadata:o,currentScreen:i}=z.getState();return t.some(n=>{if(n.screen&&n.screen!==i)return!1;let r=n.trigger_event;if(!r||typeof r=="string")return!1;let{event:a,event_config:l}=r;if(!(l??[]).some(x=>x.back_press===!0)||e.includes(le)||!e.includes(a))return!1;let g=(l??[]).filter(x=>x.back_press==null);if(g.length===0)return!0;let p=o[a]||[];return gi(g,p)})}function lt(t,e){let o=z(g=>g.currentScreen),i=z(g=>g.campaigns),n=z(g=>g.allCampaigns),r=z(g=>g.trackedEvents),a=z(g=>g.trackedEventMetadata),l=z(g=>g.variantMappings);return ci(()=>{let g=m=>m.find(u=>pi(u.screen,o)&&u.campaign_type===t&&(e?.position?u.position===e.position:!0)&&fi(u,r,a)),x=(i&&i.length>0?g(i):void 0)??g(n||[]);if(x)return ut(x)},[i,n,r,a,l,t,e,o])}K();de();Ot();K();ce();var Fo="appstorys_offline_queue";async function Io(){let t=await tt.getItem(Fo);return t?JSON.parse(t):[]}async function Bo(t){await tt.setItem(Fo,JSON.stringify(t))}function mi(t){return Math.min(3e4*Math.pow(2,t),12e4)}function yi(t){let o=t.retryCount||0,i=t.lastAttempt||0,n=mi(o);return o<3&&Date.now()-i>=n}async function hi(){let t=z.getState();return!t.accountId||!t.appId?!1:await Rt(t.accountId,t.appId,t.userId)}async function Ao(t,e){if(await hi()){let i=await tt.getItem("access_token");i&&(t.headers={...t.headers,Authorization:`Bearer ${i}`}),t.authRetried=!0,t.lastAttempt=Date.now(),e(t)}}async function ue(t,e){let o=(t.retryCount||0)+1;o<=3&&(t.retryCount=o,t.lastAttempt=Date.now(),e(t))}async function pe(t){let e=await Io();e.push(t),await Bo(e)}async function bi(){let t=await Io();if(t.length===0)return;let e=[];for(let o of t){if(!yi(o)){e.push(o);continue}try{let i=await fetch(o.url,{method:o.method,headers:o.headers,body:JSON.stringify(o.body)});if(i.ok)continue;i.status===401||i.status===403?o.authRetried||await Ao(o,n=>e.push(n)):i.status>=500&&await ue(o,n=>e.push(n))}catch{await ue(o,n=>e.push(n))}}await Bo(e)}async function ge(t){if(!navigator.onLine){await pe(t);return}await bi();try{let e=await fetch(t.url,{method:t.method,headers:t.headers,body:JSON.stringify(t.body)});return e.ok||(e.status===401||e.status===403?await Ao(t,pe):e.status>=500&&await ue(t,pe)),e}catch{await ue(t,pe);return}}async function V(t,e,o){try{if(!t)return;let i=await it(),n=z.getState(),r=["viewed","clicked","csat captured","survey captured","shared"];if(!r.includes(t)){let p=n.trackedEvents;if(!p.includes(t))n.setTrackedEvents([...p,t]);else{let x=p.filter(m=>m!==t);x.push(t),n.setTrackedEvents(x)}if(o&&Object.keys(o).length>0){let x=n.trackedEventMetadata||{},m=x[t]||[];n.setTrackedEventMetadata({...x,[t]:[...m,o]})}}let a={...o||{}};if(!r.includes(t)){let p=await Lt();a={...a,...p}}if(e&&String(e).trim()!==""){let p=Ro(e);p&&(a.variant_id=p)}let l={user_id:ht(),event:t,metadata:a};e&&(l.campaign_id=e);let g=n.trackingUrl||"https://tracking.appstorys.co";i&&await ge({url:`${g}/capture-event`,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:l})}catch(i){console.error("Error in trackEvent",i)}}K();function gt(t){if(!t)return!1;let e=z.getState(),o=e.allCampaigns||[],i=e.campaigns||[],n=String(t).trim(),r=o.find(g=>{if(!g)return!1;let p=String(g.id||"").trim(),x=g.details||{},m=String(x.campaign||x.id||"").trim();return!!(p&&p===n||m&&m===n||p&&n.includes(p)||m&&n.includes(m))});if(!r)return!1;let a={...r};delete a.trigger_event,delete a.trigger,a.display_trigger=!0;let l=i.findIndex(g=>String(g.id||"")===String(a.id||""));if(l===-1)e.saveCampaigns([a,...i]);else{let g=i[l];if(!!(g.trigger_event??g.trigger)){let x=[...i];x[l]=a,e.saveCampaigns(x)}}return!0}import{jsx as Pe,jsxs as Ci}from"react/jsx-runtime";var Eo=jt.default?.default??jt.default??jt.Lottie??jt,Si=()=>{let t=lt("BAN"),e=z(k=>k.isVisible),[o,i]=fe(!1),[n,r]=fe(null),[a,l]=fe(null),g=xi(null),[p,x]=fe(0);if(Po(()=>{t&&(i(!1),V("viewed",t.id),t.details.lottie_data&&fetch(t.details.lottie_data).then(k=>k.json()).then(k=>{r(k),k.w&&k.h&&l(k.h/k.w)}).catch(k=>console.error("Error loading Lottie:",k)))},[t]),Po(()=>{let k=()=>{g.current&&x(g.current.offsetWidth)};return k(),window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[t,o]),!t||o||!e)return null;let{details:m}=t,u=m.styling||{},v=m.height||"auto";a&&p&&(v=p*a);let f={position:"fixed",left:u.marginLeft?`${u.marginLeft}px`:"10px",right:u.marginRight?`${u.marginRight}px`:"10px",bottom:u.marginBottom?`${u.marginBottom}px`:"10px",backgroundColor:"transparent",borderRadius:`${u.topRightRadius||0}px ${u.topLeftRadius||0}px ${u.bottomRightRadius||0}px ${u.bottomLeftRadius||0}px`,overflow:"hidden",zIndex:9999,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",cursor:m.link?"pointer":"default"},b={width:"100%",height:typeof v=="number"?`${v}px`:v,display:"block",objectFit:"cover"},h=k=>{k.stopPropagation(),i(!0),V("banner_closed",t.id)};return Ci("div",{ref:g,style:f,onClick:()=>{if(m.link)if(V("clicked",t.id),m.link.startsWith("http"))window.open(m.link,"_blank");else{try{if(gt(m.link))return}catch(k){console.warn("revealCampaignFromLink error",k)}console.log("Internal link:",m.link)}},children:[n?(()=>{let k=Eo.default||Eo;return Pe(k,{animationData:n,loop:!0,autoplay:e,style:b})})():m.image?Pe("img",{src:m.image,alt:"Campaign Banner",style:b}):null,u.crossButton?.enabled&&Pe("button",{onClick:h,style:{position:"absolute",top:"5px",right:"5px",background:"rgba(0,0,0,0.3)",color:"white",border:"none",borderRadius:"50%",width:"24px",height:"24px",lineHeight:"22px",textAlign:"center",cursor:"pointer",padding:"0",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10},children:"\u2715"})]})};import{useEffect as Ee,useMemo as Lo,useRef as Do,useState as Gt}from"react";K();import{jsx as nt,jsxs as Dt}from"react/jsx-runtime";var Le=t=>(t||"").trim().toLowerCase(),xt=(t,e)=>{let o=Number(t);return Number.isFinite(o)?o:e};function vi({iconType:t,color:e}){let o=e||"#FFFFFF";return t==="close"?Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("line",{x1:"6",y1:"6",x2:"18",y2:"18",stroke:o,strokeWidth:"2.2",strokeLinecap:"round"}),nt("line",{x1:"18",y1:"6",x2:"6",y2:"18",stroke:o,strokeWidth:"2.2",strokeLinecap:"round"})]}):t==="expand"?Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("polyline",{points:"8,3 3,3 3,8",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),nt("line",{x1:"3",y1:"3",x2:"9",y2:"9",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),nt("polyline",{points:"16,21 21,21 21,16",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),nt("line",{x1:"15",y1:"15",x2:"21",y2:"21",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):t==="minimize"?Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("polyline",{points:"9,9 3,9 3,3",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),nt("line",{x1:"3",y1:"9",x2:"9",y2:"3",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),nt("polyline",{points:"15,15 21,15 21,21",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),nt("line",{x1:"15",y1:"21",x2:"21",y2:"15",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):t==="mute"?Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:o,strokeWidth:"2",strokeLinejoin:"round"}),nt("line",{x1:"16",y1:"8",x2:"21",y2:"16",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),nt("line",{x1:"21",y1:"8",x2:"16",y2:"16",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:o,strokeWidth:"2",strokeLinejoin:"round"}),nt("path",{d:"M16 10 Q18 12 16 14",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),nt("path",{d:"M18 8 Q22 12 18 16",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]})}function De({iconType:t,config:e,imageOverride:o,onClick:i}){let n=xt(e?.size,18),r=Math.max(24,n+10),a=e?.margin||{},l=o||e?.image,g=e?.color?.cross||"#FFFFFF",p=e?.color?.fill||"rgba(0,0,0,0.55)",x=e?.color?.stroke||"rgba(255,255,255,0.35)";return nt("button",{"data-control-button":"true",type:"button",onPointerDown:m=>{m.preventDefault(),m.stopPropagation()},onPointerUp:m=>{m.preventDefault(),m.stopPropagation()},onMouseDown:m=>{m.preventDefault(),m.stopPropagation()},onTouchStart:m=>{m.preventDefault(),m.stopPropagation()},onClick:m=>{m.preventDefault(),m.stopPropagation(),i()},title:e?.selectedStyle||t,style:{width:r,height:r,borderRadius:999,pointerEvents:"auto",zIndex:10030,position:"relative",border:`1px solid ${x}`,background:p,color:g,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,marginTop:xt(a.top,0),marginRight:xt(a.right,0),marginBottom:xt(a.bottom,0),marginLeft:xt(a.left,0)},children:l?nt("img",{src:l,alt:t,style:{width:n,height:n,objectFit:"contain"}}):nt(vi,{iconType:t,color:g})})}var ki=()=>{let t=lt("PIP"),e=z(q=>q.campaigns),o=z(q=>q.allCampaigns),i=z(q=>q.currentScreen),n=z(q=>q.isVisible),[r,a]=Gt(!1),[l,g]=Gt(!1),[p,x]=Gt(!0),[m,u]=Gt(!1),[v,f]=Gt(null),b=Do({x:0,y:0}),h=Do(null),y=Lo(()=>{if(t)return t;let q=Le(i),Q=pt=>pt.find(ft=>{let at=ft,wt=at.campaign_type==="PIP",j=!Le(at.screen)||Le(at.screen)===q,G=!!(at.trigger_event??at.trigger),X=at.display_trigger!==!1&&!G;return wt&&j&&X}),st=Q(e)??Q(o);return st?ut(st):void 0},[t,e,o,i]),k=Lo(()=>y,[y?.id,y?.details?.id]);if(Ee(()=>{if(!k)return;let q=k.details||{},Q=q?.styling?.soundToggle?.defaultSound||q?.styling?.appearance?.defaultSound||"yes";x(String(Q).toLowerCase()!=="yes"),a(!1),g(!1),f(null),V("viewed",k.id)},[k]),Ee(()=>{h.current&&(h.current.muted=p)},[p]),Ee(()=>{if(!m)return;let q=st=>{let pt=st.clientX-b.current.x,ft=st.clientY-b.current.y;f({x:Math.max(0,pt),y:Math.max(0,ft)})},Q=()=>{u(!1)};return window.addEventListener("mousemove",q),window.addEventListener("mouseup",Q),()=>{window.removeEventListener("mousemove",q),window.removeEventListener("mouseup",Q)}},[m]),!k||!k.details||r||!n)return null;let S=k.details,T=S.styling||{},I=T.appearance||{},c=xt(S.width??I.pipWidth,150),w=xt(S.height??I.pipHeight,300),s=Math.max(c,w),d=Math.min(c,w),E=T.cta?.container||{},F=T.cta?.text||{},A=!!(S.button_text&&S.button_text.trim().length>0),C=xt(T.cta?.container?.height,42),R=A?C+24:0,P=xt(T.pipBottomPadding,20),B=xt(T.pipTopPadding,0),_=l?S.large_video||S.small_video:S.small_video||S.large_video,$=(S.position||k.position||"right").toLowerCase(),D=!!T.isMovable,O=T.soundToggle?.enabled!==!1,W=T.crossButton?.enabled!==!1,Y=T.expandControls?.enabled!==!1&&String(T.expandablePip||"yes").toLowerCase()==="yes",dt=T.crossButton,M=l?T.expandControls?.minimise:T.expandControls?.maximise,N=p?T.soundToggle?.mute:T.soundToggle?.unmute,U={position:"fixed",zIndex:10020,width:l?"100vw":s,height:l?"100vh":d,borderRadius:0,overflow:"hidden",background:"#000",boxShadow:"0 16px 40px rgba(0,0,0,0.35)",cursor:m?"grabbing":D&&!l?"grab":"default",transition:m?"none":"width 180ms ease, height 180ms ease, transform 180ms ease"};v&&!l?(U.left=v.x,U.top=v.y):l?(U.left=0,U.top=0,U.right=0,U.bottom=0):($==="left"?U.left=24:U.right=24,B>0?U.top=B:U.bottom=P+20);let rt=q=>{if(!D||l||q.target.closest("[data-control-button='true']"))return;let st=q.currentTarget.getBoundingClientRect();b.current={x:q.clientX-st.left,y:q.clientY-st.top},f({x:st.left,y:st.top}),u(!0)},ct=()=>{if(!S.link)return;V("clicked",k.id);let q=String(S.link).trim();try{let Q=z.getState(),st=Q.allCampaigns||[],pt=Q.campaigns||[],ft=st.find(at=>at.id===q);if(console.log("[Pip] clicked link=",q,"allCount=",st.length,"visibleCount=",pt.length,"referenced=",!!ft),ft){let at={...ft};delete at.trigger_event,delete at.trigger,at.display_trigger=!0;let wt=pt.findIndex(j=>j.id===at.id);if(wt===-1)Q.saveCampaigns([at,...pt]);else{let j=pt[wt];if(!!(j.trigger_event??j.trigger)){let X=[...pt];X[wt]=at,Q.saveCampaigns(X)}}return}}catch{}window.open(S.link,"_blank")};return _?Dt("div",{style:U,onMouseDown:rt,children:[nt("video",{ref:h,src:_,autoPlay:!0,loop:!0,playsInline:!0,muted:p,style:{width:"100%",height:l&&A?`calc(100% - ${R}px)`:"100%",objectFit:l?"contain":"cover"},onClick:ct,onEnded:()=>{y&&V("analyze",y.id)}}),Dt("div",{style:{position:"absolute",top:8,right:8,display:"flex",gap:8,zIndex:2},children:[O&&nt(De,{iconType:p?"mute":"unmute",config:N,imageOverride:p?S.muteImage:S.unmuteImage,onClick:()=>x(q=>!q)}),Y&&nt(De,{iconType:l?"minimize":"expand",config:M,imageOverride:l?S.minimiseImage:S.maximiseImage,onClick:()=>{console.log("[Pip] expand button clicked - isExpanded before:",l),g(q=>{let Q=!q;return Q&&k?.id&&(V("viewed",k.id),V("analyze",k.id)),Q})}}),W&&nt(De,{iconType:"close",config:dt,imageOverride:S.crossButtonImage,onClick:()=>a(!0)})]}),l&&A&&nt("button",{"data-control-button":"true",onClick:ct,style:{position:"absolute",left:12,right:12,bottom:12,height:E.height||42,width:E.ctaFullWidth?"auto":E.ctaWidth||"auto",margin:E.ctaFullWidth?"0":"0 auto",background:E.backgroundColor||"#F7921C",color:F.color||"#fff",border:`${E.borderWidth||0}px solid ${E.borderColor||"transparent"}`,borderRadius:10,fontSize:F.fontSize||14,fontWeight:600,cursor:S.link?"pointer":"default"},children:S.button_text})]}):null};import wi,{useEffect as We,useRef as _e,useState as me}from"react";import{LottiePlayer as Ri}from"lottie-react";K();import{jsx as Nt}from"react/jsx-runtime";var yt=(t,e=0)=>{let o=Number(t);return Number.isFinite(o)?o:e},$e=t=>(t||"").trim().toLowerCase(),Ti="appstorysmediabucketdev.s3.ap-south-1.amazonaws.com",zi=t=>{try{if(typeof window>"u")return[t];let e=new URL(t);if(e.hostname!==Ti)return[t];let o=!!window.location.port,i=`/appstorys-media${e.pathname}${e.search}`;return o?[i,t]:[t]}catch{return[t]}},Fi=t=>{if(!t||typeof t!="object"||Array.isArray(t))return!1;let e=t;return Array.isArray(e.layers)||Array.isArray(e.assets)||typeof e.v=="string"},Me=class extends wi.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(){this.props.onError()}render(){return this.state.hasError?null:this.props.children}},Ii=()=>{let[t,e]=me(null),[o,i]=me([]),[n,r]=me(!1),[a,l]=me(!1),g=_e(null),p=_e(null),x=lt("FLT"),m=z(C=>C.campaigns),u=z(C=>C.allCampaigns),v=z(C=>C.currentScreen),f=z(C=>C.isVisible),b=_e(null),h=x??(()=>{let C=[...m,...u].find(R=>{let P=R;if(P.campaign_type!=="FLT")return!1;let B=!!(P.trigger_event??P.trigger);return P.display_trigger===!1||B?!1:!$e(P.screen)||$e(P.screen)===$e(v)});if(C)try{return ut(C)}catch{return C}})(),y=h?.id,k=z(C=>y?C.variantMappings[y]:void 0);if(We(()=>{if(!h?.id||!f||Be(h)&&!k)return;let R=`${h.id}:${k||""}`;b.current!==R&&(b.current=R,V("viewed",h.id))},[h?.id,k,f]),We(()=>{let C=h?.details?.lottie_data;if(e(null),i([]),r(!1),l(!1),!C)return;if(Fi(C)){e(C),l(!0);return}if(typeof C!="string"){r(!0);return}let R=zi(C);i(R),l(!0)},[h?.details?.lottie_data]),We(()=>{if(!h?.details?.lottie_data||!g.current)return;let C=Ri;if(!C||typeof C.loadAnimation!="function"){r(!0),l(!1);return}let R=!1,P=null,B=()=>{P&&typeof P.destroy=="function"&&P.destroy(),P=null,p.current=null},_=($,D)=>{if(R)return;if(D>=$.length){r(!0),l(!1),console.error("[Floater] lottie load failed",{lottieUrls:$});return}B();let O=C.loadAnimation({container:g.current,renderer:"svg",loop:!0,autoplay:!0,path:$[D]});P=O,p.current=O,O.addEventListener("DOMLoaded",()=>{R||l(!1)}),O.addEventListener("data_failed",()=>{R||_($,D+1)})};if(t){B();let $=C.loadAnimation({container:g.current,renderer:"svg",loop:!0,autoplay:!0,animationData:t});P=$,p.current=$,$.addEventListener("DOMLoaded",()=>{R||l(!1)}),$.addEventListener("data_failed",()=>{R||(r(!0),l(!1))})}else o.length>0&&_(o,0);return()=>{R=!0,B()}},[h?.details?.lottie_data,t,o]),!h||!h.details||!f)return null;let{details:S}=h,T=S.styling||{},c=(typeof S.position=="string"?S.position:typeof h.position=="string"?h.position:"right").toLowerCase()==="left"?"left":"right",w={position:"fixed",left:c==="left"?yt(T.marginLeft,12):void 0,right:c==="left"?void 0:yt(T.marginRight,12),top:yt(T.marginTop,0)>0?yt(T.marginTop,0):void 0,bottom:yt(T.marginTop,0)>0?void 0:yt(T.marginBottom,80),zIndex:10040,display:"flex"},s={width:yt(S.width,60),height:yt(S.height,60),background:"transparent",overflow:"hidden",borderBottomLeftRadius:yt(T.bottomLeftRadius,0),borderBottomRightRadius:yt(T.bottomRightRadius,0),borderTopLeftRadius:yt(T.topLeftRadius,0),borderTopRightRadius:yt(T.topRightRadius,0),display:"flex",alignItems:"center",justifyContent:"center",cursor:S.link?"pointer":"default",boxShadow:"0 8px 18px rgba(0,0,0,0.2)"},d=async()=>{if(!S.link)return;await V("clicked",h.id);let C=String(S.link).trim();try{let R=z.getState(),P=R.allCampaigns||[],B=R.campaigns||[],_=P.find($=>{if(!$)return!1;let D=String($.id||"").trim(),O=$.details||{},W=String(O.campaign||O.id||"").trim();return!!(D&&D===C||W&&W===C||D&&C.includes(D)||W&&C.includes(W))});if(console.log("[Floater] clicked link=",C,"allCampaignsCount=",P.length,"visibleCount=",B.length),console.log("[Floater] all ids=",P.map($=>$.id).slice(0,50)),console.log("[Floater] referenced found=",!!_,_&&(_.id||_.details?.campaign||_.details?.id)),_){let $={..._};delete $.trigger_event,delete $.trigger,$.display_trigger=!0;let D=B.findIndex(O=>O.id===$.id);if(D===-1)console.log("[Floater] revealing campaign (prepended)",$.id),R.saveCampaigns([$,...B]);else{let O=B[D];if(!!(O.trigger_event??O.trigger)){let Y=[...B];Y[D]=$,console.log("[Floater] replacing existing triggered campaign with revealed one",$.id),R.saveCampaigns(Y)}else console.log("[Floater] campaign already visible and not trigger-driven",$.id)}return}}catch(R){console.warn("[Floater] error while resolving referenced campaign",R)}try{window.open(S.link,"_blank")}catch{}},E=!!(S.lottie_data&&!n),F=!!S.image,A=!!(S.lottie_data&&a&&!t&&!n);return!E&&!F&&!A?null:Nt("div",{style:w,children:Nt("div",{style:s,onClick:()=>{d()},children:E?Nt(Me,{onError:()=>r(!0),children:Nt("div",{ref:g,style:{width:"100%",height:"100%",display:"block"}})},String(S.lottie_data)):A?Nt("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.08)",color:"#333",fontSize:10,fontWeight:600},children:"..."}):Nt("img",{src:S.image,alt:"floater",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})})})},Bi=Ii;K();function Wo(t){return(t||"").trim().toLowerCase()}function Oe(t,e){let o=Wo(t.screen),i=Wo(e);return!o||o===i}async function je(t){try{let e=z.getState(),o=await it(),i=e.accountId;if(!o||!i)return;e.setCurrentScreen(t),e.setTrackedEvents([]);let n=e.baseUrl||"https://users.appstorys.co",r=await fetch(`${n}/v2/${i}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify({user_id:ht(),screenName:t})});if(!r.ok)return;let a=await r.json();if(typeof a.screen_capture_enabled<"u"&&e.setScreenCaptureEnabled(!!a.screen_capture_enabled),a.variants&&a.variants.length>0){let y={};a.variants.forEach(k=>{y[k.id]=k.v_id}),e.setVariantMappings(y)}a.personalization_data&&e.setPersonalizationData(a.personalization_data);let l=e.allCampaigns||[],g=a.eligibleCampaignList||[],p=l.filter(y=>g.includes(y.id)&&Oe(y,t)),x=p.map(y=>y.id),m=g.filter(y=>!x.includes(y)),u=[];if(m.length>0){let y=await fetch(`${n}/load-campaign-data`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(m)});y.ok&&(u=(await y.json()).filter(S=>Oe(S,t)))}let v=[...p,...u],f=l.filter(y=>{let k=!!(y.trigger_event??y.trigger);return Oe(y,t)&&y.display_trigger===!0&&!k}),b=[...v],h=new Set(b.map(y=>y.id));for(let y of f)h.has(y.id)||(b.push(y),h.add(y.id));e.saveCampaigns(b)}catch(e){console.error("Error when tracking screen:",t,e)}}ce();K();de();async function Ne(t){try{let e=await it(),o=ht(),i=z.getState();if(!e||!o){console.warn("AppStorys: Missing accessToken or userId. Ensure SDK is initialized before setting user properties.");return}let n={...t||{}},r=await Lt();n={...n,...r};let a={user_id:o,attributes:n},l=i.baseUrl||"https://users.appstorys.co";await ge({url:`${l}/update-user-atr`,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:a})}catch(e){console.error("AppStorys: Error in setUserProperties:",e)}}K();function ye(t){if(!t||t.trim()==="")return t;let e=z.getState().personalizationData;if(!e||Object.keys(e).length===0)return Ai(t);let o=/\{\{([^|}\s]+)\s*\|\s*([^}]+)\}\}/g;return t.replace(o,(i,n,r)=>{let a=n.trim(),l=r.trim();return e[a]??l})}function Ai(t){let e=/\{\{[^|}\s]+\s*\|\s*([^}]+)\}\}/g;return t.replace(e,(o,i)=>i.trim())}Ot();K();K();var qe="appstorys_campaigns_cache",_o="appstorys_campaigns_etag",Ue="appstorys_campaigns_version";async function He(t,e){try{let o=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),i=o?`/appstorys-campaigns/clients/${t}/campaigns.json`:`https://dev-cdn-campaign-appstorys.s3.ap-south-1.amazonaws.com/clients/${t}/campaigns.json`,n=await tt.getItem(qe),r=await tt.getItem(_o),a=await tt.getItem(Ue),l={Accept:"application/json"};!o&&r&&(l["If-None-Match"]=r);let g=await fetch(i,{method:"GET",headers:l,...o?{cache:"no-store"}:{}});if(g.status===304)return{campaigns:n?JSON.parse(n):[],version:a?parseInt(a):1};let p=g.headers.get("ETag"),x=await g.json(),m=2,u=x,v=e;if(!v)try{let f=await it(),b=ht(),y=await fetch(`${o?"/appstorys-users":"https://users.appstorys.co"}/v2/${t}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",...f?{Authorization:`Bearer ${f}`}:{}},body:JSON.stringify({user_id:b,screenName:typeof window<"u"&&window.location&&window.location.pathname?window.location.pathname:"",silentUpdate:!0})});if(y.ok){let k=await y.json();console.info("AppStorys: fetchAllCampaigns track-user-res returned",k);let S=k?.screenName||k?.screen||k?.currentScreen||k?.screen_name||k?.current_screen;S&&(v=S);try{let T=z.getState();typeof k.screen_capture_enabled<"u"&&T.setScreenCaptureEnabled(!!k.screen_capture_enabled)}catch{}}}catch(f){console.warn("Could not fetch screen name from track-user-res:",f)}if(x.length>0&&x[0].version!==void 0&&(m=x[0].version,u=x.slice(1)),!u||u.length===0)try{let f=await it(),b=ht(),y=await fetch(`${o?"/appstorys-users":"https://users.appstorys.co"}/v2/${t}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",...f?{Authorization:`Bearer ${f}`}:{}},body:JSON.stringify({user_id:b,screenName:typeof window<"u"&&window.location&&window.location.pathname?window.location.pathname:"",silentUpdate:!0})});if(y.ok){let k=await y.json(),S=k?.user_id||k?.id||k?.userId||b;try{let T=z.getState();typeof k.screen_capture_enabled<"u"&&T.setScreenCaptureEnabled(!!k.screen_capture_enabled)}catch{}if(S){let I=await fetch(o?"/appstorys-users/load-campaign-data":"https://users.appstorys.com/load-campaign-data",{method:"POST",headers:{"Content-Type":"application/json",...f?{Authorization:`Bearer ${f}`}:{}},body:JSON.stringify({user_id:S})});if(I.ok){let c=await I.json();console.log(`Fetched ${c.length} missing campaigns from fallback`),console.log("Fallback campaigns:",JSON.stringify(c,null,2)),c&&c.length>0&&(u=c)}else console.error("Failed to fetch missing campaigns:",await I.text())}}}catch(f){console.error("Error fetching missing campaigns via fallback:",f)}if(v&&u&&u.length>0){let f=h=>(h||"").trim().toLowerCase(),b=f(v);u=u.filter(h=>!f(h.screen)||f(h.screen)===b)}return await tt.setItem(qe,JSON.stringify(u)),await tt.setItem(Ue,m.toString()),p&&await tt.setItem(_o,p),{campaigns:u,version:m}}catch(o){console.error("Error fetching campaigns:",o);let i=await tt.getItem(qe),n=await tt.getItem(Ue);return{campaigns:i?JSON.parse(i):[],version:n?parseInt(n):1}}}K();K();K();async function Ve(t,e){try{let o=await it(),i=z.getState();if(!o)return console.error("AppStorys: Access token not found for reconciliation"),!1;let n={anonymous_user_id:t,identified_user_id:e},r=i.baseUrl||"https://users.appstorys.co",a=await fetch(`${r}/reconcile-anonymous-user`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(n)});if(a.ok)return!0;{let l=await a.text();return console.error("AppStorys: Failed to reconcile anonymous user:",a.status,l),!1}}catch(o){return console.error("AppStorys: Error in reconcileAnonymousUser:",o),!1}}K();var Ye=class{isInitialized=!1;setup(){this.isInitialized||typeof window>"u"||(document.addEventListener("mouseleave",this.handleMouseLeave),window.addEventListener("popstate",this.handlePopState),window.history.state!=="appstorys_navigation"&&window.history.pushState("appstorys_navigation",""),this.isInitialized=!0)}destroy(){!this.isInitialized||typeof window>"u"||(document.removeEventListener("mouseleave",this.handleMouseLeave),window.removeEventListener("popstate",this.handlePopState),this.isInitialized=!1)}handleMouseLeave=e=>{e.clientY<=0&&Ae()&&this.triggerCampaign()};handlePopState=()=>{Ae()&&(window.history.pushState("appstorys_navigation",""),this.triggerCampaign())};triggerCampaign(){let e=z.getState(),{trackedEvents:o}=e;o.includes(le)||(console.log("AppStorys: Exit Intent triggered. Displaying campaign."),e.setTrackedEvents([...o,le]))}},$o=new Ye;K();var Qe=class{isInitialized=!1;setup(){this.isInitialized||typeof document>"u"||(document.addEventListener("visibilitychange",this.handleVisibilityChange),this.updateVisibility(document.visibilityState==="visible"),this.isInitialized=!0)}destroy(){!this.isInitialized||typeof document>"u"||(document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.isInitialized=!1)}handleVisibilityChange=()=>{this.updateVisibility(document.visibilityState==="visible")};updateVisibility(e){let o=z.getState();o.isVisible!==e&&(console.log(`AppStorys: SDK visibility changed to ${e?"visible":"hidden"}`),o.setVisibility(e))}},Ge=new Qe;Ot();var he="anonymous_user_id";async function Mo(){let t=Date.now(),e=navigator.userAgent.split(" ")[0].replace(/[^a-zA-Z0-9]/g,"_");return`${t}_${e}`}async function Oo(){try{let t=await tt.getItem(he);if(t)return t;let e=await Mo();return await tt.setItem(he,e),e}catch(t){return console.error("Error managing anonymous user ID:",t),await Mo()}}async function jo(){try{await tt.removeItem(he)}catch(t){console.error("Error clearing anonymous user ID:",t)}}async function Je(){try{return await tt.getItem(he)}catch(t){return console.error("Error getting stored anonymous user ID:",t),null}}function Pi(){if(document.getElementById("appstorys-widget-debug-styles"))return;let t=document.createElement("style");t.id="appstorys-widget-debug-styles",t.innerHTML=`
|
|
15
|
+
.appstorys-widget-debug-pill {
|
|
16
|
+
position: absolute;
|
|
17
|
+
top: 8px;
|
|
18
|
+
left: 8px;
|
|
19
|
+
background: #ff7a18;
|
|
20
|
+
color: white;
|
|
21
|
+
padding: 6px 10px;
|
|
22
|
+
border-radius: 14px;
|
|
23
|
+
font-weight: 700;
|
|
24
|
+
font-size: 12px;
|
|
25
|
+
z-index: 2147483647;
|
|
26
|
+
box-shadow: 0 6px 18px rgba(0,0,0,0.12);
|
|
27
|
+
pointer-events: none;
|
|
28
|
+
}
|
|
29
|
+
.appstorys-widget-debug-overlay {
|
|
30
|
+
outline: 3px dashed rgba(255,122,24,0.85);
|
|
31
|
+
outline-offset: 6px;
|
|
32
|
+
}
|
|
33
|
+
`,document.head.appendChild(t)}function No(t){let e=document.createElement("div");return e.className="appstorys-widget-debug-pill",e.textContent=t,e}function Ei(t){let e=t,o=getComputedStyle(e);(o.position==="static"||!o.position)&&(e.style.position="relative")}window.AppStorysShowWidgetElements=function(){try{Pi();let e=Array.from(document.querySelectorAll("[data-as-id], [data-widget], [data-widget-id]"));if(e.length||["#hero_section",".hero_section","#header_container",".header_container"].forEach(i=>{let n=document.querySelector(i);n&&e.push(n)}),!e.length){let o=No("Widget");o.style.position="fixed",o.style.top="12px",o.style.left="12px",o.style.pointerEvents="auto",document.body.appendChild(o);return}e.forEach((o,i)=>{let n=o;Ei(n),n.classList.add("appstorys-widget-debug-overlay");let r=n.querySelector(".appstorys-widget-debug-pill");r&&r.remove();let a=No("Widget "+(i+1));n.appendChild(a)})}catch(e){console.error("AppStorysShowWidgetElements error",e)}};K();import{useState as An,useEffect as Pn}from"react";import{useEffect as Li,useState as qo}from"react";import*as qt from"lottie-react";import{jsx as Ho}from"react/jsx-runtime";var Uo=qt.default?.default??qt.default??qt.Lottie??qt,bt=({src:t,alt:e,style:o,size:i})=>{let[n,r]=qo(null),[a,l]=qo(!1);Li(()=>{t&&t.toLowerCase().endsWith(".json")?fetch(t).then(p=>{if(!p.ok)throw new Error("Failed to fetch Lottie");return p.json()}).then(p=>{r(p),l(!1)}).catch(p=>{console.error("AppStorys: Error loading Lottie thumbnail:",p),l(!0)}):(r(null),l(!1))},[t]);let g={width:i?`${i}px`:o?.width||"100%",height:i?`${i}px`:o?.height||"100%",objectFit:"cover",display:"block",...o};if(n&&!a){let p=Uo.default||Uo;return Ho(p,{animationData:n,loop:!0,autoplay:!0,style:g})}return Ho("img",{src:t,alt:e||"story thumbnail",style:g,onError:()=>l(!0)})};import{jsx as Ke,jsxs as Di}from"react/jsx-runtime";var Vo=({story:t,isViewed:e,onClick:o})=>{let i=t.styling||{},n=i.size||80,r=i.ringWidth||3,a=e?"#E5E7EB":t.ringColor||"#FF0000",l=t.nameColor||"#333333",g=i.cornerRadius,p=g?`${g.topLeft||0}px ${g.topRight||0}px ${g.bottomRight||0}px ${g.bottomLeft||0}px`:"50%",x=g?`${Math.max(0,(g.topLeft||0)-3)}px ${Math.max(0,(g.topRight||0)-3)}px ${Math.max(0,(g.bottomRight||0)-3)}px ${Math.max(0,(g.bottomLeft||0)-3)}px`:"50%";return Di("div",{onClick:o,style:{display:"flex",flexDirection:"column",alignItems:"center",cursor:"pointer",flexShrink:0},children:[Ke("div",{style:{width:`${n}px`,height:`${n}px`,borderRadius:p,border:`${r}px solid ${a}`,padding:"3px",boxSizing:"border-box",transition:"transform 0.1s ease",overflow:"hidden",backgroundColor:"#f5f5f5"},children:Ke(bt,{src:t.thumbnail,alt:t.name,style:{borderRadius:x}})}),Ke("span",{style:{marginTop:"6px",fontSize:`${i.name?.size||12}px`,fontFamily:i.name?.fontFamily||"sans-serif",fontWeight:i.name?.font==="Bold"?"bold":"normal",color:l,maxWidth:`${n+10}px`,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name})]})};import{jsx as Yo}from"react/jsx-runtime";var Qo=({stories:t,viewedStories:e,onStoryClick:o})=>Yo("div",{style:{display:"flex",gap:"18px",padding:"16px 20px",overflowX:"auto",WebkitOverflowScrolling:"touch",justifyContent:"flex-start"},children:t.sort((i,n)=>i.order-n.order).map((i,n)=>Yo(Vo,{story:i,isViewed:e.includes(i.id),onClick:()=>o(n)},i.id))});import{useState as Bt,useEffect as ee,useRef as ao}from"react";K();import{jsx as Go,jsxs as Xe}from"react/jsx-runtime";var Jo=({data:t,onInteraction:e,isEditing:o=!1})=>{let i=t.layout?.type==="horizontal",n={headerTextColor:"#000000",optionBgColor:"#1A1A1A",optionTextColor:"#FFFFFF",backgroundColor:"#FFFFFF",borderRadius:24,padding:20},r=t.styling||{},a={backgroundColor:r.backgroundColor||n.backgroundColor,borderRadius:`${r.borderRadius??n.borderRadius}px`,overflow:"hidden",boxShadow:r.shadow||"0 12px 24px rgba(0,0,0,0.1)",boxSizing:"border-box",width:"100%",opacity:r.opacity??1,padding:`${r.padding??n.padding}px`,display:"flex",flexDirection:"column",alignItems:"center",gap:"16px"},l={color:r.headerTextColor||n.headerTextColor,textAlign:"center",fontWeight:"800",fontSize:`${r.fontSize?r.fontSize+4:20}px`,lineHeight:"1.2",margin:"0",width:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'},g={display:"flex",flexDirection:i?"row":"column",gap:"4px",width:"100%",backgroundColor:"#1A1A1A",borderRadius:"12px",overflow:"hidden",padding:"2px"},p={backgroundColor:r.optionBgColor||"transparent",color:r.optionTextColor||n.optionTextColor,padding:i?"14px 10px":"16px 20px",fontSize:`${r.fontSize?r.fontSize+1:16}px`,fontWeight:"700",cursor:"pointer",border:"none",width:"100%",textAlign:"center",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",transition:"background 0.2s",flex:1,borderRight:i?"1px solid rgba(255,255,255,0.1)":"none",borderBottom:i?"none":"1px solid rgba(255,255,255,0.1)"},x=u=>{o||e?.({type:"poll",pollId:t.id,optionId:u,stickerId:t.id})},m=Array.isArray(t.options)?t.options:[];return Xe("div",{style:a,children:[Go("h3",{style:l,children:t.question||"Ask A Question..."}),Go("div",{style:g,children:m.map((u,v)=>Xe("button",{style:{...p,borderRight:i&&v===m.length-1?"none":p.borderRight,borderBottom:!i&&v===m.length-1?"none":p.borderBottom},onClick:()=>x(u.id),onMouseOver:f=>{o||(f.currentTarget.style.backgroundColor="rgba(255,255,255,0.1)")},onMouseOut:f=>{o||(f.currentTarget.style.backgroundColor=r.optionBgColor||"transparent")},children:[u.text,u.percentage!==void 0&&Xe("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"8px"},children:[u.percentage,"%"]})]},u.id))})]})};import{useState as Wi}from"react";import{jsx as be,jsxs as Ko}from"react/jsx-runtime";var Xo=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=Wi(null),r={backgroundColor:"#FFFFFF",borderRadius:20,padding:16,questionTextColor:"#FFFFFF",questionBgColor:"#000000",optionBgColor:"#FFFFFF",optionTextColor:"#2B2B2B",borderColor:"#E5E7EB",activeColor:"#10b981",incorrectColor:"#ef4444",labelBgColor:"#FFFFFF",labelTextColor:"#111111",labelBorderColor:"#111111"},a=t.styling||{},l=a.padding??r.padding,g=a.fontSize?a.fontSize+6:22,p=a.optionFontSize||17,x=a.optionBorderRadius||14,m=a.borderColor||r.borderColor,u=Math.min(Math.max(Math.round(p*2.1),18),32),v={backgroundColor:a.backgroundColor||r.backgroundColor,borderRadius:`${a.borderRadius??r.borderRadius}px`,padding:`${l}px`,paddingTop:0,boxShadow:a.shadow||"0 10px 30px rgba(0,0,0,0.12)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",overflow:"hidden",opacity:a.opacity??1},f={color:a.questionTextColor||r.questionTextColor,backgroundColor:a.questionBgColor||r.questionBgColor,fontWeight:"900",fontSize:`${g}px`,lineHeight:1.25,margin:`0 -${l}px 16px -${l}px`,textAlign:"center",padding:`24px ${l}px`,borderTopLeftRadius:`${a.borderRadius??r.borderRadius}px`,borderTopRightRadius:`${a.borderRadius??r.borderRadius}px`,letterSpacing:"-0.01em"},b={backgroundColor:a.optionBgColor||r.optionBgColor,color:a.optionTextColor||r.optionTextColor,padding:`${a.optionPadding||Math.max(l*.7,10)}px ${Math.max(l*.8,12)}px`,borderRadius:`${x}px`,border:`1px solid ${m}`,display:"flex",alignItems:"center",gap:`${Math.max(Math.round(u*.45),8)}px`,cursor:i?"default":"pointer",width:"100%",textAlign:"left",boxSizing:"border-box",transition:"all 0.2s ease",boxShadow:"0 1px 2px rgba(15,23,42,0.03)"},h={width:`${u}px`,height:`${u}px`,minWidth:`${u}px`,borderRadius:"50%",backgroundColor:a.labelBgColor||r.labelBgColor,color:a.labelTextColor||r.labelTextColor,border:`${Math.max(Math.round(u*.08),1)}px solid ${a.labelBorderColor||r.labelBorderColor}`,display:"flex",alignItems:"center",justifyContent:"center",fontWeight:"700",fontSize:`${Math.max(Math.round(u*.46),10)}px`},y={backgroundColor:a.backgroundColor||r.backgroundColor,borderRadius:`0 0 ${a.borderRadius??r.borderRadius}px ${a.borderRadius??r.borderRadius}px`,display:"flex",flexDirection:"column",gap:`${Math.max(l*.55,8)}px`},k=I=>{o||i||(n(I),e?.({type:"quiz",quizId:t.id,optionId:I,stickerId:t.id}))},S=["A","B","C","D","E","F"],T=Array.isArray(t.options)?t.options:[];return T.length===0&&!o&&console.warn("AppStorys: QuizSticker has no options!",t.id),Ko("div",{style:{...v,background:a.backgroundColor||r.backgroundColor},children:[t.question&&be("h3",{style:f,children:t.question}),be("div",{style:{...y,background:"transparent"},children:T.map((I,c)=>{let w=I.label||S[c]||"\u2022",s=I.id===i,d=I.isCorrect===!0,E={...b},F={...h};return i&&(d?(E.backgroundColor=a.activeColor||r.activeColor,E.borderColor=a.activeColor||r.activeColor,E.color="#FFFFFF"):s&&(E.backgroundColor=a.incorrectColor||r.incorrectColor,E.borderColor=a.incorrectColor||r.incorrectColor,E.color="#FFFFFF")),Ko("button",{style:E,onClick:()=>k(I.id),disabled:!!i,children:[be("div",{style:h,className:"letter-circle",children:w}),be("span",{style:{fontWeight:"600",fontSize:`${p}px`},children:I.text})]},I.id)})})]})};import{useState as _i,useEffect as $i}from"react";import{jsx as Tt,jsxs as Zo}from"react/jsx-runtime";var tn=({data:t})=>{let[e,o]=_i({days:"00",hours:"00",minutes:"00",seconds:"00"});$i(()=>{if(!t.targetDate)return;let w=()=>{let d=+new Date(t.targetDate)-+new Date;if(d>0){let E=Math.floor(d/864e5),F=Math.floor(d/(1e3*60*60)%24),A=Math.floor(d/1e3/60%60),C=Math.floor(d/1e3%60);o({days:E.toString().padStart(2,"0"),hours:F.toString().padStart(2,"0"),minutes:A.toString().padStart(2,"0"),seconds:C.toString().padStart(2,"0")})}else o({days:"00",hours:"00",minutes:"00",seconds:"00"})},s=setInterval(w,1e3);return w(),()=>clearInterval(s)},[t.targetDate]);let i=t.styling||{},n=t.display||{showDays:!0,showHours:!0,showMinutes:!0,showSeconds:!0},r=Number(i.digitSize||18),a=!isNaN(r)&&r>0?r:18,l=typeof i.labelFontSize<"u"?Number(i.labelFontSize):Math.max(10,Math.round(a*.55)),g=Math.max(30,Math.round(a*1.8)),p=Math.max(24,Math.round(a*1.3)),x=Math.max(6,Math.round(a*.35)),m=Math.max(6,Math.round(a*.25)),u={backgroundColor:i.backgroundColor||"#FFFFFF",borderRadius:`${i.borderRadius!==void 0?i.borderRadius:16}px`,padding:`${i.padding!==void 0?i.padding:16}px`,boxShadow:i.shadow||"0 10px 30px rgba(0,0,0,0.08)",width:"100%",boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",border:i.borderColor?`1px solid ${i.borderColor}`:"none",overflow:"hidden",opacity:i.opacity??1},v={color:i.titleColor||"#000000",fontWeight:"700",fontSize:`${i.fontSize?i.fontSize:14}px`,width:"100%",textAlign:"center",marginBottom:"4px"},f={display:"flex",gap:`${m}px`,width:"100%",justifyContent:"center",alignItems:"center",flexWrap:"nowrap"},b={display:"flex",flexDirection:"column",alignItems:"center",gap:"2px"},h={display:"flex",gap:"2px"},y={backgroundColor:i.digitBackground||"#F1F3F5",borderRadius:`${x}px`,minWidth:`${p}px`,height:`${g}px`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:`${a}px`,fontWeight:"bold",color:i.digitColor||"#1A202C",padding:"0 4px"},k={fontSize:`${Math.max(9,l)}px`,color:i.labelColor||"#A0AEC0",fontWeight:"600",textTransform:"lowercase"},S={fontSize:`${Math.max(14,Math.round(a*.9))}px`,fontWeight:"700",color:i.labelColor||"#A0AEC0",display:"flex",alignItems:"center",lineHeight:1},T=(w,s)=>Zo("div",{style:b,children:[Tt("div",{style:h,children:w.split("").map((d,E)=>Tt("div",{style:y,children:d},E))}),Tt("span",{style:k,children:s})]}),I=[],c=0;return n.showDays!==!1&&(I.push(T(e.days,"days")),c++),n.showHours!==!1&&(c>0&&I.push(Tt("div",{style:S,children:":"},"sep-h")),I.push(T(e.hours,"hours")),c++),n.showMinutes!==!1&&(c>0&&I.push(Tt("div",{style:S,children:":"},"sep-m")),I.push(T(e.minutes,"min")),c++),n.showSeconds!==!1&&(c>0&&I.push(Tt("div",{style:S,children:":"},"sep-s")),I.push(T(e.seconds,"sec")),c++),Zo("div",{style:u,children:[t.title&&Tt("div",{style:v,children:t.title}),Tt("div",{style:f,children:I})]})};import{useState as Mi}from"react";import{jsx as Ut,jsxs as xe}from"react/jsx-runtime";var en=({data:t,onInteraction:e})=>{let[o,i]=Mi(!1),n=()=>{t.code&&(navigator.clipboard.writeText(t.code).catch(()=>{}),i(!0),e?.({type:"promo_code",value:"copied",stickerId:t.id,code:t.code}),setTimeout(()=>i(!1),2e3))},r=t.styling||{},a={backgroundColor:r.backgroundColor||"#FFFFFF",padding:"12px 18px",borderRadius:"12px",display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",height:"60px",boxSizing:"border-box",position:"relative",filter:"drop-shadow(0 8px 16px rgba(0,0,0,0.1))",cursor:"pointer",clipPath:"polygon(0% 0%, 0% 40%, 4% 50%, 0% 60%, 0% 100%, 100% 100%, 100% 60%, 96% 50%, 100% 40%, 100% 0%)",backgroundImage:`
|
|
34
|
+
radial-gradient(circle at 0px 30px, transparent 8px, white 8.5px),
|
|
35
|
+
radial-gradient(circle at 100% 30px, transparent 8px, white 8.5px)
|
|
36
|
+
`,backgroundPosition:"0 0, 100% 0",backgroundSize:"100% 100%",backgroundRepeat:"no-repeat"},l={width:"36px",height:"36px",borderRadius:"8px",backgroundColor:"#F1F3F5",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"18px",fontWeight:"800",color:"#2D3748",border:"1px solid #E2E8F0"},g={fontSize:`${r.fontSize||18}px`,fontWeight:"800",color:"#1A202C",letterSpacing:"1px",flex:1,textAlign:"center"};return xe("div",{style:a,onClick:n,children:[xe("div",{style:{display:"flex",alignItems:"center",gap:"12px",flex:1},children:[Ut("div",{style:l,children:"%"}),Ut("span",{style:g,children:t.code||"OFFER20"})]}),xe("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[o&&Ut("span",{style:{fontSize:"11px",color:"#10B981",fontWeight:"700"},children:"Copied!"}),Ut("div",{style:{padding:"8px",display:"flex",alignItems:"center"},children:xe("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#4A5568",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[Ut("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),Ut("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]})]})};import{jsx as on}from"react/jsx-runtime";var nn=({data:t,onInteraction:e,isEditing:o=!1})=>{let i={emojis:["\u{1F60D}","\u{1F44D}"]},n=Array.isArray(t.emojis)?t.emojis:Array.isArray(i.emojis)?i.emojis:[],r=g=>{o||e?.({type:"reaction",reactionId:t.id,emoji:g,stickerId:t.id})},a={display:"flex",gap:"20px",justifyContent:"center",alignItems:"center",width:"100%",padding:"12px"},l={backgroundColor:"#FFFFFF",width:"64px",height:"64px",borderRadius:"100px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 8px 30px rgba(0,0,0,0.12)",fontSize:"32px",cursor:o?"default":"pointer",transition:"all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275)",border:"none",outline:"none",padding:0,position:"relative",zIndex:1};return on("div",{style:a,children:n.map((g,p)=>on("button",{style:l,onClick:()=>r(g),onMouseOver:x=>{o||(x.currentTarget.style.transform="scale(1.15) translateY(-4px)")},onMouseOut:x=>{o||(x.currentTarget.style.transform="scale(1) translateY(0)")},children:g},p))})};import{useState as rn,useRef as Oi,useEffect as ji}from"react";import{jsx as Ze,jsxs as sn}from"react/jsx-runtime";var an=({data:t,onInteraction:e,isEditing:o=!1})=>{let i=t.maxRating||5,n=t.currentRating??Math.floor(i/2),[r,a]=rn(n),l=Oi(null),[g,p]=rn(!1),x={backgroundColor:"#FFFFFF",borderRadius:36,padding:24,titleColor:"#000000",titleFontSize:24,sliderTrackColor:"#F3F4F6",sliderFillColor:"#F97316",emojiSize:42},m=t.styling||{},u={backgroundColor:m.backgroundColor||x.backgroundColor,borderRadius:`${m.borderRadius??x.borderRadius}px`,padding:`${m.padding??x.padding}px`,boxShadow:m.shadow||"0 12px 30px rgba(0,0,0,0.08)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",alignItems:"center",gap:"20px",cursor:"default",opacity:m.opacity??1},v={color:m.titleColor||x.titleColor,fontWeight:"900",fontSize:`${m.titleFontSize||x.titleFontSize}px`,margin:"0",textAlign:"center",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',width:"100%"},f={width:"100%",height:"18px",backgroundColor:m.sliderTrackColor||x.sliderTrackColor,borderRadius:"100px",position:"relative",cursor:o?"default":"pointer",marginTop:"24px",marginBottom:"8px",userSelect:"none"},b=r/i*100,h={width:`${b}%`,height:"100%",background:m.sliderFillColor||"linear-gradient(90deg, #FF4582, #e11d48)",borderRadius:"100px",transition:g?"none":"width 0.1s ease"},y=m.emojiSize||x.emojiSize,k={position:"absolute",left:`calc(${b}% - ${y/2}px)`,top:`-${y/4}px`,fontSize:`${y}px`,userSelect:"none",cursor:"grab",transition:g?"none":"left 0.1s ease",filter:"drop-shadow(0 4px 8px rgba(0,0,0,0.2))"},S=c=>{if(!l.current||o)return;let w=l.current.getBoundingClientRect(),s=c-w.left;s<0&&(s=0),s>w.width&&(s=w.width);let d=s/w.width,E=Math.round(d*i*10)/10;a(E)},T=c=>{o||(p(!0),S(c.clientX))},I=c=>{o||(p(!0),S(c.touches[0].clientX))};return ji(()=>{let c=d=>{g&&S(d.clientX)},w=()=>{g&&(p(!1),e?.({type:"rating",ratingId:t.id,value:r,stickerId:t.id}))},s=d=>{g&&S(d.touches[0].clientX)};return g&&(window.addEventListener("mousemove",c),window.addEventListener("mouseup",w),window.addEventListener("touchmove",s),window.addEventListener("touchend",w)),()=>{window.removeEventListener("mousemove",c),window.removeEventListener("mouseup",w),window.removeEventListener("touchmove",s),window.removeEventListener("touchend",w)}},[g,r]),sn("div",{style:u,children:[Ze("h3",{style:v,children:t.title||"Do you like my space?"}),sn("div",{ref:l,style:f,onMouseDown:T,onTouchStart:I,children:[Ze("div",{style:h}),Ze("div",{style:k,className:"interactive-emoji-thumb",children:t.emoji||"\u{1F60D}"})]})]})};import{useState as Ni}from"react";import{jsx as Jt,jsxs as to}from"react/jsx-runtime";var ln=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=Ni(""),r={backgroundColor:"#FFFFFF",borderRadius:16,padding:16,promptColor:"#111111",inputBgColor:"#FFFFFF",borderColor:"#EFEFEF",textColor:"#333333",placeholderColor:"#A0AEC0"},a=t.styling||{},l={backgroundColor:a.backgroundColor||r.backgroundColor,borderRadius:`${a.borderRadius??r.borderRadius}px`,padding:`${a.padding??r.padding}px`,boxShadow:a.shadow||"0 8px 24px rgba(0,0,0,0.06)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",border:`1px solid ${a.borderColor||"#F0F0F0"}`},g={color:a.promptColor||r.promptColor,fontWeight:"700",fontSize:`${a.fontSize?a.fontSize+2:16}px`,textAlign:"center",marginBottom:"2px",width:"100%"},p={width:"100%",position:"relative",display:"flex",alignItems:"center"},x={backgroundColor:a.inputBgColor||"#F1F3F5",border:"none",borderRadius:"30px",padding:"14px 45px 14px 20px",width:"100%",boxSizing:"border-box",color:a.inputTextColor||"#1A202C",fontSize:`${a.fontSize||14}px`,outline:"none",textAlign:"left",cursor:o?"default":"text",boxShadow:"inset 0 1px 2px rgba(0,0,0,0.05)"},m={position:"absolute",right:"10px",background:a.submitBackground||"#FE6B35",color:"white",border:"none",borderRadius:"50%",width:"32px",height:"32px",display:i.length>0?"flex":"none",alignItems:"center",justifyContent:"center",cursor:"pointer",transition:"transform 0.2s"},u=f=>{o||n(f.target.value)},v=()=>{o||!i.trim()||(e?.({type:"question",questionId:t.id,value:i.trim(),stickerId:t.id}),n(""))};return to("div",{style:l,children:[Jt("div",{style:g,children:t.question||"Ask me anything"}),to("div",{style:p,children:[Jt("input",{type:"text",value:i,placeholder:t.placeholder||"Type your answer...",style:x,disabled:o,onChange:u,onKeyDown:f=>f.key==="Enter"&&v()}),Jt("button",{style:m,onClick:v,children:to("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[Jt("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),Jt("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})};import{useState as qi}from"react";import{jsx as Kt,jsxs as eo}from"react/jsx-runtime";var dn=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=qi(null),r={backgroundColor:"#FFFFFF",borderRadius:20,padding:16,questionTextColor:"#111111",optionBgColor:"#F7FAFC",optionTextColor:"#2D3748",borderColor:"#E2E8F0",activeColor:"#10B981",incorrectColor:"#EF4444"},a=t.styling||{},l={backgroundColor:a.backgroundColor||r.backgroundColor,borderRadius:`${a.borderRadius??r.borderRadius}px`,padding:`${a.padding??r.padding}px`,boxShadow:a.shadow||"0 8px 24px rgba(0,0,0,0.06)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",gap:"12px",border:a.borderColor?`1px solid ${a.borderColor}`:"none"},g={color:a.questionTextColor||r.questionTextColor,fontWeight:"800",fontSize:`${a.fontSize?a.fontSize+2:16}px`,margin:"0 0 4px 0",textAlign:"left"},p={display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"12px",width:"100%"},x={backgroundColor:a.optionBgColor||r.optionBgColor,color:a.optionTextColor||r.optionTextColor,borderRadius:"16px",border:`2px solid ${a.borderColor||r.borderColor}`,cursor:i?"default":"pointer",display:"flex",flexDirection:"column",alignItems:"center",padding:"8px",boxSizing:"border-box",transition:"all 0.2s ease",overflow:"hidden"},m=f=>{o||i||(n(f),e?.({type:"image",quizId:t.id,optionId:f,stickerId:t.id}))},u="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Crect width='100%25' height='100%25' fill='%23EDF2F7'/%3E%3Cpath d='M30 40 L40 30 L50 40 L60 30 L70 40 V60 H30 Z' fill='%23A0AEC0'/%3E%3Ccircle cx='40' cy='45' r='5' fill='%23FFFFFF'/%3E%3C/svg%3E",v=Array.isArray(t.options)?t.options:[];return eo("div",{style:l,children:[t.question&&Kt("h3",{style:g,children:t.question}),Kt("div",{style:p,children:v.map(f=>{let b=f.id===i,h=f.isCorrect===!0,y={...x};return i&&(h?(y.borderColor=a.activeColor||r.activeColor,y.backgroundColor="rgba(16, 185, 129, 0.05)"):b&&(y.borderColor=a.incorrectColor||r.incorrectColor,y.backgroundColor="rgba(239, 68, 68, 0.05)")),eo("button",{style:y,onClick:()=>m(f.id),disabled:!!i,onMouseOver:k=>{!o&&!i&&(k.currentTarget.style.transform="translateY(-2px)")},onMouseOut:k=>{!o&&!i&&(k.currentTarget.style.transform="translateY(0)")},children:[eo("div",{style:{width:"100%",aspectRatio:"1",borderRadius:"12px",overflow:"hidden",backgroundColor:"#EDF2F7",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:"8px",position:"relative"},children:[Kt("img",{src:f.image||u,alt:f.text,style:{width:"100%",height:"100%",objectFit:"cover"}}),i&&Kt("div",{style:{position:"absolute",top:"6px",right:"6px",width:"24px",height:"24px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:h?r.activeColor:b?r.incorrectColor:"#A0AEC0",color:"#FFFFFF",fontSize:"12px",fontWeight:"bold"},children:h?"\u2713":b?"\u2715":""})]}),Kt("span",{style:{fontWeight:"600",fontSize:`${a.optionFontSize||13}px`,color:i&&h?r.activeColor:r.optionTextColor,width:"100%",textAlign:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:f.text})]},f.id)})})]})};import{useState as yn}from"react";import{useState as Xt,useEffect as Ui}from"react";import{jsx as H,jsxs as et}from"react/jsx-runtime";var mn=({product:t,styling:e,onClose:o,onAddToCart:i})=>{let[n,r]=Xt(""),[a,l]=Xt(0),[g,p]=Xt(1),[x,m]=Xt(!1),[u,v]=Xt(!1),f=t.attributes||{},b=f.colors||[],h=f.sizes||[],y=f.imageUrls||[t.image],k=f.description||"";Ui(()=>{h.length>0&&r(h[0]),v(!0)},[h]);let S=()=>{let C={productId:t.productId||t.id,title:t.title,selectedSize:n,selectedColor:b[a]?.name,quantity:g,price:t.price};i(C);let R=t.redirectUrl||t.url;if(R){!R.startsWith("http")&&!R.startsWith("//")&&(R="https://"+R);try{window.open(R,"_blank","noopener,noreferrer")}catch(P){console.error("AppStorys: Redirect failed",P)}}m(!0)},T=()=>{v(!1),setTimeout(o,400)},I=e?.buttonBackground||"#000000",c=e?.buttonTextColor||"#ffffff",w=e?.titleColor||e?.textColor||"#1a1a2e",s=e?.priceColor||e?.textColor||"#1a1a2e",d=e?.mrpColor||"#8b8b98",E=e?.titleFontWeight||"600",F=e?.priceFontWeight||"700",A=e?.mrpFontWeight||"500";return x?et("div",{className:"appstorys-shopable-success-overlay",style:cn,children:[H("div",{className:"appstorys-shopable-backdrop",style:pn,onClick:T}),et("div",{className:"appstorys-shopable-sheet",style:{...un,height:"auto",minHeight:"310px",animation:"appstorys-slide-up 0.4s cubic-bezier(0.2, 0.8, 0.2, 1)"},children:[H("div",{style:gn,onClick:T}),et("div",{style:{padding:"0 20px 24px",textAlign:"center"},children:[et("div",{style:{backgroundColor:"#F3F4F6",borderRadius:"20px",padding:"22px",marginTop:"16px",display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[et("h3",{style:{margin:0,fontSize:"16px",fontWeight:"600",lineHeight:"1.4"},children:["Added to your bag",H("br",{}),"successfully"]}),H("svg",{width:"44",height:"26",viewBox:"0 0 44 26",fill:"none",children:H("path",{d:"M4 4C4 4 11 22 22 22C33 22 40 4 40 4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"})})]}),et("div",{style:{marginTop:"24px",display:"flex",flexDirection:"column",gap:"8px"},children:[H("button",{onClick:T,style:{...io,backgroundColor:"#000000",color:"#ffffff",padding:"17px",fontSize:"16px",fontWeight:"600"},children:et("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[et("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[H("path",{d:"M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"}),H("path",{d:"M3 6h18"}),H("path",{d:"M16 10a4 4 0 0 1-8 0"})]}),"Go to checkout"]})}),H("button",{onClick:T,style:{...io,backgroundColor:"transparent",color:"#000000",border:"1px solid rgba(0,0,0,0.1)",padding:"15px",fontSize:"16px"},children:"Continue with stories"})]})]})]})]}):et("div",{className:`appstorys-shopable-overlay ${u?"visible":""}`,style:cn,children:[H("div",{className:"appstorys-shopable-backdrop",style:pn,onClick:T}),et("div",{className:"appstorys-shopable-sheet",style:{...un,transform:u?"translateY(0)":"translateY(100%)",opacity:u?1:0},children:[et("div",{style:Hi,children:[H("div",{style:gn,onClick:T}),H("button",{style:Vi,onClick:T,children:et("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[H("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),H("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),et("div",{style:Yi,children:[H("div",{style:Qi,children:y.map((C,R)=>H("div",{style:{minWidth:y.length>1?"85%":"100%",aspectRatio:"1.2 / 1",maxHeight:"240px",borderRadius:"16px",overflow:"hidden",backgroundColor:"#F9FAFB"},children:H("img",{src:C,alt:t.title,style:{width:"100%",height:"100%",objectFit:"contain"}})},R))}),et("div",{style:{padding:"0 20px 20px"},children:[H("h2",{style:{margin:"16px 0 4px",fontSize:e?.titleFontSize?`${e.titleFontSize}px`:"20px",fontWeight:E,color:w,lineHeight:"1.2"},children:t.title}),et("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",marginBottom:"16px"},children:[H("span",{style:{fontSize:e?.priceFontSize?`${e.priceFontSize}px`:"18px",fontWeight:F,color:s},children:t.price}),t.oldPrice&&H("span",{style:{fontSize:e?.mrpFontSize?`${e.mrpFontSize}px`:"14px",color:d,textDecoration:"line-through",fontWeight:A},children:t.oldPrice})]}),b.length>0&&et("div",{style:oo,children:[H("div",{style:no,children:"COLOR"}),H("div",{style:{display:"flex",gap:"14px",marginTop:"12px"},children:b.map((C,R)=>et("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"5px"},children:[H("button",{onClick:()=>l(R),style:{width:"36px",height:"36px",borderRadius:"50%",border:"none",backgroundColor:C.hex||"#gray",position:"relative",cursor:"pointer",boxShadow:a===R?"0 0 0 2px #fff, 0 0 0 4px #000":"none",transition:"all 0.2s ease"}}),H("div",{style:{width:"5px",height:"5px",borderRadius:"50%",backgroundColor:a===R?"#000":"transparent",transition:"all 0.2s ease"}})]},C.id))})]}),h.length>0&&et("div",{style:oo,children:[H("div",{style:no,children:"SIZE"}),H("div",{style:{display:"flex",gap:"10px",marginTop:"12px",flexWrap:"wrap"},children:h.map(C=>et("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"4px"},children:[H("button",{onClick:()=>r(C),style:{minWidth:"42px",height:"42px",borderRadius:"50%",backgroundColor:"transparent",border:`1px solid ${n===C?"#000":"rgba(0,0,0,0.1)"}`,color:n===C?"#000":"#8b8b98",fontSize:"13px",fontWeight:"500",cursor:"pointer",transition:"all 0.2s ease"},children:C}),H("div",{style:{width:"5px",height:"5px",borderRadius:"50%",backgroundColor:n===C?"#000":"transparent",transition:"all 0.2s ease"}})]},C))})]}),k&&et("div",{style:oo,children:[H("div",{style:no,children:"DESCRIPTION"}),H("p",{style:{margin:"8px 0 0",fontSize:"14px",lineHeight:"1.5",color:"#8b8b98",wordBreak:"break-word"},children:k})]})]})]}),et("div",{style:Gi,children:[et("div",{style:{display:"flex",flexDirection:"column",gap:"1px",minWidth:"75px"},children:[H("div",{style:{fontSize:"15px",fontWeight:F,color:s},children:t.price}),t.oldPrice&&H("div",{style:{fontSize:"11px",color:d,textDecoration:"line-through",fontWeight:A},children:t.oldPrice})]}),et("div",{style:Ji,children:[H("button",{style:fn,onClick:()=>p(C=>Math.max(1,C-1)),children:H("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:H("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}),H("span",{style:{fontSize:"16px",fontWeight:"700",minWidth:"18px",textAlign:"center",color:"#000000",display:"inline-block"},children:g}),H("button",{style:fn,onClick:()=>p(C=>C+1),children:et("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[H("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),H("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),(()=>{let C=f.availability?.toLowerCase()||"",R=C==="out of stock"||C==="out-of-stock";return et("button",{onClick:R?void 0:S,disabled:R,style:{...io,backgroundColor:R?"#F3F4F6":I,color:R?"#9CA3AF":c,flex:"1",padding:"12px 8px",gap:"6px",cursor:R?"not-allowed":"pointer",opacity:R?.8:1},children:[!R&&et("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[H("path",{d:"M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"}),H("path",{d:"M3 6h18"}),H("path",{d:"M16 10a4 4 0 0 1-8 0"})]}),H("span",{style:{fontSize:"12px",fontWeight:"700",whiteSpace:"nowrap"},children:R?"Out of Stock":"Add to cart"})]})})()]})]}),H("style",{children:`
|
|
37
|
+
@keyframes appstorys-slide-up {
|
|
38
|
+
from { transform: translateY(100%); }
|
|
39
|
+
to { transform: translateY(0); }
|
|
40
|
+
}
|
|
41
|
+
.appstorys-shopable-overlay {
|
|
42
|
+
position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 10000;
|
|
43
|
+
display: flex; align-items: flex-end; justify-content: center;
|
|
44
|
+
visibility: hidden;
|
|
45
|
+
}
|
|
46
|
+
.appstorys-shopable-overlay.visible {
|
|
47
|
+
visibility: visible;
|
|
48
|
+
}
|
|
49
|
+
`})]})},cn={position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:1e4,display:"flex",alignItems:"flex-end",justifyContent:"center",pointerEvents:"auto",fontFamily:"'Inter', system-ui, -apple-system, sans-serif",width:"100%",height:"100%",boxSizing:"border-box"},pn={position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.45)",cursor:"pointer"},un={position:"relative",width:"100%",maxWidth:"500px",backgroundColor:"#fff",borderTopLeftRadius:"28px",borderTopRightRadius:"28px",borderBottomLeftRadius:0,borderBottomRightRadius:0,maxHeight:"60vh",display:"flex",flexDirection:"column",margin:0,transition:"transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s ease",boxShadow:"0 -8px 24px rgba(0,0,0,0.15)",overflow:"hidden",boxSizing:"border-box"},Hi={height:"48px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative",flexShrink:0},gn={width:"36px",height:"5px",backgroundColor:"rgba(0,0,0,0.1)",borderRadius:"3px",cursor:"pointer"},Vi={position:"absolute",right:"18px",top:"16px",border:"none",width:"28px",height:"28px",borderRadius:"50%",backgroundColor:"#F3F4F6",display:"flex",alignItems:"center",justifyContent:"center",color:"#666",cursor:"pointer"},Yi={flex:1,overflowY:"auto",WebkitOverflowScrolling:"touch"},Qi={padding:"0 16px 20px",display:"flex",gap:"8px",overflowX:"auto",scrollSnapType:"x mandatory"},oo={marginTop:"20px"},no={fontSize:"11px",fontWeight:"600",color:"rgba(0,0,0,0.5)",letterSpacing:"1.4px"},Gi={padding:"12px 16px calc(20px + env(safe-area-inset-bottom, 0px))",borderTop:"1px solid rgba(0,0,0,0.05)",display:"flex",alignItems:"center",gap:"8px",backgroundColor:"#fff",boxShadow:"0 -4px 12px rgba(0,0,0,0.06)",zIndex:10,boxSizing:"border-box"},Ji={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"100px",border:"1px solid rgba(0,0,0,0.1)"},fn={border:"none",backgroundColor:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},io={border:"none",borderRadius:"100px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"};import{Fragment as Ki,jsx as zt,jsxs as Zt}from"react/jsx-runtime";var hn=({data:t,onInteraction:e,isEditing:o})=>{let{products:i,styling:n}=t,[r,a]=yn(!1),[l,g]=yn(null),p=(b,h)=>{if(b.stopPropagation(),o)return;if(t.shopableType==="product"){g(h),a(!0),e&&e({type:"product_view",stickerId:t.id,productId:h.productId||h.id,value:h.title});return}let y=h.redirectUrl||h.url;if(y&&!y.startsWith("http")&&!y.startsWith("//")&&(y="https://"+y),e&&e({type:"buy",stickerId:t.id,productId:h.id,value:h.title,selected_option:y}),y)try{window.open(y,"_blank","noopener,noreferrer")}catch(k){console.error("AppStorys: Redirect failed",k),window.location.href=y}},x=b=>{e&&e({type:"add_to_cart",stickerId:t.id,productId:b.productId,value:b.title,selected_option:JSON.stringify({size:b.selectedSize,color:b.selectedColor,quantity:b.quantity})})},m={width:"100%",height:"100%",display:"flex",gap:"12px",overflowX:"auto",padding:"0 1px",scrollSnapType:"x mandatory",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",pointerEvents:"auto"},u={flex:"0 0 auto",width:"100%",backgroundColor:n?.cardBackground||"#ffffff",borderRadius:n?.cardBorderRadius!==void 0?`${n.cardBorderRadius}px`:n?.cardRadiusPercent!==void 0?`${n.cardRadiusPercent}%`:"12px",overflow:"hidden",boxShadow:n?.shadow||"0 -2px 12px rgba(0,0,0,0.12)",display:"flex",flexDirection:"row",alignItems:"center",padding:"8px 12px",position:"relative",scrollSnapAlign:"center",transition:"transform 0.2s ease",cursor:"pointer",boxSizing:"border-box",pointerEvents:"auto",opacity:n?.opacity??1,marginBottom:0},v={width:"64px",height:"64px",borderRadius:n?.imageRadius!==void 0?`${n.imageRadius}px`:"12px",overflow:"hidden",backgroundColor:"#f5f5f5",flexShrink:0},f={flex:1,display:"flex",flexDirection:"column",justifyContent:"center",padding:"0 12px",minWidth:0};return Zt(Ki,{children:[Zt("div",{style:m,className:"shopable-container",children:[zt("style",{children:`
|
|
50
|
+
.shopable-container::-webkit-scrollbar { display: none; }
|
|
51
|
+
.shopable-card:active { transform: scale(0.98); }
|
|
52
|
+
`}),i.map(b=>Zt("div",{style:u,className:"shopable-card",onClick:h=>p(h,b),children:[zt("div",{style:v,children:zt("img",{src:b.image,alt:b.title,style:{width:"100%",height:"100%",objectFit:"cover"}})}),Zt("div",{style:f,children:[zt("span",{style:{color:n?.titleColor||n?.textColor||"#1a1b2e",fontSize:n?.titleFontSize?`${n.titleFontSize}px`:"15px",fontWeight:n?.titleFontWeight||"700",lineHeight:"1.2",display:"block",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginBottom:"1px"},children:b.title}),Zt("div",{style:{display:"flex",alignItems:"baseline",gap:"6px",flexWrap:"wrap"},children:[zt("span",{style:{color:n?.priceColor||n?.textColor||"#1a1b2e",fontSize:n?.priceFontSize?`${n.priceFontSize}px`:"18px",fontWeight:n?.priceFontWeight||"800",display:"block"},children:b.price}),b.oldPrice&&zt("span",{style:{color:n?.mrpColor||"#8b8b98",fontSize:n?.mrpFontSize?`${n.mrpFontSize}px`:"12px",fontWeight:n?.mrpFontWeight||"500",textDecoration:"line-through"},children:b.oldPrice})]})]}),zt("div",{style:{backgroundColor:n?.buttonBackground||"#000000",color:n?.buttonTextColor||"#ffffff",fontSize:n?.buttonFontSize?`${n.buttonFontSize}px`:"14px",fontWeight:"700",padding:"10px 18px",borderRadius:n?.buttonBorderRadius!==void 0?`${n.buttonBorderRadius}px`:"100px",textAlign:"center",flexShrink:0,whiteSpace:"nowrap"},children:"Buy Now"})]},b.id))]}),r&&l&&zt(mn,{product:l,styling:n,onClose:()=>a(!1),onAddToCart:x})]})};import{jsx as mt,jsxs as Xi}from"react/jsx-runtime";var bn=({data:t,onInteraction:e,isEditing:o=!1})=>{let i={x:10,y:15,width:80,rotation:0},n=t.x??i.x,r=t.y??i.y,a=t.width??i.width,l=t.rotation??i.rotation,g={position:"absolute",top:`${r}%`,left:`${n}%`,width:`${a}%`,height:t.height?`${t.height}%`:"auto",transform:`rotate(${l}deg)`,zIndex:10,transformOrigin:"center center",boxSizing:"border-box",cursor:o?"move":"default",pointerEvents:"auto"},p={width:"100%",height:"100%",animation:t.styling?.animation,animationFillMode:"forwards"},x=()=>{switch(t.type){case"poll":return mt(Jo,{data:t,onInteraction:e,isEditing:o});case"quiz":return mt(Xo,{data:t,onInteraction:e,isEditing:o});case"rating":return mt(an,{data:t,onInteraction:e,isEditing:o});case"question":case"input":return mt(ln,{data:t,onInteraction:e,isEditing:o});case"image_quiz":return mt(dn,{data:t,onInteraction:e,isEditing:o});case"countdown":return mt(tn,{data:t,onInteraction:e,isEditing:o});case"promo_code":case"promo":return mt(en,{data:t,onInteraction:e,isEditing:o});case"reaction":return mt(nn,{data:t,onInteraction:e,isEditing:o});case"buy":case"shopable":return mt(hn,{data:t,onInteraction:e,isEditing:o});case"image":return mt("img",{src:t.url,alt:"static overlay",style:{width:"100%",height:"100%",objectFit:"fill"}});case"text":{let u=t.styling||{};return mt("span",{style:{color:u.color||"#000000",fontSize:`${u.fontSize||14}px`,fontFamily:u.fontFamily||"Arial",fontStyle:u.fontStyle||"normal",fontWeight:u.fontWeight||"normal",wordBreak:"break-word",display:"inline-block"},children:t.text})}default:return Xi("div",{style:{padding:"10px",background:"white",color:"black",borderRadius:"4px"},children:["Unsupported interactive element: ",t.type]})}};return mt("div",{style:g,className:`interactive-item-z${t.z??0}`,children:mt("div",{style:p,children:x()})})};var Ft=t=>{if(!t)return;if(typeof t=="string")return t;if(typeof t=="object"){if(typeof t.solid=="string"&&t.solid)return t.solid;if(typeof t.value=="string"&&t.value)return t.value}let e=t.color||{};if(e.type==="gradient"&&e.gradient){let{direction:o="right",from:i,to:n,stops:r=[]}=e.gradient,l={right:"to right",left:"to left",top:"to top",bottom:"to bottom"}[o]||o;if(r.length>0){let g=r.map(p=>`${p.color} ${Math.round((p.offset||0)*100)}%`).join(", ");return`linear-gradient(${l}, ${g})`}return`linear-gradient(${l}, ${i}, ${n})`}return e.solid||e.value||void 0},Se=t=>{if(!t||t.type==="none")return;let e=String(t.type).toLowerCase(),o=t.duration||.6;if(e==="fade")return`appstorys-fade-in ${o}s ease-out forwards`;if(e==="classic")return`appstorys-classic-in ${o}s cubic-bezier(0.34, 1.56, 0.64, 1) forwards`;if(e==="rotate")return`appstorys-rotate-in ${o}s ease-out forwards`;if(e==="bounce")return`appstorys-bounce-in ${o+.2}s cubic-bezier(0.68, -0.6, 0.32, 1.6) forwards`};import{jsx as kn,jsxs as Zi}from"react/jsx-runtime";var xn=(t,e)=>{let o=t?.styling?.editorSource||t?.styling?.meta?.editorSource||t?.style?.editorSource||e?.editorSource||e?.meta?.editorSource;return o==="studio"||o==="editor"?"studio":"dashboard"},Wt=(t,e)=>Array.isArray(t)?t.map((o,i)=>{let n=o?.id||o?.key||o?.value||`option_${i+1}`,r=o?.label||o?.optionLabel,a=typeof o=="string"?o:o?.text||o?.title||r||"";return{id:String(n),text:a,image:o?.image||o?.imageUrl||"",label:r,isCorrect:o?.isCorrect===!0||String(n)===String(e)}}):t&&typeof t=="object"?Object.entries(t).map(([o,i])=>{let n=typeof i=="string"?{text:i}:i||{};return{id:o,text:n.text||n.title||n.label||"",image:n.image||n.imageUrl||"",label:n.label,isCorrect:o===String(e)}}):[],Sn=t=>Array.isArray(t?.emojis)?t.emojis.map(e=>String(e)):Wt(t?.options).map(e=>e.text).filter(Boolean),Cn=t=>{let e=String(t||"").toLowerCase();return e==="quizz"?"quiz":e==="rate"?"rating":e==="input"||e==="ask_question"||e==="askquestion"?"question":e==="promo"||e==="promocode"?"promo_code":e},vn=t=>{if(t.targetDate)return t.targetDate;if(!t.endDate)return new Date(Date.now()+864e5).toISOString();try{let e=`${t.endDate}${t.endTime?`T${t.endTime}`:""}`;return new Date(e).toISOString()}catch{return t.endDate||new Date(Date.now()+864e5).toISOString()}},wn=({content:t={},onInteraction:e,isEditing:o=!1,elapsedTime:i=0})=>{let n=t?.canva||{height:1920,width:1080},r=n?.width||1080,a=n?.height||1920,l=.352,g=t?.elements||[],p=t?.image||[],x=t?.text||[],m=t?.interactions||[],u=Array.isArray(t?.shopable)&&t.shopable.length>0?t.shopable:Array.isArray(t?.styling?.shopable)?t.styling.shopable:[],v=new Set(u.map(c=>c.id)),f=(t?.styling?.shopable||[]).concat(u.map(c=>c.styling).filter(Boolean));if(g.length===0&&p.length===0&&x.length===0&&m.length===0&&u.length===0)return null;let b=g.filter(c=>!v.has(c.id)).map(c=>{let w=c.custom||{},s=w.data||{},d=w.style||c.styling||{},E=xn(c,t),F=c.position||c.postion||{},A=c.size||{},C=c.x!==void 0?c.x:F.x,R=c.y!==void 0?c.y:F.y,P=c.width!==void 0?c.width:A.width,B=C!==void 0&&!isNaN(Number(C))?Number(C)/r*100:10,_=R!==void 0&&!isNaN(Number(R))?Number(R)/a*100:15,$=P!==void 0&&!isNaN(Number(P))?Number(P)/r*100:80,D={id:c.id||Math.random().toString(),type:Cn(w.interactiveType||c.widgetType||c.type||"unknown"),x:B,y:_,width:$,rotation:d.rotation??c.rotation??0,z:c.z??c.position?.z??d.z??10,duration:s.duration||d.duration,styling:{backgroundColor:Ft(d.background||d.containerBgColor||d.backgroundColor),borderRadius:d.borderRadius!==void 0?d.borderRadius>=100?999:d.borderRadius*l:d.radius!==void 0?d.radius>=100?999:d.radius*l:0,padding:(d.containerPadding!==void 0?d.containerPadding:d.padding!==void 0?d.padding:0)*l,shadow:d.shadow,fontSize:d.questionFontSize?d.questionFontSize*l:void 0,opacity:d.opacity??1,animation:Se(d.animation)}};if(D.type==="poll"){let O=Wt(s.options);return{...D,type:"poll",question:s.question||s.title||"Poll Question",options:O,layout:s.layout||{type:"vertical",columns:1},styling:{...D.styling,headerColor:d.headerBgColor||d.background,headerTextColor:d.questionColor||d.questionTextColor||d.question?.color,optionBgColor:d.optionBgColor||d.options?.background||"#1A1A1A",optionTextColor:d.optionTextColor||d.options?.textColor||"#ffffff",optionBorderRadius:d.optionBorderRadius!==void 0?d.optionBorderRadius*l:d.options?.radius!==void 0?d.options?.radius*l:0}}}if(D.type==="quiz"){let O=d.colors||{},W=Wt(s.options,s.isCorrect);return{...D,type:"quiz",question:s.question||s.title||"Quiz Question",options:W,showExplanation:s.showExplanation,url:s.url,styling:{...D.styling,backgroundColor:d.background||d.containerBgColor||d.backgroundColor||"transparent",questionTextColor:d.questionColor||O.questionColor||d.question?.color||d.colors?.questionText||"#FF0000",questionBgColor:d.questionBgColor||O.questionBackground||d.question?.background||d.colors?.questionBg||"#3BFF00",optionBgColor:d.optionBgColor||O.optionBackground||d.options?.background||d.colors?.optionBg||"#C100FF",optionTextColor:d.optionTextColor||O.optionTextColor||d.options?.textColor||d.colors?.optionText||"#ffffff",borderColor:d.borderColor||"transparent",activeColor:d.correctColor||O.correctColor||d.correctBorderColor||"#00D9FF",incorrectColor:d.incorrectColor||O.incorrectColor||"#ef4444",optionBorderRadius:d.optionRadius!==void 0?d.optionRadius>=100?999:d.optionRadius*l:d.optionBorderRadius!==void 0?d.optionBorderRadius>=100?999:d.optionBorderRadius*l:100,optionFontSize:(d.optionFontSize?d.optionFontSize:d.typography?.optionSize?d.typography?.optionSize:d.options?.fontSize?d.options?.fontSize:16)*l*1.25}}}if(D.type==="rating")return{...D,type:"rating",title:s.title||"Do you like my space?",emoji:s.emoji||"\u{1F60D}",currentRating:s.currentRating,maxRating:s.maxRating,styling:{...D.styling,sliderTrackColor:d.colors?.sliderTrack||d.sliderTrack,sliderFillColor:d.colors?.sliderFill||d.sliderFill,emojiSize:d.emojiSize?d.emojiSize*.45:void 0,titleColor:d.colors?.titleColor||d.titleColor,titleFontSize:d.titleFontSize?d.titleFontSize*.4:void 0}};if(D.type==="question")return{...D,type:"question",question:s.question||s.title||"Ask me a question",placeholder:s.placeholder||"Type your answer...",styling:{...D.styling,promptColor:d.questionColor||d.textColor,inputBgColor:d.inputBgColor,inputTextColor:d.inputTextColor,submitBackground:d.submitBackground}};if(D.type==="image_quiz"||D.type==="imageQuiz"||(w.interactiveType||"").toLowerCase()==="media_quiz")return{...D,type:"image_quiz",question:s.question||s.title||"Image Quiz",options:Wt(s.options||[]),styling:{...D.styling,questionTextColor:d.questionColor,activeColor:d.correctColor||d.correctBorderColor,incorrectColor:d.incorrectColor,imageRadius:d.imageRadius?d.imageRadius*l:void 0}};if(D.type==="countdown")return{...D,type:"countdown",title:s.title||"Ends in...",targetDate:vn(s),styling:{...D.styling,borderColor:d.borderColor,digitBackground:d.digitBackground,digitColor:d.digitColor,digitSize:d.digitSize?d.digitSize*l:void 0,labelColor:d.labelColor,titleColor:d.titleColor},display:s.display};if(D.type==="promo_code")return{...D,type:"promo_code",code:s.code||"CODE20",styling:{...D.styling,borderColor:d.borderColor}};if(D.type==="reaction"||D.type==="emoji_reaction"){let O=Sn(s);return{...D,type:"reaction",emojis:O.length>0?O:["\u{1F60D}","\u{1F44D}"],source:E}}return D}),h=(t?.interactions||[]).filter(c=>!v.has(c.id)).map(c=>{let w=c.config||{},s=c.styling||c.style||{},d=xn(c,t),E=Cn(c.interaction_type||c.type),F=s.position||c.position||{},A=s.size||c.size||{},C=F.x??c.x,R=F.y??c.y,P=A.width??c.width,B=A.height??c.height,_=C!==void 0&&!isNaN(Number(C))?Number(C)/r*100:10,$=R!==void 0&&!isNaN(Number(R))?Number(R)/a*100:15,D=P!==void 0&&!isNaN(Number(P))?Number(P)/r*100:80,O=B!==void 0&&!isNaN(Number(B))?Number(B)/a*100:void 0,W={id:c.id||Math.random().toString(),type:E,x:_,y:$,width:D,height:O,rotation:s.rotation??c.rotation??0,z:c.z??c.position?.z??s.z??10,source:d,duration:w.duration||s.duration,styling:{backgroundColor:Ft(s.background||s.containerBgColor||s.backgroundColor),borderRadius:s.borderRadius!==void 0?s.borderRadius>=100?999:s.borderRadius*l:s.radius!==void 0?s.radius>=100?999:s.radius*l:0,padding:(s.containerPadding!==void 0?s.containerPadding:s.padding!==void 0?s.padding:0)*l,shadow:s.shadow,fontSize:s.questionSize?s.questionSize*l:s.questionFontSize?s.questionFontSize*l:void 0,opacity:s.opacity??1,animation:Se(s.animation)}};if(W.type==="rating"||W.type==="rate"){let Y=s.colors||{};return{...W,type:"rating",title:w.title||"Do you like my space?",emoji:w.emoji||"\u{1F60D}",currentRating:w.currentRating,maxRating:w.maxRating,styling:{...W.styling,sliderTrackColor:Y.sliderTrack||s.colors?.sliderTrack||s.colors?.sliderTrack,sliderFillColor:Y.sliderFill||s.colors?.sliderFill||s.sliderFill,emojiSize:s.emojiSize?s.emojiSize*.45:void 0,titleColor:Y.titleColor||s.colors?.titleColor||s.titleColor,titleFontSize:s.titleFontSize?s.titleFontSize*.4:void 0}}}if(W.type==="poll"){let Y=Wt(w.options);return{...W,type:"poll",question:w.question||w.title||"Poll Question",options:Y,layout:w.layout||{type:"vertical",columns:1},styling:{...W.styling,headerColor:s.headerBgColor||s.background,headerTextColor:s.questionColor||s.questionTextColor||s.question?.color,optionBgColor:s.optionBgColor||s.options?.background||"#1A1A1A",optionTextColor:s.optionTextColor||s.options?.textColor||"#ffffff",optionBorderRadius:s.optionBorderRadius!==void 0?s.optionBorderRadius*l:s.options?.radius!==void 0?s.options?.radius*l:0}}}if(W.type==="quiz"){let Y=s.colors||{},dt=Wt(w.options,w.isCorrect);return{...W,type:"quiz",question:w.question||w.title||"Quiz Question",options:dt,showExplanation:w.showExplanation,url:w.url,styling:{...W.styling,backgroundColor:s.background||s.containerBgColor||s.backgroundColor||"transparent",questionTextColor:s.questionColor||Y.questionColor||s.question?.color||s.colors?.questionText||"#FF0000",questionBgColor:s.questionBgColor||Y.questionBackground||s.question?.background||s.colors?.questionBg||"#3BFF00",optionBgColor:s.optionBgColor||Y.optionBackground||s.options?.background||s.colors?.optionBg||"#C100FF",optionTextColor:s.optionTextColor||Y.optionTextColor||s.options?.textColor||s.colors?.optionText||"#ffffff",borderColor:s.borderColor||"transparent",activeColor:s.correctColor||Y.correctColor||s.correctBorderColor||"#00D9FF",incorrectColor:s.incorrectColor||Y.incorrectColor||"#ef4444",optionBorderRadius:s.optionRadius!==void 0?s.optionRadius>=100?999:s.optionRadius*l:s.optionBorderRadius!==void 0?s.optionBorderRadius>=100?999:s.optionBorderRadius*l:100,optionFontSize:(s.optionFontSize?s.optionFontSize:s.typography?.optionSize?s.typography?.optionSize:s.options?.fontSize?s.options?.fontSize:16)*l*1.25}}}if(W.type==="question")return{...W,type:"question",question:w.question||w.title||"Ask me a question",placeholder:w.placeholder||"Type your answer...",styling:{...W.styling,promptColor:s.questionColor||s.promptColor||s.textColor,inputBgColor:s.inputBackground||s.inputBgColor,inputTextColor:s.inputTextColor,submitBackground:s.submitBackground}};if(W.type==="image_quiz"||W.type==="imageQuiz"||E==="media_quiz")return{...W,type:"image_quiz",question:w.question||w.title||"Image Quiz",options:Wt(w.options||[]),styling:{...W.styling,questionTextColor:s.questionColor,activeColor:s.correctColor||s.correctBorderColor,incorrectColor:s.incorrectColor,imageRadius:s.imageRadius?s.imageRadius*l:void 0}};if(W.type==="countdown")return{...W,type:"countdown",title:w.title||"Ends in...",targetDate:vn(w),styling:{...W.styling,borderColor:s.borderColor,digitBackground:s.digitBackground,digitColor:s.digitColor,digitSize:s.digitSize||s.fontSize?Number(s.digitSize||s.fontSize):void 0,labelColor:s.labelColor,titleColor:s.titleColor,labelFontSize:s.labelFontSize?Number(s.labelFontSize):void 0},display:w.display||c.display};if(W.type==="promo_code")return{...W,type:"promo_code",code:w.code||"CODE20",styling:{...W.styling,borderColor:s.borderColor}};if(W.type==="reaction"||W.type==="emoji_reaction"){let Y=Sn(w);return{...W,type:"reaction",emojis:Y.length>0?Y:["\u{1F60D}","\u{1F44D}"]}}return W}),y=u.map(c=>{let w=f.find(M=>String(M?.id)===String(c?.id))||f.find(M=>M?.id===void 0)||{},s={position:c?.position,size:c?.size,rotation:c?.rotation,z:c?.z,background:c?.background,cardBackground:c?.cardBackground,cardBorderRadius:c?.cardBorderRadius,cardRadiusPercent:c?.cardRadiusPercent,transparent:c?.transparent,textColor:c?.textColor,buttonBackground:c?.buttonBackground,buttonTextColor:c?.buttonTextColor,buttonFontSize:c?.buttonFontSize,buttonBorderRadius:c?.buttonBorderRadius,titleColor:c?.titleColor,titleFontSize:c?.titleFontSize,titleFontWeight:c?.titleFontWeight,priceColor:c?.priceColor,priceFontSize:c?.priceFontSize,priceFontWeight:c?.priceFontWeight,mrpColor:c?.mrpColor,mrpFontSize:c?.mrpFontSize,mrpFontWeight:c?.mrpFontWeight,imageRadius:c?.imageRadius,opacity:c?.opacity,animation:c?.animation},d={...w,...c?.styling||{},...Object.fromEntries(Object.entries(s).filter(([,M])=>M!==void 0))},E=d.position||{},F=d.size||{},A=d.cardBorderRadius!==void 0?Number(d.cardBorderRadius):void 0,C=d.cardRadiusPercent!==void 0?Number(d.cardRadiusPercent):void 0,R=F.height!==void 0?Number(F.height):void 0,P=A===void 0&&C!==void 0&&R!==void 0?Math.max(0,Math.min(100,C))/100*(R/2):void 0,B=A??P,_=B!==void 0&&!isNaN(B)?B*l:void 0,$=E.x!==void 0?Number(E.x)/r*100:0,D=F.width!==void 0?Number(F.width)/r*100:100,O=F.height!==void 0?Number(F.height)/a*100:void 0,W=E.y!==void 0?Number(E.y)/a*100:O?100-O-2.5:85;O&&W+O>96?W=Math.max(0,100-O):W>75&&O&&W+O>91&&(W=Math.max(0,100-O-1));let Y=Array.isArray(c.product)&&c.product.length>0,dt=Y?c.product:c.static||[];return{id:c.id||Math.random().toString(),type:"buy",shopableType:Y?"product":"static",x:$,y:W,width:D,height:O,rotation:d.rotation??0,z:d.z??10,products:dt.map(M=>{let N=M.productData||M||{},U=N.attributes||M.attributes||{},rt=U.sales_price||N.price||U.price||M.price,ct=U.sales_price?N.price||U.price||M.price:N.oldPrice||M.oldPrice,q=N.color||U.color||M.color,Q=N.size||U.size||M.size,st=U.colors||[];st.length===0&&q&&(st=[{id:q,hex:q,name:q}]);let pt=U.sizes||[];pt.length===0&&Q&&(pt=typeof Q=="string"?Q.split(",").map(at=>at.trim()):[Q]);let ft={description:N.description||U.description||M.description,color:q,size:Q,colors:st,sizes:pt,imageUrls:U.imageUrls||[U.image_link||N.imageUrl||N.image||M.imageUrl||M.image||M.url].filter(Boolean),availability:N.availability||U.availability||M.availability,tags:N.tags||U.tags||M.tags,...U};return{id:N.productId||N.id||M.productId||M.id||Math.random().toString(),image:U.image_link||N.imageUrl||N.image||M.imageUrl||M.image||M.url,url:N.link||N.url||M.link||M.url||M.redirectUrl,title:N.title||M.title,price:rt,oldPrice:ct,redirectUrl:M.redirectUrl||N.link||M.link||M.url,svg:N.svg||M.svg,productId:N.productId||M.productId,collectionId:N.collectionId||M.collectionId,feedId:N.feedId||M.feedId,attributes:ft}}),styling:{backgroundColor:Ft(d.background),cardBackground:Ft(d.cardBackground)||Ft(d.background)||"#ffffff",cardBorderRadius:_!==void 0?_:10,cardRadiusPercent:C,transparent:d.transparent===!0,textColor:d.textColor||"#ffffff",buttonBackground:d.buttonBackground||"#000000",buttonTextColor:d.buttonTextColor||"#ffffff",buttonFontSize:d.buttonFontSize||12,buttonBorderRadius:d.buttonBorderRadius!==void 0?d.buttonBorderRadius:100,titleColor:d.titleColor||d.textColor||"#1a1a2e",titleFontSize:d.titleFontSize||14,titleFontWeight:d.titleFontWeight?String(d.titleFontWeight):"600",priceColor:d.priceColor||d.textColor||"#1a1a2e",priceFontSize:d.priceFontSize||16,priceFontWeight:d.priceFontWeight?String(d.priceFontWeight):"700",mrpColor:d.mrpColor||"#8b8b98",mrpFontSize:d.mrpFontSize||12,mrpFontWeight:d.mrpFontWeight?String(d.mrpFontWeight):"500",imageRadius:d.imageRadius!==void 0?Number(d.imageRadius)*l:10,animation:Se(d.animation)}}}),k=p.map(c=>{let w=c.position||c.postion||{x:0,y:0};return{id:c.id||Math.random().toString(),type:"image",x:w.x/r*100,y:w.y/a*100,width:c.width/r*100,height:c.height?c.height/a*100:void 0,url:c.link||c.url,z:c.z??0}}),S=x.map(c=>{let w=c.position||{x:0,y:0},s=c.font||{};return{id:c.id||Math.random().toString(),type:"text",x:w.x/r*100,y:w.y/a*100,width:c.size?.width?c.size.width/r*100:void 0,text:c.value,z:c.z??1,styling:{color:c.color||"#000000",fontSize:s.fontSize?s.fontSize*l:void 0,fontFamily:s.fontFamily,fontStyle:s.fontStyle,fontWeight:s.fontWeight}}}),T=[...b,...h,...y,...k,...S].filter(c=>{if(!c.duration)return!0;let{start:w,end:s}=c.duration;return i>=w&&i<=s}).sort((c,w)=>(c.z??0)-(w.z??0));return Zi("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,pointerEvents:"none",overflow:"hidden"},children:[kn("style",{children:`
|
|
53
|
+
@keyframes appstorys-fade-in {
|
|
54
|
+
from { opacity: 0; transform: translateY(10px); }
|
|
55
|
+
to { opacity: 1; transform: translateY(0); }
|
|
56
|
+
}
|
|
57
|
+
@keyframes appstorys-classic-in {
|
|
58
|
+
0% { opacity: 0; transform: scale(0.7); }
|
|
59
|
+
70% { opacity: 1; transform: scale(1.05); }
|
|
60
|
+
100% { opacity: 1; transform: scale(1); }
|
|
61
|
+
}
|
|
62
|
+
@keyframes appstorys-rotate-in {
|
|
63
|
+
from { opacity: 0; transform: rotate(-20deg) scale(0.5); }
|
|
64
|
+
to { opacity: 1; transform: rotate(0deg) scale(1); }
|
|
65
|
+
}
|
|
66
|
+
@keyframes appstorys-bounce-in {
|
|
67
|
+
0% { opacity: 0; transform: scale(0.3); }
|
|
68
|
+
50% { opacity: 1; transform: scale(1.1); }
|
|
69
|
+
70% { opacity: 1; transform: scale(0.95); }
|
|
70
|
+
100% { opacity: 1; transform: scale(1); }
|
|
71
|
+
}
|
|
72
|
+
`}),T.map(c=>!c||typeof c!="object"||!(c.type||"").toLowerCase()?null:kn(bn,{data:c,onInteraction:e,isEditing:o},c.id))]})};import{useState as tr}from"react";import{jsx as te,jsxs as or}from"react/jsx-runtime";var er=({isPaused:t,onPress:e,style:o,size:i=36})=>{let[n,r]=tr(!1);return te("button",{onClick:e,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{width:`${i}px`,height:`${i}px`,background:n?"rgba(255, 255, 255, 0.15)":"rgba(255, 255, 255, 0.08)",border:n?"1px solid white":"1px solid rgba(255, 255, 255, 0.1)",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"10px",cursor:"pointer",transition:"all 0.2s ease",padding:0,outline:"none",...o},children:t?te("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:te("path",{d:"M5 3.867v16.266c0 .54.58.88 1.05.61l14.133-8.133c.46-.27.46-.94 0-1.21L6.05 3.257C5.58 2.987 5 3.327 5 3.867z"})}):or("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:[te("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),te("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]})})},Rn=er;import{jsx as ro}from"react/jsx-runtime";var nr=t=>{switch(t){case"left":return"flex-start";case"right":return"flex-end";default:return"center"}},ir=({cta:t,buttonText:e,onPress:o})=>!t||!e||e.trim()===""?null:ro("div",{style:{position:"absolute",bottom:t?.margin?.bottom,left:t?.margin?.left,right:t?.margin?.right,display:"flex",justifyContent:nr(t?.container?.alignment),width:"100%",pointerEvents:"none",boxSizing:"border-box",zIndex:10},children:ro("button",{style:{backgroundColor:t?.container?.backgroundColor||"#F7921C",borderColor:t?.container?.borderColor||"transparent",borderWidth:t?.container?.borderWidth??0,borderStyle:t?.container?.borderWidth?"solid":"none",borderTopRightRadius:t?.cornerRadius?.topRight,borderTopLeftRadius:t?.cornerRadius?.topLeft,borderBottomRightRadius:t?.cornerRadius?.bottomRight,borderBottomLeftRadius:t?.cornerRadius?.bottomLeft,height:t?.container?.height||42,width:t?.container?.ctaFullWidth?"100%":t?.container?.ctaWidth||"auto",justifyContent:"center",alignItems:"center",display:"flex",cursor:"pointer",outline:"none",pointerEvents:"auto",padding:"0 12px",boxSizing:"border-box"},onClick:o,children:ro("span",{style:{color:t?.text?.color||"#ffffff",fontSize:t?.text?.fontSize||14,fontFamily:t?.text?.fontFamily,fontWeight:t?.text?.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:t?.text?.fontDecoration?.includes("italic")?"italic":"normal",textDecorationLine:t?.text?.fontDecoration?.includes("underline")?"underline":"none",textAlign:"center"},children:ye(e)})})}),Tn=ir;import{jsx as Ce,jsxs as sr}from"react/jsx-runtime";var rr=({config:t,onPress:e,style:o,ignoreSizeAndMargin:i=!1})=>{if(!t||!t.enabled)return null;let{size:n=18,margin:r,color:a,image:l,selectedStyle:g}=t,p=i?40:n,x={marginTop:i?0:r?.top??0,marginBottom:i?0:r?.bottom??0,marginLeft:i?0:r?.left??0,marginRight:i?0:r?.right??0,width:p,height:p,backgroundColor:a?.fill||"transparent",borderColor:a?.stroke||"transparent",borderWidth:p*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,position:"absolute",display:"flex",padding:0,cursor:"pointer",outline:"none",borderStyle:a?.stroke?"solid":"none",...o},m=()=>{let u=a?.cross||"#ffffff";return sr("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Ce("line",{x1:"6",y1:"6",x2:"18",y2:"18",stroke:u,strokeWidth:"2.2",strokeLinecap:"round"}),Ce("line",{x1:"18",y1:"6",x2:"6",y2:"18",stroke:u,strokeWidth:"2.2",strokeLinecap:"round"})]})};return Ce("button",{onClick:e,style:x,title:g||"",children:l&&l.trim()!==""?Ce("img",{src:l,style:{width:p,height:p,objectFit:"contain"},alt:"close"}):m()})},kt=rr;import{jsx as It,jsxs as zn}from"react/jsx-runtime";var so=({config:t,onPress:e,ignoreSizeAndMargin:o=!1,enabled:i,style:n,type:r})=>{if(!t||!i)return null;let{size:a=18,margin:l,color:g,image:p,selectedStyle:x}=t,m=o?40:a,u=o?0:l?.top??0,v=o?0:l?.bottom??0,f=o?0:l?.left??0,b=o?0:l?.right??0,h={marginTop:u,marginBottom:v,marginLeft:f,marginRight:b,width:m,height:m,backgroundColor:g?.fill||"transparent",borderColor:g?.stroke||"transparent",borderWidth:m*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,display:"flex",...o?{}:{marginTop:t.margin?.top??0,marginRight:t.margin?.right??0,marginBottom:t.margin?.bottom??0,marginLeft:t.margin?.left??0},...n},y=()=>{let k=g?.cross||"#ffffff";return r==="mute"?zn("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[It("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:k,strokeWidth:"2.2",strokeLinejoin:"round"}),It("line",{x1:"16",y1:"8",x2:"21",y2:"16",stroke:k,strokeWidth:"2.2",strokeLinecap:"round"}),It("line",{x1:"21",y1:"8",x2:"16",y2:"16",stroke:k,strokeWidth:"2.2",strokeLinecap:"round"})]}):zn("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[It("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:k,strokeWidth:"2.2",strokeLinejoin:"round"}),It("path",{d:"M16 10 Q18 12 16 14",fill:"none",stroke:k,strokeWidth:"2.2",strokeLinecap:"round"}),It("path",{d:"M18 8 Q22 12 18 16",fill:"none",stroke:k,strokeWidth:"2.2",strokeLinecap:"round"})]})};return It("button",{onClick:e,style:{...h,border:h.borderColor?`${h.borderWidth}px solid ${h.borderColor}`:"none",padding:0,cursor:"pointer",outline:"none"},title:x||"",children:p&&p.trim()!==""?It("img",{src:p,style:{width:m,height:m,objectFit:"contain"},alt:r}):y()})};import{jsx as _t,jsxs as lr}from"react/jsx-runtime";var ar=({config:t,onPress:e,ignoreSizeAndMargin:o=!1,style:i})=>{if(!t||t.enabled===!1)return null;let{size:n=18,margin:r,color:a,image:l,selectedStyle:g}=t,p=o?40:n,x={marginTop:o?0:r?.top??0,marginBottom:o?0:r?.bottom??0,marginLeft:o?0:r?.left??0,marginRight:o?0:r?.right??0,width:p,height:p,backgroundColor:a?.fill||"transparent",borderColor:a?.stroke||"transparent",borderWidth:p*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,position:"absolute",display:"flex",padding:0,cursor:"pointer",outline:"none",borderStyle:a?.stroke?"solid":"none",...i},m=()=>{let u=a?.cross||"#ffffff";return lr("svg",{viewBox:"0 0 24 24",width:"60%",height:"60%",fill:"none",stroke:u,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[_t("circle",{cx:"18",cy:"5",r:"3"}),_t("circle",{cx:"6",cy:"12",r:"3"}),_t("circle",{cx:"18",cy:"19",r:"3"}),_t("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),_t("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]})};return _t("button",{onClick:e,style:x,title:g||"",children:l&&l.trim()!==""?_t("img",{src:l,style:{width:p,height:p,objectFit:"contain"},alt:"share"}):m()})},Fn=ar;import{Fragment as In,jsx as L,jsxs as J}from"react/jsx-runtime";var Bn=({stories:t,activeStoryIndex:e,dataId:o,viewedStories:i,setViewedStories:n,onNextStory:r,onPrevStory:a,onClose:l})=>{let[g,p]=Bt(0),[x,m]=Bt(0),[u,v]=Bt(!1),[f,b]=Bt(!1),[h,y]=Bt(!1),[k,S]=Bt(!1),[T,I]=Bt(null),[c,w]=Bt(typeof window<"u"?window.innerWidth>=1024:!1);ee(()=>{let j=()=>{w(window.innerWidth>=1024)};return window.addEventListener("resize",j),()=>window.removeEventListener("resize",j)},[]);let s=ao(null),d=ao(null),E=ao(0),F=t[e],A=F?.slides[g],C=A?.styling,R=C?.editorSource||C?.meta?.editorSource,P=R==="studio"||R==="editor",B=P?C?.background?.media?.mediaUrl:A?.image,_=P?A?.content?.button_text:A?.button_text,$=P?A?.content?.link:A?.link,D=A?.video||(P?A?.content?.video?.[0]?.link:void 0),O=async()=>{let j={title:F.name,text:`Check out this story: ${F.name}`,url:window.location.href};if(A?.id&&V("shared",o,{story_slide:A.id}),navigator.share)try{await navigator.share(j)}catch{}else if(navigator.clipboard)try{await navigator.clipboard.writeText(window.location.href),I("Story link copied to clipboard!"),setTimeout(()=>I(null),2500)}catch{}};if(ee(()=>{p(0),m(0),b(!1),y(!1)},[e]),ee(()=>{let j=G=>{if(!(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA"))switch(G.key){case"ArrowRight":W();break;case"ArrowLeft":Y();break;case" ":G.preventDefault(),y(X=>!X);break;case"Escape":l();break;case"s":case"S":G.preventDefault(),O();break}};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[g,e,h,F,l]),ee(()=>{F&&A&&V("viewed",o,{story_slide:A.id})},[g,F?.id,o]),ee(()=>{if(F&&A){let j=F.styling?.slideShowTime||5,G=!!D;if(s.current&&clearInterval(s.current),h){d.current&&d.current.pause();return}else d.current&&d.current.play().catch(()=>{});return G&&!f?void 0:(s.current=setInterval(()=>{m(X=>X>=100?(W(),100):X+100/(j*10))},100),()=>{s.current&&clearInterval(s.current)})}},[e,g,h,f]),!A)return null;let W=()=>{if(g<F.slides.length-1)p(j=>j+1),m(0);else{if(!i.includes(F.id)){let j=[...i,F.id];n(j),localStorage.setItem("app_storys_viewed_stories",JSON.stringify(j))}r()}},Y=()=>{g>0?(p(j=>j-1),m(0)):a()},dt=()=>{E.current=Date.now(),y(!0)},M=j=>{y(!1),Date.now()-E.current<300&&(j==="next"?W():Y())},N=()=>{b(!0)},U=j=>{let G=j?.styling,X=G?.editorSource||G?.meta?.editorSource,vt=X==="studio"||X==="editor"?j.content?.link:j.link;vt&&(V("clicked",o,{story_slide:j.id}),vt.startsWith("http")?window.open(vt,"_blank"):window.location.href=vt)},rt=j=>{j.stopPropagation(),v(!u)},ct=F?.styling?.crossButton,q=F?.styling?.soundToggle,Q=A?.styling?.cta,st=Q?.container,pt=Q?.text,ft=c?{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",background:"radial-gradient(circle at center, #0B1424 0%, #03070E 100%)",zIndex:1e5,display:"flex",flexDirection:"column",alignItems:"center",overflow:"hidden",color:"white"}:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",backgroundColor:"rgba(0,0,0,0.95)",zIndex:1e5,display:"flex",justifyContent:"center",alignItems:"center"},at=c?{position:"relative",width:"380px",height:"680px",backgroundColor:"#000",borderRadius:"20px",overflow:"hidden",display:"flex",flexDirection:"column",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.8)",border:"1px solid rgba(255, 255, 255, 0.1)",transition:"all 0.3s ease",zIndex:5}:{position:"relative",width:"100%",maxWidth:"450px",height:"100%",maxHeight:"850px",backgroundColor:"#000",borderRadius:"0px",overflow:"hidden",display:"flex",flexDirection:"column"},wt={width:"240px",height:"420px",backgroundColor:"#000",borderRadius:"16px",overflow:"hidden",opacity:.45,filter:"none",display:"flex",flexDirection:"column",boxShadow:"0 10px 20px rgba(0,0,0,0.5)",border:"1px solid rgba(255, 255, 255, 0.05)",transform:"scale(0.9)",transition:"all 0.3s ease",cursor:"pointer"};return J("div",{style:ft,onClick:()=>!c&&W(),children:[J("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:0,overflow:"hidden",pointerEvents:"none",transition:"all 0.6s ease-in-out"},children:[D?L("video",{src:D,style:{width:"100%",height:"100%",objectFit:"cover",filter:"blur(120px) saturate(1.8) opacity(0.35)"},muted:!0}):L(bt,{src:B||F.thumbnail,style:{width:"100%",height:"100%",filter:"blur(120px) saturate(1.8) opacity(0.35)"}}),L("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,background:"rgba(5, 5, 8, 0.4)"}})]},`${e}-${g}`),c&&J(In,{children:[L("div",{style:{width:"100%",display:"flex",gap:"8px",padding:"12px 20px",boxSizing:"border-box",zIndex:10},children:F.slides.map((j,G)=>{let X="0%";return G<g?X="100%":G===g&&(X=`${x}%`),L("div",{style:{flex:1,height:"3px",backgroundColor:"rgba(255,255,255,0.15)",borderRadius:"2px",overflow:"hidden"},children:L("div",{style:{width:X,height:"100%",backgroundColor:"white",transition:G===g?"width 0.1s linear":"none"}})},G)})}),J("div",{style:{width:"100%",display:"grid",gridTemplateColumns:"1fr 380px 1fr",alignItems:"center",padding:"12px 20px",boxSizing:"border-box",zIndex:k?2e3:10},children:[L("div",{}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[J("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[L(bt,{src:F.thumbnail,alt:F.name,style:{width:"36px",height:"36px",borderRadius:"50%",border:"2px solid #F97316"}}),L("span",{style:{color:"white",fontWeight:"bold",fontSize:"15px",whiteSpace:"nowrap"},children:F.name})]}),J("div",{style:{display:"flex",gap:"8px"},children:[L(Fn,{config:{enabled:(F?.styling?.share?.enabled??!0)&&!!$,image:F?.styling?.share?.image??"",color:{cross:F?.styling?.share?.color?.cross??"#ffffff",fill:F?.styling?.share?.color?.fill??"rgba(255,255,255,0.08)",stroke:F?.styling?.share?.color?.stroke??"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:F?.styling?.share?.size??36},onPress:O,style:{position:"relative",borderRadius:"10px"}}),L(so,{config:{size:36,color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},image:u?F?.styling?.soundToggle?.mute?.image||"":F?.styling?.soundToggle?.unmute?.image||""},onPress:rt,type:u?"mute":"unmute",enabled:!!q?.enabled&&!!D,style:{position:"relative",borderRadius:"10px"}}),L(Rn,{isPaused:h,onPress:()=>y(!h)})]})]}),J("div",{style:{display:"flex",gap:"10px",flex:1,justifyContent:"flex-end"},children:[J("div",{style:{position:"relative"},children:[L("button",{onClick:()=>{S(!k),y(!k)},style:{width:"36px",height:"36px",background:k?"rgba(255,255,255,0.15)":"rgba(255,255,255,0.08)",border:k?"1px solid white":"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"10px",cursor:"pointer",transition:"all 0.2s",padding:0,outline:"none"},children:J("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[L("rect",{x:"3",y:"3",width:"7",height:"7"}),L("rect",{x:"14",y:"3",width:"7",height:"7"}),L("rect",{x:"14",y:"14",width:"7",height:"7"}),L("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),k&&J(In,{children:[L("style",{children:`
|
|
73
|
+
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
74
|
+
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
|
|
75
|
+
`}),L("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0, 0, 0, 0.45)",zIndex:1e3,animation:"fadeIn 0.2s ease-out forwards"},onClick:()=>{S(!1),y(!1)}}),J("div",{style:{position:"absolute",top:"46px",right:0,width:"260px",background:"rgba(25, 25, 25, 0.98)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:"16px",padding:"18px",boxShadow:"0 20px 25px -5px rgba(0,0,0,0.4), 0 10px 10px -5px rgba(0,0,0,0.4)",zIndex:1001,animation:"fadeUp 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards"},children:[L("div",{style:{fontSize:"11px",fontWeight:"bold",color:"#9CA3AF",letterSpacing:"1px",textTransform:"uppercase",marginBottom:"16px",paddingBottom:"10px",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:"Keyboard Shortcuts"}),J("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("span",{style:{background:"rgba(255,255,255,0.08)",padding:"5px 8px",borderRadius:"5px",fontSize:"12px",color:"white",border:"1px solid rgba(255,255,255,0.1)"},children:"\u2192"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Next slide"})]}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("span",{style:{background:"rgba(255,255,255,0.08)",padding:"5px 8px",borderRadius:"5px",fontSize:"12px",color:"white",border:"1px solid rgba(255,255,255,0.1)"},children:"\u2190"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Previous slide"})]}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("span",{style:{background:"rgba(255,255,255,0.08)",padding:"4px 10px",borderRadius:"5px",fontSize:"11px",color:"#9CA3AF",textTransform:"lowercase",border:"1px solid rgba(255,255,255,0.1)"},children:"space"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Play/Pause"})]}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("span",{style:{background:"rgba(255,255,255,0.08)",padding:"4px 10px",borderRadius:"5px",fontSize:"11px",color:"#9CA3AF",textTransform:"lowercase",border:"1px solid rgba(255,255,255,0.1)"},children:"esc"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Close story"})]}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("span",{style:{background:"rgba(255,255,255,0.08)",padding:"5px 10px",borderRadius:"5px",fontSize:"12px",color:"white",fontWeight:"bold",border:"1px solid rgba(255,255,255,0.1)"},children:"S"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Share story link"})]})]})]})]})]}),L(kt,{config:{enabled:ct?.enabled??!0,image:ct?.image??"",color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:36},onPress:l,style:{position:"relative",borderRadius:"10px"}})]})]})]}),J("div",{style:{display:c?"grid":"flex",gridTemplateColumns:c?"1fr 380px 1fr":"none",alignItems:"center",justifyContent:"center",gap:"12px",flex:1,width:"100%",maxWidth:"1400px",position:"relative"},onClick:j=>c&&j.stopPropagation(),children:[c&&J("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"12px",width:"100%",boxSizing:"border-box"},children:[g>0&&(()=>{let j=F.slides[g-1];if(!j)return null;let G=j.styling,X=G?.editorSource||G?.meta?.editorSource,vt=X==="studio"||X==="editor"?G?.background?.media?.mediaUrl:j.image;return J("div",{style:wt,onClick:Y,children:[L(bt,{src:vt||F.thumbnail}),L("div",{style:{position:"absolute",top:0,bottom:0,left:0,right:0,background:"rgba(0,0,0,0.2)",backdropFilter:"blur(1px)"}})]})})(),g>0&&L("button",{onClick:Y,style:{background:"rgba(255,255,255,0.15)",border:"1px solid rgba(255,255,255,0.2)",color:"white",borderRadius:"50%",width:"40px",height:"40px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:"18px",backdropFilter:"blur(5px)",transition:"background 0.2s"},onMouseEnter:j=>j.currentTarget.style.background="rgba(255,255,255,0.25)",onMouseLeave:j=>j.currentTarget.style.background="rgba(255,255,255,0.15)",children:"\u2039"})]}),J("div",{style:at,onClick:j=>j.stopPropagation(),children:[!c&&L("div",{style:{position:"absolute",top:"0px",left:"0px",right:"0px",display:"flex",gap:"4px",padding:"10px",zIndex:10},children:F.slides.map((j,G)=>{let X="0%";return G<g?X="100%":G===g&&(X=`${x}%`),L("div",{style:{flex:1,height:"3px",backgroundColor:"rgba(255,255,255,0.3)",borderRadius:"2px",overflow:"hidden"},children:L("div",{style:{width:X,height:"100%",backgroundColor:"white",transition:G===g?"width 0.1s linear":"none"}})},G)})}),!c&&J("div",{style:{position:"absolute",top:"20px",left:"10px",right:"10px",display:"flex",alignItems:"center",justifyContent:"space-between",zIndex:10,padding:"5px"},children:[J("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[L(bt,{src:F.thumbnail,alt:F.name,style:{width:"32px",height:"32px",borderRadius:"50%"}}),L("span",{style:{color:"white",fontWeight:"bold",fontSize:"14px",textShadow:"0 1px 3px rgba(0,0,0,0.8)"},children:F.name})]}),J("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[L(so,{config:{size:32,color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},image:""},onPress:rt,type:u?"mute":"unmute",enabled:!!q?.enabled&&!!D,style:{position:"relative",borderRadius:"10px"}}),L(kt,{config:{enabled:ct?.enabled!==!1,image:"",color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:32},onPress:l,style:{position:"relative",borderRadius:"10px"}})]})]}),L("div",{style:{position:"absolute",top:0,bottom:0,left:0,width:"30%",zIndex:5,cursor:"pointer"},onMouseDown:dt,onMouseUp:()=>M("prev"),onTouchStart:dt,onTouchEnd:()=>M("prev")}),L("div",{style:{position:"absolute",top:0,bottom:0,right:0,width:"70%",zIndex:4,cursor:"pointer"},onMouseDown:dt,onMouseUp:()=>M("next"),onTouchStart:dt,onTouchEnd:()=>M("next")}),(()=>{let j=Ft(C?.background)||"#000000";return J("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",background:P?j:"#000",position:"relative",width:"100%",maxHeight:c?"none":"100%",aspectRatio:"1080 / 1920",overflow:"hidden",borderRadius:c?"16px":"0",boxShadow:c?"0 12px 36px rgba(0,0,0,0.4)":"none"},children:[D?L("video",{ref:d,src:D,autoPlay:!0,playsInline:!0,muted:u,onLoadedData:N,style:{width:"100%",height:"100%",objectFit:"cover"}}):(B||!P&&F?.thumbnail)&&L(bt,{src:B||F?.thumbnail,alt:"Story content",style:{width:"100%",height:"100%",objectFit:P?"contain":"cover"}}),L(wn,{content:{...A.content,styling:{...A.content?.styling,...A?.styling},interactions:A.interactions},elapsedTime:x/100*(F.styling?.slideShowTime||5),onInteraction:async X=>{y(!0);let{type:Pt,questionId:vt,pollId:Fe,quizId:Jn,optionId:Kn,value:Xn,stickerId:Zn}=X,ae=Pt?.split("_")[0]||"interaction";ae==="quizz"&&(ae="quiz"),Pt?.startsWith("image_quiz")&&(ae="quiz");let ti=Zn||vt||Fe||Jn||A.id,ei=Kn||X.selected_option||"",vo=z.getState(),oi=vo.userId||"anonymous",ni=vo.trackingUrl||"https://tracking.appstorys.co",ko=await it(),ii={user_id:oi,campaign_id:o,event:"interaction",metadata:{interaction_type:ae,interaction_id:ti,slide_id:A.id,selected_option:String(ei),value:String(Xn||"")}};fetch(`${ni}/capture-event`,{method:"POST",headers:{"Content-Type":"application/json",...ko?{Authorization:`Bearer ${ko}`}:{}},body:JSON.stringify(ii)}).catch(ri=>console.error("AppStorys: Instant Tracking Failed",ri))}})]})})(),(_||$)&&L(Tn,{cta:A?.styling?.cta,buttonText:_||"Learn More",onPress:j=>{j&&j.stopPropagation&&j.stopPropagation(),U(A)}})]}),c&&J("div",{style:{display:"flex",justifyContent:"flex-start",alignItems:"center",gap:"12px",width:"100%",boxSizing:"border-box"},children:[g<F.slides.length-1&&L("button",{onClick:W,style:{background:"rgba(255,255,255,0.15)",border:"1px solid rgba(255,255,255,0.2)",color:"white",borderRadius:"50%",width:"40px",height:"40px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:"18px",backdropFilter:"blur(5px)",transition:"background 0.2s"},onMouseEnter:j=>j.currentTarget.style.background="rgba(255,255,255,0.25)",onMouseLeave:j=>j.currentTarget.style.background="rgba(255,255,255,0.15)",children:"\u203A"}),(()=>{let G=g<F.slides.length-1?F.slides[g+1]:null;if(!G)return null;let X=G.styling,Pt=X?.editorSource||X?.meta?.editorSource,Fe=Pt==="studio"||Pt==="editor"?X?.background?.media?.mediaUrl:G.image;return J("div",{style:wt,onClick:W,children:[L(bt,{src:Fe||F.thumbnail}),L("div",{style:{position:"absolute",top:0,bottom:0,left:0,right:0,background:"rgba(0,0,0,0.2)",backdropFilter:"blur(1px)"}})]})})()]}),c&&e>0&&J("div",{style:{position:"absolute",bottom:"40px",left:"40px",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"5px",zIndex:20},children:[L("span",{style:{fontSize:"11px",fontWeight:"bold",color:"rgba(255,255,255,0.75)",letterSpacing:"0.4px",paddingLeft:"2px"},children:"Previous Stories"}),J("div",{style:{background:"rgba(255, 255, 255, 0.06)",padding:"8px 14px",borderRadius:"14px",display:"flex",alignItems:"center",gap:"12px",backdropFilter:"blur(16px)",cursor:"pointer",boxShadow:"0 8px 16px rgba(0, 0, 0, 0.25)",transition:"all 0.2s",maxWidth:"280px"},onClick:a,children:[L("span",{style:{color:"white",fontSize:"15px",fontWeight:"normal"},children:"\u2190"}),L("div",{style:{width:"40px",height:"40px",borderRadius:"50%",border:"2px solid white",display:"flex",alignItems:"center",justifyContent:"center",background:"white",flexShrink:0},children:L(bt,{src:t[e-1].thumbnail,style:{width:"36px",height:"36px",borderRadius:"50%"}})}),L("span",{style:{fontSize:"14px",color:"white",fontWeight:"500",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:t[e-1].name})]})]}),c&&e<t.length-1&&J("div",{style:{position:"absolute",bottom:"40px",right:"40px",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"5px",zIndex:20},children:[L("span",{style:{fontSize:"11px",fontWeight:"bold",color:"rgba(255,255,255,0.75)",letterSpacing:"0.4px",paddingLeft:"2px"},children:"Next Stories"}),J("div",{style:{background:"rgba(255, 255, 255, 0.06)",padding:"8px 14px",borderRadius:"14px",display:"flex",alignItems:"center",gap:"12px",backdropFilter:"blur(16px)",cursor:"pointer",boxShadow:"0 8px 16px rgba(0, 0, 0, 0.25)",transition:"all 0.2s",maxWidth:"280px"},onClick:r,children:[L("div",{style:{width:"40px",height:"40px",borderRadius:"50%",border:"2px solid white",display:"flex",alignItems:"center",justifyContent:"center",background:"white",flexShrink:0},children:L(bt,{src:t[e+1].thumbnail,style:{width:"36px",height:"36px",borderRadius:"50%"}})}),L("span",{style:{fontSize:"14px",color:"white",fontWeight:"500",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:t[e+1].name}),L("span",{style:{color:"white",fontSize:"15px",fontWeight:"normal"},children:"\u2192"})]})]}),T&&L("div",{style:{position:"absolute",bottom:"40px",left:"50%",transform:"translateX(-50%)",background:"rgba(20, 20, 20, 0.96)",border:"1px solid rgba(255,255,255,0.08)",padding:"12px 24px",borderRadius:"12px",color:"white",fontSize:"13px",fontWeight:"500",boxShadow:"0 10px 20px rgba(0,0,0,0.5)",backdropFilter:"blur(10px)",zIndex:1e3},children:T})]})]})};import{jsx as En,jsxs as cr}from"react/jsx-runtime";var dr=()=>{let t=lt("STR"),e=z(p=>p.isVisible),[o,i]=An(null),[n,r]=An([]);if(Pn(()=>{try{let p=localStorage.getItem("app_storys_viewed_stories");p&&r(JSON.parse(p))}catch(p){console.error("Failed to load viewed stories:",p)}},[]),Pn(()=>{t&&t.details&&V("story_module_viewed",t.id)},[t]),!t||!t.details||t.details.length===0||!e)return null;let a=p=>{i(p);let x=t.details[p];V("story_opened",t.id,{story_id:x.id,story_name:x.name})},l=()=>{o!==null&&(o<t.details.length-1?i(o+1):i(null))},g=()=>{o!==null&&o>0&&i(o-1)};return cr("div",{className:"story-group-container",style:{width:"100vw",position:"relative",left:"50%",right:"50%",marginLeft:"-50vw",marginRight:"-50vw",boxSizing:"border-box"},children:[En(Qo,{stories:t.details,viewedStories:n,onStoryClick:a}),o!==null&&En(Bn,{stories:t.details,activeStoryIndex:o,dataId:t.id,viewedStories:n,setViewedStories:r,onNextStory:l,onPrevStory:g,onClose:()=>i(null)})]})};import{useState as pr,useRef as lo,useEffect as co}from"react";import{createPortal as ur}from"react-dom";K();import{jsx as At,jsxs as fr}from"react/jsx-runtime";var gr=({position:t})=>{let e=lt("WID",{position:t}),o=z(s=>s.campaigns),i=z(s=>s.allCampaigns),n=z(s=>s.currentScreen),r=s=>(s||"").trim().toLowerCase(),a=e??(()=>{let s=r(n),d=[...o||[],...i||[]].find(E=>{let F=E;if(F.campaign_type!=="WID"||t&&F.position!==t)return!1;let A=!!(F.trigger_event??F.trigger),C=F.display_trigger!==!1&&!A,R=!r(F.screen)||r(F.screen)===s;return C&&R});if(d)try{return ut(d)}catch{return d}})(),[l,g]=pr(0),p=lo(null),x=lo(null),m=a?.details||{},u=m.widget_images||[],v=m.styling||{},f=m.type||"full",b=f==="half",h=lo([]),y=s=>{!a?.id||!s||h.current.includes(s)||(h.current.push(s),V("viewed",a.id,{widget_image:s}))};co(()=>{if(f==="full"&&u.length>1)return x.current=setInterval(()=>{g(s=>{let d=s+1;return d>=u.length?0:d})},5e3),()=>{x.current&&clearInterval(x.current)}},[f,u.length]);let k=(s,d)=>{if(a?.id&&V("clicked",a.id,{widget_image:s}),d){if(!d.startsWith("http")){try{if(gt(d))return}catch(E){console.warn("[Widget] revealCampaignFromLink error",E)}console.log("[Widget] Internal link:",d);return}window.open(d,"_blank")}},S=()=>{if(p.current&&b){let{scrollLeft:s,offsetWidth:d}=p.current,E=d/2+12,F=Math.round(s/E);g(F)}};co(()=>{if(!a?.id||f!=="full"||u.length===0)return;let s=u[l];s&&s.id&&y(s.id)},[l,a?.id,u,f]),co(()=>{if(!a?.id||!p.current||!b)return;let s=p.current,d=()=>{let{scrollLeft:E,offsetWidth:F}=s,A=F/2+12;u.forEach((C,R)=>{let P=R*A,B=P+A,_=E,$=E+F;Math.max(0,Math.min(B,$)-Math.max(P,_))/A>=.5&&y(C.id)})};return d(),s.addEventListener("scroll",d),()=>s.removeEventListener("scroll",d)},[a?.id,b,u]);let T={display:"flex",flexDirection:"row",flexWrap:b?"nowrap":"wrap",gap:"12px",width:"100%",height:b&&m.height?`${m.height}px`:"auto",marginTop:v.topMargin?`${v.topMargin}px`:"0px",marginBottom:v.bottomMargin?`${v.bottomMargin}px`:"0px",marginLeft:v.leftMargin?`${v.leftMargin}px`:"0px",marginRight:v.rightMargin?`${v.rightMargin}px`:"0px",boxSizing:"border-box",overflowX:b?"auto":"hidden",overflowY:"hidden",scrollSnapType:b?"x mandatory":void 0,msOverflowStyle:"none",scrollbarWidth:"none"},I=s=>({flex:b?"0 0 calc(50% - 6px)":"0 0 100%",height:b&&m.height?`${m.height}px`:"auto",cursor:"pointer",position:"relative",overflow:"hidden",borderRadius:v.borderRadius?`${v.borderRadius}px`:"0px",borderTopLeftRadius:v.topLeftRadius?`${v.topLeftRadius}px`:void 0,borderTopRightRadius:v.topRightRadius?`${v.topRightRadius}px`:void 0,borderBottomLeftRadius:v.bottomLeftRadius?`${v.bottomLeftRadius}px`:void 0,borderBottomRightRadius:v.bottomRightRadius?`${v.bottomRightRadius}px`:void 0,boxShadow:"0 4px 12px rgba(0,0,0,0.08)",scrollSnapAlign:"start"}),c=fr("div",{style:{width:"100%",position:"relative"},children:[At("style",{children:`
|
|
76
|
+
.widget-scroll-container::-webkit-scrollbar {
|
|
77
|
+
display: none;
|
|
78
|
+
}
|
|
79
|
+
`}),At("div",{ref:p,className:"widget-scroll-container",style:T,onScroll:S,children:b?u.map((s,d)=>At("div",{style:I(d),children:At("img",{src:s.image,alt:"widget",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"},onClick:()=>k(s.id,s.link)})},s.id)):u.length>0&&At("div",{style:I(0),children:At("img",{src:u[l].image,alt:"widget",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"},onClick:()=>k(u[l].id,u[l].link)})},`slide-${l}`)}),f==="full"&&u.length>1&&At("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"8px",width:"100%"},children:u.map((s,d)=>At("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:d===l?"#333":"#ccc",transition:"background-color 0.2s ease"}},d))})]}),w=null;if(a?.position){let s=String(a.position||"").replace(/^widget_/,""),d=[`[data-as-id="${s}"]`,`#${s}`,`.${s}`,`[data-widget="${s}"]`];for(let E of d)try{let F=document.querySelector(E);if(F){w=F,console.log("[Widget] Portal target found:",E,"for campaign",a?.id);break}}catch{}w||console.log("[Widget] No portal target found for position:",a?.position,"rendering inline for campaign:",a?.id)}return w?ur(c,w):c};import{useEffect as po,useLayoutEffect as mr,useMemo as Ln,useRef as uo,useState as ve}from"react";K();import{Fragment as br,jsx as Ht,jsxs as Dn}from"react/jsx-runtime";var go=t=>(t||"").trim().toLowerCase(),yr=()=>{let t=lt("TTP"),e=z(N=>N.campaigns),o=z(N=>N.allCampaigns),i=z(N=>N.currentScreen),n=z(N=>N.isVisible),[r,a]=ve(0),[l,g]=ve(!1),[p,x]=ve(null),[m,u]=ve({width:0,height:0}),v=uo(null),f=uo(null),b=Ln(()=>{if(t)return t;let N=go(i),U=rt=>rt.find(ct=>{let q=ct,Q=q.campaign_type==="TTP"||q.campaign_type==="TLTP",st=!go(q.screen)||go(q.screen)===N,pt=!!(q.trigger_event??q.trigger),ft=q.display_trigger!==!1&&!pt;return Q&&st&&ft});return U(e)??U(o)},[t,e,o,i]),h=Ln(()=>b?.details?.tooltips&&Array.isArray(b.details.tooltips)?[...b.details.tooltips].sort((N,U)=>(N.order??0)-(U.order??0)):b?.details?.target||b?.details?.titleText?[{...b.details,_id:b.id}]:[],[b]),y=h[r];po(()=>{},[b]);let k=uo(new Set);if(po(()=>{if(!(!b||!y||!p||l||!n))try{let N=y._id||y.id||void 0,U=String(b.id||"")+"::"+String(N||"");k.current.has(U)||(k.current.add(U),V("viewed",b.id,{tooltip_id:N}))}catch{}},[b,y,p,l,n]),po(()=>{if(!y?.target||l)return;x(null);let N=(ct=!1)=>{let q=y.target;if(!q)return null;let Q=document.getElementById(q)||document.querySelector(`[data-id="${q}"]`)||document.querySelector(`.${q}`);return Q?(x(Q.getBoundingClientRect()),ct&&Q.scrollIntoView({behavior:"smooth",block:"center"}),Q):null};N(!0)||(f.current=new MutationObserver(()=>{N(!0)&&f.current?.disconnect()}),f.current.observe(document.body,{childList:!0,subtree:!0}));let rt=()=>{let ct=N(!1);ct&&x(ct.getBoundingClientRect())};return window.addEventListener("resize",rt),window.addEventListener("scroll",rt,{passive:!0}),()=>{f.current?.disconnect(),window.removeEventListener("resize",rt),window.removeEventListener("scroll",rt)}},[y,l,r]),mr(()=>{if(v.current&&p){let{width:N,height:U}=v.current.getBoundingClientRect();u({width:N,height:U})}},[y,p]),!b||!y||l||!n||!p)return null;let S=y.styling||{},T=S.appearance||{},I=T.colors||{},c=S.cta||{},w=c.container||{},s=c.cornerRadius||{},d=c.text||{},E=y.arrowPosition||"left",A=(T.arrowStyle||{width:6,height:12}).width||6,C=p.top+window.scrollY,R=p.left+window.scrollX,P=0,B=0,_=8;E==="left"?(P=R+p.width+_,B=C+p.height/2-m.height/2):E==="right"?(P=R-m.width-_,B=C+p.height/2-m.height/2):E==="top"?(B=C+p.height+_,P=R+p.width/2-m.width/2):E==="bottom"&&(B=C-m.height-_,P=R+p.width/2-m.width/2);let $=8,D=window.scrollY,O=window.scrollY+window.innerHeight,W=window.scrollX,Y=window.scrollX+window.innerWidth;m.height>0&&(B=Math.max(D+$,Math.min(O-m.height-$,B))),m.width>0&&(P=Math.max(W+$,Math.min(Y-m.width-$,P)));let dt=()=>{let N=y.clickAction||"nextStep",U=y.link||y.url;try{let rt=y._id||y.id||void 0;b?.id&&V("clicked",b.id,{tooltip_id:rt})}catch{}if(N==="close"){g(!0),U&&window.open(U,"_blank");return}r<h.length-1?a(rt=>rt+1):(g(!0),U&&window.open(U,"_blank"))},M=()=>{y.enableBackdrop&&g(!0)};return Dn(br,{children:[y.enableBackdrop&&Ht("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:I.backdrop||"rgba(0, 0, 0, 0.7)",opacity:T.backdropOpacity?T.backdropOpacity/100:.7,zIndex:1e4},onClick:M}),Dn("div",{ref:v,style:{position:"absolute",top:B,left:P,zIndex:10001,backgroundColor:I.tooltip||"#FE6B35",padding:`${T.padding?.top??8}px ${T.padding?.right??8}px ${T.padding?.bottom??8}px ${T.padding?.left??8}px`,borderRadius:`${T.cornerRadius?.topLeft??12}px ${T.cornerRadius?.topRight??12}px ${T.cornerRadius?.bottomRight??12}px ${T.cornerRadius?.bottomLeft??12}px`,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",maxWidth:300,minWidth:200,transition:"top 0.2s ease, left 0.2s ease"},children:[Ht("div",{style:{position:"absolute",width:0,height:0,borderStyle:"solid",...E==="left"&&{left:-_,top:Math.max(12,Math.min(m.height-A*2-12,C+p.height/2-B-A)),borderWidth:`${A}px ${_}px ${A}px 0`,borderColor:`transparent ${I.tooltip||"#FE6B35"} transparent transparent`},...E==="right"&&{right:-_,top:Math.max(12,Math.min(m.height-A*2-12,C+p.height/2-B-A)),borderWidth:`${A}px 0 ${A}px ${_}px`,borderColor:`transparent transparent transparent ${I.tooltip||"#FE6B35"}`},...E==="top"&&{top:-_,left:Math.max(12,Math.min(m.width-A*2-12,R+p.width/2-P-A)),borderWidth:`0 ${A}px ${_}px ${A}px`,borderColor:`transparent transparent ${I.tooltip||"#FE6B35"} transparent`},...E==="bottom"&&{bottom:-_,left:Math.max(12,Math.min(m.width-A*2-12,R+p.width/2-P-A)),borderWidth:`${_}px ${A}px 0 ${A}px`,borderColor:`${I.tooltip||"#FE6B35"} transparent transparent transparent`}}}),y.titleText&&Ht("div",{style:{color:S.title?.color||"#ffffff",fontFamily:S.title?.fontFamily||"Arial",fontSize:S.title?.fontSize||14,textAlign:S.title?.textAlign||"center",marginBottom:S.title?.margin?.bottom??4,marginTop:S.title?.margin?.top??0,marginLeft:S.title?.margin?.left??0,marginRight:S.title?.margin?.right??0,fontWeight:S.title?.fontDecoration?.includes("bold")?"bold":600,fontStyle:S.title?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:S.title?.fontDecoration?.includes("underline")?"underline":"none"},children:y.titleText}),y.subtitleText&&Ht("div",{style:{color:S.subTitle?.color||"#ffffff",fontFamily:S.subTitle?.fontFamily||"Arial",fontSize:S.subTitle?.fontSize||12,textAlign:S.subTitle?.textAlign||"center",marginBottom:S.subTitle?.margin?.bottom??8,marginTop:S.subTitle?.margin?.top??0,marginLeft:S.subTitle?.margin?.left??0,marginRight:S.subTitle?.margin?.right??0,fontWeight:S.subTitle?.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:S.subTitle?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:S.subTitle?.fontDecoration?.includes("underline")?"underline":"none"},children:y.subtitleText}),y.ctaText&&Ht("div",{style:{display:"flex",justifyContent:w.alignment==="right"?"flex-end":w.alignment==="left"?"flex-start":"center",marginTop:8},children:Ht("button",{onClick:dt,style:{width:w.ctaFullWidth?"100%":w.ctaWidth||"auto",height:w.height||35,background:w.backgroundColor||"#F7921C",color:d.color||"#ffffff",border:`${w.borderWidth||0}px solid ${w.borderColor||"transparent"}`,borderRadius:`${s.topLeft??7}px ${s.topRight??7}px ${s.bottomRight??7}px ${s.bottomLeft??7}px`,fontSize:d.fontSize||14,fontFamily:d.fontFamily||"Arial",fontWeight:d.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:d.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:d.fontDecoration?.includes("underline")?"underline":"none",cursor:"pointer",padding:"0 12px",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:y.ctaText})})]})]})},hr=yr;import{useEffect as xr,useState as Sr}from"react";K();import{Fragment as vr,jsx as St,jsxs as fo}from"react/jsx-runtime";var Cr=()=>{let t=lt("BTS"),e=z(f=>f.campaigns),o=z(f=>f.allCampaigns),i=z(f=>f.currentScreen),n=t??(()=>{let f=(i||"").trim().toLowerCase(),b=[...e||[],...o||[]].find(h=>{if(!h||h.campaign_type!=="BTS")return!1;let y=!!(h.trigger_event??h.trigger);if(!(h.display_trigger!==!1&&!y))return!1;let S=(h.screen||"").trim().toLowerCase();return!S||S===f});if(b)try{return ut(b)}catch{return b}})(),r=z(f=>f.isVisible),[a,l]=Sr(!1);xr(()=>{n&&(l(!1),V("viewed",n.id))},[n]);let g=f=>{try{let b=z.getState(),y=(b.trackedEvents||[]).filter(k=>k!==f);b.setTrackedEvents(y)}catch{}};if(!n||a||!r)return null;let{details:p}=n,m=[...p.elements||[]].sort((f,b)=>(f.order||0)-(b.order||0)),u=p.backdropOpacity??.5;u>1&&(u=u/100);let v=f=>{switch(f.type){case"image":{let b={width:"100%",display:"block",objectFit:"contain",backgroundColor:f.imageBackgroundColor||"transparent",paddingBottom:f.paddingBottom??0,paddingLeft:f.paddingLeft??0,paddingRight:f.paddingRight??0,paddingTop:f.paddingTop??0,cursor:f.imageLink?"pointer":"default"};return St("div",{style:{textAlign:f.alignment||"left",width:"100%"},children:f.url&&St("img",{src:f.url,alt:"",style:b,onClick:()=>{if(f.imageLink){n?.id&&V("clicked",n.id);try{let h=String(f.imageLink||"").trim();if(h&&!h.startsWith("http")&>(h))return}catch(h){console.warn("revealCampaignFromLink error",h)}try{window.open(f.imageLink,"_blank")}catch{}}}})},f.id)}case"cta":{let b=f.cta||{},h=b.container||{},y=b.cornerRadius||{},k=b.margin||{},S=b.text||{};return St("div",{style:{display:"flex",justifyContent:h.alignment==="center"?"center":h.alignment==="right"?"flex-end":"flex-start",width:"100%",marginTop:k.top??0,marginBottom:k.bottom??0,marginLeft:k.left??0,marginRight:k.right??0},children:St("button",{style:{width:h.ctaFullWidth?"100%":h.ctaWidth||"auto",height:h.height||45,backgroundColor:h.ctaBoxColor||h.backgroundColor||"#FE6B35",color:S.color||"#ffffff",border:`${h.borderWidth||0}px solid ${h.borderColor||"transparent"}`,borderRadius:`${y.topLeft??12}px ${y.topRight??12}px ${y.bottomRight??12}px ${y.bottomLeft??12}px`,fontSize:S.fontSize||14,fontFamily:S.fontFamily||"Arial",fontWeight:S.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:S.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:S.fontDecoration?.includes("underline")?"underline":"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 16px"},onClick:()=>{let T=f.ctaLink||f.url;if(T){n?.id&&V("clicked",n.id);try{let I=String(T||"").trim();if(I&&!I.startsWith("http")&>(I))return}catch(I){console.warn("revealCampaignFromLink error",I)}try{window.open(T,"_blank")}catch{}}},children:f.ctaText||"Button"})},f.id)}case"body":{let b=f.titleFontStyle||{},h=f.descriptionFontStyle||{};return fo("div",{style:{width:"100%",backgroundColor:f.bodyBackgroundColor||"transparent",marginTop:f.marginTop??0,marginBottom:f.marginBottom??20,marginLeft:f.marginLeft??4,marginRight:f.marginRight??4},children:[f.titleText&&St("div",{style:{color:b.colour||"#000000",fontSize:b.fontSize?`${b.fontSize}px`:f.titleFontSize?`${f.titleFontSize}px`:"16px",fontFamily:b.fontFamily||"inherit",textAlign:b.alignment||"left",lineHeight:f.titleLineHeight||1.2,fontWeight:b.decoration?.includes("bold")?"bold":"600",fontStyle:b.decoration?.includes("italic")?"italic":"normal",textDecoration:b.decoration?.includes("underline")?"underline":"none",marginBottom:f.spacingBetweenTitleDesc??4},children:f.titleText}),f.descriptionText&&St("div",{style:{color:h.colour||"#000000",fontSize:h.fontSize?`${h.fontSize}px`:f.descriptionFontSize?`${f.descriptionFontSize}px`:"14px",fontFamily:h.fontFamily||"inherit",textAlign:h.alignment||"left",lineHeight:f.descriptionLineHeight||1.5,fontWeight:h.decoration?.includes("bold")?"bold":"normal",fontStyle:h.decoration?.includes("italic")?"italic":"normal",textDecoration:h.decoration?.includes("underline")?"underline":"none"},children:f.descriptionText})]},f.id)}default:return null}};return fo(vr,{children:[St("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:p.backdropColor||"rgba(0,0,0,0.5)",opacity:u,zIndex:999998,transition:"opacity 0.3s ease"},onClick:()=>{n?.id&&g(`viaAppStorys${n.id}`),l(!0)}}),fo("div",{style:{position:"fixed",bottom:0,left:"50%",transform:"translateX(-50%)",width:"100%",maxWidth:"500px",backgroundColor:p.backgroundColor||"#FFFFFF",borderTopLeftRadius:`${p.cornerRadius?.topLeft??16}px`,borderTopRightRadius:`${p.cornerRadius?.topRight??16}px`,borderBottomLeftRadius:`${p.cornerRadius?.bottomLeft??0}px`,borderBottomRightRadius:`${p.cornerRadius?.bottomRight??0}px`,zIndex:999999,padding:"24px 16px",boxShadow:"0 -4px 16px rgba(0,0,0,0.15)",maxHeight:"85vh",overflowY:"auto",display:"flex",flexDirection:"column",alignItems:"center",transition:"transform 0.3s ease-out"},children:[St("div",{style:{width:"40px",height:"5px",backgroundColor:"#E0E0E0",borderRadius:"2.5px",marginBottom:"16px",cursor:"pointer"},onClick:()=>l(!0)}),p.crossButton?.enabled&&St(kt,{config:p.crossButton,onPress:()=>{n?.id&&g(`viaAppStorys${n.id}`),l(!0)},style:{top:p.crossButton?.margin?.top??12,right:p.crossButton?.margin?.right??12}}),St("div",{style:{width:"100%",display:"flex",flexDirection:"column",gap:"12px"},children:m.map(v)})]})]})};import{useEffect as kr,useMemo as wr,useState as Vt}from"react";K();import{Fragment as bo,jsx as Z,jsxs as ne}from"react/jsx-runtime";var Wn=5,mo=3;function Ct(t){if(t!=null)return`${t}px`}function oe(t){return{marginTop:Ct(t?.top),marginRight:Ct(t?.right),marginBottom:Ct(t?.bottom),marginLeft:Ct(t?.left)}}function xo(t){if(t&&!(t.startsWith("http://")||t.startsWith("https://")))return t}function Yt(t){return t?{color:t.color,fontSize:t.fontSize,fontFamily:xo(t.fontFamily),textAlign:t.textAlign,fontWeight:t.fontDecoration?.includes("bold")?"bold":void 0,fontStyle:t.fontDecoration?.includes("italic")?"italic":void 0,textDecoration:t.fontDecoration?.includes("underline")?"underline":void 0}:{}}function yo(t){return`${t?.topLeft??8}px ${t?.topRight??8}px ${t?.bottomRight??8}px ${t?.bottomLeft??8}px`}function Rr(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function Tr(t){let e=t.styling?.rating?.ratingType;return e==="number"||e==="emoji"||e==="star"?e:"star"}function zr(t){let e=t.styling?.rating?.emoji;if(Array.isArray(e))return e.filter(o=>typeof o=="string"&&o.trim().length>0);if(e&&typeof e=="object"){let o=Object.values(e).filter(i=>typeof i=="string"&&i.trim().length>0);if(o.length>0)return o}if(typeof e=="string"&&e.trim()){if(e.includes(",")){let o=e.split(",").map(i=>i.trim()).filter(Boolean);if(o.length>0)return o}return[e]}return["\u{1F620}","\u{1F615}","\u{1F610}","\u{1F642}","\u{1F60D}"]}function Fr(t){return Array.from({length:5},(e,o)=>o+1)}function ho(t){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;if(typeof t=="string"&&t.trim().length>0){let e=Number(t);if(Number.isFinite(e)&&e>=0)return e}}function Ir(t){let e=t.styling?.rating||void 0,o=[e?.numberSpacing,e?.numberGap,e?.number_spacing,e?.number_gap,e?.spacingBetweenNumbers,e?.spaceBetweenNumbers,e?.numberOptionsSpacing];for(let n of o){let r=ho(n);if(r!=null)return r}let i=e?.number;if(i&&typeof i=="object"){let n=i,r=[n.spacing,n.gap,n.optionsSpacing,n.numberSpacing,n.numberGap];for(let a of r){let l=ho(a);if(l!=null)return l}}return 8}var Br=({fill:t,stroke:e})=>Z("svg",{viewBox:"0 0 24 24",width:"22",height:"22","aria-hidden":!0,children:Z("path",{d:"M12 2.25l2.91 5.89 6.5.95-4.7 4.58 1.11 6.46L12 17.03 6.18 20.13l1.11-6.46-4.7-4.58 6.5-.95L12 2.25z",fill:t,stroke:e,strokeWidth:"1.4",strokeLinejoin:"round"})}),Ar=({details:t,appearance:e,rating:o,selectedOptions:i,comments:n,isHighRating:r,feedbackOptions:a,onRate:l,onToggleOption:g,onCommentChange:p,onInlineSubmit:x,canSubmit:m})=>{let u=t.styling||{},v=u.feedbackPage||{},f=u.rating||{},b=u.initialFeedback||{},h=v.submitButton?.cta,y=Tr(t),k=y==="number"?Fr(t):[],S=y==="emoji"?zr(t):[],T=y==="number"?Ir(t):8,I=r?f.star?.high:f.star?.low;return ne(bo,{children:[Z("div",{style:oe(b.title?.margin),children:Z("div",{style:{...Yt(b.title?.textStyle),color:b.title?.textStyle?.color||"#101828",fontSize:b.title?.textStyle?.fontSize||20,lineHeight:1.3},children:t.title||"How was your experience?"})}),Z("div",{style:oe(b.subtitle?.margin),children:Z("div",{style:{...Yt(b.subtitle?.textStyle),color:b.subtitle?.textStyle?.color||"#4b5563",fontSize:b.subtitle?.textStyle?.fontSize||14,lineHeight:1.4},children:t.description_text||"Your feedback helps us improve your experience."})}),ne("div",{style:{marginTop:8,display:"flex",justifyContent:"center",gap:y==="number"?T:8,flexWrap:"wrap"},children:[y==="star"&&Array.from({length:Wn},(c,w)=>{let s=w+1,d=s<=o,E=d?I?.stylingContainer:f.star?.unselected?.stylingContainer,F=d?I?.stylingStar:f.star?.unselected?.stylingStar;return Z("button",{onClick:()=>l(s),style:{border:`${E?.borderWidth??1}px solid ${E?.border||"#d1d5db"}`,background:E?.background||"#ffffff",borderRadius:10,width:44,height:44,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},"aria-label":`Rate ${s} out of ${Wn}`,children:Z(Br,{fill:F?.background||(d?"#f59e0b":"#e5e7eb"),stroke:F?.border||(d?"#d97706":"#9ca3af")})},s)}),y==="number"&&k.map((c,w)=>{let s=c===o;return Z("button",{onClick:()=>l(c),style:{border:`1px solid ${s?"#1d4ed8":"#d1d5db"}`,background:s?"#dbeafe":"#ffffff",color:s?"#1d4ed8":"#111827",borderRadius:8,minWidth:36,height:36,padding:"0 10px",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontWeight:600},"aria-label":`Rate ${c}`,children:c},`${c}-${w}`)}),y==="emoji"&&S.map((c,w)=>{let s=w+1,d=s===o;return Z("button",{onClick:()=>l(s),style:{border:`1px solid ${d?"#1d4ed8":"#d1d5db"}`,background:d?"#dbeafe":"#ffffff",borderRadius:"999px",width:44,height:44,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:22},"aria-label":`Emoji rating ${w+1}`,children:c},`${c}-${w}`)})]}),o>0&&Z("div",{style:{marginTop:6,textAlign:"center",color:"#374151",fontSize:14},children:r?t.highStarText||f.highRatingSubtitle:t.lowStarText||f.lowRatingSubtitle}),o>0&&o<=mo&&ne(bo,{children:[a.length>0&&Z("div",{style:{...oe(v.options?.margin),display:"flex",flexDirection:"column",alignItems:"stretch",gap:v.options?.optionsSpacing??8,width:"100%"},children:a.map(c=>{let s=i.includes(c)?v.options?.selectedOptions:v.options?.nonSelectedOptions;return Z("button",{onClick:()=>g(c),style:{border:`${s?.borderWidth??1}px solid ${s?.colors?.border||"#d1d5db"}`,background:s?.colors?.background||"#f9fafb",color:s?.colors?.text||"#111827",width:"100%",height:v.options?.optionsHeight||38,borderRadius:yo(v.options?.cornerRadius),padding:"0 14px",cursor:"pointer",textAlign:"center",...Yt(s?.textStyle)},children:c},c)})}),Z("textarea",{value:n,onChange:c=>p(c.target.value),placeholder:v.additionalComments?.placeholder||"Tell us what we can improve",style:{width:"100%",boxSizing:"border-box",minHeight:56,height:56,maxHeight:64,marginTop:8,resize:"none",overflowY:"auto",border:`${v.additionalComments?.borderWidth??1}px solid ${v.additionalComments?.colors?.border||"#d1d5db"}`,background:v.additionalComments?.colors?.background||"#ffffff",color:v.additionalComments?.colors?.text||"#111827",borderRadius:8,padding:"12px",...Yt(v.additionalComments?.textStyle)}}),Z("div",{style:{position:"sticky",bottom:0,marginTop:8,paddingTop:6,paddingBottom:6,background:e?.backgroundColor||"#2f6ef5",display:"flex",justifyContent:"center"},children:Z("button",{onClick:()=>x(),disabled:!m,style:{width:Math.max(140,Math.min(ho(h?.container?.ctaWidth)??180,220)),maxWidth:"100%",minHeight:30,height:Math.max(30,Math.min(Number(h?.container?.height)||34,34)),border:`${h?.container?.borderWidth??1}px solid ${h?.container?.borderColor||"#ff7a00"}`,background:h?.container?.backgroundColor||"#ff2bc2",color:h?.text?.color||"#ffffff",borderRadius:yo(h?.cornerRadius),fontFamily:xo(h?.text?.fontFamily),fontSize:Math.min(Number(h?.text?.fontSize)||14,14),fontWeight:h?.text?.fontDecoration?.includes("bold")?"bold":600,cursor:m?"pointer":"not-allowed",opacity:m?1:.65,padding:"0 12px"},children:v.submitButton?.text||"Submit"})})]})]})},Pr=({details:t,isHighRating:e,onDone:o})=>{let i=t.styling||{},n=i.thankyouPage||{},r=i.rating||{},a=Rr(n.doneButton?.cta?.container?.alignment);return ne(bo,{children:[t.thankyouImage&&Z("div",{style:{display:"flex",justifyContent:"center",marginTop:6},children:Z("img",{src:t.thankyouImage,alt:"thank you",style:{width:n.imageStyle?.width||80,height:n.imageStyle?.height||80,objectFit:"cover",borderRadius:8}})}),Z("div",{style:{...oe(n.title?.margin),textAlign:"center"},children:Z("div",{style:{...Yt(n.title?.textStyle),color:n.title?.textStyle?.color||"#111827",fontSize:n.title?.textStyle?.fontSize||20,fontWeight:n.title?.textStyle?.fontDecoration?.includes("bold")?"bold":600},children:t.thankyouText||(e?r.highRatingTitle:r.lowRatingTitle)||"Thank you for your feedback"})}),Z("div",{style:{...oe(n.subtitle?.margin),textAlign:"center"},children:Z("div",{style:{...Yt(n.subtitle?.textStyle),color:n.subtitle?.textStyle?.color||"#4b5563",fontSize:n.subtitle?.textStyle?.fontSize||14},children:t.thankyouDescription||(e?r.highRatingSubtitle:r.lowRatingSubtitle)||"We appreciate your time."})}),Z("div",{style:{marginTop:n.doneButton?.cta?.margin?.top??14,marginBottom:n.doneButton?.cta?.margin?.bottom??0,marginLeft:n.doneButton?.cta?.margin?.left??0,marginRight:n.doneButton?.cta?.margin?.right??0,display:"flex",justifyContent:a},children:Z("button",{onClick:o,style:{width:n.doneButton?.cta?.container?.ctaFullWidth?"100%":n.doneButton?.cta?.container?.ctaWidth||"auto",height:n.doneButton?.cta?.container?.height||45,border:`${n.doneButton?.cta?.container?.borderWidth??0}px solid ${n.doneButton?.cta?.container?.borderColor||"transparent"}`,background:n.doneButton?.cta?.container?.backgroundColor||"#111827",color:n.doneButton?.cta?.text?.color||"#ffffff",borderRadius:yo(n.doneButton?.cta?.cornerRadius),fontFamily:xo(n.doneButton?.cta?.text?.fontFamily),fontSize:n.doneButton?.cta?.text?.fontSize||16,fontWeight:n.doneButton?.cta?.text?.fontDecoration?.includes("bold")?"bold":500,cursor:"pointer",padding:"0 16px"},children:n.doneButton?.text||(e?"Rate Now":"Done")})})]})},Er=()=>{let t=lt("CSAT"),e=z(C=>C.isVisible),o=z(C=>C.campaigns),i=z(C=>C.allCampaigns),n=z(C=>C.currentScreen),r=t??(()=>{let C=(n||"").trim().toLowerCase(),R=[...o||[],...i||[]].find(P=>{if(!P||P.campaign_type!=="CSAT")return!1;let B=!!(P.trigger_event??P.trigger);if(!(P.display_trigger!==!1&&!B))return!1;let $=(P.screen||"").trim().toLowerCase();return!$||$===C});if(R)try{return ut(R)}catch{return R}})(),[a,l]=Vt(!1),[g,p]=Vt(!1),[x,m]=Vt(0),[u,v]=Vt([]),[f,b]=Vt(""),[h,y]=Vt(!1);kr(()=>{if(!r)return;l(!1),p(!1),m(0),v([]),b(""),y(!1);let C=r.details?.styling?.appearance?.displayDelay??0,R=globalThis.setTimeout(()=>{p(!0),V("viewed",r.id)},Math.max(0,C)*1e3);return()=>globalThis.clearTimeout(R)},[r]);let k=wr(()=>{let C=r?.details?.feedback_option||{};return Object.keys(C).sort((R,P)=>R.localeCompare(P)).map(R=>C[R]).filter(Boolean)},[r]);if(!r||!e||a||!g)return null;let S=r.details,T=S.styling||{},I=T.appearance||{},c=x>mo,w=Number(S.width??80),s=Math.max(660,Math.min(1080,w*10)),d=C=>{v(R=>R.includes(C)?R.filter(P=>P!==C):[...R,C])},E=async C=>{let R=C?.rating??x;if(R<1)return;y(!0);let P=S.id||r.id,B=(C?.options??u)[0]||"",_=C?.comments??f??"";V("csat captured",P,{starCount:R,selectedOption:B,additionalComments:_})},F=C=>{if(m(C),C>mo){v([]),b("");let R=S.id||r?.id;setTimeout(()=>{y(!0);try{V("csat captured",R,{starCount:C,selectedOption:"",additionalComments:""})}catch(P){console.warn("Error sending csat captured",P)}},1e3)}},A=()=>{if(c&&S.link){let C=r&&r.id||void 0;try{C&&V("clicked",C)}catch{}try{let R=String(S.link||"").trim();if(R&&!R.startsWith("http")&>(R)){l(!0);return}}catch(R){console.warn("revealCampaignFromLink error",R)}try{globalThis.open(S.link,"_blank")}catch{}}l(!0)};return Z("div",{style:{position:"fixed",left:0,right:0,bottom:0,zIndex:999999,display:"flex",justifyContent:"center",alignItems:"flex-end",paddingLeft:"10px",paddingRight:"10px",paddingBottom:"10px",pointerEvents:"none"},children:ne("div",{style:{position:"relative",width:`min(${s}px, 96vw)`,maxWidth:"96vw",minWidth:"320px",minHeight:"220px",maxHeight:"55vh",overflow:"hidden",backgroundColor:I.backgroundColor||"#2f6ef5",borderRadius:`${I.borderRadius??12}px`,boxSizing:"border-box",paddingTop:"8px",paddingRight:Ct(I.padding?.right)||"12px",paddingBottom:"4px",paddingLeft:Ct(I.padding?.left)||"12px",marginTop:Ct(I.margin?.top),marginRight:Ct(I.margin?.right),marginBottom:Ct(I.margin?.bottom),marginLeft:Ct(I.margin?.left),pointerEvents:"auto",boxShadow:"0 14px 36px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column"},children:[Z("style",{children:`
|
|
80
|
+
.appstorys-csat-scroll {
|
|
81
|
+
scrollbar-width: none; /* Firefox */
|
|
82
|
+
-ms-overflow-style: none; /* IE/Edge */
|
|
83
|
+
}
|
|
84
|
+
.appstorys-csat-scroll::-webkit-scrollbar {
|
|
85
|
+
width: 0;
|
|
86
|
+
height: 0;
|
|
87
|
+
display: none; /* Chrome/Safari */
|
|
88
|
+
}
|
|
89
|
+
`}),T.crossButton?.enabled&&Z(kt,{config:T.crossButton,onPress:()=>l(!0),style:{top:T.crossButton?.margin?.top??10,right:T.crossButton?.margin?.right??10}}),Z("div",{className:"appstorys-csat-scroll",style:{flex:1,minHeight:0,overflowY:"auto",paddingBottom:4},children:h?Z(Pr,{details:S,isHighRating:c,onDone:A}):Z(Ar,{details:S,rating:x,selectedOptions:u,comments:f,isHighRating:c,feedbackOptions:k,onRate:F,onToggleOption:d,onCommentChange:b,onInlineSubmit:E,canSubmit:x>=1,appearance:I})})]})})},Lr=Er;import{useEffect as _n,useMemo as On,useState as $t}from"react";K();import{Fragment as Nn,jsx as ot,jsxs as re}from"react/jsx-runtime";function ke(t){if(t!=null)return`${t}px`}function So(t){if(t&&!(t.startsWith("http://")||t.startsWith("https://")))return t}function Qt(t){return t?{color:t.color,fontSize:t.fontSize,fontFamily:So(t.fontFamily),textAlign:t.textAlign,fontWeight:t.fontDecoration?.includes("bold")?"bold":void 0,fontStyle:t.fontDecoration?.includes("italic")?"italic":void 0,textDecoration:t.fontDecoration?.includes("underline")?"underline":void 0}:{}}function we(t){return{marginTop:ke(t?.top),marginRight:ke(t?.right),marginBottom:ke(t?.bottom),marginLeft:ke(t?.left)}}function Re(t){return`${t?.topLeft??12}px ${t?.topRight??12}px ${t?.bottomRight??t?.topRight??12}px ${t?.bottomLeft??t?.topLeft??12}px`}function jn(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function ie(t){return Math.max(0,Math.min(1,t))}function Dr(t,e){let o=(t||"").trim().replace("#","");if(o.length===3){let i=Number.parseInt(o[0]+o[0],16),n=Number.parseInt(o[1]+o[1],16),r=Number.parseInt(o[2]+o[2],16);return`rgba(${i}, ${n}, ${r}, ${ie(e)})`}if(o.length===6){let i=Number.parseInt(o.slice(0,2),16),n=Number.parseInt(o.slice(2,4),16),r=Number.parseInt(o.slice(4,6),16);return`rgba(${i}, ${n}, ${r}, ${ie(e)})`}return`rgba(0, 0, 0, ${ie(e)})`}function Wr(t){if(t==null)return .4;let e=Number(t);return Number.isFinite(e)?e>1?ie(e/100):ie(e):.4}function $n(t){return[...t.slides||[]].sort((o,i)=>(o.order??0)-(i.order??0))}function _r(t){let e=t?.options||{},o=Object.keys(e),i=n=>{let r=/(\d+)/.exec(n);if(!r)return;let a=Number(r[1]);return Number.isFinite(a)?a:void 0};return o.sort((n,r)=>{let a=i(n),l=i(r);return a!=null&&l!=null?a-l:a!=null?-1:l!=null?1:n.localeCompare(r)}),o.map(n=>e[n]).filter(n=>typeof n=="string"&&n.trim().length>0)}function $r(t,e){if(!t)return null;if(t==="alphabet"){let o="A".codePointAt(0)??65;return String.fromCodePoint(o+e%26)}return t==="number"?String(e+1):null}function Mr(t){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;if(typeof t=="string"&&t.trim().length>0){let e=Number(t);if(Number.isFinite(e)&&e>=0)return e}}function Mn(t){return Mr(t?.borderwidth)??1}var Or=({details:t,slide:e,appearance:o,selectedOption:i,comment:n,onSelectOption:r,onCommentChange:a,onSubmit:l,canSubmit:g})=>{let p=t.styling||{},x=p.options||{},m=p.cta,u=On(()=>_r(e),[e]),v=x.optionsSpacing??8,f=x.bulletSpacing??10,b=x.optionsHeight??44,h=jn(m?.container?.alignment);return re(Nn,{children:[ot("div",{style:we(p.title?.textStyle?.margin),children:ot("div",{style:{...Qt(p.title?.textStyle),color:p.title?.textStyle?.color||"#111827",fontSize:p.title?.textStyle?.fontSize||20,lineHeight:1.3,fontWeight:p.title?.textStyle?.fontDecoration?.includes("bold")?"bold":700},children:e.title||e.question||t.name||"Survey"})}),(e.subtitle||p.subtitle?.textStyle)&&ot("div",{style:we(p.subtitle?.textStyle?.margin),children:ot("div",{style:{...Qt(p.subtitle?.textStyle),color:p.subtitle?.textStyle?.color||"#6b7280",fontSize:p.subtitle?.textStyle?.fontSize||14,lineHeight:1.35},children:e.subtitle||""})}),u.length>0&&ot("div",{style:{marginTop:10,display:"flex",flexDirection:"column",gap:v},children:u.map((y,k)=>{let S=i===y,T=S?x.selectedOptions:x.nonSelectedOptions,I=Mn(T?.textStyle),c=$r(x.optionListStyle,k);return re("button",{onClick:()=>r(y),style:{width:"100%",boxSizing:"border-box",height:b,borderRadius:Re(x.cornerRadius),border:`${I}px solid ${T?.colors?.border||"#e5e7eb"}`,background:T?.colors?.background||"#ffffff",color:T?.colors?.text||"#111827",cursor:"pointer",display:"flex",alignItems:"center",gap:f,paddingLeft:14,paddingRight:14,textAlign:"left",...Qt(T?.textStyle)},"aria-pressed":S,children:[ot("span",{"aria-hidden":!0,style:{width:16,height:16,borderRadius:4,display:"inline-flex",alignItems:"center",justifyContent:"center",border:`1.5px solid ${T?.colors?.border||"#111827"}`,background:"#ffffff",flex:"0 0 auto",fontSize:11,fontWeight:700,color:T?.colors?.text||"#111827"},children:S?"\u2713":c||""}),ot("span",{style:{flex:1,minWidth:0},children:y})]},`${y}-${k}`)})}),e.additionalComment?.enabled&&ot("textarea",{value:n,onChange:y=>a(y.target.value),placeholder:e.additionalComment?.placeholder||"",style:{marginTop:10,width:"100%",boxSizing:"border-box",minHeight:72,resize:"none",overflowY:"auto",border:`${Mn(x.additionalComments?.textStyle)}px solid ${x.additionalComments?.colors?.border||"#e5e7eb"}`,background:x.additionalComments?.colors?.background||"#ffffff",color:x.additionalComments?.colors?.text||"#111827",borderRadius:10,padding:"12px",...Qt(x.additionalComments?.textStyle)}}),ot("div",{style:{position:"sticky",bottom:0,marginTop:12,paddingTop:10,paddingBottom:6,background:o?.backgroundColor||"#ffffff"},children:ot("div",{style:{marginTop:m?.margin?.top??0,marginBottom:m?.margin?.bottom??0,marginLeft:m?.margin?.left??0,marginRight:m?.margin?.right??0,display:"flex",justifyContent:h},children:ot("button",{onClick:l,disabled:!g,style:{width:m?.container?.ctaFullWidth?"100%":m?.container?.ctaWidth??"100%",height:m?.container?.height??44,border:`${m?.container?.borderWidth??0}px solid ${m?.container?.borderColor||"transparent"}`,background:m?.container?.backgroundColor||"#111827",color:m?.text?.color||"#ffffff",borderRadius:Re(m?.cornerRadius),fontFamily:So(m?.text?.fontFamily),fontSize:m?.text?.fontSize||14,fontWeight:m?.text?.fontDecoration?.includes("bold")?"bold":600,cursor:g?"pointer":"not-allowed",opacity:g?1:.6,padding:"0 16px"},children:e.submitButtonText||"Submit"})})})]})},jr=({details:t,onDone:e})=>{let i=(t.styling||{}).thankyouPage||{},n=i.cta,r=jn(n?.container?.alignment);return re(Nn,{children:[t.thankYouImage&&ot("div",{style:{display:"flex",justifyContent:"center",marginTop:8},children:ot("img",{src:t.thankYouImage,alt:"thank you",style:{width:i.imageStyle?.width||80,height:i.imageStyle?.height||80,objectFit:"cover",borderRadius:10}})}),ot("div",{style:{...we(i.title?.textStyle?.margin)},children:ot("div",{style:{...Qt(i.title?.textStyle),color:i.title?.textStyle?.color||"#111827",fontSize:i.title?.textStyle?.fontSize||20,lineHeight:1.3,fontWeight:i.title?.textStyle?.fontDecoration?.includes("bold")?"bold":700},children:t.thankYouTitle||"Thank you"})}),ot("div",{style:{...we(i.subtitle?.textStyle?.margin)},children:ot("div",{style:{...Qt(i.subtitle?.textStyle),color:i.subtitle?.textStyle?.color||"#6b7280",fontSize:i.subtitle?.textStyle?.fontSize||14,lineHeight:1.35},children:t.thankYouText||""})}),(t.thankYouButtonText||n)&&ot("div",{style:{marginTop:n?.margin?.top??14,marginBottom:n?.margin?.bottom??0,marginLeft:n?.margin?.left??0,marginRight:n?.margin?.right??0,display:"flex",justifyContent:r},children:ot("button",{onClick:e,style:{width:n?.container?.ctaFullWidth?"100%":n?.container?.ctaWidth??"auto",height:n?.container?.height??40,border:`${n?.container?.borderWidth??0}px solid ${n?.container?.borderColor||"transparent"}`,background:n?.container?.backgroundColor||"#111827",color:n?.text?.color||"#ffffff",borderRadius:Re(n?.cornerRadius),fontFamily:So(n?.text?.fontFamily),fontSize:n?.text?.fontSize||14,fontWeight:n?.text?.fontDecoration?.includes("bold")?"bold":600,cursor:"pointer",padding:"0 16px"},children:t.thankYouButtonText||"Done"})})]})},Nr=()=>{let t=lt("SUR"),e=z(B=>B.isVisible),o=z(B=>B.campaigns),i=z(B=>B.allCampaigns),n=z(B=>B.currentScreen),r=t??(()=>{let B=(n||"").trim().toLowerCase(),_=[...o||[],...i||[]].find($=>{if(!$||$.campaign_type!=="SUR")return!1;let D=!!($.trigger_event??$.trigger);if(!($.display_trigger!==!1&&!D))return!1;let W=($.screen||"").trim().toLowerCase();return!W||W===B});if(_)try{return ut(_)}catch{return _}})(),[a,l]=$t(!1),[g,p]=$t(!1),[x,m]=$t(0),[u,v]=$t(null),[f,b]=$t(""),[h,y]=$t({}),[k,S]=$t(!1);_n(()=>{if(!r)return;l(!1),p(!1),m(0),v(null),b(""),y({}),S(!1);let B=r.details?.styling?.appearance?.displayDelay??0,_=globalThis.setTimeout(()=>{p(!0);let $=r.details?.id,D=$n(r.details),O=D.length>0?D[0].id:void 0;V("viewed",r.id,{survey_id:$,slide_id:O})},Math.max(0,B)*1e3);return()=>globalThis.clearTimeout(_)},[r]);let T=On(()=>r?$n(r.details):[],[r]),I=T[x];if(_n(()=>{if(!I)return;let B=h[I.id];v(B?.option??null),b(B?.comment??"")},[I?.id]),!r||!e||a||!g)return null;let c=r.details,w=c.styling||{},s=w.appearance||{},d=s.backdropColor||"#000000",E=Wr(s.backdropOpacity),F=B=>{v(_=>_===B?null:B)},A=async(B,_)=>{let $=T.map(M=>({slide_id:M.id,order:M.order,title:M.title,question:M.question,selected_options:B[M.id]?.option,comment:B[M.id]?.comment})),D=r.id,O=[];for(let M of T){let N=B[M.id]?.option;if(!N)continue;let U=Object.entries(M.options||{}).find(([,rt])=>String(rt)===String(N));U&&O.push(U[0])}let W=$.map(M=>M.comment).filter(Boolean).join(" || ")||"",Y=c.id||D;V("survey captured",Y,{survey_id:c.id,slide_id:_,selected_options:O,otherText:W}),w.content?.isThankyouPage!==!1?S(!0):l(!0)},C=async()=>{if(!I||!u)return;let B={...h,[I.id]:{option:u,comment:f}};y(B);try{let O=r.id,W=null;if(u&&I&&I.options){let dt=Object.entries(I.options).find(([,M])=>String(M)===String(u));dt&&(W=dt[0])}let Y=c.id||O;V("survey captured",Y,{survey_id:c.id,slide_id:I.id,selected_options:W?[W]:[],otherText:f||""})}catch(O){console.warn("Error sending per-slide survey captured",O)}if((I.logic||[]).find(O=>(O.selectOption||[]).includes(u))?.redirectTo==="thank-you"){await A(B,I.id);return}if(x>=T.length-1){await A(B,I.id);return}m(O=>Math.min(O+1,T.length-1))},R=()=>{let B=c.thankYouButtonConfig;if(B?.enabled&&B.redirectUrl){try{let _=String(B.redirectUrl||"").trim();if(_&&!_.startsWith("http")&>(_)){l(!0);return}}catch(_){console.warn("revealCampaignFromLink error",_)}try{globalThis.open(B.redirectUrl,"_blank")}catch{}}l(!0)},P=async()=>{try{let B=r?.id,_=c?.id,$=I?.id;await V("SurveyDismissed",B,{survey_id:_,slide_id:$})}catch(B){console.warn("Error sending SurveyDismissed",B)}finally{l(!0)}};return I?re("div",{style:{position:"fixed",inset:0,zIndex:999999,display:"flex",justifyContent:"flex-end",alignItems:"flex-end",padding:12,pointerEvents:"none"},children:[ot("div",{"aria-hidden":!0,style:{position:"absolute",inset:0,background:Dr(d,E)}}),re("div",{style:{position:"relative",width:"min(420px, 92vw)",maxWidth:"92vw",minWidth:"320px",maxHeight:"80vh",overflow:"hidden",backgroundColor:s.backgroundColor||"#ffffff",borderRadius:Re(s.cornerRadius),boxSizing:"border-box",paddingTop:14,paddingRight:16,paddingBottom:10,paddingLeft:16,pointerEvents:"auto",boxShadow:"0 14px 36px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column"},children:[ot("style",{children:`
|
|
90
|
+
.appstorys-survey-scroll {
|
|
91
|
+
scrollbar-width: none; /* Firefox */
|
|
92
|
+
-ms-overflow-style: none; /* IE/Edge */
|
|
93
|
+
}
|
|
94
|
+
.appstorys-survey-scroll::-webkit-scrollbar {
|
|
95
|
+
width: 0;
|
|
96
|
+
height: 0;
|
|
97
|
+
display: none; /* Chrome/Safari */
|
|
98
|
+
}
|
|
99
|
+
`}),w.crossButton?.enabled&&ot(kt,{config:w.crossButton,onPress:P,style:{top:w.crossButton?.margin?.top??10,right:w.crossButton?.margin?.right??10}}),ot("div",{className:"appstorys-survey-scroll",style:{flex:1,minHeight:0,overflowY:"auto",paddingRight:2},children:k?ot(jr,{details:c,onDone:R}):ot(Or,{details:c,slide:I,appearance:s,selectedOption:u,comment:f,onSelectOption:F,onCommentChange:b,onSubmit:C,canSubmit:u!=null})})]})]}):null},qr=Nr;var Co=class{state="uninitialized";navigateToScreen;async initialize(e){let{appId:o,accountId:i,userId:n}=e;if(this.navigateToScreen=e.navigateToScreen,this.state!=="initializing"){if(this.state==="initialized"){let r=z.getState();if(r.appId===o&&r.accountId===i&&r.userId===n)return}this.state="initializing";try{let r,a;if(!n||n.trim()==="")r=await Oo(),a=!0;else{let m=await Je();m&&m!==n&&console.log("AppStorys: Found previous anonymous user, will reconcile after verification."),r=n,a=!1}if(!await Rt(i,o,r)){this.state="error";return}if(!a){let m=await Je();m&&m!==r&&(await Ve(m,r),await jo())}try{let m=await it(),u=e.baseUrl||"https://users.appstorys.co";fetch(`${u}/v2/${i}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",...m?{Authorization:`Bearer ${m}`}:{}},body:JSON.stringify({user_id:r,screenName:typeof window<"u"&&window.location&&window.location.pathname?window.location.pathname:"",silentUpdate:!0})}).then(async v=>{if(v.ok)try{let f=await v.json(),b=z.getState();if(typeof f.screen_capture_enabled<"u"){let h=!!f.screen_capture_enabled;console.info("AppStorys: track-user-res returned screen_capture_enabled=",h),b.setScreenCaptureEnabled(h)}}catch{}}).catch(v=>console.warn("track-user-res (init) failed",v))}catch(m){console.warn("track-user-res (init) setup failed",m)}let{campaigns:g,version:p}=await He(i),x=z.getState();x.setAppId(o),x.setAccountId(i),x.setUserId(r),x.setIsAnonymousUser(a),x.setBaseUrl(e.baseUrl),x.setTrackingUrl(e.trackingUrl),x.saveAllCampaigns(g),x.setCampaignVersion(p);try{z.getState().screenCaptureEnabled&&(await Promise.resolve().then(()=>(Gn(),Qn))).mountScreenCaptureButton()}catch(m){console.warn("Failed to mount screen capture button",m)}$o.setup(),Ge.setup(),this.state="initialized"}catch(r){this.state="error",console.error("AppStorys initialization failed:",r)}}}async trackScreen(e){return await this.ensureInitialized(),je(e)}async trackEvent(e,o,i){return await this.ensureInitialized(),V(e,o,i)}async setUserProperties(e){return await this.ensureInitialized(),Ne(e)}handleLink(e){if(e){if(typeof e=="string"){try{if(!e.startsWith("http")&>(e))return}catch(o){console.warn("revealCampaignFromLink error",o)}e.startsWith("http")?window.open(e,"_blank"):this.navigateToScreen?.(e)}else if(typeof e=="object"&&e.value){try{if(gt(e.value))return}catch{}this.navigateToScreen?.(e.value)}}}get visibility(){return z.getState().isVisible}set visibility(e){Ge.updateVisibility(e)}async ensureInitialized(){if(this.state==="initialized")return;let e=Date.now();for(;this.state!=="initialized";){if(this.state==="error")throw new Error("AppStorys SDK error");if(Date.now()-e>1e4)throw new Error("AppStorys SDK initialization timeout");await new Promise(o=>setTimeout(o,100))}}personalizeText(e){return ye(e)}},Pc=new Co;export{Pc as AppStorys,Si as Banner,Cr as BottomSheet,Lr as Csat,Bi as Floater,ki as Pip,wo as SdkState,dr as Story,qr as Survey,hr as Tooltip,gr as Widget,ye as personalizeText};
|
|
100
|
+
//# sourceMappingURL=index.mjs.map
|