@taole/dev-helper 0.0.20 → 0.0.22

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;
@@ -42,7 +57,8 @@ class Tdiv extends HTMLElement {
42
57
  return [
43
58
  '_class', 'usePx', '_style', 'src', 'width', 'height', 'absolute',
44
59
  'top', 'left', 'right', 'bottom', 'zIndex', 'pointer', 'flex', 'column', 'center',
45
- 'text', 'color','radius','border','borderColor', 'srcMode', 'onClick', 'debug', 'viewportWidth', 'viewportUnit'
60
+ 'text', 'color', 'radius', 'border', 'borderColor', 'srcMode', 'onClick', 'debug', 'viewportWidth', 'viewportUnit',
61
+ 'dot9', 'dot9Border'
46
62
  ];
47
63
  }
48
64
 
@@ -98,7 +114,6 @@ class Tdiv extends HTMLElement {
98
114
  _update() {
99
115
  if (this._iscalcstyle) return;
100
116
  this._iscalcstyle = true;
101
- // console.log('update');
102
117
  // 读取所有属性
103
118
  const _class = this._getAttr('_class') || '';
104
119
  const usePx = this._getAttr('usePx', 'boolean');
@@ -117,6 +132,7 @@ class Tdiv extends HTMLElement {
117
132
  const column = this._getAttr('column', 'boolean');
118
133
  const center = this._getAttr('center', 'boolean');
119
134
  const text = this._getAttr('text');
135
+ const bold = this._getAttr('bold', 'boolean');
120
136
  const color = this._getAttr('color');
121
137
  const radius = this._getAttr('radius');
122
138
  const border = this._getAttr('border');
@@ -125,6 +141,10 @@ class Tdiv extends HTMLElement {
125
141
  const debug = this._getAttr('debug', 'boolean');
126
142
  const viewportWidth = this._getAttr('viewportWidth', 'number');
127
143
  const viewportUnit = this._getAttr('viewportUnit');
144
+ const textEllipsis = this._getAttr('textEllipsis');
145
+ let dot9 = (this._getAttr('dot9', 'string') || '').split(" ");
146
+ let dot9Border = (this._getAttr('dot9Border', 'string') || this._getAttr('dot9', 'string') || '').split(" ");
147
+
128
148
  // class
129
149
  let extraClass = ['tw-img-div'];
130
150
  if (_class) extraClass.push(_class);
@@ -132,6 +152,15 @@ class Tdiv extends HTMLElement {
132
152
  // 分组样式
133
153
  const calcOpt = { usePx, viewportWidth, viewportUnit };
134
154
  let layoutStyle = '';
155
+
156
+ let useDot9 = false;
157
+ if (dot9.length === 4 && dot9Border.length === 4) {
158
+ useDot9 = true;
159
+ dot9Border.forEach((item, index) => {
160
+ dot9Border[index] = calc(item, calcOpt);
161
+ });
162
+ }
163
+
135
164
  // 宽度
136
165
  if (hasValue(width)) {
137
166
  const widthStyle = `width: ${calc(width, calcOpt)};`;
@@ -178,18 +207,44 @@ class Tdiv extends HTMLElement {
178
207
  }
179
208
 
180
209
  if (text) layoutStyle += `font-size: ${calc(text, calcOpt)};`;
210
+ if (bold) layoutStyle += `font-weight: bold;`;
211
+ if(textEllipsis !== null){
212
+ const isSingleLine = !/^\d+$/.test(textEllipsis);
213
+ layoutStyle += `overflow: hidden;`;
214
+ layoutStyle += `text-overflow: ellipsis;`;
215
+ if(isSingleLine){
216
+ layoutStyle += `white-space: nowrap;`;
217
+ } else {
218
+ layoutStyle += `white-space: pre-wrap;`;
219
+ layoutStyle += `overflow-wrap: break-word;`;
220
+ layoutStyle += `word-break: break-all;`;
221
+ layoutStyle += `display: -webkit-box;`;
222
+ layoutStyle += `-webkit-line-clamp: ${textEllipsis};`;
223
+ layoutStyle += `-webkit-box-orient: vertical;`;
224
+ layoutStyle += `line-clamp: ${textEllipsis};`;
225
+ layoutStyle += `box-orient: vertical;`;
226
+ }
227
+ }
181
228
  if (src) {
182
229
  let realSrc = src;
183
230
  if (src.indexOf('https://') === -1) {
184
- realSrc = `https://dynamics-share.tuwan.com/${src}?x-oss-process=image/format,webp/ignore-error,1`;
231
+ realSrc = `https://dynamics-share.tuwan.com/${src}`;
232
+ if (isSupportWebp) {
233
+ realSrc = `https://dynamics-share.tuwan.com/${src}?x-oss-process=image/format,webp/ignore-error,1`;
234
+ }
185
235
  }
186
- layoutStyle += `background-image: url(${realSrc});`;
187
-
188
-
189
- if (srcMode === 'fill') {
190
- layoutStyle += 'background-size: 100% 100%;';
191
- } else if (srcMode === 'cover') {
192
- layoutStyle += 'background-size: cover;';
236
+ if (useDot9) {
237
+ layoutStyle += `border-image: url(${realSrc}) ${dot9.join(" ")} fill;`;
238
+ layoutStyle += `border-width: ${dot9Border.join(" ")};`;
239
+ layoutStyle += `border-style: solid;`;
240
+ layoutStyle += `box-sizing: border-box;`;
241
+ } else {
242
+ layoutStyle += `background-image: url(${realSrc});`;
243
+ if (srcMode === 'fill') {
244
+ layoutStyle += 'background-size: 100% 100%;';
245
+ } else if (srcMode === 'cover') {
246
+ layoutStyle += 'background-size: cover;';
247
+ }
193
248
  }
194
249
  }
195
250
  if (color) layoutStyle += `color: ${color};`;
@@ -209,13 +264,14 @@ class Tdiv extends HTMLElement {
209
264
  const onClickAttr = this._getAttr('onClick');
210
265
  if (onClickAttr && typeof window[onClickAttr] === 'function') {
211
266
  window[onClickAttr](e);
212
- } else if(onClickAttr && typeof onClickAttr === 'function') {
267
+ } else if (onClickAttr && typeof onClickAttr === 'function') {
213
268
  onClickAttr(e);
214
269
  }
215
270
  }
216
271
  }
217
272
 
218
273
 
274
+
219
275
  let isRegister = false;
220
276
  function registerTdiv() {
221
277
  if (!isRegister) {
@@ -231,5 +287,5 @@ function registerTdiv() {
231
287
  registerTdiv();
232
288
 
233
289
  export default {
234
- updateConfig, setViewportWidth, setViewportUnit, setUsePx, setUseButtonEffect
290
+ isSupportWebp, updateConfig, setViewportWidth, setViewportUnit, setUsePx, setUseButtonEffect
235
291
  }
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;
@@ -126,7 +141,8 @@
126
141
  return [
127
142
  '_class', 'usePx', '_style', 'src', 'width', 'height', 'absolute',
128
143
  'top', 'left', 'right', 'bottom', 'zIndex', 'pointer', 'flex', 'column', 'center',
129
- 'text', 'color','radius','border','borderColor', 'srcMode', 'onClick', 'debug', 'viewportWidth', 'viewportUnit'
144
+ 'text', 'color', 'radius', 'border', 'borderColor', 'srcMode', 'onClick', 'debug', 'viewportWidth', 'viewportUnit',
145
+ 'dot9', 'dot9Border'
130
146
  ];
131
147
  }
132
148
 
@@ -182,7 +198,6 @@
182
198
  _update() {
183
199
  if (this._iscalcstyle) return;
184
200
  this._iscalcstyle = true;
185
- // console.log('update');
186
201
  // 读取所有属性
187
202
  const _class = this._getAttr('_class') || '';
188
203
  const usePx = this._getAttr('usePx', 'boolean');
@@ -201,6 +216,7 @@
201
216
  const column = this._getAttr('column', 'boolean');
202
217
  const center = this._getAttr('center', 'boolean');
203
218
  const text = this._getAttr('text');
219
+ const bold = this._getAttr('bold', 'boolean');
204
220
  const color = this._getAttr('color');
205
221
  const radius = this._getAttr('radius');
206
222
  const border = this._getAttr('border');
@@ -209,6 +225,10 @@
209
225
  const debug = this._getAttr('debug', 'boolean');
210
226
  const viewportWidth = this._getAttr('viewportWidth', 'number');
211
227
  const viewportUnit = this._getAttr('viewportUnit');
228
+ const textEllipsis = this._getAttr('textEllipsis');
229
+ let dot9 = (this._getAttr('dot9', 'string') || '').split(" ");
230
+ let dot9Border = (this._getAttr('dot9Border', 'string') || this._getAttr('dot9', 'string') || '').split(" ");
231
+
212
232
  // class
213
233
  let extraClass = ['tw-img-div'];
214
234
  if (_class) extraClass.push(_class);
@@ -216,6 +236,15 @@
216
236
  // 分组样式
217
237
  const calcOpt = { usePx, viewportWidth, viewportUnit };
218
238
  let layoutStyle = '';
239
+
240
+ let useDot9 = false;
241
+ if (dot9.length === 4 && dot9Border.length === 4) {
242
+ useDot9 = true;
243
+ dot9Border.forEach((item, index) => {
244
+ dot9Border[index] = calc(item, calcOpt);
245
+ });
246
+ }
247
+
219
248
  // 宽度
220
249
  if (hasValue(width)) {
221
250
  const widthStyle = `width: ${calc(width, calcOpt)};`;
@@ -262,18 +291,44 @@
262
291
  }
263
292
 
264
293
  if (text) layoutStyle += `font-size: ${calc(text, calcOpt)};`;
294
+ if (bold) layoutStyle += `font-weight: bold;`;
295
+ if(textEllipsis !== null){
296
+ const isSingleLine = !/^\d+$/.test(textEllipsis);
297
+ layoutStyle += `overflow: hidden;`;
298
+ layoutStyle += `text-overflow: ellipsis;`;
299
+ if(isSingleLine){
300
+ layoutStyle += `white-space: nowrap;`;
301
+ } else {
302
+ layoutStyle += `white-space: pre-wrap;`;
303
+ layoutStyle += `overflow-wrap: break-word;`;
304
+ layoutStyle += `word-break: break-all;`;
305
+ layoutStyle += `display: -webkit-box;`;
306
+ layoutStyle += `-webkit-line-clamp: ${textEllipsis};`;
307
+ layoutStyle += `-webkit-box-orient: vertical;`;
308
+ layoutStyle += `line-clamp: ${textEllipsis};`;
309
+ layoutStyle += `box-orient: vertical;`;
310
+ }
311
+ }
265
312
  if (src) {
266
313
  let realSrc = src;
267
314
  if (src.indexOf('https://') === -1) {
268
- realSrc = `https://dynamics-share.tuwan.com/${src}?x-oss-process=image/format,webp/ignore-error,1`;
315
+ realSrc = `https://dynamics-share.tuwan.com/${src}`;
316
+ if (isSupportWebp) {
317
+ realSrc = `https://dynamics-share.tuwan.com/${src}?x-oss-process=image/format,webp/ignore-error,1`;
318
+ }
269
319
  }
270
- layoutStyle += `background-image: url(${realSrc});`;
271
-
272
-
273
- if (srcMode === 'fill') {
274
- layoutStyle += 'background-size: 100% 100%;';
275
- } else if (srcMode === 'cover') {
276
- layoutStyle += 'background-size: cover;';
320
+ if (useDot9) {
321
+ layoutStyle += `border-image: url(${realSrc}) ${dot9.join(" ")} fill;`;
322
+ layoutStyle += `border-width: ${dot9Border.join(" ")};`;
323
+ layoutStyle += `border-style: solid;`;
324
+ layoutStyle += `box-sizing: border-box;`;
325
+ } else {
326
+ layoutStyle += `background-image: url(${realSrc});`;
327
+ if (srcMode === 'fill') {
328
+ layoutStyle += 'background-size: 100% 100%;';
329
+ } else if (srcMode === 'cover') {
330
+ layoutStyle += 'background-size: cover;';
331
+ }
277
332
  }
278
333
  }
279
334
  if (color) layoutStyle += `color: ${color};`;
@@ -293,13 +348,14 @@
293
348
  const onClickAttr = this._getAttr('onClick');
294
349
  if (onClickAttr && typeof window[onClickAttr] === 'function') {
295
350
  window[onClickAttr](e);
296
- } else if(onClickAttr && typeof onClickAttr === 'function') {
351
+ } else if (onClickAttr && typeof onClickAttr === 'function') {
297
352
  onClickAttr(e);
298
353
  }
299
354
  }
300
355
  }
301
356
 
302
357
 
358
+
303
359
  let isRegister = false;
304
360
  function registerTdiv() {
305
361
  if (!isRegister) {
@@ -315,7 +371,7 @@
315
371
  registerTdiv();
316
372
 
317
373
  var index = {
318
- updateConfig, setViewportWidth, setViewportUnit, setUsePx, setUseButtonEffect
374
+ isSupportWebp, updateConfig, setViewportWidth, setViewportUnit, setUsePx, setUseButtonEffect
319
375
  };
320
376
 
321
377
  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.22",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npx -y rimraf dist && rollup -c",