@taole/dev-helper 0.0.19 → 0.0.21

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/Tdiv/index.js CHANGED
@@ -1,6 +1,21 @@
1
1
  import setting from "./setting.js";
2
2
  import { updateConfig, setViewportWidth, setViewportUnit, setUsePx, setUseButtonEffect, subscribe } from "./setting.js";
3
3
 
4
+ const isSupportWebp = (() => {
5
+ try {
6
+ const elem = document.createElement('canvas');
7
+ if (!!(elem.getContext && elem.getContext('2d'))) {
8
+ // Was able to get context, now test webp
9
+ return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;
10
+ }
11
+ return false;
12
+ } catch (e) {
13
+ return false;
14
+ }
15
+ })();
16
+
17
+ // console.log('isSupportWebp', isSupportWebp);
18
+
4
19
  const styleText = `
5
20
  .tw-img-div {
6
21
  display: block;
@@ -181,7 +196,10 @@ class Tdiv extends HTMLElement {
181
196
  if (src) {
182
197
  let realSrc = src;
183
198
  if (src.indexOf('https://') === -1) {
184
- realSrc = `https://dynamics-share.tuwan.com/${src}?x-oss-process=image/format,webp/ignore-error,1`;
199
+ realSrc = `https://dynamics-share.tuwan.com/${src}`;
200
+ if(isSupportWebp){
201
+ realSrc = `https://dynamics-share.tuwan.com/${src}?x-oss-process=image/format,webp/ignore-error,1`;
202
+ }
185
203
  }
186
204
  layoutStyle += `background-image: url(${realSrc});`;
187
205
 
@@ -216,6 +234,7 @@ class Tdiv extends HTMLElement {
216
234
  }
217
235
 
218
236
 
237
+
219
238
  let isRegister = false;
220
239
  function registerTdiv() {
221
240
  if (!isRegister) {
@@ -231,5 +250,5 @@ function registerTdiv() {
231
250
  registerTdiv();
232
251
 
233
252
  export default {
234
- updateConfig, setViewportWidth, setViewportUnit, setUsePx, setUseButtonEffect
253
+ isSupportWebp, updateConfig, setViewportWidth, setViewportUnit, setUsePx, setUseButtonEffect
235
254
  }
@@ -34,6 +34,8 @@
34
34
  if (!this._openAppTag) {
35
35
  // 放进去一个wx-open-launch-app, 宽高占满父容器
36
36
  this._openAppTag = document.createElement('wx-open-launch-app');
37
+ this._openAppTag.style.background = "transparent";
38
+ this._openAppTag.style.opacity = 0;
37
39
  this._updateTagAttr();
38
40
 
39
41
  var contentEle = document.createElement('div');
@@ -115,7 +117,7 @@
115
117
  _genTemplate() {
116
118
  if (!this._template) {
117
119
  this._template = document.createElement('template');
118
- this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;}</style>';
120
+ this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;opacity: 0;background:transparent;}</style>';
119
121
  }
120
122
  }
121
123
  _updateTagAttr() {
package/dist/tdiv.umd.js CHANGED
@@ -85,6 +85,21 @@
85
85
  notify();
86
86
  }
87
87
 
88
+ const isSupportWebp = (() => {
89
+ try {
90
+ const elem = document.createElement('canvas');
91
+ if (!!(elem.getContext && elem.getContext('2d'))) {
92
+ // Was able to get context, now test webp
93
+ return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;
94
+ }
95
+ return false;
96
+ } catch (e) {
97
+ return false;
98
+ }
99
+ })();
100
+
101
+ // console.log('isSupportWebp', isSupportWebp);
102
+
88
103
  const styleText = `
89
104
  .tw-img-div {
90
105
  display: block;
@@ -265,7 +280,10 @@
265
280
  if (src) {
266
281
  let realSrc = src;
267
282
  if (src.indexOf('https://') === -1) {
268
- realSrc = `https://dynamics-share.tuwan.com/${src}?x-oss-process=image/format,webp/ignore-error,1`;
283
+ realSrc = `https://dynamics-share.tuwan.com/${src}`;
284
+ if(isSupportWebp){
285
+ realSrc = `https://dynamics-share.tuwan.com/${src}?x-oss-process=image/format,webp/ignore-error,1`;
286
+ }
269
287
  }
270
288
  layoutStyle += `background-image: url(${realSrc});`;
271
289
 
@@ -300,6 +318,7 @@
300
318
  }
301
319
 
302
320
 
321
+
303
322
  let isRegister = false;
304
323
  function registerTdiv() {
305
324
  if (!isRegister) {
@@ -315,7 +334,7 @@
315
334
  registerTdiv();
316
335
 
317
336
  var index = {
318
- updateConfig, setViewportWidth, setViewportUnit, setUsePx, setUseButtonEffect
337
+ isSupportWebp, updateConfig, setViewportWidth, setViewportUnit, setUsePx, setUseButtonEffect
319
338
  };
320
339
 
321
340
  return index;
@@ -28,6 +28,8 @@ function defineTag() {
28
28
  if (!this._openAppTag) {
29
29
  // 放进去一个wx-open-launch-app, 宽高占满父容器
30
30
  this._openAppTag = document.createElement('wx-open-launch-app');
31
+ this._openAppTag.style.background = "transparent";
32
+ this._openAppTag.style.opacity = 0;
31
33
  this._updateTagAttr();
32
34
 
33
35
  var contentEle = document.createElement('div');
@@ -109,7 +111,7 @@ function defineTag() {
109
111
  _genTemplate() {
110
112
  if (!this._template) {
111
113
  this._template = document.createElement('template');
112
- this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;}</style>';
114
+ this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;opacity: 0;background:transparent;}</style>';
113
115
  }
114
116
  }
115
117
  _updateTagAttr() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dev-helper",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npx -y rimraf dist && rollup -c",