@taole/dev-helper 0.0.3 → 0.0.5

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.svelte CHANGED
@@ -121,8 +121,8 @@
121
121
  export let debug = false;
122
122
 
123
123
  // 留个口子
124
- export let viewportWidth;
125
- export let viewportUnit;
124
+ export let viewportWidth = undefined;
125
+ export let viewportUnit = undefined;
126
126
 
127
127
  const dispatch = createEventDispatcher();
128
128
 
@@ -140,12 +140,16 @@
140
140
  if(viewportUnit){
141
141
  vUnit = viewportUnit;
142
142
  }
143
+ let localUsePx = setting.usePx;
144
+ if(typeof usePx === 'boolean'){
145
+ localUsePx = usePx;
146
+ }
143
147
  // @ts-ignore
144
148
  if (typeof value === "string" && !isNaN(value)) {
145
149
  value = Number(value);
146
150
  }
147
151
  if (typeof value === "number") {
148
- if (usePx) {
152
+ if (localUsePx) {
149
153
  return value + "px";
150
154
  }
151
155
  let val = ((value / vWidth) * 100).toFixed(4); // 4?
package/Tdiv/index.vue CHANGED
@@ -11,7 +11,7 @@ export default {
11
11
  name: 'Tdiv',
12
12
  props: {
13
13
  _class: { type: String, default: '' },
14
- usePx: { type: Boolean, default: false },
14
+ usePx: { type: Boolean, default: null },
15
15
  style: { type: String, default: '' },
16
16
  src: { type: String, default: '' },
17
17
  width: { type: [Number, String], default: null },
@@ -44,11 +44,15 @@ export default {
44
44
  if (this.viewportUnit) {
45
45
  vUnit = this.viewportUnit;
46
46
  }
47
+ let localUsePx = setting.usePx;
48
+ if(typeof this.usePx === 'boolean'){
49
+ localUsePx = this.usePx;
50
+ }
47
51
  const calc = (value) => {
48
52
 
49
53
  if (typeof value === 'string' && !isNaN(value)) value = Number(value);
50
54
  if (typeof value === 'number') {
51
- if (this.usePx) return value + 'px';
55
+ if (localUsePx) return value + 'px';
52
56
  let val = ((value / vWidth) * 100).toFixed(4);
53
57
  return `${val}${vUnit}`;
54
58
  }
package/Tdiv/setting.js CHANGED
@@ -1,14 +1,31 @@
1
1
  const config = {
2
2
  viewportWidth: 750,
3
3
  viewportUnit: "vw",
4
+ usePx: false,
4
5
  }
5
6
 
7
+ /**
8
+ * 设置视口宽度
9
+ * @param {number} width
10
+ */
6
11
  export function setViewportWidth(width) {
7
12
  config.viewportWidth = width;
8
13
  }
9
14
 
15
+ /**
16
+ * 设置视口单位
17
+ * @param {string} unit
18
+ */
10
19
  export function setViewportUnit(unit) {
11
20
  config.viewportUnit = unit;
12
21
  }
13
22
 
23
+ /**
24
+ * 设置是否使用px
25
+ * @param {boolean} use
26
+ */
27
+ export function setUsePx(use) {
28
+ config.usePx = use;
29
+ }
30
+
14
31
  export default config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dev-helper",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"