@taole/dev-helper 0.0.2 → 0.0.3

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
@@ -1,5 +1,6 @@
1
1
  <script>
2
2
  import { createEventDispatcher } from "svelte";
3
+ import setting from "./setting";
3
4
 
4
5
  /**
5
6
  * @type {string}
@@ -120,8 +121,8 @@
120
121
  export let debug = false;
121
122
 
122
123
  // 留个口子
123
- export const viewportWidth = 750; // 默认值不改
124
- export const viewportUnit = "vw"; // 默认值不改
124
+ export let viewportWidth;
125
+ export let viewportUnit;
125
126
 
126
127
  const dispatch = createEventDispatcher();
127
128
 
@@ -131,6 +132,14 @@
131
132
  * @returns {string}
132
133
  */
133
134
  function calc(value) {
135
+ let vWidth = setting.viewportWidth;
136
+ if(viewportWidth){
137
+ vWidth = viewportWidth;
138
+ }
139
+ let vUnit = setting.viewportUnit;
140
+ if(viewportUnit){
141
+ vUnit = viewportUnit;
142
+ }
134
143
  // @ts-ignore
135
144
  if (typeof value === "string" && !isNaN(value)) {
136
145
  value = Number(value);
@@ -139,8 +148,8 @@
139
148
  if (usePx) {
140
149
  return value + "px";
141
150
  }
142
- let val = ((value / viewportWidth) * 100).toFixed(4); // 4?
143
- return `${val}${viewportUnit}`;
151
+ let val = ((value / vWidth) * 100).toFixed(4); // 4?
152
+ return `${val}${vUnit}`;
144
153
  }
145
154
  return value;
146
155
  }
package/Tdiv/index.vue CHANGED
@@ -1,15 +1,12 @@
1
1
  <template>
2
- <div
3
- role="presentation"
4
- :class="['tw-img-div', _class]"
5
- :style="styleStr"
6
- @click="handleOnClick"
7
- >
2
+ <div role="presentation" :class="['tw-img-div', _class]" :style="styleStr" @click="handleOnClick">
8
3
  <slot />
9
4
  </div>
10
5
  </template>
11
6
 
12
7
  <script>
8
+ import setting from "./setting";
9
+
13
10
  export default {
14
11
  name: 'Tdiv',
15
12
  props: {
@@ -34,17 +31,26 @@ export default {
34
31
  srcMode: { type: String, default: 'auto' },
35
32
  onClick: { type: Function, default: null },
36
33
  debug: { type: Boolean, default: false },
34
+ viewportWidth: { type: Number, default: null },
35
+ viewportUnit: { type: String, default: null },
37
36
  },
38
37
  computed: {
39
38
  styleStr() {
40
- const viewportWidth = 750;
41
- const viewportUnit = 'vw';
39
+ let vWidth = setting.viewportWidth;
40
+ if (this.viewportWidth) {
41
+ vWidth = this.viewportWidth;
42
+ }
43
+ let vUnit = setting.viewportUnit;
44
+ if (this.viewportUnit) {
45
+ vUnit = this.viewportUnit;
46
+ }
42
47
  const calc = (value) => {
48
+
43
49
  if (typeof value === 'string' && !isNaN(value)) value = Number(value);
44
50
  if (typeof value === 'number') {
45
51
  if (this.usePx) return value + 'px';
46
- let val = ((value / viewportWidth) * 100).toFixed(4);
47
- return `${val}${viewportUnit}`;
52
+ let val = ((value / vWidth) * 100).toFixed(4);
53
+ return `${val}${vUnit}`;
48
54
  }
49
55
  return value;
50
56
  };
@@ -0,0 +1,14 @@
1
+ const config = {
2
+ viewportWidth: 750,
3
+ viewportUnit: "vw",
4
+ }
5
+
6
+ export function setViewportWidth(width) {
7
+ config.viewportWidth = width;
8
+ }
9
+
10
+ export function setViewportUnit(unit) {
11
+ config.viewportUnit = unit;
12
+ }
13
+
14
+ export default config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dev-helper",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"