@subiz/widget-v4 4.0.58 → 4.0.59

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.
@@ -32,7 +32,8 @@ class Popup extends _common.Com {
32
32
  cssready: false,
33
33
  closeAnimation: true,
34
34
  pressedSubmit: false,
35
- imageReady: false
35
+ imageReady: false,
36
+ fontReady: false
36
37
  });
37
38
 
38
39
  this._formRef = (0, _preact.createRef)();
@@ -61,6 +62,9 @@ class Popup extends _common.Com {
61
62
  });
62
63
  });
63
64
 
65
+ delete fonts.undefined;
66
+ delete fonts.null;
67
+ delete fonts[''];
64
68
  if (_index.default.size(images) == 0) this.setState({
65
69
  imageReady: true
66
70
  });
@@ -70,9 +74,34 @@ class Popup extends _common.Com {
70
74
  })));
71
75
 
72
76
  _index.default.preloadWebfonts(Object.keys(fonts));
77
+
78
+ setTimeout(async () => {
79
+ await this.waitForFont(Object.keys(fonts));
80
+ this.setState({
81
+ fontReady: true
82
+ });
83
+ });
73
84
  });
74
85
  }
75
86
 
87
+ async waitForFont(fonts) {
88
+ if (_index.default.size(fonts) == 0) return;
89
+ let ready = {};
90
+
91
+ for (var t = 0; t < 10; t++) {
92
+ for (var i = 0; i < fonts.length; i++) {
93
+ try {
94
+ if (document.fonts.check('normal 16px ' + fonts[i])) ready[fonts[i]] = true;
95
+ if (Object.keys(readycount) == fonts.length) return;
96
+ } catch (e) {}
97
+ }
98
+
99
+ await _index.default.sleep(200);
100
+ }
101
+
102
+ return;
103
+ }
104
+
76
105
  openPopup() {
77
106
  this.setState({
78
107
  close: false
@@ -917,6 +946,7 @@ class Popup extends _common.Com {
917
946
  if (!this.props.t) return null;
918
947
  if (!this.state.cssready) return null;
919
948
  if (!this.state.imageReady) return null;
949
+ if (!this.state.fontReady) return null;
920
950
  if (this.state.close) return null;
921
951
 
922
952
  let popup = _index.default.get(this.props.plugin, 'popup', {});
@@ -981,7 +981,7 @@ function getDayName(dayOfWeek) {
981
981
 
982
982
  let loadedFonts = {};
983
983
 
984
- function preloadWebfonts(fonts) {
984
+ function preloadWebfonts(fonts, done) {
985
985
  for (var i = 0; i < fonts.length; i++) {
986
986
  let font = fonts[i];
987
987
  if (!font) continue;
@@ -994,7 +994,9 @@ function preloadWebfonts(fonts) {
994
994
  node.innerHTML = '@!-/#Chào mỪng1';
995
995
  node.style.position = 'absolute';
996
996
  node.style.display = 'block';
997
- node.style.fontSize = '1px';
997
+ node.style.opacity = '0.1';
998
+ node.style.color = 'transparent';
999
+ node.style.fontSize = '20px';
998
1000
  node.style.height = '0px';
999
1001
  node.style.width = '0px';
1000
1002
  node.style.fontWeight = weight;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes