@redacto.io/dpdpa-report-sdk-js 0.2.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.
@@ -0,0 +1,426 @@
1
+ "use strict";var RedactoDpdpaReport=(()=>{var w=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var ge=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0})},ye=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of he(t))!fe.call(e,s)&&s!==r&&w(e,s,{get:()=>t[s],enumerable:!(o=me(t,s))||o.enumerable});return e};var xe=e=>ye(w({},"__esModule",{value:!0}),e);var Pe={};ge(Pe,{default:()=>Ae,destroy:()=>N,getCapturedLead:()=>ue,init:()=>ce,version:()=>pe});var F="https://salazar.redacto.tech",R={submit:"/webhook/dpdpa/generate",status:"/webhook/dpdpa/status"},$=3e3,H=3e5,A=3,P=15e3,T="redacto_dpdpa_lead",O="https://cdn.redacto.io/assets/redacto-logo.svg",c={name:"Redacto",primaryColor:"#4262ff",accentColor:"#a259ff",textColor:"#050038",borderColor:"#e5e5e5",backgroundColor:"#f7f7f7",borderRadius:"8px",fontFamily:"inherit"},B="#a6c03d",j="#f24e1e",U=2,D=120,z=/^(?!-)[a-z0-9-]{1,63}(?<!-)(\.[a-z0-9-]{1,63})+$/i,G=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,q=new Set(["gmail.com","googlemail.com","yahoo.com","yahoo.co.in","yahoo.co.uk","hotmail.com","outlook.com","live.com","icloud.com","me.com","aol.com","proton.me","protonmail.com","mail.com","gmx.com","zoho.com","rediffmail.com"]);function n(e,t,...r){let o=document.createElement(e);return t&&be(o,t),Y(o,r),o}function f(e,t,...r){let o=document.createElementNS("http://www.w3.org/2000/svg",e);if(t)for(let[s,i]of Object.entries(t))i==null||i===!1||(s==="style"&&typeof i=="object"?W(o,i):o.setAttribute(s,String(i)));return Y(o,r),o}function be(e,t){for(let[r,o]of Object.entries(t))if(!(o==null||o===!1))if(r==="style"&&typeof o=="object")W(e,o);else if(r==="className")e.className=o;else if(r==="dataset"&&typeof o=="object")Object.assign(e.dataset,o);else if(r.startsWith("on")&&typeof o=="function"){let s=r.slice(2).toLowerCase();e.addEventListener(s,o)}else r==="checked"||r==="disabled"||r==="readOnly"?e[r]=o:e.setAttribute(r,String(o))}var Ee=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","fontWeight","gridArea","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","lineClamp","lineHeight","opacity","order","orphans","scale","tabSize","widows","zIndex","zoom"]);function W(e,t){for(let[r,o]of Object.entries(t)){if(o==null)continue;let s=typeof o=="number"&&!Ee.has(r)?`${o}px`:String(o);e.style[r]=s}}function Y(e,t){for(let r of t)r==null||r===!1||(typeof r=="string"?e.appendChild(document.createTextNode(r)):e.appendChild(r))}function X(e){for(;e.firstChild;)e.removeChild(e.firstChild)}var y=class{constructor(t){this.listeners=new Set;this.state={...t}}getState(){return{...this.state}}setState(t){let r=this.state;this.state={...this.state,...t},this.listeners.forEach(o=>o(this.state,r))}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}destroy(){this.listeners.clear()}};var u=class extends Error{constructor(t,r){super(t),this.name="ApiError",this.status=r}};function J(e,t={}){let r=new AbortController,o=setTimeout(()=>r.abort(),P);return fetch(e,{...t,signal:r.signal}).finally(()=>clearTimeout(o))}function V(e){return e instanceof DOMException&&e.name==="AbortError"?new u("Request timed out",void 0):new u(e instanceof Error?e.message:"Network error",void 0)}async function K({baseUrl:e,body:t}){let r;try{r=await J(`${e}${R.submit}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(s){throw V(s)}let o;try{o=await r.json()}catch{throw new u(`Unexpected response (HTTP ${r.status})`,r.status)}if(!r.ok){let s=o&&"message"in o&&o.message?o.message:`Request failed (HTTP ${r.status})`;throw new u(s,r.status)}return o}async function Q({baseUrl:e,jobId:t}){let r=`${e}${R.status}?job_id=${encodeURIComponent(t)}`,o;try{o=await J(r,{method:"GET"})}catch(i){throw V(i)}let s;try{s=await o.json()}catch{throw new u(`Unexpected response (HTTP ${o.status})`,o.status)}if(!o.ok){let i=s&&"message"in s&&s.message?s.message:`Status check failed (HTTP ${o.status})`;throw new u(i,o.status)}return s}var Z=()=>typeof window!="undefined"&&typeof window.localStorage!="undefined",x=e=>{if(Z())try{window.localStorage.setItem(T,JSON.stringify(e))}catch(t){console.error("Failed to save lead:",t)}},ve=e=>{if(!e||typeof e!="object")return!1;let t=e;return typeof t.email=="string"&&typeof t.company_name=="string"&&typeof t.company_domain=="string"&&(t.job_id===null||typeof t.job_id=="string")&&typeof t.timestamp=="string"},ee=()=>{if(!Z())return null;try{let e=window.localStorage.getItem(T);if(!e)return null;let t=JSON.parse(e);return ve(t)?t:null}catch(e){return console.error("Failed to load lead:",e),null}};var te="redacto-dpdpa-form-styles";function Se(e){return`
2
+ :host {
3
+ display: block;
4
+ width: 100%;
5
+ container-type: inline-size;
6
+ container-name: dpdpa-card;
7
+ }
8
+
9
+ :host, :host > *, :host *, :host *::before, :host *::after {
10
+ box-sizing: border-box;
11
+ }
12
+
13
+ .dpdpa-card {
14
+ box-sizing: border-box;
15
+ width: 100%;
16
+ min-height: 520px;
17
+ display: flex;
18
+ flex-direction: column;
19
+ padding: 28px 24px;
20
+ background: ${e.background};
21
+ color: ${e.text};
22
+ border: 1px solid ${e.border};
23
+ border-radius: ${e.borderRadius};
24
+ font-family: ${e.fontFamily};
25
+ font-size: 15px;
26
+ line-height: 1.5;
27
+ text-align: left;
28
+ }
29
+
30
+ @container dpdpa-card (max-width: 420px) {
31
+ .dpdpa-card {
32
+ padding: 20px 16px;
33
+ min-height: 480px;
34
+ }
35
+ .dpdpa-heading {
36
+ font-size: 18px;
37
+ }
38
+ .dpdpa-success-title,
39
+ .dpdpa-error-title {
40
+ font-size: 16px;
41
+ }
42
+ .dpdpa-header {
43
+ margin-bottom: 16px;
44
+ }
45
+ }
46
+
47
+ @supports not (container-type: inline-size) {
48
+ @media (max-width: 480px) {
49
+ .dpdpa-card {
50
+ padding: 20px 16px;
51
+ }
52
+ .dpdpa-heading {
53
+ font-size: 18px;
54
+ }
55
+ }
56
+ }
57
+
58
+ .dpdpa-header {
59
+ display: flex;
60
+ align-items: center;
61
+ flex-wrap: wrap;
62
+ gap: 10px;
63
+ margin-bottom: 20px;
64
+ }
65
+
66
+ .dpdpa-logo {
67
+ max-height: 28px;
68
+ max-width: 140px;
69
+ display: inline-block;
70
+ object-fit: contain;
71
+ }
72
+
73
+ .dpdpa-wordmark {
74
+ font-weight: 700;
75
+ font-size: 17px;
76
+ color: ${e.text};
77
+ letter-spacing: 0.3px;
78
+ }
79
+
80
+ .dpdpa-footer {
81
+ margin-top: 20px;
82
+ padding-top: 16px;
83
+ border-top: 1px solid ${e.border};
84
+ font-size: 12px;
85
+ color: ${e.text};
86
+ opacity: 0.7;
87
+ text-align: center;
88
+ }
89
+
90
+ .dpdpa-form {
91
+ flex: 1;
92
+ display: flex;
93
+ flex-direction: column;
94
+ justify-content: flex-start;
95
+ gap: 14px;
96
+ margin: 0;
97
+ }
98
+
99
+ .dpdpa-heading {
100
+ font-size: 20px;
101
+ font-weight: 700;
102
+ margin: 0 0 4px;
103
+ color: ${e.text};
104
+ line-height: 1.3;
105
+ }
106
+
107
+ .dpdpa-subheading {
108
+ margin: 0 0 8px;
109
+ font-size: 14px;
110
+ color: ${e.text};
111
+ opacity: 0.75;
112
+ }
113
+
114
+ .dpdpa-field {
115
+ display: flex;
116
+ flex-direction: column;
117
+ gap: 4px;
118
+ }
119
+
120
+ .dpdpa-label {
121
+ font-size: 13px;
122
+ font-weight: 600;
123
+ color: ${e.text};
124
+ }
125
+
126
+ .dpdpa-input {
127
+ width: 100%;
128
+ min-width: 0;
129
+ padding: 11px 13px;
130
+ font-family: inherit;
131
+ font-size: 14px;
132
+ color: ${e.text};
133
+ background: #ffffff;
134
+ border: 1px solid ${e.border};
135
+ border-radius: ${e.borderRadius};
136
+ outline: none;
137
+ transition: border-color 0.15s ease, box-shadow 0.15s ease;
138
+ }
139
+
140
+ .dpdpa-input:focus {
141
+ border-color: ${e.primary};
142
+ box-shadow: 0 0 0 3px ${e.primaryFocus};
143
+ }
144
+
145
+ .dpdpa-input:disabled {
146
+ background: ${e.border};
147
+ opacity: 0.7;
148
+ cursor: not-allowed;
149
+ }
150
+
151
+ .dpdpa-field-error,
152
+ .dpdpa-general-error {
153
+ font-size: 12px;
154
+ color: ${e.errorColor};
155
+ line-height: 1.4;
156
+ }
157
+
158
+ .dpdpa-general-error {
159
+ padding: 10px 12px;
160
+ background: ${e.errorColor}14;
161
+ border: 1px solid ${e.errorColor}33;
162
+ border-radius: ${e.borderRadius};
163
+ }
164
+
165
+ .dpdpa-btn-primary {
166
+ display: inline-flex;
167
+ align-items: center;
168
+ justify-content: center;
169
+ gap: 8px;
170
+ width: 100%;
171
+ padding: 12px 18px;
172
+ font-family: inherit;
173
+ font-size: 15px;
174
+ font-weight: 600;
175
+ color: ${e.primaryText};
176
+ background: ${e.primary};
177
+ border: none;
178
+ border-radius: ${e.borderRadius};
179
+ cursor: pointer;
180
+ text-decoration: none;
181
+ transition: background-color 0.15s ease, transform 0.05s ease;
182
+ margin-top: 6px;
183
+ }
184
+
185
+ .dpdpa-btn-primary:hover:not(:disabled) {
186
+ background: ${e.primaryHover};
187
+ }
188
+
189
+ .dpdpa-btn-primary:active:not(:disabled) {
190
+ transform: translateY(1px);
191
+ }
192
+
193
+ .dpdpa-btn-primary:disabled {
194
+ opacity: 0.7;
195
+ cursor: not-allowed;
196
+ }
197
+
198
+ .dpdpa-btn-link {
199
+ text-decoration: none;
200
+ color: ${e.primaryText};
201
+ }
202
+
203
+ .dpdpa-spinner {
204
+ display: inline-block;
205
+ border-radius: 50%;
206
+ border-style: solid;
207
+ border-color: ${e.primaryText}4D;
208
+ animation: dpdpa-spin 0.7s linear infinite;
209
+ }
210
+
211
+ .dpdpa-spinner-inline {
212
+ width: 14px;
213
+ height: 14px;
214
+ border-width: 2px;
215
+ border-top-color: ${e.primaryText};
216
+ }
217
+
218
+ .dpdpa-polling {
219
+ flex: 1;
220
+ display: flex;
221
+ flex-direction: column;
222
+ justify-content: center;
223
+ padding: 4px 2px 8px;
224
+ gap: 16px;
225
+ }
226
+
227
+ .dpdpa-polling-sub {
228
+ margin: 0;
229
+ font-size: 13px;
230
+ color: ${e.text};
231
+ opacity: 0.6;
232
+ text-align: center;
233
+ }
234
+
235
+ .dpdpa-steps {
236
+ display: flex;
237
+ flex-direction: column;
238
+ gap: 10px;
239
+ }
240
+
241
+ .dpdpa-step {
242
+ display: flex;
243
+ align-items: center;
244
+ gap: 10px;
245
+ font-size: 15px;
246
+ animation: dpdpa-step-in 0.35s ease-out both;
247
+ }
248
+
249
+ .dpdpa-step-done .dpdpa-step-label {
250
+ color: ${e.text};
251
+ opacity: 0.6;
252
+ }
253
+
254
+ .dpdpa-step-icon {
255
+ flex: none;
256
+ width: 18px;
257
+ height: 18px;
258
+ border-radius: 50%;
259
+ display: inline-flex;
260
+ align-items: center;
261
+ justify-content: center;
262
+ }
263
+
264
+ .dpdpa-step-icon-active {
265
+ position: relative;
266
+ width: 10px;
267
+ height: 10px;
268
+ margin: 0 4px;
269
+ box-shadow: 0 0 0 0 ${e.primaryFocus};
270
+ animation: dpdpa-pulse 1.4s ease-out infinite;
271
+ }
272
+
273
+ .dpdpa-step-label {
274
+ color: ${e.text};
275
+ font-weight: 500;
276
+ word-break: break-word;
277
+ }
278
+
279
+ .dpdpa-shimmer {
280
+ background: linear-gradient(
281
+ 90deg,
282
+ ${e.text} 0%,
283
+ ${e.primary} 40%,
284
+ ${e.accent} 50%,
285
+ ${e.primary} 60%,
286
+ ${e.text} 100%
287
+ );
288
+ background-size: 200% 100%;
289
+ -webkit-background-clip: text;
290
+ background-clip: text;
291
+ -webkit-text-fill-color: transparent;
292
+ color: transparent;
293
+ animation: dpdpa-shimmer 2.2s linear infinite;
294
+ }
295
+
296
+ .dpdpa-dots {
297
+ display: inline-flex;
298
+ align-items: center;
299
+ gap: 3px;
300
+ margin-left: 2px;
301
+ }
302
+
303
+ .dpdpa-dots > span {
304
+ width: 4px;
305
+ height: 4px;
306
+ border-radius: 50%;
307
+ background: ${e.primary};
308
+ opacity: 0.4;
309
+ animation: dpdpa-dot-bounce 1.2s ease-in-out infinite;
310
+ }
311
+
312
+ .dpdpa-dots > span:nth-child(2) { animation-delay: 0.15s; }
313
+ .dpdpa-dots > span:nth-child(3) { animation-delay: 0.3s; }
314
+
315
+ @keyframes dpdpa-shimmer {
316
+ from { background-position: 200% 0; }
317
+ to { background-position: -200% 0; }
318
+ }
319
+
320
+ @keyframes dpdpa-dot-bounce {
321
+ 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
322
+ 40% { opacity: 1; transform: translateY(-3px); }
323
+ }
324
+
325
+ @keyframes dpdpa-pulse {
326
+ 0% { box-shadow: 0 0 0 0 ${e.primaryFocus}; }
327
+ 70% { box-shadow: 0 0 0 8px rgba(0, 0, 0, 0); }
328
+ 100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
329
+ }
330
+
331
+ @keyframes dpdpa-step-in {
332
+ from { opacity: 0; transform: translateY(4px); }
333
+ to { opacity: 1; transform: translateY(0); }
334
+ }
335
+
336
+ .dpdpa-progress {
337
+ width: 100%;
338
+ height: 6px;
339
+ background: ${e.border};
340
+ border-radius: 999px;
341
+ overflow: hidden;
342
+ margin-top: 4px;
343
+ }
344
+
345
+ .dpdpa-progress-fill {
346
+ height: 100%;
347
+ background: linear-gradient(to right, ${e.primary}, ${e.accent});
348
+ transition: width 0.5s ease;
349
+ }
350
+
351
+ .dpdpa-success {
352
+ flex: 1;
353
+ display: flex;
354
+ flex-direction: column;
355
+ justify-content: center;
356
+ align-items: center;
357
+ text-align: center;
358
+ gap: 12px;
359
+ padding: 8px 4px;
360
+ }
361
+
362
+ .dpdpa-check-circle {
363
+ width: 56px;
364
+ height: 56px;
365
+ border-radius: 50%;
366
+ display: flex;
367
+ align-items: center;
368
+ justify-content: center;
369
+ }
370
+
371
+ .dpdpa-success-title {
372
+ margin: 0;
373
+ font-size: 18px;
374
+ font-weight: 700;
375
+ color: ${e.text};
376
+ line-height: 1.35;
377
+ }
378
+
379
+ .dpdpa-success-sub {
380
+ margin: 0;
381
+ font-size: 14px;
382
+ color: ${e.text};
383
+ opacity: 0.75;
384
+ }
385
+
386
+ .dpdpa-reset-link {
387
+ font-size: 13px;
388
+ color: ${e.primary};
389
+ text-decoration: none;
390
+ margin-top: 4px;
391
+ cursor: pointer;
392
+ }
393
+
394
+ .dpdpa-reset-link:hover {
395
+ text-decoration: underline;
396
+ }
397
+
398
+ .dpdpa-error-view {
399
+ flex: 1;
400
+ display: flex;
401
+ flex-direction: column;
402
+ justify-content: center;
403
+ gap: 12px;
404
+ text-align: center;
405
+ padding: 8px 4px;
406
+ }
407
+
408
+ .dpdpa-error-title {
409
+ margin: 0;
410
+ font-size: 18px;
411
+ font-weight: 700;
412
+ color: ${e.errorColor};
413
+ }
414
+
415
+ .dpdpa-error-message {
416
+ margin: 0;
417
+ font-size: 14px;
418
+ color: ${e.text};
419
+ }
420
+
421
+ @keyframes dpdpa-spin {
422
+ from { transform: rotate(0deg); }
423
+ to { transform: rotate(360deg); }
424
+ }
425
+ `}function k(e,t){if(typeof document=="undefined"||e.querySelector(`#${te}`))return;let r=document.createElement("style");r.id=te,r.textContent=Se(t),e.appendChild(r)}var we=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;function re(e,t){return!e||!we.test(e.trim())?t:e.trim()}function _(e){let t=e.replace("#","").trim(),r=t.length===3?t.split("").map(o=>o+o).join(""):t;return{r:parseInt(r.slice(0,2),16),g:parseInt(r.slice(2,4),16),b:parseInt(r.slice(4,6),16)}}function Re(e,t){let{r,g:o,b:s}=_(e),i=a=>Math.max(0,Math.round(a*(1-t)));return`rgb(${i(r)}, ${i(o)}, ${i(s)})`}function Te(e,t){let{r,g:o,b:s}=_(e);return`rgba(${r}, ${o}, ${s}, ${t})`}function ke(e){let{r:t,g:r,b:o}=_(e),s=i=>{let a=i/255;return a<=.03928?a/12.92:Math.pow((a+.055)/1.055,2.4)};return .2126*s(t)+.7152*s(r)+.0722*s(o)}function _e(e){return ke(e)>.55?"#050038":"#ffffff"}function oe(e){var o;let t=re(e==null?void 0:e.primaryColor,c.primaryColor),r=re((o=e==null?void 0:e.accentColor)!=null?o:e==null?void 0:e.primaryColor,c.accentColor);return{logo:(e==null?void 0:e.logo)||O,name:(e==null?void 0:e.name)||c.name,primary:t,accent:r,primaryHover:Re(t,.08),primaryFocus:Te(t,.3),primaryText:_e(t),text:(e==null?void 0:e.textColor)||c.textColor,border:(e==null?void 0:e.borderColor)||c.borderColor,background:(e==null?void 0:e.backgroundColor)||c.backgroundColor,borderRadius:(e==null?void 0:e.borderRadius)||c.borderRadius,fontFamily:(e==null?void 0:e.fontFamily)||c.fontFamily,successColor:B,errorColor:j}}function L(e){return e.trim().toLowerCase().replace(/^https?:\/\//,"").replace(/^www\./,"").replace(/\/.*$/,"")}function C(e,t){var o;let r=t.trim();switch(e){case"company_name":return r.length<U?"Please enter a company name":r.length>D?"Company name is too long":null;case"company_domain":{if(!r)return"Enter your company domain";let s=L(r);return z.test(s)?null:"Enter a valid domain like example.com"}case"email":{if(!r)return"Enter your work email";if(!G.test(r))return"Enter a valid email";let s=(o=r.split("@")[1])==null?void 0:o.toLowerCase();return s&&q.has(s)?"Please use your work email":null}}}function se(e){let t={};return Object.keys(e).forEach(r=>{let o=C(r,e[r]);o&&(t[r]=o)}),t}function b(e){let t=n("img",{src:e.logo,alt:`${e.name} logo`,className:"dpdpa-logo",onerror:o=>{let s=o.currentTarget;s.style.display="none";let i=s.nextElementSibling;i&&(i.style.display="inline-block")}}),r=n("span",{className:"dpdpa-wordmark",style:{display:"none"}},e.name);return n("div",{className:"dpdpa-header"},t,r)}function M(e,t){let r=n("input",{type:t.type,className:"dpdpa-input",placeholder:t.placeholder,value:t.value,autocomplete:t.autocomplete,"aria-label":t.label,onInput:a=>t.onInput(a.currentTarget.value),onBlur:()=>t.onBlur()}),o=n("div",{className:"dpdpa-field-error",role:"alert",style:{display:t.error?"block":"none"}},t.error||""),s=n("label",{className:"dpdpa-label"},t.label);return{row:n("div",{className:"dpdpa-field"},s,r,o),input:r,errorSlot:o}}function E(e){return n("div",{className:"dpdpa-footer"},"Powered by ",n("strong",null,e.name))}function I(e,t,r,o,s){let i=M(e,{field:"company_name",label:"Company name",type:"text",placeholder:"Acme Inc",value:t.company_name,error:r.company_name,autocomplete:"organization",onInput:h=>s.onInput("company_name",h),onBlur:()=>s.onBlur("company_name")}),a=M(e,{field:"company_domain",label:"Company domain",type:"text",placeholder:"acme.com",value:t.company_domain,error:r.company_domain,autocomplete:"url",onInput:h=>s.onInput("company_domain",h),onBlur:()=>s.onBlur("company_domain")}),l=M(e,{field:"email",label:"Work email",type:"email",placeholder:"you@acme.com",value:t.email,error:r.email,autocomplete:"email",onInput:h=>s.onInput("email",h),onBlur:()=>s.onBlur("email")}),d=n("div",{className:"dpdpa-general-error",role:"alert",style:{display:o?"block":"none"}},o||""),p=n("button",{type:"submit",className:"dpdpa-btn-primary"},"Get my free report"),m=n("form",{className:"dpdpa-form",novalidate:"true",onSubmit:h=>{h.preventDefault(),s.onSubmit()}},n("h2",{className:"dpdpa-heading"},"Get your free DPDPA compliance report"),n("p",{className:"dpdpa-subheading"},"We'll analyse your site and deliver a compliance assessment PDF."),d,i.row,a.row,l.row,p);return{root:n("div",{className:"dpdpa-card"},b(e),m,E(e)),fieldInputs:{company_name:i.input,company_domain:a.input,email:l.input},fieldErrors:{company_name:i.errorSlot,company_domain:a.errorSlot,email:l.errorSlot},submitBtn:p,generalError:d}}function ne(e,t){let r=I(e,t,{},null,{onInput:()=>{},onBlur:()=>{},onSubmit:()=>{}});return Object.values(r.fieldInputs).forEach(o=>{o.disabled=!0}),r.submitBtn.disabled=!0,r.submitBtn.textContent="",r.submitBtn.appendChild(n("span",{className:"dpdpa-spinner dpdpa-spinner-inline"})),r.submitBtn.appendChild(document.createTextNode(" Submitting\u2026")),r.root}function Le(){return n("span",{className:"dpdpa-dots","aria-hidden":"true"},n("span"),n("span"),n("span"))}function Ce(e){return n("div",{className:"dpdpa-step-icon dpdpa-step-icon-done",style:{backgroundColor:e.successColor}},f("svg",{width:12,height:12,viewBox:"0 0 24 24",fill:"none"},f("path",{d:"M5 12l5 5L20 7",stroke:"#ffffff","stroke-width":3,"stroke-linecap":"round","stroke-linejoin":"round"})))}function Me(e){return n("div",{className:"dpdpa-step-icon dpdpa-step-icon-active",style:{backgroundColor:e.primary}})}var Ie={pending:0,researching:0,analysis_complete:2},Ne=[{label:e=>`Researching ${e}`},{label:()=>"Analysing DPDPA compliance"},{label:()=>"Generating your report"}];function ie(e,t){let r=Math.min(100,Math.round(t.elapsedMs/t.pollTimeoutMs*100)),o=n("div",{className:"dpdpa-progress-fill",style:{width:`${r}%`}}),s=n("div",{className:"dpdpa-progress",role:"progressbar","aria-label":"Report generation progress","aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":String(r)},o),i=Ie[t.subStatus],a=n("div",{className:"dpdpa-steps"});Ne.forEach((d,p)=>{if(p>i)return;let m=p===i,S=n("div",{className:`dpdpa-step ${m?"dpdpa-step-active":"dpdpa-step-done"}`},m?Me(e):Ce(e),n("span",{className:m?"dpdpa-step-label dpdpa-shimmer":"dpdpa-step-label"},d.label(t.companyName)));m&&S.appendChild(Le()),a.appendChild(S)});let l=n("div",{className:"dpdpa-polling"},a,n("p",{className:"dpdpa-polling-sub"},"This usually takes 60 to 120 seconds. Keep this tab open."),s);return n("div",{className:"dpdpa-card"},b(e),l,E(e))}function Fe(e){return n("div",{className:"dpdpa-check-circle",style:{backgroundColor:e.successColor}},f("svg",{width:28,height:28,viewBox:"0 0 24 24",fill:"none"},f("path",{d:"M5 12l5 5L20 7",stroke:"#ffffff","stroke-width":3,"stroke-linecap":"round","stroke-linejoin":"round"})))}function $e(e){let t=(e||"").trim();return t?!!(/^https?:\/\//i.test(t)||/^\/[^/]/.test(t)||t.startsWith("./")||t.startsWith("../")):!1}function ae(e,t){let r=$e(t.reportUrl)?t.reportUrl:"#",o=n("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"dpdpa-btn-primary dpdpa-btn-link"},"Download PDF"),s=n("a",{href:"#",className:"dpdpa-reset-link",onClick:a=>{a.preventDefault(),t.onReset()}},"Request another report"),i=n("div",{className:"dpdpa-success"},Fe(e),n("h3",{className:"dpdpa-success-title"},`Your DPDPA report for ${t.companyName} is ready`),n("p",{className:"dpdpa-success-sub"},"Click below to download your compliance assessment PDF."),o,s);return n("div",{className:"dpdpa-card"},b(e),i,E(e))}function le(e,t){let r=n("button",{type:"button",className:"dpdpa-btn-primary",onClick:()=>t.retryable?t.onRetry():t.onBack()},t.retryable?"Try again":"Edit details"),o=n("div",{className:"dpdpa-error-view"},n("h3",{className:"dpdpa-error-title"},"Something went wrong"),n("p",{className:"dpdpa-error-message"},t.message),r);return n("div",{className:"dpdpa-card"},b(e),o,E(e))}var de={company_name:"",company_domain:"",email:""},v=class{constructor(t){this.targetEl=null;this.hostEl=null;this.shadowRoot=null;this.idleRefs=null;this.pollTimer=null;this.pollStartedAt=0;this.pollHiddenSince=null;this.pollHiddenTotalMs=0;this.pollResumePending=!1;this.lastSubStatus=null;this.consecutiveErrors=0;this.destroyed=!1;this.unsubscribe=null;this.visibilityHandler=null;this.options=t,this.brand=oe(t.branding),this.fields={...de},this.store=new y({phase:"idle",subStatus:"pending",elapsedMs:0,jobId:null,reportUrl:null,errors:{},generalError:null,errorMessage:"",retryable:!0})}async init(){if(typeof this.options.target=="string"){let t=document.querySelector(this.options.target);if(!t)throw new Error(`DPDPA report form: target element not found for selector "${this.options.target}"`);this.targetEl=t}else this.targetEl=this.options.target;this.hostEl=document.createElement("div"),this.hostEl.setAttribute("data-redacto-dpdpa-report",""),this.hostEl.style.display="block",this.targetEl.appendChild(this.hostEl),this.shadowRoot=this.hostEl.attachShadow({mode:"open"}),k(this.shadowRoot,this.brand),this.unsubscribe=this.store.subscribe((t,r)=>{t.phase!==r.phase?this.render():t.phase==="polling"&&t.subStatus!==r.subStatus?this.render():t.phase==="polling"&&t.elapsedMs!==r.elapsedMs&&this.updateProgress()}),this.visibilityHandler=()=>this.handleVisibilityChange(),document.addEventListener("visibilitychange",this.visibilityHandler),this.render()}destroy(){var t;this.destroyed=!0,this.clearPolling(),(t=this.unsubscribe)==null||t.call(this),this.unsubscribe=null,this.visibilityHandler&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null),this.store.destroy(),this.hostEl&&this.hostEl.parentNode&&this.hostEl.parentNode.removeChild(this.hostEl),this.hostEl=null,this.shadowRoot=null,this.targetEl=null,this.idleRefs=null}render(){if(!this.shadowRoot)return;X(this.shadowRoot),k(this.shadowRoot,this.brand),this.idleRefs=null;let t=this.store.getState(),r;switch(t.phase){case"idle":this.idleRefs=I(this.brand,this.fields,t.errors,t.generalError,{onInput:(o,s)=>this.handleInput(o,s),onBlur:o=>this.handleBlur(o),onSubmit:()=>this.handleSubmit()}),r=this.idleRefs.root;break;case"submitting":r=ne(this.brand,this.fields);break;case"polling":r=ie(this.brand,{companyName:this.fields.company_name,subStatus:t.subStatus,elapsedMs:t.elapsedMs,pollTimeoutMs:this.getPollTimeout()});break;case"complete":r=ae(this.brand,{companyName:this.fields.company_name,reportUrl:t.reportUrl||"#",onReset:()=>this.resetToIdle()});break;case"error":r=le(this.brand,{message:t.errorMessage,retryable:t.retryable,onRetry:()=>this.submit(),onBack:()=>{var o;return this.backToIdle((o=t.generalError)!=null?o:t.errorMessage)}});break}if(this.shadowRoot.appendChild(r),t.phase==="idle"&&this.idleRefs){let o=Object.keys(t.errors).find(s=>!!t.errors[s]);o&&this.idleRefs.fieldInputs[o].focus()}}updateProgress(){if(!this.shadowRoot)return;let t=this.shadowRoot.querySelector(".dpdpa-progress-fill"),r=this.shadowRoot.querySelector(".dpdpa-progress");if(!t)return;let o=Math.min(100,Math.round(this.store.getState().elapsedMs/this.getPollTimeout()*100));t.style.width=`${o}%`,r&&r.setAttribute("aria-valuenow",String(o))}handleInput(t,r){if(this.fields[t]=r,this.store.getState().errors[t]){let s={...this.store.getState().errors};delete s[t],this.store.setState({errors:s}),this.idleRefs&&this.clearFieldErrorSlot(t)}}handleBlur(t){let r=C(t,this.fields[t]),o={...this.store.getState().errors};r?o[t]=r:delete o[t],this.store.setState({errors:o}),this.updateFieldErrorSlot(t,r)}updateFieldErrorSlot(t,r){if(!this.idleRefs)return;let o=this.idleRefs.fieldErrors[t];r?(o.textContent=r,o.style.display="block"):(o.textContent="",o.style.display="none")}clearFieldErrorSlot(t){if(!this.idleRefs)return;let r=this.idleRefs.fieldErrors[t];r.textContent="",r.style.display="none"}handleSubmit(){let t={company_name:this.fields.company_name.trim(),company_domain:L(this.fields.company_domain),email:this.fields.email.trim()};this.fields=t;let r=se(t);if(Object.keys(r).length>0){this.store.setState({errors:r,generalError:null}),this.render(),this.emitError("One or more fields need your attention.","validation");return}this.store.setState({errors:{},generalError:null}),this.submit()}async submit(){var r,o,s,i;let t=this.makeLead(null);try{(o=(r=this.options).onSubmit)==null||o.call(r,{email:t.email,company_name:t.company_name,company_domain:t.company_domain,timestamp:t.timestamp})}catch(a){console.error("onSubmit handler threw:",a)}x(t),this.store.setState({phase:"submitting"});try{let a=await K({baseUrl:this.getBaseUrl(),body:{company_name:t.company_name,company_domain:t.company_domain}});if(this.destroyed)return;if(a.status==="error"){this.showError(a.message||"We couldn't accept that submission.",!1),this.emitError(a.message||"Submission rejected","submit");return}let l={...t,job_id:a.job_id};x(l);try{(i=(s=this.options).onJobAccepted)==null||i.call(s,a.job_id,l)}catch(d){console.error("onJobAccepted handler threw:",d)}this.startPolling(a.job_id)}catch(a){if(this.destroyed)return;let l=a,d=!l.status||l.status>=500;this.showError(l.message||"We couldn't reach our server. Please try again.",d),this.emitError(l.message||"Submit failed","submit",l.status)}}startPolling(t){this.clearPolling(),this.pollStartedAt=Date.now(),this.pollHiddenSince=null,this.pollHiddenTotalMs=0,this.lastSubStatus=null,this.consecutiveErrors=0,this.store.setState({phase:"polling",subStatus:"pending",elapsedMs:0,jobId:t}),this.schedulePoll()}schedulePoll(){var r;if(this.destroyed)return;if(typeof document!="undefined"&&document.hidden){this.pollHiddenSince===null&&(this.pollHiddenSince=Date.now()),this.pollResumePending=!0;return}let t=(r=this.options.pollIntervalMs)!=null?r:$;this.pollTimer=setTimeout(()=>this.pollTick(),t)}getActiveElapsed(){return Date.now()-this.pollStartedAt-this.pollHiddenTotalMs}async pollTick(){var o,s,i,a;if(this.destroyed)return;let t=this.store.getState().jobId;if(!t)return;let r=this.getActiveElapsed();if(r>=this.getPollTimeout()){this.showError("Report generation is taking longer than expected. Our team has been notified.",!1),this.emitError("Polling timed out","timeout");return}try{let l=await Q({baseUrl:this.getBaseUrl(),jobId:t});if(this.destroyed)return;if(this.consecutiveErrors=0,"status"in l&&l.status==="error"){this.showError(l.message||"Report generation failed.",!0),this.emitError(l.message||"Job errored","poll");return}if(l.status==="complete"&&"report_url"in l&&l.report_url){let p=this.makeLead(t);x(p),this.store.setState({phase:"complete",reportUrl:l.report_url});try{(s=(o=this.options).onComplete)==null||s.call(o,l.report_url,p)}catch(m){console.error("onComplete handler threw:",m)}return}let d=l.status;if(d!==this.lastSubStatus){this.lastSubStatus=d;try{(a=(i=this.options).onStatusChange)==null||a.call(i,d)}catch(p){console.error("onStatusChange handler threw:",p)}}this.store.setState({phase:"polling",subStatus:d,elapsedMs:r}),this.schedulePoll()}catch(l){if(this.destroyed)return;if(this.consecutiveErrors++,this.consecutiveErrors>=A){this.showError("We can't reach our server right now. Please try again.",!0),this.emitError(l instanceof Error?l.message:"Poll failed","poll");return}this.schedulePoll()}}clearPolling(){this.pollTimer&&(clearTimeout(this.pollTimer),this.pollTimer=null),this.pollResumePending=!1}handleVisibilityChange(){if(!this.destroyed){if(document.hidden){this.store.getState().phase==="polling"&&this.pollHiddenSince===null&&(this.pollHiddenSince=Date.now());return}this.pollHiddenSince!==null&&(this.pollHiddenTotalMs+=Date.now()-this.pollHiddenSince,this.pollHiddenSince=null),this.pollResumePending&&this.store.getState().phase==="polling"&&(this.pollResumePending=!1,this.pollTick())}}showError(t,r){this.store.setState({phase:"error",errorMessage:t,retryable:r})}resetToIdle(){this.fields={...de},this.lastSubStatus=null,this.store.setState({phase:"idle",errors:{},generalError:null,errorMessage:"",reportUrl:null,jobId:null,subStatus:"pending",elapsedMs:0})}backToIdle(t){this.store.setState({phase:"idle",errors:{},generalError:t,errorMessage:""})}emitError(t,r,o){var s,i;try{let a=Object.assign(new Error(t),{phase:r,status:o});(i=(s=this.options).onError)==null||i.call(s,a)}catch(a){console.error("onError handler threw:",a)}}makeLead(t){return{email:this.fields.email,company_name:this.fields.company_name,company_domain:this.fields.company_domain,job_id:t,timestamp:new Date().toISOString()}}getBaseUrl(){return(this.options.baseUrl||F).replace(/\/$/,"")}getPollTimeout(){var t;return(t=this.options.pollTimeoutMs)!=null?t:H}};var pe="0.1.0",g=null;function ce(e){N(),g=new v(e),g.init().catch(t=>{var r;try{(r=e.onError)==null||r.call(e,Object.assign(t instanceof Error?t:new Error(String(t)),{phase:"validation"}))}catch(o){console.error("onError handler threw:",o)}})}function N(){g&&(g.destroy(),g=null)}function ue(){return ee()}var He={init:ce,destroy:N,getCapturedLead:ue,version:pe},Ae=He;return xe(Pe);})();
426
+ //# sourceMappingURL=dpdpa-report.global.js.map