@taole/dev-helper 0.0.20 → 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
  }
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dev-helper",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npx -y rimraf dist && rollup -c",