@rebilly/instruments 8.12.0 → 8.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [8.13.0](https://github.com/Rebilly/rebilly/compare/instruments/core-v8.12.1...instruments/core-v8.13.0) (2023-12-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * **instruments:** Allow instruments to work on a web component (shadow DOM) ([#2612](https://github.com/Rebilly/rebilly/issues/2612)) ([0f3ded2](https://github.com/Rebilly/rebilly/commit/0f3ded2d229a82c08bb6505243eff3257eced796))
7
+
8
+ ## [8.12.1](https://github.com/Rebilly/rebilly/compare/instruments/core-v8.12.0...instruments/core-v8.12.1) (2023-12-15)
9
+
1
10
  ## [8.12.0](https://github.com/Rebilly/rebilly/compare/instruments/core-v8.11.0...instruments/core-v8.12.0) (2023-12-14)
2
11
 
3
12
 
package/dist/index.js CHANGED
@@ -702,17 +702,17 @@ class Loader {
702
702
  }
703
703
  }
704
704
  startLoading({ section = "form", id: id2 = "" } = {}) {
705
- var _a, _b;
705
+ var _a, _b, _c;
706
706
  this[section].push(id2);
707
- const rootEl = document.querySelector(":root");
707
+ const rootEl = ((_a = state.shadowRoot) == null ? void 0 : _a.querySelector("style")) || document.querySelector(":root");
708
708
  const contentPadding = 2;
709
709
  let minHeight = "240px";
710
- if ((_a = this.DOM) == null ? void 0 : _a[section]) {
710
+ if ((_b = this.DOM) == null ? void 0 : _b[section]) {
711
711
  let loaderEl = this.DOM[section].querySelector(
712
712
  ".rebilly-instruments-loader"
713
713
  );
714
714
  const { padding, paddingTop, paddingBottom } = getComputedStyle(
715
- (_b = this.DOM) == null ? void 0 : _b[section]
715
+ (_c = this.DOM) == null ? void 0 : _c[section]
716
716
  );
717
717
  if (!loaderEl) {
718
718
  this.DOM[section].innerHTML = loaderContainer(
@@ -1542,16 +1542,14 @@ class Translate {
1542
1542
  this.languages = { ...en$1, ...es$1 };
1543
1543
  }
1544
1544
  init(locale, messages) {
1545
- this.items = Array.from(
1546
- document.querySelectorAll("[data-rebilly-i18n]")
1547
- );
1545
+ const root2 = state.shadowRoot || document;
1546
+ this.items = Array.from(root2.querySelectorAll("[data-rebilly-i18n]"));
1548
1547
  this.locale = this.getLocale(locale);
1549
1548
  this.languages = merge$1({}, { ...en$1, ...es$1 }, messages);
1550
1549
  }
1551
1550
  translateItems() {
1552
- this.items = Array.from(
1553
- document.querySelectorAll("[data-rebilly-i18n]")
1554
- );
1551
+ const root2 = state.shadowRoot || document;
1552
+ this.items = Array.from(root2.querySelectorAll("[data-rebilly-i18n]"));
1555
1553
  if (this.locale in this.languages) {
1556
1554
  return this.items.forEach((item) => {
1557
1555
  const translate = this.getTranslation(
@@ -1644,6 +1642,7 @@ const state = (() => {
1644
1642
  loader: new Loader(),
1645
1643
  translate: new Translate(),
1646
1644
  hasMounted: false,
1645
+ shadowRoot: null,
1647
1646
  toModel() {
1648
1647
  var _a;
1649
1648
  const model = {
@@ -2796,15 +2795,21 @@ const errorTemplate = (error2) => {
2796
2795
  </div>`;
2797
2796
  };
2798
2797
  function clearError() {
2799
- const errorContainer = document.querySelector("#rebilly-instruments-error");
2798
+ var _a;
2799
+ const errorContainer = (_a = state.form) == null ? void 0 : _a.querySelector(
2800
+ "#rebilly-instruments-error"
2801
+ );
2800
2802
  if (!errorContainer)
2801
2803
  return;
2802
2804
  errorContainer.innerHTML = "";
2803
2805
  }
2804
2806
  function showError(error2, isCloseable = true) {
2807
+ var _a;
2805
2808
  if (!error2)
2806
2809
  return;
2807
- const errorContainer = document.querySelector("#rebilly-instruments-error");
2810
+ const errorContainer = (_a = state.form) == null ? void 0 : _a.querySelector(
2811
+ "#rebilly-instruments-error"
2812
+ );
2808
2813
  if (!errorContainer)
2809
2814
  return;
2810
2815
  errorContainer.innerHTML = errorTemplate(error2);
@@ -2822,7 +2827,7 @@ function showError(error2, isCloseable = true) {
2822
2827
  }
2823
2828
  });
2824
2829
  }
2825
- const closeButton = document.querySelector(
2830
+ const closeButton = state.form.querySelector(
2826
2831
  ".rebilly-instruments-error-card-close-button"
2827
2832
  );
2828
2833
  if (isCloseable) {
@@ -2830,7 +2835,7 @@ function showError(error2, isCloseable = true) {
2830
2835
  window.addEventListener("click", clickOutsideError);
2831
2836
  window.addEventListener("blur", windowBlur, { once: true });
2832
2837
  } else {
2833
- const errorBox = document.querySelector(
2838
+ const errorBox = state.form.querySelector(
2834
2839
  ".rebilly-instruments-error-card"
2835
2840
  );
2836
2841
  errorBox.classList.add("not-closeable");
@@ -5983,7 +5988,7 @@ function cloneArrayDeep(val, instanceClone) {
5983
5988
  return res;
5984
5989
  }
5985
5990
  var cloneDeep_1 = cloneDeep;
5986
- const version = "55.9.0";
5991
+ const version = "55.9.1";
5987
5992
  let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
5988
5993
  let nanoid = (size2 = 21) => {
5989
5994
  let id2 = "";
@@ -10612,7 +10617,7 @@ class PlanPricingBracketModel {
10612
10617
  this.price = parsePrice(price);
10613
10618
  }
10614
10619
  }
10615
- const _PlanPricingModel = class _PlanPricingModel {
10620
+ const _PlanPricingModel = class _PlanPricingModel2 {
10616
10621
  // {
10617
10622
  // formula = PlanPricingModel.Formulas.fixedFee,
10618
10623
  // price = 0,
@@ -10620,11 +10625,11 @@ const _PlanPricingModel = class _PlanPricingModel {
10620
10625
  // brackets = [],
10621
10626
  // }
10622
10627
  constructor(data = {}) {
10623
- this.formula = data.formula ?? _PlanPricingModel.Formulas.fixedFee;
10628
+ this.formula = data.formula ?? _PlanPricingModel2.Formulas.fixedFee;
10624
10629
  switch (data.formula) {
10625
- case _PlanPricingModel.Formulas.stairstep:
10626
- case _PlanPricingModel.Formulas.tiered:
10627
- case _PlanPricingModel.Formulas.volume:
10630
+ case _PlanPricingModel2.Formulas.stairstep:
10631
+ case _PlanPricingModel2.Formulas.tiered:
10632
+ case _PlanPricingModel2.Formulas.volume:
10628
10633
  if (data.brackets == null) {
10629
10634
  throw new Error("Invalid brackets.");
10630
10635
  }
@@ -10632,23 +10637,23 @@ const _PlanPricingModel = class _PlanPricingModel {
10632
10637
  (bracket) => new PlanPricingBracketModel(bracket)
10633
10638
  );
10634
10639
  break;
10635
- case _PlanPricingModel.Formulas.flatRate:
10640
+ case _PlanPricingModel2.Formulas.flatRate:
10636
10641
  this.price = parsePrice(data.price) ?? 0;
10637
10642
  this.maxQuantity = data.maxQuantity ?? null;
10638
10643
  break;
10639
- case _PlanPricingModel.Formulas.fixedFee:
10644
+ case _PlanPricingModel2.Formulas.fixedFee:
10640
10645
  default:
10641
10646
  this.price = parsePrice(data.price) ?? 0;
10642
10647
  break;
10643
10648
  }
10644
10649
  }
10645
10650
  get isSimple() {
10646
- return Object.values(_PlanPricingModel.SimpleFormulas).includes(
10651
+ return Object.values(_PlanPricingModel2.SimpleFormulas).includes(
10647
10652
  this.formula
10648
10653
  );
10649
10654
  }
10650
10655
  get isBracket() {
10651
- return Object.values(_PlanPricingModel.BracketFormulas).includes(
10656
+ return Object.values(_PlanPricingModel2.BracketFormulas).includes(
10652
10657
  this.formula
10653
10658
  );
10654
10659
  }
@@ -13926,7 +13931,7 @@ class PaymentMetadataModel extends BaseModel {
13926
13931
  return this.landscapeLogo || this.portraitLogo;
13927
13932
  }
13928
13933
  }
13929
- const _ReadyToPayFeatureModel = class _ReadyToPayFeatureModel {
13934
+ class ReadyToPayFeatureModel {
13930
13935
  constructor({
13931
13936
  name = "",
13932
13937
  expirationTime = "",
@@ -13954,13 +13959,12 @@ const _ReadyToPayFeatureModel = class _ReadyToPayFeatureModel {
13954
13959
  this.paypalClientId = paypalClientId;
13955
13960
  this.linkToken = linkToken;
13956
13961
  }
13957
- };
13958
- _ReadyToPayFeatureModel.FeatureName = {
13962
+ }
13963
+ ReadyToPayFeatureModel.FeatureName = {
13959
13964
  paypalBillingAgreement: "PayPal billing agreement",
13960
13965
  googlePay: "Google Pay",
13961
13966
  applePay: "Apple Pay"
13962
13967
  };
13963
- let ReadyToPayFeatureModel = _ReadyToPayFeatureModel;
13964
13968
  class ReadyToPayModel {
13965
13969
  constructor({
13966
13970
  index: index2 = null,
@@ -14131,9 +14135,9 @@ async function fetchReadyToPayout() {
14131
14135
  return filterReadyToPayout(readyToPayout);
14132
14136
  });
14133
14137
  }
14134
- const _InvoiceModel = class _InvoiceModel extends BaseModel {
14138
+ const _InvoiceModel = class _InvoiceModel2 extends BaseModel {
14135
14139
  get isPaid() {
14136
- return this.status === _InvoiceModel.Status.paid;
14140
+ return this.status === _InvoiceModel2.Status.paid;
14137
14141
  }
14138
14142
  };
14139
14143
  _InvoiceModel.Status = {
@@ -14657,11 +14661,11 @@ async function fetchData({
14657
14661
  }
14658
14662
  function mountExpressMethod({ state: state2, id: id2 }) {
14659
14663
  const { Rebilly } = window;
14660
- const container = document.querySelector(
14664
+ const container = state2.form.querySelector(
14661
14665
  `.rebilly-instruments-${id2}-method`
14662
14666
  );
14663
14667
  function updateApplePayStyling() {
14664
- const applePayButton = document.querySelector(
14668
+ const applePayButton = state2.form.querySelector(
14665
14669
  "#rebilly-apple-pay-button"
14666
14670
  );
14667
14671
  const {
@@ -14679,10 +14683,11 @@ function mountExpressMethod({ state: state2, id: id2 }) {
14679
14683
  "pay-pal-billing-agreement": "paypal",
14680
14684
  "apple-pay": "applePay"
14681
14685
  };
14686
+ const element = state2.form.querySelector(
14687
+ `.rebilly-instruments-${id2}-method`
14688
+ );
14682
14689
  if (rebillyMountFunction[id2]) {
14683
- Rebilly[rebillyMountFunction[id2]].mount(
14684
- `.rebilly-instruments-${id2}-method`
14685
- );
14690
+ Rebilly[rebillyMountFunction[id2]].mount(element);
14686
14691
  if (id2 === "apple-pay") {
14687
14692
  updateApplePayStyling();
14688
14693
  }
@@ -15125,7 +15130,7 @@ async function mountMethodSelector() {
15125
15130
  state.options.digitalWallet = generateDigitalWallet({
15126
15131
  expressMethods
15127
15132
  });
15128
- const container = document.querySelector(
15133
+ const container = state.form.querySelector(
15129
15134
  '[data-rebilly-instruments="express-methods-container"]'
15130
15135
  );
15131
15136
  mountExpressMethods({
@@ -15188,7 +15193,7 @@ const baseMethodSelectorHTML = () => `
15188
15193
  async function mountForm() {
15189
15194
  var _a;
15190
15195
  state.form.innerHTML += baseMethodSelectorHTML();
15191
- const container = document.querySelector(
15196
+ const container = state.form.querySelector(
15192
15197
  '[data-rebilly-instruments="form"]'
15193
15198
  );
15194
15199
  const { paymentMethodsUrl: url } = ((_a = state == null ? void 0 : state.options) == null ? void 0 : _a._computed) || {};
@@ -15222,7 +15227,7 @@ function determineFirstView() {
15222
15227
  }
15223
15228
  }
15224
15229
  function removeForm() {
15225
- const container = document.querySelector(
15230
+ const container = state.form.querySelector(
15226
15231
  '[data-rebilly-instruments="form"]'
15227
15232
  );
15228
15233
  container.remove();
@@ -15242,9 +15247,11 @@ function addDOMElement({
15242
15247
  if (content2) {
15243
15248
  ELEMENT.innerHTML = content2;
15244
15249
  }
15245
- document[target][insertMethod](
15246
- ELEMENT
15247
- );
15250
+ if (target instanceof ShadowRoot) {
15251
+ target.prepend(ELEMENT);
15252
+ } else {
15253
+ document[target][insertMethod](ELEMENT);
15254
+ }
15248
15255
  }
15249
15256
  function hasValidCSSSelector(selector) {
15250
15257
  const REGEX_CSS_SELECTOR = /([.#][_a-z]+[_a-z0-9-:\\]*)/gi;
@@ -15283,7 +15290,7 @@ function sleep(ms) {
15283
15290
  const setupElement = ({ element = "" }) => {
15284
15291
  const { options } = state;
15285
15292
  if (element !== "form" && element !== "summary") {
15286
- throw new Error('element must be "form" or "summary"');
15293
+ throw new Error('element must be "form", or "summary"');
15287
15294
  }
15288
15295
  const getProp = () => {
15289
15296
  if (options != null && options[element]) {
@@ -23289,7 +23296,7 @@ function handleComputedProperty(options) {
23289
23296
  var _a;
23290
23297
  return Object.assign({}, options, {
23291
23298
  _computed: {
23292
- version: "8.11.0",
23299
+ version: "8.12.1",
23293
23300
  paymentMethodsUrl: ((_a = options._dev) == null ? void 0 : _a.paymentMethodsUrl) ?? "https://forms.secure-payments.app"
23294
23301
  }
23295
23302
  });
@@ -24998,7 +25005,7 @@ const theme = new Proxy(properties, {
24998
25005
  return true;
24999
25006
  }
25000
25007
  });
25001
- const _Theme = class _Theme {
25008
+ const _Theme = class _Theme2 {
25002
25009
  constructor(overrides = {}) {
25003
25010
  this.overrides = overrides;
25004
25011
  this.theme = theme;
@@ -25009,7 +25016,7 @@ const _Theme = class _Theme {
25009
25016
  });
25010
25017
  }
25011
25018
  get cssVars() {
25012
- return Object.keys(this.theme).filter((v2) => !_Theme.nonCssProperties.includes(v2)).map((p2, i2) => `${!i2 ? "" : " "}--rebilly-${p2}: ${this.theme[p2]};`).join("\n");
25019
+ return Object.keys(this.theme).filter((v2) => !_Theme2.nonCssProperties.includes(v2)).map((p2, i2) => `${!i2 ? "" : " "}--rebilly-${p2}: ${this.theme[p2]};`).join("\n");
25013
25020
  }
25014
25021
  build() {
25015
25022
  this.overrideTheme();
@@ -25023,7 +25030,7 @@ let Theme = _Theme;
25023
25030
  const vars = (theme2) => `
25024
25031
  /* Instruments 'global' variables
25025
25032
  ------------------------------------------------------------ */
25026
- :root {
25033
+ :root, :host {
25027
25034
  ${theme2.cssVars}
25028
25035
 
25029
25036
  --rebilly-fontWeight400: 400;
@@ -25176,6 +25183,12 @@ const vars = (theme2) => `
25176
25183
  border-radius: 100px;
25177
25184
  }
25178
25185
 
25186
+ .rebilly-instruments-express-methods .rebilly-instruments-google-pay-method iframe {
25187
+ width: 100%;
25188
+ height: 100%;
25189
+ border: none;
25190
+ }
25191
+
25179
25192
  @media (max-width: 600px) {
25180
25193
  .rebilly-instruments-express-methods.is-compact .rebilly-instruments-express-methods-container {
25181
25194
  -webkit-box-orient: vertical;
@@ -25732,14 +25745,14 @@ const setupStylesVars = () => {
25732
25745
  element: "style",
25733
25746
  attributes: { type: "text/css" },
25734
25747
  content: minifyCss(styleVars),
25735
- target: "head"
25748
+ target: state.shadowRoot || "head"
25736
25749
  });
25737
25750
  if (css) {
25738
25751
  addDOMElement({
25739
25752
  element: "style",
25740
25753
  attributes: { type: "text/css" },
25741
25754
  content: minifyCss(css),
25742
- target: "head"
25755
+ target: state.shadowRoot || "head"
25743
25756
  });
25744
25757
  }
25745
25758
  return styleVars;
@@ -25889,16 +25902,16 @@ async function mountModal({
25889
25902
  "beforeend",
25890
25903
  modalTemplate(isRedirect, method)
25891
25904
  );
25892
- const modalOverlay = document.querySelector(
25905
+ const modalOverlay = state.form.querySelector(
25893
25906
  ".rebilly-instruments-modal-overlay"
25894
25907
  );
25895
- const modalContainer = document.querySelector(
25908
+ const modalContainer = state.form.querySelector(
25896
25909
  ".rebilly-instruments-modal-container"
25897
25910
  );
25898
- const closeButton = document.querySelector(
25911
+ const closeButton = state.form.querySelector(
25899
25912
  ".rebilly-instruments-modal-close"
25900
25913
  );
25901
- const modalContent = document.querySelector(
25914
+ const modalContent = state.form.querySelector(
25902
25915
  ".rebilly-instruments-modal-content"
25903
25916
  );
25904
25917
  document.body.style.overflow = "hidden";
@@ -26346,6 +26359,14 @@ const setupUserFlow = ({ state: state2 = {} }) => {
26346
26359
  });
26347
26360
  }
26348
26361
  };
26362
+ function getShadowParent(element) {
26363
+ while (element.parentNode && (element = element.parentNode)) {
26364
+ if (element instanceof ShadowRoot) {
26365
+ return element;
26366
+ }
26367
+ }
26368
+ return null;
26369
+ }
26349
26370
  async function mount({
26350
26371
  setupFramepay: setupFramepay$1 = setupFramepay,
26351
26372
  ...options
@@ -26357,6 +26378,7 @@ async function mount({
26357
26378
  state.options = setupOptions({ options });
26358
26379
  state.form = setupElement({ element: "form" });
26359
26380
  state.summary = setupElement({ element: "summary" });
26381
+ state.shadowRoot = getShadowParent(state.form);
26360
26382
  if (state.form) {
26361
26383
  state.form.style.maxWidth = "750px";
26362
26384
  }
@@ -26478,7 +26500,7 @@ class RebillyInstrumentsInstance {
26478
26500
  await show({ componentName, payload });
26479
26501
  }
26480
26502
  get version() {
26481
- return `RebillyInstruments Ver.${"8.11.0"}`;
26503
+ return `RebillyInstruments Ver.${"8.12.1"}`;
26482
26504
  }
26483
26505
  on(eventName, callback) {
26484
26506
  on({ eventName, callback });