@payment-kit-js/vanilla 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * PaymentKit.js v0.5.3
2
+ * PaymentKit.js v0.5.5
3
3
  * https://paymentkit.com
4
4
  *
5
5
  * @license MIT
@@ -42,7 +42,7 @@ var PaymentKit = (() => {
42
42
  });
43
43
 
44
44
  // package.json
45
- var version = "0.5.3";
45
+ var version = "0.5.5";
46
46
 
47
47
  // src/analytics/mock-adapter.ts
48
48
  var MockAnalyticsAdapter = class {
@@ -6850,28 +6850,63 @@ var PaymentKit = (() => {
6850
6850
  return window.VGSCollect.create(vaultId, environment, () => {
6851
6851
  });
6852
6852
  }
6853
- function createVgsCardFields(form, mountPoints, css, onFocusChangeCallbacks) {
6854
- const fieldCss = css ?? {
6855
- height: "46px",
6853
+ function createVgsCardFields(form, mountPoints, css, onFocusChangeCallbacks, placeholders) {
6854
+ const sampleContainer = document.querySelector(mountPoints.pan);
6855
+ const containerPadding = sampleContainer ? getComputedStyle(sampleContainer).padding : void 0;
6856
+ const baseCss = css ?? {
6856
6857
  "font-size": "1rem",
6857
6858
  color: "#18181b",
6858
6859
  "font-family": "ui-sans-serif, system-ui, sans-serif"
6859
6860
  };
6861
+ const fieldCss = {
6862
+ ...baseCss,
6863
+ height: "100%",
6864
+ "box-sizing": "border-box",
6865
+ ...containerPadding && containerPadding !== "0px" ? { padding: containerPadding } : {}
6866
+ };
6860
6867
  const panField = form.cardNumberField(mountPoints.pan, {
6861
- placeholder: "Card number",
6868
+ placeholder: placeholders?.card_pan ?? "Card number",
6862
6869
  validations: ["required", "validCardNumber"],
6863
6870
  css: fieldCss
6864
6871
  });
6865
6872
  const expField = form.cardExpirationDateField(mountPoints.exp, {
6866
- placeholder: "MM / YY",
6873
+ placeholder: placeholders?.card_exp ?? "MM / YY",
6867
6874
  validations: ["required", "validCardExpirationDate"],
6868
6875
  css: fieldCss
6869
6876
  });
6870
6877
  const cvcField = form.cardCVCField(mountPoints.cvc, {
6871
- placeholder: "123",
6878
+ placeholder: placeholders?.card_cvc ?? "123",
6872
6879
  validations: ["required", "validCardSecurityCode"],
6873
6880
  css: fieldCss
6874
6881
  });
6882
+ for (const selector of [mountPoints.pan, mountPoints.exp, mountPoints.cvc]) {
6883
+ const container = document.querySelector(selector);
6884
+ if (!container) continue;
6885
+ const styleIframe = (iframe) => {
6886
+ const containerEl = container;
6887
+ if (getComputedStyle(containerEl).position === "static") {
6888
+ containerEl.style.position = "relative";
6889
+ }
6890
+ iframe.style.position = "absolute";
6891
+ iframe.style.inset = "0";
6892
+ iframe.style.width = "100%";
6893
+ iframe.style.height = "100%";
6894
+ iframe.style.border = "none";
6895
+ };
6896
+ const existing = container.querySelector("iframe");
6897
+ if (existing) {
6898
+ styleIframe(existing);
6899
+ } else {
6900
+ const observer = new MutationObserver((_2, obs) => {
6901
+ const iframe = container.querySelector("iframe");
6902
+ if (iframe) {
6903
+ styleIframe(iframe);
6904
+ obs.disconnect();
6905
+ }
6906
+ });
6907
+ observer.observe(container, { childList: true, subtree: true });
6908
+ }
6909
+ }
6875
6910
  if (onFocusChangeCallbacks) {
6876
6911
  const fieldMap = [
6877
6912
  [panField, "card_pan"],
@@ -6915,7 +6950,7 @@ var PaymentKit = (() => {
6915
6950
  var defCreateElement = (states) => {
6916
6951
  const { baseUrl, apiBaseUrl, cardInputConnections, secureToken, timingTracker } = states;
6917
6952
  return (type, options) => {
6918
- const { style, onLoaded, onFocusChange } = options;
6953
+ const { style, onLoaded, onFocusChange, placeholder } = options;
6919
6954
  const mountIFrame = (parentSelector) => {
6920
6955
  let cleanupVgs;
6921
6956
  let cleanupDirect;
@@ -6933,6 +6968,10 @@ var PaymentKit = (() => {
6933
6968
  if (!states.vgsFocusCallbacks) states.vgsFocusCallbacks = {};
6934
6969
  states.vgsFocusCallbacks[type] = onFocusChange;
6935
6970
  }
6971
+ if (placeholder) {
6972
+ if (!states.vgsPlaceholders) states.vgsPlaceholders = {};
6973
+ states.vgsPlaceholders[type] = placeholder;
6974
+ }
6936
6975
  if (type === "card_pan") {
6937
6976
  const vaultId = states.vgsVaultId;
6938
6977
  const vgsEnv = states.vgsEnvironment;
@@ -6978,7 +7017,8 @@ var PaymentKit = (() => {
6978
7017
  cvc: cvcSelector
6979
7018
  },
6980
7019
  css,
6981
- states.vgsFocusCallbacks
7020
+ states.vgsFocusCallbacks,
7021
+ states.vgsPlaceholders
6982
7022
  );
6983
7023
  console.log("[PaymentKit] VGS card fields created successfully");
6984
7024
  timingTracker.trackInputReady();
@@ -7005,14 +7045,25 @@ var PaymentKit = (() => {
7005
7045
  );
7006
7046
  }
7007
7047
  const parent = $(parentSelector);
7048
+ const computed = getComputedStyle(parent);
7049
+ const containerPadding = computed.padding !== "0px" ? computed.padding : void 0;
7050
+ const enhancedStyle = {
7051
+ ...style ?? {},
7052
+ height: "100%",
7053
+ boxSizing: "border-box",
7054
+ ...containerPadding ? { padding: containerPadding } : {}
7055
+ };
7008
7056
  const params = {
7009
7057
  checkout_token: secureToken,
7010
- api_base_url: apiBaseUrl
7058
+ api_base_url: apiBaseUrl,
7059
+ style: JSON.stringify(enhancedStyle)
7011
7060
  };
7012
- if (style) {
7013
- params.style = JSON.stringify(style);
7014
- }
7015
7061
  const iframe = createCheckoutIFrame(type.replace("_", "-"), baseUrl, params);
7062
+ if (computed.position === "static") {
7063
+ parent.style.position = "relative";
7064
+ }
7065
+ iframe.style.position = "absolute";
7066
+ iframe.style.inset = "0";
7016
7067
  cleanupDirect = () => {
7017
7068
  const connection = cardInputConnections[type];
7018
7069
  connection?.destroy();