@subiz/widget-v4 4.1.35 → 4.1.36
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/compiled_src/util/campaign.js +2 -6
- package/compiled_src/util/common.js +5 -7
- package/compiled_src/util/order.js +2 -4
- package/compiled_src/util/pubsub.js +3 -6
- package/dist/132.js +6661 -0
- package/dist/178.js +406 -0
- package/dist/18924eff71e.132.js +1 -0
- package/dist/18924eff71e.178.js +1 -0
- package/dist/18924eff71e.213.js +1 -0
- package/dist/18924eff71e.335.js +1 -0
- package/dist/18924eff71e.362.js +1 -0
- package/dist/18924eff71e.441.js +1 -0
- package/dist/18924eff71e.605.js +1 -0
- package/dist/18924eff71e.678.js +1 -0
- package/dist/18924eff71e.782.js +1 -0
- package/dist/18924eff71e.app.js +1 -0
- package/dist/18924eff71e.index.html +33 -0
- package/dist/18924eff71e.library.html +33 -0
- package/dist/18924eff71e.library.js +1 -0
- package/dist/18924eff71e.preview.html +759 -0
- package/dist/18924eff71e.preview.js +1 -0
- package/dist/18924eff71e.screenshoot.js +1 -0
- package/dist/18924eff71e.webview.js +1 -0
- package/dist/213.js +2780 -0
- package/dist/335.js +372 -0
- package/dist/362.js +107 -0
- package/dist/441.js +2983 -0
- package/dist/605.js +305 -0
- package/dist/678.js +107 -0
- package/dist/782.js +107 -0
- package/dist/HASH +1 -0
- package/dist/assets/img/Facebook.64607ec.png +0 -0
- package/dist/assets/img/Zalo.6845707.png +0 -0
- package/dist/assets/img/award1a.1a58e10.png +0 -0
- package/dist/assets/img/award3a.3b74423.png +0 -0
- package/dist/assets/img/award4a.ed6ccd4.png +0 -0
- package/dist/assets/img/award5.39eb7ae.png +0 -0
- package/dist/assets/img/bubble_default.7d5e4ab.svg +20 -0
- package/dist/assets/img/caret.998eb8f.svg +1 -0
- package/dist/assets/img/convos_empty.2353007.svg +72 -0
- package/dist/assets/img/default.06e6ee0.jpg +0 -0
- package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
- package/dist/assets/img/done_gray.d7e8203.svg +4 -0
- package/dist/assets/img/done_green.b817fd4.svg +4 -0
- package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
- package/dist/assets/img/empty.29bed2d.svg +23 -0
- package/dist/assets/img/empty_1.0b98af0.svg +11 -0
- package/dist/assets/img/examplte_logo.f86535f.svg +1 -0
- package/dist/assets/img/external-link.90577cc.svg +1 -0
- package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
- package/dist/assets/img/ghn.070f8e3.svg +17 -0
- package/dist/assets/img/ghtk.326eac1.svg +18 -0
- package/dist/assets/img/image_default.be0698b.png +0 -0
- package/dist/assets/img/info.ebce7ea.svg +1 -0
- package/dist/assets/img/loader.37000a7.svg +1 -0
- package/dist/assets/img/loading_static.a27f0ac.svg +10 -0
- package/dist/assets/img/main-service1.d536cc2.png +0 -0
- package/dist/assets/img/main-service2.9b99549.png +0 -0
- package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
- package/dist/assets/img/package.8d37d0f.svg +5 -0
- package/dist/assets/img/package_fade.763c001.svg +1 -0
- package/dist/assets/img/rating--average.1ea492c.svg +12 -0
- package/dist/assets/img/rating--great.e3d712e.svg +16 -0
- package/dist/assets/img/rating--poor.2938a25.svg +12 -0
- package/dist/assets/img/search.f9705ff.svg +1 -0
- package/dist/assets/img/send.6db52a9.svg +3 -0
- package/dist/assets/img/shop.f7dc7d8.svg +1 -0
- package/dist/assets/img/shop_faded.df7845a.svg +1 -0
- package/dist/assets/img/subiz-mono.877e9f5.svg +3 -0
- package/dist/assets/img/x.26fdfa3.svg +5 -0
- package/dist/malicious-app.js +13 -0
- package/dist/screenshoot.html +7 -0
- package/dist/screenshoot.js +6380 -0
- package/package.json +11 -11
- package/src/util/common.js +5 -1
package/dist/213.js
ADDED
|
@@ -0,0 +1,2780 @@
|
|
|
1
|
+
(self["webpackChunk_subiz_widget_v4"] = self["webpackChunk_subiz_widget_v4"] || []).push([[213],{
|
|
2
|
+
|
|
3
|
+
/***/ 8213:
|
|
4
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
// ESM COMPAT FLAG
|
|
8
|
+
__webpack_require__.r(__webpack_exports__);
|
|
9
|
+
|
|
10
|
+
// EXPORTS
|
|
11
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
12
|
+
"default": () => (/* binding */ Popup)
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// EXTERNAL MODULE: ./src/util/index.js + 3 modules
|
|
16
|
+
var util = __webpack_require__(4494);
|
|
17
|
+
// EXTERNAL MODULE: ./src/common.js
|
|
18
|
+
var common = __webpack_require__(2493);
|
|
19
|
+
;// CONCATENATED MODULE: ./src/popup/tick.core.commonjs.js
|
|
20
|
+
|
|
21
|
+
let obj = function () {
|
|
22
|
+
var module = {};
|
|
23
|
+
var ExtensionType = {
|
|
24
|
+
VIEW: 'view',
|
|
25
|
+
EASING_FUNCTION: 'easing-function'
|
|
26
|
+
};
|
|
27
|
+
var Extensions = {};
|
|
28
|
+
Extensions[ExtensionType.VIEW] = {};
|
|
29
|
+
Extensions[ExtensionType.EASING_FUNCTION] = {};
|
|
30
|
+
var addExtensions = function addExtensions(type, extensions) {
|
|
31
|
+
if (!Extensions[type]) return null;
|
|
32
|
+
for (var name in extensions) {
|
|
33
|
+
if (!extensions.hasOwnProperty(name)) continue;
|
|
34
|
+
if (Extensions[type][name]) return null;
|
|
35
|
+
Extensions[type][name] = extensions[name];
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var isVisible = function isVisible(element) {
|
|
39
|
+
var elementRect = element.getBoundingClientRect();
|
|
40
|
+
if (elementRect.bottom < 0) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (elementRect.top > window.scrollY + window.innerHeight) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
48
|
+
var addExtension = function addExtension(type, name, fn) {
|
|
49
|
+
if (!Extensions[type]) {
|
|
50
|
+
throw 'Can\'t add extension with type of "' + type + '", "' + type + '" is not a valid extension type. The following types are valid: ' + keysToList(Extensions);
|
|
51
|
+
}
|
|
52
|
+
if (!/^[-a-z]+$/.test(name)) {
|
|
53
|
+
throw 'Can\'t add extension with name "' + name + '", "' + name + '" is contains invalid characters. Only lowercase alphabetical characters and dashes are allowed.';
|
|
54
|
+
}
|
|
55
|
+
if (Extensions[type][name]) {
|
|
56
|
+
throw 'Can\'t add extension with name "' + name + '", "' + name + '" is already added.';
|
|
57
|
+
}
|
|
58
|
+
Extensions[type][name] = fn;
|
|
59
|
+
};
|
|
60
|
+
var getExtension = function getExtension(type, name) {
|
|
61
|
+
if (!Extensions[type]) {
|
|
62
|
+
throw 'Can\'t get extension with type of "' + type + '", "' + type + '" is not a valid extension type. The following types are available: ' + keysToList(Extensions);
|
|
63
|
+
}
|
|
64
|
+
if (!Extensions[type][name]) {
|
|
65
|
+
throw 'Can\'t get extension with name "' + name + '", "' + name + '" is not available. The following extensions are available: ' + keysToList(Extensions[type]);
|
|
66
|
+
}
|
|
67
|
+
return Extensions[type][name];
|
|
68
|
+
};
|
|
69
|
+
var destroyer = function (state) {
|
|
70
|
+
return {
|
|
71
|
+
destroy: function destroy() {
|
|
72
|
+
state.destroyed = true;
|
|
73
|
+
if (state.frame) {
|
|
74
|
+
cancelAnimationFrame(state.frame);
|
|
75
|
+
}
|
|
76
|
+
if (state.styleObserver) {
|
|
77
|
+
state.styleObserver.disconnect();
|
|
78
|
+
}
|
|
79
|
+
if (state.didResizeWindow) {
|
|
80
|
+
window.removeEventListener('resize', state.didResizeWindow);
|
|
81
|
+
}
|
|
82
|
+
if (state.root && state.root.parentNode) {
|
|
83
|
+
state.root.parentNode.removeChild(state.root);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var rooter = function (state) {
|
|
89
|
+
var root = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.createElement('span');
|
|
90
|
+
var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
91
|
+
state.root = root;
|
|
92
|
+
state.aligned = null;
|
|
93
|
+
state.destroyed = false;
|
|
94
|
+
if (root && name) {
|
|
95
|
+
state.root.classList.add('tick-' + name);
|
|
96
|
+
state.root.setAttribute('data-view', name);
|
|
97
|
+
}
|
|
98
|
+
if (root && root.dataset.layout) {
|
|
99
|
+
state.align = (root.dataset.layout.match(/left|right|center/) || [])[0] || 'left';
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
appendTo: function appendTo(element) {
|
|
103
|
+
var location = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'last';
|
|
104
|
+
if (!state.root || state.root && state.root.parentNode) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (location === 'last') {
|
|
108
|
+
if (element.childNodes.length && element.childNodes[element.childNodes.length - 1].nodeType === Node.TEXT_NODE) {
|
|
109
|
+
element.insertBefore(state.root, element.childNodes[element.childNodes.length - 1]);
|
|
110
|
+
} else {
|
|
111
|
+
element.appendChild(state.root);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (location === 'first') {
|
|
116
|
+
if (element.childNodes.length === 0) {
|
|
117
|
+
element.appendChild(state.root);
|
|
118
|
+
} else if (element.children.length === 0 && element.childNodes.length) {
|
|
119
|
+
element.insertBefore(state.root, element.childNodes[element.childNodes.length - 1]);
|
|
120
|
+
} else {
|
|
121
|
+
element.insertBefore(state.root, element.children[0]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (typeof location !== 'string') {
|
|
125
|
+
element.insertBefore(state.root, location);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
var grouper = function (state, definition) {
|
|
131
|
+
state.definition = definition;
|
|
132
|
+
return {
|
|
133
|
+
setDefinition: function setDefinition(definition) {
|
|
134
|
+
state.definition = definition;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
var drawer = function (state, _draw, drawViews, present) {
|
|
139
|
+
return {
|
|
140
|
+
draw: function draw() {
|
|
141
|
+
if (!state.dirty) {
|
|
142
|
+
if (drawViews) {
|
|
143
|
+
var redrawn = drawViews(state);
|
|
144
|
+
if (redrawn) {
|
|
145
|
+
fit(state);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
_draw(state, present);
|
|
151
|
+
fit(state);
|
|
152
|
+
state.dirty = false;
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
var fit = function fit(state) {
|
|
158
|
+
if (!state.fit) {
|
|
159
|
+
if (!state.root || !(state.root.getAttribute('data-layout') || '').match(/fit/)) {
|
|
160
|
+
state.fit = false;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
var style = window.getComputedStyle(state.root, null);
|
|
164
|
+
state.fit = true;
|
|
165
|
+
state.fitInfo = {
|
|
166
|
+
currentFontSize: parseInt(style.getPropertyValue('font-size'), 10)
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
state.fitInfo.availableWidth = state.root.parentNode.clientWidth;
|
|
170
|
+
state.fitInfo.currentWidth = state.root.scrollWidth;
|
|
171
|
+
var newFontSize = Math.min(Math.max(4, state.fitInfo.availableWidth / state.fitInfo.currentWidth * state.fitInfo.currentFontSize), 1024);
|
|
172
|
+
var dist = Math.abs(newFontSize - state.fitInfo.currentFontSize);
|
|
173
|
+
if (dist <= 1) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
state.fitInfo.currentFontSize = newFontSize;
|
|
177
|
+
state.root.style.setProperties('fontSize', state.fitInfo.currentFontSize + 'px', 'important');
|
|
178
|
+
};
|
|
179
|
+
var updater = function (state) {
|
|
180
|
+
state.dirty = true;
|
|
181
|
+
state.value = null;
|
|
182
|
+
state.valueUpdateCount = 0;
|
|
183
|
+
state.isInitialValue = function () {
|
|
184
|
+
return state.valueUpdateCount <= 1;
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
reset: function reset() {
|
|
188
|
+
state.dirty = true;
|
|
189
|
+
state.value = null;
|
|
190
|
+
state.valueUpdateCount = 0;
|
|
191
|
+
},
|
|
192
|
+
update: function update(value) {
|
|
193
|
+
if (equal(state.value, value)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
state.value = value;
|
|
197
|
+
state.valueUpdateCount++;
|
|
198
|
+
state.dirty = true;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
var resizer = function (state) {
|
|
203
|
+
state.didResizeWindow = function () {
|
|
204
|
+
state.dirty = true;
|
|
205
|
+
};
|
|
206
|
+
window.addEventListener('resize', state.didResizeWindow);
|
|
207
|
+
};
|
|
208
|
+
var _typeof = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? function (obj) {
|
|
209
|
+
return typeof obj;
|
|
210
|
+
} : function (obj) {
|
|
211
|
+
return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj;
|
|
212
|
+
};
|
|
213
|
+
var classCallCheck = function (instance, Constructor) {
|
|
214
|
+
if (!(instance instanceof Constructor)) {
|
|
215
|
+
throw new TypeError('Cannot call a class as a function');
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
var createClass = function () {
|
|
219
|
+
function defineProperties(target, props) {
|
|
220
|
+
for (var i = 0; i < props.length; i++) {
|
|
221
|
+
var descriptor = props[i];
|
|
222
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
223
|
+
descriptor.configurable = true;
|
|
224
|
+
if ('value' in descriptor) descriptor.writable = true;
|
|
225
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return function (Constructor, protoProps, staticProps) {
|
|
229
|
+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
230
|
+
if (staticProps) defineProperties(Constructor, staticProps);
|
|
231
|
+
return Constructor;
|
|
232
|
+
};
|
|
233
|
+
}();
|
|
234
|
+
var _extends = Object.assign || function (target) {
|
|
235
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
236
|
+
var source = arguments[i];
|
|
237
|
+
for (var key in source) {
|
|
238
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
239
|
+
target[key] = source[key];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return target;
|
|
244
|
+
};
|
|
245
|
+
var toConsumableArray = function (arr) {
|
|
246
|
+
if (Array.isArray(arr)) {
|
|
247
|
+
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
|
248
|
+
return arr2;
|
|
249
|
+
} else {
|
|
250
|
+
return Array.from(arr);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
var draw = function draw(state, present) {
|
|
254
|
+
var views = (state.definition || []).concat();
|
|
255
|
+
if (state.align === 'right') {
|
|
256
|
+
views.reverse();
|
|
257
|
+
}
|
|
258
|
+
var value = Array.isArray(state.value) ? state.value.concat() : _typeof(state.value) === 'object' ? clone(state.value) : state.value;
|
|
259
|
+
views.forEach(function (view) {
|
|
260
|
+
if (!view.presenter) {
|
|
261
|
+
state.update = present(view);
|
|
262
|
+
if (!view.presenter) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
view.presenter.appendTo(state.root);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
views.filter(function (view) {
|
|
269
|
+
return view.presenter !== undefined;
|
|
270
|
+
}).forEach(function (view) {
|
|
271
|
+
if (Array.isArray(value) && state.valueMapping) {
|
|
272
|
+
state.update(view, state.valueMapping === 'indexes' ? state.align === 'right' ? value.pop() : value.shift() : value);
|
|
273
|
+
} else if (view.key && value[view.key] !== undefined) {
|
|
274
|
+
state.update(view, value[view.key]);
|
|
275
|
+
} else {
|
|
276
|
+
state.update(view, value);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
state.views = views;
|
|
280
|
+
drawViews(state);
|
|
281
|
+
};
|
|
282
|
+
var drawViews = function drawViews(state) {
|
|
283
|
+
var redrawn = false;
|
|
284
|
+
state.views.filter(function (view) {
|
|
285
|
+
return view.presenter !== undefined;
|
|
286
|
+
}).forEach(function (view) {
|
|
287
|
+
if (view.presenter.draw()) {
|
|
288
|
+
redrawn = true;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
return redrawn;
|
|
292
|
+
};
|
|
293
|
+
var createRoot = function (root, definition, present) {
|
|
294
|
+
var state = {
|
|
295
|
+
valueMapping: null
|
|
296
|
+
};
|
|
297
|
+
if (root && root.dataset.valueMapping) {
|
|
298
|
+
var allowed = ['none', 'indexes'];
|
|
299
|
+
var mapping = root.dataset.valueMapping;
|
|
300
|
+
state.valueMapping = allowed.indexOf(mapping) !== -1 ? mapping : null;
|
|
301
|
+
}
|
|
302
|
+
return Object.assign({}, rooter(state, root), resizer(state), updater(state), grouper(state, definition), drawer(state, draw, drawViews, present), destroyer(state));
|
|
303
|
+
};
|
|
304
|
+
var draw$1 = function draw(state, present, ready) {
|
|
305
|
+
var value = copyArray(Array.isArray(state.value) ? state.value : (state.value + '').split(''));
|
|
306
|
+
if (state.align === 'right') {
|
|
307
|
+
value.reverse();
|
|
308
|
+
}
|
|
309
|
+
if (state.definitions.length > value.length) {
|
|
310
|
+
while (state.definitions.length > value.length) {
|
|
311
|
+
var def = state.definitions.pop();
|
|
312
|
+
def.presenter.destroy();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
value.forEach(function (value, index) {
|
|
316
|
+
var def = state.definitions[index];
|
|
317
|
+
if (!def) {
|
|
318
|
+
def = state.definitions[index] = cloneDefinition(state.definition);
|
|
319
|
+
state.update = present(def);
|
|
320
|
+
def.presenter.appendTo(state.root, state.align === 'right' ? 'first' : 'last');
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
value.forEach(function (value, index) {
|
|
324
|
+
return state.update(state.definitions[index], value);
|
|
325
|
+
});
|
|
326
|
+
state.views = value;
|
|
327
|
+
drawViews$1(state);
|
|
328
|
+
};
|
|
329
|
+
var drawViews$1 = function drawViews(state) {
|
|
330
|
+
var redrawn = false;
|
|
331
|
+
state.views.forEach(function (view, index) {
|
|
332
|
+
if (state.definitions[index].presenter.draw()) {
|
|
333
|
+
redrawn = true;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
return redrawn;
|
|
337
|
+
};
|
|
338
|
+
var createRepeater = function (root, definition, present) {
|
|
339
|
+
var state = {
|
|
340
|
+
definitions: []
|
|
341
|
+
};
|
|
342
|
+
return Object.assign({}, rooter(state, root), updater(state), grouper(state, definition), drawer(state, draw$1, drawViews$1, present), destroyer(state));
|
|
343
|
+
};
|
|
344
|
+
var text = function text(node, value) {
|
|
345
|
+
var textNode = node.childNodes[0];
|
|
346
|
+
if (!textNode) {
|
|
347
|
+
textNode = document.createTextNode(value);
|
|
348
|
+
node.appendChild(textNode);
|
|
349
|
+
} else if (value !== textNode.nodeValue) {
|
|
350
|
+
textNode.nodeValue = value;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
var create$1 = function create(name, className) {
|
|
354
|
+
var el = document.createElement(name);
|
|
355
|
+
if (className) {
|
|
356
|
+
el.className = className;
|
|
357
|
+
}
|
|
358
|
+
return el;
|
|
359
|
+
};
|
|
360
|
+
var observeAttributes = function observeAttributes(element, attributes, cb) {
|
|
361
|
+
var observer = new MutationObserver(function (mutations) {
|
|
362
|
+
attributes.forEach(function (attr) {
|
|
363
|
+
if (mutations.filter(function (mutation) {
|
|
364
|
+
return attributes.includes(mutation.attributeName);
|
|
365
|
+
}).length) {
|
|
366
|
+
cb(element.getAttribute(attr));
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
observer.observe(element, {
|
|
371
|
+
attributes: true
|
|
372
|
+
});
|
|
373
|
+
return observer;
|
|
374
|
+
};
|
|
375
|
+
var isHTMLElement = function isHTMLElement(value) {
|
|
376
|
+
return value instanceof HTMLElement;
|
|
377
|
+
};
|
|
378
|
+
var setTransform = function setTransform(element, name, value) {
|
|
379
|
+
var unit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
|
380
|
+
if (!element.transforms) {
|
|
381
|
+
element.transforms = [];
|
|
382
|
+
}
|
|
383
|
+
var t = element.transforms.find(function (t) {
|
|
384
|
+
return t.name === name;
|
|
385
|
+
});
|
|
386
|
+
if (t) {
|
|
387
|
+
t.value = value;
|
|
388
|
+
} else {
|
|
389
|
+
element.transforms.push({
|
|
390
|
+
name: name,
|
|
391
|
+
value: value,
|
|
392
|
+
unit: unit
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
setTransformStyle(element, element.transforms);
|
|
396
|
+
};
|
|
397
|
+
var setTransformStyle = function setTransformStyle(element, transforms) {
|
|
398
|
+
element.style.setProperty('transform', transforms.map(function (t) {
|
|
399
|
+
return t.name + '(' + t.value + t.unit + ')';
|
|
400
|
+
}).join(' '), 'important');
|
|
401
|
+
};
|
|
402
|
+
var capitalizeFirstLetter$1 = function capitalizeFirstLetter(string) {
|
|
403
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
404
|
+
};
|
|
405
|
+
var CACHE = {};
|
|
406
|
+
var cache = function (value, fn) {
|
|
407
|
+
var fns = fn.toString();
|
|
408
|
+
if (!CACHE[fns]) {
|
|
409
|
+
CACHE[fns] = {};
|
|
410
|
+
}
|
|
411
|
+
if (!CACHE[fns][value]) {
|
|
412
|
+
CACHE[fns][value] = fn(value);
|
|
413
|
+
}
|
|
414
|
+
return CACHE[fns][value];
|
|
415
|
+
};
|
|
416
|
+
var isInt = new RegExp('^[0-9]+$');
|
|
417
|
+
var isBoolean$1 = new RegExp('^(true|false)$');
|
|
418
|
+
var isFloat = new RegExp('^[0-9.]+$');
|
|
419
|
+
var isColor = new RegExp('color');
|
|
420
|
+
var isShadow = new RegExp('shadow');
|
|
421
|
+
var isGradient = new RegExp('^(follow-gradient|horizontal-gradient|vertical-gradient)');
|
|
422
|
+
var isDuration = new RegExp('^[.0-9]+(?:ms|s){1}$');
|
|
423
|
+
var isTransition = new RegExp('^transition-?(?:in|out)?$');
|
|
424
|
+
var isURL = new RegExp('^url\\(');
|
|
425
|
+
var toDuration = function toDuration(string) {
|
|
426
|
+
return string ? parseFloat(string) * (/ms$/.test(string) ? 1 : 1000) : 0;
|
|
427
|
+
};
|
|
428
|
+
var toTransition = function toTransition(string) {
|
|
429
|
+
return string.match(/[a-z]+(?:\(.*?\))?\s?(?:origin\(.*?\))?\s?(?:[a-z]+\(.*?\))?[ .a-z-0-9]*/g).map(toTransitionPartial);
|
|
430
|
+
};
|
|
431
|
+
var toTransitionPartial = function toTransitionPartial(string) {
|
|
432
|
+
var parts = string.match(/([a-z]+(?:\(.*?\))?)\s?(?:origin\((.*?)\))?\s?([a-z]+(?:\(.*?\))?)?\s?(?:([.0-9ms]+)?\s?(?:(ease-[a-z-]+))?\s?([.0-9ms]+)?)?/);
|
|
433
|
+
var fn = toFunctionOutline(parts[1]);
|
|
434
|
+
var origin = undefined;
|
|
435
|
+
var duration = undefined;
|
|
436
|
+
var ease = undefined;
|
|
437
|
+
var delay = undefined;
|
|
438
|
+
var resolver = undefined;
|
|
439
|
+
parts.slice(2).filter(function (part) {
|
|
440
|
+
return typeof part !== 'undefined';
|
|
441
|
+
}).forEach(function (part) {
|
|
442
|
+
if (isDuration.test(part)) {
|
|
443
|
+
if (typeof duration === 'undefined') {
|
|
444
|
+
duration = toDuration(part);
|
|
445
|
+
} else {
|
|
446
|
+
delay = toDuration(part);
|
|
447
|
+
}
|
|
448
|
+
} else if (/ /.test(part)) {
|
|
449
|
+
origin = part;
|
|
450
|
+
} else if (/^ease-[a-z-]+$/.test(part)) {
|
|
451
|
+
ease = part;
|
|
452
|
+
} else if (/^[a-z]+/.test(part)) {
|
|
453
|
+
resolver = toFunctionOutline(part);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
if (resolver) {
|
|
457
|
+
duration = undefined;
|
|
458
|
+
ease = undefined;
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
name: fn.name,
|
|
462
|
+
parameters: fn.parameters,
|
|
463
|
+
duration: duration,
|
|
464
|
+
ease: ease,
|
|
465
|
+
delay: delay,
|
|
466
|
+
origin: origin,
|
|
467
|
+
resolver: resolver
|
|
468
|
+
};
|
|
469
|
+
};
|
|
470
|
+
var toGradient = function toGradient(string) {
|
|
471
|
+
var type = string.match(/follow-gradient|horizontal-gradient|vertical-gradient/)[0];
|
|
472
|
+
var colors = string.substr(type.length).match(/(?:transparent|rgb\(.*?\)|hsl\(.*?\)|hsla\(.*?\)|rgba\(.*?\)|[a-z]+|#[abcdefABCDEF\d]+)\s?(?:[\d]{1,3}%?)?/g).map(toGradientColor);
|
|
473
|
+
return {
|
|
474
|
+
type: type,
|
|
475
|
+
colors: colors
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
var gradientOffsetRegex = /\s([\d]{1,3})%?$/;
|
|
479
|
+
var toGradientColor = function toGradientColor(string) {
|
|
480
|
+
var offset = string.match(gradientOffsetRegex);
|
|
481
|
+
return {
|
|
482
|
+
offset: offset ? parseFloat(offset[1]) / 100 : null,
|
|
483
|
+
value: toColor(string.replace(gradientOffsetRegex, ''))
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
var toColor = typeof document === 'undefined' ? function (string) {
|
|
487
|
+
return string;
|
|
488
|
+
} : function (string) {
|
|
489
|
+
if (string === 'transparent') {
|
|
490
|
+
return 'rgba(0,0,0,0)';
|
|
491
|
+
}
|
|
492
|
+
var pipette = document.createElement('span');
|
|
493
|
+
pipette.style.cssText = 'position:absolute !important;visibility:hidden !important;color:' + string + ' !important';
|
|
494
|
+
document.body.appendChild(pipette);
|
|
495
|
+
requestAnimationFrame(function () {
|
|
496
|
+
pipette.parentNode.removeChild(pipette);
|
|
497
|
+
});
|
|
498
|
+
return window.getComputedStyle(pipette).getPropertyValue('color');
|
|
499
|
+
};
|
|
500
|
+
var toShadow = function toShadow(style) {
|
|
501
|
+
if (typeof style !== 'string') {
|
|
502
|
+
return style;
|
|
503
|
+
}
|
|
504
|
+
return style.match(/([-.\d]+(?:%|ms|s|deg|cm|em|ch|ex|q|in|mm|pc|pt|px|vh|vw|vmin|vmax)?)|[%#A-Za-z0-9,.()]+/g);
|
|
505
|
+
};
|
|
506
|
+
var toURL = function toURL(style) {
|
|
507
|
+
var urls = style.match(/url\((.*?)\)/g).map(function (url) {
|
|
508
|
+
return url.substring(4, url.length - 1);
|
|
509
|
+
});
|
|
510
|
+
return urls.length === 1 ? urls[0] : urls;
|
|
511
|
+
};
|
|
512
|
+
var toStyleProperty = function toStyleProperty(key) {
|
|
513
|
+
return key.trim().split('-').map(function (key, index) {
|
|
514
|
+
return index > 0 ? capitalizeFirstLetter$1(key) : key;
|
|
515
|
+
}).join('');
|
|
516
|
+
};
|
|
517
|
+
var toStyleValue = function toStyleValue(value, property) {
|
|
518
|
+
if (isBoolean$1.test(value)) {
|
|
519
|
+
return typeof value === 'string' ? value === 'true' : value;
|
|
520
|
+
}
|
|
521
|
+
if (isInt.test(value)) return parseInt(value, 10);
|
|
522
|
+
if (isFloat.test(value)) return parseFloat(value);
|
|
523
|
+
if (isURL.test(value)) return toURL(value);
|
|
524
|
+
if (isColor.test(property)) {
|
|
525
|
+
if (isGradient.test(value)) {
|
|
526
|
+
return cache(value, toGradient);
|
|
527
|
+
}
|
|
528
|
+
return cache(value, toColor);
|
|
529
|
+
}
|
|
530
|
+
if (isShadow.test(property)) return cache(value, toShadow);
|
|
531
|
+
if (isTransition.test(property)) {
|
|
532
|
+
if (value === 'none') return value;
|
|
533
|
+
return cache(value, toTransition);
|
|
534
|
+
}
|
|
535
|
+
return value;
|
|
536
|
+
};
|
|
537
|
+
var toStyle = function toStyle(string) {
|
|
538
|
+
var parts = string.split(':').map(trim);
|
|
539
|
+
var property = toStyleProperty(parts[0]);
|
|
540
|
+
var value = toStyleValue(parts[1], parts[0]);
|
|
541
|
+
if (!property || value === null || typeof value === 'undefined') {
|
|
542
|
+
return null;
|
|
543
|
+
}
|
|
544
|
+
return {
|
|
545
|
+
property: property,
|
|
546
|
+
value: value
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
var toStyles = function toStyles(string) {
|
|
550
|
+
return string.split(';').filter(function (style) {
|
|
551
|
+
return style.trim().length;
|
|
552
|
+
}).map(toStyle).filter(function (style) {
|
|
553
|
+
return style !== null;
|
|
554
|
+
}).reduce(function (styles, style) {
|
|
555
|
+
styles[style.property] = style.value;
|
|
556
|
+
return styles;
|
|
557
|
+
}, {});
|
|
558
|
+
};
|
|
559
|
+
var easeOutSine = function easeOutSine(t) {
|
|
560
|
+
return Math.sin(t * (Math.PI / 2));
|
|
561
|
+
};
|
|
562
|
+
var easeOutCubic = function easeOutCubic(t) {
|
|
563
|
+
var t1 = t - 1;
|
|
564
|
+
return t1 * t1 * t1 + 1;
|
|
565
|
+
};
|
|
566
|
+
var easeOutBounce = function easeOutBounce(t) {
|
|
567
|
+
var scaledTime = t / 1;
|
|
568
|
+
if (scaledTime < 1 / 2.75) {
|
|
569
|
+
return 7.5625 * scaledTime * scaledTime;
|
|
570
|
+
} else if (scaledTime < 2 / 2.75) {
|
|
571
|
+
var scaledTime2 = scaledTime - 1.5 / 2.75;
|
|
572
|
+
return 7.5625 * scaledTime2 * scaledTime2 + 0.75;
|
|
573
|
+
} else if (scaledTime < 2.5 / 2.75) {
|
|
574
|
+
var _scaledTime = scaledTime - 2.25 / 2.75;
|
|
575
|
+
return 7.5625 * _scaledTime * _scaledTime + 0.9375;
|
|
576
|
+
} else {
|
|
577
|
+
var _scaledTime2 = scaledTime - 2.625 / 2.75;
|
|
578
|
+
return 7.5625 * _scaledTime2 * _scaledTime2 + 0.984375;
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
var EasingFunctions = {
|
|
582
|
+
'ease-out-sine': easeOutSine,
|
|
583
|
+
'ease-out-cubic': easeOutCubic,
|
|
584
|
+
'ease-out-bounce': easeOutBounce
|
|
585
|
+
};
|
|
586
|
+
addExtensions(ExtensionType.EASING_FUNCTION, EasingFunctions);
|
|
587
|
+
var styler = function (state) {
|
|
588
|
+
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
589
|
+
state.lastAppliedStyles = null;
|
|
590
|
+
updateStyles(state, base, state.root.dataset.style);
|
|
591
|
+
state.styleObserver = observeAttributes(state.root, ['data-style'], function (string) {
|
|
592
|
+
updateStyles(state, base, string);
|
|
593
|
+
});
|
|
594
|
+
return {
|
|
595
|
+
setStyle: function setStyle(css) {
|
|
596
|
+
updateStyles(state, base, css);
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
var updateStyles = function updateStyles(state, base, css) {
|
|
601
|
+
if (state.lastAppliedStyles === css) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
state.lastAppliedStyles = css;
|
|
605
|
+
state.style = css ? mergeObjects(base, toStyles(css)) : base;
|
|
606
|
+
state.dirty = true;
|
|
607
|
+
};
|
|
608
|
+
var Views = {
|
|
609
|
+
text: function text$$1() {
|
|
610
|
+
return function (root) {
|
|
611
|
+
var state = {};
|
|
612
|
+
var draw = function draw(state) {
|
|
613
|
+
state.root.setAttribute('data-value', state.value);
|
|
614
|
+
text(state.root, state.value);
|
|
615
|
+
};
|
|
616
|
+
return Object.assign({}, rooter(state, root, 'text'), updater(state), drawer(state, draw), destroyer(state));
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
addExtensions(ExtensionType.VIEW, Views);
|
|
621
|
+
var API$2 = function API() {
|
|
622
|
+
return {
|
|
623
|
+
Extension: {
|
|
624
|
+
Type: ExtensionType,
|
|
625
|
+
getExtension: getExtension
|
|
626
|
+
},
|
|
627
|
+
Utils: {},
|
|
628
|
+
Canvas: {},
|
|
629
|
+
DOM: {
|
|
630
|
+
visible: isVisible,
|
|
631
|
+
create: create$1,
|
|
632
|
+
transform: setTransform
|
|
633
|
+
},
|
|
634
|
+
Animation: {},
|
|
635
|
+
Date: {
|
|
636
|
+
performance: now
|
|
637
|
+
},
|
|
638
|
+
View: {
|
|
639
|
+
rooter: rooter,
|
|
640
|
+
drawer: drawer,
|
|
641
|
+
updater: updater,
|
|
642
|
+
styler: styler,
|
|
643
|
+
grouper: grouper,
|
|
644
|
+
resizer: resizer,
|
|
645
|
+
destroyer: destroyer
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
};
|
|
649
|
+
var createPresenterRoot = function createPresenterRoot(root, definition, presentDefinition) {
|
|
650
|
+
return createRoot(root, definition, presentDefinition);
|
|
651
|
+
};
|
|
652
|
+
var createPresenterRepeater = function createPresenterRepeater(root, definition, presentDefinition) {
|
|
653
|
+
return createRepeater(root, definition, presentDefinition);
|
|
654
|
+
};
|
|
655
|
+
var createPresenterView = function createPresenterView(name, root, style) {
|
|
656
|
+
var view = getExtension(ExtensionType.VIEW, name);
|
|
657
|
+
return view ? view(API$2())(root, style) : null;
|
|
658
|
+
};
|
|
659
|
+
var arrow = function arrow(str, i) {
|
|
660
|
+
return str[i] === '-' && str[i + 1] === '>';
|
|
661
|
+
};
|
|
662
|
+
var string = function string(c) {
|
|
663
|
+
return c === "'" || c === '"';
|
|
664
|
+
};
|
|
665
|
+
var comma = function comma(c) {
|
|
666
|
+
return c === ',';
|
|
667
|
+
};
|
|
668
|
+
var opener = function opener(c) {
|
|
669
|
+
return c === '(';
|
|
670
|
+
};
|
|
671
|
+
var closer = function closer(c) {
|
|
672
|
+
return c === ')';
|
|
673
|
+
};
|
|
674
|
+
var value = function value(v) {
|
|
675
|
+
return v.trim().length !== 0;
|
|
676
|
+
};
|
|
677
|
+
var add = function add(r, v) {
|
|
678
|
+
return r.push(v.trim());
|
|
679
|
+
};
|
|
680
|
+
var token = function token(r, v) {
|
|
681
|
+
if (value(v)) {
|
|
682
|
+
add(r, v);
|
|
683
|
+
return '';
|
|
684
|
+
}
|
|
685
|
+
return v;
|
|
686
|
+
};
|
|
687
|
+
var chain = function chain(_chain, output) {
|
|
688
|
+
if (_chain.length) {
|
|
689
|
+
output.push(_chain.length > 1 ? _chain.concat() : _chain[0]);
|
|
690
|
+
}
|
|
691
|
+
return [];
|
|
692
|
+
};
|
|
693
|
+
var parse$1 = function parse(i, str, result) {
|
|
694
|
+
var v = '';
|
|
695
|
+
var fns = [];
|
|
696
|
+
var quote = null;
|
|
697
|
+
var hitArrow = false;
|
|
698
|
+
while (i < str.length) {
|
|
699
|
+
var c = str[i];
|
|
700
|
+
if (opener(c)) {
|
|
701
|
+
hitArrow = false;
|
|
702
|
+
var fn = [v.trim()];
|
|
703
|
+
i = parse(i + 1, str, fn);
|
|
704
|
+
c = str[i];
|
|
705
|
+
fns.push(fn);
|
|
706
|
+
v = '';
|
|
707
|
+
} else if (closer(c)) {
|
|
708
|
+
if (hitArrow && v.trim().length) {
|
|
709
|
+
fns.push([v.trim()]);
|
|
710
|
+
v = '';
|
|
711
|
+
hitArrow = false;
|
|
712
|
+
}
|
|
713
|
+
if (value(v)) {
|
|
714
|
+
add(fns, v);
|
|
715
|
+
}
|
|
716
|
+
fns = chain(fns, result);
|
|
717
|
+
return i + 1;
|
|
718
|
+
} else {
|
|
719
|
+
if (quote !== null && c !== quote) {
|
|
720
|
+
v += c;
|
|
721
|
+
} else if (c === quote) {
|
|
722
|
+
fns.push(v);
|
|
723
|
+
v = '';
|
|
724
|
+
quote = null;
|
|
725
|
+
} else if (string(c)) {
|
|
726
|
+
v = '';
|
|
727
|
+
quote = c;
|
|
728
|
+
} else {
|
|
729
|
+
if (arrow(str, i)) {
|
|
730
|
+
hitArrow = true;
|
|
731
|
+
if (v.trim().length) {
|
|
732
|
+
fns.push([v.trim()]);
|
|
733
|
+
v = '';
|
|
734
|
+
}
|
|
735
|
+
i += 2;
|
|
736
|
+
} else if (comma(c)) {
|
|
737
|
+
if (hitArrow && v.trim().length) {
|
|
738
|
+
fns.push([v.trim()]);
|
|
739
|
+
v = '';
|
|
740
|
+
hitArrow = false;
|
|
741
|
+
}
|
|
742
|
+
fns = chain(fns, result);
|
|
743
|
+
v = token(result, v);
|
|
744
|
+
} else {
|
|
745
|
+
v += c;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
i++;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
if (hitArrow && v.trim().length || !hitArrow && v.trim().length && !fns.length) {
|
|
752
|
+
fns.push([v.trim()]);
|
|
753
|
+
v = '';
|
|
754
|
+
}
|
|
755
|
+
chain(fns, result);
|
|
756
|
+
token(result, v);
|
|
757
|
+
return i;
|
|
758
|
+
};
|
|
759
|
+
var parseTransformChain = function parseTransformChain(string) {
|
|
760
|
+
var result = [];
|
|
761
|
+
parse$1(0, string, result);
|
|
762
|
+
return result;
|
|
763
|
+
};
|
|
764
|
+
var isRootDefinition = function isRootDefinition(definition) {
|
|
765
|
+
return definition.children && definition.children.length;
|
|
766
|
+
};
|
|
767
|
+
var cloneDefinition = function cloneDefinition(definition) {
|
|
768
|
+
var clone = {};
|
|
769
|
+
for (var key in definition) {
|
|
770
|
+
if (!definition.hasOwnProperty(key)) {
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
if (key === 'root') {
|
|
774
|
+
clone[key] = definition[key].cloneNode();
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
if (key === 'children') {
|
|
778
|
+
clone[key] = definition[key] === null ? null : definition[key].map(cloneDefinition);
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
if (key === 'repeat') {
|
|
782
|
+
clone[key] = definition[key] === null ? null : cloneDefinition(definition[key]);
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
clone[key] = definition[key];
|
|
786
|
+
}
|
|
787
|
+
clone.presenter = null;
|
|
788
|
+
return clone;
|
|
789
|
+
};
|
|
790
|
+
var definitionOutline = {
|
|
791
|
+
root: null,
|
|
792
|
+
key: null,
|
|
793
|
+
view: null,
|
|
794
|
+
overlay: null,
|
|
795
|
+
presenter: null,
|
|
796
|
+
transform: null,
|
|
797
|
+
layout: null,
|
|
798
|
+
style: null,
|
|
799
|
+
repeat: null,
|
|
800
|
+
children: null,
|
|
801
|
+
className: null
|
|
802
|
+
};
|
|
803
|
+
var toPresenterDefinitionTree = function toPresenterDefinitionTree(nodes) {
|
|
804
|
+
return Array.from(nodes).map(function (node) {
|
|
805
|
+
var definition = mergeObjects(definitionOutline, {
|
|
806
|
+
root: node
|
|
807
|
+
});
|
|
808
|
+
for (var key in node.dataset) {
|
|
809
|
+
if (!node.dataset.hasOwnProperty(key)) {
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
if (typeof definition[key] === 'undefined') {
|
|
813
|
+
continue;
|
|
814
|
+
}
|
|
815
|
+
definition[key] = node.dataset[key];
|
|
816
|
+
}
|
|
817
|
+
if (definition.repeat) {
|
|
818
|
+
definition.repeat = toPresenterDefinitionTree(node.children).pop();
|
|
819
|
+
Array.from(node.children).forEach(function (node) {
|
|
820
|
+
node.parentNode.removeChild(node);
|
|
821
|
+
});
|
|
822
|
+
} else if (node.children.length) {
|
|
823
|
+
definition.children = toPresenterDefinitionTree(node.children);
|
|
824
|
+
}
|
|
825
|
+
return definition;
|
|
826
|
+
});
|
|
827
|
+
};
|
|
828
|
+
var createDOMTreeForDefinition = function createDOMTreeForDefinition(definition) {
|
|
829
|
+
return definition.map(function (def) {
|
|
830
|
+
def = mergeObjects(definitionOutline, def);
|
|
831
|
+
if (typeof def.root === 'string') {
|
|
832
|
+
def.root = document.createElement(def.root);
|
|
833
|
+
} else {
|
|
834
|
+
def.root = document.createElement('span');
|
|
835
|
+
}
|
|
836
|
+
if (def.transform) {
|
|
837
|
+
def.root.dataset.transform = def.transform;
|
|
838
|
+
}
|
|
839
|
+
if (def.className) {
|
|
840
|
+
def.root.className = def.className;
|
|
841
|
+
}
|
|
842
|
+
if (def.overlay) {
|
|
843
|
+
def.root.dataset.overlay = def.overlay;
|
|
844
|
+
}
|
|
845
|
+
if (def.view) {
|
|
846
|
+
def.root.dataset.view = def.view;
|
|
847
|
+
if (def.style) {
|
|
848
|
+
def.root.dataset.style = def.style;
|
|
849
|
+
}
|
|
850
|
+
def.repeat = null;
|
|
851
|
+
} else {
|
|
852
|
+
if (def.layout) {
|
|
853
|
+
def.root.dataset.layout = def.layout;
|
|
854
|
+
}
|
|
855
|
+
if (def.repeat) {
|
|
856
|
+
def.root.dataset.repeat = true;
|
|
857
|
+
def.repeat = createDOMTreeForDefinition(def.children).pop();
|
|
858
|
+
} else if (def.children) {
|
|
859
|
+
def.children = createDOMTreeForDefinition(def.children);
|
|
860
|
+
def.children.forEach(function (child) {
|
|
861
|
+
def.root.appendChild(child.root);
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return def;
|
|
866
|
+
});
|
|
867
|
+
};
|
|
868
|
+
var createPresenterByDefinition = function createPresenterByDefinition(definition, presentDefinition) {
|
|
869
|
+
var presenter = void 0;
|
|
870
|
+
if (definition.repeat) {
|
|
871
|
+
presenter = createPresenterRepeater(definition.root, definition.repeat, presentDefinition);
|
|
872
|
+
} else if (typeof definition.view === 'string') {
|
|
873
|
+
presenter = createPresenterView(definition.view, definition.root, definition.style);
|
|
874
|
+
} else if (isRootDefinition(definition)) {
|
|
875
|
+
presenter = createPresenterRoot(definition.root, definition.children, presentDefinition);
|
|
876
|
+
}
|
|
877
|
+
return presenter;
|
|
878
|
+
};
|
|
879
|
+
var presentTick = function presentTick(instance) {
|
|
880
|
+
var isDrawing = false;
|
|
881
|
+
var update = function update(definition, value) {
|
|
882
|
+
definition.transform(value, function (output) {
|
|
883
|
+
definition.presenter.update(output);
|
|
884
|
+
}, instance);
|
|
885
|
+
if (!isDrawing) {
|
|
886
|
+
isDrawing = true;
|
|
887
|
+
draw();
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
var draw = function draw() {
|
|
891
|
+
instance.baseDefinition.presenter.draw();
|
|
892
|
+
requestAnimationFrame(draw);
|
|
893
|
+
};
|
|
894
|
+
var presentDefinition = function presentDefinition(definition) {
|
|
895
|
+
definition.presenter = createPresenterByDefinition(definition, presentDefinition);
|
|
896
|
+
definition.transform = toTransformComposition(definition.transform, instance);
|
|
897
|
+
return update;
|
|
898
|
+
};
|
|
899
|
+
return presentDefinition(instance.baseDefinition);
|
|
900
|
+
};
|
|
901
|
+
var composeAsync = function composeAsync(instance) {
|
|
902
|
+
for (var _len = arguments.length, funcs = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
903
|
+
funcs[_key - 1] = arguments[_key];
|
|
904
|
+
}
|
|
905
|
+
return function (initialValue, callback) {
|
|
906
|
+
function compose(i, value) {
|
|
907
|
+
if (funcs.length <= i) {
|
|
908
|
+
callback(value);
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
funcs[i](value, partial(compose, [i + 1]), instance);
|
|
912
|
+
}
|
|
913
|
+
compose(0, initialValue);
|
|
914
|
+
};
|
|
915
|
+
};
|
|
916
|
+
var partial = function partial(fn) {
|
|
917
|
+
var initialArgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
918
|
+
var ctx = arguments[2];
|
|
919
|
+
return function () {
|
|
920
|
+
var args = Array.from(initialArgs);
|
|
921
|
+
Array.prototype.push.apply(args, arguments);
|
|
922
|
+
return fn.apply(ctx, args);
|
|
923
|
+
};
|
|
924
|
+
};
|
|
925
|
+
var toTransformComposition = function toTransformComposition(string, instance) {
|
|
926
|
+
if (!string) {
|
|
927
|
+
return function (value, cb) {
|
|
928
|
+
return cb(value);
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
if (typeof string === 'function') {
|
|
932
|
+
return string;
|
|
933
|
+
}
|
|
934
|
+
var result = parseTransformChain('transform(' + (/^[a-z]+$/.test(string) ? string + '()' : string) + ')');
|
|
935
|
+
return compose(result, instance);
|
|
936
|
+
};
|
|
937
|
+
var compose = function compose(chain, instance) {
|
|
938
|
+
var composition = chain.map(function (item) {
|
|
939
|
+
var name = item.shift();
|
|
940
|
+
var func = getExtension(ExtensionType.TRANSFORM, name) || function (value, cb, instance) {
|
|
941
|
+
cb(value);
|
|
942
|
+
};
|
|
943
|
+
var params = item.map(function (parameter) {
|
|
944
|
+
if (Array.isArray(parameter)) {
|
|
945
|
+
if (typeof parameter[0] === 'string') {
|
|
946
|
+
return compose([parameter], instance);
|
|
947
|
+
}
|
|
948
|
+
return compose(parameter, instance);
|
|
949
|
+
}
|
|
950
|
+
return toParameter(parameter);
|
|
951
|
+
});
|
|
952
|
+
return func.apply(undefined, toConsumableArray(params));
|
|
953
|
+
});
|
|
954
|
+
return composeAsync.apply(undefined, [instance].concat(toConsumableArray(composition)));
|
|
955
|
+
};
|
|
956
|
+
var toFunctionOutline = function toFunctionOutline(string) {
|
|
957
|
+
var name = string.match(/[a-z]+/)[0];
|
|
958
|
+
var parameters = toParameters(string.substring(name.length));
|
|
959
|
+
return {
|
|
960
|
+
name: name,
|
|
961
|
+
parameters: parameters
|
|
962
|
+
};
|
|
963
|
+
};
|
|
964
|
+
var toParameters = function toParameters(string) {
|
|
965
|
+
var arr = string.match(/('.+?')|(".+?")|(\[.+?])|([.:\-\d\sa-zA-Z]+%?)/g) || [];
|
|
966
|
+
arr.map(trim).filter(function (str) {
|
|
967
|
+
return str.length;
|
|
968
|
+
}).map(toParameter);
|
|
969
|
+
};
|
|
970
|
+
var trimEdges = function trimEdges(string) {
|
|
971
|
+
return string.substring(1, string.length - 1);
|
|
972
|
+
};
|
|
973
|
+
var isProbablyISODate = /^([\d]{4}-[\d]{1,2}-[\d]{1,2})/;
|
|
974
|
+
var isBoolean = /^(true|false)$/;
|
|
975
|
+
var isString = /^[\a-zA-Z]+$/;
|
|
976
|
+
var isZeroString = /^0[\d]+/;
|
|
977
|
+
var isQuotedString = /^('|")/;
|
|
978
|
+
var isNumber = /^-?(?:\d+)?(?:\.|0\.)?[\d]+$/;
|
|
979
|
+
var isArray = /^(\[)/;
|
|
980
|
+
var toParameter = function toParameter(string) {
|
|
981
|
+
if (isBoolean.test(string)) {
|
|
982
|
+
return string === 'true';
|
|
983
|
+
}
|
|
984
|
+
if (isArray.test(string)) {
|
|
985
|
+
return toParameters(trimEdges(string));
|
|
986
|
+
}
|
|
987
|
+
if (isProbablyISODate.test(string)) {
|
|
988
|
+
return dateFromISO(string);
|
|
989
|
+
}
|
|
990
|
+
if (isQuotedString.test(string)) {
|
|
991
|
+
return trimEdges(string);
|
|
992
|
+
}
|
|
993
|
+
if (isString.test(string) || isZeroString.test(string)) {
|
|
994
|
+
return string;
|
|
995
|
+
}
|
|
996
|
+
if (isNumber.test(string)) {
|
|
997
|
+
return parseFloat(string);
|
|
998
|
+
}
|
|
999
|
+
return string;
|
|
1000
|
+
};
|
|
1001
|
+
var toCSSValue = function toCSSValue(value) {
|
|
1002
|
+
var parts = (value + '').match(/(-?[.\d]+)(%|ms|s|deg|cm|em|ch|ex|q|in|mm|pc|pt|px|vh|vw|vmin|vmax)?/);
|
|
1003
|
+
return {
|
|
1004
|
+
value: parseFloat(parts[1]),
|
|
1005
|
+
units: parts[2]
|
|
1006
|
+
};
|
|
1007
|
+
};
|
|
1008
|
+
var mergeObjects = function mergeObjects(a) {
|
|
1009
|
+
var b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1010
|
+
var key = void 0;
|
|
1011
|
+
var obj = {};
|
|
1012
|
+
for (key in a) {
|
|
1013
|
+
if (!a.hasOwnProperty(key)) {
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
obj[key] = typeof b[key] === 'undefined' ? a[key] : b[key];
|
|
1017
|
+
}
|
|
1018
|
+
return obj;
|
|
1019
|
+
};
|
|
1020
|
+
var toFunctionReference = function toFunctionReference(string) {
|
|
1021
|
+
var ref = window;
|
|
1022
|
+
var levels = string.split('.');
|
|
1023
|
+
levels.forEach(function (level, index) {
|
|
1024
|
+
if (!ref[levels[index]]) {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
ref = ref[levels[index]];
|
|
1028
|
+
});
|
|
1029
|
+
return ref !== window ? ref : null;
|
|
1030
|
+
};
|
|
1031
|
+
var toValue = function toValue(string) {
|
|
1032
|
+
if (/^(?:[\w]+\s?:\s?[\w.]+,\s?)+(?:[\w]+\s?:\s?[\w.]+)$/g.test(string)) {
|
|
1033
|
+
return string.match(/(?:(\w+)\s?:\s?([\w.]+))/g).reduce(function (obj, current) {
|
|
1034
|
+
var parts = current.split(':');
|
|
1035
|
+
obj[parts[0]] = toParameter(parts[1]);
|
|
1036
|
+
return obj;
|
|
1037
|
+
}, {});
|
|
1038
|
+
}
|
|
1039
|
+
return toParameter(string);
|
|
1040
|
+
};
|
|
1041
|
+
var toInt = function toInt(value) {
|
|
1042
|
+
return parseInt(value, 10);
|
|
1043
|
+
};
|
|
1044
|
+
var trim = function trim(string) {
|
|
1045
|
+
return string.trim();
|
|
1046
|
+
};
|
|
1047
|
+
var capitalizeFirstLetter = function capitalizeFirstLetter(string) {
|
|
1048
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1049
|
+
};
|
|
1050
|
+
var dashesToCamels = function dashesToCamels(string) {
|
|
1051
|
+
return string.replace(/-./g, function (sub) {
|
|
1052
|
+
return sub.charAt(1).toUpperCase();
|
|
1053
|
+
});
|
|
1054
|
+
};
|
|
1055
|
+
var clone = function clone(obj) {
|
|
1056
|
+
if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null) {
|
|
1057
|
+
return util/* default */.Z.parseJSON(util/* default */.Z.stringify(obj));
|
|
1058
|
+
}
|
|
1059
|
+
return obj;
|
|
1060
|
+
};
|
|
1061
|
+
var copyArray = function copyArray(arr) {
|
|
1062
|
+
return arr.slice();
|
|
1063
|
+
};
|
|
1064
|
+
var now = function now() {
|
|
1065
|
+
return window.performance.now();
|
|
1066
|
+
};
|
|
1067
|
+
var equal = function equal(a, b) {
|
|
1068
|
+
if (isObject(a)) {
|
|
1069
|
+
return equalObjects(a, b);
|
|
1070
|
+
}
|
|
1071
|
+
if (Array.isArray(a)) {
|
|
1072
|
+
return equalArrays(a, b);
|
|
1073
|
+
}
|
|
1074
|
+
return a === b;
|
|
1075
|
+
};
|
|
1076
|
+
var isObject = function isObject(obj) {
|
|
1077
|
+
return obj === Object(obj);
|
|
1078
|
+
};
|
|
1079
|
+
var equalObjects = function equalObjects(a, b) {
|
|
1080
|
+
for (var i in a) {
|
|
1081
|
+
if (!b.hasOwnProperty(i) || a[i] !== b[i]) {
|
|
1082
|
+
return false;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return true;
|
|
1086
|
+
};
|
|
1087
|
+
var equalArrays = function equalArrays(a, b) {
|
|
1088
|
+
return a.length == b.length && a.every(function (v, i) {
|
|
1089
|
+
return v === b[i];
|
|
1090
|
+
});
|
|
1091
|
+
};
|
|
1092
|
+
var keysToList = function keysToList(obj) {
|
|
1093
|
+
return Object.keys(obj).map(function (k) {
|
|
1094
|
+
return '"' + k + '"';
|
|
1095
|
+
}).join(', ');
|
|
1096
|
+
};
|
|
1097
|
+
var Tick = function () {
|
|
1098
|
+
function Tick() {
|
|
1099
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1100
|
+
var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.createElement('div');
|
|
1101
|
+
classCallCheck(this, Tick);
|
|
1102
|
+
this._options = mergeObjects(Tick.options(), options);
|
|
1103
|
+
this._element = element;
|
|
1104
|
+
this._value = null;
|
|
1105
|
+
this._observer = null;
|
|
1106
|
+
this._viewDefinition = null;
|
|
1107
|
+
this._updater = null;
|
|
1108
|
+
this._didInit = null;
|
|
1109
|
+
this._didDestroy = null;
|
|
1110
|
+
this._willDestroy = null;
|
|
1111
|
+
this._didUpdate = null;
|
|
1112
|
+
this._init();
|
|
1113
|
+
}
|
|
1114
|
+
createClass(Tick, [{
|
|
1115
|
+
key: 'isRootElement',
|
|
1116
|
+
value: function isRootElement(element) {
|
|
1117
|
+
return this._element === element;
|
|
1118
|
+
}
|
|
1119
|
+
}, {
|
|
1120
|
+
key: 'destroy',
|
|
1121
|
+
value: function destroy$$1() {
|
|
1122
|
+
this._willDestroy(this);
|
|
1123
|
+
this._observer.disconnect();
|
|
1124
|
+
this.baseDefinition.presenter.destroy();
|
|
1125
|
+
this._didDestroy(this);
|
|
1126
|
+
}
|
|
1127
|
+
}, {
|
|
1128
|
+
key: 'redraw',
|
|
1129
|
+
value: function redraw() {
|
|
1130
|
+
if (!this.baseDefinition || !this.baseDefinition.presenter) return;
|
|
1131
|
+
this.baseDefinition.presenter.reset();
|
|
1132
|
+
this.baseDefinition.presenter.draw();
|
|
1133
|
+
this._updater(this.baseDefinition, this._value);
|
|
1134
|
+
}
|
|
1135
|
+
}, {
|
|
1136
|
+
key: '_init',
|
|
1137
|
+
value: function _init() {
|
|
1138
|
+
var _this = this;
|
|
1139
|
+
this._viewDefinition = this._options.view;
|
|
1140
|
+
this._willDestroy = this._options.willDestroy;
|
|
1141
|
+
this._didDestroy = this._options.didDestroy;
|
|
1142
|
+
this._didInit = this._options.didInit;
|
|
1143
|
+
this._didUpdate = this._options.didUpdate;
|
|
1144
|
+
this._value = this._options.value;
|
|
1145
|
+
if (!this._element.classList.contains('tick')) {
|
|
1146
|
+
this._element.classList.add('tick');
|
|
1147
|
+
}
|
|
1148
|
+
this._observer = observeAttributes(this._element, ['data-value'], function (value) {
|
|
1149
|
+
_this.value = value;
|
|
1150
|
+
});
|
|
1151
|
+
if (this._viewDefinition.root !== this._element) {
|
|
1152
|
+
Array.from(this._viewDefinition.root.children).forEach(function (node) {
|
|
1153
|
+
_this._element.appendChild(node);
|
|
1154
|
+
});
|
|
1155
|
+
this._viewDefinition.root = this._element;
|
|
1156
|
+
}
|
|
1157
|
+
if (!this._viewDefinition.view && !this._viewDefinition.children) {
|
|
1158
|
+
this._viewDefinition.view = 'text';
|
|
1159
|
+
}
|
|
1160
|
+
this._updater = presentTick(this);
|
|
1161
|
+
if (this.value !== null) {
|
|
1162
|
+
this._update(this.value);
|
|
1163
|
+
}
|
|
1164
|
+
this._element.dataset.state = 'initialised';
|
|
1165
|
+
this._didInit(this, this.value);
|
|
1166
|
+
}
|
|
1167
|
+
}, {
|
|
1168
|
+
key: '_update',
|
|
1169
|
+
value: function _update(value) {
|
|
1170
|
+
this._updater(this.baseDefinition, value);
|
|
1171
|
+
this._didUpdate(this, value);
|
|
1172
|
+
}
|
|
1173
|
+
}, {
|
|
1174
|
+
key: 'baseDefinition',
|
|
1175
|
+
get: function get$$1() {
|
|
1176
|
+
return this._viewDefinition;
|
|
1177
|
+
}
|
|
1178
|
+
}, {
|
|
1179
|
+
key: 'root',
|
|
1180
|
+
get: function get$$1() {
|
|
1181
|
+
return this._element;
|
|
1182
|
+
}
|
|
1183
|
+
}, {
|
|
1184
|
+
key: 'value',
|
|
1185
|
+
get: function get$$1() {
|
|
1186
|
+
return this._value;
|
|
1187
|
+
},
|
|
1188
|
+
set: function set$$1(value) {
|
|
1189
|
+
this._value = typeof value === 'string' ? toValue(value) : value;
|
|
1190
|
+
this._update(value);
|
|
1191
|
+
}
|
|
1192
|
+
}], [{
|
|
1193
|
+
key: 'options',
|
|
1194
|
+
value: function options() {
|
|
1195
|
+
return {
|
|
1196
|
+
value: null,
|
|
1197
|
+
view: null,
|
|
1198
|
+
didInit: function didInit(tick) {},
|
|
1199
|
+
didUpdate: function didUpdate(tick, value) {},
|
|
1200
|
+
willDestroy: function willDestroy(tick) {},
|
|
1201
|
+
didDestroy: function didDestroy(tick) {}
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
}]);
|
|
1205
|
+
return Tick;
|
|
1206
|
+
}();
|
|
1207
|
+
var instances = [];
|
|
1208
|
+
var attributes = {
|
|
1209
|
+
value: toValue,
|
|
1210
|
+
didInit: toFunctionReference,
|
|
1211
|
+
didUpdate: toFunctionReference,
|
|
1212
|
+
didDestroy: toFunctionReference,
|
|
1213
|
+
willDestroy: toFunctionReference
|
|
1214
|
+
};
|
|
1215
|
+
var getOptionsFromAttributes = function getOptionsFromAttributes(element) {
|
|
1216
|
+
var transfomers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1217
|
+
var defaults$$1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1218
|
+
var dataset = element.dataset;
|
|
1219
|
+
var options = {
|
|
1220
|
+
meta: {}
|
|
1221
|
+
};
|
|
1222
|
+
for (var prop in dataset) {
|
|
1223
|
+
if (!dataset.hasOwnProperty(prop)) {
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
var valueTransformer = transfomers[prop];
|
|
1227
|
+
var value = dataset[prop];
|
|
1228
|
+
if (valueTransformer) {
|
|
1229
|
+
value = valueTransformer(value);
|
|
1230
|
+
value = value === null ? clone(defaults$$1[prop]) : value;
|
|
1231
|
+
options[prop] = value;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
return options;
|
|
1235
|
+
};
|
|
1236
|
+
var indexOfElement = function indexOfElement(instances, element) {
|
|
1237
|
+
var i = 0;
|
|
1238
|
+
var l = instances.length;
|
|
1239
|
+
for (; i < l; i++) {
|
|
1240
|
+
if (instances[i].isRootElement(element)) {
|
|
1241
|
+
return i;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
return -1;
|
|
1245
|
+
};
|
|
1246
|
+
var parse = function parse(context) {
|
|
1247
|
+
var elements = void 0;
|
|
1248
|
+
var element = void 0;
|
|
1249
|
+
var i = void 0;
|
|
1250
|
+
var instances = [];
|
|
1251
|
+
elements = context.querySelectorAll('.tick:not([data-state])');
|
|
1252
|
+
i = elements.length;
|
|
1253
|
+
while (i--) {
|
|
1254
|
+
element = elements[i];
|
|
1255
|
+
instances.push(create(element));
|
|
1256
|
+
}
|
|
1257
|
+
return instances;
|
|
1258
|
+
};
|
|
1259
|
+
var find = function find(element) {
|
|
1260
|
+
var result = instances.filter(function (instance) {
|
|
1261
|
+
return instance.isRootElement(element);
|
|
1262
|
+
});
|
|
1263
|
+
return result ? result[0] : null;
|
|
1264
|
+
};
|
|
1265
|
+
var getDefaultOptions = function getDefaultOptions() {
|
|
1266
|
+
return _extends({}, Tick.options());
|
|
1267
|
+
};
|
|
1268
|
+
var create = function create() {
|
|
1269
|
+
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
|
|
1270
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
1271
|
+
if (element && !isHTMLElement(element)) {
|
|
1272
|
+
options = element;
|
|
1273
|
+
element = undefined;
|
|
1274
|
+
}
|
|
1275
|
+
if (element && find(element)) {
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
if (options && options.view) {
|
|
1279
|
+
options.view = createDOMTreeForDefinition([options.view])[0];
|
|
1280
|
+
}
|
|
1281
|
+
if (!options && element) {
|
|
1282
|
+
options = getOptionsFromAttributes(element, attributes, getDefaultOptions());
|
|
1283
|
+
}
|
|
1284
|
+
if (element) {
|
|
1285
|
+
if (!options) {
|
|
1286
|
+
options = {};
|
|
1287
|
+
}
|
|
1288
|
+
if (!options.view) {
|
|
1289
|
+
options.view = toPresenterDefinitionTree([element])[0];
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
var instance = new Tick(options, element);
|
|
1293
|
+
instances.push(instance);
|
|
1294
|
+
return instance;
|
|
1295
|
+
};
|
|
1296
|
+
var destroy = function destroy(element) {
|
|
1297
|
+
var index = indexOfElement(instances, element);
|
|
1298
|
+
if (index < 0) return false;
|
|
1299
|
+
instances[index].destroy();
|
|
1300
|
+
instances.splice(index, 1);
|
|
1301
|
+
return true;
|
|
1302
|
+
};
|
|
1303
|
+
var support = function () {
|
|
1304
|
+
var w = window;
|
|
1305
|
+
if (typeof w === 'undefined') {
|
|
1306
|
+
return false;
|
|
1307
|
+
}
|
|
1308
|
+
var canSupport = w.CSS && w.CSS.supports;
|
|
1309
|
+
var isIE11 = !!w.MSInputMethodContext && !!document.documentMode;
|
|
1310
|
+
var canTransform = canSupport && CSS.supports('transform', 'translateX(0)');
|
|
1311
|
+
var features = ['MutationObserver', 'requestAnimationFrame'];
|
|
1312
|
+
return isIE11 || canSupport && canTransform && !!features.filter(function (p) {
|
|
1313
|
+
return p in w;
|
|
1314
|
+
}).length;
|
|
1315
|
+
};
|
|
1316
|
+
var API = {
|
|
1317
|
+
supported: support(),
|
|
1318
|
+
options: {},
|
|
1319
|
+
DOM: {
|
|
1320
|
+
create: create,
|
|
1321
|
+
destroy: destroy,
|
|
1322
|
+
parse: parse,
|
|
1323
|
+
find: find
|
|
1324
|
+
},
|
|
1325
|
+
plugin: {
|
|
1326
|
+
add: function add(type, name, fn) {
|
|
1327
|
+
if (typeof type === 'function') {
|
|
1328
|
+
var extension = type;
|
|
1329
|
+
return addExtension(extension.identifier.type, extension.identifier.name, extension);
|
|
1330
|
+
}
|
|
1331
|
+
return addExtension(type, name, fn);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1335
|
+
var _loop = function _loop(type) {
|
|
1336
|
+
if (!ExtensionType.hasOwnProperty(type)) return 'continue';
|
|
1337
|
+
API.plugin[dashesToCamels('add-' + ExtensionType[type])] = function (name, fn) {
|
|
1338
|
+
addExtension(ExtensionType[type], name, fn);
|
|
1339
|
+
};
|
|
1340
|
+
};
|
|
1341
|
+
for (var type in ExtensionType) {
|
|
1342
|
+
var _ret = _loop(type);
|
|
1343
|
+
if (_ret === 'continue') continue;
|
|
1344
|
+
}
|
|
1345
|
+
module.exports = API;
|
|
1346
|
+
return module.exports;
|
|
1347
|
+
}();
|
|
1348
|
+
/* harmony default export */ const tick_core_commonjs = (obj);
|
|
1349
|
+
// EXTERNAL MODULE: ./src/popup/tick.view.flip.commonjs.js
|
|
1350
|
+
var tick_view_flip_commonjs = __webpack_require__(9980);
|
|
1351
|
+
var tick_view_flip_commonjs_default = /*#__PURE__*/__webpack_require__.n(tick_view_flip_commonjs);
|
|
1352
|
+
// EXTERNAL MODULE: ./node_modules/preact/dist/preact.module.js
|
|
1353
|
+
var preact_module = __webpack_require__(6400);
|
|
1354
|
+
;// CONCATENATED MODULE: ./src/popup/countdown.js
|
|
1355
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1356
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1357
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
tick_core_commonjs.plugin.add((tick_view_flip_commonjs_default()));
|
|
1363
|
+
|
|
1364
|
+
class Countdown extends common/* Com */.up {
|
|
1365
|
+
constructor(props) {
|
|
1366
|
+
super(props);
|
|
1367
|
+
_defineProperty(this, "state", {
|
|
1368
|
+
flipKey: '43'
|
|
1369
|
+
});
|
|
1370
|
+
this.timer = util/* default */.Z.setInterval(() => {
|
|
1371
|
+
if (this.props._destroy) return this.componentWillUnmount();
|
|
1372
|
+
let cd = this.props.com.countdown || {};
|
|
1373
|
+
let newFlipKey = 'cd' + ':' + cd.skin + ':' + cd.size + ':' + this.props.plugin.popup.font_family + ':';
|
|
1374
|
+
if (this.state.flipKey !== newFlipKey) this.setState({
|
|
1375
|
+
flipKey: newFlipKey
|
|
1376
|
+
});
|
|
1377
|
+
this.forceUpdate();
|
|
1378
|
+
}, 500);
|
|
1379
|
+
}
|
|
1380
|
+
componentWillUnmount() {
|
|
1381
|
+
util/* default */.Z.clearInterval(this.timer);
|
|
1382
|
+
}
|
|
1383
|
+
getCountDownDeltaSec(countdown) {
|
|
1384
|
+
let dest;
|
|
1385
|
+
if (countdown.expire_time_type === 'fixed_time') dest = countdown.fixed_time;
|
|
1386
|
+
if (countdown.expire_time_type === 'visit_time') dest = this.props.store.pageLoaded() + countdown.visit_time * 60000;
|
|
1387
|
+
if (countdown.expire_time_type === 'repeat_daily') {
|
|
1388
|
+
var start = new util/* default */.Z.Date();
|
|
1389
|
+
start.setHours(0, 0, 0, 0);
|
|
1390
|
+
dest = start.getTime() + countdown.repeat_daily * 60000;
|
|
1391
|
+
}
|
|
1392
|
+
if (countdown.expire_time_type === 'repeat_weekly') {
|
|
1393
|
+
let daytill = 0;
|
|
1394
|
+
let todayweekday = new util/* default */.Z.Date().getDay();
|
|
1395
|
+
if (todayweekday === 0) {
|
|
1396
|
+
if (countdown.repeat_weekly_weekday === 'sunday') {
|
|
1397
|
+
daytill = 0;
|
|
1398
|
+
} else {
|
|
1399
|
+
daytill = 7 - new util/* default */.Z.Date().getDay();
|
|
1400
|
+
}
|
|
1401
|
+
} else {
|
|
1402
|
+
if (countdown.repeat_weekly_weekday === 'sunday') {
|
|
1403
|
+
daytill = 7 - todayweekday;
|
|
1404
|
+
} else {
|
|
1405
|
+
daytill = WEEKDAY_INDEX[countdown.repeat_weekly_weekday] - todayweekday;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
if (daytill < 0) delta = 0;else if (daytill == 0) {
|
|
1409
|
+
var start = new util/* default */.Z.Date();
|
|
1410
|
+
start.setHours(0, 0, 0, 0);
|
|
1411
|
+
dest = start.getTime() + countdown.repeat_weekly_min * 60000;
|
|
1412
|
+
} else {
|
|
1413
|
+
var start = new util/* default */.Z.Date();
|
|
1414
|
+
start.setHours(0, 0, 0, 0);
|
|
1415
|
+
dest = start.getTime() + countdown.repeat_weekly_min * 60000 + daytill * 86400000;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
let delta = dest - util/* default */.Z.Date.now();
|
|
1419
|
+
if (delta < 0) delta = 0;
|
|
1420
|
+
return Math.floor(delta / 1000) || 0;
|
|
1421
|
+
}
|
|
1422
|
+
renderElectricCountdown(day, hour0, hour1, min0, min1, sec0, sec1) {
|
|
1423
|
+
let fs = '28px';
|
|
1424
|
+
if (this.props.com.countdown.size === 'sm') fs = '20px';
|
|
1425
|
+
if (this.props.com.countdown.size === 'lg') fs = '40px';
|
|
1426
|
+
return (0,preact_module.h)("div", {
|
|
1427
|
+
class: "countdown_electric"
|
|
1428
|
+
}, (0,preact_module.h)("div", {
|
|
1429
|
+
class: "countdown_electric_group"
|
|
1430
|
+
}, (0,preact_module.h)("div", {
|
|
1431
|
+
class: "countdown_electric_label"
|
|
1432
|
+
}, this.props.t('hour')), (0,preact_module.h)("div", {
|
|
1433
|
+
class: "countdown_electric_numbers"
|
|
1434
|
+
}, (0,preact_module.h)("div", {
|
|
1435
|
+
class: "countdown_electric_number",
|
|
1436
|
+
style: util/* default */.Z.js2css({
|
|
1437
|
+
font_size: fs,
|
|
1438
|
+
font_family: this.props.plugin.popup.font_family
|
|
1439
|
+
})
|
|
1440
|
+
}, hour0), (0,preact_module.h)("div", {
|
|
1441
|
+
class: "countdown_electric_number",
|
|
1442
|
+
style: util/* default */.Z.js2css({
|
|
1443
|
+
font_size: fs,
|
|
1444
|
+
font_family: this.props.plugin.popup.font_family
|
|
1445
|
+
})
|
|
1446
|
+
}, hour1))), (0,preact_module.h)("div", {
|
|
1447
|
+
class: "countdown_electric_group"
|
|
1448
|
+
}, (0,preact_module.h)("div", {
|
|
1449
|
+
class: "countdown_electric_label"
|
|
1450
|
+
}, this.props.t('min')), (0,preact_module.h)("div", {
|
|
1451
|
+
class: "countdown_electric_numbers"
|
|
1452
|
+
}, (0,preact_module.h)("div", {
|
|
1453
|
+
class: "countdown_electric_number",
|
|
1454
|
+
style: util/* default */.Z.js2css({
|
|
1455
|
+
font_size: fs,
|
|
1456
|
+
font_family: this.props.plugin.popup.font_family
|
|
1457
|
+
})
|
|
1458
|
+
}, min0), (0,preact_module.h)("div", {
|
|
1459
|
+
class: "countdown_electric_number",
|
|
1460
|
+
style: util/* default */.Z.js2css({
|
|
1461
|
+
font_size: fs,
|
|
1462
|
+
font_family: this.props.plugin.popup.font_family
|
|
1463
|
+
})
|
|
1464
|
+
}, min1))), (0,preact_module.h)("div", {
|
|
1465
|
+
class: "countdown_electric_group"
|
|
1466
|
+
}, (0,preact_module.h)("div", {
|
|
1467
|
+
class: "countdown_electric_label"
|
|
1468
|
+
}, this.props.t('sec')), (0,preact_module.h)("div", {
|
|
1469
|
+
class: "countdown_electric_numbers"
|
|
1470
|
+
}, (0,preact_module.h)("div", {
|
|
1471
|
+
class: "countdown_electric_number",
|
|
1472
|
+
style: util/* default */.Z.js2css({
|
|
1473
|
+
font_size: fs,
|
|
1474
|
+
font_family: this.props.plugin.popup.font_family
|
|
1475
|
+
})
|
|
1476
|
+
}, sec0), (0,preact_module.h)("div", {
|
|
1477
|
+
class: "countdown_electric_number",
|
|
1478
|
+
style: util/* default */.Z.js2css({
|
|
1479
|
+
font_size: fs,
|
|
1480
|
+
font_family: this.props.plugin.popup.font_family
|
|
1481
|
+
})
|
|
1482
|
+
}, sec1))));
|
|
1483
|
+
}
|
|
1484
|
+
renderFlipCountdown(day, hour0, hour1, min0, min1, sec0, sec1) {
|
|
1485
|
+
let $day = null;
|
|
1486
|
+
if (day > 99) day = 99;
|
|
1487
|
+
if (day > 0) {
|
|
1488
|
+
let day0 = Math.floor(day / 10) + '';
|
|
1489
|
+
let day1 = day % 10 + '';
|
|
1490
|
+
$day = (0,preact_module.h)("div", {
|
|
1491
|
+
class: "countdown_group"
|
|
1492
|
+
}, (0,preact_module.h)(Flip, {
|
|
1493
|
+
key: this.state.flipKey + 4,
|
|
1494
|
+
value: day0 + '' + day1,
|
|
1495
|
+
plugin: this.props.plugin,
|
|
1496
|
+
com: this.props.com
|
|
1497
|
+
}), (0,preact_module.h)("div", {
|
|
1498
|
+
class: "countdown_label"
|
|
1499
|
+
}, this.props.t('day')));
|
|
1500
|
+
}
|
|
1501
|
+
return (0,preact_module.h)("div", {
|
|
1502
|
+
class: "countdown"
|
|
1503
|
+
}, $day, (0,preact_module.h)("div", {
|
|
1504
|
+
class: "countdown_group"
|
|
1505
|
+
}, (0,preact_module.h)(Flip, {
|
|
1506
|
+
key: this.state.flipKey + 1,
|
|
1507
|
+
value: hour0 + '' + hour1,
|
|
1508
|
+
plugin: this.props.plugin,
|
|
1509
|
+
com: this.props.com
|
|
1510
|
+
}), (0,preact_module.h)("div", {
|
|
1511
|
+
class: "countdown_label"
|
|
1512
|
+
}, this.props.t('hour'))), (0,preact_module.h)("div", {
|
|
1513
|
+
class: "countdown_group"
|
|
1514
|
+
}, (0,preact_module.h)(Flip, {
|
|
1515
|
+
key: this.state.flipKey + 2,
|
|
1516
|
+
value: min0 + '' + min1,
|
|
1517
|
+
plugin: this.props.plugin,
|
|
1518
|
+
com: this.props.com
|
|
1519
|
+
}), (0,preact_module.h)("div", {
|
|
1520
|
+
class: "countdown_label"
|
|
1521
|
+
}, this.props.t('min'))), (0,preact_module.h)("div", {
|
|
1522
|
+
class: "countdown_group"
|
|
1523
|
+
}, (0,preact_module.h)(Flip, {
|
|
1524
|
+
key: this.state.flipKey + 3,
|
|
1525
|
+
value: sec0 + '' + sec1,
|
|
1526
|
+
plugin: this.props.plugin,
|
|
1527
|
+
com: this.props.com
|
|
1528
|
+
}), (0,preact_module.h)("div", {
|
|
1529
|
+
class: "countdown_label"
|
|
1530
|
+
}, this.props.t('sec'))));
|
|
1531
|
+
}
|
|
1532
|
+
render() {
|
|
1533
|
+
let delta = this.getCountDownDeltaSec(this.props.com.countdown);
|
|
1534
|
+
let day = Math.floor(delta / 86400);
|
|
1535
|
+
let hour = Math.floor((delta - day * 86400) / 3600);
|
|
1536
|
+
let min = Math.floor((delta - day * 86400 - hour * 3600) / 60);
|
|
1537
|
+
let sec = delta - day * 86400 - hour * 3600 - min * 60;
|
|
1538
|
+
let sec0 = Math.floor(sec / 10) + '';
|
|
1539
|
+
let sec1 = sec % 10 + '';
|
|
1540
|
+
let min0 = Math.floor(min / 10) + '';
|
|
1541
|
+
let min1 = min % 10 + '';
|
|
1542
|
+
let hour0 = Math.floor(hour / 10) + '';
|
|
1543
|
+
let hour1 = hour % 10 + '';
|
|
1544
|
+
if (this.props.com.countdown.skin === 'electric') {
|
|
1545
|
+
return this.renderElectricCountdown(day, hour0, hour1, min0, min1, sec0, sec1);
|
|
1546
|
+
}
|
|
1547
|
+
return this.renderFlipCountdown(day, hour0, hour1, min0, min1, sec0, sec1);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
const WEEKDAY_INDEX = {
|
|
1551
|
+
sunday: 0,
|
|
1552
|
+
monday: 1,
|
|
1553
|
+
tuesday: 2,
|
|
1554
|
+
wednesday: 3,
|
|
1555
|
+
thursday: 4,
|
|
1556
|
+
friday: 5,
|
|
1557
|
+
saturday: 6
|
|
1558
|
+
};
|
|
1559
|
+
class Flip extends common/* Com */.up {
|
|
1560
|
+
constructor(props) {
|
|
1561
|
+
super(props);
|
|
1562
|
+
this._tickRef = (0,preact_module/* createRef */.Vf)();
|
|
1563
|
+
}
|
|
1564
|
+
componentDidMount() {
|
|
1565
|
+
this._tickInstance = tick_core_commonjs.DOM.create(this._tickRef.current, {
|
|
1566
|
+
value: this.props.value
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
componentDidUpdate() {
|
|
1570
|
+
if (!this._tickInstance) return;
|
|
1571
|
+
this._tickInstance.value = this.props.value;
|
|
1572
|
+
}
|
|
1573
|
+
componentWillUnmount() {
|
|
1574
|
+
if (!this._tickInstance) return;
|
|
1575
|
+
tick_core_commonjs.DOM.destroy(this._tickRef.current);
|
|
1576
|
+
}
|
|
1577
|
+
render() {
|
|
1578
|
+
let fs = '28px';
|
|
1579
|
+
if (this.props.com.countdown.size === 'sm') fs = '20px';
|
|
1580
|
+
if (this.props.com.countdown.size === 'lg') fs = '40px';
|
|
1581
|
+
return (0,preact_module.h)("div", {
|
|
1582
|
+
ref: this._tickRef,
|
|
1583
|
+
class: "tick"
|
|
1584
|
+
}, (0,preact_module.h)("div", {
|
|
1585
|
+
"data-repeat": "true",
|
|
1586
|
+
"aria-hidden": "true"
|
|
1587
|
+
}, (0,preact_module.h)("span", {
|
|
1588
|
+
"data-view": "flip",
|
|
1589
|
+
style: util/* default */.Z.js2css({
|
|
1590
|
+
font_size: fs,
|
|
1591
|
+
font_family: this.props.plugin.popup.font_family
|
|
1592
|
+
})
|
|
1593
|
+
})));
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
;// CONCATENATED MODULE: ./src/popup/popup.js
|
|
1597
|
+
function popup_defineProperty(obj, key, value) { key = popup_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1598
|
+
function popup_toPropertyKey(arg) { var key = popup_toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1599
|
+
function popup_toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1600
|
+
|
|
1601
|
+
|
|
1602
|
+
|
|
1603
|
+
|
|
1604
|
+
let popupCSS = (() => __webpack_require__.e(/* import() */ 782).then(__webpack_require__.bind(__webpack_require__, 9782)))();
|
|
1605
|
+
class Popup extends common/* Com */.up {
|
|
1606
|
+
constructor(props) {
|
|
1607
|
+
super(props);
|
|
1608
|
+
popup_defineProperty(this, "state", {
|
|
1609
|
+
close: false,
|
|
1610
|
+
cssready: false,
|
|
1611
|
+
closeAnimation: true,
|
|
1612
|
+
pressedSubmit: false,
|
|
1613
|
+
imageReady: false,
|
|
1614
|
+
fontReady: false
|
|
1615
|
+
});
|
|
1616
|
+
this._formRef = (0,preact_module/* createRef */.Vf)();
|
|
1617
|
+
util/* default */.Z.setTimeout(() => this.fillForm(), 1000);
|
|
1618
|
+
util/* default */.Z.setTimeout(async () => {
|
|
1619
|
+
let {
|
|
1620
|
+
body: impression
|
|
1621
|
+
} = await this.props.store.sendImpression(this.props.plugin.id);
|
|
1622
|
+
this.impressionToken = util/* default */.Z.get(impression, 'impression_token') || '';
|
|
1623
|
+
}, 10);
|
|
1624
|
+
util/* default */.Z.setTimeout(() => {
|
|
1625
|
+
let fonts = {};
|
|
1626
|
+
fonts[this.props.plugin.popup.font_family] = true;
|
|
1627
|
+
let images = {};
|
|
1628
|
+
util/* default */.Z.map(this.props.plugin.popup.pages, page => {
|
|
1629
|
+
if (!page) return;
|
|
1630
|
+
util/* default */.Z.map(page.components, com => {
|
|
1631
|
+
fonts[util/* default */.Z.get(com, 'style.font_family')] = true;
|
|
1632
|
+
fonts[util/* default */.Z.get(com, 'mobile_style.font_family')] = true;
|
|
1633
|
+
if (com.type === 'image' && com.image && com.image.url && com.image.url.startsWith('http')) {
|
|
1634
|
+
images[com.image.url] = true;
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
});
|
|
1638
|
+
delete fonts.undefined;
|
|
1639
|
+
delete fonts.null;
|
|
1640
|
+
delete fonts[''];
|
|
1641
|
+
if (util/* default */.Z.size(images) == 0) this.setState({
|
|
1642
|
+
imageReady: true
|
|
1643
|
+
});
|
|
1644
|
+
util/* default */.Z.map(images, (_, image) => util/* default */.Z.preloadImg(image, () => this.setState({
|
|
1645
|
+
imageReady: true
|
|
1646
|
+
})));
|
|
1647
|
+
util/* default */.Z.preloadWebfonts(Object.keys(fonts));
|
|
1648
|
+
util/* default */.Z.setTimeout(async () => {
|
|
1649
|
+
await this.waitForFont(Object.keys(fonts));
|
|
1650
|
+
this.setState({
|
|
1651
|
+
fontReady: true
|
|
1652
|
+
});
|
|
1653
|
+
});
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
async waitForFont(fonts) {
|
|
1657
|
+
if (util/* default */.Z.size(fonts) == 0) return;
|
|
1658
|
+
let ready = {};
|
|
1659
|
+
for (var t = 0; t < 10; t++) {
|
|
1660
|
+
for (var i = 0; i < fonts.length; i++) {
|
|
1661
|
+
try {
|
|
1662
|
+
if (document.fonts.check('normal 16px ' + fonts[i])) ready[fonts[i]] = true;
|
|
1663
|
+
if (Object.keys(readycount) == fonts.length) return;
|
|
1664
|
+
} catch (e) {}
|
|
1665
|
+
}
|
|
1666
|
+
await util/* default */.Z.sleep(200);
|
|
1667
|
+
}
|
|
1668
|
+
return;
|
|
1669
|
+
}
|
|
1670
|
+
openPopup() {
|
|
1671
|
+
this.setState({
|
|
1672
|
+
close: false
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
getPageIndex() {
|
|
1676
|
+
if (this.props.plugin._page_index !== undefined) return this.props.plugin._page_index;
|
|
1677
|
+
return this.props.pageIndex;
|
|
1678
|
+
}
|
|
1679
|
+
isFormFilled() {
|
|
1680
|
+
let page = util/* default */.Z.get(this.props.plugin.popup, `pages.${this.getPageIndex()}`);
|
|
1681
|
+
let form = util/* default */.Z.find(page.components, com => com.type === 'form');
|
|
1682
|
+
if (!form || !form.form) return true;
|
|
1683
|
+
let fields = util/* default */.Z.get(form, 'form.fields', []);
|
|
1684
|
+
let wrong = util/* default */.Z.find(fields, field => {
|
|
1685
|
+
if (!field.is_required) return false;
|
|
1686
|
+
if (!this.isFieldValid(field.key, field.validate)) return true;
|
|
1687
|
+
return this.isFieldEmpty(field.key);
|
|
1688
|
+
});
|
|
1689
|
+
return !wrong;
|
|
1690
|
+
}
|
|
1691
|
+
fillForm() {
|
|
1692
|
+
let page = util/* default */.Z.get(this.props.plugin.popup, `pages.${this.getPageIndex()}`);
|
|
1693
|
+
let form = util/* default */.Z.find(page.components, com => com.type === 'form');
|
|
1694
|
+
if (!form) return;
|
|
1695
|
+
let user = this.props.store.matchUser();
|
|
1696
|
+
let userAttributes = util/* default */.Z.get(user, 'attributes');
|
|
1697
|
+
let fields = util/* default */.Z.get(form, 'form.fields', []);
|
|
1698
|
+
util/* default */.Z.each(fields, field => {
|
|
1699
|
+
let fieldkey = field.key;
|
|
1700
|
+
if (fieldkey === 'email') fieldkey = 'emails';
|
|
1701
|
+
if (fieldkey === 'phone') fieldkey = 'phones';
|
|
1702
|
+
if (fieldkey !== 'emails' || fieldkey != 'phones' || fieldkey !== 'fullname') return;
|
|
1703
|
+
util/* default */.Z.map(userAttributes, attr => {
|
|
1704
|
+
if (fieldkey !== attr.key) return;
|
|
1705
|
+
var input = this._formRef.current.elements[field.key];
|
|
1706
|
+
if (!input) return;
|
|
1707
|
+
input.value = attr.text;
|
|
1708
|
+
});
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
isFieldValid(key, validate) {
|
|
1712
|
+
if (!validate) return true;
|
|
1713
|
+
if (!this._formRef || !this._formRef.current) return false;
|
|
1714
|
+
var formData = new FormData(this._formRef.current);
|
|
1715
|
+
for (var pair of formData.entries()) {
|
|
1716
|
+
if (pair[0] !== key) continue;
|
|
1717
|
+
if (validate === 'email') return util/* default */.Z.isEmail(pair[1]);
|
|
1718
|
+
if (validate === 'phone') return util/* default */.Z.isPhone(pair[1]);
|
|
1719
|
+
if (validate === 'url') return util/* default */.Z.isURL(pair[1]);
|
|
1720
|
+
if (validate === 'number') return util/* default */.Z.isNumber(pair[1]);
|
|
1721
|
+
return true;
|
|
1722
|
+
}
|
|
1723
|
+
return true;
|
|
1724
|
+
}
|
|
1725
|
+
isFieldEmpty(key) {
|
|
1726
|
+
if (!this._formRef || !this._formRef.current) return false;
|
|
1727
|
+
var formData = new FormData(this._formRef.current);
|
|
1728
|
+
for (var pair of formData.entries()) {
|
|
1729
|
+
if (pair[0] !== key) continue;
|
|
1730
|
+
return pair[1] === '' || pair[1] === undefined;
|
|
1731
|
+
}
|
|
1732
|
+
return true;
|
|
1733
|
+
}
|
|
1734
|
+
renderCloseButton() {
|
|
1735
|
+
if (!this.props.plugin.popup.show_close_button) return null;
|
|
1736
|
+
return (0,preact_module.h)("div", {
|
|
1737
|
+
class: 'btn_close default',
|
|
1738
|
+
onClick: e => this.setClose(true)
|
|
1739
|
+
}, (0,preact_module.h)("svg", {
|
|
1740
|
+
class: "btn_close__icon",
|
|
1741
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1742
|
+
width: "24",
|
|
1743
|
+
height: "24",
|
|
1744
|
+
viewBox: "0 0 24 24",
|
|
1745
|
+
"stroke-linecap": "round",
|
|
1746
|
+
"stroke-linejoin": "round"
|
|
1747
|
+
}, (0,preact_module.h)("line", {
|
|
1748
|
+
x1: "17",
|
|
1749
|
+
y1: "7",
|
|
1750
|
+
x2: "7",
|
|
1751
|
+
y2: "17",
|
|
1752
|
+
style: "stroke-width: 3 !important;"
|
|
1753
|
+
}), (0,preact_module.h)("line", {
|
|
1754
|
+
x1: "7",
|
|
1755
|
+
y1: "7",
|
|
1756
|
+
x2: "17",
|
|
1757
|
+
y2: "17",
|
|
1758
|
+
style: "stroke-width: 3 !important;"
|
|
1759
|
+
})));
|
|
1760
|
+
}
|
|
1761
|
+
setClose(close) {
|
|
1762
|
+
if (close) {
|
|
1763
|
+
document.body.style.setProperty('overflow', this.lastoverflow);
|
|
1764
|
+
this.setState({
|
|
1765
|
+
closeAnimation: true
|
|
1766
|
+
});
|
|
1767
|
+
util/* default */.Z.setTimeout(() => this.setState({
|
|
1768
|
+
close: true,
|
|
1769
|
+
closeAnimation: false
|
|
1770
|
+
}), 150);
|
|
1771
|
+
if (this.props.plugin._dont_close) util/* default */.Z.setTimeout(() => {
|
|
1772
|
+
this.lastoverflow = window.getComputedStyle(document.body).getPropertyValue('overflow');
|
|
1773
|
+
document.body.style.setProperty('overflow', 'hidden', 'important');
|
|
1774
|
+
this.setState({
|
|
1775
|
+
closeAnimation: false,
|
|
1776
|
+
close: false
|
|
1777
|
+
});
|
|
1778
|
+
}, 1500);
|
|
1779
|
+
} else {
|
|
1780
|
+
this.lastoverflow = window.getComputedStyle(document.body).getPropertyValue('overflow');
|
|
1781
|
+
document.body.style.setProperty('overflow', 'hidden', 'important');
|
|
1782
|
+
this.setState({
|
|
1783
|
+
closeAnimation: false
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
onButtonClick(e, buttontype) {
|
|
1788
|
+
e.stopPropagation();
|
|
1789
|
+
let popup = util/* default */.Z.get(this.props.plugin, 'popup', {});
|
|
1790
|
+
let page = util/* default */.Z.get(this.props.plugin.popup, `pages.${this.getPageIndex()}`);
|
|
1791
|
+
let actions = [];
|
|
1792
|
+
let buttons = util/* default */.Z.find(page.components, com => com.type === 'buttons');
|
|
1793
|
+
if (buttontype === 'background') actions = util/* default */.Z.get(page, 'background_click.actions') || [];
|
|
1794
|
+
if (buttontype === 'primary' && buttons.buttons.primary_enabled) actions = buttons.buttons.primary_actions || [];
|
|
1795
|
+
if (buttontype === 'secondary' && buttons.buttons.secondary_enabled) actions = buttons.buttons.secondary_actions || [];
|
|
1796
|
+
let mustfillform = false;
|
|
1797
|
+
for (let a of actions) {
|
|
1798
|
+
if (a.action === 'conversion' || a.action === 'submit') {
|
|
1799
|
+
mustfillform = true;
|
|
1800
|
+
this.setState({
|
|
1801
|
+
pressedSubmit: true
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
if (mustfillform && !this.isFormFilled()) return;
|
|
1806
|
+
var hasConversion = false;
|
|
1807
|
+
for (let a of actions) {
|
|
1808
|
+
if (a.action === 'submit' || a.action === 'conversion') hasConversion = true;
|
|
1809
|
+
}
|
|
1810
|
+
if (hasConversion) {
|
|
1811
|
+
var formData = this._formRef.current ? new FormData(this._formRef.current) : new FormData();
|
|
1812
|
+
var summitFields = [];
|
|
1813
|
+
let user = util/* default */.Z.cloneDeep(this.props.store.matchUser());
|
|
1814
|
+
let is_lead = false;
|
|
1815
|
+
let modifiedPairs = {};
|
|
1816
|
+
for (var pair of formData.entries()) {
|
|
1817
|
+
if (modifiedPairs[pair[0]]) {
|
|
1818
|
+
let currentValue = util/* default */.Z.get(modifiedPairs, `${pair[0]}.1`, '');
|
|
1819
|
+
currentValue += `,${pair[1]}`;
|
|
1820
|
+
util/* default */.Z.set(modifiedPairs, `${pair[0]}.1`, currentValue);
|
|
1821
|
+
} else {
|
|
1822
|
+
modifiedPairs[pair[0]] = [pair[0], pair[1]];
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
for (const [_, pair] of Object.entries(modifiedPairs)) {
|
|
1826
|
+
let page = util/* default */.Z.get(this.props.plugin.popup, `pages.${this.getPageIndex()}`);
|
|
1827
|
+
let form = util/* default */.Z.find(page.components, com => com.type === 'form');
|
|
1828
|
+
let fields = util/* default */.Z.get(form, 'form.fields', []);
|
|
1829
|
+
let field = util/* default */.Z.find(fields, field => field.key === pair[0]) || {};
|
|
1830
|
+
if (!field.type) return;
|
|
1831
|
+
summitFields.push({
|
|
1832
|
+
key: pair[0],
|
|
1833
|
+
type: field.type,
|
|
1834
|
+
value: util/* default */.Z.stringify(pair[1])
|
|
1835
|
+
});
|
|
1836
|
+
let key = pair[0];
|
|
1837
|
+
if (key === 'email') key = 'emails';
|
|
1838
|
+
if (key === 'phone') key = 'phones';
|
|
1839
|
+
is_lead = is_lead || key == 'emails' || key == 'phones';
|
|
1840
|
+
util/* default */.Z.setUserAttr(user, {
|
|
1841
|
+
key: key,
|
|
1842
|
+
text: pair[1]
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
if (is_lead) util/* default */.Z.setUserAttr(user, {
|
|
1846
|
+
key: 'lead_source',
|
|
1847
|
+
text: 'plugin.' + this.props.plugin.id
|
|
1848
|
+
});
|
|
1849
|
+
this.props.store.sendConversion(this.props.plugin.id, summitFields, this.impressionToken);
|
|
1850
|
+
this.props.store.setUser(user);
|
|
1851
|
+
}
|
|
1852
|
+
for (let a of actions) {
|
|
1853
|
+
if (a.action === 'open_widget') this.props.showWidget('list');
|
|
1854
|
+
}
|
|
1855
|
+
for (let a of actions) {
|
|
1856
|
+
if (a.action === 'close') util/* default */.Z.setTimeout(() => this.setClose(true), 100);
|
|
1857
|
+
if (a.action === 'next_page') this.props.nextPage();
|
|
1858
|
+
}
|
|
1859
|
+
for (let a of actions) {
|
|
1860
|
+
if (!a.url) continue;
|
|
1861
|
+
let url = a.url;
|
|
1862
|
+
if (!url.startsWith('http://') && !url.startsWith('https://')) url = '//' + url;
|
|
1863
|
+
if (a.action === 'open_url' && a.new_tab) return window.open(url, '_blank');
|
|
1864
|
+
if (a.action === 'open_url' && !a.new_tab) {
|
|
1865
|
+
window.location.href = url;
|
|
1866
|
+
return;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
renderButtons(com, page) {
|
|
1871
|
+
let popup = util/* default */.Z.get(this.props.plugin, 'popup', {});
|
|
1872
|
+
let buttonsstyle = com.style || {};
|
|
1873
|
+
let primarystyle = Object.assign({}, buttonsstyle);
|
|
1874
|
+
delete primarystyle.justify_content;
|
|
1875
|
+
delete primarystyle.align_items;
|
|
1876
|
+
delete primarystyle.flex_direction;
|
|
1877
|
+
delete primarystyle.display;
|
|
1878
|
+
primarystyle.color = primarystyle.color || '#fff';
|
|
1879
|
+
primarystyle.font_weight = primarystyle.font_weight || '500';
|
|
1880
|
+
primarystyle.font_size = primarystyle.font_size || popup.font_size || '14px';
|
|
1881
|
+
primarystyle.background = primarystyle.background || popup.text_color;
|
|
1882
|
+
if (this.props.mobile && com.mobile_style) {
|
|
1883
|
+
primarystyle = Object.assign(primarystyle, com.mobile_style);
|
|
1884
|
+
}
|
|
1885
|
+
let $primary = null;
|
|
1886
|
+
if (com.buttons.primary_enabled && com.buttons.primary_text) {
|
|
1887
|
+
let style = Object.assign({
|
|
1888
|
+
font_size: popup.font_size || '14px'
|
|
1889
|
+
}, page.primary_button);
|
|
1890
|
+
if (util/* default */.Z.get(com, 'style.background')) style.background = com.style.background;
|
|
1891
|
+
if (util/* default */.Z.get(com, 'style.color')) style.color = com.style.color;
|
|
1892
|
+
$primary = (0,preact_module.h)("div", {
|
|
1893
|
+
class: 'btn btn__primary ',
|
|
1894
|
+
style: this.js2css(primarystyle),
|
|
1895
|
+
onClick: e => this.onButtonClick(e, 'primary')
|
|
1896
|
+
}, this.props.t.i18n(com.buttons.i18n_primary_text) || com.buttons.primary_text);
|
|
1897
|
+
}
|
|
1898
|
+
let $secondary = null;
|
|
1899
|
+
if (com.buttons.secondary_enabled && com.buttons.secondary_text) {
|
|
1900
|
+
let style = Object.assign({
|
|
1901
|
+
font_size: popup.font_size || '14px'
|
|
1902
|
+
}, page.secondary_button);
|
|
1903
|
+
if (this.props.mobile && com.mobile_style) {
|
|
1904
|
+
style = Object.assign(style, com.mobile_style);
|
|
1905
|
+
}
|
|
1906
|
+
$secondary = (0,preact_module.h)("div", {
|
|
1907
|
+
class: 'btn btn__secondary',
|
|
1908
|
+
style: this.js2css(style),
|
|
1909
|
+
onClick: e => this.onButtonClick(e, 'secondary')
|
|
1910
|
+
}, this.props.t.i18n(com.buttons.i18n_secondary_text) || com.buttons.secondary_text);
|
|
1911
|
+
}
|
|
1912
|
+
return (0,preact_module.h)("div", {
|
|
1913
|
+
class: "popup_component",
|
|
1914
|
+
style: this.js2css({
|
|
1915
|
+
display: 'flex',
|
|
1916
|
+
flex_direction: buttonsstyle.flex_direction,
|
|
1917
|
+
align_items: buttonsstyle.align_items
|
|
1918
|
+
})
|
|
1919
|
+
}, $primary, (0,preact_module.h)("div", {
|
|
1920
|
+
style: this.js2css({
|
|
1921
|
+
width: '10px',
|
|
1922
|
+
height: '1px'
|
|
1923
|
+
})
|
|
1924
|
+
}), $secondary);
|
|
1925
|
+
}
|
|
1926
|
+
js2css(js, onlyProps) {
|
|
1927
|
+
let spacer = this.props.plugin.popup.spacer || 10;
|
|
1928
|
+
return util/* default */.Z.js2css(js, onlyProps, {
|
|
1929
|
+
'@font_size': this.props.plugin.popup.font_size,
|
|
1930
|
+
'@font_family': this.props.plugin.popup.font_family,
|
|
1931
|
+
'@text_color': this.props.plugin.popup.text_color,
|
|
1932
|
+
'@faded_text_color': this.props.plugin.popup.faded_text_color,
|
|
1933
|
+
'@primary_color': this.props.plugin.popup.primary_color,
|
|
1934
|
+
'@spacer0': spacer / 2 + 'px',
|
|
1935
|
+
'@spacer': spacer + 'px',
|
|
1936
|
+
'@spacer2': spacer * 2 + 'px',
|
|
1937
|
+
'@spacer3': spacer * 3 + 'px'
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
renderSingleChoiceField(field) {
|
|
1941
|
+
var cls = 'form-control form-control__select ' + this.props.plugin.popup.theme;
|
|
1942
|
+
let $options = util/* default */.Z.map(field.options, option => {
|
|
1943
|
+
return (0,preact_module.h)("label", {
|
|
1944
|
+
class: cls
|
|
1945
|
+
}, (0,preact_module.h)("input", {
|
|
1946
|
+
type: "radio",
|
|
1947
|
+
name: field.key,
|
|
1948
|
+
value: option.value
|
|
1949
|
+
}), (0,preact_module.h)("span", null, this.props.t.i18n(option.i18n_label) || option.label));
|
|
1950
|
+
});
|
|
1951
|
+
return (0,preact_module.h)(preact_module/* Fragment */.HY, null, $options);
|
|
1952
|
+
}
|
|
1953
|
+
renderDropdownField(field) {
|
|
1954
|
+
let $options = util/* default */.Z.map(field.options, option => {
|
|
1955
|
+
return (0,preact_module.h)("option", {
|
|
1956
|
+
value: option.value
|
|
1957
|
+
}, option.value);
|
|
1958
|
+
});
|
|
1959
|
+
let theme = util/* default */.Z.get(this.props.plugin, 'popup.theme');
|
|
1960
|
+
var cls = 'form-control form-control__select ' + theme;
|
|
1961
|
+
if (theme === 'vintage') {
|
|
1962
|
+
return (0,preact_module.h)("div", {
|
|
1963
|
+
class: "form-control__text_container"
|
|
1964
|
+
}, (0,preact_module.h)("div", {
|
|
1965
|
+
class: "form-control_inside_label form-label vintage"
|
|
1966
|
+
}, this.props.t.i18n(field.i18n_label) || field.label), (0,preact_module.h)("select", {
|
|
1967
|
+
class: cls,
|
|
1968
|
+
name: field.key
|
|
1969
|
+
}, $options));
|
|
1970
|
+
}
|
|
1971
|
+
return (0,preact_module.h)("select", {
|
|
1972
|
+
class: cls,
|
|
1973
|
+
name: field.key
|
|
1974
|
+
}, $options);
|
|
1975
|
+
}
|
|
1976
|
+
renderMutiChoiceField(field) {
|
|
1977
|
+
var cls = 'form-control form-control__check ' + this.props.plugin.popup.theme;
|
|
1978
|
+
let $options = util/* default */.Z.map(field.options, option => {
|
|
1979
|
+
return (0,preact_module.h)("label", {
|
|
1980
|
+
class: cls
|
|
1981
|
+
}, (0,preact_module.h)("input", {
|
|
1982
|
+
required: field.is_required,
|
|
1983
|
+
type: "checkbox",
|
|
1984
|
+
name: field.key,
|
|
1985
|
+
value: option.value
|
|
1986
|
+
}), (0,preact_module.h)("span", null, this.props.t.i18n(option.i18n_label) || option.label));
|
|
1987
|
+
});
|
|
1988
|
+
return (0,preact_module.h)(preact_module/* Fragment */.HY, null, $options);
|
|
1989
|
+
}
|
|
1990
|
+
renderTextField(field) {
|
|
1991
|
+
let theme = util/* default */.Z.get(this.props.plugin, 'popup.theme');
|
|
1992
|
+
var cls = 'form-control form-control__text ' + theme;
|
|
1993
|
+
if (theme === 'simple') {
|
|
1994
|
+
return (0,preact_module.h)("input", {
|
|
1995
|
+
type: field.type,
|
|
1996
|
+
class: "form-control form-control__text simple",
|
|
1997
|
+
key: 'form_field_' + field.key,
|
|
1998
|
+
name: field.key,
|
|
1999
|
+
placeholder: this.props.t.i18n(field.i18n_label) || field.label || this.props.t.i18n(field.i18n_placeholder) || field.placeholder
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
if (theme === 'vintage') {
|
|
2003
|
+
return (0,preact_module.h)("div", {
|
|
2004
|
+
class: "form-control__text_container"
|
|
2005
|
+
}, (0,preact_module.h)("div", {
|
|
2006
|
+
class: "form-control_inside_label form-label vintage"
|
|
2007
|
+
}, this.props.t.i18n(field.i18n_label) || field.label), (0,preact_module.h)("input", {
|
|
2008
|
+
type: field.type,
|
|
2009
|
+
class: cls,
|
|
2010
|
+
key: 'form_field_' + field.key,
|
|
2011
|
+
name: field.key,
|
|
2012
|
+
placeholder: this.props.t.i18n(field.i18n_placeholder) || field.placeholder
|
|
2013
|
+
}));
|
|
2014
|
+
}
|
|
2015
|
+
return (0,preact_module.h)("input", {
|
|
2016
|
+
type: field.type,
|
|
2017
|
+
class: cls,
|
|
2018
|
+
key: 'form_field_' + field.key,
|
|
2019
|
+
name: field.key,
|
|
2020
|
+
placeholder: this.props.t.i18n(field.i18n_placeholder) || field.placeholder
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
renderMultilineTextField(field) {
|
|
2024
|
+
let theme = util/* default */.Z.get(this.props.plugin, 'popup.theme');
|
|
2025
|
+
var cls = 'form-control form-control__text ' + theme;
|
|
2026
|
+
if (theme === 'simple') {
|
|
2027
|
+
return (0,preact_module.h)("textarea", {
|
|
2028
|
+
rows: "3",
|
|
2029
|
+
name: field.key,
|
|
2030
|
+
type: field.type,
|
|
2031
|
+
key: 'form_field_' + field.key,
|
|
2032
|
+
class: "form-control form-control__text simple",
|
|
2033
|
+
style: this.js2css({
|
|
2034
|
+
overflow: 'auto',
|
|
2035
|
+
resize: 'none'
|
|
2036
|
+
}),
|
|
2037
|
+
placeholder: this.props.t.i18n(field.i18n_label) || field.label || this.props.t.i18n(field.i18n_placeholder) || field.placeholder
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
if (theme === 'vintage') {
|
|
2041
|
+
return (0,preact_module.h)("div", {
|
|
2042
|
+
class: "form-control__text_container"
|
|
2043
|
+
}, (0,preact_module.h)("div", {
|
|
2044
|
+
class: "form-control_inside_label form-label vintage"
|
|
2045
|
+
}, field.label), (0,preact_module.h)("textarea", {
|
|
2046
|
+
rows: "3",
|
|
2047
|
+
name: field.key,
|
|
2048
|
+
type: field.type,
|
|
2049
|
+
key: 'form_field_' + field.key,
|
|
2050
|
+
class: cls,
|
|
2051
|
+
style: this.js2css({
|
|
2052
|
+
overflow: 'auto',
|
|
2053
|
+
resize: 'none'
|
|
2054
|
+
}),
|
|
2055
|
+
placeholder: this.props.t.i18n(field.i18n_label) || field.label || this.props.t.i18n(field.i18n_placeholder) || field.placeholder
|
|
2056
|
+
}));
|
|
2057
|
+
}
|
|
2058
|
+
return (0,preact_module.h)("textarea", {
|
|
2059
|
+
rows: "3",
|
|
2060
|
+
name: field.key,
|
|
2061
|
+
type: field.type,
|
|
2062
|
+
key: 'form_field_' + field.key,
|
|
2063
|
+
class: cls,
|
|
2064
|
+
style: this.js2css({
|
|
2065
|
+
overflow: 'auto',
|
|
2066
|
+
resize: 'none'
|
|
2067
|
+
}),
|
|
2068
|
+
placeholder: this.props.t.i18n(field.i18n_placeholder) || field.placeholder
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
renderFormComponent(com) {
|
|
2072
|
+
let popup = util/* default */.Z.get(this.props.plugin, 'popup', {});
|
|
2073
|
+
let $fields = util/* default */.Z.map(com.form.fields, field => {
|
|
2074
|
+
if (field.type === 'email') return this.renderTextField(field);
|
|
2075
|
+
if (field.type === 'single-choice') return this.renderSingleChoiceField(field);
|
|
2076
|
+
if (field.type === 'multiple-choice') return this.renderMutiChoiceField(field);
|
|
2077
|
+
if (field.type === 'multiline-text') return this.renderMultilineTextField(field);
|
|
2078
|
+
if (field.type === 'text') return this.renderTextField(field);
|
|
2079
|
+
if (field.type === 'dropdown') return this.renderDropdownField(field);
|
|
2080
|
+
return;
|
|
2081
|
+
});
|
|
2082
|
+
let theme = util/* default */.Z.get(popup, 'theme');
|
|
2083
|
+
$fields = util/* default */.Z.map($fields, ($field, i) => {
|
|
2084
|
+
let $label = null;
|
|
2085
|
+
let field = com.form.fields[i];
|
|
2086
|
+
$label = (0,preact_module.h)("div", {
|
|
2087
|
+
class: "form-label",
|
|
2088
|
+
style: this.js2css({
|
|
2089
|
+
color: popup.text_color,
|
|
2090
|
+
font_family: popup.font_family,
|
|
2091
|
+
font_size: popup.font_size || '14px'
|
|
2092
|
+
})
|
|
2093
|
+
}, this.props.t.i18n(field.i18n_label) || field.label);
|
|
2094
|
+
if (theme === 'vintage' && field.type === 'dropdown') $label = null;
|
|
2095
|
+
if (theme === 'vintage' || theme === 'simple') {
|
|
2096
|
+
if (field.type === 'email' || field.type === 'text' || field.type === 'multiline-text') $label = null;
|
|
2097
|
+
}
|
|
2098
|
+
let $error = null;
|
|
2099
|
+
if (this.state.pressedSubmit && !this.isFieldValid(field.key, field.validate)) {
|
|
2100
|
+
$error = (0,preact_module.h)("div", {
|
|
2101
|
+
class: "text__danger ",
|
|
2102
|
+
style: this.js2css({
|
|
2103
|
+
margin_top: '5px',
|
|
2104
|
+
font_family: popup.font_family,
|
|
2105
|
+
font_size: popup.font_size
|
|
2106
|
+
})
|
|
2107
|
+
}, this.props.t('invalid_field'));
|
|
2108
|
+
}
|
|
2109
|
+
if (this.state.pressedSubmit && field.is_required && this.isFieldEmpty(field.key)) {
|
|
2110
|
+
$error = (0,preact_module.h)("div", {
|
|
2111
|
+
class: "text__danger ",
|
|
2112
|
+
style: this.js2css({
|
|
2113
|
+
margin_top: '5px',
|
|
2114
|
+
font_family: popup.font_family,
|
|
2115
|
+
font_size: popup.font_size
|
|
2116
|
+
})
|
|
2117
|
+
}, this.props.t('required'));
|
|
2118
|
+
}
|
|
2119
|
+
return (0,preact_module.h)("div", {
|
|
2120
|
+
class: "field"
|
|
2121
|
+
}, $label, $field, $error);
|
|
2122
|
+
});
|
|
2123
|
+
return (0,preact_module.h)("form", {
|
|
2124
|
+
style: this.js2css(com.style),
|
|
2125
|
+
class: "form popup_component",
|
|
2126
|
+
ref: this._formRef,
|
|
2127
|
+
onClick: e => e.stopPropagation()
|
|
2128
|
+
}, $fields);
|
|
2129
|
+
}
|
|
2130
|
+
renderComponents(page) {
|
|
2131
|
+
let buttons = util/* default */.Z.find(page.components, com => com.type === 'buttons');
|
|
2132
|
+
let $buttons = null;
|
|
2133
|
+
if (buttons) $buttons = this.renderButtons(buttons, page);
|
|
2134
|
+
let comIndexWithoutImg = 0;
|
|
2135
|
+
return util/* default */.Z.map(page.components, (com, i) => {
|
|
2136
|
+
if (com.type === 'image') return null;
|
|
2137
|
+
comIndexWithoutImg++;
|
|
2138
|
+
if (com.type === 'buttons') return $buttons;
|
|
2139
|
+
if (com.type === 'follow_facebook') return this.renderFollowFacebook(com);
|
|
2140
|
+
if (com.type === 'social_buttons') return this.renderSocialButtons(com);
|
|
2141
|
+
if (com.type === 'line') return this.renderLineComponent(com);
|
|
2142
|
+
if (com.type === 'text') return this.renderTextComponent(com, comIndexWithoutImg === 1);
|
|
2143
|
+
if (com.type === 'form') return this.renderFormComponent(com);
|
|
2144
|
+
if (com.type === 'countdown') return (0,preact_module.h)("div", {
|
|
2145
|
+
class: "popup_component",
|
|
2146
|
+
onClick: e => e.stopPropagation()
|
|
2147
|
+
}, (0,preact_module.h)(Countdown, {
|
|
2148
|
+
destroy: this.props.destroy,
|
|
2149
|
+
t: this.props.t,
|
|
2150
|
+
com: com,
|
|
2151
|
+
store: this.props.store,
|
|
2152
|
+
plugin: this.props.plugin
|
|
2153
|
+
}));
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2156
|
+
renderFollowFacebook(com) {
|
|
2157
|
+
let fburl = util/* default */.Z.get(com, 'follow_facebook.url');
|
|
2158
|
+
if (!fburl) return null;
|
|
2159
|
+
let style = this.props.mobile && com.mobile_style || com.style;
|
|
2160
|
+
let containerstyle = {
|
|
2161
|
+
display: 'flex',
|
|
2162
|
+
justify_content: style.justify_content
|
|
2163
|
+
};
|
|
2164
|
+
let textstyle = {};
|
|
2165
|
+
textstyle.font_family = style.font_family || this.props.plugin.popup.font_family;
|
|
2166
|
+
textstyle.font_size = style.font_size || this.props.plugin.popup.font_size || '14px';
|
|
2167
|
+
return (0,preact_module.h)("div", {
|
|
2168
|
+
class: "popup_component",
|
|
2169
|
+
style: this.js2css(containerstyle),
|
|
2170
|
+
onClick: e => e.stopPropagation()
|
|
2171
|
+
}, (0,preact_module.h)("div", {
|
|
2172
|
+
class: "follow_fb_btn"
|
|
2173
|
+
}, (0,preact_module.h)("img", {
|
|
2174
|
+
alt: "follow",
|
|
2175
|
+
class: "follow_fb_btn__img",
|
|
2176
|
+
src: __webpack_require__(9639)
|
|
2177
|
+
}), (0,preact_module.h)("span", {
|
|
2178
|
+
style: this.js2css(Object.assign({
|
|
2179
|
+
white_space: 'nowrap',
|
|
2180
|
+
overflow: 'hidden',
|
|
2181
|
+
text_overflow: 'ellipsis'
|
|
2182
|
+
}, textstyle))
|
|
2183
|
+
}, this.props.t('follow_us_on_facebook'))));
|
|
2184
|
+
}
|
|
2185
|
+
renderSocialButtons(com) {
|
|
2186
|
+
let fburl = util/* default */.Z.get(com, 'social_buttons.facebook');
|
|
2187
|
+
let $fb = null;
|
|
2188
|
+
if (fburl) {
|
|
2189
|
+
$fb = (0,preact_module.h)("a", {
|
|
2190
|
+
href: fburl,
|
|
2191
|
+
class: "social_button",
|
|
2192
|
+
target: "_blank"
|
|
2193
|
+
}, (0,preact_module.h)("img", {
|
|
2194
|
+
alt: "facebook",
|
|
2195
|
+
class: "social_button__img",
|
|
2196
|
+
src: __webpack_require__(7435)
|
|
2197
|
+
}));
|
|
2198
|
+
}
|
|
2199
|
+
let zlurl = util/* default */.Z.get(com, 'social_buttons.zalo');
|
|
2200
|
+
let $zl = null;
|
|
2201
|
+
if (zlurl) {
|
|
2202
|
+
$zl = (0,preact_module.h)("a", {
|
|
2203
|
+
href: zlurl,
|
|
2204
|
+
class: "social_button",
|
|
2205
|
+
target: "_blank"
|
|
2206
|
+
}, (0,preact_module.h)("img", {
|
|
2207
|
+
alt: "zalo",
|
|
2208
|
+
class: "social_button__img",
|
|
2209
|
+
src: __webpack_require__(7298)
|
|
2210
|
+
}));
|
|
2211
|
+
}
|
|
2212
|
+
let style = this.props.mobile && com.mobile_style || com.style;
|
|
2213
|
+
return (0,preact_module.h)("div", {
|
|
2214
|
+
class: "social_buttons popup_component",
|
|
2215
|
+
style: this.js2css(style),
|
|
2216
|
+
onClick: e => e.stopPropagation()
|
|
2217
|
+
}, $fb, " ", $zl);
|
|
2218
|
+
}
|
|
2219
|
+
renderImageComponent(com, i) {
|
|
2220
|
+
let style = Object.assign({
|
|
2221
|
+
pointer_events: 'none'
|
|
2222
|
+
}, this.props.mobile && com.mobile_style || com.style, {
|
|
2223
|
+
position: 'absolute'
|
|
2224
|
+
});
|
|
2225
|
+
if (!style.z_index) style.z_index = '-1';
|
|
2226
|
+
return (0,preact_module.h)("div", {
|
|
2227
|
+
style: this.js2css(style)
|
|
2228
|
+
}, (0,preact_module.h)("div", {
|
|
2229
|
+
id: 'image_component_' + this.props.plugin.id + '_' + this.getPageIndex() + '_' + i,
|
|
2230
|
+
style: this.js2css({
|
|
2231
|
+
width: '100%',
|
|
2232
|
+
height: '100%',
|
|
2233
|
+
background_image: `url("${encodeURI(util/* default */.Z.get(com, 'image.url'))}")`,
|
|
2234
|
+
background_size: style.background_size || 'cover',
|
|
2235
|
+
background_position: style.background_position || 'auto'
|
|
2236
|
+
})
|
|
2237
|
+
}));
|
|
2238
|
+
}
|
|
2239
|
+
renderLineComponent(com) {
|
|
2240
|
+
let style = this.props.mobile && com.mobile_style || com.style;
|
|
2241
|
+
return (0,preact_module.h)("div", {
|
|
2242
|
+
class: "popup_component",
|
|
2243
|
+
style: this.js2css(style)
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
renderTextComponent(com, isFirst) {
|
|
2247
|
+
let popup = util/* default */.Z.get(this.props.plugin, 'popup', {});
|
|
2248
|
+
let style = Object.assign({
|
|
2249
|
+
color: popup.text_color,
|
|
2250
|
+
font_family: popup.font_family,
|
|
2251
|
+
font_size: popup.font_size || '14px',
|
|
2252
|
+
white_space: 'pre-wrap'
|
|
2253
|
+
}, this.props.mobile && com.mobile_style || com.style);
|
|
2254
|
+
delete style.margin_top;
|
|
2255
|
+
return (0,preact_module.h)("div", {
|
|
2256
|
+
class: "text popup_component",
|
|
2257
|
+
style: this.js2css(style),
|
|
2258
|
+
onClick: e => e.stopPropagation()
|
|
2259
|
+
}, this.props.t.i18n(util/* default */.Z.get(com, 'text.i18n_html')) || util/* default */.Z.get(com, 'text.html'));
|
|
2260
|
+
}
|
|
2261
|
+
async refreshCSS() {
|
|
2262
|
+
let plugins = this.props.store.matchPlugin();
|
|
2263
|
+
let found = util/* default */.Z.find(plugins, plugin => plugin.id === this.props.plugin.id);
|
|
2264
|
+
if (!found) return;
|
|
2265
|
+
let css = (await popupCSS).default.default.toString();
|
|
2266
|
+
var outcss = util/* default */.Z.replaceCssVariablePlugin(css, this.props.plugin.popup);
|
|
2267
|
+
let extra_css = util/* default */.Z.get(this.props.plugin, `popup.pages.0.extra_css`, []);
|
|
2268
|
+
let extra_css_string = util/* default */.Z.map(extra_css, css => `#sbz92 ${css.selector} { ${this.js2css(css.style)}}`).join('\n');
|
|
2269
|
+
outcss += extra_css_string;
|
|
2270
|
+
util/* default */.Z.setCss(this.props.plugin.id, this.$cssStyleDiv, outcss);
|
|
2271
|
+
}
|
|
2272
|
+
componentWillUnmount() {
|
|
2273
|
+
util/* default */.Z.setCss(this.props.plugin.id, this.$cssStyleDiv, '');
|
|
2274
|
+
}
|
|
2275
|
+
async componentDidMount() {
|
|
2276
|
+
this.$cssStyleDiv = document.getElementById('subiz-style-for-' + this.props.plugin.id);
|
|
2277
|
+
if (!this.$cssStyleDiv) {
|
|
2278
|
+
this.$cssStyleDiv = document.createElement('style');
|
|
2279
|
+
document.head.appendChild(this.$cssStyleDiv);
|
|
2280
|
+
this.$cssStyleDiv.type = 'text/css';
|
|
2281
|
+
this.$cssStyleDiv.id = 'subiz-style-for-' + this.props.plugin.id;
|
|
2282
|
+
}
|
|
2283
|
+
this.props.store.onResetCSS(this, () => this.refreshCSS());
|
|
2284
|
+
await this.refreshCSS();
|
|
2285
|
+
util/* default */.Z.setTimeout(() => {
|
|
2286
|
+
this.setState({
|
|
2287
|
+
cssready: true
|
|
2288
|
+
});
|
|
2289
|
+
this.setClose(false);
|
|
2290
|
+
}, 50);
|
|
2291
|
+
}
|
|
2292
|
+
calculateContainerCss(popup, page) {
|
|
2293
|
+
let pos = popup.position || 'center';
|
|
2294
|
+
let pagestyle = Object.assign({
|
|
2295
|
+
display: 'flex'
|
|
2296
|
+
}, this.props.mobile && page.mobile_style || page.style, {
|
|
2297
|
+
max_width: '85%',
|
|
2298
|
+
max_height: '85%'
|
|
2299
|
+
});
|
|
2300
|
+
let containercss = {};
|
|
2301
|
+
util/* default */.Z.map(['left', 'top', 'right', 'bottom', 'box_shadow', 'transform'], prop => {
|
|
2302
|
+
containercss[prop] = pagestyle[prop];
|
|
2303
|
+
});
|
|
2304
|
+
containercss.position = 'absolute';
|
|
2305
|
+
if (pos === 'center' || !pos) {
|
|
2306
|
+
containercss.top = '50%';
|
|
2307
|
+
containercss.transform = 'translateY(-50%) translateX(-50%)';
|
|
2308
|
+
containercss.left = '50%';
|
|
2309
|
+
delete containercss.right;
|
|
2310
|
+
delete containercss.bottom;
|
|
2311
|
+
}
|
|
2312
|
+
if (pos === 'fullscreen') {
|
|
2313
|
+
containercss.top = 0;
|
|
2314
|
+
containercss.left = 0;
|
|
2315
|
+
containercss.right = 0;
|
|
2316
|
+
containercss.bottom = 0;
|
|
2317
|
+
containercss.display = 'flex';
|
|
2318
|
+
containercss.align_items = 'center';
|
|
2319
|
+
containercss.background = popup.background;
|
|
2320
|
+
delete containercss.width;
|
|
2321
|
+
delete containercss.height;
|
|
2322
|
+
delete containercss.transform;
|
|
2323
|
+
}
|
|
2324
|
+
if (pos === 'top-left') {
|
|
2325
|
+
containercss.top = containercss.top || '0px';
|
|
2326
|
+
containercss.left = containercss.left || '0px';
|
|
2327
|
+
delete containercss.transform;
|
|
2328
|
+
delete containercss.right;
|
|
2329
|
+
delete containercss.bottom;
|
|
2330
|
+
}
|
|
2331
|
+
if (pos === 'top-right') {
|
|
2332
|
+
containercss.top = containercss.top || '0px';
|
|
2333
|
+
containercss.right = containercss.right || '0px';
|
|
2334
|
+
delete containercss.transform;
|
|
2335
|
+
delete containercss.left;
|
|
2336
|
+
delete containercss.bottom;
|
|
2337
|
+
}
|
|
2338
|
+
if (pos === 'top-center') {
|
|
2339
|
+
containercss.transform = 'translateX(-50%)';
|
|
2340
|
+
containercss.left = '50%';
|
|
2341
|
+
containercss.top = containercss.top || '0px';
|
|
2342
|
+
delete containercss.right;
|
|
2343
|
+
delete containercss.bottom;
|
|
2344
|
+
}
|
|
2345
|
+
if (pos === 'middle-left') {
|
|
2346
|
+
containercss.top = '50%';
|
|
2347
|
+
containercss.transform = 'translateY(-50%)';
|
|
2348
|
+
containercss.left = containercss.left || '0px';
|
|
2349
|
+
delete containercss.right;
|
|
2350
|
+
delete containercss.bottom;
|
|
2351
|
+
}
|
|
2352
|
+
if (pos === 'middle-right') {
|
|
2353
|
+
containercss.top = '50%';
|
|
2354
|
+
containercss.transform = 'translateY(-50%)';
|
|
2355
|
+
containercss.right = containercss.right || '0px';
|
|
2356
|
+
delete containercss.left;
|
|
2357
|
+
delete containercss.bottom;
|
|
2358
|
+
}
|
|
2359
|
+
if (pos === 'bottom-left') {
|
|
2360
|
+
containercss.bottom = containercss.bottom || '0px';
|
|
2361
|
+
containercss.left = containercss.left || '0px';
|
|
2362
|
+
delete containercss.transform;
|
|
2363
|
+
delete containercss.top;
|
|
2364
|
+
delete containercss.right;
|
|
2365
|
+
}
|
|
2366
|
+
if (pos === 'bottom-right') {
|
|
2367
|
+
containercss.bottom = containercss.bottom || '0px';
|
|
2368
|
+
containercss.right = containercss.right || '0px';
|
|
2369
|
+
delete containercss.transform;
|
|
2370
|
+
delete containercss.top;
|
|
2371
|
+
delete containercss.left;
|
|
2372
|
+
}
|
|
2373
|
+
if (pos === 'bottom-center') {
|
|
2374
|
+
containercss.bottom = containercss.bottom || '0px';
|
|
2375
|
+
containercss.transform = 'translateX(-50%)';
|
|
2376
|
+
containercss.left = '50%';
|
|
2377
|
+
delete containercss.top;
|
|
2378
|
+
delete containercss.right;
|
|
2379
|
+
}
|
|
2380
|
+
containercss.width = pagestyle.width;
|
|
2381
|
+
containercss.height = pagestyle.height;
|
|
2382
|
+
containercss.max_width = pagestyle.max_width;
|
|
2383
|
+
containercss.max_height = pagestyle.max_height;
|
|
2384
|
+
containercss.display = pagestyle.display;
|
|
2385
|
+
containercss.border_radius = pagestyle.border_radius;
|
|
2386
|
+
containercss.overflow = pagestyle.overflow;
|
|
2387
|
+
containercss.box_shadow = pagestyle.box_shadow;
|
|
2388
|
+
if (!popup.type || popup.type === 'modal') {
|
|
2389
|
+
containercss.max_width = '80%';
|
|
2390
|
+
containercss.max_height = '95%';
|
|
2391
|
+
}
|
|
2392
|
+
if (pos === 'fullscreen') {
|
|
2393
|
+
containercss.width = '100%';
|
|
2394
|
+
containercss.height = '100%';
|
|
2395
|
+
containercss.max_width = '100%';
|
|
2396
|
+
containercss.max_height = '100%';
|
|
2397
|
+
}
|
|
2398
|
+
if (popup.type === 'bar') {
|
|
2399
|
+
containercss.width = pagestyle.width || '100%';
|
|
2400
|
+
containercss.max_width = '100%';
|
|
2401
|
+
}
|
|
2402
|
+
return containercss;
|
|
2403
|
+
}
|
|
2404
|
+
render() {
|
|
2405
|
+
if (!this.props.t) return null;
|
|
2406
|
+
if (!this.state.cssready) return null;
|
|
2407
|
+
if (!this.state.imageReady) return null;
|
|
2408
|
+
if (!this.state.fontReady) return null;
|
|
2409
|
+
if (this.state.close) return null;
|
|
2410
|
+
let popup = util/* default */.Z.get(this.props.plugin, 'popup', {});
|
|
2411
|
+
let page = util/* default */.Z.get(popup, `pages.${this.getPageIndex()}`);
|
|
2412
|
+
if (!page) return null;
|
|
2413
|
+
let pagestyle = Object.assign({}, this.props.mobile && page.mobile_style || page.style);
|
|
2414
|
+
let containercss = this.calculateContainerCss(popup, page);
|
|
2415
|
+
let animation = '';
|
|
2416
|
+
let pos = util/* default */.Z.get(this.props.plugin, 'popup.position', 'center');
|
|
2417
|
+
if (pos === 'center' || !pos) {
|
|
2418
|
+
animation = 'zoomInCenter';
|
|
2419
|
+
if (this.state.closeAnimation) animation = 'zoomOutCenter';
|
|
2420
|
+
}
|
|
2421
|
+
if (pos === 'bottom-left' || pos === 'bottom-right') animation = 'fadeInUpBig';
|
|
2422
|
+
if (pos === 'top-left' || pos === 'top-right') animation = 'fadeInDown';
|
|
2423
|
+
if (pos === 'top-center') animation = 'fadeInDownCenter';
|
|
2424
|
+
if (pos === 'middle-left') animation = 'fadeInLeftBig';
|
|
2425
|
+
if (pos === 'middle-right') animation = 'fadeInRightBig';
|
|
2426
|
+
if (pos === 'bottom-center') animation = 'fadeInUpCenter';
|
|
2427
|
+
let layout = util/* default */.Z.get(page, 'layout');
|
|
2428
|
+
if (this.props.mobile) layout = util/* default */.Z.get(page, 'mobile_layout');
|
|
2429
|
+
let formcss = {
|
|
2430
|
+
display: pagestyle.display,
|
|
2431
|
+
align_items: pagestyle.align_items,
|
|
2432
|
+
justify_content: pagestyle.justify_content,
|
|
2433
|
+
padding_top: pagestyle.padding_top,
|
|
2434
|
+
padding_left: pagestyle.padding_left,
|
|
2435
|
+
padding_right: pagestyle.padding_right,
|
|
2436
|
+
padding_bottom: pagestyle.padding_bottom,
|
|
2437
|
+
background: pagestyle.background || popup.background || '#fff',
|
|
2438
|
+
border: pagestyle.border,
|
|
2439
|
+
overflow: layout === 'row' ? 'auto' : '',
|
|
2440
|
+
max_height: layout === 'row' ? '100%' : '',
|
|
2441
|
+
min_height: layout === 'row' ? '100%' : ''
|
|
2442
|
+
};
|
|
2443
|
+
let bodycss = {
|
|
2444
|
+
overflow: layout === 'column' ? 'auto' : '',
|
|
2445
|
+
max_height: layout === 'column' ? '100%' : '',
|
|
2446
|
+
width: '100%',
|
|
2447
|
+
position: 'relative',
|
|
2448
|
+
padding_top: pagestyle.margin_top,
|
|
2449
|
+
padding_left: pagestyle.margin_left,
|
|
2450
|
+
padding_right: pagestyle.margin_right,
|
|
2451
|
+
padding_bottom: pagestyle.margin_bottom
|
|
2452
|
+
};
|
|
2453
|
+
if (this.props.highlight === 'padding') {
|
|
2454
|
+
bodycss.background = '#bad14a87';
|
|
2455
|
+
formcss.background = '#ff3d006e';
|
|
2456
|
+
}
|
|
2457
|
+
let overlaystyle = 'position: fixed !important;';
|
|
2458
|
+
if (this.props.plugin._preview) overlaystyle = 'position: absolute !important;';
|
|
2459
|
+
if (popup.overlay) overlaystyle += ' background: #000c !important;';
|
|
2460
|
+
let $imgs = util/* default */.Z.map(page.components, (com, i) => {
|
|
2461
|
+
if (com.type === 'image') return this.renderImageComponent(com, i);
|
|
2462
|
+
});
|
|
2463
|
+
let formComponents = util/* default */.Z.filter(page.components, com => com.type !== 'image');
|
|
2464
|
+
if (!formComponents.length) {
|
|
2465
|
+
formcss.background = 'transparent';
|
|
2466
|
+
formcss.padding_top = '0';
|
|
2467
|
+
formcss.padding_bottom = '0';
|
|
2468
|
+
formcss.padding_left = '0';
|
|
2469
|
+
formcss.padding_right = '0';
|
|
2470
|
+
}
|
|
2471
|
+
return (0,preact_module.h)("div", {
|
|
2472
|
+
class: "overlay",
|
|
2473
|
+
style: overlaystyle
|
|
2474
|
+
}, (0,preact_module.h)("div", {
|
|
2475
|
+
class: animation,
|
|
2476
|
+
style: this.js2css(containercss),
|
|
2477
|
+
onClick: e => e.stopPropagation()
|
|
2478
|
+
}, this.renderCloseButton(), (0,preact_module.h)("div", {
|
|
2479
|
+
style: this.js2css(bodycss),
|
|
2480
|
+
onClick: e => this.onButtonClick(e, 'background')
|
|
2481
|
+
}, $imgs, (0,preact_module.h)("div", {
|
|
2482
|
+
style: this.js2css(formcss),
|
|
2483
|
+
form: true
|
|
2484
|
+
}, this.renderComponents(page)))));
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
/***/ }),
|
|
2489
|
+
|
|
2490
|
+
/***/ 9980:
|
|
2491
|
+
/***/ ((module) => {
|
|
2492
|
+
|
|
2493
|
+
module.exports = function () {
|
|
2494
|
+
if (!module) {
|
|
2495
|
+
var module = {};
|
|
2496
|
+
}
|
|
2497
|
+
;
|
|
2498
|
+
'use strict';
|
|
2499
|
+
var classCallCheck = function (instance, Constructor) {
|
|
2500
|
+
if (!(instance instanceof Constructor)) {
|
|
2501
|
+
throw new TypeError('Cannot call a class as a function');
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
var createClass = function () {
|
|
2505
|
+
function defineProperties(target, props) {
|
|
2506
|
+
for (var i = 0; i < props.length; i++) {
|
|
2507
|
+
var descriptor = props[i];
|
|
2508
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
2509
|
+
descriptor.configurable = true;
|
|
2510
|
+
if ('value' in descriptor) descriptor.writable = true;
|
|
2511
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
return function (Constructor, protoProps, staticProps) {
|
|
2515
|
+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
2516
|
+
if (staticProps) defineProperties(Constructor, staticProps);
|
|
2517
|
+
return Constructor;
|
|
2518
|
+
};
|
|
2519
|
+
}();
|
|
2520
|
+
var index = function (_ref) {
|
|
2521
|
+
var DOM = _ref.DOM,
|
|
2522
|
+
animate = _ref.Animation.animate,
|
|
2523
|
+
Extension = _ref.Extension,
|
|
2524
|
+
performance = _ref.Date.performance,
|
|
2525
|
+
_ref$View = _ref.View,
|
|
2526
|
+
rooter = _ref$View.rooter,
|
|
2527
|
+
destroyer = _ref$View.destroyer,
|
|
2528
|
+
drawer = _ref$View.drawer,
|
|
2529
|
+
updater = _ref$View.updater,
|
|
2530
|
+
styler = _ref$View.styler;
|
|
2531
|
+
var easeOutCubic = Extension.getExtension(Extension.Type.EASING_FUNCTION, 'ease-out-cubic');
|
|
2532
|
+
var easeOutSine = Extension.getExtension(Extension.Type.EASING_FUNCTION, 'ease-out-sine');
|
|
2533
|
+
var draw = function draw(state) {
|
|
2534
|
+
if (state.isInitialValue()) {
|
|
2535
|
+
state.root.textContent = '';
|
|
2536
|
+
state.spacer = DOM.create('span', 'tick-flip-spacer');
|
|
2537
|
+
state.root.appendChild(state.spacer);
|
|
2538
|
+
var shadowTop = DOM.create('span', 'tick-flip-shadow-top tick-flip-shadow tick-flip-front');
|
|
2539
|
+
var shadowBottom = DOM.create('span', 'tick-flip-shadow-bottom tick-flip-shadow tick-flip-back');
|
|
2540
|
+
state.root.appendChild(shadowTop);
|
|
2541
|
+
state.root.appendChild(shadowBottom);
|
|
2542
|
+
state.shadowCard = DOM.create('span', 'tick-flip-card-shadow');
|
|
2543
|
+
state.root.appendChild(state.shadowCard);
|
|
2544
|
+
}
|
|
2545
|
+
state.spacer.textContent = state.value;
|
|
2546
|
+
if (!state.isInitialValue() && !DOM.visible(state.root)) {
|
|
2547
|
+
state.cards.forEach(function (card) {
|
|
2548
|
+
card.back = state.value;
|
|
2549
|
+
card.front = state.value;
|
|
2550
|
+
});
|
|
2551
|
+
return;
|
|
2552
|
+
}
|
|
2553
|
+
var turningCard = state.cards[state.cards.length - 1];
|
|
2554
|
+
if (turningCard) {
|
|
2555
|
+
turningCard.waiting = false;
|
|
2556
|
+
turningCard.offset = performance();
|
|
2557
|
+
turningCard.back = state.value;
|
|
2558
|
+
}
|
|
2559
|
+
if (state.isInitialValue()) {
|
|
2560
|
+
var initialBottomCard = new FlipCard();
|
|
2561
|
+
initialBottomCard.back = state.value;
|
|
2562
|
+
initialBottomCard.offset = null;
|
|
2563
|
+
initialBottomCard.progress = 1;
|
|
2564
|
+
state.root.insertBefore(initialBottomCard.root, state.root.firstChild);
|
|
2565
|
+
state.cards.push(initialBottomCard);
|
|
2566
|
+
}
|
|
2567
|
+
var topCard = new FlipCard();
|
|
2568
|
+
topCard.offset = null;
|
|
2569
|
+
topCard.progress = 0;
|
|
2570
|
+
topCard.visual_progress = 0;
|
|
2571
|
+
topCard.waiting = true;
|
|
2572
|
+
topCard.front = state.value;
|
|
2573
|
+
topCard.rotate(0);
|
|
2574
|
+
state.root.insertBefore(topCard.root, state.root.firstChild);
|
|
2575
|
+
state.cards.push(topCard);
|
|
2576
|
+
if (!state.animating) {
|
|
2577
|
+
state.animating = true;
|
|
2578
|
+
var ease = Extension.getExtension(Extension.Type.EASING_FUNCTION, state.style.flipEasing);
|
|
2579
|
+
var tick = function tick() {
|
|
2580
|
+
var cardsToAnimate = state.cards.filter(function (card) {
|
|
2581
|
+
return !card.done && !card.waiting;
|
|
2582
|
+
});
|
|
2583
|
+
if (cardsToAnimate.length === 0) {
|
|
2584
|
+
state.animating = false;
|
|
2585
|
+
return;
|
|
2586
|
+
}
|
|
2587
|
+
cardsToAnimate.forEach(function (card) {
|
|
2588
|
+
if (card.offset !== null) {
|
|
2589
|
+
card.progress = (performance() - card.offset) / state.style.flipDuration;
|
|
2590
|
+
}
|
|
2591
|
+
if (card.progress >= 1) {
|
|
2592
|
+
card.progress = 1;
|
|
2593
|
+
card.done = true;
|
|
2594
|
+
}
|
|
2595
|
+
card.visual_progress = ease(card.progress);
|
|
2596
|
+
});
|
|
2597
|
+
var cardDistance = 0.01;
|
|
2598
|
+
cardsToAnimate.reverse().forEach(function (card, index) {
|
|
2599
|
+
var previousCard = cardsToAnimate[index - 1];
|
|
2600
|
+
if (previousCard && card.visual_progress <= previousCard.visual_progress) {
|
|
2601
|
+
card.visual_progress = previousCard.visual_progress + cardDistance;
|
|
2602
|
+
}
|
|
2603
|
+
});
|
|
2604
|
+
cardsToAnimate.reverse();
|
|
2605
|
+
state.cards.forEach(function (card, index) {
|
|
2606
|
+
var shadowFrontProgress = 1 - Math.abs(card.visual_progress - 0.5) * 2;
|
|
2607
|
+
var highlightBackProgress = 1 - (card.visual_progress - 0.5) / 0.5;
|
|
2608
|
+
card.shadowFront = shadowFrontProgress;
|
|
2609
|
+
card.highlightBack = highlightBackProgress;
|
|
2610
|
+
var cardAbove = state.cards[index + 1];
|
|
2611
|
+
if (cardAbove && card.visual_progress > 0.5 && card.visual_progress > 0) {
|
|
2612
|
+
card.shadowBack = easeOutCubic(cardAbove.visual_progress);
|
|
2613
|
+
}
|
|
2614
|
+
});
|
|
2615
|
+
cardsToAnimate.forEach(function (card, index) {
|
|
2616
|
+
var p = card.visual_progress;
|
|
2617
|
+
if (p > 0.5 && !card.done) {
|
|
2618
|
+
card.root.style.setProperty('z-index', 10 + index, 'important');
|
|
2619
|
+
} else {
|
|
2620
|
+
card.root.style.removeProperty('z-index');
|
|
2621
|
+
}
|
|
2622
|
+
card.rotate(p * -180);
|
|
2623
|
+
});
|
|
2624
|
+
var shadowProgress = 0;
|
|
2625
|
+
var dist = 1;
|
|
2626
|
+
cardsToAnimate.forEach(function (card) {
|
|
2627
|
+
var d = Math.abs(card.visual_progress - 0.5);
|
|
2628
|
+
if (d < dist) {
|
|
2629
|
+
dist = d;
|
|
2630
|
+
shadowProgress = card.visual_progress;
|
|
2631
|
+
}
|
|
2632
|
+
});
|
|
2633
|
+
var s = shadowProgress < 0.5 ? easeOutSine(shadowProgress / 0.5) : easeOutSine((1 - shadowProgress) / 0.5);
|
|
2634
|
+
state.shadowCard.style.setProperty('opacity', s, 'important');
|
|
2635
|
+
DOM.transform(state.shadowCard, 'scaleY', s);
|
|
2636
|
+
state.cards.filter(function (card) {
|
|
2637
|
+
return card.done;
|
|
2638
|
+
}).slice(0, -1).forEach(function (card) {
|
|
2639
|
+
state.cards = state.cards.filter(function (c) {
|
|
2640
|
+
return c !== card;
|
|
2641
|
+
});
|
|
2642
|
+
if (card.root.parentNode) {
|
|
2643
|
+
state.root.removeChild(card.root);
|
|
2644
|
+
}
|
|
2645
|
+
});
|
|
2646
|
+
requestAnimationFrame(tick);
|
|
2647
|
+
};
|
|
2648
|
+
tick();
|
|
2649
|
+
}
|
|
2650
|
+
};
|
|
2651
|
+
var FlipCard = function () {
|
|
2652
|
+
function FlipCard() {
|
|
2653
|
+
classCallCheck(this, FlipCard);
|
|
2654
|
+
this._root = DOM.create('span', 'tick-flip-card');
|
|
2655
|
+
var front = DOM.create('span', 'tick-flip-panel-front tick-flip-front tick-flip-panel');
|
|
2656
|
+
var textFront = DOM.create('span', 'tick-flip-panel-front-text');
|
|
2657
|
+
var textFrontWrapper = DOM.create('span', 'tick-flip-panel-text-wrapper');
|
|
2658
|
+
textFront.appendChild(textFrontWrapper);
|
|
2659
|
+
var shadowFront = DOM.create('span', 'tick-flip-panel-front-shadow');
|
|
2660
|
+
front.appendChild(textFront);
|
|
2661
|
+
front.appendChild(shadowFront);
|
|
2662
|
+
var back = DOM.create('span', 'tick-flip-panel-back tick-flip-back tick-flip-panel');
|
|
2663
|
+
var textBack = DOM.create('span', 'tick-flip-panel-back-text');
|
|
2664
|
+
var textBackWrapper = DOM.create('span', 'tick-flip-panel-text-wrapper');
|
|
2665
|
+
textBack.appendChild(textBackWrapper);
|
|
2666
|
+
var highlightBack = DOM.create('span', 'tick-flip-panel-back-highlight');
|
|
2667
|
+
var shadowBack = DOM.create('span', 'tick-flip-panel-back-shadow');
|
|
2668
|
+
back.appendChild(textBack);
|
|
2669
|
+
back.appendChild(highlightBack);
|
|
2670
|
+
back.appendChild(shadowBack);
|
|
2671
|
+
this._root.appendChild(front);
|
|
2672
|
+
this._root.appendChild(back);
|
|
2673
|
+
this._front = front;
|
|
2674
|
+
this._back = back;
|
|
2675
|
+
this._shadowFront = shadowFront;
|
|
2676
|
+
this._shadowBack = shadowBack;
|
|
2677
|
+
this._highlightBack = highlightBack;
|
|
2678
|
+
this._textBack = textBackWrapper;
|
|
2679
|
+
this._textFront = textFrontWrapper;
|
|
2680
|
+
this._frontValue = null;
|
|
2681
|
+
this._backValue = null;
|
|
2682
|
+
}
|
|
2683
|
+
createClass(FlipCard, [{
|
|
2684
|
+
key: 'rotate',
|
|
2685
|
+
value: function rotate(degrees) {
|
|
2686
|
+
this._front.style.setProperty('transform', 'rotateX(' + degrees + 'deg)', 'important');
|
|
2687
|
+
this._back.style.setProperty('transform', 'rotateX(' + (-180 + degrees) + 'deg)', 'important');
|
|
2688
|
+
}
|
|
2689
|
+
}, {
|
|
2690
|
+
key: 'root',
|
|
2691
|
+
get: function get$$1() {
|
|
2692
|
+
return this._root;
|
|
2693
|
+
}
|
|
2694
|
+
}, {
|
|
2695
|
+
key: 'front',
|
|
2696
|
+
set: function set$$1(value) {
|
|
2697
|
+
this._frontValue = value;
|
|
2698
|
+
this._textFront.textContent = value;
|
|
2699
|
+
},
|
|
2700
|
+
get: function get$$1() {
|
|
2701
|
+
return this._frontValue;
|
|
2702
|
+
}
|
|
2703
|
+
}, {
|
|
2704
|
+
key: 'back',
|
|
2705
|
+
set: function set$$1(value) {
|
|
2706
|
+
this._backValue = value;
|
|
2707
|
+
this._textBack.textContent = value;
|
|
2708
|
+
},
|
|
2709
|
+
get: function get$$1() {
|
|
2710
|
+
return this._backValue;
|
|
2711
|
+
}
|
|
2712
|
+
}, {
|
|
2713
|
+
key: 'highlightBack',
|
|
2714
|
+
set: function set$$1(value) {
|
|
2715
|
+
this._highlightBack.style.setProperty('opacity', value, 'important');
|
|
2716
|
+
}
|
|
2717
|
+
}, {
|
|
2718
|
+
key: 'shadowBack',
|
|
2719
|
+
set: function set$$1(value) {
|
|
2720
|
+
this._shadowBack.style.setProperty('opacity', value, 'important');
|
|
2721
|
+
}
|
|
2722
|
+
}, {
|
|
2723
|
+
key: 'shadowFront',
|
|
2724
|
+
set: function set$$1(value) {
|
|
2725
|
+
this._shadowFront.style.setProperty('opacity', value, 'important');
|
|
2726
|
+
}
|
|
2727
|
+
}]);
|
|
2728
|
+
return FlipCard;
|
|
2729
|
+
}();
|
|
2730
|
+
return function (root) {
|
|
2731
|
+
var state = {
|
|
2732
|
+
cards: [],
|
|
2733
|
+
lastCard: null,
|
|
2734
|
+
initialCard: null,
|
|
2735
|
+
shadowAbove: null,
|
|
2736
|
+
shadowBelow: null,
|
|
2737
|
+
shadowCard: null,
|
|
2738
|
+
currentValue: null,
|
|
2739
|
+
lastValue: null,
|
|
2740
|
+
front: null,
|
|
2741
|
+
back: null
|
|
2742
|
+
};
|
|
2743
|
+
return Object.assign({}, rooter(state, root, 'flip'), updater(state), styler(state, {
|
|
2744
|
+
flipDuration: 800,
|
|
2745
|
+
flipEasing: 'ease-out-bounce'
|
|
2746
|
+
}), drawer(state, draw), destroyer(state));
|
|
2747
|
+
};
|
|
2748
|
+
};
|
|
2749
|
+
module.exports = index;
|
|
2750
|
+
module.exports.identifier = {
|
|
2751
|
+
name: 'flip',
|
|
2752
|
+
type: 'view'
|
|
2753
|
+
};
|
|
2754
|
+
return module.exports;
|
|
2755
|
+
}();
|
|
2756
|
+
|
|
2757
|
+
/***/ }),
|
|
2758
|
+
|
|
2759
|
+
/***/ 7435:
|
|
2760
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2761
|
+
|
|
2762
|
+
module.exports = __webpack_require__.p + "assets/img/Facebook.64607ec.png";
|
|
2763
|
+
|
|
2764
|
+
/***/ }),
|
|
2765
|
+
|
|
2766
|
+
/***/ 7298:
|
|
2767
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2768
|
+
|
|
2769
|
+
module.exports = __webpack_require__.p + "assets/img/Zalo.6845707.png";
|
|
2770
|
+
|
|
2771
|
+
/***/ }),
|
|
2772
|
+
|
|
2773
|
+
/***/ 9639:
|
|
2774
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2775
|
+
|
|
2776
|
+
module.exports = __webpack_require__.p + "assets/img/fb_inverse_circle.36c2cfc.png";
|
|
2777
|
+
|
|
2778
|
+
/***/ })
|
|
2779
|
+
|
|
2780
|
+
}]);
|