@rebilly/instruments 3.5.3-beta.0 → 3.7.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/dist/index.min.js +3 -3
- package/package.json +1 -2
- package/src/events/index.js +1 -0
- package/src/functions/mount/index.js +5 -1
- package/src/functions/mount/setup-framepay-theme.js +33 -9
- package/src/style/vendor/framepay.js +1 -1
- package/src/views/common/iframe/base-iframe.js +14 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebilly/instruments",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.2-beta.0",
|
|
4
4
|
"author": "Rebilly",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"unpkg": "dist/index.min.js",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"lodash.merge": "^4.6.2",
|
|
26
26
|
"popostmate": "^1.6.4",
|
|
27
27
|
"postcss": "^8.4.5",
|
|
28
|
-
"postcss-css-variables": "^0.18.0",
|
|
29
28
|
"rebilly-js-sdk": "^44.4.0",
|
|
30
29
|
"values.js": "^2.0.0"
|
|
31
30
|
},
|
package/src/events/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import kebabCase from 'lodash.kebabcase';
|
|
|
2
2
|
import BaseEvent from './base-event';
|
|
3
3
|
|
|
4
4
|
const events = {
|
|
5
|
+
dataReady: new BaseEvent('data-ready'),
|
|
5
6
|
instrumentReady: new BaseEvent('instrument-ready'),
|
|
6
7
|
purchaseCompleted: new BaseEvent('purchase-completed'),
|
|
7
8
|
setupCompleted: new BaseEvent('setup-completed')
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { mountSummary } from '../../views/summary';
|
|
3
3
|
import { mountMethodSelector } from '../../views/method-selector';
|
|
4
4
|
import { fetchData } from './fetch-data';
|
|
5
|
+
import Events from '../../events';
|
|
5
6
|
import setupElement from './setup-element';
|
|
6
7
|
import setupStorefront from './setup-storefront';
|
|
7
8
|
import setupOptions from './setup-options';
|
|
@@ -96,9 +97,12 @@ export async function mount({
|
|
|
96
97
|
// Setup state
|
|
97
98
|
state.options = setupOptions({ options });
|
|
98
99
|
state.storefront = setupStorefront({ options });
|
|
100
|
+
|
|
99
101
|
state.mainStyle = await setupStyles({ options });
|
|
102
|
+
|
|
100
103
|
state.data = await fetchData({ state });
|
|
101
|
-
|
|
104
|
+
Events.dataReady.dispatch(state.data);
|
|
105
|
+
|
|
102
106
|
state.options.themeFramepay = await setupFramepayTheme({ state, options });
|
|
103
107
|
state.i18n = setupI18n({ state });
|
|
104
108
|
|
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
import css from 'css';
|
|
2
|
-
import postcss from 'postcss';
|
|
3
|
-
import cssvariables from 'postcss-css-variables';
|
|
4
2
|
import camelCase from 'lodash.camelcase';
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
function processCSS(rawCss) {
|
|
5
|
+
const cssMap = {};
|
|
6
|
+
[...rawCss.matchAll(/(--rebilly.*(?=:))[:\s](.*(?=;))/g)]
|
|
7
|
+
.forEach(item => {
|
|
8
|
+
cssMap[item[1]] = item[2].trim();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
function parseValue(value) {
|
|
12
|
+
const cssVariables = value.match(/var\((.+?)\)/g);
|
|
13
|
+
if(cssVariables) {
|
|
14
|
+
let cssValue = value;
|
|
15
|
+
cssVariables.forEach(variable => {
|
|
16
|
+
const cssVarName = variable.match(/\((.*)\)/i)[1];
|
|
17
|
+
cssValue = value.replace(variable, cssMap[cssVarName]);
|
|
18
|
+
});
|
|
19
|
+
return parseValue(cssValue);
|
|
20
|
+
}
|
|
21
|
+
return value
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return Object.entries(cssMap)
|
|
25
|
+
.map(([key, value]) => [key, parseValue(value)]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function replaceCssVars(rawCss) {
|
|
29
|
+
processCSS(rawCss).forEach(([key, value]) => {
|
|
30
|
+
rawCss = rawCss.split(`var(${key})`).join(value);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return rawCss;
|
|
34
|
+
}
|
|
11
35
|
|
|
12
36
|
const getStyleProps = (ast, selector) => {
|
|
13
37
|
const { rules } = ast.stylesheet;
|
|
@@ -44,7 +68,7 @@ export default async ({
|
|
|
44
68
|
${options.css || ''}
|
|
45
69
|
`;
|
|
46
70
|
|
|
47
|
-
const resolvedCss =
|
|
71
|
+
const resolvedCss = replaceCssVars(fullCss);
|
|
48
72
|
const cssAst = css.parse(resolvedCss);
|
|
49
73
|
|
|
50
74
|
const cssSelectors = {
|
|
@@ -102,4 +126,4 @@ export default async ({
|
|
|
102
126
|
}
|
|
103
127
|
|
|
104
128
|
return framepayStyle;
|
|
105
|
-
}
|
|
129
|
+
}
|
|
@@ -20,7 +20,7 @@ export const framepayStyle = () => `
|
|
|
20
20
|
box-shadow: none;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
.rebilly-instruments-framepay .rebilly-framepay.rebilly-framepay-
|
|
23
|
+
.rebilly-instruments-framepay .rebilly-framepay.rebilly-framepay-google-pay {
|
|
24
24
|
min-height: auto;
|
|
25
25
|
border: none;
|
|
26
26
|
margin: 0;
|
|
@@ -35,16 +35,27 @@ export default class BaseIframe {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async createComponent() {
|
|
38
|
+
// Use a fake container so we can capture the appendChild call
|
|
39
|
+
// and immediately apply the feature-policy flags to the iframe
|
|
40
|
+
// before Postmate tries to load the iframe. The feature policy
|
|
41
|
+
// would otherwise not apply until the frame was reloaded.
|
|
42
|
+
const container = {
|
|
43
|
+
appendChild: (iframe) => {
|
|
44
|
+
iframe.setAttribute('loading', 'lazy');
|
|
45
|
+
iframe.setAttribute('allow', 'payment');
|
|
46
|
+
iframe.allowPaymentRequest = true;
|
|
47
|
+
this.container.appendChild(iframe);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
38
51
|
const component = await new Postmate({
|
|
39
52
|
name: this.name,
|
|
40
53
|
url: this.url,
|
|
41
|
-
container
|
|
54
|
+
container,
|
|
42
55
|
classListArray: this.classListArray,
|
|
43
56
|
model: this.model
|
|
44
57
|
});
|
|
45
58
|
|
|
46
|
-
component.frame.setAttribute('allowpaymentrequest', 'allowpaymentrequest');
|
|
47
|
-
component.frame.setAttribute('allow', 'payment');
|
|
48
59
|
return component;
|
|
49
60
|
}
|
|
50
61
|
}
|