@vope/utils 1.6.6 → 1.6.8
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 +11 -8
- package/dist/calc.js +68 -9
- package/dist/dic.d.ts +1 -1
- package/dist/index.cjs.js +70 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -10
- package/dist/memory/basic.d.ts +1 -1
- package/dist/memory/list.d.ts +1 -1
- package/dist/memory/power.d.ts +1 -1
- package/dist/memory/simple.d.ts +2 -2
- package/dist/neo4j-anchors.d.ts +1 -1
- package/dist/neo4j.d.ts +2 -2
- package/dist/rotate/angle.d.ts +1 -1
- package/dist/rotate/rad.d.ts +1 -1
- package/dist/serialize/url-params.d.ts +2 -2
- package/dist/style/css.d.ts +1 -1
- package/dist/union.d.ts +1 -1
- package/dist/url/params.d.ts +1 -1
- package/package.json +2 -2
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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:
|
|
13
|
-
|
|
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[
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
57
|
+
if (!caches) return tmp;
|
|
58
|
+
return tmp[0] === "-" ? `${caches} - ${tmp.slice(1)}` : `${caches} + ${tmp}`;
|
|
15
59
|
}, "");
|
|
16
|
-
return 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
|
-
|
|
79
|
+
calc_default as default,
|
|
21
80
|
isCalc
|
|
22
81
|
};
|
package/dist/dic.d.ts
CHANGED
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: () =>
|
|
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[
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
149
|
+
if (!caches) return tmp;
|
|
150
|
+
return tmp[0] === "-" ? `${caches} - ${tmp.slice(1)}` : `${caches} + ${tmp}`;
|
|
107
151
|
}, "");
|
|
108
|
-
return 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
|
|
1234
|
-
const imitator = new
|
|
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
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCalc,
|
|
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
|
|
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
|
|
24
|
-
import { default as
|
|
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
|
|
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
|
-
|
|
42
|
+
default3 as DicRollup,
|
|
43
43
|
FlexTable,
|
|
44
44
|
InvalidUnit,
|
|
45
45
|
MemoryBasic,
|
|
46
46
|
MemoryList,
|
|
47
47
|
MemoryPower,
|
|
48
48
|
MemorySimple,
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
default5 as Neo4j,
|
|
50
|
+
default4 as Neo4jAhchors,
|
|
51
51
|
RangeUnit,
|
|
52
|
-
|
|
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,
|
package/dist/memory/basic.d.ts
CHANGED
package/dist/memory/list.d.ts
CHANGED
package/dist/memory/power.d.ts
CHANGED
package/dist/memory/simple.d.ts
CHANGED
|
@@ -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 {
|
|
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
|
};
|
package/dist/neo4j-anchors.d.ts
CHANGED
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> {
|
package/dist/rotate/angle.d.ts
CHANGED
package/dist/rotate/rad.d.ts
CHANGED
package/dist/style/css.d.ts
CHANGED
|
@@ -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
package/dist/url/params.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vope/utils",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@type-challenges/utils": "^0.1.1",
|
|
68
68
|
"@types/lodash-es": "^4.17.12",
|
|
69
|
-
"@vope/types": "^1.
|
|
69
|
+
"@vope/types": "^1.2.0",
|
|
70
70
|
"csstype": "^3.1.3",
|
|
71
71
|
"localforage": "^1.10.0",
|
|
72
72
|
"lodash-es": "^4.17.21",
|