clxx 2.1.2 → 2.1.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.
@@ -1,4 +1,4 @@
1
- import { CSSProperties } from "@emotion/serialize";
1
+ import { Interpolation, Theme } from '@emotion/react';
2
2
  /**
3
3
  * 匹配所有的CSS数值类型的值
4
4
  */
@@ -39,4 +39,4 @@ export declare function splitValue(value: number | string, defaultUnit?: string)
39
39
  * @param style
40
40
  * @returns
41
41
  */
42
- export declare function adaptive(style: Partial<Record<keyof CSSProperties, number | string>>): import("@emotion/utils").SerializedStyles;
42
+ export declare function adaptive(style: Record<string, Interpolation<Theme>>): import("@emotion/utils").SerializedStyles;
@@ -1,5 +1,5 @@
1
- import { css } from "@emotion/react";
2
- import { getContextValue } from "../context";
1
+ import { css } from '@emotion/react';
2
+ import { getContextValue } from '../context';
3
3
  /**
4
4
  * 匹配所有的CSS数值类型的值
5
5
  */
@@ -10,11 +10,11 @@ export const CSSValueReg = /^((?:\-)?(?:\d+\.?|\.\d+|\d+\.\d+))([a-zA-Z%]*)$/;
10
10
  * @param value 长度值
11
11
  * @param defaultUnit 默认长度值单位
12
12
  */
13
- export function normalizeUnit(value, defaultUnit = "px") {
14
- if (typeof value === "number") {
13
+ export function normalizeUnit(value, defaultUnit = 'px') {
14
+ if (typeof value === 'number') {
15
15
  return value + defaultUnit;
16
16
  }
17
- if (typeof value === "string") {
17
+ if (typeof value === 'string') {
18
18
  const result = value.match(CSSValueReg);
19
19
  if (Array.isArray(result)) {
20
20
  return result[2]
@@ -39,17 +39,17 @@ export function normalizeUnit(value, defaultUnit = "px") {
39
39
  * @param value
40
40
  * @param defaultUnit
41
41
  */
42
- export function splitValue(value, defaultUnit = "px") {
43
- if (typeof value === "number") {
42
+ export function splitValue(value, defaultUnit = 'px') {
43
+ if (typeof value === 'number') {
44
44
  return { num: value, unit: defaultUnit };
45
45
  }
46
- if (typeof value === "string") {
46
+ if (typeof value === 'string') {
47
47
  const result = value.match(CSSValueReg);
48
48
  if (Array.isArray(result)) {
49
49
  return { num: parseFloat(result[1]), unit: result[2] || defaultUnit };
50
50
  }
51
51
  }
52
- throw new Error("Invalid numeric format");
52
+ throw new Error('Invalid numeric format');
53
53
  }
54
54
  /**
55
55
  * 生成自适应的样式,仅供库内部使用
@@ -65,13 +65,24 @@ export function adaptive(style) {
65
65
  const normal = {};
66
66
  for (let name in style) {
67
67
  let value = style[name];
68
- if (typeof value !== "number") {
68
+ if (typeof value !== 'number') {
69
+ normal[name] = value;
70
+ }
71
+ else if ([
72
+ 'flex',
73
+ 'flexGrow',
74
+ 'flexShrink',
75
+ 'lineHeight',
76
+ 'fontWeight',
77
+ 'zIndex',
78
+ ].includes(name) &&
79
+ typeof value === 'number') {
69
80
  normal[name] = value;
70
81
  }
71
82
  else {
72
- normal[name] = (value * 100) / 750 + "vw";
73
- max[name] = (value * ctx.maxDocWidth) / 750 + "px";
74
- min[name] = (value * ctx.minDocWidth) / 750 + "px";
83
+ normal[name] = (value * 100) / 750 + 'vw';
84
+ max[name] = (value * ctx.maxDocWidth) / 750 + 'px';
85
+ min[name] = (value * ctx.minDocWidth) / 750 + 'px';
75
86
  }
76
87
  }
77
88
  return css(Object.assign(Object.assign({}, normal), { [`@media (min-width: ${ctx.maxDocWidth}px)`]: max, [`@media (max-width: ${ctx.minDocWidth}px)`]: min }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clxx",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "Basic JS library for mobile devices",
5
5
  "main": "./build/index.js",
6
6
  "module": "./build/index.js",