@basis-theory/web-elements 3.0.0-beta.2 → 3.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,27 +1,27 @@
1
1
  {
2
- "_index-oREjBjga.js": {
3
- "file": "index-oREjBjga.js",
2
+ "_index-BBfuUaLw.js": {
3
+ "file": "index-BBfuUaLw.js",
4
4
  "name": "index",
5
5
  "dynamicImports": [
6
6
  "src/elements/create-card.ts"
7
7
  ],
8
- "integrity": "sha384-cJIUUFQ6r3cxVoriFOcPwaoiNh3fZEDVQnIz5vHikpBYUCFQXdq9TOK7zWchlegN"
8
+ "integrity": "sha384-uSoWS5QGRB9FD+tnc9SotWKHHU5/nLmr2IVmjU/YMnBOBwg3MOXjsj7VYlFw+Rpm"
9
9
  },
10
10
  "src/elements/create-card.ts": {
11
- "file": "create-card-BuOvimjH.js",
11
+ "file": "create-card-DipDWgph.js",
12
12
  "name": "create-card",
13
13
  "src": "src/elements/create-card.ts",
14
14
  "isDynamicEntry": true,
15
15
  "imports": [
16
- "_index-oREjBjga.js"
16
+ "_index-BBfuUaLw.js"
17
17
  ],
18
- "integrity": "sha384-arcYvaRuIygr99TSB9iejT6KwhxJ61qf7bks9W+lE9+jTK1EmDkAdvliMYj7AyPj"
18
+ "integrity": "sha384-ghGZpmJtjKvmURaj6QaLxtRDDbnc+4EKBMsgYO68iicGxqHHmGAsWyjbWhxBmreJ"
19
19
  },
20
20
  "src/index.ts": {
21
21
  "file": "basis-theory-sdk.umd.js",
22
22
  "name": "index",
23
23
  "src": "src/index.ts",
24
24
  "isEntry": true,
25
- "integrity": "sha384-DDUToQ7bLJ9x04+C8ghbk7ooaa7vb4OCMffjVypI3Hd7THv8C5dQ8jHOjVCNaEwe"
25
+ "integrity": "sha384-ddyMdTUvEA0NROPra0/eWz+jWaUMNSsyhhlM1rCTNGdqTMkLAHqd5G/QQPZ/uJbv"
26
26
  }
27
27
  }
@@ -1,4 +1,4 @@
1
- import { e, B, v } from "./index-oREjBjga.js";
1
+ import { e, B, v } from "./index-BBfuUaLw.js";
2
2
  export {
3
3
  e as buildDate,
4
4
  B as default,
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BasisTheory={})}(this,function(e){"use strict";const t=[/cardnumber/i,/^pan$/i,/accountnumber/i,/^number$/i],r=[/cvv/i,/cvc/i,/cvv2/i,/securitycode/i,/pin/i,/password/i,/secret/i,/token/i,/ssn/i,/track/i],n=e=>t.some(t=>t.test(e)),o=e=>r.some(t=>t.test(e)),a=e=>{const t=e.replace(/\D/g,"");if(t.length<10)return"***";const r=t.substring(0,6),n=t.substring(t.length-4),o=Math.max(t.length-10,6);return`${r}${"*".repeat(o)}${n}`},i=e=>{const t=e.replace(/[\s-]/g,"");return/^\d{13,19}$/.test(t)},s=(e,t)=>null==t?t:"function"==typeof t?"[Function]":"symbol"==typeof t?"[Symbol]":t instanceof RegExp?"[RegExp]":t instanceof Date?t:n(e)?"string"==typeof t?a(t):"***":o(e)?"***":"string"==typeof t&&i(t)?a(t):t,d=(e,t=0,r=new WeakSet)=>{if(t>=5)return"[Max Depth]";if(null==e)return e;if("string"==typeof e)return i(e)?a(e):e;if("object"!=typeof e)return e;if(e instanceof RegExp)return"[RegExp]";if(e instanceof Date)return e;if(r.has(e))return"[Circular]";let n;if(r.add(e),Array.isArray(e))n=e.map(e=>d(e,t+1,r));else{const o={};for(const[n,a]of Object.entries(e)){const e=s(n,a);o[n]=null!==e&&"object"==typeof e?d(e,t+1,r):e}n=o}return r.delete(e),n},l=(e,t)=>t?(t,r)=>{const a=(()=>{const e=new Date;return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}.${String(e.getMilliseconds()).padStart(3,"0")}`})(),i=r?(e=>{const t={};for(const[r,a]of Object.entries(e))if(n(r)||o(r)){const e="string"==typeof a?a.length:"number"==typeof a?String(a).length:0;t[`${r}_length`]=e}else t[r]=d(a);return t})(r):{};console.log(`🔍 [${a}] [${e}] ${t}`,i)}:()=>{},u=(e,t,r)=>{const n=new Error(t);return n.name="BasisTheoryError",n.code=e,n.details=r,Error.captureStackTrace&&Error.captureStackTrace(n,u),n.toJSON=()=>({name:n.name,code:n.code,message:n.message,...n.details&&{details:n.details}}),n},m=(e,t,r)=>{const n=u(e,t,r);return n.name="BasisTheoryError",n},c=(e,t,r)=>{const n=u("VALIDATION_ERROR",e,r);return n.name="ValidationError",n.field=t,n},f=(e,t,r)=>{const n=u("ELEMENT_ERROR",e,t?{elementId:t,...r}:r);return n.name="ElementError",n.elementId=t,n},h=(e,t)=>{const r=u("CONFIGURATION_ERROR",e,t);return r.name="ConfigurationError",r},p={maxRetries:2,initialDelay:500,maxDelay:3e3,backoffFactor:2},g=(e,t)=>{const r=t.initialDelay*Math.pow(t.backoffFactor,e);return Math.min(r,t.maxDelay)},y=e=>new Promise(t=>setTimeout(t,e)),b=(e,t)=>{const r=new Map,n=new Map,o=l("PostMessageClient",t.debug||!1),a=a=>{const{nonce:i,type:s,payload:d,error:l}=a.data||{};if(!s)return;if(a.origin!==t.targetOrigin)return void o("Rejected message (origin mismatch)",{receivedOrigin:a.origin,expectedOrigin:t.targetOrigin,messageType:s});if(a.source!==e.contentWindow)return;if(i){const e=r.get(i);if(e){if(o("Message received",{origin:a.origin,expectedOrigin:t.targetOrigin,type:s,nonce:i}),clearTimeout(e.timeout),r.delete(i),l){const t=m(l.code,`[${l.code}] ${l.message}`);Object.assign(t,{...void 0!==l.status&&{status:l.status},...void 0!==l.statusCode&&{statusCode:l.statusCode},...l.validationErrors&&{validationErrors:l.validationErrors},...l.body&&{body:l.body},...void 0!==l.retryCount&&{retryCount:l.retryCount},...l.details&&{details:l.details}}),e.reject(t)}else e.resolve(d);return}return}const u=n.get(s);u&&u.size>0?(o("Event received",{origin:a.origin,expectedOrigin:t.targetOrigin,type:s,nonce:i,subscriberCount:u.size}),u.forEach(e=>{try{e(d)}catch(r){t.debug&&console.error(`[PostMessage Client] Error in event subscriber for ${s}:`,r)}})):i||o("Event received but no subscribers",{type:s,availableSubscribers:Array.from(n.keys())})};window.addEventListener("message",a);const i="number"==typeof t.retries?{...p,maxRetries:t.retries}:"object"==typeof t.retries?t.retries:p,s=(n,a)=>new Promise((i,s)=>{const d=crypto.randomUUID(),l=Date.now();if(!e.contentWindow)return void s(m("IFRAME_NOT_READY","Iframe not ready"));const u=setTimeout(()=>{r.delete(d),s(m("REQUEST_TIMEOUT",`Request timeout: ${n} (${t.timeout||5e3}ms)`))},t.timeout||5e3);r.set(d,{resolve:i,reject:s,timeout:u,timestamp:l}),o("Sending request",{type:n,nonce:d}),e.contentWindow.postMessage({type:n,nonce:d,timestamp:l,payload:a},t.targetOrigin)});return{sendRequest:async(e,t)=>{let r=null;for(let a=0;a<=i.maxRetries;a++)try{return await s(e,t)}catch(n){r=n;const e=n.message;if(e.startsWith("[HANDLER_ERROR]")||"Client destroyed"===e||"Iframe not ready"===e)throw o("Not retrying error",{error:e,reason:"Non-retriable error"}),n;if(a<i.maxRetries){const t=g(a,i);o("Retrying request",{attempt:a+1,maxRetries:i.maxRetries,delayMs:t,error:e}),await y(t)}}throw r||new Error(`Request failed after ${i.maxRetries} retries: ${e}`)},ping:async(n=1e3)=>{const a=Date.now();o("Starting health check",{timeoutMs:n,iframeReady:!!e.contentWindow,targetOrigin:t.targetOrigin});try{await s("SYS_PING",void 0);const e=Date.now()-a;return o("Health check passed",{latencyMs:e}),e}catch(i){const e=`Health check failed after ${Date.now()-a}ms: ${i.message}. Target: ${t.targetOrigin}`;throw t.debug&&(o(`❌ [PostMessage Client] ${e}`),o(`📊 [PostMessage Client] Pending requests: ${r.size}`)),m("HEALTH_CHECK_FAILED",e)}},subscribe:(e,t)=>(n.has(e)||n.set(e,new Set),n.get(e).add(t),()=>{const r=n.get(e);r&&(r.delete(t),0===r.size&&n.delete(e))}),destroy:()=>{window.removeEventListener("message",a),r.forEach(({timeout:e,reject:t})=>{clearTimeout(e),t(m("CLIENT_DESTROYED","Client destroyed"))}),r.clear(),n.clear()},getPendingCount:()=>r.size}},w=e=>{const t=document.createElement("iframe");return t.src=e.src,t.setAttribute("sandbox",e.sandbox),t.title=e.title,t.setAttribute("allow","payment *"),t.setAttribute("importance","high"),t.style.opacity="0",t},E=e=>{const{elementType:t,elementId:r,client:n,eventTarget:o}=e,a=(e,n)=>{const a=new CustomEvent(e,{detail:{elementType:t,elementId:r,timestamp:Date.now(),...n}});o.dispatchEvent(a)};return{setupSubscriptions:()=>{n.subscribe("EVENT_READY",()=>{a("ready",{})}),n.subscribe("EVENT_VALUE_CHANGED",e=>{const r={isValid:e.isValid,isEmpty:e.isEmpty,error:e.error||null};if("cardNumber"===t){const t={...r,cardBrand:e.cardBrand,last4:e.last4,bin:e.bin,cvvLengths:e.cvvLengths,potentialBrands:e.potentialBrands,matchStrength:e.matchStrength};a("change",t)}else a("change","card"===t?{...r,cardBrand:e.cardBrand,last4:e.last4,bin:e.bin,errors:e.errors||null}:r)}),n.subscribe("EVENT_FOCUS",()=>{a("focus",{})}),n.subscribe("EVENT_BLUR",()=>{a("blur",{})}),n.subscribe("EVENT_ERROR",e=>{a("error",{code:e.code,message:e.message,status:e.status,validationErrors:e.validationErrors,metadata:e.metadata||{}})})},dispatchError:(e,t,r)=>{a("error",{code:e,message:t,metadata:{source:"initialization",originalError:r}})}}},v=(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="cardNumber";return{id:c,type:h,get mounted(){return d},mount:async n=>{if(d)throw f("Element is already mounted");if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/card-number.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Card Number Input"}),a.setAttribute("data-bt-element-id",c),a.setAttribute("data-theme-mode",t.themeMode||"auto"),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y,await i.sendRequest("CMD_SET_CONFIG",{elementId:c,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating");const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing");i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring");i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing");i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}},M=(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="cvv";return{id:c,type:h,get mounted(){return d},mount:async n=>{if(d)throw f("Element is already mounted",c);if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/cvv.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"CVV Input"}),a.setAttribute("data-bt-element-id",c),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y,await i.sendRequest("CMD_SET_CONFIG",{elementId:c,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,showToggle:r.showToggle,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating",c);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly,cardBrand:e.cardBrand,cvvLengths:e.cvvLengths};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing",c);i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring",c);i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing",c);i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}},R=(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="expiry";return{id:c,type:h,get mounted(){return d},mount:async n=>{if(d)throw f("Element is already mounted",c);if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/expiry.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Expiry Date Input"}),a.setAttribute("data-bt-element-id",c),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y,await i.sendRequest("CMD_SET_CONFIG",{elementId:c,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating",c);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing",c);i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring",c);i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing",c);i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}},C=(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="text";if(r.transform&&!(Array.isArray(r.transform)&&2===r.transform.length&&r.transform[0]instanceof RegExp&&"string"==typeof r.transform[1]))throw new TypeError('transform must be a tuple of [RegExp, string]. Example: [/-/g, ""]');return{id:c,type:h,get mounted(){return d},mount:async n=>{if(d)throw f("Element is already mounted",c);if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/text.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Text Input"}),a.setAttribute("data-bt-element-id",c),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y;const n=r.transform?{pattern:r.transform[0].source,flags:r.transform[0].flags,replacement:r.transform[1]}:void 0,s=r.mask?r.mask.map(e=>"string"==typeof e?e:e instanceof RegExp?{source:e.source,flags:e.flags}:e):void 0;await i.sendRequest("CMD_SET_CONFIG",{elementId:c,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,validation:r.validation,required:r.required,maxLength:r.maxLength,password:r.password,inputMode:r.inputMode,mask:s,transform:n,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating",c);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly,required:e.required,maxLength:e.maxLength,password:e.password,inputMode:e.inputMode};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing",c);i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring",c);i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing",c);i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}},T=e=>{if((e=>null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e)(e))return e;if((e=>{if("object"!=typeof e||null===e)return!1;const t=e;return"function"==typeof t.mount&&"function"==typeof t.update&&"function"==typeof t.on})(e)){if(!e.id)throw f("Element is missing id property. Ensure createElement is called after the SDK loads and all elements are mounted before calling tokenize().");return e.id}if(Array.isArray(e))return e.map(T);if("object"==typeof e&&null!==e){const t={};for(const[r,n]of Object.entries(e))t[r]=T(n);return t}return e},x={colors:{primary:"#3b82f6",error:"#ef4444",success:"#10b981",text:{primary:"#1f2937",secondary:"#6b7280",placeholder:"#9ca3af",disabled:"#d1d5db"},background:{default:"#ffffff",hover:"#f9fafb",focus:"#eff6ff",disabled:"#f9fafb"},border:{default:"#d1d5db",hover:"#9ca3af",focus:"#3b82f6",error:"#ef4444"}},typography:{fontFamily:'"Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:{sm:"14px",base:"16px",lg:"18px"},fontWeight:{normal:"400",medium:"500",semibold:"600"},lineHeight:{tight:"1.25",normal:"1.5",relaxed:"1.75"}},spacing:{xs:"4px",sm:"8px",md:"12px",lg:"16px",xl:"24px"},borders:{radius:{none:"0",sm:"2px",base:"4px",md:"6px",lg:"8px",full:"9999px"},width:{thin:"1px",base:"2px",thick:"3px"}},shadows:{none:"none",sm:"0 1px 2px 0 rgba(0, 0, 0, 0.05)",base:"0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)",md:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",lg:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",focus:"0 0 0 3px rgba(59, 130, 246, 0.1)"},transitions:{fast:"150ms cubic-bezier(0.4, 0, 0.2, 1)",base:"200ms cubic-bezier(0.4, 0, 0.2, 1)",slow:"300ms cubic-bezier(0.4, 0, 0.2, 1)"}},O=e=>{var t,r,n,o,a,i,s,d,l,u,m;return e?{colors:{primary:(null==(t=e.colors)?void 0:t.primary)??x.colors.primary,error:(null==(r=e.colors)?void 0:r.error)??x.colors.error,success:(null==(n=e.colors)?void 0:n.success)??x.colors.success,text:{...x.colors.text,...null==(o=e.colors)?void 0:o.text},background:{...x.colors.background,...null==(a=e.colors)?void 0:a.background},border:{...x.colors.border,...null==(i=e.colors)?void 0:i.border}},typography:{...x.typography,...e.typography,fontSize:{...x.typography.fontSize,...null==(s=e.typography)?void 0:s.fontSize},fontWeight:{...x.typography.fontWeight,...null==(d=e.typography)?void 0:d.fontWeight},lineHeight:{...x.typography.lineHeight,...null==(l=e.typography)?void 0:l.lineHeight}},spacing:{...x.spacing,...e.spacing},borders:{radius:{...x.borders.radius,...null==(u=e.borders)?void 0:u.radius},width:{...x.borders.width,...null==(m=e.borders)?void 0:m.width}},shadows:{...x.shadows,...e.shadows},transitions:{...x.transitions,...e.transitions}}:x},k=(e,t,r,n)=>{for(const o of Object.keys(t))r.has(o)||((null==n?void 0:n.has(o))?console.warn(`[BasisTheory] Deprecated option "${o}" in ${e}. ${n.get(o)}`):console.warn(`[BasisTheory] Unknown option "${o}" in ${e}. This option will be ignored. See https://developers.basistheory.com/docs/ for supported options.`))},_=new Set(["elementsBaseUrl","apiBaseUrl","debug","measurePerformance","timeoutMs","retryConfig","themeMode","theme","darkTheme"]),S=new Map([["iframeOrigin",'Use "elementsBaseUrl" instead.']]),D=new Set(["placeholder","ariaLabel","disabled","readOnly"]),I={cardNumber:new Set([...D]),cvv:new Set([...D,"cardBrand","cvvLengths"]),expiry:new Set([...D]),text:new Set([...D,"validation","required","maxLength","password","inputMode","mask","transform"]),card:new Set([...D,"layout","stackAt","iconPosition","cardBrands"])},A=(e,t={},r)=>{(e=>{if(!e||"string"!=typeof e||0===e.trim().length)throw h("API key is required")})(e);const n=((e={})=>{var t,r,n;k("SDKOptions",e,_,S);const o=e.elementsBaseUrl||e.iframeOrigin;if(void 0!==o){if("string"!=typeof o||0===o.trim().length)throw h("elementsBaseUrl must be a non-empty string");try{new URL(o)}catch{throw h("elementsBaseUrl must be a valid URL")}}if(void 0!==e.apiBaseUrl){if("string"!=typeof e.apiBaseUrl||0===e.apiBaseUrl.trim().length)throw h("apiBaseUrl must be a non-empty string");try{new URL(e.apiBaseUrl)}catch{throw h("apiBaseUrl must be a valid URL")}}if(void 0!==e.debug&&"boolean"!=typeof e.debug)throw h("debug must be a boolean");if(void 0!==e.measurePerformance&&"boolean"!=typeof e.measurePerformance)throw h("measurePerformance must be a boolean");if(void 0!==e.timeoutMs&&("number"!=typeof e.timeoutMs||e.timeoutMs<=0))throw h("timeoutMs must be a positive number");const a={maxRetries:(null==(t=e.retryConfig)?void 0:t.maxRetries)??3,delayMs:(null==(r=e.retryConfig)?void 0:r.delayMs)??1e3,backoffFactor:(null==(n=e.retryConfig)?void 0:n.backoffFactor)??2};if("number"!=typeof a.maxRetries||a.maxRetries<0)throw h("maxRetries must be a non-negative number");if("number"!=typeof a.delayMs||a.delayMs<=0)throw h("retryConfig.delayMs must be a positive number");if("number"!=typeof a.backoffFactor||a.backoffFactor<1)throw h("retryConfig.backoffFactor must be >= 1");const i=e.themeMode||"auto";if(!["light","dark","auto"].includes(i))throw h('themeMode must be "light", "dark", or "auto"');const s=o||"https://js.basistheory.com/3.0.0-beta.2/elements";return{iframeOrigin:new URL(s).origin,elementsBaseUrl:s,apiBaseUrl:e.apiBaseUrl,debug:e.debug??!1,measurePerformance:e.measurePerformance??!1,timeoutMs:e.timeoutMs||3e4,themeMode:i,theme:O(e.theme),darkTheme:e.darkTheme?O(e.darkTheme):void 0,retryConfig:a}})(t),o=l("SDK",n.debug||!1);o("SDK initialized",{apiKeyPrefix:e.substring(0,7)+"...",elementsBaseUrl:n.elementsBaseUrl,iframeOrigin:n.iframeOrigin,debug:n.debug||!1});const a=new Map;let i=null,s=null,d=null,m=!1,p=t.themeMode||"auto",g=null;const y={cardNumber:v,cvv:M,expiry:R,text:C},w={card:async()=>{if(!g){const e=await Promise.resolve().then(()=>L);g=e.createCardElement}return g}},E=()=>d||(m||(m=!0,d=x()),d),x=async()=>{if(i)return void o("Coordinator already initialized",{loaded:null!==i.contentWindow});o("Initializing coordinator iframe",{elementsBaseUrl:n.elementsBaseUrl}),i=document.createElement("iframe"),i.setAttribute("name","bt-coordinator"),i.setAttribute("title","BasisTheory Coordinator"),i.setAttribute("role","none"),i.style.border="none",i.style.width="0",i.style.height="0",i.style.position="absolute",i.style.top="-9999px",i.style.left="-9999px";const t=n.elementsBaseUrl.endsWith("/")?n.elementsBaseUrl:`${n.elementsBaseUrl}/`,r=new URL("coordinator.html",t);r.searchParams.set("parentOrigin",window.location.origin),i.src=r.toString(),document.body.appendChild(i),o("Coordinator iframe mounted",{url:i.src}),await new Promise((e,t)=>{const r=setTimeout(()=>{t(new Error(`Coordinator load timeout (${n.timeoutMs}ms). Try increasing timeoutMs for slow connections.`))},n.timeoutMs);i.addEventListener("load",()=>{clearTimeout(r),o("Coordinator iframe loaded"),e()},{once:!0})}),s=b(i,{targetOrigin:new URL(n.elementsBaseUrl).origin,timeout:3e4,retries:3,debug:n.debug||!1}),o("Coordinator PostMessage client created"),await s.sendRequest("CMD_SET_CONFIG",{apiKey:e,apiBaseUrl:n.apiBaseUrl,apiTimeout:3e4,apiRetries:3,debug:n.debug||!1,theme:n.theme,darkTheme:n.darkTheme,themeMode:n.themeMode}),o("Coordinator initialized successfully")},D={createElement:(t,r)=>{const s=y[t],d=w[t];if(!s&&!d)throw h(`Unknown element type: ${t}`);r&&((e,t={})=>{if(k(`ElementOptions (${e})`,t,I[e]),void 0!==t.placeholder)if("card"===e){if("object"!=typeof t.placeholder||null===t.placeholder)throw h("placeholder for card element must be an object with cardNumber, expiryDate, and cvv keys")}else if("string"!=typeof t.placeholder)throw h("placeholder must be a string");if(void 0!==t.disabled&&"boolean"!=typeof t.disabled)throw h("disabled must be a boolean");if(void 0!==t.readOnly&&"boolean"!=typeof t.readOnly)throw h("readOnly must be a boolean");if(void 0!==t.ariaLabel&&"string"!=typeof t.ariaLabel)throw h("ariaLabel must be a string");if("text"===e){if(void 0!==t.maxLength&&("number"!=typeof t.maxLength||t.maxLength<=0))throw h("maxLength must be a positive number");if(void 0!==t.password&&"boolean"!=typeof t.password)throw h("password must be a boolean");if(void 0!==t.required&&"boolean"!=typeof t.required)throw h("required must be a boolean");if(void 0!==t.validation&&!(t.validation instanceof RegExp))throw h("validation must be a RegExp");if(t.transform&&!(Array.isArray(t.transform)&&2===t.transform.length&&t.transform[0]instanceof RegExp&&"string"==typeof t.transform[1]))throw h('transform must be a tuple of [RegExp, string]. Example: [/-/g, ""]')}if("card"===e){const e=t;if(void 0!==e.layout&&!["row","column","auto"].includes(e.layout))throw h('layout must be "row", "column", or "auto"');if(void 0!==e.stackAt&&("number"!=typeof e.stackAt||e.stackAt<=0))throw h("stackAt must be a positive number");if(void 0!==e.iconPosition&&!["left","right","none"].includes(e.iconPosition))throw h('iconPosition must be "left", "right", or "none"');if(void 0!==e.cardBrands){if(!Array.isArray(e.cardBrands))throw h("cardBrands must be an array of strings");if(e.cardBrands.some(e=>"string"!=typeof e))throw h("All cardBrands must be strings")}}})(t,r);const l=`${t}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`;let u;if(o("Creating element (sync)",{type:t,elementId:l,coordinatorInitialized:null!==i,isLazyLoaded:!!d}),s)u=s(e,n,r,l,E);else{let o=null,a=null;const i=async()=>{a||(a=(async()=>{const t=await d();o=t(e,n,r,l,E)})()),await a};u={id:l,type:t,get mounted(){return(null==o?void 0:o.mounted)??!1},get fields(){return null==o?void 0:o.fields},mount:async e=>(await i(),o.mount(e)),unmount:()=>{if(!o)throw f("Element not initialized");return o.unmount()},update:async e=>{if(!o)throw f("Element not initialized");return o.update(e)},focus:()=>{if(!o)throw f("Element not initialized");return o.focus()},blur:()=>{if(!o)throw f("Element not initialized");return o.blur()},clear:()=>{if(!o)throw f("Element not initialized");return o.clear()},on:(e,t)=>o?o.on(e,t):(i().then(()=>o.on(e,t)),()=>{})}}return a.set(u.id,u),"cardNumber"===t&&u.on("change",e=>{const{cardBrand:t,cvvLengths:r}=e.detail;if(o("Card number change event received",{cardBrand:t,cvvLengths:r,cvvElementsCount:Array.from(a.values()).filter(e=>"cvv"===e.type).length}),t&&"Unknown"!==t&&r)for(const[n,i]of a)"cvv"===i.type&&i.mounted&&(o("Coordinating CVV element with card brand",{cvvElementId:n,cardBrand:t,cvvLengths:r,mounted:i.mounted}),i.update({cardBrand:t,cvvLengths:r}).catch(e=>{o("Failed to update CVV element with card brand",{cvvElementId:n,cardBrand:t,error:e.message})}))}),u},tokenize:async(e,t)=>{if(o("tokenize called",{hasPayload:!!e,hasOptions:!!t,coordinatorReady:!!s}),s||(o("Waiting for coordinator initialization"),await x()),!s)throw(()=>{const e=u("COORDINATOR_ERROR","Coordinator failed to initialize",void 0);return e.name="CoordinatorError",e})();try{const r=e?T(e):{};o("Element references resolved",{originalPayload:!!e,resolvedPayload:!!r}),o("Delegating tokenization to coordinator");const n=await s.sendRequest("CMD_TOKENIZE",{payload:r,options:t});return o("tokenize successful",{tokenId:n.id}),n}catch(r){throw o("tokenize failed",{error:r.message}),r}},tokens:{create:async e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw c("Token data must be a non-null object");if(o("tokens.create called",{type:e.type,hasData:!!e.data}),s||(o("Waiting for coordinator initialization"),await x()),!s)throw new Error("Coordinator failed to initialize");try{const t={...e,data:T(e.data)};o("Element references resolved for tokens.create",{resolvedData:!!t});const r=await s.sendRequest("CMD_TOKENS_CREATE",{data:t});return o("tokens.create successful",{tokenId:r.id}),r}catch(t){throw o("tokens.create failed",{error:t.message}),t}},retrieve:async(e,t)=>{if(o("tokens.retrieve called",{tokenId:e,hasSessionKey:!!(null==t?void 0:t.apiKey)}),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const r=await s.sendRequest("CMD_TOKENS_RETRIEVE",{id:e,apiKey:null==t?void 0:t.apiKey});return o("tokens.retrieve successful",{tokenId:r.id}),r}catch(r){throw o("tokens.retrieve failed",{error:r.message}),r}},update:async(e,t)=>{if(o("tokens.update called",{tokenId:e}),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const r=t.data?{...t,data:T(t.data)}:t,n=await s.sendRequest("CMD_TOKENS_UPDATE",{id:e,data:r});return o("tokens.update successful",{tokenId:n.id}),n}catch(r){throw o("tokens.update failed",{error:r.message}),r}},encrypt:async(e,t,r)=>{if(o("tokens.encrypt called",{isSingleToken:"type"in e&&"data"in e,keyId:r}),!e||"object"!=typeof e)throw c("tokenData must be an object");if(!t||"string"!=typeof t)throw c("publicKeyPEM is required");if(!r||"string"!=typeof r)throw c("keyId is required");if(s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const n=T(e);o("Element references resolved for tokens.encrypt",{originalData:!!e,resolvedData:!!n});const a=await s.sendRequest("CMD_TOKENS_ENCRYPT",{tokenRequests:n,publicKeyPEM:t,keyId:r});return o("tokens.encrypt successful",{isSingleToken:"encrypted"in a&&"type"in a}),a}catch(n){throw o("tokens.encrypt failed",{error:n.message}),n}}},sessions:{create:async()=>{if(o("sessions.create called"),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const e=await s.sendRequest("CMD_SESSIONS_CREATE",{});return o("sessions.create successful",{nonce:e.nonce,expiresAt:e.expires_at}),e}catch(e){throw o("sessions.create failed",{error:e.message}),e}}},tokenIntents:{create:async(e,t)=>{if(o("tokenIntents.create called",{type:e.type,hasData:!!e.data,hasOptions:!!t}),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const r=T(e.data);o("Element references resolved for token intent");const n=await s.sendRequest("CMD_TOKEN_INTENTS_CREATE",{type:e.type,data:r,options:t});return o("tokenIntents.create successful",{intentId:n.id}),n}catch(r){throw o("tokenIntents.create failed",{error:r.message}),r}},get:async(e,t)=>{if(o("tokenIntents.get called",{intentId:e}),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const r=await s.sendRequest("CMD_TOKEN_INTENTS_GET",{id:e,options:t});return o("tokenIntents.get successful",{intentId:r.id}),r}catch(r){throw o("tokenIntents.get failed",{error:r.message}),r}}},updateThemeMode:async e=>{o("updateThemeMode called",{oldMode:p,newMode:e,mountedElements:Array.from(a.values()).filter(e=>e.mounted).length}),p=e;const t=[];for(const[r,n]of a)if(n.mounted){o("Sending theme mode update to element",{elementId:r,elementType:n.type,mode:e});const a=document.querySelector(`iframe[data-bt-element-id="${n.id}"]`);a&&a.setAttribute("data-theme-mode",e);const i=n.update({themeMode:e}).catch(e=>{o("Failed to update theme mode for element",{elementId:r,error:e.message})});t.push(i)}await Promise.all(t),o("Theme mode updated for all mounted elements",{mode:e,updatedCount:Array.from(a.values()).filter(e=>e.mounted).length})}};if(r&&r.length>0){o("Draining command queue from loader",{queueLength:r.length,commands:r.map(e=>e.method)});for(const e of r)try{const t=D[e.method];if(!t)throw new Error(`Unknown method: ${e.method}`);o("Replaying queued command",{method:e.method,argsCount:e.args.length});const r=t(...e.args);r&&"function"==typeof r.then?r.then(t=>{o("Queued command completed (async)",{method:e.method}),e.resolve(t)}).catch(t=>{o("Queued command failed (async)",{method:e.method,error:t.message}),e.reject(t)}):(o("Queued command completed (sync)",{method:e.method}),e.resolve(r))}catch(A){o("Queued command failed (sync)",{method:e.method,error:A.message}),e.reject(A)}o("Command queue drain complete",{processedCount:r.length})}return D};"undefined"!=typeof window&&"undefined"!=typeof document&&document.currentScript&&!window.BasisTheory&&(window.BasisTheory=A),"undefined"!=typeof window&&(window.__BasisTheorySDK__=A);const L=Object.freeze(Object.defineProperty({__proto__:null,createCardElement:(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="card",p=e=>({id:e,type:"card",get mounted(){return d},mount:()=>{throw f("Sub-field refs cannot be mounted independently")},unmount:()=>{},update:()=>Promise.resolve(),focus:()=>{},blur:()=>{},clear:()=>{},on:()=>()=>{}});return{id:c,type:h,get mounted(){return d},fields:{number:p(`${c}__number`),expiryDate:p(`${c}__expiry`),cvc:p(`${c}__cvc`)},mount:async n=>{if(d)throw f("Element is already mounted");if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/card.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Card Input"}),a.setAttribute("data-bt-element-id",c),a.setAttribute("data-theme-mode",t.themeMode||"auto"),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y,await i.sendRequest("CMD_SET_CONFIG",{elementId:c,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,placeholder:r.placeholder,style:r.style,disabled:r.disabled,readOnly:r.readOnly,layout:r.layout||"auto",stackAt:r.stackAt||400,iconPosition:r.iconPosition||"left",cardBrands:r.cardBrands,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating");const r=e,n={placeholder:r.placeholder,style:r.style,disabled:r.disabled,readOnly:r.readOnly,layout:r.layout,stackAt:r.stackAt,iconPosition:r.iconPosition,cardBrands:r.cardBrands};void 0!==e.themeMode&&(n.themeMode=e.themeMode,n.theme=t.theme,n.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",n)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing");i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring");i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing");i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}}},Symbol.toStringTag,{value:"Module"}));e.buildDate="2026-04-13T17:05:21.283Z",e.default=A,e.version="3.0.0-beta.2",Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BasisTheory={})}(this,function(e){"use strict";const t=[/cardnumber/i,/^pan$/i,/accountnumber/i,/^number$/i],r=[/cvv/i,/cvc/i,/cvv2/i,/securitycode/i,/pin/i,/password/i,/secret/i,/token/i,/ssn/i,/track/i],n=e=>t.some(t=>t.test(e)),o=e=>r.some(t=>t.test(e)),a=e=>{const t=e.replace(/\D/g,"");if(t.length<10)return"***";const r=t.substring(0,6),n=t.substring(t.length-4),o=Math.max(t.length-10,6);return`${r}${"*".repeat(o)}${n}`},i=e=>{const t=e.replace(/[\s-]/g,"");return/^\d{13,19}$/.test(t)},s=(e,t)=>null==t?t:"function"==typeof t?"[Function]":"symbol"==typeof t?"[Symbol]":t instanceof RegExp?"[RegExp]":t instanceof Date?t:n(e)?"string"==typeof t?a(t):"***":o(e)?"***":"string"==typeof t&&i(t)?a(t):t,d=(e,t=0,r=new WeakSet)=>{if(t>=5)return"[Max Depth]";if(null==e)return e;if("string"==typeof e)return i(e)?a(e):e;if("object"!=typeof e)return e;if(e instanceof RegExp)return"[RegExp]";if(e instanceof Date)return e;if(r.has(e))return"[Circular]";let n;if(r.add(e),Array.isArray(e))n=e.map(e=>d(e,t+1,r));else{const o={};for(const[n,a]of Object.entries(e)){const e=s(n,a);o[n]=null!==e&&"object"==typeof e?d(e,t+1,r):e}n=o}return r.delete(e),n},l=(e,t)=>t?(t,r)=>{const a=(()=>{const e=new Date;return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}.${String(e.getMilliseconds()).padStart(3,"0")}`})(),i=r?(e=>{const t={};for(const[r,a]of Object.entries(e))if(n(r)||o(r)){const e="string"==typeof a?a.length:"number"==typeof a?String(a).length:0;t[`${r}_length`]=e}else t[r]=d(a);return t})(r):{};console.log(`🔍 [${a}] [${e}] ${t}`,i)}:()=>{},u=(e,t,r)=>{const n=new Error(t);return n.name="BasisTheoryError",n.code=e,n.details=r,Error.captureStackTrace&&Error.captureStackTrace(n,u),n.toJSON=()=>({name:n.name,code:n.code,message:n.message,...n.details&&{details:n.details}}),n},m=(e,t,r)=>{const n=u(e,t,r);return n.name="BasisTheoryError",n},c=(e,t,r)=>{const n=u("VALIDATION_ERROR",e,r);return n.name="ValidationError",n.field=t,n},f=(e,t,r)=>{const n=u("ELEMENT_ERROR",e,t?{elementId:t,...r}:r);return n.name="ElementError",n.elementId=t,n},h=(e,t)=>{const r=u("CONFIGURATION_ERROR",e,t);return r.name="ConfigurationError",r},p={maxRetries:2,initialDelay:500,maxDelay:3e3,backoffFactor:2},g=(e,t)=>{const r=t.initialDelay*Math.pow(t.backoffFactor,e);return Math.min(r,t.maxDelay)},y=e=>new Promise(t=>setTimeout(t,e)),b=(e,t)=>{const r=new Map,n=new Map,o=l("PostMessageClient",t.debug||!1),a=a=>{const{nonce:i,type:s,payload:d,error:l}=a.data||{};if(!s)return;if(a.origin!==t.targetOrigin)return void o("Rejected message (origin mismatch)",{receivedOrigin:a.origin,expectedOrigin:t.targetOrigin,messageType:s});if(a.source!==e.contentWindow)return;if(i){const e=r.get(i);if(e){if(o("Message received",{origin:a.origin,expectedOrigin:t.targetOrigin,type:s,nonce:i}),clearTimeout(e.timeout),r.delete(i),l){const t=m(l.code,`[${l.code}] ${l.message}`);Object.assign(t,{...void 0!==l.status&&{status:l.status},...void 0!==l.statusCode&&{statusCode:l.statusCode},...l.validationErrors&&{validationErrors:l.validationErrors},...l.body&&{body:l.body},...void 0!==l.retryCount&&{retryCount:l.retryCount},...l.details&&{details:l.details}}),e.reject(t)}else e.resolve(d);return}return}const u=n.get(s);u&&u.size>0?(o("Event received",{origin:a.origin,expectedOrigin:t.targetOrigin,type:s,nonce:i,subscriberCount:u.size}),u.forEach(e=>{try{e(d)}catch(r){t.debug&&console.error(`[PostMessage Client] Error in event subscriber for ${s}:`,r)}})):i||o("Event received but no subscribers",{type:s,availableSubscribers:Array.from(n.keys())})};window.addEventListener("message",a);const i="number"==typeof t.retries?{...p,maxRetries:t.retries}:"object"==typeof t.retries?t.retries:p,s=(n,a)=>new Promise((i,s)=>{const d=crypto.randomUUID(),l=Date.now();if(!e.contentWindow)return void s(m("IFRAME_NOT_READY","Iframe not ready"));const u=setTimeout(()=>{r.delete(d),s(m("REQUEST_TIMEOUT",`Request timeout: ${n} (${t.timeout||5e3}ms)`))},t.timeout||5e3);r.set(d,{resolve:i,reject:s,timeout:u,timestamp:l}),o("Sending request",{type:n,nonce:d}),e.contentWindow.postMessage({type:n,nonce:d,timestamp:l,payload:a},t.targetOrigin)});return{sendRequest:async(e,t)=>{let r=null;for(let a=0;a<=i.maxRetries;a++)try{return await s(e,t)}catch(n){r=n;const e=n.message;if(e.startsWith("[HANDLER_ERROR]")||"Client destroyed"===e||"Iframe not ready"===e)throw o("Not retrying error",{error:e,reason:"Non-retriable error"}),n;if(a<i.maxRetries){const t=g(a,i);o("Retrying request",{attempt:a+1,maxRetries:i.maxRetries,delayMs:t,error:e}),await y(t)}}throw r||new Error(`Request failed after ${i.maxRetries} retries: ${e}`)},ping:async(n=1e3)=>{const a=Date.now();o("Starting health check",{timeoutMs:n,iframeReady:!!e.contentWindow,targetOrigin:t.targetOrigin});try{await s("SYS_PING",void 0);const e=Date.now()-a;return o("Health check passed",{latencyMs:e}),e}catch(i){const e=`Health check failed after ${Date.now()-a}ms: ${i.message}. Target: ${t.targetOrigin}`;throw t.debug&&(o(`❌ [PostMessage Client] ${e}`),o(`📊 [PostMessage Client] Pending requests: ${r.size}`)),m("HEALTH_CHECK_FAILED",e)}},subscribe:(e,t)=>(n.has(e)||n.set(e,new Set),n.get(e).add(t),()=>{const r=n.get(e);r&&(r.delete(t),0===r.size&&n.delete(e))}),destroy:()=>{window.removeEventListener("message",a),r.forEach(({timeout:e,reject:t})=>{clearTimeout(e),t(m("CLIENT_DESTROYED","Client destroyed"))}),r.clear(),n.clear()},getPendingCount:()=>r.size}},w=e=>{const t=document.createElement("iframe");return t.src=e.src,t.setAttribute("sandbox",e.sandbox),t.title=e.title,t.setAttribute("allow","payment *"),t.setAttribute("importance","high"),t.style.opacity="0",t},E=e=>{const{elementType:t,elementId:r,client:n,eventTarget:o}=e,a=(e,n)=>{const a=new CustomEvent(e,{detail:{elementType:t,elementId:r,timestamp:Date.now(),...n}});o.dispatchEvent(a)};return{setupSubscriptions:()=>{n.subscribe("EVENT_READY",()=>{a("ready",{})}),n.subscribe("EVENT_VALUE_CHANGED",e=>{const r={isValid:e.isValid,isEmpty:e.isEmpty,error:e.error||null};if("cardNumber"===t){const t={...r,cardBrand:e.cardBrand,last4:e.last4,bin:e.bin,cvvLengths:e.cvvLengths,potentialBrands:e.potentialBrands,matchStrength:e.matchStrength};a("change",t)}else a("change","card"===t?{...r,cardBrand:e.cardBrand,last4:e.last4,bin:e.bin,errors:e.errors||null}:r)}),n.subscribe("EVENT_FOCUS",()=>{a("focus",{})}),n.subscribe("EVENT_BLUR",()=>{a("blur",{})}),n.subscribe("EVENT_ERROR",e=>{a("error",{code:e.code,message:e.message,status:e.status,validationErrors:e.validationErrors,metadata:e.metadata||{}})})},dispatchError:(e,t,r)=>{a("error",{code:e,message:t,metadata:{source:"initialization",originalError:r}})}}},v=(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="cardNumber";return{id:c,type:h,get mounted(){return d},mount:async n=>{if(d)throw f("Element is already mounted");if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/card-number.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Card Number Input"}),a.setAttribute("data-bt-element-id",c),a.setAttribute("data-theme-mode",t.themeMode||"auto"),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y,await i.sendRequest("CMD_SET_CONFIG",{elementId:c,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating");const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing");i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring");i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing");i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}},M=(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="cvv";return{id:c,type:h,get mounted(){return d},mount:async n=>{if(d)throw f("Element is already mounted",c);if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/cvv.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"CVV Input"}),a.setAttribute("data-bt-element-id",c),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y,await i.sendRequest("CMD_SET_CONFIG",{elementId:c,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,showToggle:r.showToggle,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating",c);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly,cardBrand:e.cardBrand,cvvLengths:e.cvvLengths};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing",c);i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring",c);i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing",c);i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}},R=(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="expiry";return{id:c,type:h,get mounted(){return d},mount:async n=>{if(d)throw f("Element is already mounted",c);if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/expiry.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Expiry Date Input"}),a.setAttribute("data-bt-element-id",c),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y,await i.sendRequest("CMD_SET_CONFIG",{elementId:c,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating",c);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing",c);i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring",c);i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing",c);i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}},C=(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="text";if(r.transform&&!(Array.isArray(r.transform)&&2===r.transform.length&&r.transform[0]instanceof RegExp&&"string"==typeof r.transform[1]))throw new TypeError('transform must be a tuple of [RegExp, string]. Example: [/-/g, ""]');return{id:c,type:h,get mounted(){return d},mount:async n=>{if(d)throw f("Element is already mounted",c);if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/text.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Text Input"}),a.setAttribute("data-bt-element-id",c),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y;const n=r.transform?{pattern:r.transform[0].source,flags:r.transform[0].flags,replacement:r.transform[1]}:void 0,s=r.mask?r.mask.map(e=>"string"==typeof e?e:e instanceof RegExp?{source:e.source,flags:e.flags}:e):void 0;await i.sendRequest("CMD_SET_CONFIG",{elementId:c,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,validation:r.validation,required:r.required,maxLength:r.maxLength,password:r.password,inputMode:r.inputMode,mask:s,transform:n,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating",c);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly,required:e.required,maxLength:e.maxLength,password:e.password,inputMode:e.inputMode};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing",c);i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring",c);i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing",c);i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}},T=e=>{if((e=>null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e)(e))return e;if((e=>{if("object"!=typeof e||null===e)return!1;const t=e;return"function"==typeof t.mount&&"function"==typeof t.update&&"function"==typeof t.on})(e)){if(!e.id)throw f("Element is missing id property. Ensure createElement is called after the SDK loads and all elements are mounted before calling tokenize().");return e.id}if(Array.isArray(e))return e.map(T);if("object"==typeof e&&null!==e){const t={};for(const[r,n]of Object.entries(e))t[r]=T(n);return t}return e},x={colors:{primary:"#3b82f6",error:"#ef4444",success:"#10b981",text:{primary:"#1f2937",secondary:"#6b7280",placeholder:"#9ca3af",disabled:"#d1d5db"},background:{default:"#ffffff",hover:"#f9fafb",focus:"#eff6ff",disabled:"#f9fafb"},border:{default:"#d1d5db",hover:"#9ca3af",focus:"#3b82f6",error:"#ef4444"}},typography:{fontFamily:'"Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:{sm:"14px",base:"16px",lg:"18px"},fontWeight:{normal:"400",medium:"500",semibold:"600"},lineHeight:{tight:"1.25",normal:"1.5",relaxed:"1.75"}},spacing:{xs:"4px",sm:"8px",md:"12px",lg:"16px",xl:"24px"},borders:{radius:{none:"0",sm:"2px",base:"4px",md:"6px",lg:"8px",full:"9999px"},width:{thin:"1px",base:"2px",thick:"3px"}},shadows:{none:"none",sm:"0 1px 2px 0 rgba(0, 0, 0, 0.05)",base:"0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)",md:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",lg:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",focus:"0 0 0 3px rgba(59, 130, 246, 0.1)"},transitions:{fast:"150ms cubic-bezier(0.4, 0, 0.2, 1)",base:"200ms cubic-bezier(0.4, 0, 0.2, 1)",slow:"300ms cubic-bezier(0.4, 0, 0.2, 1)"}},O=e=>{var t,r,n,o,a,i,s,d,l,u,m;return e?{colors:{primary:(null==(t=e.colors)?void 0:t.primary)??x.colors.primary,error:(null==(r=e.colors)?void 0:r.error)??x.colors.error,success:(null==(n=e.colors)?void 0:n.success)??x.colors.success,text:{...x.colors.text,...null==(o=e.colors)?void 0:o.text},background:{...x.colors.background,...null==(a=e.colors)?void 0:a.background},border:{...x.colors.border,...null==(i=e.colors)?void 0:i.border}},typography:{...x.typography,...e.typography,fontSize:{...x.typography.fontSize,...null==(s=e.typography)?void 0:s.fontSize},fontWeight:{...x.typography.fontWeight,...null==(d=e.typography)?void 0:d.fontWeight},lineHeight:{...x.typography.lineHeight,...null==(l=e.typography)?void 0:l.lineHeight}},spacing:{...x.spacing,...e.spacing},borders:{radius:{...x.borders.radius,...null==(u=e.borders)?void 0:u.radius},width:{...x.borders.width,...null==(m=e.borders)?void 0:m.width}},shadows:{...x.shadows,...e.shadows},transitions:{...x.transitions,...e.transitions}}:x},k=(e,t,r,n)=>{for(const o of Object.keys(t))r.has(o)||((null==n?void 0:n.has(o))?console.warn(`[BasisTheory] Deprecated option "${o}" in ${e}. ${n.get(o)}`):console.warn(`[BasisTheory] Unknown option "${o}" in ${e}. This option will be ignored. See https://developers.basistheory.com/docs/ for supported options.`))},_=new Set(["elementsBaseUrl","apiBaseUrl","debug","measurePerformance","timeoutMs","retryConfig","themeMode","theme","darkTheme"]),S=new Map([["iframeOrigin",'Use "elementsBaseUrl" instead.']]),D=new Set(["placeholder","ariaLabel","disabled","readOnly"]),I={cardNumber:new Set([...D]),cvv:new Set([...D,"cardBrand","cvvLengths"]),expiry:new Set([...D]),text:new Set([...D,"validation","required","maxLength","password","inputMode","mask","transform"]),card:new Set([...D,"layout","stackAt","iconPosition","cardBrands"])},A=(e,t={},r)=>{(e=>{if(!e||"string"!=typeof e||0===e.trim().length)throw h("API key is required")})(e);const n=((e={})=>{var t,r,n;k("SDKOptions",e,_,S);const o=e.elementsBaseUrl||e.iframeOrigin;if(void 0!==o){if("string"!=typeof o||0===o.trim().length)throw h("elementsBaseUrl must be a non-empty string");try{new URL(o)}catch{throw h("elementsBaseUrl must be a valid URL")}}if(void 0!==e.apiBaseUrl){if("string"!=typeof e.apiBaseUrl||0===e.apiBaseUrl.trim().length)throw h("apiBaseUrl must be a non-empty string");try{new URL(e.apiBaseUrl)}catch{throw h("apiBaseUrl must be a valid URL")}}if(void 0!==e.debug&&"boolean"!=typeof e.debug)throw h("debug must be a boolean");if(void 0!==e.measurePerformance&&"boolean"!=typeof e.measurePerformance)throw h("measurePerformance must be a boolean");if(void 0!==e.timeoutMs&&("number"!=typeof e.timeoutMs||e.timeoutMs<=0))throw h("timeoutMs must be a positive number");const a={maxRetries:(null==(t=e.retryConfig)?void 0:t.maxRetries)??3,delayMs:(null==(r=e.retryConfig)?void 0:r.delayMs)??1e3,backoffFactor:(null==(n=e.retryConfig)?void 0:n.backoffFactor)??2};if("number"!=typeof a.maxRetries||a.maxRetries<0)throw h("maxRetries must be a non-negative number");if("number"!=typeof a.delayMs||a.delayMs<=0)throw h("retryConfig.delayMs must be a positive number");if("number"!=typeof a.backoffFactor||a.backoffFactor<1)throw h("retryConfig.backoffFactor must be >= 1");const i=e.themeMode||"auto";if(!["light","dark","auto"].includes(i))throw h('themeMode must be "light", "dark", or "auto"');const s=o||"https://js.basistheory.com/3.0.0-beta.3/elements";return{iframeOrigin:new URL(s).origin,elementsBaseUrl:s,apiBaseUrl:e.apiBaseUrl,debug:e.debug??!1,measurePerformance:e.measurePerformance??!1,timeoutMs:e.timeoutMs||3e4,themeMode:i,theme:O(e.theme),darkTheme:e.darkTheme?O(e.darkTheme):void 0,retryConfig:a}})(t),o=l("SDK",n.debug||!1);o("SDK initialized",{apiKeyPrefix:e.substring(0,7)+"...",elementsBaseUrl:n.elementsBaseUrl,iframeOrigin:n.iframeOrigin,debug:n.debug||!1});const a=new Map;let i=null,s=null,d=null,m=!1,p=t.themeMode||"auto",g=null;const y={cardNumber:v,cvv:M,expiry:R,text:C},w={card:async()=>{if(!g){const e=await Promise.resolve().then(()=>L);g=e.createCardElement}return g}},E=()=>d||(m||(m=!0,d=x()),d),x=async()=>{if(i)return void o("Coordinator already initialized",{loaded:null!==i.contentWindow});o("Initializing coordinator iframe",{elementsBaseUrl:n.elementsBaseUrl}),i=document.createElement("iframe"),i.setAttribute("name","bt-coordinator"),i.setAttribute("title","BasisTheory Coordinator"),i.setAttribute("role","none"),i.style.border="none",i.style.width="0",i.style.height="0",i.style.position="absolute",i.style.top="-9999px",i.style.left="-9999px";const t=n.elementsBaseUrl.endsWith("/")?n.elementsBaseUrl:`${n.elementsBaseUrl}/`,r=new URL("coordinator.html",t);r.searchParams.set("parentOrigin",window.location.origin),i.src=r.toString(),document.body.appendChild(i),o("Coordinator iframe mounted",{url:i.src}),await new Promise((e,t)=>{const r=setTimeout(()=>{t(new Error(`Coordinator load timeout (${n.timeoutMs}ms). Try increasing timeoutMs for slow connections.`))},n.timeoutMs);i.addEventListener("load",()=>{clearTimeout(r),o("Coordinator iframe loaded"),e()},{once:!0})}),s=b(i,{targetOrigin:new URL(n.elementsBaseUrl).origin,timeout:3e4,retries:3,debug:n.debug||!1}),o("Coordinator PostMessage client created"),await s.sendRequest("CMD_SET_CONFIG",{apiKey:e,apiBaseUrl:n.apiBaseUrl,apiTimeout:3e4,apiRetries:3,debug:n.debug||!1,theme:n.theme,darkTheme:n.darkTheme,themeMode:n.themeMode}),o("Coordinator initialized successfully")},D={createElement:(t,r)=>{const s=y[t],d=w[t];if(!s&&!d)throw h(`Unknown element type: ${t}`);r&&((e,t={})=>{if(k(`ElementOptions (${e})`,t,I[e]),void 0!==t.placeholder)if("card"===e){if("object"!=typeof t.placeholder||null===t.placeholder)throw h("placeholder for card element must be an object with cardNumber, expiryDate, and cvv keys")}else if("string"!=typeof t.placeholder)throw h("placeholder must be a string");if(void 0!==t.disabled&&"boolean"!=typeof t.disabled)throw h("disabled must be a boolean");if(void 0!==t.readOnly&&"boolean"!=typeof t.readOnly)throw h("readOnly must be a boolean");if(void 0!==t.ariaLabel&&"string"!=typeof t.ariaLabel)throw h("ariaLabel must be a string");if("text"===e){if(void 0!==t.maxLength&&("number"!=typeof t.maxLength||t.maxLength<=0))throw h("maxLength must be a positive number");if(void 0!==t.password&&"boolean"!=typeof t.password)throw h("password must be a boolean");if(void 0!==t.required&&"boolean"!=typeof t.required)throw h("required must be a boolean");if(void 0!==t.validation&&!(t.validation instanceof RegExp))throw h("validation must be a RegExp");if(t.transform&&!(Array.isArray(t.transform)&&2===t.transform.length&&t.transform[0]instanceof RegExp&&"string"==typeof t.transform[1]))throw h('transform must be a tuple of [RegExp, string]. Example: [/-/g, ""]')}if("card"===e){const e=t;if(void 0!==e.layout&&!["row","column","auto"].includes(e.layout))throw h('layout must be "row", "column", or "auto"');if(void 0!==e.stackAt&&("number"!=typeof e.stackAt||e.stackAt<=0))throw h("stackAt must be a positive number");if(void 0!==e.iconPosition&&!["left","right","none"].includes(e.iconPosition))throw h('iconPosition must be "left", "right", or "none"');if(void 0!==e.cardBrands){if(!Array.isArray(e.cardBrands))throw h("cardBrands must be an array of strings");if(e.cardBrands.some(e=>"string"!=typeof e))throw h("All cardBrands must be strings")}}})(t,r);const l=`${t}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`;let u;if(o("Creating element (sync)",{type:t,elementId:l,coordinatorInitialized:null!==i,isLazyLoaded:!!d}),s)u=s(e,n,r,l,E);else{let o=null,a=null;const i=async()=>{a||(a=(async()=>{const t=await d();o=t(e,n,r,l,E)})()),await a};u={id:l,type:t,get mounted(){return(null==o?void 0:o.mounted)??!1},get fields(){return null==o?void 0:o.fields},mount:async e=>(await i(),o.mount(e)),unmount:()=>{if(!o)throw f("Element not initialized");return o.unmount()},update:async e=>{if(!o)throw f("Element not initialized");return o.update(e)},focus:()=>{if(!o)throw f("Element not initialized");return o.focus()},blur:()=>{if(!o)throw f("Element not initialized");return o.blur()},clear:()=>{if(!o)throw f("Element not initialized");return o.clear()},on:(e,t)=>o?o.on(e,t):(i().then(()=>o.on(e,t)),()=>{})}}return a.set(u.id,u),"cardNumber"===t&&u.on("change",e=>{const{cardBrand:t,cvvLengths:r}=e.detail;if(o("Card number change event received",{cardBrand:t,cvvLengths:r,cvvElementsCount:Array.from(a.values()).filter(e=>"cvv"===e.type).length}),t&&"Unknown"!==t&&r)for(const[n,i]of a)"cvv"===i.type&&i.mounted&&(o("Coordinating CVV element with card brand",{cvvElementId:n,cardBrand:t,cvvLengths:r,mounted:i.mounted}),i.update({cardBrand:t,cvvLengths:r}).catch(e=>{o("Failed to update CVV element with card brand",{cvvElementId:n,cardBrand:t,error:e.message})}))}),u},tokenize:async(e,t)=>{if(o("tokenize called",{hasPayload:!!e,hasOptions:!!t,coordinatorReady:!!s}),s||(o("Waiting for coordinator initialization"),await x()),!s)throw(()=>{const e=u("COORDINATOR_ERROR","Coordinator failed to initialize",void 0);return e.name="CoordinatorError",e})();try{const r=e?T(e):{};o("Element references resolved",{originalPayload:!!e,resolvedPayload:!!r}),o("Delegating tokenization to coordinator");const n=await s.sendRequest("CMD_TOKENIZE",{payload:r,options:t});return o("tokenize successful",{tokenId:n.id}),n}catch(r){throw o("tokenize failed",{error:r.message}),r}},tokens:{create:async e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw c("Token data must be a non-null object");if(o("tokens.create called",{type:e.type,hasData:!!e.data}),s||(o("Waiting for coordinator initialization"),await x()),!s)throw new Error("Coordinator failed to initialize");try{const t={...e,data:T(e.data)};o("Element references resolved for tokens.create",{resolvedData:!!t});const r=await s.sendRequest("CMD_TOKENS_CREATE",{data:t});return o("tokens.create successful",{tokenId:r.id}),r}catch(t){throw o("tokens.create failed",{error:t.message}),t}},retrieve:async(e,t)=>{if(o("tokens.retrieve called",{tokenId:e,hasSessionKey:!!(null==t?void 0:t.apiKey)}),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const r=await s.sendRequest("CMD_TOKENS_RETRIEVE",{id:e,apiKey:null==t?void 0:t.apiKey});return o("tokens.retrieve successful",{tokenId:r.id}),r}catch(r){throw o("tokens.retrieve failed",{error:r.message}),r}},update:async(e,t)=>{if(o("tokens.update called",{tokenId:e}),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const r=t.data?{...t,data:T(t.data)}:t,n=await s.sendRequest("CMD_TOKENS_UPDATE",{id:e,data:r});return o("tokens.update successful",{tokenId:n.id}),n}catch(r){throw o("tokens.update failed",{error:r.message}),r}},encrypt:async(e,t,r)=>{if(o("tokens.encrypt called",{isSingleToken:"type"in e&&"data"in e,keyId:r}),!e||"object"!=typeof e)throw c("tokenData must be an object");if(!t||"string"!=typeof t)throw c("publicKeyPEM is required");if(!r||"string"!=typeof r)throw c("keyId is required");if(s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const n=T(e);o("Element references resolved for tokens.encrypt",{originalData:!!e,resolvedData:!!n});const a=await s.sendRequest("CMD_TOKENS_ENCRYPT",{tokenRequests:n,publicKeyPEM:t,keyId:r});return o("tokens.encrypt successful",{isSingleToken:"encrypted"in a&&"type"in a}),a}catch(n){throw o("tokens.encrypt failed",{error:n.message}),n}}},sessions:{create:async()=>{if(o("sessions.create called"),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const e=await s.sendRequest("CMD_SESSIONS_CREATE",{});return o("sessions.create successful",{nonce:e.nonce,expiresAt:e.expires_at}),e}catch(e){throw o("sessions.create failed",{error:e.message}),e}}},tokenIntents:{create:async(e,t)=>{if(o("tokenIntents.create called",{type:e.type,hasData:!!e.data,hasOptions:!!t}),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const r=T(e.data);o("Element references resolved for token intent");const n=await s.sendRequest("CMD_TOKEN_INTENTS_CREATE",{type:e.type,data:r,options:t});return o("tokenIntents.create successful",{intentId:n.id}),n}catch(r){throw o("tokenIntents.create failed",{error:r.message}),r}},get:async(e,t)=>{if(o("tokenIntents.get called",{intentId:e}),s||await x(),!s)throw new Error("Coordinator failed to initialize");try{const r=await s.sendRequest("CMD_TOKEN_INTENTS_GET",{id:e,options:t});return o("tokenIntents.get successful",{intentId:r.id}),r}catch(r){throw o("tokenIntents.get failed",{error:r.message}),r}}},updateThemeMode:async e=>{o("updateThemeMode called",{oldMode:p,newMode:e,mountedElements:Array.from(a.values()).filter(e=>e.mounted).length}),p=e;const t=[];for(const[r,n]of a)if(n.mounted){o("Sending theme mode update to element",{elementId:r,elementType:n.type,mode:e});const a=document.querySelector(`iframe[data-bt-element-id="${n.id}"]`);a&&a.setAttribute("data-theme-mode",e);const i=n.update({themeMode:e}).catch(e=>{o("Failed to update theme mode for element",{elementId:r,error:e.message})});t.push(i)}await Promise.all(t),o("Theme mode updated for all mounted elements",{mode:e,updatedCount:Array.from(a.values()).filter(e=>e.mounted).length})}};if(r&&r.length>0){o("Draining command queue from loader",{queueLength:r.length,commands:r.map(e=>e.method)});for(const e of r)try{const t=D[e.method];if(!t)throw new Error(`Unknown method: ${e.method}`);o("Replaying queued command",{method:e.method,argsCount:e.args.length});const r=t(...e.args);r&&"function"==typeof r.then?r.then(t=>{o("Queued command completed (async)",{method:e.method}),e.resolve(t)}).catch(t=>{o("Queued command failed (async)",{method:e.method,error:t.message}),e.reject(t)}):(o("Queued command completed (sync)",{method:e.method}),e.resolve(r))}catch(A){o("Queued command failed (sync)",{method:e.method,error:A.message}),e.reject(A)}o("Command queue drain complete",{processedCount:r.length})}return D};"undefined"!=typeof window&&"undefined"!=typeof document&&document.currentScript&&!window.BasisTheory&&(window.BasisTheory=A),"undefined"!=typeof window&&(window.__BasisTheorySDK__=A);const L=Object.freeze(Object.defineProperty({__proto__:null,createCardElement:(e,t,r={},n,o)=>{let a=null,i=null,s=null,d=!1,l=null,u=null;const m=new EventTarget,c=n,h="card",p=e=>({id:e,type:"card",get mounted(){return d},mount:()=>{throw f("Sub-field refs cannot be mounted independently")},unmount:()=>{},update:()=>Promise.resolve(),focus:()=>{},blur:()=>{},clear:()=>{},on:()=>()=>{}});return{id:c,type:h,get mounted(){return d},fields:{number:p(`${c}__number`),expiryDate:p(`${c}__expiry`),cvc:p(`${c}__cvc`)},mount:async n=>{if(d)throw f("Element is already mounted");if(l="string"==typeof n?document.querySelector(n):n,!l)throw f(`Container not found: ${n}`);const p=window.location.origin,g=new URL(`${t.elementsBaseUrl}/card.html`);g.searchParams.set("parentOrigin",p),g.searchParams.set("elementId",c),g.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),g.searchParams.set("debug",String(t.debug||!1)),a=w({src:g.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Card Input"}),a.setAttribute("data-bt-element-id",c),a.setAttribute("data-theme-mode",t.themeMode||"auto"),i=b(a,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),s={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},i&&(u=E({elementType:h,elementId:c,client:i,eventTarget:m}),u.setupSubscriptions());const y=new Promise((e,r)=>{const n=setTimeout(()=>{r(f(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,c,{elementType:h,timeoutMs:t.timeoutMs}))},t.timeoutMs);m.addEventListener("ready",()=>{clearTimeout(n),e()},{once:!0})});s.mount(l,a,{timeoutMs:t.timeoutMs}),d=!0;try{await o(),await y,await i.sendRequest("CMD_SET_CONFIG",{elementId:c,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,placeholder:r.placeholder,style:r.style,disabled:r.disabled,readOnly:r.readOnly,layout:r.layout||"auto",stackAt:r.stackAt||400,iconPosition:r.iconPosition||"left",cardBrands:r.cardBrands,debug:t.debug}),a&&(a.style.opacity="1")}catch(v){throw u&&u.dispatchError("MOUNT_ERROR",v.message,v),d=!1,i&&(i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,v}},unmount:()=>{if(!d)throw f("Element is not mounted");i&&(i.sendRequest("CMD_CLEAR_CACHE",{}).catch(e=>{e.message}),i.destroy(),i=null),s&&a&&(s.unmount(a),a=null,s=null),u=null,l=null,d=!1},update:async e=>{if(!d||!i)throw f("Element must be mounted before updating");const r=e,n={placeholder:r.placeholder,style:r.style,disabled:r.disabled,readOnly:r.readOnly,layout:r.layout,stackAt:r.stackAt,iconPosition:r.iconPosition,cardBrands:r.cardBrands};void 0!==e.themeMode&&(n.themeMode=e.themeMode,n.theme=t.theme,n.darkTheme=t.darkTheme),await i.sendRequest("CMD_UPDATE_CONFIG",n)},focus:()=>{if(!d||!i)throw f("Element must be mounted before focusing");i.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!i)throw f("Element must be mounted before blurring");i.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!i)throw f("Element must be mounted before clearing");i.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(m.addEventListener(e,t),()=>m.removeEventListener(e,t))}}},Symbol.toStringTag,{value:"Module"}));e.buildDate="2026-04-13T19:51:30.877Z",e.default=A,e.version="3.0.0-beta.3",Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,4 +1,4 @@
1
- import { E as ElementError, c as createIframe, a as createPostMessageClient, b as createEventDispatcher, l as log, d as createMounter } from "./index-oREjBjga.js";
1
+ import { E as ElementError, c as createIframe, a as createPostMessageClient, b as createEventDispatcher, l as log, d as createMounter } from "./index-BBfuUaLw.js";
2
2
  const DEFAULT_CARD_STACK_THRESHOLD = 400;
3
3
  const createCardElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady) => {
4
4
  let iframe = null;
@@ -1 +1 @@
1
- {"version":3,"file":"create-card-BuOvimjH.js","sources":["../src/elements/create-card.ts"],"sourcesContent":["/**\n * Card Element Factory (Unified)\n */\n\nimport type { PostMessageClient } from '@basis-theory-elements/postmessage';\nimport { createPostMessageClient } from '@basis-theory-elements/postmessage';\nimport { ElementError, log } from '@basis-theory-elements/shared';\nimport { createMounter } from '../mounter/create-mounter';\nimport type {\n CardElement,\n ElementMounter,\n ElementOptions,\n EventListener,\n EventType,\n SDKConfig,\n SubElementRef,\n} from '../types';\nimport { createIframe } from '../utils/create-iframe';\nimport { createEventDispatcher } from '../utils/create-event-dispatcher';\n\n/**\n * Default stack threshold in pixels for CardElement auto-layout\n * When container width is below this threshold, card inputs stack vertically\n */\nconst DEFAULT_CARD_STACK_THRESHOLD = 400;\n\n/**\n * Card element options\n */\nexport interface CardElementOptions {\n /** CSS styling */\n style?: Record<string, any>;\n\n /** Placeholder text for each sub-field */\n placeholder?: {\n cardNumber?: string;\n expiryDate?: string;\n cvc?: string;\n };\n\n /** Accessibility label */\n ariaLabel?: string;\n\n /** Disabled state (applies to all 3 sub-fields) */\n disabled?: boolean;\n\n /** Read-only state (applies to all 3 sub-fields) */\n readOnly?: boolean;\n\n /** Layout mode */\n layout?: 'row' | 'column' | 'auto';\n\n /** Stack threshold in pixels (only applies when layout: 'auto') */\n stackAt?: number;\n\n /** Icon position */\n iconPosition?: 'left' | 'right' | 'none';\n\n /** Restrict accepted card brands */\n cardBrands?: string[];\n}\n\n/**\n * Factory function to create a unified card element\n * No class, pure functional approach with closure-based state\n */\nexport const createCardElement = (\n apiKey: string,\n sdkConfig: SDKConfig,\n options: CardElementOptions = {},\n coordinatorElementId: string,\n ensureCoordinatorReady: () => Promise<void>\n): CardElement => {\n // Private state (closure)\n let iframe: HTMLIFrameElement | null = null;\n let client: PostMessageClient | null = null;\n let mounter: ElementMounter | null = null;\n let isMounted = false;\n let container: HTMLElement | null = null;\n let eventDispatcher: ReturnType<typeof createEventDispatcher> | null = null;\n\n // Event target for event emission\n const eventTarget = new EventTarget();\n\n // Use coordinator-generated ID for all references\n const id = coordinatorElementId;\n const type = 'card';\n\n // Setup event dispatcher\n const setupEventListeners = () => {\n if (!client) {\n return;\n }\n\n eventDispatcher = createEventDispatcher({\n elementType: type,\n elementId: id,\n client,\n eventTarget,\n });\n\n eventDispatcher.setupSubscriptions();\n };\n\n /**\n * Create sub-element reference for tokenization\n * These refs are used in bt.tokens.create() data payload\n */\n const createSubElementRef = (subId: string): SubElementRef => ({\n id: subId,\n type: 'card',\n get mounted() {\n return isMounted;\n },\n mount: () => {\n throw ElementError('Sub-field refs cannot be mounted independently');\n },\n unmount: () => {},\n update: () => Promise.resolve(),\n focus: () => {},\n blur: () => {},\n clear: () => {},\n on: () => () => {},\n });\n\n // Public API (Element interface with sub-field refs)\n const cardElement = {\n id,\n type,\n get mounted() {\n return isMounted;\n },\n\n // Sub-field references for tokenization\n fields: {\n number: createSubElementRef(`${id}__number`),\n expiryDate: createSubElementRef(`${id}__expiry`),\n cvc: createSubElementRef(`${id}__cvc`),\n },\n\n mount: async (selector: string | HTMLElement) => {\n if (isMounted) {\n throw ElementError('Element is already mounted');\n }\n\n // Resolve container\n container =\n typeof selector === 'string'\n ? document.querySelector(selector)\n : selector;\n\n if (!container) {\n throw ElementError(`Container not found: ${selector}`);\n }\n\n // Create iframe\n const parentOrigin = window.location.origin;\n const iframeUrl = new URL(`${sdkConfig.elementsBaseUrl}/card.html`);\n iframeUrl.searchParams.set('parentOrigin', parentOrigin);\n iframeUrl.searchParams.set('elementId', id);\n iframeUrl.searchParams.set(\n 'measurePerformance',\n String(sdkConfig.measurePerformance || false)\n );\n iframeUrl.searchParams.set('debug', String(sdkConfig.debug || false));\n\n iframe = createIframe({\n src: iframeUrl.toString(),\n sandbox: 'allow-scripts allow-same-origin',\n title: options.ariaLabel || 'Card Input',\n });\n\n // Add element ID and theme mode attributes\n iframe.setAttribute('data-bt-element-id', id);\n iframe.setAttribute('data-theme-mode', sdkConfig.themeMode || 'auto');\n\n // Create PostMessage client\n client = createPostMessageClient(iframe, {\n targetOrigin: sdkConfig.iframeOrigin,\n timeout: sdkConfig.timeoutMs,\n retries: sdkConfig.retryConfig.maxRetries,\n debug: sdkConfig.debug,\n });\n\n // Create mounter\n mounter = createMounter();\n\n // Set up event listeners\n setupEventListeners();\n\n // Subscribe to 'ready' event BEFORE mounting iframe\n const readyPromise = new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(\n ElementError(\n `Iframe EVENT_READY not received within ${sdkConfig.timeoutMs}ms`,\n id,\n { elementType: type, timeoutMs: sdkConfig.timeoutMs }\n )\n );\n }, sdkConfig.timeoutMs);\n\n const handleReady = () => {\n clearTimeout(timeout);\n resolve();\n };\n\n eventTarget.addEventListener('ready', handleReady, { once: true });\n });\n\n // Mount iframe to DOM (synchronous)\n mounter.mount(container, iframe, {\n timeoutMs: sdkConfig.timeoutMs,\n });\n\n isMounted = true;\n\n // Wait for coordinator + configuration to complete\n try {\n // Wait for coordinator (loads Core SDK if needed)\n await ensureCoordinatorReady();\n\n // Wait for EVENT_READY\n await readyPromise;\n\n // Send initial configuration with card-specific options\n await client!.sendRequest('CMD_SET_CONFIG', {\n elementId: id,\n apiKey,\n apiTimeout: sdkConfig.timeoutMs,\n apiRetries: sdkConfig.retryConfig.maxRetries,\n theme: sdkConfig.theme,\n darkTheme: sdkConfig.darkTheme,\n themeMode: sdkConfig.themeMode,\n placeholder: options.placeholder,\n style: options.style,\n disabled: options.disabled,\n readOnly: options.readOnly,\n layout: options.layout || 'auto',\n stackAt: options.stackAt || DEFAULT_CARD_STACK_THRESHOLD,\n iconPosition: options.iconPosition || 'left',\n cardBrands: options.cardBrands,\n debug: sdkConfig.debug,\n });\n\n // Reveal iframe now that theme is fully applied\n if (iframe) iframe.style.opacity = '1';\n } catch (error) {\n // Dispatch error event before cleanup\n if (eventDispatcher) {\n eventDispatcher.dispatchError(\n 'MOUNT_ERROR',\n (error as Error).message,\n error as Error\n );\n }\n\n // Mount failed - clean up and mark as unmounted\n isMounted = false;\n\n if (client) {\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n eventDispatcher = null;\n container = null;\n\n throw error;\n }\n },\n\n unmount: () => {\n if (!isMounted) {\n throw ElementError('Element is not mounted');\n }\n\n // Tell iframe to notify coordinator to clear cached values (all 3 sub-fields)\n if (client) {\n client.sendRequest('CMD_CLEAR_CACHE', {}).catch((error) => {\n log('Failed to send clear cache command', {\n elementId: id,\n error: (error as Error).message,\n });\n });\n\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n eventDispatcher = null;\n container = null;\n isMounted = false;\n },\n\n update: async (newOptions: Partial<ElementOptions> & { themeMode?: string }) => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before updating');\n }\n\n // Cast to CardElementOptions to access card-specific properties\n const cardOptions = newOptions as Partial<CardElementOptions> & { themeMode?: string };\n\n // Build update payload\n const updatePayload: Record<string, any> = {\n placeholder: cardOptions.placeholder,\n style: cardOptions.style,\n disabled: cardOptions.disabled,\n readOnly: cardOptions.readOnly,\n layout: cardOptions.layout,\n stackAt: cardOptions.stackAt,\n iconPosition: cardOptions.iconPosition,\n cardBrands: cardOptions.cardBrands,\n };\n\n // Include theme mode update if provided\n if (newOptions.themeMode !== undefined) {\n updatePayload.themeMode = newOptions.themeMode;\n updatePayload.theme = sdkConfig.theme;\n updatePayload.darkTheme = sdkConfig.darkTheme;\n }\n\n await client.sendRequest('CMD_UPDATE_CONFIG', updatePayload);\n },\n\n focus: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before focusing');\n }\n\n client.sendRequest('CMD_FOCUS', {});\n },\n\n blur: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before blurring');\n }\n\n client.sendRequest('CMD_BLUR', {});\n },\n\n clear: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before clearing');\n }\n\n client.sendRequest('CMD_CLEAR', {});\n },\n\n on: (eventType: EventType, listener: EventListener) => {\n eventTarget.addEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n\n // Return unsubscribe function\n return () =>\n eventTarget.removeEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n },\n };\n\n return cardElement as CardElement;\n};\n"],"names":[],"mappings":";AAwBA,MAAM,+BAA+B;AA0C9B,MAAM,oBA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O;AACT;"}
1
+ {"version":3,"file":"create-card-DipDWgph.js","sources":["../src/elements/create-card.ts"],"sourcesContent":["/**\n * Card Element Factory (Unified)\n */\n\nimport type { PostMessageClient } from '@basis-theory-elements/postmessage';\nimport { createPostMessageClient } from '@basis-theory-elements/postmessage';\nimport { ElementError, log } from '@basis-theory-elements/shared';\nimport { createMounter } from '../mounter/create-mounter';\nimport type {\n CardElement,\n ElementMounter,\n ElementOptions,\n EventListener,\n EventType,\n SDKConfig,\n SubElementRef,\n} from '../types';\nimport { createIframe } from '../utils/create-iframe';\nimport { createEventDispatcher } from '../utils/create-event-dispatcher';\n\n/**\n * Default stack threshold in pixels for CardElement auto-layout\n * When container width is below this threshold, card inputs stack vertically\n */\nconst DEFAULT_CARD_STACK_THRESHOLD = 400;\n\n/**\n * Card element options\n */\nexport interface CardElementOptions {\n /** CSS styling */\n style?: Record<string, any>;\n\n /** Placeholder text for each sub-field */\n placeholder?: {\n cardNumber?: string;\n expiryDate?: string;\n cvc?: string;\n };\n\n /** Accessibility label */\n ariaLabel?: string;\n\n /** Disabled state (applies to all 3 sub-fields) */\n disabled?: boolean;\n\n /** Read-only state (applies to all 3 sub-fields) */\n readOnly?: boolean;\n\n /** Layout mode */\n layout?: 'row' | 'column' | 'auto';\n\n /** Stack threshold in pixels (only applies when layout: 'auto') */\n stackAt?: number;\n\n /** Icon position */\n iconPosition?: 'left' | 'right' | 'none';\n\n /** Restrict accepted card brands */\n cardBrands?: string[];\n}\n\n/**\n * Factory function to create a unified card element\n * No class, pure functional approach with closure-based state\n */\nexport const createCardElement = (\n apiKey: string,\n sdkConfig: SDKConfig,\n options: CardElementOptions = {},\n coordinatorElementId: string,\n ensureCoordinatorReady: () => Promise<void>\n): CardElement => {\n // Private state (closure)\n let iframe: HTMLIFrameElement | null = null;\n let client: PostMessageClient | null = null;\n let mounter: ElementMounter | null = null;\n let isMounted = false;\n let container: HTMLElement | null = null;\n let eventDispatcher: ReturnType<typeof createEventDispatcher> | null = null;\n\n // Event target for event emission\n const eventTarget = new EventTarget();\n\n // Use coordinator-generated ID for all references\n const id = coordinatorElementId;\n const type = 'card';\n\n // Setup event dispatcher\n const setupEventListeners = () => {\n if (!client) {\n return;\n }\n\n eventDispatcher = createEventDispatcher({\n elementType: type,\n elementId: id,\n client,\n eventTarget,\n });\n\n eventDispatcher.setupSubscriptions();\n };\n\n /**\n * Create sub-element reference for tokenization\n * These refs are used in bt.tokens.create() data payload\n */\n const createSubElementRef = (subId: string): SubElementRef => ({\n id: subId,\n type: 'card',\n get mounted() {\n return isMounted;\n },\n mount: () => {\n throw ElementError('Sub-field refs cannot be mounted independently');\n },\n unmount: () => {},\n update: () => Promise.resolve(),\n focus: () => {},\n blur: () => {},\n clear: () => {},\n on: () => () => {},\n });\n\n // Public API (Element interface with sub-field refs)\n const cardElement = {\n id,\n type,\n get mounted() {\n return isMounted;\n },\n\n // Sub-field references for tokenization\n fields: {\n number: createSubElementRef(`${id}__number`),\n expiryDate: createSubElementRef(`${id}__expiry`),\n cvc: createSubElementRef(`${id}__cvc`),\n },\n\n mount: async (selector: string | HTMLElement) => {\n if (isMounted) {\n throw ElementError('Element is already mounted');\n }\n\n // Resolve container\n container =\n typeof selector === 'string'\n ? document.querySelector(selector)\n : selector;\n\n if (!container) {\n throw ElementError(`Container not found: ${selector}`);\n }\n\n // Create iframe\n const parentOrigin = window.location.origin;\n const iframeUrl = new URL(`${sdkConfig.elementsBaseUrl}/card.html`);\n iframeUrl.searchParams.set('parentOrigin', parentOrigin);\n iframeUrl.searchParams.set('elementId', id);\n iframeUrl.searchParams.set(\n 'measurePerformance',\n String(sdkConfig.measurePerformance || false)\n );\n iframeUrl.searchParams.set('debug', String(sdkConfig.debug || false));\n\n iframe = createIframe({\n src: iframeUrl.toString(),\n sandbox: 'allow-scripts allow-same-origin',\n title: options.ariaLabel || 'Card Input',\n });\n\n // Add element ID and theme mode attributes\n iframe.setAttribute('data-bt-element-id', id);\n iframe.setAttribute('data-theme-mode', sdkConfig.themeMode || 'auto');\n\n // Create PostMessage client\n client = createPostMessageClient(iframe, {\n targetOrigin: sdkConfig.iframeOrigin,\n timeout: sdkConfig.timeoutMs,\n retries: sdkConfig.retryConfig.maxRetries,\n debug: sdkConfig.debug,\n });\n\n // Create mounter\n mounter = createMounter();\n\n // Set up event listeners\n setupEventListeners();\n\n // Subscribe to 'ready' event BEFORE mounting iframe\n const readyPromise = new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(\n ElementError(\n `Iframe EVENT_READY not received within ${sdkConfig.timeoutMs}ms`,\n id,\n { elementType: type, timeoutMs: sdkConfig.timeoutMs }\n )\n );\n }, sdkConfig.timeoutMs);\n\n const handleReady = () => {\n clearTimeout(timeout);\n resolve();\n };\n\n eventTarget.addEventListener('ready', handleReady, { once: true });\n });\n\n // Mount iframe to DOM (synchronous)\n mounter.mount(container, iframe, {\n timeoutMs: sdkConfig.timeoutMs,\n });\n\n isMounted = true;\n\n // Wait for coordinator + configuration to complete\n try {\n // Wait for coordinator (loads Core SDK if needed)\n await ensureCoordinatorReady();\n\n // Wait for EVENT_READY\n await readyPromise;\n\n // Send initial configuration with card-specific options\n await client!.sendRequest('CMD_SET_CONFIG', {\n elementId: id,\n apiKey,\n apiTimeout: sdkConfig.timeoutMs,\n apiRetries: sdkConfig.retryConfig.maxRetries,\n theme: sdkConfig.theme,\n darkTheme: sdkConfig.darkTheme,\n themeMode: sdkConfig.themeMode,\n placeholder: options.placeholder,\n style: options.style,\n disabled: options.disabled,\n readOnly: options.readOnly,\n layout: options.layout || 'auto',\n stackAt: options.stackAt || DEFAULT_CARD_STACK_THRESHOLD,\n iconPosition: options.iconPosition || 'left',\n cardBrands: options.cardBrands,\n debug: sdkConfig.debug,\n });\n\n // Reveal iframe now that theme is fully applied\n if (iframe) iframe.style.opacity = '1';\n } catch (error) {\n // Dispatch error event before cleanup\n if (eventDispatcher) {\n eventDispatcher.dispatchError(\n 'MOUNT_ERROR',\n (error as Error).message,\n error as Error\n );\n }\n\n // Mount failed - clean up and mark as unmounted\n isMounted = false;\n\n if (client) {\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n eventDispatcher = null;\n container = null;\n\n throw error;\n }\n },\n\n unmount: () => {\n if (!isMounted) {\n throw ElementError('Element is not mounted');\n }\n\n // Tell iframe to notify coordinator to clear cached values (all 3 sub-fields)\n if (client) {\n client.sendRequest('CMD_CLEAR_CACHE', {}).catch((error) => {\n log('Failed to send clear cache command', {\n elementId: id,\n error: (error as Error).message,\n });\n });\n\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n eventDispatcher = null;\n container = null;\n isMounted = false;\n },\n\n update: async (newOptions: Partial<ElementOptions> & { themeMode?: string }) => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before updating');\n }\n\n // Cast to CardElementOptions to access card-specific properties\n const cardOptions = newOptions as Partial<CardElementOptions> & { themeMode?: string };\n\n // Build update payload\n const updatePayload: Record<string, any> = {\n placeholder: cardOptions.placeholder,\n style: cardOptions.style,\n disabled: cardOptions.disabled,\n readOnly: cardOptions.readOnly,\n layout: cardOptions.layout,\n stackAt: cardOptions.stackAt,\n iconPosition: cardOptions.iconPosition,\n cardBrands: cardOptions.cardBrands,\n };\n\n // Include theme mode update if provided\n if (newOptions.themeMode !== undefined) {\n updatePayload.themeMode = newOptions.themeMode;\n updatePayload.theme = sdkConfig.theme;\n updatePayload.darkTheme = sdkConfig.darkTheme;\n }\n\n await client.sendRequest('CMD_UPDATE_CONFIG', updatePayload);\n },\n\n focus: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before focusing');\n }\n\n client.sendRequest('CMD_FOCUS', {});\n },\n\n blur: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before blurring');\n }\n\n client.sendRequest('CMD_BLUR', {});\n },\n\n clear: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before clearing');\n }\n\n client.sendRequest('CMD_CLEAR', {});\n },\n\n on: (eventType: EventType, listener: EventListener) => {\n eventTarget.addEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n\n // Return unsubscribe function\n return () =>\n eventTarget.removeEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n },\n };\n\n return cardElement as CardElement;\n};\n"],"names":[],"mappings":";AAwBA,MAAM,+BAA+B;AA0C9B,MAAM,oBAAoB,CAC/B,QACA,WACA,UAA8B,CAAA,GAC9B,sBACA,2BACgB;AAEhB,MAAI,SAAmC;AACvC,MAAI,SAAmC;AACvC,MAAI,UAAiC;AACrC,MAAI,YAAY;AAChB,MAAI,YAAgC;AACpC,MAAI,kBAAmE;AAGvE,QAAM,cAAc,IAAI,YAAA;AAGxB,QAAM,KAAK;AACX,QAAM,OAAO;AAGb,QAAM,sBAAsB,MAAM;AAChC,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,sBAAkB,sBAAsB;AAAA,MACtC,aAAa;AAAA,MACb,WAAW;AAAA,MACX;AAAA,MACA;AAAA,IAAA,CACD;AAED,oBAAgB,mBAAA;AAAA,EAClB;AAMA,QAAM,sBAAsB,CAAC,WAAkC;AAAA,IAC7D,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,IAAI,UAAU;AACZ,aAAO;AAAA,IACT;AAAA,IACA,OAAO,MAAM;AACX,YAAM,aAAa,gDAAgD;AAAA,IACrE;AAAA,IACA,SAAS,MAAM;AAAA,IAAC;AAAA,IAChB,QAAQ,MAAM,QAAQ,QAAA;AAAA,IACtB,OAAO,MAAM;AAAA,IAAC;AAAA,IACd,MAAM,MAAM;AAAA,IAAC;AAAA,IACb,OAAO,MAAM;AAAA,IAAC;AAAA,IACd,IAAI,MAAM,MAAM;AAAA,IAAC;AAAA,EAAA;AAInB,QAAM,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA,IAAI,UAAU;AACZ,aAAO;AAAA,IACT;A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MAAM;AACX,UAAI,CAAC,aAAa,CAAC,QAAQ;AACzB,cAAM,aAAa,yCAAyC;AAAA,MAC9D;AAEA,aAAO,YAAY,aAAa,EAAE;AAAA,IACpC;AAAA,IAEA,IAAI,CAAC,WAAsB,aAA4B;AACrD,kBAAY;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAIF,aAAO,MACL,YAAY;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAAA,IAEN;AAAA,EAAA;AAGF,SAAO;AACT;"}
@@ -1540,7 +1540,7 @@ const validateSDKConfig = (options = {}) => {
1540
1540
  if (!["light", "dark", "auto"].includes(themeMode)) {
1541
1541
  throw ConfigurationError('themeMode must be "light", "dark", or "auto"');
1542
1542
  }
1543
- const finalBaseUrl = baseUrl || "https://js.basistheory.com/3.0.0-beta.2/elements";
1543
+ const finalBaseUrl = baseUrl || "https://js.basistheory.com/3.0.0-beta.3/elements";
1544
1544
  const iframeOrigin = new URL(finalBaseUrl).origin;
1545
1545
  return {
1546
1546
  iframeOrigin,
@@ -1682,7 +1682,7 @@ const BasisTheory = (apiKey, options = {}, queuedCommands) => {
1682
1682
  let cardElementFactory = null;
1683
1683
  const lazyCardElement = async () => {
1684
1684
  if (!cardElementFactory) {
1685
- const module = await import("./create-card-BuOvimjH.js");
1685
+ const module = await import("./create-card-DipDWgph.js");
1686
1686
  cardElementFactory = module.createCardElement;
1687
1687
  }
1688
1688
  return cardElementFactory;
@@ -2299,8 +2299,8 @@ const BasisTheory = (apiKey, options = {}, queuedCommands) => {
2299
2299
  if (typeof window !== "undefined" && typeof document !== "undefined" && document.currentScript && !window.BasisTheory) {
2300
2300
  window.BasisTheory = BasisTheory;
2301
2301
  }
2302
- const version = "3.0.0-beta.2";
2303
- const buildDate = "2026-04-13T17:05:21.283Z";
2302
+ const version = "3.0.0-beta.3";
2303
+ const buildDate = "2026-04-13T19:51:30.877Z";
2304
2304
  if (typeof window !== "undefined") {
2305
2305
  window.__BasisTheorySDK__ = BasisTheory;
2306
2306
  }