@vope/utils 1.6.6 → 1.6.7

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/dist/calc.d.ts CHANGED
@@ -1,13 +1,16 @@
1
- type Ls = `${string}(${string})` | `${number}${string}`;
1
+ type Ls = `${string}(${string})` | `${number}${string}` | `-${number}${string}`;
2
2
  type Lv = Ls | number;
3
3
  export declare namespace Calc {
4
4
  type Value = Lv;
5
- }
6
- declare const formatter: (value: Lv) => 0 | Ls;
7
- interface Calc {
8
- (...list: Lv[]): 0 | Ls;
9
- formatter: typeof formatter;
5
+ interface Clamp {
6
+ min?: Lv;
7
+ max?: Lv;
8
+ }
10
9
  }
11
10
  export declare const isCalc: (value: Ls) => value is `calc(${string})`;
12
- declare const calc: Calc;
13
- export { calc, };
11
+ declare const calc: {
12
+ (...list: Lv[]): 0 | Ls;
13
+ formatter: (value: Lv) => 0 | Ls;
14
+ clamp(value: Lv, { min, max }: Calc.Clamp): Ls | 0;
15
+ };
16
+ export default calc;
package/dist/calc.js CHANGED
@@ -1,22 +1,81 @@
1
1
  import { isNumber } from "lodash-es";
2
+ const { parseFloat } = Number;
2
3
  const formatter = (value) => isNumber(value) ? value && `${value}px` : value;
3
4
  const isCalc = (value) => value.slice(0, 5) === "calc(" && value.slice(-1) === ")";
5
+ const re_numerical = /^(-?(?:\.\d+|\d+(?:\.\d+)?))([a-zA-Z]+|%)$/;
6
+ const re_zero = /^0[a-zA-Z]+$/;
7
+ class Memory {
8
+ data = {};
9
+ memory = {};
10
+ add(index, value, unit) {
11
+ const { data, memory } = this;
12
+ if (!isNumber(value)) {
13
+ data[index] = { value };
14
+ } else {
15
+ const point = memory[unit];
16
+ if (point === void 0) {
17
+ data[index] = { value, unit };
18
+ memory[unit] = index;
19
+ } else {
20
+ const tmp = data[point];
21
+ tmp.value = tmp.value + value;
22
+ }
23
+ }
24
+ }
25
+ }
26
+ class Manager {
27
+ memory = new Memory();
28
+ push(value, index) {
29
+ const { memory } = this;
30
+ if (isNumber(value)) return memory.add(index, value, "px");
31
+ const matchs = value.match(re_numerical);
32
+ if (matchs) return memory.add(index, parseFloat(matchs[1]), matchs[2]);
33
+ if (!isCalc(value)) return memory.add(index, value);
34
+ const tmp = value.slice(5, -1).match(re_numerical);
35
+ tmp ? memory.add(index, parseFloat(tmp[1]), tmp[2]) : memory.add(index, value.slice(4));
36
+ }
37
+ at(index) {
38
+ return this.memory.data[index];
39
+ }
40
+ }
4
41
  const calc = (...list) => {
5
42
  const size = list.length;
6
43
  if (size === 0) return 0;
7
- if (size === 1) return formatter(list[1]);
8
- const value = list.reduce((caches, value2) => {
9
- let tmp = formatter(value2);
10
- if (tmp === 0) return caches;
11
- if (isCalc(tmp)) {
12
- tmp = tmp.slice(4);
44
+ if (size === 1) return formatter(list[0]);
45
+ const manager = new Manager();
46
+ list.forEach((value2, index) => manager.push(value2, index));
47
+ const value = list.reduce((caches, _, index) => {
48
+ const data = manager.at(index);
49
+ if (!data || data.value === 0) return caches;
50
+ const { value: value2, unit } = data;
51
+ let tmp;
52
+ if (isNumber(value2)) {
53
+ tmp = value2 + unit;
54
+ } else {
55
+ tmp = value2;
13
56
  }
14
- return caches ? `${caches} + ${tmp}` : tmp;
57
+ if (!caches) return tmp;
58
+ return tmp[0] === "-" ? `${caches} - ${tmp.slice(1)}` : `${caches} + ${tmp}`;
15
59
  }, "");
16
- return value === "" ? 0 : `calc(${value})`;
60
+ return !value || re_zero.test(value) ? 0 : `calc(${value})`;
17
61
  };
18
62
  calc.formatter = formatter;
63
+ const zero = "0px";
64
+ const u = void 0;
65
+ calc.clamp = (value, { min, max }) => {
66
+ const val = calc.formatter(value);
67
+ if (min !== u && max !== u) {
68
+ return `clamp(${calc.formatter(min) || zero}, ${val || zero}, ${calc.formatter(max) || zero})`;
69
+ } else if (max !== u) {
70
+ return `max(${calc.formatter(max) || zero}, ${val || zero})`;
71
+ } else if (min !== u) {
72
+ return `min(${calc.formatter(min) || zero}, ${val || zero})`;
73
+ } else {
74
+ return val;
75
+ }
76
+ };
77
+ var calc_default = calc;
19
78
  export {
20
- calc,
79
+ calc_default as default,
21
80
  isCalc
22
81
  };
package/dist/dic.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IsNever, Revise } from '@vope/types';
1
+ import type { IsNever, Revise } from '@vope/types';
2
2
  type Key = string | number;
3
3
  export interface Dic<V extends Key> {
4
4
  label: string;
package/dist/index.cjs.js CHANGED
@@ -36,7 +36,7 @@ __export(index_exports, {
36
36
  Union: () => Union,
37
37
  WeekLastUnit: () => WeekLastUnit,
38
38
  WildcardUnit: () => WildcardUnit,
39
- calc: () => calc,
39
+ calc: () => calc_default,
40
40
  clamp: () => clamp,
41
41
  classnames: () => classnames,
42
42
  compareVersion: () => compareVersion,
@@ -91,23 +91,82 @@ module.exports = __toCommonJS(index_exports);
91
91
 
92
92
  // src/calc.ts
93
93
  var import_lodash_es = require("lodash-es");
94
+ var { parseFloat } = Number;
94
95
  var formatter = (value) => (0, import_lodash_es.isNumber)(value) ? value && `${value}px` : value;
95
96
  var isCalc = (value) => value.slice(0, 5) === "calc(" && value.slice(-1) === ")";
97
+ var re_numerical = /^(-?(?:\.\d+|\d+(?:\.\d+)?))([a-zA-Z]+|%)$/;
98
+ var re_zero = /^0[a-zA-Z]+$/;
99
+ var Memory = class {
100
+ data = {};
101
+ memory = {};
102
+ add(index, value, unit) {
103
+ const { data, memory } = this;
104
+ if (!(0, import_lodash_es.isNumber)(value)) {
105
+ data[index] = { value };
106
+ } else {
107
+ const point = memory[unit];
108
+ if (point === void 0) {
109
+ data[index] = { value, unit };
110
+ memory[unit] = index;
111
+ } else {
112
+ const tmp = data[point];
113
+ tmp.value = tmp.value + value;
114
+ }
115
+ }
116
+ }
117
+ };
118
+ var Manager = class {
119
+ memory = new Memory();
120
+ push(value, index) {
121
+ const { memory } = this;
122
+ if ((0, import_lodash_es.isNumber)(value)) return memory.add(index, value, "px");
123
+ const matchs = value.match(re_numerical);
124
+ if (matchs) return memory.add(index, parseFloat(matchs[1]), matchs[2]);
125
+ if (!isCalc(value)) return memory.add(index, value);
126
+ const tmp = value.slice(5, -1).match(re_numerical);
127
+ tmp ? memory.add(index, parseFloat(tmp[1]), tmp[2]) : memory.add(index, value.slice(4));
128
+ }
129
+ at(index) {
130
+ return this.memory.data[index];
131
+ }
132
+ };
96
133
  var calc = (...list) => {
97
134
  const size = list.length;
98
135
  if (size === 0) return 0;
99
- if (size === 1) return formatter(list[1]);
100
- const value = list.reduce((caches, value2) => {
101
- let tmp = formatter(value2);
102
- if (tmp === 0) return caches;
103
- if (isCalc(tmp)) {
104
- tmp = tmp.slice(4);
136
+ if (size === 1) return formatter(list[0]);
137
+ const manager = new Manager();
138
+ list.forEach((value2, index) => manager.push(value2, index));
139
+ const value = list.reduce((caches, _, index) => {
140
+ const data = manager.at(index);
141
+ if (!data || data.value === 0) return caches;
142
+ const { value: value2, unit } = data;
143
+ let tmp;
144
+ if ((0, import_lodash_es.isNumber)(value2)) {
145
+ tmp = value2 + unit;
146
+ } else {
147
+ tmp = value2;
105
148
  }
106
- return caches ? `${caches} + ${tmp}` : tmp;
149
+ if (!caches) return tmp;
150
+ return tmp[0] === "-" ? `${caches} - ${tmp.slice(1)}` : `${caches} + ${tmp}`;
107
151
  }, "");
108
- return value === "" ? 0 : `calc(${value})`;
152
+ return !value || re_zero.test(value) ? 0 : `calc(${value})`;
109
153
  };
110
154
  calc.formatter = formatter;
155
+ var zero = "0px";
156
+ var u = void 0;
157
+ calc.clamp = (value, { min, max }) => {
158
+ const val = calc.formatter(value);
159
+ if (min !== u && max !== u) {
160
+ return `clamp(${calc.formatter(min) || zero}, ${val || zero}, ${calc.formatter(max) || zero})`;
161
+ } else if (max !== u) {
162
+ return `max(${calc.formatter(max) || zero}, ${val || zero})`;
163
+ } else if (min !== u) {
164
+ return `min(${calc.formatter(min) || zero}, ${val || zero})`;
165
+ } else {
166
+ return val;
167
+ }
168
+ };
169
+ var calc_default = calc;
111
170
 
112
171
  // src/clamp.ts
113
172
  var clamp = (value, min, max) => {
@@ -1230,8 +1289,8 @@ var MemoryBasic = class {
1230
1289
  const { memorys, list } = this;
1231
1290
  if (!memorys.has(type)) return this;
1232
1291
  const local = hash8strings(this.#reflex(memorys.get(type)));
1233
- const Memory = this.constructor;
1234
- const imitator = new Memory(this.key, {
1292
+ const Memory2 = this.constructor;
1293
+ const imitator = new Memory2(this.key, {
1235
1294
  mount: this.#mount,
1236
1295
  reflex: this.#reflex
1237
1296
  });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { type Calc, isCalc, calc } from './calc';
1
+ export { type Calc, isCalc, default as calc } from './calc';
2
2
  export { clamp } from './clamp';
3
3
  export { classnames } from './classnames';
4
4
  export { compareVersion } from './compare/version';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isCalc, calc } from "./calc";
1
+ import { isCalc, default as default2 } from "./calc";
2
2
  import { clamp } from "./clamp";
3
3
  import { classnames } from "./classnames";
4
4
  import { compareVersion } from "./compare/version";
@@ -8,7 +8,7 @@ import { hash8object } from "./convert/object";
8
8
  import { hash8strings } from "./convert/strings";
9
9
  import { weekDic, default_max_second, default_min_second, default_max_minute, default_min_minute, default_max_hour, default_min_hour, default_max_day, default_min_day, default_max_month, default_min_month, default_max_week, default_min_week, createCronRegexText, InvalidUnit, isInvalidUnit, DayLastUnit, isDayLastUnit, WeekLastUnit, isWeekLastUnit, WildcardUnit, isWildcardUnit, RangeUnit, isRangeUnit, AggUnit, isAggUnit, Cron } from "./cron";
10
10
  import { desensEncrypt, desensDecrypt, desensReplace } from "./desens";
11
- import { default as default2 } from "./dic";
11
+ import { default as default3 } from "./dic";
12
12
  import { getEncoding } from "./encoding";
13
13
  import { inputRegex } from "./input-regex";
14
14
  import { isClass } from "./is/class";
@@ -20,8 +20,8 @@ import { MemoryBasic } from "./memory/basic";
20
20
  import { MemoryList } from "./memory/list";
21
21
  import { MemoryPower } from "./memory/power";
22
22
  import { MemorySimple } from "./memory/simple";
23
- import { default as default3 } from "./neo4j-anchors";
24
- import { default as default4 } from "./neo4j";
23
+ import { default as default4 } from "./neo4j-anchors";
24
+ import { default as default5 } from "./neo4j";
25
25
  import { once } from "./once";
26
26
  import { parseNum } from "./parse/num";
27
27
  import { deconPowersSum } from "./power/decon";
@@ -29,7 +29,7 @@ import { rotateAngle } from "./rotate/angle";
29
29
  import { rotateRad } from "./rotate/rad";
30
30
  import { cubeURLParams, flatURLParams } from "./serialize/url-params";
31
31
  import { css } from "./style/css";
32
- import { default as default5 } from "./subscriber";
32
+ import { default as default6 } from "./subscriber";
33
33
  import { FlexTable } from "./table/flex";
34
34
  import { Union } from "./union";
35
35
  import { joinPaths } from "./url/join";
@@ -39,21 +39,21 @@ export {
39
39
  AggUnit,
40
40
  Cron,
41
41
  DayLastUnit,
42
- default2 as DicRollup,
42
+ default3 as DicRollup,
43
43
  FlexTable,
44
44
  InvalidUnit,
45
45
  MemoryBasic,
46
46
  MemoryList,
47
47
  MemoryPower,
48
48
  MemorySimple,
49
- default4 as Neo4j,
50
- default3 as Neo4jAhchors,
49
+ default5 as Neo4j,
50
+ default4 as Neo4jAhchors,
51
51
  RangeUnit,
52
- default5 as Subscriber,
52
+ default6 as Subscriber,
53
53
  Union,
54
54
  WeekLastUnit,
55
55
  WildcardUnit,
56
- calc,
56
+ default2 as calc,
57
57
  clamp,
58
58
  classnames,
59
59
  compareVersion,
@@ -1,4 +1,4 @@
1
- import { type Memory } from './type';
1
+ import type { Memory } from './type';
2
2
  interface Config<Reactor> {
3
3
  /**
4
4
  * 定义数据如何挂载到存储中
@@ -1,5 +1,5 @@
1
1
  import { MemoryBasic } from './basic';
2
- import { type Memory } from './type';
2
+ import type { Memory } from './type';
3
3
  /**
4
4
  * 分类存储(基于普通的键值存储)
5
5
  */
@@ -1,5 +1,5 @@
1
1
  import { MemoryBasic } from './basic';
2
- import { type Memory } from './type';
2
+ import type { Memory } from './type';
3
3
  /**
4
4
  * 分类存储(基于2的n次幂之和构建唯一键进行存储)
5
5
  */
@@ -1,6 +1,6 @@
1
- import { Assign } from '@vope/types';
1
+ import type { Assign } from '@vope/types';
2
2
  import { MemoryBasic } from './basic';
3
- import { type Memory } from './type';
3
+ import type { Memory } from './type';
4
4
  type Transform<T, V> = {
5
5
  [P in keyof T]: T[P] extends (...args: any) => any ? (...args: Parameters<T[P]>) => ReturnType<T[P]> extends T ? V : ReturnType<T[P]> : T[P];
6
6
  };
@@ -1,4 +1,4 @@
1
- import Neo4j from './neo4j';
1
+ import type Neo4j from './neo4j';
2
2
  interface IBox {
3
3
  centerX: number;
4
4
  centerY: number;
package/dist/neo4j.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Equal } from '@type-challenges/utils';
2
- import { GetGivenProps } from '@vope/types';
1
+ import type { Equal } from '@type-challenges/utils';
2
+ import type { GetGivenProps } from '@vope/types';
3
3
  import { MemoryList } from './memory/list';
4
4
  import { MemorySimple } from './memory/simple';
5
5
  interface Config<INode extends object, IEdge extends object> {
@@ -1,4 +1,4 @@
1
- import { Point2Tuple } from '@vope/types';
1
+ import type { Point2Tuple } from '@vope/types';
2
2
  /**
3
3
  * 返回点被旋转指定角度后新的位置
4
4
  * @param from 旋转点
@@ -1,4 +1,4 @@
1
- import { Point2Tuple } from '@vope/types';
1
+ import type { Point2Tuple } from '@vope/types';
2
2
  /**
3
3
  * 返回点被旋转指定弧度后新的位置
4
4
  * @param from 旋转点
@@ -1,5 +1,5 @@
1
- import { Equal } from '@type-challenges/utils';
2
- import { UnionToTuple } from '@vope/types';
1
+ import type { Equal } from '@type-challenges/utils';
2
+ import type { UnionToTuple } from '@vope/types';
3
3
  type NativeMap = {
4
4
  string: string;
5
5
  boolean: boolean;
@@ -1,4 +1,4 @@
1
- import { Properties, PropertiesHyphen } from 'csstype';
1
+ import type { Properties, PropertiesHyphen } from 'csstype';
2
2
  export interface CSSProperties extends Properties<string | number>, PropertiesHyphen<string | number> {
3
3
  [v: `--${string}`]: string | number | undefined;
4
4
  }
package/dist/union.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Revise } from '@vope/types';
1
+ import type { Revise } from '@vope/types';
2
2
  interface Result<Data, Option> {
3
3
  data: Data;
4
4
  option: Option;
@@ -1,4 +1,4 @@
1
- import { Serializes } from '../serialize/url-params';
1
+ import { type Serializes } from '../serialize/url-params';
2
2
  /**
3
3
  * url拼接参数
4
4
  * @param url
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vope/utils",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public",