@fungies/fungies-js 0.0.3 → 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.
- package/CHANGELOG.md +10 -1
- package/README.md +21 -79
- package/dist/index.global.js +1 -0
- package/dist/index.mjs +1 -401
- package/package.json +3 -2
- package/tsup.config.ts +12 -0
- package/dist/index.js +0 -428
package/CHANGELOG.md
CHANGED
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="
|
|
59
|
-
data-fungies-frame-target="target-element-id"
|
|
53
|
+
data-fungies-mode="overlay"
|
|
60
54
|
>
|
|
61
|
-
Open
|
|
55
|
+
Open Checkout
|
|
62
56
|
</button>
|
|
63
57
|
|
|
64
|
-
<!--
|
|
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,401 +1 @@
|
|
|
1
|
-
// src/lib/logger.ts
|
|
2
|
-
var createLoggerConfig = () => ({
|
|
3
|
-
isEnabled: true
|
|
4
|
-
});
|
|
5
|
-
var log = (message, type = "log" /* LOG */, alwaysShow = false, config = createLoggerConfig()) => {
|
|
6
|
-
if (!config.isEnabled) return;
|
|
7
|
-
window.console.debug = window.console.debug || window.console.log;
|
|
8
|
-
const debugMessage = `[Fungies Debug]${message}`;
|
|
9
|
-
if (type === "log" /* LOG */) {
|
|
10
|
-
console.debug(debugMessage);
|
|
11
|
-
} else if (type === "warning" /* WARNING */) {
|
|
12
|
-
console.warn(debugMessage);
|
|
13
|
-
}
|
|
14
|
-
if (alwaysShow) {
|
|
15
|
-
console.warn(message);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// src/utils/html.ts
|
|
20
|
-
function each(className, callback) {
|
|
21
|
-
const elements = document.getElementsByClassName(className);
|
|
22
|
-
for (let i = 0; i < elements.length; i++) {
|
|
23
|
-
const thisElement = elements[i];
|
|
24
|
-
if (typeof callback === "function") {
|
|
25
|
-
callback(thisElement);
|
|
26
|
-
} else {
|
|
27
|
-
throw new Error("each(className, function() {... requires the callback argument to be of type Function");
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// src/helpers/checkout.ts
|
|
33
|
-
function showLoading() {
|
|
34
|
-
hideLoading();
|
|
35
|
-
const keyFrameStyle = document.createElement("style");
|
|
36
|
-
keyFrameStyle.type = "text/css";
|
|
37
|
-
keyFrameStyle.innerHTML = // eslint-disable-next-line no-multi-str
|
|
38
|
-
" @-webkit-keyframes rotate { 0% { -webkit-transform: rotate(45deg); } 100% { -webkit-transform: rotate(405deg); } } @keyframes rotate { from { transform: rotate(45deg); } to { transform: rotate(405deg); } }";
|
|
39
|
-
const head = document.getElementsByTagName("head")[0];
|
|
40
|
-
if (head) {
|
|
41
|
-
head.appendChild(keyFrameStyle);
|
|
42
|
-
}
|
|
43
|
-
const htmlLoader = document.createElement("div");
|
|
44
|
-
htmlLoader.setAttribute(
|
|
45
|
-
"style",
|
|
46
|
-
"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);"
|
|
47
|
-
);
|
|
48
|
-
htmlLoader.setAttribute("class", "fungies-loader" /* FUNGIES_LOADER */);
|
|
49
|
-
const mainSpinnerWrapper = document.createElement("main");
|
|
50
|
-
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%;";
|
|
51
|
-
mainSpinnerWrapper.setAttribute("style", htmlLoaderIconWrapper);
|
|
52
|
-
const spinner = document.createElement("div");
|
|
53
|
-
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;";
|
|
54
|
-
spinner.setAttribute("style", htmlLoaderIcon);
|
|
55
|
-
mainSpinnerWrapper.appendChild(spinner);
|
|
56
|
-
htmlLoader.appendChild(mainSpinnerWrapper);
|
|
57
|
-
const appendLoader = () => {
|
|
58
|
-
const body = document.getElementsByTagName("body")[0];
|
|
59
|
-
if (body) {
|
|
60
|
-
body.appendChild(htmlLoader);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
if (document.readyState === "loading") {
|
|
64
|
-
document.addEventListener("DOMContentLoaded", appendLoader);
|
|
65
|
-
} else {
|
|
66
|
-
appendLoader();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function hideLoading() {
|
|
70
|
-
each("fungies-loader" /* FUNGIES_LOADER */, (loader) => {
|
|
71
|
-
loader?.parentNode?.removeChild(loader);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
function getCheckoutOptions(element) {
|
|
75
|
-
const checkoutUrl = element.getAttribute("data-fungies-checkout-url");
|
|
76
|
-
if (!checkoutUrl) {
|
|
77
|
-
log(
|
|
78
|
-
"Element has data-fungies-checkout-url attribute but no value",
|
|
79
|
-
"warning" /* WARNING */
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
const modeAttr = element.getAttribute("data-fungies-mode");
|
|
83
|
-
const mode = modeAttr === "embed" || modeAttr === "overlay" ? modeAttr : "overlay";
|
|
84
|
-
const frameTarget = element.getAttribute("data-fungies-frame-target") || void 0;
|
|
85
|
-
const discountCode = element.getAttribute("data-fungies-discount-code") || void 0;
|
|
86
|
-
const customerEmail = element.getAttribute("data-fungies-customer-email") || void 0;
|
|
87
|
-
const quantityAttr = element.getAttribute("data-fungies-quantity");
|
|
88
|
-
const quantity = quantityAttr ? Number.parseInt(quantityAttr, 10) : void 0;
|
|
89
|
-
let items = void 0;
|
|
90
|
-
const itemsAttr = element.getAttribute("data-fungies-items");
|
|
91
|
-
if (itemsAttr) {
|
|
92
|
-
try {
|
|
93
|
-
items = JSON.parse(itemsAttr);
|
|
94
|
-
} catch (_error) {
|
|
95
|
-
log(
|
|
96
|
-
`Invalid JSON in data-fungies-items: ${itemsAttr}`,
|
|
97
|
-
"warning" /* WARNING */
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
let customFields = void 0;
|
|
102
|
-
const customFieldsAttr = element.getAttribute("data-fungies-custom-fields");
|
|
103
|
-
if (customFieldsAttr) {
|
|
104
|
-
try {
|
|
105
|
-
customFields = JSON.parse(customFieldsAttr);
|
|
106
|
-
} catch (_error) {
|
|
107
|
-
log(
|
|
108
|
-
`Invalid JSON in data-fungies-custom-fields: ${customFieldsAttr}`,
|
|
109
|
-
"warning" /* WARNING */
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const checkoutOptions = {
|
|
114
|
-
checkoutUrl,
|
|
115
|
-
settings: {
|
|
116
|
-
mode,
|
|
117
|
-
...frameTarget && { frameTarget }
|
|
118
|
-
},
|
|
119
|
-
...discountCode && { discountCode },
|
|
120
|
-
...customerEmail && { customerEmail },
|
|
121
|
-
...quantity && { quantity },
|
|
122
|
-
...items && { items },
|
|
123
|
-
...customFields && { customFields }
|
|
124
|
-
};
|
|
125
|
-
return checkoutOptions;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// src/constants/checkout.ts
|
|
129
|
-
var CHECKOUT_FRAME_CLOSED = "Checkout frame/window has been closed.";
|
|
130
|
-
var CHECKOUT_EVENTS = {
|
|
131
|
-
CHECKOUT_CLOSE: "closeWindow"
|
|
132
|
-
};
|
|
133
|
-
var CHECKOUT_MODE = {
|
|
134
|
-
EMBED: "embed",
|
|
135
|
-
OVERLAY: "overlay"
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// src/utils/device.ts
|
|
139
|
-
function isMobile() {
|
|
140
|
-
let check = false;
|
|
141
|
-
((a) => {
|
|
142
|
-
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(
|
|
143
|
-
a
|
|
144
|
-
) || /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(
|
|
145
|
-
a.substr(0, 4)
|
|
146
|
-
))
|
|
147
|
-
check = true;
|
|
148
|
-
})(navigator.userAgent || navigator.vendor);
|
|
149
|
-
return check;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// src/utils/url.ts
|
|
153
|
-
var encodeForTransport = (jsonString) => {
|
|
154
|
-
return encodeURIComponent(encodeURIComponent(jsonString));
|
|
155
|
-
};
|
|
156
|
-
var getCheckoutFrontEndURL = (checkoutInputAttributes, checkoutUrl, mode) => {
|
|
157
|
-
const url = new URL(checkoutUrl);
|
|
158
|
-
url.searchParams.append("fngs-checkout-payload", encodeForTransport(JSON.stringify(checkoutInputAttributes)));
|
|
159
|
-
url.searchParams.append("fngs-display-mode", mode);
|
|
160
|
-
return url.toString();
|
|
161
|
-
};
|
|
162
|
-
var getCheckoutUrl = ({ checkoutUrl, ...restProps }, mode) => {
|
|
163
|
-
return getCheckoutFrontEndURL(restProps, checkoutUrl, mode);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
// src/helpers/iframe.ts
|
|
167
|
-
var closeCheckoutIFrame = () => {
|
|
168
|
-
log(CHECKOUT_FRAME_CLOSED);
|
|
169
|
-
hideLoading();
|
|
170
|
-
each("fungies-frame" /* FUNGIES_FRAME */, (element) => {
|
|
171
|
-
element.parentNode?.removeChild(element);
|
|
172
|
-
});
|
|
173
|
-
if (typeof window.FungiesWindow !== "undefined" && !window.FungiesWindow.closed) {
|
|
174
|
-
window.FungiesWindow.close();
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
var renderCheckoutFrame = (checkoutProps, settings, embed) => {
|
|
178
|
-
const checkoutUrl = getCheckoutUrl(checkoutProps, settings.mode);
|
|
179
|
-
if (!embed) {
|
|
180
|
-
showLoading();
|
|
181
|
-
}
|
|
182
|
-
window.FungiesFrame = document.createElement("iframe");
|
|
183
|
-
window.FungiesFrame.className = "fungies-frame" /* FUNGIES_FRAME */;
|
|
184
|
-
window.FungiesFrame.name = "fungies_frame";
|
|
185
|
-
window.FungiesFrame.frameBorder = "0";
|
|
186
|
-
window.FungiesFrame.allowTransparency = "true";
|
|
187
|
-
window.FungiesFrame.allow = "payment";
|
|
188
|
-
if (embed) {
|
|
189
|
-
window.FungiesFrame.classList.add("fungies-frame-embed" /* FUNGIES_FRAME_EMBED */);
|
|
190
|
-
window.FungiesFrame.setAttribute("style", "width: 100%; height: 100%;");
|
|
191
|
-
const styleElement = document.createElement("style");
|
|
192
|
-
styleElement.type = "text/css";
|
|
193
|
-
styleElement.innerHTML = `.${"fungies-frame-embed" /* FUNGIES_FRAME_EMBED */}::-webkit-scrollbar { display: none !important; }`;
|
|
194
|
-
document?.getElementsByTagName("head")[0]?.appendChild(styleElement);
|
|
195
|
-
} else {
|
|
196
|
-
window.FungiesFrame.classList.add("fungies-frame-overlay" /* FUNGIES_FRAME_OVERLAY */);
|
|
197
|
-
}
|
|
198
|
-
if (!embed) {
|
|
199
|
-
if (!isMobile()) {
|
|
200
|
-
window.FungiesFrame.setAttribute(
|
|
201
|
-
"style",
|
|
202
|
-
"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%;"
|
|
203
|
-
);
|
|
204
|
-
} else {
|
|
205
|
-
window.FungiesFrame.setAttribute(
|
|
206
|
-
"style",
|
|
207
|
-
"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%;"
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
window.FungiesFrame.src = checkoutUrl;
|
|
212
|
-
if (settings?.frameTarget && embed) {
|
|
213
|
-
const target = document.getElementById(settings.frameTarget);
|
|
214
|
-
if (target) {
|
|
215
|
-
target.appendChild(window.FungiesFrame);
|
|
216
|
-
}
|
|
217
|
-
} else {
|
|
218
|
-
const body = document.getElementsByTagName("body")[0];
|
|
219
|
-
if (body) {
|
|
220
|
-
body.appendChild(window.FungiesFrame);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
// src/lib/checkout.ts
|
|
226
|
-
var openCheckout = ({ settings, ...checkoutInputAttributes }) => {
|
|
227
|
-
closeCheckoutIFrame();
|
|
228
|
-
const renderCheckoutWithSettings = () => {
|
|
229
|
-
log("Checkout.open() called");
|
|
230
|
-
renderCheckoutFrame(checkoutInputAttributes, settings, settings?.mode === CHECKOUT_MODE.EMBED);
|
|
231
|
-
};
|
|
232
|
-
if (document.readyState !== "loading") {
|
|
233
|
-
renderCheckoutWithSettings();
|
|
234
|
-
} else {
|
|
235
|
-
document.addEventListener("DOMContentLoaded", renderCheckoutWithSettings);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
var closeCheckout = () => {
|
|
239
|
-
closeCheckoutIFrame();
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
// src/helpers/dom.ts
|
|
243
|
-
var scanForCheckoutElements = () => {
|
|
244
|
-
log("Scanning for checkout elements");
|
|
245
|
-
const newFormatElements = document.querySelectorAll(
|
|
246
|
-
"[data-fungies-checkout-url]:not([data-fungies-initialized])"
|
|
247
|
-
);
|
|
248
|
-
for (const element of newFormatElements) {
|
|
249
|
-
const checkoutOptions = getCheckoutOptions(element);
|
|
250
|
-
element.addEventListener("click", (event) => {
|
|
251
|
-
event.preventDefault();
|
|
252
|
-
openCheckout(checkoutOptions);
|
|
253
|
-
});
|
|
254
|
-
element.setAttribute("data-fungies-initialized", "true");
|
|
255
|
-
}
|
|
256
|
-
const legacyFormatElements = document.querySelectorAll(
|
|
257
|
-
"[data-fungies-button]:not([data-fungies-initialized])"
|
|
258
|
-
);
|
|
259
|
-
for (const element of legacyFormatElements) {
|
|
260
|
-
const buttonUrl = element.getAttribute("data-fungies-button");
|
|
261
|
-
if (!buttonUrl) {
|
|
262
|
-
log(
|
|
263
|
-
"Element has data-fungies-button attribute but no value",
|
|
264
|
-
"warning" /* WARNING */
|
|
265
|
-
);
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
|
-
try {
|
|
269
|
-
const url = new URL(buttonUrl);
|
|
270
|
-
const pathParts = url.pathname.split("/");
|
|
271
|
-
const checkoutElementIndex = pathParts.indexOf("checkout-element");
|
|
272
|
-
const overlayIndex = pathParts.indexOf("overlay");
|
|
273
|
-
if (checkoutElementIndex === -1 && overlayIndex === -1) {
|
|
274
|
-
log(
|
|
275
|
-
`Invalid URL in data-fungies-button: ${buttonUrl}`,
|
|
276
|
-
"warning" /* WARNING */
|
|
277
|
-
);
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
const mode = "overlay";
|
|
281
|
-
const checkoutOptions = {
|
|
282
|
-
checkoutUrl: buttonUrl,
|
|
283
|
-
settings: {
|
|
284
|
-
mode
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
element.addEventListener("click", (event) => {
|
|
288
|
-
event.preventDefault();
|
|
289
|
-
openCheckout(checkoutOptions);
|
|
290
|
-
});
|
|
291
|
-
element.setAttribute("data-fungies-initialized", "true");
|
|
292
|
-
} catch (error) {
|
|
293
|
-
log(error, "error" /* ERROR */);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
var initializeDomSupport = () => {
|
|
298
|
-
log("Initializing DOM support");
|
|
299
|
-
if (document.readyState !== "loading") {
|
|
300
|
-
scanForCheckoutElements();
|
|
301
|
-
} else {
|
|
302
|
-
document.addEventListener("DOMContentLoaded", scanForCheckoutElements);
|
|
303
|
-
}
|
|
304
|
-
const observer = new MutationObserver((mutations) => {
|
|
305
|
-
let shouldScan = false;
|
|
306
|
-
for (const mutation of mutations) {
|
|
307
|
-
if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
|
|
308
|
-
for (const node of mutation.addedNodes) {
|
|
309
|
-
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
310
|
-
const element = node;
|
|
311
|
-
if (element.querySelector(
|
|
312
|
-
"[data-fungies-checkout-url]:not([data-fungies-initialized]), [data-fungies-button]:not([data-fungies-initialized])"
|
|
313
|
-
)) {
|
|
314
|
-
shouldScan = true;
|
|
315
|
-
break;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
if (shouldScan) {
|
|
322
|
-
scanForCheckoutElements();
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
observer.observe(document.body, {
|
|
326
|
-
childList: true,
|
|
327
|
-
subtree: true
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// src/helpers/events.ts
|
|
332
|
-
var _messageListener = (message) => {
|
|
333
|
-
const { data } = message;
|
|
334
|
-
switch (typeof data === "string" ? data : "") {
|
|
335
|
-
case CHECKOUT_EVENTS.CHECKOUT_CLOSE:
|
|
336
|
-
closeCheckoutIFrame();
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
function listen() {
|
|
341
|
-
if (typeof window !== "undefined") {
|
|
342
|
-
window.addEventListener("message", _messageListener, false);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// src/lib/state.ts
|
|
347
|
-
var createInitialState = () => ({
|
|
348
|
-
completedSetup: false,
|
|
349
|
-
options: null
|
|
350
|
-
});
|
|
351
|
-
var updateState = (currentState, updates) => ({
|
|
352
|
-
...currentState,
|
|
353
|
-
...updates
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
// src/lib/fungies.ts
|
|
357
|
-
var initialize = (options, currentState = createInitialState()) => {
|
|
358
|
-
if (!currentState.completedSetup) {
|
|
359
|
-
listen();
|
|
360
|
-
if (options.enableDataAttributes !== false) {
|
|
361
|
-
initializeDomSupport();
|
|
362
|
-
}
|
|
363
|
-
updateState(currentState, {
|
|
364
|
-
completedSetup: true,
|
|
365
|
-
options
|
|
366
|
-
});
|
|
367
|
-
} else {
|
|
368
|
-
log("Cannot call Fungies.Initialize() more than once per page, the call was ignored.", "warning" /* WARNING */);
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
var createFungies = () => ({
|
|
372
|
-
Checkout: {
|
|
373
|
-
open: openCheckout,
|
|
374
|
-
close: closeCheckout
|
|
375
|
-
},
|
|
376
|
-
Initialize: initialize,
|
|
377
|
-
ScanDOM: scanForCheckoutElements
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
// src/index.ts
|
|
381
|
-
var Fungies = createFungies();
|
|
382
|
-
if (typeof window !== "undefined") {
|
|
383
|
-
window.Fungies = Fungies;
|
|
384
|
-
}
|
|
385
|
-
if (typeof document !== "undefined") {
|
|
386
|
-
const currentScript = document.currentScript;
|
|
387
|
-
if (currentScript?.hasAttribute("data-auto-init")) {
|
|
388
|
-
document.addEventListener("DOMContentLoaded", async () => {
|
|
389
|
-
Fungies.Initialize({
|
|
390
|
-
enableDataAttributes: true
|
|
391
|
-
});
|
|
392
|
-
if (currentScript?.hasAttribute("data-auto-display-checkout")) {
|
|
393
|
-
const checkoutOptions = getCheckoutOptions(currentScript);
|
|
394
|
-
Fungies.Checkout.open(checkoutOptions);
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
export {
|
|
400
|
-
Fungies
|
|
401
|
-
};
|
|
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.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"typescript": "^5.7.3"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "
|
|
21
|
+
"build": "rm -rf dist/ && tsup",
|
|
22
|
+
"dev:local": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
22
23
|
"release": "pnpm run build && changeset publish",
|
|
23
24
|
"format": "biome format --write",
|
|
24
25
|
"lint": "biome check"
|
package/tsup.config.ts
ADDED
package/dist/index.js
DELETED
|
@@ -1,428 +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/lib/logger.ts
|
|
28
|
-
var createLoggerConfig = () => ({
|
|
29
|
-
isEnabled: true
|
|
30
|
-
});
|
|
31
|
-
var log = (message, type = "log" /* LOG */, alwaysShow = false, config = createLoggerConfig()) => {
|
|
32
|
-
if (!config.isEnabled) return;
|
|
33
|
-
window.console.debug = window.console.debug || window.console.log;
|
|
34
|
-
const debugMessage = `[Fungies Debug]${message}`;
|
|
35
|
-
if (type === "log" /* LOG */) {
|
|
36
|
-
console.debug(debugMessage);
|
|
37
|
-
} else if (type === "warning" /* WARNING */) {
|
|
38
|
-
console.warn(debugMessage);
|
|
39
|
-
}
|
|
40
|
-
if (alwaysShow) {
|
|
41
|
-
console.warn(message);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/utils/html.ts
|
|
46
|
-
function each(className, callback) {
|
|
47
|
-
const elements = document.getElementsByClassName(className);
|
|
48
|
-
for (let i = 0; i < elements.length; i++) {
|
|
49
|
-
const thisElement = elements[i];
|
|
50
|
-
if (typeof callback === "function") {
|
|
51
|
-
callback(thisElement);
|
|
52
|
-
} else {
|
|
53
|
-
throw new Error("each(className, function() {... requires the callback argument to be of type Function");
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/helpers/checkout.ts
|
|
59
|
-
function showLoading() {
|
|
60
|
-
hideLoading();
|
|
61
|
-
const keyFrameStyle = document.createElement("style");
|
|
62
|
-
keyFrameStyle.type = "text/css";
|
|
63
|
-
keyFrameStyle.innerHTML = // eslint-disable-next-line no-multi-str
|
|
64
|
-
" @-webkit-keyframes rotate { 0% { -webkit-transform: rotate(45deg); } 100% { -webkit-transform: rotate(405deg); } } @keyframes rotate { from { transform: rotate(45deg); } to { transform: rotate(405deg); } }";
|
|
65
|
-
const head = document.getElementsByTagName("head")[0];
|
|
66
|
-
if (head) {
|
|
67
|
-
head.appendChild(keyFrameStyle);
|
|
68
|
-
}
|
|
69
|
-
const htmlLoader = document.createElement("div");
|
|
70
|
-
htmlLoader.setAttribute(
|
|
71
|
-
"style",
|
|
72
|
-
"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);"
|
|
73
|
-
);
|
|
74
|
-
htmlLoader.setAttribute("class", "fungies-loader" /* FUNGIES_LOADER */);
|
|
75
|
-
const mainSpinnerWrapper = document.createElement("main");
|
|
76
|
-
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%;";
|
|
77
|
-
mainSpinnerWrapper.setAttribute("style", htmlLoaderIconWrapper);
|
|
78
|
-
const spinner = document.createElement("div");
|
|
79
|
-
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;";
|
|
80
|
-
spinner.setAttribute("style", htmlLoaderIcon);
|
|
81
|
-
mainSpinnerWrapper.appendChild(spinner);
|
|
82
|
-
htmlLoader.appendChild(mainSpinnerWrapper);
|
|
83
|
-
const appendLoader = () => {
|
|
84
|
-
const body = document.getElementsByTagName("body")[0];
|
|
85
|
-
if (body) {
|
|
86
|
-
body.appendChild(htmlLoader);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
if (document.readyState === "loading") {
|
|
90
|
-
document.addEventListener("DOMContentLoaded", appendLoader);
|
|
91
|
-
} else {
|
|
92
|
-
appendLoader();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function hideLoading() {
|
|
96
|
-
each("fungies-loader" /* FUNGIES_LOADER */, (loader) => {
|
|
97
|
-
loader?.parentNode?.removeChild(loader);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
function getCheckoutOptions(element) {
|
|
101
|
-
const checkoutUrl = element.getAttribute("data-fungies-checkout-url");
|
|
102
|
-
if (!checkoutUrl) {
|
|
103
|
-
log(
|
|
104
|
-
"Element has data-fungies-checkout-url attribute but no value",
|
|
105
|
-
"warning" /* WARNING */
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
const modeAttr = element.getAttribute("data-fungies-mode");
|
|
109
|
-
const mode = modeAttr === "embed" || modeAttr === "overlay" ? modeAttr : "overlay";
|
|
110
|
-
const frameTarget = element.getAttribute("data-fungies-frame-target") || void 0;
|
|
111
|
-
const discountCode = element.getAttribute("data-fungies-discount-code") || void 0;
|
|
112
|
-
const customerEmail = element.getAttribute("data-fungies-customer-email") || void 0;
|
|
113
|
-
const quantityAttr = element.getAttribute("data-fungies-quantity");
|
|
114
|
-
const quantity = quantityAttr ? Number.parseInt(quantityAttr, 10) : void 0;
|
|
115
|
-
let items = void 0;
|
|
116
|
-
const itemsAttr = element.getAttribute("data-fungies-items");
|
|
117
|
-
if (itemsAttr) {
|
|
118
|
-
try {
|
|
119
|
-
items = JSON.parse(itemsAttr);
|
|
120
|
-
} catch (_error) {
|
|
121
|
-
log(
|
|
122
|
-
`Invalid JSON in data-fungies-items: ${itemsAttr}`,
|
|
123
|
-
"warning" /* WARNING */
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
let customFields = void 0;
|
|
128
|
-
const customFieldsAttr = element.getAttribute("data-fungies-custom-fields");
|
|
129
|
-
if (customFieldsAttr) {
|
|
130
|
-
try {
|
|
131
|
-
customFields = JSON.parse(customFieldsAttr);
|
|
132
|
-
} catch (_error) {
|
|
133
|
-
log(
|
|
134
|
-
`Invalid JSON in data-fungies-custom-fields: ${customFieldsAttr}`,
|
|
135
|
-
"warning" /* WARNING */
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const checkoutOptions = {
|
|
140
|
-
checkoutUrl,
|
|
141
|
-
settings: {
|
|
142
|
-
mode,
|
|
143
|
-
...frameTarget && { frameTarget }
|
|
144
|
-
},
|
|
145
|
-
...discountCode && { discountCode },
|
|
146
|
-
...customerEmail && { customerEmail },
|
|
147
|
-
...quantity && { quantity },
|
|
148
|
-
...items && { items },
|
|
149
|
-
...customFields && { customFields }
|
|
150
|
-
};
|
|
151
|
-
return checkoutOptions;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// src/constants/checkout.ts
|
|
155
|
-
var CHECKOUT_FRAME_CLOSED = "Checkout frame/window has been closed.";
|
|
156
|
-
var CHECKOUT_EVENTS = {
|
|
157
|
-
CHECKOUT_CLOSE: "closeWindow"
|
|
158
|
-
};
|
|
159
|
-
var CHECKOUT_MODE = {
|
|
160
|
-
EMBED: "embed",
|
|
161
|
-
OVERLAY: "overlay"
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// src/utils/device.ts
|
|
165
|
-
function isMobile() {
|
|
166
|
-
let check = false;
|
|
167
|
-
((a) => {
|
|
168
|
-
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(
|
|
169
|
-
a
|
|
170
|
-
) || /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(
|
|
171
|
-
a.substr(0, 4)
|
|
172
|
-
))
|
|
173
|
-
check = true;
|
|
174
|
-
})(navigator.userAgent || navigator.vendor);
|
|
175
|
-
return check;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/utils/url.ts
|
|
179
|
-
var encodeForTransport = (jsonString) => {
|
|
180
|
-
return encodeURIComponent(encodeURIComponent(jsonString));
|
|
181
|
-
};
|
|
182
|
-
var getCheckoutFrontEndURL = (checkoutInputAttributes, checkoutUrl, mode) => {
|
|
183
|
-
const url = new URL(checkoutUrl);
|
|
184
|
-
url.searchParams.append("fngs-checkout-payload", encodeForTransport(JSON.stringify(checkoutInputAttributes)));
|
|
185
|
-
url.searchParams.append("fngs-display-mode", mode);
|
|
186
|
-
return url.toString();
|
|
187
|
-
};
|
|
188
|
-
var getCheckoutUrl = ({ checkoutUrl, ...restProps }, mode) => {
|
|
189
|
-
return getCheckoutFrontEndURL(restProps, checkoutUrl, mode);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// src/helpers/iframe.ts
|
|
193
|
-
var closeCheckoutIFrame = () => {
|
|
194
|
-
log(CHECKOUT_FRAME_CLOSED);
|
|
195
|
-
hideLoading();
|
|
196
|
-
each("fungies-frame" /* FUNGIES_FRAME */, (element) => {
|
|
197
|
-
element.parentNode?.removeChild(element);
|
|
198
|
-
});
|
|
199
|
-
if (typeof window.FungiesWindow !== "undefined" && !window.FungiesWindow.closed) {
|
|
200
|
-
window.FungiesWindow.close();
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
var renderCheckoutFrame = (checkoutProps, settings, embed) => {
|
|
204
|
-
const checkoutUrl = getCheckoutUrl(checkoutProps, settings.mode);
|
|
205
|
-
if (!embed) {
|
|
206
|
-
showLoading();
|
|
207
|
-
}
|
|
208
|
-
window.FungiesFrame = document.createElement("iframe");
|
|
209
|
-
window.FungiesFrame.className = "fungies-frame" /* FUNGIES_FRAME */;
|
|
210
|
-
window.FungiesFrame.name = "fungies_frame";
|
|
211
|
-
window.FungiesFrame.frameBorder = "0";
|
|
212
|
-
window.FungiesFrame.allowTransparency = "true";
|
|
213
|
-
window.FungiesFrame.allow = "payment";
|
|
214
|
-
if (embed) {
|
|
215
|
-
window.FungiesFrame.classList.add("fungies-frame-embed" /* FUNGIES_FRAME_EMBED */);
|
|
216
|
-
window.FungiesFrame.setAttribute("style", "width: 100%; height: 100%;");
|
|
217
|
-
const styleElement = document.createElement("style");
|
|
218
|
-
styleElement.type = "text/css";
|
|
219
|
-
styleElement.innerHTML = `.${"fungies-frame-embed" /* FUNGIES_FRAME_EMBED */}::-webkit-scrollbar { display: none !important; }`;
|
|
220
|
-
document?.getElementsByTagName("head")[0]?.appendChild(styleElement);
|
|
221
|
-
} else {
|
|
222
|
-
window.FungiesFrame.classList.add("fungies-frame-overlay" /* FUNGIES_FRAME_OVERLAY */);
|
|
223
|
-
}
|
|
224
|
-
if (!embed) {
|
|
225
|
-
if (!isMobile()) {
|
|
226
|
-
window.FungiesFrame.setAttribute(
|
|
227
|
-
"style",
|
|
228
|
-
"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%;"
|
|
229
|
-
);
|
|
230
|
-
} else {
|
|
231
|
-
window.FungiesFrame.setAttribute(
|
|
232
|
-
"style",
|
|
233
|
-
"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%;"
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
window.FungiesFrame.src = checkoutUrl;
|
|
238
|
-
if (settings?.frameTarget && embed) {
|
|
239
|
-
const target = document.getElementById(settings.frameTarget);
|
|
240
|
-
if (target) {
|
|
241
|
-
target.appendChild(window.FungiesFrame);
|
|
242
|
-
}
|
|
243
|
-
} else {
|
|
244
|
-
const body = document.getElementsByTagName("body")[0];
|
|
245
|
-
if (body) {
|
|
246
|
-
body.appendChild(window.FungiesFrame);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
// src/lib/checkout.ts
|
|
252
|
-
var openCheckout = ({ settings, ...checkoutInputAttributes }) => {
|
|
253
|
-
closeCheckoutIFrame();
|
|
254
|
-
const renderCheckoutWithSettings = () => {
|
|
255
|
-
log("Checkout.open() called");
|
|
256
|
-
renderCheckoutFrame(checkoutInputAttributes, settings, settings?.mode === CHECKOUT_MODE.EMBED);
|
|
257
|
-
};
|
|
258
|
-
if (document.readyState !== "loading") {
|
|
259
|
-
renderCheckoutWithSettings();
|
|
260
|
-
} else {
|
|
261
|
-
document.addEventListener("DOMContentLoaded", renderCheckoutWithSettings);
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
var closeCheckout = () => {
|
|
265
|
-
closeCheckoutIFrame();
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
// src/helpers/dom.ts
|
|
269
|
-
var scanForCheckoutElements = () => {
|
|
270
|
-
log("Scanning for checkout elements");
|
|
271
|
-
const newFormatElements = document.querySelectorAll(
|
|
272
|
-
"[data-fungies-checkout-url]:not([data-fungies-initialized])"
|
|
273
|
-
);
|
|
274
|
-
for (const element of newFormatElements) {
|
|
275
|
-
const checkoutOptions = getCheckoutOptions(element);
|
|
276
|
-
element.addEventListener("click", (event) => {
|
|
277
|
-
event.preventDefault();
|
|
278
|
-
openCheckout(checkoutOptions);
|
|
279
|
-
});
|
|
280
|
-
element.setAttribute("data-fungies-initialized", "true");
|
|
281
|
-
}
|
|
282
|
-
const legacyFormatElements = document.querySelectorAll(
|
|
283
|
-
"[data-fungies-button]:not([data-fungies-initialized])"
|
|
284
|
-
);
|
|
285
|
-
for (const element of legacyFormatElements) {
|
|
286
|
-
const buttonUrl = element.getAttribute("data-fungies-button");
|
|
287
|
-
if (!buttonUrl) {
|
|
288
|
-
log(
|
|
289
|
-
"Element has data-fungies-button attribute but no value",
|
|
290
|
-
"warning" /* WARNING */
|
|
291
|
-
);
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
try {
|
|
295
|
-
const url = new URL(buttonUrl);
|
|
296
|
-
const pathParts = url.pathname.split("/");
|
|
297
|
-
const checkoutElementIndex = pathParts.indexOf("checkout-element");
|
|
298
|
-
const overlayIndex = pathParts.indexOf("overlay");
|
|
299
|
-
if (checkoutElementIndex === -1 && overlayIndex === -1) {
|
|
300
|
-
log(
|
|
301
|
-
`Invalid URL in data-fungies-button: ${buttonUrl}`,
|
|
302
|
-
"warning" /* WARNING */
|
|
303
|
-
);
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
const mode = "overlay";
|
|
307
|
-
const checkoutOptions = {
|
|
308
|
-
checkoutUrl: buttonUrl,
|
|
309
|
-
settings: {
|
|
310
|
-
mode
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
element.addEventListener("click", (event) => {
|
|
314
|
-
event.preventDefault();
|
|
315
|
-
openCheckout(checkoutOptions);
|
|
316
|
-
});
|
|
317
|
-
element.setAttribute("data-fungies-initialized", "true");
|
|
318
|
-
} catch (error) {
|
|
319
|
-
log(error, "error" /* ERROR */);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
var initializeDomSupport = () => {
|
|
324
|
-
log("Initializing DOM support");
|
|
325
|
-
if (document.readyState !== "loading") {
|
|
326
|
-
scanForCheckoutElements();
|
|
327
|
-
} else {
|
|
328
|
-
document.addEventListener("DOMContentLoaded", scanForCheckoutElements);
|
|
329
|
-
}
|
|
330
|
-
const observer = new MutationObserver((mutations) => {
|
|
331
|
-
let shouldScan = false;
|
|
332
|
-
for (const mutation of mutations) {
|
|
333
|
-
if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
|
|
334
|
-
for (const node of mutation.addedNodes) {
|
|
335
|
-
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
336
|
-
const element = node;
|
|
337
|
-
if (element.querySelector(
|
|
338
|
-
"[data-fungies-checkout-url]:not([data-fungies-initialized]), [data-fungies-button]:not([data-fungies-initialized])"
|
|
339
|
-
)) {
|
|
340
|
-
shouldScan = true;
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
if (shouldScan) {
|
|
348
|
-
scanForCheckoutElements();
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
observer.observe(document.body, {
|
|
352
|
-
childList: true,
|
|
353
|
-
subtree: true
|
|
354
|
-
});
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
// src/helpers/events.ts
|
|
358
|
-
var _messageListener = (message) => {
|
|
359
|
-
const { data } = message;
|
|
360
|
-
switch (typeof data === "string" ? data : "") {
|
|
361
|
-
case CHECKOUT_EVENTS.CHECKOUT_CLOSE:
|
|
362
|
-
closeCheckoutIFrame();
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
function listen() {
|
|
367
|
-
if (typeof window !== "undefined") {
|
|
368
|
-
window.addEventListener("message", _messageListener, false);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// src/lib/state.ts
|
|
373
|
-
var createInitialState = () => ({
|
|
374
|
-
completedSetup: false,
|
|
375
|
-
options: null
|
|
376
|
-
});
|
|
377
|
-
var updateState = (currentState, updates) => ({
|
|
378
|
-
...currentState,
|
|
379
|
-
...updates
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
// src/lib/fungies.ts
|
|
383
|
-
var initialize = (options, currentState = createInitialState()) => {
|
|
384
|
-
if (!currentState.completedSetup) {
|
|
385
|
-
listen();
|
|
386
|
-
if (options.enableDataAttributes !== false) {
|
|
387
|
-
initializeDomSupport();
|
|
388
|
-
}
|
|
389
|
-
updateState(currentState, {
|
|
390
|
-
completedSetup: true,
|
|
391
|
-
options
|
|
392
|
-
});
|
|
393
|
-
} else {
|
|
394
|
-
log("Cannot call Fungies.Initialize() more than once per page, the call was ignored.", "warning" /* WARNING */);
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
var createFungies = () => ({
|
|
398
|
-
Checkout: {
|
|
399
|
-
open: openCheckout,
|
|
400
|
-
close: closeCheckout
|
|
401
|
-
},
|
|
402
|
-
Initialize: initialize,
|
|
403
|
-
ScanDOM: scanForCheckoutElements
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
// src/index.ts
|
|
407
|
-
var Fungies = createFungies();
|
|
408
|
-
if (typeof window !== "undefined") {
|
|
409
|
-
window.Fungies = Fungies;
|
|
410
|
-
}
|
|
411
|
-
if (typeof document !== "undefined") {
|
|
412
|
-
const currentScript = document.currentScript;
|
|
413
|
-
if (currentScript?.hasAttribute("data-auto-init")) {
|
|
414
|
-
document.addEventListener("DOMContentLoaded", async () => {
|
|
415
|
-
Fungies.Initialize({
|
|
416
|
-
enableDataAttributes: true
|
|
417
|
-
});
|
|
418
|
-
if (currentScript?.hasAttribute("data-auto-display-checkout")) {
|
|
419
|
-
const checkoutOptions = getCheckoutOptions(currentScript);
|
|
420
|
-
Fungies.Checkout.open(checkoutOptions);
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
426
|
-
0 && (module.exports = {
|
|
427
|
-
Fungies
|
|
428
|
-
});
|