@fungies/fungies-js 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@fungies/fungies-js": patch
3
+ ---
4
+
5
+ Auto open embed checkout
package/.gitlab-ci.yml ADDED
@@ -0,0 +1,73 @@
1
+ .fungies-js-rules:
2
+ rules:
3
+ - &fungies-js-changes-on-master
4
+ if: $CI_COMMIT_BRANCH == "master"
5
+ changes:
6
+ paths:
7
+ - "packages/fungies-js/**/*"
8
+ - &fungies-js-changes-on-mr
9
+ if: $CI_COMMIT_BRANCH != "master" && $CI_PIPELINE_SOURCE == "merge_request_event"
10
+ changes:
11
+ compare_to: "refs/heads/master"
12
+ paths:
13
+ - "packages/fungies-js/**/*"
14
+
15
+ fungies-js-build:
16
+ stage: build
17
+ extends: .use-monorepo
18
+ script:
19
+ - pnpm --filter @fungies/fungies-js install --frozen-lockfile
20
+ - pnpm --filter @fungies/fungies-js biome lint
21
+ - if [ "$CI_PIPELINE_SOURCE" = "merge_request_event" ]; then echo "$CI_MERGE_REQUEST_TITLE"; fi
22
+ - pnpm --filter @fungies/fungies-js build
23
+ rules:
24
+ - *fungies-js-changes-on-master
25
+ - *fungies-js-changes-on-mr
26
+ tags:
27
+ - dedicated
28
+
29
+ fungies-js-publish:
30
+ stage: publish
31
+ extends: .use-monorepo
32
+ script:
33
+ - |
34
+ echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
35
+
36
+ cd packages/fungies-js
37
+ pnpm install --frozen-lockfile
38
+
39
+ # Check for changes
40
+ npx @changesets/cli status --output=release.json || true
41
+
42
+ if [ ! -f "release.json" ]; then
43
+ echo "No changes to publish"
44
+ exit 0
45
+ fi
46
+
47
+ CHANGED_PACKAGES=$(jq -r '.releases | map(.name + "@" + .newVersion) | join(", ")' release.json)
48
+ echo "CHANGED_PACKAGES=$CHANGED_PACKAGES" >> variables.env
49
+
50
+ # Create commit with release info
51
+ git config --global user.name "GitLab CI"
52
+ git config --global user.email "gitlab-ci@example.com"
53
+
54
+ # Run the release process
55
+ pnpm run release
56
+
57
+ # Commit and push changes
58
+ git add .
59
+ git commit -m "chore(release): $CHANGED_PACKAGES"
60
+ git push origin $CI_COMMIT_BRANCH
61
+ rules:
62
+ - if: $CI_COMMIT_BRANCH == "master"
63
+ when: manual
64
+ needs:
65
+ - job: fungies-js-build
66
+ optional: true
67
+ variables:
68
+ GIT_STRATEGY: clone
69
+ artifacts:
70
+ reports:
71
+ dotenv: packages/fungies-js/variables.env
72
+ tags:
73
+ - dedicated
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## 0.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Auto open embed checkout
8
+ - fix displaying checkout element
9
+
10
+ ## 0.0.3
11
+
12
+ ### Patch Changes
13
+
14
+ -Allow to open embed checkout automatically.
package/README.md CHANGED
@@ -48,21 +48,33 @@ You can also use HTML data attributes to create checkout buttons without writing
48
48
 
49
49
  ```html
50
50
  <!-- Basic checkout button -->
51
- <button data-fungies-checkout-url="https://store.example.com/checkout-element/my-checkout-id" data-fungies-mode="overlay">
52
- Open Checkout
53
- </button>
54
-
55
- <!-- Embed checkout with target element -->
56
51
  <button
57
52
  data-fungies-checkout-url="https://store.example.com/checkout-element/my-checkout-id"
58
- data-fungies-mode="embed"
59
- data-fungies-frame-target="target-element-id"
53
+ data-fungies-mode="overlay"
60
54
  >
61
- Open Embed Checkout
55
+ Open Checkout
62
56
  </button>
63
57
 
64
- <!-- Target container for embed checkout -->
58
+ <!-- Script tag to initialize the SDK -->
59
+ <script
60
+ src="https://cdn.jsdelivr.net/npm/@fungies/fungies-js@CURRENT_VERSION"
61
+ defer
62
+ data-auto-init
63
+ ></script>
64
+
65
+ <!-- Embed checkout with target element -->
65
66
  <div id="target-element-id"></div>
67
+
68
+ <!-- Script tag to initialize and display checkout automatically -->
69
+ <script
70
+ src="https://cdn.jsdelivr.net/npm/@fungies/fungies-js@CURRENT_VERSION"
71
+ defer
72
+ data-auto-init
73
+ data-auto-display-checkout
74
+ data-fungies-checkout-url="https://demo.dev.fungies.net/checkout-element/a85d8c76-bc30-48a3-9861-be68952a1eca"
75
+ data-fungies-mode="embed"
76
+ data-fungies-frame-target="target-element-id"
77
+ ></script>
66
78
  ```
67
79
 
68
80
  ### Manual DOM Scanning
@@ -86,7 +98,6 @@ Fungies.ScanDOM();
86
98
  - `data-fungies-custom-fields`: (Optional) JSON string of custom fields
87
99
  - `data-fungies-button`: (Legacy format) Contains a checkout URL like "https://STORE_URL/checkout-element/:checkoutID" or "https://STORE_URL/overlay/:checkoutID"
88
100
 
89
-
90
101
  ## TypeScript Support
91
102
 
92
103
  This package includes TypeScript definitions. You can take advantage of type checking and IntelliSense in supported editors:
@@ -107,72 +118,3 @@ const openOptions: InitialCheckoutOpenOptions = {
107
118
 
108
119
  Fungies.Checkout.open(openOptions);
109
120
  ```
110
-
111
- ## Development
112
-
113
- ### Building the Package Locally
114
-
115
- ```bash
116
- # Clone the repository
117
- git clone <repository-url>
118
- cd fungies-js
119
-
120
- # Install dependencies
121
- pnpm install
122
-
123
- # Build the package
124
- pnpm run build
125
- ```
126
-
127
- ### Testing with pnpm link
128
-
129
- You can use pnpm link to create a symbolic link to your local package:
130
-
131
- ```bash
132
- pnpm setup # only if you haven't already
133
-
134
- # In the fungies-js directory
135
- pnpm link --global
136
-
137
- # In your test project directory
138
- pnpm link fungies-js
139
- ```
140
-
141
- ### Alternative: Direct Path Reference
142
-
143
- Alternatively, you can reference the package directly in your test project's package.json:
144
-
145
- ```json
146
- {
147
- "dependencies": {
148
- "@fungies/fungies-js": "file:/path/to/fungies-js"
149
- }
150
- }
151
- ```
152
-
153
- Then run `pnpm install` in your test project.
154
-
155
- ### After Making Changes
156
-
157
- When you make changes to the package:
158
-
159
- 1. Rebuild the package:
160
-
161
- ```bash
162
- # In the fungies-js directory
163
- pnpm run build
164
- ```
165
-
166
- 2. The changes will be automatically reflected in your linked project.
167
-
168
- ### Unlinking
169
-
170
- When you're done testing:
171
-
172
- ```bash
173
- # In your test project
174
- pnpm unlink fungies-js
175
-
176
- # In the fungies-js directory (optional)
177
- pnpm unlink --global
178
- ```
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var e=Object.defineProperty,t=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,o=(t,n,i)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[n]=i,a=(e,a)=>{for(var r in a||(a={}))n.call(a,r)&&o(e,r,a[r]);if(t)for(var r of t(a))i.call(a,r)&&o(e,r,a[r]);return e},r=(e,o)=>{var a={};for(var r in e)n.call(e,r)&&o.indexOf(r)<0&&(a[r]=e[r]);if(null!=e&&t)for(var r of t(e))o.indexOf(r)<0&&i.call(e,r)&&(a[r]=e[r]);return a},s=(e,t="log",n=!1,i={isEnabled:!0})=>{if(!i.isEnabled)return;window.console.debug=window.console.debug||window.console.log;const o=`[Fungies Debug]${e}`;"log"===t?console.debug(o):"warning"===t&&console.warn(o),n&&console.warn(e)};function d(e,t){const n=document.getElementsByClassName(e);for(let e=0;e<n.length;e++){const i=n[e];if("function"!=typeof t)throw new Error("each(className, function() {... requires the callback argument to be of type Function");t(i)}}function l(){d("fungies-loader",(e=>{var t;null==(t=null==e?void 0:e.parentNode)||t.removeChild(e)}))}function c(e){const t=e.getAttribute("data-fungies-checkout-url");t||s("Element has data-fungies-checkout-url attribute but no value","warning");const n=e.getAttribute("data-fungies-mode"),i="embed"===n||"overlay"===n?n:"overlay",o=e.getAttribute("data-fungies-frame-target")||void 0,r=e.getAttribute("data-fungies-discount-code")||void 0,d=e.getAttribute("data-fungies-customer-email")||void 0,l=e.getAttribute("data-fungies-quantity"),c=l?Number.parseInt(l,10):void 0;let u;const m=e.getAttribute("data-fungies-items");if(m)try{u=JSON.parse(m)}catch(e){s(`Invalid JSON in data-fungies-items: ${m}`,"warning")}let g;const p=e.getAttribute("data-fungies-custom-fields");if(p)try{g=JSON.parse(p)}catch(e){s(`Invalid JSON in data-fungies-custom-fields: ${p}`,"warning")}return a(a(a(a(a({checkoutUrl:t,settings:a({mode:i},o&&{frameTarget:o})},r&&{discountCode:r}),d&&{customerEmail:d}),c&&{quantity:c}),u&&{items:u}),g&&{customFields:g})}var u="closeWindow",m="embed";var g=(e,t,n)=>{const i=new URL(t);var o;return i.searchParams.append("fngs-checkout-payload",(o=JSON.stringify(e),encodeURIComponent(encodeURIComponent(o)))),i.searchParams.append("fngs-display-mode",n),i.toString()},p=()=>{s("Checkout frame/window has been closed."),l(),d("fungies-frame",(e=>{var t;null==(t=e.parentNode)||t.removeChild(e)})),void 0===window.FungiesWindow||window.FungiesWindow.closed||window.FungiesWindow.close()},f=(e,t,n)=>{var i;const o=((e,t)=>{var n=e,{checkoutUrl:i}=n,o=r(n,["checkoutUrl"]);return g(o,i,t)})(e,t.mode);if(n||function(){l();const e=document.createElement("style");e.type="text/css",e.innerHTML="\t\t\t\t@-webkit-keyframes rotate {\t\t\t\t\t0% {\t\t\t\t\t\t-webkit-transform: rotate(45deg);\t\t\t\t\t}\t\t\t\t\t100% {\t\t\t\t\t\t-webkit-transform: rotate(405deg);\t\t\t\t\t}\t\t\t\t}\t\t\t\t@keyframes rotate {\t\t\t\t\tfrom {\t\t\t\t\t\ttransform: rotate(45deg);\t\t\t\t\t}\t\t\t\t\tto {\t\t\t\t\t\ttransform: rotate(405deg);\t\t\t\t\t}\t\t\t\t}";const t=document.getElementsByTagName("head")[0];t&&t.appendChild(e);const n=document.createElement("div");n.setAttribute("style","z-index:99998; display: block; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; right: 0px; bottom: 0px; margin: 0px; padding: 0px; background: rgba(0,0,0,0.38);"),n.setAttribute("class","fungies-loader");const i=document.createElement("main");i.setAttribute("style","align-items: center;display: flex;flex-direction: column;justify-content: center;left: 50%;margin: 0.5rem 0;position: absolute;text-align: center;top: 50%;transform: translate(-50%, -50%);width: 90%;");const o=document.createElement("div");o.setAttribute("style","border: 4px solid #f3f3f3;border-radius: 50%;border-top: 4px solid #ccc;width: 34px;height: 34px;-webkit-animation: rotate 1s ease-in-out infinite forwards;animation: rotate 1s ease-in-out infinite forwards;"),i.appendChild(o),n.appendChild(i);const a=()=>{const e=document.getElementsByTagName("body")[0];e&&e.appendChild(n)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",a):a()}(),window.FungiesFrame=document.createElement("iframe"),window.FungiesFrame.className="fungies-frame",window.FungiesFrame.name="fungies_frame",window.FungiesFrame.frameBorder="0",window.FungiesFrame.allowTransparency="true",window.FungiesFrame.allow="payment",n){window.FungiesFrame.classList.add("fungies-frame-embed"),window.FungiesFrame.setAttribute("style","width: 100%; height: 100%;");const e=document.createElement("style");e.type="text/css",e.innerHTML=".fungies-frame-embed::-webkit-scrollbar { display: none !important; }",null==(i=null==document?void 0:document.getElementsByTagName("head")[0])||i.appendChild(e)}else window.FungiesFrame.classList.add("fungies-frame-overlay");if(n||(!function(){let e=!1;var t;return t=navigator.userAgent||navigator.vendor,(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(t.substr(0,4)))&&(e=!0),e}()?window.FungiesFrame.setAttribute("style","z-index: 2147483647; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: auto; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;"):window.FungiesFrame.setAttribute("style","z-index: 2147483647; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: scroll; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;")),window.FungiesFrame.src=o,(null==t?void 0:t.frameTarget)&&n){const e=document.getElementById(t.frameTarget);e&&e.appendChild(window.FungiesFrame)}else{const e=document.getElementsByTagName("body")[0];e&&e.appendChild(window.FungiesFrame)}},w=e=>{var t=e,{settings:n}=t,i=r(t,["settings"]);p();const o=()=>{s("Checkout.open() called"),f(i,n,(null==n?void 0:n.mode)===m)};"loading"!==document.readyState?o():document.addEventListener("DOMContentLoaded",o)},b=()=>{s("Scanning for checkout elements");const e=document.querySelectorAll("[data-fungies-checkout-url]:not([data-fungies-initialized])");for(const t of e){const e=c(t);t.addEventListener("click",(t=>{t.preventDefault(),w(e)})),t.setAttribute("data-fungies-initialized","true")}const t=document.querySelectorAll("[data-fungies-button]:not([data-fungies-initialized])");for(const e of t){const t=e.getAttribute("data-fungies-button");if(t)try{const n=new URL(t).pathname.split("/"),i=n.indexOf("checkout-element"),o=n.indexOf("overlay");if(-1===i&&-1===o){s(`Invalid URL in data-fungies-button: ${t}`,"warning");continue}const a={checkoutUrl:t,settings:{mode:"overlay"}};e.addEventListener("click",(e=>{e.preventDefault(),w(a)})),e.setAttribute("data-fungies-initialized","true")}catch(e){s(e,"error")}else s("Element has data-fungies-button attribute but no value","warning")}},h=e=>{const{data:t}=e;if(("string"==typeof t?t:"")===u)p()};var v={Checkout:{open:w,close:()=>{p()}},Initialize:(e,t={completedSetup:!1,options:null})=>{t.completedSetup?s("Cannot call Fungies.Initialize() more than once per page, the call was ignored.","warning"):("undefined"!=typeof window&&window.addEventListener("message",h,!1),!1!==e.enableDataAttributes&&(s("Initializing DOM support"),"loading"!==document.readyState?b():document.addEventListener("DOMContentLoaded",b),new MutationObserver((e=>{let t=!1;for(const n of e)if("childList"===n.type&&n.addedNodes.length>0)for(const e of n.addedNodes)if(e.nodeType===Node.ELEMENT_NODE&&e.querySelector("[data-fungies-checkout-url]:not([data-fungies-initialized]), [data-fungies-button]:not([data-fungies-initialized])")){t=!0;break}t&&b()})).observe(document.body,{childList:!0,subtree:!0})),((e,t)=>{a(a({},e),t)})(t,{completedSetup:!0,options:e}))},ScanDOM:b};if("undefined"!=typeof window&&(window.Fungies=v),"undefined"!=typeof document){const e=document.currentScript;if((null==e?void 0:e.hasAttribute("data-auto-init"))&&(v.Initialize({enableDataAttributes:!0}),null==e?void 0:e.hasAttribute("data-auto-display-checkout"))){const t=c(e);v.Checkout.open(t)}}})();
package/dist/index.mjs CHANGED
@@ -1,375 +1 @@
1
- // src/constants/checkout.ts
2
- var CHECKOUT_FRAME_CLOSED = "Checkout frame/window has been closed.";
3
- var CHECKOUT_EVENTS = {
4
- CHECKOUT_CLOSE: "closeWindow"
5
- };
6
- var CHECKOUT_MODE = {
7
- EMBED: "embed",
8
- OVERLAY: "overlay"
9
- };
10
-
11
- // src/lib/logger.ts
12
- var createLoggerConfig = () => ({
13
- isEnabled: true
14
- });
15
- var log = (message, type = "log" /* LOG */, alwaysShow = false, config = createLoggerConfig()) => {
16
- if (!config.isEnabled) return;
17
- window.console.debug = window.console.debug || window.console.log;
18
- const debugMessage = `[Fungies Debug]${message}`;
19
- if (type === "log" /* LOG */) {
20
- console.debug(debugMessage);
21
- } else if (type === "warning" /* WARNING */) {
22
- console.warn(debugMessage);
23
- }
24
- if (alwaysShow) {
25
- console.warn(message);
26
- }
27
- };
28
-
29
- // src/utils/device.ts
30
- function isMobile() {
31
- let check = false;
32
- ((a) => {
33
- if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
34
- a
35
- ) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(
36
- a.substr(0, 4)
37
- ))
38
- check = true;
39
- })(navigator.userAgent || navigator.vendor);
40
- return check;
41
- }
42
-
43
- // src/utils/html.ts
44
- function each(className, callback) {
45
- const elements = document.getElementsByClassName(className);
46
- for (let i = 0; i < elements.length; i++) {
47
- const thisElement = elements[i];
48
- if (typeof callback === "function") {
49
- callback(thisElement);
50
- } else {
51
- throw new Error("each(className, function() {... requires the callback argument to be of type Function");
52
- }
53
- }
54
- }
55
-
56
- // src/utils/url.ts
57
- var encodeForTransport = (jsonString) => {
58
- return encodeURIComponent(encodeURIComponent(jsonString));
59
- };
60
- var getCheckoutFrontEndURL = (checkoutInputAttributes, checkoutUrl, mode) => {
61
- const url = new URL(checkoutUrl);
62
- url.searchParams.append("fngs-checkout-payload", encodeForTransport(JSON.stringify(checkoutInputAttributes)));
63
- url.searchParams.append("fngs-display-mode", mode);
64
- return url.toString();
65
- };
66
- var getCheckoutUrl = ({ checkoutUrl, ...restProps }, mode) => {
67
- return getCheckoutFrontEndURL(restProps, checkoutUrl, mode);
68
- };
69
-
70
- // src/helpers/checkout.ts
71
- function showLoading() {
72
- hideLoading();
73
- const keyFrameStyle = document.createElement("style");
74
- keyFrameStyle.type = "text/css";
75
- keyFrameStyle.innerHTML = // eslint-disable-next-line no-multi-str
76
- " @-webkit-keyframes rotate { 0% { -webkit-transform: rotate(45deg); } 100% { -webkit-transform: rotate(405deg); } } @keyframes rotate { from { transform: rotate(45deg); } to { transform: rotate(405deg); } }";
77
- const head = document.getElementsByTagName("head")[0];
78
- if (head) {
79
- head.appendChild(keyFrameStyle);
80
- }
81
- const htmlLoader = document.createElement("div");
82
- htmlLoader.setAttribute(
83
- "style",
84
- "z-index:99998; display: block; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; right: 0px; bottom: 0px; margin: 0px; padding: 0px; background: rgba(0,0,0,0.38);"
85
- );
86
- htmlLoader.setAttribute("class", "fungies-loader" /* FUNGIES_LOADER */);
87
- const mainSpinnerWrapper = document.createElement("main");
88
- const htmlLoaderIconWrapper = "align-items: center;display: flex;flex-direction: column;justify-content: center;left: 50%;margin: 0.5rem 0;position: absolute;text-align: center;top: 50%;transform: translate(-50%, -50%);width: 90%;";
89
- mainSpinnerWrapper.setAttribute("style", htmlLoaderIconWrapper);
90
- const spinner = document.createElement("div");
91
- const htmlLoaderIcon = "border: 4px solid #f3f3f3;border-radius: 50%;border-top: 4px solid #ccc;width: 34px;height: 34px;-webkit-animation: rotate 1s ease-in-out infinite forwards;animation: rotate 1s ease-in-out infinite forwards;";
92
- spinner.setAttribute("style", htmlLoaderIcon);
93
- mainSpinnerWrapper.appendChild(spinner);
94
- htmlLoader.appendChild(mainSpinnerWrapper);
95
- const appendLoader = () => {
96
- const body = document.getElementsByTagName("body")[0];
97
- if (body) {
98
- body.appendChild(htmlLoader);
99
- }
100
- };
101
- if (document.readyState === "loading") {
102
- document.addEventListener("DOMContentLoaded", appendLoader);
103
- } else {
104
- appendLoader();
105
- }
106
- }
107
- function hideLoading() {
108
- each("fungies-loader" /* FUNGIES_LOADER */, (loader) => {
109
- loader?.parentNode?.removeChild(loader);
110
- });
111
- }
112
-
113
- // src/helpers/iframe.ts
114
- var closeCheckoutIFrame = () => {
115
- log(CHECKOUT_FRAME_CLOSED);
116
- hideLoading();
117
- each("fungies-frame" /* FUNGIES_FRAME */, (element) => {
118
- element.parentNode?.removeChild(element);
119
- });
120
- if (typeof window.FungiesWindow !== "undefined" && !window.FungiesWindow.closed) {
121
- window.FungiesWindow.close();
122
- }
123
- };
124
- var renderCheckoutFrame = (checkoutProps, settings, embed) => {
125
- const checkoutUrl = getCheckoutUrl(checkoutProps, settings.mode);
126
- if (!embed) {
127
- showLoading();
128
- }
129
- window.FungiesFrame = document.createElement("iframe");
130
- window.FungiesFrame.className = "fungies-frame" /* FUNGIES_FRAME */;
131
- window.FungiesFrame.name = "fungies_frame";
132
- window.FungiesFrame.frameBorder = "0";
133
- window.FungiesFrame.allowTransparency = "true";
134
- window.FungiesFrame.allow = "payment";
135
- if (embed) {
136
- window.FungiesFrame.classList.add("fungies-frame-embed" /* FUNGIES_FRAME_EMBED */);
137
- window.FungiesFrame.setAttribute("style", "width: 100%; height: 100%;");
138
- const styleElement = document.createElement("style");
139
- styleElement.type = "text/css";
140
- styleElement.innerHTML = `.${"fungies-frame-embed" /* FUNGIES_FRAME_EMBED */}::-webkit-scrollbar { display: none !important; }`;
141
- document?.getElementsByTagName("head")[0]?.appendChild(styleElement);
142
- } else {
143
- window.FungiesFrame.classList.add("fungies-frame-overlay" /* FUNGIES_FRAME_OVERLAY */);
144
- }
145
- if (!embed) {
146
- if (!isMobile()) {
147
- window.FungiesFrame.setAttribute(
148
- "style",
149
- "z-index: 2147483647; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: auto; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;"
150
- );
151
- } else {
152
- window.FungiesFrame.setAttribute(
153
- "style",
154
- "z-index: 2147483647; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: scroll; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;"
155
- );
156
- }
157
- }
158
- window.FungiesFrame.src = checkoutUrl;
159
- if (settings?.frameTarget && embed) {
160
- const target = document.getElementById(settings.frameTarget);
161
- if (target) {
162
- target.appendChild(window.FungiesFrame);
163
- }
164
- } else {
165
- const body = document.getElementsByTagName("body")[0];
166
- if (body) {
167
- body.appendChild(window.FungiesFrame);
168
- }
169
- }
170
- };
171
-
172
- // src/lib/checkout.ts
173
- var openCheckout = ({ settings, ...checkoutInputAttributes }) => {
174
- closeCheckoutIFrame();
175
- const renderCheckoutWithSettings = () => {
176
- log("Checkout.open() called");
177
- renderCheckoutFrame(checkoutInputAttributes, settings, settings?.mode === CHECKOUT_MODE.EMBED);
178
- };
179
- if (document.readyState !== "loading") {
180
- renderCheckoutWithSettings();
181
- } else {
182
- document.addEventListener("DOMContentLoaded", renderCheckoutWithSettings);
183
- }
184
- };
185
- var closeCheckout = () => {
186
- closeCheckoutIFrame();
187
- };
188
-
189
- // src/helpers/dom.ts
190
- var scanForCheckoutElements = () => {
191
- log("Scanning for checkout elements");
192
- const newFormatElements = document.querySelectorAll("[data-fungies-checkout-url]:not([data-fungies-initialized])");
193
- for (const element of newFormatElements) {
194
- const checkoutUrl = element.getAttribute("data-fungies-checkout-url");
195
- if (!checkoutUrl) {
196
- log("Element has data-fungies-checkout-url attribute but no value", "warning" /* WARNING */);
197
- continue;
198
- }
199
- const modeAttr = element.getAttribute("data-fungies-mode");
200
- const mode = modeAttr === "embed" || modeAttr === "overlay" ? modeAttr : "overlay";
201
- const frameTarget = element.getAttribute("data-fungies-frame-target") || void 0;
202
- const discountCode = element.getAttribute("data-fungies-discount-code") || void 0;
203
- const customerEmail = element.getAttribute("data-fungies-customer-email") || void 0;
204
- const quantityAttr = element.getAttribute("data-fungies-quantity");
205
- const quantity = quantityAttr ? Number.parseInt(quantityAttr, 10) : void 0;
206
- let items = void 0;
207
- const itemsAttr = element.getAttribute("data-fungies-items");
208
- if (itemsAttr) {
209
- try {
210
- items = JSON.parse(itemsAttr);
211
- } catch (_error) {
212
- log(`Invalid JSON in data-fungies-items: ${itemsAttr}`, "warning" /* WARNING */);
213
- }
214
- }
215
- let customFields = void 0;
216
- const customFieldsAttr = element.getAttribute("data-fungies-custom-fields");
217
- if (customFieldsAttr) {
218
- try {
219
- customFields = JSON.parse(customFieldsAttr);
220
- } catch (_error) {
221
- log(`Invalid JSON in data-fungies-custom-fields: ${customFieldsAttr}`, "warning" /* WARNING */);
222
- }
223
- }
224
- const checkoutOptions = {
225
- checkoutUrl,
226
- settings: {
227
- mode,
228
- ...frameTarget && { frameTarget }
229
- },
230
- ...discountCode && { discountCode },
231
- ...customerEmail && { customerEmail },
232
- ...quantity && { quantity },
233
- ...items && { items },
234
- ...customFields && { customFields }
235
- };
236
- element.addEventListener("click", (event) => {
237
- event.preventDefault();
238
- openCheckout(checkoutOptions);
239
- });
240
- element.setAttribute("data-fungies-initialized", "true");
241
- }
242
- const legacyFormatElements = document.querySelectorAll("[data-fungies-button]:not([data-fungies-initialized])");
243
- for (const element of legacyFormatElements) {
244
- const buttonUrl = element.getAttribute("data-fungies-button");
245
- if (!buttonUrl) {
246
- log("Element has data-fungies-button attribute but no value", "warning" /* WARNING */);
247
- continue;
248
- }
249
- try {
250
- const url = new URL(buttonUrl);
251
- const pathParts = url.pathname.split("/");
252
- const checkoutElementIndex = pathParts.indexOf("checkout-element");
253
- const overlayIndex = pathParts.indexOf("overlay");
254
- if (checkoutElementIndex === -1 && overlayIndex === -1) {
255
- log(`Invalid URL in data-fungies-button: ${buttonUrl}`, "warning" /* WARNING */);
256
- continue;
257
- }
258
- const mode = "overlay";
259
- const checkoutOptions = {
260
- checkoutUrl: buttonUrl,
261
- settings: {
262
- mode
263
- }
264
- };
265
- element.addEventListener("click", (event) => {
266
- event.preventDefault();
267
- openCheckout(checkoutOptions);
268
- });
269
- element.setAttribute("data-fungies-initialized", "true");
270
- } catch (error) {
271
- log(error, "error" /* ERROR */);
272
- }
273
- }
274
- };
275
- var initializeDomSupport = () => {
276
- log("Initializing DOM support");
277
- if (document.readyState !== "loading") {
278
- scanForCheckoutElements();
279
- } else {
280
- document.addEventListener("DOMContentLoaded", scanForCheckoutElements);
281
- }
282
- const observer = new MutationObserver((mutations) => {
283
- let shouldScan = false;
284
- for (const mutation of mutations) {
285
- if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
286
- for (const node of mutation.addedNodes) {
287
- if (node.nodeType === Node.ELEMENT_NODE) {
288
- const element = node;
289
- if (element.querySelector(
290
- "[data-fungies-checkout-url]:not([data-fungies-initialized]), [data-fungies-button]:not([data-fungies-initialized])"
291
- )) {
292
- shouldScan = true;
293
- break;
294
- }
295
- }
296
- }
297
- }
298
- }
299
- if (shouldScan) {
300
- scanForCheckoutElements();
301
- }
302
- });
303
- observer.observe(document.body, {
304
- childList: true,
305
- subtree: true
306
- });
307
- };
308
-
309
- // src/helpers/events.ts
310
- var _messageListener = (message) => {
311
- const { data } = message;
312
- switch (typeof data === "string" ? data : "") {
313
- case CHECKOUT_EVENTS.CHECKOUT_CLOSE:
314
- closeCheckoutIFrame();
315
- break;
316
- }
317
- };
318
- function listen() {
319
- if (typeof window !== "undefined") {
320
- window.addEventListener("message", _messageListener, false);
321
- }
322
- }
323
-
324
- // src/lib/state.ts
325
- var createInitialState = () => ({
326
- completedSetup: false,
327
- options: null
328
- });
329
- var updateState = (currentState, updates) => ({
330
- ...currentState,
331
- ...updates
332
- });
333
-
334
- // src/lib/fungies.ts
335
- var initialize = (options, currentState = createInitialState()) => {
336
- if (!currentState.completedSetup) {
337
- listen();
338
- if (options.enableDataAttributes !== false) {
339
- initializeDomSupport();
340
- }
341
- updateState(currentState, {
342
- completedSetup: true,
343
- options
344
- });
345
- } else {
346
- log("Cannot call Fungies.Initialize() more than once per page, the call was ignored.", "warning" /* WARNING */);
347
- }
348
- };
349
- var createFungies = () => ({
350
- Checkout: {
351
- open: openCheckout,
352
- close: closeCheckout
353
- },
354
- Initialize: initialize,
355
- ScanDOM: scanForCheckoutElements
356
- });
357
-
358
- // src/index.ts
359
- var Fungies = createFungies();
360
- if (typeof window !== "undefined") {
361
- window.Fungies = Fungies;
362
- }
363
- if (typeof document !== "undefined") {
364
- const currentScript = document.currentScript;
365
- if (currentScript?.hasAttribute("data-auto-init")) {
366
- document.addEventListener("DOMContentLoaded", async () => {
367
- Fungies.Initialize({
368
- enableDataAttributes: true
369
- });
370
- });
371
- }
372
- }
373
- export {
374
- Fungies
375
- };
1
+ var e=Object.defineProperty,t=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,o=(t,n,i)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[n]=i,a=(e,a)=>{for(var r in a||(a={}))n.call(a,r)&&o(e,r,a[r]);if(t)for(var r of t(a))i.call(a,r)&&o(e,r,a[r]);return e},r=(e,o)=>{var a={};for(var r in e)n.call(e,r)&&o.indexOf(r)<0&&(a[r]=e[r]);if(null!=e&&t)for(var r of t(e))o.indexOf(r)<0&&i.call(e,r)&&(a[r]=e[r]);return a},d=(e,t="log",n=!1,i={isEnabled:!0})=>{if(!i.isEnabled)return;window.console.debug=window.console.debug||window.console.log;const o=`[Fungies Debug]${e}`;"log"===t?console.debug(o):"warning"===t&&console.warn(o),n&&console.warn(e)};function s(e,t){const n=document.getElementsByClassName(e);for(let e=0;e<n.length;e++){const i=n[e];if("function"!=typeof t)throw new Error("each(className, function() {... requires the callback argument to be of type Function");t(i)}}function l(){s("fungies-loader",(e=>{var t;null==(t=null==e?void 0:e.parentNode)||t.removeChild(e)}))}function c(e){const t=e.getAttribute("data-fungies-checkout-url");t||d("Element has data-fungies-checkout-url attribute but no value","warning");const n=e.getAttribute("data-fungies-mode"),i="embed"===n||"overlay"===n?n:"overlay",o=e.getAttribute("data-fungies-frame-target")||void 0,r=e.getAttribute("data-fungies-discount-code")||void 0,s=e.getAttribute("data-fungies-customer-email")||void 0,l=e.getAttribute("data-fungies-quantity"),c=l?Number.parseInt(l,10):void 0;let u;const m=e.getAttribute("data-fungies-items");if(m)try{u=JSON.parse(m)}catch(e){d(`Invalid JSON in data-fungies-items: ${m}`,"warning")}let g;const p=e.getAttribute("data-fungies-custom-fields");if(p)try{g=JSON.parse(p)}catch(e){d(`Invalid JSON in data-fungies-custom-fields: ${p}`,"warning")}return a(a(a(a(a({checkoutUrl:t,settings:a({mode:i},o&&{frameTarget:o})},r&&{discountCode:r}),s&&{customerEmail:s}),c&&{quantity:c}),u&&{items:u}),g&&{customFields:g})}var u="closeWindow",m="embed";var g=(e,t,n)=>{const i=new URL(t);var o;return i.searchParams.append("fngs-checkout-payload",(o=JSON.stringify(e),encodeURIComponent(encodeURIComponent(o)))),i.searchParams.append("fngs-display-mode",n),i.toString()},p=()=>{d("Checkout frame/window has been closed."),l(),s("fungies-frame",(e=>{var t;null==(t=e.parentNode)||t.removeChild(e)})),void 0===window.FungiesWindow||window.FungiesWindow.closed||window.FungiesWindow.close()},f=(e,t,n)=>{var i;const o=((e,t)=>{var n=e,{checkoutUrl:i}=n,o=r(n,["checkoutUrl"]);return g(o,i,t)})(e,t.mode);if(n||function(){l();const e=document.createElement("style");e.type="text/css",e.innerHTML="\t\t\t\t@-webkit-keyframes rotate {\t\t\t\t\t0% {\t\t\t\t\t\t-webkit-transform: rotate(45deg);\t\t\t\t\t}\t\t\t\t\t100% {\t\t\t\t\t\t-webkit-transform: rotate(405deg);\t\t\t\t\t}\t\t\t\t}\t\t\t\t@keyframes rotate {\t\t\t\t\tfrom {\t\t\t\t\t\ttransform: rotate(45deg);\t\t\t\t\t}\t\t\t\t\tto {\t\t\t\t\t\ttransform: rotate(405deg);\t\t\t\t\t}\t\t\t\t}";const t=document.getElementsByTagName("head")[0];t&&t.appendChild(e);const n=document.createElement("div");n.setAttribute("style","z-index:99998; display: block; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; right: 0px; bottom: 0px; margin: 0px; padding: 0px; background: rgba(0,0,0,0.38);"),n.setAttribute("class","fungies-loader");const i=document.createElement("main");i.setAttribute("style","align-items: center;display: flex;flex-direction: column;justify-content: center;left: 50%;margin: 0.5rem 0;position: absolute;text-align: center;top: 50%;transform: translate(-50%, -50%);width: 90%;");const o=document.createElement("div");o.setAttribute("style","border: 4px solid #f3f3f3;border-radius: 50%;border-top: 4px solid #ccc;width: 34px;height: 34px;-webkit-animation: rotate 1s ease-in-out infinite forwards;animation: rotate 1s ease-in-out infinite forwards;"),i.appendChild(o),n.appendChild(i);const a=()=>{const e=document.getElementsByTagName("body")[0];e&&e.appendChild(n)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",a):a()}(),window.FungiesFrame=document.createElement("iframe"),window.FungiesFrame.className="fungies-frame",window.FungiesFrame.name="fungies_frame",window.FungiesFrame.frameBorder="0",window.FungiesFrame.allowTransparency="true",window.FungiesFrame.allow="payment",n){window.FungiesFrame.classList.add("fungies-frame-embed"),window.FungiesFrame.setAttribute("style","width: 100%; height: 100%;");const e=document.createElement("style");e.type="text/css",e.innerHTML=".fungies-frame-embed::-webkit-scrollbar { display: none !important; }",null==(i=null==document?void 0:document.getElementsByTagName("head")[0])||i.appendChild(e)}else window.FungiesFrame.classList.add("fungies-frame-overlay");if(n||(!function(){let e=!1;var t;return t=navigator.userAgent||navigator.vendor,(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(t.substr(0,4)))&&(e=!0),e}()?window.FungiesFrame.setAttribute("style","z-index: 2147483647; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: auto; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;"):window.FungiesFrame.setAttribute("style","z-index: 2147483647; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: scroll; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;")),window.FungiesFrame.src=o,(null==t?void 0:t.frameTarget)&&n){const e=document.getElementById(t.frameTarget);e&&e.appendChild(window.FungiesFrame)}else{const e=document.getElementsByTagName("body")[0];e&&e.appendChild(window.FungiesFrame)}},w=e=>{var t=e,{settings:n}=t,i=r(t,["settings"]);p();const o=()=>{d("Checkout.open() called"),f(i,n,(null==n?void 0:n.mode)===m)};"loading"!==document.readyState?o():document.addEventListener("DOMContentLoaded",o)},b=()=>{d("Scanning for checkout elements");const e=document.querySelectorAll("[data-fungies-checkout-url]:not([data-fungies-initialized])");for(const t of e){const e=c(t);t.addEventListener("click",(t=>{t.preventDefault(),w(e)})),t.setAttribute("data-fungies-initialized","true")}const t=document.querySelectorAll("[data-fungies-button]:not([data-fungies-initialized])");for(const e of t){const t=e.getAttribute("data-fungies-button");if(t)try{const n=new URL(t).pathname.split("/"),i=n.indexOf("checkout-element"),o=n.indexOf("overlay");if(-1===i&&-1===o){d(`Invalid URL in data-fungies-button: ${t}`,"warning");continue}const a={checkoutUrl:t,settings:{mode:"overlay"}};e.addEventListener("click",(e=>{e.preventDefault(),w(a)})),e.setAttribute("data-fungies-initialized","true")}catch(e){d(e,"error")}else d("Element has data-fungies-button attribute but no value","warning")}},h=e=>{const{data:t}=e;if(("string"==typeof t?t:"")===u)p()};var v={Checkout:{open:w,close:()=>{p()}},Initialize:(e,t={completedSetup:!1,options:null})=>{t.completedSetup?d("Cannot call Fungies.Initialize() more than once per page, the call was ignored.","warning"):("undefined"!=typeof window&&window.addEventListener("message",h,!1),!1!==e.enableDataAttributes&&(d("Initializing DOM support"),"loading"!==document.readyState?b():document.addEventListener("DOMContentLoaded",b),new MutationObserver((e=>{let t=!1;for(const n of e)if("childList"===n.type&&n.addedNodes.length>0)for(const e of n.addedNodes)if(e.nodeType===Node.ELEMENT_NODE&&e.querySelector("[data-fungies-checkout-url]:not([data-fungies-initialized]), [data-fungies-button]:not([data-fungies-initialized])")){t=!0;break}t&&b()})).observe(document.body,{childList:!0,subtree:!0})),((e,t)=>{a(a({},e),t)})(t,{completedSetup:!0,options:e}))},ScanDOM:b};if("undefined"!=typeof window&&(window.Fungies=v),"undefined"!=typeof document){const e=document.currentScript;if((null==e?void 0:e.hasAttribute("data-auto-init"))&&(v.Initialize({enableDataAttributes:!0}),null==e?void 0:e.hasAttribute("data-auto-display-checkout"))){const t=c(e);v.Checkout.open(t)}}export{v as Fungies};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungies/fungies-js",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -13,14 +13,13 @@
13
13
  "devDependencies": {
14
14
  "@biomejs/biome": "1.9.4",
15
15
  "@changesets/cli": "^2.28.1",
16
- "@commitlint/cli": "^19.7.1",
17
- "@commitlint/config-conventional": "^19.7.1",
18
16
  "husky": "^9.1.7",
19
17
  "tsup": "^8.4.0",
20
18
  "typescript": "^5.7.3"
21
19
  },
22
20
  "scripts": {
23
- "build": "tsup src/index.ts --format cjs,esm --dts",
21
+ "build": "rm -rf dist/ && tsup",
22
+ "dev:local": "tsup src/index.ts --format cjs,esm --dts --watch",
24
23
  "release": "pnpm run build && changeset publish",
25
24
  "format": "biome format --write",
26
25
  "lint": "biome check"
package/tsup.config.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { defineConfig, Options } from "tsup";
2
+
3
+ export const options: Options[] = [
4
+ {
5
+ entry: ["src/index.ts"],
6
+ format: ["esm", "iife"],
7
+ dts: true,
8
+ minify: "terser",
9
+ },
10
+ ];
11
+
12
+ export default defineConfig(options);
package/dist/index.js DELETED
@@ -1,402 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- Fungies: () => Fungies
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
-
27
- // src/constants/checkout.ts
28
- var CHECKOUT_FRAME_CLOSED = "Checkout frame/window has been closed.";
29
- var CHECKOUT_EVENTS = {
30
- CHECKOUT_CLOSE: "closeWindow"
31
- };
32
- var CHECKOUT_MODE = {
33
- EMBED: "embed",
34
- OVERLAY: "overlay"
35
- };
36
-
37
- // src/lib/logger.ts
38
- var createLoggerConfig = () => ({
39
- isEnabled: true
40
- });
41
- var log = (message, type = "log" /* LOG */, alwaysShow = false, config = createLoggerConfig()) => {
42
- if (!config.isEnabled) return;
43
- window.console.debug = window.console.debug || window.console.log;
44
- const debugMessage = `[Fungies Debug]${message}`;
45
- if (type === "log" /* LOG */) {
46
- console.debug(debugMessage);
47
- } else if (type === "warning" /* WARNING */) {
48
- console.warn(debugMessage);
49
- }
50
- if (alwaysShow) {
51
- console.warn(message);
52
- }
53
- };
54
-
55
- // src/utils/device.ts
56
- function isMobile() {
57
- let check = false;
58
- ((a) => {
59
- if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
60
- a
61
- ) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(
62
- a.substr(0, 4)
63
- ))
64
- check = true;
65
- })(navigator.userAgent || navigator.vendor);
66
- return check;
67
- }
68
-
69
- // src/utils/html.ts
70
- function each(className, callback) {
71
- const elements = document.getElementsByClassName(className);
72
- for (let i = 0; i < elements.length; i++) {
73
- const thisElement = elements[i];
74
- if (typeof callback === "function") {
75
- callback(thisElement);
76
- } else {
77
- throw new Error("each(className, function() {... requires the callback argument to be of type Function");
78
- }
79
- }
80
- }
81
-
82
- // src/utils/url.ts
83
- var encodeForTransport = (jsonString) => {
84
- return encodeURIComponent(encodeURIComponent(jsonString));
85
- };
86
- var getCheckoutFrontEndURL = (checkoutInputAttributes, checkoutUrl, mode) => {
87
- const url = new URL(checkoutUrl);
88
- url.searchParams.append("fngs-checkout-payload", encodeForTransport(JSON.stringify(checkoutInputAttributes)));
89
- url.searchParams.append("fngs-display-mode", mode);
90
- return url.toString();
91
- };
92
- var getCheckoutUrl = ({ checkoutUrl, ...restProps }, mode) => {
93
- return getCheckoutFrontEndURL(restProps, checkoutUrl, mode);
94
- };
95
-
96
- // src/helpers/checkout.ts
97
- function showLoading() {
98
- hideLoading();
99
- const keyFrameStyle = document.createElement("style");
100
- keyFrameStyle.type = "text/css";
101
- keyFrameStyle.innerHTML = // eslint-disable-next-line no-multi-str
102
- " @-webkit-keyframes rotate { 0% { -webkit-transform: rotate(45deg); } 100% { -webkit-transform: rotate(405deg); } } @keyframes rotate { from { transform: rotate(45deg); } to { transform: rotate(405deg); } }";
103
- const head = document.getElementsByTagName("head")[0];
104
- if (head) {
105
- head.appendChild(keyFrameStyle);
106
- }
107
- const htmlLoader = document.createElement("div");
108
- htmlLoader.setAttribute(
109
- "style",
110
- "z-index:99998; display: block; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; right: 0px; bottom: 0px; margin: 0px; padding: 0px; background: rgba(0,0,0,0.38);"
111
- );
112
- htmlLoader.setAttribute("class", "fungies-loader" /* FUNGIES_LOADER */);
113
- const mainSpinnerWrapper = document.createElement("main");
114
- const htmlLoaderIconWrapper = "align-items: center;display: flex;flex-direction: column;justify-content: center;left: 50%;margin: 0.5rem 0;position: absolute;text-align: center;top: 50%;transform: translate(-50%, -50%);width: 90%;";
115
- mainSpinnerWrapper.setAttribute("style", htmlLoaderIconWrapper);
116
- const spinner = document.createElement("div");
117
- const htmlLoaderIcon = "border: 4px solid #f3f3f3;border-radius: 50%;border-top: 4px solid #ccc;width: 34px;height: 34px;-webkit-animation: rotate 1s ease-in-out infinite forwards;animation: rotate 1s ease-in-out infinite forwards;";
118
- spinner.setAttribute("style", htmlLoaderIcon);
119
- mainSpinnerWrapper.appendChild(spinner);
120
- htmlLoader.appendChild(mainSpinnerWrapper);
121
- const appendLoader = () => {
122
- const body = document.getElementsByTagName("body")[0];
123
- if (body) {
124
- body.appendChild(htmlLoader);
125
- }
126
- };
127
- if (document.readyState === "loading") {
128
- document.addEventListener("DOMContentLoaded", appendLoader);
129
- } else {
130
- appendLoader();
131
- }
132
- }
133
- function hideLoading() {
134
- each("fungies-loader" /* FUNGIES_LOADER */, (loader) => {
135
- loader?.parentNode?.removeChild(loader);
136
- });
137
- }
138
-
139
- // src/helpers/iframe.ts
140
- var closeCheckoutIFrame = () => {
141
- log(CHECKOUT_FRAME_CLOSED);
142
- hideLoading();
143
- each("fungies-frame" /* FUNGIES_FRAME */, (element) => {
144
- element.parentNode?.removeChild(element);
145
- });
146
- if (typeof window.FungiesWindow !== "undefined" && !window.FungiesWindow.closed) {
147
- window.FungiesWindow.close();
148
- }
149
- };
150
- var renderCheckoutFrame = (checkoutProps, settings, embed) => {
151
- const checkoutUrl = getCheckoutUrl(checkoutProps, settings.mode);
152
- if (!embed) {
153
- showLoading();
154
- }
155
- window.FungiesFrame = document.createElement("iframe");
156
- window.FungiesFrame.className = "fungies-frame" /* FUNGIES_FRAME */;
157
- window.FungiesFrame.name = "fungies_frame";
158
- window.FungiesFrame.frameBorder = "0";
159
- window.FungiesFrame.allowTransparency = "true";
160
- window.FungiesFrame.allow = "payment";
161
- if (embed) {
162
- window.FungiesFrame.classList.add("fungies-frame-embed" /* FUNGIES_FRAME_EMBED */);
163
- window.FungiesFrame.setAttribute("style", "width: 100%; height: 100%;");
164
- const styleElement = document.createElement("style");
165
- styleElement.type = "text/css";
166
- styleElement.innerHTML = `.${"fungies-frame-embed" /* FUNGIES_FRAME_EMBED */}::-webkit-scrollbar { display: none !important; }`;
167
- document?.getElementsByTagName("head")[0]?.appendChild(styleElement);
168
- } else {
169
- window.FungiesFrame.classList.add("fungies-frame-overlay" /* FUNGIES_FRAME_OVERLAY */);
170
- }
171
- if (!embed) {
172
- if (!isMobile()) {
173
- window.FungiesFrame.setAttribute(
174
- "style",
175
- "z-index: 2147483647; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: auto; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;"
176
- );
177
- } else {
178
- window.FungiesFrame.setAttribute(
179
- "style",
180
- "z-index: 2147483647; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: scroll; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;"
181
- );
182
- }
183
- }
184
- window.FungiesFrame.src = checkoutUrl;
185
- if (settings?.frameTarget && embed) {
186
- const target = document.getElementById(settings.frameTarget);
187
- if (target) {
188
- target.appendChild(window.FungiesFrame);
189
- }
190
- } else {
191
- const body = document.getElementsByTagName("body")[0];
192
- if (body) {
193
- body.appendChild(window.FungiesFrame);
194
- }
195
- }
196
- };
197
-
198
- // src/lib/checkout.ts
199
- var openCheckout = ({ settings, ...checkoutInputAttributes }) => {
200
- closeCheckoutIFrame();
201
- const renderCheckoutWithSettings = () => {
202
- log("Checkout.open() called");
203
- renderCheckoutFrame(checkoutInputAttributes, settings, settings?.mode === CHECKOUT_MODE.EMBED);
204
- };
205
- if (document.readyState !== "loading") {
206
- renderCheckoutWithSettings();
207
- } else {
208
- document.addEventListener("DOMContentLoaded", renderCheckoutWithSettings);
209
- }
210
- };
211
- var closeCheckout = () => {
212
- closeCheckoutIFrame();
213
- };
214
-
215
- // src/helpers/dom.ts
216
- var scanForCheckoutElements = () => {
217
- log("Scanning for checkout elements");
218
- const newFormatElements = document.querySelectorAll("[data-fungies-checkout-url]:not([data-fungies-initialized])");
219
- for (const element of newFormatElements) {
220
- const checkoutUrl = element.getAttribute("data-fungies-checkout-url");
221
- if (!checkoutUrl) {
222
- log("Element has data-fungies-checkout-url attribute but no value", "warning" /* WARNING */);
223
- continue;
224
- }
225
- const modeAttr = element.getAttribute("data-fungies-mode");
226
- const mode = modeAttr === "embed" || modeAttr === "overlay" ? modeAttr : "overlay";
227
- const frameTarget = element.getAttribute("data-fungies-frame-target") || void 0;
228
- const discountCode = element.getAttribute("data-fungies-discount-code") || void 0;
229
- const customerEmail = element.getAttribute("data-fungies-customer-email") || void 0;
230
- const quantityAttr = element.getAttribute("data-fungies-quantity");
231
- const quantity = quantityAttr ? Number.parseInt(quantityAttr, 10) : void 0;
232
- let items = void 0;
233
- const itemsAttr = element.getAttribute("data-fungies-items");
234
- if (itemsAttr) {
235
- try {
236
- items = JSON.parse(itemsAttr);
237
- } catch (_error) {
238
- log(`Invalid JSON in data-fungies-items: ${itemsAttr}`, "warning" /* WARNING */);
239
- }
240
- }
241
- let customFields = void 0;
242
- const customFieldsAttr = element.getAttribute("data-fungies-custom-fields");
243
- if (customFieldsAttr) {
244
- try {
245
- customFields = JSON.parse(customFieldsAttr);
246
- } catch (_error) {
247
- log(`Invalid JSON in data-fungies-custom-fields: ${customFieldsAttr}`, "warning" /* WARNING */);
248
- }
249
- }
250
- const checkoutOptions = {
251
- checkoutUrl,
252
- settings: {
253
- mode,
254
- ...frameTarget && { frameTarget }
255
- },
256
- ...discountCode && { discountCode },
257
- ...customerEmail && { customerEmail },
258
- ...quantity && { quantity },
259
- ...items && { items },
260
- ...customFields && { customFields }
261
- };
262
- element.addEventListener("click", (event) => {
263
- event.preventDefault();
264
- openCheckout(checkoutOptions);
265
- });
266
- element.setAttribute("data-fungies-initialized", "true");
267
- }
268
- const legacyFormatElements = document.querySelectorAll("[data-fungies-button]:not([data-fungies-initialized])");
269
- for (const element of legacyFormatElements) {
270
- const buttonUrl = element.getAttribute("data-fungies-button");
271
- if (!buttonUrl) {
272
- log("Element has data-fungies-button attribute but no value", "warning" /* WARNING */);
273
- continue;
274
- }
275
- try {
276
- const url = new URL(buttonUrl);
277
- const pathParts = url.pathname.split("/");
278
- const checkoutElementIndex = pathParts.indexOf("checkout-element");
279
- const overlayIndex = pathParts.indexOf("overlay");
280
- if (checkoutElementIndex === -1 && overlayIndex === -1) {
281
- log(`Invalid URL in data-fungies-button: ${buttonUrl}`, "warning" /* WARNING */);
282
- continue;
283
- }
284
- const mode = "overlay";
285
- const checkoutOptions = {
286
- checkoutUrl: buttonUrl,
287
- settings: {
288
- mode
289
- }
290
- };
291
- element.addEventListener("click", (event) => {
292
- event.preventDefault();
293
- openCheckout(checkoutOptions);
294
- });
295
- element.setAttribute("data-fungies-initialized", "true");
296
- } catch (error) {
297
- log(error, "error" /* ERROR */);
298
- }
299
- }
300
- };
301
- var initializeDomSupport = () => {
302
- log("Initializing DOM support");
303
- if (document.readyState !== "loading") {
304
- scanForCheckoutElements();
305
- } else {
306
- document.addEventListener("DOMContentLoaded", scanForCheckoutElements);
307
- }
308
- const observer = new MutationObserver((mutations) => {
309
- let shouldScan = false;
310
- for (const mutation of mutations) {
311
- if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
312
- for (const node of mutation.addedNodes) {
313
- if (node.nodeType === Node.ELEMENT_NODE) {
314
- const element = node;
315
- if (element.querySelector(
316
- "[data-fungies-checkout-url]:not([data-fungies-initialized]), [data-fungies-button]:not([data-fungies-initialized])"
317
- )) {
318
- shouldScan = true;
319
- break;
320
- }
321
- }
322
- }
323
- }
324
- }
325
- if (shouldScan) {
326
- scanForCheckoutElements();
327
- }
328
- });
329
- observer.observe(document.body, {
330
- childList: true,
331
- subtree: true
332
- });
333
- };
334
-
335
- // src/helpers/events.ts
336
- var _messageListener = (message) => {
337
- const { data } = message;
338
- switch (typeof data === "string" ? data : "") {
339
- case CHECKOUT_EVENTS.CHECKOUT_CLOSE:
340
- closeCheckoutIFrame();
341
- break;
342
- }
343
- };
344
- function listen() {
345
- if (typeof window !== "undefined") {
346
- window.addEventListener("message", _messageListener, false);
347
- }
348
- }
349
-
350
- // src/lib/state.ts
351
- var createInitialState = () => ({
352
- completedSetup: false,
353
- options: null
354
- });
355
- var updateState = (currentState, updates) => ({
356
- ...currentState,
357
- ...updates
358
- });
359
-
360
- // src/lib/fungies.ts
361
- var initialize = (options, currentState = createInitialState()) => {
362
- if (!currentState.completedSetup) {
363
- listen();
364
- if (options.enableDataAttributes !== false) {
365
- initializeDomSupport();
366
- }
367
- updateState(currentState, {
368
- completedSetup: true,
369
- options
370
- });
371
- } else {
372
- log("Cannot call Fungies.Initialize() more than once per page, the call was ignored.", "warning" /* WARNING */);
373
- }
374
- };
375
- var createFungies = () => ({
376
- Checkout: {
377
- open: openCheckout,
378
- close: closeCheckout
379
- },
380
- Initialize: initialize,
381
- ScanDOM: scanForCheckoutElements
382
- });
383
-
384
- // src/index.ts
385
- var Fungies = createFungies();
386
- if (typeof window !== "undefined") {
387
- window.Fungies = Fungies;
388
- }
389
- if (typeof document !== "undefined") {
390
- const currentScript = document.currentScript;
391
- if (currentScript?.hasAttribute("data-auto-init")) {
392
- document.addEventListener("DOMContentLoaded", async () => {
393
- Fungies.Initialize({
394
- enableDataAttributes: true
395
- });
396
- });
397
- }
398
- }
399
- // Annotate the CommonJS export names for ESM import in node:
400
- 0 && (module.exports = {
401
- Fungies
402
- });